Model_Application.h
Model_Document.h
Model_PluginManager.h
- Model_Feature.h
+ Model_Object.h
+ Model_Iterator.h
+ Model_AttributeDocRef.h
)
SET(PROJECT_SOURCES
Model_Application.cxx
Model_Document.cxx
Model_PluginManager.cxx
- Model_Feature.cxx
+ Model_Object.cxx
+ Model_Iterator.cxx
+ Model_AttributeDocRef.cxx
)
ADD_DEFINITIONS(-DMODEL_EXPORTS ${CAS_DEFINITIONS})
if (myDocs.find(theDocID) != myDocs.end())
return myDocs[theDocID];
- std::shared_ptr<Model_Document> aNew(new Model_Document);
+ std::shared_ptr<Model_Document> aNew(new Model_Document(theDocID));
myDocs[theDocID] = aNew;
return aNew;
}
--- /dev/null
+// File: ModelAPI_AttributeDocRef.cxx
+// Created: 2 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#include "Model_AttributeDocRef.h"
+#include "Model_Application.h"
+
+using namespace std;
+
+void Model_AttributeDocRef::setValue(std::shared_ptr<ModelAPI_Document> theDoc)
+{
+ myComment->Set(TCollection_ExtendedString(theDoc->id().c_str()));
+}
+
+std::shared_ptr<ModelAPI_Document> Model_AttributeDocRef::value()
+{
+ if (myComment->Get().Length())
+ return Model_Application::getApplication()->getDocument(
+ TCollection_AsciiString(myComment->Get()).ToCString());
+ // not initialized
+ return std::shared_ptr<ModelAPI_Document>();
+}
+
+Model_AttributeDocRef::Model_AttributeDocRef(TDF_Label& theLabel)
+{
+ // check the attribute could be already presented in this doc (after load document)
+ if (!theLabel.FindAttribute(TDataStd_Comment::GetID(), myComment)) {
+ // create attribute: not initialized by value yet, just empty string
+ myComment = TDataStd_Comment::Set(theLabel, "");
+ }
+}
--- /dev/null
+// File: Model_AttributeDocRef.h
+// Created: 2 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef Model_AttributeDocRef_HeaderFile
+#define Model_AttributeDocRef_HeaderFile
+
+#include "Model.h"
+#include "ModelAPI_AttributeDocRef.h"
+#include <TDataStd_Comment.hxx>
+#include <TDF_Label.hxx>
+
+/**\class Model_AttributeDocRef
+ * \ingroup DataModel
+ * \brief Attribute that contains reference to another document.
+ */
+
+class MODEL_EXPORT Model_AttributeDocRef : public ModelAPI_AttributeDocRef
+{
+ Handle_TDataStd_Comment myComment; ///< reference to document is identified as string-id
+public:
+ /// Defines the document referenced from this attribute
+ virtual void setValue(std::shared_ptr<ModelAPI_Document> theDoc);
+
+ /// Returns document referenced from this attribute
+ virtual std::shared_ptr<ModelAPI_Document> value();
+
+protected:
+ /// Initializes attibutes
+ Model_AttributeDocRef(TDF_Label& theLabel);
+
+ friend class Model_Object;
+};
+
+#endif
// Author: Mikhail PONIKAROV
#include <Model_Document.h>
-#include <Model_Feature.h>
+#include <ModelAPI_Feature.h>
+#include <Model_Object.h>
+#include <Model_Application.h>
+#include <Model_PluginManager.h>
+#include <Model_Iterator.h>
#include <TDataStd_Integer.hxx>
+#include <TDataStd_Comment.hxx>
static const int UNDO_LIMIT = 10; // number of possible undo operations
using namespace std;
-bool Model_Document::Load(const char* theFileName)
+bool Model_Document::load(const char* theFileName)
{
bool myIsError = Standard_False;
/*
return !myIsError;
}
-bool Model_Document::Save(const char* theFileName)
+bool Model_Document::save(const char* theFileName)
{
bool myIsError = true;
/*
return !myIsError;
}
-void Model_Document::Close()
+void Model_Document::close()
{
myDoc->Close();
}
-void Model_Document::StartOperation()
+void Model_Document::startOperation()
{
myDoc->NewCommand();
}
-void Model_Document::FinishOperation()
+void Model_Document::finishOperation()
{
myDoc->CommitCommand();
myTransactionsAfterSave++;
}
-void Model_Document::AbortOperation()
+void Model_Document::abortOperation()
{
myDoc->AbortCommand();
}
-bool Model_Document::IsOperation()
+bool Model_Document::isOperation()
{
return myDoc->HasOpenCommand() == Standard_True ;
}
-bool Model_Document::IsModified()
+bool Model_Document::isModified()
{
return myTransactionsAfterSave != 0;
}
-bool Model_Document::CanUndo()
+bool Model_Document::canUndo()
{
return myDoc->GetAvailableUndos() > 0;
}
-void Model_Document::Undo()
+void Model_Document::undo()
{
myDoc->Undo();
myTransactionsAfterSave--;
}
-bool Model_Document::CanRedo()
+bool Model_Document::canRedo()
{
return myDoc->GetAvailableRedos() > 0;
}
-void Model_Document::Redo()
+void Model_Document::redo()
{
myDoc->Redo();
myTransactionsAfterSave++;
}
-void Model_Document::AddObject(
- std::shared_ptr<ModelAPI_Feature> theFeature, const int theGroupID)
+void Model_Document::addFeature(
+ std::shared_ptr<ModelAPI_Feature> theFeature, const std::string theGroupID)
{
- std::shared_ptr<Model_Feature> aModelFeature =
- std::dynamic_pointer_cast<Model_Feature>(theFeature);
- if (aModelFeature) {
- TDF_Label aGroupLab = myDoc->Main().FindChild(TAG_OBJECTS).FindChild(theGroupID + 1);
- TDF_Label anObjLab = aGroupLab.NewChild();
- aModelFeature->setLabel(anObjLab);
+ TDF_Label aGroupLab = groupLabel(theGroupID);
+ TDF_Label anObjLab = aGroupLab.NewChild();
+ std::shared_ptr<Model_Object> aData(new Model_Object);
+ aData->setLabel(anObjLab);
+ theFeature->setData(aData);
+ setUniqueName(theFeature, theGroupID);
+ theFeature->initAttributes();
+ TDataStd_Comment::Set(anObjLab, theFeature->getKind().c_str());
+}
+
+std::shared_ptr<ModelAPI_Feature> Model_Document::feature(TDF_Label& theLabel)
+{
+ Handle(TDataStd_Comment) aFeatureID;
+ if (theLabel.FindAttribute(TDataStd_Comment::GetID(), aFeatureID)) {
+ string anID(TCollection_AsciiString(aFeatureID->Get()).ToCString());
+ std::shared_ptr<ModelAPI_Feature> aResult = Model_PluginManager::get()->createFeature(anID);
+ std::shared_ptr<Model_Object> aData(new Model_Object);
+ aData->setLabel(theLabel);
+ aResult->setData(aData);
+ aResult->initAttributes();
+ return aResult;
}
+ return std::shared_ptr<ModelAPI_Feature>(); // not found
+}
+
+shared_ptr<ModelAPI_Document> Model_Document::subDocument(string theDocID)
+{
+ return Model_Application::getApplication()->getDocument(theDocID);
+}
+
+shared_ptr<ModelAPI_Iterator> Model_Document::featuresIterator(const string theGroup)
+{
+ shared_ptr<Model_Document> aThis(Model_Application::getApplication()->getDocument(myID));
+ return shared_ptr<ModelAPI_Iterator>(new Model_Iterator(aThis, groupLabel(theGroup)));
}
-Model_Document::Model_Document()
- : myDoc(new TDocStd_Document("BinOcaf")) // binary OCAF format
+Model_Document::Model_Document(const std::string theID)
+ : myID(theID), myDoc(new TDocStd_Document("BinOcaf")) // binary OCAF format
{
myDoc->SetUndoLimit(UNDO_LIMIT);
myTransactionsAfterSave = 0;
}
-Model_Document::~Model_Document()
+TDF_Label Model_Document::groupLabel(const string theGroup)
+{
+ if (myGroups.find(theGroup) == myGroups.end()) {
+ myGroups[theGroup] = myDoc->Main().FindChild(TAG_OBJECTS).NewChild();
+ }
+ return myGroups[theGroup];
+}
+
+void Model_Document::setUniqueName(
+ shared_ptr<ModelAPI_Feature> theFeature, const string theGroupID)
{
+ // first count all objects of such kind to start with index = count + 1
+ int aNumObjects = 0;
+ shared_ptr<ModelAPI_Iterator> anIter = featuresIterator(theGroupID);
+ for(; anIter->More(); anIter->Next()) {
+ if (anIter->CurrentKind() == theFeature->getKind())
+ aNumObjects++;
+ }
+ // generate candidate name
+ stringstream aNameStream;
+ aNameStream<<theFeature->getKind()<<"_"<<aNumObjects + 1;
+ string aName = aNameStream.str();
+ // check this is unique, if not, increase index by 1
+ for(anIter = featuresIterator(theGroupID); anIter->More();) {
+ if (anIter->CurrentName() == aName) {
+ aNumObjects++;
+ stringstream aNameStream;
+ aNameStream<<theFeature->getKind()<<"_"<<aNumObjects + 1;
+ // reinitialize iterator to make sure a new name is unique
+ anIter = featuresIterator(theGroupID);
+ } else anIter->Next();
+ }
+
+ theFeature->data()->setName(aName);
}
-// File: Model_Document.cxx
+// File: Model_Document.h
// Created: 28 Feb 2014
// Author: Mikhail PONIKAROV
#include <Model.h>
#include <ModelAPI_Document.h>
#include <TDocStd_Document.hxx>
+#include <map>
class Handle_Model_Document;
{
public:
- //! Creates new document with binary file format
- Model_Document();
- //! Deletes all high-level data, managed this document
- ~Model_Document();
-
//! Loads the OCAF document from the file.
//! \param theFileName full name of the file to load
//! \param theStudyID identifier of the SALOME study to associate with loaded file
//! \returns true if file was loaded successfully
- MODEL_EXPORT bool Load(const char* theFileName);
+ MODEL_EXPORT bool load(const char* theFileName);
//! Saves the OCAF document to the file.
//! \param theFileName full name of the file to store
//! \returns true if file was stored successfully
- MODEL_EXPORT bool Save(const char* theFileName);
+ MODEL_EXPORT bool save(const char* theFileName);
//! Removes document data
- MODEL_EXPORT void Close();
+ MODEL_EXPORT void close();
//! Starts a new operation (opens a tansaction)
- MODEL_EXPORT void StartOperation();
+ MODEL_EXPORT void startOperation();
//! Finishes the previously started operation (closes the transaction)
- MODEL_EXPORT void FinishOperation();
+ MODEL_EXPORT void finishOperation();
//! Aborts the operation
- MODEL_EXPORT void AbortOperation();
+ MODEL_EXPORT void abortOperation();
//! Returns true if operation has been started, but not yet finished or aborted
- MODEL_EXPORT bool IsOperation();
+ MODEL_EXPORT bool isOperation();
//! Returns true if document was modified (since creation/opening)
- MODEL_EXPORT bool IsModified();
+ MODEL_EXPORT bool isModified();
//! Returns True if there are available Undos
- MODEL_EXPORT bool CanUndo();
+ MODEL_EXPORT bool canUndo();
//! Undoes last operation
- MODEL_EXPORT void Undo();
+ MODEL_EXPORT void undo();
//! Returns True if there are available Redos
- MODEL_EXPORT bool CanRedo();
+ MODEL_EXPORT bool canRedo();
//! Redoes last operation
- MODEL_EXPORT void Redo();
+ MODEL_EXPORT void redo();
- //! Adds to the document the new object of the given group id
+ //! Adds to the document the new feature of the given group id
//! \param theFeature a feature object that will be connected to the document in this method
//! \param theGroupID identifier of the groups of objects (must be greater than zero)
- MODEL_EXPORT virtual void AddObject(std::shared_ptr<ModelAPI_Feature> theFeature,
- const int theGroupID);
+ MODEL_EXPORT virtual void addFeature(std::shared_ptr<ModelAPI_Feature> theFeature,
+ const std::string theGroupID);
+
+ //! Returns the existing feature by the label
+ //! \param theLabel base label of the feature
+ MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Feature> feature(TDF_Label& theLabel);
+
+ //! Adds a new sub-document by the identifier, or returns existing one if it is already exist
+ MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> subDocument(std::string theDocID);
+
+ //! Creates an iterator of the features by the specific groups
+ MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Iterator> featuresIterator(
+ const std::string theGroup);
+
+ MODEL_EXPORT virtual const std::string& id() const {return myID;}
protected:
+ //! Returns (creates if needed) the group label
+ TDF_Label groupLabel(const std::string theGroup);
+
+ //! Initializes feature with a unique name in this group (unique name is generated as
+ //! feature type + "_" + index
+ void setUniqueName(
+ std::shared_ptr<ModelAPI_Feature> theFeature, const std::string theGroupID);
+
+ //! Creates new document with binary file format
+ Model_Document(const std::string theID);
+
+ friend class Model_Application;
+
private:
+ std::string myID; ///< identifier of the document in the application
Handle_TDocStd_Document myDoc; ///< OCAF document
int myTransactionsAfterSave; ///< number of transactions after the last "save" call, used for "IsModified" method
+ std::map<std::string, TDF_Label> myGroups; ///< root labels of the features groups identified by names
};
#endif
+++ /dev/null
-// File: Model_Feature.hxx
-// Created: 21 Mar 2014
-// Author: Mikhail PONIKAROV
-
-#include <Model_Feature.h>
-
-using namespace std;
-
-Model_Feature::Model_Feature()
-{
-}
-
-void Model_Feature::setLabel(TDF_Label& theLab)
-{
- myLab = theLab;
-}
+++ /dev/null
-// File: Model_Feature.hxx
-// Created: 21 Mar 2014
-// Author: Mikhail PONIKAROV
-
-#ifndef Model_Feature_HeaderFile
-#define Model_Feature_HeaderFile
-
-#include "Model.h"
-#include <ModelAPI_Feature.h>
-#include <TDF_Label.hxx>
-
-/**\class Model_Feature
- * \ingroup DataModel
- * \brief General object of the application that allows
- * to get/set attributes from the document and compute result of an operation.
- */
-
-class Model_Feature: public ModelAPI_Feature
-{
- TDF_Label myLab; ///< label of the feature in the document
-
- Model_Feature();
- friend class Model_PluginManager;
-public:
- /// Returns the kind of a feature (like "Point")
- virtual std::string GetKind() = 0;
-
- void setLabel(TDF_Label& theLab);
-};
-
-#endif
--- /dev/null
+// File: Model_Iterator.hxx
+// Created: 1 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#include "Model_Iterator.h"
+#include "Model_Document.h"
+#include <TDataStd_Comment.hxx>
+#include <TDataStd_Name.hxx>
+
+using namespace std;
+
+void Model_Iterator::Next()
+{
+ return myIter.Next();
+}
+
+bool Model_Iterator::More()
+{
+ return myIter.More();
+}
+
+shared_ptr<ModelAPI_Feature> Model_Iterator::Current()
+{
+ TDF_Label aLab = myIter.Value()->Label();
+ return myDoc->feature(aLab);
+}
+
+string Model_Iterator::CurrentKind()
+{
+ return string(TCollection_AsciiString(
+ Handle(TDataStd_Comment)::DownCast(myIter.Value())->Get()).ToCString());
+}
+
+string Model_Iterator::CurrentName()
+{
+ TDF_Label aLab = myIter.Value()->Label();
+ Handle(TDataStd_Name) aName;
+ if (aLab.FindAttribute(TDataStd_Name::GetID(), aName))
+ return string(TCollection_AsciiString(aName->Get()).ToCString());
+ return ""; // name is not found
+}
+
+Model_Iterator::Model_Iterator(std::shared_ptr<Model_Document> theDoc, TDF_Label theLab)
+ : myDoc(theDoc), myIter(theLab, TDataStd_Comment::GetID(), Standard_False)
+{}
--- /dev/null
+// File: Model_Iterator.h
+// Created: 1 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef Model_Iterator_HeaderFile
+#define Model_Iterator_HeaderFile
+
+#include "Model.h"
+#include "ModelAPI_Iterator.h"
+#include <TDF_Label.hxx>
+#include <TDF_ChildIDIterator.hxx>
+
+class Model_Document;
+
+/**\class Model_Iterator
+ * \ingroup DataModel
+ * \brief Allows to iterate features of the document. Is created by the document
+ * (see method featuresIterator).
+ */
+
+class MODEL_EXPORT Model_Iterator : public ModelAPI_Iterator
+{
+ std::shared_ptr<Model_Document> myDoc; ///< the document of iterated objects
+ TDF_ChildIDIterator myIter; ///< iterator of the features-labels
+public:
+ /// Iterates to the next feature
+ virtual void Next();
+ /// Returns true if the current iteration is valid and next iteration is possible
+ virtual bool More();
+ /// Returns the currently iterated feature
+ virtual std::shared_ptr<ModelAPI_Feature> Current();
+ /// Returns the kind of the current feature (faster than Current()->getKind())
+ virtual std::string CurrentKind();
+ /// Returns the name of the current feature (faster than Current()->getName())
+ virtual std::string CurrentName();
+
+protected:
+ /// Initializes iterator
+ /// \param theDoc document where the iteration is performed
+ /// \param theLab label of the features group to iterate
+ Model_Iterator(std::shared_ptr<Model_Document> theDoc, TDF_Label theLab);
+
+ friend class Model_Document;
+};
+
+#endif
--- /dev/null
+// File: Model_Object.hxx
+// Created: 21 Mar 2014
+// Author: Mikhail PONIKAROV
+
+#include <Model_Object.h>
+#include <Model_AttributeDocRef.h>
+#include <TDataStd_Name.hxx>
+
+using namespace std;
+
+Model_Object::Model_Object()
+{
+}
+
+void Model_Object::setLabel(TDF_Label& theLab)
+{
+ myLab = theLab;
+}
+
+string Model_Object::getName()
+{
+ Handle(TDataStd_Name) aName;
+ if (myLab.FindAttribute(TDataStd_Name::GetID(), aName))
+ return string(TCollection_AsciiString(aName->Get()).ToCString());
+ return ""; // not defined
+}
+
+void Model_Object::setName(string theName)
+{
+ TDataStd_Name::Set(myLab, theName.c_str());
+}
+
+void Model_Object::addAttribute(string theID, string theAttrType)
+{
+ TDF_Label anAttrLab = myLab.FindChild(myAttrs.size() + 1);
+ ModelAPI_Attribute* anAttr = 0;
+ if (theAttrType == ModelAPI_AttributeDocRef::type())
+ anAttr = new Model_AttributeDocRef(anAttrLab);
+ if (anAttr)
+ myAttrs[theID] = std::shared_ptr<ModelAPI_Attribute>(anAttr);
+ else
+ ; // TODO: generate error on unknown attribute request and/or add mechanism for customization
+}
+
+shared_ptr<ModelAPI_AttributeDocRef> Model_Object::docRef(const string theID)
+{
+ map<string, shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ if (aFound == myAttrs.end()) {
+ // TODO: generate error on unknown attribute request and/or add mechanism for customization
+ return std::shared_ptr<ModelAPI_AttributeDocRef>();
+ }
+ shared_ptr<ModelAPI_AttributeDocRef> aRes =
+ dynamic_pointer_cast<ModelAPI_AttributeDocRef>(aFound->second);
+ if (!aRes) {
+ // TODO: generate error on invalid attribute type request
+ }
+ return aRes;
+}
--- /dev/null
+// File: Model_Object.hxx
+// Created: 21 Mar 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef Model_Object_HeaderFile
+#define Model_Object_HeaderFile
+
+#include "Model.h"
+#include <ModelAPI_Object.h>
+#include <TDF_Label.hxx>
+
+#include <map>
+
+class ModelAPI_Attribute;
+
+/**\class Model_Object
+ * \ingroup DataModel
+ * \brief General object of the application that allows
+ * to get/set attributes from the document and compute result of an operation.
+ */
+
+class Model_Object: public ModelAPI_Object
+{
+ TDF_Label myLab; ///< label of the feature in the document
+ /// All attributes of the object identified by the attribute ID
+ std::map<std::string, std::shared_ptr<ModelAPI_Attribute> > myAttrs;
+
+ Model_Object();
+
+ friend class Model_Document;
+
+public:
+ /// Returns the name of the feature visible by the user in the object browser
+ virtual std::string getName();
+ /// Defines the name of the feature visible by the user in the object browser
+ virtual void setName(std::string theName);
+ /// Returns the attribute that references to another document
+ std::shared_ptr<ModelAPI_AttributeDocRef> docRef(const std::string theID);
+
+ /// Initializes object by the attributes: must be called just after the object is created
+ /// for each attribute of the object
+ /// \param theID identifier of the attribute that can be referenced by this ID later
+ /// \param theAttrType type of the created attribute (received from the type method)
+ virtual void addAttribute(std::string theID, std::string theAttrType);
+
+ /// Puts feature to the document data sub-structure
+ void setLabel(TDF_Label& theLab);
+};
+
+#endif
#include <Model_PluginManager.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Plugin.h>
-#include <Model_Feature.h>
+#include <Model_Object.h>
#include <Model_Document.h>
#include <Model_Application.h>
#include <Event_Loop.h>
if (myPluginObjs.find(myCurrentPluginName) != myPluginObjs.end()) {
std::shared_ptr<ModelAPI_Feature> aCreated =
myPluginObjs[myCurrentPluginName]->createFeature(theFeatureID);
+ return aCreated;
}
}
* plugin contains which feature, loads and stores reference to loaded plugins by
* the feature functionality request.
*/
-
class Model_PluginManager : public ModelAPI_PluginManager, public Event_Listener
{
bool myPluginsInfoLoaded; ///< it true if plugins information is loaded
- /// map of feature IDs to plugin name and object
+ /// map of feature IDs to plugin name
std::map<std::string, std::string> myPlugins;
std::map<std::string, ModelAPI_Plugin*> myPluginObjs; ///< instances of the already plugins
std::string myCurrentPluginName; ///< name of the plugin that must be loaded currently
ModelAPI_PluginManager.h
ModelAPI_Plugin.h
ModelAPI_Feature.h
+ ModelAPI_Iterator.h
+ ModelAPI_Object.h
ModelAPI_Document.h
+ ModelAPI_Attribute.h
+ ModelAPI_AttributeDocRef.h
)
SET(PROJECT_SOURCES
#include "ModelAPI_Document.h"
#include "ModelAPI_PluginManager.h"
#include "ModelAPI_Feature.h"
+ #include "ModelAPI_Object.h"
%}
// to avoid error on this
// standard definitions
%include "typemaps.i"
%include "std_string.i"
+%include <std_shared_ptr.i>
// boost pointers
// %include <boost_shared_ptr.i>
-// %shared_ptr(ModelAPI_PluginManager)
-// %shared_ptr(ModelAPI_Feature)
+%shared_ptr(ModelAPI_Document)
+%shared_ptr(ModelAPI_PluginManager)
+%shared_ptr(ModelAPI_Feature)
+%shared_ptr(ModelAPI_Object)
// all supported interfaces
%include "ModelAPI_Document.h"
%include "ModelAPI_PluginManager.h"
%include "ModelAPI_Feature.h"
+%include "ModelAPI_Object.h"
--- /dev/null
+// File: ModelAPI_Attribute.h
+// Created: 2 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef ModelAPI_Attribute_HeaderFile
+#define ModelAPI_Attribute_HeaderFile
+
+#include "ModelAPI.h"
+#include <string>
+
+/**\class ModelAPI_Attribute
+ * \ingroup DataModel
+ * \brief Generic attribute of the Object.
+ */
+
+class MODELAPI_EXPORT ModelAPI_Attribute
+{
+public:
+
+ /// Returns the type of this class of attributes, not static method
+ virtual std::string attributeType() = 0;
+
+protected:
+ /// Objects are created for features automatically
+ ModelAPI_Attribute()
+ {}
+};
+
+#endif
--- /dev/null
+// File: ModelAPI_AttributeDocRef.h
+// Created: 2 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef ModelAPI_AttributeDocRef_HeaderFile
+#define ModelAPI_AttributeDocRef_HeaderFile
+
+#include "ModelAPI_Attribute.h"
+#include "ModelAPI_Document.h"
+
+/**\class ModelAPI_AttributeDocRef
+ * \ingroup DataModel
+ * \brief Attribute that contains reference to another document.
+ */
+
+class MODELAPI_EXPORT ModelAPI_AttributeDocRef : public ModelAPI_Attribute
+{
+public:
+ /// Defines the document referenced from this attribute
+ virtual void setValue(std::shared_ptr<ModelAPI_Document> theDoc) = 0;
+
+ /// Returns document referenced from this attribute
+ virtual std::shared_ptr<ModelAPI_Document> value() = 0;
+
+ /// Returns the type of this class of attributes
+ static std::string type() {return "DocRef";}
+
+ /// Returns the type of this class of attributes, not static method
+ virtual std::string attributeType() {return type();}
+
+protected:
+ /// Objects are created for features automatically
+ ModelAPI_AttributeDocRef()
+ {}
+};
+
+#endif
#define ModelAPI_Document_HeaderFile
#include <ModelAPI.h>
+#include <string>
#include <memory>
class ModelAPI_Feature;
+class ModelAPI_Iterator;
+
+/// Common groups identifiers
+/// Group of parameters
+static const std::string PARAMETERS_GROUP = "Parameters";
+/// Group of constructions
+static const std::string CONSTRUCTIONS_GROUP = "Construction";
+/// Group of parts
+static const std::string PARTS_GROUP = "Parts";
/**\class Model_Document
* \ingroup DataModel
* Also it provides acces to this data: open/save, transactions management etc.
* to provide access to all stored data.
*/
-
class ModelAPI_Document
{
public:
-
//! Loads the OCAF document from the file.
//! \param theFileName full name of the file to load
//! \param theStudyID identifier of the SALOME study to associate with loaded file
//! \returns true if file was loaded successfully
- MODELAPI_EXPORT virtual bool Load(const char* theFileName) = 0;
+ MODELAPI_EXPORT virtual bool load(const char* theFileName) = 0;
//! Saves the OCAF document to the file.
//! \param theFileName full name of the file to store
//! \returns true if file was stored successfully
- MODELAPI_EXPORT virtual bool Save(const char* theFileName) = 0;
+ MODELAPI_EXPORT virtual bool save(const char* theFileName) = 0;
//! Removes document data
- MODELAPI_EXPORT virtual void Close() = 0;
+ MODELAPI_EXPORT virtual void close() = 0;
//! Starts a new operation (opens a tansaction)
- MODELAPI_EXPORT virtual void StartOperation() = 0;
+ MODELAPI_EXPORT virtual void startOperation() = 0;
//! Finishes the previously started operation (closes the transaction)
- MODELAPI_EXPORT virtual void FinishOperation() = 0;
+ MODELAPI_EXPORT virtual void finishOperation() = 0;
//! Aborts the operation
- MODELAPI_EXPORT virtual void AbortOperation() = 0;
+ MODELAPI_EXPORT virtual void abortOperation() = 0;
//! Returns true if operation has been started, but not yet finished or aborted
- MODELAPI_EXPORT virtual bool IsOperation() = 0;
+ MODELAPI_EXPORT virtual bool isOperation() = 0;
//! Returns true if document was modified (since creation/opening)
- MODELAPI_EXPORT virtual bool IsModified() = 0;
+ MODELAPI_EXPORT virtual bool isModified() = 0;
//! Returns True if there are available Undos
- MODELAPI_EXPORT virtual bool CanUndo() = 0;
+ MODELAPI_EXPORT virtual bool canUndo() = 0;
//! Undoes last operation
- MODELAPI_EXPORT virtual void Undo() = 0;
+ MODELAPI_EXPORT virtual void undo() = 0;
//! Returns True if there are available Redos
- MODELAPI_EXPORT virtual bool CanRedo() = 0;
+ MODELAPI_EXPORT virtual bool canRedo() = 0;
//! Redoes last operation
- MODELAPI_EXPORT virtual void Redo() = 0;
+ MODELAPI_EXPORT virtual void redo() = 0;
- //! Adds to the document the new object of the given group id
+ //! Adds to the document the new feature of the given group id
//! \param theFeature a feature object that will be connected to the document in this method
- //! \param theGroupID identifier of the groups of objects (must be greater than zero)
- MODELAPI_EXPORT virtual void AddObject(std::shared_ptr<ModelAPI_Feature> theFeature,
- const int theGroupID) = 0;
+ //! \param theGroupID identifier of the groups of object
+ MODELAPI_EXPORT virtual void addFeature(std::shared_ptr<ModelAPI_Feature> theFeature,
+ const std::string theGroupID) = 0;
+
+ ///! Adds a new sub-document by the identifier, or returns existing one if it is already exist
+ MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_Document> subDocument(std::string theDocID) = 0;
+
+ ///! Creates an iterator of the features by the specific groups
+ MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_Iterator> featuresIterator(
+ const std::string theGroup) = 0;
+
+ MODELAPI_EXPORT virtual const std::string& id() const = 0;
protected:
/// Only for SWIG wrapping it is here
#include "ModelAPI.h"
#include <string>
+#include <memory>
-class ModelAPI_Feature;
+class ModelAPI_Object;
/**\class ModelAPI_Feature
* \ingroup DataModel
- * \brief General object of the application that allows
- * to get/set attributes from the document and compute result of an operation.
+ * \brief Functionality of the model object: to update result,
+ * to initialize attributes, etc.
*/
class MODELAPI_EXPORT ModelAPI_Feature
{
+ std::shared_ptr<ModelAPI_Object> myData; ///< manager of the data model of a feature
+
public:
/// Returns the kind of a feature (like "Point")
- virtual std::string GetKind() = 0;
+ virtual std::string getKind() = 0;
+
+ /// Request for initialization of data model of the feature: adding all attributes
+ virtual void initAttributes() = 0;
+
+ /// Computes or recomputes the result
+ virtual void execute() = 0;
+
+ /// Returns the data manager of this feature
+ std::shared_ptr<ModelAPI_Object> data() {return myData;}
protected:
/// Use plugin manager for features creation: this method is
/// defined here only for SWIG-wrapping
ModelAPI_Feature()
- {
- }
+ {}
+
+ /// Sets the data manager of an object (document does)
+ void setData(std::shared_ptr<ModelAPI_Object> theData) {myData = theData;}
+ friend class Model_Document;
};
#endif
--- /dev/null
+// File: ModelAPI_Iterator.hxx
+// Created: 1 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef ModelAPI_Iterator_HeaderFile
+#define ModelAPI_Iterator_HeaderFile
+
+#include "ModelAPI.h"
+#include <string>
+#include <memory>
+
+class ModelAPI_Feature;
+class ModelAPI_Document;
+
+/**\class ModelAPI_Iterator
+ * \ingroup DataModel
+ * \brief Allows to iterate features of the document. Is created by the document
+ * (see method featuresIterator).
+ */
+
+class MODELAPI_EXPORT ModelAPI_Iterator
+{
+public:
+ /// Iterates to the next feature
+ virtual void Next() = 0;
+ /// Returns true if the current iteration is valid and next iteration is possible
+ virtual bool More() = 0;
+ /// Returns the currently iterated feature
+ virtual std::shared_ptr<ModelAPI_Feature> Current() = 0;
+ /// Returns the kind of the current feature (faster than Current()->getKind())
+ virtual std::string CurrentKind() = 0;
+ /// Returns the name of the current feature (faster than Current()->getName())
+ virtual std::string CurrentName() = 0;
+
+protected:
+ /// Use plugin manager for features creation: this method is
+ /// defined here only for SWIG-wrapping
+ ModelAPI_Iterator()
+ {}
+};
+
+#endif
--- /dev/null
+// File: ModelAPI_Object.hxx
+// Created: 21 Mar 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef ModelAPI_Object_HeaderFile
+#define ModelAPI_Object_HeaderFile
+
+#include "ModelAPI.h"
+#include <string>
+#include <memory>
+
+class ModelAPI_AttributeDocRef;
+
+/**\class ModelAPI_Object
+ * \ingroup DataModel
+ * \brief General object of the application that allows
+ * to get/set attributes from the document and compute result of an operation.
+ */
+
+class MODELAPI_EXPORT ModelAPI_Object
+{
+public:
+
+ /// Returns the name of the feature visible by the user in the object browser
+ virtual std::string getName() = 0;
+
+ /// Defines the name of the feature visible by the user in the object browser
+ virtual void setName(std::string theName) = 0;
+
+ /// Returns the attribute that references to another document
+ virtual std::shared_ptr<ModelAPI_AttributeDocRef> docRef(const std::string theID) = 0;
+
+ /// Initializes object by the attributes: must be called just after the object is created
+ /// for each attribute of the object
+ /// \param theID identifier of the attribute that can be referenced by this ID later
+ /// \param theAttrType type of the created attribute (received from the type method)
+ virtual void addAttribute(std::string theID, std::string theAttrType) = 0;
+
+protected:
+ /// Objects are created for features automatically
+ ModelAPI_Object()
+ {}
+};
+
+#endif
#include <ModelAPI_Document.h>
// to avoid unresolved ModelAPI_Feature()
#include <ModelAPI_Feature.h>
+// to avoid unresolved ModelAPI_Object()
+#include <ModelAPI_Object.h>
// to avoid unresolved ModelAPI_Plugin()
#include <ModelAPI_Plugin.h>
+// to avoid unresolved ModelAPI_Iterator()
+#include <ModelAPI_Iterator.h>
+// to avoid unresolved ModelAPI_Iterator()
+#include <ModelAPI_Iterator.h>
+// to avoid unresolved ModelAPI_Attribute()
+#include <ModelAPI_Attribute.h>
+// to avoid unresolved ModelAPI_AttributeDocRef()
+#include <ModelAPI_AttributeDocRef.h>
#ifdef WIN32
#include <windows.h>
return aLibName;
}
+// for debug purpose only (cerr), before the error management system is implemented
#include <iostream>
void ModelAPI_PluginManager::loadLibrary(const string theLibName)
{
// Created: 27 Mar 2014
// Author: Mikhail PONIKAROV
-#include "PartSetPlugin_NewPart.hxx"
+#include "PartSetPlugin_NewPart.h"
+#include "ModelAPI_PluginManager.h"
+#include "ModelAPI_Document.h"
+#include "ModelAPI_Object.h"
+#include "ModelAPI_AttributeDocRef.h"
+
+using namespace std;
PartSetPlugin_NewPart::PartSetPlugin_NewPart()
{
}
+
+void PartSetPlugin_NewPart::initAttributes()
+{
+ data()->addAttribute(ModelAPI_AttributeDocRef::type(), PART_DOC_REF);
+}
+
+void PartSetPlugin_NewPart::execute()
+{
+ shared_ptr<ModelAPI_Document> aPartSetDoc = ModelAPI_PluginManager::get()->rootDocument();
+ data()->setName(string("Part_") + "1");
+ aPartSetDoc->subDocument(string("Part_") + "1");
+}
#include "PartSetPlugin.h"
#include <ModelAPI_Feature.h>
+/// part reference attribute
+const std::string PART_DOC_REF = "PartDocument";
+
/**\class PartSetPlugin_NewPart
* \ingroup DataModel
* \brief Feature for creation of the new part in PartSet.
*/
-
class PartSetPlugin_NewPart: public ModelAPI_Feature
{
public:
/// Returns the kind of a feature
- PARTSETPLUGIN_EXPORT virtual std::string GetKind() {return "new_part";}
+ PARTSETPLUGIN_EXPORT virtual std::string getKind() {return "new_part";}
+
+ /// Creates a new part document if needed
+ PARTSETPLUGIN_EXPORT virtual void execute();
+
+ /// Request for initialization of data model of the feature: adding all attributes
+ PARTSETPLUGIN_EXPORT virtual void initAttributes();
/// Use plugin manager for features creation
PartSetPlugin_NewPart();
using namespace std;
-// group identification of the newly created parts in the Part Set document
-const int MY_PARTS_GROUP = 1;
-
// the only created instance of this plugin
static PartSetPlugin_Plugin* MY_INSTANCE = new PartSetPlugin_Plugin();
{
std::shared_ptr<ModelAPI_Feature> aCreated;
if (theFeatureID == "new_part") {
- aCreated = std::shared_ptr<ModelAPI_Feature>(new PartSetPlugin_NewPart());
+ aCreated = std::shared_ptr<ModelAPI_Feature>(new PartSetPlugin_NewPart);
}
// add to a root document for the current moment
if (aCreated)
- ModelAPI_PluginManager::get()->rootDocument()->AddObject(aCreated, MY_PARTS_GROUP);
+ ModelAPI_PluginManager::get()->rootDocument()->addFeature(aCreated, PARTS_GROUP);
// feature of such kind is not found
return aCreated;
}