Revision 111
trunk/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/FLayoutZooms.java | ||
---|---|---|
21 | 21 |
*/ |
22 | 22 |
package org.gvsig.app.project.documents.layout; |
23 | 23 |
|
24 |
import java.awt.Dimension; |
|
24 | 25 |
import java.awt.Point; |
25 | 26 |
import java.awt.Toolkit; |
26 | 27 |
import java.awt.geom.AffineTransform; |
... | ... | |
258 | 259 |
if (fframes[i] instanceof IFFrameUseFMap) { |
259 | 260 |
IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i]; |
260 | 261 |
if (fframe.getATMap() != null) { |
262 |
|
|
263 |
Point2D vppo1 = FLayoutUtilities.screenCoordinatesToViewportImageCoordinates( |
|
264 |
p1, fframes[i]); |
|
265 |
Point2D vppo2 = FLayoutUtilities.screenCoordinatesToViewportImageCoordinates( |
|
266 |
p2, fframes[i]); |
|
267 |
|
|
261 | 268 |
Point2D px1 = |
262 |
FLayoutFunctions.toMapPoint(p1, fframe.getATMap());
|
|
269 |
FLayoutFunctions.toMapPoint(vppo1, fframe.getATMap());
|
|
263 | 270 |
Point2D px2 = |
264 |
FLayoutFunctions.toMapPoint(p2, fframe.getATMap());
|
|
271 |
FLayoutFunctions.toMapPoint(vppo2, fframe.getATMap());
|
|
265 | 272 |
fframe.setPointsToZoom(px1, px2); |
266 | 273 |
} |
267 | 274 |
} |
... | ... | |
365 | 372 |
* @param p2 |
366 | 373 |
* Punto final del rect?ngulo |
367 | 374 |
*/ |
368 |
public void setViewZoomIn(Point2D p1, Point2D p2) {
|
|
375 |
public void setViewZoomIn(Point2D poi1, Point2D poi2) {
|
|
369 | 376 |
IFFrame[] fframes = layout.getLayoutContext().getFFrames(); |
370 | 377 |
for (int i = 0; i < fframes.length; i++) { |
371 | 378 |
if (fframes[i] instanceof IFFrameUseFMap) { |
372 | 379 |
IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i]; |
373 | 380 |
|
374 | 381 |
if (((IFFrame) fframe).getSelected() != IFFrame.NOSELECT) { |
375 |
// IFFrameUseFMap |
|
376 |
// fframeAux=(IFFrameUseFMap)((IFFrame)fframe).cloneFFrame(layout); |
|
377 |
p1 = FLayoutFunctions.toMapPoint(p1, fframe.getATMap()); |
|
378 |
p2 = FLayoutFunctions.toMapPoint(p2, fframe.getATMap()); |
|
382 |
|
|
383 |
Point2D vppo1 = FLayoutUtilities.screenCoordinatesToViewportImageCoordinates( |
|
384 |
poi1, fframes[i]); |
|
385 |
Point2D vppo2 = FLayoutUtilities.screenCoordinatesToViewportImageCoordinates( |
|
386 |
poi2, fframes[i]); |
|
387 |
|
|
388 |
Point2D.Double mapp1 = FLayoutFunctions.toMapPoint(vppo1, fframe.getATMap()); |
|
389 |
Point2D.Double mapp2 = FLayoutFunctions.toMapPoint(vppo2, fframe.getATMap()); |
|
379 | 390 |
|
380 | 391 |
// Borramos el anterior |
381 | 392 |
observers.notifyObservers(this, |
382 | 393 |
new DefaultLayoutNotification(LayoutNotification.LAYOUT_INVALIDATED)); |
383 | 394 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
384 | 395 |
|
385 |
if (java.lang.Math.abs(p1.getX() - p2.getX()) <= 3) {
|
|
396 |
if (java.lang.Math.abs(poi1.getX() - poi2.getX()) <= 3) {
|
|
386 | 397 |
double nuevoX; |
387 | 398 |
double nuevoY; |
388 | 399 |
double cX; |
389 | 400 |
double cY; |
390 | 401 |
|
391 |
cX = p2.getX(); |
|
392 |
cY = p2.getY(); |
|
402 |
cX = mapp2.getX();
|
|
403 |
cY = mapp2.getY();
|
|
393 | 404 |
|
394 | 405 |
double factor = 1 / MapContext.ZOOMINFACTOR; |
395 | 406 |
|
... | ... | |
408 | 419 |
} else { |
409 | 420 |
// Fijamos el nuevo extent |
410 | 421 |
|
411 |
r.setFrameFromDiagonal(p1, p2);
|
|
422 |
r.setFrameFromDiagonal(mapp1, mapp2);
|
|
412 | 423 |
|
413 | 424 |
// fframeAux.setNewExtent(r); |
414 | 425 |
} |
... | ... | |
458 | 469 |
IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i]; |
459 | 470 |
|
460 | 471 |
if (((IFFrame) fframe).getSelected() != IFFrame.NOSELECT) { |
461 |
// IFFrameUseFMap |
|
462 |
// fframeAux=(IFFrameUseFMap)((IFFrame)fframe).cloneFFrame(layout); |
|
472 |
|
|
463 | 473 |
double nuevoX; |
464 | 474 |
double nuevoY; |
465 | 475 |
double cX; |
466 | 476 |
double cY; |
467 | 477 |
Point pScreen = new Point((int) p2.getX(), (int) p2.getY()); |
468 |
pWorld = |
|
469 |
FLayoutFunctions.toMapPoint(pScreen, fframe.getATMap()); |
|
478 |
|
|
479 |
Point2D vppo1 = FLayoutUtilities.screenCoordinatesToViewportImageCoordinates( |
|
480 |
pScreen, fframes[i]); |
|
481 |
|
|
482 |
pWorld = FLayoutFunctions.toMapPoint(vppo1, fframe.getATMap()); |
|
470 | 483 |
|
471 | 484 |
cX = pWorld.getX(); |
472 | 485 |
cY = pWorld.getY(); |
... | ... | |
513 | 526 |
IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i]; |
514 | 527 |
AffineTransform at = fframe.getATMap(); |
515 | 528 |
if (at != null) { |
516 |
Point2D px1 = FLayoutFunctions.toMapPoint(p1, at); |
|
517 |
Point2D px2 = FLayoutFunctions.toMapPoint(p2, at); |
|
529 |
|
|
530 |
Point2D vppo1 = FLayoutUtilities.screenCoordinatesToViewportImageCoordinates( |
|
531 |
p1, fframes[i]); |
|
532 |
Point2D vppo2 = FLayoutUtilities.screenCoordinatesToViewportImageCoordinates( |
|
533 |
p2, fframes[i]); |
|
534 |
|
|
535 |
Point2D px1 = FLayoutFunctions.toMapPoint(vppo1, at); |
|
536 |
Point2D px2 = FLayoutFunctions.toMapPoint(vppo2, at); |
|
518 | 537 |
fframe.movePoints(px1, px2); |
519 | 538 |
} |
520 | 539 |
} |
trunk/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/FLayoutUtilities.java | ||
---|---|---|
21 | 21 |
*/ |
22 | 22 |
package org.gvsig.app.project.documents.layout; |
23 | 23 |
|
24 |
import java.awt.Dimension; |
|
24 | 25 |
import java.awt.Point; |
25 | 26 |
import java.awt.geom.AffineTransform; |
26 | 27 |
import java.awt.geom.NoninvertibleTransformException; |
... | ... | |
30 | 31 |
import java.util.List; |
31 | 32 |
|
32 | 33 |
import org.cresques.cts.IProjection; |
34 |
import org.slf4j.Logger; |
|
35 |
import org.slf4j.LoggerFactory; |
|
33 | 36 |
|
34 | 37 |
import org.gvsig.app.project.documents.Document; |
38 |
import org.gvsig.app.project.documents.layout.fframes.FFrameView; |
|
39 |
import org.gvsig.app.project.documents.layout.fframes.IFFrame; |
|
40 |
import org.gvsig.app.project.documents.layout.fframes.IFFrameUseFMap; |
|
35 | 41 |
import org.gvsig.app.project.documents.view.ViewDocument; |
36 | 42 |
import org.gvsig.fmap.mapcontext.MapContext; |
37 | 43 |
import org.gvsig.fmap.mapcontext.ViewPort; |
... | ... | |
45 | 51 |
* @author Vicente Caballero Navarro |
46 | 52 |
*/ |
47 | 53 |
public class FLayoutUtilities { |
54 |
|
|
55 |
private static Logger logger = LoggerFactory.getLogger( |
|
56 |
FLayoutUtilities.class); |
|
48 | 57 |
|
49 | 58 |
/** |
50 | 59 |
* Devuelve true si las dos ArrayList que se le pasan como parametro son |
... | ... | |
379 | 388 |
return false; |
380 | 389 |
} |
381 | 390 |
|
391 |
public static Point2D screenCoordinatesToViewportImageCoordinates( |
|
392 |
Point2D screenp, IFFrame frame) { |
|
393 |
|
|
394 |
if (screenp == null || frame == null || !(frame instanceof IFFrameUseFMap)) { |
|
395 |
|
|
396 |
logger.info("Bad parameters in screenCoordinatesToViewportImageCoordinates", |
|
397 |
new Exception("Null values or Frame has no MapContext")); |
|
398 |
return screenp; |
|
399 |
} |
|
400 |
|
|
401 |
Rectangle2D.Double rect = frame.getBoundingBox(null); |
|
402 |
|
|
403 |
double screenRectWidth = rect.width; |
|
404 |
double vpWidth = ((IFFrameUseFMap) frame).getMapContext().getViewPort().getImageWidth(); |
|
405 |
if (screenRectWidth < 1 || vpWidth < 1) { |
|
406 |
logger.info("Bad size in screen/viewport (" |
|
407 |
+ "screenRectWidth = " + screenRectWidth + ", " |
|
408 |
+ "vpWidth = " + vpWidth + ")"); |
|
409 |
return screenp; |
|
410 |
} |
|
411 |
|
|
412 |
/* |
|
413 |
* Get coordinates in the rectangle (remove offset) |
|
414 |
*/ |
|
415 |
Point2D po = new Point2D.Double( |
|
416 |
screenp.getX() - rect.x, screenp.getY() - rect.y); |
|
417 |
|
|
418 |
double ratio = (vpWidth * 1d) / (screenRectWidth * 1d); |
|
419 |
Point2D resp = new Point2D.Double(ratio * po.getX(), ratio * po.getY()); |
|
420 |
return resp; |
|
421 |
} |
|
382 | 422 |
|
423 |
|
|
383 | 424 |
|
384 | 425 |
} |
Also available in: Unified diff