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