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_CurveFitting.h"
35 #include "SketchPlugin_Line.h"
36 #include "SketchPlugin_MacroArc.h"
37 #include "SketchPlugin_MacroCircle.h"
38 #include "SketchPlugin_MultiRotation.h"
39 #include "SketchPlugin_Offset.h"
40 #include "SketchPlugin_Point.h"
41 #include "SketchPlugin_Sketch.h"
42 #include "SketchPlugin_Trim.h"
43 #include "SketchPlugin_Tools.h"
45 #include "SketcherPrs_Tools.h"
47 #include <Events_InfoMessage.h>
49 #include <Locale_Convert.h>
51 #include <ModelAPI_Data.h>
52 #include <ModelAPI_Validator.h>
53 #include <ModelAPI_AttributeDouble.h>
54 #include <ModelAPI_AttributeInteger.h>
55 #include <ModelAPI_AttributeRefAttr.h>
56 #include <ModelAPI_AttributeRefAttrList.h>
57 #include <ModelAPI_AttributeRefList.h>
58 #include <ModelAPI_AttributeSelectionList.h>
59 #include <ModelAPI_AttributeString.h>
60 #include <ModelAPI_Session.h>
61 #include <ModelAPI_Tools.h>
62 #include <ModelAPI_ResultConstruction.h>
64 #include <ModelGeomAlgo_Point2D.h>
65 #include <ModelGeomAlgo_Shape.h>
67 #include <GeomAlgoAPI_EdgeBuilder.h>
68 #include <GeomAlgoAPI_ShapeTools.h>
70 #include <GeomAPI_Circ.h>
71 #include <GeomAPI_Dir2d.h>
72 #include <GeomAPI_Ellipse.h>
73 #include <GeomAPI_Lin.h>
74 #include <GeomAPI_Edge.h>
75 #include <GeomAPI_Vertex.h>
77 #include <GeomDataAPI_Point2D.h>
78 #include <GeomDataAPI_Point2DArray.h>
83 const double tolerance = 1.e-7;
85 static bool isSpline(FeaturePtr theFeature)
87 return theFeature && (theFeature->getKind() == SketchPlugin_BSpline::ID() ||
88 theFeature->getKind() == SketchPlugin_BSplinePeriodic::ID());
92 bool SketchPlugin_DistanceAttrValidator::isValid(const AttributePtr& theAttribute,
93 const std::list<std::string>& theArguments,
94 Events_InfoMessage& theError) const
96 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
97 theError = "The attribute with the %1 type is not processed";
98 theError.arg(theAttribute->attributeType());
102 // there is a check whether the feature contains a point and a linear edge or two point values
103 std::string aParamA = theArguments.front();
104 SessionPtr aMgr = ModelAPI_Session::get();
105 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
107 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
109 bool isObject = aRefAttr->isObject();
111 // an attribute is a point. A point value is valid always for the distance
114 // 1. check whether the references object is a linear
115 ObjectPtr anObject = aRefAttr->object();
117 const ModelAPI_AttributeValidator* aShapeValidator =
118 dynamic_cast<const ModelAPI_AttributeValidator*>(
119 aFactory->validator("GeomValidators_ShapeType"));
120 std::list<std::string> anArguments;
121 anArguments.push_back("circle");
122 Events_InfoMessage aCircleError;
123 bool aShapeValid = aShapeValidator->isValid(aRefAttr, anArguments, aCircleError);
124 // the circle line is not a valid case
126 theError = "Circle can not be used in distance constraint";
131 anArguments.push_back("line");
132 Events_InfoMessage aLineError;
133 aShapeValid = aShapeValidator->isValid(aRefAttr, anArguments, aLineError);
134 // if the attribute value is not a line, that means it is a vertex. A vertex is always valid
136 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
137 // If it is a line then we have to check that first attribute id not a line
138 std::shared_ptr<SketchPlugin_Feature> aSFeature =
139 std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
140 SketchPlugin_Sketch* aSketch = aSFeature->sketch();
141 std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(aSketch);
142 std::shared_ptr<GeomDataAPI_Point2D> aPoint = SketcherPrs_Tools::getFeaturePoint(
143 aFeature->data(), aParamA, aPlane);
145 theError = "One of parameters of distance constraint should be a point";
153 bool SketchPlugin_TangentAttrValidator::isValid(const AttributePtr& theAttribute,
154 const std::list<std::string>& theArguments,
155 Events_InfoMessage& theError) const
157 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
158 theError = "The attribute with the %1 type is not processed";
159 theError.arg(theAttribute->attributeType());
163 // there is a check whether the feature contains a point and a linear edge or two point values
164 std::string aParamA = theArguments.front();
165 SessionPtr aMgr = ModelAPI_Session::get();
166 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
168 FeaturePtr anAttributeFeature =
169 std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
170 AttributeRefAttrPtr aRefAttr =
171 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
173 bool isObject = aRefAttr->isObject();
174 ObjectPtr anObject = aRefAttr->object();
175 if (!isObject || !anObject.get()) {
176 theError = "It uses an empty object";
180 FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject);
182 AttributeRefAttrPtr aOtherAttr = anAttributeFeature->data()->refattr(aParamA);
183 ObjectPtr aOtherObject = aOtherAttr->object();
184 FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject);
188 if (aRefFea->getKind() == SketchPlugin_Line::ID() &&
189 aOtherFea->getKind() == SketchPlugin_Line::ID()) {
190 theError = "Two segments cannot be tangent";
193 else if (isSpline(aRefFea) && isSpline(aOtherFea)) {
194 theError = "Two B-splines cannot be tangent";
199 bool hasSpline = isSpline(aRefFea);
200 if (!hasSpline && isSpline(aOtherFea)) {
202 std::swap(aRefFea, aOtherFea);
205 auto isApplicableCoincidence = [](FeaturePtr theFeature, const std::string& theAttrName) {
206 AttributeRefAttrPtr aRefAttr = theFeature->refattr(theAttrName);
207 if (aRefAttr->isObject())
209 AttributePtr anAttr = aRefAttr->attr();
210 FeaturePtr anOwner = ModelAPI_Feature::feature(anAttr->owner());
211 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr);
213 return anOwner->getKind() == SketchPlugin_BSpline::ID() &&
214 (aPointAttr->id() == SketchPlugin_BSpline::START_ID() ||
215 aPointAttr->id() == SketchPlugin_BSpline::END_ID());
218 AttributePoint2DArrayPtr aPntArray =
219 std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(anAttr);
220 if (aPntArray && anOwner->getKind() == SketchPlugin_BSpline::ID()) {
221 // check index of the pole
222 AttributeIntegerPtr anIndex = theAttrName == SketchPlugin_Constraint::ENTITY_A() ?
223 theFeature->integer(SketchPlugin_ConstraintCoincidenceInternal::INDEX_ENTITY_A()) :
224 theFeature->integer(SketchPlugin_ConstraintCoincidenceInternal::INDEX_ENTITY_B());
225 return anIndex && (anIndex->value() == 0 || anIndex->value() == aPntArray->size() - 1);
231 AttributePoint2DArrayPtr aBSplinePoles = std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(
232 aRefFea->attribute(SketchPlugin_BSplineBase::POLES_ID()));
233 // additional check the B-spline edge and the other edge have a coincident boundary point
234 std::set<FeaturePtr> aCoincidences = SketchPlugin_Tools::findCoincidentConstraints(aRefFea);
235 for (std::set<FeaturePtr>::iterator anIt = aCoincidences.begin();
236 anIt != aCoincidences.end() && !isValid; ++anIt) {
237 std::set<FeaturePtr> aCoinc;
238 if (isApplicableCoincidence(*anIt, SketchPlugin_Constraint::ENTITY_A()))
239 SketchPlugin_Tools::findCoincidences(*anIt, SketchPlugin_Constraint::ENTITY_B(),
241 else if (isApplicableCoincidence(*anIt, SketchPlugin_Constraint::ENTITY_B()))
242 SketchPlugin_Tools::findCoincidences(*anIt, SketchPlugin_Constraint::ENTITY_A(),
245 isValid = aCoinc.find(aOtherFea) != aCoinc.end();
252 bool SketchPlugin_PerpendicularAttrValidator::isValid(const AttributePtr& theAttribute,
253 const std::list<std::string>& theArguments,
254 Events_InfoMessage& theError) const
256 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
257 theError = "The attribute with the %1 type is not processed";
258 theError.arg(theAttribute->attributeType());
262 std::string aParamA = theArguments.front();
263 SessionPtr aMgr = ModelAPI_Session::get();
264 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
266 FeaturePtr anOwner = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
267 AttributeRefAttrPtr aRefAttr =
268 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
270 bool isObject = aRefAttr->isObject();
271 ObjectPtr anObject = aRefAttr->object();
272 if (isObject && anObject.get()) {
273 FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject);
275 AttributeRefAttrPtr aOtherAttr = anOwner->refattr(aParamA);
276 ObjectPtr aOtherObject = aOtherAttr->object();
277 FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject);
279 // at least one feature should be a line
280 if (aRefFea->getKind() != SketchPlugin_Line::ID() &&
281 aOtherFea && aOtherFea->getKind() != SketchPlugin_Line::ID()) {
282 theError = "At least one feature should be a line";
285 else if (isSpline(aRefFea) || isSpline(aOtherFea)) {
286 theError = "B-spline is not supported";
291 theError = "It uses an empty object";
298 bool SketchPlugin_NotFixedValidator::isValid(const AttributePtr& theAttribute,
299 const std::list<std::string>& theArguments,
300 Events_InfoMessage& theError) const
302 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
303 theError = "The attribute with the %1 type is not processed";
304 theError.arg(theAttribute->attributeType());
308 std::shared_ptr<SketchPlugin_Feature> aFeature =
309 std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
313 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
315 SketchPlugin_Sketch* aSketch = aFeature->sketch();
316 int aNbFeatures = aSketch->numberOfSubs();
317 for (int anInd = 0; anInd < aNbFeatures; anInd++) {
318 FeaturePtr aSubFeature = aSketch->subFeature(anInd);
319 if (aSubFeature->getKind() != SketchPlugin_ConstraintRigid::ID() || aSubFeature == aFeature)
321 AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
322 aSubFeature->attribute(SketchPlugin_ConstraintRigid::ENTITY_A()));
323 if (aRefAttr->isObject()) {
324 if (aRefAttr->object() == aRAttr->object()) {
325 ObjectPtr anObject = aRefAttr->object();
326 std::wstring aName = anObject.get() ? anObject->data()->name() : L"";
327 theError = "The object %1 has been already fixed.";
332 else if (aRefAttr->attr() == aRAttr->attr()) {
333 AttributePtr anAttribute = aRefAttr->attr();
335 anAttribute.get() ? Locale::Convert::toWString(anAttribute->id()) : L"";
336 theError = "The attribute %1 has been already fixed.";
344 bool SketchPlugin_EqualAttrValidator::isValid(const AttributePtr& theAttribute,
345 const std::list<std::string>& theArguments,
346 Events_InfoMessage& theError) const
348 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
349 theError = "The attribute with the %1 type is not processed";
350 theError.arg(theAttribute->attributeType());
354 std::string aParamA = theArguments.front();
355 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
356 AttributeRefAttrPtr aRefAttr[2];
357 aRefAttr[0] = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
358 aRefAttr[1] = aFeature->data()->refattr(aParamA);
360 if (!aRefAttr[0]->isObject() || !aRefAttr[1]->isObject()) {
361 theError = "Attributes can not be used in equal constraint";
365 std::string aType[2];
366 std::list<std::string> anArguments;
367 for (int i = 0; i < 2; i++) {
368 aFeature = ModelAPI_Feature::feature(aRefAttr[i]->object());
372 aType[i] = aFeature->getKind();
373 if (aFeature->getKind() != SketchPlugin_Line::ID() &&
374 aFeature->getKind() != SketchPlugin_Circle::ID() &&
375 aFeature->getKind() != SketchPlugin_Arc::ID() &&
376 aFeature->getKind() != SketchPlugin_Ellipse::ID() &&
377 aFeature->getKind() != SketchPlugin_EllipticArc::ID()) {
378 theError = "The %1 feature is not supported by the Equal constraint.";
379 theError.arg(aFeature->getKind());
380 // wrong type of attribute
385 bool isOk = aType[0] == aType[1];
387 // circle and arc may be equal
388 isOk = (aType[0] == SketchPlugin_Arc::ID() && aType[1] == SketchPlugin_Circle::ID())
389 || (aType[0] == SketchPlugin_Circle::ID() && aType[1] == SketchPlugin_Arc::ID());
392 // ellipse and elliptic arc may be equal
393 isOk = (aType[0] == SketchPlugin_EllipticArc::ID() && aType[1] == SketchPlugin_Ellipse::ID())
394 || (aType[0] == SketchPlugin_Ellipse::ID() && aType[1] == SketchPlugin_EllipticArc::ID());
397 theError = "Features with kinds %1 and %2 can not be equal.";
398 theError.arg(aType[0]).arg(aType[1]);
404 bool SketchPlugin_MirrorAttrValidator::isValid(const AttributePtr& theAttribute,
405 const std::list<std::string>& theArguments,
406 Events_InfoMessage& theError) const
408 if (theAttribute->attributeType() != ModelAPI_AttributeRefList::typeId()) {
409 theError = "The attribute with the %1 type is not processed";
410 theError.arg(theAttribute->attributeType());
414 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
415 AttributeRefListPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
417 AttributeRefListPtr aRefListOfMirrored = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
418 aFeature->attribute(SketchPlugin_Constraint::ENTITY_C()));
419 std::list<ObjectPtr> aMirroredObjects = aRefListOfMirrored->list();
421 for(int anInd = 0; anInd < aSelAttr->size(); anInd++) {
422 ObjectPtr aSelObject = aSelAttr->object(anInd);
424 // B-splines are not supported in Mirror yet
425 FeaturePtr aSelFeature = ModelAPI_Feature::feature(aSelObject);
426 if (aSelFeature && (aSelFeature->getKind() == SketchPlugin_BSpline::ID() ||
427 aSelFeature->getKind() == SketchPlugin_BSplinePeriodic::ID())) {
428 theError = "Not supported";
432 std::wstring aName = aSelObject.get() ? aSelObject->data()->name() : L"";
433 std::list<ObjectPtr>::iterator aMirIter = aMirroredObjects.begin();
434 for (; aMirIter != aMirroredObjects.end(); aMirIter++)
435 if (aSelObject == *aMirIter) {
436 theError = "The object %1 is a result of mirror";
444 bool SketchPlugin_CoincidenceAttrValidator::isValid(const AttributePtr& theAttribute,
445 const std::list<std::string>& theArguments,
446 Events_InfoMessage& theError) const
448 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
449 theError = "The attribute with the %1 type is not processed";
450 theError.arg(theAttribute->attributeType());
454 // there is a check whether the feature contains a point and a linear edge or two point values
455 std::string aParamA = theArguments.front();
456 SessionPtr aMgr = ModelAPI_Session::get();
457 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
459 FeaturePtr aConstraint = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
460 AttributeRefAttrPtr aRefAttrA = aConstraint->data()->refattr(aParamA);
462 theError = "The %1 attribute should be %2";
463 theError.arg(aParamA).arg(ModelAPI_AttributeRefAttr::typeId());
467 AttributeRefAttrPtr aRefAttrB =
468 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
470 // first attribute is a point, it may coincide with any object
471 if (!aRefAttrA->isObject())
474 ObjectPtr anObject = aRefAttrA->object();
475 if (!anObject.get()) {
476 theError = "%1 attribute has an empty object";
477 theError.arg(aParamA);
480 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrA->object());
481 if (!aFeature.get()) {
482 theError = "%1 attribute has an empty feature";
483 theError.arg(aParamA);
487 if (aFeature->getKind() == SketchPlugin_Point::ID())
491 // second attribute is a point, it may coincide with any object
492 if (!aRefAttrB->isObject())
495 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrB->object());
497 theError = "%1 attribute has an empty object";
498 theError.arg(theAttribute->id());
501 if (aFeature->getKind() == SketchPlugin_Point::ID())
504 theError = "There is no an attribute filled by a point";
509 bool SketchPlugin_CopyValidator::isValid(const AttributePtr& theAttribute,
510 const std::list<std::string>& theArguments,
511 Events_InfoMessage& theError) const
513 if (theAttribute->attributeType() != ModelAPI_AttributeRefList::typeId()) {
514 theError = "The attribute with the %1 type is not processed";
515 theError.arg(theAttribute->attributeType());
519 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
520 AttributeRefListPtr aSelAttr =
521 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
523 AttributeRefListPtr aRefListOfInitial = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
524 aFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
525 AttributeRefListPtr aRefListOfCopied = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
526 aFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
527 std::list<ObjectPtr> anInitialObjects = aRefListOfInitial->list();
528 std::list<ObjectPtr> aCopiedObjects = aRefListOfCopied->list();
530 std::list<ObjectPtr>::iterator anObjIter;
531 for(int anInd = 0; anInd < aSelAttr->size(); anInd++) {
532 ObjectPtr aSelObject = aSelAttr->object(anInd);
533 anObjIter = anInitialObjects.begin();
534 for (; anObjIter != anInitialObjects.end(); anObjIter++)
535 if (aSelObject == *anObjIter)
537 if (anObjIter != anInitialObjects.end())
540 // B-splines are not supported in Copying features
541 FeaturePtr aSelFeature = ModelAPI_Feature::feature(aSelObject);
542 if (aFeature->getKind() != SketchPlugin_Offset::ID() &&
543 aSelFeature && (aSelFeature->getKind() == SketchPlugin_BSpline::ID() ||
544 aSelFeature->getKind() == SketchPlugin_BSplinePeriodic::ID())) {
545 theError = "Not supported";
549 anObjIter = aCopiedObjects.begin();
550 for (; anObjIter != aCopiedObjects.end(); anObjIter++) {
551 bool isFound = aSelObject == *anObjIter;
553 // check in the results of the feature
554 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anObjIter);
556 const std::list<ResultPtr>& aResults = aFeature->results();
557 for (std::list<ResultPtr>::const_iterator aResIt = aResults.begin();
558 aResIt != aResults.end() && !isFound; ++aResIt) {
559 isFound = aSelObject == *aResIt;
564 std::wstring aName = aSelObject.get() ? aSelObject->data()->name() : L"";
565 theError = "The object %1 is a result of copy";
574 bool SketchPlugin_SolverErrorValidator::isValid(
575 const std::shared_ptr<ModelAPI_Feature>& theFeature,
576 const std::list<std::string>& theArguments,
577 Events_InfoMessage& theError) const
579 AttributeStringPtr aAttributeString = theFeature->string(SketchPlugin_Sketch::SOLVER_ERROR());
581 if (!aAttributeString->value().empty()) {
582 theError = aAttributeString->value();
589 bool SketchPlugin_SolverErrorValidator::isNotObligatory(std::string theFeature,
590 std::string theAttribute)
595 static bool hasSameTangentFeature(const std::set<AttributePtr>& theRefsList,
596 const FeaturePtr theFeature)
598 for(std::set<AttributePtr>::const_iterator
599 anIt = theRefsList.cbegin(); anIt != theRefsList.cend(); ++anIt) {
600 std::shared_ptr<ModelAPI_Attribute> aAttr = (*anIt);
601 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
604 if (aFeature->getKind() == SketchPlugin_ConstraintTangent::ID()) {
605 AttributeRefAttrPtr anAttrRefA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
606 aFeature->attribute(SketchPlugin_ConstraintTangent::ENTITY_A()));
607 AttributeRefAttrPtr anAttrRefB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
608 aFeature->attribute(SketchPlugin_ConstraintTangent::ENTITY_B()));
609 if(anAttrRefA.get()) {
610 ResultPtr aResA = std::dynamic_pointer_cast<ModelAPI_Result>(anAttrRefA->object());
612 DocumentPtr aDoc = aResA->document();
614 FeaturePtr aFeatureA = aDoc->feature(aResA);
615 if(aFeatureA.get() && aFeatureA == theFeature) {
621 if(anAttrRefB.get()) {
622 ResultPtr aResB = std::dynamic_pointer_cast<ModelAPI_Result>(anAttrRefB->object());
624 DocumentPtr aDoc = aResB->document();
626 FeaturePtr aFeatureB = aDoc->feature(aResB);
627 if(aFeatureB.get() && aFeatureB == theFeature) {
638 static bool isPointPointCoincidence(const FeaturePtr& theCoincidence)
640 AttributeRefAttrPtr aRefAttr[2] = {
641 theCoincidence->refattr(SketchPlugin_Constraint::ENTITY_A()),
642 theCoincidence->refattr(SketchPlugin_Constraint::ENTITY_B())
645 bool arePoints = true;
646 for (int i = 0; i < 2 && arePoints; ++i) {
647 if (aRefAttr[i]->isObject()) {
648 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr[i]->object());
649 arePoints = aFeature.get() && aFeature->getKind() == SketchPlugin_Point::ID();
651 arePoints = aRefAttr[i]->attr().get() != NULL;
656 bool SketchPlugin_FilletVertexValidator::isValid(const AttributePtr& theAttribute,
657 const std::list<std::string>& theArguments,
658 Events_InfoMessage& theError) const
660 AttributeRefAttrPtr aPointRefAttr =
661 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
662 if(!aPointRefAttr.get()) {
663 theError = "Error: Point not selected.";
667 AttributePtr aPointAttribute = aPointRefAttr->attr();
668 if (!aPointAttribute.get()) {
669 theError = "Error: Bad point selected.";
672 std::shared_ptr<GeomAPI_Pnt2d> aSelectedPnt =
673 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aPointAttribute)->pnt();
675 // Obtain constraint coincidence for the fillet point.
676 const std::set<AttributePtr>& aRefsList = aPointAttribute->owner()->data()->refsToMe();
677 FeaturePtr aConstraintCoincidence;
678 for(std::set<AttributePtr>::const_iterator anIt = aRefsList.cbegin();
679 anIt != aRefsList.cend(); ++anIt) {
680 std::shared_ptr<ModelAPI_Attribute> aAttr = (*anIt);
681 FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
682 if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
683 if (!isPointPointCoincidence(aConstrFeature))
686 AttributeRefAttrPtr anAttrRefA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
687 aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_A()));
688 AttributeRefAttrPtr anAttrRefB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
689 aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_B()));
691 AttributePtr anAttrA = anAttrRefA->attr();
692 if(aPointAttribute == anAttrA) {
693 aConstraintCoincidence = aConstrFeature;
697 AttributePtr anAttrB = anAttrRefB->attr();
698 if(aPointAttribute == anAttrB) {
699 aConstraintCoincidence = aConstrFeature;
705 if(!aConstraintCoincidence.get()) {
706 theError = "Error: one of the selected point does not have coincidence.";
710 // Get coincides from constraint.
711 std::set<FeaturePtr> aCoinsides;
712 SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
713 SketchPlugin_ConstraintCoincidence::ENTITY_A(),
716 SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
717 SketchPlugin_ConstraintCoincidence::ENTITY_B(),
721 // Remove points and external lines from set of coincides.
722 std::set<FeaturePtr> aNewSetOfCoincides;
723 for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin();
724 anIt != aCoinsides.end(); ++anIt) {
725 std::shared_ptr<SketchPlugin_SketchEntity> aSketchEntity =
726 std::dynamic_pointer_cast<SketchPlugin_SketchEntity>(*anIt);
727 if(aSketchEntity.get() && (aSketchEntity->isCopy() || aSketchEntity->isExternal())) {
730 if((*anIt)->getKind() != SketchPlugin_Line::ID() &&
731 (*anIt)->getKind() != SketchPlugin_Arc::ID()) {
734 if((*anIt)->getKind() == SketchPlugin_Arc::ID()) {
735 AttributePtr anArcCenter = (*anIt)->attribute(SketchPlugin_Arc::CENTER_ID());
736 std::shared_ptr<GeomAPI_Pnt2d> anArcCenterPnt =
737 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anArcCenter)->pnt();
738 double aDistSelectedArcCenter = aSelectedPnt->distance(anArcCenterPnt);
739 if(aDistSelectedArcCenter < tolerance) {
743 aNewSetOfCoincides.insert(*anIt);
745 aCoinsides = aNewSetOfCoincides;
747 // If we still have more than two coincides remove auxilary entities from set of coincides.
748 if(aCoinsides.size() > 2) {
749 aNewSetOfCoincides.clear();
750 for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin();
751 anIt != aCoinsides.end(); ++anIt) {
752 if(!(*anIt)->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value()) {
753 aNewSetOfCoincides.insert(*anIt);
756 aCoinsides = aNewSetOfCoincides;
759 if(aCoinsides.size() != 2) {
760 theError = "Error: One of the selected points does not have two suitable edges for fillet.";
764 // Check that selected edges don't have tangent constraint.
765 std::set<FeaturePtr>::iterator anIt = aCoinsides.begin();
766 FeaturePtr aFirstFeature = *anIt++;
767 FeaturePtr aSecondFeature = *anIt;
768 const std::set<AttributePtr>& aFirstFeatureRefsList = aFirstFeature->data()->refsToMe();
769 if(hasSameTangentFeature(aFirstFeatureRefsList, aSecondFeature)) {
770 theError = "Error: Edges in selected point has tangent constraint.";
774 std::list<ResultPtr> aFirstResults = aFirstFeature->results();
775 for(std::list<ResultPtr>::iterator aResIt = aFirstResults.begin();
776 aResIt != aFirstResults.end(); ++aResIt) {
777 ResultPtr aRes = *aResIt;
778 const std::set<AttributePtr>& aResRefsList = aRes->data()->refsToMe();
779 if(hasSameTangentFeature(aResRefsList, aSecondFeature)) {
780 theError = "Error: Edges in selected point has tangent constraint.";
785 // Check the features are not tangent
786 std::shared_ptr<GeomAPI_Shape> aFirstShape = aFirstFeature->lastResult()->shape();
787 std::shared_ptr<GeomAPI_Shape> aSecondShape = aSecondFeature->lastResult()->shape();
788 if (!aFirstShape || !aFirstShape->isEdge() ||
789 !aSecondShape || !aSecondShape->isEdge()) {
790 theError = "Error: At least on of the features is not an edge";
794 std::shared_ptr<GeomAPI_Edge> anEdge1 = std::dynamic_pointer_cast<GeomAPI_Edge>(aFirstShape);
795 std::shared_ptr<GeomAPI_Edge> anEdge2 = std::dynamic_pointer_cast<GeomAPI_Edge>(aSecondShape);
797 static const double TOL = 1.e-7;
798 if (anEdge1->isLine() && anEdge2->isLine()) {
799 // Check that lines not collinear
800 std::shared_ptr<GeomAPI_Dir> aDir1 = anEdge1->line()->direction();
801 std::shared_ptr<GeomAPI_Dir> aDir2 = anEdge2->line()->direction();
802 double aCross = aDir1->cross(aDir2)->squareModulus();
803 if (aCross < TOL * TOL)
805 } else if (anEdge1->isArc() && anEdge2->isArc()) {
806 // check the circles are not tangent
807 std::shared_ptr<GeomAPI_Circ> aCirc1 = anEdge1->circle();
808 std::shared_ptr<GeomAPI_Circ> aCirc2 = anEdge2->circle();
809 double aDistCC = aCirc1->center()->distance(aCirc2->center());
810 double aRadSum = aCirc1->radius() + aCirc2->radius();
811 double aRadDiff = fabs(aCirc1->radius() - aCirc2->radius());
812 if (fabs(aDistCC - aRadSum) < TOL || fabs(aDistCC - aRadDiff) < TOL)
815 // check whether line and arc are tangent
816 std::shared_ptr<GeomAPI_Circ> aCirc;
817 std::shared_ptr<GeomAPI_Lin> aLine;
818 if (anEdge1->isLine()) {
819 aLine = anEdge1->line();
820 aCirc = anEdge2->circle();
822 aCirc = anEdge1->circle();
823 aLine = anEdge2->line();
826 double aDistCL = aLine->distance(aCirc->center());
827 if (fabs(aDistCL - aCirc->radius()) < TOL)
834 bool SketchPlugin_MiddlePointAttrValidator::isValid(const AttributePtr& theAttribute,
835 const std::list<std::string>& theArguments,
836 Events_InfoMessage& theError) const
838 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
839 theError = "The attribute with the %1 type is not processed";
840 theError.arg(theAttribute->attributeType());
844 // there is a check whether the feature contains a point and a linear edge or two point values
845 std::string aParamA = theArguments.front();
846 SessionPtr aMgr = ModelAPI_Session::get();
847 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
849 FeaturePtr anAttributeFeature =
850 std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
851 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
852 AttributeRefAttrPtr anOtherAttr = anAttributeFeature->data()->refattr(aParamA);
854 AttributeRefAttrPtr aRefAttrs[2] = {aRefAttr, anOtherAttr};
857 for (int i = 0; i < 2; ++i) {
858 if (!aRefAttrs[i]->isObject())
861 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrs[i]->object());
863 if (aNbPoints + aNbLines != 0)
868 if (aFeature->getKind() == SketchPlugin_Point::ID())
870 else if (aFeature->getKind() == SketchPlugin_Line::ID() ||
871 aFeature->getKind() == SketchPlugin_Arc::ID() ||
872 aFeature->getKind() == SketchPlugin_EllipticArc::ID())
877 if (aNbPoints != 1 || aNbLines != 1) {
878 theError = "Middle point constraint allows points and lines only";
884 bool SketchPlugin_ArcTangentPointValidator::isValid(const AttributePtr& theAttribute,
885 const std::list<std::string>& /*theArguments*/,
886 Events_InfoMessage& theError) const
888 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
889 theError = "The attribute with the %1 type is not processed";
890 theError.arg(theAttribute->attributeType());
893 FeaturePtr anOwner = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
894 AttributeStringPtr anArcTypeAttr = anOwner->string(SketchPlugin_MacroArc::ARC_TYPE());
895 if (anArcTypeAttr && anArcTypeAttr->value() != SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE())
896 return true; // not applicable for non-tangent arcs
898 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
899 AttributePtr anAttr = aRefAttr->attr();
901 theError = "The attribute %1 should be a point";
902 theError.arg(theAttribute->id());
906 FeaturePtr anAttrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->owner());
907 const std::string& aFeatureType = anAttrFeature->getKind();
908 if (aFeatureType == SketchPlugin_Arc::ID()) {
909 // selected point should not be a center of arc
910 const std::string& aPntId = anAttr->id();
911 if (aPntId != SketchPlugin_Arc::START_ID() && aPntId != SketchPlugin_Arc::END_ID()) {
912 theError = "The attribute %1 is not supported";
913 theError.arg(aPntId);
917 else if (aFeatureType == SketchPlugin_Line::ID()) {
918 // selected point should be bound point of line
919 const std::string& aPntId = anAttr->id();
920 if (aPntId != SketchPlugin_Line::START_ID() && aPntId != SketchPlugin_Line::END_ID()) {
921 theError = "The attribute %1 is not supported";
922 theError.arg(aPntId);
927 theError = "Unable to build tangent arc on %1";
928 theError.arg(anAttrFeature->getKind());
935 bool SketchPlugin_ArcTransversalPointValidator::isValid(
936 const AttributePtr& theAttribute,
937 const std::list<std::string>& /*theArguments*/,
938 Events_InfoMessage& theError) const
940 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
941 theError = "The attribute with the %1 type is not processed";
942 theError.arg(theAttribute->attributeType());
945 FeaturePtr anOwner = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
946 AttributeStringPtr anArcTypeAttr = anOwner->string(SketchPlugin_MacroArc::ARC_TYPE());
948 anArcTypeAttr->value() != SketchPlugin_MacroArc::ARC_TYPE_BY_TRANSVERSAL_LINE())
949 return true; // not applicable for non-transversal arcs
951 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
952 AttributePtr anAttr = aRefAttr->attr();
954 theError = "The attribute %1 should be a point";
955 theError.arg(theAttribute->id());
959 FeaturePtr anAttrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->owner());
960 const std::string& aFeatureType = anAttrFeature->getKind();
961 if (aFeatureType == SketchPlugin_Line::ID()) {
962 // selected point should be bound point of line
963 const std::string& aPntId = anAttr->id();
964 if (aPntId != SketchPlugin_Line::START_ID() && aPntId != SketchPlugin_Line::END_ID()) {
965 theError = "The attribute %1 is not supported";
966 theError.arg(aPntId);
971 theError = "Unable to build perpendicular arc on %1";
972 theError.arg(anAttrFeature->getKind());
979 bool SketchPlugin_IntersectionValidator::isValid(const AttributePtr& theAttribute,
980 const std::list<std::string>& theArguments,
981 Events_InfoMessage& theError) const
983 if (theAttribute->attributeType() != ModelAPI_AttributeSelection::typeId()) {
984 theError = "The attribute with the %1 type is not processed";
985 theError.arg(theAttribute->attributeType());
988 AttributeSelectionPtr anExternalAttr =
989 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
990 std::shared_ptr<GeomAPI_Edge> anEdge;
991 if (anExternalAttr && anExternalAttr->value() && anExternalAttr->value()->isEdge()) {
992 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anExternalAttr->value()));
993 } else if(anExternalAttr->context() && anExternalAttr->context()->shape() &&
994 anExternalAttr->context()->shape()->isEdge()) {
995 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anExternalAttr->context()->shape()));
999 theError = "The attribute %1 should be an edge";
1000 theError.arg(theAttribute->id());
1005 std::shared_ptr<SketchPlugin_Sketch> aSketch;
1006 std::set<AttributePtr> aRefs = anExternalAttr->owner()->data()->refsToMe();
1007 std::set<AttributePtr>::const_iterator anIt = aRefs.begin();
1008 for (; anIt != aRefs.end(); ++anIt) {
1009 CompositeFeaturePtr aComp =
1010 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>((*anIt)->owner());
1011 if (aComp && aComp->getKind() == SketchPlugin_Sketch::ID()) {
1012 aSketch = std::dynamic_pointer_cast<SketchPlugin_Sketch>(aComp);
1017 theError = "There is no sketch referring to the current feature";
1021 // check the edge is intersected with sketch plane
1022 std::shared_ptr<GeomAPI_Pln> aPlane = aSketch->plane();
1024 std::list<GeomPointPtr> anIntersectionsPoints;
1025 anEdge->intersectWithPlane(aPlane, anIntersectionsPoints);
1026 if (anIntersectionsPoints.empty()) {
1027 theError = "The edge is not intersected with sketch plane";
1033 bool SketchPlugin_SplitValidator::isValid(const AttributePtr& theAttribute,
1034 const std::list<std::string>& theArguments,
1035 Events_InfoMessage& theError) const
1037 bool aValid = false;
1039 if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
1040 theError = "The attribute with the %1 type is not processed";
1041 theError.arg(theAttribute->attributeType());
1044 AttributeReferencePtr aFeatureAttr =
1045 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
1046 std::shared_ptr<SketchPlugin_Feature> aSplitFeature =
1047 std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
1049 ObjectPtr anAttrObject = aFeatureAttr->value();
1050 if (!anAttrObject) {
1051 AttributePtr aPreviewAttr = aSplitFeature->attribute(SketchPlugin_Trim::PREVIEW_OBJECT());
1052 aFeatureAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(aPreviewAttr);
1053 anAttrObject = aFeatureAttr->value();
1056 FeaturePtr anAttrFeature = ModelAPI_Feature::feature(anAttrObject);
1060 // B-splines are not supported by the Split yet
1061 if (anAttrFeature->getKind() == SketchPlugin_BSpline::ID() ||
1062 anAttrFeature->getKind() == SketchPlugin_BSplinePeriodic::ID()) {
1063 theError = "Not supported";
1067 std::set<ResultPtr> anEdgeShapes;
1068 ModelGeomAlgo_Shape::shapesOfType(anAttrFeature, GeomAPI_Shape::EDGE, anEdgeShapes);
1069 if (anEdgeShapes.empty() || anEdgeShapes.size() > 1 /*there case has not existed yet*/)
1072 // coincidences to the feature
1073 std::set<std::shared_ptr<GeomDataAPI_Point2D> > aRefAttributes;
1074 ModelGeomAlgo_Point2D::getPointsOfReference(anAttrFeature,
1075 SketchPlugin_ConstraintCoincidence::ID(),
1076 aRefAttributes, SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
1078 GeomShapePtr anAttrShape = (*anEdgeShapes.begin())->shape();
1079 std::shared_ptr<SketchPlugin_Feature> aSFeature =
1080 std::dynamic_pointer_cast<SketchPlugin_Feature>(anAttrFeature);
1081 if (!aSFeature || aSFeature->isCopy())
1083 SketchPlugin_Sketch* aSketch = aSFeature->sketch();
1085 std::shared_ptr<ModelAPI_Data> aData = aSketch->data();
1086 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1087 aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
1088 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1089 aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
1090 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1091 aData->attribute(SketchPlugin_Sketch::NORM_ID()));
1092 std::shared_ptr<GeomAPI_Dir> aDirY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
1094 typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
1095 std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
1096 std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
1097 PointToRefsMap aPointsInfo;
1099 ModelGeomAlgo_Point2D::getPointsInsideShape(anAttrShape, aRefAttributes, aC->pnt(),
1100 aX->dir(), aDirY, aPointsInfo);
1101 int aCoincidentToFeature = (int)aPointsInfo.size();
1102 if (anAttrFeature->getKind() == SketchPlugin_Circle::ID() ||
1103 anAttrFeature->getKind() == SketchPlugin_Ellipse::ID())
1104 aValid = aCoincidentToFeature >= 2;
1106 aValid = aCoincidentToFeature >= 1;
1111 bool SketchPlugin_TrimValidator::isValid(const AttributePtr& theAttribute,
1112 const std::list<std::string>& theArguments,
1113 Events_InfoMessage& theError) const
1115 bool aValid = false;
1117 if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
1118 theError = "The attribute with the %1 type is not processed";
1119 theError.arg(theAttribute->attributeType());
1122 AttributeReferencePtr aBaseObjectAttr =
1123 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
1125 std::shared_ptr<SketchPlugin_Feature> aTrimFeature =
1126 std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
1128 ObjectPtr aBaseObject = aBaseObjectAttr->value();
1130 AttributePtr aPreviewAttr = aTrimFeature->attribute(SketchPlugin_Trim::PREVIEW_OBJECT());
1131 aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(aPreviewAttr);
1132 aBaseObject = aBaseObjectAttr->value();
1135 FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObject);
1139 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1140 std::dynamic_pointer_cast<SketchPlugin_Feature>(aBaseFeature);
1141 if (!aSketchFeature.get() || aSketchFeature->isCopy())
1144 // B-splines are not supported by the Trim yet
1145 if (aBaseFeature->getKind() == SketchPlugin_BSpline::ID() ||
1146 aBaseFeature->getKind() == SketchPlugin_BSplinePeriodic::ID()) {
1147 theError = "Not supported";
1152 AttributePoint2DPtr aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1153 aTrimFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT()));
1155 SketchPlugin_Sketch* aSketch = aTrimFeature->sketch();
1157 std::shared_ptr<GeomAPI_Pnt2d> anAttributePnt2d = aPoint->pnt();
1158 std::shared_ptr<GeomAPI_Pnt> anAttributePnt = aSketch->to3D(anAttributePnt2d->x(),
1159 anAttributePnt2d->y());
1161 std::map<ObjectPtr, std::set<GeomShapePtr> > aCashedShapes;
1162 std::map<ObjectPtr, std::map<std::shared_ptr<GeomAPI_Pnt>,
1163 std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
1164 std::list<std::shared_ptr<ModelAPI_Object> > > > > anObjectToPoints;
1165 SketchPlugin_SegmentationTools::fillObjectShapes(
1166 aTrimFeature.get(), aBaseObject, aCashedShapes, anObjectToPoints);
1167 const std::set<GeomShapePtr>& aShapes = aCashedShapes[aBaseObject];
1169 return aShapes.size() > 1;
1172 bool SketchPlugin_ProjectionValidator::isValid(const AttributePtr& theAttribute,
1173 const std::list<std::string>& theArguments,
1174 Events_InfoMessage& theError) const
1176 if (theAttribute->attributeType() != ModelAPI_AttributeSelection::typeId()) {
1177 theError = "The attribute with the %1 type is not processed";
1178 theError.arg(theAttribute->attributeType());
1182 AttributeSelectionPtr aFeatureAttr =
1183 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
1184 std::shared_ptr<GeomAPI_Edge> anEdge;
1185 std::shared_ptr<SketchPlugin_Feature> aSketchFeature;
1186 if (aFeatureAttr.get()) {
1187 GeomShapePtr aVal = aFeatureAttr->value();
1188 ResultPtr aRes = aFeatureAttr->context();
1189 if (aVal && aVal->isVertex())
1190 return true; // vertex is always could be projected
1191 if (aVal && aVal->isEdge()) {
1192 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aFeatureAttr->value()));
1193 } else if(aRes && aRes->shape()) {
1194 if (aRes->shape()->isVertex())
1195 return true; // vertex is always could be projected
1196 else if (aRes->shape()->isEdge())
1197 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aFeatureAttr->context()->shape()));
1200 // try to convert result to sketch feature
1203 std::dynamic_pointer_cast<SketchPlugin_Feature>(ModelAPI_Feature::feature(aRes));
1207 theError = "The attribute %1 should be an edge or vertex";
1208 theError.arg(theAttribute->id());
1213 std::shared_ptr<SketchPlugin_Sketch> aSketch;
1214 std::set<AttributePtr> aRefs = theAttribute->owner()->data()->refsToMe();
1215 std::set<AttributePtr>::const_iterator anIt = aRefs.begin();
1216 for (; anIt != aRefs.end(); ++anIt) {
1217 CompositeFeaturePtr aComp =
1218 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>((*anIt)->owner());
1219 if (aComp && aComp->getKind() == SketchPlugin_Sketch::ID()) {
1220 aSketch = std::dynamic_pointer_cast<SketchPlugin_Sketch>(aComp);
1225 theError = "There is no sketch referring to the current feature";
1228 if (aSketchFeature && aSketch.get() == aSketchFeature->sketch()) {
1229 theError = "Unable to project feature from the same sketch";
1233 std::shared_ptr<GeomAPI_Pln> aPlane = aSketch->plane();
1234 std::shared_ptr<GeomAPI_Dir> aNormal = aPlane->direction();
1235 std::shared_ptr<GeomAPI_Pnt> anOrigin = aPlane->location();
1238 if (anEdge->isLine()) {
1239 std::shared_ptr<GeomAPI_Lin> aLine = anEdge->line();
1240 std::shared_ptr<GeomAPI_Dir> aLineDir = aLine->direction();
1241 double aDot = fabs(aNormal->dot(aLineDir));
1242 aValid = fabs(aDot - 1.0) >= tolerance * tolerance;
1244 theError = "Error: Line is orthogonal to the sketch plane.";
1246 else if (anEdge->isCircle() || anEdge->isArc()) {
1247 std::shared_ptr<GeomAPI_Circ> aCircle = anEdge->circle();
1248 std::shared_ptr<GeomAPI_Dir> aCircNormal = aCircle->normal();
1249 double aDot = fabs(aNormal->dot(aCircNormal));
1250 aValid = aDot >= tolerance * tolerance;
1252 theError.arg(anEdge->isCircle() ? "Error: Circle is orthogonal to the sketch plane."
1253 : "Error: Arc is orthogonal to the sketch plane.");
1255 else if (anEdge->isEllipse()) {
1256 std::shared_ptr<GeomAPI_Ellipse> anEllipse = anEdge->ellipse();
1257 std::shared_ptr<GeomAPI_Dir> anEllipseNormal = anEllipse->normal();
1258 double aDot = fabs(aNormal->dot(anEllipseNormal));
1259 aValid = fabs(aDot - 1.0) <= tolerance * tolerance;
1261 theError.arg(anEdge->isClosed() ? "Error: Ellipse is orthogonal to the sketch plane."
1262 : "Error: Elliptic Arc is orthogonal to the sketch plane.");
1269 static std::set<FeaturePtr> common(const std::set<FeaturePtr>& theSet1,
1270 const std::set<FeaturePtr>& theSet2)
1272 std::set<FeaturePtr> aCommon;
1273 if (theSet1.empty() || theSet2.empty())
1276 std::set<FeaturePtr>::const_iterator anIt2 = theSet2.begin();
1277 for (; anIt2 != theSet2.end(); ++anIt2)
1278 if (theSet1.find(*anIt2) != theSet1.end())
1279 aCommon.insert(*anIt2);
1283 bool SketchPlugin_DifferentReferenceValidator::isValid(
1284 const AttributePtr& theAttribute,
1285 const std::list<std::string>& theArguments,
1286 Events_InfoMessage& theError) const
1288 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
1290 int aNbFeaturesReferred = 0;
1291 int aNbAttributesReferred = 0;
1292 std::set<FeaturePtr> aCommonReferredFeatures;
1294 // find all features referred by attributes listed in theArguments
1295 std::list<std::string>::const_iterator anArgIt = theArguments.begin();
1296 for (; anArgIt != theArguments.end(); ++anArgIt) {
1297 AttributeRefAttrPtr aRefAttr = anOwner->refattr(*anArgIt);
1301 std::set<FeaturePtr> aCoincidentFeatures;
1302 if (aRefAttr->isObject()) {
1303 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
1305 aCoincidentFeatures.insert(aFeature);
1306 aNbFeaturesReferred += 1;
1309 AttributePoint2DPtr aPoint =
1310 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aRefAttr->attr());
1312 aCoincidentFeatures = SketchPlugin_Tools::findFeaturesCoincidentToPoint(aPoint);
1313 aNbAttributesReferred += 1;
1317 if (aCommonReferredFeatures.empty())
1318 aCommonReferredFeatures = aCoincidentFeatures;
1320 aCommonReferredFeatures = common(aCommonReferredFeatures, aCoincidentFeatures);
1322 if (aCommonReferredFeatures.empty())
1326 bool isOk = aNbFeaturesReferred < 1;
1327 if (aNbFeaturesReferred == 1) {
1328 if (aCommonReferredFeatures.size() == 1) {
1329 FeaturePtr aFeature = *aCommonReferredFeatures.begin();
1330 isOk = aNbAttributesReferred <= 1 ||
1331 aFeature->getKind() == SketchPlugin_Circle::ID() ||
1332 aFeature->getKind() == SketchPlugin_Arc::ID();
1338 theError = "Attributes are referred to the same feature";
1342 bool SketchPlugin_DifferentPointReferenceValidator::isValid(
1343 const AttributePtr& theAttribute,
1344 const std::list<std::string>& theArguments,
1345 Events_InfoMessage& theError) const
1347 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
1348 std::set<AttributePoint2DPtr> aReferredCoincidentPoints;
1350 // find all points referred by attributes listed in theArguments
1351 bool hasRefsToPoints = false;
1352 std::list<std::string>::const_iterator anArgIt = theArguments.begin();
1353 for (; anArgIt != theArguments.end(); ++anArgIt) {
1354 AttributeRefAttrPtr aRefAttr = anOwner->refattr(*anArgIt);
1358 if (!aRefAttr->isObject()) {
1359 AttributePoint2DPtr aPoint =
1360 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aRefAttr->attr());
1361 if (aReferredCoincidentPoints.empty())
1362 aReferredCoincidentPoints = SketchPlugin_Tools::findPointsCoincidentToPoint(aPoint);
1363 else if (aReferredCoincidentPoints.find(aPoint) == aReferredCoincidentPoints.end())
1364 return true; // non-coincident point has been found
1366 hasRefsToPoints = true;
1370 if (hasRefsToPoints)
1371 theError = "Attributes are referred to the same point";
1372 return !hasRefsToPoints;
1375 bool SketchPlugin_CirclePassedPointValidator::isValid(
1376 const AttributePtr& theAttribute,
1377 const std::list<std::string>&,
1378 Events_InfoMessage& theError) const
1380 static const std::string aErrorMessage(
1381 "Passed point refers to the same feature as a center point");
1383 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
1385 AttributeRefAttrPtr aCenterRef =
1386 anOwner->refattr(SketchPlugin_MacroCircle::CENTER_POINT_REF_ID());
1387 AttributeRefAttrPtr aPassedRef =
1388 anOwner->refattr(SketchPlugin_MacroCircle::PASSED_POINT_REF_ID());
1390 if (!aPassedRef->isObject())
1393 FeaturePtr aPassedFeature = ModelAPI_Feature::feature(aPassedRef->object());
1394 if (!aPassedFeature)
1397 if (aCenterRef->isObject()) {
1398 if (aCenterRef->object() == aPassedRef->object()) {
1399 theError = aErrorMessage;
1403 AttributePoint2DPtr aCenterPoint =
1404 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aCenterRef->attr());
1406 std::set<FeaturePtr> aCoincidentFeatures =
1407 SketchPlugin_Tools::findFeaturesCoincidentToPoint(aCenterPoint);
1408 // check one of coincident features is a feature referred by passed point
1409 std::set<FeaturePtr>::const_iterator anIt = aCoincidentFeatures.begin();
1410 for(; anIt != aCoincidentFeatures.end(); ++anIt)
1411 if (*anIt == aPassedFeature) {
1412 theError = aErrorMessage;
1420 bool SketchPlugin_ThirdPointValidator::isValid(
1421 const AttributePtr& theAttribute,
1422 const std::list<std::string>& theArguments,
1423 Events_InfoMessage& theError) const
1425 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
1426 return arePointsNotOnLine(anOwner, theError) &&
1427 arePointsNotSeparated(anOwner, theArguments, theError);
1430 static std::shared_ptr<GeomAPI_Pnt2d> toPoint(const FeaturePtr& theMacroCircle,
1431 const std::string& thePointAttrName,
1432 const std::string& theRefPointAttrName)
1434 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1435 theMacroCircle->attribute(thePointAttrName));
1436 AttributeRefAttrPtr aRefAttr = theMacroCircle->refattr(theRefPointAttrName);
1438 std::shared_ptr<GeomAPI_Pnt2d> aPoint = aPointAttr->pnt();
1440 if (aRefAttr->isObject()) {
1441 // project a point onto selected feature
1442 std::shared_ptr<SketchPlugin_Feature> aFeature =
1443 std::dynamic_pointer_cast<SketchPlugin_Feature>(
1444 ModelAPI_Feature::feature(aRefAttr->object()));
1446 SketchPlugin_Sketch* aSketch = aFeature->sketch();
1447 std::shared_ptr<GeomAPI_Edge> anEdge =
1448 std::dynamic_pointer_cast<GeomAPI_Edge>(aFeature->lastResult()->shape());
1450 std::shared_ptr<GeomAPI_Pnt> aPoint3D = aSketch->to3D(aPoint->x(), aPoint->y());
1451 if (anEdge->isLine())
1452 aPoint3D = anEdge->line()->project(aPoint3D);
1453 else if (anEdge->isCircle())
1454 aPoint3D = anEdge->circle()->project(aPoint3D);
1456 aPoint = aSketch->to2D(aPoint3D);
1460 AttributePoint2DPtr anOtherPoint =
1461 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aRefAttr->attr());
1463 aPoint = anOtherPoint->pnt(); // the reference point is much more precise, use it
1470 static void threePointsOfFeature(const FeaturePtr& theMacroFeature,
1471 std::shared_ptr<GeomAPI_Pnt2d> thePoints[3])
1473 if (theMacroFeature->getKind() == SketchPlugin_MacroCircle::ID()) {
1474 thePoints[0] = toPoint(theMacroFeature,
1475 SketchPlugin_MacroCircle::FIRST_POINT_ID(),
1476 SketchPlugin_MacroCircle::FIRST_POINT_REF_ID());
1477 thePoints[1] = toPoint(theMacroFeature,
1478 SketchPlugin_MacroCircle::SECOND_POINT_ID(),
1479 SketchPlugin_MacroCircle::SECOND_POINT_REF_ID());
1480 thePoints[2] = toPoint(theMacroFeature,
1481 SketchPlugin_MacroCircle::THIRD_POINT_ID(),
1482 SketchPlugin_MacroCircle::THIRD_POINT_REF_ID());
1483 } else if (theMacroFeature->getKind() == SketchPlugin_MacroArc::ID()) {
1484 thePoints[0] = toPoint(theMacroFeature,
1485 SketchPlugin_MacroArc::START_POINT_2_ID(),
1486 SketchPlugin_MacroArc::START_POINT_REF_ID());
1487 thePoints[1] = toPoint(theMacroFeature,
1488 SketchPlugin_MacroArc::END_POINT_2_ID(),
1489 SketchPlugin_MacroArc::END_POINT_REF_ID());
1490 thePoints[2] = toPoint(theMacroFeature,
1491 SketchPlugin_MacroArc::PASSED_POINT_ID(),
1492 SketchPlugin_MacroArc::PASSED_POINT_REF_ID());
1496 static bool isPointsOnLine(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
1497 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
1498 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
1500 static const double aTolerance = 1.e-7;
1501 if (thePoint1->distance(thePoint2) < aTolerance ||
1502 thePoint1->distance(thePoint3) < aTolerance)
1505 std::shared_ptr<GeomAPI_Dir2d> aDirP1P2(new GeomAPI_Dir2d(thePoint2->x() - thePoint1->x(),
1506 thePoint2->y() - thePoint1->y()));
1507 std::shared_ptr<GeomAPI_Dir2d> aDirP1P3(new GeomAPI_Dir2d(thePoint3->x() - thePoint1->x(),
1508 thePoint3->y() - thePoint1->y()));
1509 return fabs(aDirP1P2->cross(aDirP1P3)) < aTolerance;
1512 static bool isOnSameSide(const std::shared_ptr<GeomAPI_Lin>& theLine,
1513 const std::shared_ptr<GeomAPI_Pnt>& thePoint1,
1514 const std::shared_ptr<GeomAPI_Pnt>& thePoint2)
1516 static const double aTolerance = 1.e-7;
1517 std::shared_ptr<GeomAPI_Dir> aLineDir = theLine->direction();
1518 std::shared_ptr<GeomAPI_XYZ> aLineLoc = theLine->location()->xyz();
1520 std::shared_ptr<GeomAPI_XYZ> aVec1 = thePoint1->xyz()->decreased(aLineLoc);
1521 // the first point is on the line
1522 if (aVec1->squareModulus() < aTolerance * aTolerance)
1524 std::shared_ptr<GeomAPI_Dir> aDirP1L(new GeomAPI_Dir(aVec1));
1525 std::shared_ptr<GeomAPI_XYZ> aVec2 = thePoint2->xyz()->decreased(aLineLoc);
1526 // the second point is on the line
1527 if (aVec2->squareModulus() < aTolerance * aTolerance)
1529 std::shared_ptr<GeomAPI_Dir> aDirP2L(new GeomAPI_Dir(aVec2));
1531 return aLineDir->cross(aDirP1L)->dot(aLineDir->cross(aDirP2L)) > -aTolerance;
1534 static bool isOnSameSide(const std::shared_ptr<GeomAPI_Circ>& theCircle,
1535 const std::shared_ptr<GeomAPI_Pnt>& thePoint1,
1536 const std::shared_ptr<GeomAPI_Pnt>& thePoint2)
1538 static const double aTolerance = 1.e-7;
1539 std::shared_ptr<GeomAPI_Pnt> aCenter = theCircle->center();
1540 double aDistP1C = thePoint1->distance(aCenter);
1541 double aDistP2C = thePoint2->distance(aCenter);
1542 return (aDistP1C - theCircle->radius()) * (aDistP2C - theCircle->radius()) > -aTolerance;
1545 bool SketchPlugin_ThirdPointValidator::arePointsNotOnLine(
1546 const FeaturePtr& theMacroFeature,
1547 Events_InfoMessage& theError) const
1549 static const std::string aErrorPointsOnLine(
1550 "Selected points are on the same line");
1552 std::shared_ptr<GeomAPI_Pnt2d> aPoints[3];
1553 threePointsOfFeature(theMacroFeature, aPoints);
1555 if (isPointsOnLine(aPoints[0], aPoints[1], aPoints[2])) {
1556 theError = aErrorPointsOnLine;
1562 bool SketchPlugin_ThirdPointValidator::arePointsNotSeparated(
1563 const FeaturePtr& theMacroFeature,
1564 const std::list<std::string>& theArguments,
1565 Events_InfoMessage& theError) const
1567 static const std::string aErrorPointsApart(
1568 "Selected entity is lying between first two points");
1570 AttributeRefAttrPtr aThirdPointRef = theMacroFeature->refattr(theArguments.front());
1571 FeaturePtr aRefByThird;
1572 if (aThirdPointRef->isObject())
1573 aRefByThird = ModelAPI_Feature::feature(aThirdPointRef->object());
1577 std::shared_ptr<GeomAPI_Pnt2d> aPoints[3];
1578 threePointsOfFeature(theMacroFeature, aPoints);
1580 std::shared_ptr<GeomAPI_Edge> aThirdShape =
1581 std::dynamic_pointer_cast<GeomAPI_Edge>(aRefByThird->lastResult()->shape());
1585 SketchPlugin_Sketch* aSketch =
1586 std::dynamic_pointer_cast<SketchPlugin_Feature>(theMacroFeature)->sketch();
1587 std::shared_ptr<GeomAPI_Pnt> aFirstPnt3D = aSketch->to3D(aPoints[0]->x(), aPoints[0]->y());
1588 std::shared_ptr<GeomAPI_Pnt> aSecondPnt3D = aSketch->to3D(aPoints[1]->x(), aPoints[1]->y());
1591 if (aThirdShape->isLine())
1592 isOk = isOnSameSide(aThirdShape->line(), aFirstPnt3D, aSecondPnt3D);
1593 else if (aThirdShape->isCircle() || aThirdShape->isArc())
1594 isOk = isOnSameSide(aThirdShape->circle(), aFirstPnt3D, aSecondPnt3D);
1597 theError = aErrorPointsApart;
1601 bool SketchPlugin_ArcEndPointValidator::isValid(
1602 const AttributePtr& theAttribute,
1603 const std::list<std::string>& theArguments,
1604 Events_InfoMessage& theError) const
1606 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
1607 AttributeRefAttrPtr anEndPointRef = aFeature->refattr(theArguments.front());
1609 if(!anEndPointRef.get()) {
1613 ObjectPtr anObject = anEndPointRef->object();
1614 AttributePtr anAttr = anEndPointRef->attr();
1615 if(!anObject.get() && !anAttr.get()) {
1619 if(anEndPointRef->attr().get()) {
1623 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1625 GeomShapePtr aShape = aResult->shape();
1626 if(aShape.get() && aShape->isVertex()) {
1631 aFeature = ModelAPI_Feature::feature(anObject);
1632 if(aFeature.get()) {
1633 if(aFeature->getKind() == SketchPlugin_Point::ID()) {
1641 static GeomShapePtr toInfiniteEdge(const GeomShapePtr theShape)
1643 if(!theShape.get()) {
1647 if(!theShape->isEdge()) {
1651 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
1657 if(anEdge->isLine()) {
1658 std::shared_ptr<GeomAPI_Lin> aLine = anEdge->line();
1659 GeomShapePtr aShape = GeomAlgoAPI_EdgeBuilder::line(aLine);
1663 if(anEdge->isCircle() || anEdge->isArc()) {
1664 std::shared_ptr<GeomAPI_Circ> aCircle = anEdge->circle();
1665 GeomShapePtr aShape = GeomAlgoAPI_EdgeBuilder::lineCircle(aCircle);
1672 bool SketchPlugin_ArcEndPointIntersectionValidator::isValid(
1673 const AttributePtr& theAttribute,
1674 const std::list<std::string>& theArguments,
1675 Events_InfoMessage& theError) const
1677 std::shared_ptr<SketchPlugin_MacroArc> anArcFeature =
1678 std::dynamic_pointer_cast<SketchPlugin_MacroArc>(theAttribute->owner());
1679 AttributeRefAttrPtr anEndPointRef = anArcFeature->refattr(theArguments.front());
1681 if(!anEndPointRef.get()) {
1685 GeomShapePtr anArcShape = toInfiniteEdge(anArcFeature->getArcShape(false));
1687 if(!anArcShape.get() || anArcShape->isNull()) {
1691 ObjectPtr anObject = anEndPointRef->object();
1692 AttributePtr anAttr = anEndPointRef->attr();
1693 if(!anObject.get() && !anAttr.get()) {
1697 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1699 GeomShapePtr aShape = aResult->shape();
1700 if (!aShape->isEdge())
1702 aShape = toInfiniteEdge(aShape);
1703 if(aShape.get() && !aShape->isNull()) {
1704 if(anArcShape->isIntersect(aShape)) {
1710 FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(anObject);
1711 if(aSelectedFeature.get()) {
1712 std::list<ResultPtr> aResults = aSelectedFeature->results();
1713 for(std::list<ResultPtr>::const_iterator anIt = aResults.cbegin();
1714 anIt != aResults.cend();
1717 GeomShapePtr aShape = (*anIt)->shape();
1718 if (!aShape->isEdge())
1720 aShape = toInfiniteEdge(aShape);
1721 if(aShape.get() && !aShape->isNull()) {
1722 if(anArcShape->isIntersect(aShape)) {
1732 bool SketchPlugin_HasNoConstraint::isValid(const AttributePtr& theAttribute,
1733 const std::list<std::string>& theArguments,
1734 Events_InfoMessage& theError) const
1736 std::set<std::string> aFeatureKinds;
1737 for (std::list<std::string>::const_iterator anArgIt = theArguments.begin();
1738 anArgIt != theArguments.end(); anArgIt++) {
1739 aFeatureKinds.insert(*anArgIt);
1742 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
1743 theError = "The attribute with the %1 type is not processed";
1744 theError.arg(theAttribute->attributeType());
1748 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
1750 bool isObject = aRefAttr->isObject();
1752 theError = "It uses an empty object";
1755 ObjectPtr anObject = aRefAttr->object();
1756 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1757 if (!aFeature.get()) {
1758 theError = "The feature of the checked attribute is empty";
1762 FeaturePtr aCurrentFeature = ModelAPI_Feature::feature(aRefAttr->owner());
1764 std::set<AttributePtr> aRefsList = anObject->data()->refsToMe();
1765 std::set<AttributePtr>::const_iterator anIt = aRefsList.begin();
1766 for (; anIt != aRefsList.end(); anIt++) {
1767 FeaturePtr aRefFeature = ModelAPI_Feature::feature((*anIt)->owner());
1768 if (aRefFeature.get() && aCurrentFeature != aRefFeature &&
1769 aFeatureKinds.find(aRefFeature->getKind()) != aFeatureKinds.end())
1770 return false; // constraint is found, that means that the check is not valid
1775 bool SketchPlugin_ReplicationReferenceValidator::isValid(
1776 const AttributePtr& theAttribute,
1777 const std::list<std::string>& theArguments,
1778 Events_InfoMessage& theError) const
1780 AttributeRefAttrPtr aRefAttr =
1781 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
1784 theError = "Incorrect attribute";
1789 if (aRefAttr->isObject())
1790 anOwner = aRefAttr->object();
1793 AttributePtr anAttr = aRefAttr->attr();
1794 anOwner = anAttr->owner();
1796 FeaturePtr anAttrOwnerFeature = ModelAPI_Feature::feature(anOwner);
1797 if (!anAttrOwnerFeature)
1799 AttributeBooleanPtr aCopyAttr = anAttrOwnerFeature->boolean(SketchPlugin_SketchEntity::COPY_ID());
1800 if (!aCopyAttr || !aCopyAttr->value())
1801 return true; // feature is not a copy, thus valid
1803 // check the copy feature is already referred by the "Multi" feature
1804 FeaturePtr aMultiFeature = ModelAPI_Feature::feature(theAttribute->owner());
1805 AttributeRefListPtr aRefList = aMultiFeature->reflist(theArguments.front());
1806 for (int i = 0; i < aRefList->size(); ++i)
1808 FeaturePtr aRefOwner = ModelAPI_Feature::feature(aRefList->object(i));
1809 if (aRefOwner == anAttrOwnerFeature)
1811 theError = "Attribute refers to the object generated by this feature";
1819 bool SketchPlugin_SketchFeatureValidator::isValid(const AttributePtr& theAttribute,
1820 const std::list<std::string>& theArguments,
1821 Events_InfoMessage& theError) const
1823 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId() &&
1824 theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
1825 theError = "The attribute with the %1 type is not processed";
1826 theError.arg(theAttribute->attributeType());
1830 // check the attribute refers to a sketch feature
1831 bool isSketchFeature = false;
1832 AttributeRefAttrPtr aRefAttr =
1833 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
1835 isSketchFeature = aRefAttr->isObject();
1836 if (isSketchFeature) {
1837 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
1838 isSketchFeature = aFeature.get() != NULL;
1839 if (isSketchFeature) {
1840 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1841 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1842 isSketchFeature = aSketchFeature.get() != NULL;
1847 AttributeReferencePtr aReference =
1848 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
1850 FeaturePtr aFeature = ModelAPI_Feature::feature(aReference->value());
1851 isSketchFeature = aFeature.get() && aFeature->getKind() == SketchPlugin_Sketch::ID();
1855 if (!isSketchFeature)
1856 theError = "The object selected is not a sketch feature";
1857 return isSketchFeature;
1860 bool SketchPlugin_MultiRotationAngleValidator::isValid(const AttributePtr& theAttribute,
1861 const std::list<std::string>& theArguments,
1862 Events_InfoMessage& theError) const
1864 if (theAttribute->attributeType() != ModelAPI_AttributeDouble::typeId()) {
1865 theError = "The attribute with the %1 type is not processed";
1866 theError.arg(theAttribute->attributeType());
1870 AttributeDoublePtr anAngleAttr =
1871 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
1873 FeaturePtr aMultiRotation = ModelAPI_Feature::feature(theAttribute->owner());
1874 AttributeStringPtr anAngleType =
1875 aMultiRotation->string(SketchPlugin_MultiRotation::ANGLE_TYPE());
1876 AttributeIntegerPtr aNbCopies =
1877 aMultiRotation->integer(SketchPlugin_MultiRotation::NUMBER_OF_OBJECTS_ID());
1879 if (anAngleType->value() != "FullAngle")
1881 double aFullAngleValue = anAngleAttr->value() * (aNbCopies->value() - 1);
1882 if (aFullAngleValue < -1.e-7 || aFullAngleValue > 359.9999999)
1884 theError = "Rotation single angle should produce full angle less than 360 degree";
1890 double aFullAngleValue = anAngleAttr->value();
1891 if (aFullAngleValue < -1.e-7 || aFullAngleValue > 360.0000001)
1893 theError = "Rotation full angle should be in range [0, 360]";
1901 bool SketchPlugin_BSplineValidator::isValid(const AttributePtr& theAttribute,
1902 const std::list<std::string>& theArguments,
1903 Events_InfoMessage& theError) const
1905 AttributePoint2DArrayPtr aPolesArray =
1906 std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(theAttribute);
1910 if (aPolesArray->size() < 2) {
1911 theError = "Number of B-spline poles should be 2 or more";
1918 bool SketchPlugin_CurveFittingValidator::isValid(const FeaturePtr& theFeature,
1919 const std::list<std::string>& theArguments,
1920 Events_InfoMessage& theError) const
1922 AttributeRefAttrListPtr aRefAttrList =
1923 theFeature->refattrlist(SketchPlugin_CurveFitting::POINTS_ID());
1924 AttributeBooleanPtr aPeriodicAttr =
1925 theFeature->boolean(SketchPlugin_CurveFitting::PERIODIC_ID());
1927 // check number of selected entities
1928 int aMinNbPoints = aPeriodicAttr->value() ? 3 : 2;
1929 if (aRefAttrList->size() < aMinNbPoints) {
1930 theError = "Not enough points selected. Need at least %1 points.";
1931 theError.arg(aMinNbPoints);