Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1996-12-20 |
2 | // Created by: Robert COUBLANC | |
3 | // Copyright (c) 1996-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_GraphicTool.hxx> |
19 | #include <AIS_InteractiveContext.hxx> | |
20 | #include <AIS_Shape.hxx> | |
21 | #include <Aspect_TypeOfLine.hxx> | |
7fd59977 | 22 | #include <Bnd_Box.hxx> |
23 | #include <BRep_Builder.hxx> | |
7fd59977 | 24 | #include <BRepBndLib.hxx> |
42cf5bc1 | 25 | #include <BRepTools.hxx> |
26 | #include <BRepTools_ShapeSet.hxx> | |
27 | #include <Geom_Transformation.hxx> | |
28 | #include <gp_Pnt.hxx> | |
29 | #include <Graphic3d_ArrayOfPolylines.hxx> | |
30 | #include <Graphic3d_AspectFillArea3d.hxx> | |
7fd59977 | 31 | #include <Graphic3d_AspectLine3d.hxx> |
7fd59977 | 32 | #include <Graphic3d_AspectMarker3d.hxx> |
42cf5bc1 | 33 | #include <Graphic3d_AspectText3d.hxx> |
34 | #include <Graphic3d_Group.hxx> | |
7fd59977 | 35 | #include <Graphic3d_MaterialAspect.hxx> |
48cc825e | 36 | #include <Graphic3d_SequenceOfGroup.hxx> |
42cf5bc1 | 37 | #include <Graphic3d_Structure.hxx> |
38 | #include <HLRBRep.hxx> | |
39 | #include <OSD_Timer.hxx> | |
40 | #include <Precision.hxx> | |
9dba391d | 41 | #include <Prs3d.hxx> |
42cf5bc1 | 42 | #include <Prs3d_Drawer.hxx> |
43 | #include <Prs3d_IsoAspect.hxx> | |
7fd59977 | 44 | #include <Prs3d_Presentation.hxx> |
42cf5bc1 | 45 | #include <Prs3d_Projector.hxx> |
7fd59977 | 46 | #include <Prs3d_Root.hxx> |
47 | #include <Prs3d_ShadingAspect.hxx> | |
5ad8c033 | 48 | #include <StdPrs_BndBox.hxx> |
49 | #include <StdPrs_ToolTriangulatedShape.hxx> | |
7fd59977 | 50 | #include <PrsMgr_ModedPresentation.hxx> |
42cf5bc1 | 51 | #include <Quantity_Color.hxx> |
52 | #include <Select3D_SensitiveBox.hxx> | |
7fd59977 | 53 | #include <Select3D_SensitiveEntity.hxx> |
42cf5bc1 | 54 | #include <Standard_ErrorHandler.hxx> |
55 | #include <Standard_Failure.hxx> | |
56 | #include <Standard_Type.hxx> | |
57 | #include <StdPrs_HLRPolyShape.hxx> | |
58 | #include <StdPrs_HLRShape.hxx> | |
59 | #include <StdPrs_ShadedShape.hxx> | |
42cf5bc1 | 60 | #include <StdPrs_WFShape.hxx> |
7fd59977 | 61 | #include <StdSelect.hxx> |
7fd59977 | 62 | #include <StdSelect_BRepOwner.hxx> |
42cf5bc1 | 63 | #include <StdSelect_BRepSelectionTool.hxx> |
7fd59977 | 64 | #include <StdSelect_DisplayMode.hxx> |
42cf5bc1 | 65 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
66 | #include <TopExp.hxx> | |
67 | #include <TopExp_Explorer.hxx> | |
7fd59977 | 68 | #include <TopoDS_Iterator.hxx> |
42cf5bc1 | 69 | #include <TopoDS_Shape.hxx> |
7fd59977 | 70 | |
92efcf78 | 71 | IMPLEMENT_STANDARD_RTTIEXT(AIS_Shape,AIS_InteractiveObject) |
72 | ||
7fd59977 | 73 | static Standard_Boolean IsInList(const TColStd_ListOfInteger& LL, const Standard_Integer aMode) |
74 | { | |
75 | TColStd_ListIteratorOfListOfInteger It(LL); | |
76 | for(;It.More();It.Next()){ | |
77 | if(It.Value()==aMode) | |
78 | return Standard_True;} | |
79 | return Standard_False; | |
80 | } | |
81 | ||
82 | //================================================== | |
83 | // Function: | |
84 | // Purpose : | |
85 | //================================================== | |
86 | ||
87 | AIS_Shape:: | |
88 | AIS_Shape(const TopoDS_Shape& shap): | |
89 | AIS_InteractiveObject(PrsMgr_TOP_ProjectorDependant), | |
7fd59977 | 90 | myInitAng(0.) |
91 | { | |
6262338c | 92 | Set (shap); |
7fd59977 | 93 | SetHilightMode(0); |
94 | myDrawer->SetShadingAspectGlobal(Standard_False); | |
95 | } | |
96 | ||
97 | //======================================================================= | |
98 | //function : Type | |
99 | //purpose : | |
100 | //======================================================================= | |
101 | AIS_KindOfInteractive AIS_Shape::Type() const | |
102 | {return AIS_KOI_Shape;} | |
103 | ||
104 | ||
105 | //======================================================================= | |
106 | //function : Signature | |
107 | //purpose : | |
108 | //======================================================================= | |
109 | Standard_Integer AIS_Shape::Signature() const | |
110 | {return 0;} | |
111 | ||
112 | //======================================================================= | |
113 | //function : AcceptShapeDecomposition | |
114 | //purpose : | |
115 | //======================================================================= | |
116 | Standard_Boolean AIS_Shape::AcceptShapeDecomposition() const | |
117 | {return Standard_True;} | |
118 | ||
119 | //======================================================================= | |
120 | //function : Compute | |
121 | //purpose : | |
122 | //======================================================================= | |
123 | void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/, | |
3c34883c O |
124 | const Handle(Prs3d_Presentation)& aPrs, |
125 | const Standard_Integer aMode) | |
7fd59977 | 126 | { |
127 | aPrs->Clear(); | |
128 | if(myshape.IsNull()) return; | |
129 | ||
130 | // wire,edge,vertex -> pas de HLR + priorite display superieure | |
131 | Standard_Integer TheType = (Standard_Integer) myshape.ShapeType(); | |
132 | if(TheType>4 && TheType<8) { | |
133 | aPrs->SetVisual(Graphic3d_TOS_ALL); | |
134 | aPrs->SetDisplayPriority(TheType+2); | |
135 | } | |
136 | // Shape vide -> Assemblage vide. | |
137 | if (myshape.ShapeType() == TopAbs_COMPOUND) { | |
7fd59977 | 138 | TopoDS_Iterator anExplor (myshape); |
a10fa819 | 139 | |
7fd59977 | 140 | if (!anExplor.More()) { |
141 | return; | |
142 | } | |
143 | } | |
a10fa819 | 144 | |
5ad8c033 | 145 | if (IsInfinite()) |
146 | { | |
147 | aPrs->SetInfiniteState (Standard_True); //not taken in account duting FITALL | |
7fd59977 | 148 | } |
5ad8c033 | 149 | |
150 | switch (aMode) | |
151 | { | |
152 | case AIS_WireFrame: | |
153 | { | |
154 | try | |
155 | { | |
156 | OCC_CATCH_SIGNALS | |
157 | StdPrs_WFShape::Add (aPrs, myshape, myDrawer); | |
158 | } | |
159 | catch (Standard_Failure) | |
160 | { | |
161 | #ifdef OCCT_DEBUG | |
162 | cout << "AIS_Shape::Compute() failed" << endl; | |
163 | cout << "a Shape should be incorrect : No Compute can be maked on it " << endl; | |
164 | #endif | |
165 | // presentation of the bounding box is calculated | |
166 | // Compute(aPresentationManager,aPrs,2); | |
167 | } | |
168 | break; | |
169 | } | |
170 | case AIS_Shaded: | |
7fd59977 | 171 | { |
4c513386 | 172 | if (myDrawer->IsAutoTriangulation()) |
ad3217cd | 173 | { |
4c513386 | 174 | Standard_Real anAnglePrev, anAngleNew, aCoeffPrev, aCoeffNew; |
175 | Standard_Boolean isOwnDeviationAngle = OwnDeviationAngle (anAngleNew, anAnglePrev); | |
176 | Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(aCoeffNew, aCoeffPrev); | |
177 | if ((isOwnDeviationAngle && Abs (anAngleNew - anAnglePrev) > Precision::Angular()) | |
178 | || (isOwnDeviationCoefficient && Abs (aCoeffNew - aCoeffPrev) > Precision::Confusion())) | |
179 | { | |
180 | BRepTools::Clean (myshape); | |
181 | } | |
bbf847ad | 182 | } |
ad3217cd | 183 | |
5ad8c033 | 184 | if ((Standard_Integer) myshape.ShapeType() > 4) |
185 | { | |
186 | StdPrs_WFShape::Add (aPrs, myshape, myDrawer); | |
187 | } | |
188 | else | |
189 | { | |
190 | myDrawer->SetShadingAspectGlobal (Standard_False); | |
191 | if (IsInfinite()) | |
192 | { | |
193 | StdPrs_WFShape::Add (aPrs, myshape, myDrawer); | |
194 | } | |
195 | else | |
196 | { | |
197 | try | |
198 | { | |
199 | OCC_CATCH_SIGNALS | |
200 | StdPrs_ShadedShape::Add (aPrs, myshape, myDrawer); | |
201 | } | |
202 | catch (Standard_Failure) | |
3c34883c | 203 | { |
5ad8c033 | 204 | #ifdef OCCT_DEBUG |
205 | cout << "AIS_Shape::Compute() in ShadingMode failed" << endl; | |
206 | #endif | |
207 | StdPrs_WFShape::Add (aPrs, myshape, myDrawer); | |
3c34883c O |
208 | } |
209 | } | |
7fd59977 | 210 | } |
5ad8c033 | 211 | Standard_Real aTransparency = Transparency() ; |
212 | if (aTransparency > 0.0) | |
213 | { | |
214 | SetTransparency (aTransparency); | |
7fd59977 | 215 | } |
7fd59977 | 216 | break; |
217 | } | |
5ad8c033 | 218 | |
219 | // Bounding box. | |
220 | case 2: | |
7fd59977 | 221 | { |
5ad8c033 | 222 | if (IsInfinite()) |
223 | { | |
224 | StdPrs_WFShape::Add (aPrs, myshape, myDrawer); | |
225 | } | |
226 | else | |
227 | { | |
228 | StdPrs_BndBox::Add (aPrs, BoundingBox(), myDrawer); | |
229 | } | |
7fd59977 | 230 | } |
5ad8c033 | 231 | } |
232 | ||
233 | // Recompute hidden line presentation (if necessary). | |
234 | aPrs->ReCompute(); | |
7fd59977 | 235 | } |
236 | ||
7fd59977 | 237 | //======================================================================= |
238 | //function : Compute | |
239 | //purpose : Hidden Line Removal | |
240 | //======================================================================= | |
241 | void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector, | |
3c34883c | 242 | const Handle(Prs3d_Presentation)& aPresentation) |
7fd59977 | 243 | { |
244 | Compute(aProjector,aPresentation,myshape); | |
245 | } | |
246 | ||
247 | //======================================================================= | |
248 | //function : Compute | |
249 | //purpose : | |
250 | //======================================================================= | |
251 | ||
252 | void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector, | |
3c34883c O |
253 | const Handle(Geom_Transformation)& TheTrsf, |
254 | const Handle(Prs3d_Presentation)& aPresentation) | |
7fd59977 | 255 | { |
256 | const TopLoc_Location& loc = myshape.Location(); | |
257 | TopoDS_Shape shbis = myshape.Located(TopLoc_Location(TheTrsf->Trsf())*loc); | |
258 | Compute(aProjector,aPresentation,shbis); | |
259 | } | |
260 | ||
261 | //======================================================================= | |
262 | //function : Compute | |
263 | //purpose : | |
264 | //======================================================================= | |
265 | ||
266 | void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector, | |
3c34883c O |
267 | const Handle(Prs3d_Presentation)& aPresentation, |
268 | const TopoDS_Shape& SH) | |
7fd59977 | 269 | { |
270 | if (SH.ShapeType() == TopAbs_COMPOUND) { | |
7fd59977 | 271 | TopoDS_Iterator anExplor (SH); |
a10fa819 | 272 | |
7fd59977 | 273 | if (!anExplor.More()) // Shape vide -> Assemblage vide. |
274 | return; | |
275 | } | |
a10fa819 | 276 | |
7fd59977 | 277 | Handle (Prs3d_Drawer) defdrawer = GetContext()->DefaultDrawer(); |
6262338c | 278 | if (defdrawer->DrawHiddenLine()) |
7fd59977 | 279 | {myDrawer->EnableDrawHiddenLine();} |
280 | else {myDrawer->DisableDrawHiddenLine();} | |
a10fa819 | 281 | |
7fd59977 | 282 | Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection(); |
283 | defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE); | |
284 | ||
4c513386 | 285 | if (myDrawer->IsAutoTriangulation()) |
286 | { | |
287 | // coefficients for calculation | |
288 | Standard_Real aPrevAngle, aNewAngle, aPrevCoeff, aNewCoeff; | |
289 | Standard_Boolean isOwnHLRDeviationAngle = OwnHLRDeviationAngle (aNewAngle, aPrevAngle); | |
290 | Standard_Boolean isOwnHLRDeviationCoefficient = OwnHLRDeviationCoefficient (aNewCoeff, aPrevCoeff); | |
291 | if (((Abs (aNewAngle - aPrevAngle) > Precision::Angular()) && isOwnHLRDeviationAngle) || | |
292 | ((Abs (aNewCoeff - aPrevCoeff) > Precision::Confusion()) && isOwnHLRDeviationCoefficient)) | |
293 | { | |
7fd59977 | 294 | BRepTools::Clean(SH); |
295 | } | |
4c513386 | 296 | } |
7fd59977 | 297 | |
298 | { | |
299 | try { | |
300 | OCC_CATCH_SIGNALS | |
0a768f56 | 301 | switch (TypeOfHLR()) { |
302 | case Prs3d_TOH_Algo: | |
303 | StdPrs_HLRShape::Add (aPresentation, SH, myDrawer, aProjector); | |
304 | break; | |
305 | case Prs3d_TOH_PolyAlgo: | |
306 | default: | |
307 | StdPrs_HLRPolyShape::Add (aPresentation, SH, myDrawer, aProjector); | |
308 | break; | |
309 | } | |
7fd59977 | 310 | } |
311 | catch (Standard_Failure) { | |
0797d9d3 | 312 | #ifdef OCCT_DEBUG |
7fd59977 | 313 | cout <<"AIS_Shape::Compute(Proj) HLR Algorithm failed" << endl; |
314 | #endif | |
315 | StdPrs_WFShape::Add(aPresentation,SH,myDrawer); | |
316 | } | |
317 | } | |
318 | ||
7fd59977 | 319 | defdrawer->SetTypeOfDeflection (prevdef); |
320 | } | |
321 | ||
322 | //======================================================================= | |
323 | //function : SelectionType | |
324 | //purpose : gives the type according to the Index of Selection Mode | |
325 | //======================================================================= | |
326 | ||
327 | TopAbs_ShapeEnum AIS_Shape::SelectionType(const Standard_Integer aMode) | |
328 | { | |
329 | switch(aMode){ | |
330 | case 1: | |
331 | return TopAbs_VERTEX; | |
332 | case 2: | |
333 | return TopAbs_EDGE; | |
334 | case 3: | |
335 | return TopAbs_WIRE; | |
336 | case 4: | |
337 | return TopAbs_FACE; | |
338 | case 5: | |
339 | return TopAbs_SHELL; | |
340 | case 6: | |
341 | return TopAbs_SOLID; | |
342 | case 7: | |
343 | return TopAbs_COMPSOLID; | |
344 | case 8: | |
345 | return TopAbs_COMPOUND; | |
346 | case 0: | |
347 | default: | |
348 | return TopAbs_SHAPE; | |
349 | } | |
350 | ||
351 | } | |
352 | //======================================================================= | |
353 | //function : SelectionType | |
354 | //purpose : gives the SelectionMode according to the Type od Decomposition... | |
355 | //======================================================================= | |
356 | Standard_Integer AIS_Shape::SelectionMode(const TopAbs_ShapeEnum aType) | |
357 | { | |
358 | switch(aType){ | |
359 | case TopAbs_VERTEX: | |
360 | return 1; | |
361 | case TopAbs_EDGE: | |
362 | return 2; | |
363 | case TopAbs_WIRE: | |
364 | return 3; | |
365 | case TopAbs_FACE: | |
366 | return 4; | |
367 | case TopAbs_SHELL: | |
368 | return 5; | |
369 | case TopAbs_SOLID: | |
370 | return 6; | |
371 | case TopAbs_COMPSOLID: | |
372 | return 7; | |
373 | case TopAbs_COMPOUND: | |
374 | return 8; | |
375 | case TopAbs_SHAPE: | |
376 | default: | |
377 | return 0; | |
378 | } | |
379 | } | |
380 | ||
381 | ||
382 | //======================================================================= | |
383 | //function : ComputeSelection | |
384 | //purpose : | |
385 | //======================================================================= | |
386 | ||
387 | void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, | |
3c34883c | 388 | const Standard_Integer aMode) |
7fd59977 | 389 | { |
390 | if(myshape.IsNull()) return; | |
391 | if (myshape.ShapeType() == TopAbs_COMPOUND) { | |
7fd59977 | 392 | TopoDS_Iterator anExplor (myshape); |
a10fa819 | 393 | |
81bba717 | 394 | if (!anExplor.More()) // empty Shape -> empty Assembly. |
7fd59977 | 395 | return; |
396 | } | |
397 | ||
016e5959 | 398 | TopAbs_ShapeEnum TypOfSel = AIS_Shape::SelectionType(aMode); |
7fd59977 | 399 | TopoDS_Shape shape = myshape; |
7fd59977 | 400 | |
81bba717 | 401 | // POP protection against crash in low layers |
7fd59977 | 402 | |
9dba391d | 403 | Standard_Real aDeflection = Prs3d::GetDeflection(shape, myDrawer); |
7fd59977 | 404 | try { |
405 | OCC_CATCH_SIGNALS | |
406 | StdSelect_BRepSelectionTool::Load(aSelection, | |
407 | this, | |
408 | shape, | |
409 | TypOfSel, | |
410 | aDeflection, | |
3c34883c | 411 | myDrawer->HLRAngle(), |
4c513386 | 412 | myDrawer->IsAutoTriangulation()); |
7fd59977 | 413 | } catch ( Standard_Failure ) { |
414 | // cout << "a Shape should be incorrect : A Selection on the Bnd is activated "<<endl; | |
415 | if ( aMode == 0 ) { | |
53a70197 | 416 | aSelection->Clear(); |
7fd59977 | 417 | Bnd_Box B = BoundingBox(); |
418 | Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(shape,this); | |
419 | Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox(aOwner,B); | |
420 | aSelection->Add(aSensitiveBox); | |
421 | } | |
422 | } | |
423 | ||
424 | // insert the drawer in the BrepOwners for hilight... | |
425 | StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer); | |
426 | } | |
427 | ||
7fd59977 | 428 | Quantity_NameOfColor AIS_Shape::Color() const { |
429 | Quantity_Color aColor; | |
430 | Color(aColor); | |
431 | return aColor.Name(); | |
432 | } | |
433 | ||
434 | void AIS_Shape::Color( Quantity_Color& aColor ) const { | |
435 | aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel); | |
436 | } | |
437 | ||
438 | Graphic3d_NameOfMaterial AIS_Shape::Material() const { | |
439 | return (myDrawer->ShadingAspect()->Material(myCurrentFacingModel)).Name(); | |
440 | } | |
441 | ||
442 | Standard_Real AIS_Shape::Transparency() const { | |
443 | return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel); | |
444 | } | |
7fd59977 | 445 | |
446 | //======================================================================= | |
447 | //function : SetColor | |
448 | //purpose : | |
449 | //======================================================================= | |
450 | ||
451 | void AIS_Shape::SetColor(const Quantity_NameOfColor aCol) | |
7fd59977 | 452 | { |
453 | SetColor(Quantity_Color(aCol)); | |
454 | } | |
455 | ||
5cbef0fe | 456 | //======================================================================= |
ad3217cd | 457 | //function : setColor |
458 | //purpose : | |
5cbef0fe S |
459 | //======================================================================= |
460 | ||
6262338c | 461 | void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer, |
462 | const Quantity_Color& theColor) const | |
7fd59977 | 463 | { |
6262338c | 464 | if (!theDrawer->HasOwnShadingAspect()) |
ad3217cd | 465 | { |
466 | theDrawer->SetShadingAspect (new Prs3d_ShadingAspect()); | |
6262338c | 467 | if (theDrawer->HasLink()) |
468 | { | |
469 | *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect(); | |
470 | } | |
7fd59977 | 471 | } |
6262338c | 472 | if (!theDrawer->HasOwnLineAspect()) |
ad3217cd | 473 | { |
474 | theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); | |
6262338c | 475 | if (theDrawer->HasLink()) |
476 | { | |
477 | *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect(); | |
478 | } | |
ad3217cd | 479 | } |
6262338c | 480 | if (!theDrawer->HasOwnWireAspect()) |
ad3217cd | 481 | { |
482 | theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); | |
6262338c | 483 | if (theDrawer->HasLink()) |
484 | { | |
485 | *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect(); | |
486 | } | |
ad3217cd | 487 | } |
6262338c | 488 | if (!theDrawer->HasOwnPointAspect()) |
ad3217cd | 489 | { |
7d835040 | 490 | theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_BLACK, 1.0)); |
6262338c | 491 | if (theDrawer->HasLink()) |
492 | { | |
493 | *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect(); | |
494 | } | |
ad3217cd | 495 | } |
8a5dfb38 | 496 | if (!theDrawer->HasOwnFreeBoundaryAspect()) |
497 | { | |
498 | theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); | |
499 | if (theDrawer->HasLink()) | |
500 | { | |
501 | *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect(); | |
502 | } | |
503 | } | |
504 | if (!theDrawer->HasOwnUnFreeBoundaryAspect()) | |
505 | { | |
506 | theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); | |
507 | if (theDrawer->HasLink()) | |
508 | { | |
509 | *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect(); | |
510 | } | |
511 | } | |
512 | if (!theDrawer->HasOwnSeenLineAspect()) | |
513 | { | |
514 | theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); | |
515 | if (theDrawer->HasLink()) | |
516 | { | |
517 | *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect(); | |
518 | } | |
519 | } | |
ad3217cd | 520 | |
521 | // override color | |
522 | theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel); | |
523 | theDrawer->SetShadingAspectGlobal (Standard_False); | |
524 | theDrawer->LineAspect()->SetColor (theColor); | |
525 | theDrawer->WireAspect()->SetColor (theColor); | |
526 | theDrawer->PointAspect()->SetColor (theColor); | |
8a5dfb38 | 527 | theDrawer->FreeBoundaryAspect()->SetColor (theColor); |
528 | theDrawer->UnFreeBoundaryAspect()->SetColor (theColor); | |
529 | theDrawer->SeenLineAspect()->SetColor (theColor); | |
ad3217cd | 530 | } |
a10fa819 | 531 | |
ad3217cd | 532 | //======================================================================= |
533 | //function : SetColor | |
534 | //purpose : | |
535 | //======================================================================= | |
7fd59977 | 536 | |
ad3217cd | 537 | void AIS_Shape::SetColor (const Quantity_Color& theColor) |
538 | { | |
539 | setColor (myDrawer, theColor); | |
540 | myOwnColor = theColor; | |
541 | hasOwnColor = Standard_True; | |
7fd59977 | 542 | |
48cc825e | 543 | // modify shading presentation without re-computation |
544 | const PrsMgr_Presentations& aPrsList = Presentations(); | |
545 | Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect(); | |
546 | Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect(); | |
547 | Handle(Graphic3d_AspectMarker3d) aPointAspect = myDrawer->PointAspect()->Aspect(); | |
548 | for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt) | |
ad3217cd | 549 | { |
48cc825e | 550 | const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt); |
551 | if (aPrsModed.Mode() != AIS_Shaded) | |
ad3217cd | 552 | { |
48cc825e | 553 | continue; |
554 | } | |
555 | ||
556 | const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation(); | |
557 | ||
558 | // Set aspects for presentation | |
559 | aPrs->SetPrimitivesAspect (anAreaAspect); | |
560 | aPrs->SetPrimitivesAspect (aLineAspect); | |
561 | aPrs->SetPrimitivesAspect (aPointAspect); | |
562 | ||
563 | // Go through all groups to change color for all primitives | |
564 | for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next()) | |
565 | { | |
566 | const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value(); | |
567 | ||
a10fa819 A |
568 | // Check if aspect of given type is set for the group, |
569 | // because setting aspect for group with no already set aspect | |
570 | // can lead to loss of presentation data | |
48cc825e | 571 | if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA)) |
ad3217cd | 572 | { |
48cc825e | 573 | aGroup->SetGroupPrimitivesAspect (anAreaAspect); |
ad3217cd | 574 | } |
48cc825e | 575 | if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE)) |
ad3217cd | 576 | { |
48cc825e | 577 | aGroup->SetGroupPrimitivesAspect (aLineAspect); |
ad3217cd | 578 | } |
48cc825e | 579 | if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER)) |
ad3217cd | 580 | { |
48cc825e | 581 | aGroup->SetGroupPrimitivesAspect (aPointAspect); |
ad3217cd | 582 | } |
a10fa819 | 583 | } |
7fd59977 | 584 | } |
585 | ||
ad3217cd | 586 | LoadRecomputable (AIS_WireFrame); |
587 | LoadRecomputable (2); | |
7fd59977 | 588 | } |
5cbef0fe | 589 | |
7fd59977 | 590 | //======================================================================= |
591 | //function : UnsetColor | |
ad3217cd | 592 | //purpose : |
7fd59977 | 593 | //======================================================================= |
594 | ||
595 | void AIS_Shape::UnsetColor() | |
596 | { | |
ad3217cd | 597 | if (!HasColor()) |
5cbef0fe S |
598 | { |
599 | myToRecomputeModes.Clear(); | |
600 | return; | |
601 | } | |
7fd59977 | 602 | hasOwnColor = Standard_False; |
603 | ||
ad3217cd | 604 | if (!HasWidth()) |
605 | { | |
606 | Handle(Prs3d_LineAspect) anEmptyAsp; | |
607 | myDrawer->SetLineAspect (anEmptyAsp); | |
608 | myDrawer->SetWireAspect (anEmptyAsp); | |
609 | myDrawer->SetFreeBoundaryAspect (anEmptyAsp); | |
610 | myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp); | |
611 | myDrawer->SetSeenLineAspect (anEmptyAsp); | |
612 | } | |
613 | else | |
614 | { | |
6262338c | 615 | Quantity_Color aColor = Quantity_NOC_YELLOW; |
616 | if (myDrawer->HasLink()) | |
617 | { | |
618 | AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, aColor); | |
619 | } | |
ad3217cd | 620 | myDrawer->LineAspect()->SetColor (aColor); |
6262338c | 621 | aColor = Quantity_NOC_RED; |
622 | if (myDrawer->HasLink()) | |
623 | { | |
624 | AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire, aColor); | |
625 | } | |
ad3217cd | 626 | myDrawer->WireAspect()->SetColor (aColor); |
6262338c | 627 | aColor = Quantity_NOC_GREEN; |
628 | if (myDrawer->HasLink()) | |
629 | { | |
630 | AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free, aColor); | |
631 | } | |
ad3217cd | 632 | myDrawer->FreeBoundaryAspect()->SetColor (aColor); |
6262338c | 633 | aColor = Quantity_NOC_YELLOW; |
634 | if (myDrawer->HasLink()) | |
635 | { | |
636 | AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor); | |
637 | } | |
ad3217cd | 638 | myDrawer->UnFreeBoundaryAspect()->SetColor (aColor); |
6262338c | 639 | if (myDrawer->HasLink()) |
640 | { | |
641 | AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen, aColor); | |
642 | } | |
ad3217cd | 643 | myDrawer->SeenLineAspect()->SetColor (aColor); |
644 | } | |
645 | ||
646 | if (HasMaterial() | |
647 | || IsTransparent()) | |
648 | { | |
6262338c | 649 | Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS); |
650 | Graphic3d_MaterialAspect mat = aDefaultMat; | |
651 | if (HasMaterial() || myDrawer->HasLink()) | |
652 | { | |
653 | mat = AIS_GraphicTool::GetMaterial(HasMaterial()? myDrawer : myDrawer->Link()); | |
654 | } | |
ad3217cd | 655 | if (HasMaterial()) |
656 | { | |
6262338c | 657 | Quantity_Color aColor = aDefaultMat.AmbientColor(); |
658 | if (myDrawer->HasLink()) | |
659 | { | |
4e2914a6 | 660 | aColor = myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel); |
6262338c | 661 | } |
ad3217cd | 662 | mat.SetColor (aColor); |
5cbef0fe | 663 | } |
ad3217cd | 664 | if (IsTransparent()) |
665 | { | |
666 | Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel); | |
667 | mat.SetTransparency (aTransp); | |
5cbef0fe | 668 | } |
ad3217cd | 669 | myDrawer->ShadingAspect()->SetMaterial (mat ,myCurrentFacingModel); |
5cbef0fe | 670 | } |
ad3217cd | 671 | else |
672 | { | |
673 | myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)()); | |
5cbef0fe | 674 | } |
ad3217cd | 675 | myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)()); |
5cbef0fe | 676 | |
48cc825e | 677 | // modify shading presentation without re-computation |
678 | const PrsMgr_Presentations& aPrsList = Presentations(); | |
679 | Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect(); | |
680 | Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect(); | |
681 | for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt) | |
ad3217cd | 682 | { |
48cc825e | 683 | const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt); |
684 | if (aPrsModed.Mode() != AIS_Shaded) | |
ad3217cd | 685 | { |
48cc825e | 686 | continue; |
687 | } | |
688 | ||
689 | const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation(); | |
690 | ||
691 | aPrs->SetPrimitivesAspect (anAreaAsp); | |
692 | aPrs->SetPrimitivesAspect (aLineAsp); | |
693 | ||
694 | for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next()) | |
695 | { | |
696 | const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value(); | |
697 | ||
698 | // Check if aspect of given type is set for the group, | |
a10fa819 A |
699 | // because setting aspect for group with no already set aspect |
700 | // can lead to loss of presentation data | |
ad3217cd | 701 | if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA)) |
702 | { | |
703 | aGroup->SetGroupPrimitivesAspect (anAreaAsp); | |
704 | } | |
705 | if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE)) | |
706 | { | |
707 | aGroup->SetGroupPrimitivesAspect (aLineAsp); | |
708 | } | |
7fd59977 | 709 | } |
5cbef0fe | 710 | } |
48cc825e | 711 | |
ad3217cd | 712 | LoadRecomputable (AIS_WireFrame); |
713 | LoadRecomputable (2); | |
714 | } | |
715 | ||
716 | //======================================================================= | |
717 | //function : setWidth | |
718 | //purpose : | |
719 | //======================================================================= | |
720 | ||
6262338c | 721 | void AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer, |
722 | const Standard_Real theLineWidth) const | |
ad3217cd | 723 | { |
6262338c | 724 | if (!theDrawer->HasOwnLineAspect()) |
ad3217cd | 725 | { |
726 | theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); | |
6262338c | 727 | if (theDrawer->HasLink()) |
728 | { | |
729 | *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect(); | |
730 | } | |
ad3217cd | 731 | } |
6262338c | 732 | if (!theDrawer->HasOwnWireAspect()) |
ad3217cd | 733 | { |
734 | theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); | |
6262338c | 735 | if (theDrawer->HasLink()) |
736 | { | |
737 | *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect(); | |
738 | } | |
ad3217cd | 739 | } |
8a5dfb38 | 740 | if (!theDrawer->HasOwnFreeBoundaryAspect()) |
741 | { | |
742 | theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); | |
743 | if (theDrawer->HasLink()) | |
744 | { | |
745 | *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect(); | |
746 | } | |
747 | } | |
748 | if (!theDrawer->HasOwnUnFreeBoundaryAspect()) | |
749 | { | |
750 | theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); | |
751 | if (theDrawer->HasLink()) | |
752 | { | |
753 | *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect(); | |
754 | } | |
755 | } | |
756 | if (!theDrawer->HasOwnSeenLineAspect()) | |
757 | { | |
758 | theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); | |
759 | if (theDrawer->HasLink()) | |
760 | { | |
761 | *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect(); | |
762 | } | |
763 | } | |
ad3217cd | 764 | |
765 | // override width | |
766 | theDrawer->LineAspect()->SetWidth (theLineWidth); | |
767 | theDrawer->WireAspect()->SetWidth (theLineWidth); | |
8a5dfb38 | 768 | theDrawer->FreeBoundaryAspect()->SetWidth (theLineWidth); |
769 | theDrawer->UnFreeBoundaryAspect()->SetWidth (theLineWidth); | |
770 | theDrawer->SeenLineAspect()->SetWidth (theLineWidth); | |
7fd59977 | 771 | } |
772 | ||
7fd59977 | 773 | //======================================================================= |
774 | //function : SetWidth | |
775 | //purpose : | |
776 | //======================================================================= | |
777 | ||
ad3217cd | 778 | void AIS_Shape::SetWidth (const Standard_Real theLineWidth) |
7fd59977 | 779 | { |
ad3217cd | 780 | setWidth (myDrawer, theLineWidth); |
781 | myOwnWidth = theLineWidth; | |
782 | LoadRecomputable (AIS_WireFrame); // means that it is necessary to recompute only the wireframe.... | |
783 | LoadRecomputable (2); // and the bounding box... | |
7fd59977 | 784 | } |
785 | ||
786 | //======================================================================= | |
787 | //function : UnsetWidth | |
ad3217cd | 788 | //purpose : |
7fd59977 | 789 | //======================================================================= |
790 | ||
791 | void AIS_Shape::UnsetWidth() | |
792 | { | |
ad3217cd | 793 | if (myOwnWidth == 0.0) |
5cbef0fe S |
794 | { |
795 | myToRecomputeModes.Clear(); | |
796 | return; | |
797 | } | |
5cbef0fe | 798 | |
ad3217cd | 799 | myOwnWidth = 0.0; |
800 | ||
801 | Handle(Prs3d_LineAspect) anEmptyAsp; | |
5cbef0fe | 802 | |
ad3217cd | 803 | if (!HasColor()) |
804 | { | |
805 | myDrawer->SetLineAspect (anEmptyAsp); | |
806 | myDrawer->SetWireAspect (anEmptyAsp); | |
807 | myDrawer->SetFreeBoundaryAspect (anEmptyAsp); | |
808 | myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp); | |
809 | myDrawer->SetSeenLineAspect (anEmptyAsp); | |
7fd59977 | 810 | } |
ad3217cd | 811 | else |
812 | { | |
6262338c | 813 | myDrawer->LineAspect() ->SetWidth (myDrawer->HasLink() ? |
814 | AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.); | |
815 | myDrawer->WireAspect() ->SetWidth (myDrawer->HasLink() ? | |
816 | AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Wire) : 1.); | |
817 | myDrawer->FreeBoundaryAspect() ->SetWidth (myDrawer->HasLink() ? | |
818 | AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Free) : 1.); | |
819 | myDrawer->UnFreeBoundaryAspect()->SetWidth (myDrawer->HasLink() ? | |
820 | AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree) : 1.); | |
821 | myDrawer->SeenLineAspect() ->SetWidth (myDrawer->HasLink() ? | |
822 | AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen) : 1.); | |
7fd59977 | 823 | } |
ad3217cd | 824 | LoadRecomputable (AIS_WireFrame); |
7fd59977 | 825 | } |
826 | ||
e0608a8d | 827 | //======================================================================= |
828 | //function : setMaterial | |
829 | //purpose : | |
830 | //======================================================================= | |
831 | ||
6262338c | 832 | void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)& theDrawer, |
e0608a8d | 833 | const Graphic3d_MaterialAspect& theMaterial, |
834 | const Standard_Boolean theToKeepColor, | |
835 | const Standard_Boolean theToKeepTransp) const | |
836 | { | |
837 | const Quantity_Color aColor = theDrawer->ShadingAspect()->Material (myCurrentFacingModel).Color(); | |
838 | const Standard_Real aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel); | |
6262338c | 839 | if (!theDrawer->HasOwnShadingAspect()) |
e0608a8d | 840 | { |
841 | theDrawer->SetShadingAspect (new Prs3d_ShadingAspect()); | |
6262338c | 842 | if (theDrawer->HasLink()) |
843 | { | |
844 | *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect(); | |
845 | } | |
e0608a8d | 846 | } |
847 | theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel); | |
848 | ||
849 | if (theToKeepColor) | |
850 | { | |
851 | theDrawer->ShadingAspect()->SetColor (aColor, myCurrentFacingModel); | |
852 | } | |
853 | if (theToKeepTransp) | |
854 | { | |
855 | theDrawer->ShadingAspect()->SetTransparency (aTransp, myCurrentFacingModel); | |
856 | } | |
857 | } | |
858 | ||
7fd59977 | 859 | //======================================================================= |
860 | //function : SetMaterial | |
861 | //purpose : | |
862 | //======================================================================= | |
5cbef0fe | 863 | |
7fd59977 | 864 | void AIS_Shape::SetMaterial(const Graphic3d_NameOfMaterial aMat) |
865 | { | |
a10fa819 | 866 | SetMaterial(Graphic3d_MaterialAspect(aMat)); |
7fd59977 | 867 | } |
5cbef0fe | 868 | |
7fd59977 | 869 | //======================================================================= |
870 | //function : SetMaterial | |
ad3217cd | 871 | //purpose : |
7fd59977 | 872 | //======================================================================= |
5cbef0fe | 873 | |
ad3217cd | 874 | void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat) |
7fd59977 | 875 | { |
e0608a8d | 876 | setMaterial (myDrawer, theMat, HasColor(), IsTransparent()); |
7fd59977 | 877 | hasOwnMaterial = Standard_True; |
5cbef0fe | 878 | |
48cc825e | 879 | // modify shading presentation without re-computation |
880 | const PrsMgr_Presentations& aPrsList = Presentations(); | |
881 | Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect(); | |
882 | for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt) | |
ad3217cd | 883 | { |
48cc825e | 884 | const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt); |
885 | if (aPrsModed.Mode() != AIS_Shaded) | |
af324faa | 886 | { |
48cc825e | 887 | continue; |
888 | } | |
889 | ||
890 | const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation(); | |
891 | aPrs->SetPrimitivesAspect (anAreaAsp); | |
892 | for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next()) | |
893 | { | |
894 | const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value(); | |
895 | ||
a10fa819 A |
896 | // Check if aspect of given type is set for the group, |
897 | // because setting aspect for group with no already set aspect | |
898 | // can lead to loss of presentation data | |
ad3217cd | 899 | if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA)) |
900 | { | |
901 | aGroup->SetGroupPrimitivesAspect (anAreaAsp); | |
902 | } | |
5cbef0fe | 903 | } |
7fd59977 | 904 | } |
48cc825e | 905 | |
906 | myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update | |
907 | myToRecomputeModes.Clear(); | |
7fd59977 | 908 | } |
ad3217cd | 909 | |
7fd59977 | 910 | //======================================================================= |
911 | //function : UnsetMaterial | |
ad3217cd | 912 | //purpose : |
7fd59977 | 913 | //======================================================================= |
5cbef0fe | 914 | |
7fd59977 | 915 | void AIS_Shape::UnsetMaterial() |
916 | { | |
ad3217cd | 917 | if (!HasMaterial()) |
918 | { | |
919 | return; | |
920 | } | |
5cbef0fe | 921 | |
ad3217cd | 922 | if (HasColor() |
923 | || IsTransparent()) | |
924 | { | |
6262338c | 925 | if(myDrawer->HasLink()) |
926 | { | |
927 | myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel), | |
928 | myCurrentFacingModel); | |
929 | } | |
ad3217cd | 930 | if (HasColor()) |
931 | { | |
932 | myDrawer->ShadingAspect()->SetColor (myOwnColor, myCurrentFacingModel); | |
933 | myDrawer->ShadingAspect()->SetTransparency (myTransparency, myCurrentFacingModel); | |
7fd59977 | 934 | } |
ad3217cd | 935 | } |
936 | else | |
937 | { | |
938 | myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)()); | |
7fd59977 | 939 | } |
940 | hasOwnMaterial = Standard_False; | |
ad3217cd | 941 | |
48cc825e | 942 | // modify shading presentation without re-computation |
943 | const PrsMgr_Presentations& aPrsList = Presentations(); | |
944 | Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect(); | |
945 | for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt) | |
ad3217cd | 946 | { |
48cc825e | 947 | const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt); |
948 | if (aPrsModed.Mode() != AIS_Shaded) | |
ad3217cd | 949 | { |
48cc825e | 950 | continue; |
951 | } | |
952 | ||
953 | const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation(); | |
954 | aPrs->SetPrimitivesAspect (anAreaAsp); | |
955 | for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next()) | |
956 | { | |
957 | const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value(); | |
ad3217cd | 958 | if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA)) |
959 | { | |
960 | aGroup->SetGroupPrimitivesAspect (anAreaAsp); | |
961 | } | |
7fd59977 | 962 | } |
963 | } | |
48cc825e | 964 | |
ad3217cd | 965 | myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update |
7fd59977 | 966 | myToRecomputeModes.Clear(); |
7fd59977 | 967 | } |
5cbef0fe | 968 | |
7fd59977 | 969 | //======================================================================= |
ad3217cd | 970 | //function : setTransparency |
971 | //purpose : | |
7fd59977 | 972 | //======================================================================= |
973 | ||
6262338c | 974 | void AIS_Shape::setTransparency (const Handle(Prs3d_Drawer)& theDrawer, |
975 | const Standard_Real theValue) const | |
7fd59977 | 976 | { |
6262338c | 977 | if (!theDrawer->HasOwnShadingAspect()) |
ad3217cd | 978 | { |
979 | theDrawer->SetShadingAspect (new Prs3d_ShadingAspect()); | |
6262338c | 980 | if (theDrawer->HasLink()) |
981 | { | |
982 | *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect(); | |
983 | } | |
7fd59977 | 984 | } |
5cbef0fe | 985 | |
ad3217cd | 986 | // override transparency |
987 | theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel); | |
988 | } | |
989 | ||
990 | //======================================================================= | |
991 | //function : SetTransparency | |
992 | //purpose : | |
993 | //======================================================================= | |
994 | ||
995 | void AIS_Shape::SetTransparency (const Standard_Real theValue) | |
996 | { | |
997 | setTransparency (myDrawer, theValue); | |
998 | myTransparency = theValue; | |
999 | ||
48cc825e | 1000 | // modify shading presentation without re-computation |
1001 | const PrsMgr_Presentations& aPrsList = Presentations(); | |
1002 | Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect(); | |
1003 | for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt) | |
ad3217cd | 1004 | { |
48cc825e | 1005 | const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt); |
1006 | if (aPrsModed.Mode() != AIS_Shaded) | |
ad3217cd | 1007 | { |
48cc825e | 1008 | continue; |
1009 | } | |
1010 | ||
1011 | const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation(); | |
1012 | aPrs->SetPrimitivesAspect (anAreaAsp); | |
1013 | aPrs->SetDisplayPriority (10); // force highest priority for translucent objects | |
1014 | for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next()) | |
1015 | { | |
1016 | const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value(); | |
ad3217cd | 1017 | if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA)) |
1018 | { | |
1019 | aGroup->SetGroupPrimitivesAspect (anAreaAsp); | |
1020 | } | |
7fd59977 | 1021 | } |
1022 | } | |
48cc825e | 1023 | |
ad3217cd | 1024 | myRecomputeEveryPrs = Standard_False; // no mode to recalculate - only viewer update |
5cbef0fe | 1025 | myToRecomputeModes.Clear(); |
7fd59977 | 1026 | } |
1027 | ||
1028 | //======================================================================= | |
1029 | //function : UnsetTransparency | |
ad3217cd | 1030 | //purpose : |
7fd59977 | 1031 | //======================================================================= |
5cbef0fe | 1032 | |
7fd59977 | 1033 | void AIS_Shape::UnsetTransparency() |
1034 | { | |
7fd59977 | 1035 | myTransparency = 0.0; |
6262338c | 1036 | if (!myDrawer->HasOwnShadingAspect()) |
ad3217cd | 1037 | { |
1038 | return; | |
1039 | } | |
1040 | else if (HasColor() || HasMaterial()) | |
1041 | { | |
1042 | myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel); | |
1043 | } | |
1044 | else | |
1045 | { | |
1046 | myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)()); | |
1047 | } | |
5cbef0fe | 1048 | |
48cc825e | 1049 | // modify shading presentation without re-computation |
1050 | const PrsMgr_Presentations& aPrsList = Presentations(); | |
1051 | Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect(); | |
1052 | for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt) | |
ad3217cd | 1053 | { |
48cc825e | 1054 | const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt); |
1055 | if (aPrsModed.Mode() != AIS_Shaded) | |
ad3217cd | 1056 | { |
48cc825e | 1057 | continue; |
1058 | } | |
1059 | ||
1060 | const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation(); | |
1061 | aPrs->SetPrimitivesAspect (anAreaAsp); | |
1062 | for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next()) | |
1063 | { | |
1064 | const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value(); | |
ad3217cd | 1065 | if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA)) |
1066 | { | |
1067 | aGroup->SetGroupPrimitivesAspect (anAreaAsp); | |
1068 | } | |
7fd59977 | 1069 | } |
48cc825e | 1070 | aPrs->ResetDisplayPriority(); |
7fd59977 | 1071 | } |
48cc825e | 1072 | |
ad3217cd | 1073 | myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update |
5cbef0fe | 1074 | myToRecomputeModes.Clear(); |
7fd59977 | 1075 | } |
1076 | ||
5cbef0fe S |
1077 | //======================================================================= |
1078 | //function : LoadRecomputable | |
1079 | //purpose : | |
1080 | //======================================================================= | |
7fd59977 | 1081 | |
1082 | void AIS_Shape::LoadRecomputable(const Standard_Integer TheMode) | |
1083 | { | |
5cbef0fe | 1084 | myRecomputeEveryPrs = Standard_False; |
7fd59977 | 1085 | if(!IsInList(myToRecomputeModes,TheMode)) |
1086 | myToRecomputeModes.Append(TheMode); | |
1087 | } | |
1088 | ||
7fd59977 | 1089 | //======================================================================= |
1090 | //function : BoundingBox | |
1091 | //purpose : | |
1092 | //======================================================================= | |
1093 | ||
1094 | const Bnd_Box& AIS_Shape::BoundingBox() | |
1095 | { | |
1096 | if (myshape.ShapeType() == TopAbs_COMPOUND) { | |
7fd59977 | 1097 | TopoDS_Iterator anExplor (myshape); |
a10fa819 | 1098 | |
81bba717 | 1099 | if (!anExplor.More()) { // empty Shape -> empty Assembly. |
a10fa819 | 1100 | myBB.SetVoid(); |
7fd59977 | 1101 | return myBB; |
1102 | } | |
1103 | } | |
1104 | ||
1105 | if(myCompBB) { | |
1106 | BRepBndLib::AddClose(myshape, myBB); | |
a10fa819 | 1107 | myCompBB = Standard_False; |
7fd59977 | 1108 | } |
1109 | return myBB; | |
1110 | } | |
1111 | ||
1112 | //***** | |
1113 | //***** Reset | |
1114 | //======================================================================= | |
1115 | //function : SetOwnDeviationCoefficient | |
1116 | //purpose : resets myhasOwnDeviationCoefficient to Standard_False and | |
1117 | // returns Standard_True if it change | |
1118 | //======================================================================= | |
1119 | ||
1120 | Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient () | |
1121 | { | |
6262338c | 1122 | Standard_Boolean itSet = myDrawer->HasOwnDeviationCoefficient(); |
7fd59977 | 1123 | if(itSet) myDrawer->SetDeviationCoefficient(); |
1124 | return itSet; | |
7fd59977 | 1125 | } |
1126 | ||
7fd59977 | 1127 | //======================================================================= |
1128 | //function : SetHLROwnDeviationCoefficient | |
1129 | //purpose : resets myhasOwnHLRDeviationCoefficient to Standard_False and | |
1130 | // returns Standard_True if it change | |
1131 | //======================================================================= | |
1132 | ||
1133 | Standard_Boolean AIS_Shape::SetOwnHLRDeviationCoefficient () | |
1134 | { | |
6262338c | 1135 | Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationCoefficient(); |
7fd59977 | 1136 | if(itSet) myDrawer->SetHLRDeviationCoefficient(); |
1137 | return itSet; | |
1138 | ||
1139 | } | |
1140 | ||
1141 | //======================================================================= | |
1142 | //function : SetOwnDeviationAngle | |
1143 | //purpose : resets myhasOwnDeviationAngle to Standard_False and | |
1144 | // returns Standard_True if it change | |
1145 | //======================================================================= | |
1146 | ||
1147 | Standard_Boolean AIS_Shape::SetOwnDeviationAngle () | |
1148 | { | |
6262338c | 1149 | Standard_Boolean itSet = myDrawer->HasOwnDeviationAngle(); |
7fd59977 | 1150 | if(itSet) myDrawer->SetDeviationAngle(); |
1151 | return itSet; | |
1152 | ||
1153 | } | |
1154 | ||
1155 | //======================================================================= | |
1156 | //function : SetOwnHLRDeviationAngle | |
1157 | //purpose : resets myhasOwnHLRDeviationAngle to Standard_False and | |
1158 | // returns Standard_True if it change | |
1159 | //======================================================================= | |
1160 | ||
1161 | Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle () | |
1162 | { | |
6262338c | 1163 | Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationAngle(); |
7fd59977 | 1164 | if(itSet) myDrawer->SetHLRAngle(); |
1165 | return itSet; | |
1166 | ||
1167 | } | |
1168 | //***** SetOwn | |
1169 | //======================================================================= | |
1170 | //function : SetOwnDeviationCoefficient | |
1171 | //purpose : | |
1172 | //======================================================================= | |
1173 | ||
1174 | void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real aCoefficient ) | |
1175 | { | |
1176 | myDrawer->SetDeviationCoefficient( aCoefficient ); | |
1177 | SetToUpdate(0) ; // WireFrame | |
1178 | SetToUpdate(1) ; // Shadding | |
1179 | } | |
1180 | ||
1181 | //======================================================================= | |
1182 | //function : SetOwnHLRDeviationCoefficient | |
1183 | //purpose : | |
1184 | //======================================================================= | |
1185 | ||
1186 | void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real aCoefficient ) | |
1187 | { | |
1188 | myDrawer->SetHLRDeviationCoefficient( aCoefficient ); | |
1189 | ||
1190 | } | |
1191 | ||
1192 | //======================================================================= | |
1193 | //function : SetOwnDeviationAngle | |
1194 | //purpose : | |
1195 | //======================================================================= | |
1196 | ||
1197 | void AIS_Shape::SetOwnDeviationAngle ( const Standard_Real anAngle ) | |
1198 | { | |
1199 | ||
1200 | myDrawer->SetDeviationAngle(anAngle ); | |
1201 | SetToUpdate(0) ; // WireFrame | |
1202 | } | |
1203 | //======================================================================= | |
1204 | //function : SetOwnDeviationAngle | |
1205 | //purpose : | |
1206 | //======================================================================= | |
1207 | ||
1208 | void AIS_Shape::SetAngleAndDeviation ( const Standard_Real anAngle ) | |
1209 | { | |
1210 | Standard_Real OutAngl,OutDefl; | |
1211 | HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl); | |
1212 | SetOwnDeviationAngle(anAngle) ; | |
7fd59977 | 1213 | SetOwnDeviationCoefficient(OutDefl) ; |
1214 | myInitAng = anAngle; | |
1215 | SetToUpdate(0); | |
1216 | SetToUpdate(1); | |
1217 | } | |
1218 | ||
1219 | //======================================================================= | |
1220 | //function : UserAngle | |
1221 | //purpose : | |
1222 | //======================================================================= | |
1223 | ||
1224 | Standard_Real AIS_Shape::UserAngle() const | |
1225 | { | |
1226 | return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng; | |
1227 | } | |
1228 | ||
1229 | ||
1230 | //======================================================================= | |
1231 | //function : SetHLRAngleAndDeviation | |
1232 | //purpose : | |
1233 | //======================================================================= | |
1234 | ||
1235 | void AIS_Shape::SetHLRAngleAndDeviation ( const Standard_Real anAngle ) | |
1236 | { | |
1237 | Standard_Real OutAngl,OutDefl; | |
1238 | HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl); | |
1239 | SetOwnHLRDeviationAngle( OutAngl ); | |
1240 | SetOwnHLRDeviationCoefficient(OutDefl); | |
1241 | ||
1242 | } | |
1243 | //======================================================================= | |
1244 | //function : SetOwnHLRDeviationAngle | |
1245 | //purpose : | |
1246 | //======================================================================= | |
1247 | ||
1248 | void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real anAngle ) | |
1249 | { | |
1250 | myDrawer->SetHLRAngle( anAngle ); | |
1251 | } | |
1252 | ||
1253 | //***** GetOwn | |
1254 | //======================================================================= | |
1255 | //function : OwnDeviationCoefficient | |
1256 | //purpose : | |
1257 | //======================================================================= | |
1258 | ||
1259 | Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoefficient, | |
3c34883c | 1260 | Standard_Real & aPreviousCoefficient ) const |
7fd59977 | 1261 | { |
1262 | aCoefficient = myDrawer->DeviationCoefficient(); | |
1263 | aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient (); | |
6262338c | 1264 | return myDrawer->HasOwnDeviationCoefficient() ; |
7fd59977 | 1265 | } |
1266 | ||
1267 | //======================================================================= | |
1268 | //function : OwnHLRDeviationCoefficient | |
1269 | //purpose : | |
1270 | //======================================================================= | |
1271 | ||
1272 | Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient, | |
3c34883c | 1273 | Standard_Real & aPreviousCoefficient ) const |
7fd59977 | 1274 | { |
1275 | aCoefficient = myDrawer->HLRDeviationCoefficient(); | |
1276 | aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient (); | |
6262338c | 1277 | return myDrawer->HasOwnHLRDeviationCoefficient(); |
7fd59977 | 1278 | |
1279 | } | |
1280 | ||
1281 | //======================================================================= | |
1282 | //function : OwnDeviationAngle | |
1283 | //purpose : | |
1284 | //======================================================================= | |
1285 | ||
1286 | Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle, | |
3c34883c | 1287 | Standard_Real & aPreviousAngle ) const |
7fd59977 | 1288 | { |
1289 | anAngle = myDrawer->DeviationAngle(); | |
1290 | aPreviousAngle = myDrawer->PreviousDeviationAngle (); | |
6262338c | 1291 | return myDrawer->HasOwnDeviationAngle(); |
7fd59977 | 1292 | } |
1293 | ||
1294 | //======================================================================= | |
1295 | //function : OwnHLRDeviationAngle | |
1296 | //purpose : | |
1297 | //======================================================================= | |
1298 | ||
1299 | Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real & anAngle, | |
3c34883c | 1300 | Standard_Real & aPreviousAngle ) const |
7fd59977 | 1301 | { |
1302 | anAngle = myDrawer->HLRAngle(); | |
1303 | aPreviousAngle = myDrawer->PreviousHLRDeviationAngle (); | |
6262338c | 1304 | return myDrawer->HasOwnHLRDeviationAngle(); |
7fd59977 | 1305 | } |