-// Copyright (C) 2014-2019 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
#include <QKeyEvent>
#include <QDialogButtonBox>
#include <QShortcut>
+#include <QFileDialog>
+
+#ifdef WIN32
+#pragma warning(disable : 4456) // for nested foreach
+#endif
enum ColumnType {
Col_Name,
connect(myInsertBtn, SIGNAL(clicked(bool)), SLOT(onInsert()));
aBtnLayout->addWidget(myInsertBtn);
+ myImportBtn = new QPushButton(translate("Import file"), this);
+ connect(myImportBtn, SIGNAL(clicked(bool)), SLOT(onImport()));
+ aBtnLayout->addWidget(myImportBtn);
+
myRemoveBtn = new QPushButton(translate("Remove"), this);
connect(myRemoveBtn, SIGNAL(clicked(bool)), SLOT(onRemove()));
aBtnLayout->addWidget(myRemoveBtn);
if (aId == ModelAPI_AttributeDouble::typeId()) {
AttributeDoublePtr aDouble =
std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aAttr);
- aValNames << aDouble->text().c_str();
+ aValNames << QString::fromStdWString(aDouble->text());
aValNames << QString::number(aDouble->value());
}
else if (aId == ModelAPI_AttributeInteger::typeId()) {
AttributeIntegerPtr aInt =
std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(aAttr);
- aValNames << aInt->text().c_str();
+ aValNames << QString::fromStdWString(aInt->text());
aValNames << QString::number(aInt->value());
}
else if (aId == GeomDataAPI_Point::typeId()) {
std::shared_ptr<GeomDataAPI_Point> aPnt =
std::dynamic_pointer_cast<GeomDataAPI_Point>(aAttr);
- QString aExpr = QString("%1,%2,%3").arg(aPnt->textX().c_str()).
- arg(aPnt->textY().c_str()).arg(aPnt->textZ().c_str());
+ QString aExpr = QString("%1,%2,%3").arg(QString::fromStdWString(aPnt->textX())).
+ arg(QString::fromStdWString(aPnt->textY())).
+ arg(QString::fromStdWString(aPnt->textZ()));
aValNames << aExpr;
QString aRes = QString("%1,%2,%3").arg(aPnt->x()).arg(aPnt->y()).arg(aPnt->z());
std::shared_ptr<GeomDataAPI_Point2D> aPnt =
std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
- QString aExpr = QString("%1,%2").arg(aPnt->textX().c_str()).
- arg(aPnt->textY().c_str());
+ QString aExpr = QString("%1,%2").arg(QString::fromStdWString(aPnt->textX())).
+ arg(QString::fromStdWString(aPnt->textY()));
aValNames << aExpr;
QString aRes = QString("%1,%2").arg(aPnt->x()).arg(aPnt->y());
} else
aValues << aExpr.c_str();
- std::string aErr =
- aParameter->data()->string(ParametersPlugin_Parameter::EXPRESSION_ERROR_ID())->value();
+ aErr = aParameter->data()->string(ParametersPlugin_Parameter::EXPRESSION_ERROR_ID())->value();
if (aErr.empty()) {
AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE());
aValues << QString::number(aValueAttribute->value());
FeaturePtr aFeature = myParametersList.at(myDelegate->editIndex().row());
QTreeWidgetItem* aItem = myParameters->child(myDelegate->editIndex().row());
int aColumn = myDelegate->editIndex().column();
+ int aRow = myDelegate->editIndex().row();
QString aText = aItem->text(aColumn);
bool isModified = false;
while (aText.indexOf(" ") != -1) {
aText.replace(" ", "");
}
- if (hasName(aText)) {
+ if (hasName(aText, aRow)) {
myMessage = translate("Name '%1' already exists.").arg(aText);
QTimer::singleShot(50, this, SLOT(sendWarning()));
return;
case Col_Comment:
{
AttributeStringPtr aStringAttr = aFeature->string(ParametersPlugin_Parameter::COMMENT_ID());
- aStringAttr->setValue(aText.toStdString());
+ aStringAttr->setValue(aText.toStdWString());
isModified = true;
}
break;
}
}
+void ParametersPlugin_WidgetParamsMgr::onImport()
+{
+ std::string aWinText("Select txt file");
+ std::string aFileType("Text files (*.txt);;All files (*.*)");
+ QString aQPath = QFileDialog::getOpenFileName(nullptr,
+ aWinText.c_str(), "",
+ aFileType.c_str());
+ if (aQPath.size() == 0)
+ return;
+
+ std::string aPath(aQPath.toStdString());
+ std::shared_ptr<ModelAPI_ImportParametersMessage> aMessage =
+ std::shared_ptr<ModelAPI_ImportParametersMessage>(
+ new ModelAPI_ImportParametersMessage(ModelAPI_ImportParametersMessage::eventId()));
+ aMessage->setFilename(aPath);
+ Events_Loop::loop()->send(aMessage);
+
+ updateParametersFeatures();
+ updateParametersPart();
+}
+
void ParametersPlugin_WidgetParamsMgr::onUp()
{
QTreeWidgetItem* aCurrentItem = selectedItem();
}
-bool ParametersPlugin_WidgetParamsMgr::hasName(const QString& theName) const
+bool ParametersPlugin_WidgetParamsMgr::hasName(const QString& theName, int theIndex) const
{
- int aCurrent = myDelegate->editIndex().row();
int i = 0;
foreach(FeaturePtr aFeature, myParametersList) {
- if ((i != aCurrent) && (aFeature->data()->name() == theName.toStdWString()))
+ if ((i != theIndex) && (aFeature->data()->name() == theName.toStdWString()))
return true;
i++;
}
//myRemoveBtn->setEnabled(isParameter);
myUpBtn->setEnabled(isParameter);
myDownBtn->setEnabled(isParameter);
+ myImportBtn->setEnabled(true);
} else {
myInsertBtn->setEnabled(false);
//myRemoveBtn->setEnabled(false);
myUpBtn->setEnabled(false);
myDownBtn->setEnabled(false);
+ myImportBtn->setEnabled(false);
}
myRemoveBtn->setEnabled(!aItemsList.isEmpty());
}
//myRemoveBtn->setEnabled(theEnable);
myUpBtn->setEnabled(theEnable);
myDownBtn->setEnabled(theEnable);
+ myImportBtn->setEnabled(theEnable);
}
myOkCancelBtn->button(QDialogButtonBox::Ok)->setEnabled(theEnable);
}
aItem = myParameters->child(i);
if ((aItem->text(Col_Name) == NoName) ||
(aItem->text(Col_Equation) == translate(NoValue)) ||
- (!ModelAPI_Expression::isVariable(aItem->text(Col_Name).toStdString())) ) {
+ (!ModelAPI_Expression::isVariable(aItem->text(Col_Name).toStdString())) ||
+ (hasName(aItem->text(Col_Name), i)) ) {
return false;
}
}