Skip to content

Commit

Permalink
Fixes for bugs #1390 #1435
Browse files Browse the repository at this point in the history
- Now the parameter values are saved correctly.
- BitmapAnnotation is fixed to show correct image. e.g Modelica.Mechanics.MultiBody.Examples.Systems.RobotR3.fullRobot
- TextAnnotation is fixed to display right component name and parameter value.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7970 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Feb 20, 2011
1 parent ae4c2f2 commit 4558e28
Show file tree
Hide file tree
Showing 12 changed files with 228 additions and 224 deletions.
139 changes: 59 additions & 80 deletions OMEdit/OMEditGUI/BitmapAnnotation.cpp
Expand Up @@ -67,6 +67,57 @@ BitmapAnnotation::BitmapAnnotation(QString shape, GraphicsView *graphicsView, QG
connect(this, SIGNAL(updateShapeAnnotation()), mpGraphicsView, SLOT(addClassAnnotation()));
}

QRectF BitmapAnnotation::boundingRect() const
{
return shape().boundingRect();
}

QPainterPath BitmapAnnotation::shape() const
{
QPainterPath path;
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 rect (left, top, width, height);
path.addRoundedRect(rect, mCornerRadius, mCornerRadius);

return path;
}

void BitmapAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);

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 rect (left, top, width, height);

if(!mImageSource.isEmpty())
{
//open file from image source
QByteArray data = QByteArray::fromBase64(mImageSource.toLatin1());
QImage image;
if(image.loadFromData(data))
painter->drawImage(rect, image.mirrored());
}
else
{
QImage image(mFileName);
painter->drawImage(rect, image.mirrored());
}
}

void BitmapAnnotation::addPoint(QPointF point)
{
mExtent.append(point);
Expand Down Expand Up @@ -140,81 +191,11 @@ QString BitmapAnnotation::getShapeAnnotation()
return annotationString;
}

QRectF BitmapAnnotation::boundingRect() const
{
return shape().boundingRect();
}

void BitmapAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);

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());

// top = -top;
// height = -height;

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

//painter->scale(1.0, -1.0);

if(!mImageSource.isEmpty())
{
//open file from image source
QByteArray img = QByteArray::fromBase64(mImageSource.toLatin1());
QPixmap pix;
if(pix.loadFromData(img))
painter->drawPixmap(rect.toRect(), pix);
}
else
{
QPixmap pixmap(mFileName);
painter->drawPixmap(rect.toRect(), pixmap);
}
}

QPainterPath BitmapAnnotation::shape() const
{
QPainterPath path;
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());

// top = -top;
// height = -height;

QRectF rect (left, top, width, height);
path.addRoundedRect(rect, mCornerRadius, mCornerRadius);

return path;
}

void BitmapAnnotation::setFileName(QString fileName)
{
mFileName = fileName;
}

void BitmapAnnotation::setImageSource(QString imageSource)
{
mImageSource = imageSource;
}

QString BitmapAnnotation::getFileName()
{
return mFileName;
}

void BitmapAnnotation::updateAnnotation()
{
emit updateShapeAnnotation();
Expand Down Expand Up @@ -283,7 +264,6 @@ void BitmapAnnotation::parseShapeAnnotation(QString shape, OMCProxy *omc)
{
QString modelPath = mpComponent->mpOMCProxy->getSourceFile(mpComponent->getClassName());
QFileInfo qFile(modelPath);
qDebug() << qFile.absolutePath();
this->mFileName = qFile.absolutePath() + "/" + tempFileName;
}

Expand All @@ -293,17 +273,16 @@ void BitmapAnnotation::parseShapeAnnotation(QString shape, OMCProxy *omc)
index = index + 1;
this->mImageSource = StringHandler::removeFirstLastQuotes(list.at(index));
}
}

//Pic in
//C:\OpenModelicaTrunk\libraries\msl32\Modelica\Resources\Images\MultiBody\Examples\Systems
//""../../../../Images/MultiBody/Examples/Systems/robot_kr15.bmp""

//MODEL PATH = C:\OpenModelica1.6.0\lib\omc\omlibrary\msl31/Modelica/Mechanics/MultiBody/Examples/Systems/RobotR3.mo
// + RELATIVE PATH = "../../../../Images/MultiBody/Examples/Systems/robot_kr15.bmp

//EQUALS:
void BitmapAnnotation::setImageSource(QString imageSource)
{
mImageSource = imageSource;
}

// ABSOLUTE PATH: C:\OpenModelica1.6.0\lib\omc\omlibrary\msl31/Modelica/Mechanics/MultiBody/Examples/Systems/../../../../Images/MultiBody/Examples/Systems/robot_kr15.bmp
QString BitmapAnnotation::getFileName()
{
return mFileName;
}

//Bitmapwidget declarations...
Expand Down
16 changes: 6 additions & 10 deletions OMEdit/OMEditGUI/BitmapAnnotation.h
Expand Up @@ -34,27 +34,23 @@ class BitmapAnnotation : public ShapeAnnotation
BitmapAnnotation(QString shape, Component *pParent = 0);
BitmapAnnotation(GraphicsView *graphicsView, QGraphicsItem *pParent = 0);
BitmapAnnotation(QString shape, GraphicsView *graphicsView, QGraphicsItem *pParent = 0);

QRectF boundingRect() const;
QPainterPath shape() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
void addPoint(QPointF point);
void drawRectangleCornerItems();
void updateEndPoint(QPointF point);
void drawRectangleCornerItems();
QString getShapeAnnotation();
void parseShapeAnnotation(QString shape, OMCProxy *omc);
void setFileName(QString fileName);
void updateAnnotation();
void setImageSource(QString imageSource);
void parseShapeAnnotation(QString shape, OMCProxy *omc);

QString getFileName();
QString getShapeAnnotation();

QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
QPainterPath shape() const;

Component *mpComponent;
private:
QString mFileName;
QString mImageSource;

public slots:
void updatePoint(int index, QPointF point);
};
Expand Down
56 changes: 28 additions & 28 deletions OMEdit/OMEditGUI/Component.cpp
Expand Up @@ -40,7 +40,8 @@ Component::Component(QString value, QString name, QString className, QPointF pos
{
mIsLibraryComponent = false;
mpParentComponent = pParent;
mpIconParametersList.append(mpOMCProxy->getParameters(mClassName));
mIconParametersList.append(mpOMCProxy->getParameters(mpGraphicsView->mpParentProjectTab->mModelNameStructure,
mClassName, mName));

parseAnnotationString(this, value);
// if component is an icon
Expand Down Expand Up @@ -92,18 +93,19 @@ Component::Component(QString value, QString className, int type, bool connector,
}

/* Called for component annotation instance */
Component::Component(QString value, QString className, QString transformationString,
ComponentsProperties *pComponentProperties, int type, bool connector, Component *pParent)
: ShapeAnnotation(pParent), mAnnotationString(value), mClassName(className),
mTransformationString(transformationString), mpComponentProperties(pComponentProperties), mType(type),
mIsConnector(connector)
Component::Component(QString value, QString transformationString,ComponentsProperties *pComponentProperties, int type,
bool connector, Component *pParent)
: ShapeAnnotation(pParent), mAnnotationString(value), mTransformationString(transformationString),
mpComponentProperties(pComponentProperties), mType(type), mIsConnector(connector)
{
mName = mpComponentProperties->getName();
mClassName = mpComponentProperties->getClassName();
mIsLibraryComponent = false;
mpParentComponent = pParent;
mpOMCProxy = pParent->mpOMCProxy;
mpGraphicsView = pParent->mpGraphicsView;
mpComponentProperties = pComponentProperties;

mIconParametersList.append(mpOMCProxy->getParameters(mpGraphicsView->mpParentProjectTab->mModelNameStructure,
mClassName, mName));
parseAnnotationString(this, mAnnotationString);

mpTransformation = new Transformation(this);
Expand Down Expand Up @@ -154,20 +156,24 @@ Component::Component(QString value, QString className, Component *pParent)
}

/* Used for Library Component. Called for component annotation instance */
Component::Component(QString value, QString className, QString transformationString,
ComponentsProperties *pComponentProperties, Component *pParent)
: ShapeAnnotation(pParent), mAnnotationString(value), mClassName(className),
mTransformationString(transformationString), mpComponentProperties(pComponentProperties)
Component::Component(QString value, QString transformationString, ComponentsProperties *pComponentProperties,
Component *pParent)
: ShapeAnnotation(pParent), mAnnotationString(value), mTransformationString(transformationString),
mpComponentProperties(pComponentProperties)
{
mName = mpComponentProperties->getName();
mClassName = mpComponentProperties->getClassName();
mIsLibraryComponent = true;
mpParentComponent = pParent;
mpOMCProxy = pParent->mpOMCProxy;
mType = StringHandler::ICON;
mIsConnector = false;

parseAnnotationString(this, mAnnotationString, true);
mpTransformation = new Transformation(this);
setTransform(mpTransformation->getTransformationMatrix());


//! @todo Since for some components we get empty annotations but its inherited componets does have annotations
//! @todo so set the parent give the parent bounding box the value of inherited class boundingbox.
if (mRectangle.width() > 1)
Expand All @@ -186,8 +192,8 @@ Component::Component(Component *pComponent, QString name, QPointF position, int
// Assing the Graphics View of this component to passed component. In order to avoid exceptions
pComponent->mpGraphicsView = mpGraphicsView;
// get the component parameters
mpIconParametersList.append(mpOMCProxy->getParameters(mClassName));

mIconParametersList.append(mpOMCProxy->getParameters(mpGraphicsView->mpParentProjectTab->mModelNameStructure,
mClassName, mName));
parseAnnotationString(this, mAnnotationString);
// if component is an icon
if ((mType == StringHandler::ICON))
Expand Down Expand Up @@ -836,13 +842,11 @@ void Component::getClassComponents(QString className, int type)
Component *component;
if (mIsLibraryComponent)
{
component = new Component(result, componentProperties->getClassName(),
componentsAnnotationsList.at(i), componentProperties, this);
component = new Component(result, componentsAnnotationsList.at(i), componentProperties, this);
}
else
{
component = new Component(result, componentProperties->getClassName(),
componentsAnnotationsList.at(i), componentProperties,
component = new Component(result, componentsAnnotationsList.at(i), componentProperties,
StringHandler::ICON, true, this);
}
mpComponentsList.append(component);
Expand Down Expand Up @@ -916,8 +920,7 @@ void Component::getClassComponents(QString className, int type, Component *pPare
{
QString result = mpOMCProxy->getIconAnnotation(componentProperties->getClassName());
Component *component;
component = new Component(result, componentProperties->getClassName(),
componentsAnnotationsList.at(i), componentProperties,
component = new Component(result, componentsAnnotationsList.at(i), componentProperties,
StringHandler::ICON, true, pParent);
mpComponentsList.append(component);
getClassComponents(componentProperties->getClassName(), StringHandler::ICON, component);
Expand All @@ -937,8 +940,7 @@ void Component::getClassComponents(QString className, int type, Component *pPare
{
QString result = mpOMCProxy->getDiagramAnnotation(componentProperties->getClassName());
Component *component;
component = new Component(result, componentProperties->getClassName(),
componentsAnnotationsList.at(i), componentProperties,
component = new Component(result, componentsAnnotationsList.at(i), componentProperties,
StringHandler::DIAGRAM, true, pParent);
mpComponentsList.append(component);
getClassComponents(componentProperties->getClassName(), StringHandler::DIAGRAM, component);
Expand All @@ -947,8 +949,7 @@ void Component::getClassComponents(QString className, int type, Component *pPare
{
QString result = mpOMCProxy->getIconAnnotation(componentProperties->getClassName());
Component *component;
component = new Component(result, componentProperties->getClassName(),
componentsAnnotationsList.at(i), componentProperties,
component = new Component(result, componentsAnnotationsList.at(i), componentProperties,
StringHandler::DIAGRAM, true, pParent);
mpComponentsList.append(component);
getClassComponents(componentProperties->getClassName(), StringHandler::ICON, component);
Expand All @@ -973,10 +974,9 @@ void Component::copyClassComponents(Component *pComponent)

foreach(Component *component, pComponent->mpComponentsList)
{
Component *portComponent = new Component(component->mAnnotationString, component->mClassName,
component->mTransformationString, component->mpComponentProperties,
component->mType, component->mIsConnector,
this);
Component *portComponent = new Component(component->mAnnotationString, component->mTransformationString,
component->mpComponentProperties, component->mType,
component->mIsConnector, this);
mpComponentsList.append(portComponent);
copyClassComponents(component);
}
Expand Down
10 changes: 5 additions & 5 deletions OMEdit/OMEditGUI/Component.h
Expand Up @@ -85,13 +85,13 @@ class Component : public ShapeAnnotation
Component(QString value, QString name, QString className, QPointF position, int type, bool connector,
OMCProxy *omc, GraphicsView *graphicsView, Component *pParent = 0);
Component(QString value, QString className, int type, bool connector, Component *pParent = 0);
Component(QString value, QString className, QString transformationString,
ComponentsProperties *pComponentProperties, int type, bool connector, Component *pParent = 0);
Component(QString value, QString transformationString, ComponentsProperties *pComponentProperties, int type,
bool connector, Component *pParent = 0);
/* Used for Library Component */
Component(QString value, QString className, OMCProxy *omc, Component *pParent = 0);
Component(QString value, QString className, Component *pParent = 0);
Component(QString value, QString className, QString transformationString,
ComponentsProperties *pComponentProperties, Component *pParent = 0);
Component(QString value, QString transformationString, ComponentsProperties *pComponentProperties,
Component *pParent = 0);
/* Used for Library Component */
/* Copy Constructors */
Component(Component *pComponent, QString name, QPointF position, int type, bool connector,
Expand All @@ -113,7 +113,7 @@ class Component : public ShapeAnnotation
QList<ShapeAnnotation*> mpShapesList;
QList<Component*> mpInheritanceList;
QList<Component*> mpComponentsList;
QList<IconParameters*> mpIconParametersList;
QList<IconParameters*> mIconParametersList;
bool mIsLibraryComponent;
QPointF mOldPosition;
bool isMousePressed;
Expand Down

0 comments on commit 4558e28

Please sign in to comment.