Various bug fixes (Selection, Measures/Histogram, helpers).

* Bug: In CRL/python/helpers/__init__.py, in textPythonTrace(), when an
    ErrorMessage was catched, the trace parameter was not correctly
    extracted leading to an "exception in exception".
* New: In Isobar/PyCell, exported Cell::getNonLeafInstanceOccurrences()
    collection.
* New: In Isobar/PyTransformation, type is now built so the tp_compare
    is linked to the C++ operator==().
* Change: In Hurricane::SelectionModel, Hurricane::SelectionWidget and
    CellWidget, no longer use Occurrences but directly the Selector property.
      We also use the Selector to know if an Occurrence is selected by
    looking at that property on it's Quark. This avoid a very lengthy
    search in vector when there is many elements (say > 10000).
      NOTE: This is a bad implementation as there is a confusion between
    beeing selected (that is, having a Selector property attached to
    an Occurrence Quark) and being actually displayed as selected.
    This lead to awkward implatation of the various "toggle" methods.
    Have to rethink that more clearly later.
* Bug: In CRL::Histogram, the non-inline template full specialisation
    of Measure<Histogram> must not be put in the header but in the module
    to avoid multiple definition and link failure. They are actually
    real, classic functions.
This commit is contained in:
Jean-Paul Chaput 2019-11-22 00:24:47 +01:00
parent 39cd831a57
commit f38945d200
16 changed files with 526 additions and 409 deletions

View File

@ -101,9 +101,9 @@ def textPythonTrace ( scriptPath=None, e=None, tryContinue=True ):
s += ' \"%s\"\n' % (filename)
s += ' You should check for simple python errors in this module.\n'
if isinstance(e,helpers.io.ErrorMessage): trace = e.trace()
else: trace = sys.exc_info()[2]
s += textStackTrace( traceback.extract_tb( trace ) )
if isinstance(e,helpers.io.ErrorMessage): trace = e.trace
else: trace = traceback.extract_tb( sys.exc_info()[2] )
s += textStackTrace( trace )
if e:
s += ' Error was:\n'

View File

@ -230,4 +230,47 @@ namespace CRL {
}
Measure<Histogram>::Measure ( const Name& name, Histogram* data )
: BaseMeasure(name,0)
, _data(data)
{ }
Measure<Histogram>::~Measure ()
{ delete _data; }
bool Measure<Histogram>::isSimpleData () const
{ return false; }
Histogram* Measure<Histogram>::getData () const
{ return _data; }
void Measure<Histogram>::setData ( Histogram* data )
{ _data=data; }
std::string Measure<Histogram>::toString () const
{ return "Unsupported"; }
void Measure<Histogram>::toGnuplot ( std::string basename ) const
{ _data->toGnuplot ( basename ); }
std::string Measure<Histogram>::_getString () const
{ return "<Measure Histogram>"; }
Record* Measure<Histogram>::_getRecord () const
{
Record* record = new Record ( _getString() );
if ( record ) {
record->add ( getSlot("_data",_data) );
}
return record;
}
} // End of CRL namespace.

View File

@ -59,21 +59,21 @@ namespace CRL {
// Inline Functions.
inline void Histogram::setMainTitle ( std::string title ) { _mainTitle=title; }
inline void Histogram::setMainTitle ( std::string title ) { _mainTitle=title; }
inline void Histogram::setTitle ( std::string title , size_t iset ) { if (iset<_titles .size()) _titles[iset ] = title; }
inline void Histogram::setColor ( std::string color , size_t iset ) { if (iset<_colors .size()) _colors[iset ] = color; }
inline void Histogram::setIndent ( std::string indent, size_t iset ) { if (iset<_indents.size()) _indents[iset] = indent; }
inline void Histogram::setFileExtension ( std::string extension ) { _fileExtension=extension; }
inline void Histogram::setFileExtension ( std::string extension ) { _fileExtension=extension; }
template<>
class Measure<Histogram> : public BaseMeasure {
public:
inline Measure ( const Name&, Histogram* );
Measure ( const Name&, Histogram* );
virtual ~Measure ();
virtual bool isSimpleData () const;
inline Histogram* getData () const;
inline void setData ( Histogram* );
Histogram* getData () const;
void setData ( Histogram* );
virtual std::string toString () const;
virtual void toGnuplot ( std::string basename ) const;
virtual std::string _getString () const;
@ -83,36 +83,6 @@ namespace CRL {
};
inline Measure<Histogram>::Measure ( const Name& name, Histogram* data )
: BaseMeasure(name,0), _data(data) { }
Measure<Histogram>::~Measure () { delete _data; }
bool Measure<Histogram>::isSimpleData () const { return false; }
inline Histogram* Measure<Histogram>::getData () const { return _data; }
inline void Measure<Histogram>::setData ( Histogram* data ) { _data=data; }
std::string Measure<Histogram>::toString () const
{ return "Unsupported"; }
void Measure<Histogram>::toGnuplot ( std::string basename ) const
{ _data->toGnuplot ( basename ); }
std::string Measure<Histogram>::_getString () const
{ return "<Measure Histogram>"; }
Record* Measure<Histogram>::_getRecord () const
{
Record* record = new Record ( _getString() );
if ( record ) {
record->add ( getSlot("_data",_data) );
}
return record;
}
} // CRL namespace.

View File

@ -327,24 +327,40 @@ extern "C" {
// ---------------------------------------------------------------
// Attribute Method : "PyCell_getLeafInstanceOccurrences()"
static PyObject* PyCell_getLeafInstanceOccurrences(PyCell *self) {
static PyObject* PyCell_getLeafInstanceOccurrences ( PyCell* self)
{
cdebug_log(20,0) << "PyCell_getLeafInstanceOccurrences()" << endl;
METHOD_HEAD ( "Cell.getLeafInstanceOccurrences()" )
PyOccurrenceCollection* pyOccurrenceCollection = NULL;
HTRY
Occurrences* occurrences = new Occurrences(cell->getLeafInstanceOccurrences());
pyOccurrenceCollection = PyObject_NEW(PyOccurrenceCollection, &PyTypeOccurrenceCollection);
if (pyOccurrenceCollection == NULL) {
return NULL;
}
pyOccurrenceCollection->_object = occurrences;
Occurrences* occurrences = new Occurrences(cell->getLeafInstanceOccurrences());
pyOccurrenceCollection = PyObject_NEW(PyOccurrenceCollection, &PyTypeOccurrenceCollection);
if (pyOccurrenceCollection == NULL) return NULL;
pyOccurrenceCollection->_object = occurrences;
HCATCH
return (PyObject*)pyOccurrenceCollection;
}
static PyObject* PyCell_getNonLeafInstanceOccurrences ( PyCell* self)
{
cdebug_log(20,0) << "PyCell_getNonLeafInstanceOccurrences()" << endl;
METHOD_HEAD ( "Cell.getLeafNonInstanceOccurrences()" )
PyOccurrenceCollection* pyOccurrenceCollection = NULL;
HTRY
Occurrences* occurrences = new Occurrences(cell->getNonLeafInstanceOccurrences());
pyOccurrenceCollection = PyObject_NEW(PyOccurrenceCollection, &PyTypeOccurrenceCollection);
if (pyOccurrenceCollection == NULL) return NULL;
pyOccurrenceCollection->_object = occurrences;
HCATCH
return (PyObject*)pyOccurrenceCollection;
}
@ -722,7 +738,9 @@ extern "C" {
, { "getOccurrences" , (PyCFunction)PyCell_getOccurrences , METH_NOARGS , "Returns the collection of all occurrences belonging to the cell." }
, { "getOccurrencesUnder" , (PyCFunction)PyCell_getOccurrencesUnder , METH_VARARGS, "Returns the collection of all occurrences belonging to this cell and intersecting the given rectangular area." }
, { "getLeafInstanceOccurrences" , (PyCFunction)PyCell_getLeafInstanceOccurrences , METH_NOARGS
, "Returns the collection of all occurrences belonging to the cell." }
, "Returns the collection all terminal instances occurrences." }
, { "getNonLeafInstanceOccurrences" , (PyCFunction)PyCell_getNonLeafInstanceOccurrences , METH_NOARGS
, "Returns the collection of all non-terminal instances occurrences." }
, { "getLeafInstanceOccurrencesUnder", (PyCFunction)PyCell_getLeafInstanceOccurrencesUnder, METH_VARARGS
, "Returns the collection of all occurrences belonging to this cell and intersecting the given rectangular area." }
, { "getReferences" , (PyCFunction)PyCell_getReferences , METH_VARARGS, "Returns the collection of all references belonging to the cell." }

View File

@ -520,8 +520,7 @@ extern "C" {
// x-------------------------------------------------------------x
DirectDeleteMethod(PyTransformation_DeAlloc,PyTransformation)
PyTypeObjectLinkPyTypeNewInit(Transformation)
//PyTypeObjectLinkPyType(Transformation)
PyTypeObjectLinkPyTypeAsValue(Transformation)
#else // End of Python Module Code Part.

View File

@ -761,6 +761,13 @@ namespace Hurricane {
}
void CellViewer::setCumulativeSelection ( bool state )
{
_updateState = InternalEmit;
_cellWidget->setCumulativeSelection ( state );
}
void CellViewer::raiseToolInterrupt ()
{ _toolInterrupt = true; }

View File

@ -1176,6 +1176,13 @@ namespace Hurricane {
}
void CellWidget::detach ( Selector* selector )
{
getSelectorSet().erase( selector );
emit unlinkSelector( selector );
}
void CellWidget::bindCommand ( Command* command )
{
for ( size_t i=0 ; i<_commands.size() ; i++ )
@ -1492,28 +1499,29 @@ namespace Hurricane {
_drawingPlanes.painter().setBackground ( Graphics::getBrush("background") );
_drawingPlanes.painter().setClipRect ( redrawArea );
if ( getCell() ) {
Box redrawBox = screenToDbuBox ( redrawArea );
if (getCell()) {
Box redrawBox = screenToDbuBox( redrawArea );
SelectorSet::iterator iselector;
forEach ( BasicLayer*, basicLayer, _technology->getBasicLayers() ) {
for ( BasicLayer* basicLayer : _technology->getBasicLayers() ) {
//if ( !isDrawableLayer(basicLayer->getName()) ) continue;
_drawingPlanes.setPen ( Graphics::getPen (basicLayer->getName()) );
_drawingPlanes.setBrush ( Graphics::getBrush(basicLayer->getName()) );
iselector = _selectors.begin();
for ( ; iselector != _selectors.end() ; iselector++ ) {
Occurrence occurrence = (*iselector)->getOccurrence();
Component* component = dynamic_cast<Component*>(occurrence.getEntity());
for ( Selector* selector : _selectors ) {
if (not selector->isSelected(this)) continue;
Occurrence occurrence = selector->getOccurrence();
Component* component = dynamic_cast<Component*>( occurrence.getEntity() );
if ( component == NULL ) continue;
if ( not component->getLayer() ) continue;
if ( not component->getLayer()->contains(*basicLayer) ) continue;
if (not component) continue;
if (not component->getLayer()) continue;
if (not component->getLayer()->contains(basicLayer)) continue;
Transformation transformation = occurrence.getPath().getTransformation();
_drawingQuery.drawGo ( dynamic_cast<Go*>(occurrence.getEntity())
, *basicLayer
, basicLayer
, redrawBox
, transformation
);
@ -1523,52 +1531,55 @@ namespace Hurricane {
_drawingPlanes.setPen ( Graphics::getPen ("boundaries") );
_drawingPlanes.setBrush ( Graphics::getBrush("boundaries") );
iselector = _selectors.begin();
for ( ; iselector != _selectors.end() ; iselector++ ) {
Occurrence occurrence = (*iselector)->getOccurrence();
for ( Selector* selector : _selectors ) {
if (not selector->isSelected(this)) continue;
Occurrence occurrence = selector->getOccurrence();
Instance* instance = dynamic_cast<Instance*>(occurrence.getEntity());
if ( instance ) {
if (instance) {
Transformation transformation
= occurrence.getPath().getTransformation().getTransformation(instance->getTransformation());
_drawingQuery.drawMasterCell ( instance->getMasterCell(), transformation );
_drawingQuery.drawMasterCell( instance->getMasterCell(), transformation );
}
}
_drawingPlanes.setPen ( Graphics::getPen ("rubber") );
_drawingPlanes.setBrush ( Graphics::getBrush("rubber") );
_drawingPlanes.setPen ( Graphics::getPen ("rubber") );
_drawingPlanes.setBrush( Graphics::getBrush("rubber") );
iselector = _selectors.begin();
for ( ; iselector != _selectors.end() ; iselector++ ) {
Occurrence occurrence = (*iselector)->getOccurrence();
for ( Selector* selector : _selectors ) {
if (not selector->isSelected(this)) continue;
Occurrence occurrence = selector->getOccurrence();
Rubber* rubber = dynamic_cast<Rubber*>(occurrence.getEntity());
if ( rubber == NULL ) continue;
if (not rubber) continue;
Transformation transformation = occurrence.getPath().getTransformation();
_drawingQuery.drawRubber ( rubber, redrawBox, transformation );
_drawingQuery.drawRubber( rubber, redrawBox, transformation );
}
Name extensionName = "";
iselector = _selectors.begin();
for ( ; iselector != _selectors.end() ; iselector++ ) {
Occurrence occurrence = (*iselector)->getOccurrence();
for ( Selector* selector : _selectors ) {
if (not selector->isSelected(this)) continue;
Occurrence occurrence = selector->getOccurrence();
ExtensionGo* eGo = dynamic_cast<ExtensionGo*>(occurrence.getEntity());
if ( eGo == NULL ) continue;
if (not eGo) continue;
Transformation transformation = occurrence.getPath().getTransformation();
if ( eGo->getName() != extensionName ) {
if (eGo->getName() != extensionName) {
extensionName = eGo->getName();
_drawingQuery.setDrawExtensionGo ( extensionName );
_drawingQuery.setDrawExtensionGo( extensionName );
}
if ( isDrawable(extensionName) )
_drawingQuery.drawExtensionGo ( this, eGo, NULL, redrawBox, transformation );
if (isDrawable(extensionName))
_drawingQuery.drawExtensionGo( this, eGo, NULL, redrawBox, transformation );
}
}
_drawingPlanes.end ();
_drawingPlanes.end();
_selectionHasChanged = false;
}
@ -2589,9 +2600,9 @@ namespace Hurricane {
void CellWidget::selectOccurrencesUnder ( Box selectArea )
{
if ( (++_delaySelectionChanged == 1) and not _state->cumulativeSelection() ) {
openRefreshSession ();
unselectAll ();
closeRefreshSession ();
openRefreshSession();
unselectAll();
closeRefreshSession();
}
bool selected = true;
@ -2603,12 +2614,12 @@ namespace Hurricane {
// cerr << "Selecting: " << occurrence << endl;
//}
forEach ( Occurrence, ioccurrence, getOccurrencesUnder(selectArea) )
select ( *ioccurrence );
for ( Occurrence occurrence : getOccurrencesUnder(selectArea) )
select( occurrence );
} else
selected = false;
if ( (--_delaySelectionChanged == 0) and selected ) emit selectionChanged(_selectors);
if ( (--_delaySelectionChanged == 0) and selected ) emit selectionChanged( _selectors );
}
@ -2620,29 +2631,29 @@ namespace Hurricane {
closeRefreshSession ();
}
if ( not occurrence.isValid() )
if (not occurrence.isValid())
throw Error ( "Can't select occurrence : invalid occurrence" );
if ( occurrence.getOwnerCell() != getCell() ) {
string s1 = Graphics::toHtml ( getString(getCell()) );
string s2 = Graphics::toHtml ( getString(occurrence.getOwnerCell()) );
if (occurrence.getOwnerCell() != getCell()) {
string s1 = Graphics::toHtml( getString(getCell()) );
string s2 = Graphics::toHtml( getString(occurrence.getOwnerCell()) );
throw Error ( "Can't select occurrence : incompatible occurrence %s vs. %s"
, s1.c_str(), s2.c_str() );
}
bool selected = true;
const Net* net = dynamic_cast<const Net*>(occurrence.getEntity());
const Net* net = dynamic_cast<const Net*>( occurrence.getEntity() );
if ( net ) {
SelectorCriterion* criterion = _state->getSelection().add ( net );
SelectorCriterion* criterion = _state->getSelection().add( net );
if ( criterion and (not criterion->isEnabled()) ) {
criterion->enable ();
forEach ( Component*, component, net->getComponents() ) {
Occurrence occurrence ( *component );
select ( occurrence );
criterion->enable();
for ( Component* component : net->getComponents() ) {
Occurrence occurrence ( component );
select( occurrence );
}
forEach ( Rubber*, irubber, net->getRubbers() ) {
Occurrence occurrence ( *irubber );
select ( occurrence );
for ( Rubber* rubber : net->getRubbers() ) {
Occurrence occurrence ( rubber );
select( occurrence );
}
} else
selected = false;
@ -2654,13 +2665,13 @@ namespace Hurricane {
selector = Selector::create ( occurrence );
else {
selector = dynamic_cast<Selector*>(property);
if ( not selector )
if (not selector)
throw Error ( "Abnormal property named " + getString(Selector::getPropertyName()) );
}
selector->attachTo(this);
selector->attachTo( this );
setShowSelection ( true );
//setShowSelection( true );
_selectionHasChanged = true;
if ( (--_delaySelectionChanged == 0) and selected ) {
@ -2720,50 +2731,54 @@ namespace Hurricane {
void CellWidget::toggleSelection ( Occurrence occurrence )
{
if ( not occurrence.isValid() )
throw Error ( "Can't select occurrence : invalid occurrence" );
if (not occurrence.isValid())
throw Error( "CellWidget::toggleSelection(): Unable to select invalid occurrence." );
if ( occurrence.getOwnerCell() != getCell() )
throw Error ( "Can't select occurrence : incompatible occurrence" );
throw Error( "CellWidget::toggleSelection(): Occurrence do not belong to the loaded cell." );
Property* property = occurrence.getProperty ( Selector::getPropertyName() );
Property* property = occurrence.getProperty( Selector::getPropertyName() );
Selector* selector = NULL;
if ( not property ) {
if (not property) {
// Net special case.
Net* net = dynamic_cast<Net*>(occurrence.getEntity());
if ( net ) {
if ( occurrence.getPath().isEmpty() ) {
select ( net );
Net* net = dynamic_cast<Net*>( occurrence.getEntity() );
if (net) {
if (occurrence.getPath().isEmpty()) {
select( net );
} else {
cerr << "[UNIMPLEMENTED] Selection of " << occurrence << endl;
cerr << "CellWidget::toggleSelection(): Selection of " << occurrence
<< " is not implemented." << endl;
}
} else {
selector = Selector::create ( occurrence );
selector->attachTo ( this );
setShowSelection ( true );
selector = Selector::create( occurrence );
selector->attachTo( this );
setShowSelection( true );
}
} else {
selector = dynamic_cast<Selector*>(property);
if ( !selector )
throw Error ( "Abnormal property named " + getString(Selector::getPropertyName()) );
selector = dynamic_cast<Selector*>( property );
if (not selector)
throw Error( "CellWidget::toggleSelection(): Abnormal property named "
+ getString(Selector::getPropertyName()) + " in place of Selector." );
// Net special case.
Net* net = dynamic_cast<Net*>(occurrence.getEntity());
if ( net ) {
if ( occurrence.getPath().isEmpty() ) {
unselect ( net );
Net* net = dynamic_cast<Net*>( occurrence.getEntity() );
if (net) {
if (occurrence.getPath().isEmpty()) {
unselect( net );
} else {
cerr << "[UNIMPLEMENTED] Selection of " << occurrence << endl;
cerr << "CellWidget::toggleSelection(): Selection of " << occurrence
<< " is not implemented." << endl;
}
} else {
selector->detachFrom ( this );
if (not selector->isToggleByController(this))
selector->detachFrom( this );
}
}
_selectionHasChanged = true;
if ( _state->showSelection() ) _redrawManager.refresh ();
if (_state->showSelection()) _redrawManager.refresh ();
emit selectionToggled ( occurrence );
emit selectionToggled( selector );
}
@ -2807,11 +2822,11 @@ namespace Hurricane {
void CellWidget::_unselectAll ()
{
SelectorSet::iterator iselector;
while ( !_selectors.empty() )
(*_selectors.begin())->detachFrom ( this );
while ( not _selectors.empty() )
(*_selectors.begin())->detachFrom( this );
if ( !_selectionHasChanged ) _selectionHasChanged = true;
if ( _state->showSelection() ) _redrawManager.refresh ();
if (not _selectionHasChanged) _selectionHasChanged = true;
if (_state->showSelection()) _redrawManager.refresh ();
}

View File

@ -276,6 +276,9 @@ extern "C" {
}
DirectSetBoolAttribute(PyCellViewer_setShowSelection,setShowSelection,PyCellViewer,CellViewer)
// ---------------------------------------------------------------
// PyCellViewer Attribute Method table.
@ -298,6 +301,8 @@ extern "C" {
, "Allow/disallow anonymous nets to be selectables." }
, { "setLayerVisible" , (PyCFunction)PyCellViewer_setLayerVisible , METH_VARARGS
, "Sets the visibility state of the layer <name>." }
, { "setShowSelection" , (PyCFunction)PyCellViewer_setShowSelection , METH_VARARGS
, "Display/hide the selection." }
, { "fit" , (PyCFunction)PyCellViewer_fit , METH_NOARGS
, "Triggers a full redraw of the visible area." }
, { "refresh" , (PyCFunction)PyCellViewer_refresh , METH_NOARGS

View File

@ -30,7 +30,8 @@ namespace Hurricane {
SelectionModel::SelectionModel ( QObject* parent )
: QAbstractTableModel(parent)
, _selection()
, _cellWidget(NULL)
, _selection ()
{ }
@ -41,101 +42,121 @@ namespace Hurricane {
bool SelectionModel::isCumulative () const
{
SelectionWidget* widget = qobject_cast<SelectionWidget*>(QObject::parent());
if ( widget )
if (widget)
return widget->cumulativeSelection();
return false;
}
void SelectionModel::setCellWidget ( CellWidget* w )
{
if (_cellWidget) {
disconnect( _cellWidget, 0, this , 0 );
disconnect( this , 0, _cellWidget, 0 );
}
_cellWidget = w;
if (not _cellWidget) return;
connect( _cellWidget, SIGNAL(unlinkSelector(Selector*)), this, SLOT(unlink(Selector*)) );
connect( _cellWidget, SIGNAL(cellPreModificated()) , this, SLOT(clear()) );
}
void SelectionModel::clear ()
{
beginResetModel();
for ( Selector* selector : _selection ) {
selector->resetFlags( _cellWidget, Selector::InModel|Selector::Selected );
}
_selection.clear();
endResetModel();
}
void SelectionModel::unlink ( Selector* selector )
{
beginResetModel();
for ( auto it=_selection.begin() ; it != _selection.end() ; ++it ) {
if ((*it) == selector) {
_selection.erase( it );
break;
}
}
endResetModel();
}
void SelectionModel::setSelection ( const SelectorSet& selection )
{
if (not _cellWidget) return;
beginResetModel();
if ( not isCumulative() ) _selection.clear ();
if (not isCumulative()) _selection.clear ();
SelectorSet::const_iterator iselector = selection.begin();
vector<OccurrenceItem>::iterator iitem;
for ( ; iselector != selection.end() ; iselector++ ) {
if ( isCumulative() ) {
iitem = find( _selection.begin(), _selection.end(), (*iselector)->getOccurrence() );
if ( iitem != _selection.end() ) {
(*iitem).setFlags ( OccurrenceItem::Selected );
continue;
}
for ( Selector* selector : selection ) {
if (not selector->isInModel(_cellWidget)) {
_selection.push_back( selector );
}
_selection.push_back ( OccurrenceItem((*iselector)->getOccurrence()) );
selector->setFlags( _cellWidget, Selector::InModel|Selector::Selected );
}
endResetModel();
}
void SelectionModel::setSelection ( Occurrence occurrence )
void SelectionModel::setSelection ( Selector* selector )
{
if (not _cellWidget) return;
bool modificated = false;
if ( not isCumulative() ) _selection.clear ();
size_t i = 0;
for ( ; i<_selection.size() ; i++ ) {
if ( _selection[i]._occurrence == occurrence ) break;
}
if ( i >= _selection.size() ) {
if (not isCumulative()) {
modificated = true;
beginResetModel ();
_selection.push_back ( OccurrenceItem(occurrence) );
}
else _selection[i].setFlags ( OccurrenceItem::Selected );
if ( modificated ) endResetModel ();
}
Occurrence SelectionModel::toggleSelection ( const QModelIndex& oindex )
{
if ( oindex.isValid() && ( oindex.row() < (int)_selection.size() ) ) {
_selection[oindex.row()].toggle();
emit dataChanged ( index(oindex.row(),0), index(oindex.row(),1) );
return _selection[oindex.row()]._occurrence;
_selection.clear ();
}
return Occurrence ();
}
Occurrence SelectionModel::getOccurrence ( const QModelIndex& index )
{
if ( index.isValid() && ( index.row() < (int)_selection.size() ) ) {
return _selection[index.row()]._occurrence;
}
return Occurrence ();
}
void SelectionModel::toggleSelection ( Occurrence occurrence )
{
bool found = false;
size_t i = 0;
for ( ; i<_selection.size() ; i++ ) {
if ( (not found) and (_selection[i]._occurrence == occurrence) ) {
found = true;
break;
if (not selector->isInModel(_cellWidget)) {
if (not modificated) {
modificated = true;
beginResetModel ();
}
_selection.push_back( selector );
}
selector->setFlags( _cellWidget, Selector::InModel|Selector::Selected );
if (modificated) endResetModel();
}
Selector* SelectionModel::toggleSelection ( const QModelIndex& oindex )
{
if ( oindex.isValid() and (oindex.row() < (int)_selection.size()) ) {
_selection[oindex.row()]->toggle( _cellWidget );
emit dataChanged( index(oindex.row(),0), index(oindex.row(),1) );
return _selection[ oindex.row() ];
}
if ( not found ) {
_selection.push_back ( OccurrenceItem(occurrence) );
return NULL;
}
Selector* SelectionModel::getSelector ( const QModelIndex& index )
{
if ( index.isValid() and (index.row() < (int)_selection.size()) ) {
return _selection[ index.row() ];
}
_selection[i].toggle ();
return NULL;
}
void SelectionModel::toggleSelection ( Selector* selector )
{
if (not _cellWidget) return;
selector->toggle( _cellWidget );
//emit dataChanged ( index(i,0), index(i,1) );
}
@ -167,31 +188,31 @@ namespace Hurricane {
QVariant SelectionModel::data ( const QModelIndex& index, int role ) const
{
static QBrush unselectForeground = QBrush ( QColor(255,0,0) );
static QFont occurrenceFont = Graphics::getFixedFont ( QFont::Normal );
static QFont unselectFont = Graphics::getFixedFont ( QFont::Normal, true );
static QFont selectFont = Graphics::getFixedFont ( QFont::Bold, false );
static QFontMetrics entityMetrics = QFontMetrics(selectFont);
static QBrush unselectForeground = QBrush( QColor(255,0,0) );
static QFont occurrenceFont = Graphics::getFixedFont( QFont::Normal );
static QFont unselectFont = Graphics::getFixedFont( QFont::Normal, true );
static QFont selectFont = Graphics::getFixedFont( QFont::Bold, false );
static QFontMetrics entityMetrics = QFontMetrics( selectFont );
if ( !index.isValid() ) return QVariant ();
if (not index.isValid()) return QVariant();
if ( role == Qt::SizeHintRole ) {
switch (index.column()) {
if (role == Qt::SizeHintRole) {
switch ( index.column() ) {
case 0: return 200;
default:
if ( index.row() > (int)_selection.size() ) return 0;
return entityMetrics.width(getString(_selection[index.row()]._occurrence.getEntity()).c_str());
if (index.row() > (int)_selection.size()) return 0;
return entityMetrics.width(getString( _selection[index.row()]->getEntity() ).c_str());
}
}
int row = index.row ();
if ( row >= (int)_selection.size() ) return QVariant ();
if (row >= (int)_selection.size()) return QVariant ();
if ( role == Qt::FontRole ) {
if (role == Qt::FontRole) {
switch (index.column()) {
case 0: return occurrenceFont;
case 1:
if ( _selection[row]._flags & OccurrenceItem::Selected )
if (_selection[row]->isSelected(_cellWidget))
return selectFont;
default:
return unselectFont;
@ -199,14 +220,14 @@ namespace Hurricane {
}
if ( role == Qt::ForegroundRole ) {
if ( _selection[row]._flags & OccurrenceItem::Selected ) return QVariant();
if (_selection[row]->isSelected(_cellWidget)) return QVariant();
return unselectForeground;
}
if ( role == Qt::DisplayRole ) {
if (role == Qt::DisplayRole) {
switch ( index.column() ) {
case 0: return getString(_selection[row]._occurrence.getPath().getName()).c_str();
case 1: return getString(_selection[row]._occurrence.getEntity()).c_str();
case 0: return getString(_selection[row]->getPath().getName()).c_str();
case 1: return getString(_selection[row]->getEntity()).c_str();
}
}
return QVariant();
@ -214,8 +235,8 @@ namespace Hurricane {
QVariant SelectionModel::headerData ( int section
, Qt::Orientation orientation
, int role ) const
, Qt::Orientation orientation
, int role ) const
{
if ( orientation == Qt::Vertical )
return QVariant();
@ -235,9 +256,7 @@ namespace Hurricane {
int SelectionModel::rowCount ( const QModelIndex& parent ) const
{
return _selection.size();
}
{ return _selection.size(); }
int SelectionModel::columnCount ( const QModelIndex& parent ) const
@ -246,11 +265,10 @@ namespace Hurricane {
}
const Occurrence SelectionModel::getOccurrence ( int row )
const Selector* SelectionModel::getSelector ( int row )
{
if ( row >= (int)_selection.size() ) return Occurrence();
return _selection[row]._occurrence;
if (row >= (int)_selection.size()) return NULL;
return _selection[ row ];
}

View File

@ -146,20 +146,21 @@ namespace Hurricane {
void SelectionWidget::setCellWidget ( CellWidget* cw )
{
if ( _cellWidget ) {
disconnect ( _cellWidget, 0, this , 0 );
disconnect ( this , 0, _cellWidget, 0 );
if (_cellWidget) {
disconnect( _cellWidget, 0, this , 0 );
disconnect( this , 0, _cellWidget, 0 );
}
_cellWidget = cw;
if ( !_cellWidget ) return;
_baseModel->setCellWidget( cw );
if (not _cellWidget) return;
connect ( _cellWidget, SIGNAL(selectionModeChanged()), this, SLOT(changeSelectionMode()) );
connect( _cellWidget, SIGNAL(selectionModeChanged()), this, SLOT(changeSelectionMode()) );
connect ( _cellWidget, SIGNAL(selectionChanged(const SelectorSet&))
, this , SLOT (setSelection (const SelectorSet&)) );
connect( _cellWidget, SIGNAL(selectionChanged(const SelectorSet&))
, this , SLOT (setSelection (const SelectorSet&)) );
connect ( _cellWidget, SIGNAL(selectionToggled(Occurrence)), this, SLOT(toggleSelection(Occurrence)) );
connect( _cellWidget, SIGNAL(selectionToggled(Selector*)), this , SLOT(toggleSelection(Selector*)) );
_updateState = ExternalEmit;
changeSelectionMode ();
@ -234,20 +235,20 @@ namespace Hurricane {
void SelectionWidget::toggleSelection ( const QModelIndex& index )
{
if ( index.isValid() ) {
Occurrence occurrence = _baseModel->toggleSelection ( _sortModel->mapToSource(index) );
if ( occurrence.isValid() ) {
if (index.isValid()) {
Selector* selector = _baseModel->toggleSelection( _sortModel->mapToSource(index) );
if (selector) {
_updateState = InternalEmit;
_cellWidget->toggleSelection ( occurrence );
_cellWidget->toggleSelection ( selector->getOccurrence() );
}
}
}
void SelectionWidget::toggleSelection ( Occurrence occurrence )
void SelectionWidget::toggleSelection ( Selector* selector )
{
if ( _updateState != InternalEmit ) {
_baseModel->toggleSelection ( occurrence );
if (_updateState != InternalEmit) {
_baseModel->toggleSelection( selector );
}
_updateState = ExternalEmit;
}
@ -268,15 +269,15 @@ namespace Hurricane {
}
void SelectionWidget::setSelection ( Occurrence occurrence )
{ _baseModel->setSelection ( occurrence ); }
void SelectionWidget::setSelection ( Selector* selector )
{ _baseModel->setSelection( selector ); }
void SelectionWidget::clear ()
{
_baseModel->clear ();
_view->selectionModel()->clearSelection ();
if ( _cellWidget )
{
_baseModel->clear();
_view->selectionModel()->clearSelection();
if (_cellWidget)
_cellWidget->unselectAll();
}
@ -295,8 +296,8 @@ namespace Hurricane {
void SelectionWidget::inspect ( const QModelIndex& index )
{
if ( index.isValid() ) {
Occurrence occurrence = _baseModel->getOccurrence ( _sortModel->mapToSource(index).row() );
if (index.isValid()) {
Occurrence occurrence = _baseModel->getSelector( _sortModel->mapToSource(index).row() )->getOccurrence();
emit inspect ( occurrence );
} else
emit inspect ( NULL );

View File

@ -40,36 +40,36 @@ namespace Hurricane {
const Entity* lhsEntity = lhs->getOccurrence().getEntity();
const Entity* rhsEntity = rhs->getOccurrence().getEntity();
const Component* lhsComponent = dynamic_cast<const Component*> ( lhsEntity );
const Component* rhsComponent = dynamic_cast<const Component*> ( rhsEntity );
if ( lhsComponent && rhsComponent ) return lhs < rhs; // lhs & rhs are Components.
if ( lhsComponent && !rhsComponent ) return true; // lhs only is an Component.
if ( !lhsComponent && rhsComponent ) return false; // rhs only is an Component.
const Component* lhsComponent = dynamic_cast<const Component*>( lhsEntity );
const Component* rhsComponent = dynamic_cast<const Component*>( rhsEntity );
if ( lhsComponent and rhsComponent) return lhs < rhs; // lhs & rhs are Components.
if ( lhsComponent and not rhsComponent) return true; // lhs only is an Component.
if (not lhsComponent and rhsComponent) return false; // rhs only is an Component.
const Instance* lhsInstance = dynamic_cast<const Instance*> ( lhsEntity );
const Instance* rhsInstance = dynamic_cast<const Instance*> ( rhsEntity );
const Instance* lhsInstance = dynamic_cast<const Instance*>( lhsEntity );
const Instance* rhsInstance = dynamic_cast<const Instance*>( rhsEntity );
//cerr << "Instance LHS: " << (void*)lhsInstance << " RHS: " << (void*)rhsInstance << endl;
if ( lhsInstance && rhsInstance ) return lhs < rhs; // lhs & rhs are Instances.
if ( lhsInstance && !rhsInstance ) return true; // lhs only is an Instance.
if ( !lhsInstance && rhsInstance ) return false; // rhs only is an Instance.
if ( lhsInstance and rhsInstance) return lhs < rhs; // lhs & rhs are Instances.
if ( lhsInstance and not rhsInstance) return true; // lhs only is an Instance.
if (not lhsInstance and rhsInstance) return false; // rhs only is an Instance.
const Rubber* lhsRubber = dynamic_cast<const Rubber*> ( lhsEntity );
const Rubber* rhsRubber = dynamic_cast<const Rubber*> ( rhsEntity );
if ( lhsRubber && rhsRubber ) return lhs < rhs; // lhs & rhs are Rubbers.
if ( lhsRubber && !rhsRubber ) return true; // lhs only is an Rubber.
if ( !lhsRubber && rhsRubber ) return false; // rhs only is an Rubber.
const Rubber* lhsRubber = dynamic_cast<const Rubber*>( lhsEntity );
const Rubber* rhsRubber = dynamic_cast<const Rubber*>( rhsEntity );
if ( lhsRubber and rhsRubber) return lhs < rhs; // lhs & rhs are Rubbers.
if ( lhsRubber and not rhsRubber) return true; // lhs only is an Rubber.
if (not lhsRubber and rhsRubber) return false; // rhs only is an Rubber.
const ExtensionGo* lhsExtensionGo = dynamic_cast<const ExtensionGo*> ( lhsEntity );
const ExtensionGo* rhsExtensionGo = dynamic_cast<const ExtensionGo*> ( rhsEntity );
if ( lhsExtensionGo && rhsExtensionGo ) { // lhs & rhs are ExtensionGos.
if ( lhsExtensionGo->getName() == rhsExtensionGo->getName() )
const ExtensionGo* lhsExtensionGo = dynamic_cast<const ExtensionGo*>( lhsEntity );
const ExtensionGo* rhsExtensionGo = dynamic_cast<const ExtensionGo*>( rhsEntity );
if (lhsExtensionGo and rhsExtensionGo) { // lhs & rhs are ExtensionGos.
if (lhsExtensionGo->getName() == rhsExtensionGo->getName())
return lhs < rhs;
return lhsExtensionGo->getName() < rhsExtensionGo->getName();
}
if ( lhsExtensionGo && !rhsExtensionGo ) return true; // lhs only is an ExtensionGo.
if ( !lhsExtensionGo && rhsExtensionGo ) return false; // rhs only is an ExtensionGo.
if ( lhsExtensionGo and not rhsExtensionGo) return true; // lhs only is an ExtensionGo.
if (not lhsExtensionGo and rhsExtensionGo) return false; // rhs only is an ExtensionGo.
return lhs < rhs;
}
@ -79,7 +79,7 @@ namespace Hurricane {
// Class : "Hurricane::Selector".
const Name Selector::_propertyName = _PName ( "Selector" );
const Name Selector::_propertyName = Name( "Selector" );
Selector::Selector () : PrivateProperty()
@ -88,10 +88,10 @@ namespace Hurricane {
string Selector::_getTypeName () const
{ return _TName("Selector"); }
{ return "Selector"; }
const Name& Selector::getPropertyName ()
const Name& Selector::getPropertyName ()
{ return _propertyName; }
@ -99,30 +99,18 @@ namespace Hurricane {
{ return Selector::getPropertyName(); }
Occurrence Selector::getOccurrence () const
{
DBo* owner = getOwner();
if (!owner) return Occurrence();
Quark* quark = dynamic_cast<Quark*>(owner);
assert ( quark );
return quark->getOccurrence();
}
Selector* Selector::create ( Occurrence& occurrence )
{
if ( !occurrence.isValid() )
throw Error ( "Can't create " + _TName("Selector") + " : invalid occurrence" );
if (not occurrence.isValid())
throw Error( "Selector::create(): Can't create Selector, invalid occurrence" );
if ( occurrence.getProperty(Selector::getPropertyName()) )
throw Error ( "Can't create " + _TName("Selector") + " : already exists" );
if (occurrence.getProperty(Selector::getPropertyName()))
throw Error( "Selector::create(): Can't create Selector, already exists" );
Selector* selector = new Selector();
selector->_postCreate();
occurrence.put ( selector );
occurrence.put( selector );
return selector;
}
@ -130,61 +118,146 @@ namespace Hurricane {
void Selector::_preDestroy()
{
set<CellWidget*>::iterator it = _cellWidgets.begin ();
for ( ; it != _cellWidgets.end() ; it++ )
detachFrom ( *it, true );
for ( auto iwidget : _cellWidgets ) detachFrom( iwidget.first, true );
PrivateProperty::_preDestroy();
}
string Selector::_getString() const
{
return "<" + _TName("Selector") + " " + getString(getOccurrence()) + ">";
return "<Selector " + getString(getOccurrence()) + ">";
}
Record* Selector::_getRecord () const
{
Record* record = PrivateProperty::_getRecord();
if ( record )
if (record)
record->add(getSlot("_cellWidgets", &_cellWidgets));
return record;
}
const Quark* Selector::getQuark () const
{
const Quark* owner = dynamic_cast<const Quark*>( getOwner() );
if (not owner) {
cerr << Error( "Selector::getQuark(): Selector Property is not owned by a Quark." ) << endl;
return NULL;
}
return owner;
}
Occurrence Selector::getOccurrence () const
{
const Quark* quark = getQuark();
return (quark) ? quark->getOccurrence() : Occurrence();
}
Path Selector::getPath () const
{
const Quark* quark = getQuark();
return (quark) ? quark->getOccurrence().getPath() : Path();
}
Entity* Selector::getEntity () const
{
const Quark* quark = getQuark();
return (quark) ? quark->getOccurrence().getEntity() : NULL;
}
bool Selector::isAttachedTo ( CellWidget* widget ) const
{
if ( !widget )
throw Error ( "Can't attach selector : null CellWidget." );
if (not widget)
throw Error( "Selector::isAttachedTo(): NULL widget argument." );
if ( _cellWidgets.find(widget) == _cellWidgets.end() )
return false;
return true;
return (_cellWidgets.find(widget) != _cellWidgets.end());
}
void Selector::attachTo ( CellWidget* widget )
{
if ( !widget )
throw Error ( "Can't attach selector : null CellWidget." );
if (not widget)
throw Error( "Selector::attachTo(): Cannot attach, NULL widget argument." );
_cellWidgets.insert ( widget );
widget->getSelectorSet().insert ( this );
_cellWidgets.insert( make_pair(widget,0) );
widget->getSelectorSet().insert( this );
}
void Selector::detachFrom ( CellWidget* widget, bool inDeletion )
{
if ( !widget )
throw Error ( "Can't detach selector : null CellWidget" );
if (not widget)
throw Error( "Selector::detachFrom(): Cannot detach, NULL widget argument." );
widget->getSelectorSet().erase ( this );
_cellWidgets.erase ( widget );
widget->detach( this );
_cellWidgets.erase( widget );
if ( !inDeletion && _cellWidgets.empty() ) destroy();
if (not inDeletion and _cellWidgets.empty()) destroy();
}
uint32_t Selector::getFlags ( CellWidget* widget ) const
{
map<CellWidget*,uint32_t>::const_iterator iw = _cellWidgets.find( widget );
if (iw == _cellWidgets.end()) {
cerr << Error( "Selector::getFlags(): %s is not attached to %s."
, getString(this).c_str()
, getString(widget).c_str()
) << endl;
return 0;
}
return (*iw).second;
}
void Selector::setFlags ( CellWidget* widget , uint32_t flags )
{
map<CellWidget*,uint32_t>::iterator iw = _cellWidgets.find( widget );
if (iw == _cellWidgets.end()) {
cerr << Error( "Selector::setFlags(): %s is not attached to %s."
, getString(this).c_str()
, getString(widget).c_str()
) << endl;
return;
}
(*iw).second |= flags;
}
void Selector::resetFlags ( CellWidget* widget , uint32_t flags )
{
map<CellWidget*,uint32_t>::iterator iw = _cellWidgets.find( widget );
if (iw == _cellWidgets.end()) {
cerr << Error( "Selector::resetFlags(): %s is not attached to %s."
, getString(this).c_str()
, getString(widget).c_str()
) << endl;
return;
}
(*iw).second &= ~flags;
}
void Selector::toggle ( CellWidget* widget )
{
map<CellWidget*,uint32_t>::iterator iw = _cellWidgets.find( widget );
if (iw == _cellWidgets.end()) {
cerr << Error( "Selector::toggle(): %s is not attached to %s."
, getString(this).c_str()
, getString(widget).c_str()
) << endl;
return;
}
if ((*iw).second & Selected) (*iw).second &= ~Selected;
else (*iw).second |= Selected;
(*iw).second |= ToggledByController;
}

View File

@ -141,6 +141,7 @@ namespace Hurricane {
void doGoto ();
void changeSelectionMode ();
void setShowSelection ( bool );
void setCumulativeSelection ( bool );
void setState ( shared_ptr<CellWidget::State>& );
void removeHistory ( Cell* );
void openHistoryCell ();

View File

@ -135,6 +135,7 @@ namespace Hurricane {
inline Query::Mask getQueryFilter () const ;
void bindToPalette ( PaletteWidget* );
void detachFromPalette ();
void detach ( Selector*);
void bindCommand ( Command* );
void unbindCommand ( Command* );
void resetCommands ();
@ -249,7 +250,8 @@ namespace Hurricane {
void mousePositionChanged ( const Point& position );
void selectionModeChanged ();
void selectionChanged ( const SelectorSet& );
void selectionToggled ( Occurrence );
void selectionToggled ( Selector* );
void unlinkSelector ( Selector* );
void showBoundariesToggled ( bool );
protected:
virtual void paintEvent ( QPaintEvent* );

View File

@ -8,66 +8,28 @@
// | 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 |
// | E-mail : Jean-Paul.Chaput@lip6.fr |
// | =============================================================== |
// | C++ Header : "./SelectionModel.h" |
// | C++ Header : "./hurricane/viewer/SelectionModel.h" |
// +-----------------------------------------------------------------+
#ifndef HURRICANE_SELECTION_MODEL_H
#define HURRICANE_SELECTION_MODEL_H
#include <vector>
#include <set>
#include <QFont>
#include <QApplication>
#include <QAbstractTableModel>
#include "hurricane/Commons.h"
#include "hurricane/Occurrence.h"
#include "hurricane/viewer/Graphics.h"
#include "hurricane/viewer/Selector.h"
#include <vector>
#include <QFont>
#include <QApplication>
#include <QAbstractTableModel>
#include "hurricane/Commons.h"
#include "hurricane/Occurrence.h"
#include "hurricane/viewer/Graphics.h"
#include "hurricane/viewer/Selector.h"
namespace Hurricane {
class OccurrenceItem {
public:
enum Flags { Selected=1 };
public:
inline OccurrenceItem ( Occurrence occurrence, unsigned int flags=Selected );
inline void setFlags ( unsigned int );
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::setFlags ( unsigned int flags )
{ _flags |= flags; }
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 CellWidget;
class SelectionModel : public QAbstractTableModel {
@ -76,26 +38,28 @@ namespace Hurricane {
public:
SelectionModel ( QObject* parent=NULL );
~SelectionModel ();
Occurrence getOccurrence ( const QModelIndex& index );
void setCellWidget ( CellWidget* );
Selector* getSelector ( const QModelIndex& index );
void setSelection ( const SelectorSet& selection );
void setSelection ( Occurrence occurrence );
void toggleSelection ( Occurrence occurrence );
Occurrence toggleSelection ( const QModelIndex& index );
void setSelection ( Selector* );
void toggleSelection ( Selector* );
Selector* 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 );
const Selector* getSelector ( int row );
bool isCumulative () const;
public slots:
void unlink ( Selector* );
void clear ();
private:
vector<OccurrenceItem> _selection;
CellWidget* _cellWidget;
vector<Selector*> _selection;
};
} // Hurricane namespace.
#endif // HURRICANE_SELECTION_MODEL_H

View File

@ -1,42 +1,30 @@
// -*- C++ -*-
//
// This file is part of the Coriolis Software.
// Copyright (c) UPMC/LIP6 2008-2018, All Rights Reserved
// Copyright (c) UPMC/LIP6 2008-2019, All Rights Reserved
//
// ===================================================================
//
// $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 |
// | E-mail : Jean-Paul.Chaput@lip6.fr |
// | =============================================================== |
// | C++ Header : "./SelectionWidget.h" |
// | *************************************************************** |
// | U p d a t e s |
// | |
// x-----------------------------------------------------------------x
// | C++ Header : "./hurricane/viewer/SelectionWidget.h" |
// +-----------------------------------------------------------------+
#ifndef __HURRICANE_SELECTION_WIDGET__
#define __HURRICANE_SELECTION_WIDGET__
#ifndef HURRICANE_SELECTION_WIDGET_H
#define HURRICANE_SELECTION_WIDGET_H
#include <QWidget>
#include <QTableView>
#include <QSortFilterProxyModel>
#include "hurricane/Commons.h"
#include "hurricane/Occurrence.h"
#include "hurricane/viewer/SelectionModel.h"
#include "hurricane/viewer/CellWidget.h"
class QCloseEvent;
class QSortFilterProxyModel;
class QModelIndex;
@ -49,7 +37,6 @@ class QCheckBox;
namespace Hurricane {
class Selector;
@ -62,7 +49,7 @@ namespace Hurricane {
bool cumulativeSelection () const;
signals:
void selectionModeChanged ();
void selectionToggled ( Occurrence );
void selectionToggled ( Selector* );
void inspect ( Record* );
void inspect ( Occurrence& );
public slots:
@ -73,9 +60,9 @@ namespace Hurricane {
void setCumulativeSelection ( bool );
void selectCurrent ( const QModelIndex& current, const QModelIndex& );
void setSelection ( const SelectorSet& selection );
void setSelection ( Occurrence );
void setSelection ( Selector* );
void toggleSelection ();
void toggleSelection ( Occurrence );
void toggleSelection ( Selector* );
void toggleSelection ( const QModelIndex& );
void inspect ();
private slots:
@ -83,7 +70,6 @@ namespace Hurricane {
//void dataChanged ( const QModelIndex&, const QModelIndex& );
protected:
void blockAllSignals ( bool );
private:
CellWidget* _cellWidget;
SelectionModel* _baseModel;
@ -97,7 +83,6 @@ namespace Hurricane {
};
} // End of Hurricane namespace.
} // Hurricane namespace.
#endif // __HURRICANE_SELECTION_WIDGET__
#endif // HURRICANE_SELECTION_WIDGET_H

View File

@ -34,27 +34,41 @@ namespace Hurricane {
class Selector : public PrivateProperty {
public:
enum Flags { InModel = (1<<0)
, Selected = (1<<1)
, ToggledByController = (1<<2)
};
public:
// Constructor.
static Selector* create ( Occurrence& occurrence );
// Methods.
static const Name& getPropertyName ();
virtual Name getName () const;
Occurrence getOccurrence () const;
inline set<CellWidget*>& getCellWidgetSet ();
bool isAttachedTo ( CellWidget* ) const;
void attachTo ( CellWidget* );
void detachFrom ( CellWidget* , bool inDeletion=false );
// Inspector Managment.
virtual string _getTypeName () const;
virtual string _getString () const;
virtual Record* _getRecord () const;
static Selector* create ( Occurrence& occurrence );
// Methods.
static const Name& getPropertyName ();
virtual Name getName () const;
const Quark* getQuark () const;
Occurrence getOccurrence () const;
Path getPath () const;
Entity* getEntity () const;
inline map<CellWidget*,uint32_t>& getCellWidgetSet ();
inline bool isSelected ( CellWidget* ) const;
inline bool isInModel ( CellWidget* ) const;
inline bool isToggleByController ( CellWidget* ) const;
bool isAttachedTo ( CellWidget* ) const;
void attachTo ( CellWidget* );
void detachFrom ( CellWidget* , bool inDeletion=false );
uint32_t getFlags ( CellWidget* ) const;
void setFlags ( CellWidget* , uint32_t );
void resetFlags ( CellWidget* , uint32_t );
void toggle ( CellWidget* );
// Inspector Managment.
virtual string _getTypeName () const;
virtual string _getString () const;
virtual Record* _getRecord () const;
protected:
// Internal: Attributes.
static const Name _propertyName;
set<CellWidget*> _cellWidgets;
static const Name _propertyName;
map<CellWidget*,uint32_t> _cellWidgets;
protected:
// Internal: Constructor.
@ -64,8 +78,10 @@ namespace Hurricane {
// Inline Functions.
inline set<CellWidget*>& Selector::getCellWidgetSet () { return _cellWidgets; }
inline map<CellWidget*,uint32_t>& Selector::getCellWidgetSet () { return _cellWidgets; }
inline bool Selector::isInModel ( CellWidget* w ) const { return getFlags(w) & InModel ; }
inline bool Selector::isSelected ( CellWidget* w ) const { return getFlags(w) & Selected; }
inline bool Selector::isToggleByController ( CellWidget* w ) const { return getFlags(w) & ToggledByController; }
typedef set<Selector*,SelectorLess> SelectorSet;