1 // Created on: 1995-08-02
2 // Created by: Arnaud BOUZY/Odile Olivier
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #define GER61351 //GG_171199 Enable to set an object RGB color
18 // instead a restricted object NameOfColor.
20 #include <AIS_Plane.ixx>
22 #include <TColgp_Array1OfPnt.hxx>
23 #include <TColgp_HArray1OfPnt.hxx>
25 #include <Precision.hxx>
29 #include <Graphic3d_ArrayOfQuadrangles.hxx>
30 #include <Graphic3d_Group.hxx>
31 #include <Prs3d_Drawer.hxx>
32 #include <Prs3d_LineAspect.hxx>
33 #include <Prs3d_PlaneAspect.hxx>
34 #include <Prs3d_DatumAspect.hxx>
35 #include <Prs3d_ShadingAspect.hxx>
36 #include <StdPrs_Plane.hxx>
37 #include <StdPrs_ShadedSurface.hxx>
39 #include <Geom_Plane.hxx>
40 #include <GeomAdaptor_Surface.hxx>
42 #include <Aspect_TypeOfLine.hxx>
43 #include <Graphic3d_AspectLine3d.hxx>
44 #include <Graphic3d_Structure.hxx>
45 #include <Graphic3d_MaterialAspect.hxx>
46 #include <Graphic3d_AspectFillArea3d.hxx>
48 #include <DsgPrs_XYZPlanePresentation.hxx>
49 #include <DsgPrs_ShadedPlanePresentation.hxx>
50 #include <UnitsAPI.hxx>
52 #include <Select3D_SensitiveTriangulation.hxx>
53 #include <SelectBasics_EntityOwner.hxx>
54 #include <SelectMgr_EntityOwner.hxx>
55 #include <StdPrs_ShadedShape.hxx>
57 #include <Poly_Triangulation.hxx>
59 #include <AIS_Drawer.hxx>
61 #include <TCollection_AsciiString.hxx>
63 //=======================================================================
64 //function : AIS_Plane
66 //=======================================================================
67 AIS_Plane::AIS_Plane(const Handle(Geom_Plane)& aComponent,
68 const Standard_Boolean aCurrentMode):
69 myComponent(aComponent),
70 myCenter(gp_Pnt(0.,0.,0.)),
71 myCurrentMode(aCurrentMode),
72 myAutomaticPosition(Standard_True),
73 myTypeOfPlane(AIS_TOPL_Unknown),
74 myIsXYZPlane(Standard_False),
75 myTypeOfSensitivity (Select3D_TOS_BOUNDARY)
77 InitDrawerAttributes();
80 //=======================================================================
81 //function : AIS_Plane
82 //purpose : avec une position
83 //=======================================================================
84 AIS_Plane::AIS_Plane(const Handle(Geom_Plane)& aComponent,
85 const gp_Pnt& aCenter,
86 const Standard_Boolean aCurrentMode):
87 myComponent(aComponent),
89 myCurrentMode(aCurrentMode),
90 myAutomaticPosition(Standard_True),
91 myTypeOfPlane(AIS_TOPL_Unknown),
92 myIsXYZPlane(Standard_False),
93 myTypeOfSensitivity (Select3D_TOS_BOUNDARY)
95 InitDrawerAttributes();
98 //=======================================================================
99 //function : AIS_Plane
101 //=======================================================================
102 AIS_Plane::AIS_Plane(const Handle(Geom_Plane)& aComponent,
103 const gp_Pnt& aCenter,
106 const Standard_Boolean aCurrentMode):
107 myComponent(aComponent),
111 myCurrentMode(aCurrentMode),
112 myAutomaticPosition(Standard_False),
113 myTypeOfPlane(AIS_TOPL_Unknown),
114 myIsXYZPlane(Standard_False),
115 myTypeOfSensitivity (Select3D_TOS_BOUNDARY)
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),
133 myTypeOfSensitivity (Select3D_TOS_BOUNDARY)
135 InitDrawerAttributes();
142 //=======================================================================
143 //function : SetComponent
145 //=======================================================================
147 void AIS_Plane::SetComponent(const Handle(Geom_Plane)& aComponent)
149 myComponent = aComponent;
150 myTypeOfPlane = AIS_TOPL_Unknown;
151 myIsXYZPlane = Standard_False;
152 //myCenter = gp_Pnt(0.,0.,0.);
153 myAutomaticPosition = Standard_True;
156 //=======================================================================
159 //=======================================================================
161 AIS_KindOfInteractive AIS_Plane::Type() const
162 {return AIS_KOI_Datum;}
165 //=======================================================================
166 //function : Signature
168 //=======================================================================
170 Standard_Integer AIS_Plane::Signature() const
174 //=======================================================================
175 //function : Axis2Placement
177 //=======================================================================
179 Handle(Geom_Axis2Placement) AIS_Plane::Axis2Placement()
181 Handle(Geom_Axis2Placement) Bid;
182 return IsXYZPlane() ? myAx2:Bid;
184 //=======================================================================
185 //function : SetAxis2Placement
187 //=======================================================================
189 void AIS_Plane::SetAxis2Placement(const Handle(Geom_Axis2Placement)& aComponent,
190 const AIS_TypeOfPlane aPlaneType)
192 myTypeOfPlane = aPlaneType;
193 myIsXYZPlane = Standard_True;
195 myAutomaticPosition = Standard_True;
199 //=======================================================================
200 //function : PlaneAttributes
202 //=======================================================================
203 Standard_Boolean AIS_Plane::PlaneAttributes(Handle(Geom_Plane)& aComponent,
208 Standard_Boolean aStatus (Standard_False);
209 if (!myAutomaticPosition){
210 aComponent = myComponent;
214 aStatus = Standard_True;
219 //=======================================================================
220 //function : SetPlaneAttributes
222 //=======================================================================
223 void AIS_Plane::SetPlaneAttributes(const Handle(Geom_Plane)& aComponent,
224 const gp_Pnt& aCenter,
228 myAutomaticPosition = Standard_False;
229 myComponent = aComponent;
233 myTypeOfPlane = AIS_TOPL_Unknown;
234 myIsXYZPlane = Standard_False;
237 //=======================================================================
240 //=======================================================================
241 void AIS_Plane::Compute(const Handle(PrsMgr_PresentationManager3d)& ,
242 const Handle(Prs3d_Presentation)& aPresentation,
243 const Standard_Integer aMode)
245 aPresentation->Clear();
248 aPresentation->SetInfiniteState(myInfiniteState);
249 myDrawer->PlaneAspect()->EdgesAspect()->SetWidth(myCurrentMode == 0? 1 : 3);
258 const Handle(Geom_Plane)& pl = myComponent;
259 const Handle(Geom_Plane)& thegoodpl = Handle(Geom_Plane)::DownCast(pl->Translated(pl->Location(),myCenter));
260 GeomAdaptor_Surface surf(thegoodpl);
261 StdPrs_Plane::Add(aPresentation,surf,myDrawer);
264 DsgPrs_XYZPlanePresentation::Add(aPresentation,myDrawer,myCenter,myPmin,myPmax);
272 Handle(Prs3d_PlaneAspect) theaspect = myDrawer->PlaneAspect();
273 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
274 TheGroup->SetPrimitivesAspect(myDrawer->ShadingAspect()->Aspect());
276 const Standard_Real Xmax = 0.5*Standard_Real(theaspect->PlaneXLength());
277 const Standard_Real Ymax = 0.5*Standard_Real(theaspect->PlaneYLength());
279 Handle(Graphic3d_ArrayOfQuadrangles) aQuads = new Graphic3d_ArrayOfQuadrangles(4);
281 myComponent->D0(-Xmax,Ymax,p1);
282 aQuads->AddVertex(p1);
283 myComponent->D0(Xmax,Ymax,p1);
284 aQuads->AddVertex(p1);
285 myComponent->D0(Xmax,-Ymax,p1);
286 aQuads->AddVertex(p1);
287 myComponent->D0(-Xmax,-Ymax,p1);
288 aQuads->AddVertex(p1);
290 TheGroup->AddPrimitiveArray(aQuads);
293 DsgPrs_ShadedPlanePresentation::Add(aPresentation,myDrawer,myCenter,myPmin,myPmax);
299 void AIS_Plane::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
301 PrsMgr_PresentableObject::Compute(aProjector, aTransformation, aPresentation);
304 //=======================================================================
305 //function : ComputeSelection
307 //=======================================================================
308 void AIS_Plane::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, const Standard_Integer /*theMode*/)
310 theSelection->Clear();
311 Handle(SelectMgr_EntityOwner) aSensitiveOwner = new SelectMgr_EntityOwner (this, 10);
312 Handle(Poly_Triangulation) aSensitivePoly;
316 // plane representing rectangle
317 Standard_Real aLengthX = myDrawer->PlaneAspect()->PlaneXLength() / 2.0;
318 Standard_Real aLengthY = myDrawer->PlaneAspect()->PlaneYLength() / 2.0;
319 Handle(Geom_Plane) aPlane =
320 Handle(Geom_Plane)::DownCast (myComponent->Translated (myComponent->Location(), myCenter));
322 TColgp_Array1OfPnt aRectanglePoints (1, 4);
323 aPlane->D0 ( aLengthX, aLengthY, aRectanglePoints.ChangeValue (1));
324 aPlane->D0 ( aLengthX, -aLengthY, aRectanglePoints.ChangeValue (2));
325 aPlane->D0 (-aLengthX, -aLengthY, aRectanglePoints.ChangeValue (3));
326 aPlane->D0 (-aLengthX, aLengthY, aRectanglePoints.ChangeValue (4));
328 Poly_Array1OfTriangle aTriangles (1, 2);
329 aTriangles.ChangeValue (1) = Poly_Triangle (1, 2, 3);
330 aTriangles.ChangeValue (2) = Poly_Triangle (1, 3, 4);
332 aSensitivePoly = new Poly_Triangulation (aRectanglePoints, aTriangles);
336 // plane representing triangle
337 TColgp_Array1OfPnt aTrianglePoints (1, 3);
338 aTrianglePoints.ChangeValue (1) = myCenter;
339 aTrianglePoints.ChangeValue (2) = myPmin;
340 aTrianglePoints.ChangeValue (3) = myPmax;
342 Poly_Array1OfTriangle aTriangles (1, 1);
343 aTriangles.ChangeValue (1) = Poly_Triangle(1, 2, 3);
345 aSensitivePoly = new Poly_Triangulation (aTrianglePoints, aTriangles);
348 Standard_Boolean isSensitiveInterior = myTypeOfSensitivity == Select3D_TOS_INTERIOR;
350 Handle(Select3D_SensitiveTriangulation) aSensitive =
351 new Select3D_SensitiveTriangulation (aSensitiveOwner,
354 isSensitiveInterior);
356 theSelection->Add(aSensitive);
359 //=======================================================================
362 //=======================================================================
363 void AIS_Plane::SetSize(const Standard_Real aLength)
365 SetSize(aLength,aLength);
368 void AIS_Plane::SetSize(const Standard_Real aXLength,
369 const Standard_Real aYLength)
371 //if the plane already has a proper color or size,
372 //there is already a specific PlaneAspect and DatumAspect
374 Handle(Prs3d_PlaneAspect) PA;
375 Handle(Prs3d_DatumAspect) DA;
377 PA = myDrawer->PlaneAspect();
378 DA = myDrawer->DatumAspect();
380 Standard_Boolean yenavaitPA(Standard_True),yenavaitDA(Standard_True);
381 if(myDrawer->Link()->PlaneAspect() == PA){
382 yenavaitPA = Standard_False;
383 PA = new Prs3d_PlaneAspect();}
384 if(myDrawer->Link()->DatumAspect() == DA){
385 yenavaitDA = Standard_False;
386 DA = new Prs3d_DatumAspect();
389 PA->SetPlaneLength(aXLength,aYLength);
390 DA->SetAxisLength(aXLength,aYLength,aXLength);
393 myDrawer->SetPlaneAspect(PA);
395 myDrawer->SetDatumAspect(DA);
398 myHasOwnSize = Standard_True;
404 //=======================================================================
405 //function : UnsetSize
406 //purpose : If there is a color, the size is restaured from the drawer of the context...
407 //=======================================================================
408 void AIS_Plane::UnsetSize()
411 if(!myHasOwnSize) return;
413 myDrawer->PlaneAspect().Nullify();
414 myDrawer->DatumAspect().Nullify();
417 const Handle(Prs3d_PlaneAspect)& PA = myDrawer->Link()->PlaneAspect();
418 const Handle(Prs3d_DatumAspect)& DA = myDrawer->Link()->DatumAspect();
420 myDrawer->PlaneAspect()->SetPlaneLength(PA->PlaneXLength(),PA->PlaneYLength());
421 myDrawer->DatumAspect()->SetAxisLength(DA->FirstAxisLength(),
422 DA->SecondAxisLength(),
423 DA->ThirdAxisLength());
426 myHasOwnSize = Standard_False;
432 //=======================================================================
435 //=======================================================================
437 Standard_Boolean AIS_Plane::Size(Standard_Real& X,Standard_Real& Y) const
439 X = myDrawer->PlaneAspect()->PlaneXLength();
440 Y = myDrawer->PlaneAspect()->PlaneYLength();
441 return Abs(X-Y)<=Precision::Confusion();
445 //=======================================================================
446 //function : SetColor
448 //=======================================================================
451 void AIS_Plane::SetColor(const Quantity_NameOfColor aCol)
454 SetColor(Quantity_Color(aCol));
457 void AIS_Plane::SetColor(const Quantity_Color &aCol)
460 // if the plane already has its proper size, there is an already created planeaspect
461 // Standard_Boolean yenadeja = hasOwnColor || myHasOwnSize;
462 Handle(Prs3d_PlaneAspect) PA;
463 Handle(Prs3d_DatumAspect) DA;
465 PA = myDrawer->PlaneAspect();
466 DA = myDrawer->DatumAspect();
468 Standard_Boolean yenavaitPA(Standard_True),yenavaitDA(Standard_True);
469 if(myDrawer->Link()->PlaneAspect() == PA){
470 yenavaitPA = Standard_False;
471 PA = new Prs3d_PlaneAspect();}
472 if(myDrawer->Link()->DatumAspect() == DA){
473 yenavaitDA = Standard_False;
474 DA = new Prs3d_DatumAspect();
477 PA->EdgesAspect()->SetColor(aCol);
478 DA->FirstAxisAspect()->SetColor(aCol);
479 DA->SecondAxisAspect()->SetColor(aCol);
480 DA->ThirdAxisAspect()->SetColor(aCol);
483 myDrawer->SetPlaneAspect(PA);
485 myDrawer->SetDatumAspect(DA);
487 myDrawer->ShadingAspect()->SetColor(aCol);
489 hasOwnColor=Standard_True;
492 //=======================================================================
493 //function : SetColor
495 //=======================================================================
496 void AIS_Plane::UnsetColor()
498 if(!hasOwnColor) return;
500 myDrawer->PlaneAspect().Nullify();
501 myDrawer->DatumAspect().Nullify();
504 const Handle(Prs3d_PlaneAspect)& PA = myDrawer->Link()->PlaneAspect();
505 // const Handle(Prs3d_DatumAspect)& DA = myDrawer->Link()->DatumAspect();
506 Quantity_Color C;Aspect_TypeOfLine T;Standard_Real W;
507 PA->EdgesAspect()->Aspect()->Values(C,T,W);
508 Quantity_NameOfColor Col = C.Name();
509 myDrawer->PlaneAspect()->EdgesAspect()->SetColor(Col);
511 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(Col);
512 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(Col);
513 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(Col);
517 hasOwnColor=Standard_False;
521 //=======================================================================
522 //function : ComputeFrame
524 //=======================================================================
525 void AIS_Plane::ComputeFrame()
528 const Handle(Geom_Plane)& pl = myComponent;
531 if (myAutomaticPosition) {
532 ElSLib::Parameters(pl->Pln(),myCenter,U,V);
533 pl->D0 (U, V, myCenter);
536 const Handle(Geom_Plane)& thegoodpl =
537 Handle(Geom_Plane)::DownCast(pl->Translated(pl->Location(),myCenter));
538 ElSLib::Parameters(thegoodpl->Pln(),myPmin,U,V);
542 if (U < 10*Precision::Confusion()) U=0.1;
543 if (V < 10*Precision::Confusion()) V=0.1;
545 myDrawer->PlaneAspect()->SetPlaneLength(U,V);
549 //=======================================================================
551 //purpose : to avoid warning
552 //=======================================================================
553 void AIS_Plane::Compute(const Handle(Prs3d_Projector)&,
554 const Handle(Prs3d_Presentation)&)
558 //=======================================================================
559 //function : ComputeFields
561 //=======================================================================
562 void AIS_Plane::ComputeFields()
565 Handle (Prs3d_DatumAspect) DA = myDrawer->DatumAspect();
567 gp_Pnt Orig = myAx2->Ax2().Location();
568 gp_Dir oX = myAx2->Ax2().XDirection();
569 gp_Dir oY = myAx2->Ax2().YDirection();
570 gp_Dir oZ = myAx2->Ax2().Direction();
572 Standard_Real xo,yo,zo,x1,y1,z1,x2,y2,z2,x3,y3,z3,x4=0,y4=0,z4=0;
573 Standard_Real x5=0,y5=0,z5=0;
574 Orig.Coord(xo,yo,zo);
578 Standard_Real DS1 = DA->FirstAxisLength();
579 Standard_Real DS2 = DA->SecondAxisLength();
580 Standard_Real DS3 = DA->ThirdAxisLength();
583 switch (myTypeOfPlane) {
584 case AIS_TOPL_XYPlane:
587 myComponent = new Geom_Plane(XYP);
588 x4=xo+x1*DS1; y4=yo+y1*DS1; z4=zo+z1*DS1;
589 x5=xo+x2*DS2; y5=yo+y2*DS2; z5=zo+z2*DS2;
592 case AIS_TOPL_XZPlane:
595 myComponent = new Geom_Plane(XZP);
596 x4=xo+x1*DS1; y4=yo+y1*DS1; z4=zo+z1*DS1;
597 x5=xo+x3*DS3; y5=yo+y3*DS3; z5=zo+z3*DS3;
600 case AIS_TOPL_YZPlane:
603 myComponent = new Geom_Plane(XZP);
604 x4=xo+x2*DS2; y4=yo+y2*DS2; z4=zo+z2*DS2;
605 x5=xo+x3*DS3; y5=yo+y3*DS3; z5=zo+z3*DS3;
611 myPmin.SetCoord(x4,y4,z4);
612 myPmax.SetCoord(x5,y5,z5);
616 //=======================================================================
617 //function : InitDrawerAttributes
619 //=======================================================================
621 void AIS_Plane::InitDrawerAttributes()
624 Handle(Prs3d_ShadingAspect) shasp = new Prs3d_ShadingAspect();
625 shasp->SetMaterial(Graphic3d_NOM_PLASTIC);
626 shasp->SetColor(Quantity_NOC_GRAY40);
627 myDrawer->SetShadingAspect(shasp);
628 Handle(Graphic3d_AspectFillArea3d) asf = shasp->Aspect();
629 Graphic3d_MaterialAspect asp = asf->FrontMaterial();
630 asp.SetTransparency(0.8);
631 asf->SetFrontMaterial(asp);
632 asf->SetBackMaterial(asp);
637 //=======================================================================
638 //function : AcceptDisplayMode
640 //=======================================================================
642 Standard_Boolean AIS_Plane::
643 AcceptDisplayMode(const Standard_Integer aMode) const
647 //=======================================================================
648 //function : SetContext
650 //=======================================================================
652 void AIS_Plane::SetContext(const Handle(AIS_InteractiveContext)& Ctx)
654 AIS_InteractiveObject::SetContext(Ctx);