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.

397 lines
11 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: plotdxf.cpp
  3. // Purpose:
  4. // Author: Lorenzo Marcantonio
  5. // Modified by:
  6. // Created: 01/02/2006 08:37:24
  7. // RCS-ID:
  8. // Copyright: GNU License
  9. // Licence:
  10. /////////////////////////////////////////////////////////////////////////////
  11. // Generated by DialogBlocks (unregistered), 01/02/2006 08:37:24
  12. #if defined (__GNUG__) && !defined (NO_GCC_PRAGMA)
  13. #pragma implementation "plotdxf.h"
  14. #endif
  15. #include "fctsys.h"
  16. #include "gr_basic.h"
  17. #include "common.h"
  18. #include "confirm.h"
  19. #include "program.h"
  20. #include "libcmp.h"
  21. #include "general.h"
  22. #include "worksheet.h"
  23. #include "plot_common.h"
  24. #include "protos.h"
  25. /* Variables locales : */
  26. static bool Plot_Sheet_Ref = TRUE;
  27. #include "plotdxf.h"
  28. ////@begin XPM images
  29. ////@end XPM images
  30. /***********************************************************/
  31. void WinEDA_SchematicFrame::ToPlot_DXF( wxCommandEvent& event )
  32. /***********************************************************/
  33. /* fonction relai de creation de la frame de dialogue pour trace Postscript
  34. */
  35. {
  36. wxPoint pos;
  37. pos = GetPosition();
  38. pos.x += 10;
  39. pos.y += 20;
  40. WinEDA_PlotDXFFrame* DXF_frame = new WinEDA_PlotDXFFrame( this );
  41. DXF_frame->ShowModal();
  42. DXF_frame->Destroy();
  43. }
  44. /*!
  45. * WinEDA_PlotDXFFrame type definition
  46. */
  47. IMPLEMENT_DYNAMIC_CLASS( WinEDA_PlotDXFFrame, wxDialog )
  48. /*!
  49. * WinEDA_PlotDXFFrame event table definition
  50. */
  51. BEGIN_EVENT_TABLE( WinEDA_PlotDXFFrame, wxDialog )
  52. ////@begin WinEDA_PlotDXFFrame event table entries
  53. EVT_BUTTON( ID_PLOT_DXF_CURRENT_EXECUTE, WinEDA_PlotDXFFrame::OnPlotDXFCurrentExecuteClick )
  54. EVT_BUTTON( ID_PLOT_DXF_ALL_EXECUTE, WinEDA_PlotDXFFrame::OnPlotDXFAllExecuteClick )
  55. EVT_BUTTON( wxID_CANCEL, WinEDA_PlotDXFFrame::OnCancelClick )
  56. ////@end WinEDA_PlotDXFFrame event table entries
  57. END_EVENT_TABLE()
  58. /*!
  59. * WinEDA_PlotDXFFrame constructors
  60. */
  61. WinEDA_PlotDXFFrame::WinEDA_PlotDXFFrame()
  62. {
  63. }
  64. WinEDA_PlotDXFFrame::WinEDA_PlotDXFFrame( WinEDA_DrawFrame* parent,
  65. wxWindowID id,
  66. const wxString& caption,
  67. const wxPoint& pos,
  68. const wxSize& size,
  69. long style )
  70. {
  71. m_Parent = parent;
  72. PlotDXFColorOpt = false;
  73. Create( parent, id, caption, pos, size, style );
  74. }
  75. /*!
  76. * WinEDA_PlotDXFFrame creator
  77. */
  78. bool WinEDA_PlotDXFFrame::Create( wxWindow* parent,
  79. wxWindowID id,
  80. const wxString& caption,
  81. const wxPoint& pos,
  82. const wxSize& size,
  83. long style )
  84. {
  85. ////@begin WinEDA_PlotDXFFrame member initialisation
  86. m_PlotDXFColorOption = NULL;
  87. m_Plot_Sheet_Ref = NULL;
  88. m_btClose = NULL;
  89. m_MsgBox = NULL;
  90. ////@end WinEDA_PlotDXFFrame member initialisation
  91. ////@begin WinEDA_PlotDXFFrame creation
  92. SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
  93. wxDialog::Create( parent, id, caption, pos, size, style );
  94. CreateControls();
  95. if (GetSizer())
  96. {
  97. GetSizer()->SetSizeHints(this);
  98. }
  99. Centre();
  100. ////@end WinEDA_PlotDXFFrame creation
  101. return true;
  102. }
  103. /*!
  104. * Control creation for WinEDA_PlotDXFFrame
  105. */
  106. void WinEDA_PlotDXFFrame::CreateControls()
  107. {
  108. ////@begin WinEDA_PlotDXFFrame content construction
  109. // Generated by DialogBlocks, 24/04/2009 14:25:24 (unregistered)
  110. WinEDA_PlotDXFFrame* itemDialog1 = this;
  111. wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
  112. itemDialog1->SetSizer(itemBoxSizer2);
  113. wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
  114. itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
  115. wxStaticBox* itemStaticBoxSizer6Static = new wxStaticBox(itemDialog1, wxID_ANY, _("Plot Options:"));
  116. wxStaticBoxSizer* itemStaticBoxSizer6 = new wxStaticBoxSizer(itemStaticBoxSizer6Static, wxVERTICAL);
  117. itemBoxSizer3->Add(itemStaticBoxSizer6, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
  118. wxArrayString m_PlotDXFColorOptionStrings;
  119. m_PlotDXFColorOptionStrings.Add(_("B/W"));
  120. m_PlotDXFColorOptionStrings.Add(_("Color"));
  121. m_PlotDXFColorOption = new wxRadioBox( itemDialog1, ID_RADIOBOX, _("Plot Color:"), wxDefaultPosition, wxDefaultSize, m_PlotDXFColorOptionStrings, 1, wxRA_SPECIFY_COLS );
  122. m_PlotDXFColorOption->SetSelection(0);
  123. itemStaticBoxSizer6->Add(m_PlotDXFColorOption, 0, wxGROW|wxALL, 5);
  124. m_Plot_Sheet_Ref = new wxCheckBox( itemDialog1, ID_CHECKBOX, _("Print Sheet Ref"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE );
  125. m_Plot_Sheet_Ref->SetValue(false);
  126. itemStaticBoxSizer6->Add(m_Plot_Sheet_Ref, 0, wxGROW|wxALL, 5);
  127. itemBoxSizer3->Add(5, 5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
  128. wxBoxSizer* itemBoxSizer10 = new wxBoxSizer(wxVERTICAL);
  129. itemBoxSizer3->Add(itemBoxSizer10, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
  130. wxButton* itemButton11 = new wxButton( itemDialog1, ID_PLOT_DXF_CURRENT_EXECUTE, _("&Plot Page"), wxDefaultPosition, wxDefaultSize, 0 );
  131. itemButton11->SetDefault();
  132. itemBoxSizer10->Add(itemButton11, 0, wxGROW|wxALL, 5);
  133. wxButton* itemButton12 = new wxButton( itemDialog1, ID_PLOT_DXF_ALL_EXECUTE, _("Plot A&LL"), wxDefaultPosition, wxDefaultSize, 0 );
  134. itemBoxSizer10->Add(itemButton12, 0, wxGROW|wxALL, 5);
  135. m_btClose = new wxButton( itemDialog1, wxID_CANCEL, _("Close"), wxDefaultPosition, wxDefaultSize, 0 );
  136. itemBoxSizer10->Add(m_btClose, 0, wxGROW|wxALL, 5);
  137. wxStaticText* itemStaticText15 = new wxStaticText( itemDialog1, wxID_STATIC, _("Messages :"), wxDefaultPosition, wxDefaultSize, 0 );
  138. itemBoxSizer2->Add(itemStaticText15, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5);
  139. m_MsgBox = new wxTextCtrl( itemDialog1, ID_TEXTCTRL, _T(""), wxDefaultPosition, wxSize(-1, 200), wxTE_MULTILINE );
  140. itemBoxSizer2->Add(m_MsgBox, 0, wxGROW|wxALL|wxFIXED_MINSIZE, 5);
  141. // Set validators
  142. m_PlotDXFColorOption->SetValidator( wxGenericValidator(& PlotDXFColorOpt) );
  143. m_Plot_Sheet_Ref->SetValidator( wxGenericValidator(& Plot_Sheet_Ref) );
  144. ////@end WinEDA_PlotDXFFrame content construction
  145. SetFocus(); // make the ESC work
  146. }
  147. /*!
  148. * Should we show tooltips?
  149. */
  150. bool WinEDA_PlotDXFFrame::ShowToolTips()
  151. {
  152. return true;
  153. }
  154. /*!
  155. * Get bitmap resources
  156. */
  157. wxBitmap WinEDA_PlotDXFFrame::GetBitmapResource( const wxString& name )
  158. {
  159. // Bitmap retrieval
  160. ////@begin WinEDA_PlotDXFFrame bitmap retrieval
  161. wxUnusedVar(name);
  162. return wxNullBitmap;
  163. ////@end WinEDA_PlotDXFFrame bitmap retrieval
  164. }
  165. /*!
  166. * Get icon resources
  167. */
  168. wxIcon WinEDA_PlotDXFFrame::GetIconResource( const wxString& name )
  169. {
  170. // Icon retrieval
  171. ////@begin WinEDA_PlotDXFFrame icon retrieval
  172. wxUnusedVar(name);
  173. return wxNullIcon;
  174. ////@end WinEDA_PlotDXFFrame icon retrieval
  175. }
  176. /*!
  177. * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON
  178. */
  179. void WinEDA_PlotDXFFrame::OnPlotDXFCurrentExecuteClick( wxCommandEvent& event )
  180. {
  181. int Select_PlotAll = FALSE;
  182. InitOptVars();
  183. CreateDXFFile( Select_PlotAll );
  184. m_MsgBox->AppendText( wxT( "*****\n" ) );
  185. }
  186. /*!
  187. * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON1
  188. */
  189. void WinEDA_PlotDXFFrame::OnPlotDXFAllExecuteClick( wxCommandEvent& event )
  190. {
  191. int Select_PlotAll = TRUE;
  192. InitOptVars();
  193. CreateDXFFile( Select_PlotAll );
  194. m_MsgBox->AppendText( wxT( "*****\n" ) );
  195. }
  196. /*!
  197. * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CANCEL
  198. */
  199. void WinEDA_PlotDXFFrame::OnCancelClick( wxCommandEvent& event )
  200. {
  201. InitOptVars();
  202. EndModal( 0 );
  203. }
  204. /*****************************************/
  205. void WinEDA_PlotDXFFrame::InitOptVars()
  206. /*****************************************/
  207. {
  208. Plot_Sheet_Ref = m_Plot_Sheet_Ref->GetValue();
  209. PlotDXFColorOpt = m_PlotDXFColorOption->GetSelection();
  210. }
  211. /*************************************************************/
  212. void WinEDA_PlotDXFFrame::CreateDXFFile( int AllPages )
  213. /*************************************************************/
  214. {
  215. WinEDA_SchematicFrame* schframe = (WinEDA_SchematicFrame*) m_Parent;
  216. SCH_SCREEN* screen = schframe->GetScreen();
  217. SCH_SCREEN* oldscreen = screen;
  218. DrawSheetPath* sheetpath, *oldsheetpath = schframe->GetSheet();
  219. wxString PlotFileName;
  220. Ki_PageDescr* PlotSheet;
  221. wxPoint plot_offset;
  222. /* When printing all pages, the printed page is not the current page.
  223. * In complex hierarchies, we must setup references and others parameters in the printed SCH_SCREEN
  224. * because in complex hierarchies a SCH_SCREEN (a schematic drawings)
  225. * is shared between many sheets
  226. */
  227. EDA_SheetList SheetList( NULL );
  228. sheetpath = SheetList.GetFirst();
  229. DrawSheetPath list;
  230. while (true)
  231. {
  232. if( AllPages )
  233. {
  234. if( sheetpath == NULL )
  235. break;
  236. list.Clear();
  237. if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) )
  238. {
  239. schframe->m_CurrentSheet = &list;
  240. schframe->m_CurrentSheet->UpdateAllScreenReferences();
  241. schframe->SetSheetNumberAndCount();
  242. screen = schframe->m_CurrentSheet->LastScreen();
  243. ActiveScreen = screen;
  244. }
  245. else // Should not happen
  246. return;
  247. sheetpath = SheetList.GetNext();
  248. }
  249. PlotSheet = screen->m_CurrentSheetDesc;
  250. double scale = 10;
  251. plot_offset.x = 0;
  252. plot_offset.y = 0;
  253. PlotFileName = schframe->GetUniqueFilenameForCurrentSheet( ) + wxT( ".dxf" );
  254. PlotOneSheetDXF( PlotFileName, screen, PlotSheet, plot_offset, scale );
  255. if( !AllPages )
  256. break;
  257. }
  258. ActiveScreen = oldscreen;
  259. schframe->m_CurrentSheet = oldsheetpath;
  260. schframe->m_CurrentSheet->UpdateAllScreenReferences();
  261. schframe->SetSheetNumberAndCount();
  262. }
  263. /*****************************************************************************************/
  264. void WinEDA_PlotDXFFrame::PlotOneSheetDXF( const wxString& FileName,
  265. SCH_SCREEN* screen,
  266. Ki_PageDescr* sheet,
  267. wxPoint plot_offset,
  268. double scale)
  269. /*****************************************************************************************/
  270. /* Trace en format DXF. d'une feuille de dessin
  271. */
  272. {
  273. wxString msg;
  274. FILE *output_file = wxFopen( FileName, wxT( "wt" ) );
  275. if( output_file == NULL )
  276. {
  277. msg = wxT( "\n** " );
  278. msg += _( "Unable to create " ) + FileName + wxT( " **\n\n" );
  279. m_MsgBox->AppendText( msg );
  280. wxBell();
  281. return;
  282. }
  283. SetLocaleTo_C_standard();
  284. msg.Printf( _( "Plot: %s\n" ), FileName.GetData() );
  285. m_MsgBox->AppendText( msg );
  286. DXF_Plotter *plotter = new DXF_Plotter();
  287. plotter->set_paper_size(sheet);
  288. plotter->set_viewport( plot_offset, scale, 0);
  289. plotter->set_color_mode(PlotDXFColorOpt);
  290. /* Init : */
  291. plotter->set_creator(wxT("EESchema-DXF"));
  292. plotter->set_filename(FileName);
  293. plotter->start_plot(output_file);
  294. if( Plot_Sheet_Ref )
  295. {
  296. plotter->set_color( BLACK );
  297. m_Parent->PlotWorkSheet( plotter, screen );
  298. }
  299. PlotDrawlist(plotter, screen->EEDrawList);
  300. /* fin */
  301. plotter->end_plot();
  302. delete plotter;
  303. SetLocaleTo_Default();
  304. m_MsgBox->AppendText( wxT( "Ok\n" ) );
  305. }