Salome HOME
ModuleBase_ViewerPrs is wrapped into shared_ptr.
[modules/shaper.git] / src / PartSet / PartSet_Tools.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_Tools.cpp
4 // Created:     28 Apr 2014
5 // Author:      Natalia ERMOLAEVA
6
7 #include <PartSet_Tools.h>
8 #include <PartSet_Module.h>
9 #include <PartSet_SketcherMgr.h>
10
11 #include <ModelAPI_Data.h>
12 #include <ModelAPI_AttributeDouble.h>
13 #include <ModelAPI_AttributeRefList.h>
14 #include <ModelAPI_Document.h>
15 #include <ModelAPI_Session.h>
16 #include <ModelAPI_ResultConstruction.h>
17 #include <ModelAPI_Events.h>
18
19 #include <Events_Loop.h>
20
21 #include <SketcherPrs_Tools.h>
22
23 #include <XGUI_ModuleConnector.h>
24 #include <XGUI_Displayer.h>
25 #include <XGUI_Workshop.h>
26 #include <XGUI_SelectionMgr.h>
27 #include <XGUI_Selection.h>
28
29 #include <GeomDataAPI_Point.h>
30 #include <GeomDataAPI_Dir.h>
31 #include <GeomDataAPI_Point2D.h>
32 #include <GeomAPI_Pln.h>
33 #include <GeomAPI_Pnt2d.h>
34 #include <GeomAPI_Pnt.h>
35 #include <GeomAPI_Edge.h>
36 #include <GeomAPI_Vertex.h>
37
38 #include <GeomAPI_Dir.h>
39 #include <GeomAPI_XYZ.h>
40
41 #include <SketchPlugin_Feature.h>
42 #include <SketchPlugin_Sketch.h>
43 #include <SketchPlugin_ConstraintCoincidence.h>
44 #include <SketchPlugin_ConstraintDistance.h>
45 #include <SketchPlugin_ConstraintLength.h>
46 #include <SketchPlugin_ConstraintRadius.h>
47 #include <SketchPlugin_ConstraintRigid.h>
48 #include <SketchPlugin_Constraint.h>
49 #include <SketchPlugin_Circle.h>
50 #include <SketchPlugin_Arc.h>
51 #include <SketchPlugin_Line.h>
52 #include <SketchPlugin_Point.h>
53
54 #include <ModuleBase_IWorkshop.h>
55 #include <ModuleBase_ViewerPrs.h>
56
57 #include <V3d_View.hxx>
58 #include <gp_Pln.hxx>
59 #include <gp_Circ.hxx>
60 #include <ProjLib.hxx>
61 #include <ElSLib.hxx>
62 #include <Geom_Line.hxx>
63 #include <GeomAPI_ProjectPointOnCurve.hxx>
64 #include <BRep_Tool.hxx>
65 #include <TopoDS.hxx>
66 #include <TopoDS_Edge.hxx>
67 #include <TopoDS_Vertex.hxx>
68 #include <AIS_InteractiveObject.hxx>
69 #include <StdSelect_BRepOwner.hxx>
70 #include <SelectMgr_IndexedMapOfOwner.hxx>
71
72 #ifdef _DEBUG
73 #include <QDebug>
74 #endif
75
76 const double PRECISION_TOLERANCE = 0.000001;
77 const int AIS_DEFAULT_WIDTH = 2;
78
79 int PartSet_Tools::getAISDefaultWidth()
80 {
81   return AIS_DEFAULT_WIDTH;
82 }
83
84 gp_Pnt PartSet_Tools::convertClickToPoint(QPoint thePoint, Handle(V3d_View) theView)
85 {
86   if (theView.IsNull())
87     return gp_Pnt();
88
89   V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
90   theView->Eye(XEye, YEye, ZEye);
91
92   theView->At(XAt, YAt, ZAt);
93   gp_Pnt EyePoint(XEye, YEye, ZEye);
94   gp_Pnt AtPoint(XAt, YAt, ZAt);
95
96   gp_Vec EyeVector(EyePoint, AtPoint);
97   gp_Dir EyeDir(EyeVector);
98
99   gp_Pln PlaneOfTheView = gp_Pln(AtPoint, EyeDir);
100   Standard_Real X, Y, Z;
101   theView->Convert(thePoint.x(), thePoint.y(), X, Y, Z);
102   gp_Pnt ConvertedPoint(X, Y, Z);
103
104   gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView, ConvertedPoint);
105   gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(),
106                                      PlaneOfTheView);
107   return ResultPoint;
108 }
109
110 void PartSet_Tools::convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
111 Handle(V3d_View) theView,
112                                 double& theX, double& theY)
113 {
114   if (!theSketch)
115     return;
116
117   AttributeDoublePtr anAttr;
118   std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
119
120   std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
121       aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
122
123   std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
124       aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
125   std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
126       aData->attribute(SketchPlugin_Sketch::NORM_ID()));
127   std::shared_ptr<GeomAPI_XYZ> anY = aNorm->xyz()->cross(aX->xyz());
128
129   gp_Pnt anOriginPnt(anOrigin->x(), anOrigin->y(), anOrigin->z());
130   gp_Vec aVec(anOriginPnt, thePoint);
131
132   if (!theView.IsNull()) {
133     V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
134     theView->Eye(XEye, YEye, ZEye);
135
136     theView->At(XAt, YAt, ZAt);
137     gp_Pnt EyePoint(XEye, YEye, ZEye);
138     gp_Pnt AtPoint(XAt, YAt, ZAt);
139
140     gp_Vec anEyeVec(EyePoint, AtPoint);
141     anEyeVec.Normalize();
142
143     std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
144         aData->attribute(SketchPlugin_Sketch::NORM_ID()));
145     gp_Vec aNormalVec(aNormal->x(), aNormal->y(), aNormal->z());
146
147     double aDen = anEyeVec * aNormalVec;
148     double aLVec = aDen != 0 ? aVec * aNormalVec / aDen : DBL_MAX;
149
150     gp_Vec aDeltaVec = anEyeVec * aLVec;
151     aVec = aVec - aDeltaVec;
152   }
153   theX = aVec.X() * aX->x() + aVec.Y() * aX->y() + aVec.Z() * aX->z();
154   theY = aVec.X() * anY->x() + aVec.Y() * anY->y() + aVec.Z() * anY->z();
155 }
156
157 std::shared_ptr<GeomAPI_Pnt2d> PartSet_Tools::convertTo2D(FeaturePtr theSketch, 
158                                                     const std::shared_ptr<GeomAPI_Pnt>& thePnt)
159 {
160   std::shared_ptr<GeomAPI_Pnt2d> aRes;
161   if (theSketch->getKind() != SketchPlugin_Sketch::ID())
162     return aRes;
163   std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
164       theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
165   std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
166       theSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
167   std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
168       theSketch->data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
169   std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
170   return thePnt->to2D(aC->pnt(), aX->dir(), aY);
171 }
172
173
174 std::shared_ptr<GeomAPI_Pnt> PartSet_Tools::convertTo3D(const double theX, const double theY, FeaturePtr theSketch)
175 {
176   std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
177
178   std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
179       aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
180   std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
181       aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
182   std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
183       aData->attribute(SketchPlugin_Sketch::NORM_ID()));
184   std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
185
186   std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = 
187     std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY));
188
189   return aPnt2d->to3D(aC->pnt(), aX->dir(), aY);
190 }
191
192 std::shared_ptr<ModelAPI_Document> PartSet_Tools::document()
193 {
194   return ModelAPI_Session::get()->moduleDocument();
195 }
196
197 void PartSet_Tools::setFeatureValue(FeaturePtr theFeature, double theValue,
198                                     const std::string& theAttribute)
199 {
200   if (!theFeature)
201     return;
202   std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
203   AttributeDoublePtr anAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
204       aData->attribute(theAttribute));
205   if (anAttribute)
206     anAttribute->setValue(theValue);
207 }
208
209 double PartSet_Tools::featureValue(FeaturePtr theFeature, const std::string& theAttribute,
210                                    bool& isValid)
211 {
212   isValid = false;
213   double aValue = 0;
214   if (theFeature) {
215     std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
216     AttributeDoublePtr anAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
217         aData->attribute(theAttribute));
218     if (anAttribute) {
219       aValue = anAttribute->value();
220       isValid = true;
221     }
222   }
223   return aValue;
224 }
225
226 FeaturePtr PartSet_Tools::feature(FeaturePtr theFeature, const std::string& theAttribute,
227                                   const std::string& theKind)
228 {
229   FeaturePtr aFeature;
230   if (!theFeature)
231     return aFeature;
232
233   std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
234   std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
235       ModelAPI_AttributeRefAttr>(aData->attribute(theAttribute));
236   if (anAttr) {
237     aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->object());
238     if (!theKind.empty() && aFeature && aFeature->getKind() != theKind) {
239       aFeature = FeaturePtr();
240     }
241   }
242   return aFeature;
243 }
244
245 void PartSet_Tools::createConstraint(CompositeFeaturePtr theSketch,
246                                      std::shared_ptr<GeomDataAPI_Point2D> thePoint1,
247                                      std::shared_ptr<GeomDataAPI_Point2D> thePoint2)
248 {
249   FeaturePtr aFeature;
250   if (theSketch) {
251     aFeature = theSketch->addFeature(SketchPlugin_ConstraintCoincidence::ID());
252   } else {
253     std::shared_ptr<ModelAPI_Document> aDoc = document();
254     aFeature = aDoc->addFeature(SketchPlugin_ConstraintCoincidence::ID());
255   }
256
257   std::shared_ptr<ModelAPI_Data> aData = aFeature->data();
258
259   std::shared_ptr<ModelAPI_AttributeRefAttr> aRef1 = std::dynamic_pointer_cast<
260       ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
261   aRef1->setAttr(thePoint1);
262
263   std::shared_ptr<ModelAPI_AttributeRefAttr> aRef2 = std::dynamic_pointer_cast<
264       ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
265   aRef2->setAttr(thePoint2);
266
267   // we need to flush created signal in order to coincidence is processed by solver
268   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
269 }
270
271 /*std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::
272   findAttributePoint(CompositeFeaturePtr theSketch, double theX, double theY,
273   double theTolerance, const QList<FeaturePtr>& theIgnore)
274 {
275   std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
276       new GeomAPI_Pnt2d(theX, theY));
277
278   std::list<std::shared_ptr<ModelAPI_Attribute> > anAttiributes;
279   for (int i = 0; i < theSketch->numberOfSubs(); i++) {
280     FeaturePtr aFeature = theSketch->subFeature(i);
281     if (!theIgnore.contains(aFeature)) {
282       anAttiributes = aFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
283
284       std::list<std::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt;
285       for (anIt = anAttiributes.cbegin(); anIt != anAttiributes.cend(); ++anIt) {
286         std::shared_ptr<GeomDataAPI_Point2D> aCurPoint = 
287           std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
288         double x = aCurPoint->x();
289         double y = aCurPoint->y();
290         if (aCurPoint && (aCurPoint->pnt()->distance(aClickedPoint) < theTolerance)) {
291           return aCurPoint;
292         }
293       }
294     }
295   }
296   return std::shared_ptr<GeomDataAPI_Point2D>();
297 }*/
298
299
300 std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::findFirstEqualPointInArgumentFeatures(
301                   const FeaturePtr& theFeature, const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
302 {
303   std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint;
304
305   // may be feature is not updated yet, execute is not performed and references features
306   // are not created. Case: rectangle macro feature
307   ModuleBase_ModelWidget::updateObject(theFeature);
308
309   std::list<AttributePtr> anAttributes = theFeature->data()->attributes(
310                                           ModelAPI_AttributeRefList::typeId());
311   std::list<AttributePtr>::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end();
312   for (; anIt != aLast && !aFeaturePoint.get(); anIt++) {
313     std::shared_ptr<ModelAPI_AttributeRefList> aCurSelList =
314                                       std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*anIt);
315     for (int i = 0, aNb = aCurSelList->size(); i < aNb && !aFeaturePoint.get(); i++) {
316       ObjectPtr anObject = aCurSelList->object(i);
317       FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
318       if (aFeature.get())
319         aFeaturePoint = PartSet_Tools::findFirstEqualPoint(aFeature, thePoint);
320     }
321   }
322   return aFeaturePoint;
323 }
324
325 std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::findFirstEqualPoint(const FeaturePtr& theFeature,
326                                                       const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
327 {
328   std::shared_ptr<GeomDataAPI_Point2D> aFPoint;
329
330   // find the given point in the feature attributes
331   std::list<std::shared_ptr<ModelAPI_Attribute> > anAttiributes =
332                                     theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
333   std::list<std::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt = anAttiributes.begin(),
334       aLast = anAttiributes.end();
335   for (; anIt != aLast && !aFPoint; anIt++) {
336     std::shared_ptr<GeomDataAPI_Point2D> aCurPoint = 
337       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
338     if (aCurPoint && (aCurPoint->pnt()->distance(thePoint) < Precision::Confusion())) {
339       aFPoint = aCurPoint;
340       break;
341     }
342   }
343   return aFPoint;
344 }
345
346 void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
347                                    const std::string& theAttribute, double theClickedX,
348                                    double theClickedY)
349 {
350   if (!theFeature.get())
351     return;
352
353   std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
354       new GeomAPI_Pnt2d(theClickedX, theClickedY));
355
356   // find a feature point by the selection mode
357   std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint;
358   if (theFeature->isMacro()) {
359     // the macro feature will be removed after the operation is stopped, so we need to build
360     // coicidence to possible sub-features
361     aFeaturePoint = PartSet_Tools::findFirstEqualPointInArgumentFeatures(theFeature, aClickedPoint);
362   }
363   else {
364     aFeaturePoint = std::dynamic_pointer_cast<
365         GeomDataAPI_Point2D>(theFeature->data()->attribute(theAttribute));
366   }
367   if (!aFeaturePoint)
368     return;
369
370   // get all sketch features. If the point with the given coordinates belong to any sketch feature,
371   // the constraint is created between the feature point and the found sketch point
372   std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
373   std::shared_ptr<ModelAPI_AttributeRefList> aRefList = std::dynamic_pointer_cast<
374       ModelAPI_AttributeRefList>(aData->attribute(SketchPlugin_Sketch::FEATURES_ID()));
375
376   std::list<ObjectPtr> aFeatures = aRefList->list();
377   std::list<ObjectPtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
378   std::list<std::shared_ptr<ModelAPI_Attribute> > anAttiributes;
379   for (; anIt != aLast; anIt++) {
380     FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
381     if (!aFeature.get() || theFeature == aFeature)
382       continue;
383     std::shared_ptr<GeomDataAPI_Point2D> aFPoint = PartSet_Tools::findFirstEqualPoint(aFeature,
384                                                                                 aClickedPoint);
385     if (aFPoint)
386       PartSet_Tools::createConstraint(theSketch, aFPoint, aFeaturePoint);
387   }
388 }
389
390 std::shared_ptr<GeomAPI_Pln> PartSet_Tools::sketchPlane(CompositeFeaturePtr theSketch)
391 {
392   std::shared_ptr<GeomAPI_Pln> aPlane;
393
394   std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
395   if (aData) {
396     std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
397         aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
398     std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
399         aData->attribute(SketchPlugin_Sketch::NORM_ID()));
400     if (aNormal && anOrigin) {
401       double adX = aNormal->x();
402       double adY = aNormal->y();
403       double adZ = aNormal->z();
404
405       if ( (adX != 0) || (adY != 0) || (adZ != 0) ) { // Plane is valid
406         double aX = anOrigin->x();
407         double aY = anOrigin->y();
408         double aZ = anOrigin->z();
409         gp_Pln aPln(gp_Pnt(aX, aY, aZ), gp_Dir(adX, adY, adZ));
410         double aA, aB, aC, aD;
411         aPln.Coefficients(aA, aB, aC, aD);
412         aPlane = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
413       }
414     }
415   }
416   return aPlane;
417 }
418
419 std::shared_ptr<GeomAPI_Pnt> PartSet_Tools::point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
420                                                       CompositeFeaturePtr theSketch)
421 {
422   std::shared_ptr<GeomAPI_Pnt> aPoint;
423   if (!theSketch || !thePoint2D)
424     return aPoint;
425
426   DataPtr aData = theSketch->data();
427   std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
428       aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
429   std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
430       aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
431   std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
432       aData->attribute(SketchPlugin_Sketch::NORM_ID()));
433   std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
434
435   return thePoint2D->to3D(aC->pnt(), aX->dir(), aY);
436 }
437
438 ResultPtr PartSet_Tools::findFixedObjectByExternal(const TopoDS_Shape& theShape,
439                                                    const ObjectPtr& theObject,
440                                                    CompositeFeaturePtr theSketch)
441 {
442   ResultPtr aResult;
443   if (theShape.ShapeType() == TopAbs_EDGE) {
444     // Check that we already have such external edge
445     std::shared_ptr<GeomAPI_Edge> aInEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge());
446     aInEdge->setImpl(new TopoDS_Shape(theShape));
447     aResult = findExternalEdge(theSketch, aInEdge);
448   }
449   if (theShape.ShapeType() == TopAbs_VERTEX) {
450     std::shared_ptr<GeomAPI_Vertex> aInVert = std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex());
451     aInVert->setImpl(new TopoDS_Shape(theShape));
452     aResult = findExternalVertex(theSketch, aInVert);
453   }
454   return aResult;
455 }
456
457 ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShape, 
458                                                      const ObjectPtr& theObject, 
459                                                      CompositeFeaturePtr theSketch,
460                                                      const bool theTemporary)
461 {
462   if (theShape.ShapeType() == TopAbs_EDGE) {
463     Standard_Real aStart, aEnd;
464     Handle(V3d_View) aNullView;
465     FeaturePtr aMyFeature;
466
467     Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(theShape), aStart, aEnd);
468     GeomAdaptor_Curve aAdaptor(aCurve);
469     std::shared_ptr<GeomAPI_Edge> anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge);
470     anEdge->setImpl(new TopoDS_Shape(theShape));
471     if (aAdaptor.GetType() == GeomAbs_Line) {
472       // Create line
473       aMyFeature = theSketch->addFeature(SketchPlugin_Line::ID());
474       if (!theObject.get()) {
475         // There is no selected result
476         std::shared_ptr<GeomAPI_Pnt> aPnt1 = anEdge->firstPoint();
477         std::shared_ptr<GeomAPI_Pnt> aPnt2 = anEdge->lastPoint();
478         std::shared_ptr<GeomAPI_Pnt2d> aPnt2d1 = convertTo2D(theSketch, aPnt1);
479         std::shared_ptr<GeomAPI_Pnt2d> aPnt2d2 = convertTo2D(theSketch, aPnt2);
480
481         std::shared_ptr<ModelAPI_Data> aData = aMyFeature->data();
482         std::shared_ptr<GeomDataAPI_Point2D> aPoint1 = 
483           std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::START_ID()));
484         std::shared_ptr<GeomDataAPI_Point2D> aPoint2 = 
485           std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
486
487         aPoint1->setValue(aPnt2d1);
488         aPoint2->setValue(aPnt2d2);
489
490         // If this is an axis then its name has to be changed correspondently
491         std::string aSuffix = "";
492         bool aXdir = fabs(aPnt1->x() - aPnt2->x()) > Precision::Confusion();
493         bool aYdir = fabs(aPnt1->y() - aPnt2->y()) > Precision::Confusion();
494         bool aZdir = fabs(aPnt1->z() - aPnt2->z()) > Precision::Confusion();
495         if (aXdir && (!aYdir) && (!aZdir))
496           aSuffix = "X";
497         else if ((!aXdir) && aYdir && (!aZdir))
498           aSuffix = "Y";
499         else if ((!aXdir) && (!aYdir) && aZdir)
500           aSuffix = "Z";
501         if (aSuffix.length() > 0)
502           aData->setName("Axis_" + aSuffix);
503         aMyFeature->execute();
504
505       }
506     } else if (aAdaptor.GetType() == GeomAbs_Circle) {
507       if (anEdge->isArc()) {
508         // Create arc
509         aMyFeature = theSketch->addFeature(SketchPlugin_Arc::ID());
510       }
511       else {
512         // Create circle
513         aMyFeature = theSketch->addFeature(SketchPlugin_Circle::ID());
514       }
515     }
516     if (aMyFeature) {
517       DataPtr aData = aMyFeature->data();
518       AttributeSelectionPtr anAttr = 
519         std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
520         (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
521
522       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
523       if (!aRes.get()) {
524         aRes = aMyFeature->firstResult();
525       }
526       if (anAttr.get() && aRes.get()) {
527         std::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
528         anEdge->setImpl(new TopoDS_Shape(theShape));
529
530         anAttr->setValue(aRes, anEdge);
531         //if (!theTemporary) {
532           aMyFeature->execute();
533
534           // fix this edge
535           FeaturePtr aFix = theSketch->addFeature(SketchPlugin_ConstraintRigid::ID());
536           aFix->data()->refattr(SketchPlugin_Constraint::ENTITY_A())->
537             setObject(aMyFeature->lastResult());
538         //}
539         return aMyFeature->lastResult();
540       }
541     }
542   }
543   if (theShape.ShapeType() == TopAbs_VERTEX) {
544     FeaturePtr aMyFeature = theSketch->addFeature(SketchPlugin_Point::ID());
545
546     if (aMyFeature) {
547       DataPtr aData = aMyFeature->data();
548       AttributeSelectionPtr anAttr = 
549         std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
550         (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
551
552       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
553       if (!aRes.get()) {
554         // If the point is selected not from Result object
555         std::shared_ptr<GeomAPI_Shape> aShape = 
556           std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
557         aShape->setImpl(new TopoDS_Shape(theShape));
558
559         std::shared_ptr<GeomAPI_Vertex> aVertex = 
560           std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex(aShape));
561         std::shared_ptr<GeomAPI_Pnt> aPnt = aVertex->point();
562
563         std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = convertTo2D(theSketch, aPnt);
564         std::shared_ptr<GeomDataAPI_Point2D> aPoint = 
565           std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Point::COORD_ID()));
566         aPoint->setValue(aPnt2d);
567         if ((aPnt->x() < Precision::Confusion()) && 
568             (aPnt->y() < Precision::Confusion()) &&
569             (aPnt->z() < Precision::Confusion()))
570           aData->setName("Origin");
571
572         aMyFeature->execute();
573         aRes = aMyFeature->firstResult();
574       }
575       if (anAttr.get() && aRes.get()) {
576         std::shared_ptr<GeomAPI_Shape> aVert(new GeomAPI_Shape);
577         aVert->setImpl(new TopoDS_Shape(theShape));
578
579         anAttr->setValue(aRes, aVert);
580         //if (theTemporary) {
581           aMyFeature->execute();
582
583           // fix this edge
584           FeaturePtr aFix = theSketch->addFeature(SketchPlugin_ConstraintRigid::ID());
585           aFix->data()->refattr(SketchPlugin_Constraint::ENTITY_A())->
586             setObject(aMyFeature->lastResult());
587         //}
588         return aMyFeature->lastResult();
589       }
590     }
591   }
592   return ResultPtr();
593 }
594
595 bool PartSet_Tools::isContainPresentation(const QList<ModuleBase_ViewerPrsPtr>& theSelected,
596                                           const ModuleBase_ViewerPrsPtr& thePrs)
597 {
598   foreach (ModuleBase_ViewerPrsPtr aPrs, theSelected) {
599     if (aPrs->object() == thePrs->object())
600       return true;
601   }
602   return false;
603 }
604
605 ResultPtr PartSet_Tools::findExternalEdge(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Edge> theEdge)
606 {
607   for (int i = 0; i < theSketch->numberOfSubs(); i++) {
608     FeaturePtr aFeature = theSketch->subFeature(i);
609     std::shared_ptr<SketchPlugin_Feature> aSketchFea = 
610       std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
611     if (aSketchFea) {
612       if (aSketchFea->isExternal()) {
613         std::list<ResultPtr> aResults = aSketchFea->results();
614         std::list<ResultPtr>::const_iterator aIt;
615         for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
616           ResultConstructionPtr aRes = 
617             std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aIt);
618           if (aRes) {
619             std::shared_ptr<GeomAPI_Shape> aShape = aRes->shape();
620             if (aShape) {
621               if (theEdge->isEqual(aShape))
622                 return aRes;
623             }
624           }
625         }
626       }
627     }
628   }
629   return ResultPtr();
630 }
631
632
633 ResultPtr PartSet_Tools::findExternalVertex(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Vertex> theVert)
634 {
635   for (int i = 0; i < theSketch->numberOfSubs(); i++) {
636     FeaturePtr aFeature = theSketch->subFeature(i);
637     std::shared_ptr<SketchPlugin_Feature> aSketchFea = 
638       std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
639     if (aSketchFea) {
640       if (aSketchFea->isExternal()) {
641         std::list<ResultPtr> aResults = aSketchFea->results();
642         std::list<ResultPtr>::const_iterator aIt;
643         for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
644           ResultConstructionPtr aRes = 
645             std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aIt);
646           if (aRes) {
647             std::shared_ptr<GeomAPI_Shape> aShape = aRes->shape();
648             if (aShape) {
649               if (theVert->isEqual(aShape))
650                 return aRes;
651             }
652           }
653         }
654       }
655     }
656   }
657   return ResultPtr();
658 }
659
660
661 bool PartSet_Tools::hasVertexShape(const ModuleBase_ViewerPrsPtr& thePrs, FeaturePtr theSketch,
662                                    Handle_V3d_View theView, double& theX, double& theY)
663 {
664   bool aHasVertex = false;
665
666   const GeomShapePtr& aShape = thePrs->shape();
667   if (aShape.get() && !aShape->isNull() && aShape->shapeType() == GeomAPI_Shape::VERTEX)
668   {
669     const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
670     const TopoDS_Vertex& aVertex = TopoDS::Vertex(aTDShape);
671     if (!aVertex.IsNull())
672     {
673       gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
674       PartSet_Tools::convertTo2D(aPoint, theSketch, theView, theX, theY);
675       aHasVertex = true;
676     }
677   }
678
679   return aHasVertex;
680 }
681
682 GeomShapePtr PartSet_Tools::findShapeBy2DPoint(const AttributePtr& theAttribute,
683                                                        ModuleBase_IWorkshop* theWorkshop)
684 {
685   GeomShapePtr aShape;
686   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
687   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
688
689   // 2. find visualized vertices of the attribute and if the attribute of the vertex is
690   // the same, return it
691   FeaturePtr anAttributeFeature = ModelAPI_Feature::feature(theAttribute->owner());
692   // 2.1 get visualized results of the feature
693   const std::list<ResultPtr>& aResList = anAttributeFeature->results();
694   std::list<ResultPtr>::const_iterator anIt = aResList.begin(), aLast = aResList.end();
695   for (; anIt != aLast; anIt++) {
696     AISObjectPtr aAISObj = aDisplayer->getAISObject(*anIt);
697     if (aAISObj.get() != NULL) {
698       Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
699       // 2.2 find selected owners of a visualizedd object
700       SelectMgr_IndexedMapOfOwner aSelectedOwners;
701       aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
702       for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
703         Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
704         if (!anOwner.IsNull()) {
705           Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
706           if (!aBRepOwner.IsNull() && aBRepOwner->HasShape()) {
707             const TopoDS_Shape& aBRepShape = aBRepOwner->Shape();
708             if (aBRepShape.ShapeType() == TopAbs_VERTEX) {
709               // 2.3 if the owner is vertex and an attribute of the vertex is equal to the initial
710               // attribute, returns the shape
711               PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(theWorkshop->module());
712               PartSet_SketcherMgr* aSketchMgr = aModule->sketchMgr();
713               AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(anAttributeFeature,
714                                                         aBRepShape, aSketchMgr->activeSketch());
715               if (aPntAttr.get() != NULL && aPntAttr == theAttribute) {
716                 aShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape);
717                 aShape->setImpl(new TopoDS_Shape(aBRepShape));
718                 break;
719               }
720             }
721           }
722         }
723       }
724     }
725   }
726   return aShape;
727 }
728
729 std::shared_ptr<GeomAPI_Pnt2d> PartSet_Tools::getPoint(std::shared_ptr<ModelAPI_Feature>& theFeature,
730                                                        const std::string& theAttribute)
731 {
732   std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
733
734   if (!theFeature->data())
735     return std::shared_ptr<GeomAPI_Pnt2d>();
736
737   FeaturePtr aFeature;
738   std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
739       ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(theAttribute));
740   if (!anAttr)
741     return std::shared_ptr<GeomAPI_Pnt2d>();
742
743   aFeature = ModelAPI_Feature::feature(anAttr->object());
744
745   if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID())
746     aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
747         aFeature->data()->attribute(SketchPlugin_Point::COORD_ID()));
748
749   else if (anAttr->attr()) {
750     aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
751   }
752   if (aPointAttr.get() != NULL)
753     return aPointAttr->pnt();
754   return std::shared_ptr<GeomAPI_Pnt2d>();
755 }
756
757 FeaturePtr findFirstCoincidenceByData(const DataPtr& theData, std::shared_ptr<GeomAPI_Pnt2d> thePoint)
758 {
759   FeaturePtr aCoincident;
760
761   const std::set<AttributePtr>& aRefsList = theData->refsToMe();
762   std::set<AttributePtr>::const_iterator aIt;
763   for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
764     std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
765     FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
766     if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { 
767       std::shared_ptr<GeomAPI_Pnt2d> a2dPnt = 
768         PartSet_Tools::getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A());
769       if (a2dPnt.get() && thePoint->isEqual(a2dPnt)) { 
770         aCoincident = aConstrFeature;
771         break;
772       } else {
773         a2dPnt = PartSet_Tools::getPoint(aConstrFeature,
774                                           SketchPlugin_ConstraintCoincidence::ENTITY_B());
775         if (a2dPnt.get() && thePoint->isEqual(a2dPnt)) { 
776           aCoincident = aConstrFeature;
777           break;
778         }
779       }
780     }
781   }
782   return aCoincident;
783 }
784
785 FeaturePtr PartSet_Tools::findFirstCoincidence(const FeaturePtr& theFeature,
786                                                std::shared_ptr<GeomAPI_Pnt2d> thePoint)
787 {
788   FeaturePtr aCoincident;
789   if (theFeature.get() == NULL)
790     return aCoincident;
791
792   const std::set<AttributePtr>& aRefsList = theFeature->data()->refsToMe();
793   std::set<AttributePtr>::const_iterator aIt;
794   for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
795     std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
796     FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
797     if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { 
798       std::shared_ptr<GeomAPI_Pnt2d> a2dPnt = 
799         PartSet_Tools::getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A());
800       if (a2dPnt.get() && thePoint->isEqual(a2dPnt)) { 
801         aCoincident = aConstrFeature;
802         break;
803       } else {
804         a2dPnt = PartSet_Tools::getPoint(aConstrFeature,
805                                           SketchPlugin_ConstraintCoincidence::ENTITY_B());
806         if (a2dPnt.get() && thePoint->isEqual(a2dPnt)) { 
807           aCoincident = aConstrFeature;
808           break;
809         }
810       }
811     }
812   }
813   /// Find by result
814   if (!aCoincident.get()) {
815     std::list<ResultPtr> aResults = theFeature->results();
816     std::list<ResultPtr>::const_iterator aIt;
817     for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
818       ResultPtr aResult = *aIt;
819       aCoincident = findFirstCoincidenceByData(aResult->data(), thePoint);
820       if (aCoincident.get())
821         break;
822     }
823   }
824   return aCoincident;
825 }
826
827 void PartSet_Tools::findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>& theList,
828                                      QList<FeaturePtr>& theCoincidencies,
829                                      std::string theAttr)
830 {
831   std::shared_ptr<GeomAPI_Pnt2d> aOrig = getCoincedencePoint(theStartCoin);
832   if (aOrig.get() == NULL)
833     return;
834
835   AttributeRefAttrPtr aPnt = theStartCoin->refattr(theAttr);
836   if (!aPnt) 
837     return;
838   ObjectPtr aObj = aPnt->object();
839   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
840   if (aFeature.get()) {
841     if (!theList.contains(aFeature)) {
842       theList.append(aFeature);
843       theCoincidencies.append(theStartCoin);
844       const std::set<AttributePtr>& aRefsList = aFeature->data()->refsToMe();
845       std::set<AttributePtr>::const_iterator aIt;
846       for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
847         std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
848         FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
849         if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { 
850           if (!theCoincidencies.contains(aConstrFeature)) {
851             std::shared_ptr<GeomAPI_Pnt2d> aPnt = getCoincedencePoint(aConstrFeature);
852             if (aPnt.get() && aOrig->isEqual(aPnt)) {
853               findCoincidences(aConstrFeature, theList, theCoincidencies, 
854                 SketchPlugin_ConstraintCoincidence::ENTITY_A());
855               findCoincidences(aConstrFeature, theList, theCoincidencies, 
856                 SketchPlugin_ConstraintCoincidence::ENTITY_B());
857             }
858           }
859         }
860       }
861     }
862   } else {
863     // Find by Results
864     ResultConstructionPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObj);
865     if (aResult.get()) {
866       FeaturePtr aFeature = ModelAPI_Feature::feature(aPnt->object());
867       if (!theList.contains(aFeature)) 
868         theList.append(aFeature);
869       theCoincidencies.append(theStartCoin);
870
871       const std::set<AttributePtr>& aRefsList = aResult->data()->refsToMe();
872       std::set<AttributePtr>::const_iterator aIt;
873       for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
874         std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
875         FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
876         if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { 
877           if (!theCoincidencies.contains(aConstrFeature)) {
878             std::shared_ptr<GeomAPI_Pnt2d> aPnt = getCoincedencePoint(aConstrFeature);
879             if (aPnt.get() && aOrig->isEqual(aPnt)) {
880               findCoincidences(aConstrFeature, theList, theCoincidencies, 
881                 SketchPlugin_ConstraintCoincidence::ENTITY_A());
882               findCoincidences(aConstrFeature, theList, theCoincidencies, 
883                 SketchPlugin_ConstraintCoincidence::ENTITY_B());
884             }
885           }
886         }
887       }
888     }
889   }
890 }
891
892 std::shared_ptr<GeomAPI_Pnt2d> PartSet_Tools::getCoincedencePoint(FeaturePtr theStartCoin)
893 {
894   std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(theStartCoin.get(), 
895                                                                     SketchPlugin_Constraint::ENTITY_A());
896   if (aPnt.get() == NULL)
897     aPnt = SketcherPrs_Tools::getPoint(theStartCoin.get(), SketchPlugin_Constraint::ENTITY_B());
898   return aPnt;
899 }
900
901 AttributePtr PartSet_Tools::findAttributeBy2dPoint(ObjectPtr theObj, 
902                                                    const TopoDS_Shape theShape, 
903                                                    FeaturePtr theSketch)
904 {
905
906   AttributePtr anAttribute;
907   FeaturePtr aFeature = ModelAPI_Feature::feature(theObj);
908   if (aFeature) {
909     if (theShape.ShapeType() == TopAbs_VERTEX) {
910       const TopoDS_Vertex& aVertex = TopoDS::Vertex(theShape);
911       if (!aVertex.IsNull())  {
912         gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
913         std::shared_ptr<GeomAPI_Pnt> aValue = std::shared_ptr<GeomAPI_Pnt>(
914             new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
915
916         // find the given point in the feature attributes
917         std::list<AttributePtr> anAttiributes = 
918           aFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
919         std::list<AttributePtr>::const_iterator anIt = anAttiributes.begin(), 
920                                                 aLast = anAttiributes.end();
921         for (; anIt != aLast && !anAttribute; anIt++) {
922           std::shared_ptr<GeomDataAPI_Point2D> aCurPoint = 
923             std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
924
925           std::shared_ptr<GeomAPI_Pnt> aPnt = convertTo3D(aCurPoint->x(), aCurPoint->y(), theSketch);
926           if (aPnt && (aPnt->distance(aValue) < Precision::Confusion())) {
927             anAttribute = aCurPoint;
928             break;
929           }
930         }
931       }
932     }
933   }
934   return anAttribute;
935 }
936
937 void PartSet_Tools::sendSubFeaturesEvent(const CompositeFeaturePtr& theComposite,
938                                          const Events_ID theEventId)
939 {
940   if (!theComposite.get())
941     return;
942
943   static Events_Loop* aLoop = Events_Loop::loop();
944   for (int i = 0; i < theComposite->numberOfSubs(); i++) {
945     FeaturePtr aSubFeature = theComposite->subFeature(i);
946     static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
947     aECreator->sendUpdated(aSubFeature, theEventId);
948   }
949   Events_Loop::loop()->flush(theEventId);
950 }
951
952 bool PartSet_Tools::isAuxiliarySketchEntity(const ObjectPtr& theObject)
953 {
954   bool isAuxiliaryFeature = false;
955
956   FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
957   std::string anAuxiliaryAttribute = SketchPlugin_SketchEntity::AUXILIARY_ID();
958   AttributeBooleanPtr anAuxiliaryAttr = std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(
959                                     anObjectFeature->data()->attribute(anAuxiliaryAttribute));
960   if (anAuxiliaryAttr.get())
961     isAuxiliaryFeature = anAuxiliaryAttr->value();
962
963
964   return isAuxiliaryFeature;
965 }