]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_ResultPrs.cpp
Salome HOME
Speed up the redraw of sketch with constraints moved by the point of the line
[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_PlanarEdges.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   std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
23   std::shared_ptr<GeomAPI_PlanarEdges> aWirePtr = 
24     std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(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   std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
49   if (!aShapePtr)
50     return;
51   myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
52   Set(aShapePtr->impl<TopoDS_Shape>());
53   AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
54 }
55
56
57 void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
58                                             const Standard_Integer aMode)
59 {
60   if (myIsSketchMode) {
61     if (aMode == TopAbs_FACE) {
62       BRep_Builder aBuilder;
63       TopoDS_Compound aComp;
64       aBuilder.MakeCompound(aComp);
65       aBuilder.Add(aComp, myOriginalShape);
66       std::list<std::shared_ptr<GeomAPI_Shape>>::const_iterator aIt;
67       for (aIt = myFacesList.cbegin(); aIt != myFacesList.cend(); ++aIt) {
68         TopoDS_Shape aFace = (*aIt)->impl<TopoDS_Shape>();
69         aBuilder.Add(aComp, aFace);
70       }
71       Set(aComp);
72     } else {
73       Set(myOriginalShape);
74     }
75   }
76   AIS_Shape::ComputeSelection(aSelection, aMode);
77 }