Salome HOME
[Code coverage ModelHighAPI]: Improve coverage
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_Selection.cpp
index ec6201600f530f5f3ef4a4c4071115b15af0e8cf..b9a9f0be5479305cc4eb0eb2cba7994a96107591 100644 (file)
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Feature.h>
-#include <ModelAPI_ResultCompSolid.h>
+#include <ModelAPI_ResultBody.h>
+
+
+#include <GeomAPI_Pnt.h>
 //--------------------------------------------------------------------------------------
 
 //--------------------------------------------------------------------------------------
@@ -48,6 +51,35 @@ ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType,
 {
 }
 
+ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType,
+                                               const GeomPointPtr& theSubShapeInnerPoint)
+: myVariantType(VT_TypeInnerPointPair)
+, myTypeInnerPointPair(theType, theSubShapeInnerPoint)
+{
+}
+
+ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType,
+                                               const std::list<double>& theSubShapeInnerPoint)
+: myVariantType(VT_TypeInnerPointPair)
+{
+  double aCoordinates[3] = { 0.0, 0.0, 0.0 };
+  double* aCIt = aCoordinates;
+  std::list<double>::const_iterator aPIt = theSubShapeInnerPoint.begin();
+  for (; aPIt != theSubShapeInnerPoint.end(); ++aPIt, ++aCIt)
+    *aCIt = *aPIt;
+
+  GeomPointPtr anInnerPoint(new GeomAPI_Pnt(aCoordinates[0], aCoordinates[1], aCoordinates[2]));
+  myTypeInnerPointPair = std::pair<std::string, GeomPointPtr>(theType, anInnerPoint);
+}
+
+ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType,
+  const std::string& theContextName, const int theIndex)
+  : myVariantType(VT_WeakNamingPair)
+  , myWeakNamingPair(theType, std::pair<std::string, int>(theContextName, theIndex))
+{
+}
+
+
 ModelHighAPI_Selection::~ModelHighAPI_Selection()
 {
 }
@@ -63,12 +95,20 @@ void ModelHighAPI_Selection::fillAttribute(
       return;
     case VT_TypeSubShapeNamePair:
       theAttribute->selectSubShape(myTypeSubShapeNamePair.first, myTypeSubShapeNamePair.second);
-      if(theAttribute->isInvalid()) {
-        FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
-        aFeature->setError(
-          std::string("Error: attribute \"") + theAttribute->id() + std::string("\" is invalid."));
-      }
+      break;
+    case VT_TypeInnerPointPair:
+      theAttribute->selectSubShape(myTypeInnerPointPair.first, myTypeInnerPointPair.second);
       return;
+    case VT_WeakNamingPair:
+      theAttribute->selectSubShape(
+        myWeakNamingPair.first, myWeakNamingPair.second.first, myWeakNamingPair.second.second);
+      break;
+  }
+
+  if (theAttribute->isInvalid()) {
+    FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
+    aFeature->setError(
+      std::string("Error: attribute \"") + theAttribute->id() + std::string("\" is invalid."));
   }
 }
 
@@ -85,6 +125,15 @@ void ModelHighAPI_Selection::appendToList(
       // Note: the reverse order (first - type, second - sub-shape name)
       theAttribute->append(myTypeSubShapeNamePair.second, myTypeSubShapeNamePair.first);
       return;
+    case VT_TypeInnerPointPair:
+      // Note: the reverse order (first - type, second - selected point)
+      theAttribute->append(myTypeInnerPointPair.second, myTypeInnerPointPair.first);
+      return;
+    case VT_WeakNamingPair:
+      // Note: the reverse order (first - type, second - selected point)
+      theAttribute->append(
+        myWeakNamingPair.first, myWeakNamingPair.second.first, myWeakNamingPair.second.second);
+      return;
   }
 }
 
@@ -106,6 +155,12 @@ TypeSubShapeNamePair ModelHighAPI_Selection::typeSubShapeNamePair() const
   return myTypeSubShapeNamePair;
 }
 
+//==================================================================================================
+TypeInnerPointPair ModelHighAPI_Selection::typeInnerPointPair() const
+{
+  return myTypeInnerPointPair;
+}
+
 //==================================================================================================
 std::string ModelHighAPI_Selection::shapeType() const
 {
@@ -114,6 +169,7 @@ std::string ModelHighAPI_Selection::shapeType() const
     return myResultSubShapePair.second.get() ? myResultSubShapePair.second->shapeTypeStr() :
                                                myResultSubShapePair.first->shape()->shapeTypeStr();
   case VT_TypeSubShapeNamePair: return myTypeSubShapeNamePair.first;
+  case VT_TypeInnerPointPair: return myTypeInnerPointPair.first;
   }
 
   return "SHAPE";
@@ -165,6 +221,7 @@ void ModelHighAPI_Selection::setDeflection(double theValue)
   aDeflectionAttr->setValue(theValue);
 }
 
+// LCOV_EXCL_START
 void ModelHighAPI_Selection::setTransparency(double theValue)
 {
   if (myVariantType != VT_ResultSubShapePair)
@@ -175,18 +232,18 @@ void ModelHighAPI_Selection::setTransparency(double theValue)
 
   aTransparencyAttr->setValue(theValue);
 }
+// LCOV_EXCL_STOP
 
 int ModelHighAPI_Selection::numberOfSubs() const
 {
   if (myVariantType != VT_ResultSubShapePair)
     return 0;
 
-  ResultCompSolidPtr aCompSolid =
-      std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myResultSubShapePair.first);
-  if (!aCompSolid)
+  ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myResultSubShapePair.first);
+  if (!aBody.get())
     return 0;
 
-  return aCompSolid->numberOfSubs();
+  return aBody->numberOfSubs();
 }
 
 ModelHighAPI_Selection ModelHighAPI_Selection::subResult(int theIndex) const
@@ -194,11 +251,12 @@ ModelHighAPI_Selection ModelHighAPI_Selection::subResult(int theIndex) const
   if (myVariantType != VT_ResultSubShapePair)
     return ModelHighAPI_Selection();
 
-  ResultCompSolidPtr aCompSolid =
-      std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myResultSubShapePair.first);
-  if (!aCompSolid)
+  ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myResultSubShapePair.first);
+  if (!aBody)
+    return ModelHighAPI_Selection();
+  if (theIndex >= aBody->numberOfSubs())
     return ModelHighAPI_Selection();
 
-  ResultBodyPtr aResult = aCompSolid->subResult(theIndex);
+  ResultBodyPtr aResult = aBody->subResult(theIndex);
   return ModelHighAPI_Selection(aResult, aResult->shape());
 }