Skip to content

Commit

Permalink
Implemented AddTLMBusDialog
Browse files Browse the repository at this point in the history
Add and load the TLM bus
  • Loading branch information
adeas31 committed Nov 5, 2018
1 parent 0072563 commit 416a83b
Show file tree
Hide file tree
Showing 22 changed files with 756 additions and 35 deletions.
3 changes: 2 additions & 1 deletion OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp
Expand Up @@ -981,7 +981,8 @@ void ShapeAnnotation::setShapeFlags(bool enable)
if (!mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() && !isInheritedShape()
&& !(mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::OMS
&& (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getOMSConnector()
|| mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getOMSBusConnector()))) {
|| mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getOMSBusConnector()
|| mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getOMSTLMBusConnector()))) {
setFlag(QGraphicsItem::ItemIsMovable, enable);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, enable);
}
Expand Down
27 changes: 22 additions & 5 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -459,6 +459,7 @@ Component::Component(QString name, LibraryTreeItem *pLibraryTreeItem, QString an
createStateComponent();
mpInputOutputComponentPolygon = 0;
mpBusComponentRectangle = 0;
mpTLMBusComponentPolygon = 0;
mHasTransition = false;
mIsInitialState = false;
if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::CompositeModel) {
Expand Down Expand Up @@ -534,6 +535,7 @@ Component::Component(LibraryTreeItem *pLibraryTreeItem, Component *pParentCompon
mpStateComponentRectangle = 0;
mpInputOutputComponentPolygon = 0;
mpBusComponentRectangle = 0;
mpTLMBusComponentPolygon = 0;
mHasTransition = false;
mIsInitialState = false;
drawInheritedComponentsAndShapes();
Expand Down Expand Up @@ -570,6 +572,7 @@ Component::Component(Component *pComponent, Component *pParentComponent, Compone
mpStateComponentRectangle = 0;
mpInputOutputComponentPolygon = 0;
mpBusComponentRectangle = 0;
mpTLMBusComponentPolygon = 0;
mHasTransition = false;
mIsInitialState = false;
if (mpLibraryTreeItem && mpLibraryTreeItem->getLibraryType() == LibraryTreeItem::OMS) {
Expand Down Expand Up @@ -625,6 +628,7 @@ Component::Component(Component *pComponent, GraphicsView *pGraphicsView)
createStateComponent();
mpInputOutputComponentPolygon = 0;
mpBusComponentRectangle = 0;
mpTLMBusComponentPolygon = 0;
mHasTransition = false;
mIsInitialState = false;
drawComponent();
Expand Down Expand Up @@ -670,6 +674,7 @@ Component::Component(ComponentInfo *pComponentInfo, Component *pParentComponent)
createDefaultComponent();
mpInputOutputComponentPolygon = 0;
mpBusComponentRectangle = 0;
mpTLMBusComponentPolygon = 0;
mpStateComponentRectangle = 0;
mHasTransition = false;
mIsInitialState = false;
Expand Down Expand Up @@ -1601,6 +1606,14 @@ void Component::drawOMSComponent()
mpBusComponentRectangle->setLineColor(QColor(73, 151, 60));
mpBusComponentRectangle->setFillColor(QColor(73, 151, 60));
mpBusComponentRectangle->setFillPattern(StringHandler::FillSolid);
} else if (mpLibraryTreeItem->getOMSTLMBusConnector()) { // if component is a tlm bus
mpTLMBusComponentPolygon = new PolygonAnnotation(this);
QList<QPointF> points;
points << QPointF(-100.0, 0.0) << QPointF(0.0, 100.0) << QPointF(100.0, 0.0) << QPointF(0.0, -100.0) << QPointF(-100.0, 0.0);
mpTLMBusComponentPolygon->setPoints(points);
mpTLMBusComponentPolygon->setLineColor(QColor(100, 100, 255));
mpTLMBusComponentPolygon->setFillColor(QColor(100, 100, 255));
mpTLMBusComponentPolygon->setFillPattern(StringHandler::FillSolid);
}
// return to avoid the old code. The code below should be removed later on.
return;
Expand Down Expand Up @@ -1874,6 +1887,9 @@ void Component::createResizerItems()
bool isOMSBusConnecor = (mpLibraryTreeItem
&& mpLibraryTreeItem->getLibraryType() == LibraryTreeItem::OMS
&& mpLibraryTreeItem->getOMSBusConnector());
bool isOMSTLMBusConnecor = (mpLibraryTreeItem
&& mpLibraryTreeItem->getLibraryType() == LibraryTreeItem::OMS
&& mpLibraryTreeItem->getOMSTLMBusConnector());
qreal x1, y1, x2, y2;
getResizerItemsPositions(&x1, &y1, &x2, &y2);
//Bottom left resizer
Expand All @@ -1884,7 +1900,7 @@ void Component::createResizerItems()
connect(mpBottomLeftResizerItem, SIGNAL(resizerItemMoved(QPointF)), SLOT(resizeComponent(QPointF)));
connect(mpBottomLeftResizerItem, SIGNAL(resizerItemReleased()), SLOT(finishResizeComponent()));
connect(mpBottomLeftResizerItem, SIGNAL(resizerItemPositionChanged()), SLOT(resizedComponent()));
mpBottomLeftResizerItem->blockSignals(isSystemLibrary || isInheritedComponent() || isOMSConnector || isOMSBusConnecor);
mpBottomLeftResizerItem->blockSignals(isSystemLibrary || isInheritedComponent() || isOMSConnector || isOMSBusConnecor || isOMSTLMBusConnecor);
//Top left resizer
mpTopLeftResizerItem = new ResizerItem(this);
mpTopLeftResizerItem->setPos(mapFromScene(x1, y2));
Expand All @@ -1893,7 +1909,7 @@ void Component::createResizerItems()
connect(mpTopLeftResizerItem, SIGNAL(resizerItemMoved(QPointF)), SLOT(resizeComponent(QPointF)));
connect(mpTopLeftResizerItem, SIGNAL(resizerItemReleased()), SLOT(finishResizeComponent()));
connect(mpTopLeftResizerItem, SIGNAL(resizerItemPositionChanged()), SLOT(resizedComponent()));
mpTopLeftResizerItem->blockSignals(isSystemLibrary || isInheritedComponent() || isOMSConnector || isOMSBusConnecor);
mpTopLeftResizerItem->blockSignals(isSystemLibrary || isInheritedComponent() || isOMSConnector || isOMSBusConnecor || isOMSTLMBusConnecor);
//Top Right resizer
mpTopRightResizerItem = new ResizerItem(this);
mpTopRightResizerItem->setPos(mapFromScene(x2, y2));
Expand All @@ -1902,7 +1918,7 @@ void Component::createResizerItems()
connect(mpTopRightResizerItem, SIGNAL(resizerItemMoved(QPointF)), SLOT(resizeComponent(QPointF)));
connect(mpTopRightResizerItem, SIGNAL(resizerItemReleased()), SLOT(finishResizeComponent()));
connect(mpTopRightResizerItem, SIGNAL(resizerItemPositionChanged()), SLOT(resizedComponent()));
mpTopRightResizerItem->blockSignals(isSystemLibrary || isInheritedComponent() || isOMSConnector || isOMSBusConnecor);
mpTopRightResizerItem->blockSignals(isSystemLibrary || isInheritedComponent() || isOMSConnector || isOMSBusConnecor || isOMSTLMBusConnecor);
//Bottom Right resizer
mpBottomRightResizerItem = new ResizerItem(this);
mpBottomRightResizerItem->setPos(mapFromScene(x2, y1));
Expand All @@ -1911,7 +1927,7 @@ void Component::createResizerItems()
connect(mpBottomRightResizerItem, SIGNAL(resizerItemMoved(QPointF)), SLOT(resizeComponent(QPointF)));
connect(mpBottomRightResizerItem, SIGNAL(resizerItemReleased()), SLOT(finishResizeComponent()));
connect(mpBottomRightResizerItem, SIGNAL(resizerItemPositionChanged()), SLOT(resizedComponent()));
mpBottomRightResizerItem->blockSignals(isSystemLibrary || isInheritedComponent() || isOMSConnector || isOMSBusConnecor);
mpBottomRightResizerItem->blockSignals(isSystemLibrary || isInheritedComponent() || isOMSConnector || isOMSBusConnecor || isOMSTLMBusConnecor);
}

void Component::getResizerItemsPositions(qreal *x1, qreal *y1, qreal *x2, qreal *y2)
Expand Down Expand Up @@ -2925,7 +2941,8 @@ void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
// No context menu for component of type OMS connector i.e., input/output signal or OMS bus connector.
if (mpLibraryTreeItem && mpLibraryTreeItem->getLibraryType() == LibraryTreeItem::OMS
&& (mpLibraryTreeItem->getOMSConnector()
|| mpLibraryTreeItem->getOMSBusConnector())) {
|| mpLibraryTreeItem->getOMSBusConnector()
|| mpLibraryTreeItem->getOMSTLMBusConnector())) {
return;
}

Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Component/Component.h
Expand Up @@ -266,6 +266,7 @@ class Component : public QObject, public QGraphicsItem
RectangleAnnotation *mpStateComponentRectangle;
PolygonAnnotation *mpInputOutputComponentPolygon;
RectangleAnnotation *mpBusComponentRectangle;
PolygonAnnotation *mpTLMBusComponentPolygon;
QAction *mpParametersAction;
QAction *mpFetchInterfaceDataAction;
QAction *mpAttributesAction;
Expand Down
17 changes: 12 additions & 5 deletions OMEdit/OMEditGUI/Component/CornerItem.cpp
Expand Up @@ -58,7 +58,8 @@ CornerItem::CornerItem(qreal x, qreal y, int connectedPointIndex, ShapeAnnotatio
if (mpShapeAnnotation->isInheritedShape()
|| (mpShapeAnnotation->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::OMS
&& (mpShapeAnnotation->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getOMSConnector()
|| mpShapeAnnotation->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getOMSBusConnector()))) {
|| mpShapeAnnotation->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getOMSBusConnector()
|| mpShapeAnnotation->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getOMSTLMBusConnector()))) {
setFlag(QGraphicsItem::ItemIsMovable, false);
}
/* Only shapes manipulation via CornerItem's if the class is not a system library class
Expand All @@ -69,7 +70,8 @@ CornerItem::CornerItem(qreal x, qreal y, int connectedPointIndex, ShapeAnnotatio
!mpShapeAnnotation->isInheritedShape() &&
!(mpShapeAnnotation->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::OMS &&
(mpShapeAnnotation->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getOMSConnector()
|| mpShapeAnnotation->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getOMSBusConnector()))) {
|| mpShapeAnnotation->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getOMSBusConnector()
|| mpShapeAnnotation->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getOMSTLMBusConnector()))) {
connect(this, SIGNAL(cornerItemMoved(int,QPointF)), mpShapeAnnotation, SLOT(updateCornerItemPoint(int,QPointF)));
connect(this, SIGNAL(cornerItemPress()), mpShapeAnnotation, SLOT(cornerItemPressed()));
connect(this, SIGNAL(cornerItemRelease()), mpShapeAnnotation, SLOT(cornerItemReleased()));
Expand Down Expand Up @@ -112,7 +114,8 @@ void CornerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
if (mpShapeAnnotation->isInheritedShape()
|| (mpShapeAnnotation->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::OMS
&& (mpShapeAnnotation->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getOMSConnector()
|| mpShapeAnnotation->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getOMSBusConnector()))) {
|| mpShapeAnnotation->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getOMSBusConnector()
|| mpShapeAnnotation->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getOMSTLMBusConnector()))) {
pen.setColor(Qt::darkRed);
} else {
pen.setColor(Qt::red);
Expand Down Expand Up @@ -253,7 +256,9 @@ void ResizerItem::setActive()
{
if (mpComponent->isInheritedComponent()
|| (mpComponent->getLibraryTreeItem() && mpComponent->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::OMS
&& (mpComponent->getLibraryTreeItem()->getOMSConnector() || mpComponent->getLibraryTreeItem()->getOMSBusConnector()))) {
&& (mpComponent->getLibraryTreeItem()->getOMSConnector()
|| mpComponent->getLibraryTreeItem()->getOMSBusConnector()
|| mpComponent->getLibraryTreeItem()->getOMSTLMBusConnector()))) {
mPen = mInheritedActivePen;
} else {
mPen = mActivePen;
Expand Down Expand Up @@ -387,7 +392,9 @@ void OriginItem::setActive()
setZValue(3000);
if (mpComponent->isInheritedComponent()
|| (mpComponent->getLibraryTreeItem() && mpComponent->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::OMS
&& (mpComponent->getLibraryTreeItem()->getOMSConnector() || mpComponent->getLibraryTreeItem()->getOMSBusConnector()))) {
&& (mpComponent->getLibraryTreeItem()->getOMSConnector()
|| mpComponent->getLibraryTreeItem()->getOMSBusConnector()
|| mpComponent->getLibraryTreeItem()->getOMSTLMBusConnector()))) {
mPen = mInheritedActivePen;
} else {
mPen = mActivePen;
Expand Down
4 changes: 4 additions & 0 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -3466,6 +3466,9 @@ void MainWindow::createActions()
// Add bus action
mpAddBusAction = new QAction(QIcon(":/Resources/icons/bus.svg"), Helper::addBus, this);
mpAddBusAction->setStatusTip(Helper::addBusTip);
// Add tlm bus action
mpAddTLMBusAction = new QAction(QIcon(":/Resources/icons/tlm-bus.svg"), Helper::addTLMBus, this);
mpAddTLMBusAction->setStatusTip(Helper::addTLMBusTip);
// Add SubModel Action
mpAddSubModelAction = new QAction(QIcon(":/Resources/icons/import-fmu.svg"), Helper::addSubModel, this);
mpAddSubModelAction->setStatusTip(Helper::addSubModelTip);
Expand Down Expand Up @@ -4130,6 +4133,7 @@ void MainWindow::createToolbars()
mpOMSimulatorToobar->addSeparator();
mpOMSimulatorToobar->addAction(mpAddConnectorAction);
mpOMSimulatorToobar->addAction(mpAddBusAction);
mpOMSimulatorToobar->addAction(mpAddTLMBusAction);
mpOMSimulatorToobar->addSeparator();
mpOMSimulatorToobar->addAction(mpAddSubModelAction);
mpOMSimulatorToobar->addSeparator();
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/MainWindow.h
Expand Up @@ -191,6 +191,7 @@ class MainWindow : public QMainWindow
QAction* getDeleteIconAction() {return mpDeleteIconAction;}
QAction* getAddConnectorAction() {return mpAddConnectorAction;}
QAction* getAddBusAction() {return mpAddBusAction;}
QAction* getAddTLMBusAction() {return mpAddTLMBusAction;}
QAction* getAddSubModelAction() {return mpAddSubModelAction;}
QAction* getOMSSimulationSetupAction() {return mpOMSSimulationSetupAction;}
QAction* getLogCurrentFileAction() {return mpLogCurrentFileAction;}
Expand Down Expand Up @@ -416,6 +417,7 @@ class MainWindow : public QMainWindow
QAction *mpDeleteIconAction;
QAction *mpAddConnectorAction;
QAction *mpAddBusAction;
QAction *mpAddTLMBusAction;
QAction *mpAddSubModelAction;
QAction *mpOMSSimulationSetupAction;
// Toolbars
Expand Down
97 changes: 97 additions & 0 deletions OMEdit/OMEditGUI/Modeling/BusDialog.cpp
Expand Up @@ -412,6 +412,10 @@ AddBusDialog::AddBusDialog(QList<Component *> components, GraphicsView *pGraphic
setLayout(pMainLayout);
}

/*!
* \brief AddBusDialog::addBus
* Adds the bus by calling AddBusCommand
*/
void AddBusDialog::addBus()
{
if (mpNameTextBox->text().isEmpty()) {
Expand Down Expand Up @@ -465,3 +469,96 @@ void AddBusDialog::addBus()
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->handleIconUpdated();
accept();
}

/*!
* \class AddTLMBusDialog
* \brief A dialog for creating a tlm bus.
*/
/*!
* \brief AddTLMBusDialog::AddTLMBusDialog
* \param pGraphicsView
*/
AddTLMBusDialog::AddTLMBusDialog(GraphicsView *pGraphicsView)
: QDialog(pGraphicsView)
{
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle(QString("%1 - %2").arg(Helper::applicationName).arg(Helper::addTLMBus));
setMinimumWidth(400);
mpGraphicsView = pGraphicsView;
// set heading
mpHeading = Utilities::getHeadingLabel(Helper::addTLMBus);
// set separator line
mpHorizontalLine = Utilities::getHeadingLine();
// name
mpNameLabel = new Label(Helper::name);
mpNameTextBox = new QLineEdit;
// domain
mpDomainLabel = new Label(tr("Domain:"));
mpDomainTextBox = new QLineEdit;
// dimension
mpDimensionLabel = new Label(tr("Dimension:"));
mpDimensionSpinBox = new QSpinBox;
mpDimensionSpinBox->setRange(1, 3);
// interpolation
mpInterpolationLabel = new Label(tr("Interpolation:"));
mpInterpolationComboBox = new QComboBox;
mpInterpolationComboBox->addItem("No interpolation", oms_tlm_no_interpolation);
mpInterpolationComboBox->addItem("Coarse grained", oms_tlm_coarse_grained);
mpInterpolationComboBox->addItem("Fine grained", oms_tlm_fine_grained);
// buttons
mpOkButton = new QPushButton(Helper::ok);
mpOkButton->setAutoDefault(true);
connect(mpOkButton, SIGNAL(clicked()), SLOT(addTLMBus()));
mpCancelButton = new QPushButton(Helper::cancel);
mpCancelButton->setAutoDefault(false);
connect(mpCancelButton, SIGNAL(clicked()), SLOT(reject()));
// add buttons to the button box
mpButtonBox = new QDialogButtonBox(Qt::Horizontal);
mpButtonBox->addButton(mpOkButton, QDialogButtonBox::ActionRole);
mpButtonBox->addButton(mpCancelButton, QDialogButtonBox::ActionRole);
// set the layout
QGridLayout *pMainLayout = new QGridLayout;
pMainLayout->setAlignment(Qt::AlignLeft | Qt::AlignTop);
pMainLayout->addWidget(mpHeading, 0, 0, 1, 2);
pMainLayout->addWidget(mpHorizontalLine, 1, 0, 1, 2);
pMainLayout->addWidget(mpNameLabel, 2, 0);
pMainLayout->addWidget(mpNameTextBox, 2, 1);
pMainLayout->addWidget(mpDomainLabel, 3, 0);
pMainLayout->addWidget(mpDomainTextBox, 3, 1);
pMainLayout->addWidget(mpDimensionLabel, 4, 0);
pMainLayout->addWidget(mpDimensionSpinBox, 4, 1);
pMainLayout->addWidget(mpInterpolationLabel, 5, 0);
pMainLayout->addWidget(mpInterpolationComboBox, 5, 1);
pMainLayout->addWidget(mpButtonBox, 6, 0, 1, 2, Qt::AlignRight);
setLayout(pMainLayout);
}

/*!
* \brief AddTLMBusDialog::addTLMBus
* Adds the tlm bus by calling AddTLMBusCommand
*/
void AddTLMBusDialog::addTLMBus()
{
if (mpNameTextBox->text().isEmpty()) {
QMessageBox::critical(this, QString("%1 - %2").arg(Helper::applicationName, Helper::error),
GUIMessages::getMessage(GUIMessages::ENTER_NAME).arg(tr("TLM Bus")), Helper::ok);
return;
}

if (mpDomainTextBox->text().isEmpty()) {
QMessageBox::critical(this, QString("%1 - %2").arg(Helper::applicationName, Helper::error),
GUIMessages::getMessage(GUIMessages::ENTER_NAME).arg(tr("domain")), Helper::ok);
return;
}

QString annotation = QString("Placement(true,%1,%2,-10.0,-10.0,10.0,10.0,0,%1,%2,-10.0,-10.0,10.0,10.0,)")
.arg(Utilities::mapToCoOrdinateSystem(0.5, 0, 1, -100, 100))
.arg(Utilities::mapToCoOrdinateSystem(0.5, 0, 1, -100, 100));
AddTLMBusCommand *pAddBusCommand = new AddTLMBusCommand(mpNameTextBox->text(), 0, annotation, mpGraphicsView, false, mpDomainTextBox->text(),
mpDimensionSpinBox->value(),
(oms_tlm_interpolation_t)mpInterpolationComboBox->itemData(mpInterpolationComboBox->currentIndex()).toInt());
mpGraphicsView->getModelWidget()->getUndoStack()->push(pAddBusCommand);
mpGraphicsView->getModelWidget()->updateModelText();
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->handleIconUpdated();
accept();
}
26 changes: 26 additions & 0 deletions OMEdit/OMEditGUI/Modeling/BusDialog.h
Expand Up @@ -39,6 +39,8 @@
#include <QLineEdit>
#include <QListWidget>
#include <QDialogButtonBox>
#include <QSpinBox>
#include <QComboBox>

class Component;
class ConnectorItem : public QObject
Expand Down Expand Up @@ -112,4 +114,28 @@ private slots:
void addBus();
};

class AddTLMBusDialog : public QDialog
{
Q_OBJECT
public:
AddTLMBusDialog(GraphicsView *pGraphicsView);
private:
GraphicsView *mpGraphicsView;
Label *mpHeading;
QFrame *mpHorizontalLine;
Label *mpNameLabel;
QLineEdit *mpNameTextBox;
Label *mpDomainLabel;
QLineEdit *mpDomainTextBox;
Label *mpDimensionLabel;
QSpinBox *mpDimensionSpinBox;
Label *mpInterpolationLabel;
QComboBox *mpInterpolationComboBox;
QPushButton *mpOkButton;
QPushButton *mpCancelButton;
QDialogButtonBox *mpButtonBox;
private slots:
void addTLMBus();
};

#endif // ADDBUSDIALOG_H

0 comments on commit 416a83b

Please sign in to comment.