Revision 1607

View differences:

branches/v02_desarrollo/libraries/libCq CMS for java.old/src/org/cresques/px/dxf/DxfCircle.java
13 13
import org.cresques.cts.ICoordTrans;
14 14
import org.cresques.cts.IProjection;
15 15
import org.cresques.geo.ViewPortData;
16
import org.cresques.io.DxfGroup;
16 17
import org.cresques.px.Extent;
17 18

  
18 19
/**
19 20
 * Entidad TEXT de AutoCAD
20
 * 
21
 * jmorell: Definici?n de atributos para el piloto de CAD e implementaci?n de
22
 * la escritura en formato DXF2000.
21 23
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
22 24
 */
23 25
public class DxfCircle extends DxfEntity {
......
26 28
	Point2D [] pts;
27 29
	GeneralPath gp = null;
28 30
	boolean closed = true;
31
	private Point2D center;
32
	private double radius;
29 33
	
30 34
	public DxfCircle(IProjection proj, DxfLayer layer, Point2D[] pts) {
31 35
		super(proj, layer);
......
94 98
			gp.closePath();			
95 99
		}
96 100
	}
97
	/* (non-Javadoc)
98
	 * @see org.cresques.px.dxf.DxfEntity#toDxfFileString()
101
	/**
102
	 * Escritura de c?rculos en un DXF2000.
99 103
	 */
100 104
	public String toDxfString() {
101
		// TODO Auto-generated method stub
102
		return "";
105
		StringBuffer sb = null;
106
		sb = new StringBuffer( DxfGroup.toString(0, "CIRCLE") );
107
		sb.append( DxfGroup.toString(5, getHandle()) );
108
		sb.append( DxfGroup.toString(100, "AcDbEntity") );
109
		sb.append( DxfGroup.toString(8, layer.getName()) );
110
		sb.append( DxfGroup.toString(62, dxfColor) );
111
		sb.append( DxfGroup.toString(100, "AcDbCircle") );
112
		sb.append( DxfGroup.toString(10, getCenter().getX(), 6));
113
		sb.append( DxfGroup.toString(20, getCenter().getY(), 6) );
114
		sb.append( DxfGroup.toString(40, getRadius(), 6) );
115
		return sb.toString();
103 116
	}
104 117
	/**
105 118
	 * @return
......
116 129
		return (GeneralPath) gp.clone();
117 130
	}*/
118 131

  
132
	/**
133
	 * @return Returns the radius.
134
	 */
135
	public double getRadius() {
136
		return radius;
137
	}
138
	/**
139
	 * @param radius The radius to set.
140
	 */
141
	public void setRadius(double radius) {
142
		this.radius = radius;
143
	}
144
	/**
145
	 * @return Returns the center.
146
	 */
147
	public Point2D getCenter() {
148
		return center;
149
	}
150
	/**
151
	 * @param center The center to set.
152
	 */
153
	public void setCenter(Point2D center) {
154
		this.center = center;
155
	}
119 156
}
branches/v02_desarrollo/libraries/libCq CMS for java.old/src/org/cresques/px/dxf/DxfArc.java
13 13
import org.cresques.cts.ICoordTrans;
14 14
import org.cresques.cts.IProjection;
15 15
import org.cresques.geo.ViewPortData;
16
import org.cresques.io.DxfGroup;
16 17
import org.cresques.px.Extent;
17 18

  
18 19
/**
19 20
 * Entidad TEXT de AutoCAD
20
 * 
21
 * jmorell: Definici?n de atributos para arcos necesaria para el piloto de CAD y
22
 * implementaci?n de su escritura en formato DXF2000.
21 23
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
22 24
 */
23 25
public class DxfArc extends DxfEntity {
......
26 28
	Point2D [] pts;
27 29
	GeneralPath gp = null;
28 30
	boolean closed = false;
29
	
31
	private Point2D centralPoint;
32
	private Point2D init;
33
	private Point2D end;
34
	private Point2D center;
35
	private double radius;
36
	private double initAngle;
37
	private double endAngle;
38

  
30 39
	public DxfArc(IProjection proj, DxfLayer layer, Point2D[] pts) {
31 40
		super(proj, layer);
32 41
		this.pts = pts;
......
96 105
			gp.closePath();			
97 106
		}
98 107
	}
99
	/* (non-Javadoc)
100
	 * @see org.cresques.px.dxf.DxfEntity#toDxfFileString()
108
	
109
	/**
110
	 * 050223, jmorell: Escritura de arcos en un fichero DXF2000.
101 111
	 */
102 112
	public String toDxfString() {
103
		// TODO Auto-generated method stub
104
		return "";
113
		StringBuffer sb = null;
114
		sb = new StringBuffer( DxfGroup.toString(0, "ARC") );
115
		sb.append( DxfGroup.toString(5, getHandle()) );
116
		sb.append( DxfGroup.toString(100, "AcDbEntity") );
117
		sb.append( DxfGroup.toString(8, layer.getName()) );
118
		sb.append( DxfGroup.toString(62, dxfColor) );
119
		sb.append( DxfGroup.toString(100, "AcDbCircle") );
120
		sb.append( DxfGroup.toString(10, getCenter().getX(), 6));
121
		sb.append( DxfGroup.toString(20, getCenter().getY(), 6) );
122
		sb.append( DxfGroup.toString(40, getRadius(), 6) );
123
		sb.append( DxfGroup.toString(100, "AcDbArc") );
124
		sb.append( DxfGroup.toString(50, getInitAngle(), 6) );
125
		sb.append( DxfGroup.toString(51, getEndAngle(), 6) );
126
		return sb.toString();
105 127
	}
106 128
	/**
107 129
	 * @return
......
118 140
		return (GeneralPath) gp.clone();
119 141
	}*/
120 142

  
143
	/**
144
	 * @return Returns the center.
145
	 */
146
	public Point2D getCenter() {
147
		return center;
148
	}
149
	/**
150
	 * @param center The center to set.
151
	 */
152
	public void setCenter(Point2D center) {
153
		this.center = center;
154
	}
155
	/**
156
	 * @return Returns the end.
157
	 */
158
	public Point2D getEnd() {
159
		return end;
160
	}
161
	/**
162
	 * @param end The end to set.
163
	 */
164
	public void setEnd(Point2D end) {
165
		this.end = end;
166
	}
167
	/**
168
	 * @return Returns the init.
169
	 */
170
	public Point2D getInit() {
171
		return init;
172
	}
173
	/**
174
	 * @param init The init to set.
175
	 */
176
	public void setInit(Point2D init) {
177
		this.init = init;
178
	}
179
	/**
180
	 * @return Returns the centralPoint.
181
	 */
182
	public Point2D getCentralPoint() {
183
		return centralPoint;
184
	}
185
	/**
186
	 * @param centralPoint The centralPoint to set.
187
	 */
188
	public void setCentralPoint(Point2D centralPoint) {
189
		this.centralPoint = centralPoint;
190
	}
191
	/**
192
	 * @return Returns the endAngle.
193
	 */
194
	public double getEndAngle() {
195
		return endAngle;
196
	}
197
	/**
198
	 * @param endAngle The endAngle to set.
199
	 */
200
	public void setEndAngle(double endAngle) {
201
		this.endAngle = endAngle;
202
	}
203
	/**
204
	 * @return Returns the initAngle.
205
	 */
206
	public double getInitAngle() {
207
		return initAngle;
208
	}
209
	/**
210
	 * @param initAngle The initAngle to set.
211
	 */
212
	public void setInitAngle(double initAngle) {
213
		this.initAngle = initAngle;
214
	}
215
	/**
216
	 * @return Returns the radius.
217
	 */
218
	public double getRadius() {
219
		return radius;
220
	}
221
	/**
222
	 * @param radius The radius to set.
223
	 */
224
	public void setRadius(double radius) {
225
		this.radius = radius;
226
	}
121 227
}
branches/v02_desarrollo/libraries/libCq CMS for java.old/src/org/cresques/px/dxf/DxfCalArcs.java
3 3
import java.awt.geom.Point2D;
4 4
import java.util.Vector;
5 5

  
6
/**
7
 * Calcula puntos sobre un arco.
8
 * @author jmorell
9
 *
10
 * TODO To change the template for this generated type comment go to
11
 * Window - Preferences - Java - Code Style - Code Templates
12
 */
6 13
public class DxfCalArcs {
7 14
	final boolean debug = true;
8 15
	
......
12 19
	double bulge;
13 20
	double d, dd, aci;
14 21
	Point2D coordAux;
22
	//private Point2D centralPoint;
15 23
	
16 24
	public DxfCalArcs(Point2D p1, Point2D p2, double bulge) {
17 25
		this.bulge = bulge;
......
113 121
		return arc;
114 122
	}
115 123
	
124
	/**
125
	 * 050301, jmorell: M?todo para obtener el punto central del arco.
126
	 * @return
127
	 */
128
	public Vector getCentralPoint() {
129
		Vector arc = new Vector();
130
		if (empieza <= acaba) {
131
			addNode(arc, (empieza+acaba)/2.0);
132
		} else {
133
			addNode(arc, empieza);
134
			double alfa = 360-empieza;
135
			double beta = acaba;
136
			double an = alfa + beta;
137
			double mid = an/2.0;
138
			if (mid<=alfa) {
139
				addNode(arc, empieza+mid);
140
			} else {
141
				addNode(arc, mid-alfa);
142
			}
143
		}
144
		return arc;
145
	}
146
	
116 147
	private void addNode(Vector arc, double angulo) {
117 148
		double yy = center.getY() + radio * Math.sin(angulo*Math.PI/180.0);
118 149
		double xx = center.getX() + radio * Math.cos(angulo*Math.PI/180.0);		
branches/v02_desarrollo/libraries/libCq CMS for java.old/src/org/cresques/px/dxf/DxfFeatureMaker.java
25 25
import java.awt.geom.GeneralPath;
26 26
import java.awt.geom.Point2D;
27 27

  
28
/**
29
 * Implementaci?n de la creaci?n de features de un DXF2000.
30
 */
28 31
public class DxfFeatureMaker implements DxfFile.EntityFactory, Projected {
29 32
	IProjection proj = null;
30 33
	//Feature lastFeature = null;
......
2410 2413
		// TODO Auto-generated method stub
2411 2414
		return null;
2412 2415
	}
2416

  
2417
	/* (non-Javadoc)
2418
	 * @see org.cresques.io.DxfFile.EntityFactory#createEllipse(org.cresques.io.DxfGroupVector)
2419
	 */
2420
	public void createEllipse(DxfGroupVector v) throws Exception {
2421
		// TODO Auto-generated method stub
2422
		
2423
	}
2413 2424
	
2414 2425
}
branches/v02_desarrollo/libraries/libCq CMS for java.old/src/org/cresques/px/dxf/DxfLayer.java
10 10

  
11 11
/**
12 12
 * Capas de dxf
13
 * 
13
 * jmorell: Actualizaci?n a la versi?n DXF2000.
14 14
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
15 15
 */
16 16

  
......
39 39
	}
40 40
	public Color getColor() { return AcadColor.getColor(colorNumber); }
41 41
	public String toDxfString() {
42
		  /*5
43
		  10
44
		  330
45
		  2
46
		  100
47
		  AcDbSymbolTableRecord
48
		  100
49
		  AcDbLayerTableRecord
50
		    2
51
		  0
52
		   70
53
		       0
54
		   62
55
		       7
56
		    6
57
		  Continuous
58
		  370
59
		      -3
60
		  390
61
		  F*/
42 62
		StringBuffer sb = new StringBuffer(LAYER.toString()+super.toDxfString());
63
		sb.append(DxfGroup.toString(5, 10));
64
		sb.append(DxfGroup.toString(100, "AcDbSymbolTableRecord"));
65
		sb.append(DxfGroup.toString(100, "AcDbLayerTableRecord"));
43 66
		sb.append(DxfGroup.toString(62, colorNumber));
44 67
		sb.append(DxfGroup.toString(6, lType));
45 68
		return sb.toString();
branches/v02_desarrollo/libraries/libCq CMS for java.old/src/org/cresques/px/dxf/DxfEntity.java
12 12

  
13 13
/**
14 14
 * Clase ancestro para las entidades de dxf
15
 * 
15
 * jmorell: Implementaci?n del handle imprescindible para el formato DXF2000.
16 16
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
17 17
 */
18 18

  
19 19
public abstract class DxfEntity extends PxObj implements Projected  {
20 20
	IProjection proj = null;
21 21
	DxfLayer layer = null;
22
	int dxfColor = 256;
23
	//int dxfColor = 0;
22
	//int dxfColor = 256;
23
	int dxfColor = 0;
24 24
	
25 25
	int entitiesFollow = 0;
26 26
	boolean space = false; // false --> model space, true paper space;
27
	
28
	private int handle;
27 29

  
28 30
	public DxfEntity(IProjection proj, DxfLayer layer) {
29 31
		setProjection(proj);
......
45 47
	}
46 48

  
47 49
	abstract public String toDxfString();
50
	/**
51
	 * @return Returns the handle.
52
	 */
53
	public int getHandle() {
54
		return handle;
55
	}
56
	/**
57
	 * @param handle The handle to set.
58
	 */
59
	public void setHandle(int handle) {
60
		this.handle = handle;
61
	}
48 62
}
branches/v02_desarrollo/libraries/libCq CMS for java.old/src/org/cresques/px/dxf/DxfLine.java
10 10
import java.awt.Graphics2D;
11 11
import java.awt.geom.GeneralPath;
12 12
import java.awt.geom.Point2D;
13
import java.util.Iterator;
13 14

  
14 15
import org.cresques.cts.ICoordTrans;
15 16
import org.cresques.cts.IProjection;
16 17
import org.cresques.geo.ViewPortData;
18
import org.cresques.io.DxfGroup;
17 19
import org.cresques.px.Extent;
18 20

  
19 21
/**
20 22
 * Linea de autocad (.dxf, .dwg)
21
 * 
23
 * jmorell: Actualizaci?n de la escritura de l?neas al formato DXF2000.
22 24
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
23 25
 */
24 26

  
......
73 75
		gp.moveTo((float)pt0.getX(), (float)pt0.getY());
74 76
		gp.lineTo((float)pt1.getX(), (float)pt1.getY());
75 77
	}
76
	/* (non-Javadoc)
77
	 * @see org.cresques.px.dxf.DxfEntity#toDxfFileString()
78
	
79
	/**
80
	 * 050222,jmorell: Escritura de l?neas en un DXF2000.
78 81
	 */
79 82
	public String toDxfString() {
80
		// TODO Auto-generated method stub
81
		return "";
83
		StringBuffer sb = null;
84
		sb = new StringBuffer( DxfGroup.toString(0, "LINE") );
85
		sb.append( DxfGroup.toString(5, getHandle()) );
86
		sb.append( DxfGroup.toString(100, "AcDbEntity") );
87
		sb.append( DxfGroup.toString(8, layer.getName()) );
88
		sb.append( DxfGroup.toString(62, dxfColor) );
89
		sb.append( DxfGroup.toString(100, "AcDbLine") );
90
		sb.append( DxfGroup.toString(10, pts[0].getX(), 6) );
91
		sb.append( DxfGroup.toString(20, pts[0].getY(), 6) );
92
		sb.append( DxfGroup.toString(11, pts[1].getX(), 6) );
93
		sb.append( DxfGroup.toString(21, pts[1].getY(), 6) );
94
		return sb.toString();
82 95
	}
83 96
	/**
84 97
	 * @return
branches/v02_desarrollo/libraries/libCq CMS for java.old/src/org/cresques/px/dxf/DxfPoint.java
11 11
import org.cresques.cts.ICoordTrans;
12 12
import org.cresques.cts.IProjection;
13 13
import org.cresques.geo.ViewPortData;
14
import org.cresques.io.DxfGroup;
14 15
import org.cresques.px.Extent;
15 16

  
16 17
/**
17 18
 * Entidad TEXT de AutoCAD
18
 * 
19
 * jmorell: Actualizaci?n de la escritura al formato DXF2000.
19 20
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
20 21
 */
21 22
public class DxfPoint extends DxfEntity {
22 23
	
23
	Point2D pt;
24
	private Point2D pt;
24 25
	
25 26
	public DxfPoint(IProjection proj, DxfLayer layer) {
26 27
		super(proj, layer);
......
64 65
		//g.setTransform(msave);
65 66
	}
66 67

  
67
	/* (non-Javadoc)
68
	 * @see org.cresques.px.dxf.DxfEntity#toDxfFileString()
68
	/**
69
	 * 050221, jmorell: Escritura de puntos en un DXF2000.
69 70
	 */
70 71
	public String toDxfString() {
71
		// TODO Auto-generated method stub
72
		return "";
72
		StringBuffer sb = null;
73
		sb = new StringBuffer( DxfGroup.toString(0, "POINT") );
74
		sb.append( DxfGroup.toString(5, getHandle()) );
75
		sb.append( DxfGroup.toString(100, "AcDbEntity") );
76
		sb.append( DxfGroup.toString(8, layer.getName()) );
77
		sb.append( DxfGroup.toString(62, dxfColor) );
78
		sb.append( DxfGroup.toString(100, "AcDbPoint") );
79
		sb.append( DxfGroup.toString(10, pt.getX(), 6) );
80
		sb.append( DxfGroup.toString(20, pt.getY(), 6) );
81
		sb.append( DxfGroup.toString(30, 0.0, 6) );
82
		return sb.toString();
73 83
	}
84
	/**
85
	 * @return Returns the pt.
86
	 */
87
	public Point2D getPt() {
88
		return pt;
89
	}
74 90
}
branches/v02_desarrollo/libraries/libCq CMS for java.old/src/org/cresques/px/dxf/DxfPolyline.java
21 21

  
22 22
/**
23 23
 * Polilynea de autocad
24
 * 
24
 * jmorell: Implementaci?n extra de bulges necesaria para el piloto de CAD.
25 25
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
26 26
 */
27 27

  
......
33 33
	int flags = 0;
34 34
	boolean closed = false;
35 35
	boolean hasFaces = false;
36
	private Vector bulges;
36 37
	
37 38
	public DxfPolyline(IProjection proj, DxfLayer layer) {
38 39
		super(proj, layer);
39 40
		extent = new Extent();
40 41
		pts = new Vector();
42
		bulges = new Vector();
41 43
	}
42 44

  
43 45
	public void add(Point2D pt) {
......
45 47
		extent.add(pt);
46 48
	}
47 49
	
50
	/**
51
	 * 050301, jmorell: Soluci?n provisional para implementar la lectura de polil?neas
52
	 * con arcos.
53
	 * @param pt
54
	 */
55
	public void addBulge(Double bulge) {
56
		bulges.add(bulge);
57
	}
58
	
48 59
	public void addFace(int [] face) {
49 60
		hasFaces = true;
50 61
		if (faces == null)
......
145 156
	public String toDxfString() {
146 157
		StringBuffer sb = null;
147 158
		sb = new StringBuffer( DxfGroup.toString(0, "POLYLINE") );
159
		sb.append( DxfGroup.toString(5, getHandle()) );
160
		sb.append( DxfGroup.toString(100, "AcDbEntity") );
148 161
		sb.append( DxfGroup.toString(8, layer.getName()) );
149 162
		sb.append( DxfGroup.toString(62, dxfColor) );
163
		sb.append( DxfGroup.toString(100, "AcDb2dPolyline") );
150 164
		sb.append( DxfGroup.toString(70, flags) );
151 165
		sb.append( DxfGroup.toString(66, 1) );
152 166
		Point2D pt = null;
153 167
		Iterator iter = pts.iterator();
168
		System.out.println("pts.size() = " + pts.size());
154 169
		while (iter.hasNext()) {
155 170
			pt = (Point2D) iter.next();
156 171
			sb.append( DxfGroup.toString(0, "VERTEX") );
172
			sb.append( DxfGroup.toString(5, getHandle()) );
173
			sb.append( DxfGroup.toString(100, "AcDbEntity") );
157 174
			sb.append( DxfGroup.toString(8, layer.getName()) );
175
			sb.append( DxfGroup.toString(100, "AcDbVertex") );
176
			sb.append( DxfGroup.toString(100, "AcDb2dVertex") );
158 177
			sb.append( DxfGroup.toString(10, pt.getX(), 6) );
159 178
			sb.append( DxfGroup.toString(20, pt.getY(), 6) );
160 179
			sb.append( DxfGroup.toString(30, 0.0, 6) );
161 180
		}
162 181
		sb.append( DxfGroup.toString(0, "SEQEND") );
182
		sb.append( DxfGroup.toString(5, getHandle()) );
183
		sb.append( DxfGroup.toString(100, "AcDbEntity") );
163 184
		sb.append( DxfGroup.toString(8, layer.getName()) );
164 185
		return sb.toString();
165 186
	}
......
181 202
		return new DxfCalArcs(coord1, coord2, bulge).getPoints(1);
182 203
	}
183 204

  
205
	/**
206
	 * @return Returns the pts.
207
	 */
208
	public Vector getPts() {
209
		return pts;
210
	}
211
	/**
212
	 * @param pts The pts to set.
213
	 */
214
	public void setPts(Vector pts) {
215
		this.pts = pts;
216
	}
217
	/**
218
	 * @return Returns the bulges.
219
	 */
220
	public Vector getBulges() {
221
		return bulges;
222
	}
223
	/**
224
	 * @param bulges The bulges to set.
225
	 */
226
	public void setBulges(Vector bulges) {
227
		this.bulges = bulges;
228
	}
184 229
}
branches/v02_desarrollo/libraries/libCq CMS for java.old/src/org/cresques/px/dxf/DxfEntityMaker.java
13 13
import org.cresques.px.Extent;
14 14
import org.cresques.px.IObjList;
15 15
import org.cresques.px.PxObj;
16
//import org.cresques.px.gml.Feature;
17 16

  
17
/**
18
 * jmorell: Implementaci?n de la creaci?n de entidades DXF2000.
19
 */
18 20
public class DxfEntityMaker implements DxfFile.EntityFactory, Projected {
19 21
	IProjection proj = null;
20 22
	DxfEntity lastEntity = null;
......
69 71
	public void createPolyline(DxfGroupVector grp) throws Exception {
70 72
		DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
71 73
		DxfPolyline entity = new DxfPolyline(proj, layer);
72
		
74
		if (grp.hasCode(5)) {
75
			String hexS = grp.getDataAsString(5);
76
			Integer hexI = Integer.decode("0x" + hexS);
77
			int hexi = hexI.intValue();
78
			entity.setHandle(hexi);
79
		} else {
80
			entity.setHandle(entities.size()+40);
81
		}
82

  
73 83
		double x = 0.0, y = 0.0, z = 0.0;
74 84
		double thickness = 0;
75 85
		
......
122 132
				bulge = 0.0;
123 133
			}
124 134
		}
135
		//lastEntity.setHandle(entities.size()+40);
125 136
		if (addingToBlock == false) {
126 137
			//System.out.println("createPolyline: A?adimos una polilinea a la lista de entidades");
127 138
			entities.add(lastEntity);
......
214 225
			}
215 226
			bulge = bulge_aux;			
216 227
		}
228
		/*if (grp.hasCode(5)) {
229
			String hexS = grp.getDataAsString(5);
230
			Integer hexI = Integer.decode("0x" + hexS);
231
			int hexi = hexI.intValue();
232
			lastEntity.setHandle(hexi);
233
		} else {
234
			lastEntity.setHandle(entities.size()+40);
235
		}*/
217 236
	}
218 237
	
219 238
	public void createLwPolyline(DxfGroupVector grp) throws Exception {
......
224 243
			elev = grp.getDataAsDouble(38);
225 244
		DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
226 245
		DxfLwPolyline entity = new DxfLwPolyline(proj, layer);
246
		if (grp.hasCode(5)) {
247
			String hexS = grp.getDataAsString(5);
248
			Integer hexI = Integer.decode("0x" + hexS);
249
			int hexi = hexI.intValue();
250
			entity.setHandle(hexi);
251
		} else {
252
			entity.setHandle(entities.size()+40);
253
		}
254
		double bulge = 0;
255
		boolean isNewCoord = false;
227 256
		for (int i=0; i<grp.size(); i++) {
257
			bulge = 0;
258
			isNewCoord = false;
228 259
			g = (DxfGroup) grp.get(i);
229
			if (g.getCode() == 10)
260
			if (g.getCode() == 10) {
230 261
				x = ((Double) g.getData()).doubleValue();
231
			else if (g.getCode() == 20) {
262
			} else if (g.getCode() == 20) {
232 263
				y = ((Double) g.getData()).doubleValue();
233 264
				//if (y <= 1.0) throw new Exception("Y == "+y);
234 265
				entity.add( proj.createPoint( x, y ) );
266
				entity.addBulge(new Double(0));
235 267
				x = 0.0; y = 0.0;
268
				isNewCoord = true;
269
			} else if (g.getCode() == 42) {
270
				//entity.addBulge((Double)g.getData());
271
				entity.getBulges().remove(entity.getBulges().size()-1);
272
				entity.getBulges().add((Double)g.getData());
273
				bulge = ((Double) g.getData()).doubleValue();
236 274
			}
275
			/*if (bulge == 0 && isNewCoord) {
276
				entity.addBulge(new Double(0));
277
			}*/
237 278
		}
279
		System.out.println("entity.getPts().size() = " + entity.getPts().size());
280
		System.out.println("entity.getBulges().size() = " + entity.getBulges().size());
238 281
		if (grp.hasCode(62)) {
239 282
			entity.dxfColor = grp.getDataAsInt(62);
240 283
		} else {
241 284
			//entity.dxfColor = 0;
242 285
		}
243
		if (grp.hasCode(70))
286
		if (grp.hasCode(70)) {
244 287
			entity.flags = grp.getDataAsInt(70);
288
			System.out.println("entity.flags = " + entity.flags);
289
		}
245 290
		if ((entity.flags & 0x01) == 0x01) {
246 291
			entity.closed = true;
247 292
		}
......
280 325
		pt1.setLocation(point_out1);
281 326
		pt2.setLocation(point_out2);
282 327
		DxfLine entity = new DxfLine(proj, layer, pt1, pt2);
328
		if (grp.hasCode(5)) {
329
			String hexS = grp.getDataAsString(5);
330
			Integer hexI = Integer.decode("0x" + hexS);
331
			int hexi = hexI.intValue();
332
			entity.setHandle(hexi);
333
		} else {
334
			entity.setHandle(entities.size()+40);
335
		}
283 336
		if (grp.hasCode(62)) {
284 337
			entity.dxfColor = grp.getDataAsInt(62);
285 338
		} else {
......
344 397
		DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
345 398

  
346 399
		DxfPoint entity = new DxfPoint(proj, layer);
400
		
401
		if (grp.hasCode(5)) {
402
			String hexS = grp.getDataAsString(5);
403
			Integer hexI = Integer.decode("0x" + hexS);
404
			int hexi = hexI.intValue();
405
			entity.setHandle(hexi);
406
		} else {
407
			entity.setHandle(entities.size()+40);
408
		}
347 409

  
348 410
		x = grp.getDataAsDouble(10);
349 411
		y = grp.getDataAsDouble(20);
......
405 467
			}
406 468
		}
407 469
		DxfCircle entity = new DxfCircle(proj, layer, pts);
470
		if (grp.hasCode(5)) {
471
			String hexS = grp.getDataAsString(5);
472
			Integer hexI = Integer.decode("0x" + hexS);
473
			int hexi = hexI.intValue();
474
			entity.setHandle(hexi);
475
		} else {
476
			entity.setHandle(entities.size()+40);
477
		}
478
		entity.setCenter(new Point2D.Double(x,y));
479
		entity.setRadius(r);
408 480
		if (grp.hasCode(62)) {
409 481
			entity.dxfColor = grp.getDataAsInt(62);
410 482
		} else {
......
418 490
			blk.add(entity);
419 491
		}
420 492
	}
493
	public void createEllipse(DxfGroupVector grp) throws Exception {
494
		double incX = 0.0, incY = 0.0, incZ = 0.0;
495
		double xc = 0.0, yc = 0.0, zc = 0.0;
496
		double mMAxisRatio = 0.0;
497
		DxfGroup g = null;
498
		DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
499

  
500
		xc = grp.getDataAsDouble(10);
501
		yc = grp.getDataAsDouble(20);
502
		if (grp.hasCode(30)) zc = grp.getDataAsDouble(30);
503
		incX = grp.getDataAsDouble(11);
504
		incY = grp.getDataAsDouble(21);
505
		if (grp.hasCode(30)) incZ = grp.getDataAsDouble(31);
506
		if (grp.hasCode(40)) mMAxisRatio = grp.getDataAsDouble(40);
507
		
508
		Point2D pt2 = new Point2D.Double(xc+incX, yc+incY);
509
		Point2D pt1 = new Point2D.Double(xc-incX, yc-incY);
510
		double majorAxisLength = pt1.distance(pt2);
511
		double minorAxisLength = majorAxisLength*mMAxisRatio;
512
		
513
		DxfEllipse entity = new DxfEllipse(proj, layer, pt1, pt2, minorAxisLength);
514
		if (grp.hasCode(5)) {
515
			String hexS = grp.getDataAsString(5);
516
			Integer hexI = Integer.decode("0x" + hexS);
517
			int hexi = hexI.intValue();
518
			entity.setHandle(hexi);
519
		} else {
520
			entity.setHandle(entities.size()+40);
521
		}
522
		if (grp.hasCode(62)) {
523
			entity.dxfColor = grp.getDataAsInt(62);
524
		} else {
525
			//entity.dxfColor = 0;
526
		}
527
		if (addingToBlock == false) {
528
			//System.out.println("createCircle(): A?ade un circulo a la lista de entidades");
529
			entities.add(entity);
530
		} else {
531
			//System.out.println("createCircle(): A?adimos un circulo al bloque " + iterator);
532
			blk.add(entity);
533
		}
534
	}
421 535
	public void createArc(DxfGroupVector grp) throws Exception {
422 536
		double x = 0.0, y = 0.0, z = 0.0;
423 537
		double r = 0.0, empieza = 0.0, acaba = 0.0;
......
476 590
			pts[(360-iempieza)+iacaba+1] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
477 591
		}
478 592
		DxfArc entity = new DxfArc(proj, layer, pts);
593
		if (grp.hasCode(5)) {
594
			String hexS = grp.getDataAsString(5);
595
			Integer hexI = Integer.decode("0x" + hexS);
596
			int hexi = hexI.intValue();
597
			entity.setHandle(hexi);
598
		} else {
599
			entity.setHandle(entities.size()+40);
600
		}
601
		// 050223, jmorell: Establecimiento de los par?metros del arco.
602
		entity.setCentralPoint(pts[(pts.length)/2]);
603
		entity.setInit(pts[0]);
604
		entity.setEnd(pts[pts.length-1]);
605
		entity.setCenter(center);
606
		entity.setRadius(r);
607
		entity.setInitAngle(empieza);
608
		entity.setEndAngle(acaba);
479 609
		if (grp.hasCode(62)) {
480 610
			entity.dxfColor = grp.getDataAsInt(62);
481 611
		} else {
......
872 1002
				if (addingToBlock == false) entities.add(dxfLwPolylinee);
873 1003
			} else if (dxfEntity instanceof DxfPoint) {
874 1004
				dxfPoint = (DxfPoint)dxfEntity;
875
				point1 = dxfPoint.pt;
1005
				point1 = dxfPoint.getPt();
876 1006
				//point11.setLocation(entity.pt.getX() - entity.block.bPoint.getX() + ((point1.getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + point1.getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - entity.block.bPoint.getY() + ((point1.getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + point1.getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
877 1007
				point11.setLocation(entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((point1.getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + point1.getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((point1.getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + point1.getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
878 1008
				//point11.setLocation(entity.pt.getX() + ((point1.getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + point1.getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() + ((point1.getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + point1.getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
879 1009
				DxfPoint dxfPointt = new DxfPoint(proj, layer);
880
				dxfPointt.pt = point11;
1010
				//dxfPointt.pt = point11;
1011
				dxfPointt.setPt(point11);
881 1012
				if (addingToBlock == false) entities.add(dxfPointt);
882 1013
			} else if (dxfEntity instanceof DxfText) {
883 1014
				dxfText = (DxfText)dxfEntity;
branches/v02_desarrollo/libraries/libCq CMS for java.old/src/org/cresques/px/dxf/DxfEllipse.java
1
package org.cresques.px.dxf;
2

  
3
import java.awt.Color;
4
import java.awt.Graphics2D;
5
import java.awt.geom.GeneralPath;
6
import java.awt.geom.Point2D;
7
import java.awt.geom.Line2D;
8

  
9
import org.cresques.cts.ICoordTrans;
10
import org.cresques.cts.IProjection;
11
import org.cresques.geo.ViewPortData;
12
import org.cresques.io.DxfGroup;
13
import org.cresques.px.Extent;
14

  
15
/**
16
 * Entidad ELLIPSE de AutoCAD. Implementaci?n b?sica para el piloto de CAD sobre el
17
 * formato DXF2000.
18
 * 
19
 * @author jmorell
20
 */
21
public class DxfEllipse extends DxfEntity {
22
	final static Color baseColor = new Color(69, 106, 121);
23
	//Vector points = null;
24
	GeneralPath gp = null;
25
	boolean closed = true;
26
	Point2D [] pts;
27
	private double minorAxisLength;
28
	private Point2D center;
29
	private double minorToMajorAxisRatio;
30
	
31
	public DxfEllipse(IProjection proj, DxfLayer layer, Point2D pt1, Point2D pt2, double minorAxisLength) {
32
		super(proj, layer);
33
		pts = new Point2D[2];
34
		pts[0] = pt1;
35
		pts[1] = pt2;
36
		this.minorAxisLength = minorAxisLength;
37
		extent = new Extent();
38
		for (int i=0; i<pts.length; i++) {
39
			extent.add(pts[i]);
40
		}
41
		center = new Point2D.Double((pts[0].getX()+pts[1].getX())/2.0, (pts[0].getY()+pts[1].getY())/2.0);
42
		double majorAxisLength = pt1.distance(pt2);
43
		System.out.println("minorAxisLength = " + minorAxisLength);
44
		System.out.println("majorAxisLength = " + majorAxisLength);
45
		minorToMajorAxisRatio = minorAxisLength/majorAxisLength;
46
	}
47
	
48
	private Color color = baseColor; //Color(255,214,132,255);
49
	
50
	public Color c() {return color;}
51
	public Color c(Color color) {this.color = color; return color;}
52
	
53
	public void reProject(ICoordTrans rp) {
54
		Point2D [] savePts = pts;
55

  
56
		pts = new Point2D[savePts.length];
57
		extent = new Extent();
58
		Point2D ptDest = null;
59
		for (int i=0; i<savePts.length; i++) {
60
			ptDest = rp.getPDest().createPoint(0.0,0.0);
61
			ptDest = rp.convert((Point2D) savePts[i], ptDest);
62
			this.pts[i] = ptDest;
63
			extent.add(ptDest);
64
		}
65
		setProjection(rp.getPDest());
66
	}
67
	
68
	public void draw(Graphics2D g, ViewPortData vp) {
69
		//System.out.println("Va a pintar un circle");
70
		Color color = null;
71
		if (dxfColor == AcadColor.BYLAYER)
72
			//g.setColor(layer.getColor());
73
			color = layer.getColor();
74
		else
75
			//g.setColor(AcadColor.getColor(dxfColor));
76
			color = AcadColor.getColor(dxfColor);
77
		newGP(vp);
78
		if (closed) {
79
			g.setColor(new Color(color.getRed(), color.getBlue(), color.getGreen(), 0x80));
80
			g.fill(gp);
81
		} 
82
		g.setColor(color);
83
		g.draw(gp);
84
	}
85
	
86
	private void newGP(ViewPortData vp) {
87
		//if (gp != null) return;
88
		gp = new GeneralPath();
89
		Point2D pt0 = null, pt=null, pt1=null;
90
		Point2D.Double ptTmp = new Point2D.Double(0.0, 0.0);
91
		//System.out.println("pts.length = " + pts.length);
92
		for (int i=0; i<pts.length; i++) {
93
			pt1 = (Point2D)pts[i];
94
			vp.mat.transform(pt1, ptTmp);
95
			if (pt0 == null) { 
96
				pt0 = ptTmp;
97
				gp.moveTo((float)ptTmp.getX(), (float)ptTmp.getY());
98
			} else {
99
				gp.lineTo((float)ptTmp.getX(), (float)ptTmp.getY());
100
			}			
101
		}
102
		if (closed) {
103
			gp.closePath();			
104
		}
105
	}
106
	
107
	public String toDxfString() {
108
		StringBuffer sb = null;
109
		sb = new StringBuffer( DxfGroup.toString(0, "ELLIPSE") );
110
		sb.append( DxfGroup.toString(5, getHandle()) );
111
		sb.append( DxfGroup.toString(100, "AcDbEntity") );
112
		sb.append( DxfGroup.toString(8, layer.getName()) );
113
		sb.append( DxfGroup.toString(62, dxfColor) );
114
		sb.append( DxfGroup.toString(100, "AcDbEllipse") );
115
		sb.append( DxfGroup.toString(10, getCenter().getX(), 6));
116
		sb.append( DxfGroup.toString(20, getCenter().getY(), 6) );
117
		sb.append( DxfGroup.toString(30, 0.0, 6) );
118
		sb.append( DxfGroup.toString(11, pts[1].getX()-getCenter().getX(), 6));
119
		sb.append( DxfGroup.toString(21, pts[1].getY()-getCenter().getY(), 6) );
120
		sb.append( DxfGroup.toString(31, 0.0, 6) );
121
		sb.append( DxfGroup.toString(40, getMinorToMajorAxisRatio(), 6));
122
		sb.append( DxfGroup.toString(41, 0.0, 6) );
123
		sb.append( DxfGroup.toString(42, 2*Math.PI, 6) );
124
		return sb.toString();
125
	}
126
	/**
127
	 * @return
128
	 */
129
	public Point2D[] getPts() {
130
		return pts;
131
	}
132
	
133
	/**
134
	 * @return
135
	 */
136
	/*public GeneralPath getGeneralPath(ViewPort vp) {
137
		newGP(vp);
138
		return (GeneralPath) gp.clone();
139
	}*/
140

  
141
	/**
142
	 * @return Returns the minorAxisLength.
143
	 */
144
	public double getMinorAxisLength() {
145
		return minorAxisLength;
146
	}
147
	/**
148
	 * @param minorAxisLength The minorAxisLength to set.
149
	 */
150
	public void setMinorAxisLength(double minorAxisLength) {
151
		this.minorAxisLength = minorAxisLength;
152
	}
153
	/**
154
	 * @param pts The pts to set.
155
	 */
156
	public void setPts(Point2D[] pts) {
157
		this.pts = pts;
158
	}
159
	/**
160
	 * @return Returns the center.
161
	 */
162
	public Point2D getCenter() {
163
		return center;
164
	}
165
	/**
166
	 * @param center The center to set.
167
	 */
168
	public void setCenter(Point2D center) {
169
		this.center = center;
170
	}
171
	/**
172
	 * @return Returns the majorToMinorAxisRatio.
173
	 */
174
	public double getMinorToMajorAxisRatio() {
175
		return minorToMajorAxisRatio;
176
	}
177
	/**
178
	 * @param majorToMinorAxisRatio The majorToMinorAxisRatio to set.
179
	 */
180
	public void setMinorToMajorAxisRatio(double majorToMinorAxisRatio) {
181
		this.minorToMajorAxisRatio = majorToMinorAxisRatio;
182
	}
183
}
0 184

  
branches/v02_desarrollo/libraries/libCq CMS for java.old/src/org/cresques/px/dxf/DxfLwPolyline.java
5 5

  
6 6
import java.awt.geom.Point2D;
7 7
import java.util.Iterator;
8
import java.util.Vector;
8 9

  
9 10
import org.cresques.cts.IProjection;
10 11
import org.cresques.io.DxfGroup;
11 12

  
12 13
/**
13 14
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
15
 * jmorell: Escritura de LwPolylines en formato DXF2000 con arcos.
14 16
 */
15 17
public class DxfLwPolyline extends DxfPolyline {
16 18
	public DxfLwPolyline(IProjection proj, DxfLayer layer) {
17 19
		super(proj, layer);
18 20
	}
19

  
20
	/* (non-Javadoc)
21
	 * @see org.cresques.px.dxf.DxfEntity#toDxfFileString()
21
	/**
22
	 * jmorell: Escritura de LwPolylines en formato DXF2000 con arcos.
22 23
	 */
23 24
	public String toDxfString() {
24 25
		StringBuffer sb = null;
25 26
		sb = new StringBuffer( DxfGroup.toString(0, "LWPOLYLINE") );
27
		sb.append( DxfGroup.toString(5, getHandle()) );
28
		sb.append( DxfGroup.toString(100, "AcDbEntity") );
26 29
		sb.append( DxfGroup.toString(8, layer.getName()) );
27 30
		sb.append( DxfGroup.toString(62, dxfColor) );
28 31
		sb.append( DxfGroup.toString(100, "AcDbPolyline") );
32
		sb.append( DxfGroup.toString(70, flags) );
29 33
		sb.append( DxfGroup.toString(90, pts.size()) );
30 34
		Point2D pt = null;
31
		Iterator iter = pts.iterator();
35
		double bulge;
36
		Vector bulges = getBulges();
37
		/*Iterator iter = pts.iterator();
32 38
		while (iter.hasNext()) {
33 39
			pt = (Point2D) iter.next();
34 40
			sb.append( DxfGroup.toString(10, pt.getX(), 6) );
35 41
			sb.append( DxfGroup.toString(20, pt.getY(), 6) );
42
		}*/
43
		for (int i=0;i<pts.size();i++) {
44
			pt = (Point2D)pts.get(i);
45
			bulge = ((Double)bulges.get(i)).doubleValue();
46
			sb.append( DxfGroup.toString(10, pt.getX(), 6) );
47
			sb.append( DxfGroup.toString(20, pt.getY(), 6) );
48
			sb.append( DxfGroup.toString(42, bulge, 6) );
36 49
		}
37 50
		return sb.toString();
38 51
	}

Also available in: Unified diff