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.

316 lines
9.7 KiB

  1. /******************************************************************/
  2. /* schframe.cpp - fonctions des classes du type WinEDA_DrawFrame */
  3. /******************************************************************/
  4. #ifdef __GNUG__
  5. #pragma implementation
  6. #endif
  7. #include "fctsys.h"
  8. #include "common.h"
  9. #include "program.h"
  10. #include "libcmp.h"
  11. #include "general.h"
  12. #include "bitmaps.h"
  13. #include "protos.h"
  14. #include "id.h"
  15. /*******************************/
  16. /* class WinEDA_SchematicFrame */
  17. /*******************************/
  18. BEGIN_EVENT_TABLE(WinEDA_SchematicFrame, wxFrame)
  19. COMMON_EVENTS_DRAWFRAME
  20. EVT_SOCKET(ID_EDA_SOCKET_EVENT_SERV, WinEDA_DrawFrame::OnSockRequestServer)
  21. EVT_SOCKET(ID_EDA_SOCKET_EVENT, WinEDA_DrawFrame::OnSockRequest)
  22. EVT_CLOSE(WinEDA_SchematicFrame::OnCloseWindow)
  23. EVT_SIZE(WinEDA_SchematicFrame::OnSize)
  24. EVT_MENU_RANGE(ID_LOAD_PROJECT,ID_LOAD_FILE_10,
  25. WinEDA_SchematicFrame::Process_Special_Functions)
  26. EVT_TOOL(ID_NEW_PROJECT, WinEDA_SchematicFrame::Process_Special_Functions)
  27. EVT_TOOL(ID_LOAD_PROJECT, WinEDA_SchematicFrame::Process_Special_Functions)
  28. EVT_TOOL_RANGE(ID_SCHEMATIC_MAIN_TOOLBAR_START, ID_SCHEMATIC_MAIN_TOOLBAR_END,
  29. WinEDA_SchematicFrame::Process_Special_Functions)
  30. EVT_MENU_RANGE(ID_PREFERENCES_FONT_INFOSCREEN, ID_PREFERENCES_FONT_END,
  31. WinEDA_DrawFrame::ProcessFontPreferences)
  32. EVT_MENU(ID_SAVE_PROJECT, WinEDA_SchematicFrame::Save_File)
  33. EVT_MENU(ID_SAVE_ONE_SHEET, WinEDA_SchematicFrame::Save_File)
  34. EVT_MENU(ID_SAVE_ONE_SHEET_AS, WinEDA_SchematicFrame::Save_File)
  35. EVT_TOOL(ID_SAVE_PROJECT, WinEDA_SchematicFrame::Save_File)
  36. EVT_MENU(ID_GEN_PRINT, WinEDA_SchematicFrame::ToPrinter)
  37. EVT_MENU(ID_GEN_PLOT_PS, WinEDA_SchematicFrame::ToPlot_PS)
  38. EVT_MENU(ID_GEN_PLOT_HPGL, WinEDA_SchematicFrame::ToPlot_HPGL)
  39. EVT_MENU(ID_GEN_PLOT_SVG, WinEDA_DrawFrame::SVG_Print)
  40. EVT_MENU(ID_GEN_COPY_SHEET_TO_CLIPBOARD, WinEDA_DrawFrame::CopyToClipboard)
  41. EVT_MENU(ID_GEN_COPY_BLOCK_TO_CLIPBOARD, WinEDA_DrawFrame::CopyToClipboard)
  42. EVT_MENU(ID_EXIT, WinEDA_SchematicFrame::Process_Special_Functions)
  43. EVT_MENU_RANGE(ID_CONFIG_AND_PREFERENCES_START, ID_CONFIG_AND_PREFERENCES_END, WinEDA_SchematicFrame::Process_Config)
  44. EVT_TOOL(ID_COLORS_SETUP, WinEDA_SchematicFrame::Process_Config)
  45. EVT_TOOL(ID_OPTIONS_SETUP, WinEDA_SchematicFrame::Process_Config)
  46. EVT_MENU_RANGE(ID_LANGUAGE_CHOICE, ID_LANGUAGE_CHOICE_END,
  47. WinEDA_DrawFrame::SetLanguage)
  48. EVT_TOOL_RANGE(ID_ZOOM_PLUS_BUTT, ID_ZOOM_PAGE_BUTT,
  49. WinEDA_SchematicFrame::Process_Zoom)
  50. EVT_TOOL(ID_NEW_PROJECT, WinEDA_SchematicFrame::Process_Special_Functions)
  51. EVT_TOOL(ID_LOAD_PROJECT, WinEDA_SchematicFrame::Process_Special_Functions)
  52. EVT_TOOL(ID_TO_LIBRARY, WinEDA_SchematicFrame::Process_Special_Functions)
  53. EVT_TOOL(ID_TO_LIBVIEW, WinEDA_SchematicFrame::Process_Special_Functions)
  54. EVT_TOOL(ID_TO_PCB, WinEDA_SchematicFrame::Process_Special_Functions)
  55. EVT_TOOL(ID_TO_CVPCB, WinEDA_SchematicFrame::Process_Special_Functions)
  56. EVT_TOOL(ID_SHEET_SET, WinEDA_DrawFrame::Process_PageSettings)
  57. EVT_TOOL(ID_HIERARCHY, WinEDA_SchematicFrame::Process_Special_Functions)
  58. EVT_TOOL(wxID_CUT, WinEDA_SchematicFrame::Process_Special_Functions)
  59. EVT_TOOL(wxID_COPY, WinEDA_SchematicFrame::Process_Special_Functions)
  60. EVT_TOOL(wxID_PASTE, WinEDA_SchematicFrame::Process_Special_Functions)
  61. EVT_TOOL(ID_UNDO_BUTT, WinEDA_SchematicFrame::Process_Special_Functions)
  62. EVT_TOOL(ID_GEN_PRINT, WinEDA_SchematicFrame::ToPrinter)
  63. EVT_TOOL_RANGE(ID_GET_ANNOTATE,ID_FIND_ITEMS,
  64. WinEDA_SchematicFrame::Process_Special_Functions)
  65. EVT_MENU(ID_GENERAL_HELP, WinEDA_DrawFrame::GetKicadHelp)
  66. EVT_MENU(ID_KICAD_ABOUT, WinEDA_DrawFrame::GetKicadAbout)
  67. // Tools et boutons de Schematique, Vertical toolbar:
  68. EVT_TOOL_RANGE(ID_SCHEMATIC_VERTICAL_TOOLBAR_START,
  69. ID_SCHEMATIC_VERTICAL_TOOLBAR_END,
  70. WinEDA_SchematicFrame::Process_Special_Functions)
  71. EVT_TOOL_RCLICKED(ID_LABEL_BUTT, WinEDA_SchematicFrame::ToolOnRightClick)
  72. EVT_TOOL_RCLICKED(ID_GLABEL_BUTT, WinEDA_SchematicFrame::ToolOnRightClick)
  73. EVT_MENU_RANGE(ID_POPUP_START_RANGE, ID_POPUP_END_RANGE,
  74. WinEDA_SchematicFrame::Process_Special_Functions )
  75. // Tools et boutons de Schematique, Options toolbar:
  76. EVT_TOOL_RANGE(ID_TB_OPTIONS_START,ID_TB_OPTIONS_END,
  77. WinEDA_SchematicFrame::OnSelectOptionToolbar)
  78. EVT_MENU_RANGE(ID_POPUP_GENERAL_START_RANGE, ID_POPUP_GENERAL_END_RANGE,
  79. WinEDA_SchematicFrame::Process_Special_Functions )
  80. END_EVENT_TABLE()
  81. /****************/
  82. /* Constructor */
  83. /****************/
  84. WinEDA_SchematicFrame:: WinEDA_SchematicFrame(wxWindow * father, WinEDA_App *parent,
  85. const wxString & title, const wxPoint& pos, const wxSize& size, long style) :
  86. WinEDA_DrawFrame(father, SCHEMATIC_FRAME, parent, title, pos, size, style)
  87. {
  88. m_FrameName = wxT("SchematicFrame");
  89. m_Draw_Axis = FALSE; // TRUE to show axis
  90. m_Draw_Grid = g_ShowGrid; // TRUE to show a grid
  91. m_Draw_Sheet_Ref = TRUE; // TRUE to show sheet references
  92. // Give an icon
  93. #ifdef __WINDOWS__
  94. SetIcon(wxICON(a_icon_eeschema));
  95. #else
  96. SetIcon(wxICON(icon_eeschema));
  97. #endif
  98. m_CurrentScreen = ScreenSch;
  99. g_ItemToRepeat = NULL;
  100. /* Get config */
  101. GetSettings();
  102. g_DrawMinimunLineWidth = m_Parent->m_EDA_Config->Read(MINI_DRAW_LINE_WIDTH_KEY, (long)0);
  103. g_PlotPSMinimunLineWidth = m_Parent->m_EDA_Config->Read(MINI_PLOTPS_LINE_WIDTH_KEY, (long) 4);
  104. /****/
  105. SetSize(m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y);
  106. if ( DrawPanel ) DrawPanel->m_Block_Enable = TRUE;
  107. ReCreateMenuBar();
  108. ReCreateHToolbar();
  109. ReCreateVToolbar();
  110. ReCreateOptToolbar();
  111. }
  112. /***************/
  113. /* Destructor */
  114. /***************/
  115. WinEDA_SchematicFrame::~WinEDA_SchematicFrame()
  116. {
  117. m_Parent->m_SchematicFrame = NULL;
  118. m_CurrentScreen = ScreenSch;
  119. }
  120. /**************************************************************/
  121. void WinEDA_SchematicFrame::OnCloseWindow(wxCloseEvent & Event)
  122. /**************************************************************/
  123. {
  124. SCH_SCREEN * screen;
  125. if ( m_Parent->m_LibeditFrame ) // Can close component editor ?
  126. {
  127. if ( ! m_Parent->m_LibeditFrame->Close() ) return;
  128. }
  129. screen = ScreenSch ;
  130. while( screen )
  131. {
  132. if(screen->IsModify()) break;
  133. screen = (SCH_SCREEN*)screen->Pnext;
  134. }
  135. if ( screen )
  136. {
  137. unsigned ii;
  138. wxMessageDialog dialog(this, _("Schematic modified, Save before exit ?"),
  139. _("Confirmation"), wxYES_NO | wxCANCEL | wxICON_EXCLAMATION | wxYES_DEFAULT);
  140. ii = dialog.ShowModal();
  141. switch ( ii )
  142. {
  143. case wxID_CANCEL:
  144. Event.Veto();
  145. return;
  146. case wxID_NO:
  147. break;
  148. case wxID_OK:
  149. case wxID_YES:
  150. SaveProject(this);
  151. break;
  152. }
  153. }
  154. screen = ScreenSch ;
  155. while( screen ) // Clear "flag modify" to avoid alert messages when closing sub sheets
  156. {
  157. screen->ClrModify();
  158. screen = (SCH_SCREEN*)screen->Pnext;
  159. }
  160. if ( ! ScreenSch->m_FileName.IsEmpty() && (ScreenSch->EEDrawList != NULL) )
  161. SetLastProject(ScreenSch->m_FileName);
  162. ClearProjectDrawList(ScreenSch, TRUE);
  163. /* allof sub sheets are deleted, only the main sheet is useable */
  164. m_CurrentScreen = ActiveScreen = ScreenSch;
  165. SaveSettings();
  166. m_Parent->m_EDA_Config->Write(MINI_DRAW_LINE_WIDTH_KEY, (long)g_DrawMinimunLineWidth);
  167. m_Parent->m_EDA_Config->Write(MINI_PLOTPS_LINE_WIDTH_KEY, (long) g_PlotPSMinimunLineWidth);
  168. Destroy();
  169. }
  170. /********************************************/
  171. void WinEDA_SchematicFrame::SetToolbars()
  172. /********************************************/
  173. /* Enable or disable some tools according to current conditions
  174. */
  175. {
  176. if( m_HToolBar )
  177. {
  178. if ( m_CurrentScreen->BlockLocate.m_Command == BLOCK_MOVE )
  179. {
  180. m_HToolBar->EnableTool(wxID_CUT,TRUE);
  181. m_HToolBar->EnableTool(wxID_COPY,TRUE);
  182. }
  183. else
  184. {
  185. m_HToolBar->EnableTool(wxID_CUT,FALSE);
  186. m_HToolBar->EnableTool(wxID_COPY,FALSE);
  187. }
  188. if ( g_BlockSaveDataList ) m_HToolBar->EnableTool(wxID_PASTE,TRUE);
  189. else m_HToolBar->EnableTool(wxID_PASTE,FALSE);
  190. wxMenuBar * menuBar = GetMenuBar();
  191. if ( GetScreen()->m_RedoList )
  192. {
  193. m_HToolBar->EnableTool(ID_SCHEMATIC_REDO,TRUE);
  194. menuBar->Enable(ID_SCHEMATIC_REDO,TRUE);
  195. }
  196. else
  197. {
  198. m_HToolBar->EnableTool(ID_SCHEMATIC_REDO,FALSE);
  199. menuBar->Enable(ID_SCHEMATIC_REDO,FALSE);
  200. }
  201. if ( GetScreen()->m_UndoList )
  202. {
  203. m_HToolBar->EnableTool(ID_SCHEMATIC_UNDO,TRUE);
  204. menuBar->Enable(ID_SCHEMATIC_UNDO,TRUE);
  205. }
  206. else
  207. {
  208. m_HToolBar->EnableTool(ID_SCHEMATIC_UNDO,FALSE);
  209. menuBar->Enable(ID_SCHEMATIC_UNDO,FALSE);
  210. }
  211. }
  212. if ( m_OptionsToolBar )
  213. {
  214. m_OptionsToolBar->ToggleTool(ID_TB_OPTIONS_SHOW_GRID,m_Draw_Grid);
  215. m_OptionsToolBar->SetToolShortHelp(ID_TB_OPTIONS_SHOW_GRID,
  216. m_Draw_Grid ? _("Grid not show") : _("Show Grid"));
  217. m_OptionsToolBar->ToggleTool(ID_TB_OPTIONS_SELECT_UNIT_MM,
  218. g_UnitMetric == MILLIMETRE ? TRUE : FALSE);
  219. m_OptionsToolBar->ToggleTool(ID_TB_OPTIONS_SELECT_UNIT_INCH,
  220. g_UnitMetric == INCHES ? TRUE : FALSE);
  221. m_OptionsToolBar->ToggleTool(ID_TB_OPTIONS_SELECT_CURSOR,g_CursorShape);
  222. m_OptionsToolBar->ToggleTool(ID_TB_OPTIONS_HIDDEN_PINS,g_ShowAllPins);
  223. m_OptionsToolBar->SetToolShortHelp(ID_TB_OPTIONS_HIDDEN_PINS,
  224. g_ShowAllPins ? _("No show Hidden Pins") : _("Show Hidden Pins") );
  225. m_OptionsToolBar->ToggleTool(ID_TB_OPTIONS_BUS_WIRES_ORIENT, g_HVLines);
  226. m_OptionsToolBar->SetToolShortHelp(ID_TB_OPTIONS_BUS_WIRES_ORIENT,
  227. g_HVLines ? _("Draw lines at any direction") :
  228. _("Draw lines H, V or 45 deg only") );
  229. }
  230. DisplayUnitsMsg();
  231. }
  232. /******************************************/
  233. int WinEDA_SchematicFrame::BestZoom()
  234. /******************************************/
  235. {
  236. int dx, dy, ii,jj ;
  237. int bestzoom;
  238. wxSize size;
  239. dx = m_CurrentScreen->m_CurrentSheet->m_Size.x;
  240. dy = m_CurrentScreen->m_CurrentSheet->m_Size.y;
  241. size = DrawPanel->GetClientSize();
  242. ii = dx / size.x;
  243. jj = dy / size.y;
  244. bestzoom = MAX(ii, jj) + 1;
  245. m_CurrentScreen->SetZoom(ii);
  246. m_CurrentScreen->m_Curseur.x = dx / 2;
  247. m_CurrentScreen->m_Curseur.y = dy / 2;
  248. return(bestzoom);
  249. }