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_ConstraintFillet.h"
14 #include "SketchPlugin_ConstraintRigid.h"
15 #include "SketchPlugin_Line.h"
16 #include "SketchPlugin_Point.h"
17 #include "SketchPlugin_Sketch.h"
18 #include "SketchPlugin_Tools.h"
20 #include "SketcherPrs_Tools.h"
22 #include <ModelAPI_Data.h>
23 #include <ModelAPI_Validator.h>
24 #include <ModelAPI_AttributeDouble.h>
25 #include <ModelAPI_AttributeRefAttr.h>
27 #include <ModelAPI_AttributeRefAttrList.h>
28 #include <ModelAPI_AttributeRefList.h>
29 #include <ModelAPI_AttributeSelectionList.h>
30 #include <ModelAPI_AttributeString.h>
31 #include <ModelAPI_Session.h>
32 #include <ModelAPI_ResultConstruction.h>
34 #include <GeomAPI_Lin.h>
35 #include <GeomAPI_Edge.h>
36 #include <GeomAPI_Vertex.h>
37 #include <GeomDataAPI_Point2D.h>
42 const double tolerance = 1.e-7;
44 bool SketchPlugin_DistanceAttrValidator::isValid(const AttributePtr& theAttribute,
45 const std::list<std::string>& theArguments,
46 std::string& theError) const
48 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
49 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
53 // there is a check whether the feature contains a point and a linear edge or two point values
54 std::string aParamA = theArguments.front();
55 SessionPtr aMgr = ModelAPI_Session::get();
56 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
58 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
59 bool isObject = aRefAttr->isObject();
61 // an attribute is a point. A point value is valid always for the distance
64 // 1. check whether the references object is a linear
65 ObjectPtr anObject = aRefAttr->object();
67 const ModelAPI_AttributeValidator* aShapeValidator =
68 dynamic_cast<const ModelAPI_AttributeValidator*>(aFactory->validator("GeomValidators_ShapeType"));
69 std::list<std::string> anArguments;
70 anArguments.push_back("circle");
71 std::string aCircleError;
72 bool aShapeValid = aShapeValidator->isValid(aRefAttr, anArguments, aCircleError);
73 // the circle line is not a valid case
75 theError = "Circle can not be used in distance constraint";
80 anArguments.push_back("line");
81 std::string aLineError;
82 aShapeValid = aShapeValidator->isValid(aRefAttr, anArguments, aLineError);
83 // if the attribute value is not a line, that means it is a vertex. A vertex is always valid
85 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
86 // If it is a line then we have to check that first attribute id not a line
87 std::shared_ptr<SketchPlugin_Feature> aSFeature =
88 std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
89 SketchPlugin_Sketch* aSketch = aSFeature->sketch();
90 std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(aSketch);
91 std::shared_ptr<GeomDataAPI_Point2D> aPoint = SketcherPrs_Tools::getFeaturePoint(
92 aFeature->data(), aParamA, aPlane);
94 theError = "One of parameters of distance constraint should be a point";
103 static bool hasCoincidentPoint(FeaturePtr theFeature1, FeaturePtr theFeature2)
105 FeaturePtr aConstrFeature;
106 std::list<AttributePtr> anAttrList;
107 if (theFeature1->getKind() == SketchPlugin_Circle::ID() ||
108 theFeature2->getKind() == SketchPlugin_Circle::ID())
110 if (theFeature2->getKind() == SketchPlugin_Line::ID()) {
111 anAttrList.push_back(theFeature2->attribute(SketchPlugin_Line::START_ID()));
112 anAttrList.push_back(theFeature2->attribute(SketchPlugin_Line::END_ID()));
113 } else if (theFeature2->getKind() == SketchPlugin_Arc::ID()) {
114 anAttrList.push_back(theFeature2->attribute(SketchPlugin_Arc::START_ID()));
115 anAttrList.push_back(theFeature2->attribute(SketchPlugin_Arc::END_ID()));
118 const std::set<AttributePtr>& aRefsList = theFeature1->data()->refsToMe();
119 std::set<AttributePtr>::const_iterator aRefIt = aRefsList.begin();
120 for (; aRefIt != aRefsList.end(); ++aRefIt) {
121 aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRefIt)->owner());
122 if (aConstrFeature->getKind() != SketchPlugin_ConstraintCoincidence::ID())
124 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*aRefIt);
125 AttributePtr anAttr = aRefAttr->attr();
126 if (anAttr->id() == SketchPlugin_Arc::CENTER_ID())
129 anAttr = aConstrFeature->attribute(SketchPlugin_Constraint::ENTITY_A());
130 if (anAttr == *aRefIt)
131 anAttr = aConstrFeature->attribute(SketchPlugin_Constraint::ENTITY_B());
133 aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttr);
136 anAttr = aRefAttr->attr();
137 for (std::list<AttributePtr>::const_iterator anIt = anAttrList.begin();
138 anIt != anAttrList.end(); ++anIt)
145 bool SketchPlugin_TangentAttrValidator::isValid(const AttributePtr& theAttribute,
146 const std::list<std::string>& theArguments,
147 std::string& theError) const
149 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
150 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
154 // there is a check whether the feature contains a point and a linear edge or two point values
155 std::string aParamA = theArguments.front();
156 SessionPtr aMgr = ModelAPI_Session::get();
157 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
159 FeaturePtr anAttributeFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
160 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
162 bool isObject = aRefAttr->isObject();
163 ObjectPtr anObject = aRefAttr->object();
164 if (isObject && anObject.get()) {
165 FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject);
167 AttributeRefAttrPtr aOtherAttr = anAttributeFeature->data()->refattr(aParamA);
168 ObjectPtr aOtherObject = aOtherAttr->object();
169 FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject);
173 if ((aRefFea->getKind() == SketchPlugin_Arc::ID() ||
174 aOtherFea->getKind() == SketchPlugin_Arc::ID()) &&
175 !hasCoincidentPoint(aRefFea, aOtherFea))
178 if (aRefFea->getKind() == SketchPlugin_Line::ID()) {
179 if (aOtherFea->getKind() != SketchPlugin_Arc::ID() &&
180 aOtherFea->getKind() != SketchPlugin_Circle::ID()) {
181 theError = "It refers to a " + SketchPlugin_Line::ID() + ", but " + aParamA + " is neither an "
182 + SketchPlugin_Arc::ID() + " nor " + SketchPlugin_Circle::ID();
186 else if (aRefFea->getKind() == SketchPlugin_Arc::ID()) {
187 if (aOtherFea->getKind() != SketchPlugin_Line::ID() &&
188 aOtherFea->getKind() != SketchPlugin_Arc::ID()) {
189 theError = "It refers to an " + SketchPlugin_Arc::ID() + ", but " + aParamA + " is not a "
190 + SketchPlugin_Line::ID() + " or an " + SketchPlugin_Arc::ID();
194 else if (aRefFea->getKind() == SketchPlugin_Circle::ID()) {
195 if (aOtherFea->getKind() != SketchPlugin_Line::ID()) {
196 theError = "It refers to an " + SketchPlugin_Circle::ID() + ", but " + aParamA + " is not a "
197 + SketchPlugin_Line::ID();
202 theError = "It refers to " + aRefFea->getKind() + ", but should refer to " + SketchPlugin_Line::ID()
203 + " or " + SketchPlugin_Arc::ID() + " or " + SketchPlugin_Circle::ID();
209 theError = "It uses an empty object";
216 bool SketchPlugin_NotFixedValidator::isValid(const AttributePtr& theAttribute,
217 const std::list<std::string>& theArguments,
218 std::string& theError) const
220 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
221 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
225 std::shared_ptr<SketchPlugin_Feature> aFeature =
226 std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
230 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
232 SketchPlugin_Sketch* aSketch = aFeature->sketch();
233 int aNbFeatures = aSketch->numberOfSubs();
234 for (int anInd = 0; anInd < aNbFeatures; anInd++) {
235 FeaturePtr aSubFeature = aSketch->subFeature(anInd);
236 if (aSubFeature->getKind() != SketchPlugin_ConstraintRigid::ID() || aSubFeature == aFeature)
238 AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
239 aSubFeature->attribute(SketchPlugin_ConstraintRigid::ENTITY_A()));
240 if (aRefAttr->isObject()) {
241 if (aRefAttr->object() == aRAttr->object()) {
242 ObjectPtr anObject = aRefAttr->object();
243 std::string aName = anObject.get() ? anObject->data()->name() : "";
244 theError = "The object " + aName + " has been already fixed.";
248 else if (aRefAttr->attr() == aRAttr->attr()) {
249 AttributePtr anAttribute = aRefAttr->attr();
250 std::string aName = anAttribute.get() ? anAttribute->id() : "";
251 theError = "The attribute " + aName + " has been already fixed.";
258 bool SketchPlugin_EqualAttrValidator::isValid(const AttributePtr& theAttribute,
259 const std::list<std::string>& theArguments,
260 std::string& theError) const
262 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
263 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
267 std::string aParamA = theArguments.front();
268 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
269 AttributeRefAttrPtr aRefAttr[2];
270 aRefAttr[0] = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
271 aRefAttr[1] = aFeature->data()->refattr(aParamA);
273 if (!aRefAttr[0]->isObject() || !aRefAttr[1]->isObject()) {
274 theError = "Attributes can not be used in equal constraint";
278 std::string aType[2];
279 std::list<std::string> anArguments;
280 for (int i = 0; i < 2; i++) {
281 ObjectPtr anObject = aRefAttr[i]->object();
282 if (!anObject.get()) {
283 theError = "An empty object is used.";
287 aFeature = ModelAPI_Feature::feature(anObject);
288 if (!aFeature.get()) {
289 theError = "An empty feature is used.";
293 aType[i] = aFeature->getKind();
294 if (aFeature->getKind() != SketchPlugin_Line::ID() &&
295 aFeature->getKind() != SketchPlugin_Circle::ID() &&
296 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
305 if ((aType[0] == SketchPlugin_Line::ID() || aType[1] == SketchPlugin_Line::ID()) &&
306 aType[0] != aType[1]) {
307 theError = "Feature with kinds " + aType[0] + " and " + aType[1] + "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 std::shared_ptr<SketchPlugin_ConstraintFillet> aFilletFeature = std::dynamic_pointer_cast<SketchPlugin_ConstraintFillet>(theAttribute->owner());
465 AttributeRefAttrListPtr aPointsRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
466 if(aPointsRefList->size() == 0) {
467 theError = "Error: List of points is empty.";
471 std::map<AttributePtr, SketchPlugin_ConstraintFillet::FilletFeatures> aPointsFeaturesMap = aFilletFeature->pointsFeaturesMap();
472 std::set<AttributePtr> aSetOfPointsOnResultEdges;
473 for(std::map<AttributePtr, SketchPlugin_ConstraintFillet::FilletFeatures>::iterator aPointsIter = aPointsFeaturesMap.begin();
474 aPointsIter != aPointsFeaturesMap.end();
476 const SketchPlugin_ConstraintFillet::FilletFeatures& aFeatures = aPointsIter->second;
477 const std::list<FeaturePtr>& aResultEdges = aFeatures.resultEdges;
478 for(std::list<FeaturePtr>::const_iterator aResultIter = aResultEdges.cbegin();
479 aResultIter != aResultEdges.cend();
481 FeaturePtr aResultFeature = *aResultIter;
482 if(aResultFeature->getKind() == SketchPlugin_Line::ID()) {
483 aSetOfPointsOnResultEdges.insert(aResultFeature->attribute(SketchPlugin_Line::START_ID()));
484 aSetOfPointsOnResultEdges.insert(aResultFeature->attribute(SketchPlugin_Line::END_ID()));
485 } else if(aResultFeature->getKind() == SketchPlugin_Arc::ID()) {
486 aSetOfPointsOnResultEdges.insert(aResultFeature->attribute(SketchPlugin_Arc::START_ID()));
487 aSetOfPointsOnResultEdges.insert(aResultFeature->attribute(SketchPlugin_Arc::END_ID()));
492 std::list<std::pair<ObjectPtr, AttributePtr>> aPointsList = aPointsRefList->list();
493 for(std::list<std::pair<ObjectPtr, AttributePtr>>::const_iterator aPointsIt = aPointsList.cbegin(); aPointsIt != aPointsList.cend(); aPointsIt++) {
494 ObjectPtr anObject = (*aPointsIt).first;
495 AttributePtr aPointAttribute = (*aPointsIt).second;
496 std::shared_ptr<GeomAPI_Pnt2d> aSelectedPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aPointAttribute)->pnt();
498 // If we alredy have some result then:
499 // - if it is the same point all ok, just skip it
500 // - if it is point on the fillet result edge then it is not valid
501 if(!aPointsFeaturesMap.empty()) {
502 if(aPointsFeaturesMap.find(aPointAttribute) != aPointsFeaturesMap.end()) {
506 // Check that selected point not on the one of the fillet result edge.
507 if(aSetOfPointsOnResultEdges.find(aPointAttribute) != aSetOfPointsOnResultEdges.end()) {
512 // Obtain constraint coincidence for the fillet point.
513 const std::set<AttributePtr>& aRefsList = aPointAttribute->owner()->data()->refsToMe();
514 FeaturePtr aConstraintCoincidence;
515 for(std::set<AttributePtr>::const_iterator anIt = aRefsList.cbegin(); anIt != aRefsList.cend(); ++anIt) {
516 std::shared_ptr<ModelAPI_Attribute> aAttr = (*anIt);
517 FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
518 if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
519 AttributeRefAttrPtr anAttrRefA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
520 aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_A()));
521 AttributeRefAttrPtr anAttrRefB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
522 aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_B()));
523 if(anAttrRefA.get() && !anAttrRefA->isObject()) {
524 AttributePtr anAttrA = anAttrRefA->attr();
525 if(aPointAttribute == anAttrA) {
526 aConstraintCoincidence = aConstrFeature;
530 if(anAttrRefB.get() && !anAttrRefB->isObject()) {
531 AttributePtr anAttrB = anAttrRefB->attr();
532 if(aPointAttribute == anAttrB) {
533 aConstraintCoincidence = aConstrFeature;
540 if(!aConstraintCoincidence.get()) {
541 theError = "Error: one of the selected point does not have coicidence.";
545 // Get coincides from constraint.
546 std::set<FeaturePtr> aCoinsides;
547 SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
548 SketchPlugin_ConstraintCoincidence::ENTITY_A(),
550 SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
551 SketchPlugin_ConstraintCoincidence::ENTITY_B(),
554 // Remove points from set of coincides.
555 std::set<FeaturePtr> aNewSetOfCoincides;
556 for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin(); anIt != aCoinsides.end(); ++anIt) {
557 if((*anIt)->getKind() != SketchPlugin_Line::ID() &&
558 (*anIt)->getKind() != SketchPlugin_Arc::ID()) {
561 if((*anIt)->getKind() == SketchPlugin_Arc::ID()) {
562 AttributePtr anArcCenter = (*anIt)->attribute(SketchPlugin_Arc::CENTER_ID());
563 std::shared_ptr<GeomAPI_Pnt2d> anArcCenterPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anArcCenter)->pnt();
564 double aDistSelectedArcCenter = aSelectedPnt->distance(anArcCenterPnt);
565 if(aDistSelectedArcCenter < tolerance) {
569 aNewSetOfCoincides.insert(*anIt);
571 aCoinsides = aNewSetOfCoincides;
573 // If we still have more than two coincides remove auxilary entities from set of coincides.
574 if(aCoinsides.size() > 2) {
575 aNewSetOfCoincides.clear();
576 for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin(); anIt != aCoinsides.end(); ++anIt) {
577 if(!(*anIt)->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value()) {
578 aNewSetOfCoincides.insert(*anIt);
581 aCoinsides = aNewSetOfCoincides;
584 if(aCoinsides.size() != 2) {
585 theError = ("Error: One of the selected points does not have two suitable edges for fillet.");
589 // Check that lines not collinear
590 std::set<FeaturePtr>::iterator anIt = aCoinsides.begin();
591 FeaturePtr aFirstFeature = *anIt++;
592 FeaturePtr aSecondFeature = *anIt;
593 if(aFirstFeature->getKind() == SketchPlugin_Line::ID() && aSecondFeature->getKind() == SketchPlugin_Line::ID()) {
594 std::string aStartAttr = SketchPlugin_Line::START_ID();
595 std::string anEndAttr = SketchPlugin_Line::END_ID();
596 std::shared_ptr<GeomAPI_Pnt2d> aFirstStartPnt, aFirstEndPnt, aSecondStartPnt, aSecondEndPnt;
597 aFirstStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFirstFeature->attribute(aStartAttr))->pnt();
598 aFirstEndPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFirstFeature->attribute(anEndAttr))->pnt();
599 aSecondStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aSecondFeature->attribute(aStartAttr))->pnt();
600 aSecondEndPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aSecondFeature->attribute(anEndAttr))->pnt();
601 double aCheck1 = abs((aFirstEndPnt->x() - aFirstStartPnt->x()) * (aSecondStartPnt->y() - aFirstStartPnt->y()) -
602 (aSecondStartPnt->x() - aFirstStartPnt->x()) * (aFirstEndPnt->y() - aFirstStartPnt->y()));
603 double aCheck2 = abs((aFirstEndPnt->x() - aFirstStartPnt->x()) * (aSecondEndPnt->y() - aFirstStartPnt->y()) -
604 (aSecondEndPnt->x() - aFirstStartPnt->x()) * (aFirstEndPnt->y() - aFirstStartPnt->y()));
605 if(aCheck1 < 1.e-7 && aCheck2 < 1.e-7) {
614 bool SketchPlugin_MiddlePointAttrValidator::isValid(const AttributePtr& theAttribute,
615 const std::list<std::string>& theArguments,
616 std::string& theError) const
618 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
619 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
623 // there is a check whether the feature contains a point and a linear edge or two point values
624 std::string aParamA = theArguments.front();
625 SessionPtr aMgr = ModelAPI_Session::get();
626 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
628 FeaturePtr anAttributeFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
629 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
630 AttributeRefAttrPtr anOtherAttr = anAttributeFeature->data()->refattr(aParamA);
632 AttributeRefAttrPtr aRefAttrs[2] = {aRefAttr, anOtherAttr};
635 for (int i = 0; i < 2; ++i) {
636 if (!aRefAttrs[i]->isObject())
639 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrs[i]->object());
641 if (aNbPoints + aNbLines != 0)
646 if (aFeature->getKind() == SketchPlugin_Point::ID())
648 else if (aFeature->getKind() == SketchPlugin_Line::ID())
653 if (aNbPoints != 1 || aNbLines != 1) {
654 theError = "Middle point constraint allows points and lines only";
660 bool SketchPlugin_ArcTangentPointValidator::isValid(const AttributePtr& theAttribute,
661 const std::list<std::string>& /*theArguments*/,
662 std::string& theError) const
664 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
665 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
668 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
669 AttributePtr anAttr = aRefAttr->attr();
671 theError = "The attribute " + theAttribute->id() + " should be a point";
675 FeaturePtr anAttrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->owner());
676 const std::string& aFeatureType = anAttrFeature->getKind();
677 if (aFeatureType == SketchPlugin_Arc::ID()) {
678 // selected point should not be a center of arc
679 const std::string& aPntId = anAttr->id();
680 if (aPntId != SketchPlugin_Arc::START_ID() && aPntId != SketchPlugin_Arc::END_ID()) {
681 theError = "The attribute " + aPntId + " is not supported";
685 else if (aFeatureType == SketchPlugin_Line::ID()) {
686 // selected point should be bound point of line
687 const std::string& aPntId = anAttr->id();
688 if (aPntId != SketchPlugin_Line::START_ID() && aPntId != SketchPlugin_Line::END_ID()) {
689 theError = "The attribute " + aPntId + " is not supported";
694 theError = "Unable to build tangent arc on " + anAttrFeature->getKind();
701 bool SketchPlugin_IntersectionValidator::isValid(const AttributePtr& theAttribute,
702 const std::list<std::string>& theArguments,
703 std::string& theError) const
705 if (theAttribute->attributeType() != ModelAPI_AttributeSelection::typeId()) {
706 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
709 AttributeSelectionPtr aLineAttr =
710 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
711 std::shared_ptr<GeomAPI_Edge> anEdge;
712 if(aLineAttr && aLineAttr->value() && aLineAttr->value()->isEdge()) {
713 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aLineAttr->value()));
714 } else if(aLineAttr->context() && aLineAttr->context()->shape() && aLineAttr->context()->shape()->isEdge()) {
715 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aLineAttr->context()->shape()));
718 if (!anEdge || !anEdge->isLine()) {
719 theError = "The attribute " + theAttribute->id() + " should be a line";
723 std::shared_ptr<GeomAPI_Dir> aLineDir = anEdge->line()->direction();
726 std::shared_ptr<SketchPlugin_Sketch> aSketch;
727 std::set<AttributePtr> aRefs = aLineAttr->owner()->data()->refsToMe();
728 std::set<AttributePtr>::const_iterator anIt = aRefs.begin();
729 for (; anIt != aRefs.end(); ++anIt) {
730 CompositeFeaturePtr aComp =
731 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>((*anIt)->owner());
732 if (aComp && aComp->getKind() == SketchPlugin_Sketch::ID()) {
733 aSketch = std::dynamic_pointer_cast<SketchPlugin_Sketch>(aComp);
738 theError = "There is no sketch referring to the current feature";
742 std::shared_ptr<GeomAPI_Pln> aPlane = aSketch->plane();
743 std::shared_ptr<GeomAPI_Dir> aNormal = aPlane->direction();
744 return fabs(aNormal->dot(aLineDir)) > tolerance * tolerance;