You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1565 lines
46 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
16 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
19 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
// Dick Hollenbeck's KiROUND R&D // This provides better project control over rounding to int from double // than wxRound() did. This scheme provides better logging in Debug builds // and it provides for compile time calculation of constants. #include <stdio.h> #include <assert.h> #include <limits.h> //-----<KiROUND KIT>------------------------------------------------------------ /** * KiROUND * rounds a floating point number to an int using * "round halfway cases away from zero". * In Debug build an assert fires if will not fit into an int. */ #if defined( DEBUG ) // DEBUG: a macro to capture line and file, then calls this inline static inline int KiRound( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); } else if( v < INT_MIN - 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); } return int( v ); } #define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) #else // RELEASE: a macro so compile can pre-compute constants. #define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) #endif //-----</KiROUND KIT>----------------------------------------------------------- // Only a macro is compile time calculated, an inline function causes a static constructor // in a situation like this. // Therefore the Release build is best done with a MACRO not an inline function. int Computed = KiROUND( 14.3 * 8 ); int main( int argc, char** argv ) { for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 ) { int i = KiROUND( d ); printf( "t: %d %.16g\n", i, d ); } return 0; }
14 years ago
// Dick Hollenbeck's KiROUND R&D // This provides better project control over rounding to int from double // than wxRound() did. This scheme provides better logging in Debug builds // and it provides for compile time calculation of constants. #include <stdio.h> #include <assert.h> #include <limits.h> //-----<KiROUND KIT>------------------------------------------------------------ /** * KiROUND * rounds a floating point number to an int using * "round halfway cases away from zero". * In Debug build an assert fires if will not fit into an int. */ #if defined( DEBUG ) // DEBUG: a macro to capture line and file, then calls this inline static inline int KiRound( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); } else if( v < INT_MIN - 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); } return int( v ); } #define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) #else // RELEASE: a macro so compile can pre-compute constants. #define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) #endif //-----</KiROUND KIT>----------------------------------------------------------- // Only a macro is compile time calculated, an inline function causes a static constructor // in a situation like this. // Therefore the Release build is best done with a MACRO not an inline function. int Computed = KiROUND( 14.3 * 8 ); int main( int argc, char** argv ) { for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 ) { int i = KiROUND( d ); printf( "t: %d %.16g\n", i, d ); } return 0; }
14 years ago
18 years ago
18 years ago
19 years ago
19 years ago
// Dick Hollenbeck's KiROUND R&D // This provides better project control over rounding to int from double // than wxRound() did. This scheme provides better logging in Debug builds // and it provides for compile time calculation of constants. #include <stdio.h> #include <assert.h> #include <limits.h> //-----<KiROUND KIT>------------------------------------------------------------ /** * KiROUND * rounds a floating point number to an int using * "round halfway cases away from zero". * In Debug build an assert fires if will not fit into an int. */ #if defined( DEBUG ) // DEBUG: a macro to capture line and file, then calls this inline static inline int KiRound( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); } else if( v < INT_MIN - 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); } return int( v ); } #define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) #else // RELEASE: a macro so compile can pre-compute constants. #define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) #endif //-----</KiROUND KIT>----------------------------------------------------------- // Only a macro is compile time calculated, an inline function causes a static constructor // in a situation like this. // Therefore the Release build is best done with a MACRO not an inline function. int Computed = KiROUND( 14.3 * 8 ); int main( int argc, char** argv ) { for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 ) { int i = KiROUND( d ); printf( "t: %d %.16g\n", i, d ); } return 0; }
14 years ago
// Dick Hollenbeck's KiROUND R&D // This provides better project control over rounding to int from double // than wxRound() did. This scheme provides better logging in Debug builds // and it provides for compile time calculation of constants. #include <stdio.h> #include <assert.h> #include <limits.h> //-----<KiROUND KIT>------------------------------------------------------------ /** * KiROUND * rounds a floating point number to an int using * "round halfway cases away from zero". * In Debug build an assert fires if will not fit into an int. */ #if defined( DEBUG ) // DEBUG: a macro to capture line and file, then calls this inline static inline int KiRound( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); } else if( v < INT_MIN - 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); } return int( v ); } #define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) #else // RELEASE: a macro so compile can pre-compute constants. #define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) #endif //-----</KiROUND KIT>----------------------------------------------------------- // Only a macro is compile time calculated, an inline function causes a static constructor // in a situation like this. // Therefore the Release build is best done with a MACRO not an inline function. int Computed = KiROUND( 14.3 * 8 ); int main( int argc, char** argv ) { for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 ) { int i = KiROUND( d ); printf( "t: %d %.16g\n", i, d ); } return 0; }
14 years ago
// Dick Hollenbeck's KiROUND R&D // This provides better project control over rounding to int from double // than wxRound() did. This scheme provides better logging in Debug builds // and it provides for compile time calculation of constants. #include <stdio.h> #include <assert.h> #include <limits.h> //-----<KiROUND KIT>------------------------------------------------------------ /** * KiROUND * rounds a floating point number to an int using * "round halfway cases away from zero". * In Debug build an assert fires if will not fit into an int. */ #if defined( DEBUG ) // DEBUG: a macro to capture line and file, then calls this inline static inline int KiRound( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); } else if( v < INT_MIN - 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); } return int( v ); } #define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) #else // RELEASE: a macro so compile can pre-compute constants. #define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) #endif //-----</KiROUND KIT>----------------------------------------------------------- // Only a macro is compile time calculated, an inline function causes a static constructor // in a situation like this. // Therefore the Release build is best done with a MACRO not an inline function. int Computed = KiROUND( 14.3 * 8 ); int main( int argc, char** argv ) { for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 ) { int i = KiROUND( d ); printf( "t: %d %.16g\n", i, d ); } return 0; }
14 years ago
19 years ago
18 years ago
16 years ago
18 years ago
18 years ago
18 years ago
16 years ago
16 years ago
15 years ago
16 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2007 Wayne Stambaugh <stambaughw@gmail.com>
  6. * Copyright (C) 1992-2019 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. /**
  26. * @file draw_panel.cpp
  27. */
  28. #include <fctsys.h>
  29. #include <wx/timer.h>
  30. #include <pgm_base.h>
  31. #include <kiface_i.h>
  32. #include <gr_basic.h>
  33. #include <common.h>
  34. #include <macros.h>
  35. #include <id.h>
  36. #include <class_drawpanel.h>
  37. #include <class_draw_panel_gal.h>
  38. #include <base_screen.h>
  39. #include <draw_frame.h>
  40. #include <view/view_controls.h>
  41. #include <gal/gal_display_options.h>
  42. #include <trace_helpers.h>
  43. #include <kicad_device_context.h>
  44. static const int CURSOR_SIZE = 12; ///< Cursor size in pixels
  45. #define CLIP_BOX_PADDING 2
  46. // Definitions for enabling and disabling debugging features in drawpanel.cpp.
  47. // Please don't forget to turn these off before making any commits to Launchpad.
  48. #define DEBUG_SHOW_CLIP_RECT 0 // Set to 1 to draw clipping rectangle.
  49. // Events used by EDA_DRAW_PANEL
  50. BEGIN_EVENT_TABLE( EDA_DRAW_PANEL, wxScrolledWindow )
  51. EVT_LEAVE_WINDOW( EDA_DRAW_PANEL::OnMouseLeaving )
  52. EVT_ENTER_WINDOW( EDA_DRAW_PANEL::OnMouseEntering )
  53. EVT_MOUSEWHEEL( EDA_DRAW_PANEL::OnMouseWheel )
  54. #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
  55. EVT_MAGNIFY( EDA_DRAW_PANEL::OnMagnify )
  56. #endif
  57. EVT_MOUSE_EVENTS( EDA_DRAW_PANEL::OnMouseEvent )
  58. EVT_CHAR( EDA_DRAW_PANEL::OnKeyEvent )
  59. EVT_CHAR_HOOK( EDA_DRAW_PANEL::OnKeyEvent )
  60. EVT_PAINT( EDA_DRAW_PANEL::OnPaint )
  61. EVT_ERASE_BACKGROUND( EDA_DRAW_PANEL::OnEraseBackground )
  62. EVT_SCROLLWIN( EDA_DRAW_PANEL::OnScroll )
  63. EVT_ACTIVATE( EDA_DRAW_PANEL::OnActivate )
  64. EVT_TIMER( ID_MOUSE_DOUBLECLICK, EDA_DRAW_PANEL::OnTimer )
  65. EVT_MENU_RANGE( ID_PAN_UP, ID_PAN_RIGHT, EDA_DRAW_PANEL::OnPan )
  66. END_EVENT_TABLE()
  67. /***********************************************************************/
  68. /* EDA_DRAW_PANEL base functions (EDA_DRAW_PANEL is the main panel)*/
  69. /***********************************************************************/
  70. #ifdef __WXMAC__
  71. const int drawPanelStyle = wxHSCROLL | wxVSCROLL | wxALWAYS_SHOW_SB;
  72. #else
  73. const int drawPanelStyle = wxHSCROLL | wxVSCROLL;
  74. #endif
  75. EDA_DRAW_PANEL::EDA_DRAW_PANEL( EDA_DRAW_FRAME* parent, int id,
  76. const wxPoint& pos, const wxSize& size ) :
  77. wxScrolledWindow( parent, id, pos, size, drawPanelStyle )
  78. {
  79. wxASSERT( parent );
  80. ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS );
  81. DisableKeyboardScrolling();
  82. m_scrollIncrementX = std::min( size.x / 8, 10 );
  83. m_scrollIncrementY = std::min( size.y / 8, 10 );
  84. SetLayoutDirection( wxLayout_LeftToRight );
  85. SetBackgroundColour( parent->GetDrawBgColor().ToColour() );
  86. #if KICAD_USE_BUFFERED_DC || KICAD_USE_BUFFERED_PAINTDC
  87. SetBackgroundStyle( wxBG_STYLE_CUSTOM );
  88. #endif
  89. m_ClipBox.SetSize( size );
  90. m_ClipBox.SetX( 0 );
  91. m_ClipBox.SetY( 0 );
  92. m_canStartBlock = -1; // Command block can start if >= 0
  93. m_abortRequest = false;
  94. m_enableMousewheelPan = false;
  95. m_enableZoomNoCenter = false;
  96. m_enableAutoPan = true;
  97. m_ignoreMouseEvents = false;
  98. // Be sure a mouse release button event will be ignored when creating the canvas
  99. // if the mouse click was not made inside the canvas (can happen sometimes, when
  100. // launching a editor from a double click made in another frame)
  101. m_ignoreNextLeftButtonRelease = true;
  102. m_mouseCaptureCallback = NULL;
  103. m_endMouseCaptureCallback = NULL;
  104. Pgm().CommonSettings()->Read( ENBL_MOUSEWHEEL_PAN_KEY, &m_enableMousewheelPan, false );
  105. Pgm().CommonSettings()->Read( ENBL_ZOOM_NO_CENTER_KEY, &m_enableZoomNoCenter, false );
  106. Pgm().CommonSettings()->Read( ENBL_AUTO_PAN_KEY, &m_enableAutoPan, true );
  107. m_requestAutoPan = false;
  108. m_enableBlockCommands = false;
  109. m_minDragEventCount = 0;
  110. #ifdef __WXMAC__
  111. m_defaultCursor = m_currentCursor = wxCURSOR_CROSS;
  112. m_showCrossHair = false;
  113. #else
  114. m_defaultCursor = m_currentCursor = wxCURSOR_ARROW;
  115. m_showCrossHair = true;
  116. #endif
  117. m_cursorLevel = 0;
  118. m_PrintIsMirrored = false;
  119. m_ClickTimer = (wxTimer*) NULL;
  120. m_doubleClickInterval = 250;
  121. }
  122. EDA_DRAW_PANEL::~EDA_DRAW_PANEL()
  123. {
  124. wxConfigBase* cfg = Kiface().KifaceSettings();
  125. if( cfg )
  126. {
  127. cfg->Write( ENBL_MOUSEWHEEL_PAN_KEY, m_enableMousewheelPan );
  128. cfg->Write( ENBL_ZOOM_NO_CENTER_KEY, m_enableZoomNoCenter );
  129. cfg->Write( ENBL_AUTO_PAN_KEY, m_enableAutoPan );
  130. }
  131. wxDELETE( m_ClickTimer );
  132. }
  133. EDA_DRAW_FRAME* EDA_DRAW_PANEL::GetParent() const
  134. {
  135. wxWindow* mom = wxScrolledWindow::GetParent();
  136. return (EDA_DRAW_FRAME*) mom;
  137. }
  138. void* EDA_DRAW_PANEL::GetDisplayOptions()
  139. {
  140. return GetParent()->GetDisplayOptions();
  141. }
  142. BASE_SCREEN* EDA_DRAW_PANEL::GetScreen()
  143. {
  144. EDA_DRAW_FRAME* parentFrame = GetParent();
  145. return parentFrame->GetScreen();
  146. }
  147. wxPoint EDA_DRAW_PANEL::ToDeviceXY( const wxPoint& pos )
  148. {
  149. wxPoint ret;
  150. INSTALL_UNBUFFERED_DC( dc, this );
  151. ret.x = dc.LogicalToDeviceX( pos.x );
  152. ret.y = dc.LogicalToDeviceY( pos.y );
  153. return ret;
  154. }
  155. wxPoint EDA_DRAW_PANEL::ToLogicalXY( const wxPoint& pos )
  156. {
  157. wxPoint ret;
  158. INSTALL_UNBUFFERED_DC( dc, this );
  159. ret.x = dc.DeviceToLogicalX( pos.x );
  160. ret.y = dc.DeviceToLogicalY( pos.y );
  161. return ret;
  162. }
  163. void EDA_DRAW_PANEL::DrawCrossHair( wxDC* aDC, COLOR4D aColor )
  164. {
  165. if( m_cursorLevel != 0 || aDC == NULL || !m_showCrossHair )
  166. return;
  167. wxPoint cursor = GetParent()->GetCrossHairPosition();
  168. #ifdef USE_WX_GRAPHICS_CONTEXT
  169. // Normally cursor color is set to white, so when it is xored with white
  170. // background, it is painted black effectively. wxGraphicsContext does not have
  171. // xor operation, so we need to invert the color manually.
  172. aColor.Invert();
  173. #else
  174. GRSetDrawMode( aDC, GR_XOR );
  175. #endif
  176. if( GetParent()->GetGalDisplayOptions().m_fullscreenCursor )
  177. {
  178. wxSize clientSize = GetClientSize();
  179. // Y axis
  180. wxPoint lineStart( cursor.x, aDC->DeviceToLogicalY( 0 ) );
  181. wxPoint lineEnd( cursor.x, aDC->DeviceToLogicalY( clientSize.y ) );
  182. GRLine( &m_ClipBox, aDC, lineStart, lineEnd, 0, aColor );
  183. // X axis
  184. lineStart = wxPoint( aDC->DeviceToLogicalX( 0 ), cursor.y );
  185. lineEnd = wxPoint( aDC->DeviceToLogicalX( clientSize.x ), cursor.y );
  186. GRLine( &m_ClipBox, aDC, lineStart, lineEnd, 0, aColor );
  187. }
  188. else
  189. {
  190. int len = aDC->DeviceToLogicalXRel( CURSOR_SIZE );
  191. GRLine( &m_ClipBox, aDC, cursor.x - len, cursor.y,
  192. cursor.x + len, cursor.y, 0, aColor );
  193. GRLine( &m_ClipBox, aDC, cursor.x, cursor.y - len,
  194. cursor.x, cursor.y + len, 0, aColor );
  195. }
  196. }
  197. void EDA_DRAW_PANEL::CrossHairOff( wxDC* DC )
  198. {
  199. DrawCrossHair( DC );
  200. --m_cursorLevel;
  201. }
  202. void EDA_DRAW_PANEL::CrossHairOn( wxDC* DC )
  203. {
  204. ++m_cursorLevel;
  205. DrawCrossHair( DC );
  206. if( m_cursorLevel > 0 ) // Shouldn't happen, but just in case ..
  207. m_cursorLevel = 0;
  208. }
  209. double EDA_DRAW_PANEL::GetZoom()
  210. {
  211. return GetScreen()->GetZoom();
  212. }
  213. void EDA_DRAW_PANEL::SetZoom( double zoom )
  214. {
  215. GetScreen()->SetZoom( zoom );
  216. }
  217. wxRealPoint EDA_DRAW_PANEL::GetGrid()
  218. {
  219. return GetScreen()->GetGridSize();
  220. }
  221. bool EDA_DRAW_PANEL::IsPointOnDisplay( const wxPoint& aPosition )
  222. {
  223. wxPoint pos;
  224. EDA_RECT display_rect;
  225. INSTALL_UNBUFFERED_DC( dc, this ); // Refresh the clip box to the entire screen size.
  226. SetClipBox( dc );
  227. display_rect = m_ClipBox;
  228. // Slightly decreased the size of the useful screen area to avoid drawing limits.
  229. #define PIXEL_MARGIN 8
  230. display_rect.Inflate( -PIXEL_MARGIN );
  231. return display_rect.Contains( aPosition );
  232. }
  233. void EDA_DRAW_PANEL::RefreshDrawingRect( const EDA_RECT& aRect, bool aEraseBackground )
  234. {
  235. INSTALL_UNBUFFERED_DC( dc, this );
  236. wxRect rect = aRect;
  237. rect.x = dc.LogicalToDeviceX( rect.x );
  238. rect.y = dc.LogicalToDeviceY( rect.y );
  239. rect.width = dc.LogicalToDeviceXRel( rect.width );
  240. rect.height = dc.LogicalToDeviceYRel( rect.height );
  241. wxLogTrace( kicadTraceCoords,
  242. wxT( "Refresh area: drawing (%d, %d, %d, %d), device (%d, %d, %d, %d)" ),
  243. aRect.GetX(), aRect.GetY(), aRect.GetWidth(), aRect.GetHeight(),
  244. rect.x, rect.y, rect.width, rect.height );
  245. RefreshRect( rect, aEraseBackground );
  246. }
  247. void EDA_DRAW_PANEL::Refresh( bool eraseBackground, const wxRect* rect )
  248. {
  249. if( GetParent()->IsGalCanvasActive() )
  250. {
  251. GetParent()->GetGalCanvas()->Refresh();
  252. }
  253. else
  254. {
  255. wxScrolledWindow::Refresh( eraseBackground, rect );
  256. }
  257. }
  258. wxPoint EDA_DRAW_PANEL::GetScreenCenterLogicalPosition()
  259. {
  260. wxSize size = GetClientSize() / 2;
  261. INSTALL_UNBUFFERED_DC( dc, this );
  262. return wxPoint( dc.DeviceToLogicalX( size.x ), dc.DeviceToLogicalY( size.y ) );
  263. }
  264. void EDA_DRAW_PANEL::MoveCursorToCrossHair()
  265. {
  266. MoveCursor( GetParent()->GetCrossHairPosition() );
  267. }
  268. void EDA_DRAW_PANEL::MoveCursor( const wxPoint& aPosition )
  269. {
  270. if( GetParent()->IsGalCanvasActive() )
  271. return;
  272. int x, y, xPpu, yPpu;
  273. wxPoint screenPos, drawingPos;
  274. wxRect clientRect( wxPoint( 0, 0 ), GetClientSize() );
  275. INSTALL_UNBUFFERED_DC( dc, this );
  276. screenPos.x = dc.LogicalToDeviceX( aPosition.x );
  277. screenPos.y = dc.LogicalToDeviceY( aPosition.y );
  278. // Scroll if the requested mouse position cursor is outside the drawing area.
  279. if( !clientRect.Contains( screenPos ) )
  280. {
  281. GetViewStart( &x, &y );
  282. GetScrollPixelsPerUnit( &xPpu, &yPpu );
  283. CalcUnscrolledPosition( screenPos.x, screenPos.y, &drawingPos.x, &drawingPos.y );
  284. wxLogTrace( kicadTraceCoords,
  285. wxT( "MoveCursor() initial screen position(%d, %d) " ) \
  286. wxT( "rectangle(%d, %d, %d, %d) view(%d, %d)" ),
  287. screenPos.x, screenPos.y, clientRect.x, clientRect.y,
  288. clientRect.width, clientRect.height, x, y );
  289. if( screenPos.y < clientRect.GetTop() )
  290. y -= m_scrollIncrementY * yPpu;
  291. else if( screenPos.y > clientRect.GetBottom() )
  292. y += m_scrollIncrementY * yPpu;
  293. else if( clientRect.GetRight() < screenPos.x )
  294. x += m_scrollIncrementX * xPpu;
  295. else
  296. x -= m_scrollIncrementX * xPpu;
  297. Scroll( x, y );
  298. CalcScrolledPosition( drawingPos.x, drawingPos.y, &screenPos.x, &screenPos.y );
  299. wxLogTrace( kicadTraceCoords,
  300. wxT( "MoveCursor() scrolled screen position(%d, %d) view(%d, %d)" ),
  301. screenPos.x, screenPos.y, x, y );
  302. }
  303. WarpPointer( screenPos.x, screenPos.y );
  304. }
  305. void EDA_DRAW_PANEL::OnActivate( wxActivateEvent& event )
  306. {
  307. m_canStartBlock = -1; // Block Command can't start
  308. event.Skip();
  309. }
  310. void EDA_DRAW_PANEL::OnTimer( wxTimerEvent& event )
  311. {
  312. INSTALL_UNBUFFERED_DC( DC, this );
  313. DC.SetBackground( *wxBLACK_BRUSH );
  314. GetParent()->OnLeftClick( &DC, m_CursorClickPos );
  315. }
  316. void EDA_DRAW_PANEL::OnScroll( wxScrollWinEvent& event )
  317. {
  318. int id = event.GetEventType();
  319. int x, y;
  320. int ppux, ppuy;
  321. int csizeX, csizeY;
  322. int unitsX, unitsY;
  323. GetViewStart( &x, &y );
  324. GetScrollPixelsPerUnit( &ppux, &ppuy );
  325. GetClientSize( &csizeX, &csizeY );
  326. GetVirtualSize( &unitsX, &unitsY );
  327. int tmpX = x;
  328. int tmpY = y;
  329. csizeX /= ppux;
  330. csizeY /= ppuy;
  331. unitsX /= ppux;
  332. unitsY /= ppuy;
  333. int dir = event.GetOrientation(); // wxHORIZONTAL or wxVERTICAL
  334. // On windows and on wxWidgets >= 2.9.5 and < 3.1,
  335. // there is a bug in mousewheel event which always generates 2 scroll events
  336. // (should be the case only for the default mousewheel event)
  337. // with id = wxEVT_SCROLLWIN_LINEUP or wxEVT_SCROLLWIN_LINEDOWN
  338. // so we skip these events.
  339. // Note they are here just in case, because they are not actually used
  340. // in Kicad
  341. #if wxCHECK_VERSION( 3, 1, 0 ) || !wxCHECK_VERSION( 2, 9, 5 ) || ( !defined (__WINDOWS__) && !defined (__WXMAC__) )
  342. int maxX = unitsX - csizeX;
  343. int maxY = unitsY - csizeY;
  344. if( id == wxEVT_SCROLLWIN_LINEUP )
  345. {
  346. if( dir == wxHORIZONTAL )
  347. {
  348. x -= m_scrollIncrementX;
  349. if( x < 0 )
  350. x = 0;
  351. }
  352. else
  353. {
  354. y -= m_scrollIncrementY;
  355. if( y < 0 )
  356. y = 0;
  357. }
  358. }
  359. else if( id == wxEVT_SCROLLWIN_LINEDOWN )
  360. {
  361. if( dir == wxHORIZONTAL )
  362. {
  363. x += m_scrollIncrementX;
  364. if( x > maxX )
  365. x = maxX;
  366. }
  367. else
  368. {
  369. y += m_scrollIncrementY;
  370. if( y > maxY )
  371. y = maxY;
  372. }
  373. }
  374. else
  375. #endif
  376. if( id == wxEVT_SCROLLWIN_THUMBTRACK )
  377. {
  378. if( dir == wxHORIZONTAL )
  379. x = event.GetPosition();
  380. else
  381. y = event.GetPosition();
  382. }
  383. else
  384. {
  385. event.Skip();
  386. return;
  387. }
  388. wxLogTrace( kicadTraceCoords,
  389. wxT( "Setting scroll bars ppuX=%d, ppuY=%d, unitsX=%d, unitsY=%d, posX=%d, posY=%d" ),
  390. ppux, ppuy, unitsX, unitsY, x, y );
  391. double scale = GetParent()->GetScreen()->GetScalingFactor();
  392. wxPoint center = GetParent()->GetScrollCenterPosition();
  393. center.x += KiROUND( (double) ( x - tmpX ) / scale );
  394. center.y += KiROUND( (double) ( y - tmpY ) / scale );
  395. GetParent()->SetScrollCenterPosition( center );
  396. Scroll( x, y );
  397. event.Skip();
  398. }
  399. void EDA_DRAW_PANEL::SetClipBox( wxDC& aDC, const wxRect* aRect )
  400. {
  401. wxRect clipBox;
  402. // Use the entire visible device area if no clip area was defined.
  403. if( aRect == NULL )
  404. {
  405. BASE_SCREEN* Screen = GetScreen();
  406. if( !Screen )
  407. return;
  408. Screen->m_StartVisu = CalcUnscrolledPosition( wxPoint( 0, 0 ) );
  409. clipBox.SetSize( GetClientSize() );
  410. int scrollX, scrollY;
  411. double scalar = Screen->GetScalingFactor();
  412. scrollX = KiROUND( Screen->GetGridSize().x * scalar );
  413. scrollY = KiROUND( Screen->GetGridSize().y * scalar );
  414. m_scrollIncrementX = std::max( GetClientSize().x / 8, scrollX );
  415. m_scrollIncrementY = std::max( GetClientSize().y / 8, scrollY );
  416. Screen->m_ScrollbarPos.x = GetScrollPos( wxHORIZONTAL );
  417. Screen->m_ScrollbarPos.y = GetScrollPos( wxVERTICAL );
  418. }
  419. else
  420. {
  421. clipBox = *aRect;
  422. }
  423. // Pad clip box in device units.
  424. clipBox.Inflate( CLIP_BOX_PADDING );
  425. // Convert from device units to drawing units.
  426. m_ClipBox.SetOrigin( wxPoint( aDC.DeviceToLogicalX( clipBox.x ),
  427. aDC.DeviceToLogicalY( clipBox.y ) ) );
  428. m_ClipBox.SetSize( wxSize( aDC.DeviceToLogicalXRel( clipBox.width ),
  429. aDC.DeviceToLogicalYRel( clipBox.height ) ) );
  430. wxLogTrace( kicadTraceCoords,
  431. wxT( "Device clip box=(%d, %d, %d, %d), Logical clip box=(%d, %d, %d, %d)" ),
  432. clipBox.x, clipBox.y, clipBox.width, clipBox.height,
  433. m_ClipBox.GetX(), m_ClipBox.GetY(), m_ClipBox.GetWidth(), m_ClipBox.GetHeight() );
  434. }
  435. void EDA_DRAW_PANEL::EraseScreen( wxDC* DC )
  436. {
  437. GRSetDrawMode( DC, GR_COPY );
  438. COLOR4D bgColor = GetParent()->GetDrawBgColor();
  439. GRSFilledRect( NULL, DC, m_ClipBox.GetX(), m_ClipBox.GetY(),
  440. m_ClipBox.GetRight(), m_ClipBox.GetBottom(),
  441. 0, bgColor, bgColor );
  442. // Set to one (1) to draw bounding box validate bounding box calculation.
  443. #if DEBUG_SHOW_CLIP_RECT
  444. EDA_RECT bBox = m_ClipBox;
  445. GRRect( NULL, DC, bBox.GetOrigin().x, bBox.GetOrigin().y,
  446. bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA );
  447. #endif
  448. }
  449. void EDA_DRAW_PANEL::DoPrepareDC( wxDC& dc )
  450. {
  451. wxScrolledWindow::DoPrepareDC( dc );
  452. if( GetScreen() != NULL )
  453. {
  454. double scale = GetScreen()->GetScalingFactor();
  455. dc.SetUserScale( scale, scale );
  456. wxPoint pt = GetScreen()->m_DrawOrg;
  457. dc.SetLogicalOrigin( pt.x, pt.y );
  458. }
  459. SetClipBox( dc ); // Reset the clip box to the entire screen.
  460. GRResetPenAndBrush( &dc );
  461. dc.SetBackgroundMode( wxTRANSPARENT );
  462. }
  463. void EDA_DRAW_PANEL::OnPaint( wxPaintEvent& event )
  464. {
  465. if( GetScreen() == NULL )
  466. {
  467. event.Skip();
  468. return;
  469. }
  470. INSTALL_PAINTDC( paintDC, this );
  471. wxRect region = GetUpdateRegion().GetBox();
  472. SetClipBox( paintDC, &region );
  473. ReDraw( &paintDC, true );
  474. }
  475. void EDA_DRAW_PANEL::ReDraw( wxDC* DC, bool erasebg )
  476. {
  477. BASE_SCREEN* Screen = GetScreen();
  478. if( Screen == NULL )
  479. return;
  480. COLOR4D bgColor = GetParent()->GetDrawBgColor();
  481. // TODO(JE): Is this correct?
  482. if( bgColor.GetBrightness() > 0.5 )
  483. {
  484. g_XorMode = GR_NXOR;
  485. g_GhostColor = BLACK;
  486. }
  487. else
  488. {
  489. g_XorMode = GR_XOR;
  490. g_GhostColor = WHITE;
  491. }
  492. GRResetPenAndBrush( DC );
  493. DC->SetBackground( wxBrush( bgColor.ToColour() ) );
  494. DC->SetBackgroundMode( wxSOLID );
  495. if( erasebg )
  496. EraseScreen( DC );
  497. GetParent()->RedrawActiveWindow( DC, erasebg );
  498. // Verfies that the clipping is working correctly. If these two sets of numbers are
  499. // not the same or really close. The clipping algorithms are broken.
  500. wxLogTrace( kicadTraceCoords,
  501. wxT( "Clip box: (%d, %d, %d, %d), Draw extents (%d, %d, %d, %d)" ),
  502. m_ClipBox.GetX(), m_ClipBox.GetY(), m_ClipBox.GetRight(), m_ClipBox.GetBottom(),
  503. DC->MinX(), DC->MinY(), DC->MaxX(), DC->MaxY() );
  504. }
  505. void EDA_DRAW_PANEL::SetEnableMousewheelPan( bool aEnable )
  506. {
  507. m_enableMousewheelPan = aEnable;
  508. if( GetParent()->IsGalCanvasActive() )
  509. GetParent()->GetGalCanvas()->GetViewControls()->EnableMousewheelPan( aEnable );
  510. }
  511. void EDA_DRAW_PANEL::SetEnableAutoPan( bool aEnable )
  512. {
  513. m_enableAutoPan = aEnable;
  514. if( GetParent()->IsGalCanvasActive() )
  515. GetParent()->GetGalCanvas()->GetViewControls()->EnableAutoPan( aEnable );
  516. }
  517. void EDA_DRAW_PANEL::SetEnableZoomNoCenter( bool aEnable )
  518. {
  519. m_enableZoomNoCenter = aEnable;
  520. if( GetParent()->IsGalCanvasActive() )
  521. GetParent()->GetGalCanvas()->GetViewControls()->EnableCursorWarping( !aEnable );
  522. }
  523. void EDA_DRAW_PANEL::DrawBackGround( wxDC* DC )
  524. {
  525. GRSetDrawMode( DC, GR_COPY );
  526. if( GetParent()->IsGridVisible() )
  527. DrawGrid( DC );
  528. // Draw axis
  529. if( GetParent()->GetShowAxis() )
  530. {
  531. COLOR4D axis_color = COLOR4D( BLUE );
  532. wxSize pageSize = GetParent()->GetPageSizeIU();
  533. // Draw the Y axis
  534. GRLine( &m_ClipBox, DC, 0, -pageSize.y, 0, pageSize.y, 0, axis_color );
  535. // Draw the X axis
  536. GRLine( &m_ClipBox, DC, -pageSize.x, 0, pageSize.x, 0, 0, axis_color );
  537. }
  538. if( GetParent()->GetShowOriginAxis() )
  539. DrawAuxiliaryAxis( DC, GR_COPY );
  540. if( GetParent()->GetShowGridAxis() )
  541. DrawGridAxis( DC, GR_COPY, GetParent()->GetGridOrigin() );
  542. }
  543. void EDA_DRAW_PANEL::DrawGrid( wxDC* aDC )
  544. {
  545. #define MIN_GRID_SIZE 10 // min grid size in pixels to allow drawing
  546. BASE_SCREEN* screen = GetScreen();
  547. wxRealPoint gridSize;
  548. wxSize screenSize;
  549. wxPoint org;
  550. wxRealPoint screenGridSize;
  551. /* The grid must be visible. this is possible only is grid value
  552. * and zoom value are sufficient
  553. */
  554. gridSize = screen->GetGridSize();
  555. screen->m_StartVisu = CalcUnscrolledPosition( wxPoint( 0, 0 ) );
  556. screenSize = GetClientSize();
  557. screenGridSize.x = aDC->LogicalToDeviceXRel( KiROUND( gridSize.x ) );
  558. screenGridSize.y = aDC->LogicalToDeviceYRel( KiROUND( gridSize.y ) );
  559. org = m_ClipBox.GetPosition();
  560. if( screenGridSize.x < MIN_GRID_SIZE || screenGridSize.y < MIN_GRID_SIZE )
  561. {
  562. screenGridSize.x *= 2.0;
  563. screenGridSize.y *= 2.0;
  564. gridSize.x *= 2.0;
  565. gridSize.y *= 2.0;
  566. }
  567. if( screenGridSize.x < MIN_GRID_SIZE || screenGridSize.y < MIN_GRID_SIZE )
  568. return;
  569. org = GetParent()->GetNearestGridPosition( org, &gridSize );
  570. // Setting the nearest grid position can select grid points outside the clip box.
  571. // Incrementing the start point by one grid step should prevent drawing grid points
  572. // outside the clip box.
  573. if( org.x < m_ClipBox.GetX() )
  574. org.x += KiROUND( gridSize.x );
  575. if( org.y < m_ClipBox.GetY() )
  576. org.y += KiROUND( gridSize.y );
  577. // Use a pixel based draw to display grid. There are a lot of calls, so the cost is
  578. // high and grid is slowly drawn on some platforms. Another way using blit transfert was used,
  579. // a long time ago, but it did not give very good results.
  580. // The better way is highly dependent on the platform and the graphic card.
  581. int xpos;
  582. double right = ( double ) m_ClipBox.GetRight();
  583. double bottom = ( double ) m_ClipBox.GetBottom();
  584. #if defined( USE_WX_GRAPHICS_CONTEXT )
  585. wxGCDC *gcdc = wxDynamicCast( aDC, wxGCDC );
  586. if( gcdc )
  587. {
  588. // Much faster grid drawing on systems using wxGraphicsContext
  589. wxGraphicsContext *gc = gcdc->GetGraphicsContext();
  590. // Grid point size
  591. const int gsz = 1;
  592. const double w = aDC->DeviceToLogicalXRel( gsz );
  593. const double h = aDC->DeviceToLogicalYRel( gsz );
  594. // Use our own pen
  595. wxPen pen( GetParent()->GetGridColor().ToColour(), h );
  596. pen.SetCap( wxCAP_BUTT );
  597. gc->SetPen( pen );
  598. // draw grid
  599. wxGraphicsPath path = gc->CreatePath();
  600. for( double x = (double) org.x - w/2.0; x <= right - w/2.0; x += gridSize.x )
  601. {
  602. for( double y = (double) org.y; y <= bottom; y += gridSize.y )
  603. {
  604. path.MoveToPoint( x, y );
  605. path.AddLineToPoint( x+w, y );
  606. }
  607. }
  608. gc->StrokePath( path );
  609. }
  610. else
  611. #endif
  612. {
  613. GRSetColorPen( aDC, GetParent()->GetGridColor() );
  614. for( double x = (double) org.x; x <= right; x += gridSize.x )
  615. {
  616. xpos = KiROUND( x );
  617. for( double y = (double) org.y; y <= bottom; y += gridSize.y )
  618. {
  619. aDC->DrawPoint( xpos, KiROUND( y ) );
  620. }
  621. }
  622. }
  623. }
  624. // Set to 1 to draw auxirilary axis as lines, 0 to draw as target (circle with cross)
  625. #define DRAW_AXIS_AS_LINES 0
  626. // Size in pixels of the target shape
  627. #define AXIS_SIZE_IN_PIXELS 15
  628. void EDA_DRAW_PANEL::DrawAuxiliaryAxis( wxDC* aDC, GR_DRAWMODE aDrawMode )
  629. {
  630. wxPoint origin = GetParent()->GetAuxOrigin();
  631. if( origin == wxPoint( 0, 0 ) )
  632. return;
  633. COLOR4D color = COLOR4D( RED );
  634. GRSetDrawMode( aDC, aDrawMode );
  635. #if DRAW_AXIS_AS_LINES
  636. wxSize pageSize = GetParent()->GetPageSizeIU();
  637. // Draw the Y axis
  638. GRLine( &m_ClipBox, aDC, origin.x, -pageSize.y,
  639. origin.x, pageSize.y, 0, color );
  640. // Draw the X axis
  641. GRLine( &m_ClipBox, aDC, -pageSize.x, origin.y,
  642. pageSize.x, origin.y, 0, color );
  643. #else
  644. int radius = aDC->DeviceToLogicalXRel( AXIS_SIZE_IN_PIXELS );
  645. int linewidth = aDC->DeviceToLogicalXRel( 1 );
  646. GRSetColorPen( aDC, color, linewidth );
  647. GRLine( &m_ClipBox, aDC, origin.x, origin.y-radius,
  648. origin.x, origin.y+radius, 0, color );
  649. // Draw the + shape
  650. GRLine( &m_ClipBox, aDC, origin.x-radius, origin.y,
  651. origin.x+radius, origin.y, 0, color );
  652. GRCircle( &m_ClipBox, aDC, origin, radius, linewidth, color );
  653. #endif
  654. }
  655. void EDA_DRAW_PANEL::DrawGridAxis( wxDC* aDC, GR_DRAWMODE aDrawMode, const wxPoint& aGridOrigin )
  656. {
  657. if( !GetParent()->GetShowGridAxis() || ( !aGridOrigin.x && !aGridOrigin.y ) )
  658. return;
  659. COLOR4D color = GetParent()->GetGridColor();
  660. GRSetDrawMode( aDC, aDrawMode );
  661. #if DRAW_AXIS_AS_LINES
  662. wxSize pageSize = GetParent()->GetPageSizeIU();
  663. // Draw the Y axis
  664. GRLine( &m_ClipBox, aDC, aGridOrigin.x, -pageSize.y,
  665. aGridOrigin.x, pageSize.y, 0, color );
  666. // Draw the X axis
  667. GRLine( &m_ClipBox, aDC, -pageSize.x, aGridOrigin.y,
  668. pageSize.x, aGridOrigin.y, 0, color );
  669. #else
  670. int radius = aDC->DeviceToLogicalXRel( AXIS_SIZE_IN_PIXELS );
  671. int linewidth = aDC->DeviceToLogicalXRel( 1 );
  672. GRSetColorPen( aDC, GetParent()->GetGridColor(), linewidth );
  673. GRLine( &m_ClipBox, aDC, aGridOrigin.x-radius, aGridOrigin.y-radius,
  674. aGridOrigin.x+radius, aGridOrigin.y+radius, 0, color );
  675. // Draw the X shape
  676. GRLine( &m_ClipBox, aDC, aGridOrigin.x+radius, aGridOrigin.y-radius,
  677. aGridOrigin.x-radius, aGridOrigin.y+radius, 0, color );
  678. GRCircle( &m_ClipBox, aDC, aGridOrigin, radius, linewidth, color );
  679. #endif
  680. }
  681. bool EDA_DRAW_PANEL::OnRightClick( wxMouseEvent& event )
  682. {
  683. wxPoint pos;
  684. wxMenu MasterMenu;
  685. INSTALL_UNBUFFERED_DC( dc, this );
  686. pos = event.GetLogicalPosition( dc );
  687. if( !GetParent()->OnRightClick( pos, &MasterMenu ) )
  688. return false;
  689. GetParent()->AddMenuZoomAndGrid( &MasterMenu );
  690. pos = event.GetPosition();
  691. m_ignoreMouseEvents = true;
  692. PopupMenu( &MasterMenu, pos );
  693. // The ZoomAndGrid menu is only invoked over empty space so there's no point in warping
  694. // the cursor back to the crosshair, and it's very annoying if one clicked out of the menu.
  695. m_ignoreMouseEvents = false;
  696. return true;
  697. }
  698. void EDA_DRAW_PANEL::OnMouseEntering( wxMouseEvent& aEvent )
  699. {
  700. // This is an ugly hack that fixes some cross hair display bugs when the mouse leaves the
  701. // canvas area during middle button mouse panning.
  702. if( m_cursorLevel != 0 )
  703. m_cursorLevel = 0;
  704. aEvent.Skip();
  705. }
  706. void EDA_DRAW_PANEL::OnMouseLeaving( wxMouseEvent& event )
  707. {
  708. if( m_mouseCaptureCallback == NULL ) // No command in progress.
  709. SetAutoPanRequest( false );
  710. if( !m_enableAutoPan || !m_requestAutoPan || m_ignoreMouseEvents )
  711. return;
  712. // Auto pan when mouse has left the client window
  713. // Ensure the cross_hair position is updated,
  714. // because it will be used to center the screen.
  715. // We use a position inside the client window
  716. wxRect area( wxPoint( 0, 0 ), GetClientSize() );
  717. wxPoint cross_hair_pos = event.GetPosition();
  718. // Certain window managers (e.g. awesome wm) incorrectly trigger "on leave" event,
  719. // therefore test if the cursor has really left the panel area
  720. if( !area.Contains( cross_hair_pos ) )
  721. {
  722. INSTALL_UNBUFFERED_DC( dc, this );
  723. cross_hair_pos.x = dc.DeviceToLogicalX( cross_hair_pos.x );
  724. cross_hair_pos.y = dc.DeviceToLogicalY( cross_hair_pos.y );
  725. GetParent()->SetCrossHairPosition( cross_hair_pos );
  726. wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED, ID_POPUP_ZOOM_CENTER );
  727. cmd.SetEventObject( this );
  728. GetEventHandler()->ProcessEvent( cmd );
  729. }
  730. event.Skip();
  731. }
  732. void EDA_DRAW_PANEL::OnMouseWheel( wxMouseEvent& event )
  733. {
  734. if( m_ignoreMouseEvents )
  735. return;
  736. wxRect rect = wxRect( wxPoint( 0, 0 ), GetClientSize() );
  737. // Ignore scroll events if the cursor is outside the drawing area.
  738. if( event.GetWheelRotation() == 0 || !GetParent()->IsEnabled()
  739. || !rect.Contains( event.GetPosition() ) )
  740. {
  741. wxLogTrace( kicadTraceCoords,
  742. wxT( "OnMouseWheel() position(%d, %d) rectangle(%d, %d, %d, %d)" ),
  743. event.GetPosition().x, event.GetPosition().y,
  744. rect.x, rect.y, rect.width, rect.height );
  745. event.Skip();
  746. return;
  747. }
  748. INSTALL_UNBUFFERED_DC( dc, this );
  749. GetParent()->SetCrossHairPosition( event.GetLogicalPosition( dc ) );
  750. wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
  751. cmd.SetEventObject( this );
  752. bool offCenterReq = event.ControlDown() && event.ShiftDown();
  753. offCenterReq = offCenterReq || m_enableZoomNoCenter;
  754. int axis = event.GetWheelAxis();
  755. int wheelRotation = event.GetWheelRotation();
  756. if( m_enableMousewheelPan )
  757. {
  758. // MousewheelPAN + Ctrl = zooming
  759. if( event.ControlDown() && !event.ShiftDown() )
  760. {
  761. if( wheelRotation > 0 )
  762. cmd.SetId( ID_POPUP_ZOOM_IN );
  763. else if( wheelRotation < 0)
  764. cmd.SetId( ID_POPUP_ZOOM_OUT );
  765. }
  766. // MousewheelPAN + Shift = horizontal scrolling
  767. // Without modifiers MousewheelPAN - just pan
  768. else
  769. {
  770. if( event.ShiftDown() && !event.ControlDown() )
  771. axis = wxMOUSE_WHEEL_HORIZONTAL;
  772. wxPoint newStart = GetViewStart();
  773. wxPoint center = GetParent()->GetScrollCenterPosition();
  774. double scale = GetParent()->GetScreen()->GetScalingFactor();
  775. if( axis == wxMOUSE_WHEEL_HORIZONTAL )
  776. {
  777. newStart.x += wheelRotation;
  778. center.x += KiROUND( (double) wheelRotation / scale );
  779. }
  780. else
  781. {
  782. newStart.y -= wheelRotation;
  783. center.y -= KiROUND( (double) wheelRotation / scale );
  784. }
  785. Scroll( newStart );
  786. GetParent()->SetScrollCenterPosition( center );
  787. GetParent()->SetCrossHairPosition( center, true );
  788. GetParent()->RedrawScreen( center, false );
  789. }
  790. }
  791. else if( wheelRotation > 0 )
  792. {
  793. if( event.ShiftDown() && !event.ControlDown() )
  794. cmd.SetId( ID_PAN_UP );
  795. else if( event.ControlDown() && !event.ShiftDown() )
  796. cmd.SetId( ID_PAN_LEFT );
  797. else if( offCenterReq )
  798. cmd.SetId( ID_OFFCENTER_ZOOM_IN );
  799. else
  800. cmd.SetId( ID_POPUP_ZOOM_IN );
  801. }
  802. else if( wheelRotation < 0 )
  803. {
  804. if( event.ShiftDown() && !event.ControlDown() )
  805. cmd.SetId( ID_PAN_DOWN );
  806. else if( event.ControlDown() && !event.ShiftDown() )
  807. cmd.SetId( ID_PAN_RIGHT );
  808. else if( offCenterReq )
  809. cmd.SetId( ID_OFFCENTER_ZOOM_OUT );
  810. else
  811. cmd.SetId( ID_POPUP_ZOOM_OUT );
  812. }
  813. if( cmd.GetId() )
  814. GetEventHandler()->ProcessEvent( cmd );
  815. event.Skip();
  816. }
  817. #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
  818. void EDA_DRAW_PANEL::OnMagnify( wxMouseEvent& event )
  819. {
  820. // Scale the panel around our cursor position.
  821. bool warpCursor = false;
  822. wxPoint cursorPosition = GetParent()->GetCursorPosition( false );
  823. wxPoint centerPosition = GetParent()->GetScrollCenterPosition();
  824. wxPoint vector = centerPosition - cursorPosition;
  825. double magnification = ( event.GetMagnification() + 1.0f );
  826. double scaleFactor = GetZoom() / magnification;
  827. // Scale the vector between the cursor and center point
  828. vector.x /= magnification;
  829. vector.y /= magnification;
  830. SetZoom(scaleFactor);
  831. // Recenter the window along our scaled vector such that the
  832. // cursor becomes our scale axis, remaining fixed on screen
  833. GetParent()->RedrawScreen( cursorPosition + vector, warpCursor );
  834. event.Skip();
  835. }
  836. #endif
  837. void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
  838. {
  839. int localbutt = 0;
  840. BASE_SCREEN* screen = GetScreen();
  841. if( !screen )
  842. return;
  843. /* Adjust value to filter mouse displacement before consider the drag
  844. * mouse is really a drag command, not just a movement while click
  845. */
  846. #define MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND 5
  847. if( event.Leaving() )
  848. m_canStartBlock = -1;
  849. if( !IsMouseCaptured() ) // No mouse capture in progress.
  850. SetAutoPanRequest( false );
  851. if( GetParent()->IsActive() )
  852. SetFocus();
  853. else
  854. return;
  855. if( !event.IsButton() && !event.Moving() && !event.Dragging() )
  856. return;
  857. if( event.RightDown() )
  858. {
  859. OnRightClick( event );
  860. return;
  861. }
  862. if( m_ignoreMouseEvents )
  863. return;
  864. if( event.LeftDown() )
  865. localbutt = GR_M_LEFT_DOWN;
  866. if( event.ButtonDClick( 1 ) )
  867. localbutt = GR_M_LEFT_DOWN | GR_M_DCLICK;
  868. if( event.MiddleDown() )
  869. localbutt = GR_M_MIDDLE_DOWN;
  870. INSTALL_UNBUFFERED_DC( DC, this );
  871. DC.SetBackground( *wxBLACK_BRUSH );
  872. // Compute the cursor position in drawing (logical) units.
  873. GetParent()->SetMousePosition( event.GetLogicalPosition( DC ) );
  874. int kbstat = 0;
  875. if( event.ShiftDown() )
  876. kbstat |= GR_KB_SHIFT;
  877. if( event.ControlDown() )
  878. kbstat |= GR_KB_CTRL;
  879. if( event.AltDown() )
  880. kbstat |= GR_KB_ALT;
  881. // Calling Double Click and Click functions :
  882. if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) )
  883. {
  884. if( m_ClickTimer )
  885. {
  886. m_ClickTimer->Stop();
  887. wxDELETE( m_ClickTimer );
  888. }
  889. GetParent()->OnLeftDClick( &DC, GetParent()->RefPos( true ) );
  890. // inhibit a response to the mouse left button release,
  891. // because we have a double click, and we do not want a new
  892. // OnLeftClick command at end of this Double Click
  893. m_ignoreNextLeftButtonRelease = true;
  894. }
  895. else if( event.LeftUp() )
  896. {
  897. // A block command is in progress: a left up is the end of block
  898. // or this is the end of a double click, already seen
  899. // Note also m_ignoreNextLeftButtonRelease can be set by
  900. // the call to OnLeftClick(), so do not change it after calling OnLeftClick
  901. bool ignoreEvt = m_ignoreNextLeftButtonRelease;
  902. m_ignoreNextLeftButtonRelease = false;
  903. if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK && !ignoreEvt )
  904. {
  905. EDA_ITEM* item = screen->GetCurItem();
  906. m_CursorClickPos = GetParent()->RefPos( true );
  907. // If we have an item already selected, or we are using a tool,
  908. // we won't use the disambiguation menu so process the click immediately
  909. if( ( item && item->GetEditFlags() ) || GetParent()->GetToolId() != ID_NO_TOOL_SELECTED )
  910. GetParent()->OnLeftClick( &DC, m_CursorClickPos );
  911. else
  912. {
  913. wxDELETE( m_ClickTimer );
  914. m_ClickTimer = new wxTimer(this, ID_MOUSE_DOUBLECLICK);
  915. m_ClickTimer->StartOnce( m_doubleClickInterval );
  916. }
  917. }
  918. }
  919. else if( !event.LeftIsDown() )
  920. {
  921. /* be sure there is a response to a left button release command
  922. * even when a LeftUp event is not seen. This happens when a
  923. * double click opens a dialog box, and the release mouse button
  924. * is made when the dialog box is opened.
  925. */
  926. m_ignoreNextLeftButtonRelease = false;
  927. }
  928. if( event.ButtonDown( wxMOUSE_BTN_MIDDLE ) )
  929. {
  930. m_PanStartCenter = GetParent()->GetScrollCenterPosition();
  931. m_PanStartEventPosition = event.GetPosition();
  932. INSTALL_UNBUFFERED_DC( dc, this );
  933. CrossHairOff( &dc );
  934. SetCursor( wxCURSOR_SIZING );
  935. }
  936. if( event.ButtonUp( wxMOUSE_BTN_MIDDLE ) )
  937. {
  938. INSTALL_UNBUFFERED_DC( dc, this );
  939. CrossHairOn( &dc );
  940. SetCursor( (wxStockCursor) m_currentCursor );
  941. }
  942. if( event.MiddleIsDown() )
  943. {
  944. wxPoint currentPosition = event.GetPosition();
  945. double scale = GetParent()->GetScreen()->GetScalingFactor();
  946. int x = m_PanStartCenter.x +
  947. KiROUND( (double) ( m_PanStartEventPosition.x - currentPosition.x ) / scale );
  948. int y = m_PanStartCenter.y +
  949. KiROUND( (double) ( m_PanStartEventPosition.y - currentPosition.y ) / scale );
  950. GetParent()->RedrawScreen( wxPoint( x, y ), false );
  951. }
  952. // Calling the general function on mouse changes (and pseudo key commands)
  953. GetParent()->GeneralControl( &DC, event.GetLogicalPosition( DC ), 0 );
  954. /*******************************/
  955. /* Control of block commands : */
  956. /*******************************/
  957. // Command block can't start if mouse is dragging a new panel
  958. static EDA_DRAW_PANEL* lastPanel;
  959. if( lastPanel != this )
  960. {
  961. m_minDragEventCount = 0;
  962. m_canStartBlock = -1;
  963. }
  964. /* A new command block can start after a release buttons
  965. * and if the drag is enough
  966. * This is to avoid a false start block when a dialog box is dismissed,
  967. * or when changing panels in hierarchy navigation
  968. * or when clicking while and moving mouse
  969. */
  970. if( !event.LeftIsDown() && !event.MiddleIsDown() )
  971. {
  972. m_minDragEventCount = 0;
  973. m_canStartBlock = 0;
  974. /* Remember the last cursor position when a drag mouse starts
  975. * this is the last position ** before ** clicking a button
  976. * this is useful to start a block command from the point where the
  977. * mouse was clicked first
  978. * (a filter creates a delay for the real block command start, and
  979. * we must remember this point)
  980. */
  981. m_CursorStartPos = GetParent()->GetCrossHairPosition();
  982. }
  983. if( m_enableBlockCommands && !(localbutt & GR_M_DCLICK) )
  984. {
  985. if( !screen->IsBlockActive() )
  986. {
  987. screen->m_BlockLocate.SetOrigin( m_CursorStartPos );
  988. }
  989. if( event.LeftDown() )
  990. {
  991. if( screen->m_BlockLocate.GetState() == STATE_BLOCK_MOVE )
  992. {
  993. SetAutoPanRequest( false );
  994. GetParent()->HandleBlockPlace( &DC );
  995. m_ignoreNextLeftButtonRelease = true;
  996. }
  997. }
  998. else if( ( m_canStartBlock >= 0 ) && event.LeftIsDown() && !IsMouseCaptured() )
  999. {
  1000. // Mouse is dragging: if no block in progress, start a block command.
  1001. if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK )
  1002. {
  1003. // Start a block command
  1004. int cmd_type = kbstat;
  1005. // A block command is started if the drag is enough. A small
  1006. // drag is ignored (it is certainly a little mouse move when
  1007. // clicking) not really a drag mouse
  1008. if( m_minDragEventCount < MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND )
  1009. m_minDragEventCount++;
  1010. else
  1011. {
  1012. auto cmd = (GetParent()->GetToolId() == ID_ZOOM_SELECTION) ? BLOCK_ZOOM : 0;
  1013. if( !GetParent()->HandleBlockBegin( &DC, cmd_type, m_CursorStartPos, cmd ) )
  1014. {
  1015. // should not occur: error
  1016. GetParent()->DisplayToolMsg(
  1017. wxT( "EDA_DRAW_PANEL::OnMouseEvent() Block Error" ) );
  1018. }
  1019. else
  1020. {
  1021. SetAutoPanRequest( true );
  1022. SetCursor( wxCURSOR_SIZING );
  1023. }
  1024. }
  1025. }
  1026. }
  1027. if( event.ButtonUp( wxMOUSE_BTN_LEFT ) )
  1028. {
  1029. /* Release the mouse button: end of block.
  1030. * The command can finish (DELETE) or have a next command (MOVE,
  1031. * COPY). However the block command is canceled if the block
  1032. * size is small because a block command filtering is already
  1033. * made, this case happens, but only when the on grid cursor has
  1034. * not moved.
  1035. */
  1036. #define BLOCK_MINSIZE_LIMIT 1
  1037. bool BlockIsSmall =
  1038. ( std::abs( screen->m_BlockLocate.GetWidth() ) < BLOCK_MINSIZE_LIMIT )
  1039. && ( std::abs( screen->m_BlockLocate.GetHeight() ) < BLOCK_MINSIZE_LIMIT );
  1040. if( (screen->m_BlockLocate.GetState() != STATE_NO_BLOCK) && BlockIsSmall )
  1041. {
  1042. if( m_endMouseCaptureCallback )
  1043. {
  1044. m_endMouseCaptureCallback( this, &DC );
  1045. SetAutoPanRequest( false );
  1046. }
  1047. SetCursor( (wxStockCursor) m_currentCursor );
  1048. }
  1049. else if( screen->m_BlockLocate.GetState() == STATE_BLOCK_END )
  1050. {
  1051. SetAutoPanRequest( false );
  1052. GetParent()->HandleBlockEnd( &DC );
  1053. SetCursor( (wxStockCursor) m_currentCursor );
  1054. if( screen->m_BlockLocate.GetState() == STATE_BLOCK_MOVE )
  1055. {
  1056. SetAutoPanRequest( true );
  1057. SetCursor( wxCURSOR_HAND );
  1058. }
  1059. }
  1060. }
  1061. }
  1062. // End of block command on a double click
  1063. // To avoid an unwanted block move command if the mouse is moved while double clicking
  1064. if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) )
  1065. {
  1066. if( !screen->IsBlockActive() && IsMouseCaptured() )
  1067. {
  1068. m_endMouseCaptureCallback( this, &DC );
  1069. }
  1070. }
  1071. lastPanel = this;
  1072. #ifdef __WXGTK3__
  1073. // Screen has to be updated on every operation, otherwise the cursor leaves a trail (when xor
  1074. // operation is changed to copy) or is not updated at all.
  1075. Refresh();
  1076. #endif
  1077. }
  1078. void EDA_DRAW_PANEL::OnCharHook( wxKeyEvent& event )
  1079. {
  1080. wxLogTrace( kicadTraceKeyEvent, "EDA_DRAW_PANEL::OnCharHook %s", dump( event ) );
  1081. event.Skip();
  1082. }
  1083. void EDA_DRAW_PANEL::OnKeyEvent( wxKeyEvent& event )
  1084. {
  1085. int localkey;
  1086. wxPoint pos;
  1087. wxLogTrace( kicadTraceKeyEvent, "EDA_DRAW_PANEL::OnKeyEvent %s", dump( event ) );
  1088. localkey = event.GetKeyCode();
  1089. bool keyWasHandled = false;
  1090. switch( localkey )
  1091. {
  1092. default:
  1093. break;
  1094. case WXK_ESCAPE:
  1095. m_abortRequest = true;
  1096. if( IsMouseCaptured() )
  1097. EndMouseCapture();
  1098. else
  1099. EndMouseCapture( ID_NO_TOOL_SELECTED, m_defaultCursor, wxEmptyString );
  1100. keyWasHandled = true; // The key is captured: the key event must not be skipped
  1101. break;
  1102. }
  1103. /* Normalize keys code to easily handle keys from Ctrl+A to Ctrl+Z
  1104. * They have an ascii code from 1 to 27 remapped
  1105. * to GR_KB_CTRL + 'A' to GR_KB_CTRL + 'Z'
  1106. */
  1107. if( event.ControlDown() && localkey >= WXK_CONTROL_A && localkey <= WXK_CONTROL_Z )
  1108. localkey += 'A' - 1;
  1109. /* Disallow shift for keys that have two keycodes on them (e.g. number and
  1110. * punctuation keys) leaving only the "letter keys" of A-Z.
  1111. * Then, you can have, e.g. Ctrl-5 and Ctrl-% (GB layout)
  1112. * and Ctrl-( and Ctrl-5 (FR layout).
  1113. * Otherwise, you'd have to have to say Ctrl-Shift-5 on a FR layout
  1114. */
  1115. bool keyIsLetter = ( localkey >= 'A' && localkey <= 'Z' ) ||
  1116. ( localkey >= 'a' && localkey <= 'z' );
  1117. if( event.ShiftDown() && ( keyIsLetter || localkey > 256 ) )
  1118. localkey |= GR_KB_SHIFT;
  1119. if( event.ControlDown() )
  1120. localkey |= GR_KB_CTRL;
  1121. if( event.AltDown() )
  1122. localkey |= GR_KB_ALT;
  1123. INSTALL_UNBUFFERED_DC( DC, this );
  1124. // Some key commands use the current mouse position: refresh it.
  1125. pos = wxGetMousePosition() - GetScreenPosition();
  1126. // Compute the cursor position in drawing units. Also known as logical units to wxDC.
  1127. pos = wxPoint( DC.DeviceToLogicalX( pos.x ), DC.DeviceToLogicalY( pos.y ) );
  1128. GetParent()->SetMousePosition( pos );
  1129. if( !GetParent()->GeneralControl( &DC, pos, localkey ) && !keyWasHandled )
  1130. event.Skip(); // Skip this event only when the key was not handled
  1131. }
  1132. void EDA_DRAW_PANEL::OnPan( wxCommandEvent& event )
  1133. {
  1134. int x, y;
  1135. int ppux, ppuy;
  1136. int unitsX, unitsY;
  1137. int maxX, maxY;
  1138. int tmpX, tmpY;
  1139. GetViewStart( &x, &y );
  1140. GetScrollPixelsPerUnit( &ppux, &ppuy );
  1141. GetVirtualSize( &unitsX, &unitsY );
  1142. tmpX = x;
  1143. tmpY = y;
  1144. maxX = unitsX;
  1145. maxY = unitsY;
  1146. unitsX /= ppux;
  1147. unitsY /= ppuy;
  1148. wxLogTrace( kicadTraceCoords,
  1149. wxT( "Scroll center position before pan: (%d, %d)" ), tmpX, tmpY );
  1150. switch( event.GetId() )
  1151. {
  1152. case ID_PAN_UP:
  1153. y -= m_scrollIncrementY;
  1154. break;
  1155. case ID_PAN_DOWN:
  1156. y += m_scrollIncrementY;
  1157. break;
  1158. case ID_PAN_LEFT:
  1159. x -= m_scrollIncrementX;
  1160. break;
  1161. case ID_PAN_RIGHT:
  1162. x += m_scrollIncrementX;
  1163. break;
  1164. default:
  1165. wxLogDebug( wxT( "Unknown ID %d in EDA_DRAW_PANEL::OnPan()." ), event.GetId() );
  1166. }
  1167. bool updateCenterScrollPos = true;
  1168. if( x < 0 )
  1169. {
  1170. x = 0;
  1171. updateCenterScrollPos = false;
  1172. }
  1173. if( y < 0 )
  1174. {
  1175. y = 0;
  1176. updateCenterScrollPos = false;
  1177. }
  1178. if( x > maxX )
  1179. {
  1180. x = maxX;
  1181. updateCenterScrollPos = false;
  1182. }
  1183. if( y > maxY )
  1184. {
  1185. y = maxY;
  1186. updateCenterScrollPos = false;
  1187. }
  1188. // Don't update the scroll position beyond the scroll limits.
  1189. if( updateCenterScrollPos )
  1190. {
  1191. double scale = GetParent()->GetScreen()->GetScalingFactor();
  1192. wxPoint center = GetParent()->GetScrollCenterPosition();
  1193. center.x += KiROUND( (double) ( x - tmpX ) / scale );
  1194. center.y += KiROUND( (double) ( y - tmpY ) / scale );
  1195. GetParent()->SetScrollCenterPosition( center );
  1196. wxLogTrace( kicadTraceCoords,
  1197. wxT( "Scroll center position after pan: (%d, %d)" ), center.x, center.y );
  1198. }
  1199. Scroll( x/ppux, y/ppuy );
  1200. }
  1201. void EDA_DRAW_PANEL::EndMouseCapture( int id, int cursor, const wxString& title,
  1202. bool aCallEndFunc )
  1203. {
  1204. if( m_mouseCaptureCallback && m_endMouseCaptureCallback && aCallEndFunc )
  1205. {
  1206. INSTALL_UNBUFFERED_DC( dc, this );
  1207. m_endMouseCaptureCallback( this, &dc );
  1208. }
  1209. m_mouseCaptureCallback = NULL;
  1210. m_endMouseCaptureCallback = NULL;
  1211. SetAutoPanRequest( false );
  1212. if( id != -1 && cursor != -1 )
  1213. {
  1214. wxASSERT( cursor > wxCURSOR_NONE && cursor < wxCURSOR_MAX );
  1215. GetParent()->SetToolID( id, cursor, title );
  1216. }
  1217. }
  1218. void EDA_DRAW_PANEL::CallMouseCapture( wxDC* aDC, const wxPoint& aPosition, bool aErase )
  1219. {
  1220. wxCHECK_RET( aDC != NULL, wxT( "Invalid device context." ) );
  1221. wxCHECK_RET( m_mouseCaptureCallback != NULL, wxT( "Mouse capture callback not set." ) );
  1222. m_mouseCaptureCallback( this, aDC, aPosition, aErase );
  1223. }
  1224. void EDA_DRAW_PANEL::CallEndMouseCapture( wxDC* aDC )
  1225. {
  1226. wxCHECK_RET( aDC != NULL, wxT( "Invalid device context." ) );
  1227. // CallEndMouseCapture is sometimes called with m_endMouseCaptureCallback == NULL
  1228. // for instance after an ABORT in block paste.
  1229. if( m_endMouseCaptureCallback )
  1230. m_endMouseCaptureCallback( this, aDC );
  1231. }