Skip to content

Commit

Permalink
TLM buses and connectors
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Nov 5, 2018
1 parent fb6277f commit b2e6536
Show file tree
Hide file tree
Showing 13 changed files with 450 additions and 86 deletions.
19 changes: 11 additions & 8 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -1449,6 +1449,9 @@ void Component::handleOMSComponentDoubleClick()
if (mpLibraryTreeItem && mpLibraryTreeItem->getOMSBusConnector()) {
AddBusDialog *pAddBusDialog = new AddBusDialog(QList<Component*>(), mpLibraryTreeItem, mpGraphicsView);
pAddBusDialog->exec();
} else if (mpLibraryTreeItem && mpLibraryTreeItem->getOMSTLMBusConnector()) {
AddTLMBusDialog *pAddTLMBusDialog = new AddTLMBusDialog(QList<Component*>(), mpLibraryTreeItem, mpGraphicsView);
pAddTLMBusDialog->exec();
} else if (mpLibraryTreeItem && mpLibraryTreeItem->getFMUInfo()) {
showFMUPropertiesDialog();
}
Expand Down Expand Up @@ -1655,14 +1658,14 @@ void Component::drawOMSComponent()
pBusRectangleAnnotation->setFillPattern(StringHandler::FillSolid);
mShapesList.append(pBusRectangleAnnotation);
} else if (mpLibraryTreeItem->getOMSTLMBusConnector()) { // if component is a tlm bus
PolygonAnnotation *pTLMBusPolygonAnnotation = 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);
pTLMBusPolygonAnnotation->setPoints(points);
pTLMBusPolygonAnnotation->setLineColor(QColor(100, 100, 255));
pTLMBusPolygonAnnotation->setFillColor(QColor(100, 100, 255));
pTLMBusPolygonAnnotation->setFillPattern(StringHandler::FillSolid);
mShapesList.append(pTLMBusPolygonAnnotation);
RectangleAnnotation *pTLMBusRectangleAnnotation = new RectangleAnnotation(this);
QList<QPointF> extents;
extents << QPointF(-100, -100) << QPointF(100, 100);
pTLMBusRectangleAnnotation->setExtents(extents);
pTLMBusRectangleAnnotation->setLineColor(QColor(100, 100, 255));
pTLMBusRectangleAnnotation->setFillColor(QColor(100, 100, 255));
pTLMBusRectangleAnnotation->setFillPattern(StringHandler::FillSolid);
mShapesList.append(pTLMBusRectangleAnnotation);
}
}

Expand Down
269 changes: 233 additions & 36 deletions OMEdit/OMEditGUI/Modeling/BusDialog.cpp

Large diffs are not rendered by default.

36 changes: 33 additions & 3 deletions OMEdit/OMEditGUI/Modeling/BusDialog.h
Expand Up @@ -54,6 +54,8 @@ class ConnectorItem : public QObject
QString getText() const {return mText;}
void setText(const QString &text) {mText = text;}
Component* getComponent() {return mpComponent;}
QString getTLMType() const {return mTLMType;}
void setTLMType(const QString &tlmType) {mTLMType = tlmType;}
ConnectorItem* parent() const {return mpParentConnectorItem;}
int childrenSize() const {return mChildren.size();}
void insertChild(int row, ConnectorItem *pConnectorItem) {mChildren.insert(row, pConnectorItem);}
Expand All @@ -66,6 +68,7 @@ class ConnectorItem : public QObject
private:
QString mText;
Component *mpComponent;
QString mTLMType;
ConnectorItem *mpParentConnectorItem;
QList<ConnectorItem*> mChildren;
bool mChecked;
Expand All @@ -86,12 +89,22 @@ class ConnectorsModel : public QAbstractItemModel
QModelIndex connectorItemIndex(const ConnectorItem *pConnectorItem) const;
ConnectorItem* getRootConnectorItem() {return mpRootConnectorItem;}
ConnectorItem* createConnectorItem(Component *pComponent, ConnectorItem *pParent);
void setColumnCount(int columnCount) {mColumnCount = columnCount;}

private:
ConnectorItem *mpRootConnectorItem;
int mColumnCount;
QModelIndex connectorItemIndexHelper(const ConnectorItem *pConnectorItem, const ConnectorItem *pParentConnectorItem,
const QModelIndex &parentIndex) const;
};

class ConnectorsTreeView : public QTreeView
{
Q_OBJECT
public:
ConnectorsTreeView(QWidget *pParent = 0);
};

class LibraryTreeItem;
class GraphicsView;
class Label;
Expand All @@ -108,9 +121,9 @@ class AddBusDialog : public QDialog
Label *mpNameLabel;
QLineEdit *mpNameTextBox;
ConnectorsModel *mpInputConnectorsTreeModel;
QTreeView *mpInputConnectorsTreeView;
ConnectorsTreeView *mpInputConnectorsTreeView;
ConnectorsModel *mpOutputConnectorsTreeModel;
QTreeView *mpOutputConnectorsTreeView;
ConnectorsTreeView *mpOutputConnectorsTreeView;
QPushButton *mpOkButton;
QPushButton *mpCancelButton;
QDialogButtonBox *mpButtonBox;
Expand All @@ -119,12 +132,24 @@ private slots:
void addBus();
};

class TLMConnector {
public:
QString mName;
QString mType;

TLMConnector();
TLMConnector(QString name, QString type);

bool operator==(const TLMConnector &tlmConnector) const;
};

class AddTLMBusDialog : public QDialog
{
Q_OBJECT
public:
AddTLMBusDialog(GraphicsView *pGraphicsView);
AddTLMBusDialog(QList<Component*> components, LibraryTreeItem *pLibraryTreeItem, GraphicsView *pGraphicsView);
private:
LibraryTreeItem *mpLibraryTreeItem;
GraphicsView *mpGraphicsView;
Label *mpHeading;
QFrame *mpHorizontalLine;
Expand All @@ -136,9 +161,14 @@ class AddTLMBusDialog : public QDialog
QSpinBox *mpDimensionSpinBox;
Label *mpInterpolationLabel;
QComboBox *mpInterpolationComboBox;
ConnectorsModel *mpInputConnectorsTreeModel;
ConnectorsTreeView *mpInputConnectorsTreeView;
ConnectorsModel *mpOutputConnectorsTreeModel;
ConnectorsTreeView *mpOutputConnectorsTreeView;
QPushButton *mpOkButton;
QPushButton *mpCancelButton;
QDialogButtonBox *mpButtonBox;
void markExistingTLMBusConnectors(ConnectorItem *pParentConnectorItem, QList<Component*> components);
private slots:
void addTLMBus();
};
Expand Down
72 changes: 72 additions & 0 deletions OMEdit/OMEditGUI/Modeling/Commands.cpp
Expand Up @@ -2788,3 +2788,75 @@ void AddTLMBusCommand::undo()
{

}

AddConnectorToTLMBusCommand::AddConnectorToTLMBusCommand(QString tlmBus, QString connectorName, QString connectorType,
GraphicsView *pGraphicsView, UndoCommand *pParent)
: UndoCommand(pParent)
{
mTLMBus = tlmBus;
mConnectorName = connectorName;
mConnectorType = connectorType;
mpGraphicsView = pGraphicsView;
}

/*!
* \brief AddConnectorToTLMBusCommand::redoInternal
* redoInternal the AddConnectorToTLMBusCommand.
*/
void AddConnectorToTLMBusCommand::redoInternal()
{
if (!OMSProxy::instance()->addConnectorToTLMBus(mTLMBus.toStdString().c_str(), mConnectorName.toStdString().c_str(),
mConnectorType.toStdString().c_str())) {
setFailed(true);
return;
}
mpGraphicsView->getModelWidget()->associateBusWithConnector(StringHandler::getLastWordAfterDot(mTLMBus),
StringHandler::getLastWordAfterDot(mConnectorName));
}

/*!
* \brief AddConnectorToTLMBusCommand::undo
* Undo the AddConnectorToTLMBusCommand.
*/
void AddConnectorToTLMBusCommand::undo()
{
OMSProxy::instance()->deleteConnectorFromTLMBus(mTLMBus.toStdString().c_str(), mConnectorName.toStdString().c_str());
mpGraphicsView->getModelWidget()->dissociateBusWithConnector(StringHandler::getLastWordAfterDot(mTLMBus),
StringHandler::getLastWordAfterDot(mConnectorName));
}

DeleteConnectorFromTLMBusCommand::DeleteConnectorFromTLMBusCommand(QString bus, QString connectorName, QString connectorType,
GraphicsView *pGraphicsView, UndoCommand *pParent)
: UndoCommand(pParent)
{
mTLMBus = bus;
mConnectorName = connectorName;
mConnectorType = connectorType;
mpGraphicsView = pGraphicsView;
}

/*!
* \brief DeleteConnectorFromTLMBusCommand::redoInternal
* redoInternal the DeleteConnectorFromTLMBusCommand.
*/
void DeleteConnectorFromTLMBusCommand::redoInternal()
{
if (!OMSProxy::instance()->deleteConnectorFromTLMBus(mTLMBus.toStdString().c_str(), mConnectorName.toStdString().c_str())) {
setFailed(true);
return;
}
mpGraphicsView->getModelWidget()->dissociateBusWithConnector(StringHandler::getLastWordAfterDot(mTLMBus),
StringHandler::getLastWordAfterDot(mConnectorName));
}

/*!
* \brief DeleteConnectorFromTLMBusCommand::undo
* Undo the DeleteConnectorFromTLMBusCommand.
*/
void DeleteConnectorFromTLMBusCommand::undo()
{
OMSProxy::instance()->addConnectorToTLMBus(mTLMBus.toStdString().c_str(), mConnectorName.toStdString().c_str(),
mConnectorType.toStdString().c_str());
mpGraphicsView->getModelWidget()->associateBusWithConnector(StringHandler::getLastWordAfterDot(mTLMBus),
StringHandler::getLastWordAfterDot(mConnectorName));
}
28 changes: 28 additions & 0 deletions OMEdit/OMEditGUI/Modeling/Commands.h
Expand Up @@ -598,4 +598,32 @@ class AddTLMBusCommand : public UndoCommand
Component *mpDiagramComponent;
};

class AddConnectorToTLMBusCommand : public UndoCommand
{
public:
AddConnectorToTLMBusCommand(QString tlmBus, QString connectorName, QString connectorType, GraphicsView *pGraphicsView,
UndoCommand *pParent = 0);
void redoInternal();
void undo();
private:
QString mTLMBus;
QString mConnectorName;
QString mConnectorType;
GraphicsView *mpGraphicsView;
};

class DeleteConnectorFromTLMBusCommand : public UndoCommand
{
public:
DeleteConnectorFromTLMBusCommand(QString bus, QString connectorName, QString connectorType, GraphicsView *pGraphicsView,
UndoCommand *pParent = 0);
void redoInternal();
void undo();
private:
QString mTLMBus;
QString mConnectorName;
QString mConnectorType;
GraphicsView *mpGraphicsView;
};

#endif // COMMANDS_H
13 changes: 12 additions & 1 deletion OMEdit/OMEditGUI/Modeling/ItemDelegate.cpp
Expand Up @@ -35,6 +35,7 @@
#include "Modeling/LibraryTreeWidget.h"
#include "Plotting/VariablesWidget.h"
#include "Simulation/SimulationOutputWidget.h"
#include "Modeling/BusDialog.h"

#include <QPainter>

Expand Down Expand Up @@ -192,7 +193,7 @@ void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
} else {
drawDecoration(painter, opt, decorationRect, pixmap);
}
if (parent() && qobject_cast<VariablesTreeView*>(parent())) {
if (parent() && (qobject_cast<VariablesTreeView*>(parent()) || qobject_cast<ConnectorsTreeView*>(parent()))) {
if ((index.column() == 1) && (index.flags() & Qt::ItemIsEditable)) {
/* The display rect is slightly larger than the area because it include the outer line. */
painter->drawRect(displayRect.adjusted(0, 0, -1, -1));
Expand Down Expand Up @@ -317,6 +318,11 @@ QWidget* ItemDelegate::createEditor(QWidget *pParent, const QStyleOptionViewItem
connect(pComboBox, SIGNAL(currentIndexChanged(QString)), SLOT(unitComboBoxChanged(QString)));
return pComboBox;
}
} else if (parent() && qobject_cast<ConnectorsTreeView*>(parent())) {
if (index.column() == 1) { // value column
QLineEdit *pValueTextBox = new QLineEdit(pParent);
return pValueTextBox;
}
}
return QItemDelegate::createEditor(pParent, option, index);
}
Expand All @@ -334,6 +340,11 @@ void ItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) cons
QComboBox* comboBox = static_cast<QComboBox*>(editor);
//set the index of the combo box
comboBox->setCurrentIndex(comboBox->findText(value, Qt::MatchExactly));
} else if (parent() && qobject_cast<ConnectorsTreeView*>(parent()) && index.column() == 1) {
QLineEdit *pValueTextBox = static_cast<QLineEdit*>(editor);
pValueTextBox->setText(index.data(Qt::DisplayRole).toString());
pValueTextBox->selectAll();
pValueTextBox->setFocusPolicy(Qt::WheelFocus);
} else {
QItemDelegate::setEditorData(editor, index);
}
Expand Down
23 changes: 22 additions & 1 deletion OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -5885,6 +5885,8 @@ void ModelWidget::drawOMSModelIconElements()
pChildLibraryTreeItem->getOMSTLMBusConnector()->dimensions,
pChildLibraryTreeItem->getOMSTLMBusConnector()->interpolation);
mpUndoStack->push(pAddTLMBusCommand);
// assoicated the bus component with each of its connector component
associateBusWithConnectors(pChildLibraryTreeItem->getName());
}
}
}
Expand Down Expand Up @@ -6264,6 +6266,16 @@ void ModelWidget::associateBusWithConnectors(Component *pBusComponent, GraphicsV
}
}
}
} else if (pBusComponent && pBusComponent->getLibraryTreeItem() && pBusComponent->getLibraryTreeItem()->getOMSTLMBusConnector()) {
oms3_tlmbusconnector_t *pTLMBusConnector = pBusComponent->getLibraryTreeItem()->getOMSTLMBusConnector();
if (pTLMBusConnector->connectornames) {
for (int i = 0 ; pTLMBusConnector->connectornames[i] ; i++) {
Component *pConnectorComponent = pGraphicsView->getComponentObject(QString(pTLMBusConnector->connectornames[i]));
if (pConnectorComponent) {
pConnectorComponent->setBusComponent(pBusComponent);
}
}
}
}
}

Expand Down Expand Up @@ -7324,7 +7336,16 @@ void ModelWidgetContainer::addTLMBus()
} else if (pModelWidget->getDiagramGraphicsView() && pModelWidget->getDiagramGraphicsView()->isVisible()) {
pGraphicsView = pModelWidget->getDiagramGraphicsView();
}
AddTLMBusDialog *pAddTLMBusDialog = new AddTLMBusDialog(pGraphicsView);
QList<Component*> components;
QList<QGraphicsItem*> selectedItems = pGraphicsView->scene()->selectedItems();
for (int i = 0 ; i < selectedItems.size() ; i++) {
// check the selected components.
Component *pComponent = dynamic_cast<Component*>(selectedItems.at(i));
if (pComponent && pComponent->getLibraryTreeItem() && pComponent->getLibraryTreeItem()->getOMSConnector()) {
components.append(pComponent);
}
}
AddTLMBusDialog *pAddTLMBusDialog = new AddTLMBusDialog(components, 0, pGraphicsView);
pAddTLMBusDialog->exec();
}
}
Expand Down
18 changes: 18 additions & 0 deletions OMEdit/OMEditGUI/OMS/OMSProxy.cpp
Expand Up @@ -512,6 +512,24 @@ bool OMSProxy::addConnectorToTLMBus(QString busCref, QString connectorCref, QStr
return statusToBool(status);
}

/*!
* \brief OMSProxy::deleteConnectorFromTLMBus
* Deletes a connector from a tlm bus.
* \param busCref
* \param connectorCref
* \return
*/
bool OMSProxy::deleteConnectorFromTLMBus(QString busCref, QString connectorCref)
{
QString command = "oms3_deleteConnectorFromTLMBus";
QStringList args;
args << busCref << connectorCref;
LOG_COMMAND(command, args);
oms_status_enu_t status = oms3_deleteConnectorFromTLMBus(busCref.toStdString().c_str(), connectorCref.toStdString().c_str());
logResponse(command, status, &commandTime);
return statusToBool(status);
}

/*!
* \brief OMSProxy::addSubModel
* Adds the submodel to the system
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/OMS/OMSProxy.h
Expand Up @@ -80,6 +80,7 @@ class OMSProxy : public QObject
bool addTLMBus(QString cref, QString domain, int dimensions, const oms_tlm_interpolation_t interpolation);
bool getTLMBus(QString cref, oms3_tlmbusconnector_t **pTLMBusConnector);
bool addConnectorToTLMBus(QString busCref, QString connectorCref, QString type);
bool deleteConnectorFromTLMBus(QString busCref, QString connectorCref);
bool addSubModel(QString cref, QString fmuPath);
bool getComponentType(QString cref, oms_component_enu_t *pType);

Expand Down
26 changes: 8 additions & 18 deletions OMEdit/OMEditGUI/Resources/icons/tlm-bus-connector.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b2e6536

Please sign in to comment.