Python pivy.coin.SoSeparator() Examples

The following are 27 code examples of pivy.coin.SoSeparator(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pivy.coin , or try the search function .
Example #1
Source File: shaders.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
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_()) 
Example #2
Source File: polarUtilsCmd.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def __init__(self,pl=None, sizeFont=30, color=(1.0,0.6,0.0), text='TEXT'):
    import FreeCAD, FreeCADGui
    self.node=coin.SoSeparator()
    self.color=coin.SoBaseColor()
    self.color.rgb=color
    self.node.addChild(self.color)
    self.transform=coin.SoTransform()
    self.node.addChild(self.transform)
    self.font=coin.SoFont()
    self.node.addChild(self.font)
    self.font.size=sizeFont
    self.text=coin.SoText2()
    self.text.string=text
    self.node.addChild(self.text)
    self.sg=FreeCADGui.ActiveDocument.ActiveView.getSceneGraph()
    self.sg.addChild(self.node)
    if not pl:
      pl=FreeCAD.Placement()
    self.moveto(pl) 
Example #3
Source File: polarUtilsCmd.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def __init__(self,pl=None, scale=[100,100,20],offset=100,name='ARROW'):
    # define main properties
    self.view=FreeCADGui.ActiveDocument.ActiveView
    self.sg=self.view.getSceneGraph()
    self.cb=self.view.addEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), self.pickCB)
    # define OpenInventor properties
    self.node=coin.SoSeparator() #self.node=coin.SoSelection()
    self.name=name
    self.node.setName(self.name)
    self.color=coin.SoBaseColor(); self.color.rgb=0,0.8,0
    self.transform=coin.SoTransform(); self.transform.scaleFactor.setValue(scale)
    self.cone=coin.SoCone()
    # create children of node
    self.node.addChild(self.color)
    self.node.addChild(self.transform)
    self.node.addChild(self.cone)
    # draw the arrow and move it to its Placement with the specified offset
    self.sg.addChild(self.node)
    self.offset=offset
    if not pl:
      pl=FreeCAD.Placement()
    self.moveto(pl) 
Example #4
Source File: cointools.py    From NodeEditor with MIT License 6 votes vote down vote up
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) 
Example #5
Source File: visual_test.py    From pivy with ISC License 6 votes vote down vote up
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_()) 
Example #6
Source File: mesh.py    From pivy with ISC License 6 votes vote down vote up
def simple_poly_mesh(verts, poly, color=None):
    color = color or COLORS["grey"]
    _vertices = [list(v) for v in verts]
    _polygons = []
    for pol in poly:
        _polygons += list(pol) + [-1]
    sep = coin.SoSeparator()
    vertex_property = coin.SoVertexProperty()
    face_set = coin.SoIndexedFaceSet()
    shape_hint = coin.SoShapeHints()
    shape_hint.vertexOrdering = coin.SoShapeHints.COUNTERCLOCKWISE
    shape_hint.creaseAngle = np.pi / 3
    face_mat = coin.SoMaterial()
    face_mat.diffuseColor = color
    vertex_property.vertex.setValues(0, len(_vertices), _vertices)
    face_set.coordIndex.setValues(0, len(_polygons), list(_polygons))
    vertex_property.materialBinding = coin.SoMaterialBinding.PER_VERTEX_INDEXED
    sep += [shape_hint, vertex_property, face_mat, face_set]
    return sep 
Example #7
Source File: mesh.py    From pivy with ISC License 6 votes vote down vote up
def simple_quad_mesh(points, num_u, num_v, colors=None):
    msh_sep = coin.SoSeparator()
    msh = coin.SoQuadMesh()
    vertexproperty = coin.SoVertexProperty()
    vertexproperty.vertex.setValues(0, len(points), points)
    msh.verticesPerRow = num_u
    msh.verticesPerColumn = num_v
    if colors:
        vertexproperty.materialBinding = coin.SoMaterialBinding.PER_VERTEX
        for i in range(len(colors)):
            vertexproperty.orderedRGBA.set1Value(i, coin.SbColor(colors[i]).getPackedValue())
    msh.vertexProperty = vertexproperty

    shape_hint = coin.SoShapeHints()
    shape_hint.vertexOrdering = coin.SoShapeHints.COUNTERCLOCKWISE
    shape_hint.creaseAngle = np.pi / 3
    msh_sep += [shape_hint, msh]
    return msh_sep 
Example #8
Source File: __init__.py    From pivy with ISC License 6 votes vote down vote up
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() 
Example #9
Source File: GlClipPlane.py    From pivy with ISC License 6 votes vote down vote up
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_()) 
Example #10
Source File: ParametricBlendCurve.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
def build(self):
        self.active = False
        if not hasattr(self,'switch'):
            self.sg = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph()
            self.switch = coin.SoSwitch()
            if hasattr(self,'Object'):
                self.switch.setName("%s_ControlPoints"%self.Object.Name)
            self.empty = coin.SoSeparator() # Empty node
            self.node = coin.SoSeparator()
            self.coord = CoinNodes.coordinate3Node()
            self.poly = CoinNodes.polygonNode((0.5,0.5,0.5),1)
            self.marker = CoinNodes.markerSetNode((1,0,0),coin.SoMarkerSet.DIAMOND_FILLED_7_7)
            self.node.addChild(self.coord)
            self.node.addChild(self.poly)
            self.node.addChild(self.marker)
            self.switch.addChild(self.empty)
            self.switch.addChild(self.node)
            self.sg.addChild(self.switch) 
Example #11
Source File: graphics.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
def __init__(self, render_manager):
        super(InteractionSeparator, self).__init__()
        self.render_manager = render_manager
        self.objects = coin.SoSeparator()
        self.dynamic_objects = []
        self.static_objects = []
        self.over_object = None
        self.selected_objects = []
        self.drag_objects = []

        self.on_drag = []
        self.on_drag_release = []
        self.on_drag_start = []

        self._direction = None

        self.events = coin.SoEventCallback()
        self += self.events, self.objects 
Example #12
Source File: graphics.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
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() 
Example #13
Source File: grid2.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
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) 
Example #14
Source File: loooMarkers.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def __init__(self):
        super(Axis, self).__init__()
        self.xAxisSep = coin.SoSeparator()
        self.yAxisSep = coin.SoSeparator()
        self.zAxisSep = coin.SoSeparator()
        self.xaxisColor = coin.SoBaseColor()
        self.yaxisColor = coin.SoBaseColor()
        self.zaxisColor = coin.SoBaseColor()
        self.xaxisColor.rgb  = (0.8,0,0)
        self.xpts = [] #[[p[0]-1000,p[1],p[2]],[p[0]+1000,p[1],p[2]]]
        self.yaxisColor.rgb  = (0,0.8,0)
        self.ypts = [] #[[p[0],p[1]-1000,p[2]],[p[0],p[1]+1000,p[2]]]
        self.zaxisColor.rgb  = (0,0,0.8)
        self.zpts = [] #[[p[0],p[1],p[2]-1000],[p[0],p[1],p[2]+1000]]
        self.xaxis = coin.SoLineSet()
        self.xaxisPoints = coin.SoCoordinate3()
        self.xaxisPoints.point.setValue(0,0,0)
        self.xaxisPoints.point.setValues(0,len(self.xpts),self.xpts)
        self.xAxisSep.addChild(self.xaxisColor)
        self.xAxisSep.addChild(self.xaxisPoints)
        self.xAxisSep.addChild(self.xaxis)
        self.yaxis = coin.SoLineSet()
        self.yaxisPoints = coin.SoCoordinate3()
        self.yaxisPoints.point.setValue(0,0,0)
        self.yaxisPoints.point.setValues(0,len(self.ypts),self.ypts)
        self.yAxisSep.addChild(self.yaxisColor)
        self.yAxisSep.addChild(self.yaxisPoints)
        self.yAxisSep.addChild(self.yaxis)
        self.zaxis = coin.SoLineSet()
        self.zaxisPoints = coin.SoCoordinate3()
        self.zaxisPoints.point.setValue(0,0,0)
        self.zaxisPoints.point.setValues(0,len(self.zpts),self.zpts)
        self.zAxisSep.addChild(self.zaxisColor)
        self.zAxisSep.addChild(self.zaxisPoints)
        self.zAxisSep.addChild(self.zaxis)
        self.xState = False
        self.yState = False
        self.zState = False 
Example #15
Source File: cointools.py    From NodeEditor with MIT License 5 votes vote down vote up
def displaytext(self,pos,color=(1,1,1),text=["aaa","bbb"]):
    
    textpos = coin.SoTransform()
    p=pos
    textpos.translation.setValue(p.x+10,p.y+10,p.z+10)
    font = coin.SoFont()
    font.size = 20
    text2d = coin.SoText2()
    text3d = coin.SoAsciiText()
    
    text2d.string.setValues([l.encode("utf8") for l in text if l])
    text3d.string.setValues([l.encode("utf8") for l in text if l])

    myMaterial = SoMaterial()
    myMaterial.diffuseColor.set1Value(0, SbColor(*color))

    try:
        sg=self._sg
    except:
        sg    = SoSeparator()
        self._sg= sg
        root=FreeCADGui.ActiveDocument.ActiveView.getSceneGraph()
        root.addChild(sg)
        
        
    node2d    = SoSeparator()


    node2d.addChild(textpos)
    node2d.addChild(myMaterial)
    node2d.addChild(font)
    node2d.addChild(text2d)
    #node2d.addChild(text3d)
    sg.addChild(node2d) 
Example #16
Source File: CoinNodes.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def __init__(self, color = (0.,0.,0.), font = 'sans', size = 16, offset = 0):
        super(multiTextNode, self).__init__()
        self.fontNode = coin.SoFont()
        self.textSep = coin.SoSeparator()
        self.nodeList = []
        self._data = []
        self.addChild(self.fontNode)
        self.addChild(self.textSep)
        self.color = color
        self.font = font
        self.size = size
        self.offset = offset 
Example #17
Source File: CoinNodes.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def data(self, datarr):
        if not ((len(self._data) == len(datarr[0])) & (len(self._data) == len(datarr[1]))): # lengths of the 2 arrays are different. Wipe the Separator and populate it.
            self.nodeList = []
            self._data = []
            self.textSep.removeAllChildren()
            for i in range(min(len(datarr[0]),len(datarr[1]))):
                sep = coin.SoSeparator()
                textpos = coin.SoTransform()
                textpos.translation.setValue([datarr[0][i][0],datarr[0][i][1],datarr[0][i][2]])
                text = coin.SoText2()
                field = [""]*self.offset + [datarr[1][i]]
                text.string.setValues(0,len(field),field)
                sep.addChild(textpos)
                sep.addChild(text)
                self.textSep.addChild(sep)
                self.nodeList.append((textpos,text))
                self._data.append((datarr[0][i],datarr[1][i]))
        else:
            for i in range(min(len(datarr[0]),len(datarr[1]))):
                print(range(min(len(datarr[0]),len(datarr[1]))))
                print(self.nodeList[i][0])
                self.nodeList[i][0].translation.setValue([datarr[0][i][0],datarr[0][i][1],datarr[0][i][2]])
                field = [""]*self.offset + [datarr[1][i]]
                self.nodeList[i][1].string.setValues(0,len(field),field)
                self._data[i] = (datarr[0][i],datarr[1][i])


#c = coordinate3Node([(0,1,0),(1,1,0),(2,2,1)])
#p = polygonNode((0.5,0.9,0.1),2)
#m = markerSetNode((1,0.35,0.8),1)
#t = text2dNode((0.2,0.9,0.9),'osiFont',15,(10,15,20),'blabla')
#mt = multiTextNode((0.2,0.9,0.9),'osiFont',15,(10,15,20))
#mt.data = ([(1,2,3),(4,5,6)],['bla','blublu']) 
Example #18
Source File: QuarterWidget.py    From pivy with ISC License 5 votes vote down vote up
def setSceneGraph(self, node):
        if node and self.scene==node:
            return

        camera = None
        superscene = None
        viewall = False

        if node:
            self.scene = node
            self.scene.ref()

            superscene = coin.SoSeparator()
            superscene.addChild(coin.SoDepthBuffer())
            superscene.addChild(self.headlight)

            camera = self.searchForCamera(node)
            if not camera:
                camera = coin.SoPerspectiveCamera()
                superscene.addChild(camera)
                viewall = True

            superscene.addChild(node)

        self.soeventmanager.setSceneGraph(superscene)
        self.sorendermanager.setSceneGraph(superscene)
        self.soeventmanager.setCamera(camera)
        self.sorendermanager.setCamera(camera)

        if viewall:
            self.viewAll()

        if superscene:
            superscene.touch() 
Example #19
Source File: viewer.py    From pivy with ISC License 5 votes vote down vote up
def __init__(self, *args, **kwrds):
        try:
            self.app = QtGui.QApplication([])
        except RuntimeError:
            self.app = QtGui.QApplication.instance()

        super(Viewer, self).__init__(*args, **kwrds)
        self.sg = coin.SoSeparator()
        self.sg += [coin.SoOrthographicCamera()]
        self.setSceneGraph(self.sg)
        self.setBackgroundColor(coin.SbColor(1,1,1))
        self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) 
Example #20
Source File: minimal.py    From pivy with ISC License 5 votes vote down vote up
def main():
    app = QApplication(sys.argv)

    root = SoSeparator()
    col = SoBaseColor()
    col.rgb = SbColor(1, 1, 0)
    root.addChild(col)
    root.addChild(SoCone())

    viewer = QuarterWidget()
    viewer.setSceneGraph(root)

    viewer.setWindowTitle("minimal")
    viewer.show()
    sys.exit(app.exec_()) 
Example #21
Source File: marker_from_svg.py    From pivy with ISC License 5 votes vote down vote up
def main():
    myWindow = SoGui.init(sys.argv[0])
    if myWindow == None: sys.exit(1)

    # add a new marker type:
    utils.add_marker_from_svg("test.svg", "CUSTOM_MARKER",  30)

    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() 
Example #22
Source File: event_callback.py    From pivy with ISC License 5 votes vote down vote up
def main():
    app = QApplication(sys.argv)
    viewer = quarter.QuarterWidget()

    root = coin.SoSeparator()
    root += coin.SoCone()
    root += test()

    viewer.setSceneGraph(root)
    viewer.setBackgroundColor(QColor(255, 255, 255))
    viewer.setWindowTitle("minimal")
    viewer.show()
    sys.exit(app.exec_()) 
Example #23
Source File: HUD.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def __init__(self):
        debug("HUD init")

        self.HUDNode = coin.SoSeparator()
        
        self.cam = coin.SoOrthographicCamera()
        self.cam.aspectRatio = 1
        self.cam.viewportMapping = coin.SoCamera.LEAVE_ALONE

        self.HUDNode.addChild(self.cam) 
Example #24
Source File: SurfaceEdit.py    From CurvesWB with GNU Lesser General Public License v2.1 4 votes vote down vote up
def buildViz(self):
        self.viewer=self.view.getViewer()
        FreeCAD.Console.PrintMessage(str(self.viewer)+ "\n")
        self.render=self.viewer.getSoRenderManager()
        FreeCAD.Console.PrintMessage(str(self.render)+ "\n")
        self.render.setRenderMode(self.render.WIREFRAME_OVERLAY)
        self.action=self.render.getGLRenderAction()
        FreeCAD.Console.PrintMessage(str(self.action.getTypeId().getName())+ "\n") # => "SoBoxSelectionRenderAction" is our own class
        
        if ( str(self.action.getTypeId().getName()) == "SoBoxSelectionRenderAction" ): # replace it with the standard render action
            self.glAction=coin.SoGLRenderAction(self.render.getViewportRegion())
            FreeCAD.Console.PrintMessage(str(self.glAction)+ "\n")
            self.render.setGLRenderAction(self.glAction)
            FreeCAD.Console.PrintMessage('setGLRenderAction : OK'+ "\n")
        self.cpc = loooMarkers.Container()    # control point container
        self.markerList = []
        array = toRat4D(self.selectedSurface.getPoles(), self.selectedSurface.getWeights())
        for j in range(len(array[0])):
            markerRow = []
            for i in range(len(array)):
                p = [array[i][j][0], array[i][j][1], array[i][j][2], array[i][j][3]] #[pt.x, pt.y, pt.z, pt.w]
                marker = loooMarkers.Marker([p], dynamic=True)
                markerRow.append(marker)
            self.markerList.append(markerRow)
        
        self.markerList[0][0].marker.markerIndex = coin.SoMarkerSet.SQUARE_FILLED_9_9
        self.markerList[0][-1].marker.markerIndex = coin.SoMarkerSet.DIAMOND_FILLED_9_9 #SQUARE_FILLED_9_9
        self.markerList[-1][0].marker.markerIndex = coin.SoMarkerSet.TRIANGLE_FILLED_9_9

        for row in self.markerList:
            self.cpc.addChildren(row)
        
        self.cpc.nbUPoles = len(self.markerList)
        self.cpc.nbVPoles = len(self.markerList[0])

        self.updateViewObjects()
        self.CoinSurf = coinSurface(self.selectedSurface)
        self.grid = coinGrid(self.markerList)
        self.vizSep = coin.SoSeparator()
        self.vizSep.addChild(self.SoCoords)
        self.vizSep.addChild(self.grid.gridSep)
        FreeCAD.Console.PrintMessage("Grid added\n")
        self.vizSep.addChild(self.CoinSurf.surfaceNode)
        FreeCAD.Console.PrintMessage("Surface added\n")
        self.vizSep.addChild(self.cpc)
        FreeCAD.Console.PrintMessage("container added\n")
        self.cpc.register(self.view)
        FreeCAD.Console.PrintMessage("container registered\n")
        self.sg.addChild(self.vizSep)
        #self.sg.addChild(self.grid.gridSep)
        #FreeCAD.Console.PrintMessage("Grid added\n")
        #self.sg.addChild(self.CoinSurf.surfaceNode)
        #FreeCAD.Console.PrintMessage("Surface added\n")

        self.cpc.on_drag.append(self.updateViewObjects) 
Example #25
Source File: SurfaceEdit.py    From CurvesWB with GNU Lesser General Public License v2.1 4 votes vote down vote up
def __init__(self, mlist):
        self.colorRed = coin.SoBaseColor()
        self.colorRed.rgb=(1,0,0)
        self.colorGreen = coin.SoBaseColor()
        self.colorGreen.rgb=(0,1,0)
        self.colorBlue = coin.SoBaseColor()
        self.colorBlue.rgb=(0,0,1)
        self.colorYellow = coin.SoBaseColor()
        self.colorYellow.rgb=(1,1,0)
        self.colorPurple = coin.SoBaseColor()
        self.colorPurple.rgb=(1,0,1)
        self.colorCyan = coin.SoBaseColor()
        self.colorCyan.rgb=(0,1,1)
        self.colorWhite = coin.SoBaseColor()
        self.colorWhite.rgb=(1,1,1)
        self.colorBlack = coin.SoBaseColor()
        self.colorBlack.rgb=(0,0,0)
        self.Ulen = len(mlist)
        self.Vlen = len(mlist[0])
        self.pts = []
        for row in mlist:
            for pt in row:
                self.pts.append(pt.points[0])
        num = []
        for u in range(self.Ulen):
            for v in range(self.Vlen):
                num.append(u*self.Vlen+v)
            num.append(-1)
        num2 = []
        for v in range(self.Vlen):
            for u in range(self.Ulen):
                num2.append(u*self.Vlen+v)
            num2.append(-1)
        print(str(num))
        print(str(num2))
        self.gridSep = coin.SoSeparator()
        #self.coords = coin.SoCoordinate3()
        #self.coords.point.setValues(0,len(self.pts),self.pts)

        self.Line = coin.SoIndexedLineSet()
        self.Line.coordIndex.setValues(0,len(num),num)
        self.Node = coin.SoSeparator()
        #self.Node.addChild(self.coords)
        self.Node.addChild(self.colorBlue)
        self.Node.addChild(self.Line)

        self.Line2 = coin.SoIndexedLineSet()
        self.Line2.coordIndex.setValues(0,len(num2),num2)
        self.Node2 = coin.SoSeparator()
        #self.Node2.addChild(self.coords)
        self.Node2.addChild(self.colorPurple)
        self.Node2.addChild(self.Line2)
        
        self.gridSep.addChild(self.Node)
        self.gridSep.addChild(self.Node2) 
Example #26
Source File: cointools.py    From NodeEditor with MIT License 4 votes vote down vote up
def displayline(self,pts,color=(1,1,1),linewidth=4):
    
    try:
        sg=self._sg
    except:
        sg    = SoSeparator()
        self._sg= sg
        root=FreeCADGui.ActiveDocument.ActiveView.getSceneGraph()
        root.addChild(sg)
        
        
    heart    = SoSeparator()
    coord = SoCoordinate3()
    coord.point.setValues(0,len(pts),pts)
    a=[i for i in range(len(pts))]+[-1]

    drawstyle = SoDrawStyle()
    drawstyle.style = SoDrawStyle.LINES
    drawstyle.lineWidth = 1
   

    lineSet = SoIndexedLineSet()
    lineSet.coordIndex.setValue(0)
    lineSet.coordIndex.setValues(0, len(a), a)

    myMaterial = SoMaterial()
    myBinding = SoMaterialBinding()
    myMaterial.diffuseColor.set1Value(0, SbColor(*color))
#   myMaterial.diffuseColor.set1Value(1, SbColor(0,1.,0))
#   myMaterial.diffuseColor.set1Value(2, SbColor(0,1.,1))
#   myMaterial.diffuseColor.set1Value(3, SbColor(1,0.,1))
#    myBinding.value = SoMaterialBinding.PER_PART

    heart.addChild(drawstyle)
    heart.addChild(myMaterial)
    heart.addChild(myBinding)


    heart.addChild(coord)
    heart.addChild(lineSet)
    sg.addChild(heart)
    #root.removeChild(heart)
    # self._sg=heart
   # displaytext(self,pts,color=(1,1,0)) 
Example #27
Source File: hooks.py    From CurvesWB with GNU Lesser General Public License v2.1 4 votes vote down vote up
def attach(self, vobj):
        self.ViewObject = vobj
        self.Object = vobj.Object
        
        #self.selectionNode = coin.SoType.fromName("SoFCSelection").createInstance()
        #self.selectionNode.documentName.setValue(FreeCAD.ActiveDocument.Name)
        #self.selectionNode.objectName.setValue(vobj.Object.Name) # here obj is the ViewObject, we need its associated App Object
        #self.selectionNode.subElementName.setValue("Vertex")
        
        
        #self.node = coin.SoSeparator()
        #self.node.setName("Hook")
        #self.coord = coin.SoCoordinate3()
        #self.marker = coin.SoSphere() #coin.SoMarkerSet() #((1,0,0),coin.SoMarkerSet.DIAMOND_FILLED_9_9)
        ##self.marker.markerIndex = coin.SoMarkerSet.DIAMOND_FILLED_9_9
        #self.color = coin.SoBaseColor()
        #self.color.rgb = (1,0,0)
        
        
        ##self.node.addChild(self.color)
        ##self.node.addChild(self.coord)
        ##self.node.addChild(self.marker)
        #self.selectionNode.addChild(self.color)
        #self.selectionNode.addChild(self.coord)
        #self.selectionNode.addChild(self.marker)
        
        #vobj.addDisplayMode(self.selectionNode,"Wireframe")

    #def updateData(self, fp, prop):
        #if prop == "Center":
            #vec = coin.SbVec3f(fp.Center.x, fp.Center.y, fp.Center.z)
            #self.coord.point.setValue(vec)
            ##self.coord.point.setValues(0,len([vec]),[vec])

    #def getDisplayModes(self,obj):
         #"Return a list of display modes."
         #modes=[]
         #modes.append("Wireframe")
         #return modes

    #def getDefaultDisplayMode(self):
         #'''Return the name of the default display mode. It must be defined in getDisplayModes.'''
         #return "Wireframe"

    #def setDisplayMode(self,mode):
         #return mode