You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

214 lines
5.7 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file libedit_onleftclick.cpp
  27. * @brief Eeschema library editor event handler for a mouse left button single or double click.
  28. */
  29. #include <fctsys.h>
  30. #include <class_drawpanel.h>
  31. #include <eeschema_id.h>
  32. #include <msgpanel.h>
  33. #include <general.h>
  34. #include <libeditframe.h>
  35. #include <class_libentry.h>
  36. void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition )
  37. {
  38. LIB_ITEM* item = m_drawItem;
  39. bool item_in_edit = item && item->InEditMode();
  40. bool no_item_edited = !item_in_edit;
  41. LIB_PART* part = GetCurPart();
  42. if( !part ) // No component loaded !
  43. return;
  44. if( ( GetToolId() == ID_NO_TOOL_SELECTED ) && no_item_edited )
  45. {
  46. item = LocateItemUsingCursor( aPosition );
  47. if( item )
  48. {
  49. MSG_PANEL_ITEMS items;
  50. item->GetMsgPanelInfo( items );
  51. SetMsgPanel( items );
  52. }
  53. else
  54. {
  55. DisplayCmpDoc();
  56. if( m_canvas->GetAbortRequest() )
  57. m_canvas->SetAbortRequest( false );
  58. }
  59. }
  60. switch( GetToolId() )
  61. {
  62. case ID_NO_TOOL_SELECTED:
  63. // If an item is currently in edit, finish edit
  64. if( item_in_edit )
  65. {
  66. switch( item->Type() )
  67. {
  68. case LIB_PIN_T:
  69. PlacePin();
  70. break;
  71. default:
  72. EndDrawGraphicItem( DC );
  73. break;
  74. }
  75. }
  76. break;
  77. case ID_LIBEDIT_PIN_BUTT:
  78. if( no_item_edited )
  79. CreatePin( DC );
  80. else
  81. PlacePin();
  82. break;
  83. case ID_LIBEDIT_BODY_LINE_BUTT:
  84. case ID_LIBEDIT_BODY_ARC_BUTT:
  85. case ID_LIBEDIT_BODY_CIRCLE_BUTT:
  86. case ID_LIBEDIT_BODY_RECT_BUTT:
  87. case ID_LIBEDIT_BODY_TEXT_BUTT:
  88. if( no_item_edited )
  89. m_drawItem = CreateGraphicItem( part, DC );
  90. else if( m_drawItem )
  91. {
  92. if( m_drawItem->IsNew() )
  93. GraphicItemBeginDraw( DC );
  94. else
  95. EndDrawGraphicItem( DC );
  96. }
  97. break;
  98. case ID_LIBEDIT_DELETE_ITEM_BUTT:
  99. m_drawItem = LocateItemUsingCursor( aPosition );
  100. if( m_drawItem )
  101. deleteItem( DC );
  102. else
  103. DisplayCmpDoc();
  104. break;
  105. case ID_LIBEDIT_ANCHOR_ITEM_BUTT:
  106. SaveCopyInUndoList( part );
  107. PlaceAnchor();
  108. SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
  109. break;
  110. default:
  111. wxFAIL_MSG( wxString::Format( wxT( "Unhandled command ID %d" ), GetToolId() ) );
  112. SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
  113. break;
  114. }
  115. }
  116. /*
  117. * Called on a double click:
  118. * If an editable item (field, pin, graphic):
  119. * Call the suitable dialog editor.
  120. */
  121. void LIB_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition )
  122. {
  123. LIB_PART* part = GetCurPart();
  124. if( !part )
  125. return;
  126. if( !m_drawItem || !m_drawItem->InEditMode() )
  127. { // We can locate an item
  128. m_drawItem = LocateItemUsingCursor( aPosition );
  129. if( m_drawItem == NULL )
  130. {
  131. wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
  132. cmd.SetId( ID_LIBEDIT_GET_FRAME_EDIT_PART );
  133. GetEventHandler()->ProcessEvent( cmd );
  134. }
  135. }
  136. if( m_drawItem )
  137. SetMsgPanel( m_drawItem );
  138. else
  139. return;
  140. m_canvas->SetIgnoreMouseEvents( true );
  141. bool not_edited = !m_drawItem->InEditMode();
  142. switch( m_drawItem->Type() )
  143. {
  144. case LIB_PIN_T:
  145. if( not_edited )
  146. {
  147. wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
  148. cmd.SetId( ID_LIBEDIT_EDIT_PIN );
  149. GetEventHandler()->ProcessEvent( cmd );
  150. }
  151. break;
  152. case LIB_ARC_T:
  153. case LIB_CIRCLE_T:
  154. case LIB_RECTANGLE_T:
  155. if( not_edited )
  156. EditGraphicSymbol( DC, m_drawItem );
  157. break;
  158. case LIB_POLYLINE_T:
  159. if( not_edited )
  160. EditGraphicSymbol( DC, m_drawItem );
  161. else if( m_drawItem->IsNew() )
  162. EndDrawGraphicItem( DC );
  163. break;
  164. case LIB_TEXT_T:
  165. if( not_edited )
  166. EditSymbolText( DC, m_drawItem );
  167. break;
  168. case LIB_FIELD_T:
  169. if( not_edited )
  170. EditField( (LIB_FIELD*) m_drawItem );
  171. break;
  172. default:
  173. wxFAIL_MSG( wxT( "Unhandled item <" ) + m_drawItem->GetClass() + wxT( ">" ) );
  174. break;
  175. }
  176. m_canvas->MoveCursorToCrossHair();
  177. m_canvas->SetIgnoreMouseEvents( false );
  178. }