2011-10-13 19:56:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-06-08 09:56:42 +00:00
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2012 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-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file pcbnew/controle.cpp
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <pcbcommon.h>
|
|
|
|
#include <pcbnew_id.h>
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <protos.h>
|
|
|
|
#include <collectors.h>
|
2012-04-09 09:16:47 +00:00
|
|
|
#include <menus_helpers.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-08-01 15:29:27 +00:00
|
|
|
//external functions used here:
|
2012-08-28 06:51:18 +00:00
|
|
|
extern bool Magnetize( PCB_EDIT_FRAME* frame, int aCurrentTool,
|
|
|
|
wxSize aGridSize, wxPoint on_grid, wxPoint* curpos );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2007-09-14 16:15:27 +00:00
|
|
|
/**
|
|
|
|
* Function AllAreModulesAndReturnSmallestIfSo
|
|
|
|
* tests that all items in the collection are MODULEs and if so, returns the
|
|
|
|
* smallest MODULE.
|
|
|
|
* @return BOARD_ITEM* - The smallest or NULL.
|
2007-09-25 08:23:53 +00:00
|
|
|
*/
|
2011-02-01 15:46:25 +00:00
|
|
|
static BOARD_ITEM* AllAreModulesAndReturnSmallestIfSo( GENERAL_COLLECTOR* aCollector )
|
2007-09-14 16:15:27 +00:00
|
|
|
{
|
2011-10-27 13:01:32 +00:00
|
|
|
int count = aCollector->GetPrimaryCount(); // try to use preferred layer
|
|
|
|
if( 0 == count ) count = aCollector->GetCount();
|
2007-09-25 08:23:53 +00:00
|
|
|
|
|
|
|
for( int i = 0; i<count; ++i )
|
2007-09-14 16:15:27 +00:00
|
|
|
{
|
2011-10-01 19:24:27 +00:00
|
|
|
if( (*aCollector)[i]->Type() != PCB_MODULE_T )
|
2007-09-14 16:15:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2007-09-14 16:15:27 +00:00
|
|
|
// all are modules, now find smallest MODULE
|
|
|
|
|
|
|
|
int minDim = 0x7FFFFFFF;
|
|
|
|
int minNdx = 0;
|
2007-09-25 08:23:53 +00:00
|
|
|
|
|
|
|
for( int i = 0; i<count; ++i )
|
2007-09-14 16:15:27 +00:00
|
|
|
{
|
|
|
|
MODULE* module = (MODULE*) (*aCollector)[i];
|
2007-09-25 08:23:53 +00:00
|
|
|
|
|
|
|
int lx = module->m_BoundaryBox.GetWidth();
|
|
|
|
int ly = module->m_BoundaryBox.GetHeight();
|
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
int lmin = std::min( lx, ly );
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2011-10-27 13:01:32 +00:00
|
|
|
if( lmin < minDim )
|
2007-09-14 16:15:27 +00:00
|
|
|
{
|
|
|
|
minDim = lmin;
|
|
|
|
minNdx = i;
|
|
|
|
}
|
|
|
|
}
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2007-09-14 16:15:27 +00:00
|
|
|
return (*aCollector)[minNdx];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
BOARD_ITEM* PCB_BASE_FRAME::PcbGeneralLocateAndDisplay( int aHotKeyCode )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-09-25 08:23:53 +00:00
|
|
|
BOARD_ITEM* item;
|
|
|
|
|
|
|
|
GENERAL_COLLECTORS_GUIDE guide = GetCollectorsGuide();
|
2007-08-24 03:40:04 +00:00
|
|
|
|
2007-09-26 20:10:12 +00:00
|
|
|
// Assign to scanList the proper item types desired based on tool type
|
|
|
|
// or hotkey that is in play.
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2007-10-07 18:24:15 +00:00
|
|
|
const KICAD_T* scanList = NULL;
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2007-09-25 15:10:01 +00:00
|
|
|
if( aHotKeyCode )
|
|
|
|
{
|
2007-09-26 20:10:12 +00:00
|
|
|
// @todo: add switch here and add calls to PcbGeneralLocateAndDisplay( int aHotKeyCode )
|
|
|
|
// when searching is needed from a hotkey handler
|
2007-09-25 15:10:01 +00:00
|
|
|
}
|
2011-02-24 20:22:12 +00:00
|
|
|
else if( GetToolId() == ID_NO_TOOL_SELECTED )
|
2007-09-12 02:14:07 +00:00
|
|
|
{
|
2011-12-16 13:32:23 +00:00
|
|
|
if( m_mainToolBar->GetToolToggled( ID_TOOLBARH_PCB_MODE_MODULE ) )
|
2007-09-12 02:14:07 +00:00
|
|
|
scanList = GENERAL_COLLECTOR::ModuleItems;
|
2011-12-16 13:32:23 +00:00
|
|
|
else
|
|
|
|
scanList = (DisplayOpt.DisplayZonesMode == 0) ?
|
2007-10-01 15:37:42 +00:00
|
|
|
GENERAL_COLLECTOR::AllBoardItems :
|
|
|
|
GENERAL_COLLECTOR::AllButZones;
|
2007-09-12 02:14:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-02-24 20:22:12 +00:00
|
|
|
switch( GetToolId() )
|
2007-09-12 02:14:07 +00:00
|
|
|
{
|
|
|
|
case ID_PCB_SHOW_1_RATSNEST_BUTT:
|
|
|
|
scanList = GENERAL_COLLECTOR::PadsOrModules;
|
2007-09-25 08:23:53 +00:00
|
|
|
break;
|
2007-09-12 02:14:07 +00:00
|
|
|
|
|
|
|
case ID_TRACK_BUTT:
|
|
|
|
scanList = GENERAL_COLLECTOR::Tracks;
|
2007-09-25 08:23:53 +00:00
|
|
|
break;
|
2007-09-12 02:14:07 +00:00
|
|
|
|
2011-02-21 13:54:29 +00:00
|
|
|
case ID_PCB_MODULE_BUTT:
|
2007-09-12 02:14:07 +00:00
|
|
|
scanList = GENERAL_COLLECTOR::ModuleItems;
|
|
|
|
break;
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2011-05-12 11:06:32 +00:00
|
|
|
case ID_PCB_ZONES_BUTT:
|
2012-07-13 18:55:29 +00:00
|
|
|
case ID_PCB_KEEPOUT_AREA_BUTT:
|
2011-05-12 11:06:32 +00:00
|
|
|
scanList = GENERAL_COLLECTOR::Zones;
|
|
|
|
break;
|
|
|
|
|
2007-09-12 02:14:07 +00:00
|
|
|
default:
|
2008-12-12 21:30:07 +00:00
|
|
|
scanList = DisplayOpt.DisplayZonesMode == 0 ?
|
2007-10-01 15:37:42 +00:00
|
|
|
GENERAL_COLLECTOR::AllBoardItems :
|
|
|
|
GENERAL_COLLECTOR::AllButZones;
|
2007-09-12 02:14:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-25 08:23:53 +00:00
|
|
|
m_Collector->Collect( m_Pcb, scanList, GetScreen()->RefPos( true ), guide );
|
2007-09-12 02:14:07 +00:00
|
|
|
|
2007-10-01 15:37:42 +00:00
|
|
|
#if 0
|
2007-09-25 15:10:01 +00:00
|
|
|
// debugging: print out the collected items, showing their priority order too.
|
2007-10-01 15:37:42 +00:00
|
|
|
for( int i = 0; i<m_Collector->GetCount(); ++i )
|
2007-09-25 15:10:01 +00:00
|
|
|
(*m_Collector)[i]->Show( 0, std::cout );
|
2007-10-01 15:37:42 +00:00
|
|
|
#endif
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2009-01-31 21:42:05 +00:00
|
|
|
/* Remove redundancies: sometime, zones are found twice,
|
2009-11-23 14:40:29 +00:00
|
|
|
* because zones can be filled by overlapping segments (this is a fill option)
|
2007-09-25 08:23:53 +00:00
|
|
|
*/
|
2012-05-25 01:52:04 +00:00
|
|
|
time_t timestampzone = 0;
|
2007-10-01 15:37:42 +00:00
|
|
|
|
2007-09-26 20:10:12 +00:00
|
|
|
for( int ii = 0; ii < m_Collector->GetCount(); ii++ )
|
2007-09-25 08:23:53 +00:00
|
|
|
{
|
|
|
|
item = (*m_Collector)[ii];
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( item->Type() != PCB_ZONE_T )
|
2007-09-25 08:23:53 +00:00
|
|
|
continue;
|
2007-10-01 15:37:42 +00:00
|
|
|
|
2007-09-25 08:23:53 +00:00
|
|
|
/* Found a TYPE ZONE */
|
2011-12-12 08:37:05 +00:00
|
|
|
if( item->GetTimeStamp() == timestampzone ) // Remove it, redundant, zone already found
|
2007-09-25 08:23:53 +00:00
|
|
|
{
|
|
|
|
m_Collector->Remove( ii );
|
|
|
|
ii--;
|
|
|
|
}
|
|
|
|
else
|
2011-08-26 17:01:17 +00:00
|
|
|
{
|
2011-12-12 08:37:05 +00:00
|
|
|
timestampzone = item->GetTimeStamp();
|
2011-08-26 17:01:17 +00:00
|
|
|
}
|
2007-09-25 08:23:53 +00:00
|
|
|
}
|
2007-09-12 02:14:07 +00:00
|
|
|
|
2007-09-25 08:23:53 +00:00
|
|
|
if( m_Collector->GetCount() <= 1 )
|
2007-09-12 02:14:07 +00:00
|
|
|
{
|
|
|
|
item = (*m_Collector)[0];
|
2007-09-25 08:23:53 +00:00
|
|
|
SetCurItem( item );
|
2007-09-12 02:14:07 +00:00
|
|
|
}
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
// If the count is 2, and first item is a pad or module text, and the 2nd item is its
|
2011-02-01 15:46:25 +00:00
|
|
|
// parent module:
|
2007-09-25 08:23:53 +00:00
|
|
|
else if( m_Collector->GetCount() == 2
|
2011-10-01 19:24:27 +00:00
|
|
|
&& ( (*m_Collector)[0]->Type() == PCB_PAD_T || (*m_Collector)[0]->Type() ==
|
|
|
|
PCB_MODULE_TEXT_T )
|
|
|
|
&& (*m_Collector)[1]->Type() == PCB_MODULE_T && (*m_Collector)[0]->GetParent()==
|
2007-10-01 15:37:42 +00:00
|
|
|
(*m_Collector)[1] )
|
2007-09-12 02:14:07 +00:00
|
|
|
{
|
|
|
|
item = (*m_Collector)[0];
|
2007-09-25 08:23:53 +00:00
|
|
|
SetCurItem( item );
|
2007-09-12 02:14:07 +00:00
|
|
|
}
|
2011-08-01 15:29:27 +00:00
|
|
|
// if all are modules, find the smallest one among the primary choices
|
2007-09-25 08:23:53 +00:00
|
|
|
else if( ( item = AllAreModulesAndReturnSmallestIfSo( m_Collector ) ) != NULL )
|
2007-09-14 16:15:27 +00:00
|
|
|
{
|
2007-09-25 08:23:53 +00:00
|
|
|
SetCurItem( item );
|
2007-09-14 16:15:27 +00:00
|
|
|
}
|
2009-01-31 21:42:05 +00:00
|
|
|
|
2007-09-26 20:10:12 +00:00
|
|
|
else // we can't figure out which item user wants, do popup menu so user can choose
|
2007-08-24 03:40:04 +00:00
|
|
|
{
|
2007-09-25 08:23:53 +00:00
|
|
|
wxMenu itemMenu;
|
|
|
|
|
2007-10-10 04:45:26 +00:00
|
|
|
/* Give a title to the selection menu. This is also a cancel menu item */
|
2011-09-01 12:54:34 +00:00
|
|
|
wxMenuItem * item_title = new wxMenuItem( &itemMenu, -1, _( "Selection Clarification" ) );
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2007-10-07 18:24:15 +00:00
|
|
|
#ifdef __WINDOWS__
|
2011-09-01 12:54:34 +00:00
|
|
|
wxFont bold_font( *wxNORMAL_FONT );
|
|
|
|
bold_font.SetWeight( wxFONTWEIGHT_BOLD );
|
|
|
|
bold_font.SetStyle( wxFONTSTYLE_ITALIC );
|
|
|
|
item_title->SetFont( bold_font );
|
2007-10-07 18:24:15 +00:00
|
|
|
#endif
|
2011-02-01 15:46:25 +00:00
|
|
|
|
2011-09-01 12:54:34 +00:00
|
|
|
itemMenu.Append( item_title );
|
2007-10-10 04:45:26 +00:00
|
|
|
itemMenu.AppendSeparator();
|
2007-09-12 02:14:07 +00:00
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
int limit = std::min( MAX_ITEMS_IN_PICKER, m_Collector->GetCount() );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2007-09-25 08:23:53 +00:00
|
|
|
for( int i = 0; i<limit; ++i )
|
2007-09-12 02:14:07 +00:00
|
|
|
{
|
2011-08-29 03:04:59 +00:00
|
|
|
wxString text;
|
2007-09-12 02:14:07 +00:00
|
|
|
item = (*m_Collector)[i];
|
|
|
|
|
2011-07-14 15:42:44 +00:00
|
|
|
text = item->GetSelectMenuText();
|
2011-08-29 03:04:59 +00:00
|
|
|
|
|
|
|
BITMAP_DEF xpm = item->GetMenuImage();
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2011-09-08 05:58:45 +00:00
|
|
|
AddMenuItem( &itemMenu, ID_POPUP_PCB_ITEM_SELECTION_START + i, text, KiBitmap( xpm ) );
|
2007-09-12 02:14:07 +00:00
|
|
|
}
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
/* @todo: rather than assignment to true, these should be increment and decrement
|
2011-02-01 15:46:25 +00:00
|
|
|
* operators throughout _everywhere_.
|
2007-10-01 15:37:42 +00:00
|
|
|
* That way we can handle nesting.
|
2011-02-03 19:27:28 +00:00
|
|
|
* But I tried that and found there cases where the assignment to true (converted to
|
2011-02-01 15:46:25 +00:00
|
|
|
* a m_IgnoreMouseEvents++ )
|
2011-02-03 19:27:28 +00:00
|
|
|
* was not balanced with the -- (now m_IgnoreMouseEvents=false), so I had to revert.
|
2007-10-01 15:37:42 +00:00
|
|
|
* Somebody should track down these and make them balanced.
|
2011-12-29 20:11:42 +00:00
|
|
|
* m_canvas->SetIgnoreMouseEvents( true );
|
2007-10-01 15:37:42 +00:00
|
|
|
*/
|
2007-09-12 02:14:07 +00:00
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
// this menu's handler is void PCB_BASE_FRAME::ProcessItemSelection()
|
2009-04-17 08:51:02 +00:00
|
|
|
// and it calls SetCurItem() which in turn calls DisplayInfo() on the item.
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetAbortRequest( true ); // changed in false if an item is selected
|
2011-03-10 17:52:36 +00:00
|
|
|
PopupMenu( &itemMenu );
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2007-09-12 02:14:07 +00:00
|
|
|
// The function ProcessItemSelection() has set the current item, return it.
|
2011-12-29 20:11:42 +00:00
|
|
|
if( m_canvas->GetAbortRequest() ) // Nothing selected
|
2011-03-10 17:52:36 +00:00
|
|
|
item = NULL;
|
|
|
|
else
|
|
|
|
item = GetCurItem();
|
2007-08-24 03:40:04 +00:00
|
|
|
}
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2007-08-24 03:40:04 +00:00
|
|
|
return item;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-02-01 15:46:25 +00:00
|
|
|
wxRealPoint gridSize;
|
|
|
|
wxPoint oldpos;
|
2012-08-11 12:52:13 +00:00
|
|
|
wxPoint pos = aPosition;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
if( snapToGrid )
|
|
|
|
pos = GetScreen()->GetNearestGridPosition( pos );
|
2007-08-04 01:12:30 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
oldpos = GetScreen()->GetCrossHairPosition();
|
2007-08-04 01:12:30 +00:00
|
|
|
|
2011-02-01 15:46:25 +00:00
|
|
|
gridSize = GetScreen()->GetGridSize();
|
2007-08-04 01:12:30 +00:00
|
|
|
|
2011-02-22 16:43:03 +00:00
|
|
|
switch( aHotKey )
|
2007-08-04 01:12:30 +00:00
|
|
|
{
|
2011-08-01 15:29:27 +00:00
|
|
|
case WXK_NUMPAD8:
|
2007-08-04 01:12:30 +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-04 01:12:30 +00:00
|
|
|
break;
|
|
|
|
|
2011-08-01 15:29:27 +00:00
|
|
|
case WXK_NUMPAD2:
|
2007-08-04 01:12:30 +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-04 01:12:30 +00:00
|
|
|
break;
|
|
|
|
|
2011-08-01 15:29:27 +00:00
|
|
|
case WXK_NUMPAD4:
|
2007-08-04 01:12:30 +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-04 01:12:30 +00:00
|
|
|
break;
|
|
|
|
|
2011-08-01 15:29:27 +00:00
|
|
|
case WXK_NUMPAD6:
|
2007-08-04 01:12:30 +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-04 01:12:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-02-01 15:46:25 +00:00
|
|
|
// Put cursor in new position, according to the zoom keys (if any).
|
2012-08-11 12:52:13 +00:00
|
|
|
GetScreen()->SetCrossHairPosition( pos, snapToGrid );
|
2007-08-04 01:12:30 +00:00
|
|
|
|
2011-02-01 15:46:25 +00:00
|
|
|
/* Put cursor on grid or a pad centre if requested. If the tool DELETE is active the
|
|
|
|
* cursor is left off grid this is better to reach items to delete off grid,
|
2007-08-04 01:12:30 +00:00
|
|
|
*/
|
2011-02-24 20:22:12 +00:00
|
|
|
if( GetToolId() == ID_PCB_DELETE_ITEM_BUTT )
|
2012-08-11 12:52:13 +00:00
|
|
|
snapToGrid = false;
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2012-08-11 12:52:13 +00:00
|
|
|
// Cursor is left off grid if no block in progress
|
2012-03-26 23:47:08 +00:00
|
|
|
if( GetScreen()->m_BlockLocate.GetState() != STATE_NO_BLOCK )
|
2012-08-11 12:52:13 +00:00
|
|
|
snapToGrid = true;
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2012-08-11 12:52:13 +00:00
|
|
|
wxPoint curs_pos = pos;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2012-08-28 06:51:18 +00:00
|
|
|
wxSize igridsize;
|
|
|
|
igridsize.x = KiROUND( gridSize.x );
|
|
|
|
igridsize.y = KiROUND( gridSize.y );
|
2007-08-04 01:12:30 +00:00
|
|
|
|
2012-08-28 06:51:18 +00:00
|
|
|
if( Magnetize( this, GetToolId(), igridsize, curs_pos, &pos ) )
|
2008-02-27 15:26:16 +00:00
|
|
|
{
|
2012-08-11 12:52:13 +00:00
|
|
|
GetScreen()->SetCrossHairPosition( pos, false );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If there's no intrusion and DRC is active, we pass the cursor
|
|
|
|
// "as is", and let ShowNewTrackWhenMovingCursor figure out what to do.
|
2012-08-21 10:45:54 +00:00
|
|
|
if( !Drc_On || !g_CurrentTrackSegment ||
|
|
|
|
(BOARD_ITEM*)g_CurrentTrackSegment != this->GetCurItem() ||
|
|
|
|
!LocateIntrusion( m_Pcb->m_Track, g_CurrentTrackSegment,
|
|
|
|
GetScreen()->m_Active_Layer, GetScreen()->RefPos( true ) ) )
|
2008-02-27 15:26:16 +00:00
|
|
|
{
|
2012-08-11 12:52:13 +00:00
|
|
|
GetScreen()->SetCrossHairPosition( curs_pos, snapToGrid );
|
2008-02-27 15:26:16 +00:00
|
|
|
}
|
2007-08-04 01:12:30 +00:00
|
|
|
}
|
|
|
|
|
2012-08-11 12:52:13 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
if( oldpos != GetScreen()->GetCrossHairPosition() )
|
2007-08-04 01:12:30 +00:00
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
pos = GetScreen()->GetCrossHairPosition();
|
2011-02-28 21:41:00 +00:00
|
|
|
GetScreen()->SetCrossHairPosition( oldpos, false );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->CrossHairOff( aDC );
|
2012-08-28 06:51:18 +00:00
|
|
|
GetScreen()->SetCrossHairPosition( pos, false );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->CrossHairOn( aDC );
|
2007-08-04 01:12:30 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
if( m_canvas->IsMouseCaptured() )
|
2007-08-04 01:12:30 +00:00
|
|
|
{
|
2010-10-09 08:08:29 +00:00
|
|
|
#ifdef USE_WX_OVERLAY
|
2011-12-29 20:11:42 +00:00
|
|
|
wxDCOverlay oDC( m_overlay, (wxWindowDC*)aDC );
|
2011-02-01 15:46:25 +00:00
|
|
|
oDC.Clear();
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( aDC, aPosition, false );
|
2010-09-21 23:46:02 +00:00
|
|
|
#else
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( aDC, aPosition, true );
|
2010-09-21 23:46:02 +00:00
|
|
|
#endif
|
2007-08-04 01:12:30 +00:00
|
|
|
}
|
2010-10-09 08:08:29 +00:00
|
|
|
#ifdef USE_WX_OVERLAY
|
2010-09-21 23:46:02 +00:00
|
|
|
else
|
2011-12-22 13:28:11 +00:00
|
|
|
{
|
2011-12-29 20:11:42 +00:00
|
|
|
m_overlay.Reset();
|
2011-12-22 13:28:11 +00:00
|
|
|
}
|
2010-09-21 23:46:02 +00:00
|
|
|
#endif
|
2007-08-04 01:12:30 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 16:43:03 +00:00
|
|
|
if( aHotKey )
|
2007-08-20 10:55:09 +00:00
|
|
|
{
|
2011-02-22 16:43:03 +00:00
|
|
|
OnHotKey( aDC, aHotKey, aPosition );
|
2007-08-20 10:55:09 +00:00
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
UpdateStatusBar(); /* Display new cursor coordinates */
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|