1 // Copyright (C) 2014-2019 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>
78 const double tolerance = 1.e-7;
80 static bool isSpline(FeaturePtr theFeature)
82 return theFeature && (theFeature->getKind() == SketchPlugin_BSpline::ID() ||
83 theFeature->getKind() == SketchPlugin_BSplinePeriodic::ID());
87 bool SketchPlugin_DistanceAttrValidator::isValid(const AttributePtr& theAttribute,
88 const std::list<std::string>& theArguments,
89 Events_InfoMessage& theError) const
91 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
92 theError = "The attribute with the %1 type is not processed";
93 theError.arg(theAttribute->attributeType());
97 // there is a check whether the feature contains a point and a linear edge or two point values
98 std::string aParamA = theArguments.front();
99 SessionPtr aMgr = ModelAPI_Session::get();
100 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
102 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
104 bool isObject = aRefAttr->isObject();
106 // an attribute is a point. A point value is valid always for the distance
109 // 1. check whether the references object is a linear
110 ObjectPtr anObject = aRefAttr->object();
112 const ModelAPI_AttributeValidator* aShapeValidator =
113 dynamic_cast<const ModelAPI_AttributeValidator*>(
114 aFactory->validator("GeomValidators_ShapeType"));
115 std::list<std::string> anArguments;
116 anArguments.push_back("circle");
117 Events_InfoMessage aCircleError;
118 bool aShapeValid = aShapeValidator->isValid(aRefAttr, anArguments, aCircleError);
119 // the circle line is not a valid case
121 theError = "Circle can not be used in distance constraint";
126 anArguments.push_back("line");
127 Events_InfoMessage aLineError;
128 aShapeValid = aShapeValidator->isValid(aRefAttr, anArguments, aLineError);
129 // if the attribute value is not a line, that means it is a vertex. A vertex is always valid
131 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
132 // If it is a line then we have to check that first attribute id not a line
133 std::shared_ptr<SketchPlugin_Feature> aSFeature =
134 std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
135 SketchPlugin_Sketch* aSketch = aSFeature->sketch();
136 std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(aSketch);
137 std::shared_ptr<GeomDataAPI_Point2D> aPoint = SketcherPrs_Tools::getFeaturePoint(
138 aFeature->data(), aParamA, aPlane);
140 theError = "One of parameters of distance constraint should be a point";
148 bool SketchPlugin_TangentAttrValidator::isValid(const AttributePtr& theAttribute,
149 const std::list<std::string>& theArguments,
150 Events_InfoMessage& theError) const
152 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
153 theError = "The attribute with the %1 type is not processed";
154 theError.arg(theAttribute->attributeType());
158 // there is a check whether the feature contains a point and a linear edge or two point values
159 std::string aParamA = theArguments.front();
160 SessionPtr aMgr = ModelAPI_Session::get();
161 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
163 FeaturePtr anAttributeFeature =
164 std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
165 AttributeRefAttrPtr aRefAttr =
166 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
168 bool isObject = aRefAttr->isObject();
169 ObjectPtr anObject = aRefAttr->object();
170 if (!isObject || !anObject.get()) {
171 theError = "It uses an empty object";
175 FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject);
177 AttributeRefAttrPtr aOtherAttr = anAttributeFeature->data()->refattr(aParamA);
178 ObjectPtr aOtherObject = aOtherAttr->object();
179 FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject);
183 if (aRefFea->getKind() == SketchPlugin_Line::ID() &&
184 aOtherFea->getKind() == SketchPlugin_Line::ID()) {
185 theError = "Two segments cannot be tangent";
188 else if (isSpline(aRefFea) && isSpline(aOtherFea)) {
189 theError = "Two B-splines cannot be tangent";
194 bool hasSpline = isSpline(aRefFea);
195 if (!hasSpline && isSpline(aOtherFea)) {
197 std::swap(aRefFea, aOtherFea);
200 auto isApplicableCoincidence = [](FeaturePtr theFeature, const std::string& theAttrName) {
201 AttributeRefAttrPtr aRefAttr = theFeature->refattr(theAttrName);
202 if (aRefAttr->isObject())
204 AttributePtr anAttr = aRefAttr->attr();
205 FeaturePtr anOwner = ModelAPI_Feature::feature(anAttr->owner());
206 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr);
208 return anOwner->getKind() == SketchPlugin_BSpline::ID() &&
209 (aPointAttr->id() == SketchPlugin_BSpline::START_ID() ||
210 aPointAttr->id() == SketchPlugin_BSpline::END_ID());
213 AttributePoint2DArrayPtr aPntArray =
214 std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(anAttr);
215 if (aPntArray && anOwner->getKind() == SketchPlugin_BSpline::ID()) {
216 // check index of the pole
217 AttributeIntegerPtr anIndex = theAttrName == SketchPlugin_Constraint::ENTITY_A() ?
218 theFeature->integer(SketchPlugin_ConstraintCoincidenceInternal::INDEX_ENTITY_A()) :
219 theFeature->integer(SketchPlugin_ConstraintCoincidenceInternal::INDEX_ENTITY_B());
220 return anIndex && (anIndex->value() == 0 || anIndex->value() == aPntArray->size() - 1);
226 AttributePoint2DArrayPtr aBSplinePoles = std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(
227 aRefFea->attribute(SketchPlugin_BSplineBase::POLES_ID()));
228 // additional check the B-spline edge and the other edge have a coincident boundary point
229 std::set<FeaturePtr> aCoincidences = SketchPlugin_Tools::findCoincidentConstraints(aRefFea);
230 for (std::set<FeaturePtr>::iterator anIt = aCoincidences.begin();
231 anIt != aCoincidences.end() && !isValid; ++anIt) {
232 std::set<FeaturePtr> aCoinc;
233 if (isApplicableCoincidence(*anIt, SketchPlugin_Constraint::ENTITY_A()))
234 SketchPlugin_Tools::findCoincidences(*anIt, SketchPlugin_Constraint::ENTITY_B(),
236 else if (isApplicableCoincidence(*anIt, SketchPlugin_Constraint::ENTITY_B()))
237 SketchPlugin_Tools::findCoincidences(*anIt, SketchPlugin_Constraint::ENTITY_A(),
240 isValid = aCoinc.find(aOtherFea) != aCoinc.end();
247 bool SketchPlugin_PerpendicularAttrValidator::isValid(const AttributePtr& theAttribute,
248 const std::list<std::string>& theArguments,
249 Events_InfoMessage& theError) const
251 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
252 theError = "The attribute with the %1 type is not processed";
253 theError.arg(theAttribute->attributeType());
257 std::string aParamA = theArguments.front();
258 SessionPtr aMgr = ModelAPI_Session::get();
259 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
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();
450 SessionPtr aMgr = ModelAPI_Session::get();
451 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
453 FeaturePtr aConstraint = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
454 AttributeRefAttrPtr aRefAttrA = aConstraint->data()->refattr(aParamA);
456 theError = "The %1 attribute should be %2";
457 theError.arg(aParamA).arg(ModelAPI_AttributeRefAttr::typeId());
461 AttributeRefAttrPtr aRefAttrB =
462 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
464 // first attribute is a point, it may coincide with any object
465 if (!aRefAttrA->isObject())
468 ObjectPtr anObject = aRefAttrA->object();
469 if (!anObject.get()) {
470 theError = "%1 attribute has an empty object";
471 theError.arg(aParamA);
474 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrA->object());
475 if (!aFeature.get()) {
476 theError = "%1 attribute has an empty feature";
477 theError.arg(aParamA);
481 if (aFeature->getKind() == SketchPlugin_Point::ID())
485 // second attribute is a point, it may coincide with any object
486 if (!aRefAttrB->isObject())
489 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrB->object());
491 theError = "%1 attribute has an empty object";
492 theError.arg(theAttribute->id());
495 if (aFeature->getKind() == SketchPlugin_Point::ID())
498 theError = "There is no an attribute filled by a point";
503 bool SketchPlugin_CopyValidator::isValid(const AttributePtr& theAttribute,
504 const std::list<std::string>& theArguments,
505 Events_InfoMessage& theError) const
507 if (theAttribute->attributeType() != ModelAPI_AttributeRefList::typeId()) {
508 theError = "The attribute with the %1 type is not processed";
509 theError.arg(theAttribute->attributeType());
513 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
514 AttributeRefListPtr aSelAttr =
515 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
517 AttributeRefListPtr aRefListOfInitial = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
518 aFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
519 AttributeRefListPtr aRefListOfCopied = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
520 aFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
521 std::list<ObjectPtr> anInitialObjects = aRefListOfInitial->list();
522 std::list<ObjectPtr> aCopiedObjects = aRefListOfCopied->list();
524 std::list<ObjectPtr>::iterator anObjIter;
525 for(int anInd = 0; anInd < aSelAttr->size(); anInd++) {
526 ObjectPtr aSelObject = aSelAttr->object(anInd);
527 anObjIter = anInitialObjects.begin();
528 for (; anObjIter != anInitialObjects.end(); anObjIter++)
529 if (aSelObject == *anObjIter)
531 if (anObjIter != anInitialObjects.end())
534 // B-splines are not supported in Copying features
535 FeaturePtr aSelFeature = ModelAPI_Feature::feature(aSelObject);
536 if (aSelFeature && (aSelFeature->getKind() == SketchPlugin_BSpline::ID() ||
537 aSelFeature->getKind() == SketchPlugin_BSplinePeriodic::ID())) {
538 theError = "Not supported";
542 anObjIter = aCopiedObjects.begin();
543 for (; anObjIter != aCopiedObjects.end(); anObjIter++)
544 if (aSelObject == *anObjIter) {
545 std::string aName = aSelObject.get() ? aSelObject->data()->name() : "";
546 theError = "The object %1 is a result of copy";
554 bool SketchPlugin_SolverErrorValidator::isValid(
555 const std::shared_ptr<ModelAPI_Feature>& theFeature,
556 const std::list<std::string>& theArguments,
557 Events_InfoMessage& theError) const
559 AttributeStringPtr aAttributeString = theFeature->string(SketchPlugin_Sketch::SOLVER_ERROR());
561 if (!aAttributeString->value().empty()) {
562 theError = aAttributeString->value();
569 bool SketchPlugin_SolverErrorValidator::isNotObligatory(std::string theFeature,
570 std::string theAttribute)
575 static bool hasSameTangentFeature(const std::set<AttributePtr>& theRefsList,
576 const FeaturePtr theFeature)
578 for(std::set<AttributePtr>::const_iterator
579 anIt = theRefsList.cbegin(); anIt != theRefsList.cend(); ++anIt) {
580 std::shared_ptr<ModelAPI_Attribute> aAttr = (*anIt);
581 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
584 if (aFeature->getKind() == SketchPlugin_ConstraintTangent::ID()) {
585 AttributeRefAttrPtr anAttrRefA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
586 aFeature->attribute(SketchPlugin_ConstraintTangent::ENTITY_A()));
587 AttributeRefAttrPtr anAttrRefB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
588 aFeature->attribute(SketchPlugin_ConstraintTangent::ENTITY_B()));
589 if(anAttrRefA.get()) {
590 ResultPtr aResA = std::dynamic_pointer_cast<ModelAPI_Result>(anAttrRefA->object());
592 DocumentPtr aDoc = aResA->document();
594 FeaturePtr aFeatureA = aDoc->feature(aResA);
595 if(aFeatureA.get() && aFeatureA == theFeature) {
601 if(anAttrRefB.get()) {
602 ResultPtr aResB = std::dynamic_pointer_cast<ModelAPI_Result>(anAttrRefB->object());
604 DocumentPtr aDoc = aResB->document();
606 FeaturePtr aFeatureB = aDoc->feature(aResB);
607 if(aFeatureB.get() && aFeatureB == theFeature) {
618 static bool isPointPointCoincidence(const FeaturePtr& theCoincidence)
620 AttributeRefAttrPtr aRefAttr[2] = {
621 theCoincidence->refattr(SketchPlugin_Constraint::ENTITY_A()),
622 theCoincidence->refattr(SketchPlugin_Constraint::ENTITY_B())
625 bool arePoints = true;
626 for (int i = 0; i < 2 && arePoints; ++i) {
627 if (aRefAttr[i]->isObject()) {
628 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr[i]->object());
629 arePoints = aFeature.get() && aFeature->getKind() == SketchPlugin_Point::ID();
631 arePoints = aRefAttr[i]->attr().get() != NULL;
636 bool SketchPlugin_FilletVertexValidator::isValid(const AttributePtr& theAttribute,
637 const std::list<std::string>& theArguments,
638 Events_InfoMessage& theError) const
640 AttributeRefAttrPtr aPointRefAttr =
641 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
642 if(!aPointRefAttr.get()) {
643 theError = "Error: Point not selected.";
647 AttributePtr aPointAttribute = aPointRefAttr->attr();
648 if (!aPointAttribute.get()) {
649 theError = "Error: Bad point selected.";
652 std::shared_ptr<GeomAPI_Pnt2d> aSelectedPnt =
653 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aPointAttribute)->pnt();
655 // Obtain constraint coincidence for the fillet point.
656 const std::set<AttributePtr>& aRefsList = aPointAttribute->owner()->data()->refsToMe();
657 FeaturePtr aConstraintCoincidence;
658 for(std::set<AttributePtr>::const_iterator anIt = aRefsList.cbegin();
659 anIt != aRefsList.cend(); ++anIt) {
660 std::shared_ptr<ModelAPI_Attribute> aAttr = (*anIt);
661 FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
662 if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
663 if (!isPointPointCoincidence(aConstrFeature))
666 AttributeRefAttrPtr anAttrRefA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
667 aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_A()));
668 AttributeRefAttrPtr anAttrRefB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
669 aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_B()));
671 AttributePtr anAttrA = anAttrRefA->attr();
672 if(aPointAttribute == anAttrA) {
673 aConstraintCoincidence = aConstrFeature;
677 AttributePtr anAttrB = anAttrRefB->attr();
678 if(aPointAttribute == anAttrB) {
679 aConstraintCoincidence = aConstrFeature;
685 if(!aConstraintCoincidence.get()) {
686 theError = "Error: one of the selected point does not have coincidence.";
690 // Get coincides from constraint.
691 std::set<FeaturePtr> aCoinsides;
692 SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
693 SketchPlugin_ConstraintCoincidence::ENTITY_A(),
696 SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
697 SketchPlugin_ConstraintCoincidence::ENTITY_B(),
701 // Remove points and external lines from set of coincides.
702 std::set<FeaturePtr> aNewSetOfCoincides;
703 for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin();
704 anIt != aCoinsides.end(); ++anIt) {
705 std::shared_ptr<SketchPlugin_SketchEntity> aSketchEntity =
706 std::dynamic_pointer_cast<SketchPlugin_SketchEntity>(*anIt);
707 if(aSketchEntity.get() && (aSketchEntity->isCopy() || aSketchEntity->isExternal())) {
710 if((*anIt)->getKind() != SketchPlugin_Line::ID() &&
711 (*anIt)->getKind() != SketchPlugin_Arc::ID()) {
714 if((*anIt)->getKind() == SketchPlugin_Arc::ID()) {
715 AttributePtr anArcCenter = (*anIt)->attribute(SketchPlugin_Arc::CENTER_ID());
716 std::shared_ptr<GeomAPI_Pnt2d> anArcCenterPnt =
717 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anArcCenter)->pnt();
718 double aDistSelectedArcCenter = aSelectedPnt->distance(anArcCenterPnt);
719 if(aDistSelectedArcCenter < tolerance) {
723 aNewSetOfCoincides.insert(*anIt);
725 aCoinsides = aNewSetOfCoincides;
727 // If we still have more than two coincides remove auxilary entities from set of coincides.
728 if(aCoinsides.size() > 2) {
729 aNewSetOfCoincides.clear();
730 for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin();
731 anIt != aCoinsides.end(); ++anIt) {
732 if(!(*anIt)->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value()) {
733 aNewSetOfCoincides.insert(*anIt);
736 aCoinsides = aNewSetOfCoincides;
739 if(aCoinsides.size() != 2) {
740 theError = "Error: One of the selected points does not have two suitable edges for fillet.";
744 // Check that selected edges don't have tangent constraint.
745 std::set<FeaturePtr>::iterator anIt = aCoinsides.begin();
746 FeaturePtr aFirstFeature = *anIt++;
747 FeaturePtr aSecondFeature = *anIt;
748 const std::set<AttributePtr>& aFirstFeatureRefsList = aFirstFeature->data()->refsToMe();
749 if(hasSameTangentFeature(aFirstFeatureRefsList, aSecondFeature)) {
750 theError = "Error: Edges in selected point has tangent constraint.";
754 std::list<ResultPtr> aFirstResults = aFirstFeature->results();
755 for(std::list<ResultPtr>::iterator aResIt = aFirstResults.begin();
756 aResIt != aFirstResults.end(); ++aResIt) {
757 ResultPtr aRes = *aResIt;
758 const std::set<AttributePtr>& aResRefsList = aRes->data()->refsToMe();
759 if(hasSameTangentFeature(aResRefsList, aSecondFeature)) {
760 theError = "Error: Edges in selected point has tangent constraint.";
765 // Check the features are not tangent
766 std::shared_ptr<GeomAPI_Shape> aFirstShape = aFirstFeature->lastResult()->shape();
767 std::shared_ptr<GeomAPI_Shape> aSecondShape = aSecondFeature->lastResult()->shape();
768 if (!aFirstShape || !aFirstShape->isEdge() ||
769 !aSecondShape || !aSecondShape->isEdge()) {
770 theError = "Error: At least on of the features is not an edge";
774 std::shared_ptr<GeomAPI_Edge> anEdge1 = std::dynamic_pointer_cast<GeomAPI_Edge>(aFirstShape);
775 std::shared_ptr<GeomAPI_Edge> anEdge2 = std::dynamic_pointer_cast<GeomAPI_Edge>(aSecondShape);
777 static const double TOL = 1.e-7;
778 if (anEdge1->isLine() && anEdge2->isLine()) {
779 // Check that lines not collinear
780 std::shared_ptr<GeomAPI_Dir> aDir1 = anEdge1->line()->direction();
781 std::shared_ptr<GeomAPI_Dir> aDir2 = anEdge2->line()->direction();
782 double aCross = aDir1->cross(aDir2)->squareModulus();
783 if (aCross < TOL * TOL)
785 } else if (anEdge1->isArc() && anEdge2->isArc()) {
786 // check the circles are not tangent
787 std::shared_ptr<GeomAPI_Circ> aCirc1 = anEdge1->circle();
788 std::shared_ptr<GeomAPI_Circ> aCirc2 = anEdge2->circle();
789 double aDistCC = aCirc1->center()->distance(aCirc2->center());
790 double aRadSum = aCirc1->radius() + aCirc2->radius();
791 double aRadDiff = fabs(aCirc1->radius() - aCirc2->radius());
792 if (fabs(aDistCC - aRadSum) < TOL || fabs(aDistCC - aRadDiff) < TOL)
795 // check whether line and arc are tangent
796 std::shared_ptr<GeomAPI_Circ> aCirc;
797 std::shared_ptr<GeomAPI_Lin> aLine;
798 if (anEdge1->isLine()) {
799 aLine = anEdge1->line();
800 aCirc = anEdge2->circle();
802 aCirc = anEdge1->circle();
803 aLine = anEdge2->line();
806 double aDistCL = aLine->distance(aCirc->center());
807 if (fabs(aDistCL - aCirc->radius()) < TOL)
814 bool SketchPlugin_MiddlePointAttrValidator::isValid(const AttributePtr& theAttribute,
815 const std::list<std::string>& theArguments,
816 Events_InfoMessage& theError) const
818 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
819 theError = "The attribute with the %1 type is not processed";
820 theError.arg(theAttribute->attributeType());
824 // there is a check whether the feature contains a point and a linear edge or two point values
825 std::string aParamA = theArguments.front();
826 SessionPtr aMgr = ModelAPI_Session::get();
827 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
829 FeaturePtr anAttributeFeature =
830 std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
831 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
832 AttributeRefAttrPtr anOtherAttr = anAttributeFeature->data()->refattr(aParamA);
834 AttributeRefAttrPtr aRefAttrs[2] = {aRefAttr, anOtherAttr};
837 for (int i = 0; i < 2; ++i) {
838 if (!aRefAttrs[i]->isObject())
841 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrs[i]->object());
843 if (aNbPoints + aNbLines != 0)
848 if (aFeature->getKind() == SketchPlugin_Point::ID())
850 else if (aFeature->getKind() == SketchPlugin_Line::ID() ||
851 aFeature->getKind() == SketchPlugin_Arc::ID() ||
852 aFeature->getKind() == SketchPlugin_EllipticArc::ID())
857 if (aNbPoints != 1 || aNbLines != 1) {
858 theError = "Middle point constraint allows points and lines only";
864 bool SketchPlugin_ArcTangentPointValidator::isValid(const AttributePtr& theAttribute,
865 const std::list<std::string>& /*theArguments*/,
866 Events_InfoMessage& theError) const
868 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
869 theError = "The attribute with the %1 type is not processed";
870 theError.arg(theAttribute->attributeType());
873 FeaturePtr anOwner = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
874 AttributeStringPtr anArcTypeAttr = anOwner->string(SketchPlugin_MacroArc::ARC_TYPE());
875 if (anArcTypeAttr && anArcTypeAttr->value() != SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE())
876 return true; // not applicable for non-tangent arcs
878 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
879 AttributePtr anAttr = aRefAttr->attr();
881 theError = "The attribute %1 should be a point";
882 theError.arg(theAttribute->id());
886 FeaturePtr anAttrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->owner());
887 const std::string& aFeatureType = anAttrFeature->getKind();
888 if (aFeatureType == SketchPlugin_Arc::ID()) {
889 // selected point should not be a center of arc
890 const std::string& aPntId = anAttr->id();
891 if (aPntId != SketchPlugin_Arc::START_ID() && aPntId != SketchPlugin_Arc::END_ID()) {
892 theError = "The attribute %1 is not supported";
893 theError.arg(aPntId);
897 else if (aFeatureType == SketchPlugin_Line::ID()) {
898 // selected point should be bound point of line
899 const std::string& aPntId = anAttr->id();
900 if (aPntId != SketchPlugin_Line::START_ID() && aPntId != SketchPlugin_Line::END_ID()) {
901 theError = "The attribute %1 is not supported";
902 theError.arg(aPntId);
907 theError = "Unable to build tangent arc on %1";
908 theError.arg(anAttrFeature->getKind());
915 bool SketchPlugin_ArcTransversalPointValidator::isValid(
916 const AttributePtr& theAttribute,
917 const std::list<std::string>& /*theArguments*/,
918 Events_InfoMessage& theError) const
920 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
921 theError = "The attribute with the %1 type is not processed";
922 theError.arg(theAttribute->attributeType());
925 FeaturePtr anOwner = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
926 AttributeStringPtr anArcTypeAttr = anOwner->string(SketchPlugin_MacroArc::ARC_TYPE());
928 anArcTypeAttr->value() != SketchPlugin_MacroArc::ARC_TYPE_BY_TRANSVERSAL_LINE())
929 return true; // not applicable for non-transversal arcs
931 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
932 AttributePtr anAttr = aRefAttr->attr();
934 theError = "The attribute %1 should be a point";
935 theError.arg(theAttribute->id());
939 FeaturePtr anAttrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->owner());
940 const std::string& aFeatureType = anAttrFeature->getKind();
941 if (aFeatureType == SketchPlugin_Line::ID()) {
942 // selected point should be bound point of line
943 const std::string& aPntId = anAttr->id();
944 if (aPntId != SketchPlugin_Line::START_ID() && aPntId != SketchPlugin_Line::END_ID()) {
945 theError = "The attribute %1 is not supported";
946 theError.arg(aPntId);
951 theError = "Unable to build perpendicular arc on %1";
952 theError.arg(anAttrFeature->getKind());
959 bool SketchPlugin_IntersectionValidator::isValid(const AttributePtr& theAttribute,
960 const std::list<std::string>& theArguments,
961 Events_InfoMessage& theError) const
963 if (theAttribute->attributeType() != ModelAPI_AttributeSelection::typeId()) {
964 theError = "The attribute with the %1 type is not processed";
965 theError.arg(theAttribute->attributeType());
968 AttributeSelectionPtr anExternalAttr =
969 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
970 std::shared_ptr<GeomAPI_Edge> anEdge;
971 if (anExternalAttr && anExternalAttr->value() && anExternalAttr->value()->isEdge()) {
972 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anExternalAttr->value()));
973 } else if(anExternalAttr->context() && anExternalAttr->context()->shape() &&
974 anExternalAttr->context()->shape()->isEdge()) {
975 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anExternalAttr->context()->shape()));
979 theError = "The attribute %1 should be an edge";
980 theError.arg(theAttribute->id());
985 std::shared_ptr<SketchPlugin_Sketch> aSketch;
986 std::set<AttributePtr> aRefs = anExternalAttr->owner()->data()->refsToMe();
987 std::set<AttributePtr>::const_iterator anIt = aRefs.begin();
988 for (; anIt != aRefs.end(); ++anIt) {
989 CompositeFeaturePtr aComp =
990 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>((*anIt)->owner());
991 if (aComp && aComp->getKind() == SketchPlugin_Sketch::ID()) {
992 aSketch = std::dynamic_pointer_cast<SketchPlugin_Sketch>(aComp);
997 theError = "There is no sketch referring to the current feature";
1001 // check the edge is intersected with sketch plane
1002 std::shared_ptr<GeomAPI_Pln> aPlane = aSketch->plane();
1004 std::list<GeomPointPtr> anIntersectionsPoints;
1005 anEdge->intersectWithPlane(aPlane, anIntersectionsPoints);
1006 if (anIntersectionsPoints.empty()) {
1007 theError = "The edge is not intersected with sketch plane";
1013 bool SketchPlugin_SplitValidator::isValid(const AttributePtr& theAttribute,
1014 const std::list<std::string>& theArguments,
1015 Events_InfoMessage& theError) const
1017 bool aValid = false;
1019 if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
1020 theError = "The attribute with the %1 type is not processed";
1021 theError.arg(theAttribute->attributeType());
1024 AttributeReferencePtr aFeatureAttr =
1025 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
1026 std::shared_ptr<SketchPlugin_Feature> aSplitFeature =
1027 std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
1029 ObjectPtr anAttrObject = aFeatureAttr->value();
1030 if (!anAttrObject) {
1031 AttributePtr aPreviewAttr = aSplitFeature->attribute(SketchPlugin_Trim::PREVIEW_OBJECT());
1032 aFeatureAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(aPreviewAttr);
1033 anAttrObject = aFeatureAttr->value();
1036 FeaturePtr anAttrFeature = ModelAPI_Feature::feature(anAttrObject);
1040 // B-splines are not supported by the Split yet
1041 if (anAttrFeature->getKind() == SketchPlugin_BSpline::ID() ||
1042 anAttrFeature->getKind() == SketchPlugin_BSplinePeriodic::ID()) {
1043 theError = "Not supported";
1047 std::set<ResultPtr> anEdgeShapes;
1048 ModelGeomAlgo_Shape::shapesOfType(anAttrFeature, GeomAPI_Shape::EDGE, anEdgeShapes);
1049 if (anEdgeShapes.empty() || anEdgeShapes.size() > 1 /*there case has not existed yet*/)
1052 // coincidences to the feature
1053 std::set<std::shared_ptr<GeomDataAPI_Point2D> > aRefAttributes;
1054 ModelGeomAlgo_Point2D::getPointsOfReference(anAttrFeature,
1055 SketchPlugin_ConstraintCoincidence::ID(),
1056 aRefAttributes, SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
1058 GeomShapePtr anAttrShape = (*anEdgeShapes.begin())->shape();
1059 std::shared_ptr<SketchPlugin_Feature> aSFeature =
1060 std::dynamic_pointer_cast<SketchPlugin_Feature>(anAttrFeature);
1061 if (!aSFeature || aSFeature->isCopy())
1063 SketchPlugin_Sketch* aSketch = aSFeature->sketch();
1065 std::shared_ptr<ModelAPI_Data> aData = aSketch->data();
1066 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1067 aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
1068 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1069 aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
1070 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1071 aData->attribute(SketchPlugin_Sketch::NORM_ID()));
1072 std::shared_ptr<GeomAPI_Dir> aDirY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
1074 typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
1075 std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
1076 std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
1077 PointToRefsMap aPointsInfo;
1079 ModelGeomAlgo_Point2D::getPointsInsideShape(anAttrShape, aRefAttributes, aC->pnt(),
1080 aX->dir(), aDirY, aPointsInfo);
1081 int aCoincidentToFeature = (int)aPointsInfo.size();
1082 if (anAttrFeature->getKind() == SketchPlugin_Circle::ID() ||
1083 anAttrFeature->getKind() == SketchPlugin_Ellipse::ID())
1084 aValid = aCoincidentToFeature >= 2;
1086 aValid = aCoincidentToFeature >= 1;
1091 bool SketchPlugin_TrimValidator::isValid(const AttributePtr& theAttribute,
1092 const std::list<std::string>& theArguments,
1093 Events_InfoMessage& theError) const
1095 bool aValid = false;
1097 if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
1098 theError = "The attribute with the %1 type is not processed";
1099 theError.arg(theAttribute->attributeType());
1102 AttributeReferencePtr aBaseObjectAttr =
1103 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
1105 std::shared_ptr<SketchPlugin_Feature> aTrimFeature =
1106 std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
1108 ObjectPtr aBaseObject = aBaseObjectAttr->value();
1110 AttributePtr aPreviewAttr = aTrimFeature->attribute(SketchPlugin_Trim::PREVIEW_OBJECT());
1111 aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(aPreviewAttr);
1112 aBaseObject = aBaseObjectAttr->value();
1115 FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObject);
1119 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1120 std::dynamic_pointer_cast<SketchPlugin_Feature>(aBaseFeature);
1121 if (!aSketchFeature.get() || aSketchFeature->isCopy())
1124 // B-splines are not supported by the Trim yet
1125 if (aBaseFeature->getKind() == SketchPlugin_BSpline::ID() ||
1126 aBaseFeature->getKind() == SketchPlugin_BSplinePeriodic::ID()) {
1127 theError = "Not supported";
1132 AttributePoint2DPtr aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1133 aTrimFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT()));
1135 SketchPlugin_Sketch* aSketch = aTrimFeature->sketch();
1137 std::shared_ptr<GeomAPI_Pnt2d> anAttributePnt2d = aPoint->pnt();
1138 std::shared_ptr<GeomAPI_Pnt> anAttributePnt = aSketch->to3D(anAttributePnt2d->x(),
1139 anAttributePnt2d->y());
1141 std::map<ObjectPtr, std::set<GeomShapePtr> > aCashedShapes;
1142 std::map<ObjectPtr, std::map<std::shared_ptr<GeomAPI_Pnt>,
1143 std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
1144 std::list<std::shared_ptr<ModelAPI_Object> > > > > anObjectToPoints;
1145 SketchPlugin_SegmentationTools::fillObjectShapes(
1146 aTrimFeature.get(), aBaseObject, aCashedShapes, anObjectToPoints);
1147 const std::set<GeomShapePtr>& aShapes = aCashedShapes[aBaseObject];
1149 return aShapes.size() > 1;
1152 bool SketchPlugin_ProjectionValidator::isValid(const AttributePtr& theAttribute,
1153 const std::list<std::string>& theArguments,
1154 Events_InfoMessage& theError) const
1156 if (theAttribute->attributeType() != ModelAPI_AttributeSelection::typeId()) {
1157 theError = "The attribute with the %1 type is not processed";
1158 theError.arg(theAttribute->attributeType());
1162 AttributeSelectionPtr aFeatureAttr =
1163 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
1164 std::shared_ptr<GeomAPI_Edge> anEdge;
1165 std::shared_ptr<SketchPlugin_Feature> aSketchFeature;
1166 if (aFeatureAttr.get()) {
1167 GeomShapePtr aVal = aFeatureAttr->value();
1168 ResultPtr aRes = aFeatureAttr->context();
1169 if (aVal && aVal->isVertex())
1170 return true; // vertex is always could be projected
1171 if (aVal && aVal->isEdge()) {
1172 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aFeatureAttr->value()));
1173 } else if(aRes && aRes->shape()) {
1174 if (aRes->shape()->isVertex())
1175 return true; // vertex is always could be projected
1176 else if (aRes->shape()->isEdge())
1177 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aFeatureAttr->context()->shape()));
1180 // try to convert result to sketch feature
1183 std::dynamic_pointer_cast<SketchPlugin_Feature>(ModelAPI_Feature::feature(aRes));
1187 theError = "The attribute %1 should be an edge or vertex";
1188 theError.arg(theAttribute->id());
1193 std::shared_ptr<SketchPlugin_Sketch> aSketch;
1194 std::set<AttributePtr> aRefs = theAttribute->owner()->data()->refsToMe();
1195 std::set<AttributePtr>::const_iterator anIt = aRefs.begin();
1196 for (; anIt != aRefs.end(); ++anIt) {
1197 CompositeFeaturePtr aComp =
1198 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>((*anIt)->owner());
1199 if (aComp && aComp->getKind() == SketchPlugin_Sketch::ID()) {
1200 aSketch = std::dynamic_pointer_cast<SketchPlugin_Sketch>(aComp);
1205 theError = "There is no sketch referring to the current feature";
1208 if (aSketchFeature && aSketch.get() == aSketchFeature->sketch()) {
1209 theError = "Unable to project feature from the same sketch";
1213 std::shared_ptr<GeomAPI_Pln> aPlane = aSketch->plane();
1214 std::shared_ptr<GeomAPI_Dir> aNormal = aPlane->direction();
1215 std::shared_ptr<GeomAPI_Pnt> anOrigin = aPlane->location();
1218 if (anEdge->isLine()) {
1219 std::shared_ptr<GeomAPI_Lin> aLine = anEdge->line();
1220 std::shared_ptr<GeomAPI_Dir> aLineDir = aLine->direction();
1221 double aDot = fabs(aNormal->dot(aLineDir));
1222 aValid = fabs(aDot - 1.0) >= tolerance * tolerance;
1224 theError = "Error: Line is orthogonal to the sketch plane.";
1226 else if (anEdge->isCircle() || anEdge->isArc()) {
1227 std::shared_ptr<GeomAPI_Circ> aCircle = anEdge->circle();
1228 std::shared_ptr<GeomAPI_Dir> aCircNormal = aCircle->normal();
1229 double aDot = fabs(aNormal->dot(aCircNormal));
1230 aValid = aDot >= tolerance * tolerance;
1232 theError.arg(anEdge->isCircle() ? "Error: Circle is orthogonal to the sketch plane."
1233 : "Error: Arc is orthogonal to the sketch plane.");
1235 else if (anEdge->isEllipse()) {
1236 std::shared_ptr<GeomAPI_Ellipse> anEllipse = anEdge->ellipse();
1237 std::shared_ptr<GeomAPI_Dir> anEllipseNormal = anEllipse->normal();
1238 double aDot = fabs(aNormal->dot(anEllipseNormal));
1239 aValid = fabs(aDot - 1.0) <= tolerance * tolerance;
1241 theError.arg(anEdge->isClosed() ? "Error: Ellipse is orthogonal to the sketch plane."
1242 : "Error: Elliptic Arc is orthogonal to the sketch plane.");
1249 static std::set<FeaturePtr> common(const std::set<FeaturePtr>& theSet1,
1250 const std::set<FeaturePtr>& theSet2)
1252 std::set<FeaturePtr> aCommon;
1253 if (theSet1.empty() || theSet2.empty())
1256 std::set<FeaturePtr>::const_iterator anIt2 = theSet2.begin();
1257 for (; anIt2 != theSet2.end(); ++anIt2)
1258 if (theSet1.find(*anIt2) != theSet1.end())
1259 aCommon.insert(*anIt2);
1263 bool SketchPlugin_DifferentReferenceValidator::isValid(
1264 const AttributePtr& theAttribute,
1265 const std::list<std::string>& theArguments,
1266 Events_InfoMessage& theError) const
1268 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
1270 int aNbFeaturesReferred = 0;
1271 int aNbAttributesReferred = 0;
1272 std::set<FeaturePtr> aCommonReferredFeatures;
1274 // find all features referred by attributes listed in theArguments
1275 std::list<std::string>::const_iterator anArgIt = theArguments.begin();
1276 for (; anArgIt != theArguments.end(); ++anArgIt) {
1277 AttributeRefAttrPtr aRefAttr = anOwner->refattr(*anArgIt);
1281 std::set<FeaturePtr> aCoincidentFeatures;
1282 if (aRefAttr->isObject()) {
1283 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
1285 aCoincidentFeatures.insert(aFeature);
1286 aNbFeaturesReferred += 1;
1289 AttributePoint2DPtr aPoint =
1290 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aRefAttr->attr());
1292 aCoincidentFeatures = SketchPlugin_Tools::findFeaturesCoincidentToPoint(aPoint);
1293 aNbAttributesReferred += 1;
1297 if (aCommonReferredFeatures.empty())
1298 aCommonReferredFeatures = aCoincidentFeatures;
1300 aCommonReferredFeatures = common(aCommonReferredFeatures, aCoincidentFeatures);
1302 if (aCommonReferredFeatures.empty())
1306 bool isOk = aNbFeaturesReferred < 1;
1307 if (aNbFeaturesReferred == 1) {
1308 if (aCommonReferredFeatures.size() == 1) {
1309 FeaturePtr aFeature = *aCommonReferredFeatures.begin();
1310 isOk = aNbAttributesReferred <= 1 ||
1311 aFeature->getKind() == SketchPlugin_Circle::ID() ||
1312 aFeature->getKind() == SketchPlugin_Arc::ID();
1318 theError = "Attributes are referred to the same feature";
1322 bool SketchPlugin_DifferentPointReferenceValidator::isValid(
1323 const AttributePtr& theAttribute,
1324 const std::list<std::string>& theArguments,
1325 Events_InfoMessage& theError) const
1327 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
1328 std::set<AttributePoint2DPtr> aReferredCoincidentPoints;
1330 // find all points referred by attributes listed in theArguments
1331 bool hasRefsToPoints = false;
1332 std::list<std::string>::const_iterator anArgIt = theArguments.begin();
1333 for (; anArgIt != theArguments.end(); ++anArgIt) {
1334 AttributeRefAttrPtr aRefAttr = anOwner->refattr(*anArgIt);
1338 if (!aRefAttr->isObject()) {
1339 AttributePoint2DPtr aPoint =
1340 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aRefAttr->attr());
1341 if (aReferredCoincidentPoints.empty())
1342 aReferredCoincidentPoints = SketchPlugin_Tools::findPointsCoincidentToPoint(aPoint);
1343 else if (aReferredCoincidentPoints.find(aPoint) == aReferredCoincidentPoints.end())
1344 return true; // non-coincident point has been found
1346 hasRefsToPoints = true;
1350 if (hasRefsToPoints)
1351 theError = "Attributes are referred to the same point";
1352 return !hasRefsToPoints;
1355 bool SketchPlugin_CirclePassedPointValidator::isValid(
1356 const AttributePtr& theAttribute,
1357 const std::list<std::string>&,
1358 Events_InfoMessage& theError) const
1360 static const std::string aErrorMessage(
1361 "Passed point refers to the same feature as a center point");
1363 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
1365 AttributeRefAttrPtr aCenterRef =
1366 anOwner->refattr(SketchPlugin_MacroCircle::CENTER_POINT_REF_ID());
1367 AttributeRefAttrPtr aPassedRef =
1368 anOwner->refattr(SketchPlugin_MacroCircle::PASSED_POINT_REF_ID());
1370 if (!aPassedRef->isObject())
1373 FeaturePtr aPassedFeature = ModelAPI_Feature::feature(aPassedRef->object());
1374 if (!aPassedFeature)
1377 if (aCenterRef->isObject()) {
1378 if (aCenterRef->object() == aPassedRef->object()) {
1379 theError = aErrorMessage;
1383 AttributePoint2DPtr aCenterPoint =
1384 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aCenterRef->attr());
1386 std::set<FeaturePtr> aCoincidentFeatures =
1387 SketchPlugin_Tools::findFeaturesCoincidentToPoint(aCenterPoint);
1388 // check one of coincident features is a feature referred by passed point
1389 std::set<FeaturePtr>::const_iterator anIt = aCoincidentFeatures.begin();
1390 for(; anIt != aCoincidentFeatures.end(); ++anIt)
1391 if (*anIt == aPassedFeature) {
1392 theError = aErrorMessage;
1400 bool SketchPlugin_ThirdPointValidator::isValid(
1401 const AttributePtr& theAttribute,
1402 const std::list<std::string>& theArguments,
1403 Events_InfoMessage& theError) const
1405 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
1406 return arePointsNotOnLine(anOwner, theError) &&
1407 arePointsNotSeparated(anOwner, theArguments, theError);
1410 static std::shared_ptr<GeomAPI_Pnt2d> toPoint(const FeaturePtr& theMacroCircle,
1411 const std::string& thePointAttrName,
1412 const std::string& theRefPointAttrName)
1414 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1415 theMacroCircle->attribute(thePointAttrName));
1416 AttributeRefAttrPtr aRefAttr = theMacroCircle->refattr(theRefPointAttrName);
1418 std::shared_ptr<GeomAPI_Pnt2d> aPoint = aPointAttr->pnt();
1420 if (aRefAttr->isObject()) {
1421 // project a point onto selected feature
1422 std::shared_ptr<SketchPlugin_Feature> aFeature =
1423 std::dynamic_pointer_cast<SketchPlugin_Feature>(
1424 ModelAPI_Feature::feature(aRefAttr->object()));
1426 SketchPlugin_Sketch* aSketch = aFeature->sketch();
1427 std::shared_ptr<GeomAPI_Edge> anEdge =
1428 std::dynamic_pointer_cast<GeomAPI_Edge>(aFeature->lastResult()->shape());
1430 std::shared_ptr<GeomAPI_Pnt> aPoint3D = aSketch->to3D(aPoint->x(), aPoint->y());
1431 if (anEdge->isLine())
1432 aPoint3D = anEdge->line()->project(aPoint3D);
1433 else if (anEdge->isCircle())
1434 aPoint3D = anEdge->circle()->project(aPoint3D);
1436 aPoint = aSketch->to2D(aPoint3D);
1440 AttributePoint2DPtr anOtherPoint =
1441 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aRefAttr->attr());
1443 aPoint = anOtherPoint->pnt(); // the reference point is much more precise, use it
1450 static void threePointsOfFeature(const FeaturePtr& theMacroFeature,
1451 std::shared_ptr<GeomAPI_Pnt2d> thePoints[3])
1453 if (theMacroFeature->getKind() == SketchPlugin_MacroCircle::ID()) {
1454 thePoints[0] = toPoint(theMacroFeature,
1455 SketchPlugin_MacroCircle::FIRST_POINT_ID(),
1456 SketchPlugin_MacroCircle::FIRST_POINT_REF_ID());
1457 thePoints[1] = toPoint(theMacroFeature,
1458 SketchPlugin_MacroCircle::SECOND_POINT_ID(),
1459 SketchPlugin_MacroCircle::SECOND_POINT_REF_ID());
1460 thePoints[2] = toPoint(theMacroFeature,
1461 SketchPlugin_MacroCircle::THIRD_POINT_ID(),
1462 SketchPlugin_MacroCircle::THIRD_POINT_REF_ID());
1463 } else if (theMacroFeature->getKind() == SketchPlugin_MacroArc::ID()) {
1464 thePoints[0] = toPoint(theMacroFeature,
1465 SketchPlugin_MacroArc::START_POINT_2_ID(),
1466 SketchPlugin_MacroArc::START_POINT_REF_ID());
1467 thePoints[1] = toPoint(theMacroFeature,
1468 SketchPlugin_MacroArc::END_POINT_2_ID(),
1469 SketchPlugin_MacroArc::END_POINT_REF_ID());
1470 thePoints[2] = toPoint(theMacroFeature,
1471 SketchPlugin_MacroArc::PASSED_POINT_ID(),
1472 SketchPlugin_MacroArc::PASSED_POINT_REF_ID());
1476 static bool isPointsOnLine(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
1477 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
1478 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
1480 static const double aTolerance = 1.e-7;
1481 if (thePoint1->distance(thePoint2) < aTolerance ||
1482 thePoint1->distance(thePoint3) < aTolerance)
1485 std::shared_ptr<GeomAPI_Dir2d> aDirP1P2(new GeomAPI_Dir2d(thePoint2->x() - thePoint1->x(),
1486 thePoint2->y() - thePoint1->y()));
1487 std::shared_ptr<GeomAPI_Dir2d> aDirP1P3(new GeomAPI_Dir2d(thePoint3->x() - thePoint1->x(),
1488 thePoint3->y() - thePoint1->y()));
1489 return fabs(aDirP1P2->cross(aDirP1P3)) < aTolerance;
1492 static bool isOnSameSide(const std::shared_ptr<GeomAPI_Lin>& theLine,
1493 const std::shared_ptr<GeomAPI_Pnt>& thePoint1,
1494 const std::shared_ptr<GeomAPI_Pnt>& thePoint2)
1496 static const double aTolerance = 1.e-7;
1497 std::shared_ptr<GeomAPI_Dir> aLineDir = theLine->direction();
1498 std::shared_ptr<GeomAPI_XYZ> aLineLoc = theLine->location()->xyz();
1500 std::shared_ptr<GeomAPI_XYZ> aVec1 = thePoint1->xyz()->decreased(aLineLoc);
1501 // the first point is on the line
1502 if (aVec1->squareModulus() < aTolerance * aTolerance)
1504 std::shared_ptr<GeomAPI_Dir> aDirP1L(new GeomAPI_Dir(aVec1));
1505 std::shared_ptr<GeomAPI_XYZ> aVec2 = thePoint2->xyz()->decreased(aLineLoc);
1506 // the second point is on the line
1507 if (aVec2->squareModulus() < aTolerance * aTolerance)
1509 std::shared_ptr<GeomAPI_Dir> aDirP2L(new GeomAPI_Dir(aVec2));
1511 return aLineDir->cross(aDirP1L)->dot(aLineDir->cross(aDirP2L)) > -aTolerance;
1514 static bool isOnSameSide(const std::shared_ptr<GeomAPI_Circ>& theCircle,
1515 const std::shared_ptr<GeomAPI_Pnt>& thePoint1,
1516 const std::shared_ptr<GeomAPI_Pnt>& thePoint2)
1518 static const double aTolerance = 1.e-7;
1519 std::shared_ptr<GeomAPI_Pnt> aCenter = theCircle->center();
1520 double aDistP1C = thePoint1->distance(aCenter);
1521 double aDistP2C = thePoint2->distance(aCenter);
1522 return (aDistP1C - theCircle->radius()) * (aDistP2C - theCircle->radius()) > -aTolerance;
1525 bool SketchPlugin_ThirdPointValidator::arePointsNotOnLine(
1526 const FeaturePtr& theMacroFeature,
1527 Events_InfoMessage& theError) const
1529 static const std::string aErrorPointsOnLine(
1530 "Selected points are on the same line");
1532 std::shared_ptr<GeomAPI_Pnt2d> aPoints[3];
1533 threePointsOfFeature(theMacroFeature, aPoints);
1535 if (isPointsOnLine(aPoints[0], aPoints[1], aPoints[2])) {
1536 theError = aErrorPointsOnLine;
1542 bool SketchPlugin_ThirdPointValidator::arePointsNotSeparated(
1543 const FeaturePtr& theMacroFeature,
1544 const std::list<std::string>& theArguments,
1545 Events_InfoMessage& theError) const
1547 static const std::string aErrorPointsApart(
1548 "Selected entity is lying between first two points");
1550 AttributeRefAttrPtr aThirdPointRef = theMacroFeature->refattr(theArguments.front());
1551 FeaturePtr aRefByThird;
1552 if (aThirdPointRef->isObject())
1553 aRefByThird = ModelAPI_Feature::feature(aThirdPointRef->object());
1557 std::shared_ptr<GeomAPI_Pnt2d> aPoints[3];
1558 threePointsOfFeature(theMacroFeature, aPoints);
1560 std::shared_ptr<GeomAPI_Edge> aThirdShape =
1561 std::dynamic_pointer_cast<GeomAPI_Edge>(aRefByThird->lastResult()->shape());
1565 SketchPlugin_Sketch* aSketch =
1566 std::dynamic_pointer_cast<SketchPlugin_Feature>(theMacroFeature)->sketch();
1567 std::shared_ptr<GeomAPI_Pnt> aFirstPnt3D = aSketch->to3D(aPoints[0]->x(), aPoints[0]->y());
1568 std::shared_ptr<GeomAPI_Pnt> aSecondPnt3D = aSketch->to3D(aPoints[1]->x(), aPoints[1]->y());
1571 if (aThirdShape->isLine())
1572 isOk = isOnSameSide(aThirdShape->line(), aFirstPnt3D, aSecondPnt3D);
1573 else if (aThirdShape->isCircle() || aThirdShape->isArc())
1574 isOk = isOnSameSide(aThirdShape->circle(), aFirstPnt3D, aSecondPnt3D);
1577 theError = aErrorPointsApart;
1581 bool SketchPlugin_ArcEndPointValidator::isValid(
1582 const AttributePtr& theAttribute,
1583 const std::list<std::string>& theArguments,
1584 Events_InfoMessage& theError) const
1586 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
1587 AttributeRefAttrPtr anEndPointRef = aFeature->refattr(theArguments.front());
1589 if(!anEndPointRef.get()) {
1593 ObjectPtr anObject = anEndPointRef->object();
1594 AttributePtr anAttr = anEndPointRef->attr();
1595 if(!anObject.get() && !anAttr.get()) {
1599 if(anEndPointRef->attr().get()) {
1603 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1605 GeomShapePtr aShape = aResult->shape();
1606 if(aShape.get() && aShape->isVertex()) {
1611 aFeature = ModelAPI_Feature::feature(anObject);
1612 if(aFeature.get()) {
1613 if(aFeature->getKind() == SketchPlugin_Point::ID()) {
1621 static GeomShapePtr toInfiniteEdge(const GeomShapePtr theShape)
1623 if(!theShape.get()) {
1627 if(!theShape->isEdge()) {
1631 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
1637 if(anEdge->isLine()) {
1638 std::shared_ptr<GeomAPI_Lin> aLine = anEdge->line();
1639 GeomShapePtr aShape = GeomAlgoAPI_EdgeBuilder::line(aLine);
1643 if(anEdge->isCircle() || anEdge->isArc()) {
1644 std::shared_ptr<GeomAPI_Circ> aCircle = anEdge->circle();
1645 GeomShapePtr aShape = GeomAlgoAPI_EdgeBuilder::lineCircle(aCircle);
1652 bool SketchPlugin_ArcEndPointIntersectionValidator::isValid(
1653 const AttributePtr& theAttribute,
1654 const std::list<std::string>& theArguments,
1655 Events_InfoMessage& theError) const
1657 std::shared_ptr<SketchPlugin_MacroArc> anArcFeature =
1658 std::dynamic_pointer_cast<SketchPlugin_MacroArc>(theAttribute->owner());
1659 AttributeRefAttrPtr anEndPointRef = anArcFeature->refattr(theArguments.front());
1661 if(!anEndPointRef.get()) {
1665 GeomShapePtr anArcShape = toInfiniteEdge(anArcFeature->getArcShape(false));
1667 if(!anArcShape.get() || anArcShape->isNull()) {
1671 ObjectPtr anObject = anEndPointRef->object();
1672 AttributePtr anAttr = anEndPointRef->attr();
1673 if(!anObject.get() && !anAttr.get()) {
1677 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1679 GeomShapePtr aShape = aResult->shape();
1680 if (!aShape->isEdge())
1682 aShape = toInfiniteEdge(aShape);
1683 if(aShape.get() && !aShape->isNull()) {
1684 if(anArcShape->isIntersect(aShape)) {
1690 FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(anObject);
1691 if(aSelectedFeature.get()) {
1692 std::list<ResultPtr> aResults = aSelectedFeature->results();
1693 for(std::list<ResultPtr>::const_iterator anIt = aResults.cbegin();
1694 anIt != aResults.cend();
1697 GeomShapePtr aShape = (*anIt)->shape();
1698 if (!aShape->isEdge())
1700 aShape = toInfiniteEdge(aShape);
1701 if(aShape.get() && !aShape->isNull()) {
1702 if(anArcShape->isIntersect(aShape)) {
1712 bool SketchPlugin_HasNoConstraint::isValid(const AttributePtr& theAttribute,
1713 const std::list<std::string>& theArguments,
1714 Events_InfoMessage& theError) const
1716 std::set<std::string> aFeatureKinds;
1717 for (std::list<std::string>::const_iterator anArgIt = theArguments.begin();
1718 anArgIt != theArguments.end(); anArgIt++) {
1719 aFeatureKinds.insert(*anArgIt);
1722 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
1723 theError = "The attribute with the %1 type is not processed";
1724 theError.arg(theAttribute->attributeType());
1728 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
1730 bool isObject = aRefAttr->isObject();
1732 theError = "It uses an empty object";
1735 ObjectPtr anObject = aRefAttr->object();
1736 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1737 if (!aFeature.get()) {
1738 theError = "The feature of the checked attribute is empty";
1742 FeaturePtr aCurrentFeature = ModelAPI_Feature::feature(aRefAttr->owner());
1744 std::set<AttributePtr> aRefsList = anObject->data()->refsToMe();
1745 std::set<AttributePtr>::const_iterator anIt = aRefsList.begin();
1746 for (; anIt != aRefsList.end(); anIt++) {
1747 FeaturePtr aRefFeature = ModelAPI_Feature::feature((*anIt)->owner());
1748 if (aRefFeature.get() && aCurrentFeature != aRefFeature &&
1749 aFeatureKinds.find(aRefFeature->getKind()) != aFeatureKinds.end())
1750 return false; // constraint is found, that means that the check is not valid
1755 bool SketchPlugin_ReplicationReferenceValidator::isValid(
1756 const AttributePtr& theAttribute,
1757 const std::list<std::string>& theArguments,
1758 Events_InfoMessage& theError) const
1760 AttributeRefAttrPtr aRefAttr =
1761 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
1764 theError = "Incorrect attribute";
1769 if (aRefAttr->isObject())
1770 anOwner = aRefAttr->object();
1773 AttributePtr anAttr = aRefAttr->attr();
1774 anOwner = anAttr->owner();
1776 FeaturePtr anAttrOwnerFeature = ModelAPI_Feature::feature(anOwner);
1777 if (!anAttrOwnerFeature)
1779 AttributeBooleanPtr aCopyAttr = anAttrOwnerFeature->boolean(SketchPlugin_SketchEntity::COPY_ID());
1780 if (!aCopyAttr || !aCopyAttr->value())
1781 return true; // feature is not a copy, thus valid
1783 // check the copy feature is already referred by the "Multi" feature
1784 FeaturePtr aMultiFeature = ModelAPI_Feature::feature(theAttribute->owner());
1785 AttributeRefListPtr aRefList = aMultiFeature->reflist(theArguments.front());
1786 for (int i = 0; i < aRefList->size(); ++i)
1788 FeaturePtr aRefOwner = ModelAPI_Feature::feature(aRefList->object(i));
1789 if (aRefOwner == anAttrOwnerFeature)
1791 theError = "Attribute refers to the object generated by this feature";
1799 bool SketchPlugin_SketchFeatureValidator::isValid(const AttributePtr& theAttribute,
1800 const std::list<std::string>& theArguments,
1801 Events_InfoMessage& theError) const
1803 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
1804 theError = "The attribute with the %1 type is not processed";
1805 theError.arg(theAttribute->attributeType());
1809 // check the attribute refers to a sketch feature
1810 AttributeRefAttrPtr aRefAttr =
1811 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
1812 bool isSketchFeature = aRefAttr->isObject();
1813 if (isSketchFeature) {
1814 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
1815 isSketchFeature = aFeature.get() != NULL;
1816 if (isSketchFeature) {
1817 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1818 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1819 isSketchFeature = aSketchFeature.get() != NULL;
1823 if (isSketchFeature)
1826 theError = "The object selected is not a sketch feature";
1830 bool SketchPlugin_MultiRotationAngleValidator::isValid(const AttributePtr& theAttribute,
1831 const std::list<std::string>& theArguments,
1832 Events_InfoMessage& theError) const
1834 if (theAttribute->attributeType() != ModelAPI_AttributeDouble::typeId()) {
1835 theError = "The attribute with the %1 type is not processed";
1836 theError.arg(theAttribute->attributeType());
1840 AttributeDoublePtr anAngleAttr =
1841 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
1843 FeaturePtr aMultiRotation = ModelAPI_Feature::feature(theAttribute->owner());
1844 AttributeStringPtr anAngleType =
1845 aMultiRotation->string(SketchPlugin_MultiRotation::ANGLE_TYPE());
1846 AttributeIntegerPtr aNbCopies =
1847 aMultiRotation->integer(SketchPlugin_MultiRotation::NUMBER_OF_OBJECTS_ID());
1849 if (anAngleType->value() != "FullAngle")
1851 double aFullAngleValue = anAngleAttr->value() * (aNbCopies->value() - 1);
1852 if (aFullAngleValue < -1.e-7 || aFullAngleValue > 359.9999999)
1854 theError = "Rotation single angle should produce full angle less than 360 degree";
1860 double aFullAngleValue = anAngleAttr->value();
1861 if (aFullAngleValue < -1.e-7 || aFullAngleValue > 360.0000001)
1863 theError = "Rotation full angle should be in range [0, 360]";
1871 bool SketchPlugin_BSplineValidator::isValid(const AttributePtr& theAttribute,
1872 const std::list<std::string>& theArguments,
1873 Events_InfoMessage& theError) const
1875 AttributePoint2DArrayPtr aPolesArray =
1876 std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(theAttribute);
1880 if (aPolesArray->size() < 2) {
1881 theError = "Number of B-spline poles should be 2 or more";