def __init__(self, obj): ''' Set this object to the proxy object of the actual view provider ''' obj.Proxy = self sep1 = coin.SoSeparator() self.trl1 = coin.SoTranslation() sep1.addChild(self.trl1) sep1.addChild(coin.SoSphere()) sep2 = coin.SoSeparator() self.trl2 = coin.SoTranslation() sep2.addChild(self.trl2) sep2.addChild(coin.SoSphere()) obj.RootNode.addChild(sep1) obj.RootNode.addChild(sep2)
def __init__(self, obj): ''' Set this object to the proxy object of the actual view provider ''' sep1=coin.SoSeparator() self.trl1=coin.SoTranslation() sep1.addChild(self.trl1) sep1.addChild(coin.SoSphere()) sep2=coin.SoSeparator() self.trl2=coin.SoTranslation() sep2.addChild(self.trl2) sep2.addChild(coin.SoSphere()) obj.RootNode.addChild(sep1) obj.RootNode.addChild(sep2) # triggers an updateData call so the assignment at the end obj.Proxy = self
def displaysphere(self, point, radius=5, color=(1, 1, 1)): try: sg = self._sg except: sg = SoSeparator() self._sg = sg root = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph() root.addChild(sg) p = point #say(point,color,"##########") trans = coin.SoTranslation() trans.translation.setValue(p.x, p.y, p.z) cub = coin.SoSphere() cub.radius.setValue(radius) col = coin.SoBaseColor() col.rgb = color myCustomNode = coin.SoSeparator() myCustomNode.addChild(col) myCustomNode.addChild(trans) myCustomNode.addChild(cub) sg.addChild(myCustomNode)
def shape2shape(name, geom): ''' Convert from gegede shape to a SoShape ''' obj = geom.get_shape(name) if type(obj).__name__ == 'Box': box = coin.SoCube() box.width = 2.0 * obj.dx.to(spatial_units).magnitude box.height = 2.0 * obj.dy.to(spatial_units).magnitude box.depth = 2.0 * obj.dz.to(spatial_units).magnitude return box if type(obj).__name__ == 'Tubs': tub = coin.SoCylinder() tub.radius = obj.rmax.to(spatial_units).magnitude tub.height = 0.5 * obj.dz.to(spatial_units).magnitude # fixme: no built-in support of rmin, nor start/stop angles - need to make boolean return tub if type(obj).__name__ == 'Sphere': sph = coin.SoSphere() sph.radius = obj.rmax.to(spatial_units).magnitude # fixme: no built-in support of rmin, nor start/stop angles - need to make boolean return sph if type(obj).__name__ == 'Boolean': print( 'WARNING: Boolean shapes are not supported, simply using the first shape for %s' % obj.name) return shape2shape(obj.first, geom) raise ValueError('Unsupported shape for scenegraph: "%s"' % type(obj).__name__)
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)
def __init__(self,position=FreeCAD.Vector(0,0,0),radius=1): self.trans = coin.SoTransform() self.trans.translation.setValue([position.x,position.y,position.z]) m = coin.SoMaterial() m.transparency.setValue(0.9) m.diffuseColor.setValue([0,1,0]) self.sphere = coin.SoSphere() self.sphere.radius.setValue(radius) self.baseline = None Tracker.__init__(self,children=[self.trans,m,self.sphere],name="radiusTracker")
def navi(): '''navigator startup''' mw = QtGui.qApp #mw.setOverrideCursor(QtCore.Qt.PointingHandCursor) ef = EventFilter() ef.navi = myNavigatorWidget(ef) # get a jpg filename fn = os.path.dirname(__file__) + "/pics/transpa.jpg" sg = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph() trans = coin.SoTranslation() trans.translation.setValue([0, 0, 0]) myCustomNode = coin.SoSeparator() cub = coin.SoSphere() cub.radius.setValue(10000000) i = coin.SoRotationXYZ() i.angle.setValue(1.5708) i.axis.setValue(0) myCustomNode.addChild(i) s = coin.SoRotationXYZ() s.angle.setValue(math.pi) s.axis.setValue(1) myCustomNode.addChild(s) #myCustomNode.addChild(trans) myCustomNode.addChild(cub) sg.addChild(myCustomNode) tex = coin.SoTexture2() tex.filename = fn myCustomNode.insertChild(tex, 0) ef.background = myCustomNode ef.tex = tex FreeCAD.eventfilter = ef mw.installEventFilter(ef) on_key_press(FreeCAD.eventfilter, 'O') view = FreeCADGui.activeDocument().activeView() FreeCADGui.ActiveDocument.ActiveView.setAnimationEnabled(False) mgr = view.getViewer().getSoRenderManager() mgr.setAutoClipping(0) FreeCAD.ActiveDocument.recompute() FreeCADGui.updateGui() return ef
def __init__(self, obj): ''' Set this object to the proxy object of the actual view provider ''' obj.Proxy = self self.ViewObject = obj sep1=coin.SoSeparator() sel1 = coin.SoType.fromName('SoFCSelection').createInstance() # sel1.policy.setValue(coin.SoSelection.SHIFT) sel1.ref() sep1.addChild(sel1) self.trl1=coin.SoTranslation() sel1.addChild(self.trl1) sel1.addChild(coin.SoSphere()) sep2=coin.SoSeparator() sel2 = coin.SoType.fromName('SoFCSelection').createInstance() sel2.ref() sep2.addChild(sel2) self.trl2=coin.SoTranslation() sel2.addChild(self.trl2) sel2.addChild(coin.SoSphere()) obj.RootNode.addChild(sep1) obj.RootNode.addChild(sep2) self.updateData(obj.Object, 'p2') self.sel1 = sel1 self.sel2 = sel2
def __init__(self, point, colors): self.point = point self.color = colors self.sep = coin.SoSeparator() self.pos = coin.SoTranslation() self.pos.translation = (point.x, point.y, point.z) self.sphere = coin.SoSphere() self.scale = coin.SoType.fromName('SoShapeScale').createInstance() self.scale.setPart('shape', self.sphere) self.scale.scaleFactor.setValue(7) self.material = coin.SoMaterial() self.sep.addChild(self.pos) self.sep.addChild(self.material) self.sep.addChild(self.scale) self.enabled = True self.selected = False
def createAButton(self, _vector, _color, _rotation): color = coin.SoBaseColor() color.rgb = _color transform = coin.SoTransform() tempR = coin.SbVec3f() tempR.setValue(_rotation[0], _rotation[1], _rotation[2]) transform.rotation.setValue(tempR, math.radians(_rotation[3])) sphere = coin.SoSphere() sphere.radius = self.ButtonRadius transBar = coin.SoTranslation() transBar.translation.setValue(_vector) barLine = coin.SoSeparator() barLine.addChild(color) barLine.addChild(transBar) barLine.addChild(transform) barLine.addChild(sphere) return barLine
def main(): app = QtWidgets.QApplication(sys.argv) viewer = quarter.QuarterWidget() # build a scene (sphere, cube) plane = coin.SbPlane(coin.SbVec3f(0, 0, 1), coin.SbVec3f(0, 0, 0)) root = coin.SoSeparator() myCallback = coin.SoCallback() cap = CapPlane(plane, root) myCallback.setCallback(myCallbackRoutine, cap) root += myCallback, coin.SoSphere() viewer.setSceneGraph(root) viewer.setBackgroundColor(coin.SbColor(.5, .5, .5)) viewer.setWindowTitle("GL stencil buffer") viewer.show() sys.exit(app.exec_())
def main(): app = QtWidgets.QApplication(sys.argv) root = coin.SoSeparator() mat = coin.SoMaterial() mat.diffuseColor.setValue(coin.SbColor(0.8, 1, 0.8)) mat.specularColor.setValue(coin.SbColor(1, 1, 1)) mat.shininess.setValue(1.0) mat.transparency.setValue(0.9) root.addChild(mat) root.addChild(coin.SoSphere()) root.addChild(coin.SoCube()) viewer = quarter.QuarterWidget() viewer.setSceneGraph(root) viewer.setWindowTitle("minimal") viewer.show() sys.exit(app.exec_())
def main(): app = QApplication(sys.argv) root = coin.SoSeparator() vert = coin.SoVertexShader() vert.sourceProgram = "vertex.glsl" frag = coin.SoFragmentShader() frag.sourceProgram = "frag.glsl" shaders = [vert,frag] pro = coin.SoShaderProgram() pro.shaderObject.setValues(0,len(shaders),shaders) mat = coin.SoMaterial() mat.diffuseColor.setValue(coin.SbColor(0.8, 0.8, 0.8)) mat.specularColor.setValue(coin.SbColor(1, 1, 1)) mat.shininess.setValue(1.0) mat.transparency.setValue(0.5) sphere = coin.SoSphere() sphere.radius = 1.2 root.addChild(pro) root.addChild(sphere) root.addChild(mat) root.addChild(coin.SoCube()) viewer = quarter.QuarterWidget() viewer.setSceneGraph(root) viewer.setWindowTitle("minimal") viewer.show() sys.exit(app.exec_())
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()
def createGeometry(self): sphere = coin.SoSphere() sphere.radius.setValue(50.0) return sphere
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()
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
def navi(): '''navigator startup''' mw = QtGui.QApplication #widget.setCursor(QtCore.Qt.SizeAllCursor) #cursor ausblenden #mw.setOverrideCursor(QtCore.Qt.BlankCursor) # FreeCADGui.activateWorkbench("NoneWorkbench") mw.setOverrideCursor(QtCore.Qt.PointingHandCursor) ef = EventFilter() ef.laenge = 0.0 ef.breite = 0.0 ef.campos = FreeCAD.Vector(0, 0, 20000) # ef.output.hide() ef.mouseMode = False ef.firstCall = True ef.mode = "turn" ef.navi = myNavigatorWidget(ef) ef.speed = 100 ef.direction = 0.5 * math.pi ef.roll = 0 #-------------- # get a jpg filename fn = os.path.dirname(__file__) + "/../pics/winter.jpg" sg = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph() trans = coin.SoTranslation() trans.translation.setValue([0, 0, 0]) myCustomNode = coin.SoSeparator() cub = coin.SoSphere() cub.radius.setValue(10000000) i = coin.SoRotationXYZ() i.angle.setValue(1.5708) i.axis.setValue(0) myCustomNode.addChild(i) s = coin.SoRotationXYZ() s.angle.setValue(math.pi) s.axis.setValue(1) myCustomNode.addChild(s) #myCustomNode.addChild(trans) myCustomNode.addChild(cub) sg.addChild(myCustomNode) tex = coin.SoTexture2() tex.filename = fn myCustomNode.insertChild(tex, 0) #--------------- ef.background = myCustomNode ef.tex = tex FreeCAD.eventfilter = ef mw.installEventFilter(ef) FreeCAD.eventfilter.on_key_press = on_keypress2 FreeCAD.eventfilter.on_move = on_move3 FreeCAD.eventfilter.on_clicks = on_clicks3 FreeCAD.eventfilter.on_windowslist = on_windowslist2 on_keypress2(FreeCAD.eventfilter, 'O') view = FreeCADGui.activeDocument().activeView() FreeCADGui.ActiveDocument.ActiveView.setAnimationEnabled(False) mgr = view.getViewer().getSoRenderManager() mgr.setAutoClipping(0) FreeCAD.ActiveDocument.recompute() FreeCADGui.updateGui() return ef
def navi(): '''navigator startup''' mw = QtGui.QApplication #widget.setCursor(QtCore.Qt.SizeAllCursor) #cursor ausblenden #mw.setOverrideCursor(QtCore.Qt.BlankCursor) # FreeCADGui.activateWorkbench("NoneWorkbench") mw.setOverrideCursor(QtCore.Qt.PointingHandCursor) ef = EventFilter() ef.laenge = 0.0 ef.breite = 0.0 ef.campos = FreeCAD.Vector(0, 0, 20000) # ef.output.hide() ef.mouseMode = False ef.firstCall = True ef.mode = "turn" ef.navi = myNavigatorWidget(ef) ef.speed = 100 ef.direction = 0.5 * math.pi ef.roll = 0 #-------------- # get a jpg filename # jpgfilename = QtGui.QFileDialog.getOpenFileName(QtGui.qApp.activeWindow(),'Open image file','*.jpg') fn = '/home/microelly2/FCB/b175_camera_controller/winter.jpg' fn = os.path.dirname(__file__) + "/../pics/winter.jpg" sg = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph() col = coin.SoBaseColor() #col.rgb=(1,0,0) trans = coin.SoTranslation() trans.translation.setValue([0, 0, 0]) myCustomNode = coin.SoSeparator() #myCustomNode.addChild(col) if 0 or False: cub = coin.SoCylinder() cub.radius.setValue(3000) cub.height.setValue(4000) cub.parts.set("SIDES") s = coin.SoRotationXYZ() s.angle.setValue(1.5708) s.axis.setValue(0) myCustomNode.addChild(s) s = coin.SoRotationXYZ() s.angle.setValue(math.pi) s.axis.setValue(1) myCustomNode.addChild(s) else: cub = coin.SoSphere() cub.radius.setValue(10000000) s = coin.SoRotationXYZ() s.angle.setValue(1.5708) s.axis.setValue(0) myCustomNode.addChild(s) s = coin.SoRotationXYZ() s.angle.setValue(math.pi) s.axis.setValue(1) myCustomNode.addChild(s) if False: l = coin.SoDirectionalLight() l.direction.setValue(coin.SbVec3f(0, 1, 0)) l.color.setValue(coin.SbColor(0, 0, 1)) myCustomNode.addChild(l) l = coin.SoDirectionalLight() l.direction.setValue(coin.SbVec3f(0, -1, 0)) l.color.setValue(coin.SbColor(0, 1, 1)) myCustomNode.addChild(l) l = coin.SoDirectionalLight() l.direction.setValue(coin.SbVec3f(0, 0, 1)) l.color.setValue(coin.SbColor(1, 0, 0)) myCustomNode.addChild(l) l = coin.SoDirectionalLight() l.direction.setValue(coin.SbVec3f(0, 0, -1)) l.color.setValue(coin.SbColor(0.6, 0.6, 1)) myCustomNode.addChild(l) l = coin.SoSpotLight() l.direction.setValue(coin.SbVec3f(1, 0, 1)) l.color.setValue(coin.SbColor(0, 1, 0)) l.location.setValue(coin.SbVec3f(0, 0, 0)) # l.cutOffAngle.setValue(0.01) # l.dropOffRate.setValue(1) myCustomNode.addChild(l) #myCustomNode.addChild(trans) myCustomNode.addChild(cub) sg.addChild(myCustomNode) tex = coin.SoTexture2() tex.filename = fn myCustomNode.insertChild(tex, 0) #--------------- ef.background = myCustomNode ef.tex = tex FreeCAD.eventfilter = ef mw.installEventFilter(ef) FreeCAD.eventfilter.on_key_press = on_keypress2 FreeCAD.eventfilter.on_move = on_move3 FreeCAD.eventfilter.on_clicks = on_clicks3 FreeCAD.eventfilter.on_windowslist = on_windowslist2 on_keypress2(FreeCAD.eventfilter, 'O') view = FreeCADGui.activeDocument().activeView() FreeCADGui.ActiveDocument.ActiveView.setAnimationEnabled(False) mgr = view.getViewer().getSoRenderManager() mgr.setAutoClipping(0) FreeCAD.ActiveDocument.recompute() FreeCADGui.updateGui() return ef