Skip to content

Commit

Permalink
Updated the viewport viewing area.
Browse files Browse the repository at this point in the history
Added the plotting package of OM. Will replace it later on.
Added the simulation feature. Needed few updates while in the simulation process.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6377 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Oct 14, 2010
1 parent 0941d32 commit 2088a7f
Show file tree
Hide file tree
Showing 45 changed files with 2,038 additions and 308 deletions.
15 changes: 14 additions & 1 deletion OMEdit/OMEditGUI/ComponentAnnotation.cpp
Expand Up @@ -35,7 +35,8 @@

ComponentAnnotation::ComponentAnnotation(QString value, QString className, QString transformationStr,
ComponentsProperties *pComponentProperties, IconAnnotation *pParent)
: ShapeAnnotation(pParent), mClassName(className)
: ShapeAnnotation(pParent), mClassName(className), mIconAnnotationString(value),
mTransformationString(transformationStr)
{
mpParentIcon = pParent;
mpComponentProperties = pComponentProperties;
Expand All @@ -45,6 +46,18 @@ ComponentAnnotation::ComponentAnnotation(QString value, QString className, QStri
SLOT(addConnector(ComponentAnnotation*)));
}

ComponentAnnotation::ComponentAnnotation(QString value, QString className, QString transformationStr,
ComponentsProperties *pComponentProperties, IconAnnotation *pParent, bool libraryIcon)
: ShapeAnnotation(pParent), mClassName(className), mIconAnnotationString(value),
mTransformationString(transformationStr)
{
Q_UNUSED(libraryIcon);
mpParentIcon = pParent;
mpComponentProperties = pComponentProperties;
mpParentIcon->parseIconAnnotationString(this, value);
parseTransformationString(transformationStr);
}

void ComponentAnnotation::parseTransformationString(QString value)
{
value = StringHandler::removeFirstLastCurlBrackets(value);
Expand Down
27 changes: 18 additions & 9 deletions OMEdit/OMEditGUI/ComponentAnnotation.h
Expand Up @@ -36,25 +36,22 @@

#include "ShapeAnnotation.h"
#include "IconAnnotation.h"
#include "LineAnnotation.h"
#include "PolygonAnnotation.h"
#include "RectangleAnnotation.h"
#include "EllipseAnnotation.h"
#include "TextAnnotation.h"
#include "ComponentsProperties.h"

class IconAnnotation;
class LineAnnotation;
class PolygonAnnotation;
class RectangleAnnotation;
class EllipseAnnotation;
class TextAnnotation;

class ComponentAnnotation : public ShapeAnnotation
{
Q_OBJECT
private:
QLineF line;
QString mClassName;
IconAnnotation *mpParentIcon;
bool mVisible;
qreal mPositionX;
qreal mPositionY;
bool mVisible;
qreal mScale;
qreal mAspectRatio;
bool mFlipHorizontal;
Expand All @@ -63,14 +60,26 @@ class ComponentAnnotation : public ShapeAnnotation
public:
ComponentAnnotation(QString value, QString className, QString transformationStr,
ComponentsProperties *pComponentProperties, IconAnnotation *pParent);
ComponentAnnotation(QString value, QString className, QString transformationStr,
ComponentsProperties *pComponentProperties, IconAnnotation *pParent, bool libraryIcon);
void parseTransformationString(QString value);
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
qreal getRotateAngle();
IconAnnotation* getParentIcon();

QString mClassName;
QString mIconAnnotationString;
QString mTransformationString;
QRectF mRectangle;
qreal mPositionX;
qreal mPositionY;
ComponentsProperties *mpComponentProperties;
QList<LineAnnotation*> mpLinesList;
QList<PolygonAnnotation*> mpPolygonsList;
QList<RectangleAnnotation*> mpRectanglesList;
QList<EllipseAnnotation*> mpEllipsesList;
QList<TextAnnotation*> mpTextsList;
protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
signals:
Expand Down
104 changes: 104 additions & 0 deletions OMEdit/OMEditGUI/Components.cpp
@@ -0,0 +1,104 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Linkoping University,
* Department of Computer and Information Science,
* SE-58183 Linkoping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3
* AND THIS OSMC PUBLIC LICENSE (OSMC-PL).
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S
* ACCEPTANCE OF THE OSMC PUBLIC LICENSE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from Linkoping University, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS
* OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
* Main Authors 2010: Syed Adeel Asghar, Sonia Tariq
*
*/

#include "Components.h"

Components::Components(QString value, QString className, OMCProxy *omc)
: mIconAnnotationString(value), mClassName(className)
{
mpIcon = new IconAnnotation(value, "", className, omc);
if (mpIcon->mRectangle.width() < 1)
return;
mpIcon->getClassComponents(className, true);

this->mIconPixmap = QPixmap(mpIcon->mRectangle.width() * 0.10, mpIcon->mRectangle.height() * 0.10);
this->mIconPixmap.fill(QColor(Qt::transparent));
QPainter painter(&this->mIconPixmap);
painter.scale(1.0, -1.0);
painter.scale(0.82, 0.82);
painter.setWindow(mpIcon->mRectangle.toRect());

foreach (LineAnnotation *line, mpIcon->mpLinesList)
line->drawLineAnnotaion(&painter);

foreach (PolygonAnnotation *poly, mpIcon->mpPolygonsList)
poly->drawPolygonAnnotaion(&painter);

foreach (RectangleAnnotation *rect, mpIcon->mpRectanglesList)
rect->drawRectangleAnnotaion(&painter);

foreach (EllipseAnnotation *ellipse, mpIcon->mpEllipsesList)
ellipse->drawEllipseAnnotaion(&painter);


foreach (InheritanceAnnotation *inheritance, mpIcon->mpInheritanceList)
{
foreach (LineAnnotation *line, inheritance->mpLinesList)
line->drawLineAnnotaion(&painter);

foreach (PolygonAnnotation *poly, inheritance->mpPolygonsList)
poly->drawPolygonAnnotaion(&painter);

foreach (RectangleAnnotation *rect, inheritance->mpRectanglesList)
rect->drawRectangleAnnotaion(&painter);

foreach (EllipseAnnotation *ellipse, inheritance->mpEllipsesList)
ellipse->drawEllipseAnnotaion(&painter);
}

foreach (ComponentAnnotation *component, mpIcon->mpComponentsList)
{
painter.save();
painter.translate(component->mPositionX, component->mPositionY);
painter.scale(Helper::globalXScale, Helper::globalYScale);
foreach (LineAnnotation *line, component->mpLinesList)
line->drawLineAnnotaion(&painter);

foreach (PolygonAnnotation *poly, component->mpPolygonsList)
poly->drawPolygonAnnotaion(&painter);

foreach (RectangleAnnotation *rect, component->mpRectanglesList)
rect->drawRectangleAnnotaion(&painter);

foreach (EllipseAnnotation *ellipse, component->mpEllipsesList)
ellipse->drawEllipseAnnotaion(&painter);
painter.restore();
}

painter.end();
}

QPixmap Components::getIcon()
{
return mIconPixmap;
}
56 changes: 56 additions & 0 deletions OMEdit/OMEditGUI/Components.h
@@ -0,0 +1,56 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Linkoping University,
* Department of Computer and Information Science,
* SE-58183 Linkoping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3
* AND THIS OSMC PUBLIC LICENSE (OSMC-PL).
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S
* ACCEPTANCE OF THE OSMC PUBLIC LICENSE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from Linkoping University, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS
* OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
* Main Authors 2010: Syed Adeel Asghar, Sonia Tariq
*
*/

#ifndef COMPONENTS_H
#define COMPONENTS_H

#include "IconAnnotation.h"

class IconAnnotation;
class OMCProxy;

class Components
{
private:
QString mIconAnnotationString;
QString mClassName;
QRectF mRectangle;
QPixmap mIconPixmap;
public:
Components(QString value, QString className, OMCProxy *omc);
QPixmap getIcon();

IconAnnotation *mpIcon;
};

#endif // COMPONENTS_H
25 changes: 22 additions & 3 deletions OMEdit/OMEditGUI/ConnectorWidget.cpp
Expand Up @@ -44,6 +44,7 @@ Connector::Connector(ComponentAnnotation *pComponent, GraphicsView *parentView,
setZValue(-1.0);
this->updateStartPoint(mpStartComponent->mapToScene(mpStartComponent->boundingRect().center()));
this->mEndComponentConnected = false;
this->mIsActive = false;
this->drawConnector();
}

Expand Down Expand Up @@ -300,7 +301,7 @@ void Connector::doSelect(bool lineSelected, int lineNumber)
//! @see setPassive()
void Connector::setActive()
{
//connect(this->mpParentGraphicsView, SIGNAL(keyPressDelete()), this, SLOT(deleteMe()));
connect(this->mpParentGraphicsView, SIGNAL(keyPressDelete()), this, SLOT(deleteMe()));
if(this->mEndComponentConnected)
{
mIsActive = true;
Expand All @@ -315,7 +316,7 @@ void Connector::setActive()
//! @see setActive()
void Connector::setPassive()
{
//disconnect(this->mpParentGraphicsView, SIGNAL(keyPressDelete()), this, SLOT(deleteMe()));
disconnect(this->mpParentGraphicsView, SIGNAL(keyPressDelete()), this, SLOT(deleteMe()));
if(this->mEndComponentConnected)
{
mIsActive = false;
Expand Down Expand Up @@ -354,6 +355,12 @@ void Connector::setUnHovered()
}
}

//! Asks my parent to delete myself.
void Connector::deleteMe()
{
mpParentGraphicsView->removeConnector(this);
}

ConnectorLine::ConnectorLine(qreal x1, qreal y1, qreal x2, qreal y2, int lineNumber, Connector *parent)
: QGraphicsLineItem(x1, y1, x2, y2, parent)
{
Expand All @@ -366,7 +373,7 @@ ConnectorLine::ConnectorLine(qreal x1, qreal y1, qreal x2, qreal y2, int lineNum
this->mParentConnectorEndComponentConnected = false;
this->mActivePen = QPen(Qt::red, 1.0);
this->mPassivePen = QPen(Qt::black, 1.0);
this->mHoverPen = QPen(Qt::darkRed, 6.8);
this->mHoverPen = QPen(Qt::darkRed, 6.9);
}

//! Reimplementation of paint function. Removes the ugly dotted selection box.
Expand Down Expand Up @@ -453,6 +460,18 @@ int ConnectorLine::getLineNumber()
return mLineNumber;
}

void ConnectorLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
// make the connector selected
this->setSelected(true);

QMenu menu(mpParentConnector->mpParentGraphicsView);
mpParentConnector->mpParentGraphicsView->mCancelConnectionAction->setText("Delete Connection");
mpParentConnector->mpParentGraphicsView->mCancelConnectionAction->setShortcut(QKeySequence::Delete);
menu.addAction(mpParentConnector->mpParentGraphicsView->mCancelConnectionAction);
menu.exec(event->screenPos());
}

//! Defines what shall happen if the line is selected or moved.
QVariant ConnectorLine::itemChange(GraphicsItemChange change, const QVariant &value)
{
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/ConnectorWidget.h
Expand Up @@ -82,6 +82,7 @@ public slots:
void setPassive();
void setHovered();
void setUnHovered();
void deleteMe();
};

class ConnectorLine : public QObject, public QGraphicsLineItem
Expand Down Expand Up @@ -115,6 +116,7 @@ public slots:
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
private:
bool mIsActive;
Expand Down
56 changes: 54 additions & 2 deletions OMEdit/OMEditGUI/EllipseAnnotation.cpp
Expand Up @@ -136,8 +136,60 @@ void EllipseAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem
Q_UNUSED(widget);

QPainterPath path;
//painter->rotate(ShapeAnnotation::mRotationAngle);
//painter->scale(ShapeAnnotation::mScaleX, ShapeAnnotation::mScaleY);

QPointF p1 = this->mExtent.at(0);
QPointF p2 = this->mExtent.at(1);

qreal left = qMin(p1.x(), p2.x());
qreal top = qMin(p1.y(), p2.y());
qreal width = fabs(p1.x() - p2.x());
qreal height = fabs(p1.y() - p2.y());

QRectF ellipse (left, top, width, height);

switch (this->mFillPattern)
{
case Qt::LinearGradientPattern:
{
QLinearGradient gradient(ellipse.center().x(), ellipse.center().y(), ellipse.center().x(), ellipse.y());
gradient.setColorAt(0.0, this->mFillColor);
gradient.setColorAt(1.0, this->mLineColor);
gradient.setSpread(QGradient::ReflectSpread);
painter->setBrush(gradient);
break;
}
case Qt::Dense1Pattern:
{
QLinearGradient gradient(ellipse.center().x(), ellipse.center().y(), ellipse.x(), ellipse.center().y());
gradient.setColorAt(0.0, this->mFillColor);
gradient.setColorAt(1.0, this->mLineColor);
gradient.setSpread(QGradient::ReflectSpread);
painter->setBrush(gradient);
break;
}
case Qt::RadialGradientPattern:
{
QRadialGradient gradient(ellipse.center().x(), ellipse.center().y(), width);
gradient.setColorAt(0.0, this->mFillColor);
gradient.setColorAt(1.0, this->mLineColor);
gradient.setSpread(QGradient::ReflectSpread);
painter->setBrush(gradient);
break;
}
default:
painter->setBrush(QBrush(this->mFillColor, this->mFillPattern));
break;
}
painter->setPen(QPen(this->mLineColor, this->mThickness, this->mLinePattern, Qt::RoundCap, Qt::MiterJoin));

path.addEllipse(ellipse);
painter->drawPath(path);
painter->strokePath(path, this->mLineColor);
}

void EllipseAnnotation::drawEllipseAnnotaion(QPainter *painter)
{
QPainterPath path;

QPointF p1 = this->mExtent.at(0);
QPointF p2 = this->mExtent.at(1);
Expand Down

0 comments on commit 2088a7f

Please sign in to comment.