FreeCAD: Workbench Refactor
This commit is contained in:
parent
037827669a
commit
a58dcdafb1
386 changed files with 997 additions and 64533 deletions
49
freecad_workbench/DatumCommand.py
Normal file
49
freecad_workbench/DatumCommand.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
import FreeCAD
|
||||
import FreeCADGui
|
||||
from PySide import QtGui, QtCore
|
||||
|
||||
class DatumTool:
|
||||
"""
|
||||
A tool for creating datums in existing models
|
||||
"""
|
||||
def __init__(self):
|
||||
self.active = False
|
||||
|
||||
def activate(self):
|
||||
self.active = True
|
||||
FreeCAD.Console.PrintMessage("Datum tool activatedn")
|
||||
|
||||
def deactivate(self):
|
||||
self.active = False
|
||||
FreeCAD.Console.PrintMessage("Datum tool deactivatedn")
|
||||
|
||||
def mousePressEvent(self, event):
|
||||
if self.active:
|
||||
# Create a datum at the position of the mouse click
|
||||
pos = FreeCADGui.ActiveDocument.ActiveView.getCursorPos()
|
||||
point = FreeCADGui.ActiveDocument.ActiveView.getPoint(pos)
|
||||
datum = FreeCAD.ActiveDocument.addObject("Part::Datum", "Datum")
|
||||
datum.Placement.Base = point
|
||||
datum.ViewObject.ShapeColor = (0.0, 1.0, 0.0) # Set the color of the datum to green
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
|
||||
class DatumCommand:
|
||||
"""
|
||||
A command for activating and deactivating the datum tool
|
||||
"""
|
||||
def __init__(self):
|
||||
self.tool = DatumTool()
|
||||
|
||||
def Activated(self):
|
||||
self.tool.activate()
|
||||
FreeCADGui.ActiveDocument.ActiveView.addEventCallback("SoMouseButtonEvent", self.tool.mousePressEvent)
|
||||
|
||||
def Deactivated(self):
|
||||
self.tool.deactivate()
|
||||
FreeCADGui.ActiveDocument.ActiveView.removeEventCallback("SoMouseButtonEvent", self.tool.mousePressEvent)
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap': 'path/to/icon.png', 'MenuText': 'Datum Tool', 'ToolTip': 'Creates datum elements in existing models'}
|
||||
|
||||
# Add the command to the Draft Workbench
|
||||
FreeCADGui.addCommand('DatumCommand', DatumCommand())
|
Loading…
Add table
Add a link
Reference in a new issue