Beispiel #1
0
    def testRayPick(self):
        if not FreeCAD.GuiUp:
            return
        self.planarMesh.append([-16.097176, -29.891157, 15.987688])
        self.planarMesh.append([-16.176304, -29.859991, 15.947966])
        self.planarMesh.append([-16.071451, -29.900553, 15.912505])
        self.planarMesh.append([-16.092241, -29.893408, 16.020439])
        self.planarMesh.append([-16.007210, -29.926180, 15.967641])
        self.planarMesh.append([-16.064457, -29.904951, 16.090832])
        planarMeshObject = Mesh.Mesh(self.planarMesh)

        from pivy import coin
        import FreeCADGui
        Mesh.show(planarMeshObject)
        view = FreeCADGui.ActiveDocument.ActiveView.getViewer()
        rp = coin.SoRayPickAction(
            view.getSoRenderManager().getViewportRegion())
        rp.setRay(coin.SbVec3f(-16.05, 16.0, 16.0), coin.SbVec3f(0, -1, 0))
        rp.apply(view.getSoRenderManager().getSceneGraph())
        pp = rp.getPickedPoint()
        self.failUnless(pp != None)
        det = pp.getDetail()
        self.failUnless(det.getTypeId() == coin.SoFaceDetail.getClassTypeId())
        det = coin.cast(det, str(det.getTypeId().getName()))
        self.failUnless(det.getFaceIndex() == 1)
Beispiel #2
0
 def sendRay(self, mouse_pos):
     """sends a ray trough the scene and return the nearest entity"""
     ray_pick = coin.SoRayPickAction(self.render_manager.getViewportRegion())
     ray_pick.setPoint(coin.SbVec2s(*mouse_pos))
     ray_pick.setRadius(10)
     ray_pick.setPickAll(True)
     ray_pick.apply(self.render_manager.getSceneGraph())
     picked_point = ray_pick.getPickedPointList()
     return self.objByID(picked_point)
Beispiel #3
0
 def sendRay(self, mouse_pos):
     """Send a ray through the scene and return the nearest entity."""
     ray_pick = coin.SoRayPickAction(self.render_manager.getViewportRegion())
     ray_pick.setPoint(coin.SbVec2s(*mouse_pos))
     ray_pick.setRadius(self.pick_radius)
     ray_pick.setPickAll(True)
     ray_pick.apply(self.render_manager.getSceneGraph())
     picked_point = ray_pick.getPickedPointList()
     return self.searchEditNode(picked_point)
Beispiel #4
0
 def SendRay(self, mouse_pos):
     """sends a ray through the scene and return the nearest entity"""
     render_manager = self.view.getViewer().getSoRenderManager()
     ray_pick = coin.SoRayPickAction(render_manager.getViewportRegion())
     ray_pick.setPoint(coin.SbVec2s(*mouse_pos))
     ray_pick.setRadius(20)
     ray_pick.setPickAll(True)
     ray_pick.apply(render_manager.getSceneGraph())
     picked_point = ray_pick.getPickedPointList()
     return self.ObjById(picked_point)
Beispiel #5
0
 def pickCB(self, ecb):
   event=ecb.getEvent()
   arg=None
   if event.getState()==coin.SoMouseButtonEvent.DOWN:
     render_manager=self.view.getViewer().getSoRenderManager()
     doPick=coin.SoRayPickAction(render_manager.getViewportRegion())
     doPick.setPoint(coin.SbVec2s(*ecb.getEvent().getPosition()))
     doPick.apply(render_manager.getSceneGraph())
     points=doPick.getPickedPointList()
     if points.getLength():
       path=points[0].getPath()
       if str(tuple(path)[-2].getName())==self.name: self.pickAction(path,event,arg)
Beispiel #6
0
def objectMouseClick_Coin3d(mouse_pos, pick_radius,TargetNode):
    # This section is from DRAFT
    # It must help in finding the correct node
    # which represent the widget.
    """Get edit node from given screen position."""
    viewer = Gui.ActiveDocument.ActiveView.getViewer()
    render_manager = viewer.getSoRenderManager()
    ray_pick = coin.SoRayPickAction(render_manager.getViewportRegion())
    ray_pick.setPoint(coin.SbVec2s(*mouse_pos))
    ray_pick.setRadius(pick_radius)
    ray_pick.setPickAll(True)
    ray_pick.apply(render_manager.getSceneGraph())
    picked_point = ray_pick.getPickedPoint()
    if picked_point != None and picked_point != 0:
        path = picked_point.getPath()
        if path.containsNode(TargetNode):
            return (path.getNode(path.findNode(TargetNode)))  #Not sure if we need it #TODO should we return only true?
    else:
        return None
Beispiel #7
0
    def pick(self, cursorPos, obj):
        self.vp = obj.ViewObject

        pickAction = coin.SoRayPickAction(self._getViewport())
        pickAction.setPickAll(True)
        pickAction.setRadius(Gui.activeView().getViewer().getPickRadius())
        pickAction.setPoint(coin.SbVec2s(cursorPos))
        path = self._getPathForVP(self.vp)

        sa = coin.SoSearchAction()
        sa.setNode(self.vp.RootNode)
        sa.apply(self._getSceneGraph())
        pickAction.apply(sa.getPath())

        for pp in pickAction.getPickedPointList():
            node = pp.getPath().getTail()
            detail = self._castDetail(pp.getDetail())
            self._updatePicked(node, detail)
        self._clearPreselect()
Beispiel #8
0
    def objectMouseClick_Coin3d(self, mouse_pos, pick_radius, TargetNode):
        # This section is from DRAFT
        # It must help in finding the correct node
        # which represent the widget.
        """[Get the node from given mouse / screen position.]

        Args:
            mouse_pos ([type]): [mouse position clicked or mouse is over the position]
            pick_radius ([tuple]): [ Radius of the circle where the mouse position is surrounded by]
            TargetNode ([SoSeparator]): [coin SoSeparator]

        Returns:
            [SoSeparator]: [Return the coin object if it is found. None if not found]
        """
        viewer = Gui.ActiveDocument.ActiveView.getViewer()
        render_manager = viewer.getSoRenderManager()
        ray_pick = coin.SoRayPickAction(render_manager.getViewportRegion())
        ray_pick.setPoint(coin.SbVec2s(*mouse_pos))
        ray_pick.setRadius(pick_radius)
        ray_pick.setPickAll(True)
        ray_pick.apply(render_manager.getSceneGraph())
        picked_point = ray_pick.getPickedPoint()

        if picked_point is not None and picked_point != 0:
            path = picked_point.getPath()
            if type(TargetNode) == list:
                for nodeInList in TargetNode:
                    if path.containsNode(nodeInList):
                        # print("found",nodeInList)
                        # Not sure if we need it #TODO should we return only true?
                        return (path.getNode(path.findNode(nodeInList)))
                return None  # Not found
            else:
                if path.containsNode(TargetNode):
                    # Not sure if we need it #TODO should we return only true?
                    return (path.getNode(path.findNode(TargetNode)))
        else:
            return None
 def highlight_cb(self, event_callback):
     if not ControlPoint.lock or self.current_point is not None:
         event = event_callback.getEvent()
         pos = event.getPosition()
         render_manager = self.view.getViewer().getSoRenderManager()
         ray_pick = coin.SoRayPickAction(render_manager.getViewportRegion())
         ray_pick.setPoint(coin.SbVec2s(*pos))
         ray_pick.setRadius(10)
         ray_pick.setPickAll(True)
         ray_pick.apply(render_manager.getSceneGraph())
         picked_point = ray_pick.getPickedPointList()
         for point in picked_point:
             path = point.getPath()
             length = path.getLength()
             point = path.getNode(length - 2)
             point = list(
                 filter(lambda ctrl: ctrl.getNodeId() == point.getNodeId(),
                        self.control_points))
             if point != []:
                 if (not hasattr(point[0], 'fix') or not point[0].fix):
                     self.current_point = point[0]
                     break
         else:
             self.current_point = None