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