[Bug?] TechDraw Dimensions get mixed up after editing the PartDesign model

Discussions about the development of the TechDraw workbench
aapo
Posts: 24
Joined: Mon Oct 29, 2018 6:41 pm

[Bug?] TechDraw Dimensions get mixed up after editing the PartDesign model

Postby aapo » Wed Nov 07, 2018 7:43 am

Hi,

I believe there is a problem with TechDraw, which causes some difficulties for me to (re)produce drawings. Namely, editing the model in PartDesign often leads to messed up dimensions in TechDraw. Sometimes, even a save-load cycle is enough to mess up the dimensions, but I was unable to produce an example about that. However, I could rather easily to come up with an example of the problem occurring with editing a PartDesign model:

An example file:
FreeCAD-TechDraw-holearray-orig.FCStd
(36.07 KiB) Downloaded 2 times
The TechDraw drawing of the example file is shown here:
FreeCAD-TechDraw-holearray-orig.png
FreeCAD-TechDraw-holearray-orig.png (73.49 KiB) Viewed 185 times
After I change the radius of the hole in bottom left corner from 4 mm to 1.2 mm, some of the other dimensions get mixed up somehow. I would expect just the hole radius to change, but e.g. the dimensions 10.00 and 12.00 change to 58.00 and 36.00, and some other dimensions change as well. Please note that the dimension labels themselves persist (i.e. they stay at their intended positions), but the points where the dimensions are linked to are changed. I suspect there is some kind of a problem, where the edges in the 3D-model are rebuilt, and their correspondence in TechDraw doesn't persist anymore, hence the mixup.
FreeCAD-TechDraw-holearray-changed.png
FreeCAD-TechDraw-holearray-changed.png (82.91 KiB) Viewed 185 times
I don't know if this is a known problem, but for me it's a rather minor inconvenience. As a workaround, I simply first build my 3D-model, and then make the drawings without editing the 3D-model any more. If I'll need to edit something later, I just delete the TechDraw drawing and make a new one.

Here is the FreeCAD version information, although I don't know why it says "Windows 8" instead of "Windows 10" I'm currently using:

OS: Windows 8
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.15150 (Git)
Build type: Release
Branch: master
Hash: fe8f172ce1f725cbc5e7a1538beaaac6a6529ec2
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: English/UnitedKingdom (en_GB)
wandererfan
Posts: 2013
Joined: Tue Nov 06, 2012 5:42 pm

Re: [Bug?] TechDraw Dimensions get mixed up after editing the PartDesign model

Postby wandererfan » Wed Nov 07, 2018 1:50 pm

aapo wrote:
Wed Nov 07, 2018 7:43 am
I believe there is a problem with TechDraw, which causes some difficulties for me to (re)produce drawings. Namely, editing the model in PartDesign often leads to messed up dimensions in TechDraw.
From TechDraw_Dimension_Length:
Notes
- All Dimensions are extremely vulnerable to the infamous "topological naming" issue. It is not possible at this time to keep references to 2D (projected) or 3D (actual) geometrical objects in sync with changes in the model. It is recommended that Dimensions be added towards the end of the drawing creation process.
aapo
Posts: 24
Joined: Mon Oct 29, 2018 6:41 pm

Re: [Bug?] TechDraw Dimensions get mixed up after editing the PartDesign model

Postby aapo » Wed Nov 07, 2018 4:07 pm

wandererfan wrote:
Wed Nov 07, 2018 1:50 pm
From TechDraw_Dimension_Length:
Notes
- All Dimensions are extremely vulnerable to the infamous "topological naming" issue. It is not possible at this time to keep references to 2D (projected) or 3D (actual) geometrical objects in sync with changes in the model. It is recommended that Dimensions be added towards the end of the drawing creation process.
Okay, thanks, I hadn't noticed the note in the wiki! So it is a known issue then, and it cannot be fixed properly. One thing that comes to mind would be to save the actual 2D-endpoints for each Dimension, and then rebuild every Dimension by the known 2D-endpoints every time something changes in the 3D model. But that would be quite a hack...

So, luckily there is a workaround for this, by doing the dimensioning as the absolutely final step of the work!
wandererfan
Posts: 2013
Joined: Tue Nov 06, 2012 5:42 pm

Re: [Bug?] TechDraw Dimensions get mixed up after editing the PartDesign model

Postby wandererfan » Thu Nov 08, 2018 12:53 pm

aapo wrote:
Wed Nov 07, 2018 4:07 pm
One thing that comes to mind would be to save the actual 2D-endpoints for each Dimension, and then rebuild every Dimension by the known 2D-endpoints every time something changes in the 3D model.
I suspect this would be a partial solution at best.

If the geometry has changed enough that the old Edge/Vertex numbering is incorrect, the endpoints of the the Dimension are likely to be different too.
aapo
Posts: 24
Joined: Mon Oct 29, 2018 6:41 pm

Re: [Bug?] TechDraw Dimensions get mixed up after editing the PartDesign model

Postby aapo » Thu Nov 08, 2018 1:49 pm

wandererfan wrote:
Thu Nov 08, 2018 12:53 pm
I suspect this would be a partial solution at best.

If the geometry has changed enough that the old Edge/Vertex numbering is incorrect, the endpoints of the the Dimension are likely to be different too.
That is probably true, which would make my idea an incomplete hack at best. After geometry update, it would be possible to search for the closest compatible new vertices near the old dimension endpoints, if no vertices would be exactly at the expected positions. This would, however, be both computationally expensive, and very likely unreliable under any serious 3D geometry changes, too. The upside would be that it would probably be straightforward to implement, and it would improve the current situation somewhat.

As pointed pointed out at the Wiki, the proper way would be to have a 3D <-> 2D mapping of the vertices/edges, but if I understood correctly this is difficult/missing with the current OCC system. At which operation is the numbered correspondence between 3D and 2D geometry lost in the current TechDraw implementation? Is it the flattening of the 3D geometry into a 2D plane, probably made using some OCC algorithms? Or do the actual 3D vertice/edge numbers already change randomly in PartDesign when editing a model?

I wonder if there is some industry-agreed algorithm to solve this 3D -> 2D mapping reliably. I mean, in the general case there are an unlimited number of points in 3D-space that map to exactly the same 2D point (for a given flat projection). Also, editing a 3D model adds and removes edges and vertices in an unpredictable sequence. When the user selects a 2D-point, which underlying 3D point (s)he actually wants to choose? I guess this problem would arise even if there would be a complete correspondence system between the 3D and 2D geometries. Perhaps the default choice should be the 3D point closest to the viewer.

Thinking about this, I now understand this is actually a pretty hard problem. :D
wandererfan
Posts: 2013
Joined: Tue Nov 06, 2012 5:42 pm

Re: [Bug?] TechDraw Dimensions get mixed up after editing the PartDesign model

Postby wandererfan » Fri Nov 09, 2018 1:12 pm

aapo wrote:
Thu Nov 08, 2018 1:49 pm
At which operation is the numbered correspondence between 3D and 2D geometry lost in the current TechDraw implementation? Is it the flattening of the 3D geometry into a 2D plane, probably made using some OCC algorithms? Or do the actual 3D vertice/edge numbers already change randomly in PartDesign when editing a model?
The OCC Hidden Line Removal functions (HLRBRep_Algo & friends) return a set of projected edges that have no reference back to the 3D source edge.

"The actual 3D vertice/edge numbers" can definitely change when editing the 3D model. Random might be too strong, but obviously if you remove or add geometry, the numbers will change.