Improved translation mechanism.
}
std::string Config_Translator::translate(const std::string& theContext,
- const std::string& theMessage,
+ const std::string& theMessage,
const std::list<std::string>& theParams)
{
if (myTranslator.count(theContext) > 0) {
return (myCodecs.count(theContext) > 0)? myCodecs[theContext] : "UTF-8";
}
+std::string Config_Translator::codec(const Events_InfoMessage& theInfo)
+{
+ return codec(theInfo.context());
+}
#ifdef _DEBUG
#ifdef MISSED_TRANSLATION
/// The definition provides collection and writing of missed translations
-//#define MISSED_TRANSLATION
+#define MISSED_TRANSLATION
/**
* \class Config_Translator
*/
static CONFIG_EXPORT std::string codec(const std::string& theContext);
+ /**
+ * Returns codec for the context
+ * \param theInfo the info
+ */
+ static CONFIG_EXPORT std::string codec(const Events_InfoMessage& theInfo);
+
#ifdef _DEBUG
#ifdef MISSED_TRANSLATION
static CONFIG_EXPORT void saveMissedTranslations();
{
myDoc = xmlParseDoc(BAD_CAST theRawXml.c_str());
myCurrentNode = xmlDocGetRootElement(myDoc);
+ myFeatureId = getProperty(_ID);
}
Config_WidgetAPI::~Config_WidgetAPI()
return ::getBooleanAttribute(myCurrentNode, theAttributeName, theDefault);
}
+std::string Config_WidgetAPI::featureId() const
+{
+ return myFeatureId;
+}
+
std::string Config_WidgetAPI::widgetId() const
{
return getProperty(_ID);
//! Page is container widget with combo box control to switch between pages
bool isPagedWidget() const;
+ //! Returns id of current feature
+ std::string featureId() const;
//! Returns id of current widget
std::string widgetId() const;
//! Returns icon of current widget
private:
xmlDocPtr myDoc; //!< Pointer to the root of widget's xml definition
xmlNodePtr myCurrentNode; //!< Pointer to the current node in the widget's xml definition
+ std::string myFeatureId;
friend class ModuleBase_WidgetFactory;
};
#include <ModelAPI_Result.h>
#include <Model_Data.h>
+#include <Config_Translator.h>
+
#include <Events_InfoMessage.h>
void Model_ValidatorsFactory::registerValidator(const std::string& theID,
if (!aFValidator->isValid(theFeature, anArguments, anError)) {
if (anError.empty())
anError = "Unknown error.";
- anError = aValidatorID + ": " + anError.messageString();
- theFeature->setError(anError.messageString(), false);
+ if (anError.context().empty()) {
+ anError.setContext(theFeature->getKind() + ":" + aValidatorID);
+ }
+ theFeature->setError(Config_Translator::translate(anError), false, false);
theFeature->data()->execState(ModelAPI_StateInvalidArgument);
return false;
}
if (!validate(anAttribute, aValidatorID, anError)) {
if (anError.empty())
anError = "Unknown error.";
- anError = anAttributeID + " - " + aValidatorID + ": " + anError.messageString();
- theFeature->setError(anError.messageString(), false);
+ if (anError.context().empty()) {
+ anError.setContext(theFeature->getKind() + ":" + anAttributeID + ":" + aValidatorID);
+ }
+ theFeature->setError(anError.messageString(), false, false);
theFeature->data()->execState(ModelAPI_StateInvalidArgument);
return false;
}
#include <ModelAPI_Document.h>
#include <ModelAPI_Session.h>
#include <Events_Loop.h>
+#include <Config_Translator.h>
+
+void ModelAPI_Feature::setError(const std::string& theError,
+ bool isSend,
+ bool isTranslate)
+{
+ std::string anError = isTranslate ? Config_Translator::translate(getKind(), theError)
+ : theError;
+ data()->setError(anError, isSend);
+}
const std::list<std::shared_ptr<ModelAPI_Result> >& ModelAPI_Feature::results()
{
virtual bool compute(const std::string& theAttributeId) { return false; };
/// Registers error during the execution, causes the ExecutionFailed state
- virtual void setError(const std::string& theError, bool isSend = true) {
- data()->setError(theError, isSend);
- }
+ MODELAPI_EXPORT virtual void setError(const std::string& theError,
+ bool isSend = true,
+ bool isTranslate = true);
/// Returns error, arose during the execution
virtual std::string error() const {
#include <ModuleBase_ActionInfo.h>
#include <ModuleBase_IconFactory.h>
+#include <ModuleBase_Tools.h>
ModuleBase_ActionInfo::ModuleBase_ActionInfo()
{
if (!iconFile.isEmpty()) {
icon = ModuleBase_IconFactory::loadIcon(iconFile);
}
- text = QString::fromStdString(theMessage->text());
- toolTip = QString::fromStdString(theMessage->tooltip());
+ text = ModuleBase_Tools::translate(theMessage->id(), theMessage->text());
+ toolTip = ModuleBase_Tools::translate(theMessage->id(), theMessage->tooltip());
QString aShortcutStr = QString::fromStdString(theMessage->keysequence());
if (!aShortcutStr.isEmpty()) {
shortcut = QKeySequence(aShortcutStr);
QString ModuleBase_IModule::getFeatureError(const FeaturePtr& theFeature)
{
+ // Error already translated.
std::string aMsg = ModelAPI_Tools::getFeatureError(theFeature);
- ModuleBase_Tools::translate(theFeature->getKind(), aMsg);
-
return aMsg.c_str();
}
qDebug("ModuleBase_ModelWidget::ModuleBase_ModelWidget");
#endif
+ myFeatureId = theData->featureId();
+
myIsInternal = theData->getBooleanAttribute(ATTR_INTERNAL, false);
myDefaultValue = theData->getProperty(ATTR_DEFAULT);
storeValue();
}
-QString ModuleBase_ModelWidget::getValueStateError() const
+Events_InfoMessage ModuleBase_ModelWidget::getValueStateError() const
{
- QString anError = "";
+ Events_InfoMessage aMessage;
ModuleBase_ModelWidget::ValueState aState = getValueState();
if (aState != ModuleBase_ModelWidget::Stored) {
AttributePtr anAttr = feature()->attribute(attributeID());
if (anAttr.get()) {
- QString anAttributeName = anAttr->id().c_str();
+ const std::string& anAttributeName = anAttr->id();
switch (aState) {
case ModuleBase_ModelWidget::ModifiedInViewer:
- anError = "Attribute \"" + anAttributeName +
- "\" is locked by modification value in the viewer.";
+ aMessage = "Attribute \"%1\" is locked by modification value in the viewer.";
+ aMessage.addParameter(anAttributeName);
break;
case ModuleBase_ModelWidget::Reset:
- anError = "Attribute \"" + anAttributeName + "\" is not initialized.";
+ aMessage = "Attribute \"%1\" is not initialized.";
+ aMessage.addParameter(anAttributeName);
break;
case ModuleBase_ModelWidget::ModifiedInPP: // Apply should be enabled in this mode
default:
}
}
}
- return anError;
+ return aMessage;
}
QString ModuleBase_ModelWidget::getError(const bool theValueStateChecked) const
if (!feature().get())
return anError;
+ std::string aFeatureID = feature()->getKind();
std::string anAttributeID = attributeID();
AttributePtr anAttribute = feature()->attribute(anAttributeID);
if (!anAttribute.get())
static ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
if (!aValidators->validate(anAttribute, aValidatorID, anErrorMsg)) {
if (anErrorMsg.empty())
- anErrorMsg = "unknown error.";
- anErrorMsg = anAttributeID + " - " + aValidatorID + ": " + anErrorMsg.messageString();
+ anErrorMsg = "Unknown error.";
+
+ if (anErrorMsg.context().empty()) {
+ anErrorMsg.setContext(aFeatureID + ":" + anAttributeID + ":" + aValidatorID);
+ }
}
- if (!anErrorMsg.empty()) {
- std::string aStr = Config_Translator::translate(anErrorMsg);
- std::string aCodec = Config_Translator::codec(anErrorMsg.context());
- anError = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str());
+ if (anErrorMsg.empty() && theValueStateChecked) {
+ anErrorMsg = getValueStateError();
}
- if (anError.isEmpty() && theValueStateChecked)
- anError = getValueStateError();
+ if (!anErrorMsg.empty()) {
+ anError = ModuleBase_Tools::translate(anErrorMsg);
+ }
- anError = translateString(anError);
return anError;
}
-
-QString ModuleBase_ModelWidget::translateString(const QString& theMsg) const
-{
- if (!theMsg.isEmpty()) {
- std::string aContext = feature()->getKind();
- std::string aStr = Config_Translator::translate(aContext, theMsg.toStdString().c_str());
- std::string aCodec = Config_Translator::codec(aContext);
- return QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str());
- }
- return theMsg;
-}
-
-
void ModuleBase_ModelWidget::enableFocusProcessing()
{
QList<QWidget*> aMyControls = getControls();
{
setValueState(ModifiedInPP);
}
+
+QString ModuleBase_ModelWidget::translate(const std::string& theStr) const
+{
+ return ModuleBase_Tools::translate(context(), theStr);
+}
#include <memory>
class Config_WidgetAPI;
+class Events_InfoMessage;
class ModuleBase_IWorkshop;
class ModuleBase_ViewerPrs;
class ModuleBase_WidgetValidator;
/// Returns an attribute error according to the value state
/// It exists in all cases excepring the "Store" case
- QString getValueStateError() const;
+ Events_InfoMessage getValueStateError() const;
/// Defines if it is supposed that the widget should interact with the viewer.
virtual bool isViewerSelector() { return false; }
return myFeature;
}
+ /// \return Context for translation
+ virtual std::string context() const {
+
+ std::string aContext = myFeatureId;
+ if(!aContext.empty() && !myAttributeID.empty()) {
+ aContext += ":";
+ }
+ aContext += myAttributeID;
+
+ return aContext;
+ }
+
/// Set feature which is processing by active operation
/// \param theFeature a feature object
/// \param theToStoreValue a value about necessity to store the widget value to the feature
/// \param theObj is object for moving
static void moveObject(ObjectPtr theObj);
+ /// Translate passed string with widget context()
+ virtual QString translate(const std::string& theStr) const;
+
signals:
/// The signal about widget values are to be changed
void beforeValuesChanged();
/// The method called when widget is activated
virtual void activateCustom() {};
- QString translateString(const QString& theMsg) const;
-
protected slots:
/// Processing of values changed in model widget by store the current value to the feature
void onWidgetValuesChanged();
/// A feature which is processing by active operation
FeaturePtr myFeature;
+ /// A feature ID
+ std::string myFeatureId;
+
/// Flag which shows that current operation is in editing mode
bool myIsEditing;
return true;
std::string anError = ModelAPI_Tools::getFeatureError(myFeature);
- ModuleBase_Tools::translate(myFeature->getKind(), anError);
+ //ModuleBase_Tools::translate(myFeature->getKind(), anError);
return anError.empty();
}
}
}
-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)
class GeomAPI_Shape;
+class Events_InfoMessage;
+
namespace ModuleBase_Tools {
/// Methods to adjust margins and spacings.
std::set<FeaturePtr>& theFeatures);
+/// Returns translation from the given data.
+/// If translation is not exists then it returns a string
+/// from the info data without translation
+/// \param theMessage a message which dave to be translated
+QString MODULEBASE_EXPORT translate(const Events_InfoMessage& theMessage);
+
/// 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);
+QString MODULEBASE_EXPORT translate(const std::string& theContext, const std::string& theMessage);
/// Set Highlighting of points as a Ball shape
/// \param theAIS - the presentation
ModuleBase_WidgetAction::ModuleBase_WidgetAction(QWidget* theParent,
const Config_WidgetAPI* theData)
-: ModuleBase_ModelWidget(theParent, theData)
+: ModuleBase_ModelWidget(theParent, theData),
+ myActionID(attributeID())
{
+ setAttributeID(""); // To prevent errors. Action not stored as attribtue in feature.
QHBoxLayout* aControlLay = new QHBoxLayout(this);
ModuleBase_Tools::adjustMargins(aControlLay);
- myActionID = attributeID();
- setAttributeID("");
-
myButton = new QToolButton(this);
- QString aText = QString::fromStdString(theData->widgetLabel());
- QString aToolTip = ModuleBase_Tools::wrapTextByWords(
- QString::fromStdString(theData->widgetTooltip()), myButton, DEFAULT_TOOL_TIP_WIDTH);
+ QString aText = translate(theData->widgetLabel());
+ QString aToolTip = ModuleBase_Tools::wrapTextByWords(translate(theData->widgetTooltip()),
+ myButton,
+ DEFAULT_TOOL_TIP_WIDTH);
myButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
aControlLay->addWidget(myButton);
/// \return a control list
virtual QList<QWidget*> getControls() const;
+ /// \return Context for translation
+ virtual std::string context() const {
+ return myFeature->getKind() + ":" + myActionID;
+ }
+
protected:
/// Do nothing
/// \return True in success
const Config_WidgetAPI* theData)
: ModuleBase_ModelWidget(theParent, theData)
{
- QString aText = QString::fromStdString(theData->widgetLabel());
- QString aToolTip = QString::fromStdString(theData->widgetTooltip());
+ QString aText = translate(theData->widgetLabel());
+ QString aToolTip = translate(theData->widgetTooltip());
bool isChecked = theData->getBooleanAttribute(ATTR_DEFAULT, false);
myCheckBox = new QCheckBox(aText, this);
QHBoxLayout* aLayout = new QHBoxLayout(this);
ModuleBase_Tools::adjustMargins(aLayout);
- QString aLabelText = QString::fromStdString(theData->widgetLabel());
+ QString aLabelText = translate(theData->widgetLabel());
QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
std::string aTypes = theData->getProperty("string_list");
- QStringList aList = QString(aTypes.c_str()).split(' ');
+ QStringList aList;
+
+ foreach(QString aType, QString(aTypes.c_str()).split(' ')) {
+ aList.append(translate(aType.toStdString()));
+ }
if (theData->getBooleanAttribute("use_in_title", false))
- myButtonTitles = QString(aTypes.c_str()).split(" ");
+ myButtonTitles = aList;
// Widget type can be combobox or radiobuttons
std::string aWgtType = theData->getProperty("widget_type");
{
QString aTitle;
if (myButtonTitles.length() > theIndex)
- aTitle = tr(myButtonTitles[theIndex].toStdString().c_str());
+ aTitle = myButtonTitles[theIndex];
return aTitle;
}
QFormLayout* aControlLay = new QFormLayout(this);
ModuleBase_Tools::adjustMargins(aControlLay);
- QString aLabelText = QString::fromStdString(theData->widgetLabel());
+ QString aLabelText = translate(theData->widgetLabel());
QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
myLabel = new QLabel(aLabelText, this);
if (!aLabelIcon.isEmpty())
mySpinBox->setValue(aDefVal);
}
- QString aTTip = QString::fromStdString(theData->widgetTooltip());
+ QString aTTip = translate(theData->widgetTooltip());
mySpinBox->setToolTip(aTTip);
myLabel->setToolTip(aTTip);
QFormLayout* aLayout = new QFormLayout(this);
ModuleBase_Tools::adjustMargins(aLayout);
- QString aLabelText = QString::fromStdString(theData->widgetLabel());
+ QString aLabelText = translate(theData->widgetLabel());
QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
myLabel = new QLabel(aLabelText, this);
if (!aLabelIcon.isEmpty())
myLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(aLabelIcon));
- QString aToolTip = QString::fromStdString(theData->widgetTooltip());
+ QString aToolTip = translate(theData->widgetTooltip());
myTextLine = new QLineEdit(this);
QString anObjName = QString::fromStdString(attributeID());
myTextLine->setObjectName(anObjName);
const Config_WidgetAPI* theData)
: ModuleBase_ModelWidget(theParent, theData)
{
- myTitle = QString::fromStdString(theData->getProperty("title"));
+ myTitle = translate(theData->getProperty("title"));
myType = (theData->getProperty("type") == "save") ? WFS_SAVE : WFS_OPEN;
myDefaultPath = QString::fromStdString(theData->getProperty("path"));
QFormLayout* aControlLay = new QFormLayout(this);
ModuleBase_Tools::adjustMargins(aControlLay);
- QString aLabelText = QString::fromStdString(theData->widgetLabel());
+ QString aLabelText = translate(theData->widgetLabel());
QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
myLabel = new QLabel(aLabelText, this);
if (!aLabelIcon.isEmpty())
mySpinBox->setValue(aDefVal);
}
- QString aTTip = QString::fromStdString(theData->widgetTooltip());
+ QString aTTip = translate(theData->widgetTooltip());
mySpinBox->setToolTip(aTTip);
myLabel->setToolTip(aTTip);
const Config_WidgetAPI* theData)
: ModuleBase_ModelWidget(theParent, theData)
{
- QString aText = QString::fromStdString(theData->getProperty("title"));
+ QString aText = translate(theData->getProperty("title"));
QString aLabelIcon = QString::fromStdString(theData->getProperty("icon"));
myLabel = new QLabel(aText, theParent);
if (!aLabelIcon.isEmpty()) {
if (aStrAttr.get()) {
aMsg = aStrAttr->value();
}
- ModuleBase_Tools::translate(myFeature->getKind(), aMsg);
- myLabel->setText(aMsg.c_str());
+ QString aText = ModuleBase_Tools::translate(myFeature->getKind(), aMsg);
+ myLabel->setText(aText);
}
return true;
}
{
QFormLayout* aMainLay = new QFormLayout(this);
ModuleBase_Tools::adjustMargins(aMainLay);
- QString aLabelText = QString::fromStdString(theData->widgetLabel());
+ QString aLabelText = translate(theData->widgetLabel());
QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
QLabel* aLabel = new QLabel(aLabelText, this);
if (!aLabelIcon.isEmpty())
myTypeCombo->setVisible(false);
}
- std::string aLabelText = theData->getProperty("label");
- QLabel* aListLabel = new QLabel(!aLabelText.empty() ? aLabelText.c_str()
- : tr("Selected objects:"), this);
+ QString aLabelText = translate(theData->getProperty("label"));
+ QLabel* aListLabel = new QLabel(aLabelText, this);
aMainLay->addWidget(aListLabel, 1, 0);
// if the xml definition contains one type, an information label
// should be shown near to the latest
if (theType == GroupBox && !myGroupBox) {
// group box: more than one model widget is inside
myGroupBox = new QGroupBox(this);
- myGroupBox->setTitle(QString::fromStdString(myGroupTitle));
+ myGroupBox->setTitle(translate(myGroupTitle));
myGroupBox->setVisible(false);
myGroupBox->setCheckable(true);
myGroupBox->setChecked(getDefaultValue() == "true");
- myGroupBox->setToolTip(QString::fromStdString(myToolTip));
+ myGroupBox->setToolTip(translate(myToolTip));
myGroupBoxLayout = new QGridLayout(myGroupBox);
ModuleBase_Tools::zeroMargins(myGroupBoxLayout);
#include <ModuleBase_ViewerPrs.h>
#include <ModuleBase_IconFactory.h>
+#include <Config_Translator.h>
#include <Config_WidgetAPI.h>
#include <Events_Loop.h>
#include <Events_Message.h>
QFormLayout* aLayout = new QFormLayout(this);
ModuleBase_Tools::adjustMargins(aLayout);
- QString aLabelText = QString::fromStdString(theData->widgetLabel());
+ QString aLabelText = translate(theData->widgetLabel());
QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
myLabel = new QLabel(aLabelText, this);
if (!aLabelIcon.isEmpty())
myLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(aLabelIcon));
- QString aToolTip = QString::fromStdString(theData->widgetTooltip());
+ QString aToolTip = translate(theData->widgetTooltip());
myTextLine = new QLineEdit(this);
QString anObjName = QString::fromStdString(attributeID());
myTextLine->setObjectName(anObjName);
QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
{
- std::string anError = "";
+ QString anError;
if (!theFeature.get() || !theFeature->data()->isValid())
- return anError.c_str();
+ return anError;
CompositeFeaturePtr aSketch = activeSketch();
if (aSketch.get() && aSketch == theFeature) {
- AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
- anError = aAttributeString->value();
- ModuleBase_Tools::translate(aSketch->getKind(), anError);
+ std::string aSolverError = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR())->value();
+ anError = ModuleBase_Tools::translate(aSketch->getKind(), aSolverError);
}
- return anError.c_str();
+ return anError;
}
void PartSet_SketcherMgr::clearClickedFlags()
void XGUI_ErrorDialog::addError(std::shared_ptr<Events_InfoMessage> theMsg)
{
std::string aError = Config_Translator::translate(*theMsg);
- std::string aCodec = Config_Translator::codec(theMsg->context());
+ std::string aCodec = Config_Translator::codec(*theMsg);
QString aMsg = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aError.c_str());
myErrors.append(aMsg);
refresh();