KiCad PCB EDA Suite
base_screen.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) 2015 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
31 #ifndef BASE_SCREEN_H
32 #define BASE_SCREEN_H
33 
34 #include <eda_draw_frame.h>
35 #include <base_struct.h>
36 #include <undo_redo_container.h>
37 #include <common.h>
38 
43 class GRID_TYPE
44 {
45 public:
46  int m_CmdId; // The command id of this grid ( first id is ID_POPUP_GRID_LEVEL_1000 )
47  wxRealPoint m_Size; // the size in internal unit of the grid (can differ for X and Y axis)
48 
49  GRID_TYPE& operator=( const GRID_TYPE& item )
50  {
51  if( this != &item )
52  {
53  m_CmdId = item.m_CmdId;
54  m_Size = item.m_Size;
55  }
56 
57  return *this;
58  }
59 
60  const bool operator==( const GRID_TYPE& item ) const
61  {
62  return m_Size == item.m_Size && m_CmdId == item.m_CmdId;
63  }
64 };
65 
66 
67 typedef std::vector<GRID_TYPE> GRIDS;
68 
69 
74 class BASE_SCREEN : public EDA_ITEM
75 {
76 private:
78  bool m_FlagSave;
80 
87 
90  double m_Zoom;
91 
92  //----< Old public API now is private, and migratory>------------------------
93  // called only from EDA_DRAW_FRAME
94  friend class EDA_DRAW_FRAME;
95 
103  wxPoint getNearestGridPosition( const wxPoint& aPosition, const wxPoint& aGridOrigin ) const;
104 
105  //----</Old public API now is private, and migratory>------------------------
106 
107 
108 public:
109  static wxString m_PageLayoutDescrFileName;
110 
112  wxPoint m_DrawOrg;
113 
115 
117  wxPoint m_StartVisu;
121  bool m_Center;
128 
130 
131  // Undo/redo list of commands
134 
137 
138  std::vector<double> m_ZoomList;
140 
141 public:
142  BASE_SCREEN( KICAD_T aType = SCREEN_T );
143  ~BASE_SCREEN() override { }
144 
145  void InitDataPoints( const wxSize& aPageSizeInternalUnits );
146 
147  /* general Undo/Redo command control */
148 
161  virtual void ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount = -1 ) = 0;
162 
169  virtual void ClearUndoRedoList();
170 
178  virtual void PushCommandToUndoList( PICKED_ITEMS_LIST* aItem );
179 
187  virtual void PushCommandToRedoList( PICKED_ITEMS_LIST* aItem );
188 
194 
200 
202  {
203  return m_UndoList.m_CommandsList.size();
204  }
205 
207  {
208  return m_RedoList.m_CommandsList.size();
209  }
210 
211  int GetMaxUndoItems() const { return m_UndoRedoCountMax; }
212 
213  void SetMaxUndoItems( int aMax )
214  {
215  if( aMax >= 0 && aMax < ABS_MAX_UNDO_ITEMS )
216  m_UndoRedoCountMax = aMax;
217  else
218  {
219  wxFAIL_MSG( "Maximum undo items not within limits" );
221  }
222  }
223 
224  void SetModify() { m_FlagModified = true; }
225  void ClrModify() { m_FlagModified = false; }
226  void SetSave() { m_FlagSave = true; }
227  void ClrSave() { m_FlagSave = false; }
228  bool IsModify() const { return m_FlagModified; }
229  bool IsSave() const { return m_FlagSave; }
230 
231 
232  //----<zoom stuff>---------------------------------------------------------
233 
240  double GetZoom() const { return m_Zoom; }
241 
249  virtual bool SetZoom( double iu_per_du );
250 
256  double GetMaxAllowedZoom() const { return m_ZoomList.size() ? *m_ZoomList.rbegin() : 1.0; }
257 
263  double GetMinAllowedZoom() const { return m_ZoomList.size() ? *m_ZoomList.begin() : 1.0; }
264 
265  //----<grid stuff>----------------------------------------------------------
266 
272  int GetGridCmdId() const { return m_Grid.m_CmdId; }
273 
279  const wxRealPoint& GetGridSize() const { return m_Grid.m_Size; }
280 
286  const GRID_TYPE& GetGrid() const { return m_Grid; }
287 
296  int SetGrid( const wxRealPoint& size );
297 
305  int SetGrid( int aCommandId );
306 
307  void AddGrid( const GRID_TYPE& aGrid );
308  void AddGrid( const wxRealPoint& size, EDA_UNITS_T aUnit, int id );
309 
316  bool GridExists( int aCommandId );
317 
324  size_t GetGridCount() const { return m_grids.size(); }
325 
333  GRID_TYPE& GetGrid( size_t aIndex );
334 
339  const GRIDS& GetGrids() const
340  {
341  return m_grids;
342  }
343 
353  int BuildGridsChoiceList( wxArrayString& aGridsList, bool aMmFirst) const;
354 
355 
361  virtual wxString GetClass() const override
362  {
363  return wxT( "BASE_SCREEN" );
364  }
365 
366 #if defined(DEBUG)
367  void Show( int nestLevel, std::ostream& os ) const override;
368 #endif
369 };
370 
371 #endif // BASE_SCREEN_H
double GetMinAllowedZoom() const
Function GetMinAllowedZoom returns the minimum allowed zoom factor, which was established as the firs...
Definition: base_screen.h:263
virtual void PushCommandToUndoList(PICKED_ITEMS_LIST *aItem)
Function PushCommandToUndoList add a command to undo in undo list delete the very old commands when t...
const wxRealPoint & GetGridSize() const
Return the grid size of the currently selected grid.
Definition: base_screen.h:279
int m_UndoRedoCountMax
undo/Redo command Max depth
Definition: base_screen.h:79
int m_ScreenNumber
Definition: base_screen.h:135
bool m_FlagModified
Indicates current drawing has been modified.
Definition: base_screen.h:77
int BuildGridsChoiceList(wxArrayString &aGridsList, bool aMmFirst) const
Function BuildGridsChoiceList().
void SetSave()
Definition: base_screen.h:226
virtual wxString GetClass() const override
Function GetClass returns the class name.
Definition: base_screen.h:361
wxPoint m_crossHairPosition
The cross hair position in logical (drawing) units.
Definition: base_screen.h:86
double GetZoom() const
Function GetZoom returns the current "zoom factor", which is a measure of "internal units per device ...
Definition: base_screen.h:240
int GetMaxUndoItems() const
Definition: base_screen.h:211
void AddGrid(const GRID_TYPE &aGrid)
int GetUndoCommandCount() const
Definition: base_screen.h:201
GRID_TYPE m_Grid
Current grid selection.
Definition: base_screen.h:89
#define ABS_MAX_UNDO_ITEMS
const GRID_TYPE & GetGrid() const
Return the grid object of the currently selected grid.
Definition: base_screen.h:286
#define DEFAULT_MAX_UNDO_ITEMS
virtual void ClearUndoORRedoList(UNDO_REDO_CONTAINER &aList, int aItemCount=-1)=0
Function ClearUndoORRedoList (virtual).
The base class for create windows for drawing purpose.
const bool operator==(const GRID_TYPE &item) const
Definition: base_screen.h:60
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
not really an item, used to identify a screen
Definition: typeinfo.h:86
static wxString m_PageLayoutDescrFileName
the name of the page layout descr file, or emty to used the default pagelayout
Definition: base_screen.h:109
virtual PICKED_ITEMS_LIST * PopCommandFromUndoList()
PopCommandFromUndoList return the last command to undo and remove it from list nothing is deleted.
void InitDataPoints(const wxSize &aPageSizeInternalUnits)
Definition: base_screen.cpp:63
wxPoint m_StartVisu
Coordinates in drawing units of the current view position (upper left corner of device)
Definition: base_screen.h:117
Class UNDO_REDO_CONTAINER is a holder to handle alist of undo (or redo) command.
std::vector< GRID_TYPE > GRIDS
Definition: base_screen.h:67
std::vector< PICKED_ITEMS_LIST * > m_CommandsList
bool m_Center
Center on screen.
Definition: base_screen.h:121
UNDO_REDO_CONTAINER m_UndoList
Objects list for the undo command (old data)
Definition: base_screen.h:132
bool m_Initialized
Definition: base_screen.h:129
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:74
virtual PICKED_ITEMS_LIST * PopCommandFromRedoList()
PopCommandFromRedoList return the last command to undo and remove it from list nothing is deleted.
const GRIDS & GetGrids() const
Function GetGrids().
Definition: base_screen.h:339
virtual void ClearUndoRedoList()
Function ClearUndoRedoList clear undo and redo list, using ClearUndoORRedoList() picked items are del...
~BASE_SCREEN() override
Definition: base_screen.h:143
wxRealPoint m_Size
Definition: base_screen.h:47
bool IsModify() const
Definition: base_screen.h:228
virtual bool SetZoom(double iu_per_du)
Function SetZoom adjusts the current zoom factor.
Definition: base_screen.cpp:86
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
GRID_TYPE & operator=(const GRID_TYPE &item)
Definition: base_screen.h:49
bool m_IsPrinting
Definition: base_screen.h:139
UNDO_REDO_CONTAINER m_RedoList
Objects list for the redo command (old data)
Definition: base_screen.h:133
double GetMaxAllowedZoom() const
Function GetMaxAllowedZoom returns the maximum allowed zoom factor, which was established as the last...
Definition: base_screen.h:256
GRIDS m_grids
List of valid grid sizes.
Definition: base_screen.h:88
bool GridExists(int aCommandId)
Function GridExists tests for grid command ID (not an index in grid list, but a wxID) exists in grid ...
bool IsSave() const
Definition: base_screen.h:229
Class GRID_TYPE is for grid arrays.
Definition: base_screen.h:43
BASE_SCREEN(KICAD_T aType=SCREEN_T)
Definition: base_screen.cpp:45
size_t GetGridCount() const
Function GetGridCount().
Definition: base_screen.h:324
virtual void PushCommandToRedoList(PICKED_ITEMS_LIST *aItem)
Function PushCommandToRedoList add a command to redo in redo list delete the very old commands when t...
wxPoint m_DrawOrg
offsets for drawing the circuit on the screen
Definition: base_screen.h:112
void ClrModify()
Definition: base_screen.h:225
void SetMaxUndoItems(int aMax)
Definition: base_screen.h:213
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:150
The common library.
bool m_FlagSave
Indicates automatic file save.
Definition: base_screen.h:78
int m_NumberOfScreens
Definition: base_screen.h:136
wxPoint getNearestGridPosition(const wxPoint &aPosition, const wxPoint &aGridOrigin) const
Function getNearestGridPosition returns the nearest aGridSize location to aPosition.
double m_Zoom
Current zoom coefficient.
Definition: base_screen.h:90
VECTOR2D m_ScrollCenter
Current scroll center point in logical units.
Definition: base_screen.h:127
Basic classes for most KiCad items.
void SetModify()
Definition: base_screen.h:224
int SetGrid(const wxRealPoint &size)
set the current grid size m_Grid.
int m_CmdId
Definition: base_screen.h:46
int GetGridCmdId() const
Return the command ID of the currently selected grid.
Definition: base_screen.h:272
int GetRedoCommandCount() const
Definition: base_screen.h:206
void ClrSave()
Definition: base_screen.h:227
EDA_UNITS_T
Definition: common.h:157
std::vector< double > m_ZoomList
standard zoom (i.e. scale) coefficients.
Definition: base_screen.h:138
VECTOR2D m_LocalOrigin
Relative Screen cursor coordinate (on grid) in user units.
Definition: base_screen.h:114