]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Groups transactions mechanism debug
authormpv <mikhail.ponikarov@opencascade.com>
Fri, 7 Nov 2014 10:53:02 +0000 (13:53 +0300)
committermpv <mikhail.ponikarov@opencascade.com>
Fri, 7 Nov 2014 10:53:02 +0000 (13:53 +0300)
src/Model/Model_AttributeSelectionList.cpp
src/Model/Model_AttributeSelectionList.h
src/Model/Model_ResultGroup.cpp
src/ModelAPI/ModelAPI_Tools.cpp
src/XGUI/XGUI_Selection.cpp

index e1cb750aab27fc804b051e4c8539dc277be2c0f9..443eed177df90299df12ba056135db6f98627c5b 100644 (file)
@@ -15,6 +15,8 @@ using namespace std;
 void Model_AttributeSelectionList::append(
     const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
 {
+  updateSubs();
+
   int aNewTag = mySize->Get() + 1;
   TDF_Label aNewLab = mySize->Label().FindChild(aNewTag);
 
@@ -47,12 +49,13 @@ void Model_AttributeSelectionList::setSelectionType(int theType)
 boost::shared_ptr<ModelAPI_AttributeSelection> 
   Model_AttributeSelectionList::value(const int theIndex)
 {
+  updateSubs();
   return mySubs[theIndex];
 }
 
 void Model_AttributeSelectionList::clear()
 {
-  if (!mySubs.empty()) {
+  if (mySize->Get() != 0) {
     mySize->Set(0);
     mySubs.clear();
     TDF_ChildIterator aSubIter(mySize->Label());
@@ -70,16 +73,8 @@ Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel)
     mySize = TDataStd_Integer::Set(theLabel, 0);
     mySelectionType = TDataStd_Real::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);
-    }
+    theLabel.FindAttribute(TDataStd_Real::GetID(), mySelectionType);
+    updateSubs();
   }
 }
 
@@ -91,3 +86,28 @@ void Model_AttributeSelectionList::setObject(const boost::shared_ptr<ModelAPI_Ob
     (*aSubIter)->setObject(theObject);
   }
 }
+
+void Model_AttributeSelectionList::updateSubs()
+{
+  unsigned int aNum = mySize->Get();
+  if (aNum > mySubs.size()) { // add subs what are not yet created
+    TDF_ChildIterator aSubIter(mySize->Label());
+    for(int aExisting = mySubs.size(); aExisting > 0; aSubIter.Next()) aExisting--;
+    for(; aSubIter.More(); aSubIter.Next()) {
+      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);
+    }
+  } else if (aNum < mySubs.size()) { // remove excess subs from the end
+    if (aNum == 0) {
+      mySubs.clear();
+    } else {
+      std::vector<boost::shared_ptr<Model_AttributeSelection> >::iterator aSubIter;
+      for(int aExisting = aNum; aExisting != 0; aSubIter++) aExisting--;
+      mySubs.erase(aSubIter, mySubs.end());
+    }
+  }
+}
index f10d6d97fa0e21e35c0aa3e2cd5b6d28e71929b7..51001b6d0bbb1918df625d4c233a88981784600d 100644 (file)
@@ -47,7 +47,8 @@ public:
 protected:
   /// Objects are created for features automatically
   MODEL_EXPORT Model_AttributeSelectionList(TDF_Label& theLabel);
-    /// Performs the selection for the body result (TNaming Selection)
+  /// Updates the mySubs if needed since it is not persistent value
+  void updateSubs();
 
   friend class Model_Data;
 };
index 2fd1ead9d9caec79bc5472699d5c108bafd9a236..3e467395d827eded82e71d7e8ceb128c715bc4df 100644 (file)
@@ -19,7 +19,7 @@ boost::shared_ptr<GeomAPI_Shape> Model_ResultGroup::shape() const
     AttributeSelectionListPtr aList = myOwnerData->selectionList("group_list");
     if (aList) {
       std::list<boost::shared_ptr<GeomAPI_Shape> > aSubs;
-      for(int a = aList->size(); a >= 0; a--) {
+      for(int a = aList->size() - 1; a >= 0; a--) {
         boost::shared_ptr<GeomAPI_Shape> aSelection = aList->value(a)->value();
         if (aSelection && !aSelection->isNull()) {
           aSubs.push_back(aSelection);
index 52b88b5b05aa4200a5d298039ed8bf6bbf34503a..8656f2fd7545adda30c425bc11eeeee263e04519 100644 (file)
@@ -5,19 +5,25 @@
 #include "ModelAPI_Tools.h"
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_ResultGroup.h>
 
 namespace ModelAPI_Tools {
 
-boost::shared_ptr<GeomAPI_Shape> shape(const ResultPtr& theResult)
-{
-  ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
-  if (aBody)
-    return aBody->shape();
-  ResultConstructionPtr aConstruct = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(
+  boost::shared_ptr<GeomAPI_Shape> shape(const ResultPtr& theResult)
+  {
+
+    ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+    if (aBody)
+      return aBody->shape();
+
+    ResultConstructionPtr aConstruct = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(
       theResult);
-  if (aConstruct)
-    return aConstruct->shape();
-  return boost::shared_ptr<GeomAPI_Shape>();
-}
+    if (aConstruct)
+      return aConstruct->shape();
 
+    ResultGroupPtr aGroup = boost::dynamic_pointer_cast<ModelAPI_ResultGroup>(theResult);
+    if (aGroup)
+      return aGroup->shape();
+    return boost::shared_ptr<GeomAPI_Shape>();
+  }
 }
index 0dd985f977c8c8c5c7a4aac0b3007b1f0c51079b..265fb9029145f05e8a63370042d921408ef64bff 100644 (file)
@@ -125,10 +125,12 @@ void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList,
     if (!aShape.IsNull()) {
       theList.Append(aShape);
       Handle(SelectMgr_EntityOwner) aEO = aContext->SelectedOwner();
-      Handle(AIS_InteractiveObject) anObj = 
-        Handle(AIS_InteractiveObject)::DownCast(aEO->Selectable());
-      ObjectPtr anObject = myWorkshop->displayer()->getObject(anObj);
-      theOwners.push_back(anObject);
+      if (!aEO.IsNull()) {
+        Handle(AIS_InteractiveObject) anObj = 
+          Handle(AIS_InteractiveObject)::DownCast(aEO->Selectable());
+        ObjectPtr anObject = myWorkshop->displayer()->getObject(anObj);
+        theOwners.push_back(anObject);
+      }
     }
   }
 }