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.

341 lines
13 KiB

  1. /***************************************************************************/
  2. /* moduleframe.cpp - fonctions de base de la classe WinEDA_ModuleEditFrame */
  3. /***************************************************************************/
  4. #ifdef __GNUG__
  5. #pragma implementation
  6. #endif
  7. #include "fctsys.h"
  8. #include "common.h"
  9. #include "pcbnew.h"
  10. #include "bitmaps.h"
  11. #include "protos.h"
  12. #include "id.h"
  13. /********************************/
  14. /* class WinEDA_ModuleEditFrame */
  15. /********************************/
  16. BEGIN_EVENT_TABLE( WinEDA_ModuleEditFrame, wxFrame )
  17. COMMON_EVENTS_DRAWFRAME
  18. EVT_MENU_RANGE( ID_POPUP_PCB_ITEM_SELECTION_START,
  19. ID_POPUP_PCB_ITEM_SELECTION_END,
  20. WinEDA_BasePcbFrame::ProcessItemSelection )
  21. EVT_CLOSE( WinEDA_ModuleEditFrame::OnCloseWindow )
  22. EVT_SIZE( WinEDA_ModuleEditFrame::OnSize )
  23. EVT_KICAD_CHOICEBOX( ID_ON_ZOOM_SELECT, WinEDA_PcbFrame::OnSelectZoom )
  24. EVT_KICAD_CHOICEBOX( ID_ON_GRID_SELECT, WinEDA_PcbFrame::OnSelectGrid )
  25. EVT_TOOL_RANGE( ID_ZOOM_IN_BUTT, ID_ZOOM_PAGE_BUTT,
  26. WinEDA_ModuleEditFrame::Process_Zoom )
  27. EVT_TOOL( ID_LIBEDIT_SELECT_CURRENT_LIB, WinEDA_ModuleEditFrame::Process_Special_Functions )
  28. EVT_TOOL( ID_MODEDIT_SAVE_LIBMODULE, WinEDA_ModuleEditFrame::Process_Special_Functions )
  29. EVT_TOOL( ID_LIBEDIT_DELETE_PART, WinEDA_ModuleEditFrame::Process_Special_Functions )
  30. EVT_TOOL( ID_MODEDIT_NEW_MODULE, WinEDA_ModuleEditFrame::Process_Special_Functions )
  31. EVT_TOOL( ID_MODEDIT_LOAD_MODULE, WinEDA_ModuleEditFrame::Process_Special_Functions )
  32. EVT_TOOL( ID_LIBEDIT_IMPORT_PART, WinEDA_ModuleEditFrame::Process_Special_Functions )
  33. EVT_TOOL( ID_LIBEDIT_EXPORT_PART, WinEDA_ModuleEditFrame::Process_Special_Functions )
  34. EVT_TOOL( ID_LIBEDIT_CREATE_NEW_LIB_AND_SAVE_CURRENT_PART,
  35. WinEDA_ModuleEditFrame::Process_Special_Functions )
  36. EVT_TOOL( ID_MODEDIT_SHEET_SET, WinEDA_ModuleEditFrame::Process_Special_Functions )
  37. EVT_TOOL( ID_GEN_PRINT, WinEDA_DrawFrame::ToPrinter )
  38. EVT_TOOL( ID_MODEDIT_LOAD_MODULE, WinEDA_ModuleEditFrame::Process_Special_Functions )
  39. EVT_TOOL( ID_MODEDIT_CHECK, WinEDA_ModuleEditFrame::Process_Special_Functions )
  40. EVT_TOOL( ID_MODEDIT_PAD_SETTINGS, WinEDA_ModuleEditFrame::Process_Special_Functions )
  41. EVT_TOOL( ID_MODEDIT_LOAD_MODULE_FROM_BOARD, WinEDA_ModuleEditFrame::Process_Special_Functions )
  42. EVT_TOOL( ID_MODEDIT_INSERT_MODULE_IN_BOARD, WinEDA_ModuleEditFrame::Process_Special_Functions )
  43. EVT_TOOL( ID_MODEDIT_UPDATE_MODULE_IN_BOARD, WinEDA_ModuleEditFrame::Process_Special_Functions )
  44. EVT_TOOL( ID_MODEDIT_EDIT_MODULE_PROPERTIES, WinEDA_ModuleEditFrame::Process_Special_Functions )
  45. EVT_TOOL( ID_MODEDIT_UNDO, WinEDA_ModuleEditFrame::Process_Special_Functions )
  46. EVT_TOOL( ID_MODEDIT_REDO, WinEDA_ModuleEditFrame::Process_Special_Functions )
  47. // Vertical toolbar (left click):
  48. EVT_TOOL( ID_NO_SELECT_BUTT, WinEDA_ModuleEditFrame::Process_Special_Functions )
  49. EVT_TOOL( ID_MODEDIT_ADD_PAD, WinEDA_ModuleEditFrame::Process_Special_Functions )
  50. EVT_TOOL( ID_PCB_ARC_BUTT, WinEDA_ModuleEditFrame::Process_Special_Functions )
  51. EVT_TOOL( ID_PCB_CIRCLE_BUTT, WinEDA_ModuleEditFrame::Process_Special_Functions )
  52. EVT_TOOL( ID_TEXT_COMMENT_BUTT, WinEDA_ModuleEditFrame::Process_Special_Functions )
  53. EVT_TOOL( ID_LINE_COMMENT_BUTT, WinEDA_ModuleEditFrame::Process_Special_Functions )
  54. EVT_TOOL( ID_MODEDIT_DELETE_ITEM_BUTT, WinEDA_ModuleEditFrame::Process_Special_Functions )
  55. EVT_TOOL( ID_MODEDIT_PLACE_ANCHOR, WinEDA_ModuleEditFrame::Process_Special_Functions )
  56. // Vertical toolbar (right click):
  57. EVT_TOOL_RCLICKED( ID_MODEDIT_ADD_PAD, WinEDA_ModuleEditFrame::ToolOnRightClick )
  58. EVT_TOOL_RCLICKED( ID_TRACK_BUTT, WinEDA_ModuleEditFrame::ToolOnRightClick )
  59. EVT_TOOL_RCLICKED( ID_PCB_CIRCLE_BUTT, WinEDA_ModuleEditFrame::ToolOnRightClick )
  60. EVT_TOOL_RCLICKED( ID_PCB_ARC_BUTT, WinEDA_ModuleEditFrame::ToolOnRightClick )
  61. EVT_TOOL_RCLICKED( ID_TEXT_COMMENT_BUTT, WinEDA_ModuleEditFrame::ToolOnRightClick )
  62. EVT_TOOL_RCLICKED( ID_LINE_COMMENT_BUTT, WinEDA_ModuleEditFrame::ToolOnRightClick )
  63. EVT_TOOL_RCLICKED( ID_PCB_COTATION_BUTT, WinEDA_ModuleEditFrame::ToolOnRightClick )
  64. // Options Toolbar
  65. EVT_TOOL_RANGE( ID_TB_OPTIONS_START, ID_TB_OPTIONS_END,
  66. WinEDA_ModuleEditFrame::OnSelectOptionToolbar )
  67. EVT_MENU_RANGE( ID_POPUP_PCB_START_RANGE, ID_POPUP_PCB_END_RANGE,
  68. WinEDA_ModuleEditFrame::Process_Special_Functions )
  69. // Annulation de commande en cours
  70. EVT_MENU_RANGE( ID_POPUP_GENERAL_START_RANGE, ID_POPUP_GENERAL_END_RANGE,
  71. WinEDA_PcbFrame::Process_Special_Functions )
  72. // Transformations du module
  73. EVT_MENU( ID_MODEDIT_MODULE_ROTATE, WinEDA_ModuleEditFrame::Process_Special_Functions )
  74. EVT_MENU( ID_MODEDIT_MODULE_MIRROR, WinEDA_ModuleEditFrame::Process_Special_Functions )
  75. EVT_MENU( ID_MODEDIT_MODULE_SCALE, WinEDA_ModuleEditFrame::Process_Special_Functions )
  76. EVT_MENU( ID_MODEDIT_MODULE_SCALEX, WinEDA_ModuleEditFrame::Process_Special_Functions )
  77. EVT_MENU( ID_MODEDIT_MODULE_SCALEY, WinEDA_ModuleEditFrame::Process_Special_Functions )
  78. EVT_MENU( ID_PCB_DRAWINGS_WIDTHS_SETUP, WinEDA_ModuleEditFrame::Process_Special_Functions )
  79. EVT_MENU( ID_PCB_PAD_SETUP, WinEDA_ModuleEditFrame::Process_Special_Functions )
  80. EVT_MENU( ID_PCB_USER_GRID_SETUP, WinEDA_PcbFrame::Process_Special_Functions )
  81. // Menu 3D Frame
  82. EVT_MENU( ID_MENU_PCB_SHOW_3D_FRAME, WinEDA_ModuleEditFrame::Show3D_Frame )
  83. // PopUp Menu Zoom trait�s dans drawpanel.cpp
  84. END_EVENT_TABLE()
  85. /****************/
  86. /* Constructeur */
  87. /****************/
  88. WinEDA_ModuleEditFrame::WinEDA_ModuleEditFrame( wxWindow* father, WinEDA_App* parent,
  89. const wxString& title,
  90. const wxPoint& pos, const wxSize& size,
  91. long style ) :
  92. WinEDA_BasePcbFrame( father, parent, MODULE_EDITOR_FRAME, wxEmptyString, pos, size, style )
  93. {
  94. m_FrameName = wxT( "ModEditFrame" );
  95. m_Draw_Axis = TRUE; // TRUE pour avoir les axes dessines
  96. m_Draw_Grid = TRUE; // TRUE pour avoir la axes dessinee
  97. m_Draw_Sheet_Ref = FALSE; // TRUE pour avoir le cartouche dessin�
  98. m_ZoomMaxValue = 1024;
  99. // Give an icon
  100. SetIcon( wxICON( icon_modedit ) );
  101. SetTitle( wxT( "Module Editor (lib: " ) + m_CurrentLib + wxT( ")" ) );
  102. if( ScreenModule == NULL )
  103. {
  104. ScreenModule = new PCB_SCREEN( PCB_FRAME );
  105. ActiveScreen = ScreenModule;
  106. }
  107. ScreenModule->m_UndoRedoCountMax = 10;
  108. if( g_ModuleEditor_Pcb == NULL )
  109. g_ModuleEditor_Pcb = new BOARD( NULL, this );
  110. m_Pcb = g_ModuleEditor_Pcb;
  111. m_Pcb->m_PcbFrame = this;
  112. m_CurrentScreen = ScreenModule;
  113. SetCurItem( NULL );
  114. GetSettings();
  115. wxSize GridSize( 500, 500 );
  116. if( m_Parent && m_Parent->m_EDA_Config )
  117. {
  118. long SizeX, SizeY;
  119. if( m_Parent->m_EDA_Config->Read( wxT( "ModEditGrid_X" ), &SizeX )
  120. && m_Parent->m_EDA_Config->Read( wxT( "ModEditGrid_Y" ), &SizeY ) )
  121. {
  122. GridSize.x = SizeX;
  123. GridSize.y = SizeY;
  124. }
  125. }
  126. GetScreen()->SetGrid( GridSize );
  127. SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
  128. ReCreateMenuBar();
  129. ReCreateHToolbar();
  130. ReCreateAuxiliaryToolbar();
  131. ReCreateVToolbar();
  132. ReCreateOptToolbar();
  133. if( DrawPanel )
  134. DrawPanel->m_Block_Enable = TRUE;
  135. }
  136. /****************************************************/
  137. WinEDA_ModuleEditFrame::~WinEDA_ModuleEditFrame()
  138. /****************************************************/
  139. {
  140. m_Parent->m_ModuleEditFrame = NULL;
  141. m_CurrentScreen = ScreenPcb;
  142. }
  143. /**************************************************************/
  144. void WinEDA_ModuleEditFrame::OnCloseWindow( wxCloseEvent& Event )
  145. /**************************************************************/
  146. {
  147. if( GetScreen()->IsModify() )
  148. {
  149. if( !IsOK( this, _( "Module Editor: module modified!, Continue ?" ) ) )
  150. {
  151. Event.Veto(); return;
  152. }
  153. }
  154. SaveSettings();
  155. if( m_Parent && m_Parent->m_EDA_Config )
  156. {
  157. wxSize GridSize = GetScreen()->GetGrid();
  158. m_Parent->m_EDA_Config->Write( wxT( "ModEditGrid_X" ), (long) GridSize.x );
  159. m_Parent->m_EDA_Config->Write( wxT( "ModEditGrid_Y" ), (long) GridSize.y );
  160. }
  161. Destroy();
  162. }
  163. /*********************************************/
  164. void WinEDA_ModuleEditFrame::SetToolbars()
  165. /*********************************************/
  166. {
  167. bool active, islib = TRUE;
  168. if( m_HToolBar == NULL )
  169. return;
  170. if( m_CurrentLib == wxEmptyString )
  171. islib = FALSE;
  172. m_HToolBar->EnableTool( ID_MODEDIT_SAVE_LIBMODULE, islib );
  173. m_HToolBar->EnableTool( ID_LIBEDIT_DELETE_PART, islib );
  174. if( m_Pcb->m_Modules == NULL )
  175. active = FALSE;
  176. else
  177. active = TRUE;
  178. m_HToolBar->EnableTool( ID_LIBEDIT_EXPORT_PART, active );
  179. m_HToolBar->EnableTool( ID_LIBEDIT_CREATE_NEW_LIB_AND_SAVE_CURRENT_PART, active );
  180. m_HToolBar->EnableTool( ID_MODEDIT_SAVE_LIBMODULE, active && islib );
  181. MODULE* module_in_edit = m_Pcb->m_Modules;
  182. if( module_in_edit && module_in_edit->m_Link ) // this is not a new module ...
  183. {
  184. WinEDA_PcbFrame* pcbframe = m_Parent->m_PcbFrame;
  185. BOARD* mainpcb = pcbframe->m_Pcb;
  186. MODULE* source_module = mainpcb->m_Modules;
  187. // search if the source module was not deleted:
  188. for( ; source_module != NULL; source_module = (MODULE*) source_module->Pnext )
  189. {
  190. if( module_in_edit->m_Link == source_module->m_TimeStamp )
  191. break;
  192. }
  193. if( source_module )
  194. {
  195. m_HToolBar->EnableTool( ID_MODEDIT_INSERT_MODULE_IN_BOARD, false );
  196. m_HToolBar->EnableTool( ID_MODEDIT_UPDATE_MODULE_IN_BOARD, true );
  197. }
  198. else // The source was deleted, therefore we can insert but not update the module
  199. {
  200. m_HToolBar->EnableTool( ID_MODEDIT_INSERT_MODULE_IN_BOARD, true );
  201. m_HToolBar->EnableTool( ID_MODEDIT_UPDATE_MODULE_IN_BOARD, false );
  202. }
  203. }
  204. else
  205. {
  206. m_HToolBar->EnableTool( ID_MODEDIT_INSERT_MODULE_IN_BOARD, active );
  207. m_HToolBar->EnableTool( ID_MODEDIT_UPDATE_MODULE_IN_BOARD, false );
  208. }
  209. if( GetScreen() )
  210. {
  211. m_HToolBar->EnableTool( ID_MODEDIT_UNDO, GetScreen()->m_UndoList && active );
  212. m_HToolBar->EnableTool( ID_MODEDIT_REDO, GetScreen()->m_RedoList && active );
  213. }
  214. if( m_Parent->m_PcbFrame->m_Pcb->m_Modules )
  215. {
  216. m_HToolBar->EnableTool( ID_MODEDIT_LOAD_MODULE_FROM_BOARD, TRUE );
  217. }
  218. else
  219. {
  220. m_HToolBar->EnableTool( ID_MODEDIT_LOAD_MODULE_FROM_BOARD, FALSE );
  221. }
  222. if( m_VToolBar )
  223. {
  224. m_VToolBar->EnableTool( ID_MODEDIT_ADD_PAD, active );
  225. m_VToolBar->EnableTool( ID_LINE_COMMENT_BUTT, active );
  226. m_VToolBar->EnableTool( ID_PCB_CIRCLE_BUTT, active );
  227. m_VToolBar->EnableTool( ID_PCB_ARC_BUTT, active );
  228. m_VToolBar->EnableTool( ID_TEXT_COMMENT_BUTT, active );
  229. m_VToolBar->EnableTool( ID_MODEDIT_PLACE_ANCHOR, active );
  230. m_VToolBar->EnableTool( ID_PCB_DELETE_ITEM_BUTT, active );
  231. }
  232. if( m_OptionsToolBar )
  233. {
  234. m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SELECT_UNIT_MM,
  235. g_UnitMetric == MILLIMETRE ? TRUE : FALSE );
  236. m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SELECT_UNIT_INCH,
  237. g_UnitMetric == INCHES ? TRUE : FALSE );
  238. m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_POLAR_COORD,
  239. DisplayOpt.DisplayPolarCood );
  240. m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_GRID,
  241. m_Draw_Grid );
  242. m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SELECT_CURSOR,
  243. g_CursorShape );
  244. m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_PADS_SKETCH,
  245. !m_DisplayPadFill );
  246. }
  247. if( m_AuxiliaryToolBar )
  248. {
  249. int ii, jj;
  250. if( m_SelZoomBox )
  251. {
  252. int old_choice = m_SelZoomBox->GetChoice();
  253. int new_choice = 1;
  254. int zoom;
  255. for( jj = 1, zoom = 1; zoom <= m_ZoomMaxValue; zoom <<= 1, jj++ )
  256. {
  257. if( m_CurrentScreen && (m_CurrentScreen->GetZoom() == zoom) )
  258. break;
  259. new_choice++;
  260. }
  261. if( old_choice != new_choice )
  262. m_SelZoomBox->SetSelection( new_choice );
  263. }
  264. if( m_SelGridBox && GetScreen() )
  265. {
  266. int kk = m_SelGridBox->GetChoice();
  267. for( ii = 0; g_GridList[ii].x > 0; ii++ )
  268. {
  269. if( !GetScreen()->m_UserGridIsON
  270. && (GetScreen()->GetGrid().x == g_GridList[ii].x)
  271. && (GetScreen()->GetGrid().y == g_GridList[ii].y) )
  272. {
  273. if( kk != ii )
  274. m_SelGridBox->SetSelection( ii );
  275. kk = ii;
  276. break;
  277. }
  278. }
  279. if( kk != ii )
  280. m_SelGridBox->SetSelection( ii );/* User Grid */
  281. }
  282. }
  283. DisplayUnitsMsg();
  284. }