1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_ResultSketchPrs.h
4 // Created: 25 March 2015
5 // Author: Natalia ERMOLAEVA
7 #include "PartSet_ResultSketchPrs.h"
8 #include "PartSet_Tools.h"
9 #include "ModuleBase_Tools.h"
11 #include <ModelAPI_Events.h>
12 #include <ModelAPI_Tools.h>
13 #include <ModelAPI_ResultConstruction.h>
14 #include <GeomAPI_PlanarEdges.h>
16 #include <Events_InfoMessage.h>
17 #include <Events_Loop.h>
19 #include <SketchPlugin_SketchEntity.h>
21 #include <Config_PropManager.h>
23 #include <BRep_Builder.hxx>
24 #include <Prs3d_Drawer.hxx>
26 #include <Prs3d_PointAspect.hxx>
27 #include <TopoDS_Builder.hxx>
28 #include <SelectMgr_SelectionManager.hxx>
29 #include <StdPrs_WFDeflectionShape.hxx>
30 #include <StdSelect_BRepSelectionTool.hxx>
31 #include <Graphic3d_AspectLine3d.hxx>
32 #include <Prs3d_LineAspect.hxx>
37 #include <TopTools_IndexedMapOfShape.hxx>
41 //*******************************************************************************************
43 IMPLEMENT_STANDARD_HANDLE(PartSet_ResultSketchPrs, ViewerData_AISShape);
44 IMPLEMENT_STANDARD_RTTIEXT(PartSet_ResultSketchPrs, ViewerData_AISShape);
46 PartSet_ResultSketchPrs::PartSet_ResultSketchPrs(ResultPtr theResult)
47 : ViewerData_AISShape(TopoDS_Shape()), myResult(theResult)
49 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
51 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
53 Handle(Prs3d_Drawer) aDrawer = Attributes();
54 if (aDrawer->HasOwnPointAspect())
55 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_PLUS);
57 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.));
59 // Activate individual repaintng if this is a part of compsolid
60 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
61 SetAutoHilight(aCompSolid.get() == NULL);
64 void PartSet_ResultSketchPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
65 const Handle(Prs3d_Presentation)& thePresentation,
66 const Standard_Integer theMode)
68 thePresentation->Clear();
70 TopoDS_Shape aResultShape;
71 TopoDS_Compound anAuxiliaryCompound;
72 NCollection_List<TopoDS_Shape> aFaceList;
73 fillShapes(aResultShape, anAuxiliaryCompound, mySketchFaceList);
75 bool aReadyToDisplay = !aResultShape.IsNull() || !anAuxiliaryCompound.IsNull();
77 if (aReadyToDisplay) {
78 if (!aResultShape.IsNull()) {
79 myOriginalShape = aResultShape;
80 if (!myOriginalShape.IsNull())
83 myAuxiliaryCompound = anAuxiliaryCompound;
86 setAuxiliaryPresentationStyle(false);
88 // change deviation coefficient to provide more precise circle
89 ModuleBase_Tools::setDefaultDeviationCoefficient(Shape(), Attributes());
90 AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
92 if (!myAuxiliaryCompound.IsNull()) {
93 setAuxiliaryPresentationStyle(true);
95 Handle(Prs3d_Drawer) aDrawer = Attributes();
96 StdPrs_WFDeflectionShape::Add(thePresentation, myAuxiliaryCompound, aDrawer);
99 if (!aReadyToDisplay) {
100 Events_InfoMessage("PartSet_ResultSketchPrs", "An empty AIS presentation: PartSet_ResultSketchPrs").send();
101 static const Events_ID anEvent = Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION);
102 ModelAPI_EventCreator::get()->sendUpdated(myResult, anEvent);
107 void debugInfo(const TopoDS_Shape& theShape, const TopAbs_ShapeEnum theType)
109 TopTools_IndexedMapOfShape aSubShapes;
110 TopExp::MapShapes (theShape, theType, aSubShapes);
112 Standard_Boolean isComesFromDecomposition = !((aSubShapes.Extent() == 1) && (theShape == aSubShapes (1)));
113 int anExtent = aSubShapes.Extent();
114 for (Standard_Integer aShIndex = 1; aShIndex <= aSubShapes.Extent(); ++aShIndex)
116 const TopoDS_Shape& aSubShape = aSubShapes (aShIndex);
122 void PartSet_ResultSketchPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
123 const Standard_Integer aMode)
126 // In order to avoid using custom selection modes
129 bool aShapeIsChanged = false;
130 if (aMode == AIS_Shape::SelectionMode(TopAbs_FACE) ||
131 aMode == AIS_Shape::SelectionMode(TopAbs_WIRE)) {
133 const TopoDS_Shape& aShape = Shape();
134 debugInfo(aShape, TopAbs_VERTEX); // 24
135 debugInfo(aShape, TopAbs_EDGE); // 12
136 debugInfo(aShape, TopAbs_WIRE); // 0
137 debugInfo(aShape, TopAbs_FACE); // 0
139 BRep_Builder aBuilder;
140 TopoDS_Compound aComp;
141 aBuilder.MakeCompound(aComp);
142 aBuilder.Add(aComp, myOriginalShape);
144 for(NCollection_List<TopoDS_Shape>::Iterator anIt(mySketchFaceList); anIt.More(); anIt.Next()) {
145 const TopoDS_Shape& aFace = anIt.Value();
146 aBuilder.Add(aComp, aFace);
149 debugInfo(aComp, TopAbs_VERTEX); // 24
150 debugInfo(aComp, TopAbs_EDGE); // 12
151 debugInfo(aComp, TopAbs_WIRE); // 4
152 debugInfo(aComp, TopAbs_FACE); // 2
155 aShapeIsChanged = true;
158 Set(myOriginalShape);
160 // append auxiliary compound to selection of edges/vertices
161 if (aMode == AIS_Shape::SelectionMode(TopAbs_EDGE) ||
162 aMode == AIS_Shape::SelectionMode(TopAbs_VERTEX)) {
164 bool isVertex = aMode == AIS_Shape::SelectionMode(TopAbs_VERTEX);
165 appendShapeSelection(aSelection, myAuxiliaryCompound, isVertex ? TopAbs_VERTEX : TopAbs_EDGE);
168 AIS_Shape::ComputeSelection(aSelection, aMode);
171 Set(myOriginalShape);
174 void PartSet_ResultSketchPrs::appendShapeSelection(const Handle(SelectMgr_Selection)& theSelection,
175 const TopoDS_Shape& theShape,
176 const TopAbs_ShapeEnum& theTypeOfSelection)
178 // POP protection against crash in low layers
179 Standard_Real aDeflection = Prs3d::GetDeflection(theShape, myDrawer);
181 StdSelect_BRepSelectionTool::Load(theSelection,
186 myDrawer->HLRAngle(),
187 myDrawer->IsAutoTriangulation());
188 } catch ( Standard_Failure ) {
192 void PartSet_ResultSketchPrs::setAuxiliaryPresentationStyle(const bool isAuxiliary)
194 std::vector<int> aColor;
195 Standard_Real aWidth;
196 Standard_Integer aLineStyle;
199 aColor = Config_PropManager::color("Visualization", "result_construction_color",
200 ModelAPI_ResultConstruction::DEFAULT_COLOR());
201 aWidth = PartSet_Tools::getAISDefaultWidth();// default width value
202 aLineStyle = SketchPlugin_SketchEntity::SKETCH_LINE_STYLE();
205 aColor = Config_PropManager::color("Visualization", "result_construction_color",
206 ModelAPI_ResultConstruction::DEFAULT_COLOR());
207 aWidth = PartSet_Tools::getAISDefaultWidth();// default width value
208 aLineStyle = SketchPlugin_SketchEntity::SKETCH_LINE_STYLE_AUXILIARY();
211 Handle(Prs3d_Drawer) aDrawer = Attributes();
212 setColor(aDrawer, Quantity_Color(aColor[0] / 255., aColor[1] / 255., aColor[2] / 255.,
215 setWidth(aDrawer, aWidth);
217 Handle(Prs3d_LineAspect) aLineAspect;
219 Aspect_TypeOfLine aType = (Aspect_TypeOfLine)aLineStyle;
220 if (aDrawer->HasOwnLineAspect()) {
221 aLineAspect = aDrawer->LineAspect();
223 if (aDrawer->HasOwnWireAspect()) {
224 aLineAspect = aDrawer->WireAspect();
226 Quantity_Color aCurrentColor;
227 Aspect_TypeOfLine aPrevLineType;
228 Standard_Real aCurrentWidth;
229 aLineAspect->Aspect()->Values(aCurrentColor, aPrevLineType, aCurrentWidth);
230 bool isChangedLineType = aType != aPrevLineType;
231 if (isChangedLineType) {
232 aLineAspect->SetTypeOfLine(aType);
236 void PartSet_ResultSketchPrs::fillShapes(TopoDS_Shape& theResultShape,
237 TopoDS_Compound& theAuxiliaryCompound,
238 NCollection_List<TopoDS_Shape>& theFaceList)
240 //if (!aResultShape.IsNull() || !anAuxiliaryCompound.IsNull())
241 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
246 ResultConstructionPtr aConstruction =
247 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(myResult);
248 if (aConstruction.get()) {
249 int aFacesNum = aConstruction->facesNum();
250 for(int aFaceIndex = 0; aFaceIndex < aFacesNum; aFaceIndex++) {
251 std::shared_ptr<GeomAPI_Face> aFaceShape = aConstruction->face(aFaceIndex);
252 if (aFaceShape.get()) {
253 TopoDS_Shape aFace = (aFaceShape)->impl<TopoDS_Shape>();
254 theFaceList.Append(aFace);
258 theResultShape = aShapePtr->impl<TopoDS_Shape>();
260 /// find auxiliary shapes
261 FeaturePtr aResultFeature = ModelAPI_Feature::feature(myResult);
262 CompositeFeaturePtr aSketchFeature = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>
264 std::list<ResultPtr> anAuxiliaryResults;
265 for (int i = 0; i < aSketchFeature->numberOfSubs(); i++) {
266 FeaturePtr aFeature = aSketchFeature->subFeature(i);
267 if (PartSet_Tools::isAuxiliarySketchEntity(aFeature)) {
268 std::list<ResultPtr> aResults = aFeature->results();
269 std::list<ResultPtr>::const_iterator aIt;
270 for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
271 ResultPtr aResult = *aIt;
272 if (aResult.get() && aResult->shape().get())
273 anAuxiliaryResults.push_back(aResult);
277 /// append not-edges shapes, e.g. center of a circle, an arc, a point feature
278 const std::list<std::shared_ptr<ModelAPI_Result> >& aRes = aFeature->results();
279 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aResIter = aRes.cbegin();
280 for (; aResIter != aRes.cend(); aResIter++) {
281 std::shared_ptr<ModelAPI_ResultConstruction> aConstr = std::dynamic_pointer_cast<
282 ModelAPI_ResultConstruction>(*aResIter);
284 std::shared_ptr<GeomAPI_Shape> aGeomShape = aConstr->shape();
285 if (aGeomShape.get()) {
286 const TopoDS_Shape& aShape = aGeomShape->impl<TopoDS_Shape>();
287 if (aShape.ShapeType() != TopAbs_EDGE)
288 anAuxiliaryResults.push_back(aConstr);
295 if (anAuxiliaryResults.size() > 0) {
296 BRep_Builder aBuilder;
297 //TopoDS_Compound aComp;
298 aBuilder.MakeCompound(theAuxiliaryCompound);
299 std::list<ResultPtr>::const_iterator anIt = anAuxiliaryResults.begin(),
300 aLast = anAuxiliaryResults.end();
301 for (; anIt != aLast; anIt++) {
302 ResultPtr aResult = *anIt;
304 GeomShapePtr aGeomShape = aResult->shape();
305 if (aGeomShape.get()) {
306 const TopoDS_Shape& aShape = aGeomShape->impl<TopoDS_Shape>();
307 if (!aShape.IsNull())
308 aBuilder.Add(theAuxiliaryCompound, aShape);