KiCad PCB EDA Suite
class_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 CLASS_BASE_SCREEN_H_
32 #define CLASS_BASE_SCREEN_H_
33 
34 #include <draw_frame.h>
35 #include <base_struct.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 
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 
294 
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  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 // CLASS_BASE_SCREEN_H_
virtual void PushCommandToUndoList(PICKED_ITEMS_LIST *aItem)
Function PushCommandToUndoList add a command to undo in undo list delete the very old commands when t...
void SetGridList(GRIDS &sizelist)
void SetCurItem(EDA_ITEM *aItem)
Function SetCurItem sets the currently selected object, m_CurrentItem.
int m_UndoRedoCountMax
undo/Redo command Max depth
wxPoint getCursorPosition(bool aOnGrid, const wxPoint &aGridOrigin, wxRealPoint *aGridSize) const
Function getCursorPosition returns the current cursor position in logical (drawing) units...
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
EDA_ITEM * m_CurrentItem
Currently selected object.
wxSize m_ScrollbarNumber
Current virtual draw area size in scroll units.
bool m_FlagModified
Indicates current drawing has been modified.
int m_ScrollPixelsPerUnitY
Pixels per scroll unit in the vertical direction.
void setScrollCenterPosition(const wxPoint &aPoint)
EDA_ITEM * GetCurItem() const
double GetScalingFactor() const
Function GetScalingFactor returns the inverse of the current scale used to draw items on screen...
Definition: base_screen.cpp:92
virtual wxString GetClass() const override
Function GetClass returns the class name.
wxPoint m_crossHairPosition
The cross hair position in logical (drawing) units.
#define DEFAULT_MAX_UNDO_ITEMS
Definition: draw_frame.h:46
int GetGridCmdId() const
Return the command ID of the currently selected grid.
double GetZoom() const
Function GetZoom returns the current "zoom factor", which is a measure of "internal units per device ...
wxPoint getCrossHairScreenPosition() const
Function getCursorScreenPosition returns the cross hair position in device (display) units...
GRID_TYPE m_Grid
Current grid selection.
const GRIDS & GetGrids() const
Function GetGrids().
bool IsModify() const
void ClearBlockCommand()
virtual void ClearUndoORRedoList(UNDO_REDO_CONTAINER &aList, int aItemCount=-1)=0
Function ClearUndoORRedoList (virtual).
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:54
bool SetPreviousZoom()
wxPoint m_scrollCenter
Current scroll center point in logical units.
wxPoint m_O_Curseur
Relative Screen cursor coordinate (on grid) in user units.
std::vector< GRID_TYPE > GRIDS
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
wxPoint refPos(bool useMouse) const
Function RefPos Return the reference position, coming from either the mouse position or the cursor po...
not really an item, used to identify a screen
Definition: typeinfo.h:86
size_t GetGridCount() const
Function GetGridCount().
double GetMinAllowedZoom() const
Function GetMinAllowedZoom returns the minimum allowed zoom factor, which was established as the firs...
bool SetNextZoom()
static wxString m_PageLayoutDescrFileName
the name of the page layout descr file, or emty to used the default pagelayout
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:69
int BuildGridsChoiceList(wxArrayString &aGridsList, bool aMmFirst) const
Function BuildGridsChoiceList().
int GetUndoCommandCount() const
wxPoint m_StartVisu
Coordinates in drawing units of the current view position (upper left corner of device) ...
Class UNDO_REDO_CONTAINER is a holder to handle alist of undo (or redo) command.
bool IsBlockActive() const
#define ABS_MAX_UNDO_ITEMS
Definition: draw_frame.h:47
wxPoint getCrossHairPosition(bool aInvertY) const
Function getCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
const GRID_TYPE & GetGrid() const
Return the grid object of the currently selected grid.
std::vector< PICKED_ITEMS_LIST * > m_CommandsList
wxPoint getNearestGridPosition(const wxPoint &aPosition, const wxPoint &aGridOrigin, wxRealPoint *aGridSize) const
Function getNearestGridPosition returns the nearest aGridSize location to aPosition.
bool m_Center
Center on screen.
UNDO_REDO_CONTAINER m_UndoList
Objects list for the undo command (old data)
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
void SetScalingFactor(double iu_per_du)
Function SetScalingFactor sets the scaling factor of "internal unit per device unit".
Definition: base_screen.cpp:99
const bool operator==(const GRID_TYPE &item) const
virtual PICKED_ITEMS_LIST * PopCommandFromRedoList()
PopCommandFromRedoList return the last command to undo and remove it from list nothing is deleted...
virtual void ClearUndoRedoList()
Function ClearUndoRedoList clear undo and redo list, using ClearUndoORRedoList() picked items are del...
int m_ScrollPixelsPerUnitX
Pixels per scroll unit in the horizontal direction.
wxRealPoint m_Size
void setMousePosition(const wxPoint &aPosition)
virtual int MilsToIuScalar()
Function MilsToIuScalar returns the scalar required to convert mils to internal units.
const wxPoint & getScrollCenterPosition() const
bool SetZoom(double iu_per_du)
Function SetZoom adjusts the current zoom factor.
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
GRID_TYPE & operator=(const GRID_TYPE &item)
UNDO_REDO_CONTAINER m_RedoList
Objects list for the redo command (old data)
wxPoint m_ScrollbarPos
Current scroll bar position in scroll units.
bool IsSave() const
bool IsIdle() const
Function IsIdle returns true if there is currently no block operation in progress.
This file is part of the common library.
void setCrossHairPosition(const wxPoint &aPosition, const wxPoint &aGridOrigin, bool aSnapToGrid)
Function setCrossHairPosition sets the screen cross hair position to aPosition in logical (drawing) u...
void AddGrid(const GRID_TYPE &grid)
GRIDS m_grids
List of valid grid sizes.
bool GridExists(int aCommandId)
Function GridExists tests for grid command ID (not an index in grid list, but a wxID) exists in grid ...
wxPoint m_MousePosition
Mouse cursor coordinate in logical units.
Class GRID_TYPE is for grid arrays.
BASE_SCREEN(KICAD_T aType=SCREEN_T)
Definition: base_screen.cpp:42
const wxRealPoint & GetGridSize() const
Return the grid size of the currently selected grid.
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
void SetMaxUndoItems(int aMax)
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
The common library.
bool m_FlagSave
Indicates automatic file save.
double GetMaxAllowedZoom() const
Function GetMaxAllowedZoom returns the maximum allowed zoom factor, which was established as the last...
double m_Zoom
Current zoom coefficient.
Basic classes for most KiCad items.
int SetGrid(const wxRealPoint &size)
set the current grid size m_Grid.
bool SetLastZoom()
bool SetFirstZoom()
EDA_UNITS_T
Definition: common.h:143
int GetRedoCommandCount() const
std::vector< double > m_ZoomList
standard zoom (i.e. scale) coefficients.
void Clear()
Function Clear clears the block selector by setting the command to idle, the state to no block...