From: jfa Date: Wed, 19 Jul 2023 12:30:11 +0000 (+0100) Subject: Provide name for XAOMem import feature and result if imported geometry doesn't have... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5c91d03eae720fff166c243b5922db1efd812877;p=modules%2Fshaper.git Provide name for XAOMem import feature and result if imported geometry doesn't have it. Disable editing ImportXAOMem feature. --- diff --git a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp index 491c87290..b1b5e1908 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp @@ -109,6 +109,19 @@ void ExchangePlugin_ImportFeature::initAttributes() ModelAPI_Session::get()->validators()->registerNotObligatory( getKind(), ExchangePlugin_ImportFeature::MEMORY_BUFFER_ID()); } + +bool ExchangePlugin_ImportFeature::isEditable() +{ + AttributeStringPtr aImportTypeAttr = string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID()); + std::string aFormat = aImportTypeAttr->value(); + + if (aFormat == "XAOMem") + // If the shape is imported from memory buffer, do not allow to edit the feature + return false; + + return true; +} + /* * Computes or recomputes the results */ @@ -401,8 +414,12 @@ void ExchangePlugin_ImportFeature::importXAO(const std::string& theFileName, // use the geometry name or the file name for the feature std::string aBodyName = aXaoGeometry->getName(); - if (aBodyName.empty() && !isMemoryImport) - aBodyName = GeomAlgoAPI_Tools::File_Tools::name(theFileName); + if (aBodyName.empty()) { + if (isMemoryImport) + aBodyName = "ImportXAOMem"; + else + aBodyName = GeomAlgoAPI_Tools::File_Tools::name(theFileName); + } data()->setName(Locale::Convert::toWString(aBodyName)); ResultBodyPtr aResultBody = createResultBody(aGeomShape); diff --git a/src/ExchangePlugin/ExchangePlugin_ImportFeature.h b/src/ExchangePlugin/ExchangePlugin_ImportFeature.h index 53f25c342..5f7947b76 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportFeature.h +++ b/src/ExchangePlugin/ExchangePlugin_ImportFeature.h @@ -167,6 +167,9 @@ public: /// Request for initialization of data model of the feature: adding all attributes EXCHANGEPLUGIN_EXPORT virtual void initAttributes(); + /// Return false in case of XAOMem import. + EXCHANGEPLUGIN_EXPORT virtual bool isEditable(); + protected: /// Performs the import of the file EXCHANGEPLUGIN_EXPORT void importFile(const std::string& theFileName) override; diff --git a/src/ModelAPI/ModelAPI_Feature.cpp b/src/ModelAPI/ModelAPI_Feature.cpp index 4b0939fab..c6ba39294 100644 --- a/src/ModelAPI/ModelAPI_Feature.cpp +++ b/src/ModelAPI/ModelAPI_Feature.cpp @@ -253,6 +253,11 @@ bool ModelAPI_Feature::isStable() return myIsStable; } +bool ModelAPI_Feature::isEditable() +{ + return true; +} + bool ModelAPI_Feature::customAction(const std::string& /*theActionId*/) { return false; diff --git a/src/ModelAPI/ModelAPI_Feature.h b/src/ModelAPI/ModelAPI_Feature.h index f6aec2ecb..0356f4a08 100644 --- a/src/ModelAPI/ModelAPI_Feature.h +++ b/src/ModelAPI/ModelAPI_Feature.h @@ -41,7 +41,7 @@ class ModelAPI_Feature : public ModelAPI_Object std::list > myResults; ///< is feature disabled or not bool myIsDisabled; - ///< is feature is stable (not editing) + ///< is feature stable (not editing) bool myIsStable; public: @@ -155,6 +155,9 @@ class ModelAPI_Feature : public ModelAPI_Object /// Returns the feature is stable or not. MODELAPI_EXPORT virtual bool isStable(); + /// Returns the feature is editable or not. Most of features are editable. + MODELAPI_EXPORT virtual bool isEditable(); + /// Performs some custom feature specific functionality (normally called by some GUI button) /// \param theActionId an action key /// \return a boolean value about it is performed diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 8292e70d6..03cae673e 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -1630,23 +1630,24 @@ void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const } else if (aObject->document() == aMgr->activeDocument()) { if (hasParameter || hasFeature) { - // disable Edit menu for groups under ImportResult feature bool isEnabled = true; - if (aFeature.get() && aFeature->getKind() == "Group") - { - std::shared_ptr anOwner = - ModelAPI_Tools::compositeOwner (aFeature); - - if (anOwner.get() && anOwner->getKind() == "ImportResult") - { - myMenuMgr->action("EDIT_CMD")->setEnabled(false); - isEnabled = false; + if (aFeature.get()) { + // disable Edit menu for not editable features + isEnabled = aFeature->isEditable(); + + // disable Edit menu for groups under ImportResult feature + if (aFeature->getKind() == "Group") { + std::shared_ptr anOwner = + ModelAPI_Tools::compositeOwner (aFeature); + if (anOwner.get() && anOwner->getKind() == "ImportResult") { + isEnabled = false; + } } } - if (isEnabled) - { - myMenuMgr->action("EDIT_CMD")->setEnabled(true); + myMenuMgr->action("EDIT_CMD")->setEnabled(isEnabled); + + if (isEnabled) { theMenu->addAction(myMenuMgr->action("EDIT_CMD")); if (aCurrentOp && aFeature.get()) { if (aCurrentOp->id().toStdString() == aFeature->getKind())