I have recently been looking at LibreCAD, and thought that adding a feature called 'Direct Distance Entry' (as AutoCad calls it) could be a useful addition.
This feature returns a point, a given distance and angle away from the relative zero point. The distance is entered into the command line, and the angle is between the relative zero point and the current mouse position. This requires knowing the current mouse position, and if snapping is enabled, the current snap point. These would preferably be in drawing coordinates.
Looking for a location where this information is stored, was in vain. (if you know where this is, please let me know). However, I realised that the coordinate widget shows the exact information required, including showing the coordinates of the snap point, and in drawing coordinates.
Therefore I have added a data member to the coordinate widget class, that stores the current mouse position. This involves two changes.
First in file 'qg_coordinatewidget.h', I added at line 43, the following line.
This adds an RS_Vector which holds the mouse position, and it is also public, so it can be seen in other classes.
The second change is to the file 'qg_coordinatewidget.cpp'. I added the following line to store the mouse position. (Line 87).
mousePosition = RS_Vector(x, y, 0.0);
The coordinate widget is created by the application window, so next I added a function to the application window to return the mouse position.
First, in the file 'qc_applicationwindow.h', at line 96, I added the following line.
Next, in the file 'qc_applicationwindow.cpp', I added the function at the end of the file.
Finally, I changed the file 'rs_eventhandler.cpp'. The changes are to the function 'commandEvent'.
The first change was to move the call to the current action to the start of the function. This allows the action to see the command line before checking for direct distance entry, or coordinates. This is needed for commands such as the arc command, for example. This command prompts the user for a radius, start angle and end angle. By letting the action see this first, it can choose whether to use the number or not. If it uses it, the action sets the 'accepted' attribute to true, indicating that no further action is required.
The following code is what I added for dealing with the direct distance entry.
That completes the changes required. I have attached a zip file containing the changed files. If you would like to use this feature, unzip the files and replace the existing files, and recompile.
I am using LibreCAD version 2.1.0, so the line numbers above refer to this version.
CAUTIONARY NOTE: NEVER replace files without first checking them for 'nasties'. If you don't know or understand the c++ programming language, DO NOT replace these files. Wait for them to be checked by someone else. They are in standard text format, so you could use a program like 'meld' (on linux) to check the changes.
NOTE: I do not have a github account, and have no intention of starting one. If you wish to use this change, you will need to unzip the attached file.
Please feel free to use these changes in LibreCAD (if you think it useful). I hope some users find this useful.