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.

622 lines
18 KiB

18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
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) 2007 Jean-Pierre Charras, jean-pierre.charras@gipsa-lab.inpg.fr
  5. * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 1992-2017 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 pcbnew/onleftclick.cpp
  27. * @brief Functions called when the left button is clicked or double clicked.
  28. */
  29. #include <fctsys.h>
  30. #include <class_drawpanel.h>
  31. #include <confirm.h>
  32. #include <pcb_edit_frame.h>
  33. #include <msgpanel.h>
  34. #include <class_board.h>
  35. #include <class_drawsegment.h>
  36. #include <class_dimension.h>
  37. #include <class_zone.h>
  38. #include <class_pcb_text.h>
  39. #include <class_text_mod.h>
  40. #include <class_module.h>
  41. #include <class_pcb_target.h>
  42. #include <origin_viewitem.h>
  43. #include <project.h>
  44. #include <pcbnew.h>
  45. #include <pcbnew_id.h>
  46. #include <menus_helpers.h>
  47. #include <tools/pcb_editor_control.h>
  48. #include <tools/pcbnew_control.h>
  49. /* Handle the left button mouse click, when a tool is active
  50. */
  51. void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
  52. {
  53. BOARD_ITEM* curr_item = GetCurItem();
  54. bool exit = false;
  55. bool no_tool = GetToolId() == ID_NO_TOOL_SELECTED;
  56. if( no_tool || ( curr_item && curr_item->GetFlags() ) )
  57. {
  58. m_canvas->SetAutoPanRequest( false );
  59. if( curr_item && curr_item->GetFlags() ) // Command in progress
  60. {
  61. m_canvas->SetIgnoreMouseEvents( true );
  62. m_canvas->CrossHairOff( aDC );
  63. switch( curr_item->Type() )
  64. {
  65. case PCB_ZONE_AREA_T:
  66. if( curr_item->IsNew() )
  67. {
  68. m_canvas->SetAutoPanRequest( true );
  69. Begin_Zone( aDC );
  70. }
  71. else
  72. {
  73. End_Move_Zone_Corner_Or_Outlines( aDC, static_cast<ZONE_CONTAINER*>( curr_item ) );
  74. }
  75. exit = true;
  76. break;
  77. case PCB_TRACE_T:
  78. case PCB_VIA_T:
  79. if( curr_item->IsDragging() )
  80. {
  81. PlaceDraggedOrMovedTrackSegment( static_cast<TRACK*>( curr_item ), aDC );
  82. exit = true;
  83. }
  84. break;
  85. case PCB_TEXT_T:
  86. Place_Texte_Pcb( static_cast<TEXTE_PCB*>( curr_item ), aDC );
  87. exit = true;
  88. break;
  89. case PCB_MODULE_TEXT_T:
  90. PlaceTexteModule( static_cast<TEXTE_MODULE*>( curr_item ), aDC );
  91. exit = true;
  92. break;
  93. case PCB_PAD_T:
  94. PlacePad( static_cast<D_PAD*>( curr_item ), aDC );
  95. exit = true;
  96. break;
  97. case PCB_MODULE_T:
  98. PlaceModule( static_cast<MODULE*>( curr_item ), aDC );
  99. exit = true;
  100. break;
  101. case PCB_TARGET_T:
  102. PlaceTarget( static_cast<PCB_TARGET*>( curr_item ), aDC );
  103. exit = true;
  104. break;
  105. case PCB_LINE_T:
  106. if( no_tool ) // when no tools: existing item moving.
  107. {
  108. Place_DrawItem( static_cast<DRAWSEGMENT*>( curr_item ), aDC );
  109. exit = true;
  110. }
  111. break;
  112. case PCB_DIMENSION_T:
  113. if( ! curr_item->IsNew() )
  114. { // We are moving the text of an existing dimension. Place it
  115. PlaceDimensionText( static_cast<DIMENSION*>( curr_item ), aDC );
  116. exit = true;
  117. }
  118. break;
  119. case PCB_MARKER_T: // MARKER_PCB, a marker used to show something
  120. curr_item->ClearFlags(); // Not reason to have flags set
  121. exit = true;
  122. break;
  123. default:
  124. DisplayError( this,
  125. wxString::Format(
  126. "PCB_EDIT_FRAME::OnLeftClick() err: curr_item type %d m_Flags != 0 (%X)",
  127. curr_item->Type(), curr_item->GetFlags() ) );
  128. exit = true;
  129. break;
  130. }
  131. m_canvas->SetIgnoreMouseEvents( false );
  132. m_canvas->CrossHairOn( aDC );
  133. if( exit )
  134. return;
  135. }
  136. else if( !wxGetKeyState( WXK_SHIFT ) && !wxGetKeyState( WXK_ALT )
  137. && !wxGetKeyState( WXK_CONTROL ) )
  138. {
  139. curr_item = PcbGeneralLocateAndDisplay();
  140. if( curr_item )
  141. SendMessageToEESCHEMA( curr_item );
  142. }
  143. }
  144. if( curr_item ) // display netclass info for zones, tracks and pads
  145. {
  146. switch( curr_item->Type() )
  147. {
  148. case PCB_ZONE_AREA_T:
  149. case PCB_TRACE_T:
  150. case PCB_VIA_T:
  151. case PCB_PAD_T:
  152. SetCurrentNetClass(
  153. ((BOARD_CONNECTED_ITEM*)curr_item)->GetNetClassName() );
  154. break;
  155. default:
  156. break;
  157. }
  158. }
  159. switch( GetToolId() )
  160. {
  161. case ID_MAIN_MENUBAR:
  162. case ID_NO_TOOL_SELECTED:
  163. case ID_ZOOM_SELECTION:
  164. break;
  165. case ID_PCB_MUWAVE_TOOL_SELF_CMD:
  166. case ID_PCB_MUWAVE_TOOL_GAP_CMD:
  167. case ID_PCB_MUWAVE_TOOL_STUB_CMD:
  168. case ID_PCB_MUWAVE_TOOL_STUB_ARC_CMD:
  169. case ID_PCB_MUWAVE_TOOL_FUNCTION_SHAPE_CMD:
  170. MuWaveCommand( aDC, aPosition );
  171. break;
  172. case ID_PCB_HIGHLIGHT_BUTT:
  173. {
  174. int netcode = SelectHighLight( aDC );
  175. if( netcode < 0 )
  176. SetMsgPanel( GetBoard() );
  177. else
  178. {
  179. NETINFO_ITEM* net = GetBoard()->FindNet( netcode );
  180. if( net )
  181. {
  182. MSG_PANEL_ITEMS items;
  183. net->GetMsgPanelInfo( m_UserUnits, items );
  184. SetMsgPanel( items );
  185. }
  186. }
  187. }
  188. break;
  189. case ID_PCB_SHOW_1_RATSNEST_BUTT:
  190. curr_item = PcbGeneralLocateAndDisplay();
  191. Show_1_Ratsnest( curr_item, aDC );
  192. if( curr_item )
  193. SendMessageToEESCHEMA( curr_item );
  194. break;
  195. case ID_PCB_TARGET_BUTT:
  196. if( (curr_item == NULL) || (curr_item->GetFlags() == 0) )
  197. {
  198. SetCurItem( (BOARD_ITEM*) CreateTarget( aDC ) );
  199. m_canvas->MoveCursorToCrossHair();
  200. }
  201. else if( curr_item->Type() == PCB_TARGET_T )
  202. {
  203. PlaceTarget( (PCB_TARGET*) curr_item, aDC );
  204. }
  205. else
  206. {
  207. DisplayError( this, wxT( "OnLeftClick err: not a PCB_TARGET_T" ) );
  208. }
  209. break;
  210. case ID_PCB_CIRCLE_BUTT:
  211. case ID_PCB_ARC_BUTT:
  212. case ID_PCB_ADD_LINE_BUTT:
  213. {
  214. STROKE_T shape = S_SEGMENT;
  215. if( GetToolId() == ID_PCB_CIRCLE_BUTT )
  216. shape = S_CIRCLE;
  217. if( GetToolId() == ID_PCB_ARC_BUTT )
  218. shape = S_ARC;
  219. if( IsCopperLayer( GetActiveLayer() ) )
  220. {
  221. DisplayError( this, _( "Graphic not allowed on Copper layers" ) );
  222. break;
  223. }
  224. if( (curr_item == NULL) || (curr_item->GetFlags() == 0) )
  225. {
  226. curr_item = (BOARD_ITEM*) Begin_DrawSegment( NULL, shape, aDC );
  227. SetCurItem( curr_item );
  228. m_canvas->SetAutoPanRequest( true );
  229. }
  230. else if( curr_item
  231. && (curr_item->Type() == PCB_LINE_T)
  232. && curr_item->IsNew() )
  233. {
  234. curr_item = (BOARD_ITEM*) Begin_DrawSegment( (DRAWSEGMENT*) curr_item, shape, aDC );
  235. SetCurItem( curr_item );
  236. m_canvas->SetAutoPanRequest( true );
  237. }
  238. }
  239. break;
  240. case ID_TRACK_BUTT:
  241. if( !IsCopperLayer( GetActiveLayer() ) )
  242. {
  243. DisplayError( this, _( "Tracks on Copper layers only" ) );
  244. break;
  245. }
  246. if( (curr_item == NULL) || (curr_item->GetFlags() == 0) )
  247. {
  248. curr_item = (BOARD_ITEM*) Begin_Route( NULL, aDC );
  249. SetCurItem( curr_item );
  250. if( curr_item )
  251. m_canvas->SetAutoPanRequest( true );
  252. }
  253. else if( curr_item && curr_item->IsNew() )
  254. {
  255. TRACK* track = Begin_Route( (TRACK*) curr_item, aDC );
  256. // SetCurItem() must not write to the msg panel
  257. // because a track info is displayed while moving the mouse cursor
  258. if( track ) // A new segment was created
  259. SetCurItem( curr_item = (BOARD_ITEM*) track, false );
  260. m_canvas->SetAutoPanRequest( true );
  261. }
  262. break;
  263. case ID_PCB_ZONES_BUTT:
  264. case ID_PCB_KEEPOUT_AREA_BUTT:
  265. /* ZONE or KEEPOUT Tool is selected. Determine action for a left click:
  266. * this can be start a new zone or select and move an existing zone outline corner
  267. * if found near the mouse cursor
  268. */
  269. if( (curr_item == NULL) || (curr_item->GetFlags() == 0) )
  270. {
  271. if( Begin_Zone( aDC ) )
  272. {
  273. m_canvas->SetAutoPanRequest( true );
  274. curr_item = GetBoard()->m_CurrentZoneContour;
  275. GetScreen()->SetCurItem( curr_item );
  276. }
  277. }
  278. else if( curr_item && (curr_item->Type() == PCB_ZONE_AREA_T) && curr_item->IsNew() )
  279. { // Add a new corner to the current outline being created:
  280. m_canvas->SetAutoPanRequest( true );
  281. Begin_Zone( aDC );
  282. curr_item = GetBoard()->m_CurrentZoneContour;
  283. GetScreen()->SetCurItem( curr_item );
  284. }
  285. else
  286. {
  287. DisplayError( this, wxT( "PCB_EDIT_FRAME::OnLeftClick() zone internal error" ) );
  288. }
  289. break;
  290. case ID_PCB_ADD_TEXT_BUTT:
  291. if( Edge_Cuts == GetActiveLayer() )
  292. {
  293. DisplayError( this,
  294. _( "Texts not allowed on Edge Cut layer" ) );
  295. break;
  296. }
  297. if( (curr_item == NULL) || (curr_item->GetFlags() == 0) )
  298. {
  299. SetCurItem( CreateTextePcb( aDC ) );
  300. m_canvas->MoveCursorToCrossHair();
  301. m_canvas->SetAutoPanRequest( true );
  302. }
  303. else if( curr_item->Type() == PCB_TEXT_T )
  304. {
  305. Place_Texte_Pcb( (TEXTE_PCB*) curr_item, aDC );
  306. m_canvas->SetAutoPanRequest( false );
  307. }
  308. else
  309. {
  310. DisplayError( this, wxT( "OnLeftClick err: not a PCB_TEXT_T" ) );
  311. }
  312. break;
  313. case ID_PCB_MODULE_BUTT:
  314. if( (curr_item == NULL) || (curr_item->GetFlags() == 0) )
  315. {
  316. m_canvas->MoveCursorToCrossHair();
  317. MODULE* module = LoadModuleFromLibrary( wxEmptyString, Prj().PcbFootprintLibs() );
  318. SetCurItem( (BOARD_ITEM*) module );
  319. if( module )
  320. {
  321. m_canvas->MoveCursorToCrossHair();
  322. AddModuleToBoard( module, aDC );
  323. StartMoveModule( module, aDC, false );
  324. }
  325. }
  326. else if( curr_item->Type() == PCB_MODULE_T )
  327. {
  328. PlaceModule( (MODULE*) curr_item, aDC );
  329. m_canvas->SetAutoPanRequest( false );
  330. }
  331. else
  332. {
  333. DisplayError( this, wxT( "Internal err: Struct not PCB_MODULE_T" ) );
  334. }
  335. break;
  336. case ID_PCB_DIMENSION_BUTT:
  337. if( IsCopperLayer( GetActiveLayer() ) || GetActiveLayer() == Edge_Cuts )
  338. {
  339. DisplayError( this, _( "Dimension not allowed on Copper or Edge Cut layers" ) );
  340. break;
  341. }
  342. if( !curr_item || !curr_item->GetFlags() )
  343. {
  344. curr_item = (BOARD_ITEM*) EditDimension( NULL, aDC );
  345. SetCurItem( curr_item );
  346. m_canvas->SetAutoPanRequest( true );
  347. }
  348. else if( curr_item && (curr_item->Type() == PCB_DIMENSION_T) && curr_item->IsNew() )
  349. {
  350. curr_item = (BOARD_ITEM*) EditDimension( (DIMENSION*) curr_item, aDC );
  351. SetCurItem( curr_item );
  352. m_canvas->SetAutoPanRequest( true );
  353. }
  354. else
  355. {
  356. DisplayError( this,
  357. wxT( "PCB_EDIT_FRAME::OnLeftClick() error item is not a DIMENSION" ) );
  358. }
  359. break;
  360. case ID_PCB_DELETE_ITEM_BUTT:
  361. if( !curr_item || !curr_item->GetFlags() )
  362. {
  363. curr_item = PcbGeneralLocateAndDisplay();
  364. if( curr_item && (curr_item->GetFlags() == 0) )
  365. {
  366. RemoveStruct( curr_item, aDC );
  367. SetCurItem( curr_item = NULL );
  368. }
  369. }
  370. break;
  371. case ID_PCB_PLACE_OFFSET_COORD_BUTT:
  372. PCB_EDITOR_CONTROL::SetDrillOrigin( GetGalCanvas()->GetView(), this,
  373. new KIGFX::ORIGIN_VIEWITEM( GetAuxOrigin(), UR_TRANSIENT ),
  374. GetCrossHairPosition() );
  375. m_canvas->Refresh();
  376. break;
  377. case ID_PCB_PLACE_GRID_COORD_BUTT:
  378. PCBNEW_CONTROL::SetGridOrigin( GetGalCanvas()->GetView(), this,
  379. new KIGFX::ORIGIN_VIEWITEM( GetBoard()->GetGridOrigin(), UR_TRANSIENT ),
  380. GetCrossHairPosition() );
  381. m_canvas->Refresh();
  382. break;
  383. case ID_PCB_DRAW_VIA_BUTT:
  384. DisplayError( this, _( "Via Tool not available in Legacy Toolset" ) );
  385. SetNoToolSelected();
  386. break;
  387. case ID_PCB_MEASUREMENT_TOOL:
  388. DisplayError( this, _( "Measurement Tool not available in Legacy Toolset" ) );
  389. SetNoToolSelected();
  390. break;
  391. default:
  392. DisplayError( this, wxT( "PCB_EDIT_FRAME::OnLeftClick() id error" ) );
  393. SetNoToolSelected();
  394. break;
  395. }
  396. }
  397. /* handle the double click on the mouse left button
  398. */
  399. void PCB_EDIT_FRAME::OnLeftDClick( wxDC* aDC, const wxPoint& aPosition )
  400. {
  401. BOARD_ITEM* curr_item = GetCurItem();
  402. switch( GetToolId() )
  403. {
  404. case ID_NO_TOOL_SELECTED:
  405. if( (curr_item == NULL) || (curr_item->GetFlags() == 0) )
  406. {
  407. curr_item = PcbGeneralLocateAndDisplay();
  408. }
  409. if( (curr_item == NULL) || (curr_item->GetFlags() != 0) )
  410. break;
  411. SendMessageToEESCHEMA( curr_item );
  412. // An item is found
  413. SetCurItem( curr_item );
  414. switch( curr_item->Type() )
  415. {
  416. case PCB_TRACE_T:
  417. case PCB_VIA_T:
  418. if( curr_item->IsNew() )
  419. {
  420. if( End_Route( (TRACK*) curr_item, aDC ) )
  421. m_canvas->SetAutoPanRequest( false );
  422. }
  423. else if( curr_item->GetFlags() == 0 )
  424. {
  425. Edit_TrackSegm_Width( aDC, (TRACK*) curr_item );
  426. }
  427. break;
  428. case PCB_TEXT_T:
  429. case PCB_PAD_T:
  430. case PCB_MODULE_T:
  431. case PCB_TARGET_T:
  432. case PCB_DIMENSION_T:
  433. case PCB_MODULE_TEXT_T:
  434. OnEditItemRequest( aDC, curr_item );
  435. m_canvas->MoveCursorToCrossHair();
  436. break;
  437. case PCB_LINE_T:
  438. OnEditItemRequest( aDC, curr_item );
  439. break;
  440. case PCB_ZONE_AREA_T:
  441. if( curr_item->GetFlags() )
  442. break;
  443. OnEditItemRequest( aDC, curr_item );
  444. break;
  445. default:
  446. break;
  447. }
  448. break; // end case 0
  449. case ID_TRACK_BUTT:
  450. if( curr_item && curr_item->IsNew() )
  451. {
  452. if( End_Route( (TRACK*) curr_item, aDC ) )
  453. m_canvas->SetAutoPanRequest( false );
  454. }
  455. break;
  456. case ID_PCB_ZONES_BUTT:
  457. case ID_PCB_KEEPOUT_AREA_BUTT:
  458. if( End_Zone( aDC ) )
  459. {
  460. m_canvas->SetAutoPanRequest( false );
  461. SetCurItem( NULL );
  462. }
  463. break;
  464. case ID_PCB_ADD_LINE_BUTT:
  465. case ID_PCB_ARC_BUTT:
  466. case ID_PCB_CIRCLE_BUTT:
  467. if( curr_item == NULL )
  468. break;
  469. if( curr_item->Type() != PCB_LINE_T )
  470. {
  471. DisplayErrorMessage( this, "Item type is incorrect",
  472. wxString::Format( "Selected item type is %d\n"
  473. "Expected: %d", curr_item->Type(), PCB_LINE_T ) );
  474. m_canvas->SetAutoPanRequest( false );
  475. break;
  476. }
  477. if( curr_item->IsNew() )
  478. {
  479. End_Edge( (DRAWSEGMENT*) curr_item, aDC );
  480. m_canvas->SetAutoPanRequest( false );
  481. SetCurItem( NULL );
  482. }
  483. break;
  484. }
  485. }
  486. void PCB_EDIT_FRAME::OnEditItemRequest( wxDC* aDC, BOARD_ITEM* aItem )
  487. {
  488. switch( aItem->Type() )
  489. {
  490. case PCB_TRACE_T:
  491. case PCB_VIA_T:
  492. Edit_TrackSegm_Width( aDC, static_cast<TRACK*>( aItem ) );
  493. break;
  494. case PCB_TEXT_T:
  495. InstallTextOptionsFrame( aItem, aDC );
  496. break;
  497. case PCB_PAD_T:
  498. InstallPadOptionsFrame( static_cast<D_PAD*>( aItem ) );
  499. break;
  500. case PCB_MODULE_T:
  501. InstallFootprintPropertiesDialog( static_cast<MODULE*>( aItem ), aDC );
  502. break;
  503. case PCB_TARGET_T:
  504. ShowTargetOptionsDialog( static_cast<PCB_TARGET*>( aItem ), aDC );
  505. break;
  506. case PCB_DIMENSION_T:
  507. ShowDimensionPropertyDialog( static_cast<DIMENSION*>( aItem ), aDC );
  508. break;
  509. case PCB_MODULE_TEXT_T:
  510. InstallTextOptionsFrame( aItem, aDC );
  511. break;
  512. case PCB_LINE_T:
  513. InstallGraphicItemPropertiesDialog( aItem, aDC );
  514. break;
  515. case PCB_ZONE_AREA_T:
  516. Edit_Zone_Params( aDC, static_cast<ZONE_CONTAINER*>( aItem ) );
  517. break;
  518. default:
  519. break;
  520. }
  521. }