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.

162 lines
4.0 KiB

  1. /**
  2. * @file dialog_orient_footprints.cpp
  3. */
  4. /*
  5. * This program source code file is part of KiCad, a free EDA CAD application.
  6. *
  7. * Copyright (C) 1992-2010 Jean_Pierre Charras <jp.charras@ujf-grenoble.fr>
  8. * Copyright (C) 1992-2010 KiCad Developers, see change_log.txt for contributors.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version 2
  13. * of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, you may find one here:
  22. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  23. * or you may search the http://www.gnu.org website for the version 2 license,
  24. * or you may write to the Free Software Foundation, Inc.,
  25. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  26. */
  27. #include <fctsys.h>
  28. #include <class_drawpanel.h>
  29. #include <confirm.h>
  30. #include <kicad_string.h>
  31. #include <pcbnew.h>
  32. #include <wxPcbStruct.h>
  33. #include <macros.h>
  34. #include <class_board.h>
  35. #include <class_module.h>
  36. #include <dialog_orient_footprints_base.h>
  37. /* DIALOG_ORIENT_FOOTPRINTS class declaration
  38. */
  39. class DIALOG_ORIENT_FOOTPRINTS: public DIALOG_ORIENT_FOOTPRINTS_BASE
  40. {
  41. private:
  42. PCB_EDIT_FRAME * m_Parent;
  43. static int newOrientation;
  44. public:
  45. DIALOG_ORIENT_FOOTPRINTS( PCB_EDIT_FRAME* parent );
  46. ~DIALOG_ORIENT_FOOTPRINTS() {}
  47. bool ApplyToLockedModules()
  48. {
  49. return m_ApplyToLocked->IsChecked();
  50. }
  51. int GetOrientation()
  52. {
  53. return newOrientation;
  54. }
  55. wxString GetFilter()
  56. {
  57. return m_FilterPattern->GetValue();
  58. }
  59. private:
  60. void init();
  61. void OnOkClick( wxCommandEvent& event );
  62. void OnCancelClick( wxCommandEvent& event );
  63. };
  64. int DIALOG_ORIENT_FOOTPRINTS::newOrientation = 0;
  65. DIALOG_ORIENT_FOOTPRINTS::DIALOG_ORIENT_FOOTPRINTS( PCB_EDIT_FRAME* parent )
  66. : DIALOG_ORIENT_FOOTPRINTS_BASE( parent )
  67. {
  68. m_Parent = parent;
  69. wxString txt;
  70. txt.Printf( wxT( "%g" ), (double) newOrientation/10 );
  71. m_OrientationCtrl->SetValue( txt );
  72. SetFocus();
  73. GetSizer()->SetSizeHints( this );
  74. Centre();
  75. }
  76. void PCB_EDIT_FRAME::OnOrientFootprints( wxCommandEvent& event )
  77. {
  78. DIALOG_ORIENT_FOOTPRINTS dlg( this );
  79. if( dlg.ShowModal() != wxID_OK )
  80. return;
  81. wxString text = dlg.GetFilter();
  82. if( ReOrientModules( text, dlg.GetOrientation(), dlg.ApplyToLockedModules() ) )
  83. {
  84. m_canvas->Refresh();
  85. Compile_Ratsnest( NULL, true );
  86. }
  87. }
  88. bool PCB_EDIT_FRAME::ReOrientModules( const wxString& ModuleMask, int Orient,
  89. bool include_fixe )
  90. {
  91. wxString line;
  92. bool modified = false;
  93. line.Printf( _( "OK to set footprints orientation to %.1f degrees ?" ), Orient / 10.0 );
  94. if( !IsOK( this, line ) )
  95. return false;
  96. for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() )
  97. {
  98. if( module->IsLocked() && !include_fixe )
  99. continue;
  100. if( WildCompareString( ModuleMask, module->GetReference(), false ) )
  101. {
  102. modified = true;
  103. Rotate_Module( NULL, module, Orient, false );
  104. }
  105. }
  106. if ( modified )
  107. OnModify();
  108. return modified;
  109. }
  110. void DIALOG_ORIENT_FOOTPRINTS::OnOkClick( wxCommandEvent& event )
  111. {
  112. double d_orient;
  113. wxString text = m_OrientationCtrl->GetValue();
  114. if ( ! text.ToDouble( &d_orient ) )
  115. {
  116. DisplayError( this, _( "Bad value for footprints orientation" ) );
  117. return;
  118. }
  119. newOrientation = KiROUND( d_orient * 10 );
  120. NORMALIZE_ANGLE_180( newOrientation );
  121. EndModal( wxID_OK );
  122. }
  123. void DIALOG_ORIENT_FOOTPRINTS::OnCancelClick( wxCommandEvent& event )
  124. {
  125. EndModal( wxID_CANCEL );
  126. }