From 1887f4513581a9d5f9814d8c90f4d31303c2a229 Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Sun, 3 Jun 2018 12:55:28 +0200 Subject: [PATCH] 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. --- documentation/examples/scripts/polygons.py | 59 ++++++++++++++++++++-- hurricane/src/isobar/PyPolygon.cpp | 43 +++++++++++++++- 2 files changed, 97 insertions(+), 5 deletions(-) diff --git a/documentation/examples/scripts/polygons.py b/documentation/examples/scripts/polygons.py index 2b5cbb44..3d5d45e3 100644 --- a/documentation/examples/scripts/polygons.py +++ b/documentation/examples/scripts/polygons.py @@ -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 diff --git a/hurricane/src/isobar/PyPolygon.cpp b/hurricane/src/isobar/PyPolygon.cpp index 8e697792..d80f12f3 100644 --- a/hurricane/src/isobar/PyPolygon.cpp +++ b/hurricane/src/isobar/PyPolygon.cpp @@ -46,6 +46,24 @@ namespace Isobar { } + PyObject* VectorToList ( const std::vector& v ) + { + PyObject* pyList = PyList_New( v.size() ); + + for ( size_t i=0 ; i_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 > subpolygons; + polygon->getSubPolygons( subpolygons ); + + pySubPolygons = PyList_New( subpolygons.size() ); + + for ( size_t i=0 ; i