]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Provide name for XAOMem import feature and result if imported geometry doesn't have... jfa/35140_ExportXAOMem 15/head
authorjfa <jfa@opencascade.com>
Wed, 19 Jul 2023 12:30:11 +0000 (13:30 +0100)
committerjfa <jfa@opencascade.com>
Wed, 19 Jul 2023 12:30:11 +0000 (13:30 +0100)
src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp
src/ExchangePlugin/ExchangePlugin_ImportFeature.h
src/ModelAPI/ModelAPI_Feature.cpp
src/ModelAPI/ModelAPI_Feature.h
src/PartSet/PartSet_Module.cpp

index 491c87290daa483a13b7b8fc3ce36c3c7b9ec85f..b1b5e1908dfac58b808a3a867f81305b26b2fca4 100644 (file)
@@ -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);
index 53f25c342bc94e3bc4153c0510610bc14defe5a8..5f7947b7696b1e5a3e02a28014855fec2ffcdb48 100644 (file)
@@ -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;
index 4b0939fab5e3220691f8928583537a9f76fd6d41..c6ba39294b11a6a9749dd82dc3ca7ecc9fee4793 100644 (file)
@@ -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;
index f6aec2ecbe7570820cd4f5c7cfb4fa7e2cf79cf4..0356f4a080b9f6c2c7ee3679fe6604deedbff83d 100644 (file)
@@ -41,7 +41,7 @@ class ModelAPI_Feature : public ModelAPI_Object
   std::list<std::shared_ptr<ModelAPI_Result> > 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
index 8292e70d6f6a86c708f5301bba1c18867dd2fe1f..03cae673e26381f48f3f5f13c2df4c3683fd4be7 100644 (file)
@@ -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<ModelAPI_CompositeFeature> 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<ModelAPI_CompositeFeature> 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())