From: nds Date: Mon, 2 Feb 2015 09:22:58 +0000 (+0300) Subject: Issue #392 Can not create axis on two points of one sketch X-Git-Tag: V_1.0.0~1^2~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2b9a0ebe5b0b562ead8c4516fea9ebdc331e0963;p=modules%2Fshaper.git Issue #392 Can not create axis on two points of one sketch --- diff --git a/src/ConstructionPlugin/axis_widget.xml b/src/ConstructionPlugin/axis_widget.xml index f612a83d0..a3424e3f1 100644 --- a/src/ConstructionPlugin/axis_widget.xml +++ b/src/ConstructionPlugin/axis_widget.xml @@ -14,6 +14,6 @@ tooltip="Select a second point" shape_types="vertex"> - + diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index 738664c17..e8ef2bad2 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -37,6 +37,7 @@ SET(PROJECT_HEADERS ModelAPI_ResultValidator.h ModelAPI_Session.h ModelAPI_Tools.h + ModelAPI_ShapeValidator.h ModelAPI_Validator.h ) @@ -65,6 +66,7 @@ SET(PROJECT_SOURCES ModelAPI_ResultGroup.cpp ModelAPI_ResultPart.cpp ModelAPI_Session.cpp + ModelAPI_ShapeValidator.cpp ModelAPI_Tools.cpp ) diff --git a/src/ModelAPI/ModelAPI_ShapeValidator.cpp b/src/ModelAPI/ModelAPI_ShapeValidator.cpp new file mode 100644 index 000000000..b451ed1bb --- /dev/null +++ b/src/ModelAPI/ModelAPI_ShapeValidator.cpp @@ -0,0 +1,36 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModelAPI_ShapeValidator.cpp +// Created: 2 Feb 2015 +// Author: Natalia ERMOLAEVA + +#include "ModelAPI_ShapeValidator.h" + +#include +#include "ModelAPI_Object.h" + +bool ModelAPI_ShapeValidator::isValid(const FeaturePtr& theFeature, + const AttributePtr& theAttribute, + const GeomShapePtr& theShape) const +{ + std::string aCurrentAttributeId = theAttribute->id(); + // get all feature attributes + std::list anAttrs = + theFeature->data()->attributes(ModelAPI_AttributeSelection::type()); + if (anAttrs.size() > 0 && theShape.get() != NULL) { + std::list::iterator anAttr = anAttrs.begin(); + for(; anAttr != anAttrs.end(); anAttr++) { + AttributePtr anAttribute = *anAttr; + // take into concideration only other attributes + if (anAttribute.get() != NULL && anAttribute->id() != aCurrentAttributeId) { + AttributeSelectionPtr aSelectionAttribute = + std::dynamic_pointer_cast(anAttribute); + // the shape of the attribute should be not the same + if (aSelectionAttribute.get() != NULL && theShape->isEqual(aSelectionAttribute->value())) { + return false; + } + } + } + } + return true; +} diff --git a/src/ModelAPI/ModelAPI_ShapeValidator.h b/src/ModelAPI/ModelAPI_ShapeValidator.h new file mode 100644 index 000000000..596e1c08e --- /dev/null +++ b/src/ModelAPI/ModelAPI_ShapeValidator.h @@ -0,0 +1,33 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModelAPI_ShapeValidator.h +// Created: 2 Feb 2015 +// Author: Natalia ERMOLAEVA + +#ifndef ModelAPI_ShapeValidator_H +#define ModelAPI_ShapeValidator_H + +#include + +#include +#include +#include + +#include + +/** + * Generic validator for any attribute of a feature. + */ +class ModelAPI_ShapeValidator : public ModelAPI_Validator +{ +public: + /// returns True if the attribute is valid. It checks whether the feature of the attribute + /// does not contain a selection attribute filled with the same shape + /// \param theFeature a feature to check + /// \param theAttribute an attribute to check + /// \param theShape a shape + MODELAPI_EXPORT bool isValid(const FeaturePtr& theFeature, const AttributePtr& theAttribute, + const GeomShapePtr& theShape) const; +}; + +#endif diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 070cec76c..81e45ef0a 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -502,6 +503,17 @@ bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr(*aValidator); + if (aShapeValidator) { + DataPtr aData = myFeature->data(); + AttributeSelectionPtr aSelectAttr = aData->selection(attributeID()); + if (!aShapeValidator->isValid(myFeature, aSelectAttr, theShape)) { + return false; + } + } + } } return true; } \ No newline at end of file diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 253514b35..d94e396a6 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -115,6 +116,7 @@ void PartSet_Module::registerValidators() aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator); aFactory->registerValidator("PartSet_RigidValidator", new PartSet_RigidValidator); aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator); + aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator); aFactory->registerValidator("PartSet_SketchValidator", new PartSet_SketchValidator); }