Skip to content

Commit

Permalink
Update the Diagram Window to support the dynamic select
Browse files Browse the repository at this point in the history
The variables browser slider can be used for dynamic select now.
Only supports visible and textString attributes right now without expressions.

Belonging to [master]:
  - #157
  • Loading branch information
adeas31 authored and OpenModelica-Hudson committed May 3, 2019
1 parent b38fd64 commit b3569f0
Show file tree
Hide file tree
Showing 22 changed files with 245 additions and 253 deletions.
7 changes: 6 additions & 1 deletion OMEdit/OMEdit/OMEditGUI/Animation/TimeManager.cpp
Expand Up @@ -59,7 +59,12 @@ void TimeManager::updateTick()

int TimeManager::getTimeFraction()
{
return int(_visTime / (_endTime - _startTime)*mTimeDiscretization);
return getTimeFraction(mTimeDiscretization);
}

int TimeManager::getTimeFraction(int discretization)
{
return int(_visTime / (_endTime - _startTime)*discretization);
}

double TimeManager::getEndTime() const
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEdit/OMEditGUI/Animation/TimeManager.h
Expand Up @@ -87,6 +87,7 @@ class TimeManager
/*! \brief Sets pause status to new value. */
void setPause(const bool status);
int getTimeFraction();
int getTimeFraction(int discretization);
void setSpeedUp(double value);
double getSpeedUp();
QTimer* getUpdateSceneTimer() {return mpUpdateSceneTimer;}
Expand Down
8 changes: 6 additions & 2 deletions OMEdit/OMEdit/OMEditGUI/Annotations/BitmapAnnotation.cpp
Expand Up @@ -55,7 +55,6 @@ BitmapAnnotation::BitmapAnnotation(ShapeAnnotation *pShapeAnnotation, Component
: ShapeAnnotation(pParent), mpComponent(pParent)
{
updateShape(pShapeAnnotation);
initUpdateVisible(); // DynamicSelect for visible attribute
setPos(mOrigin);
setRotation(mRotation);
connect(pShapeAnnotation, SIGNAL(updateReferenceShapes()), pShapeAnnotation, SIGNAL(changed()));
Expand Down Expand Up @@ -155,8 +154,13 @@ void BitmapAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *
{
Q_UNUSED(option);
Q_UNUSED(widget);
if (mVisible || !mDynamicVisible.isEmpty())
if (mVisible || !mDynamicVisible.isEmpty()) {
if (!mDynamicVisibleValue && ((mpGraphicsView && mpGraphicsView->isVisualizationView())
|| (mpParentComponent && mpParentComponent->getGraphicsView()->isVisualizationView()))) {
return;
}
drawBitmapAnnotaion(painter);
}
}

void BitmapAnnotation::drawBitmapAnnotaion(QPainter *painter)
Expand Down
5 changes: 4 additions & 1 deletion OMEdit/OMEdit/OMEditGUI/Annotations/EllipseAnnotation.cpp
Expand Up @@ -52,7 +52,6 @@ EllipseAnnotation::EllipseAnnotation(ShapeAnnotation *pShapeAnnotation, Componen
: ShapeAnnotation(pParent)
{
updateShape(pShapeAnnotation);
initUpdateVisible(); // DynamicSelect for visible attribute
setPos(mOrigin);
setRotation(mRotation);
connect(pShapeAnnotation, SIGNAL(updateReferenceShapes()), pShapeAnnotation, SIGNAL(changed()));
Expand Down Expand Up @@ -127,6 +126,10 @@ void EllipseAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem
Q_UNUSED(option);
Q_UNUSED(widget);
if (mVisible || !mDynamicVisible.isEmpty()) {
if (!mDynamicVisibleValue && ((mpGraphicsView && mpGraphicsView->isVisualizationView())
|| (mpParentComponent && mpParentComponent->getGraphicsView()->isVisualizationView()))) {
return;
}
drawEllipseAnnotaion(painter);
}
}
Expand Down
4 changes: 3 additions & 1 deletion OMEdit/OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp
Expand Up @@ -72,7 +72,6 @@ LineAnnotation::LineAnnotation(ShapeAnnotation *pShapeAnnotation, Component *pPa
: ShapeAnnotation(pParent)
{
updateShape(pShapeAnnotation);
initUpdateVisible(); // DynamicSelect for visible attribute
setLineType(LineAnnotation::ComponentType);
setStartComponent(0);
setEndComponent(0);
Expand Down Expand Up @@ -470,6 +469,9 @@ void LineAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
} else {
painter->setOpacity(0.2);
}
} else if (!mDynamicVisibleValue && ((mpGraphicsView && mpGraphicsView->isVisualizationView())
|| (mpParentComponent && mpParentComponent->getGraphicsView()->isVisualizationView()))) {
return;
}
drawLineAnnotaion(painter);
}
Expand Down
5 changes: 4 additions & 1 deletion OMEdit/OMEdit/OMEditGUI/Annotations/PolygonAnnotation.cpp
Expand Up @@ -52,7 +52,6 @@ PolygonAnnotation::PolygonAnnotation(ShapeAnnotation *pShapeAnnotation, Componen
: ShapeAnnotation(pParent)
{
updateShape(pShapeAnnotation);
initUpdateVisible(); // DynamicSelect for visible attribute
setPos(mOrigin);
setRotation(mRotation);
connect(pShapeAnnotation, SIGNAL(updateReferenceShapes()), pShapeAnnotation, SIGNAL(changed()));
Expand Down Expand Up @@ -180,6 +179,10 @@ void PolygonAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem
Q_UNUSED(option);
Q_UNUSED(widget);
if (mVisible || !mDynamicVisible.isEmpty()) {
if (!mDynamicVisibleValue && ((mpGraphicsView && mpGraphicsView->isVisualizationView())
|| (mpParentComponent && mpParentComponent->getGraphicsView()->isVisualizationView()))) {
return;
}
drawPolygonAnnotaion(painter);
}
}
Expand Down
4 changes: 3 additions & 1 deletion OMEdit/OMEdit/OMEditGUI/Annotations/RectangleAnnotation.cpp
Expand Up @@ -52,7 +52,6 @@ RectangleAnnotation::RectangleAnnotation(ShapeAnnotation *pShapeAnnotation, Comp
: ShapeAnnotation(pParent)
{
updateShape(pShapeAnnotation);
initUpdateVisible(); // DynamicSelect for visible attribute
setPos(mOrigin);
setRotation(mRotation);
connect(pShapeAnnotation, SIGNAL(updateReferenceShapes()), pShapeAnnotation, SIGNAL(changed()));
Expand Down Expand Up @@ -167,6 +166,9 @@ void RectangleAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsIte
} else {
painter->setOpacity(0.2);
}
} else if (!mDynamicVisibleValue && ((mpGraphicsView && mpGraphicsView->isVisualizationView())
|| (mpParentComponent && mpParentComponent->getGraphicsView()->isVisualizationView()))) {
return;
}
drawRectangleAnnotaion(painter);
}
Expand Down
132 changes: 80 additions & 52 deletions OMEdit/OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp
Expand Up @@ -49,8 +49,14 @@
void GraphicItem::setDefaults()
{
mVisible = true;
mDynamicVisible = "";
mDynamicVisibleValue = true;
mOrigin = QPointF(0, 0);
mDynamicOrigin = "";
mDynamicOriginValue = QPointF(0, 0);
mRotation = 0;
mDynamicRotation = "";
mDynamicRotationValue = 0;
}

/*!
Expand All @@ -61,9 +67,14 @@ void GraphicItem::setDefaults()
void GraphicItem::setDefaults(ShapeAnnotation *pShapeAnnotation)
{
mVisible = pShapeAnnotation->mVisible;
mDynamicVisible = pShapeAnnotation->mDynamicVisible;
mDynamicVisibleValue = pShapeAnnotation->mDynamicVisibleValue;
mOrigin = pShapeAnnotation->mOrigin;
mDynamicOrigin = pShapeAnnotation->mDynamicOrigin;
mDynamicOriginValue = pShapeAnnotation->mDynamicOriginValue;
mRotation = pShapeAnnotation->mRotation;
mDynamicVisible = pShapeAnnotation->mDynamicVisible;
mDynamicRotation = pShapeAnnotation->mDynamicRotation;
mDynamicRotationValue = pShapeAnnotation->mDynamicRotationValue;
}

/*!
Expand All @@ -77,26 +88,35 @@ void GraphicItem::parseShapeAnnotation(QString annotation)
if (list.size() < 3)
return;
// if first item of list is true then the shape should be visible.
if (list.at(0).startsWith("{")) {
// DynamicSelect
if (list.at(0).startsWith("{")) { // DynamicSelect
QStringList args = StringHandler::getStrings(StringHandler::removeFirstLastCurlBrackets(list.at(0)));
if (args.count() > 0)
if (args.count() > 0) {
mVisible = args.at(0).contains("true");
if (args.count() > 1)
}
if (args.count() > 1) {
mDynamicVisible = args.at(1); // variable name
}
else {
}
} else {
mVisible = list.at(0).contains("true");
}
// 2nd item is the origin
QStringList originList = StringHandler::getStrings(StringHandler::removeFirstLastCurlBrackets(list.at(1)));
if (originList.size() >= 2)
{
if (originList.size() >= 2) {
mOrigin.setX(originList.at(0).toFloat());
mOrigin.setY(originList.at(1).toFloat());
}
// 3rd item is the rotation
mRotation = list.at(2).toFloat();
if (list.at(2).startsWith("{")) { // DynamicSelect
QStringList args = StringHandler::getStrings(StringHandler::removeFirstLastCurlBrackets(list.at(2)));
if (args.count() > 0) {
mRotation = args.at(0).toFloat();
}
if (args.count() > 1) {
mDynamicRotation = args.at(1); // variable name
}
} else {
mRotation = list.at(2).toFloat();
}
}

/*!
Expand Down Expand Up @@ -355,6 +375,7 @@ void ShapeAnnotation::setDefaults()
mFileName = "";
mImageSource = "";
mImage = QImage(":/Resources/icons/bitmap-shape.svg");
mDynamicTextString.clear();
}

/*!
Expand Down Expand Up @@ -790,27 +811,6 @@ QImage ShapeAnnotation::getImage()
return mImage;
}

/*!
Returns a dynamic value or null if no dynamic value exists
*/
QVariant ShapeAnnotation::getDynamicValue(QString name)
{
QVariant dynamicValue; // isNull() per default
if (mpParentComponent) {
ModelWidget *pModelWidget = mpParentComponent->getGraphicsView()->getModelWidget();
if (!pModelWidget->getResultFileName().isEmpty()) {
QString fullName = pModelWidget->getResultFileName() + "." + mpParentComponent->getComponentInfo()->getName() + "." + name;
MainWindow *pMainWindow = MainWindow::instance();
VariablesTreeModel *pVariablesTreeModel = pMainWindow->getVariablesWidget()->getVariablesTreeModel();
VariablesTreeItem *pVariablesTreeItem = pVariablesTreeModel->findVariablesTreeItem(fullName, pVariablesTreeModel->getRootVariablesTreeItem());
if (pVariablesTreeItem != NULL) {
dynamicValue = pVariablesTreeItem->getValue(pVariablesTreeItem->getPreviousUnit(), pVariablesTreeItem->getUnit());
}
}
}
return dynamicValue;
}

/*!
* \brief ShapeAnnotation::applyRotation
* Applies the rotation on the shape and sets the shape transformation matrix accordingly.
Expand Down Expand Up @@ -998,33 +998,61 @@ void ShapeAnnotation::updateShape(ShapeAnnotation *pShapeAnnotation)
}

/*!
* \brief ShapeAnnotation::initUpdateVisible
* Initialize optional DynamicSelect for the visible status
* \brief ShapeAnnotation::updateDynamicSelect
* Updates the shapes according to the DynamicSelect annotation.
* \param time
*/
void ShapeAnnotation::initUpdateVisible()
void ShapeAnnotation::updateDynamicSelect(double time)
{
if (mpParentComponent) {
if (!mDynamicVisible.isEmpty()) {
updateVisible();
connect(mpParentComponent, SIGNAL(displayTextChanged()), SLOT(updateVisible()), Qt::UniqueConnection);
// visible
if (!mDynamicVisible.isEmpty()) {
if (mDynamicVisible.compare("true") == 0) {
mDynamicVisibleValue = true;
} else if (mDynamicVisible.compare("false") == 0) {
mDynamicVisibleValue = false;
} else if (mpParentComponent && mpParentComponent->getComponentInfo()) {
QString variableName = QString("%1.%2").arg(mpParentComponent->getName(), mDynamicVisible);
mDynamicVisibleValue = (bool)MainWindow::instance()->getVariablesWidget()->readVariableValue(variableName, time);
} else {
mDynamicVisibleValue = (bool)MainWindow::instance()->getVariablesWidget()->readVariableValue(mDynamicVisible, time);
}
}
}

/*!
* \brief ShapeAnnotation::updateVisible
* DynamicSelect for the visible status
*/
void ShapeAnnotation::updateVisible()
{
bool visible = mVisible; // model provided default value
if (!mDynamicVisible.isEmpty()) {
QVariant dynamicValue = getDynamicValue(mDynamicVisible);
if (!dynamicValue.isNull()) {
visible = dynamicValue.toBool();
// rotation
if (!mDynamicRotation.isEmpty()) {
bool ok = false;
float rotation = mDynamicRotation.toFloat(&ok);
if (ok) {
mDynamicRotationValue = rotation;
} else if (mpParentComponent && mpParentComponent->getComponentInfo()) {
QString variableName = QString("%1.%2").arg(mpParentComponent->getName(), mDynamicRotation);
mDynamicRotationValue = MainWindow::instance()->getVariablesWidget()->readVariableValue(variableName, time);
} else {
mDynamicRotationValue = MainWindow::instance()->getVariablesWidget()->readVariableValue(mDynamicRotation, time);
}
setRotation(mDynamicRotationValue);
update();
}
// textString
QVariant dynamicTextValue; // isNull() per default
if (mDynamicTextString.count() > 0) {
if (mpParentComponent && mpParentComponent->getComponentInfo()) {
QString variableName = QString("%1.%2").arg(mpParentComponent->getName(), mDynamicTextString.at(0).toString());
dynamicTextValue = MainWindow::instance()->getVariablesWidget()->readVariableValue(variableName, time);
} else {
dynamicTextValue = MainWindow::instance()->getVariablesWidget()->readVariableValue(mDynamicTextString.at(0).toString(), time);
}
}
if (!dynamicTextValue.isNull()) {
mTextString = dynamicTextValue.toString();
if (mTextString.isEmpty()) {
/* use variable name as default value if result not found */
mTextString = mDynamicTextString.at(0).toString();
} else if (mDynamicTextString.count() > 1) {
int digits = mDynamicTextString.at(1).toInt();
mTextString = QString::number(mTextString.toDouble(), 'g', digits);
}
update();
}
setVisible(visible);
}

/*!
Expand Down
11 changes: 7 additions & 4 deletions OMEdit/OMEdit/OMEditGUI/Annotations/ShapeAnnotation.h
Expand Up @@ -68,9 +68,14 @@ class GraphicItem
qreal getRotation() {return mRotation;}
protected:
bool mVisible;
QString mDynamicVisible; /* Dynamic variable for visible attribute */
bool mDynamicVisibleValue; /* Dynamic value for visible attribute */
QPointF mOrigin;
QString mDynamicOrigin; /* Dynamic variable for origin attribute */
QPointF mDynamicOriginValue; /* Dynamic value for origin attribute */
qreal mRotation;
QString mDynamicVisible; /* variable for visible attribute */
QString mDynamicRotation; /* Dynamic variable for origin attribute */
qreal mDynamicRotationValue; /* Dynamic value for origin attribute */
};

class FilledShape
Expand Down Expand Up @@ -177,7 +182,6 @@ class ShapeAnnotation : public QObject, public QGraphicsItem, public GraphicItem
QString getImageSource();
void setImage(QImage image);
QImage getImage();
QVariant getDynamicValue(QString name);
void applyRotation(qreal angle);
void adjustPointsWithOrigin();
void adjustExtentsWithOrigin();
Expand Down Expand Up @@ -233,7 +237,7 @@ public slots:
void referenceShapeAdded();
void referenceShapeChanged();
void referenceShapeDeleted();
void updateVisible();
void updateDynamicSelect(double time);
protected:
GraphicsView *mpGraphicsView;
Component *mpParentComponent;
Expand All @@ -260,7 +264,6 @@ public slots:
QImage mImage;
QList<CornerItem*> mCornerItemsList;
QList<QVariant> mDynamicTextString; /* list of String() arguments */
void initUpdateVisible();
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *pEvent);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
};
Expand Down

0 comments on commit b3569f0

Please sign in to comment.