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