Line2PEx - An improved line command?
Moderators: andrew, Husky, J-J
Re: Line2PEx - An improved line command?
Having looked into this, the spinbox uses the locale of the computer it is running on, unless a specific locale has been assigned to the spinbox. The decimal point character can't be changed or overwritten, and changing the specific locale would not be a simple matter for users. As Andrew suggested, using an RMathLineEdit box is the easiest way to solve this.
I have attached the two affected files - Line2PEx.ui, and Line2PEx.js. Replace these two files in Draw->Line->Line2PEx.
Using an RMathLineEdit input, you can type any value into the box, or even an expression. If you enter a negative number then the restrict changes it to a positive number.
I have included the options in a group box so you can toggle them on and off using Alt-Z. When toggled off they won't interfere with existing shortcuts. Because other commands can change the position of relativezero I store its position when using another command, and restore it when control is returned to this command.
Hope this fixes the problem.
I have attached the two affected files - Line2PEx.ui, and Line2PEx.js. Replace these two files in Draw->Line->Line2PEx.
Using an RMathLineEdit input, you can type any value into the box, or even an expression. If you enter a negative number then the restrict changes it to a positive number.
I have included the options in a group box so you can toggle them on and off using Alt-Z. When toggled off they won't interfere with existing shortcuts. Because other commands can change the position of relativezero I store its position when using another command, and restore it when control is returned to this command.
Hope this fixes the problem.
- Attachments
-
- Line2PEx.ui
- (3.82 KiB) Downloaded 927 times
-
- Line2PEx.js
- (15.32 KiB) Downloaded 899 times
Re: Line2PEx - An improved line command?
Thanks riverbuoy. I've noticed that you did not copy the changes I've made into your version (translation related). This means, I will have to re-apply my changes everytime you post a new version:
https://github.com/qcad/qcad/commit/1a9 ... 1232e9a192
For this reason, we actually use a version control system (git) which manages changes over time and allows merging. Perhaps that is something to look into in the future? Version control systems are among those tools you never wish to miss anymore once you start using them
https://github.com/qcad/qcad/commit/1a9 ... 1232e9a192
For this reason, we actually use a version control system (git) which manages changes over time and allows merging. Perhaps that is something to look into in the future? Version control systems are among those tools you never wish to miss anymore once you start using them
Re: Line2PEx - An improved line command?
Hi riverbuoy,
I briefly tested the fix and my first impression is: Much better! Thanks!
Question: If I use the wrong decimal point character it will show me the wrong value in red - but the tool is still, in limits, usable.
If I compare this with the "Line from Angle LA" tool it will warn me with the value in red and block the tool completely.
I think that makes sense - is it possible to have the same behavior in your tool?
Additional thought: Would it make sense to add on the displayed angle the decree character so that we can see a 3.5° or 7° etc info in the drawing?
I briefly tested the fix and my first impression is: Much better! Thanks!
Question: If I use the wrong decimal point character it will show me the wrong value in red - but the tool is still, in limits, usable.
If I compare this with the "Line from Angle LA" tool it will warn me with the value in red and block the tool completely.
I think that makes sense - is it possible to have the same behavior in your tool?
Additional thought: Would it make sense to add on the displayed angle the decree character so that we can see a 3.5° or 7° etc info in the drawing?
Re: Line2PEx - An improved line command?
I have changed Line2PEx.js, as I found two issues.
First, trying to use a groupBox in the options toolbar is just too problematic. So I changed the key sequence 'Alt-Z' to disable the options toolbar. Once disabled, you can then type any shortcut without it conflicting with the line options. (If the shortcut doesn't start with 'C', 'U', 'R', 'T' or 'D' then you can just type the shortcut). If you type a shortcut then the option toolbar is re-enabled, and the position of relativezero is saved. When you return to the line command, the toolbar is enabled and relativezero is put back to where it was.
The second issue concerns returning to the line command. If, for example, you draw a circle and then return to the line command, and the undo button is enabled, then undo uses the system undo, so instead of deleting the last line segment, it will delete the circle and move relativezero to the previous position. So now you've deleted the circle you just drew and relativezero is in the wrong position.
I changed undo to use transactions instead of the system undo. So now when you press undo it will delete the last line segment and not the circle.
I have attached the file 'Line2PEx.js'. Replace the existing file with this one.
First, trying to use a groupBox in the options toolbar is just too problematic. So I changed the key sequence 'Alt-Z' to disable the options toolbar. Once disabled, you can then type any shortcut without it conflicting with the line options. (If the shortcut doesn't start with 'C', 'U', 'R', 'T' or 'D' then you can just type the shortcut). If you type a shortcut then the option toolbar is re-enabled, and the position of relativezero is saved. When you return to the line command, the toolbar is enabled and relativezero is put back to where it was.
The second issue concerns returning to the line command. If, for example, you draw a circle and then return to the line command, and the undo button is enabled, then undo uses the system undo, so instead of deleting the last line segment, it will delete the circle and move relativezero to the previous position. So now you've deleted the circle you just drew and relativezero is in the wrong position.
I changed undo to use transactions instead of the system undo. So now when you press undo it will delete the last line segment and not the circle.
I have attached the file 'Line2PEx.js'. Replace the existing file with this one.
- Attachments
-
- Line2PEx.js
- (15.83 KiB) Downloaded 1036 times
Re: Line2PEx - An improved line command?
QCAD 3.6.0 comes with a new snap restriction tool which was designed to offer similar functionality as the Line2PEx to all tools:
Snap > Restrict Angle or Length
The new tool can be used similarly like Line2PEx:
- Start the regular line drawing tool Draw > Line > Line from 2 Points
- Set the start point of the line
- Click the restrict tool button in the line options tool bar (or the same button in the CAD tool bar at the left or choose menu Snap > Restrict Angle or Length or enter the key code EA): - You can now enter a restriction angle (and optionally a restriction distance): QCAD snaps to multiples of the given angle and distance.
This tool can be used in combination with any drawing or modification tool, whenever a coordinate is requested.
I've decided against displaying the angle / length inside the drawing space for now, although the code is still in Viewport.js, commented out under '// snap restriction info:' if someone wants to try it.
The angle and distance used are always visible in the status bar of course: I understand that this a bit of a compromise, compared to the Line2PEx tool, so the original Line2PEx tool is still available under Misc > Drawing, same keycode as before.
As usual, any feedback is welcome.
Snap > Restrict Angle or Length
The new tool can be used similarly like Line2PEx:
- Start the regular line drawing tool Draw > Line > Line from 2 Points
- Set the start point of the line
- Click the restrict tool button in the line options tool bar (or the same button in the CAD tool bar at the left or choose menu Snap > Restrict Angle or Length or enter the key code EA): - You can now enter a restriction angle (and optionally a restriction distance): QCAD snaps to multiples of the given angle and distance.
This tool can be used in combination with any drawing or modification tool, whenever a coordinate is requested.
I've decided against displaying the angle / length inside the drawing space for now, although the code is still in Viewport.js, commented out under '// snap restriction info:' if someone wants to try it.
The angle and distance used are always visible in the status bar of course: I understand that this a bit of a compromise, compared to the Line2PEx tool, so the original Line2PEx tool is still available under Misc > Drawing, same keycode as before.
As usual, any feedback is welcome.
Re: Line2PEx - An improved line command?
Hi Andrew,
Your two new entities, Ray and XLine, are great, and combining them with the line command is an excellent idea.
'Snap to Angle or Distance' is also great. I briefly thought about trying to do a similar thing when adding Restrict to the 'line' command, but my knowledge of the inner workings of QCAD is limited, and I realised it would be too dificult for me to do. So, I took the easy way out and resorted to using ECMAScript.
As you point out, your new restriction applies to all commands expecting coordinate input, which is far better. (By the way, I was just about to post 'DrawPolylineEx', which has the same additions as 'Line2PEx'. ). I think your new line command is the way to go.
Your hard work is much appreciated.
Now, I don't want to rain on your parade, but has anyone pointed out that the shortcut EA conflicts with 'Ellipse Arc'?
Playing with the line command, I noticed that the 'close' function doesn't move relativezero. This may be by design, but I would prefer it to move to the first point.
Similarly, if you start another command while in the line command, and relativezero is moved, when you exit that command, relativezero isn't returned to its original position.
Could I suggest, as an alternative to using single letter shortcuts, that you add two letter shortcuts to the Close, Undo and Redo buttons in the options toolbar? My suggestions would be CL, UN and RD (RE is already used for rectangle).
Could I also suggest adding the check for the 'enter' or 'return' key being pressed, and 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? Husky, at least, thought this was a good idea.
I noticed that you added the distance to 'Display Angle', which is good. However, adding the code to 'snap info' means that the display is always on, which as I said might be annoying at times. Would it be possible for me to add a toggle button to the 'restrict to angle or distance' options toolbar, and add the display code to 'RestrictAngleLength.js'?
Perhaps you could have a vote on whether or not users want this feature.
Finally, if the restriction is active when trying to select the first point, it can stop you selecting the exact point you want. (This is also the same for the 'orthogonal', 'horizontal' and 'vertical' restrictions). Now I know you can easily switch it off using the button, but would it be better to switch off restrictions while selecting the first point?
I would be quite willing to make these changes and send them to you. Perhaps you could let me know what you think?
Anyway thanks again for these great additions.
riverbuoy
Your two new entities, Ray and XLine, are great, and combining them with the line command is an excellent idea.
'Snap to Angle or Distance' is also great. I briefly thought about trying to do a similar thing when adding Restrict to the 'line' command, but my knowledge of the inner workings of QCAD is limited, and I realised it would be too dificult for me to do. So, I took the easy way out and resorted to using ECMAScript.
As you point out, your new restriction applies to all commands expecting coordinate input, which is far better. (By the way, I was just about to post 'DrawPolylineEx', which has the same additions as 'Line2PEx'. ). I think your new line command is the way to go.
Your hard work is much appreciated.
Now, I don't want to rain on your parade, but has anyone pointed out that the shortcut EA conflicts with 'Ellipse Arc'?
Playing with the line command, I noticed that the 'close' function doesn't move relativezero. This may be by design, but I would prefer it to move to the first point.
Similarly, if you start another command while in the line command, and relativezero is moved, when you exit that command, relativezero isn't returned to its original position.
Could I suggest, as an alternative to using single letter shortcuts, that you add two letter shortcuts to the Close, Undo and Redo buttons in the options toolbar? My suggestions would be CL, UN and RD (RE is already used for rectangle).
Could I also suggest adding the check for the 'enter' or 'return' key being pressed, and 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? Husky, at least, thought this was a good idea.
I noticed that you added the distance to 'Display Angle', which is good. However, adding the code to 'snap info' means that the display is always on, which as I said might be annoying at times. Would it be possible for me to add a toggle button to the 'restrict to angle or distance' options toolbar, and add the display code to 'RestrictAngleLength.js'?
Perhaps you could have a vote on whether or not users want this feature.
Finally, if the restriction is active when trying to select the first point, it can stop you selecting the exact point you want. (This is also the same for the 'orthogonal', 'horizontal' and 'vertical' restrictions). Now I know you can easily switch it off using the button, but would it be better to switch off restrictions while selecting the first point?
I would be quite willing to make these changes and send them to you. Perhaps you could let me know what you think?
Anyway thanks again for these great additions.
riverbuoy
Re: Line2PEx - An improved line command?
Thanks.riverbuoy wrote:Your two new entities, Ray and XLine, are great, and combining them with the line command is an excellent idea.
Sorry about that. I should have let you know that I'm working towards that direction.(By the way, I was just about to post 'DrawPolylineEx', which has the same additions as 'Line2PEx'. ).
Thanks for pointing that out. I've changed that to 'EG'.Now, I don't want to rain on your parade, but has anyone pointed out that the shortcut EA conflicts with 'Ellipse Arc'?
Yes, makes sense. I've adjusted that as well.Playing with the line command, I noticed that the 'close' function doesn't move relativezero. This may be by design, but I would prefer it to move to the first point.
Yes, that is not the case in general. This would take some refactoring to restore the relative zero position when an action resumes. This should be the case for all actions or none to be consistent.Similarly, if you start another command while in the line command, and relativezero is moved, when you exit that command, relativezero isn't returned to its original position.
Yes, why not. Can you try this to get a feel if that makes sense when working with the tool?Could I suggest, as an alternative to using single letter shortcuts, that you add two letter shortcuts to the Close, Undo and Redo buttons in the options toolbar? My suggestions would be CL, UN and RD (RE is already used for rectangle).
Another idea would be to use a fixed first character for all options toolbar tools. E.g. '.C' for close and '.U', '.R' or '/C', '/U', '/R' or something like that.
OK, can you try to port this over from Line2PEx? I think I missed that.Could I also suggest adding the check for the 'enter' or 'return' key being pressed, and 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? Husky, at least, thought this was a good idea.
Yes..I noticed that you added the distance to 'Display Angle', which is good. However, adding the code to 'snap info' means that the display is always on, which as I said might be annoying at times.
Yes, sure. I'm not sure if the display code can be move there easily though.Would it be possible for me to add a toggle button to the 'restrict to angle or distance' options toolbar, and add the display code to 'RestrictAngleLength.js'?
I think either an application preference or a tool bar toggle button would be fine. Users could then provide feedback based on that.Perhaps you could have a vote on whether or not users want this feature.
That's one of those tricky questions. When starting a new tool, all restrictions are switched off automatically. I think switching on / off snaps or restrictions automatically while in process of using a tool might be confusing. I guess it boils down to the question of whether QCAD can predict what the user wants to do.Finally, if the restriction is active when trying to select the first point, it can stop you selecting the exact point you want. (This is also the same for the 'orthogonal', 'horizontal' and 'vertical' restrictions). Now I know you can easily switch it off using the button, but would it be better to switch off restrictions while selecting the first point?
Yes, sure, feel free to experiment with the other ideas and submit patches or feedback.I would be quite willing to make these changes and send them to you. Perhaps you could let me know what you think?
Please note that I've already fixed the keycode and the relative zero issue:
https://github.com/qcad/qcad/commit/c55 ... 26b0c82887
Re: Line2PEx - An improved line command?
I had another look at the international keyboard layouts. The stroke character (/) requires the shift key to be pressed in quite a few layouts. The dot character (.) requires the shift key to be pressed in fewer layouts. However, the comma character (,) is directly accessible in all layouts except for some russian layouts. So I decided to use the comma character as the fixed first character for all option toolbar tools. So the shortcuts are ',C' for the close button, ',U' for undo, and ',R' for redo. I have attached the altered file 'Line2P.ui'.Andrew wrote:
Another idea would be to use a fixed first character for all options toolbar tools. E.g. '.C' for close and '.U', '.R' or '/C', '/U', '/R' or something like that.
I have also attached 'Line2P.js', which has the following changes.
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. This is in the 'keyPressEvent' function.
I also added the 'hideUiOptions' function. This stores the position of relativezero. Then I added code to 'showUiOptions' to restore the position of relativezero. To add this functionality to all commands, I would assume you could just change the default functions, 'hideUiOptions' and 'showUiOptions' and have them save and restore relativezero. I don't know if this is correct, or even easy.
Anyway, this now has the same functionality as Line2PEx, except for the displaying of angles. But displaying angles would be controlled by 'restrict to angle/length', which I haven't tried as yet.
Finally, I discovered that if you choose Line2P as the very first command you run on starting QCAD, and you enable the restrict to angle or length function, then you can't select a first point. This is because 'getRelativeZero()' returns an invalid point. This means relativezero is not initialised on startup. Setting it to point 0,0 would be useful.
Perhaps you can let me know what you think. Thanks.
riverbuoy
Re: Line2PEx - An improved line command?
OK. Eventually, that first key for tools in the options tool bar could even be configurable to some extent.riverbuoy wrote:So the shortcuts are ',C' for the close button, ',U' for undo, and ',R' for redo.
Excellent, thanks!I have attached the altered file 'Line2P.ui'.
OK, this is merged and committed, in case you want to update to the latest version of the file: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. This is in the 'keyPressEvent' function.
https://raw.githubusercontent.com/qcad/ ... /Line2P.js
You're absolutely right. This makes a lot of sense, so I've implemented that at a higher level in EAction. This means that all tools should save / restore their relative zero position after updating file EAction.js:I also added the 'hideUiOptions' function. This stores the position of relativezero. Then I added code to 'showUiOptions' to restore the position of relativezero. To add this functionality to all commands, I would assume you could just change the default functions, 'hideUiOptions' and 'showUiOptions' and have them save and restore relativezero. I don't know if this is correct, or even easy.
https://raw.githubusercontent.com/qcad/ ... EAction.js
Diffs of all changes applied in this context are at: https://github.com/qcad/qcad/commit/1bb ... fdaa7980b2
OK, this has also been fixed for the next release.Finally, I discovered that if you choose Line2P as the very first command you run on starting QCAD, and you enable the restrict to angle or length function, then you can't select a first point. This is because 'getRelativeZero()' returns an invalid point. This means relativezero is not initialised on startup. Setting it to point 0,0 would be useful.
Great work, thanks!
Re: Line2PEx - An improved line command?
Andrew
I downloaded the latest Line2P.js and EAction.js, and they are working great. Except for one slight problem. If you draw some line segments, then use another command (Circle for example), and then exit from the command, relativezero returns to its original position as expected. If you now draw another one or more line segments and then select 'restrict to angle/length', relativezero is moved to where it was when you returned from the other command.
I added the following line:-
to the end of the resumeEvent function in EAction.js. This seems to have solved the problem, so I have attached the file EAction.js with the line added.
riverbuoy
I downloaded the latest Line2P.js and EAction.js, and they are working great. Except for one slight problem. If you draw some line segments, then use another command (Circle for example), and then exit from the command, relativezero returns to its original position as expected. If you now draw another one or more line segments and then select 'restrict to angle/length', relativezero is moved to where it was when you returned from the other command.
I added the following line:-
Code: Select all
this.relativeZeroPos = undefined;
I agree that it could be changed. It could be an option in 'Application Preferences' under 'Widgets->Toolbars'. However the shortcuts are in the ui file (xml format), and they would all have to be changed. Seems quite diffcult and time consuming unless ther is a better/easier way of doing this.OK. Eventually, that first key for tools in the options tool bar could even be configurable to some extent.
riverbuoy
- Attachments
-
- EAction.js
- (43.28 KiB) Downloaded 841 times
Re: Line2PEx - An improved line command?
Great, thanks for the fix!riverbuoy wrote:This seems to have solved the problem, so I have attached the file EAction.js with the line added.
The key codes could be set / adjusted programmatically (QAction::shortcut, QAction::setShortcut), so it might be possible to simply replace the comma with something user configurable.It could be an option in 'Application Preferences' under 'Widgets->Toolbars'. However the shortcuts are in the ui file (xml format), and they would all have to be changed. Seems quite diffcult and time consuming unless ther is a better/easier way of doing this.
Re: Line2PEx - An improved line command?
Looking at EAction I discovered that the default ShowUiOptions function calls the 'initUiOptions' function. To test this I added the following function to Line2P.Andrew wrote:
The key codes could be set / adjusted programmatically (QAction::shortcut, QAction::setShortcut), so it might be possible to simply replace the comma with something user configurable.
Code: Select all
Line2P.prototype.initUiOptions = function(resume) {
var prefixChar = ".";
var optionsToolBar = EAction.getOptionsToolBar();
var w = optionsToolBar.findChild("Close");
if (!isNull(w)) {
w.shortcut = new QKeySequence(prefixChar + ",C");
}
var w = optionsToolBar.findChild("Undo");
if (!isNull(w)) {
w.shortcut = new QKeySequence(prefixChar + ",U");
}
var w = optionsToolBar.findChild("Redo");
if (!isNull(w)) {
w.shortcut = new QKeySequence(prefixChar + ",R");
}
};
Andrew, Is this the kind of thing you were thinking about?
riverbuoy
Re: Line2PEx - An improved line command?
Yes, exactly!riverbuoy wrote:Andrew, Is this the kind of thing you were thinking about?
It should be possible to do that in EAction.prototype.initUiOptions by iterating though all children (optionsToolbar.children() ). Then one could check for each child if it has a keycode starting with a ',' and if so, replace it. What do you think?riverbuoy wrote:The disadvantage is each command that has toolbar options would need to write an 'initUiOptions' function if they wanted to allow the user to change the shortcuts.
Re: Line2PEx - An improved line command?
I love it. So far it works fine for me.
I have just one suggestion to make:
It would be nice to also have the option of relative angle-increments.
What I mean is: When starting with a horizontal line and then the next line is 15° up, it would be nice, if the shown angle of the next line would also be 15° (thus relative to the previous line angle).
Thanks,
Christian
I have just one suggestion to make:
It would be nice to also have the option of relative angle-increments.
What I mean is: When starting with a horizontal line and then the next line is 15° up, it would be nice, if the shown angle of the next line would also be 15° (thus relative to the previous line angle).
Thanks,
Christian
QCAD Pro on Gentoo Linux
Re: Line2PEx - An improved line command?
Yes, I agree. This actually ocurred to me after I posted it. This is what I came up with.Andrew wrote:
It should be possible to do that in EAction.prototype.initUiOptions by iterating though all children (optionsToolbar.children() ). Then one could check for each child if it has a keycode starting with a ',' and if so, replace it. What do you think?
Code: Select all
EAction.prototype.initUiOptions = function(resume) {
var prefixChar = "/";
var optionsToolBar = EAction.getOptionsToolBar();
if (isNull(optionsToolBar)) {
return;
}
for (var i in optionsToolBar.children()) {
var child = optionsToolBar.children()[i];
var shortCut = child.shortcut;
if (!isNull(shortCut) && !shortCut.isEmpty()) {
var count = shortCut.count();
if (count < 2 || count > 4) {
// greater than 4 is actually an error
continue;
}
var str = shortCut.toString();
var firstChar = str[0];
if (firstChar === prefixChar) {
// no change needed
continue;
}
// if first key is Ctrl then the string starts with Ctrl+
// so check for a + sign, which indicates a modifier key has been used
// '+' and '-' should not be used as prefix, as they zoom in and out
if (str.indexOf('+') === -1) { // no plus sign
if (firstChar >= '!' && firstChar <= '~') { // isgraph()
str = str.replace(firstChar, prefixChar);
child.shortcut = new QKeySequence(str);
}
}
}
}
};
If you define 'initUiOptions' in a command, that overrides this function. I tested this with 'Line2P'. So if you didn't want shortcuts to be overridden, then you would define the function in the command. It can even be empty.
So, Andrew, you need to decide if you want to implement this, and if so, where it should be in 'Application->Preferences' and what it should be called.
The obvious place for the pro version is in the 'Shortcuts and Commands' option. But in the source code version it would need to be elsewhere. I'm not sure that it would be a good idea to have the option in different places.
riverbuoy