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 int aType[2] = {0, 0}; // types of attributes: 0 - incorrect, 1 - line, 2 - circle, 3 - arc
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 if (aFeature->getKind() == SketchPlugin_Line::ID()) {
291 if (aFeature->getKind() == SketchPlugin_Circle::ID()) {
295 if (aFeature->getKind() == SketchPlugin_Arc::ID()) {
299 theError = "The " + aFeature->getKind() + " feature kind of attribute is wrong. It should be " +
300 SketchPlugin_Line::ID() + " or " + SketchPlugin_Circle::ID() + " or " +
301 SketchPlugin_Arc::ID();
302 // wrong type of attribute
306 if ((aType[0] == 1 && aType[1] == 2) ||
307 (aType[0] == 2 && aType[1] == 1)) {
308 theError = "Feature with kinds " + SketchPlugin_Line::ID() + " and " +
309 SketchPlugin_Circle::ID() + "can not be equal.";
315 bool SketchPlugin_MirrorAttrValidator::isValid(const AttributePtr& theAttribute,
316 const std::list<std::string>& theArguments,
317 std::string& theError) const
319 if (theAttribute->attributeType() != ModelAPI_AttributeRefList::typeId()) {
320 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
324 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
325 AttributeRefListPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
327 AttributeRefListPtr aRefListOfMirrored = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
328 aFeature->attribute(SketchPlugin_Constraint::ENTITY_C()));
329 std::list<ObjectPtr> aMirroredObjects = aRefListOfMirrored->list();
331 for(int anInd = 0; anInd < aSelAttr->size(); anInd++) {
332 ObjectPtr aSelObject = aSelAttr->object(anInd);
333 std::string aName = aSelObject.get() ? aSelObject->data()->name() : "";
334 std::list<ObjectPtr>::iterator aMirIter = aMirroredObjects.begin();
335 for (; aMirIter != aMirroredObjects.end(); aMirIter++)
336 if (aSelObject == *aMirIter) {
337 theError = "The object " + aName + " is a result of mirror";
344 bool SketchPlugin_CoincidenceAttrValidator::isValid(const AttributePtr& theAttribute,
345 const std::list<std::string>& theArguments,
346 std::string& theError) const
348 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
349 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
353 // there is a check whether the feature contains a point and a linear edge or two point values
354 std::string aParamA = theArguments.front();
355 SessionPtr aMgr = ModelAPI_Session::get();
356 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
358 FeaturePtr aConstraint = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
359 AttributeRefAttrPtr aRefAttrA = aConstraint->data()->refattr(aParamA);
361 theError = "The " + aParamA + " attribute " + " should be " + ModelAPI_AttributeRefAttr::typeId();
365 AttributeRefAttrPtr aRefAttrB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
367 // first attribute is a point, it may coincide with any object
368 if (!aRefAttrA->isObject())
371 ObjectPtr anObject = aRefAttrA->object();
372 if (!anObject.get()) {
373 theError = aParamA + " attribute has an empty object";
376 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrA->object());
377 if (!aFeature.get()) {
378 theError = aParamA + " attribute has an empty feature";
382 if (aFeature->getKind() == SketchPlugin_Point::ID())
386 // second attribute is a point, it may coincide with any object
387 if (!aRefAttrB->isObject())
390 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrB->object());
392 theError = theAttribute->id() + " attribute has an empty object";
395 if (aFeature->getKind() == SketchPlugin_Point::ID())
398 theError = "There is no an attribute filled by a point";
403 bool SketchPlugin_CopyValidator::isValid(const AttributePtr& theAttribute,
404 const std::list<std::string>& theArguments,
405 std::string& theError) const
407 if (theAttribute->attributeType() != ModelAPI_AttributeRefList::typeId()) {
408 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
412 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
413 AttributeRefListPtr aSelAttr =
414 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
416 AttributeRefListPtr aRefListOfInitial = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
417 aFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
418 AttributeRefListPtr aRefListOfCopied = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
419 aFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
420 std::list<ObjectPtr> anInitialObjects = aRefListOfInitial->list();
421 std::list<ObjectPtr> aCopiedObjects = aRefListOfCopied->list();
423 std::list<ObjectPtr>::iterator anObjIter;
424 for(int anInd = 0; anInd < aSelAttr->size(); anInd++) {
425 ObjectPtr aSelObject = aSelAttr->object(anInd);
426 anObjIter = anInitialObjects.begin();
427 for (; anObjIter != anInitialObjects.end(); anObjIter++)
428 if (aSelObject == *anObjIter)
430 if (anObjIter != anInitialObjects.end())
432 anObjIter = aCopiedObjects.begin();
433 for (; anObjIter != aCopiedObjects.end(); anObjIter++)
434 if (aSelObject == *anObjIter) {
435 std::string aName = aSelObject.get() ? aSelObject->data()->name() : "";
436 theError = "The object " + aName + " is a result of copy";
443 bool SketchPlugin_SolverErrorValidator::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
444 const std::list<std::string>& theArguments,
445 std::string& theError) const
447 AttributeStringPtr aAttributeString = theFeature->string(SketchPlugin_Sketch::SOLVER_ERROR());
449 if (!aAttributeString->value().empty()) {
450 theError = aAttributeString->value();
457 bool SketchPlugin_SolverErrorValidator::isNotObligatory(std::string theFeature, std::string theAttribute)
462 bool SketchPlugin_FilletVertexValidator::isValid(const AttributePtr& theAttribute,
463 const std::list<std::string>& theArguments,
464 std::string& theError) const
466 if(!theAttribute.get() || !theAttribute->isInitialized()) {
467 theError = "Error: List of points is not initialized.";
471 FeaturePtr aFilletFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
472 AttributeRefAttrListPtr aPointsRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
473 if(aPointsRefList->size() == 0) {
474 theError = "Error: List of points is empty.";
478 AttributeRefAttrListPtr aBasePointsRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(
479 aFilletFeature->attribute(SketchPlugin_Constraint::ENTITY_C()));
480 AttributeRefListPtr aResultEdgesRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
481 aFilletFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
483 std::list<std::pair<ObjectPtr, AttributePtr>> aPointsList = aPointsRefList->list();
484 for(std::list<std::pair<ObjectPtr, AttributePtr>>::const_iterator anIt = aPointsList.cbegin(); anIt != aPointsList.cend(); anIt++) {
485 ObjectPtr anObject = (*anIt).first;
486 AttributePtr aPointAttribute = (*anIt).second;
488 // If we alredy have some result then:
489 // - if it is the same point all ok, just skip it
490 // - if it is point on the fillet arc then it is not valid
491 if(aBasePointsRefList->size() > 0) {
492 if(aBasePointsRefList->isInList(aPointAttribute)) {
496 // Check that selected point not on the one of the result fillet arc.
497 for(int anIndex = 0; anIndex < aBasePointsRefList->size(); anIndex++) {
498 if(aResultEdgesRefList->size() > 0) {
499 FeaturePtr aResultArc;
500 aResultArc = ModelAPI_Feature::feature(aResultEdgesRefList->object(anIndex * 3 + 2));
501 AttributePtr anArcStart = aResultArc->attribute(SketchPlugin_Arc::START_ID());
502 AttributePtr anArcEnd = aResultArc->attribute(SketchPlugin_Arc::END_ID());
503 std::shared_ptr<GeomAPI_Pnt2d> anArcStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anArcStart)->pnt();
504 std::shared_ptr<GeomAPI_Pnt2d> anArcEndPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anArcEnd)->pnt();
505 std::shared_ptr<GeomAPI_Pnt2d> aSelectedPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aPointAttribute)->pnt();
506 double aDistSelectedArcStart = aSelectedPnt->distance(anArcStartPnt);
507 double aDistSelectedArcEnd = aSelectedPnt->distance(anArcEndPnt);
508 if(aDistSelectedArcStart < tolerance || aDistSelectedArcEnd < tolerance) {
515 // Obtain constraint coincidence for the fillet point.
516 const std::set<AttributePtr>& aRefsList = aPointAttribute->owner()->data()->refsToMe();
517 FeaturePtr aConstraintCoincidence;
518 for(std::set<AttributePtr>::const_iterator anIt = aRefsList.cbegin(); anIt != aRefsList.cend(); ++anIt) {
519 std::shared_ptr<ModelAPI_Attribute> aAttr = (*anIt);
520 FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
521 if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
522 AttributeRefAttrPtr anAttrRefA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
523 aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_A()));
524 AttributeRefAttrPtr anAttrRefB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
525 aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_B()));
526 if(anAttrRefA.get() && !anAttrRefA->isObject()) {
527 AttributePtr anAttrA = anAttrRefA->attr();
528 if(aPointAttribute == anAttrA) {
529 aConstraintCoincidence = aConstrFeature;
533 if(anAttrRefB.get() && !anAttrRefB->isObject()) {
534 AttributePtr anAttrB = anAttrRefB->attr();
535 if(aPointAttribute == anAttrB) {
536 aConstraintCoincidence = aConstrFeature;
543 if(!aConstraintCoincidence.get()) {
544 theError = "Error: one of the selected point does not have coicidence.";
548 // Get coincides from constraint.
549 std::set<FeaturePtr> aCoinsides;
550 SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
551 SketchPlugin_ConstraintCoincidence::ENTITY_A(),
553 SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
554 SketchPlugin_ConstraintCoincidence::ENTITY_B(),
557 // Remove points from set of coincides.
558 std::set<FeaturePtr> aNewSetOfCoincides;
559 for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin(); anIt != aCoinsides.end(); ++anIt) {
560 if((*anIt)->getKind() == SketchPlugin_Line::ID() ||
561 (*anIt)->getKind() == SketchPlugin_Arc::ID()) {
562 aNewSetOfCoincides.insert(*anIt);
565 aCoinsides = aNewSetOfCoincides;
567 // If we still have more than two coincides remove auxilary entities from set of coincides.
568 if(aCoinsides.size() > 2) {
569 aNewSetOfCoincides.clear();
570 for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin(); anIt != aCoinsides.end(); ++anIt) {
571 if(!(*anIt)->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value()) {
572 aNewSetOfCoincides.insert(*anIt);
575 aCoinsides = aNewSetOfCoincides;
578 if(aCoinsides.size() != 2) {
579 theError = ("Error: One of the selected points does not have two suitable edges for fillet.");
583 // Check that lines not collinear
584 std::set<FeaturePtr>::iterator anIt = aCoinsides.begin();
585 FeaturePtr aFirstFeature = *anIt++;
586 FeaturePtr aSecondFeature = *anIt;
587 if(aFirstFeature->getKind() == SketchPlugin_Line::ID() && aSecondFeature->getKind() == SketchPlugin_Line::ID()) {
588 std::string aStartAttr = SketchPlugin_Line::START_ID();
589 std::string anEndAttr = SketchPlugin_Line::END_ID();
590 std::shared_ptr<GeomAPI_Pnt2d> aFirstStartPnt, aFirstEndPnt, aSecondStartPnt, aSecondEndPnt;
591 aFirstStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFirstFeature->attribute(aStartAttr))->pnt();
592 aFirstEndPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFirstFeature->attribute(anEndAttr))->pnt();
593 aSecondStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aSecondFeature->attribute(aStartAttr))->pnt();
594 aSecondEndPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aSecondFeature->attribute(anEndAttr))->pnt();
595 double aCheck1 = abs((aFirstEndPnt->x() - aFirstStartPnt->x()) * (aSecondStartPnt->y() - aFirstStartPnt->y()) -
596 (aSecondStartPnt->x() - aFirstStartPnt->x()) * (aFirstEndPnt->y() - aFirstStartPnt->y()));
597 double aCheck2 = abs((aFirstEndPnt->x() - aFirstStartPnt->x()) * (aSecondEndPnt->y() - aFirstStartPnt->y()) -
598 (aSecondEndPnt->x() - aFirstStartPnt->x()) * (aFirstEndPnt->y() - aFirstStartPnt->y()));
599 if(aCheck1 < 1.e-7 && aCheck2 < 1.e-7) {
608 bool SketchPlugin_MiddlePointAttrValidator::isValid(const AttributePtr& theAttribute,
609 const std::list<std::string>& theArguments,
610 std::string& theError) const
612 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
613 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
617 // there is a check whether the feature contains a point and a linear edge or two point values
618 std::string aParamA = theArguments.front();
619 SessionPtr aMgr = ModelAPI_Session::get();
620 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
622 FeaturePtr anAttributeFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
623 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
624 AttributeRefAttrPtr anOtherAttr = anAttributeFeature->data()->refattr(aParamA);
626 AttributeRefAttrPtr aRefAttrs[2] = {aRefAttr, anOtherAttr};
629 for (int i = 0; i < 2; ++i) {
630 if (!aRefAttrs[i]->isObject())
633 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrs[i]->object());
635 if (aNbPoints + aNbLines != 0)
640 if (aFeature->getKind() == SketchPlugin_Point::ID())
642 else if (aFeature->getKind() == SketchPlugin_Line::ID())
647 if (aNbPoints != 1 || aNbLines != 1) {
648 theError = "Middle point constraint allows points and lines only";