2011-12-29 20:11:42 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-12-21 11:52:00 +00:00
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
2012-06-08 09:56:42 +00:00
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
|
2015-12-21 11:52:00 +00:00
|
|
|
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-12-29 20:11:42 +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
|
|
|
|
*/
|
|
|
|
|
2015-01-19 08:23:10 +00:00
|
|
|
/**
|
2011-09-23 13:57:12 +00:00
|
|
|
* @file modules.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 <confirm.h>
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <macros.h>
|
|
|
|
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
|
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <drag.h>
|
2015-12-21 11:52:00 +00:00
|
|
|
#include <dialog_get_footprint_by_name.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-04-11 09:47:57 +00:00
|
|
|
static void MoveFootprint( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
|
|
|
|
const wxPoint& aPosition, bool aErase );
|
2011-01-21 19:30:59 +00:00
|
|
|
static void Abort_MoveOrCopyModule( EDA_DRAW_PANEL* Panel, wxDC* DC );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2010-07-20 18:11:34 +00:00
|
|
|
static MODULE* s_ModuleInitialCopy = NULL; /* Copy of module for
|
|
|
|
* abort/undo command
|
|
|
|
*/
|
|
|
|
static PICKED_ITEMS_LIST s_PickedList; /* a picked list to
|
|
|
|
* save initial module
|
|
|
|
* and dragged tracks
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2015-12-20 18:47:52 +00:00
|
|
|
|
|
|
|
MODULE* PCB_BASE_FRAME::GetFootprintFromBoardByReference()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2015-12-20 18:47:52 +00:00
|
|
|
wxString moduleName;
|
|
|
|
MODULE* module = NULL;
|
|
|
|
wxArrayString fplist;
|
|
|
|
|
2015-12-21 11:52:00 +00:00
|
|
|
// Build list of available fp references, to display them in dialog
|
2015-12-20 18:47:52 +00:00
|
|
|
for( MODULE* fp = GetBoard()->m_Modules; fp; fp = fp->Next() )
|
|
|
|
fplist.Add( fp->GetReference() + wxT(" ( ") + fp->GetValue() + wxT(" )") );
|
|
|
|
|
|
|
|
fplist.Sort();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2015-12-20 18:47:52 +00:00
|
|
|
DIALOG_GET_FOOTPRINT_BY_NAME dlg( this, fplist );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2015-12-21 11:52:00 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK ) //Aborted by user
|
|
|
|
return NULL;
|
2010-07-20 18:11:34 +00:00
|
|
|
|
2010-07-21 08:15:54 +00:00
|
|
|
moduleName = dlg.GetValue();
|
2010-07-20 18:11:34 +00:00
|
|
|
moduleName.Trim( true );
|
|
|
|
moduleName.Trim( false );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-07-20 18:11:34 +00:00
|
|
|
if( !moduleName.IsEmpty() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2009-01-05 05:21:35 +00:00
|
|
|
module = GetBoard()->m_Modules;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
while( module )
|
|
|
|
{
|
2013-03-13 18:53:58 +00:00
|
|
|
if( module->GetReference().CmpNoCase( moduleName ) == 0 )
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
module = module->Next();
|
|
|
|
}
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
return module;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
void PCB_EDIT_FRAME::StartMoveModule( MODULE* aModule, wxDC* aDC,
|
|
|
|
bool aDragConnectedTracks )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2012-09-11 07:33:17 +00:00
|
|
|
if( aModule == NULL )
|
2007-08-10 19:14:51 +00:00
|
|
|
return;
|
|
|
|
|
2009-08-06 07:11:04 +00:00
|
|
|
if( s_ModuleInitialCopy )
|
|
|
|
delete s_ModuleInitialCopy;
|
|
|
|
|
|
|
|
s_PickedList.ClearItemsList(); // Should be empty, but...
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
// Creates a copy of the current module, for abort and undo commands
|
2012-09-11 07:33:17 +00:00
|
|
|
s_ModuleInitialCopy = (MODULE*)aModule->Clone();
|
2012-01-14 19:50:32 +00:00
|
|
|
s_ModuleInitialCopy->SetParent( GetBoard() );
|
2011-12-21 13:42:02 +00:00
|
|
|
s_ModuleInitialCopy->ClearFlags();
|
2009-08-06 07:11:04 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
SetCurItem( aModule );
|
2009-05-24 18:28:36 +00:00
|
|
|
GetBoard()->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK;
|
2012-09-11 07:33:17 +00:00
|
|
|
aModule->SetFlags( IS_MOVED );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Show ratsnest. */
|
2017-03-13 03:19:33 +00:00
|
|
|
if( GetBoard()->IsElementVisible( LAYER_RATSNEST ) )
|
2012-09-11 07:33:17 +00:00
|
|
|
DrawGeneralRatsnest( aDC );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
EraseDragList();
|
2010-10-26 11:47:16 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
if( aDragConnectedTracks )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2012-09-11 07:33:17 +00:00
|
|
|
DRAG_LIST drglist( GetBoard() );
|
|
|
|
drglist.BuildDragListe( aModule );
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
ITEM_PICKER itemWrapper( NULL, UR_CHANGED );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
|
2009-08-06 07:11:04 +00:00
|
|
|
{
|
2012-09-11 07:33:17 +00:00
|
|
|
TRACK* segm = g_DragSegmentList[ii].m_Track;
|
2012-02-05 13:02:46 +00:00
|
|
|
itemWrapper.SetItem( segm );
|
|
|
|
itemWrapper.SetLink( segm->Clone() );
|
2013-03-28 06:40:19 +00:00
|
|
|
itemWrapper.GetLink()->SetState( IN_EDIT, false );
|
2009-11-18 12:52:19 +00:00
|
|
|
s_PickedList.PushItem( itemWrapper );
|
2009-08-06 07:11:04 +00:00
|
|
|
}
|
2012-09-11 07:33:17 +00:00
|
|
|
|
|
|
|
UndrawAndMarkSegmentsToDrag( m_canvas, aDC );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
GetBoard()->m_Status_Pcb |= DO_NOT_SHOW_GENERAL_RASTNEST;
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->SetMouseCapture( MoveFootprint, Abort_MoveOrCopyModule );
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetAutoPanRequest( true );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
// Erase the module.
|
2012-09-11 07:33:17 +00:00
|
|
|
if( aDC )
|
2008-04-01 05:21:50 +00:00
|
|
|
{
|
2012-09-11 07:33:17 +00:00
|
|
|
aModule->SetFlags( DO_NOT_DRAW );
|
|
|
|
m_canvas->RefreshDrawingRect( aModule->GetBoundingBox() );
|
|
|
|
aModule->ClearFlags( DO_NOT_DRAW );
|
2008-04-01 05:21:50 +00:00
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
m_canvas->CallMouseCapture( aDC, wxDefaultPosition, false );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2008-08-06 07:46:03 +00:00
|
|
|
/* Called on a move or copy module command abort
|
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
void Abort_MoveOrCopyModule( EDA_DRAW_PANEL* Panel, wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-03-01 19:26:17 +00:00
|
|
|
TRACK* pt_segm;
|
|
|
|
MODULE* module;
|
|
|
|
PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Panel->GetParent();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
module = (MODULE*) pcbframe->GetScreen()->GetCurItem();
|
2009-05-24 18:28:36 +00:00
|
|
|
pcbframe->GetBoard()->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK;
|
2011-02-13 09:07:30 +00:00
|
|
|
Panel->SetMouseCapture( NULL, NULL );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
if( module )
|
|
|
|
{
|
2008-08-06 07:46:03 +00:00
|
|
|
// Erase the current footprint on screen
|
2015-01-19 08:23:10 +00:00
|
|
|
module->DrawOutlinesWhenMoving( Panel, DC, g_Offset_Module );
|
2008-08-06 07:46:03 +00:00
|
|
|
|
|
|
|
/* If a move command: return to old position
|
2009-11-18 12:52:19 +00:00
|
|
|
* If a copy command, delete the new footprint
|
2008-08-06 07:46:03 +00:00
|
|
|
*/
|
2011-02-22 18:28:00 +00:00
|
|
|
if( module->IsMoving() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2012-09-11 07:33:17 +00:00
|
|
|
/* Restore old position for dragged tracks */
|
2010-08-31 15:54:05 +00:00
|
|
|
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2012-09-11 07:33:17 +00:00
|
|
|
pt_segm = g_DragSegmentList[ii].m_Track;
|
|
|
|
pt_segm->Draw( Panel, DC, GR_XOR );
|
2013-03-28 06:40:19 +00:00
|
|
|
pt_segm->SetState( IN_EDIT, false );
|
2013-07-05 17:48:01 +00:00
|
|
|
pt_segm->ClearFlags();
|
2012-09-11 07:33:17 +00:00
|
|
|
g_DragSegmentList[ii].RestoreInitialValues();
|
2007-08-10 19:14:51 +00:00
|
|
|
pt_segm->Draw( Panel, DC, GR_OR );
|
|
|
|
}
|
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
EraseDragList();
|
2011-12-21 13:42:02 +00:00
|
|
|
module->ClearFlags( IS_MOVED );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 18:28:00 +00:00
|
|
|
if( module->IsNew() ) // Copy command: delete new footprint
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2008-08-06 07:46:03 +00:00
|
|
|
module->DeleteStructure();
|
2007-08-10 19:14:51 +00:00
|
|
|
module = NULL;
|
2009-01-05 05:21:35 +00:00
|
|
|
pcbframe->GetBoard()->m_Status_Pcb = 0;
|
2011-12-10 05:33:24 +00:00
|
|
|
pcbframe->GetBoard()->BuildListOfNets();
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Redraw the module. */
|
2009-08-06 07:11:04 +00:00
|
|
|
if( module && s_ModuleInitialCopy )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-03-13 18:53:58 +00:00
|
|
|
if( s_ModuleInitialCopy->GetOrientation() != module->GetOrientation() )
|
|
|
|
pcbframe->Rotate_Module( NULL, module, s_ModuleInitialCopy->GetOrientation(), false );
|
2011-02-11 20:48:13 +00:00
|
|
|
|
2009-08-06 07:11:04 +00:00
|
|
|
if( s_ModuleInitialCopy->GetLayer() != module->GetLayer() )
|
|
|
|
pcbframe->Change_Side_Module( module, NULL );
|
2011-02-11 20:48:13 +00:00
|
|
|
|
2008-04-01 05:21:50 +00:00
|
|
|
module->Draw( Panel, DC, GR_OR );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2011-02-11 20:48:13 +00:00
|
|
|
|
2007-09-12 02:14:07 +00:00
|
|
|
pcbframe->SetCurItem( NULL );
|
2008-08-06 07:46:03 +00:00
|
|
|
|
2009-08-06 07:11:04 +00:00
|
|
|
delete s_ModuleInitialCopy;
|
|
|
|
s_ModuleInitialCopy = NULL;
|
|
|
|
s_PickedList.ClearListAndDeleteItems();
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
// Display ratsnest is allowed
|
|
|
|
pcbframe->GetBoard()->m_Status_Pcb &= ~DO_NOT_SHOW_GENERAL_RASTNEST;
|
2011-02-11 20:48:13 +00:00
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
if( pcbframe->GetBoard()->IsElementVisible( LAYER_RATSNEST ) )
|
2008-08-06 07:46:03 +00:00
|
|
|
pcbframe->DrawGeneralRatsnest( DC );
|
2010-10-09 08:08:29 +00:00
|
|
|
|
|
|
|
#ifdef __WXMAC__
|
2011-02-21 21:07:00 +00:00
|
|
|
Panel->Refresh();
|
2010-10-09 08:08:29 +00:00
|
|
|
#endif
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Redraw the footprint when moving the mouse.
|
2007-08-10 19:14:51 +00:00
|
|
|
*/
|
2011-09-07 19:41:04 +00:00
|
|
|
void MoveFootprint( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-02-03 19:27:28 +00:00
|
|
|
MODULE* module = (MODULE*) aPanel->GetScreen()->GetCurItem();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
if( module == NULL )
|
2007-08-10 19:14:51 +00:00
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Erase current footprint. */
|
2011-02-03 19:27:28 +00:00
|
|
|
if( aErase )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2015-01-19 08:23:10 +00:00
|
|
|
module->DrawOutlinesWhenMoving( aPanel, aDC, g_Offset_Module );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Redraw the module at the new position. */
|
2013-08-03 05:15:23 +00:00
|
|
|
g_Offset_Module = module->GetPosition() - aPanel->GetParent()->GetCrossHairPosition();
|
2015-01-19 08:23:10 +00:00
|
|
|
module->DrawOutlinesWhenMoving( aPanel, aDC, g_Offset_Module );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
DrawSegmentWhileMovingFootprint( aPanel, aDC );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-18 18:59:24 +00:00
|
|
|
bool PCB_EDIT_FRAME::Delete_Module( MODULE* aModule, wxDC* aDC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-18 12:52:19 +00:00
|
|
|
wxString msg;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2010-12-29 17:47:32 +00:00
|
|
|
if( aModule == NULL )
|
2011-02-22 18:28:00 +00:00
|
|
|
return false;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( aModule );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
/* Remove module from list, and put it in undo command list */
|
2010-12-29 17:47:32 +00:00
|
|
|
m_Pcb->m_Modules.Remove( aModule );
|
2013-03-28 06:40:19 +00:00
|
|
|
aModule->SetState( IS_DELETED, true );
|
2010-12-29 17:47:32 +00:00
|
|
|
SaveCopyInUndoList( aModule, UR_DELETED );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
if( aDC && GetBoard()->IsElementVisible( LAYER_RATSNEST ) )
|
2010-12-29 17:47:32 +00:00
|
|
|
Compile_Ratsnest( aDC, true );
|
2008-08-06 07:46:03 +00:00
|
|
|
|
2010-01-13 13:43:36 +00:00
|
|
|
// Redraw the full screen to ensure perfect display of board and ratsnest.
|
2010-12-29 17:47:32 +00:00
|
|
|
if( aDC )
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh();
|
2010-01-13 13:43:36 +00:00
|
|
|
|
2015-11-18 18:59:24 +00:00
|
|
|
OnModify();
|
|
|
|
|
2010-01-13 13:43:36 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::Change_Side_Module( MODULE* Module, wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-10 19:14:51 +00:00
|
|
|
if( Module == NULL )
|
|
|
|
return;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
if( ( Module->GetLayer() != F_Cu ) && ( Module->GetLayer() != B_Cu ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
return;
|
|
|
|
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
if( !Module->IsMoving() ) /* This is a simple flip, no other edition in progress */
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2009-11-18 12:52:19 +00:00
|
|
|
GetBoard()->m_Status_Pcb &= ~( LISTE_RATSNEST_ITEM_OK | CONNEXION_OK );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-08-06 07:11:04 +00:00
|
|
|
if( DC )
|
2008-04-01 05:21:50 +00:00
|
|
|
{
|
2011-12-21 13:42:02 +00:00
|
|
|
Module->SetFlags( DO_NOT_DRAW );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->RefreshDrawingRect( Module->GetBoundingBox() );
|
2011-12-21 13:42:02 +00:00
|
|
|
Module->ClearFlags( DO_NOT_DRAW );
|
2008-04-01 05:21:50 +00:00
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Show ratsnest if necessary. */
|
2017-03-13 03:19:33 +00:00
|
|
|
if( DC && GetBoard()->IsElementVisible( LAYER_RATSNEST ) )
|
2009-08-06 07:11:04 +00:00
|
|
|
DrawGeneralRatsnest( DC );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
g_Offset_Module.x = 0;
|
|
|
|
g_Offset_Module.y = 0;
|
|
|
|
}
|
2009-11-18 12:52:19 +00:00
|
|
|
else // Module is being moved.
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Erase footprint and draw outline if it has been already drawn. */
|
2009-08-06 07:11:04 +00:00
|
|
|
if( DC )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2015-01-19 08:23:10 +00:00
|
|
|
Module->DrawOutlinesWhenMoving( m_canvas, DC, g_Offset_Module );
|
2011-12-22 13:28:11 +00:00
|
|
|
DrawSegmentWhileMovingFootprint( m_canvas, DC );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
/* Flip the module */
|
2013-03-13 18:53:58 +00:00
|
|
|
Module->Flip( Module->GetPosition() );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( Module );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
if( !Module->IsMoving() ) /* Inversion simple */
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2009-08-06 07:11:04 +00:00
|
|
|
if( DC )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
Module->Draw( m_canvas, DC, GR_OR );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
if( GetBoard()->IsElementVisible( LAYER_RATSNEST ) )
|
2010-10-25 12:33:00 +00:00
|
|
|
Compile_Ratsnest( DC, true );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-08-06 07:11:04 +00:00
|
|
|
if( DC )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2015-01-19 08:23:10 +00:00
|
|
|
Module->DrawOutlinesWhenMoving( m_canvas, DC, g_Offset_Module );
|
2011-12-22 13:28:11 +00:00
|
|
|
DrawSegmentWhileMovingFootprint( m_canvas, DC );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-08-06 07:11:04 +00:00
|
|
|
GetBoard()->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-16 14:13:02 +00:00
|
|
|
void PCB_BASE_FRAME::PlaceModule( MODULE* aModule, wxDC* aDC, bool aDoNotRecreateRatsnest )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-18 12:52:19 +00:00
|
|
|
wxPoint newpos;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-09-16 14:13:02 +00:00
|
|
|
if( aModule == 0 )
|
2007-08-10 19:14:51 +00:00
|
|
|
return;
|
|
|
|
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2009-05-24 18:28:36 +00:00
|
|
|
GetBoard()->m_Status_Pcb &= ~( LISTE_RATSNEST_ITEM_OK | CONNEXION_OK);
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-09-16 14:13:02 +00:00
|
|
|
if( aModule->IsNew() )
|
2009-08-06 07:11:04 +00:00
|
|
|
{
|
2011-09-16 14:13:02 +00:00
|
|
|
SaveCopyInUndoList( aModule, UR_NEW );
|
2009-08-06 07:11:04 +00:00
|
|
|
}
|
2011-12-21 13:42:02 +00:00
|
|
|
else if( aModule->IsMoving() )
|
2009-08-06 07:11:04 +00:00
|
|
|
{
|
2011-09-16 14:13:02 +00:00
|
|
|
ITEM_PICKER picker( aModule, UR_CHANGED );
|
2012-02-05 13:02:46 +00:00
|
|
|
picker.SetLink( s_ModuleInitialCopy );
|
2009-11-18 12:52:19 +00:00
|
|
|
s_PickedList.PushItem( picker );
|
2011-09-07 19:41:04 +00:00
|
|
|
s_ModuleInitialCopy = NULL; // the picker is now owner of s_ModuleInitialCopy.
|
2009-08-06 07:11:04 +00:00
|
|
|
}
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
if( s_PickedList.GetCount() )
|
2009-08-06 07:11:04 +00:00
|
|
|
{
|
2009-11-18 12:52:19 +00:00
|
|
|
SaveCopyInUndoList( s_PickedList, UR_UNSPECIFIED );
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
// Clear list, but DO NOT delete items, because they are owned by the saved undo
|
|
|
|
// list and they therefore in use
|
2009-08-06 07:11:04 +00:00
|
|
|
s_PickedList.ClearItemsList();
|
|
|
|
}
|
|
|
|
|
2015-01-10 10:27:49 +00:00
|
|
|
DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)GetDisplayOptions();
|
|
|
|
|
|
|
|
if( displ_opts->m_Show_Module_Ratsnest && ( GetBoard()->m_Status_Pcb & LISTE_PAD_OK ) && aDC )
|
2011-09-16 14:13:02 +00:00
|
|
|
TraceModuleRatsNest( aDC );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
newpos = GetCrossHairPosition();
|
2011-09-16 14:13:02 +00:00
|
|
|
aModule->SetPosition( newpos );
|
2011-12-21 13:42:02 +00:00
|
|
|
aModule->ClearFlags();
|
2009-12-29 18:03:23 +00:00
|
|
|
|
|
|
|
delete s_ModuleInitialCopy;
|
|
|
|
s_ModuleInitialCopy = NULL;
|
2009-11-18 12:52:19 +00:00
|
|
|
|
2011-09-16 14:13:02 +00:00
|
|
|
if( aDC )
|
2011-12-22 13:28:11 +00:00
|
|
|
aModule->Draw( m_canvas, aDC, GR_OR );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
// Redraw dragged track segments, if any
|
|
|
|
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2012-09-11 07:33:17 +00:00
|
|
|
TRACK * track = g_DragSegmentList[ii].m_Track;
|
2013-03-28 06:40:19 +00:00
|
|
|
track->SetState( IN_EDIT, false );
|
2013-07-05 17:48:01 +00:00
|
|
|
track->ClearFlags();
|
2011-02-11 20:48:13 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
if( aDC )
|
|
|
|
track->Draw( m_canvas, aDC, GR_OR );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2009-12-29 18:03:23 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
// Delete drag list
|
|
|
|
EraseDragList();
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->SetMouseCapture( NULL, NULL );
|
2009-12-29 18:03:23 +00:00
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
if( GetBoard()->IsElementVisible( LAYER_RATSNEST ) && !aDoNotRecreateRatsnest )
|
2011-09-16 14:13:02 +00:00
|
|
|
Compile_Ratsnest( aDC, true );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-09-16 14:13:02 +00:00
|
|
|
if( aDC )
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh();
|
2009-08-03 12:12:29 +00:00
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( aModule );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-11-18 12:52:19 +00:00
|
|
|
* Rotate the footprint angle degrees in the direction < 0.
|
2010-01-13 13:43:36 +00:00
|
|
|
* If incremental == true, the rotation is made from the last orientation,
|
2009-11-18 12:52:19 +00:00
|
|
|
* If the module is placed in the absolute orientation angle.
|
|
|
|
* If DC == NULL, the component does not redraw.
|
|
|
|
* Otherwise, it erases and redraws turns
|
2007-08-10 19:14:51 +00:00
|
|
|
*/
|
2013-05-05 07:17:48 +00:00
|
|
|
void PCB_BASE_FRAME::Rotate_Module( wxDC* DC, MODULE* module, double angle, bool incremental )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-10 19:14:51 +00:00
|
|
|
if( module == NULL )
|
|
|
|
return;
|
|
|
|
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
if( !module->IsMoving() ) /* This is a simple rotation, no other
|
2009-11-18 12:52:19 +00:00
|
|
|
* edition in progress */
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2009-11-18 12:52:19 +00:00
|
|
|
if( DC ) // Erase footprint to screen
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-12-21 13:42:02 +00:00
|
|
|
module->SetFlags( DO_NOT_DRAW );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->RefreshDrawingRect( module->GetBoundingBox() );
|
2011-12-21 13:42:02 +00:00
|
|
|
module->ClearFlags( DO_NOT_DRAW );
|
2008-03-13 21:18:05 +00:00
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
if( GetBoard()->IsElementVisible( LAYER_RATSNEST ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
DrawGeneralRatsnest( DC );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( DC )
|
|
|
|
{
|
2015-01-19 08:23:10 +00:00
|
|
|
module->DrawOutlinesWhenMoving( m_canvas, DC, g_Offset_Module );
|
2011-12-22 13:28:11 +00:00
|
|
|
DrawSegmentWhileMovingFootprint( m_canvas, DC );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
GetBoard()->m_Status_Pcb &= ~( LISTE_RATSNEST_ITEM_OK | CONNEXION_OK );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
if( incremental )
|
2013-03-13 18:53:58 +00:00
|
|
|
module->SetOrientation( module->GetOrientation() + angle );
|
2007-08-10 19:14:51 +00:00
|
|
|
else
|
|
|
|
module->SetOrientation( angle );
|
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( module );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
if( DC )
|
|
|
|
{
|
2011-12-21 13:42:02 +00:00
|
|
|
if( !module->IsMoving() )
|
2010-07-20 18:11:34 +00:00
|
|
|
{
|
|
|
|
// not beiing moved: redraw the module and update ratsnest
|
2011-12-22 13:28:11 +00:00
|
|
|
module->Draw( m_canvas, DC, GR_OR );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
if( GetBoard()->IsElementVisible( LAYER_RATSNEST ) )
|
2010-10-07 09:05:28 +00:00
|
|
|
Compile_Ratsnest( DC, true );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
else
|
2010-07-20 18:11:34 +00:00
|
|
|
{
|
|
|
|
// Beiing moved: just redraw it
|
2015-01-19 08:23:10 +00:00
|
|
|
module->DrawOutlinesWhenMoving( m_canvas, DC, g_Offset_Module );
|
2011-12-22 13:28:11 +00:00
|
|
|
DrawSegmentWhileMovingFootprint( m_canvas, DC );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2010-01-13 13:43:36 +00:00
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
if( module->GetFlags() == 0 ) // module not in edit: redraw full screen
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh();
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-19 08:23:10 +00:00
|
|
|
// Redraw in XOR mode the outlines of the module.
|
|
|
|
void MODULE::DrawOutlinesWhenMoving( EDA_DRAW_PANEL* panel, wxDC* DC,
|
|
|
|
const wxPoint& aMoveVector )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-10 19:14:51 +00:00
|
|
|
int pad_fill_tmp;
|
|
|
|
D_PAD* pt_pad;
|
|
|
|
|
2015-01-19 08:23:10 +00:00
|
|
|
DrawEdgesOnly( panel, DC, aMoveVector, GR_XOR );
|
2015-01-10 10:27:49 +00:00
|
|
|
DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)panel->GetDisplayOptions();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
// Show pads in sketch mode to speedu up drawings
|
2015-01-10 10:27:49 +00:00
|
|
|
pad_fill_tmp = displ_opts->m_DisplayPadFill;
|
|
|
|
displ_opts->m_DisplayPadFill = true;
|
2010-09-21 23:46:02 +00:00
|
|
|
|
2015-01-19 08:23:10 +00:00
|
|
|
pt_pad = Pads();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
for( ; pt_pad != NULL; pt_pad = pt_pad->Next() )
|
2015-01-19 08:23:10 +00:00
|
|
|
pt_pad->Draw( panel, DC, GR_XOR, aMoveVector );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2015-01-10 10:27:49 +00:00
|
|
|
displ_opts->m_DisplayPadFill = pad_fill_tmp;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2015-01-19 08:23:10 +00:00
|
|
|
if( displ_opts->m_Show_Module_Ratsnest )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-03-01 19:26:17 +00:00
|
|
|
PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) panel->GetParent();
|
2015-01-19 08:23:10 +00:00
|
|
|
frame->build_ratsnest_module( this );
|
2011-09-16 14:13:02 +00:00
|
|
|
frame->TraceModuleRatsNest( DC );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|