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