It looks like you're new here. If you want to get involved, click one of these buttons!
I want to define a technology-specific grid set.
My requirements include
(1) Titles are displayed with appropriate auxiliary units like "nm" and "μm".
Many zeros are not presbyopia friendly!
(2) Locally changed (in a technology) grids do not affect the global values.
That is, when I restart with the (default) technology, the global default grids are restored.
I have created a Python macro below that has two methods.
("autorun" is set to "false" for debugging.)
<?xml version="1.0" encoding="utf-8"?>
<klayout-macro>
<description/>
<version/>
<category>pymacros</category>
<prolog/>
<epilog/>
<doc/>
<autorun>false</autorun>
<autorun-early>false</autorun-early>
<priority>0</priority>
<shortcut/>
<show-in-menu>false</show-in-menu>
<group-name/>
<menu-path/>
<interpreter>python</interpreter>
<dsl-interpreter-name/>
<text>#------------------------------------------------------------------------------------
# File: GridSetter.lym
#
# Aim: To replace the current default grid set to another one
#
# Requirements:
# 1) Menu items must be properly formatted using the appropriate auxiliary units.
# 2) The original default grids in "$HOME/.klayout/klayoutrc" must remain intact.
#------------------------------------------------------------------------------------
import pya
Application = pya.Application().instance()
MainWindow = pya.MainWindow.instance()
MainMenu = MainWindow.menu()
Dispatcher = MainWindow.dispatcher()
# My favorite grids in [nm]
nanoList = [0.5, 1.0, 2.0, 5.0, 10.0, 20.0, 50.0, 100.0]
nanoList += [200.0, 500.0, 1000.0, 2000.0, 5000.0]
# There are two methods.
# method = 1 => ClearList() + AddList()
# method = 2 => SetConfigGrids()
method = 1
def ClearList():
#--------------------------------------------------------------
# [1] Remove all entries
#--------------------------------------------------------------
path = "view_menu.default_grid"
for item in MainMenu.items(path):
MainMenu.delete_item(item)
#--------------------------------------------------------------
# [2] Update the configuration
# <default-grids>...1,2,5,10,20,50,100...</default-grids>
#--------------------------------------------------------------
#Application.set_config( "default-grids", "" )
#Application.commit_config()
def AddList():
#--------------------------------------------------------------
# [1] Add technology-specific grids
#--------------------------------------------------------------
path = "view_menu.default_grid"
for idx in range(0, len(nanoList)):
nanoVal = nanoList[idx]
micVal = nanoVal / 1000.0
a = pya.Action()
if nanoVal < 1000.0:
a.title = "{:5.1f} nm".format(nanoVal)
else:
a.title = "{:5.1f} μm".format(micVal)
# How to make each item a checkable radio button
MainMenu.insert_item( path, str(micVal), a )
#--------------------------------------------------------------
# [2] Update the configuration
# <default-grids>...1,2,5,10,20,50,100...</default-grids>
#--------------------------------------------------------------
#newGrids = ",".join( [str(x/1000.0) for x in nanoList] )
#Application.set_config( "default-grids", newGrids )
#Application.commit_config()
def SetConfigGrids():
#--------------------------------------------------------------
# [1] Prepare a new grid list as a string
#--------------------------------------------------------------
newGrids = ",".join( [str(x/1000.0) for x in nanoList] )
#--------------------------------------------------------------
# [2] Set the new grid list
#--------------------------------------------------------------
Dispatcher.set_config( "default-grids", newGrids )
#--------------------------------------------------------------------
if method == 1:
ClearList()
AddList()
elif method == 2:
SetConfigGrids()
</text>
</klayout-macro>
Both methods are unsatisfactory so far, as shown in Fig-001 through Fig-006.
Any suggestions will be appreciated.
Thanks
Kazzz-S
Comments
Hi @sekigawa,
I though about the problem and I basically think it will be very hard to override the "Grid" menu behavior. This is because this menu is updated occasionally by the system with it's own rules and it is hard to predict when.
So there are two options:
I am actually in favor of the second solution which to me seems easier to do. I can create a GitHub ticket if you like.
Best regards,
Matthias
Hello @Matthias,
Thank you for your consideration. I understand the difficulty.
I can compromise by preparing a different pymacro for each favorable grid set using method=2, such as [tech-A.lym, tech-B.lym, ..., default.lym], and calling them manually.
Best regards,
Kazzz-S
Hi @sekigawa,
I have added some feature (branch "tech-specific-grids"). It allows specifying a grid list per technology:
In addition, grids less than 0.5µm are shown in nanometers.
I can include that in the next minor release.
Best regards,
Matthias
Hello @Matthias,
Wow, thanks a lot for the new feature proposal
I've built the branch on my Mac and tested the new feature as shown in Fig.A-00 through -06 and Fig.B-00 through -06.
This is exactly what I wanted
Best regards,
Kazzz-S
@sekigawa Cool! Thanks for this feedback
You're always welcome!
It was much easier to implement in C++ - this is a spot where scripting will not really help as it conflicts with the internal logic.
I'll put that into 0.28.16. 0.29 will need a little still
Best regards,
Matthias