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-2017 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 <base_units.h>
26 #include <kiway.h>
27 #include <class_drawpanel.h>
28 
29 #include <eeschema_id.h>
30 #include <libeditframe.h>
31 #include <viewlib_frame.h>
32 #include <sch_base_frame.h>
33 #include <symbol_lib_table.h>
35 
36 
37 // Sttaic members:
38 
39 
40 SCH_BASE_FRAME::SCH_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent,
41  FRAME_T aWindowType, const wxString& aTitle,
42  const wxPoint& aPosition, const wxSize& aSize, long aStyle,
43  const wxString& aFrameName ) :
44  EDA_DRAW_FRAME( aKiway, aParent, aWindowType, aTitle, aPosition,
45  aSize, aStyle, aFrameName )
46 {
47  m_zoomLevelCoeff = 11.0; // Adjusted to roughly displays zoom level = 1
48  // when the screen shows a 1:1 image
49  // obviously depends on the monitor,
50  // but this is an acceptable value
53 }
54 
55 
56 
58 {
59 }
60 
61 
62 void SCH_BASE_FRAME::OnOpenLibraryViewer( wxCommandEvent& event )
63 {
64  LIB_VIEW_FRAME* viewlibFrame = (LIB_VIEW_FRAME*) Kiway().Player( FRAME_SCH_VIEWER, true );
65 
66  viewlibFrame->PushPreferences( m_canvas );
67 
68  // On Windows, Raise() does not bring the window on screen, when iconized
69  if( viewlibFrame->IsIconized() )
70  viewlibFrame->Iconize( false );
71 
72  viewlibFrame->Show( true );
73  viewlibFrame->Raise();
74 }
75 
76 
77 // Virtual from EDA_DRAW_FRAME
79 {
81 }
82 
83 
85 {
86  m_drawBgColor= aColor;
88 }
89 
90 
92 {
94 }
95 
97 {
99 }
100 
101 void SCH_BASE_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
102 {
103  GetScreen()->SetPageSettings( aPageSettings );
104 }
105 
106 
108 {
109  return GetScreen()->GetPageSettings();
110 }
111 
112 
113 const wxSize SCH_BASE_FRAME::GetPageSizeIU() const
114 {
115  // GetSizeIU is compile time dependent:
116  return GetScreen()->GetPageSettings().GetSizeIU();
117 }
118 
119 
121 {
122  wxASSERT( GetScreen() );
123  return GetScreen()->GetAuxOrigin();
124 }
125 
126 
127 void SCH_BASE_FRAME::SetAuxOrigin( const wxPoint& aPosition )
128 {
129  wxASSERT( GetScreen() );
130  GetScreen()->SetAuxOrigin( aPosition );
131 }
132 
133 
135 {
136  wxASSERT( GetScreen() );
137  return GetScreen()->GetTitleBlock();
138 }
139 
140 
141 void SCH_BASE_FRAME::SetTitleBlock( const TITLE_BLOCK& aTitleBlock )
142 {
143  wxASSERT( GetScreen() );
144  GetScreen()->SetTitleBlock( aTitleBlock );
145 }
146 
147 
149 {
150  wxString line;
151  int dx, dy;
152  BASE_SCREEN* screen = GetScreen();
153 
154  if( !screen )
155  return;
156 
158 
159  // Display absolute coordinates:
160  double dXpos = To_User_Unit( g_UserUnit, GetCrossHairPosition().x );
161  double dYpos = To_User_Unit( g_UserUnit, GetCrossHairPosition().y );
162 
163  if ( g_UserUnit == MILLIMETRES )
164  {
165  dXpos = RoundTo0( dXpos, 100.0 );
166  dYpos = RoundTo0( dYpos, 100.0 );
167  }
168 
169  wxString absformatter;
170  wxString locformatter;
171 
172  switch( g_UserUnit )
173  {
174  case INCHES:
175  absformatter = wxT( "X %.3f Y %.3f" );
176  locformatter = wxT( "dx %.3f dy %.3f dist %.3f" );
177  break;
178 
179  case MILLIMETRES:
180  absformatter = wxT( "X %.2f Y %.2f" );
181  locformatter = wxT( "dx %.2f dy %.2f dist %.2f" );
182  break;
183 
184  case UNSCALED_UNITS:
185  absformatter = wxT( "X %f Y %f" );
186  locformatter = wxT( "dx %f dy %f dist %f" );
187  break;
188 
189  case DEGREES:
190  wxASSERT( false );
191  break;
192  }
193 
194  line.Printf( absformatter, dXpos, dYpos );
195  SetStatusText( line, 2 );
196 
197  // Display relative coordinates:
198  dx = GetCrossHairPosition().x - screen->m_O_Curseur.x;
199  dy = GetCrossHairPosition().y - screen->m_O_Curseur.y;
200 
201  dXpos = To_User_Unit( g_UserUnit, dx );
202  dYpos = To_User_Unit( g_UserUnit, dy );
203 
204  if( g_UserUnit == MILLIMETRES )
205  {
206  dXpos = RoundTo0( dXpos, 100.0 );
207  dYpos = RoundTo0( dYpos, 100.0 );
208  }
209 
210  // We already decided the formatter above
211  line.Printf( locformatter, dXpos, dYpos, hypot( dXpos, dYpos ) );
212  SetStatusText( line, 3 );
213 
214  // refresh units display
215  DisplayUnitsMsg();
216 }
217 
218 
219 void SCH_BASE_FRAME::OnEditSymbolLibTable( wxCommandEvent& aEvent )
220 {
222  Prj().SchSymbolLibTable() );
223 
224  if( dlg.ShowModal() == wxID_CANCEL )
225  return;
226 
227  try
228  {
230 
232  }
233  catch( const IO_ERROR& ioe )
234  {
235  wxString msg = wxString::Format( _( "Error occurred saving the global symbol library "
236  "table:\n\n%s" ),
237  GetChars( ioe.What().GetData() ) );
238  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
239  }
240 
241  if( !Prj().GetProjectName().IsEmpty() )
242  {
243  wxFileName fn( Prj().GetProjectPath(), SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
244 
245  try
246  {
247  Prj().SchSymbolLibTable()->Save( fn.GetFullPath() );
248  }
249  catch( const IO_ERROR& ioe )
250  {
251  wxString msg = wxString::Format( _( "Error occurred saving project specific "
252  "symbol library table:\n\n%s" ),
253  GetChars( ioe.What() ) );
254  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
255  }
256  }
257 
258  LIB_VIEW_FRAME* viewer = (LIB_VIEW_FRAME*) Kiway().Player( FRAME_SCH_VIEWER, false );
259 
260  if( viewer )
261  viewer->ReCreateListLib();
262 }
static const wxString & GetSymbolLibTableFileName()
int m_repeatDeltaLabel
the increment value of labels like bus members when they are repeated
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
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 OnEditSymbolLibTable(wxCommandEvent &aEvent)
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:174
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:167
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
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
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
virtual ~SCH_BASE_FRAME()
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
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const override
Generate the table in s-expression format to aOutput with an indention level of aIndentLevel.
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
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
double m_zoomLevelCoeff
a suitable value to convert the internal zoom scaling factor
Definition: draw_frame.h:85
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
const TITLE_BLOCK & GetTitleBlock() const override
Class FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492
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
bool ReCreateListLib()
Function ReCreateListLib.
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...
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
static wxString GetGlobalTableFileName()
Fetch the global symbol library table file name.
Definition of class LIB_EDIT_FRAME.
Dialog to show and edit symbol library tables.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39