def __init__(self, x=0, y=0, z=0): super(ControlPoint, self).__init__() self.marker = coin.SoMarkerSet() self.mat = coin.SoMaterial() self.coordinate = coin.SoCoordinate3() self.setup_coin(x, y, z) self.fix = False
def get_drag_selection(self): """ Return a SoGroup() object of trackers to be transformed by draf """ #coordinates, markers, lines, draw-styles, transforms, etc. to be #rendered in a single SoGroup() _result = coin.SoGroup() _result.setName('PI_TRACKER') _c = [list(_v.get()) for _v in self.gui_action['selected'].values()] _count = len(_c) _coord = coin.SoCoordinate3() _coord.point.setValues(0, _count, _c) _result.addChild(_coord) _result.addChild(coin.SoMarkerSet()) if _count > 1: _line = coin.SoLineSet() _line.numVertices.setValue(_count) _result.addChild(_line) return _result
def build_selected_group(self): """ Build the SoGroup node which provides transformation for the SoMarkerSet and SoLineSet that represents the selected geometry """ _selected = self.trackers['selected'] if not _selected: return #create coordinate node from list of selected node coordinates _coord = coin.SoCoordinate3() _count = len(_selected) _coord.point.setValues(0, _count, [list(_v.get()) for _v in _selected]) #create marker / line geometry _marker = coin.SoMarkerSet() _line = coin.SoLineSet() _line.numVertices.setValue(_count) #build node and add children _group = self.nodes['selected'] _group.addChild(self.nodes['transform']) _group.addChild(_coord) _group.addChild(_marker) _group.addChild(_line)
def __init__(self, spGrp): CoinTemplate.__init__(self, spGrp) self.__markers = coin.SoMarkerSet() spGrp.addChild(self.__markers) self.__markers.startIndex = 0 self.__markers.numPoints = 1 self.__markers.markerIndex = coin.SoMarkerSet.CIRCLE_LINE_9_9
def __init__(self,sel,dotted=False,scolor=None,swidth=None): self.trans = coin.SoTransform() self.trans.translation.setValue([0,0,0]) self.children = [self.trans] rootsep = coin.SoSeparator() if not isinstance(sel,list): sel = [sel] for obj in sel: import Part if not isinstance(obj, Part.Vertex): rootsep.addChild(self.getNode(obj)) else: self.coords = coin.SoCoordinate3() self.coords.point.setValue((obj.X,obj.Y,obj.Z)) color = coin.SoBaseColor() color.rgb = FreeCADGui.draftToolBar.getDefaultColor("snap") self.marker = coin.SoMarkerSet() # this is the marker symbol self.marker.markerIndex = FreeCADGui.getMarkerIndex("quad", 9) node = coin.SoAnnotation() selnode = coin.SoSeparator() selnode.addChild(self.coords) selnode.addChild(color) selnode.addChild(self.marker) node.addChild(selnode) rootsep.addChild(node) self.children.append(rootsep) Tracker.__init__(self,dotted,scolor,swidth,children=self.children,name="ghostTracker")
def __init__(self,pos=Vector(0,0,0),name=None,idx=0,objcol=None,\ marker=FreeCADGui.getMarkerIndex("quad", 9),inactive=False): color = coin.SoBaseColor() if objcol: color.rgb = objcol[:3] else: color.rgb = FreeCADGui.draftToolBar.getDefaultColor("snap") self.marker = coin.SoMarkerSet() # this is the marker symbol self.marker.markerIndex = marker self.coords = coin.SoCoordinate3() # this is the coordinate self.coords.point.setValue((pos.x,pos.y,pos.z)) if inactive: selnode = coin.SoSeparator() else: selnode = coin.SoType.fromName("SoFCSelection").createInstance() if name: selnode.documentName.setValue(FreeCAD.ActiveDocument.Name) selnode.objectName.setValue(name) selnode.subElementName.setValue("EditNode"+str(idx)) node = coin.SoAnnotation() selnode.addChild(self.coords) selnode.addChild(color) selnode.addChild(self.marker) node.addChild(selnode) ontop = not inactive Tracker.__init__(self,children=[node],ontop=ontop,name="editTracker") self.on()
def create_rollover(self, names): """ Create the rollover node tracker """ group = coin.SoGroup() for style in [self.STYLE.ROLL_INNER, self.STYLE.ROLL_OUTER]: marker = coin.SoMarkerSet() marker.markerIndex = \ Gui.getMarkerIndex(style['shape'], style['size']) nam = names[:] nam[2] += '.' + style['id'] child = BaseTracker(nam, [self.coord, marker], style['select']) child.color.rgb = style['color'] group.addChild(child.node) self.groups['rollover'].append(child) return group
def __init__(self, names, point, nodes=None): """ Constructor """ self.type = 'NODE' if not nodes: nodes = [] elif not isinstance(nodes, list): nodes = [nodes] self.is_end_node = False self.point = tuple(point) self.ui_message = {} #build node structure for the node tracker self.coord = coin.SoCoordinate3() self.marker = coin.SoMarkerSet() self.drag_point = self.point super().__init__(names=names, children=[self.coord, self.marker] + nodes) self.update()
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 __init__(self): self.node = coin.SoSeparator() self.coordinate = coin.SoCoordinate3() self.crosshair_coord = coin.SoCoordinate3() self.transform = coin.SoTransform() _selection_node = \ coin.SoType.fromName("SoFCSelection").createInstance() _selection_node.documentName.setValue('Document') _selection_node.objectName.setValue('Test Tracker') _selection_node.subElementName.setValue('NODE-0') self.node.addChild(_selection_node) self.node.addChild(self.transform) self.node.addChild(self.coordinate) self.node.addChild(coin.SoMarkerSet()) self.coordinate.point.setValue((0.0, 0.0, 0.0)) self.view = Gui.ActiveDocument.ActiveView self.view.addEventCallback('SoLocation2Event', self.mouse_event) _fn = lambda _x: self.view.getSceneGraph().insertChild(_x, 0) self.crosshair = self.create_crosshair() todo.delay(_fn, self.node) todo.delay(_fn, self.crosshair)
def __init__(self, points, dynamic=False): super(Marker, self).__init__(dynamic) self.marker = coin.SoMarkerSet() self.marker.markerIndex = coin.SoMarkerSet.CIRCLE_FILLED_7_7 if depth(points) != 2: raise AttributeError("depth of list should be 2") self.points = points self.addChild(self.marker)
def __init__(self, points=None, color='black'): super(Marker, self).__init__() self.marker = coin.SoMarkerSet() self.marker.markerIndex = coin.SoMarkerSet.CIRCLE_FILLED_9_9 self.data = coin.SoCoordinate3() self.color = coin.SoMaterial() self.color.diffuseColor = COLORS[color] self.update(points or []) self += [self.color, self.data, self.marker]
def __init__(self): color = coin.SoBaseColor() color.rgb = FreeCADGui.DDADockWidget.getDefaultColor("snap") self.marker = coin.SoMarkerSet() # this is the marker symbol self.marker.markerIndex = coin.SoMarkerSet.CIRCLE_FILLED_9_9 self.coords = coin.SoCoordinate3() # this is the coordinate self.coords.point.setValue((0, 0, 0)) node = coin.SoAnnotation() node.addChild(self.coords) node.addChild(color) node.addChild(self.marker) Tracker.__init__(self, children=[node])
def attach(self, vobj): from pivy import coin sep = coin.SoSeparator() self.coords = coin.SoCoordinate3() sep.addChild(self.coords) self.coords.point.deleteValues(0) symbol = coin.SoMarkerSet() symbol.markerIndex = coin.SoMarkerSet.CIRCLE_FILLED_5_5 sep.addChild(symbol) rn = vobj.RootNode rn.addChild(sep) ArchComponent.ViewProviderComponent.attach(self,vobj)
def __init__(self): color = coin.SoBaseColor() color.rgb = FreeCADGui.draftToolBar.getDefaultColor("snap") self.marker = coin.SoMarkerSet() # this is the marker symbol self.marker.markerIndex = FreeCADGui.getMarkerIndex("", 9) self.coords = coin.SoCoordinate3() # this is the coordinate self.coords.point.setValue((0,0,0)) node = coin.SoAnnotation() node.addChild(self.coords) node.addChild(color) node.addChild(self.marker) Tracker.__init__(self,children=[node],name="snapTracker")
def get_drag_connection(self): """ Return a SoGroup() object of trackers which connect to the drag select """ _trackers = self.trackers['NODE'] #get list of sorted trackers _selected = [ _trackers[_k] for _k in sorted(self.gui_action['selected']) ] #get index values for first and last selected elements _idx = [int(_selected[_i].name.split('-')[1]) for _i in [0, -1]] _conn = [] self.connect_idx = 0 #if our starting node isn't the first, add the previous node if _idx[0] > 0: _conn.append(_trackers['NODE-' + str(_idx[0] - 1)]) self.connect_idx = 1 _conn.append(_selected[0]) self.drag_start = _selected[0].get() #if our ending node isn't the last, add the next node if _idx[-1] < len(_trackers) - 1: _conn.append(_trackers['NODE-' + str(_idx[-1] + 1)]) _result = coin.SoGroup() _coord = coin.SoCoordinate3() for _i, _v in enumerate(_conn): _coord.point.set1Value(_i, list(_v.get())) _marker = coin.SoMarkerSet() _line = coin.SoLineSet() _line.numVertices.setValue(_coord.point.getNum()) _node = coin.SoGroup() _node.addChild(_coord) _node.addChild(_marker) _node.addChild(_line) _result.addChild(_node) self.connect_coord = _coord return _result
def attach(self, vobj): self.Object = vobj.Object from pivy import coin sep = coin.SoSeparator() self.coords = coin.SoCoordinate3() sep.addChild(self.coords) self.coords.point.deleteValues(0) symbol = coin.SoMarkerSet() symbol.markerIndex = FreeCADGui.getMarkerIndex("", 5) sep.addChild(symbol) rn = vobj.RootNode rn.addChild(sep) ArchComponent.ViewProviderComponent.attach(self, vobj)
def __init__(self, x, y, z=0, color="red"): super(Point, self).__init__() self.marker = coin.SoMarkerSet() self.material = coin.SoMaterial() self.coordinate = coin.SoCoordinate3() self.material.setName('mat') self.marker.markerIndex = coin.SoMarkerSet.CIRCLE_FILLED_9_9 self.material.diffuseColor.setValue(COLORS[color]) self.addChild(self.coordinate) self.addChild(self.material) self.addChild(self.marker) self.coordinate.point.setValue(x, y, z)
def attach(self, vobj): self.Object = vobj.Object from pivy import coin sep = coin.SoSeparator() self.coords = coin.SoCoordinate3() sep.addChild(self.coords) self.coords.point.deleteValues(0) symbol = coin.SoMarkerSet() symbol.markerIndex = coin.SoMarkerSet.CIRCLE_FILLED_5_5 sep.addChild(symbol) rn = vobj.RootNode rn.addChild(sep) self.hiresgroup = coin.SoGroup() self.meshcolor = coin.SoBaseColor() self.hiresgroup.addChild(self.meshcolor) vobj.addDisplayMode(self.hiresgroup, "Mesh") ArchComponent.ViewProviderComponent.attach(self, vobj)
def attach(self, vobj): ''' Create Object visuals in 3D view. ''' # GeoCoord Node. self.geo_coords = coin.SoGeoCoordinate() # Point group features. points = coin.SoPointSet() self.markers = coin.SoMarkerSet() self.color_mat = coin.SoMaterial() self.point_normal = coin.SoNormal() self.point_style = coin.SoDrawStyle() self.point_style.style = coin.SoDrawStyle.POINTS # Highlight for selection. highlight = coin.SoType.fromName('SoFCSelection').createInstance() #highlight.documentName.setValue(FreeCAD.ActiveDocument.Name) #highlight.objectName.setValue(vobj.Object.Name) #highlight.subElementName.setValue("Main") highlight.addChild(self.geo_coords) highlight.addChild(points) highlight.addChild(self.markers) # Point labels features. color =coin.SoBaseColor() self.point_labels = coin.SoSeparator() self.point_labels.addChild(color) # Point group root. point_root = coin.SoSeparator() point_root.addChild(self.point_labels) point_root.addChild(self.point_style) point_root.addChild(self.point_normal) point_root.addChild(self.color_mat) point_root.addChild(highlight) vobj.addDisplayMode(point_root,"Point") # Take features from properties. if vobj.Object.Points: self.onChanged(vobj,"Elevation") self.onChanged(vobj,"PointSize") self.onChanged(vobj,"PointColor")
def __init__(self, marker=False, line=False, color=False, style=False): """ Constructor """ self.group = coin.SoGroup() self.coord = coin.SoCoordinate3() self.marker = coin.SoMarkerSet() self.line = coin.SoLineSet() self.color = coin.SoBaseColor() self.style = CoinStyles.DEFAULT self.group.addChild(self.coord) self.group.addChild(self.color) if marker: self.group.addChild(self.marker) self.group.addChild(self.line)
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, id, coord): self.node = coin.SoSeparator() self.coordinate = coin.SoCoordinate3() self.transform = coin.SoTransform() self.point = coord _selection_node = \ coin.SoType.fromName("SoFCSelection").createInstance() _selection_node.documentName.setValue('Document') _selection_node.objectName.setValue('Test Tracker') _selection_node.subElementName.setValue(str(id)) self.node.addChild(_selection_node) self.node.addChild(self.transform) self.node.addChild(self.coordinate) self.node.addChild(coin.SoMarkerSet()) self.coordinate.point.setValue(tuple(coord))
def __init__(self, pos, object_name, node_name, marker_type, marker_size): self.pos = pos self.name = node_name self.inactive = False self.color = coin.SoBaseColor() self.marker = coin.SoMarkerSet() self.marker.markerIndex = Gui.getMarkerIndex(marker_type, marker_size) self.coords = coin.SoCoordinate3() self.coords.point.setValue((pos.x, pos.y, pos.z)) selnode = None if self.inactive: selnode = coin.SoSeparator() else: selnode = coin.SoType.fromName("SoFCSelection").createInstance() selnode.documentName.setValue(App.ActiveDocument.Name) selnode.objectName.setValue(object_name) selnode.subElementName.setValue(node_name) node = coin.SoAnnotation() selnode.addChild(self.coords) selnode.addChild(self.color) selnode.addChild(self.marker) node.addChild(selnode) ontop = not self.inactive Tracker.__init__( self, children=[node], ontop=ontop, name="EditTracker") self.on()
def __init__(self, pos=Vector(0, 0, 0), name="None", idx=0, objcol=None): color = coin.SoBaseColor() if objcol: color.rgb = objcol[:3] else: color.rgb = FreeCADGui.draftToolBar.getDefaultColor("snap") self.marker = coin.SoMarkerSet() # this is the marker symbol self.marker.markerIndex = coin.SoMarkerSet.SQUARE_FILLED_9_9 self.coords = coin.SoCoordinate3() # this is the coordinate self.coords.point.setValue((pos.x, pos.y, pos.z)) selnode = coin.SoType.fromName("SoFCSelection").createInstance() selnode.documentName.setValue(FreeCAD.ActiveDocument.Name) selnode.objectName.setValue(name) selnode.subElementName.setValue("EditNode" + str(idx)) node = coin.SoAnnotation() selnode.addChild(self.coords) selnode.addChild(color) selnode.addChild(self.marker) node.addChild(selnode) Tracker.__init__(self, children=[node], ontop=True) self.on()
def build_connector_group(self): """ Build the SoGroup node which provides the connecting SoLineSet geometry to the geometry which is not being selected / dragged """ #select only the valid nodes among three _trackers = [ _c for _c in [ self.trackers['start'], self.trackers['selected'][0], self.trackers['end'] ] if _c ] #abort if we don't have at least two coordinates defined if len(_trackers) < 2: return #if end node is picked, reverse array so selected node is still 2nd if not self.trackers['start']: _trackers = list(reversed(_trackers)) #build component nodes _marker = coin.SoMarkerSet() _line = coin.SoLineSet() _line.numVertices.setValue(len(_trackers)) _coord = coin.SoCoordinate3() for _i, _v in enumerate(_trackers): _coord.point.set1Value(_i, tuple(_v.get())) #build the group node with coordinates, markers and lines group = self.nodes['connector'] group.addChild(_coord) group.addChild(_marker) group.addChild(_line)
def _build_drag_line(self): """ Build the drag line for drag operations """ #pylint: disable=no-member _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(coin.SoMarkerSet()) _g.addChild(_l) return _g
def create_default(self, names): """ Create the default node tracker """ style = self.STYLE.DEFAULT marker = coin.SoMarkerSet() marker.markerIndex = Gui.getMarkerIndex(style['shape'], style['size']) nam = names[:] nam[2] += '.' + style['id'] child = BaseTracker(nam, [self.coord, marker], style['select']) child.color.rgb = style['color'] group = coin.SoGroup() group.addChild(child.node) self.groups['default'].append(child) return group
def __init__(self, use_path=True): """docstring""" self.node = coin.SoSeparator() self.event_cb = coin.SoEventCallback() self.coordinate = coin.SoCoordinate3() self.marker = coin.SoMarkerSet() self.event_cb_switch = coin.SoSwitch() self.coordinate.point.setValue((0.0, 0.0, 0.0)) self.coordinate.setName('coordinate') self.event_cb.setName('event_cb') self.marker.setName('marker') self.cb_sigs = [ self.event_cb.addEventCallback( coin.SoLocation2Event.getClassTypeId(), self.on_mouse_cb), self.event_cb.addEventCallback( coin.SoMouseButtonEvent.getClassTypeId(), self.on_button_cb) ] self.event_cb_switch.addChild(self.event_cb) self.node.addChild(self.event_cb_switch) self.node.addChild(self.coordinate) self.node.addChild(self.marker) ViewState().sg_root.insertChild(self.node, 0) if not use_path: return _sa = coin.SoSearchAction() _sa.setNode(self.marker) _sa.apply(ViewState().sg_root) self.event_cb.setPath(_sa.getPath()) self.toggle_events()
def main(): myWindow = SoGui.init(sys.argv[0]) if myWindow == None: sys.exit(1) # add a new marker type: utils.addMarkerFromSvg("test.svg", "CUSTOM_MARKER", 50) root = coin.SoSeparator() color = coin.SoMaterial() color.diffuseColor = (1., 0., 0.) marker = coin.SoMarkerSet() marker.markerIndex = coin.SoMarkerSet.CUSTOM_MARKER data = coin.SoCoordinate3() data.point.setValue(0, 0, 0) data.point.setValues(0, 1, [[0., 0., 0.]]) myCamera = coin.SoPerspectiveCamera() root.addChild(myCamera) root.addChild(coin.SoDirectionalLight()) root.addChild(color) root.addChild(data) root.addChild(marker) root.addChild(data) root.addChild(marker) myRenderArea = SoGuiRenderArea(myWindow) myCamera.viewAll(root, myRenderArea.getViewportRegion()) myRenderArea.setSceneGraph(root) myRenderArea.setTitle("Hello Cone") myRenderArea.show() SoGui.show(myWindow) SoGui.mainLoop()