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
**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**);
Events_Loop.h
Events_LongOp.h
Events_InfoMessage.h
+ Events_MessageBool.h
)
SET(PROJECT_SOURCES
Events_Loop.cpp
Events_LongOp.cpp
Events_InfoMessage.cpp
+ Events_MessageBool.cpp
)
SET(PROJECT_LIBRARIES
--- /dev/null
+// 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);
+}
--- /dev/null
+// 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
#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());
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);
/// 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
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));
}
}
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,
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
+}
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
// 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
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
bool Model_Session::load(const char* theFileName)
{
+ myIsLoading = true;
bool aRes = ROOT_DOC->load(theFileName, "root", ROOT_DOC);
+ myIsLoading = false;
return aRes;
}
return ROOT_DOC->redoList();
}
+void Model_Session::clearUndoRedo()
+{
+ return ROOT_DOC->clearUndoRedo();
+}
+
bool Model_Session::checkLicense(const std::string& thePluginName)
{
return getPlugin(thePluginName);
{
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();
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();
/// 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
{
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();
//! \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"
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
#include <ModelAPI_Document.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_Events.h>
+#include <ModelAPI_ResultPart.h>
#include <cmath>
#include <sstream>
}
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()
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);
}
<source>General</source>
<translation>Général</translation>
</message>
+ <message>
+ <source>Creation a study</source>
+ <translation>Création d'une étude</translation>
+ </message>
+ <message>
+ <source>Create new part</source>
+ <translation>Création d'une nouvelle pièce</translation>
+ </message>
<message>
<source>Opening a study</source>
<translation>Ouverture d'une étude</translation>
#include <SketcherPrs_Tools.h>
#include <Events_Loop.h>
+#include <Events_MessageBool.h>
#include <Config_PropManager.h>
#include <Config_Keywords.h>
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();
#include <QToolBar>
#include <ModelAPI_Session.h>
+#include <Events_MessageBool.h>
#if OCC_VERSION_HEX < 0x070400
#define SALOME_PATCH_FOR_CTRL_WHEEL
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();
}
}
}
+ 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();
}
<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 -->
<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 -->
#include <Events_Loop.h>
#include <Events_InfoMessage.h>
#include <Events_LongOp.h>
+#include <Events_MessageBool.h>
#include <ExchangePlugin_ExportPart.h>
#include <ExchangePlugin_ImportPart.h>
} 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 {
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)) {