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")
def onChanged(self,vobj,prop): if prop == "ShowNodes": if hasattr(self,"nodes"): vobj.Annotation.removeChild(self.nodes) del self.nodes if vobj.ShowNodes: from pivy import coin self.nodes = coin.SoAnnotation() self.coords = coin.SoCoordinate3() self.mat = coin.SoMaterial() self.pointstyle = coin.SoDrawStyle() self.pointstyle.style = coin.SoDrawStyle.POINTS self.pointset = coin.SoType.fromName("SoBrepPointSet").createInstance() self.linestyle = coin.SoDrawStyle() self.linestyle.style = coin.SoDrawStyle.LINES self.lineset = coin.SoType.fromName("SoBrepEdgeSet").createInstance() self.facestyle = coin.SoDrawStyle() self.facestyle.style = coin.SoDrawStyle.FILLED self.shapehints = coin.SoShapeHints() self.shapehints.faceType = coin.SoShapeHints.UNKNOWN_FACE_TYPE self.fmat = coin.SoMaterial() self.fmat.transparency.setValue(0.75) self.faceset = coin.SoIndexedFaceSet() self.nodes.addChild(self.coords) self.nodes.addChild(self.mat) self.nodes.addChild(self.pointstyle) self.nodes.addChild(self.pointset) self.nodes.addChild(self.linestyle) self.nodes.addChild(self.lineset) self.nodes.addChild(self.facestyle) self.nodes.addChild(self.shapehints) self.nodes.addChild(self.fmat) self.nodes.addChild(self.faceset) vobj.Annotation.addChild(self.nodes) self.updateData(vobj.Object,"Nodes") self.onChanged(vobj,"NodeColor") self.onChanged(vobj,"NodeLine") self.onChanged(vobj,"NodeSize") elif prop == "NodeColor": if hasattr(self,"mat"): l = vobj.NodeColor self.mat.diffuseColor.setValue([l[0],l[1],l[2]]) self.fmat.diffuseColor.setValue([l[0],l[1],l[2]]) elif prop == "NodeLine": if hasattr(self,"linestyle"): self.linestyle.lineWidth = vobj.NodeLine elif prop == "NodeSize": if hasattr(self,"pointstyle"): self.pointstyle.pointSize = vobj.NodeSize elif prop == "NodeType": self.updateData(vobj.Object,"Nodes") else: ArchComponent.ViewProviderComponent.onChanged(self,vobj,prop)
def _build_drag_line(self): """ Build the drag line for drag operations """ _m = coin.SoMarkerSet() _l = coin.SoLineSet() _l.numVertices.setValue(2) _d = coin.SoDrawStyle() _d.linePattern = 0x0f0f _d.lineWeight = 2 _c = coin.SoBaseColor() _c.rgb = (0.8, 0.8, 1.0) _g = coin.SoGroup() _g.addChild(_d) _g.addChild(_c) _g.addChild(self.drag_line_coord) _g.addChild(_m) _g.addChild(_l) self.root.addChild(_g)
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.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") return
def _get_bspline(self): """ returns a coin.SoNurbsCurve and the poles seperators set the pole-values by poels.point.setValues(0, 9, mat.tolist()) """ draw_style = coin.SoDrawStyle() draw_style.lineWidth = 2 complexity = coin.SoComplexity() complexity.value = 1. spline_sep = coin.SoSeparator() upper_sep = coin.SoSeparator() lower_sep = coin.SoSeparator() knot_vector = 5 * [0] + [0.2, 0.4, 0.6, 0.8] + 5 * [1] upper_curve = coin.SoNurbsCurve() lower_curve = coin.SoNurbsCurve() upper_curve.knotVector.setValues(0, len(knot_vector), knot_vector) lower_curve.knotVector.setValues(0, len(knot_vector), knot_vector) upper_curve.numControlPoints = 9 lower_curve.numControlPoints = 9 upper_poles = coin.SoCoordinate4() lower_poles = coin.SoCoordinate4() upper_line_set = coin.SoLineSet() lower_line_set = coin.SoLineSet() # no need to set degree. Should be computed by numControlPoints and knotvector upper_sep += [ complexity, upper_poles, upper_line_set, draw_style, upper_curve ] lower_sep += [ complexity, lower_poles, lower_line_set, draw_style, lower_curve ] spline_sep += [upper_sep, lower_sep] return (spline_sep, upper_poles, lower_poles)
def __init__(self, points, dynamic=False): super(Line, self).__init__(dynamic) self.drawstyle = coin.SoDrawStyle() self.line = coin.SoLineSet() self.points = points self.addChild(self.drawstyle) self.addChild(self.line)
def attach(self,vobj): self.mat1 = coin.SoMaterial() self.mat2 = coin.SoMaterial() self.fcoords = coin.SoCoordinate3() #fs = coin.SoType.fromName("SoBrepFaceSet").createInstance() # this causes a FreeCAD freeze for me fs = coin.SoIndexedFaceSet() fs.coordIndex.setValues(0,7,[0,1,2,-1,0,2,3]) self.drawstyle = coin.SoDrawStyle() self.drawstyle.style = coin.SoDrawStyle.LINES self.lcoords = coin.SoCoordinate3() ls = coin.SoType.fromName("SoBrepEdgeSet").createInstance() ls.coordIndex.setValues(0,57,[0,1,-1,2,3,4,5,-1,6,7,8,9,-1,10,11,-1,12,13,14,15,-1,16,17,18,19,-1,20,21,-1,22,23,24,25,-1,26,27,28,29,-1,30,31,-1,32,33,34,35,-1,36,37,38,39,-1,40,41,42,43,44]) sep = coin.SoSeparator() psep = coin.SoSeparator() fsep = coin.SoSeparator() fsep.addChild(self.mat2) fsep.addChild(self.fcoords) fsep.addChild(fs) psep.addChild(self.mat1) psep.addChild(self.drawstyle) psep.addChild(self.lcoords) psep.addChild(ls) sep.addChild(fsep) sep.addChild(psep) vobj.addDisplayMode(sep,"Default") self.onChanged(vobj,"DisplaySize") self.onChanged(vobj,"LineColor") self.onChanged(vobj,"Transparency")
def __init__(self, color = (0.,0.,0.), lineWidth = 1.0, pointSize = 1.0): super(styleNode, self).__init__() self.drawStyle = coin.SoDrawStyle() self.addChild(self.drawStyle) self.color = color self.lineWidth = lineWidth self.pointSize = pointSize
def __init__(self, name="GridView"): super(gridView, self).__init__() self.setName(name) self._number_of_points = 50 self._center = (0, 0) self._scale = 1.0 self._axis = 0 # 1=X 2=Y 3=Z self.transform = coin.SoTransform() self.coord = coin.SoCoordinate3() self.sep1 = coin.SoSeparator() self.sep1.setName("Snap_Points") self.sep2 = coin.SoSeparator() self.sep2.setName("Grid") self.sep3 = coin.SoSeparator() self.sep3.setName("Axis") self.addChild(self.transform) self.addChild(self.coord) self.addChild(self.sep1) self.addChild(self.sep2) self.addChild(self.sep3) ps = coin.SoPointSet() ds = coin.SoDrawStyle() ds.pointSize = 1 self.sep1.addChild(ds) self.sep1.addChild(ps) self.color1 = (0.82, 0.15, 0.15) # red (X) self.color2 = (0.40, 0.59, 0.20) # green (Y) self.color3 = (0.13, 0.49, 0.88) # blue (Z)
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)
def build_axis(self): np = self._number_of_points n = 1 + 2 * np ds = coin.SoDrawStyle() ds.lineWidth = 2 self.sep3.addChild(ds) self.mat1 = coin.SoMaterial() #bind1 = coin.SoMaterialBinding() #bind1.value = coin.SoMaterialBinding.PER_PART ax = coin.SoIndexedLineSet() ax.coordIndex.setValue(0) ax.coordIndex.setValues(0, 3, [n * np, n * (np + 1) - 1, -1]) #self.sep3.addChild(bind1) self.sep3.addChild(self.mat1) self.sep3.addChild(ax) self.mat2 = coin.SoMaterial() #bind2 = coin.SoMaterialBinding() #bind2.value = coin.SoMaterialBinding.PER_PART ax2 = coin.SoIndexedLineSet() ax2.coordIndex.setValue(0) ax2.coordIndex.setValues(0, 3, [np, n * (n - 1) + np, -1]) #self.sep3.addChild(bind2) self.sep3.addChild(self.mat2) self.sep3.addChild(ax2)
def __init__(self, spGrp): self.__color = coin.SoBaseColor() self.__drawStyle = coin.SoDrawStyle() spGrp.addChild(self.__color) spGrp.addChild(self.__drawStyle) self.__group = spGrp self.style()
def setup_default_display_mode(self, vobj): """Setup the coin nodes of the placeholder representation of the Section Plane.""" self.clip = None self.mat1 = coin.SoMaterial() self.mat2 = coin.SoMaterial() self.fcoords = coin.SoCoordinate3() #fs = coin.SoType.fromName("SoBrepFaceSet").createInstance() # this causes a FreeCAD freeze for me fs = coin.SoIndexedFaceSet() fs.coordIndex.setValues(0, 7, [0, 1, 2, -1, 0, 2, 3]) self.drawstyle = coin.SoDrawStyle() self.drawstyle.style = coin.SoDrawStyle.LINES self.lcoords = coin.SoCoordinate3() ls = coin.SoType.fromName("SoBrepEdgeSet").createInstance() ls.coordIndex.setValues(0, 57, [ 0, 1, -1, 2, 3, 4, 5, -1, 6, 7, 8, 9, -1, 10, 11, -1, 12, 13, 14, 15, -1, 16, 17, 18, 19, -1, 20, 21, -1, 22, 23, 24, 25, -1, 26, 27, 28, 29, -1, 30, 31, -1, 32, 33, 34, 35, -1, 36, 37, 38, 39, -1, 40, 41, 42, 43, 44 ]) sep = coin.SoSeparator() psep = coin.SoSeparator() fsep = coin.SoSeparator() fsep.addChild(self.mat2) fsep.addChild(self.fcoords) fsep.addChild(fs) psep.addChild(self.mat1) psep.addChild(self.drawstyle) psep.addChild(self.lcoords) psep.addChild(ls) sep.addChild(fsep) sep.addChild(psep) vobj.addDisplayMode(sep, "Default")
def attach(self,vobj): '''Setup the scene sub-graph of the view provider''' self.mattext = coin.SoMaterial() textdrawstyle = coin.SoDrawStyle() textdrawstyle.style = coin.SoDrawStyle.FILLED self.trans = coin.SoTransform() self.font = coin.SoFont() self.text2d = coin.SoAsciiText() self.text3d = coin.SoText2() self.text2d.string = self.text3d.string = "Label" # need to init with something, otherwise, crash! self.text2d.justification = coin.SoAsciiText.LEFT self.text3d.justification = coin.SoText2.LEFT self.node2d = coin.SoGroup() self.node2d.addChild(self.trans) self.node2d.addChild(self.mattext) self.node2d.addChild(textdrawstyle) self.node2d.addChild(self.font) self.node2d.addChild(self.text2d) self.node3d = coin.SoGroup() self.node3d.addChild(self.trans) self.node3d.addChild(self.mattext) self.node3d.addChild(textdrawstyle) self.node3d.addChild(self.font) self.node3d.addChild(self.text3d) vobj.addDisplayMode(self.node2d,"2D text") vobj.addDisplayMode(self.node3d,"3D text") self.onChanged(vobj,"TextColor") self.onChanged(vobj,"FontSize") self.onChanged(vobj,"FontName") self.onChanged(vobj,"Justification") self.onChanged(vobj,"LineSpacing")
def __init__(self, names, children=None, select=True, group=False): """ Constructor """ self.visible = False self.select = select self.color = coin.SoBaseColor() self.draw_style = coin.SoDrawStyle() self.names = names self.node = coin.SoSeparator() self.parent = None if not children: children = [] if group: self.node = coin.SoGroup() if self.select: self.node = \ coin.SoType.fromName("SoFCSelection").createInstance() self.node.documentName.setValue(self.names[0]) self.node.objectName.setValue(self.names[1]) self.node.subElementName.setValue(self.names[2]) for child in [self.draw_style, self.color] + children: self.node.addChild(child)
def attach(self,vobj): self.clip = None self.mat1 = coin.SoMaterial() self.mat2 = coin.SoMaterial() self.fcoords = coin.SoCoordinate3() fs = coin.SoIndexedFaceSet() fs.coordIndex.setValues(0,7,[0,1,2,-1,0,2,3]) self.drawstyle = coin.SoDrawStyle() self.drawstyle.style = coin.SoDrawStyle.LINES self.lcoords = coin.SoCoordinate3() ls = coin.SoType.fromName("SoBrepEdgeSet").createInstance() ls.coordIndex.setValues(0,28,[0,1,-1,2,3,4,5,-1,6,7,-1,8,9,10,11,-1,12,13,-1,14,15,16,17,-1,18,19,20,21]) sep = coin.SoSeparator() psep = coin.SoSeparator() fsep = coin.SoSeparator() fsep.addChild(self.mat2) fsep.addChild(self.fcoords) fsep.addChild(fs) psep.addChild(self.mat1) psep.addChild(self.drawstyle) psep.addChild(self.lcoords) psep.addChild(ls) sep.addChild(fsep) sep.addChild(psep) vobj.addDisplayMode(sep,"Default") self.onChanged(vobj,"DisplaySize") self.onChanged(vobj,"LineColor") self.onChanged(vobj,"Transparency") self.Object = vobj.Object
def draw_line(p1, p2, color, LineWidth): try: dash = coin.SoSeparator() v = coin.SoVertexProperty() v.vertex.set1Value(0, p1) v.vertex.set1Value(1, p2) coords = coin.SoTransform() line = coin.SoLineSet() line.vertexProperty = v style = coin.SoDrawStyle() style.lineWidth = LineWidth dash.addChild(style) col1 = coin.SoBaseColor() # must be converted to SoBaseColor col1.rgb = color dash.addChild(col1) dash.addChild(line) dash.addChild(coords) return dash except Exception as err: App.Console.PrintError("'makeIt' Failed. " "{err}\n".format(err=str(err))) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)
def draw_polygon(vertices, color, LineWidth): """ Draw any polygon. This will be the base of all multi-point drawing. Curves, and arc is not here. """ if len(vertices) < 4: raise ValueError('Vertices must be 4') _polygon = coin.SoSeparator() col = coin.SoBaseColor() col.rgb = color coords = coin.SoTransform() data = coin.SoCoordinate3() face = coin.SoIndexedFaceSet() style = coin.SoDrawStyle() style.lineWidth = LineWidth _polygon.addChild(style) _polygon.addChild(col) _polygon.addChild(coords) _polygon.addChild(data) _polygon.addChild(face) i = 0 for vr in vertices: data.point.set1Value(i, vr[0], vr[1], vr[2]) i += 1 polygons = [ 0, 1, 2, 3, -1 ] # -1 means that the n-gon is terminated and a new one can be created with the next points i = 0 for p in polygons: face.coordIndex.set1Value(i, p) i += 1 return _polygon
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
def attach(self, obj): material = coin.SoMaterial() material.diffuseColor = (1.0, 0.0, 0.0) material.emissiveColor = (1.0, 0.0, 0.0) drawStyle = coin.SoDrawStyle() drawStyle.pointSize.setValue(10) drawStyle.style = coin.SoDrawStyle.LINES wireframe = coin.SoGroup() shaded = coin.SoGroup() self.wireframe = wireframe self.shaded = shaded self.coords = coin.SoCoordinate3() self.coords.point.setValues(0, 2, [FreeCAD.Vector(0, 0, 0), FreeCAD.Vector(1, 0, 0)]) wireframe += self.coords wireframe += drawStyle wireframe += material shaded += self.coords shaded += drawStyle shaded += material g = coin.SoGroup() sel1 = coin.SoType.fromName('SoFCSelection').createInstance() sel1.style = 'EMISSIVE_DIFFUSE' p1 = coin.SoType.fromName('SoIndexedPointSet').createInstance() p1.coordIndex.set1Value(0, 0) sel1 += p1 g += sel1 wireframe += g shaded += g g = coin.SoGroup() sel2 = coin.SoType.fromName('SoFCSelection').createInstance() sel2.style = 'EMISSIVE_DIFFUSE' p2 = coin.SoType.fromName('SoIndexedPointSet').createInstance() p2.coordIndex.set1Value(0, 1) sel2 += p2 g += sel2 wireframe += g shaded += g g = coin.SoGroup() sel3 = coin.SoType.fromName('SoFCSelection').createInstance() sel3.style = 'EMISSIVE_DIFFUSE' p3 = coin.SoType.fromName('SoIndexedLineSet').createInstance() p3.coordIndex.setValues(0, 2, [0, 1]) sel3 += p3 g += sel3 wireframe += g shaded += g obj.addDisplayMode(wireframe, 'Wireframe') obj.addDisplayMode(shaded, 'Shaded') self.sel1 = sel1 self.sel2 = sel2 self.sel3 = sel3 self.constructed = True self.updateData(obj.Object, 'p2')
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)
def attach(self, obj): self.wireframe = coin.SoGroup() self.shaded = coin.SoSeparator() self.drawStyle = coin.SoDrawStyle() self.drawStyle.pointSize.setValue(10) self.drawStyle.style = coin.SoDrawStyle.LINES self.pointMaterial = coin.SoMaterial() self.pointMaterial.diffuseColor = (1.0, 0.0, 0.0) self.shaded += self.drawStyle self.shaded += self.pointMaterial self.wireframe += self.drawStyle self.wireframe += self.pointMaterial vertex_data = obj.Object.getPropertyByName('Points') n = obj.Object.getPropertyByName('NetWidth') m = obj.Object.getPropertyByName('NetLength') coord = coin.SoCoordinate3() coord.point.setValues(0, len(vertex_data), vertex_data) for ii in range(n): for jj in range(m): sep = coin.SoSeparator() sep += self.pointMaterial p = vertex_data[ii * m + jj] co = coin.SoCoordinate3() co.point.setValue(p[0], p[1], p[2]) sep += co s = coin.SoType.fromName('SoPointSet').createInstance() s.numPoints.setValue(1) sep += s self.shaded += sep stations = coin.SoSeparator() stations += coord for ii in range(n): sep = coin.SoSeparator() indices = [ii + jj * n for jj in range(m)] lineSet = coin.SoType.fromName('SoBrepEdgeSet').createInstance() lineSet.coordIndex.setValues(0, len(indices), indices) sep += lineSet stations += sep self.shaded += stations self.wireframe += stations lines = coin.SoSeparator() lines += coord for jj in range(m): indices = [ii + jj * n for ii in range(n)] lineSet = coin.SoType.fromName('SoBrepEdgeSet').createInstance() lineSet.coordIndex.setValues(0, len(indices), indices) lines += lineSet self.shaded += lines self.wireframe += lines obj.addDisplayMode(self.wireframe, 'Wireframe') obj.addDisplayMode(self.shaded, 'Shaded')
def makeWindRose(epwfile,scale=1,sectors=24): """makeWindRose(site,sectors): returns a wind rose diagram as a pivy node""" try: import ladybug from ladybug import epw except Exception: FreeCAD.Console.PrintError("The ladybug module was not found. Unable to generate solar diagrams\n") return None if not epwfile: FreeCAD.Console.PrintWarning("No EPW file, unable to generate wind rose.\n") return None epw_data = ladybug.epw.EPW(epwfile) baseangle = 360/sectors sectorangles = [i * baseangle for i in range(sectors)] # the divider angles between each sector basebissect = baseangle/2 angles = [basebissect] # build a list of central direction for each sector for i in range(1,sectors): angles.append(angles[-1]+baseangle) windsbysector = [0 for i in range(sectors)] # prepare a holder for values for each sector for hour in epw_data.wind_direction: sector = min(angles, key=lambda x:abs(x-hour)) # find the closest sector angle sectorindex = angles.index(sector) windsbysector[sectorindex] = windsbysector[sectorindex] + 1 maxwind = max(windsbysector) windsbysector = [wind/maxwind for wind in windsbysector] # normalize vectors = [] # create 3D vectors dividers = [] for i in range(sectors): angle = math.radians(90 + angles[i]) x = math.cos(angle) * windsbysector[i] * scale y = math.sin(angle) * windsbysector[i] * scale vectors.append(FreeCAD.Vector(x,y,0)) secangle = math.radians(90 + sectorangles[i]) x = math.cos(secangle) * scale y = math.sin(secangle) * scale dividers.append(FreeCAD.Vector(x,y,0)) vectors.append(vectors[0]) # build coin node import Part from pivy import coin masternode = coin.SoSeparator() for r in (0.25,0.5,0.75,1.0): c = Part.makeCircle(r * scale) masternode.addChild(toNode(c)) for divider in dividers: l = Part.makeLine(FreeCAD.Vector(),divider) masternode.addChild(toNode(l)) ds = coin.SoDrawStyle() ds.lineWidth = 2.0 masternode.addChild(ds) d = Part.makePolygon(vectors) masternode.addChild(toNode(d)) return masternode
def attach(self, vobj): '''Setup the scene sub-graph of the view provider''' from pivy import coin self.Object = vobj.Object self.color = coin.SoBaseColor() if hasattr(vobj, "LineColor"): self.color.rgb.setValue(vobj.LineColor[0], vobj.LineColor[1], vobj.LineColor[2]) self.font = coin.SoFont() self.font3d = coin.SoFont() self.text = coin.SoAsciiText() self.text3d = coin.SoText2() self.text.string = "d" # some versions of coin crash if string is not set self.text3d.string = "d" self.text.justification = self.text3d.justification = coin.SoAsciiText.CENTER self.textpos = coin.SoTransform() label = coin.SoSeparator() label.addChild(self.textpos) label.addChild(self.color) label.addChild(self.font) label.addChild(self.text) label3d = coin.SoSeparator() label3d.addChild(self.textpos) label3d.addChild(self.color) label3d.addChild(self.font3d) label3d.addChild(self.text3d) self.coord1 = coin.SoCoordinate3() self.trans1 = coin.SoTransform() self.coord2 = coin.SoCoordinate3() self.trans2 = coin.SoTransform() self.marks = coin.SoSeparator() self.drawstyle = coin.SoDrawStyle() self.coords = coin.SoCoordinate3() self.arc = coin.SoType.fromName("SoBrepEdgeSet").createInstance() self.node = coin.SoGroup() self.node.addChild(self.color) self.node.addChild(self.drawstyle) self.node.addChild(self.coords) self.node.addChild(self.arc) self.node.addChild(self.marks) self.node.addChild(label) self.node3d = coin.SoGroup() self.node3d.addChild(self.color) self.node3d.addChild(self.drawstyle) self.node3d.addChild(self.coords) self.node3d.addChild(self.arc) self.node3d.addChild(self.marks) self.node3d.addChild(label3d) vobj.addDisplayMode(self.node, "2D") vobj.addDisplayMode(self.node3d, "3D") self.updateData(vobj.Object, None) self.onChanged(vobj, "FontSize") self.onChanged(vobj, "FontName") self.onChanged(vobj, "ArrowType") self.onChanged(vobj, "LineColor") # backwards compatibility self.ScaleMultiplier = 1.00
def makeBubbles(self): import Part def getNode(): # make sure we already have the complete node built r = self.ViewObject.RootNode if r.getChildren().getLength() > 2: if r.getChild(2).getChildren().getLength() > 0: if r.getChild(2).getChild(0).getChildren().getLength() > 0: return self.ViewObject.RootNode.getChild(2).getChild( 0).getChild(0) return None rn = getNode() if rn: if self.bubbles: rn.removeChild(self.bubbles) self.bubbles = None self.bubbles = coin.SoSeparator() isep = coin.SoSeparator() self.bubblestyle = coin.SoDrawStyle() self.bubblestyle.linePattern = 0xffff self.bubbles.addChild(self.bubblestyle) for i in range(len(self.ViewObject.Object.Distances)): invpl = self.ViewObject.Object.Placement.inverse() verts = self.ViewObject.Object.Shape.Edges[i].Vertexes p1 = invpl.multVec(verts[0].Point) p2 = invpl.multVec(verts[1].Point) dv = p2.sub(p1) dv.normalize() rad = self.ViewObject.BubbleSize center = p2.add(dv.scale(rad, rad, rad)) ts = Part.makeCircle(rad, center).writeInventor() cin = coin.SoInput() cin.setBuffer(ts) cob = coin.SoDB.readAll(cin) co = cob.getChild(1).getChild(0).getChild(2) li = cob.getChild(1).getChild(0).getChild(3) self.bubbles.addChild(co) self.bubbles.addChild(li) st = coin.SoSeparator() tr = coin.SoTransform() tr.translation.setValue( (center.x, center.y - rad / 4, center.z)) fo = coin.SoFont() fo.name = "Arial,Sans" fo.size = rad * 100 tx = coin.SoText2() tx.justification = coin.SoText2.CENTER tx.string = self.getNumber(i) st.addChild(tr) st.addChild(fo) st.addChild(tx) isep.addChild(st) self.bubbles.addChild(isep) rn.addChild(self.bubbles)
def attach(self, vobj): from pivy import coin self.centerlinegroup = coin.SoSeparator() self.centerlinegroup.setName("Centerline") self.centerlinecolor = coin.SoBaseColor() self.centerlinestyle = coin.SoDrawStyle() self.centerlinegroup.addChild(self.centerlinecolor) self.centerlinegroup.addChild(self.centerlinestyle) vobj.addDisplayMode(self.centerlinegroup, "Centerline") ArchComponent.ViewProviderComponent.attach(self, vobj)
def __init__(self): self.trans = coin.SoTransform() w = coin.SoDrawStyle() w.style = coin.SoDrawStyle.LINES cube = coin.SoCube() self.array = coin.SoArray() self.array.addChild(cube) Tracker.__init__( self, children=[self.trans, w, self.array], name="arrayBoxTracker" )
def __init__(self, points, color='black', width=1): self.object = coin.SoSeparator() self.ls = coin.SoLineSet() self.data = coin.SoCoordinate3() self.color = coin.SoMaterial() self.drawstyle = coin.SoDrawStyle() self.points = list(map(vector3D, points)) self.color.diffuseColor = COLORS[color] self.drawstyle.lineWidth = width self.update() self.object += [self.color, self.drawstyle, self.data, self.ls]
def __init__(self, points, width=1): self.object = coin.SoSeparator() self.ls = coin.SoLineSet() self.data = coin.SoCoordinate3() self.color = coin.SoMaterial() self.drawstyle = coin.SoDrawStyle() self.points = points self.color.diffuseColor = (1., 1., 1.) self.drawstyle.lineWidth = width self.update() self.object += self.color, self.drawstyle, self.data, self.ls
def showStatisticsLine(self, docName , shapeName , pts , color): import FreeCADGui from pivy import coin sg = FreeCADGui.getDocument(docName).ActiveView.getSceneGraph() lines = coin.SoSeparator() self.__setRootNode(docName, sg, lines) drawStyle = coin.SoDrawStyle() drawStyle.style = coin.SoDrawStyle.LINES drawStyle.lineWidth = 2 # drawStyle.pointSize = 3 lines.addChild(drawStyle) # norm = coin.SoNormal() # norm.vector.setValue(0,0,1) # lines.addChild(norm) # set color for block matColors = coin.SoMaterial() col = (color[0],color[1],color[2]) # matColors.ambientColor.setValue(color[0],color[1],color[2]) # matColors.diffuseColor.setValue(color[0],color[1],color[2]) # matColors.specularColor.setValue(color[0],color[1],color[2]) matColors.diffuseColor.setValues(0,len(pts),[col]*len(pts)) lines.addChild(matColors) tmpMatBind = coin.SoMaterialBinding() tmpMatBind.value = coin.SoMaterialBinding.PER_PART lines.addChild(tmpMatBind) # lineColor = coin.SoBaseColor() # lineColor.rgb = (color[0],color[1],color[2]) # lines.addChild(lineColor) # point # tmpPts = [] # for i in range(len(pts)-1): # tmpPts.append(pts[i]) # tmpPts.append(pts[i+1]) data = coin.SoCoordinate3() # data.point.setValues(0 , len(tmpPts),tmpPts) data.point.setValues(0 , len(pts),pts) lines.addChild(data) lineset=coin.SoLineSet() lineset.numVertices.setValues(0,1, [len(pts)] ) # lineset = coin.SoIndexedLineSet() # nums = range(len(pts)) # nums.append(-1) # lineset.coordIndex.setValues(0,len(nums), nums) lines.addChild(lineset) self.__setRootNode(docName, sg , lines)