From d33d0b41c80638ca951456b0a05afb89edb8497b Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 16 Jun 2016 11:22:46 +0300 Subject: [PATCH] Translated messages providing for SOLVER_ERROR attribute, code improvement --- src/Config/Config_Translator.h | 2 +- src/ModuleBase/ModuleBase_IModule.cpp | 13 ++++--------- src/ModuleBase/ModuleBase_OperationFeature.cpp | 1 + src/ModuleBase/ModuleBase_Tools.cpp | 13 +++++++++++++ src/ModuleBase/ModuleBase_Tools.h | 9 +++++++++ src/ModuleBase/ModuleBase_WidgetLabel.cpp | 1 + src/PartSet/PartSet_SketcherMgr.cpp | 9 +++++---- src/SketchSolver/CMakeLists.txt | 9 ++++++++- src/SketchSolver/SketchSolver_msg_en.ts | 16 ++++++++++++++++ 9 files changed, 58 insertions(+), 15 deletions(-) create mode 100755 src/SketchSolver/SketchSolver_msg_en.ts diff --git a/src/Config/Config_Translator.h b/src/Config/Config_Translator.h index cab88afdf..6f79f81d1 100644 --- a/src/Config/Config_Translator.h +++ b/src/Config/Config_Translator.h @@ -48,7 +48,7 @@ public: /** * Returns translation from the given data. - * If transdlation is not exists then it returns a string + * If translation is not exists then it returns a string * from the info data without translation * \param theContext context of the message (Feature Id) * \param theMessage a message which dave to be translated diff --git a/src/ModuleBase/ModuleBase_IModule.cpp b/src/ModuleBase/ModuleBase_IModule.cpp index 1287a605a..9442ddc27 100644 --- a/src/ModuleBase/ModuleBase_IModule.cpp +++ b/src/ModuleBase/ModuleBase_IModule.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -31,7 +30,6 @@ #include #include #include -#include ModuleBase_IModule::ModuleBase_IModule(ModuleBase_IWorkshop* theParent) : QObject(theParent), myWorkshop(theParent) @@ -108,13 +106,10 @@ bool ModuleBase_IModule::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const QString ModuleBase_IModule::getFeatureError(const FeaturePtr& theFeature) { - QString aMsg = ModelAPI_Tools::getFeatureError(theFeature).c_str(); - if (!aMsg.isEmpty()) { - std::string aStr = Config_Translator::translate(theFeature->getKind(), aMsg.toStdString()); - std::string aCodec = Config_Translator::codec(theFeature->getKind()); - aMsg = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str()); - } - return aMsg; + std::string aMsg = ModelAPI_Tools::getFeatureError(theFeature); + ModuleBase_Tools::translate(theFeature->getKind(), aMsg); + + return aMsg.c_str(); } void ModuleBase_IModule::grantedOperationIds(ModuleBase_Operation* theOperation, diff --git a/src/ModuleBase/ModuleBase_OperationFeature.cpp b/src/ModuleBase/ModuleBase_OperationFeature.cpp index 82cf7906b..ea72d2307 100755 --- a/src/ModuleBase/ModuleBase_OperationFeature.cpp +++ b/src/ModuleBase/ModuleBase_OperationFeature.cpp @@ -102,6 +102,7 @@ bool ModuleBase_OperationFeature::isValid() const return true; std::string anError = ModelAPI_Tools::getFeatureError(myFeature); + ModuleBase_Tools::translate(myFeature->getKind(), anError); return anError.empty(); } diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index a4890633a..169f911d3 100755 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -39,6 +39,7 @@ #include #include +#include #include #include @@ -50,6 +51,7 @@ #include #include #include +#include #include #include @@ -1137,6 +1139,17 @@ void convertToFeatures(const QObjectPtrList& theObjects, std::set& t } } +void translate(const std::string& theContext, std::string& theMessage) +{ + 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(); + } + } +} + } // namespace ModuleBase_Tools diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h index 2e19e0f73..ad735c09b 100755 --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -302,6 +302,15 @@ bool MODULEBASE_EXPORT askToDelete(const std::set aFeatures, /// \param theFeatures an out conteiner of features void MODULEBASE_EXPORT convertToFeatures(const QObjectPtrList& theObjects, std::set& theFeatures); + +/// Returns translation from the given data. +/// If translation is not exists then it returns a string +/// from the info data without translation +/// \param theContext context of the message (Feature Id) +/// \param theMessage a message which dave to be translated +/// \param theParams a list of parameters (can be empty) +void MODULEBASE_EXPORT translate(const std::string& theContext, std::string& theMessage); + } #endif diff --git a/src/ModuleBase/ModuleBase_WidgetLabel.cpp b/src/ModuleBase/ModuleBase_WidgetLabel.cpp index 31fe1f6c7..bab0894cb 100644 --- a/src/ModuleBase/ModuleBase_WidgetLabel.cpp +++ b/src/ModuleBase/ModuleBase_WidgetLabel.cpp @@ -55,6 +55,7 @@ bool ModuleBase_WidgetLabel::restoreValueCustom() if (aStrAttr.get()) { aMsg = aStrAttr->value(); } + ModuleBase_Tools::translate(myFeature->getKind(), aMsg); myLabel->setText(aMsg.c_str()); } return true; diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 7fcebed5a..beb3206c7 100755 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -717,16 +717,17 @@ bool PartSet_SketcherMgr::sketchSolverError() QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature) { - QString anError = ""; + std::string anError = ""; if (!theFeature.get() || !theFeature->data()->isValid()) - return anError; + return anError.c_str(); CompositeFeaturePtr aSketch = activeSketch(); if (aSketch.get() && aSketch == theFeature) { AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR()); - anError = aAttributeString->value().c_str(); + anError = aAttributeString->value(); + ModuleBase_Tools::translate(aSketch->getKind(), anError); } - return anError; + return anError.c_str(); } void PartSet_SketcherMgr::clearClickedFlags() diff --git a/src/SketchSolver/CMakeLists.txt b/src/SketchSolver/CMakeLists.txt index ac4117627..e9d814316 100644 --- a/src/SketchSolver/CMakeLists.txt +++ b/src/SketchSolver/CMakeLists.txt @@ -62,6 +62,10 @@ SET(PROJECT_LIBRARIES GeomDataAPI ) +SET(TEXT_RESOURCES + SketchSolver_msg_en.ts +) + INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/Config ${PROJECT_SOURCE_DIR}/src/SketchPlugin @@ -71,15 +75,18 @@ INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/Events ) +SOURCE_GROUP ("Resource Files" FILES ${TEXT_RESOURCES}) + ADD_DEFINITIONS(-DSKETCHSOLVER_EXPORTS) -ADD_LIBRARY(SketchSolver SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS} +ADD_LIBRARY(SketchSolver SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${TEXT_RESOURCES} ) TARGET_LINK_LIBRARIES(SketchSolver ${PROJECT_LIBRARIES} ) INSTALL(TARGETS SketchSolver DESTINATION ${SHAPER_INSTALL_PLUGIN_FILES}) +INSTALL(FILES ${TEXT_RESOURCES} DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}) # Include specific solvers diff --git a/src/SketchSolver/SketchSolver_msg_en.ts b/src/SketchSolver/SketchSolver_msg_en.ts new file mode 100755 index 000000000..424f5d40f --- /dev/null +++ b/src/SketchSolver/SketchSolver_msg_en.ts @@ -0,0 +1,16 @@ + + + + + Sketch + + The constraint is conflicting with others. To fix this, you can either undo your operation or remove a conflicting constraint. + The constraint is conflicting with others. To fix this, you can either undo your operation or remove a conflicting constraint. + + + Caution: SolveSpace crash! Constraints are wrong + Caution: SolveSpace crash! Constraints are wrong + + + + -- 2.30.2