Hello, for making measurements in parts and in assemblies, for example the axial distance between cyclindrial surfaces or the distance between parallel planar surfaces, or parallel edges, I created a modification which displays various measurements in the bottom bar, based on the items currently selected.
The following measurements are performed:
1 element:
___Face: Display area
___Edge, Wire: length
___Solid, Compound, Compound Solid: volume
___Vertex: Position (TODO)
2 elements:
___Faces: total area
_____Parallel: distance
_____Non-parallel: angle (TODO)
___Edges: total length
_____Parallel: distance
_____Non-parallel: angle (TODO)
___Vertices: delta XYZ, distance
___Solids: total volume (TODO)
3+ elements:
___Faces: total area
___Edges: total length
___Wires: total length (TODO)
___Vertices: amount
___Solids: total volume
All code is in a new C++ file in src/Gui.
It uses Part::Feature::getShape and Selection().getCompleteSelection(); it implements Gui::SelectionObserver::onSelectionChanged to listen for selection events.
Once the TopoDS_Shape is obtained using Part::Feature::getShape all measurements are done using OpenCascade.
There are commits on the vanilla freecad repo, as well as linkstage3. The code is identical across these 2 repos.
In Application.cpp, the class is instantiated, since it inherits Gui::SelectionObserver, it will automatically be registered as a selection observer and receive events.
In src/Gui/Selection.cpp at the very least calls to getMainWindow()->showMessage have to be removed or commented out, otherwise the measurement message might be overwritten. It takes over the role of some of the code in Selection.cpp, specifically the code which shows info when selecting an element. Probably some of that info should be displayed by this new code as well if this code were ever to be merged.
Some ugly things:
- I had to link Part to the Gui module in order to invoke Part::Feature::getShape, needed to get the TopoDS_Shapes to perform measurements with.
- I had to add ${OCC_INCLUDE_DIR} to CMakeLists.txt in order to use OpenCascade from the Gui module. I think the code has to be moved elsewhere ideally, but I do not know where.
- The class is initialized as the last statement of Application::Application() in Gui/Application.cpp. There must be a better entry point for this code more consistent with the rest of the codebase, but I am unsure where to put it.
- When performing control+A on a large assembly, your PC will emit the magic smoke or at least consume 100% CPU for longer then I am willing to wait. So a mechanism is needed to handle very large selections. For now limiting the selection size would likely fix this problem. Limiting to 10 selections should be a reasonable compromise.
- Some code can be removed from Selection.cpp since it no longer needs to display messages with info about selected elements. This allows a minor restructuring of Selection.cpp which I have not done yet. Right now I just uncommented showMessage() invocations. In linkstage3 branch I also remove some of the code which generates the old selection summary, but also on this repo I have not fullt removed all unused code from Selection.cpp yet.
Future improvements:
- Apart from moving the code elsewhere in the codebase to avoid having to link Part to the Gui module and having to add OpenCascade include directories to the GUi module, angular measurements would be usefull addition.
Other limitations:
- Currently it passes a tolerance value of 0 to OCC for checking if surfaces/axis/edges are parallel. In my tests it sometimes does not detect the paralleism, especially in A2+ assemblies. I am not sure what the ideal tolerance values would be.
- Units are not taken into account, there are no units. With some minor change it could display the correct units.
The goal of this code is to avoid having to use the Part_Measure_X commands and and for me to be able to perform axial measurements on cylindrical faces. That was the prime motivator for this piece of code.
I have made the commit on the 20.2 tag in FreeCAD vanilla and on one of the latest daily commits on the LinkStage3 repo:
The main piece of code is here: https://github.com/Celemation/FreeCAD/blob/joel_selection_summary_demo/src/Gui/SelectionSummary.cpp
This commit on the FreeCAD repo contains all the changes needed: https://github.com/Celemation/FreeCAD/commit/e938a6ad7078472e7ea6ae1b059d512a5a570a96
On the LinkStage3 repo the changes are done over three commits (1 initial comit with 2 minor revisions): https://github.com/EDG5000/FreeCAD_RT/commits/20220404-stable-joel-edits/src/Gui
I’m happy to hear any feedback.


