Salome HOME
Make "DoF" message from the sketch plugin translated correctly to French.
authormpv <mpv@opencascade.com>
Tue, 1 Oct 2019 11:36:20 +0000 (14:36 +0300)
committermpv <mpv@opencascade.com>
Tue, 1 Oct 2019 11:36:20 +0000 (14:36 +0300)
src/FeaturesPlugin/FeaturesPlugin_Partition.cpp
src/Model/Model_AttributeString.cpp
src/Model/Model_AttributeString.h
src/ModelAPI/ModelAPI_AttributeString.h
src/ModuleBase/ModuleBase_WidgetLabel.cpp
src/PartSet/PartSet_OverconstraintListener.cpp
src/SketchSolver/SketchSolver_Group.cpp

index 23346e9192c6462763f58337e997deb8287d7b57..96052010d10e07f7489cfdfa4bd6de18a4888a5c 100644 (file)
@@ -128,7 +128,7 @@ void FeaturesPlugin_Partition::execute()
 
   int aPartitionVersion = version();
   if (aPartitionVersion < THE_PARTITION_VERSION_1) {
-    // default behaviours of Partition
+    // default behaviors of Partition
     if(aResultShape->shapeType() == GeomAPI_Shape::COMPOUND) {
       for(GeomAPI_ShapeIterator anIt(aResultShape); anIt.more(); anIt.next()) {
         storeResult(aBaseObjects, aPlanes, anIt.current(), aMakeShapeList, aResultIndex);
index 4c812fc26744e03ee87060f3d4ee66b9fa0c3a18..108b7a544307c8c64de2637c7d33d3f28081fbd8 100644 (file)
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Object.h>
 
+#include <TDataStd_UAttribute.hxx>
 #include <Standard_TypeDef.hxx>
 #include <TCollection_AsciiString.hxx>
 #include <TCollection_ExtendedString.hxx>
 
 #include <string>
 
+// on myLabel if the Unicode string was stored
+static const Standard_GUID kUVALUE_IDENTIFIER("04cac509-b2fc-4887-b442-d2a86f2fd7bd");
+
 void Model_AttributeString::setValue(const std::string& theValue)
 {
   TCollection_ExtendedString aValue(theValue.c_str());
@@ -36,6 +40,7 @@ void Model_AttributeString::setValue(const std::string& theValue)
     if (myString.IsNull())
       myString = TDataStd_Name::Set(myLab, TCollection_ExtendedString());
     myString->Set(aValue);
+    myLab.ForgetAttribute(kUVALUE_IDENTIFIER);
     owner()->data()->sendAttributeUpdated(this);
   }
 }
@@ -47,6 +52,7 @@ void Model_AttributeString::setValue(const std::wstring& theValue)
     if (myString.IsNull())
       myString = TDataStd_Name::Set(myLab, TCollection_ExtendedString());
     myString->Set(aValue);
+    TDataStd_UAttribute::Set(myLab, kUVALUE_IDENTIFIER);
     owner()->data()->sendAttributeUpdated(this);
   }
 }
@@ -57,6 +63,7 @@ std::string Model_AttributeString::value()
     return "";  // not initialized
   return TCollection_AsciiString(myString->Get()).ToCString();
 }
+
 char16_t* Model_AttributeString::valueU()
 {
   if (myString.IsNull()) {   // not initialized
@@ -66,6 +73,10 @@ char16_t* Model_AttributeString::valueU()
   return (char16_t*)(myString->Get().ToExtString());
 }
 
+bool Model_AttributeString::isUValue() const {
+  return !myLab.IsNull() && myLab.IsAttribute(kUVALUE_IDENTIFIER);
+}
+
 Model_AttributeString::Model_AttributeString(TDF_Label& theLabel)
 {
   myLab = theLabel;
index d678d89f9743a9de6ac374f5d9ef4976036b8554..7c0257f38b20956cfb18278a8b0c5f4c17299c27 100644 (file)
@@ -47,6 +47,8 @@ class Model_AttributeString : public ModelAPI_AttributeString
   MODEL_EXPORT virtual std::string value();
   /// Returns a pointer to Unicode string
   MODEL_EXPORT virtual char16_t* valueU();
+  /// Returns true if Unicode string was stored
+  MODEL_EXPORT virtual bool isUValue() const;
 
  protected:
   /// Initializes attributes
index d753784c40bf8a37cfd3094e57cd59300393848f..d6c4b88616670c4de994105dbc78b96de5450cec 100644 (file)
@@ -41,6 +41,7 @@ class ModelAPI_AttributeString : public ModelAPI_Attribute
   MODELAPI_EXPORT virtual std::string value() = 0;
   /// Returns a pointer to Unicode string
   MODELAPI_EXPORT virtual char16_t* valueU() = 0;
+  MODELAPI_EXPORT virtual bool isUValue() const = 0;
 
   /// Returns the type of this class of attributes
   MODELAPI_EXPORT static std::string typeId()
index af8063f6abc936d0487bb6d8f7d77ff040556f33..b717bf1039c7c0dadc958836b56836424e9db179 100644 (file)
@@ -25,7 +25,9 @@
 #include <ModuleBase_Tools.h>
 
 #include <ModelAPI_AttributeString.h>
+#include <Config_Translator.h>
 
+#include <QTextCodec>
 #include <QLabel>
 #include <QVBoxLayout>
 
@@ -71,11 +73,21 @@ bool ModuleBase_WidgetLabel::restoreValueCustom()
   DataPtr aData = myFeature->data();
   AttributeStringPtr aStrAttr = aData->string(attributeID());
   if (aStrAttr.get()) {
-    std::string aMsg;
+    QString aText;
     if (aStrAttr.get()) {
-      aMsg = aStrAttr->value();
+      if (aStrAttr->isUValue()) { // already translated text
+        char16_t* aStr = aStrAttr->valueU();
+        std::wstring aWStr((wchar_t*)aStr);
+        static const int aBufSize = 1000;
+        static char aMBStr[aBufSize];
+        size_t aLen = wcstombs(aMBStr, aWStr.c_str(), aBufSize);
+        std::string aCodec = Config_Translator::codec("");
+        aText = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aMBStr);
+      } else {
+        std::string aMsg = aStrAttr->value();
+        aText = ModuleBase_Tools::translate(myFeature->getKind(), aMsg);
+      }
     }
-    QString aText = ModuleBase_Tools::translate(myFeature->getKind(), aMsg);
     myLabel->setText(aText);
   }
   return true;
index 1b2b688fd1a55986faff84f982cbd827ab71d43b..ffa27418a89ecd78a17c7f40d3a479c34c9908a6 100644 (file)
@@ -75,7 +75,7 @@ void PartSet_OverconstraintListener::setActive(const bool& theActive)
     CompositeFeaturePtr aSketch = aModule->sketchMgr()->activeSketch();
     if (aSketch.get()) {
       std::string aDOFMessage = aSketch->string(SketchPlugin_Sketch::SOLVER_DOF())->value();
-      myIsFullyConstrained = QString(aDOFMessage.c_str()).contains("DoF = 0");
+      myIsFullyConstrained = QString(aDOFMessage.c_str()).contains(" = 0");
     }
   }
 }
index 28d5550ab198b94e2490468c2d60027ad1c0a986..efed9986da7ddac98de4bb05bce9e5c91804ee5c 100644 (file)
@@ -353,21 +353,25 @@ bool SketchSolver_Group::resolveConstraints()
 // ============================================================================
 void SketchSolver_Group::computeDoF()
 {
-  std::ostringstream aDoFMsg;
+  std::string aDoFMsg;
   static const std::string aMsgContext("Sketch");
   int aDoF = mySketchSolver->dof();
   /// "DoF = 0" content of string value is used in PartSet by Sketch edit
   /// If it is changed, it should be corrected also there
   if (aDoF == 0) {
     static const std::string aMsgDoF("Sketch is fully fixed (DoF = 0)");
-    aDoFMsg << Config_Translator::translate(aMsgContext, aMsgDoF).c_str();
+    aDoFMsg = Config_Translator::translate(aMsgContext, aMsgDoF);
   } else {
     static const std::string aMsgDoF("DoF (degrees of freedom) = %1");
     Events_InfoMessage aMsg(aMsgContext, aMsgDoF);
-    aMsg.arg(aDoF);
-    aDoFMsg << Config_Translator::translate(aMsg).c_str();
+    aMsg.addParameter(aDoF);
+    aDoFMsg = Config_Translator::translate(aMsg);
   }
-  mySketch->string(SketchPlugin_Sketch::SOLVER_DOF())->setValue(aDoFMsg.str());
+  // store Unicode value for translated message about DoF
+  size_t aLen = aDoFMsg.size();
+  std::wstring aWStr(aLen, L'#');
+  mbstowcs(&aWStr[0], aDoFMsg.c_str(), aLen);
+  mySketch->string(SketchPlugin_Sketch::SOLVER_DOF())->setValue(aWStr);
 
   if (aDoF > 0 && myDOF <= 0)
     sendMessage(EVENT_SKETCH_UNDER_CONSTRAINED, mySketch, aDoF);