kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #17458
[PATCH] Friendlier warning for modifying power values
Currently, if you try to edit the value of a power component in
eeschema, you get a "... is a power component and it's [sic] value
cannot be modified!" message. That message isn't completely accurate,
though. The edit box also allows you to change the *formatting*, which
is perfectly valid to do for power texts. Unfortunately, that means that
if you want to change formatting, you have to go through the
whole-component edit dialog.
This patch removes that error message. Instead, when editing a power
component's value, the text field in the edit box is greyed out, and a
message "Power component value text cannot be modified!" is displayed
underneath it. All formatting options remain active.
Chris
diff --git a/eeschema/dialogs/dialog_edit_one_field.cpp b/eeschema/dialogs/dialog_edit_one_field.cpp
index 60ef3a6..13bd957 100644
--- a/eeschema/dialogs/dialog_edit_one_field.cpp
+++ b/eeschema/dialogs/dialog_edit_one_field.cpp
@@ -62,6 +62,7 @@ void DIALOG_EDIT_ONE_FIELD::initDlg_base()
m_Invisible->SetValue( m_text_invisible );
m_TextShapeOpt->SetSelection( m_textshape );
+ SetPowerWarning( false );
switch ( m_textHjustify )
{
@@ -97,8 +98,15 @@ void DIALOG_EDIT_ONE_FIELD::initDlg_base()
m_TextSizeText->SetLabel( msg );
m_sdbSizerButtonsOK->SetDefault();
+
}
+void DIALOG_EDIT_ONE_FIELD::SetPowerWarning( bool aWarn )
+{
+ m_PowerComponentValues->Show( aWarn );
+ m_TextValue->Enable( ! aWarn );
+ Fit();
+}
void DIALOG_EDIT_ONE_FIELD::OnTextValueSelectButtonClick( wxCommandEvent& aEvent )
{
@@ -159,8 +167,11 @@ wxString DIALOG_LIB_EDIT_ONE_FIELD::GetTextField()
}
-void DIALOG_EDIT_ONE_FIELD::TransfertDataToField()
+void DIALOG_EDIT_ONE_FIELD::TransfertDataToField( bool aIncludeText )
{
+ // This method doesn't transfer text anyway.
+ (void) aIncludeText;
+
m_textorient = m_Orient->GetValue() ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ;
wxString msg = m_TextSize->GetValue();
m_textsize = ValueFromString( g_UserUnit, msg );
@@ -197,11 +208,12 @@ void DIALOG_EDIT_ONE_FIELD::TransfertDataToField()
}
-void DIALOG_LIB_EDIT_ONE_FIELD::TransfertDataToField()
+void DIALOG_LIB_EDIT_ONE_FIELD::TransfertDataToField( bool aIncludeText )
{
- DIALOG_EDIT_ONE_FIELD::TransfertDataToField();
+ DIALOG_EDIT_ONE_FIELD::TransfertDataToField( aIncludeText );
- m_field->SetText( GetTextField() );
+ if( aIncludeText )
+ m_field->SetText( GetTextField() );
m_field->SetSize( wxSize( m_textsize, m_textsize ) );
m_field->SetOrientation( m_textorient );
@@ -255,11 +267,12 @@ wxString DIALOG_SCH_EDIT_ONE_FIELD::GetTextField()
};
-void DIALOG_SCH_EDIT_ONE_FIELD::TransfertDataToField()
+void DIALOG_SCH_EDIT_ONE_FIELD::TransfertDataToField( bool aIncludeText )
{
- DIALOG_EDIT_ONE_FIELD::TransfertDataToField();
+ DIALOG_EDIT_ONE_FIELD::TransfertDataToField( aIncludeText );
- m_field->SetText( GetTextField() );
+ if( aIncludeText )
+ m_field->SetText( GetTextField() );
m_field->SetSize( wxSize( m_textsize, m_textsize ) );
m_field->SetOrientation( m_textorient );
diff --git a/eeschema/dialogs/dialog_edit_one_field.h b/eeschema/dialogs/dialog_edit_one_field.h
index 7edd99b..c52d4ef 100644
--- a/eeschema/dialogs/dialog_edit_one_field.h
+++ b/eeschema/dialogs/dialog_edit_one_field.h
@@ -74,14 +74,27 @@ public:
/**
* Function TransfertDataToField
* Converts fields from dialog window to variables to be used by child classes
+ *
+ * @param aIncludeText Whether the valies transferred should include the actual
+ * item text. If this is false, formatting will be transferred, but text will
+ * not.
*/
- virtual void TransfertDataToField();
+ virtual void TransfertDataToField( bool aIncludeText = true );
void SetTextField( const wxString& aText )
{
m_TextValue->SetValue( aText );
}
+ /**
+ * Function SetPowerWarning
+ * Disables the Text field and displays the "Power component values cannot
+ * be modified!" warning, if aWarn is true. Performs the inverse if aWarn
+ * is false (this, however, is the default).
+ *
+ * @param aWarn whether or not to produce the warning
+ */
+ void SetPowerWarning( bool aWarn );
protected:
/**
@@ -143,7 +156,7 @@ public:
~DIALOG_LIB_EDIT_ONE_FIELD() {};
- void TransfertDataToField();
+ void TransfertDataToField( bool aIncludeText = true );
/**
* Function GetTextField
@@ -186,7 +199,7 @@ public:
// ~DIALOG_SCH_EDIT_ONE_FIELD() {};
- void TransfertDataToField();
+ void TransfertDataToField( bool aIncludeText = true );
/**
* Function GetTextField
diff --git a/eeschema/dialogs/dialog_lib_edit_text_base.cpp b/eeschema/dialogs/dialog_lib_edit_text_base.cpp
index 70324cc..5d3ca5a 100644
--- a/eeschema/dialogs/dialog_lib_edit_text_base.cpp
+++ b/eeschema/dialogs/dialog_lib_edit_text_base.cpp
@@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
-// C++ code generated with wxFormBuilder (version Jun 5 2014)
+// C++ code generated with wxFormBuilder (version Mar 13 2015)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
@@ -64,6 +64,10 @@ DIALOG_LIB_EDIT_TEXT_BASE::DIALOG_LIB_EDIT_TEXT_BASE( wxWindow* parent, wxWindow
bPropertiesSizer->Add( bUpperBoxSizer, 0, wxEXPAND, 5 );
+ m_PowerComponentValues = new wxStaticText( this, wxID_ANY, _("Power component value text cannot be modified!"), wxDefaultPosition, wxDefaultSize, 0 );
+ m_PowerComponentValues->Wrap( -1 );
+ bPropertiesSizer->Add( m_PowerComponentValues, 0, wxALL, 5 );
+
wxBoxSizer* bBottomtBoxSizer;
bBottomtBoxSizer = new wxBoxSizer( wxHORIZONTAL );
@@ -130,7 +134,6 @@ DIALOG_LIB_EDIT_TEXT_BASE::DIALOG_LIB_EDIT_TEXT_BASE( wxWindow* parent, wxWindow
this->SetSizer( bMainSizer );
this->Layout();
- bMainSizer->Fit( this );
// Connect Events
this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_LIB_EDIT_TEXT_BASE::OnCloseDialog ) );
diff --git a/eeschema/dialogs/dialog_lib_edit_text_base.fbp b/eeschema/dialogs/dialog_lib_edit_text_base.fbp
index 66f6695..b2005aa 100644
--- a/eeschema/dialogs/dialog_lib_edit_text_base.fbp
+++ b/eeschema/dialogs/dialog_lib_edit_text_base.fbp
@@ -44,7 +44,7 @@
<property name="minimum_size"></property>
<property name="name">DIALOG_LIB_EDIT_TEXT_BASE</property>
<property name="pos"></property>
- <property name="size">-1,-1</property>
+ <property name="size">615,343</property>
<property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
<property name="subclass">DIALOG_SHIM; dialog_shim.h</property>
<property name="title">Library Text Properties</property>
@@ -395,11 +395,11 @@
</object>
</object>
</object>
- <object class="sizeritem" expanded="0">
+ <object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag"></property>
<property name="proportion">0</property>
- <object class="wxBoxSizer" expanded="0">
+ <object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bTextSizeSizer</property>
<property name="orient">wxVERTICAL</property>
@@ -584,6 +584,89 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
+ <property name="flag">wxALL</property>
+ <property name="proportion">0</property>
+ <object class="wxStaticText" expanded="1">
+ <property name="BottomDockable">1</property>
+ <property name="LeftDockable">1</property>
+ <property name="RightDockable">1</property>
+ <property name="TopDockable">1</property>
+ <property name="aui_layer"></property>
+ <property name="aui_name"></property>
+ <property name="aui_position"></property>
+ <property name="aui_row"></property>
+ <property name="best_size"></property>
+ <property name="bg"></property>
+ <property name="caption"></property>
+ <property name="caption_visible">1</property>
+ <property name="center_pane">0</property>
+ <property name="close_button">1</property>
+ <property name="context_help"></property>
+ <property name="context_menu">1</property>
+ <property name="default_pane">0</property>
+ <property name="dock">Dock</property>
+ <property name="dock_fixed">0</property>
+ <property name="docking">Left</property>
+ <property name="enabled">1</property>
+ <property name="fg"></property>
+ <property name="floatable">1</property>
+ <property name="font"></property>
+ <property name="gripper">0</property>
+ <property name="hidden">0</property>
+ <property name="id">wxID_ANY</property>
+ <property name="label">Power component value text cannot be modified!</property>
+ <property name="max_size"></property>
+ <property name="maximize_button">0</property>
+ <property name="maximum_size"></property>
+ <property name="min_size"></property>
+ <property name="minimize_button">0</property>
+ <property name="minimum_size"></property>
+ <property name="moveable">1</property>
+ <property name="name">m_PowerComponentValues</property>
+ <property name="pane_border">1</property>
+ <property name="pane_position"></property>
+ <property name="pane_size"></property>
+ <property name="permission">protected</property>
+ <property name="pin_button">1</property>
+ <property name="pos"></property>
+ <property name="resize">Resizable</property>
+ <property name="show">1</property>
+ <property name="size"></property>
+ <property name="style"></property>
+ <property name="subclass"></property>
+ <property name="toolbar_pane">0</property>
+ <property name="tooltip"></property>
+ <property name="window_extra_style"></property>
+ <property name="window_name"></property>
+ <property name="window_style"></property>
+ <property name="wrap">-1</property>
+ <event name="OnChar"></event>
+ <event name="OnEnterWindow"></event>
+ <event name="OnEraseBackground"></event>
+ <event name="OnKeyDown"></event>
+ <event name="OnKeyUp"></event>
+ <event name="OnKillFocus"></event>
+ <event name="OnLeaveWindow"></event>
+ <event name="OnLeftDClick"></event>
+ <event name="OnLeftDown"></event>
+ <event name="OnLeftUp"></event>
+ <event name="OnMiddleDClick"></event>
+ <event name="OnMiddleDown"></event>
+ <event name="OnMiddleUp"></event>
+ <event name="OnMotion"></event>
+ <event name="OnMouseEvents"></event>
+ <event name="OnMouseWheel"></event>
+ <event name="OnPaint"></event>
+ <event name="OnRightDClick"></event>
+ <event name="OnRightDown"></event>
+ <event name="OnRightUp"></event>
+ <event name="OnSetFocus"></event>
+ <event name="OnSize"></event>
+ <event name="OnUpdateUI"></event>
+ </object>
+ </object>
+ <object class="sizeritem" expanded="1">
+ <property name="border">5</property>
<property name="flag">wxALIGN_CENTER|wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxBoxSizer" expanded="1">
diff --git a/eeschema/dialogs/dialog_lib_edit_text_base.h b/eeschema/dialogs/dialog_lib_edit_text_base.h
index e935857..c4d3805 100644
--- a/eeschema/dialogs/dialog_lib_edit_text_base.h
+++ b/eeschema/dialogs/dialog_lib_edit_text_base.h
@@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
-// C++ code generated with wxFormBuilder (version Jun 5 2014)
+// C++ code generated with wxFormBuilder (version Mar 13 2015)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
@@ -44,6 +44,7 @@ class DIALOG_LIB_EDIT_TEXT_BASE : public DIALOG_SHIM
wxButton* m_TextValueSelectButton;
wxStaticText* m_TextSizeText;
wxTextCtrl* m_TextSize;
+ wxStaticText* m_PowerComponentValues;
wxCheckBox* m_Orient;
wxStaticLine* m_staticline1;
wxCheckBox* m_CommonUnit;
@@ -65,7 +66,7 @@ class DIALOG_LIB_EDIT_TEXT_BASE : public DIALOG_SHIM
public:
- DIALOG_LIB_EDIT_TEXT_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Library Text Properties"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
+ DIALOG_LIB_EDIT_TEXT_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Library Text Properties"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 615,343 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_LIB_EDIT_TEXT_BASE();
};
diff --git a/eeschema/edit_component_in_schematic.cpp b/eeschema/edit_component_in_schematic.cpp
index 67c374f..3b9104a 100644
--- a/eeschema/edit_component_in_schematic.cpp
+++ b/eeschema/edit_component_in_schematic.cpp
@@ -60,16 +60,6 @@ void SCH_EDIT_FRAME::EditComponentFieldText( SCH_FIELD* aField )
fieldNdx = aField->GetId();
- if( fieldNdx == VALUE && part->IsPower() )
- {
- wxString msg = wxString::Format( _(
- "%s is a power component and it's value cannot be modified!\n\n"
- "You must create a new power component with the new value." ),
- GetChars( part->GetName() )
- );
- DisplayInfoMessage( this, msg );
- return;
- }
// Save old component in undo list if not already in edit, or moving.
if( aField->GetFlags() == 0 )
@@ -84,6 +74,13 @@ void SCH_EDIT_FRAME::EditComponentFieldText( SCH_FIELD* aField )
DIALOG_SCH_EDIT_ONE_FIELD dlg( this, title, aField );
+ // Value fields of power components cannot be modified. This will grey out
+ // the text box and display an explanation.
+ if( fieldNdx == VALUE && part->IsPower() )
+ {
+ dlg.SetPowerWarning( true );
+ }
+
//The diag may invoke a kiway player for footprint fields
//so we must use a quasimodal
int response = dlg.ShowQuasiModal();
@@ -120,12 +117,17 @@ void SCH_EDIT_FRAME::EditComponentFieldText( SCH_FIELD* aField )
DisplayError( this, _( "The reference field cannot be empty! No change" ) );
can_update = false;
}
- else if( fieldNdx == VALUE )
+ else if( fieldNdx == VALUE && ! part->IsPower() )
{
+ // Note that power components also should not have empty value fields - but
+ // since the user is forbidden from changing the value field here, if it
+ // were to happen somehow, it'd be awfully confusing if an error were to
+ // be displayed!
+
DisplayError( this, _( "The value field cannot be empty! No change" ) );
can_update = false;
}
- else
+ else if ( !( fieldNdx == VALUE && part->IsPower() ) )
{
dlg.SetTextField( wxT( "~" ) );
}
@@ -133,7 +135,7 @@ void SCH_EDIT_FRAME::EditComponentFieldText( SCH_FIELD* aField )
if( can_update )
{
- dlg.TransfertDataToField();
+ dlg.TransfertDataToField( /* aIncludeText = */ !( fieldNdx == VALUE && part->IsPower() ) );
OnModify();
m_canvas->Refresh();
}
Follow ups