KiCad PCB EDA Suite
ds_data_model.h
Go to the documentation of this file.
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-2021 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 
25 #ifndef DS_DATA_MODEL_H
26 #define DS_DATA_MODEL_H
27 
28 #include <math/vector2d.h>
29 #include <eda_text.h>
30 #include <bitmap_base.h>
31 
32 class DS_DATA_ITEM;
33 class PAGE_INFO;
34 
39 {
40 public:
41  DS_DATA_MODEL();
42 
44  {
45  ClearList();
46  }
47 
51  static DS_DATA_MODEL& GetTheInstance();
52 
58  static void SetAltInstance( DS_DATA_MODEL* aLayout = nullptr );
59 
61  void SetFileFormatVersionAtLoad( int aVersion ) { m_fileFormatVersionAtLoad = aVersion; }
62 
63  double GetLeftMargin() { return m_leftMargin; }
64  void SetLeftMargin( double aMargin ) { m_leftMargin = aMargin; }
65 
66  double GetRightMargin() { return m_rightMargin; }
67  void SetRightMargin( double aMargin ) { m_rightMargin = aMargin; }
68 
69  double GetTopMargin() { return m_topMargin; }
70  void SetTopMargin( double aMargin ) { m_topMargin = aMargin; }
71 
72  double GetBottomMargin() { return m_bottomMargin; }
73  void SetBottomMargin( double aMargin ) { m_bottomMargin = aMargin; }
74 
75  void SetupDrawEnvironment( const PAGE_INFO& aPageInfo, double aMilsToIU );
76 
83  void AllowVoidList( bool Allow ) { m_allowVoidList = Allow; }
84 
88  bool VoidListAllowed() { return m_allowVoidList; }
89 
93  void ClearList();
94 
100  void Save( const wxString& aFullFileName );
101 
107  void SaveInString( wxString* aOutputString );
108 
112  void SaveInString( std::vector<DS_DATA_ITEM*>& aItemsList, wxString* aOutputString );
113 
114  void Append( DS_DATA_ITEM* aItem );
115  void Remove( DS_DATA_ITEM* aItem );
116 
120  int GetItemIndex( DS_DATA_ITEM* aItem ) const;
121 
125  DS_DATA_ITEM* GetItem( unsigned aIdx ) const;
126 
130  std::vector<DS_DATA_ITEM*>& GetItems() { return m_list; }
131 
135  unsigned GetCount() const { return m_list.size(); }
136 
137  void SetDefaultLayout();
138  void SetEmptyLayout();
139 
143  static wxString EmptyLayout();
144 
148  static wxString DefaultLayout();
149 
159  bool LoadDrawingSheet( const wxString& aFullFileName = wxEmptyString, bool Append = false );
160 
169  void SetPageLayout( const char* aPageLayout, bool aAppend = false,
170  const wxString& aSource = wxT( "Sexpr_string" ) );
171 
175  static const wxString ResolvePath( const wxString& aPath, const wxString& aProjectPath );
176 
177  double m_WSunits2Iu; // conversion factor between
178  // ws units (mils) and draw/plot units
179  DPOINT m_RB_Corner; // coordinates of the right bottom corner (in mm)
180  DPOINT m_LT_Corner; // coordinates of the left top corner (in mm)
181  double m_DefaultLineWidth; // Used when object line width is 0
182  DSIZE m_DefaultTextSize; // Used when object text size is 0
183  double m_DefaultTextThickness; // Used when object text stroke width is 0
184  bool m_EditMode; // Used in drawing sheet editor to toggle variable substitution
185  // In normal mode (m_EditMode = false) the %format is
186  // replaced by the corresponding text.
187  // In edit mode (m_EditMode = true) the %format is
188  // displayed "as this"
189 
190 private:
191  std::vector <DS_DATA_ITEM*> m_list;
192  bool m_allowVoidList; // If false, the default drawing sheet will be loaded the
193  // first time DS_DRAW_ITEM_LIST::BuildDrawItemsList is run
194  // (useful mainly for drawing sheet editor)
196  double m_leftMargin; // the left page margin in mm
197  double m_rightMargin; // the right page margin in mm
198  double m_topMargin; // the top page margin in mm
199  double m_bottomMargin; // the bottom page margin in mm
200 };
201 
202 #endif // DS_DATA_MODEL_H
void ClearList()
Erase the list of items.
std::vector< DS_DATA_ITEM * > m_list
Handle the graphic items list to draw/plot the frame and title block.
Definition: ds_data_model.h:38
double GetRightMargin()
Definition: ds_data_model.h:66
static wxString DefaultLayout()
Return a string containing the empty layout shape.
void SetBottomMargin(double aMargin)
Definition: ds_data_model.h:73
double m_DefaultLineWidth
double GetTopMargin()
Definition: ds_data_model.h:69
void SetLeftMargin(double aMargin)
Definition: ds_data_model.h:64
std::vector< DS_DATA_ITEM * > & GetItems()
double GetLeftMargin()
Definition: ds_data_model.h:63
DPOINT m_RB_Corner
int m_fileFormatVersionAtLoad
void SetRightMargin(double aMargin)
Definition: ds_data_model.h:67
double m_topMargin
void Save(const wxString &aFullFileName)
Save the description in a file.
DPOINT m_LT_Corner
double m_DefaultTextThickness
int GetItemIndex(DS_DATA_ITEM *aItem) const
static const wxString ResolvePath(const wxString &aPath, const wxString &aProjectPath)
Resolve a path which might be project-relative or contain env variable references.
double m_bottomMargin
static DS_DATA_MODEL & GetTheInstance()
static function: returns the instance of DS_DATA_MODEL used in the application
DSIZE m_DefaultTextSize
void AllowVoidList(bool Allow)
In KiCad applications, a drawing sheet is needed So if the list is empty, a default drawing sheet is ...
Definition: ds_data_model.h:83
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:53
double GetBottomMargin()
Definition: ds_data_model.h:72
void SetTopMargin(double aMargin)
Definition: ds_data_model.h:70
double m_leftMargin
static wxString EmptyLayout()
Return a string containing the empty layout shape.
static void SetAltInstance(DS_DATA_MODEL *aLayout=nullptr)
Set an alternate instance of DS_DATA_MODEL.
double m_WSunits2Iu
double m_rightMargin
void SetFileFormatVersionAtLoad(int aVersion)
Definition: ds_data_model.h:61
void SetPageLayout(const char *aPageLayout, bool aAppend=false, const wxString &aSource=wxT("Sexpr_string"))
Populate the list from a S expr description stored in a string.
int GetFileFormatVersionAtLoad()
Definition: ds_data_model.h:60
DS_DATA_ITEM * GetItem(unsigned aIdx) const
Drawing sheet structure type definitions.
Definition: ds_data_item.h:95
void SetupDrawEnvironment(const PAGE_INFO &aPageInfo, double aMilsToIU)
bool LoadDrawingSheet(const wxString &aFullFileName=wxEmptyString, bool Append=false)
Populates the list with a custom layout or the default layout if no custom layout is available.
void SaveInString(wxString *aOutputString)
Save the description in a buffer.
unsigned GetCount() const
bool VoidListAllowed()
Definition: ds_data_model.h:88
void Remove(DS_DATA_ITEM *aItem)
void Append(DS_DATA_ITEM *aItem)