Salome HOME
bos #29475 Option to create new part on study open
authormpv <mpv@opencascade.com>
Fri, 8 Apr 2022 16:57:15 +0000 (19:57 +0300)
committervsr <vsr@opencascade.com>
Fri, 3 Jun 2022 07:36:58 +0000 (10:36 +0300)
22 files changed:
doc/gui/General/Introduction.rst
doc/gui/images/general_preferences.png
src/Events/CMakeLists.txt
src/Events/Events_MessageBool.cpp [new file with mode: 0644]
src/Events/Events_MessageBool.h [new file with mode: 0644]
src/InitializationPlugin/InitializationPlugin_Plugin.cpp
src/InitializationPlugin/InitializationPlugin_Plugin.h
src/Model/Model_Document.cpp
src/Model/Model_Document.h
src/Model/Model_Session.cpp
src/Model/Model_Session.h
src/ModelAPI/ModelAPI_Events.h
src/ModelAPI/ModelAPI_Session.h
src/ModelHighAPI/ModelHighAPI_Services.cpp
src/ModuleBase/ModuleBase_Preferences.cpp
src/ModuleBase/ModuleBase_msg_fr.ts
src/PartSet/PartSet_Module.cpp
src/SHAPERGUI/SHAPERGUI.cpp
src/SHAPERGUI/resources/LightApp.xml.in
src/XGUI/SHAPER.xml
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_WorkshopListener.cpp

index 4a9024657561d13300f04ad0b5ad290712795981..b691bdf2afa9b9c0d372d69668d6c04e73acba0b 100644 (file)
@@ -475,7 +475,7 @@ Other tabs are activated by click on tab header.
 General tab
 ^^^^^^^^^^^
 
-This tab defines what parts to be activated and what elements to be visible after opening a study or a script.
+This tab defines behavior of Parts and displayed objects on creation or opening of a study, or loading python scripts.
 
 .. figure:: /images/general_preferences.png
    :align: center
@@ -484,6 +484,8 @@ This tab defines what parts to be activated and what elements to be visible afte
 
 **Input fields**:
 
+- **Create new part** flag. If it is enabled, an empty part is created on a study creation.
+
 - **Activate** relates to activation of part when opening a HDF document. Its could be one of the following:
 
   - "Last part" - activate last part in the document (**default value**);
index e7eee1721dfa4896351afd9cdf0e1fea2129cd42..0589e79d940806f7c63efe910ee0c936e8fa8bab 100644 (file)
Binary files a/doc/gui/images/general_preferences.png and b/doc/gui/images/general_preferences.png differ
index 242a1591b22b8be74930b91d6f78a684d73f2496..6f47c6c73b8d9508431ccb08feafe666b1b22324 100644 (file)
@@ -30,6 +30,7 @@ SET(PROJECT_HEADERS
     Events_Loop.h
     Events_LongOp.h
     Events_InfoMessage.h
+    Events_MessageBool.h
 )
 
 SET(PROJECT_SOURCES
@@ -39,6 +40,7 @@ SET(PROJECT_SOURCES
     Events_Loop.cpp
     Events_LongOp.cpp
     Events_InfoMessage.cpp
+    Events_MessageBool.cpp
 )
 
 SET(PROJECT_LIBRARIES
diff --git a/src/Events/Events_MessageBool.cpp b/src/Events/Events_MessageBool.cpp
new file mode 100644 (file)
index 0000000..eb79aaa
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright (C) 2014-2021  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "Events_MessageBool.h"
+
+void Events_MessageBool::send()
+{
+  std::shared_ptr<Events_Message> aMsg(new Events_MessageBool(*this));
+  Events_Loop::loop()->send(aMsg);
+}
diff --git a/src/Events/Events_MessageBool.h b/src/Events/Events_MessageBool.h
new file mode 100644 (file)
index 0000000..891b081
--- /dev/null
@@ -0,0 +1,62 @@
+// Copyright (C) 2014-2021  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef Events_MessageBool_H_
+#define Events_MessageBool_H_
+
+#include <Events.h>
+#include <Events_Message.h>
+#include <Events_Loop.h>
+
+#include <string>
+#include <list>
+
+/**\class Events_MessageBool
+ * \ingroup EventsLoop
+ * \brief An event message for sending a message with a boolean value.
+ *        May be used for different where just a Boolean flag is needed to send.
+ */
+class Events_MessageBool: public Events_Message
+{
+public:
+
+  /// Constructor
+  /// \param theEventID an indentifier of the message
+  /// \param theValue a Boolean value to send
+  /// \param theSender a pointer on sender object
+  Events_MessageBool(const Events_ID theEventID, const bool theValue, const void* theSender = 0):
+  Events_Message(theEventID, theSender), myValue(theValue) {}
+
+  /// Default destructor
+  virtual ~Events_MessageBool() {}
+
+  /// Returns the value stored in this message.
+  const bool value() const { return myValue; }
+
+  /// Sends the message
+  EVENTS_EXPORT void send();
+
+private:
+
+  /// The stored value
+  bool myValue;
+
+};
+
+#endif
index 228c30e9a7e4e4e26d9fbb3b1114844f9e33c603..e934ae5c67f45b72b0c7fc035c5d6e0cebf3cbd9 100644 (file)
@@ -33,6 +33,7 @@
 
 #include <Events_Message.h>
 #include <Events_InfoMessage.h>
+#include <Events_MessageBool.h>
 
 #include <memory>
 
 static InitializationPlugin_Plugin* MY_INITIALIZATIONPLUGIN_INSTANCE =
     new InitializationPlugin_Plugin();
 
-InitializationPlugin_Plugin::InitializationPlugin_Plugin()
+InitializationPlugin_Plugin::InitializationPlugin_Plugin() :
+  myCreatePartOnStart(false) // by default in TUI mode part is not created on start of PartSet
 {
   char* isUnitTest = getenv("SHAPER_UNIT_TEST_IN_PROGRESS");
   myInitDataModel = (!isUnitTest || isUnitTest[0] != '1');
 
   Events_Loop* aLoop = Events_Loop::loop();
-  const Events_ID kDocCreatedEvent = ModelAPI_DocumentCreatedMessage::eventId();
+  static const Events_ID kDocCreatedEvent = ModelAPI_DocumentCreatedMessage::eventId();
   aLoop->registerListener(this, kDocCreatedEvent, NULL, true);
+  static const Events_ID kCreatePartEvent = Events_Loop::eventByName(EVENT_CREATE_PART_ON_START);
+  aLoop->registerListener(this, kCreatePartEvent, NULL, true);
 
   myEvalListener =
     std::shared_ptr<InitializationPlugin_EvalListener>(new InitializationPlugin_EvalListener());
@@ -55,7 +59,8 @@ InitializationPlugin_Plugin::InitializationPlugin_Plugin()
 
 void InitializationPlugin_Plugin::processEvent(const std::shared_ptr<Events_Message>& theMessage)
 {
-  const Events_ID kDocCreatedEvent = ModelAPI_DocumentCreatedMessage::eventId();
+  static const Events_ID kDocCreatedEvent = ModelAPI_DocumentCreatedMessage::eventId();
+  static const Events_ID kCreatePartEvent = Events_Loop::eventByName(EVENT_CREATE_PART_ON_START);
   if (theMessage->eventID() == kDocCreatedEvent) {
     std::shared_ptr<ModelAPI_DocumentCreatedMessage> aMessage = std::dynamic_pointer_cast<
         ModelAPI_DocumentCreatedMessage>(theMessage);
@@ -63,13 +68,15 @@ void InitializationPlugin_Plugin::processEvent(const std::shared_ptr<Events_Mess
 
     /// Issue 431: for the current moment create planes only in the module document,
     /// Later if it is needed we may create special initial planes in Parts (may be different)
-    if (aDoc != ModelAPI_Session::get()->moduleDocument())
+    SessionPtr aMgr = ModelAPI_Session::get();
+    if (aDoc != aMgr->moduleDocument() || aMgr->isLoading())
       return;
 
     if (myInitDataModel)
       myEvalListener->initDataModel();
 
     std::list<FeaturePtr> aFeatures;
+    aMgr->startOperation("Initialization");
 
     // the viewer update should be blocked in order to avoid the features blinking before they are
     // hidden
@@ -85,6 +92,8 @@ void InitializationPlugin_Plugin::processEvent(const std::shared_ptr<Events_Mess
     aFeatures.push_back(createPlane(aDoc, 1., 0., 0.));
     aFeatures.push_back(createPlane(aDoc, 0., -1., 0.));
     aFeatures.push_back(createPlane(aDoc, 0., 0., 1.));
+    if (myCreatePartOnStart)
+      createPart(aDoc);
     // for PartSet it is done outside of the transaction, so explicitly flush this creation
     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
 
@@ -100,13 +109,21 @@ void InitializationPlugin_Plugin::processEvent(const std::shared_ptr<Events_Mess
       }
     }
     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
-    // the viewer update should be unblocked in order to avoid the features blinking before they are
-    // hidden
+
+    aMgr->finishOperation(); // before last message flush to update the title, make it not-modified
+    aMgr->clearUndoRedo(); // to forbid undo of auxiliary elements and initial part
+
+    // the viewer update should be unblocked to avoid the features blinking before they are hidden
     aMsg = std::shared_ptr<Events_Message>(
                   new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)));
 
     Events_Loop::loop()->send(aMsg);
   }
+  else if (theMessage->eventID() == kCreatePartEvent)
+  {
+    std::shared_ptr<Events_MessageBool> aMsg = std::dynamic_pointer_cast<Events_MessageBool>(theMessage);
+    myCreatePartOnStart = aMsg->value();
+  }
 }
 
 FeaturePtr InitializationPlugin_Plugin::createPlane(DocumentPtr theDoc, double theX, double theY,
@@ -189,3 +206,10 @@ FeaturePtr InitializationPlugin_Plugin::createAxis(DocumentPtr theDoc, FeaturePt
 
   return aAxis;
 }
+
+void InitializationPlugin_Plugin::createPart(DocumentPtr thePartSet)
+{
+  std::shared_ptr<ModelAPI_Feature> aPart = thePartSet->addFeature("Part");
+  if (aPart.get())
+    aPart->execute(); // to initialize and activate this part document
+}
index bed22f693dcdffda48e61cafafb563b196811f77..4c0f583ed07ff1c3304d88003c9084dd513a7455 100644 (file)
@@ -70,9 +70,13 @@ class InitializationPlugin_Plugin : public Events_Listener
   FeaturePtr createAxis(DocumentPtr theDoc, FeaturePtr theOrigin,
                         double theX, double theY, double theZ);
 
+  /// Creates and activates a new part in PartSet document.
+  void createPart(DocumentPtr thePartSet);
+
  private:
   std::shared_ptr<InitializationPlugin_EvalListener> myEvalListener;
   bool myInitDataModel;
+  bool myCreatePartOnStart;
 };
 
 #endif
index 72b11c77e8565323ebe981df5148813a66346818..25033c4249c18488de742716e4431de6ed023ad3 100644 (file)
@@ -1129,6 +1129,21 @@ void Model_Document::redo()
   // update the current features status
   setCurrentFeature(currentFeature(false), false);
 }
+
+void Model_Document::clearUndoRedo()
+{
+  myNestedNum.clear();
+  myTransactions.clear();
+  myRedos.clear();
+  myTransactionSave = 0;
+  myDoc->ClearUndos();
+  myDoc->ClearRedos();
+  // clear for all subs
+  const std::set<int> aSubs = subDocuments();
+  for (std::set<int>::iterator aSubIter = aSubs.begin(); aSubIter != aSubs.end(); aSubIter++)
+    subDoc(*aSubIter)->clearUndoRedo();
+}
+
 // this is used for creation of undo/redo1-list by GUI
 // LCOV_EXCL_START
 std::list<std::string> Model_Document::undoList() const
index 264fdf3070d96281fed745c601af16053406cb98..c93c694ba09ed3281477273ac0e78475d739e8d8 100644 (file)
@@ -106,6 +106,8 @@ class Model_Document : public ModelAPI_Document
   MODEL_EXPORT virtual bool canRedo();
   //! Redoes last operation
   MODEL_EXPORT virtual void redo();
+  //! Clears undo/redo lists
+  MODEL_EXPORT virtual void clearUndoRedo();
 
   //! Adds to the document the new feature of the given feature id
   //! \param theID creates feature and puts it in the document
index 6071964562b64a637a18e8aedb50214109f339b0..37224746df949fbab6501ac844ccf2c02bef9e08 100644 (file)
@@ -59,7 +59,9 @@ static Model_Session* myImpl = new Model_Session();
 
 bool Model_Session::load(const char* theFileName)
 {
+  myIsLoading = true;
   bool aRes = ROOT_DOC->load(theFileName, "root", ROOT_DOC);
+  myIsLoading = false;
   return aRes;
 }
 
@@ -178,6 +180,11 @@ std::list<std::string> Model_Session::redoList()
   return ROOT_DOC->redoList();
 }
 
+void Model_Session::clearUndoRedo()
+{
+  return ROOT_DOC->clearUndoRedo();
+}
+
 bool Model_Session::checkLicense(const std::string& thePluginName)
 {
   return getPlugin(thePluginName);
@@ -447,6 +454,7 @@ Model_Session::Model_Session()
 {
   myPluginsInfoLoaded = false;
   myCheckTransactions = true;
+  myIsLoading = false;
   ModelAPI_Session::setSession(std::shared_ptr<ModelAPI_Session>(this));
   // register the configuration reading listener
   Events_Loop* aLoop = Events_Loop::loop();
index f01909bf769a272dc5e879ceff066f89b98e843d..5b300cb25684b0e518ed7f33c381c1acfa18ff94 100644 (file)
@@ -99,6 +99,8 @@ class Model_Session : public ModelAPI_Session, public Events_Listener
   MODEL_EXPORT virtual std::list<std::string> undoList();
   //! Returns stack of rolled back operations
   MODEL_EXPORT virtual std::list<std::string> redoList();
+  //! Clears undo and redo lists of all documents in the session
+  MODEL_EXPORT virtual void clearUndoRedo();
 
   /// Returns the root document of the application (that may contains sub-documents)
   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> moduleDocument();
index 0802986fd84e395c6b95e3cd55bc0ff5ca31b91f..20d90f09cd551802a603c90e0b1e3c44ebd8da4a 100644 (file)
@@ -129,6 +129,10 @@ MAYBE_UNUSED static const char * EVENT_REMOVE_CONSTRAINTS = "RemoveConstrains";
 /// Event ID that license of specified features is checked and valid
 MAYBE_UNUSED static const char * EVENT_FEATURE_LICENSE_VALID = "FeaturesLicenseValid";
 
+/// To send preferences information: create part on init or not
+MAYBE_UNUSED static const char * EVENT_CREATE_PART_ON_START = "CreatePartOnStart";
+
+
 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
 class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
 {
index 42739259ca96f863d932a4b27af4672d54956de9..4cfd45aa6336bdb875661a5b3e73d35e1c663245 100644 (file)
@@ -40,6 +40,9 @@ class ModelAPI_FiltersFactory;
 
 class MODELAPI_EXPORT ModelAPI_Session
 {
+protected:
+  bool myIsLoading; ///< keeps the state of the loading of the document
+
  public:
   /// Returns the real implementation (the alone instance per application) of the plugin manager
   static std::shared_ptr<ModelAPI_Session> get();
@@ -49,6 +52,9 @@ class MODELAPI_EXPORT ModelAPI_Session
   //! \returns true if file was loaded successfully
   virtual bool load(const char* theFileName) = 0;
 
+  //! Returns true if a loading process is performed (so, no need to react on a new part creation)
+  virtual bool isLoading() { return myIsLoading; };
+
   //! Saves the OCAF document to the file.
   //! \param theFileName full name of the file to store
   //! \param theResults the result full file names that were stored by "save"
@@ -86,6 +92,8 @@ class MODELAPI_EXPORT ModelAPI_Session
   virtual std::list<std::string> undoList() = 0;
   //! Returns stack of rolled back operations (from last rolled back to first)
   virtual std::list<std::string> redoList() = 0;
+  //! Clears undo and redo lists of all documents in the session
+  virtual void clearUndoRedo() = 0;
 
   /// Registers the plugin that creates features.
   /// It is obligatory for each plugin to call this function on loading to be found by
index 3d993de00183fbe3796704fa5185f7c33b54665c..fd564548bca2015e115be069c8dbf4f69317cae2 100644 (file)
@@ -25,6 +25,7 @@
 #include <ModelAPI_Document.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_Events.h>
+#include <ModelAPI_ResultPart.h>
 
 #include <cmath>
 #include <sstream>
@@ -108,7 +109,33 @@ void begin()
   }
   std::ostringstream aTransactionName;
   aTransactionName << "Operation_" << aTransactionID;
-  ModelAPI_Session::get()->startOperation(aTransactionName.str());
+       
+  // check the first transaction and part, automatically created on start of PartSet
+  std::shared_ptr<ModelAPI_Session> aSession = ModelAPI_Session::get();
+  if (aSession->undoList().empty() && aSession->redoList().empty() && // no undo/redo available
+      aSession->moduleDocument()->size(ModelAPI_ResultPart::group()) == 1 && // only one part
+      aSession->moduleDocument()->size(ModelAPI_Feature::group()) == 1) // only part feature
+  {
+    ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>
+      (aSession->moduleDocument()->object(ModelAPI_ResultPart::group(), 0));
+    if (aPartRes.get() && aPartRes->isActivated())
+    {
+      DocumentPtr aPartDoc = aPartRes->partDoc();
+      if (aPartDoc.get() && aPartDoc->size(ModelAPI_Feature::group()) == 0) // no features in part
+      {
+        // remove the automtically created part
+        aSession->startOperation("Delete automatic part");
+        FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(
+          aSession->moduleDocument()->object(ModelAPI_Feature::group(), 0));
+        aSession->setActiveDocument(aSession->moduleDocument());
+        aSession->moduleDocument()->removeFeature(aPartFeature);
+        aSession->finishOperation();
+        aSession->clearUndoRedo();
+      }
+    }
+  }
+
+  aSession->startOperation(aTransactionName.str());
 }
 
 void end()
index 669014dda780a75905ebf848e99900d28850dad8..2447aa8b4982e781caa6ba854f357401e2cfb1e2 100644 (file)
@@ -160,57 +160,64 @@ void ModuleBase_Preferences::resetConfigPropPreferences(SUIT_PreferenceMgr* theP
 void ModuleBase_Preferences::createGeneralTab(ModuleBase_IPrefMgr* thePref, int thePageId)
 {
   int generalTab = thePref->addPreference(QObject::tr("General"), thePageId,
-                                          SUIT_PreferenceMgr::Auto, QString(), QString());
+    SUIT_PreferenceMgr::Auto, QString(), QString());
   thePref->setItemProperty("columns", 2, generalTab);
 
   QStringList actItemList;
   actItemList << QObject::tr("Last part")
-              << QObject::tr("All parts")
-              << QObject::tr("No activation");
+    << QObject::tr("All parts")
+    << QObject::tr("No activation");
 
   QList<QVariant> actIdList;
   actIdList << 0 << 1 << 2;
 
-  // Group related to opening a study
-  int group = thePref->addPreference(QObject::tr("Opening a study"), generalTab,
+  // Group related to creation of a study
+  int group = thePref->addPreference(QObject::tr("Creation a study"), generalTab,
                                      SUIT_PreferenceMgr::Auto, QString(), QString());
 
-  int actId = thePref->addPreference(QObject::tr("Activate"), group, SUIT_PreferenceMgr::Selector,
-                                     ModuleBase_Preferences::GENERAL_SECTION,
-                                     "part_activation_study");
-  thePref->setItemProperty("strings", actItemList, actId);
-  thePref->setItemProperty("indexes", actIdList, actId);
+  int actId = thePref->addPreference(QObject::tr("Create new part"), group, SUIT_PreferenceMgr::Bool,
+                                     ModuleBase_Preferences::GENERAL_SECTION, "create_init_part");
+
+  // Group related to running a python script
+  group = thePref->addPreference(QObject::tr("Launching a python script"), generalTab,
+                                 SUIT_PreferenceMgr::Auto, QString(), QString());
 
   QStringList visuItemList;
-  visuItemList << QObject::tr("As stored in HDF")
-               << QObject::tr("Last item in each folder")
+  visuItemList << QObject::tr("Last item in each folder")
                << QObject::tr("All items")
                << QObject::tr("No visualization");
 
   QList<QVariant> visuIdList;
-  visuIdList << 0 << 1 << 2 << 3;
+  visuIdList << 0 << 1 << 2;
 
   int visuId = thePref->addPreference(QObject::tr("Display"), group, SUIT_PreferenceMgr::Selector,
                                       ModuleBase_Preferences::GENERAL_SECTION,
-                                      "part_visualization_study");
+                                      "part_visualization_script");
   thePref->setItemProperty("strings", visuItemList, visuId);
   thePref->setItemProperty("indexes", visuIdList, visuId);
 
-  // Group related to running a python script
-  group = thePref->addPreference(QObject::tr("Launching a python script"), generalTab,
+  // Group related to opening a study
+  group = thePref->addPreference(QObject::tr("Opening a study"), generalTab,
                                  SUIT_PreferenceMgr::Auto, QString(), QString());
 
+  actId = thePref->addPreference(QObject::tr("Activate"), group, SUIT_PreferenceMgr::Selector,
+                                 ModuleBase_Preferences::GENERAL_SECTION,
+                                 "part_activation_study");
+  thePref->setItemProperty("strings", actItemList, actId);
+  thePref->setItemProperty("indexes", actIdList, actId);
+
   visuItemList.clear();
-  visuItemList << QObject::tr("Last item in each folder")
+  visuItemList << QObject::tr("As stored in HDF")
+               << QObject::tr("Last item in each folder")
                << QObject::tr("All items")
                << QObject::tr("No visualization");
 
   visuIdList.clear();
-  visuIdList << 0 << 1 << 2;
+  visuIdList << 0 << 1 << 2 << 3;
 
   visuId = thePref->addPreference(QObject::tr("Display"), group, SUIT_PreferenceMgr::Selector,
                                   ModuleBase_Preferences::GENERAL_SECTION,
-                                  "part_visualization_script");
+                                  "part_visualization_study");
   thePref->setItemProperty("strings", visuItemList, visuId);
   thePref->setItemProperty("indexes", visuIdList, visuId);
 }
index 39de141b138820c2ccda7a1cc011e7fa68faed32..55870dd641f8fa1ac766116368c7f6faffbb9cba 100644 (file)
         <source>General</source>
         <translation>Général</translation>
     </message>
+    <message>
+        <source>Creation a study</source>
+        <translation>Création d&apos;une étude</translation>
+    </message>
+    <message>
+        <source>Create new part</source>
+        <translation>Création d&apos;une nouvelle pièce</translation>
+    </message>
     <message>
         <source>Opening a study</source>
         <translation>Ouverture d&apos;une étude</translation>
index 669abec834207e6fb35e40e86d5c4b788e3a2ff2..8528d7687c194bef7acefa30a8199dfedcd7d4c1 100644 (file)
 #include <SketcherPrs_Tools.h>
 
 #include <Events_Loop.h>
+#include <Events_MessageBool.h>
 #include <Config_PropManager.h>
 #include <Config_Keywords.h>
 
@@ -286,6 +287,13 @@ PartSet_Module::~PartSet_Module()
 void PartSet_Module::createFeatures()
 {
   ModuleBase_IModule::createFeatures();
+
+  // send signal to initialization plugin about the state of the preferences: to create part or not
+  bool aCreate = ModuleBase_Preferences::resourceMgr()->booleanValue(
+    ModuleBase_Preferences::GENERAL_SECTION, "create_init_part", true);
+  Events_MessageBool aCreateMsg(Events_Loop::eventByName(EVENT_CREATE_PART_ON_START), aCreate);
+  aCreateMsg.send();
+
   myRoot = new PartSet_RootNode();
   myRoot->setWorkshop(workshop());
   ModuleBase_IModule::loadProprietaryPlugins();
index daa467a94f7d3b7eef77870808ea5c320d141461..c5702bf206bb46341523fda4359688169d1caad7 100644 (file)
@@ -76,6 +76,7 @@
 #include <QToolBar>
 
 #include <ModelAPI_Session.h>
+#include <Events_MessageBool.h>
 
 #if OCC_VERSION_HEX < 0x070400
   #define SALOME_PATCH_FOR_CTRL_WHEEL
@@ -946,6 +947,8 @@ void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& the
   QString aVal = aResMgr->stringValue(theSection, theParam);
   Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
                                                     theParam.toStdString());
+  if (!aProp)
+    return; // invalid case, the property default value must be registered in XML file
   std::string aValue = aVal.toStdString();
   if (aValue.empty()) {
     aValue = aProp->defaultValue();
@@ -991,6 +994,13 @@ void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& the
       }
     }
   }
+  else if (theSection == ModuleBase_Preferences::GENERAL_SECTION && theParam == "create_init_part") {
+    bool aCreate = ModuleBase_Preferences::resourceMgr()->booleanValue(
+      ModuleBase_Preferences::GENERAL_SECTION, "create_init_part", true);
+    Events_MessageBool aCreateMsg(Events_Loop::eventByName(EVENT_CREATE_PART_ON_START), aCreate);
+    aCreateMsg.send();
+  }
+
   myWorkshop->displayer()->redisplayObjects();
 }
 
index 9aa2e50061b27f141e26eb140112dc6f9a47516b..a288317694d758a8604bf99a9ad2c623fa42f9c9 100644 (file)
@@ -27,6 +27,7 @@
     <parameter name="part_activation_study" value="0"/>
     <parameter name="part_visualization_study" value="0"/>
     <parameter name="part_visualization_script" value="1"/>
+    <parameter name="create_init_part" value="true"/>
   </section>
   <section name="Sketch">
     <!-- Sketch preferences -->
index ed65fcec5c7b7b5448a2d616d08ccc736c8f5a9b..d2ae6680702804e19c1d446ba99d34a5c5e483ba 100644 (file)
@@ -9,6 +9,7 @@
     <parameter name="part_activation_study" value="0"/>
     <parameter name="part_visualization_study" value="0"/>
     <parameter name="part_visualization_script" value="1"/>
+    <parameter name="create_init_part" value="true"/>
   </section>
   <section name="Sketch">
     <!-- Sketch preferences -->
index 67a525988a1da920e62436083d96ecc693507b71..624f6442233e1efdc94170689afdc72cac4ad8e9 100644 (file)
@@ -90,6 +90,7 @@
 #include <Events_Loop.h>
 #include <Events_InfoMessage.h>
 #include <Events_LongOp.h>
+#include <Events_MessageBool.h>
 
 #include <ExchangePlugin_ExportPart.h>
 #include <ExchangePlugin_ImportPart.h>
@@ -1161,6 +1162,12 @@ void XGUI_Workshop::onPreferences()
       } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
         myMainWindow->menuObject()->updateFromResources();
       }
+      else if (aSection == ModuleBase_Preferences::GENERAL_SECTION && aPref.second == "create_init_part") {
+        bool aCreate = ModuleBase_Preferences::resourceMgr()->booleanValue(
+          ModuleBase_Preferences::GENERAL_SECTION, "create_init_part", true);
+        Events_MessageBool aCreateMsg(Events_Loop::eventByName(EVENT_CREATE_PART_ON_START), aCreate);
+        aCreateMsg.send();
+      }
     }
     std::vector<int> aColor;
     try {
index 3041162b1c34b2af8a37b2638fd4a261259ebfe7..7514897c211a56a706dc2a057a5344e89f21ea1d 100644 (file)
@@ -193,10 +193,14 @@ void XGUI_WorkshopListener::processEvent(const std::shared_ptr<Events_Message>&
       if (aWidgetSelector)
         workshop()->selector()->setSelected(aWidgetSelector->getAttributeSelection());
     }
-  } else if (theMessage->eventID() == Events_Loop::eventByName("FinishOperation")/* ||
-             theMessage->eventID() == Events_Loop::eventByName("AbortOperation")*/)
-    workshop()->facesPanel()->reset(false); // do not flush redisplay, it is flushed after event
-
+  }
+  else if (theMessage->eventID() == Events_Loop::eventByName("FinishOperation")/* ||
+          theMessage->eventID() == Events_Loop::eventByName("AbortOperation")*/)
+  {
+    XGUI_FacesPanel* aFacesPanel = workshop()->facesPanel();
+    if (aFacesPanel)
+      aFacesPanel->reset(false); // do not flush redisplay, it is flushed after event
+  }
   //Update property panel on corresponding message. If there is no current operation (no
   //property panel), or received message has different feature to the current - do nothing.
   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {