Skip to content

Commit

Permalink
Fixes for bugs #1382 #1383
Browse files Browse the repository at this point in the history
- Fixed the BusUsage example crash problem.
- Icon and Diagram annotations for model are now saved.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7489 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Dec 18, 2010
1 parent 10ab6b8 commit ae540a6
Show file tree
Hide file tree
Showing 14 changed files with 646 additions and 481 deletions.
37 changes: 19 additions & 18 deletions OMEdit/OMEditGUI/Component.cpp
Expand Up @@ -855,6 +855,25 @@ void Component::getClassComponents(QString className, int type)
//! this function is called for diagram view
void Component::getClassComponents(QString className, int type, Component *pParent)
{
// if component type is diagram then
if (type == StringHandler::DIAGRAM)
{
// get the diagram connections
int connections = mpOMCProxy->getConnectionCount(className);

for (int i = 1 ; i <= connections ; i++)
{
QString result = mpOMCProxy->getNthConnectionAnnotation(className, i);
if (result.contains("Line"))
{
result = result.mid(QString("Line").length());
result = StringHandler::removeFirstLastBrackets(result);
LineAnnotation *lineAnnotation = new LineAnnotation(result, pParent);
Q_UNUSED(lineAnnotation);
}
}
}

int inheritanceCount = this->mpOMCProxy->getInheritanceCount(className);

for(int i = 1 ; i <= inheritanceCount ; i++)
Expand Down Expand Up @@ -930,24 +949,6 @@ void Component::getClassComponents(QString className, int type, Component *pPare
}
i++;
}
// if component type is diagram then
if (type == StringHandler::DIAGRAM)
{
// get the diagram connections
int connections = mpOMCProxy->getConnectionCount(className);

for (int i = 1 ; i <= connections ; i++)
{
QString result = mpOMCProxy->getNthConnectionAnnotation(className, i);
if (result.contains("Line"))
{
result = result.mid(QString("Line").length());
result = StringHandler::removeFirstLastBrackets(result);
LineAnnotation *lineAnnotation = new LineAnnotation(result, pParent);
Q_UNUSED(lineAnnotation);
}
}
}
}

//! this function is called when we need to create a copy of one component
Expand Down
195 changes: 105 additions & 90 deletions OMEdit/OMEditGUI/EllipseAnnotation.cpp
Expand Up @@ -37,96 +37,7 @@ EllipseAnnotation::EllipseAnnotation(QString shape, Component *pParent)
: ShapeAnnotation(pParent), mpComponent(pParent)
{
initializeFields();

// Remove { } from shape

shape = shape.replace("{", "");
shape = shape.replace("}", "");

// parse the shape to get the list of attributes of Ellipse.
QStringList list = StringHandler::getStrings(shape);
if (list.size() < 14)
{
return;
}

// if first item of list is true then the Ellipse should be visible.
this->mVisible = static_cast<QString>(list.at(0)).contains("true");

int index = 0;
if (mpComponent->mpOMCProxy->mAnnotationVersion == OMCProxy::ANNOTATION_VERSION3X)
{
mOrigin.setX(static_cast<QString>(list.at(1)).toFloat());
mOrigin.setY(static_cast<QString>(list.at(2)).toFloat());

mRotation = static_cast<QString>(list.at(3)).toFloat();
index = 3;
}

// 2,3,4 items of list contains the line color.
index = index + 1;
int red, green, blue;

red = static_cast<QString>(list.at(index)).toInt();
index = index + 1;
green = static_cast<QString>(list.at(index)).toInt();
index = index + 1;
blue = static_cast<QString>(list.at(index)).toInt();
this->mLineColor = QColor (red, green, blue);

// 5,6,7 items of list contains the fill color.
index = index + 1;
red = static_cast<QString>(list.at(index)).toInt();
index = index + 1;
green = static_cast<QString>(list.at(index)).toInt();
index = index + 1;
blue = static_cast<QString>(list.at(index)).toInt();
this->mFillColor = QColor (red, green, blue);

// 8 item of the list contains the line pattern.
index = index + 1;
QString linePattern = StringHandler::getLastWordAfterDot(list.at(index));
QMap<QString, Qt::PenStyle>::iterator it;
for (it = this->mLinePatternsMap.begin(); it != this->mLinePatternsMap.end(); ++it)
{
if (it.key().compare(linePattern) == 0)
{
this->mLinePattern = it.value();
break;
}
}

// 9 item of the list contains the fill pattern.
index = index + 1;
QString fillPattern = StringHandler::getLastWordAfterDot(list.at(index));
QMap<QString, Qt::BrushStyle>::iterator fill_it;
for (fill_it = this->mFillPatternsMap.begin(); fill_it != this->mFillPatternsMap.end(); ++fill_it)
{
if (fill_it.key().compare(fillPattern) == 0)
{
this->mFillPattern = fill_it.value();
break;
}
}

// 10 item of the list contains the thickness.
index = index + 1;
this->mThickness = static_cast<QString>(list.at(index)).toFloat();

// 11, 12, 13, 14 items of the list contains the extent points of Ellipse.
index = index + 1;
qreal x = static_cast<QString>(list.at(index)).toFloat();
index = index + 1;
qreal y = static_cast<QString>(list.at(index)).toFloat();
QPointF p1 (x, y);
index = index + 1;
x = static_cast<QString>(list.at(index)).toFloat();
index = index + 1;
y = static_cast<QString>(list.at(index)).toFloat();
QPointF p2 (x, y);

this->mExtent.append(p1);
this->mExtent.append(p2);
parseShapeAnnotation(shape, mpComponent->mpOMCProxy);
}

EllipseAnnotation::EllipseAnnotation(GraphicsView *graphicsView, QGraphicsItem *pParent)
Expand All @@ -139,6 +50,17 @@ EllipseAnnotation::EllipseAnnotation(GraphicsView *graphicsView, QGraphicsItem *
connect(this, SIGNAL(updateShapeAnnotation()), mpGraphicsView, SLOT(addClassAnnotation()));
}

EllipseAnnotation::EllipseAnnotation(QString shape, GraphicsView *graphicsView, QGraphicsItem *pParent)
: ShapeAnnotation(graphicsView, pParent)
{
// initialize all fields with default values
initializeFields();
parseShapeAnnotation(shape, mpGraphicsView->mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow->mpOMCProxy);
mIsCustomShape = true;
setAcceptHoverEvents(true);
connect(this, SIGNAL(updateShapeAnnotation()), mpGraphicsView, SLOT(addClassAnnotation()));
}

QRectF EllipseAnnotation::boundingRect() const
{
// if ((mExtent.size() < 2) or (mIsCustomRectangle and !mIsFinishedCreatingRectangle))
Expand Down Expand Up @@ -315,3 +237,96 @@ void EllipseAnnotation::updatePoint(int index, QPointF point)
{
mExtent.replace(index, point);
}

void EllipseAnnotation::parseShapeAnnotation(QString shape, OMCProxy *omc)
{
// Remove { } from shape

shape = shape.replace("{", "");
shape = shape.replace("}", "");

// parse the shape to get the list of attributes of Ellipse.
QStringList list = StringHandler::getStrings(shape);
if (list.size() < 14)
{
return;
}

// if first item of list is true then the Ellipse should be visible.
this->mVisible = static_cast<QString>(list.at(0)).contains("true");

int index = 0;
if (omc->mAnnotationVersion == OMCProxy::ANNOTATION_VERSION3X)
{
mOrigin.setX(static_cast<QString>(list.at(1)).toFloat());
mOrigin.setY(static_cast<QString>(list.at(2)).toFloat());

mRotation = static_cast<QString>(list.at(3)).toFloat();
index = 3;
}

// 2,3,4 items of list contains the line color.
index = index + 1;
int red, green, blue;

red = static_cast<QString>(list.at(index)).toInt();
index = index + 1;
green = static_cast<QString>(list.at(index)).toInt();
index = index + 1;
blue = static_cast<QString>(list.at(index)).toInt();
this->mLineColor = QColor (red, green, blue);

// 5,6,7 items of list contains the fill color.
index = index + 1;
red = static_cast<QString>(list.at(index)).toInt();
index = index + 1;
green = static_cast<QString>(list.at(index)).toInt();
index = index + 1;
blue = static_cast<QString>(list.at(index)).toInt();
this->mFillColor = QColor (red, green, blue);

// 8 item of the list contains the line pattern.
index = index + 1;
QString linePattern = StringHandler::getLastWordAfterDot(list.at(index));
QMap<QString, Qt::PenStyle>::iterator it;
for (it = this->mLinePatternsMap.begin(); it != this->mLinePatternsMap.end(); ++it)
{
if (it.key().compare(linePattern) == 0)
{
this->mLinePattern = it.value();
break;
}
}

// 9 item of the list contains the fill pattern.
index = index + 1;
QString fillPattern = StringHandler::getLastWordAfterDot(list.at(index));
QMap<QString, Qt::BrushStyle>::iterator fill_it;
for (fill_it = this->mFillPatternsMap.begin(); fill_it != this->mFillPatternsMap.end(); ++fill_it)
{
if (fill_it.key().compare(fillPattern) == 0)
{
this->mFillPattern = fill_it.value();
break;
}
}

// 10 item of the list contains the thickness.
index = index + 1;
this->mThickness = static_cast<QString>(list.at(index)).toFloat();

// 11, 12, 13, 14 items of the list contains the extent points of Ellipse.
index = index + 1;
qreal x = static_cast<QString>(list.at(index)).toFloat();
index = index + 1;
qreal y = static_cast<QString>(list.at(index)).toFloat();
QPointF p1 (x, y);
index = index + 1;
x = static_cast<QString>(list.at(index)).toFloat();
index = index + 1;
y = static_cast<QString>(list.at(index)).toFloat();
QPointF p2 (x, y);

this->mExtent.append(p1);
this->mExtent.append(p2);
}
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/EllipseAnnotation.h
Expand Up @@ -45,6 +45,7 @@ class EllipseAnnotation : public ShapeAnnotation
public:
EllipseAnnotation(QString shape, Component *pParent = 0);
EllipseAnnotation(GraphicsView *graphicsView, QGraphicsItem *pParent = 0);
EllipseAnnotation(QString shape, GraphicsView *graphicsView, QGraphicsItem *pParent = 0);
QRectF boundingRect() const;
QPainterPath shape() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
Expand All @@ -53,6 +54,7 @@ class EllipseAnnotation : public ShapeAnnotation
void updateEndPoint(QPointF point);
void drawRectangleCornerItems();
QString getShapeAnnotation();
void parseShapeAnnotation(QString shape, OMCProxy *omc);

Component *mpComponent;
public slots:
Expand Down

0 comments on commit ae540a6

Please sign in to comment.