Salome HOME
Fix for several unit-tests behavior.
authormpv <mpv@opencascade.com>
Thu, 24 Jan 2019 14:25:45 +0000 (17:25 +0300)
committermpv <mpv@opencascade.com>
Thu, 24 Jan 2019 14:25:45 +0000 (17:25 +0300)
src/GeomAlgoAPI/GeomAlgoAPI_UnifySameDomain.cpp
src/Model/Model_AttributeSelection.cpp
src/Model/Model_BodyBuilder.cpp
src/Model/Model_ResultBody.cpp

index ee9c6fecac07a7e1f67ee24b67edc6119ebdb8bf..795a0fac19512a83a9fa9597b84b26200da83bfd 100644 (file)
@@ -113,6 +113,8 @@ void GeomAlgoAPI_UnifySameDomain::modified(const std::shared_ptr<GeomAPI_Shape>
   const ShapeUpgrade_UnifySameDomain& aUnifyAlgo = this->impl<ShapeUpgrade_UnifySameDomain>();
 
   for (int aIsModified = 0; aIsModified <= 1; aIsModified++) {
+    if (!aUnifyAlgo.History()->IsSupportedType(aShape)) // to avoid crash in BRepTools_History
+      continue;
     const TopTools_ListOfShape& aMList = aIsModified ?
       aUnifyAlgo.History()->Modified(aShape) : aUnifyAlgo.History()->Generated(aShape);
     for (TopTools_ListIteratorOfListOfShape aModified(aMList); aModified.More(); aModified.Next()) {
index ce8a3b77f91206f2aa3bb29263c41d0d30db519a..ba7ebae63a9b39fa71f65155e46476d6daca9821 100644 (file)
@@ -1398,6 +1398,20 @@ void Model_AttributeSelection::updateInHistory()
   TopTools_ListOfShape aValShapes;
   if (searchNewContext(aDoc, aNewCShape, aContext, aValShape, aContLab, aNewContexts, aValShapes))
   {
+    std::set<ResultPtr> allContexts, aSkippedContext;
+    std::list<ResultPtr>::iterator aNewContext = aNewContexts.begin();
+    for(; aNewContext != aNewContexts.end(); aNewContext++)
+      allContexts.insert(*aNewContext);
+
+    // if there exist context composite and sub-result(s), leave only sub(s)
+    std::set<ResultPtr>::iterator aResIter = allContexts.begin();
+    for(; aResIter != allContexts.end(); aResIter++) {
+      ResultPtr aParent = ModelAPI_Tools::bodyOwner(*aResIter);
+      for(; aParent.get(); aParent = ModelAPI_Tools::bodyOwner(aParent))
+        if (allContexts.count(aParent))
+          aSkippedContext.insert(aParent);
+    }
+
     GeomAPI_Shape::ShapeType aListShapeType = GeomAPI_Shape::SHAPE;
     if (myParent) {
       if (myParent->selectionType() == "VERTEX") aListShapeType = GeomAPI_Shape::VERTEX;
@@ -1409,6 +1423,8 @@ void Model_AttributeSelection::updateInHistory()
     TopTools_ListIteratorOfListOfShape aNewValues(aValShapes);
     bool aFirst = true; // first is set to this, next are appended to parent
     for(; aNewCont != aNewContexts.end(); aNewCont++, aNewValues.Next()) {
+      if (aSkippedContext.count(*aNewCont))
+        continue;
 
       GeomShapePtr aValueShape;
       if (!aNewValues.Value().IsNull()) {
index a0f074c755aaad0c2f3d656d4c523388595490f1..04c4059464e89421870adc663497f17f57a86e21 100755 (executable)
@@ -270,15 +270,19 @@ void Model_BodyBuilder::storeGenerated(const std::list<GeomShapePtr>& theFromSha
 {
   bool aStored = false;
   std::list<GeomShapePtr>::const_iterator anOldIter = theFromShapes.cbegin();
-  for(; anOldIter != theFromShapes.cend(); anOldIter++) {
-    ListOfShape aNews; // check this old really generates theToShape
-    theMakeShape->generated(*anOldIter, aNews);
-    ListOfShape::iterator aNewIter = aNews.begin();
-    for(; aNewIter != aNews.end(); aNewIter++) {
-      if (theToShape->isSame(*aNewIter))
-        break;
+  for (; anOldIter != theFromShapes.cend(); anOldIter++) {
+    bool aStore = (*anOldIter)->isCompound() || (*anOldIter)->isShell() || (*anOldIter)->isWire();
+    if (!aStore) {
+      ListOfShape aNews; // check this old really generates theToShape
+      theMakeShape->generated(*anOldIter, aNews);
+      ListOfShape::iterator aNewIter = aNews.begin();
+      for (; aNewIter != aNews.end(); aNewIter++) {
+        if (theToShape->isSame(*aNewIter))
+          break;
+      }
+      aStore = aNewIter != aNews.end();
     }
-    if (aNewIter != aNews.end()) {
+    if (aStore) {
       storeGenerated(*anOldIter, theToShape, !aStored);
       TNaming_Builder* aBuilder = builder(0);
       aStored = !aBuilder->NamedShape()->IsEmpty();
@@ -359,14 +363,19 @@ void Model_BodyBuilder::storeModified(const std::list<GeomShapePtr>& theOldShape
   bool aStored = false;
   std::list<GeomShapePtr>::const_iterator anOldIter = theOldShapes.cbegin();
   for(; anOldIter != theOldShapes.cend(); anOldIter++) {
-    ListOfShape aNews; // check this old really modifies theNewShape
-    theMakeShape->modified(*anOldIter, aNews);
-    ListOfShape::iterator aNewIter = aNews.begin();
-    for(; aNewIter != aNews.end(); aNewIter++) {
-      if (theNewShape->isSame(*aNewIter))
-        break;
+    // compounds may cause crash if call "modified"
+    bool aStore = (*anOldIter)->isCompound() || (*anOldIter)->isShell() || (*anOldIter)->isWire();
+    if (!aStore) {
+      ListOfShape aNews; // check this old really modifies theNewShape
+      theMakeShape->modified(*anOldIter, aNews);
+      ListOfShape::iterator aNewIter = aNews.begin();
+      for(; aNewIter != aNews.end(); aNewIter++) {
+        if (theNewShape->isSame(*aNewIter))
+          break;
+      }
+      aStore = aNewIter != aNews.end();
     }
-    if (aNewIter != aNews.end()) {
+    if (aStore) {
       storeModified(*anOldIter, theNewShape, !aStored);
       TNaming_Builder* aBuilder = builder(0);
       aStored = !aBuilder->NamedShape()->IsEmpty();
index b6fb91da1b241d606da07ff80443c24bfe57aa2b..3ba6431181ca6347757304fb94981d50d1187b51 100644 (file)
@@ -30,6 +30,7 @@
 #include <Model_Data.h>
 #include <Events_Loop.h>
 #include <GeomAPI_ShapeIterator.h>
+#include <GeomAPI_ShapeExplorer.h>
 
 #include <TopoDS_Shape.hxx>
 #include <TopExp_Explorer.hxx>
@@ -351,9 +352,20 @@ static void collectSubs(
     return;
   if (theSubSubs.Add(theSub->impl<TopoDS_Shape>()))  {
     bool aIsComp = theSub->isCompound() || theSub->isCompSolid();
-    if (aIsComp || theOneLevelMore) {
-      for(GeomAPI_ShapeIterator anIter(theSub); anIter.more(); anIter.next()) {
-        collectSubs(anIter.current(), theSubSubs, aIsComp && theOneLevelMore);
+    if (aIsComp) {
+      for(GeomAPI_ShapeIterator anIter(theSub); anIter.more(); anIter.next())
+        collectSubs(anIter.current(), theSubSubs, theOneLevelMore);
+    } else if (theOneLevelMore) {
+      GeomAPI_Shape::ShapeType aSubType = GeomAPI_Shape::ShapeType(int(theSub->shapeType()) + 1);
+      if (aSubType == GeomAPI_Shape::SHAPE)
+        return;
+      if (aSubType == GeomAPI_Shape::SHELL)
+        aSubType = GeomAPI_Shape::FACE;
+      if (aSubType == GeomAPI_Shape::WIRE)
+        aSubType = GeomAPI_Shape::EDGE;
+
+      for(GeomAPI_ShapeExplorer anExp(theSub, aSubType); anExp.more(); anExp.next()) {
+        collectSubs(anExp.current(), theSubSubs, false);
       }
     }
   }
@@ -375,6 +387,8 @@ void Model_ResultBody::computeOldForSub(const GeomShapePtr& theSub,
     for (TopTools_MapOfShape::Iterator anOldIter(anOldSubs); anOldIter.More(); anOldIter.Next()) {
       GeomShapePtr anOldSub(new GeomAPI_Shape);
       anOldSub->setImpl<TopoDS_Shape>(new TopoDS_Shape(anOldIter.Value()));
+      if (anOldSub->isCompound() || anOldSub->isShell() || anOldSub->isWire())
+        continue; // container old-shapes are not supported by the history, may cause crash
       ListOfShape aNews;
       myIsGenerated ? myAlgo->generated(anOldSub, aNews) : myAlgo->modified(anOldSub, aNews);
       // MakeShape may return alone old shape if there is no history information for this input