コード例 #1
0
    def __init__(self, vectors: List[App.Vector] = [],
                 label: str = [[]], lineWidth=1,
                 _color=FR_COLOR.FR_BLACK,
                 _lblColor=FR_COLOR.FR_WHITE,
                 _rotation=[0.0, 0.0, 1.0, 0.0],
                  _scale: List[float] = [3, 3, 3],
                 _arrowType=0,
                 _opacity: float = 0.0):
        # Must be initialized first as per the following discussion.
        # https://stackoverflow.com/questions/67877603/how-to-override-a-function-in-an-inheritance-hierarchy#67877671
        super().__init__(vectors, label)

        self.w_lineWidth = lineWidth  # Default line width
        self.w_widgetType = constant.FR_WidgetType.FR_ARROW

        self.w_callback_ = callback  # External function
        self.w_lbl_calback_ = callback  # External function
        self.w_KB_callback_ = callback  # External function
        self.w_move_callback_ = callback  # External function
        self.w_wdgsoSwitch = coin.SoSwitch()
        self.w_color = _color  # Default color is green
        self.w_rotation = _rotation  # (x,y,z), Angle
        self.w_userData = userDataObject()   # Keep info about the widget
        self.w_userData.ArrowObj = self
        self.releaseDrag = -1  # -1 mouse no clicked not dragging, 0 is clicked, 1 is dragging
        self.arrowType = _arrowType  # 0 3D Default , 1= 2D, 2=2D
        self.w_lbluserData = fr_widget.propertyValues()
        self.w_lblColor = _lblColor
        self.w_opacity = _opacity
        self.w_scale = _scale
コード例 #2
0
 def __init__(self,
              dotted=False,
              scolor=None,
              swidth=None,
              children=[],
              ontop=False,
              name=None):
     global Part, DraftGeomUtils
     import Part, DraftGeomUtils
     self.ontop = ontop
     color = coin.SoBaseColor()
     color.rgb = scolor or FreeCADGui.draftToolBar.getDefaultColor("ui")
     drawstyle = coin.SoDrawStyle()
     if swidth:
         drawstyle.lineWidth = swidth
     if dotted:
         drawstyle.style = coin.SoDrawStyle.LINES
         drawstyle.lineWeight = 3
         drawstyle.linePattern = 0x0f0f  #0xaa
     node = coin.SoSeparator()
     for c in [drawstyle, color] + children:
         node.addChild(c)
     self.switch = coin.SoSwitch()  # this is the on/off switch
     if name:
         self.switch.setName(name)
     self.switch.addChild(node)
     self.switch.whichChild = -1
     self.Visible = False
     from DraftGui import todo
     todo.delay(self._insertSwitch, self.switch)
コード例 #3
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")
コード例 #4
0
ファイル: view_label.py プロジェクト: zikpuppy/FreeCAD
 def attach(self, vobj):
     '''Setup the scene sub-graph of the view provider'''
     self.arrow = coin.SoSeparator()
     self.arrowpos = coin.SoTransform()
     self.arrow.addChild(self.arrowpos)
     self.matline = coin.SoMaterial()
     self.drawstyle = coin.SoDrawStyle()
     self.drawstyle.style = coin.SoDrawStyle.LINES
     self.lcoords = coin.SoCoordinate3()
     self.line = coin.SoType.fromName("SoBrepEdgeSet").createInstance()
     self.mattext = coin.SoMaterial()
     textdrawstyle = coin.SoDrawStyle()
     textdrawstyle.style = coin.SoDrawStyle.FILLED
     self.textpos = coin.SoTransform()
     self.font = coin.SoFont()
     self.text2d = coin.SoText2()
     self.text3d = coin.SoAsciiText()
     self.text2d.string = self.text3d.string = "Label"  # need to init with something, otherwise, crash!
     self.text2d.justification = coin.SoText2.RIGHT
     self.text3d.justification = coin.SoAsciiText.RIGHT
     self.fcoords = coin.SoCoordinate3()
     self.frame = coin.SoType.fromName("SoBrepEdgeSet").createInstance()
     self.lineswitch = coin.SoSwitch()
     switchnode = coin.SoSeparator()
     switchnode.addChild(self.line)
     switchnode.addChild(self.arrow)
     self.lineswitch.addChild(switchnode)
     self.lineswitch.whichChild = 0
     self.node2d = coin.SoGroup()
     self.node2d.addChild(self.matline)
     self.node2d.addChild(self.arrow)
     self.node2d.addChild(self.drawstyle)
     self.node2d.addChild(self.lcoords)
     self.node2d.addChild(self.lineswitch)
     self.node2d.addChild(self.mattext)
     self.node2d.addChild(textdrawstyle)
     self.node2d.addChild(self.textpos)
     self.node2d.addChild(self.font)
     self.node2d.addChild(self.text2d)
     self.node2d.addChild(self.fcoords)
     self.node2d.addChild(self.frame)
     self.node3d = coin.SoGroup()
     self.node3d.addChild(self.matline)
     self.node3d.addChild(self.arrow)
     self.node3d.addChild(self.drawstyle)
     self.node3d.addChild(self.lcoords)
     self.node3d.addChild(self.lineswitch)
     self.node3d.addChild(self.mattext)
     self.node3d.addChild(textdrawstyle)
     self.node3d.addChild(self.textpos)
     self.node3d.addChild(self.font)
     self.node3d.addChild(self.text3d)
     self.node3d.addChild(self.fcoords)
     self.node3d.addChild(self.frame)
     vobj.addDisplayMode(self.node2d, "2D text")
     vobj.addDisplayMode(self.node3d, "3D text")
     self.onChanged(vobj, "LineColor")
     self.onChanged(vobj, "TextColor")
     self.onChanged(vobj, "ArrowSize")
     self.onChanged(vobj, "Line")
コード例 #5
0
    def attach(self, vobj):
        """Add display modes' data to the coin scenegraph.

        Add each display mode as a coin node, whose parent is this view
        provider. 

        Each display mode's node includes the data needed to display the object
        in that mode. This might include colors of faces, or the draw style of
        lines. This data is stored as additional coin nodes which are children
        of the display mode node.

        Doe not add display modes, but do add the solar diagram and compass to
        the scenegraph.
        """

        self.Object = vobj.Object
        from pivy import coin
        self.diagramsep = coin.SoSeparator()
        self.color = coin.SoBaseColor()
        self.coords = coin.SoTransform()
        self.diagramswitch = coin.SoSwitch()
        self.diagramswitch.whichChild = -1
        self.diagramswitch.addChild(self.diagramsep)
        self.diagramsep.addChild(self.coords)
        self.diagramsep.addChild(self.color)
        vobj.Annotation.addChild(self.diagramswitch)
        self.compass = Compass()
        self.updateCompassVisibility(vobj)
        self.updateCompassScale(vobj)
        self.rotateCompass(vobj)
        vobj.Annotation.addChild(self.compass.rootNode)
コード例 #6
0
ファイル: bezierCurve.py プロジェクト: sanderboer/CurvesWB
    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()
コード例 #7
0
ファイル: RobWorld.py プロジェクト: humz157643701/Animate
    def makeLabels(self):
        """
Method which makes Coin3D labels to be displayed in the FreeCAD View.

Frame labels for axes X, Y and Z are made.
The labels have the same color as the axes.

Returns:
    A SoSwitch with colored text label to be shown in the FreeCAD View.
        """
        label_strings = ["X", "Y", "Z"]
        colors = [0xFF0000FF, 0x00FF00FF, 0x0000FFFF]
        self.label_texts = []
        self.label_translations = []
        # frame translation
        self.label_translations.append(coin.SoTranslation())
        # axis translation
        self.label_translations.append(coin.SoTranslation())
        self.labels = []
        for i in range(3):
            label_group = coin.SoSeparator()
            label_group.addChild(self.label_translations[0])
            frame_axis_color = coin.SoPackedColor()
            frame_axis_color.orderedRGBA.setValue(colors[i])
            label_group.addChild(frame_axis_color)
            self.label_texts.append(coin.SoText2())
            self.label_texts[i].string.setValues(
                0, 3, ["", label_strings[i], ""])
            self.label_texts[i].justification.setValue(
                self.label_texts[i].CENTER)
            self.label_texts[i].spacing.setValue(0.45)
            label_group.addChild(self.label_texts[i])
            self.labels.append(coin.SoSwitch())
            self.labels[i].addChild(label_group)
        return self.labels
コード例 #8
0
 def makeLabels(self):
     label_strings = ["X", "Y", "Z"]
     colors = [0xFF0000FF, 0x00FF00FF, 0x0000FFFF]
     self.label_texts = []
     self.label_translations = []
     # frame translation
     self.label_translations.append(coin.SoTranslation())
     # axis translation
     self.label_translations.append(coin.SoTranslation())
     self.labels = []
     for i in range(3):
         label_group = coin.SoSeparator()
         label_group.addChild(self.label_translations[0])
         frame_axis_color = coin.SoPackedColor()
         frame_axis_color.orderedRGBA.setValue(colors[i])
         label_group.addChild(frame_axis_color)
         self.label_texts.append(coin.SoText2())
         self.label_texts[i].string.setValues(0, 3,
                                              ["", label_strings[i], ""])
         self.label_texts[i].justification.setValue(
             self.label_texts[i].CENTER)
         self.label_texts[i].spacing.setValue(0.45)
         label_group.addChild(self.label_texts[i])
         self.labels.append(coin.SoSwitch())
         self.labels[i].addChild(label_group)
     return self.labels
コード例 #9
0
    def initPage(self, obj):
        self.setTitle("Extensions")
        self.extensions = obj.Proxy.getExtensions(obj)  # pylint: disable=attribute-defined-outside-init

        self.defaultLength = PathGui.QuantitySpinBox(self.form.defaultLength,
                                                     obj,
                                                     'ExtensionLengthDefault')  # pylint: disable=attribute-defined-outside-init

        self.form.extensionTree.setEditTriggers(
            QtGui.QAbstractItemView.NoEditTriggers)
        self.form.extensionTree.setSelectionBehavior(
            QtGui.QAbstractItemView.SelectRows)

        self.switch = coin.SoSwitch()  # pylint: disable=attribute-defined-outside-init
        self.obj.ViewObject.RootNode.addChild(self.switch)
        self.switch.whichChild = coin.SO_SWITCH_ALL

        self.model = QtGui.QStandardItemModel(self.form.extensionTree)  # pylint: disable=attribute-defined-outside-init
        self.model.setHorizontalHeaderLabels(['Base', 'Extension'])

        if 0 < len(obj.ExtensionFeature):
            self.form.showExtensions.setCheckState(QtCore.Qt.Checked)
        else:
            self.form.showExtensions.setCheckState(QtCore.Qt.Unchecked)

        self.blockUpdateData = False  # pylint: disable=attribute-defined-outside-init
コード例 #10
0
    def attach(self, vobj):
        self.vobj = vobj
        self.obj = vobj.Object
        self.taskPanel = None

        # setup the axis display at the origin
        self.switch = coin.SoSwitch()
        self.sep = coin.SoSeparator()
        self.axs = coin.SoType.fromName('SoAxisCrossKit').createInstance()
        self.axs.set('xHead.transform', 'scaleFactor 2 3 2')
        self.axs.set('yHead.transform', 'scaleFactor 2 3 2')
        self.axs.set('zHead.transform', 'scaleFactor 2 3 2')
        self.sca = coin.SoType.fromName('SoShapeScale').createInstance()
        self.sca.setPart('shape', self.axs)
        self.sca.scaleFactor.setValue(0.5)
        self.mat = coin.SoMaterial()
        self.mat.diffuseColor = coin.SbColor(0.9, 0, 0.9)
        self.mat.transparency = 0.85
        self.sph = coin.SoSphere()
        self.scs = coin.SoType.fromName('SoShapeScale').createInstance()
        self.scs.setPart('shape', self.sph)
        self.scs.scaleFactor.setValue(10)
        self.sep.addChild(self.sca)
        self.sep.addChild(self.mat)
        self.sep.addChild(self.scs)
        self.switch.addChild(self.sep)
        vobj.RootNode.addChild(self.switch)
        self.showOriginAxis(False)
コード例 #11
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)
コード例 #12
0
 def attach(self, vobj):
     ArchFloor._ViewProviderFloor.attach(self, vobj)
     from pivy import coin
     self.diagramsep = coin.SoSeparator()
     self.color = coin.SoBaseColor()
     self.coords = coin.SoTransform()
     self.diagramswitch = coin.SoSwitch()
     self.diagramswitch.whichChild = -1
     self.diagramswitch.addChild(self.diagramsep)
     self.diagramsep.addChild(self.coords)
     self.diagramsep.addChild(self.color)
     vobj.Annotation.addChild(self.diagramswitch)
コード例 #13
0
    def attach(self, vp):
        # prepare transformation to keep pose corresponding to placement
        self.tf_object2world = coin.SoTransform()

        labels = self.makeLabels()
        self.font = coin.SoFontStyle()

        frame = self.makeFrame(labels[:3])
        frame.insertChild(self.tf_object2world, 0)
        frame.insertChild(self.font, 1)
        self.frame = coin.SoSwitch()
        self.frame.addChild(frame)

        self.visualisations = coin.SoSwitch()
        self.visualisations.addChild(self.frame)
        self.visualisations.whichChild.setValue(coin.SO_SWITCH_ALL)
        vp.RootNode.addChild(self.visualisations)

        vp.Object.Proxy.setProperties(vp.Object)
        self.setProperties(vp)
        self.fp = vp.Object
コード例 #14
0
ファイル: lights.py プロジェクト: dunaszegi/FreeCAD-render
    def attach(self, vobj):
        """Code executed when object is created/restored (callback)

        Parameters:
        -----------
        vobj: related ViewProviderDocumentObject
        """
        # pylint: disable=attribute-defined-outside-init

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

        # Here we create coin representation, which is in 2 parts: a light,
        # and a geometry, the former being a point light, the latter being a
        # faceset embedded in 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.FILLED
        self.coin.node.addChild(self.coin.drawstyle)
        self.coin.coords = coin.SoCoordinate3()

        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.faceset = coin.SoFaceSet()
        self.coin.faceset.numVertices.setValues(0, 1, [5])
        self.coin.node.addChild(self.coin.faceset)

        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)
        self._update_color(self.fpo)
        self._update_power(self.fpo)
        self._update_size(self.fpo)
コード例 #15
0
ファイル: lights.py プロジェクト: zero804/FreeCAD-render
    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)
コード例 #16
0
    def __init__(self):

        super().init(name='Drag Tracker')

        self.start = ()

        self.drag_switch = coin.SoSwitch()
        self.drag_node = coin.SoSeparator()
        self.drag_event_callback = coin.SoEventCallback()
        self.full_group = coin.SoSeparator()
        self.manual_group = coin.SoSeparator()

        self.drag_transform = coin.SoTransform()
        self.drag_tracker_node = None
        self.drag_point = None

        self.update_translate = True
        self.update_rotate = True

        self.drag_line_coord = coin.SoCoordinate3()

        self.drag_event_callback.setPath(None)

        self.drag_node.addChild(self.drag_event_callback)
        self.drag_node.addChild(self.manual_group)
        self.drag_node.addChild(self.drag_transform)
        self.drag_node.addChild(self.full_group)

        self.drag_switch.addChild(self._build_drag_line())
        self.drag_switch.addChild(self.drag_node)
        self.drag_switch.whichChild = -3

        self.abort = False

        #coordinate tracking properties
        self.delta = ()
        self.coordinates = ()

        #cumulate angle, center of rotation and current drag rotation
        self.angle = 0.0
        self.rotation_center = None
        self.rotation = 0.0

        #flag indicating scenegraph updates are complete
        self.sg_ok = False

        #reference to scenegrapg root node (used internally)
        self._sg_root = None

        #set to indicate to base tracker not to push updates during on_drag()
        self.override = False
コード例 #17
0
 def _createText(self, label, string, justification, x, y):
     pos = self._position(x, y)
     mat = self._material(0)
     fnt = self._font()
     txt = self._text(label, string, justification)
     sep = coin.SoSeparator()
     sep.addChild(pos)
     sep.addChild(mat)
     sep.addChild(fnt)
     sep.addChild(txt)
     switch = coin.SoSwitch()
     switch.addChild(sep)
     switch.whichChild = coin.SO_SWITCH_ALL
     self.sw[label] = switch
コード例 #18
0
 def __init__(self,
              vectors: List[App.Vector] = [],
              label: str = "",
              lineWidth=1):
     super().__init__(vectors, label)
     # Must be initialized first as per the following discussion.
     # https://stackoverflow.com/questions/67877603/how-to-override-a-function-in-an-inheritance-hierarchy#67877671
     self.w_lineWidth = lineWidth  # Default line width
     self.w_widgetType = constant.FR_WidgetType.FR_EDGE
     self.w_callback_ = callback  # External function
     self.w_lbl_calback_ = lblcallback  # External function
     self.w_KB_callback_ = KBcallback  # External function
     self.w_move_callback_ = movecallback  # External function
     self.w_wdgsoSwitch = coin.SoSwitch()
     self.w_wdgsoSwitch.whichChild = coin.SO_SWITCH_ALL  # Show all
     self.w_lbluserData = fr_widget.propertyValues()
コード例 #19
0
    def attach(self, vobj):
        PathLog.track()
        self.setupColors()
        self.vobj = vobj
        self.obj = vobj.Object
        self.tags = []
        self.switch = coin.SoSwitch()
        vobj.RootNode.addChild(self.switch)
        self.turnMarkerDisplayOn(False)

        if self.obj and self.obj.Base:
            for i in self.obj.Base.InList:
                if hasattr(i, 'Group') and self.obj.Base.Name in [o.Name for o in i.Group]:
                    i.Group = [o for o in i.Group if o.Name != self.obj.Base.Name]
            if self.obj.Base.ViewObject:
                self.obj.Base.ViewObject.Visibility = False
コード例 #20
0
 def __init__(self, parent, dynamic=False):
     super(CustomText, self).__init__(parent.points, dynamic)
     #self._text_offset = FreeCAD.Vector(0,0,0)
     self._text_translate = coin.SoTranslation()
     self._text_font = coin.SoFont()
     self._text_font.name = "Arial:Bold"
     self._text_font.size = 13.0
     self._text = coin.SoText2()
     self._text_switch = coin.SoSwitch()
     self._text_switch.addChild(self._text_translate)
     self._text_switch.addChild(self._text_font)
     self._text_switch.addChild(self._text)
     self.addChild(self._text_switch)
     self.parent = parent
     self.parent.on_drag.append(self.translate)
     self.translate()
コード例 #21
0
    def attach(self,vobj):

        self.Object = vobj.Object
        self.clip = None
        from pivy import coin
        self.sep = coin.SoGroup()
        self.mat = coin.SoMaterial()
        self.sep.addChild(self.mat)
        self.dst = coin.SoDrawStyle()
        self.sep.addChild(self.dst)
        self.lco = coin.SoCoordinate3()
        self.sep.addChild(self.lco)
        lin = coin.SoType.fromName("SoBrepEdgeSet").createInstance()
        lin.coordIndex.setValues([0,1,-1,2,3,-1,4,5,-1])
        self.sep.addChild(lin)
        self.bbox = coin.SoSwitch()
        self.bbox.whichChild = -1
        bboxsep = coin.SoSeparator()
        self.bbox.addChild(bboxsep)
        drawstyle = coin.SoDrawStyle()
        drawstyle.style = coin.SoDrawStyle.LINES
        drawstyle.lineWidth = 3
        drawstyle.linePattern = 0x0f0f  # 0xaa
        bboxsep.addChild(drawstyle)
        self.bbco = coin.SoCoordinate3()
        bboxsep.addChild(self.bbco)
        lin = coin.SoIndexedLineSet()
        lin.coordIndex.setValues([0,1,2,3,0,-1,4,5,6,7,4,-1,0,4,-1,1,5,-1,2,6,-1,3,7,-1])
        bboxsep.addChild(lin)
        self.sep.addChild(self.bbox)
        self.tra = coin.SoTransform()
        self.tra.rotation.setValue(FreeCAD.Rotation(0,0,90).Q)
        self.sep.addChild(self.tra)
        self.fon = coin.SoFont()
        self.sep.addChild(self.fon)
        self.txt = coin.SoAsciiText()
        self.txt.justification = coin.SoText2.LEFT
        self.txt.string.setValue("level")
        self.sep.addChild(self.txt)
        vobj.addDisplayMode(self.sep,"Default")
        self.onChanged(vobj,"ShapeColor")
        self.onChanged(vobj,"FontName")
        self.onChanged(vobj,"ShowLevel")
        self.onChanged(vobj,"FontSize")
        self.onChanged(vobj,"AutogroupBox")
        self.setProperties(vobj)
        return
コード例 #22
0
    def __init__(self, view, names, base_node):
        """
        Constructor
        """

        self.base_node = base_node

        self.viewport = \
            view.getViewer().getSoRenderManager().getViewportRegion()

        self.nodes = {
            'connector': coin.SoGroup(),
            'selected': coin.SoGroup(),
            'switch': coin.SoSwitch(),
            'transform': coin.SoTransform(),
        }

        self.view = view
        self.start_path = None

        self.gui_callbacks = {
            'SoLocation2Event': \
                view.addEventCallback('SoLocation2Event', self.mouse_action)
        }

        self.callbacks = []

        self.datums = {
            _k: None for _k in ['origin', 'picked', 'start', 'drag_start']
        }

        self.datums['rotation'] = {
            'center': None, 'ref_vec': Vector(), 'angle': 0.0
        }

        names.append('DRAG TRACKER')

        super().__init__(names, [
            self.nodes['connector'], self.nodes['selected']
        ], False)

        self.nodes['selected'].addChild(self.nodes['transform'])
        self.nodes['switch'].addChild(self.node)

        self.on(self.nodes['switch'])

        self.insert_node(self.nodes['switch'], self.base_node)
コード例 #23
0
    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
コード例 #24
0
ファイル: coin.py プロジェクト: howetuft/FreeCAD-render
    def __init__(self):
        """Initialize object."""
        # Root node
        self.node = coin.SoSeparator()

        # Switch (visibility)
        self.switch = coin.SoSwitch()
        self.node.addChild(self.switch)

        # Transform (placement)
        self.transform = coin.SoTransform()
        self.switch.addChild(self.transform)

        # Display group (starting point for shape or light nodes)
        self.display_group = coin.SoGroup()
        self.switch.addChild(self.display_group)

        self.set_visibility(True)
コード例 #25
0
    def __init__(self, points, sh=None):
        super(MarkerOnShape, self).__init__(points, True)
        self._shape = None
        self._sublink = None
        self._tangent = None
        self._text_translate = coin.SoTranslation()
        self._text = coin.SoText2()
        self._text_switch = coin.SoSwitch()
        self._text_switch.addChild(self._text_translate)
        self._text_switch.addChild(self._text)
        self.on_drag_start.append(self.add_text)
        self.on_drag_release.append(self.remove_text)
        self.addChild(self._text_switch)

        if isinstance(sh, Part.Shape):
            self.snap_shape = sh
        elif isinstance(sh, (tuple, list)):
            self.sublink = sh
コード例 #26
0
ファイル: ArchSite.py プロジェクト: sdh4/FreeCAD
    def attach(self, vobj):

        self.Object = vobj.Object
        from pivy import coin
        self.diagramsep = coin.SoSeparator()
        self.color = coin.SoBaseColor()
        self.coords = coin.SoTransform()
        self.diagramswitch = coin.SoSwitch()
        self.diagramswitch.whichChild = -1
        self.diagramswitch.addChild(self.diagramsep)
        self.diagramsep.addChild(self.coords)
        self.diagramsep.addChild(self.color)
        vobj.Annotation.addChild(self.diagramswitch)
        self.compass = Compass()
        self.updateCompassVisibility(vobj)
        self.updateCompassScale(vobj)
        self.rotateCompass(vobj)
        vobj.Annotation.addChild(self.compass.rootNode)
コード例 #27
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)
コード例 #28
0
ファイル: TrackerTools.py プロジェクト: sgnannan/DDA
 def __init__(self, dotted=False, scolor=None, swidth=None, children=[], ontop=False):
     self.ontop = ontop
     color = coin.SoBaseColor()
     color.rgb = scolor or FreeCADGui.DDADockWidget.getDefaultColor("ui")
     drawstyle = coin.SoDrawStyle()
     if swidth:
         drawstyle.lineWidth = swidth
     if dotted:
         drawstyle.style = coin.SoDrawStyle.LINES
         drawstyle.lineWeight = 3
         drawstyle.linePattern = 0x0f0f  # 0xaa , 虚线的具体样式
     node = coin.SoSeparator()
     for c in [drawstyle, color] + children:  # openInventor的处理方式,前两决定后续children的样式
         node.addChild(c)
     self.switch = coin.SoSwitch()  # this is the on/off switch
     self.switch.addChild(node)
     self.switch.whichChild = -1
     self.Visible = False
     todo.delay(self._insertSwitch, self.switch)
コード例 #29
0
    def initPage(self, obj):
        self.setTitle("Extensions")
        self.OpIcon = ":/icons/view-axonometric.svg"
        self.setIcon(self.OpIcon)
        self.initialEdgeCount = -1
        self.edgeCountThreshold = 30
        self.fieldsSet = False
        self.useOutlineCheckbox = None
        self.useOutline = -1
        self.extensionsCache = dict()
        self.extensionsReady = False
        self.enabled = True
        self.lastDefaultLength = ""

        self.extensions = list()

        self.defaultLength = PathGui.QuantitySpinBox(self.form.defaultLength,
                                                     obj,
                                                     "ExtensionLengthDefault")

        self.form.extensionTree.setEditTriggers(
            QtGui.QAbstractItemView.NoEditTriggers)
        self.form.extensionTree.setSelectionBehavior(
            QtGui.QAbstractItemView.SelectRows)

        self.switch = coin.SoSwitch()
        self.obj.ViewObject.RootNode.addChild(self.switch)
        self.switch.whichChild = coin.SO_SWITCH_ALL

        self.model = QtGui.QStandardItemModel(self.form.extensionTree)
        self.model.setHorizontalHeaderLabels(["Base", "Extension"])
        """
        # russ4262: This `if` block shows all available extensions upon edit of operation with any extension enabled.
        # This can cause the model(s) to overly obscured due to previews of extensions.
        # Would be great if only enabled extensions were shown.
        if 0 < len(obj.ExtensionFeature):
            self.form.showExtensions.setCheckState(QtCore.Qt.Checked)
        else:
            self.form.showExtensions.setCheckState(QtCore.Qt.Unchecked)
        """
        self.form.showExtensions.setCheckState(QtCore.Qt.Unchecked)

        self.blockUpdateData = False
コード例 #30
0
 def build(self):
     self.active = False
     if not hasattr(self, 'switch'):
         self.sg = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph()
         self.switch = coin.SoSwitch()
         if hasattr(self, 'Object'):
             self.switch.setName("%s_ControlPoints" % self.Object.Name)
         self.empty = coin.SoSeparator()  # Empty node
         self.node = coin.SoSeparator()
         self.coord = CoinNodes.coordinate3Node()
         self.poly = CoinNodes.polygonNode((0.5, 0.5, 0.5), 1)
         self.marker = CoinNodes.markerSetNode(
             (1, 0, 0), coin.SoMarkerSet.DIAMOND_FILLED_7_7)
         self.node.addChild(self.coord)
         self.node.addChild(self.poly)
         self.node.addChild(self.marker)
         self.switch.addChild(self.empty)
         self.switch.addChild(self.node)
         self.sg.addChild(self.switch)