Anabatic transient commit 3.

* New: In Anabatic:
    - AnabaticEngine now have a valid destructor and a "reset()" method.
This commit is contained in:
Jean-Paul Chaput 2016-05-26 18:30:03 +02:00
parent a4655aec8b
commit d7bd8a4bf4
8 changed files with 146 additions and 90 deletions

View File

@ -61,6 +61,9 @@ namespace Anabatic {
: Super(cell) : Super(cell)
, _configuration (new ConfigurationConcrete()) , _configuration (new ConfigurationConcrete())
, _matrix () , _matrix ()
, _gcells ()
, _viewer (NULL)
, _flags (Flags::NoFlags)
{ {
_matrix.setCell( cell, _configuration->getSliceHeight()*2 ); _matrix.setCell( cell, _configuration->getSliceHeight()*2 );
} }
@ -90,20 +93,27 @@ namespace Anabatic {
AnabaticEngine::~AnabaticEngine () AnabaticEngine::~AnabaticEngine ()
{ {
while ( not _gcells.empty() ) (*_gcells.rbegin())->destroy();
delete _configuration; delete _configuration;
} }
void AnabaticEngine::_preDestroy () void AnabaticEngine::_preDestroy ()
{ {
// To be done: destroy the whole set of GCells. _clear();
// Must be stored in some way before destruction (in a set<> ?).
Super::_preDestroy(); 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 () Configuration* AnabaticEngine::getConfiguration ()
{ return _configuration; } { 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("_configuration", _configuration) );
record->add( getSlot("_gcells" , &_gcells ) ); record->add( getSlot("_gcells" , &_gcells ) );
record->add( getSlot("_matrix" , &_matrix ) ); record->add( getSlot("_matrix" , &_matrix ) );
record->add( getSlot("_flags" , &_flags ) );
return record; return record;
} }

View File

@ -39,7 +39,7 @@ namespace Anabatic {
s += (_flags & SourceGCell) ? 's' : '-'; s += (_flags & SourceGCell) ? 's' : '-';
s += (_flags & TargetGCell) ? 't' : '-'; s += (_flags & TargetGCell) ? 't' : '-';
s += (_flags & Invalidated) ? 'i' : '-'; s += (_flags & Invalidated) ? 'i' : '-';
s += (_flags & MoveSide ) ? 'M' : '-'; s += (_flags & Destroy ) ? 'D' : '-';
s += (_flags & PitchAbove ) ? 'A' : '-'; s += (_flags & PitchAbove ) ? 'A' : '-';
s += (_flags & PitchBelow ) ? 'B' : '-'; s += (_flags & PitchBelow ) ? 'B' : '-';

View File

@ -75,22 +75,20 @@ namespace Anabatic {
{ } { }
void GCell::_preDestroy () void GCell::_destroyEdges ()
{ {
for ( Edge* edge : _westEdges ) edge->destroy(); while (not _westEdges.empty()) (* _westEdges.rbegin())->destroy();
for ( Edge* edge : _eastEdges ) edge->destroy(); while (not _eastEdges.empty()) (* _eastEdges.rbegin())->destroy();
for ( Edge* edge : _southEdges ) edge->destroy(); while (not _southEdges.empty()) (*_southEdges.rbegin())->destroy();
for ( Edge* edge : _northEdges ) edge->destroy(); while (not _northEdges.empty()) (*_northEdges.rbegin())->destroy();
_anabatic->_remove( this );
Super::_preDestroy();
} }
void GCell::destroy () void GCell::_preDestroy ()
{ {
_preDestroy(); _destroyEdges();
delete this; _anabatic->_remove( this );
Super::_preDestroy();
} }
@ -139,7 +137,7 @@ namespace Anabatic {
_southEdges.insert( iedge, edge ); _southEdges.insert( iedge, edge );
for ( auto iedge2=_southEdges.begin() ; iedge2 != _southEdges.end() ; ++iedge2 ) 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); cdebug.tabw(110,-1);
return; return;
} }
@ -270,7 +268,7 @@ namespace Anabatic {
GCell* chunk = _create( x, getYMin() ); GCell* chunk = _create( x, getYMin() );
cdebug.log(110) << "New chunk:" << chunk << endl; 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 ); Edge::create( this, chunk, Flags::Horizontal );
if (not _southEdges.empty()) { if (not _southEdges.empty()) {
@ -322,7 +320,7 @@ namespace Anabatic {
GCell* chunk = _create( getXMin(), y ); GCell* chunk = _create( getXMin(), y );
cdebug.log(110) << "New chunk:" << chunk << endl; 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 ); Edge::create( this, chunk, Flags::Vertical );
if (not _westEdges.empty()) { if (not _westEdges.empty()) {

View File

@ -58,6 +58,74 @@ namespace Anabatic {
using CRL::AllianceFramework; 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; size_t GraphicAnabaticEngine::_references = 0;
GraphicAnabaticEngine* GraphicAnabaticEngine::_singleton = NULL; GraphicAnabaticEngine* GraphicAnabaticEngine::_singleton = NULL;
@ -184,62 +252,9 @@ namespace Anabatic {
if (_viewer) _viewer->emitCellAboutToChange(); if (_viewer) _viewer->emitCellAboutToChange();
AnabaticEngine* engine = getForFramework( CreateEngine ); AnabaticEngine* engine = getForFramework( CreateEngine );
#define TEST_2 1 //anabaticTest_1( engine );
//anabaticTest_2( engine );
#ifdef TEST_1 anabaticTest_3( 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;
#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);
// }
if (_viewer) _viewer->emitCellChanged(); if (_viewer) _viewer->emitCellChanged();
} }

View File

@ -145,6 +145,7 @@ extern "C" {
} }
#if 0
PyObject* PyAnabaticEngine_runTest ( PyAnabaticEngine* self, PyObject* args ) PyObject* PyAnabaticEngine_runTest ( PyAnabaticEngine* self, PyObject* args )
{ {
cdebug.log(32) << "PyAnabaticEngine_runTest()" << endl; cdebug.log(32) << "PyAnabaticEngine_runTest()" << endl;
@ -169,6 +170,7 @@ extern "C" {
Py_RETURN_NONE; Py_RETURN_NONE;
} }
#endif
// Standart Accessors (Attributes). // Standart Accessors (Attributes).
@ -184,8 +186,10 @@ extern "C" {
, "Create a Anabatic engine on this cell." } , "Create a Anabatic engine on this cell." }
, { "setViewer" , (PyCFunction)PyAnabaticEngine_setViewer , METH_VARARGS , { "setViewer" , (PyCFunction)PyAnabaticEngine_setViewer , METH_VARARGS
, "Associate a Viewer to this AnabaticEngine." } , "Associate a Viewer to this AnabaticEngine." }
#if 0
, { "runTest" , (PyCFunction)PyAnabaticEngine_runTest , METH_VARARGS , { "runTest" , (PyCFunction)PyAnabaticEngine_runTest , METH_VARARGS
, "Run the test procedure." } , "Run the test procedure." }
#endif
, { "destroy" , (PyCFunction)PyAnabaticEngine_destroy , METH_NOARGS , { "destroy" , (PyCFunction)PyAnabaticEngine_destroy , METH_NOARGS
, "Destroy the associated hurricane object. The python object remains." } , "Destroy the associated hurricane object. The python object remains." }
, {NULL, NULL, 0, NULL} /* sentinel */ , {NULL, NULL, 0, NULL} /* sentinel */

View File

@ -18,6 +18,7 @@
#define ANABATIC_ANABATIC_ENGINE_H #define ANABATIC_ANABATIC_ENGINE_H
#include <string> #include <string>
#include <vector>
namespace Hurricane { namespace Hurricane {
class Name; class Name;
@ -35,6 +36,7 @@ namespace Hurricane {
namespace Anabatic { namespace Anabatic {
using std::string; using std::string;
using std::vector;
using Hurricane::Name; using Hurricane::Name;
using Hurricane::Record; using Hurricane::Record;
using Hurricane::Interval; using Hurricane::Interval;
@ -58,10 +60,13 @@ namespace Anabatic {
inline GCell* getGCellUnder ( DbU::Unit x, DbU::Unit y ) const; inline GCell* getGCellUnder ( DbU::Unit x, DbU::Unit y ) const;
inline GCell* getGCellUnder ( Point ) const; inline GCell* getGCellUnder ( Point ) const;
int getCapacity ( Interval, Flags ) const; int getCapacity ( Interval, Flags ) const;
inline const Flags& flags () const;
inline Flags& flags ();
void reset ();
inline void _add ( GCell* ); inline void _add ( GCell* );
inline void _remove ( GCell* ); inline void _remove ( GCell* );
inline void _updateLookup ( GCell* ); inline void _updateLookup ( GCell* );
void _runTest (); inline bool _inDestroy () const;
// Inspector support. // Inspector support.
virtual Record* _getRecord () const; virtual Record* _getRecord () const;
virtual string _getString () const; virtual string _getString () const;
@ -71,6 +76,7 @@ namespace Anabatic {
virtual ~AnabaticEngine (); virtual ~AnabaticEngine ();
virtual void _postCreate (); virtual void _postCreate ();
virtual void _preDestroy (); virtual void _preDestroy ();
void _clear ();
private: private:
AnabaticEngine ( const AnabaticEngine& ); AnabaticEngine ( const AnabaticEngine& );
AnabaticEngine& operator= ( const AnabaticEngine& ); AnabaticEngine& operator= ( const AnabaticEngine& );
@ -78,20 +84,37 @@ namespace Anabatic {
static Name _toolName; static Name _toolName;
Configuration* _configuration; Configuration* _configuration;
Matrix _matrix; Matrix _matrix;
GCellSet _gcells; vector<GCell*> _gcells;
CellViewer* _viewer; CellViewer* _viewer;
Flags _flags;
}; };
inline CellViewer* AnabaticEngine::getViewer () const { return _viewer; } inline CellViewer* AnabaticEngine::getViewer () const { return _viewer; }
inline void AnabaticEngine::setViewer ( CellViewer* viewer ) { _viewer=viewer; } inline void AnabaticEngine::setViewer ( CellViewer* viewer ) { _viewer=viewer; }
inline GCell* AnabaticEngine::getSouthWestGCell () const { return *(_gcells.begin()); } 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 ( DbU::Unit x, DbU::Unit y ) const { return _matrix.getUnder(x,y); }
inline GCell* AnabaticEngine::getGCellUnder ( Point p ) const { return _matrix.getUnder(p); } inline GCell* AnabaticEngine::getGCellUnder ( Point p ) const { return _matrix.getUnder(p); }
inline void AnabaticEngine::_add ( GCell* gcell ) { _gcells.insert(gcell); } inline const Flags& AnabaticEngine::flags () const { return _flags; }
inline void AnabaticEngine::_remove ( GCell* gcell ) { _gcells.erase(gcell); } inline Flags& AnabaticEngine::flags () { return _flags; }
inline void AnabaticEngine::_updateLookup ( GCell* gcell ) { _matrix.updateLookup(gcell); } 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. } // Anabatic namespace.

View File

@ -29,8 +29,8 @@ namespace Anabatic {
, Vertical = (1<<1) , Vertical = (1<<1)
, SourceGCell = (1<<2) , SourceGCell = (1<<2)
, TargetGCell = (1<<3) , TargetGCell = (1<<3)
, MoveSide = (1<<4) , Invalidated = (1<<4)
, Invalidated = (1<<5) , Destroy = (1<<5)
, WestSide = Horizontal|TargetGCell , WestSide = Horizontal|TargetGCell
, EastSide = Horizontal|SourceGCell , EastSide = Horizontal|SourceGCell
, SouthSide = Vertical |TargetGCell , SouthSide = Vertical |TargetGCell

View File

@ -53,7 +53,6 @@ namespace Anabatic {
static Box getBorder ( const GCell*, const GCell* ); static Box getBorder ( const GCell*, const GCell* );
public: public:
static GCell* create ( AnabaticEngine* ); static GCell* create ( AnabaticEngine* );
virtual void destroy ();
public: public:
inline bool isHFlat () const; inline bool isHFlat () const;
inline bool isVFlat () const; inline bool isVFlat () const;
@ -81,6 +80,7 @@ namespace Anabatic {
inline Flags& flags (); inline Flags& flags ();
void _add ( Edge* edge, Flags side ); void _add ( Edge* edge, Flags side );
void _remove ( Edge* edge, Flags side=Flags::AllSides ); void _remove ( Edge* edge, Flags side=Flags::AllSides );
void _destroyEdges ();
private: private:
void _revalidate (); void _revalidate ();
void _moveEdges ( GCell* dest, size_t ibegin, Flags flags ); void _moveEdges ( GCell* dest, size_t ibegin, Flags flags );