From 56b2abb2602d10e6e9b50c50c545663ce4ea3765 Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Mon, 19 Oct 2009 17:17:21 +0000 Subject: [PATCH] - Change: In CellWidget & Command, rewrite of the active command mechanism. Now a command is associated to one CellWidget exactly, the active flag was shared among all CellWidget which was an error (do not show unless we start to multithread). - New: In SelectCommand/SelectionPopup/SelectionPopupModel now there are three selection mode: Mode 0: Select all Component under point. Mode 1: Select whole nets whose at least one component is under point. Mode 2: Same as 1, but hide all cluttering "*nymous*" nets. Rotation through the mode is done by pressing repeadedly the 'N' key. The various select modes are implemented through "sub" Collections. --- hurricane/CMakeLists.txt | 1 + hurricane/src/hviewer/AreaCommand.cpp | 24 +- hurricane/src/hviewer/CMakeLists.txt | 13 +- hurricane/src/hviewer/CellViewer.cpp | 68 ++--- hurricane/src/hviewer/CellWidget.cpp | 143 ++++++++--- hurricane/src/hviewer/Command.cpp | 44 ++-- hurricane/src/hviewer/HierarchyCommand.cpp | 42 ++-- hurricane/src/hviewer/MoveCommand.cpp | 63 +++-- hurricane/src/hviewer/RulerCommand.cpp | 103 ++++---- hurricane/src/hviewer/SelectCommand.cpp | 232 ++++++++++++++++-- hurricane/src/hviewer/SelectionPopup.cpp | 37 +-- hurricane/src/hviewer/SelectionPopupModel.cpp | 51 +++- hurricane/src/hviewer/ZoomCommand.cpp | 59 +++-- .../hviewer/hurricane/viewer/AreaCommand.h | 36 +-- .../src/hviewer/hurricane/viewer/CellViewer.h | 82 +++---- .../src/hviewer/hurricane/viewer/CellWidget.h | 20 +- .../src/hviewer/hurricane/viewer/Command.h | 47 ++-- .../hurricane/viewer/HierarchyCommand.h | 11 +- .../hviewer/hurricane/viewer/MoveCommand.h | 23 +- .../hviewer/hurricane/viewer/RulerCommand.h | 25 +- .../hviewer/hurricane/viewer/SelectCommand.h | 22 +- .../hviewer/hurricane/viewer/SelectionPopup.h | 33 ++- .../hurricane/viewer/SelectionPopupModel.h | 29 ++- .../hviewer/hurricane/viewer/ZoomCommand.h | 22 +- 24 files changed, 776 insertions(+), 454 deletions(-) diff --git a/hurricane/CMakeLists.txt b/hurricane/CMakeLists.txt index 4f0b95fe..d9a0bc3a 100644 --- a/hurricane/CMakeLists.txt +++ b/hurricane/CMakeLists.txt @@ -42,6 +42,7 @@ SET(QT_USE_QTXML "true") FIND_PACKAGE(Qt4 REQUIRED) # find and setup Qt4 for this project FIND_PACKAGE(BISON REQUIRED) FIND_PACKAGE(FLEX REQUIRED) +FIND_PACKAGE(Boost 1.33.1 COMPONENTS regex REQUIRED) FIND_PACKAGE(PythonLibs REQUIRED) IF(BUILD_DOC) FIND_PACKAGE(Doxygen) diff --git a/hurricane/src/hviewer/AreaCommand.cpp b/hurricane/src/hviewer/AreaCommand.cpp index b1cb49a8..521990c0 100644 --- a/hurricane/src/hviewer/AreaCommand.cpp +++ b/hurricane/src/hviewer/AreaCommand.cpp @@ -39,7 +39,7 @@ namespace Hurricane { AreaCommand::AreaCommand () - : Command() + : Command () , _startPoint () , _stopPoint () , _drawingThreshold(10) @@ -52,32 +52,30 @@ namespace Hurricane { - bool AreaCommand::mouseMoveEvent ( CellWidget* widget, QMouseEvent* event ) + void AreaCommand::mouseMoveEvent ( QMouseEvent* event ) { - if ( !_drawingEnabled ) return false; + if ( !_drawingEnabled ) return; setStopPoint ( event->pos() ); - widget->update (); - - return true; + _cellWidget->update (); } - void AreaCommand::draw ( CellWidget* widget ) + void AreaCommand::draw () { if ( !_drawingEnabled ) return; if ( ( abs(_stopPoint.x()-_startPoint.x()) > _drawingThreshold ) && ( abs(_stopPoint.y()-_startPoint.y()) > _drawingThreshold ) ) { - widget->setPen ( Graphics::getPen("grid"), 2 ); - widget->drawScreenRect ( _startPoint, _stopPoint, 2 ); - drawCorner ( widget, true ); - drawCorner ( widget, false ); + _cellWidget->setPen ( Graphics::getPen("grid"), 2 ); + _cellWidget->drawScreenRect ( _startPoint, _stopPoint, 2 ); + drawCorner ( true ); + drawCorner ( false ); } } - void AreaCommand::drawCorner ( CellWidget* widget, bool bottomLeft ) + void AreaCommand::drawCorner ( bool bottomLeft ) { QRect zoomRect = QRect(_startPoint,_stopPoint).normalized(); QPoint base = (bottomLeft) ? zoomRect.bottomLeft() : zoomRect.topRight(); @@ -92,7 +90,7 @@ namespace Hurricane { _cornerPoints[0].ry() += (bottomLeft) ? -10 : 10; _cornerPoints[2].rx() += (bottomLeft) ? 10 : -10; - widget->drawScreenPolyline ( _cornerPoints, 3, 4, 2 ); + _cellWidget->drawScreenPolyline ( _cornerPoints, 3, 4, 2 ); } diff --git a/hurricane/src/hviewer/CMakeLists.txt b/hurricane/src/hviewer/CMakeLists.txt index 96325c06..10017a17 100644 --- a/hurricane/src/hviewer/CMakeLists.txt +++ b/hurricane/src/hviewer/CMakeLists.txt @@ -1,7 +1,8 @@ include ( ${QT_USE_FILE} ) - include_directories ( ${HURRICANE_SOURCE_DIR}/src/hurricane + include_directories ( ${Boost_INCLUDE_DIRS} + ${HURRICANE_SOURCE_DIR}/src/hurricane ${HURRICANE_SOURCE_DIR}/src/hviewer ) set ( mocincludes hurricane/viewer/HApplication.h @@ -109,10 +110,16 @@ if ( BUILD_STATIC ) add_library ( hviewer-static STATIC ${cpps} ${MOC_SRCS} ${RCC_SRCS} ) - target_link_libraries ( hviewer-static hurricane-static ${QT_LIBRARIES} ) + target_link_libraries ( hviewer-static hurricane-static + ${QT_LIBRARIES} + ${Boost_LIBRARIES} + ) install ( TARGETS hviewer-static DESTINATION /lib ) else ( BUILD_STATIC ) add_library ( hviewer SHARED ${cpps} ${MOC_SRCS} ${RCC_SRCS} ) - target_link_libraries ( hviewer ${QT_LIBRARIES} hurricane ) + target_link_libraries ( hviewer hurricane + ${QT_LIBRARIES} + ${Boost_LIBRARIES} + ) install ( TARGETS hviewer DESTINATION /lib ) endif ( BUILD_STATIC ) diff --git a/hurricane/src/hviewer/CellViewer.cpp b/hurricane/src/hviewer/CellViewer.cpp index 2d0734ab..ac7f183e 100644 --- a/hurricane/src/hviewer/CellViewer.cpp +++ b/hurricane/src/hviewer/CellViewer.cpp @@ -49,40 +49,40 @@ namespace Hurricane { - CellViewer::CellViewer ( QWidget* parent ) : QMainWindow (parent) - , _applicationName (tr("Viewer")) - , _toolInterruptAction(NULL) - , _openAction (NULL) - , _nextAction (NULL) - , _printAction (NULL) - , _imageAction (NULL) - , _saveAction (NULL) - , _closeAction (NULL) - , _exitAction (NULL) - , _refreshAction (NULL) - , _fitToContentsAction(NULL) - , _showSelectionAction(NULL) - , _rubberChangeAction (NULL) - , _clearRulersAction (NULL) - , _controllerAction (NULL) - , _fileMenu (NULL) - , _viewMenu (NULL) - , _toolsMenu (NULL) - , _debugMenu (NULL) - //, _mapView (NULL) - , _palette (NULL) - , _mousePosition (NULL) - , _controller (NULL) - , _cellWidget (NULL) - , _moveCommand () - , _zoomCommand () - , _rulerCommand () - , _selectCommand () - , _hierarchyCommand () - , _cellHistory () - , _firstShow (false) - , _toolInterrupt (false) - , _updateState (ExternalEmit) + CellViewer::CellViewer ( QWidget* parent ) : QMainWindow (parent) + , _applicationName (tr("Viewer")) + , _toolInterruptAction (NULL) + , _openAction (NULL) + , _nextAction (NULL) + , _printAction (NULL) + , _imageAction (NULL) + , _saveAction (NULL) + , _closeAction (NULL) + , _exitAction (NULL) + , _refreshAction (NULL) + , _fitToContentsAction (NULL) + , _showSelectionAction (NULL) + , _rubberChangeAction (NULL) + , _clearRulersAction (NULL) + , _controllerAction (NULL) + , _fileMenu (NULL) + , _viewMenu (NULL) + , _toolsMenu (NULL) + , _debugMenu (NULL) + //, _mapView (NULL) + , _palette (NULL) + , _mousePosition (NULL) + , _controller (NULL) + , _cellWidget (NULL) + , _moveCommand () + , _zoomCommand () + , _rulerCommand () + , _selectCommand () + , _hierarchyCommand () + , _cellHistory () + , _firstShow (false) + , _toolInterrupt (false) + , _updateState (ExternalEmit) { setObjectName("viewer"); diff --git a/hurricane/src/hviewer/CellWidget.cpp b/hurricane/src/hviewer/CellWidget.cpp index b24823a6..e230716a 100644 --- a/hurricane/src/hviewer/CellWidget.cpp +++ b/hurricane/src/hviewer/CellWidget.cpp @@ -61,6 +61,9 @@ namespace { + using namespace std; + + string getTime ( const char* format ) { time_t t = time(NULL); @@ -1095,6 +1098,7 @@ namespace Hurricane { , _cellModificated (true) , _enableRedrawInterrupt(false) , _selectors () + , _activeCommand (NULL) , _commands () , _redrawRectCount (0) , _textFontHeight (20) @@ -1172,6 +1176,7 @@ namespace Hurricane { for ( size_t i=0 ; i<_commands.size() ; i++ ) if ( _commands[i] == command ) return; + command->setCellWidget ( this ); _commands.push_back ( command ); } @@ -1182,6 +1187,8 @@ namespace Hurricane { for ( ; i<_commands.size() ; i++ ) if ( _commands[i] == command ) break; + if ( i < _commands.size() ) _commands[i]->setCellWidget ( NULL ); + for ( ; i+1<_commands.size() ; i++ ) _commands[i] = _commands[i+1]; @@ -1806,10 +1813,17 @@ namespace Hurricane { if ( onScreen ) pxGrad = dbuToScreenX ( graduation ); else pxGrad = dbuToDisplayX ( graduation ); + if ( tick % 10 ) { _drawingPlanes.painter().drawLine ( pxGrad, pxOrigin.y() , pxGrad, pxOrigin.y()+((tick%2)?5:10) ); } else { + if ( tick == 0 ) { + int delta = (increase) ? 2 : -2; + _drawingPlanes.painter().drawLine ( pxGrad-delta, pxOrigin.y() + , pxGrad-delta, pxOrigin.y()+tickLength ); + } + _drawingPlanes.painter().drawLine ( pxGrad, pxOrigin.y() , pxGrad, pxOrigin.y()+tickLength ); @@ -1867,6 +1881,11 @@ namespace Hurricane { _drawingPlanes.painter().drawLine ( pxAngle.x() , pyGrad , pxAngle.x()-((tick%2)?5:10), pyGrad ); } else { + if ( tick == 0 ) { + _drawingPlanes.painter().drawLine ( pxAngle.x() , pyGrad-2 + , pxAngle.x()-tickLength, pyGrad-2); + } + _drawingPlanes.painter().drawLine ( pxAngle.x() , pyGrad , pxAngle.x()-tickLength, pyGrad ); @@ -2234,7 +2253,7 @@ namespace Hurricane { _drawingPlanes.begin (); _drawingPlanes.copyToScreen (); for ( size_t i=0 ; i<_commands.size() ; i++ ) - _commands[i]->draw ( this ); + _commands[i]->draw (); if ( isDrawable("spot") ) _spot.moveTo ( _mousePosition ); _drawingPlanes.end (); @@ -2282,63 +2301,94 @@ namespace Hurricane { void CellWidget::wheelEvent ( QWheelEvent* event ) { - bool commandActive = false; - for ( size_t i=0 ; i<_commands.size() && !commandActive; i++ ) - commandActive = _commands[i]->wheelEvent ( this, event ); - - if ( !commandActive ) QWidget::wheelEvent ( event ); + event->ignore (); + for ( size_t i=0 ; (i<_commands.size()) and not event->isAccepted(); i++ ) { + if ( _activeCommand + and (_commands[i] != _activeCommand ) + and (_commands[i]->getType() != Command::AlwaysActive) ) + continue; + _commands[i]->wheelEvent ( event ); + } } void CellWidget::keyPressEvent ( QKeyEvent* event ) { - bool commandActive = false; - for ( size_t i=0 ; i<_commands.size() && !commandActive; i++ ) - commandActive = _commands[i]->keyPressEvent ( this, event ); - - if ( !commandActive ) QWidget::keyPressEvent ( event ); + event->ignore (); + //cerr << "CellWidget::keyPressEvent " << event->isAccepted() << endl; + for ( size_t i=0 ; (i<_commands.size()) and not event->isAccepted(); i++ ) { + if ( _activeCommand + and (_commands[i] != _activeCommand ) + and (_commands[i]->getType() != Command::AlwaysActive) ) + continue; + //cerr << " Calling [" << i << "] " << _commands[i]->getName() << endl; + _commands[i]->keyPressEvent ( event ); + } } void CellWidget::keyReleaseEvent ( QKeyEvent* event ) { - bool commandActive = false; - for ( size_t i=0 ; i<_commands.size() && !commandActive; i++ ) - commandActive = _commands[i]->keyReleaseEvent ( this, event ); - - if ( !commandActive ) QWidget::keyReleaseEvent ( event ); + event->ignore (); + //cerr << "CellWidget::keyReleaseEvent " << event->isAccepted() << endl; + for ( size_t i=0 ; (i<_commands.size()) and not event->isAccepted(); i++ ) { + if ( _activeCommand + and (_commands[i] != _activeCommand ) + and (_commands[i]->getType() != Command::AlwaysActive) ) + continue; + //cerr << " Calling [" << i << "] " << _commands[i]->getName() << endl; + _commands[i]->keyReleaseEvent ( event ); + } } void CellWidget::mouseMoveEvent ( QMouseEvent* event ) { - bool commandActive = false; - for ( size_t i=0 ; i<_commands.size() && !commandActive; i++ ) - commandActive = _commands[i]->mouseMoveEvent ( this, event ); - - if ( !commandActive ) { - _mousePosition = event->pos(); - updateMousePosition (); - repaint (); + event->ignore (); + for ( size_t i=0 ; (i<_commands.size()) and not event->isAccepted(); i++ ) { + if ( _activeCommand + and (_commands[i] != _activeCommand ) + and (_commands[i]->getType() != Command::AlwaysActive) ) + continue; + _commands[i]->mouseMoveEvent ( event ); } + + _mousePosition = event->pos(); + updateMousePosition (); + repaint (); } void CellWidget::mousePressEvent ( QMouseEvent* event ) { - bool commandActive = false; - for ( size_t i=0 ; i<_commands.size() && !commandActive; i++ ) - commandActive = _commands[i]->mousePressEvent ( this, event ); + event->ignore (); + //cerr << "CellWidget::mousePressEvent " << event->isAccepted() << endl; + for ( size_t i=0 ; (i<_commands.size()) and not event->isAccepted(); i++ ) { + if ( _activeCommand + and (_commands[i] != _activeCommand ) + and (_commands[i]->getType() != Command::AlwaysActive) ) + continue; + //cerr << " Calling [" << i << "] " << _commands[i]->getName() << endl; + _commands[i]->mousePressEvent ( event ); + } - _spot.setShowSpot ( !commandActive ); + _spot.setShowSpot ( !_activeCommand ); } void CellWidget::mouseReleaseEvent ( QMouseEvent* event ) { - bool commandActive = false; - for ( size_t i=0 ; i<_commands.size() && !commandActive; i++ ) - commandActive = _commands[i]->mouseReleaseEvent ( this, event ); + event->ignore (); + //cerr << "CellWidget::mouseReleaseEvent " << event->isAccepted() << endl; + for ( size_t i=0 ; (i<_commands.size()) and not event->isAccepted(); i++ ) { + if ( _activeCommand + and (_commands[i] != _activeCommand ) + and (_commands[i]->getType() != Command::AlwaysActive) ) + continue; + //cerr << " Calling [" << i << "] " << _commands[i]->getName() << endl; + _commands[i]->mouseReleaseEvent ( event ); + } + //if ( not _activeCommand ) QWidget::mouseReleaseEvent ( event ); _spot.setShowSpot ( true ); } @@ -2457,7 +2507,7 @@ namespace Hurricane { Occurrences CellWidget::getOccurrencesUnder ( const Box& area ) const { - return getCell()->getOccurrencesUnder(area).getSubSet(Occurrences_IsSelectable(this)); + return getCell()->getOccurrencesUnder(area,3).getSubSet(Occurrences_IsSelectable(this)); } @@ -2519,6 +2569,7 @@ namespace Hurricane { selector->attachTo(this); + setShowSelection ( true ); _selectionHasChanged = true; if ( !_delaySelectionChanged ) emit selectionChanged(_selectors); } @@ -2592,13 +2643,35 @@ namespace Hurricane { Property* property = occurrence.getProperty ( Selector::getPropertyName() ); Selector* selector = NULL; if ( !property ) { - selector = Selector::create ( occurrence ); - selector->attachTo ( this ); + // Net special case. + Net* net = dynamic_cast(occurrence.getEntity()); + if ( net ) { + if ( occurrence.getPath().isEmpty() ) { + select ( net ); + } else { + cerr << "[UNIMPLEMENTED] Selection of " << occurrence << endl; + } + } else { + selector = Selector::create ( occurrence ); + selector->attachTo ( this ); + setShowSelection ( true ); + } } else { selector = dynamic_cast(property); if ( !selector ) throw Error ( "Abnormal property named " + getString(Selector::getPropertyName()) ); - selector->detachFrom ( this ); + + // Net special case. + Net* net = dynamic_cast(occurrence.getEntity()); + if ( net ) { + if ( occurrence.getPath().isEmpty() ) { + unselect ( net ); + } else { + cerr << "[UNIMPLEMENTED] Selection of " << occurrence << endl; + } + } else { + selector->detachFrom ( this ); + } } _selectionHasChanged = true; diff --git a/hurricane/src/hviewer/Command.cpp b/hurricane/src/hviewer/Command.cpp index 10aaba45..84379315 100644 --- a/hurricane/src/hviewer/Command.cpp +++ b/hurricane/src/hviewer/Command.cpp @@ -39,45 +39,35 @@ namespace Hurricane { Command::Command () - : _cellWidgets() - , _active(false) + : _cellWidget() + , _active (false) { } Command::~Command () { - set::iterator iwidget = _cellWidgets.begin(); - for ( ; iwidget != _cellWidgets.end() ; iwidget++ ) - (*iwidget)->unbindCommand ( this ); + if ( _cellWidget ) _cellWidget->unbindCommand ( this ); } - bool Command::wheelEvent ( CellWidget*, QWheelEvent* ) - { return false; } + Command::Type Command::getType () const + { return Normal; } - bool Command::keyPressEvent ( CellWidget*, QKeyEvent* ) - { return false; } + void Command::setActive ( bool state ) + { + _active = state; + _cellWidget->setActiveCommand ( (state and (getType() != AlwaysActive)) ? this : NULL ); + } - bool Command::keyReleaseEvent ( CellWidget*, QKeyEvent* ) - { return false; } - - - bool Command::mouseMoveEvent ( CellWidget*, QMouseEvent* ) - { return false; } - - - bool Command::mousePressEvent ( CellWidget*, QMouseEvent* ) - { return false; } - - - bool Command::mouseReleaseEvent ( CellWidget*, QMouseEvent* ) - { return false; } - - - void Command::draw ( CellWidget* ) - { } + void Command::wheelEvent ( QWheelEvent* ) { } + void Command::keyPressEvent ( QKeyEvent* ) { } + void Command::keyReleaseEvent ( QKeyEvent* ) { } + void Command::mouseMoveEvent ( QMouseEvent* ) { } + void Command::mousePressEvent ( QMouseEvent* ) { } + void Command::mouseReleaseEvent ( QMouseEvent* ) { } + void Command::draw () { } } // End of Hurricane namespace. diff --git a/hurricane/src/hviewer/HierarchyCommand.cpp b/hurricane/src/hviewer/HierarchyCommand.cpp index 2dede1f1..b9ce7906 100644 --- a/hurricane/src/hviewer/HierarchyCommand.cpp +++ b/hurricane/src/hviewer/HierarchyCommand.cpp @@ -40,62 +40,64 @@ namespace Hurricane { // Class : "HierarchyCommand". + string HierarchyCommand::_name = "HierarchyCommand"; + + HierarchyCommand::HierarchyCommand () - : Command () - , _history() + : Command () + , _history () , _historyIndex(0) - { - } + { } HierarchyCommand::~HierarchyCommand () - { - } + { } - bool HierarchyCommand::keyReleaseEvent ( CellWidget* widget, QKeyEvent* event ) + const string& HierarchyCommand::getName () const + { return _name; } + + + void HierarchyCommand::keyReleaseEvent ( QKeyEvent* event ) { bool control = (event->modifiers() & Qt::ControlModifier); bool shift = (event->modifiers() & Qt::ShiftModifier ); - if ( !shift && !control ) return false; - if ( !widget->getCell() ) return false; + if ( !shift && !control ) return; + if ( !_cellWidget->getCell() ) return; - QPoint position ( widget->mapFromGlobal(QCursor::pos()) ); - Box pointBox ( widget->screenToDbuBox(QRect(position,QSize(1,1))) ); + QPoint position ( _cellWidget->mapFromGlobal(QCursor::pos()) ); + Box pointBox ( _cellWidget->screenToDbuBox(QRect(position,QSize(1,1))) ); switch ( event->key() ) { case Qt::Key_Up: if ( ( _historyIndex > 0 ) && (shift || control) ) { - widget->setState ( _history[--_historyIndex]._state ); + _cellWidget->setState ( _history[--_historyIndex]._state ); } break; case Qt::Key_Down: { if ( control ) { if ( _history.empty() ) - _history.push_back ( HistoryEntry ( NULL, widget->getState() ) ); + _history.push_back ( HistoryEntry ( NULL, _cellWidget->getState() ) ); - Instances instances = widget->getCell()->getInstancesUnder ( pointBox ); + Instances instances = _cellWidget->getCell()->getInstancesUnder ( pointBox ); if ( !instances.isEmpty() ) { _history.erase ( _history.begin()+_historyIndex+1, _history.end() ); Instance* instance = instances.getFirst (); - widget->setCell ( instance->getMasterCell() ); - _history.push_back ( HistoryEntry ( instance, widget->getState() ) ); + _cellWidget->setCell ( instance->getMasterCell() ); + _history.push_back ( HistoryEntry ( instance, _cellWidget->getState() ) ); _historyIndex++; } } else if ( shift ) { if ( _historyIndex+1 < _history.size() ) { - widget->setState ( _history[++_historyIndex]._state ); + _cellWidget->setState ( _history[++_historyIndex]._state ); } } } break; - default: - return false; } - return true; } diff --git a/hurricane/src/hviewer/MoveCommand.cpp b/hurricane/src/hviewer/MoveCommand.cpp index 9e550f98..3b75886c 100644 --- a/hurricane/src/hviewer/MoveCommand.cpp +++ b/hurricane/src/hviewer/MoveCommand.cpp @@ -37,6 +37,9 @@ namespace Hurricane { // Class : "MoveCommand". + string MoveCommand::_name = "MoveCommand"; + + MoveCommand::MoveCommand () : Command () , _firstEvent (true) @@ -48,47 +51,53 @@ namespace Hurricane { { } - bool MoveCommand::keyPressEvent ( CellWidget* widget, QKeyEvent* event ) + const string& MoveCommand::getName () const + { return _name; } + + + Command::Type MoveCommand::getType () const + { return AlwaysActive; } + + + void MoveCommand::keyPressEvent ( QKeyEvent* event ) { if ( event->modifiers() & (Qt::ControlModifier|Qt::ShiftModifier) ) - return false; + return; switch ( event->key() ) { - case Qt::Key_Up: widget->goUp (); return true; - case Qt::Key_Down: widget->goDown (); return true; - case Qt::Key_Left: widget->goLeft (); return true; - case Qt::Key_Right: widget->goRight (); return true; + case Qt::Key_Up: _cellWidget->goUp (); return; + case Qt::Key_Down: _cellWidget->goDown (); return; + case Qt::Key_Left: _cellWidget->goLeft (); return; + case Qt::Key_Right: _cellWidget->goRight (); return; case Qt::Key_Space: if ( !isActive() ) { setActive ( true ); _firstEvent = true; - //_lastPosition = widget->getMousePosition(); - widget->pushCursor ( Qt::ClosedHandCursor ); - return true; + //_lastPosition = _cellWidget->getMousePosition(); + _cellWidget->pushCursor ( Qt::ClosedHandCursor ); + return; } } - return false; } - bool MoveCommand::keyReleaseEvent ( CellWidget* widget, QKeyEvent* event ) + void MoveCommand::keyReleaseEvent ( QKeyEvent* event ) { switch ( event->key() ) { case Qt::Key_Space: if ( isActive() && !event->isAutoRepeat() ) { setActive ( false ); - widget->popCursor (); - return true; + _cellWidget->popCursor (); + return; } break; } - return false; } - bool MoveCommand::mouseMoveEvent ( CellWidget* widget, QMouseEvent* event ) + void MoveCommand::mouseMoveEvent ( QMouseEvent* event ) { - if ( !isActive() ) return false; + if ( !isActive() ) return; QPoint eventPosition = event->pos(); if ( _firstEvent ) { _firstEvent = false; _lastPosition = eventPosition; } @@ -101,24 +110,10 @@ namespace Hurricane { dx -= rx; dy -= ry; - if ( dx > 0 ) widget->goLeft ( dx ); - if ( dx < 0 ) widget->goRight ( -dx ); - if ( dy > 0 ) widget->goUp ( dy ); - if ( dy < 0 ) widget->goDown ( -dy ); - - return true; - } - - - bool MoveCommand::mousePressEvent ( CellWidget* widget, QMouseEvent* event ) - { - return isActive(); - } - - - bool MoveCommand::mouseReleaseEvent ( CellWidget* widget, QMouseEvent* event ) - { - return isActive(); + if ( dx > 0 ) _cellWidget->goLeft ( dx ); + if ( dx < 0 ) _cellWidget->goRight ( -dx ); + if ( dy > 0 ) _cellWidget->goUp ( dy ); + if ( dy < 0 ) _cellWidget->goDown ( -dy ); } diff --git a/hurricane/src/hviewer/RulerCommand.cpp b/hurricane/src/hviewer/RulerCommand.cpp index a55d90f2..c449d1ee 100644 --- a/hurricane/src/hviewer/RulerCommand.cpp +++ b/hurricane/src/hviewer/RulerCommand.cpp @@ -37,9 +37,12 @@ namespace Hurricane { // Class : "RulerCommand". + string RulerCommand::_name = "RulerCommand"; + + RulerCommand::RulerCommand () - : Command () - , _ruler () + : Command() + , _ruler () { } @@ -47,62 +50,54 @@ namespace Hurricane { { } - bool RulerCommand::keyPressEvent ( CellWidget* widget, QKeyEvent* event ) - { - return false; - } + const string& RulerCommand::getName () const + { return _name; } - bool RulerCommand::keyReleaseEvent ( CellWidget* widget, QKeyEvent* event ) - { - return false; - } - - - bool RulerCommand::mouseMoveEvent ( CellWidget* widget, QMouseEvent* event ) - { - if ( !isActive() ) return false; - - _ruler->setExtremity ( widget->_onSnapGrid(widget->screenToDbuPoint(event->pos())) ); - widget->update (); - - return true; - } - - - bool RulerCommand::mousePressEvent ( CellWidget* widget, QMouseEvent* event ) - { - if ( event->modifiers() & Qt::ShiftModifier ) { - if ( event->button() == Qt::LeftButton ) { - if ( !isActive() ) { - setActive ( true ); - _ruler.reset ( new Ruler - (widget->_onSnapGrid(widget->screenToDbuPoint(widget->getMousePosition())) ) ); - return true; - } else { - widget->addRuler ( _ruler ); - setActive ( false ); - _ruler.reset (); - } - } else if ( event->button() == Qt::RightButton ){ - if ( isActive() ) { - setActive ( false ); - _ruler.reset (); - } - } - } - return isActive(); - } - - - bool RulerCommand::mouseReleaseEvent ( CellWidget* widget, QMouseEvent* event ) - { return false; } - - - void RulerCommand::draw ( CellWidget* widget ) + void RulerCommand::mouseMoveEvent ( QMouseEvent* event ) { if ( !isActive() ) return; - widget->drawRuler ( _ruler ); + + _ruler->setExtremity ( _cellWidget->_onSnapGrid(_cellWidget->screenToDbuPoint(event->pos())) ); + _cellWidget->update (); + } + + + void RulerCommand::mousePressEvent ( QMouseEvent* event ) + { + if ( (event->modifiers() & Qt::ShiftModifier ) + and (event->button() == Qt::LeftButton ) ) { + setActive ( true ); + _ruler.reset ( new Ruler + (_cellWidget->_onSnapGrid(_cellWidget->screenToDbuPoint(_cellWidget->getMousePosition())) ) ); + return; + } + + if ( isActive() ) { + if ( event->button() != Qt::RightButton ) + _cellWidget->addRuler ( _ruler ); + + setActive ( false ); + _ruler.reset (); + } + } + + + void RulerCommand::keyPressEvent ( QKeyEvent* event ) + { + if ( !isActive() ) return; + + if ( event->key() == Qt::Key_Escape ) { + setActive ( false ); + _ruler.reset (); + } + } + + + void RulerCommand::draw () + { + if ( !isActive() ) return; + _cellWidget->drawRuler ( _ruler ); } diff --git a/hurricane/src/hviewer/SelectCommand.cpp b/hurricane/src/hviewer/SelectCommand.cpp index a1777dad..9b7077d6 100644 --- a/hurricane/src/hviewer/SelectCommand.cpp +++ b/hurricane/src/hviewer/SelectCommand.cpp @@ -23,27 +23,182 @@ // x-----------------------------------------------------------------x -#include -#include -#include +#include +#include +#include -#include "hurricane/Cell.h" +#include -#include "hurricane/viewer/CellWidget.h" -#include "hurricane/viewer/SelectCommand.h" -#include "hurricane/viewer/SelectionPopup.h" +#include "hurricane/Path.h" +#include "hurricane/Entity.h" +#include "hurricane/Net.h" +#include "hurricane/Component.h" +#include "hurricane/Occurrence.h" +#include "hurricane/HyperNet.h" +#include "hurricane/Cell.h" +#include "hurricane/viewer/CellWidget.h" +#include "hurricane/viewer/SelectCommand.h" +#include "hurricane/viewer/SelectionPopup.h" namespace Hurricane { + typedef Locator OccurrenceLoc; + typedef Collection OccurrenceCol; + + +// ------------------------------------------------------------------- +// Class : "Hurricane::Occurrence_GetNets". + + + class Occurrences_GetNets : public OccurrenceCol { + + public: + // Sub-Class: Locator. + class Locator : public OccurrenceLoc { + public: + Locator ( Occurrences, bool hideAnon ); + inline Locator ( const Locator& ); + inline ~Locator (); + virtual Occurrence getElement () const; + virtual OccurrenceLoc* getClone () const; + virtual bool isValid () const; + virtual void progress (); + virtual string _getString () const; + protected: + OccurrenceLoc* _primaryLoc; + Occurrence _element; + set _netOccurrences; + bool _hideAnonymous; + }; + + public: + // Occurrences_GetNets Methods. + inline Occurrences_GetNets ( Occurrences, bool hideAnon ); + inline Occurrences_GetNets ( const Occurrences_GetNets& ); + virtual OccurrenceCol* getClone () const; + virtual OccurrenceLoc* getLocator () const; + virtual string _getString () const; + + protected: + // Occurrences_GetNets Attributes. + Occurrences _primaryCol; + bool _hideAnonymous; + }; + + + inline Occurrences_GetNets::Locator::Locator ( const Locator &locator ) + : OccurrenceLoc () + , _primaryLoc (locator._primaryLoc->getClone()) + , _element () + , _netOccurrences() + , _hideAnonymous (locator._hideAnonymous) + { } + + + inline Occurrences_GetNets::Locator::~Locator () + { delete _primaryLoc; } + + + inline Occurrences_GetNets::Occurrences_GetNets ( Occurrences primaryCol, bool hideAnon ) + : OccurrenceCol () + , _primaryCol (primaryCol) + , _hideAnonymous(hideAnon) + { } + + + inline Occurrences_GetNets::Occurrences_GetNets ( const Occurrences_GetNets& occurrences ) + : OccurrenceCol () + , _primaryCol (occurrences._primaryCol) + , _hideAnonymous(occurrences._hideAnonymous) + { } + + + Occurrences_GetNets::Locator::Locator ( Occurrences primaryCol, bool hideAnon ) + : OccurrenceLoc () + , _primaryLoc (primaryCol.getLocator()) + , _element () + , _netOccurrences() + , _hideAnonymous (hideAnon) + { progress (); } + + + OccurrenceLoc* Occurrences_GetNets::Locator::getClone () const + { return new Locator(*this); } + + + Occurrence Occurrences_GetNets::Locator::getElement () const + { return _element; } + + + bool Occurrences_GetNets::Locator::isValid () const + { return _primaryLoc->isValid(); } + + + void Occurrences_GetNets::Locator::progress () + { + ltrace(80) << "Occurrences_GetNets::Locator::progress()" << endl; + + boost::regex pattern ( "onymous" ); + boost::smatch match; + + for ( ; _primaryLoc->isValid() ; _primaryLoc->progress() ) { + Occurrence element = _primaryLoc->getElement(); + + Component* component = dynamic_cast(element.getEntity()); + if ( not component ) continue; + + Net* net = component->getNet(); + Occurrence netOccurrence ( net, element.getPath() ); + + if ( _hideAnonymous + and boost::regex_search(getString(net->getName()),match,pattern,boost::match_extra) ) + continue; + + _element = getHyperNetRootNetOccurrence ( netOccurrence ); + + if ( _netOccurrences.find(_element) != _netOccurrences.end() ) continue; + _netOccurrences.insert ( _element ); + + break; + } + } + + + string Occurrences_GetNets::Locator::_getString () const + { + string s = "<" + _TName("Occurrences_GetNets::Locator") + ">"; + return s; + } + + + OccurrenceCol* Occurrences_GetNets::getClone () const + { return new Occurrences_GetNets(*this); } + + + OccurrenceLoc* Occurrences_GetNets::getLocator () const + { return new Locator(_primaryCol,_hideAnonymous); } + + + string Occurrences_GetNets::_getString () const + { + string s = "<" + _TName("Occurrences_GetNets") + ">"; + return s; + } + + // ------------------------------------------------------------------- // Class : "SelectCommand". + string SelectCommand::_name = "SelectCommand"; + + SelectCommand::SelectCommand () - : AreaCommand() + : AreaCommand () , _selectionPopup(NULL) + , _selectMode (0) { _selectionPopup = new SelectionPopup (); @@ -53,39 +208,64 @@ namespace Hurricane { SelectCommand::~SelectCommand () + { delete _selectionPopup; } + + + const string& SelectCommand::getName () const + { return _name; } + + + void SelectCommand::keyPressEvent ( QKeyEvent* event ) { - delete _selectionPopup; + if ( event->key() == Qt::Key_N ) { + event->accept(); + _selectMode = (++_selectMode) % 3; + } } - bool SelectCommand::mousePressEvent ( CellWidget* widget, QMouseEvent* event ) + void SelectCommand::mousePressEvent ( QMouseEvent* event ) { - if ( isActive() ) return true; + if ( isActive() ) return; if ( event->button() == Qt::RightButton ) { if ( !event->modifiers() ) { + event->accept (); setActive ( true ); setStartPoint ( event->pos() ); setDrawingEnabled ( true ); } else if ( event->modifiers() == Qt::ControlModifier ) { - QRect selectArea ( event->pos() - QPoint(2,2), QSize(4,4) ); - forEach ( Occurrence, ioccurrence, widget->getOccurrencesUnder(selectArea) ) - _selectionPopup->add ( *ioccurrence ); + event->accept (); + QRect selectArea ( event->pos() - QPoint(2,2), QSize(4,4) ); + //_selectionPopup->loadOccurrences ( _cellWidget->getOccurrencesUnder(selectArea) ); + Occurrences selection; + switch ( _selectMode ) { + case 0: + selection = _cellWidget->getOccurrencesUnder(selectArea); + break; + case 1: + selection = Occurrences_GetNets(_cellWidget->getOccurrencesUnder(selectArea),false); + break; + case 2: + selection = Occurrences_GetNets(_cellWidget->getOccurrencesUnder(selectArea),true); + break; + } + _selectionPopup->loadOccurrences ( selection ); _selectionPopup->updateLayout (); _selectionPopup->move ( event->globalPos() ); _selectionPopup->popup (); } } - - return isActive(); } - bool SelectCommand::mouseReleaseEvent ( CellWidget* widget, QMouseEvent* event ) + void SelectCommand::mouseReleaseEvent ( QMouseEvent* event ) { - if ( !isActive() ) - _startPoint = _stopPoint = event->pos(); + if ( !isActive() ) return; + //_startPoint = _stopPoint = event->pos(); + + event->accept (); setActive ( false ); setDrawingEnabled ( false ); @@ -96,16 +276,14 @@ namespace Hurricane { else selectArea = QRect ( _startPoint, _stopPoint ); - //widget->unselectAll (); - widget->selectOccurrencesUnder ( widget->screenToDbuBox(selectArea) ); - bool somethingSelected = !widget->getSelectorSet().empty(); + //_cellWidget->unselectAll (); + _cellWidget->selectOccurrencesUnder ( _cellWidget->screenToDbuBox(selectArea) ); + bool somethingSelected = !_cellWidget->getSelectorSet().empty(); - if ( widget->getState()->showSelection() != somethingSelected ) - widget->setShowSelection ( somethingSelected ); + if ( _cellWidget->showSelection() != somethingSelected ) + _cellWidget->setShowSelection ( somethingSelected ); else - widget->refresh (); - - return true; + _cellWidget->refresh (); } diff --git a/hurricane/src/hviewer/SelectionPopup.cpp b/hurricane/src/hviewer/SelectionPopup.cpp index 4f98e223..da8fc325 100644 --- a/hurricane/src/hviewer/SelectionPopup.cpp +++ b/hurricane/src/hviewer/SelectionPopup.cpp @@ -2,7 +2,7 @@ // -*- C++ -*- // // 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 // // =================================================================== // @@ -29,16 +29,18 @@ #include #include -#include "hurricane/Commons.h" - -#include "hurricane/viewer/Graphics.h" -#include "hurricane/viewer/SelectionPopupModel.h" -#include "hurricane/viewer/SelectionPopup.h" +#include "hurricane/Commons.h" +#include "hurricane/viewer/Graphics.h" +#include "hurricane/viewer/SelectionPopupModel.h" +#include "hurricane/viewer/SelectionPopup.h" namespace Hurricane { +// ------------------------------------------------------------------- +// Class : "Hurricane::SelectionPopup". + SelectionPopup::SelectionPopup ( QWidget* parent ) : QWidget(parent) @@ -98,9 +100,8 @@ namespace Hurricane { void SelectionPopup::keyPressEvent ( QKeyEvent* event ) { - cerr << "SelectionPopup::keyPressEvent()" << endl; - - QWidget::keyPressEvent ( event ); + //cerr << "SelectionPopup::keyPressEvent()" << endl; + //QWidget::keyPressEvent ( event ); } @@ -132,16 +133,12 @@ namespace Hurricane { } - void SelectionPopup::add ( Occurrence occurrence, bool showChange ) - { - _model->add ( occurrence, showChange ); - } + void SelectionPopup::loadOccurrences ( Occurrences occurrences, bool showChange ) + { _model->loadOccurrences ( occurrences, showChange ); } void SelectionPopup::clear () - { - _model->clear (); - } + { _model->clear (); } void SelectionPopup::updateLayout () @@ -158,4 +155,12 @@ namespace Hurricane { } + void SelectionPopup::clearFilter () + { if (_model) _model->clearFilter(); } + + + void SelectionPopup::setFilter ( OccurrenceFilter filter ) + { if (_model) _model->setFilter(filter); } + + } // End of Hurricane namespace. diff --git a/hurricane/src/hviewer/SelectionPopupModel.cpp b/hurricane/src/hviewer/SelectionPopupModel.cpp index 5a270c4d..d368f16a 100644 --- a/hurricane/src/hviewer/SelectionPopupModel.cpp +++ b/hurricane/src/hviewer/SelectionPopupModel.cpp @@ -36,23 +36,56 @@ namespace Hurricane { +// ------------------------------------------------------------------- +// Class : "Occurrence_AcceptAll". + + + class Occurrence_AcceptAll : public Filter { + public: + virtual Filter* getClone () const; + virtual bool accept ( Occurrence ) const; + virtual string _getString () const; + }; + + + Filter* Occurrence_AcceptAll::getClone () const { return new Occurrence_AcceptAll(); } + bool Occurrence_AcceptAll::accept ( Occurrence ) const { return true; } + string Occurrence_AcceptAll::_getString () const { return ""; } + + +// ------------------------------------------------------------------- +// Class : "Hurricane::SelectionPopupModel". + + SelectionPopupModel::SelectionPopupModel ( QObject* parent ) : QAbstractTableModel(parent) - , _occurrences(NULL) + , _filter (new Occurrence_AcceptAll()) + , _occurrences (NULL) { } SelectionPopupModel::~SelectionPopupModel () - { - clear (); - } + { clear (); } - void SelectionPopupModel::add ( Occurrence occurrence, bool showChange ) + void SelectionPopupModel::clearFilter () + { _filter = new Occurrence_AcceptAll(); } + + + void SelectionPopupModel::setFilter ( OccurrenceFilter filter ) + { _filter = filter; } + + + OccurrenceFilter SelectionPopupModel::getFilter () + { return _filter; } + + + void SelectionPopupModel::loadOccurrences ( Occurrences occurrences, bool showChange ) { if ( !_occurrences ) _occurrences = new vector (); - - _occurrences->push_back ( occurrence ); + forEach ( Occurrence, ioccurrence, occurrences.getSubSet(getFilter()) ) { + _occurrences->push_back ( *ioccurrence ); + } if ( showChange ) emit layoutChanged (); } @@ -68,9 +101,7 @@ namespace Hurricane { void SelectionPopupModel::updateLayout () - { - emit layoutChanged (); - } + { emit layoutChanged (); } QVariant SelectionPopupModel::data ( const QModelIndex& index, int role ) const diff --git a/hurricane/src/hviewer/ZoomCommand.cpp b/hurricane/src/hviewer/ZoomCommand.cpp index 48f68ce5..dc1e1eb3 100644 --- a/hurricane/src/hviewer/ZoomCommand.cpp +++ b/hurricane/src/hviewer/ZoomCommand.cpp @@ -38,6 +38,9 @@ namespace Hurricane { // Class : "ZoomCommand". + string ZoomCommand::_name = "ZoomCommand"; + + ZoomCommand::ZoomCommand () : AreaCommand() { } @@ -47,51 +50,56 @@ namespace Hurricane { { } - bool ZoomCommand::wheelEvent ( CellWidget* widget, QWheelEvent* event ) - { - if ( event->delta() > 0 ) widget->setScale ( widget->getScale()/1.2 ); - else if ( event->delta() < 0 ) widget->setScale ( widget->getScale()*1.2 ); - event->accept (); + const string& ZoomCommand::getName () const + { return _name; } - return true; + + Command::Type ZoomCommand::getType () const + { return AlwaysActive; } + + + void ZoomCommand::wheelEvent ( QWheelEvent* event ) + { + if ( event->delta() > 0 ) _cellWidget->setScale ( _cellWidget->getScale()/1.2 ); + else if ( event->delta() < 0 ) _cellWidget->setScale ( _cellWidget->getScale()*1.2 ); + event->accept (); } - bool ZoomCommand::keyPressEvent ( CellWidget* widget, QKeyEvent* event ) + void ZoomCommand::keyPressEvent ( QKeyEvent* event ) { bool control = (event->modifiers() & Qt::ControlModifier); switch ( event->key() ) { case Qt::Key_Z: - if ( control ) widget->scaleHistoryDown(); - else widget->setScale ( widget->getScale()*2.0 ); - return true; + if ( control ) _cellWidget->scaleHistoryDown(); + else _cellWidget->setScale ( _cellWidget->getScale()*2.0 ); + return; case Qt::Key_M: - if ( control ) widget->scaleHistoryUp (); - else widget->setScale ( widget->getScale()/2.0 ); - return true; + if ( control ) _cellWidget->scaleHistoryUp (); + else _cellWidget->setScale ( _cellWidget->getScale()/2.0 ); + return; } - return false; } - bool ZoomCommand::mousePressEvent ( CellWidget* widget, QMouseEvent* event ) + void ZoomCommand::mousePressEvent ( QMouseEvent* event ) { - if ( isActive() ) return true; + if ( isActive() ) return; + if ( _cellWidget->getActiveCommand() and (_cellWidget->getActiveCommand() != this) ) + return; if ( ( event->button() == Qt::LeftButton ) && !event->modifiers() ) { setActive ( true ); setStartPoint ( event->pos() ); setDrawingEnabled ( true ); } - - return isActive(); } - bool ZoomCommand::mouseReleaseEvent ( CellWidget* widget, QMouseEvent* event ) + void ZoomCommand::mouseReleaseEvent ( QMouseEvent* event ) { - if ( !isActive() ) return false; + if ( !isActive() ) return; setActive ( false ); setDrawingEnabled ( false ); @@ -99,14 +107,13 @@ namespace Hurricane { QRect zoomArea = QRect ( _startPoint, _stopPoint ); if ( ( abs(zoomArea.width ()) > getDrawingThreshold() ) && ( abs(zoomArea.height()) > getDrawingThreshold() ) ) { - widget->reframe ( widget->screenToDbuBox(zoomArea) ); - return true; - } // else { + _cellWidget->reframe ( _cellWidget->screenToDbuBox(zoomArea) ); + return; + } + //else { // cerr << Warning("Rejecting too small zoom request.") << endl; - // widget->update (); + // _cellWidget->update (); //} - - return false; } diff --git a/hurricane/src/hviewer/hurricane/viewer/AreaCommand.h b/hurricane/src/hviewer/hurricane/viewer/AreaCommand.h index c428ee23..6e006c95 100644 --- a/hurricane/src/hviewer/hurricane/viewer/AreaCommand.h +++ b/hurricane/src/hviewer/hurricane/viewer/AreaCommand.h @@ -36,26 +36,26 @@ namespace Hurricane { class AreaCommand : public Command { public: - AreaCommand (); - virtual ~AreaCommand (); - inline void setStartPoint ( const QPoint& start ); - inline void setStopPoint ( const QPoint& stop ); - inline void setDrawingEnabled ( bool state ); - inline void setDrawingThreshold ( int ); - virtual void draw ( CellWidget* widget ); - virtual void drawCorner ( CellWidget* widget, bool bottomLeft ); - virtual bool mouseMoveEvent ( CellWidget* widget, QMouseEvent* event ); - inline bool isDrawingEnabled () const; - inline int getDrawingThreshold () const; + AreaCommand (); + virtual ~AreaCommand (); + inline void setStartPoint ( const QPoint& start ); + inline void setStopPoint ( const QPoint& stop ); + inline void setDrawingEnabled ( bool state ); + inline void setDrawingThreshold ( int ); + virtual void draw (); + virtual void drawCorner ( bool bottomLeft ); + virtual void mouseMoveEvent ( QMouseEvent* event ); + inline bool isDrawingEnabled () const; + inline int getDrawingThreshold () const; protected: - QPoint _startPoint; - QPoint _stopPoint; - QPoint _cornerPoints[3]; - int _drawingThreshold; - bool _drawingEnabled; + QPoint _startPoint; + QPoint _stopPoint; + QPoint _cornerPoints[3]; + int _drawingThreshold; + bool _drawingEnabled; private: - AreaCommand ( const AreaCommand& ); - AreaCommand& operator= ( const AreaCommand& ); + AreaCommand ( const AreaCommand& ); + AreaCommand& operator= ( const AreaCommand& ); }; diff --git a/hurricane/src/hviewer/hurricane/viewer/CellViewer.h b/hurricane/src/hviewer/hurricane/viewer/CellViewer.h index c33500e2..a35efb5c 100644 --- a/hurricane/src/hviewer/hurricane/viewer/CellViewer.h +++ b/hurricane/src/hviewer/hurricane/viewer/CellViewer.h @@ -64,7 +64,9 @@ namespace Hurricane { class CellViewer : public QMainWindow { Q_OBJECT; - + + public: + enum { CellHistorySize = 10 }; public: CellViewer ( QWidget* parent=NULL ); virtual ~CellViewer (); @@ -93,52 +95,50 @@ namespace Hurricane { void showSelectionToggled ( bool ); void stateChanged ( shared_ptr& ); void redrawCellWidget (); - - public: - enum { CellHistorySize = 10 }; - protected: - QString _applicationName; - QAction* _toolInterruptAction; - QAction* _openAction; - QAction* _nextAction; - QAction* _cellHistoryAction[CellHistorySize]; - QAction* _printAction; - QAction* _imageAction; - QAction* _saveAction; - QAction* _closeAction; - QAction* _exitAction; - QAction* _refreshAction; - QAction* _fitToContentsAction; - QAction* _showSelectionAction; - QAction* _rubberChangeAction; - QAction* _clearRulersAction; - QAction* _controllerAction; - QMenu* _fileMenu; - QMenu* _viewMenu; - QMenu* _toolsMenu; - QMenu* _debugMenu; - //MapView* _mapView; - HPalette* _palette; - MousePositionWidget* _mousePosition; - ControllerWidget* _controller; - CellWidget* _cellWidget; - MoveCommand _moveCommand; - ZoomCommand _zoomCommand; - RulerCommand _rulerCommand; - SelectCommand _selectCommand; - HierarchyCommand _hierarchyCommand; - list< shared_ptr > - _cellHistory; - bool _firstShow; - bool _toolInterrupt; - UpdateState _updateState; - protected: void createActions (); void createMenus (); void createLayout (); void refreshTitle (); void refreshHistory (); + + protected: + QString _applicationName; + QAction* _toolInterruptAction; + QAction* _openAction; + QAction* _nextAction; + QAction* _cellHistoryAction[CellHistorySize]; + QAction* _printAction; + QAction* _imageAction; + QAction* _saveAction; + QAction* _closeAction; + QAction* _exitAction; + QAction* _refreshAction; + QAction* _fitToContentsAction; + QAction* _showSelectionAction; + QAction* _rubberChangeAction; + QAction* _clearRulersAction; + QAction* _controllerAction; + QMenu* _fileMenu; + QMenu* _viewMenu; + QMenu* _toolsMenu; + QMenu* _debugMenu; + //MapView* _mapView; + HPalette* _palette; + MousePositionWidget* _mousePosition; + ControllerWidget* _controller; + CellWidget* _cellWidget; + MoveCommand _moveCommand; + ZoomCommand _zoomCommand; + RulerCommand _rulerCommand; + SelectCommand _selectCommand; + HierarchyCommand _hierarchyCommand; + list< shared_ptr > + _cellHistory; + bool _firstShow; + bool _toolInterrupt; + UpdateState _updateState; + }; diff --git a/hurricane/src/hviewer/hurricane/viewer/CellWidget.h b/hurricane/src/hviewer/hurricane/viewer/CellWidget.h index 664eced1..c2e9d80c 100644 --- a/hurricane/src/hviewer/hurricane/viewer/CellWidget.h +++ b/hurricane/src/hviewer/hurricane/viewer/CellWidget.h @@ -137,6 +137,9 @@ namespace Hurricane { void detachFromPalette (); void bindCommand ( Command* ); void unbindCommand ( Command* ); + inline void setActiveCommand ( Command* ); + inline Command* getActiveCommand () const; + inline void resetActiveCommand (); inline void setCursorStep ( DbU::Unit ); inline bool realMode () const; inline bool symbolicMode () const; @@ -625,6 +628,7 @@ namespace Hurricane { bool _cellModificated; bool _enableRedrawInterrupt; SelectorSet _selectors; + Command* _activeCommand; vector _commands; size_t _redrawRectCount; int _textFontHeight; @@ -1018,16 +1022,28 @@ namespace Hurricane { { return _scaleHistory[_ihistory]._scale; } - CellWidget::FindStateName::FindStateName ( const Name& cellName ) + inline CellWidget::FindStateName::FindStateName ( const Name& cellName ) : unary_function< const shared_ptr&, bool >() , _cellName(cellName) { } - bool CellWidget::FindStateName::operator () ( const shared_ptr& state ) + inline bool CellWidget::FindStateName::operator () ( const shared_ptr& state ) { return state->getName() == _cellName; } + inline void CellWidget::setActiveCommand ( Command* command ) + { _activeCommand = command; } + + + inline Command* CellWidget::getActiveCommand () const + { return _activeCommand; } + + + inline void CellWidget::resetActiveCommand () + { _activeCommand = NULL; } + + inline void CellWidget::setCursorStep ( DbU::Unit step ) { _state->setCursorStep(step); } diff --git a/hurricane/src/hviewer/hurricane/viewer/Command.h b/hurricane/src/hviewer/hurricane/viewer/Command.h index 96790090..6f782082 100644 --- a/hurricane/src/hviewer/hurricane/viewer/Command.h +++ b/hurricane/src/hviewer/hurricane/viewer/Command.h @@ -27,9 +27,9 @@ #define __HURRICANE_COMMAND_H__ -#include +#include -using namespace std; +using std::map; class QKeyEvent; @@ -45,31 +45,34 @@ namespace Hurricane { class Command { public: - Command (); - virtual ~Command (); - inline bool isActive (); - inline void setActive ( bool state ); - virtual bool wheelEvent ( CellWidget*, QWheelEvent* ); - virtual bool keyPressEvent ( CellWidget*, QKeyEvent* ); - virtual bool keyReleaseEvent ( CellWidget*, QKeyEvent* ); - virtual bool mouseMoveEvent ( CellWidget*, QMouseEvent* ); - virtual bool mousePressEvent ( CellWidget*, QMouseEvent* ); - virtual bool mouseReleaseEvent ( CellWidget*, QMouseEvent* ); - virtual void draw ( CellWidget* ); - inline set& getCellWidgets (); + enum Type { Normal=1, AlwaysActive=2 }; + public: + Command (); + virtual ~Command (); + virtual const string& getName () const = 0; + virtual Type getType () const; + inline bool isActive () const; + void setActive ( bool state ); + inline void setCellWidget ( CellWidget* ); + virtual void wheelEvent ( QWheelEvent* ); + virtual void keyPressEvent ( QKeyEvent* ); + virtual void keyReleaseEvent ( QKeyEvent* ); + virtual void mouseMoveEvent ( QMouseEvent* ); + virtual void mousePressEvent ( QMouseEvent* ); + virtual void mouseReleaseEvent ( QMouseEvent* ); + virtual void draw (); private: - set _cellWidgets; - bool _active; - private: - Command ( const Command& ); - Command& operator= ( const Command& ); + Command ( const Command& ); + Command& operator= ( const Command& ); + protected: + CellWidget* _cellWidget; + bool _active; }; // Inline Functions. - inline set& Command::getCellWidgets () { return _cellWidgets; } - inline bool Command::isActive () { return _active; } - inline void Command::setActive ( bool state ) { _active = state; } + bool Command::isActive () const { return _active; } + void Command::setCellWidget ( CellWidget* widget ) { _cellWidget=widget; } } diff --git a/hurricane/src/hviewer/hurricane/viewer/HierarchyCommand.h b/hurricane/src/hviewer/hurricane/viewer/HierarchyCommand.h index dcb5e552..d2627355 100644 --- a/hurricane/src/hviewer/hurricane/viewer/HierarchyCommand.h +++ b/hurricane/src/hviewer/hurricane/viewer/HierarchyCommand.h @@ -51,7 +51,11 @@ namespace Hurricane { public: HierarchyCommand (); virtual ~HierarchyCommand (); - virtual bool keyReleaseEvent ( CellWidget*, QKeyEvent* ); + virtual const string& getName () const; + virtual void keyReleaseEvent ( QKeyEvent* ); + private: + HierarchyCommand ( const HierarchyCommand& ); + HierarchyCommand& operator= ( const HierarchyCommand& ); private: class HistoryEntry { @@ -61,11 +65,8 @@ namespace Hurricane { Instance* _instance; shared_ptr _state; }; - - private: - HierarchyCommand ( const HierarchyCommand& ); - HierarchyCommand& operator= ( const HierarchyCommand& ); private: + static string _name; vector _history; size_t _historyIndex; }; diff --git a/hurricane/src/hviewer/hurricane/viewer/MoveCommand.h b/hurricane/src/hviewer/hurricane/viewer/MoveCommand.h index 48defe17..dd4125d0 100644 --- a/hurricane/src/hviewer/hurricane/viewer/MoveCommand.h +++ b/hurricane/src/hviewer/hurricane/viewer/MoveCommand.h @@ -36,19 +36,20 @@ namespace Hurricane { class MoveCommand : public Command { public: - MoveCommand (); - virtual ~MoveCommand (); - virtual bool keyPressEvent ( CellWidget*, QKeyEvent* ); - virtual bool keyReleaseEvent ( CellWidget*, QKeyEvent* ); - virtual bool mouseMoveEvent ( CellWidget*, QMouseEvent* ); - virtual bool mousePressEvent ( CellWidget*, QMouseEvent* ); - virtual bool mouseReleaseEvent ( CellWidget*, QMouseEvent* ); + MoveCommand (); + virtual ~MoveCommand (); + virtual const string& getName () const; + virtual Type getType () const; + virtual void keyPressEvent ( QKeyEvent* ); + virtual void keyReleaseEvent ( QKeyEvent* ); + virtual void mouseMoveEvent ( QMouseEvent* ); private: - bool _firstEvent; - QPoint _lastPosition; + MoveCommand ( const MoveCommand& ); + MoveCommand& operator= ( const MoveCommand& ); private: - MoveCommand ( const MoveCommand& ); - MoveCommand& operator= ( const MoveCommand& ); + static string _name; + bool _firstEvent; + QPoint _lastPosition; }; diff --git a/hurricane/src/hviewer/hurricane/viewer/RulerCommand.h b/hurricane/src/hviewer/hurricane/viewer/RulerCommand.h index e2702a64..e1798d89 100644 --- a/hurricane/src/hviewer/hurricane/viewer/RulerCommand.h +++ b/hurricane/src/hviewer/hurricane/viewer/RulerCommand.h @@ -37,20 +37,19 @@ namespace Hurricane { class RulerCommand : public Command { public: - RulerCommand (); - virtual ~RulerCommand (); - virtual bool keyPressEvent ( CellWidget*, QKeyEvent* ); - virtual bool keyReleaseEvent ( CellWidget*, QKeyEvent* ); - virtual bool mouseMoveEvent ( CellWidget*, QMouseEvent* ); - virtual bool mousePressEvent ( CellWidget*, QMouseEvent* ); - virtual bool mouseReleaseEvent ( CellWidget*, QMouseEvent* ); - virtual void draw ( CellWidget* ); - protected: - bool _active; - std::tr1::shared_ptr _ruler; + RulerCommand (); + virtual ~RulerCommand (); + virtual const string& getName () const; + virtual void mouseMoveEvent ( QMouseEvent* ); + virtual void mousePressEvent ( QMouseEvent* ); + virtual void keyPressEvent ( QKeyEvent* ); + virtual void draw (); private: - RulerCommand ( const RulerCommand& ); - RulerCommand& operator= ( const RulerCommand& ); + RulerCommand ( const RulerCommand& ); + RulerCommand& operator= ( const RulerCommand& ); + protected: + static string _name; + std::tr1::shared_ptr _ruler; }; diff --git a/hurricane/src/hviewer/hurricane/viewer/SelectCommand.h b/hurricane/src/hviewer/hurricane/viewer/SelectCommand.h index 53968e5a..a10d46f8 100644 --- a/hurricane/src/hviewer/hurricane/viewer/SelectCommand.h +++ b/hurricane/src/hviewer/hurricane/viewer/SelectCommand.h @@ -52,18 +52,22 @@ namespace Hurricane { Q_OBJECT; public: - SelectCommand (); - virtual ~SelectCommand (); - virtual bool mousePressEvent ( CellWidget*, QMouseEvent* ); - virtual bool mouseReleaseEvent ( CellWidget*, QMouseEvent* ); - void bindToAction ( QAction* action ); + SelectCommand (); + virtual ~SelectCommand (); + virtual const string& getName () const; + virtual void keyPressEvent ( QKeyEvent* ); + virtual void mousePressEvent ( QMouseEvent* ); + virtual void mouseReleaseEvent ( QMouseEvent* ); + void bindToAction ( QAction* ); signals: - void selectionToggled ( Occurrence occurrence ); + void selectionToggled ( Occurrence ); private: - SelectionPopup* _selectionPopup; + SelectCommand ( const SelectCommand& ); + SelectCommand& operator= ( const SelectCommand& ); private: - SelectCommand ( const SelectCommand& ); - SelectCommand& operator= ( const SelectCommand& ); + static string _name; + SelectionPopup* _selectionPopup; + unsigned int _selectMode; }; diff --git a/hurricane/src/hviewer/hurricane/viewer/SelectionPopup.h b/hurricane/src/hviewer/hurricane/viewer/SelectionPopup.h index 1f1fe77d..e67b7ac3 100644 --- a/hurricane/src/hviewer/hurricane/viewer/SelectionPopup.h +++ b/hurricane/src/hviewer/hurricane/viewer/SelectionPopup.h @@ -32,6 +32,7 @@ #include "hurricane/Commons.h" #include "hurricane/Occurrence.h" +#include "hurricane/Occurrences.h" class QModelIndex; @@ -43,6 +44,10 @@ class QHeaderView; namespace Hurricane { +// ------------------------------------------------------------------- +// Class : "Hurricane::SelectionPopup". + + class SelectionPopupModel; @@ -50,24 +55,26 @@ namespace Hurricane { Q_OBJECT; public: - SelectionPopup ( QWidget* parent=NULL ); - void updateLayout (); - void popup (); + SelectionPopup ( QWidget* parent=NULL ); + void updateLayout (); + void popup (); + void clearFilter (); + void setFilter ( OccurrenceFilter ); signals: - void selectionToggled ( Occurrence occurrence ); + void selectionToggled ( Occurrence ); public slots: - void add ( Occurrence occurrence, bool showChange=false ); - void clear (); - void forceRowHeight (); + void loadOccurrences ( Occurrences, bool showChange=false ); + void clear (); + void forceRowHeight (); protected: - virtual void keyPressEvent ( QKeyEvent * event ); - virtual void mouseMoveEvent ( QMouseEvent* event ); - virtual void mouseReleaseEvent ( QMouseEvent* event ); + virtual void keyPressEvent ( QKeyEvent * ); + virtual void mouseMoveEvent ( QMouseEvent* ); + virtual void mouseReleaseEvent ( QMouseEvent* ); private: - SelectionPopupModel* _model; - QTableView* _view; - int _rowHeight; + SelectionPopupModel* _model; + QTableView* _view; + int _rowHeight; }; diff --git a/hurricane/src/hviewer/hurricane/viewer/SelectionPopupModel.h b/hurricane/src/hviewer/hurricane/viewer/SelectionPopupModel.h index f6b9af4d..53f47f11 100644 --- a/hurricane/src/hviewer/hurricane/viewer/SelectionPopupModel.h +++ b/hurricane/src/hviewer/hurricane/viewer/SelectionPopupModel.h @@ -2,7 +2,7 @@ // -*- C++ -*- // // 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 // // =================================================================== // @@ -35,6 +35,7 @@ #include "hurricane/Commons.h" #include "hurricane/Occurrence.h" +#include "hurricane/Occurrences.h" #include "hurricane/viewer/Graphics.h" @@ -48,19 +49,23 @@ namespace Hurricane { Q_OBJECT; public: - SelectionPopupModel ( QObject* parent=NULL ); - ~SelectionPopupModel (); - void add ( Occurrence occurrence, bool showChange=false ); - void clear (); - void updateLayout (); - int rowCount ( const QModelIndex& parent=QModelIndex() ) const; - int columnCount ( const QModelIndex& parent=QModelIndex() ) const; - QVariant data ( const QModelIndex& index, int role=Qt::DisplayRole ) const; - QVariant headerData ( int section, Qt::Orientation orientation, int role=Qt::DisplayRole ) const; - Occurrence getOccurrence ( int row ); + SelectionPopupModel ( QObject* parent=NULL ); + ~SelectionPopupModel (); + void clearFilter (); + void setFilter ( OccurrenceFilter ); + OccurrenceFilter getFilter (); + void loadOccurrences ( Occurrences, bool showChange=false ); + void clear (); + void updateLayout (); + int rowCount ( const QModelIndex& parent=QModelIndex() ) const; + int columnCount ( const QModelIndex& parent=QModelIndex() ) const; + QVariant data ( const QModelIndex& index, int role=Qt::DisplayRole ) const; + QVariant headerData ( int section, Qt::Orientation orientation, int role=Qt::DisplayRole ) const; + Occurrence getOccurrence ( int row ); private: - vector* _occurrences; + OccurrenceFilter _filter; + vector* _occurrences; }; diff --git a/hurricane/src/hviewer/hurricane/viewer/ZoomCommand.h b/hurricane/src/hviewer/hurricane/viewer/ZoomCommand.h index 3a976123..fd14dc36 100644 --- a/hurricane/src/hviewer/hurricane/viewer/ZoomCommand.h +++ b/hurricane/src/hviewer/hurricane/viewer/ZoomCommand.h @@ -36,15 +36,19 @@ namespace Hurricane { class ZoomCommand : public AreaCommand { public: - ZoomCommand (); - virtual ~ZoomCommand (); - virtual bool wheelEvent ( CellWidget*, QWheelEvent* ); - virtual bool keyPressEvent ( CellWidget*, QKeyEvent* ); - virtual bool mousePressEvent ( CellWidget*, QMouseEvent* ); - virtual bool mouseReleaseEvent ( CellWidget*, QMouseEvent* ); - private: - ZoomCommand ( const ZoomCommand& ); - ZoomCommand& operator= ( const ZoomCommand& ); + ZoomCommand (); + virtual ~ZoomCommand (); + virtual const string& getName () const; + virtual Type getType () const; + virtual void wheelEvent ( QWheelEvent* ); + virtual void keyPressEvent ( QKeyEvent* ); + virtual void mousePressEvent ( QMouseEvent* ); + virtual void mouseReleaseEvent ( QMouseEvent* ); + private: + ZoomCommand ( const ZoomCommand& ); + ZoomCommand& operator= ( const ZoomCommand& ); + private: + static string _name; };