Skip to content

Populate Series of Components#159

Open
Electro707 wants to merge 4 commits intoyaqwsx:masterfrom
Electro707:pr_populate_multiple
Open

Populate Series of Components#159
Electro707 wants to merge 4 commits intoyaqwsx:masterfrom
Electro707:pr_populate_multiple

Conversation

@Electro707
Copy link
Copy Markdown
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 thread pcbdraw/populate.py Outdated
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
Copy Markdown
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
Copy Markdown
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

Comment thread pcbdraw/populate.py Outdated
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
Copy Markdown
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
Copy Markdown
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
Comment thread pcbdraw/populate.py Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@Electro707 Electro707 force-pushed the pr_populate_multiple branch from c822fb2 to eea9aec Compare April 7, 2024 04:32
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