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
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
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
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?
- (32.42 KiB) Downloaded 217 times