def makeLabels(self): """ Method which makes Coin3D labels to be displayed in the FreeCAD View. Frame labels for axes X, Y and Z are made. The labels have the same color as the axes. Returns: A SoSwitch with colored text label to be shown in the FreeCAD View. """ label_strings = ["X", "Y", "Z"] colors = [0xFF0000FF, 0x00FF00FF, 0x0000FFFF] self.label_texts = [] self.label_translations = [] # frame translation self.label_translations.append(coin.SoTranslation()) # axis translation self.label_translations.append(coin.SoTranslation()) self.labels = [] for i in range(3): label_group = coin.SoSeparator() label_group.addChild(self.label_translations[0]) frame_axis_color = coin.SoPackedColor() frame_axis_color.orderedRGBA.setValue(colors[i]) label_group.addChild(frame_axis_color) self.label_texts.append(coin.SoText2()) self.label_texts[i].string.setValues( 0, 3, ["", label_strings[i], ""]) self.label_texts[i].justification.setValue( self.label_texts[i].CENTER) self.label_texts[i].spacing.setValue(0.45) label_group.addChild(self.label_texts[i]) self.labels.append(coin.SoSwitch()) self.labels[i].addChild(label_group) return self.labels
def makeLabels(self): label_strings = ["X", "Y", "Z"] colors = [0xFF0000FF, 0x00FF00FF, 0x0000FFFF] self.label_texts = [] self.label_translations = [] # frame translation self.label_translations.append(coin.SoTranslation()) # axis translation self.label_translations.append(coin.SoTranslation()) self.labels = [] for i in range(3): label_group = coin.SoSeparator() label_group.addChild(self.label_translations[0]) frame_axis_color = coin.SoPackedColor() frame_axis_color.orderedRGBA.setValue(colors[i]) label_group.addChild(frame_axis_color) self.label_texts.append(coin.SoText2()) self.label_texts[i].string.setValues(0, 3, ["", label_strings[i], ""]) self.label_texts[i].justification.setValue( self.label_texts[i].CENTER) self.label_texts[i].spacing.setValue(0.45) label_group.addChild(self.label_texts[i]) self.labels.append(coin.SoSwitch()) self.labels[i].addChild(label_group) return self.labels
def __createTexts(self): font = coin.SoFont() font.name.setValue('Times-Roman') font.size.setValue(9) scaleLen = self.__AxisWidth / self.__scalesNum4XAxis # add x scales flag = False if self.__xMax - self.__xMin > 10: flag = True nums = self.__AxisWidth / scaleLen for i in range(nums): g = coin.SoSeparator() # translation t = coin.SoTranslation() t.translation.setValue(i * scaleLen, -scaleLen * (i % 3 + 1), 0) g.addChild(t) # color g.addChild(__baseColor__) #font g.addChild(font) # text text = coin.SoText3() if flag: text.string = '%d' % int( (self.__xMax - self.__xMin) * i / nums) else: text.string = '%.4lf' % ( (self.__xMax - self.__xMin) * i / nums) text.justification = coin.SoText3.RIGHT g.addChild(text) self.__rootTexts.addChild(g) # add y scales nums = self.__AxisHeight / scaleLen for i in range(nums): g = coin.SoSeparator() # translation t = coin.SoTranslation() t.translation.setValue(-scaleLen, i * scaleLen, 0) g.addChild(t) # color g.addChild(__baseColor__) #font g.addChild(font) # text text = coin.SoText3() text.string = '%.4lf' % (self.__yMin + (self.__yMax - self.__yMin) * i / nums) text.justification = coin.SoText3.RIGHT g.addChild(text) self.__rootTexts.addChild(g)
def __init__(self, view, coneHeight=5): self.view = view self.tsze = coneHeight self.cam = coin.SoOrthographicCamera() self.cam.aspectRatio = 1 self.cam.viewportMapping = coin.SoCamera.LEAVE_ALONE self.pos = coin.SoTranslation() self.mat = coin.SoMaterial() self.mat.diffuseColor = coin.SbColor(0.9, 0.0, 0.9) self.mat.transparency = 0 self.fnt = coin.SoFont() self.txt = coin.SoText2() self.txt.string = 'setValues' self.txt.justification = coin.SoText2.LEFT self.sep = coin.SoSeparator() self.sep.addChild(self.cam) self.sep.addChild(self.pos) self.sep.addChild(self.mat) self.sep.addChild(self.fnt) self.sep.addChild(self.txt) self.tTrf = coin.SoTransform() self.tTrf.translation.setValue((0, -self.tsze / 2, 0)) self.tTrf.center.setValue((0, self.tsze / 2, 0)) self.tTrf.rotation.setValue(coin.SbVec3f((1, 0, 0)), -math.pi / 2) self.tPos = coin.SoTranslation() self.tMat = coin.SoMaterial() self.tMat.diffuseColor = coin.SbColor(0.4, 0.4, 0.4) self.tMat.transparency = 0.8 self.tool = coin.SoCone() self.tool.height.setValue(self.tsze) self.tool.bottomRadius.setValue(self.tsze / 4) self.tSep = coin.SoSeparator() self.tSep.addChild(self.tPos) self.tSep.addChild(self.tTrf) self.tSep.addChild(self.tMat) self.tSep.addChild(self.tool) self.viewer = self.view.getViewer() self.render = self.viewer.getSoRenderManager() self.sup = None self.updatePreferences() self.setPosition(0, 0, 0, 0, 0, 0, False, False)
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 __createGraphTitle(self): font = coin.SoFont() font.name.setValue('Times-Roman') font.size.setValue(16) g = coin.SoSeparator() # translation t = coin.SoTranslation() t.translation.setValue(self.__AxisWidth / 2, self.__AxisHeight * 1.1, 0) g.addChild(t) # color g.addChild(__baseColor__) #font g.addChild(font) # text text = coin.SoText3() text.string = self.__graphTitle text.justification = coin.SoText3.CENTER g.addChild(text) self.__root.addChild(g)
def __createHintTextsAndColors(self): rootHint = coin.SoSeparator() # hint lines colorLines = coin.SoSeparator() rootHint.addChild(colorLines) mat = coin.SoMaterial() mat.diffuseColor.setValues(0, len(self.__hintColors), self.__hintColors) colorLines.addChild(mat) bind = coin.SoMaterialBinding() bind.value = coin.SoMaterialBinding.PER_PART colorLines.addChild(bind) lineCoords = coin.SoCoordinate3() colorLines.addChild(lineCoords) lineset = coin.SoLineSet() colorLines.addChild(lineset) space = self.__AxisHeight / self.__scalesNum4XAxis startX = self.__AxisWidth * 1.05 pts = [] for i, s in enumerate(self.__hintTexts): pts.append((startX, self.__AxisHeight - i * space, 0)) pts.append((startX + space, self.__AxisHeight - i * space, 0)) lineCoords.point.setValues(0, len(pts), pts) nums = [2] * (len(pts) / 2) lineset.numVertices.setValues(0, len(nums), nums) # add texts font = coin.SoFont() font.name.setValue('Times-Roman') font.size.setValue(9) scaleLen = self.__AxisHeight / self.__scalesNum4XAxis for i in range(len(self.__hintColors)): g = coin.SoSeparator() # translation t = coin.SoTranslation() t.translation.setValue(startX + space * 2, self.__AxisHeight - i * space, 0) g.addChild(t) # color col = coin.SoBaseColor() col.rgb.setValue(self.__hintColors[i][:3]) g.addChild(col) #font g.addChild(font) # text text = coin.SoText3() text.string = self.__hintTexts[i] text.justification = coin.SoText3.LEFT g.addChild(text) rootHint.addChild(g) self.__root.addChild(rootHint)
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 __init__(self, points, sh=None): super(MarkerOnEdge, self).__init__(points, True) self._shape = None self._sublink = None self._tangent = None self._text_type = 0 self._text_translate = coin.SoTranslation() self._text_font = coin.SoFont() self._text_font.name = "Arial:Bold" self._text_font.size = 13.0 self._text = coin.SoText2() self._text_switch = coin.SoSwitch() self._text_switch.whichChild = coin.SO_SWITCH_ALL self._text_switch.addChild(self._text_translate) self._text_switch.addChild(self._text_font) self._text_switch.addChild(self._text) #self.on_drag_start.append(self.add_text) #self.on_drag_release.append(self.remove_text) self.on_drag.append(self.update_text) self.update_text() self.addChild(self._text_switch) if isinstance(sh, Part.Shape): self.snap_shape = sh elif isinstance(sh, (tuple, list)): self.sublink = sh
def __init__(self, points, dynamic=False, arrow_size=0.04, length=2): super(Arrow, self).__init__(points, dynamic) self.arrow_sep = coin.SoSeparator() self.arrow_rot = coin.SoRotation() self.arrow_scale = coin.SoScale() self.arrow_translate = coin.SoTranslation() self.arrow_scale.scaleFactor.setValue(arrow_size, arrow_size, arrow_size) self.cone = coin.SoCone() arrow_length = coin.SoScale() arrow_length.scaleFactor = (1, length, 1) arrow_origin = coin.SoTranslation() arrow_origin.translation = (0, -1, 0) self.arrow_sep += [self.arrow_translate, self.arrow_rot, self.arrow_scale] self.arrow_sep += [arrow_length, arrow_origin, self.cone] self += [self.arrow_sep] self.set_arrow_direction()
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, sim): self.sim = sim # Scene axis label length = 1 self.r = coin.SoSeparator() st = coin.SoDrawStyle() st.lineWidth = 3 self.r.addChild(st) data = {'x': (1, 0, 0), 'y': (0, 1, 0), 'z': (0, 0, 1)} #text_ref = coin.SoText2() #self.r.addChild(text_ref) #text_ref.string = 'Tracer rendering' for k in data: vx, vy, vz = data[k] vec = (length * vx, length * vy, length * vz) s1 = coin.SoSeparator() la = coin.SoLabel() la.label = k s1.addChild(la) tr1 = coin.SoTranslation() tr1.translation = vec s1.addChild(tr1) self.r.addChild(s1) s2 = coin.SoSeparator() tr2 = coin.SoTransform() tr2.translation.setValue(data[k]) s2.addChild(tr2) matxt = coin.SoMaterial() matxt.diffuseColor = data[k] s2.addChild(matxt) txaxis = coin.SoText2() txaxis.string = k s2.addChild(txaxis) self.r.addChild(s2) ma = coin.SoMaterial() ma.diffuseColor = data[k] self.r.addChild(ma) co = coin.SoCoordinate3() co.point.setValues(0, 2, [(0, 0, 0), vec]) self.r.addChild(co) ls = coin.SoLineSet() ls.numVertices.setValues(0, 1, [2]) self.r.addChild(ls)
def _update_grid(self, grid_x, grid_y, drag_release=False): self.grid.removeAllChildren() x_points_lower = [[x, grid_y[0], -0.001] for x in grid_x] x_points_upper = [[x, grid_y[-1], -0.001] for x in grid_x] y_points_lower = [[grid_x[0], y, -0.001] for y in grid_y] y_points_upper = [[grid_x[-1], y, -0.001] for y in grid_y] for l in zip(x_points_lower, x_points_upper): self.grid += [pp.Line(l, color='grey').object] for l in zip(y_points_lower, y_points_upper): self.grid += [pp.Line(l, color='grey').object] for l in y_points_upper: color = coin.SoMaterial() color.diffuseColor = [0, 0, 0] textsep = coin.SoSeparator() text = coin.SoText2() trans = coin.SoTranslation() trans.translation = l text.string = self.text_repr(l[1] * self.value_scale) textsep += [color, trans, text] self.grid += [textsep] interpolation = self.spline.interpolation(50) if drag_release: for i in self.back: color = coin.SoMaterial() color.diffuseColor = [0, 0, 0] textsep = coin.SoSeparator() scale = coin.SoScale() text = coin.SoAsciiText() trans = coin.SoTranslation() rot = coin.SoRotationXYZ() rot.axis = coin.SoRotationXYZ.Z rot.angle.setValue(np.pi / 2) scale.scaleFactor = (self.text_scale, self.text_scale, self.text_scale) trans.translation = (i[0], i[1], 0.001) text.string = self.text_repr( interpolation(i[0]) * self.value_scale * self.scale[1]) textsep += [color, trans, scale, rot, text] self.grid += [textsep]
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, parent, dynamic=False): super(CustomText, self).__init__(parent.points, dynamic) #self._text_offset = FreeCAD.Vector(0,0,0) self._text_translate = coin.SoTranslation() self._text_font = coin.SoFont() self._text_font.name = "Arial:Bold" self._text_font.size = 13.0 self._text = coin.SoText2() self._text_switch = coin.SoSwitch() self._text_switch.addChild(self._text_translate) self._text_switch.addChild(self._text_font) self._text_switch.addChild(self._text) self.addChild(self._text_switch) self.parent = parent self.parent.on_drag.append(self.translate) self.translate()
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 Activated(self): self.states = [ 'selecting_face', 'choosing_drafting_tools', 'drawing', 'extruding', 'finalizing' ] self.state = self.states[0] # Coin Separator for text helping user during the command textSep = coin.SoSeparator() cam = coin.SoOrthographicCamera() cam.aspectRatio = 1 cam.viewportMapping = coin.SoCamera.LEAVE_ALONE trans = coin.SoTranslation() trans.translation = (-0.98, 0.85, 0) myFont = coin.SoFont() myFont.name = "Arial" size = 50 myFont.size.setValue(size) self.SoText2 = coin.SoText2() self.SoText2.string.setValues( 0, 2, ["Sélectionner une face d'un composant", ""]) color = coin.SoBaseColor() color.rgb = (0, 0, 0) textSep.addChild(cam) textSep.addChild(trans) textSep.addChild(color) textSep.addChild(myFont) textSep.addChild(self.SoText2) activeDoc = Gui.ActiveDocument view = activeDoc.ActiveView self.sg = view.getSceneGraph() viewer = view.getViewer() self.render = viewer.getSoRenderManager() self.sup = self.render.addSuperimposition(textSep) self.sg.touch() # Timer to check what the user is doing self.machining_timer = QtCore.QTimer() self.machining_timer.setInterval(200) self.machining_timer.timeout.connect(self.check) self.start()
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 __init__(self, view, coneHeight): self.view = view self.tsze = coneHeight self.trf = coin.SoTransform() self.pos = coin.SoTranslation() self.mat = coin.SoMaterial() self.mat.diffuseColor = coin.SbColor(0.4, 0.4, 0.4) self.mat.transparency = 0.8 self.sep = coin.SoSeparator() self.sep.addChild(self.pos) self.sep.addChild(self.trf) self.sep.addChild(self.mat) self.tool = None self.setToolShape(None)
def get_scene_graph_transform(self): """ Create the Coin3D transform to translate and rotate this frame, in accordance with the self._rot and self._loc matrices held in this class. """ n = coin.SoSeparator() if N.any(self._loc != N.array((0, 0, 0))): tr = coin.SoTranslation() x, y, z = self._loc tr.translation = coin.SbVec3f((x, y, z)) #print "tr.translation = ",tr.translation.getValue().getValue() n.addChild(tr) if not N.all(N.equal(self._rot, N.eye(3))): m = self._rot # http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm tr = m[0, 0] + m[1, 1] + m[2, 2] if tr > 0: S = N.sqrt(tr + 1.0) * 2 qw = 0.25 * S qx = (m[2, 1] - m[1, 2]) / S qy = (m[0, 2] - m[2, 0]) / S qz = (m[1, 0] - m[0, 1]) / S elif m[0, 0] > m[1, 1] and m[0, 0] > m[2, 2]: S = N.sqrt(1.0 + m[0, 0] - m[1, 1] - m[2, 2]) * 2 qw = (m[2, 1] - m[1, 2]) / S qx = 0.25 * S qy = (m[0, 1] + m[1, 0]) / S qz = (m[0, 2] + m[2, 0]) / S elif m[1, 1] > m[2, 2]: S = N.sqrt(1.0 + m[1, 1] - m[0, 0] - m[2, 2]) * 2 qw = (m[0, 2] - m[2, 0]) / S qx = (m[0, 1] + m[1, 0]) / S qy = 0.25 * S qz = (m[1, 2] + m[2, 1]) / S else: S = N.sqrt(1.0 + m[2, 2] - m[0, 0] - m[1, 1]) * 2 qw = (m[1, 0] - m[0, 1]) / S qx = (m[0, 2] + m[2, 0]) / S qy = (m[1, 2] + m[2, 1]) / S qz = 0.25 * S ro = coin.SoRotation() ro.rotation = (qx, qy, qz, qw) n.addChild(ro) return n
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
def createABar(self, _vector, _color, _length, _rotation): color = coin.SoBaseColor() transform = coin.SoTransform() tempR = coin.SbVec3f() tempR.setValue(_rotation[0], _rotation[1], _rotation[2]) transform.rotation.setValue(tempR, math.radians(_rotation[3])) color.rgb = _color cylinder = coin.SoCylinder() cylinder.height = _length cylinder.radius = self.barRadius transBar = coin.SoTranslation() transBar.translation.setValue(_vector) barLine = coin.SoSeparator() barLine.addChild(color) barLine.addChild(transBar) barLine.addChild(transform) barLine.addChild(cylinder) return barLine
def __init__(self, points, sh=None): super(MarkerOnShape, self).__init__(points, True) self._shape = None self._sublink = None self._tangent = None self._text_translate = coin.SoTranslation() self._text = coin.SoText2() self._text_switch = coin.SoSwitch() self._text_switch.addChild(self._text_translate) self._text_switch.addChild(self._text) self.on_drag_start.append(self.add_text) self.on_drag_release.append(self.remove_text) self.addChild(self._text_switch) if isinstance(sh, Part.Shape): self.snap_shape = sh elif isinstance(sh, (tuple, list)): self.sublink = sh
def attach(self, obj): "'''Setup the scene sub-graph of the view provider, this method is mandatory'''" self.wireframe = coin.SoGroup() self.scale = coin.SoScale() # self.color = coin.SoBaseColor() self.trans = coin.SoTranslation() self.data = coin.SoCube() # Switch Z to proper default value self.trans.translation.setValue([0, 0, 100]) self.wireframe.addChild(self.trans) style = coin.SoDrawStyle() style.style = coin.SoDrawStyle.LINES self.wireframe.addChild(style) self.wireframe.addChild(self.scale) # self.wireframe.addChild(self.color) self.wireframe.addChild(self.data) obj.addDisplayMode(self.wireframe, "Wireframe")
def onChanged(self, vobj, prop): ''' Update Object visuals when a view property changed. ''' labels = vobj.getPropertyByName("Labels") self.point_labels.removeAllChildren() if labels: if prop == "Labels" or prop == "Name" or prop == "NortingEasting"\ or prop == "Elevation" or prop == "Description": origin = geo_origin.get(vobj.Object.Points[0]) show_name = vobj.getPropertyByName("Name") show_ne = vobj.getPropertyByName("NortingEasting") show_z = vobj.getPropertyByName("Elevation") show_des = vobj.getPropertyByName("Description") for vector in vobj.Object.Points: font = coin.SoFont() font.size = 1000 point_label = coin.SoSeparator() location = coin.SoTranslation() text = coin.SoAsciiText() index = vobj.Object.Points.index(vector) labels =[] if show_name: labels.append(vobj.Object.PointNames[index]) if show_ne: labels.extend([str(round(vector.x/1000, 3)), str(round(vector.y/1000,3))]) if show_z: labels.append(str(round(vector.z/1000,3))) if show_des and vobj.Object.Descriptions: labels.append(vobj.Object.Descriptions[index]) location.translation = vector.sub(FreeCAD.Vector(origin.Origin.x, origin.Origin.y, 0)) text.string.setValues(labels) point_label.addChild(font) point_label.addChild(location) point_label.addChild(text) self.point_labels.addChild(point_label) if prop == "PointSize": size = vobj.getPropertyByName("PointSize") self.point_style.pointSize = size if prop == "PointColor": color = vobj.getPropertyByName("PointColor") self.color_mat.diffuseColor = (color[0],color[1],color[2])
def Activated(self, index=0): if index == 1: debug("GeomInfo activated") self.stack = [] # install the function in resident mode FreeCADGui.Selection.addObserver(self) self.active = True self.textSep = coin.SoSeparator() self.cam = coin.SoOrthographicCamera() self.cam.aspectRatio = 1 self.cam.viewportMapping = coin.SoCamera.LEAVE_ALONE self.trans = coin.SoTranslation() self.trans.translation = (-0.98, 0.90, 0) self.myFont = coin.SoFont() self.myFont.name = "FreeMono,FreeSans,sans" size = FreeCAD.ParamGet( "User parameter:BaseApp/Preferences/Mod/Curves").GetInt( 'GeomInfoFontSize', 14) print(size) self.myFont.size.setValue(size) self.SoText2 = coin.SoText2() self.SoText2.string = "" # "Nothing Selected\r2nd line" self.color = coin.SoBaseColor() self.color.rgb = (0, 0, 0) self.textSep.addChild(self.cam) self.textSep.addChild(self.trans) self.textSep.addChild(self.color) self.textSep.addChild(self.myFont) self.textSep.addChild(self.SoText2) self.addHUD() self.Active = True self.viz = False self.getTopo() elif (index == 0) and self.Active: debug("GeomInfo off") self.removeHUD() self.Active = False FreeCADGui.Selection.removeObserver(self)
def draw_snap(self, sel, sensor): """Method that draw the current snap point""" if self.snap_point != sel: if self.snap_point is not None: self.root.removeChild(self.SnapNode) self.snap_point = sel if sel is not None: col = coin.SoBaseColor() col.rgb = (0, 1, 0) trans = coin.SoTranslation() trans.translation.setValue(sel) snap = coin.SoMarkerSet() # this is the marker symbol snap.markerIndex = FreeCADGui.getMarkerIndex("", 9) # cub = coin.SoSphere() self.SnapNode = coin.SoSeparator() self.SnapNode.addChild(col) self.SnapNode.addChild(trans) self.SnapNode.addChild(snap) self.root.addChild(self.SnapNode)
def __init__(self): super(textArea, self).__init__() self.trans = coin.SoTranslation() self.trans.translation = (-0.98,0.95,0) self.font = coin.SoFont() self.font.name = "osiFont,FreeSans,sans" self.font.size.setValue(16.0) self.str = coin.SoText2() self.str.string = "" self.color = coin.SoBaseColor() self.color.rgb = (0,0,0) self.addChild(self.trans) self.addChild(self.color) self.addChild(self.font) self.addChild(self.str)
def attach(self, obj): self.shaded = coin.SoGroup() self.wireframe = coin.SoGroup() self.color = coin.SoBaseColor() self.trans = coin.SoTranslation() self.box = coin.SoCube() self.shaded.addChild(self.color) self.shaded.addChild(self.trans) self.shaded.addChild(self.box) obj.addDisplayMode(self.shaded, "Shaded") style = coin.SoDrawStyle() style.style = coin.SoDrawStyle.LINES self.wireframe.addChild(style) self.wireframe.addChild(self.color) self.wireframe.addChild(self.trans) self.wireframe.addChild(self.box) obj.addDisplayMode(self.wireframe, "Wireframe") self.onChanged(obj, "Color") return