Exemple #1
0
 def attach(self, vobj):
     self.bubbles = None
     self.bubbletexts = []
     sep = coin.SoSeparator()
     self.mat = coin.SoMaterial()
     self.linestyle = coin.SoDrawStyle()
     self.linecoords = coin.SoCoordinate3()
     self.lineset = coin.SoType.fromName("SoBrepEdgeSet").createInstance()
     self.bubbleset = coin.SoSeparator()
     sep.addChild(self.mat)
     sep.addChild(self.linestyle)
     sep.addChild(self.linecoords)
     sep.addChild(self.lineset)
     sep.addChild(self.bubbleset)
     vobj.addDisplayMode(sep, "Default")
     self.onChanged(vobj, "BubbleSize")
Exemple #2
0
    def __init__(self):

        #generate coordinates
        _coords = self.generate_coordinates()

        #build node structure
        self.node = coin.SoSeparator()
        self.trackers = []

        self.active_node = -1
        self.size = 1.0

        self.tracker_node = coin.SoSeparator()
        self.crosshair_transform = coin.SoTransform()

        for _i, _v in enumerate(_coords):

            _t = NodeTracker(_i, _v)
            self.trackers.append(_t)
            self.tracker_node.addChild(_t.node)

        #build wire node structure
        _wire_coord = coin.SoCoordinate3()
        _wire_coord.point.setValues(_coords)

        _wire_node = coin.SoSeparator()
        _wire_node.addChild(_wire_coord)
        _wire_node.addChild(coin.SoLineSet())

        #add wire and node trackers to main node
        self.node.addChild(self.tracker_node)
        self.node.addChild(_wire_node)

        #set up event callbacks
        self.view = Gui.ActiveDocument.ActiveView
        self.view.addEventCallback(
            'SoLocation2Event', self.mouse_event)

        #add nodes and crosshair
        _fn = lambda _x: self.view.getSceneGraph().insertChild(_x, 0)

        self.crosshair = self.create_crosshair()

        todo.delay(_fn, self.node)
        todo.delay(_fn, self.crosshair)

        todo.delay(Gui.SendMsgToActiveView, "ViewFit")
Exemple #3
0
    def __init__(self, points, vertices, **kwargs):
        """Initialize object.

        Args:
            points -- points for the shape (iterable of 3-uples)
            vertices -- vertices for the shape (iterable)

        Keyword args:
            wireframe -- flag to draw a wireframe (SoLineSet) rather than a
                shaded object (SoFaceSet)
            drawstyle -- a Coin SoDrawStyle object to describe draw style
                (optional)
            material -- a Coin SoMaterial object to describe material
                (optional)
        """
        super().__init__()

        # Drawstyle
        try:
            self.drawstyle = kwargs["drawstyle"]
        except KeyError:
            self.drawstyle = coin.SoDrawStyle()
            self.drawstyle.lineWidth = 1
            self.drawstyle.linePattern = 0xAAAA
            self.drawstyle.style = coin.SoDrawStyle.FILLED
        finally:
            self.display_group.addChild(self.drawstyle)

        # Material
        try:
            self.material = kwargs["material"]
        except KeyError:
            self.material = coin.SoMaterial()
        finally:
            self.display_group.addChild(self.material)

        # Coordinates
        self.coords = coin.SoCoordinate3()
        self.coords.point.setValues(0, len(points), points)
        self.display_group.addChild(self.coords)

        # Shape (faceset or lineset)
        wireframe = kwargs.get("wireframe", False)
        self.shape = coin.SoLineSet() if wireframe else coin.SoFaceSet()
        self.shape.numVertices.setValues(0, len(vertices), vertices)
        self.display_group.addChild(self.shape)
Exemple #4
0
 def attach(self, vobj):
     self.Object = vobj.Object
     from pivy import coin
     sep = coin.SoSeparator()
     self.coords = coin.SoCoordinate3()
     sep.addChild(self.coords)
     self.coords.point.deleteValues(0)
     symbol = coin.SoMarkerSet()
     symbol.markerIndex = coin.SoMarkerSet.CIRCLE_FILLED_5_5
     sep.addChild(symbol)
     rn = vobj.RootNode
     rn.addChild(sep)
     self.hiresgroup = coin.SoGroup()
     self.meshcolor = coin.SoBaseColor()
     self.hiresgroup.addChild(self.meshcolor)
     vobj.addDisplayMode(self.hiresgroup, "Mesh")
     ArchComponent.ViewProviderComponent.attach(self, vobj)
Exemple #5
0
 def __init__(self,dotted=False,scolor=None,swidth=None,face=False):
     self.origin = Vector(0,0,0)
     line = coin.SoLineSet()
     line.numVertices.setValue(5)
     self.coords = coin.SoCoordinate3() # this is the coordinate
     self.coords.point.setValues(0,50,[[0,0,0],[2,0,0],[2,2,0],[0,2,0],[0,0,0]])
     if face:
         m1 = coin.SoMaterial()
         m1.transparency.setValue(0.5)
         m1.diffuseColor.setValue([0.5,0.5,1.0])
         f = coin.SoIndexedFaceSet()
         f.coordIndex.setValues([0,1,2,3])
         Tracker.__init__(self,dotted,scolor,swidth,[self.coords,line,m1,f],name="rectangleTracker")
     else:
         Tracker.__init__(self,dotted,scolor,swidth,[self.coords,line],name="rectangleTracker")
     self.u = FreeCAD.DraftWorkingPlane.u
     self.v = FreeCAD.DraftWorkingPlane.v
    def createExtensionSoSwitch(self, ext):
        sep = coin.SoSeparator()
        pos = coin.SoTranslation()
        mat = coin.SoMaterial()
        crd = coin.SoCoordinate3()
        fce = coin.SoFaceSet()
        hnt = coin.SoShapeHints()

        if not ext is None:
            try:
                wire =  ext.getWire()
            except FreeCAD.Base.FreeCADError:
                wire = None
            if wire:
                if isinstance(wire, (list, tuple)):
                    p0 = [p for p in wire[0].discretize(Deflection=0.02)]
                    p1 = [p for p in wire[1].discretize(Deflection=0.02)]
                    p2 = list(reversed(p1))
                    polygon = [(p.x, p.y, p.z) for p in (p0 + p2)]
                else:
                    poly = [p for p in wire.discretize(Deflection=0.02)][:-1]
                    polygon = [(p.x, p.y, p.z) for p in poly]
                crd.point.setValues(polygon)
            else:
                return None

            mat.diffuseColor = self.ColourDisabled
            mat.transparency = self.TransparencyDeselected

            hnt.faceType = coin.SoShapeHints.UNKNOWN_FACE_TYPE
            hnt.vertexOrdering = coin.SoShapeHints.CLOCKWISE

            sep.addChild(pos)
            sep.addChild(mat)
            sep.addChild(hnt)
            sep.addChild(crd)
            sep.addChild(fce)

        switch = coin.SoSwitch()
        switch.addChild(sep)
        switch.whichChild = coin.SO_SWITCH_NONE

        self.material = mat

        return switch
Exemple #7
0
 def attach(self,vobj):
     self.Object = vobj.Object
     from pivy import coin
     tex = coin.SoTexture2()
     tex.image = Draft.loadTexture(Draft.svgpatterns()['simple'][1], 128)
     texcoords = coin.SoTextureCoordinatePlane()
     s = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch").GetFloat("patternScale",0.01)
     texcoords.directionS.setValue(s,0,0)
     texcoords.directionT.setValue(0,s,0)
     self.fcoords = coin.SoCoordinate3()
     self.fset = coin.SoIndexedFaceSet()
     sep = coin.SoSeparator()
     sep.addChild(tex)
     sep.addChild(texcoords)
     sep.addChild(self.fcoords)
     sep.addChild(self.fset)
     vobj.RootNode.addChild(sep)
     ArchComponent.ViewProviderComponent.attach(self,vobj)
 def attach(self,vobj):
     self.Object = vobj.Object
     # adding arrows
     rn = vobj.RootNode
     self.col = coin.SoBaseColor()
     self.setColor()
     ds = coin.SoDrawStyle()
     ds.style = coin.SoDrawStyle.LINES
     self.lcoords = coin.SoCoordinate3()
     ls = coin.SoLineSet()
     ls.numVertices.setValues([2,4,4,2,4,4,2,4,4,2,4,4])
     pt = coin.SoAnnotation()
     pt.addChild(self.col)
     pt.addChild(ds)
     pt.addChild(self.lcoords)
     pt.addChild(ls)
     rn.addChild(pt)
     self.setVerts()
def sceneDrawPath(path, color=(0, 0, 1)):
    coPoint = coin.SoCoordinate3()

    pts = []
    for pt in path:
        pts.append([pt[0], pt[1], topZ])

    coPoint.point.setValues(0, len(pts), pts)
    ma = coin.SoBaseColor()
    ma.rgb = color
    li = coin.SoLineSet()
    li.numVertices.setValue(len(pts))
    pathNode = coin.SoSeparator()
    pathNode.addChild(coPoint)
    pathNode.addChild(ma)
    pathNode.addChild(li)
    sceneGraph.addChild(pathNode)
    scenePathNodes.append(pathNode) #for scene cleanup afterwards
Exemple #10
0
    def __init__(self, points, dynamic=False):
        super(Object3D, self).__init__()
        self.data = coin.SoCoordinate3()
        self.color = coin.SoMaterial()
        self.set_color()
        self += [self.color, self.data]
        self.start_pos = None
        self.dynamic = dynamic

        # callback function lists
        self.on_drag = []
        self.on_drag_release = []
        self.on_drag_start = []

        self._delete = False
        self._tmp_points = None
        self.enabled = True
        self.points = points
Exemple #11
0
 def recompute(self):
     """Recompute the tracker."""
     import Part
     if self.circle:
         self.sep.removeChild(self.circle)
     self.circle = None
     if (self.endangle < self.startangle) or not self.autoinvert:
         c = Part.makeCircle(1, Vector(0, 0, 0), self.normal, self.endangle,
                             self.startangle)
     else:
         c = Part.makeCircle(1, Vector(0, 0, 0), self.normal,
                             self.startangle, self.endangle)
     buf = c.writeInventor(2, 0.01)
     try:
         ivin = coin.SoInput()
         ivin.setBuffer(buf)
         ivob = coin.SoDB.readAll(ivin)
     except Exception:
         # workaround for pivy SoInput.setBuffer() bug
         buf = buf.replace("\n", "")
         pts = re.findall("point \[(.*?)\]", buf)[0]
         pts = pts.split(",")
         pc = []
         for p in pts:
             v = p.strip().split()
             pc.append([float(v[0]), float(v[1]), float(v[2])])
         coords = coin.SoCoordinate3()
         coords.point.setValues(0, len(pc), pc)
         line = coin.SoLineSet()
         line.numVertices.setValue(-1)
         self.circle = coin.SoSeparator()
         self.circle.addChild(coords)
         self.circle.addChild(line)
         self.sep.addChild(self.circle)
     else:
         if ivob and ivob.getNumChildren() > 1:
             self.circle = ivob.getChild(1).getChild(0)
             self.circle.removeChild(self.circle.getChild(0))
             self.circle.removeChild(self.circle.getChild(0))
             self.sep.addChild(self.circle)
         else:
             FreeCAD.Console.PrintWarning(
                 "arcTracker.recompute() failed to read-in Inventor string\n"
             )
Exemple #12
0
    def __init__(self, position=App.Vector(0, 0, 0), radius=1):
        self.trans = coin.SoTransform()
        self.trans.translation.setValue([position.x, position.y, position.z])
        self.line = coin.SoLineSet()
        self.line.numVertices.setValue(4)
        m = coin.SoMaterial()
        m.transparency.setValue(0.9)
        m.diffuseColor.setValue([0, 1, 0])
        self.coords = coin.SoCoordinate3()
        self.coords.point.set1Value(0, [0.0, 0.0, 0.0])
        self.coords.point.set1Value(1, [100.0, 0.0, 0.0])
        self.coords.point.set1Value(2, [200.0, 200.0, 0.0])
        self.coords.point.set1Value(3, [200.0, 400.0, 0.0])

        Tracker.__init__(self,
                         children=[m, self.trans, self.line, self.coords],
                         name="radiusTracker")

        self.on()
Exemple #13
0
 def toNode(shape):
     "builds a pivy node from a simple linear shape"
     from pivy import coin
     buf = shape.writeInventor(2, 0.01)
     buf = buf.replace("\n", "")
     pts = re.findall("point \[(.*?)\]", buf)[0]
     pts = pts.split(",")
     pc = []
     for p in pts:
         v = p.strip().split()
         pc.append([float(v[0]), float(v[1]), float(v[2])])
     coords = coin.SoCoordinate3()
     coords.point.setValues(0, len(pc), pc)
     line = coin.SoLineSet()
     line.numVertices.setValue(-1)
     item = coin.SoSeparator()
     item.addChild(coords)
     item.addChild(line)
     return item
Exemple #14
0
    def attach(self,vobj):

        ArchComponent.ViewProviderComponent.attach(self,vobj)
        from pivy import coin
        self.color = coin.SoBaseColor()
        self.font = coin.SoFont()
        self.text1 = coin.SoAsciiText()
        self.text1.string = " "
        self.text1.justification = coin.SoAsciiText.LEFT
        self.text2 = coin.SoAsciiText()
        self.text2.string = " "
        self.text2.justification = coin.SoAsciiText.LEFT
        self.coords = coin.SoTransform()
        self.header = coin.SoTransform()
        self.label = coin.SoSwitch()
        sep = coin.SoSeparator()
        self.label.whichChild = 0
        sep.addChild(self.coords)
        sep.addChild(self.color)
        sep.addChild(self.font)
        sep.addChild(self.text2)
        sep.addChild(self.header)
        sep.addChild(self.text1)
        self.label.addChild(sep)
        vobj.Annotation.addChild(self.label)
        self.onChanged(vobj,"TextColor")
        self.onChanged(vobj,"FontSize")
        self.onChanged(vobj,"FirstLine")
        self.onChanged(vobj,"LineSpacing")
        self.onChanged(vobj,"FontName")
        self.Object = vobj.Object
        # footprint mode
        self.fmat = coin.SoMaterial()
        self.fcoords = coin.SoCoordinate3()
        self.fset = coin.SoIndexedFaceSet()
        fhints = coin.SoShapeHints()
        fhints.vertexOrdering = fhints.COUNTERCLOCKWISE
        sep = coin.SoSeparator()
        sep.addChild(self.fmat)
        sep.addChild(self.fcoords)
        sep.addChild(fhints)
        sep.addChild(self.fset)
        vobj.RootNode.addChild(sep)
    def __init__(self, marker=False, line=False, color=False, style=False):
        """
        Constructor
        """

        self.group = coin.SoGroup()
        self.coord = coin.SoCoordinate3()
        self.marker = coin.SoMarkerSet()
        self.line = coin.SoLineSet()
        self.color = coin.SoBaseColor()

        self.style = CoinStyles.DEFAULT

        self.group.addChild(self.coord)
        self.group.addChild(self.color)

        if marker:
            self.group.addChild(self.marker)

        self.group.addChild(self.line)
Exemple #16
0
    def __init__(self, id, coord):

        self.node = coin.SoSeparator()
        self.coordinate = coin.SoCoordinate3()
        self.transform = coin.SoTransform()
        self.point = coord

        _selection_node = \
            coin.SoType.fromName("SoFCSelection").createInstance()

        _selection_node.documentName.setValue('Document')
        _selection_node.objectName.setValue('Test Tracker')
        _selection_node.subElementName.setValue(str(id))

        self.node.addChild(_selection_node)
        self.node.addChild(self.transform)
        self.node.addChild(self.coordinate)
        self.node.addChild(coin.SoMarkerSet())

        self.coordinate.point.setValue(tuple(coord))
Exemple #17
0
 def onChanged(self, vobj, prop):
     if prop == "Positions":
         if not vobj.Draw:
             return
         if vobj.Proxy.indexPosition:
             po = list(vobj.Positions[vobj.Proxy.indexPosition-1:])
         else:
             po = list(vobj.Positions[vobj.Proxy.indexPosition:])
         vobj.Proxy.indexPosition = len(vobj.Positions)
         co = coin.SoCoordinate3()
         co.point.setValues(0, len(po), po)
         ma = coin.SoBaseColor()
         ma.rgb = vobj.Color[0:3]
         li = coin.SoLineSet()
         li.numVertices.setValue(len(po))
         no = coin.SoSeparator()
         no.addChild(co)
         no.addChild(ma)
         no.addChild(li)
         vobj.RootNode.addChild(no)
Exemple #18
0
 def attach(self, vobj):
     Draft._ViewProviderDraft.attach(self, vobj)
     from pivy import coin
     self.coords = coin.SoCoordinate3()
     self.lineset = coin.SoLineSet()
     self.lineset.numVertices.setValue(-1)
     lineStyle = coin.SoDrawStyle()
     lineStyle.linePattern = 0x0f0f
     self.color = coin.SoBaseColor()
     self.switch = coin.SoSwitch()
     sep = coin.SoSeparator()
     self.switch.whichChild = -1
     sep.addChild(self.color)
     sep.addChild(lineStyle)
     sep.addChild(self.coords)
     sep.addChild(self.lineset)
     self.switch.addChild(sep)
     vobj.Annotation.addChild(self.switch)
     self.onChanged(vobj, "ShowMargin")
     self.onChanged(vobj, "LineColor")
Exemple #19
0
    def __init__(self, pos, object_name, node_name, marker_type, marker_size):

        self.pos = pos
        self.name = node_name

        self.inactive = False

        self.color = coin.SoBaseColor()

        self.marker = coin.SoMarkerSet()

        self.marker.markerIndex = Gui.getMarkerIndex(marker_type, marker_size)

        self.coords = coin.SoCoordinate3()
        self.coords.point.setValue((pos.x, pos.y, pos.z))

        selnode = None

        if self.inactive:
            selnode = coin.SoSeparator()

        else:
            selnode = coin.SoType.fromName("SoFCSelection").createInstance()
            selnode.documentName.setValue(App.ActiveDocument.Name)
            selnode.objectName.setValue(object_name)
            selnode.subElementName.setValue(node_name)

        node = coin.SoAnnotation()

        selnode.addChild(self.coords)
        selnode.addChild(self.color)
        selnode.addChild(self.marker)

        node.addChild(selnode)

        ontop = not self.inactive

        Tracker.__init__(
            self, children=[node], ontop=ontop, name="EditTracker")

        self.on()
Exemple #20
0
    def attach(self, obj):
        "Setup the scene sub-graph of the view provider, this method is mandatory"
        self.shaded = coin.SoGroup()
        self.wireframe = coin.SoGroup()
        self.color = coin.SoBaseColor()

        self.data = coin.SoCoordinate3()
        self.face = coin.SoIndexedFaceSet()

        self.shaded.addChild(self.color)
        self.shaded.addChild(self.data)
        self.shaded.addChild(self.face)
        obj.addDisplayMode(self.shaded, "Shaded")
        style = coin.SoDrawStyle()
        style.style = coin.SoDrawStyle.LINES
        self.wireframe.addChild(style)
        self.wireframe.addChild(self.color)
        self.wireframe.addChild(self.data)
        self.wireframe.addChild(self.face)
        obj.addDisplayMode(self.wireframe, "Wireframe")
        self.onChanged(obj, "Color")
Exemple #21
0
 def __init__(self, pos=Vector(0, 0, 0), name="None", idx=0, objcol=None):
     color = coin.SoBaseColor()
     if objcol:
         color.rgb = objcol[:3]
     else:
         color.rgb = FreeCADGui.draftToolBar.getDefaultColor("snap")
     self.marker = coin.SoMarkerSet()  # this is the marker symbol
     self.marker.markerIndex = coin.SoMarkerSet.SQUARE_FILLED_9_9
     self.coords = coin.SoCoordinate3()  # this is the coordinate
     self.coords.point.setValue((pos.x, pos.y, pos.z))
     selnode = coin.SoType.fromName("SoFCSelection").createInstance()
     selnode.documentName.setValue(FreeCAD.ActiveDocument.Name)
     selnode.objectName.setValue(name)
     selnode.subElementName.setValue("EditNode" + str(idx))
     node = coin.SoAnnotation()
     selnode.addChild(self.coords)
     selnode.addChild(color)
     selnode.addChild(self.marker)
     node.addChild(selnode)
     Tracker.__init__(self, children=[node], ontop=True)
     self.on()
    def create_crosshair(self):

        _switch = coin.SoSwitch()
        _node = coin.SoSeparator()
        _coord = coin.SoCoordinate3()
        _transform = coin.SoTransform()

        self.crosshair_coord.point.setValues(0, 5, [(1.0, 0.0, 0.0),
                                                    (0.0, 1.0, 0.0),
                                                    (-1.0, 0.0, 0.0),
                                                    (0.0, -1.0, 0.0),
                                                    (1.0, 0.0, 0.0)])
        _nodes = [_transform, self.crosshair_coord, coin.SoLineSet()]

        for _v in _nodes:
            _node.addChild(_v)

        _switch.addChild(_node)
        _switch.whichChild = -1

        return _switch
Exemple #23
0
    def attach(self, vobj):
        #self.__init__(vobj)  # Fehler Bei loeschen + strg-z
        self.shaded = coin.SoSeparator()

        t = coin.SoType.fromName("SoBrepEdgeSet")
        self.lineset = t.createInstance()

        self.lineset.highlightIndex = -1
        self.lineset.selectionIndex = 0
        self.color = coin.SoBaseColor()
        c = vobj.LineColor
        self.color.rgb.setValue(c[0], c[1], c[2])
        self.drawstyle = coin.SoDrawStyle()
        self.drawstyle.lineWidth = 1
        self.data = coin.SoCoordinate3()
        self.shaded.addChild(self.color)
        self.shaded.addChild(self.drawstyle)
        self.shaded.addChild(self.data)
        self.shaded.addChild(self.lineset)
        vobj.addDisplayMode(self.shaded, 'Shaded')
        pass
Exemple #24
0
 def __init__(self, points, dynamic=False):
     super(Object3D, self).__init__()
     self._sel_color = COLORS[self.sel_col]
     self._ovr_color = COLORS[self.ovr_col]
     self._std_color = COLORS[self.std_col]
     self.data = coin.SoCoordinate3()
     self.color = coin.SoMaterial()
     self.color.diffuseColor = self._std_color
     self.addChild(self.color)
     self.addChild(self.data)
     self.start_pos = None
     self.dynamic = dynamic
     self.on_drag = []
     self.on_drag_release = []
     self.on_drag_start = []
     self._delete = False
     self._tmp_points = None
     self.enabled = True
     if depth(points) != 2:
         raise AttributeError('depth of list should be 2')
     self.points = points
Exemple #25
0
 def onChanged(self, vobj, prop):
     if prop == "ShowNodes":
         if hasattr(self, "nodes"):
             vobj.Annotation.removeChild(self.nodes)
             del self.nodes
         if vobj.ShowNodes:
             from pivy import coin
             self.nodes = coin.SoAnnotation()
             self.coords = coin.SoCoordinate3()
             self.mat = coin.SoMaterial()
             self.pointstyle = coin.SoDrawStyle()
             self.pointstyle.style = coin.SoDrawStyle.POINTS
             self.pointset = coin.SoType.fromName(
                 "SoBrepPointSet").createInstance()
             self.linestyle = coin.SoDrawStyle()
             self.linestyle.style = coin.SoDrawStyle.LINES
             self.lineset = coin.SoType.fromName(
                 "SoBrepEdgeSet").createInstance()
             self.nodes.addChild(self.coords)
             self.nodes.addChild(self.mat)
             self.nodes.addChild(self.pointstyle)
             self.nodes.addChild(self.pointset)
             self.nodes.addChild(self.linestyle)
             self.nodes.addChild(self.lineset)
             vobj.Annotation.addChild(self.nodes)
             self.updateData(vobj.Object, "Nodes")
             self.onChanged(vobj, "NodeColor")
             self.onChanged(vobj, "NodeLine")
             self.onChanged(vobj, "NodeSize")
     elif prop == "NodeColor":
         if hasattr(self, "mat"):
             l = vobj.NodeColor
             self.mat.diffuseColor.setValue([l[0], l[1], l[2]])
     elif prop == "NodeLine":
         if hasattr(self, "linestyle"):
             self.linestyle.lineWidth = vobj.NodeLine
     elif prop == "NodeSize":
         if hasattr(self, "pointstyle"):
             self.pointstyle.pointSize = vobj.NodeSize
     ArchComponent.ViewProviderComponent.onChanged(self, vobj, prop)
Exemple #26
0
    def update_arrow(self, obj, vobj):
        """Update the arrow tip of the line."""
        if hasattr(self, "symbol"):
            if self.arrow.findChild(self.symbol) != -1:
                self.arrow.removeChild(self.symbol)

        s = utils.ARROW_TYPES.index(vobj.ArrowType)
        self.symbol = gui_utils.dim_symbol(s)

        if vobj.ArrowType == "Circle":
            # TODO: fix behavior of the 'Circle' marker.
            # Instead of appearing at the tip of the line
            # the 'Circle' marker appears displaced and duplicated
            # a certain distance from the tip, which is the `TargetPoint`.
            # Somehow the translation is added to the position of the tip
            # resulting in a wrong value.
            # So the arrow position is reset; nevertheless, this doesn't
            # entirely fix the issue.
            coords2 = coin.SoCoordinate3()
            coords2.point.setValues([obj.Points[-1]])
            self.arrow.addChild(coords2)
            self.arrowpos.translation.setValue((0, 0, 0))
        else:
            self.arrowpos.translation.setValue(obj.Points[-1])
        self.arrow.addChild(self.symbol)

        v1 = obj.Points[-2].sub(obj.Points[-1])

        if not DraftVecUtils.isNull(v1):
            v1.normalize()
            v2 = App.Vector(0, 0, 1)
            if round(v2.getAngle(v1), 4) in [0, round(math.pi, 4)]:
                v2 = App.Vector(0, 1, 0)

            v3 = v1.cross(v2).negative()

            _rot_mat = DraftVecUtils.getPlaneRotation(v1, v3, v2)
            q = App.Placement(_rot_mat).Rotation.Q
            self.arrowpos.rotation.setValue((q[0], q[1], q[2], q[3]))
Exemple #27
0
    def createGeometry(self):
        node = coin.SoSeparator()

        coords = coin.SoCoordinate3()

        #rectangle
        coords.point.set1Value(0, 0, 0, 0)
        coords.point.set1Value(1, 10000, 0, 0)
        coords.point.set1Value(2, 10000, 0, 10000)
        coords.point.set1Value(3, 0, 0, 10000)

        #triangles
        coords.point.set1Value(4, 0, 0, 0)
        coords.point.set1Value(5, 0, 0, 10000)
        coords.point.set1Value(6, 5000, 5000, 5000)

        coords.point.set1Value(7, 0, 0, 0)
        coords.point.set1Value(8, 10000, 0, 0)
        coords.point.set1Value(9, 5000, 5000, 5000)

        coords.point.set1Value(10, 10000, 0, 0)
        coords.point.set1Value(12, 5000, 5000, 5000)
        coords.point.set1Value(11, 10000, 0, 10000)

        coords.point.set1Value(13, 10000, 0, 10000)
        coords.point.set1Value(14, 5000, 5000, 5000)
        coords.point.set1Value(15, 0, 0, 10000)

        faceset = coin.SoFaceSet()
        faceset.numVertices.set1Value(0, 4)
        faceset.numVertices.set1Value(1, 3)
        faceset.numVertices.set1Value(2, 3)
        faceset.numVertices.set1Value(3, 3)
        faceset.numVertices.set1Value(4, 3)

        node.addChild(coords)
        node.addChild(faceset)

        return node
    def attach(self, vobj):
        self.ViewObject = vobj
        self.Object = vobj.Object
        self.LithophaneImage = self.Object.Proxy

        self.Object.setEditorMode("UpdateNotifier", 2)

        self.imageNode = coin.SoSeparator()

        self.coords = coin.SoCoordinate3()
        self.coords.point.set1Value(0, 0, 0, -1)
        self.coords.point.set1Value(1, 1, 0, -1)
        self.coords.point.set1Value(2, 1, 1, -1)
        self.coords.point.set1Value(3, 0, 1, -1)

        textureCoords = coin.SoTextureCoordinate2()
        textureCoords.point.set1Value(0, 0, 0)
        textureCoords.point.set1Value(1, 1, 0)
        textureCoords.point.set1Value(2, 1, 1)
        textureCoords.point.set1Value(3, 0, 1)

        faceset = coin.SoFaceSet()
        faceset.numVertices.set1Value(0, 4)

        # This makes it possible to select the object in the 3D View
        selectionNode = coin.SoType.fromName("SoFCSelection").createInstance()
        selectionNode.documentName.setValue(FreeCAD.ActiveDocument.Name)
        selectionNode.objectName.setValue(self.Object.Name)
        selectionNode.subElementName.setValue("Face")
        selectionNode.addChild(faceset)

        self.texture = coin.SoTexture2()

        self.imageNode.addChild(self.coords)
        self.imageNode.addChild(textureCoords)
        self.imageNode.addChild(self.texture)
        self.imageNode.addChild(selectionNode)

        vobj.addDisplayMode(self.imageNode, "LithophaneImage")
    def build_connector_group(self):
        """
        Build the SoGroup node which provides the connecting SoLineSet
        geometry to the geometry which is not being selected / dragged
        """

        #select only the valid nodes among three
        _trackers = [
            _c for _c in [
                self.trackers['start'], self.trackers['selected'][0],
                self.trackers['end']
            ] if _c
        ]

        #abort if we don't have at least two coordinates defined
        if len(_trackers) < 2:
            return

        #if end node is picked, reverse array so selected node is still 2nd
        if not self.trackers['start']:
            _trackers = list(reversed(_trackers))

        #build component nodes
        _marker = coin.SoMarkerSet()

        _line = coin.SoLineSet()
        _line.numVertices.setValue(len(_trackers))

        _coord = coin.SoCoordinate3()

        for _i, _v in enumerate(_trackers):
            _coord.point.set1Value(_i, tuple(_v.get()))

        #build the group node with coordinates, markers and lines
        group = self.nodes['connector']
        group.addChild(_coord)
        group.addChild(_marker)
        group.addChild(_line)
Exemple #30
0
    def buildCoordinates(self):
        from pivy import coin

        coords = coin.SoCoordinate3()

        # North Arrow
        coords.point.set1Value(0, 0, 0, 0)
        coords.point.set1Value(1, COMPASS_POINTER_WIDTH, COMPASS_POINTER_WIDTH,
                               0)
        coords.point.set1Value(2, 0, COMPASS_POINTER_LENGTH, 0)
        coords.point.set1Value(3, -COMPASS_POINTER_WIDTH,
                               COMPASS_POINTER_WIDTH, 0)

        # East Arrow
        coords.point.set1Value(4, 0, 0, 0)
        coords.point.set1Value(5, COMPASS_POINTER_WIDTH,
                               -COMPASS_POINTER_WIDTH, 0)
        coords.point.set1Value(6, COMPASS_POINTER_LENGTH, 0, 0)
        coords.point.set1Value(7, COMPASS_POINTER_WIDTH, COMPASS_POINTER_WIDTH,
                               0)

        # South Arrow
        coords.point.set1Value(8, 0, 0, 0)
        coords.point.set1Value(9, -COMPASS_POINTER_WIDTH,
                               -COMPASS_POINTER_WIDTH, 0)
        coords.point.set1Value(10, 0, -COMPASS_POINTER_LENGTH, 0)
        coords.point.set1Value(11, COMPASS_POINTER_WIDTH,
                               -COMPASS_POINTER_WIDTH, 0)

        # West Arrow
        coords.point.set1Value(12, 0, 0, 0)
        coords.point.set1Value(13, -COMPASS_POINTER_WIDTH,
                               COMPASS_POINTER_WIDTH, 0)
        coords.point.set1Value(14, -COMPASS_POINTER_LENGTH, 0, 0)
        coords.point.set1Value(15, -COMPASS_POINTER_WIDTH,
                               -COMPASS_POINTER_WIDTH, 0)

        return coords