1 // Created on: 1995-08-02
2 // Created by: Arnaud BOUZY/Odile Olivier
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #define GER61351 //GG_171199 Enable to set an object RGB color
23 // instead a restricted object NameOfColor.
25 #include <AIS_Plane.ixx>
27 #include <TColgp_Array1OfPnt.hxx>
28 #include <TColgp_HArray1OfPnt.hxx>
30 #include <Precision.hxx>
34 #include <Graphic3d_ArrayOfQuadrangles.hxx>
35 #include <Graphic3d_Group.hxx>
36 #include <Prs3d_Drawer.hxx>
37 #include <Prs3d_LineAspect.hxx>
38 #include <Prs3d_PlaneAspect.hxx>
39 #include <Prs3d_DatumAspect.hxx>
40 #include <Prs3d_ShadingAspect.hxx>
41 #include <StdPrs_Plane.hxx>
42 #include <StdPrs_ShadedSurface.hxx>
44 #include <Geom_Plane.hxx>
45 #include <GeomAdaptor_Surface.hxx>
47 #include <Aspect_TypeOfLine.hxx>
48 #include <Graphic3d_AspectLine3d.hxx>
49 #include <Graphic3d_Structure.hxx>
50 #include <Graphic3d_MaterialAspect.hxx>
51 #include <Graphic3d_AspectFillArea3d.hxx>
53 #include <DsgPrs_XYZPlanePresentation.hxx>
54 #include <DsgPrs_ShadedPlanePresentation.hxx>
55 #include <UnitsAPI.hxx>
57 #include <SelectBasics_EntityOwner.hxx>
58 #include <SelectMgr_EntityOwner.hxx>
59 #include <Select3D_SensitiveFace.hxx>
60 #include <StdPrs_ShadedShape.hxx>
62 #include <AIS_Drawer.hxx>
64 #include <TCollection_AsciiString.hxx>
66 //=======================================================================
67 //function : AIS_Plane
69 //=======================================================================
70 AIS_Plane::AIS_Plane(const Handle(Geom_Plane)& aComponent,
71 const Standard_Boolean aCurrentMode):
72 myComponent(aComponent),
73 myCenter(gp_Pnt(0.,0.,0.)),
74 myCurrentMode(aCurrentMode),
75 myAutomaticPosition(Standard_True),
76 myTypeOfPlane(AIS_TOPL_Unknown),
77 myIsXYZPlane(Standard_False)
79 InitDrawerAttributes();
82 //=======================================================================
83 //function : AIS_Plane
84 //purpose : avec une position
85 //=======================================================================
86 AIS_Plane::AIS_Plane(const Handle(Geom_Plane)& aComponent,
87 const gp_Pnt& aCenter,
88 const Standard_Boolean aCurrentMode):
89 myComponent(aComponent),
91 myCurrentMode(aCurrentMode),
92 myAutomaticPosition(Standard_True),
93 myTypeOfPlane(AIS_TOPL_Unknown),
94 myIsXYZPlane(Standard_False)
96 InitDrawerAttributes();
99 //=======================================================================
100 //function : AIS_Plane
102 //=======================================================================
103 AIS_Plane::AIS_Plane(const Handle(Geom_Plane)& aComponent,
104 const gp_Pnt& aCenter,
107 const Standard_Boolean aCurrentMode):
108 myComponent(aComponent),
112 myCurrentMode(aCurrentMode),
113 myAutomaticPosition(Standard_False),
114 myTypeOfPlane(AIS_TOPL_Unknown),
115 myIsXYZPlane(Standard_False)
117 InitDrawerAttributes();
121 //=======================================================================
122 //function : AIS_Plane
123 //purpose : XYPlane, XZPlane, YZPlane
124 //=======================================================================
125 AIS_Plane::AIS_Plane(const Handle(Geom_Axis2Placement)& aComponent,
126 const AIS_TypeOfPlane aPlaneType,
127 const Standard_Boolean aCurrentMode):
129 myCurrentMode(aCurrentMode),
130 myAutomaticPosition(Standard_True),
131 myTypeOfPlane(aPlaneType),
132 myIsXYZPlane(Standard_True)
134 InitDrawerAttributes();
141 //=======================================================================
142 //function : SetComponent
144 //=======================================================================
146 void AIS_Plane::SetComponent(const Handle(Geom_Plane)& aComponent)
148 myComponent = aComponent;
149 myTypeOfPlane = AIS_TOPL_Unknown;
150 myIsXYZPlane = Standard_False;
151 //myCenter = gp_Pnt(0.,0.,0.);
152 myAutomaticPosition = Standard_True;
155 //=======================================================================
158 //=======================================================================
160 AIS_KindOfInteractive AIS_Plane::Type() const
161 {return AIS_KOI_Datum;}
164 //=======================================================================
165 //function : Signature
167 //=======================================================================
169 Standard_Integer AIS_Plane::Signature() const
173 //=======================================================================
174 //function : Axis2Placement
176 //=======================================================================
178 Handle(Geom_Axis2Placement) AIS_Plane::Axis2Placement()
180 Handle(Geom_Axis2Placement) Bid;
181 return IsXYZPlane() ? myAx2:Bid;
183 //=======================================================================
184 //function : SetAxis2Placement
186 //=======================================================================
188 void AIS_Plane::SetAxis2Placement(const Handle(Geom_Axis2Placement)& aComponent,
189 const AIS_TypeOfPlane aPlaneType)
191 myTypeOfPlane = aPlaneType;
192 myIsXYZPlane = Standard_True;
194 myAutomaticPosition = Standard_True;
198 //=======================================================================
199 //function : PlaneAttributes
201 //=======================================================================
202 Standard_Boolean AIS_Plane::PlaneAttributes(Handle(Geom_Plane)& aComponent,
207 Standard_Boolean aStatus (Standard_False);
208 if (!myAutomaticPosition){
209 aComponent = myComponent;
213 aStatus = Standard_True;
218 //=======================================================================
219 //function : SetPlaneAttributes
221 //=======================================================================
222 void AIS_Plane::SetPlaneAttributes(const Handle(Geom_Plane)& aComponent,
223 const gp_Pnt& aCenter,
227 myAutomaticPosition = Standard_False;
228 myComponent = aComponent;
232 myTypeOfPlane = AIS_TOPL_Unknown;
233 myIsXYZPlane = Standard_False;
236 //=======================================================================
239 //=======================================================================
240 void AIS_Plane::Compute(const Handle(PrsMgr_PresentationManager3d)& ,
241 const Handle(Prs3d_Presentation)& aPresentation,
242 const Standard_Integer aMode)
244 aPresentation->Clear();
247 aPresentation->SetInfiniteState(myInfiniteState);
248 myDrawer->PlaneAspect()->EdgesAspect()->SetWidth(myCurrentMode == 0? 1 : 3);
257 const Handle(Geom_Plane)& pl = myComponent;
258 const Handle(Geom_Plane)& thegoodpl = Handle(Geom_Plane)::DownCast(pl->Translated(pl->Location(),myCenter));
259 GeomAdaptor_Surface surf(thegoodpl);
260 StdPrs_Plane::Add(aPresentation,surf,myDrawer);
263 DsgPrs_XYZPlanePresentation::Add(aPresentation,myDrawer,myCenter,myPmin,myPmax);
271 Handle(Prs3d_PlaneAspect) theaspect = myDrawer->PlaneAspect();
272 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
273 TheGroup->SetPrimitivesAspect(myDrawer->ShadingAspect()->Aspect());
275 const Standard_Real Xmax = 0.5*Standard_Real(theaspect->PlaneXLength());
276 const Standard_Real Ymax = 0.5*Standard_Real(theaspect->PlaneYLength());
278 Handle(Graphic3d_ArrayOfQuadrangles) aQuads = new Graphic3d_ArrayOfQuadrangles(4);
280 myComponent->D0(-Xmax,Ymax,p1);
281 aQuads->AddVertex(p1);
282 myComponent->D0(Xmax,Ymax,p1);
283 aQuads->AddVertex(p1);
284 myComponent->D0(Xmax,-Ymax,p1);
285 aQuads->AddVertex(p1);
286 myComponent->D0(-Xmax,-Ymax,p1);
287 aQuads->AddVertex(p1);
289 TheGroup->AddPrimitiveArray(aQuads);
292 DsgPrs_ShadedPlanePresentation::Add(aPresentation,myDrawer,myCenter,myPmin,myPmax);
298 void AIS_Plane::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
300 PrsMgr_PresentableObject::Compute(aProjector, aTransformation, aPresentation);
303 //=======================================================================
304 //function : ComputeSelection
306 //=======================================================================
307 void AIS_Plane::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
308 const Standard_Integer)
311 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,10);
312 Handle(Select3D_SensitiveFace) sfac;
316 Handle(TColgp_HArray1OfPnt) harr = new TColgp_HArray1OfPnt(1,5);
317 TColgp_Array1OfPnt& arr = harr->ChangeArray1();
318 Standard_Real lx = myDrawer->PlaneAspect()->PlaneXLength()/2.;
319 Standard_Real ly = myDrawer->PlaneAspect()->PlaneYLength()/2.;
320 const Handle(Geom_Plane)& pl = myComponent;
321 const Handle(Geom_Plane)& thegoodpl = Handle(Geom_Plane)::DownCast(pl->Translated(pl->Location(),myCenter));
323 thegoodpl->D0(lx,ly,arr(1));
324 thegoodpl->D0(lx,-ly,arr(2));
325 thegoodpl->D0(-lx,-ly,arr(3));
326 thegoodpl->D0(-lx,ly,arr(4));
328 sfac = new Select3D_SensitiveFace(eown,harr,Select3D_TOS_BOUNDARY);
332 Handle(TColgp_HArray1OfPnt) harr1 = new TColgp_HArray1OfPnt(1,4);
333 TColgp_Array1OfPnt& arr1 = harr1->ChangeArray1();
339 sfac = new Select3D_SensitiveFace(eown,harr1,Select3D_TOS_BOUNDARY);
342 aSelection->Add(sfac);
348 //=======================================================================
351 //=======================================================================
352 void AIS_Plane::SetSize(const Standard_Real aLength)
354 SetSize(aLength,aLength);
357 void AIS_Plane::SetSize(const Standard_Real aXLength,
358 const Standard_Real aYLength)
360 //if the plane already has a proper color or size,
361 //there is already a specific PlaneAspect and DatumAspect
363 Handle(Prs3d_PlaneAspect) PA;
364 Handle(Prs3d_DatumAspect) DA;
366 PA = myDrawer->PlaneAspect();
367 DA = myDrawer->DatumAspect();
369 Standard_Boolean yenavaitPA(Standard_True),yenavaitDA(Standard_True);
370 if(myDrawer->Link()->PlaneAspect() == PA){
371 yenavaitPA = Standard_False;
372 PA = new Prs3d_PlaneAspect();}
373 if(myDrawer->Link()->DatumAspect() == DA){
374 yenavaitDA = Standard_False;
375 DA = new Prs3d_DatumAspect();
378 PA->SetPlaneLength(aXLength,aYLength);
379 DA->SetAxisLength(aXLength,aYLength,aXLength);
382 myDrawer->SetPlaneAspect(PA);
384 myDrawer->SetDatumAspect(DA);
387 myHasOwnSize = Standard_True;
393 //=======================================================================
394 //function : UnsetSize
395 //purpose : If there is a color, the size is restaured from the drawer of the context...
396 //=======================================================================
397 void AIS_Plane::UnsetSize()
400 if(!myHasOwnSize) return;
402 myDrawer->PlaneAspect().Nullify();
403 myDrawer->DatumAspect().Nullify();
406 const Handle(Prs3d_PlaneAspect)& PA = myDrawer->Link()->PlaneAspect();
407 const Handle(Prs3d_DatumAspect)& DA = myDrawer->Link()->DatumAspect();
409 myDrawer->PlaneAspect()->SetPlaneLength(PA->PlaneXLength(),PA->PlaneYLength());
410 myDrawer->DatumAspect()->SetAxisLength(DA->FirstAxisLength(),
411 DA->SecondAxisLength(),
412 DA->ThirdAxisLength());
415 myHasOwnSize = Standard_False;
421 //=======================================================================
424 //=======================================================================
426 Standard_Boolean AIS_Plane::Size(Standard_Real& X,Standard_Real& Y) const
428 X = myDrawer->PlaneAspect()->PlaneXLength();
429 Y = myDrawer->PlaneAspect()->PlaneYLength();
430 return Abs(X-Y)<=Precision::Confusion();
434 //=======================================================================
435 //function : SetColor
437 //=======================================================================
440 void AIS_Plane::SetColor(const Quantity_NameOfColor aCol)
443 SetColor(Quantity_Color(aCol));
446 void AIS_Plane::SetColor(const Quantity_Color &aCol)
449 // if the plane already has its proper size, there is an already created planeaspect
450 // Standard_Boolean yenadeja = hasOwnColor || myHasOwnSize;
451 Handle(Prs3d_PlaneAspect) PA;
452 Handle(Prs3d_DatumAspect) DA;
454 PA = myDrawer->PlaneAspect();
455 DA = myDrawer->DatumAspect();
457 Standard_Boolean yenavaitPA(Standard_True),yenavaitDA(Standard_True);
458 if(myDrawer->Link()->PlaneAspect() == PA){
459 yenavaitPA = Standard_False;
460 PA = new Prs3d_PlaneAspect();}
461 if(myDrawer->Link()->DatumAspect() == DA){
462 yenavaitDA = Standard_False;
463 DA = new Prs3d_DatumAspect();
466 PA->EdgesAspect()->SetColor(aCol);
467 DA->FirstAxisAspect()->SetColor(aCol);
468 DA->SecondAxisAspect()->SetColor(aCol);
469 DA->ThirdAxisAspect()->SetColor(aCol);
472 myDrawer->SetPlaneAspect(PA);
474 myDrawer->SetDatumAspect(DA);
476 myDrawer->ShadingAspect()->SetColor(aCol);
478 hasOwnColor=Standard_True;
481 //=======================================================================
482 //function : SetColor
484 //=======================================================================
485 void AIS_Plane::UnsetColor()
487 if(!hasOwnColor) return;
489 myDrawer->PlaneAspect().Nullify();
490 myDrawer->DatumAspect().Nullify();
493 const Handle(Prs3d_PlaneAspect)& PA = myDrawer->Link()->PlaneAspect();
494 // const Handle(Prs3d_DatumAspect)& DA = myDrawer->Link()->DatumAspect();
495 Quantity_Color C;Aspect_TypeOfLine T;Standard_Real W;
496 PA->EdgesAspect()->Aspect()->Values(C,T,W);
497 Quantity_NameOfColor Col = C.Name();
498 myDrawer->PlaneAspect()->EdgesAspect()->SetColor(Col);
500 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(Col);
501 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(Col);
502 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(Col);
506 hasOwnColor=Standard_False;
510 //=======================================================================
511 //function : ComputeFrame
513 //=======================================================================
514 void AIS_Plane::ComputeFrame()
517 const Handle(Geom_Plane)& pl = myComponent;
520 if (myAutomaticPosition) {
521 ElSLib::Parameters(pl->Pln(),myCenter,U,V);
522 pl->D0 (U, V, myCenter);
525 const Handle(Geom_Plane)& thegoodpl =
526 Handle(Geom_Plane)::DownCast(pl->Translated(pl->Location(),myCenter));
527 ElSLib::Parameters(thegoodpl->Pln(),myPmin,U,V);
531 if (U < 10*Precision::Confusion()) U=0.1;
532 if (V < 10*Precision::Confusion()) V=0.1;
534 myDrawer->PlaneAspect()->SetPlaneLength(U,V);
538 //=======================================================================
540 //purpose : to avoid warning
541 //=======================================================================
542 void AIS_Plane::Compute(const Handle(Prs3d_Projector)&,
543 const Handle(Prs3d_Presentation)&)
547 //=======================================================================
548 //function : ComputeFields
550 //=======================================================================
551 void AIS_Plane::ComputeFields()
554 Handle (Prs3d_DatumAspect) DA = myDrawer->DatumAspect();
556 gp_Pnt Orig = myAx2->Ax2().Location();
557 gp_Dir oX = myAx2->Ax2().XDirection();
558 gp_Dir oY = myAx2->Ax2().YDirection();
559 gp_Dir oZ = myAx2->Ax2().Direction();
561 Standard_Real xo,yo,zo,x1,y1,z1,x2,y2,z2,x3,y3,z3,x4=0,y4=0,z4=0;
562 Standard_Real x5=0,y5=0,z5=0;
563 Orig.Coord(xo,yo,zo);
567 Standard_Real DS1 = DA->FirstAxisLength();
568 Standard_Real DS2 = DA->SecondAxisLength();
569 Standard_Real DS3 = DA->ThirdAxisLength();
572 switch (myTypeOfPlane) {
573 case AIS_TOPL_XYPlane:
576 myComponent = new Geom_Plane(XYP);
577 x4=xo+x1*DS1; y4=yo+y1*DS1; z4=zo+z1*DS1;
578 x5=xo+x2*DS2; y5=yo+y2*DS2; z5=zo+z2*DS2;
581 case AIS_TOPL_XZPlane:
584 myComponent = new Geom_Plane(XZP);
585 x4=xo+x1*DS1; y4=yo+y1*DS1; z4=zo+z1*DS1;
586 x5=xo+x3*DS3; y5=yo+y3*DS3; z5=zo+z3*DS3;
589 case AIS_TOPL_YZPlane:
592 myComponent = new Geom_Plane(XZP);
593 x4=xo+x2*DS2; y4=yo+y2*DS2; z4=zo+z2*DS2;
594 x5=xo+x3*DS3; y5=yo+y3*DS3; z5=zo+z3*DS3;
600 myPmin.SetCoord(x4,y4,z4);
601 myPmax.SetCoord(x5,y5,z5);
605 //=======================================================================
606 //function : InitDrawerAttributes
608 //=======================================================================
610 void AIS_Plane::InitDrawerAttributes()
613 Handle(Prs3d_ShadingAspect) shasp = new Prs3d_ShadingAspect();
614 shasp->SetMaterial(Graphic3d_NOM_PLASTIC);
615 shasp->SetColor(Quantity_NOC_GRAY40);
616 myDrawer->SetShadingAspect(shasp);
617 Handle(Graphic3d_AspectFillArea3d) asf = shasp->Aspect();
618 Graphic3d_MaterialAspect asp = asf->FrontMaterial();
619 asp.SetTransparency(0.8);
620 asf->SetFrontMaterial(asp);
621 asf->SetBackMaterial(asp);
626 //=======================================================================
627 //function : AcceptDisplayMode
629 //=======================================================================
631 Standard_Boolean AIS_Plane::
632 AcceptDisplayMode(const Standard_Integer aMode) const
636 //=======================================================================
637 //function : SetContext
639 //=======================================================================
641 void AIS_Plane::SetContext(const Handle(AIS_InteractiveContext)& Ctx)
643 AIS_InteractiveObject::SetContext(Ctx);