Skip to content

Commit

Permalink
- Directly use the getClassInformaiton struct generated by OpenModeli…
Browse files Browse the repository at this point in the history
…ca scripting API.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25290 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Mar 27, 2015
1 parent 8395c45 commit f315596
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 304 deletions.
6 changes: 3 additions & 3 deletions OMEdit/OMEditGUI/Editors/FindReplaceDialog.cpp
Expand Up @@ -149,7 +149,7 @@ void FindReplaceDialog::readFindTextFromSettings()
int numFindTexts = qMin(findTexts.size(), (int)MaxFindTexts);
for (int i = 0; i < numFindTexts; ++i)
{
FindText findText = qvariant_cast<FindText>(findTexts[i]);
FindTextOM findText = qvariant_cast<FindTextOM>(findTexts[i]);
mpFindComboBox->addItem(findText.text);
}
}
Expand All @@ -165,11 +165,11 @@ void FindReplaceDialog::saveFindTextToSettings(QString textToFind)
// remove the already present text from the list.
foreach (QVariant text, texts)
{
FindText findText = qvariant_cast<FindText>(text);
FindTextOM findText = qvariant_cast<FindTextOM>(text);
if (findText.text.compare(textToFind) == 0)
texts.removeOne(text);
}
FindText findText;
FindTextOM findText;
findText.text = textToFind;
texts.prepend(QVariant::fromValue(findText));
while (texts.size() > MaxFindTexts)
Expand Down
6 changes: 3 additions & 3 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -54,13 +54,13 @@ MainWindow::MainWindow(QSplashScreen *pSplashScreen, QWidget *parent)
QFont monospaceFont("Monospace");
monospaceFont.setStyleHint(QFont::TypeWriter);
Helper::monospacedFontInfo = QFontInfo(monospaceFont);
/*! @note Register the RecentFile, FindText and DebuggerConfiguration struct in the Qt's meta system
/*! @note Register the RecentFile, FindTextOM and DebuggerConfiguration struct in the Qt's meta system
* Don't remove/move the following lines.
* Because RecentFile, FindText and DebuggerConfiguration structs should be registered before reading the recentFilesList, FindText and
* Because RecentFile, FindTextOM and DebuggerConfiguration structs should be registered before reading the recentFilesList, FindTextOM and
DebuggerConfiguration section respectively from the settings file.
*/
qRegisterMetaTypeStreamOperators<RecentFile>("RecentFile");
qRegisterMetaTypeStreamOperators<FindText>("FindText");
qRegisterMetaTypeStreamOperators<FindTextOM>("FindTextOM");
qRegisterMetaTypeStreamOperators<DebuggerConfiguration>("DebuggerConfiguration");
/*! @note The above three lines registers the structs as QMetaObjects. Do not remove/move them. */
setObjectName("MainWindow");
Expand Down
315 changes: 103 additions & 212 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp

Large diffs are not rendered by default.

72 changes: 35 additions & 37 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h
Expand Up @@ -101,54 +101,53 @@ class LibraryTreeNode : public QTreeWidgetItem
SaveFolderStructure,
SaveUnspecified
};
LibraryTreeNode(LibraryType type, QString text, QString parentName, QString nameStructure, QString tooltip,
StringHandler::ModelicaClasses modelicaType, QString fileName, bool readOnly, bool isSaved, bool isProtected,
LibraryTreeWidget *pParent);
QIcon getModelicaNodeIcon();
LibraryTreeNode(LibraryType type, QString text, QString parentName, QString nameStructure,
OMCInterface::getClassInformation_res classInformation, QString fileName, bool isSaved, LibraryTreeWidget *pParent);
LibraryType getLibraryType() {return mLibraryType;}
void setLibraryType(LibraryType libraryType) {mLibraryType = libraryType;}
void setModelicaType(StringHandler::ModelicaClasses type);
StringHandler::ModelicaClasses getModelicaType();
void setName(QString name);
const QString& getName() const;
void setParentName(QString parentName);
const QString& getParentName();
void setNameStructure(QString nameStructure);
const QString& getNameStructure();
void setSystemLibrary(bool systemLibrary) {mSystemLibrary = systemLibrary;}
bool isSystemLibrary() {return mSystemLibrary;}
void setModelWidget(ModelWidget *pModelWidget) {mpModelWidget = pModelWidget;}
ModelWidget* getModelWidget() {return mpModelWidget;}
void setName(QString name) {mName = name;}
const QString& getName() const {return mName;}
void setParentName(QString parentName) {mParentName = parentName;}
const QString& getParentName() {return mParentName;}
void setNameStructure(QString nameStructure) {mNameStructure = nameStructure;}
const QString& getNameStructure() {return mNameStructure;}
void setClassInformation(OMCInterface::getClassInformation_res classInformation);
OMCInterface::getClassInformation_res getClassInformation() {return mClassInformation;}
void setFileName(QString fileName);
const QString& getFileName();
void setReadOnly(bool readOnly);
bool isReadOnly();
void setSystemLibrary(bool systemLibrary);
bool isSystemLibrary();
void setIsSaved(bool isSaved);
bool isSaved();
void setIsProtected(bool isProtected);
bool isProtected();
void setIsPartial(bool isPartial) {mIsPartial = isPartial;}
bool isPartial() {return mIsPartial;}
void setSaveContentsType(LibraryTreeNode::SaveContentsType saveContentsType);
SaveContentsType getSaveContentsType();
void setIsDocumentationClass(bool documentationClass);
bool isDocumentationClass();
void setModelWidget(ModelWidget *pModelWidget);
ModelWidget* getModelWidget();
const QString& getFileName() {return mFileName;}
void setReadOnly(bool readOnly) {mReadOnly = readOnly;}
bool isReadOnly() {return mReadOnly;}
void setIsSaved(bool isSaved) {mIsSaved = isSaved;}
bool isSaved() {return mIsSaved;}
void setIsProtected(bool isProtected) {mIsProtected = isProtected;}
bool isProtected() {return mIsProtected;}
void setIsDocumentationClass(bool documentationClass) {mDocumentationClass = documentationClass;}
bool isDocumentationClass() {return mDocumentationClass;}
void setSaveContentsType(LibraryTreeNode::SaveContentsType saveContentsType) {mSaveContentsType = saveContentsType;}
StringHandler::ModelicaClasses getRestriction() {return StringHandler::getModelicaClassType(mClassInformation.restriction);}
bool isPartial() {return mClassInformation.partialPrefix;}
SaveContentsType getSaveContentsType() {return mSaveContentsType;}
void updateAttributes();
QIcon getModelicaNodeIcon();
private:
LibraryTreeWidget *mpLibraryTreeWidget;
LibraryType mLibraryType;
StringHandler::ModelicaClasses mModelicaType;
bool mSystemLibrary;
ModelWidget *mpModelWidget;
LibraryTreeWidget *mpLibraryTreeWidget;
QString mName;
QString mParentName;
QString mNameStructure;
OMCInterface::getClassInformation_res mClassInformation;
QString mFileName;
bool mReadOnly;
bool mSystemLibrary;
bool mIsSaved;
bool mIsProtected;
SaveContentsType mSaveContentsType;
bool mDocumentationClass;
bool mIsPartial;
ModelWidget *mpModelWidget;
SaveContentsType mSaveContentsType;
};

class LibraryTreeWidget : public QTreeWidget
Expand All @@ -170,8 +169,7 @@ class LibraryTreeWidget : public QTreeWidget
void addLibraryTreeNodes(QList<LibraryTreeNode*> libraryTreeNodes);
bool isLibraryTreeNodeExpanded(QTreeWidgetItem *item);
static bool sortNodesAscending(const LibraryTreeNode *node1, const LibraryTreeNode *node2);
LibraryTreeNode* addLibraryTreeNode(QString name, StringHandler::ModelicaClasses type, QString parentName=QString(),
bool isSaved = true, int insertIndex = 0);
LibraryTreeNode* addLibraryTreeNode(QString name, QString parentName = QString(""), bool isSaved = true, int insertIndex = 0);
LibraryTreeNode* addLibraryTreeNode(QString name, bool isSaved, int insertIndex = 0);
LibraryTreeNode* getLibraryTreeNode(QString nameStructure, Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive);
QList<LibraryTreeNode*> getLibraryTreeNodesList();
Expand Down
18 changes: 8 additions & 10 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -382,7 +382,7 @@ bool GraphicsView::addComponent(QString className, QPointF position)
if (!pLibraryTreeNode) {
return false;
}
StringHandler::ModelicaClasses type = pLibraryTreeNode->getModelicaType();
StringHandler::ModelicaClasses type = pLibraryTreeNode->getRestriction();
QString name = pLibraryTreeNode->getName();
OptionsDialog *pOptionsDialog = mpModelWidget->getModelWidgetContainer()->getMainWindow()->getOptionsDialog();
// item not to be dropped on itself; if dropping an item on itself
Expand Down Expand Up @@ -1974,7 +1974,7 @@ ModelWidget::ModelWidget(LibraryTreeNode* pLibraryTreeNode, ModelWidgetContainer
pViewButtonsHorizontalLayout->addWidget(mpDiagramViewToolButton);
pViewButtonsHorizontalLayout->addWidget(mpTextViewToolButton);
pViewButtonsHorizontalLayout->addWidget(mpDocumentationViewToolButton);
mpModelicaTypeLabel->setText(StringHandler::getModelicaClassType(pLibraryTreeNode->getModelicaType()));
mpModelicaTypeLabel->setText(StringHandler::getModelicaClassType(pLibraryTreeNode->getRestriction()));
mpViewTypeLabel->setText(StringHandler::getViewType(StringHandler::Diagram));
// icon graphics framework
mpIconGraphicsScene = new GraphicsScene(StringHandler::Icon, this);
Expand Down Expand Up @@ -2289,8 +2289,9 @@ void ModelWidget::getModelIconDiagramShapes(QString className, QString annotatio
{
/* get the class file path */
QString classFileName;
QVariantMap classInformation = mpModelWidgetContainer->getMainWindow()->getOMCProxy()->getClassInformation(className);
classFileName = classInformation["fileName"].toString();
OMCInterface::getClassInformation_res classInformation;
classInformation = mpModelWidgetContainer->getMainWindow()->getOMCProxy()->getClassInformation(className);
classFileName = classInformation.fileName;
/* create the bitmap shape */
shape = shape.mid(QString("Bitmap").length());
shape = StringHandler::removeFirstLastBrackets(shape);
Expand Down Expand Up @@ -2440,13 +2441,10 @@ void ModelWidget::refresh()
pOMCProxy->removeCachedOMCCommand(mpLibraryTreeNode->getNameStructure());
/* set the LibraryTreeNode filename, type & tooltip */
pOMCProxy->setSourceFile(mpLibraryTreeNode->getNameStructure(), mpLibraryTreeNode->getFileName());
QVariantMap info = pOMCProxy->getClassInformation(mpLibraryTreeNode->getNameStructure());
StringHandler::ModelicaClasses type = info.find("restriction") == info.end() ? pOMCProxy->getClassRestriction(mpLibraryTreeNode->getNameStructure()) : StringHandler::getModelicaClassType(info["restriction"].toString());
mpLibraryTreeNode->setModelicaType(type);
mpLibraryTreeNode->setToolTip(0, StringHandler::createTooltip(info, mpLibraryTreeNode->getName(), mpLibraryTreeNode->getNameStructure()));
/* set the LibraryTreeNode icon */
mpLibraryTreeNode->setClassInformation(pOMCProxy->getClassInformation(mpLibraryTreeNode->getNameStructure()));
bool isDocumentationClass = mpModelWidgetContainer->getMainWindow()->getOMCProxy()->getDocumentationClassAnnotation(mpLibraryTreeNode->getNameStructure());
mpLibraryTreeNode->setIsDocumentationClass(isDocumentationClass);
mpLibraryTreeNode->updateAttributes();
mpModelWidgetContainer->getMainWindow()->getLibraryTreeWidget()->loadLibraryComponent(mpLibraryTreeNode);
/* remove everything from the icon view */
mpIconGraphicsView->removeAllComponents();
Expand Down Expand Up @@ -2698,7 +2696,7 @@ bool ModelWidget::modelicaEditorTextChanged()
if (modelName.compare(parentName) == 0)
parentName = "";
LibraryTreeNode *pLibraryTreeNode;
pLibraryTreeNode = pLibraryTreeWidget->addLibraryTreeNode(modelName, pOMCProxy->getClassRestriction(modelName), parentName, false);
pLibraryTreeNode = pLibraryTreeWidget->addLibraryTreeNode(modelName, parentName, false);
pLibraryTreeWidget->createLibraryTreeNodes(pLibraryTreeNode);
}
return true;
Expand Down
16 changes: 6 additions & 10 deletions OMEdit/OMEditGUI/Modeling/ModelicaClassDialog.cpp
Expand Up @@ -406,9 +406,7 @@ void ModelicaClassDialog::createModelicaClass()
}
//open the new tab in central widget and add the model to library tree.
LibraryTreeNode *pLibraryTreeNode;
pLibraryTreeNode = pLibraryTreeWidget->addLibraryTreeNode(mpNameTextBox->text().trimmed(),
StringHandler::getModelicaClassType(mpSpecializationComboBox->currentText()),
mpParentClassTextBox->text().trimmed(), false);
pLibraryTreeNode = pLibraryTreeWidget->addLibraryTreeNode(mpNameTextBox->text().trimmed(), mpParentClassTextBox->text().trimmed(), false);
pLibraryTreeNode->setSaveContentsType(mpSaveContentsInOneFileCheckBox->isChecked() ? LibraryTreeNode::SaveInOneFile : LibraryTreeNode::SaveFolderStructure);
pLibraryTreeWidget->addToExpandedLibraryTreeNodesList(pLibraryTreeNode);
pLibraryTreeWidget->showModelWidget(pLibraryTreeNode, true, !mpExtendsClassTextBox->text().isEmpty());
Expand Down Expand Up @@ -643,7 +641,7 @@ SaveAsClassDialog::SaveAsClassDialog(ModelWidget *pModelWidget, MainWindow *pPar
// create save contents of package in one file checkbox
mpSaveContentsInOneFileCheckBox = new QCheckBox(tr("Save contents in one file"));
mpSaveContentsInOneFileCheckBox->setChecked(true);
if (pModelWidget->getLibraryTreeNode()->getModelicaType() == StringHandler::Package && mpParentClassComboBox->currentText().isEmpty())
if (pModelWidget->getLibraryTreeNode()->getRestriction() == StringHandler::Package && mpParentClassComboBox->currentText().isEmpty())
mpSaveContentsInOneFileCheckBox->setVisible(true);
else
mpSaveContentsInOneFileCheckBox->setVisible(false);
Expand Down Expand Up @@ -681,7 +679,7 @@ QComboBox* SaveAsClassDialog::getParentClassComboBox()
*/
void SaveAsClassDialog::saveAsModelicaClass()
{
QString type = StringHandler::getModelicaClassType(mpModelWidget->getLibraryTreeNode()->getModelicaType());
QString type = StringHandler::getModelicaClassType(mpModelWidget->getLibraryTreeNode()->getRestriction());
if (mpNameTextBox->text().isEmpty())
{
QMessageBox::critical(this, QString(Helper::applicationName).append(" - ").append(Helper::error), GUIMessages::getMessage(
Expand Down Expand Up @@ -753,8 +751,7 @@ void SaveAsClassDialog::saveAsModelicaClass()
}
//open the new tab in central widget and add the model to library tree.
LibraryTreeNode *pLibraryTreeNode;
pLibraryTreeNode = pLibraryTreeWidget->addLibraryTreeNode(mpNameTextBox->text(), mpModelWidget->getLibraryTreeNode()->getModelicaType(),
mpParentClassComboBox->currentText(), false);
pLibraryTreeNode = pLibraryTreeWidget->addLibraryTreeNode(mpNameTextBox->text(), mpParentClassComboBox->currentText(), false);
pLibraryTreeNode->setSaveContentsType(mpSaveContentsInOneFileCheckBox->isChecked() ? LibraryTreeNode::SaveInOneFile : LibraryTreeNode::SaveFolderStructure);
pLibraryTreeWidget->addToExpandedLibraryTreeNodesList(pLibraryTreeNode);
pLibraryTreeWidget->showModelWidget(pLibraryTreeNode);
Expand All @@ -763,7 +760,7 @@ void SaveAsClassDialog::saveAsModelicaClass()

void SaveAsClassDialog::showHideSaveContentsInOneFileCheckBox(QString text)
{
if (text.isEmpty() && mpModelWidget->getLibraryTreeNode()->getModelicaType() == StringHandler::Package)
if (text.isEmpty() && mpModelWidget->getLibraryTreeNode()->getRestriction() == StringHandler::Package)
mpSaveContentsInOneFileCheckBox->setVisible(true);
else
mpSaveContentsInOneFileCheckBox->setVisible(false);
Expand Down Expand Up @@ -851,8 +848,7 @@ void CopyClassDialog::copyClass()
LibraryTreeWidget *pLibraryTreeWidget = mpMainWindow->getLibraryTreeWidget();
LibraryTreeNode *pLibraryTreeNode;
QString className = mpNameTextBox->text().trimmed();
pLibraryTreeNode = pLibraryTreeWidget->addLibraryTreeNode(className, mpMainWindow->getOMCProxy()->getClassRestriction(className),
mpPathTextBox->text().trimmed(), false);
pLibraryTreeNode = pLibraryTreeWidget->addLibraryTreeNode(className, mpPathTextBox->text().trimmed(), false);
pLibraryTreeNode->setSaveContentsType(mpLibraryTreeNode->getSaveContentsType());
pLibraryTreeWidget->addToExpandedLibraryTreeNodesList(pLibraryTreeNode);
}
Expand Down
27 changes: 4 additions & 23 deletions OMEdit/OMEditGUI/OMC/OMCProxy.cpp
Expand Up @@ -51,8 +51,6 @@ void* omc_Main_init(void *threadData, void *args);
void* omc_Main_readSettings(void *threadData, void *args);
}

#include "OpenModelicaScriptingAPIQt.h"

#include <stdexcept>
#include <stdlib.h>
#include <iostream>
Expand Down Expand Up @@ -846,33 +844,16 @@ QStringList OMCProxy::searchClassNames(QString searchText, bool findInText)
\param className - is the name of the class whose information is retrieved.
\return the class information list.
*/
QVariantMap OMCProxy::getClassInformation(QString className)
OMCInterface::getClassInformation_res OMCProxy::getClassInformation(QString className)
{
QVariantMap result;
OMCInterface::getClassInformation_res classInformation;
try {
OMCInterface::getClassInformation_res classInformation = mpOMCInterface->getClassInformation(className);
result["restriction"] = classInformation.restriction;
result["comment"] = classInformation.comment;
result["partialPrefix"] = classInformation.partialPrefix;
result["finalPrefix"] = classInformation.finalPrefix;
result["encapsulatedPrefix"] = classInformation.encapsulatedPrefix;
/*
Since now we set the fileName via loadString() & parseString() so this API might return us className/<interactive>.
We only set the fileName field if returned value is really a file path.
*/
result["fileName"] = classInformation.fileName.endsWith(".mo") ? classInformation.fileName : "";
result["fileReadOnly"] = classInformation.fileReadOnly;
result["lineNumberStart"] = (long long) classInformation.lineNumberStart;
result["columnNumberStart"] = (long long) classInformation.columnNumberStart;
result["lineNumberEnd"] = (long long) classInformation.lineNumberEnd;
result["columnNumberEnd"] = (long long) classInformation.columnNumberEnd;
result["dimensions"] = "";
//res["dimensions"] = classInformation.dimensions;
classInformation = mpOMCInterface->getClassInformation(className);
} catch (std::exception &exception) {
showException(exception);
printMessagesStringInternal();
}
return result;
return classInformation;
}

/*!
Expand Down
3 changes: 2 additions & 1 deletion OMEdit/OMEditGUI/OMC/OMCProxy.h
Expand Up @@ -39,6 +39,7 @@
#ifndef OMCPROXY_H
#define OMCPROXY_H

#include "OpenModelicaScriptingAPIQt.h"
#include "MainWindow.h"
#include "Component.h"
#include "StringHandler.h"
Expand Down Expand Up @@ -114,7 +115,7 @@ class OMCProxy : public QObject
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, bool findInText = "false");
QVariantMap getClassInformation(QString className);
OMCInterface::getClassInformation_res getClassInformation(QString className);
bool isPackage(QString className);
bool isBuiltinType(QString typeName);
QString getBuiltinType(QString typeName);
Expand Down
10 changes: 5 additions & 5 deletions OMEdit/OMEditGUI/Util/Utilities.h
Expand Up @@ -164,29 +164,29 @@ inline QDataStream& operator>>(QDataStream& in, RecentFile& recentFile)
return in;
}

//! @struct FindText
//! @struct FindTextOM
/*! \brief It contains the recently searched text from find/replace dialog .
* We must register this struct as a meta type since we need to use it as a QVariant.
* This is used to store the recent texts information in omedit.ini file.
* The QDataStream also needed to be defined for this struct.
*/
struct FindText
struct FindTextOM
{
QString text;
operator QVariant() const
{
return QVariant::fromValue(*this);
}
};
Q_DECLARE_METATYPE(FindText)
Q_DECLARE_METATYPE(FindTextOM)

inline QDataStream& operator<<(QDataStream& out, const FindText& findText)
inline QDataStream& operator<<(QDataStream& out, const FindTextOM& findText)
{
out << findText.text;
return out;
}

inline QDataStream& operator>>(QDataStream& in, FindText& findText)
inline QDataStream& operator>>(QDataStream& in, FindTextOM& findText)
{
in >> findText.text;
return in;
Expand Down

0 comments on commit f315596

Please sign in to comment.