Salome HOME
Adding test for bos #41748 [CEA] Issue in interpolation edition
[modules/shaper.git] / src / XGUI / XGUI_Tools.cpp
index 4ca26b798ef4d8bfc41a36657ed1bbb6f108617d..0b1d37a6433ca1c706d03c550628a4b3d0dd4ca4 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -40,7 +40,7 @@
 #include <Events_InfoMessage.h>
 
 #include <GeomAPI_Shape.h>
-#include <GeomAlgoAPI_CompoundBuilder.h>
+#include <GeomAPI_IndexedMapOfShape.h>
 
 #include <TopoDS_Shape.hxx>
 
@@ -182,6 +182,20 @@ bool isAscii(const QString& theStr)
   return true;
 }
 
+//******************************************************************
+bool isValidName(const QString& theName)
+{
+  QChar aChar;
+  for (int i = 0; i < theName.size(); i++) {
+    aChar = theName[i];
+    if (!aChar.isLetterOrNumber()) {
+      if ((aChar != "_") && (!aChar.isSpace()))
+        return false;
+    }
+  }
+  return true;
+}
+
 //******************************************************************
 bool canRename(const ObjectPtr& theObject, const QString& theName)
 {
@@ -194,7 +208,7 @@ bool canRename(const ObjectPtr& theObject, const QString& theName)
     double aValue;
     ResultParameterPtr aParam;
     if (ModelAPI_Tools::findVariable(theObject->document(),
-          FeaturePtr(), qPrintable(theName), aValue, aParam)) {
+          FeaturePtr(), theName.toStdWString(), aValue, aParam)) {
       const char* aKeyStr = "Selected parameter can not be renamed to: %1. "
                             "There is a parameter with the same name. Its value is: %2.";
       QString aErrMsg(QObject::tr(aKeyStr).arg(theName).arg(aValue));
@@ -205,6 +219,9 @@ bool canRename(const ObjectPtr& theObject, const QString& theName)
     }
   }
   else {
+    if (!isValidName(theName))
+      return false;
+
     DocumentPtr aDoc = theObject->document();
     ObjectPtr aObj =
       aDoc->objectByName(aType, theName.toStdWString());
@@ -283,7 +300,8 @@ QString generateName(const ModuleBase_ViewerPrsPtr& thePrs)
           aTypeName = "shape";
           break;
         }
-        int aId = GeomAlgoAPI_CompoundBuilder::id(aContext, aSubShape);
+        GeomAPI_IndexedMapOfShape aSubShapesMap (aContext);
+        int aId = aSubShapesMap.FindIndexEqualLocations(aSubShape);
         aName += QString("/%1_%2").arg(aTypeName).arg(aId);
       }
     }