KiCad PCB EDA Suite
sch_base_frame.cpp
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) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
5  * Copyright (C) 2015 KiCad Developers, see change_log.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 #include <sch_base_frame.h>
26 #include <viewlib_frame.h>
27 #include <libeditframe.h>
28 #include <base_units.h>
29 #include <kiway.h>
30 #include <class_drawpanel.h>
31 
32 // Sttaic members:
33 
34 
35 SCH_BASE_FRAME::SCH_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent,
36  FRAME_T aWindowType, const wxString& aTitle,
37  const wxPoint& aPosition, const wxSize& aSize, long aStyle,
38  const wxString& aFrameName ) :
39  EDA_DRAW_FRAME( aKiway, aParent, aWindowType, aTitle, aPosition,
40  aSize, aStyle, aFrameName )
41 {
42  m_zoomLevelCoeff = 11.0; // Adjusted to roughly displays zoom level = 1
43  // when the screen shows a 1:1 image
44  // obviously depends on the monitor,
45  // but this is an acceptable value
48 }
49 
50 
51 void SCH_BASE_FRAME::OnOpenLibraryViewer( wxCommandEvent& event )
52 {
53  LIB_VIEW_FRAME* viewlibFrame = (LIB_VIEW_FRAME*) Kiway().Player( FRAME_SCH_VIEWER, true );
54 
55  viewlibFrame->PushPreferences( m_canvas );
56 
57  // On Windows, Raise() does not bring the window on screen, when iconized
58  if( viewlibFrame->IsIconized() )
59  viewlibFrame->Iconize( false );
60 
61  viewlibFrame->Show( true );
62  viewlibFrame->Raise();
63 }
64 
65 // Virtual from EDA_DRAW_FRAME
67 {
69 }
70 
72 {
73  m_drawBgColor= aColor;
75 }
76 
77 
79 {
81 }
82 
84 {
86 }
87 
88 void SCH_BASE_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
89 {
90  GetScreen()->SetPageSettings( aPageSettings );
91 }
92 
93 
95 {
96  return GetScreen()->GetPageSettings();
97 }
98 
99 
100 const wxSize SCH_BASE_FRAME::GetPageSizeIU() const
101 {
102  // GetSizeIU is compile time dependent:
103  return GetScreen()->GetPageSettings().GetSizeIU();
104 }
105 
106 
108 {
109  wxASSERT( GetScreen() );
110  return GetScreen()->GetAuxOrigin();
111 }
112 
113 
114 void SCH_BASE_FRAME::SetAuxOrigin( const wxPoint& aPosition )
115 {
116  wxASSERT( GetScreen() );
117  GetScreen()->SetAuxOrigin( aPosition );
118 }
119 
120 
122 {
123  wxASSERT( GetScreen() );
124  return GetScreen()->GetTitleBlock();
125 }
126 
127 
128 void SCH_BASE_FRAME::SetTitleBlock( const TITLE_BLOCK& aTitleBlock )
129 {
130  wxASSERT( GetScreen() );
131  GetScreen()->SetTitleBlock( aTitleBlock );
132 }
133 
134 
136 {
137  wxString line;
138  int dx, dy;
139  BASE_SCREEN* screen = GetScreen();
140 
141  if( !screen )
142  return;
143 
145 
146  // Display absolute coordinates:
147  double dXpos = To_User_Unit( g_UserUnit, GetCrossHairPosition().x );
148  double dYpos = To_User_Unit( g_UserUnit, GetCrossHairPosition().y );
149 
150  if ( g_UserUnit == MILLIMETRES )
151  {
152  dXpos = RoundTo0( dXpos, 100.0 );
153  dYpos = RoundTo0( dYpos, 100.0 );
154  }
155 
156  wxString absformatter;
157  wxString locformatter;
158 
159  switch( g_UserUnit )
160  {
161  case INCHES:
162  absformatter = wxT( "X %.3f Y %.3f" );
163  locformatter = wxT( "dx %.3f dy %.3f dist %.3f" );
164  break;
165 
166  case MILLIMETRES:
167  absformatter = wxT( "X %.2f Y %.2f" );
168  locformatter = wxT( "dx %.2f dy %.2f dist %.2f" );
169  break;
170 
171  case UNSCALED_UNITS:
172  absformatter = wxT( "X %f Y %f" );
173  locformatter = wxT( "dx %f dy %f dist %f" );
174  break;
175 
176  case DEGREES:
177  wxASSERT( false );
178  break;
179  }
180 
181  line.Printf( absformatter, dXpos, dYpos );
182  SetStatusText( line, 2 );
183 
184  // Display relative coordinates:
185  dx = GetCrossHairPosition().x - screen->m_O_Curseur.x;
186  dy = GetCrossHairPosition().y - screen->m_O_Curseur.y;
187 
188  dXpos = To_User_Unit( g_UserUnit, dx );
189  dYpos = To_User_Unit( g_UserUnit, dy );
190 
191  if( g_UserUnit == MILLIMETRES )
192  {
193  dXpos = RoundTo0( dXpos, 100.0 );
194  dYpos = RoundTo0( dYpos, 100.0 );
195  }
196 
197  // We already decided the formatter above
198  line.Printf( locformatter, dXpos, dYpos, hypot( dXpos, dYpos ) );
199  SetStatusText( line, 3 );
200 
201  // refresh units display
202  DisplayUnitsMsg();
203 }
int m_repeatDeltaLabel
the increment value of labels like bus members when they are repeated
const wxPoint & GetAuxOrigin() const
SCH_BASE_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aWindowType, const wxString &aTitle, const wxPoint &aPosition, const wxSize &aSize, long aStyle, const wxString &aFrameName)
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_player.h:60
void OnOpenLibraryViewer(wxCommandEvent &event)
Function OnOpenLibraryViewer Open the library viewer only to browse library contents.
void SetLayerColor(COLOR4D aColor, SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:173
virtual const wxString GetZoomLevelIndicator() const
Function GetZoomLevelIndicator returns a human readable value which can be displayed as zoom level in...
Definition: draw_frame.cpp:680
Implementation of conversion functions that require both schematic and board internal units...
double RoundTo0(double x, double precision)
Round to the nearest precision.
Definition: common.cpp:182
#define DEFAULT_REPEAT_LABEL_INC
the default value (overwritten by the eeschema config)
Definition: general.h:49
FRAME_T
Enum FRAME_T is the set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:34
SCH_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
wxPoint m_repeatStep
the increment value of the position of an item when it is repeated
const wxPoint & GetAuxOrigin() const override
Function GetAuxOrigin returns the origin of the axis used for plotting and various exports...
void SetPageSettings(const PAGE_INFO &aPageSettings)
void SetAuxOrigin(const wxPoint &aPosition)
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:53
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:166
void PushPreferences(const EDA_DRAW_PANEL *aParentCanvas)
Function PushPreferences Pushes a few preferences from a parent window to a child window...
Definition: draw_frame.cpp:806
COLOR4D m_drawBgColor
the background color of the draw canvas BLACK for Pcbnew, BLACK or WHITE for eeschema ...
Definition: draw_frame.h:83
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout, or editing view.
wxPoint m_O_Curseur
Relative Screen cursor coordinate (on grid) in user units.
const wxString GetZoomLevelIndicator() const override
Function GetZoomLevelIndicator returns a human readable value which can be displayed as zoom level in...
Component library viewer main window.
Definition: viewlib_frame.h:49
const wxSize GetPageSizeIU() const override
Function GetPageSizeIU works off of GetPageSettings() to return the size of the paper page in the int...
void DisplayUnitsMsg()
Function DisplayUnitsMsg displays current unit pane on the status bar.
Definition: draw_frame.cpp:503
virtual BASE_SCREEN * GetScreen() const
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
Definition: draw_frame.h:309
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, KIWAY_PLAYER *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:302
void SetAuxOrigin(const wxPoint &aPosition) override
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock) override
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: common.h:145
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:257
#define DEFAULT_REPEAT_OFFSET_Y
the default Y value (overwritten by the eeschema config)
Definition: general.h:47
COLOR4D GetDrawBgColor() const override
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
void SetPageSettings(const PAGE_INFO &aPageSettings) override
const TITLE_BLOCK & GetTitleBlock() const
#define DEFAULT_REPEAT_OFFSET_X
the default X value (overwritten by the eeschema config)
Definition: general.h:46
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
const PAGE_INFO & GetPageSettings() const override
void UpdateStatusBar() override
Function UpdateStatusBar updates the status bar information.
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:92
double m_zoomLevelCoeff
a suitable value to convert the internal zoom scaling factor
Definition: draw_frame.h:85
const TITLE_BLOCK & GetTitleBlock() const override
void SetDrawBgColor(COLOR4D aColor) override
const PAGE_INFO & GetPageSettings() const
double To_User_Unit(EDA_UNITS_T aUnit, double aValue)
Function To_User_Unit convert aValue in internal units to the appropriate user units defined by aUnit...
Definition: base_units.cpp:90
virtual void UpdateStatusBar()
Function UpdateStatusBar updates the status bar information.
Definition: draw_frame.cpp:669
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
Definition of class LIB_EDIT_FRAME.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39