From f34b13a292fb44e42c7ee61d3a420a39b29730c3 Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Fri, 16 May 2008 15:28:39 +0000 Subject: [PATCH] The new Viewer (h). --- hurricane/src/CMakeLists.txt | 2 +- hurricane/src/hviewer/CMakeLists.txt | 44 ++ hurricane/src/hviewer/CellViewer.cpp | 144 ++++ hurricane/src/hviewer/CellViewer.h | 64 ++ hurricane/src/hviewer/CellViewer.qrc | 12 + hurricane/src/hviewer/CellWidget.cpp | 665 ++++++++++++++++++ hurricane/src/hviewer/CellWidget.h | 221 ++++++ hurricane/src/hviewer/DisplayStyle.cpp | 303 ++++++++ hurricane/src/hviewer/DisplayStyle.h | 198 ++++++ hurricane/src/hviewer/Graphics.cpp | 176 +++++ hurricane/src/hviewer/Graphics.h | 102 +++ hurricane/src/hviewer/GroupPaletteEntry.cpp | 153 ++++ hurricane/src/hviewer/GroupPaletteEntry.h | 61 ++ hurricane/src/hviewer/LayerPaletteEntry.cpp | 96 +++ hurricane/src/hviewer/LayerPaletteEntry.h | 54 ++ hurricane/src/hviewer/Palette.cpp | 183 +++++ hurricane/src/hviewer/Palette.h | 70 ++ hurricane/src/hviewer/PaletteEntry.cpp | 54 ++ hurricane/src/hviewer/PaletteEntry.h | 78 ++ hurricane/src/hviewer/ScreenUtilities.cpp | 84 +++ hurricane/src/hviewer/ScreenUtilities.h | 35 + hurricane/src/hviewer/ViewerPaletteEntry.cpp | 95 +++ hurricane/src/hviewer/ViewerPaletteEntry.h | 55 ++ hurricane/src/hviewer/etc/display.xml | 78 ++ hurricane/src/hviewer/images/gtk-go-down.png | Bin 0 -> 536 bytes .../src/hviewer/images/gtk-go-forward-ltr.png | Bin 0 -> 522 bytes .../src/hviewer/images/gtk-go-forward-rtl.png | Bin 0 -> 523 bytes hurricane/src/hviewer/images/gtk-go-up.png | Bin 0 -> 605 bytes .../src/hviewer/images/palette_hide_all.png | Bin 0 -> 923 bytes .../src/hviewer/images/palette_show_all.png | Bin 0 -> 1398 bytes hurricane/src/hviewer/images/stock_open.png | Bin 0 -> 394 bytes hurricane/src/hviewer/images/stock_save.png | Bin 0 -> 850 bytes .../src/hviewer/obsoletes/LayersList.cpp | 134 ++++ hurricane/src/hviewer/obsoletes/LayersList.h | 79 +++ .../src/hviewer/obsoletes/ScreenLayer.cpp | 72 ++ hurricane/src/hviewer/obsoletes/ScreenLayer.h | 86 +++ 36 files changed, 3397 insertions(+), 1 deletion(-) create mode 100644 hurricane/src/hviewer/CMakeLists.txt create mode 100644 hurricane/src/hviewer/CellViewer.cpp create mode 100644 hurricane/src/hviewer/CellViewer.h create mode 100644 hurricane/src/hviewer/CellViewer.qrc create mode 100644 hurricane/src/hviewer/CellWidget.cpp create mode 100644 hurricane/src/hviewer/CellWidget.h create mode 100644 hurricane/src/hviewer/DisplayStyle.cpp create mode 100644 hurricane/src/hviewer/DisplayStyle.h create mode 100644 hurricane/src/hviewer/Graphics.cpp create mode 100644 hurricane/src/hviewer/Graphics.h create mode 100644 hurricane/src/hviewer/GroupPaletteEntry.cpp create mode 100644 hurricane/src/hviewer/GroupPaletteEntry.h create mode 100644 hurricane/src/hviewer/LayerPaletteEntry.cpp create mode 100644 hurricane/src/hviewer/LayerPaletteEntry.h create mode 100644 hurricane/src/hviewer/Palette.cpp create mode 100644 hurricane/src/hviewer/Palette.h create mode 100644 hurricane/src/hviewer/PaletteEntry.cpp create mode 100644 hurricane/src/hviewer/PaletteEntry.h create mode 100644 hurricane/src/hviewer/ScreenUtilities.cpp create mode 100644 hurricane/src/hviewer/ScreenUtilities.h create mode 100644 hurricane/src/hviewer/ViewerPaletteEntry.cpp create mode 100644 hurricane/src/hviewer/ViewerPaletteEntry.h create mode 100644 hurricane/src/hviewer/etc/display.xml create mode 100644 hurricane/src/hviewer/images/gtk-go-down.png create mode 100644 hurricane/src/hviewer/images/gtk-go-forward-ltr.png create mode 100644 hurricane/src/hviewer/images/gtk-go-forward-rtl.png create mode 100644 hurricane/src/hviewer/images/gtk-go-up.png create mode 100644 hurricane/src/hviewer/images/palette_hide_all.png create mode 100644 hurricane/src/hviewer/images/palette_show_all.png create mode 100644 hurricane/src/hviewer/images/stock_open.png create mode 100644 hurricane/src/hviewer/images/stock_save.png create mode 100644 hurricane/src/hviewer/obsoletes/LayersList.cpp create mode 100644 hurricane/src/hviewer/obsoletes/LayersList.h create mode 100644 hurricane/src/hviewer/obsoletes/ScreenLayer.cpp create mode 100644 hurricane/src/hviewer/obsoletes/ScreenLayer.h diff --git a/hurricane/src/CMakeLists.txt b/hurricane/src/CMakeLists.txt index 9349bb14..b25d9854 100644 --- a/hurricane/src/CMakeLists.txt +++ b/hurricane/src/CMakeLists.txt @@ -1,4 +1,4 @@ add_subdirectory(hurricane) add_subdirectory(hinspector) -add_subdirectory(viewer) +add_subdirectory(hviewer) add_subdirectory(pyext) diff --git a/hurricane/src/hviewer/CMakeLists.txt b/hurricane/src/hviewer/CMakeLists.txt new file mode 100644 index 00000000..6850f615 --- /dev/null +++ b/hurricane/src/hviewer/CMakeLists.txt @@ -0,0 +1,44 @@ + + include ( ${QT_USE_FILE} ) + + include_directories ( ${HURRICANE_SOURCE_DIR}/src/hurricane ) + + set ( includes ScreenUtilities.h + DisplayStyle.h + Graphics.h + ) + set ( mocincludes PaletteEntry.h + LayerPaletteEntry.h + GroupPaletteEntry.h + ViewerPaletteEntry.h + Palette.h + CellWidget.h + CellViewer.h + ) + set ( exports ScreenUtilities.h + PaletteEntry.h + Palette.h + DisplayStyle.h + Graphics.h + CellViewer.h + ) + set ( cpps ScreenUtilities.cpp + DisplayStyle.cpp + Graphics.cpp + PaletteEntry.cpp + LayerPaletteEntry.cpp + GroupPaletteEntry.cpp + ViewerPaletteEntry.cpp + Palette.cpp + CellWidget.cpp + CellViewer.cpp + ) + + qt4_wrap_cpp ( MOC_SRCS ${mocincludes} ) + qt4_add_resources ( RCC_SRCS CellViewer.qrc ) + + add_library ( hviewer SHARED ${cpps} ${MOC_SRCS} ${RCC_SRCS} ) + target_link_libraries ( hviewer ${QT_LIBRARIES} hurricane ) + + install ( FILES ${exports} DESTINATION /include/hurricane ) + install ( TARGETS hviewer DESTINATION /lib ) diff --git a/hurricane/src/hviewer/CellViewer.cpp b/hurricane/src/hviewer/CellViewer.cpp new file mode 100644 index 00000000..c3132ac0 --- /dev/null +++ b/hurricane/src/hviewer/CellViewer.cpp @@ -0,0 +1,144 @@ + + +// -*- C++ -*- + + +# include +# include +# include +# include + +# include "Cell.h" + +//# include "MapView.h" +# include "Palette.h" +# include "CellWidget.h" +# include "CellViewer.h" + + +namespace Hurricane { + + +CellViewer::CellViewer ( Cell* cell ) : QMainWindow() + , _openAction(NULL) + , _nextCellAction(NULL) + , _previousCellAction(NULL) + , _nextAction(NULL) + , _saveAction(NULL) + , _exitAction(NULL) + , _refreshAction(NULL) + , _fitToContentsAction(NULL) + , _showBoundariesAction(NULL) + , _fileMenu(NULL) + , _viewMenu(NULL) + //, _mapView(NULL) + , _palette(NULL) + , _cellWidget(NULL) +{ + createMenus (); + createLayout ( cell ); +} + + + + +void CellViewer::createActions () +{ + if ( _openAction ) return; + + _openAction = new QAction ( tr("&Open Cell"), this ); + _openAction->setIcon ( QIcon(":/images/stock_open.png") ); + _openAction->setStatusTip ( tr("Open (load) a new Cell") ); + + _nextCellAction = new QAction ( tr("Next Cell"), this ); + _nextCellAction->setStatusTip ( tr("Go to the next Cell in history") ); + + _previousCellAction = new QAction ( tr("Previous Cell"), this ); + _previousCellAction->setStatusTip ( tr("Go to the previous Cell in history") ); + + _nextAction = new QAction ( tr("&Next Breakpoint"), this ); + _nextAction->setStatusTip ( tr("Proceed to the next breakpoint") ); + + _saveAction = new QAction ( tr("&Save Cell"), this ); + _saveAction->setIcon ( QIcon(":/images/stock_save.png") ); + _saveAction->setStatusTip ( tr("Save the current Cell") ); + + _exitAction = new QAction ( tr("&Exit"), this ); + _exitAction->setStatusTip ( tr("Close Coriolis CellViewer") ); + _exitAction->setShortcut ( QKeySequence(tr("CTRL+Q")) ); + connect ( _exitAction, SIGNAL(triggered()), this, SLOT(close()) ); + + _refreshAction = new QAction ( tr("&Refresh"), this ); + _refreshAction->setStatusTip ( tr("Force full redrawing of the display") ); + _refreshAction->setShortcut ( QKeySequence(tr("CTRL+L")) ); + + _fitToContentsAction = new QAction ( tr("&Fit to Contents"), this ); + _fitToContentsAction->setStatusTip ( tr("Adjust zoom to fit the whole cell's contents") ); + _fitToContentsAction->setShortcut ( Qt::Key_F ); + + _showBoundariesAction = new QAction ( tr("&Boundaries"), this ); + _showBoundariesAction->setCheckable ( true ); + _showBoundariesAction->setStatusTip ( tr("Show/hide cell & instances abutment boxes") ); +} + + + +void CellViewer::createMenus () +{ + if ( _fileMenu ) return; + if ( !_openAction ) createActions (); + + _fileMenu = menuBar()->addMenu ( tr("File") ); + _fileMenu->addAction ( _openAction ); + _fileMenu->addAction ( _nextCellAction ); + _fileMenu->addAction ( _previousCellAction ); + _fileMenu->addAction ( _nextAction ); + _fileMenu->addAction ( _saveAction ); + _fileMenu->addAction ( _exitAction ); + + _viewMenu = menuBar()->addMenu ( tr("View") ); + _viewMenu->addAction ( _refreshAction ); + _viewMenu->addAction ( _fitToContentsAction ); + _viewMenu->addAction ( _showBoundariesAction ); +} + + + +void CellViewer::createLayout ( Cell* cell ) +{ + if ( _cellWidget ) return; + + _cellWidget = new CellWidget ( cell ); + _palette = _cellWidget->getPalette(); +//_mapView = _cellWidget->getMapView (); + + setCorner ( Qt::TopLeftCorner , Qt::LeftDockWidgetArea ); + setCorner ( Qt::BottomLeftCorner , Qt::LeftDockWidgetArea ); + setCorner ( Qt::TopRightCorner , Qt::RightDockWidgetArea ); + setCorner ( Qt::BottomRightCorner, Qt::RightDockWidgetArea ); + +// QDockWidget* mapViewDock = new QDockWidget ( tr("Map") ); +// mapViewDock->setObjectName ( "MapView" ); +// mapViewDock->setWidget ( _mapView ); +// mapViewDock->setAllowedAreas ( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); +// addDockWidget ( Qt::RightDockWidgetArea, mapViewDock ); + + QDockWidget* layerMapDock = new QDockWidget ( tr("Layers") ); + layerMapDock->setObjectName ( "Palette" ); + layerMapDock->setWidget ( _palette ); + layerMapDock->setAllowedAreas ( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); + addDockWidget ( Qt::RightDockWidgetArea, layerMapDock ); + + setCentralWidget ( _cellWidget ); + + connect ( _refreshAction , SIGNAL(triggered()) , _cellWidget, SLOT(redraw ()) ); + connect ( _fitToContentsAction , SIGNAL(triggered()) , _cellWidget, SLOT(fitToContents()) ); + + _showBoundariesAction->setChecked ( _cellWidget->showBoundaries() ); + connect ( _showBoundariesAction, SIGNAL(toggled(bool)), _cellWidget, SLOT(setShowBoundaries(bool)) ); + + _cellWidget->redraw (); +} + + +} // End of Hurricane namespace. diff --git a/hurricane/src/hviewer/CellViewer.h b/hurricane/src/hviewer/CellViewer.h new file mode 100644 index 00000000..add53688 --- /dev/null +++ b/hurricane/src/hviewer/CellViewer.h @@ -0,0 +1,64 @@ + +// -*- C++ -*- + + +# ifndef __CELL_VIEWER_H__ +# define __CELL_VIEWER_H__ + + +using namespace std; + +# include + +class QKeyEvent; +class QAction; +class QMenu; + +# include "Commons.h" + + + + +namespace Hurricane { + + + class Cell; + class Palette; +//class MapView; + class CellWidget; + + + class CellViewer : public QMainWindow { + Q_OBJECT; + + protected: + QAction* _openAction; + QAction* _nextCellAction; + QAction* _previousCellAction; + QAction* _nextAction; + QAction* _saveAction; + QAction* _exitAction; + QAction* _refreshAction; + QAction* _fitToContentsAction; + QAction* _showBoundariesAction; + QMenu* _fileMenu; + QMenu* _viewMenu; + //MapView* _mapView; + Palette* _palette; + CellWidget* _cellWidget; + + public: + CellViewer ( Cell* cell ); + + protected: + void createActions (); + void createMenus (); + void createLayout ( Cell* cell ); + }; + + + +} // End of Hurricane namespace. + + +# endif diff --git a/hurricane/src/hviewer/CellViewer.qrc b/hurricane/src/hviewer/CellViewer.qrc new file mode 100644 index 00000000..65078a51 --- /dev/null +++ b/hurricane/src/hviewer/CellViewer.qrc @@ -0,0 +1,12 @@ + + + images/stock_open.png + images/stock_save.png + images/palette_show_all.png + images/palette_hide_all.png + images/gtk-go-up.png + images/gtk-go-down.png + images/gtk-go-forward-rtl.png + images/gtk-go-forward-ltr.png + + diff --git a/hurricane/src/hviewer/CellWidget.cpp b/hurricane/src/hviewer/CellWidget.cpp new file mode 100644 index 00000000..0679d285 --- /dev/null +++ b/hurricane/src/hviewer/CellWidget.cpp @@ -0,0 +1,665 @@ + +// -*- C++ -*- + + +# include +# include +# include +# include +# include +# include + +# include "DataBase.h" +# include "Technology.h" +# include "BasicLayer.h" +# include "Cell.h" +# include "Instance.h" +# include "Slice.h" +# include "Segment.h" +# include "Contact.h" + +# include "Graphics.h" +# include "PaletteEntry.h" +# include "Palette.h" +// # include "MapView.h" +# include "CellWidget.h" + + + + +namespace Hurricane { + + +const int CellWidget::_stripWidth = 100; + + + + +CellWidget::CellWidget ( Cell* cell ) : QWidget() + , _palette(NULL) + , _displayArea(0,0,6*_stripWidth,6*_stripWidth) + , _visibleArea(_stripWidth,_stripWidth,4*_stripWidth,4*_stripWidth) + , _scale(1.0) + , _offsetVA(_stripWidth,_stripWidth) + , _drawingBuffer(6*_stripWidth,6*_stripWidth) + , _painter() + , _lastMousePosition(0,0) + , _cell(cell) + , _mouseGo(false) + , _openCell(true) + , _showBoundaries(true) + , _redrawRectCount(0) +{ +//setBackgroundRole ( QPalette::Dark ); +//setAutoFillBackground ( false ); + setAttribute ( Qt::WA_OpaquePaintEvent ); +//setAttribute ( Qt::WA_NoSystemBackground ); +//setAttribute ( Qt::WA_PaintOnScreen ); +//setAttribute ( Qt::WA_StaticContents ); + setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding ); + setFocusPolicy ( Qt::StrongFocus ); + +//_mapView = new MapView ( this ); + _palette = new Palette ( this ); + + fitToContents (); + _openCell = false; +} + + +CellWidget::~CellWidget () +{ + cerr << "CellWidget::~CellWidget()" << endl; +} + + +void CellWidget::pushCursor ( Qt::CursorShape cursor ) +{ + setCursor ( cursor ); + _cursors.push_back ( cursor ); +} + + +void CellWidget::popCursor () +{ + _cursors.pop_back (); + if ( !_cursors.empty() ) + setCursor ( _cursors.back() ); + else + unsetCursor (); +} + + +QSize CellWidget::minimumSizeHint () const +{ + return QSize(_stripWidth*4,_stripWidth*4); +} + + +void CellWidget::redraw ( QRect redrawArea ) +{ + _redrawRectCount = 0; + + pushCursor ( Qt::BusyCursor ); + + _painter.begin ( &_drawingBuffer ); + + _painter.setPen ( Qt::NoPen ); + _painter.setBackground ( Graphics::getBrush("background") ); + _painter.setClipRect ( redrawArea ); + _painter.eraseRect ( redrawArea ); + + Box redrawBox = getBox ( redrawArea ); + + vector& paletteEntries = _palette->getEntries (); + for ( size_t i=0 ; igetName()) ); + _painter.setBrush ( Graphics::getBrush(paletteEntries[i]->getName()) ); + + if ( paletteEntries[i]->isBasicLayer() && isDrawable(paletteEntries[i]) ) { + drawCell ( _cell, paletteEntries[i]->getBasicLayer(), redrawBox, Transformation() ); + } else if ( (paletteEntries[i]->getName() == DisplayStyle::Boundaries) + && paletteEntries[i]->isChecked() ) { + drawBoundaries ( _cell, redrawBox, Transformation() ); + } + + } + + _painter.end (); + + update (); + popCursor (); + + cerr << "Redrawed rectangles: " << _redrawRectCount << endl; +} + + +void CellWidget::drawBoundaries ( const Cell* cell + , const Box& redrawArea + , const Transformation& transformation + ) +{ + drawBox ( transformation.getBox(cell->getAbutmentBox()) ); + for_each_instance ( instance, cell->getInstances() ) { + drawBoundaries ( instance, redrawArea, transformation ); + end_for; + } +} + + +void CellWidget::drawBoundaries ( const Instance* instance + , const Box& redrawArea + , const Transformation& transformation + ) +{ + Box masterArea = redrawArea; + Transformation masterTransformation = instance->getTransformation(); + + instance->getTransformation().getInvert().applyOn ( masterArea ); + transformation.applyOn ( masterTransformation ); + + drawBoundaries ( instance->getMasterCell(), masterArea, masterTransformation ); +} + + +bool CellWidget::isDrawable ( PaletteEntry* entry ) +{ + return entry->isChecked() + && ( entry->getBasicLayer()->getDisplayThreshold() < _scale*100 ); +} + + +void CellWidget::drawCell ( const Cell* cell + , const BasicLayer* basicLayer + , const Box& redrawArea + , const Transformation& transformation + ) +{ + for_each_instance ( instance, cell->getInstancesUnder(redrawArea) ) { + drawInstance ( instance, basicLayer, redrawArea, transformation ); + end_for; + } + + for_each_slice ( slice, cell->getSlices() ) { + drawSlice ( slice, basicLayer, redrawArea, transformation ); + end_for; + } +} + + +void CellWidget::drawInstance ( const Instance* instance + , const BasicLayer* basicLayer + , const Box& redrawArea + , const Transformation& transformation + ) +{ + Box masterArea = redrawArea; + Transformation masterTransformation = instance->getTransformation(); + + instance->getTransformation().getInvert().applyOn ( masterArea ); + transformation.applyOn ( masterTransformation ); + + drawCell ( instance->getMasterCell(), basicLayer, masterArea, masterTransformation ); +} + + +void CellWidget::drawSlice ( const Slice* slice + , const BasicLayer* basicLayer + , const Box& redrawArea + , const Transformation& transformation + ) +{ + if ( slice->getLayer()->contains(basicLayer) ) { + if ( slice->getBoundingBox().intersect(redrawArea) ) { + for_each_go ( go, slice->getGosUnder(redrawArea) ) { + drawGo ( go, basicLayer, redrawArea, transformation ); + end_for; + } + } + } +} + + +void CellWidget::drawGo ( const Go* go + , const BasicLayer* basicLayer + , const Box& redrawArea + , const Transformation& transformation + ) +{ + const Segment* segment = dynamic_cast(go); + if (segment) { + drawSegment ( segment, basicLayer, redrawArea, transformation ); + return; + } + + const Contact* contact = dynamic_cast(go); + if (contact) { + drawContact ( contact, basicLayer, redrawArea, transformation ); + return; + } +} + + +void CellWidget::drawSegment ( const Segment* segment + , const BasicLayer* basicLayer + , const Box& redrawArea + , const Transformation& transformation + ) +{ + if ( 1 < getScreenLength(segment->getWidth()) ) { + drawBox ( transformation.getBox(segment->getBoundingBox(basicLayer)) ); + } else { + drawLine ( transformation.getPoint(segment->getSourcePosition()), + transformation.getPoint(segment->getTargetPosition()) ); + } +} + + +void CellWidget::drawContact ( const Contact* contact + , const BasicLayer* basicLayer + , const Box& redrawArea + , const Transformation& transformation + ) +{ + drawBox ( transformation.getBox(contact->getBoundingBox(basicLayer)) ); +} + + +void CellWidget::drawBox ( const Box& box ) +{ + _redrawRectCount++; + _painter.drawRect ( getScreenRect(box) ); +} + + +void CellWidget::drawLine ( const Point& p1, const Point& p2 ) +{ + _painter.drawLine ( getScreenPoint(p1), getScreenPoint(p2) ); +} + + +void CellWidget::goLeft ( int dx ) +{ + if ( !dx ) dx = geometry().size().width() / 4; + if ( _offsetVA.rx() - dx >= 0 ) { + _offsetVA.rx() -= dx; + update (); + } else { + shiftLeft ( dx ); + } +} + + +void CellWidget::goRight ( int dx ) +{ + if ( !dx ) dx = geometry().size().width() / 4; + +//cerr << "CellWidget::goRight() - dx: " << dx << " (offset: " << _offsetVA.rx() << ")" << endl; + + if ( _offsetVA.rx() + dx < 2*_stripWidth ) { + _offsetVA.rx() += dx; + update (); + } else { + shiftRight ( dx ); + } +} + + +void CellWidget::goUp ( int dy ) +{ + if ( !dy ) dy = geometry().size().height() / 4; + if ( _offsetVA.ry() - dy >= 0 ) { + _offsetVA.ry() -= dy; + update (); + } else { + shiftUp ( dy ); + } +} + + +void CellWidget::goDown ( int dy ) +{ + if ( !dy ) dy = geometry().size().height() / 4; + if ( _offsetVA.ry() + dy < 2*_stripWidth ) { + _offsetVA.ry() += dy; + update (); + } else { + shiftDown ( dy ); + } +} + + +void CellWidget::screenReframe () +{ + _offsetVA.rx() = _stripWidth; + _offsetVA.ry() = _stripWidth; + + Unit xmin = (Unit)( _visibleArea.getXMin() - ((float)_offsetVA.x()/_scale) ); + Unit xmax = (Unit)( xmin + ((float)_drawingBuffer.width()/_scale) ) ; + Unit ymax = (Unit)( _visibleArea.getYMax() + ((float)_offsetVA.y()/_scale) ); + Unit ymin = (Unit)( ymax - ((float)_drawingBuffer.height()/_scale) ) ; + + _displayArea = Box ( xmin, ymin, xmax, ymax ); + + redraw (); +} + + +void CellWidget::setScale ( float scale ) +{ + _scale = scale; + + Point center = _visibleArea.getCenter(); + + _visibleArea.makeEmpty (); + _visibleArea.merge ( (Unit)( center.getX() - width () / (_scale*2) ) + , (Unit)( center.getY() - height() / (_scale*2) ) + , (Unit)( center.getX() + width () / (_scale*2) ) + , (Unit)( center.getY() + height() / (_scale*2) ) + ); + +//cerr << "_visibleArea: " << _visibleArea << " (offset: " << _offsetVA.x() << ")" << endl; +//cerr << " " << center << endl; + + screenReframe (); +} + + +void CellWidget::reframe ( const Box& box ) +{ +//cerr << "CellWidget::reframe() - " << box << endl; +//cerr << " widget size := " << _drawingBuffer.width() << "x" << _drawingBuffer.height() << endl; + + int width = this->width (); + int height = this->height (); + + float scaleX = width / (float)box.getWidth (); + float scaleY = height / (float)box.getHeight(); + _scale = min ( scaleX, scaleY ); + +//cerr << " _scale := " << _scale << endl; + + Point center = box.getCenter(); + + width /= 2; + height /= 2; + + _visibleArea = Box ( (Unit)( center.getX() - width / _scale ) + , (Unit)( center.getY() - height / _scale ) + , (Unit)( center.getX() + width / _scale ) + , (Unit)( center.getY() + height / _scale ) + ); + screenReframe (); + +//cerr << " _displayArea: " << _displayArea << " (offset: " << _offsetVA.x() << ")" << endl; +} + + +void CellWidget::fitToContents () +{ + reframe ( _cell->getBoundingBox() ); +} + + +void CellWidget::shiftLeft ( int dx ) +{ +//cerr << "CellWidget::shiftLeft() - " << dx << " (offset: " << _offsetVA.rx() << ")" << endl; + + int leftShift = ( 1 + ( dx - _offsetVA.rx() ) / _stripWidth ) * _stripWidth; + + _displayArea.translate ( - (Unit)( leftShift / _scale ) , 0 ); + _visibleArea.translate ( - (Unit)( leftShift / _scale ) , 0 ); + _offsetVA.rx() -= dx - leftShift; + + if ( leftShift >= _drawingBuffer.width() ) { + redraw (); + } else { + //cerr << "Left Shift " << leftShift << " (offset: " << _offsetVA.rx() << ")" << endl; + _painter.begin ( &_drawingBuffer ); + _painter.drawPixmap ( leftShift, 0 + , _drawingBuffer + , 0, 0 + , _drawingBuffer.width()-leftShift, _drawingBuffer.height() + ); + _painter.end (); + + redraw ( QRect ( QPoint ( 0, 0 ) + , QSize ( leftShift, _drawingBuffer.height() )) ); + } + + assert ( _offsetVA.rx() >= 0 ); +} + + +void CellWidget::shiftRight ( int dx ) +{ +//cerr << "CellWidget::shiftRight() - " << dx << " (offset: " << _offsetVA.rx() << ")" << endl; + + int rightShift = ( ( _offsetVA.rx() + dx ) / _stripWidth ) * _stripWidth; + + _displayArea.translate ( (Unit)( rightShift / _scale ) , 0 ); + _visibleArea.translate ( (Unit)( rightShift / _scale ) , 0 ); + _offsetVA.rx() += dx - rightShift; + +//cerr << " _displayArea: " << _displayArea << endl; + + if ( rightShift >= _drawingBuffer.width() ) { + redraw (); + } else { + //cerr << " Right Shift " << rightShift << " (offset: " << _offsetVA.rx() << ")" << endl; + _painter.begin ( &_drawingBuffer ); + _painter.drawPixmap ( 0, 0 + , _drawingBuffer + , rightShift, 0 + , _drawingBuffer.width()-rightShift, _drawingBuffer.height() + ); + _painter.end (); + + redraw ( QRect ( QPoint ( _drawingBuffer.width()-rightShift, 0 ) + , QSize ( rightShift, _drawingBuffer.height() )) ); + } + + assert ( _offsetVA.rx() >= 0 ); +} + + +void CellWidget::shiftUp ( int dy ) +{ +//cerr << "CellWidget::shiftUp() - " << dy << " (offset: " << _offsetVA.ry() << ")" << endl; + + int upShift = ( 1 + ( dy - _offsetVA.ry() ) / _stripWidth ) * _stripWidth; + + _displayArea.translate ( 0, (Unit)( upShift / _scale ) ); + _visibleArea.translate ( 0, (Unit)( upShift / _scale ) ); + _offsetVA.ry() -= dy - upShift; + + if ( upShift >= _drawingBuffer.height() ) { + redraw (); + } else { + //cerr << "Left Shift " << upShift << " (offset: " << _offsetVA.ry() << ")" << endl; + _painter.begin ( &_drawingBuffer ); + _painter.drawPixmap ( 0, upShift + , _drawingBuffer + , 0, 0 + , _drawingBuffer.width(), _drawingBuffer.height()-upShift + ); + _painter.end (); + + redraw ( QRect ( QPoint ( 0, 0 ) + , QSize ( _drawingBuffer.width(), upShift )) ); + } + + assert ( _offsetVA.ry() >= 0 ); +} + + +void CellWidget::shiftDown ( int dy ) +{ +//cerr << "CellWidget::shiftDown() - " << dy << " (offset: " << _offsetVA.ry() << ")" << endl; + + int downShift = ( ( _offsetVA.ry() + dy ) / _stripWidth ) * _stripWidth; + + _displayArea.translate ( 0, - (Unit)( downShift / _scale ) ); + _visibleArea.translate ( 0, - (Unit)( downShift / _scale ) ); + _offsetVA.ry() += dy - downShift; + + if ( downShift >= _drawingBuffer.height() ) { + redraw (); + } else { + //cerr << "Right Shift " << downShift << " (offset: " << _offsetVA.ry() << ")" << endl; + _painter.begin ( &_drawingBuffer ); + _painter.drawPixmap ( 0, 0 + , _drawingBuffer + , 0, downShift + , _drawingBuffer.width(), _drawingBuffer.height()-downShift + ); + _painter.end (); + + redraw ( QRect ( QPoint ( 0, _drawingBuffer.height()-downShift ) + , QSize ( _drawingBuffer.width(), downShift )) ); + } + + assert ( _offsetVA.ry() >= 0 ); +} + + +void CellWidget::paintEvent ( QPaintEvent* ) +{ +//cerr << "CellWidget::paintEvent()" << endl; + + QPainter painter ( this ); + painter.drawPixmap ( 0, 0, _drawingBuffer, _offsetVA.rx(), _offsetVA.ry(), width(), height() ); +} + + +void CellWidget::resizeEvent ( QResizeEvent* ) +{ + QSize uaDelta ( 0, 0 ); + QSize uaSize = geometry().size(); + + uaSize.rwidth () += 2*_stripWidth; + uaSize.rheight() += 2*_stripWidth; + + if ( uaSize.width () > _drawingBuffer.width () ) + uaDelta.rwidth () = uaSize.width () - _drawingBuffer.width (); + + if ( uaSize.height() > _drawingBuffer.height() ) + uaDelta.rheight() = uaSize.height() - _drawingBuffer.height(); + +//cerr << "New UA widget size: " << uaSize.width() << "x" << uaSize.height() << endl; + + if ( uaDelta.width() || uaDelta.height() ) { + _displayArea.inflate ( 0, 0, (Unit)(uaDelta.width()/_scale), (Unit)(uaDelta.height()/_scale) ); + _visibleArea.inflate ( 0, 0, (Unit)(uaDelta.width()/_scale), (Unit)(uaDelta.height()/_scale) ); + //cerr << "new " << _displayArea << endl; + + //cerr << "Previous buffer size: " << _drawingBuffer.width () << "x" + // << _drawingBuffer.height() << endl; + + QSize bufferSize ( ( ( uaSize.width () / _stripWidth ) + 1 ) * _stripWidth + , ( ( uaSize.height() / _stripWidth ) + 1 ) * _stripWidth ); + _drawingBuffer = QPixmap ( bufferSize ); + + //cerr << "Effective buffer resize to: " << bufferSize.width() << "x" + // << bufferSize.height() << endl; + } + redraw (); +} + + +void CellWidget::keyPressEvent ( QKeyEvent* event ) +{ + switch ( event->key() ) { + case Qt::Key_Up: goUp (); break; + case Qt::Key_Down: goDown (); break; + case Qt::Key_Left: goLeft (); break; + case Qt::Key_Right: goRight (); break; + case Qt::Key_Z: setScale ( _scale*2.0 ); break; + case Qt::Key_M: setScale ( _scale/2.0 ); break; + } +} + + +void CellWidget::mouseMoveEvent ( QMouseEvent* event ) +{ +//cerr << "CellWidget::mouseMoveEvent()" << endl; + + if ( _mouseGo ) { + int dx = event->x() - _lastMousePosition.x(); + dx <<= 1; + //cerr << "dX (px): " << dx << " _offsetVA.rx() " << _offsetVA.rx() << endl; + if ( dx > 0 ) goLeft ( dx ); + if ( dx < 0 ) goRight ( -dx ); + + int dy = event->y() - _lastMousePosition.y(); + dy <<= 1; + //cerr << "dY (px): " << dy << " _offsetVA.ry() " << _offsetVA.ry() << endl; + if ( dy > 0 ) goUp ( dy ); + if ( dy < 0 ) goDown ( -dy ); + + _lastMousePosition = event->pos(); + } +} + + +void CellWidget::mousePressEvent ( QMouseEvent* event ) +{ + if ( ( event->button() == Qt::LeftButton ) && !_mouseGo ) { + _mouseGo = true; + _lastMousePosition = event->pos(); + pushCursor ( Qt::ClosedHandCursor ); + } +} + + +void CellWidget::mouseReleaseEvent ( QMouseEvent* event ) +{ + if ( ( event->button() == Qt::LeftButton ) && _mouseGo ) { + _mouseGo = false; + popCursor (); + } +} + + +QPoint CellWidget::getScreenPoint ( Unit x, Unit y ) const +{ + return QPoint ( getScreenX(x), getScreenY(y) ); +} + + +QPoint CellWidget::getScreenPoint ( const Point& point ) const +{ + return getScreenPoint ( point.getX(), point.getY() ); +} + + +QRect CellWidget::getScreenRect ( Unit x1, Unit y1, Unit x2, Unit y2 ) const +{ + return QRect ( getScreenX(x1) + , getScreenY(y2) + , getScreenX(x2) - getScreenX(x1) + , getScreenY(y1) - getScreenY(y2) + ); +} + + +QRect CellWidget::getScreenRect ( const Box& box ) const +{ + return getScreenRect ( box.getXMin() + , box.getYMin() + , box.getXMax() + , box.getYMax() + ); +} + + +void CellWidget::setShowBoundaries ( bool state ) +{ + if ( _showBoundaries != state ) { + _showBoundaries = state; + redraw (); + } +} + + +} // End of Hurricane namespace. diff --git a/hurricane/src/hviewer/CellWidget.h b/hurricane/src/hviewer/CellWidget.h new file mode 100644 index 00000000..ed07797b --- /dev/null +++ b/hurricane/src/hviewer/CellWidget.h @@ -0,0 +1,221 @@ + +// -*- C++ -*- + + +# ifndef __CELL_WIDGET_H__ +# define __CELL_WIDGET_H__ + +# include + +# include + +# include +# include +# include +# include +# include + +class QCursor; +class QResizeEvent; +class QMouseEvent; +class QKeyEvent; +class QAction; + + +# include "Commons.h" +# include "Point.h" +# include "Box.h" +# include "Transformation.h" + +# include "DisplayStyle.h" + + + + +namespace Hurricane { + + class BasicLayer; + class Go; + class Cell; + class Instance; + class Slice; + class Segment; + class Contact; + + class PaletteEntry; + class Palette; +//class MapView; + + + class CellWidget : public QWidget { + Q_OBJECT; + + // Attributes. + protected: + static const int _stripWidth; + vector _cursors; +// MapView* _mapView; + Palette* _palette; + Box _displayArea; + Box _visibleArea; + float _scale; + QPoint _offsetVA; + QPixmap _drawingBuffer; + QPainter _painter; + QPoint _lastMousePosition; + Cell* _cell; + bool _mouseGo; + bool _openCell; + bool _showBoundaries; + size_t _redrawRectCount; + + public: + CellWidget ( Cell* cell ); + virtual ~CellWidget (); + + public slots: + void redraw ( QRect redrawArea ); + inline void redraw (); + void goLeft ( int dx = 0 ); + void goRight ( int dx = 0 ); + void goUp ( int dy = 0 ); + void goDown ( int dy = 0 ); + void fitToContents (); + void setScale ( float scale ); + void setShowBoundaries ( bool state ); + void reframe ( const Box& box ); + void screenReframe (); + void shiftLeft ( int dx ); + void shiftRight ( int dx ); + void shiftUp ( int dy ); + void shiftDown ( int dy ); + + // Qt QWidget Overloads. + public: + void pushCursor ( Qt::CursorShape cursor ); + void popCursor (); + QSize minimumSizeHint () const; + void paintEvent ( QPaintEvent* ); + void resizeEvent ( QResizeEvent* ); + void keyPressEvent ( QKeyEvent* ); + void mouseMoveEvent ( QMouseEvent* ); + void mousePressEvent ( QMouseEvent* ); + void mouseReleaseEvent ( QMouseEvent* ); + + // Geometric conversions. + public: + QRect getScreenRect ( Unit x1, Unit y1, Unit x2, Unit y2 ) const; + QRect getScreenRect ( const Box& box ) const; + QPoint getScreenPoint ( Unit x, Unit y ) const; + QPoint getScreenPoint ( const Point& point ) const; + inline int getScreenX ( Unit x ) const; + inline int getScreenY ( Unit y ) const; + inline int getScreenLength ( Unit length ) const; + inline Unit getX ( int x ) const; + inline Unit getY ( int y ) const; + inline Unit getLength ( int length ) const; + inline Box getBox ( const QRect& rect ) const; + + // Painter control & Hurricane objects drawing primitives. + public: + void drawBoundaries ( const Cell* , const Box&, const Transformation& ); + void drawBoundaries ( const Instance*, const Box&, const Transformation& ); + bool isDrawable ( PaletteEntry* entry ); + void drawCell ( const Cell* , const BasicLayer*, const Box&, const Transformation& ); + void drawInstance ( const Instance*, const BasicLayer*, const Box&, const Transformation& ); + void drawSlice ( const Slice* , const BasicLayer*, const Box&, const Transformation& ); + void drawGo ( const Go* , const BasicLayer*, const Box&, const Transformation& ); + void drawSegment ( const Segment* , const BasicLayer*, const Box&, const Transformation& ); + void drawContact ( const Contact* , const BasicLayer*, const Box&, const Transformation& ); + void drawBox ( const Box& ); + void drawLine ( const Point&, const Point& ); + + // Accessors. + public: +// MapView* getMapView () { return _mapView; }; + inline Cell* getCell () const; + inline Palette* getPalette (); + inline bool showBoundaries () const; + + // Modifiers. + public: + }; + + + + +inline void CellWidget::redraw () +{ + redraw ( QRect(QPoint(0,0),_drawingBuffer.size()) ); +} + + +inline int CellWidget::getScreenX ( Unit x ) const +{ + return (int)rint ( (float)( x - _displayArea.getXMin() ) * _scale ); +} + + +inline int CellWidget::getScreenY ( Unit y ) const +{ + return (int)rint ( (float)( _displayArea.getYMax() - y ) * _scale ); +} + + +inline int CellWidget::getScreenLength ( Unit length ) const +{ + return (int)rint ( (float)length * _scale ); +} + + +inline Unit CellWidget::getX ( int x ) const +{ + return (Unit)(x/_scale) + _displayArea.getXMin(); +} + + +inline Unit CellWidget::getY ( int y ) const +{ + return _displayArea.getYMax() - (Unit)(y/_scale); +} + + +inline Unit CellWidget::getLength ( int length ) const +{ + return (int)( (float)length / _scale ); +} + + +inline Box CellWidget::getBox ( const QRect& rect ) const +{ + return Box ( getX(rect.x()) + , getY(rect.y()) + , getX(rect.x()+rect.width ()) + , getY(rect.y()+rect.height())); +} + + +inline Cell* CellWidget::getCell () const +{ + return _cell; +} + + +inline Palette* CellWidget::getPalette () +{ + return _palette; +} + + +inline bool CellWidget::showBoundaries () const +{ + return _showBoundaries; +} + + + + +} // End of Hurricane namespace. + + +# endif diff --git a/hurricane/src/hviewer/DisplayStyle.cpp b/hurricane/src/hviewer/DisplayStyle.cpp new file mode 100644 index 00000000..4d1bf482 --- /dev/null +++ b/hurricane/src/hviewer/DisplayStyle.cpp @@ -0,0 +1,303 @@ + +// -*- C++ -*- + + +# include + +# include "DisplayStyle.h" + + + + +namespace Hurricane { + + + const Name DisplayStyle::UnmatchedGroup; + const Name DisplayStyle::Viewer = "Viewer"; + const Name DisplayStyle::Fallback = "fallback"; + const Name DisplayStyle::Background = "background"; + const Name DisplayStyle::Foreground = "foreground"; + const Name DisplayStyle::Rubber = "rubber"; + const Name DisplayStyle::Phantom = "phantom"; + const Name DisplayStyle::Boundaries = "boundaries"; + const Name DisplayStyle::Marker = "marker"; + const Name DisplayStyle::SelectionDraw = "selectionDraw"; + const Name DisplayStyle::SelectionFill = "selectionFill"; + const Name DisplayStyle::Grid = "grid"; + const Name DisplayStyle::Spot = "spot"; + const Name DisplayStyle::Ghost = "ghost"; + const Name DisplayStyle::Text = "text"; + const Name DisplayStyle::Undef = "undef"; + + + + DrawingStyle::DrawingStyle ( const Name& name + , const string& pattern + , int red + , int green + , int blue + , int borderWidth + , float threshold + ) : _name(name) + , _pattern(pattern) + , _color(QColor(red,green,blue)) + , _pen(_color) + , _brush(Hurricane::getBrush(_pattern,red,green,blue)) + , _threshold(threshold) + , _refcount(1) + { + if ( borderWidth ) + _pen.setWidth ( borderWidth ); + else + _pen.setStyle ( Qt::NoPen ); + } + + + + DrawingStyle* DrawingStyle::create ( const Name& name + , const string& pattern + , int red + , int green + , int blue + , int borderWidth + , float threshold + ) + { + return new DrawingStyle ( name, pattern, red, green, blue, borderWidth, threshold ); + } + + + DrawingStyle::~DrawingStyle () + { + assert ( _refcount == 0 ); + } + + + size_t DrawingStyle::unlink () + { + _refcount--; + + if ( !_refcount ) { + delete this; + return 0; + } + + return _refcount; + } + + + DrawingStyle* DrawingStyle::link () + { + _refcount++; + + return this; + } + + + DrawingGroup::DrawingGroup ( const Name& name ) + : _name(name), _drawingStyles() + { + } + + + DrawingGroup* DrawingGroup::getClone () + { + DrawingGroup* clone = new DrawingGroup ( getName() ); + + for ( size_t i=0 ; i < _drawingStyles.size() ; i++ ) + clone->_drawingStyles.push_back ( _drawingStyles[i]->link() ); + + return clone; + } + + + DrawingGroup::~DrawingGroup () + { + for ( size_t i=0 ; i < _drawingStyles.size() ; i++ ) + _drawingStyles[i]->unlink (); + } + + + size_t DrawingGroup::findIndex ( const Name& key ) const + { + for ( size_t i=0 ; i < _drawingStyles.size() ; i++ ) { + if ( _drawingStyles[i]->getName() == key ) + return i; + } + + return InvalidIndex; + } + + + DrawingStyle* DrawingGroup::find ( const Name& key ) + { + size_t i = findIndex ( key ); + if ( i != InvalidIndex ) + return _drawingStyles[i]; + + return NULL; + } + + + DrawingStyle* DrawingGroup::addDrawingStyle ( const Name& key + , const string& pattern + , int red + , int green + , int blue + , int borderWidth + , float threshold + ) + { + size_t i = findIndex ( key ); + if ( i != InvalidIndex ) { + _drawingStyles[i]->unlink (); + } else { + i = _drawingStyles.size (); + _drawingStyles.push_back ( NULL ); + } + + return _drawingStyles[i] = + DrawingStyle::create ( key, pattern, red, green, blue, borderWidth, threshold ); + } + + + DisplayStyle::DisplayStyle ( const Name& name ) + : _name(name), _groups() + { + addDrawingStyle ( Viewer, Fallback , "FFFFFFFFFFFFFFFF", 0, 0, 0, 1, 1.0 ); + addDrawingStyle ( Viewer, Background , "FFFFFFFFFFFFFFFF", 50, 50, 50, 1, 1.0 ); + addDrawingStyle ( Viewer, Foreground , "FFFFFFFFFFFFFFFF", 255, 255, 255, 1, 1.0 ); + addDrawingStyle ( Viewer, Rubber , "FFFFFFFFFFFFFFFF", 192, 0, 192, 1, 1.0 ); + addDrawingStyle ( Viewer, Phantom , "FFFFFFFFFFFFFFFF", 139, 134, 130, 1, 1.0 ); + addDrawingStyle ( Viewer, Boundaries , "0000000000000000", 208, 199, 192, 1, 1.0 ); + addDrawingStyle ( Viewer, Marker , "FFFFFFFFFFFFFFFF", 80, 250, 80, 1, 1.0 ); + addDrawingStyle ( Viewer, SelectionDraw, "FFFFFFFFFFFFFFFF", 255, 255, 255, 1, 1.0 ); + addDrawingStyle ( Viewer, SelectionFill, "FFFFFFFFFFFFFFFF", 255, 255, 255, 1, 1.0 ); + addDrawingStyle ( Viewer, Grid , "FFFFFFFFFFFFFFFF", 255, 255, 255, 1, 1.0 ); + addDrawingStyle ( Viewer, Spot , "FFFFFFFFFFFFFFFF", 255, 255, 255, 1, 1.0 ); + addDrawingStyle ( Viewer, Ghost , "FFFFFFFFFFFFFFFF", 255, 255, 255, 1, 1.0 ); + addDrawingStyle ( Viewer, Text , "8822441188224411", 255, 255, 255, 0, 1.0 ); + addDrawingStyle ( Viewer, Undef , "2244118822441188", 238, 130, 238, 0, 1.0 ); + } + + + DisplayStyle::~DisplayStyle () + { + for ( size_t i=0 ; i < _groups.size() ; i++ ) { + delete _groups[i]; + } + } + + + const Name& DisplayStyle::getGroup ( const Name& key ) const + { + for ( size_t gi=0 ; gi < _groups.size() ; gi++ ) { + DrawingStyle* style = _groups[gi]->find ( key ); + if ( style ) + return _groups[gi]->getName(); + } + + return UnmatchedGroup; + } + + + const string& DisplayStyle::getPattern ( const Name& key ) const + { + return find(key)->getPattern(); + } + + + const QColor& DisplayStyle::getColor ( const Name& key ) const + { + return find(key)->getColor(); + } + + + const QPen& DisplayStyle::getPen ( const Name& key ) const + { + return find(key)->getPen(); + } + + + const QBrush& DisplayStyle::getBrush ( const Name& key ) const + { + return find(key)->getBrush(); + } + + + float DisplayStyle::getThreshold ( const Name& key ) const + { + return find(key)->getThreshold(); + } + + + void DisplayStyle::findOrCreate ( const Name& groupKey, size_t& gi ) + { + for ( gi=0 ; gi < _groups.size() ; gi++ ) { + if ( _groups[gi]->getName() == groupKey ) + break; + } + if ( gi == _groups.size() ) + _groups.push_back ( new DrawingGroup(groupKey) ); + } + + + void DisplayStyle::find ( const Name& groupKey + , const Name& key + , size_t& gi + , size_t& si + ) + { + for ( gi=0 ; gi < _groups.size() ; gi++ ) { + if ( _groups[gi]->getName() == groupKey ) { + si = _groups[gi]->findIndex ( key ); + if ( si != InvalidIndex ) + return; + } + } + + gi = InvalidIndex; + si = InvalidIndex; + } + + + DrawingStyle* DisplayStyle::find ( const Name& key ) const + { + for ( size_t gi=0 ; gi < _groups.size() ; gi++ ) { + DrawingStyle* style = _groups[gi]->find ( key ); + if ( style ) + return style; + } + + return find ( "fallback" ); + } + + + void DisplayStyle::addDrawingStyle ( const Name& groupKey + , const Name& key + , const string& pattern + , int red + , int green + , int blue + , int borderWidth + , float threshold + ) + { + size_t gi; + findOrCreate ( groupKey, gi ); + + _groups[gi]->addDrawingStyle ( key, pattern, red, green, blue, borderWidth, threshold ); + } + + + void DisplayStyle::inheritFrom ( const DisplayStyle* base ) + { + assert ( base != NULL ); + + for ( size_t gi=0 ; gi < base->_groups.size() ; gi++ ) { + _groups.push_back ( base->_groups[gi]->getClone() ); + } + } + + +} diff --git a/hurricane/src/hviewer/DisplayStyle.h b/hurricane/src/hviewer/DisplayStyle.h new file mode 100644 index 00000000..a1b29304 --- /dev/null +++ b/hurricane/src/hviewer/DisplayStyle.h @@ -0,0 +1,198 @@ + +// -*- C++ -*- + + +# ifndef __DISPLAYSTYLE_H__ +# define __DISPLAYSTYLE_H__ + + +# include +# include + +# include +# include +# include + +# include "Commons.h" +# include "Name.h" + +# include "ScreenUtilities.h" + + +namespace Hurricane { + + + + + class DrawingStyle { + + public: + // Constructors & Destructors. + static DrawingStyle* create ( const Name& name + , const string& pattern ="FFFFFFFFFFFFFFFF" + , int red =0 + , int green =0 + , int blue =0 + , int borderWidth=0 + , float threshold =1.0 + ); + DrawingStyle* link (); + size_t unlink (); + + // Accessors. + inline const Name& getName () const; + inline const string& getPattern () const; + inline const QColor& getColor () const; + inline const QPen& getPen () const; + inline const QBrush& getBrush () const; + inline float getThreshold () const; + + protected: + // Internal - Attributes. + const Name _name; + string _pattern; + QColor _color; + QPen _pen; + QBrush _brush; + float _threshold; + size_t _refcount; + + // Internal - Constructors & Destructors. + DrawingStyle ( const Name& name + , const string& pattern ="FFFFFFFFFFFFFFFF" + , int red =0 + , int green =0 + , int blue =0 + , int borderWidth=0 + , float threshold =1.0 + ); + DrawingStyle ( const DrawingStyle& ); + ~DrawingStyle (); + DrawingStyle& operator= ( const DrawingStyle& ); + + }; + + + + + class DrawingGroup { + + public: + // Constructors & Destructors. + DrawingGroup ( const Name& name ); + ~DrawingGroup (); + DrawingGroup* getClone (); + + // Methods. + inline const Name& getName () const; + inline vector& getDrawingStyles (); + size_t findIndex ( const Name& key ) const; + DrawingStyle* find ( const Name& key ); + DrawingStyle* addDrawingStyle ( const Name& key + , const string& pattern + , int red + , int green + , int blue + , int borderWidth + , float threshold + ); + + protected: + // Internal - Attributes. + const Name _name; + vector _drawingStyles; + + // Internal - Constructors & Destructors. + DrawingGroup ( const DrawingGroup& ); + DrawingGroup& operator= ( const DrawingGroup& ); + + }; + + + + + class DisplayStyle { + + public: + // Static Members. + static const Name Viewer; + static const Name Fallback; + static const Name Background; + static const Name Foreground; + static const Name Rubber; + static const Name Phantom; + static const Name Boundaries; + static const Name Marker; + static const Name SelectionDraw; + static const Name SelectionFill; + static const Name Grid; + static const Name Spot; + static const Name Ghost; + static const Name Text; + static const Name Undef; + static const Name UnmatchedGroup; + + // Constructor & Destructor. + DisplayStyle ( const Name& name ); + ~DisplayStyle (); + + // Accessors. + const Name& getName () const; + const Name& getGroup ( const Name& key ) const; + const string& getPattern ( const Name& key ) const; + const QColor& getColor ( const Name& key ) const; + const QPen& getPen ( const Name& key ) const; + const QBrush& getBrush ( const Name& key ) const; + float getThreshold ( const Name& key ) const; + inline vector& getDrawingGroups (); + DrawingStyle* find ( const Name& key ) const; + + // Modifiers. + void inheritFrom ( const DisplayStyle* base ); + void addDrawingStyle ( const Name& groupKey + , const Name& key + , const string& pattern + , int red + , int green + , int blue + , int borderWidth + , float threshold + ); + + protected: + // Internals - Attributes. + const Name _name; + vector _groups; + + // Internals - Methods. + void findOrCreate ( const Name& groupKey + , size_t& gi ); + void find ( const Name& groupKey + , const Name& key + , size_t& gi + , size_t& si ); + + }; + + + + + // Functions. + inline const Name& DrawingStyle::getName () const { return _name; } + inline const string& DrawingStyle::getPattern () const { return _pattern; } + inline const QColor& DrawingStyle::getColor () const { return _color; } + inline const QPen& DrawingStyle::getPen () const { return _pen; } + inline const QBrush& DrawingStyle::getBrush () const { return _brush; } + inline float DrawingStyle::getThreshold () const { return _threshold; } + + inline const Name& DrawingGroup::getName () const { return _name; } + inline vector& DrawingGroup::getDrawingStyles () { return _drawingStyles; } + + inline const Name& DisplayStyle::getName () const { return _name; } + inline vector& DisplayStyle::getDrawingGroups () { return _groups; } + + +} // End of Hurricane namespace. + + +# endif diff --git a/hurricane/src/hviewer/Graphics.cpp b/hurricane/src/hviewer/Graphics.cpp new file mode 100644 index 00000000..78051d1c --- /dev/null +++ b/hurricane/src/hviewer/Graphics.cpp @@ -0,0 +1,176 @@ + + +// -*- C++ -*- + + +# include + +# include +# include +# include +# include + +# include "Name.h" + +# include "DisplayStyle.h" +# include "Graphics.h" + + + + +namespace Hurricane { + + + Graphics* Graphics::_singleton = NULL; + + + Graphics::Graphics () + : _styles() + , _active(NULL) + { + _styles.push_back ( new DisplayStyle("Fallback") ); + _active = _styles[0]; + } + + + Graphics::~Graphics () + { + delete _singleton; + } + + + Graphics* Graphics::getGraphics () + { + if ( !_singleton ) + _singleton = new Graphics (); + + return _singleton; + } + + + const QFont Graphics::getFixedFont ( bool bold, bool underline ) + { + const QFont defaultFont = QApplication::font (); + + QFont fixedFont ( "Bitstream Vera Sans Mono", defaultFont.pointSize() ); + if ( bold ) fixedFont.setBold ( true ); + if ( underline ) fixedFont.setUnderline ( true ); + + return fixedFont; + } + + + size_t Graphics::_findStyle ( const Name& name ) const + { + size_t si = 0; + for ( ; si < _styles.size() ; si++ ) + if ( _styles[si]->getName() == name ) + break; + + return si; + } + + + + void Graphics::_addStyle ( DisplayStyle* displayStyle ) + { + size_t si = _findStyle(displayStyle->getName()); + if ( si != _styles.size() ) { + cerr << "[WARNING] Graphics::addStyle(): overriding style \"" + << displayStyle->getName() << "\"." << endl; + + delete _styles [ si ]; + } else { + _styles.push_back ( NULL ); + } + + _styles [ si ] = displayStyle; + _active = _styles [ si ]; + } + + + void Graphics::_setStyle ( const Name& key ) + { + size_t si = _findStyle(key); + if ( si == _styles.size() ) { + cerr << "[WARNING] Graphics::setStyle(): no style named \"" << key << "\"." << endl; + return; + } + + _active = _styles [ si ]; + } + + + DisplayStyle* Graphics::_getStyle ( const Name& key ) + { + size_t si = _findStyle(key); + if ( si == _styles.size() ) + return NULL; + + return _styles [ si ]; + } + + + void Graphics::addStyle ( DisplayStyle* displayStyle ) + { + getGraphics()->_addStyle ( displayStyle ); + } + + + void Graphics::setStyle ( const Name& key ) + { + getGraphics()->_setStyle ( key ); + } + + + DisplayStyle* Graphics::getStyle ( const Name& key ) + { + return getGraphics()->_getStyle ( key ); + } + + + DisplayStyle* Graphics::getStyle () + { + return getGraphics()->_getStyle (); + } + + + const Name& Graphics::getGroup ( const Name& key ) + { + return getGraphics()->_getGroup ( key ); + } + + + const QColor& Graphics::getColor ( const Name& key ) + { + return getGraphics()->_getColor ( key ); + } + + + const QPen& Graphics::getPen ( const Name& key ) + { + return getGraphics()->_getPen ( key ); + } + + + const QBrush& Graphics::getBrush ( const Name& key ) + { + return getGraphics()->_getBrush ( key ); + } + + + const string& Graphics::getPattern ( const Name& key ) + { + return getGraphics()->_getPattern ( key ); + } + + + float Graphics::getThreshold ( const Name& key ) + { + return getGraphics()->_getThreshold ( key ); + } + + + + +} // End of Hurricane namespace. diff --git a/hurricane/src/hviewer/Graphics.h b/hurricane/src/hviewer/Graphics.h new file mode 100644 index 00000000..d4383163 --- /dev/null +++ b/hurricane/src/hviewer/Graphics.h @@ -0,0 +1,102 @@ + +// -*- C++ -*- + + +# ifndef __GRAPHICS_H__ +# define __GRAPHICS_H__ + + +# include +# include + +# include "DisplayStyle.h" + +class QFont; +class QColor; +class QPen; +class QBrush; + + + + +namespace Hurricane { + + + class Name; + + + class Graphics { + + public: + // Accessors. + static Graphics* getGraphics (); + static const QFont getFixedFont ( bool bold=false, bool underline=false ); + static const Name& getGroup ( const Name& key ); + static const QColor& getColor ( const Name& key ); + static const QPen& getPen ( const Name& key ); + static const QBrush& getBrush ( const Name& key ); + static const string& getPattern ( const Name& key ); + static float getThreshold ( const Name& key ); + + // Modifiers. + static void addStyle ( DisplayStyle* displayStyle ); + static void setStyle ( const Name& key ); + static DisplayStyle* getStyle ( const Name& key ); + static DisplayStyle* getStyle (); + + // Internals - Attributes. + protected: + static Graphics* _singleton; + vector _styles; + DisplayStyle* _active; + + // Internals - Constructors & Destructors. + Graphics (); + Graphics ( const Graphics& ); + Graphics& operator= ( const Graphics& ); + ~Graphics (); + + // Internals - Methods. + size_t _findStyle ( const Name& key ) const; + void _addStyle ( DisplayStyle* displayStyle ); + void _setStyle ( const Name& key ); + DisplayStyle* _getStyle ( const Name& key ); + DisplayStyle* _getStyle () const; + inline const Name& _getGroup ( const Name& key ) const; + inline const QColor& _getColor ( const Name& key ) const; + inline const QPen& _getPen ( const Name& key ) const; + inline const QBrush& _getBrush ( const Name& key ) const; + inline const string& _getPattern ( const Name& key ) const; + inline float _getThreshold ( const Name& key ) const; + + }; + + + inline const Name& Graphics::_getGroup ( const Name& name ) const + { return _active->getGroup(name); } + + inline const QColor& Graphics::_getColor ( const Name& name ) const + { return _active->getColor(name); } + + inline const QPen& Graphics::_getPen ( const Name& name ) const + { return _active->getPen(name); } + + inline const QBrush& Graphics::_getBrush ( const Name& name ) const + { return _active->getBrush(name); } + + inline const string& Graphics::_getPattern ( const Name& name ) const + { return _active->getPattern(name); } + + inline float Graphics::_getThreshold ( const Name& name ) const + { return _active->getThreshold(name); } + + inline DisplayStyle* Graphics::_getStyle () const + { return _active; } + + + + +} // End of Hurricane namespace. + + +# endif diff --git a/hurricane/src/hviewer/GroupPaletteEntry.cpp b/hurricane/src/hviewer/GroupPaletteEntry.cpp new file mode 100644 index 00000000..373d9c33 --- /dev/null +++ b/hurricane/src/hviewer/GroupPaletteEntry.cpp @@ -0,0 +1,153 @@ + +// -*- C++ -*- + + +# include +# include + +# include "Graphics.h" +# include "GroupPaletteEntry.h" +# include "Palette.h" + + +namespace Hurricane { + + + GroupPaletteEntry::GroupPaletteEntry ( Palette* palette, const Name& name ) + : PaletteEntry(palette) + , _name(name) + , _button(NULL) + , _index(0) + , _expanded(true) + { + } + + + GroupPaletteEntry* GroupPaletteEntry::create ( Palette* palette, const Name& name ) + { + GroupPaletteEntry* entry = new GroupPaletteEntry ( palette, name ); + + entry->_postCreate (); + + return entry; + } + + + void GroupPaletteEntry::_postCreate () + { + + _index = _palette->getEntries().size(); + + QHBoxLayout* layout = new QHBoxLayout (); + layout->setContentsMargins ( 0, 0, 0, 0 ); + + _button = new QPushButton ( this ); + _button->setFlat ( true ); + _button->setText ( getString(getName()).c_str() ); + _button->setFont ( Graphics::getFixedFont(true,true) ); + + layout->addWidget ( _button ); + layout->addStretch (); + + setLayout ( layout ); + + connect ( _button, SIGNAL(clicked()), this, SLOT(toggle()) ); + } + + + bool GroupPaletteEntry::isGroup () const + { + return true; + } + + + bool GroupPaletteEntry::isBasicLayer () const + { + return false; + } + + + const Name& GroupPaletteEntry::getName () const + { + return _name; + } + + + BasicLayer* GroupPaletteEntry::getBasicLayer () + { + return NULL; + } + + + bool GroupPaletteEntry::isChecked () const + { + return _expanded; + } + + + void GroupPaletteEntry::setChecked ( bool state ) + { + _expanded = state; + + hideShow (); + } + + + void GroupPaletteEntry::toggle () + { + _expanded = !_expanded; + + hideShow (); + } + + + void GroupPaletteEntry::hideShow () + { + vector entries = _palette->getEntries (); + + if ( entries[_index] != this ) + cerr << "[ERROR] Incoherent index for group \"" << getString(getName()) << "\"." << endl; + + _button->setText ( getLabel().c_str() ); + + for ( size_t i=_index+1 ; iisGroup() ) break; + + if ( _expanded ) entries[i]->show (); + else entries[i]->hide (); + } + } + + + string GroupPaletteEntry::getLabel () + { + string label = getString(getName()); + + for ( size_t i=0 ; isetFont ( Graphics::getFixedFont(true,true) ); + else + _button->setFont ( Graphics::getFixedFont(true,false) ); + + label.insert ( 0, spacingLeft, ' ' ); + label.append ( spacingRight, ' ' ); + + return label; + } + + +} // End of Hurricane namespace. diff --git a/hurricane/src/hviewer/GroupPaletteEntry.h b/hurricane/src/hviewer/GroupPaletteEntry.h new file mode 100644 index 00000000..21d295e5 --- /dev/null +++ b/hurricane/src/hviewer/GroupPaletteEntry.h @@ -0,0 +1,61 @@ + +// -*- C++ -*- + + +# ifndef __GROUP_PALETTE_ENTRY_H__ +# define __GROUP_PALETTE_ENTRY_H__ + + +class QPushButton; + +# include "Name.h" + +# include "PaletteEntry.h" + + +namespace Hurricane { + + + class GroupPaletteEntry : public PaletteEntry { + Q_OBJECT; + + // Constructor. + public: + static GroupPaletteEntry* create ( Palette* palette, const Name& name ); + + // Methods. + public: + virtual bool isGroup () const; + virtual bool isBasicLayer () const; + virtual const Name& getName () const; + virtual BasicLayer* getBasicLayer (); + virtual bool isChecked () const; + virtual void setChecked ( bool state ); + + // Slots. + public slots: + virtual void toggle (); + + // Internal - Attributes. + protected: + const Name _name; + QPushButton* _button; + size_t _index; + bool _expanded; + + // Internal - Constructor. + GroupPaletteEntry ( Palette* palette, const Name& name ); + GroupPaletteEntry ( const GroupPaletteEntry& ); + GroupPaletteEntry& operator= ( const GroupPaletteEntry& ); + virtual void _postCreate (); + + // Internal - Methods. + void hideShow (); + string getLabel (); + }; + + +} // End of Hurricane namespace. + + +# endif diff --git a/hurricane/src/hviewer/LayerPaletteEntry.cpp b/hurricane/src/hviewer/LayerPaletteEntry.cpp new file mode 100644 index 00000000..2b1fa2fc --- /dev/null +++ b/hurricane/src/hviewer/LayerPaletteEntry.cpp @@ -0,0 +1,96 @@ + +// -*- C++ -*- + + +# include +# include + +# include "BasicLayer.h" + +# include "Graphics.h" +# include "LayerPaletteEntry.h" +# include "Palette.h" + + +namespace Hurricane { + + + LayerPaletteEntry::LayerPaletteEntry ( Palette* entry, BasicLayer* basicLayer ) + : PaletteEntry(entry) + , _basicLayer(basicLayer) + { + } + + + LayerPaletteEntry* LayerPaletteEntry::create ( Palette* palette, BasicLayer* basicLayer ) + { + LayerPaletteEntry* entry = new LayerPaletteEntry ( palette, basicLayer ); + + entry->_postCreate (); + + return entry; + } + + + void LayerPaletteEntry::_postCreate () + { + QHBoxLayout* layout = new QHBoxLayout (); + layout->setContentsMargins ( 0, 0, 0, 0 ); + + layout->addWidget ( new PaletteSample(this) ); + + _checkBox = new QCheckBox ( this ); + _checkBox->setChecked ( true ); + _checkBox->setText ( getString(getName()).c_str() ); + _checkBox->setFont ( Graphics::getFixedFont() ); + layout->addWidget ( _checkBox ); + + setLayout ( layout ); + + connect ( _checkBox, SIGNAL(clicked()), this, SLOT(toggle()) ); + } + + + bool LayerPaletteEntry::isGroup () const + { + return false; + } + + + bool LayerPaletteEntry::isBasicLayer () const + { + return true; + } + + + const Name& LayerPaletteEntry::getName () const + { + return _basicLayer->getName(); + } + + + BasicLayer* LayerPaletteEntry::getBasicLayer () + { + return _basicLayer; + } + + + bool LayerPaletteEntry::isChecked () const + { + return _checkBox->isChecked (); + } + + + void LayerPaletteEntry::setChecked ( bool state ) + { + _checkBox->setChecked ( state ); + } + + + void LayerPaletteEntry::toggle () + { + _palette->redrawCellWidget(); + } + + +} // End of Hurricane namespace. diff --git a/hurricane/src/hviewer/LayerPaletteEntry.h b/hurricane/src/hviewer/LayerPaletteEntry.h new file mode 100644 index 00000000..fbd584e5 --- /dev/null +++ b/hurricane/src/hviewer/LayerPaletteEntry.h @@ -0,0 +1,54 @@ + +// -*- C++ -*- + + +# ifndef __LAYER_PALETTE_ENTRY_H__ +# define __LAYER_PALETTE_ENTRY_H__ + + +class QCheckBox; + +# include "PaletteEntry.h" + + +namespace Hurricane { + + + class LayerPaletteEntry : public PaletteEntry { + Q_OBJECT; + + // Constructor. + public: + static LayerPaletteEntry* create ( Palette* palette, BasicLayer* basicLayer ); + + // Methods. + public: + virtual bool isGroup () const; + virtual bool isBasicLayer () const; + virtual const Name& getName () const; + virtual BasicLayer* getBasicLayer (); + virtual bool isChecked () const; + virtual void setChecked ( bool state ); + + // Slots. + public slots: + virtual void toggle (); + + // Internal - Attributes. + protected: + BasicLayer* _basicLayer; + QCheckBox* _checkBox; + + // Internal - Constructor. + LayerPaletteEntry ( Palette* palette, BasicLayer* basicLayer ); + LayerPaletteEntry ( const LayerPaletteEntry& ); + LayerPaletteEntry& operator= ( const LayerPaletteEntry& ); + virtual void _postCreate (); + + }; + + +} // End of Hurricane namespace. + + +# endif diff --git a/hurricane/src/hviewer/Palette.cpp b/hurricane/src/hviewer/Palette.cpp new file mode 100644 index 00000000..b4684e8b --- /dev/null +++ b/hurricane/src/hviewer/Palette.cpp @@ -0,0 +1,183 @@ + +// -*- C++ -*- + + +# include + +# include +# include +# include +# include + +# include "Name.h" +# include "DataBase.h" +# include "Technology.h" +# include "BasicLayer.h" +# include "BasicLayers.h" + +# include "Graphics.h" +# include "PaletteEntry.h" +# include "LayerPaletteEntry.h" +# include "GroupPaletteEntry.h" +# include "ViewerPaletteEntry.h" +# include "Palette.h" +# include "CellWidget.h" + + +namespace Hurricane { + + + + Palette::Palette ( CellWidget* cellWidget ) : QScrollArea() + , _cellWidget(cellWidget) + , _entries() + , _showAll(NULL) + , _hideAll(NULL) + { + setWidgetResizable ( true ); + + QWidget* adaptator = new QWidget (); + QVBoxLayout* layout = new QVBoxLayout (); + + //layout->setContentsMargins ( 0, 0, 0, 0 ); + + vector groups = Graphics::getStyle()->getDrawingGroups(); + vector styles = groups[0]->getDrawingStyles(); + + GroupPaletteEntry* gentry = GroupPaletteEntry::create ( this, groups[0]->getName() ); + layout->addWidget ( gentry, 0, Qt::AlignLeft ); + layout->addSpacing ( -5 ); + _entries.push_back ( gentry ); + + for ( size_t si=0 ; sigetName() == DisplayStyle::Foreground ) continue; + if ( styles[si]->getName() == DisplayStyle::Background ) continue; + if ( styles[si]->getName() == DisplayStyle::Foreground ) continue; + if ( styles[si]->getName() == DisplayStyle::SelectionDraw ) continue; + if ( styles[si]->getName() == DisplayStyle::SelectionFill ) continue; + if ( styles[si]->getName() == DisplayStyle::Foreground ) continue; + + ViewerPaletteEntry* entry = ViewerPaletteEntry::create ( this, styles[si]->getName() ); + layout->addWidget ( entry, 0, Qt::AlignLeft ); + _entries.push_back ( entry ); + } + gentry->setChecked ( false ); + + DataBase* database = getDataBase(); + if ( database ) { + Technology* technology = database->getTechnology(); + if ( technology ) { + for ( size_t gi=1 ; gigetName() ); + layout->addWidget ( gentry, 0, Qt::AlignLeft ); + layout->addSpacing ( -5 ); + _entries.push_back ( gentry ); + + styles = groups[gi]->getDrawingStyles(); + for ( size_t si=0 ; sigetBasicLayer ( styles[si]->getName() ); + + if ( basicLayer ) { + LayerPaletteEntry* entry = LayerPaletteEntry::create ( this, basicLayer ); + layout->addWidget ( entry, 0, Qt::AlignLeft ); + _entries.push_back ( entry ); + } + } + gentry->setChecked ( false ); + } + bool unmatched = false; + for_each_basic_layer ( basicLayer, technology->getBasicLayers() ) { + if ( !find(basicLayer->getName()) ) { + if ( !unmatched ) { + unmatched = true; + gentry = GroupPaletteEntry::create ( this, "Unmatcheds" ); + layout->addWidget ( gentry, 0, Qt::AlignLeft ); + layout->addSpacing ( -5 ); + _entries.push_back ( gentry ); + } + LayerPaletteEntry* entry = LayerPaletteEntry::create ( this, basicLayer ); + layout->addWidget ( entry, 0, Qt::AlignLeft ); + _entries.push_back ( entry ); + + cerr << "[WARNING] BasicLayer \"" << basicLayer->getName() + << "\" has no associated DisplayStyle." << endl; + } + end_for; + } + if ( unmatched ) + gentry->setChecked ( false ); + } + } + + _showAll = new QPushButton ( this ); + _showAll->setIcon ( QIcon(":/images/palette_show_all.png") ); + _showAll->setFlat ( true ); + + _hideAll = new QPushButton ( this ); + _hideAll->setIcon ( QIcon(":/images/palette_hide_all.png") ); + _hideAll->setFlat ( true ); + + connect ( _showAll, SIGNAL(clicked()), this, SLOT(showAll()) ); + connect ( _hideAll, SIGNAL(clicked()), this, SLOT(hideAll()) ); + + QHBoxLayout* bottomEntry = new QHBoxLayout (); + bottomEntry->setContentsMargins ( 0, 0, 0, 0 ); + bottomEntry->addWidget ( _showAll ); + bottomEntry->addWidget ( _hideAll ); + layout->addLayout ( bottomEntry ); + layout->addStretch (); + + adaptator->setLayout ( layout ); + setWidget ( adaptator ); + setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff ); + setVerticalScrollBarPolicy ( Qt::ScrollBarAsNeeded ); + setFrameStyle ( QFrame::Plain ); + } + + + bool Palette::isDrawable ( size_t index ) + { + if ( index < _entries.size() ) + return _entries[index]->isChecked (); + + return false; + } + + + void Palette::showAll () + { + for ( size_t i=0 ; i<_entries.size() ; i++ ) + if ( !_entries[i]->isGroup() ) + _entries[i]->setChecked ( true ); + + _cellWidget->redraw (); + } + + + void Palette::hideAll () + { + for ( size_t i=0 ; i<_entries.size() ; i++ ) + if ( !_entries[i]->isGroup() ) + _entries[i]->setChecked ( false ); + + _cellWidget->redraw (); + } + + + void Palette::redrawCellWidget () + { + _cellWidget->redraw (); + } + + + PaletteEntry* Palette::find ( const Name& name ) + { + for ( size_t i=0 ; i<_entries.size() ; i++ ) { + if ( _entries[i]->getName() == name ) + return _entries[i]; + } + return NULL; + } + + +} // End of Hurricane namespace. diff --git a/hurricane/src/hviewer/Palette.h b/hurricane/src/hviewer/Palette.h new file mode 100644 index 00000000..714a46d5 --- /dev/null +++ b/hurricane/src/hviewer/Palette.h @@ -0,0 +1,70 @@ + +// -*- C++ -*- + + +# ifndef __PALETTET__ +# define __PALETTE__ + +# include +# include +# include +# include + +# include "Commons.h" + + + class QCheckBox; + class QPushButton; + + +namespace Hurricane { + + + using namespace std; + + + class Name; + class BasicLayer; + class PaletteEntry; + class CellWidget; + + + class Palette : public QScrollArea { + Q_OBJECT; + + // Constructor. + public: + Palette ( CellWidget* cellWidget ); + // Methods. + bool isDrawable ( size_t index ); + inline CellWidget* getCellWidget (); + inline vector& getEntries (); + void redrawCellWidget (); + PaletteEntry* find ( const Name& name ); + // Slots. + public slots: + void showAll (); + void hideAll (); + + // Internal - Attributes. + protected: + CellWidget* _cellWidget; + vector _entries; + QPushButton* _showAll; + QPushButton* _hideAll; + // Internal - Constructors. + Palette ( const Palette& ); + Palette& operator= ( const Palette& ); + + }; + + + // Inline Functions. + inline CellWidget* Palette::getCellWidget () { return _cellWidget; } + inline vector& Palette::getEntries () { return _entries; } + + +} // End of Hurricane namespace. + + +# endif diff --git a/hurricane/src/hviewer/PaletteEntry.cpp b/hurricane/src/hviewer/PaletteEntry.cpp new file mode 100644 index 00000000..d6f6d655 --- /dev/null +++ b/hurricane/src/hviewer/PaletteEntry.cpp @@ -0,0 +1,54 @@ + +// -*- C++ -*- + + +# include + +# include "Graphics.h" +# include "PaletteEntry.h" + + +namespace Hurricane { + + + PaletteSample::PaletteSample ( PaletteEntry* entry ) + : QWidget() + , _sample(QSize(20,20)) + , _entry(entry) + { + setAttribute ( Qt::WA_StaticContents ); + setSizePolicy ( QSizePolicy::Fixed, QSizePolicy::Fixed ); + setFixedSize ( 20, 20 ); + + redraw (); + } + + + void PaletteSample::redraw () + { + QPainter painter ( &_sample ); + + painter.setPen ( Qt::NoPen ); + painter.setBackground ( Graphics::getBrush("background") ); + painter.eraseRect ( 0, 0, 20, 20 ); + painter.setPen ( Graphics::getPen (_entry->getName()) ); + painter.setBrush ( Graphics::getBrush(_entry->getName()) ); + painter.drawRect ( 2, 2, 16, 16 ); + } + + + void PaletteSample::paintEvent ( QPaintEvent* ) + { + QPainter painter ( this ); + painter.drawPixmap ( 0, 0, _sample ); + } + + + PaletteEntry::PaletteEntry ( Palette* palette ) + : QWidget() + , _palette(palette) + { + } + + +} // End of Hurricane namespace. diff --git a/hurricane/src/hviewer/PaletteEntry.h b/hurricane/src/hviewer/PaletteEntry.h new file mode 100644 index 00000000..0fb0c046 --- /dev/null +++ b/hurricane/src/hviewer/PaletteEntry.h @@ -0,0 +1,78 @@ + +// -*- C++ -*- + + +# ifndef __PALETTE_ENTRY_H__ +# define __PALETTE_ENTRY_H__ + +# include +# include +# include + +class QPaintEvent; +class QCheckBox; + +# include "Commons.h" + + +namespace Hurricane { + + + class Name; + class BasicLayer; + class Palette; + class PaletteEntry; + + + class PaletteSample : public QWidget { + Q_OBJECT; + + // Constructor. + public: + PaletteSample ( PaletteEntry* entry ); + + // Internals - Attributes. + protected: + QPixmap _sample; + PaletteEntry* _entry; + + // Internals - Methods. + void redraw (); + void paintEvent ( QPaintEvent* ); + + }; + + + class PaletteEntry : public QWidget { + Q_OBJECT; + + // Methods. + public: + virtual const Name& getName () const = 0; + virtual bool isGroup () const = 0; + virtual bool isBasicLayer () const = 0; + virtual BasicLayer* getBasicLayer () = 0; + virtual bool isChecked () const = 0; + virtual void setChecked ( bool state ) = 0; + + // Slots. + public slots: + virtual void toggle () = 0; + + // Internal - Attributes. + protected: + Palette* _palette; + + // Internal - Constructor. + PaletteEntry ( Palette* palette ); + PaletteEntry ( const PaletteEntry& ); + PaletteEntry& operator= ( const PaletteEntry& ); + virtual void _postCreate () = 0; + + }; + + +} // End of Hurricane namespace. + + +# endif diff --git a/hurricane/src/hviewer/ScreenUtilities.cpp b/hurricane/src/hviewer/ScreenUtilities.cpp new file mode 100644 index 00000000..ba63a9c4 --- /dev/null +++ b/hurricane/src/hviewer/ScreenUtilities.cpp @@ -0,0 +1,84 @@ + +// -*- C++ -*- + + +# include + +# include "BasicLayer.h" + +# include "ScreenUtilities.h" + + + + +namespace { + + + inline bool charToBits ( uchar& b, char c, bool low=true ) + { + bool isValid = true; + uchar value = 0xF; + + if ( (c >= '0') && (c <= '9') ) value = (uchar)( c - '0' ); + else { + if ( (c >= 'a') && (c <= 'f') ) value = (uchar)( c - 'a' + 10 ); + else { + if ( (c >= 'A') && (c <= 'F') ) value = (uchar)( c - 'A' + 10 ); + else + isValid = false; + } + } + + b &= (low) ? 0xF0 : 0x0F; + b += (low) ? value : (value<<4); + + return isValid; + } + + + bool getPattern ( uchar bits[], const string& pattern ) + { + bool isValid = true; + + for ( size_t i=0 ; i 15 ) { isValid = false; break; } + isValid &= charToBits ( bits[i/2], pattern[i], i%2 ); + } + return isValid; + } + + +} + + + + +namespace Hurricane { + + +QBrush getBrush ( const string& pattern, int red, int green, int blue ) +{ + if ( pattern != "FFFFFFFFFFFFFFFF" ) { + uchar bits[8]; + + if ( !getPattern(bits,pattern) ) + cerr << "[WARNING] Invalid stipple pattern: \"0x" << pattern << "\"." << endl; + + return QBrush ( QColor(red,green,blue), QBitmap::fromData(QSize(8,8),bits,QImage::Format_Mono) ); + } + + return QBrush ( QColor(red,green,blue), Qt::SolidPattern ); +} + + +QBrush getBrush ( const BasicLayer* layer ) +{ + return getBrush ( layer->getFillPattern() + , layer->getRedValue() + , layer->getGreenValue() + , layer->getBlueValue() + ); +} + + +} // End of Hurricane namespace. diff --git a/hurricane/src/hviewer/ScreenUtilities.h b/hurricane/src/hviewer/ScreenUtilities.h new file mode 100644 index 00000000..4140069e --- /dev/null +++ b/hurricane/src/hviewer/ScreenUtilities.h @@ -0,0 +1,35 @@ + +// -*- C++ -*- + + +# ifndef __SCREENUTILITIES_H__ +# define __SCREENUTILITIES_H__ + +# include +# include + +# include "Commons.h" + + +namespace Hurricane { + + + class BasicLayer; + + + // Constants. + const size_t InvalidIndex = (size_t)-1; + + + // Functions. + + QBrush getBrush ( const string& pattern, int red, int green, int blue ); + QBrush getBrush ( const BasicLayer* layer ); + + + + +} // End of Hurricane namespace. + + +# endif diff --git a/hurricane/src/hviewer/ViewerPaletteEntry.cpp b/hurricane/src/hviewer/ViewerPaletteEntry.cpp new file mode 100644 index 00000000..7bc84586 --- /dev/null +++ b/hurricane/src/hviewer/ViewerPaletteEntry.cpp @@ -0,0 +1,95 @@ + +// -*- C++ -*- + + +# include +# include + +# include "BasicLayer.h" + +# include "Graphics.h" +# include "ViewerPaletteEntry.h" +# include "Palette.h" + + +namespace Hurricane { + + + ViewerPaletteEntry::ViewerPaletteEntry ( Palette* entry, const Name& name ) + : PaletteEntry(entry) + , _name(name) + { + } + + + ViewerPaletteEntry* ViewerPaletteEntry::create ( Palette* palette, const Name& name ) + { + ViewerPaletteEntry* entry = new ViewerPaletteEntry ( palette, name ); + + entry->_postCreate (); + + return entry; + } + + + void ViewerPaletteEntry::_postCreate () + { + QHBoxLayout* layout = new QHBoxLayout (); + layout->setContentsMargins ( 0, 0, 0, 0 ); + + layout->addWidget ( new PaletteSample(this) ); + + _checkBox = new QCheckBox ( this ); + _checkBox->setChecked ( true ); + _checkBox->setText ( getString(getName()).c_str() ); + layout->addWidget ( _checkBox ); + + setLayout ( layout ); + + connect ( _checkBox, SIGNAL(clicked()), this, SLOT(toggle()) ); + } + + + bool ViewerPaletteEntry::isGroup () const + { + return false; + } + + + bool ViewerPaletteEntry::isBasicLayer () const + { + return false; + } + + + const Name& ViewerPaletteEntry::getName () const + { + return _name; + } + + + BasicLayer* ViewerPaletteEntry::getBasicLayer () + { + return NULL; + } + + + bool ViewerPaletteEntry::isChecked () const + { + return _checkBox->isChecked (); + } + + + void ViewerPaletteEntry::setChecked ( bool state ) + { + _checkBox->setChecked ( state ); + } + + + void ViewerPaletteEntry::toggle () + { + _palette->redrawCellWidget(); + } + + +} // End of Hurricane namespace. diff --git a/hurricane/src/hviewer/ViewerPaletteEntry.h b/hurricane/src/hviewer/ViewerPaletteEntry.h new file mode 100644 index 00000000..2b0cb48d --- /dev/null +++ b/hurricane/src/hviewer/ViewerPaletteEntry.h @@ -0,0 +1,55 @@ + +// -*- C++ -*- + + +# ifndef __VIEWER_PALETTE_ENTRY_H__ +# define __VIEWER_PALETTE_ENTRY_H__ + + +class QCheckBox; + +# include "Name.h" +# include "PaletteEntry.h" + + +namespace Hurricane { + + + class ViewerPaletteEntry : public PaletteEntry { + Q_OBJECT; + + // Constructor. + public: + static ViewerPaletteEntry* create ( Palette* palette, const Name& name ); + + // Methods. + public: + virtual bool isGroup () const; + virtual bool isBasicLayer () const; + virtual const Name& getName () const; + virtual BasicLayer* getBasicLayer (); + virtual bool isChecked () const; + virtual void setChecked ( bool state ); + + // Slots. + public slots: + virtual void toggle (); + + // Internal - Attributes. + protected: + const Name _name; + QCheckBox* _checkBox; + + // Internal - Constructor. + ViewerPaletteEntry ( Palette* palette, const Name& name ); + ViewerPaletteEntry ( const ViewerPaletteEntry& ); + ViewerPaletteEntry& operator= ( const ViewerPaletteEntry& ); + virtual void _postCreate (); + + }; + + +} // End of Hurricane namespace. + + +# endif diff --git a/hurricane/src/hviewer/etc/display.xml b/hurricane/src/hviewer/etc/display.xml new file mode 100644 index 00000000..80719376 --- /dev/null +++ b/hurricane/src/hviewer/etc/display.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/hurricane/src/hviewer/images/gtk-go-down.png b/hurricane/src/hviewer/images/gtk-go-down.png new file mode 100644 index 0000000000000000000000000000000000000000..c8f54fb919a106efbda7efc3896fb5be03bfd8a0 GIT binary patch literal 536 zcmV+z0_XjSP)P*DMoq#*3HX#RY^SdIdxGYjiHtvw--f=I`N z+8_md*!s@Z`Ed^^nWU?;WA-+d0LFm}pqnU3ON*U?iTBgb`Lw&wO*cYHi3(({$q$A{ z)8G@XK2EnOty=>v;1^I|ntj2_c7sl+(Q*DZI6wH7fY)7JE8U(ffdxX~x9e+tdHyA< zI}IWo_r~=e@TRK^vnFSqyF>E%?Q6DwoN(QVN`n`Dg#s7?Mu5k_-qhS8#u$#ita*d` ztnw-_2229B{_IsU=acS!)nny*lhhn|tqi#EBpCvRfrr42n-;IOh!RSaJGyB9|LtGw azmHp`TEWigP)-(u5Kah1Y#(wqittcB1&SRcHOpJnggNao`k4 ztb_T0cWXP8q7aqoKVcbzF$NJK3I&yEQkAi}d%*j}3V;*htU;V8wAN^?QQ5B@Ktzy$ z-{67166MJWDz83x(-pY@U$*y1+A$JFh1yGN&9j*~Y8%xCFlr-7y@1P$7ICXtxPK47 zf1|ch1$Yh&05PBdBY%52I>e`eAJ)`W9h?!UG@*Td;uP#38up2w0!P5P1^Bxt&*K-f zOY{#7yTqHWE^pc|lpOZ&q~SA+s^*4QsBp7*u~p7f>mT(-H+ z755go<5_mCNxL84B;MG=V1|7@|mtz&QLB$Oa?Zx4T2Z9$@R_I}sy_tTfW?+|GRa?e2U7|LchIE>y2b zEI=P%dJPZ(K70=ckf>Jx5#Tp>ekSuFpwKIT2=F^U$~0Ow@fAaCnzezNyvhHZRS}WI zzt<(^BhUomtk>|A{P?1V(FzekDTUDr>pWULhSwW0yQK=Ni(dgIfh*u1@FpwyVfmW= zqM;c(L?t9^#Q1MyMt(AX4dcSpYW@4gVBmsY>BPIdBJ(X=tmX> zqX8%wjnXEyM$#Dgg{2iXz8|7g_8U+UI4@Msk8%M-z`*kSm;0%?Z;XAK$z3Fk+EuP+ zDu4w>OIvGP{@(j%O-VZ<3)}(YrLDD#DV~|suTQDpT&5=~6mtUz&;n{{AP3v)S)2BG z3N006V0bk7{~2fmww=lANs(nqMJGtxorYri3!J>LO7J&3nPkaDA21d`1(*g#!U=TM zqC8^P#w7S!VTWlZuj));Z4np@QhgirMtaivUaU8O4i{|Sy(hotz4{ literal 0 HcmV?d00001 diff --git a/hurricane/src/hviewer/images/gtk-go-up.png b/hurricane/src/hviewer/images/gtk-go-up.png new file mode 100644 index 0000000000000000000000000000000000000000..da3eab90988542f48fadcb32d030cede59b619f5 GIT binary patch literal 605 zcmV-j0;2tiP)a(NT8p+&hT=jHK|yN~v7k#AiZ9?>b^d<>Va+zA%cm5Lxt zDTtfFL8_gh+ID6-G08bD?wzC)lS#63;Rkn--Qd2f)oLg@U2f@Q?mij^DxG+cIgJ|cORBQ@&E>q z!*LpJjD1gZ*4VzdQ3}Zd3?SRxK5sic8oqt(d+9qOf{1X`?=jr}&f-d&%?D2kA&m?` z0IpqVCpX@7dJGQ6$+b!hDvb7ju=DC!w)#GH2_FGr7GQuyU>P`r-B8<03rz+GpsI)p zDzSy6x(x&_FmM(4Km_PXfV!JQVB$=SCShWTMN!R6gbf`4V<2`Jk<0t5MUgWZ-2AAj z`}#saO&?6vyA1h9D3X6(xF@Zo-R8&+T5GNXPf-FtbEX{JFp+9lCwJY@3!hXNslHW_3S1!HxKJR<4*8|{x zH9-&rK?uW2rBbO>!jS*|X|7D*kB|3v*9}A0eS6z%!q9bHce4q@PN&mR)$bR;^CW%N zytA}GzVCUC0}up3KEYS_1d!L^Jtt9LTnr0=BC^2 z_tWDF{H9*7*X#8>z(EiM9Q|~K3BlMj0gA;^38Bc>YKqcq0xTBu`FI>Xp9+pK#u!Jy z7_Zlh1%M>Ua=9FN+s1ggjGl8G$Fc471ZkF4HbSzDP?i9()}WM9-v?+kTCLmLXsNj8 z_Eu^eBbj3VJo5Q*~(KI1iqi0r&MC^4nhb? z(g7i&+o-2c>t1Hb0=Vbn$C@NbQmF*cY&II_=Lf*~F2TANz%+GzIz7I3lLbV;-;o2r zFidl`Itb2yxtC>x6a~PtOmn#eC=?2XLLm%QRaI4$DadvOQ7n}XClkeZ-0z|%V#mQ* ztB7K;$dZa8fGo46;-I1!tx$ZWL=m7^WcTrw<8k)EzvesEJ{9K)c&qGRY@AZ=DfK*- zp3->X@shr(&n~_~`G7so^L!sbQEIhv`2e_WZ?_o7^@v_pQQQy60rI!NY06USd6WXI z*BBEL1LxaYyWMWz-tH@ujgwR`%^zouv)!&%0He`lqG|h|ejzy_sr*lwuIsvG0W6oy zC+!oQS2P?B29J-dw`}|01J7nJFPa80ojyO$=jn&6)YBZ_zb(r!G>x5A6y@&$FBY$_ zvl#$Fk|aq0-EOaUcXtAKS^?btR3Y0fA(jQ;ID~j!HgIlmZr9gWR~HvyIGK#cgF!SN z|6s*G$!UPxIOuRV8cikumStHO=Reoy22ZX)tJQ2?UIGjT{eG_pfKat6%fAD+ZN~w4 xco>hTQvh8zjMeJ+KOiTArxlX-`BOoY_6sUuZ>tv?-5vk{002ovPDHLkV1g2Br9S`w literal 0 HcmV?d00001 diff --git a/hurricane/src/hviewer/images/palette_show_all.png b/hurricane/src/hviewer/images/palette_show_all.png new file mode 100644 index 0000000000000000000000000000000000000000..712566bfed59230064c4a106e07b40493a5637ec GIT binary patch literal 1398 zcmV-+1&R8JP)O4EabgM)*EG?mZ)HLjh2fBg9VeZ5Z8_4?blr>8Vsuh;9Rr!+k| zIXUTc{@nq2PI27z-rly27^5_f0nRy3lFb)67niQNfJu)Gm4@p*^_kO z_XOmmkt9jN7|?1R9bH^xp^~GVCnOAQ`(KzAKxeZcP!youUM$LGAc`2vM|wKFzrVfR zB<2_6j4>9+y8#p(V2n~iL?kS0H}grtIb*UoR-l}e-0Y5{}6>1nG4oS)mat^>oN z>v9elhGA&hD@43hnY?>DlSL~!AV)bbZ8Y+IMFA+~Tv32HP7(oB*EJ1zeDwV!0W?k1 zR24AIR;$r?1-PsdLcM_FSk`3n=h`hgkO6*4hiNKG6ak~ra_M=%o}_wu)n{*zrUZRold9I=?DfL2Pl^nMO9x1uPFI_ zUqT-YnoYqlA;Ll1wyX^B&5ddPj+i~kXb|}RY9&&pTo#Asvs@;VoXdmAmq*Tlmt{1Y z&%Y!0ilQhA0)R0g8ATB}psMAvI7^&cEEc8WMp7!9m*coDz}R>^oo3}s*59n|OL#A( zA@`S;Ow#*%#>!>D_r>}mU`i=v45-&@wMyj`sf3~MJTILj0TjjeMSUNSXEVTYCKK_c z>-UGlO(u7l1l;R+9;JY$8Ai1VJU()+s=#s?$C3yUJxY@V@ckelBu9j#zTIxOFD}wF z41M3SGG;96^78f;I6J$$ySV|R*PeHGcYhB=(R^-MK)KxQ*6YA*CL|X{oKp(4+p1cx z1C55NR;z$vh$_)+8irv2$H#_|XL34St$ZKob`3*Sf#Fa@xcKQ;ii}9+t5w6O)$&ZO zR+a^DPDm61K@f(72u&slFrN#+7Z;}4>j8vt9)`ed=DLdoz&WLy1Bw#InkMF>2;ltq zxZ4Fhj}StDBoPs|EY70{SgkC}bvGmTODfW%>+7qlyE~z+Fa$L1?Cj_Wu&l+xvVi4M zl%+5fj3|n(t193)zVCT}>oVrLnS>Z)j4^;xLgE-OP4Ql(BJ1^Hv0MT{uw1TIK)+wB zsVXp;JUq$>@zE85OBRF+HWK+&>p zQP}0>WHKIauKW10R%^9@Zr3!M&CTEAm=H>V)6-sWFxcHDzqx<@@ZtUYckj}4JRXg% zuC@cGR7fKTq9}?0QAdDgvtG~Vj0AdpJsgh58N+Yw>)#B#7=fcB!Q9nVzu)TthEc5w z$-Hh-GM_$;Mw1C(S+?zYfBpyLuYqrK|Y%jXFDfG=t4(p`m)62M5P7>I??YT`S@4UagsS7R(c3f9>;?rb! zaD#~=cX2m%tv4U#pK&Ly7=bDDum7bcu7UV&G2G#_q6WpOz#}2z+Wen!_+^N z#Taji$^5tT&yA+YbD}>A-*rc>&@J$O`1HN~g=HtCw8Y${CTbluS^x9doozvTU7fB! z+IjKLB91AqPxdZu)ogUlaV?!?t+!9b*osfeS7U5qaw$oIWxDE!~|t56N=tVO=-^N+z96f&eKJ0q`7yi=*}O! z7w7Pv|MNWO|2zkl`HzU7pDc>M6|U6kIB@cGa2=MoKNQAd>&NBwvMWEA+d%W92mf4w z0EETXkFLEFfRf^!C=(I@qN*a2u+X)43X82@EN0O4Ra9zqvR=f65vKZyfgJUkP{vD< zo|=LxC7I$wN9btM3m_(9*7b%K@%&AOHYgH9^+ya zvR*6>5Ockv993!(lhZS@!r!K*85(m_r#AsmuPda^V{NY-Amw{EAVtaO2H*g1G@HuJc>3zyf&(3qR*r%f~%+pt<%(Imz5 z@Mbl4Zrvc!=U#Abu@`b}CF%_=43AF$AX$4UKUIQea}M+K^Z5OKW@l%4YwJVXXrQoo z4^~Sno>3<~FO4B>*-3Ud?5s>w0&wowVT!ioai-!b4yTJiAV44xpm0+*d$$z;Fg-CI z6c5`)zY@jS^Zewf_w%)s2-9K#MfjXm%1`TZyq3M5J5VP$xP1I%P&d?0DNi>`FQpe z!T?(ZeetFa%BJjc-k{gOEyh2H%Ll0F|;r + +# include +# include +# include +# include +# include +# include + +# include "Name.h" + +# include "ScreenLayer.h" +# include "LayersList.h" +# include "CellWidget.h" + + +namespace Hurricane { + + +ScreenLayerEntry::ScreenLayerEntry ( ScreenLayer* layer, LayersList* layersList ) + : QWidget() + , _layersList(layersList) +{ + QHBoxLayout* layout = new QHBoxLayout (); + layout->setContentsMargins ( 0, 0, 0, 0 ); + + _sample = layer->getSample(); + layout->addWidget ( _sample ); + + _checkBox = new QCheckBox ( this ); + _checkBox->setText ( getString(layer->getName()).c_str() ); + _checkBox->setChecked ( true ); + layout->addWidget ( _checkBox ); + + setLayout ( layout ); +} + + +void ScreenLayerEntry::setChecked ( bool state ) +{ + _checkBox->setChecked ( state ); + _sample ->setVisible ( state ); +} + + +bool ScreenLayerEntry::isChecked () const +{ + return _checkBox->isChecked (); +} + + +void ScreenLayerEntry::toggle () +{ + _sample->setVisible ( _checkBox->isChecked() ); + _layersList->getCellWidget()->redraw(); +} + + + +LayersList::LayersList ( CellWidget* cellWidget ) : QScrollArea() + , _cellWidget(cellWidget) + , _entries() + , _showAll(NULL) + , _hideAll(NULL) +{ + QWidget* adaptator = new QWidget (); + QVBoxLayout* layout = new QVBoxLayout (); + + vector& screenLayers = _cellWidget->getScreenLayers (); + + for ( size_t i=0 ; i < screenLayers.size() ; i++ ) { + _entries.push_back ( new ScreenLayerEntry(screenLayers[i],this) ); + layout->addWidget ( _entries.back() ); + connect ( _entries.back()->getCheckBox(), SIGNAL(clicked()), _entries.back(), SLOT(toggle()) ); + } + layout->addStretch (); + + _showAll = new QPushButton ( this ); + _showAll->setIcon ( QIcon(":/images/palette_show_all.png") ); + _showAll->setFlat ( true ); + + _hideAll = new QPushButton ( this ); + _hideAll->setIcon ( QIcon(":/images/palette_hide_all.png") ); + _hideAll->setFlat ( true ); + + connect ( _showAll, SIGNAL(clicked()), this, SLOT(showAll()) ); + connect ( _hideAll, SIGNAL(clicked()), this, SLOT(hideAll()) ); + + QHBoxLayout* bottomEntry = new QHBoxLayout (); + bottomEntry->setContentsMargins ( 0, 0, 0, 0 ); + bottomEntry->addWidget ( _showAll ); + bottomEntry->addWidget ( _hideAll ); + layout->addLayout ( bottomEntry ); + + adaptator->setLayout ( layout ); + setWidget ( adaptator ); + setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff ); + setVerticalScrollBarPolicy ( Qt::ScrollBarAsNeeded ); + setFrameStyle ( QFrame::Plain ); +} + + +bool LayersList::isVisible ( size_t index ) +{ + if ( index < _entries.size() ) + return _entries[index]->isChecked (); + + return false; +} + + +void LayersList::showAll () +{ + for ( size_t i=0 ; i<_entries.size() ; i++ ) + _entries[i]->setChecked ( true ); + + _cellWidget->redraw (); +} + + +void LayersList::hideAll () +{ + for ( size_t i=0 ; i<_entries.size() ; i++ ) + _entries[i]->setChecked ( false ); + + _cellWidget->redraw (); +} + + +} // End of Hurricane namespace. diff --git a/hurricane/src/hviewer/obsoletes/LayersList.h b/hurricane/src/hviewer/obsoletes/LayersList.h new file mode 100644 index 00000000..d3abed24 --- /dev/null +++ b/hurricane/src/hviewer/obsoletes/LayersList.h @@ -0,0 +1,79 @@ + +// -*- C++ -*- + + +# ifndef __LAYERSLIST__ +# define __LAYERSLIST__ + +# include +# include +# include +# include + +# include "Commons.h" + + + class QCheckBox; + class QPushButton; + + +namespace Hurricane { + + + using namespace std; + + + class LayerSample; + class ScreenLayer; + class LayersList; + class CellWidget; + + + class ScreenLayerEntry : public QWidget { + Q_OBJECT; + + protected: + LayersList* _layersList; + LayerSample* _sample; + QCheckBox* _checkBox; + + public: + ScreenLayerEntry ( ScreenLayer* layer, LayersList* layerList ); + + public: + bool isChecked () const; + void setChecked ( bool state ); + QCheckBox* getCheckBox () { return _checkBox; }; + + public slots: + void toggle (); + }; + + + class LayersList : public QScrollArea { + Q_OBJECT; + + protected: + CellWidget* _cellWidget; + vector _entries; + QPushButton* _showAll; + QPushButton* _hideAll; + + public: + LayersList ( CellWidget* cellWidget ); + + public: + CellWidget* getCellWidget () { return _cellWidget; }; + vector& getEntries () { return _entries; }; + bool isVisible ( size_t index ); + + public slots: + void showAll (); + void hideAll (); + }; + + +} // End of Hurricane namespace. + + +# endif diff --git a/hurricane/src/hviewer/obsoletes/ScreenLayer.cpp b/hurricane/src/hviewer/obsoletes/ScreenLayer.cpp new file mode 100644 index 00000000..378d5bdd --- /dev/null +++ b/hurricane/src/hviewer/obsoletes/ScreenLayer.cpp @@ -0,0 +1,72 @@ + +// -*- C++ -*- + + +# include + +# include "BasicLayer.h" + +# include "ScreenUtilities.h" +# include "ScreenLayer.h" +# include "Graphics.h" + + + + +namespace Hurricane { + + +LayerSample::LayerSample ( ScreenLayer* layer ) + : QWidget() + , _sample(QSize(20,20)) + , _layer(layer) +{ + setAttribute ( Qt::WA_StaticContents ); + setSizePolicy ( QSizePolicy::Fixed, QSizePolicy::Fixed ); + setFixedSize ( 20, 20 ); + + redraw (); +} + + +void LayerSample::redraw () +{ + QPainter painter ( &_sample ); + + painter.setPen ( Qt::NoPen ); + painter.setBackground ( Graphics::getBrush("background") ); + painter.eraseRect ( 0, 0, 20, 20 ); + painter.setPen ( Graphics::getPen (_layer->getName()) ); + painter.setBrush ( Graphics::getBrush(_layer->getName()) ); + painter.drawRect ( 2, 2, 16, 16 ); +} + + +void LayerSample::paintEvent ( QPaintEvent* ) +{ + QPainter painter ( this ); + painter.drawPixmap ( 0, 0, _sample ); +} + + +ScreenLayer::ScreenLayer ( BasicLayer* basicLayer + , size_t index + , bool isVisible + ) : _layer(basicLayer) + , _isVisible(isVisible) +{} + + +const Name& ScreenLayer::getName () const +{ + return _layer->getName (); +} + + +LayerSample* ScreenLayer::getSample () +{ + return new LayerSample ( this ); +} + + +} // End of Hurricane namespace. diff --git a/hurricane/src/hviewer/obsoletes/ScreenLayer.h b/hurricane/src/hviewer/obsoletes/ScreenLayer.h new file mode 100644 index 00000000..da11a592 --- /dev/null +++ b/hurricane/src/hviewer/obsoletes/ScreenLayer.h @@ -0,0 +1,86 @@ + +// -*- C++ -*- + + +# ifndef __SCREENLAYER_H__ +# define __SCREENLAYER_H__ + +# include +# include +# include +# include + +class QPaintEvent; + +# include "Commons.h" + + +namespace Hurricane { + + + class Name; + class BasicLayer; + class ScreenLayer; + + + class LayerSample : public QWidget { + Q_OBJECT; + + protected: + QPixmap _sample; + ScreenLayer* _layer; + + public: + LayerSample ( ScreenLayer* layer ); + + protected: + void redraw (); + void paintEvent ( QPaintEvent* ); + + public: + + inline void setVisible ( bool state ); + }; + + + class ScreenLayer { + + protected: + BasicLayer* _layer; + bool _isVisible; + QBrush _brush; + + // Constructor. + public: + ScreenLayer ( BasicLayer* layer, size_t index, bool isVisible ); + + // Predicates. + public: + bool isVisible () const { return _isVisible; }; + // Accessors. + public: + BasicLayer* getBasicLayer () const { return _layer; }; + const Name& getName () const; + + // Methods. + public: + LayerSample* getSample (); + + // Modifiers. + public: + inline void setVisible ( bool state ) { _isVisible=state; }; + }; + + + + + inline void LayerSample::setVisible ( bool state ) + { + _layer->setVisible ( state ); + } + + +} // End of Hurricane namespace. + + +# endif