2012-01-04 22:08:46 +00:00
|
|
|
/*
|
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
|
|
|
|
*/
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
/**
|
|
|
|
* @file schedit.cpp
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <appl_wxstruct.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <eda_doc.h>
|
|
|
|
#include <wxEeschemaStruct.h>
|
|
|
|
#include <kicad_device_context.h>
|
|
|
|
#include <hotkeys_basic.h>
|
|
|
|
|
|
|
|
#include <general.h>
|
|
|
|
#include <eeschema_id.h>
|
|
|
|
#include <protos.h>
|
|
|
|
#include <class_library.h>
|
|
|
|
#include <sch_bus_entry.h>
|
|
|
|
#include <sch_marker.h>
|
|
|
|
#include <sch_component.h>
|
|
|
|
#include <sch_junction.h>
|
|
|
|
#include <sch_line.h>
|
|
|
|
#include <sch_sheet.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-04-17 16:25:29 +00:00
|
|
|
int id = event.GetId();
|
|
|
|
wxPoint pos;
|
|
|
|
SCH_SCREEN* screen = GetScreen();
|
2011-03-25 19:16:05 +00:00
|
|
|
SCH_ITEM* item = screen->GetCurItem();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
pos = wxGetMousePosition();
|
|
|
|
|
|
|
|
pos.y += 20;
|
|
|
|
|
|
|
|
// If needed, stop the current command and deselect current tool
|
|
|
|
switch( id )
|
|
|
|
{
|
2011-03-11 14:44:08 +00:00
|
|
|
case wxID_CUT:
|
|
|
|
case wxID_COPY:
|
|
|
|
case ID_POPUP_CANCEL_CURRENT_COMMAND:
|
2008-03-10 11:42:41 +00:00
|
|
|
case ID_POPUP_SCH_ENTRY_SELECT_SLASH:
|
|
|
|
case ID_POPUP_SCH_ENTRY_SELECT_ANTISLASH:
|
2012-10-23 16:37:19 +00:00
|
|
|
case ID_POPUP_SCH_BEGIN_WIRE:
|
|
|
|
case ID_POPUP_SCH_BEGIN_BUS:
|
2008-03-10 11:42:41 +00:00
|
|
|
case ID_POPUP_END_LINE:
|
|
|
|
case ID_POPUP_SCH_SET_SHAPE_TEXT:
|
|
|
|
case ID_POPUP_SCH_CLEANUP_SHEET:
|
|
|
|
case ID_POPUP_SCH_END_SHEET:
|
|
|
|
case ID_POPUP_SCH_RESIZE_SHEET:
|
2009-05-16 05:38:38 +00:00
|
|
|
case ID_POPUP_IMPORT_GLABEL:
|
2008-03-10 11:42:41 +00:00
|
|
|
case ID_POPUP_SCH_INIT_CMP:
|
|
|
|
case ID_POPUP_SCH_DISPLAYDOC_CMP:
|
|
|
|
case ID_POPUP_SCH_EDIT_CONVERT_CMP:
|
|
|
|
case ID_POPUP_DELETE_BLOCK:
|
|
|
|
case ID_POPUP_PLACE_BLOCK:
|
|
|
|
case ID_POPUP_ZOOM_BLOCK:
|
|
|
|
case ID_POPUP_DRAG_BLOCK:
|
|
|
|
case ID_POPUP_COPY_BLOCK:
|
|
|
|
case ID_POPUP_SCH_DELETE_NODE:
|
|
|
|
case ID_POPUP_SCH_DELETE_CONNECTION:
|
|
|
|
case ID_POPUP_SCH_ENTER_SHEET:
|
|
|
|
case ID_POPUP_SCH_LEAVE_SHEET:
|
|
|
|
case ID_POPUP_SCH_ADD_JUNCTION:
|
|
|
|
case ID_POPUP_SCH_ADD_LABEL:
|
2009-07-08 15:42:45 +00:00
|
|
|
case ID_POPUP_SCH_GETINFO_MARKER:
|
2008-03-10 11:42:41 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* At this point: Do nothing. these commands do not need to stop the
|
|
|
|
* current command (mainly a block command) or reset the current state
|
|
|
|
* They will be executed later, in next switch structure.
|
2008-03-10 11:42:41 +00:00
|
|
|
*/
|
|
|
|
break;
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
case ID_POPUP_SCH_DELETE_CMP:
|
2009-11-04 20:46:53 +00:00
|
|
|
case ID_POPUP_SCH_DELETE:
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2009-12-20 19:48:58 +00:00
|
|
|
// Stop the current command (if any) but keep the current tool
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->EndMouseCapture();
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
default:
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
// Stop the current command and deselect the current tool
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
INSTALL_UNBUFFERED_DC( dc, m_canvas );
|
2011-05-16 19:32:57 +00:00
|
|
|
item = screen->GetCurItem(); // Can be modified by previous calls.
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
switch( id )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
case ID_HIERARCHY:
|
|
|
|
InstallHierarchyFrame( &dc, pos );
|
2011-01-12 21:47:54 +00:00
|
|
|
m_itemToRepeat = NULL;
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case wxID_CUT:
|
2012-03-26 23:47:08 +00:00
|
|
|
if( screen->m_BlockLocate.GetCommand() != BLOCK_MOVE )
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
2011-10-27 13:34:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
HandleBlockEndByPopUp( BLOCK_DELETE, &dc );
|
2011-01-12 21:47:54 +00:00
|
|
|
m_itemToRepeat = NULL;
|
2009-01-06 20:09:32 +00:00
|
|
|
SetSheetNumberAndCount();
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case wxID_PASTE:
|
2011-02-11 20:48:13 +00:00
|
|
|
HandleBlockBegin( &dc, BLOCK_PASTE, screen->GetCrossHairPosition() );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_SCH_ENTRY_SELECT_SLASH:
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2011-03-25 19:16:05 +00:00
|
|
|
SetBusEntryShape( &dc, (SCH_BUS_ENTRY*) item, '/' );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_SCH_ENTRY_SELECT_ANTISLASH:
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2011-03-25 19:16:05 +00:00
|
|
|
SetBusEntryShape( &dc, (SCH_BUS_ENTRY*) item, '\\' );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_CANCEL_CURRENT_COMMAND:
|
2011-12-22 13:28:11 +00:00
|
|
|
if( m_canvas->IsMouseCaptured() )
|
2011-03-11 14:44:08 +00:00
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->EndMouseCapture();
|
|
|
|
SetToolID( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString );
|
2011-03-11 14:44:08 +00:00
|
|
|
}
|
|
|
|
else
|
2011-10-27 17:51:22 +00:00
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
|
2011-10-27 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_END_LINE:
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
EndSegment( &dc );
|
|
|
|
break;
|
|
|
|
|
2012-10-23 16:37:19 +00:00
|
|
|
case ID_POPUP_SCH_BEGIN_WIRE:
|
|
|
|
m_canvas->MoveCursorToCrossHair();
|
|
|
|
OnLeftClick( &dc, screen->GetCrossHairPosition() );
|
|
|
|
break;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-10-23 16:37:19 +00:00
|
|
|
case ID_POPUP_SCH_BEGIN_BUS:
|
|
|
|
m_canvas->MoveCursorToCrossHair();
|
|
|
|
OnLeftClick( &dc, screen->GetCrossHairPosition() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_SCH_SET_SHAPE_TEXT:
|
2008-02-21 12:21:01 +00:00
|
|
|
// Not used
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_SCH_DELETE_NODE:
|
|
|
|
case ID_POPUP_SCH_DELETE_CONNECTION:
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2011-04-15 12:40:56 +00:00
|
|
|
DeleteConnection( id == ID_POPUP_SCH_DELETE_CONNECTION );
|
2008-04-17 16:25:29 +00:00
|
|
|
screen->SetCurItem( NULL );
|
2011-01-12 21:47:54 +00:00
|
|
|
m_itemToRepeat = NULL;
|
2011-12-22 13:28:11 +00:00
|
|
|
screen->TestDanglingEnds( m_canvas, &dc );
|
|
|
|
m_canvas->Refresh();
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_SCH_BREAK_WIRE:
|
|
|
|
{
|
2012-02-26 18:39:39 +00:00
|
|
|
DLIST< SCH_ITEM > oldWires;
|
|
|
|
|
|
|
|
oldWires.SetOwnership( false ); // Prevent DLIST for deleting items in destructor.
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2012-02-26 18:39:39 +00:00
|
|
|
screen->ExtractWires( oldWires, true );
|
2011-02-11 20:48:13 +00:00
|
|
|
screen->BreakSegment( screen->GetCrossHairPosition() );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
if( oldWires.GetCount() != 0 )
|
|
|
|
{
|
|
|
|
PICKED_ITEMS_LIST oldItems;
|
|
|
|
|
|
|
|
oldItems.m_Status = UR_WIRE_IMAGE;
|
|
|
|
|
|
|
|
while( oldWires.GetCount() != 0 )
|
|
|
|
{
|
|
|
|
ITEM_PICKER picker = ITEM_PICKER( oldWires.PopFront(), UR_WIRE_IMAGE );
|
|
|
|
oldItems.PushItem( picker );
|
|
|
|
}
|
|
|
|
|
|
|
|
SaveCopyInUndoList( oldItems, UR_WIRE_IMAGE );
|
|
|
|
}
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
screen->TestDanglingEnds( m_canvas, &dc );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2010-09-05 17:01:48 +00:00
|
|
|
break;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
case ID_POPUP_SCH_DELETE_CMP:
|
|
|
|
case ID_POPUP_SCH_DELETE:
|
2010-09-05 17:01:48 +00:00
|
|
|
if( item == NULL )
|
|
|
|
break;
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
DeleteItem( item );
|
2010-09-05 17:01:48 +00:00
|
|
|
screen->SetCurItem( NULL );
|
2011-01-12 21:47:54 +00:00
|
|
|
m_itemToRepeat = NULL;
|
2011-12-22 13:28:11 +00:00
|
|
|
screen->TestDanglingEnds( m_canvas, &dc );
|
2010-09-05 17:01:48 +00:00
|
|
|
SetSheetNumberAndCount();
|
|
|
|
OnModify();
|
2011-03-25 19:16:05 +00:00
|
|
|
break;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
case ID_POPUP_SCH_END_SHEET:
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2012-01-04 22:08:46 +00:00
|
|
|
addCurrentItemToList( &dc );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_SCH_RESIZE_SHEET:
|
2011-03-25 19:16:05 +00:00
|
|
|
ReSizeSheet( (SCH_SHEET*) item, &dc );
|
2011-12-22 13:28:11 +00:00
|
|
|
screen->TestDanglingEnds( m_canvas, &dc );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2009-05-16 05:38:38 +00:00
|
|
|
case ID_POPUP_IMPORT_GLABEL:
|
2011-03-25 19:16:05 +00:00
|
|
|
if( item != NULL && item->Type() == SCH_SHEET_T )
|
2011-03-30 19:26:05 +00:00
|
|
|
screen->SetCurItem( ImportSheetPin( (SCH_SHEET*) item, &dc ) );
|
2009-05-16 05:38:38 +00:00
|
|
|
break;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
case ID_POPUP_SCH_CLEANUP_SHEET:
|
2011-03-25 19:16:05 +00:00
|
|
|
if( item != NULL && item->Type() == SCH_SHEET_T )
|
2010-06-24 18:31:43 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) item;
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
if( !sheet->HasUndefinedPins() )
|
2010-06-24 18:31:43 +00:00
|
|
|
{
|
|
|
|
DisplayInfoMessage( this,
|
2010-12-08 20:12:46 +00:00
|
|
|
_( "There are no undefined labels in this sheet to clean up." ) );
|
2010-06-24 18:31:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
if( !IsOK( this, _( "Do you wish to cleanup this sheet?" ) ) )
|
2010-06-24 18:31:43 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Save sheet in undo list before cleaning up unreferenced hierarchical labels. */
|
|
|
|
SaveCopyInUndoList( sheet, UR_CHANGED );
|
|
|
|
sheet->CleanupSheet();
|
|
|
|
OnModify();
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->RefreshDrawingRect( sheet->GetBoundingBox() );
|
2010-06-24 18:31:43 +00:00
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_SCH_INIT_CMP:
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
case ID_POPUP_SCH_EDIT_CONVERT_CMP:
|
2008-03-10 11:42:41 +00:00
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
// Ensure the struct is a component (could be a struct of a component, like Field, text..)
|
2011-03-25 19:16:05 +00:00
|
|
|
if( item && item->Type() == SCH_COMPONENT_T )
|
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2011-03-25 19:16:05 +00:00
|
|
|
ConvertPart( (SCH_COMPONENT*) item, &dc );
|
|
|
|
}
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_SCH_DISPLAYDOC_CMP:
|
2008-03-10 11:42:41 +00:00
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
// Ensure the struct is a component (could be a piece of a component, like Field, text..)
|
2011-03-25 19:16:05 +00:00
|
|
|
if( item && item->Type() == SCH_COMPONENT_T )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-10-25 15:43:42 +00:00
|
|
|
LIB_ALIAS* LibEntry;
|
2011-03-25 19:16:05 +00:00
|
|
|
LibEntry = CMP_LIBRARY::FindLibraryEntry( ( (SCH_COMPONENT*) item )->GetLibName() );
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( LibEntry && LibEntry->GetDocFileName() != wxEmptyString )
|
2009-04-07 11:53:58 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
GetAssociatedDocument( this, LibEntry->GetDocFileName(),
|
2010-10-25 15:43:42 +00:00
|
|
|
&wxGetApp().GetLibraryPathList() );
|
2009-04-07 11:53:58 +00:00
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_SCH_ENTER_SHEET:
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
if( item && (item->Type() == SCH_SHEET_T) )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-02-05 02:21:11 +00:00
|
|
|
m_CurrentSheet->Push( (SCH_SHEET*) item );
|
|
|
|
DisplayCurrentSheet();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2011-03-25 19:16:05 +00:00
|
|
|
|
|
|
|
break;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
case ID_POPUP_SCH_LEAVE_SHEET:
|
2011-02-05 02:21:11 +00:00
|
|
|
m_CurrentSheet->Pop();
|
|
|
|
DisplayCurrentSheet();
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case wxID_COPY: // really this is a Save block for paste
|
|
|
|
HandleBlockEndByPopUp( BLOCK_SAVE, &dc );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_PLACE_BLOCK:
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetAutoPanRequest( false );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
HandleBlockPlace( &dc );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_ZOOM_BLOCK:
|
|
|
|
HandleBlockEndByPopUp( BLOCK_ZOOM, &dc );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_DELETE_BLOCK:
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
HandleBlockEndByPopUp( BLOCK_DELETE, &dc );
|
2009-01-06 20:09:32 +00:00
|
|
|
SetSheetNumberAndCount();
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_COPY_BLOCK:
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
HandleBlockEndByPopUp( BLOCK_COPY, &dc );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_DRAG_BLOCK:
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
HandleBlockEndByPopUp( BLOCK_DRAG, &dc );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_SCH_ADD_JUNCTION:
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2011-02-11 20:48:13 +00:00
|
|
|
screen->SetCurItem( AddJunction( &dc, screen->GetCrossHairPosition(), true ) );
|
2011-12-22 13:28:11 +00:00
|
|
|
screen->TestDanglingEnds( m_canvas, &dc );
|
2008-04-17 16:25:29 +00:00
|
|
|
screen->SetCurItem( NULL );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_SCH_ADD_LABEL:
|
|
|
|
case ID_POPUP_SCH_ADD_GLABEL:
|
2010-12-08 20:12:46 +00:00
|
|
|
screen->SetCurItem( CreateNewText( &dc, id == ID_POPUP_SCH_ADD_LABEL ?
|
|
|
|
LAYER_LOCLABEL : LAYER_GLOBLABEL ) );
|
2011-03-25 19:16:05 +00:00
|
|
|
item = screen->GetCurItem();
|
|
|
|
|
|
|
|
if( item )
|
2012-01-04 22:08:46 +00:00
|
|
|
addCurrentItemToList( &dc );
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2009-07-08 15:42:45 +00:00
|
|
|
case ID_POPUP_SCH_GETINFO_MARKER:
|
2011-03-25 19:16:05 +00:00
|
|
|
if( item && item->Type() == SCH_MARKER_T )
|
|
|
|
( (SCH_MARKER*) item )->DisplayMarkerInfo( this );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2009-07-08 15:42:45 +00:00
|
|
|
break;
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
default: // Log error:
|
2011-10-27 17:51:22 +00:00
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "Cannot process command event ID %d" ),
|
|
|
|
event.GetId() ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
// End switch ( id ) (Command execution)
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-02-24 20:22:12 +00:00
|
|
|
if( GetToolId() == ID_NO_TOOL_SELECTED )
|
2011-01-12 21:47:54 +00:00
|
|
|
m_itemToRepeat = NULL;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-19 12:08:12 +00:00
|
|
|
void SCH_EDIT_FRAME::OnMoveItem( wxCommandEvent& aEvent )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-04-19 12:08:12 +00:00
|
|
|
SCH_SCREEN* screen = GetScreen();
|
2012-10-08 19:34:04 +00:00
|
|
|
SCH_ITEM* item = screen->GetCurItem();
|
2011-04-19 12:08:12 +00:00
|
|
|
|
|
|
|
if( item == NULL )
|
2011-10-21 13:59:15 +00:00
|
|
|
{
|
|
|
|
// If we didn't get here by a hot key, then something has gone wrong.
|
|
|
|
if( aEvent.GetInt() == 0 )
|
|
|
|
return;
|
|
|
|
|
2011-10-26 20:46:04 +00:00
|
|
|
EDA_HOTKEY_CLIENT_DATA* data = (EDA_HOTKEY_CLIENT_DATA*) aEvent.GetClientObject();
|
2011-10-21 13:59:15 +00:00
|
|
|
|
2011-10-26 20:46:04 +00:00
|
|
|
wxCHECK_RET( data != NULL, wxT( "Invalid hot key client object." ) );
|
2011-10-21 13:59:15 +00:00
|
|
|
|
|
|
|
item = LocateAndShowItem( data->GetPosition(), SCH_COLLECTOR::MovableItems,
|
|
|
|
aEvent.GetInt() );
|
|
|
|
|
|
|
|
// Exit if no item found at the current location or the item is already being edited.
|
|
|
|
if( (item == NULL) || (item->GetFlags() != 0) )
|
|
|
|
return;
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
INSTALL_UNBUFFERED_DC( dc, m_canvas );
|
2011-04-19 12:08:12 +00:00
|
|
|
|
|
|
|
switch( item->Type() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-10-19 20:32:21 +00:00
|
|
|
case SCH_LINE_T:
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2011-10-19 20:32:21 +00:00
|
|
|
case SCH_JUNCTION_T:
|
|
|
|
case SCH_NO_CONNECT_T:
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_BUS_ENTRY_T:
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_HIERARCHICAL_LABEL_T:
|
|
|
|
case SCH_TEXT_T:
|
2011-10-19 20:32:21 +00:00
|
|
|
case SCH_COMPONENT_T:
|
2011-10-21 13:59:15 +00:00
|
|
|
case SCH_SHEET_PIN_T:
|
2011-10-22 12:31:44 +00:00
|
|
|
case SCH_FIELD_T:
|
2011-10-19 20:32:21 +00:00
|
|
|
MoveItem( item, &dc );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2011-08-31 14:59:20 +00:00
|
|
|
case SCH_BITMAP_T:
|
|
|
|
MoveImage( (SCH_BITMAP*) item, &dc );
|
|
|
|
break;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_SHEET_T:
|
2011-04-19 12:08:12 +00:00
|
|
|
StartMoveSheet( (SCH_SHEET*) item, &dc );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2011-10-19 20:32:21 +00:00
|
|
|
case SCH_MARKER_T:
|
2007-08-20 01:20:48 +00:00
|
|
|
default:
|
2011-04-19 12:08:12 +00:00
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "Cannot move item type %s" ),
|
|
|
|
GetChars( item->GetClass() ) ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-04-19 12:08:12 +00:00
|
|
|
|
|
|
|
if( GetToolId() == ID_NO_TOOL_SELECTED )
|
|
|
|
m_itemToRepeat = NULL;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2011-02-05 19:22:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SCH_EDIT_FRAME::OnCancelCurrentCommand( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = GetScreen();
|
|
|
|
|
|
|
|
if( screen->IsBlockActive() )
|
|
|
|
{
|
2012-02-28 20:14:17 +00:00
|
|
|
m_canvas->SetCursor( (wxStockCursor) m_canvas->GetDefaultCursor() );
|
2011-02-05 19:22:58 +00:00
|
|
|
screen->ClearBlockCommand();
|
|
|
|
|
|
|
|
// Stop the current command (if any) but keep the current tool
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->EndMouseCapture();
|
2011-02-05 19:22:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
if( m_canvas->IsMouseCaptured() ) // Stop the current command but keep the current tool
|
|
|
|
m_canvas->EndMouseCapture();
|
2011-03-05 10:35:18 +00:00
|
|
|
else // Deselect current tool
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
|
2011-03-05 10:35:18 +00:00
|
|
|
}
|
2011-02-05 19:22:58 +00:00
|
|
|
}
|
2011-02-21 13:54:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SCH_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
|
|
|
|
{
|
2012-03-19 07:48:29 +00:00
|
|
|
int id = aEvent.GetId();
|
2011-02-21 13:54:29 +00:00
|
|
|
|
|
|
|
// Stop the current command and deselect the current tool.
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
|
2011-02-21 13:54:29 +00:00
|
|
|
|
|
|
|
switch( id )
|
|
|
|
{
|
2011-02-24 20:22:12 +00:00
|
|
|
case ID_NO_TOOL_SELECTED:
|
2011-12-22 13:28:11 +00:00
|
|
|
SetToolID( id, m_canvas->GetDefaultCursor(), _( "No tool selected" ) );
|
2011-02-21 13:54:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_HIERARCHY_PUSH_POP_BUTT:
|
|
|
|
SetToolID( id, wxCURSOR_HAND, _( "Descend or ascend hierarchy" ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_NOCONN_BUTT:
|
|
|
|
SetToolID( id, wxCURSOR_PENCIL, _( "Add no connect" ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_WIRE_BUTT:
|
|
|
|
SetToolID( id, wxCURSOR_PENCIL, _( "Add wire" ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_BUS_BUTT:
|
|
|
|
SetToolID( id, wxCURSOR_PENCIL, _( "Add bus" ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_LINE_COMMENT_BUTT:
|
|
|
|
SetToolID( id, wxCURSOR_PENCIL, _( "Add lines" ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_JUNCTION_BUTT:
|
|
|
|
SetToolID( id, wxCURSOR_PENCIL, _( "Add junction" ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_LABEL_BUTT:
|
|
|
|
SetToolID( id, wxCURSOR_PENCIL, _( "Add label" ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_GLABEL_BUTT:
|
|
|
|
SetToolID( id, wxCURSOR_PENCIL, _( "Add global label" ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_HIERLABEL_BUTT:
|
|
|
|
SetToolID( id, wxCURSOR_PENCIL, _( "Add hierarchical label" ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_TEXT_COMMENT_BUTT:
|
|
|
|
SetToolID( id, wxCURSOR_PENCIL, _( "Add text" ) );
|
|
|
|
break;
|
|
|
|
|
2011-08-31 14:59:20 +00:00
|
|
|
case ID_ADD_IMAGE_BUTT:
|
|
|
|
SetToolID( id, wxCURSOR_PENCIL, _( "Add image" ) );
|
|
|
|
break;
|
|
|
|
|
2011-02-21 13:54:29 +00:00
|
|
|
case ID_WIRETOBUS_ENTRY_BUTT:
|
|
|
|
SetToolID( id, wxCURSOR_PENCIL, _( "Add wire to bus entry" ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_BUSTOBUS_ENTRY_BUTT:
|
|
|
|
SetToolID( id, wxCURSOR_PENCIL, _( "Add bus to bus entry" ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_SHEET_SYMBOL_BUTT:
|
|
|
|
SetToolID( id, wxCURSOR_PENCIL, _( "Add sheet" ) );
|
|
|
|
break;
|
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
case ID_SHEET_PIN_BUTT:
|
2011-02-21 13:54:29 +00:00
|
|
|
SetToolID( id, wxCURSOR_PENCIL, _( "Add sheet pins" ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_IMPORT_HLABEL_BUTT:
|
|
|
|
SetToolID( id, wxCURSOR_PENCIL, _( "Import sheet pins" ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_SCH_PLACE_COMPONENT:
|
|
|
|
SetToolID( id, wxCURSOR_PENCIL, _( "Add component" ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_PLACE_POWER_BUTT:
|
|
|
|
SetToolID( id, wxCURSOR_PENCIL, _( "Add power" ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_SCHEMATIC_DELETE_ITEM_BUTT:
|
|
|
|
SetToolID( id, wxCURSOR_BULLSEYE, _( "Delete item" ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
m_itemToRepeat = NULL;
|
|
|
|
}
|
2011-10-24 13:56:35 +00:00
|
|
|
|
|
|
|
// Simulate left click event if we got here from a hot key.
|
2011-10-26 20:46:04 +00:00
|
|
|
if( aEvent.GetClientObject() != NULL )
|
2011-10-24 13:56:35 +00:00
|
|
|
{
|
2011-10-26 20:46:04 +00:00
|
|
|
EDA_HOTKEY_CLIENT_DATA* data = (EDA_HOTKEY_CLIENT_DATA*) aEvent.GetClientObject();
|
2011-10-24 13:56:35 +00:00
|
|
|
|
|
|
|
wxPoint pos = data->GetPosition();
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
INSTALL_UNBUFFERED_DC( dc, m_canvas );
|
2011-10-24 13:56:35 +00:00
|
|
|
OnLeftClick( &dc, pos );
|
|
|
|
}
|
2011-02-21 13:54:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_EDIT_FRAME::OnUpdateSelectTool( wxUpdateUIEvent& aEvent )
|
|
|
|
{
|
2011-12-14 20:03:15 +00:00
|
|
|
if( aEvent.GetEventObject() == m_drawToolBar )
|
2011-02-24 20:22:12 +00:00
|
|
|
aEvent.Check( GetToolId() == aEvent.GetId() );
|
2011-02-21 13:54:29 +00:00
|
|
|
}
|
2011-04-15 12:40:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SCH_EDIT_FRAME::DeleteConnection( bool aFullConnection )
|
|
|
|
{
|
2012-08-24 11:14:10 +00:00
|
|
|
PICKED_ITEMS_LIST pickList;
|
|
|
|
SCH_SCREEN* screen = GetScreen();
|
|
|
|
wxPoint pos = screen->GetCrossHairPosition();
|
2011-04-15 12:40:56 +00:00
|
|
|
|
|
|
|
if( screen->GetConnection( pos, pickList, aFullConnection ) != 0 )
|
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
DeleteItemsInList( m_canvas, pickList );
|
2011-04-15 12:40:56 +00:00
|
|
|
OnModify();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_EDIT_FRAME::DeleteItemAtCrossHair( wxDC* DC )
|
|
|
|
{
|
2012-08-24 11:14:10 +00:00
|
|
|
SCH_ITEM* item;
|
2011-04-15 12:40:56 +00:00
|
|
|
SCH_SCREEN* screen = GetScreen();
|
|
|
|
|
|
|
|
item = LocateItem( screen->GetCrossHairPosition(), SCH_COLLECTOR::ParentItems );
|
|
|
|
|
|
|
|
if( item )
|
|
|
|
{
|
|
|
|
bool itemHasConnections = item->IsConnectable();
|
|
|
|
|
|
|
|
screen->SetCurItem( NULL );
|
|
|
|
SetRepeatItem( NULL );
|
|
|
|
DeleteItem( item );
|
|
|
|
|
|
|
|
if( itemHasConnections )
|
2011-12-22 13:28:11 +00:00
|
|
|
screen->TestDanglingEnds( m_canvas, DC );
|
2011-04-15 12:40:56 +00:00
|
|
|
|
|
|
|
OnModify();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2011-10-22 12:31:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void moveItem( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase )
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
|
2012-08-24 11:14:10 +00:00
|
|
|
SCH_ITEM* item = screen->GetCurItem();
|
2011-10-22 12:31:44 +00:00
|
|
|
|
|
|
|
wxCHECK_RET( (item != NULL), wxT( "Cannot move invalid schematic item." ) );
|
|
|
|
|
2012-01-24 17:46:32 +00:00
|
|
|
#ifndef USE_WX_OVERLAY
|
2011-10-22 12:31:44 +00:00
|
|
|
// Erase the current item at its current position.
|
|
|
|
if( aErase )
|
|
|
|
item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
|
2012-01-24 17:46:32 +00:00
|
|
|
#endif
|
2012-08-24 11:14:10 +00:00
|
|
|
|
2011-10-22 12:31:44 +00:00
|
|
|
item->SetPosition( screen->GetCrossHairPosition() );
|
|
|
|
|
|
|
|
// Draw the item item at it's new position.
|
|
|
|
item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void abortMoveItem( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
|
|
|
|
{
|
2012-08-24 11:14:10 +00:00
|
|
|
SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
|
|
|
|
SCH_ITEM* item = screen->GetCurItem();
|
2011-10-22 12:31:44 +00:00
|
|
|
SCH_EDIT_FRAME* parent = ( SCH_EDIT_FRAME* ) aPanel->GetParent();
|
|
|
|
|
|
|
|
parent->SetRepeatItem( NULL );
|
|
|
|
screen->SetCurItem( NULL );
|
|
|
|
|
|
|
|
if( item == NULL ) /* no current item */
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( item->IsNew() )
|
|
|
|
{
|
|
|
|
delete item;
|
|
|
|
item = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCH_ITEM* oldItem = parent->GetUndoItem();
|
|
|
|
|
|
|
|
SCH_ITEM* currentItem;
|
|
|
|
|
|
|
|
// Items that are children of other objects are undone by swapping the contents
|
|
|
|
// of the parent items.
|
|
|
|
if( (item->Type() == SCH_SHEET_PIN_T) || (item->Type() == SCH_FIELD_T) )
|
|
|
|
{
|
|
|
|
currentItem = (SCH_ITEM*) item->GetParent();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
currentItem = item;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxCHECK_RET( oldItem != NULL && currentItem->Type() == oldItem->Type(),
|
|
|
|
wxT( "Cannot restore undefined or bad last schematic item." ) );
|
|
|
|
|
|
|
|
// Never delete existing item, because it can be referenced by an undo/redo command
|
|
|
|
// Just restore its data
|
|
|
|
currentItem->SwapData( oldItem );
|
|
|
|
item->ClearFlags();
|
|
|
|
}
|
|
|
|
|
|
|
|
aPanel->Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_EDIT_FRAME::MoveItem( SCH_ITEM* aItem, wxDC* aDC )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( aItem != NULL, wxT( "Cannot move invalid schematic item" ) );
|
|
|
|
|
|
|
|
m_itemToRepeat = NULL;
|
|
|
|
|
|
|
|
if( !aItem->IsNew() )
|
|
|
|
{
|
|
|
|
if( (aItem->Type() == SCH_SHEET_PIN_T) || (aItem->Type() == SCH_FIELD_T) )
|
|
|
|
SetUndoItem( (SCH_ITEM*) aItem->GetParent() );
|
|
|
|
else
|
|
|
|
SetUndoItem( aItem );
|
|
|
|
}
|
|
|
|
|
|
|
|
aItem->SetFlags( IS_MOVED );
|
2012-01-24 17:46:32 +00:00
|
|
|
#ifdef USE_WX_OVERLAY
|
|
|
|
this->Refresh();
|
|
|
|
this->Update();
|
|
|
|
#endif
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->CrossHairOff( aDC );
|
2011-10-22 12:31:44 +00:00
|
|
|
|
|
|
|
if( aItem->Type() != SCH_SHEET_PIN_T )
|
|
|
|
GetScreen()->SetCrossHairPosition( aItem->GetPosition() );
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2011-10-22 12:31:44 +00:00
|
|
|
|
|
|
|
OnModify();
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->SetMouseCapture( moveItem, abortMoveItem );
|
2011-10-22 12:31:44 +00:00
|
|
|
GetScreen()->SetCurItem( aItem );
|
2011-12-22 13:28:11 +00:00
|
|
|
moveItem( m_canvas, aDC, wxDefaultPosition, true );
|
|
|
|
m_canvas->CrossHairOn( aDC );
|
2011-10-22 12:31:44 +00:00
|
|
|
}
|
2011-10-26 20:46:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SCH_EDIT_FRAME::OnRotate( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = GetScreen();
|
2012-08-24 11:14:10 +00:00
|
|
|
SCH_ITEM* item = screen->GetCurItem();
|
2011-10-26 20:46:04 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
INSTALL_UNBUFFERED_DC( dc, m_canvas );
|
2011-10-26 20:46:04 +00:00
|
|
|
|
|
|
|
if( item == NULL )
|
|
|
|
{
|
|
|
|
// Allows block rotate operation on hot key.
|
2012-03-26 23:47:08 +00:00
|
|
|
if( screen->m_BlockLocate.GetState() != STATE_NO_BLOCK )
|
2011-10-26 20:46:04 +00:00
|
|
|
{
|
|
|
|
HandleBlockEndByPopUp( BLOCK_ROTATE, &dc );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-28 20:30:50 +00:00
|
|
|
// If we didn't get here by a hot key, then something has gone wrong.
|
|
|
|
if( aEvent.GetInt() == 0 )
|
|
|
|
return;
|
|
|
|
|
2011-10-26 20:46:04 +00:00
|
|
|
EDA_HOTKEY_CLIENT_DATA* data = (EDA_HOTKEY_CLIENT_DATA*) aEvent.GetClientObject();
|
|
|
|
|
|
|
|
wxCHECK_RET( data != NULL, wxT( "Invalid hot key client object." ) );
|
|
|
|
|
|
|
|
item = LocateAndShowItem( data->GetPosition(), SCH_COLLECTOR::RotatableItems,
|
|
|
|
aEvent.GetInt() );
|
|
|
|
|
|
|
|
// Exit if no item found at the current location or the item is already being edited.
|
|
|
|
if( (item == NULL) || (item->GetFlags() != 0) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case SCH_COMPONENT_T:
|
2011-10-28 20:30:50 +00:00
|
|
|
if( aEvent.GetId() == ID_SCH_ROTATE_CLOCKWISE )
|
|
|
|
OrientComponent( CMP_ROTATE_CLOCKWISE );
|
|
|
|
else if( aEvent.GetId() == ID_SCH_ROTATE_COUNTERCLOCKWISE )
|
|
|
|
OrientComponent( CMP_ROTATE_COUNTERCLOCKWISE );
|
|
|
|
else
|
|
|
|
wxFAIL_MSG( wxT( "Unknown rotate item command ID." ) );
|
|
|
|
|
|
|
|
break;
|
2011-10-26 20:46:04 +00:00
|
|
|
|
|
|
|
case SCH_TEXT_T:
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_HIERARCHICAL_LABEL_T:
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2011-10-26 20:46:04 +00:00
|
|
|
ChangeTextOrient( (SCH_TEXT*) item, &dc );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_FIELD_T:
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2011-10-26 20:46:04 +00:00
|
|
|
RotateField( (SCH_FIELD*) item, &dc );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_BITMAP_T:
|
|
|
|
RotateImage( (SCH_BITMAP*) item );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_SHEET_T: /// @todo allow sheet rotate on hotkey
|
|
|
|
default:
|
2011-10-27 13:34:28 +00:00
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "Cannot rotate schematic item type %s." ),
|
|
|
|
GetChars( item->GetClass() ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( item->GetFlags() == 0 )
|
|
|
|
screen->SetCurItem( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_EDIT_FRAME::OnEditItem( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = GetScreen();
|
|
|
|
SCH_ITEM* item = screen->GetCurItem();
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
INSTALL_UNBUFFERED_DC( dc, m_canvas );
|
2011-10-27 13:34:28 +00:00
|
|
|
|
|
|
|
if( item == NULL )
|
|
|
|
{
|
|
|
|
// If we didn't get here by a hot key, then something has gone wrong.
|
|
|
|
if( aEvent.GetInt() == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
EDA_HOTKEY_CLIENT_DATA* data = (EDA_HOTKEY_CLIENT_DATA*) aEvent.GetClientObject();
|
|
|
|
|
|
|
|
wxCHECK_RET( data != NULL, wxT( "Invalid hot key client object." ) );
|
|
|
|
|
|
|
|
item = LocateAndShowItem( data->GetPosition(), SCH_COLLECTOR::EditableItems,
|
|
|
|
aEvent.GetInt() );
|
|
|
|
|
|
|
|
// Exit if no item found at the current location or the item is already being edited.
|
|
|
|
if( (item == NULL) || (item->GetFlags() != 0) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case SCH_COMPONENT_T:
|
|
|
|
{
|
|
|
|
switch( aEvent.GetId() )
|
|
|
|
{
|
|
|
|
case ID_SCH_EDIT_COMPONENT_REFERENCE:
|
2012-06-03 11:16:08 +00:00
|
|
|
EditComponentFieldText( ( (SCH_COMPONENT*) item )->GetField( REFERENCE ) );
|
2011-10-27 13:34:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_SCH_EDIT_COMPONENT_VALUE:
|
2012-06-03 11:16:08 +00:00
|
|
|
EditComponentFieldText( ( (SCH_COMPONENT*) item )->GetField( VALUE ) );
|
2011-10-27 13:34:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_SCH_EDIT_COMPONENT_FOOTPRINT:
|
2012-06-03 11:16:08 +00:00
|
|
|
EditComponentFieldText( ( (SCH_COMPONENT*) item )->GetField( FOOTPRINT ) );
|
2011-10-27 13:34:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_SCH_EDIT_ITEM:
|
|
|
|
EditComponent( (SCH_COMPONENT*) item );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "Invalid schematic component edit command ID %d" ),
|
|
|
|
aEvent.GetId() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SCH_SHEET_T:
|
|
|
|
EditSheet( (SCH_SHEET*) item, &dc );
|
2011-10-26 20:46:04 +00:00
|
|
|
break;
|
2011-10-27 13:34:28 +00:00
|
|
|
|
|
|
|
case SCH_SHEET_PIN_T:
|
|
|
|
EditSheetPin( (SCH_SHEET_PIN*) item, &dc );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_TEXT_T:
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_HIERARCHICAL_LABEL_T:
|
|
|
|
EditSchematicText( (SCH_TEXT*) item );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_FIELD_T:
|
2012-06-03 11:16:08 +00:00
|
|
|
EditComponentFieldText( (SCH_FIELD*) item );
|
2011-10-27 13:34:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_BITMAP_T:
|
|
|
|
EditImage( (SCH_BITMAP*) item );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "Cannot edit schematic item type %s." ),
|
|
|
|
GetChars( item->GetClass() ) ) );
|
2011-10-26 20:46:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( item->GetFlags() == 0 )
|
|
|
|
screen->SetCurItem( NULL );
|
|
|
|
}
|
2011-10-27 17:51:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SCH_EDIT_FRAME::OnDragItem( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = GetScreen();
|
|
|
|
SCH_ITEM* item = screen->GetCurItem();
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
INSTALL_UNBUFFERED_DC( dc, m_canvas );
|
2011-10-27 17:51:22 +00:00
|
|
|
|
|
|
|
if( item == NULL )
|
|
|
|
{
|
|
|
|
// If we didn't get here by a hot key, then something has gone wrong.
|
|
|
|
if( aEvent.GetInt() == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
EDA_HOTKEY_CLIENT_DATA* data = (EDA_HOTKEY_CLIENT_DATA*) aEvent.GetClientObject();
|
|
|
|
|
|
|
|
wxCHECK_RET( data != NULL, wxT( "Invalid hot key client object." ) );
|
|
|
|
|
|
|
|
item = LocateAndShowItem( data->GetPosition(), SCH_COLLECTOR::DraggableItems,
|
|
|
|
aEvent.GetInt() );
|
|
|
|
|
|
|
|
// Exit if no item found at the current location or the item is already being edited.
|
|
|
|
if( (item == NULL) || (item->GetFlags() != 0) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case SCH_BUS_ENTRY_T:
|
|
|
|
case SCH_LINE_T:
|
|
|
|
case SCH_JUNCTION_T:
|
|
|
|
if( item->GetLayer() == LAYER_BUS )
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Fall thru if item is not on bus layer.
|
|
|
|
case SCH_COMPONENT_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_HIERARCHICAL_LABEL_T:
|
|
|
|
case SCH_SHEET_T:
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2011-10-27 17:51:22 +00:00
|
|
|
|
|
|
|
// The easiest way to handle a drag component or sheet command
|
|
|
|
// is to simulate a block drag command
|
2012-03-26 23:47:08 +00:00
|
|
|
if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK )
|
2011-10-27 17:51:22 +00:00
|
|
|
{
|
|
|
|
if( !HandleBlockBegin( &dc, BLOCK_DRAG, screen->GetCrossHairPosition() ) )
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Give a non null size to the search block:
|
|
|
|
screen->m_BlockLocate.Inflate( 1 );
|
|
|
|
HandleBlockEnd( &dc );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "Cannot drag schematic item type %s." ),
|
|
|
|
GetChars( item->GetClass() ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Since the drag is actually a block command, clear the current item.
|
|
|
|
screen->SetCurItem( NULL );
|
|
|
|
}
|
2011-10-28 20:30:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SCH_EDIT_FRAME::OnOrient( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = GetScreen();
|
2012-08-24 11:14:10 +00:00
|
|
|
SCH_ITEM* item = screen->GetCurItem();
|
2011-10-28 20:30:50 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
INSTALL_UNBUFFERED_DC( dc, m_canvas );
|
2011-10-28 20:30:50 +00:00
|
|
|
|
|
|
|
if( item == NULL )
|
|
|
|
{
|
|
|
|
// Allows block rotate operation on hot key.
|
2012-03-26 23:47:08 +00:00
|
|
|
if( screen->m_BlockLocate.GetState() != STATE_NO_BLOCK )
|
2011-10-28 20:30:50 +00:00
|
|
|
{
|
|
|
|
if( aEvent.GetId() == ID_SCH_MIRROR_X )
|
|
|
|
HandleBlockEndByPopUp( BLOCK_MIRROR_X, &dc );
|
|
|
|
else if( aEvent.GetId() == ID_SCH_MIRROR_Y )
|
|
|
|
HandleBlockEndByPopUp( BLOCK_MIRROR_Y, &dc );
|
|
|
|
else
|
|
|
|
wxFAIL_MSG( wxT( "Unknown block oriention command ID." ) );
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we didn't get here by a hot key, then something has gone wrong.
|
|
|
|
if( aEvent.GetInt() == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
EDA_HOTKEY_CLIENT_DATA* data = (EDA_HOTKEY_CLIENT_DATA*) aEvent.GetClientObject();
|
|
|
|
|
|
|
|
wxCHECK_RET( data != NULL, wxT( "Invalid hot key client object." ) );
|
|
|
|
|
|
|
|
item = LocateAndShowItem( data->GetPosition(), SCH_COLLECTOR::OrientableItems,
|
|
|
|
aEvent.GetInt() );
|
|
|
|
|
|
|
|
// Exit if no item found at the current location or the item is already being edited.
|
|
|
|
if( (item == NULL) || (item->GetFlags() != 0) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case SCH_COMPONENT_T:
|
|
|
|
if( aEvent.GetId() == ID_SCH_MIRROR_X )
|
|
|
|
OrientComponent( CMP_MIRROR_X );
|
|
|
|
else if( aEvent.GetId() == ID_SCH_MIRROR_Y )
|
|
|
|
OrientComponent( CMP_MIRROR_Y );
|
|
|
|
else if( aEvent.GetId() == ID_SCH_ORIENT_NORMAL )
|
|
|
|
OrientComponent( CMP_NORMAL );
|
|
|
|
else
|
|
|
|
wxFAIL_MSG( wxT( "Invalid orient schematic component command ID." ) );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_BITMAP_T:
|
|
|
|
if( aEvent.GetId() == ID_SCH_MIRROR_X )
|
|
|
|
MirrorImage( (SCH_BITMAP*) item, true );
|
|
|
|
else if( aEvent.GetId() == ID_SCH_MIRROR_Y )
|
|
|
|
MirrorImage( (SCH_BITMAP*) item, false );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "Schematic object type %s cannot be oriented." ),
|
|
|
|
GetChars( item->GetClass() ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( item->GetFlags() == 0 )
|
|
|
|
screen->SetCurItem( NULL );
|
|
|
|
}
|