Config_PointerMessage.cpp
Config_Common.cpp
Config_ValidatorMessage.cpp
+ Config_Prop.cpp
Config_PropManager.cpp
)
--- /dev/null
+// File: Config_Prop.cpp
+// Created: 18 Sep 2014
+// Author: Mikhail PONIKAROV
+
+
+#include "Config_Prop.h"
+#include "Events_Loop.h"
+#include "Events_Message.h"
+
+void Config_Prop::setValue(const std::string& theValue)
+{
+ if (theValue != myValue) {
+ myValue = theValue;
+ static const Events_ID aChangedEvent = Events_Loop::loop()->eventByName("PreferenceChanged");
+ Events_Loop::loop()->send(boost::shared_ptr<Events_Message>(
+ new Events_Message(aChangedEvent, this)));
+ }
+}
{
return myValue;
}
- void setValue(const std::string& theValue)
- {
- myValue = theValue;
- }
+
+ CONFIG_EXPORT void setValue(const std::string& theValue);
bool operator==(const Config_Prop* theProp) const
{
myLoadedByDemand.insert(theID);
}
+//=======================================================================
+bool Model_Application::isLoadByDemand(std::string theID)
+{
+ return myLoadedByDemand.find(theID) != myLoadedByDemand.end();
+}
+
//=======================================================================
Model_Application::Model_Application()
{
void setLoadPath(std::string thePath);
//! Defines that specified document must be loaded by demand
void setLoadByDemand(std::string theID);
+ //! Returns true if specified document must be loaded by demand
+ bool isLoadByDemand(std::string theID);
public:
// Redefined OCAF methods
#include <Events_Error.h>
#include <TDataStd_Name.hxx>
+#include <TDataStd_UAttribute.hxx>
#include <string>
if (!myLab.IsNull())
myLab.ForgetAllAttributes();
}
+
+Standard_GUID kMustBeUpdatedGUID("baede74c-31a6-4416-9c4d-e48ce65f2005");
+
+void Model_Data::mustBeUpdated(const bool theFlag)
+{
+ if (theFlag)
+ TDataStd_UAttribute::Set(myLab, kMustBeUpdatedGUID);
+ else
+ myLab.ForgetAttribute(kMustBeUpdatedGUID);
+}
+
+bool Model_Data::mustBeUpdated()
+{
+ return myLab.IsAttribute(kMustBeUpdatedGUID) == Standard_True;
+}
}
MODEL_EXPORT virtual void erase();
+
+ /// Makes feature must be updated later (on rebuild). Normally the Updater must call it
+ /// in case of not-automatic update to true
+ MODEL_EXPORT virtual void mustBeUpdated(const bool theFlag);
+
+ /// Returns true if feature must be updated (re-executed) on rebuild
+ MODEL_EXPORT virtual bool mustBeUpdated();
};
#endif
//! Removes information that there is a reference to this object
void objectIsNotReferenced(const ObjectPtr& theObject);
+ //! Returns all sub documents
+ const std::set<std::string>& subDocuments() const {return mySubs;}
+
friend class Model_Application;
friend class Model_Session;
friend class Model_AttributeReference;
}
}
+std::list<boost::shared_ptr<ModelAPI_Document> > Model_Session::allOpenedDocuments()
+{
+ list<boost::shared_ptr<ModelAPI_Document> > aResult;
+ aResult.push_back(moduleDocument());
+ // add subs recursively
+ list<boost::shared_ptr<ModelAPI_Document> >::iterator aDoc = aResult.begin();
+ for(; aDoc != aResult.end(); aDoc++) {
+ DocumentPtr anAPIDoc = *aDoc;
+ boost::shared_ptr<Model_Document> aDoc = boost::dynamic_pointer_cast<Model_Document>(anAPIDoc);
+ if (aDoc) {
+ std::set<std::string>::const_iterator aSubIter = aDoc->subDocuments().cbegin();
+ for(; aSubIter != aDoc->subDocuments().cend(); aSubIter++) {
+ if (!Model_Application::getApplication()->isLoadByDemand(*aSubIter)) {
+ aResult.push_back(Model_Application::getApplication()->getDocument(*aSubIter));
+ }
+ }
+ }
+ }
+ return aResult;
+}
+
boost::shared_ptr<ModelAPI_Document> Model_Session::copy(
boost::shared_ptr<ModelAPI_Document> theSource, std::string theID)
{
/// Defines the current document that used for current work in the application
MODEL_EXPORT virtual void setActiveDocument(boost::shared_ptr<ModelAPI_Document> theDoc);
+ /// Returns all the opened documents of the session (without postponed)
+ MODEL_EXPORT virtual std::list<boost::shared_ptr<ModelAPI_Document> > allOpenedDocuments();
+
/// Registers the plugin that creates features.
/// It is obligatory for each plugin to call this function on loading to be found by
/// the plugin manager on call of the feature)
#include <Events_Loop.h>
#include <Events_LongOp.h>
#include <Events_Error.h>
+#include <Config_PropManager.h>
using namespace std;
Model_Update MY_INSTANCE; /// the only one instance initialized on load of the library
-Model_Update::Model_Update()
+Model_Update::Model_Update() : isCreated(false)
{
+ static const Events_ID kChangedEvent = Events_Loop::loop()->eventByName("PreferenceChanged");
+ Events_Loop::loop()->registerListener(this, kChangedEvent);
+ static const Events_ID kRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
+ Events_Loop::loop()->registerListener(this, kRebuildEvent);
Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ Config_PropManager::registerProp("Model update", "automatic_rebuild", "Rebuild automatically",
+ Config_Prop::Bool, "false");
+ isAutomatic = Config_PropManager::findProp("Model update", "automatic_rebuild")->value() == "true";
}
void Model_Update::processEvent(const boost::shared_ptr<Events_Message>& theMessage)
{
+ static const Events_ID kChangedEvent = Events_Loop::loop()->eventByName("PreferenceChanged");
+ static const Events_ID kRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
+ bool isAutomaticChanged = false;
+ if (theMessage->eventID() == kChangedEvent) { // automatic and manual rebuild flag is changed
+ isAutomatic =
+ Config_PropManager::findProp("Model update", "automatic_rebuild")->value() == "true";
+ } else if (theMessage->eventID() == kRebuildEvent) { // the rebuild command
+ if (isAutomatic == false) {
+ isAutomaticChanged = true;
+ isAutomatic = true;
+ }
+ }
+
if (isExecuted)
return; // nothing to do: it is executed now
+ // execute just created features anyway
+ isCreated = theMessage->eventID() == Events_Loop::eventByName(EVENT_OBJECT_CREATED);
+
//Events_LongOp::start(this);
isExecuted = true;
+ list<boost::shared_ptr<ModelAPI_Document> > aDocs;
boost::shared_ptr<ModelAPI_ObjectUpdatedMessage> aMsg =
boost::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
- myInitial = aMsg->objects();
+ if (aMsg) myInitial = aMsg->objects();
+ else {
+ myInitial.clear();
+ // on change flag all documents must be updated
+ if (isAutomatic) {
+ aDocs = ModelAPI_Session::get()->allOpenedDocuments();
+ }
+ }
// collect all documents involved into the update
- set<boost::shared_ptr<ModelAPI_Document> > aDocs;
set<boost::shared_ptr<ModelAPI_Object> >::iterator aFIter = myInitial.begin();
for (; aFIter != myInitial.end(); aFIter++) {
- aDocs.insert((*aFIter)->document());
+ aDocs.push_back((*aFIter)->document());
}
// iterate all features of features-documents to update them (including hidden)
- set<boost::shared_ptr<ModelAPI_Document> >::iterator aDIter = aDocs.begin();
+ list<boost::shared_ptr<ModelAPI_Document> >::iterator aDIter = aDocs.begin();
for (; aDIter != aDocs.end(); aDIter++) {
int aNbFeatures = (*aDIter)->size(ModelAPI_Feature::group(), true);
for (int aFIndex = 0; aFIndex < aNbFeatures; aFIndex++) {
static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
Events_Loop::loop()->flush(EVENT_DISP);
//Events_LongOp::end(this);
+ if (isAutomaticChanged) isAutomatic = false;
+ isCreated = false;
isExecuted = false;
}
// check all features this feature depended on (recursive call of updateFeature)
bool aMustbeUpdated = myInitial.find(theFeature) != myInitial.end();
if (theFeature) { // only real feature contains references to other objects
+ if (theFeature->data()->mustBeUpdated()) aMustbeUpdated = true;
// references
list<boost::shared_ptr<ModelAPI_Attribute> > aRefs = theFeature->data()->attributes(
ModelAPI_AttributeReference::type());
!theFeature->isPersistentResult()) {
ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
if (aFactory->validate(theFeature)) {
- try {
- theFeature->execute();
- } catch(...) {
- Events_Error::send(
- "Feature " + theFeature->getKind() + " has failed during the execution");
- theFeature->eraseResults();
+ if (isAutomatic || (isCreated && myInitial.find(theFeature) != myInitial.end()) ||
+ !theFeature->isPersistentResult() /* execute quick, not persistent results */) {
+ try {
+ theFeature->execute();
+ theFeature->data()->mustBeUpdated(false);
+ } catch(...) {
+ Events_Error::send(
+ "Feature " + theFeature->getKind() + " has failed during the execution");
+ theFeature->eraseResults();
+ }
+ } else {
+ theFeature->data()->mustBeUpdated(true);
+ aMustbeUpdated = false;
}
} else {
theFeature->eraseResults();
*/
class Model_Update : public Events_Listener
{
- ///< initial set of updated features that must be processed
+ /// initial set of updated features that must be processed
std::set<boost::shared_ptr<ModelAPI_Object> > myInitial;
- ///< already updated and processed features and modificated feature flag
+ /// already updated and processed features and modificated feature flag
std::map<boost::shared_ptr<ModelAPI_Object>, bool> myUpdated;
- ///< to know that all next updates are caused by this execution
+ /// to know that all next updates are caused by this execution
bool isExecuted;
+ /// to know execute or not automatically all update
+ bool isAutomatic;
+ /// execute just created features for sure
+ bool isCreated;
+
public:
/// Is called only once, on startup of the application
Model_Update();
{
}
+ /// Makes feature must be updated later (on rebuild). Normally the Updater must call it
+ /// in case of not-automatic update to true
+ virtual void mustBeUpdated(const bool theFlag) = 0;
+
+ /// Returns true if feature must be updated (re-executed) on rebuild
+ virtual bool mustBeUpdated() = 0;
+
protected:
/// Objects are created for features automatically
ModelAPI_Data()
//! \param theIndex zero-based index of feature in the group
//! \param theHidden if it is true, it counts also the features that are not in tree
virtual boost::shared_ptr<ModelAPI_Object>
- object(const std::string& theGroupID, const int theIndex, const bool theHidden = false) = 0;
+ object(const std::string& theGroupID, const int theIndex, const bool theHidden = false) = 0;
//! Returns the number of objects in the group of objects
//! If theHidden is true, it counts also the features that are not in tree
/// Defines the current document that used for current work in the application
virtual void setActiveDocument(boost::shared_ptr<ModelAPI_Document> theDoc) = 0;
+ /// Returns all the opened documents of the session (without postponed)
+ virtual std::list<boost::shared_ptr<ModelAPI_Document> > allOpenedDocuments() = 0;
+
/// Copies the document to the new one with the given id
virtual boost::shared_ptr<ModelAPI_Document> copy(boost::shared_ptr<ModelAPI_Document> theSource,
std::string theID) = 0;
aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
QIcon(":pictures/rebuild.png"));
+ aCommand->connectTo(this, SLOT(onRebuild()));
aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
QIcon(":pictures/save.png"));
updateCommandStatus();
}
+//******************************************************
+void XGUI_Workshop::onRebuild()
+{
+ static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
+ Events_Loop::loop()->send(boost::shared_ptr<Events_Message>(
+ new Events_Message(aRebuildEvent, this)));
+}
+
//******************************************************
void XGUI_Workshop::onPreferences()
{
void onExit();
void onUndo();
void onRedo();
+ void onRebuild();
void onPreferences();
void showPropertyPanel();