]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_ResultPrs.cpp
Salome HOME
Porting on SALOME 7.6.0
[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 <Prs3d_IsoAspect.hxx>
15 #include <TopoDS_Builder.hxx>
16
17 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ResultPrs, AIS_Shape);
18 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, AIS_Shape);
19
20 ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
21   : AIS_Shape(TopoDS_Shape()), myResult(theResult), myIsSketchMode(false)
22 {
23   std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
24   std::shared_ptr<GeomAPI_PlanarEdges> aWirePtr = 
25     std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aShapePtr);
26   if (aWirePtr) {
27     if (aWirePtr->hasPlane() ) {
28       // If this is a wire with plane defined thin it is a sketch-like object
29       // It must have invisible faces
30       myIsSketchMode = true;
31     }
32   }
33   Set(aShapePtr->impl<TopoDS_Shape>());
34 }
35
36
37 void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
38                                    const Handle(Prs3d_Presentation)& thePresentation, 
39                                    const Standard_Integer theMode)
40 {
41   std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
42   if (!aShapePtr)
43     return;
44   if (myIsSketchMode) {
45     myFacesList.clear();
46     ResultConstructionPtr aConstruction = 
47       std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(myResult);
48     if (aConstruction.get()) {
49       int aFacesNum = aConstruction->facesNum();
50       for(int aFaceIndex = 0; aFaceIndex < aFacesNum; aFaceIndex++) {
51         myFacesList.push_back(aConstruction->face(aFaceIndex));
52       }
53     }
54   }
55   myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
56   if (!myOriginalShape.IsNull()) {
57     Set(myOriginalShape);
58     AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
59   }
60 }
61
62
63 void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
64                                             const Standard_Integer aMode)
65 {
66   if (aMode > TopAbs_SHAPE)
67     // In order to avoid using custom selection modes
68     return;
69
70   if (myIsSketchMode) {
71     if (aMode == TopAbs_FACE) {
72       BRep_Builder aBuilder;
73       TopoDS_Compound aComp;
74       aBuilder.MakeCompound(aComp);
75       aBuilder.Add(aComp, myOriginalShape);
76       std::list<std::shared_ptr<GeomAPI_Shape>>::const_iterator aIt;
77       for (aIt = myFacesList.cbegin(); aIt != myFacesList.cend(); ++aIt) {
78         TopoDS_Shape aFace = (*aIt)->impl<TopoDS_Shape>();
79         aBuilder.Add(aComp, aFace);
80       }
81       Set(aComp);
82     } else {
83       Set(myOriginalShape);
84     }
85   }
86   AIS_Shape::ComputeSelection(aSelection, aMode);
87 }