* ./hurricane/src/hviewer :
- Bug: do not redraw the grid with each paintEvent(). This is a terrific cpu eater. Grid is now drawn into the same plane as the layers.
This commit is contained in:
parent
259ae70943
commit
f62dcb53b6
|
@ -23,6 +23,9 @@
|
||||||
// x-----------------------------------------------------------------x
|
// x-----------------------------------------------------------------x
|
||||||
|
|
||||||
|
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
@ -864,9 +867,9 @@ namespace Hurricane {
|
||||||
//setBackgroundRole ( QPalette::Dark );
|
//setBackgroundRole ( QPalette::Dark );
|
||||||
//setAutoFillBackground ( false );
|
//setAutoFillBackground ( false );
|
||||||
setAttribute ( Qt::WA_OpaquePaintEvent );
|
setAttribute ( Qt::WA_OpaquePaintEvent );
|
||||||
//setAttribute ( Qt::WA_NoSystemBackground );
|
setAttribute ( Qt::WA_NoSystemBackground );
|
||||||
//setAttribute ( Qt::WA_PaintOnScreen );
|
setAttribute ( Qt::WA_PaintOnScreen );
|
||||||
//setAttribute ( Qt::WA_StaticContents );
|
setAttribute ( Qt::WA_StaticContents );
|
||||||
setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding );
|
setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding );
|
||||||
setFocusPolicy ( Qt::StrongFocus );
|
setFocusPolicy ( Qt::StrongFocus );
|
||||||
setMouseTracking ( true );
|
setMouseTracking ( true );
|
||||||
|
@ -1123,6 +1126,8 @@ namespace Hurricane {
|
||||||
_cellModificated = false;
|
_cellModificated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( isDrawable("grid") ) drawGrid ( redrawArea );
|
||||||
|
|
||||||
setDarkening ( 100 );
|
setDarkening ( 100 );
|
||||||
if ( _showSelection )
|
if ( _showSelection )
|
||||||
redrawSelection ( redrawArea );
|
redrawSelection ( redrawArea );
|
||||||
|
@ -1130,25 +1135,25 @@ namespace Hurricane {
|
||||||
popCursor ();
|
popCursor ();
|
||||||
|
|
||||||
timer.stop ();
|
timer.stop ();
|
||||||
cerr << "CellWidget::redraw() - " << _redrawRectCount
|
// cerr << "CellWidget::redraw() - " << _redrawRectCount
|
||||||
<< " in " << timer.getCombTime() << "s ("
|
// << " in " << timer.getCombTime() << "s ("
|
||||||
<< setprecision(3) << (timer.getCombTime()/_redrawRectCount) << " s/r)";
|
// << setprecision(3) << (timer.getCombTime()/_redrawRectCount) << " s/r)";
|
||||||
if ( _drawingQuery.getGoCount() )
|
// if ( _drawingQuery.getGoCount() )
|
||||||
cerr << " " << _drawingQuery.getGoCount()
|
// cerr << " " << _drawingQuery.getGoCount()
|
||||||
<< " (" << setprecision(3) << (timer.getCombTime()/_drawingQuery.getGoCount()) << " s/go)";
|
// << " (" << setprecision(3) << (timer.getCombTime()/_drawingQuery.getGoCount()) << " s/go)";
|
||||||
else
|
// else
|
||||||
cerr << " 0 Gos";
|
// cerr << " 0 Gos";
|
||||||
if ( _drawingQuery.getExtensionGoCount() )
|
// if ( _drawingQuery.getExtensionGoCount() )
|
||||||
cerr << " " << _drawingQuery.getExtensionGoCount()
|
// cerr << " " << _drawingQuery.getExtensionGoCount()
|
||||||
<< " (" << setprecision(3) << (timer.getCombTime()/_drawingQuery.getExtensionGoCount()) << " s/ego)";
|
// << " (" << setprecision(3) << (timer.getCombTime()/_drawingQuery.getExtensionGoCount()) << " s/ego)";
|
||||||
else
|
// else
|
||||||
cerr << " 0 eGos";
|
// cerr << " 0 eGos";
|
||||||
if ( _drawingQuery.getInstanceCount() )
|
// if ( _drawingQuery.getInstanceCount() )
|
||||||
cerr << " " << _drawingQuery.getInstanceCount()
|
// cerr << " " << _drawingQuery.getInstanceCount()
|
||||||
<< " (" << setprecision(3) << (timer.getCombTime()/_drawingQuery.getInstanceCount()) << " s/inst)";
|
// << " (" << setprecision(3) << (timer.getCombTime()/_drawingQuery.getInstanceCount()) << " s/inst)";
|
||||||
else
|
// else
|
||||||
cerr << " 0 Instances";
|
// cerr << " 0 Instances";
|
||||||
cerr << endl;
|
// cerr << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1363,9 +1368,14 @@ namespace Hurricane {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CellWidget::drawGrid ()
|
void CellWidget::drawGrid ( QRect redrawArea )
|
||||||
{
|
{
|
||||||
_drawingPlanes.painter(PlaneId::Widget).setPen ( Graphics::getPen("grid") );
|
_drawingPlanes.select ( PlaneId::Normal );
|
||||||
|
_drawingPlanes.painterBegin ();
|
||||||
|
_drawingPlanes.painter ().setClipRect ( redrawArea );
|
||||||
|
_drawingPlanes.painter ( PlaneId::Normal ).setPen ( Graphics::getPen("grid") );
|
||||||
|
|
||||||
|
Box redrawBox = displayToDbuBox ( redrawArea ).inflate ( DbU::lambda(1.0) );
|
||||||
|
|
||||||
bool lambdaGrid = false;
|
bool lambdaGrid = false;
|
||||||
if ( Graphics::getThreshold("grid")/DbU::lambda(1.0) < _scale/5 )
|
if ( Graphics::getThreshold("grid")/DbU::lambda(1.0) < _scale/5 )
|
||||||
|
@ -1377,28 +1387,33 @@ namespace Hurricane {
|
||||||
DbU::Unit yGrid;
|
DbU::Unit yGrid;
|
||||||
QPoint center;
|
QPoint center;
|
||||||
|
|
||||||
for ( yGrid = DbU::getOnSnapGrid(_visibleArea.getYMin())
|
for ( yGrid = DbU::getOnSnapGrid(redrawBox.getYMin())
|
||||||
; yGrid < _visibleArea.getYMax()
|
; yGrid < redrawBox.getYMax()
|
||||||
; yGrid += gridStep
|
; yGrid += gridStep
|
||||||
) {
|
) {
|
||||||
for ( xGrid = DbU::getOnSnapGrid(_visibleArea.getXMin())
|
for ( xGrid = DbU::getOnSnapGrid(redrawBox.getXMin())
|
||||||
; xGrid < _visibleArea.getXMax()
|
; xGrid < redrawBox.getXMax()
|
||||||
; xGrid += gridStep
|
; xGrid += gridStep
|
||||||
) {
|
) {
|
||||||
center = dbuToScreenPoint(xGrid,yGrid);
|
center = dbuToDisplayPoint(xGrid,yGrid);
|
||||||
if ( (xGrid % superGridStep) || (yGrid % superGridStep) ) {
|
if ( (xGrid % superGridStep) || (yGrid % superGridStep) ) {
|
||||||
if ( lambdaGrid )
|
if ( lambdaGrid ) {
|
||||||
_drawingPlanes.painter(PlaneId::Widget).drawPoint ( center );
|
_drawingPlanes.painter(PlaneId::Normal).drawPoint ( center );
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if ( lambdaGrid ) {
|
if ( lambdaGrid ) {
|
||||||
_drawingPlanes.painter(PlaneId::Widget).drawLine ( center.x()-3, center.y() , center.x()+3, center.y() );
|
_drawingPlanes.painter(PlaneId::Normal).drawLine ( center.x()-3, center.y() , center.x()+3, center.y() );
|
||||||
_drawingPlanes.painter(PlaneId::Widget).drawLine ( center.x() , center.y()-3, center.x() , center.y()+3 );
|
_drawingPlanes.painter(PlaneId::Normal).drawLine ( center.x() , center.y()-3, center.x() , center.y()+3 );
|
||||||
} else {
|
} else {
|
||||||
_drawingPlanes.painter(PlaneId::Widget).drawPoint ( center );
|
_drawingPlanes.painter(PlaneId::Normal).drawPoint ( center );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_drawingPlanes.copyToSelect ( redrawArea );
|
||||||
|
_drawingPlanes.painterEnd ();
|
||||||
|
repaint ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1639,14 +1654,28 @@ namespace Hurricane {
|
||||||
|
|
||||||
void CellWidget::paintEvent ( QPaintEvent* event )
|
void CellWidget::paintEvent ( QPaintEvent* event )
|
||||||
{
|
{
|
||||||
|
static Timer timer;
|
||||||
|
static time_t prevTime = 0;
|
||||||
|
static time_t currTime = 0;
|
||||||
|
|
||||||
|
timer.start ();
|
||||||
_drawingPlanes.painterBegin ( PlaneId::Widget );
|
_drawingPlanes.painterBegin ( PlaneId::Widget );
|
||||||
_drawingPlanes.copyToScreen ();
|
_drawingPlanes.copyToScreen ();
|
||||||
for ( size_t i=0 ; i<_commands.size() ; i++ )
|
for ( size_t i=0 ; i<_commands.size() ; i++ )
|
||||||
_commands[i]->draw ( this );
|
_commands[i]->draw ( this );
|
||||||
|
|
||||||
if ( isDrawable("grid") ) drawGrid ();
|
// if ( isDrawable("grid") ) drawGrid ();
|
||||||
if ( isDrawable("spot") ) _spot.moveTo ( _mousePosition );
|
if ( isDrawable("spot") ) _spot.moveTo ( _mousePosition );
|
||||||
_drawingPlanes.painterEnd ( PlaneId::Widget );
|
_drawingPlanes.painterEnd ( PlaneId::Widget );
|
||||||
|
timer.stop ();
|
||||||
|
|
||||||
|
time ( &currTime );
|
||||||
|
double delta = difftime ( currTime, prevTime );
|
||||||
|
|
||||||
|
// if ( delta )
|
||||||
|
// cerr << "CellWidget::paintEvent() - lagging: " << delta << endl;
|
||||||
|
|
||||||
|
prevTime = currTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// -*- C++ -*-
|
// -*- C++ -*-
|
||||||
//
|
//
|
||||||
// This file is part of the Coriolis Software.
|
// This file is part of the Coriolis Software.
|
||||||
// Copyright (c) UPMC/LIP6 2008-2008, All Rights Reserved
|
// Copyright (c) UPMC/LIP6 2008-2009, All Rights Reserved
|
||||||
//
|
//
|
||||||
// ===================================================================
|
// ===================================================================
|
||||||
//
|
//
|
||||||
|
@ -60,8 +60,8 @@ namespace Hurricane {
|
||||||
bool ZoomCommand::keyPressEvent ( CellWidget* widget, QKeyEvent* event )
|
bool ZoomCommand::keyPressEvent ( CellWidget* widget, QKeyEvent* event )
|
||||||
{
|
{
|
||||||
switch ( event->key() ) {
|
switch ( event->key() ) {
|
||||||
case Qt::Key_Z: widget->setScale ( widget->getScale()/2.0 ); return true;
|
case Qt::Key_Z: widget->setScale ( widget->getScale()*2.0 ); return true;
|
||||||
case Qt::Key_M: widget->setScale ( widget->getScale()*2.0 ); return true;
|
case Qt::Key_M: widget->setScale ( widget->getScale()/2.0 ); return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,7 @@ namespace Hurricane {
|
||||||
void drawLine ( DbU::Unit, DbU::Unit, DbU::Unit, DbU::Unit, bool mode=true );
|
void drawLine ( DbU::Unit, DbU::Unit, DbU::Unit, DbU::Unit, bool mode=true );
|
||||||
void drawLine ( const Point&, const Point&, bool mode=true );
|
void drawLine ( const Point&, const Point&, bool mode=true );
|
||||||
void drawText ( const Point&, const Name&, int angle=0, bool reverse=false );
|
void drawText ( const Point&, const Name&, int angle=0, bool reverse=false );
|
||||||
void drawGrid ();
|
void drawGrid ( QRect );
|
||||||
void drawSpot ();
|
void drawSpot ();
|
||||||
void drawScreenLine ( const QPoint&, const QPoint&, size_t plane=PlaneId::Working, bool mode=true );
|
void drawScreenLine ( const QPoint&, const QPoint&, size_t plane=PlaneId::Working, bool mode=true );
|
||||||
void drawScreenRect ( const QPoint&, const QPoint&, size_t plane=PlaneId::Working );
|
void drawScreenRect ( const QPoint&, const QPoint&, size_t plane=PlaneId::Working );
|
||||||
|
|
Loading…
Reference in New Issue