Skip to content

pymod branch: reimplemented methods are not getting called #197

@klayoutmatthias

Description

@klayoutmatthias

See https://www.klayout.de/forum/discussion/1152

The following code isn't working in the standalone module. In the application this will produce a layout with three circles.

Reason: gsi::Callback::can_issue (gsiCallback.h:76 and then pyaObject.cc:119) checks for pya::PythonInterpreter::instance() != 0 which is not the case for the standalone module.

import klayout.db as pya

# --------------------------------------------------------
#  Library definition

class TestPCell(pya.PCellDeclarationHelper):

  def __init__(self):

    super(TestPCell, self).__init__()

    self.param("l", self.TypeLayer, "Layer", default = pya.LayerInfo(1, 0))
    self.param("r", self.TypeDouble, "Radius", default = 1000.0)
    self.param("n", self.TypeInt, "Number of points", default = 64)

  def display_text_impl(self):
    return "Circle (l=%s,r=%.12g,n=%d)" % (str(self.l), self.r, self.n)
  
  def produce_impl(self):
    self.cell.shapes(self.l_layer).insert(pya.DPolygon.ellipse(pya.DBox(-self.r, -self.r, self.r, self.r), self.n))

class TestLib(pya.Library):

  def __init__(self):
    self.description = "Test library"
    self.layout().register_pcell("Circle", TestPCell())
    self.register("TestLib")
    
# create and register the library
lib = TestLib()


# --------------------------------------------------------
#  Client code

lay = pya.Layout()
top = lay.create_cell("TOP")

output_file = "test.gds"

para = { "l": pya.LayerInfo(1, 0) }

pcell = lay.create_cell("Circle", "TestLib", para)
trans = pya.DCplxTrans.new(1, 0, False, 0, 0)
top.insert(pya.DCellInstArray(pcell.cell_index(), trans))

para = { "l": pya.LayerInfo(2, 0), "r": 750.0 }

pcell = lay.create_cell("Circle", "TestLib", para)
trans = pya.DCplxTrans.new(1, 0, False, 0, 2000.0)
top.insert(pya.DCellInstArray(pcell.cell_index(), trans))

para = { "l": pya.LayerInfo(2, 0), "r": 500.0, "n": 16 }

pcell = lay.create_cell("Circle", "TestLib", para)
trans = pya.DCplxTrans.new(1, 0, False, 0, 3000.0)
top.insert(pya.DCellInstArray(pcell.cell_index(), trans))

lay.write(output_file)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions