omdl  v0.9.5
OpenSCAD Mechanical Design Library
docs_module.scad
Go to the documentation of this file.
1 //! Module: Drafting and drawing tools.
2 /***************************************************************************//**
3  \file
4  \author Roy Allen Sutton
5  \date 2019-2024
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.)
32 
33  \amu_include (include/amu/pgid_pparent_path_n.amu)
34 *******************************************************************************/
35 
36 //----------------------------------------------------------------------------//
37 // group.
38 //----------------------------------------------------------------------------//
39 
40 /***************************************************************************//**
41  \amu_include (include/amu/group_in_parent.amu)
42 
43  /+
44  remove this file and add draft-base.scad file as required include
45  +/
46  \amu_define FILE_NAME ()
47  \amu_define includes_required_add
48  (
49  tools/align.scad
50  tools/operation_cs.scad
51  tools/polytope.scad
52  ${PATH_NAME}/draft-base.scad
53  )
54  \amu_include (include/amu/includes_required.amu)
55 *******************************************************************************/
56 
57 //----------------------------------------------------------------------------//
58 
59 /***************************************************************************//**
60  \addtogroup \amu_eval(${group})
61 
62  \details
63 
64  This module provides basic 2D drafting tools. Below is an example
65  output (png and svg format) and script. Numerous ways exists to
66  generate a printable form of the 2D result. For example: (1) Render
67  the 2D design. (2) Export as DXF. (3) Open the exported DXF file
68  using [LibreCAD]. (4) Select print preview and change the print
69  scale as needed for the sheet size and target output page. (5)
70  Finally print or save a PDF file.
71 
72  \amu_define title (Drafting example)
73  \amu_define image_views (top)
74  \amu_define image_size (uxga)
75  \amu_define html_image_w (768)
76  \amu_define output_scad_last (true)
77 
78  \amu_include (include/amu/scope_diagrams_3d.amu)
79 
80  [LibreCAD]: https://librecad.org
81 *******************************************************************************/
82 
83 //----------------------------------------------------------------------------//
84 // openscad-amu auxiliary scripts
85 //----------------------------------------------------------------------------//
86 
87 /*
88 BEGIN_SCOPE example;
89  BEGIN_OPENSCAD;
90  include <omdl-base.scad>;
91  include <tools/align.scad>;
92  include <tools/operation_cs.scad>;
93  include <tools/drafting/draft-base.scad>;
94 
95  length_unit_base = "mm";
96  length_unit_default = "mm";
97 
98  draft_sheet_scale = 1;
99  draft_sheet_size = "A";
100 
101  draft_layers_show = ["default", "sheet", "titleblock", "table", "note", "dim"];
102  //draft_layers_show = ["default", "dim"];
103  //draft_layers_show = ["default"];
104 
105  draft_config_map =
106  map_merge
107  (
108  [ // override defaults
109  ["line-use-hull", false],
110  ["dim-offset", length(3)],
111  ["dim-leader-length", length(3)],
112  ["dim-line-distance", length(3)],
113  ["dim-line-extension-length", length(5)]
114  ],
115  draft_config_map_style1
116  );
117 
118  draft_sheet(grid=0);
119 
120  draft_move
121  (
122  [
123  [[-1, 1]], [[1, 1]], [[-1,-1]], [[1, -1]],
124  [[0, 1/2], ["H","4"]], [[1, 0], ["H","1"]]
125  ]
126  )
127  {
128  $draft_scale = draft_sheet_scale;
129 
130  draft_ruler(order=[1,-1], label_hide=true);
131  draft_ruler(order=-1, label_hide=true);
132  draft_ruler();
133  draft_title_block
134  (
135  text=
136  [
137  ["SPROCKET", "LOWER REAR SECTION, ASSEMBLY 2 OF 3"],
138  "02/22/2019", "RAS", "X1234567890", "1", "",
139  ["ABS", "BLACK"], "STANDARD", "RAS", "SAR",
140  "3 COPIES REQUIRED", "APPROX. 30 MINUTE BUILD TIME",
141  ["UNLESS STATED OTHERWISE ALL", "DIMS ARE +/- 0.25", "ANGLES +/- 1", "REMOVE ALL BURRS"]
142  ],
143  zp=[1,-1], number=false
144  );
145 
146  draft_table
147  (
148  map=
149  [
150  [ "title", [ "REVISIONS", 3/2 ] ],
151  [ "heads", [ ["DATE", "REV", "REF", "AUTH"], 3/4 ] ],
152  [ "cols", [ 3, 2, 2, 2 ] ],
153  [ "rows", [ [ ["01-01-19", "R0", "X0", "RAS"], 1 ],
154  [ ["01-14-19", "R1", "X1", "RAS"], 1 ],
155  [ ["01-21-19", "R2", "X2", "RAS"], 1 ]
156  ]
157  ]
158  ],
159  fmap=draft_table_format_map_ccc,
160  zp=[-1,-1]
161  );
162 
163  draft_note
164  (
165  head="NOTE:",
166  note=["INSTALL SPROCKET", "BEFORE HUB-S32", "SEE: X1234567891"],
167  size=[7, 2, 3/4],
168  zp=[-1/2,0]
169  );
170  }
171 
172  t1 = 12;
173  r1 = length(50);
174  r2 = length(25);
175  o1 = length(2);
176  r3 = length(10);
177  a1 = 47.5;
178 
179  t2 = 5;
180  o2 = length(32);
181  r4 = length(4);
182 
183  function bev(p, a, o, r) = [p, p+r*[cos(a+o), sin(a+o)], p+r*[cos(a-o), sin(a-o)]];
184 
185  draft_move ( [ [[1, -1/2], ["E","3"]] ] )
186  union()
187  {
188  draft_in_layers()
189  difference()
190  {
191  circle(r=r1);
192 
193  circle(r=r2);
194 
195  for (i=[0:360/t1:360])
196  {
197  p1 = (r1-o1)*[cos(i), sin(i)];
198  p2 = (r1-o1-r3)*[cos(i), sin(i)];
199 
200  translate(p1) circle(r=r3);
201  polygon(bev(p2, angle_ll(x_axis2d_uv, p2), a1, r3*2));
202  }
203 
204  for (i=[0:360/t2:360])
205  translate(o2*[cos(i), sin(i)])
206  circle(r=r4);
207  }
208 
209  color("black")
210  {
211  draft_in_layers(["dim"])
212  {
213  draft_arc(r=r1, s=2, v1=360/t1*2.25, v2=360/t1*0.25);
214  draft_arc(r=r1-o1, s=2, v1=360/t1*8, v2=360/t1*5);
215  draft_arc(r=o2, s=2, fn=72);
216 
217  draft_arc(c=[o1-r1, 0], r=r3, s=2, fn=72);
218  }
219 
220  draft_dim_center(r=r2);
221  draft_dim_center(c=[o1-r1, 0], r=r3, v=45);
222 
223  draft_dim_radius(r=r1, v=360/t1*1);
224  draft_dim_radius(r=r1-o1, v=360/t1*7);
225  draft_dim_radius(r=o2, v=360/t2*4.5, u="in");
226 
227  draft_dim_radius(c=[o1-r1, 0], r=r3, v=0, d=true, o=0);
228 
229  draft_dim_angle(r=r1*(1+1/8), v1 = 360/t2*(t2-1));
230 
231  bt = bev([0, r1-o1-r3], 90, a1, r3);
232  b1 = first(bt); b2 = second(bt); b3 = third(bt);
233  draft_dim_angle(c=b1, r=r3*2, v1=[b1, b3], v2=[b1, b2], e=1+1/10);
234 
235  draft_dim_line(p1=[0,r1-o1-r3], d=r1*1.4, e=[r1*1.35, r1/4], u="mm");
236 
237  draft_dim_leader(p=[o2,0], l1=10, v2=0, l2=15, ts=[2,1.5], t=[str("D ", r4), str("X ", t2)]);
238  }
239  }
240 
241  // end_include
242  END_OPENSCAD;
243 
244  BEGIN_MFSCRIPT;
245  include --path "${INCLUDE_PATH}" {var_init,var_gen_png2eps}.mfs;
246  table_unset_all sizes;
247 
248  images name "sizes" types "uxga";
249  views name "views" distance "600" views "top";
250 
251  variables set_opts_combine "sizes views";
252  variables add_opts "--autocenter";
253 
254  include --path "${INCLUDE_PATH}" scr_make_mf.mfs;
255  END_MFSCRIPT;
256 END_SCOPE;
257 */
258 
259 //----------------------------------------------------------------------------//
260 // end of file
261 //----------------------------------------------------------------------------//