Salome HOME
Issue #2156 Impossible to valid the sketch: better debug information about store...
[modules/shaper.git] / src / ModuleBase / ModuleBase_Tools.cpp
index 1a436ee441c14f07cba7742da52a8e253dd963a3..c505732941a6984b43cc223c2269e7a34b7f6ec8 100755 (executable)
@@ -73,23 +73,6 @@ const double DEFAULT_DEVIATION_COEFFICIENT = 1.e-4;
 
 //#define DEBUG_ACTIVATE_WINDOW
 //#define DEBUG_SET_FOCUS
-//#define DEBUG_SELECTION_INFO
-
-#ifdef DEBUG_SELECTION_INFO
-#include <ModuleBase_ISelection.h>
-#include <ModuleBase_ViewerPrs.h>
-
-#include <AIS_InteractiveContext.hxx>
-#include <AIS_ListOfInteractive.hxx>
-#include <AIS_ListIteratorOfListOfInteractive.hxx>
-#include <AIS_Shape.hxx>
-#include <TopoDS_Shape.hxx>
-#include <AIS_LocalContext.hxx>
-#include <NCollection_List.hxx>
-#include <StdSelect_BRepOwner.hxx>
-#include <TColStd_ListOfInteger.hxx>
-#include <TColStd_ListIteratorOfListOfInteger.hxx>
-#endif
 
 #ifdef WIN32
 # define FSEP "\\"
@@ -221,7 +204,7 @@ QPixmap lighter(const QString& theIcon, const int theLighterValue)
 
 void setSpinText(ModuleBase_ParamSpinBox* theSpin, const QString& theText)
 {
-  if (theSpin->text() == theText) 
+  if (theSpin->text() == theText)
     return;
   // In order to avoid extra text setting because it will
   // reset cursor position in control
@@ -283,6 +266,15 @@ QAction* createAction(const QIcon& theIcon, const QString& theText,
   return anAction;
 }
 
+#ifdef _DEBUG
+QString objectName(const ObjectPtr& theObj)
+{
+  if (!theObj.get())
+    return "";
+
+  return theObj->data()->name().c_str();
+}
+
 QString objectInfo(const ObjectPtr& theObj, const bool isUseAttributesInfo)
 {
   QString aFeatureStr = "feature";
@@ -317,203 +309,16 @@ QString objectInfo(const ObjectPtr& theObj, const bool isUseAttributesInfo)
     if (isUseAttributesInfo) {
       std::set<std::shared_ptr<ModelAPI_Attribute> > anAttributes;
       std::string aPointsInfo = ModelGeomAlgo_Point2D::getPontAttributesInfo(aFeature,
-                                                                             anAttributes).c_str();
+                                                                          anAttributes).c_str();
       if (!aPointsInfo.empty())
-        aFeatureStr.append(QString(", attributes: %1").arg(aPointsInfo.c_str()).toStdString().c_str());
+        aFeatureStr.append(QString(", attributes: %1")
+          .arg(aPointsInfo.c_str()).toStdString().c_str());
     }
   }
 
   return aFeatureStr;
 }
-
-#ifdef DEBUG_SELECTION_INFO
-QString getShapeTypeInfo(const int theType)
-{
-  QString anInfo = "Undefined";
-  switch(theType) {
-    case TopAbs_COMPOUND:  anInfo = "compound"; break;
-    case TopAbs_COMPSOLID: anInfo = "compsolid"; break;
-    case TopAbs_SOLID:     anInfo = "solid"; break;
-    case TopAbs_SHELL:     anInfo = "shell"; break;
-    case TopAbs_FACE:      anInfo = "face"; break;
-    case TopAbs_WIRE:      anInfo = "wire"; break;
-    case TopAbs_EDGE:      anInfo = "edge"; break;
-    case TopAbs_VERTEX:    anInfo = "vertex"; break;
-    case TopAbs_SHAPE:     anInfo = "shape"; break;
-    case ModuleBase_ResultPrs::Sel_Result:
-                           anInfo = "result_shape"; break;
-    default: break;
-  }
-  return anInfo;
-}
-
-QString getModeInfo(const int theMode)
-{
-  QString anInfo = "Undefined";
-  switch(theMode) {
-    case 0: anInfo = "SHAPE(0)"; break;
-    case 1: anInfo = "VERTEX(1)"; break;
-    case 2: anInfo = "EDGE(2)"; break;
-    case 3: anInfo = "WIRE(3)"; break;
-    case 4: anInfo = "FACE(4)"; break;
-    case 5: anInfo = "SHELL(5)"; break;
-    case 6: anInfo = "SOLID(6)"; break;
-    case 7: anInfo = "COMPSOLID(7)"; break;
-    case 8: anInfo = "COMPOUND(8)"; break;
-    case 100: anInfo = "Sel_Mode_First(100)"; break; //SketcherPrs_Tools
-    case 101: anInfo = "Sel_Constraint(101)"; break;
-    case 102: anInfo = "Sel_Dimension_All(102)"; break;
-    case 103: anInfo = "Sel_Dimension_Line(103)"; break;
-    case 104: anInfo = "Sel_Dimension_Text(104)"; break;
-    default: break;
-  }
-  return anInfo;
-}
-
-QString displayedInteractiveObjects(Handle(AIS_InteractiveContext)& theContext,
-                                    const bool theShapeInfoOnly = true)
-{
-  if (theContext.IsNull())
-    return "";
-  AIS_ListOfInteractive aListOfIO;
-  theContext->DisplayedObjects(aListOfIO, false);
-  QStringList anObjects;
-  AIS_ListIteratorOfListOfInteractive aIt;
-  for (aIt.Initialize(aListOfIO); aIt.More(); aIt.Next()) {
-    Handle(AIS_InteractiveObject) anAISIO = aIt.Value();
-    Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISIO);
-    if (theShapeInfoOnly && aShapePrs.IsNull())
-      continue;
-
-    QString anInfo = "IO";
-    std::ostringstream aPtrStr;
-    aPtrStr << "[" << anAISIO.Access() << "]";
-    anInfo += aPtrStr.str().c_str();
-
-    if (!aShapePrs.IsNull()) {
-      const TopoDS_Shape& aShape = aShapePrs->Shape();
-      if (aShape.IsNull()) {
-        //Events_Error::throwException("An empty AIS presentation");
-      }
-      else
-        anInfo += QString(", shape type: %1").arg(getShapeTypeInfo(aShape.ShapeType()));
-    }
-    TColStd_ListOfInteger aTColModes;
-    theContext->ActivatedModes(anAISIO, aTColModes);
-    TColStd_ListIteratorOfListOfInteger itr( aTColModes );
-    QIntList aModesActivatedForIO;
-    bool isDeactivated = false;
-    QStringList aModes;
-    for (; itr.More(); itr.Next() ) {
-      Standard_Integer aMode = itr.Value();
-      aModes.append(getModeInfo(aMode));
-      //int aShapeMode = (aMode > 8)? aMode : AIS_Shape::SelectionType(aMode);
-    }
-    if (aModes.size() > 0)
-      anInfo += QString(", activated modes: %1").arg(aModes.join(", "));
-
-    anObjects += anInfo;
-  }
-  QString aValue = QString("displayedIO[%1]").arg(anObjects.size());
-  if (anObjects.size() > 0)
-    aValue += QString(":\n  %1").arg(anObjects.join("\n  "));
-  return aValue;
-}
-
-QString activeOwners(Handle(AIS_InteractiveContext)& theContext, const bool theShapeInfoOnly = true)
-{
-  if (theContext.IsNull())
-    return "";
-  Handle(AIS_LocalContext) aLContext = theContext->LocalContext();
-  TCollection_AsciiString aSelectionName = aLContext->SelectionName();
-  aLContext->UnhilightPicked(Standard_False);
-
-  NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
-  aLContext->MainSelector()->ActiveOwners(anActiveOwners);
-  NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (anActiveOwners);
-  Handle(SelectMgr_EntityOwner) anOwner;
-  QStringList anObjects;
-  for (; anOwnersIt.More(); anOwnersIt.Next()) {
-    anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
-    Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
-    if (theShapeInfoOnly && BROwnr.IsNull())
-      continue;
-
-    QString anInfo = "Owner";
-    std::ostringstream aPtrStr;
-    aPtrStr << "[" << anOwner.Access() << "]";
-    anInfo += aPtrStr.str().c_str();
-
-    Handle(AIS_InteractiveObject) aAISObj = 
-          Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
-    if (!aAISObj.IsNull()) {
-      std::ostringstream aPtrStr;
-      aPtrStr << "[" << aAISObj.Access() << "]";
-      anInfo += QString(", selectable(IO): %1").arg(aPtrStr.str().c_str());
-    }
-
-    if (!BROwnr.IsNull() && BROwnr->HasShape()) {
-      const TopoDS_Shape& aShape = BROwnr->Shape();
-      if (aShape.IsNull()) {
-        //Events_Error::throwException("An empty AIS presentation");
-      }
-      else
-        anInfo += QString(", shape type: %1").arg(getShapeTypeInfo(aShape.ShapeType()));
-    }
-    anObjects += anInfo;
-  }
-  QString aValue = QString("activeOwners[%1]").arg(anObjects.size());
-  if (anObjects.size() > 0)
-    aValue += QString(":\n  %1").arg(anObjects.join("\n  "));
-  return aValue;
-}
-
-QString selectedOwners(Handle(AIS_InteractiveContext)& theContext, const bool theShapeInfoOnly = true)
-{
-  QStringList anObjects;
-  if (theContext.IsNull())
-    return "";
-
-  QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
-  for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected()) {
-    Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
-    Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
-    if (theShapeInfoOnly && BROwnr.IsNull())
-      continue;
-
-    if (aSelectedIds.contains((long)anOwner.Access()))
-      continue;
-    aSelectedIds.append((long)anOwner.Access());
-
-    QString anInfo = "Owner";
-    std::ostringstream aPtrStr;
-    aPtrStr << "[" << anOwner.Access() << "]";
-    anInfo += aPtrStr.str().c_str();
-
-    if (!BROwnr.IsNull() && BROwnr->HasShape()) {
-      const TopoDS_Shape& aShape = BROwnr->Shape();
-      anInfo += QString(", shape type = %1").arg(getShapeTypeInfo(aShape.ShapeType()));
-    }
-    anObjects += anInfo;
-  }
-  QString aValue = QString("selectedOwners[%1]").arg(anObjects.size());
-  if (anObjects.size() > 0)
-    aValue += QString(":\n  %1").arg(anObjects.join("\n  "));
-  return aValue;
-}
-#endif
-
-void selectionInfo(Handle(AIS_InteractiveContext)& theContext, const std::string& thePrefix)
-{
-#ifdef DEBUG_SELECTION_INFO
-  QString aValue = QString("\n\n\nDEBUG_SELECTION_INFO for '%1'\n%2\n%3\n%4")
-                                              .arg(thePrefix.c_str())
-                                              .arg(displayedInteractiveObjects(theContext))
-                                              .arg(activeOwners(theContext))
-                                              .arg(selectedOwners(theContext));
-  qDebug(aValue.toStdString().c_str());
 #endif
-}
 
 typedef QMap<QString, int> ShapeTypes;
 static ShapeTypes myShapeTypes;
@@ -548,12 +353,13 @@ int shapeType(const QString& theType)
 }
 
 void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFeature,
-                  bool& hasParameter, bool& hasCompositeOwner)
+                  bool& hasParameter, bool& hasCompositeOwner, bool& hasResultInHistory)
 {
   hasResult = false;
   hasFeature = false;
   hasParameter = false;
   hasCompositeOwner = false;
+  hasResultInHistory = false;
   foreach(ObjectPtr aObj, theObjects) {
     FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
@@ -562,8 +368,14 @@ void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFe
     hasResult |= (aResult.get() != NULL);
     hasFeature |= (aFeature.get() != NULL);
     hasParameter |= (aConstruction.get() != NULL);
-    if (hasFeature) 
+    if (hasFeature)
       hasCompositeOwner |= (ModelAPI_Tools::compositeOwner(aFeature) != NULL);
+
+    if (!hasResultInHistory && aResult.get()) {
+      FeaturePtr aFeature = ModelAPI_Feature::feature(aResult);
+      hasResultInHistory = aFeature.get() && aFeature->isInHistory();
+    }
+
     if (hasFeature && hasResult  && hasParameter && hasCompositeOwner)
       break;
   }
@@ -615,20 +427,17 @@ void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape,
 
   double aDeflection;
   if (isConstruction)
-    aDeflection = Config_PropManager::real("Visualization", "construction_deflection",
-                                           ModelAPI_ResultConstruction::DEFAULT_DEFLECTION());
+    aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
   else
-    aDeflection = Config_PropManager::real("Visualization", "body_deflection",
-                                           ModelAPI_ResultBody::DEFAULT_DEFLECTION());
+    aDeflection = Config_PropManager::real("Visualization", "body_deflection");
 
   theDrawer->SetDeviationCoefficient(aDeflection);
 }
 
 Quantity_Color color(const std::string& theSection,
-                     const std::string& theName,
-                     const std::string& theDefault)
+                     const std::string& theName)
 {
-  std::vector<int> aColor = Config_PropManager::color(theSection, theName, theDefault);
+  std::vector<int> aColor = Config_PropManager::color(theSection, theName);
   return Quantity_Color(aColor[0] / 255., aColor[1] / 255., aColor[2] / 255., Quantity_TOC_RGB);
 }
 
@@ -637,17 +446,20 @@ ObjectPtr getObject(const AttributePtr& theAttribute)
   ObjectPtr anObject;
   std::string anAttrType = theAttribute->attributeType();
   if (anAttrType == ModelAPI_AttributeRefAttr::typeId()) {
-    AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+    AttributeRefAttrPtr anAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
     if (anAttr != NULL && anAttr->isObject())
       anObject = anAttr->object();
   }
   if (anAttrType == ModelAPI_AttributeSelection::typeId()) {
-    AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+    AttributeSelectionPtr anAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
     if (anAttr != NULL)
       anObject = anAttr->context();
   }
   if (anAttrType == ModelAPI_AttributeReference::typeId()) {
-    AttributeReferencePtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
+    AttributeReferencePtr anAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
     if (anAttr.get() != NULL)
       anObject = anAttr->value();
   }
@@ -704,7 +516,8 @@ void getParameters(QStringList& theParameters)
   }
 }
 
-std::string findGreedAttribute(ModuleBase_IWorkshop* theWorkshop, const FeaturePtr& theFeature)
+std::string findGreedAttribute(ModuleBase_IWorkshop* theWorkshop,
+                               const FeaturePtr& theFeature)
 {
   std::string anAttributeId;
 
@@ -729,14 +542,16 @@ bool hasObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
 
   std::string aType = theAttribute->attributeType();
   if (aType == ModelAPI_AttributeReference::typeId()) {
-    AttributeReferencePtr aRef = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
+    AttributeReferencePtr aRef =
+      std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
     ObjectPtr aObject = aRef->value();
     aHasObject = aObject && aObject->isSame(theObject);
     //if (!(aObject && aObject->isSame(theObject))) {
     //  aRef->setValue(theObject);
     //}
   } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
-    AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+    AttributeRefAttrPtr aRefAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
 
     AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
     if (anAttribute.get()) {
@@ -762,17 +577,17 @@ bool hasObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
                          std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
     aHasObject = aSelectionListAttr->isInList(aResult, theShape, theTemporarily);
-    //if (!theCheckIfAttributeHasObject || !aSelectionListAttr->isInList(aResult, theShape, theTemporarily))
-    //  aSelectionListAttr->append(aResult, theShape, theTemporarily);
   }
   else if (aType == ModelAPI_AttributeRefList::typeId()) {
-    AttributeRefListPtr aRefListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
+    AttributeRefListPtr aRefListAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
     aHasObject = aRefListAttr->isInList(theObject);
     //if (!theCheckIfAttributeHasObject || !aRefListAttr->isInList(theObject))
     //  aRefListAttr->append(theObject);
   }
   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
-    AttributeRefAttrListPtr aRefAttrListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
+    AttributeRefAttrListPtr aRefAttrListAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
     AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
 
     if (anAttribute.get()) {
@@ -799,13 +614,15 @@ bool setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
   bool isDone = true;
   std::string aType = theAttribute->attributeType();
   if (aType == ModelAPI_AttributeReference::typeId()) {
-    AttributeReferencePtr aRef = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
+    AttributeReferencePtr aRef =
+      std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
     ObjectPtr aObject = aRef->value();
     if (!(aObject && aObject->isSame(theObject))) {
       aRef->setValue(theObject);
     }
   } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
-    AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+    AttributeRefAttrPtr aRefAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
 
     AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
     if (anAttribute.get())
@@ -828,11 +645,13 @@ bool setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
     AttributeSelectionListPtr aSelectionListAttr =
                          std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-    if (!theCheckIfAttributeHasObject || !aSelectionListAttr->isInList(aResult, theShape, theTemporarily))
+    if (!theCheckIfAttributeHasObject ||
+        !aSelectionListAttr->isInList(aResult, theShape, theTemporarily))
       aSelectionListAttr->append(aResult, theShape, theTemporarily);
   }
   else if (aType == ModelAPI_AttributeRefList::typeId()) {
-    AttributeRefListPtr aRefListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
+    AttributeRefListPtr aRefListAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
     if (!theCheckIfAttributeHasObject || !aRefListAttr->isInList(theObject)) {
       if (theObject.get())
         aRefListAttr->append(theObject);
@@ -841,7 +660,8 @@ bool setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
     }
   }
   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
-    AttributeRefAttrListPtr aRefAttrListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
+    AttributeRefAttrListPtr aRefAttrListAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
     AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
 
     if (anAttribute.get()) {
@@ -869,7 +689,8 @@ GeomShapePtr getShape(const AttributePtr& theAttribute, ModuleBase_IWorkshop* th
   std::string aType = theAttribute->attributeType();
   if (aType == ModelAPI_AttributeReference::typeId()) {
   } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
-    AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+    AttributeRefAttrPtr aRefAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
     if (aRefAttr.get() && !aRefAttr->isObject()) {
       AttributePtr anAttribute = aRefAttr->attr();
       aShape = theWorkshop->module()->findShape(anAttribute);
@@ -888,7 +709,12 @@ void flushUpdated(ObjectPtr theObject)
 {
   blockUpdateViewer(true);
 
+  // Fix the problem of not previewed results of constraints applied. Flush Create/Delete
+  // (for the sketch result) to start processing of the sketch in the solver.
+  // TODO: these flushes should be moved in a separate method provided by Model
+  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
 
   blockUpdateViewer(false);
 }
@@ -952,7 +778,20 @@ QString wrapTextByWords(const QString& theValue, QWidget* theWidget,
 }
 
 //**************************************************************
-void refsToFeatureInFeatureDocument(const ObjectPtr& theObject, std::set<FeaturePtr>& theRefFeatures)
+QLocale doubleLocale()
+{
+  // VSR 01/07/2010: Disable thousands separator for spin box
+  // (to avoid inconsistency of double-2-string and string-2-double conversion)
+  QLocale aLocale;
+  aLocale.setNumberOptions(aLocale.numberOptions() |
+                           QLocale::OmitGroupSeparator |
+                           QLocale::RejectGroupSeparator);
+  return aLocale;
+}
+
+//**************************************************************
+void refsToFeatureInFeatureDocument(const ObjectPtr& theObject,
+                                    std::set<FeaturePtr>& theRefFeatures)
 {
   FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
   if (aFeature.get()) {
@@ -1052,10 +891,11 @@ bool askToDelete(const std::set<FeaturePtr> theFeatures,
   std::string aNotActivatedNames;
   if (!ModelAPI_Tools::allDocumentsActivated(aNotActivatedNames)) {
     if (ModuleBase_Tools::hasModuleDocumentFeature(theFeatures))
-      aNotActivatedDocWrn = QObject::tr("Selected objects can be used in Part documents which are not loaded:%1.\n")
+      aNotActivatedDocWrn =
+        QObject::tr("Selected objects can be used in Part documents which are not loaded:%1.\n")
                             .arg(aNotActivatedNames.c_str());
   }
-  
+
   std::set<FeaturePtr> aFeaturesRefsTo;
   std::set<FeaturePtr> aFeaturesRefsToParameter;
   std::set<FeaturePtr> aParameterFeatures;
@@ -1128,17 +968,25 @@ bool askToDelete(const std::set<FeaturePtr> theFeatures,
   if (!thePrefixInfo.empty())
     aText = thePrefixInfo.c_str();
   QString aSep = ", ";
-  if (!aPartFeatureNames.empty())
-    aText += QString(QObject::tr("The following parts will be deleted: %1.\n")).arg(aPartFeatureNames.join(aSep));
+  if (!aPartFeatureNames.empty()) {
+    aText += QString(QObject::tr("The following parts will be deleted: %1.\n"))
+             .arg(aPartFeatureNames.join(aSep));
+  }
   if (!aNotActivatedDocWrn.isEmpty())
     aText += aNotActivatedDocWrn;
-  if (!anOtherFeatureNames.empty())
-    aText += QString(QObject::tr("Features are used in the following features: %1.\nThese features will be deleted.\n"))
+  if (!anOtherFeatureNames.empty()) {
+    const char* aMsg = "Features are used in the following features: %1.\nThese "
+                       "features will be deleted.\n";
+    aText += QString(QObject::tr(aMsg))
                      .arg(anOtherFeatureNames.join(aSep));
+  }
   if (!aParamFeatureNames.empty()) {
-    aText += QString(QObject::tr("Parameters are used in the following features: %1.\nThese features will be deleted.\nOr parameters could be replaced by their values.\n"))
+    const char* aMsg = "Parameters are used in the following features: %1.\nThese features will "
+                       "be deleted.\nOr parameters could be replaced by their values.\n";
+    aText += QString(QObject::tr(aMsg))
                      .arg(aParamFeatureNames.join(aSep));
-    QPushButton *aReplaceButton = aMessageBox.addButton(QObject::tr("Replace"), QMessageBox::ActionRole);
+    QPushButton *aReplaceButton =
+      aMessageBox.addButton(QObject::tr("Replace"), QMessageBox::ActionRole);
   }
 
   if (!aText.isEmpty()) {
@@ -1155,7 +1003,8 @@ bool askToDelete(const std::set<FeaturePtr> theFeatures,
         ModelAPI_ReplaceParameterMessage::send(aObj, 0);
     }
     else
-      theReferencesToDelete.insert(aFeaturesRefsToParameterOnly.begin(), aFeaturesRefsToParameterOnly.end());
+      theReferencesToDelete.insert(aFeaturesRefsToParameterOnly.begin(),
+                                   aFeaturesRefsToParameterOnly.end());
   }
   return true;
 }
@@ -1175,15 +1024,34 @@ void convertToFeatures(const QObjectPtrList& theObjects, std::set<FeaturePtr>& t
   }
 }
 
-void translate(const std::string& theContext, std::string& theMessage)
+QString translate(const Events_InfoMessage& theMessage)
 {
+  QString aMessage;
+
+  if (!theMessage.empty()) {
+    std::string aStr = Config_Translator::translate(theMessage);
+    if (!aStr.empty()) {
+      std::string aCodec = Config_Translator::codec(theMessage);
+      aMessage = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str());
+    }
+  }
+
+  return aMessage;
+}
+
+QString translate(const std::string& theContext, const std::string& theMessage)
+{
+  QString aMessage;
+
   if (!theMessage.empty()) {
     std::string aStr = Config_Translator::translate(theContext, theMessage);
     if (!aStr.empty()) {
       std::string aCodec = Config_Translator::codec(theContext);
-      theMessage = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str()).toStdString();
+      aMessage = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str());
     }
   }
+
+  return aMessage;
 }
 
 void setPointBallHighlighting(AIS_Shape* theAIS)
@@ -1208,7 +1076,8 @@ void setPointBallHighlighting(AIS_Shape* theAIS)
     aPixMap = new Image_AlienPixMap();
     if(!aPixMap->Load(aFile.c_str())) {
       // The icon for constraint is not found
-      static const std::string aMsg = "Error: Point market not found by path: \"" + aFile + "\". Falling back.";
+      static const std::string aMsg =
+        "Error: Point market not found by path: \"" + aFile + "\". Falling back.";
       //Events_InfoMessage("ModuleBase_Tools::setPointBallHighlighting", aMsg).send();
     }
   }