Salome HOME
Issue #3221: Set gray color for disabled features
[modules/shaper.git] / src / ModelAPI / ModelAPI_Tools.cpp
index 8922813f0e401fc32c4ab68b3d481b80fd022611..2f87922c2c277aea736198a3391fbd4ec0a28d14 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 #include <iostream>
 #include <sstream>
 
-// To support old types of GCC (less than 5.0), check the wide-string conversion is working
-#if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)  && \
-    (__cplusplus >= 201402L || !defined(__GLIBCXX__)   || \
-    (defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE > 4))
-#define HAVE_WORKING_WIDESTRING 1
-#else
-#define HAVE_WORKING_WIDESTRING 0
-#endif
-
-#if HAVE_WORKING_WIDESTRING
-#include <codecvt>
-#endif
-
 #include <Events_Loop.h>
+#include <Locale_Convert.h>
 #include <ModelAPI_Events.h>
 
 #include <GeomAPI_ShapeHierarchy.h>
@@ -185,7 +173,7 @@ std::string getFeatureError(const FeaturePtr& theFeature)
 ObjectPtr objectByName(const DocumentPtr& theDocument, const std::string& theGroup,
                        const std::string& theName)
 {
-  std::wstring aName = toWString(theName);
+  std::wstring aName = Locale::Convert::toWString(theName);
   for (int anIndex = 0; anIndex < theDocument->size(theGroup); ++anIndex) {
     ObjectPtr anObject = theDocument->object(theGroup, anIndex);
     if (anObject->data()->name() == aName)
@@ -373,7 +361,7 @@ bool allDocumentsActivated(std::wstring& theNotActivatedNames)
 }
 
 bool removeFeaturesAndReferences(const std::set<FeaturePtr>& theFeatures,
-                                 const bool theFlushRedisplay,
+                                 const bool /*theFlushRedisplay*/,
                                  const bool theUseComposite,
                                  const bool theUseRecursion)
 {
@@ -483,10 +471,10 @@ void findReferences(const std::set<FeaturePtr>& theFeatures,
       }
       else { // filter references to skip composition features of the current feature
         std::set<FeaturePtr> aFilteredFeatures;
-        std::set<FeaturePtr>::const_iterator anIt = aSelRefFeatures.begin(),
-                                             aLast = aSelRefFeatures.end();
-        for (; anIt != aLast; anIt++) {
-          FeaturePtr aCFeature = *anIt;
+        std::set<FeaturePtr>::const_iterator aRefIt = aSelRefFeatures.begin(),
+                                             aRefLast = aSelRefFeatures.end();
+        for (; aRefIt != aRefLast; aRefIt++) {
+          FeaturePtr aCFeature = *aRefIt;
           CompositeFeaturePtr aComposite =
             std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aCFeature);
           if (aComposite.get() && aComposite->isSub(aFeature))
@@ -557,7 +545,7 @@ void findAllReferences(const std::set<FeaturePtr>& theFeatures,
     aResultRefList.insert(aMainRefList.begin(), aMainRefList.end());
     for (; anIt != aLast; anIt++) {
       FeaturePtr aFeature = *anIt;
-      int aRecLevel = 0;
+      aRecLevel = 0;
 #ifdef DEBUG_REMOVE_FEATURES_RECURSE
       std::cout << " Ref: " << getFeatureInfo(aFeature) << std::endl;
 #endif
@@ -1058,10 +1046,10 @@ std::list<FeaturePtr> referencedFeatures(
       for(; aResIter != aResSet.end(); aResIter++) {
         std::list<ResultPtr>::const_iterator aGroupRes = (*aResIter)->results().cbegin();
         for(; aGroupRes != (*aResIter)->results().cend(); aGroupRes++) {
-          const std::set<AttributePtr>& aRefs = (*aGroupRes)->data()->refsToMe();
-          std::set<AttributePtr>::const_iterator aRef = aRefs.cbegin();
-          for(; aRef != aRefs.cend(); aRef++) {
-            FeaturePtr aFeat = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRef)->owner());
+          const std::set<AttributePtr>& aGroupRefs = (*aGroupRes)->data()->refsToMe();
+          std::set<AttributePtr>::const_iterator aRefIt = aGroupRefs.cbegin();
+          for(; aRefIt != aGroupRefs.cend(); aRefIt++) {
+            FeaturePtr aFeat = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRefIt)->owner());
             if (aFeat.get() && !aGroupOperations.count(aFeat) && !aFeat->results().empty() &&
                 aFeat->firstResult()->groupName() == ModelAPI_ResultGroup::group()) {
               // iterate results of this group operation because it may be without theTarget shape
@@ -1117,41 +1105,5 @@ std::list<FeaturePtr> referencedFeatures(
 }
 
 // LCOV_EXCL_STOP
-std::string toString(const std::wstring& theWStr)
-{
-#if HAVE_WORKING_WIDESTRING
-  static std::wstring_convert<std::codecvt_utf8<wchar_t> > aConvertor;
-  return aConvertor.to_bytes(theWStr);
-#else
-  char* aBuf = new char[2 * (theWStr.size() + 1)];
-  size_t aNbChars = std::wcstombs(aBuf, theWStr.c_str(), theWStr.size());
-  if (aNbChars != (size_t)-1)
-    aBuf[aNbChars] = '\0';
-  std::string aStr(aBuf);
-  delete[] aBuf;
-  return aStr;
-#endif
-}
-
-/*! Converts a byte string to an extended string
-*  \param theStr a byte string
-*/
-std::wstring toWString(const std::string& theStr)
-{
-#if HAVE_WORKING_WIDESTRING
-  static std::wstring_convert<std::codecvt_utf8<wchar_t> > aConvertor;
-  return aConvertor.from_bytes(theStr);
-#else
-  wchar_t* aBuf = new wchar_t[theStr.size() + 1];
-  size_t aNbWChars = std::mbstowcs(aBuf, theStr.c_str(), theStr.size());
-  if (aNbWChars != (size_t)-1)
-    aBuf[aNbWChars] = L'\0';
-  std::wstring aWStr(aBuf);
-  delete[] aBuf;
-  return aWStr;
-#endif
-}
-
-
 
 } // namespace ModelAPI_Tools