def __init__(self, obj, nr=6, na=6, distribution="polar", wavelength=633, D=5, enabled=True): WBPart.__init__(self, obj, "RaysPar", enabled) obj.addProperty("App::PropertyIntegerConstraint", "nr", "Shape", "Number of rays (radial)").nr = (0, 0, 10000, 1) obj.addProperty("App::PropertyIntegerConstraint", "na", "Shape", "Number of rays (angular)").na = (0, 0, 10000, 1) obj.addProperty("App::PropertyString", "distribution", "Options", "Ray distribution (Polar for the moment)") obj.addProperty("App::PropertyLength", "wl", "Options", "Wavelength of the source") obj.addProperty("App::PropertyLength", "D", "Shape", "Ray Source Diameter") #obj.addProperty("App::PropertyVector","axis","","Direction of propagation") obj.nr = nr obj.na = na obj.distribution = distribution.lower() obj.wl = Units.Quantity( "{} nm".format(wavelength)) # wavelength is received in nm obj.D = D obj.enabled = enabled r, g, b = wavelength2RGB(obj.wl.getValueAs("µm").Value) obj.ViewObject.ShapeColor = (r, g, b, 0.0)
def __init__(self, obj, nr=6, na=6, distribution="polar", wavelength=633, angle=30, enabled=True): WBPart.__init__(self, obj, "RaysPoint") obj.Proxy = self obj.addProperty("App::PropertyIntegerConstraint", "nr", "Shape", "Number of rays (radial)").nr = (0, 0, 10000, 1) obj.addProperty("App::PropertyIntegerConstraint", "na", "Shape", "Number of rays (angular)").na = (0, 0, 10000, 1) obj.addProperty("App::PropertyString", "distribution", "Options", "Ray distribution (Polar for the moment)") obj.addProperty("App::PropertyLength", "wl", "Options", "Wavelength of the source") obj.addProperty("App::PropertyAngle", "angle", "Shape", "Source subtended angle") obj.nr = nr obj.na = na obj.distribution = distribution.lower() obj.wl = Units.Quantity( "{} nm".format(wavelength)) # wavelength is received in nm obj.angle = angle obj.enabled = enabled r, g, b = wavelength2RGB(obj.wl.getValueAs("µm").Value) obj.ViewObject.ShapeColor = (r, g, b, 0.0)
def Activated(self): myObj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "PROP") PP = PropagatePart(myObj) myObj.ViewObject.Proxy = 0 doc = FreeCAD.activeDocument() #Se agrupan los rayos para poder eliminarlos facil grp = doc.addObject("App::DocumentObjectGroup", "Rays") llines = [] #Crear un diccionario para agrupar los rayos por longitud de onda raydict = {} for ray in PP.S.prop_ray: #lines = Part.Wire(get_prop_shape(ray)) llines = get_prop_shape(ray) wl = ray.wavelength raydict[wl] = llines + raydict.get(wl, []) for wl in raydict.keys(): lines = Part.makeCompound(raydict[wl]) myObj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "Ray") myObj.Shape = lines r, g, b = wavelength2RGB(wl) myObj.ViewObject.LineColor = (r, g, b, 0.) myObj.ViewObject.Proxy = 0 grp.addObject(myObj) FreeCAD.ActiveDocument.recompute() FreeCAD.ActiveDocument.recompute()
def __init__(self, obj, Sx=5, Sy=5, Nx=5, Ny=5, nr=6, na=6, angle=10, distribution="polar", wavelength=633, enabled=True): WBPart.__init__(self, obj, "RaysArray", enabled) obj.addProperty("App::PropertyInteger", "nr").nr = nr obj.addProperty("App::PropertyInteger", "na").na = na obj.addProperty("App::PropertyFloat", "angle").angle = angle obj.addProperty("App::PropertyString", "distribution").distribution = distribution obj.addProperty("App::PropertyFloat", "wavelength").wavelength = wavelength obj.addProperty("App::PropertyFloat", "xSize").xSize = Sx obj.addProperty("App::PropertyFloat", "ySize").ySize = Sy obj.addProperty("App::PropertyInteger", "Nx").Nx = Nx obj.addProperty("App::PropertyInteger", "Ny").Ny = Ny r, g, b = wavelength2RGB(wavelength / 1000.) obj.ViewObject.ShapeColor = (r, g, b, 0.)
def propertyChanged(self, obj, prop): # To keep all the housekeeping that WBPart do, this method replaces # the standard onChanged if prop == "wavelenght": r,g,b = wavelength2RGB(obj.wavelenght/1000.) obj.ViewObject.ShapeColor = (r,g,b,0.)
def propertyChanged(self, obj, prop): # To keep all the housekeeping that WBPart do, this method replaces # the standard onChanged if prop == "wl": r, g, b = wavelength2RGB(obj.wl.getValueAs("µm").Value) obj.ViewObject.ShapeColor = (r, g, b, 0.0)
def __init__(self, obj, wavelength=633, enabled=True): WBPart.__init__(self, obj, "Ray") obj.Proxy = self obj.addProperty("App::PropertyLength", "wl", "Options", "Wavelength of the source") # wavelength is received in nm obj.wl = Units.Quantity("{} nm".format(wavelength)) obj.enabled = enabled r, g, b = wavelength2RGB(obj.wl.getValueAs("µm").Value) obj.ViewObject.ShapeColor = (r, g, b, 0.0)
def execute(self, obj): raydict = {} raylist = [] colorlist = [] for ray in self.S.prop_ray: llines = get_prop_shape(ray) wl = ray.wavelength raydict[wl] = llines + raydict.get(wl, []) raylist = raylist + llines r, g, b = wavelength2RGB(wl) colorlist = colorlist + [(r, g, b, 0.)] * len(llines) lines = Part.makeCompound(raylist) obj.Shape = lines obj.ViewObject.LineColorArray = colorlist obj.ViewObject.Proxy = 0 # this is mandatory unless we code the ViewProvider too