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.

311 lines
10 KiB

* 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
* 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
* 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
12 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2004-2010 Jean-Pierre Charras <jean-pierre.charras@gpisa-lab.inpg.fr>
  5. * Copyright (C) 2010-2016 KiCad Developers, see change_log.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /***************************************************************************/
  25. /* Dialog editor for text on copper and technical layers (TEXTE_PCB class) */
  26. /***************************************************************************/
  27. #include <fctsys.h>
  28. #include <gr_basic.h>
  29. #include <class_drawpanel.h>
  30. #include <pcbnew.h>
  31. #include <wxPcbStruct.h>
  32. #include <drawtxt.h>
  33. #include <confirm.h>
  34. #include <base_units.h>
  35. #include <wx/valnum.h>
  36. #include <class_board.h>
  37. #include <class_pcb_text.h>
  38. #include <vector>
  39. #include <wx/wx.h>
  40. #include <dialog_pcb_text_properties_base.h>
  41. #include <class_pcb_layer_box_selector.h>
  42. class PCB_EDIT_FRAME;
  43. class TEXTE_PCB;
  44. class DIALOG_PCB_TEXT_PROPERTIES : public DIALOG_PCB_TEXT_PROPERTIES_BASE
  45. {
  46. public:
  47. DIALOG_PCB_TEXT_PROPERTIES( PCB_EDIT_FRAME* parent, TEXTE_PCB* passedTextPCB, wxDC* DC );
  48. private:
  49. PCB_EDIT_FRAME* m_Parent;
  50. wxDC* m_DC;
  51. TEXTE_PCB* m_SelectedPCBText;
  52. wxFloatingPointValidator<double> m_OrientValidator;
  53. double m_OrientValue;
  54. bool TransferDataToWindow();
  55. bool TransferDataFromWindow();
  56. // Virtual event handler
  57. virtual void OnInitDlg( wxInitDialogEvent& event )
  58. {
  59. // Call the default wxDialog handler of a wxInitDialogEvent
  60. TransferDataToWindow();
  61. // Now all widgets have the size fixed, call FinishDialogSettings
  62. FinishDialogSettings();
  63. }
  64. };
  65. /**
  66. * DIALOG_PCB_TEXT_PROPERTIES, derived from DIALOG_PCB_TEXT_PROPERTIES_BASE
  67. * @see dialog_dialog_pcb_text_properties_base.h and
  68. * dialog_dialog_pcb_text_properties_base.cpp, automatically created by
  69. * wxFormBuilder.
  70. */
  71. DIALOG_PCB_TEXT_PROPERTIES::DIALOG_PCB_TEXT_PROPERTIES( PCB_EDIT_FRAME* parent,
  72. TEXTE_PCB* passedTextPCB, wxDC* DC ) :
  73. DIALOG_PCB_TEXT_PROPERTIES_BASE( parent ),
  74. m_OrientValidator( 1, &m_OrientValue )
  75. {
  76. m_Parent = parent;
  77. m_DC = DC;
  78. m_SelectedPCBText = passedTextPCB;
  79. m_OrientValue = 0.0;
  80. m_OrientValidator.SetRange( -360.0, 360.0 );
  81. m_OrientCtrl->SetValidator( m_OrientValidator );
  82. m_OrientValidator.SetWindow( m_OrientCtrl );
  83. m_StandardSizerOK->SetDefault();
  84. FixOSXCancelButtonIssue();
  85. }
  86. /**
  87. * Routine for main window class to launch text properties dialog.
  88. */
  89. void PCB_EDIT_FRAME::InstallTextPCBOptionsFrame( TEXTE_PCB* TextPCB, wxDC* DC )
  90. {
  91. m_canvas->SetIgnoreMouseEvents( true );
  92. #ifndef __WXMAC__
  93. DIALOG_PCB_TEXT_PROPERTIES dlg( this, TextPCB, DC );
  94. #else
  95. // Avoid "writes" in the dialog, creates errors with WxOverlay and NSView
  96. // Raising an Exception - Fixes #891347
  97. DIALOG_PCB_TEXT_PROPERTIES dlg( this, TextPCB, NULL );
  98. #endif
  99. dlg.ShowModal();
  100. m_canvas->MoveCursorToCrossHair();
  101. m_canvas->SetIgnoreMouseEvents( false );
  102. }
  103. bool DIALOG_PCB_TEXT_PROPERTIES::TransferDataToWindow()
  104. {
  105. // Put units symbols to text labels where appropriate
  106. AddUnitSymbol( *m_SizeXLabel );
  107. AddUnitSymbol( *m_SizeYLabel );
  108. AddUnitSymbol( *m_ThicknessLabel );
  109. AddUnitSymbol( *m_PositionXLabel );
  110. AddUnitSymbol( *m_PositionYLabel );
  111. // Fill fields with current values
  112. *m_TextContentCtrl << m_SelectedPCBText->GetText();
  113. PutValueInLocalUnits( *m_SizeXCtrl, m_SelectedPCBText->GetSize().x );
  114. PutValueInLocalUnits( *m_SizeYCtrl, m_SelectedPCBText->GetSize().y );
  115. PutValueInLocalUnits( *m_ThicknessCtrl, m_SelectedPCBText->GetThickness() );
  116. PutValueInLocalUnits( *m_PositionXCtrl, m_SelectedPCBText->GetTextPosition().x );
  117. PutValueInLocalUnits( *m_PositionYCtrl, m_SelectedPCBText->GetTextPosition().y );
  118. // Configure the layers list selector
  119. m_LayerSelectionCtrl->SetLayersHotkeys( false );
  120. // A text has no sense on edge cut layer
  121. m_LayerSelectionCtrl->SetLayerSet( Edge_Cuts );
  122. m_LayerSelectionCtrl->SetBoardFrame( m_Parent );
  123. m_LayerSelectionCtrl->Resync();
  124. m_LayerSelectionCtrl->SetLayerSelection( m_SelectedPCBText->GetLayer() );
  125. m_OrientValue = m_SelectedPCBText->GetOrientation() / 10.0;
  126. if( m_SelectedPCBText->IsMirrored() )
  127. m_DisplayCtrl->SetSelection( 1 );
  128. else
  129. m_DisplayCtrl->SetSelection( 0 );
  130. if( m_SelectedPCBText->IsItalic() )
  131. m_StyleCtrl->SetSelection( 1 );
  132. else
  133. m_StyleCtrl->SetSelection( 0 );
  134. // Set justification
  135. EDA_TEXT_HJUSTIFY_T hJustify = m_SelectedPCBText->GetHorizJustify();
  136. m_justifyChoice->SetSelection( (int) hJustify + 1 );
  137. // Manually set tab order
  138. m_SizeXCtrl->MoveAfterInTabOrder( m_TextContentCtrl );
  139. m_SizeYCtrl->MoveAfterInTabOrder( m_SizeXCtrl );
  140. m_ThicknessCtrl->MoveAfterInTabOrder( m_SizeYCtrl );
  141. m_PositionXCtrl->MoveAfterInTabOrder( m_ThicknessCtrl );
  142. m_PositionYCtrl->MoveAfterInTabOrder( m_PositionXCtrl );
  143. m_OrientCtrl->MoveAfterInTabOrder( m_PositionYCtrl );
  144. m_LayerSelectionCtrl->MoveAfterInTabOrder( m_OrientCtrl );
  145. m_StyleCtrl->MoveAfterInTabOrder( m_LayerSelectionCtrl );
  146. m_DisplayCtrl->MoveAfterInTabOrder( m_StyleCtrl );
  147. m_justifyChoice->MoveAfterInTabOrder( m_DisplayCtrl );
  148. // Set focus on most important control
  149. m_TextContentCtrl->SetFocus();
  150. m_TextContentCtrl->SetSelection( -1, -1 );
  151. return DIALOG_PCB_TEXT_PROPERTIES_BASE::TransferDataToWindow();
  152. }
  153. bool DIALOG_PCB_TEXT_PROPERTIES::TransferDataFromWindow()
  154. {
  155. if( !DIALOG_PCB_TEXT_PROPERTIES_BASE::TransferDataFromWindow() )
  156. return false;
  157. // Test for acceptable layer.
  158. // Incorrect layer can happen for old boards,
  159. // having texts on edge cut layer for instance
  160. if( m_LayerSelectionCtrl->GetLayerSelection() < 0 )
  161. {
  162. wxMessageBox( _( "No layer selected, Please select the text layer" ) );
  163. return false;
  164. }
  165. wxPoint newPosition;
  166. wxSize newSize;
  167. // If no other command in progress, prepare undo command
  168. // (for a command in progress, will be made later, at the completion of command)
  169. if( m_SelectedPCBText->GetFlags() == 0 )
  170. m_Parent->SaveCopyInUndoList( m_SelectedPCBText, UR_CHANGED );
  171. /* set flag in edit to force undo/redo/abort proper operation,
  172. * and avoid new calls to SaveCopyInUndoList for the same text
  173. * this can occurs when a text is moved, and then rotated, edited ..
  174. */
  175. if( m_SelectedPCBText->GetFlags() != 0 )
  176. m_SelectedPCBText->SetFlags( IN_EDIT );
  177. #ifndef USE_WX_OVERLAY
  178. // Erase old text on screen if context is available
  179. if( m_DC )
  180. {
  181. m_SelectedPCBText->Draw( m_Parent->GetCanvas(), m_DC, GR_XOR );
  182. }
  183. #endif
  184. // Set the new text content
  185. if( !m_TextContentCtrl->GetValue().IsEmpty() )
  186. {
  187. m_SelectedPCBText->SetText( m_TextContentCtrl->GetValue() );
  188. }
  189. // Set PCB Text position
  190. newPosition.x = ValueFromString( g_UserUnit, m_PositionXCtrl->GetValue() );
  191. newPosition.y = ValueFromString( g_UserUnit, m_PositionYCtrl->GetValue() );
  192. m_SelectedPCBText->SetTextPosition( newPosition );
  193. // Check constraints and set PCB Text size
  194. newSize.x = ValueFromString( g_UserUnit, m_SizeXCtrl->GetValue() );
  195. newSize.y = ValueFromString( g_UserUnit, m_SizeYCtrl->GetValue() );
  196. if( newSize.x < TEXTS_MIN_SIZE )
  197. newSize.x = TEXTS_MIN_SIZE;
  198. if( newSize.y < TEXTS_MIN_SIZE )
  199. newSize.y = TEXTS_MIN_SIZE;
  200. if( newSize.x > TEXTS_MAX_WIDTH )
  201. newSize.x = TEXTS_MAX_WIDTH;
  202. if( newSize.y > TEXTS_MAX_WIDTH )
  203. newSize.y = TEXTS_MAX_WIDTH;
  204. m_SelectedPCBText->SetSize( newSize );
  205. // Set the new thickness
  206. m_SelectedPCBText->SetThickness( ValueFromString( g_UserUnit,
  207. m_ThicknessCtrl->GetValue() ) );
  208. // Test for acceptable values for thickness and size and clamp if fails
  209. int maxthickness = Clamp_Text_PenSize( m_SelectedPCBText->GetThickness(),
  210. m_SelectedPCBText->GetSize() );
  211. if( m_SelectedPCBText->GetThickness() > maxthickness )
  212. {
  213. DisplayError( NULL,
  214. _( "The text thickness is too large for the text size. It will be clamped" ) );
  215. m_SelectedPCBText->SetThickness( maxthickness );
  216. }
  217. // Set the layer on which the PCB text is laying
  218. m_SelectedPCBText->SetLayer( ToLAYER_ID( m_LayerSelectionCtrl->GetLayerSelection() ) );
  219. // Set whether the PCB text is mirrored (faced down from layer face perspective)
  220. m_SelectedPCBText->SetMirrored( m_DisplayCtrl->GetSelection() == 1 );
  221. // Set the text orientation
  222. m_SelectedPCBText->SetOrientation( m_OrientValue * 10.0 );
  223. // Set whether the PCB text is slanted (it is not italics, as italics has additional curves in style)
  224. m_SelectedPCBText->SetItalic( m_StyleCtrl->GetSelection() );
  225. // Set justification
  226. switch( m_justifyChoice->GetSelection() )
  227. {
  228. case 0:
  229. m_SelectedPCBText->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
  230. break;
  231. case 1:
  232. m_SelectedPCBText->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
  233. break;
  234. case 2:
  235. m_SelectedPCBText->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
  236. break;
  237. default:
  238. break;
  239. }
  240. #ifndef USE_WX_OVERLAY
  241. // Finally, display new text if there is a context to do so
  242. if( m_DC )
  243. {
  244. m_SelectedPCBText->Draw( m_Parent->GetCanvas(), m_DC, GR_OR );
  245. }
  246. #else
  247. m_parent->Refresh();
  248. #endif
  249. m_Parent->OnModify();
  250. return true;
  251. }