Line2PEx - An improved line command?

This forum is for QCAD user developed script Add Ons and Plug-ins.
Please use this forum to request/submit your script Add-Ons & Plug-in idea's.

Moderators: Clive, andrew, Husky

Line2PEx - An improved line command?

Postby riverbuoy » Sat Jan 25, 2014 4:02 am

Line2PEx - An improved Line command?

I have made some changes and added new features to the Line command. I think
this is an improvement, but do you? It would be useful to get some feedback.
The shortcut for this command is LX, or use linex or lx in the command line.

The attached zip file contains the Line2PEx subdirectory. Extract this to the
'scripts/Draw/Line' subdirectory.
This does not replace the existing line command, but adds a new line command,
using the same icon, but with the letters 'Ex' added to the icon. In this
instance Ex could stand for extended or expanded line command. But the
features I have added could be most useful to experienced users. However, for
now, it stands for experimental. There is no guarantee there are no bugs in
this command. If you find one please let me know.

I have used 'lupdate' to replace the ts files in the ts subdirectory.
Unfortunately I don't have enough knowledge of any foreign languages to
translate any of the files. I will need to leave it to someone else, sorry.
I have also updated the english html files in the doc subdirectory. Again I
will need to leave it to others to translate.

I have made the following changes.
The first change was to add a Redo command, and I added a new button to the
options toolbar. The icon for 'redo' is the 'undo' icon flipped horizontally.
When adding the button, I also assigned the keys C, U and R to the close, undo
and redo buttons. So in drawing mode you only have to press the C, U or R keys
to invoke the function. (Clicking the buttons still works).
This command differs slightly from the standard redo command. With the standard
redo, if you undo one or more line segments and then select or enter a co-
ordinate, the standard redo is no longer available. However the redo I added is
still available, and if you select or enter a co-ordinate, and then select
redo, a line will be drawn from the current position to the last undone point.
If there are more undone points you can continue to redo back to where you
started from.

Next, I decided it would be useful to be able to enter the commands in the
command line (as you could in earlier versions). So I added a command event
function to check for commands entered in the command line. However, I don't
want to type the whole command in full, I just want to be able to type as few
letters as required to distinguish between the commands. So I used the
'startsWith' function to check for commands. In this case close, undo and redo
start with different letters, so you only have to enter c, u or r, followed by
enter or return to select the command. (Because I used 'startsWith', typing
"c", "cl", "clo", "clos" and "close", will all select the close command.
Similarly this also works with undo and redo.).

After this, I then decided to change the prompt on the command line to inform
the user what options are available after each point selected, or command
entered. So I created a new function 'setPrompt'.
So the 'First point' prompt is the same. After selecting the first point the
prompt changes to 'Next point'. After selecting a second point, the prompt
changes to 'Next point or [Undo]'. Choosing a third point, the prompt changes
to 'Next point or [Close/Undo]'. If you undo a line segment, the prompt
changes to 'Next point or [Close/Undo/Redo]'.
Notice, the first character of each command is upper case to indicate to the
user what characters to enter in the command line to select that command. In
this case only one character is needed.
But, if you had three commands:- 'close', 'copy' and 'clear', checked for
in that order, the prompt could be '...[Close/COpy/CLEar]'. As 'close' is
checked for first, then 'c' is enough to select it. Copy is checked for next,
so 'co' distinguishes it from close. Clear is checked next. Close starts with
'cl', so we need 'cle' to distinguish clear from close.

Next I added a 'keyPressEvent' function. This checks for the 'enter' or
'return' key being pressed. If the current prompt is 'First point', then
pressing enter or return causes the first point to be set to the last position
in the drawing.

The next feature was inspired by LibreCAD's line command. If you hold the
shift key when selecting a point with the mouse, the angle of the line will
be constrained to the nearest multiple of fifteen degrees.
I thought this could be useful, not only for selecting points with the mouse,
but also when entering distances. At the moment, using 'restrictOrthogonal' or
snapping to grid points, is restricting for using exact angles with distances.
However, I don't want to use the shift key, and I don't want to be limited to
fifteen degrees. So I have added an option to the options toolbar, a button
labelled 'Restrict to multiple of', followed by a spinbox containing the angle
you want to restrict to multiples of. The default is fifteen degrees, but you
can enter any value between 0.0 and 90.0 degrees.
If you set the angle to 0.0 degrees, then you effectively switch off the
command. But you can toggle 'restrict' on and off using the T key, or entering
't' in the command line.
If you set the angle to 90.0 degrees, this is equivalent to using
'restrictOrthogonal'.

When testing this feature, it occured to me that it would be useful to show
the angle of the nearest multiple in preview mode, especially for short line
segments. So I added this feature. However I realised that showing the angle
with every mouse move could become annoying. So I added the 'Display Angles'
button to the options toolbar. You can toggle the display of angles on and off
by pressing the D key, or entering 'd' in the command line. This only works
when 'Restrict to multiple of' is enabled.
If you enter an absolute or relative co-ordinate then 'restrict' is over-ridden
by the co-ordinate. Also the 'close' command ignores the 'restrict' setting.

I hope you find this useful. But also let me know what you think. For example,
is this command now too fussy, confusing or complicated for new users?

riverbuoy
Attachments
Line2PEx.zip
(32.42 KiB) Downloaded 64 times
riverbuoy
Active Member
 
Posts: 34
Joined: Thu Oct 03, 2013 5:37 pm

Re: Line2PEx - An improved line command?

Postby Clive » Sat Jan 25, 2014 2:18 pm

riverbuoy wrote:I have made some changes and added new features to the Line command. I think
this is an improvement, but do you? It would be useful to get some feedback.

Hi riverbuoy, just spent a few minutes testing your new feature and 'WOW' 8) - I'll say its useful. Everything seems to be working good for me so far..but I'll let you know if I come across any bugs.
riverbuoy wrote: For example,
is this command now too fussy, confusing or complicated for new users?

No I personally don't think so, I think its the opposite - very helpful, well done riverbuoy and thankyou very much indeed :D .
Clive
User avatar
Clive
Moderator
 
Posts: 898
Joined: Thu Aug 25, 2011 9:28 pm
Location: UK

Re: Line2PEx - An improved line command?

Postby Husky » Sun Jan 26, 2014 9:14 pm

Hi riverbuoy,

I see you kept your self busy - GOOD FOR US! 8) 8) 8) Thanks for doing that!!

I installed the new Tool and I like it. I started testing for me to see how this tool could improve my CAD life - and of course ... I'm looking for bugs :lol: :lol: :lol:

Here are my first impression:

riverbuoy wrote:I have made the following changes.
The first change was to add a Redo command, ...
Nice!

riverbuoy wrote:Next I added a 'keyPressEvent' function. This checks for the 'enter' or
'return' key being pressed. If the current prompt is 'First point', then
pressing enter or return causes the first point to be set to the last position
in the drawing.
Yep - really helpful - I would like to have that with all tools ... :wink:

riverbuoy wrote:The next feature was inspired by LibreCAD's line command. If you hold the
shift key when selecting a point with the mouse, the angle of the line will
be constrained to the nearest multiple of fifteen degrees.

This is a very old feature what is used since ever in Windows - you can find it since many decades in all kinds of drawing Programs.
However - I like a function to control with the mouse and a key the angles of a line - and I was missing this option in QCAD. But I can't ask for everything .... 8)
So, that means I'm more than happy to see it now in your new Line tool - Ok, without using a key but I think your solution fits the task!

riverbuoy wrote:... it occured to me that it would be useful to show
the angle of the nearest multiple in preview mode, especially for short line
segments.
Indeed a nice and useful extra!

riverbuoy wrote: ...is this command now too fussy, confusing or complicated for new users?

I have to agree with clive: No, not at all!!!

Ok, long story short: My personal opinion on this new tool is that I like it - that I need it!
I think it should replace the old "Line 2 Points" tool and additional I like to see all remaining drawing tools in QCAD with this new "Return - > jump to the last active Point" for a new first point ... option. :wink:

Thank you very much riverbuoy for working on something like this - well done!!!
User avatar
Husky
Moderator
 
Posts: 622
Joined: Wed May 11, 2011 9:25 am
Location: USA

Re: Line2PEx - An improved line command?

Postby andrew » Wed Jan 29, 2014 10:18 am

riverbuoy: Thanks for this valuable contribution!

I've briefly tested the tool and it works great.

When adding the button, I also assigned the keys C, U and R to the close, undo
and redo buttons. So in drawing mode you only have to press the C, U or R keys
to invoke the function. (Clicking the buttons still works).


Note that this breaks other key codes which start with these letters while the LX tool is active.
For example, if you are drawing lines (LX) and at some point you want to quickly trim a line and then continue drawing lines, you could press RM for trim, then Escape and you're back to drawing lines. The keycode RM does not work as long as LX is active since R is used for the redo command. Possible workarounds would be to use unique two-letter codes for these buttons or something like Ctrl-R or perhaps Shift-C, Shift-U, Shift-R? Maybe someone has a better idea?

I agree that this should replace the line (LI) command.
How about including this tool for a wider audience as additional tool in the next release and schedule it to replace the LI tool in the release after that?
That would give us the chance to gather some feedback first.

The tool is now checked into git at:
https://github.com/qcad/qcad/tree/maste ... e/Line2PEx

riverbuoy: Please let me know if you have a github account, so I can add you as collaborator.
User avatar
andrew
Site Admin
 
Posts: 2524
Joined: Fri Mar 30, 2007 6:07 am

Re: Line2PEx - An improved line command?

Postby Clive » Wed Jan 29, 2014 10:35 am

The great thing about this new tool is that drawing with the isometric grid has now become so much easier :wink: .
Clive
User avatar
Clive
Moderator
 
Posts: 898
Joined: Thu Aug 25, 2011 9:28 pm
Location: UK

Re: Line2PEx - An improved line command?

Postby riverbuoy » Thu Jan 30, 2014 11:04 pm

Hi all

Thanks for your feedback and kind words.

Andrew wrote:
Note that this breaks other key codes which start with these letters while the LX tool is active.


I was aware that these would stop shortcuts from working, but I was thinking that users wouldn't want to use other commands while using the line command. Your trim example convinces me that users may well use other commands while in the line command.

Andrew wrote:
Possible workarounds would be to use unique two-letter codes for these buttons or something like Ctrl-R or perhaps Shift-C, Shift-U, Shift-R? Maybe someone has a better idea?


Thinking about this, I looked at the codes that are being used and keys that can be accessed on the keyboard without having to use the shift key. I decided to use the stroke key ('/'). Most people use the American name 'slash' but the UK name is stroke. Slash always makes me think of the shower scene in Alfred Hitchcock's film 'Psycho'. :shock: :)
Therefore I changed the shortcuts in Line2PEx.ui to '/C', '/U', '/R', '/T' and '/D', so they no longer clash with any other shortcuts. I also thought that you could reserve the use of the stroke command to be used as the first character of all shortcuts when accessing items in the options toolbar. So each command with items in the options toolbar should start their shortcuts with the stroke character, and you could use the same shortcuts without affecting other commands.
To test this I added shortcuts to the draw polyline command. I set the shortcut for the close button to '/C' and '/U' for the undo button, the same as used in the line command. I then ran the line command and drew some line segments, but didn't close them at this point. Then I started the polyline command and drew some polyline segments. Using '/U' undid the polyline segments, leaving the line segments unchanged. Using '/C' closed the polyline, leaving the line segments unchanged. I then exited the polyline command and returned to the line command and typed '/C' which closed the line segments.
So commands could use their own shortcuts without having to worry about other command's shortcuts. Also you are not limited to just two characters. For example if you had two commands - clear and copy- you could set the shortcuts to '/CL' and '/CO'. But you could also just use '/C' for clear and '/O' for copy. This would be up to the command's author.
So my suggestion is to reserve the stroke character for shortcuts to items in the options toolbar, and ensure that they all start with stroke. As stroke is currently not used, this would be the time to make such a decision. (Of course you could use another character and reserve the use of that character).

Andrew wrote:
How about including this tool for a wider audience as additional tool in the next release and schedule it to replace the LI tool in the release after that?
That would give us the chance to gather some feedback first.


This is an excellent idea and I agree completely. I changed the name to Line2PEx precisely so that users could test it and provide feedback.

Andrew wrote:
Please let me know if you have a github account


I don't use github or any other version control system.


riverbuoy
riverbuoy
Active Member
 
Posts: 34
Joined: Thu Oct 03, 2013 5:37 pm

Re: Line2PEx - An improved line command?

Postby Husky » Fri Jan 31, 2014 3:08 am

riverbuoy wrote:Thinking about this, I looked at the codes that are being used and keys that can be accessed on the keyboard without having to use the shift key.

Please - consider how many countries around the world have to use the shift key to reach the "/"!

... uni-regensburg.de/EDV/Misc/KeyBoards/
(@Andrew: Please unlock this url)

Simple math for those Keyboard user: They need now for the new commands 3 keys .... :cry:
User avatar
Husky
Moderator
 
Posts: 622
Joined: Wed May 11, 2011 9:25 am
Location: USA

Re: Line2PEx - An improved line command?

Postby riverbuoy » Fri Jan 31, 2014 9:54 pm

Husky wrote:
Please - consider how many countries around the world have to use the shift key to reach the "/"!


Oops! Sorry about that. :oops:
Thanks for the great link to keyboard layouts. I have now added this to my bookmarks.
My thinking was to try and find a non alphanumeric character which has not yet been used, and probably won't be used in any future shortcuts. Looking at all the layouts the only constant keys seem to be shift, control, alt, return and backspace. I would like to avoid using shift, control and alt, because I like to keep my right hand on the mouse and type the shortcuts with my left hand. Using shift, control or alt means stretching trying to reach a key. That leaves the backspace key which is on every keyboard. I tested this and it works. So in drawing mode 'backspace,C' closes line segments, and in command line mode, 'backspace,C' works as expected. However I am not sure if this is a good idea.
The next candidates are dot and comma. However most russian keyboard layouts need to use shift to access these keys.
Failing this it appears that the letters K and W are not used to start any shortcut.
So should it be backspace, dot, comma, K, W or something else?

What do you think?

riverbuoy
riverbuoy
Active Member
 
Posts: 34
Joined: Thu Oct 03, 2013 5:37 pm

Re: Line2PEx - An improved line command?

Postby andrew » Sat Feb 01, 2014 1:43 pm

Backspace is used for deleting the current selection on Mac OS X (since there is no delete key on Mac computers, respectively, the key labeled 'delete' is in fact backspace.

I agree, that all option tool bar widgets should be accessible through key codes starting with the same key.

I'd suggest to go with '/' for now. This can relatively easily be made configurable in the future by automatically substituting '/' in all option tool bar widget keycodes with something else, based on a user preference.

By the way, 'W' is used to display tool bars (WA for the arc toolbar, WL for the line toolbar, etc).
User avatar
andrew
Site Admin
 
Posts: 2524
Joined: Fri Mar 30, 2007 6:07 am

Re: Line2PEx - An improved line command?

Postby riverbuoy » Sat Feb 01, 2014 10:56 pm

When thinking about this, it suddenly occurred to me that if you could turn off all the options with one simple command that could be the answer to this. We could keep the single letter shortcuts (for speed), and turn off the options when you want to use another command.
After much trial and error, I discovered that if you put the options into a groupBox (using QDeigner) you can toggle the groupBox on and off. When you set the 'enabled' property to false, all the items in the box are also disabled, and it takes care of remembering the settings for each item. I then decided to use 'Alt-Z' to toggle the options on and off. So I added a keyReleaseEvent function to Line2PEx.js to check for this. (Note: I set the title of the groupBox to an empty string, and chose the flat shape which doesn't draw a border, so the options look exactly the same.).
So I changed two files:- Line2PEx.js and Line2PEx.ui. I have attached these two files, so just replace the current ones to get this new functionality. So while using the line command just type Alt-Z followed by the two letter shortcut for the command you want. Because all the options are off they won't cause any conflicts with existing shortcuts.
When you exit that command, control returns automatically to the line command and the groupBox is enabled so you don't need to type Alt-Z to turn it back on. (This wasn't my doing, QCAD seems to do it automatically).

Is this the answer? Let me know what you think.

riverbuoy
Attachments
Line2PEx.ui
(6.13 KiB) Downloaded 52 times
Line2PEx.js
(14.49 KiB) Downloaded 52 times
riverbuoy
Active Member
 
Posts: 34
Joined: Thu Oct 03, 2013 5:37 pm

Re: Line2PEx - An improved line command?

Postby Husky » Sun Feb 02, 2014 9:32 am

riverbuoy wrote:So I changed two files:- Line2PEx.js and Line2PEx.ui.


Hi riverbuoy,

thanks for the new files - I will test them for me! My first impression was .... a kind of tight feeling :lol:

Could you provide a couple more pixel in the hight of the bar?
This occurs on Win XP/32

Husky-2014.02.02-01.png
Husky-2014.02.02-01.png (17.8 KiB) Viewed 1728 times


It wasn't a problem with the forerunner version ...
Thanks!
User avatar
Husky
Moderator
 
Posts: 622
Joined: Wed May 11, 2011 9:25 am
Location: USA

Re: Line2PEx - An improved line command?

Postby riverbuoy » Sun Feb 02, 2014 9:40 pm

Sorry about that. I had changed the vertical size policy to fixed instead of preferred. So I have changed it back to preferred. Unfortunately I don't have Windows to test this (I use linux), so I can't guarantee this.
However I have attached the changed file.
Attachments
Line2PEx.ui
(7.38 KiB) Downloaded 55 times
riverbuoy
Active Member
 
Posts: 34
Joined: Thu Oct 03, 2013 5:37 pm

Re: Line2PEx - An improved line command?

Postby Husky » Sun Feb 02, 2014 9:49 pm

Hi,

my QCAD is adjusted for Decimal Points as dot instead of comma.
Application Preferences, General, Coordinate Format, Decimal Point: Dot '.'(Default)

Nevertheless the new line tool ignores my settings and works only with comma.

Husky-2014.02.02-01.png
Husky-2014.02.02-01.png (2.67 KiB) Viewed 1708 times


Is it possible to change that ..... ? e_surprised
User avatar
Husky
Moderator
 
Posts: 622
Joined: Wed May 11, 2011 9:25 am
Location: USA

Re: Line2PEx - An improved line command?

Postby Husky » Sun Feb 02, 2014 10:00 pm

riverbuoy wrote:Sorry about that.

No Problem!!!

Thanks for the new file - it works! :D
User avatar
Husky
Moderator
 
Posts: 622
Joined: Wed May 11, 2011 9:25 am
Location: USA

Re: Line2PEx - An improved line command?

Postby andrew » Wed Feb 12, 2014 11:18 am

riverbuoy: There is a new bug report for this tool at:
http://www.qcad.org/bugtracker/index.ph ... sk_id=1020

I think this problem could be easily fixed by using an RMathLineEdit instead of a spin box for the angle input. What do you think?
User avatar
andrew
Site Admin
 
Posts: 2524
Joined: Fri Mar 30, 2007 6:07 am

Next

Return to QCAD 3 ' script Add-On & Plug-in challenge '

Who is online

Users browsing this forum: No registered users and 1 guest