Author Topic: Getting specific type of user input  (Read 2092 times)

0 Members and 1 Guest are viewing this topic.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Getting specific type of user input
« on: January 18, 2017, 06:25:55 PM »
I think that I am doing what I usually do, overthink the issue. I could use a hand with this....I need to get user input of Point Numbers. These will always be positive and non-zero. The user may respond with just a single number, or multiple numbers separated by a comma, or a range of numbers separated by a hyphen. So any of these scenarios are valid:
23
23,28,25
23-25
20,23-25,46,50,100-123

I don't believe that the GetInteger() method will work since it's a string being returned. So I need to use GetString() with the PromptStringOptions property Allow spaces set to false. My question is, how do I force the input to be in the correct format? Only allow positive integers, separated by a single comma, and/or positive integers separated by a single hyphen, and disallow all other input (other than ENTER or ESC)?

I'm hoping that I've just overlooked something relatively simple and you all can show me the path. Thanks!


kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2138
  • class keyThumper<T>:ILazy<T>
Re: Getting specific type of user input
« Reply #1 on: January 18, 2017, 08:16:12 PM »

I think you'll need to build your own parser for the string Jeff.

Using a tilde ( ~) for range may save some confusion asserting no negative numbers.

Do you want the return to be a list of integers ?

I assume you want duplicates removed from the final result ?

I'd be tempted to just ignore any minus characters ( perhaps advise the user you have done so ... " naughty girl, do better next time" )

Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Atook

  • Swamp Rat
  • Posts: 1029
  • AKA Tim
Re: Getting specific type of user input
« Reply #2 on: January 18, 2017, 08:52:41 PM »
I think parsing a string is the way to go. To filter the input as the user is entering, I can think of two options:

  • Build a little dialog with text box, and filter on the TextChanged event.
  • Add/Remove an IMessageFilter to the Application while receiving input and filter bad input there.
I'd opt for the first.

I'd imagine there's a regex expression you could use for filtering the string, though regex is above my paygrade.

There might be a cleaner way to do it, but someone else would will to chime in with it.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2138
  • class keyThumper<T>:ILazy<T>
Re: Getting specific type of user input
« Reply #3 on: January 18, 2017, 09:36:46 PM »

The parser is fairly simple.
Split the input string on ','

iterate the result of split
If the item contains a tilde , split the item.
   assert first and last are numeric
   build a range from abs(first) to abs(last)
   add this to result list.

else
   assert item is numeric
   add abs(item) to result list
   add abs

Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Getting specific type of user input
« Reply #4 on: January 18, 2017, 10:39:34 PM »
Thanks, guys. Kerry, I already have a parser which works great to convert the string to an array of integers. My desire is to insure the string is created properly as the user enters the numbers of interest. Atook, I was hoping to keep it all on the command line, but had considered using a form so I can easily test the keypress event for either a digit, comma, or hyphen being entered and whether it is at an applicable location (hyphen can only follow a digit; comma can only follow a digit, both a comma and hyphen must be followed by a digit). So I guess a small form is what is needed.

n.yuan

  • Bull Frog
  • Posts: 348
Re: Getting specific type of user input
« Reply #5 on: January 19, 2017, 10:08:17 AM »
This is interesting topic on user experience. Thinking how thing going from user's perspective, I think, command line input should be used for simple input. When you allow user to input multiple numbers, and numbers in a range, it is a bit beyond "simple": we can imagine the user would pause to figure out what range she would enter. So, in this particular case, I'd prefer asking user to input single number at command line and give option for multiple number input via a small form, using GetInteger() with keyword, like:

"Enter one point number: (Multiple/Cancel) <Multiple> "

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Getting specific type of user input
« Reply #6 on: January 19, 2017, 10:44:44 AM »
Let me explain why I wanted to do this... There are many Civil 3D users who have been using the Land Development Desktop application for years. When selecting points to edit, move, rotate, etc. they are used to the following (taken from the LDD help file):

Several point commands display the following prompt, which you can use to create a selection set of points:

Points to Lock (All/Numbers/Group/Selection/Dialog) ? <All>:

Type All to select all the points in the project.
Type Numbers to specify point numbers or names.
Type Group to specify a point group.
Type Selection and then select the points from the drawing. This option only selects points that are visible in the drawing.
Type Dialog to select points by specifying descriptions keys, point groups, elevations, numbers, descriptions, names, and XDRefs.
Specifying Point Numbers
When you use the Numbers option, separate each number with a comma (,), or type a range of points by using a hyphen (for example, type 1-5).

So the command line entry is something they are very accustomed to and I am trying to make their transition to C3D as seamless as possible. I've already been bitten by the inability to use the All option as a keyword in .NET, as that is predefined and cannot be overridden, at least not that I have been able to find. Subsequent editing commands will reuse the last entered option and point list, as seen by this command sequence o rotate points:

Command:
Points to Rotate (All/Numbers/Group/Selection/Dialog) ? <All>: n
Point Numbers <>: 1-5,15-20

Base point for rotation:
Angular units: Degrees/Minutes/Seconds (DD.MMSS)
Rotation angle: 20

Command:
LDD
Points to Rotate (All/Numbers/Group/Selection/Dialog) ? <Numbers>:

Point Numbers <1-5,15-20>: *Cancel*

One small change to this is that if the Number option is selected and the user wants to input Names instead, then they will need to enter N again as a Keyword so I can differentiate between the Number or Name entry. Most of the users I've spoken with do not use the name option so figured that would be the easiest way to implement it.
« Last Edit: January 19, 2017, 10:53:56 AM by Jeff_M »

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Getting specific type of user input
« Reply #7 on: January 28, 2017, 04:09:49 PM »
Following up on this, I went back to Land Desktop and ran a command using the point number option. It allows any entry, but then validates it when the user hits Enter. If an incorrect range is entered, i.e. "1x-5" instead of "1-5", a message box is displayed with the incorrect list entry. I have adopted this same strategy and it seems to be working fine now. As usual, I was over thinking the problem.... :-)