Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TechDraw: drawing number autofill #18815

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pmjdebruijn
Copy link
Contributor

@pmjdebruijn pmjdebruijn commented Jan 1, 2025

DO NOT MERGE AS IS

This set of changes:

[1] set the PDF creator metadata, however, it should probably also include a FreeCAD version number, which I wasn't quite sure how to do.

[2][3][4] The template changes are basically this:

sed -i 's#freecad:editable="identification_number"#freecad:editable="drawing_number" freecad:autofill="drawing_number"#g' *.svg
sed -i 's#freecad:editable="identification_number"#freecad:editable="drawing_number" freecad:autofill="drawing_number"#g' *.svg
sed -i 's#freecad:editable="DrawingNumber"#freecad:editable="drawing_number" freecad:autofill="drawing_number"#g' *.svg

[5] The actual drawing_number autofill is a proof of concept, currently it fills a completely random number which probably isn't exactly great, as multiple pages for the same document get different numbers.

It would probably be better to take the last 48bits of the UUID, convert that to a ULongLong and modulo a 15 digits number from that, shifting the minimum up, so autogenerated drawing_numbers are unlikely to ever conflict with manually assigned ones.

+        bool ok;
+        auto value = QString::fromUtf8("97fac286-2231-46f6-8d8d-a3a167e78259").split("-").takeLast().toULongLong(&ok, 16);
+        if (ok) {
+            return QString::asprintf("%015d", value % 899999999999999 + 100000000000000);

(That sample code doesn't compile)

@github-actions github-actions bot added the Mod: TechDraw Related to the TechDraw Workbench label Jan 1, 2025
@pmjdebruijn
Copy link
Contributor Author

pmjdebruijn commented Jan 1, 2025

[6] Templates currently default to Assembly Drawing as document_type, which seems the less common case to me, this is possibly my own bias speaking here, not sure. But effectively it's this:

sed -i 's#Assembly Drawing#Component Drawing#g' *.svg

[7] I forgot the process the ISO 5457 subdirectory with all the sed lines, so here goes.

@WandererFan
Copy link
Contributor

You might want to put something at the top saying why we are doing this.

I would change Creator to just "FreeCAD".

For the version number, something like this should do it:

    auto config = App::Application::Config();
    auto major = config["BuildVersionMajor"];
    auto minor = config["BuildVersionMinor"];
    auto point = config["BuildVersionPoint"];
    auto suffix = config["BuildVersionSuffix"];

@pmjdebruijn
Copy link
Contributor Author

I removed the PDF creator, to solely focus on the drawing_number autofill here, but essentially:

Defaulting drawing_number to the string 'DN' is never useful for anybody.

Professional user will always want to enter their own number, in which case this patch won't negatively affect them.

However in case of hobbyist users, having a semi-random unique number can be rather useful in being able to unique identify drawings.

@WandererFan WandererFan marked this pull request as draft January 3, 2025 14:56
@WandererFan
Copy link
Contributor

I've marked this as Draft to prevent accidental merge.

@pmjdebruijn
Copy link
Contributor Author

So I figured out how to derive a random number from the document's UUID. This means that all the drawings in the same project will get the same random drawing numbers assigned by default. The user can always override of course.

As stated before, this change will make sure drawings have a unique number on them by default.

I think this is ready for a serious review now.

@WandererFan
Copy link
Contributor

@FreeCAD/cad-advisory-group I have no idea if this is a good idea or not.

My suspicion is that in any organization that actual needs drawings to be numbered will have their own ideas on how that number should be generated.

@pmjdebruijn
Copy link
Contributor Author

I'm sure that's right. But this change does not create any problem for anybody who wants to use their own numbering system, as the document number remains editable as before. So no tangible change in that situation.

This change just replaces the default 'DN' string, which is universally useless to everybody, with a semi-random number, so anybody who doesn't explicitly enter their own number, still gets at least some unique reference number, which can be used (referenced to) entirely in hindsight, because it's already there by default.

@pierreporte
Copy link

Writing a random number is a very bad idea. It is better to have an empty field that a field containing wrong information from the start. Even though it’s the responsibility of the designer to ensure everything is correct, it is a new source of mistakes that could easily avoided. Also, even though it’s not used, the document number is still binding and the recipient may not be aware that it is not to be used. Even though the random reference is unlikely to clash with existing drawing numbers (which is actually debatable), it can look legitimate and this is dangerous. I strongly advise against this method, and encourage you to modify your PR to keep the field empty by default. The ideal situation is a number that is pulled directly from the PDM but we’re not there yet.

Besides, assigning a reference for all the pages in a document is also a bad idea because it is possible to create multiple drawings in a single documents. This problem could be solved by fixing #13913 (new drawing container, that holds multiple pages).

@semhustej
Copy link

I agree with @pierreporte that having random drawing numbers by default could lead to mistakes/misunderstandings which are hard to troubleshoot. Wrong information is more dangerous than no information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Mod: TechDraw Related to the TechDraw Workbench
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants