+ return true;
+}
+
+bool PartSet_AngleSelection::isValid(const ModuleBase_ISelection* theSelection,
+ ModuleBase_Operation* theOperation) const
+{
+ if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+ return isEmptySelectionValid(theOperation);
+ } else {
+ int aCount = shapesNbLines(theSelection);
+ return (aCount > 0) && (aCount < 3);
+ }
+}
+
+bool PartSet_EqualSelection::isValid(const ModuleBase_ISelection* theSelection,
+ ModuleBase_Operation* theOperation) const
+{
+ if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+ return isEmptySelectionValid(theOperation);
+ } else {
+ QList<ModuleBase_ViewerPrsPtr> aList =
+ theSelection->getSelected(ModuleBase_ISelection::Viewer);
+ int aCount = 0;
+ int aType = 0;
+ foreach (ModuleBase_ViewerPrsPtr aPrs, aList) {
+ GeomShapePtr aShape = aPrs->shape();
+ if (aShape.get() && aShape->isEdge()) {
+ aCount++;
+ GeomAPI_Edge aEdge(aShape);
+ if (aEdge.isLine()) {
+ if (aCount == 1)
+ aType = 1;
+ else if (aType != 1)
+ return false;
+ } else if (aEdge.isCircle() || aEdge.isArc()) {
+ if (aCount == 1)
+ aType = 2;
+ else if (aType != 2)
+ return false;
+ } else if (aEdge.isEllipse()) {
+ if (aCount == 1)
+ aType = 3;
+ else if (aType != 3)
+ return false;
+ }
+ } else
+ return false;
+ }
+ return (aCount > 0) && (aCount < 3);
+ }
+}
+
+bool PartSet_CollinearSelection::isValid(const ModuleBase_ISelection* theSelection,
+ ModuleBase_Operation* theOperation) const
+{
+ if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+ return isEmptySelectionValid(theOperation);
+ } else {
+ int aCount = shapesNbLines(theSelection);
+ return (aCount > 0) && (aCount < 3);
+ }
+}
+
+bool PartSet_MiddlePointSelection::isValid(const ModuleBase_ISelection* theSelection,
+ ModuleBase_Operation* theOperation) const
+{
+ if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0)
+ return isEmptySelectionValid(theOperation);
+ else
+ return shapesNbLines(theSelection) == 1 || shapesNbPoints(theSelection) == 1;
+}
+
+bool PartSet_MultyTranslationSelection::isValid(const ModuleBase_ISelection* theSelection,
+ ModuleBase_Operation* theOperation) const
+{
+ if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+ return isEmptySelectionValid(theOperation);
+ } else {
+ int aCount = shapesNbLines(theSelection);
+ return aCount > 0;
+ }
+}
+
+bool PartSet_SplitSelection::isValid(const ModuleBase_ISelection* theSelection,
+ ModuleBase_Operation* theOperation) const
+{
+ if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+ return isEmptySelectionValid(theOperation);
+ } else {
+ int aCount = shapesNbLines(theSelection);
+ return aCount > 0;
+ }
+}
+
+bool PartSet_ProjectionSelection::isValid(const ModuleBase_ISelection* theSelection,
+ ModuleBase_Operation* theOperation) const
+{
+ if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+ return isEmptySelectionValid(theOperation);
+ } else {
+ int aCount = shapesNbLines(theSelection);
+ return aCount > 0;
+ }
+}
+
+bool PartSet_IntersectionSelection::isValid(const ModuleBase_ISelection* theSelection,
+ ModuleBase_Operation* theOperation) const
+{
+ if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+ return isEmptySelectionValid(theOperation);
+ } else {
+ int aCount = shapesNbLines(theSelection);
+ return aCount == 0;
+ }
+}
+
+
+std::string PartSet_DifferentObjectsValidator::errorMessage(
+ const PartSet_DifferentObjectsValidator::ErrorType& theType,
+ const std::string& thEqualObject, const std::string& theFirstAttribute,
+ const std::string& theSecondAttribute) const
+{
+ std::string anError;
+ switch (theType) {
+ case EqualObjects:
+ anError = "The feature uses one " + thEqualObject + " object in " +
+ theFirstAttribute + " and " + theSecondAttribute + " attributes.";
+ break;
+ case EqualAttributes:
+ anError = "The feature uses reference to one " + thEqualObject + " attribute in " +
+ theFirstAttribute + " and " + theSecondAttribute + " attributes.";
+ break;
+ case EqualShapes:
+ anError = "The feature uses one shape in " +
+ theFirstAttribute + " and " + theSecondAttribute + " attributes.";
+ break;
+ case EmptyShapes:
+ anError = "The feature uses empty shapes in " +
+ theFirstAttribute + " and " + theSecondAttribute + " attributes.";
+ break;
+ break;
+ default:
+ break;
+ }
+ return anError;
+}
+
+bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const
+{
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+
+ // the type of validated attributes should be equal, attributes with
+ // different types are not validated
+ // Check RefAttr attributes
+ std::string anAttrType = theAttribute->attributeType();
+ std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs;
+
+ if (anAttrType == ModelAPI_AttributeRefAttr::typeId()) {
+ AttributeRefAttrPtr anAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ bool isObject = anAttr->isObject();
+ ObjectPtr anObject = anAttr->object();
+
+ anAttrs = aFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
+ if (anAttrs.size() > 0) {
+ std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttrIter = anAttrs.begin();
+ for(; anAttrIter != anAttrs.end(); anAttrIter++) {
+ if ((*anAttrIter).get() && (*anAttrIter)->id() != theAttribute->id()) {
+ std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttrIter);
+ if (aRef->isObject() != isObject)
+ continue;
+ if (isObject) {
+ if (aRef->object() == anObject) {
+ theError = errorMessage(EqualObjects, anObject.get() ? anObject->data()->name() : "",
+ theAttribute->id(), aRef->id());
+ return false;
+ }
+ }
+ else { // the attribute reference
+ AttributePtr anAttributeAttr = anAttr->attr();
+ if (aRef->attr() == anAttributeAttr) {
+ theError = errorMessage(EqualAttributes,
+ anAttributeAttr.get() ? anAttributeAttr->id() : "",
+ theAttribute->id(), aRef->id());
+ return false;
+ }
+ }
+ }
+ }
+ }
+ }
+ else if (anAttrType == ModelAPI_AttributeSelection::typeId()) {
+ AttributeSelectionPtr anAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+ ResultPtr aContext = anAttr->context();
+ FeaturePtr aContextFeature = anAttr->contextFeature();
+ GeomShapePtr aShape = anAttr->value();
+
+ // Check selection attributes
+ anAttrs = aFeature->data()->attributes(ModelAPI_AttributeSelection::typeId());
+ if (anAttrs.size() > 0) {