Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import FreeCAD, Part
- from pivy.coin import *
- from pivy import coin
- class _Point:
- def __init__(self, obj,x,y,z):
- obj.addProperty("App::PropertyFloat","x_pt","Point","Location").x_pt = x
- obj.addProperty("App::PropertyFloat","y_pt","Point","Location").y_pt = y
- obj.addProperty("App::PropertyFloat","z_pt","Point","Location").z_pt = z
- obj.Proxy = self
- def execute(self, obj):
- if obj.ViewObject:
- obj.ViewObject.update()
- class _ViewProviderPoint:
- def __init__(self, obj):
- obj.addProperty("App::PropertyColor","PointColor","Base","Point color")
- obj.addProperty("App::PropertyInteger", "PointSize", "Base", "Point size")
- obj.Proxy = self
- def __del__(self):
- FreeCADGui.ActiveDocument.ActiveView.getSceneGraph().removeChild(self.selnode)
- def attach(self, obj):
- self.material = coin.SoMaterial()
- self.color = coin.SoBaseColor()
- self.style=coin.SoDrawStyle()
- self.myPoint = coin.SoPointSet()
- self.selnode=coin.SoType.fromName("SoFCSelection").createInstance()
- self.selnode.documentName.setValue(FreeCAD.ActiveDocument.Name)
- self.selnode.objectName.setValue(obj.Object.Name)
- self.selnode.subElementName.setValue("Point")
- self.node=coin.SoSeparator()
- self.coords = coin.SoCoordinate3()
- self.node.addChild(self.coords)
- self.node.addChild(self.material)
- self.node.addChild(self.color)
- self.node.addChild(self.style)
- self.node.addChild(self.myPoint)
- self.selnode.addChild(self.node)
- FreeCADGui.ActiveDocument.ActiveView.getSceneGraph().addChild(self.selnode)
- def updateData(self, fp, prop):
- self.coords.point.setValue(fp.x_pt,fp.y_pt,fp.z_pt)
- def onChanged(self, vp, prop):
- c = vp.getPropertyByName("PointColor")
- self.color.rgb.setValue(c[0],c[1],c[2])
- self.style.pointSize =vp.getPropertyByName("PointSize")
- if vp.getPropertyByName("Visibility")== False:
- self.material.transparency.setValue(1.0)
- else:
- self.material.transparency.setValue(.1)
- def getIcon(self):
- return """
- /* XPM */
- static char * test_xpm[] = {
- "16 16 2 1",
- " c #FFFFFF",
- ". c #000000",
- " ",
- " ",
- " ",
- " ",
- " ",
- " .. ",
- " .... ",
- " ...... ",
- " .... ",
- " .. ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " "};
- """
- def __getstate__(self):
- return None
- def __setstate__(self,state):
- return None
- def makePoint(x_pt=0, y_pt=0, z_pt=0,c=(0,1,0),point_size= 5):
- ''' make a point (at coordinates x,y,z ,color(r,g,b),point_size)
- example usage:
- p1 = makePoint()
- p1.ViewObject.Visibility= False # make it invisible
- p1.ViewObject.Visibility= True # make it visible
- p1 = makePoint(-1,0,0) #make a point at -1,0,0
- p1 = makePoint(1,0,0,(1,0,0)) # color = red
- p1.x_pt = 1 #move it in x
- p1.ViewObject.PointColor =(0.0,0.0,1.0) #change the color-make sure values are floats
- '''
- obj=FreeCAD.ActiveDocument.addObject("App::FeaturePython","Point")
- _Point(obj,x_pt,y_pt,z_pt)
- _ViewProviderPoint(obj.ViewObject)
- obj.ViewObject.PointColor = (float(c[0]), float(c[1]), float(c[2]))
- obj.ViewObject.PointSize = point_size
- obj.ViewObject.Visibility = True
- FreeCAD.ActiveDocument.recompute()
- return obj
- ''' example usage:
- p1 = makePoint()
- p1.ViewObject.Visibility= False # make it invisible
- p1.ViewObject.Visibility= True # make it visible
- p2 = makePoint(-1,0,0)
- p3 = makePoint(1,0,0,(1,0,0)) # color = red
- p4 = makePoint()
- p4.x_pt = 1 #move it in x
- p5 = makePoint()
- p5.ViewObject.PointColor =(0.0,0.0,1.0) #change the color
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement