From 9c1e51f612f16af7808281fb4c2736dadc6547dd Mon Sep 17 00:00:00 2001 From: Adeel Asghar Date: Mon, 17 Mar 2014 14:20:40 +0000 Subject: [PATCH] - Display the bitmap is library browser. - Handle the extends class bitmaps. git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@19610 f25d12d1-65f4-0310-ae8a-bbce733d8d8e --- .../Annotations/BitmapAnnotation.cpp | 8 ++++--- .../OMEditGUI/Annotations/BitmapAnnotation.h | 4 ++-- .../OMEditGUI/Annotations/ShapeAnnotation.cpp | 22 ++++--------------- .../OMEditGUI/Annotations/ShapeAnnotation.h | 1 + OMEdit/OMEditGUI/Component/Component.cpp | 18 ++++++++------- .../GUI/Containers/ModelWidgetContainer.cpp | 16 +++++++++----- .../GUI/Containers/ModelWidgetContainer.h | 2 +- 7 files changed, 34 insertions(+), 37 deletions(-) diff --git a/OMEdit/OMEditGUI/Annotations/BitmapAnnotation.cpp b/OMEdit/OMEditGUI/Annotations/BitmapAnnotation.cpp index 79d5d21e3c3..411b47ae18b 100644 --- a/OMEdit/OMEditGUI/Annotations/BitmapAnnotation.cpp +++ b/OMEdit/OMEditGUI/Annotations/BitmapAnnotation.cpp @@ -37,9 +37,10 @@ #include "BitmapAnnotation.h" -BitmapAnnotation::BitmapAnnotation(QString annotation, Component *pParent) +BitmapAnnotation::BitmapAnnotation(QString classFileName, QString annotation, Component *pParent) : ShapeAnnotation(pParent), mpComponent(pParent) { + mClassFileName = classFileName; // set the default values GraphicItem::setDefaults(); ShapeAnnotation::setDefaults(); @@ -48,11 +49,12 @@ BitmapAnnotation::BitmapAnnotation(QString annotation, Component *pParent) setRotation(mRotation); } -BitmapAnnotation::BitmapAnnotation(QString annotation, bool inheritedShape, GraphicsView *pGraphicsView) +BitmapAnnotation::BitmapAnnotation(QString classFileName, QString annotation, bool inheritedShape, GraphicsView *pGraphicsView) : ShapeAnnotation(inheritedShape, pGraphicsView, 0) { setFlag(QGraphicsItem::ItemIsSelectable); mpComponent = 0; + mClassFileName = classFileName; // set the default values GraphicItem::setDefaults(); ShapeAnnotation::setDefaults(); @@ -149,7 +151,7 @@ QString BitmapAnnotation::getShapeAnnotation() void BitmapAnnotation::duplicate() { - BitmapAnnotation *pBitmapAnnotation = new BitmapAnnotation("", false, mpGraphicsView); + BitmapAnnotation *pBitmapAnnotation = new BitmapAnnotation(mClassFileName, "", false, mpGraphicsView); QPointF gridStep(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(), mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep()); pBitmapAnnotation->setOrigin(mOrigin + gridStep); diff --git a/OMEdit/OMEditGUI/Annotations/BitmapAnnotation.h b/OMEdit/OMEditGUI/Annotations/BitmapAnnotation.h index d9077f5c3bf..7add77a9896 100644 --- a/OMEdit/OMEditGUI/Annotations/BitmapAnnotation.h +++ b/OMEdit/OMEditGUI/Annotations/BitmapAnnotation.h @@ -47,8 +47,8 @@ class BitmapAnnotation : public ShapeAnnotation { Q_OBJECT public: - BitmapAnnotation(QString annotation, Component *pParent); - BitmapAnnotation(QString annotation, bool inheritedShape, GraphicsView *pGraphicsView); + BitmapAnnotation(QString classFileName, QString annotation, Component *pParent); + BitmapAnnotation(QString classFileName, QString annotation, bool inheritedShape, GraphicsView *pGraphicsView); void parseShapeAnnotation(QString annotation); QRectF boundingRect() const; QPainterPath shape() const; diff --git a/OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp b/OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp index 9316e42ef38..793bf86a635 100644 --- a/OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp +++ b/OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp @@ -992,35 +992,21 @@ void ShapeAnnotation::setFileName(QString fileName, Component *pComponent) return; } - GraphicsView *pGraphicsView = 0; OMCProxy *pOMCProxy = 0; if (pComponent) { - pGraphicsView = pComponent->getGraphicsView(); + pOMCProxy = pComponent->getOMCProxy(); } else if (mpGraphicsView) { - pGraphicsView = mpGraphicsView; + pOMCProxy = mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow()->getOMCProxy(); } - pOMCProxy = pGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow()->getOMCProxy(); mOriginalFileName = fileName; QUrl fileUrl(mOriginalFileName); QFileInfo fileInfo(mOriginalFileName); - QString classFileName = ""; - /* if the bitmap is part of a component then read the component filename. */ - if (pComponent) - { - QStringList classInformation = pOMCProxy->getClassInformation(pComponent->getClassName()); - if (classInformation.size() > 2) - classFileName = classInformation.at(2); - } - /* if bitmap is part of a icon/diagram of a class then read the class filename. */ - else - { - classFileName = pGraphicsView->getModelWidget()->getLibraryTreeNode()->getFileName(); - } - QFileInfo classFileInfo(classFileName); + QFileInfo classFileInfo(mClassFileName); + /* if its a modelica:// link then make it absolute path */ if (fileUrl.scheme().toLower().compare("modelica") == 0) { diff --git a/OMEdit/OMEditGUI/Annotations/ShapeAnnotation.h b/OMEdit/OMEditGUI/Annotations/ShapeAnnotation.h index b48f62f66a4..a11699b15c4 100644 --- a/OMEdit/OMEditGUI/Annotations/ShapeAnnotation.h +++ b/OMEdit/OMEditGUI/Annotations/ShapeAnnotation.h @@ -215,6 +215,7 @@ public slots: StringHandler::TextAlignment mHorizontalAlignment; QString mOriginalFileName; QString mFileName; + QString mClassFileName; /* Used to find the bitmap relative locations. */ QString mImageSource; QImage mImage; QList mCornerItemsList; diff --git a/OMEdit/OMEditGUI/Component/Component.cpp b/OMEdit/OMEditGUI/Component/Component.cpp index 270e7ce43e3..508167f1b1d 100644 --- a/OMEdit/OMEditGUI/Component/Component.cpp +++ b/OMEdit/OMEditGUI/Component/Component.cpp @@ -327,14 +327,16 @@ void Component::parseAnnotationString(QString annotation) } else if (shape.startsWith("Bitmap")) { - //! @note No Bitmaps for library icons. - if (!isLibraryComponent()) - { - shape = shape.mid(QString("Bitmap").length()); - shape = StringHandler::removeFirstLastBrackets(shape); - BitmapAnnotation *pBitmapAnnotation = new BitmapAnnotation(shape, this); - mpShapesList.append(pBitmapAnnotation); - } + /* get the class file path */ + QString classFileName; + QStringList classInformation = mpOMCProxy->getClassInformation(mClassName); + if (classInformation.size() > 2) + classFileName = classInformation.at(2); + /* create the bitmap shape */ + shape = shape.mid(QString("Bitmap").length()); + shape = StringHandler::removeFirstLastBrackets(shape); + BitmapAnnotation *pBitmapAnnotation = new BitmapAnnotation(classFileName, shape, this); + mpShapesList.append(pBitmapAnnotation); } } } diff --git a/OMEdit/OMEditGUI/GUI/Containers/ModelWidgetContainer.cpp b/OMEdit/OMEditGUI/GUI/Containers/ModelWidgetContainer.cpp index 2001e232fc4..1a9d5eff195 100644 --- a/OMEdit/OMEditGUI/GUI/Containers/ModelWidgetContainer.cpp +++ b/OMEdit/OMEditGUI/GUI/Containers/ModelWidgetContainer.cpp @@ -775,7 +775,7 @@ void GraphicsView::createBitmapShape(QPointF point) if (!isCreatingBitmapShape()) { setIsCreatingBitmapShape(true); - mpBitmapShapeAnnotation = new BitmapAnnotation("", false, this); + mpBitmapShapeAnnotation = new BitmapAnnotation(mpModelWidget->getLibraryTreeNode()->getFileName(), "", false, this); mpBitmapShapeAnnotation->replaceExtent(0, point); mpBitmapShapeAnnotation->replaceExtent(1, point); } @@ -2206,12 +2206,12 @@ void ModelWidget::getModelIconDiagramShapes(QString className, bool inheritedCyc } OMCProxy *pOMCProxy = mpModelWidgetContainer->getMainWindow()->getOMCProxy(); QString iconAnnotationString = pOMCProxy->getIconAnnotation(className); - getModelIconDiagramShapes(iconAnnotationString, StringHandler::Icon, inheritedCycle); + getModelIconDiagramShapes(className, iconAnnotationString, StringHandler::Icon, inheritedCycle); QString diagramAnnotationString = pOMCProxy->getDiagramAnnotation(className); - getModelIconDiagramShapes(diagramAnnotationString, StringHandler::Diagram, inheritedCycle); + getModelIconDiagramShapes(className, diagramAnnotationString, StringHandler::Diagram, inheritedCycle); } -void ModelWidget::getModelIconDiagramShapes(QString annotationString, StringHandler::ViewType viewType, bool inheritedCycle) +void ModelWidget::getModelIconDiagramShapes(QString className, QString annotationString, StringHandler::ViewType viewType, bool inheritedCycle) { annotationString = StringHandler::removeFirstLastCurlBrackets(annotationString); if (annotationString.isEmpty()) @@ -2308,9 +2308,15 @@ void ModelWidget::getModelIconDiagramShapes(QString annotationString, StringHand } else if (shape.startsWith("Bitmap")) { + /* get the class file path */ + QString classFileName; + QStringList classInformation = mpModelWidgetContainer->getMainWindow()->getOMCProxy()->getClassInformation(className); + if (classInformation.size() > 2) + classFileName = classInformation.at(2); + /* create the bitmap shape */ shape = shape.mid(QString("Bitmap").length()); shape = StringHandler::removeFirstLastBrackets(shape); - BitmapAnnotation *pBitmapAnnotation = new BitmapAnnotation(shape, inheritedCycle, pGraphicsView); + BitmapAnnotation *pBitmapAnnotation = new BitmapAnnotation(classFileName, shape, inheritedCycle, pGraphicsView); pBitmapAnnotation->initializeTransformation(); pBitmapAnnotation->drawCornerItems(); pBitmapAnnotation->setCornerItemsPassive(); diff --git a/OMEdit/OMEditGUI/GUI/Containers/ModelWidgetContainer.h b/OMEdit/OMEditGUI/GUI/Containers/ModelWidgetContainer.h index 327a87c4760..c0d225664b3 100644 --- a/OMEdit/OMEditGUI/GUI/Containers/ModelWidgetContainer.h +++ b/OMEdit/OMEditGUI/GUI/Containers/ModelWidgetContainer.h @@ -300,7 +300,7 @@ class ModelWidget : public QWidget void updateParentModelsText(QString className); void getModelComponents(QString className, bool inheritedCycle = false); void getModelIconDiagramShapes(QString className, bool inheritedCycle = false); - void getModelIconDiagramShapes(QString annotationString, StringHandler::ViewType viewType, bool inheritedCycle = false); + void getModelIconDiagramShapes(QString className, QString annotationString, StringHandler::ViewType viewType, bool inheritedCycle = false); void getModelConnections(QString className, bool inheritedCycle = false); Component* getConnectorComponent(Component *pConnectorComponent, QString connectorName); void refresh();