Python pivy.coin.SoTransform() Examples

The following are 8 code examples of pivy.coin.SoTransform(). 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: 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 #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: assembly.py    From FreeCAD_assembly3 with GNU General Public License v3.0 5 votes vote down vote up
def setupAxis(self):
        vobj = getattr(self,'ViewObject', None)
        if not vobj:
            return
        switch = getattr(self,'axisNode',None)
        if not self.showCS():
            if switch:
                switch.whichChild = -1
            return

        if not switch:
            parentSwitch = vobj.SwitchNode
            if not parentSwitch.getNumChildren():
                return

            from pivy import coin
            switch = coin.SoSwitch()
            node = coin.SoType.fromName('SoFCSelectionRoot').createInstance()
            switch.addChild(node)
            trans = coin.SoTransform()
            node.addChild(trans)
            node.addChild(ViewProviderAsmElement.getAxis())
            self.axisNode = switch
            self.transNode = trans
            for i in range(parentSwitch.getNumChildren()):
                parentSwitch.getChild(i).addChild(switch)

        switch.whichChild = 0

        pla = vobj.Object.Placement.inverse().multiply(
                utils.getElementPlacement(vobj.Object.Shape))
        self.transNode.translation.setValue(pla.Base)
        self.transNode.rotation.setValue(pla.Rotation.Q) 
Example #4
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, trans = (0,0,0), text = ''):
        super(text2dNode, self).__init__()
        self.fontNode = coin.SoFont()
        self.transNode = coin.SoTransform()
        self.textNode = coin.SoText2()
        self.addChild(self.fontNode)
        self.addChild(self.transNode)
        self.addChild(self.textNode)
        self.color = color
        self.font = font
        self.size = size
        self.trans = trans
        self.text = text 
Example #5
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 #6
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 #7
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 #8
Source File: grid.py    From CurvesWB with GNU Lesser General Public License v2.1 4 votes vote down vote up
def attach(self, obj):

        self.trans = coin.SoTransform()

        self.xy = gridNode()
        self.xy.vector1dir = (1,0,0)
        self.xy.vector1color = (0.827,0.149,0.149) # red (X)
        self.xy.vector2dir = (0,1,0)
        self.xy.vector2color = (0.400,0.590,0.200) # green (Y)
        self.xy.mainDim = 100
        self.xy.subDim = 10
        self.xy.maxviz = 1.0
   
        self.xz = gridNode()
        self.xz.vector1dir = (1,0,0)
        self.xz.vector1color = (0.827,0.149,0.149) # red (X)
        self.xz.vector2dir = (0,0,1)
        self.xz.vector2color = (0.133,0.490,0.882) # blue (Z)
        self.xz.mainDim = 100
        self.xz.subDim = 10
        self.xz.maxviz = 0.5
   
        self.yz = gridNode()
        self.yz.vector1dir = (0,1,0)
        self.yz.vector1color = (0.400,0.590,0.200) # green (Y)
        self.yz.vector2dir = (0,0,1)
        self.yz.vector2color = (0.133,0.490,0.882) # blue (Z)
        self.yz.mainDim = 100
        self.yz.subDim = 10
        self.yz.maxviz = 0.5
   
        self.sg = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph()
        self.cam = FreeCADGui.ActiveDocument.ActiveView.getCameraNode()
   
        self.xy.linkTo(self.cam)
        self.xy.factor = 1.
        self.xz.linkTo(self.cam)
        self.xz.factor = 50.
        self.yz.linkTo(self.cam)
        self.yz.factor = 50.

        self.grid = coin.SoGroup()

        self.grid.addChild(self.trans)
        self.grid.addChild(self.xy)
        self.grid.addChild(self.xz)
        self.grid.addChild(self.yz)
        obj.addDisplayMode(self.grid,"Wireframe")

        self.ViewObject = obj
        self.Object = obj.Object

#    def updateCam(self):
#        self.cam = FreeCADGui.ActiveDocument.ActiveView.getCameraNode()
#        self.xy.linkTo(self.cam)
#        self.xz.linkTo(self.cam)
#        self.yz.linkTo(self.cam)