Salome HOME
Create Presentation for rigid constraint
[modules/shaper.git] / src / ModuleBase / ModuleBase_ResultPrs.cpp
1 // File:        ModuleBase_ResultPrs.cpp
2 // Created:     21 October 2014
3 // Author:      Vitaly SMETANNIKOV
4
5 #include "ModuleBase_ResultPrs.h"
6
7 #include <ModelAPI_Tools.h>
8 #include <GeomAPI_Wire.h>
9 #include <GeomAlgoAPI_SketchBuilder.h>
10
11 #include <BRep_Builder.hxx>
12 #include <AIS_Drawer.hxx>
13 #include <Prs3d_IsoAspect.hxx>
14 #include <TopoDS_Builder.hxx>
15
16 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ResultPrs, AIS_Shape);
17 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, AIS_Shape);
18
19 ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
20   : AIS_Shape(TopoDS_Shape()), myResult(theResult), myIsSketchMode(false)
21 {
22   boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
23   boost::shared_ptr<GeomAPI_Wire> aWirePtr = 
24     boost::dynamic_pointer_cast<GeomAPI_Wire>(aShapePtr);
25   if (aWirePtr) {
26     if (aWirePtr->hasPlane() ) {
27       // If this is a wire with plane defined thin it is a sketch-like object
28       // It must have invisible faces
29       GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(),
30         aWirePtr->dirY(), aWirePtr->norm(), aWirePtr, myFacesList);
31
32       myOriginalShape = aWirePtr->impl<TopoDS_Shape>();
33       Set(myOriginalShape);
34       myIsSketchMode = true;
35     } else {
36       Set(aWirePtr->impl<TopoDS_Shape>());
37     }
38   } else {
39     Set(aShapePtr->impl<TopoDS_Shape>());
40   }
41 }
42
43
44 void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
45                                    const Handle(Prs3d_Presentation)& thePresentation, 
46                                    const Standard_Integer theMode)
47 {
48   boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
49   myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
50   Set(aShapePtr->impl<TopoDS_Shape>());
51   AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
52 }
53
54
55 void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
56                                             const Standard_Integer aMode)
57 {
58   if (myIsSketchMode) {
59     if (aMode == TopAbs_FACE) {
60       BRep_Builder aBuilder;
61       TopoDS_Compound aComp;
62       aBuilder.MakeCompound(aComp);
63       aBuilder.Add(aComp, myOriginalShape);
64       std::list<boost::shared_ptr<GeomAPI_Shape>>::const_iterator aIt;
65       for (aIt = myFacesList.cbegin(); aIt != myFacesList.cend(); ++aIt) {
66         TopoDS_Shape aFace = (*aIt)->impl<TopoDS_Shape>();
67         aBuilder.Add(aComp, aFace);
68       }
69       Set(aComp);
70     } else {
71       Set(myOriginalShape);
72     }
73   }
74   AIS_Shape::ComputeSelection(aSelection, aMode);
75 }