]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'master' of newgeom:newgeom
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 2 Apr 2014 12:40:42 +0000 (16:40 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 2 Apr 2014 12:40:42 +0000 (16:40 +0400)
Conflicts:
src/ModelAPI/CMakeLists.txt

31 files changed:
src/Model/CMakeLists.txt
src/Model/Model_Application.cxx
src/Model/Model_Application.h
src/Model/Model_AttributeDocRef.cxx [new file with mode: 0644]
src/Model/Model_AttributeDocRef.h [new file with mode: 0644]
src/Model/Model_Document.cxx
src/Model/Model_Document.h
src/Model/Model_Feature.cxx [deleted file]
src/Model/Model_Feature.h [deleted file]
src/Model/Model_Iterator.cxx [new file with mode: 0644]
src/Model/Model_Iterator.h [new file with mode: 0644]
src/Model/Model_Object.cxx [new file with mode: 0644]
src/Model/Model_Object.h [new file with mode: 0644]
src/Model/Model_PluginManager.cxx
src/Model/Model_PluginManager.h
src/ModelAPI/CMakeLists.txt
src/ModelAPI/ModelAPI.i
src/ModelAPI/ModelAPI_Attribute.h [new file with mode: 0644]
src/ModelAPI/ModelAPI_AttributeDocRef.h [new file with mode: 0644]
src/ModelAPI/ModelAPI_Document.h
src/ModelAPI/ModelAPI_Feature.h
src/ModelAPI/ModelAPI_Iterator.h [new file with mode: 0644]
src/ModelAPI/ModelAPI_Object.h [new file with mode: 0644]
src/ModelAPI/ModelAPI_Plugin.h
src/ModelAPI/ModelAPI_PluginManager.cxx
src/ModelAPI/ModelAPI_PluginManager.h
src/PartSetPlugin/CMakeLists.txt
src/PartSetPlugin/PartSetPlugin_NewPart.cxx
src/PartSetPlugin/PartSetPlugin_NewPart.h
src/PartSetPlugin/PartSetPlugin_Plugin.cxx
src/PartSetPlugin/PartSetPlugin_Plugin.h

index 42ee4f4c64d9fc1f2895cb1c2b53d3b8cd86917a..ae05dd9268b3fcec9a5dfb9fbc604db90646686e 100644 (file)
@@ -2,22 +2,27 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)
 
 INCLUDE(Common)
 INCLUDE(FindCAS)
-INCLUDE(FindBoost)
 
 SET(PROJECT_HEADERS
     Model.h
+    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} ${BOOST_DEFINITIONS})
+ADD_DEFINITIONS(-DMODEL_EXPORTS ${CAS_DEFINITIONS})
 ADD_LIBRARY(Model SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
 TARGET_LINK_LIBRARIES(Model ${PROJECT_LIBRARIES} ${CAS_OCAF} ModelAPI Event Config)
 
index dab193d13b3cf3a2734c3e8dafea19a93b5f3640..aab352e75c7ecd02a8052759619e1afd879e7462 100644 (file)
@@ -2,8 +2,8 @@
 // Created:    Fri Sep 2 2011
 // Author:     Mikhail PONIKAROV
 
-#include <Model_Application.hxx>
-#include <Model_Document.hxx>
+#include <Model_Application.h>
+#include <Model_Document.h>
 
 IMPLEMENT_STANDARD_HANDLE(Model_Application, TDocStd_Application)
 IMPLEMENT_STANDARD_RTTIEXT(Model_Application, TDocStd_Application)
@@ -14,7 +14,7 @@ static Handle_Model_Application TheApplication = new Model_Application;
 //function : getApplication
 //purpose  : 
 //=======================================================================
-Handle_Model_Application Model_Application::GetApplication()
+Handle(Model_Application) Model_Application::getApplication()
 {
   return TheApplication;
 }
@@ -23,13 +23,14 @@ Handle_Model_Application Model_Application::GetApplication()
 //function : getDocument
 //purpose  : 
 //=======================================================================
-ModelAPI_Document* Model_Application::GetMainDocument()
+std::shared_ptr<Model_Document> Model_Application::getDocument(std::string theDocID)
 {
+  if (myDocs.find(theDocID) != myDocs.end())
+    return myDocs[theDocID];
 
-  if (myMainDoc.IsNull()) {
-    myMainDoc = new Model_Document("BinOcaf");
-  }
-  return *myMainDoc;
+  std::shared_ptr<Model_Document> aNew(new Model_Document(theDocID));
+  myDocs[theDocID] = aNew;
+  return aNew;
 }
 
 //=======================================================================
index 77d669257079fc13b303f0bd4203334cf570a16b..75aa172afbaae4798eac9f331427a73551aa4362 100644 (file)
@@ -6,9 +6,9 @@
 #ifndef Model_Application_HeaderFile
 #define Model_Application_HeaderFile
 
-#include <Model_Document.hxx> 
-#include <ModelAPI_Application.hxx> 
+#include <Model_Document.h> 
 #include <TDocStd_Application.hxx>
+#include <map>
 
 // Define handle class 
 DEFINE_STANDARD_HANDLE(Model_Application, TDocStd_Application)
@@ -19,19 +19,18 @@ DEFINE_STANDARD_HANDLE(Model_Application, TDocStd_Application)
  * Application supports the formats and document management. It is uses OCAF-lke
  * architecture and just implements specific features of the module.
  */
-class Model_Application: public TDocStd_Application, public ModelAPI_Application
+class Model_Application: public TDocStd_Application
 {
 public:
   // useful methods inside of the module
 
   // CASCADE RTTI
-  DEFINE_STANDARD_RTTI(Model_Application)
-  ;
+  DEFINE_STANDARD_RTTI(Model_Application);
 
   //! Retuns the application: one per process    
-  MODEL_EXPORT static Handle_Model_Application GetApplication();
-  //! Returns the main document (on first call creates it)
-  MODEL_EXPORT ModelAPI_Document* GetMainDocument();
+  MODEL_EXPORT static Handle_Model_Application getApplication();
+  //! Returns the main document (on first call creates it) by the string identifier
+  MODEL_EXPORT std::shared_ptr<Model_Document> getDocument(std::string theDocID);
 
 public:
   // Redefined OCAF methods
@@ -46,8 +45,8 @@ public:
   Model_Application();
 
 private:
-
-  Handle_Model_Document myMainDoc; ///< main document of an application
+  /// Map from string identifiers to created documents of an application
+  std::map<std::string, std::shared_ptr<Model_Document> > myDocs;
 };
 
 #endif
diff --git a/src/Model/Model_AttributeDocRef.cxx b/src/Model/Model_AttributeDocRef.cxx
new file mode 100644 (file)
index 0000000..07712d0
--- /dev/null
@@ -0,0 +1,31 @@
+// 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, "");
+  }
+}
diff --git a/src/Model/Model_AttributeDocRef.h b/src/Model/Model_AttributeDocRef.h
new file mode 100644 (file)
index 0000000..2218557
--- /dev/null
@@ -0,0 +1,35 @@
+// 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
index dd34e598b24aeb0e165af8b104c162084fa69c21..6555a22dbefadab02d2c39b052a97ec73bc501dc 100644 (file)
@@ -1,25 +1,26 @@
 // File:        Model_Document.cxx
-// Created:     28 Dec 2011
+// Created:     28 Feb 2014
 // Author:      Mikhail PONIKAROV
-// Copyright:   CEA 2011
 
 #include <Model_Document.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>
 
-IMPLEMENT_STANDARD_HANDLE(Model_Document, MMgt_TShared)
-IMPLEMENT_STANDARD_RTTIEXT(Model_Document, MMgt_TShared)
-
-static const int UNDO_LIMIT = 10; // number of possible undo operations in the module
+static const int UNDO_LIMIT = 10; // number of possible undo operations
 
 static const int TAG_GENERAL = 1; // general properties tag
 static const int TAG_OBJECTS = 2; // tag of the objects sub-tree (Root for Model_ObjectsMgr)
 static const int TAG_HISTORY = 3; // tag of the history sub-tree (Root for Model_History)
-static const int TAG_ISOTOPES = 4; // tag of the isotopes sub-tree (Root for MaterialMC_Isotope)
 
 using namespace std;
 
-bool Model_Document::Load(const char* theFileName)
+bool Model_Document::load(const char* theFileName)
 {
   bool myIsError = Standard_False;
   /*
@@ -60,7 +61,7 @@ bool Model_Document::Load(const char* theFileName)
   return !myIsError;
 }
 
-bool Model_Document::Save(const char* theFileName)
+bool Model_Document::save(const char* theFileName)
 {
   bool myIsError = true;
   /*
@@ -98,66 +99,137 @@ bool Model_Document::Save(const char* theFileName)
   return !myIsError;
 }
 
-void Model_Document::Close()
+void Model_Document::close()
 {
-  TDocStd_Document::Close();
+  myDoc->Close();
 }
 
-void Model_Document::StartOperation()
+void Model_Document::startOperation()
 {
-  TDocStd_Document::NewCommand();
+  myDoc->NewCommand();
 }
 
-void Model_Document::FinishOperation()
+void Model_Document::finishOperation()
 {
-  TDocStd_Document::CommitCommand();
+  myDoc->CommitCommand();
   myTransactionsAfterSave++;
 }
 
-void Model_Document::AbortOperation()
+void Model_Document::abortOperation()
 {
-  TDocStd_Document::AbortCommand();
+  myDoc->AbortCommand();
 }
 
-bool Model_Document::IsOperation()
+bool Model_Document::isOperation()
 {
-  return TDocStd_Document::HasOpenCommand() == Standard_True ;
+  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 TDocStd_Document::GetAvailableUndos() > 0;
+  return myDoc->GetAvailableUndos() > 0;
 }
 
-void Model_Document::Undo()
+void Model_Document::undo()
 {
-  TDocStd_Document::Undo();
+  myDoc->Undo();
   myTransactionsAfterSave--;
 }
 
-bool Model_Document::CanRedo()
+bool Model_Document::canRedo()
 {
-  return TDocStd_Document::GetAvailableRedos() > 0;
+  return myDoc->GetAvailableRedos() > 0;
 }
 
-void Model_Document::Redo()
+void Model_Document::redo()
 {
-  TDocStd_Document::Redo();
+  myDoc->Redo();
   myTransactionsAfterSave++;
 }
 
-Model_Document::Model_Document(const TCollection_ExtendedString& theStorageFormat)
-    : TDocStd_Document(theStorageFormat)
+void Model_Document::addFeature(
+  std::shared_ptr<ModelAPI_Feature> theFeature, const std::string theGroupID)
+{
+  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(const std::string theID)
+    : myID(theID), myDoc(new TDocStd_Document("BinOcaf")) // binary OCAF format
 {
-  SetUndoLimit(UNDO_LIMIT);
+  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);
 }
index bdd5d8e0c510d8d04b28d42b4860da287dfb3180..bc7d6db7422b77c2832bdf815ae936999e0c3374 100644 (file)
@@ -1,7 +1,6 @@
-// File:        Model_Document.hxx
-// Created:     28 Dec 2011
+// File:        Model_Document.h
+// Created:     28 Feb 2014
 // Author:      Mikhail PONIKAROV
-// Copyright:   CEA 2011
 
 #ifndef Model_Document_HeaderFile
 #define Model_Document_HeaderFile
@@ -9,6 +8,7 @@
 #include <Model.h>
 #include <ModelAPI_Document.h>
 #include <TDocStd_Document.hxx>
+#include <map>
 
 class Handle_Model_Document;
 
@@ -21,59 +21,83 @@ class Handle_Model_Document;
  * to provide access to all stored data.
  */
 
-class Model_Document: public TDocStd_Document, public ModelAPI_Document
+class Model_Document: public ModelAPI_Document
 {
 public:
 
-  DEFINE_STANDARD_RTTI(Model_Document)
-  ;
-
-  //! Creates new document by the format string of a storage
-  Model_Document(const TCollection_ExtendedString& theStorageFormat);
-  //! 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 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 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
 };
 
-// Define handle class 
-DEFINE_STANDARD_HANDLE(Model_Document, TDocStd_Document)
-
 #endif
diff --git a/src/Model/Model_Feature.cxx b/src/Model/Model_Feature.cxx
deleted file mode 100644 (file)
index 0ff2838..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-// File:        Model_Feature.hxx
-// Created:     21 Mar 2014
-// Author:      Mikhail PONIKAROV
-
-#include <Model_Feature.h>
-
-using namespace std;
-
-Model_Feature::Model_Feature()
-{
-}
-
-string Model_Feature::GetKind()
-{
-  return "Point";
-}
diff --git a/src/Model/Model_Feature.h b/src/Model/Model_Feature.h
deleted file mode 100644 (file)
index 0b51f72..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-// 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>
-
-/**\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
-{
-  Model_Feature();
-
-  friend class Model_PluginManager;
-public:
-  /// Returns the kind of a feature (like "Point")
-  virtual std::string GetKind();
-};
-
-#endif
diff --git a/src/Model/Model_Iterator.cxx b/src/Model/Model_Iterator.cxx
new file mode 100644 (file)
index 0000000..917d892
--- /dev/null
@@ -0,0 +1,45 @@
+// 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)
+{}
diff --git a/src/Model/Model_Iterator.h b/src/Model/Model_Iterator.h
new file mode 100644 (file)
index 0000000..2ec50ab
--- /dev/null
@@ -0,0 +1,46 @@
+// 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
diff --git a/src/Model/Model_Object.cxx b/src/Model/Model_Object.cxx
new file mode 100644 (file)
index 0000000..7350809
--- /dev/null
@@ -0,0 +1,58 @@
+// 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;
+}
diff --git a/src/Model/Model_Object.h b/src/Model/Model_Object.h
new file mode 100644 (file)
index 0000000..d96f90b
--- /dev/null
@@ -0,0 +1,50 @@
+// 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
index c4e28665dcd82d3e7d086d489d0ca02ac801caeb..f2b7a55947445e063f08d3bc6938144f9afbf627 100644 (file)
@@ -5,7 +5,9 @@
 #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>
 #include <Config_FeatureMessage.h>
 #include <Config_ModuleReader.h>
@@ -14,7 +16,7 @@ using namespace std;
 
 static Model_PluginManager* myImpl = new Model_PluginManager();
 
-boost::shared_ptr<ModelAPI_Feature> Model_PluginManager::createFeature(string theFeatureID)
+std::shared_ptr<ModelAPI_Feature> Model_PluginManager::createFeature(string theFeatureID)
 {
   if (this != myImpl) return myImpl->createFeature(theFeatureID);
 
@@ -26,19 +28,28 @@ boost::shared_ptr<ModelAPI_Feature> Model_PluginManager::createFeature(string th
       loadLibrary(myCurrentPluginName);
     }
     if (myPluginObjs.find(myCurrentPluginName) != myPluginObjs.end()) {
-      return myPluginObjs[myCurrentPluginName]->createFeature(theFeatureID);
+      std::shared_ptr<ModelAPI_Feature> aCreated = 
+        myPluginObjs[myCurrentPluginName]->createFeature(theFeatureID);
+      return aCreated;
     }
   }
 
-  return boost::shared_ptr<ModelAPI_Feature>(); // return nothing
+  return std::shared_ptr<ModelAPI_Feature>(); // return nothing
 }
 
+std::shared_ptr<ModelAPI_Document> Model_PluginManager::rootDocument()
+{
+  return std::shared_ptr<ModelAPI_Document>(
+    Model_Application::getApplication()->getDocument("root"));
+}
+
+
 Model_PluginManager::Model_PluginManager()
 {
   myPluginsInfoLoaded = false;
   static Event_ID aFeatureEvent = Event_Loop::eventByName("RegisterFeature");
 
-  ModelAPI_PluginManager::SetPluginManager(boost::shared_ptr<ModelAPI_PluginManager>(this));
+  ModelAPI_PluginManager::SetPluginManager(std::shared_ptr<ModelAPI_PluginManager>(this));
   // register the configuration reading listener
   Event_Loop* aLoop = Event_Loop::loop();
   aLoop->registerListener(this, aFeatureEvent);
@@ -51,7 +62,7 @@ void Model_PluginManager::processEvent(const Event_Message* theMessage)
   if (aMsg) {
     // proccess the plugin info, load plugin
     if (myPlugins.find(aMsg->id()) == myPlugins.end()) {
-      myPlugins[aMsg->id()] = aMsg->pluginLibrary(); // TO DO: plugin name must be also imported from XMLs
+      myPlugins[aMsg->id()] = aMsg->pluginLibrary();
     }
   }
   // plugins information was started to load, so, it will be loaded
index 5a847abce16589cfe4f65c7c2b274afcbfe8586d..196ebd6ca5a9cb5b7aed6f7e87614ca9b19e12fd 100644 (file)
 #include <Event_Listener.h>
 #include <map>
 
+class Model_Document;
+
 /**\class Model_PluginManager
  * \ingroup DataModel
  * \brief Object that knows (from the initial XML file) which
  * 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
 public:
   /// Creates the feature object using plugins functionality
-  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID);
+  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID);
+
+  /// Returns the root document of the application (that may contains sub-documents)
+  virtual std::shared_ptr<ModelAPI_Document> rootDocument();
 
   /// Registers the plugin that creates features.
   /// It is obligatory for each plugin to call this function on loading to be found by 
index 0013e1b6aaeff539ceea822fb3f5f7d3788edd26..47f665e5375c07044d0c9bc72f0345571953cd92 100644 (file)
@@ -2,7 +2,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)
 
 FIND_PACKAGE(SWIG REQUIRED)
 INCLUDE(${SWIG_USE_FILE})
-INCLUDE(FindBoost)
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
 
 SET(PROJECT_HEADERS
@@ -11,7 +10,11 @@ SET(PROJECT_HEADERS
     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
index 6deac8560d12022d94d480dbdb03a81772a588b1..7490fc63663b4aa05b96e1628b0fe2470a4e7f71 100644 (file)
@@ -5,6 +5,7 @@
   #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>
+// %include <boost_shared_ptr.i>
+%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"
diff --git a/src/ModelAPI/ModelAPI_Attribute.h b/src/ModelAPI/ModelAPI_Attribute.h
new file mode 100644 (file)
index 0000000..cd7d36a
--- /dev/null
@@ -0,0 +1,29 @@
+// 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
diff --git a/src/ModelAPI/ModelAPI_AttributeDocRef.h b/src/ModelAPI/ModelAPI_AttributeDocRef.h
new file mode 100644 (file)
index 0000000..e9a602d
--- /dev/null
@@ -0,0 +1,37 @@
+// 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
index 911aca0680be06183f0093859ee21bebed285c9a..90a6a9184341b7a7c1b0519892ba32aad4c8b39c 100644 (file)
@@ -1,12 +1,24 @@
-// File:        Model_Document.hxx
-// Created:     28 Dec 2011
+// File:        ModelAPI_Document.cxx
+// Created:     28 Feb 2014
 // Author:      Mikhail PONIKAROV
-// Copyright:   CEA 2011
 
 #ifndef ModelAPI_Document_HeaderFile
 #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 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 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
index 2c9339c7410305e9336e93fa85ae8442ff97c44c..a33d05084ea4c88675d15d9b6a653e2ebf9eecdd 100644 (file)
@@ -7,27 +7,42 @@
 
 #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
diff --git a/src/ModelAPI/ModelAPI_Iterator.h b/src/ModelAPI/ModelAPI_Iterator.h
new file mode 100644 (file)
index 0000000..84afc73
--- /dev/null
@@ -0,0 +1,42 @@
+// 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
diff --git a/src/ModelAPI/ModelAPI_Object.h b/src/ModelAPI/ModelAPI_Object.h
new file mode 100644 (file)
index 0000000..490e561
--- /dev/null
@@ -0,0 +1,45 @@
+// 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
index 5d2d0430ceec5c39db9222803d1f184a9869b76c..0605d8b6f1997c5bedc6f5a18b965ec709dc5e71 100644 (file)
@@ -7,7 +7,7 @@
 
 #include "ModelAPI.h"
 #include <string>
-#include <boost/shared_ptr.hpp>
+#include <memory>
 
 class ModelAPI_Feature;
 
@@ -20,7 +20,7 @@ class MODELAPI_EXPORT ModelAPI_Plugin
 {
 public:
   /// Creates the feature object of this plugin by the feature string ID
-  virtual boost::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID) = 0;
+  virtual std::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID) = 0;
 
 protected:
   /// Is needed for python wrapping by swig
index d4a20feaeeed02c0db864f2e2f50e7dc7524ab63..4e9406a9a94c41ab8b19d4caf4e77aa6e4d54d57 100644 (file)
@@ -7,8 +7,18 @@
 #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>
@@ -22,19 +32,19 @@ using namespace std;
 string library(const string& theLibName);
 
 /// Manager that will be initialized from Model package, one per application
-boost::shared_ptr<ModelAPI_PluginManager> MY_MANAGER;
+std::shared_ptr<ModelAPI_PluginManager> MY_MANAGER;
 
 ModelAPI_PluginManager::ModelAPI_PluginManager()
 {
 }
 
 void ModelAPI_PluginManager::SetPluginManager(
-  boost::shared_ptr<ModelAPI_PluginManager> theManager)
+  std::shared_ptr<ModelAPI_PluginManager> theManager)
 {
   MY_MANAGER = theManager;
 }
 
-boost::shared_ptr<ModelAPI_PluginManager> ModelAPI_PluginManager::get()
+std::shared_ptr<ModelAPI_PluginManager> ModelAPI_PluginManager::get()
 {
   if (!MY_MANAGER) { // import Model library that implements this interface of ModelAPI
     loadLibrary("Model");
@@ -62,6 +72,8 @@ string library(const string& theLibName)
   return aLibName;
 }
 
+// for debug purpose only (cerr), before the error management system is implemented
+#include <iostream>
 void ModelAPI_PluginManager::loadLibrary(const string theLibName)
 {
   string aFileName = library(theLibName);
index 620501bfd07e97d18d1cbf8dc82236ba6a5fafce..b53a66336d512b13dd815dcdb6bbd3318f6c8190 100644 (file)
@@ -7,10 +7,11 @@
 
 #include "ModelAPI.h"
 #include <string>
-#include <boost/shared_ptr.hpp>
+#include <memory>
 
 class ModelAPI_Feature;
 class ModelAPI_Plugin;
+class ModelAPI_Document;
 
 /**\class ModelAPI_PluginManager
  * \ingroup DataModel
@@ -23,16 +24,19 @@ class MODELAPI_EXPORT ModelAPI_PluginManager
 {
 public:
   /// Creates the feature object using plugins functionality
-  virtual boost::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID) = 0;
+  virtual std::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID) = 0;
 
   /// Returns the real implementation (the alone instance per application) of the plugin manager
-  static boost::shared_ptr<ModelAPI_PluginManager> get();
+  static std::shared_ptr<ModelAPI_PluginManager> get();
 
   /// 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)
   virtual void registerPlugin(ModelAPI_Plugin* thePlugin) = 0;
 
+  /// Returns the root document of the application (that may contains sub-documents)
+  virtual std::shared_ptr<ModelAPI_Document> rootDocument() = 0;
+
   /// loads the library with specific name, appends "lib*.dll" or "*.so" depending on the platform
   static void ModelAPI_PluginManager::loadLibrary(const std::string theLibName);
 
@@ -40,7 +44,7 @@ public:
   ModelAPI_PluginManager();
 
 protected:
-  static void SetPluginManager(boost::shared_ptr<ModelAPI_PluginManager> theManager);
+  static void SetPluginManager(std::shared_ptr<ModelAPI_PluginManager> theManager);
 };
 
 #endif
index ab07cdc88c95c8d495c2127794685c3ff07cf55c..10d71fce75c5f3a173699115416a23a07bce5762 100644 (file)
@@ -1,7 +1,6 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)
 
 INCLUDE(Common)
-INCLUDE(FindBoost)
 
 SET(PROJECT_HEADERS
     PartSetPlugin.h
index 7959ef0442a988cea52d86d2660f1df6ceaf86eb..2b2c59bc31133f6c560e0250e32e422c5a831997 100644 (file)
@@ -2,8 +2,26 @@
 // 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");
+}
index 9b824c0ee3763d0e42bad659c0d689f80911eed8..1294d4ddb170bb805f86123ede3487877ca5c4f8 100644 (file)
@@ -8,16 +8,24 @@
 #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();
index d3d295dc72f8c90fc1e81cf81b3d84e83c6cbf9c..61fbc5a0ba86ba6c4776eed60f52a645019e8e86 100644 (file)
@@ -1,6 +1,7 @@
 #include "PartSetPlugin_Plugin.h"
 #include "PartSetPlugin_NewPart.h"
 #include <ModelAPI_PluginManager.h>
+#include <ModelAPI_Document.h>
 
 using namespace std;
 
@@ -13,11 +14,15 @@ PartSetPlugin_Plugin::PartSetPlugin_Plugin()
   ModelAPI_PluginManager::get()->registerPlugin(this);
 }
 
-boost::shared_ptr<ModelAPI_Feature> PartSetPlugin_Plugin::createFeature(string theFeatureID)
+std::shared_ptr<ModelAPI_Feature> PartSetPlugin_Plugin::createFeature(string theFeatureID)
 {
+  std::shared_ptr<ModelAPI_Feature> aCreated;
   if (theFeatureID == "new_part") {
-    return boost::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()->addFeature(aCreated, PARTS_GROUP);
   // feature of such kind is not found
-  return boost::shared_ptr<ModelAPI_Feature>();
+  return aCreated;
 }
index ff577f79a3adec8e2003a43ece502a805e536255..74f6e73c02d90caa136d918152b0ce52d2f5c650 100644 (file)
@@ -13,7 +13,7 @@ class PARTSETPLUGIN_EXPORT PartSetPlugin_Plugin: public ModelAPI_Plugin
 {
 public:
   /// Creates the feature object of this plugin by the feature string ID
-  virtual boost::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID);
+  virtual std::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID);
 
 public:
   /// Is needed for python wrapping by swig