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.

481 lines
14 KiB

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
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
18 years ago
18 years ago
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: plotps.cpp
  3. // Purpose:
  4. // Author: jean-pierre Charras
  5. // Modified by:
  6. // Created: 01/02/2006 08:37:24
  7. // RCS-ID:
  8. // Copyright: GNU License
  9. // License:
  10. /////////////////////////////////////////////////////////////////////////////
  11. // Generated by DialogBlocks (unregistered), 01/02/2006 08:37:24
  12. #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
  13. #pragma implementation "plotps.h"
  14. #endif
  15. #include "fctsys.h"
  16. #include "gr_basic.h"
  17. #include "common.h"
  18. #include "confirm.h"
  19. #include "worksheet.h"
  20. #include "plot_common.h"
  21. #include "program.h"
  22. #include "general.h"
  23. #include "protos.h"
  24. enum PageFormatReq {
  25. PAGE_SIZE_AUTO,
  26. PAGE_SIZE_A4,
  27. PAGE_SIZE_A
  28. };
  29. /* Variables locales : */
  30. static int PS_SizeSelect = PAGE_SIZE_AUTO;
  31. static bool Plot_Sheet_Ref = TRUE;
  32. #include "plotps.h"
  33. ////@begin XPM images
  34. ////@end XPM images
  35. void WinEDA_SchematicFrame::ToPlot_PS( wxCommandEvent& event )
  36. {
  37. wxPoint pos;
  38. pos = GetPosition();
  39. pos.x += 10;
  40. pos.y += 20;
  41. WinEDA_PlotPSFrame* Ps_frame = new WinEDA_PlotPSFrame( this );
  42. Ps_frame->ShowModal();
  43. Ps_frame->Destroy();
  44. }
  45. /*!
  46. * WinEDA_PlotPSFrame type definition
  47. */
  48. IMPLEMENT_DYNAMIC_CLASS( WinEDA_PlotPSFrame, wxDialog )
  49. /*!
  50. * WinEDA_PlotPSFrame event table definition
  51. */
  52. BEGIN_EVENT_TABLE( WinEDA_PlotPSFrame, wxDialog )
  53. ////@begin WinEDA_PlotPSFrame event table entries
  54. EVT_BUTTON( ID_PLOT_PS_CURRENT_EXECUTE,
  55. WinEDA_PlotPSFrame::OnPlotPsCurrentExecuteClick )
  56. EVT_BUTTON( ID_PLOT_PS_ALL_EXECUTE,
  57. WinEDA_PlotPSFrame::OnPlotPsAllExecuteClick )
  58. EVT_BUTTON( wxID_CANCEL, WinEDA_PlotPSFrame::OnCancelClick )
  59. ////@end WinEDA_PlotPSFrame event table entries
  60. END_EVENT_TABLE()
  61. /*!
  62. * WinEDA_PlotPSFrame constructors
  63. */
  64. WinEDA_PlotPSFrame::WinEDA_PlotPSFrame()
  65. {
  66. }
  67. WinEDA_PlotPSFrame::WinEDA_PlotPSFrame( WinEDA_DrawFrame* parent,
  68. wxWindowID id,
  69. const wxString& caption,
  70. const wxPoint& pos,
  71. const wxSize& size,
  72. long style )
  73. {
  74. m_Parent = parent;
  75. PlotPSColorOpt = false;
  76. Create( parent, id, caption, pos, size, style );
  77. }
  78. /*!
  79. * WinEDA_PlotPSFrame creator
  80. */
  81. bool WinEDA_PlotPSFrame::Create( wxWindow* parent,
  82. wxWindowID id,
  83. const wxString& caption,
  84. const wxPoint& pos,
  85. const wxSize& size,
  86. long style )
  87. {
  88. ////@begin WinEDA_PlotPSFrame member initialization
  89. m_SizeOption = NULL;
  90. m_PlotPSColorOption = NULL;
  91. m_Plot_Sheet_Ref = NULL;
  92. m_btClose = NULL;
  93. m_DefaultLineSizeCtrlSizer = NULL;
  94. m_MsgBox = NULL;
  95. ////@end WinEDA_PlotPSFrame member initialisation
  96. ////@begin WinEDA_PlotPSFrame creation
  97. SetExtraStyle( wxWS_EX_BLOCK_EVENTS );
  98. wxDialog::Create( parent, id, caption, pos, size, style );
  99. CreateControls();
  100. if( GetSizer() )
  101. {
  102. GetSizer()->SetSizeHints( this );
  103. }
  104. Centre();
  105. ////@end WinEDA_PlotPSFrame creation
  106. return true;
  107. }
  108. /*!
  109. * Control creation for WinEDA_PlotPSFrame
  110. */
  111. void WinEDA_PlotPSFrame::CreateControls()
  112. {
  113. ////@begin WinEDA_PlotPSFrame content construction
  114. // Generated by DialogBlocks, 24/04/2009 14:25:24 (unregistered)
  115. WinEDA_PlotPSFrame* itemDialog1 = this;
  116. wxBoxSizer* itemBoxSizer2 = new wxBoxSizer( wxVERTICAL );
  117. itemDialog1->SetSizer( itemBoxSizer2 );
  118. wxBoxSizer* itemBoxSizer3 = new wxBoxSizer( wxHORIZONTAL );
  119. itemBoxSizer2->Add( itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5 );
  120. wxArrayString m_SizeOptionStrings;
  121. m_SizeOptionStrings.Add( _( "Auto" ) );
  122. m_SizeOptionStrings.Add( _( "Page Size A4" ) );
  123. m_SizeOptionStrings.Add( _( "Page Size A" ) );
  124. m_SizeOption =
  125. new wxRadioBox( itemDialog1, ID_RADIOBOX1, _( "Plot page size:" ),
  126. wxDefaultPosition, wxDefaultSize, m_SizeOptionStrings,
  127. 1, wxRA_SPECIFY_COLS );
  128. m_SizeOption->SetSelection( 0 );
  129. itemBoxSizer3->Add( m_SizeOption, 0, wxGROW | wxALL, 5 );
  130. itemBoxSizer3->Add( 5, 5, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
  131. wxStaticBox* itemStaticBoxSizer6Static =
  132. new wxStaticBox( itemDialog1, wxID_ANY, _( "Plot Options:" ) );
  133. wxStaticBoxSizer* itemStaticBoxSizer6 =
  134. new wxStaticBoxSizer( itemStaticBoxSizer6Static, wxVERTICAL );
  135. itemBoxSizer3->Add( itemStaticBoxSizer6,
  136. 0,
  137. wxALIGN_CENTER_VERTICAL | wxALL,
  138. 5 );
  139. wxArrayString m_PlotPSColorOptionStrings;
  140. m_PlotPSColorOptionStrings.Add( _( "B/W" ) );
  141. m_PlotPSColorOptionStrings.Add( _( "Color" ) );
  142. m_PlotPSColorOption =
  143. new wxRadioBox( itemDialog1, ID_RADIOBOX, _( "Plot Color:" ),
  144. wxDefaultPosition, wxDefaultSize,
  145. m_PlotPSColorOptionStrings, 1, wxRA_SPECIFY_COLS );
  146. m_PlotPSColorOption->SetSelection( 0 );
  147. itemStaticBoxSizer6->Add( m_PlotPSColorOption, 0, wxGROW | wxALL, 5 );
  148. m_Plot_Sheet_Ref =
  149. new wxCheckBox( itemDialog1, ID_CHECKBOX, _( "Print Sheet Ref" ),
  150. wxDefaultPosition, wxDefaultSize, wxCHK_2STATE );
  151. m_Plot_Sheet_Ref->SetValue( false );
  152. itemStaticBoxSizer6->Add( m_Plot_Sheet_Ref, 0, wxGROW | wxALL, 5 );
  153. itemBoxSizer3->Add( 5, 5, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
  154. wxBoxSizer* itemBoxSizer10 = new wxBoxSizer( wxVERTICAL );
  155. itemBoxSizer3->Add( itemBoxSizer10, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
  156. wxButton* itemButton11 = new wxButton( itemDialog1,
  157. ID_PLOT_PS_CURRENT_EXECUTE,
  158. _( "&Plot Page" ),
  159. wxDefaultPosition,
  160. wxDefaultSize,
  161. 0 );
  162. itemButton11->SetDefault();
  163. itemBoxSizer10->Add( itemButton11, 0, wxGROW | wxALL, 5 );
  164. wxButton* itemButton12 = new wxButton( itemDialog1,
  165. ID_PLOT_PS_ALL_EXECUTE,
  166. _( "Plot A&LL" ),
  167. wxDefaultPosition,
  168. wxDefaultSize,
  169. 0 );
  170. itemBoxSizer10->Add( itemButton12, 0, wxGROW | wxALL, 5 );
  171. m_btClose = new wxButton( itemDialog1, wxID_CANCEL, _( "Close" ),
  172. wxDefaultPosition, wxDefaultSize, 0 );
  173. itemBoxSizer10->Add( m_btClose, 0, wxGROW | wxALL, 5 );
  174. m_DefaultLineSizeCtrlSizer = new wxBoxSizer( wxVERTICAL );
  175. itemBoxSizer2->Add( m_DefaultLineSizeCtrlSizer, 0, wxGROW | wxALL, 5 );
  176. wxStaticText* itemStaticText15 = new wxStaticText( itemDialog1,
  177. wxID_STATIC,
  178. _( "Messages :" ),
  179. wxDefaultPosition,
  180. wxDefaultSize,
  181. 0 );
  182. itemBoxSizer2->Add( itemStaticText15,
  183. 0,
  184. wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP |
  185. wxADJUST_MINSIZE,
  186. 5 );
  187. m_MsgBox = new wxTextCtrl( itemDialog1, ID_TEXTCTRL, _T( "" ),
  188. wxDefaultPosition, wxSize( -1, 200 ),
  189. wxTE_MULTILINE );
  190. itemBoxSizer2->Add( m_MsgBox, 0, wxGROW | wxALL | wxFIXED_MINSIZE, 5 );
  191. // Set validators
  192. m_SizeOption->SetValidator( wxGenericValidator( &PS_SizeSelect ) );
  193. m_PlotPSColorOption->SetValidator( wxGenericValidator( &PlotPSColorOpt ) );
  194. m_Plot_Sheet_Ref->SetValidator( wxGenericValidator( &Plot_Sheet_Ref ) );
  195. ////@end WinEDA_PlotPSFrame content construction
  196. SetFocus(); // make the ESC work
  197. m_DefaultLineSizeCtrl = new WinEDA_ValueCtrl( this,
  198. _( "Default Line Width" ),
  199. g_DrawDefaultLineThickness,
  200. g_UnitMetric,
  201. m_DefaultLineSizeCtrlSizer,
  202. EESCHEMA_INTERNAL_UNIT );
  203. }
  204. /*!
  205. * Should we show tooltips?
  206. */
  207. bool WinEDA_PlotPSFrame::ShowToolTips()
  208. {
  209. return true;
  210. }
  211. /*!
  212. * Get bitmap resources
  213. */
  214. wxBitmap WinEDA_PlotPSFrame::GetBitmapResource( const wxString& name )
  215. {
  216. // Bitmap retrieval
  217. ////@begin WinEDA_PlotPSFrame bitmap retrieval
  218. wxUnusedVar( name );
  219. return wxNullBitmap;
  220. ////@end WinEDA_PlotPSFrame bitmap retrieval
  221. }
  222. /*!
  223. * Get icon resources
  224. */
  225. wxIcon WinEDA_PlotPSFrame::GetIconResource( const wxString& name )
  226. {
  227. // Icon retrieval
  228. ////@begin WinEDA_PlotPSFrame icon retrieval
  229. wxUnusedVar( name );
  230. return wxNullIcon;
  231. ////@end WinEDA_PlotPSFrame icon retrieval
  232. }
  233. /*!
  234. * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON
  235. */
  236. void WinEDA_PlotPSFrame::OnPlotPsCurrentExecuteClick( wxCommandEvent& event )
  237. {
  238. int Select_PlotAll = FALSE;
  239. InitOptVars();
  240. CreatePSFile( Select_PlotAll, PS_SizeSelect );
  241. m_MsgBox->AppendText( wxT( "*****\n" ) );
  242. }
  243. /*!
  244. * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON1
  245. */
  246. void WinEDA_PlotPSFrame::OnPlotPsAllExecuteClick( wxCommandEvent& event )
  247. {
  248. int Select_PlotAll = TRUE;
  249. InitOptVars();
  250. CreatePSFile( Select_PlotAll, PS_SizeSelect );
  251. m_MsgBox->AppendText( wxT( "*****\n" ) );
  252. }
  253. /*!
  254. * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CANCEL
  255. */
  256. void WinEDA_PlotPSFrame::OnCancelClick( wxCommandEvent& event )
  257. {
  258. InitOptVars();
  259. EndModal( 0 );
  260. }
  261. void WinEDA_PlotPSFrame::InitOptVars()
  262. {
  263. Plot_Sheet_Ref = m_Plot_Sheet_Ref->GetValue();
  264. PlotPSColorOpt = m_PlotPSColorOption->GetSelection();
  265. PS_SizeSelect = m_SizeOption->GetSelection();
  266. g_DrawDefaultLineThickness = m_DefaultLineSizeCtrl->GetValue();
  267. if( g_DrawDefaultLineThickness < 1 )
  268. g_DrawDefaultLineThickness = 1;
  269. }
  270. void WinEDA_PlotPSFrame::CreatePSFile( int AllPages, int pagesize )
  271. {
  272. WinEDA_SchematicFrame* schframe = (WinEDA_SchematicFrame*) m_Parent;
  273. SCH_SCREEN* screen = schframe->GetScreen();
  274. SCH_SCREEN* oldscreen = screen;
  275. SCH_SHEET_PATH* sheetpath, * oldsheetpath = schframe->GetSheet();
  276. wxString PlotFileName;
  277. Ki_PageDescr* PlotSheet, * RealSheet;
  278. wxPoint plot_offset;
  279. /* When printing all pages, the printed page is not the current page.
  280. * In complex hierarchies, we must setup references and others parameters
  281. * in the printed SCH_SCREEN
  282. * because in complex hierarchies a SCH_SCREEN (a schematic drawings)
  283. * is shared between many sheets
  284. */
  285. SCH_SHEET_LIST SheetList( NULL );
  286. sheetpath = SheetList.GetFirst();
  287. SCH_SHEET_PATH list;
  288. while( true )
  289. {
  290. if( AllPages )
  291. {
  292. if( sheetpath == NULL )
  293. break;
  294. list.Clear();
  295. if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) )
  296. {
  297. schframe->m_CurrentSheet = &list;
  298. schframe->m_CurrentSheet->UpdateAllScreenReferences();
  299. schframe->SetSheetNumberAndCount();
  300. screen = schframe->m_CurrentSheet->LastScreen();
  301. ActiveScreen = screen;
  302. }
  303. else // Should not happen
  304. return;
  305. sheetpath = SheetList.GetNext();
  306. }
  307. PlotSheet = screen->m_CurrentSheetDesc;
  308. switch( pagesize )
  309. {
  310. case PAGE_SIZE_A:
  311. RealSheet = &g_Sheet_A;
  312. break;
  313. case PAGE_SIZE_A4:
  314. RealSheet = &g_Sheet_A4;
  315. break;
  316. case PAGE_SIZE_AUTO:
  317. default:
  318. RealSheet = PlotSheet;
  319. break;
  320. }
  321. double scalex = (double) RealSheet->m_Size.x / PlotSheet->m_Size.x;
  322. double scaley = (double) RealSheet->m_Size.y / PlotSheet->m_Size.y;
  323. double scale = 10 * MIN( scalex, scaley );
  324. plot_offset.x = 0;
  325. plot_offset.y = 0;
  326. PlotFileName = schframe->GetUniqueFilenameForCurrentSheet() + wxT(
  327. ".ps" );
  328. PlotOneSheetPS( PlotFileName, screen, RealSheet, plot_offset, scale );
  329. if( !AllPages )
  330. break;
  331. }
  332. ActiveScreen = oldscreen;
  333. schframe->m_CurrentSheet = oldsheetpath;
  334. schframe->m_CurrentSheet->UpdateAllScreenReferences();
  335. schframe->SetSheetNumberAndCount();
  336. }
  337. void WinEDA_PlotPSFrame::PlotOneSheetPS( const wxString& FileName,
  338. SCH_SCREEN* screen,
  339. Ki_PageDescr* sheet,
  340. wxPoint plot_offset,
  341. double scale )
  342. {
  343. wxString msg;
  344. FILE* output_file = wxFopen( FileName, wxT( "wt" ) );
  345. if( output_file == NULL )
  346. {
  347. msg = wxT( "\n** " );
  348. msg += _( "Unable to create " ) + FileName + wxT( " **\n\n" );
  349. m_MsgBox->AppendText( msg );
  350. wxBell();
  351. return;
  352. }
  353. SetLocaleTo_C_standard();
  354. msg.Printf( _( "Plot: %s\n" ), FileName.GetData() );
  355. m_MsgBox->AppendText( msg );
  356. PS_PLOTTER* plotter = new PS_PLOTTER();
  357. plotter->set_paper_size( sheet );
  358. plotter->set_viewport( plot_offset, scale, 0 );
  359. plotter->set_default_line_width( g_DrawDefaultLineThickness );
  360. plotter->set_color_mode( PlotPSColorOpt );
  361. /* Init : */
  362. plotter->set_creator( wxT( "EESchema-PS" ) );
  363. plotter->set_filename( FileName );
  364. plotter->start_plot( output_file );
  365. if( Plot_Sheet_Ref )
  366. {
  367. plotter->set_color( BLACK );
  368. m_Parent->PlotWorkSheet( plotter, screen );
  369. }
  370. PlotDrawlist( plotter, screen->EEDrawList );
  371. plotter->end_plot();
  372. delete plotter;
  373. SetLocaleTo_Default();
  374. m_MsgBox->AppendText( wxT( "Ok\n" ) );
  375. }