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.

215 lines
5.7 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2006 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 2010 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 1992-2011 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 <general.h>
  33. #include <libeditframe.h>
  34. #include <class_libentry.h>
  35. void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition )
  36. {
  37. LIB_ITEM* item = m_drawItem;
  38. bool no_item_edited = item == NULL || item->GetFlags() == 0;
  39. if( m_component == NULL ) // No component loaded !
  40. return;
  41. if( ( GetToolId() == ID_NO_TOOL_SELECTED ) && no_item_edited )
  42. {
  43. item = LocateItemUsingCursor( aPosition );
  44. if( item )
  45. item->DisplayInfo( this );
  46. else
  47. {
  48. DisplayCmpDoc();
  49. if( m_canvas->GetAbortRequest() )
  50. m_canvas->SetAbortRequest( false );
  51. }
  52. }
  53. switch( GetToolId() )
  54. {
  55. case ID_NO_TOOL_SELECTED:
  56. if( item && item->GetFlags() ) // moved object
  57. {
  58. switch( item->Type() )
  59. {
  60. case LIB_PIN_T:
  61. PlacePin( DC );
  62. break;
  63. default:
  64. EndDrawGraphicItem( DC );
  65. break;
  66. }
  67. }
  68. break;
  69. case ID_LIBEDIT_PIN_BUTT:
  70. if( no_item_edited )
  71. {
  72. CreatePin( DC );
  73. }
  74. else
  75. {
  76. PlacePin( DC );
  77. }
  78. break;
  79. case ID_LIBEDIT_BODY_LINE_BUTT:
  80. case ID_LIBEDIT_BODY_ARC_BUTT:
  81. case ID_LIBEDIT_BODY_CIRCLE_BUTT:
  82. case ID_LIBEDIT_BODY_RECT_BUTT:
  83. case ID_LIBEDIT_BODY_TEXT_BUTT:
  84. if( no_item_edited )
  85. {
  86. m_drawItem = CreateGraphicItem( m_component, DC );
  87. }
  88. else if( m_drawItem )
  89. {
  90. if( m_drawItem->IsNew() )
  91. GraphicItemBeginDraw( DC );
  92. else
  93. EndDrawGraphicItem( DC );
  94. }
  95. break;
  96. case ID_LIBEDIT_DELETE_ITEM_BUTT:
  97. m_drawItem = LocateItemUsingCursor( aPosition );
  98. if( m_drawItem )
  99. deleteItem( DC );
  100. else
  101. DisplayCmpDoc();
  102. break;
  103. case ID_LIBEDIT_ANCHOR_ITEM_BUTT:
  104. SaveCopyInUndoList( m_component );
  105. PlaceAnchor();
  106. SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
  107. break;
  108. default:
  109. wxFAIL_MSG( wxString::Format( wxT( "Unhandled command ID %d" ), GetToolId() ) );
  110. SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
  111. break;
  112. }
  113. }
  114. /*
  115. * Called on a double click:
  116. * If an editable item (field, pin, graphic):
  117. * Call the suitable dialog editor.
  118. */
  119. void LIB_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition )
  120. {
  121. if( m_component == NULL )
  122. return;
  123. if( ( m_drawItem == NULL ) || ( m_drawItem->GetFlags() == 0 ) )
  124. { // We can locate an item
  125. m_drawItem = LocateItemUsingCursor( aPosition );
  126. if( m_drawItem == NULL )
  127. {
  128. wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
  129. cmd.SetId( ID_LIBEDIT_GET_FRAME_EDIT_PART );
  130. GetEventHandler()->ProcessEvent( cmd );
  131. }
  132. }
  133. if( m_drawItem )
  134. m_drawItem->DisplayInfo( this );
  135. else
  136. return;
  137. m_canvas->SetIgnoreMouseEvents( true );
  138. switch( m_drawItem->Type() )
  139. {
  140. case LIB_PIN_T:
  141. if( m_drawItem->GetFlags() == 0 )
  142. {
  143. wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
  144. cmd.SetId( ID_LIBEDIT_EDIT_PIN );
  145. GetEventHandler()->ProcessEvent( cmd );
  146. }
  147. break;
  148. case LIB_ARC_T:
  149. case LIB_CIRCLE_T:
  150. case LIB_RECTANGLE_T:
  151. if( m_drawItem->GetFlags() == 0 )
  152. {
  153. EditGraphicSymbol( DC, m_drawItem );
  154. }
  155. break;
  156. case LIB_POLYLINE_T:
  157. if( m_drawItem->GetFlags() == 0 )
  158. {
  159. EditGraphicSymbol( DC, m_drawItem );
  160. }
  161. else if( m_drawItem->IsNew() )
  162. {
  163. EndDrawGraphicItem( DC );
  164. }
  165. break;
  166. case LIB_TEXT_T:
  167. if( m_drawItem->GetFlags() == 0 )
  168. {
  169. EditSymbolText( DC, m_drawItem );
  170. }
  171. break;
  172. case LIB_FIELD_T:
  173. if( m_drawItem->GetFlags() == 0 )
  174. {
  175. EditField( (LIB_FIELD*) m_drawItem );
  176. }
  177. break;
  178. default:
  179. wxFAIL_MSG( wxT( "Unhandled item <" ) + m_drawItem->GetClass() + wxT( ">" ) );
  180. break;
  181. }
  182. m_canvas->MoveCursorToCrossHair();
  183. m_canvas->SetIgnoreMouseEvents( false );
  184. }