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