Module PlaisirMaths : nomenclature (BOM), export en un clic, matériaux et étiquettes #6

Merged
pgp merged 18 commits from bom-export into main 2026-11-02 15:47:38 +00:00
Contributor

Module FreeCAD PlaisirMaths : export des pièces, nomenclature (BOM) lue par l'application Plaisir-Maths et étiquettes de stockage, d'après Export BOM FreeCAD - consignes.md, puis simplifié à l'usage.

Contenu

  • Module PlaisirMaths/ (FreeCAD 1.1), installé par ./install.sh : barre d'outils « Plaisir-Maths » et observateur qui écrit la BOM à chaque enregistrement (sans jamais bloquer l'enregistrement). MultiExport.FCMacro devient un lanceur.
  • Collections dans l'arbre : un composé ou un groupe nommé …_COLL est une collection ; ses instances (pièce, clones Draft, liens) donnent les quantités ; une collection placée dans une autre y est développée ; tout élément compte dans la BOM, seuls les _STEP/_STL/_SVG sont exportés.
  • Matériaux : bibliothèque Plaisir-Maths de l'atelier Materials (CONCEPTION/Matériaux/ dans Nextcloud, générée depuis WebApp/MATERIAUX.md) ; les matériaux d'une pièce viennent de Shape Material, sous-parties comprises ; bouton « Couleurs depuis les matériaux ».
  • Fenêtre BOM : collections, quantités, matériaux, références, avertissements, ajout de pièces hors CAO, écriture de la BOM.
  • <Document>.bom.json / .BOM.md : format plaisir-maths-bom v1 inchangé (chemins relatifs à Plaisir-Maths, SHA-256, paramètres, avertissements). Écart aux consignes, choisi par Pierre : fichiers garde les fichiers du dernier export tant qu'ils existent, jusqu'au prochain export.
  • Export en un clic : un fichier par pièce dans <Document>-Export/ (vidé de l'export précédent) : STEP avec couleurs par face, 3MF en option, SVG pour la découpe laser. L'ancienne fenêtre reste en « Export personnalisé » (calepinage, fichier combiné, nombre d'exemplaires) ; _STL traité comme _STEP ; SVG nommés d'après la pièce.
  • Étiquettes de stockage : SVG 150 × 100 mm par pièce (rendu isométrique aux couleurs des matériaux, vue de dessus cotée, nom, référence, collections, QR code de la référence par un générateur sans dépendance).
  • Références : table CONCEPTION/Table des références.csv, validée par Pierre, et commande « Appliquer la table des références » qui n'écrase jamais une valeur saisie ; commande « Ménage » pour écarter les anciennes pièces.

Tests

Faits avec FreeCAD 1.1.4 (AppImage, profil temporaire) sur des copies de pièces2026-10-19.FCStd, HexaGo_coins_PLA_sans_débord_V2.1_blocage.FCStd et Portique_v2.2.FCStd : critères d'acceptation des consignes, BOM et export avec collections, clones et collections imbriquées, matériaux et couleurs, étiquettes (rendu vérifié dans Inkscape, QR décodé par zxing ; générateur QR identique module par module à la bibliothèque qrcode). Interface testée en pilotant FreeCAD par script ; pas de tests automatisés dans le dépôt.

🤖 Generated with Claude Code

Module FreeCAD **PlaisirMaths** : export des pièces, nomenclature (BOM) lue par l'application Plaisir-Maths et étiquettes de stockage, d'après `Export BOM FreeCAD - consignes.md`, puis simplifié à l'usage. ## Contenu - **Module** `PlaisirMaths/` (FreeCAD 1.1), installé par `./install.sh` : barre d'outils « Plaisir-Maths » et observateur qui écrit la BOM à chaque enregistrement (sans jamais bloquer l'enregistrement). `MultiExport.FCMacro` devient un lanceur. - **Collections dans l'arbre** : un composé ou un groupe nommé `…_COLL` est une collection ; ses instances (pièce, clones Draft, liens) donnent les quantités ; une collection placée dans une autre y est développée ; tout élément compte dans la BOM, seuls les `_STEP`/`_STL`/`_SVG` sont exportés. - **Matériaux** : bibliothèque Plaisir-Maths de l'atelier Materials (`CONCEPTION/Matériaux/` dans Nextcloud, générée depuis `WebApp/MATERIAUX.md`) ; les matériaux d'une pièce viennent de `Shape Material`, sous-parties comprises ; bouton « Couleurs depuis les matériaux ». - **Fenêtre BOM** : collections, quantités, matériaux, références, avertissements, ajout de pièces hors CAO, écriture de la BOM. - **`<Document>.bom.json` / `.BOM.md`** : format `plaisir-maths-bom` v1 inchangé (chemins relatifs à `Plaisir-Maths`, SHA-256, paramètres, avertissements). Écart aux consignes, choisi par Pierre : `fichiers` garde les fichiers du dernier export tant qu'ils existent, jusqu'au prochain export. - **Export en un clic** : un fichier par pièce dans `<Document>-Export/` (vidé de l'export précédent) : STEP avec couleurs par face, 3MF en option, SVG pour la découpe laser. L'ancienne fenêtre reste en « Export personnalisé » (calepinage, fichier combiné, nombre d'exemplaires) ; `_STL` traité comme `_STEP` ; SVG nommés d'après la pièce. - **Étiquettes de stockage** : SVG 150 × 100 mm par pièce (rendu isométrique aux couleurs des matériaux, vue de dessus cotée, nom, référence, collections, QR code de la référence par un générateur sans dépendance). - **Références** : table `CONCEPTION/Table des références.csv`, validée par Pierre, et commande « Appliquer la table des références » qui n'écrase jamais une valeur saisie ; commande « Ménage » pour écarter les anciennes pièces. ## Tests Faits avec FreeCAD 1.1.4 (AppImage, profil temporaire) sur des copies de `pièces2026-10-19.FCStd`, `HexaGo_coins_PLA_sans_débord_V2.1_blocage.FCStd` et `Portique_v2.2.FCStd` : critères d'acceptation des consignes, BOM et export avec collections, clones et collections imbriquées, matériaux et couleurs, étiquettes (rendu vérifié dans Inkscape, QR décodé par zxing ; générateur QR identique module par module à la bibliothèque `qrcode`). Interface testée en pilotant FreeCAD par script ; pas de tests automatisés dans le dépôt. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
pgp added 16 commits 2026-11-01 19:08:06 +00:00
- New module PlaisirMaths/ (FreeCAD 1.1): Init.py installs a document
  observer that writes the BOM after each save, catching and logging any
  error so saving is never blocked; InitGui.py registers the commands and
  a global "Plaisir-Maths" toolbar (Export, Ajouter les propriétés, Ménage,
  Écrire la BOM, BOM à l'enregistrement toggle).
- Automatic BOM writing can be switched off via the user parameter
  BaseApp/Preferences/Macros/PlaisirMaths/EcritureAutomatique.
- Export dialog moved into plaisirmaths/multiexport.py, loads its .ui next
  to itself and no longer crashes without an active document;
  MultiExport.FCMacro is now a thin launcher.
- BOM writing, property and cleanup commands are stubs for the next steps.
- install.sh copies the module into ~/.local/share/FreeCAD/v1-1/Mod.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- _STL (legacy suffix, still used in 5 documents) is exported like _STEP.
- Simple SVG export writes <Label>_<n>.svg instead of the temporary
  sketch name (Sketch011-.svg); temporary objects are removed by Name.
- New "Collection × N / Appliquer" row: selects the pieces of a collection
  from the Nomenclature sheet with quantity × N and deselects the others.
- Pieces with pm_exporter = False are not selected by default.
- The dialog records the files produced per source object, shared files
  (calepinage, combined STEP/3MF) being listed under each piece, for the
  bom.json "fichiers" field.
- New plaisirmaths/pieces.py: exportable-piece helpers and Nomenclature
  sheet reading, shared with the upcoming BOM steps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- New plaisirmaths/proprietes.py: adds pm_reference, pm_version, pm_nom,
  pm_procede, pm_materiaux, pm_poids_g and pm_exporter (group
  PlaisirMaths) to every exportable object, pre-filling pm_nom from the
  label and pm_procede from the suffix; existing values are never
  overwritten, an empty pm_nom is filled in.
- Creates the Nomenclature and PiecesHorsCAO sheets with their header row
  when missing; reports a label clash instead of creating a duplicate.
- Runs as a single undoable transaction; the toolbar command shows a
  summary dialog and logs it to the report view.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- New plaisirmaths/menage.py (no GUI): for each exportable piece, its
  type, pm_nom, visibility, the objects using it as an input (ignoring
  groups, sheets, sketch attachment and external geometry), presence in
  the last *-Exports folder (falling back to the newest one in the
  directory, suffix-insensitive, "indéterminé" for anonymous SVGs) and
  probable duplicates (same name, or volume and bounding box within 0.1 %).
- Applying only sets pm_exporter (adding missing properties), never
  renames or deletes, in one undoable transaction.
- New plaisirmaths/menage_dialog.py: sortable table with a "Garder"
  checkbox per piece; selecting a row selects the object in the tree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- plaisirmaths/bom.py implements the plaisir-maths-bom v1 format: pieces
  (CAD objects with pm_exporter and PiecesHorsCAO rows) sorted by name,
  nomenclature lines merged per (collection, piece) and sorted, named
  cells of the other sheets as parametres, SHA-256 of the saved .FCStd,
  paths relative to the Plaisir-Maths folder (NFC, "/").
- Validation never blocks writing: missing or invalid references,
  duplicate names/references, invalid or unknown nomenclature lines,
  orphan pieces and a missing Nomenclature sheet go to avertissements
  and the report view.
- Atomic writes (temporary "~" file then rename).
- The save observer only writes for documents with exportable pieces or
  a Nomenclature sheet; the full export writes the BOM with fichiers.
- New "Racine" preference to force the Plaisir-Maths root folder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A plain save no longer empties "fichiers": the files listed in the
previous bom.json are kept, per CAD object, as long as they still exist
on disk, so saving right after an export does not hide them from the
application before Nextcloud has synced the export's JSON.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- New plaisirmaths/references.py: proposes PM-CE references for every
  exportable piece from the Ménage analysis, one number block per game
  folder, keeping references already assigned in PRODUCTION/ (PM-CE-1000
  Vé marqué, PM-CE-1001 reserved), sharing a reference between pieces of
  the same name within a game and leaving pieces suggested for removal
  (old base of a renamed variant, hidden and not exported, RAIE_Huitièmes)
  unnumbered; proposes pm_nom with leading all-caps words capitalised.
- The table is a ";" CSV that Pierre reviews before anything is written.
- New "Appliquer la table des références" command: fills pm_reference and
  pm_version only when empty, pm_nom and pm_procede only while they still
  hold their pre-filled value, reports conflicts, one undoable transaction.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The bom.json carries the SHA-256 of the .FCStd on disk; written from a
modified, unsaved document it described a state the file did not
contain. "Écrire la BOM" and the export now ask to save first (Save /
Ignore / Cancel). README: recommended procedure for a document.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- New plaisirmaths/etiquettes.py: one SVG label per selected piece with
  an isometric render (PNG, taken in a temporary document so the working
  document is untouched), a top view with overall dimensions built from
  TechDraw.projectEx (sharp, smooth and outline edges) and thickness,
  pm_nom, reference-version, collections × quantities from the
  Nomenclature sheet, source document and a QR code of the reference.
- Default-grey pieces are coloured from their first material.
- New plaisirmaths/qr.py: dependency-free QR encoder (byte mode, ECC M,
  versions 1-10), checked module for module against the qrcode library
  for all masks and decoded with zxing.
- Export dialog: "Étiquettes de stockage" checkbox; a labels-only export
  keeps the previous fichiers in the BOM.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A collection is a group (DocumentObjectGroup, App::Part…) whose label
  ends with "_COLL"; its code is the label without the suffix. Members
  are the pieces it contains (plain sub-groups included) and App::Links
  to pieces elsewhere, so a piece can belong to several collections.
- Quantity per collection copy = pm_quantite of the member (the piece or
  the link), 1 by default, plus an optional pm_remarque.
- Hors-CAO pieces are tree objects flagged pm_hors_cao (procédé "achat"
  by default) instead of PiecesHorsCAO rows.
- "Ajouter les propriétés" no longer creates sheets; it adds pm_quantite
  and pm_remarque to collection members.
- New warnings: link to a non-piece, nested collection, unnamed "_COLL"
  group, old sheets still holding data; orphan = piece in no _COLL group.
  Links are never exportable pieces themselves.
- bom.json format unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- New plaisirmaths/materiaux.py: generates one .FCMat per material
  (colour, density, stable UUID) from WebApp/MATERIAUX.md, never
  overwriting an existing file, and registers the folder
  (Plaisir-Maths/CONCEPTION/Matériaux, or the DossierMateriaux
  preference) as the "Plaisir-Maths" library of the Materials workbench
  at startup (Init.py).
- A piece's materials are its ShapeMaterial or, for a compound/fusion,
  those of its sub-parts ordered by volume; pm_materiaux remains the
  fallback. The BOM warns about pieces without material and materials
  outside the Plaisir-Maths library.
- Labels render each sub-part separately with its material colour (the
  material wins over a colour set by hand, which FreeCAD keeps when a
  material is assigned).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The "BOM" toolbar button opens a window listing each _COLL collection
  with its pieces (pm_nom, object or link → target, quantity spin box,
  materials, reference, procédé, editable remark), the pieces in no
  collection, and the live list of BOM warnings.
- Quantity and remark edits are written to the member (piece or link)
  as undoable transactions; selecting a row selects the object.
- "Ajouter une pièce hors CAO…" creates a geometry-less object
  (pm_hors_cao) with its properties in the chosen collection.
- "Couleurs depuis les matériaux" colours pieces and their sub-parts from
  their material (per-face colours for compounds, main material for
  fusions); pieces without material keep their colour.
- "Écrire la BOM" offers to save first, then writes .bom.json/.BOM.md.
- The BOM can be previewed for a document not yet saved (no SHA-256).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- New plaisirmaths/export_bom.py: exports every exportable piece found in
  a _COLL group once (no copies): STEP with per-face colours (and 3MF as
  an option) for 3D pieces, SVG cut outline for _SVG pieces, optional
  storage labels; the folder is emptied of previous export files first
  (other files and sub-folders are kept); the BOM is rewritten with
  fichiers.
- Toolbar: "Exporter" is the one-click export (offers to save first,
  leaves the document unmodified), "Options d'export" sets STEP / 3MF /
  labels, the previous dialog stays as "Export personnalisé"; the
  toolbar entries are rewritten in a fixed order. "BOM" button renamed
  command PlaisirMaths_BOM; the BOM window gets an "Exporter" button.
- Ménage looks first at <Document>-Export.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Follows how Portique_v2.2 is modelled: COMPTEUR_COLL is a Part::Compound
holding the assembled kit (pieces, Draft clones of them, 4 clones of
Pied_COLL, wooden sticks and cards without export suffix).

- A collection is a group or a Part::Compound whose label ends in _COLL.
- Each element is an instance: links and Draft clones (chains included)
  resolve to the original piece; a piece's quantity is the sum of its
  instances (pm_quantite each, 1 by default), summed without warning.
- A collection inside another (or a clone of it) is expanded: its pieces
  count once per instance; it also stays a collection of its own.
- Every element of a collection is a BOM piece; only _STEP/_STL/_SVG
  pieces are exported. Orphans are only reported for those.
- BOM window: one row per piece and collection with its instance count;
  the quantity is editable only for a single direct instance; selecting a
  row selects all its instances.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
shape.BoundBox is loose until a shape has been meshed for display, so a
piece's dimensions_mm depended on whether it had been shown (Portique:
Logement_rotule_bleu 38.0 mm in the GUI, 41.1 mm otherwise) and the BOM
could change between two saves of an unchanged document. Use
optimalBoundingBox(False, False) for the BOM, the labels and Ménage's
duplicate detection (~1.3 s per save on Portique and ADP).

Pieces with procédé "achat" no longer get the "aucun matériau" warning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collection elements without export suffix (Bâton horizontal, Jambe,
carte chiffre in Portique_v2.2) are BOM pieces and need references too;
"Appliquer la table des références" now matches any piece of the BOM.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pgp merged commit 66ce304186 into main 2026-11-02 15:47:38 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
thomalex.moreau/MultiExport-FreeCAD!6
No description provided.