Revision 4522 trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/ScaleCADTool.java
ScaleCADTool.java | ||
---|---|---|
46 | 46 |
import java.awt.geom.Point2D; |
47 | 47 |
import java.awt.geom.Point2D.Double; |
48 | 48 |
import java.io.IOException; |
49 |
import java.util.ArrayList; |
|
49 | 50 |
|
50 | 51 |
import com.iver.andami.PluginServices; |
51 | 52 |
import com.iver.cit.gvsig.CADExtension; |
52 | 53 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
53 | 54 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
54 | 55 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
56 |
import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited; |
|
55 | 57 |
import com.iver.cit.gvsig.fmap.edition.UtilFunctions; |
56 | 58 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
57 | 59 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
... | ... | |
118 | 120 |
FBitSet selection = CADExtension.getCADToolAdapter() |
119 | 121 |
.getVectorialAdapter().getSelection(); |
120 | 122 |
|
121 |
if (selection.cardinality() == 0) { |
|
123 |
if (selection.cardinality() == 0 && !CADExtension.getCADToolAdapter().getCadTool().getClass().getName().equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) {
|
|
122 | 124 |
CADExtension.setCADTool("selection"); |
123 | 125 |
((SelectionCADTool) CADExtension.getCADToolAdapter().getCadTool()).setNextTool( |
124 | 126 |
"scale"); |
... | ... | |
135 | 137 |
public void addPoint(double x, double y,InputEvent event) { |
136 | 138 |
ScaleCADToolState actualState = (ScaleCADToolState) _fsm.getPreviousState(); |
137 | 139 |
String status = actualState.getName(); |
138 |
VectorialEditableAdapter vea = getCadToolAdapter().getVectorialAdapter(); |
|
139 |
FBitSet selection = vea.getSelection(); |
|
140 | 140 |
|
141 | 141 |
|
142 | 142 |
if (status.equals("Scale.PointMain")) { |
... | ... | |
146 | 146 |
PluginServices.getMDIManager().setWaitCursor(); |
147 | 147 |
lastPoint = new Point2D.Double(x, y); |
148 | 148 |
|
149 |
double w; |
|
150 |
double h; |
|
151 |
w = lastPoint.getX() - firstPoint.getX(); |
|
152 |
h = lastPoint.getY() - firstPoint.getY(); |
|
149 |
//double w;
|
|
150 |
//double h;
|
|
151 |
//w = lastPoint.getX() - firstPoint.getX();
|
|
152 |
//h = lastPoint.getY() - firstPoint.getY();
|
|
153 | 153 |
|
154 | 154 |
try { |
155 | 155 |
double size=getCadToolAdapter().getMapControl().getViewPort().toMapDistance(getCadToolAdapter().getMapControl().getWidth()); |
... | ... | |
196 | 196 |
* @param y par?metro x del punto que se pase para dibujar. |
197 | 197 |
*/ |
198 | 198 |
public void drawOperation(Graphics g, double x, double y) { |
199 |
ScaleCADToolState actualState = ((ScaleCADToolContext) _fsm).getState(); |
|
200 |
String status = actualState.getName(); |
|
201 |
VectorialEditableAdapter vea = getCadToolAdapter().getVectorialAdapter(); |
|
202 |
FBitSet selection = vea.getSelection(); |
|
203 |
Point2D currentPoint = new Point2D.Double(x, y); |
|
199 |
ScaleCADToolState actualState = ((ScaleCADToolContext) _fsm).getState(); |
|
200 |
String status = actualState.getName(); |
|
201 |
ArrayList selectedRow = getSelectedRow(); |
|
202 |
Point2D currentPoint = new Point2D.Double(x, y); |
|
204 | 203 |
|
204 |
if (status.equals("Scale.ScaleFactorOrReference")) { |
|
205 |
for (int i = 0; i < selectedRow.size(); i++) { |
|
206 |
DefaultFeature fea = (DefaultFeature) ((DefaultRowEdited) selectedRow |
|
207 |
.get(i)).getLinkedRow(); |
|
208 |
IGeometry geometry = fea.getGeometry(); |
|
209 |
double size = getCadToolAdapter().getMapControl().getViewPort() |
|
210 |
.toMapDistance( |
|
211 |
getCadToolAdapter().getMapControl().getWidth()); |
|
212 |
UtilFunctions.scaleGeom(geometry, firstPoint, firstPoint |
|
213 |
.distance(currentPoint) |
|
214 |
/ (size / 40), firstPoint.distance(currentPoint) |
|
215 |
/ (size / 40)); |
|
216 |
geometry.draw((Graphics2D) g, getCadToolAdapter() |
|
217 |
.getMapControl().getViewPort(), CADTool.modifySymbol); |
|
218 |
drawLine((Graphics2D) g, firstPoint, currentPoint); |
|
219 |
PluginServices.getMainFrame().getStatusBar().setMessage( |
|
220 |
"5", |
|
221 |
"Factor = " + firstPoint.distance(currentPoint) |
|
222 |
/ (size / 40)); |
|
205 | 223 |
|
206 |
if (status.equals("Scale.ScaleFactorOrReference")) { |
|
207 |
try { |
|
208 |
for (int i = 0; i < vea.getRowCount(); i++) { |
|
209 |
if (selection.get(i)) { |
|
210 |
IGeometry geometry = vea.getShape(i); |
|
211 |
double size=getCadToolAdapter().getMapControl().getViewPort().toMapDistance(getCadToolAdapter().getMapControl().getWidth()); |
|
212 |
UtilFunctions.scaleGeom(geometry, firstPoint, |
|
213 |
firstPoint.distance(currentPoint)/(size/40), |
|
214 |
firstPoint.distance(currentPoint)/(size/40)); |
|
215 |
geometry.draw((Graphics2D) g, |
|
216 |
getCadToolAdapter().getMapControl().getViewPort(), |
|
217 |
CADTool.modifySymbol); |
|
218 |
drawLine((Graphics2D) g, firstPoint, currentPoint); |
|
219 |
PluginServices.getMainFrame().getStatusBar().setMessage("5","Factor = "+firstPoint.distance(currentPoint)/(size/40)); |
|
220 |
} |
|
221 |
} |
|
222 |
} catch (DriverIOException e) { |
|
223 |
e.printStackTrace(); |
|
224 |
} catch (IOException e) { |
|
225 |
e.printStackTrace(); |
|
226 | 224 |
} |
225 |
|
|
227 | 226 |
} else if (status.equals("Scale.EndPointScale")) { |
228 |
try {
|
|
229 |
for (int i = 0; i < vea.getRowCount(); i++) {
|
|
230 |
if (selection.get(i)) {
|
|
231 |
IGeometry geometry = vea.getShape(i);
|
|
227 |
for (int i = 0; i < selectedRow.size(); i++) {
|
|
228 |
DefaultFeature fea = (DefaultFeature) ((DefaultRowEdited) selectedRow
|
|
229 |
.get(i)).getLinkedRow();
|
|
230 |
IGeometry geometry = fea.getGeometry();
|
|
232 | 231 |
|
232 |
double distrr = orr.distance(frr); |
|
233 |
double distre = ore.distance(currentPoint); |
|
234 |
double escalado = distre / distrr; |
|
233 | 235 |
|
234 |
double distrr = orr.distance(frr); |
|
235 |
double distre = ore.distance(currentPoint); |
|
236 |
double escalado = distre / distrr; |
|
236 |
UtilFunctions.scaleGeom(geometry, scalePoint, escalado, |
|
237 |
escalado); |
|
238 |
// geometry.scale(scalePoint, escalado, escalado); |
|
239 |
geometry.draw((Graphics2D) g, getCadToolAdapter() |
|
240 |
.getMapControl().getViewPort(), CADTool.modifySymbol); |
|
241 |
drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y)); |
|
237 | 242 |
|
238 |
UtilFunctions.scaleGeom(geometry, scalePoint, escalado, escalado); |
|
239 |
// geometry.scale(scalePoint, escalado, escalado); |
|
240 |
geometry.draw((Graphics2D) g, |
|
241 |
getCadToolAdapter().getMapControl().getViewPort(), |
|
242 |
CADTool.modifySymbol); |
|
243 |
drawLine((Graphics2D) g, firstPoint, |
|
244 |
new Point2D.Double(x, y)); |
|
245 |
} |
|
246 |
} |
|
247 |
} catch (DriverIOException e) { |
|
248 |
e.printStackTrace(); |
|
249 |
} catch (IOException e1) { |
|
250 |
e1.printStackTrace(); |
|
251 | 243 |
} |
252 | 244 |
} |
253 |
}
|
|
245 |
}
|
|
254 | 246 |
|
255 | 247 |
/** |
256 |
* Add a diferent option. |
|
257 |
* |
|
258 |
* @param s Diferent option. |
|
259 |
*/ |
|
248 |
* Add a diferent option. |
|
249 |
* |
|
250 |
* @param s |
|
251 |
* Diferent option. |
|
252 |
*/ |
|
260 | 253 |
public void addOption(String s) { |
261 | 254 |
ScaleCADToolState actualState = (ScaleCADToolState) _fsm.getPreviousState(); |
262 | 255 |
String status = actualState.getName(); |
Also available in: Unified diff