From d7bd8a4bf446028a744d8049e4d9324104e2e69f Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Thu, 26 May 2016 18:30:03 +0200 Subject: [PATCH] Anabatic transient commit 3. * New: In Anabatic: - AnabaticEngine now have a valid destructor and a "reset()" method. --- anabatic/src/AnabaticEngine.cpp | 28 ++++-- anabatic/src/Constants.cpp | 2 +- anabatic/src/GCell.cpp | 26 +++-- anabatic/src/GraphicAnabaticEngine.cpp | 127 ++++++++++++++----------- anabatic/src/PyAnabaticEngine.cpp | 4 + anabatic/src/anabatic/AnabaticEngine.h | 43 +++++++-- anabatic/src/anabatic/Constants.h | 4 +- anabatic/src/anabatic/GCell.h | 2 +- 8 files changed, 146 insertions(+), 90 deletions(-) diff --git a/anabatic/src/AnabaticEngine.cpp b/anabatic/src/AnabaticEngine.cpp index da32a645..81321562 100644 --- a/anabatic/src/AnabaticEngine.cpp +++ b/anabatic/src/AnabaticEngine.cpp @@ -61,6 +61,9 @@ namespace Anabatic { : Super(cell) , _configuration (new ConfigurationConcrete()) , _matrix () + , _gcells () + , _viewer (NULL) + , _flags (Flags::NoFlags) { _matrix.setCell( cell, _configuration->getSliceHeight()*2 ); } @@ -90,20 +93,27 @@ namespace Anabatic { AnabaticEngine::~AnabaticEngine () { - while ( not _gcells.empty() ) (*_gcells.rbegin())->destroy(); delete _configuration; } void AnabaticEngine::_preDestroy () { - // To be done: destroy the whole set of GCells. - // Must be stored in some way before destruction (in a set<> ?). - + _clear(); Super::_preDestroy(); } + void AnabaticEngine::_clear () + { + _flags |= Flags::Destroy; + + for ( GCell* gcell : _gcells ) gcell->_destroyEdges(); + for ( GCell* gcell : _gcells ) gcell->destroy(); + _gcells.clear(); + } + + Configuration* AnabaticEngine::getConfiguration () { return _configuration; } @@ -137,9 +147,14 @@ namespace Anabatic { } - void AnabaticEngine::_runTest () + void AnabaticEngine::reset () { - cerr << "AnabaticEngine::_runTest() called." << endl; + _clear(); + _flags.reset( Flags::Destroy ); + + UpdateSession::open(); + GCell::create( this ); + UpdateSession::close(); } @@ -161,6 +176,7 @@ namespace Anabatic { record->add( getSlot("_configuration", _configuration) ); record->add( getSlot("_gcells" , &_gcells ) ); record->add( getSlot("_matrix" , &_matrix ) ); + record->add( getSlot("_flags" , &_flags ) ); return record; } diff --git a/anabatic/src/Constants.cpp b/anabatic/src/Constants.cpp index cd72bf44..01072dfb 100644 --- a/anabatic/src/Constants.cpp +++ b/anabatic/src/Constants.cpp @@ -39,7 +39,7 @@ namespace Anabatic { s += (_flags & SourceGCell) ? 's' : '-'; s += (_flags & TargetGCell) ? 't' : '-'; s += (_flags & Invalidated) ? 'i' : '-'; - s += (_flags & MoveSide ) ? 'M' : '-'; + s += (_flags & Destroy ) ? 'D' : '-'; s += (_flags & PitchAbove ) ? 'A' : '-'; s += (_flags & PitchBelow ) ? 'B' : '-'; diff --git a/anabatic/src/GCell.cpp b/anabatic/src/GCell.cpp index 5ee25582..ebe70e36 100644 --- a/anabatic/src/GCell.cpp +++ b/anabatic/src/GCell.cpp @@ -75,22 +75,20 @@ namespace Anabatic { { } - void GCell::_preDestroy () + void GCell::_destroyEdges () { - for ( Edge* edge : _westEdges ) edge->destroy(); - for ( Edge* edge : _eastEdges ) edge->destroy(); - for ( Edge* edge : _southEdges ) edge->destroy(); - for ( Edge* edge : _northEdges ) edge->destroy(); - - _anabatic->_remove( this ); - Super::_preDestroy(); + while (not _westEdges.empty()) (* _westEdges.rbegin())->destroy(); + while (not _eastEdges.empty()) (* _eastEdges.rbegin())->destroy(); + while (not _southEdges.empty()) (*_southEdges.rbegin())->destroy(); + while (not _northEdges.empty()) (*_northEdges.rbegin())->destroy(); } - void GCell::destroy () + void GCell::_preDestroy () { - _preDestroy(); - delete this; + _destroyEdges(); + _anabatic->_remove( this ); + Super::_preDestroy(); } @@ -139,7 +137,7 @@ namespace Anabatic { _southEdges.insert( iedge, edge ); for ( auto iedge2=_southEdges.begin() ; iedge2 != _southEdges.end() ; ++iedge2 ) - cdebug.log(110) << "| @" << DbU::getValueString((*iedge)->getAxisMin()) << " " << *iedge2 << endl; + cdebug.log(110) << "| @" << DbU::getValueString((*iedge2)->getAxisMin()) << " " << *iedge2 << endl; cdebug.tabw(110,-1); return; } @@ -270,7 +268,7 @@ namespace Anabatic { GCell* chunk = _create( x, getYMin() ); cdebug.log(110) << "New chunk:" << chunk << endl; - _moveEdges( chunk, 0, Flags::EastSide|Flags::MoveSide ); + _moveEdges( chunk, 0, Flags::EastSide ); Edge::create( this, chunk, Flags::Horizontal ); if (not _southEdges.empty()) { @@ -322,7 +320,7 @@ namespace Anabatic { GCell* chunk = _create( getXMin(), y ); cdebug.log(110) << "New chunk:" << chunk << endl; - _moveEdges( chunk, 0, Flags::NorthSide|Flags::MoveSide ); + _moveEdges( chunk, 0, Flags::NorthSide ); Edge::create( this, chunk, Flags::Vertical ); if (not _westEdges.empty()) { diff --git a/anabatic/src/GraphicAnabaticEngine.cpp b/anabatic/src/GraphicAnabaticEngine.cpp index ef3861bf..34e8bb8e 100644 --- a/anabatic/src/GraphicAnabaticEngine.cpp +++ b/anabatic/src/GraphicAnabaticEngine.cpp @@ -56,7 +56,75 @@ namespace Anabatic { using Hurricane::ExceptionWidget; using CRL::Catalog; using CRL::AllianceFramework; + +// ------------------------------------------------------------------- +// Test functions. + + void anabaticTest_1 ( AnabaticEngine* engine ) + { + engine->getSouthWestGCell()->doGrid(); + + Point position ( DbU::fromLambda(100.0), DbU::fromLambda(100.0) ); + GCell* gcell = engine->getGCellUnder( position ); + + cerr << "Gcell under:" << position << " is " << gcell << endl; + } + + + void anabaticTest_2 ( AnabaticEngine* engine ) + { + GCell* row0 = engine->getSouthWestGCell(); + DbU::Unit xcorner = engine->getCell()->getAbutmentBox().getXMin(); + DbU::Unit ycorner = engine->getCell()->getAbutmentBox().getYMin(); + + cdebug.log(119,1) << "row0: " << row0 << endl; + + GCell* row1 = row0->hcut( ycorner+DbU::fromLambda(50.0) ); + cdebug.tabw(119,-1); + cdebug.log(119,1) << "row1: " << row1 << endl; + + GCell* row2 = row1->hcut( ycorner+DbU::fromLambda(2*50.0) ); + cdebug.tabw(119,-1); + cdebug.log(119,1) << "row2: " << row2 << endl; + + row0 = row0->vcut( xcorner+DbU::fromLambda(50.0) ); + cdebug.tabw(119,-1); + cdebug.log(119,1) << "row0+1: " << row0 << endl; + + row0 = row0->vcut( xcorner+DbU::fromLambda(3*50.0) ); + cdebug.tabw(119,-1); + cdebug.log(119,1) << "row0+2: " << row0 << endl; + + row0 = row0->vcut( xcorner+DbU::fromLambda(5*50.0) ); + cdebug.tabw(119,-1); + cdebug.log(119,1) << "row0+3: " << row0 << endl; + + row1 = row1->vcut( xcorner+DbU::fromLambda(2*50.0) ); + cdebug.tabw(119,-1); + cdebug.log(119,1) << "row1+1: " << row1 << endl; + + cdebug.tabw(119,-1); + } + + + void anabaticTest_3 ( AnabaticEngine* engine ) + { + for ( int i=0 ; i<4 ; ++i ) { + cdebug.log(110,1) << "Running test 3, loop:" << i << " ..." << endl; + + if ( i%2) anabaticTest_1( engine ); + else anabaticTest_2( engine ); + + engine->reset(); + cdebug.log(110,1) << "Test 3, loop:" << i << " completed." << endl; + cdebug.tabw(110,-1); + } + } + + +// ------------------------------------------------------------------- +// Class : "Anabatic::GraphicAnabaticEngine". size_t GraphicAnabaticEngine::_references = 0; GraphicAnabaticEngine* GraphicAnabaticEngine::_singleton = NULL; @@ -184,62 +252,9 @@ namespace Anabatic { if (_viewer) _viewer->emitCellAboutToChange(); AnabaticEngine* engine = getForFramework( CreateEngine ); -#define TEST_2 1 - -#ifdef TEST_1 - engine->getSouthWestGCell()->doGrid(); - - Point position ( DbU::fromLambda(100.0), DbU::fromLambda(100.0) ); - GCell* gcell = engine->getGCellUnder( position ); - - cerr << "Gcell under:" << position << " is " << gcell << endl; -#endif - -#ifdef TEST_2 - GCell* row0 = engine->getSouthWestGCell(); - DbU::Unit xcorner = getCell()->getAbutmentBox().getXMin(); - DbU::Unit ycorner = getCell()->getAbutmentBox().getYMin(); - - cdebug.log(119,1) << "row0: " << row0 << endl; - - GCell* row1 = row0->hcut( ycorner+DbU::fromLambda(50.0) ); - cdebug.tabw(119,-1); - cdebug.log(119,1) << "row1: " << row1 << endl; - - GCell* row2 = row1->hcut( ycorner+DbU::fromLambda(2*50.0) ); - cdebug.tabw(119,-1); - cdebug.log(119,1) << "row2: " << row2 << endl; - - row0 = row0->vcut( xcorner+DbU::fromLambda(50.0) ); - cdebug.tabw(119,-1); - cdebug.log(119,1) << "row0+1: " << row0 << endl; - - row0 = row0->vcut( xcorner+DbU::fromLambda(3*50.0) ); - cdebug.tabw(119,-1); - cdebug.log(119,1) << "row0+2: " << row0 << endl; - - row0 = row0->vcut( xcorner+DbU::fromLambda(5*50.0) ); - cdebug.tabw(119,-1); - cdebug.log(119,1) << "row0+3: " << row0 << endl; - - row1 = row1->vcut( xcorner+DbU::fromLambda(2*50.0) ); - cdebug.tabw(119,-1); - cdebug.log(119,1) << "row1+1: " << row1 << endl; - - - cdebug.tabw(119,-1); -#endif - - // gcell = gcell->hcut( ycut+DbU::fromLambda(50.0) ); - // cerr << "New GCell: " << gcell << endl; - - // DbU::Unit ycut = getCell()->getAbutmentBox().getYMin() + DbU::fromLambda(50.0); - // for ( ; ycut < getCell()->getAbutmentBox().getYMax() ; ycut += DbU::fromLambda(50.0) ) { - // cdebug.log(119,2) << "H cut line (y coordinate): " << DbU::getValueString(ycut) << endl; - // gcell = gcell->hcut( ycut ); - // cerr << gcell << endl; - // cdebug.tabw(119,-2); - // } + //anabaticTest_1( engine ); + //anabaticTest_2( engine ); + anabaticTest_3( engine ); if (_viewer) _viewer->emitCellChanged(); } diff --git a/anabatic/src/PyAnabaticEngine.cpp b/anabatic/src/PyAnabaticEngine.cpp index 3fe9d06f..b5ac08e2 100644 --- a/anabatic/src/PyAnabaticEngine.cpp +++ b/anabatic/src/PyAnabaticEngine.cpp @@ -145,6 +145,7 @@ extern "C" { } +#if 0 PyObject* PyAnabaticEngine_runTest ( PyAnabaticEngine* self, PyObject* args ) { cdebug.log(32) << "PyAnabaticEngine_runTest()" << endl; @@ -169,6 +170,7 @@ extern "C" { Py_RETURN_NONE; } +#endif // Standart Accessors (Attributes). @@ -184,8 +186,10 @@ extern "C" { , "Create a Anabatic engine on this cell." } , { "setViewer" , (PyCFunction)PyAnabaticEngine_setViewer , METH_VARARGS , "Associate a Viewer to this AnabaticEngine." } +#if 0 , { "runTest" , (PyCFunction)PyAnabaticEngine_runTest , METH_VARARGS , "Run the test procedure." } +#endif , { "destroy" , (PyCFunction)PyAnabaticEngine_destroy , METH_NOARGS , "Destroy the associated hurricane object. The python object remains." } , {NULL, NULL, 0, NULL} /* sentinel */ diff --git a/anabatic/src/anabatic/AnabaticEngine.h b/anabatic/src/anabatic/AnabaticEngine.h index e633d076..b492169f 100644 --- a/anabatic/src/anabatic/AnabaticEngine.h +++ b/anabatic/src/anabatic/AnabaticEngine.h @@ -18,6 +18,7 @@ #define ANABATIC_ANABATIC_ENGINE_H #include +#include namespace Hurricane { class Name; @@ -35,6 +36,7 @@ namespace Hurricane { namespace Anabatic { using std::string; + using std::vector; using Hurricane::Name; using Hurricane::Record; using Hurricane::Interval; @@ -58,10 +60,13 @@ namespace Anabatic { inline GCell* getGCellUnder ( DbU::Unit x, DbU::Unit y ) const; inline GCell* getGCellUnder ( Point ) const; int getCapacity ( Interval, Flags ) const; + inline const Flags& flags () const; + inline Flags& flags (); + void reset (); inline void _add ( GCell* ); inline void _remove ( GCell* ); inline void _updateLookup ( GCell* ); - void _runTest (); + inline bool _inDestroy () const; // Inspector support. virtual Record* _getRecord () const; virtual string _getString () const; @@ -71,6 +76,7 @@ namespace Anabatic { virtual ~AnabaticEngine (); virtual void _postCreate (); virtual void _preDestroy (); + void _clear (); private: AnabaticEngine ( const AnabaticEngine& ); AnabaticEngine& operator= ( const AnabaticEngine& ); @@ -78,20 +84,37 @@ namespace Anabatic { static Name _toolName; Configuration* _configuration; Matrix _matrix; - GCellSet _gcells; + vector _gcells; CellViewer* _viewer; + Flags _flags; }; - inline CellViewer* AnabaticEngine::getViewer () const { return _viewer; } - inline void AnabaticEngine::setViewer ( CellViewer* viewer ) { _viewer=viewer; } - inline GCell* AnabaticEngine::getSouthWestGCell () const { return *(_gcells.begin()); } - inline GCell* AnabaticEngine::getGCellUnder ( DbU::Unit x, DbU::Unit y ) const { return _matrix.getUnder(x,y); } - inline GCell* AnabaticEngine::getGCellUnder ( Point p ) const { return _matrix.getUnder(p); } - inline void AnabaticEngine::_add ( GCell* gcell ) { _gcells.insert(gcell); } - inline void AnabaticEngine::_remove ( GCell* gcell ) { _gcells.erase(gcell); } - inline void AnabaticEngine::_updateLookup ( GCell* gcell ) { _matrix.updateLookup(gcell); } + inline CellViewer* AnabaticEngine::getViewer () const { return _viewer; } + inline void AnabaticEngine::setViewer ( CellViewer* viewer ) { _viewer=viewer; } + inline GCell* AnabaticEngine::getSouthWestGCell () const { return _gcells[0]; } + inline GCell* AnabaticEngine::getGCellUnder ( DbU::Unit x, DbU::Unit y ) const { return _matrix.getUnder(x,y); } + inline GCell* AnabaticEngine::getGCellUnder ( Point p ) const { return _matrix.getUnder(p); } + inline const Flags& AnabaticEngine::flags () const { return _flags; } + inline Flags& AnabaticEngine::flags () { return _flags; } + inline void AnabaticEngine::_updateLookup ( GCell* gcell ) { _matrix.updateLookup(gcell); } + inline bool AnabaticEngine::_inDestroy () const { return _flags & Flags::Destroy; } + inline void AnabaticEngine::_add ( GCell* gcell ) + { + _gcells.push_back( gcell ); + std::sort( _gcells.begin(), _gcells.end(), Entity::CompareById() ); + } + + inline void AnabaticEngine::_remove ( GCell* gcell ) + { + for ( auto igcell = _gcells.begin() ; igcell != _gcells.end() ; ++igcell ) + if (*igcell == gcell) { + if (_inDestroy()) (*igcell) = NULL; + else _gcells.erase(igcell); + break; + } + } } // Anabatic namespace. diff --git a/anabatic/src/anabatic/Constants.h b/anabatic/src/anabatic/Constants.h index 509c5498..d3ccde41 100644 --- a/anabatic/src/anabatic/Constants.h +++ b/anabatic/src/anabatic/Constants.h @@ -29,8 +29,8 @@ namespace Anabatic { , Vertical = (1<<1) , SourceGCell = (1<<2) , TargetGCell = (1<<3) - , MoveSide = (1<<4) - , Invalidated = (1<<5) + , Invalidated = (1<<4) + , Destroy = (1<<5) , WestSide = Horizontal|TargetGCell , EastSide = Horizontal|SourceGCell , SouthSide = Vertical |TargetGCell diff --git a/anabatic/src/anabatic/GCell.h b/anabatic/src/anabatic/GCell.h index 93fb0459..5b2955cd 100644 --- a/anabatic/src/anabatic/GCell.h +++ b/anabatic/src/anabatic/GCell.h @@ -53,7 +53,6 @@ namespace Anabatic { static Box getBorder ( const GCell*, const GCell* ); public: static GCell* create ( AnabaticEngine* ); - virtual void destroy (); public: inline bool isHFlat () const; inline bool isVFlat () const; @@ -81,6 +80,7 @@ namespace Anabatic { inline Flags& flags (); void _add ( Edge* edge, Flags side ); void _remove ( Edge* edge, Flags side=Flags::AllSides ); + void _destroyEdges (); private: void _revalidate (); void _moveEdges ( GCell* dest, size_t ibegin, Flags flags );