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.

218 lines
8.1 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.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 WS_DATA_MODEL_H
  25. #define WS_DATA_MODEL_H
  26. #include <math/vector2d.h>
  27. #include <eda_text.h>
  28. #include <eda_text.h>
  29. #include <bitmap_base.h>
  30. #include <ws_data_item.h>
  31. /**
  32. * WS_DATA_MODEL handles the graphic items list to draw/plot the frame and title block
  33. */
  34. class WS_DATA_MODEL
  35. {
  36. std::vector <WS_DATA_ITEM*> m_list;
  37. bool m_allowVoidList; // If false, the default page layout will be loaded the
  38. // first time WS_DRAW_ITEM_LIST::BuildWorkSheetGraphicList
  39. // is run (useful mainly for page layout editor)
  40. double m_leftMargin; // the left page margin in mm
  41. double m_rightMargin; // the right page margin in mm
  42. double m_topMargin; // the top page margin in mm
  43. double m_bottomMargin; // the bottom page margin in mm
  44. public:
  45. double m_WSunits2Iu; // conversion factor between
  46. // ws units (mils) and draw/plot units
  47. DPOINT m_RB_Corner; // cordinates of the right bottom corner (in mm)
  48. DPOINT m_LT_Corner; // cordinates of the left top corner (in mm)
  49. double m_DefaultLineWidth; // Used when object line width is 0
  50. DSIZE m_DefaultTextSize; // Used when object text size is 0
  51. double m_DefaultTextThickness; // Used when object text stroke width is 0
  52. bool m_EditMode; // Used in page layout editor to toggle variable substution
  53. // In normal mode (m_EditMode = false) the %format is
  54. // replaced by the corresponding text.
  55. // In edit mode (m_EditMode = true) the %format is
  56. // displayed "as this"
  57. public:
  58. WS_DATA_MODEL();
  59. ~WS_DATA_MODEL()
  60. {
  61. ClearList();
  62. }
  63. /**
  64. * static function: returns the instance of WS_DATA_MODEL used in the application
  65. */
  66. static WS_DATA_MODEL& GetTheInstance();
  67. /**
  68. * static function: Set an alternate instance of WS_DATA_MODEL
  69. * mainly used in page setting dialog
  70. * @param aLayout = the alternate page layout; if null restore the basic page layout
  71. */
  72. static void SetAltInstance( WS_DATA_MODEL* aLayout = NULL );
  73. // Accessors:
  74. double GetLeftMargin() { return m_leftMargin; }
  75. void SetLeftMargin( double aMargin ) { m_leftMargin = aMargin; }
  76. double GetRightMargin() { return m_rightMargin; }
  77. void SetRightMargin( double aMargin ) { m_rightMargin = aMargin; }
  78. double GetTopMargin() { return m_topMargin; }
  79. void SetTopMargin( double aMargin ) { m_topMargin = aMargin; }
  80. double GetBottomMargin() { return m_bottomMargin; }
  81. void SetBottomMargin( double aMargin ) { m_bottomMargin = aMargin; }
  82. void SetupDrawEnvironment( const PAGE_INFO& aPageInfo, double aMilsToIU );
  83. /**
  84. * In Kicad applications, a page layout description is needed
  85. * So if the list is empty, a default description is loaded,
  86. * the first time a page layout is drawn.
  87. * However, in page layout editor, an empty list is acceptable.
  88. * AllowVoidList allows or not the empty list
  89. */
  90. void AllowVoidList( bool Allow ) { m_allowVoidList = Allow; }
  91. /**
  92. * @return true if an empty list is allowed
  93. * (mainly allowed for page layout editor).
  94. */
  95. bool VoidListAllowed() { return m_allowVoidList; }
  96. /**
  97. * erase the list of items
  98. */
  99. void ClearList();
  100. /**
  101. * Save the description in a file
  102. * @param aFullFileName the filename of the file to created
  103. */
  104. void Save( const wxString& aFullFileName );
  105. /**
  106. * Save the description in a buffer
  107. * @param aOutputString = a wxString to store the S expr string
  108. */
  109. void SaveInString( wxString& aOutputString );
  110. /**
  111. * Fill the given string with an S-expr serialization of the WS_DATA_ITEMs
  112. */
  113. void SaveInString( std::vector<WS_DATA_ITEM*> aItemsList, wxString& aOutputString );
  114. void Append( WS_DATA_ITEM* aItem );
  115. void Remove( WS_DATA_ITEM* aItem );
  116. /**
  117. * @return the index of aItem, or -1 if does not exist
  118. */
  119. int GetItemIndex( WS_DATA_ITEM* aItem ) const;
  120. /**
  121. * @return the item from its index aIdx, or NULL if does not exist
  122. */
  123. WS_DATA_ITEM* GetItem( unsigned aIdx ) const;
  124. /**
  125. * @return a reference to the items.
  126. */
  127. std::vector<WS_DATA_ITEM*>& GetItems() { return m_list; }
  128. /**
  129. * @return the item count
  130. */
  131. unsigned GetCount() const { return m_list.size(); }
  132. void SetDefaultLayout();
  133. void SetEmptyLayout();
  134. /**
  135. * Returns a string containing the empty layout shape
  136. */
  137. static wxString EmptyLayout();
  138. /**
  139. * Returns a string containing the empty layout shape
  140. */
  141. static wxString DefaultLayout();
  142. /**
  143. * Populates the list with a custom layout, or
  144. * the default layout, if no custom layout available
  145. * @param aFullFileName = the custom page layout description file.
  146. * if empty, loads the file defined by KICAD_WKSFILE
  147. * and if its is not defined, uses the default internal description
  148. * @param Append = if true: do not delete old layout, and load only
  149. aFullFileName.
  150. */
  151. void SetPageLayout( const wxString& aFullFileName = wxEmptyString, bool Append = false );
  152. /**
  153. * Populates the list from a S expr description stored in a string
  154. * @param aPageLayout = the S expr string
  155. * @param aAppend Do not delete old layout if true and append \a aPageLayout
  156. * the existing one.
  157. @param aSource is the layout source description.
  158. */
  159. void SetPageLayout( const char* aPageLayout, bool aAppend = false,
  160. const wxString& aSource = wxT( "Sexpr_string" ) );
  161. /**
  162. * @return a short filename from a full filename:
  163. * if the path is the current project path, or if the path
  164. * is the same as kicad.pro (in template), returns the shortname
  165. * else do nothing and returns a full filename
  166. * @param aFullFileName = the full filename, which can be a relative
  167. * @param aProjectPath = the curr project absolute path (can be empty)
  168. */
  169. static const wxString MakeShortFileName( const wxString& aFullFileName,
  170. const wxString& aProjectPath );
  171. /**
  172. * Static function
  173. * @return a full filename from a short filename.
  174. * @param aShortFileName = the short filename, which can be a relative
  175. * @param aProjectPath = the curr project absolute path (can be empty)
  176. * or absolute path, and can include env variable reference ( ${envvar} expression )
  177. * if the short filename path is relative, it is expected relative to the project path
  178. * or (if aProjectPath is empty or if the file does not exist)
  179. * relative to kicad.pro (in template)
  180. * If aShortFileName is absolute return aShortFileName
  181. */
  182. static const wxString MakeFullFileName( const wxString& aShortFileName,
  183. const wxString& aProjectPath );
  184. };
  185. #endif // WS_DATA_MODEL_H