Skip to content

Commit

Permalink
Merge branch 'adeas31-oms'
Browse files Browse the repository at this point in the history
  • Loading branch information
Adeel Asghar committed Jul 13, 2018
2 parents 0e9c2ff + ebbf3d0 commit 01356ff
Show file tree
Hide file tree
Showing 44 changed files with 4,654 additions and 131 deletions.
113 changes: 113 additions & 0 deletions OMEdit/OMEditGUI/Annotations/BitmapAnnotation.cpp
Expand Up @@ -35,6 +35,8 @@
#include "BitmapAnnotation.h"
#include "Modeling/Commands.h"

#include <QMessageBox>

BitmapAnnotation::BitmapAnnotation(QString classFileName, QString annotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(false, pGraphicsView, 0)
{
Expand Down Expand Up @@ -75,6 +77,38 @@ BitmapAnnotation::BitmapAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsVi
connect(pShapeAnnotation, SIGNAL(deleted()), this, SLOT(referenceShapeDeleted()));
}

/*!
* \brief BitmapAnnotation::BitmapAnnotation
* Used by OMSimulator FMU ModelWidget\n
* We always make this shape as inherited shape since its not allowed to be modified.
* \param classFileName
* \param pGraphicsView
*/
BitmapAnnotation::BitmapAnnotation(QString classFileName, GraphicsView *pGraphicsView)
: ShapeAnnotation(true, pGraphicsView, 0)
{
mpComponent = 0;
mClassFileName = classFileName;
// set the default values
GraphicItem::setDefaults();
ShapeAnnotation::setDefaults();
// set users default value by reading the settings file.
ShapeAnnotation::setUserDefaults();
QList<QPointF> extents;
extents << QPointF(-100, -100) << QPointF(100, 100);
setExtents(extents);
setPos(mOrigin);
setRotation(mRotation);
setShapeFlags(true);

setFileName(mClassFileName);
if (!mFileName.isEmpty()) {
mImage.load(mFileName);
} else {
mImage = QImage(":/Resources/icons/bitmap-shape.svg");
}
}

void BitmapAnnotation::parseShapeAnnotation(QString annotation)
{
GraphicItem::parseShapeAnnotation(annotation);
Expand Down Expand Up @@ -214,3 +248,82 @@ void BitmapAnnotation::duplicate()
setSelected(false);
pBitmapAnnotation->setSelected(true);
}

AddOrEditSubModelIconDialog::AddOrEditSubModelIconDialog(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView, QWidget *pParent)
: QDialog(pParent)
{
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle(QString("%1 - %2 Icon").arg(Helper::applicationName).arg(pShapeAnnotation ? Helper::edit : Helper::add));
setMinimumWidth(400);
mpShapeAnnotation = pShapeAnnotation;
mpGraphicsView = pGraphicsView;
mpFileLabel = new Label(Helper::fileLabel);
mpFileTextBox = new QLineEdit(mpShapeAnnotation ? mpShapeAnnotation->getFileName() : "");
mpFileTextBox->setEnabled(false);
mpBrowseFileButton = new QPushButton(Helper::browse);
connect(mpBrowseFileButton, SIGNAL(clicked()), SLOT(browseImageFile()));
mpPreviewImageLabel = new Label;
mpPreviewImageLabel->setAlignment(Qt::AlignCenter);
if (mpShapeAnnotation) {
mpPreviewImageLabel->setPixmap(QPixmap::fromImage(mpShapeAnnotation->getImage()));
}
mpPreviewImageScrollArea = new QScrollArea;
mpPreviewImageScrollArea->setMinimumSize(400, 150);
mpPreviewImageScrollArea->setWidgetResizable(true);
mpPreviewImageScrollArea->setWidget(mpPreviewImageLabel);
// Create the buttons
mpOkButton = new QPushButton(Helper::ok);
mpOkButton->setAutoDefault(true);
connect(mpOkButton, SIGNAL(clicked()), this, SLOT(addOrEditIcon()));
mpCancelButton = new QPushButton(Helper::cancel);
mpCancelButton->setAutoDefault(false);
connect(mpCancelButton, SIGNAL(clicked()), this, SLOT(reject()));
mpButtonBox = new QDialogButtonBox(Qt::Horizontal);
mpButtonBox->addButton(mpOkButton, QDialogButtonBox::ActionRole);
mpButtonBox->addButton(mpCancelButton, QDialogButtonBox::ActionRole);
// set the layput
QGridLayout *pMainLayout = new QGridLayout;
pMainLayout->addWidget(mpFileLabel, 0, 0);
pMainLayout->addWidget(mpFileTextBox, 0, 1);
pMainLayout->addWidget(mpBrowseFileButton, 0, 2);
pMainLayout->addWidget(mpPreviewImageScrollArea, 1, 0, 1, 3);
pMainLayout->addWidget(mpButtonBox, 2, 0, 1, 3, Qt::AlignRight);
setLayout(pMainLayout);
}

void AddOrEditSubModelIconDialog::browseImageFile()
{
QString imageFileName = StringHandler::getOpenFileName(this, QString(Helper::applicationName).append(" - ").append(Helper::chooseFile),
NULL, Helper::bitmapFileTypes, NULL);
if (imageFileName.isEmpty()) {
return;
}
mpFileTextBox->setText(imageFileName);
QPixmap pixmap;
pixmap.load(imageFileName);
mpPreviewImageLabel->setPixmap(pixmap);
}

void AddOrEditSubModelIconDialog::addOrEditIcon()
{
if (mpShapeAnnotation) { // edit case
if (mpShapeAnnotation->getFileName().compare(mpFileTextBox->text()) != 0) {
QString oldIcon = mpShapeAnnotation->getFileName();
QString newIcon = mpFileTextBox->text();
UpdateSubModelIconCommand *pUpdateSubModelIconCommand = new UpdateSubModelIconCommand(oldIcon, newIcon, mpShapeAnnotation);
mpGraphicsView->getModelWidget()->getUndoStack()->push(pUpdateSubModelIconCommand);
mpGraphicsView->getModelWidget()->updateModelText();
}
} else { // add case
if (mpFileTextBox->text().isEmpty()) {
QMessageBox::critical(this, QString("%1 - %2").arg(Helper::applicationName, Helper::error),
GUIMessages::getMessage(GUIMessages::ENTER_NAME).arg(Helper::fileLabel), Helper::ok);
mpFileTextBox->setFocus();
return;
}
AddSubModelIconCommand *pAddSubModelIconCommand = new AddSubModelIconCommand(mpFileTextBox->text(), mpGraphicsView);
mpGraphicsView->getModelWidget()->getUndoStack()->push(pAddSubModelIconCommand);
mpGraphicsView->getModelWidget()->updateModelText();
}
accept();
}
24 changes: 24 additions & 0 deletions OMEdit/OMEditGUI/Annotations/BitmapAnnotation.h
Expand Up @@ -36,6 +36,7 @@
#define BITMAPANNOTATION_H

#include "ShapeAnnotation.h"
#include "Util/Utilities.h"

class Component;
class BitmapAnnotation : public ShapeAnnotation
Expand All @@ -48,6 +49,8 @@ class BitmapAnnotation : public ShapeAnnotation
BitmapAnnotation(ShapeAnnotation *pShapeAnnotation, Component *pParent);
// Used for icon/diagram inherited shape
BitmapAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView);
// Used for OMSimulator FMU
BitmapAnnotation(QString classFileName, GraphicsView *pGraphicsView);
void parseShapeAnnotation(QString annotation);
QRectF boundingRect() const;
QPainterPath shape() const;
Expand All @@ -62,4 +65,25 @@ public slots:
void duplicate();
};

class AddOrEditSubModelIconDialog : public QDialog
{
Q_OBJECT
public:
AddOrEditSubModelIconDialog(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView, QWidget *pParent = 0);
private:
ShapeAnnotation *mpShapeAnnotation;
GraphicsView *mpGraphicsView;
Label *mpFileLabel;
QLineEdit *mpFileTextBox;
QPushButton *mpBrowseFileButton;
QScrollArea *mpPreviewImageScrollArea;
Label *mpPreviewImageLabel;
QPushButton *mpOkButton;
QPushButton *mpCancelButton;
QDialogButtonBox *mpButtonBox;
public slots:
void browseImageFile();
void addOrEditIcon();
};

#endif // BITMAPANNOTATION_H
37 changes: 37 additions & 0 deletions OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp
Expand Up @@ -1023,6 +1023,41 @@ void LineAnnotation::setAligned(bool aligned)
update();
}

/*!
* \brief LineAnnotation::updateOMSConnection
* Updates the OMSimulator model connection
*/
void LineAnnotation::updateOMSConnection()
{
// connection geometry
ssd_connection_geometry_t* pConnectionGeometry = new ssd_connection_geometry_t;
pConnectionGeometry->n = mPoints.size();
pConnectionGeometry->pointsX = new double[mPoints.size()];
pConnectionGeometry->pointsY = new double[mPoints.size()];
for (int i = 0 ; i < mPoints.size() ; i++) {
pConnectionGeometry->pointsX[i] = mPoints.at(i).x();
pConnectionGeometry->pointsY[i] = mPoints.at(i).y();
}
// connection
oms_connection_t connection;
connection.type = oms_connection_fmi;
connection.parent = new char[mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure().toStdString().size() + 1];
strcpy(connection.parent, mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure().toStdString().c_str());
connection.conA = new char[getStartComponentName().toStdString().size() + 1];
strcpy(connection.conA, getStartComponentName().toStdString().c_str());
connection.conB = new char[getEndComponentName().toStdString().size() + 1];
strcpy(connection.conB, getEndComponentName().toStdString().c_str());
connection.geometry = pConnectionGeometry;
OMSProxy::instance()->updateConnection(mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure(),
getStartComponentName(), getEndComponentName(), &connection);
delete[] connection.parent;
delete[] connection.conA;
delete[] connection.conB;
delete[] pConnectionGeometry->pointsX;
delete[] pConnectionGeometry->pointsY;
delete pConnectionGeometry;
}

QVariant LineAnnotation::itemChange(GraphicsItemChange change, const QVariant &value)
{
ShapeAnnotation::itemChange(change, value);
Expand Down Expand Up @@ -1115,6 +1150,8 @@ void LineAnnotation::updateConnectionAnnotation()
if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType()== LibraryTreeItem::CompositeModel) {
CompositeModelEditor *pCompositeModelEditor = dynamic_cast<CompositeModelEditor*>(mpGraphicsView->getModelWidget()->getEditor());
pCompositeModelEditor->updateConnection(this);
} else if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType()== LibraryTreeItem::OMS) {
updateOMSConnection();
} else {
// get the connection line annotation.
QString annotationString = QString("annotate=").append(getShapeAnnotation());
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Annotations/LineAnnotation.h
Expand Up @@ -128,6 +128,7 @@ class LineAnnotation : public ShapeAnnotation
void setShapeFlags(bool enable);
void updateShape(ShapeAnnotation *pShapeAnnotation);
void setAligned(bool aligned);
void updateOMSConnection();
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value);

Expand Down
25 changes: 25 additions & 0 deletions OMEdit/OMEditGUI/Annotations/RectangleAnnotation.cpp
Expand Up @@ -91,6 +91,31 @@ RectangleAnnotation::RectangleAnnotation(Component *pParent)
setRotation(mRotation);
}

/*!
* \brief RectangleAnnotation::RectangleAnnotation
* Used by OMSimulator FMU ModelWidget\n
* We always make this shape as inherited shape since its not allowed to be modified.
* \param pGraphicsView
*/
RectangleAnnotation::RectangleAnnotation(GraphicsView *pGraphicsView)
: ShapeAnnotation(true, pGraphicsView, 0)
{
// set the default values
GraphicItem::setDefaults();
FilledShape::setDefaults();
ShapeAnnotation::setDefaults();
// create a grey rectangle
setLineColor(QColor(0, 0, 0));
setFillColor(QColor(240, 240, 240));
setFillPattern(StringHandler::FillSolid);
QList<QPointF> extents;
extents << QPointF(-100, -100) << QPointF(100, 100);
setExtents(extents);
setPos(mOrigin);
setRotation(mRotation);
setShapeFlags(true);
}

void RectangleAnnotation::parseShapeAnnotation(QString annotation)
{
GraphicItem::parseShapeAnnotation(annotation);
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Annotations/RectangleAnnotation.h
Expand Up @@ -50,6 +50,8 @@ class RectangleAnnotation : public ShapeAnnotation
RectangleAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView);
// Used for default component
RectangleAnnotation(Component *pParent);
// Used for OMSimulator FMU
RectangleAnnotation(GraphicsView *pGraphicsView);
void parseShapeAnnotation(QString annotation);
QRectF boundingRect() const;
QPainterPath shape() const;
Expand Down
37 changes: 31 additions & 6 deletions OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp
Expand Up @@ -445,6 +445,10 @@ void ShapeAnnotation::createActions()
mpEditTransitionAction = new QAction(Helper::editTransition, mpGraphicsView);
mpEditTransitionAction->setStatusTip(tr("Edits the transition"));
connect(mpEditTransitionAction, SIGNAL(triggered()), SLOT(editTransition()));
// delete submodel icon action
mpDeleteSubModelIconAction = new QAction(QIcon(":/Resources/icons/delete.svg"), tr("Delete SubModel Icon"), mpGraphicsView);
mpDeleteSubModelIconAction->setStatusTip(tr("Deletes the submodel icon"));
connect(mpDeleteSubModelIconAction, SIGNAL(triggered()), SLOT(deleteSubModelIcon()));
}

/*!
Expand Down Expand Up @@ -974,11 +978,13 @@ void ShapeAnnotation::adjustGeometries()
*/
void ShapeAnnotation::setShapeFlags(bool enable)
{
/*
Only set the ItemIsMovable & ItemSendsGeometryChanges flags on shape if the class is not a system library class
AND shape is not an inherited shape.
*/
if (!mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() && !isInheritedShape()) {
/* Only set the ItemIsMovable & ItemSendsGeometryChanges flags on shape if the class is not a system library class
* AND shape is not an inherited shape.
* AND shape is not a OMS connector i.e., input/output signals of fmu.
*/
if (!mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() && !isInheritedShape()
&& !(mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::OMS
&& mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getOMSConnector())) {
setFlag(QGraphicsItem::ItemIsMovable, enable);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, enable);
}
Expand Down Expand Up @@ -1591,6 +1597,16 @@ void ShapeAnnotation::editTransition()
pCreateOrEditTransitionDialog->exec();
}

/*!
* \brief ShapeAnnotation::deleteSubModelIcon
* Slot activated when delete submodel icon option is chosen from context menu of the shape.
*/
void ShapeAnnotation::deleteSubModelIcon()
{
mpGraphicsView->getModelWidget()->getUndoStack()->push(new DeleteSubModelIconCommand(mOriginalFileName, mpGraphicsView));
mpGraphicsView->getModelWidget()->updateModelText();
}

/*!
* \brief ShapeAnnotation::alignInterfaces
* Slot activated when Align Interfaces option is chosen from context menu of the shape.
Expand Down Expand Up @@ -1639,7 +1655,7 @@ void ShapeAnnotation::contextMenuEvent(QGraphicsSceneContextMenuEvent *pEvent)

menu.addSeparator();
menu.addAction(mpGraphicsView->getDeleteAction());
} else {
} else if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType()== LibraryTreeItem::Modelica) {
menu.addAction(mpShapePropertiesAction);
menu.addSeparator();
if (isInheritedShape()) {
Expand Down Expand Up @@ -1676,6 +1692,15 @@ void ShapeAnnotation::contextMenuEvent(QGraphicsSceneContextMenuEvent *pEvent)
menu.addSeparator();
menu.addAction(mpEditTransitionAction);
}
} else if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType()== LibraryTreeItem::OMS) {
BitmapAnnotation *pBitmapAnnotation = dynamic_cast<BitmapAnnotation*>(this);
if (pBitmapAnnotation && mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getOMSElement()
&& (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getOMSElement()->type == oms_component_fmu
|| mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getOMSElement()->type == oms_component_table)) {
menu.addAction(mpDeleteSubModelIconAction);
} else {
return;
}
}
menu.exec(pEvent->screenPos());
}
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Annotations/ShapeAnnotation.h
Expand Up @@ -113,6 +113,7 @@ class ShapeAnnotation : public QObject, public QGraphicsItem, public GraphicItem
QAction *mpAlignInterfacesAction;
QAction *mpShapeAttributesAction;
QAction *mpEditTransitionAction;
QAction *mpDeleteSubModelIconAction;
public:
enum LineGeometryType {VerticalLine, HorizontalLine};
Transformation mTransformation;
Expand Down Expand Up @@ -228,6 +229,7 @@ public slots:
void alignInterfaces();
void showShapeAttributes();
void editTransition();
void deleteSubModelIcon();
void manhattanizeShape(bool addToStack = true);
void referenceShapeAdded();
void referenceShapeChanged();
Expand Down
24 changes: 24 additions & 0 deletions OMEdit/OMEditGUI/Annotations/TextAnnotation.cpp
Expand Up @@ -125,6 +125,30 @@ TextAnnotation::TextAnnotation(QString annotation, LineAnnotation *pLineAnnotati
}
}

/*!
* \brief TextAnnotation::TextAnnotation
* Used by OMSimulator FMU ModelWidget\n
* We always make this shape as inherited shape since its not allowed to be modified.
* \param pGraphicsView
*/
TextAnnotation::TextAnnotation(GraphicsView *pGraphicsView)
: ShapeAnnotation(true, pGraphicsView, 0)
{
mpComponent = 0;
// set the default values
GraphicItem::setDefaults();
FilledShape::setDefaults();
ShapeAnnotation::setDefaults();
// give a reasonable size
mExtents.replace(0, QPointF(-100, 20));
mExtents.replace(1, QPointF(100, -20));
setTextString("%name");
initUpdateTextString();
setPos(mOrigin);
setRotation(mRotation);
setShapeFlags(true);
}

/*!
* \brief TextAnnotation::parseShapeAnnotation
* Parses the text annotation string
Expand Down

0 comments on commit 01356ff

Please sign in to comment.