From: dbv Date: Thu, 26 May 2016 15:16:08 +0000 (+0300) Subject: Validator for Pipe path selection which disables local selection of wires. X-Git-Tag: V_2.3.1~47 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=52af71800665828f10db95f67db1949ca6115383;p=modules%2Fshaper.git Validator for Pipe path selection which disables local selection of wires. --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp index d6fa48f3d..d42ede130 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp @@ -53,6 +53,8 @@ FeaturesPlugin_Plugin::FeaturesPlugin_Plugin() new FeaturesPlugin_ValidatorRemoveSubShapesSelection); aFactory->registerValidator("FeaturesPlugin_ValidatorRemoveSubShapesResult", new FeaturesPlugin_ValidatorRemoveSubShapesResult); + aFactory->registerValidator("FeaturesPlugin_ValidatorPipePath", + new FeaturesPlugin_ValidatorPipePath); // register this plugin ModelAPI_Session::get()->registerPlugin(this); diff --git a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp index 1aee44fa6..7cf005d96 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp @@ -29,6 +29,32 @@ #include #include +//================================================================================================== +bool FeaturesPlugin_ValidatorPipePath::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const +{ + AttributeSelectionPtr aPathAttrSelection = std::dynamic_pointer_cast(theAttribute); + if(!aPathAttrSelection.get()) { + theError = "Error: This validator can only work with path selector in \"Pipe\" feature."; + return false; + } + + GeomShapePtr aPathShape = aPathAttrSelection->value(); + ResultPtr aContext = aPathAttrSelection->context(); + if(!aContext.get()) { + theError = "Error: Empty context."; + return false; + } + GeomShapePtr aContextShape = aContext->shape(); + if(aPathShape.get() && aPathShape->shapeType() == GeomAPI_Shape::WIRE && !aPathShape->isEqual(aContextShape)) { + theError = "Error: Local selection of wires not allowed."; + return false; + } + + return true; +} + //================================================================================================== bool FeaturesPlugin_ValidatorPipeLocations::isValid(const std::shared_ptr& theFeature, const std::list& theArguments, diff --git a/src/FeaturesPlugin/FeaturesPlugin_Validators.h b/src/FeaturesPlugin/FeaturesPlugin_Validators.h index fb05c2ab3..da6180e58 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.h @@ -10,6 +10,21 @@ #include #include +/// \class FeaturesPlugin_ValidatorPipePath +/// \ingroup Validators +/// \brief A validator for selection pipe path. +class FeaturesPlugin_ValidatorPipePath: public ModelAPI_AttributeValidator +{ +public: + //! \return True if the attribute is valid. + //! \param[in] theAttribute the checked attribute. + //! \param[in] theArguments arguments of the attribute. + //! \param[out] theError error message. + virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const; +}; + /// \class FeaturesPlugin_ValidatorPipeLocations /// \ingroup Validators /// \brief Validator for the pipe locations. @@ -35,7 +50,7 @@ class FeaturesPlugin_ValidatorPipeLocations: public ModelAPI_FeatureValidator class FeaturesPlugin_ValidatorBaseForGeneration: public ModelAPI_AttributeValidator { public: - //! Returns true if attribute has selection type listed in the parameter arguments. + //! \return true if attribute has selection type listed in the parameter arguments. //! \param[in] theAttribute the checked attribute. //! \param[in] theArguments arguments of the attribute. //! \param[out] theError error message. @@ -55,7 +70,7 @@ private: class FeaturesPlugin_ValidatorCompositeLauncher: public ModelAPI_AttributeValidator { public: - //! Returns true if attribute has selection type listed in the parameter arguments. + //! \return true if attribute has selection type listed in the parameter arguments. //! \param[in] theAttribute the checked attribute. //! \param[in] theArguments arguments of the attribute. //! \param[out] theError error message. @@ -71,7 +86,7 @@ public: class FeaturesPlugin_ValidatorCanBeEmpty: public ModelAPI_FeatureValidator { public: - //! Returns true if attribute listed in the parameter arguments are planar. + //! \return true if attribute listed in the parameter arguments are planar. //! \param[in] theFeature the checked feature. //! \param[in] theArguments arguments of the attribute. //! \param[out] theError error message. @@ -79,7 +94,7 @@ public: const std::list& theArguments, std::string& theError) const; - /// Returns true if the attribute in feature is not obligatory for the feature execution + /// \return true if the attribute in feature is not obligatory for the feature execution virtual bool isNotObligatory(std::string theFeature, std::string theAttribute); private: @@ -149,7 +164,7 @@ class FeaturesPlugin_ValidatorRemoveSubShapesResult: public ModelAPI_FeatureVali const std::list& theArguments, std::string& theError) const; - /// Returns true if the attribute in feature is not obligatory for the feature execution + /// \return true if the attribute in feature is not obligatory for the feature execution virtual bool isNotObligatory(std::string theFeature, std::string theAttribute); }; diff --git a/src/FeaturesPlugin/pipe_widget.xml b/src/FeaturesPlugin/pipe_widget.xml index 591b9e420..def2fd264 100644 --- a/src/FeaturesPlugin/pipe_widget.xml +++ b/src/FeaturesPlugin/pipe_widget.xml @@ -13,6 +13,7 @@ label="Path object:" tooltip="Select an edge or wire for path" shape_types="edge wire"> +