1 // Copyright (C) 2014-2020 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SketchPlugin_Validators.h"
22 #include "SketchPlugin_Arc.h"
23 #include "SketchPlugin_BSpline.h"
24 #include "SketchPlugin_BSplinePeriodic.h"
25 #include "SketchPlugin_Circle.h"
26 #include "SketchPlugin_ConstraintCoincidence.h"
27 #include "SketchPlugin_ConstraintCoincidenceInternal.h"
28 #include "SketchPlugin_ConstraintDistance.h"
29 #include "SketchPlugin_ConstraintRigid.h"
30 #include "SketchPlugin_ConstraintTangent.h"
31 #include "SketchPlugin_Ellipse.h"
32 #include "SketchPlugin_EllipticArc.h"
33 #include "SketchPlugin_Fillet.h"
34 #include "SketchPlugin_CurveFitting.h"
35 #include "SketchPlugin_Line.h"
36 #include "SketchPlugin_MacroArc.h"
37 #include "SketchPlugin_MacroCircle.h"
38 #include "SketchPlugin_MultiRotation.h"
39 #include "SketchPlugin_Offset.h"
40 #include "SketchPlugin_Point.h"
41 #include "SketchPlugin_Sketch.h"
42 #include "SketchPlugin_Trim.h"
43 #include "SketchPlugin_Tools.h"
45 #include "SketcherPrs_Tools.h"
47 #include <Events_InfoMessage.h>
49 #include <ModelAPI_Data.h>
50 #include <ModelAPI_Validator.h>
51 #include <ModelAPI_AttributeDouble.h>
52 #include <ModelAPI_AttributeInteger.h>
53 #include <ModelAPI_AttributeRefAttr.h>
54 #include <ModelAPI_AttributeRefAttrList.h>
55 #include <ModelAPI_AttributeRefList.h>
56 #include <ModelAPI_AttributeSelectionList.h>
57 #include <ModelAPI_AttributeString.h>
58 #include <ModelAPI_Session.h>
59 #include <ModelAPI_Tools.h>
60 #include <ModelAPI_ResultConstruction.h>
62 #include <ModelGeomAlgo_Point2D.h>
63 #include <ModelGeomAlgo_Shape.h>
65 #include <GeomAlgoAPI_EdgeBuilder.h>
66 #include <GeomAlgoAPI_ShapeTools.h>
68 #include <GeomAPI_BSpline.h>
69 #include <GeomAPI_Circ.h>
70 #include <GeomAPI_Dir2d.h>
71 #include <GeomAPI_Ellipse.h>
72 #include <GeomAPI_Lin.h>
73 #include <GeomAPI_Edge.h>
74 #include <GeomAPI_Vertex.h>
76 #include <GeomDataAPI_Point2D.h>
77 #include <GeomDataAPI_Point2DArray.h>
83 #pragma warning(disable: 4100)
86 const double tolerance = 1.e-7;
88 static bool isSpline(FeaturePtr theFeature)
90 return theFeature && (theFeature->getKind() == SketchPlugin_BSpline::ID() ||
91 theFeature->getKind() == SketchPlugin_BSplinePeriodic::ID());
95 bool SketchPlugin_DistanceAttrValidator::isValid(const AttributePtr& theAttribute,
96 const std::list<std::string>& theArguments,
97 Events_InfoMessage& theError) const
99 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
100 theError = "The attribute with the %1 type is not processed";
101 theError.arg(theAttribute->attributeType());
105 // there is a check whether the feature contains a point and a linear edge or two point values
106 std::string aParamA = theArguments.front();
107 SessionPtr aMgr = ModelAPI_Session::get();
108 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
110 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
112 bool isObject = aRefAttr->isObject();
114 // an attribute is a point. A point value is valid always for the distance
117 // 1. check whether the references object is a linear
118 ObjectPtr anObject = aRefAttr->object();
120 const ModelAPI_AttributeValidator* aShapeValidator =
121 dynamic_cast<const ModelAPI_AttributeValidator*>(
122 aFactory->validator("GeomValidators_ShapeType"));
123 std::list<std::string> anArguments;
124 anArguments.push_back("circle");
125 Events_InfoMessage aCircleError;
126 bool aShapeValid = aShapeValidator->isValid(aRefAttr, anArguments, aCircleError);
127 // the circle line is not a valid case
129 theError = "Circle can not be used in distance constraint";
134 anArguments.push_back("line");
135 Events_InfoMessage aLineError;
136 aShapeValid = aShapeValidator->isValid(aRefAttr, anArguments, aLineError);
137 // if the attribute value is not a line, that means it is a vertex. A vertex is always valid
139 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
140 // If it is a line then we have to check that first attribute id not a line
141 std::shared_ptr<SketchPlugin_Feature> aSFeature =
142 std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
143 SketchPlugin_Sketch* aSketch = aSFeature->sketch();
144 std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(aSketch);
145 std::shared_ptr<GeomDataAPI_Point2D> aPoint = SketcherPrs_Tools::getFeaturePoint(
146 aFeature->data(), aParamA, aPlane);
148 theError = "One of parameters of distance constraint should be a point";
156 bool SketchPlugin_TangentAttrValidator::isValid(const AttributePtr& theAttribute,
157 const std::list<std::string>& theArguments,
158 Events_InfoMessage& theError) const
160 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
161 theError = "The attribute with the %1 type is not processed";
162 theError.arg(theAttribute->attributeType());
166 // there is a check whether the feature contains a point and a linear edge or two point values
167 std::string aParamA = theArguments.front();
169 FeaturePtr anAttributeFeature =
170 std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
171 AttributeRefAttrPtr aRefAttr =
172 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
174 bool isObject = aRefAttr->isObject();
175 ObjectPtr anObject = aRefAttr->object();
176 if (!isObject || !anObject.get()) {
177 theError = "It uses an empty object";
181 FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject);
183 AttributeRefAttrPtr aOtherAttr = anAttributeFeature->data()->refattr(aParamA);
184 ObjectPtr aOtherObject = aOtherAttr->object();
185 FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject);
189 if (aRefFea->getKind() == SketchPlugin_Line::ID() &&
190 aOtherFea->getKind() == SketchPlugin_Line::ID()) {
191 theError = "Two segments cannot be tangent";
194 else if (isSpline(aRefFea) && isSpline(aOtherFea)) {
195 theError = "Two B-splines cannot be tangent";
200 bool hasSpline = isSpline(aRefFea);
201 if (!hasSpline && isSpline(aOtherFea)) {
203 std::swap(aRefFea, aOtherFea);
206 auto isApplicableCoincidence = [](FeaturePtr theFeature, const std::string& theAttrName) {
207 AttributeRefAttrPtr aRefAttr = theFeature->refattr(theAttrName);
208 if (aRefAttr->isObject())
210 AttributePtr anAttr = aRefAttr->attr();
211 FeaturePtr anOwner = ModelAPI_Feature::feature(anAttr->owner());
212 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr);
214 return anOwner->getKind() == SketchPlugin_BSpline::ID() &&
215 (aPointAttr->id() == SketchPlugin_BSpline::START_ID() ||
216 aPointAttr->id() == SketchPlugin_BSpline::END_ID());
219 AttributePoint2DArrayPtr aPntArray =
220 std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(anAttr);
221 if (aPntArray && anOwner->getKind() == SketchPlugin_BSpline::ID()) {
222 // check index of the pole
223 AttributeIntegerPtr anIndex = theAttrName == SketchPlugin_Constraint::ENTITY_A() ?
224 theFeature->integer(SketchPlugin_ConstraintCoincidenceInternal::INDEX_ENTITY_A()) :
225 theFeature->integer(SketchPlugin_ConstraintCoincidenceInternal::INDEX_ENTITY_B());
226 return anIndex && (anIndex->value() == 0 || anIndex->value() == aPntArray->size() - 1);
232 AttributePoint2DArrayPtr aBSplinePoles = std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(
233 aRefFea->attribute(SketchPlugin_BSplineBase::POLES_ID()));
234 // additional check the B-spline edge and the other edge have a coincident boundary point
235 std::set<FeaturePtr> aCoincidences = SketchPlugin_Tools::findCoincidentConstraints(aRefFea);
236 for (std::set<FeaturePtr>::iterator anIt = aCoincidences.begin();
237 anIt != aCoincidences.end() && !isValid; ++anIt) {
238 std::set<FeaturePtr> aCoinc;
239 if (isApplicableCoincidence(*anIt, SketchPlugin_Constraint::ENTITY_A()))
240 SketchPlugin_Tools::findCoincidences(*anIt, SketchPlugin_Constraint::ENTITY_B(),
242 else if (isApplicableCoincidence(*anIt, SketchPlugin_Constraint::ENTITY_B()))
243 SketchPlugin_Tools::findCoincidences(*anIt, SketchPlugin_Constraint::ENTITY_A(),
246 std::set<FeaturePtr>::iterator aFoundCoinc = aCoinc.find(aOtherFea);
247 if (aFoundCoinc != aCoinc.end()) {
248 // do not take into account internal constraints
249 AttributeReferencePtr aParent =
250 (*aFoundCoinc)->reference(SketchPlugin_SketchEntity::PARENT_ID());
251 isValid = !aParent || !aParent->isInitialized() || aParent->value() != aRefFea;
259 bool SketchPlugin_PerpendicularAttrValidator::isValid(const AttributePtr& theAttribute,
260 const std::list<std::string>& theArguments,
261 Events_InfoMessage& theError) const
263 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
264 theError = "The attribute with the %1 type is not processed";
265 theError.arg(theAttribute->attributeType());
269 std::string aParamA = theArguments.front();
271 FeaturePtr anOwner = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
272 AttributeRefAttrPtr aRefAttr =
273 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
275 bool isObject = aRefAttr->isObject();
276 ObjectPtr anObject = aRefAttr->object();
277 if (isObject && anObject.get()) {
278 FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject);
280 AttributeRefAttrPtr aOtherAttr = anOwner->refattr(aParamA);
281 ObjectPtr aOtherObject = aOtherAttr->object();
282 FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject);
284 // at least one feature should be a line
285 if (aRefFea->getKind() != SketchPlugin_Line::ID() &&
286 aOtherFea && aOtherFea->getKind() != SketchPlugin_Line::ID()) {
287 theError = "At least one feature should be a line";
290 else if (isSpline(aRefFea) || isSpline(aOtherFea)) {
291 theError = "B-spline is not supported";
296 theError = "It uses an empty object";
303 bool SketchPlugin_NotFixedValidator::isValid(const AttributePtr& theAttribute,
304 const std::list<std::string>& theArguments,
305 Events_InfoMessage& theError) const
307 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
308 theError = "The attribute with the %1 type is not processed";
309 theError.arg(theAttribute->attributeType());
313 std::shared_ptr<SketchPlugin_Feature> aFeature =
314 std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
318 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
320 SketchPlugin_Sketch* aSketch = aFeature->sketch();
321 int aNbFeatures = aSketch->numberOfSubs();
322 for (int anInd = 0; anInd < aNbFeatures; anInd++) {
323 FeaturePtr aSubFeature = aSketch->subFeature(anInd);
324 if (aSubFeature->getKind() != SketchPlugin_ConstraintRigid::ID() || aSubFeature == aFeature)
326 AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
327 aSubFeature->attribute(SketchPlugin_ConstraintRigid::ENTITY_A()));
328 if (aRefAttr->isObject()) {
329 if (aRefAttr->object() == aRAttr->object()) {
330 ObjectPtr anObject = aRefAttr->object();
331 std::string aName = anObject.get() ? anObject->data()->name() : "";
332 theError = "The object %1 has been already fixed.";
337 else if (aRefAttr->attr() == aRAttr->attr()) {
338 AttributePtr anAttribute = aRefAttr->attr();
339 std::string aName = anAttribute.get() ? anAttribute->id() : "";
340 theError = "The attribute %1 has been already fixed.";
348 bool SketchPlugin_EqualAttrValidator::isValid(const AttributePtr& theAttribute,
349 const std::list<std::string>& theArguments,
350 Events_InfoMessage& theError) const
352 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
353 theError = "The attribute with the %1 type is not processed";
354 theError.arg(theAttribute->attributeType());
358 std::string aParamA = theArguments.front();
359 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
360 AttributeRefAttrPtr aRefAttr[2];
361 aRefAttr[0] = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
362 aRefAttr[1] = aFeature->data()->refattr(aParamA);
364 if (!aRefAttr[0]->isObject() || !aRefAttr[1]->isObject()) {
365 theError = "Attributes can not be used in equal constraint";
369 std::string aType[2];
370 std::list<std::string> anArguments;
371 for (int i = 0; i < 2; i++) {
372 aFeature = ModelAPI_Feature::feature(aRefAttr[i]->object());
376 aType[i] = aFeature->getKind();
377 if (aFeature->getKind() != SketchPlugin_Line::ID() &&
378 aFeature->getKind() != SketchPlugin_Circle::ID() &&
379 aFeature->getKind() != SketchPlugin_Arc::ID() &&
380 aFeature->getKind() != SketchPlugin_Ellipse::ID() &&
381 aFeature->getKind() != SketchPlugin_EllipticArc::ID()) {
382 theError = "The %1 feature is not supported by the Equal constraint.";
383 theError.arg(aFeature->getKind());
384 // wrong type of attribute
389 bool isOk = aType[0] == aType[1];
391 // circle and arc may be equal
392 isOk = (aType[0] == SketchPlugin_Arc::ID() && aType[1] == SketchPlugin_Circle::ID())
393 || (aType[0] == SketchPlugin_Circle::ID() && aType[1] == SketchPlugin_Arc::ID());
396 // ellipse and elliptic arc may be equal
397 isOk = (aType[0] == SketchPlugin_EllipticArc::ID() && aType[1] == SketchPlugin_Ellipse::ID())
398 || (aType[0] == SketchPlugin_Ellipse::ID() && aType[1] == SketchPlugin_EllipticArc::ID());
401 theError = "Features with kinds %1 and %2 can not be equal.";
402 theError.arg(aType[0]).arg(aType[1]);
408 bool SketchPlugin_MirrorAttrValidator::isValid(const AttributePtr& theAttribute,
409 const std::list<std::string>& theArguments,
410 Events_InfoMessage& theError) const
412 if (theAttribute->attributeType() != ModelAPI_AttributeRefList::typeId()) {
413 theError = "The attribute with the %1 type is not processed";
414 theError.arg(theAttribute->attributeType());
418 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
419 AttributeRefListPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
421 AttributeRefListPtr aRefListOfMirrored = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
422 aFeature->attribute(SketchPlugin_Constraint::ENTITY_C()));
423 std::list<ObjectPtr> aMirroredObjects = aRefListOfMirrored->list();
425 for(int anInd = 0; anInd < aSelAttr->size(); anInd++) {
426 ObjectPtr aSelObject = aSelAttr->object(anInd);
428 // B-splines are not supported in Mirror yet
429 FeaturePtr aSelFeature = ModelAPI_Feature::feature(aSelObject);
430 if (aSelFeature && (aSelFeature->getKind() == SketchPlugin_BSpline::ID() ||
431 aSelFeature->getKind() == SketchPlugin_BSplinePeriodic::ID())) {
432 theError = "Not supported";
436 std::string aName = aSelObject.get() ? aSelObject->data()->name() : "";
437 std::list<ObjectPtr>::iterator aMirIter = aMirroredObjects.begin();
438 for (; aMirIter != aMirroredObjects.end(); aMirIter++)
439 if (aSelObject == *aMirIter) {
440 theError = "The object %1 is a result of mirror";
448 bool SketchPlugin_CoincidenceAttrValidator::isValid(const AttributePtr& theAttribute,
449 const std::list<std::string>& theArguments,
450 Events_InfoMessage& theError) const
452 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
453 theError = "The attribute with the %1 type is not processed";
454 theError.arg(theAttribute->attributeType());
458 // there is a check whether the feature contains a point and a linear edge or two point values
459 std::string aParamA = theArguments.front();
461 FeaturePtr aConstraint = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
462 AttributeRefAttrPtr aRefAttrA = aConstraint->data()->refattr(aParamA);
464 theError = "The %1 attribute should be %2";
465 theError.arg(aParamA).arg(ModelAPI_AttributeRefAttr::typeId());
469 AttributeRefAttrPtr aRefAttrB =
470 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
472 // first attribute is a point, it may coincide with any object
473 if (!aRefAttrA->isObject())
476 ObjectPtr anObject = aRefAttrA->object();
477 if (!anObject.get()) {
478 theError = "%1 attribute has an empty object";
479 theError.arg(aParamA);
482 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrA->object());
483 if (!aFeature.get()) {
484 theError = "%1 attribute has an empty feature";
485 theError.arg(aParamA);
489 if (aFeature->getKind() == SketchPlugin_Point::ID())
493 // second attribute is a point, it may coincide with any object
494 if (!aRefAttrB->isObject())
497 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrB->object());
499 theError = "%1 attribute has an empty object";
500 theError.arg(theAttribute->id());
503 if (aFeature->getKind() == SketchPlugin_Point::ID())
506 theError = "There is no an attribute filled by a point";
511 bool SketchPlugin_CopyValidator::isValid(const AttributePtr& theAttribute,
512 const std::list<std::string>& theArguments,
513 Events_InfoMessage& theError) const
515 if (theAttribute->attributeType() != ModelAPI_AttributeRefList::typeId()) {
516 theError = "The attribute with the %1 type is not processed";
517 theError.arg(theAttribute->attributeType());
521 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
522 AttributeRefListPtr aSelAttr =
523 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
524 std::set<ObjectPtr> aSelected;
526 AttributeRefListPtr aRefListOfInitial = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
527 aFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
528 AttributeRefListPtr aRefListOfCopied = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
529 aFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
530 std::list<ObjectPtr> anInitialObjects = aRefListOfInitial->list();
531 std::list<ObjectPtr> aCopiedObjects = aRefListOfCopied->list();
533 std::list<ObjectPtr>::iterator anObjIter;
534 for(int anInd = 0; anInd < aSelAttr->size(); anInd++) {
535 ObjectPtr aSelObject = aSelAttr->object(anInd);
536 if (aSelected.find(aSelObject) != aSelected.end()) {
537 theError = "Error: An object selected twice";
540 aSelected.insert(aSelObject);
542 anObjIter = anInitialObjects.begin();
543 for (; anObjIter != anInitialObjects.end(); anObjIter++)
544 if (aSelObject == *anObjIter)
546 if (anObjIter != anInitialObjects.end())
549 // B-splines are not supported in Copying features
550 FeaturePtr aSelFeature = ModelAPI_Feature::feature(aSelObject);
551 if (aFeature->getKind() != SketchPlugin_Offset::ID() &&
552 aSelFeature && (aSelFeature->getKind() == SketchPlugin_BSpline::ID() ||
553 aSelFeature->getKind() == SketchPlugin_BSplinePeriodic::ID())) {
554 theError = "Not supported";
558 anObjIter = aCopiedObjects.begin();
559 for (; anObjIter != aCopiedObjects.end(); anObjIter++) {
560 bool isFound = aSelObject == *anObjIter;
562 // check in the results of the feature
563 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anObjIter);
565 const std::list<ResultPtr>& aResults = aFeature->results();
566 for (std::list<ResultPtr>::const_iterator aResIt = aResults.begin();
567 aResIt != aResults.end() && !isFound; ++aResIt) {
568 isFound = aSelObject == *aResIt;
573 std::string aName = aSelObject.get() ? aSelObject->data()->name() : "";
574 theError = "The object %1 is a result of copy";
583 bool SketchPlugin_SolverErrorValidator::isValid(
584 const std::shared_ptr<ModelAPI_Feature>& theFeature,
585 const std::list<std::string>& theArguments,
586 Events_InfoMessage& theError) const
588 AttributeStringPtr aAttributeString = theFeature->string(SketchPlugin_Sketch::SOLVER_ERROR());
590 if (!aAttributeString->value().empty()) {
591 theError = aAttributeString->value();
598 bool SketchPlugin_SolverErrorValidator::isNotObligatory(std::string theFeature,
599 std::string theAttribute)
604 static bool hasSameTangentFeature(const std::set<AttributePtr>& theRefsList,
605 const FeaturePtr theFeature)
607 for(std::set<AttributePtr>::const_iterator
608 anIt = theRefsList.cbegin(); anIt != theRefsList.cend(); ++anIt) {
609 std::shared_ptr<ModelAPI_Attribute> aAttr = (*anIt);
610 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
613 if (aFeature->getKind() == SketchPlugin_ConstraintTangent::ID()) {
614 AttributeRefAttrPtr anAttrRefA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
615 aFeature->attribute(SketchPlugin_ConstraintTangent::ENTITY_A()));
616 AttributeRefAttrPtr anAttrRefB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
617 aFeature->attribute(SketchPlugin_ConstraintTangent::ENTITY_B()));
618 if(anAttrRefA.get()) {
619 ResultPtr aResA = std::dynamic_pointer_cast<ModelAPI_Result>(anAttrRefA->object());
621 DocumentPtr aDoc = aResA->document();
623 FeaturePtr aFeatureA = aDoc->feature(aResA);
624 if(aFeatureA.get() && aFeatureA == theFeature) {
630 if(anAttrRefB.get()) {
631 ResultPtr aResB = std::dynamic_pointer_cast<ModelAPI_Result>(anAttrRefB->object());
633 DocumentPtr aDoc = aResB->document();
635 FeaturePtr aFeatureB = aDoc->feature(aResB);
636 if(aFeatureB.get() && aFeatureB == theFeature) {
647 static bool isPointPointCoincidence(const FeaturePtr& theCoincidence)
649 AttributeRefAttrPtr aRefAttr[2] = {
650 theCoincidence->refattr(SketchPlugin_Constraint::ENTITY_A()),
651 theCoincidence->refattr(SketchPlugin_Constraint::ENTITY_B())
654 bool arePoints = true;
655 for (int i = 0; i < 2 && arePoints; ++i) {
656 if (aRefAttr[i]->isObject()) {
657 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr[i]->object());
658 arePoints = aFeature.get() && aFeature->getKind() == SketchPlugin_Point::ID();
660 arePoints = aRefAttr[i]->attr().get() != NULL;
665 bool SketchPlugin_FilletVertexValidator::isValid(const AttributePtr& theAttribute,
666 const std::list<std::string>& theArguments,
667 Events_InfoMessage& theError) const
669 AttributeRefAttrPtr aPointRefAttr =
670 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
671 if(!aPointRefAttr.get()) {
672 theError = "Error: Point not selected.";
676 AttributePtr aPointAttribute = aPointRefAttr->attr();
677 if (!aPointAttribute.get()) {
678 theError = "Error: Bad point selected.";
681 std::shared_ptr<GeomAPI_Pnt2d> aSelectedPnt =
682 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aPointAttribute)->pnt();
684 // Obtain constraint coincidence for the fillet point.
685 const std::set<AttributePtr>& aRefsList = aPointAttribute->owner()->data()->refsToMe();
686 FeaturePtr aConstraintCoincidence;
687 for(std::set<AttributePtr>::const_iterator anIt = aRefsList.cbegin();
688 anIt != aRefsList.cend(); ++anIt) {
689 std::shared_ptr<ModelAPI_Attribute> aAttr = (*anIt);
690 FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
691 if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
692 if (!isPointPointCoincidence(aConstrFeature))
695 AttributeRefAttrPtr anAttrRefA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
696 aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_A()));
697 AttributeRefAttrPtr anAttrRefB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
698 aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_B()));
700 AttributePtr anAttrA = anAttrRefA->attr();
701 if(aPointAttribute == anAttrA) {
702 aConstraintCoincidence = aConstrFeature;
706 AttributePtr anAttrB = anAttrRefB->attr();
707 if(aPointAttribute == anAttrB) {
708 aConstraintCoincidence = aConstrFeature;
714 if(!aConstraintCoincidence.get()) {
715 theError = "Error: one of the selected point does not have coincidence.";
719 // Get coincides from constraint.
720 std::set<FeaturePtr> aCoinsides;
721 SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
722 SketchPlugin_ConstraintCoincidence::ENTITY_A(),
725 SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
726 SketchPlugin_ConstraintCoincidence::ENTITY_B(),
730 // Remove points and external lines from set of coincides.
731 std::set<FeaturePtr> aNewSetOfCoincides;
732 for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin();
733 anIt != aCoinsides.end(); ++anIt) {
734 std::shared_ptr<SketchPlugin_SketchEntity> aSketchEntity =
735 std::dynamic_pointer_cast<SketchPlugin_SketchEntity>(*anIt);
736 if(aSketchEntity.get() && (aSketchEntity->isCopy() || aSketchEntity->isExternal())) {
739 if((*anIt)->getKind() != SketchPlugin_Line::ID() &&
740 (*anIt)->getKind() != SketchPlugin_Arc::ID()) {
743 if((*anIt)->getKind() == SketchPlugin_Arc::ID()) {
744 AttributePtr anArcCenter = (*anIt)->attribute(SketchPlugin_Arc::CENTER_ID());
745 std::shared_ptr<GeomAPI_Pnt2d> anArcCenterPnt =
746 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anArcCenter)->pnt();
747 double aDistSelectedArcCenter = aSelectedPnt->distance(anArcCenterPnt);
748 if(aDistSelectedArcCenter < tolerance) {
752 aNewSetOfCoincides.insert(*anIt);
754 aCoinsides = aNewSetOfCoincides;
756 // If we still have more than two coincides remove auxilary entities from set of coincides.
757 if(aCoinsides.size() > 2) {
758 aNewSetOfCoincides.clear();
759 for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin();
760 anIt != aCoinsides.end(); ++anIt) {
761 if(!(*anIt)->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value()) {
762 aNewSetOfCoincides.insert(*anIt);
765 aCoinsides = aNewSetOfCoincides;
768 if(aCoinsides.size() != 2) {
769 theError = "Error: One of the selected points does not have two suitable edges for fillet.";
773 // Check that selected edges don't have tangent constraint.
774 std::set<FeaturePtr>::iterator anIt = aCoinsides.begin();
775 FeaturePtr aFirstFeature = *anIt++;
776 FeaturePtr aSecondFeature = *anIt;
777 const std::set<AttributePtr>& aFirstFeatureRefsList = aFirstFeature->data()->refsToMe();
778 if(hasSameTangentFeature(aFirstFeatureRefsList, aSecondFeature)) {
779 theError = "Error: Edges in selected point has tangent constraint.";
783 std::list<ResultPtr> aFirstResults = aFirstFeature->results();
784 for(std::list<ResultPtr>::iterator aResIt = aFirstResults.begin();
785 aResIt != aFirstResults.end(); ++aResIt) {
786 ResultPtr aRes = *aResIt;
787 const std::set<AttributePtr>& aResRefsList = aRes->data()->refsToMe();
788 if(hasSameTangentFeature(aResRefsList, aSecondFeature)) {
789 theError = "Error: Edges in selected point has tangent constraint.";
794 // Check the features are not tangent
795 std::shared_ptr<GeomAPI_Shape> aFirstShape = aFirstFeature->lastResult()->shape();
796 std::shared_ptr<GeomAPI_Shape> aSecondShape = aSecondFeature->lastResult()->shape();
797 if (!aFirstShape || !aFirstShape->isEdge() ||
798 !aSecondShape || !aSecondShape->isEdge()) {
799 theError = "Error: At least on of the features is not an edge";
803 std::shared_ptr<GeomAPI_Edge> anEdge1 = std::dynamic_pointer_cast<GeomAPI_Edge>(aFirstShape);
804 std::shared_ptr<GeomAPI_Edge> anEdge2 = std::dynamic_pointer_cast<GeomAPI_Edge>(aSecondShape);
806 static const double TOL = 1.e-7;
807 if (anEdge1->isLine() && anEdge2->isLine()) {
808 // Check that lines not collinear
809 std::shared_ptr<GeomAPI_Dir> aDir1 = anEdge1->line()->direction();
810 std::shared_ptr<GeomAPI_Dir> aDir2 = anEdge2->line()->direction();
811 double aCross = aDir1->cross(aDir2)->squareModulus();
812 if (aCross < TOL * TOL)
814 } else if (anEdge1->isArc() && anEdge2->isArc()) {
815 // check the circles are not tangent
816 std::shared_ptr<GeomAPI_Circ> aCirc1 = anEdge1->circle();
817 std::shared_ptr<GeomAPI_Circ> aCirc2 = anEdge2->circle();
818 double aDistCC = aCirc1->center()->distance(aCirc2->center());
819 double aRadSum = aCirc1->radius() + aCirc2->radius();
820 double aRadDiff = fabs(aCirc1->radius() - aCirc2->radius());
821 if (fabs(aDistCC - aRadSum) < TOL || fabs(aDistCC - aRadDiff) < TOL)
824 // check whether line and arc are tangent
825 std::shared_ptr<GeomAPI_Circ> aCirc;
826 std::shared_ptr<GeomAPI_Lin> aLine;
827 if (anEdge1->isLine()) {
828 aLine = anEdge1->line();
829 aCirc = anEdge2->circle();
831 aCirc = anEdge1->circle();
832 aLine = anEdge2->line();
835 double aDistCL = aLine->distance(aCirc->center());
836 if (fabs(aDistCL - aCirc->radius()) < TOL)
843 bool SketchPlugin_MiddlePointAttrValidator::isValid(const AttributePtr& theAttribute,
844 const std::list<std::string>& theArguments,
845 Events_InfoMessage& theError) const
847 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
848 theError = "The attribute with the %1 type is not processed";
849 theError.arg(theAttribute->attributeType());
853 // there is a check whether the feature contains a point and a linear edge or two point values
854 std::string aParamA = theArguments.front();
856 FeaturePtr anAttributeFeature =
857 std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
858 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
859 AttributeRefAttrPtr anOtherAttr = anAttributeFeature->data()->refattr(aParamA);
861 AttributeRefAttrPtr aRefAttrs[2] = {aRefAttr, anOtherAttr};
864 for (int i = 0; i < 2; ++i) {
865 if (!aRefAttrs[i]->isObject())
868 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrs[i]->object());
870 if (aNbPoints + aNbLines != 0)
875 if (aFeature->getKind() == SketchPlugin_Point::ID())
877 else if (aFeature->getKind() == SketchPlugin_Line::ID() ||
878 aFeature->getKind() == SketchPlugin_Arc::ID() ||
879 aFeature->getKind() == SketchPlugin_EllipticArc::ID())
884 if (aNbPoints != 1 || aNbLines != 1) {
885 theError = "Middle point constraint allows points and lines only";
891 bool SketchPlugin_ArcTangentPointValidator::isValid(const AttributePtr& theAttribute,
892 const std::list<std::string>& /*theArguments*/,
893 Events_InfoMessage& theError) const
895 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
896 theError = "The attribute with the %1 type is not processed";
897 theError.arg(theAttribute->attributeType());
900 FeaturePtr anOwner = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
901 AttributeStringPtr anArcTypeAttr = anOwner->string(SketchPlugin_MacroArc::ARC_TYPE());
902 if (anArcTypeAttr && anArcTypeAttr->value() != SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE())
903 return true; // not applicable for non-tangent arcs
905 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
906 AttributePtr anAttr = aRefAttr->attr();
908 theError = "The attribute %1 should be a point";
909 theError.arg(theAttribute->id());
913 FeaturePtr anAttrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->owner());
914 const std::string& aFeatureType = anAttrFeature->getKind();
915 if (aFeatureType == SketchPlugin_Arc::ID()) {
916 // selected point should not be a center of arc
917 const std::string& aPntId = anAttr->id();
918 if (aPntId != SketchPlugin_Arc::START_ID() && aPntId != SketchPlugin_Arc::END_ID()) {
919 theError = "The attribute %1 is not supported";
920 theError.arg(aPntId);
924 else if (aFeatureType == SketchPlugin_Line::ID()) {
925 // selected point should be bound point of line
926 const std::string& aPntId = anAttr->id();
927 if (aPntId != SketchPlugin_Line::START_ID() && aPntId != SketchPlugin_Line::END_ID()) {
928 theError = "The attribute %1 is not supported";
929 theError.arg(aPntId);
934 theError = "Unable to build tangent arc on %1";
935 theError.arg(anAttrFeature->getKind());
942 bool SketchPlugin_ArcTransversalPointValidator::isValid(
943 const AttributePtr& theAttribute,
944 const std::list<std::string>& /*theArguments*/,
945 Events_InfoMessage& theError) const
947 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
948 theError = "The attribute with the %1 type is not processed";
949 theError.arg(theAttribute->attributeType());
952 FeaturePtr anOwner = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
953 AttributeStringPtr anArcTypeAttr = anOwner->string(SketchPlugin_MacroArc::ARC_TYPE());
955 anArcTypeAttr->value() != SketchPlugin_MacroArc::ARC_TYPE_BY_TRANSVERSAL_LINE())
956 return true; // not applicable for non-transversal arcs
958 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
959 AttributePtr anAttr = aRefAttr->attr();
961 theError = "The attribute %1 should be a point";
962 theError.arg(theAttribute->id());
966 FeaturePtr anAttrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->owner());
967 const std::string& aFeatureType = anAttrFeature->getKind();
968 if (aFeatureType == SketchPlugin_Line::ID()) {
969 // selected point should be bound point of line
970 const std::string& aPntId = anAttr->id();
971 if (aPntId != SketchPlugin_Line::START_ID() && aPntId != SketchPlugin_Line::END_ID()) {
972 theError = "The attribute %1 is not supported";
973 theError.arg(aPntId);
978 theError = "Unable to build perpendicular arc on %1";
979 theError.arg(anAttrFeature->getKind());
986 bool SketchPlugin_IntersectionValidator::isValid(const AttributePtr& theAttribute,
987 const std::list<std::string>& theArguments,
988 Events_InfoMessage& theError) const
990 if (theAttribute->attributeType() != ModelAPI_AttributeSelection::typeId()) {
991 theError = "The attribute with the %1 type is not processed";
992 theError.arg(theAttribute->attributeType());
995 AttributeSelectionPtr anExternalAttr =
996 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
997 std::shared_ptr<GeomAPI_Edge> anEdge;
998 if (anExternalAttr && anExternalAttr->value() && anExternalAttr->value()->isEdge()) {
999 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anExternalAttr->value()));
1000 } else if(anExternalAttr->context() && anExternalAttr->context()->shape() &&
1001 anExternalAttr->context()->shape()->isEdge()) {
1002 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anExternalAttr->context()->shape()));
1006 theError = "The attribute %1 should be an edge";
1007 theError.arg(theAttribute->id());
1012 std::shared_ptr<SketchPlugin_Sketch> aSketch;
1013 std::set<AttributePtr> aRefs = anExternalAttr->owner()->data()->refsToMe();
1014 std::set<AttributePtr>::const_iterator anIt = aRefs.begin();
1015 for (; anIt != aRefs.end(); ++anIt) {
1016 CompositeFeaturePtr aComp =
1017 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>((*anIt)->owner());
1018 if (aComp && aComp->getKind() == SketchPlugin_Sketch::ID()) {
1019 aSketch = std::dynamic_pointer_cast<SketchPlugin_Sketch>(aComp);
1024 theError = "There is no sketch referring to the current feature";
1028 // check the edge is intersected with sketch plane
1029 std::shared_ptr<GeomAPI_Pln> aPlane = aSketch->plane();
1031 std::list<GeomPointPtr> anIntersectionsPoints;
1032 anEdge->intersectWithPlane(aPlane, anIntersectionsPoints);
1033 if (anIntersectionsPoints.empty()) {
1034 theError = "The edge is not intersected with sketch plane";
1040 bool SketchPlugin_SplitValidator::isValid(const AttributePtr& theAttribute,
1041 const std::list<std::string>& theArguments,
1042 Events_InfoMessage& theError) const
1044 bool aValid = false;
1046 if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
1047 theError = "The attribute with the %1 type is not processed";
1048 theError.arg(theAttribute->attributeType());
1051 AttributeReferencePtr aFeatureAttr =
1052 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
1053 std::shared_ptr<SketchPlugin_Feature> aSplitFeature =
1054 std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
1056 ObjectPtr anAttrObject = aFeatureAttr->value();
1057 if (!anAttrObject) {
1058 AttributePtr aPreviewAttr = aSplitFeature->attribute(SketchPlugin_Trim::PREVIEW_OBJECT());
1059 aFeatureAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(aPreviewAttr);
1060 anAttrObject = aFeatureAttr->value();
1063 FeaturePtr anAttrFeature = ModelAPI_Feature::feature(anAttrObject);
1067 // B-splines are not supported by the Split yet
1068 if (anAttrFeature->getKind() == SketchPlugin_BSpline::ID() ||
1069 anAttrFeature->getKind() == SketchPlugin_BSplinePeriodic::ID()) {
1070 theError = "Not supported";
1074 std::set<ResultPtr> anEdgeShapes;
1075 ModelGeomAlgo_Shape::shapesOfType(anAttrFeature, GeomAPI_Shape::EDGE, anEdgeShapes);
1076 if (anEdgeShapes.empty() || anEdgeShapes.size() > 1 /*there case has not existed yet*/)
1079 // coincidences to the feature
1080 std::set<std::shared_ptr<GeomDataAPI_Point2D> > aRefAttributes;
1081 ModelGeomAlgo_Point2D::getPointsOfReference(anAttrFeature,
1082 SketchPlugin_ConstraintCoincidence::ID(),
1083 aRefAttributes, SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
1085 GeomShapePtr anAttrShape = (*anEdgeShapes.begin())->shape();
1086 std::shared_ptr<SketchPlugin_Feature> aSFeature =
1087 std::dynamic_pointer_cast<SketchPlugin_Feature>(anAttrFeature);
1088 if (!aSFeature || aSFeature->isCopy())
1090 SketchPlugin_Sketch* aSketch = aSFeature->sketch();
1092 std::shared_ptr<ModelAPI_Data> aData = aSketch->data();
1093 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1094 aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
1095 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1096 aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
1097 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1098 aData->attribute(SketchPlugin_Sketch::NORM_ID()));
1099 std::shared_ptr<GeomAPI_Dir> aDirY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
1101 typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
1102 std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
1103 std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
1104 PointToRefsMap aPointsInfo;
1106 ModelGeomAlgo_Point2D::getPointsInsideShape(anAttrShape, aRefAttributes, aC->pnt(),
1107 aX->dir(), aDirY, aPointsInfo);
1108 int aCoincidentToFeature = (int)aPointsInfo.size();
1109 if (anAttrFeature->getKind() == SketchPlugin_Circle::ID() ||
1110 anAttrFeature->getKind() == SketchPlugin_Ellipse::ID())
1111 aValid = aCoincidentToFeature >= 2;
1113 aValid = aCoincidentToFeature >= 1;
1118 bool SketchPlugin_TrimValidator::isValid(const AttributePtr& theAttribute,
1119 const std::list<std::string>& theArguments,
1120 Events_InfoMessage& theError) const
1122 bool aValid = false;
1124 if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
1125 theError = "The attribute with the %1 type is not processed";
1126 theError.arg(theAttribute->attributeType());
1129 AttributeReferencePtr aBaseObjectAttr =
1130 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
1132 std::shared_ptr<SketchPlugin_Feature> aTrimFeature =
1133 std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
1135 ObjectPtr aBaseObject = aBaseObjectAttr->value();
1137 AttributePtr aPreviewAttr = aTrimFeature->attribute(SketchPlugin_Trim::PREVIEW_OBJECT());
1138 aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(aPreviewAttr);
1139 aBaseObject = aBaseObjectAttr->value();
1142 FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObject);
1146 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1147 std::dynamic_pointer_cast<SketchPlugin_Feature>(aBaseFeature);
1148 if (!aSketchFeature.get() || aSketchFeature->isCopy())
1151 // B-splines are not supported by the Trim yet
1152 if (aBaseFeature->getKind() == SketchPlugin_BSpline::ID() ||
1153 aBaseFeature->getKind() == SketchPlugin_BSplinePeriodic::ID()) {
1154 theError = "Not supported";
1159 AttributePoint2DPtr aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1160 aTrimFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT()));
1162 SketchPlugin_Sketch* aSketch = aTrimFeature->sketch();
1164 std::shared_ptr<GeomAPI_Pnt2d> anAttributePnt2d = aPoint->pnt();
1165 std::shared_ptr<GeomAPI_Pnt> anAttributePnt = aSketch->to3D(anAttributePnt2d->x(),
1166 anAttributePnt2d->y());
1168 std::map<ObjectPtr, std::set<GeomShapePtr> > aCashedShapes;
1169 std::map<ObjectPtr, std::map<std::shared_ptr<GeomAPI_Pnt>,
1170 std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
1171 std::list<std::shared_ptr<ModelAPI_Object> > > > > anObjectToPoints;
1172 SketchPlugin_SegmentationTools::fillObjectShapes(
1173 aTrimFeature.get(), aBaseObject, aCashedShapes, anObjectToPoints);
1174 const std::set<GeomShapePtr>& aShapes = aCashedShapes[aBaseObject];
1176 return aShapes.size() > 1;
1179 bool SketchPlugin_ProjectionValidator::isValid(const AttributePtr& theAttribute,
1180 const std::list<std::string>& theArguments,
1181 Events_InfoMessage& theError) const
1183 if (theAttribute->attributeType() != ModelAPI_AttributeSelection::typeId()) {
1184 theError = "The attribute with the %1 type is not processed";
1185 theError.arg(theAttribute->attributeType());
1189 AttributeSelectionPtr aFeatureAttr =
1190 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
1191 std::shared_ptr<GeomAPI_Vertex> aVertex;
1192 std::shared_ptr<GeomAPI_Edge> anEdge;
1193 std::shared_ptr<SketchPlugin_Feature> aSketchFeature;
1194 if (aFeatureAttr.get()) {
1195 GeomShapePtr aVal = aFeatureAttr->value();
1196 ResultPtr aRes = aFeatureAttr->context();
1197 if (aVal && aVal->isVertex())
1198 aVertex = std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex(aVal));
1199 else if (aVal && aVal->isEdge()) {
1200 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aVal));
1201 } else if(aRes && aRes->shape()) {
1202 if (aRes->shape()->isVertex())
1203 aVertex = std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex(aRes->shape()));
1204 else if (aRes->shape()->isEdge())
1205 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aRes->shape()));
1208 // try to convert result to sketch feature
1211 std::dynamic_pointer_cast<SketchPlugin_Feature>(ModelAPI_Feature::feature(aRes));
1214 if (!aVertex && !anEdge) {
1215 theError = "The attribute %1 should be an edge or vertex";
1216 theError.arg(theAttribute->id());
1221 std::shared_ptr<SketchPlugin_Sketch> aSketch;
1222 std::set<AttributePtr> aRefs = theAttribute->owner()->data()->refsToMe();
1223 std::set<AttributePtr>::const_iterator anIt = aRefs.begin();
1224 for (; anIt != aRefs.end(); ++anIt) {
1225 CompositeFeaturePtr aComp =
1226 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>((*anIt)->owner());
1227 if (aComp && aComp->getKind() == SketchPlugin_Sketch::ID()) {
1228 aSketch = std::dynamic_pointer_cast<SketchPlugin_Sketch>(aComp);
1233 theError = "There is no sketch referring to the current feature";
1236 if (aSketchFeature && aSketch.get() == aSketchFeature->sketch()) {
1237 theError = "Unable to project feature from the same sketch";
1241 std::shared_ptr<GeomAPI_Pln> aPlane = aSketch->plane();
1242 std::shared_ptr<GeomAPI_Dir> aNormal = aPlane->direction();
1243 std::shared_ptr<GeomAPI_Pnt> anOrigin = aPlane->location();
1247 aValid = true; // vertex is always could be projected
1248 else if (anEdge->isLine()) {
1249 std::shared_ptr<GeomAPI_Lin> aLine = anEdge->line();
1250 std::shared_ptr<GeomAPI_Dir> aLineDir = aLine->direction();
1251 double aDot = fabs(aNormal->dot(aLineDir));
1252 aValid = fabs(aDot - 1.0) >= tolerance * tolerance;
1254 theError = "Error: Line is orthogonal to the sketch plane.";
1256 else if (anEdge->isCircle() || anEdge->isArc()) {
1257 std::shared_ptr<GeomAPI_Circ> aCircle = anEdge->circle();
1258 std::shared_ptr<GeomAPI_Dir> aCircNormal = aCircle->normal();
1259 double aDot = fabs(aNormal->dot(aCircNormal));
1260 aValid = aDot >= tolerance * tolerance;
1262 theError.arg(anEdge->isCircle() ? "Error: Circle is orthogonal to the sketch plane."
1263 : "Error: Arc is orthogonal to the sketch plane.");
1265 else if (anEdge->isEllipse()) {
1266 std::shared_ptr<GeomAPI_Ellipse> anEllipse = anEdge->ellipse();
1267 std::shared_ptr<GeomAPI_Dir> anEllipseNormal = anEllipse->normal();
1268 double aDot = fabs(aNormal->dot(anEllipseNormal));
1269 aValid = aDot >= tolerance * tolerance;
1271 theError.arg(anEdge->isClosed() ? "Error: Ellipse is orthogonal to the sketch plane."
1272 : "Error: Elliptic Arc is orthogonal to the sketch plane.");
1274 else if (anEdge->isBSpline()) {
1275 // check B-spline is periodic and planar
1276 std::shared_ptr<GeomAPI_Curve> aCurve(new GeomAPI_Curve(anEdge));
1277 std::shared_ptr<GeomAPI_BSpline> aBSpline(new GeomAPI_BSpline(aCurve));
1278 if (aBSpline->isPeriodic()) {
1279 GeomPlanePtr aBSplinePlane = GeomAlgoAPI_ShapeTools::findPlane(ListOfShape(1, anEdge));
1280 if (aBSplinePlane) {
1281 std::shared_ptr<GeomAPI_Dir> aBSplineNormal = aBSplinePlane->direction();
1282 double aDot = fabs(aNormal->dot(aBSplineNormal));
1283 aValid = fabs(aDot - 1.0) <= tolerance * tolerance;
1285 // B-spline's plane is orthogonal to the sketch plane,
1286 // thus, need to check whether B-spline is planar.
1287 std::list<GeomPointPtr> aPoles = aBSpline->poles();
1288 for (std::list<GeomPointPtr>::iterator it = aPoles.begin();
1289 it != aPoles.end() && !aValid; ++it) {
1290 if (aBSplinePlane->distance(*it) > tolerance)
1291 aValid = true; // non-planar B-spline curve
1294 theError = "Error: Periodic B-spline is orthogonal to the sketch plane.";
1304 static std::set<FeaturePtr> common(const std::set<FeaturePtr>& theSet1,
1305 const std::set<FeaturePtr>& theSet2)
1307 std::set<FeaturePtr> aCommon;
1308 if (theSet1.empty() || theSet2.empty())
1311 std::set<FeaturePtr>::const_iterator anIt2 = theSet2.begin();
1312 for (; anIt2 != theSet2.end(); ++anIt2)
1313 if (theSet1.find(*anIt2) != theSet1.end())
1314 aCommon.insert(*anIt2);
1318 bool SketchPlugin_DifferentReferenceValidator::isValid(
1319 const AttributePtr& theAttribute,
1320 const std::list<std::string>& theArguments,
1321 Events_InfoMessage& theError) const
1323 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
1325 int aNbFeaturesReferred = 0;
1326 int aNbAttributesReferred = 0;
1327 std::set<FeaturePtr> aCommonReferredFeatures;
1329 // find all features referred by attributes listed in theArguments
1330 std::list<std::string>::const_iterator anArgIt = theArguments.begin();
1331 for (; anArgIt != theArguments.end(); ++anArgIt) {
1332 AttributeRefAttrPtr aRefAttr = anOwner->refattr(*anArgIt);
1336 std::set<FeaturePtr> aCoincidentFeatures;
1337 if (aRefAttr->isObject()) {
1338 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
1340 aCoincidentFeatures.insert(aFeature);
1341 aNbFeaturesReferred += 1;
1344 AttributePoint2DPtr aPoint =
1345 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aRefAttr->attr());
1347 aCoincidentFeatures = SketchPlugin_Tools::findFeaturesCoincidentToPoint(aPoint);
1348 aNbAttributesReferred += 1;
1352 if (aCommonReferredFeatures.empty())
1353 aCommonReferredFeatures = aCoincidentFeatures;
1355 aCommonReferredFeatures = common(aCommonReferredFeatures, aCoincidentFeatures);
1357 if (aCommonReferredFeatures.empty())
1361 bool isOk = aNbFeaturesReferred < 1;
1362 if (aNbFeaturesReferred == 1) {
1363 if (aCommonReferredFeatures.size() == 1) {
1364 FeaturePtr aFeature = *aCommonReferredFeatures.begin();
1365 isOk = aNbAttributesReferred <= 1 ||
1366 aFeature->getKind() == SketchPlugin_Circle::ID() ||
1367 aFeature->getKind() == SketchPlugin_Arc::ID();
1373 theError = "Attributes are referred to the same feature";
1377 bool SketchPlugin_DifferentPointReferenceValidator::isValid(
1378 const AttributePtr& theAttribute,
1379 const std::list<std::string>& theArguments,
1380 Events_InfoMessage& theError) const
1382 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
1383 std::set<AttributePoint2DPtr> aReferredCoincidentPoints;
1385 // find all points referred by attributes listed in theArguments
1386 bool hasRefsToPoints = false;
1387 std::list<std::string>::const_iterator anArgIt = theArguments.begin();
1388 for (; anArgIt != theArguments.end(); ++anArgIt) {
1389 AttributeRefAttrPtr aRefAttr = anOwner->refattr(*anArgIt);
1393 if (!aRefAttr->isObject()) {
1394 AttributePoint2DPtr aPoint =
1395 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aRefAttr->attr());
1396 if (aReferredCoincidentPoints.empty())
1397 aReferredCoincidentPoints = SketchPlugin_Tools::findPointsCoincidentToPoint(aPoint);
1398 else if (aReferredCoincidentPoints.find(aPoint) == aReferredCoincidentPoints.end())
1399 return true; // non-coincident point has been found
1401 hasRefsToPoints = true;
1405 if (hasRefsToPoints)
1406 theError = "Attributes are referred to the same point";
1407 return !hasRefsToPoints;
1410 bool SketchPlugin_CirclePassedPointValidator::isValid(
1411 const AttributePtr& theAttribute,
1412 const std::list<std::string>&,
1413 Events_InfoMessage& theError) const
1415 static const std::string aErrorMessage(
1416 "Passed point refers to the same feature as a center point");
1418 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
1420 AttributeRefAttrPtr aCenterRef =
1421 anOwner->refattr(SketchPlugin_MacroCircle::CENTER_POINT_REF_ID());
1422 AttributeRefAttrPtr aPassedRef =
1423 anOwner->refattr(SketchPlugin_MacroCircle::PASSED_POINT_REF_ID());
1425 if (!aPassedRef->isObject())
1428 FeaturePtr aPassedFeature = ModelAPI_Feature::feature(aPassedRef->object());
1429 if (!aPassedFeature)
1432 if (aCenterRef->isObject()) {
1433 if (aCenterRef->object() == aPassedRef->object()) {
1434 theError = aErrorMessage;
1438 AttributePoint2DPtr aCenterPoint =
1439 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aCenterRef->attr());
1441 std::set<FeaturePtr> aCoincidentFeatures =
1442 SketchPlugin_Tools::findFeaturesCoincidentToPoint(aCenterPoint);
1443 // check one of coincident features is a feature referred by passed point
1444 std::set<FeaturePtr>::const_iterator anIt = aCoincidentFeatures.begin();
1445 for(; anIt != aCoincidentFeatures.end(); ++anIt)
1446 if (*anIt == aPassedFeature) {
1447 theError = aErrorMessage;
1455 bool SketchPlugin_ThirdPointValidator::isValid(
1456 const AttributePtr& theAttribute,
1457 const std::list<std::string>& theArguments,
1458 Events_InfoMessage& theError) const
1460 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
1461 return arePointsNotOnLine(anOwner, theError) &&
1462 arePointsNotSeparated(anOwner, theArguments, theError);
1465 static std::shared_ptr<GeomAPI_Pnt2d> toPoint(const FeaturePtr& theMacroCircle,
1466 const std::string& thePointAttrName,
1467 const std::string& theRefPointAttrName)
1469 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1470 theMacroCircle->attribute(thePointAttrName));
1471 AttributeRefAttrPtr aRefAttr = theMacroCircle->refattr(theRefPointAttrName);
1473 std::shared_ptr<GeomAPI_Pnt2d> aPoint = aPointAttr->pnt();
1475 if (aRefAttr->isObject()) {
1476 // project a point onto selected feature
1477 std::shared_ptr<SketchPlugin_Feature> aFeature =
1478 std::dynamic_pointer_cast<SketchPlugin_Feature>(
1479 ModelAPI_Feature::feature(aRefAttr->object()));
1481 SketchPlugin_Sketch* aSketch = aFeature->sketch();
1482 std::shared_ptr<GeomAPI_Edge> anEdge =
1483 std::dynamic_pointer_cast<GeomAPI_Edge>(aFeature->lastResult()->shape());
1485 std::shared_ptr<GeomAPI_Pnt> aPoint3D = aSketch->to3D(aPoint->x(), aPoint->y());
1486 if (anEdge->isLine())
1487 aPoint3D = anEdge->line()->project(aPoint3D);
1488 else if (anEdge->isCircle())
1489 aPoint3D = anEdge->circle()->project(aPoint3D);
1491 aPoint = aSketch->to2D(aPoint3D);
1495 AttributePoint2DPtr anOtherPoint =
1496 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aRefAttr->attr());
1498 aPoint = anOtherPoint->pnt(); // the reference point is much more precise, use it
1505 static void threePointsOfFeature(const FeaturePtr& theMacroFeature,
1506 std::shared_ptr<GeomAPI_Pnt2d> thePoints[3])
1508 if (theMacroFeature->getKind() == SketchPlugin_MacroCircle::ID()) {
1509 thePoints[0] = toPoint(theMacroFeature,
1510 SketchPlugin_MacroCircle::FIRST_POINT_ID(),
1511 SketchPlugin_MacroCircle::FIRST_POINT_REF_ID());
1512 thePoints[1] = toPoint(theMacroFeature,
1513 SketchPlugin_MacroCircle::SECOND_POINT_ID(),
1514 SketchPlugin_MacroCircle::SECOND_POINT_REF_ID());
1515 thePoints[2] = toPoint(theMacroFeature,
1516 SketchPlugin_MacroCircle::THIRD_POINT_ID(),
1517 SketchPlugin_MacroCircle::THIRD_POINT_REF_ID());
1518 } else if (theMacroFeature->getKind() == SketchPlugin_MacroArc::ID()) {
1519 thePoints[0] = toPoint(theMacroFeature,
1520 SketchPlugin_MacroArc::START_POINT_2_ID(),
1521 SketchPlugin_MacroArc::START_POINT_REF_ID());
1522 thePoints[1] = toPoint(theMacroFeature,
1523 SketchPlugin_MacroArc::END_POINT_2_ID(),
1524 SketchPlugin_MacroArc::END_POINT_REF_ID());
1525 thePoints[2] = toPoint(theMacroFeature,
1526 SketchPlugin_MacroArc::PASSED_POINT_ID(),
1527 SketchPlugin_MacroArc::PASSED_POINT_REF_ID());
1531 static bool isPointsOnLine(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
1532 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
1533 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
1535 static const double aTolerance = 1.e-7;
1536 if (thePoint1->distance(thePoint2) < aTolerance ||
1537 thePoint1->distance(thePoint3) < aTolerance)
1540 std::shared_ptr<GeomAPI_Dir2d> aDirP1P2(new GeomAPI_Dir2d(thePoint2->x() - thePoint1->x(),
1541 thePoint2->y() - thePoint1->y()));
1542 std::shared_ptr<GeomAPI_Dir2d> aDirP1P3(new GeomAPI_Dir2d(thePoint3->x() - thePoint1->x(),
1543 thePoint3->y() - thePoint1->y()));
1544 return fabs(aDirP1P2->cross(aDirP1P3)) < aTolerance;
1547 static bool isOnSameSide(const std::shared_ptr<GeomAPI_Lin>& theLine,
1548 const std::shared_ptr<GeomAPI_Pnt>& thePoint1,
1549 const std::shared_ptr<GeomAPI_Pnt>& thePoint2)
1551 static const double aTolerance = 1.e-7;
1552 std::shared_ptr<GeomAPI_Dir> aLineDir = theLine->direction();
1553 std::shared_ptr<GeomAPI_XYZ> aLineLoc = theLine->location()->xyz();
1555 std::shared_ptr<GeomAPI_XYZ> aVec1 = thePoint1->xyz()->decreased(aLineLoc);
1556 // the first point is on the line
1557 if (aVec1->squareModulus() < aTolerance * aTolerance)
1559 std::shared_ptr<GeomAPI_Dir> aDirP1L(new GeomAPI_Dir(aVec1));
1560 std::shared_ptr<GeomAPI_XYZ> aVec2 = thePoint2->xyz()->decreased(aLineLoc);
1561 // the second point is on the line
1562 if (aVec2->squareModulus() < aTolerance * aTolerance)
1564 std::shared_ptr<GeomAPI_Dir> aDirP2L(new GeomAPI_Dir(aVec2));
1566 return aLineDir->cross(aDirP1L)->dot(aLineDir->cross(aDirP2L)) > -aTolerance;
1569 static bool isOnSameSide(const std::shared_ptr<GeomAPI_Circ>& theCircle,
1570 const std::shared_ptr<GeomAPI_Pnt>& thePoint1,
1571 const std::shared_ptr<GeomAPI_Pnt>& thePoint2)
1573 static const double aTolerance = 1.e-7;
1574 std::shared_ptr<GeomAPI_Pnt> aCenter = theCircle->center();
1575 double aDistP1C = thePoint1->distance(aCenter);
1576 double aDistP2C = thePoint2->distance(aCenter);
1577 return (aDistP1C - theCircle->radius()) * (aDistP2C - theCircle->radius()) > -aTolerance;
1580 bool SketchPlugin_ThirdPointValidator::arePointsNotOnLine(
1581 const FeaturePtr& theMacroFeature,
1582 Events_InfoMessage& theError) const
1584 static const std::string aErrorPointsOnLine(
1585 "Selected points are on the same line");
1587 std::shared_ptr<GeomAPI_Pnt2d> aPoints[3];
1588 threePointsOfFeature(theMacroFeature, aPoints);
1590 if (isPointsOnLine(aPoints[0], aPoints[1], aPoints[2])) {
1591 theError = aErrorPointsOnLine;
1597 bool SketchPlugin_ThirdPointValidator::arePointsNotSeparated(
1598 const FeaturePtr& theMacroFeature,
1599 const std::list<std::string>& theArguments,
1600 Events_InfoMessage& theError) const
1602 static const std::string aErrorPointsApart(
1603 "Selected entity is lying between first two points");
1605 AttributeRefAttrPtr aThirdPointRef = theMacroFeature->refattr(theArguments.front());
1606 FeaturePtr aRefByThird;
1607 if (aThirdPointRef->isObject())
1608 aRefByThird = ModelAPI_Feature::feature(aThirdPointRef->object());
1612 std::shared_ptr<GeomAPI_Pnt2d> aPoints[3];
1613 threePointsOfFeature(theMacroFeature, aPoints);
1615 std::shared_ptr<GeomAPI_Edge> aThirdShape =
1616 std::dynamic_pointer_cast<GeomAPI_Edge>(aRefByThird->lastResult()->shape());
1620 SketchPlugin_Sketch* aSketch =
1621 std::dynamic_pointer_cast<SketchPlugin_Feature>(theMacroFeature)->sketch();
1622 std::shared_ptr<GeomAPI_Pnt> aFirstPnt3D = aSketch->to3D(aPoints[0]->x(), aPoints[0]->y());
1623 std::shared_ptr<GeomAPI_Pnt> aSecondPnt3D = aSketch->to3D(aPoints[1]->x(), aPoints[1]->y());
1626 if (aThirdShape->isLine())
1627 isOk = isOnSameSide(aThirdShape->line(), aFirstPnt3D, aSecondPnt3D);
1628 else if (aThirdShape->isCircle() || aThirdShape->isArc())
1629 isOk = isOnSameSide(aThirdShape->circle(), aFirstPnt3D, aSecondPnt3D);
1632 theError = aErrorPointsApart;
1636 bool SketchPlugin_ArcEndPointValidator::isValid(
1637 const AttributePtr& theAttribute,
1638 const std::list<std::string>& theArguments,
1639 Events_InfoMessage& theError) const
1641 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
1642 AttributeRefAttrPtr anEndPointRef = aFeature->refattr(theArguments.front());
1644 if(!anEndPointRef.get()) {
1648 ObjectPtr anObject = anEndPointRef->object();
1649 AttributePtr anAttr = anEndPointRef->attr();
1650 if(!anObject.get() && !anAttr.get()) {
1654 if(anEndPointRef->attr().get()) {
1658 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1660 GeomShapePtr aShape = aResult->shape();
1661 if(aShape.get() && aShape->isVertex()) {
1666 aFeature = ModelAPI_Feature::feature(anObject);
1667 if(aFeature.get()) {
1668 if(aFeature->getKind() == SketchPlugin_Point::ID()) {
1676 static GeomShapePtr toInfiniteEdge(const GeomShapePtr theShape)
1678 if(!theShape.get()) {
1682 if(!theShape->isEdge()) {
1686 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
1692 if(anEdge->isLine()) {
1693 std::shared_ptr<GeomAPI_Lin> aLine = anEdge->line();
1694 GeomShapePtr aShape = GeomAlgoAPI_EdgeBuilder::line(aLine);
1698 if(anEdge->isCircle() || anEdge->isArc()) {
1699 std::shared_ptr<GeomAPI_Circ> aCircle = anEdge->circle();
1700 GeomShapePtr aShape = GeomAlgoAPI_EdgeBuilder::lineCircle(aCircle);
1707 bool SketchPlugin_ArcEndPointIntersectionValidator::isValid(
1708 const AttributePtr& theAttribute,
1709 const std::list<std::string>& theArguments,
1710 Events_InfoMessage& theError) const
1712 std::shared_ptr<SketchPlugin_MacroArc> anArcFeature =
1713 std::dynamic_pointer_cast<SketchPlugin_MacroArc>(theAttribute->owner());
1714 AttributeRefAttrPtr anEndPointRef = anArcFeature->refattr(theArguments.front());
1716 if(!anEndPointRef.get()) {
1720 GeomShapePtr anArcShape = toInfiniteEdge(anArcFeature->getArcShape(false));
1722 if(!anArcShape.get() || anArcShape->isNull()) {
1726 ObjectPtr anObject = anEndPointRef->object();
1727 AttributePtr anAttr = anEndPointRef->attr();
1728 if(!anObject.get() && !anAttr.get()) {
1732 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1734 GeomShapePtr aShape = aResult->shape();
1735 if (!aShape->isEdge())
1737 aShape = toInfiniteEdge(aShape);
1738 if(aShape.get() && !aShape->isNull()) {
1739 if(anArcShape->isIntersect(aShape)) {
1745 FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(anObject);
1746 if(aSelectedFeature.get()) {
1747 std::list<ResultPtr> aResults = aSelectedFeature->results();
1748 for(std::list<ResultPtr>::const_iterator anIt = aResults.cbegin();
1749 anIt != aResults.cend();
1752 GeomShapePtr aShape = (*anIt)->shape();
1753 if (!aShape->isEdge())
1755 aShape = toInfiniteEdge(aShape);
1756 if(aShape.get() && !aShape->isNull()) {
1757 if(anArcShape->isIntersect(aShape)) {
1767 bool SketchPlugin_HasNoConstraint::isValid(const AttributePtr& theAttribute,
1768 const std::list<std::string>& theArguments,
1769 Events_InfoMessage& theError) const
1771 std::set<std::string> aFeatureKinds;
1772 for (std::list<std::string>::const_iterator anArgIt = theArguments.begin();
1773 anArgIt != theArguments.end(); anArgIt++) {
1774 aFeatureKinds.insert(*anArgIt);
1777 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
1778 theError = "The attribute with the %1 type is not processed";
1779 theError.arg(theAttribute->attributeType());
1783 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
1785 bool isObject = aRefAttr->isObject();
1787 theError = "It uses an empty object";
1790 ObjectPtr anObject = aRefAttr->object();
1791 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1792 if (!aFeature.get()) {
1793 theError = "The feature of the checked attribute is empty";
1797 FeaturePtr aCurrentFeature = ModelAPI_Feature::feature(aRefAttr->owner());
1799 std::set<AttributePtr> aRefsList = anObject->data()->refsToMe();
1800 std::set<AttributePtr>::const_iterator anIt = aRefsList.begin();
1801 for (; anIt != aRefsList.end(); anIt++) {
1802 FeaturePtr aRefFeature = ModelAPI_Feature::feature((*anIt)->owner());
1803 if (aRefFeature.get() && aCurrentFeature != aRefFeature &&
1804 aFeatureKinds.find(aRefFeature->getKind()) != aFeatureKinds.end())
1805 return false; // constraint is found, that means that the check is not valid
1810 bool SketchPlugin_ReplicationReferenceValidator::isValid(
1811 const AttributePtr& theAttribute,
1812 const std::list<std::string>& theArguments,
1813 Events_InfoMessage& theError) const
1815 AttributeRefAttrPtr aRefAttr =
1816 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
1819 theError = "Incorrect attribute";
1824 if (aRefAttr->isObject())
1825 anOwner = aRefAttr->object();
1828 AttributePtr anAttr = aRefAttr->attr();
1829 anOwner = anAttr->owner();
1831 FeaturePtr anAttrOwnerFeature = ModelAPI_Feature::feature(anOwner);
1832 if (!anAttrOwnerFeature)
1834 AttributeBooleanPtr aCopyAttr = anAttrOwnerFeature->boolean(SketchPlugin_SketchEntity::COPY_ID());
1835 if (!aCopyAttr || !aCopyAttr->value())
1836 return true; // feature is not a copy, thus valid
1838 FeaturePtr aMultiFeature = ModelAPI_Feature::feature(theAttribute->owner());
1839 // Collect original entities
1840 std::set<FeaturePtr> anOriginalFeatures;
1841 if (theArguments.size() > 1) {
1842 AttributeRefListPtr anOrigList = aMultiFeature->reflist(theArguments.back());
1843 for (int i = 0; i < anOrigList->size(); ++i)
1845 FeaturePtr aFeature = ModelAPI_Feature::feature(anOrigList->object(i));
1846 if (aFeature == anAttrOwnerFeature)
1851 // check the copy feature is already referred by the "Multi" feature
1852 AttributeRefListPtr aRefList = aMultiFeature->reflist(theArguments.front());
1853 for (int i = 0; i < aRefList->size(); ++i)
1855 FeaturePtr aRefOwner = ModelAPI_Feature::feature(aRefList->object(i));
1856 if (aRefOwner == anAttrOwnerFeature)
1858 theError = "Attribute refers to the object generated by this feature";
1866 bool SketchPlugin_SketchFeatureValidator::isValid(const AttributePtr& theAttribute,
1867 const std::list<std::string>& theArguments,
1868 Events_InfoMessage& theError) const
1870 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId() &&
1871 theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
1872 theError = "The attribute with the %1 type is not processed";
1873 theError.arg(theAttribute->attributeType());
1877 // check the attribute refers to a sketch feature
1878 bool isSketchFeature = false;
1879 AttributeRefAttrPtr aRefAttr =
1880 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
1882 isSketchFeature = aRefAttr->isObject();
1883 if (isSketchFeature) {
1884 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
1885 isSketchFeature = aFeature.get() != NULL;
1886 if (isSketchFeature) {
1887 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1888 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1889 isSketchFeature = aSketchFeature.get() != NULL;
1894 AttributeReferencePtr aReference =
1895 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
1897 FeaturePtr aFeature = ModelAPI_Feature::feature(aReference->value());
1898 isSketchFeature = aFeature.get() && aFeature->getKind() == SketchPlugin_Sketch::ID();
1902 if (!isSketchFeature)
1903 theError = "The object selected is not a sketch feature";
1904 return isSketchFeature;
1907 bool SketchPlugin_MultiRotationAngleValidator::isValid(const AttributePtr& theAttribute,
1908 const std::list<std::string>& theArguments,
1909 Events_InfoMessage& theError) const
1911 if (theAttribute->attributeType() != ModelAPI_AttributeDouble::typeId()) {
1912 theError = "The attribute with the %1 type is not processed";
1913 theError.arg(theAttribute->attributeType());
1917 AttributeDoublePtr anAngleAttr =
1918 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
1920 FeaturePtr aMultiRotation = ModelAPI_Feature::feature(theAttribute->owner());
1921 AttributeStringPtr anAngleType =
1922 aMultiRotation->string(SketchPlugin_MultiRotation::ANGLE_TYPE());
1923 AttributeIntegerPtr aNbCopies =
1924 aMultiRotation->integer(SketchPlugin_MultiRotation::NUMBER_OF_OBJECTS_ID());
1926 if (anAngleType->value() != "FullAngle")
1928 double aFullAngleValue = anAngleAttr->value() * (aNbCopies->value() - 1);
1929 if (aFullAngleValue < -1.e-7 || aFullAngleValue > 359.9999999)
1931 theError = "Rotation single angle should produce full angle less than 360 degree";
1937 double aFullAngleValue = anAngleAttr->value();
1938 if (aFullAngleValue < -1.e-7 || aFullAngleValue > 360.0000001)
1940 theError = "Rotation full angle should be in range [0, 360]";
1948 bool SketchPlugin_BSplineValidator::isValid(const AttributePtr& theAttribute,
1949 const std::list<std::string>& theArguments,
1950 Events_InfoMessage& theError) const
1952 AttributePoint2DArrayPtr aPolesArray =
1953 std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(theAttribute);
1957 if (aPolesArray->size() < 2) {
1958 theError = "Number of B-spline poles should be 2 or more";
1965 bool SketchPlugin_CurveFittingValidator::isValid(const FeaturePtr& theFeature,
1966 const std::list<std::string>& theArguments,
1967 Events_InfoMessage& theError) const
1969 AttributeRefAttrListPtr aRefAttrList =
1970 theFeature->refattrlist(SketchPlugin_CurveFitting::POINTS_ID());
1971 AttributeBooleanPtr aPeriodicAttr =
1972 theFeature->boolean(SketchPlugin_CurveFitting::PERIODIC_ID());
1974 // check number of selected entities
1975 int aMinNbPoints = aPeriodicAttr->value() ? 3 : 2;
1976 if (aRefAttrList->size() < aMinNbPoints) {
1977 theError = "Not enough points selected. Need at least %1 points.";
1978 theError.arg(aMinNbPoints);