]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/SketchPlugin_Validators.cpp
Salome HOME
Fix for the issue #1818: checking angle for fillet on Linux.
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Validators.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        SketchPlugin_Validators.cpp
4 // Created:     01 Aug 2014
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "SketchPlugin_Validators.h"
8
9 #include "SketchPlugin_Arc.h"
10 #include "SketchPlugin_Circle.h"
11 #include "SketchPlugin_ConstraintCoincidence.h"
12 #include "SketchPlugin_ConstraintDistance.h"
13 #include "SketchPlugin_ConstraintFillet.h"
14 #include "SketchPlugin_ConstraintRigid.h"
15 #include "SketchPlugin_ConstraintTangent.h"
16 #include "SketchPlugin_Line.h"
17 #include "SketchPlugin_Point.h"
18 #include "SketchPlugin_Sketch.h"
19 #include "SketchPlugin_Tools.h"
20
21 #include "SketcherPrs_Tools.h"
22
23 #include <Events_InfoMessage.h>
24
25 #include <ModelAPI_Data.h>
26 #include <ModelAPI_Validator.h>
27 #include <ModelAPI_AttributeDouble.h>
28 #include <ModelAPI_AttributeRefAttr.h>
29
30 #include <ModelAPI_AttributeRefAttrList.h>
31 #include <ModelAPI_AttributeRefList.h>
32 #include <ModelAPI_AttributeSelectionList.h>
33 #include <ModelAPI_AttributeString.h>
34 #include <ModelAPI_Session.h>
35 #include <ModelAPI_Tools.h>
36 #include <ModelAPI_ResultConstruction.h>
37
38 #include <ModelGeomAlgo_Point2D.h>
39
40 #include <GeomAPI_Circ.h>
41 #include <GeomAPI_Lin.h>
42 #include <GeomAPI_Edge.h>
43 #include <GeomAPI_Vertex.h>
44 #include <GeomDataAPI_Point2D.h>
45
46 #include <algorithm>
47 #include <cmath>
48
49 const double tolerance = 1.e-7;
50
51 bool SketchPlugin_DistanceAttrValidator::isValid(const AttributePtr& theAttribute, 
52                                                  const std::list<std::string>& theArguments,
53                                                  Events_InfoMessage& theError) const
54 {
55   if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
56     theError = "The attribute with the %1 type is not processed";
57     theError.arg(theAttribute->attributeType());
58     return false;
59   }
60
61   // there is a check whether the feature contains a point and a linear edge or two point values
62   std::string aParamA = theArguments.front();
63   SessionPtr aMgr = ModelAPI_Session::get();
64   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
65
66   AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
67   bool isObject = aRefAttr->isObject();
68   if (!isObject) {
69     // an attribute is a point. A point value is valid always for the distance
70     return true;
71   } else {
72     // 1. check whether the references object is a linear
73     ObjectPtr anObject = aRefAttr->object();
74
75     const ModelAPI_AttributeValidator* aShapeValidator = 
76       dynamic_cast<const ModelAPI_AttributeValidator*>(aFactory->validator("GeomValidators_ShapeType"));
77     std::list<std::string> anArguments;
78     anArguments.push_back("circle");
79     Events_InfoMessage aCircleError;
80     bool aShapeValid = aShapeValidator->isValid(aRefAttr, anArguments, aCircleError);
81     // the circle line is not a valid case
82     if (aShapeValid) {
83       theError = "Circle can not be used in distance constraint";
84       return false;
85     }
86       
87     anArguments.clear();
88     anArguments.push_back("line");
89     Events_InfoMessage aLineError;
90     aShapeValid = aShapeValidator->isValid(aRefAttr, anArguments, aLineError);
91     // if the attribute value is not a line, that means it is a vertex. A vertex is always valid
92     if (aShapeValid) {
93       FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
94       // If it is a line then we have to check that first attribute id not a line
95       std::shared_ptr<SketchPlugin_Feature> aSFeature =
96         std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
97       SketchPlugin_Sketch* aSketch = aSFeature->sketch();
98       std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(aSketch);
99       std::shared_ptr<GeomDataAPI_Point2D> aPoint = SketcherPrs_Tools::getFeaturePoint(
100         aFeature->data(), aParamA, aPlane);
101       if (!aPoint.get()) {
102         theError = "One of parameters of distance constraint should be a point";
103         return false;
104       }
105     }
106   }
107   return true;
108 }
109
110 static bool isCoincident(FeaturePtr theFeature1, FeaturePtr theFeature2)
111 {
112   AttributePtr aFeature1PointAttr[2];
113   if(theFeature1->getKind() == SketchPlugin_Line::ID()) {
114     aFeature1PointAttr[0] = theFeature1->attribute(SketchPlugin_Line::START_ID());
115     aFeature1PointAttr[1] = theFeature1->attribute(SketchPlugin_Line::END_ID());
116   } else if(theFeature1->getKind() == SketchPlugin_Arc::ID()) {
117     aFeature1PointAttr[0] = theFeature1->attribute(SketchPlugin_Arc::START_ID());
118     aFeature1PointAttr[1] = theFeature1->attribute(SketchPlugin_Arc::END_ID());
119   }
120
121   std::set<AttributePtr> aRefsList = theFeature1->data()->refsToMe();
122   for(std::set<AttributePtr>::const_iterator aRefIt = aRefsList.begin();
123       aRefIt != aRefsList.end();
124       ++aRefIt) {
125     // Find constraint 
126     FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRefIt)->owner());
127     if(aRefFeature->getKind() != SketchPlugin_ConstraintCoincidence::ID())
128       continue;
129     AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*aRefIt);
130     AttributePtr anAttr = aRefAttr->attr();
131     if(anAttr != aFeature1PointAttr[0] && anAttr != aFeature1PointAttr[1])
132       continue;
133
134     // Get coincides from constraint.
135     std::set<FeaturePtr> aCoinsides;
136     SketchPlugin_Tools::findCoincidences(aRefFeature,
137                                          SketchPlugin_ConstraintCoincidence::ENTITY_A(),
138                                          aCoinsides);
139     SketchPlugin_Tools::findCoincidences(aRefFeature,
140                                          SketchPlugin_ConstraintCoincidence::ENTITY_B(),
141                                          aCoinsides);
142
143     if(aCoinsides.find(theFeature2) != aCoinsides.end()) {
144       return true;
145     }
146   }
147
148   return false;
149 }
150
151 static bool hasCoincidentPoint(FeaturePtr theFeature1, FeaturePtr theFeature2)
152 {
153   if(theFeature1->getKind() == SketchPlugin_Circle::ID() ||
154       theFeature2->getKind() == SketchPlugin_Circle::ID()) {
155     return false;
156   }
157
158   return (isCoincident(theFeature1, theFeature2) && isCoincident(theFeature2, theFeature1));
159 }
160
161 bool SketchPlugin_TangentAttrValidator::isValid(const AttributePtr& theAttribute, 
162                                                 const std::list<std::string>& theArguments,
163                                                 Events_InfoMessage& theError) const
164 {
165   if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
166     theError = "The attribute with the %1 type is not processed";
167     theError.arg(theAttribute->attributeType());
168     return false;
169   }
170
171   // there is a check whether the feature contains a point and a linear edge or two point values
172   std::string aParamA = theArguments.front();
173   SessionPtr aMgr = ModelAPI_Session::get();
174   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
175
176   FeaturePtr anAttributeFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
177   AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
178
179   bool isObject = aRefAttr->isObject();
180   ObjectPtr anObject = aRefAttr->object();
181   if (isObject && anObject.get()) {
182     FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject);
183
184     AttributeRefAttrPtr aOtherAttr = anAttributeFeature->data()->refattr(aParamA);
185     ObjectPtr aOtherObject = aOtherAttr->object();
186     FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject);
187     if (!aOtherFea)
188       return true;
189
190     if ((aRefFea->getKind() == SketchPlugin_Arc::ID() ||
191         aOtherFea->getKind() == SketchPlugin_Arc::ID()) &&
192         !hasCoincidentPoint(aRefFea, aOtherFea))
193       return false;
194
195     if (aRefFea->getKind() == SketchPlugin_Line::ID()) {
196       if (aOtherFea->getKind() != SketchPlugin_Arc::ID() &&
197           aOtherFea->getKind() != SketchPlugin_Circle::ID()) {
198         theError = "It refers to a %1, but %2 is neither an %3 nor %4";
199         theError.arg(SketchPlugin_Line::ID()).arg(aParamA)
200             .arg(SketchPlugin_Arc::ID()).arg(SketchPlugin_Circle::ID());
201         return false;
202       }
203     }
204     else if (aRefFea->getKind() == SketchPlugin_Arc::ID()) {
205       if (aOtherFea->getKind() != SketchPlugin_Line::ID() &&
206         aOtherFea->getKind() != SketchPlugin_Arc::ID()) {
207         theError = "It refers to an %1, but %2 is not a %3 or an %4";
208         theError.arg(SketchPlugin_Arc::ID()).arg(aParamA)
209             .arg(SketchPlugin_Line::ID()).arg(SketchPlugin_Arc::ID());
210         return false;
211       }
212     }
213     else if (aRefFea->getKind() == SketchPlugin_Circle::ID()) {
214       if (aOtherFea->getKind() != SketchPlugin_Line::ID()) {
215         theError = "It refers to an %1, but %2 is not a %3";
216         theError.arg(SketchPlugin_Circle::ID()).arg(aParamA)
217             .arg(SketchPlugin_Line::ID());
218         return false;
219       }
220     }
221     else {
222       theError = "It refers to %1, but should refer to %2 or %3 or %4";
223       theError.arg(aRefFea->getKind()).arg(SketchPlugin_Line::ID())
224           .arg(SketchPlugin_Arc::ID()).arg(SketchPlugin_Circle::ID());
225       return false;
226     }
227     return true;
228   }
229   else {
230     theError = "It uses an empty object";
231     return false;
232   }
233
234   return true;
235 }
236
237 bool SketchPlugin_NotFixedValidator::isValid(const AttributePtr& theAttribute,
238                                              const std::list<std::string>& theArguments,
239                                              Events_InfoMessage& theError) const
240 {
241   if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
242     theError = "The attribute with the %1 type is not processed";
243     theError.arg(theAttribute->attributeType());
244     return false;
245   }
246
247   std::shared_ptr<SketchPlugin_Feature> aFeature =
248       std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
249   if (!aFeature)
250     return true;
251
252   AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
253
254   SketchPlugin_Sketch* aSketch = aFeature->sketch();
255   int aNbFeatures = aSketch->numberOfSubs();
256   for (int anInd = 0; anInd < aNbFeatures; anInd++) {
257     FeaturePtr aSubFeature = aSketch->subFeature(anInd);
258     if (aSubFeature->getKind() != SketchPlugin_ConstraintRigid::ID() || aSubFeature == aFeature)
259       continue;
260     AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
261         aSubFeature->attribute(SketchPlugin_ConstraintRigid::ENTITY_A()));
262     if (aRefAttr->isObject()) {
263       if (aRefAttr->object() == aRAttr->object()) {
264         ObjectPtr anObject = aRefAttr->object();
265         std::string aName = anObject.get() ? anObject->data()->name() : "";
266         theError = "The object %1 has been already fixed.";
267         theError.arg(aName);
268         return false;
269       }
270     }
271     else if (aRefAttr->attr() == aRAttr->attr()) {
272       AttributePtr anAttribute = aRefAttr->attr();
273       std::string aName = anAttribute.get() ? anAttribute->id() : "";
274       theError = "The attribute %1 has been already fixed.";
275       theError.arg(aName);
276       return false;
277     }
278   }
279   return true;
280 }
281
282 bool SketchPlugin_EqualAttrValidator::isValid(const AttributePtr& theAttribute, 
283                                               const std::list<std::string>& theArguments,
284                                               Events_InfoMessage& theError) const
285 {
286   if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
287     theError = "The attribute with the %1 type is not processed";
288     theError.arg(theAttribute->attributeType());
289     return false;
290   }
291
292   std::string aParamA = theArguments.front();
293   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
294   AttributeRefAttrPtr aRefAttr[2];
295   aRefAttr[0] = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
296   aRefAttr[1] = aFeature->data()->refattr(aParamA);
297
298   if (!aRefAttr[0]->isObject() || !aRefAttr[1]->isObject()) {
299     theError = "Attributes can not be used in equal constraint";
300     return false;
301   }
302
303   std::string aType[2];
304   std::list<std::string> anArguments;
305   for (int i = 0; i < 2; i++) {
306     ObjectPtr anObject = aRefAttr[i]->object();
307     if (!anObject.get()) {
308       theError = "An empty object is used.";
309       return false;
310     }
311
312     aFeature = ModelAPI_Feature::feature(anObject);
313     if (!aFeature.get()) {
314       theError = "An empty feature is used.";
315       return false;
316     }
317
318     aType[i] = aFeature->getKind();
319     if (aFeature->getKind() != SketchPlugin_Line::ID() &&
320         aFeature->getKind() != SketchPlugin_Circle::ID() &&
321         aFeature->getKind() != SketchPlugin_Arc::ID()) {
322       theError = "The %1 feature kind of attribute is wrong. It should be %2 or %3 or %4";
323       theError.arg(aFeature->getKind()).arg(SketchPlugin_Line::ID())
324           .arg(SketchPlugin_Circle::ID()).arg(SketchPlugin_Arc::ID());
325       // wrong type of attribute
326       return false;
327     }
328   }
329
330   if ((aType[0] == SketchPlugin_Line::ID() || aType[1] == SketchPlugin_Line::ID()) &&
331       aType[0] != aType[1]) {
332     theError = "Feature with kinds %1 and %2 can not be equal.";
333     theError.arg(aType[0]).arg(aType[1]);
334     return false;
335   }
336   return true;
337 }
338
339 bool SketchPlugin_MirrorAttrValidator::isValid(const AttributePtr& theAttribute, 
340                                                const std::list<std::string>& theArguments,
341                                                Events_InfoMessage& theError) const
342 {
343   if (theAttribute->attributeType() != ModelAPI_AttributeRefList::typeId()) {
344     theError = "The attribute with the %1 type is not processed";
345     theError.arg(theAttribute->attributeType());
346     return false;
347   }
348
349   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
350   AttributeRefListPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
351
352   AttributeRefListPtr aRefListOfMirrored = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
353       aFeature->attribute(SketchPlugin_Constraint::ENTITY_C()));
354   std::list<ObjectPtr> aMirroredObjects = aRefListOfMirrored->list();
355
356   for(int anInd = 0; anInd < aSelAttr->size(); anInd++) {
357     ObjectPtr aSelObject = aSelAttr->object(anInd);
358     std::string aName = aSelObject.get() ? aSelObject->data()->name() : "";
359     std::list<ObjectPtr>::iterator aMirIter = aMirroredObjects.begin();
360     for (; aMirIter != aMirroredObjects.end(); aMirIter++)
361       if (aSelObject == *aMirIter) {
362         theError = "The object %1 is a result of mirror";
363         theError.arg(aName);
364         return false;
365       }
366   }
367   return true;
368 }
369
370 bool SketchPlugin_CoincidenceAttrValidator::isValid(const AttributePtr& theAttribute, 
371                                                     const std::list<std::string>& theArguments,
372                                                     Events_InfoMessage& theError) const
373 {
374   if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
375     theError = "The attribute with the %1 type is not processed";
376     theError.arg(theAttribute->attributeType());
377     return false;
378   }
379
380   // there is a check whether the feature contains a point and a linear edge or two point values
381   std::string aParamA = theArguments.front();
382   SessionPtr aMgr = ModelAPI_Session::get();
383   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
384
385   FeaturePtr aConstraint = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
386   AttributeRefAttrPtr aRefAttrA = aConstraint->data()->refattr(aParamA);
387   if (!aRefAttrA) {
388     theError = "The %1 attribute should be %2";
389     theError.arg(aParamA).arg(ModelAPI_AttributeRefAttr::typeId());
390     return false;
391   }
392
393   AttributeRefAttrPtr aRefAttrB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
394
395   // first attribute is a point, it may coincide with any object
396   if (!aRefAttrA->isObject())
397     return true;
398   else {
399     ObjectPtr anObject = aRefAttrA->object();
400     if (!anObject.get()) {
401       theError = "%1 attribute has an empty object";
402       theError.arg(aParamA);
403       return false;
404     }
405     FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrA->object());
406     if (!aFeature.get()) {
407       theError = "%1 attribute has an empty feature";
408       theError.arg(aParamA);
409       return false;
410     }
411
412     if (aFeature->getKind() == SketchPlugin_Point::ID())
413       return true;
414   }
415
416   // second attribute is a point, it may coincide with any object
417   if (!aRefAttrB->isObject())
418     return true;
419   else {
420     FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrB->object());
421     if (!aFeature) {
422       theError = "%1 attribute has an empty object";
423       theError.arg(theAttribute->id());
424       return false;
425     }
426     if (aFeature->getKind() == SketchPlugin_Point::ID())
427       return true;
428   }
429   theError = "There is no an attribute filled by a point";
430   return false;
431 }
432
433
434 bool SketchPlugin_CopyValidator::isValid(const AttributePtr& theAttribute, 
435                                          const std::list<std::string>& theArguments,
436                                          Events_InfoMessage& theError) const
437 {
438   if (theAttribute->attributeType() != ModelAPI_AttributeRefList::typeId()) {
439     theError = "The attribute with the %1 type is not processed";
440     theError.arg(theAttribute->attributeType());
441     return false;
442   }
443
444   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
445   AttributeRefListPtr aSelAttr = 
446     std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
447
448   AttributeRefListPtr aRefListOfInitial = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
449       aFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
450   AttributeRefListPtr aRefListOfCopied = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
451       aFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
452   std::list<ObjectPtr> anInitialObjects = aRefListOfInitial->list();
453   std::list<ObjectPtr> aCopiedObjects = aRefListOfCopied->list();
454
455   std::list<ObjectPtr>::iterator anObjIter;
456   for(int anInd = 0; anInd < aSelAttr->size(); anInd++) {
457     ObjectPtr aSelObject = aSelAttr->object(anInd);
458     anObjIter = anInitialObjects.begin();
459     for (; anObjIter != anInitialObjects.end(); anObjIter++)
460       if (aSelObject == *anObjIter)
461         break;
462     if (anObjIter != anInitialObjects.end())
463       continue;
464     anObjIter = aCopiedObjects.begin();
465     for (; anObjIter != aCopiedObjects.end(); anObjIter++)
466       if (aSelObject == *anObjIter) {
467         std::string aName = aSelObject.get() ? aSelObject->data()->name() : "";
468         theError = "The object %1 is a result of copy";
469         theError.arg(aName);
470         return false;
471       }
472   }
473   return true;
474 }
475
476 bool SketchPlugin_SolverErrorValidator::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
477                                                 const std::list<std::string>& theArguments,
478                                                 Events_InfoMessage& theError) const
479 {
480   AttributeStringPtr aAttributeString = theFeature->string(SketchPlugin_Sketch::SOLVER_ERROR());
481
482   if (!aAttributeString->value().empty()) {
483     theError = aAttributeString->value();
484     return false;
485   }
486
487   return true;
488 }
489
490 bool SketchPlugin_SolverErrorValidator::isNotObligatory(std::string theFeature, std::string theAttribute)
491 {
492   return true;
493 }
494
495 static bool hasSameTangentFeature(const std::set<AttributePtr>& theRefsList, const FeaturePtr theFeature)
496 {
497   for(std::set<AttributePtr>::const_iterator anIt = theRefsList.cbegin(); anIt != theRefsList.cend(); ++anIt) {
498     std::shared_ptr<ModelAPI_Attribute> aAttr = (*anIt);
499     FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
500     if (aFeature->getKind() == SketchPlugin_ConstraintTangent::ID()) {
501       AttributeRefAttrPtr anAttrRefA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
502         aFeature->attribute(SketchPlugin_ConstraintTangent::ENTITY_A()));
503       AttributeRefAttrPtr anAttrRefB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
504         aFeature->attribute(SketchPlugin_ConstraintTangent::ENTITY_B()));
505       if(anAttrRefA.get()) {
506         ResultPtr aResA = std::dynamic_pointer_cast<ModelAPI_Result>(anAttrRefA->object());
507         if(aResA.get()) {
508           DocumentPtr aDoc = aResA->document();
509           if(aDoc.get()) {
510             FeaturePtr aFeatureA = aDoc->feature(aResA);
511             if(aFeatureA.get() && aFeatureA == theFeature) {
512               return true;
513             }
514           }
515         }
516       }
517       if(anAttrRefB.get()) {
518         ResultPtr aResB = std::dynamic_pointer_cast<ModelAPI_Result>(anAttrRefB->object());
519         if(aResB.get()) {
520           DocumentPtr aDoc = aResB->document();
521           if(aDoc.get()) {
522             FeaturePtr aFeatureB = aDoc->feature(aResB);
523             if(aFeatureB.get() && aFeatureB == theFeature) {
524               return true;
525             }
526           }
527         }
528       }
529     }
530   }
531   return false;
532 }
533
534 bool SketchPlugin_FilletVertexValidator::isValid(const AttributePtr& theAttribute,
535                                                  const std::list<std::string>& theArguments,
536                                                  Events_InfoMessage& theError) const
537 {
538   std::shared_ptr<SketchPlugin_ConstraintFillet> aFilletFeature = std::dynamic_pointer_cast<SketchPlugin_ConstraintFillet>(theAttribute->owner());
539   AttributeRefAttrListPtr aPointsRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
540   if(aPointsRefList->size() == 0) {
541     theError = "Error: List of points is empty.";
542     return false;
543   }
544
545   std::map<AttributePtr, SketchPlugin_ConstraintFillet::FilletFeatures> aPointsFeaturesMap = aFilletFeature->pointsFeaturesMap();
546   std::set<AttributePtr> aSetOfPointsOnResultEdges;
547   for(std::map<AttributePtr, SketchPlugin_ConstraintFillet::FilletFeatures>::iterator aPointsIter = aPointsFeaturesMap.begin();
548       aPointsIter != aPointsFeaturesMap.end();
549       ++aPointsIter) {
550     const SketchPlugin_ConstraintFillet::FilletFeatures& aFeatures = aPointsIter->second;
551     const std::list<FeaturePtr>& aResultEdges = aFeatures.resultEdges;
552     for(std::list<FeaturePtr>::const_iterator aResultIter = aResultEdges.cbegin();
553         aResultIter != aResultEdges.cend();
554         ++aResultIter) {
555       FeaturePtr aResultFeature = *aResultIter;
556       if(aResultFeature->getKind() == SketchPlugin_Line::ID()) {
557         aSetOfPointsOnResultEdges.insert(aResultFeature->attribute(SketchPlugin_Line::START_ID()));
558         aSetOfPointsOnResultEdges.insert(aResultFeature->attribute(SketchPlugin_Line::END_ID()));
559       } else if(aResultFeature->getKind() == SketchPlugin_Arc::ID()) {
560         aSetOfPointsOnResultEdges.insert(aResultFeature->attribute(SketchPlugin_Arc::START_ID()));
561         aSetOfPointsOnResultEdges.insert(aResultFeature->attribute(SketchPlugin_Arc::END_ID()));
562       }
563     }
564   }
565
566   std::list<std::pair<ObjectPtr, AttributePtr>> aPointsList = aPointsRefList->list();
567   for(std::list<std::pair<ObjectPtr, AttributePtr>>::const_iterator aPointsIt = aPointsList.cbegin(); aPointsIt != aPointsList.cend(); aPointsIt++) {
568     ObjectPtr anObject = (*aPointsIt).first;
569     AttributePtr aPointAttribute = (*aPointsIt).second;
570     if (!aPointAttribute.get())
571         return false;
572     std::shared_ptr<GeomAPI_Pnt2d> aSelectedPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aPointAttribute)->pnt();
573
574     // If we alredy have some result then:
575     // - if it is the same point all ok, just skip it
576     // - if it is point on the fillet result edge then it is not valid
577     if(!aPointsFeaturesMap.empty()) {
578       if(aPointsFeaturesMap.find(aPointAttribute) != aPointsFeaturesMap.end()) {
579         continue;
580       }
581
582       // Check that selected point not on the one of the fillet result edge.
583       if(aSetOfPointsOnResultEdges.find(aPointAttribute) != aSetOfPointsOnResultEdges.end()) {
584         return false;
585       }
586     }
587
588     // Obtain constraint coincidence for the fillet point.
589     const std::set<AttributePtr>& aRefsList = aPointAttribute->owner()->data()->refsToMe();
590     FeaturePtr aConstraintCoincidence;
591     for(std::set<AttributePtr>::const_iterator anIt = aRefsList.cbegin(); anIt != aRefsList.cend(); ++anIt) {
592       std::shared_ptr<ModelAPI_Attribute> aAttr = (*anIt);
593       FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
594       if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
595         AttributeRefAttrPtr anAttrRefA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
596           aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_A()));
597         AttributeRefAttrPtr anAttrRefB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
598           aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_B()));
599         if(anAttrRefA.get() && !anAttrRefA->isObject()) {
600           AttributePtr anAttrA = anAttrRefA->attr();
601           if(aPointAttribute == anAttrA) {
602             aConstraintCoincidence = aConstrFeature;
603             break;
604           }
605         }
606         if(anAttrRefB.get() && !anAttrRefB->isObject()) {
607           AttributePtr anAttrB = anAttrRefB->attr();
608           if(aPointAttribute == anAttrB) {
609             aConstraintCoincidence = aConstrFeature;
610             break;
611           }
612         }
613       }
614     }
615
616     if(!aConstraintCoincidence.get()) {
617       theError = "Error: one of the selected point does not have coicidence.";
618       return false;
619     }
620
621     // Get coincides from constraint.
622     std::set<FeaturePtr> aCoinsides;
623     SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
624                                          SketchPlugin_ConstraintCoincidence::ENTITY_A(),
625                                          aCoinsides);
626     SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
627                                          SketchPlugin_ConstraintCoincidence::ENTITY_B(),
628                                          aCoinsides);
629
630     // Remove points from set of coincides.
631     std::set<FeaturePtr> aNewSetOfCoincides;
632     for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin(); anIt != aCoinsides.end(); ++anIt) {
633       if((*anIt)->getKind() != SketchPlugin_Line::ID() &&
634          (*anIt)->getKind() != SketchPlugin_Arc::ID()) {
635            continue;
636       }
637       if((*anIt)->getKind() == SketchPlugin_Arc::ID()) {
638         AttributePtr anArcCenter = (*anIt)->attribute(SketchPlugin_Arc::CENTER_ID());
639         std::shared_ptr<GeomAPI_Pnt2d> anArcCenterPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anArcCenter)->pnt();
640         double aDistSelectedArcCenter = aSelectedPnt->distance(anArcCenterPnt);
641         if(aDistSelectedArcCenter < tolerance) {
642           continue;
643         }
644       }
645       aNewSetOfCoincides.insert(*anIt);
646     }
647     aCoinsides = aNewSetOfCoincides;
648
649     // If we still have more than two coincides remove auxilary entities from set of coincides.
650     if(aCoinsides.size() > 2) {
651       aNewSetOfCoincides.clear();
652       for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin(); anIt != aCoinsides.end(); ++anIt) {
653         if(!(*anIt)->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value()) {
654           aNewSetOfCoincides.insert(*anIt);
655         }
656       }
657       aCoinsides = aNewSetOfCoincides;
658     }
659
660     if(aCoinsides.size() != 2) {
661       theError = "Error: One of the selected points does not have two suitable edges for fillet.";
662       return false;
663     }
664
665     // Check that selected edges don't have tangent constraint.
666     std::set<FeaturePtr>::iterator anIt = aCoinsides.begin();
667     FeaturePtr aFirstFeature = *anIt++;
668     FeaturePtr aSecondFeature = *anIt;
669     const std::set<AttributePtr>& aFirstFeatureRefsList = aFirstFeature->data()->refsToMe();
670     if(hasSameTangentFeature(aFirstFeatureRefsList, aSecondFeature)) {
671       theError = "Error: Edges in selected point has tangent constraint.";
672       return false;
673     }
674
675     std::list<ResultPtr> aFirstResults = aFirstFeature->results();
676     for(std::list<ResultPtr>::iterator aResIt = aFirstResults.begin(); aResIt != aFirstResults.end(); ++aResIt) {
677       ResultPtr aRes = *aResIt;
678       const std::set<AttributePtr>& aResRefsList = aRes->data()->refsToMe();
679       if(hasSameTangentFeature(aResRefsList, aSecondFeature)) {
680         theError = "Error: Edges in selected point has tangent constraint.";
681         return false;
682       }
683     }
684
685     // Check that lines not collinear
686     if(aFirstFeature->getKind() == SketchPlugin_Line::ID() && aSecondFeature->getKind() == SketchPlugin_Line::ID()) {
687       std::string aStartAttr = SketchPlugin_Line::START_ID();
688       std::string anEndAttr = SketchPlugin_Line::END_ID();
689       std::shared_ptr<GeomAPI_Pnt2d> aFirstStartPnt, aFirstEndPnt, aSecondStartPnt, aSecondEndPnt;
690       aFirstStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFirstFeature->attribute(aStartAttr))->pnt();
691       aFirstEndPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFirstFeature->attribute(anEndAttr))->pnt();
692       aSecondStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aSecondFeature->attribute(aStartAttr))->pnt();
693       aSecondEndPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aSecondFeature->attribute(anEndAttr))->pnt();
694       double aCheck1 = fabs((aFirstEndPnt->x() - aFirstStartPnt->x()) * (aSecondStartPnt->y() - aFirstStartPnt->y()) -
695         (aSecondStartPnt->x() - aFirstStartPnt->x()) * (aFirstEndPnt->y() - aFirstStartPnt->y()));
696       double aCheck2 = fabs((aFirstEndPnt->x() - aFirstStartPnt->x()) * (aSecondEndPnt->y() - aFirstStartPnt->y()) -
697         (aSecondEndPnt->x() - aFirstStartPnt->x()) * (aFirstEndPnt->y() - aFirstStartPnt->y()));
698       if(aCheck1 < 1.e-7 && aCheck2 < 1.e-7) {
699         return false;
700       }
701     }
702   }
703
704   return true;
705 }
706
707 bool SketchPlugin_MiddlePointAttrValidator::isValid(const AttributePtr& theAttribute, 
708                                                     const std::list<std::string>& theArguments,
709                                                     Events_InfoMessage& theError) const
710 {
711   if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
712     theError = "The attribute with the %1 type is not processed";
713     theError.arg(theAttribute->attributeType());
714     return false;
715   }
716
717   // there is a check whether the feature contains a point and a linear edge or two point values
718   std::string aParamA = theArguments.front();
719   SessionPtr aMgr = ModelAPI_Session::get();
720   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
721
722   FeaturePtr anAttributeFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
723   AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
724   AttributeRefAttrPtr anOtherAttr = anAttributeFeature->data()->refattr(aParamA);
725
726   AttributeRefAttrPtr aRefAttrs[2] = {aRefAttr, anOtherAttr};
727   int aNbPoints = 0;
728   int aNbLines = 0;
729   for (int i = 0; i < 2; ++i) {
730     if (!aRefAttrs[i]->isObject())
731       ++aNbPoints;
732     else {
733       FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrs[i]->object());
734       if (!aFeature) {
735         if (aNbPoints + aNbLines != 0)
736           return true;
737         else continue;
738       }
739
740       if (aFeature->getKind() == SketchPlugin_Point::ID())
741         ++aNbPoints;
742       else if (aFeature->getKind() == SketchPlugin_Line::ID())
743         ++aNbLines;
744     }
745   }
746
747   if (aNbPoints != 1 || aNbLines != 1) {
748     theError = "Middle point constraint allows points and lines only";
749     return false;
750   }
751   return true;
752 }
753
754 bool SketchPlugin_ArcTangentPointValidator::isValid(const AttributePtr& theAttribute,
755                                                     const std::list<std::string>& /*theArguments*/,
756                                                     Events_InfoMessage& theError) const
757 {
758   if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
759     theError = "The attribute with the %1 type is not processed";
760     theError.arg(theAttribute->attributeType());
761     return false;
762   }
763   AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
764   AttributePtr anAttr = aRefAttr->attr();
765   if (!anAttr) {
766     theError = "The attribute %1 should be a point";
767     theError.arg(theAttribute->id());
768     return false;
769   }
770
771   FeaturePtr anAttrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->owner());
772   const std::string& aFeatureType = anAttrFeature->getKind();
773   if (aFeatureType == SketchPlugin_Arc::ID()) {
774     // selected point should not be a center of arc
775     const std::string& aPntId = anAttr->id();
776     if (aPntId != SketchPlugin_Arc::START_ID() && aPntId != SketchPlugin_Arc::END_ID()) {
777       theError = "The attribute %1 is not supported";
778       theError.arg(aPntId);
779       return false;
780     }
781   }
782   else if (aFeatureType == SketchPlugin_Line::ID()) {
783     // selected point should be bound point of line
784     const std::string& aPntId = anAttr->id();
785     if (aPntId != SketchPlugin_Line::START_ID() && aPntId != SketchPlugin_Line::END_ID()) {
786       theError = "The attribute %1 is not supported";
787       theError.arg(aPntId);
788       return false;
789     }
790   }
791   else {
792     theError = "Unable to build tangent arc on %1";
793     theError.arg(anAttrFeature->getKind());
794     return false;
795   }
796
797   // Check the tangent point is equal to arc end
798   FeaturePtr anArc = std::dynamic_pointer_cast<ModelAPI_Feature>(aRefAttr->owner());
799   std::shared_ptr<GeomDataAPI_Point2D> anEndPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
800       anArc->attribute(SketchPlugin_Arc::END_ID()));
801   if (anEndPoint->isInitialized()) {
802     std::shared_ptr<GeomDataAPI_Point2D> aTangPt =
803         std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr);
804     if (aTangPt->pnt()->distance(anEndPoint->pnt()) < tolerance) {
805       theError = "Unable to build arc on same points";
806       return false;
807     }
808   }
809
810   return true;
811 }
812
813 bool SketchPlugin_IntersectionValidator::isValid(const AttributePtr& theAttribute,
814                                                  const std::list<std::string>& theArguments,
815                                                  Events_InfoMessage& theError) const
816 {
817   if (theAttribute->attributeType() != ModelAPI_AttributeSelection::typeId()) {
818     theError = "The attribute with the %1 type is not processed";
819     theError.arg(theAttribute->attributeType());
820     return false;
821   }
822   AttributeSelectionPtr aLineAttr =
823                               std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
824   std::shared_ptr<GeomAPI_Edge> anEdge;
825   if(aLineAttr && aLineAttr->value() && aLineAttr->value()->isEdge()) {
826     anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aLineAttr->value()));
827   } else if(aLineAttr->context() && aLineAttr->context()->shape() && aLineAttr->context()->shape()->isEdge()) {
828     anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aLineAttr->context()->shape()));
829   }
830
831   if (!anEdge || !anEdge->isLine()) {
832     theError = "The attribute %1 should be a line";
833     theError.arg(theAttribute->id());
834     return false;
835   }
836
837   std::shared_ptr<GeomAPI_Dir> aLineDir = anEdge->line()->direction();
838
839   // find a sketch
840   std::shared_ptr<SketchPlugin_Sketch> aSketch;
841   std::set<AttributePtr> aRefs = aLineAttr->owner()->data()->refsToMe();
842   std::set<AttributePtr>::const_iterator anIt = aRefs.begin();
843   for (; anIt != aRefs.end(); ++anIt) {
844     CompositeFeaturePtr aComp =
845         std::dynamic_pointer_cast<ModelAPI_CompositeFeature>((*anIt)->owner());
846     if (aComp && aComp->getKind() == SketchPlugin_Sketch::ID()) {
847       aSketch = std::dynamic_pointer_cast<SketchPlugin_Sketch>(aComp);
848       break;
849     }
850   }
851   if (!aSketch) {
852     theError = "There is no sketch referring to the current feature";
853     return false;
854   }
855
856   std::shared_ptr<GeomAPI_Pln> aPlane = aSketch->plane();
857   std::shared_ptr<GeomAPI_Dir> aNormal = aPlane->direction();
858   return fabs(aNormal->dot(aLineDir)) > tolerance * tolerance;
859 }
860
861 bool SketchPlugin_SplitValidator::isValid(const AttributePtr& theAttribute,
862                                           const std::list<std::string>& theArguments,
863                                           Events_InfoMessage& theError) const
864 {
865   bool aValid = false;
866
867   if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
868     theError = "The attribute with the %1 type is not processed";
869     theError.arg(theAttribute->attributeType());
870     return aValid;
871   }
872   AttributeReferencePtr aFeatureAttr =
873             std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
874
875   ObjectPtr anAttrObject = aFeatureAttr->value();
876   FeaturePtr anAttrFeature = ModelAPI_Feature::feature(anAttrObject);
877   if (!anAttrFeature)
878     return aValid;
879
880   std::string aKind = anAttrFeature->getKind();
881   if (aKind == SketchPlugin_Line::ID() ||
882       aKind == SketchPlugin_Arc::ID() ||
883       aKind == SketchPlugin_Circle::ID()) {
884
885     std::set<GeomShapePtr> anEdgeShapes;
886     ModelAPI_Tools::shapesOfType(anAttrFeature, GeomAPI_Shape::EDGE, anEdgeShapes);
887     if (anEdgeShapes.empty() || anEdgeShapes.size() > 1 /*there case has not existed yet*/)
888       return aValid;
889
890     // coincidences to the feature
891     std::set<std::shared_ptr<GeomDataAPI_Point2D> > aRefAttributes;
892     ModelGeomAlgo_Point2D::getPointsOfReference(anAttrFeature, SketchPlugin_ConstraintCoincidence::ID(),
893                          aRefAttributes, SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
894
895     GeomShapePtr anAttrShape = *anEdgeShapes.begin();
896     std::shared_ptr<SketchPlugin_Feature> aSFeature =
897                                  std::dynamic_pointer_cast<SketchPlugin_Feature>(anAttrFeature);
898     SketchPlugin_Sketch* aSketch = aSFeature->sketch();
899     
900     std::shared_ptr<ModelAPI_Data> aData = aSketch->data();
901     std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
902         aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
903     std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
904         aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
905     std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
906         aData->attribute(SketchPlugin_Sketch::NORM_ID()));
907     std::shared_ptr<GeomAPI_Dir> aDirY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
908     
909     std::list<std::shared_ptr<GeomAPI_Pnt> > aPoints;
910     std::map<std::shared_ptr<GeomDataAPI_Point2D>, std::shared_ptr<GeomAPI_Pnt> > aPointToAttributes;
911     ModelGeomAlgo_Point2D::getPointsInsideShape(anAttrShape, aRefAttributes, aC->pnt(),
912                                                 aX->dir(), aDirY, aPoints, aPointToAttributes);
913
914     int aCoincidentToFeature = (int)aPoints.size();
915     if (aKind == SketchPlugin_Circle::ID())
916       aValid = aCoincidentToFeature >= 2;
917     else
918       aValid = aCoincidentToFeature >= 1;
919   }
920
921   return aValid;
922 }
923
924 bool SketchPlugin_ProjectionValidator::isValid(const AttributePtr& theAttribute,
925                                                const std::list<std::string>& theArguments,
926                                                Events_InfoMessage& theError) const
927 {
928   if (theAttribute->attributeType() != ModelAPI_AttributeSelection::typeId()) {
929     theError = "The attribute with the %1 type is not processed";
930     theError.arg(theAttribute->attributeType());
931     return false;
932   }
933
934   AttributeSelectionPtr aFeatureAttr =
935       std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
936   std::shared_ptr<GeomAPI_Edge> anEdge;
937   if (aFeatureAttr.get()) {
938     GeomShapePtr aVal = aFeatureAttr->value();
939     ResultPtr aRes = aFeatureAttr->context();
940     if(aFeatureAttr->value() && aFeatureAttr->value()->isEdge()) {
941       anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aFeatureAttr->value()));
942     } else if(aFeatureAttr->context() && aFeatureAttr->context()->shape() &&
943               aFeatureAttr->context()->shape()->isEdge()) {
944       anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aFeatureAttr->context()->shape()));
945     }
946   }
947   if (!anEdge) {
948     theError = "The attribute %1 should be an edge";
949     theError.arg(theAttribute->id());
950     return false;
951   }
952
953   // find a sketch
954   std::shared_ptr<SketchPlugin_Sketch> aSketch;
955   std::set<AttributePtr> aRefs = theAttribute->owner()->data()->refsToMe();
956   std::set<AttributePtr>::const_iterator anIt = aRefs.begin();
957   for (; anIt != aRefs.end(); ++anIt) {
958     CompositeFeaturePtr aComp =
959         std::dynamic_pointer_cast<ModelAPI_CompositeFeature>((*anIt)->owner());
960     if (aComp && aComp->getKind() == SketchPlugin_Sketch::ID()) {
961       aSketch = std::dynamic_pointer_cast<SketchPlugin_Sketch>(aComp);
962       break;
963     }
964   }
965   if (!aSketch) {
966     theError = "There is no sketch referring to the current feature";
967     return false;
968   }
969
970   std::shared_ptr<GeomAPI_Pln> aPlane = aSketch->plane();
971   std::shared_ptr<GeomAPI_Dir> aNormal = aPlane->direction();
972   std::shared_ptr<GeomAPI_Pnt> anOrigin = aPlane->location();
973
974   if (anEdge->isLine()) {
975     std::shared_ptr<GeomAPI_Lin> aLine = anEdge->line();
976     std::shared_ptr<GeomAPI_Dir> aLineDir = aLine->direction();
977     std::shared_ptr<GeomAPI_Pnt> aLineLoc = aLine->location();
978     double aDot = aNormal->dot(aLineDir);
979     double aDist = aLineLoc->xyz()->decreased(anOrigin->xyz())->dot(aNormal->xyz());
980     bool aValid = (fabs(aDot) >= tolerance && fabs(aDot) < 1.0 - tolerance) ||
981            (fabs(aDot) < tolerance && fabs(aDist) > tolerance);
982     if (!aValid)
983       theError = "Error: Edge is already in the sketch plane.";
984     return aValid;
985   }
986   else if (anEdge->isCircle() || anEdge->isArc()) {
987     std::shared_ptr<GeomAPI_Circ> aCircle = anEdge->circle();
988     std::shared_ptr<GeomAPI_Dir> aCircNormal = aCircle->normal();
989     std::shared_ptr<GeomAPI_Pnt> aCircCenter = aCircle->center();
990     double aDot = fabs(aNormal->dot(aCircNormal));
991     double aDist = aCircCenter->xyz()->decreased(anOrigin->xyz())->dot(aNormal->xyz());
992     bool aValid = fabs(aDot - 1.0) < tolerance * tolerance && fabs(aDist) > tolerance;
993     if (!aValid)
994       theError.arg(anEdge->isCircle() ? "Error: Cirlce is already in the sketch plane."
995                                       : "Error: Arc is already in the sketch plane.");
996     return aValid;
997   }
998
999   theError = "Error: Selected object is not line, circle or arc.";
1000   return false;
1001 }