Exemple #1
0
 private Bounds getBounds(VisualShape v) {
   Bounds b = null;
   if (v == null) return null;
   if (v.getFaces2(BranchGroup.class) != null) b = v.getFaces2(BranchGroup.class).getBounds();
   if (v.getEdges2(BranchGroup.class) != null)
     b.combine(v.getEdges2(BranchGroup.class).getBounds());
   return b;
 }
Exemple #2
0
  public void draw(DrawModel d) {
    view.detach();
    rotation.removeAllChildren();
    drawModel = d;
    if (drawModel.getPicture() == null) return;
    Integer i = 0;
    for (VisualShape v : drawModel.getPicture()) {
      TransformGroup shapeGroup = new TransformGroup();
      rotation.addChild(shapeGroup);
      BranchGroup faces = v.getFaces2(BranchGroup.class);
      BranchGroup edges = v.getEdges2(BranchGroup.class);
      BranchGroup text = v.getText2(BranchGroup.class);
      if (faces == null && edges == null) continue;
      i++;
      if (faces != null) {
        faces.detach();
        rotation.addChild(faces);
        faces.setPickable(true);
        faces.setUserData(v);
        faces.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
        faces.setName(i.toString());
      }
      if (edges != null) {
        edges.detach();
        rotation.addChild(edges);
        edges.setPickable(true);
        edges.setUserData(v);
        edges.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
        edges.setName(i.toString());
      }

      if (text != null) {
        text.detach();
        rotation.addChild(text);
        text.setPickable(false);
        if (text instanceof BranchGroup) {
          BranchGroup bg = (BranchGroup) text;
          for (int j = 0; j < bg.numChildren(); j++) {
            Node child = bg.getChild(j);
            if (child instanceof TransformGroup) {
              TransformGroup tg = (TransformGroup) child;
              tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
              tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
              textLabels.add(tg);
            }
          }
        }

        //        		edges.setUserData(v);
        //        		edges.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
        //         		edges.setName(i.toString());
      }
    }
    root.addChild(view);
  }
Exemple #3
0
    @Override
    public void updateScene(int xpos, int ypos) {
      // TODO Auto-generated method stub
      //
      //			if ((mevent.getID() == MouseEvent.MOUSE_DRAGGED) &&
      //					!mevent.isAltDown() && mevent.isMetaDown()) {
      //
      ////			if (mevent.getID() == MouseEvent.MOUSE_DRAGGED) {
      //					int x = mevent.getX();
      //					int y = mevent.getY();
      //
      //					int dx = x - x_last;
      //					int dy = y - y_last;
      //
      //					center.x += dx * 0.02;
      //					center.y -= dy * 0.02;
      //
      //					x_last = x;
      //					y_last = y;
      //					updateView();
      //			}
      //			else if (mevent.getID() == MouseEvent.MOUSE_PRESSED) {
      //				x_last = mevent	.getX();
      //				y_last = mevent.getY();
      //			}
      //
      //

      if (!mevent.isMetaDown() && !mevent.isAltDown()) {
        BranchGroup bg = null;
        Shape3D s = null;
        pickCanvas.setFlags(
            PickInfo.NODE | PickInfo.SCENEGRAPHPATH | PickInfo.CLOSEST_INTERSECTION_POINT);
        pickCanvas.setShapeLocation(xpos, ypos);

        PickInfo pickInfo = pickCanvas.pickClosest();
        if (pickInfo != null) {
          //					if (drawing instanceof Mesh) {
          //						Point3d p = pickInfo.getClosestIntersectionPoint();
          //
          //						Mesh m = (Mesh)drawing;
          //						MeshPoint mp = m.find(p.x, p.y, p.z);
          //						if (mp != null) mp.select();
          //
          //						m.setLineColor(Color.GREEN);
          //						m.setLineWidth(5);
          ////						createSceneGraph(drawing);
          //
          ////						view.detach();
          //						draw(drawing);
          ////						root.addChild(view);
          //						return;
          //					}

          System.out.println(pickInfo.getClosestIntersectionPoint());

          bg = (BranchGroup) pickCanvas.getNode(pickInfo, PickTool.TYPE_BRANCH_GROUP);
          //					s = (Shape3D) pickCanvas.getNode(pickInfo, PickTool.TYPE_SHAPE3D);

          if (bg != null) {
            System.out.println("Shape " + bg.getName() + " selected");
            if (bg.getUserData() != null) {
              VisualShape sh = (VisualShape) bg.getUserData();
              Mesh m = sh.getMesh();
              if (m != null) {
                Point3d p3d = pickInfo.getClosestIntersectionPoint();
                m.selectNearestPoint(p3d.x, p3d.y, p3d.z);
                m.createTextLabels();
                System.out.println("Result = " + m.getResult(p3d.x, p3d.y, p3d.z));
                draw(drawModel);
              } else {
                sh.select();
                //								drawing.meshShape(sh);
                //								draw(drawing);
              }

              //							Visible v = (Visible) bg.getUserData();
              //							v.select();
            }
          }

          //					if (s != null) {
          //						System.out.println("Shape "+s.getName()+" selected");
          //						if (s.getUserData() != null) {
          //							Visible v = (Visible) s.getUserData();
          //							v.select();
          //						}
          //
          //					}

        }
      }
    }