2011-10-19 20:32:21 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eeschema/controle.cpp
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <eda_dde.h>
|
|
|
|
#include <wxEeschemaStruct.h>
|
2012-04-09 09:16:47 +00:00
|
|
|
#include <menus_helpers.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <eeschema_id.h>
|
|
|
|
#include <general.h>
|
|
|
|
#include <hotkeys.h>
|
|
|
|
#include <protos.h>
|
|
|
|
#include <libeditframe.h>
|
|
|
|
#include <viewlib_frame.h>
|
|
|
|
#include <lib_draw_item.h>
|
|
|
|
#include <lib_pin.h>
|
|
|
|
#include <sch_sheet.h>
|
|
|
|
#include <sch_sheet_path.h>
|
|
|
|
#include <sch_marker.h>
|
|
|
|
#include <sch_component.h>
|
2009-07-07 17:50:02 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
SCH_ITEM* SCH_EDIT_FRAME::LocateAndShowItem( const wxPoint& aPosition, const KICAD_T aFilterList[],
|
|
|
|
int aHotKeyCommandId )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2011-02-02 19:01:21 +00:00
|
|
|
SCH_ITEM* item;
|
2009-01-31 10:05:16 +00:00
|
|
|
wxString msg;
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_PIN* Pin = NULL;
|
2008-03-20 01:50:21 +00:00
|
|
|
SCH_COMPONENT* LibItem = NULL;
|
2011-02-02 19:01:21 +00:00
|
|
|
wxPoint gridPosition = GetScreen()->GetNearestGridPosition( aPosition );
|
2007-08-14 19:24:48 +00:00
|
|
|
|
2012-08-11 12:52:13 +00:00
|
|
|
// Check the on grid position first. There is more likely to be multiple items on
|
2011-03-25 19:16:05 +00:00
|
|
|
// grid than off grid.
|
|
|
|
item = LocateItem( gridPosition, aFilterList, aHotKeyCommandId );
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
// If the user aborted the clarification context menu, don't show it again at the
|
|
|
|
// off grid position.
|
2011-12-29 20:11:42 +00:00
|
|
|
if( !item && m_canvas->GetAbortRequest() )
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetAbortRequest( false );
|
2011-03-25 19:16:05 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !item && (aPosition != gridPosition) )
|
|
|
|
item = LocateItem( aPosition, aFilterList, aHotKeyCommandId );
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2011-02-02 19:01:21 +00:00
|
|
|
if( !item )
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetAbortRequest( false ); // Just in case the user aborted the context menu.
|
2007-08-14 19:24:48 +00:00
|
|
|
return NULL;
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
2007-08-14 19:24:48 +00:00
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
/* Cross probing to Pcbnew if a pin or a component is found */
|
2011-02-02 19:01:21 +00:00
|
|
|
switch( item->Type() )
|
2007-08-14 19:24:48 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_FIELD_T:
|
|
|
|
case LIB_FIELD_T:
|
2011-02-02 19:01:21 +00:00
|
|
|
LibItem = (SCH_COMPONENT*) item->GetParent();
|
|
|
|
SendMessageToPCBNEW( item, LibItem );
|
2007-08-14 19:24:48 +00:00
|
|
|
break;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_COMPONENT_T:
|
2011-02-02 19:01:21 +00:00
|
|
|
LibItem = (SCH_COMPONENT*) item;
|
|
|
|
SendMessageToPCBNEW( item, LibItem );
|
2007-08-14 19:24:48 +00:00
|
|
|
break;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
case LIB_PIN_T:
|
2011-02-02 19:01:21 +00:00
|
|
|
Pin = (LIB_PIN*) item;
|
2011-05-07 08:13:09 +00:00
|
|
|
LibItem = (SCH_COMPONENT*) LocateItem( aPosition, SCH_COLLECTOR::ComponentsOnly );
|
2007-08-14 19:24:48 +00:00
|
|
|
break;
|
2011-03-25 19:16:05 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
;
|
2007-08-14 19:24:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( Pin )
|
|
|
|
{
|
2011-02-02 19:01:21 +00:00
|
|
|
// Force display pin information (the previous display could be a component info)
|
2009-04-17 08:51:02 +00:00
|
|
|
Pin->DisplayInfo( this );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2007-08-14 19:24:48 +00:00
|
|
|
if( LibItem )
|
2011-12-08 21:05:43 +00:00
|
|
|
AppendMsgPanel( LibItem->GetRef( m_CurrentSheet ),
|
2009-10-14 19:43:31 +00:00
|
|
|
LibItem->GetField( VALUE )->m_Text, DARKCYAN );
|
2007-08-14 19:24:48 +00:00
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
// Cross probing:2 - pin found, and send a locate pin command to Pcbnew (highlight net)
|
2008-02-29 20:35:11 +00:00
|
|
|
SendMessageToPCBNEW( Pin, LibItem );
|
2007-08-14 19:24:48 +00:00
|
|
|
}
|
2011-02-02 19:01:21 +00:00
|
|
|
|
|
|
|
return item;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, const KICAD_T aFilterList[],
|
|
|
|
int aHotKeyCommandId )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
SCH_ITEM* item = NULL;
|
2007-08-14 19:24:48 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
m_collectedItems.Collect( GetScreen()->GetDrawItems(), aFilterList, aPosition );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
if( m_collectedItems.GetCount() == 0 )
|
2007-08-14 19:24:48 +00:00
|
|
|
{
|
2009-10-14 19:43:31 +00:00
|
|
|
ClearMsgPanel();
|
2007-08-14 19:24:48 +00:00
|
|
|
}
|
2011-03-25 19:16:05 +00:00
|
|
|
else if( m_collectedItems.GetCount() == 1 )
|
2007-08-14 19:24:48 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
item = m_collectedItems[0];
|
2007-08-14 19:24:48 +00:00
|
|
|
}
|
2011-03-25 19:16:05 +00:00
|
|
|
else
|
2007-08-14 19:24:48 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
// There are certain combinations of items that do not need clarification such as
|
|
|
|
// a corner were two lines meet or all the items form a junction.
|
|
|
|
if( aHotKeyCommandId )
|
2007-08-14 19:24:48 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
switch( aHotKeyCommandId )
|
|
|
|
{
|
|
|
|
case HK_DRAG:
|
2011-05-20 19:21:09 +00:00
|
|
|
if( m_collectedItems.IsCorner() || m_collectedItems.IsNode( false )
|
|
|
|
|| m_collectedItems.IsDraggableJunction() )
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
|
|
|
item = m_collectedItems[0];
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
2007-08-14 19:24:48 +00:00
|
|
|
}
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
if( item == NULL )
|
|
|
|
{
|
|
|
|
wxASSERT_MSG( m_collectedItems.GetCount() <= MAX_SELECT_ITEM_IDS,
|
|
|
|
wxT( "Select item clarification context menu size limit exceeded." ) );
|
|
|
|
|
|
|
|
wxMenu selectMenu;
|
|
|
|
wxMenuItem* title = new wxMenuItem( &selectMenu, wxID_NONE, _( "Clarify Selection" ) );
|
|
|
|
|
|
|
|
selectMenu.Append( title );
|
|
|
|
selectMenu.AppendSeparator();
|
|
|
|
|
|
|
|
for( int i = 0; i < m_collectedItems.GetCount() && i < MAX_SELECT_ITEM_IDS; i++ )
|
|
|
|
{
|
|
|
|
wxString text = m_collectedItems[i]->GetSelectMenuText();
|
2011-08-29 03:04:59 +00:00
|
|
|
BITMAP_DEF xpm = m_collectedItems[i]->GetMenuImage();
|
2011-09-08 05:58:45 +00:00
|
|
|
AddMenuItem( &selectMenu, ID_SELECT_ITEM_START + i, text, KiBitmap( xpm ) );
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set to NULL in case user aborts the clarification context menu.
|
|
|
|
GetScreen()->SetCurItem( NULL );
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetAbortRequest( true ); // Changed to false if an item is selected
|
2011-03-25 19:16:05 +00:00
|
|
|
PopupMenu( &selectMenu );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2011-03-25 19:16:05 +00:00
|
|
|
item = GetScreen()->GetCurItem();
|
|
|
|
}
|
2007-08-14 19:24:48 +00:00
|
|
|
}
|
|
|
|
|
2011-10-19 20:32:21 +00:00
|
|
|
GetScreen()->SetCurItem( item );
|
|
|
|
|
2011-02-02 19:01:21 +00:00
|
|
|
if( item )
|
2011-03-25 19:16:05 +00:00
|
|
|
item->DisplayInfo( this );
|
|
|
|
else
|
2010-07-21 01:37:34 +00:00
|
|
|
ClearMsgPanel();
|
2007-08-14 19:24:48 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
return item;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-22 16:43:03 +00:00
|
|
|
void SCH_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey )
|
2008-04-21 06:34:56 +00:00
|
|
|
{
|
2011-02-01 15:46:25 +00:00
|
|
|
wxRealPoint gridSize;
|
2009-01-31 10:05:16 +00:00
|
|
|
SCH_SCREEN* screen = GetScreen();
|
2011-02-01 15:46:25 +00:00
|
|
|
wxPoint oldpos;
|
|
|
|
wxPoint pos = aPosition;
|
2008-04-21 06:34:56 +00:00
|
|
|
|
2012-08-11 12:52:13 +00:00
|
|
|
// when moving mouse, use the "magnetic" grid, unless the shift+ctrl keys is pressed
|
|
|
|
// for next cursor position
|
|
|
|
// ( shift or ctrl key down are PAN command with mouse wheel)
|
|
|
|
bool snapToGrid = true;
|
|
|
|
if( !aHotKey && wxGetKeyState( WXK_SHIFT ) && wxGetKeyState( WXK_CONTROL ) )
|
|
|
|
snapToGrid = false;
|
|
|
|
|
2012-08-21 10:45:54 +00:00
|
|
|
// Cursor is left off grid only if no block in progress
|
|
|
|
if( GetScreen()->m_BlockLocate.GetState() != STATE_NO_BLOCK )
|
|
|
|
snapToGrid = true;
|
|
|
|
|
2012-08-11 12:52:13 +00:00
|
|
|
if( snapToGrid )
|
|
|
|
pos = screen->GetNearestGridPosition( pos );
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
oldpos = screen->GetCrossHairPosition();
|
2011-02-01 15:46:25 +00:00
|
|
|
gridSize = screen->GetGridSize();
|
2008-04-21 06:34:56 +00:00
|
|
|
|
2011-02-22 16:43:03 +00:00
|
|
|
switch( aHotKey )
|
2008-04-21 06:34:56 +00:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
case WXK_NUMPAD8:
|
2008-04-21 06:34:56 +00:00
|
|
|
case WXK_UP:
|
// 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
|
|
|
pos.y -= KiROUND( gridSize.y );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursor( pos );
|
2008-04-21 06:34:56 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
case WXK_NUMPAD2:
|
2008-04-21 06:34:56 +00:00
|
|
|
case WXK_DOWN:
|
// 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
|
|
|
pos.y += KiROUND( gridSize.y );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursor( pos );
|
2008-04-21 06:34:56 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
case WXK_NUMPAD4:
|
2008-04-21 06:34:56 +00:00
|
|
|
case WXK_LEFT:
|
// 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
|
|
|
pos.x -= KiROUND( gridSize.x );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursor( pos );
|
2008-04-21 06:34:56 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
case WXK_NUMPAD6:
|
2008-04-21 06:34:56 +00:00
|
|
|
case WXK_RIGHT:
|
// 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
|
|
|
pos.x += KiROUND( gridSize.x );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursor( pos );
|
2008-04-21 06:34:56 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-02-01 15:46:25 +00:00
|
|
|
// Update cursor position.
|
2012-08-11 12:52:13 +00:00
|
|
|
screen->SetCrossHairPosition( pos, snapToGrid );
|
2008-04-21 06:34:56 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
if( oldpos != screen->GetCrossHairPosition() )
|
2008-04-21 06:34:56 +00:00
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
pos = screen->GetCrossHairPosition();
|
2012-08-11 12:52:13 +00:00
|
|
|
screen->SetCrossHairPosition( oldpos, false);
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->CrossHairOff( aDC );
|
2012-08-11 12:52:13 +00:00
|
|
|
screen->SetCrossHairPosition( pos, snapToGrid );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->CrossHairOn( aDC );
|
2008-04-21 06:34:56 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
if( m_canvas->IsMouseCaptured() )
|
2008-04-21 06:34:56 +00:00
|
|
|
{
|
2011-05-20 18:25:11 +00:00
|
|
|
#ifdef USE_WX_OVERLAY
|
2011-12-29 20:11:42 +00:00
|
|
|
wxDCOverlay oDC( m_overlay, (wxWindowDC*)aDC );
|
2011-05-20 18:25:11 +00:00
|
|
|
oDC.Clear();
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( aDC, aPosition, false );
|
2011-05-20 18:25:11 +00:00
|
|
|
#else
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( aDC, aPosition, true );
|
2011-05-20 18:25:11 +00:00
|
|
|
#endif
|
2008-04-21 06:34:56 +00:00
|
|
|
}
|
2011-05-20 18:25:11 +00:00
|
|
|
#ifdef USE_WX_OVERLAY
|
|
|
|
else
|
2011-12-29 20:11:42 +00:00
|
|
|
{
|
|
|
|
m_overlay.Reset();
|
|
|
|
}
|
2011-05-20 18:25:11 +00:00
|
|
|
#endif
|
2008-04-21 06:34:56 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 16:43:03 +00:00
|
|
|
if( aHotKey )
|
2008-04-21 06:34:56 +00:00
|
|
|
{
|
2011-03-10 19:36:30 +00:00
|
|
|
if( screen->GetCurItem() && screen->GetCurItem()->GetFlags() )
|
2011-02-22 16:43:03 +00:00
|
|
|
OnHotKey( aDC, aHotKey, aPosition, screen->GetCurItem() );
|
2008-04-21 06:34:56 +00:00
|
|
|
else
|
2011-02-22 16:43:03 +00:00
|
|
|
OnHotKey( aDC, aHotKey, aPosition, NULL );
|
2008-04-21 06:34:56 +00:00
|
|
|
}
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
UpdateStatusBar(); /* Display cursor coordinates info */
|
2008-04-21 06:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-22 16:43:03 +00:00
|
|
|
void LIB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey )
|
2008-04-21 06:34:56 +00:00
|
|
|
{
|
2011-02-01 15:46:25 +00:00
|
|
|
wxRealPoint gridSize;
|
2009-01-31 10:05:16 +00:00
|
|
|
SCH_SCREEN* screen = GetScreen();
|
2011-02-01 15:46:25 +00:00
|
|
|
wxPoint oldpos;
|
|
|
|
wxPoint pos = aPosition;
|
2008-04-21 06:34:56 +00:00
|
|
|
|
2012-08-11 12:52:13 +00:00
|
|
|
// when moving mouse, use the "magnetic" grid, unless the shift+ctrl keys is pressed
|
|
|
|
// for next cursor position
|
|
|
|
// ( shift or ctrl key down are PAN command with mouse wheel)
|
|
|
|
bool snapToGrid = true;
|
|
|
|
if( !aHotKey && wxGetKeyState( WXK_SHIFT ) && wxGetKeyState( WXK_CONTROL ) )
|
|
|
|
snapToGrid = false;
|
|
|
|
|
2012-08-21 10:45:54 +00:00
|
|
|
// Cursor is left off grid only if no block in progress
|
|
|
|
if( GetScreen()->m_BlockLocate.GetState() != STATE_NO_BLOCK )
|
|
|
|
snapToGrid = true;
|
|
|
|
|
2012-08-11 12:52:13 +00:00
|
|
|
if( snapToGrid )
|
|
|
|
pos = screen->GetNearestGridPosition( pos );
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
oldpos = screen->GetCrossHairPosition();
|
2011-02-01 15:46:25 +00:00
|
|
|
gridSize = screen->GetGridSize();
|
2008-04-21 06:34:56 +00:00
|
|
|
|
2011-02-22 16:43:03 +00:00
|
|
|
switch( aHotKey )
|
2008-04-21 06:34:56 +00:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
case WXK_NUMPAD8:
|
2008-04-21 06:34:56 +00:00
|
|
|
case WXK_UP:
|
// 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
|
|
|
pos.y -= KiROUND( gridSize.y );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursor( pos );
|
2008-04-21 06:34:56 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
case WXK_NUMPAD2:
|
2008-04-21 06:34:56 +00:00
|
|
|
case WXK_DOWN:
|
// 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
|
|
|
pos.y += KiROUND( gridSize.y );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursor( pos );
|
2008-04-21 06:34:56 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
case WXK_NUMPAD4:
|
2008-04-21 06:34:56 +00:00
|
|
|
case WXK_LEFT:
|
// 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
|
|
|
pos.x -= KiROUND( gridSize.x );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursor( pos );
|
2008-04-21 06:34:56 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
case WXK_NUMPAD6:
|
2008-04-21 06:34:56 +00:00
|
|
|
case WXK_RIGHT:
|
// 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
|
|
|
pos.x += KiROUND( gridSize.x );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursor( pos );
|
2008-04-21 06:34:56 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-02-01 15:46:25 +00:00
|
|
|
// Update the cursor position.
|
2012-08-11 12:52:13 +00:00
|
|
|
screen->SetCrossHairPosition( pos, snapToGrid );
|
2008-04-21 06:34:56 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
if( oldpos != screen->GetCrossHairPosition() )
|
2008-04-21 06:34:56 +00:00
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
pos = screen->GetCrossHairPosition();
|
2012-08-11 12:52:13 +00:00
|
|
|
screen->SetCrossHairPosition( oldpos, false );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->CrossHairOff( aDC );
|
2012-08-11 12:52:13 +00:00
|
|
|
screen->SetCrossHairPosition( pos, snapToGrid );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->CrossHairOn( aDC );
|
2008-04-21 06:34:56 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
if( m_canvas->IsMouseCaptured() )
|
2008-04-21 06:34:56 +00:00
|
|
|
{
|
2011-05-20 18:25:11 +00:00
|
|
|
#ifdef USE_WX_OVERLAY
|
2011-12-29 20:11:42 +00:00
|
|
|
wxDCOverlay oDC( m_overlay, (wxWindowDC*)aDC );
|
2011-05-20 18:25:11 +00:00
|
|
|
oDC.Clear();
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( aDC, aPosition, false );
|
2011-05-20 18:25:11 +00:00
|
|
|
#else
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( aDC, aPosition, true );
|
2011-05-20 18:25:11 +00:00
|
|
|
#endif
|
2008-04-21 06:34:56 +00:00
|
|
|
}
|
2011-05-20 18:25:11 +00:00
|
|
|
#ifdef USE_WX_OVERLAY
|
|
|
|
else
|
2011-12-29 20:11:42 +00:00
|
|
|
{
|
|
|
|
m_overlay.Reset();
|
|
|
|
}
|
2011-05-20 18:25:11 +00:00
|
|
|
#endif
|
2008-04-21 06:34:56 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 16:43:03 +00:00
|
|
|
if( aHotKey )
|
2008-04-21 06:34:56 +00:00
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
OnHotKey( aDC, aHotKey, aPosition, NULL );
|
2008-04-21 06:34:56 +00:00
|
|
|
}
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
UpdateStatusBar();
|
2008-04-21 06:34:56 +00:00
|
|
|
}
|
|
|
|
|
2009-01-31 10:05:16 +00:00
|
|
|
|
2011-02-22 16:43:03 +00:00
|
|
|
void LIB_VIEW_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-02-01 15:46:25 +00:00
|
|
|
wxRealPoint gridSize;
|
2009-01-31 10:05:16 +00:00
|
|
|
SCH_SCREEN* screen = GetScreen();
|
2011-02-01 15:46:25 +00:00
|
|
|
wxPoint oldpos;
|
|
|
|
wxPoint pos = aPosition;
|
2007-08-14 19:24:48 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
pos = screen->GetNearestGridPosition( pos );
|
|
|
|
oldpos = screen->GetCrossHairPosition();
|
2011-02-01 15:46:25 +00:00
|
|
|
gridSize = screen->GetGridSize();
|
2007-08-14 19:24:48 +00:00
|
|
|
|
2011-02-22 16:43:03 +00:00
|
|
|
switch( aHotKey )
|
2007-08-14 19:24:48 +00:00
|
|
|
{
|
2007-08-30 08:15:05 +00:00
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
case WXK_NUMPAD8:
|
2007-08-14 19:24:48 +00:00
|
|
|
case WXK_UP:
|
// 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
|
|
|
pos.y -= KiROUND( gridSize.y );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursor( pos );
|
2007-08-14 19:24:48 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
case WXK_NUMPAD2:
|
2007-08-14 19:24:48 +00:00
|
|
|
case WXK_DOWN:
|
// 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
|
|
|
pos.y += KiROUND( gridSize.y );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursor( pos );
|
2007-08-14 19:24:48 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
case WXK_NUMPAD4:
|
2007-08-14 19:24:48 +00:00
|
|
|
case WXK_LEFT:
|
// 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
|
|
|
pos.x -= KiROUND( gridSize.x );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursor( pos );
|
2007-08-14 19:24:48 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
case WXK_NUMPAD6:
|
2007-08-14 19:24:48 +00:00
|
|
|
case WXK_RIGHT:
|
// 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
|
|
|
pos.x += KiROUND( gridSize.x );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursor( pos );
|
2007-08-14 19:24:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-02-01 15:46:25 +00:00
|
|
|
// Update cursor position.
|
2011-02-11 20:48:13 +00:00
|
|
|
screen->SetCrossHairPosition( pos );
|
2007-08-14 19:24:48 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
if( oldpos != screen->GetCrossHairPosition() )
|
2007-08-14 19:24:48 +00:00
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
pos = screen->GetCrossHairPosition();
|
|
|
|
screen->SetCrossHairPosition( oldpos );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->CrossHairOff( aDC );
|
2011-02-11 20:48:13 +00:00
|
|
|
screen->SetCrossHairPosition( pos );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->CrossHairOn( aDC );
|
2007-08-14 19:24:48 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
if( m_canvas->IsMouseCaptured() )
|
2007-08-14 19:24:48 +00:00
|
|
|
{
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( aDC, aPosition, true );
|
2007-08-14 19:24:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-22 16:43:03 +00:00
|
|
|
if( aHotKey )
|
2007-08-14 19:24:48 +00:00
|
|
|
{
|
2011-03-10 19:36:30 +00:00
|
|
|
if( screen->GetCurItem() && screen->GetCurItem()->GetFlags() )
|
2011-02-22 16:43:03 +00:00
|
|
|
OnHotKey( aDC, aHotKey, aPosition, screen->GetCurItem() );
|
2007-08-14 19:24:48 +00:00
|
|
|
else
|
2011-02-22 16:43:03 +00:00
|
|
|
OnHotKey( aDC, aHotKey, aPosition, NULL );
|
2007-08-14 19:24:48 +00:00
|
|
|
}
|
2007-08-21 19:37:31 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
UpdateStatusBar();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|