def __init__(self): col = [0.2, 0.2, 0.3] pick = coin.SoPickStyle() pick.style.setValue(coin.SoPickStyle.UNPICKABLE) self.trans = coin.SoTransform() self.trans.translation.setValue([0, 0, 0]) mat1 = coin.SoMaterial() mat1.transparency.setValue(0.7) mat1.diffuseColor.setValue(col) self.coords1 = coin.SoCoordinate3() self.lines1 = coin.SoLineSet() mat2 = coin.SoMaterial() mat2.transparency.setValue(0.3) mat2.diffuseColor.setValue(col) self.coords2 = coin.SoCoordinate3() self.lines2 = coin.SoLineSet() mat3 = coin.SoMaterial() mat3.transparency.setValue(0) mat3.diffuseColor.setValue(col) self.coords3 = coin.SoCoordinate3() self.lines3 = coin.SoLineSet() s = coin.SoSeparator() s.addChild(pick) s.addChild(self.trans) s.addChild(mat1) s.addChild(self.coords1) s.addChild(self.lines1) s.addChild(mat2) s.addChild(self.coords2) s.addChild(self.lines2) s.addChild(mat3) s.addChild(self.coords3) s.addChild(self.lines3) Tracker.__init__(self, children=[s]) self.reset()
def __init__(self): # getting screen distance p1 = Draft.get3DView().getPoint((100,100)) p2 = Draft.get3DView().getPoint((110,100)) bl = (p2.sub(p1)).Length * (Draft.getParam("snapRange", 8)/2) pick = coin.SoPickStyle() pick.style.setValue(coin.SoPickStyle.UNPICKABLE) self.trans = coin.SoTransform() self.trans.translation.setValue([0,0,0]) m1 = coin.SoMaterial() m1.transparency.setValue(0.8) m1.diffuseColor.setValue([0.4,0.4,0.6]) c1 = coin.SoCoordinate3() c1.point.setValues([[-bl,-bl,0],[bl,-bl,0],[bl,bl,0],[-bl,bl,0]]) f = coin.SoIndexedFaceSet() f.coordIndex.setValues([0,1,2,3]) m2 = coin.SoMaterial() m2.transparency.setValue(0.7) m2.diffuseColor.setValue([0.2,0.2,0.3]) c2 = coin.SoCoordinate3() c2.point.setValues([[0,bl,0],[0,0,0],[bl,0,0],[-.05*bl,.95*bl,0],[0,bl,0], [.05*bl,.95*bl,0],[.95*bl,.05*bl,0],[bl,0,0],[.95*bl,-.05*bl,0]]) l = coin.SoLineSet() l.numVertices.setValues([3,3,3]) s = coin.SoSeparator() s.addChild(pick) s.addChild(self.trans) s.addChild(m1) s.addChild(c1) s.addChild(f) s.addChild(m2) s.addChild(c2) s.addChild(l) Tracker.__init__(self,children=[s],name="planeTracker")
def __init__(self): GRID_TRANSPARENCY = 0 col = self.getGridColor() pick = coin.SoPickStyle() pick.style.setValue(coin.SoPickStyle.UNPICKABLE) self.trans = coin.SoTransform() self.trans.translation.setValue([0, 0, 0]) mat1 = coin.SoMaterial() mat1.transparency.setValue(0.7*(1-GRID_TRANSPARENCY)) mat1.diffuseColor.setValue(col) self.font = coin.SoFont() self.coords1 = coin.SoCoordinate3() self.lines1 = coin.SoLineSet() texts = coin.SoSeparator() t1 = coin.SoSeparator() self.textpos1 = coin.SoTransform() self.text1 = coin.SoAsciiText() self.text1.string = " " t2 = coin.SoSeparator() self.textpos2 = coin.SoTransform() self.textpos2.rotation.setValue((0.0, 0.0, 0.7071067811865475, 0.7071067811865476)) self.text2 = coin.SoAsciiText() self.text2.string = " " t1.addChild(self.textpos1) t1.addChild(self.text1) t2.addChild(self.textpos2) t2.addChild(self.text2) texts.addChild(self.font) texts.addChild(t1) texts.addChild(t2) mat2 = coin.SoMaterial() mat2.transparency.setValue(0.3*(1-GRID_TRANSPARENCY)) mat2.diffuseColor.setValue(col) self.coords2 = coin.SoCoordinate3() self.lines2 = coin.SoLineSet() mat3 = coin.SoMaterial() mat3.transparency.setValue(GRID_TRANSPARENCY) mat3.diffuseColor.setValue(col) self.coords3 = coin.SoCoordinate3() self.lines3 = coin.SoLineSet() self.pts = [] s = coin.SoSeparator() s.addChild(pick) s.addChild(self.trans) s.addChild(mat1) s.addChild(self.coords1) s.addChild(self.lines1) s.addChild(mat2) s.addChild(self.coords2) s.addChild(self.lines2) s.addChild(mat3) s.addChild(self.coords3) s.addChild(self.lines3) s.addChild(texts) Tracker.__init__(self, children=[s], name="gridTracker") self.reset()
def _getPickStyleNode(self, viewprovider, make_if_missing=True): from pivy import coin sa = coin.SoSearchAction() sa.setType(coin.SoPickStyle.getClassTypeId()) sa.traverse(viewprovider.RootNode) if sa.isFound() and sa.getPath().getLength() == 1: return sa.getPath().getTail() else: if not make_if_missing: return None pick_style = coin.SoPickStyle() pick_style.style.setValue(coin.SoPickStyle.SHAPE) viewprovider.RootNode.insertChild(pick_style, 0) return pick_style
def dim_dash(p1, p2, color, LineWidth): dash = coin.SoSeparator() pick_style = coin.SoPickStyle() pick_style.style.setValue(coin.SoPickStyle.UNPICKABLE) #This will disallow to be picked by mouse click v = coin.SoVertexProperty() v.vertex.set1Value(0, p1) v.vertex.set1Value(1, p2) line = coin.SoLineSet() line.vertexProperty = v style = coin.SoDrawStyle() style.lineWidth = LineWidth my_transparency = coin.SoMaterial() my_transparency.transparency.setValue(0.5) dash.addChild(pick_style) #This will disallow to be picked by mouse click dash.addChild(style) dash.addChild(my_transparency) dash.addChild(color) dash.addChild(line) return dash
def __init__(self, names, children=None, has_events=True): """ Constructor """ super().__init__(names[2]) self.node_ok = False self.names = names self.name = names[2] self.state = TrackerContainer() self.color = coin.SoBaseColor() self.draw_style = coin.SoDrawStyle() self.node = coin.SoSeparator() self.parent = None self.picker = coin.SoPickStyle() self.switch = coin.SoSwitch() self.coin_style = CoinStyles.DEFAULT self.active_style = None self.matrix = None self.drag_group = None self.drag_copy = None self.select_state = '' self.show_drag_line = True self.partial_idx = [] #list to store indices for partial selections self.do_unset = False if not children: children = [] self.sel_node = \ coin.SoType.fromName("SoFCSelection").createInstance() self.sel_node.documentName.setValue(names[0]) self.sel_node.objectName.setValue(names[1]) self.sel_node.subElementName.setValue(names[2]) for child in [self.picker, self.draw_style, self.color] + children: self.node.addChild(child) self.separator = coin.SoSeparator() self.separator.addChild(self.sel_node) self.separator.addChild(self.node) self.switch.addChild(self.separator) self.callbacks = None if has_events: self.callbacks = { 'SoLocation2Event': ViewState().view.addEventCallback('SoLocation2Event', self.mouse_event), 'SoMouseButtonEvent': ViewState().view.addEventCallback('SoMouseButtonEvent', self.button_event) } #bypass overrides on initialization BaseTracker.set_style(self, CoinStyles.DEFAULT) BaseTracker.set_visibility(self, True) self.switch.whichChild = 0
def __init__(self): # self.space = 1 self.space = Draft.getParam("gridSpacing") # self.mainlines = 10 self.mainlines = Draft.getParam("gridEvery") self.numlines = 100 col = [0.2, 0.2, 0.3] pick = coin.SoPickStyle() pick.style.setValue(coin.SoPickStyle.UNPICKABLE) self.trans = coin.SoTransform() self.trans.translation.setValue([0, 0, 0]) bound = (self.numlines / 2) * self.space pts = [] mpts = [] apts = [] for i in range(self.numlines + 1): curr = -bound + i * self.space z = 0 if i / float(self.mainlines) == i / self.mainlines: if round(curr, 4) == 0: apts.extend([[-bound, curr, z], [bound, curr, z]]) apts.extend([[curr, -bound, z], [curr, bound, z]]) else: mpts.extend([[-bound, curr, z], [bound, curr, z]]) mpts.extend([[curr, -bound, z], [curr, bound, z]]) else: pts.extend([[-bound, curr, z], [bound, curr, z]]) pts.extend([[curr, -bound, z], [curr, bound, z]]) idx = [] midx = [] aidx = [] for p in range(0, len(pts), 2): idx.append(2) for mp in range(0, len(mpts), 2): midx.append(2) for ap in range(0, len(apts), 2): aidx.append(2) mat1 = coin.SoMaterial() mat1.transparency.setValue(0.7) mat1.diffuseColor.setValue(col) self.coords1 = coin.SoCoordinate3() self.coords1.point.setValues(pts) lines1 = coin.SoLineSet() lines1.numVertices.setValues(idx) mat2 = coin.SoMaterial() mat2.transparency.setValue(0.3) mat2.diffuseColor.setValue(col) self.coords2 = coin.SoCoordinate3() self.coords2.point.setValues(mpts) lines2 = coin.SoLineSet() lines2.numVertices.setValues(midx) mat3 = coin.SoMaterial() mat3.transparency.setValue(0) mat3.diffuseColor.setValue(col) self.coords3 = coin.SoCoordinate3() self.coords3.point.setValues(apts) lines3 = coin.SoLineSet() lines3.numVertices.setValues(aidx) s = coin.SoSeparator() s.addChild(pick) s.addChild(self.trans) s.addChild(mat1) s.addChild(self.coords1) s.addChild(lines1) s.addChild(mat2) s.addChild(self.coords2) s.addChild(lines2) s.addChild(mat3) s.addChild(self.coords3) s.addChild(lines3) Tracker.__init__(self, children=[s]) self.update()