Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions OpticalObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ class OpticalMirror():
'''This class will be loaded when the workbench is activated in FreeCAD. You must restart FreeCAD to apply changes in this class'''

def Activated(self):
FreeCAD.ActiveDocument.openTransaction("Make mirror")
selection = Gui.Selection.getSelectionEx()
Gui.doCommand('import OpticsWorkbench')
Gui.doCommand('objects = []')
Expand All @@ -341,6 +342,7 @@ def Activated(self):
'objects.append(FreeCAD.ActiveDocument.getObject("%s"))' % (sel.ObjectName))

Gui.doCommand('OpticsWorkbench.makeMirror(objects)')
FreeCAD.ActiveDocument.commitTransaction()

def IsActive(self):
'''Here you can define if the command must be active or not (greyed) if certain conditions
Expand All @@ -362,6 +364,7 @@ class OpticalAbsorber():
'''This class will be loaded when the workbench is activated in FreeCAD. You must restart FreeCAD to apply changes in this class'''

def Activated(self):
FreeCAD.ActiveDocument.openTransaction("Make absorber")
selection = Gui.Selection.getSelectionEx()
Gui.doCommand('import OpticsWorkbench')
Gui.doCommand('objects = []')
Expand All @@ -370,6 +373,7 @@ def Activated(self):
'objects.append(FreeCAD.ActiveDocument.getObject("%s"))' % (sel.ObjectName))

Gui.doCommand('OpticsWorkbench.makeAbsorber(objects)')
FreeCAD.ActiveDocument.commitTransaction()

def IsActive(self):
'''Here you can define if the command must be active or not (greyed) if certain conditions
Expand All @@ -391,6 +395,7 @@ class OpticalLens():
'''This class will be loaded when the workbench is activated in FreeCAD. You must restart FreeCAD to apply changes in this class'''

def Activated(self):
FreeCAD.ActiveDocument.openTransaction("Make lens")
selection = Gui.Selection.getSelectionEx()
Gui.doCommand('import OpticsWorkbench')
Gui.doCommand('objects = []')
Expand All @@ -399,6 +404,7 @@ def Activated(self):
'objects.append(FreeCAD.ActiveDocument.getObject("%s"))' % (sel.ObjectName))

Gui.doCommand('OpticsWorkbench.makeLens(objects, material="Quartz")')
FreeCAD.ActiveDocument.commitTransaction()

def IsActive(self):
'''Here you can define if the command must be active or not (greyed) if certain conditions
Expand All @@ -420,6 +426,7 @@ class OpticalGrating():
'''This class will be loaded when the workbench is activated in FreeCAD. You must restart FreeCAD to apply changes in this class'''

def Activated(self):
FreeCAD.ActiveDocument.openTransaction("Make grating")
selection = Gui.Selection.getSelectionEx()
Gui.doCommand('import OpticsWorkbench')
Gui.doCommand('objects = []')
Expand All @@ -428,6 +435,7 @@ def Activated(self):
'objects.append(FreeCAD.ActiveDocument.getObject("%s"))' % (sel.ObjectName))

Gui.doCommand('OpticsWorkbench.makeGrating(objects)')
FreeCAD.ActiveDocument.commitTransaction()

def IsActive(self):
'''Here you can define if the command must be active or not (greyed) if certain conditions
Expand All @@ -449,6 +457,7 @@ class OpticalEmitter():
'''This class will be loaded when the workbench is activated in FreeCAD. You must restart FreeCAD to apply changes in this class'''

def Activated(self):
FreeCAD.ActiveDocument.openTransaction("Make ray")
selection = Gui.Selection.getSelectionEx()
Gui.doCommand('import OpticsWorkbench')
if len(selection) > 0:
Expand All @@ -460,6 +469,7 @@ def Activated(self):

Gui.doCommand(
'OpticsWorkbench.makeRay(baseShape=[obj, %s])' % faces)
FreeCAD.ActiveDocument.commitTransaction()

def IsActive(self):
'''Here you can define if the command must be active or not (greyed) if certain conditions
Expand Down
5 changes: 3 additions & 2 deletions Plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ class RayHits2CSV():

def Activated(self):
'''Will be called when the feature is executed.'''
# Generate commands in the FreeCAD python console to plot ray hits for selected absorber
# Generate commands in the FreeCAD python console to write ray hits for selected absorber as csv
activeDocument().openTransaction("Ray hit to csv")
Gui.doCommand('import OpticsWorkbench')
Gui.doCommand('OpticsWorkbench.Hits2CSV()')
activeDocument().commitTransaction()


def IsActive(self):
Expand All @@ -129,4 +131,3 @@ def GetResources(self):

Gui.addCommand('RayHits', PlotRayHits())
Gui.addCommand('Hits2CSV', RayHits2CSV())

12 changes: 12 additions & 0 deletions Ray.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,9 +911,11 @@ class Ray():

def Activated(self):
'''Will be called when the feature is executed.'''
FreeCAD.ActiveDocument.openTransaction("Make ray")
# Generate commands in the FreeCAD python console to create Ray
Gui.doCommand('import OpticsWorkbench')
Gui.doCommand('OpticsWorkbench.makeRay()')
FreeCAD.ActiveDocument.commitTransaction()

def IsActive(self):
'''Here you can define if the command must be active or not (greyed) if certain conditions
Expand All @@ -940,8 +942,10 @@ class RaySun():
def Activated(self):
'''Will be called when the feature is executed.'''
# Generate commands in the FreeCAD python console to create Ray
FreeCAD.ActiveDocument.openTransaction("Make sun ray")
Gui.doCommand('import OpticsWorkbench')
Gui.doCommand('OpticsWorkbench.makeSunRay()')
FreeCAD.ActiveDocument.commitTransaction()

def IsActive(self):
'''Here you can define if the command must be active or not (greyed) if certain conditions
Expand Down Expand Up @@ -973,9 +977,11 @@ class Beam2D():
def Activated(self):
'''Will be called when the feature is executed.'''
# Generate commands in the FreeCAD python console to create Ray
FreeCAD.ActiveDocument.openTransaction("Make beam 2d")
Gui.doCommand('import OpticsWorkbench')
Gui.doCommand(
'OpticsWorkbench.makeRay(beamNrColumns=50, beamDistance=0.1, rayBundleType="parallel")')
FreeCAD.ActiveDocument.commitTransaction()

def IsActive(self):
'''Here you can define if the command must be active or not (greyed) if certain conditions
Expand Down Expand Up @@ -1005,9 +1011,11 @@ class RadialBeam2D():
def Activated(self):
'''Will be called when the feature is executed.'''
# Generate commands in the FreeCAD python console to create Ray
FreeCAD.ActiveDocument.openTransaction("Make radial beam 2d")
Gui.doCommand('import OpticsWorkbench')
Gui.doCommand(
'OpticsWorkbench.makeRay(beamNrColumns=64, rayBundleType="spherical")')
FreeCAD.ActiveDocument.commitTransaction()

def IsActive(self):
'''Here you can define if the command must be active or not (greyed) if certain conditions
Expand Down Expand Up @@ -1040,10 +1048,12 @@ class SphericalBeam():
def Activated(self):
'''Will be called when the feature is executed.'''
# Generate commands in the FreeCAD python console to create Ray
FreeCAD.ActiveDocument.openTransaction("Make spherical beam")
Gui.doCommand('import OpticsWorkbench')
Gui.doCommand(
'OpticsWorkbench.makeRay(beamNrColumns=8, beamNrRows=8, rayBundleType="spherical")'
)
FreeCAD.ActiveDocument.commitTransaction()

def IsActive(self):
'''Here you can define if the command must be active or not (greyed) if certain conditions
Expand Down Expand Up @@ -1127,8 +1137,10 @@ class GridToFocalBeam():
'''A grid of rays converging toward a focal point'''

def Activated(self):
FreeCAD.ActiveDocument.openTransaction("Make grid to focal beam")
Gui.doCommand('import OpticsWorkbench')
Gui.doCommand('r = OpticsWorkbench.makeRay(beamNrColumns=10, beamNrRows=3, beamDistance=1.0, rayBundleType="focal", focalPoint=FreeCAD.Vector(0, 0, 100))')
FreeCAD.ActiveDocument.commitTransaction

def IsActive(self):
return activeDocument() is not None
Expand Down
2 changes: 2 additions & 0 deletions SunRay.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ class RaySun():
'''This class will be loaded when the workbench is activated in FreeCAD. You must restart FreeCAD to apply changes in this class'''

def Activated(self):
FreeCAD.ActiveDocument.openTransaction("Make sun ray")
Gui.doCommand('import OpticsWorkbench')
Gui.doCommand('OpticsWorkbench.makeSunRay()')
FreeCAD.ActiveDocument.commitTransaction()

def IsActive(self):
'''Here you can define if the command must be active or not (greyed) if certain conditions
Expand Down