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.

575 lines
16 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
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
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: svg_print.cpp
  3. // Purpose:
  4. // Author: jean-pierre Charras
  5. // Modified by:
  6. // Created: 05/02/2006 11:05:19
  7. // RCS-ID:
  8. // Copyright: License GNU
  9. // Licence:
  10. /////////////////////////////////////////////////////////////////////////////
  11. // Generated by DialogBlocks (unregistered), 05/02/2006 11:05:19
  12. #if defined (__GNUG__) && !defined (NO_GCC_PRAGMA)
  13. #pragma implementation "svg_print.h"
  14. #endif
  15. // For compilers that support precompilation, includes "wx/wx.h".
  16. #include "wx/wxprec.h"
  17. #ifdef __BORLANDC__
  18. #pragma hdrstop
  19. #endif
  20. #ifndef WX_PRECOMP
  21. #include "wx/wx.h"
  22. #endif
  23. ////@begin includes
  24. ////@end includes
  25. #include <ctype.h>
  26. #include "wx/metafile.h"
  27. #include "wx/image.h"
  28. #include "fctsys.h"
  29. #include "gr_basic.h"
  30. #include "common.h"
  31. #include "dcsvg.h"
  32. #include "svg_print.h"
  33. #ifdef EESCHEMA
  34. #include "program.h"
  35. #endif
  36. ////@begin XPM images
  37. ////@end XPM images
  38. extern BASE_SCREEN* ActiveScreen;
  39. #ifdef EESCHEMA
  40. #define WIDTH_MAX_VALUE 100
  41. #else
  42. #define WIDTH_MAX_VALUE 1000
  43. #endif
  44. #define WIDTH_MIN_VALUE 1
  45. // Variables locales
  46. static int s_SVGPenMinWidth; /* Minimum pen width (in internal units) for printing */
  47. static int Select_PrintAll = FALSE;
  48. static bool Print_Sheet_Ref = TRUE;
  49. static int s_PlotBlackAndWhite = 0;
  50. /*******************************************************/
  51. void WinEDA_DrawFrame::SVG_Print( wxCommandEvent& event )
  52. /*******************************************************/
  53. /* Prepare les structures de donnees de gestion de l'impression
  54. * et affiche la fenetre de dialogue de gestion de l'impression des feuilles
  55. */
  56. {
  57. // Arret des commandes en cours
  58. if( DrawPanel->ManageCurseur && DrawPanel->ForceCloseManageCurseur )
  59. {
  60. wxClientDC dc( DrawPanel );
  61. DrawPanel->PrepareDC( dc );
  62. DrawPanel->ForceCloseManageCurseur( DrawPanel, &dc );
  63. }
  64. SetToolID( 0, wxCURSOR_ARROW, wxEmptyString );
  65. WinEDA_PrintSVGFrame frame( this );
  66. frame.ShowModal();
  67. }
  68. /*!
  69. * WinEDA_PrintSVGFrame type definition
  70. */
  71. IMPLEMENT_DYNAMIC_CLASS( WinEDA_PrintSVGFrame, wxDialog )
  72. /*!
  73. * WinEDA_PrintSVGFrame event table definition
  74. */
  75. BEGIN_EVENT_TABLE( WinEDA_PrintSVGFrame, wxDialog )
  76. ////@begin WinEDA_PrintSVGFrame event table entries
  77. EVT_CLOSE( WinEDA_PrintSVGFrame::OnCloseWindow )
  78. EVT_RADIOBOX( ID_RADIOBOX_SETPRINTMODE, WinEDA_PrintSVGFrame::OnRadioboxSetprintmodeSelected )
  79. EVT_BUTTON( ID_PRINT_EXECUTE, WinEDA_PrintSVGFrame::OnPrintExecuteClick )
  80. EVT_BUTTON( wxID_CLOSE, WinEDA_PrintSVGFrame::OnCloseClick )
  81. ////@end WinEDA_PrintSVGFrame event table entries
  82. END_EVENT_TABLE()
  83. /*!
  84. * WinEDA_PrintSVGFrame constructors
  85. */
  86. WinEDA_PrintSVGFrame::WinEDA_PrintSVGFrame()
  87. {
  88. }
  89. WinEDA_PrintSVGFrame::WinEDA_PrintSVGFrame( WinEDA_DrawFrame* parent,
  90. wxWindowID id,
  91. const wxString& caption,
  92. const wxPoint& pos,
  93. const wxSize& size,
  94. long style )
  95. {
  96. m_Parent = parent;
  97. m_ImageXSize_mm = 270;
  98. wxConfig* Config = m_Parent->m_Parent->m_EDA_Config;
  99. if( Config )
  100. {
  101. Config->Read( wxT( "PlotSVGPenWidth" ), &s_SVGPenMinWidth );
  102. Config->Read( wxT( "PlotSVGModeColor" ), &s_PlotBlackAndWhite );
  103. }
  104. Create( parent, id, caption, pos, size, style );
  105. }
  106. /*!
  107. * WinEDA_PrintSVGFrame creator
  108. */
  109. bool WinEDA_PrintSVGFrame::Create( wxWindow* parent,
  110. wxWindowID id,
  111. const wxString& caption,
  112. const wxPoint& pos,
  113. const wxSize& size,
  114. long style )
  115. {
  116. ////@begin WinEDA_PrintSVGFrame member initialisation
  117. m_DialogPenWidthSizer = NULL;
  118. m_ModeColorOption = NULL;
  119. m_Print_Sheet_Ref = NULL;
  120. m_PagesOption = NULL;
  121. m_FileNameCtrl = NULL;
  122. m_MessagesBox = NULL;
  123. ////@end WinEDA_PrintSVGFrame member initialisation
  124. ////@begin WinEDA_PrintSVGFrame creation
  125. SetExtraStyle( GetExtraStyle() | wxWS_EX_BLOCK_EVENTS );
  126. wxDialog::Create( parent, id, caption, pos, size, style );
  127. CreateControls();
  128. if( GetSizer() )
  129. {
  130. GetSizer()->SetSizeHints( this );
  131. }
  132. Centre();
  133. ////@end WinEDA_PrintSVGFrame creation
  134. return true;
  135. }
  136. /*!
  137. * Control creation for WinEDA_PrintSVGFrame
  138. */
  139. void WinEDA_PrintSVGFrame::CreateControls()
  140. {
  141. SetFont( *g_DialogFont );
  142. ////@begin WinEDA_PrintSVGFrame content construction
  143. // Generated by DialogBlocks, 24/01/2007 19:00:23 (unregistered)
  144. WinEDA_PrintSVGFrame* itemDialog1 = this;
  145. wxBoxSizer* itemBoxSizer2 = new wxBoxSizer( wxVERTICAL );
  146. itemDialog1->SetSizer( itemBoxSizer2 );
  147. wxBoxSizer* itemBoxSizer3 = new wxBoxSizer( wxHORIZONTAL );
  148. itemBoxSizer2->Add( itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5 );
  149. wxBoxSizer* itemBoxSizer4 = new wxBoxSizer( wxVERTICAL );
  150. itemBoxSizer3->Add( itemBoxSizer4, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
  151. m_DialogPenWidthSizer = new wxBoxSizer( wxVERTICAL );
  152. itemBoxSizer4->Add( m_DialogPenWidthSizer, 0, wxGROW | wxALL, 5 );
  153. wxString m_ModeColorOptionStrings[] = {
  154. _( "Color" ),
  155. _( "Black and White" )
  156. };
  157. m_ModeColorOption = new wxRadioBox( itemDialog1, ID_RADIOBOX_SETPRINTMODE, _(
  158. "Print mode" ), wxDefaultPosition, wxDefaultSize, 2,
  159. m_ModeColorOptionStrings, 1,
  160. wxRA_SPECIFY_COLS );
  161. m_ModeColorOption->SetSelection( 0 );
  162. itemBoxSizer4->Add( m_ModeColorOption, 0, wxALIGN_LEFT | wxALL, 5 );
  163. m_Print_Sheet_Ref = new wxCheckBox( itemDialog1, ID_CHECKBOX, _(
  164. "Print Sheet Ref" ), wxDefaultPosition, wxDefaultSize,
  165. wxCHK_2STATE );
  166. m_Print_Sheet_Ref->SetValue( false );
  167. itemBoxSizer4->Add( m_Print_Sheet_Ref, 0, wxALIGN_LEFT | wxALL, 5 );
  168. itemBoxSizer3->Add( 5, 5, 0, wxALIGN_CENTER_VERTICAL | wxALL, 15 );
  169. wxBoxSizer* itemBoxSizer9 = new wxBoxSizer( wxVERTICAL );
  170. itemBoxSizer3->Add( itemBoxSizer9, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
  171. wxString m_PagesOptionStrings[] = {
  172. _( "Current" ),
  173. _( "All" )
  174. };
  175. m_PagesOption = new wxRadioBox( itemDialog1, ID_RADIOBOX1, _(
  176. "Page Print:" ), wxDefaultPosition,
  177. wxDefaultSize, 2, m_PagesOptionStrings, 1,
  178. wxRA_SPECIFY_COLS );
  179. m_PagesOption->SetSelection( 0 );
  180. itemBoxSizer9->Add( m_PagesOption, 0, wxALIGN_LEFT | wxALL, 5 );
  181. wxButton* itemButton11 = new wxButton( itemDialog1, ID_PRINT_EXECUTE, _(
  182. "Create &File" ), wxDefaultPosition,
  183. wxDefaultSize, 0 );
  184. itemButton11->SetDefault();
  185. itemButton11->SetForegroundColour( wxColour( 0, 128, 0 ) );
  186. itemBoxSizer9->Add( itemButton11, 0, wxGROW | wxALL, 5 );
  187. wxButton* itemButton12 = new wxButton( itemDialog1, wxID_CLOSE, _(
  188. "&Close" ), wxDefaultPosition,
  189. wxDefaultSize, 0 );
  190. itemButton12->SetForegroundColour( wxColour( 0, 0, 198 ) );
  191. itemBoxSizer9->Add( itemButton12, 0, wxGROW | wxALL, 5 );
  192. wxStaticText* itemStaticText13 = new wxStaticText( itemDialog1, wxID_STATIC, _(
  193. "Filename:" ), wxDefaultPosition,
  194. wxDefaultSize, 0 );
  195. itemBoxSizer2->Add( itemStaticText13,
  196. 0,
  197. wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP | wxADJUST_MINSIZE,
  198. 5 );
  199. m_FileNameCtrl = new wxTextCtrl( itemDialog1, ID_TEXTCTRL, _T(
  200. "" ), wxDefaultPosition, wxDefaultSize,
  201. 0 );
  202. itemBoxSizer2->Add( m_FileNameCtrl, 0, wxGROW | wxALL, 5 );
  203. wxStaticText* itemStaticText15 = new wxStaticText( itemDialog1, wxID_STATIC, _(
  204. "Messages:" ), wxDefaultPosition,
  205. wxDefaultSize, 0 );
  206. itemBoxSizer2->Add( itemStaticText15,
  207. 0,
  208. wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP | wxADJUST_MINSIZE,
  209. 5 );
  210. m_MessagesBox = new wxTextCtrl( itemDialog1, ID_TEXTCTRL1, _T(
  211. "" ), wxDefaultPosition, wxSize( -1,
  212. 100 ), wxTE_MULTILINE | wxTE_READONLY );
  213. itemBoxSizer2->Add( m_MessagesBox, 0, wxGROW | wxALL, 5 );
  214. // Set validators
  215. m_ModeColorOption->SetValidator( wxGenericValidator( &s_PlotBlackAndWhite ) );
  216. m_Print_Sheet_Ref->SetValidator( wxGenericValidator( &Print_Sheet_Ref ) );
  217. ////@end WinEDA_PrintSVGFrame content construction
  218. m_DialogPenWidth = new WinEDA_ValueCtrl( this, _(
  219. "Pen width mini" ), s_SVGPenMinWidth,
  220. g_UnitMetric, m_DialogPenWidthSizer,
  221. m_Parent->m_InternalUnits );
  222. }
  223. /*!
  224. * Should we show tooltips?
  225. */
  226. bool WinEDA_PrintSVGFrame::ShowToolTips()
  227. {
  228. return true;
  229. }
  230. /*!
  231. * Get bitmap resources
  232. */
  233. wxBitmap WinEDA_PrintSVGFrame::GetBitmapResource( const wxString& name )
  234. {
  235. // Bitmap retrieval
  236. ////@begin WinEDA_PrintSVGFrame bitmap retrieval
  237. wxUnusedVar( name );
  238. return wxNullBitmap;
  239. ////@end WinEDA_PrintSVGFrame bitmap retrieval
  240. }
  241. /*!
  242. * Get icon resources
  243. */
  244. wxIcon WinEDA_PrintSVGFrame::GetIconResource( const wxString& name )
  245. {
  246. // Icon retrieval
  247. ////@begin WinEDA_PrintSVGFrame icon retrieval
  248. wxUnusedVar( name );
  249. return wxNullIcon;
  250. ////@end WinEDA_PrintSVGFrame icon retrieval
  251. }
  252. /******************************************************/
  253. wxString WinEDA_PrintSVGFrame::ReturnFullFileName()
  254. /******************************************************/
  255. {
  256. wxString name, ext;
  257. name = m_Parent->GetBaseScreen()->m_FileName;
  258. ChangeFileNameExt( name, wxT( ".svg" ) );
  259. return name;
  260. }
  261. /********************************************/
  262. void WinEDA_PrintSVGFrame::SetPenWidth()
  263. /********************************************/
  264. {
  265. s_SVGPenMinWidth = m_DialogPenWidth->GetValue();
  266. if( s_SVGPenMinWidth > WIDTH_MAX_VALUE )
  267. {
  268. s_SVGPenMinWidth = WIDTH_MAX_VALUE;
  269. }
  270. if( s_SVGPenMinWidth < WIDTH_MIN_VALUE )
  271. {
  272. s_SVGPenMinWidth = WIDTH_MIN_VALUE;
  273. }
  274. m_DialogPenWidth->SetValue( s_SVGPenMinWidth );
  275. }
  276. /**************************************************************/
  277. void WinEDA_PrintSVGFrame::PrintSVGDoc( wxCommandEvent& event )
  278. /**************************************************************/
  279. /* Called on activate "Print CURRENT" button
  280. */
  281. {
  282. bool print_ref = TRUE;
  283. wxString msg;
  284. Select_PrintAll = FALSE;
  285. if( m_PagesOption && (m_PagesOption->GetSelection() == 1) )
  286. Select_PrintAll = TRUE;
  287. if( (m_Print_Sheet_Ref == NULL) || (m_Print_Sheet_Ref->GetValue() == FALSE) )
  288. print_ref = FALSE;
  289. SetPenWidth();
  290. BASE_SCREEN* screen = m_Parent->GetBaseScreen();
  291. BASE_SCREEN* oldscreen = screen;
  292. #ifndef EESCHEMA
  293. if( Select_PrintAll )
  294. while( screen->Pback )
  295. screen = (BASE_SCREEN*) screen->Pback;
  296. #endif
  297. if( (m_Parent->m_Ident == PCB_FRAME) || (m_Parent->m_Ident == GERBER_FRAME) )
  298. {
  299. if( Select_PrintAll )
  300. {
  301. m_PrintMaskLayer = 0xFFFFFFFF;
  302. }
  303. else
  304. m_PrintMaskLayer = 1;
  305. }
  306. if( screen == NULL )
  307. return;
  308. #ifdef EESCHEMA
  309. if( Select_PrintAll && m_Parent->m_Ident == SCHEMATIC_FRAME )
  310. {
  311. EDA_ScreenList ScreenList;
  312. for( SCH_SCREEN* schscreen = ScreenList.GetFirst(); schscreen != NULL;
  313. schscreen = ScreenList.GetNext() )
  314. {
  315. /* Create all files *.svg */
  316. ( (WinEDA_SchematicFrame*) m_Parent )->SetScreen( schscreen );
  317. wxString FullFileName = schscreen->m_FileName;
  318. ChangeFileNameExt( FullFileName, wxT( ".svg" ) );
  319. bool success = DrawPage( FullFileName, schscreen );
  320. msg = _( "Create file " ) + FullFileName;
  321. if( !success )
  322. msg += _( " error" );
  323. msg += wxT( "\n" );
  324. m_MessagesBox->AppendText( msg );
  325. }
  326. }
  327. else
  328. #endif
  329. {
  330. wxString FullFileName = m_FileNameCtrl->GetValue();
  331. if( FullFileName.IsEmpty() )
  332. {
  333. FullFileName = screen->m_FileName;
  334. ChangeFileNameExt( FullFileName, wxT( ".svg" ) );
  335. }
  336. bool success = DrawPage( FullFileName, screen );
  337. msg = _( "Create file " ) + FullFileName;
  338. if( !success )
  339. msg += _( " error" );
  340. msg += wxT( "\n" );
  341. m_MessagesBox->AppendText( msg );
  342. }
  343. ActiveScreen = oldscreen;
  344. }
  345. /*****************************************************************/
  346. bool WinEDA_PrintSVGFrame::DrawPage( const wxString& FullFileName, BASE_SCREEN* screen )
  347. /*****************************************************************/
  348. /*
  349. * Routine effective d'impression
  350. */
  351. {
  352. int tmpzoom;
  353. wxPoint tmp_startvisu;
  354. wxSize SheetSize; // Sheet size in internal units
  355. wxPoint old_org;
  356. float dpi;
  357. bool success = TRUE;
  358. /* modification des cadrages et reglages locaux */
  359. tmp_startvisu = screen->m_StartVisu;
  360. tmpzoom = screen->GetZoom();
  361. old_org = screen->m_DrawOrg;
  362. screen->m_DrawOrg.x = screen->m_DrawOrg.y = 0;
  363. screen->m_StartVisu.x = screen->m_StartVisu.y = 0;
  364. SheetSize = screen->m_CurrentSheetDesc->m_Size; // size in 1/1000 inch
  365. SheetSize.x *= m_Parent->m_InternalUnits / 1000;
  366. SheetSize.y *= m_Parent->m_InternalUnits / 1000; // size in pixels
  367. screen->SetZoom( 1 );
  368. dpi = (float) SheetSize.x * 25.4 / m_ImageXSize_mm;
  369. WinEDA_DrawPanel* panel = m_Parent->DrawPanel;
  370. wxSVGFileDC dc( FullFileName, SheetSize.x, SheetSize.y, dpi );
  371. if( !dc.Ok() )
  372. {
  373. DisplayError( this, wxT( "SVGprint error: wxSVGFileDC not OK" ) );
  374. success = FALSE;
  375. }
  376. else
  377. {
  378. EDA_Rect tmp = panel->m_ClipBox;
  379. GRResetPenAndBrush( &dc );
  380. s_SVGPenMinWidth = m_DialogPenWidth->GetValue();
  381. SetPenMinWidth( s_SVGPenMinWidth );
  382. GRForceBlackPen( m_ModeColorOption->GetSelection() == 0 ? FALSE : TRUE );
  383. panel->m_ClipBox.SetX( 0 ); panel->m_ClipBox.SetY( 0 );
  384. panel->m_ClipBox.SetWidth( 0x7FFFFF0 ); panel->m_ClipBox.SetHeight( 0x7FFFFF0 );
  385. g_IsPrinting = TRUE;
  386. setlocale( LC_NUMERIC, "C" ); // Switch the locale to standard C (needed to print floating point numbers like 1.3)
  387. panel->PrintPage( &dc, m_Print_Sheet_Ref, m_PrintMaskLayer );
  388. setlocale( LC_NUMERIC, "" ); // revert to the current locale
  389. g_IsPrinting = FALSE;
  390. panel->m_ClipBox = tmp;
  391. }
  392. GRForceBlackPen( FALSE );
  393. SetPenMinWidth( 1 );
  394. screen->m_StartVisu = tmp_startvisu;
  395. screen->m_DrawOrg = old_org;
  396. screen->SetZoom( tmpzoom );
  397. return success;
  398. }
  399. /*!
  400. * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_PRINT_EXECUTE
  401. */
  402. void WinEDA_PrintSVGFrame::OnPrintExecuteClick( wxCommandEvent& event )
  403. {
  404. PrintSVGDoc( event );
  405. }
  406. /*!
  407. * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CLOSE
  408. */
  409. void WinEDA_PrintSVGFrame::OnCloseClick( wxCommandEvent& event )
  410. {
  411. Close( TRUE );
  412. }
  413. /*!
  414. * wxEVT_CLOSE_WINDOW event handler for ID_DIALOG
  415. */
  416. void WinEDA_PrintSVGFrame::OnCloseWindow( wxCloseEvent& event )
  417. {
  418. wxConfig* Config = m_Parent->m_Parent->m_EDA_Config;
  419. if( Config )
  420. {
  421. s_PlotBlackAndWhite = m_ModeColorOption->GetSelection();
  422. Config->Write( wxT( "PlotSVGPenWidth" ), s_SVGPenMinWidth );
  423. Config->Write( wxT( "PlotSVGModeColor" ), s_PlotBlackAndWhite );
  424. }
  425. event.Skip();
  426. }
  427. /*!
  428. * wxEVT_COMMAND_RADIOBOX_SELECTED event handler for ID_RADIOBOX_SETPRINTMODE
  429. */
  430. void WinEDA_PrintSVGFrame::OnRadioboxSetprintmodeSelected( wxCommandEvent& event )
  431. {
  432. s_PlotBlackAndWhite = m_ModeColorOption->GetSelection();
  433. event.Skip();
  434. }