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.

504 lines
16 KiB

16 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
18 years ago
18 years ago
16 years ago
  1. /**************************************************************/
  2. /* onleftclick.cpp: */
  3. /* function called when the left button is clicked (released) */
  4. /* function called when the left button is double clicked */
  5. /**************************************************************/
  6. #include "fctsys.h"
  7. #include "common.h"
  8. #include "class_drawpanel.h"
  9. #include "confirm.h"
  10. #include "pcbnew.h"
  11. #include "wxPcbStruct.h"
  12. #include "pcbnew_id.h"
  13. /********************************************************************/
  14. void WinEDA_PcbFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
  15. /********************************************************************/
  16. /* Handle the left buttom mouse click, when a tool is active
  17. */
  18. {
  19. BOARD_ITEM* DrawStruct = GetCurItem();
  20. bool exit = false;
  21. if( (m_ID_current_state == 0) || ( DrawStruct && DrawStruct->m_Flags ) )
  22. {
  23. DrawPanel->m_AutoPAN_Request = false;
  24. if( DrawStruct && DrawStruct->m_Flags ) // "POPUP" in progress
  25. {
  26. DrawPanel->m_IgnoreMouseEvents = true;
  27. DrawPanel->CursorOff( DC );
  28. switch( DrawStruct->Type() )
  29. {
  30. case TYPE_ZONE_CONTAINER:
  31. if( (DrawStruct->m_Flags & IS_NEW) )
  32. {
  33. DrawPanel->m_AutoPAN_Request = true;
  34. Begin_Zone( DC );
  35. }
  36. else
  37. End_Move_Zone_Corner_Or_Outlines( DC, (ZONE_CONTAINER*) DrawStruct );
  38. exit = true;
  39. break;
  40. case TYPE_TRACK:
  41. case TYPE_VIA:
  42. if( DrawStruct->m_Flags & IS_DRAGGED )
  43. {
  44. PlaceDraggedOrMovedTrackSegment( (TRACK*) DrawStruct, DC );
  45. exit = true;
  46. }
  47. break;
  48. case TYPE_TEXTE:
  49. Place_Texte_Pcb( (TEXTE_PCB*) DrawStruct, DC );
  50. exit = true;
  51. break;
  52. case TYPE_TEXTE_MODULE:
  53. PlaceTexteModule( (TEXTE_MODULE*) DrawStruct, DC );
  54. exit = true;
  55. break;
  56. case TYPE_PAD:
  57. PlacePad( (D_PAD*) DrawStruct, DC );
  58. exit = true;
  59. break;
  60. case TYPE_MODULE:
  61. Place_Module( (MODULE*) DrawStruct, DC );
  62. exit = true;
  63. break;
  64. case TYPE_MIRE:
  65. Place_Mire( (MIREPCB*) DrawStruct, DC );
  66. exit = true;
  67. break;
  68. case TYPE_DRAWSEGMENT:
  69. if( m_ID_current_state == 0 )
  70. {
  71. Place_DrawItem( (DRAWSEGMENT*) DrawStruct, DC );
  72. exit = true;
  73. }
  74. break;
  75. default:
  76. if( m_ID_current_state == 0 )
  77. {
  78. DisplayError( this,
  79. wxT(
  80. "WinEDA_PcbFrame::OnLeftClick() err: DrawType %d m_Flags != 0" ),
  81. DrawStruct->Type() );
  82. exit = true;
  83. }
  84. break;
  85. }
  86. DrawPanel->m_IgnoreMouseEvents = false;
  87. DrawPanel->CursorOn( DC );
  88. if( exit )
  89. return;
  90. }
  91. else if( !wxGetKeyState( WXK_SHIFT ) && !wxGetKeyState( WXK_ALT )
  92. && !wxGetKeyState( WXK_CONTROL ) )
  93. {
  94. DrawStruct = PcbGeneralLocateAndDisplay();
  95. if( DrawStruct )
  96. SendMessageToEESCHEMA( DrawStruct );
  97. }
  98. }
  99. if( DrawStruct ) // display netclass info for zones, tracks and pads
  100. {
  101. switch( DrawStruct->Type() )
  102. {
  103. case TYPE_ZONE_CONTAINER:
  104. case TYPE_TRACK:
  105. case TYPE_VIA:
  106. case TYPE_PAD:
  107. GetBoard()->SetCurrentNetClass(
  108. ((BOARD_CONNECTED_ITEM*)DrawStruct)->GetNetClassName() );
  109. m_TrackAndViasSizesList_Changed = true;
  110. AuxiliaryToolBar_Update_UI();
  111. break;
  112. default:
  113. break;
  114. }
  115. }
  116. switch( m_ID_current_state )
  117. {
  118. case ID_MAIN_MENUBAR:
  119. case 0:
  120. break;
  121. case ID_NO_SELECT_BUTT:
  122. break;
  123. case ID_PCB_MUWAVE_TOOL_SELF_CMD:
  124. case ID_PCB_MUWAVE_TOOL_GAP_CMD:
  125. case ID_PCB_MUWAVE_TOOL_STUB_CMD:
  126. case ID_PCB_MUWAVE_TOOL_STUB_ARC_CMD:
  127. case ID_PCB_MUWAVE_TOOL_FUNCTION_SHAPE_CMD:
  128. MuWaveCommand( DC, MousePos );
  129. break;
  130. case ID_PCB_HIGHLIGHT_BUTT:
  131. {
  132. int netcode = Select_High_Light( DC );
  133. if( netcode < 0 )
  134. GetBoard()->DisplayInfo( this );
  135. else
  136. {
  137. NETINFO_ITEM* net = GetBoard()->FindNet( netcode );
  138. if( net )
  139. net->DisplayInfo( this );
  140. }
  141. }
  142. break;
  143. case ID_PCB_SHOW_1_RATSNEST_BUTT:
  144. DrawStruct = PcbGeneralLocateAndDisplay();
  145. Show_1_Ratsnest( DrawStruct, DC );
  146. if( DrawStruct )
  147. SendMessageToEESCHEMA( DrawStruct );
  148. break;
  149. case ID_PCB_MIRE_BUTT:
  150. if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) )
  151. {
  152. SetCurItem( Create_Mire( DC ) );
  153. DrawPanel->MouseToCursorSchema();
  154. }
  155. else if( DrawStruct->Type() == TYPE_MIRE )
  156. {
  157. Place_Mire( (MIREPCB*) DrawStruct, DC );
  158. }
  159. else
  160. DisplayError( this, wxT( "Internal err: Struct not TYPE_MIRE" ) );
  161. break;
  162. case ID_PCB_CIRCLE_BUTT:
  163. case ID_PCB_ARC_BUTT:
  164. case ID_PCB_ADD_LINE_BUTT:
  165. {
  166. int shape = S_SEGMENT;
  167. if( m_ID_current_state == ID_PCB_CIRCLE_BUTT )
  168. shape = S_CIRCLE;
  169. if( m_ID_current_state == ID_PCB_ARC_BUTT )
  170. shape = S_ARC;
  171. if( ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer <= LAST_COPPER_LAYER )
  172. {
  173. DisplayError( this, _( "Graphic not authorized on Copper layers" ) );
  174. break;
  175. }
  176. if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) )
  177. {
  178. DrawStruct = Begin_DrawSegment( NULL, shape, DC );
  179. SetCurItem( DrawStruct );
  180. DrawPanel->m_AutoPAN_Request = true;
  181. }
  182. else if( DrawStruct
  183. && (DrawStruct->Type() == TYPE_DRAWSEGMENT)
  184. && (DrawStruct->m_Flags & IS_NEW) )
  185. {
  186. DrawStruct = Begin_DrawSegment( (DRAWSEGMENT*) DrawStruct, shape, DC );
  187. SetCurItem( DrawStruct );
  188. DrawPanel->m_AutoPAN_Request = true;
  189. }
  190. break;
  191. }
  192. case ID_TRACK_BUTT:
  193. if( ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer > LAST_COPPER_LAYER )
  194. {
  195. DisplayError( this, _( "Tracks on Copper layers only " ) );
  196. break;
  197. }
  198. if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) )
  199. {
  200. DrawStruct = Begin_Route( NULL, DC );
  201. SetCurItem( DrawStruct );
  202. if( DrawStruct )
  203. DrawPanel->m_AutoPAN_Request = true;
  204. }
  205. else if( DrawStruct && (DrawStruct->m_Flags & IS_NEW) )
  206. {
  207. TRACK* track = Begin_Route( (TRACK*) DrawStruct, DC );
  208. // SetCurItem() must not write to the msg panel
  209. // because a track info is displayed while moving the mouse cursor
  210. if( track ) // A new segment was created
  211. SetCurItem( DrawStruct = track, false );
  212. DrawPanel->m_AutoPAN_Request = true;
  213. }
  214. break;
  215. case ID_PCB_ZONES_BUTT:
  216. /* ZONE Tool is selected. Determine action for a left click:
  217. * this can be start a new zone or select and move an existing zone outline corner
  218. * if found near the mouse cursor
  219. */
  220. if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) )
  221. {
  222. // there is no current item, try to find something under mouse
  223. DrawStruct = PcbGeneralLocateAndDisplay();
  224. bool hit_on_corner = false;
  225. if( DrawStruct && (DrawStruct->Type() == TYPE_ZONE_CONTAINER) )
  226. {
  227. // We have a hit under mouse (a zone outline corner or segment)
  228. // test for a corner only because want to move corners only.
  229. ZONE_CONTAINER* edge_zone = (ZONE_CONTAINER*) DrawStruct;
  230. if( edge_zone->HitTestForCorner( GetScreen()->RefPos( true ) ) >= 0 ) // corner located!
  231. hit_on_corner = true;
  232. }
  233. if( hit_on_corner )
  234. {
  235. DrawPanel->MouseToCursorSchema();
  236. ZONE_CONTAINER* zone_cont = (ZONE_CONTAINER*) GetCurItem();
  237. DrawPanel->m_AutoPAN_Request = true;
  238. Start_Move_Zone_Corner( DC,
  239. zone_cont,
  240. zone_cont->m_CornerSelection,
  241. false );
  242. }
  243. else if( Begin_Zone( DC ) )
  244. {
  245. DrawPanel->m_AutoPAN_Request = true;
  246. DrawStruct = GetBoard()->m_CurrentZoneContour;
  247. GetScreen()->SetCurItem( DrawStruct );
  248. }
  249. }
  250. else if( DrawStruct
  251. && (DrawStruct->Type() == TYPE_ZONE_CONTAINER)
  252. && (DrawStruct->m_Flags & IS_NEW) )
  253. { // Add a new corner to the current outline beeing created:
  254. DrawPanel->m_AutoPAN_Request = true;
  255. Begin_Zone( DC );
  256. DrawStruct = GetBoard()->m_CurrentZoneContour;
  257. GetScreen()->SetCurItem( DrawStruct );
  258. }
  259. else
  260. DisplayError( this, wxT( "WinEDA_PcbFrame::OnLeftClick() zone internal error" ) );
  261. break;
  262. case ID_PCB_ADD_TEXT_BUTT:
  263. if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) )
  264. {
  265. SetCurItem( Create_Texte_Pcb( DC ) );
  266. DrawPanel->MouseToCursorSchema();
  267. DrawPanel->m_AutoPAN_Request = true;
  268. }
  269. else if( DrawStruct->Type() == TYPE_TEXTE )
  270. {
  271. Place_Texte_Pcb( (TEXTE_PCB*) DrawStruct, DC );
  272. DrawPanel->m_AutoPAN_Request = false;
  273. }
  274. else
  275. DisplayError( this, wxT( "Internal err: Struct not TYPE_TEXTE" ) );
  276. break;
  277. case ID_COMPONENT_BUTT:
  278. if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) )
  279. {
  280. DrawPanel->MouseToCursorSchema();
  281. DrawStruct = Load_Module_From_Library( wxEmptyString, DC );
  282. SetCurItem( DrawStruct );
  283. if( DrawStruct )
  284. StartMove_Module( (MODULE*) DrawStruct, DC );
  285. }
  286. else if( DrawStruct->Type() == TYPE_MODULE )
  287. {
  288. Place_Module( (MODULE*) DrawStruct, DC );
  289. DrawPanel->m_AutoPAN_Request = false;
  290. }
  291. else
  292. DisplayError( this, wxT( "Internal err: Struct not TYPE_MODULE" ) );
  293. break;
  294. case ID_PCB_COTATION_BUTT:
  295. if( ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer <= LAST_COPPER_LAYER )
  296. {
  297. DisplayError( this, _( "Cotation not authorized on Copper layers" ) );
  298. break;
  299. }
  300. if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) )
  301. {
  302. DrawStruct = Begin_Cotation( NULL, DC );
  303. SetCurItem( DrawStruct );
  304. DrawPanel->m_AutoPAN_Request = true;
  305. }
  306. else if( DrawStruct
  307. && (DrawStruct->Type() == TYPE_COTATION)
  308. && (DrawStruct->m_Flags & IS_NEW) )
  309. {
  310. DrawStruct = Begin_Cotation( (COTATION*) DrawStruct, DC );
  311. SetCurItem( DrawStruct );
  312. DrawPanel->m_AutoPAN_Request = true;
  313. }
  314. else
  315. DisplayError( this, wxT( "Internal err: Struct not COTATION" ) );
  316. break;
  317. case ID_PCB_DELETE_ITEM_BUTT:
  318. if( !DrawStruct || (DrawStruct->m_Flags == 0) )
  319. {
  320. DrawStruct = PcbGeneralLocateAndDisplay();
  321. if( DrawStruct && (DrawStruct->m_Flags == 0) )
  322. {
  323. RemoveStruct( DrawStruct, DC );
  324. SetCurItem( DrawStruct = NULL );
  325. }
  326. }
  327. break;
  328. case ID_PCB_PLACE_OFFSET_COORD_BUTT:
  329. DrawPanel->DrawAuxiliaryAxis( DC, GR_XOR );
  330. m_Auxiliary_Axis_Position = GetScreen()->m_Curseur;
  331. DrawPanel->DrawAuxiliaryAxis( DC, GR_COPY );
  332. GetScreen()->SetModify();
  333. break;
  334. default:
  335. DrawPanel->SetCursor( wxCURSOR_ARROW );
  336. DisplayError( this, wxT( "WinEDA_PcbFrame::OnLeftClick() id error" ) );
  337. SetToolID( 0, wxCURSOR_ARROW, wxEmptyString );
  338. break;
  339. }
  340. }
  341. /********************************************************************************/
  342. void WinEDA_PcbFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
  343. /********************************************************************************/
  344. /* handle the double click on the mouse left button
  345. */
  346. {
  347. BOARD_ITEM* DrawStruct = GetCurItem();
  348. wxPoint pos = GetPosition();
  349. switch( m_ID_current_state )
  350. {
  351. case 0:
  352. if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) )
  353. {
  354. DrawStruct = PcbGeneralLocateAndDisplay();
  355. }
  356. if( (DrawStruct == NULL) || (DrawStruct->m_Flags != 0) )
  357. break;
  358. SendMessageToEESCHEMA( DrawStruct );
  359. // An item is found
  360. SetCurItem( DrawStruct );
  361. switch( DrawStruct->Type() )
  362. {
  363. case TYPE_TRACK:
  364. case TYPE_VIA:
  365. if( DrawStruct->m_Flags & IS_NEW )
  366. {
  367. End_Route( (TRACK*) DrawStruct, DC );
  368. DrawPanel->m_AutoPAN_Request = false;
  369. }
  370. else if( DrawStruct->m_Flags == 0 )
  371. {
  372. Edit_TrackSegm_Width( DC, (TRACK*) DrawStruct );
  373. }
  374. break;
  375. case TYPE_TEXTE:
  376. InstallTextPCBOptionsFrame( (TEXTE_PCB*) DrawStruct, DC );
  377. DrawPanel->MouseToCursorSchema();
  378. break;
  379. case TYPE_PAD:
  380. InstallPadOptionsFrame( (D_PAD*) DrawStruct, DC, pos );
  381. DrawPanel->MouseToCursorSchema();
  382. break;
  383. case TYPE_MODULE:
  384. InstallModuleOptionsFrame( (MODULE*) DrawStruct, DC );
  385. DrawPanel->MouseToCursorSchema();
  386. break;
  387. case TYPE_MIRE:
  388. InstallMireOptionsFrame( (MIREPCB*) DrawStruct, DC, pos );
  389. DrawPanel->MouseToCursorSchema();
  390. break;
  391. case TYPE_COTATION:
  392. Install_Edit_Cotation( (COTATION*) DrawStruct, DC, pos );
  393. DrawPanel->MouseToCursorSchema();
  394. break;
  395. case TYPE_TEXTE_MODULE:
  396. InstallTextModOptionsFrame( (TEXTE_MODULE*) DrawStruct, DC );
  397. DrawPanel->MouseToCursorSchema();
  398. break;
  399. case TYPE_DRAWSEGMENT:
  400. InstallGraphicItemPropertiesDialog( (DRAWSEGMENT*) DrawStruct, DC );
  401. break;
  402. case TYPE_ZONE_CONTAINER:
  403. if( DrawStruct->m_Flags )
  404. break;
  405. Edit_Zone_Params( DC, (ZONE_CONTAINER*) DrawStruct );
  406. break;
  407. default:
  408. break;
  409. }
  410. break; // end case 0
  411. case ID_TRACK_BUTT:
  412. if( DrawStruct && (DrawStruct->m_Flags & IS_NEW) )
  413. {
  414. End_Route( (TRACK*) DrawStruct, DC );
  415. DrawPanel->m_AutoPAN_Request = false;
  416. }
  417. break;
  418. case ID_PCB_ZONES_BUTT:
  419. if( End_Zone( DC ) )
  420. {
  421. DrawPanel->m_AutoPAN_Request = false;
  422. SetCurItem( NULL );
  423. }
  424. break;
  425. case ID_PCB_ADD_LINE_BUTT:
  426. case ID_PCB_ARC_BUTT:
  427. case ID_PCB_CIRCLE_BUTT:
  428. if( DrawStruct == NULL )
  429. break;
  430. if( DrawStruct->Type() != TYPE_DRAWSEGMENT )
  431. {
  432. DisplayError( this, wxT( "DrawStruct Type error" ) );
  433. DrawPanel->m_AutoPAN_Request = false;
  434. break;
  435. }
  436. if( (DrawStruct->m_Flags & IS_NEW) )
  437. {
  438. End_Edge( (DRAWSEGMENT*) DrawStruct, DC );
  439. DrawPanel->m_AutoPAN_Request = false;
  440. SetCurItem( NULL );
  441. }
  442. break;
  443. }
  444. }