stipple.hpp
Go to the documentation of this file.
1 /*
2  * COPYRIGHT
3  *
4  * Stipple, cross hatching add-in for gEDA PCB
5  * Copyright (C) 2015 Charles Repetti
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21 */
22 
124 //
125 // \image html PercentFill.png
126 
132 #ifndef STIPPLE_HPP_
133 #define STIPPLE_HPP_
134 
135 #include <stdio.h>
136 #include <stdlib.h>
137 #include <math.h>
138 
139 extern "C" {
140 #include "config.h"
141 #include "global.h"
142 #include "data.h"
143 #include "macro.h"
144 #include "create.h"
145 #include "remove.h"
146 #include "hid.h"
147 #include "error.h"
148 #include "rtree.h"
149 #include "polygon.h"
150 #include "polyarea.h"
151 #include "assert.h"
152 #include "strflags.h"
153 #include "find.h"
154 #include "misc.h"
155 #include "draw.h"
156 #include "undo.h"
157 }
158 
159 #include <gtk/gtk.h>
160 
161 #include <iostream>
162 #include <fstream>
163 #include <string>
164 #include <iterator>
165 #include <algorithm>
166 #include <deque>
167 
168 #include <boost/math/constants/constants.hpp>
169 #include <boost/polygon/polygon.hpp>
170 #include <boost/foreach.hpp>
171 #include <boost/format.hpp>
172 #include <boost/regex.hpp>
173 #include <boost/lexical_cast.hpp>
174 #include <boost/geometry/geometries/geometries.hpp>
175 
176 #include <boost/geometry.hpp>
177 #include <boost/geometry/geometries/point_xy.hpp>
178 #include <boost/geometry/geometries/polygon.hpp>
179 
181 #define foreach BOOST_FOREACH
182 
184 #define BoxTypePtr BoxType *
185 
187 #define LayerTypePtr LayerType *
188 
190 #define PointTypePtr PointType *
191 
193 #define PolygonTypePtr PolygonType *
194 
195 namespace gtl = boost::polygon;
196 
197 using namespace std;
198 using namespace gtl;
199 using namespace boost::polygon::operators;
200 
202 typedef gtl::polygon_with_holes_data<int> b_polygon;
203 
205 typedef gtl::polygon_traits<b_polygon>::point_type b_point;
206 
208 typedef gtl::polygon_with_holes_traits<b_polygon>::hole_type b_hole;
209 
211 typedef std::vector<b_polygon> b_polygon_set;
212 
214 const double PI = boost::math::constants::pi<double>();
215 
217 const string component_perimeter = "comp-perim";
218 
220 const string component_stipple = "comp-stipple";
221 
223 const string solder_perimeter = "solder-perim";
224 
226 const string solder_stipple = "solder-stipple";
227 
229 const double NanometerToMil = 3.93700787E10-5;
230 
232 const Coord MilToNanometer = 254;
233 
236 extern bool Cancel;
237 
238 extern Coord
242  SolderTrace,
246  SolderPitch;
247 
250 { MakeTopLayer, MakeBottomLayer, MakeBothLayers, MakeSelected, MakeDelete };
251 
253 extern MakeLayers_t MakeLayers;
254 
256 extern vector<string> MakeLayerNames;
257 
259 void ParameterDialog();
260 
265 void MakeAllLayers();
266 
269 void LayerFactory(int i);
270 
272 void Log(const char *format, ...);
273 
277 #define POLYGON_LP(layer) do { \
278  GList *__iter, *__next; \
279  Cardinal n = 0; \
280  for (__iter = (layer)->Polygon, __next = g_list_next (__iter); \
281  __iter != NULL; \
282  __iter = __next, __next = g_list_next (__iter), n++) { \
283  PolygonType *polygon = (PolygonType *)__iter->data;
284 
288 #define POLYGONPOINT_LP(polygon) do { \
289  int n; \
290  PointTypePtr point; \
291  for (n = (int)((polygon)->PointN) - 1; n != -1; n--) \
292  { \
293  point = &(polygon)->Points[n]
294 
298 #define VIA_LP(top) do { \
299  GList *__iter, *__next; \
300  Cardinal n = 0; \
301  for (__iter = (top)->Via, __next = g_list_next (__iter); \
302  __iter != NULL; \
303  __iter = __next, __next = g_list_next (__iter), n++) { \
304  PinType *via = (PinType *)__iter->data;
305 
309 #define LINE_LP(layer) do { \
310  GList *__iter, *__next; \
311  Cardinal n = 0; \
312  for (__iter = (layer)->Line, __next = g_list_next (__iter); \
313  __iter != NULL; \
314  __iter = __next, __next = g_list_next (__iter), n++) { \
315  LineType *line = (LineType *)__iter->data;
316 
320 #define ELEMENT_LP(top) do { \
321  GList *__iter, *__next; \
322  Cardinal n = 0; \
323  for (__iter = (top)->Element, __next = g_list_next (__iter); \
324  __iter != NULL; \
325  __iter = __next, __next = g_list_next (__iter), n++) { \
326  ElementType *element = (ElementType *)__iter->data;
327 
331 #define PAD_LP(element) do { \
332  GList *__iter, *__next; \
333  Cardinal n = 0; \
334  for (__iter = (element)->Pad, __next = g_list_next (__iter); \
335  __iter != NULL; \
336  __iter = __next, __next = g_list_next (__iter), n++) { \
337  PadType *pad = (PadType *)__iter->data;
338 
342 #define PIN_LP(element) do { \
343  GList *__iter, *__next; \
344  Cardinal n = 0; \
345  for (__iter = (element)->Pin, __next = g_list_next (__iter); \
346  __iter != NULL; \
347  __iter = __next, __next = g_list_next (__iter), n++) { \
348  PinType *pin = (PinType *)__iter->data;
349 
350 #endif /* STIPPLE_HPP_ */
351 
354 {
355  public:
356 
359 
362 
367 };
368 
371 
372 private:
373 
375  long ReadDefault(string File, string Key, Coord Default);
376 
378  bool ReadDefaults();
379 
380 public:
381 
383  static void ButtonPress( GtkButton *widget, gpointer data );
384 
386  static void KeyPress( GtkButton *widget, gpointer data );
387 
389  static gboolean UpdateProgress(GtkProgressBar *PB);
390 
392  static void Progress(float progress, string Message);
393 
395  static int PercentFill(double Trace, double Pitch);
396 
398  void ParameterDialog();
399 
400 };
401 
403 class Layer
404 {
405 
406 protected:
407 
409  double Angle2D(
410  int X0, int Y0,
411  int X1, int Y1);
412 
415  LayerTypePtr FindLayerByName(string Name);
416 
418  b_polygon MakeCircularOverlay(
419  Coord x, Coord y, Coord Radius, int SegmentCount = 24);
420 
422  b_polygon MakeRectangularOverlay(
423  Coord x0, Coord y0, Coord x1, Coord y1, Coord Thickness);
424 
427  b_polygon MakeRoundedRectangle(
428  int x0, int y0, int x1, int y1, int Radius, int Smoothness);
429 
431  b_polygon_set ReadTemplatePolygons(LayerTypePtr layer);
432 
435  b_polygon_set LoadPCB(string LayerName, Coord Trace);
436 
445  vector<StippledPolygon> CalculateStipples(
446  LayerTypePtr layer, b_polygon_set Union,
447  Coord Trace, Coord Pitch, int i);
448 
451  void InsertToPCB(
452  LayerTypePtr layer, vector<StippledPolygon> StippledPolygons);
453 
454 public:
455 
459  void MakeLayer(int i);
460 };
461 
462 
Worker thread for a single layer's stipple processing.
Definition: stipple.hpp:403
const Coord MilToNanometer
Unit translation: 1 mil (1/1000 of an inch) = 254 nanometers.
Definition: stipple.hpp:232
b_polygon_set Overlays
Overlays are solid shadows for lines, vias and pads which from (with clearance) featured borders with...
Definition: stipple.hpp:366
MakeLayers_t MakeLayers
The checkbox translation of the work order.
Definition: stipple.cpp:32
gtl::polygon_with_holes_data< int > b_polygon
A shorthand for a set of coordinates from a boost polygon.
Definition: stipple.hpp:202
Coord ComponentPitch
The pitch size (spacing) to be used on the component layer.
Definition: stipple.cpp:31
b_polygon Outline
Store the perimeter of a stippled region.
Definition: stipple.hpp:358
Coord SolderPitch
The pitch size (spacing) to be used on the solder layer.
Definition: stipple.cpp:31
std::vector< b_polygon > b_polygon_set
A shorthand for a boost collection of polygons.
Definition: stipple.hpp:211
void LayerFactory(int i)
Since Gnome threads can not use a C++ decorated function as an entry point, this serves as a thunk to...
Definition: glue.cpp:66
const string component_stipple
the PCB name of the component stipple layer.
Definition: stipple.hpp:220
bool Cancel
The dialog box is on its own thread, so a cancel request is signaled by setting this variable...
Definition: dialog.cpp:30
Coord ComponentTrace
The size trace to be used in stipples on the component layer.
Definition: stipple.cpp:31
b_polygon_set CutOuts
Cutouts are the holes in the regions.
Definition: stipple.hpp:361
const string component_perimeter
the PCB name of the component perimeter layer.
Definition: stipple.hpp:217
The main user interface.
Definition: stipple.hpp:370
const string solder_stipple
the PCB name of the solder stipple layer.
Definition: stipple.hpp:226
Coord SolderTrace
The size trace to be used in stipples on the solder layer.
Definition: stipple.cpp:31
const double NanometerToMil
Unit translation: 1 nanometer = .00003... mills.
Definition: stipple.hpp:229
void Log(const char *format,...)
A simple log print to stout.
Definition: glue.cpp:54
A single boost polygon with all of it's cutouts.
Definition: stipple.hpp:353
MakeLayers_t
These correspond to the work order filled in by the operator in the dialog.
Definition: stipple.hpp:249
const string solder_perimeter
the PCB name of the sodler perimeter layer.
Definition: stipple.hpp:223
gtl::polygon_traits< b_polygon >::point_type b_point
A shorthand for boost points (coordinates).
Definition: stipple.hpp:205
vector< string > MakeLayerNames
A list of layer names to be stippled.
Definition: stipple.cpp:33
const double PI
Used for rounding edges and drawing approximate circles.
Definition: stipple.hpp:214
gtl::polygon_with_holes_traits< b_polygon >::hole_type b_hole
A shorthand for the boost polygon holes.
Definition: stipple.hpp:208
#define LayerTypePtr
Shorthand for a PCB Layer.
Definition: stipple.hpp:187
void ParameterDialog()
The user interface.
void MakeAllLayers()
Since the dialog runs on the PCB GUI thread, a new spool thread is used to delegate all of the worker...
Definition: glue.cpp:72