Revision 16780

View differences:

branches/v10/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/writers/dxf/DxfWriter.java
29 29
import com.iver.cit.gvsig.fmap.core.FPoint2D;
30 30
import com.iver.cit.gvsig.fmap.core.FPoint3D;
31 31
import com.iver.cit.gvsig.fmap.core.FShape;
32
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
32 33
import com.iver.cit.gvsig.fmap.core.IFeature;
33 34
import com.iver.cit.gvsig.fmap.core.IGeometry;
34 35
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
......
142 143
				indexRotationText=i;
143 144
			}
144 145
		}
146
		k = 0;
145 147
	}
146 148

  
147 149
public void process(IRowEdited row) throws EditionException {
......
161 163

  
162 164
	    	// ////////////////
163 165
	        if (geom.getGeometryType()==FShape.POINT) {
164
	            createPoint2D(handle, k, geom, values);
165
	            k++;
166
	            k=createPoint2D(handle, k, geom, values);
166 167
	        } else if (geom.getGeometryType()==(FShape.POINT | FShape.Z)) {
167 168
	            dxf3DFile = true;
168
	            createPoint3D(handle, k, geom, values);
169
	            k++;
169
	            k=createPoint3D(handle, k, geom, values);
170 170
	        } else if (geom.getGeometryType()==FShape.LINE) {
171
	            createLwPolyline2D(handle, k, geom, false,values);
172
	            k++;
171
	            k=createLwPolyline2D(handle, k, geom, false,values);
173 172
	        } else if (geom.getGeometryType()==(FShape.LINE | FShape.Z)) {
174 173
	            dxf3DFile = true;
175 174
	            k = createPolyline3D(handle, k, geom, values);
176 175
	        } else if (geom.getGeometryType()==FShape.POLYGON) {
177 176
	            // createPolygon2D(handle, k, geom);
178
	            createLwPolyline2D(handle, k, geom, true,values);
179
	            k++;
177
	            k=createLwPolyline2D(handle, k, geom, true,values);
180 178
	        } else if (geom.getGeometryType()==(FShape.POLYGON | FShape.Z)) {
181 179
	            dxf3DFile = true;
182 180
	            k = createPolyline3D(handle, k, geom, values);
183 181
	            // k = createPolygon3D(handle, k, geom);
184 182
	        } else if (geom.getGeometryType()==FShape.CIRCLE) {
185 183
	        	FCircle2D circle = (FCircle2D) geom.getInternalShape();
186
	        	createCircle2D(handle, k, circle, values);
187
	            k++;
184
	        	k=createCircle2D(handle, k, circle, values);
188 185
	        } else if (geom.getGeometryType()==FShape.ARC) {
189 186
	        	FArc2D arc = (FArc2D) geom.getInternalShape();
190
	        	createArc2D(arc, values);
191
	            k++;
187
	        	k=createArc2D(handle, k, arc, values);
192 188
	        } else if (geom.getGeometryType()==FShape.ELLIPSE) {
193 189
	        	FEllipse2D ellipse = (FEllipse2D) geom.getInternalShape();
194
	        	createEllipse2D(ellipse, values);
195
	            k++;
196
			/* } else if (geom instanceof FGeometryCollection) {
190
	        	k=createEllipse2D(handle, k, ellipse, values);
191
	       /* } else if (geom instanceof FGeometryCollection) {
197 192
				// System.out.println("Polil?nea encontrada (Soluci?n
198 193
				// provisional).");
199 194
				FGeometryCollection gc = (FGeometryCollection)geom;
......
325 320

  
326 321

  
327 322
	}
328
	private void createArc2D(FArc2D fArc,Value[] values) throws Exception {
323
	private int createArc2D(int handle, int k,FArc2D fArc,Value[] values) throws Exception {
329 324
		Point2D[] pts = new Point2D[3];
330 325
		pts[0] = fArc.getInit();
331 326
		pts[1] = fArc.getMid();
......
379 374
		ai.setData(new Double(initAngle));
380 375
		ae.setCode(51);
381 376
		ae.setData(new Double(endAngle));
382
		DxfGroupVector av = updateProperties(values);
377
		DxfGroupVector av = updateProperties(values,k);
383 378
//		av.add(arcLayer);
384 379
		av.add(ax);
385 380
		av.add(ay);
......
387 382
		av.add(ai);
388 383
		av.add(ae);
389 384
		entityMaker.createArc(av);
390

  
385
		k++;
386
		return k;
391 387
	}
392 388

  
393
	private void createCircle2D(int handle, int k2, FCircle2D geom,Value[] values)
389
	private int createCircle2D(int handle, int k, FCircle2D geom,Value[] values)
394 390
			throws Exception {
395
		DxfGroupVector polv = updateProperties(values);
391
		DxfGroupVector polv = updateProperties(values,k);
396 392
//		DxfGroup polylineLayer = new DxfGroup(8, "default");
397 393
//		polv.add(polylineLayer);
398 394
//		DxfGroup handleGroup = new DxfGroup();
......
424 420
		polv.add(radius);
425 421

  
426 422
		entityMaker.createCircle(polv);
427

  
423
		k++;
424
		return k;
428 425
	}
429 426

  
430
	private void createEllipse2D(FEllipse2D fElip, Value[] values) throws Exception {
427
	private int createEllipse2D(int handle, int k,FEllipse2D fElip, Value[] values) throws Exception {
431 428
		Point2D center = new Point2D.Double((fElip.getInit().getX() + fElip
432 429
				.getEnd().getX()) / 2, (fElip.getInit().getY() + fElip.getEnd()
433 430
				.getY()) / 2);
......
480 477
		yc.setData(new Double(endPointOfMajorAxis.getY() - center.getY()));
481 478
		minToMaj.setCode(40);
482 479
		minToMaj.setData(new Double(mToMAR));
483
		DxfGroupVector av = updateProperties(values);
480
		DxfGroupVector av = updateProperties(values,k);
484 481
//		av.add(arcLayer);
485 482
		av.add(x);
486 483
		av.add(y);
......
488 485
		av.add(yc);
489 486
		av.add(minToMaj);
490 487
		entityMaker.createEllipse(av);
488
		k++;
489
		return k;
491 490
	}
492 491

  
493 492
	public void postProcess() throws EditionException {
......
533 532
		for (int i = 0; i < geometries.length; i++) {
534 533
			IGeometry geom = geometries[i];
535 534
			if (geom.getGeometryType() == FShape.POINT) {
536
				createPoint2D(handle, k, geom, null);
537
				k++;
535
				k=createPoint2D(handle, k, geom, null);
538 536
			} else if (geom.getGeometryType() == (FShape.POINT | FShape.Z)) {
539 537
				dxf3DFile = true;
540
				createPoint3D(handle, k, geom, null);
541
				k++;
538
				k=createPoint3D(handle, k, geom, null);
542 539
			} else if (geom.getGeometryType() == FShape.LINE) {
543
				createLwPolyline2D(handle, k, geom, false, null);
544
				k++;
540
				k=createLwPolyline2D(handle, k, geom, false, null);
545 541
			} else if (geom.getGeometryType() == (FShape.LINE | FShape.Z)) {
546 542
				dxf3DFile = true;
547 543
				k = createPolyline3D(handle, k, geom, null);
548 544
			} else if (geom.getGeometryType() == FShape.POLYGON) {
549 545
				// createPolygon2D(handle, k, geom);
550
				createLwPolyline2D(handle, k, geom, true,null);
551
				k++;
546
				k=createLwPolyline2D(handle, k, geom, true,null);
552 547
			} else if (geom.getGeometryType() == (FShape.POLYGON | FShape.Z)) {
553 548
				dxf3DFile = true;
554 549
				k = createPolygon3D(handle, k, geom, null);
......
573 568
	 */
574 569
	private int createPolygon3D(int handle, int k, IGeometry geom, Value[] values)
575 570
			throws Exception {
576
		DxfGroupVector polv = updateProperties(values);
571
		DxfGroupVector polv = updateProperties(values,k);
577 572
//		DxfGroup polylineLayer = new DxfGroup(8, "default");
578 573
//		polv.add(polylineLayer);
579 574
//		DxfGroup handleGroup = new DxfGroup();
......
697 692
	 */
698 693
	private void createPolygon2D(int handle, int k, IGeometry geom,Value[] values)
699 694
			throws Exception {
700
		DxfGroupVector polv = updateProperties(values);
695
		DxfGroupVector polv = updateProperties(values,k);
701 696
//		DxfGroup polylineLayer = new DxfGroup(8, "default");
702 697
//		polv.add(polylineLayer);
703 698
//		DxfGroup handleGroup = new DxfGroup();
......
747 742
	 */
748 743
	private int createPolyline3D(int handle, int k, IGeometry geom, Value[] values)
749 744
			throws Exception {
750
		DxfGroupVector polv = updateProperties(values);
745
		DxfGroupVector polv = updateProperties(values,k);
751 746
//		DxfGroup polylineLayer = new DxfGroup(8, "default");
752 747
//		polv.add(polylineLayer);
753 748
//		DxfGroup handleGroup = new DxfGroup();
......
862 857
		return k;
863 858
	}
864 859

  
865
	private DxfGroupVector updateProperties(Value[] values){
860
	private DxfGroupVector updateProperties(Value[] values,int k){
866 861
		DxfGroupVector polv = new DxfGroupVector();
867 862
		String layer=DEFAULT_LAYER;
868 863
		Integer color=DEFAULT_COLOR;
......
919 914
	 * @param geom
920 915
	 * @throws Exception
921 916
	 */
922
	private void createLwPolyline2D(int handle, int k, IGeometry geom, boolean isPolygon, Value[] values)
917
	private int createLwPolyline2D(int handle, int k, IGeometry geom, boolean isPolygon, Value[] values)
923 918
			throws Exception {
924
//		arrayFields.add("ID");
925
//		arrayFields.add("FShape");
926
//		arrayFields.add("Entity");
927
//		String layer=DEFAULT_LAYER;
928
//		Integer color=DEFAULT_COLOR;
929
//		Double elevation=DEFAULT_ELEVATION;
930
//		Double thickness=DEFAULT_THICKNESS;
931
//		if (!(values[3] instanceof NullValue)){
932
//			layer = values[3].toString();
933
//		}
934
//		if (!(values[4] instanceof NullValue)){
935
//			color = new Integer(((NumericValue)values[4]).intValue());
936
//		}
937
//		if (!(values[5] instanceof NullValue)){
938
//			elevation= new Double(((NumericValue)values[5]).doubleValue());
939
//		}
940
//		if (!(values[6] instanceof NullValue)){
941
//			thickness= new Double(((NumericValue)values[6]).doubleValue());
942
//		}
943
//		if (!(values[7] instanceof NullValue)){
944
//			text = values[7].toString();
945
//		}
946
//		String heightText=values[8].toString();
947
//		String rotationText=values[9].toString();
948

  
949

  
950
		DxfGroupVector polv = null;
951
//		DxfGroup polylineLayer = new DxfGroup(8, layer);
952

  
953
//		DxfGroup handleGroup = new DxfGroup();
954
//		handleGroup.setCode(5);
955
//		handleGroup.setData(new Integer(handle + k).toString());
956

  
919
		boolean first=true;
920
		DxfGroupVector polv = updateProperties(values,k);
957 921
		Vector vpoints = new Vector();
958 922

  
959 923
		DxfGroup polylineFlag = new DxfGroup();
......
983 947
			int theType = theIterator.currentSegment(theData);
984 948
			switch (theType) {
985 949
			case PathIterator.SEG_MOVETO:
986
				if (polv != null)
950
				if (!first)
987 951
				{
988 952
					for (int j = 0; j < vpoints.size(); j++) {
989 953
						DxfGroup xvertex = new DxfGroup();
......
995 959
						polv.add(xvertex);
996 960
						polv.add(yvertex);
997 961
					}
962

  
998 963
					entityMaker.createLwPolyline(polv);
964
					k++;
965
					polv = updateProperties(values,k);
966

  
999 967
				}
1000
				polv = updateProperties(values);
968
				first=false;
1001 969
				polv.add(polylineFlag);
1002 970
				vpoints.clear();
1003 971
				vpoints.add(new FPoint2D(theData[0], theData[1]));
......
1032 1000
			polv.add(xvertex);
1033 1001
			polv.add(yvertex);
1034 1002
		}
1003

  
1035 1004
		entityMaker.createLwPolyline(polv);
1005
		k++;
1006
		return k;
1036 1007
	}
1037 1008

  
1038 1009
	/**
......
1041 1012
	 * @param geom
1042 1013
	 * @throws Exception
1043 1014
	 */
1044
	private void createPoint3D(int handle, int k, IGeometry geom, Value[] values)
1015
	private int createPoint3D(int handle, int k, IGeometry geom, Value[] values)
1045 1016
			throws Exception {
1046 1017
		if (indexText!=-1 && !(values[indexText] instanceof NullValue)){
1047
			createText3D(handle,k,geom,values);
1048
			return;
1018
			return createText3D(handle,k,geom,values);
1049 1019
		}
1050 1020
		FPoint3D point = new FPoint3D(0, 0, 0);
1051 1021
		double[] pointCoords = new double[6];
......
1076 1046
		handleElevation.setCode(38);
1077 1047
		handleElevation.setData(elevation);
1078 1048

  
1079
		DxfGroupVector pv = updateProperties(values);
1049
		DxfGroupVector pv = updateProperties(values,k);
1080 1050
		pv.add(handleElevation);
1081 1051
//		pv.add(pointLayer);
1082 1052
//		pv.add(handleGroup);
......
1084 1054
		pv.add(py);
1085 1055
		pv.add(pz);
1086 1056
		entityMaker.createPoint(pv);
1057
		k++;
1058
		return k;
1087 1059
	}
1088 1060

  
1089 1061
	/**
......
1092 1064
	 * @param geom
1093 1065
	 * @throws Exception
1094 1066
	 */
1095
	private void createPoint2D(int handle, int k, IGeometry geom, Value[] values)
1067
	private int createPoint2D(int handle, int k, IGeometry geom, Value[] values)
1096 1068
			throws Exception {
1097 1069

  
1098 1070
		if (indexText!= -1 && !(values[indexText] instanceof NullValue)){
1099
			createText2D(handle,k,geom,values);
1100
			return;
1071
			return createText2D(handle,k,geom,values);
1101 1072
		}
1102 1073
//		String layer=DEFAULT_LAYER;
1103 1074
//		Integer color=DEFAULT_COLOR;
......
1152 1123
		pz.setCode(30);
1153 1124
		// POINT del DXF tiene cota. Le asigno cero arbitrariamente.
1154 1125
		pz.setData(new Double(0.0));
1155
		DxfGroupVector pv = updateProperties(values);
1126
		DxfGroupVector pv = updateProperties(values,k);
1156 1127
//		pv.add(pointLayer);
1157 1128
//		pv.add(handleGroup);
1158 1129
//		pv.add(handleColor);
......
1162 1133
		pv.add(py);
1163 1134
		pv.add(pz);
1164 1135
		entityMaker.createPoint(pv);
1136
		k++;
1137
		return k;
1165 1138
	}
1166 1139
	/**
1167 1140
	 * @param handle
......
1169 1142
	 * @param geom
1170 1143
	 * @throws Exception
1171 1144
	 */
1172
	private void createText2D(int handle, int k, IGeometry geom, Value[] values)
1145
	private int createText2D(int handle, int k, IGeometry geom, Value[] values)
1173 1146
			throws Exception {
1174 1147
//		String layer=DEFAULT_LAYER;
1175 1148
//		Integer color=DEFAULT_COLOR;
......
1252 1225
		pz.setCode(30);
1253 1226
		// POINT del DXF tiene cota. Le asigno cero arbitrariamente.
1254 1227
		pz.setData(new Double(0.0));
1255
		DxfGroupVector pv = updateProperties(values);
1228
		DxfGroupVector pv = updateProperties(values,k);
1256 1229
//		pv.add(pointLayer);
1257 1230
//		pv.add(handleColor);
1258 1231
//		pv.add(handleElevation);
......
1265 1238
		pv.add(py);
1266 1239
		pv.add(pz);
1267 1240
		entityMaker.createText(pv);
1241
		k++;
1242
		return k;
1268 1243
	}
1269
	private void createText3D(int handle, int k, IGeometry geom, Value[] values)
1244
	private int createText3D(int handle, int k, IGeometry geom, Value[] values)
1270 1245
			throws Exception {
1271 1246
		// String layer=DEFAULT_LAYER;
1272 1247
		// Integer color=DEFAULT_COLOR;
......
1344 1319
		py.setData(new Double(point.getY()));
1345 1320
		pz.setCode(30);
1346 1321
		pz.setData(new Double(point.getZs()[0]));
1347
		DxfGroupVector pv = updateProperties(values);
1322
		DxfGroupVector pv = updateProperties(values,k);
1348 1323
		// pv.add(pointLayer);
1349 1324
		// pv.add(handleColor);
1350 1325
		pv.add(handleElevation);
......
1357 1332
		pv.add(py);
1358 1333
		pv.add(pz);
1359 1334
		entityMaker.createText(pv);
1335
		k++;
1336
		return k;
1360 1337
	}
1361 1338
	private boolean constantElevation(double[] velev) {
1362 1339
		boolean constant = true;

Also available in: Unified diff