mirror of https://github.com/KLayout/klayout.git
Added an editor hooks example for Ruby
This commit is contained in:
parent
972514454b
commit
b079398b02
|
|
@ -20,5 +20,7 @@
|
||||||
<file alias="pcell_sample_python.lym">macro_templates/pcell_sample_python.lym</file>
|
<file alias="pcell_sample_python.lym">macro_templates/pcell_sample_python.lym</file>
|
||||||
<file alias="via_pcell_sample_python.lym">macro_templates/via_pcell_sample_python.lym</file>
|
<file alias="via_pcell_sample_python.lym">macro_templates/via_pcell_sample_python.lym</file>
|
||||||
<file alias="via_pcell_sample.lym">macro_templates/via_pcell_sample.lym</file>
|
<file alias="via_pcell_sample.lym">macro_templates/via_pcell_sample.lym</file>
|
||||||
|
<file alias="editor_hooks_sample_python.lym">macro_templates/editor_hooks_sample_python.lym</file>
|
||||||
|
<file alias="editor_hooks_sample.lym">macro_templates/editor_hooks_sample.lym</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,188 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<klayout-macro>
|
||||||
|
<description>Editor hooks sample (Ruby)\nThis sample shows how to implement editor hooks</description>
|
||||||
|
<format>general</format>
|
||||||
|
<autorun>true</autorun>
|
||||||
|
<autorun-early>false</autorun-early>
|
||||||
|
<show-in-menu>false</show-in-menu>
|
||||||
|
<category>macros</category>
|
||||||
|
<interpreter>ruby</interpreter>
|
||||||
|
<text>module MyEditorHooks
|
||||||
|
|
||||||
|
# This demo installs editor hooks to indicate the forbidding regions around a shape
|
||||||
|
#
|
||||||
|
# It follows some hypothetical technology that defines three layers:
|
||||||
|
#
|
||||||
|
# 1/0: min space 0.2, euclidian
|
||||||
|
# 2/0: min space 0.5, projection
|
||||||
|
# 3/0: min space 1.0, projection
|
||||||
|
#
|
||||||
|
# The forbidding region is highlighted while the shapes
|
||||||
|
# are drawn.
|
||||||
|
#
|
||||||
|
# Space between instances: 0.4
|
||||||
|
|
||||||
|
class MyEditorHooks < RBA::EditorHooks
|
||||||
|
|
||||||
|
def initialize
|
||||||
|
|
||||||
|
self.register("MyEditorHooks")
|
||||||
|
|
||||||
|
@markers = []
|
||||||
|
@view = nil
|
||||||
|
@layout = nil
|
||||||
|
@space = 0.0
|
||||||
|
|
||||||
|
@spaces = {
|
||||||
|
RBA::LayerInfo::new(1, 0) => [ 0.2, RBA::Region::Euclidian ],
|
||||||
|
RBA::LayerInfo::new(2, 0) => [ 0.5, RBA::Region::Projection ],
|
||||||
|
RBA::LayerInfo::new(3, 0) => [ 1.0, RBA::Region::Projection ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@instance_space = 0.4
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_space_from_layer(layer_index)
|
||||||
|
|
||||||
|
# pick the space value
|
||||||
|
lp = @layout.get_info(layer_index)
|
||||||
|
if @spaces[lp]
|
||||||
|
(s, m) = @spaces[lp]
|
||||||
|
@space = s / @layout.dbu
|
||||||
|
@metrics = m
|
||||||
|
else
|
||||||
|
@space = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_marker_from_shape(shape, trans)
|
||||||
|
|
||||||
|
if !@space
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
p = shape.polygon
|
||||||
|
if p && p.num_points < 100
|
||||||
|
r = RBA::Region::new
|
||||||
|
r.merged_semantics = (p.num_points != 2)
|
||||||
|
r.insert(p)
|
||||||
|
r = r.drc_hull(@metrics, @space)
|
||||||
|
r.each do |pp|
|
||||||
|
m = RBA::Marker::new(@view)
|
||||||
|
m.line_style = 2
|
||||||
|
m.vertex_size = 0
|
||||||
|
m.set_polygon(trans * pp)
|
||||||
|
@markers.append(m)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
t = shape.text
|
||||||
|
if t
|
||||||
|
m = RBA::Marker::new(@view)
|
||||||
|
m.set_box(trans * t.bbox.enlarged(@space))
|
||||||
|
@markers.append(m)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def clear_markers
|
||||||
|
@markers.each { |m| m._destroy }
|
||||||
|
@markers = []
|
||||||
|
end
|
||||||
|
|
||||||
|
def cleanup
|
||||||
|
self.clear_markers
|
||||||
|
@view = nil
|
||||||
|
@layout = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def setup(cv)
|
||||||
|
@view = cv.view
|
||||||
|
@layout = cv.layout
|
||||||
|
self.clear_markers
|
||||||
|
end
|
||||||
|
|
||||||
|
# Shape creation protocol
|
||||||
|
|
||||||
|
def begin_create_shapes(cv, layer)
|
||||||
|
self.setup(cv)
|
||||||
|
# pick the space value
|
||||||
|
self.set_space_from_layer(layer.layer_index)
|
||||||
|
end
|
||||||
|
|
||||||
|
def begin_new_shapes
|
||||||
|
self.clear_markers
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_shape(shape, trans)
|
||||||
|
# create a marker with space halo
|
||||||
|
self.add_marker_from_shape(shape, trans)
|
||||||
|
end
|
||||||
|
|
||||||
|
def end_create_shapes
|
||||||
|
self.cleanup
|
||||||
|
end
|
||||||
|
|
||||||
|
# Instance creation protocol
|
||||||
|
|
||||||
|
def begin_create_instances(cv)
|
||||||
|
self.setup(cv)
|
||||||
|
end
|
||||||
|
|
||||||
|
def begin_new_instances
|
||||||
|
self.clear_markers
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_instance(instance, trans)
|
||||||
|
m = RBA::Marker::new(@view)
|
||||||
|
m.set_box(trans * instance.bbox.enlarged(@instance_space / @layout.dbu))
|
||||||
|
@markers.append(m)
|
||||||
|
end
|
||||||
|
|
||||||
|
def end_create_instances
|
||||||
|
self.cleanup
|
||||||
|
end
|
||||||
|
|
||||||
|
# Modification protocol
|
||||||
|
|
||||||
|
def begin_edit(cv)
|
||||||
|
self.setup(cv)
|
||||||
|
end
|
||||||
|
|
||||||
|
def begin_edits
|
||||||
|
self.clear_markers
|
||||||
|
end
|
||||||
|
|
||||||
|
def transformed(path, applied, trans)
|
||||||
|
if !path.shape
|
||||||
|
m = RBA::Marker::new(@view)
|
||||||
|
m.set_box(trans * (applied * path.inst.bbox).enlarged(@instance_space / @layout.dbu))
|
||||||
|
@markers.append(m)
|
||||||
|
else
|
||||||
|
self.set_space_from_layer(path.layer)
|
||||||
|
self.add_marker_from_shape(path.shape, trans * applied)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def modified(path, shape, trans)
|
||||||
|
self.set_space_from_layer(path.layer)
|
||||||
|
self.add_marker_from_shape(shape, trans)
|
||||||
|
end
|
||||||
|
|
||||||
|
def commit_edit
|
||||||
|
# nothing here.
|
||||||
|
end
|
||||||
|
|
||||||
|
def end_edit
|
||||||
|
self.cleanup
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
MyEditorHooks::new
|
||||||
|
|
||||||
|
end
|
||||||
|
</text>
|
||||||
|
</klayout-macro>
|
||||||
|
|
@ -21,6 +21,7 @@ pcell.lym
|
||||||
:Samples;;
|
:Samples;;
|
||||||
pcell_sample.lym
|
pcell_sample.lym
|
||||||
via_pcell_sample.lym
|
via_pcell_sample.lym
|
||||||
|
editor_hooks_sample.lym
|
||||||
qt_designer.lym
|
qt_designer.lym
|
||||||
qt_dialog.lym
|
qt_dialog.lym
|
||||||
qt_server.lym
|
qt_server.lym
|
||||||
|
|
@ -40,6 +41,7 @@ pcell_python.lym
|
||||||
:Samples;;
|
:Samples;;
|
||||||
pcell_sample_python.lym
|
pcell_sample_python.lym
|
||||||
via_pcell_sample_python.lym
|
via_pcell_sample_python.lym
|
||||||
|
editor_hooks_sample_python.lym
|
||||||
qt_designer_python.lym
|
qt_designer_python.lym
|
||||||
qt_dialog_python.lym
|
qt_dialog_python.lym
|
||||||
qt_server_python.lym
|
qt_server_python.lym
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue