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 <SketcherPrs_Tools.h>
23 #include <Config_PropManager.h>
25 #include <BRep_Builder.hxx>
26 #include <Prs3d_Drawer.hxx>
28 #include <Prs3d_PointAspect.hxx>
29 #include <TopoDS_Builder.hxx>
30 #include <SelectMgr_SelectionManager.hxx>
31 #include <StdPrs_WFDeflectionShape.hxx>
32 #include <StdSelect_BRepSelectionTool.hxx>
33 #include <Graphic3d_AspectLine3d.hxx>
34 #include <Prs3d_LineAspect.hxx>
35 #include <Graphic3d_AspectMarker3d.hxx>
40 #include <TopTools_IndexedMapOfShape.hxx>
44 //*******************************************************************************************
46 IMPLEMENT_STANDARD_HANDLE(PartSet_ResultSketchPrs, ViewerData_AISShape);
47 IMPLEMENT_STANDARD_RTTIEXT(PartSet_ResultSketchPrs, ViewerData_AISShape);
49 PartSet_ResultSketchPrs::PartSet_ResultSketchPrs(ResultPtr theResult)
50 : ViewerData_AISShape(TopoDS_Shape()), myResult(theResult)
52 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
54 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
56 Handle(Prs3d_Drawer) aDrawer = Attributes();
57 if (aDrawer->HasOwnPointAspect())
58 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_PLUS);
60 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.));
62 // Activate individual repaintng if this is a part of compsolid
63 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
64 SetAutoHilight(aCompSolid.get() == NULL);
66 ModuleBase_Tools::setPointBallHighlighting(this);
69 void PartSet_ResultSketchPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
70 const Handle(Prs3d_Presentation)& thePresentation,
71 const Standard_Integer theMode)
73 thePresentation->Clear();
75 TopoDS_Shape aResultShape;
76 TopoDS_Compound anAuxiliaryCompound;
77 NCollection_List<TopoDS_Shape> aFaceList;
78 fillShapes(aResultShape, anAuxiliaryCompound, mySketchFaceList);
80 bool aReadyToDisplay = !aResultShape.IsNull() || !anAuxiliaryCompound.IsNull();
82 if (aReadyToDisplay) {
83 if (!aResultShape.IsNull()) {
84 myOriginalShape = aResultShape;
85 if (!myOriginalShape.IsNull())
88 myAuxiliaryCompound = anAuxiliaryCompound;
91 setAuxiliaryPresentationStyle(false);
93 // change deviation coefficient to provide more precise circle
94 ModuleBase_Tools::setDefaultDeviationCoefficient(myResult, Attributes());
95 AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
97 if (!myAuxiliaryCompound.IsNull()) {
98 setAuxiliaryPresentationStyle(true);
100 Handle(Prs3d_Drawer) aDrawer = Attributes();
101 StdPrs_WFDeflectionShape::Add(thePresentation, myAuxiliaryCompound, aDrawer);
104 if (!aReadyToDisplay) {
105 Events_InfoMessage("PartSet_ResultSketchPrs", "An empty AIS presentation: PartSet_ResultSketchPrs").send();
106 static const Events_ID anEvent = Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION);
107 ModelAPI_EventCreator::get()->sendUpdated(myResult, anEvent);
112 void debugInfo(const TopoDS_Shape& theShape, const TopAbs_ShapeEnum theType)
114 TopTools_IndexedMapOfShape aSubShapes;
115 TopExp::MapShapes (theShape, theType, aSubShapes);
117 Standard_Boolean isComesFromDecomposition = !((aSubShapes.Extent() == 1) && (theShape == aSubShapes (1)));
118 int anExtent = aSubShapes.Extent();
119 for (Standard_Integer aShIndex = 1; aShIndex <= aSubShapes.Extent(); ++aShIndex)
121 const TopoDS_Shape& aSubShape = aSubShapes (aShIndex);
127 void PartSet_ResultSketchPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
128 const Standard_Integer theMode)
133 aMode != SketcherPrs_Tools::Sel_Sketch_Face &&
134 aMode != SketcherPrs_Tools::Sel_Sketch_Wire)
135 // In order to avoid using custom selection modes
138 bool aShapeIsChanged = false;
139 if (aMode == SketcherPrs_Tools::Sel_Sketch_Face ||
140 aMode == SketcherPrs_Tools::Sel_Sketch_Wire) {
141 aMode = (aMode == SketcherPrs_Tools::Sel_Sketch_Face) ? AIS_Shape::SelectionMode(TopAbs_FACE)
142 : AIS_Shape::SelectionMode(TopAbs_WIRE);
144 const TopoDS_Shape& aShape = Shape();
145 debugInfo(aShape, TopAbs_VERTEX); // 24
146 debugInfo(aShape, TopAbs_EDGE); // 12
147 debugInfo(aShape, TopAbs_WIRE); // 0
148 debugInfo(aShape, TopAbs_FACE); // 0
150 BRep_Builder aBuilder;
151 TopoDS_Compound aComp;
152 aBuilder.MakeCompound(aComp);
153 aBuilder.Add(aComp, myOriginalShape);
155 for(NCollection_List<TopoDS_Shape>::Iterator anIt(mySketchFaceList); anIt.More(); anIt.Next()) {
156 const TopoDS_Shape& aFace = anIt.Value();
157 aBuilder.Add(aComp, aFace);
160 debugInfo(aComp, TopAbs_VERTEX); // 24
161 debugInfo(aComp, TopAbs_EDGE); // 12
162 debugInfo(aComp, TopAbs_WIRE); // 4
163 debugInfo(aComp, TopAbs_FACE); // 2
166 aShapeIsChanged = true;
169 Set(myOriginalShape);
171 // append auxiliary compound to selection of edges/vertices
172 if (aMode == AIS_Shape::SelectionMode(TopAbs_EDGE) ||
173 aMode == AIS_Shape::SelectionMode(TopAbs_VERTEX)) {
175 bool isVertex = aMode == AIS_Shape::SelectionMode(TopAbs_VERTEX);
176 appendShapeSelection(aSelection, myAuxiliaryCompound, isVertex ? TopAbs_VERTEX : TopAbs_EDGE);
179 AIS_Shape::ComputeSelection(aSelection, aMode);
182 Set(myOriginalShape);
185 void PartSet_ResultSketchPrs::appendShapeSelection(const Handle(SelectMgr_Selection)& theSelection,
186 const TopoDS_Shape& theShape,
187 const TopAbs_ShapeEnum& theTypeOfSelection)
189 // POP protection against crash in low layers
190 Standard_Real aDeflection = Prs3d::GetDeflection(theShape, myDrawer);
192 StdSelect_BRepSelectionTool::Load(theSelection,
197 myDrawer->HLRAngle(),
198 myDrawer->IsAutoTriangulation());
199 } catch ( Standard_Failure ) {
203 void PartSet_ResultSketchPrs::setAuxiliaryPresentationStyle(const bool isAuxiliary)
205 std::vector<int> aColor;
206 Standard_Real aWidth;
207 Standard_Integer aLineStyle;
210 aColor = Config_PropManager::color("Visualization", "result_construction_color",
211 ModelAPI_ResultConstruction::DEFAULT_COLOR());
212 aWidth = PartSet_Tools::getAISDefaultWidth();// default width value
213 aLineStyle = SketchPlugin_SketchEntity::SKETCH_LINE_STYLE();
216 aColor = Config_PropManager::color("Visualization", "result_construction_color",
217 ModelAPI_ResultConstruction::DEFAULT_COLOR());
218 aWidth = PartSet_Tools::getAISDefaultWidth();// default width value
219 aLineStyle = SketchPlugin_SketchEntity::SKETCH_LINE_STYLE_AUXILIARY();
222 Handle(Prs3d_Drawer) aDrawer = Attributes();
223 setColor(aDrawer, Quantity_Color(aColor[0] / 255., aColor[1] / 255., aColor[2] / 255.,
226 setWidth(aDrawer, aWidth);
228 Handle(Prs3d_LineAspect) aLineAspect;
230 Aspect_TypeOfLine aType = (Aspect_TypeOfLine)aLineStyle;
231 if (aDrawer->HasOwnLineAspect()) {
232 aLineAspect = aDrawer->LineAspect();
234 if (aDrawer->HasOwnWireAspect()) {
235 aLineAspect = aDrawer->WireAspect();
237 Quantity_Color aCurrentColor;
238 Aspect_TypeOfLine aPrevLineType;
239 Standard_Real aCurrentWidth;
240 aLineAspect->Aspect()->Values(aCurrentColor, aPrevLineType, aCurrentWidth);
241 bool isChangedLineType = aType != aPrevLineType;
242 if (isChangedLineType) {
243 aLineAspect->SetTypeOfLine(aType);
247 void PartSet_ResultSketchPrs::fillShapes(TopoDS_Shape& theResultShape,
248 TopoDS_Compound& theAuxiliaryCompound,
249 NCollection_List<TopoDS_Shape>& theFaceList)
251 //if (!aResultShape.IsNull() || !anAuxiliaryCompound.IsNull())
252 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
257 ResultConstructionPtr aConstruction =
258 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(myResult);
259 if (aConstruction.get()) {
260 int aFacesNum = aConstruction->facesNum();
261 for(int aFaceIndex = 0; aFaceIndex < aFacesNum; aFaceIndex++) {
262 std::shared_ptr<GeomAPI_Face> aFaceShape = aConstruction->face(aFaceIndex);
263 if (aFaceShape.get()) {
264 TopoDS_Shape aFace = (aFaceShape)->impl<TopoDS_Shape>();
265 theFaceList.Append(aFace);
269 theResultShape = aShapePtr->impl<TopoDS_Shape>();
271 /// find auxiliary shapes
272 FeaturePtr aResultFeature = ModelAPI_Feature::feature(myResult);
273 CompositeFeaturePtr aSketchFeature = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>
275 std::list<ResultPtr> anAuxiliaryResults;
276 for (int i = 0; i < aSketchFeature->numberOfSubs(); i++) {
277 FeaturePtr aFeature = aSketchFeature->subFeature(i);
278 if (PartSet_Tools::isAuxiliarySketchEntity(aFeature)) {
279 std::list<ResultPtr> aResults = aFeature->results();
280 std::list<ResultPtr>::const_iterator aIt;
281 for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
282 ResultPtr aResult = *aIt;
283 if (aResult.get() && aResult->shape().get())
284 anAuxiliaryResults.push_back(aResult);
288 /// append not-edges shapes, e.g. center of a circle, an arc, a point feature
289 const std::list<std::shared_ptr<ModelAPI_Result> >& aRes = aFeature->results();
290 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aResIter = aRes.cbegin();
291 for (; aResIter != aRes.cend(); aResIter++) {
292 std::shared_ptr<ModelAPI_ResultConstruction> aConstr = std::dynamic_pointer_cast<
293 ModelAPI_ResultConstruction>(*aResIter);
295 std::shared_ptr<GeomAPI_Shape> aGeomShape = aConstr->shape();
296 if (aGeomShape.get()) {
297 const TopoDS_Shape& aShape = aGeomShape->impl<TopoDS_Shape>();
298 if (aShape.ShapeType() != TopAbs_EDGE)
299 anAuxiliaryResults.push_back(aConstr);
306 if (anAuxiliaryResults.size() > 0) {
307 BRep_Builder aBuilder;
308 //TopoDS_Compound aComp;
309 aBuilder.MakeCompound(theAuxiliaryCompound);
310 std::list<ResultPtr>::const_iterator anIt = anAuxiliaryResults.begin(),
311 aLast = anAuxiliaryResults.end();
312 for (; anIt != aLast; anIt++) {
313 ResultPtr aResult = *anIt;
315 GeomShapePtr aGeomShape = aResult->shape();
316 if (aGeomShape.get()) {
317 const TopoDS_Shape& aShape = aGeomShape->impl<TopoDS_Shape>();
318 if (!aShape.IsNull())
319 aBuilder.Add(theAuxiliaryCompound, aShape);