1 2 #ifndef DIALOG_EDIT_ONE_FIELD_H_ 3 #define DIALOG_EDIT_ONE_FIELD_H_ 4 5 /* 6 * This program source code file is part of KiCad, a free EDA CAD application. 7 * 8 * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@gipsa-lab.inpg.com 9 * Copyright (C) 2016 Wayne Stambaugh, stambaughw@gmail.com 10 * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors. 11 * 12 * This program is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU General Public License 14 * as published by the Free Software Foundation; either version 2 15 * of the License, or (at your option) any later version. 16 * 17 * This program is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU General Public License for more details. 21 * 22 * You should have received a copy of the GNU General Public License 23 * along with this program; if not, you may find one here: 24 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 25 * or you may search the http://www.gnu.org website for the version 2 license, 26 * or you may write to the Free Software Foundation, Inc., 27 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 28 */ 29 30 #include <dialog_lib_text_properties_base.h> 31 #include <widgets/unit_binder.h> 32 #include <lib_field.h> 33 #include <template_fieldnames.h> 34 35 class SCH_BASE_FRAME; 36 class SCH_FIELD; 37 class EDA_TEXT; 38 class SCINTILLA_TRICKS; 39 40 41 /** 42 * A base class to edit schematic and symbol library fields. 43 * 44 * This class is setup in expectation of its children possibly using Kiway player so 45 * #DIALOG_SHIM::ShowQuasiModal is required when calling any subclasses. 46 */ 47 class DIALOG_FIELD_PROPERTIES : public DIALOG_LIB_TEXT_PROPERTIES_BASE 48 { 49 public: 50 DIALOG_FIELD_PROPERTIES( SCH_BASE_FRAME* aParent, const wxString& aTitle, 51 const EDA_TEXT* aTextItem ); 52 53 ~DIALOG_FIELD_PROPERTIES() override; 54 55 bool TransferDataToWindow() override; 56 bool TransferDataFromWindow() override; 57 GetParent()58 SCH_BASE_FRAME* GetParent() { return dynamic_cast< SCH_BASE_FRAME* >( wxDialog::GetParent() ); } 59 GetText()60 const wxString& GetText() const { return m_text; } 61 62 protected: 63 void init(); 64 65 void updateText( EDA_TEXT* aText ); 66 67 /** 68 * Handle the select button next to the text value field. The current assumption 69 * is that this event will only be enabled for footprint type fields. In the future 70 * this function may need to be moved to the subclasses to access m_field and check for 71 * the field type if more select actions are desired. 72 * 73 * @param aEvent is the wX event thrown when the button is clicked, this isn't used 74 */ 75 void OnTextValueSelectButtonClick( wxCommandEvent& aEvent ) override; 76 77 /** 78 * Used to select the variant part of some text fields (for instance, the question mark 79 * or number in a reference). 80 */ 81 virtual void OnSetFocusText( wxFocusEvent& event ) override; 82 83 UNIT_BINDER m_posX; 84 UNIT_BINDER m_posY; 85 UNIT_BINDER m_textSize; 86 87 int m_fieldId; 88 bool m_isPower; 89 wxString m_text; 90 bool m_isItalic; 91 bool m_isBold; 92 wxPoint m_position; 93 int m_size; 94 bool m_isVertical; 95 int m_verticalJustification; 96 int m_horizontalJustification; 97 bool m_isVisible; 98 99 bool m_firstFocus; 100 101 SCINTILLA_TRICKS* m_scintillaTricks; 102 }; 103 104 105 /** 106 * Handle editing a single symbol field in the symbol editor. 107 * 108 * @note Use ShowQuasiModal when calling this class! 109 */ 110 class DIALOG_LIB_FIELD_PROPERTIES : public DIALOG_FIELD_PROPERTIES 111 { 112 public: 113 DIALOG_LIB_FIELD_PROPERTIES( SCH_BASE_FRAME* aParent, const wxString& aTitle, 114 const LIB_FIELD* aField ); 115 ~DIALOG_LIB_FIELD_PROPERTIES()116 ~DIALOG_LIB_FIELD_PROPERTIES() {} 117 UpdateField(LIB_FIELD * aField)118 void UpdateField( LIB_FIELD* aField ) 119 { 120 wxString value = m_text; 121 122 if( m_fieldId == VALUE_FIELD ) 123 value = EscapeString( value, CTX_LIBID ); 124 125 aField->SetText( value ); 126 127 // VALUE === symbol name, so update the parent symbol if it changes. 128 if( m_fieldId == VALUE_FIELD && aField->GetParent() ) 129 aField->GetParent()->SetName( value ); 130 131 updateText( aField ); 132 133 aField->SetHorizJustify( EDA_TEXT::MapHorizJustify( m_horizontalJustification - 1 ) ); 134 aField->SetVertJustify( EDA_TEXT::MapVertJustify( m_verticalJustification - 1 ) ); 135 aField->SetTextPos( m_position ); 136 } 137 }; 138 139 140 /** 141 * Handle editing a single symbol field in the schematic editor. 142 * 143 * @note Use ShowQuasiModal when calling this class! 144 */ 145 class DIALOG_SCH_FIELD_PROPERTIES : public DIALOG_FIELD_PROPERTIES 146 { 147 public: 148 DIALOG_SCH_FIELD_PROPERTIES( SCH_BASE_FRAME* aParent, const wxString& aTitle, 149 const SCH_FIELD* aField ); 150 ~DIALOG_SCH_FIELD_PROPERTIES()151 ~DIALOG_SCH_FIELD_PROPERTIES() {} 152 153 void onScintillaCharAdded( wxStyledTextEvent &aEvent ); 154 155 void UpdateField( SCH_FIELD* aField, SCH_SHEET_PATH* aSheetPath ); 156 157 private: 158 const SCH_FIELD* m_field; 159 bool m_isSheetFilename; 160 }; 161 162 #endif // DIALOG_EDIT_ONE_FIELD_H_ 163