Salome HOME
Issue #1662: implementation of Recover feature.
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_Tools.cpp
index 9a6c10e97238d8b2c375441282f1416ea06f996e..be4e0186f020be400cbafd5d67dee676583dcb72 100644 (file)
 #include "ModelHighAPI_Double.h"
 #include "ModelHighAPI_Integer.h"
 #include "ModelHighAPI_RefAttr.h"
+#include "ModelHighAPI_Reference.h"
 #include "ModelHighAPI_Selection.h"
 
+#include <algorithm>
+
 //--------------------------------------------------------------------------------------
 void fillAttribute(const std::shared_ptr<GeomAPI_Pnt2d> & theValue,
                    const std::shared_ptr<GeomDataAPI_Point2D> & theAttribute)
@@ -93,6 +96,56 @@ void fillAttribute(const ModelHighAPI_RefAttr & theValue,
   theValue.fillAttribute(theAttribute);
 }
 
+//--------------------------------------------------------------------------------------
+void fillAttribute(const std::list<ModelHighAPI_RefAttr> & theValue,
+                   const std::shared_ptr<ModelAPI_AttributeRefAttrList> & theAttribute)
+{
+  theAttribute->clear();
+  for (auto it = theValue.begin(); it != theValue.end(); ++it)
+    it->appendToList(theAttribute);
+}
+
+//--------------------------------------------------------------------------------------
+void fillAttribute(const ModelHighAPI_Reference & theValue,
+                   const std::shared_ptr<ModelAPI_AttributeReference> & theAttribute)
+{
+  theValue.fillAttribute(theAttribute);
+}
+
+//--------------------------------------------------------------------------------------
+void fillAttribute(const std::list<ModelHighAPI_Reference> & theValue,
+                   const std::shared_ptr<ModelAPI_AttributeRefList> & theAttribute)
+{
+  theAttribute->clear();
+  for (auto it = theValue.begin(); it != theValue.end(); ++it)
+    it->appendToList(theAttribute);
+}
+
+//--------------------------------------------------------------------------------------
+void fillAttribute(const std::shared_ptr<ModelAPI_Object> & theValue,
+                   const std::shared_ptr<ModelAPI_AttributeReference> & theAttribute)
+{
+  theAttribute->setValue(theValue);
+}
+
+//--------------------------------------------------------------------------------------
+void fillAttribute(const std::list<std::shared_ptr<ModelAPI_Object> > & theValue,
+                   const std::shared_ptr<ModelAPI_AttributeRefList> & theAttribute)
+{
+  theAttribute->clear();
+  for (auto it = theValue.begin(); it != theValue.end(); ++it)
+    theAttribute->append(*it);
+}
+
+MODELHIGHAPI_EXPORT
+void fillAttribute(const std::list<ModelHighAPI_Selection> & theValue,
+                   const std::shared_ptr<ModelAPI_AttributeRefList> & theAttribute)
+{
+  theAttribute->clear();
+  for (auto it = theValue.begin(); it != theValue.end(); ++it)
+    theAttribute->append(it->resultSubShapePair().first); // use only context
+}
+
 //--------------------------------------------------------------------------------------
 void fillAttribute(const ModelHighAPI_Selection & theValue,
                    const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute)
@@ -121,4 +174,64 @@ void fillAttribute(const char * theValue,
   theAttribute->setValue(theValue);
 }
 
+//==================================================================================================
+GeomAPI_Shape::ShapeType shapeTypeByStr(const std::string& theShapeTypeStr)
+{
+  GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE;
+
+  std::string aShapeTypeStr = theShapeTypeStr;
+  std::transform(aShapeTypeStr.begin(), aShapeTypeStr.end(), aShapeTypeStr.begin(), ::tolower);
+
+  if(theShapeTypeStr == "compound") {
+    aShapeType = GeomAPI_Shape::COMPOUND;
+  } else if(theShapeTypeStr == "compsolid") {
+    aShapeType = GeomAPI_Shape::COMPSOLID;
+  } else if(theShapeTypeStr == "solid") {
+    aShapeType = GeomAPI_Shape::SOLID;
+  } else if(theShapeTypeStr == "shell") {
+    aShapeType = GeomAPI_Shape::SHELL;
+  } else if(theShapeTypeStr == "face") {
+    aShapeType = GeomAPI_Shape::FACE;
+  } else if(theShapeTypeStr == "wire") {
+    aShapeType = GeomAPI_Shape::WIRE;
+  } else if(theShapeTypeStr == "edge") {
+    aShapeType = GeomAPI_Shape::EDGE;
+  } else if(theShapeTypeStr == "vertex") {
+    aShapeType = GeomAPI_Shape::VERTEX;
+  } else if(theShapeTypeStr == "shape") {
+    aShapeType = GeomAPI_Shape::SHAPE;
+  }
+
+  return aShapeType;
+}
+
+//==================================================================================================
+GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection)
+{
+  GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE;
+
+  switch(theSelection.variantType()) {
+    case ModelHighAPI_Selection::VT_ResultSubShapePair: {
+      ResultSubShapePair aPair = theSelection.resultSubShapePair();
+      GeomShapePtr aShape = aPair.second;
+      if(!aShape.get()) {
+        aShape = aPair.first->shape();
+      }
+      if(!aShape.get()) {
+        return aShapeType;
+      }
+      aShapeType = aShape->shapeType();
+      break;
+    }
+    case ModelHighAPI_Selection::VT_TypeSubShapeNamePair: {
+      TypeSubShapeNamePair aPair = theSelection.typeSubShapeNamePair();
+      std::string aType = aPair.first;
+      aShapeType = shapeTypeByStr(aType);
+      break;
+    }
+  }
+
+  return aShapeType;
+}
+
 //--------------------------------------------------------------------------------------