omdl  v1.0
OpenSCAD Mechanical Design Library
docs_group.scad
Go to the documentation of this file.
1 //! Group: drafting and drawing tools for graphical design documentation.
2 /***************************************************************************//**
3  \file
4  \author Roy Allen Sutton
5  \date 2019-2024,2026
6 
7  \copyright
8 
9  This file is part of [omdl] (https://github.com/royasutton/omdl),
10  an OpenSCAD mechanical design library.
11 
12  The \em omdl is free software; you can redistribute it and/or modify
13  it under the terms of the [GNU Lesser General Public License]
14  (http://www.gnu.org/licenses/lgpl.html) as published by the Free
15  Software Foundation; either version 2.1 of the License, or (at
16  your option) any later version.
17 
18  The \em omdl is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  Lesser General Public License for more details.
22 
23  You should have received a copy of the GNU Lesser General Public
24  License along with the \em omdl; if not, write to the Free Software
25  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26  02110-1301, USA; or see <http://www.gnu.org/licenses/>.
27 
28  \details
29 
30  \amu_define group_name (Drafting)
31  \amu_define group_brief (Drafting and drawing tools for graphical design documentation.)
32 
33  \amu_include (include/amu/doxyg_init_ppd_gp.amu)
34 *******************************************************************************/
35 
36 // group begin and includes-required
37 /***************************************************************************//**
38  \amu_include (include/amu/doxyg_define_in_parent.amu)
39 
40  /+
41  remove *this* file and add draft-base.scad file as required include
42  +/
43 
44  \amu_define FILE_NAME ()
45  \amu_define includes_required_add
46  (
47  transforms/base_cs.scad
48  tools/common/polytope.scad
49  ${PATH_NAME}/draft-base.scad
50  )
51  \amu_include (include/amu/includes_required.amu)
52 *******************************************************************************/
53 
54 // member-wide reference definitions
55 /***************************************************************************//**
56  \amu_define group_references
57  (
58  )
59 *******************************************************************************/
60 
61 // member-wide documentation and conventions
62 /***************************************************************************//**
63  \addtogroup \amu_eval(${group})
64  \details
65  \anchor \amu_eval(${group})_conventions
66  \par Conventions
67 
68  \b Naming
69 
70  All public modules and functions are prefixed with \c draft_*.
71  Internal (private) identifiers carry an additional leading
72  underscore: \c \_draft_*. Configuration getter functions follow the
73  form \c \_draft_get_* and are private; callers should use the public
74  variable \ref draft_config_map together with the map_merge() or
75  map_update() override pattern shown in that variable's documentation.
76 
77  \b Common \b Parameters
78 
79  The following short-name parameters carry consistent meaning across
80  all modules in this library:
81 
82  parameter | data type | meaning
83  :------------:|:-------------------------:|:----------------------------------------------
84  \c w | decimal | line weight (width multiplier)
85  \c s | integer \| integer-list | line style; see \ref draft_line()
86  \c a | integer \| integer-list-5 | arrowhead style; see \ref draft_arrow()
87  \c a1, \c a2 | integer \| integer-list-5 | per-endpoint arrowhead overrides
88  \c o | point-2d | origin or center coordinate
89  \c off | decimal \| decimal-list-2 | dimension line offset distance
90  \c t | string \| string-list | text string or measured-value override
91  \c u | string | unit identifier for measured values
92  \c ts | decimal-list-3 | text size [width, line-height, heading-height]
93  \c tp | decimal-list-2..4 | text placement [-1, +1 per axis] (1)
94  \c rm | integer \| integer-list-2 | measurement rounding mode (2)
95  \c cmh | decimal | minimum horizontal cell size
96  \c cmv | decimal | minimum vertical cell size
97  \c layers | string-list | drafting layer names to render this object on
98  \c window | boolean | return bounding rectangle instead of geometry
99  \c zp | decimal-list-2 \| decimal | zone/window alignment scaler [-1, +1]
100  \c line | value-list-2 | border line config [width, [style]]
101 
102  (1) text placement [-1, +1] per axis with optional \c tp[2] pivot
103  offset (angle dims) and optional \c tp[3] rotation offset.
104 
105  (2) measurement rounding mode: 0=none, 1=round_d, 2=round_s.
106 
107  \b Scale \b Variables
108 
109  Two scale variables govern geometry size and must be kept in sync:
110 
111  - \ref draft_sheet_scale is a plain variable set once at design time.
112  Scales all sheet-level constructions (frame, zones, title block,
113  tables). Does \b not propagate through children automatically.
114  - \ref $draft_scale is a special variable that \b does propagate
115  through the OpenSCAD child scope. Set it explicitly inside
116  composite operations so that objects placed via \ref draft_move
117  inherit the correct scale:
118 
119  \code{.C}
120  draft_move ( [ ... ] )
121  {
122  $draft_scale = draft_sheet_scale;
123  // child objects here inherit $draft_scale automatically
124  }
125  \endcode
126 
127  \b Layers
128 
129  Every module accepts a \c layers parameter. The global variable \ref
130  draft_layers_show lists the layers that will actually be rendered;
131  all others are suppressed. Setting it to \c ["all"] renders
132  everything; \c "all" is a wildcard that matches any layer list.
133 
134  Default layer assignments by module category:
135 
136  category | default layer name
137  :-------------------|:------------------:
138  general geometry | \c "default"
139  sheet / frame | \c "sheet"
140  tables | \c "table"
141  notes | \c "note"
142  title block | \c "titleblock"
143  dimensions | \c "dim"
144 
145  To isolate a drawing phase, restrict \ref draft_layers_show:
146 
147  \code{.C}
148  draft_layers_show = ["default", "dim"]; // geometry + dimensions only
149  \endcode
150 
151  \b Configuration \b and \b Style \b Maps
152 
153  All style defaults live in \ref draft_config_map, initialised to \ref
154  draft_config_map_style1. Apply selective overrides with map_merge(),
155  placing overrides first so they take precedence:
156 
157  \code{.C}
158  draft_config_map =
159  map_merge
160  (
161  [ ["dim-offset", length(3)], ["line-use-hull", false] ],
162  draft_config_map_style1
163  );
164  \endcode
165 
166  All dimension values in configuration maps should be expressed via \c
167  length() or \c angle() with an explicit unit string so that designs
168  remain unit-independent.
169 
170  \b Typical \b Workflow
171 
172  A minimal complete script follows the pattern shown in the auxiliary
173  example block at the bottom of this file:
174 
175  -# Add required include files (see Required above).
176  -# Set \ref length_unit_base and \ref draft_layers_show.
177  -# Optionally override \ref draft_config_map with \c map_merge() or
178  map_update().
179  -# Call draft_sheet() to establish the frame and zones.
180  -# Use draft_move() to place the title block, tables, and notes
181  into named or indexed sheet zones.
182  -# Draw geometry inside draft_in_layers() to assign it to a layer,
183  then annotate with draft_dim_line(), draft_dim_radius(), etc.
184 
185  \par Example
186 
187  An example script and its output are shown below. There are numerous
188  ways to generate a printable form of the 2D result. For example: (1)
189  render the 2D design; (2) export it as a DXF file; (3) open the
190  exported DXF file in [LibreCAD]; (4) select print preview and adjust
191  the print scale as needed for the target sheet size and output
192  format; (5) then print or save the result as a PDF.
193 
194  \amu_define title (Drafting example)
195  \amu_define image_views (top)
196  \amu_define image_size (uxga)
197  \amu_define html_image_w (768)
198  \amu_define output_scad_last (true)
199 
200  \amu_include (include/amu/scope_diagrams_3d.amu)
201 
202  [LibreCAD]: https://librecad.org
203 *******************************************************************************/
204 
205 //----------------------------------------------------------------------------//
206 // openscad-amu auxiliary scripts
207 //----------------------------------------------------------------------------//
208 
209 /*
210 BEGIN_SCOPE example;
211  BEGIN_OPENSCAD;
212  include <omdl-base.scad>;
213  include <transforms/base_cs.scad>;
214  include <tools/2d/drafting/draft-base.scad>;
215 
216  length_unit_base = "mm";
217  length_unit_default = "mm";
218 
219  draft_sheet_scale = 1;
220  draft_sheet_size = "A";
221 
222  draft_layers_show = ["default", "sheet", "titleblock", "table", "note", "dim"];
223  //draft_layers_show = ["default", "dim"];
224  //draft_layers_show = ["default"];
225 
226  draft_config_map =
227  map_merge
228  (
229  [ // override defaults
230  ["line-use-hull", false],
231  ["dim-offset", length(3)],
232  ["dim-leader-length", length(3)],
233  ["dim-line-distance", length(3)],
234  ["dim-line-extension-length", length(5)]
235  ],
236  draft_config_map_style1
237  );
238 
239  draft_sheet(grid=0);
240 
241  draft_move
242  (
243  [
244  [[-1, 1]], [[1, 1]], [[-1,-1]], [[1, -1]],
245  [[0, 1/2], ["H","4"]], [[1, 0], ["H","1"]]
246  ]
247  )
248  {
249  $draft_scale = draft_sheet_scale;
250 
251  draft_ruler(order=[1,-1], label_hide=true);
252  draft_ruler(order=-1, label_hide=true);
253  draft_ruler();
254  draft_title_block
255  (
256  text=
257  [
258  ["SPROCKET", "LOWER REAR SECTION, ASSEMBLY 2 OF 3"],
259  "02/22/2019", "RAS", "X1234567890", "1", "",
260  ["ABS", "BLACK"], "STANDARD", "RAS", "SAR",
261  "3 COPIES REQUIRED", "APPROX. 30 MINUTE BUILD TIME",
262  ["UNLESS STATED OTHERWISE ALL", "DIMS ARE +/- 0.25", "ANGLES +/- 1", "REMOVE ALL BURRS"]
263  ],
264  zp=[1,-1], number=false
265  );
266 
267  draft_table
268  (
269  map=
270  [
271  [ "title", [ "REVISIONS", 3/2 ] ],
272  [ "heads", [ ["DATE", "REV", "REF", "AUTH"], 3/4 ] ],
273  [ "cols", [ 3, 2, 2, 2 ] ],
274  [ "rows", [ [ ["01-01-19", "R0", "X0", "RAS"], 1 ],
275  [ ["01-14-19", "R1", "X1", "RAS"], 1 ],
276  [ ["01-21-19", "R2", "X2", "RAS"], 1 ]
277  ]
278  ]
279  ],
280  fmap=draft_table_format_map_ccc,
281  zp=[-1,-1]
282  );
283 
284  draft_note
285  (
286  head="NOTE:",
287  note=["INSTALL SPROCKET", "BEFORE HUB-S32", "SEE: X1234567891"],
288  size=[7, 2, 3/4],
289  zp=[-1/2,0]
290  );
291  }
292 
293  t1 = 12;
294  r1 = length(50);
295  r2 = length(25);
296  o1 = length(2);
297  r3 = length(10);
298  a1 = 47.5;
299 
300  t2 = 5;
301  o2 = length(32);
302  r4 = length(4);
303 
304  function bev(p, a, o, r) = [p, p+r*[cos(a+o), sin(a+o)], p+r*[cos(a-o), sin(a-o)]];
305 
306  draft_move ( [ [[1, -1/2], ["E","3"]] ] )
307  union()
308  {
309  draft_in_layers()
310  difference()
311  {
312  circle(r=r1);
313 
314  circle(r=r2);
315 
316  for (i=[0:360/t1:360])
317  {
318  p1 = (r1-o1)*[cos(i), sin(i)];
319  p2 = (r1-o1-r3)*[cos(i), sin(i)];
320 
321  translate(p1) circle(r=r3);
322  polygon(bev(p2, angle_ll(x_axis2d_uv, p2), a1, r3*2));
323  }
324 
325  for (i=[0:360/t2:360])
326  translate(o2*[cos(i), sin(i)])
327  circle(r=r4);
328  }
329 
330  color("black")
331  {
332  draft_in_layers(["dim"])
333  {
334  draft_arc(r=r1, s=2, v1=360/t1*2.25, v2=360/t1*0.25);
335  draft_arc(r=r1-o1, s=2, v1=360/t1*8, v2=360/t1*5);
336  draft_arc(r=o2, s=2, fn=72);
337 
338  draft_arc(o=[o1-r1, 0], r=r3, s=2, fn=72);
339  }
340 
341  draft_dim_center(r=r2);
342  draft_dim_center(o=[o1-r1, 0], r=r3, v=45);
343 
344  draft_dim_radius(r=r1, v=360/t1*1);
345  draft_dim_radius(r=r1-o1, v=360/t1*7);
346  draft_dim_radius(r=o2, v=360/t2*4.5, u="in");
347 
348  draft_dim_radius(o=[o1-r1, 0], r=r3, v=0, d=true, off=0);
349 
350  draft_dim_angle(r=r1*(1+1/8), v1 = 360/t2*(t2-1));
351 
352  bt = bev([0, r1-o1-r3], 90, a1, r3);
353  b1 = first(bt); b2 = second(bt); b3 = third(bt);
354  draft_dim_angle(o=b1, r=r3*2, v1=[b1, b3], v2=[b1, b2], e=1+1/10);
355 
356  draft_dim_line(p1=[0,r1-o1-r3], d=r1*1.4, e=[r1*1.35, r1/4], u="mm");
357 
358  draft_dim_leader(p=[o2,0], l1=10, v2=0, l2=15, ts=[2,1.5], t=[str("D ", r4), str("X ", t2)]);
359  }
360  }
361 
362  // end_include
363  END_OPENSCAD;
364 
365  BEGIN_MFSCRIPT;
366  include --path "${INCLUDE_PATH}" {var_init,var_gen_png2eps}.mfs;
367  table_unset_all sizes;
368 
369  images name "sizes" types "uxga";
370  views name "views" distance "600" views "top";
371 
372  variables set_opts_combine "sizes views";
373  variables add_opts "--autocenter";
374 
375  include --path "${INCLUDE_PATH}" scr_make_mf.mfs;
376  END_MFSCRIPT;
377 END_SCOPE;
378 */
379 
380 //----------------------------------------------------------------------------//
381 // end of file
382 //----------------------------------------------------------------------------//