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_Array1OfVertex.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);
249 myDrawer->PlaneAspect()->EdgesAspect()->SetWidth(3);
251 myDrawer->PlaneAspect()->EdgesAspect()->SetWidth(1);
255 const Handle(Geom_Plane)& pl = myComponent;
256 const Handle(Geom_Plane)& thegoodpl = Handle(Geom_Plane)::DownCast
257 (pl->Translated(pl->Location(),myCenter));
258 GeomAdaptor_Surface surf(thegoodpl);
259 StdPrs_Plane::Add(aPresentation,surf,myDrawer);
262 DsgPrs_XYZPlanePresentation::Add(aPresentation,myDrawer,myCenter,myPmin,myPmax);
265 else if (aMode == 1){
268 Handle(Prs3d_PlaneAspect) theaspect = myDrawer->PlaneAspect();
269 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
271 Standard_Real Xmax,Ymax;
272 Xmax = Standard_Real(theaspect->PlaneXLength())/2.;
273 Ymax = Standard_Real(theaspect->PlaneYLength())/2.;
274 static Graphic3d_Array1OfVertex vertices(1,5);
275 TheGroup->SetPrimitivesAspect(myDrawer->ShadingAspect()->Aspect());
276 myComponent->D0(-Xmax,Ymax,p1);
277 vertices(1).SetCoord(p1.X(),p1.Y(),p1.Z());
278 vertices(5).SetCoord(p1.X(),p1.Y(),p1.Z());
279 myComponent->D0(Xmax,Ymax,p1);
280 vertices(2).SetCoord(p1.X(),p1.Y(),p1.Z());
281 myComponent->D0(Xmax,-Ymax,p1);
282 vertices(3).SetCoord(p1.X(),p1.Y(),p1.Z());
283 myComponent->D0(-Xmax,-Ymax,p1);
284 vertices(4).SetCoord(p1.X(),p1.Y(),p1.Z());
285 TheGroup->Polygon(vertices);
289 DsgPrs_ShadedPlanePresentation::Add(aPresentation,myDrawer,myCenter,myPmin,myPmax);
296 void AIS_Plane::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
298 // Standard_NotImplemented::Raise("AIS_Plane::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
299 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
302 //=======================================================================
303 //function : ComputeSelection
305 //=======================================================================
306 void AIS_Plane::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
307 const Standard_Integer)
310 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,10);
311 Handle(Select3D_SensitiveFace) sfac;
315 Handle(TColgp_HArray1OfPnt) harr = new TColgp_HArray1OfPnt(1,5);
316 TColgp_Array1OfPnt& arr = harr->ChangeArray1();
317 Standard_Real lx = myDrawer->PlaneAspect()->PlaneXLength()/2.;
318 Standard_Real ly = myDrawer->PlaneAspect()->PlaneYLength()/2.;
319 const Handle(Geom_Plane)& pl = myComponent;
320 const Handle(Geom_Plane)& thegoodpl = Handle(Geom_Plane)::DownCast(pl->Translated(pl->Location(),myCenter));
322 thegoodpl->D0(lx,ly,arr(1));
323 thegoodpl->D0(lx,-ly,arr(2));
324 thegoodpl->D0(-lx,-ly,arr(3));
325 thegoodpl->D0(-lx,ly,arr(4));
327 sfac = new Select3D_SensitiveFace(eown,harr,Select3D_TOS_BOUNDARY);
331 Handle(TColgp_HArray1OfPnt) harr1 = new TColgp_HArray1OfPnt(1,4);
332 TColgp_Array1OfPnt& arr1 = harr1->ChangeArray1();
338 sfac = new Select3D_SensitiveFace(eown,harr1,Select3D_TOS_BOUNDARY);
341 aSelection->Add(sfac);
347 //=======================================================================
350 //=======================================================================
351 void AIS_Plane::SetSize(const Standard_Real aLength)
353 SetSize(aLength,aLength);
356 void AIS_Plane::SetSize(const Standard_Real aXLength,
357 const Standard_Real aYLength)
359 //if the plane already has a proper color or size,
360 //there is already a specific PlaneAspect and DatumAspect
362 Handle(Prs3d_PlaneAspect) PA;
363 Handle(Prs3d_DatumAspect) DA;
365 PA = myDrawer->PlaneAspect();
366 DA = myDrawer->DatumAspect();
368 Standard_Boolean yenavaitPA(Standard_True),yenavaitDA(Standard_True);
369 if(myDrawer->Link()->PlaneAspect() == PA){
370 yenavaitPA = Standard_False;
371 PA = new Prs3d_PlaneAspect();}
372 if(myDrawer->Link()->DatumAspect() == DA){
373 yenavaitDA = Standard_False;
374 DA = new Prs3d_DatumAspect();
377 PA->SetPlaneLength(aXLength,aYLength);
378 DA->SetAxisLength(aXLength,aYLength,aXLength);
381 myDrawer->SetPlaneAspect(PA);
383 myDrawer->SetDatumAspect(DA);
386 myHasOwnSize = Standard_True;
392 //=======================================================================
393 //function : UnsetSize
394 //purpose : If there is a color, the size is restaured from the drawer of the context...
395 //=======================================================================
396 void AIS_Plane::UnsetSize()
399 if(!myHasOwnSize) return;
401 myDrawer->PlaneAspect().Nullify();
402 myDrawer->DatumAspect().Nullify();
405 const Handle(Prs3d_PlaneAspect)& PA = myDrawer->Link()->PlaneAspect();
406 const Handle(Prs3d_DatumAspect)& DA = myDrawer->Link()->DatumAspect();
408 myDrawer->PlaneAspect()->SetPlaneLength(PA->PlaneXLength(),PA->PlaneYLength());
409 myDrawer->DatumAspect()->SetAxisLength(DA->FirstAxisLength(),
410 DA->SecondAxisLength(),
411 DA->ThirdAxisLength());
414 myHasOwnSize = Standard_False;
420 //=======================================================================
423 //=======================================================================
425 Standard_Boolean AIS_Plane::Size(Standard_Real& X,Standard_Real& Y) const
427 X = myDrawer->PlaneAspect()->PlaneXLength();
428 Y = myDrawer->PlaneAspect()->PlaneYLength();
429 return Abs(X-Y)<=Precision::Confusion();
433 //=======================================================================
434 //function : SetColor
436 //=======================================================================
439 void AIS_Plane::SetColor(const Quantity_NameOfColor aCol)
442 SetColor(Quantity_Color(aCol));
445 void AIS_Plane::SetColor(const Quantity_Color &aCol)
448 // if the plane already has its proper size, there is an already created planeaspect
449 // Standard_Boolean yenadeja = hasOwnColor || myHasOwnSize;
450 Handle(Prs3d_PlaneAspect) PA;
451 Handle(Prs3d_DatumAspect) DA;
453 PA = myDrawer->PlaneAspect();
454 DA = myDrawer->DatumAspect();
456 Standard_Boolean yenavaitPA(Standard_True),yenavaitDA(Standard_True);
457 if(myDrawer->Link()->PlaneAspect() == PA){
458 yenavaitPA = Standard_False;
459 PA = new Prs3d_PlaneAspect();}
460 if(myDrawer->Link()->DatumAspect() == DA){
461 yenavaitDA = Standard_False;
462 DA = new Prs3d_DatumAspect();
465 PA->EdgesAspect()->SetColor(aCol);
466 DA->FirstAxisAspect()->SetColor(aCol);
467 DA->SecondAxisAspect()->SetColor(aCol);
468 DA->ThirdAxisAspect()->SetColor(aCol);
471 myDrawer->SetPlaneAspect(PA);
473 myDrawer->SetDatumAspect(DA);
475 myDrawer->ShadingAspect()->SetColor(aCol);
477 hasOwnColor=Standard_True;
480 //=======================================================================
481 //function : SetColor
483 //=======================================================================
484 void AIS_Plane::UnsetColor()
486 if(!hasOwnColor) return;
488 myDrawer->PlaneAspect().Nullify();
489 myDrawer->DatumAspect().Nullify();
492 const Handle(Prs3d_PlaneAspect)& PA = myDrawer->Link()->PlaneAspect();
493 // const Handle(Prs3d_DatumAspect)& DA = myDrawer->Link()->DatumAspect();
494 Quantity_Color C;Aspect_TypeOfLine T;Standard_Real W;
495 PA->EdgesAspect()->Aspect()->Values(C,T,W);
496 Quantity_NameOfColor Col = C.Name();
497 myDrawer->PlaneAspect()->EdgesAspect()->SetColor(Col);
499 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(Col);
500 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(Col);
501 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(Col);
505 hasOwnColor=Standard_False;
509 //=======================================================================
510 //function : ComputeFrame
512 //=======================================================================
513 void AIS_Plane::ComputeFrame()
516 const Handle(Geom_Plane)& pl = myComponent;
519 if (myAutomaticPosition) {
520 ElSLib::Parameters(pl->Pln(),myCenter,U,V);
521 pl->D0 (U, V, myCenter);
524 const Handle(Geom_Plane)& thegoodpl =
525 Handle(Geom_Plane)::DownCast(pl->Translated(pl->Location(),myCenter));
526 ElSLib::Parameters(thegoodpl->Pln(),myPmin,U,V);
530 if (U < 10*Precision::Confusion()) U=0.1;
531 if (V < 10*Precision::Confusion()) V=0.1;
533 myDrawer->PlaneAspect()->SetPlaneLength(U,V);
537 //=======================================================================
539 //purpose : to avoid warning
540 //=======================================================================
541 void AIS_Plane::Compute(const Handle(PrsMgr_PresentationManager2d)&,
542 const Handle(Graphic2d_GraphicObject)&,
543 const Standard_Integer)
547 //=======================================================================
549 //purpose : to avoid warning
550 //=======================================================================
551 void AIS_Plane::Compute(const Handle(Prs3d_Projector)&,
552 const Handle(Prs3d_Presentation)&)
556 //=======================================================================
557 //function : ComputeFields
559 //=======================================================================
560 void AIS_Plane::ComputeFields()
563 Handle (Prs3d_DatumAspect) DA = myDrawer->DatumAspect();
565 gp_Pnt Orig = myAx2->Ax2().Location();
566 gp_Dir oX = myAx2->Ax2().XDirection();
567 gp_Dir oY = myAx2->Ax2().YDirection();
568 gp_Dir oZ = myAx2->Ax2().Direction();
570 Standard_Real xo,yo,zo,x1,y1,z1,x2,y2,z2,x3,y3,z3,x4=0,y4=0,z4=0;
571 Standard_Real x5=0,y5=0,z5=0;
572 Orig.Coord(xo,yo,zo);
576 Standard_Real DS1 = DA->FirstAxisLength();
577 Standard_Real DS2 = DA->SecondAxisLength();
578 Standard_Real DS3 = DA->ThirdAxisLength();
581 switch (myTypeOfPlane) {
582 case AIS_TOPL_XYPlane:
585 myComponent = new Geom_Plane(XYP);
586 x4=xo+x1*DS1; y4=yo+y1*DS1; z4=zo+z1*DS1;
587 x5=xo+x2*DS2; y5=yo+y2*DS2; z5=zo+z2*DS2;
590 case AIS_TOPL_XZPlane:
593 myComponent = new Geom_Plane(XZP);
594 x4=xo+x1*DS1; y4=yo+y1*DS1; z4=zo+z1*DS1;
595 x5=xo+x3*DS3; y5=yo+y3*DS3; z5=zo+z3*DS3;
598 case AIS_TOPL_YZPlane:
601 myComponent = new Geom_Plane(XZP);
602 x4=xo+x2*DS2; y4=yo+y2*DS2; z4=zo+z2*DS2;
603 x5=xo+x3*DS3; y5=yo+y3*DS3; z5=zo+z3*DS3;
609 myPmin.SetCoord(x4,y4,z4);
610 myPmax.SetCoord(x5,y5,z5);
614 //=======================================================================
615 //function : InitDrawerAttributes
617 //=======================================================================
619 void AIS_Plane::InitDrawerAttributes()
622 Handle(Prs3d_ShadingAspect) shasp = new Prs3d_ShadingAspect();
623 shasp->SetMaterial(Graphic3d_NOM_PLASTIC);
624 shasp->SetColor(Quantity_NOC_GRAY40);
625 myDrawer->SetShadingAspect(shasp);
626 Handle(Graphic3d_AspectFillArea3d) asf = shasp->Aspect();
627 Graphic3d_MaterialAspect asp = asf->FrontMaterial();
628 asp.SetTransparency(0.8);
629 asf->SetFrontMaterial(asp);
630 asf->SetBackMaterial(asp);
635 //=======================================================================
636 //function : AcceptDisplayMode
638 //=======================================================================
640 Standard_Boolean AIS_Plane::
641 AcceptDisplayMode(const Standard_Integer aMode) const
645 //=======================================================================
646 //function : SetContext
648 //=======================================================================
650 void AIS_Plane::SetContext(const Handle(AIS_InteractiveContext)& Ctx)
652 AIS_InteractiveObject::SetContext(Ctx);