0024481: Test "Perform Infinite Point" provides wrong result for a solid
[occt.git] / src / AIS / AIS_Plane.cxx
CommitLineData
b311480e 1// Created on: 1995-08-02
2// Created by: Arnaud BOUZY/Odile Olivier
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
973c2be1 8// This library is free software; you can redistribute it and / or modify it
9// under the terms of the GNU Lesser General Public 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#define GER61351 //GG_171199 Enable to set an object RGB color
18// instead a restricted object NameOfColor.
19
20#include <AIS_Plane.ixx>
21
22#include <TColgp_Array1OfPnt.hxx>
23#include <TColgp_HArray1OfPnt.hxx>
24
25#include <Precision.hxx>
26#include <gp_Pnt.hxx>
27#include <ElSLib.hxx>
28
b8ddfc2f 29#include <Graphic3d_ArrayOfQuadrangles.hxx>
7fd59977 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>
38
39#include <Geom_Plane.hxx>
40#include <GeomAdaptor_Surface.hxx>
41
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>
47
48#include <DsgPrs_XYZPlanePresentation.hxx>
49#include <DsgPrs_ShadedPlanePresentation.hxx>
50#include <UnitsAPI.hxx>
51
52#include <SelectBasics_EntityOwner.hxx>
53#include <SelectMgr_EntityOwner.hxx>
54#include <Select3D_SensitiveFace.hxx>
55#include <StdPrs_ShadedShape.hxx>
56
57#include <AIS_Drawer.hxx>
58
59#include <TCollection_AsciiString.hxx>
60
61//=======================================================================
62//function : AIS_Plane
63//purpose :
64//=======================================================================
65AIS_Plane::AIS_Plane(const Handle(Geom_Plane)& aComponent,
66 const Standard_Boolean aCurrentMode):
67myComponent(aComponent),
68myCenter(gp_Pnt(0.,0.,0.)),
69myCurrentMode(aCurrentMode),
70myAutomaticPosition(Standard_True),
71myTypeOfPlane(AIS_TOPL_Unknown),
9e8804b6 72myIsXYZPlane(Standard_False),
73myTypeOfSensitivity (Select3D_TOS_BOUNDARY)
7fd59977 74{
75 InitDrawerAttributes();
76}
77
78//=======================================================================
79//function : AIS_Plane
80//purpose : avec une position
81//=======================================================================
82AIS_Plane::AIS_Plane(const Handle(Geom_Plane)& aComponent,
83 const gp_Pnt& aCenter,
84 const Standard_Boolean aCurrentMode):
85myComponent(aComponent),
86myCenter(aCenter),
87myCurrentMode(aCurrentMode),
88myAutomaticPosition(Standard_True),
89myTypeOfPlane(AIS_TOPL_Unknown),
9e8804b6 90myIsXYZPlane(Standard_False),
91myTypeOfSensitivity (Select3D_TOS_BOUNDARY)
7fd59977 92{
93 InitDrawerAttributes();
94}
95
96//=======================================================================
97//function : AIS_Plane
98//purpose :
99//=======================================================================
100AIS_Plane::AIS_Plane(const Handle(Geom_Plane)& aComponent,
101 const gp_Pnt& aCenter,
102 const gp_Pnt& aPmin,
103 const gp_Pnt& aPmax,
104 const Standard_Boolean aCurrentMode):
105myComponent(aComponent),
106myCenter(aCenter),
107myPmin(aPmin),
108myPmax(aPmax),
109myCurrentMode(aCurrentMode),
110myAutomaticPosition(Standard_False),
111myTypeOfPlane(AIS_TOPL_Unknown),
9e8804b6 112myIsXYZPlane(Standard_False),
113myTypeOfSensitivity (Select3D_TOS_BOUNDARY)
7fd59977 114{
115 InitDrawerAttributes();
116 SetHilightMode(0);
117}
118
119//=======================================================================
120//function : AIS_Plane
121//purpose : XYPlane, XZPlane, YZPlane
122//=======================================================================
123AIS_Plane::AIS_Plane(const Handle(Geom_Axis2Placement)& aComponent,
124 const AIS_TypeOfPlane aPlaneType,
125 const Standard_Boolean aCurrentMode):
126myAx2(aComponent),
127myCurrentMode(aCurrentMode),
128myAutomaticPosition(Standard_True),
129myTypeOfPlane(aPlaneType),
9e8804b6 130myIsXYZPlane(Standard_True),
131myTypeOfSensitivity (Select3D_TOS_BOUNDARY)
7fd59977 132{
133 InitDrawerAttributes();
134 ComputeFields();
135 SetHilightMode(0);
136
137}
138
139
140//=======================================================================
141//function : SetComponent
142//purpose :
143//=======================================================================
144
145void AIS_Plane::SetComponent(const Handle(Geom_Plane)& aComponent)
146{
147 myComponent = aComponent;
148 myTypeOfPlane = AIS_TOPL_Unknown;
149 myIsXYZPlane = Standard_False;
150 //myCenter = gp_Pnt(0.,0.,0.);
151 myAutomaticPosition = Standard_True;
152}
153
154//=======================================================================
155//function : Type
156//purpose :
157//=======================================================================
158
159AIS_KindOfInteractive AIS_Plane::Type() const
160{return AIS_KOI_Datum;}
161
162
163//=======================================================================
164//function : Signature
165//purpose :
166//=======================================================================
167
168Standard_Integer AIS_Plane::Signature() const
169{return 7;}
170
171
172//=======================================================================
173//function : Axis2Placement
174//purpose :
175//=======================================================================
176
177Handle(Geom_Axis2Placement) AIS_Plane::Axis2Placement()
178{
179 Handle(Geom_Axis2Placement) Bid;
180 return IsXYZPlane() ? myAx2:Bid;
181}
182//=======================================================================
183//function : SetAxis2Placement
184//purpose :
185//=======================================================================
186
187 void AIS_Plane::SetAxis2Placement(const Handle(Geom_Axis2Placement)& aComponent,
188 const AIS_TypeOfPlane aPlaneType)
189{
190 myTypeOfPlane = aPlaneType;
191 myIsXYZPlane = Standard_True;
192 myAx2= aComponent;
193 myAutomaticPosition = Standard_True;
194 ComputeFields();
195}
196
197//=======================================================================
198//function : PlaneAttributes
199//purpose :
200//=======================================================================
201Standard_Boolean AIS_Plane::PlaneAttributes(Handle(Geom_Plane)& aComponent,
202 gp_Pnt& aCenter,
203 gp_Pnt& aPmin,
204 gp_Pnt& aPmax)
205{
206 Standard_Boolean aStatus (Standard_False);
207 if (!myAutomaticPosition){
208 aComponent = myComponent;
209 aCenter = myCenter;
210 aPmin = myPmin;
211 aPmax = myPmax;
212 aStatus = Standard_True;
213 }
214 return aStatus;
215}
216
217//=======================================================================
218//function : SetPlaneAttributes
219//purpose :
220//=======================================================================
221void AIS_Plane::SetPlaneAttributes(const Handle(Geom_Plane)& aComponent,
222 const gp_Pnt& aCenter,
223 const gp_Pnt& aPmin,
224 const gp_Pnt& aPmax)
225{
226 myAutomaticPosition = Standard_False;
227 myComponent = aComponent;
228 myCenter = aCenter;
229 myPmin = aPmin;
230 myPmax = aPmax;
231 myTypeOfPlane = AIS_TOPL_Unknown;
232 myIsXYZPlane = Standard_False;
233}
234
235//=======================================================================
236//function : Compute
237//purpose :
238//=======================================================================
239void AIS_Plane::Compute(const Handle(PrsMgr_PresentationManager3d)& ,
240 const Handle(Prs3d_Presentation)& aPresentation,
241 const Standard_Integer aMode)
242{
243 aPresentation->Clear();
244
245 ComputeFields();
246 aPresentation->SetInfiniteState(myInfiniteState);
b8ddfc2f 247 myDrawer->PlaneAspect()->EdgesAspect()->SetWidth(myCurrentMode == 0? 1 : 3);
248
249 switch (aMode)
250 {
251 case 0:
252 {
253 if (!myIsXYZPlane)
254 {
255 ComputeFrame();
256 const Handle(Geom_Plane)& pl = myComponent;
257 const Handle(Geom_Plane)& thegoodpl = Handle(Geom_Plane)::DownCast(pl->Translated(pl->Location(),myCenter));
258 GeomAdaptor_Surface surf(thegoodpl);
259 StdPrs_Plane::Add(aPresentation,surf,myDrawer);
260 }
261 else
262 DsgPrs_XYZPlanePresentation::Add(aPresentation,myDrawer,myCenter,myPmin,myPmax);
263 break;
7fd59977 264 }
b8ddfc2f 265 case 1:
266 {
267 if (!myIsXYZPlane)
268 {
269 ComputeFrame();
270 Handle(Prs3d_PlaneAspect) theaspect = myDrawer->PlaneAspect();
271 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
272 TheGroup->SetPrimitivesAspect(myDrawer->ShadingAspect()->Aspect());
273 gp_Pnt p1;
274 const Standard_Real Xmax = 0.5*Standard_Real(theaspect->PlaneXLength());
275 const Standard_Real Ymax = 0.5*Standard_Real(theaspect->PlaneYLength());
276
277 Handle(Graphic3d_ArrayOfQuadrangles) aQuads = new Graphic3d_ArrayOfQuadrangles(4);
278
279 myComponent->D0(-Xmax,Ymax,p1);
280 aQuads->AddVertex(p1);
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
288 TheGroup->AddPrimitiveArray(aQuads);
7fd59977 289 }
b8ddfc2f 290 else
291 DsgPrs_ShadedPlanePresentation::Add(aPresentation,myDrawer,myCenter,myPmin,myPmax);
292 break;
7fd59977 293 }
294 }
7fd59977 295}
296
297void AIS_Plane::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
298{
b8ddfc2f 299 PrsMgr_PresentableObject::Compute(aProjector, aTransformation, aPresentation);
7fd59977 300}
301
302//=======================================================================
303//function : ComputeSelection
304//purpose :
305//=======================================================================
306void AIS_Plane::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
307 const Standard_Integer)
308{
309 aSelection->Clear();
310 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,10);
311 Handle(Select3D_SensitiveFace) sfac;
312
313 if (!myIsXYZPlane){
314
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));
321
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));
326 arr(5) = arr(1);
9e8804b6 327 sfac = new Select3D_SensitiveFace(eown,harr,myTypeOfSensitivity);
7fd59977 328
329 }
330 else {
331 Handle(TColgp_HArray1OfPnt) harr1 = new TColgp_HArray1OfPnt(1,4);
332 TColgp_Array1OfPnt& arr1 = harr1->ChangeArray1();
333
334 arr1(1) = myCenter;
335 arr1(2) = myPmin;
336 arr1(3) = myPmax;
337 arr1(4) = myCenter;
9e8804b6 338 sfac = new Select3D_SensitiveFace(eown,harr1,myTypeOfSensitivity);
7fd59977 339
340 }
341 aSelection->Add(sfac);
342}
343
344
345
346
347//=======================================================================
348//function : SetSize
349//purpose :
350//=======================================================================
351void AIS_Plane::SetSize(const Standard_Real aLength)
352{
353 SetSize(aLength,aLength);
354}
355
356void AIS_Plane::SetSize(const Standard_Real aXLength,
357 const Standard_Real aYLength)
358{
81bba717 359 //if the plane already has a proper color or size,
360 //there is already a specific PlaneAspect and DatumAspect
7fd59977 361
362 Handle(Prs3d_PlaneAspect) PA;
363 Handle(Prs3d_DatumAspect) DA;
364
365 PA = myDrawer->PlaneAspect();
366 DA = myDrawer->DatumAspect();
367
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();
375 }
376
377 PA->SetPlaneLength(aXLength,aYLength);
378 DA->SetAxisLength(aXLength,aYLength,aXLength);
379
380 if(!yenavaitPA)
381 myDrawer->SetPlaneAspect(PA);
382 if(!yenavaitDA)
383 myDrawer->SetDatumAspect(DA);
384
385
386 myHasOwnSize = Standard_True;
387 Update();
388 UpdateSelection();
389}
390
391
392//=======================================================================
393//function : UnsetSize
81bba717 394//purpose : If there is a color, the size is restaured from the drawer of the context...
7fd59977 395//=======================================================================
396void AIS_Plane::UnsetSize()
397{
398
399 if(!myHasOwnSize) return;
400 if(!hasOwnColor){
401 myDrawer->PlaneAspect().Nullify();
402 myDrawer->DatumAspect().Nullify();
403 }
404 else{
405 const Handle(Prs3d_PlaneAspect)& PA = myDrawer->Link()->PlaneAspect();
406 const Handle(Prs3d_DatumAspect)& DA = myDrawer->Link()->DatumAspect();
407
408 myDrawer->PlaneAspect()->SetPlaneLength(PA->PlaneXLength(),PA->PlaneYLength());
409 myDrawer->DatumAspect()->SetAxisLength(DA->FirstAxisLength(),
410 DA->SecondAxisLength(),
411 DA->ThirdAxisLength());
412 }
413
414 myHasOwnSize = Standard_False;
415 Update();
416 UpdateSelection();
417
418}
419
420//=======================================================================
421//function : Size
422//purpose :
423//=======================================================================
424
425Standard_Boolean AIS_Plane::Size(Standard_Real& X,Standard_Real& Y) const
426{
427 X = myDrawer->PlaneAspect()->PlaneXLength();
428 Y = myDrawer->PlaneAspect()->PlaneYLength();
429 return Abs(X-Y)<=Precision::Confusion();
430}
431
432
433//=======================================================================
434//function : SetColor
435//purpose :
436//=======================================================================
437
438
439void AIS_Plane::SetColor(const Quantity_NameOfColor aCol)
440#ifdef GER61351
441{
442 SetColor(Quantity_Color(aCol));
443}
444
445void AIS_Plane::SetColor(const Quantity_Color &aCol)
446#endif
447{
81bba717 448 // if the plane already has its proper size, there is an already created planeaspect
7fd59977 449// Standard_Boolean yenadeja = hasOwnColor || myHasOwnSize;
450 Handle(Prs3d_PlaneAspect) PA;
451 Handle(Prs3d_DatumAspect) DA;
452
453 PA = myDrawer->PlaneAspect();
454 DA = myDrawer->DatumAspect();
455
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();
463 }
464
465 PA->EdgesAspect()->SetColor(aCol);
466 DA->FirstAxisAspect()->SetColor(aCol);
467 DA->SecondAxisAspect()->SetColor(aCol);
468 DA->ThirdAxisAspect()->SetColor(aCol);
469
470 if(!yenavaitPA)
471 myDrawer->SetPlaneAspect(PA);
472 if(!yenavaitDA)
473 myDrawer->SetDatumAspect(DA);
474
475 myDrawer->ShadingAspect()->SetColor(aCol);
476
477 hasOwnColor=Standard_True;
478 myOwnColor = aCol;
479}
480//=======================================================================
481//function : SetColor
482//purpose :
483//=======================================================================
484void AIS_Plane::UnsetColor()
485{
486 if(!hasOwnColor) return;
487 if(!myHasOwnSize){
488 myDrawer->PlaneAspect().Nullify();
489 myDrawer->DatumAspect().Nullify();
490 }
491 else{
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);
498
499 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(Col);
500 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(Col);
501 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(Col);
502 }
503
504
505 hasOwnColor=Standard_False;
506
507}
508
509//=======================================================================
510//function : ComputeFrame
511//purpose :
512//=======================================================================
513void AIS_Plane::ComputeFrame()
514{
515
516 const Handle(Geom_Plane)& pl = myComponent;
517 Standard_Real U,V;
518
519 if (myAutomaticPosition) {
520 ElSLib::Parameters(pl->Pln(),myCenter,U,V);
521 pl->D0 (U, V, myCenter);
522 }
523 else {
524 const Handle(Geom_Plane)& thegoodpl =
525 Handle(Geom_Plane)::DownCast(pl->Translated(pl->Location(),myCenter));
526 ElSLib::Parameters(thegoodpl->Pln(),myPmin,U,V);
527
528 U = 2.4*Abs(U);
529 V = 2.4*Abs(V);
530 if (U < 10*Precision::Confusion()) U=0.1;
531 if (V < 10*Precision::Confusion()) V=0.1;
532 SetSize(U,V);
533 myDrawer->PlaneAspect()->SetPlaneLength(U,V);
534 }
535}
536
537//=======================================================================
7fd59977 538//function : Compute
539//purpose : to avoid warning
540//=======================================================================
541void AIS_Plane::Compute(const Handle(Prs3d_Projector)&,
542 const Handle(Prs3d_Presentation)&)
543{
544}
545
546//=======================================================================
547//function : ComputeFields
548//purpose :
549//=======================================================================
550void AIS_Plane::ComputeFields()
551{
552 if (myIsXYZPlane){
553 Handle (Prs3d_DatumAspect) DA = myDrawer->DatumAspect();
554
555 gp_Pnt Orig = myAx2->Ax2().Location();
556 gp_Dir oX = myAx2->Ax2().XDirection();
557 gp_Dir oY = myAx2->Ax2().YDirection();
558 gp_Dir oZ = myAx2->Ax2().Direction();
559 myCenter = Orig;
560 Standard_Real xo,yo,zo,x1,y1,z1,x2,y2,z2,x3,y3,z3,x4=0,y4=0,z4=0;
561 Standard_Real x5=0,y5=0,z5=0;
562 Orig.Coord(xo,yo,zo);
563 oX.Coord(x1,y1,z1);
564 oY.Coord(x2,y2,z2);
565 oZ.Coord(x3,y3,z3);
566 Standard_Real DS1 = DA->FirstAxisLength();
567 Standard_Real DS2 = DA->SecondAxisLength();
568 Standard_Real DS3 = DA->ThirdAxisLength();
569// gp_Pnt aPt2,aPt3;
570
571 switch (myTypeOfPlane) {
572 case AIS_TOPL_XYPlane:
573 {
574 gp_Pln XYP(0,0,1,0);
575 myComponent = new Geom_Plane(XYP);
576 x4=xo+x1*DS1; y4=yo+y1*DS1; z4=zo+z1*DS1;
577 x5=xo+x2*DS2; y5=yo+y2*DS2; z5=zo+z2*DS2;
578 break;
579 }
580 case AIS_TOPL_XZPlane:
581 {
582 gp_Pln XZP(0,1,0,0);
583 myComponent = new Geom_Plane(XZP);
584 x4=xo+x1*DS1; y4=yo+y1*DS1; z4=zo+z1*DS1;
585 x5=xo+x3*DS3; y5=yo+y3*DS3; z5=zo+z3*DS3;
586 break;
587 }
588 case AIS_TOPL_YZPlane:
589 {
590 gp_Pln XZP(1,0,0,0);
591 myComponent = new Geom_Plane(XZP);
592 x4=xo+x2*DS2; y4=yo+y2*DS2; z4=zo+z2*DS2;
593 x5=xo+x3*DS3; y5=yo+y3*DS3; z5=zo+z3*DS3;
594 break;
595 }
596 default:
597 break;
598 }
599 myPmin.SetCoord(x4,y4,z4);
600 myPmax.SetCoord(x5,y5,z5);
601 }
602
603}
604//=======================================================================
605//function : InitDrawerAttributes
606//purpose :
607//=======================================================================
608
609void AIS_Plane::InitDrawerAttributes()
610{
611
612 Handle(Prs3d_ShadingAspect) shasp = new Prs3d_ShadingAspect();
613 shasp->SetMaterial(Graphic3d_NOM_PLASTIC);
614 shasp->SetColor(Quantity_NOC_GRAY40);
615 myDrawer->SetShadingAspect(shasp);
616 Handle(Graphic3d_AspectFillArea3d) asf = shasp->Aspect();
617 Graphic3d_MaterialAspect asp = asf->FrontMaterial();
618 asp.SetTransparency(0.8);
619 asf->SetFrontMaterial(asp);
620 asf->SetBackMaterial(asp);
621
622
623}
624
625//=======================================================================
626//function : AcceptDisplayMode
627//purpose :
628//=======================================================================
629
630Standard_Boolean AIS_Plane::
631AcceptDisplayMode(const Standard_Integer aMode) const
632{return aMode == 0;}
633
634
635//=======================================================================
636//function : SetContext
637//purpose :
638//=======================================================================
639
640void AIS_Plane::SetContext(const Handle(AIS_InteractiveContext)& Ctx)
641{
642 AIS_InteractiveObject::SetContext(Ctx);
643 ComputeFields();
644
645}