wxstruct.h 40.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

26 27 28 29
/**
 * @file wxstruct.h
 * @brief Base window classes and related definitions.
 */
30

Dick Hollenbeck's avatar
Dick Hollenbeck committed
31 32
#ifndef  WXSTRUCT_H_
#define  WXSTRUCT_H_
33 34


35 36
#include <vector>

37
#include <wx/socket.h>
38 39
#include <wx/log.h>
#include <wx/config.h>
40 41
#include <wx/wxhtml.h>
#include <wx/laywin.h>
42
#include <wx/aui/aui.h>
43
#include <wx/docview.h>
44

45
#include <colors.h>
46
#include <fctsys.h>
47
#include <common.h>
48
#include <layers_id_colors_and_visibility.h>
dickelbeck's avatar
dickelbeck committed
49

50 51 52 53
#ifdef USE_WX_OVERLAY
#include <wx/overlay.h>
#endif

54
// Option for main frames
55
#define KICAD_DEFAULT_DRAWFRAME_STYLE wxDEFAULT_FRAME_STYLE | wxWANTS_CHARS
56

57 58 59 60 61 62

// Readability helper definitions for creating backup files.
#define CREATE_BACKUP_FILE    true
#define NO_BACKUP_FILE        false


63
class EDA_ITEM;
64
class EDA_RECT;
65
class EDA_DRAW_PANEL;
66
class EDA_DRAW_PANEL_GAL;
67
class EDA_MSG_PANEL;
68 69
class BASE_SCREEN;
class PARAM_CFG_BASE;
70
class PAGE_INFO;
71
class PLOTTER;
72
class TITLE_BLOCK;
73 74
class MSG_PANEL_ITEM;

75

dickelbeck's avatar
dickelbeck committed
76 77 78
enum id_librarytype {
    LIBRARY_TYPE_EESCHEMA,
    LIBRARY_TYPE_PCBNEW,
79 80
    LIBRARY_TYPE_DOC,
    LIBRARY_TYPE_SYMBOL
81 82
};

83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
enum ID_DRAWFRAME_TYPE
{
    NOT_INIT_FRAME_TYPE = 0,
    SCHEMATIC_FRAME_TYPE,
    LIBEDITOR_FRAME_TYPE,
    VIEWER_FRAME_TYPE,
    PCB_FRAME_TYPE,
    MODULE_EDITOR_FRAME_TYPE,
    MODULE_VIEWER_FRAME_TYPE,
    FOOTPRINT_WIZARD_FRAME_TYPE,
    CVPCB_FRAME_TYPE,
    CVPCB_DISPLAY_FRAME_TYPE,
    GERBER_FRAME_TYPE,
    TEXT_EDITOR_FRAME_TYPE,
    DISPLAY3D_FRAME_TYPE,
98 99
    KICAD_MAIN_FRAME_TYPE,
    PL_EDITOR_FRAME_TYPE
100 101 102
};


103
/// Custom trace mask to enable and disable auto save tracing.
104
extern const wxChar traceAutoSave[];
105 106


107 108
/**
 * Class EDA_BASE_FRAME
109
 * is the base frame for deriving all KiCad main window classes.  This class is not
110 111 112 113
 * intended to be used directly.  It provides support for automatic calls to
 * a virtual SaveSettings() function.  SaveSettings() for a derived class can choose
 * to do nothing, or rely on basic SaveSettings() support in this base class to do
 * most of the work by calling it from the derived class's SaveSettings().
114
 */
115
class EDA_BASE_FRAME : public wxFrame
116
{
117 118 119 120 121 122 123 124 125 126 127 128 129
    /**
     * Function windowClosing
     * (with its unexpected name so it does not collide with the real OnWindowClose()
     * function provided in derived classes) is called just before a window
     * closing, and is used to call a derivation specific
     * SaveSettings().  SaveSettings() is called for all derived wxFrames in this
     * base class overload.  (Calling it from a destructor is deprecated since the
     * wxFrame's position is not available in the destructor on linux.)  In other words,
     * you should not need to call call SaveSettings() anywhere, except in this
     * one function found only in this class.
     */
    void windowClosing( wxCloseEvent& event );

130
protected:
131
    ID_DRAWFRAME_TYPE m_Ident;      ///< Id Type (pcb, schematic, library..)
Wayne Stambaugh's avatar
Wayne Stambaugh committed
132 133 134
    wxPoint      m_FramePos;
    wxSize       m_FrameSize;

135
    wxAuiToolBar* m_mainToolBar;    ///< Standard horizontal Toolbar
Wayne Stambaugh's avatar
Wayne Stambaugh committed
136
    bool         m_FrameIsActive;
137 138 139
    wxString     m_FrameName;       ///< name used for writing and reading setup
                                    ///< It is "SchematicFrame", "PcbFrame" ....
    wxString     m_AboutTitle;      ///< Name of program displayed in About.
140

Wayne Stambaugh's avatar
Wayne Stambaugh committed
141
    wxAuiManager m_auimgr;
142

143 144 145 146 147 148 149 150 151 152 153 154
    /// Flag to indicate if this frame supports auto save.
    bool         m_hasAutoSave;

    /// Flag to indicate the last auto save state.
    bool         m_autoSaveState;

    /// The auto save interval time in seconds.
    int          m_autoSaveInterval;

    /// The timer used to implement the auto save feature;
    wxTimer*     m_autoSaveTimer;

155 156
    wxString     m_perspective;     ///< wxAuiManager perspective.

157 158 159 160 161 162 163
    /**
     * Function onAutoSaveTimer
     * handles the auto save timer event.
     */
    void onAutoSaveTimer( wxTimerEvent& aEvent );

    /**
164 165
     * Function autoSaveRequired
     * returns the auto save status of the application.  Override this function if
166 167
     * your derived frame supports automatic file saving.
     */
168
    virtual bool isAutoSaveRequired() const { return false; }
169 170 171 172 173 174 175 176 177

    /**
     * Function doAutoSave
     * should be overridden by the derived class to handle the auto save feature.
     *
     * @return true if the auto save was successful otherwise false.
     */
    virtual bool doAutoSave();

178
public:
179 180 181 182 183
    EDA_BASE_FRAME( wxWindow* aParent, ID_DRAWFRAME_TYPE aFrameType,
                    const wxString& aTitle,
                    const wxPoint& aPos, const wxSize& aSize,
                    long aStyle,
                    const wxString & aFrameName );
184

185
    ~EDA_BASE_FRAME();
186

187 188 189 190 191 192 193
    /**
     * Function ProcessEvent
     * overrides the default process event handler to implement the auto save feature.
     *
     * @warning If you override this function in a derived class, make sure you call
     *          down to this or the auto save feature will be disabled.
     */
194 195
    bool ProcessEvent( wxEvent& aEvent );       // overload wxFrame::ProcessEvent()

196 197 198 199 200 201 202 203
    void SetAutoSaveInterval( int aInterval ) { m_autoSaveInterval = aInterval; }

    int GetAutoSaveInterval() const { return m_autoSaveInterval; }

    wxString GetName() const { return m_FrameName; }

    bool IsActive() const { return m_FrameIsActive; }

204
    bool IsType( ID_DRAWFRAME_TYPE aType ) const { return m_Ident == aType; }
205

206
    void GetKicadHelp( wxCommandEvent& event );
207

208
    void GetKicadAbout( wxCommandEvent& event );
209 210

    /**
211 212
     * Function CopyVersionInfoToClipboard
     * copies the version information to the clipboard for bug reporting purposes.
213
     */
214 215 216
    void CopyVersionInfoToClipboard( wxCommandEvent& event );

    void PrintMsg( const wxString& text );
217

218 219 220 221 222
    /**
     * Append the copy version information to clipboard help menu entry to \a aMenu.
     *
     * @param aMenu - The menu to append.
     */
223
    void AddHelpVersionInfoMenuEntry( wxMenu* aMenu );
224

225 226 227 228 229 230 231
    /**
     * Load common frame parameters from configuration.
     *
     * The method is virtual so you can override it to load frame specific
     * parameters.  Don't forget to call the base method or your frames won't
     * remember their positions and sizes.
     */
232
    virtual void LoadSettings();
233 234

    /**
235
     * Save common frame parameters to configuration data file.
236 237
     *
     * The method is virtual so you can override it to save frame specific
238 239 240 241
     * parameters.  Don't forget to call the base class's SaveSettings() from
     * your derived SaveSettings() otherwise the frames won't remember their
     * positions and sizes.  The virtual call to SaveSettings is done safely
     * only in EDA_BASE_FRAME::Show( bool ).
242
     */
243 244
    virtual void SaveSettings();

245 246 247 248 249 250 251 252 253
    /**
     * Function SaveProjectSettings
     * saves changes to the project settings to the project (.pro) file.
     * The method is virtual so you can override it to call the suitable save method.
     * The base method do nothing
     * @param aAskForSave = true to open a dialog before saving the settings
     */
    virtual void SaveProjectSettings( bool aAskForSave ) {};

254 255
    /**
     * Function OnSelectPreferredEditor
256
     * Open a dialog to select the editor that will used in KiCad
257 258 259 260 261
     * to edit or display files (reports ... )
     * The full filename editor is saved in configuration (global params)
     */
    virtual void OnSelectPreferredEditor( wxCommandEvent& event );

262 263
    // Read/Save and Import/export hotkeys config

264 265
    /**
     * Function ReadHotkeyConfig
266
     * Read configuration data and fill the current hotkey list with hotkeys
267
     * @param aDescList = current hotkey list descr. to initialize.
268
     */
269
    int ReadHotkeyConfig( struct EDA_HOTKEY_CONFIG* aDescList );
270

271 272
    /**
     * Function WriteHotkeyConfig
273 274 275 276
     * Store the current hotkey list
     * It is stored using the standard wxConfig mechanism or a file.
     *
     * @param aDescList = pointer to the current hotkey list.
277
     * @param aFullFileName = a wxString pointer to a full file name.
278 279 280 281
     *  if NULL, use the standard wxConfig mechanism (default)
     * the output format is: shortcut  "key"  "function"
     * lines starting with # are comments
     */
282
    int WriteHotkeyConfig( struct EDA_HOTKEY_CONFIG* aDescList, wxString* aFullFileName = NULL);
283

284 285
    /**
     * Function ReadHotkeyConfigFile
286
     * Read an old configuration file (&ltfile&gt.key) and fill the current hotkey list
287 288
     * with hotkeys
     * @param aFilename = file name to read.
289
     * @param aDescList = current hotkey list descr. to initialize.
290
     */
291
    int ReadHotkeyConfigFile( const wxString& aFilename, struct EDA_HOTKEY_CONFIG* aDescList );
292

293 294
    /**
     * Function ImportHotkeyConfigFromFile
295
     * Prompt the user for an old hotkey file to read, and read it.
296
     * @param aDescList = current hotkey list descr. to initialize.
297
     */
298
    void ImportHotkeyConfigFromFile( struct EDA_HOTKEY_CONFIG* aDescList );
299

300 301
    /**
     * Function ExportHotkeyConfigToFile
302
     * Prompt the user for an old hotkey file to read, and read it.
303
     * @param aDescList = current hotkey list descr. to initialize.
304
     */
305
    void ExportHotkeyConfigToFile( struct EDA_HOTKEY_CONFIG* aDescList );
306

307 308
    /**
     * Function SetLanguage
309 310 311 312
     * called on a language menu selection
     * when using a derived function, do not forget to call this one
     */
    virtual void SetLanguage( wxCommandEvent& event );
313

314
    /**
315 316
     * Function GetFileFromHistory
     * fetches the file name from the file history list.
317 318 319
     * and removes the selected file, if this file does not exists
     * Note also the menu is updated, if wxFileHistory::UseMenu
     * was called at init time
320 321 322 323
     * @param cmdId The command ID associated with the \a aFileHistory object.
     * @param type Please document me!
     * @param aFileHistory The wxFileHistory in use. If null, the main application file
     *                     history is used
324 325
     * @return a wxString containing the selected filename
     */
326 327
    wxString GetFileFromHistory( int cmdId, const wxString& type,
                                 wxFileHistory* aFileHistory = NULL );
328 329 330

    /**
     * Function UpdateFileHistory
331 332 333
     * Updates the list of recently opened files.
     * Note also the menu is updated, if wxFileHistory::UseMenu
     * was called at init time
334
     * @param FullFileName The full file name including the path.
335 336
     * @param aFileHistory The wxFileHistory in use.
     * If NULL, the main application file history is used.
337
     */
338
    void UpdateFileHistory( const wxString& FullFileName, wxFileHistory * aFileHistory = NULL );
339

340 341 342 343 344
    /**
     * Function ReCreateMenuBar
     * Creates recreates the menu bar.
     * Needed when the language is changed
     */
345
    virtual void ReCreateMenuBar();
346 347 348 349 350

    /**
     * Function IsWritable
     * checks if \a aFileName can be written.
     * <p>
351 352 353 354 355 356
     * The function performs a number of tests on \a aFileName to verify that it
     * can be saved.  If \a aFileName defines a path with no file name, them the
     * path is tested for user write permission.  If \a aFileName defines a file
     * name that does not exist in the path, the path is tested for user write
     * permission.  If \a aFileName defines a file that already exits, the file
     * name is tested for user write permissions.
357 358
     * </p>
     *
359 360
     * @note The file name path must be set or an assertion will be raised on debug
     *       builds and return false on release builds.
361 362 363 364
     * @param aFileName The full path and/or file name of the file to test.
     * @return False if \a aFileName cannot be written.
     */
    bool IsWritable( const wxFileName& aFileName );
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382

    /**
     * Function CheckForAutoSaveFile
     * checks if an auto save file exists for \a aFileName and takes the appropriate
     * action depending on the user input.
     * <p>
     * If an auto save file exists for \a aFileName, the user is prompted if they wish
     * to replace file \a aFileName with the auto saved file.  If the user chooses to
     * replace the file, the backup file of \a aFileName is removed, \a aFileName is
     * renamed to the backup file name, and the auto save file is renamed to \a aFileName.
     * If user chooses to keep the existing version of \a aFileName, the auto save file
     * is removed.
     * </p>
     * @param aFileName A wxFileName object containing the file name to check.
     * @param aBackupFileExtension A wxString object containing the backup file extension
     *                             used to create the backup file name.
     */
    void CheckForAutoSaveFile( const wxFileName& aFileName, const wxString& aBackupFileExtension );
383 384 385 386 387 388 389 390 391 392 393 394 395

    /**
     * Function SetModalMode
     * Disable or enable all other windows, to emulate a dialog behavior
     * Useful when the frame is used to show and selec items
     * (see FOOTPRINT_VIEWER_FRAME and LIB_VIEW_FRAME)
     *
     * @param aModal = true to disable all other opened windows (i.e.
     * this windows is in dialog mode
     *               = false to enable other windows
     * This function is analog to MakeModal( aModal ), deprecated since wxWidgets 2.9.4
     */
    void SetModalMode( bool aModal );
396 397 398
};


399 400
/**
 * Class EDA_DRAW_FRAME
401 402
 * is the base class for create windows for drawing purpose.  The Eeschema, Pcbnew and
 * GerbView main windows are just a few examples of classes derived from EDA_DRAW_FRAME.
403
 */
404
class EDA_DRAW_FRAME : public EDA_BASE_FRAME
405
{
406 407 408 409
    /// Let the #EDA_DRAW_PANEL object have access to the protected data since
    /// it is closely tied to the #EDA_DRAW_FRAME.
    friend class EDA_DRAW_PANEL;

410
    ///< Id of active button on the vertical toolbar.
411
    int         m_toolId;
412

413 414 415 416 417 418
    BASE_SCREEN*    m_currentScreen;        ///< current used SCREEN

    bool        m_snapToGrid;               ///< Indicates if cursor should be snapped to grid.
    bool        m_galCanvasActive;          ///< whether to use new GAL engine

    EDA_DRAW_PANEL_GAL* m_galCanvas;
419

420
protected:
421
    EDA_HOTKEY_CONFIG* m_HotkeysZoomAndGridList;
422 423 424
    int         m_LastGridSizeId;           // the command id offset (>= 0) of the last selected grid
                                            // 0 is for the grid corresponding to
                                            // a wxCommand ID = ID_POPUP_GRID_LEVEL_1000.
425
    bool        m_DrawGrid;                 // hide/Show grid
426
    EDA_COLOR_T m_GridColor;                // Grid color
427

428 429 430
    /// The area to draw on.
    EDA_DRAW_PANEL* m_canvas;

431
    /// Tool ID of previously active draw tool bar button.
432
    int     m_lastDrawToolId;
433

434 435 436
    /// The shape of the KiCad cursor.  The default value (0) is the normal cross
    /// hair cursor.  Set to non-zero value to draw the full screen cursor.
    /// @note This is not the system mouse cursor.
437
    int     m_cursorShape;
438 439

    /// True shows the X and Y axis indicators.
440
    bool    m_showAxis;
441 442

    /// True shows the grid axis indicators.
443
    bool    m_showGridAxis;
444 445 446

    /// True shows the origin axis used to indicate the coordinate offset for
    /// drill, gerber, and component position files.
447
    bool    m_showOriginAxis;
448 449

    /// True shows the drawing border and title block.
450
    bool    m_showBorderAndTitleBlock;
451 452

    /// Choice box to choose the grid size.
453
    wxComboBox*     m_gridSelectBox;
454 455

    /// Choice box to choose the zoom value.
456
    wxComboBox*     m_zoomSelectBox;
457 458 459

    /// The tool bar that contains the buttons for quick access to the application draw
    /// tools.  It typically is located on the right side of the main window.
460
    wxAuiToolBar*   m_drawToolBar;
461 462

    /// The options tool bar typcially located on the left edge of the main window.
463
    wxAuiToolBar*   m_optionsToolBar;
464

465
    /// Panel used to display information at the bottom of the main window.
466
    EDA_MSG_PANEL*  m_messagePanel;
467

468
    int             m_MsgFrameHeight;
469

470 471
#ifdef USE_WX_OVERLAY
    // MAC Uses overlay to workaround the wxINVERT and wxXOR miss
472
    wxOverlay       m_overlay;
473
#endif
474

475
    void SetScreen( BASE_SCREEN* aScreen )  { m_currentScreen = aScreen; }
476

477 478 479 480 481 482 483
    /**
     * Function unitsChangeRefresh
     * is called when when the units setting has changed to allow for any derived classes
     * to handle refreshing and controls that have units based measurements in them.  The
     * default version only updates the status bar.  Don't forget to call the default
     * in your derived class or the status bar will not get updated properly.
     */
484
    virtual void unitsChangeRefresh();
485

486
public:
487 488 489 490 491 492
    EDA_DRAW_FRAME( wxWindow* aParent,
                    ID_DRAWFRAME_TYPE aFrameType,
                    const wxString& aTitle,
                    const wxPoint& aPos, const wxSize& aSize,
                    long aStyle,
                    const wxString & aFrameName );
dickelbeck's avatar
dickelbeck committed
493

494
    ~EDA_DRAW_FRAME();
495

496 497 498 499 500 501 502 503 504 505
    virtual void SetPageSettings( const PAGE_INFO& aPageSettings ) = 0;
    virtual const PAGE_INFO& GetPageSettings() const = 0;

    /**
     * Function GetPageSizeIU
     * works off of GetPageSettings() to return the size of the paper page in
     * the internal units of this particular view.
     */
    virtual const wxSize GetPageSizeIU() const = 0;

506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586
    /**
     * Function GetAuxOrigin
     * returns the origin of the axis used for plotting and various exports.
     */
    virtual const wxPoint& GetAuxOrigin() const = 0;
    virtual void SetAuxOrigin( const wxPoint& aPosition ) = 0;

    /**
     * Function GetGridOrigin
     * returns the absolute coordinates of the origin of the snap grid.  This is
     * treated as a relative offset, and snapping will occur at multiples of the grid
     * size relative to this point.
     */
    virtual const wxPoint& GetGridOrigin() const = 0;
    virtual void SetGridOrigin( const wxPoint& aPosition ) = 0;

    //-----<BASE_SCREEN API moved here>------------------------------------------
    /**
     * Function GetCrossHairPosition
     * return the current cross hair position in logical (drawing) coordinates.
     * @param aInvertY Inverts the Y axis position.
     * @return The cross hair position in drawing coordinates.
     */
    wxPoint GetCrossHairPosition( bool aInvertY = false ) const;

    /**
     * Function SetCrossHairPosition
     * sets the screen cross hair position to \a aPosition in logical (drawing) units.
     * @param aPosition The new cross hair position.
     * @param aSnapToGrid Sets the cross hair position to the nearest grid position to
     *                    \a aPosition.
     *
     */
    void SetCrossHairPosition( const wxPoint& aPosition, bool aSnapToGrid = true );

    /**
     * Function GetCursorPosition
     * returns the current cursor position in logical (drawing) units.
     * @param aOnGrid Returns the nearest grid position at the current cursor position.
     * @param aGridSize Custom grid size instead of the current grid size.  Only valid
     *        if \a aOnGrid is true.
     * @return The current cursor position.
     */
    wxPoint GetCursorPosition( bool aOnGrid, wxRealPoint* aGridSize = NULL ) const;

    /**
     * Function GetNearestGridPosition
     * returns the nearest \a aGridSize location to \a aPosition.
     * @param aPosition The position to check.
     * @param aGridSize The grid size to locate to if provided.  If NULL then the current
     *                  grid size is used.
     * @return The nearst grid position.
     */
    wxPoint GetNearestGridPosition( const wxPoint& aPosition, wxRealPoint* aGridSize = NULL ) const;

    /**
     * Function GetCursorScreenPosition
     * returns the cross hair position in device (display) units.b
     * @return The current cross hair position.
     */
    wxPoint GetCrossHairScreenPosition() const;

    void SetMousePosition( const wxPoint& aPosition );

    /**
     * Function RefPos
     * Return the reference position, coming from either the mouse position
     * or the cursor position.
     *
     * @param useMouse If true, return mouse position, else cursor's.
     *
     * @return wxPoint - The reference point, either the mouse position or
     *                   the cursor position.
     */
    wxPoint RefPos( bool useMouse ) const;

    const wxPoint& GetScrollCenterPosition() const;
    void SetScrollCenterPosition( const wxPoint& aPoint );

    //-----</BASE_SCREEN API moved here>-----------------------------------------

587

588 589 590
    virtual const TITLE_BLOCK& GetTitleBlock() const = 0;
    virtual void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) = 0;

591 592 593 594 595 596 597 598
    int GetCursorShape() const { return m_cursorShape; }

    void SetCursorShape( int aCursorShape ) { m_cursorShape = aCursorShape; }

    bool GetShowBorderAndTitleBlock() const { return m_showBorderAndTitleBlock; }

    void SetShowBorderAndTitleBlock( bool aShow ) { m_showBorderAndTitleBlock = aShow; }

599
    EDA_DRAW_PANEL* GetCanvas() { return m_canvas; }
600

601
    virtual wxString GetScreenDesc() const;
dickelbeck's avatar
dickelbeck committed
602

603
    /**
604 605 606 607
     * Function GetScreen
     * returns a pointer to a BASE_SCREEN or one of its
     * derivatives.  It is overloaded by derived classes to return
     * SCH_SCREEN or PCB_SCREEN.
608
     */
609
    virtual BASE_SCREEN* GetScreen() const  { return m_currentScreen; }
610

611 612 613 614 615 616 617 618 619 620 621
    /**
     * Execute a remote command send via a socket to the application,
     * port KICAD_PCB_PORT_SERVICE_NUMBER (currently 4242)
     * It called by EDA_DRAW_FRAME::OnSockRequest().
     * this is a virtual function becuse the actual commands depends on the
     * application.
     * the basic function do nothing
     * @param cmdline = received command from socket
     */
    virtual void ExecuteRemoteCommand( const char* cmdline ){}

622 623
    void OnMenuOpen( wxMenuEvent& event );
    void  OnMouseEvent( wxMouseEvent& event );
624

625 626 627 628 629 630 631 632 633
    /** function SkipNextLeftButtonReleaseEvent
     * after calling this function, if the left mouse button
     * is down, the next left mouse button release event will be ignored.
     * It is is usefull for instance when closing a dialog on a mouse click,
     * to skip the next mouse left button release event
     * by the parent window, because the mouse button
     * clicked on the dialog is often released in the parent frame,
     * and therefore creates a left button released mouse event
     * which can be unwanted in some cases
634
     */
635
    void SkipNextLeftButtonReleaseEvent();
636

637 638
    virtual void OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
                           EDA_ITEM* aItem = NULL );
639

640 641
    /**
     * Function AddMenuZoomAndGrid (virtual)
642 643 644 645
     * Add standard zoom commands and submenu zoom and grid selection to a popup menu
     * uses zoom hotkeys info base to add hotkeys info to menu commands
     * @param aMasterMenu = the menu to populate.
     */
646
    virtual void AddMenuZoomAndGrid( wxMenu* aMasterMenu );
647

648 649
    void EraseMsgBox();
    void Process_PageSettings( wxCommandEvent& event );
650

651 652
    /**
     * Function SetLanguage
653 654 655
     * called on a language menu selection
     * when using a derived function, do not forget to call this one
     */
656
    virtual void SetLanguage( wxCommandEvent& event );
657

658 659 660 661
    virtual void ReCreateHToolbar() = 0;
    virtual void ReCreateVToolbar() = 0;
    virtual void ReCreateMenuBar();
    virtual void ReCreateAuxiliaryToolbar();
662

663 664
    /**
     * Function SetToolID
665 666 667 668 669 670 671 672 673
     * sets the tool command ID to \a aId and sets the cursor to \a aCursor.  The
     * command ID must be greater or equal ::ID_NO_TOOL_SELECTED.  If the command
     * ID is less than ::ID_NO_TOOL_SELECTED, the tool command ID is set to
     * ::ID_NO_TOOL_SELECTED.  On debug builds, an assertion will be raised when
     * \a aId is invalid.
     * @param aId New tool command ID if greater than or equal to ::ID_NO_TOOL_SELECTED.
                  If less than zero, the current tool command ID is retained.
     * @param aCursor Sets the cursor shape if greater than or equal to zero.
     * @param aToolMsg The tool message to set in the status bar.
674
     */
675 676 677
    virtual void SetToolID( int aId, int aCursor, const wxString& aToolMsg );

    int GetToolId() const { return m_toolId; }
678

679
    /* These 4 functions provide a basic way to show/hide grid
charras's avatar
charras committed
680
     * and /get/set grid color.
681
     * These parameters are saved in KiCad config for each main frame
charras's avatar
charras committed
682
     */
683 684
    /**
     * Function IsGridVisible() , virtual
charras's avatar
charras committed
685 686
     * @return true if the grid must be shown
     */
687
    virtual bool IsGridVisible() const
charras's avatar
charras committed
688 689 690 691
    {
        return m_DrawGrid;
    }

692 693
    /**
     * Function SetGridVisibility() , virtual
charras's avatar
charras committed
694 695 696
     * It may be overloaded by derived classes
     * @param aVisible = true if the grid must be shown
     */
697
    virtual void SetGridVisibility( bool aVisible )
charras's avatar
charras committed
698 699 700 701
    {
        m_DrawGrid = aVisible;
    }

702 703
    /**
     * Function GetGridColor() , virtual
charras's avatar
charras committed
704 705
     * @return the color of the grid
     */
706
    virtual EDA_COLOR_T GetGridColor() const
charras's avatar
charras committed
707 708 709 710
    {
        return m_GridColor;
    }

711 712
    /**
     * Function SetGridColor() , virtual
charras's avatar
charras committed
713 714
     * @param aColor = the new color of the grid
     */
715
    virtual void SetGridColor( EDA_COLOR_T aColor )
charras's avatar
charras committed
716 717 718 719
    {
        m_GridColor = aColor;
    }

720 721 722
    /**
     * Function GetGridPosition
     * returns the nearest grid position to \a aPosition if a screen is defined and snap to
723
     * grid is enabled.  Otherwise, the original positions is returned.
724 725 726 727
     * @see m_snapToGrid and m_BaseScreen members.
     * @param aPosition The position to test.
     * @return The wxPoint of the appropriate cursor position.
     */
728
    wxPoint GetGridPosition( const wxPoint& aPosition ) const;
charras's avatar
charras committed
729

730 731 732 733 734 735 736 737 738 739
    /**
     * Command event handler for selecting grid sizes.
     *
     * All commands that set the grid size should eventually end up here.
     * This is where the application setting is saved.  If you override
     * this method, make sure you call down to the base class.
     *
     * @param event - Command event passed by selecting grid size from the
     *                grid size combobox on the toolbar.
     */
740
    virtual void OnSelectGrid( wxCommandEvent& event );
741 742 743 744 745 746 747 748

    /**
     * Functions OnSelectZoom
     * sets the zoom factor when selected by the zoom list box in the main tool bar.
     * @note List position 0 is fit to page
     *       List position >= 1 = zoom (1 to zoom max)
     *       Last list position is custom zoom not in zoom list.
     */
749
    virtual void OnSelectZoom( wxCommandEvent& event );
750

751 752 753 754 755 756 757 758 759 760 761 762 763
    // Command event handlers shared by all applications derived from EDA_DRAW_FRAME.
    void OnToggleGridState( wxCommandEvent& aEvent );
    void OnSelectUnits( wxCommandEvent& aEvent );
    void OnToggleCrossHairStyle( wxCommandEvent& aEvent );

    // Update user interface event handlers shared by all applications derived from
    // EDA_DRAW_FRAME.
    void OnUpdateUndo( wxUpdateUIEvent& aEvent );
    void OnUpdateRedo( wxUpdateUIEvent& aEvent );
    void OnUpdateGrid( wxUpdateUIEvent& aEvent );
    void OnUpdateUnits( wxUpdateUIEvent& aEvent );
    void OnUpdateCrossHairStyle( wxUpdateUIEvent& aEvent );

764
    /**
765
     * Function GeneralControl
766 767 768 769 770 771
     * performs application specific control using \a aDC at \a aPosition in logical units.
     * <p>
     * Override this function for application specific control.  This function gets
     * called on every mouse and key event.
     *</p>
     * @param aDC A device context.
772
     * @param aPosition The current cursor position in logical (drawing) units.
773
     * @param aHotKey A key event used for application specific control if not zero.
774
     */
775
    virtual void GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ) { }
776

777 778 779 780
    /**
     * Function OnSize
     * recalculates the size of toolbars and display panel when the frame size changes.
     */
781
    virtual void OnSize( wxSizeEvent& event );
782

783
    void OnEraseBackground( wxEraseEvent& SizeEvent );
dickelbeck's avatar
dickelbeck committed
784

785
    virtual void OnZoom( wxCommandEvent& event );
786 787 788 789

    /**
     * Function RedrawScreen
     * redraws the entire screen area by updating the scroll bars and mouse pointer in
790 791 792
     * order to have \a aCenterPoint at the center of the screen.
     * @param aCenterPoint The position in logical units to center the scroll bars.
     * @param aWarpPointer Moves the mouse cursor to \a aCenterPoint if true.
793
     */
794
    void RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointer );
795

796 797 798
    /**
     * Function RedrawScreen2
     * puts the crosshair back to the screen position it had before zooming
799
     * @param posBefore screen position of the crosshair before zooming
800 801 802
     */
    void RedrawScreen2( const wxPoint& posBefore );

803 804 805 806 807
    /**
     * Function Zoom_Automatique
     * redraws the screen with best zoom level and the best centering
     * that shows all the page or the board
     */
808
    void Zoom_Automatique( bool aWarpPointer );
dickelbeck's avatar
dickelbeck committed
809

810
    /* Set the zoom level to show the area Rect */
811
    void Window_Zoom( EDA_RECT& Rect );
dickelbeck's avatar
dickelbeck committed
812

813
    /** Return the zoom level which displays the full page on screen */
814
    virtual double BestZoom() = 0;
dickelbeck's avatar
dickelbeck committed
815

816 817 818 819
    /**
     * Function GetZoom
     * @return The current zoom level.
     */
820 821 822
    double GetZoom();

    /**
823 824
     * Function DrawWorkSheet
     * Draws on screen the page layout with the frame and the basic inscriptions.
825
     * @param aDC The device context.
826 827 828 829 830 831 832
     * @param aScreen screen to draw
     * @param aLineWidth The pen width to use to draw the layout.
     * @param aScale The mils to Iu conversion factor.
     * @param aFilename The filename to display in basic inscriptions.
     */
    void DrawWorkSheet( wxDC* aDC, BASE_SCREEN* aScreen, int aLineWidth,
                         double aScale, const wxString &aFilename );
833

834 835 836 837 838 839 840
    void            DisplayToolMsg( const wxString& msg );
    virtual void    RedrawActiveWindow( wxDC* DC, bool EraseBg ) = 0;
    virtual void    OnLeftClick( wxDC* DC, const wxPoint& MousePos ) = 0;
    virtual void    OnLeftDClick( wxDC* DC, const wxPoint& MousePos );
    virtual bool    OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ) = 0;
    virtual void    ToolOnRightClick( wxCommandEvent& event );
    void            AdjustScrollBars( const wxPoint& aCenterPosition );
841

842 843 844 845
    /**
     * Function OnActivate (virtual)
     * is called when activating the frame.
     * In derived classes with a overriding OnActivate function,
846
     * do not forget to call this EDA_DRAW_FRAME::OnActivate( event ) basic function.
847
     */
848
    virtual void OnActivate( wxActivateEvent& event );
849

850 851 852 853 854 855 856 857 858 859
    /**
     * Function UpdateStatusBar
     * updates the status bar information.
     *
     * The base method updates the absolute and relative coordinates and the
     * zoom information.  If you override this virtual method, make sure to call
     * this subclassed method.  The status bar can draw itself.  This is not
     * a drawing function per se, but rather updates lines of text held by
     * the components within the status bar which is owned by the wxFrame.
     * <p>
860 861
     * On a MAC, be careful about calling this function when there is an
     * existing wxDC in existence on a sibling window.
862
     */
863
    virtual void UpdateStatusBar();
864

865 866 867 868
    /**
     * Function DisplayUnitsMsg
     * displays current unit pane on the status bar.
     */
869
    void DisplayUnitsMsg();
dickelbeck's avatar
dickelbeck committed
870

871
    /* Handlers for block commands */
872
    virtual void InitBlockPasteInfos();
873 874 875 876 877 878 879

    /**
     * Function HandleBlockBegin
     * initializes the block command including the command type, initial position,
     * and other variables.
     */
    virtual bool HandleBlockBegin( wxDC* aDC, int aKey, const wxPoint& aPosition );
880 881 882

    /**
     * Function ReturnBlockCommand
883 884 885 886
     * Returns the block command code (BLOCK_MOVE, BLOCK_COPY...) corresponding to the
     * keys pressed (ALT, SHIFT, SHIFT ALT ..) when block command is started by dragging
     * the mouse.
     *
887 888 889
     * @param aKey = the key modifiers (Alt, Shift ...)
     * @return the block command id (BLOCK_MOVE, BLOCK_COPY...)
     */
890
    virtual int ReturnBlockCommand( int aKey );
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911

    /**
     * Function HandleBlockPlace( )
     * Called after HandleBlockEnd, when a block command needs to be
     * executed after the block is moved to its new place
     * (bloc move, drag, copy .. )
     * Parameters must be initialized in GetScreen()->m_BlockLocate
     */
    virtual void HandleBlockPlace( wxDC* DC );

    /**
     * Function HandleBlockEnd( )
     * Handle the "end"  of a block command,
     * i.e. is called at the end of the definition of the area of a block.
     * depending on the current block command, this command is executed
     * or parameters are initialized to prepare a call to HandleBlockPlace
     * in GetScreen()->m_BlockLocate
     * @return false if no item selected, or command finished,
     * true if some items found and HandleBlockPlace must be called later
     */
    virtual bool HandleBlockEnd( wxDC* DC );
dickelbeck's avatar
dickelbeck committed
912

913 914 915 916
    /**
     * Function CopyToClipboard
     * copies the current page or the current block to the clipboard.
     */
917
    void CopyToClipboard( wxCommandEvent& event );
dickelbeck's avatar
dickelbeck committed
918 919

    /* interprocess communication */
920 921
    void OnSockRequest( wxSocketEvent& evt );
    void OnSockRequestServer( wxSocketEvent& evt );
922

923 924 925 926 927 928 929
    /**
     * Function LoadSettings
     * loads the draw frame specific configuration settings.
     *
     * Don't forget to call this base method from any derived classes or the
     * settings common to the draw frame will not get loaded.
     */
930
    virtual void LoadSettings();
931 932 933 934 935 936 937 938

    /**
     * Funxtion SaveSettings
     * saves the draw frame specific configuration settings.
     *
     * Don't forget to call this base method from any derived classes or the
     * settings common to the draw frame will not get saved.
     */
939
    virtual void SaveSettings();
940

941 942 943 944 945 946 947 948 949
    /**
     * Append a message to the message panel.
     *
     * This helper method checks to make sure the message panel exists in
     * the frame and appends a message to it using the message panel
     * AppendMessage() method.
     *
     * @param textUpper - The message upper text.
     * @param textLower - The message lower text.
950
     * @param color - A color ID from the KiCad color list (see colors.h).
951 952 953
     * @param pad - Number of spaces to pad between messages (default = 4).
     */
    void AppendMsgPanel( const wxString& textUpper, const wxString& textLower,
954
                         EDA_COLOR_T color, int pad = 6 );
955 956 957 958 959 960

    /**
     * Clear all messages from the message panel.
     */
    void ClearMsgPanel( void );

961 962 963 964 965 966 967 968 969 970
    /**
     * Function SetMsgPanel
     * clears the message panel and populates it with the contents of \a aList.
     *
     * @param aList is the list of #MSG_PANEL_ITEM objects to fill the message panel.
     */
    void SetMsgPanel( const std::vector< MSG_PANEL_ITEM >& aList );

    void SetMsgPanel( EDA_ITEM* aItem );

971 972
    /**
     * Function PrintPage
charras's avatar
charras committed
973
     * used to print a page
974
     * Print the page pointed by current screen, set by the calling print function
charras's avatar
charras committed
975 976 977 978 979
     * @param aDC = wxDC given by the calling print function
     * @param aPrintMask = not used here
     * @param aPrintMirrorMode = not used here (Set when printing in mirror mode)
     * @param aData = a pointer on an auxiliary data (not always used, NULL if not used)
     */
980
    virtual void PrintPage( wxDC* aDC, LAYER_MSK aPrintMask, bool aPrintMirrorMode, void* aData = NULL );
charras's avatar
charras committed
981

982 983
    /**
     * Function CoordinateToString
984
     * is a helper to convert the \a integer coordinate \a aValue to a string in inches or mm
985 986 987 988 989 990
     * according to the current user units setting.
     * @param aValue The coordinate to convert.
     * @param aConvertToMils Convert inch values to mils if true.  This setting has no effect if
     *                       the current user unit is millimeters.
     * @return The converted string for display in user interface elements.
     */
991
    wxString CoordinateToString( int aValue, bool aConvertToMils = false ) const;
992

993 994 995 996 997 998 999 1000 1001
    /**
     * Function LengthDoubleToString
     * is a helper to convert the \a double value \a aValue to a string in inches or mm
     * according to the current user units setting.
     * @param aValue The coordinate to convert.
     * @param aConvertToMils Convert inch values to mils if true.  This setting has no effect if
     *                       the current user unit is millimeters.
     * @return The converted string for display in user interface elements.
     */
1002
    wxString LengthDoubleToString( double aValue, bool aConvertToMils = false ) const;
1003

1004 1005 1006
    /**
     * Function UseGalCanvas
     * used to switch between standard and GAL-based canvas.
1007 1008
     *
     * @param aEnable True for GAL-based canvas, false for standard canvas.
1009
     */
1010
    virtual void UseGalCanvas( bool aEnable );
1011

1012
    /**
1013
     * Function IsGalCanvasActive
1014
     * is used to check which canvas (GAL-based or standard) is currently in use.
1015
     *
1016 1017
     * @return True for GAL-based canvas, false for standard canvas.
     */
1018 1019
    bool IsGalCanvasActive() const          { return m_galCanvasActive; }
    void SetGalCanvasActive( bool aState )  { m_galCanvasActive = aState; }
1020 1021

    /**
1022
     * Function GetGalCanvas
1023 1024 1025 1026
     * returns a pointer to GAL-based canvas of given EDA draw frame.
     *
     * @return Pointer to GAL-based canvas.
     */
1027 1028
    EDA_DRAW_PANEL_GAL* GetGalCanvas() const        { return m_galCanvas; }
    void SetGalCanvas( EDA_DRAW_PANEL_GAL* aPanel ) { m_galCanvas = aPanel; }
1029

jean-pierre charras's avatar
jean-pierre charras committed
1030
    DECLARE_EVENT_TABLE()
1031
};
1032 1033


1034
/**
1035
 * Specialization of the wxAuiPaneInfo class for KiCad panels.
1036 1037
 *
 * Documentation for wxAui is poor at this time. The following notes spring from errors made in
1038
 * previous KiCad implementations:
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050
 *
 * wxAuiPaneInfo.ToolbarPane() and .Defaults() are used to clear and then prepare the objects so
 * only use them once at the beginning of configuration..
 *
 * Panels are organized in layers, from 0 (close to the center) and increasing outward. Note
 * that for ToolbarPanes, layer 0 considered a special default value, and ToolbarPanes on
 * layer 0 are pushed to layer 10 automatically. Use Layer 1 for the inner layer as a work-
 * around.
 *
 * Each panel has rows, starting at 0. Each row has positions starting at 0. Each item in a panel
 * can have it's row and position set.
 *
1051
 * Eventually panels will be movable. Each initialization function sets up the panel for this,
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062
 * then after a //==// break has additional calls to anchor toolbars in a way that matches
 * present functionality.
 */

class EDA_PANEINFO : public wxAuiPaneInfo
{

public:

    /**
     * Function HorizontalToolbarPane
1063
     * Change *this to a horizontal toolbar for KiCad.
1064 1065 1066 1067 1068 1069 1070
     */
    EDA_PANEINFO& HorizontalToolbarPane()
    {
        ToolbarPane();
        CloseButton( false );
        LeftDockable( false );
        RightDockable( false );
1071
        //====================  Remove calls below here for movable toolbars //
1072 1073 1074 1075 1076 1077 1078 1079 1080
        Gripper( false );
        DockFixed( true );
        Movable( false );
        Resizable( true );
        return *this;
    }

    /**
     * Function VerticalToolbarPane
1081
     * Change *this to a vertical toolbar for KiCad.
1082 1083 1084 1085 1086 1087 1088
     */
    EDA_PANEINFO& VerticalToolbarPane()
    {
        ToolbarPane();
        CloseButton( false );
        TopDockable( false );
        BottomDockable( false );
1089
        //====================  Remove calls below here for movable toolbars //
1090 1091 1092 1093 1094 1095 1096 1097 1098
        Gripper( false );
        DockFixed( true );
        Movable( false );
        Resizable( true );
        return *this;
    }

    /**
     * Function MessageToolbarPane
1099
     * Change *this to a message pane for KiCad.
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114
     *
     */
    EDA_PANEINFO& MessageToolbarPane()
    {
        Gripper( false );
        DockFixed( true );
        Movable( false );
        Floatable( false );
        CloseButton( false );
        CaptionVisible( false );
        return *this;
    }

    /**
     * Function LayersToolbarPane
1115
     * Change *this to a layers toolbar for KiCad.
1116 1117 1118 1119 1120 1121 1122 1123 1124
     */
    EDA_PANEINFO& LayersToolbarPane()
    {
        CloseButton( false );
        return *this;
    }

    /**
     * Function InfoToolbarPane
1125
     * Change *this to a information panel for for KiCad.
1126 1127
     *
     * Info panes are used for vertical display of information next to the center pane.
1128
     * Used in CvPcb and the library viewer primarily.
1129 1130 1131 1132 1133 1134 1135 1136 1137
     */
    EDA_PANEINFO& InfoToolbarPane()
    {
        Gripper( false );
        CloseButton( false );
        CaptionVisible( false );
        return *this;
    }

1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150
    /**
     * Function ScriptingToolbarPane
     * Change *this to a scripting toolbar for KiCad.
     */
    EDA_PANEINFO& ScriptingToolbarPane()
    {
        CloseButton( false );
        Floatable( true );
        Resizable( true );
        return *this;
    }


1151 1152
};

Dick Hollenbeck's avatar
Dick Hollenbeck committed
1153
#endif  // WXSTRUCT_H_