Anabatic transient commit 3.
* New: In Anabatic: - AnabaticEngine now have a valid destructor and a "reset()" method.
This commit is contained in:
parent
a4655aec8b
commit
d7bd8a4bf4
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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' : '-';
|
||||
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#define ANABATIC_ANABATIC_ENGINE_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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<GCell*> _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.
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Reference in New Issue