[FIXED] Dimensions attached to Cosmetic Lines disappear with save-load cycle

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
aapo
Posts: 626
Joined: Mon Oct 29, 2018 6:41 pm

[FIXED] Dimensions attached to Cosmetic Lines disappear with save-load cycle

Post by aapo »

Hi!

I've encountered something that I believe is a bug: Quite often Dimensions attached to Cosmetic Lines disappear with save-load cycle. It's easy to reproduce: Make a TD drawing, add e.g. some Center Lines, attach new Dimensions to them. Everything looks fine, but save the file, close FreeCAD and reopen the file. Alas, sometimes, the Dimensions fail to load correctly. See the pics below (pic 1 before save), and notice the disappearing angle dimension and distance dimension upon file reload (pic 2) and related error messages. Please note that Dimensions attached to something else than Cosmetic Lines always appear OK, and the Cosmetic Lines themselves appear at correct locations. Also, .FCStd file included.

Code: Select all

16:49:51  DVP::getGeomByIndex(6) - invalid index - size: 6
16:49:51  Dimension has invalid 2D References
16:49:52  DVP::getGeomByIndex(6) - invalid index - size: 6
16:49:52  Dimension003 has invalid 2D References
TD-SaveLoadBug-p01.png
TD-SaveLoadBug-p01.png (35.08 KiB) Viewed 1339 times
TD-SaveLoadBug-p02.png
TD-SaveLoadBug-p02.png (37.83 KiB) Viewed 1339 times

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.21.30922 (Git)
Build type: Release
Branch: master
Hash: 8ec1279ea8ee32a36fae683b42b5cfc5821734b5
Python 3.10.6, Qt 5.15.4, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.3
Locale: English/United Kingdom (en_GB)
Installed mods: 
  * Assembly4 0.12.4
  * Curves 0.5.8
  * Defeaturing 1.2.0
  * fasteners 0.4.6
  * FCGear 1.0.0
  * freecad.gears 1.0.0
  * Manipulator 1.4.9
  * Reinforcement
  * Render 2022.2.0
  * sheetmetal 0.2.57
  * ThreadProfile 1.83.0
  * toSketch 1.0.0
Attachments
TD-SaveLoadBug.FCStd
(27.78 KiB) Downloaded 26 times
Last edited by aapo on Fri Nov 18, 2022 8:22 am, edited 1 time in total.
domad
Veteran
Posts: 2096
Joined: Mon Jun 22, 2020 12:16 pm

Re: [BUG?] Dimensions attached to Cosmetic Lines disappear with save-load cycle

Post by domad »

aapo wrote: Thu Nov 10, 2022 2:55 pm .....
Greetings to the Community!
I confirm the problem, it is highlighted when you draw cosmetic lines with the functions:
- Add Centerline to Faces;
- Add Centerline between 2 Lines;
- Add Centerline between 2 Points;
and you create an angular dimension, or a linear dimension, using one of these axes.
The following error is reported in the report after recalculation:
"DVP :: getGeomByIndex (6) - invalid index - size: 6
Dimension has invalid 2D References ".

Code: Select all

OS: Linux Mint 20.3 (X-Cinnamon / cinnamon)
Word size of FreeCAD: 64-bit
Version: 0.21.30922 (Git) AppImage
Build type: Release
Branch: master
Hash: 8ec1279ea8ee32a36fae683b42b5cfc5821734b5
Python 3.10.6, Qt 5.15.4, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.3
It does not happen if you use cosmetic lines between two vertices and/or lines generated by the extensions.
The animated gif shows the angular dimension bug.
Attachments
Angular dimension bug.gif
Angular dimension bug.gif (714.46 KiB) Viewed 1306 times
aapo
Posts: 626
Joined: Mon Oct 29, 2018 6:41 pm

Re: [BUG?] Dimensions attached to Cosmetic Lines disappear with save-load cycle

Post by aapo »

This seems to be a bug with ordering of recomputes when restoring the Document: The failed Dimensions can be revived by selecting them in the TreeView, and choosing from the right-click context menu "Recompute Object". The 1st step (i.e. clicking) brings the affected Dimensions back but with wrong data (endpoints), and the 2nd step updates the data (endpoints) and revives the Dimensions. Curiously, clicking the TechDraw "Redraw Everything" button (the two green cyclic arrows) does not accomplish this, but the Dimensions need to be fixed individually. Anyways, Good News is that this should be much simpler to fix than I feared, it's probably just a question of refreshing the affected Dimensions later during the document restore.

TD-SaveLoadBug-p03.png
TD-SaveLoadBug-p03.png (38.08 KiB) Viewed 1155 times
TD-SaveLoadBug-p04.png
TD-SaveLoadBug-p04.png (49.12 KiB) Viewed 1155 times

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.21.31035 (Git)
Build type: Release
Branch: master
Hash: c8074a972ee233d303e50e5d525aecae09c1cd04
Python 3.10.6, Qt 5.15.4, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.3
Locale: English/United Kingdom (en_GB)
Installed mods: 
  * Assembly4 0.12.4
  * Curves 0.5.8
  * Defeaturing 1.2.0
  * fasteners 0.4.6
  * FCGear 1.0.0
  * freecad.gears 1.0.0
  * Manipulator 1.4.9
  * Reinforcement
  * Render 2022.2.0
  * sheetmetal 0.2.57
  * ThreadProfile 1.83.0
  * toSketch 1.0.0
aapo
Posts: 626
Joined: Mon Oct 29, 2018 6:41 pm

Re: [BUG?] Dimensions attached to Cosmetic Lines disappear with save-load cycle

Post by aapo »

I think I managed to fix the problem, so I made a Pull Request here: https://github.com/FreeCAD/FreeCAD/pull/7827

The problem was slightly more complicated than I initially assumed, and it was a side-effect of WandererFan's new excellent multi-threading code, which processed the Face Extraction in another thread. Unfortunately, some Cosmetic Edges (namely CenterLines of Faces) depended on such Faces, but the multi-threading code did not wait until Faces had been processed, but only until Edges had. Because some of these CenterLine Edges could only exist after Face creation, I postponed the Dimension updating during Document Restore until all the Faces (and Cosmetc CenterLines) had been created. This works fine, and seems to fix the problem. Also, processing doesn't appear to be noticeably slower, things are just being done in different order.

Thus, Dimensions attached to Cosmetic CenterLines were not restored properly during document restore, because the Dimension processing started before the multi-threaded Face detection algorithm had finished, and some types of CenterLines depended on the existence of these Faces. This patch delays the Dimension processing until all geometry, including face-dependant CenterLines, actually exists.
Last edited by aapo on Thu Nov 17, 2022 11:39 pm, edited 2 times in total.
aapo
Posts: 626
Joined: Mon Oct 29, 2018 6:41 pm

Re: [BUG?] Dimensions attached to Cosmetic Lines disappear with save-load cycle

Post by aapo »

domad wrote: Thu Nov 10, 2022 4:52 pm It does not happen if you use cosmetic lines between two vertices and/or lines generated by the extensions.
This was a good catch, thanks! This fact helped me to find the actual position of the problematic code. :D

addCenterLinesToGeom() was processed in a different place than addCosmeticVertexesToGeom() and addCosmeticEdgesToGeom(), which indirectly caused the problem.
User avatar
wandererfan
Veteran
Posts: 6326
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [BUG?] Dimensions attached to Cosmetic Lines disappear with save-load cycle

Post by wandererfan »

aapo wrote: Thu Nov 17, 2022 11:30 pm
I had just logged in to mention that centerlines were the source of the problem and I discovered that the problem is solved and a PR waiting! Fantastic! Thank you.

git commit 2e19e5f6fb
aapo
Posts: 626
Joined: Mon Oct 29, 2018 6:41 pm

Re: [BUG?] Dimensions attached to Cosmetic Lines disappear with save-load cycle

Post by aapo »

wandererfan wrote: Fri Nov 18, 2022 12:29 am I had just logged in to mention that centerlines were the source of the problem and I discovered that the problem is solved and a PR waiting! Fantastic! Thank you.
You're welcome, and thanks for merging! Bit by bit FreeCAD advances :D
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: [FIXED] Dimensions attached to Cosmetic Lines disappear with save-load cycle

Post by Kunda1 »

Yay!
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
aapo
Posts: 626
Joined: Mon Oct 29, 2018 6:41 pm

Re: [BUG?] Dimensions attached to Cosmetic Lines disappear with save-load cycle

Post by aapo »

wandererfan wrote: Fri Nov 18, 2022 12:29 am I had just logged in to mention that centerlines were the source of the problem and I discovered that the problem is solved and a PR waiting! Fantastic! Thank you.

git commit 2e19e5f6fb
On further inspection, I believe I overlooked a case where TD Faces detection is turned off (either by Coarse Views, or if it's intentionally excluded by the user). I made a new PR to fix that case, too: https://github.com/FreeCAD/FreeCAD/pull/7842
domad
Veteran
Posts: 2096
Joined: Mon Jun 22, 2020 12:16 pm

Re: [BUG?] Dimensions attached to Cosmetic Lines disappear with save-load cycle

Post by domad »

aapo wrote: Sun Nov 20, 2022 12:09 pm On further inspection, I believe I overlooked a case where TD Faces detection is turned off (either by Coarse Views, or if it's intentionally excluded by the user). I made a new PR to fix that case, too: https://github.com/FreeCAD/FreeCAD/pull/7842
Hi @aapo, greetings to the Community!
Thank you for your painstaking refinement work
Post Reply