gaf: Fix memory leak
[geda-gaf.git] / docs / wiki / geda-guile_scripting.ru.html
blobe29db1c741bc6d4f8d10c49dfc3af2abbc1ab071
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html>
4 <head>
5 <link rel="stylesheet" media="screen" type="text/css" href="./style.css" />
6 <link rel="stylesheet" media="screen" type="text/css" href="./design.css" />
7 <link rel="stylesheet" media="print" type="text/css" href="./print.css" />
9 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
10 </head>
11 <body>
13 <p>
14 <em>Эта страница доступна также на следующих языках:</em>
15 <a href="geda-guile_scripting.html" class="wikilink1" title="geda-guile_scripting.html">English</a>
16 </p>
18 <h2 id="скриптыguile">Скрипты Guile</h2>
19 <div class="level2">
21 <p>
22 В gEDA/gaf для обеспечения возможности написания скриптов на Scheme
23 используется Guile Scheme, и в распоряжении
24 разработчика оказываются все возможности языка Guile. <em>Справочное
25 руководство по Guile</em> [<em>Guile Reference Manual</em>] можно найти либо в
26 формате Info (<code>info guile</code> на большинстве систем), либо в
27 формате HTML на
28 веб-странице Guile.
29 </p>
31 <p>
32 Для доступа к объектам и страницам gEDA и для их изменения имеется набор
33 модулей, называемый gEDA Scheme API. Есть и <em>Справочное руководство по
34 Scheme в gEDA</em> [<em>gEDA Scheme Reference Manual</em>] в формате Info
35 (<code>info geda-scheme</code>).
36 </p>
38 </div>
40 <h3 id="учебники">Учебники</h3>
41 <div class="level3">
42 <ul>
43 <li class="level1"><div class="li"> <a href="geda-gnetlistschemetutorial.ru.html" class="wikilink2" title="geda-gnetlistschemetutorial.ru.html">Написание скриптов драйверов gnetlist на Scheme</a> (<em>John Doty</em>)</div>
44 </li>
45 </ul>
47 <p>
48 Смотрите также раздел <a href="geda-gschem_ug-extensions.ru.html" class="wikilink1" title="geda-gschem_ug-extensions.ru.html">Расширение
49 функциональности gschem</a> <em><a href="geda-gschem_ug.ru.html" class="wikilink1" title="geda-gschem_ug.ru.html">Руководства пользователя
50 gEDA gschem</a></em> и раздел <a href="geda-gnetlist_ug.ru.html#apiдрайверавscheme" class="wikilink1" title="geda-gnetlist_ug.ru.html">API драйвера в Scheme</a>
51 <em><a href="geda-gnetlist_ug.ru.html" class="wikilink1" title="geda-gnetlist_ug.ru.html">Руководства пользователя gEDA gnetlist</a></em>.
52 </p>
54 </div>
56 <h3 id="справочнаяинформация">Справочная информация</h3>
57 <div class="level3">
58 <ul>
59 <li class="level1"><div class="li"> <a href="https://www.google.com/search?q=gEDA%3Agnetlist%20Scheme%20primitives&amp;btnI=lucky" class="interwiki iw_go" title="https://www.google.com/search?q=gEDA%3Agnetlist%20Scheme%20primitives&amp;btnI=lucky">Примитивы Scheme для gnetlist</a></div>
60 </li>
61 <li class="level1"><div class="li"> <a href="geda-gschemrepl.ru.html" class="wikilink2" title="geda-gschemrepl.ru.html">Использование REPL в gschem</a></div>
62 </li>
63 </ul>
65 </div>
67 <h3 id="примерыскриптов">Примеры скриптов</h3>
68 <div class="level3">
70 <p>
71 Каждый скрипт можно скачать и загрузить в <strong>gschem</strong>:
72 </p>
73 <ul>
74 <li class="level1"><div class="li"> нажмите <kbd>:</kbd> и введите <pre class="code lisp"><span class="br0">&#40;</span>load <span class="st0">&quot;filename.scm&quot;</span><span class="br0">&#41;</span></pre>
75 </div>
76 </li>
77 <li class="level1"><div class="li"> затем нажмите <kbd>Enter</kbd></div>
78 </li>
79 </ul>
81 </div>
83 <h4 id="удалениеобъектовсзаданнымисвойствами">Удаление объектов с заданными свойствами</h4>
84 <div class="level4">
86 <p>
87 Например, удалим все объекты, являющиеся окружностями или дугами с нулевым
88 радиусом
89 </p>
90 <dl class="file">
91 <dt><a href="/./doku.php?do=export_code&amp;id=:geda:guile_scripting.ru.txt&amp;codeblock=1" title="Download Snippet" class="mediafile mf_scm">remove-objects.scm</a></dt>
92 <dd><pre class="code file lisp"><span class="br0">&#40;</span>use-modules <span class="br0">&#40;</span>geda page<span class="br0">&#41;</span><span class="br0">&#41;</span>
93 &nbsp;
94 <span class="co1">; Проверяет, является ли объект OBJECT окружностью (circle)</span>
95 <span class="co1">; или дугой (arc) с нулевым радиусом</span>
96 <span class="br0">&#40;</span>define <span class="br0">&#40;</span>zero-radius-object? object<span class="br0">&#41;</span>
97 <span class="br0">&#40;</span><span class="kw1">or</span>
98 <span class="br0">&#40;</span><span class="kw1">and</span> <span class="br0">&#40;</span>circle? object<span class="br0">&#41;</span> <span class="br0">&#40;</span><span class="sy0">=</span> <span class="br0">&#40;</span>circle-radius object<span class="br0">&#41;</span> <span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
99 <span class="br0">&#40;</span><span class="kw1">and</span> <span class="br0">&#40;</span>arc? object<span class="br0">&#41;</span> <span class="br0">&#40;</span><span class="sy0">=</span> <span class="br0">&#40;</span>arc-radius object<span class="br0">&#41;</span> <span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
100 &nbsp;
101 <span class="br0">&#40;</span><span class="kw1">apply</span> page-remove<span class="sy0">!</span> <span class="br0">&#40;</span>active-page<span class="br0">&#41;</span>
102 <span class="br0">&#40;</span>filter
103 zero-radius-object?
104 <span class="br0">&#40;</span>page-contents <span class="br0">&#40;</span>active-page<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></pre>
105 </dd></dl>
108 Предположим, нам необходимо удалить компонент с известным атрибутом, тогда
109 нам нужно также отделить и удалить все его атрибуты. Функция, определённая
110 ниже делает именно это.
111 </p>
112 <dl class="file">
113 <dt><a href="/./doku.php?do=export_code&amp;id=:geda:guile_scripting.ru.txt&amp;codeblock=2" title="Download Snippet" class="mediafile mf_scm">remove-components-with-attribs.scm</a></dt>
114 <dd><pre class="code file lisp"><span class="br0">&#40;</span>use-modules <span class="br0">&#40;</span>geda page<span class="br0">&#41;</span><span class="br0">&#41;</span>
115 <span class="br0">&#40;</span>use-modules <span class="br0">&#40;</span>geda object<span class="br0">&#41;</span><span class="br0">&#41;</span>
116 <span class="br0">&#40;</span>use-modules <span class="br0">&#40;</span>geda attrib<span class="br0">&#41;</span><span class="br0">&#41;</span>
117 &nbsp;
118 <span class="co1">; Удаляет все компоненты, имеющие атрибут NAME=VALUE, со страницы PAGE</span>
119 <span class="br0">&#40;</span>define <span class="br0">&#40;</span>delete-components-by-attrib<span class="sy0">!</span> page <span class="kw1">name</span> <span class="kw1">value</span><span class="br0">&#41;</span>
120 <span class="br0">&#40;</span>for-each
121 <span class="br0">&#40;</span><span class="kw1">lambda</span> <span class="br0">&#40;</span>obj<span class="br0">&#41;</span>
122 <span class="br0">&#40;</span><span class="kw1">if</span> <span class="br0">&#40;</span>component? obj<span class="br0">&#41;</span>
123 <span class="br0">&#40;</span>for-each
124 <span class="br0">&#40;</span><span class="kw1">lambda</span> <span class="br0">&#40;</span>attr<span class="br0">&#41;</span>
125 <span class="br0">&#40;</span><span class="kw1">and</span>
126 <span class="br0">&#40;</span>string<span class="sy0">=</span>? <span class="br0">&#40;</span>attrib-name attr<span class="br0">&#41;</span> <span class="kw1">name</span><span class="br0">&#41;</span>
127 <span class="br0">&#40;</span>string<span class="sy0">=</span>? <span class="br0">&#40;</span>attrib-value attr<span class="br0">&#41;</span> <span class="kw1">value</span><span class="br0">&#41;</span>
128 <span class="br0">&#40;</span><span class="kw1">let</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>attached-attribs <span class="br0">&#40;</span>object-attribs obj<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
129 <span class="br0">&#40;</span><span class="kw1">apply</span> detach-attribs<span class="sy0">!</span> obj attached-attribs<span class="br0">&#41;</span>
130 <span class="br0">&#40;</span><span class="kw1">apply</span> page-remove<span class="sy0">!</span> page obj attached-attribs<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
131 <span class="br0">&#40;</span>object-attribs obj<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
132 <span class="br0">&#40;</span>page-contents page<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></pre>
133 </dd></dl>
136 После загрузки файла, нажмите <kbd>:</kbd> и введите, например,
137 </p>
138 <pre class="code lisp"><span class="br0">&#40;</span>delete-components-by-attrib<span class="sy0">!</span> <span class="br0">&#40;</span>active-page<span class="br0">&#41;</span> <span class="st0">&quot;refdes&quot;</span> <span class="st0">&quot;R1&quot;</span><span class="br0">&#41;</span> </pre>
140 </div>
142 <h4 id="процедурыдлявводавывода">Процедуры для ввода/вывода</h4>
143 <div class="level4">
146 Следующий скрипт определяет две процедуры, которые могут использоваться
147 в режиме пакетной обработки с помощью скриптов для <strong>gaf shell</strong>:
148 </p>
149 <ul>
150 <li class="level1"><div class="li"> <code>schematic-file-&gt;page</code></div>
151 </li>
152 <li class="level1"><div class="li"> <code>page-&gt;schematic-file</code></div>
153 </li>
154 </ul>
155 <dl class="file">
156 <dt><a href="/./doku.php?do=export_code&amp;id=:geda:guile_scripting.ru.txt&amp;codeblock=4" title="Download Snippet" class="mediafile mf_scm">geda-io.scm</a></dt>
157 <dd><pre class="code file lisp"><span class="br0">&#40;</span>use-modules <span class="br0">&#40;</span>ice-<span class="nu0">9</span> lineio<span class="br0">&#41;</span><span class="br0">&#41;</span>
158 <span class="br0">&#40;</span>use-modules <span class="br0">&#40;</span>geda page<span class="br0">&#41;</span><span class="br0">&#41;</span>
159 &nbsp;
160 <span class="co1">; Процедуры ввода/вывода</span>
161 <span class="co1">; Читает файл FILE и выводит строку</span>
162 <span class="br0">&#40;</span>define <span class="br0">&#40;</span>file-<span class="sy0">&gt;</span>string file<span class="br0">&#41;</span>
163 <span class="br0">&#40;</span><span class="kw1">let</span>* <span class="br0">&#40;</span><span class="br0">&#40;</span>port <span class="br0">&#40;</span>make-line-buffering-input-port <span class="br0">&#40;</span>open-file file <span class="st0">&quot;r&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
164 <span class="br0">&#40;</span><span class="kw1">do</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>line <span class="st0">&quot;&quot;</span> <span class="br0">&#40;</span>read-string port<span class="br0">&#41;</span><span class="br0">&#41;</span>
165 <span class="br0">&#40;</span>s <span class="st0">&quot;&quot;</span> <span class="br0">&#40;</span>string-append s line<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
166 <span class="br0">&#40;</span><span class="br0">&#40;</span>eof-object? line<span class="br0">&#41;</span> <span class="co1">; тест</span>
167 <span class="br0">&#40;</span>close-port port<span class="br0">&#41;</span> <span class="co1">; выражение(я) для вычисления в конце</span>
168 s<span class="br0">&#41;</span> <span class="co1">; возвращаемое значение</span>
169 <span class="co1">; empty body</span>
170 <span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
171 &nbsp;
172 <span class="co1">; читает файл схемы FILE и возвращает объект страницы PAGE</span>
173 <span class="br0">&#40;</span>define <span class="br0">&#40;</span>schematic-file-<span class="sy0">&gt;</span>page file<span class="br0">&#41;</span>
174 <span class="br0">&#40;</span>string-<span class="sy0">&gt;</span>page file <span class="br0">&#40;</span>file-<span class="sy0">&gt;</span>string file<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
175 &nbsp;
176 <span class="co1">; сохраняет страницу схемы PAGE в файл FILE</span>
177 <span class="br0">&#40;</span>define <span class="br0">&#40;</span>page-<span class="sy0">&gt;</span>schematic-file page file<span class="br0">&#41;</span>
178 <span class="br0">&#40;</span>with-output-to-file file
179 <span class="br0">&#40;</span><span class="kw1">lambda</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#40;</span>display <span class="br0">&#40;</span>page-<span class="sy0">&gt;</span>string page<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></pre>
180 </dd></dl>
182 </div>
184 <h4 id="копированиеперемещениеивращениеобъектов">Копирование, перемещение и вращение объектов</h4>
185 <div class="level4">
186 <dl class="file">
187 <dt><a href="/./doku.php?do=export_code&amp;id=:geda:guile_scripting.ru.txt&amp;codeblock=5" title="Download Snippet" class="mediafile mf_scm">move-and-rotate.scm</a></dt>
188 <dd><pre class="code file lisp"> <span class="co1">; Scripting example by vzh per request of</span>
189 <span class="co1">; Kai-Martin Knaak :-)</span>
190 <span class="co1">; Use at your own risk.</span>
191 &nbsp;
192 <span class="co1">; Основная процедура здесь</span>
193 <span class="co1">; multiple-copy-move-and-rotate-selection, что можно сократить до</span>
194 <span class="co1">; mcmars.</span>
195 <span class="co1">; Использование:</span>
196 <span class="co1">; запустите gschem, чтобы там можно было использовать этот скрипт, например</span>
197 <span class="co1">; gschem -s move-and-rotate.scm</span>
198 <span class="co1">; выделите объекты в gschem, нажмите ':' (двоеточие) и наберите</span>
199 <span class="co1">; (mcmars '(1000 . 500) 90 10)</span>
200 <span class="co1">; нажмите &lt;Enter&gt;</span>
201 <span class="co1">; Наслаждайтесь!</span>
202 &nbsp;
203 &nbsp;
204 <span class="br0">&#40;</span>use-modules <span class="br0">&#40;</span>gschem selection<span class="br0">&#41;</span><span class="br0">&#41;</span>
205 &nbsp;
206 <span class="co1">; округление координат по ALIGN</span>
207 <span class="br0">&#40;</span>define <span class="br0">&#40;</span>ceiling-coords vector align<span class="br0">&#41;</span>
208 <span class="br0">&#40;</span><span class="kw1">cons</span>
209 <span class="br0">&#40;</span>* <span class="br0">&#40;</span>ceiling-quotient <span class="br0">&#40;</span><span class="kw1">car</span> vector<span class="br0">&#41;</span> align<span class="br0">&#41;</span> align<span class="br0">&#41;</span>
210 <span class="br0">&#40;</span>* <span class="br0">&#40;</span>ceiling-quotient <span class="br0">&#40;</span><span class="kw1">cdr</span> vector<span class="br0">&#41;</span> align<span class="br0">&#41;</span> align<span class="br0">&#41;</span>
211 <span class="br0">&#41;</span><span class="br0">&#41;</span>
212 &nbsp;
213 <span class="co1">; Получение минимума X и минимума Y двух пар координат</span>
214 <span class="br0">&#40;</span>define <span class="br0">&#40;</span>min-coords coord1 coord2<span class="br0">&#41;</span>
215 <span class="br0">&#40;</span><span class="kw1">let</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>x <span class="br0">&#40;</span><span class="kw1">min</span> <span class="br0">&#40;</span><span class="kw1">car</span> coord1<span class="br0">&#41;</span> <span class="br0">&#40;</span><span class="kw1">car</span> coord2<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
216 <span class="br0">&#40;</span>y <span class="br0">&#40;</span><span class="kw1">min</span> <span class="br0">&#40;</span><span class="kw1">cdr</span> coord1<span class="br0">&#41;</span> <span class="br0">&#40;</span><span class="kw1">cdr</span> coord2<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
217 <span class="co1">; возвращаемое значение</span>
218 <span class="br0">&#40;</span><span class="kw1">cons</span> x y<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
219 &nbsp;
220 <span class="co1">; Копирование, перемещение и вращение текущего выделения. Выделенные объекты</span>
221 <span class="co1">; сначала копируются, затем перемещаются на вектор VECTOR и, наконец, вращаются</span>
222 <span class="co1">; на угол ANGLE вокруг центра, который рассчитывается как округлённая до</span>
223 <span class="co1">; множителей 100 левая нижняя координата всех объектов в выделении.</span>
224 <span class="co1">; Если никакие объекты не выделены, открывает диалоговое окно сообщений gschem</span>
225 <span class="co1">; с предупреждением.</span>
226 <span class="co1">; Возвращает скопированные объекты.</span>
227 <span class="br0">&#40;</span>define <span class="br0">&#40;</span>copy-move-and-rotate-selection vector angle<span class="br0">&#41;</span>
228 <span class="br0">&#40;</span><span class="kw1">let</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>objects <span class="br0">&#40;</span>page-selection <span class="br0">&#40;</span>active-page<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
229 <span class="br0">&#40;</span><span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw1">null</span>? objects<span class="br0">&#41;</span>
230 <span class="br0">&#40;</span>gschem-msg <span class="st0">&quot;Select something first!&quot;</span><span class="br0">&#41;</span>
231 <span class="co1">; else</span>
232 <span class="br0">&#40;</span><span class="kw1">let</span>* <span class="br0">&#40;</span><span class="br0">&#40;</span>copied-objects <span class="br0">&#40;</span>map copy-object objects<span class="br0">&#41;</span><span class="br0">&#41;</span>
233 <span class="br0">&#40;</span>translated-objects <span class="br0">&#40;</span><span class="kw1">apply</span> translate-objects<span class="sy0">!</span> vector copied-objects<span class="br0">&#41;</span><span class="br0">&#41;</span>
234 <span class="br0">&#40;</span>bounds <span class="br0">&#40;</span><span class="kw1">apply</span> object-bounds translated-objects<span class="br0">&#41;</span><span class="br0">&#41;</span>
235 <span class="br0">&#40;</span>rotation-center <span class="br0">&#40;</span>ceiling-coords <span class="br0">&#40;</span>min-coords <span class="br0">&#40;</span><span class="kw1">car</span> bounds<span class="br0">&#41;</span> <span class="br0">&#40;</span><span class="kw1">cdr</span> bounds<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="nu0">100</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
236 <span class="br0">&#40;</span>rotated-objects <span class="br0">&#40;</span><span class="kw1">apply</span> rotate-objects<span class="sy0">!</span> rotation-center angle translated-objects<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
237 <span class="br0">&#40;</span><span class="kw1">apply</span> page-append<span class="sy0">!</span> <span class="br0">&#40;</span>active-page<span class="br0">&#41;</span> rotated-objects<span class="br0">&#41;</span>
238 rotated-objects<span class="br0">&#41;</span>
239 <span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
240 &nbsp;
241 <span class="co1">; Умножает VECTOR, который должен быть парой, на число NUMBER</span>
242 <span class="br0">&#40;</span>define <span class="br0">&#40;</span>multiply-vector-by vector number<span class="br0">&#41;</span>
243 <span class="br0">&#40;</span><span class="kw1">cons</span> <span class="br0">&#40;</span>* number <span class="br0">&#40;</span><span class="kw1">car</span> vector<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#40;</span>* number <span class="br0">&#40;</span><span class="kw1">cdr</span> vector<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
244 &nbsp;
245 <span class="co1">; Копирование, перемещение и вращение текущего выделения количество</span>
246 <span class="co1">; раз, указанное аргументом NUMBER. Применяет процедуру</span>
247 <span class="co1">; copy-move-and-rotate-selection несколько раз, каждый раз увеличивая</span>
248 <span class="co1">; вектор и угол на заданные значения VECTOR и ANGLE.</span>
249 <span class="co1">; Если никакие объекты не выделены, открывает gschem message dialog with</span>
250 <span class="co1">; warning.</span>
251 <span class="co1">; Если никакие объекты не выделены, открывает диалоговое окно сообщений gschem</span>
252 <span class="co1">; с предупреждением.</span>
253 <span class="co1">; Возвращаемое значение не определено.</span>
254 <span class="br0">&#40;</span>define <span class="br0">&#40;</span>multiple-copy-move-and-rotate-selection vector angle num<span class="br0">&#41;</span>
255 <span class="br0">&#40;</span><span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw1">null</span>? <span class="br0">&#40;</span>page-selection <span class="br0">&#40;</span>active-page<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
256 <span class="br0">&#40;</span>gschem-msg <span class="st0">&quot;Select something first!&quot;</span><span class="br0">&#41;</span>
257 <span class="co1">; else</span>
258 <span class="br0">&#40;</span><span class="kw1">do</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>i num <span class="br0">&#40;</span><span class="nu0">1</span>- i<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
259 <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="sy0">=</span> i <span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
260 <span class="br0">&#40;</span>copy-move-and-rotate-selection
261 <span class="br0">&#40;</span>multiply-vector-by vector i<span class="br0">&#41;</span> <span class="br0">&#40;</span>* angle i<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
262 <span class="br0">&#41;</span><span class="br0">&#41;</span>
263 &nbsp;
264 <span class="co1">; Сокращение для имени процедуры multiple-copy-move-and-rotate-selection</span>
265 <span class="br0">&#40;</span>define mcmars multiple-copy-move-and-rotate-selection<span class="br0">&#41;</span> </pre>
266 </dd></dl>
268 </div>
270 <h4 id="редактированиегруппыатрибутов">Редактирование группы атрибутов</h4>
271 <div class="level4">
274 Допустим, вы выделили несколько позиционных обозначений (атрибут refdes)
275 резисторов и хотите переименовать их все сразу, например, если они были
276 скопированы из другого места.
277 </p>
278 <dl class="file">
279 <dt><a href="/./doku.php?do=export_code&amp;id=:geda:guile_scripting.ru.txt&amp;codeblock=6" title="Download Snippet" class="mediafile mf_">set-selected-attribs-value</a></dt>
280 <dd><pre class="code file lisp"><span class="br0">&#40;</span>use-modules <span class="br0">&#40;</span>gschem selection<span class="br0">&#41;</span><span class="br0">&#41;</span>
281 &nbsp;
282 <span class="br0">&#40;</span>define <span class="br0">&#40;</span>set-selected-attribs-value<span class="sy0">!</span> <span class="kw1">value</span><span class="br0">&#41;</span>
283 <span class="br0">&#40;</span>for-each
284 <span class="br0">&#40;</span><span class="kw1">lambda</span> <span class="br0">&#40;</span>attrib<span class="br0">&#41;</span>
285 <span class="br0">&#40;</span>set-attrib-value<span class="sy0">!</span> attrib <span class="kw1">value</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
286 <span class="br0">&#40;</span>page-selection <span class="br0">&#40;</span>active-page<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></pre>
287 </dd></dl>
290 Использование процедуры в <strong>gschem</strong>:
291 </p>
292 <pre class="code lisp"><span class="br0">&#40;</span>set-selected-attribs-value<span class="sy0">!</span> <span class="st0">&quot;R100.?&quot;</span><span class="br0">&#41;</span> </pre>
295 Теперь, после изменения их номеров с помощью <kbd>T</kbd> <kbd>U</kbd>, вы
296 копируете их все и хотите переименовать эти скопированные резисторы, добавив
297 суффикс:
298 </p>
299 <dl class="file">
300 <dt><a href="/./doku.php?do=export_code&amp;id=:geda:guile_scripting.ru.txt&amp;codeblock=8" title="Download Snippet" class="mediafile mf_scm">append-selected-attribs-suffix.scm</a></dt>
301 <dd><pre class="code file lisp"><span class="br0">&#40;</span>use-modules <span class="br0">&#40;</span>gschem selection<span class="br0">&#41;</span><span class="br0">&#41;</span>
302 &nbsp;
303 <span class="br0">&#40;</span>define <span class="br0">&#40;</span>append-selected-attribs-suffix<span class="sy0">!</span> suffix<span class="br0">&#41;</span>
304 <span class="br0">&#40;</span>for-each
305 <span class="br0">&#40;</span><span class="kw1">lambda</span> <span class="br0">&#40;</span>attrib<span class="br0">&#41;</span>
306 <span class="br0">&#40;</span>set-attrib-value<span class="sy0">!</span>
307 attrib
308 <span class="br0">&#40;</span>string-append <span class="br0">&#40;</span>attrib-value attrib<span class="br0">&#41;</span> suffix<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
309 <span class="br0">&#40;</span>page-selection <span class="br0">&#40;</span>active-page<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></pre>
310 </dd></dl>
313 Использование процедуры в <strong>gschem</strong>:
314 </p>
315 <pre class="code lisp"><span class="br0">&#40;</span>append-selected-attribs-suffix<span class="sy0">!</span> <span class="st0">&quot;-top&quot;</span><span class="br0">&#41;</span> </pre>
318 Теперь переименуем несколько других атрибутов, добавив префикс:
319 </p>
320 <dl class="file">
321 <dt><a href="/./doku.php?do=export_code&amp;id=:geda:guile_scripting.ru.txt&amp;codeblock=10" title="Download Snippet" class="mediafile mf_scm">append-selected-attribs-prefix.scm</a></dt>
322 <dd><pre class="code file lisp"><span class="br0">&#40;</span>use-modules <span class="br0">&#40;</span>gschem selection<span class="br0">&#41;</span><span class="br0">&#41;</span>
323 &nbsp;
324 <span class="br0">&#40;</span>define <span class="br0">&#40;</span>append-selected-attribs-prefix<span class="sy0">!</span> prefix<span class="br0">&#41;</span>
325 <span class="br0">&#40;</span>for-each
326 <span class="br0">&#40;</span><span class="kw1">lambda</span> <span class="br0">&#40;</span>object<span class="br0">&#41;</span>
327 <span class="br0">&#40;</span><span class="kw1">and</span> <span class="br0">&#40;</span>attribute? object<span class="br0">&#41;</span>
328 <span class="br0">&#40;</span>set-attrib-value<span class="sy0">!</span>
329 object
330 <span class="br0">&#40;</span>string-append prefix <span class="br0">&#40;</span>attrib-value object<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
331 <span class="br0">&#40;</span>page-selection <span class="br0">&#40;</span>active-page<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></pre>
332 </dd></dl>
335 Использование процедуры в <strong>gschem</strong>:
336 </p>
337 <pre class="code lisp"><span class="br0">&#40;</span>append-selected-attribs-prefix<span class="sy0">!</span> <span class="st0">&quot;A1.&quot;</span><span class="br0">&#41;</span> </pre>
340 Давайте заменим первые буквы выделенных атрибутов префиксом:
341 </p>
342 <dl class="file">
343 <dt><a href="/./doku.php?do=export_code&amp;id=:geda:guile_scripting.ru.txt&amp;codeblock=12" title="Download Snippet" class="mediafile mf_scm">append-selected-attribs-prefix.scm</a></dt>
344 <dd><pre class="code file lisp"><span class="br0">&#40;</span>use-modules <span class="br0">&#40;</span>gschem selection<span class="br0">&#41;</span><span class="br0">&#41;</span>
345 &nbsp;
346 <span class="br0">&#40;</span>define <span class="br0">&#40;</span>replace-selected-attribs-prefix<span class="sy0">!</span> prefix<span class="br0">&#41;</span>
347 <span class="br0">&#40;</span>for-each
348 <span class="br0">&#40;</span><span class="kw1">lambda</span> <span class="br0">&#40;</span>object<span class="br0">&#41;</span>
349 <span class="br0">&#40;</span><span class="kw1">and</span> <span class="br0">&#40;</span>attribute? object<span class="br0">&#41;</span>
350 <span class="br0">&#40;</span>set-attrib-value<span class="sy0">!</span>
351 object
352 <span class="br0">&#40;</span>string-append
353 prefix
354 <span class="br0">&#40;</span>string-copy <span class="br0">&#40;</span>attrib-value object<span class="br0">&#41;</span> <span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
355 <span class="br0">&#40;</span>page-selection <span class="br0">&#40;</span>active-page<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></pre>
356 </dd></dl>
359 Использование процедуры в <strong>gschem</strong>:
360 </p>
361 <pre class="code lisp"><span class="br0">&#40;</span>replace-selected-attribs-prefix<span class="sy0">!</span> <span class="st0">&quot;C&quot;</span><span class="br0">&#41;</span> </pre>
364 Давайте переименуем выделенные атрибуты <code>netname=</code>, увеличив их значения
365 на определённое число:
366 </p>
367 <dl class="file">
368 <dt><a href="/./doku.php?do=export_code&amp;id=:geda:guile_scripting.ru.txt&amp;codeblock=14" title="Download Snippet" class="mediafile mf_scm">add-selected-attribs-number.scm</a></dt>
369 <dd><pre class="code file lisp"><span class="br0">&#40;</span>use-modules <span class="br0">&#40;</span>gschem selection<span class="br0">&#41;</span><span class="br0">&#41;</span>
370 &nbsp;
371 <span class="br0">&#40;</span>define <span class="br0">&#40;</span>add-selected-attribs-number<span class="sy0">!</span> number<span class="br0">&#41;</span>
372 <span class="br0">&#40;</span>for-each
373 <span class="br0">&#40;</span><span class="kw1">lambda</span> <span class="br0">&#40;</span>object<span class="br0">&#41;</span>
374 <span class="br0">&#40;</span><span class="kw1">and</span> <span class="br0">&#40;</span>attribute? object<span class="br0">&#41;</span>
375 <span class="br0">&#40;</span>set-attrib-value<span class="sy0">!</span>
376 object
377 <span class="br0">&#40;</span>number-<span class="sy0">&gt;</span>string
378 <span class="br0">&#40;</span>+ <span class="br0">&#40;</span>string-<span class="sy0">&gt;</span>number <span class="br0">&#40;</span>attrib-value object<span class="br0">&#41;</span><span class="br0">&#41;</span> number<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
379 <span class="br0">&#40;</span>page-selection <span class="br0">&#40;</span>active-page<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></pre>
380 </dd></dl>
383 Использование процедуры в <strong>gschem</strong>:
384 </p>
385 <pre class="code lisp"><span class="br0">&#40;</span>add-selected-attribs-number<span class="sy0">!</span> <span class="nu0">100</span><span class="br0">&#41;</span> </pre>
388 Мы могли бы задать любую функцию вместо &quot;+&quot; для номера соединения в этой
389 процедуре. Например:
390 </p>
391 <dl class="file">
392 <dt><a href="/./doku.php?do=export_code&amp;id=:geda:guile_scripting.ru.txt&amp;codeblock=16" title="Download Snippet" class="mediafile mf_scm">use-another-func.scm</a></dt>
393 <dd><pre class="code file lisp"><span class="br0">&#40;</span>use-modules <span class="br0">&#40;</span>gschem selection<span class="br0">&#41;</span><span class="br0">&#41;</span>
394 &nbsp;
395 <span class="br0">&#40;</span>define <span class="br0">&#40;</span>use-another-func<span class="sy0">!</span> func<span class="br0">&#41;</span>
396 <span class="br0">&#40;</span>for-each
397 <span class="br0">&#40;</span><span class="kw1">lambda</span> <span class="br0">&#40;</span>object<span class="br0">&#41;</span>
398 <span class="br0">&#40;</span><span class="kw1">and</span> <span class="br0">&#40;</span>attribute? object<span class="br0">&#41;</span>
399 <span class="br0">&#40;</span>set-attrib-value<span class="sy0">!</span>
400 object
401 <span class="br0">&#40;</span>number-<span class="sy0">&gt;</span>string
402 <span class="br0">&#40;</span>func <span class="br0">&#40;</span>string-<span class="sy0">&gt;</span>number <span class="br0">&#40;</span>attrib-value object<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
403 <span class="br0">&#40;</span>page-selection <span class="br0">&#40;</span>active-page<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></pre>
404 </dd></dl>
407 Использование процедуры в <strong>gschem</strong>:
408 </p>
409 <pre class="code lisp"><span class="br0">&#40;</span>use-another-func<span class="sy0">!</span> -<span class="br0">&#41;</span>
410 <span class="br0">&#40;</span>define <span class="br0">&#40;</span>multiply-by-<span class="nu0">2</span> x<span class="br0">&#41;</span>
411 <span class="br0">&#40;</span>* <span class="nu0">2</span> x<span class="br0">&#41;</span><span class="br0">&#41;</span>
412 <span class="br0">&#40;</span>use-another-func<span class="sy0">!</span> multiply-by-<span class="nu0">2</span><span class="br0">&#41;</span></pre>
414 </div>
415 </body>
416 </html>