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