Salome HOME
The list of selection attributes is added
authormpv <mikhail.ponikarov@opencascade.com>
Wed, 22 Oct 2014 13:24:51 +0000 (17:24 +0400)
committermpv <mikhail.ponikarov@opencascade.com>
Wed, 22 Oct 2014 13:24:51 +0000 (17:24 +0400)
src/Model/CMakeLists.txt
src/Model/Model_AttributeSelection.h
src/Model/Model_AttributeSelectionList.cpp [new file with mode: 0644]
src/Model/Model_AttributeSelectionList.h [new file with mode: 0644]
src/Model/Model_Data.cpp
src/Model/Model_Data.h
src/ModelAPI/CMakeLists.txt
src/ModelAPI/ModelAPI.i
src/ModelAPI/ModelAPI_AttributeSelectionList.h [new file with mode: 0644]
src/ModelAPI/ModelAPI_Data.h
src/ModelAPI/ModelAPI_Session.cpp

index c9715ebc2fc95683283cd4f0ff189ae166504ecb..25626636a6b84efb703e177012b6a97e7e2e0a29 100644 (file)
@@ -15,6 +15,7 @@ SET(PROJECT_HEADERS
     Model_AttributeString.h
     Model_AttributeInteger.h
     Model_AttributeSelection.h
+    Model_AttributeSelectionList.h
     Model_Events.h
     Model_Update.h
     Model_Validator.h
@@ -38,6 +39,7 @@ SET(PROJECT_SOURCES
     Model_AttributeString.cpp
     Model_AttributeInteger.cpp
     Model_AttributeSelection.cpp
+    Model_AttributeSelectionList.cpp
     Model_Events.cpp
     Model_Update.cpp
     Model_Validator.cpp
index b41c4dffc83712520ab9aef3052f8499871f2926..2e71baea1c1406510278abcce44fdf12118a74ef 100644 (file)
@@ -28,6 +28,7 @@ public:
   /// Returns the context of the selection (the whole shape owner)
   MODEL_EXPORT virtual ResultPtr context();
 
+  /// Sets the feature object
   MODEL_EXPORT virtual void setObject(const boost::shared_ptr<ModelAPI_Object>& theObject);
 
 protected:
@@ -43,6 +44,7 @@ protected:
     const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape);
 
   friend class Model_Data;
+  friend class Model_AttributeSelectionList;
 };
 
 #endif
diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp
new file mode 100644 (file)
index 0000000..8483411
--- /dev/null
@@ -0,0 +1,71 @@
+// File:        Model_AttributeSelectionList.h
+// Created:     22 Oct 2014
+// Author:      Mikhail PONIKAROV
+
+#include "Model_AttributeSelectionList.h"
+#include "Model_AttributeSelection.h"
+#include "Model_Application.h"
+#include "Model_Events.h"
+#include "Model_Data.h"
+
+#include <TDF_ChildIterator.hxx>
+
+using namespace std;
+
+void Model_AttributeSelectionList::append(
+    const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
+{
+  int aNewTag = mySize->Get() + 1;
+  TDF_Label aNewLab = mySize->Label().FindChild(aNewTag);
+  mySubs.push_back(boost::shared_ptr<Model_AttributeSelection>(
+    new Model_AttributeSelection(aNewLab)));
+  mySize->Set(aNewTag);
+}
+
+int Model_AttributeSelectionList::size()
+{
+  return mySize->Get();
+}
+
+boost::shared_ptr<ModelAPI_AttributeSelection> 
+  Model_AttributeSelectionList::value(const int theIndex)
+{
+  return mySubs[theIndex];
+}
+
+void Model_AttributeSelectionList::clear()
+{
+  mySubs.clear();
+  TDF_ChildIterator aSubIter(mySize->Label());
+  for(; aSubIter.More(); aSubIter.Next()) {
+    aSubIter.Value().ForgetAllAttributes(Standard_True);
+  }
+}
+
+Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel)
+{
+  myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True;
+  if (!myIsInitialized) {
+    mySize = TDataStd_Integer::Set(theLabel, 0);
+  } else { // recollect mySubs
+    int aNum = mySize->Get();
+    TDF_ChildIterator aSubIter(theLabel);
+    for(; aSubIter.More(), aNum != 0; aSubIter.Next(), aNum--) {
+      TDF_Label aChildLab = aSubIter.Value();
+      boost::shared_ptr<Model_AttributeSelection> aNewAttr = 
+        boost::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aChildLab));
+      if (owner())
+        aNewAttr->setObject(owner());
+      mySubs.push_back(aNewAttr);
+    }
+  }
+}
+
+void Model_AttributeSelectionList::setObject(const boost::shared_ptr<ModelAPI_Object>& theObject)
+{
+  ModelAPI_AttributeSelectionList::setObject(theObject);
+  std::vector<boost::shared_ptr<Model_AttributeSelection> >::iterator aSubIter = mySubs.begin();
+  for(; aSubIter != mySubs.end(); aSubIter++) {
+    (*aSubIter)->setObject(theObject);
+  }
+}
diff --git a/src/Model/Model_AttributeSelectionList.h b/src/Model/Model_AttributeSelectionList.h
new file mode 100644 (file)
index 0000000..103b213
--- /dev/null
@@ -0,0 +1,49 @@
+// File:        Model_AttributeSelectionList.h
+// Created:     22 Oct 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef Model_AttributeSelectionList_H_
+#define Model_AttributeSelectionList_H_
+
+#include "Model.h"
+#include "Model_AttributeSelection.h"
+#include <ModelAPI_AttributeSelectionList.h>
+#include <TDataStd_Integer.hxx>
+#include <vector>
+
+/**\class Model_AttributeSelectionList
+ * \ingroup DataModel
+ * \brief Attribute that contains list of references to the sub-shapes with
+ * possibility to manage them.
+ */
+
+class Model_AttributeSelectionList : public ModelAPI_AttributeSelectionList
+{
+  Handle(TDataStd_Integer) mySize;  ///< Contains size of this list
+  std::vector<boost::shared_ptr<Model_AttributeSelection> > mySubs; /// the selection attributes
+public:
+  /// Adds the new reference to the end of the list
+  MODEL_EXPORT virtual void append(
+    const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape);
+
+  /// Returns the number ofselection attributes in the list
+  MODEL_EXPORT virtual int size();
+
+  /// Returns the attribute selection by the index (zero based)
+  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeSelection> value(const int theIndex);
+
+  /// Returns all attributes
+  MODEL_EXPORT virtual void clear();
+
+  /// Sets the feature object
+  MODEL_EXPORT virtual void setObject(const boost::shared_ptr<ModelAPI_Object>& theObject);
+
+protected:
+  /// Objects are created for features automatically
+  MODEL_EXPORT Model_AttributeSelectionList(TDF_Label& theLabel);
+    /// Performs the selection for the body result (TNaming Selection)
+
+  friend class Model_Data;
+};
+
+#endif
index c76a2f26f8e8f9297e451bc6d400395e2bb45539..7b25cb2402ade82d8c1f59edd252cb414188cc11 100644 (file)
@@ -12,6 +12,7 @@
 #include <Model_AttributeBoolean.h>
 #include <Model_AttributeString.h>
 #include <Model_AttributeSelection.h>
+#include <Model_AttributeSelectionList.h>
 #include <Model_Events.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Result.h>
@@ -76,6 +77,8 @@ void Model_Data::addAttribute(const std::string& theID, const std::string theAtt
     anAttr = new Model_AttributeReference(anAttrLab);
   } else if (theAttrType == ModelAPI_AttributeSelection::type()) {
     anAttr = new Model_AttributeSelection(anAttrLab);
+  } else if (theAttrType == ModelAPI_AttributeSelectionList::type()) {
+    anAttr = new Model_AttributeSelectionList(anAttrLab);
   } else if (theAttrType == ModelAPI_AttributeRefAttr::type()) {
     anAttr = new Model_AttributeRefAttr(anAttrLab);
   } else if (theAttrType == ModelAPI_AttributeRefList::type()) {
@@ -97,7 +100,8 @@ void Model_Data::addAttribute(const std::string& theID, const std::string theAtt
 
 boost::shared_ptr<ModelAPI_AttributeDocRef> Model_Data::document(const std::string& theID)
 {
-  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+  std::map<std::string, boost::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 boost::shared_ptr<ModelAPI_AttributeDocRef>();
@@ -112,7 +116,8 @@ boost::shared_ptr<ModelAPI_AttributeDocRef> Model_Data::document(const std::stri
 
 boost::shared_ptr<ModelAPI_AttributeDouble> Model_Data::real(const std::string& theID)
 {
-  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+  std::map<std::string, boost::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 boost::shared_ptr<ModelAPI_AttributeDouble>();
@@ -127,7 +132,8 @@ boost::shared_ptr<ModelAPI_AttributeDouble> Model_Data::real(const std::string&
 
 boost::shared_ptr<ModelAPI_AttributeInteger> Model_Data::integer(const std::string& theID)
 {
-  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+  std::map<std::string, boost::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 boost::shared_ptr<ModelAPI_AttributeInteger>();
@@ -142,7 +148,8 @@ boost::shared_ptr<ModelAPI_AttributeInteger> Model_Data::integer(const std::stri
 
 boost::shared_ptr<ModelAPI_AttributeBoolean> Model_Data::boolean(const std::string& theID)
 {
-  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+  std::map<std::string, boost::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 boost::shared_ptr<ModelAPI_AttributeBoolean>();
@@ -157,7 +164,8 @@ boost::shared_ptr<ModelAPI_AttributeBoolean> Model_Data::boolean(const std::stri
 
 boost::shared_ptr<ModelAPI_AttributeString> Model_Data::string(const std::string& theID)
 {
-  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+  std::map<std::string, boost::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 boost::shared_ptr<ModelAPI_AttributeString>();
@@ -173,7 +181,8 @@ boost::shared_ptr<ModelAPI_AttributeString> Model_Data::string(const std::string
 
 boost::shared_ptr<ModelAPI_AttributeReference> Model_Data::reference(const std::string& theID)
 {
-  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+  std::map<std::string, boost::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 boost::shared_ptr<ModelAPI_AttributeReference>();
@@ -188,7 +197,8 @@ boost::shared_ptr<ModelAPI_AttributeReference> Model_Data::reference(const std::
 
 boost::shared_ptr<ModelAPI_AttributeSelection> Model_Data::selection(const std::string& theID)
 {
-  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+  std::map<std::string, boost::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 boost::shared_ptr<ModelAPI_AttributeSelection>();
@@ -201,9 +211,27 @@ boost::shared_ptr<ModelAPI_AttributeSelection> Model_Data::selection(const std::
   return aRes;
 }
 
+boost::shared_ptr<ModelAPI_AttributeSelectionList> 
+  Model_Data::selectionList(const std::string& theID)
+{
+  std::map<std::string, boost::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 boost::shared_ptr<ModelAPI_AttributeSelectionList>();
+  }
+  boost::shared_ptr<ModelAPI_AttributeSelectionList> aRes = 
+    boost::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aFound->second);
+  if (!aRes) {
+    // TODO: generate error on invalid attribute type request
+  }
+  return aRes;
+}
+
 boost::shared_ptr<ModelAPI_AttributeRefAttr> Model_Data::refattr(const std::string& theID)
 {
-  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+  std::map<std::string, boost::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 boost::shared_ptr<ModelAPI_AttributeRefAttr>();
@@ -218,7 +246,8 @@ boost::shared_ptr<ModelAPI_AttributeRefAttr> Model_Data::refattr(const std::stri
 
 boost::shared_ptr<ModelAPI_AttributeRefList> Model_Data::reflist(const std::string& theID)
 {
-  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+  std::map<std::string, boost::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 boost::shared_ptr<ModelAPI_AttributeRefList>();
@@ -241,7 +270,8 @@ boost::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string& t
 
 const std::string& Model_Data::id(const boost::shared_ptr<ModelAPI_Attribute>& theAttr)
 {
-  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = myAttrs.begin();
+  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = 
+    myAttrs.begin();
   for (; anAttr != myAttrs.end(); anAttr++) {
     if (anAttr->second == theAttr)
       return anAttr->first;
index 8aead1b5b9c1a0e0b8435307d67f446095ca6220..c923d79aff29905090c06d7c5044bb2ffe270a31 100644 (file)
@@ -76,6 +76,9 @@ class Model_Data : public ModelAPI_Data
   /// Returns the attribute that contains selection to a shape
   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeSelection>
     selection(const std::string& theID);
+  /// Returns the attribute that contains selection to a shape
+  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeSelectionList> 
+    selectionList(const std::string& theID);
   /// Returns the attribute that contains reference to an attribute of a feature
   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeRefAttr>
     refattr(const std::string& theID);
index 13e4ee12ee28db715e778ed6d4ba2b257e57d0ac..9bebf30fbb0812a0ed77c4f41b42b5c004d372a2 100644 (file)
@@ -22,6 +22,7 @@ SET(PROJECT_HEADERS
     ModelAPI_AttributeBoolean.h
     ModelAPI_AttributeString.h
     ModelAPI_AttributeSelection.h
+    ModelAPI_AttributeSelectionList.h
     ModelAPI_Events.h
     ModelAPI_Validator.h
     ModelAPI_FeatureValidator.h
index 0eb00bd495b6bb40e5d44883ea780f9050d4a502..7ff2bfc8e52974b6b3030849510dac2f7d67c6e1 100644 (file)
@@ -17,6 +17,7 @@
   #include "ModelAPI_AttributeReference.h"
   #include "ModelAPI_AttributeRefAttr.h"
   #include "ModelAPI_AttributeSelection.h"
+  #include "ModelAPI_AttributeSelectionList.h"
   #include "ModelAPI_Validator.h"
   #include "ModelAPI_AttributeRefList.h"
   #include "ModelAPI_AttributeBoolean.h"
@@ -62,6 +63,7 @@
 %shared_ptr(ModelAPI_AttributeRefList)
 %shared_ptr(ModelAPI_AttributeBoolean)
 %shared_ptr(ModelAPI_AttributeSelection)
+%shared_ptr(ModelAPI_AttributeSelectionList)
 %shared_ptr(ModelAPI_Result)
 %shared_ptr(ModelAPI_ResultConstruction)
 %shared_ptr(ModelAPI_ResultBody)
@@ -84,6 +86,7 @@
 %include "ModelAPI_AttributeRefAttr.h"
 %include "ModelAPI_AttributeBoolean.h"
 %include "ModelAPI_AttributeSelection.h"
+%include "ModelAPI_AttributeSelectionList.h"
 %include "ModelAPI_AttributeRefList.h"
 %include "ModelAPI_Validator.h"
 %include "ModelAPI_Result.h"
diff --git a/src/ModelAPI/ModelAPI_AttributeSelectionList.h b/src/ModelAPI/ModelAPI_AttributeSelectionList.h
new file mode 100644 (file)
index 0000000..4305471
--- /dev/null
@@ -0,0 +1,57 @@
+// File:        ModelAPI_AttributeSelectionList.h
+// Created:     22 Oct 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef ModelAPI_AttributeSelectionList_H_
+#define ModelAPI_AttributeSelectionList_H_
+
+#include "ModelAPI_AttributeSelection.h"
+#include <ModelAPI_Result.h>
+
+/**\class ModelAPI_AttributeSelectionList
+ * \ingroup DataModel
+ * \brief Attribute that contains list of references to the sub-shapes with
+ * possibility to manage them.
+ */
+
+class ModelAPI_AttributeSelectionList : public ModelAPI_Attribute
+{
+ public:
+  /// Adds the new reference to the end of the list
+  virtual void append(
+    const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape) = 0;
+
+  /// Returns the number ofselection attributes in the list
+  virtual int size() = 0;
+
+  /// Returns the attribute selection by the index (zero based)
+  virtual boost::shared_ptr<ModelAPI_AttributeSelection> value(const int theIndex) = 0;
+
+  /// Returns all attributes
+  virtual void clear() = 0;
+
+  /// Returns the type of this class of attributes
+  static std::string type()
+  {
+    return "SelectionList";
+  }
+
+  /// Returns the type of this class of attributes, not static method
+  virtual std::string attributeType()
+  {
+    return type();
+  }
+
+  /// To virtually destroy the fields of successors
+  virtual ~ModelAPI_AttributeSelectionList()
+  {
+  }
+
+ protected:
+  /// Objects are created for features automatically
+  MODELAPI_EXPORT ModelAPI_AttributeSelectionList()
+  {
+  }
+};
+
+#endif
index 1bd01c5b3692d1ab9fa97bcbe0edc21c0277b9c7..e9852e6e26a6936d70ab8e2eace6e1135eed5555 100644 (file)
@@ -22,6 +22,7 @@ class ModelAPI_Document;
 class ModelAPI_Attribute;
 class ModelAPI_Feature;
 class ModelAPI_AttributeSelection;
+class ModelAPI_AttributeSelectionList;
 class GeomAPI_Shape;
 
 /**\class ModelAPI_Data
@@ -50,6 +51,9 @@ class MODELAPI_EXPORT ModelAPI_Data
   virtual boost::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID) = 0;
   /// Returns the attribute that contains selection to a shape
   virtual boost::shared_ptr<ModelAPI_AttributeSelection> selection(const std::string& theID) = 0;
+  /// Returns the attribute that contains selection to a shape
+  virtual boost::shared_ptr<ModelAPI_AttributeSelectionList> 
+    selectionList(const std::string& theID) = 0;
   /// Returns the attribute that contains reference to an attribute of a feature
   virtual boost::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID) = 0;
   /// Returns the attribute that contains list of references to features
index 137f8f8a54abce115a3e9970efb20d32bc507a25..db8a54ca2c32b820601dcd261c42429dd40f8633 100644 (file)
@@ -23,6 +23,7 @@
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_AttributeBoolean.h>
 #include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Validator.h>