Salome HOME
Tests fix
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Union.cpp
index 2b3188ddcbd4d5f4fcc439063fa034cc734974a5..e9cbaee7de9a13a1aaa3a2d56001da00a5becfaf 100644 (file)
 #include <GeomAlgoAPI_Boolean.h>
 #include <GeomAlgoAPI_MakeShapeList.h>
 #include <GeomAlgoAPI_PaveFiller.h>
+#include <GeomAlgoAPI_UnifySameDomain.h>
 
 #include <GeomAPI_ShapeExplorer.h>
+#include <GeomAPI_ShapeIterator.h>
 
 #include <ModelAPI_AttributeSelectionList.h>
-#include <ModelAPI_ResultCompSolid.h>
+#include <ModelAPI_ResultBody.h>
 #include <ModelAPI_Tools.h>
 
 //=================================================================================================
@@ -57,7 +59,7 @@ void FeaturesPlugin_Union::execute()
       return;
     }
     ResultPtr aContext = anObjectAttr->context();
-    ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
+    ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
     if(aResCompSolidPtr.get()) {
       std::shared_ptr<GeomAPI_Shape> aContextShape = aResCompSolidPtr->shape();
       std::map<std::shared_ptr<GeomAPI_Shape>, ListOfShape>::iterator
@@ -87,7 +89,7 @@ void FeaturesPlugin_Union::execute()
     anObjects.insert(anObjects.end(), aUsedInOperationSolids.begin(), aUsedInOperationSolids.end());
 
     // Collect solids from compsolid which will not be modified in boolean operation.
-    for(GeomAPI_ShapeExplorer anExp(aCompSolid, GeomAPI_Shape::SOLID); anExp.more(); anExp.next()) {
+    for(GeomAPI_ShapeIterator anExp(aCompSolid); anExp.more(); anExp.next()) {
       std::shared_ptr<GeomAPI_Shape> aSolidInCompSolid = anExp.current();
       ListOfShape::iterator anIt = aUsedInOperationSolids.begin();
       for(; anIt != aUsedInOperationSolids.end(); anIt++) {
@@ -107,31 +109,36 @@ void FeaturesPlugin_Union::execute()
   }
 
   // Fuse objects.
+  std::shared_ptr<GeomAlgoAPI_MakeShape> anAlgo;
   ListOfShape aTools;
-  aTools.splice(aTools.begin(), anObjects, anObjects.begin());
-  std::shared_ptr<GeomAlgoAPI_Boolean> aFuseAlgo(new GeomAlgoAPI_Boolean(anObjects,
-                                                            aTools,
-                                                            GeomAlgoAPI_Boolean::BOOL_FUSE));
+  if (anObjects.front()->shapeType() == GeomAPI_Shape::SOLID) {
+    aTools.splice(aTools.begin(), anObjects, anObjects.begin());
+    anAlgo.reset(new GeomAlgoAPI_Boolean(anObjects,
+                 aTools,
+                 GeomAlgoAPI_Boolean::BOOL_FUSE));
+  } else {
+    anAlgo.reset(new GeomAlgoAPI_UnifySameDomain(anObjects));
+  }
 
   // Checking that the algorithm worked properly.
-  GeomAlgoAPI_MakeShapeList aMakeShapeList;
+  std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList());
   GeomAPI_DataMapOfShapeShape aMapOfShapes;
-  if(!aFuseAlgo->isDone()) {
+  if(!anAlgo->isDone()) {
     setError("Error: Boolean algorithm failed.");
     return;
   }
-  if(aFuseAlgo->shape()->isNull()) {
+  if(anAlgo->shape()->isNull()) {
     setError("Error: Resulting shape is Null.");
     return;
   }
-  if(!aFuseAlgo->isValid()) {
+  if(!anAlgo->isValid()) {
     setError("Error: Resulting shape is not valid.");
     return;
   }
 
-  GeomShapePtr aShape = aFuseAlgo->shape();
-  aMakeShapeList.appendAlgo(aFuseAlgo);
-  aMapOfShapes.merge(aFuseAlgo->mapOfSubShapes());
+  GeomShapePtr aShape = anAlgo->shape();
+  aMakeShapeList->appendAlgo(anAlgo);
+  aMapOfShapes.merge(anAlgo->mapOfSubShapes());
 
   // Store original shapes for naming.
   anObjects.splice(anObjects.begin(), aTools);
@@ -156,24 +163,20 @@ void FeaturesPlugin_Union::execute()
     }
 
     aShape = aFillerAlgo->shape();
-    aMakeShapeList.appendAlgo(aFillerAlgo);
+    aMakeShapeList->appendAlgo(aFillerAlgo);
     aMapOfShapes.merge(aFillerAlgo->mapOfSubShapes());
   }
+  // workaround: make copy to name edges correctly
 
   // Store result and naming.
-  const int aModifyTag = 1;
-  const int aDeletedTag = 2;
-  /// sub solids will be placed at labels 3, 4, etc. if result is compound of solids
-  const int aSubsolidsTag = 3;
-  const std::string aModName = "Modified";
 
   std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
-  aResultBody->storeModified(anObjects.front(), aShape, aSubsolidsTag);
+  aResultBody->storeModified(anObjects.front(), aShape);
 
   for(ListOfShape::const_iterator anIter = anObjects.begin(); anIter != anObjects.end(); ++anIter) {
-    aResultBody->loadAndOrientModifiedShapes(&aMakeShapeList, *anIter, GeomAPI_Shape::FACE,
-                                             aModifyTag, aModName, aMapOfShapes);
-    aResultBody->loadDeletedShapes(&aMakeShapeList, *anIter, GeomAPI_Shape::FACE, aDeletedTag);
+    aResultBody->loadModifiedShapes(aMakeShapeList, *anIter, GeomAPI_Shape::EDGE);
+    aResultBody->loadModifiedShapes(aMakeShapeList, *anIter, GeomAPI_Shape::FACE);
+    //aResultBody->loadDeletedShapes(&aMakeShapeList, *anIter, GeomAPI_Shape::FACE, aDeletedTag);
   }
 
   setResult(aResultBody);