Commit 92109564 authored by Wayne Stambaugh's avatar Wayne Stambaugh

EESchema code simplification improvements.

* Factor component unit select handling out of huge switch statement into
  a separate function.
parent 430a39d7
......@@ -85,6 +85,23 @@ enum id_eeschema_frm
ID_POPUP_SCH_EDIT_REF_CMP,
ID_POPUP_SCH_EDIT_FOOTPRINT_CMP,
ID_POPUP_SCH_EDIT_CONVERT_CMP,
ID_POPUP_SCH_ROTATE_FIELD,
ID_POPUP_SCH_EDIT_FIELD,
ID_POPUP_SCH_CHANGE_TYPE_TEXT,
ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_LABEL,
ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_GLABEL,
ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_COMMENT,
ID_POPUP_SCH_DISPLAYDOC_CMP,
ID_POPUP_SCH_ENTER_SHEET,
ID_POPUP_SCH_LEAVE_SHEET,
ID_POPUP_SCH_ADD_JUNCTION,
ID_POPUP_SCH_ADD_LABEL,
ID_POPUP_SCH_ADD_GLABEL,
ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_HLABEL,
ID_POPUP_SCH_GETINFO_MARKER,
ID_POPUP_END_RANGE,
// Unit select context menus command IDs.
ID_POPUP_SCH_SELECT_UNIT_CMP,
ID_POPUP_SCH_SELECT_UNIT1,
ID_POPUP_SCH_SELECT_UNIT2,
......@@ -112,21 +129,6 @@ enum id_eeschema_frm
ID_POPUP_SCH_SELECT_UNIT24,
ID_POPUP_SCH_SELECT_UNIT25,
ID_POPUP_SCH_SELECT_UNIT26,
ID_POPUP_SCH_ROTATE_FIELD,
ID_POPUP_SCH_EDIT_FIELD,
ID_POPUP_SCH_CHANGE_TYPE_TEXT,
ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_LABEL,
ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_GLABEL,
ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_COMMENT,
ID_POPUP_SCH_DISPLAYDOC_CMP,
ID_POPUP_SCH_ENTER_SHEET,
ID_POPUP_SCH_LEAVE_SHEET,
ID_POPUP_SCH_ADD_JUNCTION,
ID_POPUP_SCH_ADD_LABEL,
ID_POPUP_SCH_ADD_GLABEL,
ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_HLABEL,
ID_POPUP_SCH_GETINFO_MARKER,
ID_POPUP_END_RANGE,
// Schematic editor commmands. These are command IDs that are generated by multiple
// events (menus, toolbar, context menu, etc.) that result in the same event handler.
......
......@@ -10,12 +10,14 @@
#include "confirm.h"
#include "class_sch_screen.h"
#include "wxEeschemaStruct.h"
#include "kicad_device_context.h"
#include "general.h"
#include "protos.h"
#include "class_library.h"
#include "sch_component.h"
#include "viewlib_frame.h"
#include "eeschema_id.h"
#include "dialog_get_component.h"
......@@ -307,55 +309,77 @@ static void ExitPlaceCmp( EDA_DRAW_PANEL* Panel, wxDC* DC )
/*
* Handle select part in multi-part component.
*/
void SCH_EDIT_FRAME::SelPartUnit( SCH_COMPONENT* DrawComponent, int unit, wxDC* DC )
void SCH_EDIT_FRAME::OnSelectUnit( wxCommandEvent& aEvent )
{
int m_UnitCount;
LIB_COMPONENT* LibEntry;
SCH_SCREEN* screen = GetScreen();
if( DrawComponent == NULL )
if( screen->GetCurItem() == NULL )
return;
LibEntry = CMP_LIBRARY::FindLibraryComponent( DrawComponent->GetLibName() );
INSTALL_UNBUFFERED_DC( dc, DrawPanel );
if( LibEntry == NULL )
return;
// Verify the selected item is a component, it may be part of a component such as a field
// or text item.
if( screen->GetCurItem()->Type() != SCH_COMPONENT_T )
{
screen->SetCurItem( LocateSmallestComponent( screen ) );
if( screen->GetCurItem() == NULL )
return;
}
DrawPanel->MoveCursorToCrossHair();
SCH_COMPONENT* component = (SCH_COMPONENT*) screen->GetCurItem();
wxCHECK_RET( (component != NULL) && (component->Type() == SCH_COMPONENT_T),
wxT( "Cannot select unit for invalid component." ) );
m_UnitCount = LibEntry->GetPartCount();
int unit = aEvent.GetId() + 1 - ID_POPUP_SCH_SELECT_UNIT1;
if( m_UnitCount <= 1 )
LIB_COMPONENT* libEntry = CMP_LIBRARY::FindLibraryComponent( component->GetLibName() );
if( libEntry == NULL )
return;
if( DrawComponent->GetUnit() == unit )
wxCHECK_RET( (unit >= 1) && (unit <= libEntry->GetPartCount()),
wxString::Format( wxT( "Cannot select unit %d from component "), unit ) +
libEntry->GetName() );
int unitCount = libEntry->GetPartCount();
if( (unitCount <= 1) || (component->GetUnit() == unit) )
return;
if( unit < 1 )
unit = 1;
if( unit > m_UnitCount )
unit = m_UnitCount;
if( unit > unitCount )
unit = unitCount;
int curr_flg = DrawComponent->m_Flags;
if( ! curr_flg ) // No command in progress: save in undo list
SaveCopyInUndoList( DrawComponent, UR_CHANGED );
int flags = component->GetFlags();
if( curr_flg )
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
if( !flags ) // No command in progress: save in undo list
SaveCopyInUndoList( component, UR_CHANGED );
if( flags )
component->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
else
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode );
component->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), g_XorMode );
/* Update the unit number. */
DrawComponent->SetUnitSelection( GetSheet(), unit );
DrawComponent->SetUnit( unit );
DrawComponent->m_Flags = curr_flg; // Restore m_Flag modified by SetUnit();
component->SetUnitSelection( GetSheet(), unit );
component->SetUnit( unit );
component->SetFlags( flags ); // Restore m_Flag modified by SetUnit();
/* Redraw the component in the new position. */
if( DrawComponent->m_Flags )
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
if( flags )
component->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
else
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
component->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
GetScreen()->TestDanglingEnds( DrawPanel, DC );
OnModify( );
GetScreen()->TestDanglingEnds( DrawPanel, &dc );
OnModify();
}
......
......@@ -71,33 +71,6 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
case ID_POPUP_SCH_EDIT_REF_CMP:
case ID_POPUP_SCH_EDIT_FOOTPRINT_CMP:
case ID_POPUP_SCH_EDIT_CONVERT_CMP:
case ID_POPUP_SCH_SELECT_UNIT_CMP:
case ID_POPUP_SCH_SELECT_UNIT1:
case ID_POPUP_SCH_SELECT_UNIT2:
case ID_POPUP_SCH_SELECT_UNIT3:
case ID_POPUP_SCH_SELECT_UNIT4:
case ID_POPUP_SCH_SELECT_UNIT5:
case ID_POPUP_SCH_SELECT_UNIT6:
case ID_POPUP_SCH_SELECT_UNIT7:
case ID_POPUP_SCH_SELECT_UNIT8:
case ID_POPUP_SCH_SELECT_UNIT9:
case ID_POPUP_SCH_SELECT_UNIT10:
case ID_POPUP_SCH_SELECT_UNIT11:
case ID_POPUP_SCH_SELECT_UNIT12:
case ID_POPUP_SCH_SELECT_UNIT13:
case ID_POPUP_SCH_SELECT_UNIT14:
case ID_POPUP_SCH_SELECT_UNIT15:
case ID_POPUP_SCH_SELECT_UNIT16:
case ID_POPUP_SCH_SELECT_UNIT17:
case ID_POPUP_SCH_SELECT_UNIT18:
case ID_POPUP_SCH_SELECT_UNIT19:
case ID_POPUP_SCH_SELECT_UNIT20:
case ID_POPUP_SCH_SELECT_UNIT21:
case ID_POPUP_SCH_SELECT_UNIT22:
case ID_POPUP_SCH_SELECT_UNIT23:
case ID_POPUP_SCH_SELECT_UNIT24:
case ID_POPUP_SCH_SELECT_UNIT25:
case ID_POPUP_SCH_SELECT_UNIT26:
case ID_POPUP_SCH_ROTATE_FIELD:
case ID_POPUP_SCH_EDIT_FIELD:
case ID_POPUP_DELETE_BLOCK:
......@@ -362,8 +335,8 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
case ID_POPUP_SCH_DRAG_WIRE_REQUEST:
DrawPanel->MoveCursorToCrossHair();
// The easiest way to handle a drag component is to simulate a
// block drag command
// The easiest way to handle a drag component is to simulate a block drag command
if( screen->m_BlockLocate.m_State == STATE_NO_BLOCK )
{
if( !HandleBlockBegin( &dc, BLOCK_DRAG, screen->GetCrossHairPosition() ) )
......@@ -494,46 +467,6 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
ConvertPart( (SCH_COMPONENT*) screen->GetCurItem(), &dc );
break;
case ID_POPUP_SCH_SELECT_UNIT1:
case ID_POPUP_SCH_SELECT_UNIT2:
case ID_POPUP_SCH_SELECT_UNIT3:
case ID_POPUP_SCH_SELECT_UNIT4:
case ID_POPUP_SCH_SELECT_UNIT5:
case ID_POPUP_SCH_SELECT_UNIT6:
case ID_POPUP_SCH_SELECT_UNIT7:
case ID_POPUP_SCH_SELECT_UNIT8:
case ID_POPUP_SCH_SELECT_UNIT9:
case ID_POPUP_SCH_SELECT_UNIT10:
case ID_POPUP_SCH_SELECT_UNIT11:
case ID_POPUP_SCH_SELECT_UNIT12:
case ID_POPUP_SCH_SELECT_UNIT13:
case ID_POPUP_SCH_SELECT_UNIT14:
case ID_POPUP_SCH_SELECT_UNIT15:
case ID_POPUP_SCH_SELECT_UNIT16:
case ID_POPUP_SCH_SELECT_UNIT17:
case ID_POPUP_SCH_SELECT_UNIT18:
case ID_POPUP_SCH_SELECT_UNIT19:
case ID_POPUP_SCH_SELECT_UNIT20:
case ID_POPUP_SCH_SELECT_UNIT21:
case ID_POPUP_SCH_SELECT_UNIT22:
case ID_POPUP_SCH_SELECT_UNIT23:
case ID_POPUP_SCH_SELECT_UNIT24:
case ID_POPUP_SCH_SELECT_UNIT25:
case ID_POPUP_SCH_SELECT_UNIT26:
// Ensure the struct is a component (could be a struct of a
// component, like Field, text..)
if( screen->GetCurItem()->Type() != SCH_COMPONENT_T )
screen->SetCurItem( LocateSmallestComponent( screen ) );
if( screen->GetCurItem() == NULL )
break;
DrawPanel->MoveCursorToCrossHair();
SelPartUnit( (SCH_COMPONENT*) screen->GetCurItem(),
id + 1 - ID_POPUP_SCH_SELECT_UNIT1, &dc );
break;
case ID_POPUP_SCH_DISPLAYDOC_CMP:
// Ensure the struct is a component (could be a piece of a
......@@ -541,8 +474,7 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
if( screen->GetCurItem()->Type() != SCH_COMPONENT_T )
screen->SetCurItem( LocateSmallestComponent( screen ) );
if( screen->GetCurItem() == NULL )
break;
if( screen->GetCurItem() )
{
LIB_ALIAS* LibEntry;
LibEntry = CMP_LIBRARY::FindLibraryEntry(
......
......@@ -119,6 +119,9 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME )
EVT_MENU_RANGE( ID_POPUP_GENERAL_START_RANGE, ID_POPUP_GENERAL_END_RANGE,
SCH_EDIT_FRAME::Process_Special_Functions )
EVT_MENU_RANGE( ID_POPUP_SCH_SELECT_UNIT1, ID_POPUP_SCH_SELECT_UNIT26,
SCH_EDIT_FRAME::OnSelectUnit )
/* Handle user interface update events. */
EVT_UPDATE_UI( wxID_CUT, SCH_EDIT_FRAME::OnUpdateBlockSelected )
EVT_UPDATE_UI( wxID_COPY, SCH_EDIT_FRAME::OnUpdateBlockSelected )
......
......@@ -520,8 +520,7 @@ public:
wxDC* DC, int type_rotate );
private:
void SelPartUnit( SCH_COMPONENT* DrawComponent,
int unit, wxDC* DC );
void OnSelectUnit( wxCommandEvent& aEvent );
void ConvertPart( SCH_COMPONENT* DrawComponent, wxDC* DC );
void SetInitCmp( SCH_COMPONENT* DrawComponent, wxDC* DC );
void EditComponentReference( SCH_COMPONENT* DrawLibItem,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment