Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate Series of Components #159

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Electro707
Copy link
Contributor

This PR adds the ability for populate to take a series of components with a start and end reference delimited with a -, and use all the ones in between.

For example, R3-R20 will be treated like R3,R4,R5...R19,R20

This PR also makes a copy of stdout and replaces it back. This is because during debugging, I noticed that when the click application is called, stdout no longer points to the terminal's stdout after the execution is completed.

@Electro707 Electro707 changed the title Added ability for populate to parse a series of components (for examp… Populate Series of Components Jan 6, 2024
Comment on lines 38 to 55
for i in reversed(range(len(components))):
c = components[i]
if c.count('-') == 1: # if we have a - for a range (for example R3-R9)
m = re.match(r'(\w*?)(\d+)-(\w*?)(\d+)$', c)
try:
prefix = m.group(1)
if prefix != m.group(3): # if the first and second prefix don't match, ignore
continue
start_n = int(m.group(2))
end_n = int(m.group(4))
except (IndexError, ValueError):
# if we either didn't have a full regex match, or the numbers weren't integers somehow?
continue
if start_n > end_n: # check that the first number is the lower limit (R6-R2 is not valid)
continue
# Replace XY-XZ with [XY, X(Y+1), X(Y+2), ..., X(Z-1), ZX]
components += [f"{prefix}{i}" for i in range(start_n, end_n+1)]
components.pop(i)
Copy link
Owner

Choose a reason for hiding this comment

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

Just an idea - wouldn't it be cleaner to modify PcbDraw to accept ranges as well for filtering and highlighting? We would cover another use case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah that's fair. I'll look into incorporating it directly in plot

@@ -244,11 +263,13 @@ def generate_image(boardfilename: str, side: str, components: List[str],
plot_args += ["--filter", ",".join(components)]
plot_args += ["--highlight", ",".join(active)]
plot_args += [boardfilename, outputfile]
tmp_std = sys.stdout # make a copy of stdout
Copy link
Owner

Choose a reason for hiding this comment

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

I understand that Click changes stdout. But I have two questions:

  • why it matters?
  • the comment "make a copy of stdout" adds no information. I can see you make it. But why? This is what should be in the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • in case there are any temporary debug print statements (yes I know the debugger exists, but at times it's easier for quick debug sessions)
  • can iterate in the comment if it's worth keeping

@yaqwsx yaqwsx force-pushed the master branch 2 times, most recently from 51ee017 to d2af9d4 Compare March 25, 2024 06:39
for i in reversed(range(len(components))):
c = components[i]
if c.count('-') == 1: # if we have a - for a range (for example R3-R9)
m = re.match(r'(\w*?)(\d+)-(\w*?)(\d+)$', c)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why (\w*?)? This will match things like 1-10, is this desirable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not intentional. Will replace with [a-zA-Z]

Copy link
Contributor

Choose a reason for hiding this comment

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

Also force "1 or more", don't allow 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Also re-based with master

set-soft added a commit to INTI-CMNB/KiBot that referenced this pull request Mar 27, 2024
- In the `show_components` and `highlight` options.
- So one entry can be something like *R10-R20*.
- Can be disabled using the global option `allow_component_ranges`.

Idea from yaqwsx/PcbDraw#159
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.

3 participants