diff --git a/docs/icons/apple-touch-icon.png b/docs/icons/apple-touch-icon.png new file mode 100644 index 0000000..b14ce81 Binary files /dev/null and b/docs/icons/apple-touch-icon.png differ diff --git a/docs/icons/icon-192.png b/docs/icons/icon-192.png new file mode 100644 index 0000000..76291a1 Binary files /dev/null and b/docs/icons/icon-192.png differ diff --git a/docs/icons/icon-512.png b/docs/icons/icon-512.png new file mode 100644 index 0000000..9f1d3f3 Binary files /dev/null and b/docs/icons/icon-512.png differ diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..a6b7641 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,335 @@ + + + + + +tolstack guide: 1-D tolerance stack-up from a STEP assembly and 2D PDF drawings + + + + + + + + + + + + + + + + +
+ +
tolstackGuide
+GitHub +
+
+

tolstack — tolerance stack-up from 3D + 2D, straight to Excel

+

Pick a gap or step between two faces of a STEP assembly. tolstack finds the chain of parts
+in between, reads the tolerances from your 2D drawings (or the general-tolerance table), and gives
+you worst case, RSS, Cp/Cpk and Monte Carlo results in an Excel file with live formulas, a colour
+section picture, the 2D evidence and a reviewer sign-off block.

+
+ + + + + + + + + + + + + + +
pick the faces and the chaincheck the chain (with section picture)result
step 2step 3result
+

Try it in one command: python -m tolstack demo tolstack_demo --run (writes a demo STEP, 2D PDFs, a config and the Excel report).

+

What it does

+
    +
  1. Reads the STEP assembly: every part, its name and its planar faces along the stack-up axis (X/Y/Z).
  2. +
  3. Finds contacts: a top face of one part and a bottom face of another at the same height (within
    +the contact tolerance, default 0.02 mm) whose real face outlines overlap — holes and L-shapes
    +included, so two parts whose bounding boxes overlap but whose material does not touch are not linked.
  4. +
  5. Lists the possible chains from your From face to your To face, ranked: fewest contacts first,
    +then the largest weakest contact area. You see every candidate and pick the one that matches how the
    +parts are really held. Each part contributes the distance between the two faces it uses. The chain is
    +always checked against the 3D (sum of rows = To − From); a chain that does not close is refused.
  6. +
  7. Finds tolerances: +
      +
    • The 2D PDF whose file name matches the part name (or the one you assign) is searched for that
      +dimension: 62.73±0.1, 2 +0/-0.05, upper- or lower-only 4 +0.1/0 / 4 0/-0.05, limit dimensions
      +12.10/12.00 or 5.95~6.05.
      +All candidates are ranked and shown; you can pick another one. The used one is cropped with a red box as evidence.
    • +
    • Title-block notes ("TOLERANCES UNLESS SPECIFIED …") are never mistaken for a dimension.
    • +
    • If the 3D nominal differs from the drawing nominal, the drawing limits are kept and the difference is noted.
    • +
    • Drawings without a text layer (text exported as lines) are flagged; with Tesseract installed they can be OCR'd.
    • +
    • Otherwise the general tolerance of that part's drawing applies: a size table under "TOLERANCES UNLESS
      +OTHERWISE SPECIFIED" / "未注公差", one ± value, ISO 2768 / JIS B 0405 / GB/T 1804 class f, m, c or v,
      +or a decimal-places rule (X.XX ±0.05). The source column names the drawing and the kind of note.
    • +
    • Without a drawing, without a note, or for a size the note does not cover, the app's general tolerance
      +table
      applies (editable; default 0–10 ±0.05, 10–50 ±0.10, >50 ±0.15). Following the drawing can be switched off.
    • +
    • GD&T callouts (flatness, parallelism, profile, position …) found on the drawings are listed. They
      +are not in the stack unless you add one as a row (zone of total width t → nominal 0, ± t/2).
    • +
    +
  8. +
  9. Analyzes: nominal, mean shift for asymmetric tolerances, worst case, RSS, Cp, Cpk, predicted ppm and yield,
    +contribution %, a sensitivity table (which tolerance to tighten first) and a Monte Carlo % out of spec. Each row can be normal (±3σ by default), uniform
    +or triangular.
  10. +
  11. Writes Excel: inputs in yellow, everything else a formula (edit a tolerance or a distribution and the
    +whole stack, Cp/Cpk and verdicts recalculate), PASS/FAIL, contribution chart, section picture,
    +"2D references" sheet, "Sensitivity" sheet, "Assumptions" sheet (method, chain used, other chains found, general table) and a
    +Prepared / Checked / Approved block. Prints landscape on one page width.
  12. +
+

You stay in control: the chain is an editable table, so you can change values, flip a direction, or add
+rows the CAD cannot see, such as PCB bow, switch travel, assembly float or glue thickness.

+

Without a STEP file, and after the stack-up

+

Some stacks are not a chain of flat faces: the radial squeeze of a seal ring, a pin in a hole, a fit
+between two diameters. For those, write the rows yourself in a config (rows) and run it the same way:

+ +

The Excel file gets a Measured sheet (live: it reads the stack from the Stack-up sheet, the readings and the
+fit points are inputs, the limit is SLOPE / INTERCEPT) and a Chart sheet. Try it:
+python -m tolstack run examples/seal_squeeze_config.yaml, or in the web app choose Rows by hand (no STEP)
+and Fill in the example.

+

Install

+
git clone https://github.com/juw12/tolstack.git
+cd tolstack
+pip install -e ".[app]"          # or: pip install -r requirements.txt
+

Windows, no command line: double-click start.bat. It creates .venv, installs tolstack and opens the app.

+

Docker:

+
docker build -t tolstack .
+docker run --rm -p 8501:8501 tolstack      # then open http://localhost:8501
+

Python 3.10–3.13. Works on Windows, macOS and Linux. Optional: Tesseract
+for OCR of drawings without a text layer.

+

Use it

+

Web app

+
streamlit run app.py
+
    +
  1. Sidebar: Demo assembly (to try it), upload the STEP and 2D PDFs - as loose files, a whole folder or one
    +zip / 7z, up to 2 GB per file on a PC (on the shared server the limit follows its memory, about 110 MB of
    +STEP in a 1 GiB pod) - or type the path to a STEP, a folder, a zip or a 7z on this computer.
    +Pointed at a project hand-over folder (16 ... 3D), tolstack also looks inside its zip / 7z files, drops
    +repeated copies of the same STEP, offers the newest full assembly first, and takes the drawings from the
    +17 ... 2D folder next to it.
    +Native Creo / Pro-E files (.prt.N, .asm.N): on a PC with Creo Parametric installed, the folder's
    +assemblies are listed and Convert with Creo has Creo save the chosen one as STEP in the background
    +(files are copied to a private folder first; yours is not changed). Set TOLSTACK_CREO to parametric.exe
    +if Creo is not under PTC\Creo *. Creo needs a working license (a refusal by the license server is shown
    +as such) and can not open files saved by a newer Creo (each file's release is checked first). tolstack does not decode Creo files itself - their geometry format is PTC's own.
    +A saved YAML config can be loaded at the top of the sidebar to restore an analysis.
  2. +
  3. Choose Step or Gap, then the From part + face and the To part + face; set LSL/USL (optional).
    +The 3D view next to the lists highlights the picked parts and faces and follows every change (toggle it off
    +for a very large assembly). Faces are picked in the lists, not by clicking in the view.
  4. +
  5. Pick the chain from the ranked list (and exclude parts that must not be in it), then Build chain from 3D.
    +A section picture of the chain appears right away.
  6. +
  7. Check the table. Open "2D drawings" to assign a drawing to a part or choose another dimension candidate.
  8. +
  9. Read the result (nominal, WC, RSS, verdict, Cpk, Monte Carlo), then Create Excel.
    +Download this analysis as a config saves a portable YAML: it names the STEP and the drawings
    +(drawings/) instead of a path on one computer, so it runs from any folder that holds those files.
  10. +
  11. Optional: "GD&T on the drawings" adds a callout as a row; "Sensitivity" shows what each row does to the result.
  12. +
+

Rows by hand (no STEP) in the sidebar opens a table for a stack written by hand: label, part, nominal,
+tolerances, direction, diameter and distribution per row, LSL / USL, and (optional) measured groups and a
+functional limit - typed in or fitted from test points. Calculate gives the same result, Excel and pictures
+as tolstack run; the analysis downloads as a config. A saved config with rows loads straight into this page.

+

Each browser session works in its own folder on the server; folders idle for a day are removed.

+

Command line / batch

+
python -m tolstack demo examples/demo --run                            # demo STEP + 2D PDFs + config -> Excel
+python -m tolstack faces examples/demo/demo_assembly.step --axis z     # parts, faces, contact count
+python -m tolstack paths examples/demo_config.yaml                     # candidate chains
+python -m tolstack run examples/demo_config.yaml                       # -> examples/out/demo_ta.xlsx
+python -m tolstack run examples/seal_squeeze_config.yaml               # hand-written rows, no STEP -> Excel + 2 PNG
+python -m tolstack fits model.step COVER FRAME --rows                  # locating fits between two parts -> rows
+

After pip install -e . the same commands work as tolstack demo|faces|paths|fits|run.

+

Config file (version 1)

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
keymeaning
versionconfig schema version, 1
step, axisSTEP file (relative to the config) and stack-up axis x/y/z
from, to{part, face: top/bottom, level}; result = to − from
excludeparts the chain must not pass through
chain_optionwhich ranked chain to use (1 = best), see tolstack paths
contact_tolfaces closer than this (mm) count as touching
spec{lsl, usl}
drawings, drawing_map, ocrPDF globs; {PART: file.pdf} overrides ('' = no drawing); OCR on/off
general_tolerance[[from, to, ±tol], ...] - the app table
general_from_drawingtrue (default): use the general-tolerance note of each part's drawing before the table
sigma_level, mc_samplestolerance = ±k σ for normal rows; Monte Carlo sample count
extrarows that are not part thickness (bow, travel, float …); same keys as rows
rowsa stack written by hand, instead of step / from / to: {label, nominal} plus optional part, description, tol_plus, tol_minus, direction (+1 / -1), dist, source, diameter
diameter (in a row)true: nominal and tolerance are written as a diameter and halved for a one-side stack
measuredgroups of measured results: [{name, values: [...]}] or [{name, min, max}], optional result text
limit{value} or a fit {x: [...], y: [...], y_limit}; optional side (lower default / upper) and label
picturestrue: also write <output>_chart.png and <output>_table.png
overridesper row label, e.g. {B: {tol_plus: 0.03, tol_minus: 0.03, dist: uniform, source: "CPK data"}}
section, output, title, project, name, type, authorreport options
+

Unknown keys are rejected, so a typo cannot silently change a result. See examples/demo_config.yaml
+and examples/seal_squeeze_config.yaml.

+

Limits (read before trusting a result)

+ +

Development

+
pip install -e ".[app,dev]"
+pytest -q
+ruff check .
+mypy
+

See CONTRIBUTING.md for the code layout and the rules for changes, and CHANGELOG.md for what changed.

+

MIT licence.

+
+ + + + diff --git a/docs/manifest.webmanifest b/docs/manifest.webmanifest new file mode 100644 index 0000000..02cd499 --- /dev/null +++ b/docs/manifest.webmanifest @@ -0,0 +1,22 @@ +{ + "name": "tolstack", + "short_name": "tolstack", + "description": "1-D tolerance stack-up from a STEP assembly and 2D PDF drawings", + "start_url": "./", + "scope": "./", + "display": "standalone", + "background_color": "#fbfaf6", + "theme_color": "#309523", + "icons": [ + { + "src": "icons/icon-192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "icons/icon-512.png", + "sizes": "512x512", + "type": "image/png" + } + ] +} diff --git a/docs/sw.js b/docs/sw.js new file mode 100644 index 0000000..03174db --- /dev/null +++ b/docs/sw.js @@ -0,0 +1,19 @@ +// Keeps the guide readable without a connection: the page and its own files, newest first when online. +const CACHE = 'guide-86f41309e9'; +self.addEventListener('install', event => { + event.waitUntil(caches.open(CACHE).then(cache => cache.addAll(['./', 'manifest.webmanifest', 'icons/icon-192.png'])).then(() => self.skipWaiting())); +}); +self.addEventListener('activate', event => { + event.waitUntil(caches.keys().then(keys => Promise.all(keys.filter(key => key !== CACHE).map(key => caches.delete(key)))).then(() => self.clients.claim())); +}); +self.addEventListener('fetch', event => { + const request = event.request; + if (request.method !== 'GET' || new URL(request.url).origin !== location.origin) return; + event.respondWith( + fetch(request).then(answer => { + const copy = answer.clone(); + caches.open(CACHE).then(cache => cache.put(request, copy)); + return answer; + }).catch(() => caches.match(request).then(found => found || caches.match('./'))) + ); +});