Ejemplo n.º 1
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)
Ejemplo n.º 2
0
def curveNode(cur):
    bspline = False
    rational = False
    try:
        poles = cur.getPoles()
        weights = cur.getWeights()
    except:
        return False
    try:
        rational = cur.isRational()
    except:
        pass
    try:
        knots = cur.getKnots()
        mults = cur.getMultiplicities()
        bspline = True
    except:
        bspline = False

    # *** Set poles ***
    polesnode = coinNodes.coordinate3Node(poles)

    # *** Set weights ***
    weightStr = getString(weights)

    polySep = coinNodes.polygonNode((0.5, 0.5, 0.5), 1)
    polySep.vertices = poles

    # *** Set markers ***
    markerSep = coinNodes.markerSetNode((1, 0, 0),
                                        coin.SoMarkerSet.DIAMOND_FILLED_9_9)
    markerSep.color = [(1, 0, 0)] + [(0.5, 0.0, 0.5)] * (len(poles) - 1)

    if rational:
        # *** Set weight text ***
        weightSep = coinNodes.multiTextNode((1, 0, 0), "osiFont,FreeSans,sans",
                                            16, 0)
        weightSep.data = (poles, weightStr)

    if bspline:

        # *** Set knots ***
        knotPoints = []
        for k in knots:
            p = cur.value(k)
            knotPoints.append((p.x, p.y, p.z))
        knotsnode = coinNodes.coordinate3Node(knotPoints)
        # *** Set texts ***
        multStr = []
        for m in mults:
            multStr.append("\n%d" % m)

        knotMarkerSep = coinNodes.markerSetNode(
            (0, 0, 1), coin.SoMarkerSet.CIRCLE_FILLED_5_5)
        knotMarkerSep.color = [(0, 0, 1)] * len(knotPoints)

        # *** Set mult text ***
        multSep = coinNodes.multiTextNode((0, 0, 1), "osiFont,FreeSans,sans",
                                          16, 1)
        multSep.data = (knotPoints, multStr)

    vizSep = coin.SoSeparator()
    vizSep.addChild(polesnode)
    vizSep.addChild(polySep)
    vizSep.addChild(markerSep)
    if rational:
        vizSep.addChild(weightSep)
    if bspline:
        vizSep.addChild(knotsnode)
        vizSep.addChild(knotMarkerSep)
        vizSep.addChild(multSep)
    return vizSep