Skip to content

Commit

Permalink
State Machines GUI support.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Aug 8, 2017
1 parent 7dd1e00 commit 9f04cba
Show file tree
Hide file tree
Showing 28 changed files with 2,197 additions and 118 deletions.
501 changes: 480 additions & 21 deletions OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp

Large diffs are not rendered by default.

67 changes: 62 additions & 5 deletions OMEdit/OMEditGUI/Annotations/LineAnnotation.h
Expand Up @@ -44,25 +44,34 @@

class Label;
class Component;
class TextAnnotation;

class LineAnnotation : public ShapeAnnotation
{
Q_OBJECT
public:
enum LineType {
ComponentType, /* Line is within Component. */
ConnectionType, /* Line is a connection. */
ShapeType /* Line is a custom shape. */
ComponentType, /* Line is within Component. */
ConnectionType, /* Line is a connection. */
TransitionType, /* Line is a transition. */
InitialStateType, /* Line is an initial state. */
ShapeType /* Line is a custom shape. */
};
// Used for icon/diagram shape
LineAnnotation(QString annotation, GraphicsView *pGraphicsView);
// Used for shape inside a component
LineAnnotation(ShapeAnnotation *pShapeAnnotation, Component *pParent);
// Used for icon/diagram inherited shape
LineAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView);
// Used for creating connection
LineAnnotation(Component *pStartComponent, GraphicsView *pGraphicsView);
// Used for creating connection/transition
LineAnnotation(LineAnnotation::LineType lineType, Component *pStartComponent, GraphicsView *pGraphicsView);
// Used for reading a connection
LineAnnotation(QString annotation, Component *pStartComponent, Component *pEndComponent, GraphicsView *pGraphicsView);
// Used for reading a transition
LineAnnotation(QString annotation, QString text, Component *pStartComponent, Component *pEndComponent, QString condition, QString immediate,
QString reset, QString synchronize, QString priority, GraphicsView *pGraphicsView);
// Used for reading an initial state
LineAnnotation(QString annotation, Component *pComponent, GraphicsView *pGraphicsView);
// Used for non-exisiting component
LineAnnotation(Component *pParent);
// Used for non-existing class
Expand All @@ -74,6 +83,7 @@ class LineAnnotation : public ShapeAnnotation
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
void drawLineAnnotaion(QPainter *painter);
void drawArrow(QPainter *painter, QPointF startPos, QPointF endPos, qreal size, int arrowType) const;
QPolygonF perpendicularLine(QPointF startPos, QPointF endPos, qreal size) const;
QString getOMCShapeAnnotation();
QString getShapeAnnotation();
QString getCompositeModelShapeAnnotation();
Expand All @@ -83,6 +93,7 @@ class LineAnnotation : public ShapeAnnotation
void updateStartPoint(QPointF point);
void updateEndPoint(QPointF point);
void moveAllPoints(qreal offsetX, qreal offsetY);
void updateTransitionTextPosition();
void setLineType(LineType lineType) {mLineType = lineType;}
LineType getLineType() {return mLineType;}
void setStartComponent(Component *pStartComponent) {mpStartComponent = pStartComponent;}
Expand All @@ -93,6 +104,17 @@ class LineAnnotation : public ShapeAnnotation
Component* getEndComponent() {return mpEndComponent;}
void setEndComponentName(QString name) {mEndComponentName = name;}
QString getEndComponentName() {return mEndComponentName;}
void setCondition(QString condition) {mCondition = condition;}
QString getCondition() {return mCondition;}
void setImmediate(bool immediate) {mImmediate = immediate;}
bool getImmediate() {return mImmediate;}
void setReset(bool reset) {mReset = reset;}
bool getReset() {return mReset;}
void setSynchronize(bool synchronize) {mSynchronize = synchronize;}
bool getSynchronize() {return mSynchronize;}
void setPriority(int priority) {mPriority = priority;}
int getPriority() {return mPriority;}
TextAnnotation* getTextAnnotation() {return mpTextAnnotation;}
void setOldAnnotation(QString oldAnnotation) {mOldAnnotation = oldAnnotation;}
QString getOldAnnotation() {return mOldAnnotation;}
void setDelay(QString delay) {mDelay = delay;}
Expand All @@ -115,6 +137,13 @@ class LineAnnotation : public ShapeAnnotation
QString mStartComponentName;
Component *mpEndComponent;
QString mEndComponentName;
QString mCondition;
bool mImmediate;
bool mReset;
bool mSynchronize;
int mPriority;
TextAnnotation *mpTextAnnotation;
// MetaModel attributes
QString mOldAnnotation;
// CompositeModel attributes
QString mDelay;
Expand All @@ -125,6 +154,8 @@ public slots:
void handleComponentMoved();
void updateConnectionAnnotation();
void updateConnectionTransformation(QUndoCommand *pUndoCommand);
void updateTransitionAnnotation(QString oldCondition, bool oldImmediate, bool oldReset, bool oldSynchronize, int oldPriority);
void updateInitialStateAnnotation();
void duplicate();
};

Expand Down Expand Up @@ -251,4 +282,30 @@ public slots:
void createConnection();
};

class CreateOrEditTransitionDialog : public QDialog
{
Q_OBJECT
public:
CreateOrEditTransitionDialog(GraphicsView *pGraphicsView, LineAnnotation *pTransitionLineAnnotation, bool editCase, QWidget *pParent = 0);
private:
GraphicsView *mpGraphicsView;
LineAnnotation *mpTransitionLineAnnotation;
bool mEditCase;
Label *mpHeading;
QFrame *mpHorizontalLine;
QGroupBox *mpPropertiesGroupBox;
Label *mpConditionLabel;
QLineEdit *mpConditionTextBox;
QCheckBox *mpImmediateCheckBox;
QCheckBox *mpResetCheckBox;
QCheckBox *mpSynchronizeCheckBox;
Label *mpPriorityLabel;
QSpinBox *mpPrioritySpinBox;
QPushButton *mpOkButton;
QPushButton *mpCancelButton;
QDialogButtonBox *mpButtonBox;
public slots:
void createOrEditTransition();
};

#endif // LINEANNOTATION_H
92 changes: 57 additions & 35 deletions OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp
Expand Up @@ -442,6 +442,10 @@ void ShapeAnnotation::createActions()
mpShapeAttributesAction = new QAction(Helper::attributes, mpGraphicsView);
mpShapeAttributesAction->setStatusTip(tr("Shows the shape attributes"));
connect(mpShapeAttributesAction, SIGNAL(triggered()), SLOT(showShapeAttributes()));
// edit transition action
mpEditTransitionAction = new QAction(Helper::editTransition, mpGraphicsView);
mpEditTransitionAction->setStatusTip(tr("Edits the transition"));
connect(mpEditTransitionAction, SIGNAL(triggered()), SLOT(editTransition()));
}

/*!
Expand Down Expand Up @@ -620,8 +624,11 @@ void ShapeAnnotation::drawCornerItems()
for (int i = 0 ; i < mPoints.size() ; i++) {
QPointF point = mPoints.at(i);
CornerItem *pCornerItem = new CornerItem(point.x(), point.y(), i, this);
/* if line is a connection then make the first and last point non moveable. */
if ((lineType == LineAnnotation::ConnectionType) && (i == 0 || i == mPoints.size() - 1)) {
/* if line is a connection or transition then make the first and last point non movable.
* if line is initial state then make the first point non movable.
*/
if ((((lineType == LineAnnotation::ConnectionType || lineType == LineAnnotation::TransitionType) && (i == 0 || i == mPoints.size() - 1))
|| (lineType == LineAnnotation::InitialStateType && i == 0))) {
pCornerItem->setFlag(QGraphicsItem::ItemIsMovable, false);
}
mCornerItemsList.append(pCornerItem);
Expand Down Expand Up @@ -914,6 +921,9 @@ void ShapeAnnotation::adjustCornerItemsConnectedIndexes()
void ShapeAnnotation::removeRedundantPointsGeometriesAndCornerItems()
{
for (int i = 0 ; i < mPoints.size() ; i++) {
if (mPoints.size() <= 2) {
break;
}
if ((i+1 < mPoints.size() && mPoints[i].y() == mPoints[i + 1].y() && i+2 < mPoints.size() && mPoints[i + 1].y() == mPoints[i + 2].y()) ||
(i+1 < mPoints.size() && mPoints[i].x() == mPoints[i + 1].x() && i+2 < mPoints.size() && mPoints[i + 1].x() == mPoints[i + 2].x())) {
mPoints.removeAt(i + 1);
Expand Down Expand Up @@ -1012,6 +1022,9 @@ void ShapeAnnotation::updateVisible()
*/
void ShapeAnnotation::manhattanizeShape(bool addToStack)
{
if (mSmooth == StringHandler::SmoothBezier) {
return;
}
QString oldAnnotation = getOMCShapeAnnotation();
int startIndex = -1;
for (int i = 0 ; i < mPoints.size() ; i++) {
Expand Down Expand Up @@ -1128,18 +1141,6 @@ void ShapeAnnotation::referenceShapeDeleted()
}
}

/*!
Slot activated when Delete option is chosen from context menu of the shape.\n
Deletes the connection.
*/
void ShapeAnnotation::deleteConnection()
{
LineAnnotation *pLineAnnotation = dynamic_cast<LineAnnotation*>(this);
if (pLineAnnotation && pLineAnnotation->getLineType() == LineAnnotation::ConnectionType) {
mpGraphicsView->deleteConnection(pLineAnnotation);
}
}

/*!
* \brief ShapeAnnotation::deleteMe
* Deletes the shape. Slot activated when Del key is pressed while the shape is selected.\n
Expand All @@ -1148,7 +1149,16 @@ void ShapeAnnotation::deleteConnection()
void ShapeAnnotation::deleteMe()
{
// delete the shape
mpGraphicsView->deleteShape(this);
LineAnnotation *pLineAnnotation = dynamic_cast<LineAnnotation*>(this);
if (pLineAnnotation && pLineAnnotation->getLineType() == LineAnnotation::ConnectionType) {
mpGraphicsView->deleteConnection(pLineAnnotation);
} else if (pLineAnnotation && pLineAnnotation->getLineType() == LineAnnotation::TransitionType) {
mpGraphicsView->deleteTransition(pLineAnnotation);
} else if (pLineAnnotation && pLineAnnotation->getLineType() == LineAnnotation::InitialStateType) {
mpGraphicsView->deleteInitialState(pLineAnnotation);
} else {
mpGraphicsView->deleteShape(this);
}
}

/*!
Expand Down Expand Up @@ -1560,6 +1570,21 @@ void ShapeAnnotation::showShapeAttributes()
pCompositeModelConnectionAttributes->exec();
}

/*!
* \brief ShapeAnnotation::editTransition
* Slot activated when edit transition option is chosen from context menu of the transition.
*/
void ShapeAnnotation::editTransition()
{
if (!mpGraphicsView) {
return;
}
LineAnnotation *pTransitionLineAnnotation = dynamic_cast<LineAnnotation*>(this);
CreateOrEditTransitionDialog *pCreateOrEditTransitionDialog = new CreateOrEditTransitionDialog(mpGraphicsView, pTransitionLineAnnotation,
true, MainWindow::instance());
pCreateOrEditTransitionDialog->exec();
}

/*!
* \brief ShapeAnnotation::alignInterfaces
* Slot activated when Align Interfaces option is chosen from context menu of the shape.
Expand Down Expand Up @@ -1626,12 +1651,12 @@ void ShapeAnnotation::contextMenuEvent(QGraphicsSceneContextMenuEvent *pEvent)
LineAnnotation::LineType lineType = LineAnnotation::ShapeType;
if (pLineAnnotation) {
lineType = pLineAnnotation->getLineType();
if (lineType != LineAnnotation::ConnectionType) {
if (lineType != LineAnnotation::ConnectionType && lineType != LineAnnotation::TransitionType) {
menu.addAction(mpGraphicsView->getManhattanizeAction());
}
}
menu.addAction(mpGraphicsView->getDeleteAction());
if (lineType != LineAnnotation::ConnectionType) {
if (lineType != LineAnnotation::ConnectionType && lineType != LineAnnotation::TransitionType) {
menu.addAction(mpGraphicsView->getDuplicateAction());
menu.addSeparator();
menu.addAction(mpGraphicsView->getBringToFrontAction());
Expand All @@ -1641,6 +1666,9 @@ void ShapeAnnotation::contextMenuEvent(QGraphicsSceneContextMenuEvent *pEvent)
menu.addSeparator();
menu.addAction(mpGraphicsView->getRotateClockwiseAction());
menu.addAction(mpGraphicsView->getRotateAntiClockwiseAction());
} else if (lineType == LineAnnotation::TransitionType) {
menu.addSeparator();
menu.addAction(mpEditTransitionAction);
}
}
menu.exec(pEvent->screenPos());
Expand All @@ -1667,22 +1695,19 @@ QVariant ShapeAnnotation::itemChange(GraphicsItemChange change, const QVariant &
setCursor(Qt::SizeAllCursor);
/* Only allow manipulations on shapes if the class is not a system library class OR shape is not an inherited component. */
if (!mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() && !isInheritedShape()) {
if (lineType == LineAnnotation::ConnectionType) {
connect(mpGraphicsView, SIGNAL(mouseDelete()), SLOT(deleteConnection()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(keyPressDelete()), SLOT(deleteConnection()), Qt::UniqueConnection);
} else {
if (pLineAnnotation) {
connect(mpGraphicsView, SIGNAL(mouseManhattanize()), this, SLOT(manhattanizeShape()), Qt::UniqueConnection);
}
connect(mpGraphicsView, SIGNAL(mouseDelete()), this, SLOT(deleteMe()), Qt::UniqueConnection);
if (pLineAnnotation) {
connect(mpGraphicsView, SIGNAL(mouseManhattanize()), this, SLOT(manhattanizeShape()), Qt::UniqueConnection);
}
connect(mpGraphicsView, SIGNAL(mouseDelete()), this, SLOT(deleteMe()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(keyPressDelete()), this, SLOT(deleteMe()), Qt::UniqueConnection);
if (lineType == LineAnnotation::ShapeType) {
connect(mpGraphicsView, SIGNAL(mouseDuplicate()), this, SLOT(duplicate()), Qt::UniqueConnection);
connect(mpGraphicsView->getBringToFrontAction(), SIGNAL(triggered()), this, SLOT(bringToFront()), Qt::UniqueConnection);
connect(mpGraphicsView->getBringForwardAction(), SIGNAL(triggered()), this, SLOT(bringForward()), Qt::UniqueConnection);
connect(mpGraphicsView->getSendToBackAction(), SIGNAL(triggered()), this, SLOT(sendToBack()), Qt::UniqueConnection);
connect(mpGraphicsView->getSendBackwardAction(), SIGNAL(triggered()), this, SLOT(sendBackward()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(mouseRotateClockwise()), this, SLOT(rotateClockwise()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(mouseRotateAntiClockwise()), this, SLOT(rotateAntiClockwise()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(keyPressDelete()), this, SLOT(deleteMe()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(keyPressDuplicate()), this, SLOT(duplicate()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(keyPressRotateClockwise()), this, SLOT(rotateClockwise()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(keyPressRotateAntiClockwise()), this, SLOT(rotateAntiClockwise()), Qt::UniqueConnection);
Expand All @@ -1705,22 +1730,19 @@ QVariant ShapeAnnotation::itemChange(GraphicsItemChange change, const QVariant &
unsetCursor();
/* Only allow manipulations on shapes if the class is not a system library class OR shape is not an inherited component. */
if (!mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() && !isInheritedShape()) {
if (lineType == LineAnnotation::ConnectionType) {
disconnect(mpGraphicsView, SIGNAL(mouseDelete()), this, SLOT(deleteConnection()));
disconnect(mpGraphicsView, SIGNAL(keyPressDelete()), this, SLOT(deleteConnection()));
} else {
if (pLineAnnotation) {
disconnect(mpGraphicsView, SIGNAL(mouseManhattanize()), this, SLOT(manhattanizeShape()));
}
disconnect(mpGraphicsView, SIGNAL(mouseDelete()), this, SLOT(deleteMe()));
if (pLineAnnotation) {
disconnect(mpGraphicsView, SIGNAL(mouseManhattanize()), this, SLOT(manhattanizeShape()));
}
disconnect(mpGraphicsView, SIGNAL(mouseDelete()), this, SLOT(deleteMe()));
disconnect(mpGraphicsView, SIGNAL(keyPressDelete()), this, SLOT(deleteMe()));
if (lineType == LineAnnotation::ShapeType) {
disconnect(mpGraphicsView, SIGNAL(mouseDuplicate()), this, SLOT(duplicate()));
disconnect(mpGraphicsView->getBringToFrontAction(), SIGNAL(triggered()), this, SLOT(bringToFront()));
disconnect(mpGraphicsView->getBringForwardAction(), SIGNAL(triggered()), this, SLOT(bringForward()));
disconnect(mpGraphicsView->getSendToBackAction(), SIGNAL(triggered()), this, SLOT(sendToBack()));
disconnect(mpGraphicsView->getSendBackwardAction(), SIGNAL(triggered()), this, SLOT(sendBackward()));
disconnect(mpGraphicsView, SIGNAL(mouseRotateClockwise()), this, SLOT(rotateClockwise()));
disconnect(mpGraphicsView, SIGNAL(mouseRotateAntiClockwise()), this, SLOT(rotateAntiClockwise()));
disconnect(mpGraphicsView, SIGNAL(keyPressDelete()), this, SLOT(deleteMe()));
disconnect(mpGraphicsView, SIGNAL(keyPressDuplicate()), this, SLOT(duplicate()));
disconnect(mpGraphicsView, SIGNAL(keyPressRotateClockwise()), this, SLOT(rotateClockwise()));
disconnect(mpGraphicsView, SIGNAL(keyPressRotateAntiClockwise()), this, SLOT(rotateAntiClockwise()));
Expand Down
3 changes: 2 additions & 1 deletion OMEdit/OMEditGUI/Annotations/ShapeAnnotation.h
Expand Up @@ -112,6 +112,7 @@ class ShapeAnnotation : public QObject, public QGraphicsItem, public GraphicItem
QAction *mpShapePropertiesAction;
QAction *mpAlignInterfacesAction;
QAction *mpShapeAttributesAction;
QAction *mpEditTransitionAction;
public:
enum LineGeometryType {VerticalLine, HorizontalLine};
Transformation mTransformation;
Expand Down Expand Up @@ -198,7 +199,6 @@ class ShapeAnnotation : public QObject, public QGraphicsItem, public GraphicItem
void changed();
void deleted();
public slots:
void deleteConnection();
void deleteMe();
virtual void duplicate();
void bringToFront();
Expand Down Expand Up @@ -227,6 +227,7 @@ public slots:
void showShapeProperties();
void alignInterfaces();
void showShapeAttributes();
void editTransition();
void manhattanizeShape(bool addToStack = true);
void referenceShapeAdded();
void referenceShapeChanged();
Expand Down

0 comments on commit 9f04cba

Please sign in to comment.