-// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023 CEA, EDF
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include <pyconfig.h>
#include <Events_InfoMessage.h>
+#include <Locale_Convert.h>
+
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_AttributeRefList.h>
#include <QMessageBox>
+#include <ModuleBase_Tools.h>
+
#include <string>
#include <set>
#include <sstream>
//------------------------------------------------------------------------------
// Tools
-static std::string toStdString(double theValue)
+static std::wstring toStdWString(double theValue)
{
- std::ostringstream sstream;
+ std::wostringstream sstream;
sstream << theValue;
- size_t aPos = sstream.str().find(".");
- std::string aPnt = "";
- if (aPos == std::string::npos)
- aPnt = ".";
+ size_t aPos = sstream.str().find(L".");
+ std::wstring aPnt = L"";
+ if (aPos == std::wstring::npos)
+ aPnt = L".";
return sstream.str() + aPnt;
}
-static std::set<std::string> toSet(const std::list<std::string>& theContainer)
-{
- return std::set<std::string>(theContainer.begin(), theContainer.end());
-}
-
//------------------------------------------------------------------------------
ParametersPlugin_EvalListener::ParametersPlugin_EvalListener()
ModelAPI_ReplaceParameterMessage::eventId()
};
- for (int i = 0; i < sizeof(anEvents_IDs)/sizeof(anEvents_IDs[0]); ++i)
+ for (unsigned long long i = 0; i < sizeof(anEvents_IDs)/sizeof(anEvents_IDs[0]); ++i)
aLoop->registerListener(this, anEvents_IDs[i], NULL, true);
}
}
}
-std::string ParametersPlugin_EvalListener::renameInPythonExpression(
- const std::string& theExpression,
- const std::string& theOldName,
- const std::string& theNewName)
+std::wstring ParametersPlugin_EvalListener::renameInPythonExpression(
+ const std::wstring& theExpression,
+ const std::wstring& theOldName,
+ const std::wstring& theNewName)
{
- std::string anExpressionString = theExpression;
+ std::wstring anExpressionString = theExpression;
// ask interpreter to compute the positions in the expression
std::shared_ptr<ModelAPI_ComputePositionsMessage> aMsg =
int aLineNo = ritLine->first - 1;
size_t aLineStart = 0;
for (int i = 0; i < aLineNo; ++i)
- aLineStart = anExpressionString.find("\n", aLineStart) + 1;
+ aLineStart = anExpressionString.find(L"\n", aLineStart) + 1;
const std::list<int>& aColOffsets = ritLine->second;
std::list<int>::const_reverse_iterator ritOffset = aColOffsets.rbegin();
void ParametersPlugin_EvalListener::renameInParameter(
std::shared_ptr<ParametersPlugin_Parameter> theParameter,
- const std::string& theOldName,
- const std::string& theNewName)
+ const std::wstring& theOldName,
+ const std::wstring& theNewName)
{
std::shared_ptr<ModelAPI_AttributeString> anExpressionAttribute =
theParameter->string(ParametersPlugin_Parameter::EXPRESSION_ID());
- std::string anExpressionString = anExpressionAttribute->value();
+ std::wstring anExpressionString = anExpressionAttribute->isUValue() ?
+ Locale::Convert::toWString(anExpressionAttribute->valueU()) :
+ Locale::Convert::toWString(anExpressionAttribute->value());
anExpressionString = renameInPythonExpression(anExpressionString,
theOldName,
theNewName);
void ParametersPlugin_EvalListener::renameInAttribute(
std::shared_ptr<ModelAPI_Attribute> theAttribute,
- const std::string& theOldName,
- const std::string& theNewName)
+ const std::wstring& theOldName,
+ const std::wstring& theNewName)
{
if (theAttribute->attributeType() == ModelAPI_AttributeInteger::typeId()) {
AttributeIntegerPtr anAttribute =
std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(theAttribute);
- std::string anExpressionString = anAttribute->text();
+ std::wstring anExpressionString = anAttribute->text();
anExpressionString = renameInPythonExpression(anExpressionString,
theOldName, theNewName);
anAttribute->setText(anExpressionString);
if (theAttribute->attributeType() == ModelAPI_AttributeDouble::typeId()) {
AttributeDoublePtr anAttribute =
std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
- std::string anExpressionString = anAttribute->text();
+ std::wstring anExpressionString = anAttribute->text();
anExpressionString = renameInPythonExpression(anExpressionString,
theOldName, theNewName);
anAttribute->setText(anExpressionString);
if (theAttribute->attributeType() == GeomDataAPI_Point::typeId()) {
AttributePointPtr anAttribute =
std::dynamic_pointer_cast<GeomDataAPI_Point>(theAttribute);
- std::string anExpressionString[3] = {
+ std::wstring anExpressionString[3] = {
anAttribute->textX(),
anAttribute->textY(),
anAttribute->textZ()
if (theAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
AttributePoint2DPtr anAttribute =
std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
- std::string anExpressionString[2] = {
+ std::wstring anExpressionString[2] = {
anAttribute->textX(),
anAttribute->textY()
};
void ParametersPlugin_EvalListener::renameInDependents(
std::shared_ptr<ModelAPI_ResultParameter> theResultParameter,
- const std::string& theOldName,
- const std::string& theNewName)
+ const std::wstring& theOldName,
+ const std::wstring& theNewName)
{
std::set<std::shared_ptr<ModelAPI_Attribute> > anAttributes =
theResultParameter->data()->refsToMe();
void setParameterName(ResultParameterPtr theResultParameter, const std::string& theName)
{
bool aWasBlocked = theResultParameter->data()->blockSendAttributeUpdated(true);
- theResultParameter->data()->setName(theName);
+ theResultParameter->data()->setName(Locale::Convert::toWString(theName));
theResultParameter->data()->blockSendAttributeUpdated(aWasBlocked, false);
std::shared_ptr<ParametersPlugin_Parameter> aParameter =
std::dynamic_pointer_cast<ParametersPlugin_Parameter>(
ModelAPI_Feature::feature(theResultParameter));
- std::string anOldName = aParameter->name();
+ std::string anOldName = Locale::Convert::toString(aParameter->name());
aWasBlocked = aParameter->data()->blockSendAttributeUpdated(true);
- aParameter->data()->setName(theName);
+ aParameter->data()->setName(Locale::Convert::toWString(theName));
aParameter->string(ParametersPlugin_Parameter::VARIABLE_ID())->setValue(theName);
aParameter->data()->blockSendAttributeUpdated(aWasBlocked);
}
if (!aParameter.get())
return;
- std::string aNotActivatedNames;
+ std::wstring aNotActivatedNames;
if (!ModelAPI_Tools::allDocumentsActivated(aNotActivatedNames)) {
- QMessageBox::StandardButton aRes = QMessageBox::warning(0, QObject::tr("Warning"),
- QObject::tr("Selected objects can be used in Part documents which are not loaded: "
- "%1. Whould you like to continue?").arg(aNotActivatedNames.c_str()),
- QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
+ static const std::string aMsgContext("ParametersPlugin");
+ static const std::string aMsgText =
+ "Selected objects can be used in Part documents which are not loaded: " +
+ std::string("%1. Would you like to continue?");
+ Events_InfoMessage aMsg(aMsgContext, aMsgText);
+ aMsg.arg(aNotActivatedNames.c_str());
+ QMessageBox::StandardButton aRes =
+ QMessageBox::warning(0, ModuleBase_Tools::translate(aMsgContext, "Warning"),
+ ModuleBase_Tools::translate(aMsg),
+ QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
if (aRes != QMessageBox::Yes) {
- setParameterName(aResultParameter, aMessage->oldName());
+ setParameterName(aResultParameter, Locale::Convert::toString(aMessage->oldName()));
return;
}
}
// try to update the parameter feature according the new name
- setParameterName(aResultParameter, aMessage->newName());
+ setParameterName(aResultParameter, Locale::Convert::toString(aMessage->newName()));
if (!isValidAttribute(aParameter->string(ParametersPlugin_Parameter::VARIABLE_ID()))) {
//setParameterName(aResultParameter, aMessage->oldName());
if (myOldNames.find(aParameter.get()) == myOldNames.end())
return;
}
- std::string anOldName = aMessage->oldName();
+ std::wstring anOldName = aMessage->oldName();
if (myOldNames.find(aParameter.get()) != myOldNames.end()) {
anOldName = myOldNames[aParameter.get()];
myOldNames.erase(aParameter.get());
return;
double aRealValue = aResultParameter->data()->real(ModelAPI_ResultParameter::VALUE())->value();
- std::string aValue = toStdString(aRealValue);
+ std::wstring aValue = toStdWString(aRealValue);
renameInDependents(aResultParameter, aResultParameter->data()->name(), aValue);
}