Package theia :: Package rendering :: Module features
[hide private]
[frames] | no frames]

Source Code for Module theia.rendering.features

  1  '''Features module or theia, to represent objects as FreeCAD Python features.''' 
  2   
  3  # Provides: 
  4  #   class FCObject 
  5  #   class FCMirror 
  6  #   class FCSpecial 
  7  #   class FCBeamSplitter 
  8  #   class FCLens 
  9  #   class FCBeamDump 
 10  #   class FCBeam 
 11   
 12  from FreeCAD import Base 
 13  from ..helpers import settings 
 14  from ..helpers.units import deg 
 15  from .shapes import mirrorShape, lensShape, beamDumpShape, beamShape 
 16  from .shapes import beamSplitterShape 
 17   
18 -class FCObject(object):
19 '''Mother class for all FreeCAD objects. 20 21 fact: Factor to compensate for unit difference with FreeCAD. [float] 22 ''' 23 fact = settings.FCFactor
24 - def __init__(self, obj):
25 '''Custom properties of the object. 26 ''' 27 obj.Proxy = self
28
29 -class FCMirror(FCObject):
30 - def __init__(self, obj, mirror):
31 super(FCMirror, self).__init__(obj) 32 obj.Shape = mirrorShape(mirror) 33 obj.addProperty("App::PropertyString", "Wedge", "Mirror", 34 "Wedge of the mirror").Wedge = str(mirror.Wedge/deg) + ' deg' 35 obj.addProperty("App::PropertyString", "HRK", "Mirror", 36 "HR curvature").HRK = str(mirror.HRK) + ' m^-1' 37 obj.addProperty("App::PropertyString", "ARK", "Mirror", 38 "AR curvature").ARK = str(mirror.ARK) + ' m^-1' 39 obj.addProperty("App::PropertyDistance", "Thick", "Mirror", 40 "Thickness of mirror").Thick = mirror.Thick/self.fact 41 obj.addProperty("App::PropertyString", "N", "Mirror", 42 "Optical index").N = str(mirror.N) 43 obj.addProperty("App::PropertyDistance", "Dia", "Mirror", 44 "Diameter").Dia = mirror.Dia/.001 45 obj.Placement.Base = Base.Vector(tuple(mirror.HRCenter/self.fact))
46
47 -class FCSpecial(FCObject):
48 - def __init__(self, obj, opt):
49 super(FCSpecial, self).__init__(obj) 50 obj.Shape = mirrorShape(opt) 51 obj.addProperty("App::PropertyString", "Wedge", "Special", 52 "Wedge of the optic").Wedge = str(opt.Wedge/deg) + ' deg' 53 obj.addProperty("App::PropertyString", "HRK", "Special", 54 "HR curvature").HRK = str(opt.HRK) + ' m^-1' 55 obj.addProperty("App::PropertyString", "ARK", "Special", 56 "AR curvature").ARK = str(opt.ARK) + ' m^-1' 57 obj.addProperty("App::PropertyDistance", "Thick", "Special", 58 "Thickness of optic").Thick = opt.Thick/self.fact 59 obj.addProperty("App::PropertyString", "N", "Special", 60 "Optical index").N = str(opt.N) 61 obj.addProperty("App::PropertyDistance", "Dia", "Special", 62 "Diameter").Dia = opt.Dia/.001 63 obj.addProperty("App::PropertyString", "TonHR", "Action", 64 "Action for T on HR").TonHR = '+' + str(opt.TonHR) 65 obj.addProperty("App::PropertyString", "RonHR", "Action", 66 "Action for R on HR").RonHR = '+' + str(opt.RonHR) 67 obj.addProperty("App::PropertyString", "TonAR", "Action", 68 "Action for T on AR").TonAR = '+' + str(opt.TonAR) 69 obj.addProperty("App::PropertyString", "RonAR", "Action", 70 "Action for R on AR").RonAR = '+' + str(opt.RonAR) 71 obj.Placement.Base = Base.Vector(tuple(opt.HRCenter/self.fact))
72
73 -class FCBeamSplitter(FCObject):
74 - def __init__(self, obj, beamSplitter):
75 super(FCBeamSplitter, self).__init__(obj) 76 obj.Shape = beamSplitterShape(beamSplitter) 77 obj.addProperty("App::PropertyString", "Wedge", "BeamSplitter", 78 "Wedge of the beam splitter").Wedge = str(beamSplitter.Wedge/deg) \ 79 + ' deg' 80 obj.addProperty("App::PropertyString", "HRK", "BeamSplitter", 81 "HR curvature").HRK = str(beamSplitter.HRK) + ' m^-1' 82 obj.addProperty("App::PropertyString", "ARK", "BeamSplitter", 83 "AR curvature").ARK = str(beamSplitter.ARK) + ' m^-1' 84 obj.addProperty("App::PropertyDistance", "Thick", "BeamSplitter", 85 "Thickness of beam splitter").Thick = beamSplitter.Thick/self.fact 86 obj.addProperty("App::PropertyString", "N", "BeamSplitter", 87 "Optical index").N = str(beamSplitter.N) 88 obj.addProperty("App::PropertyDistance", "Dia", "BeamSplitter", 89 "Diameter").Dia = beamSplitter.Dia/.001 90 obj.Placement.Base = Base.Vector(tuple(beamSplitter.HRCenter/self.fact))
91
92 -class FCLens(FCObject):
93 - def __init__(self, obj, lens):
94 super(FCLens, self).__init__(obj) 95 obj.Shape = lensShape(lens) 96 if lens.Name == "ThinLens": 97 obj.addProperty("App::PropertyDistance", "Focal", "Lens", 98 "FocalLength").Focal = lens.Focal/self.fact 99 else: 100 obj.addProperty("App::PropertyString", "K1", "Lens", 101 "K1 curvature").K1 = str(lens.HRK) + ' m^-1' 102 obj.addProperty("App::PropertyString", "K2", "Lens", 103 "K2 curvature").K2 = str(lens.ARK) + ' m^-1' 104 obj.addProperty("App::PropertyDistance", "Thick", "Lens", 105 "Thickness of lens").Thick = lens.Thick/self.fact 106 obj.addProperty("App::PropertyFloat", "N", "Lens", 107 "Optical index").N = lens.N 108 109 obj.addProperty("App::PropertyDistance", "Dia", "Lens", 110 "Diameter").Dia = lens.Dia/self.fact 111 obj.Placement.Base = Base.Vector(tuple(lens.HRCenter/self.fact))
112
113 -class FCBeamDump(FCObject):
114 - def __init__(self, obj, beamDump):
115 super(FCBeamDump, self).__init__(obj) 116 obj.Shape = beamDumpShape(beamDump) 117 obj.addProperty("App::PropertyDistance", "Thick", "BeamDump", 118 "Thickness of beamdump").Thick = beamDump.Thick/self.fact 119 obj.addProperty("App::PropertyDistance", "Dia", "BeamDump", 120 "Diameter").Dia = beamDump.Dia/self.fact 121 obj.Placement.Base = Base.Vector(tuple(beamDump.HRCenter/self.fact))
122
123 -class FCBeam(FCObject):
124 - def __init__(self, obj, beam):
125 super(FCBeam, self).__init__(obj) 126 obj.Shape = beamShape(beam) 127 128 #general 129 obj.addProperty("App::PropertyString", "Order", "Beam", 130 "Order of the beam").Order = str(beam.StrayOrder) 131 obj.addProperty("App::PropertyString", "Ref", "Beam", 132 "Full Reference of the beam").Ref = str(beam.Ref) 133 obj.addProperty("App::PropertyString", "P", "Beam", 134 "Power of the beam").P = str(beam.P/0.001) + 'mW' 135 obj.addProperty("App::PropertyString", "L", "Beam", 136 "Length of beam").L = str(beam.Length) + 'm'\ 137 if beam.Length > 0. else 'open' 138 obj.addProperty("App::PropertyString", "WDx", "Beam", 139 "Waist distance X").WDx = str(beam.DWx) + 'm' 140 obj.addProperty("App::PropertyString", "WDy", "Beam", 141 "Waist distance Y").WDy = str(beam.DWy) + 'm' 142 obj.addProperty("App::PropertyString", "Wx", "Beam", 143 "Waist on X").Wx = str(beam.Wx/0.001) + 'mm' 144 obj.addProperty("App::PropertyString", "Wy", "Beam", 145 "Waist on Y").Wy = str(beam.Wy/0.001) + 'mm' 146 147 #origin 148 obj.addProperty("App::PropertyString", "OriginOptic", "Origin", 149 "Origin Optic").OriginOptic = beam.Optic 150 obj.addProperty("App::PropertyString", "OriginFace", "Origin", 151 "Origin Face").OriginFace = beam.Face 152 obj.addProperty("App::PropertyString", "IWx", "Origin", 153 "Origin width on X").IWx = str(beam.IWx/0.001) + 'mm' 154 obj.addProperty("App::PropertyString", "IWy", "Origin", 155 "Origin width on Y").IWy = str(beam.IWy/0.001) + 'mm' 156 157 #target 158 obj.addProperty("App::PropertyString", "TargetOptic", "Target", 159 "Target Optic").TargetOptic = beam.TargetOptic \ 160 if beam.TargetOptic is not None else 'open' 161 obj.addProperty("App::PropertyString", "TargetFace", "Target", 162 "Target Face").TargetFace = beam.TargetFace \ 163 if beam.TargetFace is not None else 'open' 164 obj.addProperty("App::PropertyString", "TWx", "Target", 165 "Target width on X").TWx = str(beam.TWx/0.001) + 'mm'\ 166 if beam.TWx is not None else 'open' 167 obj.addProperty("App::PropertyString", "TWy", "Target", 168 "Target width on Y").TWy = str(beam.TWy/0.001) + 'mm'\ 169 if beam.TWy is not None else 'open' 170 171 #placement 172 obj.Placement.Base = Base.Vector(tuple(beam.Pos/self.fact))
173