Salome HOME
correction of Model_Data for AttributeRefAttrList
authornds <nds@opencascade.com>
Thu, 21 Jan 2016 09:18:25 +0000 (12:18 +0300)
committerdbv <dbv@opencascade.com>
Tue, 16 Feb 2016 14:04:25 +0000 (17:04 +0300)
src/Model/Model_AttributeRefAttrList.h
src/Model/Model_Data.cpp
src/Model/Model_Data.h
src/ModelAPI/ModelAPI_AttributeRefAttrList.h
src/ModelAPI/ModelAPI_Data.h
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetSelector.cpp
src/ModuleBase/ModuleBase_WidgetSelector.h
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h

index 0d36c383edde37b42acbc730938640c6a8239f94..2e666db26557e2cbab6388e40a6fbfa96574d990 100755 (executable)
@@ -60,7 +60,7 @@ class Model_AttributeRefAttrList : public ModelAPI_AttributeRefAttrList
   MODEL_EXPORT virtual AttributePtr attribute(const int theIndex) const;
 
   /// Removes the last element in the list.
-  MODEL_EXPORT virtual void removeLast() = 0;
+  MODEL_EXPORT virtual void removeLast();
 
   /// Removes the elements from the list.
   /// \param theIndices a list of indices of elements to be removed
index 067b3c6dfba39d2175def1ee3e5be4415ef9ffb7..530293b7e7061a9d5ae53833766eb8d3b7b9adf2 100644 (file)
@@ -11,6 +11,7 @@
 #include <Model_AttributeReference.h>
 #include <Model_AttributeRefAttr.h>
 #include <Model_AttributeRefList.h>
+#include <Model_AttributeRefAttrList.h>
 #include <Model_AttributeBoolean.h>
 #include <Model_AttributeString.h>
 #include <Model_AttributeSelection.h>
@@ -146,6 +147,8 @@ AttributePtr Model_Data::addAttribute(const std::string& theID, const std::strin
     anAttr = new Model_AttributeRefAttr(anAttrLab);
   } else if (theAttrType == ModelAPI_AttributeRefList::typeId()) {
     anAttr = new Model_AttributeRefList(anAttrLab);
+  } else if (theAttrType == ModelAPI_AttributeRefAttrList::typeId()) {
+    anAttr = new Model_AttributeRefAttrList(anAttrLab);
   } else if (theAttrType == ModelAPI_AttributeIntArray::typeId()) {
     anAttr = new Model_AttributeIntArray(anAttrLab);
   } 
@@ -202,6 +205,7 @@ GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelection, selection);
 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelectionList, selectionList);
 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefAttr, refattr);
 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefList, reflist);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefAttrList, refattrlist);
 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeIntArray, intArray);
 
 std::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string& theID)
@@ -525,6 +529,15 @@ void Model_Data::referencesToObjects(
       for(int a = aRef->size() - 1; a >= 0; a--) {
         aReferenced.push_back(aRef->value(a)->context());
       }
+    } else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
+      std::shared_ptr<ModelAPI_AttributeRefAttrList> aRefAttr = std::dynamic_pointer_cast<
+          ModelAPI_AttributeRefAttrList>(anAttr->second);
+      std::list<std::pair<ObjectPtr, AttributePtr> > aRefs = aRefAttr->list();
+      std::list<std::pair<ObjectPtr, AttributePtr> >::const_iterator anIt = aRefs.begin(),
+                                                                     aLast = aRefs.end();
+      for (; anIt != aLast; anIt++) {
+        aReferenced.push_back(anIt->first);
+      }
     } else if (aType == ModelAPI_AttributeInteger::typeId()) { // integer attribute
       AttributeIntegerPtr anAttribute =
           std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttr->second);
index ec219f55229fc86fae952a07ece680f1d3d9487b..8f8cfe5151f3d22f073a2120d45b10f1553e4bfe 100644 (file)
@@ -16,6 +16,7 @@
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_AttributeRefAttrList.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_AttributeIntArray.h>
 #include <ModelAPI_Data.h>
@@ -103,6 +104,10 @@ class Model_Data : public ModelAPI_Data
   /// Returns the attribute that contains list of references to features
   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeRefList>
     reflist(const std::string& theID);
+  /// Returns the attribute that contains list of references to features
+  /// or reference to an attribute of a feature
+  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeRefAttrList>
+    refattrlist(const std::string& theID);
   /// Returns the attribute that contains boolean value
   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeBoolean>
     boolean(const std::string& theID);
index 633bcb54db103321c02012803c68af91fc177b38..cd011712a5aa3dbdaab2b8ea814e003578602958 100755 (executable)
@@ -43,8 +43,7 @@ class ModelAPI_AttributeRefAttrList : public ModelAPI_Attribute
   virtual void clear() = 0;
 
   /// Returns number of features in the list
-  ///\param theWithEmpty if it is false, returns the number of not-empty referenced objects
-  virtual int size(const bool theWithEmpty = true) const = 0;
+  virtual int size() const = 0;
 
   /// Returns the list of features and attributes (if it is reference to the attribute)
   virtual std::list<std::pair<ObjectPtr, AttributePtr> > list() = 0;
index c9599820691e0201db1026df0264f2ce84a535ea..05dc2be644771e2b21e80311250421a2d14eb311 100644 (file)
@@ -24,6 +24,7 @@ class ModelAPI_AttributeDouble;
 class ModelAPI_AttributeReference;
 class ModelAPI_AttributeRefAttr;
 class ModelAPI_AttributeRefList;
+class ModelAPI_AttributeRefAttrList;
 class ModelAPI_AttributeBoolean;
 class ModelAPI_AttributeString;
 class ModelAPI_Document;
@@ -77,6 +78,9 @@ class MODELAPI_EXPORT ModelAPI_Data
   virtual std::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID) = 0;
   /// Returns the attribute that contains list of references to features
   virtual std::shared_ptr<ModelAPI_AttributeRefList> reflist(const std::string& theID) = 0;
+  /// Returns the attribute that contains list of references to features or reference to
+  /// an attribute of a feature
+  virtual std::shared_ptr<ModelAPI_AttributeRefAttrList> refattrlist(const std::string& theID) = 0;
   /// Returns the attribute that contains boolean value
   virtual std::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string& theID) = 0;
   /// Returns the attribute that contains boolean value
index 28d40d2829a9c617de91772783b11aec72d49d77..c8250969a14b0a3c665aaae4741d34b71ae4aca5 100755 (executable)
@@ -247,9 +247,8 @@ bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerP
   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
   std::string aType = anAttribute->attributeType();
   if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
-    AttributeRefAttrListPtr aRefAttrListAttr =
+    AttributeRefAttrListPtr aRefAttrListAttr = 
                  std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
-
     bool isDone = false;
     if (!thePrs.shape().IsNull()) {
       GeomShapePtr aGeomShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape);
@@ -261,15 +260,21 @@ bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerP
         isDone = true;
       }
     }
-    if (!isDone)
-      ModuleBase_WidgetSelector::setSelectionCustom(thePrs);
+    if (!isDone) {
+      //ModuleBase_WidgetSelector::setSelectionCustom(thePrs);
+      ObjectPtr anObject;
+      GeomShapePtr aShape;
+      getGeomSelection(thePrs, anObject, aShape);
+      setObject(anObject, aShape);
+    }
   }
   else {
-    ModuleBase_WidgetSelector::setSelectionCustom(thePrs);
-    /*ObjectPtr anObject;
+    //ModuleBase_WidgetSelector::setSelectionCustom(thePrs);
+
+    ObjectPtr anObject;
     GeomShapePtr aShape;
     getGeomSelection(thePrs, anObject, aShape);
-    setObject(anObject, aShape);*/
+    setObject(anObject, aShape);
   }
   return true;
 }
index 0f0b2c15a8eda3efe5a491fa3fa50df0ec93a98b..c5be67919c214a1eca31ed60a5e52eb68b83ad39 100755 (executable)
@@ -150,17 +150,6 @@ bool ModuleBase_WidgetSelector::isValidSelectionCustom(const ModuleBase_ViewerPr
   return aValid;
 }
 
-//********************************************************************
-bool ModuleBase_WidgetSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
-{
-  ObjectPtr anObject;
-  GeomShapePtr aShape;
-  getGeomSelection(thePrs, anObject, aShape);
-
-  setObject(anObject, aShape);
-  return true;
-}
-
 //********************************************************************
 void ModuleBase_WidgetSelector::deactivate()
 {
index 150a0ce349d07410f8403d447a8fb27c9372e547..8a282c3625b3e80f49a8ac0a3159c837d2907af3 100755 (executable)
@@ -51,10 +51,6 @@ Q_OBJECT
   /// \return a boolean value
   virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
 
-  /// Fills the attribute with the value of the selected owner
-  /// \param thePrs a selected owner
-  virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
-
   /// The methiod called when widget is deactivated
   virtual void deactivate();
 
index a51e16be651c62dc2258c39e65d020d8bdf05cd5..e062d4f096e28ba2bb3a098a36247f265790c10c 100644 (file)
@@ -111,25 +111,24 @@ void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject,
                                                GeomShapePtr theShape)
 {
   DataPtr aData = myFeature->data();
-  AttributeReferencePtr aRef = aData->reference(attributeID());
-  if (aRef) {
+  std::string aType = aData->attribute(attributeID())->attributeType();
+  if (aType == ModelAPI_AttributeReference::typeId()) {
+    AttributeReferencePtr aRef = aData->reference(attributeID());
     ObjectPtr aObject = aRef->value();
     if (!(aObject && aObject->isSame(theSelectedObject))) {
       aRef->setValue(theSelectedObject);
     }
-  } else {
+  } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
     AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
-    if (aRefAttr) {
-      ObjectPtr aObject = aRefAttr->object();
-      if (!(aObject && aObject->isSame(theSelectedObject))) {
-        aRefAttr->setObject(theSelectedObject);
-      }
-    } else {
-      AttributeSelectionPtr aSelectAttr = aData->selection(attributeID());
-      ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
-      if (aSelectAttr.get() != NULL) {
-        aSelectAttr->setValue(aResult, theShape);
-      }
+    ObjectPtr aObject = aRefAttr->object();
+    if (!(aObject && aObject->isSame(theSelectedObject))) {
+      aRefAttr->setObject(theSelectedObject);
+    }
+  } else if (aType == ModelAPI_AttributeSelection::typeId()) {
+    AttributeSelectionPtr aSelectAttr = aData->selection(attributeID());
+    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
+    if (aSelectAttr.get() != NULL) {
+      aSelectAttr->setValue(aResult, theShape);
     }
   }
 }
@@ -275,3 +274,14 @@ void ModuleBase_WidgetShapeSelector::restoreAttributeValue(bool theValid)
       aRefAttr->setAttr(myRefAttribute);
   }
 }
+
+//********************************************************************
+bool ModuleBase_WidgetShapeSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
+{
+  ObjectPtr anObject;
+  GeomShapePtr aShape;
+  getGeomSelection(thePrs, anObject, aShape);
+
+  setObject(anObject, aShape);
+  return true;
+}
index 2c8a10363e630fcade439ae6b895a0545e62459f..a750c80331fd29e6c23b69dda819d730e97d51eb 100644 (file)
@@ -104,6 +104,10 @@ Q_OBJECT
   /// \return a list of shapes
   virtual QIntList getShapeTypes() const;
 
+  /// Fills the attribute with the value of the selected owner
+  /// \param thePrs a selected owner
+  virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
+
   /// Store the values to the model attribute of the widget. It casts this attribute to
   /// the specific type and set the given values
   /// \param theSelectedObject an object