pythonCascade Sample Problems

self.Initialize()
if self.NbActiveLights >=
self.myGraphicDriver.InquireLightLimit():
print "You have reached the
limit number of active lights :" +
`self.myGraphicDriver.InquireLightLimit()`
print "Clear lights to create
new ones."
return
self.myCurrentMode = CurAction3d_BeginSpotLight
sb =
self.frame.GetStatusBar().SetStatusText("Pick the light position")
#
in OnLeftButtonEvent
elif self.myCurrentMode ==
CurAction3d_BeginSpotLight:
x,y = self.ConvertEventCoords(event)
self.p1 =
self.ConvertClickToPoint(x,y,self.view)
self.myCurrent_SpotLight =
V3d_SpotLight(self.viewer,0.,0.,1.,
self.p1.X(),self.p1.Y(),self.p1.Z(),Quantity_NOC_RED)
self.view.SetLightOn(self.myCurrent_SpotLight)
self.NbActiveLights =
self.NbActiveLights + 1
self.p2 =
gp_Pnt(self.p1.X(),self.p1.Y(),self.p1.Z()+1.)
coneHeigth=self.p1.Distance(self.p2)
MakeCone = BRepPrimAPI_MakeCone(gp_Ax2(self.p1,
gp_Dir(gp_Vec(self.p1, self.p2))), 0,
(self.p1.Distance(self.p2))/math.tan(1.04), coneHeigth)
self.spotConeShape =
AIS_Shape(TopoDS_Solid())
self.spotConeShape.Set(MakeCone.Shape())
self.interactive_context.Display(self.spotConeShape,1);
self.frame.GetStatusBar().SetStatusText("Pick the target
point")
self.myCurrentMode =
CurAction3d_TargetSpotLight
elif self.myCurrentMode ==
CurAction3d_TargetSpotLight:
x,y =
self.ConvertEventCoords(event)
self.p2 =
self.ConvertClickToPoint(x,y,self.view)
self.frame.GetStatusBar().SetStatusText("Pick a third point (to
define the angle)")
self.myCurrentMode =
CurAction3d_EndSpotLight
elif self.myCurrentMode ==
CurAction3d_EndSpotLight:
self.frame.GetStatusBar().SetStatusText("Ready")
self.myCurrentMode =
CurAction3d_Nothing
self.interactive_context.Erase(self.spotConeShape,1,0)
#
in mouse move
if self.myCurrentMode ==
CurAction3d_TargetSpotLight :
x,y =
self.ConvertEventCoords(event)
self.p2 =
self.ConvertClickToPoint(x,y,self.view)
coneHeigth =
self.p1.Distance(self.p2)
if coneHeigth >
Precision.Confusion():
MakeCone =
BRepPrimAPI_MakeCone(gp_Ax2(self.p1, gp_Dir(gp_Vec(self.p1, self.p2))), 0,
(self.p1.Distance(self.p2))/math.tan(1.04), coneHeigth)
self.spotConeShape.Set(MakeCone.Shape())
self.interactive_context.Redisplay(self.spotConeShape,1,0)
self.myCurrent_SpotLight.SetDirection(self.p2.X()-self.p1.X(),self.p2.Y()-self.p1.Y(),self.p2.Z()-self.p1.Z())
self.view.UpdateLights()
elif self.myCurrentMode ==
CurAction3d_EndSpotLight :
x,y =
self.ConvertEventCoords(event)
self.p3 =
self.ConvertClickToPoint(x,y,self.view)
coneHeigth =
self.p1.Distance(self.p2)
if self.p2.Distance(self.p3)
> Precision.Confusion():
MakeCone = BRepPrimAPI_MakeCone(gp_Ax2(self.p1, gp_Dir(gp_Vec(self.p1,
self.p2))), 0, self.p2.Distance(self.p3), coneHeigth)
self.spotConeShape.Set(MakeCone.Shape())
self.interactive_context.Redisplay(self.spotConeShape,1,0)
self.myCurrent_SpotLight.SetAngle(math.atan(self.p2.Distance(self.p3)/self.p1.Distance(self.p2)))
self.view.UpdateLights()