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;
75 void PartSet_ResultSketchPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
76 const Handle(Prs3d_Presentation)& thePresentation,
77 const Standard_Integer theMode)
79 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
81 Events_Error::throwException("An empty AIS presentation: PartSet_ResultSketchPrs");
86 ResultConstructionPtr aConstruction =
87 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(myResult);
88 if (aConstruction.get()) {
89 int aFacesNum = aConstruction->facesNum();
90 for(int aFaceIndex = 0; aFaceIndex < aFacesNum; aFaceIndex++) {
91 myFacesList.push_back(aConstruction->face(aFaceIndex));
95 myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
96 if (!myOriginalShape.IsNull()) {
99 // change deviation coefficient to provide more precise circle
100 ModuleBase_Tools::setDefaultDeviationCoefficient(myOriginalShape, Attributes());
101 AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
104 Events_Error::throwException("An empty AIS presentation: PartSet_ResultSketchPrs");
107 // create auxiliary shapes
108 FeaturePtr aResultFeature = ModelAPI_Feature::feature(myResult);
109 CompositeFeaturePtr aSketchFeature = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>
111 std::list<ResultPtr> anAuxiliaryResults;
112 for (int i = 0; i < aSketchFeature->numberOfSubs(); i++) {
113 FeaturePtr aFeature = aSketchFeature->subFeature(i);
114 if (PartSet_Tools::isAuxiliarySketchEntity(aFeature)) {
115 std::list<ResultPtr> aResults = aFeature->results();
116 std::list<ResultPtr>::const_iterator aIt;
117 for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
118 ResultPtr aResult = *aIt;
119 if (aResult.get() && aResult->shape().get())
120 anAuxiliaryResults.push_back(aResult);
124 if (anAuxiliaryResults.size() > 0) {
125 std::vector<int> aColor;
126 aColor = Config_PropManager::color("Visualization", "sketch_auxiliary_color",
127 SKETCH_AUXILIARY_COLOR);
128 Standard_Real anAuxiliaryWidth = 1.;
129 Standard_Integer anAuxiliaryLineStyle = 3;
131 SetColor(Quantity_Color(aColor[0] / 255., aColor[1] / 255., aColor[2] / 255., Quantity_TOC_RGB));
133 //thePresentation->Clear();
134 Handle(Prs3d_Drawer) aDrawer = Attributes();
135 setWidth(aDrawer, anAuxiliaryWidth);
137 Handle(Prs3d_LineAspect) aLineAspect;
139 Aspect_TypeOfLine aType = (Aspect_TypeOfLine)anAuxiliaryLineStyle;
140 if (aDrawer->HasOwnLineAspect()) {
141 aLineAspect = aDrawer->LineAspect();
143 if (aDrawer->HasOwnWireAspect()) {
144 aLineAspect = aDrawer->WireAspect();
146 Quantity_Color aCurrentColor;
147 Aspect_TypeOfLine aCurrentType;
148 Standard_Real aCurrentWidth;
149 aLineAspect->Aspect()->Values(aCurrentColor, aCurrentType, aCurrentWidth);
150 bool isChanged = aType != aCurrentType;
152 aLineAspect->SetTypeOfLine(aType);
154 // end of set line style
156 BRep_Builder aBuilder;
157 TopoDS_Compound aComp;
158 aBuilder.MakeCompound(aComp);
160 std::list<ResultPtr>::const_iterator anIt = anAuxiliaryResults.begin(),
161 aLast = anAuxiliaryResults.end();
162 for (; anIt != aLast; anIt++) {
163 ResultPtr aResult = *anIt;
165 GeomShapePtr aGeomShape = aResult->shape();
166 if (aGeomShape.get()) {
167 const TopoDS_Shape& aShape = aGeomShape->impl<TopoDS_Shape>();
168 if (!aShape.IsNull())
169 aBuilder.Add(aComp, aShape);
173 myAuxiliaryCompound = aComp;
174 StdPrs_WFDeflectionShape::Add(thePresentation, aComp, aDrawer);
179 void debugInfo(const TopoDS_Shape& theShape, const TopAbs_ShapeEnum theType)
181 TopTools_IndexedMapOfShape aSubShapes;
182 TopExp::MapShapes (theShape, theType, aSubShapes);
184 Standard_Boolean isComesFromDecomposition = !((aSubShapes.Extent() == 1) && (theShape == aSubShapes (1)));
185 int anExtent = aSubShapes.Extent();
186 for (Standard_Integer aShIndex = 1; aShIndex <= aSubShapes.Extent(); ++aShIndex)
188 const TopoDS_Shape& aSubShape = aSubShapes (aShIndex);
194 void PartSet_ResultSketchPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
195 const Standard_Integer aMode)
198 // In order to avoid using custom selection modes
201 if (aMode == AIS_Shape::SelectionMode(TopAbs_FACE)) {
203 const TopoDS_Shape& aShape = Shape();
204 debugInfo(aShape, TopAbs_VERTEX); // 24
205 debugInfo(aShape, TopAbs_EDGE); // 12
206 debugInfo(aShape, TopAbs_WIRE); // 0
207 debugInfo(aShape, TopAbs_FACE); // 0
209 BRep_Builder aBuilder;
210 TopoDS_Compound aComp;
211 aBuilder.MakeCompound(aComp);
212 aBuilder.Add(aComp, myOriginalShape);
213 std::list<std::shared_ptr<GeomAPI_Shape>>::const_iterator aIt;
214 for (aIt = myFacesList.cbegin(); aIt != myFacesList.cend(); ++aIt) {
215 TopoDS_Shape aFace = (*aIt)->impl<TopoDS_Shape>();
216 aBuilder.Add(aComp, aFace);
217 // for sketch presentation in the face mode wires should be selectable also
218 // accoring to #1343 Improvement of Extrusion and Revolution operations
219 appendShapeSelection(aSelection, aFace, TopAbs_WIRE);
222 debugInfo(aComp, TopAbs_VERTEX); // 24
223 debugInfo(aComp, TopAbs_EDGE); // 12
224 debugInfo(aComp, TopAbs_WIRE); // 4
225 debugInfo(aComp, TopAbs_FACE); // 2
229 Set(myOriginalShape);
231 // append auxiliary compound to selection of edges/vertices
232 if (aMode == AIS_Shape::SelectionMode(TopAbs_EDGE) ||
233 aMode == AIS_Shape::SelectionMode(TopAbs_VERTEX)) {
235 bool isVertex = aMode == AIS_Shape::SelectionMode(TopAbs_VERTEX);
236 appendShapeSelection(aSelection, myAuxiliaryCompound, isVertex ? TopAbs_VERTEX : TopAbs_EDGE);
239 AIS_Shape::ComputeSelection(aSelection, aMode);
242 void PartSet_ResultSketchPrs::appendShapeSelection(const Handle(SelectMgr_Selection)& theSelection,
243 const TopoDS_Shape& theShape,
244 const TopAbs_ShapeEnum& theTypeOfSelection)
246 // POP protection against crash in low layers
247 Standard_Real aDeflection = Prs3d::GetDeflection(theShape, myDrawer);
249 StdSelect_BRepSelectionTool::Load(theSelection,
254 myDrawer->HLRAngle(),
255 myDrawer->IsAutoTriangulation());
256 } catch ( Standard_Failure ) {