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