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.

278 lines
8.2 KiB

9 years ago
9 years ago
9 years ago
9 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 1992-2019 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. #include <fctsys.h>
  26. #include <kiway.h>
  27. #include <eeschema_id.h>
  28. #include <sch_draw_panel.h>
  29. #include <sch_edit_frame.h>
  30. #include <sim/sim_plot_frame.h>
  31. #include <menus_helpers.h>
  32. #include <sch_component.h>
  33. #include <sch_sheet.h>
  34. #include <sch_sheet_path.h>
  35. #include <netlist_object.h>
  36. #include <sch_view.h>
  37. void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
  38. {
  39. switch( GetToolId() )
  40. {
  41. case ID_HIGHLIGHT_BUTT:
  42. case ID_WIRE_BUTT:
  43. case ID_BUS_BUTT:
  44. case ID_NOCONN_BUTT:
  45. case ID_JUNCTION_BUTT:
  46. case ID_WIRETOBUS_ENTRY_BUTT:
  47. case ID_BUSTOBUS_ENTRY_BUTT:
  48. case ID_SCH_PLACE_COMPONENT:
  49. case ID_PLACE_POWER_BUTT:
  50. case ID_LABEL_BUTT:
  51. case ID_GLOBALLABEL_BUTT:
  52. case ID_HIERLABEL_BUTT:
  53. case ID_TEXT_COMMENT_BUTT:
  54. case ID_LINE_COMMENT_BUTT:
  55. case ID_ADD_IMAGE_BUTT:
  56. case ID_ZOOM_SELECTION:
  57. return; // Moved to modern toolset
  58. default:
  59. break;
  60. }
  61. SCH_ITEM* item = GetScreen()->GetCurItem();
  62. // item_flags != 0 means a current item in edit, or new ...
  63. int item_flags = item ? (item->GetFlags() & ~HIGHLIGHTED) : 0;
  64. if( ( GetToolId() == ID_NO_TOOL_SELECTED ) || item_flags )
  65. {
  66. m_canvas->SetAutoPanRequest( false );
  67. SetRepeatItem( NULL );
  68. if( item_flags )
  69. {
  70. switch( item->Type() )
  71. {
  72. case SCH_SHEET_PIN_T:
  73. case SCH_SHEET_T:
  74. case SCH_FIELD_T:
  75. AddItemToScreen( item );
  76. GetCanvas()->GetView()->ClearPreview();
  77. GetCanvas()->GetView()->ClearHiddenFlags();
  78. return;
  79. default:
  80. wxFAIL_MSG( wxT( "SCH_EDIT_FRAME::OnLeftClick error. Item type <" ) +
  81. item->GetClass() + wxT( "> is already being edited." ) );
  82. item->ClearFlags();
  83. break;
  84. }
  85. }
  86. else
  87. {
  88. item = LocateAndShowItem( aPosition );
  89. }
  90. }
  91. if( !item ) // If clicked on a empty area, clear any highligthed symbol
  92. GetCanvas()->GetView()->HighlightItem( nullptr, nullptr );
  93. switch( GetToolId() )
  94. {
  95. case ID_NO_TOOL_SELECTED:
  96. break;
  97. case ID_SCHEMATIC_DELETE_ITEM_BUTT:
  98. DeleteItemAtCrossHair();
  99. break;
  100. case ID_SHEET_SYMBOL_BUTT:
  101. if( item_flags == 0 )
  102. {
  103. item = CreateSheet( aDC );
  104. if( item != NULL )
  105. {
  106. GetScreen()->SetCurItem( item );
  107. m_canvas->SetAutoPanRequest( true );
  108. }
  109. }
  110. else
  111. {
  112. AddItemToScreen( item );
  113. }
  114. break;
  115. case ID_IMPORT_HLABEL_BUTT:
  116. case ID_SHEET_PIN_BUTT:
  117. if( item_flags == 0 )
  118. item = LocateAndShowItem( aPosition, SCH_COLLECTOR::SheetsAndSheetLabels );
  119. if( item == NULL )
  120. break;
  121. if( (item->Type() == SCH_SHEET_T) && (item_flags == 0) )
  122. {
  123. if( GetToolId() == ID_IMPORT_HLABEL_BUTT )
  124. GetScreen()->SetCurItem( ImportSheetPin( (SCH_SHEET*) item ) );
  125. else
  126. GetScreen()->SetCurItem( CreateSheetPin( (SCH_SHEET*) item ) );
  127. }
  128. else if( (item->Type() == SCH_SHEET_PIN_T) && (item->GetFlags() != 0) )
  129. {
  130. AddItemToScreen( item );
  131. }
  132. break;
  133. #ifdef KICAD_SPICE
  134. case ID_SIM_PROBE:
  135. {
  136. constexpr KICAD_T wiresAndComponents[] = { SCH_LINE_T,
  137. SCH_COMPONENT_T,
  138. SCH_SHEET_PIN_T,
  139. EOT };
  140. item = LocateAndShowItem( aPosition, wiresAndComponents );
  141. if( !item )
  142. break;
  143. std::unique_ptr<NETLIST_OBJECT_LIST> netlist( BuildNetListBase() );
  144. for( NETLIST_OBJECT* obj : *netlist )
  145. {
  146. if( obj->m_Comp == item )
  147. {
  148. SIM_PLOT_FRAME* simFrame = (SIM_PLOT_FRAME*) Kiway().Player( FRAME_SIMULATOR, false );
  149. if( simFrame )
  150. simFrame->AddVoltagePlot( obj->GetNetName() );
  151. break;
  152. }
  153. }
  154. }
  155. break;
  156. case ID_SIM_TUNE:
  157. {
  158. constexpr KICAD_T fieldsAndComponents[] = { SCH_COMPONENT_T, SCH_FIELD_T, EOT };
  159. item = LocateAndShowItem( aPosition, fieldsAndComponents );
  160. if( !item )
  161. return;
  162. if( item->Type() != SCH_COMPONENT_T )
  163. {
  164. item = static_cast<SCH_ITEM*>( item->GetParent() );
  165. if( item->Type() != SCH_COMPONENT_T )
  166. return;
  167. }
  168. SIM_PLOT_FRAME* simFrame = (SIM_PLOT_FRAME*) Kiway().Player( FRAME_SIMULATOR, false );
  169. if( simFrame )
  170. simFrame->AddTuner( static_cast<SCH_COMPONENT*>( item ) );
  171. }
  172. break;
  173. #endif /* KICAD_SPICE */
  174. default:
  175. SetNoToolSelected();
  176. wxFAIL_MSG( wxT( "SCH_EDIT_FRAME::OnLeftClick invalid tool ID <" ) +
  177. wxString::Format( wxT( "%d> selected." ), GetToolId() ) );
  178. }
  179. }
  180. /**
  181. * Function OnLeftDClick
  182. * called on a double click event from the drawpanel mouse handler
  183. * if an editable item is found (text, component)
  184. * Call the suitable dialog editor.
  185. * Id a create command is in progress:
  186. * validate and finish the command
  187. */
  188. void SCH_EDIT_FRAME::OnLeftDClick( wxDC* aDC, const wxPoint& aPosition )
  189. {
  190. EDA_ITEM* item = GetScreen()->GetCurItem();
  191. switch( GetToolId() )
  192. {
  193. case ID_NO_TOOL_SELECTED:
  194. if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
  195. item = LocateAndShowItem( aPosition, SCH_COLLECTOR::DoubleClickItems );
  196. if( ( item == NULL ) || ( item->GetFlags() != 0 ) )
  197. break;
  198. switch( item->Type() )
  199. {
  200. case SCH_SHEET_T:
  201. g_CurrentSheet->push_back( (SCH_SHEET*) item );
  202. DisplayCurrentSheet();
  203. break;
  204. case SCH_COMPONENT_T:
  205. EditComponent( (SCH_COMPONENT*) item );
  206. GetCanvas()->MoveCursorToCrossHair();
  207. if( item->GetFlags() == 0 )
  208. GetScreen()->SetCurItem( NULL );
  209. GetCanvas()->Refresh();
  210. break;
  211. case SCH_TEXT_T:
  212. case SCH_LABEL_T:
  213. case SCH_GLOBAL_LABEL_T:
  214. case SCH_HIER_LABEL_T:
  215. EditSchematicText( (SCH_TEXT*) item );
  216. break;
  217. case SCH_BITMAP_T:
  218. // The bitmap is cached in Opengl: clear the cache, because
  219. // the cache data is perhaps invalid
  220. if( EditImage( (SCH_BITMAP*) item ) )
  221. GetCanvas()->GetView()->RecacheAllItems();
  222. break;
  223. case SCH_FIELD_T:
  224. EditComponentFieldText( (SCH_FIELD*) item );
  225. GetCanvas()->MoveCursorToCrossHair();
  226. break;
  227. case SCH_MARKER_T:
  228. ( (SCH_MARKER*) item )->DisplayMarkerInfo( this );
  229. break;
  230. default:
  231. break;
  232. }
  233. break;
  234. }
  235. }