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