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