#include "Config_Common.h"
#include <Events_Error.h>
+#include <Events_InfoMessage.h>
Config_DataModelReader::Config_DataModelReader()
std::string aName = getProperty(theNode, FOLDER_NAME);
std::string aGroupType = getProperty(theNode, GROUP_TYPE);
if (aName.empty() || aGroupType.empty())
- Events_Error::send("Reading dataModel.xml: wrong folder definition");
+ Events_InfoMessage("Config_DataModelReader", "Reading dataModel.xml: wrong folder definition.").send();
std::string aIcon = getProperty(theNode, NODE_ICON);
std::string aEmpty = getProperty(theNode, SHOW_EMPTY);
return true;
}
-std::string Config_Translator::translate(const Events_InfoMessage& theInfo)
+std::string Config_Translator::translate(std::shared_ptr<Events_InfoMessage> theInfo)
{
- std::string aContext = theInfo.context();
- std::string aMessage = theInfo.message();
- std::list<std::string> aParameters = theInfo.parameters();
- if (myTranslator.count(aContext) > 0) {
- if (myTranslator[aContext].count(aMessage) > 0) {
- std::string aTranslation = myTranslator[aContext][aMessage];
- if (aParameters.size() > 0) {
- std::list<std::string>::const_iterator aIt;
- int i;
- char aBuf[20];
- std::string aParam;
- for (i=1, aIt = aParameters.cbegin(); aIt != aParameters.cend(); aIt++, i++) {
- aParam = (*aIt);
- sprintf(aBuf, "%d ", i);
- std::string aCode = std::string("%") + std::string(aBuf);
- size_t aPos = aTranslation.find(aCode);
- if (aPos != std::string::npos) {
- std::string aFirst = aTranslation.substr(0, aPos);
- std::string aLast = aTranslation.substr(aPos + aCode.length(), std::string::npos);
- aTranslation = aFirst + aParam + aLast;
- }
- }
+ std::string aContext = theInfo->context();
+ std::string aMessage = theInfo->message();
+ std::list<std::string> aParameters = theInfo->parameters();
+ return translate(aContext, aMessage, aParameters);
+}
+
+
+std::string insertParameters(const std::string& theString, const std::list<std::string>& theParams)
+{
+ std::string aResult = theString;
+ std::list<std::string>::const_iterator aIt;
+ int i;
+ char aBuf[20];
+ std::string aParam;
+ for (i=1, aIt = theParams.cbegin(); aIt != theParams.cend(); aIt++, i++) {
+ aParam = (*aIt);
+ sprintf_s(aBuf, "%d", i);
+ std::string aCode = std::string("%") + std::string(aBuf);
+ size_t aPos = aResult.find(aCode);
+ if (aPos != std::string::npos) {
+ std::string aFirst = aResult.substr(0, aPos);
+ std::string aLast = aResult.substr(aPos + aCode.length(), std::string::npos);
+ aResult = aFirst + aParam + aLast;
+ }
+ }
+ return aResult;
+}
+
+std::string Config_Translator::translate(const std::string& theContext,
+ const std::string& theMessage,
+ const std::list<std::string>& theParams)
+{
+ if (myTranslator.count(theContext) > 0) {
+ if (myTranslator[theContext].count(theMessage) > 0) {
+ std::string aTranslation = myTranslator[theContext][theMessage];
+ if (theParams.size() > 0) {
+ aTranslation = insertParameters(aTranslation, theParams);
}
return aTranslation;
}
}
- return "";
+ std::string aMsg = theMessage;
+ if (theParams.size() > 0) {
+ aMsg = insertParameters(aMsg, theParams);
+ }
+ return aMsg;
}
#include <string>
#include <map>
+/**
+ * \class Config_Translator
+ * \ingroup Config
+ * \brief Class for messages translation on different languages. It can load TS
+ * files wich contain translation string and provides translations of messages from source code
+ */
class Config_Translator
{
public:
* from the info data without translation
* \param theInfo an info message
*/
- static CONFIG_EXPORT std::string translate(const Events_InfoMessage& theInfo);
+ static CONFIG_EXPORT std::string translate(std::shared_ptr<Events_InfoMessage> theInfo);
+
+ /**
+ * Returns translation from the given data.
+ * If transdlation 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)
+ */
+ static CONFIG_EXPORT std::string translate(const std::string& theContext,
+ const std::string& theMessage,
+ const std::list<std::string>& theParams = std::list<std::string>());
private:
static Translator myTranslator;
#include <Events_Message.h>
#include <Events_Loop.h>
+/**\class Events_InfoMessage
+ * \ingroup EventsLoop
+ * \brief An event message for sending a string message which has to be translated.
+ */
class Events_InfoMessage: public Events_Message
{
public:
- Events_InfoMessage(const void* theSender = 0) :
- Events_Message(Events_Loop::eventByName("InfoMessage"), theSender) {}
+ /// Constructor
+ /// \param theSender a pointer on sender object
+ Events_InfoMessage(const void* theSender = 0):Events_Message(Events_Loop::eventByName("InfoMessage"), theSender) {}
+
+ /// Constructor
+ /// \param theSender a pointer on sender object
+ Events_InfoMessage(const std::string& theContext,
+ const std::string& theMsg, const void* theSender = 0):
+ Events_Message(Events_Loop::eventByName("InfoMessage"), theSender),
+ myContext(theContext), myMessage(theMsg) {}
+
+ /// default destructor
+ virtual ~Events_InfoMessage() {}
+
+ /// Identifier of this event (one for all errors)
+ static Events_ID errorID() { return Events_Loop::loop()->eventByName("InfoMessage"); }
+
+ /// Set a context string
+ /// \param theContext a context string
void setContext(const std::string& theContext) { myContext = theContext; }
+
+ /// Returns context string
std::string context() const { return myContext; }
+ /// Set message string for translation
+ /// \param theMsg the string of message
void setMessage(const std::string& theMsg) { myMessage = theMsg; }
+ /// Returns message
std::string message() const { return myMessage; }
+ /// Add parameter for message string of string type
+ /// \param theParam the parameter
void addParameter(const std::string& theParam)
{
myParameters.push_back(theParam);
}
+ /// Add parameter for message string of double type
+ /// \param theParam the parameter
void addParameter(double theParam)
{
char aBuf[50];
myParameters.push_back(aStr);
}
+ /// Add parameter for message string of integer type
+ /// \param theParam the parameter
void addParameter(int theParam)
{
char aBuf[50];
myParameters.push_back(aStr);
}
+ /// Returns list of parameters
std::list<std::string> parameters() const { return myParameters; }
+ /// Add parameter for message string of string type
+ /// \param theParam the parameter
+ Events_InfoMessage& arg(const std::string& theParam) { addParameter(theParam); return *this; }
+
+ /// Add parameter for message string of integer type
+ /// \param theParam the parameter
+ Events_InfoMessage& arg(int theParam) { addParameter(theParam); return *this; }
+
+ /// Add parameter for message string of double type
+ /// \param theParam the parameter
+ Events_InfoMessage& arg(double theParam) { addParameter(theParam); return *this; }
+
+ void send() {
+ std::shared_ptr<Events_Message> aMsg(new Events_InfoMessage(*this));
+ Events_Loop::loop()->send(aMsg);
+ }
+
private:
/// Context of the messgae
/// Event ID that visualization must be redisplayed (comes with ModelAPI_ObjectUpdatedMessage)
static const char * EVENT_OPERATION_LAUNCHED = "OperationLaunched";
/// Event ID that plugin is loaded (comes with ModelAPI_ObjectUpdatedMessage)
-static const char * EVENT_PLUGIN_LOADED = "PliginLoaded";
+static const char * EVENT_PLUGIN_LOADED = "PluginLoaded";
//
static const char * EVENT_DOCUMENT_CHANGED = "CurrentDocumentChanged";
#include <Config_PointerMessage.h>
#include <Config_WidgetReader.h>
#include <Config_ModuleReader.h>
+#include <Config_Translator.h>
#include <QAction>
#include <QMainWindow>
QString ModuleBase_IModule::getFeatureError(const FeaturePtr& theFeature)
{
- return ModelAPI_Tools::getFeatureError(theFeature).c_str();
+ QString aMsg = ModelAPI_Tools::getFeatureError(theFeature).c_str();
+ if (!aMsg.isEmpty())
+ aMsg = Config_Translator::translate(theFeature->getKind(), aMsg.toStdString()).c_str();
+ return aMsg;
}
void ModuleBase_IModule::grantedOperationIds(ModuleBase_Operation* theOperation,
<name>SketchConstraintVertical</name>
<message>
<source>Model_FeatureValidator: Attribute "ConstraintEntityA" is not initialized.</source>
- <translation>Line for constraint is not selected.</translation>
+ <translation>Select a line for the constraint definition.</translation>
</message>
<message>
<source>ModelAPI_StateInvalidArgument</source>
#include <XGUI_ErrorDialog.h>
#include <ModuleBase_Tools.h>
+#include <Config_Translator.h>
#include <QDialogButtonBox>
#include <QHBoxLayout>
QDialog::reject();
}
-void XGUI_ErrorDialog::addError(const QString& theError)
+void XGUI_ErrorDialog::addError(std::shared_ptr<Events_InfoMessage> theMsg)
{
- myErrors.append(theError);
+ std::string aError = Config_Translator::translate(theMsg);
+ myErrors.append(aError.c_str());
refresh();
if (!isVisible()) {
show();
#include <QDialog>
class QTextEdit;
+class Events_InfoMessage;
/**
* \ingroup GUI
XGUI_EXPORT void clear();
/// Add error message
- XGUI_EXPORT void addError(const QString&);
+ XGUI_EXPORT void addError(std::shared_ptr<Events_InfoMessage> theMsg);
/// Remove error message
XGUI_EXPORT void removeError(const QString&);
{
XGUI_SelectionMgr* aSelector = myWorkshop->selector();
connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
-
- XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
}
XGUI_ModuleConnector::~XGUI_ModuleConnector()
myDisplayer(0)
//myViewerSelMode(TopAbs_FACE)
{
+ mySelector = new XGUI_SelectionMgr(this);
+ myModuleConnector = new XGUI_ModuleConnector(this);
+ myOperationMgr = new XGUI_OperationMgr(this, 0);
+ ModuleBase_IWorkshop* aWorkshop = moduleConnector();
+ // Has to be defined first in order to get errors and messages from other components
+ myEventsListener = new XGUI_WorkshopListener(aWorkshop);
+
#ifndef HAVE_SALOME
myMainWindow = new AppElements_MainWindow();
}
myDataModelXMLReader = new Config_DataModelReader();
- myDataModelXMLReader->readAll();
+ //myDataModelXMLReader->readAll();
myDisplayer = new XGUI_Displayer(this);
- mySelector = new XGUI_SelectionMgr(this);
connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateCommandStatus()));
- myOperationMgr = new XGUI_OperationMgr(this, 0);
myActionsMgr = new XGUI_ActionsMgr(this);
myMenuMgr = new XGUI_MenuMgr(this);
myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop());
//connect(myViewerProxy, SIGNAL(selectionChanged()),
// myActionsMgr, SLOT(updateOnViewSelection()));
- myModuleConnector = new XGUI_ModuleConnector(this);
-
- ModuleBase_IWorkshop* aWorkshop = moduleConnector();
myOperationMgr->setWorkshop(aWorkshop);
myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop);
- myEventsListener = new XGUI_WorkshopListener(aWorkshop);
connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)),
SLOT(onOperationStarted(ModuleBase_Operation*)));
onTrihedronVisibilityChanged(true);
#endif
- connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
- connect(myEventsListener, SIGNAL(errorOccurred(const QString&)),
- myErrorDlg, SLOT(addError(const QString&)));
+ connect(myEventsListener, SIGNAL(errorOccurred(std::shared_ptr<Events_InfoMessage>)),
+ myErrorDlg, SLOT(addError(std::shared_ptr<Events_InfoMessage>)));
//Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
// Config_Prop::Color, "225,225,225");
//******************************************************
void XGUI_Workshop::startApplication()
{
+ //Initialize event listening
+ myEventsListener->initializeEventListening();
+
+ myDataModelXMLReader->readAll();
initMenu();
Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
Config_Prop::Directory, "");
- //Initialize event listening
- myEventsListener->initializeEventListening();
registerValidators();
/// Emitted when selection happens in Salome viewer
void salomeViewerSelection();
- /// Emitted when error in application happens
- void errorOccurred(const QString&);
-
//! the signal about the workshop actions states are updated.
void commandStatusUpdated();
#include <Config_PointerMessage.h>
#include <Config_SelectionFilterMessage.h>
#include <Config_Keywords.h>
+#include <Events_InfoMessage.h>
#include <QApplication>
#include <QMainWindow>
{
//Initialize event listening
Events_Loop* aLoop = Events_Loop::loop();
- aLoop->registerListener(this, Events_Error::errorID()); //!< Listening application errors.
+ //aLoop->registerListener(this, Events_Error::errorID()); //!< Listening application errors.
+ aLoop->registerListener(this, Events_InfoMessage::errorID()); //!< Listening application errors.
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED));
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
aDisplayer->enableUpdateViewer(true);
} else {
//Show error dialog if error message received.
- std::shared_ptr<Events_Error> anAppError = std::dynamic_pointer_cast<Events_Error>(theMessage);
- if (anAppError) {
- emit errorOccurred(QString::fromLatin1(anAppError->description()));
+ std::shared_ptr<Events_InfoMessage> anIngfoMsg = std::dynamic_pointer_cast<Events_InfoMessage>(theMessage);
+ if (anIngfoMsg) {
+ emit errorOccurred(anIngfoMsg);
}
return;
}
#include <Events_Message.h>
#include <ModelAPI_Feature.h>
+#include <Events_InfoMessage.h>
#include <QObject>
class ModuleBase_IWorkshop;
class QString;
+class Events_InfoMessage;
/**\class XGUI_WorkshopListener
* \ingroup GUI
signals:
/// Emitted when error in applivation happens
- void errorOccurred(const QString&);
+ void errorOccurred(std::shared_ptr<Events_InfoMessage> theMsg);
protected:
/// Procedure to process postponed events
<context>
<name>XGUI_ErrorDialog</name>
<message>
- <location filename="XGUI_ErrorDialog.cpp" line="23"/>
+ <location filename="XGUI_ErrorDialog.cpp" line="24"/>
<source>Application errors</source>
<translation type="unfinished"></translation>
</message>
<context>
<name>XGUI_Workshop</name>
<message>
- <location filename="XGUI_Workshop.cpp" line="300"/>
- <location filename="XGUI_Workshop.cpp" line="354"/>
+ <location filename="XGUI_Workshop.cpp" line="302"/>
+ <location filename="XGUI_Workshop.cpp" line="356"/>
<source>Undo</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="301"/>
- <location filename="XGUI_Workshop.cpp" line="354"/>
+ <location filename="XGUI_Workshop.cpp" line="303"/>
+ <location filename="XGUI_Workshop.cpp" line="356"/>
<source>Undo last command</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="304"/>
+ <location filename="XGUI_Workshop.cpp" line="306"/>
<source>INF_DESK_TOOLBAR_STANDARD</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="310"/>
- <location filename="XGUI_Workshop.cpp" line="363"/>
+ <location filename="XGUI_Workshop.cpp" line="312"/>
+ <location filename="XGUI_Workshop.cpp" line="365"/>
<source>Redo</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="310"/>
- <location filename="XGUI_Workshop.cpp" line="363"/>
+ <location filename="XGUI_Workshop.cpp" line="312"/>
+ <location filename="XGUI_Workshop.cpp" line="365"/>
<source>Redo last command</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="327"/>
+ <location filename="XGUI_Workshop.cpp" line="329"/>
<source>Export native...</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="327"/>
+ <location filename="XGUI_Workshop.cpp" line="329"/>
<source>Export the current document into a native file</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="332"/>
+ <location filename="XGUI_Workshop.cpp" line="334"/>
<source>Import native...</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="332"/>
+ <location filename="XGUI_Workshop.cpp" line="334"/>
<source>Import native file</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="344"/>
- <location filename="XGUI_Workshop.cpp" line="833"/>
+ <location filename="XGUI_Workshop.cpp" line="346"/>
+ <location filename="XGUI_Workshop.cpp" line="835"/>
<source>Save</source>
<extracomment>Title of the dialog which asks user if he wants to save study in existing non-empty folder</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="344"/>
+ <location filename="XGUI_Workshop.cpp" line="346"/>
<source>Save the document</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="349"/>
+ <location filename="XGUI_Workshop.cpp" line="351"/>
<source>Save as...</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="349"/>
+ <location filename="XGUI_Workshop.cpp" line="351"/>
<source>Save the document into a file</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="377"/>
+ <location filename="XGUI_Workshop.cpp" line="379"/>
<source>Open...</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="377"/>
+ <location filename="XGUI_Workshop.cpp" line="379"/>
<source>Open a new document</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="381"/>
+ <location filename="XGUI_Workshop.cpp" line="383"/>
<source>Preferences</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="381"/>
+ <location filename="XGUI_Workshop.cpp" line="383"/>
<source>Edit preferences</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="385"/>
+ <location filename="XGUI_Workshop.cpp" line="387"/>
<source>Exit</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="385"/>
+ <location filename="XGUI_Workshop.cpp" line="387"/>
<source>Exit application</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="695"/>
- <location filename="XGUI_Workshop.cpp" line="751"/>
+ <location filename="XGUI_Workshop.cpp" line="697"/>
+ <location filename="XGUI_Workshop.cpp" line="753"/>
<source>Save current file</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="696"/>
+ <location filename="XGUI_Workshop.cpp" line="698"/>
<source>The document is modified, save before opening another?</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="707"/>
+ <location filename="XGUI_Workshop.cpp" line="709"/>
<source>Select directory</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="712"/>
+ <location filename="XGUI_Workshop.cpp" line="714"/>
<source>Warning</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="712"/>
+ <location filename="XGUI_Workshop.cpp" line="714"/>
<source>Unable to open the file.</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="751"/>
+ <location filename="XGUI_Workshop.cpp" line="753"/>
<source>The document is modified, save before exit?</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="817"/>
+ <location filename="XGUI_Workshop.cpp" line="819"/>
<source>Select directory to save files...</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="819"/>
+ <location filename="XGUI_Workshop.cpp" line="821"/>
<source>Directories (*)</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="834"/>
+ <location filename="XGUI_Workshop.cpp" line="836"/>
<source>The directory already contains some files, save anyway?</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="967"/>
+ <location filename="XGUI_Workshop.cpp" line="969"/>
<source>Information about module "%1" doesn't exist.</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="1098"/>
+ <location filename="XGUI_Workshop.cpp" line="1100"/>
<source>Object browser</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="1430"/>
+ <location filename="XGUI_Workshop.cpp" line="1432"/>
<source>Unused features are the following: %1.
These features will be deleted.
Would you like to continue?</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="1468"/>
+ <location filename="XGUI_Workshop.cpp" line="1470"/>
<source>All features are relevant, there is nothing to be deleted</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="1968"/>
+ <location filename="XGUI_Workshop.cpp" line="1970"/>
<source>Find results</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_Workshop.cpp" line="1969"/>
+ <location filename="XGUI_Workshop.cpp" line="1971"/>
<source>Results not found</source>
<translation type="unfinished"></translation>
</message>