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