2011-10-13 19:56:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-01-16 16:39:06 +00:00
|
|
|
* Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2017-09-21 12:58:08 +00:00
|
|
|
* Copyright (C) 2007 Wayne Stambaugh <stambaughw@gmail.com>
|
2019-01-16 16:39:06 +00:00
|
|
|
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-13 19:56:32 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2011-03-09 20:09:11 +00:00
|
|
|
/**
|
2014-10-06 01:18:24 +00:00
|
|
|
* @file draw_panel.cpp
|
2011-03-09 20:09:11 +00:00
|
|
|
*/
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
2017-12-06 05:25:52 +00:00
|
|
|
#include <wx/timer.h>
|
* 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.
2014-03-20 00:42:08 +00:00
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <kiface_i.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <id.h>
|
|
|
|
#include <class_drawpanel.h>
|
2014-04-04 09:56:04 +00:00
|
|
|
#include <class_draw_panel_gal.h>
|
2018-01-29 10:37:29 +00:00
|
|
|
#include <base_screen.h>
|
* 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.
2014-03-20 00:42:08 +00:00
|
|
|
#include <draw_frame.h>
|
2015-07-09 08:18:27 +00:00
|
|
|
#include <view/view_controls.h>
|
2017-03-19 20:51:59 +00:00
|
|
|
#include <gal/gal_display_options.h>
|
2018-04-13 13:58:25 +00:00
|
|
|
#include <trace_helpers.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <kicad_device_context.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-05-27 00:19:12 +00:00
|
|
|
static const int CURSOR_SIZE = 12; ///< Cursor size in pixels
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-02-21 13:54:29 +00:00
|
|
|
#define CLIP_BOX_PADDING 2
|
2009-12-19 16:10:25 +00:00
|
|
|
|
* 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.
2014-03-20 00:42:08 +00:00
|
|
|
// Definitions for enabling and disabling debugging features in drawpanel.cpp.
|
|
|
|
// Please don't forget to turn these off before making any commits to Launchpad.
|
2010-02-22 16:45:35 +00:00
|
|
|
#define DEBUG_SHOW_CLIP_RECT 0 // Set to 1 to draw clipping rectangle.
|
2011-02-09 19:47:33 +00:00
|
|
|
|
* 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.
2014-03-20 00:42:08 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
// Events used by EDA_DRAW_PANEL
|
|
|
|
BEGIN_EVENT_TABLE( EDA_DRAW_PANEL, wxScrolledWindow )
|
|
|
|
EVT_LEAVE_WINDOW( EDA_DRAW_PANEL::OnMouseLeaving )
|
2015-07-22 23:33:50 +00:00
|
|
|
EVT_ENTER_WINDOW( EDA_DRAW_PANEL::OnMouseEntering )
|
2011-01-21 19:30:59 +00:00
|
|
|
EVT_MOUSEWHEEL( EDA_DRAW_PANEL::OnMouseWheel )
|
2016-01-25 00:18:29 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
|
2015-05-21 20:54:29 +00:00
|
|
|
EVT_MAGNIFY( EDA_DRAW_PANEL::OnMagnify )
|
|
|
|
#endif
|
2011-01-21 19:30:59 +00:00
|
|
|
EVT_PAINT( EDA_DRAW_PANEL::OnPaint )
|
2011-01-30 22:22:38 +00:00
|
|
|
EVT_ERASE_BACKGROUND( EDA_DRAW_PANEL::OnEraseBackground )
|
2011-01-21 19:30:59 +00:00
|
|
|
EVT_SCROLLWIN( EDA_DRAW_PANEL::OnScroll )
|
|
|
|
EVT_ACTIVATE( EDA_DRAW_PANEL::OnActivate )
|
|
|
|
EVT_MENU_RANGE( ID_PAN_UP, ID_PAN_RIGHT, EDA_DRAW_PANEL::OnPan )
|
2007-05-06 16:03:28 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/***********************************************************************/
|
2011-01-21 19:30:59 +00:00
|
|
|
/* EDA_DRAW_PANEL base functions (EDA_DRAW_PANEL is the main panel)*/
|
2009-11-23 15:16:50 +00:00
|
|
|
/***********************************************************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2018-03-06 20:30:15 +00:00
|
|
|
#ifdef __WXMAC__
|
2018-08-11 16:04:46 +00:00
|
|
|
const int drawPanelStyle = wxHSCROLL | wxVSCROLL | wxALWAYS_SHOW_SB;
|
2018-03-06 20:30:15 +00:00
|
|
|
#else
|
2018-08-11 16:04:46 +00:00
|
|
|
const int drawPanelStyle = wxHSCROLL | wxVSCROLL;
|
2018-03-06 20:30:15 +00:00
|
|
|
#endif
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
EDA_DRAW_PANEL::EDA_DRAW_PANEL( EDA_DRAW_FRAME* parent, int id,
|
|
|
|
const wxPoint& pos, const wxSize& size ) :
|
2018-03-06 20:30:15 +00:00
|
|
|
wxScrolledWindow( parent, id, pos, size, drawPanelStyle )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-02-09 19:47:33 +00:00
|
|
|
wxASSERT( parent );
|
2010-02-08 18:15:42 +00:00
|
|
|
|
2013-08-26 12:23:17 +00:00
|
|
|
ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS );
|
2013-11-17 16:48:47 +00:00
|
|
|
DisableKeyboardScrolling();
|
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
m_scrollIncrementX = std::min( size.x / 8, 10 );
|
|
|
|
m_scrollIncrementY = std::min( size.y / 8, 10 );
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2016-03-22 18:53:50 +00:00
|
|
|
SetLayoutDirection( wxLayout_LeftToRight );
|
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
SetBackgroundColour( parent->GetDrawBgColor().ToColour() );
|
2011-01-30 22:22:38 +00:00
|
|
|
|
|
|
|
#if KICAD_USE_BUFFERED_DC || KICAD_USE_BUFFERED_PAINTDC
|
2009-12-29 10:35:11 +00:00
|
|
|
SetBackgroundStyle( wxBG_STYLE_CUSTOM );
|
2010-01-14 20:20:59 +00:00
|
|
|
#endif
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
m_ClipBox.SetSize( size );
|
|
|
|
m_ClipBox.SetX( 0 );
|
|
|
|
m_ClipBox.SetY( 0 );
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canStartBlock = -1; // Command block can start if >= 0
|
|
|
|
m_abortRequest = false;
|
2016-02-24 19:53:02 +00:00
|
|
|
m_enableMousewheelPan = false;
|
2013-02-02 19:10:48 +00:00
|
|
|
m_enableZoomNoCenter = false;
|
2011-12-29 20:11:42 +00:00
|
|
|
m_enableAutoPan = true;
|
|
|
|
m_ignoreMouseEvents = false;
|
2016-06-17 17:58:14 +00:00
|
|
|
// Be sure a mouse release button event will be ignored when creating the canvas
|
|
|
|
// if the mouse click was not made inside the canvas (can happen sometimes, when
|
2018-04-08 10:28:59 +00:00
|
|
|
// launching a editor from a double click made in another frame)
|
2016-06-17 17:58:14 +00:00
|
|
|
m_ignoreNextLeftButtonRelease = true;
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
m_mouseCaptureCallback = NULL;
|
|
|
|
m_endMouseCaptureCallback = NULL;
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2018-07-01 14:48:35 +00:00
|
|
|
Pgm().CommonSettings()->Read( ENBL_MOUSEWHEEL_PAN_KEY, &m_enableMousewheelPan, false );
|
|
|
|
Pgm().CommonSettings()->Read( ENBL_ZOOM_NO_CENTER_KEY, &m_enableZoomNoCenter, false );
|
|
|
|
Pgm().CommonSettings()->Read( ENBL_AUTO_PAN_KEY, &m_enableAutoPan, true );
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
m_requestAutoPan = false;
|
2012-12-06 21:53:00 +00:00
|
|
|
m_minDragEventCount = 0;
|
2011-02-09 19:47:33 +00:00
|
|
|
|
|
|
|
#ifdef __WXMAC__
|
2011-03-09 20:09:11 +00:00
|
|
|
m_defaultCursor = m_currentCursor = wxCURSOR_CROSS;
|
2011-02-09 19:47:33 +00:00
|
|
|
m_showCrossHair = false;
|
|
|
|
#else
|
2011-03-09 20:09:11 +00:00
|
|
|
m_defaultCursor = m_currentCursor = wxCURSOR_ARROW;
|
2011-02-09 19:47:33 +00:00
|
|
|
m_showCrossHair = true;
|
|
|
|
#endif
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
m_cursorLevel = 0;
|
2011-02-09 19:47:33 +00:00
|
|
|
m_PrintIsMirrored = false;
|
2017-12-06 05:25:52 +00:00
|
|
|
|
|
|
|
m_ClickTimer = (wxTimer*) NULL;
|
|
|
|
m_doubleClickInterval = 250;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
EDA_DRAW_PANEL::~EDA_DRAW_PANEL()
|
2009-04-08 18:06:22 +00:00
|
|
|
{
|
* 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.
2014-03-20 00:42:08 +00:00
|
|
|
wxConfigBase* cfg = Kiface().KifaceSettings();
|
|
|
|
|
|
|
|
if( cfg )
|
|
|
|
{
|
2016-02-24 19:53:02 +00:00
|
|
|
cfg->Write( ENBL_MOUSEWHEEL_PAN_KEY, m_enableMousewheelPan );
|
* 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.
2014-03-20 00:42:08 +00:00
|
|
|
cfg->Write( ENBL_ZOOM_NO_CENTER_KEY, m_enableZoomNoCenter );
|
|
|
|
cfg->Write( ENBL_AUTO_PAN_KEY, m_enableAutoPan );
|
|
|
|
}
|
2017-12-06 05:25:52 +00:00
|
|
|
|
|
|
|
wxDELETE( m_ClickTimer );
|
2009-04-08 18:06:22 +00:00
|
|
|
}
|
|
|
|
|
2013-08-05 21:02:41 +00:00
|
|
|
|
2014-05-04 17:08:36 +00:00
|
|
|
EDA_DRAW_FRAME* EDA_DRAW_PANEL::GetParent() const
|
2011-02-09 19:47:33 +00:00
|
|
|
{
|
2013-08-05 21:02:41 +00:00
|
|
|
wxWindow* mom = wxScrolledWindow::GetParent();
|
|
|
|
return (EDA_DRAW_FRAME*) mom;
|
2011-02-09 19:47:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-10 10:27:49 +00:00
|
|
|
void* EDA_DRAW_PANEL::GetDisplayOptions()
|
|
|
|
{
|
|
|
|
return GetParent()->GetDisplayOptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
BASE_SCREEN* EDA_DRAW_PANEL::GetScreen()
|
2008-04-17 16:25:29 +00:00
|
|
|
{
|
2011-02-09 19:47:33 +00:00
|
|
|
EDA_DRAW_FRAME* parentFrame = GetParent();
|
2010-01-17 14:20:29 +00:00
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
return parentFrame->GetScreen();
|
2008-04-17 16:25:29 +00:00
|
|
|
}
|
|
|
|
|
2015-07-22 23:33:50 +00:00
|
|
|
|
2013-02-02 19:10:48 +00:00
|
|
|
wxPoint EDA_DRAW_PANEL::ToDeviceXY( const wxPoint& pos )
|
|
|
|
{
|
2013-02-12 03:56:46 +00:00
|
|
|
wxPoint ret;
|
|
|
|
INSTALL_UNBUFFERED_DC( dc, this );
|
|
|
|
ret.x = dc.LogicalToDeviceX( pos.x );
|
|
|
|
ret.y = dc.LogicalToDeviceY( pos.y );
|
|
|
|
return ret;
|
2013-02-02 19:10:48 +00:00
|
|
|
}
|
|
|
|
|
2015-07-22 23:33:50 +00:00
|
|
|
|
2013-02-02 19:10:48 +00:00
|
|
|
wxPoint EDA_DRAW_PANEL::ToLogicalXY( const wxPoint& pos )
|
|
|
|
{
|
2013-02-12 03:56:46 +00:00
|
|
|
wxPoint ret;
|
|
|
|
INSTALL_UNBUFFERED_DC( dc, this );
|
|
|
|
ret.x = dc.DeviceToLogicalX( pos.x );
|
|
|
|
ret.y = dc.DeviceToLogicalY( pos.y );
|
|
|
|
return ret;
|
2013-02-02 19:10:48 +00:00
|
|
|
}
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2015-07-22 23:33:50 +00:00
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
void EDA_DRAW_PANEL::DrawCrossHair( wxDC* aDC, COLOR4D aColor )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-02-09 19:47:33 +00:00
|
|
|
if( m_cursorLevel != 0 || aDC == NULL || !m_showCrossHair )
|
2007-08-22 05:11:01 +00:00
|
|
|
return;
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
wxPoint cursor = GetParent()->GetCrossHairPosition();
|
2007-10-06 16:16:48 +00:00
|
|
|
|
2018-02-07 14:00:26 +00:00
|
|
|
#ifdef USE_WX_GRAPHICS_CONTEXT
|
|
|
|
// Normally cursor color is set to white, so when it is xored with white
|
|
|
|
// background, it is painted black effectively. wxGraphicsContext does not have
|
|
|
|
// xor operation, so we need to invert the color manually.
|
|
|
|
aColor.Invert();
|
|
|
|
#else
|
2010-01-22 18:13:43 +00:00
|
|
|
GRSetDrawMode( aDC, GR_XOR );
|
2018-02-07 14:00:26 +00:00
|
|
|
#endif
|
2010-02-10 21:39:32 +00:00
|
|
|
|
2017-03-19 20:51:59 +00:00
|
|
|
if( GetParent()->GetGalDisplayOptions().m_fullscreenCursor )
|
2007-08-22 05:11:01 +00:00
|
|
|
{
|
2012-04-23 21:56:26 +00:00
|
|
|
wxSize clientSize = GetClientSize();
|
|
|
|
|
|
|
|
// Y axis
|
|
|
|
wxPoint lineStart( cursor.x, aDC->DeviceToLogicalY( 0 ) );
|
|
|
|
wxPoint lineEnd( cursor.x, aDC->DeviceToLogicalY( clientSize.y ) );
|
|
|
|
|
|
|
|
GRLine( &m_ClipBox, aDC, lineStart, lineEnd, 0, aColor );
|
|
|
|
|
|
|
|
// X axis
|
|
|
|
lineStart = wxPoint( aDC->DeviceToLogicalX( 0 ), cursor.y );
|
|
|
|
lineEnd = wxPoint( aDC->DeviceToLogicalX( clientSize.x ), cursor.y );
|
|
|
|
|
|
|
|
GRLine( &m_ClipBox, aDC, lineStart, lineEnd, 0, aColor );
|
2007-08-22 05:11:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-08 18:15:42 +00:00
|
|
|
int len = aDC->DeviceToLogicalXRel( CURSOR_SIZE );
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2012-04-23 21:56:26 +00:00
|
|
|
GRLine( &m_ClipBox, aDC, cursor.x - len, cursor.y,
|
|
|
|
cursor.x + len, cursor.y, 0, aColor );
|
|
|
|
GRLine( &m_ClipBox, aDC, cursor.x, cursor.y - len,
|
|
|
|
cursor.x, cursor.y + len, 0, aColor );
|
2007-08-22 05:11:01 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
void EDA_DRAW_PANEL::CrossHairOff( wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawCrossHair( DC );
|
2011-02-09 19:47:33 +00:00
|
|
|
--m_cursorLevel;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
void EDA_DRAW_PANEL::CrossHairOn( wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-02-09 19:47:33 +00:00
|
|
|
++m_cursorLevel;
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawCrossHair( DC );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-02-09 19:47:33 +00:00
|
|
|
if( m_cursorLevel > 0 ) // Shouldn't happen, but just in case ..
|
|
|
|
m_cursorLevel = 0;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-07 21:47:25 +00:00
|
|
|
double EDA_DRAW_PANEL::GetZoom()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
return GetScreen()->GetZoom();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2012-05-07 21:47:25 +00:00
|
|
|
void EDA_DRAW_PANEL::SetZoom( double zoom )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
GetScreen()->SetZoom( zoom );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
wxRealPoint EDA_DRAW_PANEL::GetGrid()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-10-14 19:43:31 +00:00
|
|
|
return GetScreen()->GetGridSize();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-09 19:47:33 +00:00
|
|
|
bool EDA_DRAW_PANEL::IsPointOnDisplay( const wxPoint& aPosition )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
wxPoint pos;
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT display_rect;
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2011-02-09 19:47:33 +00:00
|
|
|
INSTALL_UNBUFFERED_DC( dc, this ); // Refresh the clip box to the entire screen size.
|
2011-01-30 22:22:38 +00:00
|
|
|
SetClipBox( dc );
|
2010-02-08 18:15:42 +00:00
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
display_rect = m_ClipBox;
|
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
// Slightly decreased the size of the useful screen area to avoid drawing limits.
|
2007-08-22 05:11:01 +00:00
|
|
|
#define PIXEL_MARGIN 8
|
2009-12-29 10:35:11 +00:00
|
|
|
display_rect.Inflate( -PIXEL_MARGIN );
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2011-02-09 19:47:33 +00:00
|
|
|
return display_rect.Contains( aPosition );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
void EDA_DRAW_PANEL::RefreshDrawingRect( const EDA_RECT& aRect, bool aEraseBackground )
|
2008-03-10 15:00:22 +00:00
|
|
|
{
|
2011-01-30 22:22:38 +00:00
|
|
|
INSTALL_UNBUFFERED_DC( dc, this );
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
wxRect rect = aRect;
|
2008-03-11 01:19:08 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
rect.x = dc.LogicalToDeviceX( rect.x );
|
|
|
|
rect.y = dc.LogicalToDeviceY( rect.y );
|
|
|
|
rect.width = dc.LogicalToDeviceXRel( rect.width );
|
|
|
|
rect.height = dc.LogicalToDeviceYRel( rect.height );
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2017-09-21 12:58:08 +00:00
|
|
|
wxLogTrace( kicadTraceCoords,
|
2011-01-30 22:22:38 +00:00
|
|
|
wxT( "Refresh area: drawing (%d, %d, %d, %d), device (%d, %d, %d, %d)" ),
|
|
|
|
aRect.GetX(), aRect.GetY(), aRect.GetWidth(), aRect.GetHeight(),
|
|
|
|
rect.x, rect.y, rect.width, rect.height );
|
2008-05-17 19:08:23 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
RefreshRect( rect, aEraseBackground );
|
2008-03-10 08:14:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-20 15:29:32 +00:00
|
|
|
void EDA_DRAW_PANEL::Refresh( bool eraseBackground, const wxRect* rect )
|
|
|
|
{
|
2019-05-27 16:16:54 +00:00
|
|
|
GetParent()->GetGalCanvas()->Refresh();
|
2013-09-20 15:29:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-31 18:26:12 +00:00
|
|
|
wxPoint EDA_DRAW_PANEL::GetScreenCenterLogicalPosition()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-01-31 18:26:12 +00:00
|
|
|
wxSize size = GetClientSize() / 2;
|
|
|
|
INSTALL_UNBUFFERED_DC( dc, this );
|
2010-02-08 18:15:42 +00:00
|
|
|
|
2011-01-31 18:26:12 +00:00
|
|
|
return wxPoint( dc.DeviceToLogicalX( size.x ), dc.DeviceToLogicalY( size.y ) );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
void EDA_DRAW_PANEL::MoveCursorToCrossHair()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2013-08-03 05:15:23 +00:00
|
|
|
MoveCursor( GetParent()->GetCrossHairPosition() );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2011-02-01 15:46:25 +00:00
|
|
|
void EDA_DRAW_PANEL::MoveCursor( const wxPoint& aPosition )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2019-05-27 16:16:54 +00:00
|
|
|
// JEY TODO: OBSOLETE
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_PANEL::OnActivate( wxActivateEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canStartBlock = -1; // Block Command can't start
|
2007-08-22 05:11:01 +00:00
|
|
|
event.Skip();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_PANEL::OnScroll( wxScrollWinEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
int id = event.GetEventType();
|
|
|
|
int x, y;
|
2010-02-22 16:45:35 +00:00
|
|
|
int ppux, ppuy;
|
2012-04-11 18:54:20 +00:00
|
|
|
int csizeX, csizeY;
|
2010-02-22 16:45:35 +00:00
|
|
|
int unitsX, unitsY;
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
|
|
GetViewStart( &x, &y );
|
2010-02-22 16:45:35 +00:00
|
|
|
GetScrollPixelsPerUnit( &ppux, &ppuy );
|
2012-04-11 18:54:20 +00:00
|
|
|
GetClientSize( &csizeX, &csizeY );
|
2010-02-22 16:45:35 +00:00
|
|
|
GetVirtualSize( &unitsX, &unitsY );
|
2012-04-11 18:54:20 +00:00
|
|
|
|
2012-04-12 07:58:12 +00:00
|
|
|
int tmpX = x;
|
|
|
|
int tmpY = y;
|
|
|
|
|
2012-04-11 18:54:20 +00:00
|
|
|
csizeX /= ppux;
|
|
|
|
csizeY /= ppuy;
|
2010-02-22 16:45:35 +00:00
|
|
|
|
|
|
|
unitsX /= ppux;
|
|
|
|
unitsY /= ppuy;
|
|
|
|
|
2014-07-20 15:23:48 +00:00
|
|
|
int dir = event.GetOrientation(); // wxHORIZONTAL or wxVERTICAL
|
2012-04-11 18:54:20 +00:00
|
|
|
|
2014-07-20 15:23:48 +00:00
|
|
|
// On windows and on wxWidgets >= 2.9.5 and < 3.1,
|
|
|
|
// there is a bug in mousewheel event which always generates 2 scroll events
|
|
|
|
// (should be the case only for the default mousewheel event)
|
|
|
|
// with id = wxEVT_SCROLLWIN_LINEUP or wxEVT_SCROLLWIN_LINEDOWN
|
|
|
|
// so we skip these events.
|
|
|
|
// Note they are here just in case, because they are not actually used
|
|
|
|
// in Kicad
|
2016-02-24 19:53:02 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 1, 0 ) || !wxCHECK_VERSION( 2, 9, 5 ) || ( !defined (__WINDOWS__) && !defined (__WXMAC__) )
|
2014-07-20 15:23:48 +00:00
|
|
|
int maxX = unitsX - csizeX;
|
|
|
|
int maxY = unitsY - csizeY;
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
|
|
if( id == wxEVT_SCROLLWIN_LINEUP )
|
2010-02-22 16:45:35 +00:00
|
|
|
{
|
|
|
|
if( dir == wxHORIZONTAL )
|
|
|
|
{
|
|
|
|
x -= m_scrollIncrementX;
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
if( x < 0 )
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
y -= m_scrollIncrementY;
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
if( y < 0 )
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
}
|
2007-08-22 05:11:01 +00:00
|
|
|
else if( id == wxEVT_SCROLLWIN_LINEDOWN )
|
2010-02-22 16:45:35 +00:00
|
|
|
{
|
|
|
|
if( dir == wxHORIZONTAL )
|
|
|
|
{
|
|
|
|
x += m_scrollIncrementX;
|
|
|
|
if( x > maxX )
|
|
|
|
x = maxX;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
y += m_scrollIncrementY;
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
if( y > maxY )
|
|
|
|
y = maxY;
|
|
|
|
}
|
|
|
|
}
|
2014-07-20 15:23:48 +00:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if( id == wxEVT_SCROLLWIN_THUMBTRACK )
|
2007-08-22 05:11:01 +00:00
|
|
|
{
|
|
|
|
if( dir == wxHORIZONTAL )
|
2010-02-22 16:45:35 +00:00
|
|
|
x = event.GetPosition();
|
2007-08-22 05:11:01 +00:00
|
|
|
else
|
2010-02-22 16:45:35 +00:00
|
|
|
y = event.GetPosition();
|
2007-08-22 05:11:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
event.Skip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-21 12:58:08 +00:00
|
|
|
wxLogTrace( kicadTraceCoords,
|
2011-02-16 19:16:38 +00:00
|
|
|
wxT( "Setting scroll bars ppuX=%d, ppuY=%d, unitsX=%d, unitsY=%d, posX=%d, posY=%d" ),
|
|
|
|
ppux, ppuy, unitsX, unitsY, x, y );
|
2010-02-10 21:39:32 +00:00
|
|
|
|
2012-04-12 07:58:12 +00:00
|
|
|
double scale = GetParent()->GetScreen()->GetScalingFactor();
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
wxPoint center = GetParent()->GetScrollCenterPosition();
|
// 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;
}
2012-04-19 06:55:45 +00:00
|
|
|
center.x += KiROUND( (double) ( x - tmpX ) / scale );
|
|
|
|
center.y += KiROUND( (double) ( y - tmpY ) / scale );
|
2013-08-03 05:15:23 +00:00
|
|
|
GetParent()->SetScrollCenterPosition( center );
|
2012-04-12 07:58:12 +00:00
|
|
|
|
2012-04-11 18:54:20 +00:00
|
|
|
Scroll( x, y );
|
2007-08-22 05:11:01 +00:00
|
|
|
event.Skip();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
void EDA_DRAW_PANEL::SetClipBox( wxDC& aDC, const wxRect* aRect )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-01-30 22:22:38 +00:00
|
|
|
wxRect clipBox;
|
|
|
|
|
|
|
|
// Use the entire visible device area if no clip area was defined.
|
|
|
|
if( aRect == NULL )
|
|
|
|
{
|
|
|
|
BASE_SCREEN* Screen = GetScreen();
|
2010-02-08 18:15:42 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
if( !Screen )
|
|
|
|
return;
|
2008-03-10 08:14:20 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
Screen->m_StartVisu = CalcUnscrolledPosition( wxPoint( 0, 0 ) );
|
|
|
|
clipBox.SetSize( GetClientSize() );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
int scrollX, scrollY;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
double scalar = Screen->GetScalingFactor();
|
// 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;
}
2012-04-19 06:55:45 +00:00
|
|
|
scrollX = KiROUND( Screen->GetGridSize().x * scalar );
|
|
|
|
scrollY = KiROUND( Screen->GetGridSize().y * scalar );
|
2010-02-08 18:15:42 +00:00
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
m_scrollIncrementX = std::max( GetClientSize().x / 8, scrollX );
|
|
|
|
m_scrollIncrementY = std::max( GetClientSize().y / 8, scrollY );
|
2011-01-30 22:22:38 +00:00
|
|
|
Screen->m_ScrollbarPos.x = GetScrollPos( wxHORIZONTAL );
|
|
|
|
Screen->m_ScrollbarPos.y = GetScrollPos( wxVERTICAL );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clipBox = *aRect;
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
// Pad clip box in device units.
|
|
|
|
clipBox.Inflate( CLIP_BOX_PADDING );
|
2010-02-08 18:15:42 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
// Convert from device units to drawing units.
|
2011-12-21 13:42:02 +00:00
|
|
|
m_ClipBox.SetOrigin( wxPoint( aDC.DeviceToLogicalX( clipBox.x ),
|
|
|
|
aDC.DeviceToLogicalY( clipBox.y ) ) );
|
|
|
|
m_ClipBox.SetSize( wxSize( aDC.DeviceToLogicalXRel( clipBox.width ),
|
|
|
|
aDC.DeviceToLogicalYRel( clipBox.height ) ) );
|
2010-02-08 18:15:42 +00:00
|
|
|
|
2017-09-21 12:58:08 +00:00
|
|
|
wxLogTrace( kicadTraceCoords,
|
2011-02-09 19:47:33 +00:00
|
|
|
wxT( "Device clip box=(%d, %d, %d, %d), Logical clip box=(%d, %d, %d, %d)" ),
|
2011-01-30 22:22:38 +00:00
|
|
|
clipBox.x, clipBox.y, clipBox.width, clipBox.height,
|
2011-12-21 13:42:02 +00:00
|
|
|
m_ClipBox.GetX(), m_ClipBox.GetY(), m_ClipBox.GetWidth(), m_ClipBox.GetHeight() );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_PANEL::EraseScreen( wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
GRSetDrawMode( DC, GR_COPY );
|
2008-03-10 15:51:44 +00:00
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
COLOR4D bgColor = GetParent()->GetDrawBgColor();
|
2014-06-20 11:13:04 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
GRSFilledRect( NULL, DC, m_ClipBox.GetX(), m_ClipBox.GetY(),
|
2009-04-15 19:53:41 +00:00
|
|
|
m_ClipBox.GetRight(), m_ClipBox.GetBottom(),
|
2014-06-20 11:13:04 +00:00
|
|
|
0, bgColor, bgColor );
|
2010-02-22 16:45:35 +00:00
|
|
|
|
2012-04-23 21:56:26 +00:00
|
|
|
// Set to one (1) to draw bounding box validate bounding box calculation.
|
2010-02-22 16:45:35 +00:00
|
|
|
#if DEBUG_SHOW_CLIP_RECT
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT bBox = m_ClipBox;
|
2010-02-22 16:45:35 +00:00
|
|
|
GRRect( NULL, DC, bBox.GetOrigin().x, bBox.GetOrigin().y,
|
|
|
|
bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA );
|
|
|
|
#endif
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
void EDA_DRAW_PANEL::DoPrepareDC( wxDC& dc )
|
2010-02-08 18:15:42 +00:00
|
|
|
{
|
2011-01-30 22:22:38 +00:00
|
|
|
wxScrolledWindow::DoPrepareDC( dc );
|
|
|
|
|
2010-02-08 18:15:42 +00:00
|
|
|
if( GetScreen() != NULL )
|
|
|
|
{
|
|
|
|
double scale = GetScreen()->GetScalingFactor();
|
2010-02-22 16:45:35 +00:00
|
|
|
dc.SetUserScale( scale, scale );
|
2010-01-17 14:20:29 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
wxPoint pt = GetScreen()->m_DrawOrg;
|
2010-02-22 16:45:35 +00:00
|
|
|
dc.SetLogicalOrigin( pt.x, pt.y );
|
2010-02-08 18:15:42 +00:00
|
|
|
}
|
2009-01-04 18:52:57 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
SetClipBox( dc ); // Reset the clip box to the entire screen.
|
2010-02-08 18:15:42 +00:00
|
|
|
GRResetPenAndBrush( &dc );
|
|
|
|
dc.SetBackgroundMode( wxTRANSPARENT );
|
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_PANEL::OnPaint( wxPaintEvent& event )
|
2008-03-06 01:46:30 +00:00
|
|
|
{
|
2009-06-26 17:24:32 +00:00
|
|
|
if( GetScreen() == NULL )
|
|
|
|
{
|
|
|
|
event.Skip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-02-08 18:15:42 +00:00
|
|
|
INSTALL_PAINTDC( paintDC, this );
|
2010-01-17 14:20:29 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
wxRect region = GetUpdateRegion().GetBox();
|
|
|
|
SetClipBox( paintDC, ®ion );
|
2011-02-08 14:48:38 +00:00
|
|
|
ReDraw( &paintDC, true );
|
2008-03-06 01:46:30 +00:00
|
|
|
}
|
|
|
|
|
2008-03-10 08:14:20 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_PANEL::ReDraw( wxDC* DC, bool erasebg )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
BASE_SCREEN* Screen = GetScreen();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
if( Screen == NULL )
|
2007-08-15 02:43:57 +00:00
|
|
|
return;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
COLOR4D bgColor = GetParent()->GetDrawBgColor();
|
2014-06-20 11:13:04 +00:00
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
// TODO(JE): Is this correct?
|
|
|
|
if( bgColor.GetBrightness() > 0.5 )
|
2007-08-22 05:11:01 +00:00
|
|
|
{
|
|
|
|
g_XorMode = GR_NXOR;
|
|
|
|
g_GhostColor = BLACK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_XorMode = GR_XOR;
|
|
|
|
g_GhostColor = WHITE;
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
GRResetPenAndBrush( DC );
|
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
DC->SetBackground( wxBrush( bgColor.ToColour() ) );
|
2011-02-08 14:48:38 +00:00
|
|
|
DC->SetBackgroundMode( wxSOLID );
|
2013-07-20 19:36:19 +00:00
|
|
|
|
|
|
|
if( erasebg )
|
|
|
|
EraseScreen( DC );
|
|
|
|
|
2011-02-09 19:47:33 +00:00
|
|
|
GetParent()->RedrawActiveWindow( DC, erasebg );
|
2011-02-08 14:48:38 +00:00
|
|
|
|
|
|
|
// Verfies that the clipping is working correctly. If these two sets of numbers are
|
|
|
|
// not the same or really close. The clipping algorithms are broken.
|
2017-09-21 12:58:08 +00:00
|
|
|
wxLogTrace( kicadTraceCoords,
|
2011-02-08 14:48:38 +00:00
|
|
|
wxT( "Clip box: (%d, %d, %d, %d), Draw extents (%d, %d, %d, %d)" ),
|
|
|
|
m_ClipBox.GetX(), m_ClipBox.GetY(), m_ClipBox.GetRight(), m_ClipBox.GetBottom(),
|
|
|
|
DC->MinX(), DC->MinY(), DC->MaxX(), DC->MaxY() );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2016-02-24 19:53:02 +00:00
|
|
|
void EDA_DRAW_PANEL::SetEnableMousewheelPan( bool aEnable )
|
|
|
|
{
|
|
|
|
m_enableMousewheelPan = aEnable;
|
|
|
|
|
2019-05-27 16:16:54 +00:00
|
|
|
GetParent()->GetGalCanvas()->GetViewControls()->EnableMousewheelPan( aEnable );
|
2016-02-24 19:53:02 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 22:04:52 +00:00
|
|
|
void EDA_DRAW_PANEL::SetEnableAutoPan( bool aEnable )
|
|
|
|
{
|
|
|
|
m_enableAutoPan = aEnable;
|
|
|
|
|
2019-05-27 16:16:54 +00:00
|
|
|
GetParent()->GetGalCanvas()->GetViewControls()->EnableAutoPan( aEnable );
|
2017-11-23 22:04:52 +00:00
|
|
|
}
|
|
|
|
|
2016-02-24 19:53:02 +00:00
|
|
|
|
2015-07-09 08:18:27 +00:00
|
|
|
void EDA_DRAW_PANEL::SetEnableZoomNoCenter( bool aEnable )
|
|
|
|
{
|
|
|
|
m_enableZoomNoCenter = aEnable;
|
|
|
|
|
2019-05-27 16:16:54 +00:00
|
|
|
GetParent()->GetGalCanvas()->GetViewControls()->EnableCursorWarping( !aEnable );
|
2015-07-09 08:18:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_PANEL::DrawBackGround( wxDC* DC )
|
2010-01-17 14:20:29 +00:00
|
|
|
{
|
|
|
|
GRSetDrawMode( DC, GR_COPY );
|
|
|
|
|
2011-02-09 19:47:33 +00:00
|
|
|
if( GetParent()->IsGridVisible() )
|
2010-01-17 14:20:29 +00:00
|
|
|
DrawGrid( DC );
|
|
|
|
|
2011-12-22 21:57:50 +00:00
|
|
|
// Draw axis
|
2018-08-03 11:51:41 +00:00
|
|
|
if( GetParent()->GetShowAxis() )
|
2010-01-17 14:20:29 +00:00
|
|
|
{
|
2018-02-07 14:00:26 +00:00
|
|
|
COLOR4D axis_color = COLOR4D( BLUE );
|
2011-12-22 21:57:50 +00:00
|
|
|
wxSize pageSize = GetParent()->GetPageSizeIU();
|
2010-01-17 14:20:29 +00:00
|
|
|
|
2011-12-22 21:57:50 +00:00
|
|
|
// Draw the Y axis
|
2015-10-25 16:58:04 +00:00
|
|
|
GRLine( &m_ClipBox, DC, 0, -pageSize.y, 0, pageSize.y, 0, axis_color );
|
2011-12-22 21:57:50 +00:00
|
|
|
|
|
|
|
// Draw the X axis
|
2015-10-25 16:58:04 +00:00
|
|
|
GRLine( &m_ClipBox, DC, -pageSize.x, 0, pageSize.x, 0, 0, axis_color );
|
2010-01-17 14:20:29 +00:00
|
|
|
}
|
|
|
|
|
2018-08-03 11:51:41 +00:00
|
|
|
if( GetParent()->GetShowOriginAxis() )
|
2010-01-17 14:20:29 +00:00
|
|
|
DrawAuxiliaryAxis( DC, GR_COPY );
|
2010-07-13 10:42:32 +00:00
|
|
|
|
2018-08-03 11:51:41 +00:00
|
|
|
if( GetParent()->GetShowGridAxis() )
|
2013-08-03 05:15:23 +00:00
|
|
|
DrawGridAxis( DC, GR_COPY, GetParent()->GetGridOrigin() );
|
2010-01-17 14:20:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-09 19:47:33 +00:00
|
|
|
void EDA_DRAW_PANEL::DrawGrid( wxDC* aDC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-09-23 14:04:08 +00:00
|
|
|
#define MIN_GRID_SIZE 10 // min grid size in pixels to allow drawing
|
2007-08-22 05:11:01 +00:00
|
|
|
BASE_SCREEN* screen = GetScreen();
|
2011-01-30 22:22:38 +00:00
|
|
|
wxRealPoint gridSize;
|
|
|
|
wxSize screenSize;
|
2007-08-22 05:11:01 +00:00
|
|
|
wxPoint org;
|
2011-01-30 22:22:38 +00:00
|
|
|
wxRealPoint screenGridSize;
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2007-12-09 09:00:15 +00:00
|
|
|
/* The grid must be visible. this is possible only is grid value
|
|
|
|
* and zoom value are sufficient
|
|
|
|
*/
|
2011-01-30 22:22:38 +00:00
|
|
|
gridSize = screen->GetGridSize();
|
|
|
|
screen->m_StartVisu = CalcUnscrolledPosition( wxPoint( 0, 0 ) );
|
|
|
|
screenSize = GetClientSize();
|
2010-02-08 18:15:42 +00:00
|
|
|
|
// 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;
}
2012-04-19 06:55:45 +00:00
|
|
|
screenGridSize.x = aDC->LogicalToDeviceXRel( KiROUND( gridSize.x ) );
|
|
|
|
screenGridSize.y = aDC->LogicalToDeviceYRel( KiROUND( gridSize.y ) );
|
2009-02-26 20:06:51 +00:00
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
org = m_ClipBox.GetPosition();
|
2010-01-17 14:20:29 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
if( screenGridSize.x < MIN_GRID_SIZE || screenGridSize.y < MIN_GRID_SIZE )
|
2007-08-22 05:11:01 +00:00
|
|
|
{
|
2011-01-30 22:22:38 +00:00
|
|
|
screenGridSize.x *= 2.0;
|
|
|
|
screenGridSize.y *= 2.0;
|
|
|
|
gridSize.x *= 2.0;
|
|
|
|
gridSize.y *= 2.0;
|
2007-08-22 05:11:01 +00:00
|
|
|
}
|
2007-12-09 09:00:15 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
if( screenGridSize.x < MIN_GRID_SIZE || screenGridSize.y < MIN_GRID_SIZE )
|
|
|
|
return;
|
2010-01-17 14:20:29 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
org = GetParent()->GetNearestGridPosition( org, &gridSize );
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2011-01-31 18:26:12 +00:00
|
|
|
// Setting the nearest grid position can select grid points outside the clip box.
|
|
|
|
// Incrementing the start point by one grid step should prevent drawing grid points
|
|
|
|
// outside the clip box.
|
|
|
|
if( org.x < m_ClipBox.GetX() )
|
// 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;
}
2012-04-19 06:55:45 +00:00
|
|
|
org.x += KiROUND( gridSize.x );
|
2011-01-31 18:26:12 +00:00
|
|
|
|
|
|
|
if( org.y < m_ClipBox.GetY() )
|
// 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;
}
2012-04-19 06:55:45 +00:00
|
|
|
org.y += KiROUND( gridSize.y );
|
2011-01-31 18:26:12 +00:00
|
|
|
|
2011-02-09 19:47:33 +00:00
|
|
|
// Use a pixel based draw to display grid. There are a lot of calls, so the cost is
|
2018-04-08 10:28:59 +00:00
|
|
|
// high and grid is slowly drawn on some platforms. Another way using blit transfert was used,
|
2015-12-27 12:16:46 +00:00
|
|
|
// a long time ago, but it did not give very good results.
|
|
|
|
// The better way is highly dependent on the platform and the graphic card.
|
2011-01-30 22:22:38 +00:00
|
|
|
int xpos;
|
|
|
|
double right = ( double ) m_ClipBox.GetRight();
|
|
|
|
double bottom = ( double ) m_ClipBox.GetBottom();
|
2010-01-14 08:55:45 +00:00
|
|
|
|
2018-02-07 14:00:26 +00:00
|
|
|
#if defined( USE_WX_GRAPHICS_CONTEXT )
|
2016-01-04 20:13:10 +00:00
|
|
|
wxGCDC *gcdc = wxDynamicCast( aDC, wxGCDC );
|
2018-02-07 14:00:26 +00:00
|
|
|
|
2016-01-04 20:13:10 +00:00
|
|
|
if( gcdc )
|
2010-09-19 10:23:53 +00:00
|
|
|
{
|
2018-02-07 14:00:26 +00:00
|
|
|
// Much faster grid drawing on systems using wxGraphicsContext
|
2016-01-04 20:13:10 +00:00
|
|
|
wxGraphicsContext *gc = gcdc->GetGraphicsContext();
|
|
|
|
|
|
|
|
// Grid point size
|
|
|
|
const int gsz = 1;
|
|
|
|
const double w = aDC->DeviceToLogicalXRel( gsz );
|
|
|
|
const double h = aDC->DeviceToLogicalYRel( gsz );
|
2010-09-19 10:23:53 +00:00
|
|
|
|
2016-01-04 20:13:10 +00:00
|
|
|
// Use our own pen
|
2017-02-22 19:06:49 +00:00
|
|
|
wxPen pen( GetParent()->GetGridColor().ToColour(), h );
|
2016-01-04 20:13:10 +00:00
|
|
|
pen.SetCap( wxCAP_BUTT );
|
|
|
|
gc->SetPen( pen );
|
|
|
|
|
|
|
|
// draw grid
|
|
|
|
wxGraphicsPath path = gc->CreatePath();
|
|
|
|
for( double x = (double) org.x - w/2.0; x <= right - w/2.0; x += gridSize.x )
|
2010-01-13 20:03:33 +00:00
|
|
|
{
|
2016-01-04 20:13:10 +00:00
|
|
|
for( double y = (double) org.y; y <= bottom; y += gridSize.y )
|
|
|
|
{
|
|
|
|
path.MoveToPoint( x, y );
|
|
|
|
path.AddLineToPoint( x+w, y );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gc->StrokePath( path );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
GRSetColorPen( aDC, GetParent()->GetGridColor() );
|
|
|
|
|
|
|
|
for( double x = (double) org.x; x <= right; x += gridSize.x )
|
|
|
|
{
|
|
|
|
xpos = KiROUND( x );
|
|
|
|
|
|
|
|
for( double y = (double) org.y; y <= bottom; y += gridSize.y )
|
|
|
|
{
|
|
|
|
aDC->DrawPoint( xpos, KiROUND( y ) );
|
|
|
|
}
|
2010-01-13 20:03:33 +00:00
|
|
|
}
|
2007-08-22 05:11:01 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2015-11-29 14:53:03 +00:00
|
|
|
// Set to 1 to draw auxirilary axis as lines, 0 to draw as target (circle with cross)
|
|
|
|
#define DRAW_AXIS_AS_LINES 0
|
|
|
|
// Size in pixels of the target shape
|
|
|
|
#define AXIS_SIZE_IN_PIXELS 15
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2012-09-01 13:38:27 +00:00
|
|
|
void EDA_DRAW_PANEL::DrawAuxiliaryAxis( wxDC* aDC, GR_DRAWMODE aDrawMode )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2013-08-03 05:15:23 +00:00
|
|
|
wxPoint origin = GetParent()->GetAuxOrigin();
|
2011-12-31 05:44:00 +00:00
|
|
|
|
|
|
|
if( origin == wxPoint( 0, 0 ) )
|
2007-08-22 05:11:01 +00:00
|
|
|
return;
|
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
COLOR4D color = COLOR4D( RED );
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2010-12-29 17:47:32 +00:00
|
|
|
GRSetDrawMode( aDC, aDrawMode );
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2015-11-29 14:53:03 +00:00
|
|
|
#if DRAW_AXIS_AS_LINES
|
|
|
|
wxSize pageSize = GetParent()->GetPageSizeIU();
|
2011-12-22 21:57:50 +00:00
|
|
|
// Draw the Y axis
|
2015-10-25 16:58:04 +00:00
|
|
|
GRLine( &m_ClipBox, aDC, origin.x, -pageSize.y,
|
|
|
|
origin.x, pageSize.y, 0, color );
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2011-12-22 21:57:50 +00:00
|
|
|
// Draw the X axis
|
2015-10-25 16:58:04 +00:00
|
|
|
GRLine( &m_ClipBox, aDC, -pageSize.x, origin.y,
|
|
|
|
pageSize.x, origin.y, 0, color );
|
2015-11-29 14:53:03 +00:00
|
|
|
#else
|
|
|
|
int radius = aDC->DeviceToLogicalXRel( AXIS_SIZE_IN_PIXELS );
|
|
|
|
int linewidth = aDC->DeviceToLogicalXRel( 1 );
|
|
|
|
|
|
|
|
GRSetColorPen( aDC, color, linewidth );
|
|
|
|
|
|
|
|
GRLine( &m_ClipBox, aDC, origin.x, origin.y-radius,
|
|
|
|
origin.x, origin.y+radius, 0, color );
|
|
|
|
|
|
|
|
// Draw the + shape
|
|
|
|
GRLine( &m_ClipBox, aDC, origin.x-radius, origin.y,
|
|
|
|
origin.x+radius, origin.y, 0, color );
|
|
|
|
|
|
|
|
GRCircle( &m_ClipBox, aDC, origin, radius, linewidth, color );
|
|
|
|
#endif
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
void EDA_DRAW_PANEL::DrawGridAxis( wxDC* aDC, GR_DRAWMODE aDrawMode, const wxPoint& aGridOrigin )
|
2010-07-13 10:42:32 +00:00
|
|
|
{
|
2018-08-03 11:51:41 +00:00
|
|
|
if( !GetParent()->GetShowGridAxis() || ( !aGridOrigin.x && !aGridOrigin.y ) )
|
2010-07-13 10:42:32 +00:00
|
|
|
return;
|
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
COLOR4D color = GetParent()->GetGridColor();
|
2010-07-13 10:42:32 +00:00
|
|
|
|
2010-12-29 17:47:32 +00:00
|
|
|
GRSetDrawMode( aDC, aDrawMode );
|
2010-07-13 10:42:32 +00:00
|
|
|
|
2015-11-29 14:53:03 +00:00
|
|
|
#if DRAW_AXIS_AS_LINES
|
|
|
|
wxSize pageSize = GetParent()->GetPageSizeIU();
|
2011-12-22 21:57:50 +00:00
|
|
|
// Draw the Y axis
|
2015-10-25 16:58:04 +00:00
|
|
|
GRLine( &m_ClipBox, aDC, aGridOrigin.x, -pageSize.y,
|
|
|
|
aGridOrigin.x, pageSize.y, 0, color );
|
2010-07-13 10:42:32 +00:00
|
|
|
|
2011-12-22 21:57:50 +00:00
|
|
|
// Draw the X axis
|
2015-10-25 16:58:04 +00:00
|
|
|
GRLine( &m_ClipBox, aDC, -pageSize.x, aGridOrigin.y,
|
|
|
|
pageSize.x, aGridOrigin.y, 0, color );
|
2015-11-29 14:53:03 +00:00
|
|
|
#else
|
|
|
|
int radius = aDC->DeviceToLogicalXRel( AXIS_SIZE_IN_PIXELS );
|
|
|
|
int linewidth = aDC->DeviceToLogicalXRel( 1 );
|
|
|
|
|
|
|
|
GRSetColorPen( aDC, GetParent()->GetGridColor(), linewidth );
|
|
|
|
|
|
|
|
GRLine( &m_ClipBox, aDC, aGridOrigin.x-radius, aGridOrigin.y-radius,
|
|
|
|
aGridOrigin.x+radius, aGridOrigin.y+radius, 0, color );
|
|
|
|
|
|
|
|
// Draw the X shape
|
|
|
|
GRLine( &m_ClipBox, aDC, aGridOrigin.x+radius, aGridOrigin.y-radius,
|
|
|
|
aGridOrigin.x-radius, aGridOrigin.y+radius, 0, color );
|
|
|
|
|
|
|
|
GRCircle( &m_ClipBox, aDC, aGridOrigin, radius, linewidth, color );
|
|
|
|
#endif
|
2010-07-13 10:42:32 +00:00
|
|
|
}
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
|
2015-07-22 23:33:50 +00:00
|
|
|
void EDA_DRAW_PANEL::OnMouseEntering( wxMouseEvent& aEvent )
|
|
|
|
{
|
|
|
|
// This is an ugly hack that fixes some cross hair display bugs when the mouse leaves the
|
|
|
|
// canvas area during middle button mouse panning.
|
|
|
|
if( m_cursorLevel != 0 )
|
|
|
|
m_cursorLevel = 0;
|
|
|
|
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_PANEL::OnMouseLeaving( wxMouseEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
if( m_mouseCaptureCallback == NULL ) // No command in progress.
|
2018-12-11 16:49:28 +00:00
|
|
|
SetAutoPanRequest( false );
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
if( !m_enableAutoPan || !m_requestAutoPan || m_ignoreMouseEvents )
|
2007-08-22 05:11:01 +00:00
|
|
|
return;
|
|
|
|
|
2013-06-10 13:23:58 +00:00
|
|
|
// Auto pan when mouse has left the client window
|
|
|
|
// Ensure the cross_hair position is updated,
|
|
|
|
// because it will be used to center the screen.
|
|
|
|
// We use a position inside the client window
|
2015-08-27 08:29:12 +00:00
|
|
|
wxRect area( wxPoint( 0, 0 ), GetClientSize() );
|
2013-06-10 13:23:58 +00:00
|
|
|
wxPoint cross_hair_pos = event.GetPosition();
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2015-08-27 08:29:12 +00:00
|
|
|
// Certain window managers (e.g. awesome wm) incorrectly trigger "on leave" event,
|
|
|
|
// therefore test if the cursor has really left the panel area
|
|
|
|
if( !area.Contains( cross_hair_pos ) )
|
|
|
|
{
|
|
|
|
INSTALL_UNBUFFERED_DC( dc, this );
|
|
|
|
cross_hair_pos.x = dc.DeviceToLogicalX( cross_hair_pos.x );
|
|
|
|
cross_hair_pos.y = dc.DeviceToLogicalY( cross_hair_pos.y );
|
2013-06-10 13:23:58 +00:00
|
|
|
|
2015-08-27 08:29:12 +00:00
|
|
|
GetParent()->SetCrossHairPosition( cross_hair_pos );
|
2013-06-10 13:23:58 +00:00
|
|
|
|
2015-08-27 08:29:12 +00:00
|
|
|
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED, ID_POPUP_ZOOM_CENTER );
|
|
|
|
cmd.SetEventObject( this );
|
|
|
|
GetEventHandler()->ProcessEvent( cmd );
|
|
|
|
}
|
2011-02-21 13:54:29 +00:00
|
|
|
|
|
|
|
event.Skip();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_PANEL::OnMouseWheel( wxMouseEvent& event )
|
2008-12-19 13:51:48 +00:00
|
|
|
{
|
2011-12-29 20:11:42 +00:00
|
|
|
if( m_ignoreMouseEvents )
|
2010-01-15 10:02:47 +00:00
|
|
|
return;
|
|
|
|
|
2010-01-17 14:20:29 +00:00
|
|
|
wxRect rect = wxRect( wxPoint( 0, 0 ), GetClientSize() );
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2012-04-23 21:56:26 +00:00
|
|
|
// Ignore scroll events if the cursor is outside the drawing area.
|
2009-01-07 15:59:49 +00:00
|
|
|
if( event.GetWheelRotation() == 0 || !GetParent()->IsEnabled()
|
2010-01-17 14:20:29 +00:00
|
|
|
|| !rect.Contains( event.GetPosition() ) )
|
2008-12-19 13:51:48 +00:00
|
|
|
{
|
2017-09-21 12:58:08 +00:00
|
|
|
wxLogTrace( kicadTraceCoords,
|
2011-02-09 19:47:33 +00:00
|
|
|
wxT( "OnMouseWheel() position(%d, %d) rectangle(%d, %d, %d, %d)" ),
|
2009-01-17 20:31:19 +00:00
|
|
|
event.GetPosition().x, event.GetPosition().y,
|
|
|
|
rect.x, rect.y, rect.width, rect.height );
|
2008-12-19 13:51:48 +00:00
|
|
|
event.Skip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-09 19:47:33 +00:00
|
|
|
INSTALL_UNBUFFERED_DC( dc, this );
|
2013-08-03 05:15:23 +00:00
|
|
|
GetParent()->SetCrossHairPosition( event.GetLogicalPosition( dc ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
|
2008-12-19 13:51:48 +00:00
|
|
|
cmd.SetEventObject( this );
|
|
|
|
|
2013-07-22 18:38:04 +00:00
|
|
|
bool offCenterReq = event.ControlDown() && event.ShiftDown();
|
|
|
|
offCenterReq = offCenterReq || m_enableZoomNoCenter;
|
|
|
|
|
2013-11-27 13:20:42 +00:00
|
|
|
int axis = event.GetWheelAxis();
|
2016-02-24 19:53:02 +00:00
|
|
|
int wheelRotation = event.GetWheelRotation();
|
|
|
|
|
|
|
|
if( m_enableMousewheelPan )
|
|
|
|
{
|
2017-01-17 15:36:31 +00:00
|
|
|
// MousewheelPAN + Ctrl = zooming
|
|
|
|
if( event.ControlDown() && !event.ShiftDown() )
|
|
|
|
{
|
|
|
|
if( wheelRotation > 0 )
|
|
|
|
cmd.SetId( ID_POPUP_ZOOM_IN );
|
|
|
|
else if( wheelRotation < 0)
|
|
|
|
cmd.SetId( ID_POPUP_ZOOM_OUT );
|
|
|
|
}
|
|
|
|
// MousewheelPAN + Shift = horizontal scrolling
|
|
|
|
// Without modifiers MousewheelPAN - just pan
|
2016-02-24 19:53:02 +00:00
|
|
|
else
|
2017-01-17 15:36:31 +00:00
|
|
|
{
|
2017-12-05 00:02:28 +00:00
|
|
|
if( event.ShiftDown() && !event.ControlDown() )
|
|
|
|
axis = wxMOUSE_WHEEL_HORIZONTAL;
|
|
|
|
|
2017-01-17 15:36:31 +00:00
|
|
|
wxPoint newStart = GetViewStart();
|
2017-12-05 00:02:28 +00:00
|
|
|
wxPoint center = GetParent()->GetScrollCenterPosition();
|
|
|
|
double scale = GetParent()->GetScreen()->GetScalingFactor();
|
|
|
|
|
2017-01-17 15:36:31 +00:00
|
|
|
if( axis == wxMOUSE_WHEEL_HORIZONTAL )
|
2017-12-05 00:02:28 +00:00
|
|
|
{
|
2017-01-17 15:36:31 +00:00
|
|
|
newStart.x += wheelRotation;
|
2017-12-05 00:02:28 +00:00
|
|
|
center.x += KiROUND( (double) wheelRotation / scale );
|
|
|
|
}
|
2017-01-17 15:36:31 +00:00
|
|
|
else
|
2017-12-05 00:02:28 +00:00
|
|
|
{
|
2017-01-17 15:36:31 +00:00
|
|
|
newStart.y -= wheelRotation;
|
2017-12-05 00:02:28 +00:00
|
|
|
center.y -= KiROUND( (double) wheelRotation / scale );
|
|
|
|
}
|
|
|
|
Scroll( newStart );
|
2017-01-17 15:36:31 +00:00
|
|
|
|
|
|
|
GetParent()->SetScrollCenterPosition( center );
|
2017-12-05 00:02:28 +00:00
|
|
|
GetParent()->SetCrossHairPosition( center, true );
|
2017-01-17 15:36:31 +00:00
|
|
|
}
|
2016-02-24 19:53:02 +00:00
|
|
|
}
|
|
|
|
else if( wheelRotation > 0 )
|
2008-12-19 13:51:48 +00:00
|
|
|
{
|
|
|
|
if( event.ShiftDown() && !event.ControlDown() )
|
2016-03-01 20:19:00 +00:00
|
|
|
cmd.SetId( ID_PAN_UP );
|
2008-12-19 13:51:48 +00:00
|
|
|
else if( event.ControlDown() && !event.ShiftDown() )
|
|
|
|
cmd.SetId( ID_PAN_LEFT );
|
2013-07-22 18:38:04 +00:00
|
|
|
else if( offCenterReq )
|
2013-02-02 19:10:48 +00:00
|
|
|
cmd.SetId( ID_OFFCENTER_ZOOM_IN );
|
2008-12-19 13:51:48 +00:00
|
|
|
else
|
|
|
|
cmd.SetId( ID_POPUP_ZOOM_IN );
|
|
|
|
}
|
2016-02-24 19:53:02 +00:00
|
|
|
else if( wheelRotation < 0 )
|
2008-12-19 13:51:48 +00:00
|
|
|
{
|
|
|
|
if( event.ShiftDown() && !event.ControlDown() )
|
2016-03-01 20:19:00 +00:00
|
|
|
cmd.SetId( ID_PAN_DOWN );
|
2008-12-19 13:51:48 +00:00
|
|
|
else if( event.ControlDown() && !event.ShiftDown() )
|
|
|
|
cmd.SetId( ID_PAN_RIGHT );
|
2013-07-22 18:38:04 +00:00
|
|
|
else if( offCenterReq )
|
2013-02-02 19:10:48 +00:00
|
|
|
cmd.SetId( ID_OFFCENTER_ZOOM_OUT );
|
2008-12-19 13:51:48 +00:00
|
|
|
else
|
|
|
|
cmd.SetId( ID_POPUP_ZOOM_OUT );
|
|
|
|
}
|
|
|
|
|
2016-02-24 19:53:02 +00:00
|
|
|
if( cmd.GetId() )
|
|
|
|
GetEventHandler()->ProcessEvent( cmd );
|
2010-02-22 16:45:35 +00:00
|
|
|
event.Skip();
|
2008-12-19 13:51:48 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2016-01-25 00:18:29 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
|
2015-05-21 20:54:29 +00:00
|
|
|
void EDA_DRAW_PANEL::OnMagnify( wxMouseEvent& event )
|
|
|
|
{
|
|
|
|
// Scale the panel around our cursor position.
|
|
|
|
bool warpCursor = false;
|
|
|
|
|
|
|
|
wxPoint cursorPosition = GetParent()->GetCursorPosition( false );
|
|
|
|
wxPoint centerPosition = GetParent()->GetScrollCenterPosition();
|
|
|
|
wxPoint vector = centerPosition - cursorPosition;
|
|
|
|
|
|
|
|
double magnification = ( event.GetMagnification() + 1.0f );
|
|
|
|
double scaleFactor = GetZoom() / magnification;
|
|
|
|
|
|
|
|
// Scale the vector between the cursor and center point
|
|
|
|
vector.x /= magnification;
|
|
|
|
vector.y /= magnification;
|
|
|
|
|
|
|
|
SetZoom(scaleFactor);
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2011-12-17 21:21:03 +00:00
|
|
|
void EDA_DRAW_PANEL::OnCharHook( wxKeyEvent& event )
|
|
|
|
{
|
2018-04-13 13:58:25 +00:00
|
|
|
wxLogTrace( kicadTraceKeyEvent, "EDA_DRAW_PANEL::OnCharHook %s", dump( event ) );
|
2011-12-17 21:21:03 +00:00
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2018-02-07 14:00:26 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_PANEL::OnPan( wxCommandEvent& event )
|
2008-12-19 13:51:48 +00:00
|
|
|
{
|
2010-01-17 14:20:29 +00:00
|
|
|
int x, y;
|
2010-02-22 16:45:35 +00:00
|
|
|
int ppux, ppuy;
|
|
|
|
int unitsX, unitsY;
|
|
|
|
int maxX, maxY;
|
2015-07-22 23:33:50 +00:00
|
|
|
int tmpX, tmpY;
|
2008-12-19 13:51:48 +00:00
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
GetViewStart( &x, &y );
|
|
|
|
GetScrollPixelsPerUnit( &ppux, &ppuy );
|
|
|
|
GetVirtualSize( &unitsX, &unitsY );
|
2015-07-22 23:33:50 +00:00
|
|
|
tmpX = x;
|
|
|
|
tmpY = y;
|
2010-02-22 16:45:35 +00:00
|
|
|
maxX = unitsX;
|
|
|
|
maxY = unitsY;
|
|
|
|
unitsX /= ppux;
|
|
|
|
unitsY /= ppuy;
|
2008-12-19 13:51:48 +00:00
|
|
|
|
2017-09-21 12:58:08 +00:00
|
|
|
wxLogTrace( kicadTraceCoords,
|
2015-07-22 23:33:50 +00:00
|
|
|
wxT( "Scroll center position before pan: (%d, %d)" ), tmpX, tmpY );
|
|
|
|
|
2008-12-19 13:51:48 +00:00
|
|
|
switch( event.GetId() )
|
|
|
|
{
|
|
|
|
case ID_PAN_UP:
|
2010-02-08 18:15:42 +00:00
|
|
|
y -= m_scrollIncrementY;
|
2008-12-19 13:51:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_PAN_DOWN:
|
2010-02-08 18:15:42 +00:00
|
|
|
y += m_scrollIncrementY;
|
2008-12-19 13:51:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_PAN_LEFT:
|
2010-02-08 18:15:42 +00:00
|
|
|
x -= m_scrollIncrementX;
|
2008-12-19 13:51:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_PAN_RIGHT:
|
2010-02-08 18:15:42 +00:00
|
|
|
x += m_scrollIncrementX;
|
2008-12-19 13:51:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-01-21 19:30:59 +00:00
|
|
|
wxLogDebug( wxT( "Unknown ID %d in EDA_DRAW_PANEL::OnPan()." ), event.GetId() );
|
2008-12-19 13:51:48 +00:00
|
|
|
}
|
|
|
|
|
2015-07-22 23:33:50 +00:00
|
|
|
bool updateCenterScrollPos = true;
|
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
if( x < 0 )
|
2015-07-22 23:33:50 +00:00
|
|
|
{
|
2010-02-22 16:45:35 +00:00
|
|
|
x = 0;
|
2015-07-22 23:33:50 +00:00
|
|
|
updateCenterScrollPos = false;
|
|
|
|
}
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
if( y < 0 )
|
2015-07-22 23:33:50 +00:00
|
|
|
{
|
2010-02-22 16:45:35 +00:00
|
|
|
y = 0;
|
2015-07-22 23:33:50 +00:00
|
|
|
updateCenterScrollPos = false;
|
|
|
|
}
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
if( x > maxX )
|
2015-07-22 23:33:50 +00:00
|
|
|
{
|
2010-02-22 16:45:35 +00:00
|
|
|
x = maxX;
|
2015-07-22 23:33:50 +00:00
|
|
|
updateCenterScrollPos = false;
|
|
|
|
}
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
if( y > maxY )
|
2015-07-22 23:33:50 +00:00
|
|
|
{
|
2010-02-22 16:45:35 +00:00
|
|
|
y = maxY;
|
2015-07-22 23:33:50 +00:00
|
|
|
updateCenterScrollPos = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't update the scroll position beyond the scroll limits.
|
|
|
|
if( updateCenterScrollPos )
|
|
|
|
{
|
|
|
|
double scale = GetParent()->GetScreen()->GetScalingFactor();
|
|
|
|
|
|
|
|
wxPoint center = GetParent()->GetScrollCenterPosition();
|
|
|
|
center.x += KiROUND( (double) ( x - tmpX ) / scale );
|
|
|
|
center.y += KiROUND( (double) ( y - tmpY ) / scale );
|
|
|
|
GetParent()->SetScrollCenterPosition( center );
|
|
|
|
|
2017-09-21 12:58:08 +00:00
|
|
|
wxLogTrace( kicadTraceCoords,
|
2015-07-22 23:33:50 +00:00
|
|
|
wxT( "Scroll center position after pan: (%d, %d)" ), center.x, center.y );
|
|
|
|
}
|
2010-02-22 16:45:35 +00:00
|
|
|
|
2010-02-23 20:22:31 +00:00
|
|
|
Scroll( x/ppux, y/ppuy );
|
2008-12-19 13:51:48 +00:00
|
|
|
}
|
2009-09-14 13:24:17 +00:00
|
|
|
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
void EDA_DRAW_PANEL::EndMouseCapture( int id, int cursor, const wxString& title,
|
|
|
|
bool aCallEndFunc )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2011-11-10 15:55:05 +00:00
|
|
|
if( m_mouseCaptureCallback && m_endMouseCaptureCallback && aCallEndFunc )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2011-01-30 22:22:38 +00:00
|
|
|
INSTALL_UNBUFFERED_DC( dc, this );
|
2011-02-11 20:48:13 +00:00
|
|
|
m_endMouseCaptureCallback( this, &dc );
|
2009-12-20 19:48:58 +00:00
|
|
|
}
|
2011-02-24 20:22:12 +00:00
|
|
|
|
2011-02-17 18:34:27 +00:00
|
|
|
m_mouseCaptureCallback = NULL;
|
|
|
|
m_endMouseCaptureCallback = NULL;
|
2018-12-11 16:49:28 +00:00
|
|
|
SetAutoPanRequest( false );
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2009-12-20 19:48:58 +00:00
|
|
|
if( id != -1 && cursor != -1 )
|
|
|
|
{
|
|
|
|
wxASSERT( cursor > wxCURSOR_NONE && cursor < wxCURSOR_MAX );
|
2011-02-09 19:47:33 +00:00
|
|
|
GetParent()->SetToolID( id, cursor, title );
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-29 20:11:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
void EDA_DRAW_PANEL::CallMouseCapture( wxDC* aDC, const wxPoint& aPosition, bool aErase )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( aDC != NULL, wxT( "Invalid device context." ) );
|
|
|
|
wxCHECK_RET( m_mouseCaptureCallback != NULL, wxT( "Mouse capture callback not set." ) );
|
|
|
|
|
|
|
|
m_mouseCaptureCallback( this, aDC, aPosition, aErase );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_DRAW_PANEL::CallEndMouseCapture( wxDC* aDC )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( aDC != NULL, wxT( "Invalid device context." ) );
|
|
|
|
|
2015-05-03 06:31:14 +00:00
|
|
|
// CallEndMouseCapture is sometimes called with m_endMouseCaptureCallback == NULL
|
|
|
|
// for instance after an ABORT in block paste.
|
|
|
|
if( m_endMouseCaptureCallback )
|
|
|
|
m_endMouseCaptureCallback( this, aDC );
|
2011-12-29 20:11:42 +00:00
|
|
|
}
|