]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Added "Object" feature: result of the operation in specialized folders.
authormpv <mikhail.ponikarov@opencascade.com>
Mon, 19 May 2014 08:27:48 +0000 (12:27 +0400)
committermpv <mikhail.ponikarov@opencascade.com>
Mon, 19 May 2014 08:27:48 +0000 (12:27 +0400)
src/Model/CMakeLists.txt
src/Model/Model_Document.cpp
src/Model/Model_Document.h
src/Model/Model_Object.cpp [new file with mode: 0644]
src/Model/Model_Object.h [new file with mode: 0644]
src/ModelAPI/CMakeLists.txt
src/ModelAPI/ModelAPI.i
src/ModelAPI/ModelAPI_Document.h
src/ModelAPI/ModelAPI_Object.h [new file with mode: 0644]
src/ModelAPI/ModelAPI_PluginManager.cpp

index 65c929cc5bfe0dc3da72f73d9f5e1f359613972a..5db73c34774b755d8dbb34729b1ae8a32b41fe31 100644 (file)
@@ -7,6 +7,7 @@ SET(PROJECT_HEADERS
     Model_Document.h
     Model_PluginManager.h
     Model_Data.h
+    Model_Object.h
     Model_AttributeDouble.h
     Model_AttributeDocRef.h
     Model_AttributeReference.h
@@ -20,6 +21,7 @@ SET(PROJECT_SOURCES
     Model_Document.cpp
     Model_PluginManager.cpp
     Model_Data.cpp
+    Model_Object.cpp
     Model_AttributeDouble.cpp
     Model_AttributeDocRef.cpp
     Model_AttributeReference.cpp
index 943992055a274818587808ac2ff7e0542ceb6c50..be6a5957bdd7823c46c62d23d4942ba34d05a1d0 100644 (file)
@@ -5,6 +5,7 @@
 #include <Model_Document.h>
 #include <ModelAPI_Feature.h>
 #include <Model_Data.h>
+#include <Model_Object.h>
 #include <Model_Application.h>
 #include <Model_PluginManager.h>
 #include <Model_Events.h>
@@ -16,6 +17,7 @@
 #include <TDF_ChildIDIterator.hxx>
 #include <TDataStd_ReferenceArray.hxx>
 #include <TDataStd_HLabelArray1.hxx>
+#include <TDataStd_Name.hxx>
 
 #include <climits>
 
@@ -275,40 +277,54 @@ boost::shared_ptr<ModelAPI_Feature> Model_Document::addFeature(string theID)
   return aFeature;
 }
 
+/// Appenad to the array of references a new referenced label
+static void AddToRefArray(TDF_Label& theArrayLab, TDF_Label& theReferenced) {
+  Handle(TDataStd_ReferenceArray) aRefs;
+  if (!theArrayLab.FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
+    aRefs = TDataStd_ReferenceArray::Set(theArrayLab, 0, 0);
+    aRefs->SetValue(0, theReferenced);
+  } else { // extend array by one more element
+    Handle(TDataStd_HLabelArray1) aNewArray = 
+      new TDataStd_HLabelArray1(aRefs->Lower(), aRefs->Upper() + 1);
+    for(int a = aRefs->Lower(); a <= aRefs->Upper(); a++) {
+      aNewArray->SetValue(a, aRefs->Value(a));
+    }
+    aNewArray->SetValue(aRefs->Upper() + 1, theReferenced);
+    aRefs->SetInternalArray(aNewArray);
+  }
+}
+
 void Model_Document::addFeature(const boost::shared_ptr<ModelAPI_Feature> theFeature)
 {
-  const std::string& aGroup = theFeature->getGroup();
-  TDF_Label aGroupLab = groupLabel(aGroup);
-  TDF_Label anObjLab = aGroupLab.NewChild();
-  boost::shared_ptr<Model_Data> aData(new Model_Data);
-  aData->setFeature(theFeature);
-  aData->setLabel(anObjLab);
   boost::shared_ptr<ModelAPI_Document> aThis = 
     Model_Application::getApplication()->getDocument(myID);
+  TDF_Label aFeaturesLab = groupLabel(FEATURES_GROUP);
+  TDF_Label aFeatureLab = aFeaturesLab.NewChild();
+
+  // organize feature and data objects
+  boost::shared_ptr<Model_Data> aData(new Model_Data);
+  aData->setFeature(theFeature);
+  aData->setLabel(aFeatureLab);
   theFeature->setDoc(aThis);
   theFeature->setData(aData);
   setUniqueName(theFeature);
   theFeature->initAttributes();
+
   // keep the feature ID to restore document later correctly
-  TDataStd_Comment::Set(anObjLab, theFeature->getKind().c_str());
-  // put index of the feature in the group in the tree
-  TDataStd_Integer::Set(anObjLab, myFeatures[aGroup].size());
-  myFeatures[aGroup].push_back(theFeature);
+  TDataStd_Comment::Set(aFeatureLab, theFeature->getKind().c_str());
+  myFeatures.push_back(theFeature);
   // store feature in the history of features array
   if (theFeature->isInHistory()) {
-    Handle(TDataStd_ReferenceArray) aRefs;
-    if (!groupLabel(FEATURES_GROUP).FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
-      aRefs = TDataStd_ReferenceArray::Set(groupLabel(FEATURES_GROUP), 0, 0);
-      aRefs->SetValue(0, anObjLab);
-    } else { // extend array by one more element
-      Handle(TDataStd_HLabelArray1) aNewArray = 
-        new TDataStd_HLabelArray1(aRefs->Lower(), aRefs->Upper() + 1);
-      for(int a = aRefs->Lower(); a <= aRefs->Upper(); a++) {
-        aNewArray->SetValue(a, aRefs->Value(a));
-      }
-      aNewArray->SetValue(aRefs->Upper() + 1, anObjLab);
-      aRefs->SetInternalArray(aNewArray);
-    }
+    AddToRefArray(aFeaturesLab, aFeatureLab);
+    // add featue to the group
+    const std::string& aGroup = theFeature->getGroup();
+    TDF_Label aGroupLab = groupLabel(aGroup);
+    AddToRefArray(aGroupLab, aFeatureLab);
+    // new name of this feature object by default equal to name of feature
+    TDF_Label anObjLab = aGroupLab.NewChild();
+    TCollection_ExtendedString aName(theFeature->data()->getName().c_str());
+    TDataStd_Name::Set(anObjLab, aName);
+    AddToRefArray(aGroupLab.FindChild(1), anObjLab); // reference to names is on the first sub
   }
 
   // event: feature is added
@@ -319,32 +335,17 @@ void Model_Document::addFeature(const boost::shared_ptr<ModelAPI_Feature> theFea
 
 boost::shared_ptr<ModelAPI_Feature> Model_Document::feature(TDF_Label& theLabel)
 {
-  Handle(TDataStd_Integer) aFeatureIndex;
-  if (theLabel.FindAttribute(TDataStd_Integer::GetID(), aFeatureIndex)) {
-    Handle(TDataStd_Comment) aGroupID;
-    if (theLabel.Father().FindAttribute(TDataStd_Comment::GetID(), aGroupID)) {
-      string aGroup = TCollection_AsciiString(aGroupID->Get()).ToCString();
-      if (myFeatures[aGroup].size() > aFeatureIndex->Get())
-        return myFeatures[aGroup][aFeatureIndex->Get()];
-    }
+  // iterate all features, may be optimized later by keeping labels-map
+  vector<boost::shared_ptr<ModelAPI_Feature> >::iterator aFIter = myFeatures.begin();
+  for(; aFIter != myFeatures.end(); aFIter++) {
+    boost::shared_ptr<Model_Data> aData = 
+      boost::dynamic_pointer_cast<Model_Data>((*aFIter)->data());
+    if (aData->label().IsEqual(theLabel))
+      return *aFIter;
   }
   return boost::shared_ptr<ModelAPI_Feature>(); // not found
 }
 
-int Model_Document::featureIndex(boost::shared_ptr<ModelAPI_Feature> theFeature)
-{
-  if (theFeature->document().get() != this) {
-    return theFeature->document()->featureIndex(theFeature);
-  }
-  boost::shared_ptr<Model_Data> aData =
-    boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
-  Handle(TDataStd_Integer) aFeatureIndex;
-  if (aData->label().FindAttribute(TDataStd_Integer::GetID(), aFeatureIndex)) {
-    return aFeatureIndex->Get();
-  }
-  return -1; // not found
-}
-
 boost::shared_ptr<ModelAPI_Document> Model_Document::subDocument(string theDocID)
 {
   // just store sub-document identifier here to manage it later
@@ -356,46 +357,38 @@ boost::shared_ptr<ModelAPI_Document> Model_Document::subDocument(string theDocID
 boost::shared_ptr<ModelAPI_Feature> Model_Document::feature(
   const string& theGroupID, const int theIndex)
 {
-  if (theGroupID == FEATURES_GROUP) { // history is just a references array
-    Handle(TDataStd_ReferenceArray) aRefs;
-    if (groupLabel(FEATURES_GROUP).FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
-      if (aRefs->Lower() <= theIndex && aRefs->Upper() >= theIndex) {
-        TDF_Label aFeatureLab = aRefs->Value(theIndex);
-        return feature(aFeatureLab);
+  TDF_Label aGroupLab = groupLabel(theGroupID);
+  Handle(TDataStd_ReferenceArray) aRefs;
+  if (aGroupLab.FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
+    if (aRefs->Lower() <= theIndex && aRefs->Upper() >= theIndex) {
+      TDF_Label aFeatureLab = aRefs->Value(theIndex);
+      boost::shared_ptr<ModelAPI_Feature> aFeature = feature(aFeatureLab);
+
+      if (theGroupID == FEATURES_GROUP) { // just returns the feature from the history
+        return aFeature;
+      } else { // create a new object from the group to return it
+        Handle(TDataStd_Name) aName; // name of the object
+        if (aGroupLab.FindChild(1).FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs))
+          aRefs->Value(theIndex).FindAttribute(TDataStd_Name::GetID(), aName);
+        boost::shared_ptr<Model_Object> anObj(new Model_Object(aFeature, aName));
+        return anObj;
       }
     }
-  } else { // one of the group
-    map<string, vector<boost::shared_ptr<ModelAPI_Feature> > >::iterator aGroup = 
-      myFeatures.find(theGroupID);
-    if (aGroup != myFeatures.end() && (int)(aGroup->second.size()) > theIndex) {
-      return aGroup->second[theIndex];
-    }
   }
+
   // not found
   return boost::shared_ptr<ModelAPI_Feature>();
 }
 
 int Model_Document::size(const string& theGroupID) 
 {
-  if (theGroupID == FEATURES_GROUP) { // history is just a references array
-    Handle(TDataStd_ReferenceArray) aRefs;
-    if (groupLabel(FEATURES_GROUP).FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs))
-      return aRefs->Length();
-  } else { // one of the group
-    map<string, vector<boost::shared_ptr<ModelAPI_Feature> > >::iterator aGroup = 
-      myFeatures.find(theGroupID);
-    if (aGroup != myFeatures.end())
-      return aGroup->second.size();
-  }
+  Handle(TDataStd_ReferenceArray) aRefs;
+  if (groupLabel(FEATURES_GROUP).FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs))
+    return aRefs->Length();
   // group is not found
   return 0;
 }
 
-const vector<string>& Model_Document::getGroups() const
-{
-  return myGroupsNames;
-}
-
 Model_Document::Model_Document(const std::string theID)
     : myID(theID), myDoc(new TDocStd_Document("BinOcaf")) // binary OCAF format
 {
@@ -409,23 +402,27 @@ Model_Document::Model_Document(const std::string theID)
 
 TDF_Label Model_Document::groupLabel(const string theGroup)
 {
-  if (myGroups.find(theGroup) == myGroups.end()) {
-    myGroups[theGroup] = myDoc->Main().FindChild(TAG_OBJECTS).NewChild();
-    myGroupsNames.push_back(theGroup);
-    // set to the group label the group idntifier to restore on "open"
-    TDataStd_Comment::Set(myGroups[theGroup], theGroup.c_str());
-    myFeatures[theGroup] = vector<boost::shared_ptr<ModelAPI_Feature> >();
+  // searching for existing
+  TCollection_ExtendedString aGroup(theGroup.c_str());
+  TDF_ChildIDIterator aGroupIter(myDoc->Main().FindChild(TAG_OBJECTS), TDataStd_Comment::GetID());
+  for(; aGroupIter.More(); aGroupIter.Next()) {
+    Handle(TDataStd_Comment) aName = Handle(TDataStd_Comment)::DownCast(aGroupIter.Value());
+    if (aName->Get() == aGroup)
+      return aGroupIter.Value()->Label();
   }
-  return myGroups[theGroup];
+  // create a new
+  TDF_Label aNew = myDoc->Main().FindChild(TAG_OBJECTS).NewChild();
+  TDataStd_Comment::Set(aNew, aGroup);
+  return aNew;
 }
 
 void Model_Document::setUniqueName(boost::shared_ptr<ModelAPI_Feature> theFeature)
 {
   // first count all objects of such kind to start with index = count + 1
   int a, aNumObjects = 0;
-  int aSize = size(theFeature->getGroup());
+  int aSize = size(FEATURES_GROUP);
   for(a = 0; a < aSize; a++) {
-    if (feature(theFeature->getGroup(), a)->getKind() == theFeature->getKind())
+    if (feature(FEATURES_GROUP, a)->getKind() == theFeature->getKind())
       aNumObjects++;
   }
   // generate candidate name
@@ -434,7 +431,7 @@ void Model_Document::setUniqueName(boost::shared_ptr<ModelAPI_Feature> theFeatur
   string aName = aNameStream.str();
   // check this is unique, if not, increase index by 1
   for(a = 0; a < aSize;) {
-    if (feature(theFeature->getGroup(), a)->data()->getName() == aName) {
+    if (feature(FEATURES_GROUP, a)->data()->getName() == aName) {
       aNumObjects++;
       stringstream aNameStream;
       aNameStream<<theFeature->getKind()<<"_"<<aNumObjects + 1;
@@ -446,98 +443,81 @@ void Model_Document::setUniqueName(boost::shared_ptr<ModelAPI_Feature> theFeatur
   theFeature->data()->setName(aName);
 }
 
+//! Returns the object by the feature
+boost::shared_ptr<ModelAPI_Feature> Model_Document::objectByFeature(
+  const boost::shared_ptr<ModelAPI_Feature> theFeature)
+{
+  for(int a = 0; a < size(theFeature->getGroup()); a++) {
+    boost::shared_ptr<Model_Object> anObj = 
+      boost::dynamic_pointer_cast<Model_Object>(feature(theFeature->getGroup(), a));
+    if (anObj) {
+      return anObj;
+    }
+  }
+  return boost::shared_ptr<ModelAPI_Feature>(); // not found
+}
+
 void Model_Document::synchronizeFeatures()
 {
   boost::shared_ptr<ModelAPI_Document> aThis = Model_Application::getApplication()->getDocument(myID);
-  // iterate groups labels
-  TDF_ChildIDIterator aGroupsIter(myDoc->Main().FindChild(TAG_OBJECTS),
-    TDataStd_Comment::GetID(), Standard_False);
-  vector<string>::iterator aGroupNamesIter = myGroupsNames.begin();
-  for(; aGroupsIter.More() && aGroupNamesIter != myGroupsNames.end();
-        aGroupsIter.Next(), aGroupNamesIter++) {
-    string aGroupName = TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(
-      aGroupsIter.Value())->Get()).ToCString();
-    if (*aGroupNamesIter != aGroupName) 
-      break; // all since there is a change this must be recreated from scratch
-  }
-  // delete all groups left after the data model groups iteration
-  while(aGroupNamesIter != myGroupsNames.end()) {
-    string aGroupName = *aGroupNamesIter;
-    myFeatures.erase(aGroupName);
-    myGroups.erase(aGroupName);
-    aGroupNamesIter = myGroupsNames.erase(aGroupNamesIter);
-    // say that features were deleted from group
-    Model_FeatureDeletedMessage aMsg(aThis, aGroupName);
-    Events_Loop::loop()->send(aMsg);
-  }
-  // create new groups basing on the following data model update
-  for(; aGroupsIter.More(); aGroupsIter.Next()) {
-    string aGroupName = TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(
-      aGroupsIter.Value())->Get()).ToCString();
-    myGroupsNames.push_back(aGroupName);
-    myGroups[aGroupName] = aGroupsIter.Value()->Label();
-    myFeatures[aGroupName] = vector<boost::shared_ptr<ModelAPI_Feature> >();
-  }
-  // update features group by group
-  aGroupsIter.Initialize(myDoc->Main().FindChild(TAG_OBJECTS),
-    TDataStd_Comment::GetID(), Standard_False);
-  for(; aGroupsIter.More(); aGroupsIter.Next()) {
-    string aGroupName = TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(
-      aGroupsIter.Value())->Get()).ToCString();
-    // iterate features in internal container
-    vector<boost::shared_ptr<ModelAPI_Feature> >& aFeatures = myFeatures[aGroupName];
-    vector<boost::shared_ptr<ModelAPI_Feature> >::iterator aFIter = aFeatures.begin();
-    // and in parallel iterate labels of features
-    TDF_ChildIDIterator aFLabIter(
-      aGroupsIter.Value()->Label(), TDataStd_Comment::GetID(), Standard_False);
-    while(aFIter != aFeatures.end() || aFLabIter.More()) {
-      static const int INFINITE_TAG = INT_MAX; // no label means that it exists somwhere in infinite
-      int aFeatureTag = INFINITE_TAG; 
-      if (aFIter != aFeatures.end()) { // existing tag for feature
-        boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>((*aFIter)->data());
-        aFeatureTag = aData->label().Tag();
-      }
-      int aDSTag = INFINITE_TAG; 
-      if (aFLabIter.More()) { // next label in DS is existing
-        aDSTag = aFLabIter.Value()->Label().Tag();
-      }
-      if (aDSTag > aFeatureTag) { // feature is removed
-        aFIter = aFeatures.erase(aFIter);
-        // event: model is updated
-        Model_FeatureDeletedMessage aMsg(aThis, aGroupName);
-        Events_Loop::loop()->send(aMsg);
-      } else if (aDSTag < aFeatureTag) { // a new feature is inserted
-        // create a feature
-        boost::shared_ptr<ModelAPI_Feature> aFeature = ModelAPI_PluginManager::get()->createFeature(
-          TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(
-          aFLabIter.Value())->Get()).ToCString());
-
-        if (aFIter == aFeatures.end()) { // must be before "setData" to redo the sketch line correctly
-          aFeatures.push_back(aFeature);
-          aFIter = aFeatures.end();
-        } else {
-          aFIter++;
-          aFeatures.insert(aFIter, aFeature);
-        }
-        boost::shared_ptr<Model_Data> aData(new Model_Data);
-        TDF_Label aLab = aFLabIter.Value()->Label();
-        aData->setLabel(aLab);
-        aData->setFeature(aFeature);
-        aFeature->setDoc(aThis);
-        aFeature->setData(aData);
-        aFeature->initAttributes();
-
-        // event: model is updated
-        static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_CREATED);
-        Model_FeatureUpdatedMessage aMsg(aFeature, anEvent);
-        Events_Loop::loop()->send(aMsg);
-
-        // feature for this label is added, so go to the next label
-        aFLabIter.Next();
-      } else { // nothing is changed, both iterators are incremented
+  // update features
+  vector<boost::shared_ptr<ModelAPI_Feature> >::iterator aFIter = myFeatures.begin();
+  // and in parallel iterate labels of features
+  TDF_ChildIDIterator aFLabIter(groupLabel(FEATURES_GROUP), TDataStd_Comment::GetID());
+  while(aFIter != myFeatures.end() || aFLabIter.More()) {
+    static const int INFINITE_TAG = INT_MAX; // no label means that it exists somwhere in infinite
+    int aFeatureTag = INFINITE_TAG; 
+    if (aFIter != myFeatures.end()) { // existing tag for feature
+      boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>((*aFIter)->data());
+      aFeatureTag = aData->label().Tag();
+    }
+    int aDSTag = INFINITE_TAG; 
+    if (aFLabIter.More()) { // next label in DS is existing
+      aDSTag = aFLabIter.Value()->Label().Tag();
+    }
+    if (aDSTag > aFeatureTag) { // feature is removed
+      Model_FeatureDeletedMessage aMsg1(aThis, FEATURES_GROUP);
+      Model_FeatureDeletedMessage aMsg2(aThis, (*aFIter)->getGroup());
+      aFIter = myFeatures.erase(aFIter);
+      // event: model is updated
+      Events_Loop::loop()->send(aMsg1);
+      Events_Loop::loop()->send(aMsg2);
+    } else if (aDSTag < aFeatureTag) { // a new feature is inserted
+      // create a feature
+      boost::shared_ptr<ModelAPI_Feature> aFeature = ModelAPI_PluginManager::get()->createFeature(
+        TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(
+        aFLabIter.Value())->Get()).ToCString());
+
+      if (aFIter == myFeatures.end()) { // must be before "setData" to redo the sketch line correctly
+        myFeatures.push_back(aFeature);
+        aFIter = myFeatures.end();
+      } else {
         aFIter++;
-        aFLabIter.Next();
+        myFeatures.insert(aFIter, aFeature);
       }
+      boost::shared_ptr<Model_Data> aData(new Model_Data);
+      TDF_Label aLab = aFLabIter.Value()->Label();
+      aData->setLabel(aLab);
+      aData->setFeature(aFeature);
+      aFeature->setDoc(aThis);
+      aFeature->setData(aData);
+      aFeature->initAttributes();
+
+      // event: model is updated
+      static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_CREATED);
+      Model_FeatureUpdatedMessage aMsg1(aFeature, anEvent);
+      Events_Loop::loop()->send(aMsg1);
+      boost::shared_ptr<ModelAPI_Feature> anObj = objectByFeature(aFeature);
+      if (anObj) {
+        Model_FeatureUpdatedMessage aMsg2(anObj, anEvent);
+        Events_Loop::loop()->send(aMsg2);
+      }
+
+      // feature for this label is added, so go to the next label
+      aFLabIter.Next();
+    } else { // nothing is changed, both iterators are incremented
+      aFIter++;
+      aFLabIter.Next();
     }
   }
 }
index 6d5d04b6babd0c0dacc596fcae00a1e9ddda8774..218ea615bf88cdc004b6c5f8ece6bae4b2acdcc9 100644 (file)
@@ -80,13 +80,6 @@ public:
   //! Returns the number of features in the group
   MODEL_EXPORT virtual int size(const std::string& theGroupID);
 
-  ///! Returns the vector of groups already added to the document
-  MODEL_EXPORT virtual const std::vector<std::string>& getGroups() const;
-
-  //! Returns the index of feature in the group (zero based)
-  //! \retruns -1 if not found
-  MODEL_EXPORT virtual int featureIndex(boost::shared_ptr<ModelAPI_Feature> theFeature);
-
 protected:
 
   //! Returns (creates if needed) the group label
@@ -99,7 +92,11 @@ protected:
   //! Adds to the document the new feature
   void addFeature(const boost::shared_ptr<ModelAPI_Feature> theFeature);
 
-  //! Synchronizes myGroups, myGroupsNames, myFeatures and mySubs list with the updated document
+  //! Returns the object by the feature
+  boost::shared_ptr<ModelAPI_Feature> objectByFeature(
+    const boost::shared_ptr<ModelAPI_Feature> theFeature);
+
+  //! Synchronizes myFeatures list with the updated document
   void synchronizeFeatures();
 
   //! Creates new document with binary file format
@@ -114,12 +111,11 @@ private:
   int myTransactionsAfterSave;
   /// number of myTransactionsAfterSave for the nested transaction start
   int myNestedStart;
-  /// root labels of the features groups identified by names
-  std::map<std::string, TDF_Label> myGroups;
-  std::vector<std::string> myGroupsNames; ///< names of added groups to the document
-  /// Features managed by this document: by group name
-  std::map<std::string, std::vector<boost::shared_ptr<ModelAPI_Feature> > > myFeatures;
-  std::set<std::string> mySubs; ///< set of identifiers of sub-documents of this document
+  /// All features managed by this document (not only in history of OB)
+  std::vector<boost::shared_ptr<ModelAPI_Feature> > myFeatures;
+
+  ///< set of identifiers of sub-documents of this document
+  std::set<std::string> mySubs;
   /// transaction indexes (related to myTransactionsAfterSave) which were empty in this doc
   std::map<int, bool> myIsEmptyTr;
 };
diff --git a/src/Model/Model_Object.cpp b/src/Model/Model_Object.cpp
new file mode 100644 (file)
index 0000000..9b39c6d
--- /dev/null
@@ -0,0 +1,27 @@
+// File:        Model_Object.cpp
+// Created:     19 May 2014
+// Author:      Mikhail PONIKAROV
+
+#include "Model_Object.h"
+#include <TCollection_AsciiString.hxx>
+
+boost::shared_ptr<ModelAPI_Feature> Model_Object::featureRef()
+{
+  return myRef;
+}
+
+std::string Model_Object::getName()
+{
+  return TCollection_AsciiString(myName->Get()).ToCString();
+}
+
+void Model_Object::setName(std::string theName)
+{
+  myName->Set(theName.c_str());
+}
+
+Model_Object::Model_Object(boost::shared_ptr<ModelAPI_Feature> theRef,
+                           Handle_TDataStd_Name theName)
+                           : myRef(theRef), myName(theName)
+{
+}
diff --git a/src/Model/Model_Object.h b/src/Model/Model_Object.h
new file mode 100644 (file)
index 0000000..18314c0
--- /dev/null
@@ -0,0 +1,53 @@
+// File:        Model_Object.hxx
+// Created:     19 May 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef Model_Object_HeaderFile
+#define Model_Object_HeaderFile
+
+#include <Model.h>
+#include <ModelAPI_Object.h>
+
+#include <TDataStd_Name.hxx>
+
+/**\class ModelAPI_Object
+ * \ingroup DataModel
+ * \brief Represents the result of some feature in the object browser
+ * under the specific folder. Just a reference to specific feature-operation
+ * with possibility to rename it.
+ */
+class Model_Object : public ModelAPI_Object
+{
+  boost::shared_ptr<ModelAPI_Feature> myRef; ///< the referenced feature
+  Handle_TDataStd_Name myName; ///< the name of this object that may be changed
+public:
+  /// Reference to the feature-operation that produces this object
+  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> featureRef();
+
+  /// Returns the name of this object (by default equal to the name of feature)
+  MODEL_EXPORT virtual std::string getName();
+
+  /// Defines the name of the object
+  MODEL_EXPORT virtual void setName(std::string theName);
+
+  /// Returns the kind of a feature (like "Point")
+  MODEL_EXPORT virtual const std::string& getKind() {return myRef->getKind();}
+
+  /// Returns to which group in the document must be added feature
+  MODEL_EXPORT virtual const std::string& getGroup() {return myRef->getGroup();}
+
+  /// It is just a reference: don't init attributes
+  MODEL_EXPORT virtual void initAttributes() {}
+
+  /// It is just a reference: don't execute
+  MODEL_EXPORT virtual void execute() {}
+
+private:
+
+  /// Constructor fully defines this object
+  Model_Object(boost::shared_ptr<ModelAPI_Feature> theRef, Handle_TDataStd_Name theName);
+
+  friend class Model_Document;
+};
+
+#endif
index e57b2c619d4220ceba7aad9370d72e1053389dae..49757f69fe70022388c2ecab6a6b10fc6b4919ec 100644 (file)
@@ -8,6 +8,7 @@ SET(PROJECT_HEADERS
     ModelAPI_Plugin.h
     ModelAPI_Feature.h
     ModelAPI_Data.h
+    ModelAPI_Object.h
     ModelAPI_Document.h
     ModelAPI_Attribute.h
     ModelAPI_AttributeDouble.h
index 097bdcfd25b523cb85e70a3f0b0a65a97f7fedc3..589ac4026502f73df3b9f3ae0bfd9bea3a5d75a9 100644 (file)
@@ -6,6 +6,7 @@
   #include "ModelAPI_PluginManager.h"
   #include "ModelAPI_Feature.h"
   #include "ModelAPI_Data.h"
+  #include "ModelAPI_Object.h"
   #include "ModelAPI_Attribute.h"
   #include "ModelAPI_AttributeDocRef.h"
   #include "ModelAPI_AttributeDouble.h"
@@ -27,6 +28,7 @@
 %shared_ptr(ModelAPI_PluginManager)
 %shared_ptr(ModelAPI_Feature)
 %shared_ptr(ModelAPI_Data)
+%shared_ptr(ModelAPI_Object)
 %shared_ptr(ModelAPI_Attribute)
 %shared_ptr(ModelAPI_AttributeDocRef)
 %shared_ptr(ModelAPI_AttributeDouble)
@@ -38,6 +40,7 @@
 %include "ModelAPI_PluginManager.h"
 %include "ModelAPI_Feature.h"
 %include "ModelAPI_Data.h"
+%include "ModelAPI_Object.h"
 %include "ModelAPI_Attribute.h"
 %include "ModelAPI_AttributeDocRef.h"
 %include "ModelAPI_AttributeDouble.h"
index 4ae7380227ed57209753cbf3c8857670cee363c2..311745a16e24b69c22fc67d981fdcccc19032944 100644 (file)
@@ -82,12 +82,6 @@ public:
   //! Returns the number of features in the group
   MODELAPI_EXPORT virtual int size(const std::string& theGroupID) = 0;
 
-  //! Returns the index of feature in the group (zero based)
-  MODELAPI_EXPORT virtual int featureIndex(boost::shared_ptr<ModelAPI_Feature> theFeature) = 0;
-
-  ///! Returns the vector of groups already added to the document
-  MODELAPI_EXPORT virtual const std::vector<std::string>& getGroups() const = 0;
-
   /// To virtually destroy the fields of successors
   virtual ~ModelAPI_Document() {}
 
diff --git a/src/ModelAPI/ModelAPI_Object.h b/src/ModelAPI/ModelAPI_Object.h
new file mode 100644 (file)
index 0000000..64240ce
--- /dev/null
@@ -0,0 +1,33 @@
+// File:        ModelAPI_Object.hxx
+// Created:     19 May 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef ModelAPI_Object_HeaderFile
+#define ModelAPI_Object_HeaderFile
+
+#include "ModelAPI_Feature.h"
+
+/**\class ModelAPI_Object
+ * \ingroup DataModel
+ * \brief Represents the result of some feature in the object browser
+ * under the specific folder. Just a reference to specific feature-operation
+ * with possibility to rename it.
+ */
+class ModelAPI_Object : public ModelAPI_Feature
+{
+public:
+
+  /// It is never located in history
+  MODELAPI_EXPORT virtual bool isInHistory() {return false;}
+
+  /// Reference to the feature-operation that produces this object
+  MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> featureRef() = 0;
+
+  /// Returns the name of this object (by default equal to the name of feature)
+  MODELAPI_EXPORT virtual std::string getName() = 0;
+
+  /// Defines the name of the object
+  MODELAPI_EXPORT virtual void setName(std::string theName) = 0;
+};
+
+#endif
index bfdfbe813035c83f0223da6749244f43a45c8da5..a8d497c7c6986d6146148f7d525e83c54b09374d 100644 (file)
@@ -7,6 +7,7 @@
 #include <ModelAPI_Document.h>
 // to avoid unresolved ModelAPI_Feature()
 #include <ModelAPI_Feature.h>
+#include <ModelAPI_Object.h>
 // to avoid unresolved ModelAPI_Data()
 #include <ModelAPI_Data.h>
 // to avoid unresolved ModelAPI_Plugin()