Salome HOME
updated copyright message
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_Tools.cpp
index 0b72c418f795263e3808897a343f6f11068bf968..67824fd334e2164555f31f22f34cb7a77136d9ef 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -29,6 +29,8 @@
 #include <GeomDataAPI_Point2D.h>
 #include <GeomDataAPI_Point2DArray.h>
 //--------------------------------------------------------------------------------------
+#include <GeomAlgoAPI_Tools.h>
+//--------------------------------------------------------------------------------------
 #include <Locale_Convert.h>
 //--------------------------------------------------------------------------------------
 #include <ModelAPI_AttributeBoolean.h>
@@ -168,8 +170,18 @@ void fillAttribute(const std::shared_ptr<ModelAPI_Object> & 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)
+  int aSize = theAttribute->size();
+  // keep objects at the beginning of the list if they the same
+  auto it = theValue.begin();
+  for (int anIndex = 0; it != theValue.end() && anIndex < aSize; ++it, ++anIndex)
+    if (theAttribute->object(anIndex) != *it) {
+      // remove the tail of the list
+      while (++anIndex <= aSize)
+        theAttribute->removeLast();
+      break;
+    }
+  // append the rest of elements
+  for (; it != theValue.end(); ++it)
     theAttribute->append(*it);
 }
 
@@ -214,6 +226,13 @@ void fillAttribute(const std::string & theValue,
   theAttribute->setValue(theValue);
 }
 
+//--------------------------------------------------------------------------------------
+void fillAttribute(const std::wstring & theValue,
+  const std::shared_ptr<ModelAPI_AttributeString> & theAttribute)
+{
+  theAttribute->setValue(theValue);
+}
+
 //--------------------------------------------------------------------------------------
 void fillAttribute(const char * theValue,
                    const std::shared_ptr<ModelAPI_AttributeString> & theAttribute)
@@ -349,7 +368,7 @@ GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection
     case ModelHighAPI_Selection::VT_ResultSubShapePair: {
       ResultSubShapePair aPair = theSelection.resultSubShapePair();
       GeomShapePtr aShape = aPair.second;
-      if(!aShape.get()) {
+      if(!aShape.get() && aPair.first.get()) {
         aShape = aPair.first->shape();
       }
       if(!aShape.get()) {
@@ -512,6 +531,8 @@ static bool dumpToPython(SessionPtr theSession,
   if (aDump.get()) {
     aDump->string("file_path")->setValue(theFilename);
     aDump->string("file_format")->setValue("py");
+    std::string aTrek = GeomAlgoAPI_Tools::File_Tools::path(theFilename);
+    aDump->string("dump_dir")->setValue(aTrek);
     aDump->boolean("topological_naming")->setValue((theSelectionType & CHECK_NAMING) != 0);
     aDump->boolean("geometric_selection")->setValue((theSelectionType & CHECK_GEOMETRICAL) != 0);
     aDump->boolean("weak_naming")->setValue((theSelectionType & CHECK_WEAK) != 0);
@@ -538,7 +559,7 @@ static bool checkDump(SessionPtr theSession,
   // execute the dumped
   PyGILState_STATE gstate = PyGILState_Ensure(); /* acquire python thread */
   static char aReadMode[] = "r";
-  FILE* PyFileObject = _Py_fopen(theFilename, aReadMode);
+  FILE* PyFileObject = fopen(theFilename, aReadMode);
   PyRun_SimpleFileEx(PyFileObject, theFilename, 1);
   PyGILState_Release(gstate); /* release python thread */