Skip to content

Commit

Permalink
State machines debugging supports all result file formats
Browse files Browse the repository at this point in the history
Diagram window for visualization
Visualization controls in VariablesWidget
States and transitions are visualized as active or inactive
  • Loading branch information
adeas31 committed Nov 15, 2018
1 parent eb5a8a2 commit 0e17c70
Show file tree
Hide file tree
Showing 26 changed files with 914 additions and 104 deletions.
4 changes: 2 additions & 2 deletions OMEdit/OMEditGUI/Animation/AbstractAnimationWindow.cpp
Expand Up @@ -77,7 +77,7 @@ AbstractAnimationWindow::AbstractAnimationWindow(QWidget *pParent)
mCameraInitialized(false)
{
// to distinguish this widget as a subwindow among the plotwindows
setObjectName(QString("animationWidget"));
setObjectName(QString("animationWindow"));
//the viewer widget
mpViewerWidget = new ViewerWidget(this);
// we need to set the minimum height so that visualization window is still shown when we cascade windows.
Expand Down Expand Up @@ -190,7 +190,7 @@ void AbstractAnimationWindow::createActions()
mpAnimationSpeedLabel->setText(tr("Speed:"));
mpSpeedComboBox = new QComboBox;
mpSpeedComboBox->setEditable(true);
mpSpeedComboBox->addItems(QStringList() << "10" << "5" << "2" << "1" << "0.5" << "0.2" << "0.1");
mpSpeedComboBox->addItems(Helper::speedOptions.split(","));
mpSpeedComboBox->setCurrentIndex(3);
mpSpeedComboBox->setMaximumSize(QSize(toolbarIconSize*2, toolbarIconSize));
mpSpeedComboBox->setEnabled(false);
Expand Down
43 changes: 42 additions & 1 deletion OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp
Expand Up @@ -58,6 +58,7 @@ LineAnnotation::LineAnnotation(QString annotation, GraphicsView *pGraphicsView)
setZfr("");
setAlpha("");
setOMSConnectionType(oms3_connection_single);
setActiveState(false);
// set the default values
GraphicItem::setDefaults();
ShapeAnnotation::setDefaults();
Expand Down Expand Up @@ -87,6 +88,7 @@ LineAnnotation::LineAnnotation(ShapeAnnotation *pShapeAnnotation, Component *pPa
setZfr("");
setAlpha("");
setOMSConnectionType(oms3_connection_single);
setActiveState(false);
setPos(mOrigin);
setRotation(mRotation);
connect(pShapeAnnotation, SIGNAL(updateReferenceShapes()), pShapeAnnotation, SIGNAL(changed()));
Expand Down Expand Up @@ -125,6 +127,7 @@ LineAnnotation::LineAnnotation(LineAnnotation::LineType lineType, Component *pSt
setSynchronize(false);
setPriority(1);
setOMSConnectionType(oms3_connection_single);
setActiveState(false);
if (mLineType == LineAnnotation::ConnectionType) {
/* Use the linecolor of the first shape from icon layer of start component for the connection line.
* Or use black color if there is no shape in the icon layer
Expand Down Expand Up @@ -210,6 +213,7 @@ LineAnnotation::LineAnnotation(QString annotation, Component *pStartComponent, C
setZfr("");
setAlpha("");
setOMSConnectionType(oms3_connection_single);
setActiveState(false);
parseShapeAnnotation(annotation);
/* make the points relative to origin */
QList<QPointF> points;
Expand Down Expand Up @@ -248,6 +252,7 @@ LineAnnotation::LineAnnotation(QString annotation, QString text, Component *pSta
setZfr("");
setAlpha("");
setOMSConnectionType(oms3_connection_single);
setActiveState(false);
parseShapeAnnotation(annotation);
/* make the points relative to origin */
QList<QPointF> points;
Expand Down Expand Up @@ -287,6 +292,7 @@ LineAnnotation::LineAnnotation(QString annotation, Component *pComponent, Graphi
setZfr("");
setAlpha("");
setOMSConnectionType(oms3_connection_single);
setActiveState(false);
parseShapeAnnotation(annotation);
/* make the points relative to origin */
QList<QPointF> points;
Expand Down Expand Up @@ -318,6 +324,7 @@ LineAnnotation::LineAnnotation(Component *pParent)
setZfr("");
setAlpha("");
setOMSConnectionType(oms3_connection_single);
setActiveState(false);
// set the default values
GraphicItem::setDefaults();
ShapeAnnotation::setDefaults();
Expand Down Expand Up @@ -354,6 +361,7 @@ LineAnnotation::LineAnnotation(GraphicsView *pGraphicsView)
setZfr("");
setAlpha("");
setOMSConnectionType(oms3_connection_single);
setActiveState(false);
// set the default values
GraphicItem::setDefaults();
ShapeAnnotation::setDefaults();
Expand Down Expand Up @@ -467,6 +475,13 @@ void LineAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
Q_UNUSED(option);
Q_UNUSED(widget);
if (mVisible || !mDynamicVisible.isEmpty()) {
if (mLineType == LineAnnotation::TransitionType && mpGraphicsView->isVisualizationView()) {
if (isActiveState()) {
painter->setOpacity(1.0);
} else {
painter->setOpacity(0.2);
}
}
drawLineAnnotaion(painter);
}
}
Expand Down Expand Up @@ -1019,20 +1034,27 @@ void LineAnnotation::updateShape(ShapeAnnotation *pShapeAnnotation)
setReset(pLineAnnotation->getReset());
setSynchronize(pLineAnnotation->getSynchronize());
setPriority(pLineAnnotation->getPriority());
mpTextAnnotation = pLineAnnotation->getTextAnnotation();
if (pLineAnnotation->getTextAnnotation()) {
mpTextAnnotation = new TextAnnotation("", this);
mpTextAnnotation->updateShape(pLineAnnotation->getTextAnnotation());
} else {
mpTextAnnotation = 0;
}
setOldAnnotation(pLineAnnotation->getOldAnnotation());
setDelay(pLineAnnotation->getDelay());
setZf(pLineAnnotation->getZf());
setZfr(pLineAnnotation->getZfr());
setAlpha(pLineAnnotation->getAlpha());
setOMSConnectionType(pLineAnnotation->getOMSConnectionType());
setActiveState(pLineAnnotation->isActiveState());
// set the default values
GraphicItem::setDefaults(pShapeAnnotation);
mPoints.clear();
QList<QPointF> points = pShapeAnnotation->getPoints();
for (int i = 0 ; i < points.size() ; i++) {
addPoint(points[i]);
}
updateTransitionTextPosition();
ShapeAnnotation::setDefaults(pShapeAnnotation);
}

Expand Down Expand Up @@ -1093,6 +1115,22 @@ void LineAnnotation::showOMSConnection()
}
}

void LineAnnotation::updateToolTip()
{
if (mLineType == LineAnnotation::ConnectionType) {
setToolTip(QString("<b>connect</b>(%1, %2)").arg(getStartComponentName()).arg(getEndComponentName()));
} else if (mLineType == LineAnnotation::TransitionType) {
setToolTip(QString("<b>transition</b>(%1, %2, %3, %4, %5, %6, %7)")
.arg(getStartComponentName())
.arg(getEndComponentName())
.arg(getCondition())
.arg(getImmediate() ? "true" : "false")
.arg(getReset() ? "true" : "false")
.arg(getSynchronize() ? "true" : "false")
.arg(getPriority()));
}
}

QVariant LineAnnotation::itemChange(GraphicsItemChange change, const QVariant &value)
{
ShapeAnnotation::itemChange(change, value);
Expand Down Expand Up @@ -2076,6 +2114,9 @@ CreateOrEditTransitionDialog::CreateOrEditTransitionDialog(GraphicsView *pGraphi
// Create the buttons
mpOkButton = new QPushButton(Helper::ok);
mpOkButton->setAutoDefault(true);
if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() || mpGraphicsView->isVisualizationView()) {
mpOkButton->setDisabled(true);
}
connect(mpOkButton, SIGNAL(clicked()), SLOT(createOrEditTransition()));
mpCancelButton = new QPushButton(Helper::cancel);
mpCancelButton->setAutoDefault(false);
Expand Down
8 changes: 6 additions & 2 deletions OMEdit/OMEditGUI/Annotations/LineAnnotation.h
Expand Up @@ -126,12 +126,15 @@ class LineAnnotation : public ShapeAnnotation
QString getZfr() {return mZfr;}
void setAlpha(QString alpha) {mAlpha = alpha;}
QString getAlpha() {return mAlpha;}
void setOMSConnectionType(oms3_connection_type_enu_t connectionType) {mOMSConnectionType = connectionType;}
oms3_connection_type_enu_t getOMSConnectionType() {return mOMSConnectionType;}
void setActiveState(bool activeState) {mActiveState = activeState;}
bool isActiveState() {return mActiveState;}
void setShapeFlags(bool enable);
void updateShape(ShapeAnnotation *pShapeAnnotation);
void setAligned(bool aligned);
void updateOMSConnection();
void setOMSConnectionType(oms3_connection_type_enu_t connectionType) {mOMSConnectionType = connectionType;}
oms3_connection_type_enu_t getOMSConnectionType() {return mOMSConnectionType;}
void updateToolTip();
void showOMSConnection();
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
Expand All @@ -156,6 +159,7 @@ class LineAnnotation : public ShapeAnnotation
QString mZfr;
QString mAlpha;
oms3_connection_type_enu_t mOMSConnectionType;
bool mActiveState;
public slots:
void handleComponentMoved();
void updateConnectionAnnotation();
Expand Down
9 changes: 9 additions & 0 deletions OMEdit/OMEditGUI/Annotations/RectangleAnnotation.cpp
Expand Up @@ -159,6 +159,15 @@ void RectangleAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsIte
Q_UNUSED(option);
Q_UNUSED(widget);
if (mVisible || !mDynamicVisible.isEmpty()) {
// state machine visualization
if (mpParentComponent && mpParentComponent->getLibraryTreeItem() && mpParentComponent->getLibraryTreeItem()->isState()
&& mpParentComponent->getGraphicsView()->isVisualizationView()) {
if (mpParentComponent->isActiveState()) {
painter->setOpacity(1.0);
} else {
painter->setOpacity(0.2);
}
}
drawRectangleAnnotaion(painter);
}
}
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp
Expand Up @@ -381,6 +381,7 @@ void ShapeAnnotation::setDefaults(ShapeAnnotation *pShapeAnnotation)
mTextString = pShapeAnnotation->mTextString;
mFontSize = pShapeAnnotation->mFontSize;
mFontName = pShapeAnnotation->mFontName;
mTextStyles = pShapeAnnotation->mTextStyles;
mHorizontalAlignment = pShapeAnnotation->mHorizontalAlignment;
mOriginalFileName = mOriginalFileName;
mFileName = pShapeAnnotation->mFileName;
Expand Down
20 changes: 20 additions & 0 deletions OMEdit/OMEditGUI/Annotations/TextAnnotation.cpp
Expand Up @@ -269,6 +269,26 @@ void TextAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
return;
}
if (mVisible || !mDynamicVisible.isEmpty()) {
// state machine visualization
// text annotation on a component
if (mpComponent && mpComponent->getLibraryTreeItem() && mpComponent->getLibraryTreeItem()->isState()
&& mpComponent->getGraphicsView()->isVisualizationView()) {
if (mpComponent->isActiveState()) {
painter->setOpacity(1.0);
} else {
painter->setOpacity(0.2);
}
}
// text annotation on a transition
LineAnnotation *pTransitionLineAnnotation = dynamic_cast<LineAnnotation*>(parentItem());
if (pTransitionLineAnnotation && pTransitionLineAnnotation->getLineType() == LineAnnotation::TransitionType
&& pTransitionLineAnnotation->getGraphicsView() && pTransitionLineAnnotation->getGraphicsView()->isVisualizationView()) {
if (pTransitionLineAnnotation->isActiveState()) {
painter->setOpacity(1.0);
} else {
painter->setOpacity(0.2);
}
}
drawTextAnnotaion(painter);
}
}
Expand Down
36 changes: 29 additions & 7 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -38,6 +38,7 @@
#include "FMUProperties.h"
#include "Modeling/Commands.h"
#include "Modeling/DocumentationWidget.h"
#include "Plotting/VariablesWidget.h"
#include "Modeling/BusDialog.h"

#include <QMessageBox>
Expand Down Expand Up @@ -460,6 +461,7 @@ Component::Component(QString name, LibraryTreeItem *pLibraryTreeItem, QString an
createStateComponent();
mHasTransition = false;
mIsInitialState = false;
mActiveState = false;
mpBusComponent = 0;
if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::CompositeModel) {
mpDefaultComponentRectangle->setVisible(true);
Expand Down Expand Up @@ -532,6 +534,7 @@ Component::Component(LibraryTreeItem *pLibraryTreeItem, Component *pParentCompon
mpStateComponentRectangle = 0;
mHasTransition = false;
mIsInitialState = false;
mActiveState = false;
mpBusComponent = 0;
drawInheritedComponentsAndShapes();
setDialogAnnotation(QStringList());
Expand Down Expand Up @@ -567,6 +570,7 @@ Component::Component(Component *pComponent, Component *pParentComponent, Compone
mpStateComponentRectangle = 0;
mHasTransition = false;
mIsInitialState = false;
mActiveState = false;
mpBusComponent = mpReferenceComponent->getBusComponent();
drawInheritedComponentsAndShapes();
mTransformation = Transformation(mpReferenceComponent->mTransformation);
Expand Down Expand Up @@ -616,8 +620,9 @@ Component::Component(Component *pComponent, GraphicsView *pGraphicsView)
createNonExistingComponent();
createDefaultComponent();
createStateComponent();
mHasTransition = false;
mIsInitialState = false;
mHasTransition = mpReferenceComponent->hasTransition();;
mIsInitialState = mpReferenceComponent->isInitialState();
mActiveState = false;
mpBusComponent = 0;
drawComponent();
mTransformation = Transformation(mpReferenceComponent->mTransformation);
Expand Down Expand Up @@ -663,6 +668,7 @@ Component::Component(ComponentInfo *pComponentInfo, Component *pParentComponent)
mpStateComponentRectangle = 0;
mHasTransition = false;
mIsInitialState = false;
mActiveState = false;
mpBusComponent = 0;

if (mpComponentInfo->getTLMCausality() == StringHandler::getTLMCausality(StringHandler::TLMBidirectional)) {
Expand Down Expand Up @@ -1347,17 +1353,15 @@ void Component::renameComponentInConnections(QString newName)
QString startComponentName = pConnectionLineAnnotation->getStartComponentName();
startComponentName.replace(getName(), newName);
pConnectionLineAnnotation->setStartComponentName(startComponentName);
pConnectionLineAnnotation->setToolTip(QString("<b>connect</b>(%1, %2)").arg(pConnectionLineAnnotation->getStartComponentName())
.arg(pConnectionLineAnnotation->getEndComponentName()));
pConnectionLineAnnotation->updateToolTip();
}
// update end component name
Component *pEndComponent = pConnectionLineAnnotation->getEndComponent();
if (pEndComponent->getRootParentComponent() == this) {
QString endComponentName = pConnectionLineAnnotation->getEndComponentName();
endComponentName.replace(getName(), newName);
pConnectionLineAnnotation->setEndComponentName(endComponentName);
pConnectionLineAnnotation->setToolTip(QString("<b>connect</b>(%1, %2)").arg(pConnectionLineAnnotation->getStartComponentName())
.arg(pConnectionLineAnnotation->getEndComponentName()));
pConnectionLineAnnotation->updateToolTip();
}
}
}
Expand Down Expand Up @@ -2108,7 +2112,7 @@ void Component::updateToolTip()
comment.replace("src=\"file://", "src=\"");
#endif

if ((mIsInheritedComponent || mComponentType == Component::Port) && mpReferenceComponent) {
if ((mIsInheritedComponent || mComponentType == Component::Port) && mpReferenceComponent && !mpGraphicsView->isVisualizationView()) {
setToolTip(tr("<b>%1</b> %2<br/>%3<br /><br />Component declared in %4").arg(mpComponentInfo->getClassName())
.arg(mpComponentInfo->getName()).arg(comment)
.arg(mpReferenceComponent->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getNameStructure()));
Expand Down Expand Up @@ -2909,6 +2913,24 @@ void Component::showFMUPropertiesDialog()
}
}

/*!
* \brief Component::updateDynamicSelect
* Slot activated when updateDynamicSelect SIGNAL is raised by VariablesWidget during the visualization of result file.
* \param time
*/
void Component::updateDynamicSelect(double time)
{
if (mpLibraryTreeItem && mpLibraryTreeItem->isState()) {
double value = MainWindow::instance()->getVariablesWidget()->readVariableValue(getName() + ".active", time);
setActiveState(value);
foreach (LineAnnotation *pTransitionLineAnnotation, mpGraphicsView->getTransitionsList()) {
if (pTransitionLineAnnotation->getEndComponent()->getName().compare(getName()) == 0) {
pTransitionLineAnnotation->setActiveState(value);
}
}
}
}

/*!
* \brief Component::contextMenuEvent
* Reimplementation of contextMenuEvent.\n
Expand Down
6 changes: 6 additions & 0 deletions OMEdit/OMEditGUI/Component/Component.h
Expand Up @@ -226,7 +226,11 @@ class Component : public QObject, public QGraphicsItem
void addConnectionDetails(LineAnnotation *pConnectorLineAnnotation);
void removeConnectionDetails(LineAnnotation *pConnectorLineAnnotation);
void setHasTransition(bool hasTransition);
bool hasTransition() {return mHasTransition;}
void setIsInitialState(bool isInitialState);
bool isInitialState() {return mIsInitialState;}
void setActiveState(bool activeState) {mActiveState = activeState;}
bool isActiveState() {return mActiveState;}
void removeChildren();
void emitAdded();
void emitTransformChange() {emit transformChange();}
Expand Down Expand Up @@ -293,6 +297,7 @@ class Component : public QObject, public QGraphicsItem
QPointF mOldPosition;
bool mHasTransition;
bool mIsInitialState;
bool mActiveState;
Component *mpBusComponent;
void createNonExistingComponent();
void createDefaultComponent();
Expand Down Expand Up @@ -370,6 +375,7 @@ public slots:
void viewDocumentation();
void showSubModelAttributes();
void showFMUPropertiesDialog();
void updateDynamicSelect(double time);
protected:
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Component/ComponentProperties.cpp
Expand Up @@ -776,7 +776,7 @@ void ComponentParameters::setUpDialog()
mpOkButton = new QPushButton(Helper::ok);
mpOkButton->setAutoDefault(true);
connect(mpOkButton, SIGNAL(clicked()), this, SLOT(updateComponentParameters()));
if (mpComponent->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->isSystemLibrary()) {
if (mpComponent->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() || mpComponent->getGraphicsView()->isVisualizationView()) {
mpOkButton->setDisabled(true);
}
mpCancelButton = new QPushButton(Helper::cancel);
Expand Down

0 comments on commit 0e17c70

Please sign in to comment.