59 for( current = m_memory; current; current = next )
61 next = current->m_next;
79 m_freelist = m_freelist->
m_next;
81 else if( m_freememory < AllocBlock::m_pointsperblock )
84 newobjc = m_memory->m_memory + m_freememory;
91 newblock->m_next = m_memory;
93 newobjc = m_memory->m_memory;
100 wxASSERT( brdr.
m_cost - m_mincost < m_ncost );
102 int index = brdr.
m_cost & m_costmask;
103 newobjc->
m_next = m_costring[index];
104 m_costring[index] = newobjc;
106 if( !m_costring[ m_mincostindex ] )
110 wxASSERT( m_mincostindex == 0 && m_mincost == 0 );
112 m_mincostindex = index;
128 m_costring[ m_mincostindex ] = obj->
m_next;
133 if( !m_costring[ m_mincostindex ] )
136 for( i = m_mincostindex; i < m_ncost; i++ )
138 if( m_costring[ i ] )
142 for( i = 0; i < m_mincostindex; i++ )
144 if( m_costring[ i ] )
158 wxASSERT( m_costring[ m_mincostindex ] );
159 wxASSERT( m_costring[ m_mincostindex ]->m_cost > m_mincost );
160 wxASSERT( ( m_costring[ m_mincostindex ]->m_cost & m_costmask ) == m_mincostindex );
161 m_mincost = m_costring[ m_mincostindex ]->m_cost;
171 m_dump = fopen(
"Routerdump.txt",
"w" );
181 a2dCanvasObjectList::iterator iter;
194 if( !
final && editcopy )
219 if( m_rastermaxy - m_rasterminy > 10000 )
228 m_height = m_rastermaxy - m_rasterminy;
258 if( !
final && editcopy )
283 fprintf( m_dump,
"Route init\n" );
303 int nextx,
int nexty,
310 wxASSERT( nextx >= 0 && nextx <=
m_width );
311 wxASSERT( nexty >= 0 && nexty <=
m_height );
316 if( next->
m_flags & flag_reachable )
336 if( next->
m_flags & flag_original )
350 !( ( current->
m_flags & flag_original ) && ( next->
m_flags & flag_original ) ) &&
364 queue->
Add( border );
399 fprintf( m_dump,
"Route Final 1 %p %d\n", wire, wire->
GetSegments()->GetCount() );
438 if ( maxDisLocated && maxDisLocated->
IsInternal() )
475 startisbegin = !startisbegin;
515 int y1 = ( int ) floor( targetpos.m_y *
m_rasterinv ) - m_rasterminy;
517 int y2 = ( int ) ceil( targetpos.m_y *
m_rasterinv ) - m_rasterminy;
527 fprintf( m_dump,
"Route Final 2 %p %d\n", wire, wire->
GetSegments()->GetCount() );
538 startpos = startisbegin ? wire->
GetSegments()->front()->GetPoint() : wire->
GetSegments()->back()->GetPoint();
547 int starty = ( int ) floor( ( startpos.m_y + 0.5 *
m_raster ) *
m_rasterinv ) - m_rasterminy;
574 if( point->
m_flags & flag_reachable )
582 point->m_y = border.m_y;
588 if( point->
m_flags & ( flag_targetwire | flag_targetpin | flag_targetapprox ) )
622 point->
m_flags |= flag_reachable;
634 point->
m_x, point->m_y - 1,
645 point->
m_x, point->m_y + 1,
659 point->
m_x - 1, point->m_y,
670 point->
m_x + 1, point->m_y,
678 wxASSERT( &queue.
GetBest() == &border );
687 fprintf( m_dump,
"Route Final 3 %p %d\n", wire, wire->
GetSegments()->GetCount() );
738 if( end->
m_flags & flag_targetapprox )
751 if ( point.m_y != targetpos.m_y )
757 if ( point.m_x != targetpos.m_x )
764 newpoints->push_front( p );
766 newpoints->push_back( p );
769 else if( end->
m_flags & flag_targetwire )
774 if( dispinpos != endpoint )
786 if ( point.m_y != dispinpos.m_y )
792 if ( point.m_x != dispinpos.m_x )
799 newpoints->push_front( p );
801 newpoints->push_back( p );
810 current->
m_flags |= flag_final;
853 int x = current->
m_x;
854 int y = current->m_y;
888 fprintf( m_dump,
"Route Final 4 %p %d\n", wire, wire->
GetSegments()->GetCount() );
905 if( maxx > m_rastermaxx ) maxx = m_rastermaxx;
906 if( miny < m_rasterminy ) miny = m_rasterminy;
907 if( maxy > m_rastermaxy ) maxy = m_rastermaxy;
911 int minyi = ( miny - m_rasterminy );
912 int maxyi = ( maxy - m_rasterminy );
916 for( y = minyi; y <= maxyi; y++ )
918 for( x = minxi; x <= maxxi; x++ )
936 a2dVertexList::const_iterator iter = points->begin();
937 a2dVertexList::const_iterator prev = iter;
940 for( ; iter != points->end(); ++iter )
942 double x1l = ( *prev )->m_x;
943 double y1l = ( *prev )->m_y;
944 double x2l = ( *iter )->m_x;
945 double y2l = ( *iter )->m_y;
946 double x1, y1, x2, y2;
953 int miny = ( int ) floor( ( wxMin( y1, y2 ) + 0.5 *
m_raster ) * m_rasterinv );
954 int maxy = ( int ) ceil ( ( wxMax( y1, y2 ) - 0.5 *
m_raster ) * m_rasterinv );
957 if( maxx > m_rastermaxx ) maxx = m_rastermaxx;
958 if( miny < m_rasterminy ) miny = m_rasterminy;
959 if( maxy > m_rastermaxy ) maxy = m_rastermaxy;
963 int minyi = ( miny - m_rasterminy );
964 int maxyi = ( maxy - m_rasterminy );
969 for(
int y = minyi; y <= maxyi; y++ )
974 else if( minyi == maxyi )
977 for(
int x = minxi; x <= maxxi; x++ )
996 if( maxx > m_rastermaxx ) maxx = m_rastermaxx;
997 if( miny < m_rasterminy ) miny = m_rasterminy;
998 if( maxy > m_rastermaxy ) maxy = m_rastermaxy;
1002 int minyi = ( miny - m_rasterminy );
1003 int maxyi = ( maxy - m_rasterminy );
1007 for( y = minyi; y <= maxyi; y++ )
1009 for( x = minxi; x <= maxxi; x++ )
1018 a2dVertexList::const_iterator iter = points->begin();
1019 a2dVertexList::const_iterator prev = iter;
1022 for( ; iter != points->end(); ++iter )
1027 double x1l = ( *prev )->m_x;
1028 double y1l = ( *prev )->m_y;
1029 double x2l = ( *iter )->m_x;
1030 double y2l = ( *iter )->m_y;
1031 double x1, y1, x2, y2;
1039 int miny = ( int ) floor( ( wxMin( y1, y2 ) + 0.5 *
m_raster ) * m_rasterinv );
1040 int maxy = ( int ) ceil ( ( wxMax( y1, y2 ) - 0.5 *
m_raster ) * m_rasterinv );
1043 if( maxx > m_rastermaxx ) maxx = m_rastermaxx;
1044 if( miny < m_rasterminy ) miny = m_rasterminy;
1045 if( maxy > m_rastermaxy ) maxy = m_rastermaxy;
1049 int minyi = ( miny - m_rasterminy );
1050 int maxyi = ( maxy - m_rasterminy );
1052 if( minxi == maxxi )
1055 for(
int y = minyi; y <= maxyi; y++ )
1060 else if( minyi == maxyi )
1063 for(
int x = minxi; x <= maxxi; x++ )
1106 wxChar* buffer =
new wxChar [
m_widthp1 * 2 + 1 ];
1113 for( x = 0; x <=
m_width; x++ )
1122 if( ho == 0 && vo == 0 )
1123 *pos++ = wxT(
'.' );
1124 else if( ho == 1 && vo == 0 )
1125 *pos++ = wxT(
'-' );
1126 else if( ho == 0 && vo == 1 )
1127 *pos++ = wxT(
'|' );
1128 else if( ho == 1 && vo == 1 )
1129 *pos++ = wxT(
'x' );
1130 else if( ho == 2 && vo == 0 )
1131 *pos++ = wxT(
'=' );
1132 else if( ho == 0 && vo == 2 )
1133 *pos++ = wxT(
'"' );
1135 *pos++ = wxT(
'X' );
1138 ( point0->
m_flags & flag_final ) ||
1139 ( point1->
m_flags & flag_final ) ||
1140 ( point2->
m_flags & flag_final ) ||
1141 ( point3->
m_flags & flag_final )
1143 *pos++ = wxT(
'#' );
1144 else if( point0->
m_flags & flag_targetpin )
1145 *pos++ = wxT(
'P' );
1146 else if( point0->
m_flags & flag_targetapprox )
1147 *pos++ = wxT(
'A' );
1148 else if( point0->
m_flags & flag_targetwire )
1149 *pos++ = wxT(
'W' );
1151 ( point0->
m_flags & flag_reachable ) ||
1152 ( point1->
m_flags & flag_reachable ) ||
1153 ( point2->
m_flags & flag_reachable ) ||
1154 ( point3->
m_flags & flag_reachable )
1156 *pos++ = wxT(
'R' );
1158 *pos++ = wxT(
' ' );
1162 fprintf( file,
"%s\n", buffer );
1164 wxLogDebug( buffer );
1171 void a2dRouteData::DumpCost()
1174 wxLogDebug( _T(
"\nCost" ) );
1177 wxChar* buffer =
new wxChar [
m_widthp1 * 3 * 2 + 1 ];
1183 for( x = 0; x <=
m_width; x++ )
1186 int val = point->m_cost;
1188 *pos++ = val / 10 % 10 + wxT(
'0' );
1189 *pos++ = val % 10 + wxT(
'0' );
1190 *pos++ = wxT(
' ' );
1193 val = point->m_cost;
1195 *pos++ = val / 10 % 10 + wxT(
'0' );
1196 *pos++ = val % 10 + wxT(
'0' );
1197 *pos++ = wxT(
'|' );
1200 wxLogDebug( buffer );
1203 for( x = 0; x <=
m_width; x++ )
1206 int val = point->m_cost;
1208 *pos++ = val / 10 % 10 + wxT(
'0' );
1209 *pos++ = val % 10 + wxT(
'0' );
1210 *pos++ = wxT(
' ' );
1213 val = point->m_cost;
1215 *pos++ = val / 10 % 10 + wxT(
'0' );
1216 *pos++ = val % 10 + wxT(
'0' );
1217 *pos++ = wxT(
'|' );
1220 wxLogDebug( buffer );
1221 wxLogDebug( _T(
"" ) );
1231 wxLogDebug( wxT(
"VertexList" ) );
1234 wxLogDebug( wxT(
"%12.3lf %12.3lf" ), ( *iter )->m_x, ( *iter )->m_y );
unsigned short * m_horizontaloccupation
occupation counts for horizontal edges ( a 2d array )
wxPoint2DDouble a2dPoint2D
this to define if coordinate numbers are integer or doubles
This is a priority queue for border points.
a2dPin * IsDislocated() const
RoutePoint * m_routepoints
Routing points.
Temporary object used in editing connected objects.
#define wxDynamicCast(obj, className)
Define wxDynamicCast so that it will give a compiler error for unrelated types.
double m_rasterborder
an extra border in the raster area around the bounding box
unsigned short & GetHorizontalOccupation(int x, int y)
Get an element of the horizontal occupation array.
void Add(const BorderPoint &brdr)
Add a border object.
const a2dAffineMatrix & GetTransformMatrix() const
get the matrix used to position the object
AllocBlock * m_memory
Current memory allocation block.
result of dir1^dir2 for two opposing directions
unsigned short m_x
coordinates of this point
a2dPin is used in a2dCanvasObject to add pins to it.
polygon defined with list of points.
static a2dPropertyIdVoidPtr * PROPID_ToolObject
set for objects that act as tool object, when a tool is in action.
a2dDrawing * GetRoot() const
get a2dCanvasDocument of the object.
void Enlarge(const double Marge)
enlarge with the given amount
BorderPoint * m_next
pointer to the next point with same cost in the queue or to a free point
a2dBoundingBox GetCalculatedBoundingBox(int nChildLevels)
Like GetBbox, but it always calculcates the bounding box from scratch.
An entry in the border queue.
virtual void SetPending(bool pending)
set this object pending for update
a2dPin * IsConnectedTo(a2dPin *pin=a2dAnyPin) const
Return the pin to which this pin is connected.
The base class for all drawable objects in a a2dCanvasDocument.
BorderPoint * m_costring[m_ncost]
The starting points of the cost lists.
void AddOccupationPolyline(const a2dVertexList *points, const a2dAffineMatrix &trns, short incr)
add a polyline to the occupation area
void SetFlagRoutePointAllDirs(int x, int y, RoutePointFlag flag)
Set a flag in the route points for all directions.
const BorderPoint & GetBest()
Get the best border point.
a2dPoint2D GetAbsXY() const
get absolute position of the pin ( after applying the parent's matrix and its own matrix ) ...
a2dCanvasObject is the base class for Canvas Objects.
min usual direction value
a2dCanvasObjectList * GetChildObjectList()
get the list where the child objects are stored in.
vertex list of line and arc segments.
void TransformPoint(double x, double y, double &tx, double &ty) const
Transform a point.
int m_widthp1
width of the routing raster array + 1
unsigned int m_cost
minimum cost to reach this point
void AddBorderPoint(BorderQueue *queue, RoutePoint *current, int nextx, int nexty, int dir, int prevdir)
Add a new point on the route.
int m_heightp1
height of the routing raster array + 1
unsigned m_mincostindex
ring index of the current minimum cost (starting point or ring buffer )
int m_freememory
Number of free elements in memory allocation block.
a2dWirePolylineL is a polyline that adjusts itself when the objects it connects move ...
RoutePoint & GetRoutePoint(int x, int y, int dir)
Get an element of the route point array.
unsigned char m_prevdir
direction of the previous point
used to change a property on objects
bool GetValid() const
returns true if boundingbox is calculated properly and therefore its valid flag is set...
void Expand(const a2dPoint2D &, const a2dPoint2D &)
expand boundingbox width two points
double GetMinX() const
get minimum X of the boundingbox
#define forEachIn(listtype, list)
easy iteration for a2dlist
a2dCanvasObject * m_showobject
the show object given in the constructor
double GetPosX() const
get x position from affine matrix
void SetSegments(a2dVertexList *points)
Set the list of points ( the old list is NOT DELETED !!! )
#define wxStaticCast(obj, className)
The wxWindows 2.4.2 wxStaticCast is buggy. It evaluates its argument twice.
a2dVertexListPtr GetSegments()
Get the list of points ( this is not a copy! )
Normal straight line segment in a2dVertexList and a2dVertexArray.
~a2dRouteData()
Destructor.
Class for rerouting wires.
bool IsNotEmpty()
Check if the queue is empty.
bool IsInternal() const
see SetInternal()
Contains a2dDrawing Class to hold a drawing.
used to set the complete Segment list/array of polygons
bool GetRerouteAdded() const
see SetRerouteAdded()
unsigned char m_direction
direction to the source
virtual bool Submit(a2dCommand *command, bool storeIt=true)
next to the base class submit, it sets a2DocumentCommandProcessor for a2dCommand
A 2x3 affine matrix class for 2D transformations.
double GetMaxX() const
get maximum X of the boundingbox
double GetPosY() const
get y position from affine matrix
int m_width
width of the routing raster array
unsigned char m_prevdir
direction of the previous point
static double m_raster
the size of the raster
BorderPoint * m_freelist
The starting point of the free list.
unsigned short & GetVerticalOccupation(int x, int y)
Get an element of the vertical occupation array.
double m_x
x endpoint of line
the data structure holding the per point information
void MapBbox(const a2dAffineMatrix &matrix)
a2dCommandProcessor * GetCommandProcessor() const
Returns a pointer to the command processor associated with this document.
void SetFlagRect(const a2dBoundingBox &bbox, RoutePointFlag flag)
Set a RoutePoint flag in a rectangle.
double m_y
y endpoint of line
number of usual direction values
wire classes for connecting objects.
unsigned short m_x
coordinates of this point (only set if reachable)
double GetMaxY() const
get maximum Y of the boundingbox
void AddOccupationRect(const a2dBoundingBox &bbox, short incr)
add a bounding box to the occupied area
bool m_ok
if true, the raster is initialized
bool RerouteWire(a2dWirePolylineL *wire, a2dPin *dispin, a2dPin *startpin, bool startisbegin, bool final)
Reroute a wire.
unsigned char m_direction
direction to the source (only set if reachable)
RoutePointFlag
flags for RoutePoint
bool IsHorizontalOccupied(int x, int y)
Is an element of the horizontal occupation array.
The a2dBoundingBox class stores one a2dBoundingBox of a a2dCanvasObject.
bool Invert(void)
Invert matrix.
double m_rasterinv
the inverse size of the raster
void SetRerouteAdded(bool onOff)
indicated if the wire is added recently to be rerouted, used in routing algorithms of wire between ob...
unsigned short * m_verticaloccupation
occupation counts for vertical edges ( a 2d array )
double GetMinY() const
get minimum Y of the boundingbox
void SetPosXyPoint(const a2dPoint2D &pos)
set position to x,y
basetype GetPropertyValue(const a2dObject *obj) const
Get the property value in obj.
unsigned short m_flags
various flags
int m_rasterminx
the limits of the raster area
int m_height
height of the routing raster array
a2dCanvasObject * GetParent() const
get parent object of the pin
a2dRouteData(a2dCanvasObject *showobject, bool final)
Standard constructor takes the show object under which is routed.
a2dBoundingBox CalculateRoutingBbox(a2dCanvasObject *object)
Calculates the routing relevant bounding box of an object.
void DumpOccupation(FILE *file)
Dump the occupation arrays.
unsigned int m_cost
minimum cost to reach this point
bool GetReroute() const
see SetReroute()
bool IsVerticalOccupied(int x, int y)
Is an element of the vertical occupation array.
void SetFlagPolyline(const a2dVertexList *points, const a2dAffineMatrix &trns, RoutePointFlag flag)
Set a RoutePoint flag along a polyline.
void RmvBest()
Remove the best border point.
max usual direction value