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