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 <draw_frame.h>
35 #include <base_struct.h>
36 #include <undo_redo_container.h>
37 #include <block_commande.h>
38 #include <common.h>
39 #include <id.h>
40 
45 class GRID_TYPE
46 {
47 public:
48  int m_CmdId; // The command id of this grid ( first id is ID_POPUP_GRID_LEVEL_1000 )
49  wxRealPoint m_Size; // the size in internal unit of the grid (can differ for X and Y axis)
50 
51  GRID_TYPE& operator=( const GRID_TYPE& item )
52  {
53  if( this != &item )
54  {
55  m_CmdId = item.m_CmdId;
56  m_Size = item.m_Size;
57  }
58 
59  return *this;
60  }
61 
62  const bool operator==( const GRID_TYPE& item ) const
63  {
64  return m_Size == item.m_Size && m_CmdId == item.m_CmdId;
65  }
66 };
67 
68 
69 typedef std::vector<GRID_TYPE> GRIDS;
70 
71 
76 class BASE_SCREEN : public EDA_ITEM
77 {
78 private:
81  bool m_FlagSave;
87 
94 
95  double m_Zoom;
96 
97  //----< Old public API now is private, and migratory>------------------------
98  // called only from EDA_DRAW_FRAME
99  friend class EDA_DRAW_FRAME;
100 
107  wxPoint getCrossHairPosition( bool aInvertY ) const
108  {
109  if( aInvertY )
110  return wxPoint( m_crossHairPosition.x, -m_crossHairPosition.y );
111 
112  return wxPoint( m_crossHairPosition.x, m_crossHairPosition.y );
113  }
114 
124  void setCrossHairPosition( const wxPoint& aPosition, const wxPoint& aGridOrigin, bool aSnapToGrid );
125 
131  wxPoint getCrossHairScreenPosition() const;
132 
142  wxPoint getNearestGridPosition( const wxPoint& aPosition, const wxPoint& aGridOrigin,
143  wxRealPoint* aGridSize ) const;
144 
154  wxPoint getCursorPosition( bool aOnGrid, const wxPoint& aGridOrigin, wxRealPoint* aGridSize ) const;
155 
156  void setMousePosition( const wxPoint& aPosition ) { m_MousePosition = aPosition; }
157 
168  wxPoint refPos( bool useMouse ) const
169  {
170  return useMouse ? m_MousePosition : m_crossHairPosition;
171  }
172 
173  const wxPoint& getScrollCenterPosition() const { return m_scrollCenter; }
174  void setScrollCenterPosition( const wxPoint& aPoint ) { m_scrollCenter = aPoint; }
175 
176  //----</Old public API now is private, and migratory>------------------------
177 
178 
179 public:
180  static wxString m_PageLayoutDescrFileName;
181 
184 
186 
188  // Scrollbars management:
191 
197 
202  bool m_Center;
208 
209  // Undo/redo list of commands
212 
213  // block control
215 
218 
219  std::vector<double> m_ZoomList;
221 
222 public:
223  BASE_SCREEN( KICAD_T aType = SCREEN_T );
224  ~BASE_SCREEN();
225 
231  void SetCurItem( EDA_ITEM* aItem ) { m_CurrentItem = aItem; }
232 
233  EDA_ITEM* GetCurItem() const { return m_CurrentItem; }
234 
235  void InitDataPoints( const wxSize& aPageSizeInternalUnits );
236 
245  virtual int MilsToIuScalar() { return 1; }
246 
247  /* general Undo/Redo command control */
248 
261  virtual void ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount = -1 ) = 0;
262 
269  virtual void ClearUndoRedoList();
270 
278  virtual void PushCommandToUndoList( PICKED_ITEMS_LIST* aItem );
279 
287  virtual void PushCommandToRedoList( PICKED_ITEMS_LIST* aItem );
288 
293  virtual PICKED_ITEMS_LIST* PopCommandFromUndoList();
294 
299  virtual PICKED_ITEMS_LIST* PopCommandFromRedoList();
300 
302  {
303  return m_UndoList.m_CommandsList.size();
304  }
305 
307  {
308  return m_RedoList.m_CommandsList.size();
309  }
310 
311  int GetMaxUndoItems() const { return m_UndoRedoCountMax; }
312 
313  void SetMaxUndoItems( int aMax )
314  {
315  if( aMax >= 0 && aMax < ABS_MAX_UNDO_ITEMS )
316  m_UndoRedoCountMax = aMax;
317  else
318  {
319  wxFAIL_MSG( "Maximum undo items not within limits" );
320  m_UndoRedoCountMax = DEFAULT_MAX_UNDO_ITEMS;
321  }
322  }
323 
324  void SetModify() { m_FlagModified = true; }
325  void ClrModify() { m_FlagModified = false; }
326  void SetSave() { m_FlagSave = true; }
327  void ClrSave() { m_FlagSave = false; }
328  bool IsModify() const { return m_FlagModified; }
329  bool IsSave() const { return m_FlagSave; }
330 
331 
332  //----<zoom stuff>---------------------------------------------------------
333 
340  double GetZoom() const { return m_Zoom; }
341 
349  virtual bool SetZoom( double iu_per_du );
350 
351  bool SetNextZoom();
352  bool SetPreviousZoom();
353  bool SetFirstZoom();
354  bool SetLastZoom();
355 
361  double GetMaxAllowedZoom() const { return m_ZoomList.size() ? *m_ZoomList.rbegin() : 1.0; }
362 
368  double GetMinAllowedZoom() const { return m_ZoomList.size() ? *m_ZoomList.begin() : 1.0; }
369 
383  void SetScalingFactor( double iu_per_du );
384 
393  double GetScalingFactor() const;
394 
395 
396  //----<grid stuff>----------------------------------------------------------
397 
403  int GetGridCmdId() const { return m_Grid.m_CmdId; }
404 
410  const wxRealPoint& GetGridSize() const { return m_Grid.m_Size; }
411 
417  const GRID_TYPE& GetGrid() const { return m_Grid; }
418 
427  int SetGrid( const wxRealPoint& size );
428 
436  int SetGrid( int aCommandId );
437 
438  void SetGridList( GRIDS& sizelist );
439  void AddGrid( const GRID_TYPE& grid );
440  void AddGrid( const wxRealPoint& size, int id );
441  void AddGrid( const wxRealPoint& size, EDA_UNITS_T aUnit, int id );
442 
449  bool GridExists( int aCommandId );
450 
457  size_t GetGridCount() const { return m_grids.size(); }
458 
466  GRID_TYPE& GetGrid( size_t aIndex );
467 
472  const GRIDS& GetGrids() const
473  {
474  return m_grids;
475  }
476 
486  int BuildGridsChoiceList( wxArrayString& aGridsList, bool aMmFirst) const;
487 
488 
494  virtual wxString GetClass() const override
495  {
496  return wxT( "BASE_SCREEN" );
497  }
498 
499  inline bool IsBlockActive() const { return !m_BlockLocate.IsIdle(); }
500 
501  void ClearBlockCommand() { m_BlockLocate.Clear(); }
502 
503 #if defined(DEBUG)
504  void Show( int nestLevel, std::ostream& os ) const override;
505 #endif
506 };
507 
508 #endif // BASE_SCREEN_H
void SetCurItem(EDA_ITEM *aItem)
Function SetCurItem sets the currently selected object, m_CurrentItem.
Definition: base_screen.h:231
int m_UndoRedoCountMax
undo/Redo command Max depth
Definition: base_screen.h:86
int m_ScreenNumber
Definition: base_screen.h:216
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
Definition: base_screen.h:214
EDA_ITEM * m_CurrentItem
Currently selected object.
Definition: base_screen.h:82
wxSize m_ScrollbarNumber
Current virtual draw area size in scroll units.
Definition: base_screen.h:192
bool m_FlagModified
Indicates current drawing has been modified.
Definition: base_screen.h:80
int m_ScrollPixelsPerUnitY
Pixels per scroll unit in the vertical direction.
Definition: base_screen.h:190
void setScrollCenterPosition(const wxPoint &aPoint)
Definition: base_screen.h:174
EDA_ITEM * GetCurItem() const
Definition: base_screen.h:233
void SetSave()
Definition: base_screen.h:326
virtual wxString GetClass() const override
Function GetClass returns the class name.
Definition: base_screen.h:494
wxPoint m_crossHairPosition
The cross hair position in logical (drawing) units.
Definition: base_screen.h:93
#define DEFAULT_MAX_UNDO_ITEMS
Definition: draw_frame.h:47
int GetGridCmdId() const
Return the command ID of the currently selected grid.
Definition: base_screen.h:403
double GetZoom() const
Function GetZoom returns the current "zoom factor", which is a measure of "internal units per device ...
Definition: base_screen.h:340
GRID_TYPE m_Grid
Current grid selection.
Definition: base_screen.h:83
const GRIDS & GetGrids() const
Function GetGrids().
Definition: base_screen.h:472
bool IsModify() const
Definition: base_screen.h:328
void ClearBlockCommand()
Definition: base_screen.h:501
The base class for create windows for drawing purpose.
Definition: draw_frame.h:78
wxPoint m_scrollCenter
Current scroll center point in logical units.
Definition: base_screen.h:84
wxPoint m_O_Curseur
Relative Screen cursor coordinate (on grid) in user units.
Definition: base_screen.h:185
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
int GetMaxUndoItems() const
Definition: base_screen.h:311
wxPoint refPos(bool useMouse) const
Function RefPos Return the reference position, coming from either the mouse position or the cursor po...
Definition: base_screen.h:168
not really an item, used to identify a screen
Definition: typeinfo.h:86
size_t GetGridCount() const
Function GetGridCount().
Definition: base_screen.h:457
double GetMinAllowedZoom() const
Function GetMinAllowedZoom returns the minimum allowed zoom factor, which was established as the firs...
Definition: base_screen.h:368
static wxString m_PageLayoutDescrFileName
the name of the page layout descr file, or emty to used the default pagelayout
Definition: base_screen.h:180
int GetUndoCommandCount() const
Definition: base_screen.h:301
wxPoint m_StartVisu
Coordinates in drawing units of the current view position (upper left corner of device) ...
Definition: base_screen.h:198
Class UNDO_REDO_CONTAINER is a holder to handle alist of undo (or redo) command.
bool IsBlockActive() const
Definition: base_screen.h:499
#define ABS_MAX_UNDO_ITEMS
Definition: draw_frame.h:48
wxPoint getCrossHairPosition(bool aInvertY) const
Function getCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
Definition: base_screen.h:107
std::vector< GRID_TYPE > GRIDS
Definition: base_screen.h:69
const GRID_TYPE & GetGrid() const
Return the grid object of the currently selected grid.
Definition: base_screen.h:417
std::vector< PICKED_ITEMS_LIST * > m_CommandsList
bool m_Center
Center on screen.
Definition: base_screen.h:202
UNDO_REDO_CONTAINER m_UndoList
Objects list for the undo command (old data)
Definition: base_screen.h:210
bool m_Initialized
Definition: base_screen.h:207
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:76
const bool operator==(const GRID_TYPE &item) const
Definition: base_screen.h:62
int m_ScrollPixelsPerUnitX
Pixels per scroll unit in the horizontal direction.
Definition: base_screen.h:189
wxRealPoint m_Size
Definition: base_screen.h:49
void setMousePosition(const wxPoint &aPosition)
Definition: base_screen.h:156
virtual int MilsToIuScalar()
Function MilsToIuScalar returns the scalar required to convert mils to internal units.
Definition: base_screen.h:245
const wxPoint & getScrollCenterPosition() const
Definition: base_screen.h:173
int m_UndoRedoCountMax
default Undo/Redo command Max depth, to be handed
Definition: draw_frame.h:118
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:51
bool m_IsPrinting
Definition: base_screen.h:220
UNDO_REDO_CONTAINER m_RedoList
Objects list for the redo command (old data)
Definition: base_screen.h:211
wxPoint m_ScrollbarPos
Current scroll bar position in scroll units.
Definition: base_screen.h:196
bool IsSave() const
Definition: base_screen.h:329
bool IsIdle() const
Function IsIdle returns true if there is currently no block operation in progress.
This file is part of the common library.
GRIDS m_grids
List of valid grid sizes.
Definition: base_screen.h:79
wxPoint m_MousePosition
Mouse cursor coordinate in logical units.
Definition: base_screen.h:85
Class GRID_TYPE is for grid arrays.
Definition: base_screen.h:45
const wxRealPoint & GetGridSize() const
Return the grid size of the currently selected grid.
Definition: base_screen.h:410
wxPoint m_DrawOrg
offsets for drawing the circuit on the screen
Definition: base_screen.h:183
void ClrModify()
Definition: base_screen.h:325
void SetMaxUndoItems(int aMax)
Definition: base_screen.h:313
void SetNextZoom()
Change the zoom to the next one available.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
The common library.
bool m_FlagSave
Indicates automatic file save.
Definition: base_screen.h:81
int m_NumberOfScreens
Definition: base_screen.h:217
double GetMaxAllowedZoom() const
Function GetMaxAllowedZoom returns the maximum allowed zoom factor, which was established as the last...
Definition: base_screen.h:361
double m_Zoom
Current zoom coefficient.
Definition: base_screen.h:95
Basic classes for most KiCad items.
void SetModify()
Definition: base_screen.h:324
int m_CmdId
Definition: base_screen.h:48
void ClrSave()
Definition: base_screen.h:327
EDA_UNITS_T
Definition: common.h:159
int GetRedoCommandCount() const
Definition: base_screen.h:306
std::vector< double > m_ZoomList
standard zoom (i.e. scale) coefficients.
Definition: base_screen.h:219
void Clear()
Function Clear clears the block selector by setting the command to idle, the state to no block...