Skip to content

Add dynamic preset support - #41

Closed
Gerard-Taulats wants to merge 11 commits into
aesc-silicon:mainfrom
Gerard-Taulats:Gerard-Taulats-dynamic-presets
Closed

Gerard-Taulats wants to merge 11 commits into
aesc-silicon:mainfrom
Gerard-Taulats:Gerard-Taulats-dynamic-presets

Conversation

@Gerard-Taulats

Copy link
Copy Markdown
Contributor

Removes hardcoded presets, reading the files present at "config" folder.
Allows for users to add their custom presets and be readily available from Blender UI.

A set of new properties have been added to the "config" YAML files under "pdk_config", where name, description, order and default color can be set.
"Order" are integers. Default value is 0. If same value is set, then it's ordered alphabetically.
Since I set order of existing presets greater than 0, any new custom preset added by the user will take preference in the list.

I'm thinking next step to polish stuff is to not have a pre-import popup, and instead choose pdk and color from the import window.

TODO: Update readme.md and schema.json, add "def_color" to presets and make default def_color=""

Signed-off-by: Gerard Taulats <gerardtaulats@gmail.com>
Signed-off-by: Gerard Taulats <gerardtaulats@gmail.com>
@Gerard-Taulats
Gerard-Taulats requested a review from dnltz as a code owner June 30, 2026 13:23
@Gerard-Taulats
Gerard-Taulats marked this pull request as draft June 30, 2026 13:23
Signed-off-by: Gerard Taulats <gerardtaulats@gmail.com>
Signed-off-by: Gerard Taulats <gerardtaulats@gmail.com>
Signed-off-by: Gerard Taulats <gerardtaulats@gmail.com>
Signed-off-by: Gerard Taulats <gerardtaulats@gmail.com>
@Gerard-Taulats
Gerard-Taulats force-pushed the Gerard-Taulats-dynamic-presets branch 2 times, most recently from 278f2cb to 89ea42a Compare July 6, 2026 20:55
Signed-off-by: Gerard Taulats <gerardtaulats@gmail.com>
@Gerard-Taulats
Gerard-Taulats force-pushed the Gerard-Taulats-dynamic-presets branch from 89ea42a to 0408b60 Compare July 6, 2026 21:00
@Gerard-Taulats
Gerard-Taulats marked this pull request as ready for review July 6, 2026 21:01
Comment thread import_gdsii/__init__.py Resolved
Comment thread import_gdsii/configs/gf180mcu.yaml Resolved
Comment thread import_gdsii/__init__.py Resolved
Comment thread import_gdsii/__init__.py Resolved
Comment thread import_gdsii/__init__.py
key=lambda kv: (kv[1]["order"], kv[0])
))

PDK_CONFIGS = load_pdk_configs()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use a constant variable for those information.

Comment thread import_gdsii/__init__.py
addon_dir = Path(__file__).parent
color_path = addon_dir / PDK_CONFIGS.get(pdk, {}).get('color_path', pdk)
schemes = [('realistic', 'Realistic', 'Realistic color scheme')]
pdf_dict = PDK_CONFIGS.get(pdk, {})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call load_pdk_configs instead of the constant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having mixed feelings about this. This constant is being used across 7 functions. While that'd help to maintain latest folder status, I think it's a bit too much to call this every time. What's the usual way on handling these cases? Is it the way you suggest?🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the function should be run inside "register_properties", GDSIIPreImportDialog class and Import GDSII class once, and pass around data for functions that need it. What do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, loading it once and storing it internally is the right way. I think I already did this with other data.

Comment thread import_gdsii/__init__.py Resolved
Comment thread import_gdsii/__init__.py Resolved
Comment thread import_gdsii/__init__.py Resolved
Comment thread import_gdsii/__init__.py Resolved
Signed-off-by: Gerard Taulats <gerardtaulats@gmail.com>
Signed-off-by: Gerard Taulats <gerardtaulats@gmail.com>
@Gerard-Taulats
Gerard-Taulats force-pushed the Gerard-Taulats-dynamic-presets branch from 4b9bab7 to e3a86bd Compare July 12, 2026 21:26
Signed-off-by: Gerard Taulats <gerardtaulats@gmail.com>
@Gerard-Taulats
Gerard-Taulats force-pushed the Gerard-Taulats-dynamic-presets branch 3 times, most recently from d8f394f to 0173cc8 Compare July 14, 2026 16:38
Signed-off-by: Gerard Taulats <gerardtaulats@gmail.com>
@Gerard-Taulats
Gerard-Taulats force-pushed the Gerard-Taulats-dynamic-presets branch from 0173cc8 to 22fcd80 Compare July 14, 2026 16:39
Comment thread import_gdsii/__init__.py
pdk_info = PDK_CONFIGS.get(pdk_selection, {})
addon_dir = Path(__file__).parent
yamlfile = addon_dir / pdk_info.get('config_path', 'configs/ihp-sg13g2.yaml')
yamlfile = addon_dir / pdk_info.get('config_path', f"configs/{pdk_info["file_name"]}.yaml")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude: bug: nested " inside an f-string delimited by " is a SyntaxError before Python 3.12 — this addon targets Blender 3.4+ (older Python), so the module won't even import.

Suggested change
yamlfile = addon_dir / pdk_info.get('config_path', f"configs/{pdk_info["file_name"]}.yaml")
yamlfile = addon_dir / pdk_info.get('config_path', f'configs/{pdk_info["file_name"]}.yaml')

Comment thread import_gdsii/__init__.py
colorfile = Path(custom_color_path)
else:
color_dir = addon_dir / pdk_info.get('color_path', 'configs/colors/ihp-sg13g2')
color_dir = addon_dir / pdk_info.get('color_path', f"configs/colors/{pdk_info["file_name"]}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude: bug: same nested-quote SyntaxError as the yamlfile line above.

Suggested change
color_dir = addon_dir / pdk_info.get('color_path', f"configs/colors/{pdk_info["file_name"]}")
color_dir = addon_dir / pdk_info.get('color_path', f'configs/colors/{pdk_info["file_name"]}')

Comment thread import_gdsii/__init__.py
if k not in pdk_order
}
sorted_pdks.update(dict(sorted(remaining.items())))
elif item in pdks.keys():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude: bug: _config_order.yaml lists raw file stems (ihp-sg13g2), but pdks is keyed by the uppercased form (IHP_SG13G2) from line 50 — so item in pdks.keys() and k not in pdk_order (line 77) never match, and custom ordering silently falls back to alphabetical every time. Normalize item/pdk_order entries with the same .upper().replace('-', '_') transform used on line 50 before comparing.

Comment thread import_gdsii/__init__.py
color_file = yaml.safe_load(file.read_text(encoding='utf-8'))
schemes.append((file.stem, color_file.get('name', file.stem),
color_file.get('description', file.stem)))
if file.stem==pdf_dict["def_color"]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude: bug: if pdk isn't a valid key (e.g. the stale fallback below), pdf_dict is {} and this raises KeyError.

Suggested change
if file.stem==pdf_dict["def_color"]:
if file.stem==pdf_dict.get("def_color"):

Comment thread import_gdsii/__init__.py
items = []
# TODO: Load only when accessing list or when opening file explorer, not every refresh. Or add a refresh button

pdk = getattr(context.scene, 'gdsii_pdk_selection', 'IHP_SG13G2')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude: nit: this fallback is still the old hardcoded 'IHP_SG13G2' — the rest of this PR switched to next(iter(PDK_CONFIGS)) for the same purpose (lines 625, 638, 777).

Suggested change
pdk = getattr(context.scene, 'gdsii_pdk_selection', 'IHP_SG13G2')
pdk = getattr(context.scene, 'gdsii_pdk_selection', next(iter(PDK_CONFIGS)))

Comment thread import_gdsii/__init__.py
addon_dir = Path(__file__).parent
color_path = addon_dir / PDK_CONFIGS.get(pdk, {}).get('color_path', pdk)
schemes = [('realistic', 'Realistic', 'Realistic color scheme')]
pdf_dict = PDK_CONFIGS.get(pdk, {})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, loading it once and storing it internally is the right way. I think I already did this with other data.

@Gerard-Taulats

Copy link
Copy Markdown
Contributor Author

Replaced by #43

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants