Skip to content

Commit

Permalink
A fix in a bug in rect mirror, and a fix in a bux in rayspoint
Browse files Browse the repository at this point in the history
fixes: #6
  • Loading branch information
ramezquitao committed Aug 3, 2017
1 parent 6284cc8 commit 8f98123
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 52 deletions.
33 changes: 17 additions & 16 deletions pyOpToolsWB/raysparallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from wbcommand import *
from pyoptools.misc.pmisc.misc import wavelength2RGB
import pyoptools.raytrace.ray.ray_source as rs_lib
from Units import Quantity
from math import radians

class RaysParallelGUI(WBCommandGUI):
def __init__(self):
Expand All @@ -13,11 +15,11 @@ def accept(self):
Y=self.form.Oy.value()
Z=self.form.Oz.value()

Dx = self.form.Dx.value()
Dy = self.form.Dy.value()
Dz = self.form.Dz.value()
Xrot = self.form.Xrot.value()
Yrot = self.form.Yrot.value()
Zrot = self.form.Zrot.value()


axis = FreeCAD.Vector(Dx,Dy,Dz)

nr = self.form.nr.value()
na = self.form.na.value()
Expand All @@ -28,12 +30,12 @@ def accept(self):
D = self.form.D.value()
m=FreeCAD.Matrix()

#m.rotateX(radians(Ox))
#m.rotateY(radians(Oy))
#m.rotateZ(radians(Oz))
m.rotateX(radians(Xrot))
m.rotateY(radians(Yrot))
m.rotateZ(radians(Zrot))

m.move((X,Y,Z))
obj=InsertRPar(nr,na, distribution,wavelenght,D,axis,"S",enabled)
obj=InsertRPar(nr,na, distribution,wavelenght,D,"S",enabled)

p1 = FreeCAD.Placement(m)
obj.Placement = p1
Expand All @@ -54,23 +56,22 @@ def GetResources(self):


class RaysParPart(WBPart):
def __init__(self,obj,nr=6,na=6,distribution="polar",wavelenght=633, D=5,axis=FreeCAD.Vector((0,0,1)),enabled=True):
def __init__(self,obj,nr=6,na=6,distribution="polar",wavelenght=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.addProperty("App::PropertyVector","axis","","Direction of propagation")

obj.nr=nr
obj.na=na
obj.distribution=distribution.lower()
obj.wl = Quantity("{} nm".format(wavelenght)) # wavelenght is received in nm

obj.D = D
obj.axis = axis
obj.enabled=enabled
r,g,b = wavelength2RGB(obj.wl.getValueAs("µm").Value)

Expand All @@ -93,16 +94,16 @@ def propertyChanged(self, obj, prop):

def pyoptools_repr(self,obj):
X,Y,Z = obj.Placement.Base
RZ,RY,RX = obj.Placement.Rotation.toEuler()
dist=obj.distribution
nr=obj.nr
na=obj.na
wl=obj.wl.getValueAs("µm").Value
R=obj.D/2.
DX,DY,DZ=obj.axis
r=[]
if obj.enabled:
if dist=="polar":
r=rs_lib.parallel_beam_p(origin=(X,Y,Z),direction=(DX,DY,DZ),
r=rs_lib.parallel_beam_p(origin=(X,Y,Z),direction=(radians(RX),radians(RY),radians(RZ)),
radius=R, num_rays=(nr,na),wavelength=wl,
label="")
elif dist=="cartesian":
Expand All @@ -126,7 +127,7 @@ def execute(self,obj):

if dist == "polar":
r=obj.D.Value/2.
d=Part.makeCylinder(r,5,FreeCAD.Vector(0,0,0),obj.axis)
d=Part.makeCylinder(r,5)
#d.translate(FreeCAD.Base.Vector(0,0,-0.5))
else: #Cartesian
#Todo: Crear una piramide en lugar de un cono
Expand All @@ -136,10 +137,10 @@ def execute(self,obj):



def InsertRPar(nr=6, na=6,distribution="polar",wavelenght=633,D=5, axis =FreeCAD.Vector((0,0,1)),ID="S",enabled = True):
def InsertRPar(nr=6, na=6,distribution="polar",wavelenght=633,D=5,ID="S",enabled = True):
import FreeCAD
myObj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",ID)
RaysParPart(myObj,nr,na,distribution,wavelenght,D,axis,enabled)
RaysParPart(myObj,nr,na,distribution,wavelenght,D,enabled)
myObj.ViewObject.Proxy = 0 # this is mandatory unless we code the ViewProvider too
FreeCAD.ActiveDocument.recompute()
return myObj
70 changes: 34 additions & 36 deletions pyOpToolsWB/rayspoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,24 @@ def accept(self):
Y=self.form.Oy.value()
Z=self.form.Oz.value()

Dx = self.form.Dx.value()
Dy = self.form.Dy.value()
Dz = self.form.Dz.value()

axis = FreeCAD.Vector(Dx,Dy,Dz)
Xrot = self.form.Xrot.value()
Yrot = self.form.Yrot.value()
Zrot = self.form.Zrot.value()

nr = self.form.nr.value()
na = self.form.na.value()
distribution = self.form.RayDistribution.currentText()
wavelenght = self.form.wavelenght.value()
angle = self.form.ang.value()
enabled = self.form.Enabled.isChecked()

m=FreeCAD.Matrix()
#m.rotateX(radians(Ox))
#m.rotateY(radians(Oy))
#m.rotateZ(radians(Oz))
m.rotateX(radians(Xrot))
m.rotateY(radians(Yrot))
m.rotateZ(radians(Zrot))

m.move((X,Y,Z))
obj=InsertRPoint(nr,na, distribution,wavelenght,angle,axis,"S",enabled)
obj=InsertRPoint(nr,na, distribution,wavelenght,angle,"S",enabled)

p1 = FreeCAD.Placement(m)
obj.Placement = p1
Expand All @@ -53,21 +52,19 @@ def GetResources(self):


class RaysPointPart(WBPart):
def __init__(self,obj,nr=6,na=6,distribution="polar",wavelenght=633, angle=30,axis=FreeCAD.Vector((0,0,1)),enabled = True):
def __init__(self,obj,nr=6,na=6,distribution="polar",wavelenght=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.addProperty("App::PropertyVector","axis","","Direction of propagation")
obj.nr=nr
obj.na=na
obj.distribution=distribution.lower()
obj.wl = Quantity("{} nm".format(wavelenght)) # wavelenght is received in nm
obj.angle = angle
obj.axis = axis
obj.enabled=enabled

r,g,b = wavelength2RGB(obj.wl.getValueAs("µm").Value)
Expand All @@ -85,26 +82,6 @@ def propertyChanged(self, obj, prop):
obj.ViewObject.ShapeColor = (r,g,b,0.)


def execute(self,obj):
import Part,FreeCAD

dist = obj.distribution.lower()


if dist not in ["polar","cartesian"]:
obj.distribution="polar"
print "Ray Distribution not understood, changing it to polar"

if dist == "polar":
print obj.angle , type(obj.angle)
r=5*tan(obj.angle.getValueAs("rad").Value)
d=Part.makeCone(0,r,5,FreeCAD.Vector(0,0,0),obj.axis)
#d.translate(FreeCAD.Base.Vector(0,0,-0.5))
else: #Cartesian
#Todo: Crear una piramide en lugar de un cono
d=Part.makeCone(0,10,10,dir)
d.translate(FreeCAD.Base.Vector(0,0,-0.5))
obj.Shape = d

def pyoptools_repr(self,obj):
dist=obj.distribution
Expand All @@ -113,11 +90,11 @@ def pyoptools_repr(self,obj):
wl=obj.wl.getValueAs("µm").Value
ang=obj.angle.getValueAs("rad").Value

DX,DY,DZ=obj.axis
X,Y,Z = obj.Placement.Base
RZ,RY,RX = obj.Placement.Rotation.toEuler()

if dist=="polar":
r=rs_lib.point_source_p(origin=(X,Y,Z),direction=(DX,DY,DZ),span=ang,
r=rs_lib.point_source_p(origin=(X,Y,Z),direction=(radians(RX),radians(RY),radians(RZ)),span=ang,
num_rays=(nr,na),wavelength=wl, label="")
elif dist=="cartesian":
print "cartesian ray distribution, not implemented yet"
Expand All @@ -128,11 +105,32 @@ def pyoptools_repr(self,obj):

return r

def execute(self,obj):
import Part,FreeCAD

dist = obj.distribution.lower()


if dist not in ["polar","cartesian"]:
obj.distribution="polar"
print "Ray Distribution not understood, changing it to polar"

if dist == "polar":
print obj.angle , type(obj.angle)
r=5*tan(obj.angle.getValueAs("rad").Value)
d=Part.makeCone(0,r,5)
#d.translate(FreeCAD.Base.Vector(0,0,-0.5))
else: #Cartesian
#Todo: Crear una piramide en lugar de un cono
d=Part.makeCone(0,10,10,dir)
d.translate(FreeCAD.Base.Vector(0,0,-0.5))
obj.Shape = d


def InsertRPoint(nr=6, na=6,distribution="polar",wavelenght=633,angle=30, axis =FreeCAD.Vector((0,0,1)),ID="S", enabled = True):
def InsertRPoint(nr=6, na=6,distribution="polar",wavelenght=633,angle=30,ID="S", enabled = True):
import FreeCAD
myObj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",ID)
RaysPointPart(myObj,nr,na,distribution,wavelenght,angle,axis,enabled)
RaysPointPart(myObj,nr,na,distribution,wavelenght,angle,enabled)
myObj.ViewObject.Proxy = 0 # this is mandatory unless we code the ViewProvider too
FreeCAD.ActiveDocument.recompute()
return myObj
Expand Down

0 comments on commit 8f98123

Please sign in to comment.