2 // Created: Wed Aug 2 16:20:31 1995
3 // Author: Arnaud BOUZY/Odile Olivier
6 #define GER61351 //GG_171199 Enable to set an object RGB color
7 // instead a restricted object NameOfColor.
9 #include <AIS_Plane.ixx>
11 #include <TColgp_Array1OfPnt.hxx>
12 #include <TColgp_HArray1OfPnt.hxx>
14 #include <Precision.hxx>
18 #include <Graphic3d_Array1OfVertex.hxx>
19 #include <Graphic3d_Group.hxx>
20 #include <Prs3d_Drawer.hxx>
21 #include <Prs3d_LineAspect.hxx>
22 #include <Prs3d_PlaneAspect.hxx>
23 #include <Prs3d_DatumAspect.hxx>
24 #include <Prs3d_ShadingAspect.hxx>
25 #include <StdPrs_Plane.hxx>
26 #include <StdPrs_ShadedSurface.hxx>
28 #include <Geom_Plane.hxx>
29 #include <GeomAdaptor_Surface.hxx>
31 #include <Aspect_TypeOfLine.hxx>
32 #include <Graphic3d_AspectLine3d.hxx>
33 #include <Graphic3d_Structure.hxx>
34 #include <Graphic3d_MaterialAspect.hxx>
35 #include <Graphic3d_AspectFillArea3d.hxx>
37 #include <DsgPrs_XYZPlanePresentation.hxx>
38 #include <DsgPrs_ShadedPlanePresentation.hxx>
39 #include <UnitsAPI.hxx>
41 #include <SelectBasics_EntityOwner.hxx>
42 #include <SelectMgr_EntityOwner.hxx>
43 #include <Select3D_SensitiveFace.hxx>
44 #include <StdPrs_ShadedShape.hxx>
46 #include <AIS_Drawer.hxx>
48 #include <TCollection_AsciiString.hxx>
50 //=======================================================================
51 //function : AIS_Plane
53 //=======================================================================
54 AIS_Plane::AIS_Plane(const Handle(Geom_Plane)& aComponent,
55 const Standard_Boolean aCurrentMode):
56 myComponent(aComponent),
57 myCenter(gp_Pnt(0.,0.,0.)),
58 myCurrentMode(aCurrentMode),
59 myAutomaticPosition(Standard_True),
60 myTypeOfPlane(AIS_TOPL_Unknown),
61 myIsXYZPlane(Standard_False)
63 InitDrawerAttributes();
66 //=======================================================================
67 //function : AIS_Plane
68 //purpose : avec une position
69 //=======================================================================
70 AIS_Plane::AIS_Plane(const Handle(Geom_Plane)& aComponent,
71 const gp_Pnt& aCenter,
72 const Standard_Boolean aCurrentMode):
73 myComponent(aComponent),
75 myCurrentMode(aCurrentMode),
76 myAutomaticPosition(Standard_True),
77 myTypeOfPlane(AIS_TOPL_Unknown),
78 myIsXYZPlane(Standard_False)
80 InitDrawerAttributes();
83 //=======================================================================
84 //function : AIS_Plane
86 //=======================================================================
87 AIS_Plane::AIS_Plane(const Handle(Geom_Plane)& aComponent,
88 const gp_Pnt& aCenter,
91 const Standard_Boolean aCurrentMode):
92 myComponent(aComponent),
96 myCurrentMode(aCurrentMode),
97 myAutomaticPosition(Standard_False),
98 myTypeOfPlane(AIS_TOPL_Unknown),
99 myIsXYZPlane(Standard_False)
101 InitDrawerAttributes();
105 //=======================================================================
106 //function : AIS_Plane
107 //purpose : XYPlane, XZPlane, YZPlane
108 //=======================================================================
109 AIS_Plane::AIS_Plane(const Handle(Geom_Axis2Placement)& aComponent,
110 const AIS_TypeOfPlane aPlaneType,
111 const Standard_Boolean aCurrentMode):
113 myCurrentMode(aCurrentMode),
114 myAutomaticPosition(Standard_True),
115 myTypeOfPlane(aPlaneType),
116 myIsXYZPlane(Standard_True)
118 InitDrawerAttributes();
125 //=======================================================================
126 //function : SetComponent
128 //=======================================================================
130 void AIS_Plane::SetComponent(const Handle(Geom_Plane)& aComponent)
132 myComponent = aComponent;
133 myTypeOfPlane = AIS_TOPL_Unknown;
134 myIsXYZPlane = Standard_False;
135 //myCenter = gp_Pnt(0.,0.,0.);
136 myAutomaticPosition = Standard_True;
139 //=======================================================================
142 //=======================================================================
144 AIS_KindOfInteractive AIS_Plane::Type() const
145 {return AIS_KOI_Datum;}
148 //=======================================================================
149 //function : Signature
151 //=======================================================================
153 Standard_Integer AIS_Plane::Signature() const
157 //=======================================================================
158 //function : Axis2Placement
160 //=======================================================================
162 Handle(Geom_Axis2Placement) AIS_Plane::Axis2Placement()
164 Handle(Geom_Axis2Placement) Bid;
165 return IsXYZPlane() ? myAx2:Bid;
167 //=======================================================================
168 //function : SetAxis2Placement
170 //=======================================================================
172 void AIS_Plane::SetAxis2Placement(const Handle(Geom_Axis2Placement)& aComponent,
173 const AIS_TypeOfPlane aPlaneType)
175 myTypeOfPlane = aPlaneType;
176 myIsXYZPlane = Standard_True;
178 myAutomaticPosition = Standard_True;
182 //=======================================================================
183 //function : PlaneAttributes
185 //=======================================================================
186 Standard_Boolean AIS_Plane::PlaneAttributes(Handle(Geom_Plane)& aComponent,
191 Standard_Boolean aStatus (Standard_False);
192 if (!myAutomaticPosition){
193 aComponent = myComponent;
197 aStatus = Standard_True;
202 //=======================================================================
203 //function : SetPlaneAttributes
205 //=======================================================================
206 void AIS_Plane::SetPlaneAttributes(const Handle(Geom_Plane)& aComponent,
207 const gp_Pnt& aCenter,
211 myAutomaticPosition = Standard_False;
212 myComponent = aComponent;
216 myTypeOfPlane = AIS_TOPL_Unknown;
217 myIsXYZPlane = Standard_False;
220 //=======================================================================
223 //=======================================================================
224 void AIS_Plane::Compute(const Handle(PrsMgr_PresentationManager3d)& ,
225 const Handle(Prs3d_Presentation)& aPresentation,
226 const Standard_Integer aMode)
228 aPresentation->Clear();
231 aPresentation->SetInfiniteState(myInfiniteState);
233 myDrawer->PlaneAspect()->EdgesAspect()->SetWidth(3);
235 myDrawer->PlaneAspect()->EdgesAspect()->SetWidth(1);
239 const Handle(Geom_Plane)& pl = myComponent;
240 const Handle(Geom_Plane)& thegoodpl = Handle(Geom_Plane)::DownCast
241 (pl->Translated(pl->Location(),myCenter));
242 GeomAdaptor_Surface surf(thegoodpl);
243 StdPrs_Plane::Add(aPresentation,surf,myDrawer);
246 DsgPrs_XYZPlanePresentation::Add(aPresentation,myDrawer,myCenter,myPmin,myPmax);
249 else if (aMode == 1){
252 Handle(Prs3d_PlaneAspect) theaspect = myDrawer->PlaneAspect();
253 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
255 Standard_Real Xmax,Ymax;
256 Xmax = Standard_Real(theaspect->PlaneXLength())/2.;
257 Ymax = Standard_Real(theaspect->PlaneYLength())/2.;
258 static Graphic3d_Array1OfVertex vertices(1,5);
259 TheGroup->SetPrimitivesAspect(myDrawer->ShadingAspect()->Aspect());
260 myComponent->D0(-Xmax,Ymax,p1);
261 vertices(1).SetCoord(p1.X(),p1.Y(),p1.Z());
262 vertices(5).SetCoord(p1.X(),p1.Y(),p1.Z());
263 myComponent->D0(Xmax,Ymax,p1);
264 vertices(2).SetCoord(p1.X(),p1.Y(),p1.Z());
265 myComponent->D0(Xmax,-Ymax,p1);
266 vertices(3).SetCoord(p1.X(),p1.Y(),p1.Z());
267 myComponent->D0(-Xmax,-Ymax,p1);
268 vertices(4).SetCoord(p1.X(),p1.Y(),p1.Z());
269 TheGroup->Polygon(vertices);
273 DsgPrs_ShadedPlanePresentation::Add(aPresentation,myDrawer,myCenter,myPmin,myPmax);
280 void AIS_Plane::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
282 // Standard_NotImplemented::Raise("AIS_Plane::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
283 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
286 //=======================================================================
287 //function : ComputeSelection
289 //=======================================================================
290 void AIS_Plane::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
291 const Standard_Integer)
294 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,10);
295 Handle(Select3D_SensitiveFace) sfac;
299 Handle(TColgp_HArray1OfPnt) harr = new TColgp_HArray1OfPnt(1,5);
300 TColgp_Array1OfPnt& arr = harr->ChangeArray1();
301 Standard_Real lx = myDrawer->PlaneAspect()->PlaneXLength()/2.;
302 Standard_Real ly = myDrawer->PlaneAspect()->PlaneYLength()/2.;
303 const Handle(Geom_Plane)& pl = myComponent;
304 const Handle(Geom_Plane)& thegoodpl = Handle(Geom_Plane)::DownCast(pl->Translated(pl->Location(),myCenter));
306 thegoodpl->D0(lx,ly,arr(1));
307 thegoodpl->D0(lx,-ly,arr(2));
308 thegoodpl->D0(-lx,-ly,arr(3));
309 thegoodpl->D0(-lx,ly,arr(4));
311 sfac = new Select3D_SensitiveFace(eown,harr,Select3D_TOS_BOUNDARY);
315 Handle(TColgp_HArray1OfPnt) harr1 = new TColgp_HArray1OfPnt(1,4);
316 TColgp_Array1OfPnt& arr1 = harr1->ChangeArray1();
322 sfac = new Select3D_SensitiveFace(eown,harr1,Select3D_TOS_BOUNDARY);
325 aSelection->Add(sfac);
331 //=======================================================================
334 //=======================================================================
335 void AIS_Plane::SetSize(const Standard_Real aLength)
337 SetSize(aLength,aLength);
340 void AIS_Plane::SetSize(const Standard_Real aXLength,
341 const Standard_Real aYLength)
343 //if the plane already has a proper color or size,
344 //there is already a specific PlaneAspect and DatumAspect
346 Handle(Prs3d_PlaneAspect) PA;
347 Handle(Prs3d_DatumAspect) DA;
349 PA = myDrawer->PlaneAspect();
350 DA = myDrawer->DatumAspect();
352 Standard_Boolean yenavaitPA(Standard_True),yenavaitDA(Standard_True);
353 if(myDrawer->Link()->PlaneAspect() == PA){
354 yenavaitPA = Standard_False;
355 PA = new Prs3d_PlaneAspect();}
356 if(myDrawer->Link()->DatumAspect() == DA){
357 yenavaitDA = Standard_False;
358 DA = new Prs3d_DatumAspect();
361 PA->SetPlaneLength(aXLength,aYLength);
362 DA->SetAxisLength(aXLength,aYLength,aXLength);
365 myDrawer->SetPlaneAspect(PA);
367 myDrawer->SetDatumAspect(DA);
370 myHasOwnSize = Standard_True;
376 //=======================================================================
377 //function : UnsetSize
378 //purpose : If there is a color, the size is restaured from the drawer of the context...
379 //=======================================================================
380 void AIS_Plane::UnsetSize()
383 if(!myHasOwnSize) return;
385 myDrawer->PlaneAspect().Nullify();
386 myDrawer->DatumAspect().Nullify();
389 const Handle(Prs3d_PlaneAspect)& PA = myDrawer->Link()->PlaneAspect();
390 const Handle(Prs3d_DatumAspect)& DA = myDrawer->Link()->DatumAspect();
392 myDrawer->PlaneAspect()->SetPlaneLength(PA->PlaneXLength(),PA->PlaneYLength());
393 myDrawer->DatumAspect()->SetAxisLength(DA->FirstAxisLength(),
394 DA->SecondAxisLength(),
395 DA->ThirdAxisLength());
398 myHasOwnSize = Standard_False;
404 //=======================================================================
407 //=======================================================================
409 Standard_Boolean AIS_Plane::Size(Standard_Real& X,Standard_Real& Y) const
411 X = myDrawer->PlaneAspect()->PlaneXLength();
412 Y = myDrawer->PlaneAspect()->PlaneYLength();
413 return Abs(X-Y)<=Precision::Confusion();
417 //=======================================================================
418 //function : SetColor
420 //=======================================================================
423 void AIS_Plane::SetColor(const Quantity_NameOfColor aCol)
426 SetColor(Quantity_Color(aCol));
429 void AIS_Plane::SetColor(const Quantity_Color &aCol)
432 // if the plane already has its proper size, there is an already created planeaspect
433 // Standard_Boolean yenadeja = hasOwnColor || myHasOwnSize;
434 Handle(Prs3d_PlaneAspect) PA;
435 Handle(Prs3d_DatumAspect) DA;
437 PA = myDrawer->PlaneAspect();
438 DA = myDrawer->DatumAspect();
440 Standard_Boolean yenavaitPA(Standard_True),yenavaitDA(Standard_True);
441 if(myDrawer->Link()->PlaneAspect() == PA){
442 yenavaitPA = Standard_False;
443 PA = new Prs3d_PlaneAspect();}
444 if(myDrawer->Link()->DatumAspect() == DA){
445 yenavaitDA = Standard_False;
446 DA = new Prs3d_DatumAspect();
449 PA->EdgesAspect()->SetColor(aCol);
450 DA->FirstAxisAspect()->SetColor(aCol);
451 DA->SecondAxisAspect()->SetColor(aCol);
452 DA->ThirdAxisAspect()->SetColor(aCol);
455 myDrawer->SetPlaneAspect(PA);
457 myDrawer->SetDatumAspect(DA);
459 myDrawer->ShadingAspect()->SetColor(aCol);
461 hasOwnColor=Standard_True;
464 //=======================================================================
465 //function : SetColor
467 //=======================================================================
468 void AIS_Plane::UnsetColor()
470 if(!hasOwnColor) return;
472 myDrawer->PlaneAspect().Nullify();
473 myDrawer->DatumAspect().Nullify();
476 const Handle(Prs3d_PlaneAspect)& PA = myDrawer->Link()->PlaneAspect();
477 // const Handle(Prs3d_DatumAspect)& DA = myDrawer->Link()->DatumAspect();
478 Quantity_Color C;Aspect_TypeOfLine T;Standard_Real W;
479 PA->EdgesAspect()->Aspect()->Values(C,T,W);
480 Quantity_NameOfColor Col = C.Name();
481 myDrawer->PlaneAspect()->EdgesAspect()->SetColor(Col);
483 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(Col);
484 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(Col);
485 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(Col);
489 hasOwnColor=Standard_False;
493 //=======================================================================
494 //function : ComputeFrame
496 //=======================================================================
497 void AIS_Plane::ComputeFrame()
500 const Handle(Geom_Plane)& pl = myComponent;
503 if (myAutomaticPosition) {
504 ElSLib::Parameters(pl->Pln(),myCenter,U,V);
505 pl->D0 (U, V, myCenter);
508 const Handle(Geom_Plane)& thegoodpl =
509 Handle(Geom_Plane)::DownCast(pl->Translated(pl->Location(),myCenter));
510 ElSLib::Parameters(thegoodpl->Pln(),myPmin,U,V);
514 if (U < 10*Precision::Confusion()) U=0.1;
515 if (V < 10*Precision::Confusion()) V=0.1;
517 myDrawer->PlaneAspect()->SetPlaneLength(U,V);
521 //=======================================================================
523 //purpose : to avoid warning
524 //=======================================================================
525 void AIS_Plane::Compute(const Handle(PrsMgr_PresentationManager2d)&,
526 const Handle(Graphic2d_GraphicObject)&,
527 const Standard_Integer)
531 //=======================================================================
533 //purpose : to avoid warning
534 //=======================================================================
535 void AIS_Plane::Compute(const Handle(Prs3d_Projector)&,
536 const Handle(Prs3d_Presentation)&)
540 //=======================================================================
541 //function : ComputeFields
543 //=======================================================================
544 void AIS_Plane::ComputeFields()
547 Handle (Prs3d_DatumAspect) DA = myDrawer->DatumAspect();
549 gp_Pnt Orig = myAx2->Ax2().Location();
550 gp_Dir oX = myAx2->Ax2().XDirection();
551 gp_Dir oY = myAx2->Ax2().YDirection();
552 gp_Dir oZ = myAx2->Ax2().Direction();
554 Standard_Real xo,yo,zo,x1,y1,z1,x2,y2,z2,x3,y3,z3,x4=0,y4=0,z4=0;
555 Standard_Real x5=0,y5=0,z5=0;
556 Orig.Coord(xo,yo,zo);
560 Standard_Real DS1 = DA->FirstAxisLength();
561 Standard_Real DS2 = DA->SecondAxisLength();
562 Standard_Real DS3 = DA->ThirdAxisLength();
565 switch (myTypeOfPlane) {
566 case AIS_TOPL_XYPlane:
569 myComponent = new Geom_Plane(XYP);
570 x4=xo+x1*DS1; y4=yo+y1*DS1; z4=zo+z1*DS1;
571 x5=xo+x2*DS2; y5=yo+y2*DS2; z5=zo+z2*DS2;
574 case AIS_TOPL_XZPlane:
577 myComponent = new Geom_Plane(XZP);
578 x4=xo+x1*DS1; y4=yo+y1*DS1; z4=zo+z1*DS1;
579 x5=xo+x3*DS3; y5=yo+y3*DS3; z5=zo+z3*DS3;
582 case AIS_TOPL_YZPlane:
585 myComponent = new Geom_Plane(XZP);
586 x4=xo+x2*DS2; y4=yo+y2*DS2; z4=zo+z2*DS2;
587 x5=xo+x3*DS3; y5=yo+y3*DS3; z5=zo+z3*DS3;
593 myPmin.SetCoord(x4,y4,z4);
594 myPmax.SetCoord(x5,y5,z5);
598 //=======================================================================
599 //function : InitDrawerAttributes
601 //=======================================================================
603 void AIS_Plane::InitDrawerAttributes()
606 Handle(Prs3d_ShadingAspect) shasp = new Prs3d_ShadingAspect();
607 shasp->SetMaterial(Graphic3d_NOM_PLASTIC);
608 shasp->SetColor(Quantity_NOC_GRAY40);
609 myDrawer->SetShadingAspect(shasp);
610 Handle(Graphic3d_AspectFillArea3d) asf = shasp->Aspect();
611 Graphic3d_MaterialAspect asp = asf->FrontMaterial();
612 asp.SetTransparency(0.8);
613 asf->SetFrontMaterial(asp);
614 asf->SetBackMaterial(asp);
619 //=======================================================================
620 //function : AcceptDisplayMode
622 //=======================================================================
624 Standard_Boolean AIS_Plane::
625 AcceptDisplayMode(const Standard_Integer aMode) const
629 //=======================================================================
630 //function : SetContext
632 //=======================================================================
634 void AIS_Plane::SetContext(const Handle(AIS_InteractiveContext)& Ctx)
636 AIS_InteractiveObject::SetContext(Ctx);