Skip to content

Commit b0914b2

Browse files
committed
- Use the fileName argument of parseString & loadString.
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23855 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 4c37e90 commit b0914b2

File tree

6 files changed

+50
-62
lines changed

6 files changed

+50
-62
lines changed

OMEdit/OMEditGUI/Editors/ModelicaTextEditor.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,22 +167,22 @@ QStringList ModelicaTextEditor::getClassNames(QString *errorString)
167167
OMCProxy *pOMCProxy = mpModelWidget->getModelWidgetContainer()->getMainWindow()->getOMCProxy();
168168
QStringList classNames;
169169
LibraryTreeNode *pLibraryTreeNode = mpModelWidget->getLibraryTreeNode();
170-
if (toPlainText().isEmpty())
171-
{
170+
if (toPlainText().isEmpty()) {
172171
*errorString = tr("Start and End modifiers are different");
173172
return QStringList();
174-
}
175-
else
176-
{
177-
if (pLibraryTreeNode->getParentName().isEmpty())
178-
{
179-
classNames = pOMCProxy->parseString(StringHandler::escapeString(toPlainText()));
180-
}
181-
else
182-
{
183-
classNames = pOMCProxy->parseString("within " + pLibraryTreeNode->getParentName() + ";" + StringHandler::escapeString(toPlainText()));
173+
} else {
174+
if (pLibraryTreeNode->getParentName().isEmpty()) {
175+
classNames = pOMCProxy->parseString(StringHandler::escapeString(toPlainText()), pLibraryTreeNode->getNameStructure());
176+
} else {
177+
classNames = pOMCProxy->parseString("within " + pLibraryTreeNode->getParentName() + ";" + StringHandler::escapeString(toPlainText()), pLibraryTreeNode->getNameStructure());
184178
}
185179
}
180+
// if user is defining multiple top level classes.
181+
if (classNames.size() > 1) {
182+
*errorString = QString(GUIMessages::getMessage(GUIMessages::MULTIPLE_TOP_LEVEL_CLASSES)).arg(pLibraryTreeNode->getNameStructure())
183+
.arg(classNames.join(","));
184+
return QStringList();
185+
}
186186
bool existModel = false;
187187
QStringList existingmodelsList;
188188
// check if the class already exists

OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,49 +1924,41 @@ void LibraryTreeWidget::openFile(QString fileName, QString encoding, bool showPr
19241924

19251925
void LibraryTreeWidget::parseAndLoadModelicaText(QString modelText)
19261926
{
1927-
QStringList modelsList = mpMainWindow->getOMCProxy()->parseString(StringHandler::escapeString(modelText));
1928-
if (modelsList.size() == 0)
1927+
QStringList classNames = mpMainWindow->getOMCProxy()->parseString(StringHandler::escapeString(modelText), "");
1928+
if (classNames.size() == 0) {
1929+
return;
1930+
}
1931+
// if user is defining multiple top level classes.
1932+
if (classNames.size() > 1) {
1933+
QMessageBox::critical(mpMainWindow, QString(Helper::applicationName).append(" - ").append(Helper::error),
1934+
QString(GUIMessages::getMessage(GUIMessages::MULTIPLE_TOP_LEVEL_CLASSES)).arg("").arg(classNames.join(",")),
1935+
Helper::ok);
19291936
return;
1930-
QStringList existingmodelsList;
1931-
bool existModel = false;
1932-
// check if the model already exists
1933-
foreach(QString model, modelsList)
1934-
{
1935-
if (mpMainWindow->getOMCProxy()->existClass(model))
1936-
{
1937-
existingmodelsList.append(model);
1938-
existModel = true;
1939-
}
19401937
}
1938+
QString className = classNames.at(0);
1939+
bool existModel = mpMainWindow->getOMCProxy()->existClass(className);
19411940
// check if existModel is true
1942-
if (existModel)
1943-
{
1941+
if (existModel) {
19441942
QMessageBox *pMessageBox = new QMessageBox(mpMainWindow);
19451943
pMessageBox->setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::information));
19461944
pMessageBox->setIcon(QMessageBox::Information);
19471945
pMessageBox->setText(QString(GUIMessages::getMessage(GUIMessages::UNABLE_TO_LOAD_MODEL).arg("")));
19481946
pMessageBox->setInformativeText(QString(GUIMessages::getMessage(GUIMessages::REDEFINING_EXISTING_CLASSES))
1949-
.arg(existingmodelsList.join(",")).append("\n")
1947+
.arg(className).append("\n")
19501948
.append(GUIMessages::getMessage(GUIMessages::DELETE_AND_LOAD).arg("")));
19511949
pMessageBox->setStandardButtons(QMessageBox::Ok);
19521950
pMessageBox->exec();
1953-
}
1954-
// if no conflicting model found then just load the file simply
1955-
else
1956-
{
1951+
} else { // if no conflicting model found then just load the file simply
19571952
// load the model text in OMC
1958-
if (mpMainWindow->getOMCProxy()->loadString(StringHandler::escapeString(modelText)))
1959-
{
1960-
foreach (QString model, modelsList)
1961-
{
1962-
QString modelName = StringHandler::getLastWordAfterDot(model);
1963-
QString parentName = StringHandler::removeLastWordAfterDot(model);
1964-
if (modelName.compare(parentName) == 0)
1965-
parentName = "";
1966-
LibraryTreeNode *pLibraryTreeNode;
1967-
pLibraryTreeNode = addLibraryTreeNode(modelName, mpMainWindow->getOMCProxy()->getClassRestriction(modelName), parentName);
1968-
createLibraryTreeNodes(pLibraryTreeNode);
1953+
if (mpMainWindow->getOMCProxy()->loadString(StringHandler::escapeString(modelText), className)) {
1954+
QString modelName = StringHandler::getLastWordAfterDot(className);
1955+
QString parentName = StringHandler::removeLastWordAfterDot(className);
1956+
if (modelName.compare(parentName) == 0) {
1957+
parentName = "";
19691958
}
1959+
LibraryTreeNode *pLibraryTreeNode;
1960+
pLibraryTreeNode = addLibraryTreeNode(modelName, mpMainWindow->getOMCProxy()->getClassRestriction(className), parentName);
1961+
createLibraryTreeNodes(pLibraryTreeNode);
19701962
}
19711963
}
19721964
}

OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2708,26 +2708,22 @@ bool ModelWidget::modelicaEditorTextChanged()
27082708
QStringList classNames = mpModelicaTextEditor->getClassNames(&errorString);
27092709
LibraryTreeWidget *pLibraryTreeWidget = mpModelWidgetContainer->getMainWindow()->getLibraryTreeWidget();
27102710
OMCProxy *pOMCProxy = mpModelWidgetContainer->getMainWindow()->getOMCProxy();
2711-
if (classNames.size() == 0)
2712-
{
2713-
if (!errorString.isEmpty())
2714-
{
2711+
if (classNames.size() == 0) {
2712+
if (!errorString.isEmpty()) {
27152713
MessagesWidget *pMessagesWidget = getModelWidgetContainer()->getMainWindow()->getMessagesWidget();
27162714
pMessagesWidget->addGUIMessage(new MessageItem("", false, 0, 0, 0, 0, errorString, Helper::syntaxKind, Helper::errorLevel, 0));
27172715
}
27182716
return false;
27192717
}
27202718
/* if no errors are found with the Modelica Text then load it in OMC */
27212719
QString modelicaText = mpModelicaTextEditor->toPlainText();
2722-
if (mpLibraryTreeNode->getParentName().isEmpty())
2723-
{
2724-
if (!pOMCProxy->loadString(StringHandler::escapeString(modelicaText)))
2720+
if (mpLibraryTreeNode->getParentName().isEmpty()) {
2721+
if (!pOMCProxy->loadString(StringHandler::escapeString(modelicaText), classNames.at(0)))
27252722
return false;
2726-
}
2727-
else
2728-
{
2729-
if (!pOMCProxy->loadString("within " + mpLibraryTreeNode->getParentName() + ";" + StringHandler::escapeString(modelicaText)))
2723+
} else {
2724+
if (!pOMCProxy->loadString("within " + mpLibraryTreeNode->getParentName() + ";" + StringHandler::escapeString(modelicaText), classNames.at(0))) {
27302725
return false;
2726+
}
27312727
}
27322728
/* first handle the current class */
27332729
/* if user has changed the class then refresh it. */

OMEdit/OMEditGUI/OMC/OMCProxy.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,9 +1741,9 @@ bool OMCProxy::loadFile(QString fileName, QString encoding)
17411741
\param value - the string to load.
17421742
\return true on success
17431743
*/
1744-
bool OMCProxy::loadString(QString value, bool checkError)
1744+
bool OMCProxy::loadString(QString value, QString fileName, bool checkError)
17451745
{
1746-
sendCommand("loadString(\"" + value.replace("\"", "\\\"") + "\")");
1746+
sendCommand("loadString(\"" + value.replace("\"", "\\\"") + "\", \"" + fileName + "\")");
17471747
bool result = StringHandler::unparseBool(getResult());
17481748
if (checkError) {
17491749
printMessagesStringInternal();
@@ -1774,9 +1774,9 @@ bool OMCProxy::parseFile(QString fileName, QString encoding)
17741774
\param value - the string to parse.
17751775
\return the list of models inside the string.
17761776
*/
1777-
QStringList OMCProxy::parseString(QString value)
1777+
QStringList OMCProxy::parseString(QString value, QString fileName)
17781778
{
1779-
sendCommand("parseString(\"" + value.replace("\"", "\\\"") + "\")");
1779+
sendCommand("parseString(\"" + value.replace("\"", "\\\"") + "\", \"" + fileName + "\")");
17801780
QString result = StringHandler::removeFirstLastCurlBrackets(getResult());
17811781
QStringList list = result.split(",", QString::SkipEmptyParts);
17821782
printMessagesStringInternal();
@@ -1797,7 +1797,7 @@ bool OMCProxy::createClass(QString type, QString className, QString extendsClass
17971797
} else {
17981798
expression = type + " " + className + " extends " + extendsClass + "; end " + className + ";";
17991799
}
1800-
return loadString(StringHandler::escapeString(expression), false);
1800+
return loadString(StringHandler::escapeString(expression), className, false);
18011801
}
18021802

18031803
/*!
@@ -1815,7 +1815,7 @@ bool OMCProxy::createSubClass(QString type, QString className, QString parentCla
18151815
} else {
18161816
expression = "within " + parentClassName + "; " + type + " " + className + " extends " + extendsClass + "; end " + className + ";";
18171817
}
1818-
return loadString(StringHandler::escapeString(expression), false);
1818+
return loadString(StringHandler::escapeString(expression), parentClassName + "." + className, false);
18191819
}
18201820

18211821
/*!

OMEdit/OMEditGUI/OMC/OMCProxy.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ class OMCProxy : public QObject
170170
QString changeDirectory(QString directory = QString());
171171
bool loadModel(QString library, QString version = QString("default"));
172172
bool loadFile(QString fileName, QString encoding = Helper::utf8);
173-
bool loadString(QString value, bool checkError = true);
173+
bool loadString(QString value, QString fileName, bool checkError = true);
174174
bool parseFile(QString fileName, QString encoding = Helper::utf8);
175-
QStringList parseString(QString value);
175+
QStringList parseString(QString value, QString fileName);
176176
bool createClass(QString type, QString className, QString extendsClass);
177177
bool createSubClass(QString type, QString className, QString parentClassName, QString extendsClass);
178178
bool existClass(QString className);

OMEdit/OMEditGUI/Util/Helper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ QString GUIMessages::getMessage(int type)
508508
case REDEFINING_EXISTING_CLASSES:
509509
return tr("Redefining class(es) <b>%1</b> which already exists.");
510510
case MULTIPLE_TOP_LEVEL_CLASSES:
511-
return tr("Only single nonstructured entity is allowed to be stored in the file. The file <b>%1</b> contains following classes <b>%2</b>.");
511+
return tr("Only single nonstructured entity is allowed to be stored in the file. <b>%1</b> contains following classes <b>%2</b>.");
512512
case CLOSE_INTERACTIVE_SIMULATION_TAB:
513513
return tr("Are you sure you want to close <b>%1</b> interactive simulation?");
514514
case INFO_CLOSE_INTERACTIVE_SIMULATION_TAB:

0 commit comments

Comments
 (0)