예제 #1
0
 def __init__(self, dotted=False, scolor=None, swidth=None, ontop=False):
     line = coin.SoLineSet()
     line.numVertices.setValue(2)
     self.coords = coin.SoCoordinate3()  # this is the coordinate
     self.coords.point.setValues(0, 2, [[0, 0, 0], [1, 0, 0]])
     Tracker.__init__(self, dotted, scolor, swidth, [self.coords, line],
                      ontop)
예제 #2
0
def dim_dash(p1, p2):
    """Return a SoSeparator with a line used to make dimension dashes.

    It is used by `dim_symbol` to create line end symbols
    like `'Tick-2'`, `'DimOvershoot'`, and `'ExtOvershoot'` dashes.

    Parameters
    ----------
    p1: tuple of three floats or Base::Vector3
        A point to define a line vertex.

    p2: tuple of three floats or Base::Vector3
        A point to define a line vertex.

    Returns
    -------
    Coin.SoSeparator
        A Coin object with a `SoLineSet` created from `p1` and `p2`
        as vertices.
    """
    dash = coin.SoSeparator()
    v = coin.SoVertexProperty()
    v.vertex.set1Value(0, p1)
    v.vertex.set1Value(1, p2)
    line = coin.SoLineSet()
    line.vertexProperty = v
    dash.addChild(line)
    return dash
예제 #3
0
 def __init__(self):
     # getting screen distance
     p1 = Draft.get3DView().getPoint((100,100))
     p2 = Draft.get3DView().getPoint((110,100))
     bl = (p2.sub(p1)).Length * (Draft.getParam("snapRange",5)/2)
     pick = coin.SoPickStyle()
     pick.style.setValue(coin.SoPickStyle.UNPICKABLE)
     self.trans = coin.SoTransform()
     self.trans.translation.setValue([0,0,0])
     m1 = coin.SoMaterial()
     m1.transparency.setValue(0.8)
     m1.diffuseColor.setValue([0.4,0.4,0.6])
     c1 = coin.SoCoordinate3()
     c1.point.setValues([[-bl,-bl,0],[bl,-bl,0],[bl,bl,0],[-bl,bl,0]])
     f = coin.SoIndexedFaceSet()
     f.coordIndex.setValues([0,1,2,3])
     m2 = coin.SoMaterial()
     m2.transparency.setValue(0.7)
     m2.diffuseColor.setValue([0.2,0.2,0.3])
     c2 = coin.SoCoordinate3()
     c2.point.setValues([[0,bl,0],[0,0,0],[bl,0,0],[-.05*bl,.95*bl,0],[0,bl,0],
                         [.05*bl,.95*bl,0],[.95*bl,.05*bl,0],[bl,0,0],[.95*bl,-.05*bl,0]])
     l = coin.SoLineSet()
     l.numVertices.setValues([3,3,3])
     s = coin.SoSeparator()
     s.addChild(pick)
     s.addChild(self.trans)
     s.addChild(m1)
     s.addChild(c1)
     s.addChild(f)
     s.addChild(m2)
     s.addChild(c2)
     s.addChild(l)
     Tracker.__init__(self,children=[s],name="planeTracker")
예제 #4
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
예제 #5
0
    def nodeInit(self):
        self.sg = self.view.getSceneGraph()
        self.coord = CoinNodes.coordinate3Node([(0, 0, 0)])
        self.markers = CoinNodes.markerSetNode((1, 0.35, 0.8), 70)
        self.polygon = coin.SoLineSet(
        )  #CoinNodes.sensorPolyNode((0.0,0.5,0.0),1)
        #self.polygon.transparency = 0.7
        #self.polygon.linkTo(self.coord)
        self.switch = coin.SoSwitch()
        self.empty = coin.SoSeparator()
        self.sepa = coin.SoSeparator()
        self.switch.addChild(self.sepa)
        self.switch.addChild(self.empty)
        self.switch.whichChild = 0
        self.sepa.addChild(self.coord)
        self.sepa.addChild(self.markers)
        self.sg.addChild(self.switch)

        self.info = [
            "LMB : add pole", "Del : remove last pole",
            "I / D : Increase / Decrease degree", "Left CTRL : snap",
            "Enter : Accept", "Esc : Abort"
        ]
        self.Block1 = HUD.textArea()
        self.Block1.setFont("Sans", 12.0, (0., 0., 0.))
        self.Block1.text = self.info + ["Degree : %s" % self.curve.Degree]

        self.myHud = HUD.HUD()
        self.myHud.addBlock(self.Block1)
        self.myHud.add()
예제 #6
0
 def __init__(self,dotted=False,scolor=None,swidth=None):
     line = coin.SoLineSet()
     line.numVertices.setValue(4)
     self.coords = coin.SoCoordinate3() # this is the coordinate
     self.coords.point.setValues(0,4,[[0,0,0],[0,0,0],[0,0,0],[0,0,0]])
     Tracker.__init__(self,dotted,scolor,swidth,[self.coords,line],name="dimTracker")
     self.p1 = self.p2 = self.p3 = None
예제 #7
0
 def __init__(self):
     # getting screen distance
     p1 = FreeCADGui.ActiveDocument.ActiveView.getPoint((100, 100))
     p2 = FreeCADGui.ActiveDocument.ActiveView.getPoint((110, 100))
     bl = (p2.sub(p1)).Length * (Base.getParam("snapRange") / 2)
     self.trans = coin.SoTransform()
     self.trans.translation.setValue([0, 0, 0])
     m1 = coin.SoMaterial()
     m1.transparency.setValue(0.8)
     m1.diffuseColor.setValue([0.4, 0.4, 0.6])
     c1 = coin.SoCoordinate3()
     c1.point.setValues([[-bl, -bl, 0], [bl, -bl, 0], [bl, bl, 0], [-bl, bl, 0]])
     f = coin.SoIndexedFaceSet()
     f.coordIndex.setValues([0, 1, 2, 3])
     m2 = coin.SoMaterial()
     m2.transparency.setValue(0.7)
     m2.diffuseColor.setValue([0.2, 0.2, 0.3])
     c2 = coin.SoCoordinate3()
     c2.point.setValues([[0, bl, 0], [0, 0, 0], [bl, 0, 0], [-.05 * bl, .95 * bl, 0], [0, bl, 0],
                         [.05 * bl, .95 * bl, 0], [.95 * bl, .05 * bl, 0], [bl, 0, 0], [.95 * bl, -.05 * bl, 0]])
     l = coin.SoLineSet()
     l.numVertices.setValues([3, 3, 3])
     s = coin.SoSeparator()
     s.addChild(self.trans)
     s.addChild(m1)
     s.addChild(c1)
     s.addChild(f)
     s.addChild(m2)
     s.addChild(c2)
     s.addChild(l)
     Tracker.__init__(self, children=[s])
예제 #8
0
    def _build_drag_line(self):
        """
        Build the drag line for drag operations
        """

        _m = coin.SoMarkerSet()

        _l = coin.SoLineSet()
        _l.numVertices.setValue(2)

        _d = coin.SoDrawStyle()
        _d.linePattern = 0x0f0f
        _d.lineWeight = 2

        _c = coin.SoBaseColor()
        _c.rgb = (0.8, 0.8, 1.0)

        _g = coin.SoGroup()
        _g.addChild(_d)
        _g.addChild(_c)
        _g.addChild(self.drag_line_coord)
        _g.addChild(_m)
        _g.addChild(_l)

        self.root.addChild(_g)
예제 #9
0
    def updateData(self, obj, prop):

        if prop == "Shape":
            if hasattr(self, "centerline"):
                if self.centerline:
                    self.centerlinegroup.removeChild(self.centerline)
            if hasattr(obj.Proxy, "wires"):
                if obj.Proxy.wires:
                    from pivy import coin
                    import re, Part
                    self.centerline = coin.SoSeparator()
                    comp = Part.makeCompound(obj.Proxy.wires)
                    pts = re.findall("point \[(.*?)\]",
                                     comp.writeInventor().replace("\n", ""))
                    pts = [p.split(",") for p in pts]
                    for pt in pts:
                        ps = coin.SoSeparator()
                        plist = []
                        for p in pt:
                            c = []
                            for pstr in p.split(" "):
                                if pstr:
                                    c.append(float(pstr))
                            plist.append(c)
                        coords = coin.SoCoordinate3()
                        coords.point.setValues(plist)
                        ps.addChild(coords)
                        ls = coin.SoLineSet()
                        ls.numVertices = -1
                        ps.addChild(ls)
                        self.centerline.addChild(ps)
                    self.centerlinegroup.addChild(self.centerline)
        ArchComponent.ViewProviderComponent.updateData(self, obj, prop)
예제 #10
0
 def __init__(self, points, color='black'):
     self.ls = coin.SoLineSet()
     self.data = coin.SoCoordinate3()
     self.color = coin.SoMaterial()
     self.points = list(map(vector3D, points))
     self.color.diffuseColor = COLORS[color]
     self.update()
     self += [self.color, self.data, self.ls]
예제 #11
0
    def recompute(self):
        """
        Recompute geometry based on current points
        """
        if not self.points:
            return

        if len(self.points) <= 1:
            return

        if self.wire:
            self.sep.removeChild(self.wire)

        wire = Part.makePolygon(self.points)

        buf = wire.writeInventor(2, 0.01)

        try:
            ivin = coin.SoInput()
            ivin.setBuffer(buf)
            ivob = coin.SoDB.readAll(ivin)

        except:

            import re

            buf = buf.replace('\n', '')
            pts = re.findall(r'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.wire = coin.SoSeparator()
            self.wire.addChild(coords)

            self.sep.addChild(self.wire)

        else:
            if ivob and ivob.getNumChildren() > 1:

                self.wire = ivob.getChild(1).getChild(0)
                self.wire.removeChild(self.wire.getChild(0))
                self.wire.removeChild(self.wire.getChild(0))
                self.sep.addChild(self.wire)

            else:
                App.Console.PrintWarning("""
                    AlignmentTracker.recompute() failed to read Inventor string\n
                """)
예제 #12
0
 def recompute(self):
     if (len(self.points) >= 2):
         if self.bezcurve: self.sep.removeChild(self.bezcurve)
         self.bezcurve = None
         ###            c =  Part.BSplineCurve()  #!!!!!!!!!!!!!!!
         c = Part.BezierCurve()
         # DNC: allows to close the curve by placing ends close to each other
         if (len(self.points) >= 3) and (
             (self.points[0] - self.points[-1]).Length < Draft.tolerance()):
             # YVH: Added a try to bypass some hazardous situations
             try:
                 ###                    c.interpolate(self.points[:-1], True)  #!!!!!!!!!!!!
                 c.setPoles(self.points[:-1])
             except Part.OCCError:
                 pass
         elif self.points:
             try:
                 ###                   c.interpolate(self.points, False)  #!!!!!!!
                 c.setPoles(self.points)
             except Part.OCCError:
                 pass
         c = c.toShape()  #???? c = Part.Edge(c)?, c = Part.Wire(c)??
         buf = c.writeInventor(2, 0.01)
         #fp=open("spline.iv","w")
         #fp.write(buf)
         #fp.close()
         try:
             ivin = coin.SoInput()
             ivin.setBuffer(buf)
             ivob = coin.SoDB.readAll(ivin)
         except:
             # workaround for pivy SoInput.setBuffer() bug
             import re
             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.bezcurve = coin.SoSeparator()
             self.bezcurve.addChild(coords)
             self.bezcurve.addChild(line)
             self.sep.addChild(self.bezcurve)
         else:
             if ivob and ivob.getNumChildren() > 1:
                 self.bezcurve = ivob.getChild(1).getChild(0)
                 self.bezcurve.removeChild(self.bezcurve.getChild(0))
                 self.bezcurve.removeChild(self.bezcurve.getChild(0))
                 self.sep.addChild(self.bezcurve)
             else:
                 FreeCAD.Console.PrintWarning(
                     "bezcurveTracker.recompute() failed to read-in Inventor string\n"
                 )
예제 #13
0
    def attach(self, vobj):
        """Respond to created/restored object event (callback).

        Args:
            vobj -- Related ViewProviderDocumentObject
        """
        # pylint: disable=attribute-defined-outside-init
        self.fpo = vobj.Object

        # Here we create a coin representation
        self.coin = SimpleNamespace()
        scene = Gui.ActiveDocument.ActiveView.getSceneGraph()

        size = 5
        height = 10

        self.coin.geometry = coin.SoSwitch()
        self.coin.node = coin.SoSeparator()
        self.coin.transform = coin.SoTransform()
        self.coin.node.addChild(self.coin.transform)
        self.coin.material = coin.SoMaterial()
        self.coin.node.addChild(self.coin.material)
        self.coin.drawstyle = coin.SoDrawStyle()
        self.coin.drawstyle.style = coin.SoDrawStyle.LINES
        self.coin.drawstyle.lineWidth = 1
        self.coin.drawstyle.linePattern = 0xaaaa
        self.coin.node.addChild(self.coin.drawstyle)
        self.coin.coords = coin.SoCoordinate3()
        self.coin.coords.point.setValues(
            0, 15,
            [(-size * 2, +size, 0),          # Front rectangle
             (+size * 2, +size, 0),          # Front rectangle
             (+size * 2, -size, 0),          # Front rectangle
             (-size * 2, -size, 0),          # Front rectangle
             (-size * 2, +size, 0),          # Front rectangle
             (-size * 2, +size, 0),          # Left triangle
             (0, 0, height * 2),             # Left triangle
             (-size * 2, -size, 0),          # Left triangle
             (+size * 2, +size, 0),          # Right triangle
             (0, 0, height * 2),             # Right triangle
             (+size * 2, -size, 0),          # Right triangle
             (-size * 1.8, 1.2 * +size, 0),  # Up triangle (arrow)
             (0, 1.4 * +size, 0),            # Up triangle (arrow)
             (+size * 1.8, 1.2 * +size, 0),  # Up triangle (arrow)
             (-size * 1.8, 1.2 * +size, 0)]  # Up triangle (arrow)
        )
        self.coin.node.addChild(self.coin.coords)
        self.coin.lineset = coin.SoLineSet()
        self.coin.lineset.numVertices.setValues(0, 4, [5, 3, 3, 4])
        self.coin.node.addChild(self.coin.lineset)

        self.coin.geometry.addChild(self.coin.node)
        self.coin.geometry.whichChild.setValue(coin.SO_SWITCH_ALL)
        scene.addChild(self.coin.geometry)  # Insert back
        vobj.addDisplayMode(self.coin.geometry, "Shaded")

        # Update coin elements with actual object properties
        self._update_placement(self.fpo)
예제 #14
0
    def recompute(self):
        """Recompute the tracker."""
        if self.bezcurve:
            for seg in self.bezcurve:
                self.sep.removeChild(seg)
                seg = None

        self.bezcurve = []

        if (len(self.points) >= 2):
            if self.degree:
                poles = self.points[1:]
                segpoleslst = [poles[x:x+self.degree] for x in range(0, len(poles), (self.degree or 1))]
            else:
                segpoleslst = [self.points]
            startpoint = self.points[0]

            for segpoles in segpoleslst:
                c = Part.BezierCurve()  # last segment may have lower degree
                c.increase(len(segpoles))
                c.setPoles([startpoint] + segpoles)
                c = c.toShape()
                startpoint = segpoles[-1]
                buf = c.writeInventor(2, 0.01)
            # fp=open("spline.iv", "w")
            # fp.write(buf)
            # fp.close()
                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)
                    bezcurveseg = coin.SoSeparator()
                    bezcurveseg.addChild(coords)
                    bezcurveseg.addChild(line)
                    self.sep.addChild(bezcurveseg)
                else:
                    if ivob and ivob.getNumChildren() > 1:
                        bezcurveseg = ivob.getChild(1).getChild(0)
                        bezcurveseg.removeChild(bezcurveseg.getChild(0))
                        bezcurveseg.removeChild(bezcurveseg.getChild(0))
                        self.sep.addChild(bezcurveseg)
                    else:
                        FreeCAD.Console.PrintWarning("bezcurveTracker.recompute() failed to read-in Inventor string\n")
                self.bezcurve.append(bezcurveseg)
예제 #15
0
 def __init__(self, dotted=False, scolor=None, swidth=None):
     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, 5, [[0, 0, 0], [2, 0, 0], [2, 2, 0], [0, 2, 0], [0, 0, 0]])
     Tracker.__init__(self, dotted, scolor, swidth, [self.coords, line])
     self.u = plane.u
     self.v = plane.v
예제 #16
0
 def __init__(self,wire):
     self.line = coin.SoLineSet()
     self.closed = DraftGeomUtils.isReallyClosed(wire)
     if self.closed:
         self.line.numVertices.setValue(len(wire.Vertexes)+1)
     else:
         self.line.numVertices.setValue(len(wire.Vertexes))
     self.coords = coin.SoCoordinate3()
     self.update(wire)
     Tracker.__init__(self,children=[self.coords,self.line],name="wireTracker")
예제 #17
0
 def attach(self, vobj):
     self.seperator = coin.SoSeparator()
     self.point = coin.SoLineSet()
     self.data = coin.SoCoordinate3()
     self.color = coin.SoMaterial()
     self.color.diffuseColor.setValue(0, 0, 0)
     self.seperator.addChild(self.color)
     self.seperator.addChild(self.data)
     self.seperator.addChild(self.point)
     vobj.addDisplayMode(self.seperator, 'out')
예제 #18
0
파일: rhbuilder.py 프로젝트: xy0xy/T-SPLINE
 def __init__(self, points, width=1):
     self.object = coin.SoSeparator()
     self.ls = coin.SoLineSet()
     self.data = coin.SoCoordinate3()
     self.color = coin.SoMaterial()
     self.drawstyle = coin.SoDrawStyle()
     self.points = points
     self.color.diffuseColor = (1., 1., 1.)
     self.drawstyle.lineWidth = width
     self.update()
     self.object += self.color, self.drawstyle, self.data, self.ls
예제 #19
0
 def __init__(self, points, color='black', width=1):
     self.object = coin.SoSeparator()
     self.ls = coin.SoLineSet()
     self.data = coin.SoCoordinate3()
     self.color = coin.SoMaterial()
     self.drawstyle = coin.SoDrawStyle()
     self.points = list(map(vector3D, points))
     self.color.diffuseColor = COLORS[color]
     self.drawstyle.lineWidth = width
     self.update()
     self.object += [self.color, self.drawstyle, self.data, self.ls]
예제 #20
0
    def showStatisticsLine(self, docName , shapeName , pts , color):
        import FreeCADGui
        from pivy import coin
        
        sg = FreeCADGui.getDocument(docName).ActiveView.getSceneGraph()
        lines = coin.SoSeparator()
        self.__setRootNode(docName, sg, lines)
        
        drawStyle = coin.SoDrawStyle()
        drawStyle.style = coin.SoDrawStyle.LINES
        drawStyle.lineWidth = 2
#        drawStyle.pointSize = 3
        lines.addChild(drawStyle)
        
#        norm = coin.SoNormal()
#        norm.vector.setValue(0,0,1)
#        lines.addChild(norm)
        
        # set color for block
        matColors = coin.SoMaterial()
        col = (color[0],color[1],color[2])
#        matColors.ambientColor.setValue(color[0],color[1],color[2])
#        matColors.diffuseColor.setValue(color[0],color[1],color[2])
#        matColors.specularColor.setValue(color[0],color[1],color[2])
        matColors.diffuseColor.setValues(0,len(pts),[col]*len(pts))
        lines.addChild(matColors)

        tmpMatBind = coin.SoMaterialBinding()
        tmpMatBind.value = coin.SoMaterialBinding.PER_PART
        lines.addChild(tmpMatBind)
#        lineColor = coin.SoBaseColor()
#        lineColor.rgb = (color[0],color[1],color[2])
#        lines.addChild(lineColor)

        # point
#        tmpPts = []
#        for i in range(len(pts)-1):
#            tmpPts.append(pts[i])
#            tmpPts.append(pts[i+1])
        data = coin.SoCoordinate3()
#        data.point.setValues(0 , len(tmpPts),tmpPts)
        data.point.setValues(0 , len(pts),pts)
        lines.addChild(data)
        
        lineset=coin.SoLineSet()
        lineset.numVertices.setValues(0,1, [len(pts)] )
#        lineset = coin.SoIndexedLineSet()
#        nums = range(len(pts))
#        nums.append(-1)
#        lineset.coordIndex.setValues(0,len(nums), nums)
        lines.addChild(lineset)
        
        self.__setRootNode(docName, sg , lines)
예제 #21
0
    def get_drag_connection(self):
        """
        Return a SoGroup() object of trackers which connect to the drag select
        """

        _trackers = self.trackers['NODE']

        #get list of sorted trackers
        _selected = [
            _trackers[_k] for _k in sorted(self.gui_action['selected'])
        ]

        #get index values for first and last selected elements
        _idx = [int(_selected[_i].name.split('-')[1]) for _i in [0, -1]]
        _conn = []

        self.connect_idx = 0

        #if our starting node isn't the first, add the previous node
        if _idx[0] > 0:
            _conn.append(_trackers['NODE-' + str(_idx[0] - 1)])
            self.connect_idx = 1

        _conn.append(_selected[0])
        self.drag_start = _selected[0].get()

        #if our ending node isn't the last, add the next node
        if _idx[-1] < len(_trackers) - 1:
            _conn.append(_trackers['NODE-' + str(_idx[-1] + 1)])

        _result = coin.SoGroup()

        _coord = coin.SoCoordinate3()

        for _i, _v in enumerate(_conn):
            _coord.point.set1Value(_i, list(_v.get()))

        _marker = coin.SoMarkerSet()

        _line = coin.SoLineSet()
        _line.numVertices.setValue(_coord.point.getNum())

        _node = coin.SoGroup()
        _node.addChild(_coord)
        _node.addChild(_marker)
        _node.addChild(_line)

        _result.addChild(_node)

        self.connect_coord = _coord

        return _result
예제 #22
0
    def attach(self, vobj):
        """Respond to created/restored object event (callback).

        Args:
            vobj -- Related ViewProviderDocumentObject
        """
        # pylint: disable=attribute-defined-outside-init

        self.fpo = vobj.Object
        PointLight.set_properties(self.fpo)

        # Here we create coin representation, which is in 2 parts: a light,
        # and a geometry (the latter being a lineset embedded inside a switch)
        self.coin = SimpleNamespace()
        scene = Gui.ActiveDocument.ActiveView.getSceneGraph()

        # Create pointlight in scenegraph
        self.coin.light = coin.SoPointLight()
        scene.insertChild(self.coin.light, 0)  # Insert frontwise

        # Create geometry in scenegraph
        self.coin.geometry = coin.SoSwitch()

        self.coin.node = coin.SoSeparator()
        self.coin.transform = coin.SoTransform()
        self.coin.node.addChild(self.coin.transform)
        self.coin.material = coin.SoMaterial()
        self.coin.node.addChild(self.coin.material)
        self.coin.drawstyle = coin.SoDrawStyle()
        self.coin.drawstyle.style = coin.SoDrawStyle.LINES
        self.coin.drawstyle.lineWidth = 1
        self.coin.drawstyle.linePattern = 0xaaaa
        self.coin.node.addChild(self.coin.drawstyle)
        self.coin.coords = coin.SoCoordinate3()
        self.coin.coords.point.setValues(0, len(self.SHAPE), self.SHAPE)
        self.coin.node.addChild(self.coin.coords)
        self.coin.lineset = coin.SoLineSet()
        self.coin.lineset.numVertices.setValues(0,
                                                len(self.SHAPE) // 2,
                                                [2] * (len(self.SHAPE) // 2))
        self.coin.node.addChild(self.coin.lineset)

        self.coin.geometry.addChild(self.coin.node)
        self.coin.geometry.whichChild.setValue(coin.SO_SWITCH_ALL)
        scene.addChild(self.coin.geometry)  # Insert back
        vobj.addDisplayMode(self.coin.geometry, "Shaded")

        # Update coin elements with actual object properties
        self._update_location(self.fpo)
        self._update_color(self.fpo)
        self._update_power(self.fpo)
        self._update_radius(self.fpo)
예제 #23
0
    def __init__(self, sim):
        self.sim = sim

        # Scene axis label
        length = 1
        self.r = coin.SoSeparator()
        st = coin.SoDrawStyle()
        st.lineWidth = 3
        self.r.addChild(st)
        data = {'x': (1, 0, 0), 'y': (0, 1, 0), 'z': (0, 0, 1)}

        #text_ref = coin.SoText2()
        #self.r.addChild(text_ref)
        #text_ref.string = 'Tracer rendering'

        for k in data:

            vx, vy, vz = data[k]
            vec = (length * vx, length * vy, length * vz)

            s1 = coin.SoSeparator()
            la = coin.SoLabel()
            la.label = k
            s1.addChild(la)
            tr1 = coin.SoTranslation()
            tr1.translation = vec
            s1.addChild(tr1)
            self.r.addChild(s1)

            s2 = coin.SoSeparator()
            tr2 = coin.SoTransform()
            tr2.translation.setValue(data[k])
            s2.addChild(tr2)
            matxt = coin.SoMaterial()
            matxt.diffuseColor = data[k]
            s2.addChild(matxt)
            txaxis = coin.SoText2()
            txaxis.string = k
            s2.addChild(txaxis)
            self.r.addChild(s2)

            ma = coin.SoMaterial()
            ma.diffuseColor = data[k]
            self.r.addChild(ma)

            co = coin.SoCoordinate3()
            co.point.setValues(0, 2, [(0, 0, 0), vec])
            self.r.addChild(co)

            ls = coin.SoLineSet()
            ls.numVertices.setValues(0, 1, [2])
            self.r.addChild(ls)
예제 #24
0
 def __init__(self):
     super(Axis, self).__init__()
     self.xAxisSep = coin.SoSeparator()
     self.yAxisSep = coin.SoSeparator()
     self.zAxisSep = coin.SoSeparator()
     self.xaxisColor = coin.SoBaseColor()
     self.yaxisColor = coin.SoBaseColor()
     self.zaxisColor = coin.SoBaseColor()
     self.xaxisColor.rgb  = (0.8,0,0)
     self.xpts = [] #[[p[0]-1000,p[1],p[2]],[p[0]+1000,p[1],p[2]]]
     self.yaxisColor.rgb  = (0,0.8,0)
     self.ypts = [] #[[p[0],p[1]-1000,p[2]],[p[0],p[1]+1000,p[2]]]
     self.zaxisColor.rgb  = (0,0,0.8)
     self.zpts = [] #[[p[0],p[1],p[2]-1000],[p[0],p[1],p[2]+1000]]
     self.xaxis = coin.SoLineSet()
     self.xaxisPoints = coin.SoCoordinate3()
     self.xaxisPoints.point.setValue(0,0,0)
     self.xaxisPoints.point.setValues(0,len(self.xpts),self.xpts)
     self.xAxisSep.addChild(self.xaxisColor)
     self.xAxisSep.addChild(self.xaxisPoints)
     self.xAxisSep.addChild(self.xaxis)
     self.yaxis = coin.SoLineSet()
     self.yaxisPoints = coin.SoCoordinate3()
     self.yaxisPoints.point.setValue(0,0,0)
     self.yaxisPoints.point.setValues(0,len(self.ypts),self.ypts)
     self.yAxisSep.addChild(self.yaxisColor)
     self.yAxisSep.addChild(self.yaxisPoints)
     self.yAxisSep.addChild(self.yaxis)
     self.zaxis = coin.SoLineSet()
     self.zaxisPoints = coin.SoCoordinate3()
     self.zaxisPoints.point.setValue(0,0,0)
     self.zaxisPoints.point.setValues(0,len(self.zpts),self.zpts)
     self.zAxisSep.addChild(self.zaxisColor)
     self.zAxisSep.addChild(self.zaxisPoints)
     self.zAxisSep.addChild(self.zaxis)
     self.xState = False
     self.yState = False
     self.zState = False
예제 #25
0
 def __init__(self):
     col = self.getGridColor()
     pick = coin.SoPickStyle()
     pick.style.setValue(coin.SoPickStyle.UNPICKABLE)
     self.trans = coin.SoTransform()
     self.trans.translation.setValue([0,0,0])
     mat1 = coin.SoMaterial()
     mat1.transparency.setValue(0.7)
     mat1.diffuseColor.setValue(col)
     self.coords1 = coin.SoCoordinate3()
     self.lines1 = coin.SoLineSet()
     mat2 = coin.SoMaterial()
     mat2.transparency.setValue(0.3)
     mat2.diffuseColor.setValue(col)
     self.coords2 = coin.SoCoordinate3()
     self.lines2 = coin.SoLineSet()
     mat3 = coin.SoMaterial()
     mat3.transparency.setValue(0)
     mat3.diffuseColor.setValue(col)
     self.coords3 = coin.SoCoordinate3()
     self.lines3 = coin.SoLineSet()
     self.pts = []
     s = coin.SoSeparator()
     s.addChild(pick)
     s.addChild(self.trans)
     s.addChild(mat1)
     s.addChild(self.coords1)
     s.addChild(self.lines1)
     s.addChild(mat2)
     s.addChild(self.coords2)
     s.addChild(self.lines2)
     s.addChild(mat3)
     s.addChild(self.coords3)
     s.addChild(self.lines3)
     Tracker.__init__(self,children=[s],name="gridTracker")
     self.reset()
예제 #26
0
def dim_dash(p1, p2, color, LineWidth):
    dash = coin.SoSeparator()
    v = coin.SoVertexProperty()
    v.vertex.set1Value(0, p1)
    v.vertex.set1Value(1, p2)
    line = coin.SoLineSet()
    line.vertexProperty = v
    style = coin.SoDrawStyle()
    style.lineWidth = LineWidth
    my_transparency = coin.SoMaterial()
    my_transparency.transparency.setValue(0.5)
    dash.addChild(style)
    dash.addChild(my_transparency)
    dash.addChild(color)
    dash.addChild(line)
    return dash
예제 #27
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")
예제 #28
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)
예제 #29
0
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
예제 #30
0
 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()