Esempio n. 1
0
    def setupGroundNode(self):
        groundNode = coin.SoSeparator()

        self.groundCoordinates = coin.SoCoordinate3()

        self.groundTexture = coin.SoTexture2()
        self.groundTexture.filename = py2_utils.textureFileString(
            self.Object.GroundImage)
        self.groundTexture.model = coin.SoMultiTextureImageElement.REPLACE

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

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

        groundNode.addChild(self.groundCoordinates)
        groundNode.addChild(groundTextureCoordinates)
        groundNode.addChild(self.groundTexture)
        groundNode.addChild(faceset)

        return groundNode
Esempio n. 2
0
    def setupSkyNode(self):
        skyNode = coin.SoSeparator()

        self.skyCoordinates = coin.SoCoordinate3()

        self.skyTexture = coin.SoTexture2()
        self.skyTexture.filename = py2_utils.textureFileString(
            self.Object.SkyImage)
        self.skyTexture.model = coin.SoMultiTextureImageElement.REPLACE

        self.skyTextureCoordinates = coin.SoTextureCoordinate2()

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

        skyNode.addChild(self.skyCoordinates)
        skyNode.addChild(self.skyTextureCoordinates)
        skyNode.addChild(self.skyTexture)
        skyNode.addChild(faceset)

        return skyNode
Esempio n. 3
0
    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)
Esempio n. 4
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)
Esempio n. 5
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
Esempio n. 6
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 __init__(self, names, nodes=None):
        """
        Constructor
        """

        self.face = coin.SoFaceSet()

        self.coord = coin.SoCoordinate3()
        self.points = None
        self.selection_nodes = None
        self.selection_indices = []
        self.names = names

        self.group = coin.SoSeparator()
        self.drag_coord = None
        self.drag_idx = None
        self.drag_start = []

        self.trackers = []
        self.start = Vector()
        self.size = Vector()

        self.transparency = coin.SoTransparencyType()

        if not nodes:
            nodes = []

        elif not isinstance(nodes, list):
            nodes = list(nodes)

        nodes += [self.coord, self.transparency, self.face]

        super().__init__(names, nodes)

        self._build_trackers()

        for _t in self.trackers:
            self.node.addChild(_t.switch)
Esempio n. 9
0
    def setupPanoramaNode(self):
        panoramaNode = coin.SoSeparator()

        self.panoramaCoordinates = coin.SoCoordinate3()

        self.panoramaTextureCoordinates = coin.SoTextureCoordinate2()

        self.panoramaTexture = coin.SoTexture2()
        self.panoramaTexture.filename = py2_utils.textureFileString(
            self.Object.PanoramaImage)
        self.panoramaTexture.model = coin.SoMultiTextureImageElement.REPLACE

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

        panoramaNode.addChild(self.panoramaCoordinates)
        panoramaNode.addChild(self.panoramaTextureCoordinates)
        panoramaNode.addChild(self.panoramaTexture)
        panoramaNode.addChild(faceset)

        return panoramaNode
Esempio n. 10
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:
            wire = ext.getWire()
            if wire:
                poly = [p for p in wire.discretize(Deflection=0.01)][:-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
Esempio n. 11
0
    def createExtensionSoSwitch(self, ext):
        if not ext:
            return None

        sep = coin.SoSeparator()
        pos = coin.SoTranslation()
        mat = coin.SoMaterial()
        crd = coin.SoCoordinate3()
        fce = coin.SoFaceSet()
        hnt = coin.SoShapeHints()
        numVert = list()  # track number of vertices in each polygon face

        try:
            wire = ext.getWire()
        except FreeCAD.Base.FreeCADError:
            wire = None

        if not wire:
            return None

        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:
            if ext.extFaces:
                # Create polygon for each extension face in compound extensions
                allPolys = list()
                extFaces = ext.getExtensionFaces(wire)
                for f in extFaces:
                    pCnt = 0
                    wCnt = 0
                    for w in f.Wires:
                        if wCnt == 0:
                            poly = [p for p in w.discretize(Deflection=0.01)]
                        else:
                            poly = [p for p in w.discretize(Deflection=0.01)
                                    ][:-1]
                        pCnt += len(poly)
                        allPolys.extend(poly)
                    numVert.append(pCnt)
                polygon = [(p.x, p.y, p.z) for p in allPolys]
            else:
                # poly = [p for p in wire.discretize(Deflection=0.02)][:-1]
                poly = [p for p in wire.discretize(Deflection=0.02)]
                polygon = [(p.x, p.y, p.z) for p in poly]
        crd.point.setValues(polygon)

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

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

        if numVert:
            # Transfer vertex counts for polygon faces
            fce.numVertices.setValues(tuple(numVert))

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

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

        self.material = mat

        return switch
Esempio n. 12
0
    def onChanged(self, vobj, prop):

        if prop == "LineColor":
            if hasattr(vobj, "LineColor"):
                l = vobj.LineColor
                self.mat.diffuseColor.setValue([l[0], l[1], l[2]])
        elif prop == "DrawStyle":
            if hasattr(vobj, "DrawStyle"):
                if vobj.DrawStyle == "Solid":
                    self.linestyle.linePattern = 0xffff
                elif vobj.DrawStyle == "Dashed":
                    self.linestyle.linePattern = 0xf00f
                elif vobj.DrawStyle == "Dotted":
                    self.linestyle.linePattern = 0x0f0f
                else:
                    self.linestyle.linePattern = 0xff88
        elif prop == "LineWidth":
            if hasattr(vobj, "LineWidth"):
                self.linestyle.lineWidth = vobj.LineWidth
        elif prop in ["BubbleSize", "BubblePosition", "FontName", "FontSize"]:
            if hasattr(self, "bubbleset"):
                if self.bubbles:
                    self.bubbleset.removeChild(self.bubbles)
                    self.bubbles = None
                if vobj.Object.Shape:
                    if vobj.Object.Shape.Edges:
                        self.bubbles = coin.SoSeparator()
                        self.bubblestyle = coin.SoDrawStyle()
                        self.bubblestyle.linePattern = 0xffff
                        self.bubbles.addChild(self.bubblestyle)
                        self.bubbletexts = []
                        self.bubbledata = []
                        pos = ["Start"]
                        if hasattr(vobj, "BubblePosition"):
                            if vobj.BubblePosition in [
                                    "Both", "Arrow left", "Arrow right",
                                    "Bar left", "Bar right"
                            ]:
                                pos = ["Start", "End"]
                            elif vobj.BubblePosition == "None":
                                pos = []
                            else:
                                pos = [vobj.BubblePosition]
                        for i in range(len(vobj.Object.Distances)):
                            for p in pos:
                                if hasattr(
                                        vobj.Object,
                                        "Limit") and vobj.Object.Limit.Value:
                                    verts = [
                                        vobj.Object.Placement.inverse(
                                        ).multVec(vobj.Object.Shape.Edges[i].
                                                  Vertexes[0].Point),
                                        vobj.Object.Placement.inverse().
                                        multVec(vobj.Object.Shape.Edges[
                                            i + 1].Vertexes[0].Point)
                                    ]
                                else:
                                    verts = [
                                        vobj.Object.Placement.inverse(
                                        ).multVec(v.Point) for v in
                                        vobj.Object.Shape.Edges[i].Vertexes
                                    ]
                                arrow = None
                                if p == "Start":
                                    p1 = verts[0]
                                    p2 = verts[1]
                                    if vobj.BubblePosition.endswith("left"):
                                        arrow = True
                                    elif vobj.BubblePosition.endswith("right"):
                                        arrow = False
                                else:
                                    p1 = verts[1]
                                    p2 = verts[0]
                                    if vobj.BubblePosition.endswith("left"):
                                        arrow = False
                                    elif vobj.BubblePosition.endswith("right"):
                                        arrow = True
                                dv = p2.sub(p1)
                                dv.normalize()
                                if hasattr(vobj.BubbleSize, "Value"):
                                    rad = vobj.BubbleSize.Value / 2
                                else:
                                    rad = vobj.BubbleSize / 2
                                center = p2.add(Vector(dv).multiply(rad))
                                normal = vobj.Object.Placement.Rotation.multVec(
                                    Vector(0, 0, 1))
                                chord = dv.cross(normal)
                                if arrow:
                                    p3 = p2.add(
                                        Vector(chord).multiply(rad /
                                                               2).negative())
                                    if vobj.BubblePosition.startswith("Arrow"):
                                        p4 = p3.add(
                                            Vector(dv).multiply(rad *
                                                                2).negative())
                                        p5 = p2.add(
                                            Vector(dv).multiply(
                                                rad).negative()).add(
                                                    Vector(chord).multiply(
                                                        rad * 1.5).negative())
                                        pts = [
                                            tuple(p3),
                                            tuple(p5),
                                            tuple(p4),
                                            tuple(p3)
                                        ]
                                        center = p5.add(
                                            Vector(chord).multiply(rad * 2.5))
                                    else:
                                        p4 = p3.add(
                                            Vector(dv).multiply(rad /
                                                                2).negative())
                                        p5 = p4.add(
                                            Vector(chord).multiply(
                                                rad * 1.5).negative())
                                        p6 = p5.add(
                                            Vector(dv).multiply(rad / 2))
                                        pts = [
                                            tuple(p3),
                                            tuple(p6),
                                            tuple(p5),
                                            tuple(p4),
                                            tuple(p3)
                                        ]
                                        center = p5.add(
                                            Vector(chord).multiply(rad * 3))
                                    coords = coin.SoCoordinate3()
                                    coords.point.setValues(0, len(pts), pts)
                                    line = coin.SoFaceSet()
                                    line.numVertices.setValue(-1)
                                    cir = Part.makePolygon(pts)
                                    cir.Placement = vobj.Object.Placement
                                    self.bubbledata.append(cir)
                                elif arrow == False:
                                    p3 = p2.add(
                                        Vector(chord).multiply(rad / 2))
                                    if vobj.BubblePosition.startswith("Arrow"):
                                        p4 = p3.add(
                                            Vector(dv).multiply(rad *
                                                                2).negative())
                                        p5 = p2.add(
                                            Vector(dv).multiply(
                                                rad).negative()).add(
                                                    Vector(chord).multiply(
                                                        rad * 1.5))
                                        pts = [
                                            tuple(p3),
                                            tuple(p4),
                                            tuple(p5),
                                            tuple(p3)
                                        ]
                                        center = p5.add(
                                            Vector(chord).multiply(
                                                rad * 2.5).negative())
                                    else:
                                        p4 = p3.add(
                                            Vector(dv).multiply(rad /
                                                                2).negative())
                                        p5 = p4.add(
                                            Vector(chord).multiply(rad * 1.5))
                                        p6 = p5.add(
                                            Vector(dv).multiply(rad / 2))
                                        pts = [
                                            tuple(p3),
                                            tuple(p4),
                                            tuple(p5),
                                            tuple(p6),
                                            tuple(p3)
                                        ]
                                        center = p5.add(
                                            Vector(chord).multiply(
                                                rad * 3).negative())
                                    coords = coin.SoCoordinate3()
                                    coords.point.setValues(0, len(pts), pts)
                                    line = coin.SoFaceSet()
                                    line.numVertices.setValue(-1)
                                    cir = Part.makePolygon(pts)
                                    cir.Placement = vobj.Object.Placement
                                    self.bubbledata.append(cir)
                                else:
                                    cir = Part.makeCircle(rad, center)
                                    buf = cir.writeInventor()
                                    try:
                                        cin = coin.SoInput()
                                        cin.setBuffer(buf)
                                        cob = coin.SoDB.readAll(cin)
                                    except Exception:
                                        # workaround for pivy SoInput.setBuffer() bug
                                        buf = buf.replace("\n", "")
                                        pts = re.findall(
                                            "point \[(.*?)\]", buf)[0]
                                        pts = pts.split(",")
                                        pc = []
                                        for point in pts:
                                            v = point.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)
                                    else:
                                        coords = cob.getChild(1).getChild(
                                            0).getChild(2)
                                        line = cob.getChild(1).getChild(
                                            0).getChild(3)
                                    cir.Placement = vobj.Object.Placement
                                    self.bubbledata.append(cir)
                                self.bubbles.addChild(coords)
                                self.bubbles.addChild(line)
                                st = coin.SoSeparator()
                                tr = coin.SoTransform()
                                fs = rad * 1.5
                                if hasattr(vobj, "FontSize"):
                                    fs = vobj.FontSize.Value
                                txpos = FreeCAD.Vector(center.x,
                                                       center.y - fs / 2.5,
                                                       center.z)
                                tr.translation.setValue(tuple(txpos))
                                fo = coin.SoFont()
                                fn = Draft.getParam("textfont", "Arial,Sans")
                                if hasattr(vobj, "FontName"):
                                    if vobj.FontName:
                                        try:
                                            fn = str(vobj.FontName)
                                        except Exception:
                                            pass
                                fo.name = fn
                                fo.size = fs
                                tx = coin.SoAsciiText()
                                tx.justification = coin.SoText2.CENTER
                                self.bubbletexts.append(
                                    (tx,
                                     vobj.Object.Placement.multVec(center)))
                                st.addChild(tr)
                                st.addChild(fo)
                                st.addChild(tx)
                                self.bubbles.addChild(st)
                        self.bubbleset.addChild(self.bubbles)
                        self.onChanged(vobj, "NumberingStyle")
            if prop in ["FontName", "FontSize"]:
                self.onChanged(vobj, "ShowLabel")
        elif prop in ["NumberingStyle", "StartNumber"]:
            if hasattr(self, "bubbletexts"):
                num = 0
                if hasattr(vobj, "StartNumber"):
                    if vobj.StartNumber > 1:
                        num = vobj.StartNumber - 1
                alt = False
                for t in self.bubbletexts:
                    t[0].string = self.getNumber(vobj, num)
                    num += 1
                    if hasattr(vobj, "BubblePosition"):
                        if vobj.BubblePosition in [
                                "Both", "Arrow left", "Arrow right",
                                "Bar left", "Bar right"
                        ]:
                            if not alt:
                                num -= 1
                    alt = not alt
        elif prop in ["ShowLabel", "LabelOffset"]:
            if hasattr(self, "labels"):
                if self.labels:
                    self.labelset.removeChild(self.labels)
            self.labels = None
            if hasattr(vobj, "ShowLabel") and hasattr(vobj.Object, "Labels"):
                if vobj.ShowLabel:
                    self.labels = coin.SoSeparator()
                    if hasattr(vobj.Object,
                               "Limit") and vobj.Object.Limit.Value:
                        n = len(vobj.Object.Shape.Edges) / 2
                    else:
                        n = len(vobj.Object.Shape.Edges)
                    for i in range(n):
                        if len(vobj.Object.Labels) > i:
                            if vobj.Object.Labels[i]:
                                vert = vobj.Object.Shape.Edges[i].Vertexes[
                                    0].Point
                                if hasattr(vobj, "LabelOffset"):
                                    pl = FreeCAD.Placement(vobj.LabelOffset)
                                    pl.Base = vert.add(pl.Base)
                                st = coin.SoSeparator()
                                tr = coin.SoTransform()
                                fo = coin.SoFont()
                                tx = coin.SoAsciiText()
                                tx.justification = coin.SoText2.LEFT
                                t = vobj.Object.Labels[i]
                                if six.PY2 and isinstance(t, six.text_type):
                                    t = t.encode("utf8")
                                tx.string.setValue(t)
                                if hasattr(vobj, "FontSize"):
                                    fs = vobj.FontSize.Value
                                elif hasattr(vobj.BubbleSize, "Value"):
                                    fs = vobj.BubbleSize.Value * 0.75
                                else:
                                    fs = vobj.BubbleSize * 0.75
                                tr.translation.setValue(tuple(pl.Base))
                                tr.rotation.setValue(pl.Rotation.Q)
                                fn = Draft.getParam("textfont", "Arial,Sans")
                                if hasattr(vobj, "FontName"):
                                    if vobj.FontName:
                                        try:
                                            fn = str(vobj.FontName)
                                        except Exception:
                                            pass
                                fo.name = fn
                                fo.size = fs
                                st.addChild(tr)
                                st.addChild(fo)
                                st.addChild(tx)
                                self.labels.addChild(st)
                    self.labelset.addChild(self.labels)
Esempio n. 13
0
def dim_symbol(symbol=None, invert=False):
    """Return the specified dimension symbol.

    Parameters
    ----------
    symbol: int, optional
        It defaults to `None`, in which it gets the value from the parameter
        database, `get_param("dimsymbol", 0)`.

        A numerical value defines different markers
         * 0, `SoSphere`
         * 1, `SoSeparator` with a `SoLineSet`, a circle (in fact a 24 sided polygon)
         * 2, `SoSeparator` with a `soCone`
         * 3, `SoSeparator` with a `SoFaceSet`
         * 4, `SoSeparator` with a `SoLineSet`, calling `dim_dash`
         * Otherwise, `SoSphere`

    invert: bool, optional
        It defaults to `False`.
        If it is `True` and `symbol=2`, the cone will be rotated
        -90 degrees around the Z axis, otherwise the rotation is positive,
        +90 degrees.

    Returns
    -------
    Coin.SoNode
        A `Coin.SoSphere`, or `Coin.SoSeparator` (circle, cone, face, line)
        that will be used as a dimension symbol.
    """
    if symbol is None:
        symbol = utils.get_param("dimsymbol", 0)

    if symbol == 0:
        # marker = coin.SoMarkerSet()
        # marker.markerIndex = 80

        # Returning a sphere means that the bounding box will
        # be 3-dimensional; a marker will always be planar seen from any
        # orientation but it currently doesn't work correctly
        marker = coin.SoSphere()
        return marker
    elif symbol == 1:
        marker = coin.SoSeparator()
        v = coin.SoVertexProperty()
        for i in range(25):
            ang = math.radians(i * 15)
            v.vertex.set1Value(i, (math.sin(ang), math.cos(ang), 0))
        p = coin.SoLineSet()
        p.vertexProperty = v
        marker.addChild(p)
        return marker
    elif symbol == 2:
        marker = coin.SoSeparator()
        t = coin.SoTransform()
        t.translation.setValue((0, -2, 0))
        t.center.setValue((0, 2, 0))
        if invert:
            t.rotation.setValue(coin.SbVec3f((0, 0, 1)), -math.pi / 2)
        else:
            t.rotation.setValue(coin.SbVec3f((0, 0, 1)), math.pi / 2)
        c = coin.SoCone()
        c.height.setValue(4)
        marker.addChild(t)
        marker.addChild(c)
        return marker
    elif symbol == 3:
        marker = coin.SoSeparator()
        # hints are required otherwise only the bottom of the face is colored
        h = coin.SoShapeHints()
        h.vertexOrdering = h.COUNTERCLOCKWISE
        c = coin.SoCoordinate3()
        c.point.setValues([(-1, -2, 0), (0, 2, 0), (1, 2, 0), (0, -2, 0)])
        f = coin.SoFaceSet()
        marker.addChild(h)
        marker.addChild(c)
        marker.addChild(f)
        return marker
    elif symbol == 4:
        return dim_dash((-1.5, -1.5, 0), (1.5, 1.5, 0))
    else:
        _wrn(
            translate("draft",
                      "Symbol not implemented. Using a default symbol."))
        return coin.SoSphere()
Esempio n. 14
0
    def __init__(self, view):
        self.view = view
        self.fnt = []
        self.mat = []
        self.txt = {}
        self.sw = {}
        self.hide = True
        self.show = True
        self.formatTimeRemainingTotal = _formatTimeTotal

        # Background
        self.posB = coin.SoTranslation()
        self.matB = self._material(0.8)
        self.cooB = coin.SoCoordinate3()
        self.fceB = coin.SoFaceSet()

        self.cooB.point.setValues(self.pointsScaledTo(1))

        self.sepB = coin.SoSeparator()
        self.sepB.addChild(self.posB)
        self.sepB.addChild(self.matB)
        self.sepB.addChild(self.cooB)
        self.sepB.addChild(self.fceB)

        # Foreground
        self.posF = coin.SoTranslation()
        self.matF = self._material(0.7)
        self.cooF = coin.SoCoordinate3()
        self.fceF = coin.SoFaceSet()

        self.sepF = coin.SoSeparator()

        self.sepF.addChild(self.posF)
        self.sepF.addChild(self.matF)
        self.sepF.addChild(self.cooF)
        self.sepF.addChild(self.fceF)

        self.prgr = coin.SoSwitch()
        self.prgr.addChild(self.sepB)
        self.prgr.addChild(self.sepF)
        self.prgr.whichChild = coin.SO_SWITCH_ALL
        self.sw['bar'] = self.prgr

        # Elapsed
        self._createText('elapsed', '0:00', coin.SoText2.LEFT, self.MinX,
                         self.MaxY)
        self._createText('total', '0:00', coin.SoText2.RIGHT, self.MaxX,
                         self.MaxY)
        self._createText('percent', '0%', coin.SoText2.CENTER, 0, self.MaxY)

        # tie everything together under a switch
        self.sep = coin.SoSwitch()
        for sw in self.sw.values():
            self.sep.addChild(sw)
        self.sep.whichChild = coin.SO_SWITCH_ALL

        # timing
        self.start = None
        self.elapsed = None
        self.line = None
        self.pathLength = None
Esempio n. 15
0
def dim_symbol(symbol=None, invert=False):
    """Return the specified dimension symbol.

    Parameters
    ----------
    symbol: int, optional
        It defaults to `None`, in which it gets the value from the parameter
        database, `get_param("dimsymbol", 0)`.

        A numerical value defines different markers
         * 0, `SoSphere`
         * 1, `SoMarkerSet` with a circle
         * 2, `SoSeparator` with a `soCone`
         * 3, `SoSeparator` with a `SoFaceSet`
         * 4, `SoSeparator` with a `SoLineSet`, calling `dim_dash`
         * Otherwise, `SoSphere`

    invert: bool, optional
        It defaults to `False`.
        If it is `True` and `symbol=2`, the cone will be rotated
        -90 degrees around the Z axis, otherwise the rotation is positive,
        +90 degrees.

    Returns
    -------
    Coin.SoNode
        A `Coin.SoSphere`, or `Coin.SoMarkerSet` (circle),
        or `Coin.SoSeparator` (cone, face, line)
        that will be used as a dimension symbol.
    """
    if symbol is None:
        symbol = utils.get_param("dimsymbol", 0)

    if symbol == 0:
        # marker = coin.SoMarkerSet()
        # marker.markerIndex = 80

        # Returning a sphere means that the bounding box will
        # be 3-dimensional; a marker will always be planar seen from any
        # orientation but it currently doesn't work correctly
        marker = coin.SoSphere()
        return marker
    elif symbol == 1:
        marker = coin.SoMarkerSet()
        # Should be the same as
        # marker.markerIndex = 10
        marker.markerIndex = Gui.getMarkerIndex("circle", 9)
        return marker
    elif symbol == 2:
        marker = coin.SoSeparator()
        t = coin.SoTransform()
        t.translation.setValue((0, -2, 0))
        t.center.setValue((0, 2, 0))
        if invert:
            t.rotation.setValue(coin.SbVec3f((0, 0, 1)), -math.pi/2)
        else:
            t.rotation.setValue(coin.SbVec3f((0, 0, 1)), math.pi/2)
        c = coin.SoCone()
        c.height.setValue(4)
        marker.addChild(t)
        marker.addChild(c)
        return marker
    elif symbol == 3:
        marker = coin.SoSeparator()
        c = coin.SoCoordinate3()
        c.point.setValues([(-1, -2, 0), (0, 2, 0),
                           (1, 2, 0), (0, -2, 0)])
        f = coin.SoFaceSet()
        marker.addChild(c)
        marker.addChild(f)
        return marker
    elif symbol == 4:
        return dimDash((-1.5, -1.5, 0), (1.5, 1.5, 0))
    else:
        _wrn(_tr("Symbol not implemented. Use a default symbol."))
        return coin.SoSphere()
Esempio n. 16
0
 def __init__(self, points, dynamic=False):
     super(Polygon, self).__init__(points, dynamic)
     self.polygon = coin.SoFaceSet()
     self.addChild(self.polygon)
Esempio n. 17
0
    def __init__(self, layout=0):
        node = Gui.ActiveDocument.ActiveView.getSceneGraph()

        bb = coin.SoVRMLBillboard()
        b = coin.SoSphere()
        t = coin.SoTransform()
        t.translation.setValue(FreeCAD.Vector(0, 0, 10))

        mat = coin.SoMaterial()
        # mat.diffuseColor.setValue([1.,0.,1.])
        mat.emissiveColor.setValue([1., 1., 0.])

        ssa = coin.SoSeparator()
        ssa.addChild(t)
        ssa.addChild(bb)

        node.addChild(ssa)
        if layout == 0:
            vertices = [
                (30, 20, 0),
                (30, 50, 0),
                (0, 50, 0),
                (0, 0, 0),
            ]
        if layout == 1:
            vertices = [
                (30, 80, 0),
                (0, 80, 0),
                (0, 0, 0),
            ]
        if layout == 2:
            vertices = [(60, 80, 0), (0, 80, 0), (0, 0, 0), (60, 0, 0)]

        vc = len(vertices)
        numvertices = (vc, vc)

        myVertexProperty = coin.SoVertexProperty()
        myVertexProperty.vertex.setValues(0, vc, vertices)

        # Define the FaceSet
        myFaceSet = coin.SoFaceSet()
        myFaceSet.vertexProperty = myVertexProperty
        myFaceSet.numVertices.setValues(0, 1, numvertices)

        ss = coin.SoSeparator()
        bb.addChild(ss)

        africaSep = coin.SoSeparator()
        africaTranslate = coin.SoTranslation()
        font = coin.SoFont()
        font.size = 20
        africaText = coin.SoText2()
        africaTranslate.translation = (2., 40.0, 1.)
        # africaText.string = "AFRICA"
        africaText.string.setValues(
            ["Station", "", "Road 66", "AB - CD", "EF"])
        bb.addChild(africaSep)
        textmat = coin.SoMaterial()
        textmat.diffuseColor.setValue([0., 0., 0.])
        # mat.emissiveColor.setValue([1.,1.,0.])
        africaSep.addChild(font)
        africaSep.addChild(textmat)
        africaSep.addChild(africaTranslate)
        africaSep.addChild(africaText)

        ss.addChild(mat)
        ss.addChild(myFaceSet)
        ss.addChild(b)
        self.placement = t
        self.material = mat
        self.face = ss

        self.parentN = node
        self.billboard = ssa
        self.text = africaText