+ added Point command to the Draft module (danfalck)
git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5326 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
parent
7ed0b0ae49
commit
9c7f5499b1
|
@ -1270,6 +1270,29 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None,name="Sketch"):
|
||||||
FreeCAD.ActiveDocument.removeObject(obj.Name)
|
FreeCAD.ActiveDocument.removeObject(obj.Name)
|
||||||
FreeCAD.ActiveDocument.recompute()
|
FreeCAD.ActiveDocument.recompute()
|
||||||
return nobj
|
return nobj
|
||||||
|
|
||||||
|
def makePoint(X=0, Y=0, Z=0,color=(0,1,0),name = "Point", 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 = 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("Part::FeaturePython",name)
|
||||||
|
_Point(obj,X,Y,Z)
|
||||||
|
_ViewProviderPoint(obj.ViewObject)
|
||||||
|
obj.X = X
|
||||||
|
obj.Y = Y
|
||||||
|
obj.Z = Z
|
||||||
|
obj.ViewObject.PointColor = (float(color[0]), float(color[1]), float(color[2]))
|
||||||
|
obj.ViewObject.PointSize = point_size
|
||||||
|
obj.ViewObject.Visibility = True
|
||||||
|
FreeCAD.ActiveDocument.recompute()
|
||||||
|
return obj
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
# Python Features definitions
|
# Python Features definitions
|
||||||
|
@ -2294,3 +2317,42 @@ class _ViewProviderArray(_ViewProviderDraft):
|
||||||
|
|
||||||
def claimChildren(self):
|
def claimChildren(self):
|
||||||
return [self.Object.Base]
|
return [self.Object.Base]
|
||||||
|
|
||||||
|
class _Point:
|
||||||
|
def __init__(self, obj,x,y,z):
|
||||||
|
obj.addProperty("App::PropertyFloat","X","Point","Location").X = x
|
||||||
|
obj.addProperty("App::PropertyFloat","Y","Point","Location").Y = y
|
||||||
|
obj.addProperty("App::PropertyFloat","Z","Point","Location").Z = z
|
||||||
|
mode = 2
|
||||||
|
obj.setEditorMode('Placement',mode)
|
||||||
|
obj.Proxy = self
|
||||||
|
self.Type = "Point"
|
||||||
|
|
||||||
|
def execute(self, fp):
|
||||||
|
self.createGeometry(fp)
|
||||||
|
|
||||||
|
def createGeometry(self,fp):
|
||||||
|
shape = Part.Vertex(Vector(fp.X,fp.Y,fp.Z))
|
||||||
|
fp.Shape = shape
|
||||||
|
|
||||||
|
class _ViewProviderPoint:
|
||||||
|
def __init__(self, obj):
|
||||||
|
obj.Proxy = self
|
||||||
|
|
||||||
|
def onChanged(self, vp, prop):
|
||||||
|
mode = 2
|
||||||
|
vp.setEditorMode('LineColor',mode)
|
||||||
|
vp.setEditorMode('LineWidth',mode)
|
||||||
|
vp.setEditorMode('BoundingBox',mode)
|
||||||
|
vp.setEditorMode('ControlPoints',mode)
|
||||||
|
vp.setEditorMode('Deviation',mode)
|
||||||
|
vp.setEditorMode('DiffuseColor',mode)
|
||||||
|
vp.setEditorMode('DisplayMode',mode)
|
||||||
|
vp.setEditorMode('Lighting',mode)
|
||||||
|
vp.setEditorMode('LineMaterial',mode)
|
||||||
|
vp.setEditorMode('ShapeColor',mode)
|
||||||
|
vp.setEditorMode('ShapeMaterial',mode)
|
||||||
|
vp.setEditorMode('Transparency',mode)
|
||||||
|
|
||||||
|
def getIcon(self):
|
||||||
|
return ":/icons/Draft_Dot.svg"
|
||||||
|
|
|
@ -3585,6 +3585,41 @@ class Array():
|
||||||
FreeCAD.ActiveDocument.openTransaction("Array")
|
FreeCAD.ActiveDocument.openTransaction("Array")
|
||||||
Draft.makeArray(obj,Vector(1,0,0),Vector(0,1,0),2,2)
|
Draft.makeArray(obj,Vector(1,0,0),Vector(0,1,0),2,2)
|
||||||
FreeCAD.ActiveDocument.commitTransaction()
|
FreeCAD.ActiveDocument.commitTransaction()
|
||||||
|
|
||||||
|
class Point:
|
||||||
|
"this class will create a vertex after the user clicks a point on the screen"
|
||||||
|
|
||||||
|
def GetResources(self):
|
||||||
|
return {'Pixmap' : 'Draft_Point',
|
||||||
|
'MenuText': QtCore.QT_TRANSLATE_NOOP("Draft_Point", "Point"),
|
||||||
|
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Draft_Point", "Creates a point object")}
|
||||||
|
|
||||||
|
def Activated(self):
|
||||||
|
self.view = FreeCADGui.ActiveDocument.ActiveView
|
||||||
|
self.stack = []
|
||||||
|
self.point = None
|
||||||
|
# adding 2 callback functions
|
||||||
|
self.callbackClick = self.view.addEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(),self.click)
|
||||||
|
self.callbackMove = self.view.addEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(),self.move)
|
||||||
|
|
||||||
|
def move(self,event_cb):
|
||||||
|
event = event_cb.getEvent()
|
||||||
|
mousepos = event.getPosition().getValue()
|
||||||
|
ctrl = event.wasCtrlDown()
|
||||||
|
self.point = FreeCADGui.Snapper.snap(mousepos,active=ctrl)
|
||||||
|
|
||||||
|
def click(self,event_cb):
|
||||||
|
event = event_cb.getEvent()
|
||||||
|
if event.getState() == coin.SoMouseButtonEvent.DOWN:
|
||||||
|
if self.point:
|
||||||
|
self.stack.append(self.point)
|
||||||
|
if len(self.stack) == 1:
|
||||||
|
self.view.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(),self.callbackClick)
|
||||||
|
self.view.removeEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(),self.callbackMove)
|
||||||
|
FreeCAD.ActiveDocument.openTransaction("Create Point")
|
||||||
|
Draft.makePoint((self.stack[0][0]),(self.stack[0][1]),0.0)
|
||||||
|
FreeCAD.ActiveDocument.commitTransaction()
|
||||||
|
FreeCADGui.Snapper.off()
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
# Adds the icons & commands to the FreeCAD command manager, and sets defaults
|
# Adds the icons & commands to the FreeCAD command manager, and sets defaults
|
||||||
|
@ -3601,6 +3636,7 @@ FreeCADGui.addCommand('Draft_Rectangle',Rectangle())
|
||||||
FreeCADGui.addCommand('Draft_Dimension',Dimension())
|
FreeCADGui.addCommand('Draft_Dimension',Dimension())
|
||||||
FreeCADGui.addCommand('Draft_Polygon',Polygon())
|
FreeCADGui.addCommand('Draft_Polygon',Polygon())
|
||||||
FreeCADGui.addCommand('Draft_BSpline',BSpline())
|
FreeCADGui.addCommand('Draft_BSpline',BSpline())
|
||||||
|
FreeCADGui.addCommand('Draft_Point',Point())
|
||||||
|
|
||||||
# modification commands
|
# modification commands
|
||||||
FreeCADGui.addCommand('Draft_Move',Move())
|
FreeCADGui.addCommand('Draft_Move',Move())
|
||||||
|
|
|
@ -187,7 +187,7 @@ class DraftWorkbench (Workbench):
|
||||||
pass
|
pass
|
||||||
self.cmdList = ["Draft_Line","Draft_Wire","Draft_Circle","Draft_Arc",
|
self.cmdList = ["Draft_Line","Draft_Wire","Draft_Circle","Draft_Arc",
|
||||||
"Draft_Polygon","Draft_Rectangle", "Draft_Text",
|
"Draft_Polygon","Draft_Rectangle", "Draft_Text",
|
||||||
"Draft_Dimension", "Draft_BSpline"]
|
"Draft_Dimension", "Draft_BSpline","Draft_Point"]
|
||||||
self.modList = ["Draft_Move","Draft_Rotate","Draft_Offset",
|
self.modList = ["Draft_Move","Draft_Rotate","Draft_Offset",
|
||||||
"Draft_Trimex", "Draft_Upgrade", "Draft_Downgrade", "Draft_Scale",
|
"Draft_Trimex", "Draft_Upgrade", "Draft_Downgrade", "Draft_Scale",
|
||||||
"Draft_Drawing","Draft_Edit","Draft_WireToBSpline","Draft_AddPoint",
|
"Draft_Drawing","Draft_Edit","Draft_WireToBSpline","Draft_AddPoint",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user