def attach(self, vobj): # self.ViewObject = vobj self.Object = vobj.Object self.gridDM = coin.SoGroup() self.pointsDM = coin.SoGroup() self.ProfDM = coin.SoGroup() self.railDM = coin.SoGroup() self.coord = CoinNodes.coordinate3Node(self.Object.Points) self.row = CoinNodes.rowNode((0.8, 0.4, 0.4), 1.0) self.col = CoinNodes.colNode((0.4, 0.4, 0.8), 1.0) self.pointSet = coin.SoPointSet() self.style = CoinNodes.styleNode((0, 0, 0), 1.0, 2.0) self.style.addChild(self.pointSet) # vobj.addChild(self.coord) self.ProfDM.addChild(self.coord) self.ProfDM.addChild(self.row) self.railDM.addChild(self.coord) self.railDM.addChild(self.col) self.gridDM.addChild(self.coord) self.gridDM.addChild(self.row) self.gridDM.addChild(self.col) self.pointsDM.addChild(self.coord) self.pointsDM.addChild(self.style) # self.points.addChild(self.pointSet) vobj.addDisplayMode(self.gridDM, "Wireframe") vobj.addDisplayMode(self.pointsDM, "Points") vobj.addDisplayMode(self.ProfDM, "Profiles") vobj.addDisplayMode(self.railDM, "Rails")
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)
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
def surfNode(surf): bspline = False rational = False try: poles = surf.getPoles() weights = surf.getWeights() nbU = int(surf.NbUPoles) nbV = int(surf.NbVPoles) except: return False try: rational = surf.isURational() or surf.isVRational() except: pass try: uknots = surf.getUKnots() vknots = surf.getVKnots() bspline = True except: bspline = False # *** Set poles *** flatPoles = to1D(poles) polesnode = coinNodes.coordinate3Node(flatPoles) # *** Set weights *** flatW = to1D(weights) weightStr = getString(flatW) polyRowSep = coinNodes.rowNode((0.5, 0, 0), 1) polyRowSep.vertices = (nbU, nbV) polyRowSep.color = [(0.5, 0.0, 0.0)] * len(flatPoles) polyColSep = coinNodes.colNode((0, 0, 0.5), 1) polyColSep.vertices = (nbU, nbV) polyColSep.color = [(0.0, 0.0, 0.5)] * len(flatPoles) # *** 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(flatPoles) - 1) u0, u1, v0, v1 = surf.bounds() halfU = u0 + 1. * (u1 - u0) / 2 halfV = v0 + 1. * (v1 - v0) / 2 UPos = surf.value(halfU, v0) Uletter = coinNodes.text2dNode((0, 0, 0), "osiFont,FreeSans,sans", 20, (UPos.x, UPos.y, UPos.z), 'U') VPos = surf.value(u0, halfV) Vletter = coinNodes.text2dNode((0, 0, 0), "osiFont,FreeSans,sans", 20, (VPos.x, VPos.y, VPos.z), 'V') vizSep = coin.SoSeparator() vizSep.addChild(polesnode) vizSep.addChild(polyRowSep) vizSep.addChild(polyColSep) vizSep.addChild(markerSep) vizSep.addChild(Uletter) vizSep.addChild(Vletter) if rational: # *** Set weight text *** weightSep = coinNodes.multiTextNode((1, 0, 0), "osiFont,FreeSans,sans", 16, 0) weightSep.data = (flatPoles, weightStr) vizSep.addChild(weightSep) if bspline: # *** Set knots *** uknotPoints = [] nb_curves = 0 for k in uknots: try: uIso = surf.uIso(k) epts = uIso.toShape().discretize(100) if len(epts) == 100: for p in epts: uknotPoints.append((p.x, p.y, p.z)) nb_curves += 1 except: FreeCAD.Console.PrintError("Error computing surface U Iso\n") if nb_curves > 0: uknotsnode = coinNodes.coordinate3Node(uknotPoints) uCurves = coinNodes.rowNode((1.0, 0.5, 0.3), 3) uCurves.color = [(1.0, 0.5, 0.3)] * 99 uCurves.color += [(0.7, 0.0, 0.3)] * (nb_curves - 1) * 99 uCurves.vertices = (nb_curves, 100) vizSep.addChild(uknotsnode) vizSep.addChild(uCurves) vknotPoints = [] nb_curves = 0 for k in vknots: try: vIso = surf.vIso(k) epts = vIso.toShape().discretize(100) if len(epts) == 100: for p in epts: vknotPoints.append((p.x, p.y, p.z)) nb_curves += 1 except: FreeCAD.Console.PrintError("Error computing surface V Iso\n") if nb_curves > 0: vknotsnode = coinNodes.coordinate3Node(vknotPoints) vCurves = coinNodes.rowNode((0.3, 0.5, 1.0), 3) vCurves.color = [(0.8, 0.8, 0.0)] * 99 vCurves.color += [(0.3, 0.0, 0.7)] * (nb_curves - 1) * 99 vCurves.vertices = (nb_curves, 100) vizSep.addChild(vknotsnode) vizSep.addChild(vCurves) # removed because of several FC crashes ## ***** isoCurves ****** #uparam = paramList(16,u0,u1) #uisoPoints = [] #nb_curves = 0 #for k in uparam: #try: #uIso = surf.uIso(k) #epts = uIso.toShape().discretize(100) #if len(epts) == 100: #for p in epts: #uisoPoints.append((p.x,p.y,p.z)) #nb_curves += 1 #except: #FreeCAD.Console.PrintError("Error computing surface U Iso\n") #if nb_curves > 0: #uisonode = coinNodes.coordinate3Node(uisoPoints) #uisoCurves = coinNodes.rowNode((0.0,0.0,0.0),1) #uisoCurves.transparency = 0.8 #uisoCurves.vertices=(nb_curves,100) #vizSep.addChild(uisonode) #vizSep.addChild(uisoCurves) ##debug(str(uCurves.vertices)) #vparam = paramList(16,v0,v1) #visoPoints = [] #nb_curves = 0 #for k in vparam: #try: #vIso = surf.vIso(k) #epts = vIso.toShape().discretize(100) #if len(epts) == 100: #for p in epts: #vknotPoints.append((p.x,p.y,p.z)) #nb_curves += 1 #except: #FreeCAD.Console.PrintError("Error computing surface V Iso\n") #if nb_curves > 0: #visonode = coinNodes.coordinate3Node(visoPoints) #visoCurves = coinNodes.rowNode((0.0,0.0,0.0),1) #visoCurves.transparency = 0.8 #visoCurves.vertices=(nb_curves,100) #vizSep.addChild(visonode) #vizSep.addChild(visoCurves) ## *** Set texts *** #multStr = [] #for m in mults: #multStr.append("%d"%m) #knotMarkerSep = coinNodes.markerSetNode((0,0,1),coin.SoMarkerSet.CIRCLE_FILLED_9_9) ## *** Set mult text *** #multSep = coinNodes.multiTextNode((0,0,1),"osiFont,FreeSans,sans",16,1) #multSep.data = (knotPoints,multStr) return vizSep