devman.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <!DOCTYPE html>
  2. <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
  3. <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
  4. <head>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>FlatCAM Developer Manual &mdash; Cirkuix 0.5 documentation</title>
  8. <link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>
  9. <script type="text/javascript">
  10. var DOCUMENTATION_OPTIONS = {
  11. URL_ROOT:'./',
  12. VERSION:'0.5',
  13. COLLAPSE_INDEX:false,
  14. FILE_SUFFIX:'.html',
  15. HAS_SOURCE: true
  16. };
  17. </script>
  18. <script type="text/javascript" src="_static/jquery.js"></script>
  19. <script type="text/javascript" src="_static/underscore.js"></script>
  20. <script type="text/javascript" src="_static/doctools.js"></script>
  21. <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  22. <script type="text/javascript" src="_static/js/theme.js"></script>
  23. <script type="text/javascript">
  24. jQuery(function () {
  25. SphinxRtdTheme.StickyNav.enable();
  26. });
  27. </script>
  28. <link rel="top" title="Cirkuix 0.5 documentation" href="index.html"/>
  29. <link rel="prev" title="FlatCAM Application" href="app.html"/>
  30. <script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
  31. </head>
  32. <body class="wy-body-for-nav" role="document">
  33. <div class="wy-grid-for-nav">
  34. <nav data-toggle="wy-nav-shift" class="wy-nav-side">
  35. <div class="wy-side-nav-search">
  36. <a href="index.html" class="icon icon-home"> Cirkuix</a>
  37. <div role="search">
  38. <form id ="rtd-search-form" class="wy-form" action="search.html" method="get">
  39. <input type="text" name="q" placeholder="Search docs" />
  40. <input type="hidden" name="check_keywords" value="yes" />
  41. <input type="hidden" name="area" value="default" />
  42. </form>
  43. </div>
  44. </div>
  45. <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
  46. <ul class="current">
  47. <li class="toctree-l1"><a class="reference internal" href="camlib.html">Camlib</a><ul>
  48. <li class="toctree-l2"><a class="reference internal" href="camlib.html#geometry">Geometry</a></li>
  49. <li class="toctree-l2"><a class="reference internal" href="camlib.html#gerber">Gerber</a></li>
  50. <li class="toctree-l2"><a class="reference internal" href="camlib.html#aperturemacro">ApertureMacro</a></li>
  51. <li class="toctree-l2"><a class="reference internal" href="camlib.html#excellon">Excellon</a></li>
  52. <li class="toctree-l2"><a class="reference internal" href="camlib.html#cncjob">CNCJob</a></li>
  53. </ul>
  54. </li>
  55. <li class="toctree-l1"><a class="reference internal" href="flatcamobj.html">FlatCAM Objects</a><ul>
  56. <li class="toctree-l2"><a class="reference internal" href="flatcamobj.html#flatcamobj">FlatCAMObj</a></li>
  57. <li class="toctree-l2"><a class="reference internal" href="flatcamobj.html#flatcamgerber">FlatCAMGerber</a></li>
  58. <li class="toctree-l2"><a class="reference internal" href="flatcamobj.html#flatcamexcellon">FlatCAMExcellon</a></li>
  59. <li class="toctree-l2"><a class="reference internal" href="flatcamobj.html#flatcamcncjob">FlatCAMCNCjob</a></li>
  60. <li class="toctree-l2"><a class="reference internal" href="flatcamobj.html#flatcamgeometry">FlatCAMGeometry</a></li>
  61. </ul>
  62. </li>
  63. <li class="toctree-l1"><a class="reference internal" href="app.html">FlatCAM Application</a><ul>
  64. <li class="toctree-l2"><a class="reference internal" href="app.html#app">App</a></li>
  65. <li class="toctree-l2"><a class="reference internal" href="app.html#plotcanvas">PlotCanvas</a></li>
  66. <li class="toctree-l2"><a class="reference internal" href="app.html#objectcollection">ObjectCollection</a></li>
  67. <li class="toctree-l2"><a class="reference internal" href="app.html#measurement">Measurement</a></li>
  68. </ul>
  69. </li>
  70. <li class="toctree-l1 current"><a class="current reference internal" href="">FlatCAM Developer Manual</a><ul>
  71. <li class="toctree-l2"><a class="reference internal" href="#options">Options</a></li>
  72. <li class="toctree-l2"><a class="reference internal" href="#serialization">Serialization</a></li>
  73. <li class="toctree-l2"><a class="reference internal" href="#geometry-processing">Geometry Processing</a></li>
  74. </ul>
  75. </li>
  76. </ul>
  77. </div>
  78. &nbsp;
  79. </nav>
  80. <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
  81. <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
  82. <i data-toggle="wy-nav-top" class="icon icon-reorder"></i>
  83. <a href="index.html">Cirkuix</a>
  84. </nav>
  85. <div class="wy-nav-content">
  86. <div class="rst-content">
  87. <div role="navigation" aria-label="breadcrumbs navigation">
  88. <ul class="wy-breadcrumbs">
  89. <li><a href="index.html">Docs</a> &raquo;</li>
  90. <li>FlatCAM Developer Manual</li>
  91. <li class="wy-breadcrumbs-aside">
  92. <a href="_sources/devman.txt" rel="nofollow"> View page source</a>
  93. </li>
  94. </ul>
  95. <hr/>
  96. </div>
  97. <div role="main">
  98. <div class="section" id="flatcam-developer-manual">
  99. <h1>FlatCAM Developer Manual<a class="headerlink" href="#flatcam-developer-manual" title="Permalink to this headline">¶</a></h1>
  100. <div class="section" id="options">
  101. <h2>Options<a class="headerlink" href="#options" title="Permalink to this headline">¶</a></h2>
  102. <p>There are <strong>Application Defaults</strong>, <strong>Project Options</strong> and <strong>Object Options</strong> in FlatCAM.</p>
  103. <p><strong>Application Defaults</strong> are stored in <tt class="docutils literal"><span class="pre">app.defaults</span></tt>. This gets populated (updated) from the <tt class="docutils literal"><span class="pre">defaults.json</span></tt> file upon startup. These can be edited from the Options tab, where each widget calls <tt class="docutils literal"><span class="pre">app.on_options_update()</span></tt> if a change is detected. This function iterates over the keys of <tt class="docutils literal"><span class="pre">app.defaults</span></tt> and reads the GUI elements whose name is <tt class="docutils literal"><span class="pre">type</span> <span class="pre">+</span> <span class="pre">&quot;_app_&quot;</span> <span class="pre">key</span></tt>. Therefore, for an option to be recognized, it must be added to <tt class="docutils literal"><span class="pre">defaults.json</span></tt> in the first place. When saving, done in <tt class="docutils literal"><span class="pre">app.on_file_savedefaults()</span></tt>, the file is updated, not overwritten.</p>
  104. <p><strong>Project Options</strong> inherit all options from Application Defaults upon startup. They can be changed thereafter from the UI or by opening a project, which contain previously saved Project Options. These are store in <tt class="docutils literal"><span class="pre">app.options</span></tt> and can be written and read from the Options tab in the same way as with Application defaults.</p>
  105. <p><strong>Object Options</strong> for each object are inherited from Project Options upon creation of each new object. They can be modified independently from the Project&#8217;s options thereafter through the UI, where the widget containing the option is identified by name: <tt class="docutils literal"><span class="pre">type</span> <span class="pre">+</span> <span class="pre">kind</span> <span class="pre">+</span> <span class="pre">&quot;_&quot;</span> <span class="pre">+</span> <span class="pre">option</span></tt>. They are stored in <tt class="docutils literal"><span class="pre">object.options</span></tt>. They are saved along the Project options when saving the project.</p>
  106. <p>The syntax of UI widget names contain a <tt class="docutils literal"><span class="pre">type</span></tt>, which identifies what <em>type of widget</em> it is and how its value is supposed to be fetched, and a <tt class="docutils literal"><span class="pre">kind</span></tt>, which refer to what <em>kind of FlatCAM Object</em> it is for.</p>
  107. </div>
  108. <div class="section" id="serialization">
  109. <h2>Serialization<a class="headerlink" href="#serialization" title="Permalink to this headline">¶</a></h2>
  110. <p>Serialization refers to converting objects into a form that can be saved in a text file and recontructing objects from a text file.</p>
  111. <p>Saving and loading projects require serialization. These are done in <tt class="docutils literal"><span class="pre">App.save_project(filename)</span></tt> and <tt class="docutils literal"><span class="pre">App.open_project(filename)</span></tt>.</p>
  112. <p>Serialization in FlatCAM takes 2 forms. The first is calling objects&#8217; <tt class="docutils literal"><span class="pre">to_dict()</span></tt> method, which is inherited from <tt class="docutils literal"><span class="pre">Geometry.to_dict()</span></tt>:</p>
  113. <div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">to_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  114. <span class="sd">&quot;&quot;&quot;</span>
  115. <span class="sd"> Returns a respresentation of the object as a dictionary.</span>
  116. <span class="sd"> Attributes to include are listed in ``self.ser_attrs``.</span>
  117. <span class="sd"> :return: A dictionary-encoded copy of the object.</span>
  118. <span class="sd"> :rtype: dict</span>
  119. <span class="sd"> &quot;&quot;&quot;</span>
  120. <span class="n">d</span> <span class="o">=</span> <span class="p">{}</span>
  121. <span class="k">for</span> <span class="n">attr</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">ser_attrs</span><span class="p">:</span>
  122. <span class="n">d</span><span class="p">[</span><span class="n">attr</span><span class="p">]</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">attr</span><span class="p">)</span>
  123. <span class="k">return</span> <span class="n">d</span>
  124. </pre></div>
  125. </div>
  126. <p>This creates a dictionary with attributes specified in the object&#8217;s <tt class="docutils literal"><span class="pre">ser_attrs</span></tt> list. If these are not in a serialized form, they will be processed later by the function <tt class="docutils literal"><span class="pre">to_dict()</span></tt>:</p>
  127. <div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">to_dict</span><span class="p">(</span><span class="n">geo</span><span class="p">):</span>
  128. <span class="sd">&quot;&quot;&quot;</span>
  129. <span class="sd"> Makes a Shapely geometry object into serializeable form.</span>
  130. <span class="sd"> :param geo: Shapely geometry.</span>
  131. <span class="sd"> :type geo: BaseGeometry</span>
  132. <span class="sd"> :return: Dictionary with serializable form if ``geo`` was</span>
  133. <span class="sd"> BaseGeometry, otherwise returns ``geo``.</span>
  134. <span class="sd"> &quot;&quot;&quot;</span>
  135. <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">geo</span><span class="p">,</span> <span class="n">BaseGeometry</span><span class="p">):</span>
  136. <span class="k">return</span> <span class="p">{</span>
  137. <span class="s">&quot;__class__&quot;</span><span class="p">:</span> <span class="s">&quot;Shply&quot;</span><span class="p">,</span>
  138. <span class="s">&quot;__inst__&quot;</span><span class="p">:</span> <span class="n">sdumps</span><span class="p">(</span><span class="n">geo</span><span class="p">)</span>
  139. <span class="p">}</span>
  140. <span class="k">return</span> <span class="n">geo</span>
  141. </pre></div>
  142. </div>
  143. <p>This is used in <tt class="docutils literal"><span class="pre">json.dump(d,</span> <span class="pre">f,</span> <span class="pre">default=to_dict)</span></tt> and is applied to objects that json encounters to be in a non-serialized form.</p>
  144. </div>
  145. <div class="section" id="geometry-processing">
  146. <h2>Geometry Processing<a class="headerlink" href="#geometry-processing" title="Permalink to this headline">¶</a></h2>
  147. </div>
  148. </div>
  149. </div>
  150. <footer>
  151. <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
  152. <a href="app.html" class="btn btn-neutral" title="FlatCAM Application"><span class="icon icon-circle-arrow-left"></span> Previous</a>
  153. </div>
  154. <hr/>
  155. <div role="contentinfo">
  156. <p>
  157. &copy; Copyright 2014, Juan Pablo Caram.
  158. </p>
  159. </div>
  160. <a href="https://github.com/snide/sphinx_rtd_theme">Sphinx theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>
  161. </footer>
  162. </div>
  163. </div>
  164. </section>
  165. </div>
  166. </body>
  167. </html>