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.

224 lines
5.8 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_ZOOM_SELECTION:
  63. break;
  64. case ID_NO_TOOL_SELECTED:
  65. // If an item is currently in edit, finish edit
  66. if( item_in_edit )
  67. {
  68. switch( item->Type() )
  69. {
  70. case LIB_PIN_T:
  71. PlacePin();
  72. break;
  73. default:
  74. EndDrawGraphicItem( DC );
  75. break;
  76. }
  77. }
  78. break;
  79. case ID_LIBEDIT_PIN_BUTT:
  80. if( no_item_edited )
  81. CreatePin( DC );
  82. else
  83. PlacePin();
  84. break;
  85. case ID_LIBEDIT_BODY_LINE_BUTT:
  86. case ID_LIBEDIT_BODY_ARC_BUTT:
  87. case ID_LIBEDIT_BODY_CIRCLE_BUTT:
  88. case ID_LIBEDIT_BODY_RECT_BUTT:
  89. case ID_LIBEDIT_BODY_TEXT_BUTT:
  90. if( no_item_edited )
  91. m_drawItem = CreateGraphicItem( part, DC );
  92. else if( m_drawItem )
  93. {
  94. if( m_drawItem->IsNew() )
  95. GraphicItemBeginDraw( DC );
  96. else
  97. EndDrawGraphicItem( DC );
  98. }
  99. break;
  100. case ID_LIBEDIT_DELETE_ITEM_BUTT:
  101. m_drawItem = LocateItemUsingCursor( aPosition );
  102. if( m_drawItem )
  103. deleteItem( DC );
  104. else
  105. {
  106. DisplayCmpDoc();
  107. if( m_canvas->GetAbortRequest() )
  108. m_canvas->SetAbortRequest( false );
  109. }
  110. break;
  111. case ID_LIBEDIT_ANCHOR_ITEM_BUTT:
  112. SaveCopyInUndoList( part );
  113. PlaceAnchor();
  114. SetNoToolSelected();
  115. break;
  116. default:
  117. wxFAIL_MSG( wxString::Format( wxT( "Unhandled command ID %d" ), GetToolId() ) );
  118. SetNoToolSelected();
  119. break;
  120. }
  121. }
  122. /*
  123. * Called on a double click:
  124. * If an editable item (field, pin, graphic):
  125. * Call the suitable dialog editor.
  126. */
  127. void LIB_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition )
  128. {
  129. LIB_PART* part = GetCurPart();
  130. if( !part )
  131. return;
  132. if( !m_drawItem || !m_drawItem->InEditMode() )
  133. { // We can locate an item
  134. m_drawItem = LocateItemUsingCursor( aPosition, LIB_COLLECTOR::DoubleClickItems );
  135. if( m_drawItem == NULL )
  136. {
  137. if( m_canvas->GetAbortRequest() )
  138. m_canvas->SetAbortRequest( false );
  139. wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
  140. cmd.SetId( ID_LIBEDIT_GET_FRAME_EDIT_PART );
  141. GetEventHandler()->ProcessEvent( cmd );
  142. }
  143. }
  144. if( m_drawItem )
  145. SetMsgPanel( m_drawItem );
  146. else
  147. return;
  148. m_canvas->SetIgnoreMouseEvents( true );
  149. bool not_edited = !m_drawItem->InEditMode();
  150. switch( m_drawItem->Type() )
  151. {
  152. case LIB_PIN_T:
  153. if( not_edited )
  154. {
  155. wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
  156. cmd.SetId( ID_LIBEDIT_EDIT_PIN );
  157. GetEventHandler()->ProcessEvent( cmd );
  158. }
  159. break;
  160. case LIB_ARC_T:
  161. case LIB_CIRCLE_T:
  162. case LIB_RECTANGLE_T:
  163. if( not_edited )
  164. EditGraphicSymbol( DC, m_drawItem );
  165. break;
  166. case LIB_POLYLINE_T:
  167. if( not_edited )
  168. EditGraphicSymbol( DC, m_drawItem );
  169. else if( m_drawItem->IsNew() )
  170. EndDrawGraphicItem( DC );
  171. break;
  172. case LIB_TEXT_T:
  173. if( not_edited )
  174. EditSymbolText( DC, m_drawItem );
  175. break;
  176. case LIB_FIELD_T:
  177. if( not_edited )
  178. EditField( (LIB_FIELD*) m_drawItem );
  179. break;
  180. default:
  181. wxFAIL_MSG( wxT( "Unhandled item <" ) + m_drawItem->GetClass() + wxT( ">" ) );
  182. break;
  183. }
  184. m_canvas->MoveCursorToCrossHair();
  185. m_canvas->SetIgnoreMouseEvents( false );
  186. }