Salome HOME
[Code coverage]: Move checking the algorithm's result into separate function
[modules/shaper.git] / src / BuildPlugin / BuildPlugin_Filling.cpp
index a5597f6e620543b40fd2f750c0d658edaa42dfbf..dcf51a8b540186976cef84f2b8370ba9e9108568 100644 (file)
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_ResultBody.h>
 
+#include <GeomAlgoAPI_Copy.h>
 #include <GeomAlgoAPI_Filling.h>
 #include <GeomAlgoAPI_ShapeTools.h>
+#include <GeomAlgoAPI_Tools.h>
 
 #include <GeomAPI_Pnt.h>
 #include <GeomAPI_ShapeExplorer.h>
@@ -66,8 +68,8 @@ void BuildPlugin_Filling::initAttributes()
   data()->addAttribute(TOLERANCE_3D_ID(), ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(APPROXIMATION_ID(), ModelAPI_AttributeBoolean::typeId());
 
-  restoreDefaultParameters();
-  string(ADVANCED_OPTIONS_ID())->setValue("");
+  if (string(ADVANCED_OPTIONS_ID())->value().empty())
+    restoreDefaultParameters();
 }
 
 //=================================================================================================
@@ -94,8 +96,10 @@ void BuildPlugin_Filling::execute()
 
   // get base objects list
   AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID());
-  if (aSelectionList->size() <= 1)
+  if (aSelectionList->size() <= 1) {
+    setError("Not enough objects is selected");
     return;
+  }
 
   // collect base shapes
   for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
@@ -113,7 +117,9 @@ void BuildPlugin_Filling::execute()
 
   // build result
   aFilling->build(aParameters.isApprox);
-  if (isFailed(aFilling)) {
+  std::string anError;
+  if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aFilling, getKind(), anError)) {
+    setError(anError);
     removeResults(0);
     return;
   }
@@ -126,32 +132,11 @@ void BuildPlugin_Filling::execute()
   int anEdgeInd = 0;
   for(GeomAPI_ShapeExplorer anExp(aCreatedFace, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
     GeomShapePtr anEdge = anExp.current();
-    aResultBody->generated(anEdge, "Edge_" + std::to_string((long long)anEdgeInd), ++anEdgeInd);
+    aResultBody->generated(anEdge, "Edge_" + std::to_string((long long)anEdgeInd));
   }
   setResult(aResultBody, 0);
 }
 
-bool BuildPlugin_Filling::isFailed(
-    const std::shared_ptr<GeomAlgoAPI_MakeShape>& theAlgorithm)
-{
-  if (!theAlgorithm->isDone()) {
-    static const std::string aFeatureError = "Error: filling algorithm failed.";
-    setError(aFeatureError);
-    return true;
-  }
-  if (theAlgorithm->shape()->isNull()) {
-    static const std::string aShapeError = "Error: Resulting shape of filling is Null.";
-    setError(aShapeError);
-    return true;
-  }
-  if (!theAlgorithm->isValid()) {
-    std::string aFeatureError = "Error: Resulting shape of filling is not valid.";
-    setError(aFeatureError);
-    return true;
-  }
-  return false;
-}
-
 //=================================================================================================
 void BuildPlugin_Filling::attributeChanged(const std::string& theID)
 {
@@ -167,7 +152,7 @@ GeomEdgePtr BuildPlugin_Filling::toEdge(const GeomShapePtr& theShape, const std:
   GeomEdgePtr anEdge;
   switch (theShape->shapeType()) {
   case GeomAPI_Shape::EDGE:
-    anEdge = GeomEdgePtr(new GeomAPI_Edge(theShape));
+    anEdge = GeomEdgePtr(new GeomAPI_Edge(GeomAlgoAPI_Copy(theShape).shape()));
     break;
   case GeomAPI_Shape::WIRE:
     anEdge = GeomAlgoAPI_ShapeTools::wireToEdge(
@@ -189,6 +174,10 @@ GeomEdgePtr BuildPlugin_Filling::toEdge(const GeomShapePtr& theShape, const std:
     // check the distance to previous edge boundaries, reverse edge if necessary
     GeomPointPtr aStartPnt = anEdge->firstPoint();
     GeomPointPtr aEndPnt = anEdge->lastPoint();
+    if (anEdge->orientation() == GeomAPI_Shape::REVERSED) {
+      aStartPnt = anEdge->lastPoint();
+      aEndPnt = anEdge->firstPoint();
+    }
     bool isReverse = false;
     if (myLastEdgeStartPoint) {
       double d1 = myLastEdgeStartPoint->distance(aStartPnt)