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.

388 lines
11 KiB

18 years ago
18 years ago
18 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 2011 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 eeschema/onleftclick.cpp
  27. */
  28. #include <fctsys.h>
  29. #include <eeschema_id.h>
  30. #include <class_drawpanel.h>
  31. #include <confirm.h>
  32. #include <wxEeschemaStruct.h>
  33. #include <menus_helpers.h>
  34. #include <general.h>
  35. #include <sch_bus_entry.h>
  36. #include <sch_text.h>
  37. #include <sch_marker.h>
  38. #include <sch_junction.h>
  39. #include <sch_line.h>
  40. #include <sch_no_connect.h>
  41. #include <sch_component.h>
  42. #include <sch_sheet.h>
  43. #include <sch_bitmap.h>
  44. static wxArrayString s_CmpNameList;
  45. static wxArrayString s_PowerNameList;
  46. void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
  47. {
  48. SCH_ITEM* item = GetScreen()->GetCurItem();
  49. wxPoint gridPosition = GetGridPosition( aPosition );
  50. if( ( GetToolId() == ID_NO_TOOL_SELECTED ) || ( item && item->GetFlags() ) )
  51. {
  52. m_canvas->SetAutoPanRequest( false );
  53. m_itemToRepeat = NULL;
  54. if( item && item->GetFlags() )
  55. {
  56. switch( item->Type() )
  57. {
  58. case SCH_LABEL_T:
  59. case SCH_GLOBAL_LABEL_T:
  60. case SCH_HIERARCHICAL_LABEL_T:
  61. case SCH_TEXT_T:
  62. case SCH_SHEET_PIN_T:
  63. case SCH_SHEET_T:
  64. case SCH_BUS_ENTRY_T:
  65. case SCH_JUNCTION_T:
  66. case SCH_COMPONENT_T:
  67. case SCH_FIELD_T:
  68. case SCH_BITMAP_T:
  69. case SCH_NO_CONNECT_T:
  70. addCurrentItemToList( aDC );
  71. return;
  72. case SCH_LINE_T: // May already be drawing segment.
  73. break;
  74. default:
  75. wxFAIL_MSG( wxT( "SCH_EDIT_FRAME::OnLeftClick error. Item type <" ) +
  76. item->GetClass() + wxT( "> is already being edited." ) );
  77. item->ClearFlags();
  78. }
  79. }
  80. else
  81. {
  82. item = LocateAndShowItem( aPosition );
  83. }
  84. }
  85. switch( GetToolId() )
  86. {
  87. case ID_NO_TOOL_SELECTED:
  88. break;
  89. case ID_HIERARCHY_PUSH_POP_BUTT:
  90. if( ( item && item->GetFlags() ) || ( g_RootSheet->CountSheets() == 0 ) )
  91. break;
  92. item = LocateAndShowItem( aPosition, SCH_COLLECTOR::SheetsOnly );
  93. if( item )
  94. {
  95. m_CurrentSheet->Push( (SCH_SHEET*) item );
  96. DisplayCurrentSheet();
  97. }
  98. else
  99. {
  100. wxCHECK_RET( m_CurrentSheet->Last() != g_RootSheet,
  101. wxT( "Cannot leave root sheet. Bad Programmer!" ) );
  102. m_CurrentSheet->Pop();
  103. DisplayCurrentSheet();
  104. }
  105. break;
  106. case ID_NOCONN_BUTT:
  107. if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
  108. {
  109. m_itemToRepeat = AddNoConnect( aDC, gridPosition );
  110. GetScreen()->SetCurItem( m_itemToRepeat );
  111. m_canvas->SetAutoPanRequest( true );
  112. }
  113. else
  114. {
  115. addCurrentItemToList( aDC );
  116. }
  117. break;
  118. case ID_JUNCTION_BUTT:
  119. if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
  120. {
  121. m_itemToRepeat = AddJunction( aDC, gridPosition, true );
  122. GetScreen()->SetCurItem( m_itemToRepeat );
  123. m_canvas->SetAutoPanRequest( true );
  124. }
  125. else
  126. {
  127. addCurrentItemToList( aDC );
  128. }
  129. break;
  130. case ID_WIRETOBUS_ENTRY_BUTT:
  131. case ID_BUSTOBUS_ENTRY_BUTT:
  132. if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
  133. {
  134. CreateBusEntry( aDC, ( GetToolId() == ID_WIRETOBUS_ENTRY_BUTT ) ?
  135. WIRE_TO_BUS : BUS_TO_BUS );
  136. m_canvas->SetAutoPanRequest( true );
  137. }
  138. else
  139. {
  140. addCurrentItemToList( aDC );
  141. }
  142. break;
  143. case ID_SCHEMATIC_DELETE_ITEM_BUTT:
  144. DeleteItemAtCrossHair( aDC );
  145. break;
  146. case ID_WIRE_BUTT:
  147. BeginSegment( aDC, LAYER_WIRE );
  148. m_canvas->SetAutoPanRequest( true );
  149. break;
  150. case ID_BUS_BUTT:
  151. BeginSegment( aDC, LAYER_BUS );
  152. m_canvas->SetAutoPanRequest( true );
  153. break;
  154. case ID_LINE_COMMENT_BUTT:
  155. BeginSegment( aDC, LAYER_NOTES );
  156. m_canvas->SetAutoPanRequest( true );
  157. break;
  158. case ID_TEXT_COMMENT_BUTT:
  159. if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
  160. {
  161. GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_NOTES ) );
  162. m_canvas->SetAutoPanRequest( true );
  163. }
  164. else
  165. {
  166. addCurrentItemToList( aDC );
  167. }
  168. break;
  169. case ID_ADD_IMAGE_BUTT:
  170. if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
  171. {
  172. GetScreen()->SetCurItem( CreateNewImage( aDC ) );
  173. m_canvas->SetAutoPanRequest( true );
  174. }
  175. else
  176. {
  177. addCurrentItemToList( aDC );
  178. }
  179. break;
  180. case ID_LABEL_BUTT:
  181. if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
  182. {
  183. GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_LOCLABEL ) );
  184. m_canvas->SetAutoPanRequest( true );
  185. }
  186. else
  187. {
  188. addCurrentItemToList( aDC );
  189. }
  190. break;
  191. case ID_GLABEL_BUTT:
  192. case ID_HIERLABEL_BUTT:
  193. if( (item == NULL) || (item->GetFlags() == 0) )
  194. {
  195. if( GetToolId() == ID_GLABEL_BUTT )
  196. GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_GLOBLABEL ) );
  197. if( GetToolId() == ID_HIERLABEL_BUTT )
  198. GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_HIERLABEL ) );
  199. m_canvas->SetAutoPanRequest( true );
  200. }
  201. else
  202. {
  203. addCurrentItemToList( aDC );
  204. }
  205. break;
  206. case ID_SHEET_SYMBOL_BUTT:
  207. if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
  208. {
  209. item = CreateSheet( aDC );
  210. if( item != NULL )
  211. {
  212. GetScreen()->SetCurItem( item );
  213. m_canvas->SetAutoPanRequest( true );
  214. }
  215. }
  216. else
  217. {
  218. addCurrentItemToList( aDC );
  219. }
  220. break;
  221. case ID_IMPORT_HLABEL_BUTT:
  222. case ID_SHEET_PIN_BUTT:
  223. if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
  224. item = LocateAndShowItem( aPosition, SCH_COLLECTOR::SheetsAndSheetLabels );
  225. if( item == NULL )
  226. break;
  227. if( (item->Type() == SCH_SHEET_T) && (item->GetFlags() == 0) )
  228. {
  229. if( GetToolId() == ID_IMPORT_HLABEL_BUTT )
  230. GetScreen()->SetCurItem( ImportSheetPin( (SCH_SHEET*) item, aDC ) );
  231. else
  232. GetScreen()->SetCurItem( CreateSheetPin( (SCH_SHEET*) item, aDC ) );
  233. }
  234. else if( (item->Type() == SCH_SHEET_PIN_T) && (item->GetFlags() != 0) )
  235. {
  236. addCurrentItemToList( aDC );
  237. }
  238. break;
  239. case ID_SCH_PLACE_COMPONENT:
  240. if( (item == NULL) || (item->GetFlags() == 0) )
  241. {
  242. GetScreen()->SetCurItem( Load_Component( aDC, wxEmptyString, s_CmpNameList, true ) );
  243. m_canvas->SetAutoPanRequest( true );
  244. }
  245. else
  246. {
  247. addCurrentItemToList( aDC );
  248. }
  249. break;
  250. case ID_PLACE_POWER_BUTT:
  251. if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
  252. {
  253. GetScreen()->SetCurItem( Load_Component( aDC, wxT( "power" ),
  254. s_PowerNameList, false ) );
  255. m_canvas->SetAutoPanRequest( true );
  256. }
  257. else
  258. {
  259. addCurrentItemToList( aDC );
  260. }
  261. break;
  262. default:
  263. SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
  264. wxFAIL_MSG( wxT( "SCH_EDIT_FRAME::OnLeftClick invalid tool ID <" ) +
  265. wxString::Format( wxT( "%d> selected." ), GetToolId() ) );
  266. }
  267. }
  268. /**
  269. * Function OnLeftDClick
  270. * called on a double click event from the drawpanel mouse handler
  271. * if an editable item is found (text, component)
  272. * Call the suitable dialog editor.
  273. * Id a create command is in progress:
  274. * validate and finish the command
  275. */
  276. void SCH_EDIT_FRAME::OnLeftDClick( wxDC* aDC, const wxPoint& aPosition )
  277. {
  278. EDA_ITEM* item = GetScreen()->GetCurItem();
  279. switch( GetToolId() )
  280. {
  281. case ID_NO_TOOL_SELECTED:
  282. if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
  283. {
  284. item = LocateAndShowItem( aPosition );
  285. }
  286. if( ( item == NULL ) || ( item->GetFlags() != 0 ) )
  287. break;
  288. switch( item->Type() )
  289. {
  290. case SCH_SHEET_T:
  291. m_CurrentSheet->Push( (SCH_SHEET*) item );
  292. DisplayCurrentSheet();
  293. break;
  294. case SCH_COMPONENT_T:
  295. EditComponent( (SCH_COMPONENT*) item );
  296. m_canvas->MoveCursorToCrossHair();
  297. break;
  298. case SCH_TEXT_T:
  299. case SCH_LABEL_T:
  300. case SCH_GLOBAL_LABEL_T:
  301. case SCH_HIERARCHICAL_LABEL_T:
  302. EditSchematicText( (SCH_TEXT*) item );
  303. break;
  304. case SCH_BITMAP_T:
  305. EditImage( (SCH_BITMAP*) item );
  306. break;
  307. case SCH_FIELD_T:
  308. EditComponentFieldText( (SCH_FIELD*) item, aDC );
  309. m_canvas->MoveCursorToCrossHair();
  310. break;
  311. case SCH_MARKER_T:
  312. ( (SCH_MARKER*) item )->DisplayMarkerInfo( this );
  313. break;
  314. default:
  315. break;
  316. }
  317. break;
  318. case ID_BUS_BUTT:
  319. case ID_WIRE_BUTT:
  320. case ID_LINE_COMMENT_BUTT:
  321. if( item && item->IsNew() )
  322. EndSegment( aDC );
  323. break;
  324. }
  325. }