Hello,

I'm implementing a J(DOM)tree allowing to zoom and pan (the JSVGCanvas) on the element selected in the tree.

Inspired by FindDialog class of Squiggle, I implemented this function as shown bellow. I'm not sure if it is the best way to do this.

My problem is : It doesn't take into account the successive transform of parent nodes. (given by <g transform="translate(100,200)"> for instance)

Do I need to parse each "transform" attribute of the parents ?
Is there a simpler way to implement this functionnality (getting the global bounding box of an element)?


Thanks
        Tom

[...]

if (node instanceof SVGLocatable) {
 SVGRect bb = ((SVGLocatable)node).getBBox();
 Rectangle2D shape;
 try {
  shape = new
   Rectangle2D.Double(bb.getX(),bb.getY(),bb.getWidth(),bb.getHeight());
 } catch (NullPointerException e) { return;}
 AffineTransform at;
 boolean centerZoom = false;
 if (centerZoom) {
  at = svgCanvas.getInitialTransform();
 } else {
  at = svgCanvas.getRenderingTransform();
 }
 Rectangle2D gnb = at.createTransformedShape(shape).getBounds();
 Dimension canvasSize = svgCanvas.getSize();
 AffineTransform Tx = AffineTransform.getTranslateInstance(
                        -gnb.getX()-gnb.getWidth()/2,
                        -gnb.getY()-gnb.getHeight()/2);

 if (centerZoom) {
  double sx = canvasSize.width/gnb.getWidth();
  double sy = canvasSize.height/gnb.getHeight();
  double scale = Math.min(sx,sy);
  if (scale > 1) {
   Tx.preConcatenate(AffineTransform.getScaleInstance(scale,scale));
  }
 }
 Tx.preConcatenate(AffineTransform.getTranslateInstance(
                           canvasSize.width/2,canvasSize.height/2));
                                        
 AffineTransform newRT = new AffineTransform(at);
 newRT.preConcatenate(Tx);
 svgCanvas.setRenderingTransform(newRT);
}
[...]
--
______________________________________
Thomas Estier

Field and Space Robotics

Autonomous Systems Lab
I2S-LSA
Swiss Federal Institute of Technology
1015 Lausanne EPFL
Switzerland

Tel, Fax (+41 21 693) 38 85 / 78 07
http://dmtwww.epfl.ch/isr/asl/
email: [EMAIL PROTECTED]
______________________________________
IEEE/RSJ International Conference on
Intelligent Robots and Systems

IROS 2002 : http://iros02.epfl.ch


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to