From: mpv Date: Tue, 1 Oct 2019 11:36:20 +0000 (+0300) Subject: Make "DoF" message from the sketch plugin translated correctly to French. X-Git-Tag: V9_4_0a2~4^2~40 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cfeb101356ed62a533474075cb22853a0e1f30d1;p=modules%2Fshaper.git Make "DoF" message from the sketch plugin translated correctly to French. --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp b/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp index 23346e919..96052010d 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp @@ -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); diff --git a/src/Model/Model_AttributeString.cpp b/src/Model/Model_AttributeString.cpp index 4c812fc26..108b7a544 100644 --- a/src/Model/Model_AttributeString.cpp +++ b/src/Model/Model_AttributeString.cpp @@ -23,12 +23,16 @@ #include #include +#include #include #include #include #include +// 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; diff --git a/src/Model/Model_AttributeString.h b/src/Model/Model_AttributeString.h index d678d89f9..7c0257f38 100644 --- a/src/Model/Model_AttributeString.h +++ b/src/Model/Model_AttributeString.h @@ -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 diff --git a/src/ModelAPI/ModelAPI_AttributeString.h b/src/ModelAPI/ModelAPI_AttributeString.h index d753784c4..d6c4b8861 100644 --- a/src/ModelAPI/ModelAPI_AttributeString.h +++ b/src/ModelAPI/ModelAPI_AttributeString.h @@ -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() diff --git a/src/ModuleBase/ModuleBase_WidgetLabel.cpp b/src/ModuleBase/ModuleBase_WidgetLabel.cpp index af8063f6a..b717bf103 100644 --- a/src/ModuleBase/ModuleBase_WidgetLabel.cpp +++ b/src/ModuleBase/ModuleBase_WidgetLabel.cpp @@ -25,7 +25,9 @@ #include #include +#include +#include #include #include @@ -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; diff --git a/src/PartSet/PartSet_OverconstraintListener.cpp b/src/PartSet/PartSet_OverconstraintListener.cpp index 1b2b688fd..ffa27418a 100644 --- a/src/PartSet/PartSet_OverconstraintListener.cpp +++ b/src/PartSet/PartSet_OverconstraintListener.cpp @@ -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"); } } } diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index 28d5550ab..efed9986d 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -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);