dimlines.scad 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. /* This is a first pass at dimension lines for OpenSCAD. The text generated for
  2. * this comes from http://www.thingiverse.com/thing:59817, and I gratefully
  3. * acknowledge user PGreenland for creating this dotmatrix style font.
  4. *
  5. * Download his file first, TextGenerator.scad, before attempting to run this
  6. * program.
  7. *
  8. * What this program does:
  9. *
  10. * This program can draw lines with arrows and has a primitive dimensioning
  11. * element for putting text within arrows. In addition, should the area being
  12. * dimensioned be too narrow, there is a provision for putting the text on
  13. * either side of the arrows.
  14. *
  15. * The dimension lines are drawn on the xy plane and are meant to be seen in a
  16. * top view.
  17. *
  18. * =======================================================
  19. * Be sure to view this from above -- ctrl-4
  20. * =======================================================
  21. *
  22. * Available:
  23. *
  24. * Assorted constants to ease the use of dimensioning line. Because there is
  25. * no introspection regarding the dimensions of your creations, you will want
  26. * to adjust the parameters to fit the context of your creation. You can adjust
  27. * the size of the text, lines, etc to match the rest of your objects.
  28. *
  29. * the following functions or modules are available.
  30. *
  31. * line(length, width, height=DIM_HEIGHT, left_arrow=false, right_arrow=false)
  32. * Can draw a line with the options of including an arrow at either end
  33. *
  34. * circle_center(radius, size, line_width)
  35. * Draws the cross in the center of a circle. There are defaults for the
  36. * cross size and line width
  37. *
  38. * dimensions(length, line_width, loc=DIM_CENTER)
  39. * draws text within lines, such as <--- 3.5 --->
  40. * with the use of the variable loc you can alter the placement of the text
  41. * loc=DIM_CENTER <--- 3.5 ---> this is the default
  42. * loc=DIM_LEFT 3.5 <---->
  43. * loc=DIM_RIGHT <----> 3.5
  44. * loc=DIM_OUTSIDE ---> 3.5 <---
  45. *
  46. * leader_line(angle, radius, angle_length, horz_line_length,
  47. * direction=DIM_RIGHT, line_width, text)
  48. *
  49. * for use in pointing to the edge of a circle and showing text
  50. *
  51. * usage of the leader line:
  52. * translate to the center of the circle
  53. * Typically leader lines have a bend in them. The angle variable is used
  54. * to specify the angle from which the line will point to the center of the
  55. * circle. The radius specifies the location of the arrow. The
  56. * angle_length is distance that the leader line takes until meeting the
  57. * horizontal line. Once the angled line meets the horizontal line, that
  58. * line will either extend to the right or left. direction and therefore
  59. * be either DIM_RIGHT or DIM_LEFT. line_width typically would be whatever
  60. * constant you have selected for all your dimensioned lines. Finally, the
  61. * text will be the value that you wish to show, such as R 0.500.
  62. *
  63. *
  64. * Created by Don Smiley
  65. */
  66. //use <OpenSCAD_3D_Text_Generator/TextGenerator.scad>
  67. use <TextGenerator.scad>
  68. // these variables are used within the modules
  69. DIM_CENTER = 0;
  70. DIM_LEFT = 1;
  71. DIM_RIGHT = 2;
  72. DIM_OUTSIDE = 3;
  73. DIM_HORZ = 0;
  74. DIM_VERT = 1;
  75. DIM_UPPER_LEFT = 0;
  76. DIM_UPPER_RIGHT = 1;
  77. DIM_LOWER_LEFT = 2;
  78. DIM_LOWER_RIGHT = 3;
  79. /* Constants related to the annotation lines
  80. *
  81. * Because the dimension of the part to be documented can vary widely, you
  82. * probably are going to need to adjust the parameters to fit the context of
  83. * your part.
  84. *
  85. * For example, the following parameters were used for a part 3.5 units long.
  86. * In addition, DIM_HEIGHT is a height meant to be slightly above your tallest
  87. * part.
  88. */
  89. DIM_LINE_WIDTH = .025; // width of dimension lines
  90. DIM_SPACE = .1; // a spacing value to make it easier to adjust line spacing etc
  91. DIM_HEIGHT = .01; // height of lines
  92. // refers to the size of the cross within a circle
  93. DIM_HOLE_CENTER = DIM_LINE_WIDTH * 6;
  94. // an approximation that sets the font size relative to the line widths
  95. DIM_FONTSCALEFACTOR = .7;
  96. OFFSET = .05; // added to the hole length to extend past the surface of the cube
  97. module arrow(arr_points, arr_length, height) {
  98. // arrow points to the left
  99. linear_extrude(height=height, convexity=2)
  100. polygon(
  101. points = [[0, 0],
  102. [arr_points, arr_points / 2],
  103. [arr_length, 0],
  104. [arr_points, -arr_points / 2]],
  105. paths = [[0, 1, 2, 3]], convexity = 2);
  106. }
  107. module line(length, width=DIM_LINE_WIDTH,
  108. height=DIM_HEIGHT,
  109. left_arrow=false,
  110. right_arrow=false
  111. ) {
  112. /* This module draws a line that can have an arrow on either end. Because
  113. * the intended use is to be viewed strictly from above, the height of the
  114. * line is set arbitrarily thin.
  115. *
  116. * The factors arr_length and arr_points are used to create a proportionate
  117. * arrow. Your sense of asthetics may lead you to choose different
  118. * numbers.
  119. */
  120. arr_points = width * 4;
  121. arr_length = arr_points * .6;
  122. union() {
  123. if (left_arrow && right_arrow) {
  124. translate([arr_length, -width / 2, 0])
  125. cube([length - arr_length * 2, width, height], center=false);
  126. } else {
  127. if (left_arrow) {
  128. translate([arr_length, -width / 2, 0])
  129. cube([length - arr_length, width, height], center=false);
  130. } else {
  131. if (right_arrow) {
  132. translate([0, -width / 2, 0])
  133. cube([length - arr_length, width, height], center=false);
  134. } else {
  135. translate([0, -width / 2, 0])
  136. cube([length, width, height], center=false);
  137. }
  138. }
  139. }
  140. if (left_arrow) {
  141. arrow(arr_points, arr_length, height);
  142. }
  143. if (right_arrow) {
  144. translate([length, 0, 0])
  145. rotate([0, 0, 180])
  146. arrow(arr_points, arr_length, height);
  147. }
  148. }
  149. }
  150. module circle_center(radius, size=DIM_HOLE_CENTER, line_width=DIM_LINE_WIDTH) {
  151. translate([-size / 2, 0, 0])
  152. line(length=size, width=line_width, height=DIM_HEIGHT, left_arrow=false,
  153. right_arrow=false);
  154. translate([radius - size / 2, 0, 0])
  155. line(length=size, width=line_width, height=DIM_HEIGHT, left_arrow=false,
  156. right_arrow=false);
  157. translate([-radius - size / 2, 0, 0])
  158. line(length=size, width=line_width, height=DIM_HEIGHT, left_arrow=false,
  159. right_arrow=false);
  160. translate([0, -size / 2, 0])
  161. rotate([0, 0, 90])
  162. line(length=size, width=line_width, height=DIM_HEIGHT, left_arrow=false,
  163. right_arrow=false);
  164. translate([0, radius - size / 2, 0])
  165. rotate([0, 0, 90])
  166. line(length=size, width=line_width, height=DIM_HEIGHT, left_arrow=false,
  167. right_arrow=false);
  168. translate([0, -radius - size / 2, 0])
  169. rotate([0, 0, 90])
  170. line(length=size, width=line_width, height=DIM_HEIGHT, left_arrow=false,
  171. right_arrow=false);
  172. }
  173. module dimensions(length, line_width=DIM_LINE_WIDTH, loc=DIM_CENTER) {
  174. DIM_FONTSCALE = line_width * DIM_FONTSCALEFACTOR;
  175. text = str(length);
  176. space = len(text) * DIM_FONTSCALE * 7;
  177. if (loc == DIM_CENTER) {
  178. line(length=length / 2 - space / 2, width=line_width, height=DIM_HEIGHT,
  179. left_arrow=true, right_arrow=false);
  180. translate([(length) / 2 - space / 2 * .9, -DIM_FONTSCALE * 3, 0])
  181. scale([DIM_FONTSCALE, DIM_FONTSCALE, DIM_FONTSCALE])
  182. drawtext(text);
  183. translate([length / 2 + space / 2, 0, 0])
  184. line(length=length / 2 - space / 2, width=line_width, height=DIM_HEIGHT,
  185. left_arrow=false, right_arrow=true);
  186. } else {
  187. if (loc == DIM_LEFT) {
  188. line(length=length, width=line_width, height=DIM_HEIGHT,
  189. left_arrow=true, right_arrow=true);
  190. translate([-space, -DIM_FONTSCALE * 3, 0])
  191. scale([DIM_FONTSCALE, DIM_FONTSCALE, DIM_FONTSCALE])
  192. drawtext(text);
  193. } else {
  194. if (loc == DIM_RIGHT) {
  195. line(length=length, width=line_width, height=DIM_HEIGHT,
  196. left_arrow=true, right_arrow=true);
  197. translate([length + space, -DIM_FONTSCALE * 3, 0])
  198. scale([DIM_FONTSCALE, DIM_FONTSCALE, DIM_FONTSCALE])
  199. drawtext(text);
  200. } else {
  201. if (loc == DIM_OUTSIDE) {
  202. rotate([0, 180, 0])
  203. line(length=length / 2, width=line_width, height=DIM_HEIGHT,
  204. left_arrow=true, right_arrow=false);
  205. translate([(length) / 2 - space / 2 * .9,
  206. -DIM_FONTSCALE * 3, 0])
  207. scale([DIM_FONTSCALE, DIM_FONTSCALE, DIM_FONTSCALE])
  208. drawtext(text);
  209. translate([length, 0, 0])
  210. line(length=length / 2, width=line_width, height=DIM_HEIGHT,
  211. left_arrow=true, right_arrow=false);
  212. }
  213. }
  214. }
  215. }
  216. }
  217. module leader_line(angle, radius, angle_length, horz_line_length,
  218. direction=DIM_RIGHT, line_width=DIM_LINE_WIDTH, text, do_circle=false) {
  219. /* leader_line
  220. *
  221. * Creates a line that points directly at a center point from the given
  222. * radius.
  223. * Then, a short horzizontal line is generated, followed by text. The
  224. * direction of the horizontal short line defaults to the right, the
  225. * choice made by either DIM_RIGHT or DIM_LEFT
  226. */
  227. DIM_FONTSCALE = line_width * DIM_FONTSCALEFACTOR;
  228. text_length = len(text) * DIM_FONTSCALE * 6;
  229. space = DIM_FONTSCALE * 6;
  230. rotate([0, 0, angle])
  231. translate([radius, 0, 0])
  232. line(length=angle_length, width=line_width, height=DIM_HEIGHT,
  233. left_arrow=true, right_arrow=false);
  234. rotate([0, 0, angle])
  235. translate([radius + angle_length, 0, 0])
  236. rotate([0, 0, -angle])
  237. union() {
  238. if (direction == DIM_RIGHT) {
  239. line(length=horz_line_length, width=line_width, height=DIM_HEIGHT,
  240. left_arrow=false, right_arrow=false);
  241. translate([(horz_line_length + space), -DIM_FONTSCALE * 3, 0])
  242. scale([DIM_FONTSCALE, DIM_FONTSCALE, DIM_FONTSCALE])
  243. drawtext(text);
  244. if (do_circle) {
  245. translate([(horz_line_length + space + text_length/2),
  246. 0, 0])
  247. difference() {
  248. cylinder(h=DIM_HEIGHT, r=text_length + space - line_width,
  249. center=true, $fn=100);
  250. cylinder(h=.05, r=text_length + space - line_width * 2,
  251. center=true, $fn=100);
  252. }
  253. }
  254. } else {
  255. translate([-horz_line_length, 0, 0])
  256. line(length=horz_line_length, width=line_width, height=DIM_HEIGHT,
  257. left_arrow=false, right_arrow=false);
  258. translate([-(horz_line_length + space + text_length),
  259. -DIM_FONTSCALE * 3,
  260. 0])
  261. scale([DIM_FONTSCALE, DIM_FONTSCALE, DIM_FONTSCALE])
  262. drawtext(text);
  263. }
  264. }
  265. }
  266. module titleblock(lines, descs, details) {
  267. /* titleblock
  268. *
  269. * This module accepts the following arrays with formats:
  270. *
  271. * holds the description of the lines. width is a factor that
  272. * expands the line width beyond DIM_LINE_WIDTH
  273. *
  274. * lines = [[startx, starty, horz/vert, length, width],
  275. * [startx, starty, horz/vert, length, width]]
  276. *
  277. * holds the descriptions of the title blocks. these are meant to sit in
  278. * the upper left corner. size, like width above, is a factor that
  279. * increases/decreases the size of the font
  280. *
  281. * descs = [[startx, starty, horz/vert, text, size],
  282. * [startx, starty, horz/vert, text, size]]
  283. *
  284. * holds the detail associated with the part being documented
  285. *
  286. * details = [[startx, starty, horz/vert, text, size],
  287. * [startx, starty, horz/vert, text, size]]
  288. */
  289. DIM_FONTSCALE = DIM_LINE_WIDTH * .7;
  290. for (line = lines) {
  291. translate([line[0] * DIM_LINE_WIDTH,
  292. line[1] * DIM_LINE_WIDTH,
  293. 0])
  294. if (line[2] == DIM_VERT) {
  295. rotate([0, 0, -90])
  296. line(length=line[3] * DIM_LINE_WIDTH,
  297. width=DIM_LINE_WIDTH * line[4], height=DIM_HEIGHT,
  298. left_arrow=false, right_arrow=false);
  299. } else {
  300. line(length=(line[3] + 1) * DIM_LINE_WIDTH,
  301. width=DIM_LINE_WIDTH * line[4], height=DIM_HEIGHT,
  302. left_arrow=false, right_arrow=false);
  303. }
  304. }
  305. for (line = descs) {
  306. translate([line[0] * DIM_LINE_WIDTH, line[1] * DIM_LINE_WIDTH, 0])
  307. if (line[2] == DIM_VERT) {
  308. rotate([0, 0, 90])
  309. scale([DIM_FONTSCALE * line[4], DIM_FONTSCALE * line[4],
  310. DIM_FONTSCALE * line[4]])
  311. drawtext(line[3]);
  312. } else {
  313. scale([DIM_FONTSCALE * line[4], DIM_FONTSCALE * line[4],
  314. DIM_FONTSCALE * line[4]])
  315. drawtext(line[3]);
  316. }
  317. }
  318. for (line = details) {
  319. translate([line[0] * DIM_LINE_WIDTH, line[1] * DIM_LINE_WIDTH, 0])
  320. if (line[2] == DIM_VERT) {
  321. rotate([0, 0, 90])
  322. scale([DIM_FONTSCALE * line[4], DIM_FONTSCALE * line[4],
  323. DIM_FONTSCALE * line[4]])
  324. drawtext(line[3]);
  325. } else {
  326. scale([DIM_FONTSCALE * line[4], DIM_FONTSCALE * line[4],
  327. DIM_FONTSCALE * line[4]])
  328. drawtext(line[3]);
  329. }
  330. }
  331. }
  332. module sample_titleblock1() {
  333. /* sample titleblock
  334. *
  335. * Note the use of double thickness lines around the perimeter. Any line
  336. * can be adjusted to be thinner or thicker.
  337. *
  338. * Note also that since lines are centered on their widths, some adjustments
  339. * for half-width spacing is needed to avoid a jagged look on corners.
  340. * You can see that in the horizontal lines in the first section that are
  341. * offset by 1, which is the half-width of the outside line.
  342. */
  343. title_width = 290;
  344. row_height = 15;
  345. cols = [-1, 50, 114, 200, 215, 260];
  346. rows = [0, -row_height, -row_height * 2, -row_height * 3, -row_height * 4];
  347. // spacing tweaks to fit into the blocks
  348. desc_x = 2; // column offset for start of small text
  349. desc_y = -5; // row offset for start of small text
  350. det_y = -12; // row offset for start of detail text
  351. desc_size = .75; // relative size of description text
  352. lines = [
  353. // horizontal lines
  354. [cols[0], rows[0], DIM_HORZ, title_width, 2],
  355. [cols[0], rows[1], DIM_HORZ, title_width, 1],
  356. [cols[2], rows[2], DIM_HORZ, title_width - cols[2] - 1, 1],
  357. [cols[3], rows[3], DIM_HORZ, title_width - cols[3] - 1, 1],
  358. [cols[0], rows[4] - 1, DIM_HORZ, title_width, 2],
  359. // vertical lines
  360. [0, 0, DIM_VERT, row_height * 4, 2],
  361. [cols[1], rows[0], DIM_VERT, row_height, 1],
  362. [cols[2], rows[0], DIM_VERT, row_height * 4, 1],
  363. [cols[3], rows[0], DIM_VERT, row_height * 4, 1],
  364. [cols[4], rows[3], DIM_VERT, row_height, 1],
  365. [cols[5], rows[3], DIM_VERT, row_height, 1],
  366. [title_width - 1, 0, DIM_VERT, row_height * 4, 2],
  367. ];
  368. descs = [
  369. [cols[0] + desc_x, rows[0] + desc_y, DIM_HORZ,
  370. "Responsible dep", desc_size],
  371. [cols[1] + desc_x, rows[0] + desc_y, DIM_HORZ,
  372. "Technical reference", desc_size],
  373. [cols[2] + desc_x, rows[0] + desc_y, DIM_HORZ,
  374. "Creator", desc_size],
  375. [cols[3] + desc_x, rows[0] + desc_y, DIM_HORZ,
  376. "Approval person", desc_size],
  377. [cols[2] + desc_x, rows[1] + desc_y, DIM_HORZ,
  378. "Document type", desc_size],
  379. [cols[3] + desc_x, rows[1] + desc_y, DIM_HORZ,
  380. "Document status", desc_size],
  381. [cols[2] + desc_x, rows[2] + desc_y, DIM_HORZ,
  382. "Title", desc_size],
  383. [cols[3] + desc_x, rows[2] + desc_y, DIM_HORZ,
  384. "Identification number", desc_size],
  385. [cols[3] + desc_x, rows[3] + desc_y, DIM_HORZ,
  386. "Rev", desc_size],
  387. [cols[4] + desc_x, rows[3] + desc_y, DIM_HORZ,
  388. "Date of issue", desc_size],
  389. [cols[5] + desc_x, rows[3] + desc_y, DIM_HORZ,
  390. "Sheet", desc_size]
  391. ];
  392. details = [
  393. [cols[0] + desc_x, rows[0] + det_y, DIM_HORZ,
  394. " ", 1], //Responsible dep.
  395. [cols[1] + desc_x, rows[0] + det_y, DIM_HORZ,
  396. " ", 1], //Technical reference
  397. [cols[2] + desc_x, rows[0] + det_y, DIM_HORZ,
  398. "D. Smiley ", 1], //Creator
  399. [cols[3] + desc_x, rows[0] + det_y, DIM_HORZ,
  400. " ", 1], //Approval person
  401. [cols[0] + desc_x + 10, rows[2] + det_y, DIM_HORZ,
  402. "My OpenSCAD Project", 1],
  403. [cols[2] + desc_x, rows[1] + det_y, DIM_HORZ,
  404. " ", 1], //Document type
  405. [cols[3] + desc_x, rows[1] + det_y, DIM_HORZ,
  406. "First issue", 1], //Document status
  407. [cols[2] + desc_x, rows[2] + det_y, DIM_HORZ,
  408. "Sample Part", 1], //Title
  409. [cols[3] + desc_x, rows[2] + det_y, DIM_HORZ,
  410. "123", 1], //Identification number
  411. [cols[3] + desc_x, rows[3] + det_y, DIM_HORZ,
  412. " ", 1], //Rev
  413. [cols[4] + desc_x, rows[3] + det_y, DIM_HORZ,
  414. "2013-3-31", 1], //Date of issue
  415. [cols[5] + desc_x, rows[3] + det_y, DIM_HORZ,
  416. "1/100", 1] //Sheet
  417. ];
  418. titleblock(lines, descs, details);
  419. }
  420. module sample_revisionblock(revisions) {
  421. DIM_FONTSCALE = DIM_LINE_WIDTH * .7;
  422. // revision block headings
  423. row_height = 15;
  424. revision_width = 100;
  425. desc_x = 2;
  426. desc_y = -10;
  427. desc_size = 1;
  428. cols = [0, 20, 60, revision_width];
  429. rows = [0, -row_height, -row_height * 2];
  430. // draw
  431. lines = [
  432. // horizontal lines
  433. [cols[0], rows[0], DIM_HORZ, revision_width, 1],
  434. [cols[0], rows[1], DIM_HORZ, revision_width, 1],
  435. [cols[0], rows[2], DIM_HORZ, revision_width, 1],
  436. // vertical lines
  437. [cols[0], rows[0], DIM_VERT, row_height * 2, 1],
  438. [cols[1], rows[0], DIM_VERT, row_height, 1],
  439. [cols[2], rows[0], DIM_VERT, row_height, 1],
  440. [cols[3], rows[0], DIM_VERT, row_height * 2, 1],
  441. ];
  442. descs = [
  443. [cols[0] + desc_x, rows[0] + desc_y, DIM_HORZ,
  444. "Rev.", desc_size],
  445. [cols[1] + desc_x, rows[0] + desc_y, DIM_HORZ,
  446. "Date", desc_size],
  447. [cols[2] + desc_x, rows[0] + desc_y, DIM_HORZ,
  448. "Initials", desc_size],
  449. [cols[1] + desc_x, rows[1] + desc_y, DIM_HORZ,
  450. "Revisions", desc_size],
  451. ];
  452. details = [];
  453. num_revisions = len(revisions);
  454. translate([-(revision_width + 40) * DIM_LINE_WIDTH,
  455. row_height * 2 * DIM_LINE_WIDTH, 0])
  456. union() {
  457. titleblock(lines, descs, details);
  458. // now for the start of actual revisions
  459. // do this piecemeal -- draw the vertical first
  460. for (col = cols) {
  461. translate([col * DIM_LINE_WIDTH, 0, 0])
  462. rotate([0, 0, 90])
  463. line(num_revisions * row_height * DIM_LINE_WIDTH);
  464. }
  465. for (row = [0: len(revisions)]) {
  466. translate([0, row * row_height * DIM_LINE_WIDTH, 0])
  467. line(revision_width * DIM_LINE_WIDTH);
  468. for (col = [0:2]) {
  469. translate([(cols[col] + desc_x) * DIM_LINE_WIDTH,
  470. ((row + 1) * row_height + desc_y) * DIM_LINE_WIDTH, 0])
  471. scale([DIM_FONTSCALE, DIM_FONTSCALE, DIM_FONTSCALE])
  472. drawtext(revisions[row][col]);
  473. }
  474. }
  475. }
  476. }
  477. module sample_titleblock2() {
  478. row_height = 20;
  479. cols = [-.5, 100, 154, 270];
  480. title_width = cols[3];
  481. rows = [0, -row_height, -row_height * 2, -row_height * 3, -row_height * 4,
  482. -row_height * 5, -row_height * 6, -row_height * 7
  483. ];
  484. // spacing tweaks to fit into the blocks
  485. desc_x = 2; // column offset for start of small text
  486. desc_y = -5; // row offset for start of small text
  487. det_x = 15; // col offset for start of detail text
  488. det_y = -15; // row offset for start of detail text
  489. desc_size = .75; // relative size of description text
  490. lines = [
  491. // horizontal lines
  492. [-.5, 0, DIM_HORZ, title_width, 1],
  493. [cols[2], rows[1], DIM_HORZ, cols[3] - cols[2] - .5, 1],
  494. [cols[0], rows[2], DIM_HORZ, cols[1] - cols[0] - .5, 1],
  495. [cols[0], rows[3], DIM_HORZ, cols[3] - .5, 1],
  496. [cols[0], rows[4], DIM_HORZ, cols[2] - .5, 1],
  497. [cols[0], rows[5], DIM_HORZ, cols[3] - .5, 1],
  498. [cols[0], rows[6], DIM_HORZ, cols[2] - .5, 1],
  499. [cols[0], rows[7], DIM_HORZ, cols[2] - .5, 1],
  500. [cols[0], rows[7], DIM_HORZ, title_width, 1],
  501. // vertical lines
  502. [cols[0], rows[0], DIM_VERT, -rows[7], 1],
  503. [cols[1], rows[0], DIM_VERT, -rows[7], 1],
  504. [cols[2], rows[0], DIM_VERT, -rows[7], 1],
  505. [cols[3], rows[0], DIM_VERT, -rows[7], 1],
  506. ];
  507. part_desc = ["Material", "Finish", "Weight", "Part No."];
  508. doc_desc = ["Drawing Number",
  509. "Created by",
  510. "Reviewed by",
  511. "Date of issue"
  512. ];
  513. // aspects of the part
  514. part_details = [
  515. "My Sample Part", // title
  516. "Stainless Steel", // material
  517. " ", // finish
  518. "2.5", // weight
  519. "123", // part no
  520. ];
  521. // aspects documenting the creation of the part
  522. doc_details = [
  523. "33-2", // Drawing No.
  524. "D. Smiley", // Created by
  525. " ", // Reviewd by
  526. "2013-3-31", // Date
  527. ];
  528. // the organization making the part
  529. org_details = [
  530. "My logo",
  531. "Canny Machines",
  532. "Org Address, phone"
  533. ];
  534. descs = [
  535. // part description
  536. [cols[0] + desc_x, rows[2] + desc_y, DIM_HORZ, part_desc[0], desc_size],
  537. [cols[0] + desc_x, rows[3] + desc_y, DIM_HORZ, part_desc[1], desc_size],
  538. [cols[0] + desc_x, rows[4] + desc_y, DIM_HORZ, part_desc[2], desc_size],
  539. [cols[0] + desc_x, rows[5] + desc_y, DIM_HORZ, part_desc[3], desc_size],
  540. // documentation description
  541. [cols[1] + desc_x, rows[3] + desc_y, DIM_HORZ, doc_desc[0], desc_size],
  542. [cols[1] + desc_x, rows[4] + desc_y, DIM_HORZ, doc_desc[1], desc_size],
  543. [cols[1] + desc_x, rows[5] + desc_y, DIM_HORZ, doc_desc[2], desc_size],
  544. [cols[1] + desc_x, rows[6] + desc_y, DIM_HORZ, doc_desc[3], desc_size],
  545. ];
  546. details = [
  547. [cols[0] + desc_x, rows[0] + det_y, DIM_HORZ, part_details[0], 1.5],
  548. [cols[0] + desc_x, rows[2] + det_y, DIM_HORZ, part_details[1], 1],
  549. [cols[0] + desc_x, rows[3] + det_y, DIM_HORZ, part_details[2], 1],
  550. [cols[0] + desc_x, rows[4] + det_y, DIM_HORZ, part_details[3], 1],
  551. [cols[0] + desc_x, rows[5] + det_y, DIM_HORZ, part_details[4], 1],
  552. [cols[1] + desc_x * 2, rows[3] + det_y, DIM_HORZ, doc_details[0], 1],
  553. [cols[1] + desc_x * 2, rows[4] + det_y, DIM_HORZ, doc_details[1], 1],
  554. [cols[1] + desc_x * 2, rows[5] + det_y, DIM_HORZ, doc_details[2], 1],
  555. [cols[1] + desc_x * 2, rows[6] + det_y, DIM_HORZ, doc_details[3], 1],
  556. // Organization Details
  557. [cols[1] + desc_x, rows[1] + det_y, DIM_HORZ, org_details[0], 1.5],
  558. [cols[2] + desc_x, rows[0] + det_y, DIM_HORZ, org_details[1], 1.5],
  559. [cols[2] + desc_x, rows[1] + det_y, DIM_HORZ, org_details[2], 1],
  560. ];
  561. titleblock(lines, descs, details);
  562. revisions = [
  563. ["1a", "2013-4-1", "ds"],
  564. ["1b", "2013-4-2", "ds"],
  565. ["2a", "2013-4-3", "ds"],
  566. ["3a", "2013-4-5", "ds"],
  567. ["4a", "2013-4-15", "ds"],
  568. ];
  569. rotate([0, 0, 90])
  570. sample_revisionblock(revisions);
  571. }
  572. module sample_lines(){
  573. // sample lines
  574. union() {
  575. line(length=2, width=DIM_LINE_WIDTH, height=DIM_HEIGHT,
  576. left_arrow=false, right_arrow=false);
  577. translate([0, -0.25, 0])
  578. line(length=2, width=DIM_LINE_WIDTH, height=DIM_HEIGHT, left_arrow=true,
  579. right_arrow=false);
  580. translate([0, -0.5, 0])
  581. line(length=2, width=DIM_LINE_WIDTH, height=DIM_HEIGHT,
  582. left_arrow=false, right_arrow=true);
  583. translate([0, -0.75, 0])
  584. line(length=2, width=DIM_LINE_WIDTH, height=DIM_HEIGHT, left_arrow=true,
  585. right_arrow=true);
  586. }
  587. }
  588. module sample_dimensions() {
  589. /* shows all possibilities
  590. DIM_CENTER = 0;
  591. DIM_LEFT = 1;
  592. DIM_RIGHT = 2;
  593. DIM_OUTSIDE = 3;
  594. */
  595. length = 2.5;
  596. // The following two lines are vertical lines that bracket the dimensions
  597. // left arrow
  598. translate([0, -1.75, 0])
  599. rotate([0, 0, 90])
  600. line(length=length, width=DIM_LINE_WIDTH, height=DIM_HEIGHT,
  601. left_arrow=false, right_arrow=false);
  602. // right arrow
  603. translate([length, -1.75, 0])
  604. rotate([0, 0, 90])
  605. line(length=length, width=DIM_LINE_WIDTH, height=DIM_HEIGHT,
  606. left_arrow=false, right_arrow=false);
  607. // The following runs through all the dimension types
  608. for (i = [0:4]) {
  609. translate([0, -.5 * i, 0])
  610. dimensions(length=length, line_width=DIM_LINE_WIDTH, loc=i);
  611. }
  612. }
  613. module sample_leaderlines() {
  614. radius = .25;
  615. for (i = [0:6]) {
  616. leader_line(angle=i * 15, radius=.25, angle_length=(i * .25),
  617. horz_line_length=.5, direction=DIM_RIGHT,
  618. line_width=DIM_LINE_WIDTH,
  619. text=str("leader line angle: ", i * 15 + 90),
  620. do_circle=false
  621. );
  622. }
  623. for (i = [1:7]) {
  624. leader_line(angle=i * 20 + 90, radius=.25,
  625. angle_length=.75,
  626. horz_line_length=.5, direction=DIM_LEFT,
  627. line_width=DIM_LINE_WIDTH,
  628. text=str("leader line angle: ", i * 20 + 90));
  629. }
  630. for (i = [1:4]) {
  631. leader_line(angle=-i * 20, radius=.25, angle_length=1.5,
  632. horz_line_length=.25, direction=DIM_RIGHT,
  633. line_width=DIM_LINE_WIDTH,
  634. text=str(i),
  635. do_circle=true
  636. );
  637. }
  638. }
  639. module sample_circlecenter() {
  640. radius = .25;
  641. difference() {
  642. cube([1, 1, 1], center=true);
  643. cylinder(h=1.1, r=radius, center=true, $fn=100);
  644. }
  645. color("Black")
  646. translate([0, 0, .51])
  647. circle_center(radius=radius, size=DIM_HOLE_CENTER,
  648. line_width=DIM_LINE_WIDTH);
  649. }
  650. // uncomment these to sample
  651. // sample_lines();
  652. //
  653. // translate([-5.5, 0, 0])
  654. // sample_dimensions();
  655. //
  656. // translate([4, 0, 0])
  657. // sample_circlecenter();
  658. //
  659. // translate([-2, 3, 0])
  660. // sample_leaderlines();
  661. //
  662. // translate([3, 4, 0])
  663. // sample_titleblock1();
  664. //
  665. // translate([0, -2, 0])
  666. // sample_titleblock2();