Salome HOME
Issue #273: Add copyright string
[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 <GeomAPI_PlanarEdges.h>
11 #include <GeomAlgoAPI_SketchBuilder.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       GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(),
32         aWirePtr->dirY(), aWirePtr->norm(), aWirePtr, myFacesList);
33
34       myOriginalShape = aWirePtr->impl<TopoDS_Shape>();
35       Set(myOriginalShape);
36       myIsSketchMode = true;
37     } else {
38       Set(aWirePtr->impl<TopoDS_Shape>());
39     }
40   } else {
41     Set(aShapePtr->impl<TopoDS_Shape>());
42   }
43 }
44
45
46 void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
47                                    const Handle(Prs3d_Presentation)& thePresentation, 
48                                    const Standard_Integer theMode)
49 {
50   std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
51   if (!aShapePtr)
52     return;
53   myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
54   Set(aShapePtr->impl<TopoDS_Shape>());
55   AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
56 }
57
58
59 void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
60                                             const Standard_Integer aMode)
61 {
62   if (myIsSketchMode) {
63     if (aMode == TopAbs_FACE) {
64       BRep_Builder aBuilder;
65       TopoDS_Compound aComp;
66       aBuilder.MakeCompound(aComp);
67       aBuilder.Add(aComp, myOriginalShape);
68       std::list<std::shared_ptr<GeomAPI_Shape>>::const_iterator aIt;
69       for (aIt = myFacesList.cbegin(); aIt != myFacesList.cend(); ++aIt) {
70         TopoDS_Shape aFace = (*aIt)->impl<TopoDS_Shape>();
71         aBuilder.Add(aComp, aFace);
72       }
73       Set(aComp);
74     } else {
75       Set(myOriginalShape);
76     }
77   }
78   AIS_Shape::ComputeSelection(aSelection, aMode);
79 }