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_Line.h"
35 #include "SketchPlugin_MacroArc.h"
36 #include "SketchPlugin_MacroCircle.h"
37 #include "SketchPlugin_MultiRotation.h"
38 #include "SketchPlugin_Point.h"
39 #include "SketchPlugin_Sketch.h"
40 #include "SketchPlugin_Trim.h"
41 #include "SketchPlugin_Tools.h"
43 #include "SketcherPrs_Tools.h"
45 #include <Events_InfoMessage.h>
47 #include <ModelAPI_Data.h>
48 #include <ModelAPI_Validator.h>
49 #include <ModelAPI_AttributeDouble.h>
50 #include <ModelAPI_AttributeInteger.h>
51 #include <ModelAPI_AttributeRefAttr.h>
52 #include <ModelAPI_AttributeRefList.h>
53 #include <ModelAPI_AttributeSelectionList.h>
54 #include <ModelAPI_AttributeString.h>
55 #include <ModelAPI_Session.h>
56 #include <ModelAPI_Tools.h>
57 #include <ModelAPI_ResultConstruction.h>
59 #include <ModelGeomAlgo_Point2D.h>
60 #include <ModelGeomAlgo_Shape.h>
62 #include <GeomAlgoAPI_EdgeBuilder.h>
63 #include <GeomAlgoAPI_ShapeTools.h>
65 #include <GeomAPI_Circ.h>
66 #include <GeomAPI_Dir2d.h>
67 #include <GeomAPI_Ellipse.h>
68 #include <GeomAPI_Lin.h>
69 #include <GeomAPI_Edge.h>
70 #include <GeomAPI_Vertex.h>
72 #include <GeomDataAPI_Point2D.h>
73 #include <GeomDataAPI_Point2DArray.h>
79 #pragma warning(disable: 4100)
82 const double tolerance = 1.e-7;
84 static bool isSpline(FeaturePtr theFeature)
86 return theFeature && (theFeature->getKind() == SketchPlugin_BSpline::ID() ||
87 theFeature->getKind() == SketchPlugin_BSplinePeriodic::ID());
91 bool SketchPlugin_DistanceAttrValidator::isValid(const AttributePtr& theAttribute,
92 const std::list<std::string>& theArguments,
93 Events_InfoMessage& theError) const
95 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
96 theError = "The attribute with the %1 type is not processed";
97 theError.arg(theAttribute->attributeType());
101 // there is a check whether the feature contains a point and a linear edge or two point values
102 std::string aParamA = theArguments.front();
103 SessionPtr aMgr = ModelAPI_Session::get();
104 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
106 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
108 bool isObject = aRefAttr->isObject();
110 // an attribute is a point. A point value is valid always for the distance
113 // 1. check whether the references object is a linear
114 ObjectPtr anObject = aRefAttr->object();
116 const ModelAPI_AttributeValidator* aShapeValidator =
117 dynamic_cast<const ModelAPI_AttributeValidator*>(
118 aFactory->validator("GeomValidators_ShapeType"));
119 std::list<std::string> anArguments;
120 anArguments.push_back("circle");
121 Events_InfoMessage aCircleError;
122 bool aShapeValid = aShapeValidator->isValid(aRefAttr, anArguments, aCircleError);
123 // the circle line is not a valid case
125 theError = "Circle can not be used in distance constraint";
130 anArguments.push_back("line");
131 Events_InfoMessage aLineError;
132 aShapeValid = aShapeValidator->isValid(aRefAttr, anArguments, aLineError);
133 // if the attribute value is not a line, that means it is a vertex. A vertex is always valid
135 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
136 // If it is a line then we have to check that first attribute id not a line
137 std::shared_ptr<SketchPlugin_Feature> aSFeature =
138 std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
139 SketchPlugin_Sketch* aSketch = aSFeature->sketch();
140 std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(aSketch);
141 std::shared_ptr<GeomDataAPI_Point2D> aPoint = SketcherPrs_Tools::getFeaturePoint(
142 aFeature->data(), aParamA, aPlane);
144 theError = "One of parameters of distance constraint should be a point";
152 bool SketchPlugin_TangentAttrValidator::isValid(const AttributePtr& theAttribute,
153 const std::list<std::string>& theArguments,
154 Events_InfoMessage& theError) const
156 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
157 theError = "The attribute with the %1 type is not processed";
158 theError.arg(theAttribute->attributeType());
162 // there is a check whether the feature contains a point and a linear edge or two point values
163 std::string aParamA = theArguments.front();
165 FeaturePtr anAttributeFeature =
166 std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
167 AttributeRefAttrPtr aRefAttr =
168 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
170 bool isObject = aRefAttr->isObject();
171 ObjectPtr anObject = aRefAttr->object();
172 if (!isObject || !anObject.get()) {
173 theError = "It uses an empty object";
177 FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject);
179 AttributeRefAttrPtr aOtherAttr = anAttributeFeature->data()->refattr(aParamA);
180 ObjectPtr aOtherObject = aOtherAttr->object();
181 FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject);
185 if (aRefFea->getKind() == SketchPlugin_Line::ID() &&
186 aOtherFea->getKind() == SketchPlugin_Line::ID()) {
187 theError = "Two segments cannot be tangent";
190 else if (isSpline(aRefFea) && isSpline(aOtherFea)) {
191 theError = "Two B-splines cannot be tangent";
196 bool hasSpline = isSpline(aRefFea);
197 if (!hasSpline && isSpline(aOtherFea)) {
199 std::swap(aRefFea, aOtherFea);
202 auto isApplicableCoincidence = [](FeaturePtr theFeature, const std::string& theAttrName) {
203 AttributeRefAttrPtr aRefAttr = theFeature->refattr(theAttrName);
204 if (aRefAttr->isObject())
206 AttributePtr anAttr = aRefAttr->attr();
207 FeaturePtr anOwner = ModelAPI_Feature::feature(anAttr->owner());
208 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr);
210 return anOwner->getKind() == SketchPlugin_BSpline::ID() &&
211 (aPointAttr->id() == SketchPlugin_BSpline::START_ID() ||
212 aPointAttr->id() == SketchPlugin_BSpline::END_ID());
215 AttributePoint2DArrayPtr aPntArray =
216 std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(anAttr);
217 if (aPntArray && anOwner->getKind() == SketchPlugin_BSpline::ID()) {
218 // check index of the pole
219 AttributeIntegerPtr anIndex = theAttrName == SketchPlugin_Constraint::ENTITY_A() ?
220 theFeature->integer(SketchPlugin_ConstraintCoincidenceInternal::INDEX_ENTITY_A()) :
221 theFeature->integer(SketchPlugin_ConstraintCoincidenceInternal::INDEX_ENTITY_B());
222 return anIndex && (anIndex->value() == 0 || anIndex->value() == aPntArray->size() - 1);
228 AttributePoint2DArrayPtr aBSplinePoles = std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(
229 aRefFea->attribute(SketchPlugin_BSplineBase::POLES_ID()));
230 // additional check the B-spline edge and the other edge have a coincident boundary point
231 std::set<FeaturePtr> aCoincidences = SketchPlugin_Tools::findCoincidentConstraints(aRefFea);
232 for (std::set<FeaturePtr>::iterator anIt = aCoincidences.begin();
233 anIt != aCoincidences.end() && !isValid; ++anIt) {
234 std::set<FeaturePtr> aCoinc;
235 if (isApplicableCoincidence(*anIt, SketchPlugin_Constraint::ENTITY_A()))
236 SketchPlugin_Tools::findCoincidences(*anIt, SketchPlugin_Constraint::ENTITY_B(),
238 else if (isApplicableCoincidence(*anIt, SketchPlugin_Constraint::ENTITY_B()))
239 SketchPlugin_Tools::findCoincidences(*anIt, SketchPlugin_Constraint::ENTITY_A(),
242 isValid = aCoinc.find(aOtherFea) != aCoinc.end();
249 bool SketchPlugin_PerpendicularAttrValidator::isValid(const AttributePtr& theAttribute,
250 const std::list<std::string>& theArguments,
251 Events_InfoMessage& theError) const
253 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
254 theError = "The attribute with the %1 type is not processed";
255 theError.arg(theAttribute->attributeType());
259 std::string aParamA = theArguments.front();
261 FeaturePtr anOwner = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
262 AttributeRefAttrPtr aRefAttr =
263 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
265 bool isObject = aRefAttr->isObject();
266 ObjectPtr anObject = aRefAttr->object();
267 if (isObject && anObject.get()) {
268 FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject);
270 AttributeRefAttrPtr aOtherAttr = anOwner->refattr(aParamA);
271 ObjectPtr aOtherObject = aOtherAttr->object();
272 FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject);
274 // at least one feature should be a line
275 if (aRefFea->getKind() != SketchPlugin_Line::ID() &&
276 aOtherFea && aOtherFea->getKind() != SketchPlugin_Line::ID()) {
277 theError = "At least one feature should be a line";
280 else if (isSpline(aRefFea) || isSpline(aOtherFea)) {
281 theError = "B-spline is not supported";
286 theError = "It uses an empty object";
293 bool SketchPlugin_NotFixedValidator::isValid(const AttributePtr& theAttribute,
294 const std::list<std::string>& theArguments,
295 Events_InfoMessage& theError) const
297 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
298 theError = "The attribute with the %1 type is not processed";
299 theError.arg(theAttribute->attributeType());
303 std::shared_ptr<SketchPlugin_Feature> aFeature =
304 std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
308 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
310 SketchPlugin_Sketch* aSketch = aFeature->sketch();
311 int aNbFeatures = aSketch->numberOfSubs();
312 for (int anInd = 0; anInd < aNbFeatures; anInd++) {
313 FeaturePtr aSubFeature = aSketch->subFeature(anInd);
314 if (aSubFeature->getKind() != SketchPlugin_ConstraintRigid::ID() || aSubFeature == aFeature)
316 AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
317 aSubFeature->attribute(SketchPlugin_ConstraintRigid::ENTITY_A()));
318 if (aRefAttr->isObject()) {
319 if (aRefAttr->object() == aRAttr->object()) {
320 ObjectPtr anObject = aRefAttr->object();
321 std::string aName = anObject.get() ? anObject->data()->name() : "";
322 theError = "The object %1 has been already fixed.";
327 else if (aRefAttr->attr() == aRAttr->attr()) {
328 AttributePtr anAttribute = aRefAttr->attr();
329 std::string aName = anAttribute.get() ? anAttribute->id() : "";
330 theError = "The attribute %1 has been already fixed.";
338 bool SketchPlugin_EqualAttrValidator::isValid(const AttributePtr& theAttribute,
339 const std::list<std::string>& theArguments,
340 Events_InfoMessage& theError) const
342 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
343 theError = "The attribute with the %1 type is not processed";
344 theError.arg(theAttribute->attributeType());
348 std::string aParamA = theArguments.front();
349 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
350 AttributeRefAttrPtr aRefAttr[2];
351 aRefAttr[0] = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
352 aRefAttr[1] = aFeature->data()->refattr(aParamA);
354 if (!aRefAttr[0]->isObject() || !aRefAttr[1]->isObject()) {
355 theError = "Attributes can not be used in equal constraint";
359 std::string aType[2];
360 std::list<std::string> anArguments;
361 for (int i = 0; i < 2; i++) {
362 aFeature = ModelAPI_Feature::feature(aRefAttr[i]->object());
366 aType[i] = aFeature->getKind();
367 if (aFeature->getKind() != SketchPlugin_Line::ID() &&
368 aFeature->getKind() != SketchPlugin_Circle::ID() &&
369 aFeature->getKind() != SketchPlugin_Arc::ID() &&
370 aFeature->getKind() != SketchPlugin_Ellipse::ID() &&
371 aFeature->getKind() != SketchPlugin_EllipticArc::ID()) {
372 theError = "The %1 feature is not supported by the Equal constraint.";
373 theError.arg(aFeature->getKind());
374 // wrong type of attribute
379 bool isOk = aType[0] == aType[1];
381 // circle and arc may be equal
382 isOk = (aType[0] == SketchPlugin_Arc::ID() && aType[1] == SketchPlugin_Circle::ID())
383 || (aType[0] == SketchPlugin_Circle::ID() && aType[1] == SketchPlugin_Arc::ID());
386 // ellipse and elliptic arc may be equal
387 isOk = (aType[0] == SketchPlugin_EllipticArc::ID() && aType[1] == SketchPlugin_Ellipse::ID())
388 || (aType[0] == SketchPlugin_Ellipse::ID() && aType[1] == SketchPlugin_EllipticArc::ID());
391 theError = "Features with kinds %1 and %2 can not be equal.";
392 theError.arg(aType[0]).arg(aType[1]);
398 bool SketchPlugin_MirrorAttrValidator::isValid(const AttributePtr& theAttribute,
399 const std::list<std::string>& theArguments,
400 Events_InfoMessage& theError) const
402 if (theAttribute->attributeType() != ModelAPI_AttributeRefList::typeId()) {
403 theError = "The attribute with the %1 type is not processed";
404 theError.arg(theAttribute->attributeType());
408 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
409 AttributeRefListPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
411 AttributeRefListPtr aRefListOfMirrored = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
412 aFeature->attribute(SketchPlugin_Constraint::ENTITY_C()));
413 std::list<ObjectPtr> aMirroredObjects = aRefListOfMirrored->list();
415 for(int anInd = 0; anInd < aSelAttr->size(); anInd++) {
416 ObjectPtr aSelObject = aSelAttr->object(anInd);
418 // B-splines are not supported in Mirror yet
419 FeaturePtr aSelFeature = ModelAPI_Feature::feature(aSelObject);
420 if (aSelFeature && (aSelFeature->getKind() == SketchPlugin_BSpline::ID() ||
421 aSelFeature->getKind() == SketchPlugin_BSplinePeriodic::ID())) {
422 theError = "Not supported";
426 std::string aName = aSelObject.get() ? aSelObject->data()->name() : "";
427 std::list<ObjectPtr>::iterator aMirIter = aMirroredObjects.begin();
428 for (; aMirIter != aMirroredObjects.end(); aMirIter++)
429 if (aSelObject == *aMirIter) {
430 theError = "The object %1 is a result of mirror";
438 bool SketchPlugin_CoincidenceAttrValidator::isValid(const AttributePtr& theAttribute,
439 const std::list<std::string>& theArguments,
440 Events_InfoMessage& theError) const
442 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
443 theError = "The attribute with the %1 type is not processed";
444 theError.arg(theAttribute->attributeType());
448 // there is a check whether the feature contains a point and a linear edge or two point values
449 std::string aParamA = theArguments.front();
451 FeaturePtr aConstraint = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
452 AttributeRefAttrPtr aRefAttrA = aConstraint->data()->refattr(aParamA);
454 theError = "The %1 attribute should be %2";
455 theError.arg(aParamA).arg(ModelAPI_AttributeRefAttr::typeId());
459 AttributeRefAttrPtr aRefAttrB =
460 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
462 // first attribute is a point, it may coincide with any object
463 if (!aRefAttrA->isObject())
466 ObjectPtr anObject = aRefAttrA->object();
467 if (!anObject.get()) {
468 theError = "%1 attribute has an empty object";
469 theError.arg(aParamA);
472 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrA->object());
473 if (!aFeature.get()) {
474 theError = "%1 attribute has an empty feature";
475 theError.arg(aParamA);
479 if (aFeature->getKind() == SketchPlugin_Point::ID())
483 // second attribute is a point, it may coincide with any object
484 if (!aRefAttrB->isObject())
487 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrB->object());
489 theError = "%1 attribute has an empty object";
490 theError.arg(theAttribute->id());
493 if (aFeature->getKind() == SketchPlugin_Point::ID())
496 theError = "There is no an attribute filled by a point";
501 bool SketchPlugin_CopyValidator::isValid(const AttributePtr& theAttribute,
502 const std::list<std::string>& theArguments,
503 Events_InfoMessage& theError) const
505 if (theAttribute->attributeType() != ModelAPI_AttributeRefList::typeId()) {
506 theError = "The attribute with the %1 type is not processed";
507 theError.arg(theAttribute->attributeType());
511 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
512 AttributeRefListPtr aSelAttr =
513 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
515 AttributeRefListPtr aRefListOfInitial = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
516 aFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
517 AttributeRefListPtr aRefListOfCopied = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
518 aFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
519 std::list<ObjectPtr> anInitialObjects = aRefListOfInitial->list();
520 std::list<ObjectPtr> aCopiedObjects = aRefListOfCopied->list();
522 std::list<ObjectPtr>::iterator anObjIter;
523 for(int anInd = 0; anInd < aSelAttr->size(); anInd++) {
524 ObjectPtr aSelObject = aSelAttr->object(anInd);
525 anObjIter = anInitialObjects.begin();
526 for (; anObjIter != anInitialObjects.end(); anObjIter++)
527 if (aSelObject == *anObjIter)
529 if (anObjIter != anInitialObjects.end())
532 // B-splines are not supported in Copying features
533 FeaturePtr aSelFeature = ModelAPI_Feature::feature(aSelObject);
534 if (aSelFeature && (aSelFeature->getKind() == SketchPlugin_BSpline::ID() ||
535 aSelFeature->getKind() == SketchPlugin_BSplinePeriodic::ID())) {
536 theError = "Not supported";
540 anObjIter = aCopiedObjects.begin();
541 for (; anObjIter != aCopiedObjects.end(); anObjIter++)
542 if (aSelObject == *anObjIter) {
543 std::string aName = aSelObject.get() ? aSelObject->data()->name() : "";
544 theError = "The object %1 is a result of copy";
552 bool SketchPlugin_SolverErrorValidator::isValid(
553 const std::shared_ptr<ModelAPI_Feature>& theFeature,
554 const std::list<std::string>& theArguments,
555 Events_InfoMessage& theError) const
557 AttributeStringPtr aAttributeString = theFeature->string(SketchPlugin_Sketch::SOLVER_ERROR());
559 if (!aAttributeString->value().empty()) {
560 theError = aAttributeString->value();
567 bool SketchPlugin_SolverErrorValidator::isNotObligatory(std::string theFeature,
568 std::string theAttribute)
573 static bool hasSameTangentFeature(const std::set<AttributePtr>& theRefsList,
574 const FeaturePtr theFeature)
576 for(std::set<AttributePtr>::const_iterator
577 anIt = theRefsList.cbegin(); anIt != theRefsList.cend(); ++anIt) {
578 std::shared_ptr<ModelAPI_Attribute> aAttr = (*anIt);
579 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
582 if (aFeature->getKind() == SketchPlugin_ConstraintTangent::ID()) {
583 AttributeRefAttrPtr anAttrRefA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
584 aFeature->attribute(SketchPlugin_ConstraintTangent::ENTITY_A()));
585 AttributeRefAttrPtr anAttrRefB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
586 aFeature->attribute(SketchPlugin_ConstraintTangent::ENTITY_B()));
587 if(anAttrRefA.get()) {
588 ResultPtr aResA = std::dynamic_pointer_cast<ModelAPI_Result>(anAttrRefA->object());
590 DocumentPtr aDoc = aResA->document();
592 FeaturePtr aFeatureA = aDoc->feature(aResA);
593 if(aFeatureA.get() && aFeatureA == theFeature) {
599 if(anAttrRefB.get()) {
600 ResultPtr aResB = std::dynamic_pointer_cast<ModelAPI_Result>(anAttrRefB->object());
602 DocumentPtr aDoc = aResB->document();
604 FeaturePtr aFeatureB = aDoc->feature(aResB);
605 if(aFeatureB.get() && aFeatureB == theFeature) {
616 static bool isPointPointCoincidence(const FeaturePtr& theCoincidence)
618 AttributeRefAttrPtr aRefAttr[2] = {
619 theCoincidence->refattr(SketchPlugin_Constraint::ENTITY_A()),
620 theCoincidence->refattr(SketchPlugin_Constraint::ENTITY_B())
623 bool arePoints = true;
624 for (int i = 0; i < 2 && arePoints; ++i) {
625 if (aRefAttr[i]->isObject()) {
626 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr[i]->object());
627 arePoints = aFeature.get() && aFeature->getKind() == SketchPlugin_Point::ID();
629 arePoints = aRefAttr[i]->attr().get() != NULL;
634 bool SketchPlugin_FilletVertexValidator::isValid(const AttributePtr& theAttribute,
635 const std::list<std::string>& theArguments,
636 Events_InfoMessage& theError) const
638 AttributeRefAttrPtr aPointRefAttr =
639 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
640 if(!aPointRefAttr.get()) {
641 theError = "Error: Point not selected.";
645 AttributePtr aPointAttribute = aPointRefAttr->attr();
646 if (!aPointAttribute.get()) {
647 theError = "Error: Bad point selected.";
650 std::shared_ptr<GeomAPI_Pnt2d> aSelectedPnt =
651 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aPointAttribute)->pnt();
653 // Obtain constraint coincidence for the fillet point.
654 const std::set<AttributePtr>& aRefsList = aPointAttribute->owner()->data()->refsToMe();
655 FeaturePtr aConstraintCoincidence;
656 for(std::set<AttributePtr>::const_iterator anIt = aRefsList.cbegin();
657 anIt != aRefsList.cend(); ++anIt) {
658 std::shared_ptr<ModelAPI_Attribute> aAttr = (*anIt);
659 FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
660 if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
661 if (!isPointPointCoincidence(aConstrFeature))
664 AttributeRefAttrPtr anAttrRefA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
665 aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_A()));
666 AttributeRefAttrPtr anAttrRefB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
667 aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_B()));
669 AttributePtr anAttrA = anAttrRefA->attr();
670 if(aPointAttribute == anAttrA) {
671 aConstraintCoincidence = aConstrFeature;
675 AttributePtr anAttrB = anAttrRefB->attr();
676 if(aPointAttribute == anAttrB) {
677 aConstraintCoincidence = aConstrFeature;
683 if(!aConstraintCoincidence.get()) {
684 theError = "Error: one of the selected point does not have coincidence.";
688 // Get coincides from constraint.
689 std::set<FeaturePtr> aCoinsides;
690 SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
691 SketchPlugin_ConstraintCoincidence::ENTITY_A(),
694 SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
695 SketchPlugin_ConstraintCoincidence::ENTITY_B(),
699 // Remove points and external lines from set of coincides.
700 std::set<FeaturePtr> aNewSetOfCoincides;
701 for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin();
702 anIt != aCoinsides.end(); ++anIt) {
703 std::shared_ptr<SketchPlugin_SketchEntity> aSketchEntity =
704 std::dynamic_pointer_cast<SketchPlugin_SketchEntity>(*anIt);
705 if(aSketchEntity.get() && (aSketchEntity->isCopy() || aSketchEntity->isExternal())) {
708 if((*anIt)->getKind() != SketchPlugin_Line::ID() &&
709 (*anIt)->getKind() != SketchPlugin_Arc::ID()) {
712 if((*anIt)->getKind() == SketchPlugin_Arc::ID()) {
713 AttributePtr anArcCenter = (*anIt)->attribute(SketchPlugin_Arc::CENTER_ID());
714 std::shared_ptr<GeomAPI_Pnt2d> anArcCenterPnt =
715 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anArcCenter)->pnt();
716 double aDistSelectedArcCenter = aSelectedPnt->distance(anArcCenterPnt);
717 if(aDistSelectedArcCenter < tolerance) {
721 aNewSetOfCoincides.insert(*anIt);
723 aCoinsides = aNewSetOfCoincides;
725 // If we still have more than two coincides remove auxilary entities from set of coincides.
726 if(aCoinsides.size() > 2) {
727 aNewSetOfCoincides.clear();
728 for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin();
729 anIt != aCoinsides.end(); ++anIt) {
730 if(!(*anIt)->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value()) {
731 aNewSetOfCoincides.insert(*anIt);
734 aCoinsides = aNewSetOfCoincides;
737 if(aCoinsides.size() != 2) {
738 theError = "Error: One of the selected points does not have two suitable edges for fillet.";
742 // Check that selected edges don't have tangent constraint.
743 std::set<FeaturePtr>::iterator anIt = aCoinsides.begin();
744 FeaturePtr aFirstFeature = *anIt++;
745 FeaturePtr aSecondFeature = *anIt;
746 const std::set<AttributePtr>& aFirstFeatureRefsList = aFirstFeature->data()->refsToMe();
747 if(hasSameTangentFeature(aFirstFeatureRefsList, aSecondFeature)) {
748 theError = "Error: Edges in selected point has tangent constraint.";
752 std::list<ResultPtr> aFirstResults = aFirstFeature->results();
753 for(std::list<ResultPtr>::iterator aResIt = aFirstResults.begin();
754 aResIt != aFirstResults.end(); ++aResIt) {
755 ResultPtr aRes = *aResIt;
756 const std::set<AttributePtr>& aResRefsList = aRes->data()->refsToMe();
757 if(hasSameTangentFeature(aResRefsList, aSecondFeature)) {
758 theError = "Error: Edges in selected point has tangent constraint.";
763 // Check the features are not tangent
764 std::shared_ptr<GeomAPI_Shape> aFirstShape = aFirstFeature->lastResult()->shape();
765 std::shared_ptr<GeomAPI_Shape> aSecondShape = aSecondFeature->lastResult()->shape();
766 if (!aFirstShape || !aFirstShape->isEdge() ||
767 !aSecondShape || !aSecondShape->isEdge()) {
768 theError = "Error: At least on of the features is not an edge";
772 std::shared_ptr<GeomAPI_Edge> anEdge1 = std::dynamic_pointer_cast<GeomAPI_Edge>(aFirstShape);
773 std::shared_ptr<GeomAPI_Edge> anEdge2 = std::dynamic_pointer_cast<GeomAPI_Edge>(aSecondShape);
775 static const double TOL = 1.e-7;
776 if (anEdge1->isLine() && anEdge2->isLine()) {
777 // Check that lines not collinear
778 std::shared_ptr<GeomAPI_Dir> aDir1 = anEdge1->line()->direction();
779 std::shared_ptr<GeomAPI_Dir> aDir2 = anEdge2->line()->direction();
780 double aCross = aDir1->cross(aDir2)->squareModulus();
781 if (aCross < TOL * TOL)
783 } else if (anEdge1->isArc() && anEdge2->isArc()) {
784 // check the circles are not tangent
785 std::shared_ptr<GeomAPI_Circ> aCirc1 = anEdge1->circle();
786 std::shared_ptr<GeomAPI_Circ> aCirc2 = anEdge2->circle();
787 double aDistCC = aCirc1->center()->distance(aCirc2->center());
788 double aRadSum = aCirc1->radius() + aCirc2->radius();
789 double aRadDiff = fabs(aCirc1->radius() - aCirc2->radius());
790 if (fabs(aDistCC - aRadSum) < TOL || fabs(aDistCC - aRadDiff) < TOL)
793 // check whether line and arc are tangent
794 std::shared_ptr<GeomAPI_Circ> aCirc;
795 std::shared_ptr<GeomAPI_Lin> aLine;
796 if (anEdge1->isLine()) {
797 aLine = anEdge1->line();
798 aCirc = anEdge2->circle();
800 aCirc = anEdge1->circle();
801 aLine = anEdge2->line();
804 double aDistCL = aLine->distance(aCirc->center());
805 if (fabs(aDistCL - aCirc->radius()) < TOL)
812 bool SketchPlugin_MiddlePointAttrValidator::isValid(const AttributePtr& theAttribute,
813 const std::list<std::string>& theArguments,
814 Events_InfoMessage& theError) const
816 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
817 theError = "The attribute with the %1 type is not processed";
818 theError.arg(theAttribute->attributeType());
822 // there is a check whether the feature contains a point and a linear edge or two point values
823 std::string aParamA = theArguments.front();
825 FeaturePtr anAttributeFeature =
826 std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
827 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
828 AttributeRefAttrPtr anOtherAttr = anAttributeFeature->data()->refattr(aParamA);
830 AttributeRefAttrPtr aRefAttrs[2] = {aRefAttr, anOtherAttr};
833 for (int i = 0; i < 2; ++i) {
834 if (!aRefAttrs[i]->isObject())
837 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrs[i]->object());
839 if (aNbPoints + aNbLines != 0)
844 if (aFeature->getKind() == SketchPlugin_Point::ID())
846 else if (aFeature->getKind() == SketchPlugin_Line::ID() ||
847 aFeature->getKind() == SketchPlugin_Arc::ID() ||
848 aFeature->getKind() == SketchPlugin_EllipticArc::ID())
853 if (aNbPoints != 1 || aNbLines != 1) {
854 theError = "Middle point constraint allows points and lines only";
860 bool SketchPlugin_ArcTangentPointValidator::isValid(const AttributePtr& theAttribute,
861 const std::list<std::string>& /*theArguments*/,
862 Events_InfoMessage& theError) const
864 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
865 theError = "The attribute with the %1 type is not processed";
866 theError.arg(theAttribute->attributeType());
869 FeaturePtr anOwner = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
870 AttributeStringPtr anArcTypeAttr = anOwner->string(SketchPlugin_MacroArc::ARC_TYPE());
871 if (anArcTypeAttr && anArcTypeAttr->value() != SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE())
872 return true; // not applicable for non-tangent arcs
874 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
875 AttributePtr anAttr = aRefAttr->attr();
877 theError = "The attribute %1 should be a point";
878 theError.arg(theAttribute->id());
882 FeaturePtr anAttrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->owner());
883 const std::string& aFeatureType = anAttrFeature->getKind();
884 if (aFeatureType == SketchPlugin_Arc::ID()) {
885 // selected point should not be a center of arc
886 const std::string& aPntId = anAttr->id();
887 if (aPntId != SketchPlugin_Arc::START_ID() && aPntId != SketchPlugin_Arc::END_ID()) {
888 theError = "The attribute %1 is not supported";
889 theError.arg(aPntId);
893 else if (aFeatureType == SketchPlugin_Line::ID()) {
894 // selected point should be bound point of line
895 const std::string& aPntId = anAttr->id();
896 if (aPntId != SketchPlugin_Line::START_ID() && aPntId != SketchPlugin_Line::END_ID()) {
897 theError = "The attribute %1 is not supported";
898 theError.arg(aPntId);
903 theError = "Unable to build tangent arc on %1";
904 theError.arg(anAttrFeature->getKind());
911 bool SketchPlugin_ArcTransversalPointValidator::isValid(
912 const AttributePtr& theAttribute,
913 const std::list<std::string>& /*theArguments*/,
914 Events_InfoMessage& theError) const
916 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
917 theError = "The attribute with the %1 type is not processed";
918 theError.arg(theAttribute->attributeType());
921 FeaturePtr anOwner = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
922 AttributeStringPtr anArcTypeAttr = anOwner->string(SketchPlugin_MacroArc::ARC_TYPE());
924 anArcTypeAttr->value() != SketchPlugin_MacroArc::ARC_TYPE_BY_TRANSVERSAL_LINE())
925 return true; // not applicable for non-transversal arcs
927 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
928 AttributePtr anAttr = aRefAttr->attr();
930 theError = "The attribute %1 should be a point";
931 theError.arg(theAttribute->id());
935 FeaturePtr anAttrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->owner());
936 const std::string& aFeatureType = anAttrFeature->getKind();
937 if (aFeatureType == SketchPlugin_Line::ID()) {
938 // selected point should be bound point of line
939 const std::string& aPntId = anAttr->id();
940 if (aPntId != SketchPlugin_Line::START_ID() && aPntId != SketchPlugin_Line::END_ID()) {
941 theError = "The attribute %1 is not supported";
942 theError.arg(aPntId);
947 theError = "Unable to build perpendicular arc on %1";
948 theError.arg(anAttrFeature->getKind());
955 bool SketchPlugin_IntersectionValidator::isValid(const AttributePtr& theAttribute,
956 const std::list<std::string>& theArguments,
957 Events_InfoMessage& theError) const
959 if (theAttribute->attributeType() != ModelAPI_AttributeSelection::typeId()) {
960 theError = "The attribute with the %1 type is not processed";
961 theError.arg(theAttribute->attributeType());
964 AttributeSelectionPtr anExternalAttr =
965 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
966 std::shared_ptr<GeomAPI_Edge> anEdge;
967 if (anExternalAttr && anExternalAttr->value() && anExternalAttr->value()->isEdge()) {
968 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anExternalAttr->value()));
969 } else if(anExternalAttr->context() && anExternalAttr->context()->shape() &&
970 anExternalAttr->context()->shape()->isEdge()) {
971 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anExternalAttr->context()->shape()));
975 theError = "The attribute %1 should be an edge";
976 theError.arg(theAttribute->id());
981 std::shared_ptr<SketchPlugin_Sketch> aSketch;
982 std::set<AttributePtr> aRefs = anExternalAttr->owner()->data()->refsToMe();
983 std::set<AttributePtr>::const_iterator anIt = aRefs.begin();
984 for (; anIt != aRefs.end(); ++anIt) {
985 CompositeFeaturePtr aComp =
986 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>((*anIt)->owner());
987 if (aComp && aComp->getKind() == SketchPlugin_Sketch::ID()) {
988 aSketch = std::dynamic_pointer_cast<SketchPlugin_Sketch>(aComp);
993 theError = "There is no sketch referring to the current feature";
997 // check the edge is intersected with sketch plane
998 std::shared_ptr<GeomAPI_Pln> aPlane = aSketch->plane();
1000 std::list<GeomPointPtr> anIntersectionsPoints;
1001 anEdge->intersectWithPlane(aPlane, anIntersectionsPoints);
1002 if (anIntersectionsPoints.empty()) {
1003 theError = "The edge is not intersected with sketch plane";
1009 bool SketchPlugin_SplitValidator::isValid(const AttributePtr& theAttribute,
1010 const std::list<std::string>& theArguments,
1011 Events_InfoMessage& theError) const
1013 bool aValid = false;
1015 if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
1016 theError = "The attribute with the %1 type is not processed";
1017 theError.arg(theAttribute->attributeType());
1020 AttributeReferencePtr aFeatureAttr =
1021 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
1022 std::shared_ptr<SketchPlugin_Feature> aSplitFeature =
1023 std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
1025 ObjectPtr anAttrObject = aFeatureAttr->value();
1026 if (!anAttrObject) {
1027 AttributePtr aPreviewAttr = aSplitFeature->attribute(SketchPlugin_Trim::PREVIEW_OBJECT());
1028 aFeatureAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(aPreviewAttr);
1029 anAttrObject = aFeatureAttr->value();
1032 FeaturePtr anAttrFeature = ModelAPI_Feature::feature(anAttrObject);
1036 // B-splines are not supported by the Split yet
1037 if (anAttrFeature->getKind() == SketchPlugin_BSpline::ID() ||
1038 anAttrFeature->getKind() == SketchPlugin_BSplinePeriodic::ID()) {
1039 theError = "Not supported";
1043 std::set<ResultPtr> anEdgeShapes;
1044 ModelGeomAlgo_Shape::shapesOfType(anAttrFeature, GeomAPI_Shape::EDGE, anEdgeShapes);
1045 if (anEdgeShapes.empty() || anEdgeShapes.size() > 1 /*there case has not existed yet*/)
1048 // coincidences to the feature
1049 std::set<std::shared_ptr<GeomDataAPI_Point2D> > aRefAttributes;
1050 ModelGeomAlgo_Point2D::getPointsOfReference(anAttrFeature,
1051 SketchPlugin_ConstraintCoincidence::ID(),
1052 aRefAttributes, SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
1054 GeomShapePtr anAttrShape = (*anEdgeShapes.begin())->shape();
1055 std::shared_ptr<SketchPlugin_Feature> aSFeature =
1056 std::dynamic_pointer_cast<SketchPlugin_Feature>(anAttrFeature);
1057 if (!aSFeature || aSFeature->isCopy())
1059 SketchPlugin_Sketch* aSketch = aSFeature->sketch();
1061 std::shared_ptr<ModelAPI_Data> aData = aSketch->data();
1062 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1063 aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
1064 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1065 aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
1066 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1067 aData->attribute(SketchPlugin_Sketch::NORM_ID()));
1068 std::shared_ptr<GeomAPI_Dir> aDirY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
1070 typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
1071 std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
1072 std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
1073 PointToRefsMap aPointsInfo;
1075 ModelGeomAlgo_Point2D::getPointsInsideShape(anAttrShape, aRefAttributes, aC->pnt(),
1076 aX->dir(), aDirY, aPointsInfo);
1077 int aCoincidentToFeature = (int)aPointsInfo.size();
1078 if (anAttrFeature->getKind() == SketchPlugin_Circle::ID() ||
1079 anAttrFeature->getKind() == SketchPlugin_Ellipse::ID())
1080 aValid = aCoincidentToFeature >= 2;
1082 aValid = aCoincidentToFeature >= 1;
1087 bool SketchPlugin_TrimValidator::isValid(const AttributePtr& theAttribute,
1088 const std::list<std::string>& theArguments,
1089 Events_InfoMessage& theError) const
1091 bool aValid = false;
1093 if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
1094 theError = "The attribute with the %1 type is not processed";
1095 theError.arg(theAttribute->attributeType());
1098 AttributeReferencePtr aBaseObjectAttr =
1099 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
1101 std::shared_ptr<SketchPlugin_Feature> aTrimFeature =
1102 std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
1104 ObjectPtr aBaseObject = aBaseObjectAttr->value();
1106 AttributePtr aPreviewAttr = aTrimFeature->attribute(SketchPlugin_Trim::PREVIEW_OBJECT());
1107 aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(aPreviewAttr);
1108 aBaseObject = aBaseObjectAttr->value();
1111 FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObject);
1115 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1116 std::dynamic_pointer_cast<SketchPlugin_Feature>(aBaseFeature);
1117 if (!aSketchFeature.get() || aSketchFeature->isCopy())
1120 // B-splines are not supported by the Trim yet
1121 if (aBaseFeature->getKind() == SketchPlugin_BSpline::ID() ||
1122 aBaseFeature->getKind() == SketchPlugin_BSplinePeriodic::ID()) {
1123 theError = "Not supported";
1128 AttributePoint2DPtr aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1129 aTrimFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT()));
1131 SketchPlugin_Sketch* aSketch = aTrimFeature->sketch();
1133 std::shared_ptr<GeomAPI_Pnt2d> anAttributePnt2d = aPoint->pnt();
1134 std::shared_ptr<GeomAPI_Pnt> anAttributePnt = aSketch->to3D(anAttributePnt2d->x(),
1135 anAttributePnt2d->y());
1137 std::map<ObjectPtr, std::set<GeomShapePtr> > aCashedShapes;
1138 std::map<ObjectPtr, std::map<std::shared_ptr<GeomAPI_Pnt>,
1139 std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
1140 std::list<std::shared_ptr<ModelAPI_Object> > > > > anObjectToPoints;
1141 SketchPlugin_SegmentationTools::fillObjectShapes(
1142 aTrimFeature.get(), aBaseObject, aCashedShapes, anObjectToPoints);
1143 const std::set<GeomShapePtr>& aShapes = aCashedShapes[aBaseObject];
1145 return aShapes.size() > 1;
1148 bool SketchPlugin_ProjectionValidator::isValid(const AttributePtr& theAttribute,
1149 const std::list<std::string>& theArguments,
1150 Events_InfoMessage& theError) const
1152 if (theAttribute->attributeType() != ModelAPI_AttributeSelection::typeId()) {
1153 theError = "The attribute with the %1 type is not processed";
1154 theError.arg(theAttribute->attributeType());
1158 AttributeSelectionPtr aFeatureAttr =
1159 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
1160 std::shared_ptr<GeomAPI_Edge> anEdge;
1161 std::shared_ptr<SketchPlugin_Feature> aSketchFeature;
1162 if (aFeatureAttr.get()) {
1163 GeomShapePtr aVal = aFeatureAttr->value();
1164 ResultPtr aRes = aFeatureAttr->context();
1165 if (aVal && aVal->isVertex())
1166 return true; // vertex is always could be projected
1167 if (aVal && aVal->isEdge()) {
1168 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aFeatureAttr->value()));
1169 } else if(aRes && aRes->shape()) {
1170 if (aRes->shape()->isVertex())
1171 return true; // vertex is always could be projected
1172 else if (aRes->shape()->isEdge())
1173 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aFeatureAttr->context()->shape()));
1176 // try to convert result to sketch feature
1179 std::dynamic_pointer_cast<SketchPlugin_Feature>(ModelAPI_Feature::feature(aRes));
1183 theError = "The attribute %1 should be an edge or vertex";
1184 theError.arg(theAttribute->id());
1189 std::shared_ptr<SketchPlugin_Sketch> aSketch;
1190 std::set<AttributePtr> aRefs = theAttribute->owner()->data()->refsToMe();
1191 std::set<AttributePtr>::const_iterator anIt = aRefs.begin();
1192 for (; anIt != aRefs.end(); ++anIt) {
1193 CompositeFeaturePtr aComp =
1194 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>((*anIt)->owner());
1195 if (aComp && aComp->getKind() == SketchPlugin_Sketch::ID()) {
1196 aSketch = std::dynamic_pointer_cast<SketchPlugin_Sketch>(aComp);
1201 theError = "There is no sketch referring to the current feature";
1204 if (aSketchFeature && aSketch.get() == aSketchFeature->sketch()) {
1205 theError = "Unable to project feature from the same sketch";
1209 std::shared_ptr<GeomAPI_Pln> aPlane = aSketch->plane();
1210 std::shared_ptr<GeomAPI_Dir> aNormal = aPlane->direction();
1211 std::shared_ptr<GeomAPI_Pnt> anOrigin = aPlane->location();
1214 if (anEdge->isLine()) {
1215 std::shared_ptr<GeomAPI_Lin> aLine = anEdge->line();
1216 std::shared_ptr<GeomAPI_Dir> aLineDir = aLine->direction();
1217 double aDot = fabs(aNormal->dot(aLineDir));
1218 aValid = fabs(aDot - 1.0) >= tolerance * tolerance;
1220 theError = "Error: Line is orthogonal to the sketch plane.";
1222 else if (anEdge->isCircle() || anEdge->isArc()) {
1223 std::shared_ptr<GeomAPI_Circ> aCircle = anEdge->circle();
1224 std::shared_ptr<GeomAPI_Dir> aCircNormal = aCircle->normal();
1225 double aDot = fabs(aNormal->dot(aCircNormal));
1226 aValid = aDot >= tolerance * tolerance;
1228 theError.arg(anEdge->isCircle() ? "Error: Circle is orthogonal to the sketch plane."
1229 : "Error: Arc is orthogonal to the sketch plane.");
1231 else if (anEdge->isEllipse()) {
1232 std::shared_ptr<GeomAPI_Ellipse> anEllipse = anEdge->ellipse();
1233 std::shared_ptr<GeomAPI_Dir> anEllipseNormal = anEllipse->normal();
1234 double aDot = fabs(aNormal->dot(anEllipseNormal));
1235 aValid = fabs(aDot - 1.0) <= tolerance * tolerance;
1237 theError.arg(anEdge->isClosed() ? "Error: Ellipse is orthogonal to the sketch plane."
1238 : "Error: Elliptic Arc is orthogonal to the sketch plane.");
1245 static std::set<FeaturePtr> common(const std::set<FeaturePtr>& theSet1,
1246 const std::set<FeaturePtr>& theSet2)
1248 std::set<FeaturePtr> aCommon;
1249 if (theSet1.empty() || theSet2.empty())
1252 std::set<FeaturePtr>::const_iterator anIt2 = theSet2.begin();
1253 for (; anIt2 != theSet2.end(); ++anIt2)
1254 if (theSet1.find(*anIt2) != theSet1.end())
1255 aCommon.insert(*anIt2);
1259 bool SketchPlugin_DifferentReferenceValidator::isValid(
1260 const AttributePtr& theAttribute,
1261 const std::list<std::string>& theArguments,
1262 Events_InfoMessage& theError) const
1264 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
1266 int aNbFeaturesReferred = 0;
1267 int aNbAttributesReferred = 0;
1268 std::set<FeaturePtr> aCommonReferredFeatures;
1270 // find all features referred by attributes listed in theArguments
1271 std::list<std::string>::const_iterator anArgIt = theArguments.begin();
1272 for (; anArgIt != theArguments.end(); ++anArgIt) {
1273 AttributeRefAttrPtr aRefAttr = anOwner->refattr(*anArgIt);
1277 std::set<FeaturePtr> aCoincidentFeatures;
1278 if (aRefAttr->isObject()) {
1279 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
1281 aCoincidentFeatures.insert(aFeature);
1282 aNbFeaturesReferred += 1;
1285 AttributePoint2DPtr aPoint =
1286 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aRefAttr->attr());
1288 aCoincidentFeatures = SketchPlugin_Tools::findFeaturesCoincidentToPoint(aPoint);
1289 aNbAttributesReferred += 1;
1293 if (aCommonReferredFeatures.empty())
1294 aCommonReferredFeatures = aCoincidentFeatures;
1296 aCommonReferredFeatures = common(aCommonReferredFeatures, aCoincidentFeatures);
1298 if (aCommonReferredFeatures.empty())
1302 bool isOk = aNbFeaturesReferred < 1;
1303 if (aNbFeaturesReferred == 1) {
1304 if (aCommonReferredFeatures.size() == 1) {
1305 FeaturePtr aFeature = *aCommonReferredFeatures.begin();
1306 isOk = aNbAttributesReferred <= 1 ||
1307 aFeature->getKind() == SketchPlugin_Circle::ID() ||
1308 aFeature->getKind() == SketchPlugin_Arc::ID();
1314 theError = "Attributes are referred to the same feature";
1318 bool SketchPlugin_DifferentPointReferenceValidator::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());
1324 std::set<AttributePoint2DPtr> aReferredCoincidentPoints;
1326 // find all points referred by attributes listed in theArguments
1327 bool hasRefsToPoints = false;
1328 std::list<std::string>::const_iterator anArgIt = theArguments.begin();
1329 for (; anArgIt != theArguments.end(); ++anArgIt) {
1330 AttributeRefAttrPtr aRefAttr = anOwner->refattr(*anArgIt);
1334 if (!aRefAttr->isObject()) {
1335 AttributePoint2DPtr aPoint =
1336 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aRefAttr->attr());
1337 if (aReferredCoincidentPoints.empty())
1338 aReferredCoincidentPoints = SketchPlugin_Tools::findPointsCoincidentToPoint(aPoint);
1339 else if (aReferredCoincidentPoints.find(aPoint) == aReferredCoincidentPoints.end())
1340 return true; // non-coincident point has been found
1342 hasRefsToPoints = true;
1346 if (hasRefsToPoints)
1347 theError = "Attributes are referred to the same point";
1348 return !hasRefsToPoints;
1351 bool SketchPlugin_CirclePassedPointValidator::isValid(
1352 const AttributePtr& theAttribute,
1353 const std::list<std::string>&,
1354 Events_InfoMessage& theError) const
1356 static const std::string aErrorMessage(
1357 "Passed point refers to the same feature as a center point");
1359 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
1361 AttributeRefAttrPtr aCenterRef =
1362 anOwner->refattr(SketchPlugin_MacroCircle::CENTER_POINT_REF_ID());
1363 AttributeRefAttrPtr aPassedRef =
1364 anOwner->refattr(SketchPlugin_MacroCircle::PASSED_POINT_REF_ID());
1366 if (!aPassedRef->isObject())
1369 FeaturePtr aPassedFeature = ModelAPI_Feature::feature(aPassedRef->object());
1370 if (!aPassedFeature)
1373 if (aCenterRef->isObject()) {
1374 if (aCenterRef->object() == aPassedRef->object()) {
1375 theError = aErrorMessage;
1379 AttributePoint2DPtr aCenterPoint =
1380 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aCenterRef->attr());
1382 std::set<FeaturePtr> aCoincidentFeatures =
1383 SketchPlugin_Tools::findFeaturesCoincidentToPoint(aCenterPoint);
1384 // check one of coincident features is a feature referred by passed point
1385 std::set<FeaturePtr>::const_iterator anIt = aCoincidentFeatures.begin();
1386 for(; anIt != aCoincidentFeatures.end(); ++anIt)
1387 if (*anIt == aPassedFeature) {
1388 theError = aErrorMessage;
1396 bool SketchPlugin_ThirdPointValidator::isValid(
1397 const AttributePtr& theAttribute,
1398 const std::list<std::string>& theArguments,
1399 Events_InfoMessage& theError) const
1401 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
1402 return arePointsNotOnLine(anOwner, theError) &&
1403 arePointsNotSeparated(anOwner, theArguments, theError);
1406 static std::shared_ptr<GeomAPI_Pnt2d> toPoint(const FeaturePtr& theMacroCircle,
1407 const std::string& thePointAttrName,
1408 const std::string& theRefPointAttrName)
1410 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1411 theMacroCircle->attribute(thePointAttrName));
1412 AttributeRefAttrPtr aRefAttr = theMacroCircle->refattr(theRefPointAttrName);
1414 std::shared_ptr<GeomAPI_Pnt2d> aPoint = aPointAttr->pnt();
1416 if (aRefAttr->isObject()) {
1417 // project a point onto selected feature
1418 std::shared_ptr<SketchPlugin_Feature> aFeature =
1419 std::dynamic_pointer_cast<SketchPlugin_Feature>(
1420 ModelAPI_Feature::feature(aRefAttr->object()));
1422 SketchPlugin_Sketch* aSketch = aFeature->sketch();
1423 std::shared_ptr<GeomAPI_Edge> anEdge =
1424 std::dynamic_pointer_cast<GeomAPI_Edge>(aFeature->lastResult()->shape());
1426 std::shared_ptr<GeomAPI_Pnt> aPoint3D = aSketch->to3D(aPoint->x(), aPoint->y());
1427 if (anEdge->isLine())
1428 aPoint3D = anEdge->line()->project(aPoint3D);
1429 else if (anEdge->isCircle())
1430 aPoint3D = anEdge->circle()->project(aPoint3D);
1432 aPoint = aSketch->to2D(aPoint3D);
1436 AttributePoint2DPtr anOtherPoint =
1437 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aRefAttr->attr());
1439 aPoint = anOtherPoint->pnt(); // the reference point is much more precise, use it
1446 static void threePointsOfFeature(const FeaturePtr& theMacroFeature,
1447 std::shared_ptr<GeomAPI_Pnt2d> thePoints[3])
1449 if (theMacroFeature->getKind() == SketchPlugin_MacroCircle::ID()) {
1450 thePoints[0] = toPoint(theMacroFeature,
1451 SketchPlugin_MacroCircle::FIRST_POINT_ID(),
1452 SketchPlugin_MacroCircle::FIRST_POINT_REF_ID());
1453 thePoints[1] = toPoint(theMacroFeature,
1454 SketchPlugin_MacroCircle::SECOND_POINT_ID(),
1455 SketchPlugin_MacroCircle::SECOND_POINT_REF_ID());
1456 thePoints[2] = toPoint(theMacroFeature,
1457 SketchPlugin_MacroCircle::THIRD_POINT_ID(),
1458 SketchPlugin_MacroCircle::THIRD_POINT_REF_ID());
1459 } else if (theMacroFeature->getKind() == SketchPlugin_MacroArc::ID()) {
1460 thePoints[0] = toPoint(theMacroFeature,
1461 SketchPlugin_MacroArc::START_POINT_2_ID(),
1462 SketchPlugin_MacroArc::START_POINT_REF_ID());
1463 thePoints[1] = toPoint(theMacroFeature,
1464 SketchPlugin_MacroArc::END_POINT_2_ID(),
1465 SketchPlugin_MacroArc::END_POINT_REF_ID());
1466 thePoints[2] = toPoint(theMacroFeature,
1467 SketchPlugin_MacroArc::PASSED_POINT_ID(),
1468 SketchPlugin_MacroArc::PASSED_POINT_REF_ID());
1472 static bool isPointsOnLine(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
1473 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
1474 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
1476 static const double aTolerance = 1.e-7;
1477 if (thePoint1->distance(thePoint2) < aTolerance ||
1478 thePoint1->distance(thePoint3) < aTolerance)
1481 std::shared_ptr<GeomAPI_Dir2d> aDirP1P2(new GeomAPI_Dir2d(thePoint2->x() - thePoint1->x(),
1482 thePoint2->y() - thePoint1->y()));
1483 std::shared_ptr<GeomAPI_Dir2d> aDirP1P3(new GeomAPI_Dir2d(thePoint3->x() - thePoint1->x(),
1484 thePoint3->y() - thePoint1->y()));
1485 return fabs(aDirP1P2->cross(aDirP1P3)) < aTolerance;
1488 static bool isOnSameSide(const std::shared_ptr<GeomAPI_Lin>& theLine,
1489 const std::shared_ptr<GeomAPI_Pnt>& thePoint1,
1490 const std::shared_ptr<GeomAPI_Pnt>& thePoint2)
1492 static const double aTolerance = 1.e-7;
1493 std::shared_ptr<GeomAPI_Dir> aLineDir = theLine->direction();
1494 std::shared_ptr<GeomAPI_XYZ> aLineLoc = theLine->location()->xyz();
1496 std::shared_ptr<GeomAPI_XYZ> aVec1 = thePoint1->xyz()->decreased(aLineLoc);
1497 // the first point is on the line
1498 if (aVec1->squareModulus() < aTolerance * aTolerance)
1500 std::shared_ptr<GeomAPI_Dir> aDirP1L(new GeomAPI_Dir(aVec1));
1501 std::shared_ptr<GeomAPI_XYZ> aVec2 = thePoint2->xyz()->decreased(aLineLoc);
1502 // the second point is on the line
1503 if (aVec2->squareModulus() < aTolerance * aTolerance)
1505 std::shared_ptr<GeomAPI_Dir> aDirP2L(new GeomAPI_Dir(aVec2));
1507 return aLineDir->cross(aDirP1L)->dot(aLineDir->cross(aDirP2L)) > -aTolerance;
1510 static bool isOnSameSide(const std::shared_ptr<GeomAPI_Circ>& theCircle,
1511 const std::shared_ptr<GeomAPI_Pnt>& thePoint1,
1512 const std::shared_ptr<GeomAPI_Pnt>& thePoint2)
1514 static const double aTolerance = 1.e-7;
1515 std::shared_ptr<GeomAPI_Pnt> aCenter = theCircle->center();
1516 double aDistP1C = thePoint1->distance(aCenter);
1517 double aDistP2C = thePoint2->distance(aCenter);
1518 return (aDistP1C - theCircle->radius()) * (aDistP2C - theCircle->radius()) > -aTolerance;
1521 bool SketchPlugin_ThirdPointValidator::arePointsNotOnLine(
1522 const FeaturePtr& theMacroFeature,
1523 Events_InfoMessage& theError) const
1525 static const std::string aErrorPointsOnLine(
1526 "Selected points are on the same line");
1528 std::shared_ptr<GeomAPI_Pnt2d> aPoints[3];
1529 threePointsOfFeature(theMacroFeature, aPoints);
1531 if (isPointsOnLine(aPoints[0], aPoints[1], aPoints[2])) {
1532 theError = aErrorPointsOnLine;
1538 bool SketchPlugin_ThirdPointValidator::arePointsNotSeparated(
1539 const FeaturePtr& theMacroFeature,
1540 const std::list<std::string>& theArguments,
1541 Events_InfoMessage& theError) const
1543 static const std::string aErrorPointsApart(
1544 "Selected entity is lying between first two points");
1546 AttributeRefAttrPtr aThirdPointRef = theMacroFeature->refattr(theArguments.front());
1547 FeaturePtr aRefByThird;
1548 if (aThirdPointRef->isObject())
1549 aRefByThird = ModelAPI_Feature::feature(aThirdPointRef->object());
1553 std::shared_ptr<GeomAPI_Pnt2d> aPoints[3];
1554 threePointsOfFeature(theMacroFeature, aPoints);
1556 std::shared_ptr<GeomAPI_Edge> aThirdShape =
1557 std::dynamic_pointer_cast<GeomAPI_Edge>(aRefByThird->lastResult()->shape());
1561 SketchPlugin_Sketch* aSketch =
1562 std::dynamic_pointer_cast<SketchPlugin_Feature>(theMacroFeature)->sketch();
1563 std::shared_ptr<GeomAPI_Pnt> aFirstPnt3D = aSketch->to3D(aPoints[0]->x(), aPoints[0]->y());
1564 std::shared_ptr<GeomAPI_Pnt> aSecondPnt3D = aSketch->to3D(aPoints[1]->x(), aPoints[1]->y());
1567 if (aThirdShape->isLine())
1568 isOk = isOnSameSide(aThirdShape->line(), aFirstPnt3D, aSecondPnt3D);
1569 else if (aThirdShape->isCircle() || aThirdShape->isArc())
1570 isOk = isOnSameSide(aThirdShape->circle(), aFirstPnt3D, aSecondPnt3D);
1573 theError = aErrorPointsApart;
1577 bool SketchPlugin_ArcEndPointValidator::isValid(
1578 const AttributePtr& theAttribute,
1579 const std::list<std::string>& theArguments,
1580 Events_InfoMessage& theError) const
1582 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
1583 AttributeRefAttrPtr anEndPointRef = aFeature->refattr(theArguments.front());
1585 if(!anEndPointRef.get()) {
1589 ObjectPtr anObject = anEndPointRef->object();
1590 AttributePtr anAttr = anEndPointRef->attr();
1591 if(!anObject.get() && !anAttr.get()) {
1595 if(anEndPointRef->attr().get()) {
1599 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1601 GeomShapePtr aShape = aResult->shape();
1602 if(aShape.get() && aShape->isVertex()) {
1607 aFeature = ModelAPI_Feature::feature(anObject);
1608 if(aFeature.get()) {
1609 if(aFeature->getKind() == SketchPlugin_Point::ID()) {
1617 static GeomShapePtr toInfiniteEdge(const GeomShapePtr theShape)
1619 if(!theShape.get()) {
1623 if(!theShape->isEdge()) {
1627 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
1633 if(anEdge->isLine()) {
1634 std::shared_ptr<GeomAPI_Lin> aLine = anEdge->line();
1635 GeomShapePtr aShape = GeomAlgoAPI_EdgeBuilder::line(aLine);
1639 if(anEdge->isCircle() || anEdge->isArc()) {
1640 std::shared_ptr<GeomAPI_Circ> aCircle = anEdge->circle();
1641 GeomShapePtr aShape = GeomAlgoAPI_EdgeBuilder::lineCircle(aCircle);
1648 bool SketchPlugin_ArcEndPointIntersectionValidator::isValid(
1649 const AttributePtr& theAttribute,
1650 const std::list<std::string>& theArguments,
1651 Events_InfoMessage& theError) const
1653 std::shared_ptr<SketchPlugin_MacroArc> anArcFeature =
1654 std::dynamic_pointer_cast<SketchPlugin_MacroArc>(theAttribute->owner());
1655 AttributeRefAttrPtr anEndPointRef = anArcFeature->refattr(theArguments.front());
1657 if(!anEndPointRef.get()) {
1661 GeomShapePtr anArcShape = toInfiniteEdge(anArcFeature->getArcShape(false));
1663 if(!anArcShape.get() || anArcShape->isNull()) {
1667 ObjectPtr anObject = anEndPointRef->object();
1668 AttributePtr anAttr = anEndPointRef->attr();
1669 if(!anObject.get() && !anAttr.get()) {
1673 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1675 GeomShapePtr aShape = aResult->shape();
1676 if (!aShape->isEdge())
1678 aShape = toInfiniteEdge(aShape);
1679 if(aShape.get() && !aShape->isNull()) {
1680 if(anArcShape->isIntersect(aShape)) {
1686 FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(anObject);
1687 if(aSelectedFeature.get()) {
1688 std::list<ResultPtr> aResults = aSelectedFeature->results();
1689 for(std::list<ResultPtr>::const_iterator anIt = aResults.cbegin();
1690 anIt != aResults.cend();
1693 GeomShapePtr aShape = (*anIt)->shape();
1694 if (!aShape->isEdge())
1696 aShape = toInfiniteEdge(aShape);
1697 if(aShape.get() && !aShape->isNull()) {
1698 if(anArcShape->isIntersect(aShape)) {
1708 bool SketchPlugin_HasNoConstraint::isValid(const AttributePtr& theAttribute,
1709 const std::list<std::string>& theArguments,
1710 Events_InfoMessage& theError) const
1712 std::set<std::string> aFeatureKinds;
1713 for (std::list<std::string>::const_iterator anArgIt = theArguments.begin();
1714 anArgIt != theArguments.end(); anArgIt++) {
1715 aFeatureKinds.insert(*anArgIt);
1718 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
1719 theError = "The attribute with the %1 type is not processed";
1720 theError.arg(theAttribute->attributeType());
1724 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
1726 bool isObject = aRefAttr->isObject();
1728 theError = "It uses an empty object";
1731 ObjectPtr anObject = aRefAttr->object();
1732 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1733 if (!aFeature.get()) {
1734 theError = "The feature of the checked attribute is empty";
1738 FeaturePtr aCurrentFeature = ModelAPI_Feature::feature(aRefAttr->owner());
1740 std::set<AttributePtr> aRefsList = anObject->data()->refsToMe();
1741 std::set<AttributePtr>::const_iterator anIt = aRefsList.begin();
1742 for (; anIt != aRefsList.end(); anIt++) {
1743 FeaturePtr aRefFeature = ModelAPI_Feature::feature((*anIt)->owner());
1744 if (aRefFeature.get() && aCurrentFeature != aRefFeature &&
1745 aFeatureKinds.find(aRefFeature->getKind()) != aFeatureKinds.end())
1746 return false; // constraint is found, that means that the check is not valid
1751 bool SketchPlugin_ReplicationReferenceValidator::isValid(
1752 const AttributePtr& theAttribute,
1753 const std::list<std::string>& theArguments,
1754 Events_InfoMessage& theError) const
1756 AttributeRefAttrPtr aRefAttr =
1757 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
1760 theError = "Incorrect attribute";
1765 if (aRefAttr->isObject())
1766 anOwner = aRefAttr->object();
1769 AttributePtr anAttr = aRefAttr->attr();
1770 anOwner = anAttr->owner();
1772 FeaturePtr anAttrOwnerFeature = ModelAPI_Feature::feature(anOwner);
1773 if (!anAttrOwnerFeature)
1775 AttributeBooleanPtr aCopyAttr = anAttrOwnerFeature->boolean(SketchPlugin_SketchEntity::COPY_ID());
1776 if (!aCopyAttr || !aCopyAttr->value())
1777 return true; // feature is not a copy, thus valid
1779 // check the copy feature is already referred by the "Multi" feature
1780 FeaturePtr aMultiFeature = ModelAPI_Feature::feature(theAttribute->owner());
1781 AttributeRefListPtr aRefList = aMultiFeature->reflist(theArguments.front());
1782 for (int i = 0; i < aRefList->size(); ++i)
1784 FeaturePtr aRefOwner = ModelAPI_Feature::feature(aRefList->object(i));
1785 if (aRefOwner == anAttrOwnerFeature)
1787 theError = "Attribute refers to the object generated by this feature";
1795 bool SketchPlugin_SketchFeatureValidator::isValid(const AttributePtr& theAttribute,
1796 const std::list<std::string>& theArguments,
1797 Events_InfoMessage& theError) const
1799 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId() &&
1800 theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
1801 theError = "The attribute with the %1 type is not processed";
1802 theError.arg(theAttribute->attributeType());
1806 // check the attribute refers to a sketch feature
1807 bool isSketchFeature = false;
1808 AttributeRefAttrPtr aRefAttr =
1809 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
1811 isSketchFeature = aRefAttr->isObject();
1812 if (isSketchFeature) {
1813 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
1814 isSketchFeature = aFeature.get() != NULL;
1815 if (isSketchFeature) {
1816 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1817 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1818 isSketchFeature = aSketchFeature.get() != NULL;
1823 AttributeReferencePtr aReference =
1824 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
1826 FeaturePtr aFeature = ModelAPI_Feature::feature(aReference->value());
1827 isSketchFeature = aFeature.get() && aFeature->getKind() == SketchPlugin_Sketch::ID();
1831 if (!isSketchFeature)
1832 theError = "The object selected is not a sketch feature";
1833 return isSketchFeature;
1836 bool SketchPlugin_MultiRotationAngleValidator::isValid(const AttributePtr& theAttribute,
1837 const std::list<std::string>& theArguments,
1838 Events_InfoMessage& theError) const
1840 if (theAttribute->attributeType() != ModelAPI_AttributeDouble::typeId()) {
1841 theError = "The attribute with the %1 type is not processed";
1842 theError.arg(theAttribute->attributeType());
1846 AttributeDoublePtr anAngleAttr =
1847 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
1849 FeaturePtr aMultiRotation = ModelAPI_Feature::feature(theAttribute->owner());
1850 AttributeStringPtr anAngleType =
1851 aMultiRotation->string(SketchPlugin_MultiRotation::ANGLE_TYPE());
1852 AttributeIntegerPtr aNbCopies =
1853 aMultiRotation->integer(SketchPlugin_MultiRotation::NUMBER_OF_OBJECTS_ID());
1855 if (anAngleType->value() != "FullAngle")
1857 double aFullAngleValue = anAngleAttr->value() * (aNbCopies->value() - 1);
1858 if (aFullAngleValue < -1.e-7 || aFullAngleValue > 359.9999999)
1860 theError = "Rotation single angle should produce full angle less than 360 degree";
1866 double aFullAngleValue = anAngleAttr->value();
1867 if (aFullAngleValue < -1.e-7 || aFullAngleValue > 360.0000001)
1869 theError = "Rotation full angle should be in range [0, 360]";
1877 bool SketchPlugin_BSplineValidator::isValid(const AttributePtr& theAttribute,
1878 const std::list<std::string>& theArguments,
1879 Events_InfoMessage& theError) const
1881 AttributePoint2DArrayPtr aPolesArray =
1882 std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(theAttribute);
1886 if (aPolesArray->size() < 2) {
1887 theError = "Number of B-spline poles should be 2 or more";