Skip to content

Commit

Permalink
Updated the tmp directory path in simulation and Plot Widget.
Browse files Browse the repository at this point in the history
Updated the Splash Screen text.
Added the contextmenu to tree.
Added the resources file.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6463 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Oct 19, 2010
1 parent 60bf026 commit 9e6843f
Show file tree
Hide file tree
Showing 24 changed files with 988 additions and 674 deletions.
6 changes: 5 additions & 1 deletion OMEdit/OMEditGUI/Helper.cpp
Expand Up @@ -35,7 +35,7 @@

QString Helper::applicationName = "OMEdit";
QString Helper::applicationVersion = "0.0.1";
QString Helper::applicationIntroText = "Open Modelica Graphical Editor";
QString Helper::applicationIntroText = "Open Modelica Connection Editor";
QString Helper::omcServerName = "OMEditor";
QString Helper::omFileTypes = "*.mo";
QString Helper::omFileOpenText = "Modelica Files (*.mo)";
Expand Down Expand Up @@ -72,4 +72,8 @@ QString GUIMessages::getMessage(int type)
return "Incompatible types for the connectors.";
else if (type == SAVE_CHANGES)
return "Do you want to save your changes before closing?";
else if (type == DELETE_FAIL)
return "Unable to delete. Server error has occurred while trying to delete.";
else if (type == ONLY_MODEL_ALLOWED)
return "This item is not a model.";
}
4 changes: 3 additions & 1 deletion OMEdit/OMEditGUI/Helper.h
Expand Up @@ -67,7 +67,9 @@ class GUIMessages
ERROR_OCCURRED,
NO_OPEN_MODELICA_KEYWORDS,
INCOMPATIBLE_CONNECTORS,
SAVE_CHANGES
SAVE_CHANGES,
DELETE_FAIL,
ONLY_MODEL_ALLOWED
};

static QString getMessage(int type);
Expand Down
1,185 changes: 596 additions & 589 deletions OMEdit/OMEditGUI/IconAnnotation.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/IconAnnotation.h
Expand Up @@ -77,6 +77,7 @@ class IconAnnotation : public ShapeAnnotation
QAction *mpIconPropertiesAction;

void createActions();
void getAnnotationString();
public:
IconAnnotation(QString value, QString name, QString className, QPointF position, OMCProxy *omc,
GraphicsScene *graphicsScene, GraphicsView *graphicsView);
Expand Down
88 changes: 87 additions & 1 deletion OMEdit/OMEditGUI/LibraryWidget.cpp
Expand Up @@ -56,21 +56,27 @@ LibraryWidget::LibraryWidget(MainWindow *parent)
mpTree->setIndentation(13);
mpTree->setDragEnabled(true);
mpTree->setIconSize(QSize(20, 20));
mpTree->setColumnCount(1);

mpProjectsTree = new QTreeWidget(this);
mpProjectsTree->setHeaderLabel(tr("Modelica Files"));
mpProjectsTree->setColumnCount(1);
mpProjectsTree->setIndentation(13);
mpTree->setColumnCount(1);
mpProjectsTree->setContextMenuPolicy(Qt::CustomContextMenu);

mpGrid = new QVBoxLayout(this);
mpGrid->setContentsMargins(0, 0, 0, 0);
mpGrid->addWidget(mpTree);
mpGrid->addWidget(mpProjectsTree);

setLayout(mpGrid);

createActions();

connect(mpTree, SIGNAL(itemClicked(QTreeWidgetItem*,int)), SLOT(showLib(QTreeWidgetItem*)));
connect(mpTree, SIGNAL(itemExpanded(QTreeWidgetItem*)), SLOT(showLib(QTreeWidgetItem*)));
connect(mpProjectsTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), SLOT(openProjectTab(QTreeWidgetItem*,int)));
connect(mpProjectsTree, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showContextMenu(QPoint)));
}

//! Let the user add the OM Standard Library to library widget.
Expand Down Expand Up @@ -303,3 +309,83 @@ IconAnnotation* LibraryWidget::getGlobalIconObject(QString className)
}
return NULL;
}

void LibraryWidget::updateNodeText(QString text, QString textStructure)
{
mSelectedItem->setText(0, text);
mSelectedItem->setToolTip(0, textStructure);
}

void LibraryWidget::createActions()
{
mRenameAction = new QAction(QIcon(":/Resources/icons/rename.png"), tr("Rename"), this);
connect(mRenameAction, SIGNAL(triggered()), SLOT(renameClass()));

mCheckModelAction = new QAction(QIcon(":/Resources/icons/check.png"), tr("Check"), this);
connect(mCheckModelAction, SIGNAL(triggered()), SLOT(checkClass()));

mDeleteAction = new QAction(QIcon(":/Resources/icons/delete.png"), tr("Delete"), this);
connect(mDeleteAction, SIGNAL(triggered()), SLOT(deleteClass()));
}

void LibraryWidget::openProjectTab(QTreeWidgetItem *item, int column)
{
bool isFound = false;
// if the clicked item is model
if (mpParentMainWindow->mpOMCProxy->isWhat(StringHandler::MODEL, item->toolTip(column)))
{
ProjectTab *pCurrentTab = mpParentMainWindow->mpProjectTabs->getTabByName(item->toolTip(column));
if (pCurrentTab)
{
mpParentMainWindow->mpProjectTabs->setCurrentWidget(pCurrentTab);
isFound = true;

}
// if the tab is closed by user then reopen it and set is current tab
if (!isFound)
{
//! @todo make it better load the model here and get the components required.
mpParentMainWindow->mpProjectTabs->addProjectTab(new ProjectTab(mpParentMainWindow->mpProjectTabs),
"model1234");
}
}
else
{
mpParentMainWindow->mpMessageWidget->printGUIInfoMessage(GUIMessages::getMessage(GUIMessages::ONLY_MODEL_ALLOWED));
}
}

void LibraryWidget::showContextMenu(QPoint point)
{
int adjust = 24;
QTreeWidgetItem *item = 0;
item = mpProjectsTree->itemAt(point);

if (item)
{
mSelectedItem = item;
QMenu menu(this);
menu.addAction(mRenameAction);
menu.addAction(mCheckModelAction);
menu.addAction(mDeleteAction);
point.setY(point.y() + adjust);
menu.exec(mpProjectsTree->mapToGlobal(point));
}
}

void LibraryWidget::renameClass()
{
RenameClassWidget *renameWidget = new RenameClassWidget(mSelectedItem->text(0), mSelectedItem->toolTip(0),
mpParentMainWindow);
renameWidget->show();
}

void LibraryWidget::checkClass()
{

}

void LibraryWidget::deleteClass()
{

}
13 changes: 13 additions & 0 deletions OMEdit/OMEditGUI/LibraryWidget.h
Expand Up @@ -75,15 +75,28 @@ class LibraryWidget : public QWidget
bool isTreeItemLoaded(QTreeWidgetItem *item);
void addGlobalIconObject(IconAnnotation* icon);
IconAnnotation* getGlobalIconObject(QString className);
void updateNodeText(QString text, QString textStructure);
void createActions();

QTreeWidgetItem *mSelectedItem;
private slots:
void showLib(QTreeWidgetItem *item);
void openProjectTab(QTreeWidgetItem *item, int column);
void showContextMenu(QPoint point);
void renameClass();
void checkClass();
void deleteClass();
private:
//Member variables
MainWindow *mpParentMainWindow;
QTreeWidget *mpTree;
QVBoxLayout *mpGrid;
QList<QString> mTreeList;
QList<IconAnnotation*> mGlobalIconsList;

QAction *mRenameAction;
QAction *mCheckModelAction;
QAction *mDeleteAction;
};

#endif // LIBRARYWIDGET_H
68 changes: 68 additions & 0 deletions OMEdit/OMEditGUI/ModelWidget.cpp
Expand Up @@ -383,3 +383,71 @@ void NewModel::createModel()
this->mpParentMainWindow->mpProjectTabs->addNewProjectTab(this->mpModelNameTextBox->text(), modelStructure);
this->accept();
}

RenameClassWidget::RenameClassWidget(QString name, QString nameStructure, MainWindow *parent)
: QDialog(parent, Qt::WindowTitleHint), mName(name), mNameStructure(nameStructure)
{
setAttribute(Qt::WA_DeleteOnClose);
mpParentMainWindow = parent;

this->setWindowTitle(QString(Helper::applicationName).append(" - Rename ").append(name));
this->setMaximumSize(300, 100);
this->setMinimumSize(300, 100);
this->setModal(true);

this->mpModelNameTextBox = new QLineEdit(name);
this->mpModelNameLabel = new QLabel(tr("New Name:"));
// Create the buttons
this->mpOkButton = new QPushButton(tr("Rename"));
this->mpOkButton->setAutoDefault(true);
connect(this->mpOkButton, SIGNAL(pressed()), this, SLOT(renameClass()));
this->mpCancelButton = new QPushButton(tr("&Cancel"));
this->mpCancelButton->setAutoDefault(false);
connect(this->mpCancelButton, SIGNAL(pressed()), this, SLOT(reject()));

this->mpButtonBox = new QDialogButtonBox(Qt::Horizontal);
this->mpButtonBox->addButton(this->mpOkButton, QDialogButtonBox::ActionRole);
this->mpButtonBox->addButton(this->mpCancelButton, QDialogButtonBox::ActionRole);

// Create a layout
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(this->mpModelNameLabel, 0, 0);
mainLayout->addWidget(this->mpModelNameTextBox, 1, 0);
mainLayout->addWidget(this->mpButtonBox, 2, 0);

setLayout(mainLayout);
}

RenameClassWidget::~RenameClassWidget()
{

}

void RenameClassWidget::renameClass()
{
QString newName = mpModelNameTextBox->text().trimmed();
QString newNameStructure;
if (mpParentMainWindow->mpOMCProxy->renameClass(mNameStructure, newName))
{
// Find the Tab and rename it to new Name
newNameStructure = StringHandler::removeFirstLastCurlBrackets(mpParentMainWindow->mpOMCProxy->getResult());
ProjectTab *pCurrentTab = mpParentMainWindow->mpProjectTabs->getTabByName(mNameStructure);
if (pCurrentTab)
{
pCurrentTab->updateTabName(newName, newNameStructure);
}
// Change the name in tree as well
mpParentMainWindow->mpLibrary->updateNodeText(newName, newNameStructure);
mpParentMainWindow->mpMessageWidget->printGUIInfoMessage("Renamed '"+mName+"' to '"+mpModelNameTextBox->text().trimmed()+"'");
accept();
}
else
{
QMessageBox::critical(this, Helper::applicationName + " - Error",
GUIMessages::getMessage(GUIMessages::ERROR_OCCURRED) +
"\n\n" + mpParentMainWindow->mpOMCProxy->getResult() +
"\n\n" + GUIMessages::getMessage(GUIMessages::NO_OPEN_MODELICA_KEYWORDS),
tr("OK"));
return;
}
}
20 changes: 20 additions & 0 deletions OMEdit/OMEditGUI/ModelWidget.h
Expand Up @@ -107,4 +107,24 @@ public slots:
void createModel();
};

class RenameClassWidget : public QDialog
{
Q_OBJECT
public:
RenameClassWidget(QString name, QString nameStructure, MainWindow *parent = 0);
~RenameClassWidget();

MainWindow *mpParentMainWindow;
private:
QString mName;
QString mNameStructure;
QLabel *mpModelNameLabel;
QLineEdit *mpModelNameTextBox;
QPushButton *mpCancelButton;
QPushButton *mpOkButton;
QDialogButtonBox *mpButtonBox;
public slots:
void renameClass();
};

#endif // MODELWIDGET_H
20 changes: 19 additions & 1 deletion OMEdit/OMEditGUI/OMCProxy.cpp
Expand Up @@ -61,7 +61,7 @@ OMCProxy::OMCProxy(MainWindow *pParent)
this->mpOMCLogger->setWindowFlags(Qt::WindowTitleHint);
this->mpOMCLogger->setMaximumSize(640, 480);
this->mpOMCLogger->setMinimumSize(640, 480);
this->mpOMCLogger->setWindowIcon(QIcon("../OMEditGUI/Resources/icons/console.png"));
this->mpOMCLogger->setWindowIcon(QIcon(":/Resources/icons/console.png"));
this->mpOMCLogger->setWindowTitle(QString(Helper::applicationName).append(" - OMC Messages Log"));
// Set the QTextEdit Box
this->mpTextEdit = new QTextEdit();
Expand Down Expand Up @@ -559,6 +559,24 @@ bool OMCProxy::existClass(QString className)
return false;
}

bool OMCProxy::renameClass(QString oldName, QString newName)
{
sendCommand("renameClass(" + oldName + ", " + newName + ")");
if (getResult().toLower().contains("error"))
return false;
else
return true;
}

bool OMCProxy::deleteClass(QString className)
{
sendCommand("deleteClass(" + className + ")");
if (getResult().contains("true"))
return true;
else
return false;
}

QString OMCProxy::getSourceFile(QString modelName)
{
sendCommand("getSourceFile(" + modelName + ")");
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/OMCProxy.h
Expand Up @@ -96,6 +96,8 @@ class OMCProxy : public QObject
bool createModel(QString modelName);
bool newModel(QString modelName, QString parentModelName);
bool existClass(QString className);
bool renameClass(QString oldName, QString newName);
bool deleteClass(QString className);
QString getSourceFile(QString modelName);
bool setSourceFile(QString modelName, QString path);
bool save(QString modelName);
Expand Down
8 changes: 6 additions & 2 deletions OMEdit/OMEditGUI/OMEditGUI.pro
Expand Up @@ -109,8 +109,8 @@ DEFINES += __x86__ \
__OSVERSION__=4 \
__WIN32__
LIBS += -L. \
-lomniORB414_rtd \
-lomnithread34_rtd
-lomniORB414_rt \
-lomnithread34_rt

INCLUDEPATH += C:\\Thesis\\omniORB-4.1.4\\include \
../Pltpkg2 \
Expand All @@ -136,3 +136,7 @@ FORMS += \
../Pltpkg2/dataSelect.ui \
../Pltpkg2/compoundWidget.ui \
IconProperties.ui

RESOURCES += resource_omedit.qrc

RC_FILE = rc_omedit.rc
5 changes: 5 additions & 0 deletions OMEdit/OMEditGUI/OMEdit_Resources.qrc
@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/">
<file>Resources/icons/omeditor.png</file>
</qresource>
</RCC>
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/PlotWidget.cpp
Expand Up @@ -66,7 +66,7 @@ PlotWidget::PlotWidget(MainWindow *pParent)

void PlotWidget::readPlotVariables(QString fileName)
{
QFile simulationResultFile(QString(qApp->applicationDirPath()).append("/../tmp/").append(fileName));
QFile simulationResultFile(QString(qApp->applicationDirPath()).append("/tmp/").append(fileName));
simulationResultFile.open(QIODevice::ReadOnly);

QList<QString> plotVariablesList;
Expand Down

0 comments on commit 9e6843f

Please sign in to comment.