diff --git a/hurricane/src/hviewer/AreaCommand.cpp b/hurricane/src/hviewer/AreaCommand.cpp index 45031058..60eab0e2 100644 --- a/hurricane/src/hviewer/AreaCommand.cpp +++ b/hurricane/src/hviewer/AreaCommand.cpp @@ -68,6 +68,7 @@ namespace Hurricane { : Command() , _startPoint() , _stopPoint() + , _drawingEnabled(false) { } @@ -78,7 +79,7 @@ namespace Hurricane { bool AreaCommand::mouseMoveEvent ( CellWidget* widget, QMouseEvent* event ) { - if ( !isActive() ) return false; + if ( !_drawingEnabled ) return false; setStopPoint ( event->pos() ); widget->update (); @@ -89,7 +90,7 @@ namespace Hurricane { void AreaCommand::draw ( CellWidget* widget ) { - if ( !_active ) return; + if ( !_drawingEnabled ) return; widget->drawScreenRect ( _startPoint, _stopPoint ); drawCorner ( widget, true ); diff --git a/hurricane/src/hviewer/CMakeLists.txt b/hurricane/src/hviewer/CMakeLists.txt index c7f9861f..c8869489 100644 --- a/hurricane/src/hviewer/CMakeLists.txt +++ b/hurricane/src/hviewer/CMakeLists.txt @@ -19,6 +19,8 @@ hurricane/viewer/CellViewer.h hurricane/viewer/RecordModel.h hurricane/viewer/HInspectorWidget.h + hurricane/viewer/HSelectionPopupModel.h + hurricane/viewer/HSelectionPopup.h hurricane/viewer/HSelectionModel.h hurricane/viewer/HSelection.h hurricane/viewer/HNetlistModel.h @@ -41,6 +43,8 @@ hurricane/viewer/CellWidgets.h hurricane/viewer/CellViewer.h hurricane/viewer/HInspectorWidget.h + hurricane/viewer/HSelectionPopupModel.h + hurricane/viewer/HSelectionPopup.h hurricane/viewer/HSelectionModel.h hurricane/viewer/HSelection.h hurricane/viewer/NetInformations.h @@ -68,6 +72,8 @@ CellViewer.cpp RecordModel.cpp HInspectorWidget.cpp + HSelectionPopupModel.cpp + HSelectionPopup.cpp HSelectionModel.cpp HSelection.cpp NetInformations.cpp diff --git a/hurricane/src/hviewer/CellViewer.cpp b/hurricane/src/hviewer/CellViewer.cpp index cd646657..2c7b0aad 100644 --- a/hurricane/src/hviewer/CellViewer.cpp +++ b/hurricane/src/hviewer/CellViewer.cpp @@ -450,10 +450,23 @@ namespace Hurricane { { if ( !_selectionBrowser ) { _selectionBrowser = new HSelection (); - _selectionBrowser->setSelection ( _cellWidget->getSelectorSet() ); - connect ( _selectionBrowser, SIGNAL(destroyed()), this, SLOT(selectionBrowserDestroyed()) ); - connect ( &_selectCommand , SIGNAL(selectionChanged(const set&,Cell*)) + _selectionBrowser->setSelection ( _cellWidget->getSelectorSet(), _cellWidget->getCell() ); + + connect ( _selectionBrowser , SIGNAL(destroyed()), this, SLOT(selectionBrowserDestroyed()) ); + connect ( _cellWidget , SIGNAL(selectionChanged(const set&,Cell*)) , _selectionBrowser, SLOT (setSelection (const set&,Cell*)) ); + connect ( &_selectCommand , SIGNAL(selectionToggled (Occurrence,bool)) + , _cellWidget , SLOT (toggleSelect (Occurrence,bool)) ); + connect ( _selectionBrowser, SIGNAL(occurrenceToggled(Occurrence,bool)) + , _cellWidget , SLOT (toggleSelect (Occurrence,bool)) ); + connect ( _cellWidget , SIGNAL(occurrenceToggled(Occurrence)) + , _selectionBrowser, SLOT (toggleSelection (Occurrence)) ); + connect ( _selectionBrowser, SIGNAL(cumulativeToggled (bool)) + , _cellWidget , SLOT (setCumulativeSelection(bool)) ); + connect ( _selectionBrowser, SIGNAL(selectionCleared()) + , _cellWidget , SLOT (unselectAll ()) ); + connect ( _selectionBrowser, SIGNAL(showSelected (bool)) + , _cellWidget , SLOT (setShowSelection(bool)) ); } _selectionBrowser->show (); } diff --git a/hurricane/src/hviewer/CellWidget.cpp b/hurricane/src/hviewer/CellWidget.cpp index 6460bff3..f880c29a 100644 --- a/hurricane/src/hviewer/CellWidget.cpp +++ b/hurricane/src/hviewer/CellWidget.cpp @@ -351,6 +351,7 @@ namespace Hurricane { , _cell(NULL) , _showBoundaries(true) , _showSelection(false) + , _cumulativeSelection(false) , _selectionHasChanged(false) , _commands() , _redrawRectCount(0) @@ -457,6 +458,13 @@ namespace Hurricane { } + void CellWidget::setCumulativeSelection ( bool state ) + { + cerr << "CellWidget::setCumulativeSelection() - " << state << endl; + _cumulativeSelection = state; + } + + void CellWidget::redraw ( QRect redrawArea ) { // cerr << "CellWidget::redraw() - " @@ -1068,6 +1076,17 @@ namespace Hurricane { } + void CellWidget::selectOccurrencesUnder ( Box selectArea ) + { + if ( !_cumulativeSelection ) unselectAll ( true ); + + forEach ( Occurrence, ioccurrence, _cell->getOccurrencesUnder(selectArea) ) + select ( *ioccurrence ); + + emit selectionChanged(_selectors,_cell); + } + + void CellWidget::unselect ( Occurrence occurrence ) { if ( !occurrence.isValid() ) @@ -1101,4 +1120,31 @@ namespace Hurricane { } + void CellWidget::toggleSelect ( Occurrence occurrence, bool fromPopup ) + { + if ( !occurrence.isValid() ) + throw Error ( "Can't select occurrence : invalid occurrence" ); + + if ( occurrence.getOwnerCell() != getCell() ) + throw Error ( "Can't select occurrence : incompatible occurrence" ); + + Property* property = occurrence.getProperty ( Selector::getPropertyName() ); + Selector* selector = NULL; + if ( !property ) { + selector = Selector::create ( occurrence ); + selector->attachTo ( this ); + } else { + selector = dynamic_cast(property); + if ( !selector ) + throw Error ( "Abnormal property named " + getString(Selector::getPropertyName()) ); + selector->detachFrom ( this ); + } + + _selectionHasChanged = true; + redraw (); + + if ( fromPopup ) emit occurrenceToggled ( occurrence ); + } + + } // End of Hurricane namespace. diff --git a/hurricane/src/hviewer/HInspectorWidget.cpp b/hurricane/src/hviewer/HInspectorWidget.cpp index 9de4a1e2..bc976845 100644 --- a/hurricane/src/hviewer/HInspectorWidget.cpp +++ b/hurricane/src/hviewer/HInspectorWidget.cpp @@ -180,10 +180,10 @@ namespace Hurricane { HInspectorWidget::HInspectorWidget ( QWidget* parent ) : QWidget(parent) - , _recordModel(NULL) + , _baseModel(NULL) , _sortModel(NULL) , _historyComboBox(NULL) - , _slotsView(NULL) + , _view(NULL) , _rowHeight(20) , _history() { @@ -192,17 +192,17 @@ namespace Hurricane { _rowHeight = QFontMetrics(Graphics::getFixedFont()).height() + 4; - _slotsView = new QTableView(this); - _slotsView->setShowGrid(false); - _slotsView->setAlternatingRowColors(true); - _slotsView->setSelectionBehavior(QAbstractItemView::SelectRows); - _slotsView->setSortingEnabled(true); + _view = new QTableView(this); + _view->setShowGrid(false); + _view->setAlternatingRowColors(true); + _view->setSelectionBehavior(QAbstractItemView::SelectRows); + _view->setSortingEnabled(true); - QHeaderView* horizontalHeader = _slotsView->horizontalHeader (); + QHeaderView* horizontalHeader = _view->horizontalHeader (); horizontalHeader->setStretchLastSection ( true ); horizontalHeader->setMinimumSectionSize ( 200 ); - QHeaderView* verticalHeader = _slotsView->verticalHeader (); + QHeaderView* verticalHeader = _view->verticalHeader (); verticalHeader->setVisible ( false ); _historyComboBox = new QComboBox ( this ); @@ -214,7 +214,7 @@ namespace Hurricane { QGridLayout* inspectorLayout = new QGridLayout(); inspectorLayout->addWidget(_historyComboBox , 0, 0, 1, 2); - inspectorLayout->addWidget(_slotsView , 1, 0, 1, 2); + inspectorLayout->addWidget(_view , 1, 0, 1, 2); inspectorLayout->addWidget(filterPatternLabel , 2, 0); inspectorLayout->addWidget(_filterPatternLineEdit, 2, 1); @@ -237,24 +237,32 @@ namespace Hurricane { } + void HInspectorWidget::forceRowHeight () + { + for ( int rows=_sortModel->rowCount()-1; rows >= 0 ; rows-- ) + _view->setRowHeight ( rows, _rowHeight ); + } + + void HInspectorWidget::setRootRecord ( Record* record ) { _history.setRootRecord ( record ); - if ( !_recordModel ) { - _recordModel = new RecordModel ( this ); + if ( !_baseModel ) { + _baseModel = new RecordModel ( this ); _sortModel = new QSortFilterProxyModel ( this ); - _sortModel->setSourceModel ( _recordModel ); + _sortModel->setSourceModel ( _baseModel ); _sortModel->setDynamicSortFilter ( true ); _sortModel->setFilterKeyColumn ( 1 ); - _slotsView->setModel ( _sortModel ); - _slotsView->horizontalHeader()->setStretchLastSection ( true ); - _slotsView->resizeColumnToContents ( 0 ); + _view->setModel ( _sortModel ); + _view->horizontalHeader()->setStretchLastSection ( true ); + _view->resizeColumnToContents ( 0 ); // Only after creating the RecordModel can we connect the ComboBox. connect ( _historyComboBox, SIGNAL(currentIndexChanged(int)) , this , SLOT(historyChanged(int)) ); + connect ( _baseModel, SIGNAL(layoutChanged()), this, SLOT(forceRowHeight()) ); } setSlot (); @@ -265,13 +273,13 @@ namespace Hurricane { { bool change = true; - change = _recordModel->setSlot ( _history.getSlot(), _history.getDepth() ); - if ( change ) { - int rows = _sortModel->rowCount (); - for ( rows-- ; rows >= 0 ; rows-- ) - _slotsView->setRowHeight ( rows, _rowHeight ); - _slotsView->selectRow ( 0 ); - } + change = _baseModel->setSlot ( _history.getSlot(), _history.getDepth() ); +// if ( change ) { +// int rows = _sortModel->rowCount (); +// for ( rows-- ; rows >= 0 ; rows-- ) +// _view->setRowHeight ( rows, _rowHeight ); +// _view->selectRow ( 0 ); +// } return change; } @@ -302,9 +310,9 @@ namespace Hurricane { void HInspectorWidget::keyPressEvent ( QKeyEvent *event ) { if ( event->key() == Qt::Key_Right ) { - QModelIndex index = _slotsView->currentIndex(); + QModelIndex index = _view->currentIndex(); if ( index.isValid() ) { - Slot* slot = _recordModel->getRecord()->getSlot(_sortModel->mapToSource(index).row()); + Slot* slot = _baseModel->getRecord()->getSlot(_sortModel->mapToSource(index).row()); if ( slot ) pushSlot ( slot ); @@ -312,7 +320,7 @@ namespace Hurricane { } else if ( event->key() == Qt::Key_Left ) { back (); } else if ( event->key() == Qt::Key_O ) { - forkInspector ( _slotsView->currentIndex() ); + forkInspector ( _view->currentIndex() ); } else { event->ignore(); } @@ -322,6 +330,7 @@ namespace Hurricane { void HInspectorWidget::textFilterChanged () { _sortModel->setFilterRegExp ( _filterPatternLineEdit->text() ); + forceRowHeight (); } @@ -337,7 +346,7 @@ namespace Hurricane { void HInspectorWidget::forkInspector ( const QModelIndex& index ) { if ( index.isValid() ) { - Slot* slot = _recordModel->getRecord()->getSlot(_sortModel->mapToSource(index).row()); + Slot* slot = _baseModel->getRecord()->getSlot(_sortModel->mapToSource(index).row()); Record* record = slot->getDataRecord(); if ( record ) { diff --git a/hurricane/src/hviewer/HNetlist.cpp b/hurricane/src/hviewer/HNetlist.cpp index cef27205..029b7c31 100644 --- a/hurricane/src/hviewer/HNetlist.cpp +++ b/hurricane/src/hviewer/HNetlist.cpp @@ -72,9 +72,9 @@ namespace Hurricane { HNetlist::HNetlist ( QWidget* parent ) : QWidget(parent) - , _netlistModel(NULL) + , _baseModel(NULL) , _sortModel(NULL) - , _netlistView(NULL) + , _view(NULL) , _rowHeight(20) , _cellWidget(NULL) { @@ -83,26 +83,26 @@ namespace Hurricane { _rowHeight = QFontMetrics(Graphics::getFixedFont()).height() + 4; - _netlistModel = new HNetlistModel ( this ); + _baseModel = new HNetlistModel ( this ); _sortModel = new QSortFilterProxyModel ( this ); - _sortModel->setSourceModel ( _netlistModel ); + _sortModel->setSourceModel ( _baseModel ); _sortModel->setDynamicSortFilter ( true ); _sortModel->setFilterKeyColumn ( 0 ); - _netlistView = new QTableView(this); - _netlistView->setShowGrid(false); - _netlistView->setAlternatingRowColors(true); - _netlistView->setSelectionBehavior(QAbstractItemView::SelectRows); - _netlistView->setSortingEnabled(true); - _netlistView->setModel ( _sortModel ); - _netlistView->horizontalHeader()->setStretchLastSection ( true ); + _view = new QTableView(this); + _view->setShowGrid(false); + _view->setAlternatingRowColors(true); + _view->setSelectionBehavior(QAbstractItemView::SelectRows); + _view->setSortingEnabled(true); + _view->setModel ( _sortModel ); + _view->horizontalHeader()->setStretchLastSection ( true ); - QHeaderView* horizontalHeader = _netlistView->horizontalHeader (); + QHeaderView* horizontalHeader = _view->horizontalHeader (); horizontalHeader->setStretchLastSection ( true ); horizontalHeader->setMinimumSectionSize ( 200 ); - QHeaderView* verticalHeader = _netlistView->verticalHeader (); + QHeaderView* verticalHeader = _view->verticalHeader (); verticalHeader->setVisible ( false ); _filterPatternLineEdit = new QLineEdit(this); @@ -110,7 +110,7 @@ namespace Hurricane { filterPatternLabel->setBuddy(_filterPatternLineEdit); QGridLayout* inspectorLayout = new QGridLayout(); - inspectorLayout->addWidget(_netlistView , 1, 0, 1, 2); + inspectorLayout->addWidget(_view , 1, 0, 1, 2); inspectorLayout->addWidget(filterPatternLabel , 2, 0); inspectorLayout->addWidget(_filterPatternLineEdit, 2, 1); @@ -119,9 +119,10 @@ namespace Hurricane { connect ( _filterPatternLineEdit, SIGNAL(textChanged(const QString &)) , this , SLOT(textFilterChanged()) ); - connect ( _netlistView , SIGNAL(activated(const QModelIndex&)) + connect ( _view , SIGNAL(activated(const QModelIndex&)) , this , SLOT(selectNet(const QModelIndex&)) ); + connect ( _baseModel , SIGNAL(layoutChanged()), this, SLOT(forceRowHeight()) ); setWindowTitle(tr("Netlist")); resize(500, 300); @@ -129,9 +130,16 @@ namespace Hurricane { } + void HNetlist::forceRowHeight () + { + for ( int rows=_sortModel->rowCount()-1; rows >= 0 ; rows-- ) + _view->setRowHeight ( rows, _rowHeight ); + } + + void HNetlist::selectNet ( const QModelIndex& index ) { - const Net* net = _netlistModel->getNet ( _sortModel->mapToSource(index).row() ); + const Net* net = _baseModel->getNet ( _sortModel->mapToSource(index).row() ); if ( _cellWidget && net ) { _cellWidget->unselectAll (); @@ -142,7 +150,7 @@ namespace Hurricane { void HNetlist::keyPressEvent ( QKeyEvent* event ) { - if ( event->key() == Qt::Key_I ) { runInspector(_netlistView->currentIndex()); } + if ( event->key() == Qt::Key_I ) { runInspector(_view->currentIndex()); } else { event->ignore(); } @@ -152,13 +160,14 @@ namespace Hurricane { void HNetlist::textFilterChanged () { _sortModel->setFilterRegExp ( _filterPatternLineEdit->text() ); + forceRowHeight (); } void HNetlist::runInspector ( const QModelIndex& index ) { if ( index.isValid() ) { - const Net* net = _netlistModel->getNet ( _sortModel->mapToSource(index).row() ); + const Net* net = _baseModel->getNet ( _sortModel->mapToSource(index).row() ); HInspectorWidget* inspector = new HInspectorWidget (); diff --git a/hurricane/src/hviewer/HSelection.cpp b/hurricane/src/hviewer/HSelection.cpp index a08f73fc..fb693653 100644 --- a/hurricane/src/hviewer/HSelection.cpp +++ b/hurricane/src/hviewer/HSelection.cpp @@ -50,11 +50,15 @@ #include +#include #include +#include +#include #include #include #include #include +#include #include #include "hurricane/Commons.h" @@ -72,9 +76,10 @@ namespace Hurricane { HSelection::HSelection ( QWidget* parent ) : QWidget(parent) - , _selectionModel(NULL) + , _baseModel(NULL) , _sortModel(NULL) - , _selectionView(NULL) + , _view(NULL) + , _cumulative(NULL) , _rowHeight(20) { setAttribute ( Qt::WA_DeleteOnClose ); @@ -82,51 +87,90 @@ namespace Hurricane { _rowHeight = QFontMetrics(Graphics::getFixedFont()).height() + 4; - _selectionModel = new HSelectionModel ( this ); - - _sortModel = new QSortFilterProxyModel ( this ); - _sortModel->setSourceModel ( _selectionModel ); - _sortModel->setDynamicSortFilter ( true ); - _sortModel->setFilterKeyColumn ( 0 ); - - _selectionView = new QTableView(this); - _selectionView->setShowGrid(false); - _selectionView->setAlternatingRowColors(true); - _selectionView->setSelectionBehavior(QAbstractItemView::SelectRows); - _selectionView->setSortingEnabled(true); - _selectionView->setModel ( _sortModel ); - _selectionView->horizontalHeader()->setStretchLastSection ( true ); - - QHeaderView* horizontalHeader = _selectionView->horizontalHeader (); - horizontalHeader->setStretchLastSection ( true ); - horizontalHeader->setMinimumSectionSize ( 200 ); - - QHeaderView* verticalHeader = _selectionView->verticalHeader (); - verticalHeader->setVisible ( false ); - _filterPatternLineEdit = new QLineEdit(this); QLabel* filterPatternLabel = new QLabel(tr("&Filter pattern:"), this); filterPatternLabel->setBuddy(_filterPatternLineEdit); - QGridLayout* inspectorLayout = new QGridLayout(); - inspectorLayout->addWidget(_selectionView , 1, 0, 1, 2); - inspectorLayout->addWidget(filterPatternLabel , 2, 0); - inspectorLayout->addWidget(_filterPatternLineEdit, 2, 1); + QHBoxLayout* hLayout1 = new QHBoxLayout (); + hLayout1->addWidget ( filterPatternLabel ); + hLayout1->addWidget ( _filterPatternLineEdit ); - setLayout ( inspectorLayout ); + QFrame* separator = new QFrame (); + separator->setFrameShape ( QFrame::HLine ); + separator->setFrameShadow ( QFrame::Sunken ); + + _cumulative = new QCheckBox (); + _cumulative->setText ( tr("Cumulative Selection") ); + _cumulative->setChecked ( false ); + + QPushButton* clear = new QPushButton (); + clear->setText ( tr("Clear") ); + + QHBoxLayout* hLayout2 = new QHBoxLayout (); + hLayout2->addWidget ( _cumulative ); + hLayout2->addStretch (); + hLayout2->addWidget ( clear ); + + _baseModel = new HSelectionModel ( this ); + + _sortModel = new QSortFilterProxyModel ( this ); + _sortModel->setSourceModel ( _baseModel ); + _sortModel->setDynamicSortFilter ( true ); + _sortModel->setFilterKeyColumn ( 0 ); + + _view = new QTableView(this); + _view->setShowGrid(false); + _view->setAlternatingRowColors(true); + _view->setSelectionBehavior(QAbstractItemView::SelectRows); + _view->setSortingEnabled(true); + _view->setModel ( _sortModel ); + _view->horizontalHeader()->setStretchLastSection ( true ); + + QHeaderView* horizontalHeader = _view->horizontalHeader (); + horizontalHeader->setStretchLastSection ( true ); + horizontalHeader->setMinimumSectionSize ( 200 ); + + QHeaderView* verticalHeader = _view->verticalHeader (); + verticalHeader->setVisible ( false ); + + QVBoxLayout* vLayout = new QVBoxLayout (); + vLayout->addWidget ( _view ); + vLayout->addLayout ( hLayout1 ); + vLayout->addWidget ( separator ); + vLayout->addLayout ( hLayout2 ); + + setLayout ( vLayout ); connect ( _filterPatternLineEdit, SIGNAL(textChanged(const QString &)) , this , SLOT(textFilterChanged()) ); + connect ( _baseModel , SIGNAL(layoutChanged()), this, SLOT(forceRowHeight()) ); + connect ( _cumulative, SIGNAL(toggled(bool)) , this, SIGNAL(cumulativeToggled(bool)) ); + connect ( clear , SIGNAL(clicked()) , this, SIGNAL(selectionCleared()) ); + connect ( clear , SIGNAL(clicked()) , _baseModel, SLOT(clear()) ); - setWindowTitle(tr("Selection")); - resize(500, 300); + setWindowTitle ( tr("Selection") ); + resize ( 500, 300 ); + } + + + void HSelection::hideEvent ( QHideEvent* event ) + { + emit showSelected(false); + } + + + void HSelection::forceRowHeight () + { + for ( int rows=_sortModel->rowCount()-1; rows >= 0 ; rows-- ) + _view->setRowHeight ( rows, _rowHeight ); } void HSelection::keyPressEvent ( QKeyEvent* event ) { - if ( event->key() == Qt::Key_I ) { runInspector(_selectionView->currentIndex()); } + if ( event->key() == Qt::Key_I ) { runInspector ( _view->currentIndex() ); } + else if ( event->key() == Qt::Key_T ) { toggleSelection ( _view->currentIndex() ); } else event->ignore(); } @@ -134,38 +178,48 @@ namespace Hurricane { void HSelection::textFilterChanged () { _sortModel->setFilterRegExp ( _filterPatternLineEdit->text() ); + forceRowHeight (); } - void HSelection::addToSelection ( Selector* selector ) + bool HSelection::isCumulative () const { - _selectionModel->addToSelection ( selector ); - int rows = _sortModel->rowCount () - 1; - _selectionView->setRowHeight ( rows, _rowHeight ); + return _cumulative->isChecked(); + } + + + void HSelection::toggleSelection ( const QModelIndex& index ) + { + Occurrence occurrence = _baseModel->toggleSelection ( index ); + if ( occurrence.isValid() ) + emit occurrenceToggled ( occurrence, false ); + } + + + void HSelection::toggleSelection ( Occurrence occurrence ) + { + _baseModel->toggleSelection ( occurrence ); } void HSelection::setSelection ( const set& selection, Cell* cell ) { - _selectionModel->setSelection ( selection ); + _baseModel->setSelection ( selection ); string windowTitle = "Selection"; if ( cell ) windowTitle += getString(cell); else windowTitle += ""; setWindowTitle ( tr(windowTitle.c_str()) ); - int rows = _sortModel->rowCount (); - for ( rows-- ; rows >= 0 ; rows-- ) - _selectionView->setRowHeight ( rows, _rowHeight ); - _selectionView->selectRow ( 0 ); - _selectionView->resizeColumnToContents ( 0 ); + _view->selectRow ( 0 ); + _view->resizeColumnToContents ( 0 ); } void HSelection::runInspector ( const QModelIndex& index ) { if ( index.isValid() ) { - Occurrence occurrence = _selectionModel->getOccurrence ( _sortModel->mapToSource(index).row() ); + Occurrence occurrence = _baseModel->getOccurrence ( _sortModel->mapToSource(index).row() ); HInspectorWidget* inspector = new HInspectorWidget (); diff --git a/hurricane/src/hviewer/HSelectionModel.cpp b/hurricane/src/hviewer/HSelectionModel.cpp index a524d356..7bcefe8e 100644 --- a/hurricane/src/hviewer/HSelectionModel.cpp +++ b/hurricane/src/hviewer/HSelectionModel.cpp @@ -50,6 +50,8 @@ // x-----------------------------------------------------------------x +#include + #include #include "hurricane/Path.h" @@ -58,6 +60,7 @@ #include "hurricane/viewer/Graphics.h" #include "hurricane/viewer/Selector.h" #include "hurricane/viewer/HSelectionModel.h" +#include "hurricane/viewer/HSelection.h" namespace Hurricane { @@ -73,22 +76,77 @@ namespace Hurricane { { } - void HSelectionModel::setSelection ( const set& selection ) + bool HSelectionModel::isCumulative () const + { + HSelection* widget = qobject_cast(QObject::parent()); + if ( widget ) + return widget->isCumulative(); + + return true; + } + + + void HSelectionModel::clear () { _selection.clear (); + emit layoutChanged (); + } - set::const_iterator iselector = selection.begin(); - for ( ; iselector != selection.end() ; iselector++ ) - _selection.push_back ( (*iselector)->getOccurrence() ); + + void HSelectionModel::setSelection ( const set& selection ) + { + if ( !isCumulative() ) _selection.clear (); + + set::const_iterator iselector = selection.begin(); + vector::iterator iitem; + for ( ; iselector != selection.end() ; iselector++ ) { + if ( isCumulative() ) { + iitem = find( _selection.begin(), _selection.end(), (*iselector)->getOccurrence() ); + if ( iitem != _selection.end() ) { + (*iitem)._flags |= OccurrenceItem::Selected; + continue; + } + } + _selection.push_back ( OccurrenceItem((*iselector)->getOccurrence()) ); + } emit layoutChanged (); } - void HSelectionModel::addToSelection ( Selector* selector ) + Occurrence HSelectionModel::toggleSelection ( const QModelIndex& index ) { - _selection.push_back ( selector->getOccurrence() ); + if ( index.isValid() && ( index.row() < (int)_selection.size() ) ) { + _selection[index.row()].toggle(); + emit layoutChanged (); + return _selection[index.row()]._occurrence; + } + + return Occurrence (); + } + + + void HSelectionModel::toggleSelection ( Occurrence occurrence ) + { + bool found = false; + size_t i = 0; + for ( ; i<_selection.size() ; i++ ) { + if ( !found && (_selection[i]._occurrence == occurrence) ) { + found = true; + if ( isCumulative() ) break; + } + if ( found && ( i < _selection.size()-1 ) ) + _selection[i] = _selection[i+1]; + } + + if ( !found ) + _selection.push_back ( OccurrenceItem(occurrence) ); + else { + if ( isCumulative() ) _selection[i].toggle (); + else _selection.pop_back (); + } + emit layoutChanged (); } @@ -107,20 +165,24 @@ namespace Hurricane { } } + int row = index.row (); + if ( row >= (int)_selection.size() ) return QVariant (); + if ( role == Qt::FontRole ) { switch (index.column()) { case 0: return occurrenceFont; - default: return entityFont; + case 1: + if ( _selection[row]._flags & OccurrenceItem::Selected ) + return entityFont; + default: + return occurrenceFont; } } if ( role == Qt::DisplayRole ) { - int row = index.row (); - if ( row < (int)_selection.size() ) { - switch ( index.column() ) { - case 0: return getString(_selection[row].getPath()).c_str(); - case 1: return getString(_selection[row].getEntity()).c_str(); - } + switch ( index.column() ) { + case 0: return getString(_selection[row]._occurrence.getPath()).c_str(); + case 1: return getString(_selection[row]._occurrence.getEntity()).c_str(); } } return QVariant(); @@ -159,7 +221,7 @@ namespace Hurricane { { if ( row >= (int)_selection.size() ) return Occurrence(); - return _selection[row]; + return _selection[row]._occurrence; } diff --git a/hurricane/src/hviewer/HSelectionPopup.cpp b/hurricane/src/hviewer/HSelectionPopup.cpp new file mode 100644 index 00000000..2679a8bb --- /dev/null +++ b/hurricane/src/hviewer/HSelectionPopup.cpp @@ -0,0 +1,186 @@ + +// -*- C++ -*- +// +// This file is part of the Coriolis Project. +// Copyright (C) Laboratoire LIP6 - Departement ASIM +// Universite Pierre et Marie Curie +// +// Main contributors : +// Christophe Alexandre +// Sophie Belloeil +// Hugo Clément +// Jean-Paul Chaput +// Damien Dupuis +// Christian Masson +// Marek Sroka +// +// The Coriolis Project is free software; you can redistribute it +// and/or modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// The Coriolis Project is distributed in the hope that it will be +// useful, but WITHOUT ANY WARRANTY; without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with the Coriolis Project; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA +// +// License-Tag +// Authors-Tag +// =================================================================== +// +// $Id$ +// +// x-----------------------------------------------------------------x +// | | +// | H U R R I C A N E | +// | | +// | Author : Jean-Paul CHAPUT | +// | E-mail : Jean-Paul.Chaput@asim.lip6.fr | +// | =============================================================== | +// | C++ Module : "./HSelectionPopup.cpp" | +// | *************************************************************** | +// | U p d a t e s | +// | | +// x-----------------------------------------------------------------x + + +#include +#include +#include +#include +#include +#include + +#include "hurricane/Commons.h" + +#include "hurricane/viewer/Graphics.h" +#include "hurricane/viewer/HSelectionPopupModel.h" +#include "hurricane/viewer/HSelectionPopup.h" + + +namespace Hurricane { + + + + HSelectionPopup::HSelectionPopup ( QWidget* parent ) + : QWidget(parent) + , _model(NULL) + , _view(NULL) + , _rowHeight(20) + { + setAttribute ( Qt::WA_DeleteOnClose ); + setAttribute ( Qt::WA_QuitOnClose, false ); + //setWindowFlags ( Qt::Popup ); + setWindowFlags ( Qt::FramelessWindowHint ); + setWindowOpacity ( 0.7 ); + + _rowHeight = QFontMetrics(Graphics::getFixedFont()).height() + 4; + + _model = new HSelectionPopupModel ( this ); + + _view = new QTableView ( this ); + _view->setShowGrid ( false ); + _view->setAlternatingRowColors ( true ); + _view->setSelectionBehavior ( QAbstractItemView::SelectRows ); + _view->setModel ( _model ); + _view->horizontalHeader()->setStretchLastSection ( true ); + _view->setWordWrap ( false ); + //_view->setTextElideMode ( Qt::ElideRight ); + //_view->setFixedSize ( QSize(300,100) ); + //_view->setIconSize ( QSize(600,40) ); + //_view->setStyleSheet ( "QTableView { background-color: #555555; }" ); + + QHeaderView* horizontalHeader = _view->horizontalHeader (); + horizontalHeader->setStretchLastSection ( true ); + horizontalHeader->setMinimumSectionSize ( 200 ); + horizontalHeader->setVisible ( false ); + + QHeaderView* verticalHeader = _view->verticalHeader (); + verticalHeader->setVisible ( false ); + + connect ( _model, SIGNAL(layoutChanged()), this, SLOT(forceRowHeight()) ); + + resize ( 600, 10 ); + } + + + void HSelectionPopup::popup () + { + show (); + grabMouse (); + } + + + void HSelectionPopup::forceRowHeight () + { + for ( int rows=_model->rowCount()-1; rows >= 0 ; rows-- ) + _view->setRowHeight ( rows, _rowHeight ); + } + + + void HSelectionPopup::keyPressEvent ( QKeyEvent* event ) + { + event->ignore(); + } + + + + void HSelectionPopup::mouseMoveEvent ( QMouseEvent* event ) + { + QModelIndex index = _view->indexAt ( event->pos() ); + if ( index.isValid() ) + _view->selectionModel()->select ( index, QItemSelectionModel::ClearAndSelect ); + else + _view->selectionModel()->clearSelection (); + } + + + + void HSelectionPopup::mouseReleaseEvent ( QMouseEvent* event ) + { + releaseMouse (); + hide (); + + QModelIndex index = _view->indexAt ( event->pos() ); + if ( index.isValid() ) { + Occurrence occurrence = _model->getOccurrence(index.row()); + if ( occurrence.getEntity() ) + emit occurrenceSelected ( occurrence, true ); + } + + clear (); + } + + + void HSelectionPopup::add ( Occurrence occurrence, bool showChange ) + { + _model->add ( occurrence, showChange ); + } + + + void HSelectionPopup::clear () + { + _model->clear (); + } + + + void HSelectionPopup::updateLayout () + { + _model->updateLayout (); + + // This seems a very bad way to set the size of the popup window + // and underlying QTableView (top-down instead of bottom-up). + int rows = _model->rowCount(); + QSize windowSize = QSize ( 600, _rowHeight*rows + 4 ); + + resize ( windowSize ); + _view->resize ( windowSize ); + } + + +} // End of Hurricane namespace. diff --git a/hurricane/src/hviewer/HSelectionPopupModel.cpp b/hurricane/src/hviewer/HSelectionPopupModel.cpp new file mode 100644 index 00000000..6976fc77 --- /dev/null +++ b/hurricane/src/hviewer/HSelectionPopupModel.cpp @@ -0,0 +1,183 @@ + +// -*- C++ -*- +// +// This file is part of the Coriolis Project. +// Copyright (C) Laboratoire LIP6 - Departement ASIM +// Universite Pierre et Marie Curie +// +// Main contributors : +// Christophe Alexandre +// Sophie Belloeil +// Hugo Clément +// Jean-Paul Chaput +// Damien Dupuis +// Christian Masson +// Marek Sroka +// +// The Coriolis Project is free software; you can redistribute it +// and/or modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// The Coriolis Project is distributed in the hope that it will be +// useful, but WITHOUT ANY WARRANTY; without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with the Coriolis Project; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA +// +// License-Tag +// Authors-Tag +// =================================================================== +// +// $Id$ +// +// x-----------------------------------------------------------------x +// | | +// | H U R R I C A N E | +// | V L S I B a c k e n d D a t a - B a s e | +// | | +// | Author : Jean-Paul CHAPUT | +// | E-mail : Jean-Paul.Chaput@asim.lip6.fr | +// | =============================================================== | +// | C++ Module : "./HSelectionPopupModel.cpp" | +// | *************************************************************** | +// | U p d a t e s | +// | | +// x-----------------------------------------------------------------x + + +#include + +#include "hurricane/Path.h" +#include "hurricane/Entity.h" +#include "hurricane/Occurrence.h" +#include "hurricane/viewer/Graphics.h" +#include "hurricane/viewer/Selector.h" +#include "hurricane/viewer/HSelectionPopupModel.h" + + +namespace Hurricane { + + + HSelectionPopupModel::HSelectionPopupModel ( QObject* parent ) + : QAbstractTableModel(parent) + , _occurrences(NULL) + { } + + + HSelectionPopupModel::~HSelectionPopupModel () + { + clear (); + } + + + void HSelectionPopupModel::add ( Occurrence occurrence, bool showChange ) + { + if ( !_occurrences ) _occurrences = new vector (); + + _occurrences->push_back ( occurrence ); + if ( showChange ) emit layoutChanged (); + } + + + void HSelectionPopupModel::clear () + { + if ( _occurrences ) { + delete _occurrences; + _occurrences = NULL; + } + emit layoutChanged (); + } + + + void HSelectionPopupModel::updateLayout () + { + emit layoutChanged (); + } + + + QVariant HSelectionPopupModel::data ( const QModelIndex& index, int role ) const + { + static QFont occurrenceFont = Graphics::getFixedFont ( QFont::Normal ); + static QFont entityFont = Graphics::getFixedFont ( QFont::Bold, false ); + + if ( !index.isValid() ) return QVariant (); + + if ( role == Qt::SizeHintRole ) { + switch (index.column()) { + default: return -1; + } + } + + if ( role == Qt::FontRole ) { + switch (index.column()) { + default: return entityFont; + } + } + + if ( role == Qt::DisplayRole ) { + int row = index.row (); + string name; + if ( _occurrences ) { + if ( row < (int)_occurrences->size() ) { + if ( index.column() == 0 ) { + name = getString ( (*_occurrences)[row].getPath() ) + + getString ( (*_occurrences)[row].getEntity() ); + return name.c_str(); + } + } + } else { + if ( row < 1 ) { + if ( index.column() == 0 ) { + return QVariant ( tr("Nothing Selectable") ); + } + } + } + } + + return QVariant(); + } + + + QVariant HSelectionPopupModel::headerData ( int section + , Qt::Orientation orientation + , int role ) const + { + if ( ( orientation == Qt::Vertical ) || (role != Qt::DisplayRole) ) + return QVariant(); + + if ( section == 0 ) { + return "Path+Entity"; + } + + return QVariant(); + } + + + int HSelectionPopupModel::rowCount ( const QModelIndex& parent ) const + { + if ( !_occurrences ) return 1; + return _occurrences->size(); + } + + + int HSelectionPopupModel::columnCount ( const QModelIndex& parent ) const + { + return 1; + } + + + Occurrence HSelectionPopupModel::getOccurrence ( int row ) + { + if ( !_occurrences || (row >= (int)_occurrences->size()) ) + return Occurrence(); + + return (*_occurrences)[row]; + } + + +} // End of Hurricane namespace. diff --git a/hurricane/src/hviewer/SelectCommand.cpp b/hurricane/src/hviewer/SelectCommand.cpp index 234b88ef..5e66bfdb 100644 --- a/hurricane/src/hviewer/SelectCommand.cpp +++ b/hurricane/src/hviewer/SelectCommand.cpp @@ -58,6 +58,7 @@ # include "hurricane/viewer/CellWidget.h" # include "hurricane/viewer/SelectCommand.h" +# include "hurricane/viewer/HSelectionPopup.h" namespace Hurricane { @@ -70,11 +71,19 @@ namespace Hurricane { SelectCommand::SelectCommand () : AreaCommand() , _selectAction(NULL) - { } + , _selectionPopup(NULL) + { + _selectionPopup = new HSelectionPopup (); + + connect ( _selectionPopup, SIGNAL(occurrenceSelected(Occurrence,bool)) + , this , SIGNAL(selectionToggled (Occurrence,bool)) ); + } SelectCommand::~SelectCommand () - { } + { + delete _selectionPopup; + } void SelectCommand::bindToAction ( QAction* action ) @@ -87,9 +96,21 @@ namespace Hurricane { { if ( isActive() ) return true; - if ( (event->button() == Qt::RightButton) && !event->modifiers() ) { - setActive ( true ); - setStartPoint ( event->pos() ); + if ( event->button() == Qt::RightButton ) { + if ( !event->modifiers() ) { + 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->getCell()->getOccurrencesUnder(widget->screenToDbuBox(selectArea)) ) { + _selectionPopup->add ( *ioccurrence ); + } + _selectionPopup->updateLayout (); + _selectionPopup->move ( event->globalPos() ); + _selectionPopup->popup (); + } } return isActive(); @@ -101,6 +122,7 @@ namespace Hurricane { if ( !isActive() ) return false; setActive ( false ); + setDrawingEnabled ( false ); QRect selectArea; if ( _startPoint == _stopPoint ) @@ -108,11 +130,9 @@ namespace Hurricane { else selectArea = QRect ( _startPoint, _stopPoint ); - widget->unselectAll (); - forEach ( Occurrence, ioccurrence - , widget->getCell()->getOccurrencesUnder(widget->screenToDbuBox(selectArea)) ) { - widget->select ( *ioccurrence ); - } + //widget->unselectAll (); + widget->selectOccurrencesUnder ( widget->screenToDbuBox(selectArea) ); + if ( _selectAction ) { if ( !_selectAction->isChecked() ) _selectAction->setChecked ( true ); @@ -122,11 +142,10 @@ namespace Hurricane { widget->setShowSelection ( true ); widget->redraw (); } - - emit selectionChanged(widget->getSelectorSet(),widget->getCell()); - + return false; } + } // End of Hurricane namespace. diff --git a/hurricane/src/hviewer/ZoomCommand.cpp b/hurricane/src/hviewer/ZoomCommand.cpp index f20e5bb8..dd589be3 100644 --- a/hurricane/src/hviewer/ZoomCommand.cpp +++ b/hurricane/src/hviewer/ZoomCommand.cpp @@ -88,8 +88,9 @@ namespace Hurricane { if ( isActive() ) return true; if ( (event->button() == Qt::LeftButton) && (event->modifiers() & Qt::ControlModifier) ) { - setActive ( true ); - setStartPoint ( event->pos() ); + setActive ( true ); + setStartPoint ( event->pos() ); + setDrawingEnabled ( true ); } return isActive(); @@ -100,7 +101,8 @@ namespace Hurricane { { if ( !isActive() ) return false; - setActive ( false ); + setActive ( false ); + setDrawingEnabled ( false ); widget->reframe ( widget->screenToDbuBox(QRect(_startPoint,_stopPoint)) ); diff --git a/hurricane/src/hviewer/hurricane/viewer/AreaCommand.h b/hurricane/src/hviewer/hurricane/viewer/AreaCommand.h index 6e1f6792..c9b3804b 100644 --- a/hurricane/src/hviewer/hurricane/viewer/AreaCommand.h +++ b/hurricane/src/hviewer/hurricane/viewer/AreaCommand.h @@ -67,13 +67,16 @@ namespace Hurricane { virtual ~AreaCommand (); inline void setStartPoint ( const QPoint& start ); inline void setStopPoint ( const QPoint& stop ); + inline void setDrawingEnabled ( bool state ); virtual void draw ( CellWidget* widget ); virtual void drawCorner ( CellWidget* widget, bool bottomLeft ); virtual bool mouseMoveEvent ( CellWidget* widget, QMouseEvent* event ); + inline bool isDrawingEnabled () const; protected: QPoint _startPoint; QPoint _stopPoint; QPoint _cornerPoints[3]; + bool _drawingEnabled; private: AreaCommand ( const AreaCommand& ); AreaCommand& operator= ( const AreaCommand& ); @@ -88,6 +91,14 @@ namespace Hurricane { { _stopPoint = stop; } + inline void AreaCommand::setDrawingEnabled ( bool state ) + { _drawingEnabled = state; } + + + inline bool AreaCommand::isDrawingEnabled () const + { return _drawingEnabled; } + + } diff --git a/hurricane/src/hviewer/hurricane/viewer/CellWidget.h b/hurricane/src/hviewer/hurricane/viewer/CellWidget.h index 4688311a..e13a7784 100644 --- a/hurricane/src/hviewer/hurricane/viewer/CellWidget.h +++ b/hurricane/src/hviewer/hurricane/viewer/CellWidget.h @@ -111,90 +111,95 @@ namespace Hurricane { public: // Constructor & Destructor. - CellWidget ( QWidget* parent=NULL ); - virtual ~CellWidget (); + CellWidget ( QWidget* parent=NULL ); + virtual ~CellWidget (); // Accessors. - // MapView* getMapView () { return _mapView; }; - void setCell ( Cell* cell ); - inline Cell* getCell () const; - inline HPalette* getPalette (); - void bindToPalette ( HPalette* palette ); - void detachFromPalette (); - void bindCommand ( Command* command ); - void unbindCommand ( Command* command ); - inline bool showBoundaries () const; - inline set& getSelectorSet (); - inline bool showSelection () const; - void select ( const Net* net, bool delayRedraw=false ); - void select ( Occurrence occurence ); - void unselect ( Occurrence occurence ); - void unselectAll ( bool delayRedraw=true ); - inline void setStartLevel ( int level ); - inline void setStopLevel ( int level ); - inline void setQueryFilter ( int filter ); + // MapView* getMapView () { return _mapView; }; + void setCell ( Cell* cell ); + inline Cell* getCell () const; + inline HPalette* getPalette (); + void bindToPalette ( HPalette* palette ); + void detachFromPalette (); + void bindCommand ( Command* command ); + void unbindCommand ( Command* command ); + inline bool showBoundaries () const; + inline set& getSelectorSet (); + inline bool showSelection () const; + inline void setStartLevel ( int level ); + inline void setStopLevel ( int level ); + inline void setQueryFilter ( int filter ); // Painter control & Hurricane objects drawing primitives. - inline float getScale () const; - bool isDrawable ( const Name& entryName ); - void drawBox ( const Box& ); - void drawLine ( const Point&, const Point& ); - void drawGrid (); - void drawSpot (); - void drawScreenRect ( const QPoint&, const QPoint& ); - void drawScreenPolyline ( const QPoint*, int, int ); + inline float getScale () const; + bool isDrawable ( const Name& entryName ); + void drawBox ( const Box& ); + void drawLine ( const Point&, const Point& ); + void drawGrid (); + void drawSpot (); + void drawScreenRect ( const QPoint&, const QPoint& ); + void drawScreenPolyline ( const QPoint*, int, int ); // Geometric conversions. - QRect dbuToDisplayRect ( DbU::Unit x1, DbU::Unit y1, DbU::Unit x2, DbU::Unit y2 ) const; - QRect dbuToDisplayRect ( const Box& box ) const; - QPoint dbuToDisplayPoint ( DbU::Unit x, DbU::Unit y ) const; - QPoint dbuToDisplayPoint ( const Point& point ) const; - inline int dbuToDisplayX ( DbU::Unit x ) const; - inline int dbuToDisplayY ( DbU::Unit y ) const; - inline int dbuToDisplayLength ( DbU::Unit length ) const; - inline int dbuToScreenX ( DbU::Unit x ) const; - inline int dbuToScreenY ( DbU::Unit y ) const; - QPoint dbuToScreenPoint ( DbU::Unit x, DbU::Unit y ) const; - inline QPoint dbuToScreenPoint ( const Point& point ) const; - inline DbU::Unit displayToDbuX ( int x ) const; - inline DbU::Unit displayToDbuY ( int y ) const; - inline DbU::Unit displayToDbuLength ( int length ) const; - inline Box displayToDbuBox ( const QRect& rect ) const; - inline DbU::Unit screenToDbuX ( int x ) const; - inline DbU::Unit screenToDbuY ( int y ) const; - inline Point screenToDbuPoint ( const QPoint& point ) const; - inline Box screenToDbuBox ( const QRect& rect ) const; + QRect dbuToDisplayRect ( DbU::Unit x1, DbU::Unit y1, DbU::Unit x2, DbU::Unit y2 ) const; + QRect dbuToDisplayRect ( const Box& box ) const; + QPoint dbuToDisplayPoint ( DbU::Unit x, DbU::Unit y ) const; + QPoint dbuToDisplayPoint ( const Point& point ) const; + inline int dbuToDisplayX ( DbU::Unit x ) const; + inline int dbuToDisplayY ( DbU::Unit y ) const; + inline int dbuToDisplayLength ( DbU::Unit length ) const; + inline int dbuToScreenX ( DbU::Unit x ) const; + inline int dbuToScreenY ( DbU::Unit y ) const; + QPoint dbuToScreenPoint ( DbU::Unit x, DbU::Unit y ) const; + inline QPoint dbuToScreenPoint ( const Point& point ) const; + inline DbU::Unit displayToDbuX ( int x ) const; + inline DbU::Unit displayToDbuY ( int y ) const; + inline DbU::Unit displayToDbuLength ( int length ) const; + inline Box displayToDbuBox ( const QRect& rect ) const; + inline DbU::Unit screenToDbuX ( int x ) const; + inline DbU::Unit screenToDbuY ( int y ) const; + inline Point screenToDbuPoint ( const QPoint& point ) const; + inline Box screenToDbuBox ( const QRect& rect ) const; // Qt QWidget Functions Overloads. - 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* ); + 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* ); signals: - void mousePositionChanged ( const Point& position ); + void mousePositionChanged ( const Point& position ); + void selectionChanged ( const set&, Cell* ); + void occurrenceToggled ( Occurrence ); public slots: // Qt QWidget Slots Overload & CellWidget Specifics. - inline DrawingPlanes& getDrawingPlanes (); - inline QPoint& getOffsetVA (); - void setShowSelection ( bool state ); - inline void redraw (); - void redraw ( QRect redrawArea ); - inline void redrawSelection (); - void redrawSelection ( QRect redrawArea ); - 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 displayReframe (); - void shiftLeft ( int dx ); - void shiftRight ( int dx ); - void shiftUp ( int dy ); - void shiftDown ( int dy ); + inline DrawingPlanes& getDrawingPlanes (); + inline QPoint& getOffsetVA (); + void select ( const Net* net, bool delayRedraw=false ); + void select ( Occurrence occurence ); + void selectOccurrencesUnder ( Box selectArea ); + void unselect ( Occurrence occurence ); + void unselectAll ( bool delayRedraw=false ); + void toggleSelect ( Occurrence occurence, bool fromPopup ); + void setShowSelection ( bool state ); + void setCumulativeSelection ( bool state ); + inline void redraw (); + void redraw ( QRect redrawArea ); + inline void redrawSelection (); + void redrawSelection ( QRect redrawArea ); + 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 displayReframe (); + void shiftLeft ( int dx ); + void shiftRight ( int dx ); + void shiftUp ( int dy ); + void shiftDown ( int dy ); private: class Spot { @@ -298,6 +303,7 @@ namespace Hurricane { Cell* _cell; bool _showBoundaries; bool _showSelection; + bool _cumulativeSelection; bool _selectionHasChanged; set _selectors; vector _commands; diff --git a/hurricane/src/hviewer/hurricane/viewer/HInspectorWidget.h b/hurricane/src/hviewer/hurricane/viewer/HInspectorWidget.h index 2ab04da0..77d2ff24 100644 --- a/hurricane/src/hviewer/hurricane/viewer/HInspectorWidget.h +++ b/hurricane/src/hviewer/hurricane/viewer/HInspectorWidget.h @@ -108,6 +108,7 @@ namespace Hurricane { ~HInspectorWidget (); void setRootRecord ( Record* record ); private slots: + void forceRowHeight (); void textFilterChanged (); void historyChanged ( int depth ); void forkInspector ( const QModelIndex& index ); @@ -120,10 +121,10 @@ namespace Hurricane { bool setSlot (); private: - RecordModel* _recordModel; + RecordModel* _baseModel; QSortFilterProxyModel* _sortModel; QComboBox* _historyComboBox; - QTableView* _slotsView; + QTableView* _view; QLineEdit* _filterPatternLineEdit; int _rowHeight; History _history; diff --git a/hurricane/src/hviewer/hurricane/viewer/HNetlist.h b/hurricane/src/hviewer/hurricane/viewer/HNetlist.h index 04095d9f..a02f36a0 100644 --- a/hurricane/src/hviewer/hurricane/viewer/HNetlist.h +++ b/hurricane/src/hviewer/hurricane/viewer/HNetlist.h @@ -88,6 +88,8 @@ namespace Hurricane { template void setCellWidget ( CellWidget* cw ); void runInspector ( const QModelIndex& index ); + public slots: + void forceRowHeight (); private slots: void textFilterChanged (); void selectNet ( const QModelIndex& index ); @@ -95,9 +97,9 @@ namespace Hurricane { void keyPressEvent ( QKeyEvent * event ); private: - HNetlistModel* _netlistModel; + HNetlistModel* _baseModel; QSortFilterProxyModel* _sortModel; - QTableView* _netlistView; + QTableView* _view; QLineEdit* _filterPatternLineEdit; int _rowHeight; CellWidget* _cellWidget; @@ -107,23 +109,23 @@ namespace Hurricane { template void HNetlist::setCell ( Cell* cell ) { - _netlistModel->setCell ( cell ); + _baseModel->setCell ( cell ); string windowTitle = "Netlist" + getString(cell); setWindowTitle ( tr(windowTitle.c_str()) ); int rows = _sortModel->rowCount (); for ( rows-- ; rows >= 0 ; rows-- ) - _netlistView->setRowHeight ( rows, _rowHeight ); - _netlistView->selectRow ( 0 ); - _netlistView->resizeColumnToContents ( 0 ); + _view->setRowHeight ( rows, _rowHeight ); + _view->selectRow ( 0 ); + _view->resizeColumnToContents ( 0 ); } template void HNetlist::setCellWidget ( CellWidget* cw ) { - if ( _netlistModel->getCell() != cw->getCell() ) + if ( _baseModel->getCell() != cw->getCell() ) setCell( cw->getCell() ); _cellWidget = cw; diff --git a/hurricane/src/hviewer/hurricane/viewer/HSelection.h b/hurricane/src/hviewer/hurricane/viewer/HSelection.h index 7d76cf96..68582fa4 100644 --- a/hurricane/src/hviewer/hurricane/viewer/HSelection.h +++ b/hurricane/src/hviewer/hurricane/viewer/HSelection.h @@ -59,6 +59,7 @@ #include #include "hurricane/Commons.h" +#include "hurricane/Occurrence.h" #include "hurricane/viewer/HSelectionModel.h" @@ -68,12 +69,14 @@ class QTableView; class QLineEdit; class QComboBox; class QHeaderView; +class QCheckBox; namespace Hurricane { class Selector; + class QCloseEvent; class HSelection : public QWidget { @@ -82,19 +85,29 @@ namespace Hurricane { public: HSelection ( QWidget* parent=NULL ); void runInspector ( const QModelIndex& index ); + bool isCumulative () const; + signals: + void showSelected ( bool ); + void occurrenceToggled ( Occurrence, bool ); + void cumulativeToggled ( bool ); + void selectionCleared (); public slots: void setSelection ( const set& selection, Cell* cell=NULL ); - void addToSelection ( Selector* selector ); + void toggleSelection ( Occurrence occurrence ); + void toggleSelection ( const QModelIndex& index ); + void forceRowHeight (); private slots: void textFilterChanged (); protected: - void keyPressEvent ( QKeyEvent * event ); + virtual void keyPressEvent ( QKeyEvent * event ); + virtual void hideEvent ( QHideEvent* event ); private: - HSelectionModel* _selectionModel; + HSelectionModel* _baseModel; QSortFilterProxyModel* _sortModel; - QTableView* _selectionView; + QTableView* _view; QLineEdit* _filterPatternLineEdit; + QCheckBox* _cumulative; int _rowHeight; }; diff --git a/hurricane/src/hviewer/hurricane/viewer/HSelectionModel.h b/hurricane/src/hviewer/hurricane/viewer/HSelectionModel.h index 5b5d7aeb..ebf80ab9 100644 --- a/hurricane/src/hviewer/hurricane/viewer/HSelectionModel.h +++ b/hurricane/src/hviewer/hurricane/viewer/HSelectionModel.h @@ -71,22 +71,58 @@ namespace Hurricane { class Selector; + class OccurrenceItem { + public: + enum Flags { Selected=1 }; + public: + inline OccurrenceItem ( Occurrence occurrence, unsigned int flags=Selected ); + inline void toggle (); + inline bool operator== ( const OccurrenceItem& other ) const; + public: + unsigned int _flags; + Occurrence _occurrence; + }; + + + inline OccurrenceItem::OccurrenceItem ( Occurrence occurrence, unsigned int flags ) + : _flags(flags) + , _occurrence(occurrence) + { } + + + inline void OccurrenceItem::toggle () + { + if ( _flags & Selected ) _flags &= ~Selected; + else _flags |= Selected; + } + + + inline bool OccurrenceItem::operator== ( const OccurrenceItem& other ) const + { + return _occurrence == other._occurrence; + } + + class HSelectionModel : public QAbstractTableModel { Q_OBJECT; public: - HSelectionModel ( QObject* parent=NULL ); - ~HSelectionModel (); - void setSelection ( const set& selection ); - void addToSelection ( Selector* selector ); - 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; - const Occurrence getOccurrence ( int row ); + HSelectionModel ( QObject* parent=NULL ); + ~HSelectionModel (); + void setSelection ( const set& selection ); + void toggleSelection ( Occurrence occurrence ); + Occurrence toggleSelection ( const QModelIndex& index ); + 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; + const Occurrence getOccurrence ( int row ); + bool isCumulative () const; + public slots: + void clear (); private: - vector _selection; + vector _selection; }; diff --git a/hurricane/src/hviewer/hurricane/viewer/HSelectionPopup.h b/hurricane/src/hviewer/hurricane/viewer/HSelectionPopup.h new file mode 100644 index 00000000..9c9b0e40 --- /dev/null +++ b/hurricane/src/hviewer/hurricane/viewer/HSelectionPopup.h @@ -0,0 +1,104 @@ + +// -*- C++ -*- +// +// This file is part of the Coriolis Project. +// Copyright (C) Laboratoire LIP6 - Departement ASIM +// Universite Pierre et Marie Curie +// +// Main contributors : +// Christophe Alexandre +// Sophie Belloeil +// Hugo Clément +// Jean-Paul Chaput +// Damien Dupuis +// Christian Masson +// Marek Sroka +// +// The Coriolis Project is free software; you can redistribute it +// and/or modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// The Coriolis Project is distributed in the hope that it will be +// useful, but WITHOUT ANY WARRANTY; without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with the Coriolis Project; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA +// +// License-Tag +// Authors-Tag +// =================================================================== +// +// $Id$ +// +// x-----------------------------------------------------------------x +// | | +// | H U R R I C A N E | +// | V L S I B a c k e n d D a t a - B a s e | +// | | +// | Author : Jean-Paul CHAPUT | +// | E-mail : Jean-Paul.Chaput@asim.lip6.fr | +// | =============================================================== | +// | C++ Header : "./HSelectionPopup.h" | +// | *************************************************************** | +// | U p d a t e s | +// | | +// x-----------------------------------------------------------------x + + +#ifndef __HURRICANE_SELECTION_POPUP_WIDGET_H__ +#define __HURRICANE_SELECTION_POPUP_WIDGET_H__ + + +#include +#include + +#include "hurricane/Commons.h" +#include "hurricane/Occurrence.h" + + +class QModelIndex; +class QTableView; +class QComboBox; +class QHeaderView; + + +namespace Hurricane { + + + class HSelectionPopupModel; + + + class HSelectionPopup : public QWidget { + Q_OBJECT; + + public: + HSelectionPopup ( QWidget* parent=NULL ); + void updateLayout (); + void popup (); + signals: + void occurrenceSelected ( Occurrence occurrence, bool fromPopup ); + public slots: + void add ( Occurrence occurrence, bool showChange=false ); + void clear (); + void forceRowHeight (); + protected: + virtual void keyPressEvent ( QKeyEvent * event ); + virtual void mouseMoveEvent ( QMouseEvent* event ); + virtual void mouseReleaseEvent ( QMouseEvent* event ); + + private: + HSelectionPopupModel* _model; + QTableView* _view; + int _rowHeight; + }; + + +} // End of Hurricane namespace. + + +#endif // __HURRICANE_SELECTION_POPUP_WIDGET_H__ diff --git a/hurricane/src/hviewer/hurricane/viewer/HSelectionPopupModel.h b/hurricane/src/hviewer/hurricane/viewer/HSelectionPopupModel.h new file mode 100644 index 00000000..54d45f9b --- /dev/null +++ b/hurricane/src/hviewer/hurricane/viewer/HSelectionPopupModel.h @@ -0,0 +1,97 @@ + +// -*- C++ -*- +// +// This file is part of the Coriolis Project. +// Copyright (C) Laboratoire LIP6 - Departement ASIM +// Universite Pierre et Marie Curie +// +// Main contributors : +// Christophe Alexandre +// Sophie Belloeil +// Hugo Clément +// Jean-Paul Chaput +// Damien Dupuis +// Christian Masson +// Marek Sroka +// +// The Coriolis Project is free software; you can redistribute it +// and/or modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// The Coriolis Project is distributed in the hope that it will be +// useful, but WITHOUT ANY WARRANTY; without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with the Coriolis Project; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA +// +// License-Tag +// Authors-Tag +// =================================================================== +// +// $Id$ +// +// x-----------------------------------------------------------------x +// | | +// | H U R R I C A N E | +// | V L S I B a c k e n d D a t a - B a s e | +// | | +// | Author : Jean-Paul CHAPUT | +// | E-mail : Jean-Paul.Chaput@asim.lip6.fr | +// | =============================================================== | +// | C++ Header : "./HSelectionPopupModel.h" | +// | *************************************************************** | +// | U p d a t e s | +// | | +// x-----------------------------------------------------------------x + + +#ifndef __HURRICANE_SELECTION_POPUP_MODEL_H__ +#define __HURRICANE_SELECTION_POPUP_MODEL_H__ + +#include +#include + +#include +#include +#include + +#include "hurricane/Commons.h" +#include "hurricane/Occurrence.h" +#include "hurricane/viewer/Graphics.h" + + +namespace Hurricane { + + + class Selector; + + + class HSelectionPopupModel : public QAbstractTableModel { + Q_OBJECT; + + public: + HSelectionPopupModel ( QObject* parent=NULL ); + ~HSelectionPopupModel (); + 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 ); + + private: + vector* _occurrences; + }; + + +} // End of Hurricane namespace. + + +#endif // __HURRICANE_SELECTION_POPUP_MODEL_H__ diff --git a/hurricane/src/hviewer/hurricane/viewer/SelectCommand.h b/hurricane/src/hviewer/hurricane/viewer/SelectCommand.h index 96420d18..441b115c 100644 --- a/hurricane/src/hviewer/hurricane/viewer/SelectCommand.h +++ b/hurricane/src/hviewer/hurricane/viewer/SelectCommand.h @@ -60,6 +60,7 @@ class QAction; +#include "hurricane/Occurrence.h" #include "hurricane/viewer/AreaCommand.h" @@ -71,6 +72,7 @@ namespace Hurricane { class Cell; class Selector; + class HSelectionPopup; class SelectCommand : public QObject, public AreaCommand { @@ -83,16 +85,17 @@ namespace Hurricane { virtual bool mouseReleaseEvent ( CellWidget*, QMouseEvent* ); void bindToAction ( QAction* action ); signals: - void selectionChanged ( const set&, Cell* ); + void selectionToggled ( Occurrence occurrence, bool fromPopup ); private: QAction* _selectAction; + HSelectionPopup* _selectionPopup; private: SelectCommand ( const SelectCommand& ); SelectCommand& operator= ( const SelectCommand& ); }; -} +} // End of Hurricane namespace. #endif