Revision 10820 trunk/libraries/libDwg/src/com/iver/cit/jdwglib/dwg/objects/DwgPFacePolyline.java
DwgPFacePolyline.java | ||
---|---|---|
42 | 42 |
* dac@iver.es |
43 | 43 |
*/ |
44 | 44 |
/* CVS MESSAGES: |
45 |
* |
|
46 |
* $Id$ |
|
47 |
* $Log$ |
|
48 |
* Revision 1.2 2007-03-06 19:39:38 azabala |
|
49 |
* Changes to adapt dwg 12 to general architecture |
|
50 |
* |
|
51 |
* Revision 1.1 2007/03/01 19:58:53 azabala |
|
52 |
* refactor of pface and mesh names |
|
53 |
* |
|
54 |
* Revision 1.2 2007/02/07 12:44:27 fdiaz |
|
55 |
* A?adido o modificado el metodo clone para que el DwgObject se encargue de las propiedades comunes a todos los objetos. |
|
56 |
* A?adido el metodo fill. |
|
57 |
* |
|
58 |
* Revision 1.1 2007/02/05 07:03:22 azabala |
|
59 |
* *** empty log message *** |
|
60 |
* |
|
61 |
* |
|
62 |
*/ |
|
45 |
* |
|
46 |
* $Id$ |
|
47 |
* $Log$ |
|
48 |
* Revision 1.3 2007-03-20 19:57:08 azabala |
|
49 |
* source code cleaning |
|
50 |
* |
|
51 |
* Revision 1.2 2007/03/06 19:39:38 azabala |
|
52 |
* Changes to adapt dwg 12 to general architecture |
|
53 |
* |
|
54 |
* Revision 1.1 2007/03/01 19:58:53 azabala |
|
55 |
* refactor of pface and mesh names |
|
56 |
* |
|
57 |
* Revision 1.2 2007/02/07 12:44:27 fdiaz |
|
58 |
* A?adido o modificado el metodo clone para que el DwgObject se encargue de las propiedades comunes a todos los objetos. |
|
59 |
* A?adido el metodo fill. |
|
60 |
* |
|
61 |
* Revision 1.1 2007/02/05 07:03:22 azabala |
|
62 |
* *** empty log message *** |
|
63 |
* |
|
64 |
* |
|
65 |
*/ |
|
63 | 66 |
package com.iver.cit.jdwglib.dwg.objects; |
64 | 67 |
|
68 |
import java.awt.geom.Point2D; |
|
65 | 69 |
import java.util.ArrayList; |
66 | 70 |
import java.util.List; |
71 |
import java.util.Map; |
|
67 | 72 |
|
68 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
73 |
import com.iver.cit.gvsig.fmap.core.FGeometryCollection; |
|
74 |
import com.iver.cit.gvsig.fmap.core.FPolygon3D; |
|
75 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
76 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
|
69 | 77 |
import com.iver.cit.jdwglib.dwg.DwgFile; |
70 | 78 |
import com.iver.cit.jdwglib.dwg.DwgHandleReference; |
71 | 79 |
import com.iver.cit.jdwglib.dwg.DwgObject; |
72 | 80 |
import com.iver.cit.jdwglib.dwg.IDwg2FMap; |
81 |
import com.iver.cit.jdwglib.dwg.IDwgBlockMember; |
|
73 | 82 |
import com.iver.cit.jdwglib.dwg.IDwgPolyline; |
74 | 83 |
import com.iver.cit.jdwglib.dwg.IDwgVertex; |
84 |
import com.iver.cit.jdwglib.util.FMapUtil; |
|
75 | 85 |
|
76 | 86 |
/** |
77 | 87 |
* This DWG entity is a "Polyface Mesh". |
78 | 88 |
* |
79 |
* */ |
|
89 |
*/ |
|
90 |
|
|
91 |
/* |
|
92 |
* azabala DXF 12 spec says: "If the Vertex defines a face of the mesh, its |
|
93 |
* Vertex flags (70) group has the 128 bit set but not the 64 bit. The 10, 20, |
|
94 |
* and 30 (location) groups of the face entity are irrelevant and are always |
|
95 |
* written as zero in a DXF file. |
|
96 |
* |
|
97 |
* The vertex indexes that define the mesh are given by 71, 72, 73, and 74 |
|
98 |
* groups, the values of which are integers specifying one of the previously |
|
99 |
* defined vertices by index. |
|
100 |
* |
|
101 |
* If the index is negative, the edge that begins with that vertex is invisible. |
|
102 |
* |
|
103 |
* The first zero vertex marks the end of the vertices of the face. |
|
104 |
* |
|
105 |
* Since the 71 through 74 groups are optional fields with default values of |
|
106 |
* zero, they are present in DXF only if nonzero." |
|
107 |
* |
|
108 |
* But DWG 12 spec doesnt say anything about 71,72,73 and 74 fields for VERTEX. |
|
109 |
*/ |
|
80 | 110 |
public class DwgPFacePolyline extends DwgObject |
81 |
implements IDwgPolyline, IDwg2FMap{ |
|
111 |
implements IDwgPolyline, IDwg2FMap, IDwgBlockMember{ |
|
112 |
|
|
113 |
public static final int NUM_VERTEX_OF_FACE = 4; |
|
114 |
|
|
115 |
|
|
82 | 116 |
/** |
83 |
* number of vertices in the mesh |
|
84 |
* */ |
|
117 |
* number of vertices in the mesh (as it is readed from the dwg file... very |
|
118 |
* often is wrong) |
|
119 |
*/ |
|
85 | 120 |
private int vertexCount; |
86 | 121 |
/** |
87 |
* number of faces of the mesh |
|
88 |
* */ |
|
122 |
* number of faces of the mesh (as it is readed from the dwg file... very |
|
123 |
* often is wrong) |
|
124 |
*/ |
|
89 | 125 |
private int faceCount; |
90 | 126 |
|
91 | 127 |
|
... | ... | |
93 | 129 |
private DwgHandleReference lastVertexHandle; |
94 | 130 |
private DwgHandleReference seqendHandle; |
95 | 131 |
|
132 |
/** |
|
133 |
* Collection of all the vertices of the polyface mesh |
|
134 |
*/ |
|
96 | 135 |
private List vertices; |
136 |
/** |
|
137 |
* Collection of all the faces of the polyface mesh, whose vertices are in |
|
138 |
* vertices List. |
|
139 |
*/ |
|
140 |
private List faces; |
|
97 | 141 |
|
98 | 142 |
/** |
99 | 143 |
* Constructor |
100 |
* */
|
|
144 |
*/ |
|
101 | 145 |
public DwgPFacePolyline(int index) { |
102 | 146 |
super(index); |
103 | 147 |
vertices = new ArrayList(); |
148 |
faces = new ArrayList(); |
|
104 | 149 |
} |
105 | 150 |
|
106 | 151 |
public void setVertexCount(int vertexCount) { |
... | ... | |
142 | 187 |
public int getVertexCount() { |
143 | 188 |
return vertexCount; |
144 | 189 |
} |
190 |
|
|
145 | 191 |
public Object clone(){ |
146 | 192 |
DwgPFacePolyline obj = new DwgPFacePolyline(index); |
147 | 193 |
this.fill(obj); |
... | ... | |
151 | 197 |
protected void fill(DwgObject obj){ |
152 | 198 |
super.fill(obj); |
153 | 199 |
DwgPFacePolyline myObj = (DwgPFacePolyline)obj; |
154 |
|
|
155 | 200 |
myObj.setFaceCount(faceCount); |
156 | 201 |
myObj.setFirstVertexHandle(firstVertexHandle); |
157 | 202 |
myObj.setLastVertexHandle(lastVertexHandle); |
158 | 203 |
myObj.setSeqendHandle(seqendHandle); |
159 | 204 |
myObj.setVertexCount(vertexCount); |
205 |
myObj.setVertices(this.vertices); |
|
206 |
myObj.setFaces(this.faces); |
|
160 | 207 |
|
161 | 208 |
} |
162 | 209 |
|
210 |
public void setFaces(List faces) { |
|
211 |
this.faces = faces; |
|
212 |
} |
|
213 |
|
|
214 |
public List getFaces(){ |
|
215 |
return this.faces; |
|
216 |
} |
|
217 |
|
|
163 | 218 |
public List getVertices() { |
164 | 219 |
return vertices; |
165 | 220 |
} |
... | ... | |
169 | 224 |
} |
170 | 225 |
|
171 | 226 |
public void calculateGisModel(DwgFile dwgFile) { |
172 |
/* |
|
173 |
/* |
|
174 |
int flags = getFlags(); |
|
175 |
// En estas dos lineas de abajo y en el resto del metodo |
|
176 |
// se mantiene el mecanismo anterior al refactoring. |
|
177 |
// TODO: Pensar si deberiamos coger el handle completo. |
|
178 |
// Tal vez deberiamos tomar el handle completo y evaluar |
|
179 |
// a donde apuntan (pueden haber 2 handles con codigo y offset |
|
180 |
// distintos y que, sin embargo apunten al mismo objeto). |
|
181 |
int firstHandle = getFirstVertexHandle().getOffset(); |
|
182 |
int lastHandle = getLastVertexHandle().getOffset(); |
|
183 |
ArrayList pts = new ArrayList(); |
|
184 |
ArrayList bulges = new ArrayList(); |
|
185 |
double[] pt = new double[3]; |
|
186 |
double bulge = 0d; |
|
187 |
|
|
188 |
DwgObject first = dwgFile.getDwgObjectFromHandle(firstHandle); |
|
189 |
DwgObject last = dwgFile.getDwgObjectFromHandle(lastHandle); |
|
190 |
if(first == null || last == null){ |
|
191 |
System.out.println("Polyline2D con vertices inicial o final a null"); |
|
192 |
return; |
|
193 |
} |
|
194 |
|
|
195 |
if(!(first instanceof DwgVertex2D)){ |
|
196 |
System.out.println("El primer vertice de Polyline2D es "+ |
|
197 |
first.getClass().getName()); |
|
198 |
return; |
|
199 |
} |
|
200 |
|
|
201 |
if(!(last instanceof DwgVertex2D)){ |
|
202 |
System.out.println("El primer vertice de Polyline2D es "+ |
|
203 |
first.getClass().getName()); |
|
204 |
return; |
|
205 |
} |
|
206 |
|
|
207 |
int firstObjIdx = dwgFile.getIndexOf(first); |
|
208 |
int lastObjIdx = dwgFile.getIndexOf(last); |
|
209 |
if(firstObjIdx == -1 || lastObjIdx == -1){ |
|
210 |
System.out.println("Calculate GIS Model: Problemas en la LinkedList: 1?="+firstObjIdx+",Ultimo="+lastObjIdx); |
|
211 |
return; |
|
212 |
} |
|
213 |
|
|
214 |
// pt = ((DwgVertex2D)first).getPoint(); |
|
215 |
// pts.add(new Point2D.Double(pt[0], pt[1])); |
|
216 |
// bulge = ((DwgVertex2D)first).getBulge(); |
|
217 |
// bulges.add(new Double(bulge)); |
|
218 |
|
|
219 |
for(int i = firstObjIdx; i <= lastObjIdx; i++){ |
|
220 |
DwgObject obj = dwgFile.getDwgObject(i); |
|
221 |
if(obj instanceof DwgVertex2D){ |
|
222 |
DwgVertex2D vertex = (DwgVertex2D) obj; |
|
223 |
pt = vertex.getPoint(); |
|
224 |
pts.add(new Point2D.Double(pt[0], pt[1])); |
|
225 |
bulge = vertex.getBulge(); |
|
226 |
bulges.add(new Double(bulge)); |
|
227 |
}else{ |
|
228 |
System.out.println("Encontrado "+obj.getClass().getName()+" en la lista de vertices de Polyline2D"); |
|
229 |
} |
|
230 |
}//for |
|
231 |
|
|
232 |
if (pts.size()>0) { |
|
233 |
Point2D[] newPts = new Point2D[pts.size()]; |
|
234 |
if ((flags & 0x1)==0x1) { |
|
235 |
newPts = new Point2D[pts.size()+1]; |
|
236 |
for (int j=0;j<pts.size();j++) { |
|
237 |
newPts[j] = (Point2D)pts.get(j); |
|
238 |
} |
|
239 |
newPts[pts.size()] = (Point2D)pts.get(0); |
|
240 |
bulges.add(new Double(0)); |
|
241 |
} else { |
|
242 |
for (int j=0;j<pts.size();j++) { |
|
243 |
newPts[j] = (Point2D)pts.get(j); |
|
244 |
} |
|
227 |
// In DWG 13, 14 and 2000 version, a Polyface mesh has |
|
228 |
// handles references to its vertices. |
|
229 |
// In DWG 12 vertices are after the entity |
|
230 |
if(firstVertexHandle != null && lastVertexHandle != null){ |
|
231 |
DwgObject first = dwgFile.getDwgObjectFromHandle(firstVertexHandle.getOffset()); |
|
232 |
DwgObject last = dwgFile.getDwgObjectFromHandle(lastVertexHandle.getOffset()); |
|
233 |
if(first == null || last == null){ |
|
234 |
System.out.println("DwgPFacePolyline con vertices inicial o final a null"); |
|
235 |
return; |
|
245 | 236 |
} |
246 |
double[] bs = new double[bulges.size()]; |
|
247 |
for (int j=0;j<bulges.size();j++) { |
|
248 |
bs[j] = ((Double)bulges.get(j)).doubleValue(); |
|
237 |
|
|
238 |
if(!(first instanceof IDwgVertex)){ |
|
239 |
System.out.println("El primer vertice de PFacePolyline es "+ |
|
240 |
first.getClass().getName()); |
|
241 |
return; |
|
249 | 242 |
} |
250 |
setBulges(bs); |
|
251 |
Point2D[] points = GisModelCurveCalculator. |
|
252 |
calculateGisModelBulge(newPts, bs); |
|
253 |
setPts(points); |
|
243 |
|
|
244 |
if(!(last instanceof IDwgVertex)){ |
|
245 |
System.out.println("El ultimo vertice de PFacePolyline es "+ |
|
246 |
last.getClass().getName()); |
|
247 |
return; |
|
248 |
} |
|
249 |
|
|
250 |
int firstObjIdx = dwgFile.getIndexOf(first); |
|
251 |
int lastObjIdx = dwgFile.getIndexOf(last); |
|
252 |
if(firstObjIdx == -1 || lastObjIdx == -1){ |
|
253 |
System.out.println("Calculate GIS Model: Problemas en "+ |
|
254 |
"la localizacion de vertices: 1?=" |
|
255 |
+firstObjIdx+ |
|
256 |
",Ultimo="+lastObjIdx); |
|
257 |
return; |
|
258 |
} |
|
259 |
for(int i = firstObjIdx; i <= lastObjIdx; i++){ |
|
260 |
DwgObject obj = dwgFile.getDwgObject(i); |
|
261 |
if(obj instanceof IDwgVertex){ |
|
262 |
this.addVertex((IDwgVertex)obj); |
|
263 |
}else if(obj instanceof DwgSeqend){ |
|
264 |
// TODO SEE IF BREAK THE ITERATION |
|
265 |
break; |
|
266 |
}else{ |
|
267 |
System.out.println("Encontrado "+obj.getClass().getName()+" en la lista de vertices de Polyline3D"); |
|
268 |
} |
|
269 |
}// for |
|
270 |
|
|
254 | 271 |
} else { |
255 | 272 |
System.out.println("Encontrada polil?nea sin puntos ..."); |
256 |
// TODO: No se debe mandar nunca una polil?nea sin puntos, si esto |
|
273 |
// TODO: No se debe mandar nunca una polil?nea sin puntos, si |
|
274 |
// esto |
|
257 | 275 |
// ocurre es porque existe un error que hay que corregir ... |
258 |
} |
|
259 |
|
|
260 |
**/ |
|
261 |
} |
|
276 |
} |
|
262 | 277 |
|
263 |
public FShape toFMapGeometry(boolean is3DFile) { |
|
264 |
// TODO Auto-generated method stub |
|
265 |
return null; |
|
266 | 278 |
} |
267 |
|
|
279 |
|
|
280 |
|
|
281 |
public IGeometry toFMapGeometry(boolean is3DFile) { |
|
282 |
FGeometryCollection solution = null; |
|
283 |
IGeometry[] geometries = null; |
|
284 |
if(vertices != null && faces != null){ |
|
285 |
if(vertices.size() == 0 || faces.size() == 0){ |
|
286 |
return solution; |
|
287 |
} |
|
288 |
ArrayList geomList = new ArrayList(); |
|
289 |
int numFaces = faces.size(); |
|
290 |
for(int i = 0; i < numFaces; i++){ |
|
291 |
DwgVertexPFaceFace face = (DwgVertexPFaceFace) faces.get(i); |
|
292 |
int[] verticesId = face.getVerticesidx(); |
|
293 |
ArrayList pts = new ArrayList(); |
|
294 |
boolean lastWasInvisible = true; |
|
295 |
for(int j = 0; j < NUM_VERTEX_OF_FACE; j++){ |
|
296 |
if(verticesId[j] > 0){ |
|
297 |
if(lastWasInvisible){ |
|
298 |
pts.clear(); |
|
299 |
lastWasInvisible = false; |
|
300 |
} |
|
301 |
// the index is 1-based |
|
302 |
try{ |
|
303 |
pts.add(vertices.get(verticesId[j] -1)); |
|
304 |
}catch(Throwable t){ |
|
305 |
t.printStackTrace(); |
|
306 |
} |
|
307 |
|
|
308 |
} else if(verticesId[j] < 0 && !lastWasInvisible){ |
|
309 |
lastWasInvisible = true; |
|
310 |
pts.add(vertices.get( (verticesId[j] * -1) -1)); |
|
311 |
} |
|
312 |
}// for j |
|
313 |
|
|
314 |
FPolygon3D polygon = FMapUtil.ptsTo3DPolygon(pts); |
|
315 |
IGeometry geom = ShapeFactory.createGeometry(polygon); |
|
316 |
geomList.add(geom); |
|
317 |
|
|
318 |
|
|
319 |
// if(!lastWasInvisible){ |
|
320 |
// if(vertex[nrV] < 0){ |
|
321 |
// line.addPoint(knot[-vertex[nrV] - 1]); |
|
322 |
// } else{ |
|
323 |
// line.addPoint(knot[vertex[nrV] - 1]); |
|
324 |
// } |
|
325 |
// set.addDrawable(line); |
|
326 |
// } |
|
327 |
|
|
328 |
}// for i |
|
329 |
geometries = new IGeometry[geomList.size()]; |
|
330 |
geomList.toArray(geometries); |
|
331 |
solution = new FGeometryCollection(geometries); |
|
332 |
} |
|
333 |
return solution; |
|
334 |
|
|
335 |
} |
|
336 |
/* |
|
337 |
* (non-Javadoc) |
|
338 |
* |
|
339 |
* @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapString(boolean) |
|
340 |
*/ |
|
268 | 341 |
public String toFMapString(boolean is3DFile) { |
269 |
// TODO Auto-generated method stub |
|
270 |
return null; |
|
342 |
if(is3DFile) |
|
343 |
return "FPolyline3D"; |
|
344 |
else |
|
345 |
return "FPolyline2D"; |
|
271 | 346 |
} |
347 |
|
|
348 |
public String toString(){ |
|
349 |
return "PFacePolyline"; |
|
350 |
} |
|
272 | 351 |
|
273 | 352 |
public void addVertex(IDwgVertex vertex) { |
274 |
//here we save the vertex (not the coordinate) because |
|
275 |
//this Polyline could have two kind of vertex (pface and pfaceface) |
|
276 |
vertices.add(vertex); |
|
353 |
// here we save the vertex (not the coordinate) because |
|
354 |
// this Polyline could have two kind of vertex (pface and pfaceface) |
|
355 |
if(vertex instanceof DwgVertexPFaceFace) |
|
356 |
faces.add(vertex); |
|
357 |
else |
|
358 |
vertices.add(vertex); |
|
277 | 359 |
} |
360 |
|
|
361 |
public void dump(){ |
|
362 |
System.out.println("<PFacePolyline vertexCount="+vertexCount+" faceCount"+faceCount+">"); |
|
363 |
int numRealVertex = 1; |
|
364 |
for(int i = 0; i < vertices.size(); i++){ |
|
365 |
IDwgVertex vertex = (IDwgVertex) vertices.get(i); |
|
366 |
double[] point = vertex.getPoint(); |
|
367 |
System.out.println("<Vertex idx="+numRealVertex+" class="+vertex.getClass().getName()+" x="+point[0]+" y="+point[1]+" z="+point[2]+" >"); |
|
368 |
numRealVertex++; |
|
369 |
} |
|
370 |
|
|
371 |
for(int i = 0; i < faces.size(); i++){ |
|
372 |
IDwgVertex vertex = (IDwgVertex) faces.get(i); |
|
373 |
if(vertex instanceof DwgVertexPFaceFace){ |
|
374 |
int[] point = ((DwgVertexPFaceFace)vertex).getVerticesidx(); |
|
375 |
System.out.println("<Vertex class="+vertex.getClass().getName()+" 1="+point[0]+" 2="+point[1]+" 3="+point[2]+" 4="+ point[3]+">"); |
|
376 |
} |
|
377 |
} |
|
378 |
System.out.println("</PFacePolyline>"); |
|
379 |
} |
|
278 | 380 |
|
381 |
public void transform2Block(double[] bPoint, Point2D insPoint, double[] scale, double rot, List dwgObjectsWithoutBlocks, Map handle_objectsWithoutBlocks, DwgFile callBack) { |
|
382 |
DwgPFacePolyline transformedEntity = null; |
|
383 |
List vertices = this.getVertices(); |
|
384 |
if (vertices != null) { |
|
385 |
if(vertices.size() == 0) |
|
386 |
return; |
|
387 |
List transformedVertices = new ArrayList(); |
|
388 |
for (int i=0;i < vertices.size();i++) { |
|
389 |
double[] pointAux = null; |
|
390 |
IDwgVertex vertex = (IDwgVertex) vertices.get(i); |
|
391 |
if(!(vertex instanceof DwgVertexPFaceFace)){ |
|
392 |
// DwgVertexPFaceFace hasnt coordinates, instead |
|
393 |
// it has indices in the vertex array |
|
394 |
double[] point = vertex.getPoint(); |
|
395 |
pointAux = new double[]{point[0] - bPoint[0], |
|
396 |
point[1] - bPoint[1], point[2] - bPoint[2]}; |
|
397 |
|
|
398 |
double laX = insPoint.getX() + ((pointAux[0] * scale[0])*Math.cos(rot) + (pointAux[1]*scale[1])*(-1)*Math.sin(rot)); |
|
399 |
double laY = insPoint.getY() + ((pointAux[0]*scale[0])*Math.sin(rot) + (pointAux[1]*scale[1])*Math.cos(rot)); |
|
400 |
double laZ = pointAux[2]; |
|
401 |
vertex.setPoint(new double[]{laX, laY, laZ}); |
|
402 |
transformedVertices.add(vertex); |
|
403 |
} |
|
404 |
}// for |
|
405 |
transformedEntity = (DwgPFacePolyline)this.clone(); |
|
406 |
fill(transformedEntity); |
|
407 |
dwgObjectsWithoutBlocks.add(transformedEntity); |
|
408 |
handle_objectsWithoutBlocks.put(new Integer(transformedEntity.getHandle().getOffset()), transformedEntity); |
|
409 |
}// if |
|
410 |
} |
|
279 | 411 |
} |
280 | 412 |
|
Also available in: Unified diff