WIP: Streamlined d25 script notation

This commit is contained in:
Matthias Koefferlein 2022-03-06 10:35:58 +01:00
parent 4acd0aabc5
commit f681d96558
2 changed files with 78 additions and 56 deletions

View File

@ -20,12 +20,47 @@ module D25
class D25Display class D25Display
attr_accessor :fill, :frame, :like attr_accessor :fill, :frame, :like, :name
def initialize def initialize
self.fill = nil self.fill = nil
self.frame = nil self.frame = nil
self.like = nil self.like = nil
self.name = nil
end
def set_fill(arg)
if !arg.is_a?(0xffffff.class)
raise("'fill' must be a color value (an integer)")
end
self.fill = arg
end
def set_frame(arg)
if !arg.is_a?(0xffffff.class)
raise("'frame' must be a color value (an integer)")
end
self.frame = arg
end
def set_color(arg)
if !arg.is_a?(0xffffff.class)
raise("'color' must be a color value (an integer)")
end
self.fill = arg
self.frame = nil
end
def set_like(arg)
li = nil
if arg.is_a?(String)
li = RBA::LayerInfo::from_string(arg)
elsif arg.is_a?(RBA::LayerInfo)
li = arg
else
raise("'like' must be a string or LayerInfo object")
end
self.like = li
end end
end end
@ -58,6 +93,7 @@ module D25
zstart = nil zstart = nil
zstop = nil zstop = nil
height = nil height = nil
display = D25Display::new
args.each do |a| args.each do |a|
@ -88,19 +124,31 @@ module D25
end end
height = a[:height] height = a[:height]
end end
if a[:zstart] if a[:zstart]
if zstart if zstart
raise("Duplicate zstart specification") raise("Duplicate zstart specification")
end end
zstart = a[:zstart] zstart = a[:zstart]
end end
if a[:zstop] if a[:zstop]
if zstop if zstop
raise("Duplicate zstop specification") raise("Duplicate zstop specification")
end end
zstop = a[:zstop] zstop = a[:zstop]
end end
invalid_keys = a.keys.select { |k| ![ :height, :zstart, :zstop ].member?(k) }
a[:color] && display.set_color(a[:color])
a[:frame] && display.set_frame(a[:frame])
a[:fill] && display.set_fill(a[:fill])
a[:like] && display.set_like(a[:like])
if a[:name]
display.name = a[:name].to_s
end
invalid_keys = a.keys.select { |k| ![ :height, :zstart, :zstop, :color, :frame, :fill, :like, :name ].member?(k) }
if invalid_keys.size > 0 if invalid_keys.size > 0
raise("Keyword argument(s) not understood: #{invalid_keys.collect(&:to_s).join(',')}") raise("Keyword argument(s) not understood: #{invalid_keys.collect(&:to_s).join(',')}")
end end
@ -128,7 +176,7 @@ module D25
raise("No layer specified") raise("No layer specified")
end end
info = D25ZInfo::new(layer, zstart, zstop, @display || D25Display::new) info = D25ZInfo::new(layer, zstart, zstop, @display || display)
@zstack << info @zstack << info
return info return info
@ -137,7 +185,7 @@ module D25
end end
def display(*args, &block) def zz(*args, &block)
begin begin
@ -156,46 +204,16 @@ module D25
elsif a.is_a?(Hash) elsif a.is_a?(Hash)
hollow_fill = 0xffffffff a[:color] && display.set_color(a[:color])
a[:frame] && display.set_frame(a[:frame])
a[:fill] && display.set_fill(a[:fill])
a[:like] && display.set_like(a[:like])
if a[:color] if a[:name]
if !a[:color].is_a?(0xffffff.class) display.name = a[:name].to_s
raise("'color' must be a color value (an integer)")
end
display.fill = a[:color]
display.frame = nil
end
if a[:frame]
if !a[:frame].is_a?(0xffffff.class)
raise("'frame' must be a color value (an integer)")
end
display.frame = a[:frame]
end
if a[:fill]
if !a[:fill].is_a?(0xffffff.class)
raise("'fill' must be a color value (an integer)")
end
display.fill = a[:fill]
end
if a[:hollow]
if a[:hollow]
display.fill = hollow_fill
end
end end
if a[:like] invalid_keys = a.keys.select { |k| ![ :fill, :frame, :color, :hollow, :like, :name ].member?(k) }
li = nil
if a[:like].is_a?(String)
li = RBA::LayerInfo::from_string(a[:like])
elsif a[:like].is_a?(RBA::LayerInfo)
li = a[:like]
else
raise("'like' must be a string or LayerInfo object")
end
display.like = li
end
invalid_keys = a.keys.select { |k| ![ :fill, :frame, :color, :hollow, :like ].member?(k) }
if invalid_keys.size > 0 if invalid_keys.size > 0
raise("Keyword argument(s) not understood: #{invalid_keys.collect(&:to_s).join(',')}") raise("Keyword argument(s) not understood: #{invalid_keys.collect(&:to_s).join(',')}")
end end

View File

@ -22,34 +22,38 @@
# z(layer, options ...): # z(layer, options ...):
# #
# This function generates a extruded view from the given layer. # This function generates a extruded view from the given layer.
# The "options" describe the z extension. Valid forms are: #
# Some options control the z extrusion:
# #
# z(layer, 0.1 .. 0.2) extrude layer to z = 0.1 to 0.2 um # z(layer, 0.1 .. 0.2) extrude layer to z = 0.1 to 0.2 um
# z(layer, zstart: 0.1, zstop: 0.2) same as above # z(layer, zstart: 0.1, zstop: 0.2) same as above
# z(layer, zstart: 0.1, height: 0.1) same as above, but with height instead of zstop # z(layer, zstart: 0.1, height: 0.1) same as above, but with height instead of zstop
# z(layer, height: 200.nm) extrude layer from last z position with a height of 200nm # z(layer, height: 200.nm) extrude layer from last z position with a height of 200nm
#
# You can specify display options:
#
# z(..., color: 0xff0000) use bright red for the material color (RGB)
# z(..., frame: 0xff0000) use bright red for the frame color (combine with "fill" for the fill color)
# z(..., fill: 0x00ff00) use bright green for the fill color along (combine with "frame" for the frame color)
# z(..., like: "7/0") borrow style from layout view's style for layer "7/0"
# z(..., name: "M1") assigns a name to show for the material
# #
# If layer is an original layer, the display options (colors, hollow) are taken # If no display options are given and layer is an original layer, the colors are taken
# from the original layer's display style. Otherwise KLayout decides about the # from the original layer's display style. Otherwise KLayout decides about the
# initial display options. Use "display(...)" to control the display options. # colors itself using the application's palette.
# #
# display(options) { block } # zz(options) { block }
# display(z(...), z(...), ..., options): # zz(z(...), z(...), ..., options):
# #
# Specify the display options to use for the layers generated inside the block # Creates a display group. The display options are the same for all
# (which must contains at least one "z" call) or the given z calls: # extrusion specs within the group.
#
# Options are:
#
# display(..., color: 0xff0000) use bright red for the material color (RGB)
# display(..., frame: 0xff0000) use bright red for the frame color (combine with "fill" for the fill color)
# display(..., fill: 0x00ff00) use bright green for the fill color along (combine with "frame" for the frame color)
# display(..., like: "7/0") borrow style from layout view's style for layer "7/0"
# #
# The options of "zz" are "name", "color", "frame", "fill" and "like".
z(input(1, 0), 0.1 .. 0.2) z(input(1, 0), 0.1 .. 0.2)
z(input(2, 0), height: 250.nm, color: 0xffbc80)
display(like: 7/0) do zz(like: 7/0, name: "Metal") do
z(input(7, 0), height: 100.nm) z(input(7, 0), height: 100.nm)
z(input(8, 0), height: 150.nm) z(input(8, 0), height: 150.nm)
end end