1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "PartSet_Validators.h"
23 #include "PartSet_Tools.h"
24 #include "PartSet_SketcherMgr.h"
27 #include <TopoDS_Edge.hxx>
28 #include <BRep_Tool.hxx>
29 #include <GeomAdaptor_Curve.hxx>
30 #include <GeomAbs_CurveType.hxx>
31 #include <ModuleBase_ISelection.h>
32 #include <ModuleBase_WidgetShapeSelector.h>
33 #include <ModuleBase_OperationFeature.h>
34 #include <ModuleBase_ViewerPrs.h>
36 #include <GeomDataAPI_Point2D.h>
37 #include <GeomAPI_Pnt2d.h>
39 #include <Events_InfoMessage.h>
41 #include <ModelAPI_AttributeRefAttr.h>
42 #include <ModelAPI_AttributeSelection.h>
43 #include <ModelAPI_AttributeReference.h>
44 #include <ModelAPI_AttributeSelectionList.h>
45 #include <ModelAPI_AttributeRefList.h>
46 #include <ModelAPI_Object.h>
47 #include <ModelAPI_ResultBody.h>
48 #include <ModelAPI_Session.h>
49 #include <ModelAPI_Tools.h>
51 #include <SketchPlugin_Sketch.h>
52 #include <SketchPlugin_ConstraintCoincidence.h>
53 #include <SketchPlugin_Arc.h>
54 #include <SketchPlugin_Point.h>
55 #include <GeomAPI_Edge.h>
62 int shapesNbPoints(const ModuleBase_ISelection* theSelection)
64 QList<ModuleBase_ViewerPrsPtr> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
65 ModuleBase_ISelection::filterSelectionOnEqualPoints(aList);
68 foreach (ModuleBase_ViewerPrsPtr aPrs, aList) {
69 const GeomShapePtr& aShape = aPrs->shape();
70 if (aShape.get() && !aShape->isNull()) {
71 if (aShape->shapeType() == GeomAPI_Shape::VERTEX)
78 int shapesNbLines(const ModuleBase_ISelection* theSelection)
80 QList<ModuleBase_ViewerPrsPtr> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
82 foreach(ModuleBase_ViewerPrsPtr aPrs, aList) {
83 const GeomShapePtr& aShape = aPrs->shape();
84 if (aShape.get() && !aShape->isNull()) {
85 if (aShape->shapeType() == GeomAPI_Shape::EDGE) {
86 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
87 TopoDS_Edge aEdge = TopoDS::Edge(aTDShape);
88 Standard_Real aStart, aEnd;
89 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
90 GeomAdaptor_Curve aAdaptor(aCurve);
91 if (aAdaptor.GetType() == GeomAbs_Line)
100 std::shared_ptr<GeomAPI_Pln> sketcherPlane(ModuleBase_Operation* theOperation)
102 std::shared_ptr<GeomAPI_Pln> aEmptyPln;
104 ModuleBase_OperationFeature* aFeatureOp =
105 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
107 CompositeFeaturePtr aFeature =
108 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeatureOp->feature());
109 if (aFeature && (aFeature->getKind() == SketchPlugin_Sketch::ID()))
110 return PartSet_Tools::sketchPlane(aFeature);
117 bool isEmptySelectionValid(ModuleBase_Operation* theOperation)
119 ModuleBase_OperationFeature* aFeatureOp =
120 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
121 // during the create operation empty selection is always valid
122 if (!aFeatureOp->isEditOperation()) {
126 if (PartSet_SketcherMgr::isSketchOperation(aFeatureOp)) {
127 std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
134 // in edit operation an empty selection is always valid, performed for re-entrant operrations
139 bool PartSet_DistanceSelection::isValid(const ModuleBase_ISelection* theSelection,
140 ModuleBase_Operation* theOperation) const
142 if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
143 return isEmptySelectionValid(theOperation);
145 int aCount = shapesNbPoints(theSelection) + shapesNbLines(theSelection);
146 return (aCount > 0) && (aCount < 3);
150 bool PartSet_LengthSelection::isValid(const ModuleBase_ISelection* theSelection,
151 ModuleBase_Operation* theOperation) const
153 if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
154 return isEmptySelectionValid(theOperation);
156 int aCount = shapesNbLines(theSelection);
157 return (aCount == 1);
161 bool PartSet_PerpendicularSelection::isValid(const ModuleBase_ISelection* theSelection,
162 ModuleBase_Operation* theOperation) const
164 if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
165 return isEmptySelectionValid(theOperation);
167 int aCount = shapesNbLines(theSelection);
168 return (aCount > 0) && (aCount < 3);
172 bool PartSet_ParallelSelection::isValid(const ModuleBase_ISelection* theSelection,
173 ModuleBase_Operation* theOperation) const
175 if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
176 return isEmptySelectionValid(theOperation);
178 int aCount = shapesNbLines(theSelection);
179 return (aCount > 0) && (aCount < 3);
183 bool PartSet_RadiusSelection::isValid(const ModuleBase_ISelection* theSelection,
184 ModuleBase_Operation* theOperation) const
186 if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
187 return isEmptySelectionValid(theOperation);
189 QList<ModuleBase_ViewerPrsPtr> aList =
190 theSelection->getSelected(ModuleBase_ISelection::Viewer);
192 foreach (ModuleBase_ViewerPrsPtr aPrs, aList) {
193 const GeomShapePtr& aShape = aPrs->shape();
194 if (aShape.get() && !aShape->isNull()) {
195 if (aShape->shapeType() == GeomAPI_Shape::EDGE) {
196 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
197 TopoDS_Edge aEdge = TopoDS::Edge(aTDShape);
198 Standard_Real aStart, aEnd;
199 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
200 GeomAdaptor_Curve aAdaptor(aCurve);
201 if (aAdaptor.GetType() == GeomAbs_Circle)
206 return (aCount == 1);
210 bool PartSet_RigidSelection::isValid(const ModuleBase_ISelection* theSelection,
211 ModuleBase_Operation* theOperation) const
213 if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
214 return isEmptySelectionValid(theOperation);
216 QList<ModuleBase_ViewerPrsPtr> aList =
217 theSelection->getSelected(ModuleBase_ISelection::Viewer);
219 foreach (ModuleBase_ViewerPrsPtr aPrs, aList) {
220 ObjectPtr aObj = aPrs->object();
222 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
223 if (aFeature.get()) {
224 CompositeFeaturePtr aComp = ModelAPI_Tools::compositeOwner(aFeature);
225 if (aComp.get() && (aComp->getKind() == SketchPlugin_Sketch::ID()))
230 return (aCount == 1);
235 bool PartSet_CoincidentSelection::isValid(const ModuleBase_ISelection* theSelection,
236 ModuleBase_Operation* theOperation) const
238 if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
239 return isEmptySelectionValid(theOperation);
241 // Coincident can be applied to points and to lines
242 int aCount = shapesNbPoints(theSelection);
243 aCount += shapesNbLines(theSelection);
244 return (aCount > 0) && (aCount < 3);
248 bool PartSet_HVDirSelection::isValid(const ModuleBase_ISelection* theSelection,
249 ModuleBase_Operation* theOperation) const
251 if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
252 return isEmptySelectionValid(theOperation);
254 int aCount = shapesNbLines(theSelection);
255 return (aCount == 1);
259 bool PartSet_FilletSelection::isValid(const ModuleBase_ISelection* theSelection,
260 ModuleBase_Operation* theOperation) const
262 if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
263 return isEmptySelectionValid(theOperation);
265 int aCount = shapesNbPoints(theSelection);
270 bool PartSet_TangentSelection::isValid(const ModuleBase_ISelection* theSelection,
271 ModuleBase_Operation* theOperation) const
273 if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
274 return isEmptySelectionValid(theOperation);
276 QList<ModuleBase_ViewerPrsPtr> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
277 if ((aList.size() == 0) || (aList.size() > 2))
280 ModuleBase_ViewerPrsPtr aPrs = aList.first();
281 const GeomShapePtr& aShape = aPrs->shape();
282 if (!aShape.get() || aShape->isNull() || aShape->shapeType() != GeomAPI_Shape::EDGE)
284 GeomAPI_Edge aEdge1(aShape);
286 if (aEdge1.isLine() || aEdge1.isArc()) {
287 if (aList.size() == 2) {
288 // Check second selection
290 const GeomShapePtr& aShape2 = aPrs->shape();
291 if (!aShape2.get() || aShape2->isNull() || aShape2->shapeType() != GeomAPI_Shape::EDGE)
293 GeomAPI_Edge aEdge2(aShape2);
295 if (aEdge1.isLine() && aEdge2.isArc())
297 else if (aEdge1.isArc() && aEdge2.isLine())
308 bool PartSet_AngleSelection::isValid(const ModuleBase_ISelection* theSelection,
309 ModuleBase_Operation* theOperation) const
311 if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
312 return isEmptySelectionValid(theOperation);
314 int aCount = shapesNbLines(theSelection);
315 return (aCount > 0) && (aCount < 3);
319 bool PartSet_EqualSelection::isValid(const ModuleBase_ISelection* theSelection,
320 ModuleBase_Operation* theOperation) const
322 if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
323 return isEmptySelectionValid(theOperation);
325 QList<ModuleBase_ViewerPrsPtr> aList =
326 theSelection->getSelected(ModuleBase_ISelection::Viewer);
329 foreach (ModuleBase_ViewerPrsPtr aPrs, aList) {
330 GeomShapePtr aShape = aPrs->shape();
331 if (aShape.get() && aShape->isEdge()) {
333 GeomAPI_Edge aEdge(aShape);
334 if (aEdge.isLine()) {
339 } else if (aEdge.isCircle()) {
344 } else if (aEdge.isArc()) {
353 return (aCount > 0) && (aCount < 3);
357 bool PartSet_CollinearSelection::isValid(const ModuleBase_ISelection* theSelection,
358 ModuleBase_Operation* theOperation) const
360 if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
361 return isEmptySelectionValid(theOperation);
363 int aCount = shapesNbLines(theSelection);
364 return (aCount > 0) && (aCount < 3);
368 bool PartSet_MiddlePointSelection::isValid(const ModuleBase_ISelection* theSelection,
369 ModuleBase_Operation* theOperation) const
371 if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0)
372 return isEmptySelectionValid(theOperation);
374 return shapesNbLines(theSelection) == 1 || shapesNbPoints(theSelection) == 1;
377 bool PartSet_MultyTranslationSelection::isValid(const ModuleBase_ISelection* theSelection,
378 ModuleBase_Operation* theOperation) const
380 if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
381 return isEmptySelectionValid(theOperation);
383 int aCount = shapesNbLines(theSelection);
388 bool PartSet_SplitSelection::isValid(const ModuleBase_ISelection* theSelection,
389 ModuleBase_Operation* theOperation) const
391 if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
392 return isEmptySelectionValid(theOperation);
394 int aCount = shapesNbLines(theSelection);
399 bool PartSet_ProjectionSelection::isValid(const ModuleBase_ISelection* theSelection,
400 ModuleBase_Operation* theOperation) const
402 if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
403 return isEmptySelectionValid(theOperation);
405 int aCount = shapesNbLines(theSelection);
410 bool PartSet_IntersectionSelection::isValid(const ModuleBase_ISelection* theSelection,
411 ModuleBase_Operation* theOperation) const
413 if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
414 return isEmptySelectionValid(theOperation);
416 int aCount = shapesNbLines(theSelection);
422 std::string PartSet_DifferentObjectsValidator::errorMessage(
423 const PartSet_DifferentObjectsValidator::ErrorType& theType,
424 const std::string& thEqualObject, const std::string& theFirstAttribute,
425 const std::string& theSecondAttribute) const
430 anError = "The feature uses one " + thEqualObject + " object in " +
431 theFirstAttribute + " and " + theSecondAttribute + " attributes.";
433 case EqualAttributes:
434 anError = "The feature uses reference to one " + thEqualObject + " attribute in " +
435 theFirstAttribute + " and " + theSecondAttribute + " attributes.";
438 anError = "The feature uses one shape in " +
439 theFirstAttribute + " and " + theSecondAttribute + " attributes.";
442 anError = "The feature uses empty shapes in " +
443 theFirstAttribute + " and " + theSecondAttribute + " attributes.";
452 bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute,
453 const std::list<std::string>& theArguments,
454 Events_InfoMessage& theError) const
456 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
458 // the type of validated attributes should be equal, attributes with
459 // different types are not validated
460 // Check RefAttr attributes
461 std::string anAttrType = theAttribute->attributeType();
462 std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs;
464 if (anAttrType == ModelAPI_AttributeRefAttr::typeId()) {
465 AttributeRefAttrPtr anAttr =
466 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
467 bool isObject = anAttr->isObject();
468 ObjectPtr anObject = anAttr->object();
470 anAttrs = aFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
471 if (anAttrs.size() > 0) {
472 std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttrIter = anAttrs.begin();
473 for(; anAttrIter != anAttrs.end(); anAttrIter++) {
474 if ((*anAttrIter).get() && (*anAttrIter)->id() != theAttribute->id()) {
475 std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
476 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttrIter);
477 if (aRef->isObject() != isObject)
480 if (aRef->object() == anObject) {
481 theError = errorMessage(EqualObjects, anObject.get() ? anObject->data()->name() : "",
482 theAttribute->id(), aRef->id());
486 else { // the attribute reference
487 AttributePtr anAttributeAttr = anAttr->attr();
488 if (aRef->attr() == anAttributeAttr) {
489 theError = errorMessage(EqualAttributes,
490 anAttributeAttr.get() ? anAttributeAttr->id() : "",
491 theAttribute->id(), aRef->id());
499 else if (anAttrType == ModelAPI_AttributeSelection::typeId()) {
500 AttributeSelectionPtr anAttr =
501 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
502 ResultPtr aContext = anAttr->context();
503 GeomShapePtr aShape = anAttr->value();
505 // Check selection attributes
506 anAttrs = aFeature->data()->attributes(ModelAPI_AttributeSelection::typeId());
507 if (anAttrs.size() > 0) {
508 std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
509 for(; anAttr != anAttrs.end(); anAttr++) {
510 if ((*anAttr).get() && (*anAttr)->id() != theAttribute->id()) {
511 std::shared_ptr<ModelAPI_AttributeSelection> aRef =
512 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(*anAttr);
513 // check the object is already presented
514 if (aRef->context() == aContext) {
515 bool aHasShape = aShape.get() != NULL;
516 if (!aHasShape || aRef->value()->isEqual(aShape)) {
517 theError = errorMessage(EqualShapes, "", theAttribute->id(), aRef->id());
525 else if (anAttrType == ModelAPI_AttributeReference::typeId()) {
526 AttributeReferencePtr anAttr =
527 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
528 ObjectPtr anObject = anAttr->value();
529 // Check selection attributes
530 anAttrs = aFeature->data()->attributes(ModelAPI_AttributeReference::typeId());
531 if (anAttrs.size() > 0) {
532 std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
533 for(; anAttr != anAttrs.end(); anAttr++) {
534 if ((*anAttr).get() && (*anAttr)->id() != theAttribute->id()) {
535 std::shared_ptr<ModelAPI_AttributeReference> aRef =
536 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(*anAttr);
537 // check the object is already presented
538 if (aRef->value() == anObject) {
539 theError = errorMessage(EqualObjects, anObject.get() ? anObject->data()->name() : "",
540 theAttribute->id(), aRef->id());
548 else if(anAttrType == ModelAPI_AttributeSelectionList::typeId()) {
549 std::shared_ptr<ModelAPI_AttributeSelectionList> aCurSelList =
550 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
551 anAttrs = aFeature->data()->attributes(ModelAPI_AttributeSelectionList::typeId());
552 if(anAttrs.size() > 0) {
553 std::list<std::shared_ptr<ModelAPI_Attribute>>::iterator anAttrItr = anAttrs.begin();
554 for(; anAttrItr != anAttrs.end(); anAttrItr++){
555 if ((*anAttrItr).get() && (*anAttrItr)->id() != theAttribute->id()){
556 std::shared_ptr<ModelAPI_AttributeSelectionList> aRefSelList =
557 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(*anAttrItr);
558 for(int i = 0; i < aCurSelList->size(); i++) {
559 std::shared_ptr<ModelAPI_AttributeSelection> aCurSel = aCurSelList->value(i);
560 ResultPtr aCurSelContext = aCurSel->context();
561 ResultBodyPtr aCurSelCompSolidPtr = ModelAPI_Tools::bodyOwner(aCurSelContext);
562 std::shared_ptr<GeomAPI_Shape> aCurSelCompSolid;
563 if(aCurSelCompSolidPtr.get()) {
564 aCurSelCompSolid = aCurSelCompSolidPtr->shape();
566 for(int j = 0; j < aRefSelList->size(); j++) {
567 std::shared_ptr<ModelAPI_AttributeSelection> aRefSel = aRefSelList->value(j);
568 ResultPtr aRefSelContext = aRefSel->context();
569 ResultBodyPtr aRefSelCompSolidPtr =
570 ModelAPI_Tools::bodyOwner(aRefSelContext);
571 std::shared_ptr<GeomAPI_Shape> aRefSelCompSolid;
572 if(aRefSelCompSolidPtr.get()) {
573 aRefSelCompSolid = aRefSelCompSolidPtr->shape();
575 if ((aCurSelCompSolid.get() && aCurSelCompSolid->isEqual(aRefSel->value()))
576 || (aRefSelCompSolid.get() && aRefSelCompSolid->isEqual(aCurSel->value()))) {
577 theError = errorMessage(EqualShapes, "", theAttribute->id(),
581 if(aCurSelContext == aRefSelContext) {
582 if (aCurSel->value().get() == NULL || aRefSel->value().get() == NULL) {
583 theError = errorMessage(EmptyShapes, "", theAttribute->id(),
587 if (aCurSel->value()->isEqual(aRefSel->value())) {
588 theError = errorMessage(EqualShapes, "", theAttribute->id(),
599 else if (anAttrType == ModelAPI_AttributeRefList::typeId()) {
600 std::shared_ptr<ModelAPI_AttributeRefList> aCurSelList =
601 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
602 anAttrs = aFeature->data()->attributes(ModelAPI_AttributeRefList::typeId());
603 if (anAttrs.size() > 0) {
604 std::list<std::shared_ptr<ModelAPI_Attribute>>::iterator anAttrItr = anAttrs.begin();
605 for (; anAttrItr != anAttrs.end(); anAttrItr++){
606 if ((*anAttrItr).get() && (*anAttrItr)->id() != theAttribute->id()){
607 std::shared_ptr<ModelAPI_AttributeRefList> aRefSelList =
608 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*anAttrItr);
609 for (int i = 0; i < aCurSelList->size(); i++) {
610 ObjectPtr aCurSelObject = aCurSelList->object(i);
611 for (int j = 0; j < aRefSelList->size(); j++) {
612 if (aCurSelObject == aRefSelList->object(j)) {
613 theError = errorMessage(EqualObjects,
614 aCurSelObject.get() ? aCurSelObject->data()->name() : "",
615 theAttribute->id(), aCurSelList->id());
627 bool PartSet_DifferentPointsValidator::isValid(const AttributePtr& theAttribute,
628 const std::list<std::string>& theArguments,
629 Events_InfoMessage& theError) const
631 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
633 // the type of validated attributes should be equal, attributes with
634 // different types are not validated
635 // Check RefAttr attributes
636 std::string anAttrType = theAttribute->attributeType();
637 std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs;
638 if (anAttrType != ModelAPI_AttributeRefAttr::typeId())
641 // obtain point of the given attribute
642 AttributePoint2DPtr anAttributePoint = getRefPointAttribute(theAttribute);
643 if (!anAttributePoint.get() || !anAttributePoint->isInitialized())
646 // obtain point of the parameter attribute
647 AttributePoint2DPtr anArgumentPoint = getRefPointAttribute
648 (aFeature->attribute(theArguments.front()));
650 if (!anArgumentPoint.get() || !anArgumentPoint->isInitialized())
653 return !anAttributePoint->pnt()->isEqual(anArgumentPoint->pnt());
656 AttributePoint2DPtr PartSet_DifferentPointsValidator::getRefPointAttribute
657 (const AttributePtr& theAttribute) const
659 AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
661 AttributePoint2DPtr aPointAttribute;
662 if (anAttr->isObject()) {
663 ObjectPtr anObject = anAttr->object();
664 if (anObject.get()) {
665 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
666 if (aFeature->getKind() == SketchPlugin_Point::ID())
667 aPointAttribute = std::dynamic_pointer_cast<GeomDataAPI_Point2D>
668 (aFeature->attribute(SketchPlugin_Point::COORD_ID()));
672 aPointAttribute = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
674 return aPointAttribute;
677 bool PartSet_CoincidentAttr::isValid(const AttributePtr& theAttribute,
678 const std::list<std::string>& theArguments,
679 Events_InfoMessage& theError) const
681 if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
682 theError = "The attribute with the %1 type is not processed";
683 theError.arg(theAttribute->attributeType());
687 // there is a check whether the feature contains a point and a linear edge or two point values
688 std::string aParamA = theArguments.front();
689 SessionPtr aMgr = ModelAPI_Session::get();
690 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
692 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
693 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
694 QList<FeaturePtr> aCoinsideLines;
695 QList<FeaturePtr> aCoins;
697 bool isObject = aRefAttr->isObject();
698 ObjectPtr anObject = aRefAttr->object();
699 if (isObject && anObject) {
700 FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject);
701 AttributeRefAttrPtr aOtherAttr = aFeature->data()->refattr(aParamA);
702 ObjectPtr aOtherObject = aOtherAttr->object();
703 // if the other attribute is not filled still, the result is true
704 if (!aOtherObject.get())
706 FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject);
708 // check that both have coincidence
709 FeaturePtr aConstrFeature;
710 std::set<FeaturePtr> aCoinList;
711 const std::set<std::shared_ptr<ModelAPI_Attribute>>& aRefsList = aRefFea->data()->refsToMe();
712 std::set<std::shared_ptr<ModelAPI_Attribute>>::const_iterator aIt;
713 for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
714 std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
715 aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
716 if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
717 AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
718 AttributePtr aAR = aRAttr->attr();
719 if (aAR->id() != SketchPlugin_Arc::CENTER_ID()) // ignore constraint to center of arc
720 aCoinList.insert(aConstrFeature);
721 QList<bool> anIsAttributes;
722 PartSet_Tools::findCoincidences(aConstrFeature, aCoinsideLines, aCoins,
723 SketchPlugin_ConstraintCoincidence::ENTITY_A(),
725 PartSet_Tools::findCoincidences(aConstrFeature, aCoinsideLines, aCoins,
726 SketchPlugin_ConstraintCoincidence::ENTITY_B(),
730 // if there is no coincidence then it is not valid
731 if (aCoinList.size() > 0) {
732 QList<FeaturePtr>::const_iterator anIt = aCoinsideLines.begin(), aLast = aCoinsideLines.end();
734 for (; anIt != aLast && !aValid; anIt++) {
735 aValid = *anIt == aOtherFea;
741 theError = "There is no a common coincident point.";