Salome HOME
It provides a point attribute restore selection by activation of a shape selection...
[modules/shaper.git] / src / ModuleBase / ModuleBase_ResultPrs.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_ResultPrs.cpp
4 // Created:     21 October 2014
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "ModuleBase_ResultPrs.h"
8
9 #include <ModelAPI_Tools.h>
10 #include <ModelAPI_ResultConstruction.h>
11 #include <GeomAPI_PlanarEdges.h>
12
13 #include <BRep_Builder.hxx>
14 #include <AIS_Drawer.hxx>
15 #include <Prs3d_IsoAspect.hxx>
16 #include <TopoDS_Builder.hxx>
17
18 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ResultPrs, AIS_Shape);
19 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, AIS_Shape);
20
21 ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
22   : AIS_Shape(TopoDS_Shape()), myResult(theResult), myIsSketchMode(false)
23 {
24   std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
25   std::shared_ptr<GeomAPI_PlanarEdges> aWirePtr = 
26     std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aShapePtr);
27   if (aWirePtr) {
28     if (aWirePtr->hasPlane() ) {
29       // If this is a wire with plane defined thin it is a sketch-like object
30       // It must have invisible faces
31       myIsSketchMode = true;
32     }
33   }
34   Set(aShapePtr->impl<TopoDS_Shape>());
35 }
36
37
38 void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
39                                    const Handle(Prs3d_Presentation)& thePresentation, 
40                                    const Standard_Integer theMode)
41 {
42   std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
43   if (!aShapePtr)
44     return;
45   if (myIsSketchMode) {
46     myFacesList.clear();
47     ResultConstructionPtr aConstruction = 
48       std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(myResult);
49     if (aConstruction.get()) {
50       int aFacesNum = aConstruction->facesNum();
51       for(int aFaceIndex = 0; aFaceIndex < aFacesNum; aFaceIndex++) {
52         myFacesList.push_back(aConstruction->face(aFaceIndex));
53       }
54     }
55   }
56   myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
57   if (!myOriginalShape.IsNull()) {
58     Set(myOriginalShape);
59     AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
60   }
61 }
62
63
64 void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
65                                             const Standard_Integer aMode)
66 {
67   if (aMode > TopAbs_SHAPE)
68     // In order to avoid using custom selection modes
69     return;
70
71   if (myIsSketchMode) {
72     if (aMode == TopAbs_FACE) {
73       BRep_Builder aBuilder;
74       TopoDS_Compound aComp;
75       aBuilder.MakeCompound(aComp);
76       aBuilder.Add(aComp, myOriginalShape);
77       std::list<std::shared_ptr<GeomAPI_Shape>>::const_iterator aIt;
78       for (aIt = myFacesList.cbegin(); aIt != myFacesList.cend(); ++aIt) {
79         TopoDS_Shape aFace = (*aIt)->impl<TopoDS_Shape>();
80         aBuilder.Add(aComp, aFace);
81       }
82       Set(aComp);
83     } else {
84       Set(myOriginalShape);
85     }
86   }
87   AIS_Shape::ComputeSelection(aSelection, aMode);
88 }