Skip to content

Commit

Permalink
OMSimulator rename functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Aug 3, 2018
1 parent 445f370 commit 51c079c
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 54 deletions.
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Annotations/TextAnnotation.cpp
Expand Up @@ -583,7 +583,7 @@ void TextAnnotation::updateTextString()
if (mOriginalTextString.toLower().contains("%name")) {
mTextString.replace(QRegExp("%name"), mpComponent->getName());
}
if (mOriginalTextString.toLower().contains("%class")) {
if (mOriginalTextString.toLower().contains("%class") && mpComponent->getLibraryTreeItem()) {
mTextString.replace(QRegExp("%class"), mpComponent->getLibraryTreeItem()->getNameStructure());
}
if (!mTextString.contains("%")) {
Expand Down
26 changes: 19 additions & 7 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -498,6 +498,7 @@ Component::Component(QString name, LibraryTreeItem *pLibraryTreeItem, QString an
connect(mpLibraryTreeItem, SIGNAL(unLoadedForComponent()), SLOT(handleUnloaded()));
connect(mpLibraryTreeItem, SIGNAL(shapeAddedForComponent()), SLOT(handleShapeAdded()));
connect(mpLibraryTreeItem, SIGNAL(componentAddedForComponent()), SLOT(handleComponentAdded()));
connect(mpLibraryTreeItem, SIGNAL(nameChanged()), SLOT(handleNameChanged()));
}
connect(this, SIGNAL(transformHasChanged()), SLOT(updatePlacementAnnotation()));
connect(this, SIGNAL(transformHasChanged()), SLOT(updateOriginItem()));
Expand Down Expand Up @@ -2122,6 +2123,23 @@ void Component::handleComponentAdded()
pComponent->updateConnections();
}

/*!
* \brief Component::handleNameChanged
* Handles the name change of OMSimulator elements.
*/
void Component::handleNameChanged()
{
if (mpComponentInfo) {
// we should update connections associated with this component before updating the component name
renameComponentInConnections(mpLibraryTreeItem->getName());
mpComponentInfo->setName(mpLibraryTreeItem->getName());
mpComponentInfo->setClassName(mpLibraryTreeItem->getNameStructure());
}
updateToolTip();
displayTextChangedRecursive();
update();
}

/*!
* \brief Component::referenceComponentAdded
* Adds the referenced components when reference component is added.
Expand Down Expand Up @@ -2322,13 +2340,7 @@ void Component::componentCommentHasChanged()
void Component::componentNameHasChanged()
{
updateToolTip();
if (mpLibraryTreeItem && mpLibraryTreeItem->getLibraryType() == LibraryTreeItem::OMS) {
mpLibraryTreeItem->setName(mpComponentInfo->getName());
MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->updateLibraryTreeItem(mpLibraryTreeItem);
emit displayTextChanged();
} else {
displayTextChangedRecursive();
}
displayTextChangedRecursive();
update();
}

Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Component/Component.h
Expand Up @@ -329,6 +329,7 @@ public slots:
void handleUnloaded();
void handleShapeAdded();
void handleComponentAdded();
void handleNameChanged();
void referenceComponentAdded();
void referenceComponentTransformHasChanged();
void referenceComponentChanged();
Expand Down
23 changes: 17 additions & 6 deletions OMEdit/OMEditGUI/Component/FMUProperties.cpp
Expand Up @@ -35,6 +35,8 @@
#include "Modeling/Commands.h"
#include "ComponentProperties.h"

#include <QMessageBox>

FMUProperties::FMUProperties()
{
mParameterValues.clear();
Expand Down Expand Up @@ -63,7 +65,6 @@ FMUPropertiesDialog::FMUPropertiesDialog(Component *pComponent, QWidget *pParent
// Create the name label and text box
mpNameLabel = new Label(Helper::name);
mpNameTextBox = new QLineEdit(mpComponent->getName());
mpNameTextBox->setDisabled(true);
// FMU Info
const oms_fmu_info_t *pFMUInfo = mpComponent->getLibraryTreeItem()->getFMUInfo();
mpGeneralGroupBox = new QGroupBox(Helper::general);
Expand Down Expand Up @@ -301,8 +302,19 @@ FMUPropertiesDialog::FMUPropertiesDialog(Component *pComponent, QWidget *pParent
*/
void FMUPropertiesDialog::updateFMUParameters()
{
QString oldName = mpComponent->getLibraryTreeItem()->getNameStructure();
QString newName = QString("%1.%2").arg(mpComponent->getLibraryTreeItem()->parent()->getNameStructure(), mpNameTextBox->text());
// check name
if (mpNameTextBox->text().isEmpty()) {
QMessageBox::critical(this, QString("%1 - %2").arg(Helper::applicationName).arg(Helper::error), GUIMessages::getMessage(
GUIMessages::ENTER_NAME).arg(Helper::item), Helper::ok);
return;
}
ModelWidget *pModelWidget = mpComponent->getGraphicsView()->getModelWidget();
pModelWidget->getUndoStack()->beginMacro("Update FMU properties");
// if the name is same as old then skip OMSRenameCommand.
if (mpNameTextBox->text().compare(mpComponent->getName()) != 0) {
// push the change on the undo stack
pModelWidget->getUndoStack()->push(new OMSRenameCommand(mpComponent->getLibraryTreeItem(), mpNameTextBox->text()));
}
FMUProperties newFMUProperties;
foreach (QLineEdit *pParameterLineEdit, mParameterLineEdits) {
newFMUProperties.mParameterValues.append(pParameterLineEdit->text());
Expand All @@ -311,10 +323,9 @@ void FMUPropertiesDialog::updateFMUParameters()
newFMUProperties.mInputValues.append(pInputLineEdit->text());
}
// push the change on the undo stack
FMUPropertiesCommand *pFMUPropertiesCommand = new FMUPropertiesCommand(mpComponent, oldName, newName, mOldFMUProperties, newFMUProperties);
ModelWidget *pModelWidget = mpComponent->getGraphicsView()->getModelWidget();
pModelWidget->getUndoStack()->push(pFMUPropertiesCommand);
pModelWidget->getUndoStack()->push(new FMUPropertiesCommand(mpComponent, mpNameTextBox->text(), mOldFMUProperties, newFMUProperties));
pModelWidget->updateModelText();
pModelWidget->endMacro();
// accept the dialog
accept();
}
55 changes: 42 additions & 13 deletions OMEdit/OMEditGUI/Modeling/Commands.cpp
Expand Up @@ -1931,13 +1931,11 @@ void DeleteSubModelCommand::undo()
mpGraphicsView->addComponentToList(mpComponent);
}

FMUPropertiesCommand::FMUPropertiesCommand(Component *pComponent, QString oldName, QString newName, FMUProperties oldFMUProperties,
FMUPropertiesCommand::FMUPropertiesCommand(Component *pComponent, QString name, FMUProperties oldFMUProperties,
FMUProperties newFMUProperties, QUndoCommand *pParent)
: QUndoCommand(pParent)
{
mpComponent = pComponent;
mOldName = oldName;
mNewName = newName;
mOldFMUProperties = oldFMUProperties;
mNewFMUProperties = newFMUProperties;
setText(QString("Update FMU %1 Parameters").arg(mpComponent->getName()));
Expand All @@ -1949,11 +1947,6 @@ FMUPropertiesCommand::FMUPropertiesCommand(Component *pComponent, QString oldNam
*/
void FMUPropertiesCommand::redo()
{
// Rename
// if (OMSProxy::instance()->rename(mOldName, mNewName)) {
// mpComponent->getComponentInfo()->setName(mNewName.split('.').last());
// mpComponent->componentNameHasChanged();
// }
// Parameters
int parametersIndex = 0;
int inputsIndex = 0;
Expand Down Expand Up @@ -2007,11 +2000,6 @@ void FMUPropertiesCommand::redo()
*/
void FMUPropertiesCommand::undo()
{
// Rename
// if (OMSProxy::instance()->rename(mNewName, mOldName)) {
// mpComponent->getComponentInfo()->setName(mOldName.split('.').last());
// mpComponent->componentNameHasChanged();
// }
// Parameters
int parametersIndex = 0;
int inputsIndex = 0;
Expand Down Expand Up @@ -2293,3 +2281,44 @@ void DeleteSubModelIconCommand::undo()
}
}
}

OMSRenameCommand::OMSRenameCommand(LibraryTreeItem *pLibraryTreeItem, QString name, QUndoCommand *pParent)
: QUndoCommand(pParent)
{
mpLibraryTreeItem = pLibraryTreeItem;
mOldName = mpLibraryTreeItem->getName();
mNewName = name;
setText("OMS rename");
}

/*!
* \brief OMSRenameCommand::redo
* Redo the OMSRenameCommand
*/
void OMSRenameCommand::redo()
{
QString identOld = mpLibraryTreeItem->getNameStructure();
QString identNew = mpLibraryTreeItem->parent()->getNameStructure().isEmpty() ? mNewName : mpLibraryTreeItem->parent()->getNameStructure() + "." + mNewName;
OMSProxy::instance()->rename(identOld, identNew);
mpLibraryTreeItem->setName(mNewName);
mpLibraryTreeItem->setNameStructure(identNew);
MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->updateLibraryTreeItem(mpLibraryTreeItem);
mpLibraryTreeItem->emitNameChanged();
mpLibraryTreeItem->updateChildrenNameStructure();
}

/*!
* \brief OMSRenameCommand::undo
* Undo the OMSRenameCommand
*/
void OMSRenameCommand::undo()
{
QString identOld = mpLibraryTreeItem->getNameStructure();
QString identNew = mpLibraryTreeItem->parent()->getNameStructure().isEmpty() ? mOldName : mpLibraryTreeItem->parent()->getNameStructure() + "." + mOldName;
OMSProxy::instance()->rename(identOld, identNew);
mpLibraryTreeItem->setName(mOldName);
mpLibraryTreeItem->setNameStructure(identNew);
MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->updateLibraryTreeItem(mpLibraryTreeItem);
mpLibraryTreeItem->emitNameChanged();
mpLibraryTreeItem->updateChildrenNameStructure();
}
18 changes: 14 additions & 4 deletions OMEdit/OMEditGUI/Modeling/Commands.h
Expand Up @@ -431,14 +431,12 @@ class DeleteSubModelCommand : public QUndoCommand
class FMUPropertiesCommand : public QUndoCommand
{
public:
FMUPropertiesCommand(Component *pComponent, QString oldName, QString newName, FMUProperties oldFMUProperties,
FMUProperties newFMUProperties, QUndoCommand *pParent = 0);
FMUPropertiesCommand(Component *pComponent, QString name, FMUProperties oldFMUProperties, FMUProperties newFMUProperties,
QUndoCommand *pParent = 0);
void redo();
void undo();
private:
Component *mpComponent;
QString mOldName;
QString mNewName;
FMUProperties mOldFMUProperties;
FMUProperties mNewFMUProperties;
};
Expand Down Expand Up @@ -477,4 +475,16 @@ class DeleteSubModelIconCommand : public QUndoCommand
GraphicsView *mpGraphicsView;
};

class OMSRenameCommand : public QUndoCommand
{
public:
OMSRenameCommand(LibraryTreeItem *pLibraryTreeItem, QString name, QUndoCommand *pParent = 0);
void redo();
void undo();
private:
LibraryTreeItem *mpLibraryTreeItem;
QString mOldName;
QString mNewName;
};

#endif // COMMANDS_H
44 changes: 33 additions & 11 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -606,6 +606,21 @@ void LibraryTreeItem::emitComponentAdded(Component *pComponent)
emit componentAddedForComponent();
}

/*!
* \brief LibraryTreeItem::updateChildrenNameStructure
* Updates the children name structure recursively.
*/
void LibraryTreeItem::updateChildrenNameStructure()
{
for (int i = 0; i < childrenSize(); i++) {
LibraryTreeItem *pChildLibraryTreeItem = child(i);
if (pChildLibraryTreeItem) {
pChildLibraryTreeItem->setNameStructure(QString("%1.%2").arg(mNameStructure, pChildLibraryTreeItem->getName()));
pChildLibraryTreeItem->updateChildrenNameStructure();
}
}
}

/*!
* \brief LibraryTreeItem::handleLoaded
* Handles the case when an undefined inherited class is loaded.
Expand Down Expand Up @@ -2751,11 +2766,10 @@ void LibraryTreeView::createActions()
mpTLMCoSimulationAction = new QAction(QIcon(":/Resources/icons/tlm-simulate.svg"), Helper::tlmCoSimulationSetup, this);
mpTLMCoSimulationAction->setStatusTip(Helper::tlmCoSimulationSetupTip);
connect(mpTLMCoSimulationAction, SIGNAL(triggered()), SLOT(TLMSimulate()));
// rename OMSimulator model Action
mpRenameOMSModelAction = new QAction(Helper::rename, this);
mpRenameOMSModelAction->setStatusTip(Helper::renameOMSModelTip);
mpRenameOMSModelAction->setEnabled(false);
connect(mpRenameOMSModelAction, SIGNAL(triggered()), SLOT(renameOMSModel()));
// OMSimulator rename Action
mpOMSRenameAction = new QAction(Helper::rename, this);
mpOMSRenameAction->setStatusTip(Helper::OMSRenameTip);
connect(mpOMSRenameAction, SIGNAL(triggered()), SLOT(OMSRename()));
// OMSimulator simulation setup action
mpOMSSimulationSetupAction = new QAction(QIcon(":/Resources/icons/tlm-simulate.svg"), Helper::OMSSimulationSetup, this);
mpOMSSimulationSetupAction->setStatusTip(Helper::OMSSimulationSetupTip);
Expand Down Expand Up @@ -2949,12 +2963,15 @@ void LibraryTreeView::showContextMenu(QPoint point)
break;
case LibraryTreeItem::OMS:
menu.addAction(mpViewDiagramAction);
if (pLibraryTreeItem->isTopLevel() || (!pLibraryTreeItem->getOMSConnector())) {
menu.addSeparator();
menu.addAction(mpOMSRenameAction);
}
if (pLibraryTreeItem->isTopLevel()) {
menu.addSeparator();
menu.addAction(mpSaveAction);
menu.addAction(mpSaveAsAction);
menu.addSeparator();
menu.addAction(mpRenameOMSModelAction);
menu.addAction(mpOMSSimulationSetupAction);
menu.addSeparator();
menu.addAction(mpUnloadOMSModelAction);
Expand Down Expand Up @@ -3482,12 +3499,17 @@ void LibraryTreeView::openOMSSimulationDialog()
}
}

void LibraryTreeView::renameOMSModel()
/*!
* \brief LibraryTreeView::OMSRename
* Opens the RenameItemDialog.
*/
void LibraryTreeView::OMSRename()
{
/*! @todo Implement the OMSimulator model rename functionality.
* We need to update the name structure of nested models.
*/
qDebug() << "not implemented yet";
LibraryTreeItem *pLibraryTreeItem = getSelectedLibraryTreeItem();
if (pLibraryTreeItem) {
RenameItemDialog *pRenameItemDialog = new RenameItemDialog(pLibraryTreeItem, MainWindow::instance());
pRenameItemDialog->exec();
}
}

/*!
Expand Down
7 changes: 5 additions & 2 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h
Expand Up @@ -150,6 +150,8 @@ class LibraryTreeItem : public QObject
void emitUnLoaded();
void emitShapeAdded(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView);
void emitComponentAdded(Component *pComponent);
void emitNameChanged() {emit nameChanged();}
void updateChildrenNameStructure();
void emitConnectionAdded(LineAnnotation *pConnectionLineAnnotation) {emit connectionAdded(pConnectionLineAnnotation);}
void emitCoOrdinateSystemUpdated(GraphicsView *pGraphicsView) {emit coOrdinateSystemUpdated(pGraphicsView);}

Expand Down Expand Up @@ -189,6 +191,7 @@ class LibraryTreeItem : public QObject
void shapeAddedForComponent();
void componentAdded(Component *pComponent);
void componentAddedForComponent();
void nameChanged();
void connectionAdded(LineAnnotation *pConnectionLineAnnotation);
void iconUpdated();
void coOrdinateSystemUpdated(GraphicsView *pGraphicsView);
Expand Down Expand Up @@ -350,7 +353,7 @@ class LibraryTreeView : public QTreeView
QAction *mpGenerateVerificationScenariosAction;
QAction *mpFetchInterfaceDataAction;
QAction *mpTLMCoSimulationAction;
QAction *mpRenameOMSModelAction;
QAction *mpOMSRenameAction;
QAction *mpOMSSimulationSetupAction;
QAction *mpUnloadOMSModelAction;
void createActions();
Expand Down Expand Up @@ -400,7 +403,7 @@ public slots:
void fetchInterfaceData();
void TLMSimulate();
void openOMSSimulationDialog();
void renameOMSModel();
void OMSRename();
void unloadOMSModel();
protected:
virtual void mouseDoubleClickEvent(QMouseEvent *event);
Expand Down

0 comments on commit 51c079c

Please sign in to comment.