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.

177 lines
4.5 KiB

  1. /**
  2. * @file set_grid.cpp
  3. * @brief Manage user grid.
  4. */
  5. #include <fctsys.h>
  6. #include <common.h>
  7. #include <class_drawpanel.h>
  8. #include <wxBasePcbFrame.h>
  9. #include <base_units.h>
  10. #include <pcbnew.h>
  11. #include <pcbnew_id.h>
  12. #include <dialog_set_grid_base.h>
  13. class DIALOG_SET_GRID : public DIALOG_SET_GRID_BASE
  14. {
  15. public:
  16. DIALOG_SET_GRID( wxWindow* parent, const wxPoint& pos );
  17. ~DIALOG_SET_GRID() { }
  18. void SetGridSize( const wxRealPoint& grid );
  19. wxRealPoint GetGridSize();
  20. void SetGridUnits( int units );
  21. int GetGridUnits();
  22. void SetGridOrigin( const wxPoint& grid );
  23. wxPoint GetGridOrigin();
  24. void SetGridForFastSwitching( wxArrayString aGrids, int aGrid1, int aGrid2 );
  25. void GetGridForFastSwitching( int& aGrid1, int& aGrid2 );
  26. private:
  27. void OnResetGridOrgClick( wxCommandEvent& event );
  28. void OnCancelClick( wxCommandEvent& event );
  29. void OnOkClick( wxCommandEvent& event );
  30. };
  31. void PCB_BASE_FRAME::InstallGridFrame( const wxPoint& pos )
  32. {
  33. DIALOG_SET_GRID dlg( this, pos );
  34. dlg.SetGridUnits( m_UserGridUnit );
  35. dlg.SetGridSize( m_UserGridSize );
  36. dlg.SetGridOrigin( GetScreen()->m_GridOrigin );
  37. if( m_gridSelectBox )
  38. dlg.SetGridForFastSwitching( m_gridSelectBox->GetStrings(), m_FastGrid1, m_FastGrid2 );
  39. if( dlg.ShowModal() == wxID_CANCEL )
  40. return;
  41. m_UserGridSize = dlg.GetGridSize();
  42. m_UserGridUnit = (EDA_UNITS_T) dlg.GetGridUnits();
  43. GetScreen()->m_GridOrigin = dlg.GetGridOrigin();
  44. GetScreen()->AddGrid( m_UserGridSize, m_UserGridUnit, ID_POPUP_GRID_USER );
  45. dlg.GetGridForFastSwitching( m_FastGrid1, m_FastGrid2 );
  46. // If the user grid is the current option, recall SetGrid()
  47. // to force new values put in list as current grid value
  48. if( GetScreen()->GetGridId() == ID_POPUP_GRID_USER )
  49. GetScreen()->SetGrid( ID_POPUP_GRID_USER );
  50. m_canvas->Refresh();
  51. }
  52. DIALOG_SET_GRID::DIALOG_SET_GRID( wxWindow* parent, const wxPoint& pos ) :
  53. DIALOG_SET_GRID_BASE( parent )
  54. {
  55. SetFocus();
  56. m_TextPosXUnits->SetLabel( GetUnitsLabel( g_UserUnit ) );
  57. m_TextPosYUnits->SetLabel( GetUnitsLabel( g_UserUnit ) );
  58. m_sdbSizer1OK->SetDefault();
  59. GetSizer()->SetSizeHints( this );
  60. Centre();
  61. }
  62. void DIALOG_SET_GRID::SetGridSize( const wxRealPoint& grid )
  63. {
  64. wxString msg;
  65. msg.Printf( wxT( "%.4f" ), grid.x );
  66. m_OptGridSizeX->SetValue( msg );
  67. msg.Printf( wxT( "%.4f" ), grid.y );
  68. m_OptGridSizeY->SetValue( msg );
  69. }
  70. wxRealPoint DIALOG_SET_GRID::GetGridSize()
  71. {
  72. wxRealPoint grid;
  73. /* TODO: Some error checking here would be a good thing. */
  74. m_OptGridSizeX->GetValue().ToDouble( &grid.x );
  75. m_OptGridSizeY->GetValue().ToDouble( &grid.y );
  76. return grid;
  77. }
  78. void DIALOG_SET_GRID::SetGridUnits( int units )
  79. {
  80. if( units != INCHES )
  81. m_UnitGrid->SetSelection( 1 );
  82. }
  83. int DIALOG_SET_GRID::GetGridUnits()
  84. {
  85. return m_UnitGrid->GetSelection();
  86. }
  87. wxPoint DIALOG_SET_GRID::GetGridOrigin()
  88. {
  89. wxPoint grid;
  90. /* TODO: Some error checking here would be a good thing. */
  91. grid.x = ReturnValueFromTextCtrl( *m_GridOriginXCtrl );
  92. grid.y = ReturnValueFromTextCtrl( *m_GridOriginYCtrl );
  93. return grid;
  94. }
  95. void DIALOG_SET_GRID::SetGridOrigin( const wxPoint& grid )
  96. {
  97. wxString msg;
  98. PutValueInLocalUnits( *m_GridOriginXCtrl, grid.x );
  99. PutValueInLocalUnits( *m_GridOriginYCtrl, grid.y );
  100. }
  101. void DIALOG_SET_GRID::SetGridForFastSwitching( wxArrayString aGrids, int aGrid1, int aGrid2 )
  102. {
  103. for( wxArrayString::iterator i = aGrids.begin(); i != aGrids.end(); i++ )
  104. {
  105. m_comboBoxGrid1->Append( *i );
  106. m_comboBoxGrid2->Append( *i );
  107. }
  108. m_comboBoxGrid1->SetSelection( aGrid1 );
  109. m_comboBoxGrid2->SetSelection( aGrid2 );
  110. }
  111. void DIALOG_SET_GRID::GetGridForFastSwitching( int& aGrid1, int& aGrid2 )
  112. {
  113. aGrid1 = m_comboBoxGrid1->GetSelection();
  114. aGrid2 = m_comboBoxGrid2->GetSelection();
  115. }
  116. void DIALOG_SET_GRID::OnResetGridOrgClick( wxCommandEvent& event )
  117. {
  118. SetGridOrigin( wxPoint(0,0) );
  119. }
  120. /*****************************************************************/
  121. void DIALOG_SET_GRID::OnCancelClick( wxCommandEvent& event )
  122. /*****************************************************************/
  123. {
  124. EndModal( wxID_CANCEL );
  125. }
  126. /*************************************************************************/
  127. void DIALOG_SET_GRID::OnOkClick( wxCommandEvent& event )
  128. /*************************************************************************/
  129. {
  130. EndModal( wxID_OK );
  131. }