Skip to content

Commit

Permalink
Fix for bug #1498
Browse files Browse the repository at this point in the history
- Diagram view can be exported to SVG format.
- Diagram view can be printed. However, there are some problems while printing, especially when you try to make a pdf, the text of components does not show up.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9502 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Jul 18, 2011
1 parent 4c4c5f4 commit c324b4c
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 22 deletions.
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Helper.cpp
Expand Up @@ -43,6 +43,7 @@ QString Helper::omcServerName = "OMEdit";
QString Helper::omFileTypes = "Modelica Files (*.mo)";
QString Helper::omnotebookFileTypes = "OMNotebook Files (*.onb *.onbz *.nb)";
QString Helper::imageFileTypes = "Image Files (*.png *.bmp)";
QString Helper::svgFileTypes = "SVG Files (*.svg)";
#ifdef WIN32
QString Helper::tmpPath = QString(getenv("OPENMODELICAHOME")).replace("\\", "/").append(QString("/tmp/OMEdit"));
#else
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Helper.h
Expand Up @@ -50,6 +50,7 @@ class Helper
static QString omFileTypes;
static QString omnotebookFileTypes;
static QString imageFileTypes;
static QString svgFileTypes;
static QString tmpPath;
static QString settingsFileName;
static QString documentationBaseUrl;
Expand Down
12 changes: 7 additions & 5 deletions OMEdit/OMEditGUI/LineAnnotation.cpp
Expand Up @@ -143,10 +143,12 @@ void LineAnnotation::drawLineAnnotaion(QPainter *painter)
qreal thickness;

// make the pen width upper rounded for spline, otherwise spline is distorted
if (mSmooth)
thickness = ceil(mThickness);
else
thickness = mThickness;
thickness = ceil(mThickness);
// this is commented intentionally so that we dont need path stroker. Also helps in svg rendering
// if (mSmooth)
// thickness = ceil(mThickness);
// else
// thickness = mThickness;

QPen pen(this->mLineColor, thickness, this->mLinePattern);
pen.setCosmetic(true);
Expand All @@ -162,7 +164,7 @@ void LineAnnotation::drawLineAnnotaion(QPainter *painter)
else
painter->drawPolygon(drawArrow(mPoints.at(0), mPoints.at(1), mArrowSize * 2, mStartArrow));

painter->drawPath(getShape());
painter->drawPath(getShape());

// draw end arrow
if (mEndArrow == ShapeAnnotation::Filled)
Expand Down
7 changes: 6 additions & 1 deletion OMEdit/OMEditGUI/PolygonAnnotation.cpp
Expand Up @@ -96,7 +96,12 @@ void PolygonAnnotation::drawPolygonAnnotaion(QPainter *painter)
painter->setBrush(QBrush(this->mFillColor, this->mFillPattern));
break;
}
QPen pen(this->mLineColor, this->mThickness, this->mLinePattern);

qreal thickness;
// if (mCornerRadius > 0) // this is commented intentionally so that we dont need path stroker. Also helps in svg rendering
thickness = ceil(mThickness);

QPen pen(this->mLineColor, thickness, this->mLinePattern);
pen.setCosmetic(true);
painter->setPen(pen);

Expand Down
18 changes: 15 additions & 3 deletions OMEdit/OMEditGUI/ProjectTabWidget.cpp
Expand Up @@ -970,7 +970,11 @@ void GraphicsView::contextMenuEvent(QContextMenuEvent *event)
QMenu menu(mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow);
mpCancelConnectionAction->setText("Context Menu");
//menu.addAction(mpPasteComponentAction);
menu.addAction(mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow->exportAsImage);
//menu.addSeparator();
menu.addAction(mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow->exportAsImageAction);
menu.addAction(mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow->exportAsSvgAction);
menu.addAction(mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow->printModelAction);
menu.addSeparator();
menu.addAction(mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow->exportToOMNotebookAction);
menu.exec(event->globalPos());
return; // return from it because at a time we only want one context menu.
Expand Down Expand Up @@ -3229,7 +3233,11 @@ void ProjectTabWidget::enableProjectToolbar()
// enable the shapes tool bar
mpParentMainWindow->shapesToolBar->setEnabled(true);
// enable the export as image action
mpParentMainWindow->exportAsImage->setEnabled(true);
mpParentMainWindow->exportAsImageAction->setEnabled(true);
// enable the export as svg action
mpParentMainWindow->exportAsSvgAction->setEnabled(true);
// enable the print model action
mpParentMainWindow->printModelAction->setEnabled(true);
// enable the export to omnotebook action
mpParentMainWindow->exportToOMNotebookAction->setEnabled(true);
mToolBarEnabled = true;
Expand All @@ -3249,7 +3257,11 @@ void ProjectTabWidget::disableProjectToolbar()
// disable the shapes tool bar
mpParentMainWindow->shapesToolBar->setEnabled(false);
// disable the export as image action
mpParentMainWindow->exportAsImage->setEnabled(false);
mpParentMainWindow->exportAsImageAction->setEnabled(false);
// disable the export as svg action
mpParentMainWindow->exportAsSvgAction->setEnabled(false);
// disable the print model action
mpParentMainWindow->printModelAction->setEnabled(false);
// enable the export to omnotebook action
mpParentMainWindow->exportToOMNotebookAction->setEnabled(false);
mToolBarEnabled = false;
Expand Down
8 changes: 2 additions & 6 deletions OMEdit/OMEditGUI/RectangleAnnotation.cpp
Expand Up @@ -129,12 +129,8 @@ void RectangleAnnotation::drawRectangleAnnotaion(QPainter *painter)

// make the pen width upper rounded if rectangle is rounded
qreal thickness;
if (mCornerRadius > 0)
{
}
thickness = ceil(mThickness);


// if (mCornerRadius > 0) // this is commented intentionally so that we dont need path stroker. Also helps in svg rendering
thickness = ceil(mThickness);

QPen pen(mLineColor, thickness, mLinePattern);
pen.setCosmetic(true);
Expand Down
76 changes: 70 additions & 6 deletions OMEdit/OMEditGUI/mainwindow.cpp
Expand Up @@ -39,9 +39,11 @@
*/

#include <QtGui>
#include <QtSvg/QSvgGenerator>

#include "mainwindow.h"


using namespace OMPlot;

//! Constructor
Expand Down Expand Up @@ -416,10 +418,20 @@ void MainWindow::createActions()
importFromOMNotebookAction->setStatusTip(tr("Imports the models from OMNotebook"));
connect(importFromOMNotebookAction, SIGNAL(triggered()), SLOT(importModelfromOMNotebook()));

exportAsImage = new QAction(QIcon(":/Resources/icons/bitmap-shape.png"), tr("Export as Image (png)"), this);
exportAsImage->setStatusTip(tr("Exports the current model to Image (png)"));
exportAsImage->setEnabled(false);
connect(exportAsImage, SIGNAL(triggered()), SLOT(exportModelAsImage()));
exportAsImageAction = new QAction(QIcon(":/Resources/icons/bitmap-shape.png"), tr("Export as Image (png)"), this);
exportAsImageAction->setStatusTip(tr("Exports the current model to Image (png)"));
exportAsImageAction->setEnabled(false);
connect(exportAsImageAction, SIGNAL(triggered()), SLOT(exportModelAsImage()));

exportAsSvgAction = new QAction(tr("Export as SVG"), this);
exportAsSvgAction->setStatusTip(tr("Exports the current model to SVG"));
exportAsSvgAction->setEnabled(false);
connect(exportAsSvgAction, SIGNAL(triggered()), SLOT(exportModelAsSvg()));

printModelAction = new QAction(tr("Print"), this);
printModelAction->setStatusTip(tr("Prints the current model"));
printModelAction->setEnabled(false);
connect(printModelAction, SIGNAL(triggered()), SLOT(printModel()));

openOptions = new QAction(tr("Options"), this);
openOptions->setStatusTip(tr("Shows the options window"));
Expand Down Expand Up @@ -1026,10 +1038,11 @@ void MainWindow::importModelfromOMNotebook()
progressBar.hide();
}

//! Exports the current model as png image
//! @see exportModelAsSvg()
//! @see printModel()
void MainWindow::exportModelAsImage()
{
QDir fileDialogSaveDir;

QString imageFileName = StringHandler::getSaveFileName(this, tr("Export as Image"), NULL,
Helper::imageFileTypes, NULL, "png");

Expand All @@ -1054,6 +1067,57 @@ void MainWindow::exportModelAsImage()
mpMessageWidget->printGUIErrorMessage("Error saving the image file.");
}

//! Exports the current model as SVG
//! @see exportModelAsImage()
//! @see printModel()
void MainWindow::exportModelAsSvg()
{
QString svgFileName = StringHandler::getSaveFileName(this, tr("Export as SVG"), NULL,
Helper::svgFileTypes, NULL, "svg");

// if user cancels the operation. or closes the export dialog box.
if (svgFileName.isEmpty())
return;

ProjectTab *pCurrentTab = mpProjectTabs->getCurrentTab();
QSvgGenerator svgGenerator;
svgGenerator.setTitle(tr("OMEdit - OpenModelica Connection Editor"));
svgGenerator.setDescription(tr("Generated by OpenModelica Connection Editor Tool"));
svgGenerator.setSize(pCurrentTab->mpDiagramGraphicsView->viewport()->size());
svgGenerator.setFileName(svgFileName);

QPainter painter(&svgGenerator);
painter.setWindow(pCurrentTab->mpDiagramGraphicsView->viewport()->rect());
// paint the background color first
painter.fillRect(painter.viewport(), pCurrentTab->mpDiagramGraphicsView->palette().background());
// paint all the items
pCurrentTab->mpDiagramGraphicsView->render(&painter, QRectF(painter.viewport()), pCurrentTab->mpDiagramGraphicsView->viewport()->rect());
painter.end();
}

//! Prints the current model
//! @see exportModelAsImage()
//! @see exportModelAsSvg()
void MainWindow::printModel()
{
ProjectTab *pCurrentTab = mpProjectTabs->getCurrentTab();
QPrinter printer;
printer.setDocName("OMEdit-Print");
printer.setCreator("OpenModelica Connection Editor");

QPrintDialog printerDialog(&printer);
if (printerDialog.exec())
{
QPainter painter(&printer);
painter.setWindow(pCurrentTab->mpDiagramGraphicsView->viewport()->rect());
// paint the background color first
painter.fillRect(painter.viewport(), pCurrentTab->mpDiagramGraphicsView->palette().background());
// paint all the items
pCurrentTab->mpDiagramGraphicsView->render(&painter, QRectF(painter.viewport()), pCurrentTab->mpDiagramGraphicsView->viewport()->rect());
painter.end();
}
}

void MainWindow::openConfigurationOptions()
{
this->mpOptionsWidget->show();
Expand Down
6 changes: 5 additions & 1 deletion OMEdit/OMEditGUI/mainwindow.h
Expand Up @@ -145,7 +145,9 @@ class MainWindow : public QMainWindow
QAction *openOMShellAction;
QAction *exportToOMNotebookAction;
QAction *importFromOMNotebookAction;
QAction *exportAsImage;
QAction *exportAsImageAction;
QAction *exportAsSvgAction;
QAction *printModelAction;
QAction *openOptions;
QAction *gridLinesAction;
QAction *resetZoomAction;
Expand Down Expand Up @@ -209,6 +211,8 @@ private slots:
void createOMNotebookCodeCell(QDomDocument xmlDocument, QDomElement pDomElement);
void importModelfromOMNotebook();
void exportModelAsImage();
void exportModelAsSvg();
void printModel();
void openConfigurationOptions();
void flatModel();
void checkModel();
Expand Down

0 comments on commit c324b4c

Please sign in to comment.