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

Source Code for Module theia.rendering.writer

 1  '''Writer module for theia, to write CAD content to files.''' 
 2   
 3  # Provides: 
 4  #   writeToCAD 
 5  #   writeTree 
 6   
 7  from FreeCAD import Base 
 8  import Part 
 9  from ..helpers import settings 
10  from ..helpers.tools import shortRef 
11  from .features import FCMirror, FCBeamSplitter, FCLens, FCBeamDump, FCBeam 
12  from .features import FCSpecial 
13   
14 -def writeToCAD(component, doc):
15 '''Write the relevant FreeCAD objects of components in CAD file. 16 17 This function is for everything except for beams. 18 To the doc .fcstd file are added one object per optic and beam, they 19 are of type Part::FeaturePython to allow for shapes and features. 20 21 The important functions are the PythonFeatures 22 constructors found in features, and the shape functions found in shapes. 23 24 component: component to represent. [Mirror, Lens, BeamDump, Ghost, Beam] 25 doc: CAD file to write to. [CAD file] 26 27 No return value. 28 29 ''' 30 31 # here are some dics to refer to the right features and shapes for all 32 # components 33 fact = settings.FCFactor #factor for units in CAD 34 FCDic = {'Mirror': FCMirror, 35 'ThickLens': FCLens, 36 'ThinLens': FCLens, 37 'BeamDump': FCBeamDump, 38 'BeamSplitter': FCBeamSplitter, 39 'Special': FCSpecial} 40 41 #First take care of optics 42 if component.Name in ['Mirror', 'ThickLens', 'ThinLens', 'BeamDump', 43 'BeamSplitter', 'Special']: 44 FCDic[component.Name](doc.addObject("Part::FeaturePython", 45 component.Ref), component) 46 47 # Then tree (call write tree function) 48 if component.Name == 'BeamTree': 49 writeTree(component, doc)
50
51 -def writeTree(tree, doc):
52 '''Recursively write the shape and feature content of the beams of a tree. 53 54 If the tree's root is not None, write the shape and feature for tree.Root 55 and start over for the daughter trees. 56 57 tree: beamtree to write the info. [BeamTree] 58 doc: CAD file to write to. [CAD file] 59 60 No return value. 61 62 ''' 63 fact = settings.FCFactor #factor for units in CAD 64 65 if tree.Root is not None: 66 # write FreeCAD object of beam according to short option 67 if tree.Root.N == 1. or not settings.short: 68 FCBeam(doc.addObject("Part::FeaturePython", tree.Root.Ref\ 69 if not settings.short else shortRef(tree.Root.Ref)), tree.Root) 70 71 # add laser object if input beam 72 if 't' not in tree.Root.Ref and 'r' not in tree.Root.Ref: 73 laserObj = doc.addObject("Part::FeaturePython", 'laser') 74 laserObj.Shape = Part.makeCylinder(0.01/fact, 0.1/fact, 75 Base.Vector(0,0,0), 76 Base.Vector(tuple(-tree.Root.Dir))) 77 laserObj.Placement.Base = Base.Vector(tuple(tree.Root.Pos/fact)) 78 79 #recursively for daughter beams 80 if tree.T is not None: 81 writeTree(tree.T, doc) 82 if tree.R is not None: 83 writeTree(tree.R, doc)
84