Skip to content

Commit

Permalink
Merge pull request #46 from rfranke/dynvis
Browse files Browse the repository at this point in the history
Implement DynamicSelect for visible, ticket:3675
  • Loading branch information
adeas31 committed Oct 27, 2016
2 parents f9c1597 + 1b12531 commit 6ab411c
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 33 deletions.
3 changes: 2 additions & 1 deletion OMEdit/OMEditGUI/Annotations/BitmapAnnotation.cpp
Expand Up @@ -53,6 +53,7 @@ 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 @@ -120,7 +121,7 @@ void BitmapAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *
{
Q_UNUSED(option);
Q_UNUSED(widget);
if (mVisible)
if (mVisible || !mDynamicVisible.isEmpty())
drawBitmapAnnotaion(painter);
}

Expand Down
4 changes: 2 additions & 2 deletions OMEdit/OMEditGUI/Annotations/EllipseAnnotation.cpp
Expand Up @@ -52,6 +52,7 @@ 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 @@ -125,8 +126,7 @@ void EllipseAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem
{
Q_UNUSED(option);
Q_UNUSED(widget);
if (mVisible)
{
if (mVisible || !mDynamicVisible.isEmpty()) {
drawEllipseAnnotaion(painter);
}
}
Expand Down
3 changes: 2 additions & 1 deletion OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp
Expand Up @@ -58,6 +58,7 @@ 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 @@ -290,7 +291,7 @@ void LineAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
{
Q_UNUSED(option);
Q_UNUSED(widget);
if (mVisible) {
if (mVisible || !mDynamicVisible.isEmpty()) {
drawLineAnnotaion(painter);
}
}
Expand Down
3 changes: 2 additions & 1 deletion OMEdit/OMEditGUI/Annotations/PolygonAnnotation.cpp
Expand Up @@ -52,6 +52,7 @@ 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 @@ -157,7 +158,7 @@ void PolygonAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem
{
Q_UNUSED(option);
Q_UNUSED(widget);
if (mVisible) {
if (mVisible || !mDynamicVisible.isEmpty()) {
drawPolygonAnnotaion(painter);
}
}
Expand Down
4 changes: 3 additions & 1 deletion OMEdit/OMEditGUI/Annotations/RectangleAnnotation.cpp
Expand Up @@ -52,6 +52,7 @@ 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 @@ -132,8 +133,9 @@ void RectangleAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsIte
{
Q_UNUSED(option);
Q_UNUSED(widget);
if (mVisible)
if (mVisible || !mDynamicVisible.isEmpty()) {
drawRectangleAnnotaion(painter);
}
}

void RectangleAnnotation::drawRectangleAnnotaion(QPainter *painter)
Expand Down
68 changes: 66 additions & 2 deletions OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp
Expand Up @@ -38,6 +38,7 @@
#include "Commands.h"
#include "ComponentProperties.h"
#include "FetchInterfaceDataDialog.h"
#include "VariablesWidget.h"

/*!
* \brief GraphicItem::setDefaults
Expand All @@ -60,6 +61,7 @@ void GraphicItem::setDefaults(ShapeAnnotation *pShapeAnnotation)
mVisible = pShapeAnnotation->mVisible;
mOrigin = pShapeAnnotation->mOrigin;
mRotation = pShapeAnnotation->mRotation;
mDynamicVisible = pShapeAnnotation->mDynamicVisible;
}

/*!
Expand All @@ -73,7 +75,17 @@ void GraphicItem::parseShapeAnnotation(QString annotation)
if (list.size() < 3)
return;
// if first item of list is true then the shape should be visible.
mVisible = list.at(0).contains("true");
if (list.at(0).startsWith("{")) {
// DynamicSelect
QStringList args = StringHandler::getStrings(StringHandler::removeFirstLastCurlBrackets(list.at(0)));
if (args.count() > 0)
mVisible = args.at(0).contains("true");
if (args.count() > 1)
mDynamicVisible = args.at(1); // variable name
}
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)
Expand Down Expand Up @@ -301,6 +313,7 @@ ShapeAnnotation::ShapeAnnotation(bool inheritedShape, GraphicsView *pGraphicsVie
: QGraphicsItem(pParent)
{
mpGraphicsView = pGraphicsView;
mpParentComponent = 0;
mTransformation = Transformation(StringHandler::Diagram);
mIsCustomShape = true;
mIsInheritedShape = inheritedShape;
Expand Down Expand Up @@ -372,7 +385,7 @@ void ShapeAnnotation::setDefaults(ShapeAnnotation *pShapeAnnotation)
mClassFileName = pShapeAnnotation->mClassFileName;
mImageSource = pShapeAnnotation->mImageSource;
mImage = pShapeAnnotation->mImage;
mDynamicSelect = pShapeAnnotation->mDynamicSelect;
mDynamicTextString = pShapeAnnotation->mDynamicTextString;
}

/*!
Expand Down Expand Up @@ -766,6 +779,27 @@ 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 = pModelWidget->getModelWidgetContainer()->getMainWindow();
VariablesTreeModel *pVariablesTreeModel = pMainWindow->getVariablesWidget()->getVariablesTreeModel();
VariablesTreeItem *pVariablesTreeItem = pVariablesTreeModel->findVariablesTreeItem(fullName, pVariablesTreeModel->getRootVariablesTreeItem());
if (pVariablesTreeItem != NULL) {
dynamicValue = pVariablesTreeItem->getValue(pVariablesTreeItem->getUnit(), pMainWindow->getOMCProxy());
}
}
}
return dynamicValue;
}

/*!
* \brief ShapeAnnotation::applyRotation
* Applies the rotation on the shape and sets the shape transformation matrix accordingly.
Expand Down Expand Up @@ -945,6 +979,36 @@ void ShapeAnnotation::updateShape(ShapeAnnotation *pShapeAnnotation)
Q_UNUSED(pShapeAnnotation);
}

/*!
* \brief ShapeAnnotation::initUpdateVisible
* Initialize optional DynamicSelect for the visible status
*/
void ShapeAnnotation::initUpdateVisible()
{
if (mpParentComponent) {
if (!mDynamicVisible.isEmpty()) {
updateVisible();
connect(mpParentComponent, SIGNAL(displayTextChanged()), SLOT(updateVisible()), Qt::UniqueConnection);
}
}
}

/*!
* \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();
}
}
setVisible(visible);
}

/*!
* \brief ShapeAnnotation::manhattanizeShape
* Slot activated when mpManhattanizeShapeAction triggered signal is raised.\n
Expand Down
6 changes: 5 additions & 1 deletion OMEdit/OMEditGUI/Annotations/ShapeAnnotation.h
Expand Up @@ -71,6 +71,7 @@ class GraphicItem
bool mVisible;
QPointF mOrigin;
qreal mRotation;
QString mDynamicVisible; /* variable for visible attribute */
};

class FilledShape
Expand Down Expand Up @@ -176,6 +177,7 @@ 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 @@ -230,6 +232,7 @@ public slots:
void referenceShapeAdded();
void referenceShapeChanged();
void referenceShapeDeleted();
void updateVisible();
protected:
GraphicsView *mpGraphicsView;
Component *mpParentComponent;
Expand All @@ -254,8 +257,9 @@ public slots:
QString mClassFileName; /* Used to find the bitmap relative locations. */
QString mImageSource;
QImage mImage;
QStringList mDynamicSelect; /* list of DynamicSelect arguments */
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
52 changes: 28 additions & 24 deletions OMEdit/OMEditGUI/Annotations/TextAnnotation.cpp
Expand Up @@ -34,7 +34,6 @@

#include "TextAnnotation.h"
#include "Commands.h"
#include "VariablesWidget.h"

/*!
* \class TextAnnotation
Expand Down Expand Up @@ -64,6 +63,7 @@ TextAnnotation::TextAnnotation(ShapeAnnotation *pShapeAnnotation, Component *pPa
: ShapeAnnotation(pParent), mpComponent(pParent)
{
updateShape(pShapeAnnotation);
initUpdateVisible(); // DynamicSelect for visible attribute
initUpdateTextString();
setPos(mOrigin);
setRotation(mRotation);
Expand Down Expand Up @@ -126,9 +126,13 @@ void TextAnnotation::parseShapeAnnotation(QString annotation)
// 10th item of the list contains the textString.
if (list.at(9).startsWith("{")) {
// DynamicSelect
mDynamicSelect = StringHandler::getStrings(StringHandler::removeFirstLastCurlBrackets(list.at(9)));
if (mDynamicSelect.count() >= 1)
mOriginalTextString = StringHandler::removeFirstLastQuotes(mDynamicSelect.at(0));
QStringList args = StringHandler::getStrings(StringHandler::removeFirstLastCurlBrackets(list.at(9)));
if (args.count() > 0)
mOriginalTextString = StringHandler::removeFirstLastQuotes(args.at(0));
if (args.count() > 1)
mDynamicTextString << args.at(1); // variable name
if (args.count() > 2)
mDynamicTextString << args.at(2); // significantDigits
}
else {
mOriginalTextString = StringHandler::removeFirstLastQuotes(list.at(9));
Expand Down Expand Up @@ -217,7 +221,7 @@ void TextAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
} else if (mpComponent && mpComponent->getGraphicsView()->isRenderingLibraryPixmap()) {
return;
}
if (mVisible) {
if (mVisible || !mDynamicVisible.isEmpty()) {
drawTextAnnotaion(painter);
}
}
Expand Down Expand Up @@ -429,7 +433,7 @@ void TextAnnotation::updateShape(ShapeAnnotation *pShapeAnnotation)
void TextAnnotation::initUpdateTextString()
{
if (mpComponent) {
if (mOriginalTextString.contains("%") || mDynamicSelect.count() >= 2) {
if (mOriginalTextString.contains("%") || mDynamicTextString.count() > 0) {
updateTextString();
connect(mpComponent, SIGNAL(displayTextChanged()), SLOT(updateTextString()), Qt::UniqueConnection);
}
Expand Down Expand Up @@ -469,6 +473,24 @@ void TextAnnotation::updateTextStringHelper(QRegExp regExp)
*/
void TextAnnotation::updateTextString()
{
/* optional DynamicSelect of textString attribute */
QVariant dynamicValue; // isNull() per default
if (mDynamicTextString.count() > 0) {
dynamicValue = getDynamicValue(mDynamicTextString.at(0).toString());
}
if (!dynamicValue.isNull()) {
mTextString = dynamicValue.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);
}
return;
}
/* alternatively use model provided value */
/* From Modelica Spec 32revision2,
* There are a number of common macros that can be used in the text, and they should be replaced when displaying
* the text as follows:
Expand All @@ -479,24 +501,6 @@ void TextAnnotation::updateTextString()
* - %name replaced by the name of the component (i.e. the identifier for it in in the enclosing class).
* - %class replaced by the name of the class.
*/
// first check for available results and DynamicSelect
ModelWidget *pModelWidget = mpComponent->getGraphicsView()->getModelWidget();
if (!pModelWidget->getResultFileName().isEmpty() && mDynamicSelect.count() >= 2) {
MainWindow *pMainWindow = pModelWidget->getModelWidgetContainer()->getMainWindow();
VariablesTreeModel *pVariablesTreeModel = pMainWindow->getVariablesWidget()->getVariablesTreeModel();
VariablesTreeItem *pVariablesTreeItem = pVariablesTreeModel->findVariablesTreeItem(pModelWidget->getResultFileName() + "." + mpComponent->getComponentInfo()->getName() + "." + mDynamicSelect.at(1), pVariablesTreeModel->getRootVariablesTreeItem());
if (pVariablesTreeItem != NULL) {
mTextString = pVariablesTreeItem->getValue(pVariablesTreeItem->getUnit(), pMainWindow->getOMCProxy()).toString();
if (mDynamicSelect.count() >= 3) {
int digits = mDynamicSelect.at(2).toInt();
mTextString = QString::number(mTextString.toDouble(), 'g', digits);
}
}
else
mTextString = mDynamicSelect.at(1); // default value if result not found
return;
}
// alternatively use model value
mTextString = mOriginalTextString;
if (!mTextString.contains("%")) {
return;
Expand Down

0 comments on commit 6ab411c

Please sign in to comment.