Jump to content

Anyone up to rewriting "Adjust Text to Fit Rectangle.vi" to handle CamelCase?


Recommended Posts

UPDATE: Solution posted below.

In LV2020, if you right-click on VI's panel icon, there's a new menu item: "Set Icon to VI Name". It splits the name at spaces into words and creates a nice text icon. Great!

But some places have coding conventions that require no spaces in the name -- it's easier to use git with such files. And in that case, the current code sees the VI name as all one string.

I would very much appreciate it if someone with spare time wants to rewrite this VI to handle CamelCase names:
vi.lib\LabVIEW Icon API\Set Text Icon\Adjust Text to Fit Rectangle.vi

There's a small While Loop at the left side of the diagram that splits the VI name into an array words. It needs a bit of adjustment, something like, "If input string contains spaces then do the While Loop as it stands today. Otherwise, call some function that will split the string into an array of words based on CamelCase separation."

If it helps, I found this rather amazing Stack Overflow post that provides a detailed 10-part regex expression that can successfully translate this:

Quote

__ToGetYourGEDInTimeASongAboutThe26ABCsIsOfTheEssenceButAPersonalIDCardForUser_456InRoom26AContainingABC26TimesIsNotAsEasyAs123ForC3POOrR2D2Or2R2D

into this:

Quote

To Get Your GED In Time A Song About The 26 ABCs Is Of The Essence But A Personal ID Card For User 456 In Room 26A Containing ABC 26 Times Is Not As Easy As 123 For C3PO Or R2D2 Or 2R2D

I couldn't quickly get it working, so I moved on to other projects. But it would be nice...

Edited by Aristos Queue
Link to comment
2 hours ago, Aristos Queue said:

But some places have coding conventions that require no spaces in the name -- it's easier to use git with such files.

Probably best for a new thread, but I'm curious about why you claim it's easier to use git with files with no spaces. In my (admittedly non-advanced) dealings with git I haven't seen any problems with files with spaces. Now repo names with spaces? Yes, that has caused issues. :) But I've been working with very large codebases in git containing VIs and project libraries/classes with normal naming conventions (including spaces) and have had no issues.

Link to comment
19 hours ago, Aristos Queue said:

And if we had something like "Split English CamelCase.vi"

I do have an implementation of "Split English CamelCase" that handles acronyms: https://github.com/JKSH/LQ-CodeGen/blob/labview-api/src/LabVIEW/Icons and Wires/Name to Icon Lines.vi -- It's based on a shorter regex and currently doesn't handle digits, underscores, or plurals-of-acronyms.

I won't be trying to update the icon generator or VI Analyzer within the next 2 months, but someone who wants to try is welcome to use my VI as a starting point.

Link to comment

@JKSH Thank you very much. 

Attached, folks, is a revised copy of the .lvllib and its subVIs that will set icons for camel case VI names. Just unzip it to replace the files currently in your 2020 install -- make a backup copy first in case I've done something egregious.

Text-Based VI Icon.lvlib.zip

Included in the directory is one VI that is *not* part of the library: "Configure Named Icons.vi"

If you open it, you can fill in a list of words to abbreviate and list of words to ignore. If you run the VI, these lists will be saved to your LabVIEW config file.

The regular expression parser can be improved to handle a lot more cases, if someone wants to tackle it, but this is good enough for my purposes. 

 

  • Thanks 2
Link to comment
7 hours ago, JKSH said:

@Aristos Queue You're welcome. Glad I could help.

How about storing the elements from "TextIcons.Ignore" in a Set instead of an Array?

It would be fine to do... I just didn't bother writing the conversion. The performance differences between a set and linear searching an array are essentially impossible to measure until about 1000 elements on a modern CPU.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.