- 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:
parent
66cbe976c3
commit
54219843d6
|
@ -33,6 +33,7 @@
|
|||
#include <QApplication>
|
||||
#include <QPrinter>
|
||||
#include <QPrintDialog>
|
||||
#include <QFileDialog>
|
||||
|
||||
#include "hurricane/DataBase.h"
|
||||
#include "hurricane/Cell.h"
|
||||
|
@ -52,6 +53,7 @@ namespace Hurricane {
|
|||
, _openAction(NULL)
|
||||
, _nextAction(NULL)
|
||||
, _printAction(NULL)
|
||||
, _imageAction(NULL)
|
||||
, _saveAction(NULL)
|
||||
, _closeAction(NULL)
|
||||
, _exitAction(NULL)
|
||||
|
@ -124,6 +126,12 @@ namespace Hurricane {
|
|||
_printAction->setVisible ( true );
|
||||
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->setObjectName ( "viewer.menuBar.file.saveCell" );
|
||||
_saveAction->setIcon ( QIcon(":/images/stock_save.png") );
|
||||
|
@ -193,6 +201,7 @@ namespace Hurricane {
|
|||
}
|
||||
_fileMenu->addSeparator ();
|
||||
_fileMenu->addAction ( _printAction );
|
||||
_fileMenu->addAction ( _imageAction );
|
||||
_fileMenu->addAction ( _saveAction );
|
||||
_fileMenu->addSeparator ();
|
||||
_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.
|
||||
|
|
|
@ -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 yimage = 0;
|
||||
|
@ -673,28 +673,40 @@ namespace Hurricane {
|
|||
begin ( PlaneId::Image );
|
||||
|
||||
_painters[PlaneId::Image].setRenderHint ( QPainter::Antialiasing, false );
|
||||
_painters[PlaneId::Image].drawPixmap
|
||||
( ximage, yimage
|
||||
, *_planes[PlaneId::Normal]
|
||||
, _cellWidget->getOffsetVA().rx()+sx, _cellWidget->getOffsetVA().ry()+sy
|
||||
, w, h
|
||||
);
|
||||
if ( _cellWidget->showSelection() ) {
|
||||
_painters[PlaneId::Image].drawPixmap
|
||||
( ximage, yimage
|
||||
, *_planes[PlaneId::Selection]
|
||||
, _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;
|
||||
_painters[PlaneId::Image].setPen(Qt::white);
|
||||
_painters[PlaneId::Image].drawRect(xGradient-1, h+9, 512, 31);
|
||||
_painters[PlaneId::Image].setPen(Qt::NoPen);
|
||||
for ( unsigned i = 0 ; i < 256 ; i++ ) {
|
||||
_painters[PlaneId::Image].setBrush(Graphics::getColorScale(ColorScale::Fire).getBrush(i,100) );
|
||||
_painters[PlaneId::Image].drawRect(xGradient+(i*2), h+10, 2, 30);
|
||||
if ( i==0 || i==51 || i==102 || i==153 || i==204 || i==255 ) {
|
||||
QRect tArea (xGradient+(i*2)-15, h+44, 30, 12);
|
||||
std::ostringstream oss;
|
||||
oss << (float)(i)/255;
|
||||
_painters[PlaneId::Image].setPen(Qt::white);
|
||||
_painters[PlaneId::Image].drawLine(xGradient+(i*2), h+38, xGradient+(i*2), h+42);
|
||||
_painters[PlaneId::Image].drawText(tArea, Qt::AlignCenter, oss.str().c_str());
|
||||
_painters[PlaneId::Image].setPen(Qt::NoPen);
|
||||
if ( !noScale ) {
|
||||
int xGradient = (w-510)/2;
|
||||
_painters[PlaneId::Image].setPen(Qt::white);
|
||||
_painters[PlaneId::Image].drawRect(xGradient-1, h+9, 512, 31);
|
||||
_painters[PlaneId::Image].setPen(Qt::NoPen);
|
||||
for ( unsigned i = 0 ; i < 256 ; i++ ) {
|
||||
_painters[PlaneId::Image].setBrush(Graphics::getColorScale(ColorScale::Fire).getBrush(i,100) );
|
||||
_painters[PlaneId::Image].drawRect(xGradient+(i*2), h+10, 2, 30);
|
||||
if ( i==0 || i==51 || i==102 || i==153 || i==204 || i==255 ) {
|
||||
QRect tArea (xGradient+(i*2)-15, h+44, 30, 12);
|
||||
std::ostringstream oss;
|
||||
oss << (float)(i)/255;
|
||||
_painters[PlaneId::Image].setPen(Qt::white);
|
||||
_painters[PlaneId::Image].drawLine(xGradient+(i*2), h+38, xGradient+(i*2), h+42);
|
||||
_painters[PlaneId::Image].drawText(tArea, Qt::AlignCenter, oss.str().c_str());
|
||||
_painters[PlaneId::Image].setPen(Qt::NoPen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -741,7 +753,14 @@ namespace Hurricane {
|
|||
{
|
||||
_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 );
|
||||
}
|
||||
|
||||
|
@ -1454,8 +1473,10 @@ namespace Hurricane {
|
|||
|
||||
Instance* instance = dynamic_cast<Instance*>(occurrence.getEntity());
|
||||
if ( instance ) {
|
||||
// Temporary.
|
||||
//drawInstance ( instance, basicLayer, redrawBox, transformation );
|
||||
_drawingPlanes.setPen ( Graphics::getPen ("boundaries",getDarkening()) );
|
||||
_drawingPlanes.setBrush ( Graphics::getBrush("boundaries",getDarkening()) );
|
||||
|
||||
_drawingQuery.drawMasterCell ( instance->getMasterCell(), instance->getTransformation().getTransformation(transformation) );
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
// -*- C++ -*-
|
||||
//
|
||||
// This file is part of the Coriolis Software.
|
||||
|
@ -86,6 +85,7 @@ namespace Hurricane {
|
|||
void showController ();
|
||||
void openHistoryCell ();
|
||||
void printDisplay ();
|
||||
void imageDisplay ();
|
||||
signals:
|
||||
void showSelectionToggled ( bool );
|
||||
void stateChanged ( shared_ptr<CellWidget::State>& );
|
||||
|
@ -99,6 +99,7 @@ namespace Hurricane {
|
|||
QAction* _nextAction;
|
||||
QAction* _cellHistoryAction[CellHistorySize];
|
||||
QAction* _printAction;
|
||||
QAction* _imageAction;
|
||||
QAction* _saveAction;
|
||||
QAction* _closeAction;
|
||||
QAction* _exitAction;
|
||||
|
|
|
@ -153,7 +153,7 @@ namespace Hurricane {
|
|||
inline QPainter& getPainter ( size_t plane=PlaneId::Working );
|
||||
inline int getDarkening () const;
|
||||
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 QPoint& getMousePosition () const;
|
||||
inline void updateMousePosition ();
|
||||
|
@ -403,8 +403,8 @@ namespace Hurricane {
|
|||
void copyToScreen ( int sx, int sy, int h, int w );
|
||||
inline void copyToPrinter ( QPrinter*, bool imageOnly );
|
||||
void copyToPrinter ( int sx, int sy, int h, int w, QPrinter*, bool imageOnly );
|
||||
inline void copyToImage ( QImage* );
|
||||
void copyToImage ( int sx, int sy, int h, int w, QImage* );
|
||||
inline void copyToImage ( QImage*, bool noScale );
|
||||
void copyToImage ( int sx, int sy, int h, int w, QImage*, bool noScale );
|
||||
private:
|
||||
static const int _cartoucheWidth;
|
||||
static const int _cartoucheHeight;
|
||||
|
@ -447,6 +447,9 @@ namespace Hurricane {
|
|||
virtual void goCallback ( Go* );
|
||||
virtual void rubberCallback ( Rubber* );
|
||||
virtual void extensionGoCallback ( Go* );
|
||||
void drawMasterCell ( const Cell* cell
|
||||
, const Transformation& transformation
|
||||
);
|
||||
void drawGo ( const Go* go
|
||||
, const BasicLayer* basicLayer
|
||||
, 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
|
||||
, 0
|
||||
, _cellWidget->geometry().width()
|
||||
, _cellWidget->geometry().height()
|
||||
, image
|
||||
, noScale
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1086,8 +1090,8 @@ namespace Hurricane {
|
|||
{ _drawingPlanes.copyToPrinter ( printer, imageOnly ); }
|
||||
|
||||
|
||||
inline void CellWidget::copyToImage ( QImage* image )
|
||||
{ _drawingPlanes.copyToImage ( image ); }
|
||||
inline void CellWidget::copyToImage ( QImage* image, bool noScale )
|
||||
{ _drawingPlanes.copyToImage ( image, noScale ); }
|
||||
|
||||
|
||||
inline int CellWidget::dbuToDisplayX ( DbU::Unit x ) const
|
||||
|
|
Loading…
Reference in New Issue