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.

337 lines
9.4 KiB

16 years ago
16 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file sch_text.h
  27. * @brief Implementation of the label properties dialog.
  28. */
  29. #include <fctsys.h>
  30. #include <wx/valgen.h>
  31. #include <wx/valnum.h>
  32. #include <schframe.h>
  33. #include <base_units.h>
  34. #include <class_drawpanel.h>
  35. #include <general.h>
  36. #include <drawtxt.h>
  37. #include <confirm.h>
  38. #include <sch_text.h>
  39. #include <typeinfo>
  40. #include <dialog_edit_label_base.h>
  41. class SCH_EDIT_FRAME;
  42. class SCH_TEXT;
  43. class DIALOG_LABEL_EDITOR : public DIALOG_LABEL_EDITOR_BASE
  44. {
  45. public:
  46. DIALOG_LABEL_EDITOR( SCH_EDIT_FRAME* parent, SCH_TEXT* aTextItem );
  47. void SetTitle( const wxString& aTitle ) override
  48. {
  49. // This class is shared for numerous tasks: a couple of
  50. // single line labels and multi-line text fields.
  51. // Often the desired size of the multi-line text field editor
  52. // is larger than is needed for the single line label.
  53. // Therefore the session retained sizes of these dialogs needs
  54. // to be class independent, make them title dependent.
  55. switch( m_CurrentText->Type() )
  56. {
  57. case SCH_GLOBAL_LABEL_T:
  58. case SCH_HIERARCHICAL_LABEL_T:
  59. case SCH_LABEL_T:
  60. // labels can share retained settings probably.
  61. break;
  62. default:
  63. m_hash_key = TO_UTF8( aTitle );
  64. m_hash_key += typeid(*this).name();
  65. }
  66. DIALOG_LABEL_EDITOR_BASE::SetTitle( aTitle );
  67. }
  68. private:
  69. void InitDialog( ) override;
  70. virtual void OnEnterKey( wxCommandEvent& aEvent ) override;
  71. virtual void OnOkClick( wxCommandEvent& aEvent ) override;
  72. virtual void OnCancelClick( wxCommandEvent& aEvent ) override;
  73. void TextPropertiesAccept( wxCommandEvent& aEvent );
  74. SCH_EDIT_FRAME* m_Parent;
  75. SCH_TEXT* m_CurrentText;
  76. wxTextCtrl* m_textLabel;
  77. };
  78. /* Edit the properties of the text (Label, Global label, graphic text).. )
  79. * pointed by "aTextStruct"
  80. */
  81. void SCH_EDIT_FRAME::EditSchematicText( SCH_TEXT* aTextItem )
  82. {
  83. if( aTextItem == NULL )
  84. return;
  85. DIALOG_LABEL_EDITOR dialog( this, aTextItem );
  86. dialog.ShowModal();
  87. }
  88. DIALOG_LABEL_EDITOR::DIALOG_LABEL_EDITOR( SCH_EDIT_FRAME* aParent, SCH_TEXT* aTextItem ) :
  89. DIALOG_LABEL_EDITOR_BASE( aParent )
  90. {
  91. m_Parent = aParent;
  92. m_CurrentText = aTextItem;
  93. InitDialog();
  94. // Conservative limits 0.0 to 10.0 inches
  95. const int minSize = 0; // a value like 0.01 is better, but if > 0, creates
  96. // annoying issues when trying to enter a value starting by 0 or .0
  97. const int maxSize = 10 * 1000 * IU_PER_MILS;
  98. wxFloatingPointValidator<double> textSizeValidator( NULL, wxNUM_VAL_NO_TRAILING_ZEROES );
  99. textSizeValidator.SetPrecision( 4 );
  100. textSizeValidator.SetRange( To_User_Unit( g_UserUnit, minSize ),
  101. To_User_Unit( g_UserUnit, maxSize ) );
  102. m_TextSize->SetValidator( textSizeValidator );
  103. // Now all widgets have the size fixed, call FinishDialogSettings
  104. FinishDialogSettings();
  105. }
  106. void DIALOG_LABEL_EDITOR::InitDialog()
  107. {
  108. wxString msg;
  109. bool multiLine = false;
  110. if( m_CurrentText->IsMultilineAllowed() )
  111. {
  112. m_textLabel = m_textLabelMultiLine;
  113. m_textLabelSingleLine->Show( false );
  114. multiLine = true;
  115. }
  116. else
  117. {
  118. m_textLabel = m_textLabelSingleLine;
  119. m_textLabelMultiLine->Show( false );
  120. wxTextValidator* validator = (wxTextValidator*) m_textLabel->GetValidator();
  121. wxArrayString excludes;
  122. // Add invalid label characters to this list.
  123. excludes.Add( wxT( " " ) );
  124. validator->SetExcludes( excludes );
  125. }
  126. m_textLabel->SetValue( m_CurrentText->GetText() );
  127. m_textLabel->SetFocus();
  128. switch( m_CurrentText->Type() )
  129. {
  130. case SCH_GLOBAL_LABEL_T:
  131. SetTitle( _( "Global Label Properties" ) );
  132. break;
  133. case SCH_HIERARCHICAL_LABEL_T:
  134. SetTitle( _( "Hierarchical Label Properties" ) );
  135. break;
  136. case SCH_LABEL_T:
  137. SetTitle( _( "Label Properties" ) );
  138. break;
  139. case SCH_SHEET_PIN_T:
  140. SetTitle( _( "Hierarchical Sheet Pin Properties." ) );
  141. break;
  142. default:
  143. SetTitle( _( "Text Properties" ) );
  144. break;
  145. }
  146. const int MINTEXTWIDTH = 40; // M's are big characters, a few establish a lot of width
  147. int max_len = 0;
  148. if ( !multiLine )
  149. {
  150. max_len = m_CurrentText->GetText().Length();
  151. }
  152. else
  153. {
  154. // calculate the length of the biggest line
  155. // we cannot use the length of the entire text that has no meaning
  156. int curr_len = MINTEXTWIDTH;
  157. int imax = m_CurrentText->GetText().Length();
  158. for( int count = 0; count < imax; count++ )
  159. {
  160. if( m_CurrentText->GetText()[count] == '\n' ||
  161. m_CurrentText->GetText()[count] == '\r' ) // new line
  162. {
  163. curr_len = 0;
  164. }
  165. else
  166. {
  167. curr_len++;
  168. if ( max_len < curr_len )
  169. max_len = curr_len;
  170. }
  171. }
  172. }
  173. if( max_len < MINTEXTWIDTH )
  174. max_len = MINTEXTWIDTH;
  175. wxString textWidth;
  176. textWidth.Append( 'M', MINTEXTWIDTH );
  177. EnsureTextCtrlWidth( m_textLabel, &textWidth );
  178. // Set text options:
  179. m_TextOrient->SetSelection( m_CurrentText->GetLabelSpinStyle() );
  180. m_TextShape->SetSelection( m_CurrentText->GetShape() );
  181. int style = 0;
  182. if( m_CurrentText->IsItalic() )
  183. style = 1;
  184. if( m_CurrentText->IsBold() )
  185. style += 2;
  186. m_TextStyle->SetSelection( style );
  187. wxString units = ReturnUnitSymbol( g_UserUnit, wxT( "(%s)" ) );
  188. msg.Printf( _( "H%s x W%s" ), GetChars( units ), GetChars( units ) );
  189. m_staticSizeUnits->SetLabel( msg );
  190. msg = StringFromValue( g_UserUnit, m_CurrentText->GetTextWidth() );
  191. m_TextSize->SetValue( msg );
  192. if( m_CurrentText->Type() != SCH_GLOBAL_LABEL_T
  193. && m_CurrentText->Type() != SCH_HIERARCHICAL_LABEL_T )
  194. {
  195. m_TextShape->Show( false );
  196. }
  197. m_sdbSizer1OK->SetDefault();
  198. }
  199. /*!
  200. * wxTE_PROCESS_ENTER event handler for m_textLabel
  201. */
  202. void DIALOG_LABEL_EDITOR::OnEnterKey( wxCommandEvent& aEvent )
  203. {
  204. TextPropertiesAccept( aEvent );
  205. }
  206. /*!
  207. * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
  208. */
  209. void DIALOG_LABEL_EDITOR::OnOkClick( wxCommandEvent& aEvent )
  210. {
  211. TextPropertiesAccept( aEvent );
  212. }
  213. /*!
  214. * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CANCEL
  215. */
  216. void DIALOG_LABEL_EDITOR::OnCancelClick( wxCommandEvent& aEvent )
  217. {
  218. m_Parent->GetCanvas()->MoveCursorToCrossHair();
  219. EndModal( wxID_CANCEL );
  220. }
  221. void DIALOG_LABEL_EDITOR::TextPropertiesAccept( wxCommandEvent& aEvent )
  222. {
  223. wxString text;
  224. int value;
  225. /* save old text in undo list if not already in edit */
  226. /* or the label to be edited is part of a block */
  227. if( m_CurrentText->GetFlags() == 0 ||
  228. m_Parent->GetScreen()->m_BlockLocate.GetState() != STATE_NO_BLOCK )
  229. m_Parent->SaveCopyInUndoList( m_CurrentText, UR_CHANGED );
  230. m_Parent->GetCanvas()->RefreshDrawingRect( m_CurrentText->GetBoundingBox() );
  231. text = m_textLabel->GetValue();
  232. if( !text.IsEmpty() )
  233. m_CurrentText->SetText( text );
  234. else if( !m_CurrentText->IsNew() )
  235. {
  236. DisplayError( this, _( "Empty Text!" ) );
  237. return;
  238. }
  239. m_CurrentText->SetLabelSpinStyle( m_TextOrient->GetSelection() );
  240. text = m_TextSize->GetValue();
  241. value = ValueFromString( g_UserUnit, text );
  242. m_CurrentText->SetTextSize( wxSize( value, value ) );
  243. if( m_TextShape )
  244. /// @todo move cast to widget
  245. m_CurrentText->SetShape( static_cast<PINSHEETLABEL_SHAPE>( m_TextShape->GetSelection() ) );
  246. int style = m_TextStyle->GetSelection();
  247. m_CurrentText->SetItalic( ( style & 1 ) );
  248. if( ( style & 2 ) )
  249. {
  250. m_CurrentText->SetBold( true );
  251. m_CurrentText->SetThickness( GetPenSizeForBold( m_CurrentText->GetTextWidth() ) );
  252. }
  253. else
  254. {
  255. m_CurrentText->SetBold( false );
  256. m_CurrentText->SetThickness( 0 );
  257. }
  258. m_Parent->OnModify();
  259. // Make the text size the new default size ( if it is a new text ):
  260. if( m_CurrentText->IsNew() )
  261. SetDefaultTextSize( m_CurrentText->GetTextWidth() );
  262. m_Parent->GetCanvas()->RefreshDrawingRect( m_CurrentText->GetBoundingBox() );
  263. m_Parent->GetCanvas()->MoveCursorToCrossHair();
  264. EndModal( wxID_OK );
  265. }