<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
<plugins module="PartSet">
+ <!-- Initialization plugin must be first here to initialize the PartSet document -->
+ <plugin library="InitializationPlugin"/>
<plugin library="PartSetPlugin" configuration="plugin-PartSet.xml"/>
<plugin library="SketchPlugin" configuration="plugin-Sketch.xml"/>
<plugin library="ConstructionPlugin" configuration="plugin-Construction.xml"/>
<plugin library="FeaturesPlugin" configuration="plugin-Features.xml"/>
<plugin library="ExchangePlugin" configuration="plugin-Exchange.xml"/>
<plugin script="ConnectorPlugin" configuration="plugin-Connector.xml" dependency="Geometry"/>
- <plugin library="InitializationPlugin"/>
<plugin library="SketchSolver"/>
<plugin library="GeomValidators"/>
<plugin library="DFBrowser" internal="true"/>
-
// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
#include <InitializationPlugin_Plugin.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeString.h>
-
+#include <ModelAPI_Events.h>
#include <Events_Message.h>
-
-#include <ModelAPI_Events.h>
-#include <ModelAPI_Session.h>
+#include <Events_Error.h>
#include <memory>
-#ifdef _DEBUG
-#include <iostream>
-#endif
-
// the only created instance of this plugin
static InitializationPlugin_Plugin* MY_INITIALIZATIONPLUGIN_INSTANCE = new InitializationPlugin_Plugin();
InitializationPlugin_Plugin::InitializationPlugin_Plugin()
{
- // register this plugin
- SessionPtr aSession = ModelAPI_Session::get();
- aSession->registerPlugin(this);
-
Events_Loop* aLoop = Events_Loop::loop();
const Events_ID kDocCreatedEvent = ModelAPI_DocumentCreatedMessage::eventId();
aLoop->registerListener(this, kDocCreatedEvent, NULL, true);
}
-FeaturePtr InitializationPlugin_Plugin::createFeature(std::string theFeatureID)
-{
- return FeaturePtr();
-}
-
void InitializationPlugin_Plugin::processEvent(const std::shared_ptr<Events_Message>& theMessage)
{
const Events_ID kDocCreatedEvent = ModelAPI_DocumentCreatedMessage::eventId();
createPlane(aDoc, 1., 0., 0.);
createPlane(aDoc, 0., 1., 0.);
createPlane(aDoc, 0., 0., 1.);
+ // for PartSet it is done outside of the transaction, so explicitly flush this creation
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
} else if (theMessage.get()) {
- #ifdef _DEBUG
- std::cout << "InitializationPlugin_Plugin::processEvent: unhandled message caught: " << std::endl
- << theMessage->eventID().eventText() << std::endl;
- #endif
+ Events_Error::send(
+ std::string("InitializationPlugin_Plugin::processEvent: unhandled message caught: ") +
+ theMessage->eventID().eventText());
}
}
} else if (theC) {
aPlane->data()->setName("X0Y");
}
+ aPlane->setInHistory(aPlane, false); // don't show automatically created feature in the features history
}
void InitializationPlugin_Plugin::createPoint(DocumentPtr theDoc)
aPoint->real("y")->setValue(0.);
aPoint->real("z")->setValue(0.);
aPoint->data()->setName("Origin");
+ aPoint->setInHistory(aPoint, false); // don't show automatically created feature in the features history
}
-
#include <InitializationPlugin.h>
-#include <ModelAPI_Plugin.h>
#include <ModelAPI_Feature.h>
#include <Events_Loop.h>
/**\class InitializationPlugin_Plugin
* TODO: Add documentation
*/
-class INITIALIZATIONPLUGIN_EXPORT InitializationPlugin_Plugin : public ModelAPI_Plugin,
- public Events_Listener
+class INITIALIZATIONPLUGIN_EXPORT InitializationPlugin_Plugin : public Events_Listener
{
public:
InitializationPlugin_Plugin();
~InitializationPlugin_Plugin() {}
- /// Creates the feature object of this plugin by the feature string ID
- virtual FeaturePtr createFeature(std::string theFeatureID);
virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
void createPlane(DocumentPtr theDoc, double theA, double theB, double theC);
static const std::string thePartSetKind("PartSet");
static const std::string thePartKind("Part");
+ bool isRoot = theDocID == "root"; // the document is root
std::shared_ptr<Model_Document> aNew(
- new Model_Document(theDocID, theDocID == "root" ? thePartSetKind : thePartKind));
+ new Model_Document(theDocID, isRoot ? thePartSetKind : thePartKind));
myDocs[theDocID] = aNew;
- Events_ID anId = ModelAPI_DocumentCreatedMessage::eventId();
- std::shared_ptr<ModelAPI_DocumentCreatedMessage> aMessage =
- std::shared_ptr<ModelAPI_DocumentCreatedMessage>(new ModelAPI_DocumentCreatedMessage(anId, this));
- aMessage->setDocument(aNew);
- Events_Loop::loop()->send(aMessage);
// load it if it must be loaded by demand
if (myLoadedByDemand.find(theDocID) != myLoadedByDemand.end() && !myPath.empty()) {
aNew->load(myPath.c_str());
myLoadedByDemand.erase(theDocID); // done, don't do it anymore
+ } else {
+ static Events_ID anId = ModelAPI_DocumentCreatedMessage::eventId();
+ std::shared_ptr<ModelAPI_DocumentCreatedMessage> aMessage = std::shared_ptr
+ <ModelAPI_DocumentCreatedMessage>(new ModelAPI_DocumentCreatedMessage(anId, this));
+ aMessage->setDocument(aNew);
+ Events_Loop::loop()->send(aMessage);
}
return myDocs[theDocID];
FeaturePtr aFeature = ModelAPI_Session::get()->createFeature(theID);
if (!aFeature)
return aFeature;
- std::shared_ptr<Model_Document> aDocToAdd = std::dynamic_pointer_cast<Model_Document>(
- aFeature->documentToAdd());
+ Model_Document* aDocToAdd;
+ if (aFeature->documentToAdd().get()) { // use the customized document to add
+ aDocToAdd = std::dynamic_pointer_cast<Model_Document>(aFeature->documentToAdd()).get();
+ } else { // if customized is not presented, add to "this" document
+ aDocToAdd = this;
+ }
if (aFeature) {
TDF_Label aFeatureLab;
if (!aFeature->isAction()) { // do not add action to the data model
}
/// Appenad to the array of references a new referenced label.
-/// If theIndex is not -1, removes element at thisindex, not theReferenced.
+/// If theIndex is not -1, removes element at this index, not theReferenced.
/// \returns the index of removed element
static int RemoveFromRefArray(TDF_Label theArrayLab, TDF_Label theReferenced, const int theIndex =
-1)
}
}
+void Model_Document::addToHistory(const std::shared_ptr<ModelAPI_Object> theObject)
+{
+ TDF_Label aFeaturesLab = featuresLabel();
+ std::shared_ptr<Model_Data> aData = std::static_pointer_cast<Model_Data>(theObject->data());
+ if (!aData) {
+ return; // not found feature => do not remove
+ }
+ TDF_Label aFeatureLabel = aData->label().Father();
+ // store feature in the history of features array
+ if (theObject->isInHistory()) {
+ AddToRefArray(aFeaturesLab, aFeatureLabel);
+ } else {
+ RemoveFromRefArray(aFeaturesLab, aFeatureLabel);
+ }
+}
+
FeaturePtr Model_Document::feature(TDF_Label& theLabel) const
{
if (myObjs.IsBound(theLabel))
//! Returns the list of Ids of the operations that can be redoed (called for the root document)
std::list<std::string> redoList() const;
+ /// Internally makes document know that feature was removed or added in history after creation
+ MODEL_EXPORT virtual void addToHistory(const std::shared_ptr<ModelAPI_Object> theObject);
+
friend class Model_Application;
friend class Model_Session;
friend class Model_Update;
std::shared_ptr<ModelAPI_Document> Model_Session::moduleDocument()
{
- return std::shared_ptr<ModelAPI_Document>(
+ bool aFirstCall = !Model_Application::getApplication()->hasDocument("root");
+ if (aFirstCall) {
+ // creation of the root document is always outside of the transaction, so, avoid checking it
+ setCheckTransactions(false);
+ }
+ std::shared_ptr<ModelAPI_Document> aDoc = std::shared_ptr<ModelAPI_Document>(
Model_Application::getApplication()->getDocument("root"));
+ if (aFirstCall) {
+ // creation of the root document is always outside of the transaction, so, avoid checking it
+ setCheckTransactions(true);
+ }
+ return aDoc;
}
std::shared_ptr<ModelAPI_Document> Model_Session::document(std::string theDocID)
protected:
/// Only for SWIG wrapping it is here
MODELAPI_EXPORT ModelAPI_Document();
+
+ /// Internally makes document know that feature was removed or added in history after creation
+ MODELAPI_EXPORT virtual void addToHistory(const std::shared_ptr<ModelAPI_Object> theObject) = 0;
+
+ friend class ModelAPI_Object; // to add or remove from the history
};
//! Pointer on document object
std::shared_ptr<ModelAPI_Document> ModelAPI_Feature::documentToAdd()
{
- return ModelAPI_Session::get()->activeDocument();
+ // null pointer t ouse the current document
+ return std::shared_ptr<ModelAPI_Document>();
}
void ModelAPI_Feature::erase()
}
/// Must return document where the new feature must be added to
- /// By default it is current document
+ /// By default it is null document: it is added to the document this method is called to
MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_Document> documentToAdd();
/// To virtually destroy the fields of successors
// Author: Mikhail PONIKAROV
#include "ModelAPI_Object.h"
-
+#include "ModelAPI_Document.h"
bool ModelAPI_Object::isInHistory()
{
- return true;
+ return myInHistory;
+}
+
+void ModelAPI_Object::setInHistory(
+ const std::shared_ptr<ModelAPI_Object> theObject, const bool theFlag)
+{
+ if (myInHistory != theFlag) {
+ myInHistory = theFlag;
+ myDoc->addToHistory(theObject);
+ }
}
std::shared_ptr<ModelAPI_Data> ModelAPI_Object::data() const
{
}
+ModelAPI_Object::ModelAPI_Object() : myInHistory(true)
+{
+}
+
ModelAPI_Object::~ModelAPI_Object()
{
}
{
std::shared_ptr<ModelAPI_Data> myData; ///< manager of the data model of a feature
std::shared_ptr<ModelAPI_Document> myDoc; ///< document this object belongs to
+ bool myInHistory; ///< keep the information about the presense of the object in the history tree
public:
/// By default object is displayed in the object browser.
MODELAPI_EXPORT virtual bool isInHistory();
+ /// Makes object presented or not in the history of the created objects
+ /// \param theObject is shared pointer to "this"
+ /// \param theFlag is boolean value: to add or remove from the history
+ MODELAPI_EXPORT virtual void setInHistory(
+ const std::shared_ptr<ModelAPI_Object> theObject, const bool theFlag);
+
/// Returns the data manager of this object: attributes
MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_Data> data() const;
// MODELAPI_EXPORT
MODELAPI_EXPORT virtual void attributeChanged(const std::string& theID);
+ /// Initializes the default states of the object
+ MODELAPI_EXPORT ModelAPI_Object();
+
/// To use virtuality for destructors
MODELAPI_EXPORT virtual ~ModelAPI_Object();