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 if(!theAttribute.get() || !theAttribute->isInitialized()) {
465 theError = "Error: List of points is not initialized.";
469 std::shared_ptr<SketchPlugin_ConstraintFillet> aFilletFeature = std::dynamic_pointer_cast<SketchPlugin_ConstraintFillet>(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 std::list<AttributePtr> aBasePointsList = aFilletFeature->basePoints();
477 std::list<FeaturePtr> aResultEdgesList = aFilletFeature->resultEdges();
479 std::list<std::pair<ObjectPtr, AttributePtr>> aPointsList = aPointsRefList->list();
480 for(std::list<std::pair<ObjectPtr, AttributePtr>>::const_iterator aPointsIt = aPointsList.cbegin(); aPointsIt != aPointsList.cend(); aPointsIt++) {
481 ObjectPtr anObject = (*aPointsIt).first;
482 AttributePtr aPointAttribute = (*aPointsIt).second;
483 std::shared_ptr<GeomAPI_Pnt2d> aSelectedPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aPointAttribute)->pnt();
485 // If we alredy have some result then:
486 // - if it is the same point all ok, just skip it
487 // - if it is point on the fillet arc then it is not valid
488 if(!aBasePointsList.empty()) {
489 if(std::find(aBasePointsList.begin(), aBasePointsList.end(), aPointAttribute) != aBasePointsList.end()) {
493 // Check that selected point not on the one of the result fillet arc.
494 std::list<FeaturePtr>::iterator aResultEdgesIt = aResultEdgesList.begin();
495 for(unsigned int anIndex = 0; anIndex < aBasePointsList.size(); anIndex++) {
496 if(aResultEdgesList.size() > 0) {
497 FeaturePtr aResultArc;
498 std::advance(aResultEdgesIt, 2);
499 aResultArc = *aResultEdgesIt++;
500 AttributePtr anArcStart = aResultArc->attribute(SketchPlugin_Arc::START_ID());
501 AttributePtr anArcEnd = aResultArc->attribute(SketchPlugin_Arc::END_ID());
502 std::shared_ptr<GeomAPI_Pnt2d> anArcStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anArcStart)->pnt();
503 std::shared_ptr<GeomAPI_Pnt2d> anArcEndPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anArcEnd)->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()) {
562 if((*anIt)->getKind() == SketchPlugin_Arc::ID()) {
563 AttributePtr anArcCenter = (*anIt)->attribute(SketchPlugin_Arc::CENTER_ID());
564 std::shared_ptr<GeomAPI_Pnt2d> anArcCenterPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anArcCenter)->pnt();
565 double aDistSelectedArcCenter = aSelectedPnt->distance(anArcCenterPnt);
566 if(aDistSelectedArcCenter < tolerance) {
570 aNewSetOfCoincides.insert(*anIt);
572 aCoinsides = aNewSetOfCoincides;
574 // If we still have more than two coincides remove auxilary entities from set of coincides.
575 if(aCoinsides.size() > 2) {
576 aNewSetOfCoincides.clear();
577 for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin(); anIt != aCoinsides.end(); ++anIt) {
578 if(!(*anIt)->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value()) {
579 aNewSetOfCoincides.insert(*anIt);
582 aCoinsides = aNewSetOfCoincides;
585 if(aCoinsides.size() != 2) {
586 theError = ("Error: One of the selected points does not have two suitable edges for fillet.");
590 // Check that lines not collinear
591 std::set<FeaturePtr>::iterator anIt = aCoinsides.begin();
592 FeaturePtr aFirstFeature = *anIt++;
593 FeaturePtr aSecondFeature = *anIt;
594 if(aFirstFeature->getKind() == SketchPlugin_Line::ID() && aSecondFeature->getKind() == SketchPlugin_Line::ID()) {
595 std::string aStartAttr = SketchPlugin_Line::START_ID();
596 std::string anEndAttr = SketchPlugin_Line::END_ID();
597 std::shared_ptr<GeomAPI_Pnt2d> aFirstStartPnt, aFirstEndPnt, aSecondStartPnt, aSecondEndPnt;
598 aFirstStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFirstFeature->attribute(aStartAttr))->pnt();
599 aFirstEndPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFirstFeature->attribute(anEndAttr))->pnt();
600 aSecondStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aSecondFeature->attribute(aStartAttr))->pnt();
601 aSecondEndPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aSecondFeature->attribute(anEndAttr))->pnt();
602 double aCheck1 = abs((aFirstEndPnt->x() - aFirstStartPnt->x()) * (aSecondStartPnt->y() - aFirstStartPnt->y()) -
603 (aSecondStartPnt->x() - aFirstStartPnt->x()) * (aFirstEndPnt->y() - aFirstStartPnt->y()));
604 double aCheck2 = abs((aFirstEndPnt->x() - aFirstStartPnt->x()) * (aSecondEndPnt->y() - aFirstStartPnt->y()) -
605 (aSecondEndPnt->x() - aFirstStartPnt->x()) * (aFirstEndPnt->y() - aFirstStartPnt->y()));
606 if(aCheck1 < 1.e-7 && aCheck2 < 1.e-7) {
615 bool SketchPlugin_MiddlePointAttrValidator::isValid(const AttributePtr& theAttribute,
616 const std::list<std::string>& theArguments,
617 std::string& theError) const
619 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
620 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
624 // there is a check whether the feature contains a point and a linear edge or two point values
625 std::string aParamA = theArguments.front();
626 SessionPtr aMgr = ModelAPI_Session::get();
627 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
629 FeaturePtr anAttributeFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
630 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
631 AttributeRefAttrPtr anOtherAttr = anAttributeFeature->data()->refattr(aParamA);
633 AttributeRefAttrPtr aRefAttrs[2] = {aRefAttr, anOtherAttr};
636 for (int i = 0; i < 2; ++i) {
637 if (!aRefAttrs[i]->isObject())
640 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrs[i]->object());
642 if (aNbPoints + aNbLines != 0)
647 if (aFeature->getKind() == SketchPlugin_Point::ID())
649 else if (aFeature->getKind() == SketchPlugin_Line::ID())
654 if (aNbPoints != 1 || aNbLines != 1) {
655 theError = "Middle point constraint allows points and lines only";
661 bool SketchPlugin_ArcTangentPointValidator::isValid(const AttributePtr& theAttribute,
662 const std::list<std::string>& /*theArguments*/,
663 std::string& theError) const
665 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
666 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
669 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
670 AttributePtr anAttr = aRefAttr->attr();
672 theError = "The attribute " + theAttribute->id() + " should be a point";
676 FeaturePtr anAttrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->owner());
677 const std::string& aFeatureType = anAttrFeature->getKind();
678 if (aFeatureType == SketchPlugin_Arc::ID()) {
679 // selected point should not be a center of arc
680 const std::string& aPntId = anAttr->id();
681 if (aPntId != SketchPlugin_Arc::START_ID() && aPntId != SketchPlugin_Arc::END_ID()) {
682 theError = "The attribute " + aPntId + " is not supported";
686 else if (aFeatureType == SketchPlugin_Line::ID()) {
687 // selected point should be bound point of line
688 const std::string& aPntId = anAttr->id();
689 if (aPntId != SketchPlugin_Line::START_ID() && aPntId != SketchPlugin_Line::END_ID()) {
690 theError = "The attribute " + aPntId + " is not supported";
695 theError = "Unable to build tangent arc on " + anAttrFeature->getKind();
702 bool SketchPlugin_IntersectionValidator::isValid(const AttributePtr& theAttribute,
703 const std::list<std::string>& theArguments,
704 std::string& theError) const
706 if (theAttribute->attributeType() != ModelAPI_AttributeSelection::typeId()) {
707 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
710 AttributeSelectionPtr aLineAttr =
711 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
712 std::shared_ptr<GeomAPI_Edge> anEdge;
713 if(aLineAttr && aLineAttr->value() && aLineAttr->value()->isEdge()) {
714 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aLineAttr->value()));
715 } else if(aLineAttr->context() && aLineAttr->context()->shape() && aLineAttr->context()->shape()->isEdge()) {
716 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aLineAttr->context()->shape()));
719 if (!anEdge || !anEdge->isLine()) {
720 theError = "The attribute " + theAttribute->id() + " should be a line";
724 std::shared_ptr<GeomAPI_Dir> aLineDir = anEdge->line()->direction();
727 std::shared_ptr<SketchPlugin_Sketch> aSketch;
728 std::set<AttributePtr> aRefs = aLineAttr->owner()->data()->refsToMe();
729 std::set<AttributePtr>::const_iterator anIt = aRefs.begin();
730 for (; anIt != aRefs.end(); ++anIt) {
731 CompositeFeaturePtr aComp =
732 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>((*anIt)->owner());
733 if (aComp && aComp->getKind() == SketchPlugin_Sketch::ID()) {
734 aSketch = std::dynamic_pointer_cast<SketchPlugin_Sketch>(aComp);
739 theError = "There is no sketch referring to the current feature";
743 std::shared_ptr<GeomAPI_Pln> aPlane = aSketch->plane();
744 std::shared_ptr<GeomAPI_Dir> aNormal = aPlane->direction();
745 return fabs(aNormal->dot(aLineDir)) > tolerance * tolerance;