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.

320 lines
8.3 KiB

  1. /**
  2. * @file wxwineda.cpp
  3. */
  4. #include <fctsys.h>
  5. #include <wxstruct.h>
  6. #include <dialog_helpers.h>
  7. /*******************************************************/
  8. /* Class to edit a graphic + text size in INCHES or MM */
  9. /*******************************************************/
  10. EDA_GRAPHIC_TEXT_CTRL::EDA_GRAPHIC_TEXT_CTRL( wxWindow* parent,
  11. const wxString& Title,
  12. const wxString& TextToEdit,
  13. int textsize,
  14. EDA_UNITS_T user_unit,
  15. wxBoxSizer* BoxSizer,
  16. int framelen,
  17. int internal_unit )
  18. {
  19. m_UserUnit = user_unit;
  20. m_Internal_Unit = internal_unit;
  21. m_Title = NULL;
  22. m_Title = new wxStaticText( parent, -1, Title );
  23. BoxSizer->Add( m_Title, 0,
  24. wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
  25. m_FrameText = new wxTextCtrl( parent, -1, TextToEdit );
  26. BoxSizer->Add( m_FrameText, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
  27. if( !Title.IsEmpty() )
  28. {
  29. wxString msg = _( "Size" ) + ReturnUnitSymbol( m_UserUnit );
  30. wxStaticText* text = new wxStaticText( parent, -1, msg );
  31. BoxSizer->Add( text, 0,
  32. wxGROW | wxLEFT | wxRIGHT, 5 );
  33. }
  34. wxString value = FormatSize( m_Internal_Unit, m_UserUnit, textsize );
  35. m_FrameSize = new wxTextCtrl( parent, -1, value, wxDefaultPosition,
  36. wxSize( 70, -1 ) );
  37. BoxSizer->Add( m_FrameSize, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
  38. }
  39. EDA_GRAPHIC_TEXT_CTRL::~EDA_GRAPHIC_TEXT_CTRL()
  40. {
  41. /* no, these are deleted by the BoxSizer
  42. delete m_FrameText;
  43. delete m_Title;
  44. */
  45. }
  46. wxString EDA_GRAPHIC_TEXT_CTRL::FormatSize( int internalUnit, EDA_UNITS_T aUnit,
  47. int textSize )
  48. {
  49. wxString value;
  50. // Limiting the size of the text of reasonable values.
  51. if( textSize < 10 )
  52. textSize = 10;
  53. if( textSize > 3000 )
  54. textSize = 3000;
  55. value.Printf( ( internalUnit > 1000 ) ? wxT( "%.4f" ) : wxT( "%.3f" ),
  56. To_User_Unit( aUnit, textSize, internalUnit ) );
  57. return value;
  58. }
  59. void EDA_GRAPHIC_TEXT_CTRL::SetTitle( const wxString& title )
  60. {
  61. m_Title->SetLabel( title );
  62. }
  63. void EDA_GRAPHIC_TEXT_CTRL::SetValue( const wxString& value )
  64. {
  65. m_FrameText->SetValue( value );
  66. }
  67. void EDA_GRAPHIC_TEXT_CTRL::SetValue( int textSize )
  68. {
  69. wxString value = FormatSize( m_Internal_Unit, m_UserUnit, textSize );
  70. m_FrameSize->SetValue( value );
  71. }
  72. const wxString EDA_GRAPHIC_TEXT_CTRL::GetText() const
  73. {
  74. wxString text = m_FrameText->GetValue();
  75. return text;
  76. }
  77. int EDA_GRAPHIC_TEXT_CTRL::ParseSize( const wxString& sizeText,
  78. int internalUnit, EDA_UNITS_T aUnit )
  79. {
  80. int textsize;
  81. textsize = ReturnValueFromString( aUnit, sizeText, internalUnit );
  82. // Limit to reasonable size
  83. if( textsize < 10 )
  84. textsize = 10;
  85. if( textsize > 3000 )
  86. textsize = 3000;
  87. return textsize;
  88. }
  89. int EDA_GRAPHIC_TEXT_CTRL::GetTextSize()
  90. {
  91. return ParseSize( m_FrameSize->GetValue(), m_Internal_Unit, m_UserUnit );
  92. }
  93. void EDA_GRAPHIC_TEXT_CTRL::Enable( bool state )
  94. {
  95. m_FrameText->Enable( state );
  96. }
  97. /********************************************************/
  98. /* Class to display and edit a coordinated INCHES or MM */
  99. /********************************************************/
  100. EDA_POSITION_CTRL::EDA_POSITION_CTRL( wxWindow* parent,
  101. const wxString& title,
  102. const wxPoint& pos_to_edit,
  103. EDA_UNITS_T user_unit,
  104. wxBoxSizer* BoxSizer,
  105. int internal_unit )
  106. {
  107. wxString text;
  108. m_UserUnit = user_unit;
  109. m_Internal_Unit = internal_unit;
  110. if( title.IsEmpty() )
  111. text = _( "Pos " );
  112. else
  113. text = title;
  114. text += _( "X" ) + ReturnUnitSymbol( m_UserUnit );
  115. m_TextX = new wxStaticText( parent, -1, text );
  116. BoxSizer->Add( m_TextX, 0,
  117. wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
  118. m_FramePosX = new wxTextCtrl( parent, -1, wxEmptyString,
  119. wxDefaultPosition );
  120. BoxSizer->Add( m_FramePosX, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
  121. if( title.IsEmpty() )
  122. text = _( "Pos " );
  123. else
  124. text = title;
  125. text += _( "Y" ) + ReturnUnitSymbol( m_UserUnit );
  126. m_TextY = new wxStaticText( parent, -1, text );
  127. BoxSizer->Add( m_TextY, 0,
  128. wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
  129. m_FramePosY = new wxTextCtrl( parent, -1, wxEmptyString );
  130. BoxSizer->Add( m_FramePosY, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
  131. SetValue( pos_to_edit.x, pos_to_edit.y );
  132. }
  133. EDA_POSITION_CTRL::~EDA_POSITION_CTRL()
  134. {
  135. delete m_TextX;
  136. delete m_TextY;
  137. delete m_FramePosX;
  138. delete m_FramePosY;
  139. }
  140. /* Returns (in internal units) to coordinate between (in user units)
  141. */
  142. wxPoint EDA_POSITION_CTRL::GetValue()
  143. {
  144. wxPoint coord;
  145. coord.x = ReturnValueFromString( m_UserUnit, m_FramePosX->GetValue(), m_Internal_Unit );
  146. coord.y = ReturnValueFromString( m_UserUnit, m_FramePosY->GetValue(), m_Internal_Unit );
  147. return coord;
  148. }
  149. void EDA_POSITION_CTRL::Enable( bool x_win_on, bool y_win_on )
  150. {
  151. m_FramePosX->Enable( x_win_on );
  152. m_FramePosY->Enable( y_win_on );
  153. }
  154. void EDA_POSITION_CTRL::SetValue( int x_value, int y_value )
  155. {
  156. wxString msg;
  157. m_Pos_To_Edit.x = x_value;
  158. m_Pos_To_Edit.y = y_value;
  159. msg = ReturnStringFromValue( m_UserUnit, m_Pos_To_Edit.x, m_Internal_Unit );
  160. m_FramePosX->Clear();
  161. m_FramePosX->SetValue( msg );
  162. msg = ReturnStringFromValue( m_UserUnit, m_Pos_To_Edit.y, m_Internal_Unit );
  163. m_FramePosY->Clear();
  164. m_FramePosY->SetValue( msg );
  165. }
  166. /*******************/
  167. /* EDA_SIZE_CTRL */
  168. /*******************/
  169. EDA_SIZE_CTRL::EDA_SIZE_CTRL( wxWindow* parent, const wxString& title,
  170. const wxSize& size_to_edit,
  171. EDA_UNITS_T aUnit, wxBoxSizer* aBoxSizer,
  172. int internal_unit ) :
  173. EDA_POSITION_CTRL( parent, title,
  174. wxPoint( size_to_edit.x, size_to_edit.y ),
  175. aUnit, aBoxSizer, internal_unit )
  176. {
  177. }
  178. wxSize EDA_SIZE_CTRL::GetValue()
  179. {
  180. wxPoint pos = EDA_POSITION_CTRL::GetValue();
  181. wxSize size;
  182. size.x = pos.x;
  183. size.y = pos.y;
  184. return size;
  185. }
  186. /**************************************************************/
  187. /* Class to display and edit a dimension INCHES, MM, or other */
  188. /**************************************************************/
  189. EDA_VALUE_CTRL::EDA_VALUE_CTRL( wxWindow* parent, const wxString& title,
  190. int value, EDA_UNITS_T user_unit, wxBoxSizer* BoxSizer,
  191. int internal_unit )
  192. {
  193. wxString label = title;
  194. m_UserUnit = user_unit;
  195. m_Internal_Unit = internal_unit;
  196. m_Value = value;
  197. label += ReturnUnitSymbol( m_UserUnit );
  198. m_Text = new wxStaticText( parent, -1, label );
  199. BoxSizer->Add( m_Text, 0,
  200. wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
  201. wxString stringvalue = ReturnStringFromValue( m_UserUnit, m_Value,
  202. m_Internal_Unit );
  203. m_ValueCtrl = new wxTextCtrl( parent, -1, stringvalue );
  204. BoxSizer->Add( m_ValueCtrl,
  205. 0,
  206. wxGROW | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT | wxBOTTOM,
  207. 5 );
  208. }
  209. EDA_VALUE_CTRL::~EDA_VALUE_CTRL()
  210. {
  211. delete m_ValueCtrl;
  212. delete m_Text;
  213. }
  214. int EDA_VALUE_CTRL::GetValue()
  215. {
  216. int coord;
  217. wxString txtvalue = m_ValueCtrl->GetValue();
  218. coord = ReturnValueFromString( m_UserUnit, txtvalue, m_Internal_Unit );
  219. return coord;
  220. }
  221. void EDA_VALUE_CTRL::SetValue( int new_value )
  222. {
  223. wxString buffer;
  224. m_Value = new_value;
  225. buffer = ReturnStringFromValue( m_UserUnit, m_Value, m_Internal_Unit );
  226. m_ValueCtrl->SetValue( buffer );
  227. }
  228. void EDA_VALUE_CTRL::Enable( bool enbl )
  229. {
  230. m_ValueCtrl->Enable( enbl );
  231. m_Text->Enable( enbl );
  232. }