Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple Beamsplitters #57

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions InitGui.py
Original file line number Diff line number Diff line change
@@ -37,9 +37,10 @@ def Initialize(self):
QT_TRANSLATE_NOOP('Workbench', '2D Radial Beam'),
QT_TRANSLATE_NOOP('Workbench', 'Spherical Beam')]
optics = [QT_TRANSLATE_NOOP('Workbench', 'Emitter'),
QT_TRANSLATE_NOOP('Workbench', 'Mirror'),
QT_TRANSLATE_NOOP('Workbench', 'Grating'),
QT_TRANSLATE_NOOP('Workbench', 'Absorber'),
QT_TRANSLATE_NOOP('Workbench', 'Mirror'),
QT_TRANSLATE_NOOP('Workbench', 'Splitter'),
QT_TRANSLATE_NOOP('Workbench', 'Grating'),
QT_TRANSLATE_NOOP('Workbench', 'Absorber'),
QT_TRANSLATE_NOOP('Workbench', 'Lens')]
actions = [QT_TRANSLATE_NOOP('Workbench', 'Off'), QT_TRANSLATE_NOOP('Workbench', 'Start')]
analysis= [QT_TRANSLATE_NOOP('Workbench', 'RayHits'), QT_TRANSLATE_NOOP('Workbench', 'Hits2CSV')]
37 changes: 35 additions & 2 deletions OpticalObject.py
Original file line number Diff line number Diff line change
@@ -24,8 +24,8 @@ def __init__(self,
base = [],
type = 'mirror',
collectStatistics = False):
fp.addProperty('App::PropertyEnumeration', 'OpticalType', 'OpticalObject', '').OpticalType = ['mirror', 'absorber']
fp.addProperty('App::PropertyLinkList', 'Base', 'OpticalObject',
fp.addProperty('App::PropertyEnumeration', 'OpticalType', 'OpticalObject', '').OpticalType = ['mirror', 'splitter', 'absorber']
fp.addProperty('App::PropertyLinkList', 'Base', 'OpticalObject',
translate('Mirror', 'FreeCAD objects to be mirrors or absorbers')).Base = base
fp.addProperty('App::PropertyBool', 'collectStatistics', 'OpticalObject',
translate('Mirror', 'Count number and coordinates of ray hits')).collectStatistics = collectStatistics
@@ -187,6 +187,10 @@ def getIcon(self):
if self.Object.OpticalType == 'mirror':
return os.path.join(_icondir_, 'mirror.svg')


if self.Object.OpticalType == 'splitter':
return os.path.join(_icondir_, 'splitter.svg')

if self.Object.OpticalType == 'absorber':
return os.path.join(_icondir_, 'absorber.svg')

@@ -296,6 +300,34 @@ def GetResources(self):
'ToolTip' : QT_TRANSLATE_NOOP('Mirror','Declare your FreeCAD objects to be optical mirrors') }


class OpticalSplitter():
'''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):
selection = Gui.Selection.getSelectionEx()
Gui.doCommand('import OpticsWorkbench')
Gui.doCommand('objects = []')
for sel in selection:
Gui.doCommand('objects.append(FreeCAD.ActiveDocument.getObject("%s"))'%(sel.ObjectName))

Gui.doCommand('OpticsWorkbench.makeSplitter(objects)')

def IsActive(self):
'''Here you can define if the command must be active or not (greyed) if certain conditions
are met or not. This function is optional.'''
if FreeCAD.ActiveDocument:
return(True)
else:
return(False)

def GetResources(self):
'''Return the icon which will appear in the tree view. This method is optional and if not defined a default icon is shown.'''
return {'Pixmap' : os.path.join(_icondir_, 'splitter.svg'),
'Accel' : '', # a default shortcut (optional)
'MenuText': QT_TRANSLATE_NOOP('Splitter', 'Beam Splitter'),
'ToolTip' : QT_TRANSLATE_NOOP('Splitter','Declare your FreeCAD objects to be beam splitters') }


class OpticalAbsorber():
'''This class will be loaded when the workbench is activated in FreeCAD. You must restart FreeCAD to apply changes in this class'''

@@ -408,6 +440,7 @@ def GetResources(self):

Gui.addCommand('Emitter', OpticalEmitter())
Gui.addCommand('Mirror', OpticalMirror())
Gui.addCommand('Splitter', OpticalSplitter())
Gui.addCommand('Absorber', OpticalAbsorber())
Gui.addCommand('Lens', OpticalLens())
Gui.addCommand('Grating', OpticalGrating())
9 changes: 9 additions & 0 deletions OpticsWorkbench.py
Original file line number Diff line number Diff line change
@@ -149,6 +149,15 @@ def makeMirror(base = [], collectStatistics = False):
recompute()
return fp

def makeSplitter(base = [], collectStatistics = False):
#reload(OpticalObject)
'''All FreeCAD objects in base will be optical mirrors.'''
fp = activeDocument().addObject('Part::FeaturePython', 'Splitter')
OpticalObject.OpticalObjectWorker(fp, base, type = 'splitter', collectStatistics = collectStatistics)
OpticalObject.OpticalObjectViewProvider(fp.ViewObject)
recompute()
return fp

def makeAbsorber(base = [], collectStatistics = False):
#reload(OpticalObject)
'''All FreeCAD objects in base will be optical light absorbers.'''
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -93,6 +93,13 @@ The FreeCAD objects in parameter Base will act as mirrors
* Select some FreeCAD objects, then create Optical Mirror
see also [Statistics](#Statistics)

### ![Optical Splitter](./icons/splitter.svg) Optical Splitter
The FreeCAD objects in parameter Base will act as simple beamsplitters. There is no power tracking: the splitter just creates two new rays; one transmitted (without refraction), one reflected.
* Select FreeCAD objects that are single faces or planes (i.e. no solids), then turn them into beamsplitters
![screenshot](./examples/example_simple_beamsplitter.png)
Turning a solid, like a cube, into a splitter will cause transmitted rays to be reflected inside the object until the maximum iteration number is reached, adding many further rays that are transmitted to the outside.
see also [Statistics](#Statistics)

### ![Optical Absorber](./icons/absorber.svg) Optical Absorber
The FreeCAD objects in parameter `Base` will swallow the rays of light.
* Select some FreeCAD objects
Loading