ad3217cd |
1 | // Created on: 2014-04-24 |
2 | // Created by: Kirill Gavrilov |
3 | // Copyright (c) 2014 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #include <AIS_ColoredShape.hxx> |
17 | |
18 | #include <AIS_InteractiveContext.hxx> |
19 | #include <BRep_Builder.hxx> |
20 | #include <BRepTools.hxx> |
6985e642 |
21 | #include <BRepMesh_IncrementalMesh.hxx> |
ad3217cd |
22 | #include <gp_Pnt2d.hxx> |
23 | #include <Graphic3d_AspectFillArea3d.hxx> |
24 | #include <Graphic3d_AspectLine3d.hxx> |
9c86076b |
25 | #include <Graphic3d_ArrayOfTriangles.hxx> |
26 | #include <Graphic3d_ArrayOfSegments.hxx> |
ad3217cd |
27 | #include <Graphic3d_Group.hxx> |
28 | #include <Graphic3d_StructureManager.hxx> |
29 | #include <Graphic3d_Texture2Dmanual.hxx> |
30 | #include <Precision.hxx> |
6262338c |
31 | #include <Prs3d.hxx> |
ad3217cd |
32 | #include <Prs3d_LineAspect.hxx> |
33 | #include <Prs3d_IsoAspect.hxx> |
34 | #include <Prs3d_Presentation.hxx> |
35 | #include <Prs3d_ShadingAspect.hxx> |
36 | #include <Prs3d_Root.hxx> |
37 | #include <PrsMgr_PresentationManager3d.hxx> |
38 | #include <Standard_ErrorHandler.hxx> |
6985e642 |
39 | #include <StdSelect_BRepSelectionTool.hxx> |
ad3217cd |
40 | #include <StdPrs_ShadedShape.hxx> |
5ad8c033 |
41 | #include <StdPrs_ToolTriangulatedShape.hxx> |
42 | #include <StdPrs_WFShape.hxx> |
ad3217cd |
43 | #include <TopExp_Explorer.hxx> |
44 | #include <TopoDS.hxx> |
45 | #include <TopoDS_Compound.hxx> |
46 | #include <TopoDS_Iterator.hxx> |
47 | |
92efcf78 |
48 | IMPLEMENT_STANDARD_RTTIEXT(AIS_ColoredShape,AIS_Shape) |
49 | IMPLEMENT_STANDARD_RTTIEXT(AIS_ColoredDrawer,Prs3d_Drawer) |
50 | |
9c86076b |
51 | namespace |
52 | { |
53 | //! Collect all sub-compounds into map. |
54 | static void collectSubCompounds (TopTools_MapOfShape& theMap, |
55 | const TopoDS_Shape& theShape) |
56 | { |
57 | for (TopoDS_Iterator aChildIter (theShape); aChildIter.More(); aChildIter.Next()) |
58 | { |
59 | const TopoDS_Shape& aShape = aChildIter.Value(); |
60 | if (aShape.ShapeType() == TopAbs_COMPOUND |
61 | && theMap.Add (aShape)) |
62 | { |
478ad1d1 |
63 | collectSubCompounds (theMap, aShape); |
9c86076b |
64 | } |
65 | } |
66 | } |
67 | } |
68 | |
ad3217cd |
69 | //======================================================================= |
70 | //function : AIS_ColoredShape |
71 | //purpose : |
72 | //======================================================================= |
73 | AIS_ColoredShape::AIS_ColoredShape (const TopoDS_Shape& theShape) |
74 | : AIS_Shape (theShape) |
75 | { |
76 | // disable dedicated line aspects |
77 | myDrawer->SetFreeBoundaryAspect (myDrawer->LineAspect()); |
78 | myDrawer->SetUnFreeBoundaryAspect(myDrawer->LineAspect()); |
79 | myDrawer->SetSeenLineAspect (myDrawer->LineAspect()); |
7604a153 |
80 | myDrawer->SetFaceBoundaryAspect (myDrawer->LineAspect()); |
ad3217cd |
81 | } |
82 | |
83 | //======================================================================= |
84 | //function : AIS_ColoredShape |
85 | //purpose : |
86 | //======================================================================= |
87 | AIS_ColoredShape::AIS_ColoredShape (const Handle(AIS_Shape)& theShape) |
88 | : AIS_Shape (theShape->Shape()) |
89 | { |
90 | // disable dedicated line aspects |
91 | myDrawer->SetFreeBoundaryAspect (myDrawer->LineAspect()); |
92 | myDrawer->SetUnFreeBoundaryAspect(myDrawer->LineAspect()); |
93 | myDrawer->SetSeenLineAspect (myDrawer->LineAspect()); |
7604a153 |
94 | myDrawer->SetFaceBoundaryAspect (myDrawer->LineAspect()); |
ad3217cd |
95 | if (theShape->HasMaterial()) |
96 | { |
97 | SetMaterial (theShape->Material()); |
98 | } |
99 | if (theShape->HasColor()) |
100 | { |
87432b82 |
101 | Quantity_Color aColor; |
102 | theShape->Color (aColor); |
103 | SetColor (aColor); |
ad3217cd |
104 | } |
105 | if (theShape->HasWidth()) |
106 | { |
107 | SetWidth (theShape->Width()); |
108 | } |
109 | if (theShape->IsTransparent()) |
110 | { |
111 | SetTransparency (theShape->Transparency()); |
112 | } |
113 | } |
114 | |
115 | //======================================================================= |
116 | //function : CustomAspects |
117 | //purpose : |
118 | //======================================================================= |
119 | Handle(AIS_ColoredDrawer) AIS_ColoredShape::CustomAspects (const TopoDS_Shape& theShape) |
120 | { |
121 | Handle(AIS_ColoredDrawer) aDrawer; |
122 | myShapeColors.Find (theShape, aDrawer); |
123 | if (aDrawer.IsNull()) |
124 | { |
125 | aDrawer = new AIS_ColoredDrawer (myDrawer); |
126 | myShapeColors.Bind (theShape, aDrawer); |
226fce20 |
127 | SetToUpdate(); |
ad3217cd |
128 | } |
129 | return aDrawer; |
130 | } |
131 | |
132 | //======================================================================= |
133 | //function : ClearCustomAspects |
134 | //purpose : |
135 | //======================================================================= |
136 | void AIS_ColoredShape::ClearCustomAspects() |
137 | { |
138 | if (myShapeColors.IsEmpty()) |
139 | { |
140 | return; |
141 | } |
142 | myShapeColors.Clear(); |
226fce20 |
143 | SetToUpdate(); |
ad3217cd |
144 | } |
145 | |
146 | //======================================================================= |
147 | //function : UnsetCustomAspects |
148 | //purpose : |
149 | //======================================================================= |
150 | void AIS_ColoredShape::UnsetCustomAspects (const TopoDS_Shape& theShape, |
151 | const Standard_Boolean theToUnregister) |
152 | { |
153 | if (!myShapeColors.IsBound (theShape)) |
154 | { |
155 | return; |
156 | } |
157 | |
226fce20 |
158 | SetToUpdate(); |
ad3217cd |
159 | if (theToUnregister) |
160 | { |
161 | myShapeColors.UnBind (theShape); |
162 | return; |
163 | } |
164 | |
165 | myShapeColors.ChangeFind (theShape) = new AIS_ColoredDrawer (myDrawer); |
166 | } |
167 | |
168 | //======================================================================= |
169 | //function : SetCustomColor |
170 | //purpose : |
171 | //======================================================================= |
172 | void AIS_ColoredShape::SetCustomColor (const TopoDS_Shape& theShape, |
173 | const Quantity_Color& theColor) |
174 | { |
175 | if (theShape.IsNull()) |
176 | { |
177 | return; |
178 | } |
179 | |
180 | const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape); |
181 | setColor (aDrawer, theColor); |
182 | aDrawer->SetOwnColor (theColor); |
ad3217cd |
183 | } |
184 | |
c1197a15 |
185 | //======================================================================= |
186 | //function : SetCustomTransparency |
187 | //purpose : |
188 | //======================================================================= |
189 | void AIS_ColoredShape::SetCustomTransparency (const TopoDS_Shape& theShape, |
190 | Standard_Real theTransparency) |
191 | { |
192 | if (theShape.IsNull()) |
193 | { |
194 | return; |
195 | } |
196 | |
197 | const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape); |
198 | setTransparency (aDrawer, theTransparency); |
199 | aDrawer->SetOwnTransparency (theTransparency); |
c1197a15 |
200 | } |
201 | |
ad3217cd |
202 | //======================================================================= |
203 | //function : SetCustomWidth |
204 | //purpose : |
205 | //======================================================================= |
206 | void AIS_ColoredShape::SetCustomWidth (const TopoDS_Shape& theShape, |
207 | const Standard_Real theLineWidth) |
208 | { |
209 | if (theShape.IsNull()) |
210 | { |
211 | return; |
212 | } |
213 | |
214 | const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape); |
c1197a15 |
215 | setWidth (aDrawer, theLineWidth); |
ad3217cd |
216 | aDrawer->SetOwnWidth (theLineWidth); |
ad3217cd |
217 | } |
218 | |
219 | //======================================================================= |
220 | //function : SetColor |
221 | //purpose : |
222 | //======================================================================= |
223 | |
224 | void AIS_ColoredShape::SetColor (const Quantity_Color& theColor) |
225 | { |
fb66bb28 |
226 | for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next()) |
ad3217cd |
227 | { |
228 | const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value(); |
229 | if (aDrawer->HasOwnColor()) |
230 | { |
231 | continue; |
232 | } |
233 | |
6262338c |
234 | if (aDrawer->HasOwnShadingAspect()) |
ad3217cd |
235 | { |
236 | aDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel); |
237 | } |
6262338c |
238 | if (aDrawer->HasOwnLineAspect()) |
ad3217cd |
239 | { |
240 | aDrawer->LineAspect()->SetColor (theColor); |
241 | } |
6262338c |
242 | if (aDrawer->HasOwnWireAspect()) |
ad3217cd |
243 | { |
244 | aDrawer->WireAspect()->SetColor (theColor); |
245 | } |
7604a153 |
246 | if (aDrawer->HasOwnFaceBoundaryAspect()) |
247 | { |
248 | aDrawer->FaceBoundaryAspect()->SetColor (theColor); |
249 | } |
ad3217cd |
250 | } |
bf5f0ca2 |
251 | AIS_Shape::SetColor (theColor); |
ad3217cd |
252 | } |
253 | |
254 | //======================================================================= |
255 | //function : SetWidth |
256 | //purpose : |
257 | //======================================================================= |
258 | |
259 | void AIS_ColoredShape::SetWidth (const Standard_Real theLineWidth) |
260 | { |
fb66bb28 |
261 | for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next()) |
ad3217cd |
262 | { |
263 | const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value(); |
264 | if (aDrawer->HasOwnWidth()) |
265 | { |
266 | continue; |
267 | } |
268 | |
6262338c |
269 | if (aDrawer->HasOwnLineAspect()) |
ad3217cd |
270 | { |
271 | aDrawer->LineAspect()->SetWidth (theLineWidth); |
272 | } |
6262338c |
273 | if (aDrawer->HasOwnWireAspect()) |
ad3217cd |
274 | { |
275 | aDrawer->WireAspect()->SetWidth (theLineWidth); |
276 | } |
7604a153 |
277 | if (aDrawer->HasOwnFaceBoundaryAspect()) |
278 | { |
279 | aDrawer->FaceBoundaryAspect()->SetWidth (theLineWidth); |
280 | } |
ad3217cd |
281 | } |
bf5f0ca2 |
282 | AIS_Shape::SetWidth (theLineWidth); |
283 | } |
284 | |
285 | //======================================================================= |
286 | //function : UnsetWidth |
287 | //purpose : |
288 | //======================================================================= |
289 | void AIS_ColoredShape::UnsetWidth() |
290 | { |
291 | SetWidth (1.0f); |
ad3217cd |
292 | } |
293 | |
294 | //======================================================================= |
295 | //function : SetTransparency |
296 | //purpose : |
297 | //======================================================================= |
298 | |
299 | void AIS_ColoredShape::SetTransparency (const Standard_Real theValue) |
300 | { |
fb66bb28 |
301 | for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next()) |
ad3217cd |
302 | { |
c1197a15 |
303 | const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value(); |
304 | if (aDrawer->HasOwnTransparency()) |
305 | { |
306 | continue; |
307 | } |
308 | |
6262338c |
309 | if (aDrawer->HasOwnShadingAspect()) |
ad3217cd |
310 | { |
311 | aDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel); |
312 | } |
313 | } |
bf5f0ca2 |
314 | AIS_Shape::SetTransparency (theValue); |
ad3217cd |
315 | } |
316 | |
f6d4c5cf |
317 | //======================================================================= |
318 | //function : UnsetTransparency |
319 | //purpose : |
320 | //======================================================================= |
321 | void AIS_ColoredShape::UnsetTransparency() |
322 | { |
bf5f0ca2 |
323 | SetTransparency (0.0f); |
f6d4c5cf |
324 | } |
325 | |
e0608a8d |
326 | //======================================================================= |
327 | //function : SetMaterial |
328 | //purpose : |
329 | //======================================================================= |
330 | |
331 | void AIS_ColoredShape::SetMaterial (const Graphic3d_MaterialAspect& theMaterial) |
332 | { |
fb66bb28 |
333 | for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next()) |
e0608a8d |
334 | { |
335 | const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value(); |
336 | //if (aDrawer->HasOwnMaterial()) continue; |
6262338c |
337 | if (aDrawer->HasOwnShadingAspect()) |
e0608a8d |
338 | { |
c1197a15 |
339 | setMaterial (aDrawer, theMaterial, aDrawer->HasOwnColor(), aDrawer->HasOwnTransparency()); |
e0608a8d |
340 | } |
341 | } |
bf5f0ca2 |
342 | AIS_Shape::SetMaterial (theMaterial); |
e0608a8d |
343 | } |
344 | |
ad3217cd |
345 | //======================================================================= |
346 | //function : Compute |
347 | //purpose : |
348 | //======================================================================= |
f8e0c6c4 |
349 | void AIS_ColoredShape::Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr, |
ad3217cd |
350 | const Handle(Prs3d_Presentation)& thePrs, |
351 | const Standard_Integer theMode) |
352 | { |
ede89abc |
353 | if (myshape.IsNull()) |
354 | { |
355 | return; |
356 | } |
357 | |
ad3217cd |
358 | if (IsInfinite()) |
359 | { |
360 | thePrs->SetInfiniteState (Standard_True); |
361 | } |
362 | |
f8e0c6c4 |
363 | switch (theMode) |
ad3217cd |
364 | { |
f8e0c6c4 |
365 | case AIS_WireFrame: |
ad3217cd |
366 | { |
83b0f13a |
367 | StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True); |
368 | |
306f5893 |
369 | // After this call if type of deflection is relative |
370 | // computed deflection coefficient is stored as absolute. |
f8e0c6c4 |
371 | Prs3d::GetDeflection (myshape, myDrawer); |
372 | break; |
373 | } |
374 | case AIS_Shaded: |
375 | { |
376 | if (myDrawer->IsAutoTriangulation()) |
5ad8c033 |
377 | { |
f8e0c6c4 |
378 | // compute mesh for entire shape beforehand to ensure consistency and optimizations (parallelization) |
379 | StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True); |
380 | |
381 | // After this call if type of deflection is relative |
382 | // computed deflection coefficient is stored as absolute. |
383 | Standard_Boolean wasRecomputed = StdPrs_ToolTriangulatedShape::Tessellate (myshape, myDrawer); |
384 | |
385 | // Set to update wireframe presentation on triangulation. |
386 | if (myDrawer->IsoOnTriangulation() && wasRecomputed) |
387 | { |
388 | SetToUpdate (AIS_WireFrame); |
389 | } |
5ad8c033 |
390 | } |
f8e0c6c4 |
391 | break; |
392 | } |
393 | case 2: |
394 | { |
395 | AIS_Shape::Compute (thePrsMgr, thePrs, theMode); |
396 | return; |
397 | } |
398 | default: |
399 | { |
400 | return; |
ad3217cd |
401 | } |
ad3217cd |
402 | } |
403 | |
6985e642 |
404 | // Extract myShapeColors map (KeyshapeColored -> Color) to subshapes map (Subshape -> Color). |
405 | // This needed when colored shape is not part of BaseShape (but subshapes are) and actually container for subshapes. |
9c86076b |
406 | AIS_DataMapOfShapeDrawer aSubshapeDrawerMap; |
6985e642 |
407 | fillSubshapeDrawerMap (aSubshapeDrawerMap); |
408 | |
409 | Handle(AIS_ColoredDrawer) aBaseDrawer; |
410 | myShapeColors.Find (myshape, aBaseDrawer); |
411 | |
412 | // myShapeColors + anOpened --> array[TopAbs_ShapeEnum] of map of color-to-compound |
413 | DataMapOfDrawerCompd aDispatchedOpened[(size_t)TopAbs_SHAPE]; |
414 | DataMapOfDrawerCompd aDispatchedClosed; |
415 | dispatchColors (aBaseDrawer, myshape, |
416 | aSubshapeDrawerMap, TopAbs_COMPOUND, Standard_False, |
417 | aDispatchedOpened, theMode == AIS_Shaded ? aDispatchedClosed : aDispatchedOpened[TopAbs_FACE]); |
418 | addShapesWithCustomProps (thePrs, aDispatchedOpened, aDispatchedClosed, theMode); |
419 | } |
420 | |
421 | //======================================================================= |
422 | //function : fillSubshapeDrawerMap |
423 | //purpose : |
424 | //======================================================================= |
425 | void AIS_ColoredShape::fillSubshapeDrawerMap (AIS_DataMapOfShapeDrawer& theSubshapeDrawerMap) const |
426 | { |
427 | // unroll compounds specified for grouping sub-shapes with the same style |
428 | // (e.g. the compounds that are not a part of the main shape) |
429 | TopTools_MapOfShape aMapOfOwnCompounds; |
430 | if (myshape.ShapeType() == TopAbs_COMPOUND) |
5bffb882 |
431 | { |
6985e642 |
432 | aMapOfOwnCompounds.Add (myshape); |
433 | collectSubCompounds (aMapOfOwnCompounds, myshape); |
434 | } |
435 | for (AIS_DataMapOfShapeDrawer::Iterator aKeyShapeIter (myShapeColors); |
436 | aKeyShapeIter.More(); aKeyShapeIter.Next()) |
437 | { |
438 | const TopoDS_Shape& aKeyShape = aKeyShapeIter.Key(); |
439 | if (aKeyShape.ShapeType() != TopAbs_COMPOUND |
440 | || aMapOfOwnCompounds.Contains (aKeyShape)) |
5bffb882 |
441 | { |
6985e642 |
442 | continue; |
5bffb882 |
443 | } |
9c86076b |
444 | |
6985e642 |
445 | for (TopoDS_Iterator aChildIter (aKeyShape); aChildIter.More(); aChildIter.Next()) |
446 | { |
447 | const TopoDS_Shape& aShape = aChildIter.Value(); |
448 | if (!myShapeColors.IsBound (aShape)) |
9c86076b |
449 | { |
6985e642 |
450 | bindSubShapes (theSubshapeDrawerMap, aShape, aKeyShapeIter.Value()); |
5bffb882 |
451 | } |
452 | } |
6985e642 |
453 | } |
9c86076b |
454 | |
6985e642 |
455 | // assign other sub-shapes with styles |
456 | for (AIS_DataMapOfShapeDrawer::Iterator aKeyShapeIter (myShapeColors); |
457 | aKeyShapeIter.More(); aKeyShapeIter.Next()) |
458 | { |
459 | const TopoDS_Shape& aKeyShape = aKeyShapeIter.Key(); |
460 | if (myshape == aKeyShape |
461 | || (aKeyShape.ShapeType() == TopAbs_COMPOUND |
462 | && !aMapOfOwnCompounds.Contains (aKeyShape))) |
9c86076b |
463 | { |
6985e642 |
464 | continue; |
9c86076b |
465 | } |
6985e642 |
466 | |
467 | bindSubShapes (theSubshapeDrawerMap, aKeyShape, aKeyShapeIter.Value()); |
468 | } |
469 | } |
470 | |
471 | //======================================================================= |
472 | //function : ComputeSelection |
473 | //purpose : |
474 | //======================================================================= |
475 | void AIS_ColoredShape::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, |
476 | const Standard_Integer theMode) |
477 | { |
478 | if (myshape.IsNull()) |
479 | { |
480 | return; |
481 | } |
482 | else if (isShapeEntirelyVisible()) |
483 | { |
484 | base_type::ComputeSelection (theSelection, theMode); |
485 | return; |
486 | } |
487 | |
488 | const TopAbs_ShapeEnum aTypOfSel = AIS_Shape::SelectionType (theMode); |
489 | const Standard_Real aDeflection = Prs3d::GetDeflection (myshape, myDrawer); |
490 | const Standard_Real aDeviationAngle = myDrawer->HLRAngle(); |
491 | const Standard_Integer aPriority = StdSelect_BRepSelectionTool::GetStandardPriority (myshape, aTypOfSel); |
492 | if (myDrawer->IsAutoTriangulation() |
493 | && !BRepTools::Triangulation (myshape, Precision::Infinite())) |
494 | { |
495 | BRepMesh_IncrementalMesh aMesher (myshape, aDeflection, Standard_False, aDeviationAngle); |
496 | } |
497 | |
498 | AIS_DataMapOfShapeDrawer aSubshapeDrawerMap; |
499 | fillSubshapeDrawerMap (aSubshapeDrawerMap); |
500 | |
501 | Handle(StdSelect_BRepOwner) aBrepOwner = new StdSelect_BRepOwner (myshape, aPriority); |
502 | if (aTypOfSel == TopAbs_SHAPE) |
503 | { |
504 | aBrepOwner = new StdSelect_BRepOwner (myshape, aPriority); |
5bffb882 |
505 | } |
9c86076b |
506 | |
507 | Handle(AIS_ColoredDrawer) aBaseDrawer; |
508 | myShapeColors.Find (myshape, aBaseDrawer); |
6985e642 |
509 | computeSubshapeSelection (aBaseDrawer, aSubshapeDrawerMap, myshape, aBrepOwner, theSelection, |
510 | aTypOfSel, aPriority, aDeflection, aDeviationAngle); |
9c86076b |
511 | |
6985e642 |
512 | Handle(SelectMgr_SelectableObject) aThis (this); |
b5cce1ab |
513 | for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (theSelection->Entities()); aSelEntIter.More(); aSelEntIter.Next()) |
6985e642 |
514 | { |
b5cce1ab |
515 | Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (aSelEntIter.Value()->BaseSensitive()->OwnerId()); |
6985e642 |
516 | anOwner->Set (aThis); |
517 | } |
518 | |
519 | StdSelect_BRepSelectionTool::PreBuildBVH (theSelection); |
520 | } |
521 | |
522 | //======================================================================= |
523 | //function : computeSubshapeSelection |
524 | //purpose : |
525 | //======================================================================= |
526 | void AIS_ColoredShape::computeSubshapeSelection (const Handle(AIS_ColoredDrawer)& theParentDrawer, |
527 | const AIS_DataMapOfShapeDrawer& theShapeDrawerMap, |
528 | const TopoDS_Shape& theShape, |
529 | const Handle(StdSelect_BRepOwner)& theOwner, |
530 | const Handle(SelectMgr_Selection)& theSelection, |
531 | const TopAbs_ShapeEnum theTypOfSel, |
532 | const Standard_Integer thePriority, |
533 | const Standard_Real theDeflection, |
534 | const Standard_Real theDeflAngle) |
535 | { |
536 | Handle(AIS_ColoredDrawer) aDrawer = theParentDrawer; |
537 | theShapeDrawerMap.Find (theShape, aDrawer); |
538 | if (!aDrawer.IsNull() |
539 | && aDrawer->IsHidden()) |
540 | { |
541 | return; |
542 | } |
543 | |
544 | const Standard_Integer aNbPOnEdge = 9; |
545 | const Standard_Real aMaximalParameter = 500.0; |
546 | if (theTypOfSel == TopAbs_SHAPE |
547 | && theShape.ShapeType() >= TopAbs_FACE) |
548 | { |
549 | StdSelect_BRepSelectionTool::ComputeSensitive (theShape, theOwner, theSelection, |
550 | theDeflection, theDeflAngle, aNbPOnEdge, aMaximalParameter, myDrawer->IsAutoTriangulation()); |
551 | return; |
552 | } |
553 | else if (theShape.ShapeType() == theTypOfSel) |
554 | { |
555 | const Standard_Boolean isComesFromDecomposition = !theShape.IsEqual (myshape); |
556 | Handle(StdSelect_BRepOwner) aBrepOwner = new StdSelect_BRepOwner (theShape, thePriority, isComesFromDecomposition); |
557 | StdSelect_BRepSelectionTool::ComputeSensitive (theShape, aBrepOwner, theSelection, |
558 | theDeflection, theDeflAngle, aNbPOnEdge, aMaximalParameter, myDrawer->IsAutoTriangulation()); |
559 | return; |
560 | } |
561 | |
562 | for (TopoDS_Iterator aSubShapeIter (theShape); aSubShapeIter.More(); aSubShapeIter.Next()) |
563 | { |
564 | const TopoDS_Shape& aSubShape = aSubShapeIter.Value(); |
565 | computeSubshapeSelection (aDrawer, theShapeDrawerMap, aSubShape, |
566 | theOwner, theSelection, theTypOfSel, thePriority, |
567 | theDeflection, theDeflAngle); |
568 | } |
5bffb882 |
569 | } |
ad3217cd |
570 | |
5bffb882 |
571 | //======================================================================= |
572 | //function : addShapesWithCustomProps |
573 | //purpose : |
574 | //======================================================================= |
575 | void AIS_ColoredShape::addShapesWithCustomProps (const Handle(Prs3d_Presentation)& thePrs, |
9c86076b |
576 | const DataMapOfDrawerCompd* theDrawerOpenedShapePerType, |
577 | const DataMapOfDrawerCompd& theDrawerClosedFaces, |
578 | const Standard_Integer theMode) |
5bffb882 |
579 | { |
0493ffd0 |
580 | Handle(Graphic3d_Group) anOpenGroup, aClosedGroup, anEdgesGroup; |
9c86076b |
581 | for (size_t aShType = 0; aShType <= (size_t )TopAbs_SHAPE; ++aShType) |
582 | { |
583 | const Standard_Boolean isClosed = aShType == TopAbs_SHAPE; |
584 | Handle(Graphic3d_Group)& aShadedGroup = isClosed ? aClosedGroup : anOpenGroup; |
585 | const DataMapOfDrawerCompd& aDrawerShapeMap = isClosed |
586 | ? theDrawerClosedFaces |
587 | : theDrawerOpenedShapePerType[aShType]; |
588 | for (DataMapOfDrawerCompd::Iterator aMapIter (aDrawerShapeMap); |
ad3217cd |
589 | aMapIter.More(); aMapIter.Next()) |
590 | { |
9c86076b |
591 | const Handle(AIS_ColoredDrawer)& aCustomDrawer = aMapIter.Key(); |
ad3217cd |
592 | const TopoDS_Compound& aShapeDraw = aMapIter.Value(); // compound of subshapes with <aShType> type |
6262338c |
593 | Handle(Prs3d_Drawer) aDrawer; |
9c86076b |
594 | if (!aCustomDrawer.IsNull()) |
86766b0e |
595 | { |
596 | aDrawer = aCustomDrawer; |
597 | if (aCustomDrawer->IsHidden()) |
598 | { |
599 | continue; |
600 | } |
601 | } |
602 | else |
603 | { |
604 | aDrawer = myDrawer; |
605 | } |
ad3217cd |
606 | |
7f917335 |
607 | // It is supposed that absolute deflection contains previously computed relative deflection |
608 | // (if deflection type is relative). |
609 | // In case of CustomDrawer it is taken from Link(). |
610 | Aspect_TypeOfDeflection aPrevType = aDrawer->TypeOfDeflection(); |
611 | aDrawer->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE); |
612 | |
ad3217cd |
613 | // Draw each kind of subshapes and personal-colored shapes in a separate group |
614 | // since it's necessary to set transparency/material for all subshapes |
615 | // without affecting their unique colors |
5bffb882 |
616 | if (theMode == AIS_Shaded |
617 | && aShapeDraw.ShapeType() <= TopAbs_FACE |
618 | && !IsInfinite()) |
ad3217cd |
619 | { |
9c86076b |
620 | // add wireframe presentation for isolated edges and vertices |
621 | StdPrs_ShadedShape::AddWireframeForFreeElements (thePrs, aShapeDraw, aDrawer); |
622 | |
623 | // add special wireframe presentation for faces without triangulation |
624 | StdPrs_ShadedShape::AddWireframeForFacesWithoutTriangles (thePrs, aShapeDraw, aDrawer); |
625 | |
a6dee93d |
626 | Handle(Graphic3d_ArrayOfTriangles) aTriangles = StdPrs_ShadedShape::FillTriangles (aShapeDraw, |
627 | aDrawer->ShadingAspect()->Aspect()->ToMapTexture() |
628 | && !aDrawer->ShadingAspect()->Aspect()->TextureMap().IsNull(), |
629 | myUVOrigin, myUVRepeat, myUVScale); |
9c86076b |
630 | if (!aTriangles.IsNull()) |
631 | { |
632 | if (aShadedGroup.IsNull()) |
633 | { |
0493ffd0 |
634 | aShadedGroup = thePrs->NewGroup(); |
9c86076b |
635 | aShadedGroup->SetClosed (isClosed); |
636 | } |
637 | aShadedGroup->SetPrimitivesAspect (aDrawer->ShadingAspect()->Aspect()); |
638 | aShadedGroup->AddPrimitiveArray (aTriangles); |
639 | } |
640 | |
641 | if (aDrawer->FaceBoundaryDraw()) |
642 | { |
0493ffd0 |
643 | if (Handle(Graphic3d_ArrayOfSegments) aBndSegments = StdPrs_ShadedShape::FillFaceBoundaries (aShapeDraw, aDrawer->FaceBoundaryUpperContinuity())) |
9c86076b |
644 | { |
0493ffd0 |
645 | if (anEdgesGroup.IsNull()) |
9c86076b |
646 | { |
0493ffd0 |
647 | anEdgesGroup = thePrs->NewGroup(); |
9c86076b |
648 | } |
649 | |
0493ffd0 |
650 | anEdgesGroup->SetPrimitivesAspect (aDrawer->FaceBoundaryAspect()->Aspect()); |
651 | anEdgesGroup->AddPrimitiveArray (aBndSegments); |
9c86076b |
652 | } |
653 | } |
5bffb882 |
654 | } |
655 | else |
656 | { |
5ad8c033 |
657 | StdPrs_WFShape::Add (thePrs, aShapeDraw, aDrawer); |
ad3217cd |
658 | } |
7f917335 |
659 | aDrawer->SetTypeOfDeflection (aPrevType); |
ad3217cd |
660 | } |
661 | } |
662 | } |
663 | |
664 | //======================================================================= |
665 | //function : dispatchColors |
666 | //purpose : |
667 | //======================================================================= |
9c86076b |
668 | Standard_Boolean AIS_ColoredShape::dispatchColors (const Handle(AIS_ColoredDrawer)& theParentDrawer, |
669 | const TopoDS_Shape& theShapeToParse, |
670 | const AIS_DataMapOfShapeDrawer& theShapeDrawerMap, |
671 | const TopAbs_ShapeEnum theParentType, |
672 | const Standard_Boolean theIsParentClosed, |
673 | DataMapOfDrawerCompd* theDrawerOpenedShapePerType, |
674 | DataMapOfDrawerCompd& theDrawerClosedFaces) |
ad3217cd |
675 | { |
9c86076b |
676 | const TopAbs_ShapeEnum aShapeType = theShapeToParse.ShapeType(); |
677 | if (aShapeType == TopAbs_SHAPE) |
ad3217cd |
678 | { |
679 | return Standard_False; |
680 | } |
681 | |
682 | // check own setting of current shape |
9c86076b |
683 | Handle(AIS_ColoredDrawer) aDrawer = theParentDrawer; |
684 | const Standard_Boolean isOverriden = theShapeDrawerMap.Find (theShapeToParse, aDrawer); |
685 | if (isOverriden |
686 | && aDrawer->IsHidden()) |
687 | { |
688 | return Standard_True; |
689 | } |
690 | |
691 | // handle compounds, solids and shells |
692 | Standard_Boolean isSubOverride = Standard_False; |
693 | if (aShapeType <= TopAbs_SHELL) |
694 | { |
695 | // detect parts of closed solids |
696 | Standard_Boolean isClosedShell = theParentType == TopAbs_SOLID |
697 | && aShapeType == TopAbs_SHELL |
698 | && BRep_Tool::IsClosed (theShapeToParse) |
699 | && StdPrs_ToolTriangulatedShape::IsTriangulated (theShapeToParse); |
700 | if (isClosedShell) |
701 | { |
702 | for (TopoDS_Iterator aFaceIter (theShapeToParse); aFaceIter.More(); aFaceIter.Next()) |
703 | { |
704 | const TopoDS_Shape& aFace = aFaceIter.Value(); |
705 | Handle(AIS_ColoredDrawer) aFaceDrawer; |
c1197a15 |
706 | if (aFace.ShapeType() != TopAbs_FACE |
707 | || !theShapeDrawerMap.Find (aFace, aFaceDrawer)) |
708 | { |
709 | continue; |
710 | } |
711 | |
712 | if (aFaceDrawer->IsHidden()) |
9c86076b |
713 | { |
714 | isClosedShell = Standard_False; |
715 | break; |
716 | } |
c1197a15 |
717 | else if (aFaceDrawer->HasOwnShadingAspect() |
718 | && aFaceDrawer->ShadingAspect()->Aspect()->AlphaMode() != Graphic3d_AlphaMode_Opaque) |
719 | { |
720 | if (aFaceDrawer->ShadingAspect()->Aspect()->AlphaMode() != Graphic3d_AlphaMode_BlendAuto |
721 | || aFaceDrawer->ShadingAspect()->Aspect()->FrontMaterial().Alpha() < 1.0f |
722 | || (aFaceDrawer->ShadingAspect()->Aspect()->Distinguish() |
723 | && aFaceDrawer->ShadingAspect()->Aspect()->BackMaterial().Alpha() < 1.0f)) |
724 | { |
725 | isClosedShell = Standard_False; |
726 | break; |
727 | } |
728 | } |
9c86076b |
729 | } |
730 | } |
731 | |
732 | for (TopoDS_Iterator aSubShapeIter (theShapeToParse); aSubShapeIter.More(); aSubShapeIter.Next()) |
733 | { |
734 | const TopoDS_Shape& aSubShape = aSubShapeIter.Value(); |
735 | if (dispatchColors (aDrawer, aSubShape, |
736 | theShapeDrawerMap, aShapeType, |
737 | isClosedShell, |
738 | theDrawerOpenedShapePerType, |
739 | theDrawerClosedFaces)) |
740 | { |
741 | isSubOverride = Standard_True; |
742 | } |
743 | } |
744 | return isOverriden || isSubOverride; |
745 | } |
ad3217cd |
746 | |
747 | // iterate on sub-shapes |
748 | BRep_Builder aBBuilder; |
9c86076b |
749 | TopoDS_Shape aShapeCopy = theShapeToParse.EmptyCopied(); |
750 | aShapeCopy.Closed (theShapeToParse.Closed()); |
ad3217cd |
751 | Standard_Integer nbDef = 0; |
9c86076b |
752 | for (TopoDS_Iterator aSubShapeIter (theShapeToParse); aSubShapeIter.More(); aSubShapeIter.Next()) |
753 | { |
754 | const TopoDS_Shape& aSubShape = aSubShapeIter.Value(); |
755 | if (dispatchColors (aDrawer, aSubShape, |
756 | theShapeDrawerMap, aShapeType, |
757 | theIsParentClosed, |
758 | theDrawerOpenedShapePerType, |
759 | theDrawerClosedFaces)) |
ad3217cd |
760 | { |
761 | isSubOverride = Standard_True; |
762 | } |
763 | else |
764 | { |
9c86076b |
765 | aBBuilder.Add (aShapeCopy, aSubShape); |
ad3217cd |
766 | ++nbDef; |
767 | } |
768 | } |
9c86076b |
769 | if (aShapeType == TopAbs_FACE || !isSubOverride) |
ad3217cd |
770 | { |
9c86076b |
771 | aShapeCopy = theShapeToParse; |
ad3217cd |
772 | } |
773 | else if (nbDef == 0) |
774 | { |
775 | return isOverriden || isSubOverride; // empty compound |
776 | } |
777 | |
778 | // if any of styles is overridden regarding to default one, add rest to map |
779 | if (isOverriden |
780 | || (isSubOverride && theParentType != TopAbs_WIRE // avoid drawing edges when vertex color is overridden |
781 | && theParentType != TopAbs_FACE) // avoid drawing edges of the same color as face |
9c86076b |
782 | || (theParentType <= TopAbs_SHELL && !(isOverriden || isSubOverride))) // bind original shape to default color |
ad3217cd |
783 | { |
784 | TopoDS_Compound aCompound; |
9c86076b |
785 | DataMapOfDrawerCompd& aDrawerShapeMap = theIsParentClosed |
786 | && aShapeType == TopAbs_FACE |
787 | ? theDrawerClosedFaces |
788 | : theDrawerOpenedShapePerType[(size_t)aShapeType]; |
789 | if (!aDrawerShapeMap.FindFromKey (aDrawer, aCompound)) |
ad3217cd |
790 | { |
791 | aBBuilder.MakeCompound (aCompound); |
9c86076b |
792 | aDrawerShapeMap.Add (aDrawer, aCompound); |
ad3217cd |
793 | } |
794 | aBBuilder.Add (aCompound, aShapeCopy); |
795 | } |
796 | return isOverriden || isSubOverride; |
797 | } |
798 | |
5bffb882 |
799 | //======================================================================= |
800 | //function : isShapeEntirelyVisible |
801 | //purpose : |
802 | //======================================================================= |
803 | Standard_Boolean AIS_ColoredShape::isShapeEntirelyVisible() const |
804 | { |
fb66bb28 |
805 | for (AIS_DataMapOfShapeDrawer::Iterator aMapIter (myShapeColors); aMapIter.More(); aMapIter.Next()) |
5bffb882 |
806 | { |
807 | if (aMapIter.Value()->IsHidden()) |
808 | { |
809 | return Standard_False; |
810 | } |
811 | } |
812 | return Standard_True; |
813 | } |
814 | |
815 | //======================================================================= |
816 | //function : bindSubShapes |
817 | //purpose : |
818 | //======================================================================= |
9c86076b |
819 | void AIS_ColoredShape::bindSubShapes (AIS_DataMapOfShapeDrawer& theShapeDrawerMap, |
820 | const TopoDS_Shape& theKeyShape, |
6985e642 |
821 | const Handle(AIS_ColoredDrawer)& theDrawer) const |
5bffb882 |
822 | { |
9c86076b |
823 | TopAbs_ShapeEnum aShapeWithColorType = theKeyShape.ShapeType(); |
5bffb882 |
824 | if (aShapeWithColorType == TopAbs_COMPOUND) |
825 | { |
9c86076b |
826 | theShapeDrawerMap.Bind (theKeyShape, theDrawer); |
ad3217cd |
827 | } |
5bffb882 |
828 | else if (aShapeWithColorType == TopAbs_SOLID || aShapeWithColorType == TopAbs_SHELL) |
829 | { |
9c86076b |
830 | for (TopExp_Explorer anExp (theKeyShape, TopAbs_FACE); anExp.More(); anExp.Next()) |
5bffb882 |
831 | { |
9c86076b |
832 | if (!theShapeDrawerMap.IsBound (anExp.Current())) |
5bffb882 |
833 | { |
9c86076b |
834 | theShapeDrawerMap.Bind (anExp.Current(), theDrawer); |
5bffb882 |
835 | } |
836 | } |
837 | } |
838 | else if (aShapeWithColorType == TopAbs_WIRE) |
839 | { |
9c86076b |
840 | for (TopExp_Explorer anExp (theKeyShape, TopAbs_EDGE); anExp.More(); anExp.Next()) |
5bffb882 |
841 | { |
9c86076b |
842 | if (!theShapeDrawerMap.IsBound (anExp.Current())) |
5bffb882 |
843 | { |
9c86076b |
844 | theShapeDrawerMap.Bind (anExp.Current(), theDrawer); |
5bffb882 |
845 | } |
846 | } |
847 | } |
848 | else |
849 | { |
850 | // bind single face, edge and vertex |
851 | // force rebind if required due to the color of single shape has |
852 | // higher priority than the color of "compound" shape (wire is a |
853 | // compound of edges, shell is a compound of faces) that contains |
854 | // this single shape. |
9c86076b |
855 | theShapeDrawerMap.Bind (theKeyShape, theDrawer); |
5bffb882 |
856 | } |
ad3217cd |
857 | } |