Skip to content

Commit 7a3e652

Browse files
committed
Added the support for user defined shapes.
Removed the QtSvgdll as it is not needed anymore. Caching the OMC commands so that library browsing become more faster. More enhanced library icons. git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7273 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 5e62d3e commit 7a3e652

39 files changed

+1689
-380
lines changed

OMEdit/OMEditGUI/Component.cpp

Lines changed: 58 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
Component::Component(QString value, QString name, QString className, QPointF position, int type, bool connector,
3737
OMCProxy *omc, GraphicsView *graphicsView, Component *pParent)
38-
: ShapeAnnotation(pParent), mAnnotationString(value), mName(name), mClassName(className), mType(type),
38+
: ShapeAnnotation(graphicsView, pParent), mAnnotationString(value), mName(name), mClassName(className), mType(type),
3939
mIsConnector(connector), mpOMCProxy(omc), mpGraphicsView(graphicsView)
4040
{
4141
mIsLibraryComponent = false;
@@ -44,17 +44,25 @@ Component::Component(QString value, QString name, QString className, QPointF pos
4444

4545
parseAnnotationString(this, value);
4646
// if component is an icon
47-
if (mType == StringHandler::ICON)
47+
if ((mType == StringHandler::ICON))
4848
{
49-
scale(Helper::globalIconXScale, Helper::globalIconYScale);
5049
setPos(position);
51-
setComponentFlags();
52-
setAcceptHoverEvents(true);
53-
getClassComponents(mClassName, mType);
54-
createActions();
50+
if (mpGraphicsView->mpParentProjectTab->isReadOnly())
51+
{
52+
scale(Helper::globalDiagramXScale, Helper::globalDiagramYScale);
53+
getClassComponents(mClassName, mType);
54+
}
55+
else
56+
{
57+
scale(Helper::globalIconXScale, Helper::globalIconYScale);
58+
setComponentFlags();
59+
setAcceptHoverEvents(true);
60+
getClassComponents(mClassName, mType);
61+
createActions();
62+
}
5563
}
5664
// if component is a diagram
57-
else if (mType == StringHandler::DIAGRAM)
65+
else if ((mType == StringHandler::DIAGRAM))
5866
{
5967
scale(Helper::globalDiagramXScale, Helper::globalDiagramYScale);
6068
setPos(position);
@@ -121,7 +129,7 @@ Component::Component(QString value, QString className, OMCProxy *omc, Component
121129
mType = StringHandler::ICON;
122130
mIsConnector = false;
123131

124-
parseAnnotationString(this, value);
132+
parseAnnotationString(this, value, true);
125133
getClassComponents(mClassName, mType);
126134
}
127135

@@ -137,7 +145,12 @@ Component::Component(QString value, QString className, Component *pParent)
137145
mpComponentProperties = 0;
138146
mType = StringHandler::ICON;
139147
mIsConnector = false;
140-
parseAnnotationString(this, mAnnotationString);
148+
parseAnnotationString(this, mAnnotationString, true);
149+
150+
//! @todo Since for some components we get empty annotations but its inherited componets does have annotations
151+
//! @todo so set the parent give the parent bounding box the value of inherited class boundingbox.
152+
if (mRectangle.width() > 1)
153+
getRootParentComponent()->mRectangle = mRectangle;
141154
}
142155

143156
/* Used for Library Component. Called for component annotation instance */
@@ -151,13 +164,19 @@ Component::Component(QString value, QString className, QString transformationStr
151164
mpOMCProxy = pParent->mpOMCProxy;
152165
mType = StringHandler::ICON;
153166
mIsConnector = false;
154-
parseAnnotationString(this, mAnnotationString);
167+
parseAnnotationString(this, mAnnotationString, true);
155168
mpTransformation = new Transformation(this);
169+
setTransform(mpTransformation->getTransformationMatrix());
170+
171+
//! @todo Since for some components we get empty annotations but its inherited componets does have annotations
172+
//! @todo so set the parent give the parent bounding box the value of inherited class boundingbox.
173+
if (mRectangle.width() > 1)
174+
getRootParentComponent()->mRectangle = mRectangle;
156175
}
157176

158177
Component::Component(Component *pComponent, QString name, QPointF position, int type, bool connector,
159178
GraphicsView *graphicsView, Component *pParent)
160-
: ShapeAnnotation(pParent), mName(name), mType(type), mIsConnector(connector), mpGraphicsView(graphicsView)
179+
: ShapeAnnotation(graphicsView, pParent), mName(name), mType(type), mIsConnector(connector), mpGraphicsView(graphicsView)
161180
{
162181
mpParentComponent = pParent;
163182
mClassName = pComponent->mClassName;
@@ -171,18 +190,26 @@ Component::Component(Component *pComponent, QString name, QPointF position, int
171190

172191
parseAnnotationString(this, mAnnotationString);
173192
// if component is an icon
174-
if (mType == StringHandler::ICON)
193+
if ((mType == StringHandler::ICON))
175194
{
176-
scale(Helper::globalIconXScale, Helper::globalIconYScale);
177195
setPos(position);
178-
setComponentFlags();
179-
setAcceptHoverEvents(true);
180-
copyClassComponents(pComponent);
181-
createSelectionBox();
182-
createActions();
196+
if (mpGraphicsView->mpParentProjectTab->isReadOnly())
197+
{
198+
scale(Helper::globalDiagramXScale, Helper::globalDiagramYScale);
199+
copyClassComponents(pComponent);
200+
}
201+
else
202+
{
203+
scale(Helper::globalIconXScale, Helper::globalIconYScale);
204+
setComponentFlags();
205+
setAcceptHoverEvents(true);
206+
copyClassComponents(pComponent);
207+
createSelectionBox();
208+
createActions();
209+
}
183210
}
184211
// if component is a diagram
185-
else if (mType == StringHandler::DIAGRAM)
212+
else if ((mType == StringHandler::DIAGRAM))
186213
{
187214
scale(Helper::globalDiagramXScale, Helper::globalDiagramYScale);
188215
setPos(position);
@@ -210,7 +237,7 @@ Component::~Component()
210237

211238
//! Parses the result of getIconAnnotation command.
212239
//! @param value is the result of getIconAnnotation command obtained from OMC.
213-
bool Component::parseAnnotationString(Component *item, QString value)
240+
bool Component::parseAnnotationString(Component *item, QString value, bool libraryIcon)
214241
{
215242
value = StringHandler::removeFirstLastCurlBrackets(value);
216243
if (value.isEmpty())
@@ -292,12 +319,16 @@ bool Component::parseAnnotationString(Component *item, QString value)
292319
EllipseAnnotation *ellipseAnnotation = new EllipseAnnotation(shape, item);
293320
item->mpShapesList.append(ellipseAnnotation);
294321
}
295-
if (shape.startsWith("Text"))
322+
// don't parse the text annotation for library icon
323+
if (!libraryIcon)
296324
{
297-
shape = shape.mid(QString("Text").length());
298-
shape = StringHandler::removeFirstLastBrackets(shape);
299-
TextAnnotation *textAnnotation = new TextAnnotation(shape, item);
300-
item->mpShapesList.append(textAnnotation);
325+
if (shape.startsWith("Text"))
326+
{
327+
shape = shape.mid(QString("Text").length());
328+
shape = StringHandler::removeFirstLastBrackets(shape);
329+
TextAnnotation *textAnnotation = new TextAnnotation(shape, item);
330+
item->mpShapesList.append(textAnnotation);
331+
}
301332
}
302333
}
303334
}
@@ -349,7 +380,7 @@ void Component::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
349380
void Component::mousePressEvent(QGraphicsSceneMouseEvent *event)
350381
{
351382
// if user is viewing the component in Icon View
352-
if (mpGraphicsView->mIconType == StringHandler::DIAGRAM)
383+
if ((mpGraphicsView->mIconType == StringHandler::DIAGRAM) or (mpGraphicsView->mpParentProjectTab->isReadOnly()))
353384
return;
354385
// if we are creating the connector then make sure user can not select and move components
355386
if ((mpGraphicsView->mIsCreatingConnector) and !mpParentComponent)
@@ -652,73 +683,6 @@ void Component::deleteMe()
652683
delete(this);
653684
}
654685

655-
//! Slot that moves component one pixel upwards
656-
//! @see moveDown()
657-
//! @see moveLeft()
658-
//! @see moveRight()
659-
void Component::moveUp()
660-
{
661-
this->setPos(this->pos().x(), this->mapFromScene(this->mapToScene(this->pos())).y()+1);
662-
mpGraphicsView->scene()->update();
663-
}
664-
665-
//! Slot that moves component one pixel downwards
666-
//! @see moveUp()
667-
//! @see moveLeft()
668-
//! @see moveRight()
669-
void Component::moveDown()
670-
{
671-
this->setPos(this->pos().x(), this->mapFromScene(this->mapToScene(this->pos())).y()-1);
672-
mpGraphicsView->scene()->update();
673-
}
674-
675-
//! Slot that moves component one pixel leftwards
676-
//! @see moveUp()
677-
//! @see moveDown()
678-
//! @see moveRight()
679-
void Component::moveLeft()
680-
{
681-
this->setPos(this->mapFromScene(this->mapToScene(this->pos())).x()-1, this->pos().y());
682-
mpGraphicsView->scene()->update();
683-
}
684-
685-
//! Slot that moves component one pixel rightwards
686-
//! @see moveUp()
687-
//! @see moveDown()
688-
//! @see moveLeft()
689-
void Component::moveRight()
690-
{
691-
this->setPos(this->mapFromScene(this->mapToScene(this->pos())).x()+1, this->pos().y());
692-
mpGraphicsView->scene()->update();
693-
}
694-
695-
void Component::rotateClockwise()
696-
{
697-
qreal rotation = this->rotation();
698-
qreal rotateIncrement = 90;
699-
700-
if (rotation == -270)
701-
this->setRotation(0);
702-
else
703-
this->setRotation(rotation - rotateIncrement);
704-
}
705-
706-
void Component::rotateAntiClockwise()
707-
{
708-
qreal rotation = this->rotation();
709-
qreal rotateIncrement = -90;
710-
711-
if (rotation == 270)
712-
this->setRotation(0);
713-
else
714-
this->setRotation(rotation - rotateIncrement);
715-
}
716-
717-
void Component::resetRotation()
718-
{
719-
this->setRotation(0);
720-
}
721-
722686
void Component::openIconProperties()
723687
{
724688
IconProperties *iconProperties = new IconProperties(this, mpGraphicsView->mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow);

OMEdit/OMEditGUI/Component.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class Component : public ShapeAnnotation
118118
QPointF mOldPosition;
119119
bool isMousePressed;
120120

121-
bool parseAnnotationString(Component *item, QString value);
121+
bool parseAnnotationString(Component *item, QString value, bool libraryIcon = false);
122122
QRectF boundingRect() const;
123123
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
124124
QString getName();
@@ -151,13 +151,6 @@ public slots:
151151
void showSelectionBox();
152152
void resizeComponent(qreal resizeFactorX, qreal resizeFactorY);
153153
void deleteMe();
154-
void moveUp();
155-
void moveDown();
156-
void moveLeft();
157-
void moveRight();
158-
void rotateClockwise();
159-
void rotateAntiClockwise();
160-
void resetRotation();
161154
void openIconProperties();
162155
void openIconAttributes();
163156
protected:

OMEdit/OMEditGUI/ConnectorWidget.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
*/
4040

4141
#include "ConnectorWidget.h"
42+
#include "Component.h"
4243

4344
Connector::Connector(Component *pComponent, GraphicsView *pParentView, QGraphicsItem *pParent)
4445
{
@@ -47,7 +48,7 @@ Connector::Connector(Component *pComponent, GraphicsView *pParentView, QGraphics
4748
this->setStartComponent(pComponent);
4849
setFlags(QGraphicsItem::ItemIsFocusable);
4950
this->setPos(mpStartComponent->mapToScene(mpStartComponent->boundingRect().center()));
50-
this->scale(Helper::globalIconXScale, Helper::globalIconYScale);
51+
this->scale(1.0, 1.0);
5152
setZValue(-1.0);
5253
this->updateStartPoint(mpStartComponent->mapToScene(mpStartComponent->boundingRect().center()));
5354
this->mEndComponentConnected = false;
@@ -75,7 +76,7 @@ Connector::Connector(Component *pStartPort, Component *pEndPort, GraphicsView *p
7576
mPoints = points;
7677

7778
//Setup the geometries vector based on the point geometry
78-
for(int i=0; i != mPoints.size()-1; ++i)
79+
for(int i = 0 ; i < mPoints.size()-1 ; ++i)
7980
{
8081
if(mPoints[i].x() == mPoints[i+1].x())
8182
mGeometries.push_back(Connector::VERTICAL);
@@ -91,7 +92,7 @@ Connector::Connector(Component *pStartPort, Component *pEndPort, GraphicsView *p
9192
connect(mpEndComponent->mpParentComponent, SIGNAL(componentDeleted()), SLOT(deleteMe()));
9293

9394
//Create the lines, so that drawConnector has something to work with
94-
for(int i = 0; i != mPoints.size()-1; ++i)
95+
for(int i = 0 ; i < mPoints.size()-1 ; ++i)
9596
{
9697
ConnectorLine *tempLine = new ConnectorLine(mapFromScene(mPoints[i]).x(), mapFromScene(mPoints[i]).y(),
9798
mapFromScene(mPoints[i+1]).x(), mapFromScene(mPoints[i+1]).y(),
@@ -109,9 +110,9 @@ Connector::Connector(Component *pStartPort, Component *pEndPort, GraphicsView *p
109110
this->drawConnector();
110111

111112
//Make all lines selectable and all lines except first and last movable
112-
for(int i=1; i!=mpLines.size()-1; ++i)
113+
for(int i = 1 ; i < mpLines.size() - 1 ; ++i)
113114
mpLines[i]->setFlag(QGraphicsItem::ItemIsMovable, true);
114-
for(int i=0; i!=mpLines.size(); ++i)
115+
for(int i = 0 ; i < mpLines.size() ; ++i)
115116
mpLines[i]->setFlag(QGraphicsItem::ItemIsSelectable, true);
116117

117118
mpStartComponent->mpParentComponent->addConnector(this);
@@ -493,7 +494,10 @@ ConnectorLine::ConnectorLine(qreal x1, qreal y1, qreal x2, qreal y2, int lineNum
493494
this->mParentConnectorEndComponentConnected = false;
494495
this->mActivePen = QPen(Qt::red);
495496
this->mPassivePen = QPen(Qt::black);
496-
this->mHoverPen = QPen(Qt::darkRed, 7);
497+
QPen pen (Qt::darkRed);
498+
pen.setWidth(3);
499+
pen.setCosmetic(true);
500+
this->mHoverPen = pen;
497501
}
498502

499503
//! Reimplementation of paint function. Removes the ugly dotted selection box.

OMEdit/OMEditGUI/ConnectorWidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
#include <QtCore>
4545
#include <QtGui>
46-
#include "Component.h"
46+
//#include "Component.h"
4747

4848
class ConnectorLine;
4949
class GraphicsView;

0 commit comments

Comments
 (0)