You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

378 lines
16 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2010-2013 Jean-Pierre Charras jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2013 KiCad Developers, see change_log.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (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, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #ifndef _CLASS_GERBER_H_
  25. #define _CLASS_GERBER_H_
  26. #include <vector>
  27. #include <set>
  28. #include <dcode.h>
  29. #include <class_gerber_draw_item.h>
  30. #include <class_aperture_macro.h>
  31. // An useful macro used when reading gerber files;
  32. #define IsNumber( x ) ( ( ( (x) >= '0' ) && ( (x) <='9' ) ) \
  33. || ( (x) == '-' ) || ( (x) == '+' ) || ( (x) == '.' ) )
  34. class GERBVIEW_FRAME;
  35. class D_CODE;
  36. /* gerber files have different parameters to define units and how items must be plotted.
  37. * some are for the entire file, and other can change along a file.
  38. * In Gerber world:
  39. * an image is the entire gerber file and its "global" parameters
  40. * a layer (that is very different from a board layer) is just a sub set of a file that
  41. * have specific parameters
  42. * if a Image parameter is set more than once, only the last value is used
  43. * Some parameters can change along a file and are not layer specific: they are stored
  44. * in GERBER_ITEM items, when instancied.
  45. *
  46. * In GerbView, to handle these parameters, there are 2 classes:
  47. * GERBER_IMAGE : the main class containing most of parameters and data to plot a graphic layer
  48. * Some of them can change along the file
  49. * There is one GERBER_IMAGE per file and one graphic layer per file or GERBER_IMAGE
  50. * GerbView does not read and merge 2 gerber file in one graphic layer:
  51. * I believe this is not possible due to the constraints in Image parameters.
  52. * GERBER_LAYER : containing the subset of parameters that is layer speficic
  53. * A GERBER_IMAGE must include one GERBER_LAYER to define all parameters to plot a file.
  54. * But a GERBER_IMAGE can use more than one GERBER_LAYER.
  55. */
  56. class GERBER_IMAGE;
  57. class X2_ATTRIBUTE_FILEFUNCTION;
  58. class GERBER_LAYER
  59. {
  60. friend class GERBER_IMAGE;
  61. public:
  62. // These parameters are layer specfic:
  63. wxString m_LayerName; // Layer name, from LN <name>* command
  64. bool m_LayerNegative; // true = Negative Layer: command LP
  65. wxRealPoint m_StepForRepeat; // X and Y offsets for Step and Repeat command
  66. int m_XRepeatCount; // The repeat count on X axis
  67. int m_YRepeatCount; // The repeat count on Y axis
  68. bool m_StepForRepeatMetric; // false = Inches, true = metric
  69. // needed here because repeated
  70. // gerber items can have coordinates
  71. // in different units than step parameters
  72. // and the actual coordinates calculation must handle this
  73. public:
  74. GERBER_LAYER();
  75. ~GERBER_LAYER();
  76. private:
  77. void ResetDefaultValues();
  78. };
  79. /**
  80. * Class GERBER_IMAGE
  81. * holds the Image data and parameters for one gerber file
  82. * and layer parameters (TODO: move them in GERBER_LAYER class
  83. */
  84. class GERBER_IMAGE
  85. {
  86. GERBVIEW_FRAME* m_Parent; // the parent GERBVIEW_FRAME (used to display messages...)
  87. D_CODE* m_Aperture_List[TOOLS_MAX_COUNT]; ///< Dcode (Aperture) List for this layer (max 999)
  88. bool m_Exposure; ///< whether an aperture macro tool is flashed on or off
  89. GERBER_LAYER m_GBRLayerParams; // hold params for the current gerber layer
  90. public:
  91. bool m_InUse; // true if this image is currently in use
  92. // (a file is loaded in it)
  93. wxString m_FileName; // Full File Name for this layer
  94. wxString m_ImageName; // Image name, from IN <name>* command
  95. bool m_IsX2_file; // true if a X2 gerber attribute was found in file
  96. X2_ATTRIBUTE_FILEFUNCTION* m_FileFunction; // file function parameters, found in a %TF command
  97. // or a G04
  98. wxString m_MD5_value; // MD5 value found in a %TF.MD5 command
  99. wxString m_PartString; // string found in a %TF.Part command
  100. int m_GraphicLayer; // Graphic layer Number
  101. bool m_ImageNegative; // true = Negative image
  102. bool m_ImageJustifyXCenter; // Image Justify Center on X axis (default = false)
  103. bool m_ImageJustifyYCenter; // Image Justify Center on Y axis (default = false)
  104. wxPoint m_ImageJustifyOffset; // Image Justify Offset on XY axis (default = 0,0)
  105. bool m_GerbMetric; // false = Inches, true = metric
  106. bool m_Relative; // false = absolute Coord, true = relative Coord
  107. bool m_NoTrailingZeros; // true: remove tailing zeros.
  108. bool m_DecimalFormat; // true: use floating point notations for coordinates
  109. // If true, overrides m_NoTrailingZeros parameter.
  110. wxPoint m_ImageOffset; // Coord Offset, from IO command
  111. wxSize m_FmtScale; // Fmt 2.3: m_FmtScale = 3, fmt 3.4: m_FmtScale = 4
  112. wxSize m_FmtLen; // Nb chars per coord. ex fmt 2.3, m_FmtLen = 5
  113. int m_ImageRotation; // Image rotation (0, 90, 180, 270 only) in degrees
  114. double m_LocalRotation; // Local rotation, in degrees, added to m_ImageRotation
  115. // Note this value is stored in 0.1 degrees
  116. wxPoint m_Offset; // Coord Offset, from OF command
  117. wxRealPoint m_Scale; // scale (X and Y) of layer.
  118. bool m_SwapAxis; // false (default) if A = X and B = Y
  119. // true if A = Y, B = X
  120. bool m_MirrorA; // true: miror / axe A (X)
  121. bool m_MirrorB; // true: miror / axe B (Y)
  122. int m_Iterpolation; // Linear, 90 arc, Circ.
  123. int m_Current_Tool; // Current Tool (Dcode) number selected
  124. int m_Last_Pen_Command; // Current or last pen state (0..9, set by Dn option with n <10
  125. int m_CommandState; // state of gerber analysis command.
  126. wxPoint m_CurrentPos; // current specified coord for plot
  127. wxPoint m_PreviousPos; // old current specified coord for plot
  128. wxPoint m_IJPos; // IJ coord (for arcs & circles )
  129. FILE* m_Current_File; // Current file to read
  130. #define INCLUDE_FILES_CNT_MAX 10
  131. FILE* m_FilesList[INCLUDE_FILES_CNT_MAX + 2]; // Included files list
  132. int m_FilesPtr; // Stack pointer for files list
  133. int m_Selected_Tool; // For hightlight: current selected Dcode
  134. bool m_Has_DCode; // true = DCodes in file
  135. // (false = no DCode -> separate DCode file
  136. bool m_360Arc_enbl; // Enbl 360 deg circular interpolation
  137. bool m_PolygonFillMode; // Enable polygon mode (read coord as a polygon descr)
  138. int m_PolygonFillModeState; // In polygon mode: 0 = first segm, 1 = next segm
  139. APERTURE_MACRO_SET m_aperture_macros; ///< a collection of APERTURE_MACROS, sorted by name
  140. private:
  141. int m_hasNegativeItems; // true if the image is negative or has some negative items
  142. // Used to optimize drawing, because when there are no
  143. // negative items screen refresh does not need
  144. // to build an intermediate bitmap specfic to this image
  145. // -1 = negative items are
  146. // 0 = no negative items found
  147. // 1 = have negative items found
  148. public:
  149. GERBER_IMAGE( GERBVIEW_FRAME* aParent, int layer );
  150. virtual ~GERBER_IMAGE();
  151. void Clear_GERBER_IMAGE();
  152. int UsedDcodeNumber();
  153. virtual void ResetDefaultValues();
  154. /**
  155. * Function GetParent
  156. * @return the GERBVIEW_FRAME parent of this GERBER_IMAGE
  157. */
  158. GERBVIEW_FRAME* GetParent() const
  159. {
  160. return m_Parent;
  161. }
  162. /**
  163. * Function GetItemsList
  164. * @return the first GERBER_DRAW_ITEM * item of the items list
  165. */
  166. GERBER_DRAW_ITEM * GetItemsList();
  167. /**
  168. * Function GetLayerParams
  169. * @return the current layers params
  170. */
  171. GERBER_LAYER& GetLayerParams()
  172. {
  173. return m_GBRLayerParams;
  174. }
  175. /**
  176. * Function HasNegativeItems
  177. * @return true if at least one item must be drawn in background color
  178. * used to optimize screen refresh (when no items are in background color
  179. * refresh can be faster)
  180. */
  181. bool HasNegativeItems();
  182. /**
  183. * Function ReportMessage
  184. * Add a message (a string) in message list
  185. * for instance when reading a Gerber file
  186. * @param aMessage = the straing to add in list
  187. */
  188. void ReportMessage( const wxString aMessage );
  189. /**
  190. * Function ClearMessageList
  191. * Clear the message list
  192. * Call it before reading a Gerber file
  193. */
  194. void ClearMessageList();
  195. /**
  196. * Function InitToolTable
  197. */
  198. void InitToolTable();
  199. /**
  200. * Function ReadXYCoord
  201. * Returns the current coordinate type pointed to by XnnYnn Text (XnnnnYmmmm)
  202. */
  203. wxPoint ReadXYCoord( char*& Text );
  204. /**
  205. * Function ReadIJCoord
  206. * Returns the current coordinate type pointed to by InnJnn Text (InnnnJmmmm)
  207. * These coordinates are relative, so if coordinate is absent, it's value
  208. * defaults to 0
  209. */
  210. wxPoint ReadIJCoord( char*& Text );
  211. // functions to read G commands or D commands:
  212. int GCodeNumber( char*& Text );
  213. int DCodeNumber( char*& Text );
  214. // functions to execute G commands or D commands:
  215. bool Execute_G_Command( char*& text, int G_command );
  216. bool Execute_DCODE_Command( char*& text, int D_command );
  217. /**
  218. * Function ReadRS274XCommand
  219. * reads a single RS274X command terminated with a %
  220. */
  221. bool ReadRS274XCommand( char aBuff[GERBER_BUFZ], char* & text );
  222. /**
  223. * Function ExecuteRS274XCommand
  224. * executes 1 command
  225. */
  226. bool ExecuteRS274XCommand( int command, char aBuff[GERBER_BUFZ],
  227. char* & text );
  228. /**
  229. * Function ReadApertureMacro
  230. * reads in an aperture macro and saves it in m_aperture_macros.
  231. * @param aBuff a character buffer at least GERBER_BUFZ long that can be
  232. * used to read successive lines from the gerber file.
  233. * @param text A reference to a character pointer which gives the initial
  234. * text to read from.
  235. * @param gerber_file Which file to read from for continuation.
  236. * @return bool - true if a macro was read in successfully, else false.
  237. */
  238. bool ReadApertureMacro( char aBuff[GERBER_BUFZ], char* & text,
  239. FILE * gerber_file );
  240. /**
  241. * Function GetDCODE
  242. * returns a pointer to the D_CODE within this GERBER for the given
  243. * \a aDCODE.
  244. * @param aDCODE The numeric value of the D_CODE to look up.
  245. * @param createIfNoExist If true, then create the D_CODE if it does not
  246. * exist.
  247. * @return D_CODE* - the one implied by the given \a aDCODE, or NULL
  248. * if the requested \a aDCODE is out of range.
  249. */
  250. D_CODE* GetDCODE( int aDCODE, bool createIfNoExist = true );
  251. /**
  252. * Function FindApertureMacro
  253. * looks up a previously read in aperture macro.
  254. * @param aLookup A dummy APERTURE_MACRO with [only] the name field set.
  255. * @return APERTURE_MACRO* - the one with a matching name, or NULL if
  256. * not found.
  257. */
  258. APERTURE_MACRO* FindApertureMacro( const APERTURE_MACRO& aLookup );
  259. /**
  260. * Function StepAndRepeatItem
  261. * Gerber format has a command Step an Repeat
  262. * This function must be called when reading a gerber file and
  263. * after creating a new gerber item that must be repeated
  264. * (i.e when m_XRepeatCount or m_YRepeatCount are > 1)
  265. * @param aItem = the item to repeat
  266. */
  267. void StepAndRepeatItem( const GERBER_DRAW_ITEM& aItem );
  268. /**
  269. * Function DisplayImageInfo
  270. * has knowledge about the frame and how and where to put status information
  271. * about this object into the frame's message panel.
  272. * Display info about Image Parameters.
  273. */
  274. void DisplayImageInfo( void );
  275. };
  276. /**
  277. * @brief GERBER_IMAGE_LIST is a helper class to handle a list of GERBER_IMAGE files
  278. * which are loaded and can be displayed
  279. * there are 32 images max which can be loaded
  280. */
  281. class GERBER_IMAGE_LIST
  282. {
  283. // the list of loaded images (1 image = 1 gerber file)
  284. std::vector<GERBER_IMAGE*> m_GERBER_List;
  285. public:
  286. GERBER_IMAGE_LIST();
  287. ~GERBER_IMAGE_LIST();
  288. //Accessor
  289. GERBER_IMAGE* GetGbrImage( int aIdx );
  290. /**
  291. * Add a GERBER_IMAGE* at index aIdx
  292. * or at the first free location if aIdx < 0
  293. * @param aGbrImage = the image to add
  294. * @param aIdx = the location to use ( 0 ... GERBER_DRAWLAYERS_COUNT-1 )
  295. * @return true if the index used, or -1 if no room to add image
  296. */
  297. int AddGbrImage( GERBER_IMAGE* aGbrImage, int aIdx );
  298. /**
  299. * remove all loaded data in list
  300. */
  301. void ClearList();
  302. /**
  303. * remove the loaded data of image aIdx
  304. * @param aIdx = the index ( 0 ... GERBER_DRAWLAYERS_COUNT-1 )
  305. */
  306. void ClearImage( int aIdx );
  307. /**
  308. * @return a name for image aIdx which can be used in layers manager
  309. * and layer selector
  310. * is is "Layer n" (n = aIdx+1), followed by file attribute info (if X2 format)
  311. * @param aIdx = the index ( 0 ... GERBER_DRAWLAYERS_COUNT-1 )
  312. */
  313. const wxString GetDisplayName( int aIdx );
  314. /**
  315. * @return true if image is used (loaded and with items)
  316. * @param aIdx = the index ( 0 ... GERBER_DRAWLAYERS_COUNT-1 )
  317. */
  318. bool IsUsed( int aIdx );
  319. /**
  320. * Sort loaded images by Z order priority, if they have the X2 FileFormat info
  321. * @param aDrawList: the draw list associated to the gerber images
  322. * (SortImagesByZOrder updates the graphic layer of these items)
  323. */
  324. void SortImagesByZOrder( GERBER_DRAW_ITEM* aDrawList );
  325. };
  326. extern GERBER_IMAGE_LIST g_GERBER_List;
  327. #endif // ifndef _CLASS_GERBER_H_