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_Tools.h>
12 #include <ModelAPI_ResultConstruction.h>
13 #include <GeomAPI_PlanarEdges.h>
15 #include <Events_Error.h>
17 #include <SketchPlugin_SketchEntity.h>
19 #include <Config_PropManager.h>
21 #include <BRep_Builder.hxx>
22 #include <Prs3d_Drawer.hxx>
24 #include <Prs3d_PointAspect.hxx>
25 #include <TopoDS_Builder.hxx>
26 #include <SelectMgr_SelectionManager.hxx>
27 #include <StdPrs_WFDeflectionShape.hxx>
28 #include <StdSelect_BRepSelectionTool.hxx>
29 #include <Graphic3d_AspectLine3d.hxx>
30 #include <Prs3d_LineAspect.hxx>
35 #include <TopTools_IndexedMapOfShape.hxx>
39 //*******************************************************************************************
41 IMPLEMENT_STANDARD_HANDLE(PartSet_ResultSketchPrs, ViewerData_AISShape);
42 IMPLEMENT_STANDARD_RTTIEXT(PartSet_ResultSketchPrs, ViewerData_AISShape);
44 PartSet_ResultSketchPrs::PartSet_ResultSketchPrs(ResultPtr theResult)
45 : ViewerData_AISShape(TopoDS_Shape()), myResult(theResult)
47 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
49 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
51 Handle(Prs3d_Drawer) aDrawer = Attributes();
52 if (aDrawer->HasOwnPointAspect())
53 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_PLUS);
55 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.));
57 // Activate individual repaintng if this is a part of compsolid
58 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
59 SetAutoHilight(aCompSolid.get() == NULL);
62 bool PartSet_ResultSketchPrs::isValidShapeType(const TopAbs_ShapeEnum& theBaseType,
63 const TopAbs_ShapeEnum& theCheckedType)
65 bool aValid = theBaseType == theCheckedType;
67 // currently this functionality is for all, as we have no separate wire selection mode
68 // lately it should be corrected to have the following check only for sketch presentations
69 aValid = theBaseType == TopAbs_FACE && theCheckedType == TopAbs_WIRE;
74 void PartSet_ResultSketchPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
75 const Handle(Prs3d_Presentation)& thePresentation,
76 const Standard_Integer theMode)
78 thePresentation->Clear();
80 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
82 Events_Error::throwException("An empty AIS presentation: PartSet_ResultSketchPrs");
86 setAuxiliaryPresentationStyle(false);
89 ResultConstructionPtr aConstruction =
90 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(myResult);
91 if (aConstruction.get()) {
92 int aFacesNum = aConstruction->facesNum();
93 for(int aFaceIndex = 0; aFaceIndex < aFacesNum; aFaceIndex++) {
94 myFacesList.push_back(aConstruction->face(aFaceIndex));
97 myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
98 if (!myOriginalShape.IsNull()) {
101 // change deviation coefficient to provide more precise circle
102 ModuleBase_Tools::setDefaultDeviationCoefficient(myOriginalShape, Attributes());
103 AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
106 Events_Error::throwException("An empty AIS presentation: PartSet_ResultSketchPrs");
108 // visualize auxiliary shapes and sketch construction elements(point, center of a circle)
109 FeaturePtr aResultFeature = ModelAPI_Feature::feature(myResult);
110 CompositeFeaturePtr aSketchFeature = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>
112 std::list<ResultPtr> anAuxiliaryResults;
113 /// append auxiliary shapes
114 for (int i = 0; i < aSketchFeature->numberOfSubs(); i++) {
115 FeaturePtr aFeature = aSketchFeature->subFeature(i);
116 if (PartSet_Tools::isAuxiliarySketchEntity(aFeature)) {
117 std::list<ResultPtr> aResults = aFeature->results();
118 std::list<ResultPtr>::const_iterator aIt;
119 for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
120 ResultPtr aResult = *aIt;
121 if (aResult.get() && aResult->shape().get())
122 anAuxiliaryResults.push_back(aResult);
126 /// append not-edges shapes, e.g. center of a circle, an arc, a point feature
127 const std::list<std::shared_ptr<ModelAPI_Result> >& aRes = aFeature->results();
128 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aResIter = aRes.cbegin();
129 for (; aResIter != aRes.cend(); aResIter++) {
130 std::shared_ptr<ModelAPI_ResultConstruction> aConstr = std::dynamic_pointer_cast<
131 ModelAPI_ResultConstruction>(*aResIter);
133 std::shared_ptr<GeomAPI_Shape> aGeomShape = aConstr->shape();
134 if (aGeomShape.get()) {
135 const TopoDS_Shape& aShape = aGeomShape->impl<TopoDS_Shape>();
136 if (aShape.ShapeType() != TopAbs_EDGE)
137 anAuxiliaryResults.push_back(aConstr);
144 if (anAuxiliaryResults.size() > 0) {
145 setAuxiliaryPresentationStyle(true);
147 BRep_Builder aBuilder;
148 TopoDS_Compound aComp;
149 aBuilder.MakeCompound(aComp);
150 std::list<ResultPtr>::const_iterator anIt = anAuxiliaryResults.begin(),
151 aLast = anAuxiliaryResults.end();
152 for (; anIt != aLast; anIt++) {
153 ResultPtr aResult = *anIt;
155 GeomShapePtr aGeomShape = aResult->shape();
156 if (aGeomShape.get()) {
157 const TopoDS_Shape& aShape = aGeomShape->impl<TopoDS_Shape>();
158 if (!aShape.IsNull())
159 aBuilder.Add(aComp, aShape);
163 myAuxiliaryCompound = aComp;
164 Handle(Prs3d_Drawer) aDrawer = Attributes();
165 StdPrs_WFDeflectionShape::Add(thePresentation, aComp, aDrawer);
170 void debugInfo(const TopoDS_Shape& theShape, const TopAbs_ShapeEnum theType)
172 TopTools_IndexedMapOfShape aSubShapes;
173 TopExp::MapShapes (theShape, theType, aSubShapes);
175 Standard_Boolean isComesFromDecomposition = !((aSubShapes.Extent() == 1) && (theShape == aSubShapes (1)));
176 int anExtent = aSubShapes.Extent();
177 for (Standard_Integer aShIndex = 1; aShIndex <= aSubShapes.Extent(); ++aShIndex)
179 const TopoDS_Shape& aSubShape = aSubShapes (aShIndex);
185 void PartSet_ResultSketchPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
186 const Standard_Integer aMode)
189 // In order to avoid using custom selection modes
192 if (aMode == AIS_Shape::SelectionMode(TopAbs_FACE)) {
194 const TopoDS_Shape& aShape = Shape();
195 debugInfo(aShape, TopAbs_VERTEX); // 24
196 debugInfo(aShape, TopAbs_EDGE); // 12
197 debugInfo(aShape, TopAbs_WIRE); // 0
198 debugInfo(aShape, TopAbs_FACE); // 0
200 BRep_Builder aBuilder;
201 TopoDS_Compound aComp;
202 aBuilder.MakeCompound(aComp);
203 aBuilder.Add(aComp, myOriginalShape);
204 std::list<std::shared_ptr<GeomAPI_Shape>>::const_iterator aIt;
205 for (aIt = myFacesList.cbegin(); aIt != myFacesList.cend(); ++aIt) {
206 TopoDS_Shape aFace = (*aIt)->impl<TopoDS_Shape>();
207 aBuilder.Add(aComp, aFace);
208 // for sketch presentation in the face mode wires should be selectable also
209 // accoring to #1343 Improvement of Extrusion and Revolution operations
210 appendShapeSelection(aSelection, aFace, TopAbs_WIRE);
213 debugInfo(aComp, TopAbs_VERTEX); // 24
214 debugInfo(aComp, TopAbs_EDGE); // 12
215 debugInfo(aComp, TopAbs_WIRE); // 4
216 debugInfo(aComp, TopAbs_FACE); // 2
220 Set(myOriginalShape);
222 // append auxiliary compound to selection of edges/vertices
223 if (aMode == AIS_Shape::SelectionMode(TopAbs_EDGE) ||
224 aMode == AIS_Shape::SelectionMode(TopAbs_VERTEX)) {
226 bool isVertex = aMode == AIS_Shape::SelectionMode(TopAbs_VERTEX);
227 appendShapeSelection(aSelection, myAuxiliaryCompound, isVertex ? TopAbs_VERTEX : TopAbs_EDGE);
230 AIS_Shape::ComputeSelection(aSelection, aMode);
233 void PartSet_ResultSketchPrs::appendShapeSelection(const Handle(SelectMgr_Selection)& theSelection,
234 const TopoDS_Shape& theShape,
235 const TopAbs_ShapeEnum& theTypeOfSelection)
237 // POP protection against crash in low layers
238 Standard_Real aDeflection = Prs3d::GetDeflection(theShape, myDrawer);
240 StdSelect_BRepSelectionTool::Load(theSelection,
245 myDrawer->HLRAngle(),
246 myDrawer->IsAutoTriangulation());
247 } catch ( Standard_Failure ) {
251 void PartSet_ResultSketchPrs::setAuxiliaryPresentationStyle(const bool isAuxiliary)
253 std::vector<int> aColor;
254 Standard_Real aWidth;
255 Standard_Integer aLineStyle;
258 aColor = Config_PropManager::color("Visualization", "result_construction_color",
259 ModelAPI_ResultConstruction::DEFAULT_COLOR());
260 aWidth = PartSet_Tools::getAISDefaultWidth();// default width value
261 aLineStyle = SketchPlugin_SketchEntity::SKETCH_LINE_STYLE();
264 aColor = Config_PropManager::color("Visualization", "sketch_auxiliary_color",
265 SKETCH_AUXILIARY_COLOR);
266 aWidth = SketchPlugin_SketchEntity::SKETCH_LINE_WIDTH_AUXILIARY();
267 aLineStyle = SketchPlugin_SketchEntity::SKETCH_LINE_STYLE_AUXILIARY();
270 Handle(Prs3d_Drawer) aDrawer = Attributes();
271 setColor(aDrawer, Quantity_Color(aColor[0] / 255., aColor[1] / 255., aColor[2] / 255.,
274 setWidth(aDrawer, aWidth);
276 Handle(Prs3d_LineAspect) aLineAspect;
278 Aspect_TypeOfLine aType = (Aspect_TypeOfLine)aLineStyle;
279 if (aDrawer->HasOwnLineAspect()) {
280 aLineAspect = aDrawer->LineAspect();
282 if (aDrawer->HasOwnWireAspect()) {
283 aLineAspect = aDrawer->WireAspect();
285 Quantity_Color aCurrentColor;
286 Aspect_TypeOfLine aPrevLineType;
287 Standard_Real aCurrentWidth;
288 aLineAspect->Aspect()->Values(aCurrentColor, aPrevLineType, aCurrentWidth);
289 bool isChangedLineType = aType != aPrevLineType;
290 if (isChangedLineType) {
291 aLineAspect->SetTypeOfLine(aType);