]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_ResultPrs.cpp
Salome HOME
Issue #2052: Modification of parameters don't work (sketch, extrusion)
[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_Events.h>
11 #include <ModelAPI_Tools.h>
12 #include <ModelAPI_ResultConstruction.h>
13 #include <ModelAPI_ResultCompSolid.h>
14 #include <GeomAPI_PlanarEdges.h>
15
16 #include <Events_InfoMessage.h>
17 #include <Events_Loop.h>
18
19 #include <BRep_Builder.hxx>
20 #include <Prs3d_Drawer.hxx>
21 #include <Prs3d.hxx>
22 #include <Prs3d_PointAspect.hxx>
23 #include <Prs3d_IsoAspect.hxx>
24 #include <TopoDS_Builder.hxx>
25 #include <TopoDS.hxx>
26 #include <SelectMgr_SequenceOfOwner.hxx>
27 #include <SelectMgr_EntityOwner.hxx>
28 #include <SelectMgr_SelectionManager.hxx>
29 #include <StdPrs_WFShape.hxx>
30 #include <StdSelect_BRepSelectionTool.hxx>
31 #include <AIS_InteractiveContext.hxx>
32 #include <AIS_Selection.hxx>
33 #include <TColStd_ListIteratorOfListOfInteger.hxx>
34 #include <Graphic3d_AspectMarker3d.hxx>
35 #include <TopExp_Explorer.hxx>
36
37 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_BRepOwner, StdSelect_BRepOwner);
38
39 //*******************************************************************************************
40
41 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, ViewerData_AISShape);
42
43
44
45 ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
46   : ViewerData_AISShape(TopoDS_Shape()), myResult(theResult), myAdditionalSelectionPriority(0)
47 {
48   std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
49   TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
50   Set(aShape);
51   Handle(Prs3d_Drawer) aDrawer = Attributes();
52   if (aDrawer->HasOwnPointAspect())
53     aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_PLUS);
54   else
55     aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.));
56
57   // Activate individual repaintng if this is a part of compsolid
58   ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
59   SetAutoHilight(aCompSolid.get() == NULL);
60
61   ModuleBase_Tools::setPointBallHighlighting(this);
62 }
63
64 void ModuleBase_ResultPrs::setAdditionalSelectionPriority(const int thePriority)
65 {
66   myAdditionalSelectionPriority = thePriority;
67 }
68
69 void ModuleBase_ResultPrs::Compute(
70           const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
71           const Handle(Prs3d_Presentation)& thePresentation,
72           const Standard_Integer theMode)
73 {
74   std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
75   bool aReadyToDisplay = aShapePtr.get();
76   if (aReadyToDisplay) {
77     myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
78     if (!myOriginalShape.IsNull())
79       Set(myOriginalShape);
80   }
81   // change deviation coefficient to provide more precise circle
82   //ModuleBase_Tools::setDefaultDeviationCoefficient(myResult, Attributes());
83   AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
84
85   if (!aReadyToDisplay) {
86     Events_InfoMessage("ModuleBase_ResultPrs",
87                        "An empty AIS presentation: ModuleBase_ResultPrs").send();
88     static const Events_ID anEvent = Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION);
89     ModelAPI_EventCreator::get()->sendUpdated(myResult, anEvent);
90   }
91 }
92
93 void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
94                                             const Standard_Integer aMode)
95 {
96   if (aMode > TopAbs_SHAPE) {
97     // In order to avoid using custom selection modes
98     if (aMode == ModuleBase_ResultPrs::Sel_Result) {
99       AIS_Shape::ComputeSelection(aSelection, TopAbs_COMPOUND);
100     }
101     return;
102   }
103
104   // TODO: OCCT issue should be created for the COMPOUND processing
105   // before it is fixed, the next workaround in necessary
106   if (aMode == AIS_Shape::SelectionMode(TopAbs_COMPOUND)) {
107     const TopoDS_Shape& aShape = Shape();
108     TopExp_Explorer aCompExp(aShape, TopAbs_COMPOUND);
109     // do not activate in compound mode shapes which do not contain compounds
110     if (!aCompExp.More())
111       return;
112   }
113
114   if (aMode == AIS_Shape::SelectionMode(TopAbs_COMPSOLID)) {
115     // Limit selection area only by actual object (Shape)
116     ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
117     if (aCompSolid.get()) {
118       std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aCompSolid);
119       if (aShapePtr.get()) {
120         TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
121         int aPriority = StdSelect_BRepSelectionTool::GetStandardPriority(aShape, TopAbs_COMPSOLID);
122         /// It is important to have priority for the shape of comp solid result less than priority
123         /// for the presentation shape which is a sub-result.
124         /// Reason is to select the sub-objects before: #1592
125         aPriority = aPriority - 1;
126         double aDeflection = Prs3d::GetDeflection(aShape, myDrawer);
127
128         Handle(ModuleBase_BRepOwner) aOwner = new ModuleBase_BRepOwner(aShape, aPriority);
129         StdSelect_BRepSelectionTool::ComputeSensitive(aShape, aOwner, aSelection,
130           aDeflection, myDrawer->HLRAngle(), 9, 500);
131
132         for (aSelection->Init(); aSelection->More(); aSelection->Next()) {
133           Handle(SelectMgr_EntityOwner) anOwner =
134             Handle(SelectMgr_EntityOwner)
135             ::DownCast(aSelection->Sensitive()->BaseSensitive()->OwnerId());
136           anOwner->Set(this);
137         }
138         return;
139       }
140     }
141     //AIS_Shape::ComputeSelection(aSelection, 0);
142   }
143   AIS_Shape::ComputeSelection(aSelection, aMode);
144
145   if (myAdditionalSelectionPriority > 0) {
146     for (aSelection->Init(); aSelection->More(); aSelection->Next()) {
147       Handle(SelectBasics_EntityOwner) aBasicsOwner =
148         aSelection->Sensitive()->BaseSensitive()->OwnerId();
149       if (!aBasicsOwner.IsNull())
150         aBasicsOwner->Set(aBasicsOwner->Priority() + myAdditionalSelectionPriority);
151     }
152   }
153 }
154
155 void ModuleBase_ResultPrs::appendWiresSelection(const Handle(SelectMgr_Selection)& theSelection,
156                                                 const TopoDS_Shape& theShape)
157 {
158   static TopAbs_ShapeEnum TypOfSel
159           = AIS_Shape::SelectionType(AIS_Shape::SelectionMode(TopAbs_WIRE));
160   // POP protection against crash in low layers
161   Standard_Real aDeflection = Prs3d::GetDeflection(theShape, myDrawer);
162   try {
163     StdSelect_BRepSelectionTool::Load(theSelection,
164                                       this,
165                                       theShape,
166                                       TypOfSel,
167                                       aDeflection,
168                                       myDrawer->HLRAngle(),
169                                       myDrawer->IsAutoTriangulation());
170   } catch ( Standard_Failure ) {
171   }
172 }
173
174 void ModuleBase_ResultPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
175                                            const SelectMgr_SequenceOfOwner& theOwners)
176 {
177   Handle(SelectMgr_EntityOwner) anOwner;
178   Handle(ModuleBase_BRepOwner) aCompOwner;
179   for (int i = 1; i <= theOwners.Length(); i++) {
180     anOwner = theOwners.Value(i);
181     aCompOwner = Handle(ModuleBase_BRepOwner)::DownCast(anOwner);
182     if (aCompOwner.IsNull()) {
183       thePM->Color(anOwner->Selectable(), GetContext()->SelectionStyle());
184     }
185     else {
186       TopoDS_Shape aShape = aCompOwner->Shape();
187       Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
188       aSelectionPrs->Clear();
189
190       StdPrs_WFShape::Add(aSelectionPrs, aShape, myDrawer);
191
192       aSelectionPrs->SetDisplayPriority(9);
193       aSelectionPrs->Highlight(GetContext()->SelectionStyle());
194       aSelectionPrs->Display();
195       thePM->Color(this, GetContext()->SelectionStyle());
196     }
197   }
198 }
199
200 void ModuleBase_ResultPrs::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
201                                                  const Handle(Graphic3d_HighlightStyle)& theStyle,
202                                                  const Handle(SelectMgr_EntityOwner)& theOwner)
203 {
204   Handle(StdSelect_BRepOwner) aOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
205   if (aOwner.IsNull())
206     return;
207
208   TopoDS_Shape aShape = aOwner->Shape();
209   if (!aShape.IsNull()) {
210     thePM->Color(this, theStyle);
211
212     Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
213     aHilightPrs->Clear();
214
215     StdPrs_WFShape::Add(aHilightPrs, aShape, myDrawer);
216     aHilightPrs->Highlight(theStyle);
217
218     if (thePM->IsImmediateModeOn())
219       thePM->AddToImmediateList(aHilightPrs);
220   }
221 }