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);
128 anAttr = aRefAttr->attr();
129 for (std::list<AttributePtr>::const_iterator anIt = anAttrList.begin();
130 anIt != anAttrList.end(); ++anIt)
137 bool SketchPlugin_TangentAttrValidator::isValid(const AttributePtr& theAttribute,
138 const std::list<std::string>& theArguments,
139 std::string& theError) const
141 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
142 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
146 // there is a check whether the feature contains a point and a linear edge or two point values
147 std::string aParamA = theArguments.front();
148 SessionPtr aMgr = ModelAPI_Session::get();
149 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
151 FeaturePtr anAttributeFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
152 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
154 bool isObject = aRefAttr->isObject();
155 ObjectPtr anObject = aRefAttr->object();
156 if (isObject && anObject.get()) {
157 FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject);
159 AttributeRefAttrPtr aOtherAttr = anAttributeFeature->data()->refattr(aParamA);
160 ObjectPtr aOtherObject = aOtherAttr->object();
161 FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject);
165 if ((aRefFea->getKind() == SketchPlugin_Arc::ID() ||
166 aOtherFea->getKind() == SketchPlugin_Arc::ID()) &&
167 !hasCoincidentPoint(aRefFea, aOtherFea))
170 if (aRefFea->getKind() == SketchPlugin_Line::ID()) {
171 if (aOtherFea->getKind() != SketchPlugin_Arc::ID() &&
172 aOtherFea->getKind() != SketchPlugin_Circle::ID()) {
173 theError = "It refers to a " + SketchPlugin_Line::ID() + ", but " + aParamA + " is neither an "
174 + SketchPlugin_Arc::ID() + " nor " + SketchPlugin_Circle::ID();
178 else if (aRefFea->getKind() == SketchPlugin_Arc::ID()) {
179 if (aOtherFea->getKind() != SketchPlugin_Line::ID() &&
180 aOtherFea->getKind() != SketchPlugin_Arc::ID()) {
181 theError = "It refers to an " + SketchPlugin_Arc::ID() + ", but " + aParamA + " is not a "
182 + SketchPlugin_Line::ID() + " or an " + SketchPlugin_Arc::ID();
186 else if (aRefFea->getKind() == SketchPlugin_Circle::ID()) {
187 if (aOtherFea->getKind() != SketchPlugin_Line::ID()) {
188 theError = "It refers to an " + SketchPlugin_Circle::ID() + ", but " + aParamA + " is not a "
189 + SketchPlugin_Line::ID();
194 theError = "It refers to " + aRefFea->getKind() + ", but should refer to " + SketchPlugin_Line::ID()
195 + " or " + SketchPlugin_Arc::ID() + " or " + SketchPlugin_Circle::ID();
201 theError = "It uses an empty object";
208 bool SketchPlugin_NotFixedValidator::isValid(const AttributePtr& theAttribute,
209 const std::list<std::string>& theArguments,
210 std::string& theError) const
212 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
213 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
217 std::shared_ptr<SketchPlugin_Feature> aFeature =
218 std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
222 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
224 SketchPlugin_Sketch* aSketch = aFeature->sketch();
225 int aNbFeatures = aSketch->numberOfSubs();
226 for (int anInd = 0; anInd < aNbFeatures; anInd++) {
227 FeaturePtr aSubFeature = aSketch->subFeature(anInd);
228 if (aSubFeature->getKind() != SketchPlugin_ConstraintRigid::ID() || aSubFeature == aFeature)
230 AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
231 aSubFeature->attribute(SketchPlugin_ConstraintRigid::ENTITY_A()));
232 if (aRefAttr->isObject()) {
233 if (aRefAttr->object() == aRAttr->object()) {
234 ObjectPtr anObject = aRefAttr->object();
235 std::string aName = anObject.get() ? anObject->data()->name() : "";
236 theError = "The object " + aName + " has been already fixed.";
240 else if (aRefAttr->attr() == aRAttr->attr()) {
241 AttributePtr anAttribute = aRefAttr->attr();
242 std::string aName = anAttribute.get() ? anAttribute->id() : "";
243 theError = "The attribute " + aName + " has been already fixed.";
250 bool SketchPlugin_EqualAttrValidator::isValid(const AttributePtr& theAttribute,
251 const std::list<std::string>& theArguments,
252 std::string& theError) const
254 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
255 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
259 std::string aParamA = theArguments.front();
260 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
261 AttributeRefAttrPtr aRefAttr[2];
262 aRefAttr[0] = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
263 aRefAttr[1] = aFeature->data()->refattr(aParamA);
265 if (!aRefAttr[0]->isObject() || !aRefAttr[1]->isObject()) {
266 theError = "Attributes can not be used in equal constraint";
270 int aType[2] = {0, 0}; // types of attributes: 0 - incorrect, 1 - line, 2 - circle, 3 - arc
271 std::list<std::string> anArguments;
272 for (int i = 0; i < 2; i++) {
273 ObjectPtr anObject = aRefAttr[i]->object();
274 if (!anObject.get()) {
275 theError = "An empty object is used.";
279 aFeature = ModelAPI_Feature::feature(anObject);
280 if (!aFeature.get()) {
281 theError = "An empty feature is used.";
285 if (aFeature->getKind() == SketchPlugin_Line::ID()) {
289 if (aFeature->getKind() == SketchPlugin_Circle::ID()) {
293 if (aFeature->getKind() == SketchPlugin_Arc::ID()) {
297 theError = "The " + aFeature->getKind() + " feature kind of attribute is wrong. It should be " +
298 SketchPlugin_Line::ID() + " or " + SketchPlugin_Circle::ID() + " or " +
299 SketchPlugin_Arc::ID();
300 // wrong type of attribute
304 if ((aType[0] == 1 && aType[1] == 2) ||
305 (aType[0] == 2 && aType[1] == 1)) {
306 theError = "Feature with kinds " + SketchPlugin_Line::ID() + " and " +
307 SketchPlugin_Circle::ID() + "can not be equal.";
313 bool SketchPlugin_MirrorAttrValidator::isValid(const AttributePtr& theAttribute,
314 const std::list<std::string>& theArguments,
315 std::string& theError) const
317 if (theAttribute->attributeType() != ModelAPI_AttributeRefList::typeId()) {
318 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
322 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
323 AttributeRefListPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
325 AttributeRefListPtr aRefListOfMirrored = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
326 aFeature->attribute(SketchPlugin_Constraint::ENTITY_C()));
327 std::list<ObjectPtr> aMirroredObjects = aRefListOfMirrored->list();
329 for(int anInd = 0; anInd < aSelAttr->size(); anInd++) {
330 ObjectPtr aSelObject = aSelAttr->object(anInd);
331 std::string aName = aSelObject.get() ? aSelObject->data()->name() : "";
332 std::list<ObjectPtr>::iterator aMirIter = aMirroredObjects.begin();
333 for (; aMirIter != aMirroredObjects.end(); aMirIter++)
334 if (aSelObject == *aMirIter) {
335 theError = "The object " + aName + " is a result of mirror";
342 bool SketchPlugin_CoincidenceAttrValidator::isValid(const AttributePtr& theAttribute,
343 const std::list<std::string>& theArguments,
344 std::string& theError) const
346 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
347 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
351 // there is a check whether the feature contains a point and a linear edge or two point values
352 std::string aParamA = theArguments.front();
353 SessionPtr aMgr = ModelAPI_Session::get();
354 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
356 FeaturePtr aConstraint = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
357 AttributeRefAttrPtr aRefAttrA = aConstraint->data()->refattr(aParamA);
359 theError = "The " + aParamA + " attribute " + " should be " + ModelAPI_AttributeRefAttr::typeId();
363 AttributeRefAttrPtr aRefAttrB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
365 // first attribute is a point, it may coincide with any object
366 if (!aRefAttrA->isObject())
369 ObjectPtr anObject = aRefAttrA->object();
370 if (!anObject.get()) {
371 theError = aParamA + " attribute has an empty object";
374 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrA->object());
375 if (!aFeature.get()) {
376 theError = aParamA + " attribute has an empty feature";
380 if (aFeature->getKind() == SketchPlugin_Point::ID())
384 // second attribute is a point, it may coincide with any object
385 if (!aRefAttrB->isObject())
388 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrB->object());
390 theError = theAttribute->id() + " attribute has an empty object";
393 if (aFeature->getKind() == SketchPlugin_Point::ID())
396 theError = "There is no an attribute filled by a point";
401 bool SketchPlugin_CopyValidator::isValid(const AttributePtr& theAttribute,
402 const std::list<std::string>& theArguments,
403 std::string& theError) const
405 if (theAttribute->attributeType() != ModelAPI_AttributeRefList::typeId()) {
406 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
410 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
411 AttributeRefListPtr aSelAttr =
412 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
414 AttributeRefListPtr aRefListOfInitial = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
415 aFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
416 AttributeRefListPtr aRefListOfCopied = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
417 aFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
418 std::list<ObjectPtr> anInitialObjects = aRefListOfInitial->list();
419 std::list<ObjectPtr> aCopiedObjects = aRefListOfCopied->list();
421 std::list<ObjectPtr>::iterator anObjIter;
422 for(int anInd = 0; anInd < aSelAttr->size(); anInd++) {
423 ObjectPtr aSelObject = aSelAttr->object(anInd);
424 anObjIter = anInitialObjects.begin();
425 for (; anObjIter != anInitialObjects.end(); anObjIter++)
426 if (aSelObject == *anObjIter)
428 if (anObjIter != anInitialObjects.end())
430 anObjIter = aCopiedObjects.begin();
431 for (; anObjIter != aCopiedObjects.end(); anObjIter++)
432 if (aSelObject == *anObjIter) {
433 std::string aName = aSelObject.get() ? aSelObject->data()->name() : "";
434 theError = "The object " + aName + " is a result of copy";
441 bool SketchPlugin_SolverErrorValidator::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
442 const std::list<std::string>& theArguments,
443 std::string& theError) const
445 AttributeStringPtr aAttributeString = theFeature->string(SketchPlugin_Sketch::SOLVER_ERROR());
447 if (!aAttributeString->value().empty()) {
448 theError = aAttributeString->value();
455 bool SketchPlugin_SolverErrorValidator::isNotObligatory(std::string theFeature, std::string theAttribute)
460 bool SketchPlugin_FilletVertexValidator::isValid(const AttributePtr& theAttribute,
461 const std::list<std::string>& theArguments,
462 std::string& theError) const
464 if(!theAttribute.get() || !theAttribute->isInitialized()) {
465 theError = "Error: List of points is not initialized.";
469 FeaturePtr aFilletFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
470 AttributeRefAttrListPtr aPointsRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
471 if(aPointsRefList->size() == 0) {
472 theError = "Error: List of points is empty.";
476 AttributeRefAttrListPtr aBasePointsRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(
477 aFilletFeature->attribute(SketchPlugin_Constraint::ENTITY_C()));
478 AttributeRefListPtr aResultEdgesRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
479 aFilletFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
481 std::list<std::pair<ObjectPtr, AttributePtr>> aPointsList = aPointsRefList->list();
482 for(std::list<std::pair<ObjectPtr, AttributePtr>>::const_iterator anIt = aPointsList.cbegin(); anIt != aPointsList.cend(); anIt++) {
483 ObjectPtr anObject = (*anIt).first;
484 AttributePtr aPointAttribute = (*anIt).second;
486 // If we alredy have some result then:
487 // - if it is the same point all ok, just skip it
488 // - if it is point on the fillet arc then it is not valid
489 if(aBasePointsRefList->size() > 0) {
490 if(aBasePointsRefList->isInList(aPointAttribute)) {
494 // Check that selected point not on the one of the result fillet arc.
495 for(int anIndex = 0; anIndex < aBasePointsRefList->size(); anIndex++) {
496 if(aResultEdgesRefList->size() > 0) {
497 FeaturePtr aResultArc;
498 aResultArc = ModelAPI_Feature::feature(aResultEdgesRefList->object(anIndex * 3 + 2));
499 AttributePtr anArcStart = aResultArc->attribute(SketchPlugin_Arc::START_ID());
500 AttributePtr anArcEnd = aResultArc->attribute(SketchPlugin_Arc::END_ID());
501 std::shared_ptr<GeomAPI_Pnt2d> anArcStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anArcStart)->pnt();
502 std::shared_ptr<GeomAPI_Pnt2d> anArcEndPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anArcEnd)->pnt();
503 std::shared_ptr<GeomAPI_Pnt2d> aSelectedPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aPointAttribute)->pnt();
504 double aDistSelectedArcStart = aSelectedPnt->distance(anArcStartPnt);
505 double aDistSelectedArcEnd = aSelectedPnt->distance(anArcEndPnt);
506 if(aDistSelectedArcStart < tolerance || aDistSelectedArcEnd < tolerance) {
513 // Obtain constraint coincidence for the fillet point.
514 const std::set<AttributePtr>& aRefsList = aPointAttribute->owner()->data()->refsToMe();
515 FeaturePtr aConstraintCoincidence;
516 for(std::set<AttributePtr>::const_iterator anIt = aRefsList.cbegin(); anIt != aRefsList.cend(); ++anIt) {
517 std::shared_ptr<ModelAPI_Attribute> aAttr = (*anIt);
518 FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
519 if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
520 AttributeRefAttrPtr anAttrRefA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
521 aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_A()));
522 AttributeRefAttrPtr anAttrRefB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
523 aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_B()));
524 if(anAttrRefA.get() && !anAttrRefA->isObject()) {
525 AttributePtr anAttrA = anAttrRefA->attr();
526 if(aPointAttribute == anAttrA) {
527 aConstraintCoincidence = aConstrFeature;
531 if(anAttrRefB.get() && !anAttrRefB->isObject()) {
532 AttributePtr anAttrB = anAttrRefB->attr();
533 if(aPointAttribute == anAttrB) {
534 aConstraintCoincidence = aConstrFeature;
541 if(!aConstraintCoincidence.get()) {
542 theError = "Error: one of the selected point does not have coicidence.";
546 // Get coincides from constraint.
547 std::set<FeaturePtr> aCoinsides;
548 SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
549 SketchPlugin_ConstraintCoincidence::ENTITY_A(),
551 SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
552 SketchPlugin_ConstraintCoincidence::ENTITY_B(),
555 // Remove points from set of coincides.
556 std::set<FeaturePtr> aNewSetOfCoincides;
557 for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin(); anIt != aCoinsides.end(); ++anIt) {
558 if((*anIt)->getKind() == SketchPlugin_Line::ID() ||
559 (*anIt)->getKind() == SketchPlugin_Arc::ID()) {
560 aNewSetOfCoincides.insert(*anIt);
563 aCoinsides = aNewSetOfCoincides;
565 // If we still have more than two coincides remove auxilary entities from set of coincides.
566 if(aCoinsides.size() > 2) {
567 aNewSetOfCoincides.clear();
568 for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin(); anIt != aCoinsides.end(); ++anIt) {
569 if(!(*anIt)->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value()) {
570 aNewSetOfCoincides.insert(*anIt);
573 aCoinsides = aNewSetOfCoincides;
576 if(aCoinsides.size() != 2) {
577 theError = ("Error: One of the selected points does not have two suitable edges for fillet.");
581 // Check that lines not collinear
582 std::set<FeaturePtr>::iterator anIt = aCoinsides.begin();
583 FeaturePtr aFirstFeature = *anIt++;
584 FeaturePtr aSecondFeature = *anIt;
585 if(aFirstFeature->getKind() == SketchPlugin_Line::ID() && aSecondFeature->getKind() == SketchPlugin_Line::ID()) {
586 std::string aStartAttr = SketchPlugin_Line::START_ID();
587 std::string anEndAttr = SketchPlugin_Line::END_ID();
588 std::shared_ptr<GeomAPI_Pnt2d> aFirstStartPnt, aFirstEndPnt, aSecondStartPnt, aSecondEndPnt;
589 aFirstStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFirstFeature->attribute(aStartAttr))->pnt();
590 aFirstEndPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFirstFeature->attribute(anEndAttr))->pnt();
591 aSecondStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aSecondFeature->attribute(aStartAttr))->pnt();
592 aSecondEndPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aSecondFeature->attribute(anEndAttr))->pnt();
593 double aCheck1 = abs((aFirstEndPnt->x() - aFirstStartPnt->x()) * (aSecondStartPnt->y() - aFirstStartPnt->y()) -
594 (aSecondStartPnt->x() - aFirstStartPnt->x()) * (aFirstEndPnt->y() - aFirstStartPnt->y()));
595 double aCheck2 = abs((aFirstEndPnt->x() - aFirstStartPnt->x()) * (aSecondEndPnt->y() - aFirstStartPnt->y()) -
596 (aSecondEndPnt->x() - aFirstStartPnt->x()) * (aFirstEndPnt->y() - aFirstStartPnt->y()));
597 if(aCheck1 < 1.e-7 && aCheck2 < 1.e-7) {
606 bool SketchPlugin_MiddlePointAttrValidator::isValid(const AttributePtr& theAttribute,
607 const std::list<std::string>& theArguments,
608 std::string& theError) const
610 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
611 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
615 // there is a check whether the feature contains a point and a linear edge or two point values
616 std::string aParamA = theArguments.front();
617 SessionPtr aMgr = ModelAPI_Session::get();
618 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
620 FeaturePtr anAttributeFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
621 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
622 AttributeRefAttrPtr anOtherAttr = anAttributeFeature->data()->refattr(aParamA);
624 AttributeRefAttrPtr aRefAttrs[2] = {aRefAttr, anOtherAttr};
627 for (int i = 0; i < 2; ++i) {
628 if (!aRefAttrs[i]->isObject())
631 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrs[i]->object());
633 if (aNbPoints + aNbLines != 0)
638 if (aFeature->getKind() == SketchPlugin_Point::ID())
640 else if (aFeature->getKind() == SketchPlugin_Line::ID())
645 if (aNbPoints != 1 || aNbLines != 1) {
646 theError = "Middle point constraint allows points and lines only";