Salome HOME
Updated events for Model and minor other changes
authormpv <mikhail.ponikarov@opencascade.com>
Thu, 10 Apr 2014 13:37:17 +0000 (17:37 +0400)
committermpv <mikhail.ponikarov@opencascade.com>
Thu, 10 Apr 2014 13:37:17 +0000 (17:37 +0400)
24 files changed:
src/Config/Config_FeatureMessage.h
src/Config/Config_FeatureReader.h
src/Config/Config_ModuleReader.h
src/Config/Config_WidgetReader.h
src/Config/Config_XMLReader.h
src/Model/CMakeLists.txt
src/Model/Model_Application.cxx
src/Model/Model_Application.h
src/Model/Model_AttributeDocRef.h
src/Model/Model_AttributeDouble.h
src/Model/Model_Data.cxx [new file with mode: 0644]
src/Model/Model_Data.h [new file with mode: 0644]
src/Model/Model_Document.cxx
src/Model/Model_Document.h
src/Model/Model_Events.cxx [new file with mode: 0644]
src/Model/Model_Events.h [new file with mode: 0644]
src/Model/Model_Iterator.cxx
src/Model/Model_Object.cxx [deleted file]
src/Model/Model_Object.h [deleted file]
src/Model/Model_PluginManager.cxx
src/ModelAPI/ModelAPI_AttributeDouble.h
src/XGUI/CMakeLists.txt
src/XGUI/XGUI_DocumentDataModel.cpp
src/XGUI/XGUI_Viewer.cpp

index 8fce1b17369d6feee884351efea7d80c5bf76f6d..4185b4b9620831fa1bd01133e06b903339d6a530 100644 (file)
@@ -11,7 +11,7 @@
  * Example of the feature entry:\r
  * <feature id="Part" text="New part" tooltip="Creates a new part" icon=":pictures/part_ico.png"/>\r
  */\r
-class CONFIG_EXPORT Config_FeatureMessage: public Event_Message\r
+class Config_FeatureMessage: public Event_Message\r
 {\r
   std::string myId;  //Feature unique id\r
   std::string myText; //Represents action's text\r
@@ -25,31 +25,31 @@ class CONFIG_EXPORT Config_FeatureMessage: public Event_Message
 \r
 public:\r
   //const Event_ID theID, const void* theSender = 0\r
-  Config_FeatureMessage(const Event_ID theId, const void* theParent = 0);\r
+  CONFIG_EXPORT Config_FeatureMessage(const Event_ID theId, const void* theParent = 0);\r
 \r
   //TODO(sbh): Implement static method to extract event id [SEID]\r
   //static const char* eventId() { return ""; }\r
 \r
   //Auto-generated getters/setters\r
-  const std::string& icon() const;\r
-  const std::string& id() const;\r
-  const std::string& keysequence() const;\r
-  const std::string& text() const;\r
-  const std::string& tooltip() const;\r
-\r
-  const std::string& groupId() const;\r
-  const std::string& workbenchId() const;\r
-  const std::string& pluginLibrary() const;\r
-\r
-  void setIcon(const std::string& icon);\r
-  void setId(const std::string& id);\r
-  void setKeysequence(const std::string& keysequence);\r
-  void setText(const std::string& text);\r
-  void setTooltip(const std::string& tooltip);\r
-\r
-  void setGroupId(const std::string& groupId);\r
-  void setWorkbenchId(const std::string& workbenchId);\r
-  void setPluginLibrary(const std::string& thePluginLibrary);\r
+  CONFIG_EXPORT const std::string& icon() const;\r
+  CONFIG_EXPORT const std::string& id() const;\r
+  CONFIG_EXPORT const std::string& keysequence() const;\r
+  CONFIG_EXPORT const std::string& text() const;\r
+  CONFIG_EXPORT const std::string& tooltip() const;\r
+\r
+  CONFIG_EXPORT const std::string& groupId() const;\r
+  CONFIG_EXPORT const std::string& workbenchId() const;\r
+  CONFIG_EXPORT const std::string& pluginLibrary() const;\r
+\r
+  CONFIG_EXPORT void setIcon(const std::string& icon);\r
+  CONFIG_EXPORT void setId(const std::string& id);\r
+  CONFIG_EXPORT void setKeysequence(const std::string& keysequence);\r
+  CONFIG_EXPORT void setText(const std::string& text);\r
+  CONFIG_EXPORT void setTooltip(const std::string& tooltip);\r
+\r
+  CONFIG_EXPORT void setGroupId(const std::string& groupId);\r
+  CONFIG_EXPORT void setWorkbenchId(const std::string& workbenchId);\r
+  CONFIG_EXPORT void setPluginLibrary(const std::string& thePluginLibrary);\r
 };\r
 \r
 #endif // CONFIG_MESSAGE_H
index 117e8bd6ce18748c66e0e6bfedf2d05857cca997..da5fa77fea93a188d7db3ca6b4ffe831dffee718 100644 (file)
@@ -16,7 +16,7 @@
 
 class Config_FeatureMessage;
 
-class CONFIG_EXPORT Config_FeatureReader: public Config_XMLReader
+class Config_FeatureReader: public Config_XMLReader
 {
 public:
   Config_FeatureReader(const std::string& theXmlFile,
index 5a19c24c04667d9d738a51b814a9392e467aee65..33567bdd27aa495af8caad59436d0c9ba8a0fbed 100644 (file)
 #include <string>
 
 
-class CONFIG_EXPORT Config_ModuleReader: public Config_XMLReader
+class Config_ModuleReader: public Config_XMLReader
 {
 
 public:
-  Config_ModuleReader();
-  virtual ~Config_ModuleReader();
+  CONFIG_EXPORT Config_ModuleReader();
+  CONFIG_EXPORT virtual ~Config_ModuleReader();
 
-  void setAutoImport(bool enabled);
-  const std::map<std::string, std::string>& plugins() const;
+  CONFIG_EXPORT void setAutoImport(bool enabled);
+  CONFIG_EXPORT const std::map<std::string, std::string>& plugins() const;
 
-  std::string getModuleName();
+  CONFIG_EXPORT std::string getModuleName();
 
 protected:
   void processNode(xmlNodePtr aNode);
index 58fd904b062024a8658865e7b75d67f0e5748f3e..7b5aa86f4908e97aa352db1eebfd5ce62c91a978 100644 (file)
 #include <string>
 
 
-class CONFIG_EXPORT Config_WidgetReader: public Config_XMLReader
+class Config_WidgetReader: public Config_XMLReader
 {
 public:
-  Config_WidgetReader(const std::string& theXmlFile);
-  virtual ~Config_WidgetReader();
+  CONFIG_EXPORT Config_WidgetReader(const std::string& theXmlFile);
+  CONFIG_EXPORT virtual ~Config_WidgetReader();
 
-  std::string featureWidgetCfg(std::string theFeatureName);
+  CONFIG_EXPORT std::string featureWidgetCfg(std::string theFeatureName);
 
 protected:
   void processNode(xmlNodePtr theNode);
index 331de4b6b4383406639f112b18237a1796a04ccb..95d3ea651c49b4df5c83fd46d133d30b2f1b423e 100644 (file)
@@ -30,13 +30,13 @@ struct _xmlDoc;
  * for all xml operations.
  *
  */
-class CONFIG_EXPORT Config_XMLReader
+class Config_XMLReader
 {
 public:
-  Config_XMLReader(const std::string& theXmlFile);
-  virtual ~Config_XMLReader();
+  CONFIG_EXPORT Config_XMLReader(const std::string& theXmlFile);
+  CONFIG_EXPORT virtual ~Config_XMLReader();
 
-  void readAll();
+  CONFIG_EXPORT void readAll();
 
 protected:
   virtual void processNode(xmlNodePtr aNode);
index eca79ac1adc5a33e9eed2bdb82dc6c2f7d29af1f..48a70e9acdf6be457d8f1e9fb1c49110c516390b 100644 (file)
@@ -8,20 +8,22 @@ SET(PROJECT_HEADERS
     Model_Application.h
     Model_Document.h
     Model_PluginManager.h
-    Model_Object.h
+    Model_Data.h
     Model_Iterator.h
     Model_AttributeDouble.h
     Model_AttributeDocRef.h
+    Model_Events.h
 )
 
 SET(PROJECT_SOURCES
     Model_Application.cxx
     Model_Document.cxx
     Model_PluginManager.cxx
-    Model_Object.cxx
+    Model_Data.cxx
     Model_Iterator.cxx
     Model_AttributeDouble.cxx
     Model_AttributeDocRef.cxx
+    Model_Events.cxx
 )
 
 ADD_DEFINITIONS(-DMODEL_EXPORTS ${CAS_DEFINITIONS})
index 260db7d444ae0841f47903849630f20e3eb95b01..a8c8966b3962cb43eb08f6e3e72faea022fc9ffa 100644 (file)
@@ -25,14 +25,14 @@ Handle(Model_Application) Model_Application::getApplication()
 //function : getDocument
 //purpose  : 
 //=======================================================================
-std::shared_ptr<Model_Document> Model_Application::getDocument(string theDocID)
+const std::shared_ptr<Model_Document>& Model_Application::getDocument(string theDocID)
 {
   if (myDocs.find(theDocID) != myDocs.end())
     return myDocs[theDocID];
 
   std::shared_ptr<Model_Document> aNew(new Model_Document(theDocID));
   myDocs[theDocID] = aNew;
-  return aNew;
+  return myDocs[theDocID];
 }
 
 void Model_Application::deleteDocument(string theDocID)
index 998aba08b0792db08a6c1112a9ef3de1cf6c01f5..c4f578f0443e755afdbd314578199f3d91457f94 100644 (file)
@@ -30,7 +30,7 @@ public:
   //! Retuns the application: one per process    
   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);
+  MODEL_EXPORT const std::shared_ptr<Model_Document>& getDocument(std::string theDocID);
   //! Deletes the document from the application
   MODEL_EXPORT void deleteDocument(std::string theDocID);
 
index 2218557242fc5931548c5350ec8240f30f723465..778ed316bd0eceda4ef02932193287ca0b35bfb6 100644 (file)
  * \brief Attribute that contains reference to another document.
  */
 
-class MODEL_EXPORT Model_AttributeDocRef : public ModelAPI_AttributeDocRef
+class 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);
+  MODEL_EXPORT virtual void setValue(std::shared_ptr<ModelAPI_Document> theDoc);
 
   /// Returns document referenced from this attribute
-  virtual std::shared_ptr<ModelAPI_Document> value();
+  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> value();
 
 protected:
   /// Initializes attibutes
   Model_AttributeDocRef(TDF_Label& theLabel);
 
-  friend class Model_Object;
+  friend class Model_Data;
 };
 
 #endif
index d498bc42ba2e89b968102edf14e6da4685a0d2a2..0079b639ced68fb7b877a666a5ddc967392bf757 100644 (file)
  * \brief Attribute that contains real value with double precision.
  */
 
-class MODEL_EXPORT Model_AttributeDouble : public ModelAPI_AttributeDouble
+class Model_AttributeDouble : public ModelAPI_AttributeDouble
 {
   Handle_TDataStd_Real myReal; ///< double is Real attribute
 public:
   /// Defines the double value
-  virtual void setValue(const double theValue);
+  MODEL_EXPORT virtual void setValue(const double theValue);
 
   /// Returns the double value
-  virtual double value();
+  MODEL_EXPORT virtual double value();
 
 protected:
   /// Initializes attibutes
   Model_AttributeDouble(TDF_Label& theLabel);
 
-  friend class Model_Object;
+  friend class Model_Data;
 };
 
 #endif
diff --git a/src/Model/Model_Data.cxx b/src/Model/Model_Data.cxx
new file mode 100644 (file)
index 0000000..a9ac29b
--- /dev/null
@@ -0,0 +1,77 @@
+// File:        Model_Data.hxx
+// Created:     21 Mar 2014
+// Author:      Mikhail PONIKAROV
+
+#include <Model_Data.h>
+#include <Model_AttributeDocRef.h>
+#include <Model_AttributeDouble.h>
+#include <TDataStd_Name.hxx>
+
+using namespace std;
+
+Model_Data::Model_Data()
+{
+}
+
+void Model_Data::setLabel(TDF_Label& theLab)
+{
+  myLab = theLab;
+}
+
+string Model_Data::getName()
+{
+  Handle(TDataStd_Name) aName;
+  if (myLab.FindAttribute(TDataStd_Name::GetID(), aName))
+    return string(TCollection_AsciiString(aName->Get()).ToCString());
+  return ""; // not defined
+}
+
+void Model_Data::setName(string theName)
+{
+  TDataStd_Name::Set(myLab, theName.c_str());
+}
+
+void Model_Data::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);
+  else if (theAttrType == ModelAPI_AttributeDouble::type())
+    anAttr = new Model_AttributeDouble(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_Data::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;
+}
+
+shared_ptr<ModelAPI_AttributeDouble> Model_Data::real(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_AttributeDouble>();
+  }
+  shared_ptr<ModelAPI_AttributeDouble> aRes = 
+    dynamic_pointer_cast<ModelAPI_AttributeDouble>(aFound->second);
+  if (!aRes) {
+    // TODO: generate error on invalid attribute type request
+  }
+  return aRes;
+}
diff --git a/src/Model/Model_Data.h b/src/Model/Model_Data.h
new file mode 100644 (file)
index 0000000..b634d93
--- /dev/null
@@ -0,0 +1,63 @@
+// File:        Model_Data.hxx
+// Created:     21 Mar 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef Model_Data_HeaderFile
+#define Model_Data_HeaderFile
+
+#include "Model.h"
+#include <ModelAPI_Object.h>
+#include <TDF_Label.hxx>
+
+#include <map>
+
+class ModelAPI_Attribute;
+
+/**\class Model_Data
+ * \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_Data: 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_Data();
+
+  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
+  MODEL_EXPORT virtual std::string getName();
+  /// Defines the name of the feature visible by the user in the object browser
+  MODEL_EXPORT virtual void setName(std::string theName);
+  /// Returns the attribute that references to another document
+  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeDocRef> docRef(const std::string theID);
+  /// Returns the attribute that contains real value with double precision
+  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeDouble> real(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)
+  MODEL_EXPORT virtual void addAttribute(std::string theID, std::string theAttrType);
+
+  /// Returns the document of this data
+  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> document() {return myDoc;}
+
+  /// Puts feature to the document data sub-structure
+  MODEL_EXPORT void setLabel(TDF_Label& theLab);
+
+  /// Sets the document of this data
+  MODEL_EXPORT virtual void setDocument(const std::shared_ptr<ModelAPI_Document>& theDoc) {myDoc = theDoc;}
+};
+
+#endif
index 9eebe15d103f5f84e9dab52c49ae2b72ba55cd18..0e976420c45652ec8dd63448b16428dce0790e84 100644 (file)
@@ -4,10 +4,11 @@
 
 #include <Model_Document.h>
 #include <ModelAPI_Feature.h>
-#include <Model_Object.h>
+#include <Model_Data.h>
 #include <Model_Application.h>
 #include <Model_PluginManager.h>
 #include <Model_Iterator.h>
+#include <Model_Events.h>
 #include <Event_Loop.h>
 
 #include <TDataStd_Integer.hxx>
@@ -17,7 +18,7 @@
 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_OBJECTS = 2; // tag of the objects sub-tree (Root for Model_DatasMgr)
 static const int TAG_HISTORY = 3; // tag of the history sub-tree (Root for Model_History)
 
 using namespace std;
@@ -219,7 +220,7 @@ void Model_Document::addFeature(const std::shared_ptr<ModelAPI_Feature> theFeatu
   const std::string& aGroup = theFeature->getGroup();
   TDF_Label aGroupLab = groupLabel(aGroup);
   TDF_Label anObjLab = aGroupLab.NewChild();
-  std::shared_ptr<Model_Object> aData(new Model_Object);
+  std::shared_ptr<Model_Data> aData(new Model_Data);
   aData->setLabel(anObjLab);
   aData->setDocument(Model_Application::getApplication()->getDocument(myID));
   theFeature->setData(aData);
@@ -231,9 +232,9 @@ void Model_Document::addFeature(const std::shared_ptr<ModelAPI_Feature> theFeatu
   TDataStd_Integer::Set(anObjLab, myFeatures[aGroup].size());
   myFeatures[aGroup].push_back(theFeature);
 
-  // event: model is updated
-  static Event_ID anEvent = Event_Loop::eventByName(EVENT_FEATURE_UPDATED);
-  ModelAPI_FeatureUpdatedMessage aMsg(theFeature);
+  // event: feature is added
+  static Event_ID anEvent = Event_Loop::eventByName(EVENT_FEATURE_CREATED);
+  ModelAPI_FeatureUpdatedMessage aMsg(theFeature, anEvent);
   Event_Loop::loop()->send(aMsg);
 }
 
@@ -255,7 +256,7 @@ int Model_Document::featureIndex(shared_ptr<ModelAPI_Feature> theFeature)
   if (theFeature->data()->document().get() != this) {
     return theFeature->data()->document()->featureIndex(theFeature);
   }
-  shared_ptr<Model_Object> aData = dynamic_pointer_cast<Model_Object>(theFeature->data());
+  shared_ptr<Model_Data> aData = dynamic_pointer_cast<Model_Data>(theFeature->data());
   Handle(TDataStd_Integer) aFeatureIndex;
   if (aData->label().FindAttribute(TDataStd_Integer::GetID(), aFeatureIndex)) {
     return aFeatureIndex->Get();
@@ -389,7 +390,7 @@ void Model_Document::synchronizeFeatures()
       static const int INFINITE_TAG = MAXINT; // no label means that it exists somwhere in infinite
       int aFeatureTag = INFINITE_TAG; 
       if (aFIter != aFeatures.end()) { // existing tag for feature
-        shared_ptr<Model_Object> aData = dynamic_pointer_cast<Model_Object>((*aFIter)->data());
+        shared_ptr<Model_Data> aData = dynamic_pointer_cast<Model_Data>((*aFIter)->data());
         aFeatureTag = aData->label().Tag();
       }
       int aDSTag = INFINITE_TAG; 
@@ -398,21 +399,25 @@ void Model_Document::synchronizeFeatures()
       }
       if (aDSTag > aFeatureTag) { // feature is removed
         aFIter = aFeatures.erase(aFIter);
+        // event: model is updated
+        ModelAPI_FeatureDeletedMessage aMsg(
+          Model_Application::getApplication()->getDocument(myID), aGroupName);
+        Event_Loop::loop()->send(aMsg);
       } else if (aDSTag < aFeatureTag) { // a new feature is inserted
         // create a feature
         shared_ptr<ModelAPI_Feature> aFeature = ModelAPI_PluginManager::get()->createFeature(
           TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(
           aFLabIter.Value())->Get()).ToCString());
 
-        std::shared_ptr<Model_Object> aData(new Model_Object);
+        std::shared_ptr<Model_Data> aData(new Model_Data);
         TDF_Label aLab = aFLabIter.Value()->Label();
         aData->setLabel(aLab);
         aData->setDocument(Model_Application::getApplication()->getDocument(myID));
         aFeature->setData(aData);
         aFeature->initAttributes();
         // event: model is updated
-        static Event_ID anEvent = Event_Loop::eventByName(EVENT_FEATURE_UPDATED);
-        ModelAPI_FeatureUpdatedMessage aMsg(aFeature);
+        static Event_ID anEvent = Event_Loop::eventByName(EVENT_FEATURE_CREATED);
+        ModelAPI_FeatureUpdatedMessage aMsg(aFeature, anEvent);
         Event_Loop::loop()->send(aMsg);
 
         if (aFIter == aFeatures.end()) {
@@ -431,19 +436,3 @@ void Model_Document::synchronizeFeatures()
     }
   }
 }
-
-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 ec5de4b9f4c5869227c061952bd35e99f23a8333..678a3f83d00466f33a40db2fb7b0aaf94ea0e277 100644 (file)
@@ -7,7 +7,6 @@
 
 #include <Model.h>
 #include <ModelAPI_Document.h>
-#include <Event_Message.h>
 
 #include <TDocStd_Document.hxx>
 #include <map>
@@ -126,21 +125,4 @@ private:
   std::map<int, bool> myIsEmptyTr;
 };
 
-/// 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
diff --git a/src/Model/Model_Events.cxx b/src/Model/Model_Events.cxx
new file mode 100644 (file)
index 0000000..f9ddb0f
--- /dev/null
@@ -0,0 +1,24 @@
+// File:        Model_Events.cxx
+// Created:     10 Apr 2014
+// Author:      Mikhail PONIKAROV
+
+#include <Model_Events.h>
+#include <Event_Loop.h>
+
+ModelAPI_FeatureUpdatedMessage::ModelAPI_FeatureUpdatedMessage(
+  const std::shared_ptr<ModelAPI_Feature>& theFeature, const Event_ID& theEvent)
+  : Event_Message(theEvent, 0), myFeature(theFeature)
+{}
+
+ModelAPI_FeatureDeletedMessage::ModelAPI_FeatureDeletedMessage(
+  const std::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup)
+  : Event_Message(messageId(), 0), myDoc(theDoc), myGroup(theGroup)
+
+{
+}
+
+const Event_ID ModelAPI_FeatureDeletedMessage::messageId()
+{
+  static Event_ID MY_ID = Event_Loop::eventByName(EVENT_FEATURE_DELETED);
+  return MY_ID;
+}
diff --git a/src/Model/Model_Events.h b/src/Model/Model_Events.h
new file mode 100644 (file)
index 0000000..e969458
--- /dev/null
@@ -0,0 +1,54 @@
+// File:        Model_Events.h
+// Created:     10 Apr 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef Model_Events_HeaderFile
+#define Model_Events_HeaderFile
+
+#include <Model.h>
+#include <Event_Message.h>
+#include <memory>
+#include <string>
+
+class ModelAPI_Feature;
+class ModelAPI_Document;
+
+/// Event ID that feature is created (comes with ModelAPI_FeatureUpdatedMessage)
+static const char * EVENT_FEATURE_CREATED = "FeatureCreated";
+/// Event ID that data of feature is updated (comes with ModelAPI_FeatureUpdatedMessage)
+static const char * EVENT_FEATURE_UPDATED = "FeatureUpdated";
+/// Event ID that data of feature is deleted (comes with ModelAPI_FeatureDeletedMessage)
+static const char * EVENT_FEATURE_DELETED = "FeatureDeleted";
+
+/// 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(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+    const Event_ID& theEvent);
+
+  /// Returns the feature that has been updated
+  std::shared_ptr<ModelAPI_Feature> feature() {return myFeature;}
+};
+
+/// Message that feature was deleted (used for Object Browser update)
+class ModelAPI_FeatureDeletedMessage : public Event_Message {
+  std::shared_ptr<ModelAPI_Document> myDoc; ///< document owner of the feature
+  std::string myGroup; ///< group identifier that contained the deleted feature
+public:
+  /// creates a message by initialization of fields
+  ModelAPI_FeatureDeletedMessage(const std::shared_ptr<ModelAPI_Document>& theDoc,
+    const std::string& theGroup);
+
+  /// Returns the ID of this message (EVENT_FEATURE_DELETED)
+  static const Event_ID messageId();
+
+  /// Returns the feature that has been updated
+  std::shared_ptr<ModelAPI_Document> document() {return myDoc;}
+
+  /// Returns the group where the feature was deleted
+  const std::string& group() {return myGroup;}
+};
+
+#endif
index 42ed7309ffc8fa2d133f1ca636f26b220709bafa..b8a765d91a577ae16745f99f41b1a10f009794b0 100644 (file)
@@ -5,7 +5,7 @@
 #include "Model_Iterator.h"
 #include "Model_Document.h"
 #include "ModelAPI_Feature.h"
-#include "Model_Object.h"
+#include "Model_Data.h"
 #include <TDataStd_Comment.hxx>
 #include <TDataStd_Name.hxx>
 
@@ -54,7 +54,7 @@ int Model_Iterator::numIterationsLeft()
 bool Model_Iterator::is(std::shared_ptr<ModelAPI_Feature> theFeature)
 {
   return (myIter.Value()->Label() == 
-    dynamic_pointer_cast<Model_Object>(theFeature->data())->label()) == Standard_True;
+    dynamic_pointer_cast<Model_Data>(theFeature->data())->label()) == Standard_True;
 
 }
 
diff --git a/src/Model/Model_Object.cxx b/src/Model/Model_Object.cxx
deleted file mode 100644 (file)
index 0312a0c..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-// File:        Model_Object.hxx
-// Created:     21 Mar 2014
-// Author:      Mikhail PONIKAROV
-
-#include <Model_Object.h>
-#include <Model_AttributeDocRef.h>
-#include <Model_AttributeDouble.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);
-  else if (theAttrType == ModelAPI_AttributeDouble::type())
-    anAttr = new Model_AttributeDouble(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;
-}
-
-shared_ptr<ModelAPI_AttributeDouble> Model_Object::real(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_AttributeDouble>();
-  }
-  shared_ptr<ModelAPI_AttributeDouble> aRes = 
-    dynamic_pointer_cast<ModelAPI_AttributeDouble>(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
deleted file mode 100644 (file)
index 9a778c9..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-// 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;
-
-  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
-  MODEL_EXPORT virtual std::string getName();
-  /// Defines the name of the feature visible by the user in the object browser
-  MODEL_EXPORT virtual void setName(std::string theName);
-  /// Returns the attribute that references to another document
-  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeDocRef> docRef(const std::string theID);
-  /// Returns the attribute that contains real value with double precision
-  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeDouble> real(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)
-  MODEL_EXPORT virtual void addAttribute(std::string theID, std::string theAttrType);
-
-  /// Returns the document of this data
-  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> document() {return myDoc;}
-
-  /// Puts feature to the document data sub-structure
-  MODEL_EXPORT void setLabel(TDF_Label& theLab);
-
-  /// Sets the document of this data
-  MODEL_EXPORT virtual void setDocument(const std::shared_ptr<ModelAPI_Document>& theDoc) {myDoc = theDoc;}
-};
-
-#endif
index cca7b72fd9c4f44a97b33d04247d75270de6dced..ea0b826a646015a0606057a963dbf1d6848248c7 100644 (file)
@@ -5,7 +5,7 @@
 #include <Model_PluginManager.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Plugin.h>
-#include <Model_Object.h>
+#include <Model_Data.h>
 #include <Model_Document.h>
 #include <Model_Application.h>
 #include <Event_Loop.h>
index 7dfb882c308d8adb883f71304d0efc3f8fb706d0..cc6a2dd261cf864484584e00ed3755ef1fc3eaf2 100644 (file)
@@ -16,7 +16,7 @@ class MODELAPI_EXPORT ModelAPI_AttributeDouble : public ModelAPI_Attribute
 {
 public:
   /// Defines the double value
-  virtual void setValue(double theValue) = 0;
+  virtual void setValue(const double theValue) = 0;
 
   /// Returns the double value
   virtual double value() = 0;
index 33d7a9765a2ed09abc61c954a30e158a6b33e050..f428942ff1f5c490b024f3bcf2723a8ac60e8cca 100644 (file)
@@ -67,7 +67,6 @@ SET(PROJECT_LIBRARIES
        ${QT_QTMAIN_LIBRARY}
        ${CAS_VIEWER}
        ${CAS_KERNEL}
-    ${CAS_OCAF}
        PyConsole
        PyInterp
        PyEvent
index 0cb6233693614dfebc36e5b5e1b8dfe3c3a4e9eb..c3f8a437b13e4050370883f217dbb7cc3b405c83 100644 (file)
@@ -6,7 +6,7 @@
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Object.h>
-#include <Model_Document.h>
+#include <Model_Events.h>
 
 #include <Event_Loop.h>
 
index 6bec77168952fad966741f91e2c8b30c31822bb9..ed02e33b1ff2161568636af0b9008d353c3d23d3 100644 (file)
@@ -324,7 +324,7 @@ bool XGUI_Viewer::computeTrihedronSize(double& theNewSize, double& theSize)
   if (aMaxSide < Precision::Confusion())
     return false;
 
-  static float EPS = 5.0E-3;
+  static float EPS = (float)5.0E-3;
   theSize = trihedron()->Size();
   //theNewSize = aMaxSide*aSizeInPercents / 100.0;