1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: SketchPlugin_Validators.cpp
4 // Created: 01 Aug 2014
5 // Author: Vitaly SMETANNIKOV
7 #include "SketchPlugin_Validators.h"
9 #include "SketchPlugin_Arc.h"
10 #include "SketchPlugin_Circle.h"
11 #include "SketchPlugin_ConstraintCoincidence.h"
12 #include "SketchPlugin_ConstraintDistance.h"
13 #include "SketchPlugin_ConstraintRigid.h"
14 #include "SketchPlugin_Line.h"
15 #include "SketchPlugin_Point.h"
16 #include "SketchPlugin_Sketch.h"
17 #include "SketchPlugin_Tools.h"
19 #include "SketcherPrs_Tools.h"
21 #include <ModelAPI_Data.h>
22 #include <ModelAPI_Validator.h>
23 #include <ModelAPI_AttributeDouble.h>
24 #include <ModelAPI_AttributeRefAttr.h>
26 #include <ModelAPI_AttributeRefAttrList.h>
27 #include <ModelAPI_AttributeRefList.h>
28 #include <ModelAPI_AttributeSelectionList.h>
29 #include <ModelAPI_AttributeString.h>
30 #include <ModelAPI_Session.h>
31 #include <ModelAPI_ResultConstruction.h>
33 #include <GeomAPI_Vertex.h>
34 #include <GeomDataAPI_Point2D.h>
36 const double tolerance = 1.e-7;
38 bool SketchPlugin_DistanceAttrValidator::isValid(const AttributePtr& theAttribute,
39 const std::list<std::string>& theArguments,
40 std::string& theError) const
42 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
43 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
47 // there is a check whether the feature contains a point and a linear edge or two point values
48 std::string aParamA = theArguments.front();
49 SessionPtr aMgr = ModelAPI_Session::get();
50 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
52 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
53 bool isObject = aRefAttr->isObject();
55 // an attribute is a point. A point value is valid always for the distance
58 // 1. check whether the references object is a linear
59 ObjectPtr anObject = aRefAttr->object();
61 const ModelAPI_AttributeValidator* aShapeValidator =
62 dynamic_cast<const ModelAPI_AttributeValidator*>(aFactory->validator("GeomValidators_ShapeType"));
63 std::list<std::string> anArguments;
64 anArguments.push_back("circle");
65 std::string aCircleError;
66 bool aShapeValid = aShapeValidator->isValid(aRefAttr, anArguments, aCircleError);
67 // the circle line is not a valid case
69 theError = "Circle can not be used in distance constraint";
74 anArguments.push_back("line");
75 std::string aLineError;
76 aShapeValid = aShapeValidator->isValid(aRefAttr, anArguments, aLineError);
77 // if the attribute value is not a line, that means it is a vertex. A vertex is always valid
79 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
80 // If it is a line then we have to check that first attribute id not a line
81 std::shared_ptr<SketchPlugin_Feature> aSFeature =
82 std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
83 SketchPlugin_Sketch* aSketch = aSFeature->sketch();
84 std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(aSketch);
85 std::shared_ptr<GeomDataAPI_Point2D> aPoint = SketcherPrs_Tools::getFeaturePoint(
86 aFeature->data(), aParamA, aPlane);
88 theError = "One of parameters of distance constraint should be a point";
97 static bool hasCoincidentPoint(FeaturePtr theFeature1, FeaturePtr theFeature2)
99 FeaturePtr aConstrFeature;
100 std::list<AttributePtr> anAttrList;
101 if (theFeature1->getKind() == SketchPlugin_Circle::ID() ||
102 theFeature2->getKind() == SketchPlugin_Circle::ID())
104 if (theFeature2->getKind() == SketchPlugin_Line::ID()) {
105 anAttrList.push_back(theFeature2->attribute(SketchPlugin_Line::START_ID()));
106 anAttrList.push_back(theFeature2->attribute(SketchPlugin_Line::END_ID()));
107 } else if (theFeature2->getKind() == SketchPlugin_Arc::ID()) {
108 anAttrList.push_back(theFeature2->attribute(SketchPlugin_Arc::START_ID()));
109 anAttrList.push_back(theFeature2->attribute(SketchPlugin_Arc::END_ID()));
112 const std::set<AttributePtr>& aRefsList = theFeature1->data()->refsToMe();
113 std::set<AttributePtr>::const_iterator aRefIt = aRefsList.begin();
114 for (; aRefIt != aRefsList.end(); ++aRefIt) {
115 aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRefIt)->owner());
116 if (aConstrFeature->getKind() != SketchPlugin_ConstraintCoincidence::ID())
118 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*aRefIt);
119 AttributePtr anAttr = aRefAttr->attr();
120 if (anAttr->id() == SketchPlugin_Arc::CENTER_ID())
123 anAttr = aConstrFeature->attribute(SketchPlugin_Constraint::ENTITY_A());
124 if (anAttr == *aRefIt)
125 anAttr = aConstrFeature->attribute(SketchPlugin_Constraint::ENTITY_B());
127 aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttr);
130 anAttr = aRefAttr->attr();
131 for (std::list<AttributePtr>::const_iterator anIt = anAttrList.begin();
132 anIt != anAttrList.end(); ++anIt)
139 bool SketchPlugin_TangentAttrValidator::isValid(const AttributePtr& theAttribute,
140 const std::list<std::string>& theArguments,
141 std::string& theError) const
143 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
144 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
148 // there is a check whether the feature contains a point and a linear edge or two point values
149 std::string aParamA = theArguments.front();
150 SessionPtr aMgr = ModelAPI_Session::get();
151 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
153 FeaturePtr anAttributeFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
154 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
156 bool isObject = aRefAttr->isObject();
157 ObjectPtr anObject = aRefAttr->object();
158 if (isObject && anObject.get()) {
159 FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject);
161 AttributeRefAttrPtr aOtherAttr = anAttributeFeature->data()->refattr(aParamA);
162 ObjectPtr aOtherObject = aOtherAttr->object();
163 FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject);
167 if ((aRefFea->getKind() == SketchPlugin_Arc::ID() ||
168 aOtherFea->getKind() == SketchPlugin_Arc::ID()) &&
169 !hasCoincidentPoint(aRefFea, aOtherFea))
172 if (aRefFea->getKind() == SketchPlugin_Line::ID()) {
173 if (aOtherFea->getKind() != SketchPlugin_Arc::ID() &&
174 aOtherFea->getKind() != SketchPlugin_Circle::ID()) {
175 theError = "It refers to a " + SketchPlugin_Line::ID() + ", but " + aParamA + " is neither an "
176 + SketchPlugin_Arc::ID() + " nor " + SketchPlugin_Circle::ID();
180 else if (aRefFea->getKind() == SketchPlugin_Arc::ID()) {
181 if (aOtherFea->getKind() != SketchPlugin_Line::ID() &&
182 aOtherFea->getKind() != SketchPlugin_Arc::ID()) {
183 theError = "It refers to an " + SketchPlugin_Arc::ID() + ", but " + aParamA + " is not a "
184 + SketchPlugin_Line::ID() + " or an " + SketchPlugin_Arc::ID();
188 else if (aRefFea->getKind() == SketchPlugin_Circle::ID()) {
189 if (aOtherFea->getKind() != SketchPlugin_Line::ID()) {
190 theError = "It refers to an " + SketchPlugin_Circle::ID() + ", but " + aParamA + " is not a "
191 + SketchPlugin_Line::ID();
196 theError = "It refers to " + aRefFea->getKind() + ", but should refer to " + SketchPlugin_Line::ID()
197 + " or " + SketchPlugin_Arc::ID() + " or " + SketchPlugin_Circle::ID();
203 theError = "It uses an empty object";
210 bool SketchPlugin_NotFixedValidator::isValid(const AttributePtr& theAttribute,
211 const std::list<std::string>& theArguments,
212 std::string& theError) const
214 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
215 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
219 std::shared_ptr<SketchPlugin_Feature> aFeature =
220 std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
224 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
226 SketchPlugin_Sketch* aSketch = aFeature->sketch();
227 int aNbFeatures = aSketch->numberOfSubs();
228 for (int anInd = 0; anInd < aNbFeatures; anInd++) {
229 FeaturePtr aSubFeature = aSketch->subFeature(anInd);
230 if (aSubFeature->getKind() != SketchPlugin_ConstraintRigid::ID() || aSubFeature == aFeature)
232 AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
233 aSubFeature->attribute(SketchPlugin_ConstraintRigid::ENTITY_A()));
234 if (aRefAttr->isObject()) {
235 if (aRefAttr->object() == aRAttr->object()) {
236 ObjectPtr anObject = aRefAttr->object();
237 std::string aName = anObject.get() ? anObject->data()->name() : "";
238 theError = "The object " + aName + " has been already fixed.";
242 else if (aRefAttr->attr() == aRAttr->attr()) {
243 AttributePtr anAttribute = aRefAttr->attr();
244 std::string aName = anAttribute.get() ? anAttribute->id() : "";
245 theError = "The attribute " + aName + " has been already fixed.";
252 bool SketchPlugin_EqualAttrValidator::isValid(const AttributePtr& theAttribute,
253 const std::list<std::string>& theArguments,
254 std::string& theError) const
256 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
257 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
261 std::string aParamA = theArguments.front();
262 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
263 AttributeRefAttrPtr aRefAttr[2];
264 aRefAttr[0] = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
265 aRefAttr[1] = aFeature->data()->refattr(aParamA);
267 if (!aRefAttr[0]->isObject() || !aRefAttr[1]->isObject()) {
268 theError = "Attributes can not be used in equal constraint";
272 std::string aType[2];
273 std::list<std::string> anArguments;
274 for (int i = 0; i < 2; i++) {
275 ObjectPtr anObject = aRefAttr[i]->object();
276 if (!anObject.get()) {
277 theError = "An empty object is used.";
281 aFeature = ModelAPI_Feature::feature(anObject);
282 if (!aFeature.get()) {
283 theError = "An empty feature is used.";
287 aType[i] = aFeature->getKind();
288 if (aFeature->getKind() != SketchPlugin_Line::ID() &&
289 aFeature->getKind() != SketchPlugin_Circle::ID() &&
290 aFeature->getKind() != SketchPlugin_Arc::ID()) {
291 theError = "The " + aFeature->getKind() + " feature kind of attribute is wrong. It should be " +
292 SketchPlugin_Line::ID() + " or " + SketchPlugin_Circle::ID() + " or " +
293 SketchPlugin_Arc::ID();
294 // wrong type of attribute
299 if ((aType[0] == SketchPlugin_Line::ID() || aType[1] == SketchPlugin_Line::ID()) &&
300 aType[0] != aType[1]) {
301 theError = "Feature with kinds " + aType[0] + " and " + aType[1] + "can not be equal.";
307 bool SketchPlugin_MirrorAttrValidator::isValid(const AttributePtr& theAttribute,
308 const std::list<std::string>& theArguments,
309 std::string& theError) const
311 if (theAttribute->attributeType() != ModelAPI_AttributeRefList::typeId()) {
312 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
316 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
317 AttributeRefListPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
319 AttributeRefListPtr aRefListOfMirrored = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
320 aFeature->attribute(SketchPlugin_Constraint::ENTITY_C()));
321 std::list<ObjectPtr> aMirroredObjects = aRefListOfMirrored->list();
323 for(int anInd = 0; anInd < aSelAttr->size(); anInd++) {
324 ObjectPtr aSelObject = aSelAttr->object(anInd);
325 std::string aName = aSelObject.get() ? aSelObject->data()->name() : "";
326 std::list<ObjectPtr>::iterator aMirIter = aMirroredObjects.begin();
327 for (; aMirIter != aMirroredObjects.end(); aMirIter++)
328 if (aSelObject == *aMirIter) {
329 theError = "The object " + aName + " is a result of mirror";
336 bool SketchPlugin_CoincidenceAttrValidator::isValid(const AttributePtr& theAttribute,
337 const std::list<std::string>& theArguments,
338 std::string& theError) const
340 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
341 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
345 // there is a check whether the feature contains a point and a linear edge or two point values
346 std::string aParamA = theArguments.front();
347 SessionPtr aMgr = ModelAPI_Session::get();
348 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
350 FeaturePtr aConstraint = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
351 AttributeRefAttrPtr aRefAttrA = aConstraint->data()->refattr(aParamA);
353 theError = "The " + aParamA + " attribute " + " should be " + ModelAPI_AttributeRefAttr::typeId();
357 AttributeRefAttrPtr aRefAttrB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
359 // first attribute is a point, it may coincide with any object
360 if (!aRefAttrA->isObject())
363 ObjectPtr anObject = aRefAttrA->object();
364 if (!anObject.get()) {
365 theError = aParamA + " attribute has an empty object";
368 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrA->object());
369 if (!aFeature.get()) {
370 theError = aParamA + " attribute has an empty feature";
374 if (aFeature->getKind() == SketchPlugin_Point::ID())
378 // second attribute is a point, it may coincide with any object
379 if (!aRefAttrB->isObject())
382 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrB->object());
384 theError = theAttribute->id() + " attribute has an empty object";
387 if (aFeature->getKind() == SketchPlugin_Point::ID())
390 theError = "There is no an attribute filled by a point";
395 bool SketchPlugin_CopyValidator::isValid(const AttributePtr& theAttribute,
396 const std::list<std::string>& theArguments,
397 std::string& theError) const
399 if (theAttribute->attributeType() != ModelAPI_AttributeRefList::typeId()) {
400 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
404 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
405 AttributeRefListPtr aSelAttr =
406 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
408 AttributeRefListPtr aRefListOfInitial = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
409 aFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
410 AttributeRefListPtr aRefListOfCopied = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
411 aFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
412 std::list<ObjectPtr> anInitialObjects = aRefListOfInitial->list();
413 std::list<ObjectPtr> aCopiedObjects = aRefListOfCopied->list();
415 std::list<ObjectPtr>::iterator anObjIter;
416 for(int anInd = 0; anInd < aSelAttr->size(); anInd++) {
417 ObjectPtr aSelObject = aSelAttr->object(anInd);
418 anObjIter = anInitialObjects.begin();
419 for (; anObjIter != anInitialObjects.end(); anObjIter++)
420 if (aSelObject == *anObjIter)
422 if (anObjIter != anInitialObjects.end())
424 anObjIter = aCopiedObjects.begin();
425 for (; anObjIter != aCopiedObjects.end(); anObjIter++)
426 if (aSelObject == *anObjIter) {
427 std::string aName = aSelObject.get() ? aSelObject->data()->name() : "";
428 theError = "The object " + aName + " is a result of copy";
435 bool SketchPlugin_SolverErrorValidator::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
436 const std::list<std::string>& theArguments,
437 std::string& theError) const
439 AttributeStringPtr aAttributeString = theFeature->string(SketchPlugin_Sketch::SOLVER_ERROR());
441 if (!aAttributeString->value().empty()) {
442 theError = aAttributeString->value();
449 bool SketchPlugin_SolverErrorValidator::isNotObligatory(std::string theFeature, std::string theAttribute)
454 bool SketchPlugin_FilletVertexValidator::isValid(const AttributePtr& theAttribute,
455 const std::list<std::string>& theArguments,
456 std::string& theError) const
458 if(!theAttribute.get() || !theAttribute->isInitialized()) {
459 theError = "Error: List of points is not initialized.";
463 FeaturePtr aFilletFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
464 AttributeRefAttrListPtr aPointsRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
465 if(aPointsRefList->size() == 0) {
466 theError = "Error: List of points is empty.";
470 AttributeRefAttrListPtr aBasePointsRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(
471 aFilletFeature->attribute(SketchPlugin_Constraint::ENTITY_C()));
472 AttributeRefListPtr aResultEdgesRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
473 aFilletFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
475 std::list<std::pair<ObjectPtr, AttributePtr>> aPointsList = aPointsRefList->list();
476 for(std::list<std::pair<ObjectPtr, AttributePtr>>::const_iterator anIt = aPointsList.cbegin(); anIt != aPointsList.cend(); anIt++) {
477 ObjectPtr anObject = (*anIt).first;
478 AttributePtr aPointAttribute = (*anIt).second;
480 // If we alredy have some result then:
481 // - if it is the same point all ok, just skip it
482 // - if it is point on the fillet arc then it is not valid
483 if(aBasePointsRefList->size() > 0) {
484 if(aBasePointsRefList->isInList(aPointAttribute)) {
488 // Check that selected point not on the one of the result fillet arc.
489 for(int anIndex = 0; anIndex < aBasePointsRefList->size(); anIndex++) {
490 if(aResultEdgesRefList->size() > 0) {
491 FeaturePtr aResultArc;
492 aResultArc = ModelAPI_Feature::feature(aResultEdgesRefList->object(anIndex * 3 + 2));
493 AttributePtr anArcStart = aResultArc->attribute(SketchPlugin_Arc::START_ID());
494 AttributePtr anArcEnd = aResultArc->attribute(SketchPlugin_Arc::END_ID());
495 std::shared_ptr<GeomAPI_Pnt2d> anArcStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anArcStart)->pnt();
496 std::shared_ptr<GeomAPI_Pnt2d> anArcEndPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anArcEnd)->pnt();
497 std::shared_ptr<GeomAPI_Pnt2d> aSelectedPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aPointAttribute)->pnt();
498 double aDistSelectedArcStart = aSelectedPnt->distance(anArcStartPnt);
499 double aDistSelectedArcEnd = aSelectedPnt->distance(anArcEndPnt);
500 if(aDistSelectedArcStart < tolerance || aDistSelectedArcEnd < tolerance) {
507 // Obtain constraint coincidence for the fillet point.
508 const std::set<AttributePtr>& aRefsList = aPointAttribute->owner()->data()->refsToMe();
509 FeaturePtr aConstraintCoincidence;
510 for(std::set<AttributePtr>::const_iterator anIt = aRefsList.cbegin(); anIt != aRefsList.cend(); ++anIt) {
511 std::shared_ptr<ModelAPI_Attribute> aAttr = (*anIt);
512 FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
513 if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
514 AttributeRefAttrPtr anAttrRefA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
515 aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_A()));
516 AttributeRefAttrPtr anAttrRefB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
517 aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_B()));
518 if(anAttrRefA.get() && !anAttrRefA->isObject()) {
519 AttributePtr anAttrA = anAttrRefA->attr();
520 if(aPointAttribute == anAttrA) {
521 aConstraintCoincidence = aConstrFeature;
525 if(anAttrRefB.get() && !anAttrRefB->isObject()) {
526 AttributePtr anAttrB = anAttrRefB->attr();
527 if(aPointAttribute == anAttrB) {
528 aConstraintCoincidence = aConstrFeature;
535 if(!aConstraintCoincidence.get()) {
536 theError = "Error: one of the selected point does not have coicidence.";
540 // Get coincides from constraint.
541 std::set<FeaturePtr> aCoinsides;
542 SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
543 SketchPlugin_ConstraintCoincidence::ENTITY_A(),
545 SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
546 SketchPlugin_ConstraintCoincidence::ENTITY_B(),
549 // Remove points from set of coincides.
550 std::set<FeaturePtr> aNewSetOfCoincides;
551 for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin(); anIt != aCoinsides.end(); ++anIt) {
552 if((*anIt)->getKind() == SketchPlugin_Line::ID() ||
553 (*anIt)->getKind() == SketchPlugin_Arc::ID()) {
554 aNewSetOfCoincides.insert(*anIt);
557 aCoinsides = aNewSetOfCoincides;
559 // If we still have more than two coincides remove auxilary entities from set of coincides.
560 if(aCoinsides.size() > 2) {
561 aNewSetOfCoincides.clear();
562 for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin(); anIt != aCoinsides.end(); ++anIt) {
563 if(!(*anIt)->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value()) {
564 aNewSetOfCoincides.insert(*anIt);
567 aCoinsides = aNewSetOfCoincides;
570 if(aCoinsides.size() != 2) {
571 theError = ("Error: One of the selected points does not have two suitable edges for fillet.");
575 // Check that lines not collinear
576 std::set<FeaturePtr>::iterator anIt = aCoinsides.begin();
577 FeaturePtr aFirstFeature = *anIt++;
578 FeaturePtr aSecondFeature = *anIt;
579 if(aFirstFeature->getKind() == SketchPlugin_Line::ID() && aSecondFeature->getKind() == SketchPlugin_Line::ID()) {
580 std::string aStartAttr = SketchPlugin_Line::START_ID();
581 std::string anEndAttr = SketchPlugin_Line::END_ID();
582 std::shared_ptr<GeomAPI_Pnt2d> aFirstStartPnt, aFirstEndPnt, aSecondStartPnt, aSecondEndPnt;
583 aFirstStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFirstFeature->attribute(aStartAttr))->pnt();
584 aFirstEndPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFirstFeature->attribute(anEndAttr))->pnt();
585 aSecondStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aSecondFeature->attribute(aStartAttr))->pnt();
586 aSecondEndPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aSecondFeature->attribute(anEndAttr))->pnt();
587 double aCheck1 = abs((aFirstEndPnt->x() - aFirstStartPnt->x()) * (aSecondStartPnt->y() - aFirstStartPnt->y()) -
588 (aSecondStartPnt->x() - aFirstStartPnt->x()) * (aFirstEndPnt->y() - aFirstStartPnt->y()));
589 double aCheck2 = abs((aFirstEndPnt->x() - aFirstStartPnt->x()) * (aSecondEndPnt->y() - aFirstStartPnt->y()) -
590 (aSecondEndPnt->x() - aFirstStartPnt->x()) * (aFirstEndPnt->y() - aFirstStartPnt->y()));
591 if(aCheck1 < 1.e-7 && aCheck2 < 1.e-7) {
600 bool SketchPlugin_MiddlePointAttrValidator::isValid(const AttributePtr& theAttribute,
601 const std::list<std::string>& theArguments,
602 std::string& theError) const
604 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
605 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
609 // there is a check whether the feature contains a point and a linear edge or two point values
610 std::string aParamA = theArguments.front();
611 SessionPtr aMgr = ModelAPI_Session::get();
612 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
614 FeaturePtr anAttributeFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
615 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
616 AttributeRefAttrPtr anOtherAttr = anAttributeFeature->data()->refattr(aParamA);
618 AttributeRefAttrPtr aRefAttrs[2] = {aRefAttr, anOtherAttr};
621 for (int i = 0; i < 2; ++i) {
622 if (!aRefAttrs[i]->isObject())
625 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrs[i]->object());
627 if (aNbPoints + aNbLines != 0)
632 if (aFeature->getKind() == SketchPlugin_Point::ID())
634 else if (aFeature->getKind() == SketchPlugin_Line::ID())
639 if (aNbPoints != 1 || aNbLines != 1) {
640 theError = "Middle point constraint allows points and lines only";
646 bool SketchPlugin_ArcTangentPointValidator::isValid(const AttributePtr& theAttribute,
647 const std::list<std::string>& /*theArguments*/,
648 std::string& theError) const
650 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
651 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
654 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
655 AttributePtr anAttr = aRefAttr->attr();
657 theError = "The attribute " + theAttribute->id() + " should be a point";
661 FeaturePtr anAttrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->owner());
662 const std::string& aFeatureType = anAttrFeature->getKind();
663 if (aFeatureType == SketchPlugin_Arc::ID()) {
664 // selected point should not be a center of arc
665 const std::string& aPntId = anAttr->id();
666 if (aPntId != SketchPlugin_Arc::START_ID() && aPntId != SketchPlugin_Arc::END_ID()) {
667 theError = "The attribute " + aPntId + " is not supported";
671 else if (aFeatureType == SketchPlugin_Line::ID()) {
672 // selected point should be bound point of line
673 const std::string& aPntId = anAttr->id();
674 if (aPntId != SketchPlugin_Line::START_ID() && aPntId != SketchPlugin_Line::END_ID()) {
675 theError = "The attribute " + aPntId + " is not supported";
680 theError = "Unable to build tangent arc on " + anAttrFeature->getKind();