Skip to content

Commit

Permalink
- Use getClassNames via direct scripting API.
Browse files Browse the repository at this point in the history
- Removed some unused APIs.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@24446 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Feb 5, 2015
1 parent cd436af commit 4239033
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 78 deletions.
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -1146,7 +1146,7 @@ void MainWindow::loadSystemLibrary()
if (mpOMCProxy->loadModel(pAction->text()))
{
/* since few libraries load dependent libraries automatically. So if the dependent library is not loaded then load it. */
QStringList systemLibs = mpOMCProxy->getClassNames("");
QStringList systemLibs = mpOMCProxy->getClassNames();
foreach (QString systemLib, systemLibs)
{
LibraryTreeNode* pLoadedLibraryTreeNode = mpLibraryTreeWidget->getLibraryTreeNode(systemLib);
Expand Down
6 changes: 3 additions & 3 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -677,7 +677,7 @@ void LibraryTreeWidget::addModelicaLibraries(QSplashScreen *pSplashScreen)
// load Modelica System Libraries.
mpMainWindow->getOMCProxy()->loadSystemLibraries(pSplashScreen);
pSplashScreen->showMessage(tr("Creating Components"), Qt::AlignRight, Qt::white);
QStringList systemLibs = mpMainWindow->getOMCProxy()->getClassNames("");
QStringList systemLibs = mpMainWindow->getOMCProxy()->getClassNames();
systemLibs.prepend("OpenModelica");
systemLibs.sort();
foreach (QString lib, systemLibs)
Expand All @@ -698,7 +698,7 @@ void LibraryTreeWidget::addModelicaLibraries(QSplashScreen *pSplashScreen)
}
// load Modelica User Libraries.
mpMainWindow->getOMCProxy()->loadUserLibraries(pSplashScreen);
QStringList userLibs = mpMainWindow->getOMCProxy()->getClassNames("");
QStringList userLibs = mpMainWindow->getOMCProxy()->getClassNames();
foreach (QString lib, userLibs)
{
if (systemLibs.contains(lib))
Expand All @@ -720,7 +720,7 @@ void LibraryTreeWidget::addModelicaLibraries(QSplashScreen *pSplashScreen)

void LibraryTreeWidget::createLibraryTreeNodes(LibraryTreeNode *pLibraryTreeNode)
{
QStringList libs = mpMainWindow->getOMCProxy()->getClassNames(pLibraryTreeNode->getNameStructure(), "true");
QStringList libs = mpMainWindow->getOMCProxy()->getClassNames(pLibraryTreeNode->getNameStructure(), true);
if (!libs.isEmpty())
libs.removeFirst();
QList<LibraryTreeNode*> nodes;
Expand Down
84 changes: 15 additions & 69 deletions OMEdit/OMEditGUI/OMC/OMCProxy.cpp
Expand Up @@ -926,42 +926,6 @@ QString OMCProxy::getVersion(QString className)
return mpOMCInterface->getVersion(className);
}

/*!
Gets the OMC annotation version
\return the annotation version
*/
QString OMCProxy::getAnnotationVersion()
{
sendCommand("getAnnotationVersion()");
return getResult();
}

/*!
Sends OMC setEnvironmentVar command.
\param name - the variable name
\param value - the variable value
\return true on success
*/
bool OMCProxy::setEnvironmentVar(QString name, QString value)
{
sendCommand("setEnvironmentVar(\"" + name + "\", \"" + value + "\")");
if (getResult().toLower().contains("ok"))
return true;
else
return false;
}

/*!
Gets OMC getEnvironmentVar command.
\param name - the variable name
\return the environment variable value.
*/
QString OMCProxy::getEnvironmentVar(QString name)
{
sendCommand("getEnvironmentVar(\"" + name + "\")");
return getResult();
}

/*!
Loads the Modelica System Libraries.\n
Reads the omedit.ini file to get the libraries to load.
Expand All @@ -970,30 +934,27 @@ void OMCProxy::loadSystemLibraries(QSplashScreen *pSplashScreen)
{
QSettings *pSettings = OpenModelica::getApplicationSettings();
bool forceModelicaLoad = true;
if (pSettings->contains("forceModelicaLoad"))
if (pSettings->contains("forceModelicaLoad")) {
forceModelicaLoad = pSettings->value("forceModelicaLoad").toBool();
}
pSettings->beginGroup("libraries");
QStringList libraries = pSettings->childKeys();
pSettings->endGroup();
/*
Only force loading of Modelica & ModelicaReference if user is using OMEdit for the first time.
Later user must use the libraries options dialog.
*/
if (forceModelicaLoad)
{
if (!pSettings->contains("libraries/Modelica"))
{
if (forceModelicaLoad) {
if (!pSettings->contains("libraries/Modelica")) {
pSettings->setValue("libraries/Modelica","default");
libraries.prepend("Modelica");
}
if (!pSettings->contains("libraries/ModelicaReference"))
{
if (!pSettings->contains("libraries/ModelicaReference")) {
pSettings->setValue("libraries/ModelicaReference","default");
libraries.prepend("ModelicaReference");
}
}
foreach (QString lib, libraries)
{
foreach (QString lib, libraries) {
pSplashScreen->showMessage(QString(Helper::loading).append(" ").append(lib), Qt::AlignRight, Qt::white);
QString version = pSettings->value("libraries/" + lib).toString();
loadModel(lib, version);
Expand All @@ -1011,13 +972,11 @@ void OMCProxy::loadUserLibraries(QSplashScreen *pSplashScreen)
pSettings->beginGroup("userlibraries");
QStringList libraries = pSettings->childKeys();
pSettings->endGroup();
foreach (QString lib, libraries)
{
foreach (QString lib, libraries) {
QString encoding = pSettings->value("userlibraries/" + lib).toString();
QString fileName = QUrl::fromPercentEncoding(QByteArray(lib.toStdString().c_str()));
pSplashScreen->showMessage(QString(Helper::loading).append(" ").append(fileName), Qt::AlignRight, Qt::white);
if (parseFile(fileName, encoding))
{
if (parseFile(fileName, encoding)) {
QString result = StringHandler::removeFirstLastCurlBrackets(getResult());
QStringList modelsList = result.split(",", QString::SkipEmptyParts);
/*
Expand All @@ -1026,8 +985,7 @@ void OMCProxy::loadUserLibraries(QSplashScreen *pSplashScreen)
"A nonstructured entity [e.g. the file A.mo] shall contain only a stored-definition that defines a class [A] with a name
matching the name of the nonstructured entity."
*/
if (modelsList.size() > 1)
{
if (modelsList.size() > 1) {
QMessageBox *pMessageBox = new QMessageBox(mpMainWindow);
pMessageBox->setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::error));
pMessageBox->setIcon(QMessageBox::Critical);
Expand All @@ -1041,17 +999,14 @@ void OMCProxy::loadUserLibraries(QSplashScreen *pSplashScreen)
QStringList existingmodelsList;
bool existModel = false;
// check if the model already exists
foreach(QString model, modelsList)
{
if (existClass(model))
{
foreach(QString model, modelsList) {
if (existClass(model)) {
existingmodelsList.append(model);
existModel = true;
}
}
// if existModel is true, show user an error message
if (existModel)
{
if (existModel) {
QMessageBox *pMessageBox = new QMessageBox(mpMainWindow);
pMessageBox->setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::information));
pMessageBox->setIcon(QMessageBox::Information);
Expand All @@ -1061,10 +1016,7 @@ void OMCProxy::loadUserLibraries(QSplashScreen *pSplashScreen)
.append(GUIMessages::getMessage(GUIMessages::DELETE_AND_LOAD).arg(encoding)));
pMessageBox->setStandardButtons(QMessageBox::Ok);
pMessageBox->exec();
}
// if no conflicting model found then just load the file simply
else
{
} else { // if no conflicting model found then just load the file simply
loadFile(fileName, encoding);
}
}
Expand All @@ -1079,15 +1031,9 @@ void OMCProxy::loadUserLibraries(QSplashScreen *pSplashScreen)
\param showProtected - returns the protected classes as well.
\return the list of classes
*/
QStringList OMCProxy::getClassNames(QString className, QString recursive, QString qualified, QString showProtected)
QStringList OMCProxy::getClassNames(QString className, bool recursive, bool qualified, bool sort, bool builtin, bool showProtected)
{
if (className.isEmpty())
sendCommand("getClassNames(recursive=" + recursive + ",qualified=" + qualified + ",showProtected=" + showProtected + ")");
else
sendCommand("getClassNames(" + className + ",recursive=" + recursive + ",qualified=" + qualified + ",showProtected=" + showProtected + ")");
QString result = StringHandler::removeFirstLastCurlBrackets(getResult());
QStringList list = result.split(",", QString::SkipEmptyParts);
return list;
return mpOMCInterface->getClassNames(className, recursive, qualified, sort, builtin, showProtected);
}

/*!
Expand Down
7 changes: 2 additions & 5 deletions OMEdit/OMEditGUI/OMC/OMCProxy.h
Expand Up @@ -123,13 +123,10 @@ class OMCProxy : public QObject
QString getErrorLevel();
int getErrorId();
QString getVersion(QString className = QString("OpenModelica"));
QString getAnnotationVersion();
bool setEnvironmentVar(QString name, QString value);
QString getEnvironmentVar(QString name);
void loadSystemLibraries(QSplashScreen *pSplashScreen);
void loadUserLibraries(QSplashScreen *pSplashScreen);
QStringList getClassNames(QString className = QString(), QString recursive = QString("false"), QString qualified = QString("false"),
QString showProtected = QString("true"));
QStringList getClassNames(QString className = QString("AllLoadedClasses"), bool recursive = false, bool qualified = "false",
bool sort = false, bool builtin = false, bool showProtected = "true");
QStringList searchClassNames(QString searchText, QString findInText = QString("false"));
QVariantMap getClassInformation(QString className);
bool isPackage(QString className);
Expand Down

0 comments on commit 4239033

Please sign in to comment.