Exported Polygon::getSubPolygons() to Python.
* New: In Hurricane::Isobar::PyPolygon, export the getSubPolygons() method. Makes a list of list (maybe tuple should have been better to prevent user's rewrite). * Change: In documentation/examples/scripts/, update polygons.py to serve as a very basic test-bench for Polygon, manhattanhization and sub-polygons display.
This commit is contained in:
parent
4f089ffdea
commit
1887f45135
|
@ -5,7 +5,8 @@ from Hurricane import *
|
|||
from CRL import *
|
||||
|
||||
|
||||
def toDbU ( l ): return DbU.fromLambda(l)
|
||||
def toDbU ( l ): return DbU.fromLambda(l)
|
||||
def toMicron ( u ): return DbU.toPhysical( u, DbU.UnitPowerMicro )
|
||||
|
||||
|
||||
def doBreak ( level, message ):
|
||||
|
@ -23,6 +24,7 @@ def buildPolygons ( editor ):
|
|||
cell.setTerminal( True )
|
||||
|
||||
cell.setAbutmentBox( Box( toDbU(-5.0), toDbU(-5.0), toDbU(65.0), toDbU(75.0) ) )
|
||||
#cell.setAbutmentBox( Box( toDbU(-5.0), toDbU(-5.0), toDbU(21.0), toDbU(35.0) ) )
|
||||
|
||||
if editor:
|
||||
UpdateSession.close()
|
||||
|
@ -33,6 +35,7 @@ def buildPolygons ( editor ):
|
|||
technology = DataBase.getDB().getTechnology()
|
||||
metal1 = technology.getLayer( "METAL1" )
|
||||
metal2 = technology.getLayer( "METAL2" )
|
||||
metal3 = technology.getLayer( "METAL3" )
|
||||
metal4 = technology.getLayer( "METAL4" )
|
||||
poly = technology.getLayer( "POLY" )
|
||||
ptrans = technology.getLayer( "PTRANS" )
|
||||
|
@ -102,10 +105,60 @@ def buildPolygons ( editor ):
|
|||
p = Polygon.create( net, metal2, points )
|
||||
p.translate( toDbU(30.0), toDbU(40.0) )
|
||||
|
||||
# Big parallelogram.
|
||||
points = [ Point( toDbU( 0.0), toDbU( 0.0) )
|
||||
, Point( toDbU( 20.0), toDbU( 20.0) )
|
||||
, Point( toDbU( 60.0), toDbU( 20.0) )
|
||||
, Point( toDbU( 40.0), toDbU( 0.0) ) ]
|
||||
p = Polygon.create( net, metal3, points )
|
||||
p.translate( toDbU(70.0), toDbU(0.0) )
|
||||
|
||||
points = [ Point( toDbU( 0.0), toDbU( 20.0) )
|
||||
, Point( toDbU( 40.0), toDbU( 20.0) )
|
||||
, Point( toDbU( 60.0), toDbU( 0.0) )
|
||||
, Point( toDbU( 20.0), toDbU( 0.0) ) ]
|
||||
p = Polygon.create( net, metal3, points )
|
||||
p.translate( toDbU(140.0), toDbU(0.0) )
|
||||
|
||||
points = [ Point( toDbU( 0.0), toDbU( 0.0) )
|
||||
, Point( toDbU( 0.0), toDbU( 10.0) )
|
||||
, Point( toDbU( 20.0), toDbU( 30.0) )
|
||||
, Point( toDbU( 60.0), toDbU( 30.0) )
|
||||
, Point( toDbU( 60.0), toDbU( 20.0) )
|
||||
, Point( toDbU( 40.0), toDbU( 0.0) ) ]
|
||||
p = Polygon.create( net, metal3, points )
|
||||
p.translate( toDbU(70.0), toDbU(40.0) )
|
||||
|
||||
points = [ Point( toDbU( 0.0), toDbU( 20.0) )
|
||||
, Point( toDbU( 0.0), toDbU( 30.0) )
|
||||
, Point( toDbU( 40.0), toDbU( 30.0) )
|
||||
, Point( toDbU( 60.0), toDbU( 10.0) )
|
||||
, Point( toDbU( 60.0), toDbU( 0.0) )
|
||||
, Point( toDbU( 20.0), toDbU( 0.0) ) ]
|
||||
p = Polygon.create( net, metal3, points )
|
||||
p.translate( toDbU(140.0), toDbU(40.0) )
|
||||
|
||||
|
||||
print 'Normalized and manhattanized contour:'
|
||||
i = 0
|
||||
for point in p.getMContour():
|
||||
print '| %d '%i, point \
|
||||
, '[%fum %fum]' % ( toMicron(point.getX()) \
|
||||
, toMicron(point.getY()) )
|
||||
i += 1
|
||||
|
||||
print 'Sub-polygons (for GDSII generation)'
|
||||
subpolygons = p.getSubPolygons()
|
||||
for i in range(len(subpolygons)):
|
||||
print '+ Sub-Polygon %d:' % i
|
||||
for j in range(len(subpolygons[i])):
|
||||
print ' [%3d]' % j, subpolygons[i][j] \
|
||||
, '[%fum %fum]' % ( toMicron(subpolygons[i][j].getX()) \
|
||||
, toMicron(subpolygons[i][j].getY()) )
|
||||
|
||||
UpdateSession.close()
|
||||
|
||||
#AllianceFramework.get().saveCell( cell, Catalog.State.Views )
|
||||
# No saving as we don't have a GDSII driver (yet).
|
||||
Gds.save( cell )
|
||||
return
|
||||
|
||||
|
||||
|
|
|
@ -46,6 +46,24 @@ namespace Isobar {
|
|||
}
|
||||
|
||||
|
||||
PyObject* VectorToList ( const std::vector<Point>& v )
|
||||
{
|
||||
PyObject* pyList = PyList_New( v.size() );
|
||||
|
||||
for ( size_t i=0 ; i<v.size() ; ++i ) {
|
||||
PyPoint* pyPoint = PyObject_NEW( PyPoint, &PyTypePoint );
|
||||
if (pyPoint == NULL) { return NULL; }
|
||||
|
||||
HTRY
|
||||
pyPoint->_object = new Point ( v[i] );
|
||||
HCATCH
|
||||
PyList_SetItem( pyList, i, (PyObject*)pyPoint );
|
||||
}
|
||||
|
||||
return pyList;
|
||||
}
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
||||
|
@ -120,6 +138,28 @@ extern "C" {
|
|||
}
|
||||
|
||||
|
||||
static PyObject* PyPolygon_getSubPolygons ( PyPolygon *self )
|
||||
{
|
||||
cdebug_log(20,0) << "PyPolygon_getSubPolygons()" << endl;
|
||||
|
||||
PyObject* pySubPolygons = NULL;
|
||||
|
||||
METHOD_HEAD( "Polygon.SubPolygons()" )
|
||||
HTRY
|
||||
vector< vector<Point> > subpolygons;
|
||||
polygon->getSubPolygons( subpolygons );
|
||||
|
||||
pySubPolygons = PyList_New( subpolygons.size() );
|
||||
|
||||
for ( size_t i=0 ; i<subpolygons.size() ; ++i ) {
|
||||
PyList_SetItem( pySubPolygons, i, VectorToList( subpolygons[i] ) );
|
||||
}
|
||||
HCATCH
|
||||
|
||||
return pySubPolygons;
|
||||
}
|
||||
|
||||
|
||||
static PyObject* PyPolygon_setPoints ( PyPolygon *self, PyObject* args )
|
||||
{
|
||||
cdebug_log(20,0) << "Polygon.setPoints()" << endl;
|
||||
|
@ -128,8 +168,6 @@ extern "C" {
|
|||
METHOD_HEAD( "Polygon.setPoints()" )
|
||||
|
||||
PyObject* arg0 = NULL;
|
||||
PyObject* arg1 = NULL;
|
||||
PyObject* arg2 = NULL;
|
||||
if (not PyArg_ParseTuple( args, "O:Polygon.setPoints", &arg0 )) {
|
||||
PyErr_SetString( ConstructorError, "Invalid number of parameters for Polygon.setPoints()." );
|
||||
return NULL;
|
||||
|
@ -200,6 +238,7 @@ extern "C" {
|
|||
, { "getY" , (PyCFunction)PyPolygon_getY , METH_NOARGS , "Return the Polygon Y value." }
|
||||
, { "getBoundingBox", (PyCFunction)PyPolygon_getBoundingBox, METH_NOARGS , "Return the Polygon Bounding Box." }
|
||||
, { "getMContour" , (PyCFunction)PyPolygon_getMContour , METH_NOARGS , "Return the points of the manhattanized contour." }
|
||||
, { "getSubPolygons", (PyCFunction)PyPolygon_getSubPolygons, METH_NOARGS , "Return the list of sub-polygons (GDSII compliants)." }
|
||||
, { "setPoints" , (PyCFunction)PyPolygon_setPoints , METH_VARARGS, "Sets the Polygon Bounding Box." }
|
||||
, { "translate" , (PyCFunction)PyPolygon_translate , METH_VARARGS, "Translates the Polygon of dx and dy." }
|
||||
, { "destroy" , (PyCFunction)PyPolygon_destroy , METH_NOARGS
|
||||
|
|
Loading…
Reference in New Issue