]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'master' of newgeom:newgeom.git
authorsbh <sergey.belash@opencascade.com>
Tue, 8 Apr 2014 14:41:53 +0000 (18:41 +0400)
committersbh <sergey.belash@opencascade.com>
Tue, 8 Apr 2014 14:41:53 +0000 (18:41 +0400)
20 files changed:
src/Event/Event_Message.cxx
src/Event/Event_Message.h
src/Model/Model_AttributeDouble.cxx
src/Model/Model_Document.cxx
src/Model/Model_Document.h
src/Model/Model_Iterator.cxx
src/Model/Model_Iterator.h
src/Model/Model_Object.h
src/Model/Model_PluginManager.cxx
src/Model/Model_PluginManager.h
src/ModelAPI/ModelAPI.i
src/ModelAPI/ModelAPI_Document.h
src/ModelAPI/ModelAPI_Feature.h
src/ModelAPI/ModelAPI_Iterator.h
src/ModelAPI/ModelAPI_Object.h
src/ModelAPI/ModelAPI_PluginManager.h
src/PartSetPlugin/PartSetPlugin_Part.cxx
src/PartSetPlugin/PartSetPlugin_Part.h
src/PartSetPlugin/PartSetPlugin_Plugin.cxx
src/PartSetPlugin/PartSetPlugin_Point.h

index ecf88a1e89c2085da5409a3c846799b165877ebc..764ed826f66fda4ffd1f935d367fe09b3aad83cb 100644 (file)
@@ -3,8 +3,3 @@
 // Author:     Mikhail PONIKAROV
 
 #include <Event_Message.h>
-
-Event_Message::Event_Message(const Event_ID theID, const void* theSender)
-    : myEventId(theID), mySender((void*) theSender)
-{
-}
index 6c851815c65372c0d3042e2e134a9ea8e2dc45ab..e07621af75f692e7045c558d065d88706bbd7164 100644 (file)
@@ -42,7 +42,9 @@ class EVENT_EXPORT Event_Message {
 public:
 
   //! Creates the message
-  Event_Message(const Event_ID theID, const void* theSender = 0);
+  Event_Message(const Event_ID theID, const void* theSender = 0)
+    : myEventId(theID), mySender((void*) theSender) {}
+  //! do nothing in the destructor yet
   virtual ~Event_Message() {}
 
   //! Returns identifier of the message
index 7e2ed83e183ddfc4c4b5a502cd7afb7864e5adf0..23e15f0e1ad9457e92570a83dec685aa67ed0314 100644 (file)
@@ -24,4 +24,3 @@ Model_AttributeDouble::Model_AttributeDouble(TDF_Label& theLabel)
     myReal = TDataStd_Real::Set(theLabel, 0.);
   }
 }
-
index 3aea0ff6ecbba55a254edcc0bab07a5c64e65c7b..7c2077cb91c95d51c678da3e154a80f661ab96fb 100644 (file)
@@ -8,6 +8,7 @@
 #include <Model_Application.h>
 #include <Model_PluginManager.h>
 #include <Model_Iterator.h>
+#include <Event_Loop.h>
 
 #include <TDataStd_Integer.hxx>
 #include <TDataStd_Comment.hxx>
@@ -152,27 +153,46 @@ void Model_Document::redo()
   myTransactionsAfterSave++;
 }
 
-void Model_Document::addFeature(
-  std::shared_ptr<ModelAPI_Feature> theFeature, const std::string theGroupID)
+shared_ptr<ModelAPI_Feature> Model_Document::addFeature(string theID)
 {
-  TDF_Label aGroupLab = groupLabel(theGroupID);
+  shared_ptr<ModelAPI_Feature> aFeature = ModelAPI_PluginManager::get()->createFeature(theID);
+  if (aFeature) {
+    dynamic_pointer_cast<Model_Document>(aFeature->documentToAdd())->addFeature(aFeature);
+  } else {
+    // TODO: generate error that feature is not created
+  }
+  return aFeature;
+}
+
+void Model_Document::addFeature(const std::shared_ptr<ModelAPI_Feature> theFeature)
+{
+  TDF_Label aGroupLab = groupLabel(theFeature->getGroup());
   TDF_Label anObjLab = aGroupLab.NewChild();
   std::shared_ptr<Model_Object> aData(new Model_Object);
   aData->setLabel(anObjLab);
+  aData->setDocument(Model_Application::getApplication()->getDocument(myID));
   theFeature->setData(aData);
-  setUniqueName(theFeature, theGroupID);
+  setUniqueName(theFeature);
   theFeature->initAttributes();
+  // keep the feature ID to restore document later correctly
   TDataStd_Comment::Set(anObjLab, theFeature->getKind().c_str());
+
+  // event: model is updated
+  static Event_ID anEvent = Event_Loop::eventByName(EVENT_FEATURE_UPDATED);
+  ModelAPI_FeatureUpdatedMessage aMsg(theFeature);
+  Event_Loop::loop()->send(aMsg);
 }
 
-std::shared_ptr<ModelAPI_Feature> Model_Document::feature(TDF_Label& theLabel)
+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<ModelAPI_Feature> aResult = 
+      Model_PluginManager::get()->createFeature(anID);
     std::shared_ptr<Model_Object> aData(new Model_Object);
     aData->setLabel(theLabel);
+    aData->setDocument(Model_Application::getApplication()->getDocument(myID));
     aResult->setData(aData);
     aResult->initAttributes();
     return aResult;
@@ -180,6 +200,17 @@ std::shared_ptr<ModelAPI_Feature> Model_Document::feature(TDF_Label& theLabel)
   return std::shared_ptr<ModelAPI_Feature>(); // not found
 }
 
+int Model_Document::featureIndex(shared_ptr<ModelAPI_Feature> theFeature)
+{
+  if (theFeature->data()->document().get() != this)
+    return theFeature->data()->document()->featureIndex(theFeature);
+  shared_ptr<ModelAPI_Iterator> anIter(featuresIterator(theFeature->getGroup()));
+  for(int anIndex = 0; anIter->more(); anIter->next(), anIndex++)
+    if (anIter->is(theFeature)) 
+      return anIndex;
+  return -1; // not found
+}
+
 shared_ptr<ModelAPI_Document> Model_Document::subDocument(string theDocID)
 {
   return Model_Application::getApplication()->getDocument(theDocID);
@@ -199,6 +230,11 @@ shared_ptr<ModelAPI_Feature> Model_Document::feature(const string& theGroupID, c
   return anIter->current();
 }
 
+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
 {
@@ -210,16 +246,17 @@ 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);
   }
   return myGroups[theGroup];
 }
 
 void Model_Document::setUniqueName(
-  shared_ptr<ModelAPI_Feature> theFeature, const string theGroupID)
+  shared_ptr<ModelAPI_Feature> theFeature)
 {
   // first count all objects of such kind to start with index = count + 1
   int aNumObjects = 0;
-  shared_ptr<ModelAPI_Iterator> anIter = featuresIterator(theGroupID);
+  shared_ptr<ModelAPI_Iterator> anIter = featuresIterator(theFeature->getGroup());
   for(; anIter->more(); anIter->next()) {
     if (anIter->currentKind() == theFeature->getKind())
       aNumObjects++;
@@ -229,15 +266,32 @@ void Model_Document::setUniqueName(
   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();) {
+  for(anIter = featuresIterator(theFeature->getGroup()); 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);
+      anIter = featuresIterator(theFeature->getGroup());
     } else anIter->next();
   }
 
   theFeature->data()->setName(aName);
 }
+
+
+ModelAPI_FeatureUpdatedMessage::ModelAPI_FeatureUpdatedMessage(
+  shared_ptr<ModelAPI_Feature> theFeature)
+  : Event_Message(messageId(), 0), myFeature(theFeature)
+{}
+
+const Event_ID ModelAPI_FeatureUpdatedMessage::messageId()
+{
+  static Event_ID MY_ID = Event_Loop::eventByName("FeatureUpdated");
+  return MY_ID;
+}
+
+shared_ptr<ModelAPI_Feature> ModelAPI_FeatureUpdatedMessage::feature()
+{
+  return myFeature;
+}
index d96aa15dd039747a06d2fb7113adab3947353a7d..6dd9e4396c0e8b57c06c307739fdecf28cea9682 100644 (file)
@@ -7,6 +7,8 @@
 
 #include <Model.h>
 #include <ModelAPI_Document.h>
+#include <Event_Message.h>
+
 #include <TDocStd_Document.hxx>
 #include <map>
 
@@ -59,11 +61,9 @@ public:
   //! Redoes last operation
   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);
+  //! Adds to the document the new feature of the given feature id
+  //! \param creates feature and puts it in the document
+  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID);
 
   //! Returns the existing feature by the label
   //! \param theLabel base label of the feature
@@ -82,6 +82,13 @@ public:
   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Feature> 
     feature(const std::string& theGroupID, const int theIndex);
 
+  ///! 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(std::shared_ptr<ModelAPI_Feature> theFeature);
+
 protected:
 
   //! Returns (creates if needed) the group label
@@ -89,8 +96,10 @@ protected:
 
   //! 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);
+  void setUniqueName(std::shared_ptr<ModelAPI_Feature> theFeature);
+
+  //! Adds to the document the new feature
+  void addFeature(const std::shared_ptr<ModelAPI_Feature> theFeature);
 
   //! Creates new document with binary file format
   Model_Document(const std::string theID);
@@ -102,6 +111,24 @@ private:
   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
+  std::vector<std::string> myGroupsNames; ///< names of added groups to the document
+};
+
+/// Event ID that model is updated
+static const char * EVENT_FEATURE_UPDATED = "FeatureUpdated";
+
+/// Message that feature was changed (used for Object Browser update)
+class ModelAPI_FeatureUpdatedMessage : public Event_Message {
+  std::shared_ptr<ModelAPI_Feature> myFeature; ///< which feature is changed
+public:
+  /// sender is not important, all information is located in the feature
+  ModelAPI_FeatureUpdatedMessage(std::shared_ptr<ModelAPI_Feature> theFeature);
+
+  /// Returns the ID of this message
+  static const Event_ID messageId();
+
+  /// Returns the feature that has been updated
+  std::shared_ptr<ModelAPI_Feature> feature();
 };
 
 #endif
index ae62fa928d37acc908da3989b0e1a9a163b0cb7c..4e2cf09422e38ff824874185903bd65301719f17 100644 (file)
@@ -4,6 +4,8 @@
 
 #include "Model_Iterator.h"
 #include "Model_Document.h"
+#include "ModelAPI_Feature.h"
+#include "Model_Object.h"
 #include <TDataStd_Comment.hxx>
 #include <TDataStd_Name.hxx>
 
@@ -49,6 +51,14 @@ int Model_Iterator::numIterationsLeft()
   return aResult;
 }
 
+bool Model_Iterator::is(std::shared_ptr<ModelAPI_Feature> theFeature)
+{
+  return myIter.Value()->Label() == 
+    dynamic_pointer_cast<Model_Object>(theFeature->data())->label();
+
+}
+
+
 Model_Iterator::Model_Iterator(std::shared_ptr<Model_Document> theDoc, TDF_Label theLab)
   : myDoc(theDoc), myIter(theLab, TDataStd_Comment::GetID(), Standard_False)
 {}
index 4da78e26712f49b1113ac59e44b9743bdfbf1065..80fc76caf047c36afab07652e136acf56993ae24 100644 (file)
@@ -37,6 +37,10 @@ public:
   /// \returns number of left iterations
   virtual int numIterationsLeft();
 
+  /// Compares the current feature with the given one
+  /// \returns true if given feature equals to the current one
+  virtual bool is(std::shared_ptr<ModelAPI_Feature> theFeature);
+
 protected:
   /// Initializes iterator
   /// \param theDoc document where the iteration is performed
index ecaca8920761a0f9e736b38f9997bf59bbe5bce0..6b1f785f4a6da6fd62553fb362d4482bb4fa5afb 100644 (file)
@@ -19,15 +19,20 @@ class ModelAPI_Attribute;
  * to get/set attributes from the document and compute result of an operation.
  */
 
-class Model_Object: public ModelAPI_Object
+class MODEL_EXPORT 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;
 
+  std::shared_ptr<ModelAPI_Document> myDoc; ///< document this feature belongs to
+
   Model_Object();
 
+  TDF_Label label() {return myLab;}
+
   friend class Model_Document;
+  friend class Model_Iterator;
 
 public:
   /// Returns the name of the feature visible by the user in the object browser
@@ -45,8 +50,14 @@ public:
   /// \param theAttrType type of the created attribute (received from the type method)
   virtual void addAttribute(std::string theID, std::string theAttrType);
 
+  /// Returns the document of this data
+  virtual std::shared_ptr<ModelAPI_Document> document() {return myDoc;}
+
   /// Puts feature to the document data sub-structure
   void setLabel(TDF_Label& theLab);
+
+  /// Sets the document of this data
+  virtual void setDocument(const std::shared_ptr<ModelAPI_Document>& theDoc) {myDoc = theDoc;}
 };
 
 #endif
index ce53ba069235590fa25c98e975f96dcbafcebf57..cca7b72fd9c4f44a97b33d04247d75270de6dced 100644 (file)
@@ -16,7 +16,7 @@ using namespace std;
 
 static Model_PluginManager* myImpl = new Model_PluginManager();
 
-std::shared_ptr<ModelAPI_Feature> Model_PluginManager::createFeature(string theFeatureID)
+shared_ptr<ModelAPI_Feature> Model_PluginManager::createFeature(string theFeatureID)
 {
   if (this != myImpl) return myImpl->createFeature(theFeatureID);
 
index c0cc31e5f4232af4aecd1e076fa1d3d9d29d5eaa..6da805cfa54e5aa27dad46dda311f96ec9cd944c 100644 (file)
@@ -27,9 +27,6 @@ class Model_PluginManager : public ModelAPI_PluginManager, public Event_Listener
   std::string myCurrentPluginName; ///< name of the plugin that must be loaded currently
   std::shared_ptr<ModelAPI_Document> myCurrentDoc; ///< current working document
 public:
-  /// Creates the feature object using plugins functionality
-  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID);
-
   /// Returns the root document of the application (that may contains sub-documents)
   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> rootDocument();
 
@@ -50,9 +47,12 @@ public:
   /// Is called only once, on startup of the application
   Model_PluginManager();
 
-private:
+protected:
   /// Loads (if not done yet) the information about the features and plugins
   void LoadPluginsInfo();
+
+  /// Creates the feature object using plugins functionality
+  virtual std::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID);
 };
 
 #endif
index ad58d4228849d4ab6ebe79c500a7af6f952d5e42..96d4414a9e9e37518e188fdc4dcf09f07da48c65 100644 (file)
@@ -9,6 +9,7 @@
   #include "ModelAPI_Attribute.h"
   #include "ModelAPI_AttributeDocRef.h"
   #include "ModelAPI_AttributeDouble.h"
+  #include "ModelAPI_Iterator.h"
 %}
 
 // to avoid error on this
@@ -28,6 +29,7 @@
 %shared_ptr(ModelAPI_Attribute)
 %shared_ptr(ModelAPI_AttributeDocRef)
 %shared_ptr(ModelAPI_AttributeDouble)
+%shared_ptr(ModelAPI_Iterator)
 
 // all supported interfaces
 %include "ModelAPI_Document.h"
@@ -37,3 +39,4 @@
 %include "ModelAPI_Attribute.h"
 %include "ModelAPI_AttributeDocRef.h"
 %include "ModelAPI_AttributeDouble.h"
+%include "ModelAPI_Iterator.h"
index e40e9f5b592dd45fe091fe378ad721a45cd160c6..50209d63ebfcbfecb31510da7dcc579b4ad11a11 100644 (file)
@@ -8,6 +8,7 @@
 #include <ModelAPI.h>
 #include <string>
 #include <memory>
+#include <vector>
 
 class ModelAPI_Feature;
 class ModelAPI_Iterator;
@@ -65,11 +66,9 @@ public:
   //! Redoes last operation
   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 to the document the new feature of the given feature id
+  //! \param creates feature and puts it in the document
+  MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID) = 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;
@@ -85,12 +84,16 @@ public:
   MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_Feature> 
     feature(const std::string& theGroupID, const int theIndex) = 0;
 
+  //! Returns the index of feature in the group (zero based)
+  MODELAPI_EXPORT virtual int featureIndex(std::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;
+
 protected:
   /// Only for SWIG wrapping it is here
   MODELAPI_EXPORT ModelAPI_Document()
-  {
-  }
-  ;
+  {}
 };
 
 #endif
index a33d05084ea4c88675d15d9b6a653e2ebf9eecdd..fd19221b0b246c4223ec5f9eec5bac5eadb27d8c 100644 (file)
@@ -6,24 +6,29 @@
 #define ModelAPI_Feature_HeaderFile
 
 #include "ModelAPI.h"
+#include "ModelAPI_PluginManager.h"
+
 #include <string>
 #include <memory>
 
 class ModelAPI_Object;
+class ModelAPI_Document;
 
 /**\class ModelAPI_Feature
  * \ingroup DataModel
  * \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 const std::string& getKind() = 0;
+
+  /// Returns to which group in the document must be added feature
+  virtual const std::string& getGroup() = 0;
 
   /// Request for initialization of data model of the feature: adding all attributes
   virtual void initAttributes() = 0;
@@ -32,7 +37,12 @@ public:
   virtual void execute() = 0;
 
   /// Returns the data manager of this feature
-  std::shared_ptr<ModelAPI_Object> data() {return myData;}
+  virtual std::shared_ptr<ModelAPI_Object> data() {return myData;}
+
+  /// Must return document where the new feature must be added to
+  /// By default it is current document
+  virtual std::shared_ptr<ModelAPI_Document> documentToAdd()
+  {return ModelAPI_PluginManager::get()->currentDocument();}
 
 protected:
   /// Use plugin manager for features creation: this method is 
index 22d2066b36cad4ad85fe0b0bec1efc44ce9eb40e..73187982f5e4269907a827353c924bbffc05a428 100644 (file)
@@ -34,6 +34,9 @@ public:
   /// Don't changes the current position of iterator. Not fast: iterates the left items.
   /// \returns number of left iterations
   virtual int numIterationsLeft() = 0;
+  /// Compares the current feature with the given one
+  /// \returns true if given feature equals to the current one
+  virtual bool is(std::shared_ptr<ModelAPI_Feature> theFeature) = 0;
 
 protected:
   /// Use plugin manager for features creation: this method is 
index 7f78a35ce277e7b98bb3ae200087394094398b61..cf81f99bfee1dda02e24ba738a498ef8c6aeaf65 100644 (file)
@@ -11,6 +11,7 @@
 
 class ModelAPI_AttributeDocRef;
 class ModelAPI_AttributeDouble;
+class ModelAPI_Document;
 
 /**\class ModelAPI_Object
  * \ingroup DataModel
@@ -39,6 +40,9 @@ public:
   /// \param theAttrType type of the created attribute (received from the type method)
   virtual void addAttribute(std::string theID, std::string theAttrType) = 0;
 
+  /// Returns the document of this data
+  virtual std::shared_ptr<ModelAPI_Document> document() = 0;
+
 protected:
   /// Objects are created for features automatically
   ModelAPI_Object()
index 34e5cca94d86107731235dd0cc50172140ca623d..3250bea97894ae162f2266645a16dbbd2ad47c6c 100644 (file)
@@ -23,9 +23,6 @@ class ModelAPI_Document;
 class MODELAPI_EXPORT ModelAPI_PluginManager
 {
 public:
-  /// Creates the feature object using plugins functionality
-  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 std::shared_ptr<ModelAPI_PluginManager> get();
 
@@ -50,7 +47,12 @@ public:
   ModelAPI_PluginManager();
 
 protected:
+  /// Creates the feature object using plugins functionality
+  virtual std::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID) = 0;
+
   static void SetPluginManager(std::shared_ptr<ModelAPI_PluginManager> theManager);
+
+  friend class Model_Document;
 };
 
 #endif
index fd9d69d8797293423a875263374dcbeb6021ff6c..5dca088f8ebb3ee320f21072327b511c40f88612 100644 (file)
@@ -28,3 +28,7 @@ void PartSetPlugin_Part::execute()
     aDocRef->setValue(aPartSetDoc->subDocument(data()->getName()));
   }
 }
+
+shared_ptr<ModelAPI_Document> PartSetPlugin_Part::documentToAdd() {
+  return ModelAPI_PluginManager::get()->rootDocument();
+}
index c40f1633dbef112e4456c8a5bd58d8fb974f8f98..f1ee4306421704bdbd9ddf2af2a055113f15e9b9 100644 (file)
@@ -19,7 +19,12 @@ class PartSetPlugin_Part: public ModelAPI_Feature
 {
 public:
   /// Returns the kind of a feature
-  PARTSETPLUGIN_EXPORT virtual std::string getKind() {return "Part";}
+  PARTSETPLUGIN_EXPORT virtual const std::string& getKind() 
+  {static std::string MY_KIND = "Part"; return MY_KIND;}
+
+  /// Returns to which group in the document must be added feature
+  PARTSETPLUGIN_EXPORT virtual const std::string& getGroup() 
+  {static std::string MY_GROUP = "Parts"; return MY_GROUP;}
 
   /// Creates a new part document if needed
   PARTSETPLUGIN_EXPORT virtual void execute();
@@ -27,6 +32,8 @@ public:
   /// Request for initialization of data model of the feature: adding all attributes
   PARTSETPLUGIN_EXPORT virtual void initAttributes();
 
+  PARTSETPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Document> documentToAdd();
+
   /// Use plugin manager for features creation
   PartSetPlugin_Part();
 };
index c1998aefa4ffe117e1eab7afbcbd663e5e8453ed..33323903724e41a2c8a97b33029a2c1d239c8069 100644 (file)
@@ -15,24 +15,13 @@ PartSetPlugin_Plugin::PartSetPlugin_Plugin()
   ModelAPI_PluginManager::get()->registerPlugin(this);
 }
 
-std::shared_ptr<ModelAPI_Feature> PartSetPlugin_Plugin::createFeature(string theFeatureID)
+shared_ptr<ModelAPI_Feature> PartSetPlugin_Plugin::createFeature(string theFeatureID)
 {
-  std::shared_ptr<ModelAPI_Feature> aCreated;
-  bool isCurrent = true; // to create a feature in the current document
   if (theFeatureID == "Part") {
-    aCreated = std::shared_ptr<ModelAPI_Feature>(new PartSetPlugin_Part);
-    isCurrent = false; // allways create in the root document
+    return shared_ptr<ModelAPI_Feature>(new PartSetPlugin_Part);
   } else if (theFeatureID == "Point") {
-    aCreated = std::shared_ptr<ModelAPI_Feature>(new PartSetPlugin_Point);
-  }
-
-  // add to a root document for the current moment
-  if (aCreated) {
-    shared_ptr<ModelAPI_Document> aDoc = isCurrent ? 
-      ModelAPI_PluginManager::get()->currentDocument() :
-      ModelAPI_PluginManager::get()->rootDocument();
-    aDoc->addFeature(aCreated, PARTS_GROUP);
+    return shared_ptr<ModelAPI_Feature>(new PartSetPlugin_Point);
   }
   // feature of such kind is not found
-  return aCreated;
+  return shared_ptr<ModelAPI_Feature>();
 }
index c5f3d2e14ca817f998053851c1433ecb673c421f..4a8766ae6e57335e756e9883ef15caebc8091bc4 100644 (file)
@@ -23,7 +23,12 @@ class PartSetPlugin_Point: public ModelAPI_Feature
 {
 public:
   /// Returns the kind of a feature
-  PARTSETPLUGIN_EXPORT virtual std::string getKind() {return "Point";}
+  PARTSETPLUGIN_EXPORT virtual const std::string& getKind() 
+  {static std::string MY_KIND = "Point"; return MY_KIND;}
+
+  /// Returns to which group in the document must be added feature
+  PARTSETPLUGIN_EXPORT virtual const std::string& getGroup() 
+  {static std::string MY_GROUP = "Construction"; return MY_GROUP;}
 
   /// Creates a new part document if needed
   PARTSETPLUGIN_EXPORT virtual void execute();