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