Skip to content

Commit

Permalink
Fixes ticket:5816
Browse files Browse the repository at this point in the history
Read the coordinate system from the model.
If its not complete then read from the first base class. Use the merged coordinate system everywhere.
Otherwise use the default values.

Fixes ticket:5878 rendering of bitmap shape
Fixes ticket:5879 Added origin marker for graphical primitive shapes
  • Loading branch information
adeas31 committed Apr 3, 2020
1 parent 45c31e9 commit 58c7a53
Show file tree
Hide file tree
Showing 38 changed files with 1,878 additions and 1,320 deletions.
10 changes: 5 additions & 5 deletions OMCompiler/Compiler/FrontEnd/Constants.mo
Expand Up @@ -181,22 +181,22 @@ end GraphicItem;
record CoordinateSystem
Real extent[2,2]/*(each final unit=\"mm\")*/;
Boolean preserveAspectRatio=true;
Real initialScale = 0.1;
Real grid[2]/*(each final unit=\"mm\")*/ = {2.0, 2.0};
Boolean preserveAspectRatio;
Real initialScale;
Real grid[2]/*(each final unit=\"mm\")*/;
end CoordinateSystem;
// example
// CoordinateSystem(extent = {{-10, -10}, {10, 10}});
// i.e. a coordinate system with width 20 units and height 20 units.
record Icon \"Representation of the icon layer\"
CoordinateSystem coordinateSystem(extent = {{-100, -100}, {100, 100}});
CoordinateSystem coordinateSystem;
//GraphicItem[:] graphics;
end Icon;
record Diagram \"Representation of the diagram layer\"
CoordinateSystem coordinateSystem(extent = {{-100, -100}, {100, 100}});
CoordinateSystem coordinateSystem;
//GraphicItem[:] graphics;
end Diagram;
Expand Down
21 changes: 13 additions & 8 deletions OMEdit/OMEditLIB/Annotations/BitmapAnnotation.cpp
Expand Up @@ -41,7 +41,8 @@
BitmapAnnotation::BitmapAnnotation(QString classFileName, QString annotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(false, pGraphicsView, 0, 0)
{
mpComponent = 0;
mpOriginItem = new OriginItem(this);
mpOriginItem->setPassive();
mClassFileName = classFileName;
// set the default values
GraphicItem::setDefaults();
Expand All @@ -53,8 +54,9 @@ BitmapAnnotation::BitmapAnnotation(QString classFileName, QString annotation, Gr
}

BitmapAnnotation::BitmapAnnotation(ShapeAnnotation *pShapeAnnotation, Component *pParent)
: ShapeAnnotation(pShapeAnnotation, pParent), mpComponent(pParent)
: ShapeAnnotation(pShapeAnnotation, pParent)
{
mpOriginItem = 0;
updateShape(pShapeAnnotation);
setPos(mOrigin);
setRotation(mRotation);
Expand All @@ -63,10 +65,12 @@ BitmapAnnotation::BitmapAnnotation(ShapeAnnotation *pShapeAnnotation, Component
BitmapAnnotation::BitmapAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(true, pGraphicsView, pShapeAnnotation, 0)
{
mpComponent = 0;
mpOriginItem = new OriginItem(this);
mpOriginItem->setPassive();
updateShape(pShapeAnnotation);
setShapeFlags(true);
mpGraphicsView->addItem(this);
mpGraphicsView->addItem(mpOriginItem);
}

/*!
Expand All @@ -79,7 +83,8 @@ BitmapAnnotation::BitmapAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsVi
BitmapAnnotation::BitmapAnnotation(QString classFileName, GraphicsView *pGraphicsView)
: ShapeAnnotation(true, pGraphicsView, 0, 0)
{
mpComponent = 0;
mpOriginItem = new OriginItem(this);
mpOriginItem->setPassive();
mClassFileName = classFileName;
// set the default values
GraphicItem::setDefaults();
Expand Down Expand Up @@ -158,7 +163,7 @@ void BitmapAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *

void BitmapAnnotation::drawBitmapAnnotaion(QPainter *painter)
{
painter->drawImage(getBoundingRect(), mImage.mirrored());
painter->drawImage(getBoundingRect().normalized(), mImage.mirrored());
}

/*!
Expand Down Expand Up @@ -243,12 +248,12 @@ void BitmapAnnotation::duplicate()
{
BitmapAnnotation *pBitmapAnnotation = new BitmapAnnotation(mClassFileName, "", mpGraphicsView);
pBitmapAnnotation->updateShape(this);
QPointF gridStep(mpGraphicsView->mCoOrdinateSystem.getHorizontalGridStep() * 5,
mpGraphicsView->mCoOrdinateSystem.getVerticalGridStep() * 5);
QPointF gridStep(mpGraphicsView->mMergedCoOrdinateSystem.getHorizontalGridStep() * 5,
mpGraphicsView->mMergedCoOrdinateSystem.getVerticalGridStep() * 5);
pBitmapAnnotation->setOrigin(mOrigin + gridStep);
pBitmapAnnotation->initializeTransformation();
pBitmapAnnotation->drawCornerItems();
pBitmapAnnotation->setCornerItemsActiveOrPassive();
pBitmapAnnotation->applyTransformation();
pBitmapAnnotation->update();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pBitmapAnnotation));
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pBitmapAnnotation, mpGraphicsView);
Expand Down
2 changes: 0 additions & 2 deletions OMEdit/OMEditLIB/Annotations/BitmapAnnotation.h
Expand Up @@ -60,8 +60,6 @@ class BitmapAnnotation : public ShapeAnnotation
QString getOMCShapeAnnotationWithShapeName() override;
QString getShapeAnnotation() override;
void updateShape(ShapeAnnotation *pShapeAnnotation) override;
private:
Component *mpComponent;
public slots:
void duplicate() override;
};
Expand Down
12 changes: 9 additions & 3 deletions OMEdit/OMEditLIB/Annotations/EllipseAnnotation.cpp
Expand Up @@ -38,6 +38,8 @@
EllipseAnnotation::EllipseAnnotation(QString annotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(false, pGraphicsView, 0, 0)
{
mpOriginItem = new OriginItem(this);
mpOriginItem->setPassive();
// set the default values
GraphicItem::setDefaults();
FilledShape::setDefaults();
Expand All @@ -51,6 +53,7 @@ EllipseAnnotation::EllipseAnnotation(QString annotation, GraphicsView *pGraphics
EllipseAnnotation::EllipseAnnotation(ShapeAnnotation *pShapeAnnotation, Component *pParent)
: ShapeAnnotation(pShapeAnnotation, pParent)
{
mpOriginItem = 0;
updateShape(pShapeAnnotation);
setPos(mOrigin);
setRotation(mRotation);
Expand All @@ -59,9 +62,12 @@ EllipseAnnotation::EllipseAnnotation(ShapeAnnotation *pShapeAnnotation, Componen
EllipseAnnotation::EllipseAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(true, pGraphicsView, pShapeAnnotation, 0)
{
mpOriginItem = new OriginItem(this);
mpOriginItem->setPassive();
updateShape(pShapeAnnotation);
setShapeFlags(true);
mpGraphicsView->addItem(this);
mpGraphicsView->addItem(mpOriginItem);
}

void EllipseAnnotation::parseShapeAnnotation(QString annotation)
Expand Down Expand Up @@ -229,12 +235,12 @@ void EllipseAnnotation::duplicate()
{
EllipseAnnotation *pEllipseAnnotation = new EllipseAnnotation("", mpGraphicsView);
pEllipseAnnotation->updateShape(this);
QPointF gridStep(mpGraphicsView->mCoOrdinateSystem.getHorizontalGridStep() * 5,
mpGraphicsView->mCoOrdinateSystem.getVerticalGridStep() * 5);
QPointF gridStep(mpGraphicsView->mMergedCoOrdinateSystem.getHorizontalGridStep() * 5,
mpGraphicsView->mMergedCoOrdinateSystem.getVerticalGridStep() * 5);
pEllipseAnnotation->setOrigin(mOrigin + gridStep);
pEllipseAnnotation->initializeTransformation();
pEllipseAnnotation->drawCornerItems();
pEllipseAnnotation->setCornerItemsActiveOrPassive();
pEllipseAnnotation->applyTransformation();
pEllipseAnnotation->update();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pEllipseAnnotation));
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pEllipseAnnotation, mpGraphicsView);
Expand Down
24 changes: 17 additions & 7 deletions OMEdit/OMEditLIB/Annotations/LineAnnotation.cpp
Expand Up @@ -44,6 +44,8 @@
LineAnnotation::LineAnnotation(QString annotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(false, pGraphicsView, 0, 0)
{
mpOriginItem = new OriginItem(this);
mpOriginItem->setPassive();
setLineType(LineAnnotation::ShapeType);
setStartComponent(0);
setEndComponent(0);
Expand Down Expand Up @@ -72,6 +74,7 @@ LineAnnotation::LineAnnotation(QString annotation, GraphicsView *pGraphicsView)
LineAnnotation::LineAnnotation(ShapeAnnotation *pShapeAnnotation, Component *pParent)
: ShapeAnnotation(pShapeAnnotation, pParent)
{
mpOriginItem = 0;
updateShape(pShapeAnnotation);
setLineType(LineAnnotation::ComponentType);
setStartComponent(0);
Expand All @@ -96,15 +99,18 @@ LineAnnotation::LineAnnotation(ShapeAnnotation *pShapeAnnotation, Component *pPa
LineAnnotation::LineAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(true, pGraphicsView, pShapeAnnotation, 0)
{
mpOriginItem = new OriginItem(this);
mpOriginItem->setPassive();
updateShape(pShapeAnnotation);
setShapeFlags(true);
mpGraphicsView->addItem(this);
mpGraphicsView->addItem(mpOriginItem);
}

LineAnnotation::LineAnnotation(LineAnnotation::LineType lineType, Component *pStartComponent, GraphicsView *pGraphicsView)
: ShapeAnnotation(false, pGraphicsView, 0, 0)
{
setFlag(QGraphicsItem::ItemIsSelectable);
mpOriginItem = 0;
mLineType = lineType;
setZValue(1000);
// set the default values
Expand Down Expand Up @@ -172,6 +178,7 @@ LineAnnotation::LineAnnotation(LineAnnotation::LineType lineType, Component *pSt
LineAnnotation::LineAnnotation(QString annotation, Component *pStartComponent, Component *pEndComponent, GraphicsView *pGraphicsView)
: ShapeAnnotation(false, pGraphicsView, 0, 0)
{
mpOriginItem = 0;
setFlag(QGraphicsItem::ItemIsSelectable);
mLineType = LineAnnotation::ConnectionType;
setZValue(1000);
Expand Down Expand Up @@ -212,6 +219,7 @@ LineAnnotation::LineAnnotation(QString annotation, QString text, Component *pSta
QString immediate, QString reset, QString synchronize, QString priority, GraphicsView *pGraphicsView)
: ShapeAnnotation(false, pGraphicsView, 0, 0)
{
mpOriginItem = 0;
setFlag(QGraphicsItem::ItemIsSelectable);
mLineType = LineAnnotation::TransitionType;
setZValue(1000);
Expand Down Expand Up @@ -251,6 +259,7 @@ LineAnnotation::LineAnnotation(QString annotation, QString text, Component *pSta
LineAnnotation::LineAnnotation(QString annotation, Component *pComponent, GraphicsView *pGraphicsView)
: ShapeAnnotation(false, pGraphicsView, 0, 0)
{
mpOriginItem = 0;
setFlag(QGraphicsItem::ItemIsSelectable);
mLineType = LineAnnotation::InitialStateType;
setZValue(1000);
Expand Down Expand Up @@ -290,6 +299,7 @@ LineAnnotation::LineAnnotation(QString annotation, Component *pComponent, Graphi
LineAnnotation::LineAnnotation(Component *pParent)
: ShapeAnnotation(0, pParent)
{
mpOriginItem = 0;
setLineType(LineAnnotation::ComponentType);
setStartComponent(0);
setEndComponent(0);
Expand Down Expand Up @@ -327,6 +337,7 @@ LineAnnotation::LineAnnotation(Component *pParent)
LineAnnotation::LineAnnotation(GraphicsView *pGraphicsView)
: ShapeAnnotation(true, pGraphicsView, 0, 0)
{
mpOriginItem = 0;
setLineType(LineAnnotation::ShapeType);
setStartComponent(0);
setEndComponent(0);
Expand Down Expand Up @@ -1258,8 +1269,7 @@ void LineAnnotation::updateInitialStateAnnotation()
QString annotationString = QString("annotate=$annotation(%1)").arg(getShapeAnnotation());
// update the initial state
OMCProxy *pOMCProxy = MainWindow::instance()->getOMCProxy();
pOMCProxy->updateInitialState(mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure(), getStartComponentName(),
annotationString);
pOMCProxy->updateInitialState(mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure(), getStartComponentName(), annotationString);
}

/*!
Expand All @@ -1270,12 +1280,12 @@ void LineAnnotation::duplicate()
{
LineAnnotation *pLineAnnotation = new LineAnnotation("", mpGraphicsView);
pLineAnnotation->updateShape(this);
QPointF gridStep(mpGraphicsView->mCoOrdinateSystem.getHorizontalGridStep() * 5,
mpGraphicsView->mCoOrdinateSystem.getVerticalGridStep() * 5);
QPointF gridStep(mpGraphicsView->mMergedCoOrdinateSystem.getHorizontalGridStep() * 5,
mpGraphicsView->mMergedCoOrdinateSystem.getVerticalGridStep() * 5);
pLineAnnotation->setOrigin(mOrigin + gridStep);
pLineAnnotation->initializeTransformation();
pLineAnnotation->drawCornerItems();
pLineAnnotation->setCornerItemsActiveOrPassive();
pLineAnnotation->applyTransformation();
pLineAnnotation->update();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pLineAnnotation));
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pLineAnnotation, mpGraphicsView);
Expand All @@ -1286,9 +1296,9 @@ void LineAnnotation::duplicate()
void LineAnnotation::redraw(const QString& annotation, std::function<void()> updateAnnotationFunction)
{
parseShapeAnnotation(annotation);
initializeTransformation();
removeCornerItems();
drawCornerItems();
applyTransformation();
adjustGeometries();
setCornerItemsActiveOrPassive();
update();
Expand Down
13 changes: 10 additions & 3 deletions OMEdit/OMEditLIB/Annotations/PolygonAnnotation.cpp
Expand Up @@ -38,6 +38,8 @@
PolygonAnnotation::PolygonAnnotation(QString annotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(false, pGraphicsView, 0, 0)
{
mpOriginItem = new OriginItem(this);
mpOriginItem->setPassive();
// set the default values
GraphicItem::setDefaults();
FilledShape::setDefaults();
Expand All @@ -51,6 +53,7 @@ PolygonAnnotation::PolygonAnnotation(QString annotation, GraphicsView *pGraphics
PolygonAnnotation::PolygonAnnotation(ShapeAnnotation *pShapeAnnotation, Component *pParent)
: ShapeAnnotation(pShapeAnnotation, pParent)
{
mpOriginItem = 0;
updateShape(pShapeAnnotation);
setPos(mOrigin);
setRotation(mRotation);
Expand All @@ -59,14 +62,18 @@ PolygonAnnotation::PolygonAnnotation(ShapeAnnotation *pShapeAnnotation, Componen
PolygonAnnotation::PolygonAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(true, pGraphicsView, pShapeAnnotation, 0)
{
mpOriginItem = new OriginItem(this);
mpOriginItem->setPassive();
updateShape(pShapeAnnotation);
setShapeFlags(true);
mpGraphicsView->addItem(this);
mpGraphicsView->addItem(mpOriginItem);
}

PolygonAnnotation::PolygonAnnotation(Component *pParent)
: ShapeAnnotation(0, pParent)
{
mpOriginItem = 0;
// set the default values
GraphicItem::setDefaults();
FilledShape::setDefaults();
Expand Down Expand Up @@ -302,12 +309,12 @@ void PolygonAnnotation::duplicate()
{
PolygonAnnotation *pPolygonAnnotation = new PolygonAnnotation("", mpGraphicsView);
pPolygonAnnotation->updateShape(this);
QPointF gridStep(mpGraphicsView->mCoOrdinateSystem.getHorizontalGridStep() * 5,
mpGraphicsView->mCoOrdinateSystem.getVerticalGridStep() * 5);
QPointF gridStep(mpGraphicsView->mMergedCoOrdinateSystem.getHorizontalGridStep() * 5,
mpGraphicsView->mMergedCoOrdinateSystem.getVerticalGridStep() * 5);
pPolygonAnnotation->setOrigin(mOrigin + gridStep);
pPolygonAnnotation->initializeTransformation();
pPolygonAnnotation->drawCornerItems();
pPolygonAnnotation->setCornerItemsActiveOrPassive();
pPolygonAnnotation->applyTransformation();
pPolygonAnnotation->update();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pPolygonAnnotation));
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pPolygonAnnotation, mpGraphicsView);
Expand Down
16 changes: 12 additions & 4 deletions OMEdit/OMEditLIB/Annotations/RectangleAnnotation.cpp
Expand Up @@ -38,6 +38,8 @@
RectangleAnnotation::RectangleAnnotation(QString annotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(false, pGraphicsView, 0, 0)
{
mpOriginItem = new OriginItem(this);
mpOriginItem->setPassive();
// set the default values
GraphicItem::setDefaults();
FilledShape::setDefaults();
Expand All @@ -51,6 +53,7 @@ RectangleAnnotation::RectangleAnnotation(QString annotation, GraphicsView *pGrap
RectangleAnnotation::RectangleAnnotation(ShapeAnnotation *pShapeAnnotation, Component *pParent)
: ShapeAnnotation(pShapeAnnotation, pParent)
{
mpOriginItem = 0;
updateShape(pShapeAnnotation);
setPos(mOrigin);
setRotation(mRotation);
Expand All @@ -59,14 +62,18 @@ RectangleAnnotation::RectangleAnnotation(ShapeAnnotation *pShapeAnnotation, Comp
RectangleAnnotation::RectangleAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(true, pGraphicsView, pShapeAnnotation, 0)
{
mpOriginItem = new OriginItem(this);
mpOriginItem->setPassive();
updateShape(pShapeAnnotation);
setShapeFlags(true);
mpGraphicsView->addItem(this);
mpGraphicsView->addItem(mpOriginItem);
}

RectangleAnnotation::RectangleAnnotation(Component *pParent)
: ShapeAnnotation(0, pParent)
{
mpOriginItem = 0;
// set the default values
GraphicItem::setDefaults();
FilledShape::setDefaults();
Expand All @@ -91,6 +98,7 @@ RectangleAnnotation::RectangleAnnotation(Component *pParent)
RectangleAnnotation::RectangleAnnotation(GraphicsView *pGraphicsView)
: ShapeAnnotation(true, pGraphicsView, 0, 0)
{
mpOriginItem = 0;
// set the default values
GraphicItem::setDefaults();
FilledShape::setDefaults();
Expand Down Expand Up @@ -170,7 +178,7 @@ void RectangleAnnotation::drawRectangleAnnotaion(QPainter *painter)
{
applyLinePattern(painter);
applyFillPattern(painter);
painter->drawRoundedRect(getBoundingRect(), mRadius, mRadius);
painter->drawRoundedRect(getBoundingRect().normalized(), mRadius, mRadius);
}

/*!
Expand Down Expand Up @@ -259,12 +267,12 @@ void RectangleAnnotation::duplicate()
{
RectangleAnnotation *pRectangleAnnotation = new RectangleAnnotation("", mpGraphicsView);
pRectangleAnnotation->updateShape(this);
QPointF gridStep(mpGraphicsView->mCoOrdinateSystem.getHorizontalGridStep() * 5,
mpGraphicsView->mCoOrdinateSystem.getVerticalGridStep() * 5);
QPointF gridStep(mpGraphicsView->mMergedCoOrdinateSystem.getHorizontalGridStep() * 5,
mpGraphicsView->mMergedCoOrdinateSystem.getVerticalGridStep() * 5);
pRectangleAnnotation->setOrigin(mOrigin + gridStep);
pRectangleAnnotation->initializeTransformation();
pRectangleAnnotation->drawCornerItems();
pRectangleAnnotation->setCornerItemsActiveOrPassive();
pRectangleAnnotation->applyTransformation();
pRectangleAnnotation->update();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pRectangleAnnotation));
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pRectangleAnnotation, mpGraphicsView);
Expand Down

0 comments on commit 58c7a53

Please sign in to comment.