1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include "ModuleBase_ResultPrs.h"
21 #include "ModuleBase_Tools.h"
23 #include <ModelAPI_Events.h>
24 #include <ModelAPI_Tools.h>
25 #include <ModelAPI_ResultConstruction.h>
26 #include <ModelAPI_ResultCompSolid.h>
27 #include <GeomAPI_PlanarEdges.h>
29 #include <Events_InfoMessage.h>
30 #include <Events_Loop.h>
32 #include <BRep_Builder.hxx>
33 #include <Prs3d_Drawer.hxx>
35 #include <Prs3d_PointAspect.hxx>
36 #include <Prs3d_IsoAspect.hxx>
37 #include <TopoDS_Builder.hxx>
39 #include <SelectMgr_SequenceOfOwner.hxx>
40 #include <SelectMgr_EntityOwner.hxx>
41 #include <SelectMgr_SelectionManager.hxx>
42 #include <StdPrs_WFShape.hxx>
43 #include <StdSelect_BRepSelectionTool.hxx>
44 #include <AIS_InteractiveContext.hxx>
45 #include <AIS_Selection.hxx>
46 #include <TColStd_ListIteratorOfListOfInteger.hxx>
47 #include <Graphic3d_AspectMarker3d.hxx>
48 #include <TopExp_Explorer.hxx>
50 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_BRepOwner, StdSelect_BRepOwner);
52 //*******************************************************************************************
54 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, ViewerData_AISShape);
58 ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
59 : ViewerData_AISShape(TopoDS_Shape()), myResult(theResult), myAdditionalSelectionPriority(0)
61 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
62 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
64 Handle(Prs3d_Drawer) aDrawer = Attributes();
65 if (aDrawer->HasOwnPointAspect())
66 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_PLUS);
68 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.));
70 // Activate individual repaintng if this is a part of compsolid
71 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
72 SetAutoHilight(aCompSolid.get() == NULL);
74 ModuleBase_Tools::setPointBallHighlighting(this);
77 void ModuleBase_ResultPrs::setAdditionalSelectionPriority(const int thePriority)
79 myAdditionalSelectionPriority = thePriority;
82 void ModuleBase_ResultPrs::Compute(
83 const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
84 const Handle(Prs3d_Presentation)& thePresentation,
85 const Standard_Integer theMode)
87 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
88 bool aReadyToDisplay = aShapePtr.get();
89 if (aReadyToDisplay) {
90 myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
91 if (!myOriginalShape.IsNull())
94 // change deviation coefficient to provide more precise circle
95 //ModuleBase_Tools::setDefaultDeviationCoefficient(myResult, Attributes());
96 AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
98 if (!aReadyToDisplay) {
99 Events_InfoMessage("ModuleBase_ResultPrs",
100 "An empty AIS presentation: ModuleBase_ResultPrs").send();
101 static const Events_ID anEvent = Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION);
102 ModelAPI_EventCreator::get()->sendUpdated(myResult, anEvent);
106 void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
107 const Standard_Integer aMode)
109 if (aMode > TopAbs_SHAPE) {
110 // In order to avoid using custom selection modes
111 if (aMode == ModuleBase_ResultPrs::Sel_Result) {
112 AIS_Shape::ComputeSelection(aSelection, TopAbs_COMPOUND);
117 // TODO: OCCT issue should be created for the COMPOUND processing
118 // before it is fixed, the next workaround in necessary
119 if (aMode == AIS_Shape::SelectionMode(TopAbs_COMPOUND)) {
120 const TopoDS_Shape& aShape = Shape();
121 TopExp_Explorer aCompExp(aShape, TopAbs_COMPOUND);
122 // do not activate in compound mode shapes which do not contain compounds
123 if (!aCompExp.More())
127 if (aMode == AIS_Shape::SelectionMode(TopAbs_COMPSOLID)) {
128 // Limit selection area only by actual object (Shape)
129 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
130 if (aCompSolid.get()) {
131 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aCompSolid);
132 if (aShapePtr.get()) {
133 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
134 int aPriority = StdSelect_BRepSelectionTool::GetStandardPriority(aShape, TopAbs_COMPSOLID);
135 /// It is important to have priority for the shape of comp solid result less than priority
136 /// for the presentation shape which is a sub-result.
137 /// Reason is to select the sub-objects before: #1592
138 aPriority = aPriority - 1;
139 double aDeflection = Prs3d::GetDeflection(aShape, myDrawer);
141 Handle(ModuleBase_BRepOwner) aOwner = new ModuleBase_BRepOwner(aShape, aPriority);
142 StdSelect_BRepSelectionTool::ComputeSensitive(aShape, aOwner, aSelection,
143 aDeflection, myDrawer->HLRAngle(), 9, 500);
145 for (aSelection->Init(); aSelection->More(); aSelection->Next()) {
146 Handle(SelectMgr_EntityOwner) anOwner =
147 Handle(SelectMgr_EntityOwner)
148 ::DownCast(aSelection->Sensitive()->BaseSensitive()->OwnerId());
154 //AIS_Shape::ComputeSelection(aSelection, 0);
156 AIS_Shape::ComputeSelection(aSelection, aMode);
158 if (myAdditionalSelectionPriority > 0) {
159 for (aSelection->Init(); aSelection->More(); aSelection->Next()) {
160 Handle(SelectBasics_EntityOwner) aBasicsOwner =
161 aSelection->Sensitive()->BaseSensitive()->OwnerId();
162 if (!aBasicsOwner.IsNull())
163 aBasicsOwner->Set(aBasicsOwner->Priority() + myAdditionalSelectionPriority);
168 void ModuleBase_ResultPrs::appendWiresSelection(const Handle(SelectMgr_Selection)& theSelection,
169 const TopoDS_Shape& theShape)
171 static TopAbs_ShapeEnum TypOfSel
172 = AIS_Shape::SelectionType(AIS_Shape::SelectionMode(TopAbs_WIRE));
173 // POP protection against crash in low layers
174 Standard_Real aDeflection = Prs3d::GetDeflection(theShape, myDrawer);
176 StdSelect_BRepSelectionTool::Load(theSelection,
181 myDrawer->HLRAngle(),
182 myDrawer->IsAutoTriangulation());
183 } catch ( Standard_Failure ) {
187 void ModuleBase_ResultPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
188 const SelectMgr_SequenceOfOwner& theOwners)
190 Handle(SelectMgr_EntityOwner) anOwner;
191 Handle(ModuleBase_BRepOwner) aCompOwner;
192 for (int i = 1; i <= theOwners.Length(); i++) {
193 anOwner = theOwners.Value(i);
194 aCompOwner = Handle(ModuleBase_BRepOwner)::DownCast(anOwner);
195 if (aCompOwner.IsNull()) {
196 thePM->Color(anOwner->Selectable(), GetContext()->SelectionStyle());
199 TopoDS_Shape aShape = aCompOwner->Shape();
200 Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
201 aSelectionPrs->Clear();
203 StdPrs_WFShape::Add(aSelectionPrs, aShape, myDrawer);
205 aSelectionPrs->SetDisplayPriority(9);
206 aSelectionPrs->Highlight(GetContext()->SelectionStyle());
207 aSelectionPrs->Display();
208 thePM->Color(this, GetContext()->SelectionStyle());
213 void ModuleBase_ResultPrs::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
214 const Handle(Graphic3d_HighlightStyle)& theStyle,
215 const Handle(SelectMgr_EntityOwner)& theOwner)
217 Handle(StdSelect_BRepOwner) aOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
221 TopoDS_Shape aShape = aOwner->Shape();
222 if (!aShape.IsNull()) {
223 thePM->Color(this, theStyle);
225 Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
226 aHilightPrs->Clear();
228 StdPrs_WFShape::Add(aHilightPrs, aShape, myDrawer);
229 aHilightPrs->Highlight(theStyle);
231 if (thePM->IsImmediateModeOn())
232 thePM->AddToImmediateList(aHilightPrs);