Commit 66566f9b authored by Wayne Stambaugh's avatar Wayne Stambaugh

EESchema command handling and other minor improvements.

* Schematic editor cancel current tool command now use a single command
  ID that is used everywhere the event is generated.
* Moved cancel current tool code from Process_Special_Functions to a
  separate event handler.
* Add idle check method to block select object.
* Add block active check to base screen object.
parent da106200
...@@ -160,6 +160,16 @@ void BLOCK_SELECTOR::PushItem( ITEM_PICKER& aItem ) ...@@ -160,6 +160,16 @@ void BLOCK_SELECTOR::PushItem( ITEM_PICKER& aItem )
} }
void BLOCK_SELECTOR::Clear()
{
if( m_Command != BLOCK_IDLE )
{
m_Command = BLOCK_IDLE;
m_State = STATE_NO_BLOCK;
ClearItemsList();
}
}
/* First command block function: /* First command block function:
* Init the Block infos: command type, initial position, and other variables.. * Init the Block infos: command type, initial position, and other variables..
...@@ -201,6 +211,7 @@ bool EDA_DRAW_FRAME::HandleBlockBegin( wxDC* DC, int key, const wxPoint& startpo ...@@ -201,6 +211,7 @@ bool EDA_DRAW_FRAME::HandleBlockBegin( wxDC* DC, int key, const wxPoint& startpo
Block->m_BlockLastCursorPosition.x = 0; Block->m_BlockLastCursorPosition.x = 0;
Block->m_BlockLastCursorPosition.y = 0; Block->m_BlockLastCursorPosition.y = 0;
InitBlockPasteInfos(); InitBlockPasteInfos();
if( Block->m_ItemsSelection.GetCount() == 0 ) /* No data to paste */ if( Block->m_ItemsSelection.GetCount() == 0 ) /* No data to paste */
{ {
DisplayError( this, wxT( "No Block to paste" ), 20 ); DisplayError( this, wxT( "No Block to paste" ), 20 );
...@@ -208,6 +219,7 @@ bool EDA_DRAW_FRAME::HandleBlockBegin( wxDC* DC, int key, const wxPoint& startpo ...@@ -208,6 +219,7 @@ bool EDA_DRAW_FRAME::HandleBlockBegin( wxDC* DC, int key, const wxPoint& startpo
DrawPanel->ManageCurseur = NULL; DrawPanel->ManageCurseur = NULL;
return true; return true;
} }
if( DrawPanel->ManageCurseur == NULL ) if( DrawPanel->ManageCurseur == NULL )
{ {
Block->m_ItemsSelection.ClearItemsList(); Block->m_ItemsSelection.ClearItemsList();
...@@ -215,6 +227,7 @@ bool EDA_DRAW_FRAME::HandleBlockBegin( wxDC* DC, int key, const wxPoint& startpo ...@@ -215,6 +227,7 @@ bool EDA_DRAW_FRAME::HandleBlockBegin( wxDC* DC, int key, const wxPoint& startpo
wxT( "EDA_DRAW_FRAME::HandleBlockBegin() Err: ManageCurseur NULL" ) ); wxT( "EDA_DRAW_FRAME::HandleBlockBegin() Err: ManageCurseur NULL" ) );
return true; return true;
} }
Block->m_State = STATE_BLOCK_MOVE; Block->m_State = STATE_BLOCK_MOVE;
DrawPanel->ManageCurseur( DrawPanel, DC, startpos, false ); DrawPanel->ManageCurseur( DrawPanel, DC, startpos, false );
break; break;
......
...@@ -30,11 +30,11 @@ void EDA_DRAW_FRAME::CopyToClipboard( wxCommandEvent& event ) ...@@ -30,11 +30,11 @@ void EDA_DRAW_FRAME::CopyToClipboard( wxCommandEvent& event )
if( event.GetId() == ID_GEN_COPY_BLOCK_TO_CLIPBOARD ) if( event.GetId() == ID_GEN_COPY_BLOCK_TO_CLIPBOARD )
{ {
if( GetScreen()->m_BlockLocate.m_Command != BLOCK_IDLE ) if( GetScreen()->IsBlockActive() )
DrawPanel->SetCursor( wxCursor( DrawPanel->m_PanelCursor = DrawPanel->SetCursor( wxCursor( DrawPanel->m_PanelCursor =
DrawPanel->m_PanelDefaultCursor ) ); DrawPanel->m_PanelDefaultCursor ) );
DrawPanel->UnManageCursor( ); DrawPanel->UnManageCursor();
} }
} }
...@@ -60,7 +60,7 @@ bool DrawPage( EDA_DRAW_FRAME* aFrame ) ...@@ -60,7 +60,7 @@ bool DrawPage( EDA_DRAW_FRAME* aFrame )
/* scale is the ratio resolution/internal units */ /* scale is the ratio resolution/internal units */
float scale = 82.0 / aFrame->m_InternalUnits; float scale = 82.0 / aFrame->m_InternalUnits;
if( screen->m_BlockLocate.m_Command != BLOCK_IDLE ) if( screen->IsBlockActive() )
{ {
DrawBlock = TRUE; DrawBlock = TRUE;
DrawArea.SetX( screen->m_BlockLocate.GetX() ); DrawArea.SetX( screen->m_BlockLocate.GetX() );
......
...@@ -1043,8 +1043,7 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event ) ...@@ -1043,8 +1043,7 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
if( m_Block_Enable && !(localbutt & GR_M_DCLICK) ) if( m_Block_Enable && !(localbutt & GR_M_DCLICK) )
{ {
if( ( screen->m_BlockLocate.m_Command == BLOCK_IDLE ) if( !screen->IsBlockActive() )
|| ( screen->m_BlockLocate.m_State == STATE_NO_BLOCK ) )
{ {
screen->m_BlockLocate.SetOrigin( m_CursorStartPos ); screen->m_BlockLocate.SetOrigin( m_CursorStartPos );
} }
...@@ -1138,7 +1137,7 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event ) ...@@ -1138,7 +1137,7 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
// To avoid an unwanted block move command if the mouse is moved while double clicking // To avoid an unwanted block move command if the mouse is moved while double clicking
if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) ) if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) )
{ {
if( screen->m_BlockLocate.m_Command != BLOCK_IDLE ) if( !screen->IsBlockActive() )
{ {
if( ForceCloseManageCurseur ) if( ForceCloseManageCurseur )
{ {
......
...@@ -127,6 +127,10 @@ enum id_eeschema_frm ...@@ -127,6 +127,10 @@ enum id_eeschema_frm
ID_POPUP_SCH_GETINFO_MARKER, ID_POPUP_SCH_GETINFO_MARKER,
ID_POPUP_END_RANGE, 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.
ID_CANCEL_CURRENT_COMMAND,
/* Library editor main menubar IDs. */ /* Library editor main menubar IDs. */
ID_LIBEDIT_DIMENSIONS, ID_LIBEDIT_DIMENSIONS,
......
...@@ -31,7 +31,7 @@ static void AddMenusForPin( wxMenu* PopMenu, LIB_PIN* Pin, LIB_EDIT_FRAME* frame ...@@ -31,7 +31,7 @@ static void AddMenusForPin( wxMenu* PopMenu, LIB_PIN* Pin, LIB_EDIT_FRAME* frame
bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ) bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
{ {
LIB_DRAW_ITEM* DrawEntry = LocateItemUsingCursor(); LIB_DRAW_ITEM* DrawEntry = LocateItemUsingCursor();
bool BlockActive = (GetScreen()->m_BlockLocate.m_Command != BLOCK_IDLE ); bool BlockActive = GetScreen()->IsBlockActive();
if( m_component == NULL ) if( m_component == NULL )
return true; return true;
......
...@@ -51,7 +51,7 @@ static void AddMenusForMarkers( wxMenu* aPopMenu, SCH_MARKER* aMarker, SCH_EDIT_ ...@@ -51,7 +51,7 @@ static void AddMenusForMarkers( wxMenu* aPopMenu, SCH_MARKER* aMarker, SCH_EDIT_
bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
{ {
SCH_ITEM* DrawStruct = (SCH_ITEM*) GetScreen()->GetCurItem(); SCH_ITEM* DrawStruct = (SCH_ITEM*) GetScreen()->GetCurItem();
bool BlockActive = (GetScreen()->m_BlockLocate.m_Command != BLOCK_IDLE); bool BlockActive = GetScreen()->IsBlockActive();
// Do not start a block command on context menu. // Do not start a block command on context menu.
DrawPanel->m_CanStartBlock = -1; DrawPanel->m_CanStartBlock = -1;
...@@ -83,11 +83,11 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) ...@@ -83,11 +83,11 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
{ {
if( DrawStruct && DrawStruct->m_Flags ) if( DrawStruct && DrawStruct->m_Flags )
{ {
ADD_MENUITEM( PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND, _( "Cancel" ), cancel_xpm ); ADD_MENUITEM( PopMenu, ID_CANCEL_CURRENT_COMMAND, _( "Cancel" ), cancel_xpm );
} }
else else
{ {
ADD_MENUITEM( PopMenu, ID_POPUP_CLOSE_CURRENT_TOOL, _( "End Tool" ), cancel_tool_xpm ); ADD_MENUITEM( PopMenu, ID_CANCEL_CURRENT_COMMAND, _( "End Tool" ), cancel_tool_xpm );
} }
PopMenu->AppendSeparator(); PopMenu->AppendSeparator();
} }
...@@ -95,7 +95,7 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) ...@@ -95,7 +95,7 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
{ {
if( DrawStruct && DrawStruct->m_Flags ) if( DrawStruct && DrawStruct->m_Flags )
{ {
ADD_MENUITEM( PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND, _( "Cancel" ), cancel_xpm ); ADD_MENUITEM( PopMenu, ID_CANCEL_CURRENT_COMMAND, _( "Cancel" ), cancel_xpm );
PopMenu->AppendSeparator(); PopMenu->AppendSeparator();
} }
} }
......
...@@ -124,23 +124,6 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -124,23 +124,6 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
*/ */
break; break;
case ID_POPUP_CANCEL_CURRENT_COMMAND:
if( screen->m_BlockLocate.m_Command != BLOCK_IDLE )
DrawPanel->SetCursor( wxCursor( DrawPanel->m_PanelCursor =
DrawPanel->m_PanelDefaultCursor ) );
// Stop the current command (if any) but keep the current tool
DrawPanel->UnManageCursor();
/* Should not be executed, except bug. */
if( screen->m_BlockLocate.m_Command != BLOCK_IDLE )
{
screen->m_BlockLocate.m_Command = BLOCK_IDLE;
screen->m_BlockLocate.m_State = STATE_NO_BLOCK;
screen->m_BlockLocate.ClearItemsList();
}
break;
case ID_POPUP_SCH_DELETE_CMP: case ID_POPUP_SCH_DELETE_CMP:
case ID_POPUP_SCH_DELETE: case ID_POPUP_SCH_DELETE:
...@@ -255,10 +238,6 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -255,10 +238,6 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
SetBusEntryShape( &dc, (SCH_BUS_ENTRY*) screen->GetCurItem(), '\\' ); SetBusEntryShape( &dc, (SCH_BUS_ENTRY*) screen->GetCurItem(), '\\' );
break; break;
case ID_NO_SELECT_BUTT:
SetToolID( 0, wxCURSOR_ARROW, wxEmptyString );
break;
case ID_POPUP_CANCEL_CURRENT_COMMAND: case ID_POPUP_CANCEL_CURRENT_COMMAND:
if( m_ID_current_state == 0 ) if( m_ID_current_state == 0 )
SetToolID( 0, wxCURSOR_ARROW, wxEmptyString ); SetToolID( 0, wxCURSOR_ARROW, wxEmptyString );
...@@ -807,3 +786,24 @@ void SCH_EDIT_FRAME::Process_Move_Item( SCH_ITEM* DrawStruct, wxDC* DC ) ...@@ -807,3 +786,24 @@ void SCH_EDIT_FRAME::Process_Move_Item( SCH_ITEM* DrawStruct, wxDC* DC )
break; break;
} }
} }
void SCH_EDIT_FRAME::OnCancelCurrentCommand( wxCommandEvent& aEvent )
{
SCH_SCREEN* screen = GetScreen();
if( screen->IsBlockActive() )
{
DrawPanel->SetCursor( wxCursor( DrawPanel->m_PanelCursor =
DrawPanel->m_PanelDefaultCursor ) );
screen->ClearBlockCommand();
// Stop the current command (if any) but keep the current tool
DrawPanel->UnManageCursor();
}
else
{
// Stop the current command (if any) but keep the current tool
DrawPanel->UnManageCursor( 0, wxCURSOR_ARROW );
}
}
...@@ -108,11 +108,12 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME ) ...@@ -108,11 +108,12 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME )
EVT_MENU( ID_KICAD_ABOUT, EDA_DRAW_FRAME::GetKicadAbout ) EVT_MENU( ID_KICAD_ABOUT, EDA_DRAW_FRAME::GetKicadAbout )
// Tools and buttons for vertical toolbar. // Tools and buttons for vertical toolbar.
EVT_TOOL( ID_NO_SELECT_BUTT, SCH_EDIT_FRAME::Process_Special_Functions ) EVT_TOOL( ID_CANCEL_CURRENT_COMMAND, SCH_EDIT_FRAME::OnCancelCurrentCommand )
EVT_TOOL_RANGE( ID_SCHEMATIC_VERTICAL_TOOLBAR_START, EVT_TOOL_RANGE( ID_SCHEMATIC_VERTICAL_TOOLBAR_START,
ID_SCHEMATIC_VERTICAL_TOOLBAR_END, ID_SCHEMATIC_VERTICAL_TOOLBAR_END,
SCH_EDIT_FRAME::Process_Special_Functions ) SCH_EDIT_FRAME::Process_Special_Functions )
EVT_MENU( ID_CANCEL_CURRENT_COMMAND, SCH_EDIT_FRAME::OnCancelCurrentCommand )
EVT_MENU_RANGE( ID_POPUP_START_RANGE, ID_POPUP_END_RANGE, EVT_MENU_RANGE( ID_POPUP_START_RANGE, ID_POPUP_END_RANGE,
SCH_EDIT_FRAME::Process_Special_Functions ) SCH_EDIT_FRAME::Process_Special_Functions )
......
...@@ -148,9 +148,8 @@ void SCH_EDIT_FRAME::ReCreateVToolbar() ...@@ -148,9 +148,8 @@ void SCH_EDIT_FRAME::ReCreateVToolbar()
m_VToolBar = new WinEDA_Toolbar( TOOLBAR_TOOL, this, ID_V_TOOLBAR, FALSE ); m_VToolBar = new WinEDA_Toolbar( TOOLBAR_TOOL, this, ID_V_TOOLBAR, FALSE );
// Set up toolbar // Set up toolbar
m_VToolBar->AddTool( ID_NO_SELECT_BUTT, wxEmptyString, m_VToolBar->AddTool( ID_CANCEL_CURRENT_COMMAND, wxEmptyString,
wxBitmap( cursor_xpm ), wxEmptyString, wxITEM_CHECK ); wxBitmap( cursor_xpm ), wxEmptyString, wxITEM_CHECK );
m_VToolBar->ToggleTool( ID_NO_SELECT_BUTT, TRUE );
m_VToolBar->AddTool( ID_HIERARCHY_PUSH_POP_BUTT, wxEmptyString, m_VToolBar->AddTool( ID_HIERARCHY_PUSH_POP_BUTT, wxEmptyString,
wxBitmap( hierarchy_cursor_xpm ), wxBitmap( hierarchy_cursor_xpm ),
......
...@@ -130,6 +130,19 @@ public: ...@@ -130,6 +130,19 @@ public:
* returns true if the current block command is a drag operation. * returns true if the current block command is a drag operation.
*/ */
bool IsDragging() const { return m_Command == BLOCK_DRAG; } bool IsDragging() const { return m_Command == BLOCK_DRAG; }
/**
* Function IsIdle
* returns true if there is currently no block operation in progress.
*/
inline bool IsIdle() const { return m_Command == BLOCK_IDLE; }
/**
* Function Clear
* clears the block selector by setting the command to idle, the state to no block,
* and clears the selected item list.
*/
void Clear();
}; };
......
...@@ -393,6 +393,14 @@ public: ...@@ -393,6 +393,14 @@ public:
virtual void AddItem( EDA_ITEM* aItem ); virtual void AddItem( EDA_ITEM* aItem );
virtual void InsertItem( EDA_ITEMS::iterator aIter, EDA_ITEM* aItem ); virtual void InsertItem( EDA_ITEMS::iterator aIter, EDA_ITEM* aItem );
/**
* Function IsBlockActive
* returns true if a block command is in progress.
*/
inline bool IsBlockActive() const { return !m_BlockLocate.IsIdle(); }
void ClearBlockCommand() { m_BlockLocate.Clear(); }
#if defined(DEBUG) #if defined(DEBUG)
/** /**
......
...@@ -418,6 +418,7 @@ private: ...@@ -418,6 +418,7 @@ private:
void OnOpenLibraryViewer( wxCommandEvent& event ); void OnOpenLibraryViewer( wxCommandEvent& event );
void OnOpenLibraryEditor( wxCommandEvent& event ); void OnOpenLibraryEditor( wxCommandEvent& event );
void OnSetOptions( wxCommandEvent& event ); void OnSetOptions( wxCommandEvent& event );
void OnCancelCurrentCommand( wxCommandEvent& aEvent );
/* edition events functions */ /* edition events functions */
void OnCopySchematicItemRequest( wxCommandEvent& event ); void OnCopySchematicItemRequest( wxCommandEvent& event );
......
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