Revision 23273 branches/v2_0_0_prep/libraries/libFMap_data_dwg/src/org/gvsig/fmap/data/feature/file/dwg/DWGResource.java

View differences:

DWGResource.java
30 30
 */
31 31
package org.gvsig.fmap.data.feature.file.dwg;
32 32

  
33
import java.awt.Color;
34
import java.awt.geom.AffineTransform;
35
import java.awt.geom.Arc2D;
36
import java.awt.geom.Rectangle2D;
37 33
import java.io.File;
38 34
import java.io.IOException;
39
import java.util.ArrayList;
40
import java.util.Iterator;
41 35
import java.util.List;
36
import java.util.TreeSet;
42 37

  
43 38
import org.gvsig.fmap.data.DataException;
44 39
import org.gvsig.fmap.data.OpenException;
45 40
import org.gvsig.fmap.data.ReadException;
46 41
import org.gvsig.fmap.data.feature.Feature;
47
import org.gvsig.fmap.data.feature.FeatureAttributeDescriptor;
48 42
import org.gvsig.fmap.data.feature.FeatureType;
49
import org.gvsig.fmap.data.feature.IsNotFeatureSettingException;
50 43
import org.gvsig.fmap.data.feature.UnsupportedVersionException;
51 44
import org.gvsig.fmap.data.feature.file.FileMemoryResource;
52 45
import org.gvsig.fmap.data.feature.file.FileStoreParameters;
53
//import org.gvsig.fmap.data.feature.file.dgn.utils.DGNElemArc;
54
//import org.gvsig.fmap.data.feature.file.dgn.utils.DGNElemComplexHeader;
55
//import org.gvsig.fmap.data.feature.file.dgn.utils.DGNElemCore;
56
//import org.gvsig.fmap.data.feature.file.dgn.utils.DGNElemMultiPoint;
57
//import org.gvsig.fmap.data.feature.file.dgn.utils.DGNElemText;
58
//import org.gvsig.fmap.data.feature.file.dgn.utils.DGNFileHeader;
59
//import org.gvsig.fmap.data.feature.file.dgn.utils.DGNReader;
46
import org.gvsig.fmap.data.feature.operation.LegendLabelingManager;
47
import org.gvsig.fmap.data.feature.operation.LegendLabelingManagerFactory;
60 48
import org.gvsig.fmap.geom.Geometry;
61
import org.gvsig.fmap.geom.GeometryFactory;
62
import org.gvsig.fmap.geom.GeometryManager;
63 49
import org.gvsig.fmap.geom.primitive.DefaultEnvelope;
64 50
import org.gvsig.fmap.geom.primitive.Envelope;
65
import org.gvsig.fmap.geom.primitive.GeneralPathX;
66
import org.gvsig.fmap.mapcontext.rendering.legend.LegendFactory;
67
import org.gvsig.fmap.mapcontext.rendering.legend.VectorialUniqueValueLegend;
68
import org.gvsig.fmap.mapcontext.rendering.legend.styling.AttrInTableLabelingStrategy;
69
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
70
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory;
71 51
import org.gvsig.i18n.Messages;
72 52

  
73 53
import com.iver.cit.jdwglib.dwg.DwgFile;
......
84 64
 */
85 65
public class DWGResource extends FileMemoryResource {
86 66

  
87
	private final int ID_FIELD_ID = 0;
88
	private final int ID_FIELD_FSHAPE = 1;
89
	private final int ID_FIELD_ENTITY = 2;
90
	private final int ID_FIELD_LAYER = 3;
91
	private final int ID_FIELD_COLOR = 4;
92
	private final int ID_FIELD_ELEVATION = 5;
93
	private final int ID_FIELD_THICKNESS = 6;
94
	private final int ID_FIELD_HEIGHTTEXT = 7;
95
	private final int ID_FIELD_ROTATIONTEXT = 8;
96
	private final int ID_FIELD_TEXT = 9;
97
	private final int ID_FIELD_GEOMETRY = 10;
67
	private static LegendLabelingManagerFactory legendLabelingManagerFactory = null;
98 68

  
69
	public static final int ID_FIELD_ID = 0;
70
	public static final int ID_FIELD_FSHAPE = 1;
71
	public static final int ID_FIELD_ENTITY = 2;
72
	public static final int ID_FIELD_LAYER = 3;
73
	public static final int ID_FIELD_COLOR = 4;
74
	public static final int ID_FIELD_ELEVATION = 5;
75
	public static final int ID_FIELD_THICKNESS = 6;
76
	public static final int ID_FIELD_HEIGHTTEXT = 7;
77
	public static final int ID_FIELD_ROTATIONTEXT = 8;
78
	public static final int ID_FIELD_TEXT = 9;
79
	public static final int ID_FIELD_GEOMETRY = 10;
99 80

  
100 81

  
101 82

  
83

  
102 84
	private FeatureType featureType;
103 85

  
104
	private AttrInTableLabelingStrategy labeling;
105
	private VectorialUniqueValueLegend defaultLegend;
106 86

  
87
	private LegendLabelingManager legendlabelingManager;
107 88
	private Envelope fullEnvelope;
108 89

  
90

  
109 91
	/**
110 92
	 * @param params
111 93
	 */
......
132 114
//		float heightText = 10;
133 115
//		attr.setLoadedInMemory(true);
134 116
		initializeFeatureType();
117
		if (legendLabelingManagerFactory != null){
118
			legendlabelingManager = legendLabelingManagerFactory.newManager();
119
		}else{
120
			legendlabelingManager = null;
121
		}
122

  
135 123
		fullEnvelope = new DefaultEnvelope(2);
136 124
		File file = this.getFile();
137 125
		DwgFile dwg = new DwgFile(file.getAbsolutePath());
......
170 158
			}
171 159
		}
172 160

  
161
		TreeSet colorSet=new TreeSet();
173 162

  
174 163
		boolean is3dFile = dwg.isDwg3DFile();
175 164

  
......
204 193
						color = Math.abs(color);
205 194
					if(color > 255)
206 195
						color = colorByLayer;
196

  
197

  
207 198
					feature.set(ID_FIELD_COLOR, color);
199
					colorSet.add(new Integer(color));
208 200

  
201

  
209 202
					if(entity instanceof IDwg3DTestable){
210 203
						feature.set(ID_FIELD_ELEVATION, ((IDwg3DTestable)entity).getZ());
211 204
					}
......
229 222

  
230 223
					feature.setGeometry(ID_FIELD_GEOMETRY, geometry);
231 224

  
232
					this.addFeature(new DWGFeature(feature));
233 225

  
226
					this.addFeature(feature);
227
					if (this.legendlabelingManager != null){
228
						this.legendlabelingManager.add(feature);
229
					}
230

  
234 231
				}//if instanceof
235 232
			} catch (ReadException e) {
236 233
				throw new OpenException(this.description(),e);
......
238 235

  
239 236

  
240 237
		}//for
241
		defaultLegend = LegendFactory
242
		.createVectorialUniqueValueLegend(Geometry.TYPES.GEOMETRY);
243
		defaultLegend.setClassifyingFieldNames(new String[] {"Color"});
244 238

  
245
		String[] types = new String[featureType.size()];
246
		Iterator iter = featureType.iterator();
247
		int i=0;
248
		while (iter.hasNext()){
249
			types[i] = ((FeatureAttributeDescriptor)iter.next()).getDataType();
250
			i++;
251
		}
252
		defaultLegend.setClassifyingFieldTypes(types);
253 239

  
254
		ISymbol myDefaultSymbol = SymbologyFactory.
255
		createDefaultSymbolByShapeType(Geometry.TYPES.GEOMETRY, Color.BLACK);
256 240

  
257
		defaultLegend.setDefaultSymbol(myDefaultSymbol);
258 241

  
259
		labeling = new AttrInTableLabelingStrategy();
260
		(labeling).setTextFieldId(ID_FIELD_TEXT);
261
		(labeling).setRotationFieldId(ID_FIELD_ROTATIONTEXT);
262
		(labeling).setHeightFieldId(ID_FIELD_HEIGHTTEXT);
263
		(labeling).setUnit(1); //MapContext.NAMES[1] (meters)
242

  
243
//		String[] types = new String[featureType.size()];
244
//		Iterator iter = featureType.iterator();
245
//		int i=0;
246
//		while (iter.hasNext()){
247
//			types[i] = ((FeatureAttributeDescriptor)iter.next()).getDataType();
248
//			i++;
249
//		}
250

  
264 251
	}
265 252

  
266 253
	/* (non-Javadoc)
......
281 268
	 */
282 269
	protected Object getDefaultLegend() throws ReadException {
283 270
		this.checkOpen();
284
		return this.defaultLegend;
271
		if (legendlabelingManager == null){
272
			return null;
273
		}
274
		return legendlabelingManager.getDefaultLegend();
285 275
	}
286 276

  
287 277
	/* (non-Javadoc)
......
305 295
		return super.getFeature(index);
306 296
	}
307 297

  
308
	protected AttrInTableLabelingStrategy getDefaultLabelingStrategy()  throws ReadException {
298
	protected Object getDefaultLabelingStrategy()  throws ReadException {
309 299
		this.checkOpen();
310
		return labeling;
300
		if (legendlabelingManager == null){
301
			return null;
302
		}
303
		return legendlabelingManager.getLabeling();
311 304
	}
312 305

  
306
	public static void setLegendLabelingManagerFactory(LegendLabelingManagerFactory factory) {
307
		legendLabelingManagerFactory = factory;
308
	}
309

  
310
	public static LegendLabelingManagerFactory getLegendLabelingManagerFactory() {
311
		return legendLabelingManagerFactory;
312
	}
313

  
313 314
}
314 315

  

Also available in: Unified diff