Revision 4637 trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/RotateCADTool.java
RotateCADTool.java | ||
---|---|---|
42 | 42 |
|
43 | 43 |
import java.awt.Graphics; |
44 | 44 |
import java.awt.Graphics2D; |
45 |
import java.awt.Image; |
|
45 | 46 |
import java.awt.event.InputEvent; |
46 | 47 |
import java.awt.geom.AffineTransform; |
47 | 48 |
import java.awt.geom.Point2D; |
... | ... | |
50 | 51 |
|
51 | 52 |
import com.iver.andami.PluginServices; |
52 | 53 |
import com.iver.cit.gvsig.CADExtension; |
54 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
53 | 55 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
54 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
|
55 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
|
56 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
57 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
|
58 | 56 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
59 | 57 |
import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited; |
60 | 58 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
61 | 59 |
import com.iver.cit.gvsig.fmap.edition.UtilFunctions; |
62 |
import com.iver.cit.gvsig.gui.cad.CADTool;
|
|
60 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
|
|
63 | 61 |
import com.iver.cit.gvsig.gui.cad.DefaultCADTool; |
64 | 62 |
import com.iver.cit.gvsig.gui.cad.tools.smc.RotateCADToolContext; |
65 | 63 |
import com.iver.cit.gvsig.gui.cad.tools.smc.RotateCADToolContext.RotateCADToolState; |
64 |
import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
|
66 | 65 |
|
67 | 66 |
|
68 | 67 |
/** |
... | ... | |
133 | 132 |
RotateCADToolState actualState = (RotateCADToolState) _fsm.getPreviousState(); |
134 | 133 |
String status = actualState.getName(); |
135 | 134 |
ArrayList selectedRow=getSelectedRows(); |
136 |
|
|
135 |
VectorialLayerEdited vle=getVLE(); |
|
136 |
VectorialEditableAdapter vea = vle.getVEA(); |
|
137 | 137 |
if (status.equals("Rotate.PointMain")) { |
138 | 138 |
firstPoint = new Point2D.Double(x, y); |
139 | 139 |
} else if (status.equals("Rotate.AngleOrPoint")) { |
... | ... | |
146 | 146 |
h = lastPoint.getY() - firstPoint.getY(); |
147 | 147 |
|
148 | 148 |
try { |
149 |
getCadToolAdapter().getVectorialAdapter().startComplexRow();
|
|
150 |
|
|
149 |
vea.startComplexRow();
|
|
150 |
///ArrayList selectedRowAux=new ArrayList(); |
|
151 | 151 |
for (int i = 0; i < selectedRow.size(); i++) { |
152 |
DefaultFeature fea = (DefaultFeature) ((DefaultRowEdited) selectedRow
|
|
153 |
.get(i)).getLinkedRow().cloneRow();
|
|
152 |
DefaultRowEdited row=(DefaultRowEdited) selectedRow.get(i);
|
|
153 |
DefaultFeature fea = (DefaultFeature) row.getLinkedRow().cloneRow();
|
|
154 | 154 |
// Rotamos la geometry |
155 | 155 |
UtilFunctions.rotateGeom(fea.getGeometry(), -Math.atan2(w, |
156 | 156 |
h) |
157 | 157 |
+ (Math.PI / 2), firstPoint.getX(), firstPoint |
158 | 158 |
.getY()); |
159 | 159 |
|
160 |
getCadToolAdapter().getVectorialAdapter().modifyRow(i, fea,
|
|
160 |
int index=vea.modifyRow(row.getIndex(), fea,
|
|
161 | 161 |
getName()); |
162 |
///selectedRowAux.add(new DefaultRowEdited(fea,IRowEdited.STATUS_MODIFIED,index)); |
|
162 | 163 |
} |
164 |
|
|
165 |
vea.endComplexRow(); |
|
163 | 166 |
clearSelection(); |
164 |
getCadToolAdapter().getVectorialAdapter().endComplexRow();
|
|
167 |
///selectedRow=selectedRowAux;
|
|
165 | 168 |
} catch (DriverIOException e) { |
166 | 169 |
e.printStackTrace(); |
167 | 170 |
} catch (IOException e1) { |
... | ... | |
183 | 186 |
public void drawOperation(Graphics g, double x, double y) { |
184 | 187 |
RotateCADToolState actualState = ((RotateCADToolContext) _fsm).getState(); |
185 | 188 |
String status = actualState.getName(); |
186 |
ArrayList selectedRow=getSelectedRows(); |
|
189 |
VectorialLayerEdited vle=getVLE(); |
|
190 |
//ArrayList selectedRow=getSelectedRows(); |
|
187 | 191 |
|
188 |
drawHandlers(g, selectedRow, |
|
189 |
getCadToolAdapter().getMapControl().getViewPort() |
|
190 |
.getAffineTransform()); |
|
192 |
// drawHandlers(g, selectedRow,
|
|
193 |
// getCadToolAdapter().getMapControl().getViewPort()
|
|
194 |
// .getAffineTransform());
|
|
191 | 195 |
if (status.equals("Rotate.AngleOrPoint")) { |
192 | 196 |
double w; |
193 | 197 |
double h; |
194 | 198 |
w = x - firstPoint.getX(); |
195 | 199 |
h = y - firstPoint.getY(); |
200 |
ViewPort vp=vle.getLayer().getFMap().getViewPort(); |
|
201 |
Point2D point = vp.fromMapPoint(firstPoint.getX(), |
|
202 |
firstPoint.getY()); |
|
203 |
AffineTransform at = AffineTransform.getRotateInstance(Math.atan2( |
|
204 |
w, h) - (Math.PI / 2), (int) point.getX(), |
|
205 |
(int) point.getY()); |
|
196 | 206 |
|
207 |
Image imgSel = vle.getSelectionImage(); |
|
208 |
((Graphics2D)g).drawImage(imgSel, at, null); |
|
209 |
drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y)); |
|
197 | 210 |
///AffineTransform at = AffineTransform.getRotateInstance(+Math.atan2( |
198 | 211 |
/// w, h) - (Math.PI / 2), (int) point.getX(), |
199 | 212 |
/// (int) point.getY()); |
... | ... | |
203 | 216 |
|
204 | 217 |
///drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y)); |
205 | 218 |
|
206 |
|
|
219 |
/* |
|
207 | 220 |
for (int i = 0; i < selectedRow.size(); i++) { |
208 | 221 |
// IGeometry geometry = |
209 | 222 |
// getCadToolAdapter().getVectorialAdapter().getShape(i); |
... | ... | |
225 | 238 |
CADTool.drawingSymbol); |
226 | 239 |
|
227 | 240 |
} |
241 |
*/ |
|
242 |
}else{ |
|
243 |
Image imgSel = vle.getSelectionImage(); |
|
244 |
g.drawImage(imgSel, 0, 0, null); |
|
245 |
Image imgHand = vle.getHandlersImage(); |
|
246 |
g.drawImage(imgHand, 0, 0, null); |
|
228 | 247 |
} |
229 | 248 |
} |
230 | 249 |
|
... | ... | |
246 | 265 |
RotateCADToolState actualState = (RotateCADToolState) _fsm.getPreviousState(); |
247 | 266 |
String status = actualState.getName(); |
248 | 267 |
ArrayList selectedRow=getSelectedRows(); |
249 |
|
|
268 |
VectorialLayerEdited vle=getVLE(); |
|
269 |
VectorialEditableAdapter vea = vle.getVEA(); |
|
250 | 270 |
if (status.equals("Rotate.AngleOrPoint")) { |
251 | 271 |
try { |
272 |
|
|
273 |
vea.startComplexRow(); |
|
274 |
///ArrayList selectedRowAux=new ArrayList(); |
|
252 | 275 |
for (int i = 0; i < selectedRow.size(); i++) { |
253 |
DefaultFeature fea = (DefaultFeature) ((DefaultRowEdited) selectedRow
|
|
254 |
.get(i)).getLinkedRow().cloneRow();
|
|
276 |
DefaultRowEdited row=(DefaultRowEdited) selectedRow.get(i);
|
|
277 |
DefaultFeature fea = (DefaultFeature) row.getLinkedRow().cloneRow();
|
|
255 | 278 |
// Rotamos la geometry |
256 | 279 |
AffineTransform at = new AffineTransform(); |
257 | 280 |
at.rotate(Math.toRadians(d), |
258 | 281 |
firstPoint.getX(), firstPoint.getY()); |
259 | 282 |
fea.getGeometry().transform(at); |
260 |
getCadToolAdapter().getVectorialAdapter().modifyRow(i, fea,getName());
|
|
261 |
|
|
283 |
int index=vea.modifyRow(row.getIndex(), fea,getName());
|
|
284 |
///selectedRowAux.add(new DefaultRowEdited(fea,IRowEdited.STATUS_MODIFIED,index)); |
|
262 | 285 |
} |
286 |
vea.endComplexRow(); |
|
263 | 287 |
clearSelection(); |
288 |
///selectedRow=selectedRowAux; |
|
264 | 289 |
} catch (DriverIOException e) { |
265 | 290 |
e.printStackTrace(); |
266 | 291 |
} catch (IOException e1) { |
Also available in: Unified diff