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.

314 lines
8.5 KiB

18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
17 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: dialog_orient_footprints.cpp
  3. // Purpose:
  4. // Author: j-p Charras
  5. // Modified by:
  6. // Created: 11/07/2008 13:32:12
  7. // RCS-ID:
  8. // Copyright: j-p Charras
  9. // Licence: GPL
  10. /////////////////////////////////////////////////////////////////////////////
  11. // Generated by DialogBlocks (unregistered), 11/07/2008 13:32:12
  12. ////@begin includes
  13. ////@end includes
  14. #include "fctsys.h"
  15. #include "class_drawpanel.h"
  16. #include "confirm.h"
  17. #include "kicad_string.h"
  18. #include "pcbnew.h"
  19. #include "wxPcbStruct.h"
  20. #include "dialog_orient_footprints.h"
  21. ////@begin XPM images
  22. ////@end XPM images
  23. int s_NewOrientation = 0;
  24. /*!
  25. * dialog_orient_footprints type definition
  26. */
  27. IMPLEMENT_DYNAMIC_CLASS( dialog_orient_footprints, wxDialog )
  28. /*!
  29. * dialog_orient_footprints event table definition
  30. */
  31. BEGIN_EVENT_TABLE( dialog_orient_footprints, wxDialog )
  32. ////@begin dialog_orient_footprints event table entries
  33. EVT_CLOSE( dialog_orient_footprints::OnCloseWindow )
  34. EVT_BUTTON( wxID_OK, dialog_orient_footprints::OnOkClick )
  35. EVT_BUTTON( wxID_CANCEL, dialog_orient_footprints::OnCancelClick )
  36. ////@end dialog_orient_footprints event table entries
  37. END_EVENT_TABLE()
  38. /*!
  39. * dialog_orient_footprints constructors
  40. */
  41. dialog_orient_footprints::dialog_orient_footprints()
  42. {
  43. Init();
  44. }
  45. dialog_orient_footprints::dialog_orient_footprints( WinEDA_PcbFrame* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
  46. {
  47. m_Parent = parent;
  48. Init();
  49. Create(parent, id, caption, pos, size, style);
  50. }
  51. /*!
  52. * dialog_orient_footprints creator
  53. */
  54. bool dialog_orient_footprints::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
  55. {
  56. ////@begin dialog_orient_footprints creation
  57. SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
  58. wxDialog::Create( parent, id, caption, pos, size, style );
  59. CreateControls();
  60. if (GetSizer())
  61. {
  62. GetSizer()->SetSizeHints(this);
  63. }
  64. Centre();
  65. ////@end dialog_orient_footprints creation
  66. return true;
  67. }
  68. /*!
  69. * dialog_orient_footprints destructor
  70. */
  71. dialog_orient_footprints::~dialog_orient_footprints()
  72. {
  73. ////@begin dialog_orient_footprints destruction
  74. ////@end dialog_orient_footprints destruction
  75. }
  76. /*!
  77. * Member initialisation
  78. */
  79. void dialog_orient_footprints::Init()
  80. {
  81. ////@begin dialog_orient_footprints member initialisation
  82. m_OrientationCtrl = NULL;
  83. m_FilterPattern = NULL;
  84. m_ApplyToLocked = NULL;
  85. m_CloseButton = NULL;
  86. ////@end dialog_orient_footprints member initialisation
  87. }
  88. /*!
  89. * Control creation for dialog_orient_footprints
  90. */
  91. void dialog_orient_footprints::CreateControls()
  92. {
  93. ////@begin dialog_orient_footprints content construction
  94. // Generated by DialogBlocks, 11/07/2008 16:49:18 (unregistered)
  95. dialog_orient_footprints* itemDialog1 = this;
  96. wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
  97. itemDialog1->SetSizer(itemBoxSizer2);
  98. wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL);
  99. itemBoxSizer2->Add(itemBoxSizer3, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
  100. wxStaticText* itemStaticText4 = new wxStaticText( itemDialog1, wxID_STATIC, _("Orientation:"), wxDefaultPosition, wxDefaultSize, 0 );
  101. itemBoxSizer3->Add(itemStaticText4, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5);
  102. m_OrientationCtrl = new wxTextCtrl( itemDialog1, ID_TEXTCTRLROT_VALUE, _T(""), wxDefaultPosition, wxDefaultSize, 0 );
  103. if (dialog_orient_footprints::ShowToolTips())
  104. m_OrientationCtrl->SetToolTip(_("New orientation (0.1 degree resolution)"));
  105. itemBoxSizer3->Add(m_OrientationCtrl, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5);
  106. wxStaticText* itemStaticText6 = new wxStaticText( itemDialog1, wxID_STATIC, _("Filter:"), wxDefaultPosition, wxDefaultSize, 0 );
  107. itemBoxSizer3->Add(itemStaticText6, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5);
  108. m_FilterPattern = new wxTextCtrl( itemDialog1, ID_TEXTCTRL_FOOTPRINTS_FILTER, _("*"), wxDefaultPosition, wxDefaultSize, 0 );
  109. if (dialog_orient_footprints::ShowToolTips())
  110. m_FilterPattern->SetToolTip(_("Filter to select footprints by reference"));
  111. itemBoxSizer3->Add(m_FilterPattern, 1, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5);
  112. itemBoxSizer3->Add(5, 5, 0, wxGROW|wxALL, 5);
  113. m_ApplyToLocked = new wxCheckBox( itemDialog1, ID_CHECKBOX_APPLY_TO_LOCKED, _("Include Locked Footprints"), wxDefaultPosition, wxDefaultSize, 0 );
  114. m_ApplyToLocked->SetValue(false);
  115. if (dialog_orient_footprints::ShowToolTips())
  116. m_ApplyToLocked->SetToolTip(_("Force locked footprints to be modified"));
  117. itemBoxSizer3->Add(m_ApplyToLocked, 0, wxGROW|wxALL, 5);
  118. wxBoxSizer* itemBoxSizer10 = new wxBoxSizer(wxVERTICAL);
  119. itemBoxSizer2->Add(itemBoxSizer10, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
  120. wxButton* itemButton11 = new wxButton( itemDialog1, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0 );
  121. itemBoxSizer10->Add(itemButton11, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
  122. m_CloseButton = new wxButton( itemDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
  123. m_CloseButton->SetDefault();
  124. itemBoxSizer10->Add(m_CloseButton, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
  125. ////@end dialog_orient_footprints content construction
  126. wxString txt;
  127. txt.Printf(wxT("%g"), (double) s_NewOrientation/10);
  128. m_OrientationCtrl->SetValue(txt);
  129. m_CloseButton->SetFocus( );
  130. }
  131. /*!
  132. * Should we show tooltips?
  133. */
  134. bool dialog_orient_footprints::ShowToolTips()
  135. {
  136. return true;
  137. }
  138. /*!
  139. * Get bitmap resources
  140. */
  141. wxBitmap dialog_orient_footprints::GetBitmapResource( const wxString& name )
  142. {
  143. // Bitmap retrieval
  144. ////@begin dialog_orient_footprints bitmap retrieval
  145. wxUnusedVar(name);
  146. return wxNullBitmap;
  147. ////@end dialog_orient_footprints bitmap retrieval
  148. }
  149. /*!
  150. * Get icon resources
  151. */
  152. wxIcon dialog_orient_footprints::GetIconResource( const wxString& name )
  153. {
  154. // Icon retrieval
  155. ////@begin dialog_orient_footprints icon retrieval
  156. wxUnusedVar(name);
  157. return wxNullIcon;
  158. ////@end dialog_orient_footprints icon retrieval
  159. }
  160. /***********************************************/
  161. void WinEDA_PcbFrame::OnOrientFootprints( void )
  162. /***********************************************/
  163. /**
  164. * Function OnOrientFootprints
  165. * install the dialog box for the comman Orient Footprints
  166. */
  167. {
  168. dialog_orient_footprints dialogbox(this);
  169. dialogbox.ShowModal();
  170. dialogbox.Destroy();
  171. }
  172. /*******************************************************************/
  173. void WinEDA_PcbFrame::ReOrientModules( const wxString& ModuleMask,
  174. int Orient, bool include_fixe )
  175. /*******************************************************************/
  176. /**
  177. * Function ReOrientModules
  178. * Set the orientation of footprints
  179. * @param ModuleMask = mask (wildcard allowed) selection
  180. * @param Orient = new orientation
  181. * @param include_fixe = true to orient locked footprints
  182. */
  183. {
  184. wxString line;
  185. bool redraw = false;
  186. line.Printf( _( "Ok to set footprints orientation to %g degrees ?" ), (double)Orient / 10 );
  187. if( !IsOK( this, line ) )
  188. return;
  189. for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() )
  190. {
  191. if( module->IsLocked() && !include_fixe )
  192. continue;
  193. if( WildCompareString( ModuleMask, module->m_Reference->m_Text, FALSE ) )
  194. {
  195. OnModify();
  196. redraw = true;
  197. Rotate_Module( NULL, module, Orient, FALSE );
  198. }
  199. }
  200. if ( redraw )
  201. DrawPanel->Refresh();
  202. }
  203. /*!
  204. * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
  205. */
  206. void dialog_orient_footprints::OnOkClick( wxCommandEvent& event )
  207. {
  208. double d_orient;
  209. wxString text = m_OrientationCtrl->GetValue();
  210. if ( ! text.ToDouble(&d_orient) )
  211. {
  212. DisplayError(this, _("Bad value for footprints orientation"));
  213. return;
  214. }
  215. s_NewOrientation = wxRound(d_orient * 10);
  216. if ( s_NewOrientation > 3600 )
  217. s_NewOrientation = 3600;
  218. if ( s_NewOrientation < -3600 )
  219. s_NewOrientation = -3600;
  220. text = m_FilterPattern->GetValue();
  221. m_Parent->ReOrientModules( text, s_NewOrientation, m_ApplyToLocked->IsChecked() );
  222. Close();
  223. }
  224. /*!
  225. * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CANCEL
  226. */
  227. void dialog_orient_footprints::OnCancelClick( wxCommandEvent& event )
  228. {
  229. Close();
  230. }
  231. /*!
  232. * wxEVT_CLOSE_WINDOW event handler for ID_DIALOG_ORIENT_FOOTPRINTS
  233. */
  234. void dialog_orient_footprints::OnCloseWindow( wxCloseEvent& event )
  235. {
  236. EndModal(1);
  237. }