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