Skip to content

Commit

Permalink
- Added the Search with Modelica Standard Library
Browse files Browse the repository at this point in the history
- Added very basic export to OMNotebook.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7962 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Feb 18, 2011
1 parent 1b8cfa6 commit 56c487b
Show file tree
Hide file tree
Showing 16 changed files with 534 additions and 61 deletions.
23 changes: 23 additions & 0 deletions OMEdit/INSTALL.txt
@@ -0,0 +1,23 @@
2011-02-16 [adeel.asghar@liu.se]
------------------------------

Windows
------------------------------

OMEdit uses Qt 4.7.0
------------------------------
- Download the Qt SDK for windows from http://qt.nokia.com/downloads. The SDK also contains the Qt Creator.

OmniORB
------------------------------
- OMEdit uses the OmniORB 4.1.4.
- If you have OMDev downloaded then make sure its environment variable is also set. OmniORB is included in OMDev package.
- If you don't have OMDev then download OmniORB from
https://openmodelica.ida.liu.se/svn/OpenModelica/installers/windows/OMDev/lib/omniORB-4.1.4-mingw and set the path in
OMEditGUI.pro file accordingly.
- Load the project in Qt Creator, build and run.
- Copy omniORB414_rt.dll and omniORB414_rtd.dll from /omniORB-4.1.4-mingw/bin/x86_win32 to /location-where-OMEdit.exe-is-created.

------------------------------
Adeel.
adeel.asghar@liu.se
11 changes: 9 additions & 2 deletions OMEdit/OMEditGUI/Helper.cpp
Expand Up @@ -40,8 +40,9 @@ QString Helper::applicationIntroText = "OpenModelica Connection Editor";
QString Helper::OpenModelicaHome = QString();
QString Helper::OpenModelicaLibrary = QString();
QString Helper::omcServerName = "OMEdit";
QString Helper::omFileTypes = "*.mo";
QString Helper::omFileOpenText = "Modelica Files (*.mo)";
QString Helper::omFileTypes = "Modelica Files (*.mo)";
QString Helper::omnotebookFileTypes = "OMNotebook Files (*.onb *.onbz *.nb)";
QString Helper::imageFileTypes = "Image Files (*.png)";
#ifdef WIN32
QString Helper::tmpPath = QString(getenv("OPENMODELICAHOME")).append(QString("/tmp/OMEdit"));
#else
Expand Down Expand Up @@ -69,6 +70,8 @@ QSize Helper::buttonIconSize = QSize(20, 20);
int Helper::headingFontSize = 18;
int Helper::tabWidth = 20;
qreal Helper::shapesStrokeWidth = 5.0;
QString Helper::modelicaLibrarySearchText = QString("Search Modelica Standard Library");
QString Helper::noItemFound = QString("Sorry, no items found");

QString Helper::ModelicaSimulationMethods = "DASSL,DASSL2,Euler,Runge-Kutta";
QString Helper::ModelicaSimulationOutputFormats = "mat,csv,plt,empty";
Expand Down Expand Up @@ -131,6 +134,10 @@ QString GUIMessages::getMessage(int type)
return "The %1 '%2' is contained inside a package. It is automatically saved when you save the package.";
case SEARCH_STRING_NOT_FOUND:
return "The search string '%1' is not found.";
case FILE_REMOVED_MSG:
return "The file '%1' has been removed outside %2. Do you want to keep it?";
case FILE_MODIFIED_MSG:
return "The file '%1' has been modified outside %2. Do you want to reload it?";
default:
return "";
}
Expand Down
9 changes: 7 additions & 2 deletions OMEdit/OMEditGUI/Helper.h
Expand Up @@ -48,7 +48,8 @@ class Helper
static QString OpenModelicaLibrary;
static QString omcServerName;
static QString omFileTypes;
static QString omFileOpenText;
static QString omnotebookFileTypes;
static QString imageFileTypes;
static QString tmpPath;
static QString settingsFileName;
static QString documentationBaseUrl;
Expand All @@ -72,6 +73,8 @@ class Helper
static int headingFontSize;
static int tabWidth;
static qreal shapesStrokeWidth;
static QString modelicaLibrarySearchText;
static QString noItemFound;
};

class GUIMessages
Expand Down Expand Up @@ -105,7 +108,9 @@ class GUIMessages
COMMENT_SAVE_ERROR,
ATTRIBUTES_SAVE_ERROR,
CHILD_MODEL_SAVE,
SEARCH_STRING_NOT_FOUND
SEARCH_STRING_NOT_FOUND,
FILE_REMOVED_MSG,
FILE_MODIFIED_MSG
};

static QString getMessage(int type);
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/IconProperties.cpp
Expand Up @@ -115,6 +115,8 @@ void IconProperties::setUpDialog()
QGridLayout *gridParametersLayout = new QGridLayout;
gridParametersLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);



for (int i = 0 ; i < mpComponent->mpIconParametersList.size() ; i++)
{
IconParameters *iconParameter = mpComponent->mpIconParametersList.at(i);
Expand Down
174 changes: 149 additions & 25 deletions OMEdit/OMEditGUI/LibraryWidget.cpp
Expand Up @@ -45,7 +45,7 @@
#include "LibraryWidget.h"

ModelicaTreeNode::ModelicaTreeNode(QString text, QString parentName, QString tooltip, int type, QTreeWidget *parent)
:QTreeWidgetItem(parent)
: QTreeWidgetItem(parent)
{
mType = type;
mName = text;
Expand Down Expand Up @@ -286,7 +286,7 @@ void ModelicaTree::checkModelicaModel()
widget->show();
}

bool ModelicaTree::deleteNodeTriggered(ModelicaTreeNode *node)
bool ModelicaTree::deleteNodeTriggered(ModelicaTreeNode *node, bool askQuestion)
{
QString msg;
MainWindow *pMainWindow = mpParentLibraryWidget->mpParentMainWindow;
Expand All @@ -306,33 +306,39 @@ bool ModelicaTree::deleteNodeTriggered(ModelicaTreeNode *node)
break;
}

QMessageBox *msgBox = new QMessageBox(pMainWindow);
msgBox->setWindowTitle(QString(Helper::applicationName).append(" - Question"));
msgBox->setIcon(QMessageBox::Question);
msgBox->setText(msg);
msgBox->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox->setDefaultButton(QMessageBox::Yes);
if (askQuestion)
{
QMessageBox *msgBox = new QMessageBox(pMainWindow);
msgBox->setWindowTitle(QString(Helper::applicationName).append(" - Question"));
msgBox->setIcon(QMessageBox::Question);
msgBox->setText(msg);
msgBox->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox->setDefaultButton(QMessageBox::Yes);

int answer = msgBox->exec();
int answer = msgBox->exec();

switch (answer)
{
case QMessageBox::Yes:
// Yes was clicked. Don't return.
break;
case QMessageBox::No:
// No was clicked
return false;
default:
// should never be reached
return false;
switch (answer)
{
case QMessageBox::Yes:
// Yes was clicked. Don't return.
break;
case QMessageBox::No:
// No was clicked
return false;
default:
// should never be reached
return false;
}
}

if (pMainWindow->mpOMCProxy->deleteClass(treeNode->mNameStructure))
{
// print the message before deleting node,
// because after delete node is not available to print message :)
pMainWindow->mpMessageWidget->printGUIInfoMessage("'" + treeNode->mName + "' deleted successfully.");
// because after delete treenode is not available to print message :)
if (askQuestion)
{
pMainWindow->mpMessageWidget->printGUIInfoMessage("'" + treeNode->mName + "' deleted successfully.");
}
deleteNode(treeNode);
if (treeNode->childCount())
qDeleteAll(treeNode->takeChildren());
Expand Down Expand Up @@ -376,6 +382,15 @@ void ModelicaTree::saveChildModels(QString modelName, QString filePath)
saveChildModels(pCurrentTab->mModelNameStructure, filePath);
}
}
// if not found in removed tabs then read the model name form tree
else
{
pMainWindow->mpOMCProxy->setSourceFile(childNode->mNameStructure, filePath);
if (childNode->mType == StringHandler::PACKAGE)
{
saveChildModels(childNode->mNameStructure, filePath);
}
}
}
}
}
Expand Down Expand Up @@ -439,11 +454,13 @@ void LibraryTree::addModelicaStandardLibrary()
if (mpParentLibraryWidget->mpParentMainWindow->mpOMCProxy->isStandardLibraryLoaded())
{
// It should be possible to load multiple libraries in OMEdit...
const int numLib=1;
const char *libs[numLib] = {"Modelica"};
const int numLib=2;
const char *libs[numLib] = {"Modelica", "ModelicaServices"};
for (int i=0; i<numLib; i++) {
LibraryTreeNode *newTreePost = new LibraryTreeNode(QString(libs[i]), QString(""), QString(libs[i]),
(QTreeWidget*)0);
this);
int classType = mpParentLibraryWidget->mpParentMainWindow->mpOMCProxy->getClassRestriction(QString(libs[i]));
newTreePost->mType = classType;
newTreePost->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator);
insertTopLevelItem(0, newTreePost);

Expand Down Expand Up @@ -742,6 +759,113 @@ void LibraryTree::treeItemPressed(QTreeWidgetItem *item)
drag->exec(Qt::CopyAction);
}

MSLSearchBox::MSLSearchBox()
: mDefaultText(Helper::modelicaLibrarySearchText)
{
setText(mDefaultText);
}

void MSLSearchBox::focusInEvent(QFocusEvent *event)
{
Q_UNUSED(event);

if (text().compare(mDefaultText) == 0)
setText(tr(""));
}

void MSLSearchBox::focusOutEvent(QFocusEvent *event)
{
Q_UNUSED(event);

if (text().isEmpty())
{
setText(mDefaultText);
}
}

SearchMSLWidget::SearchMSLWidget(MainWindow *pParent)
: QWidget(pParent)
{
mpParentMainWindow = pParent;

// get MSL recursive
mMSLItemsList = mpParentMainWindow->mpOMCProxy->getClassNamesRecursive(tr("Modelica"));

// create search controls
mpSearchTextBox = new MSLSearchBox;
connect(mpSearchTextBox, SIGNAL(returnPressed()), SLOT(searchMSL()));

mpSearchButton = new QPushButton(tr("Search"));
connect(mpSearchButton, SIGNAL(pressed()), SLOT(searchMSL()));

mpSearchedItemsTree = new LibraryTree(mpParentMainWindow->mpLibrary);
mpSearchedItemsTree->setFrameShape(QFrame::StyledPanel);
mpSearchedItemsTree->setHeaderLabel(tr("Searched Items"));

// add the search controls to layout
QHBoxLayout *horizontalLayout = new QHBoxLayout;
horizontalLayout->addWidget(mpSearchTextBox);
horizontalLayout->addWidget(mpSearchButton);

QVBoxLayout *verticalLayout = new QVBoxLayout;
verticalLayout->setContentsMargins(0, 0, 2, 0);
verticalLayout->addLayout(horizontalLayout);
verticalLayout->addWidget(mpSearchedItemsTree);

setLayout(verticalLayout);
}

void SearchMSLWidget::searchMSL()
{
// Remove the items from search tree
int i = 0;
while(i < mpSearchedItemsTree->topLevelItemCount())
{
qDeleteAll(mpSearchedItemsTree->topLevelItem(i)->takeChildren());
delete mpSearchedItemsTree->topLevelItem(i);
i = 0; //Restart iteration
}

QString foundedItemString;
QStringList foundedItemsList;

foreach (QString item, mMSLItemsList)
{
item = item.trimmed();
// for packages...so that the search don't go inside a package....
if (!foundedItemString.isEmpty())
{
if (item.startsWith(foundedItemString, Qt::CaseInsensitive))
continue;
}
if (item.contains(mpSearchTextBox->text().trimmed(), Qt::CaseInsensitive))
{
foundedItemString = item;
foundedItemsList.append(item);
}
}

// if no item is found
if (foundedItemsList.isEmpty())
{
mpSearchedItemsTree->insertTopLevelItem(0, new QTreeWidgetItem(QStringList(Helper::noItemFound)));
return;
}

foreach (QString foundedItem, foundedItemsList)
{
LibraryTreeNode *newTreePost = new LibraryTreeNode(foundedItem, QString(""), foundedItem, mpSearchedItemsTree);
newTreePost->mType = mpParentMainWindow->mpOMCProxy->getClassRestriction(foundedItem);
mpSearchedItemsTree->insertTopLevelItem(0, newTreePost);

// get the Icon for Modelica tree node
LibraryLoader *libraryLoader = new LibraryLoader(newTreePost, foundedItem, mpSearchedItemsTree);
libraryLoader->start(QThread::HighestPriority);
while (libraryLoader->isRunning())
qApp->processEvents();
}
}

//! Constructor.
//! @param parent defines a parent to the new instanced object.
LibraryWidget::LibraryWidget(MainWindow *parent)
Expand Down
35 changes: 31 additions & 4 deletions OMEdit/OMEditGUI/LibraryWidget.h
Expand Up @@ -97,7 +97,7 @@ public slots:
void showContextMenu(QPoint point);
void renameClass();
void checkModelicaModel();
bool deleteNodeTriggered(ModelicaTreeNode *node = 0);
bool deleteNodeTriggered(ModelicaTreeNode *node = 0, bool askQuestion = true);
void saveChildModels(QString modelName, QString filePath);
};

Expand Down Expand Up @@ -142,10 +142,37 @@ private slots:
void showComponent();
void viewDocumentation();
void checkLibraryModel();
void loadingLibraryComponent(LibraryTreeNode *treeNode, QString className);
void treeItemPressed(QTreeWidgetItem *item);
//protected:
// virtual void mousePressEvent(QMouseEvent *event);
public slots:
void loadingLibraryComponent(LibraryTreeNode *treeNode, QString className);
};

class MSLSearchBox : public QLineEdit
{
public:
MSLSearchBox();

QString mDefaultText;
protected:
virtual void focusInEvent(QFocusEvent *event);
virtual void focusOutEvent(QFocusEvent *event);
};

class SearchMSLWidget : public QWidget
{
Q_OBJECT
public:
SearchMSLWidget(MainWindow *pParent = 0);

MainWindow *mpParentMainWindow;
private:
MSLSearchBox *mpSearchTextBox;
QPushButton *mpSearchButton;
LibraryTree *mpSearchedItemsTree;
QStringList mMSLItemsList;

public slots:
void searchMSL();
};

class LibraryWidget : public QWidget
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/ModelicaEditor.cpp
Expand Up @@ -43,7 +43,7 @@ ModelicaEditor::ModelicaEditor(ProjectTab *pParent)
setObjectName(tr("ModelicaEditor"));
// depending on the project tab readonly state set the text view readonly state
setReadOnly(mpParentProjectTab->isReadOnly());
connect(this, SIGNAL(focusOut()), mpParentProjectTab, SLOT(ModelicaEditorTextChanged()));
connect(this, SIGNAL(focusOut()), mpParentProjectTab, SLOT(modelicaEditorTextChanged()));

mpFindWidget = new QWidget;
mpFindWidget->setContentsMargins(0, 0, 0, 0);
Expand Down

0 comments on commit 56c487b

Please sign in to comment.