- Modified 'copy to image' :

o added bool noScale to hide colorScale (only useful for congestionMap)
        o respect the cellWidget aspect ratio when saving

    - Adding 'Save to image' functino which call a QFileDialog to choose file name

    - Highlight a masterCell's abutmentbox when it's selected (there is a bug in this)
This commit is contained in:
Damien Dupuis 2009-07-24 10:32:14 +00:00
parent 66cbe976c3
commit 54219843d6
4 changed files with 84 additions and 32 deletions

View File

@ -33,6 +33,7 @@
#include <QApplication> #include <QApplication>
#include <QPrinter> #include <QPrinter>
#include <QPrintDialog> #include <QPrintDialog>
#include <QFileDialog>
#include "hurricane/DataBase.h" #include "hurricane/DataBase.h"
#include "hurricane/Cell.h" #include "hurricane/Cell.h"
@ -52,6 +53,7 @@ namespace Hurricane {
, _openAction(NULL) , _openAction(NULL)
, _nextAction(NULL) , _nextAction(NULL)
, _printAction(NULL) , _printAction(NULL)
, _imageAction(NULL)
, _saveAction(NULL) , _saveAction(NULL)
, _closeAction(NULL) , _closeAction(NULL)
, _exitAction(NULL) , _exitAction(NULL)
@ -124,6 +126,12 @@ namespace Hurricane {
_printAction->setVisible ( true ); _printAction->setVisible ( true );
connect ( _printAction, SIGNAL(triggered()), this, SLOT(printDisplay()) ); connect ( _printAction, SIGNAL(triggered()), this, SLOT(printDisplay()) );
_imageAction = new QAction ( tr("Save to &Image"), this );
_imageAction->setObjectName ( "viewer.menuBar.file.image" );
_imageAction->setStatusTip ( tr("Save the displayed area to image") );
_imageAction->setVisible ( true );
connect ( _imageAction, SIGNAL(triggered()), this, SLOT(imageDisplay()) );
_saveAction = new QAction ( tr("&Save Cell"), this ); _saveAction = new QAction ( tr("&Save Cell"), this );
_saveAction->setObjectName ( "viewer.menuBar.file.saveCell" ); _saveAction->setObjectName ( "viewer.menuBar.file.saveCell" );
_saveAction->setIcon ( QIcon(":/images/stock_save.png") ); _saveAction->setIcon ( QIcon(":/images/stock_save.png") );
@ -193,6 +201,7 @@ namespace Hurricane {
} }
_fileMenu->addSeparator (); _fileMenu->addSeparator ();
_fileMenu->addAction ( _printAction ); _fileMenu->addAction ( _printAction );
_fileMenu->addAction ( _imageAction );
_fileMenu->addAction ( _saveAction ); _fileMenu->addAction ( _saveAction );
_fileMenu->addSeparator (); _fileMenu->addSeparator ();
_fileMenu->addAction ( _closeAction ); _fileMenu->addAction ( _closeAction );
@ -437,4 +446,21 @@ namespace Hurricane {
} }
void CellViewer::imageDisplay ()
{
if ( !_cellWidget ) return;
if ( !_cellWidget->getCell() ) {
cerr << Warning("Unable to save to image, no cell loaded yet.") << endl;
return;
}
QImage image ( _cellWidget->width(), _cellWidget->height(), QImage::Format_RGB32 );
_cellWidget->copyToImage ( &image, true ); //true for no scale (use for map congestion)
QString filePath = QFileDialog::getSaveFileName ( this, tr("Save image as ..."), "", tr("Image PNG ( *.png )") );
image.save ( filePath, "png" );
}
} // End of Hurricane namespace. } // End of Hurricane namespace.

View File

@ -662,7 +662,7 @@ namespace Hurricane {
} }
void CellWidget::DrawingPlanes::copyToImage ( int sx, int sy, int w, int h, QImage* image ) void CellWidget::DrawingPlanes::copyToImage ( int sx, int sy, int w, int h, QImage* image, bool noScale )
{ {
int ximage = 0; int ximage = 0;
int yimage = 0; int yimage = 0;
@ -673,28 +673,40 @@ namespace Hurricane {
begin ( PlaneId::Image ); begin ( PlaneId::Image );
_painters[PlaneId::Image].setRenderHint ( QPainter::Antialiasing, false ); _painters[PlaneId::Image].setRenderHint ( QPainter::Antialiasing, false );
_painters[PlaneId::Image].drawPixmap if ( _cellWidget->showSelection() ) {
( ximage, yimage _painters[PlaneId::Image].drawPixmap
, *_planes[PlaneId::Normal] ( ximage, yimage
, _cellWidget->getOffsetVA().rx()+sx, _cellWidget->getOffsetVA().ry()+sy , *_planes[PlaneId::Selection]
, w, h , _cellWidget->getOffsetVA().rx()+sx, _cellWidget->getOffsetVA().ry()+sy
); , w, h
);
}
else {
_painters[PlaneId::Image].drawPixmap
( ximage, yimage
, *_planes[PlaneId::Normal]
, _cellWidget->getOffsetVA().rx()+sx, _cellWidget->getOffsetVA().ry()+sy
, w, h
);
}
int xGradient = (w-510)/2; if ( !noScale ) {
_painters[PlaneId::Image].setPen(Qt::white); int xGradient = (w-510)/2;
_painters[PlaneId::Image].drawRect(xGradient-1, h+9, 512, 31); _painters[PlaneId::Image].setPen(Qt::white);
_painters[PlaneId::Image].setPen(Qt::NoPen); _painters[PlaneId::Image].drawRect(xGradient-1, h+9, 512, 31);
for ( unsigned i = 0 ; i < 256 ; i++ ) { _painters[PlaneId::Image].setPen(Qt::NoPen);
_painters[PlaneId::Image].setBrush(Graphics::getColorScale(ColorScale::Fire).getBrush(i,100) ); for ( unsigned i = 0 ; i < 256 ; i++ ) {
_painters[PlaneId::Image].drawRect(xGradient+(i*2), h+10, 2, 30); _painters[PlaneId::Image].setBrush(Graphics::getColorScale(ColorScale::Fire).getBrush(i,100) );
if ( i==0 || i==51 || i==102 || i==153 || i==204 || i==255 ) { _painters[PlaneId::Image].drawRect(xGradient+(i*2), h+10, 2, 30);
QRect tArea (xGradient+(i*2)-15, h+44, 30, 12); if ( i==0 || i==51 || i==102 || i==153 || i==204 || i==255 ) {
std::ostringstream oss; QRect tArea (xGradient+(i*2)-15, h+44, 30, 12);
oss << (float)(i)/255; std::ostringstream oss;
_painters[PlaneId::Image].setPen(Qt::white); oss << (float)(i)/255;
_painters[PlaneId::Image].drawLine(xGradient+(i*2), h+38, xGradient+(i*2), h+42); _painters[PlaneId::Image].setPen(Qt::white);
_painters[PlaneId::Image].drawText(tArea, Qt::AlignCenter, oss.str().c_str()); _painters[PlaneId::Image].drawLine(xGradient+(i*2), h+38, xGradient+(i*2), h+42);
_painters[PlaneId::Image].setPen(Qt::NoPen); _painters[PlaneId::Image].drawText(tArea, Qt::AlignCenter, oss.str().c_str());
_painters[PlaneId::Image].setPen(Qt::NoPen);
}
} }
} }
@ -741,7 +753,14 @@ namespace Hurricane {
{ {
_instanceCount++; _instanceCount++;
Box bbox = getTransformation().getBox(getMasterCell()->getAbutmentBox()); drawMasterCell ( getMasterCell(), getTransformation() );
}
void CellWidget::DrawingQuery::drawMasterCell ( const Cell* cell
, const Transformation& transformation
)
{
Box bbox = transformation.getBox(cell->getAbutmentBox());
_cellWidget->drawBox ( bbox ); _cellWidget->drawBox ( bbox );
} }
@ -1454,8 +1473,10 @@ namespace Hurricane {
Instance* instance = dynamic_cast<Instance*>(occurrence.getEntity()); Instance* instance = dynamic_cast<Instance*>(occurrence.getEntity());
if ( instance ) { if ( instance ) {
// Temporary. _drawingPlanes.setPen ( Graphics::getPen ("boundaries",getDarkening()) );
//drawInstance ( instance, basicLayer, redrawBox, transformation ); _drawingPlanes.setBrush ( Graphics::getBrush("boundaries",getDarkening()) );
_drawingQuery.drawMasterCell ( instance->getMasterCell(), instance->getTransformation().getTransformation(transformation) );
continue; continue;
} }

View File

@ -1,4 +1,3 @@
// -*- C++ -*- // -*- C++ -*-
// //
// This file is part of the Coriolis Software. // This file is part of the Coriolis Software.
@ -86,6 +85,7 @@ namespace Hurricane {
void showController (); void showController ();
void openHistoryCell (); void openHistoryCell ();
void printDisplay (); void printDisplay ();
void imageDisplay ();
signals: signals:
void showSelectionToggled ( bool ); void showSelectionToggled ( bool );
void stateChanged ( shared_ptr<CellWidget::State>& ); void stateChanged ( shared_ptr<CellWidget::State>& );
@ -99,6 +99,7 @@ namespace Hurricane {
QAction* _nextAction; QAction* _nextAction;
QAction* _cellHistoryAction[CellHistorySize]; QAction* _cellHistoryAction[CellHistorySize];
QAction* _printAction; QAction* _printAction;
QAction* _imageAction;
QAction* _saveAction; QAction* _saveAction;
QAction* _closeAction; QAction* _closeAction;
QAction* _exitAction; QAction* _exitAction;

View File

@ -153,7 +153,7 @@ namespace Hurricane {
inline QPainter& getPainter ( size_t plane=PlaneId::Working ); inline QPainter& getPainter ( size_t plane=PlaneId::Working );
inline int getDarkening () const; inline int getDarkening () const;
inline void copyToPrinter ( QPrinter*, bool imageOnly = false ); inline void copyToPrinter ( QPrinter*, bool imageOnly = false );
inline void copyToImage ( QImage* ); inline void copyToImage ( QImage*, bool noScale = false );
inline const float& getScale () const; inline const float& getScale () const;
inline const QPoint& getMousePosition () const; inline const QPoint& getMousePosition () const;
inline void updateMousePosition (); inline void updateMousePosition ();
@ -403,8 +403,8 @@ namespace Hurricane {
void copyToScreen ( int sx, int sy, int h, int w ); void copyToScreen ( int sx, int sy, int h, int w );
inline void copyToPrinter ( QPrinter*, bool imageOnly ); inline void copyToPrinter ( QPrinter*, bool imageOnly );
void copyToPrinter ( int sx, int sy, int h, int w, QPrinter*, bool imageOnly ); void copyToPrinter ( int sx, int sy, int h, int w, QPrinter*, bool imageOnly );
inline void copyToImage ( QImage* ); inline void copyToImage ( QImage*, bool noScale );
void copyToImage ( int sx, int sy, int h, int w, QImage* ); void copyToImage ( int sx, int sy, int h, int w, QImage*, bool noScale );
private: private:
static const int _cartoucheWidth; static const int _cartoucheWidth;
static const int _cartoucheHeight; static const int _cartoucheHeight;
@ -447,6 +447,9 @@ namespace Hurricane {
virtual void goCallback ( Go* ); virtual void goCallback ( Go* );
virtual void rubberCallback ( Rubber* ); virtual void rubberCallback ( Rubber* );
virtual void extensionGoCallback ( Go* ); virtual void extensionGoCallback ( Go* );
void drawMasterCell ( const Cell* cell
, const Transformation& transformation
);
void drawGo ( const Go* go void drawGo ( const Go* go
, const BasicLayer* basicLayer , const BasicLayer* basicLayer
, const Box& area , const Box& area
@ -825,13 +828,14 @@ namespace Hurricane {
} }
inline void CellWidget::DrawingPlanes::copyToImage ( QImage* image ) inline void CellWidget::DrawingPlanes::copyToImage ( QImage* image, bool noScale )
{ {
copyToImage ( 0 copyToImage ( 0
, 0 , 0
, _cellWidget->geometry().width() , _cellWidget->geometry().width()
, _cellWidget->geometry().height() , _cellWidget->geometry().height()
, image , image
, noScale
); );
} }
@ -1086,8 +1090,8 @@ namespace Hurricane {
{ _drawingPlanes.copyToPrinter ( printer, imageOnly ); } { _drawingPlanes.copyToPrinter ( printer, imageOnly ); }
inline void CellWidget::copyToImage ( QImage* image ) inline void CellWidget::copyToImage ( QImage* image, bool noScale )
{ _drawingPlanes.copyToImage ( image ); } { _drawingPlanes.copyToImage ( image, noScale ); }
inline int CellWidget::dbuToDisplayX ( DbU::Unit x ) const inline int CellWidget::dbuToDisplayX ( DbU::Unit x ) const