diff --git a/change_log.txt b/change_log.txt index b2b5792244..5c47e30b8f 100644 --- a/change_log.txt +++ b/change_log.txt @@ -5,6 +5,12 @@ Started 2007-June-11 Please add newer entries at the top, list the date and your name with email address. +2008-Nov-25 UPDATE Dick Hollenbeck +================================================================================ ++eeschema + edit component in schematic editor. works except for field add, remove, move up. + + 2008-Nov-24 UPDATE Dick Hollenbeck ================================================================================ +eeschema diff --git a/common/wxwineda.cpp b/common/wxwineda.cpp index 185d30f95d..94e588c6ad 100644 --- a/common/wxwineda.cpp +++ b/common/wxwineda.cpp @@ -1,6 +1,6 @@ - /**********************************************************/ - /* wxwineda.cpp - fonctions des classes du type WinEDAxxxx */ - /**********************************************************/ +/**********************************************************/ +/* wxwineda.cpp - fonctions des classes du type WinEDAxxxx */ +/**********************************************************/ #ifdef __GNUG__ #pragma implementation @@ -10,23 +10,31 @@ #include "common.h" - /**********************************************************************************/ /* Classe WinEDA_EnterText pour entrer une ligne texte au clavier dans les frames */ /**********************************************************************************/ -WinEDA_EnterText::WinEDA_EnterText(wxWindow *parent, const wxString &Title, - const wxString & TextToEdit, wxBoxSizer * BoxSizer, const wxSize & Size ) +WinEDA_EnterText::WinEDA_EnterText( wxWindow* parent, + const wxString& Title, + const wxString& TextToEdit, + wxBoxSizer* BoxSizer, + const wxSize& Size ) { - m_Modify = FALSE; - if ( TextToEdit ) m_NewText = TextToEdit; + m_Modify = FALSE; + if( TextToEdit ) + m_NewText = TextToEdit; - m_Title = new wxStaticText(parent, -1, Title); - m_Title->SetForegroundColour(wxColour(200,0,0) ); - BoxSizer->Add(m_Title, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5); + m_Title = new wxStaticText( parent, -1, Title ); - m_FrameText = new wxTextCtrl(parent, -1, TextToEdit, wxDefaultPosition, Size); - m_FrameText->SetInsertionPoint(1); - BoxSizer->Add(m_FrameText, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5); + m_Title->SetForegroundColour( wxColour( 200, 0, 0 ) ); + BoxSizer->Add( m_Title, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP | wxADJUST_MINSIZE, 5 ); + + m_FrameText = new wxTextCtrl( parent, -1, TextToEdit, wxDefaultPosition, Size ); + + m_FrameText->SetInsertionPoint( 1 ); + BoxSizer->Add( m_FrameText, + 0, + wxGROW | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT | wxBOTTOM, + 5 ); } @@ -34,234 +42,289 @@ WinEDA_EnterText::WinEDA_EnterText(wxWindow *parent, const wxString &Title, wxString WinEDA_EnterText::GetValue() /****************************************/ { - m_Modify = m_FrameText->IsModified(); - m_NewText = m_FrameText->GetValue(); - return m_NewText; + m_Modify = m_FrameText->IsModified(); + m_NewText = m_FrameText->GetValue(); + return m_NewText; } -void WinEDA_EnterText::GetValue(char * buffer, int lenmax) + +void WinEDA_EnterText::GetValue( char* buffer, int lenmax ) { - m_Modify = m_FrameText->IsModified(); - if (buffer) - { - m_NewText = m_FrameText->GetValue(); - int ii, ll = m_NewText.Len(); - for ( ii = 0; ii < ll && ii < (lenmax-1); ii++ ); - buffer[ii] = m_NewText.GetChar(ii); - buffer[lenmax-1] = 0; - } + m_Modify = m_FrameText->IsModified(); + if( buffer ) + { + m_NewText = m_FrameText->GetValue(); + int ii, ll = m_NewText.Len(); + for( ii = 0; ii < ll && ii < (lenmax - 1); ii++ ) + ; + + buffer[ii] = m_NewText.GetChar( ii ); + buffer[lenmax - 1] = 0; + } } -void WinEDA_EnterText::SetValue(const wxString & new_text) + +void WinEDA_EnterText::SetValue( const wxString& new_text ) { - m_FrameText->SetValue(new_text); + m_FrameText->SetValue( new_text ); } -void WinEDA_EnterText::Enable(bool enbl) + +void WinEDA_EnterText::Enable( bool enbl ) { - m_Title->Enable(enbl); - m_FrameText->Enable(enbl); + m_Title->Enable( enbl ); + m_FrameText->Enable( enbl ); } /*********************************************************************/ /* Classe pour editer un texte graphique + dimension en INCHES ou MM */ /*********************************************************************/ -WinEDA_GraphicTextCtrl::WinEDA_GraphicTextCtrl(wxWindow *parent, - const wxString & Title, - const wxString & TextToEdit, int textsize, - int units, wxBoxSizer * BoxSizer, int framelen, - int internal_unit) +WinEDA_GraphicTextCtrl::WinEDA_GraphicTextCtrl( wxWindow* parent, + const wxString& Title, + const wxString& TextToEdit, int textsize, + int units, wxBoxSizer* BoxSizer, int framelen, + int internal_unit ) { - m_Units = units; - m_Internal_Unit = internal_unit; - m_Title = NULL; - // Limitation de la taille du texte a de valeurs raisonnables - if ( textsize < 10 ) textsize = 10; - if ( textsize > 3000 ) textsize = 3000; + m_Units = units; + m_Internal_Unit = internal_unit; + m_Title = NULL; - m_Title = new wxStaticText(parent, -1, Title); - BoxSizer->Add(m_Title, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5); + m_Title = new wxStaticText( parent, -1, Title ); - m_FrameText = new wxTextCtrl(parent, -1, TextToEdit); - BoxSizer->Add(m_FrameText, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5); + BoxSizer->Add( m_Title, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP | wxADJUST_MINSIZE, 5 ); - if ( ! Title.IsEmpty()) - { - wxString msg; msg = _("Size") + ReturnUnitSymbol(m_Units); - wxStaticText * text = new wxStaticText(parent, -1, msg); - BoxSizer->Add(text, 0, wxGROW|wxLEFT|wxRIGHT|wxADJUST_MINSIZE, 5); - } + m_FrameText = new wxTextCtrl( parent, -1, TextToEdit ); - wxString value; - value.Printf(( m_Internal_Unit > 1000 ) ? wxT("%.4f") : wxT("%.3f"), - To_User_Unit(m_Units, textsize, m_Internal_Unit) ); - m_FrameSize = new wxTextCtrl(parent, -1, value, wxDefaultPosition ,wxSize(70,-1)); - BoxSizer->Add(m_FrameSize, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5); + BoxSizer->Add( m_FrameText, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 ); + + if( !Title.IsEmpty() ) + { + wxString msg = _( "Size" ) + ReturnUnitSymbol( m_Units ); + wxStaticText* text = new wxStaticText( parent, -1, msg ); + + BoxSizer->Add( text, 0, wxGROW | wxLEFT | wxRIGHT | wxADJUST_MINSIZE, 5 ); + } + + wxString value = FormatSize( m_Internal_Unit, m_Units, textsize ); + + m_FrameSize = new wxTextCtrl( parent, -1, value, wxDefaultPosition, wxSize( 70, -1 ) ); + + BoxSizer->Add( m_FrameSize, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 ); } WinEDA_GraphicTextCtrl::~WinEDA_GraphicTextCtrl() { - delete m_FrameText; - delete m_Title; + /* no, these are deleted by the BoxSizer + delete m_FrameText; + delete m_Title; + */ } -void WinEDA_GraphicTextCtrl::SetTitle(const wxString & title) + +wxString WinEDA_GraphicTextCtrl::FormatSize( int internalUnit, int units, int textSize ) { - m_Title->SetLabel(title); + wxString value; + + // Limitation de la taille du texte a de valeurs raisonnables + if( textSize < 10 ) + textSize = 10; + + if( textSize > 3000 ) + textSize = 3000; + + value.Printf( ( internalUnit > 1000 ) ? wxT( "%.4f" ) : wxT( "%.3f" ), + To_User_Unit( units, textSize, internalUnit ) ); + + return value; } -void WinEDA_GraphicTextCtrl::SetValue(const wxString & value) + +void WinEDA_GraphicTextCtrl::SetTitle( const wxString& title ) { - m_FrameText->SetValue(value); + m_Title->SetLabel( title ); } -void WinEDA_GraphicTextCtrl::SetValue(int value) + +void WinEDA_GraphicTextCtrl::SetValue( const wxString& value ) { - wxString msg; - msg.Printf(( m_Internal_Unit > 1000 ) ? wxT("%.4f") : wxT("%.3f"), - To_User_Unit(m_Units, value, m_Internal_Unit) ); - m_FrameSize->SetValue(msg); + m_FrameText->SetValue( value ); +} + + +void WinEDA_GraphicTextCtrl::SetValue( int textSize ) +{ + wxString value = FormatSize( m_Internal_Unit, m_Units, textSize ); + m_FrameSize->SetValue( value ); } wxString WinEDA_GraphicTextCtrl::GetText() { -wxString text = m_FrameText->GetValue(); - return text; + wxString text = m_FrameText->GetValue(); + return text; } + +int WinEDA_GraphicTextCtrl::ParseSize( const wxString& sizeText, int internalUnit, int units ) +{ + int textsize; + + double dtmp; + + sizeText.ToDouble( &dtmp ); + + textsize = (int) From_User_Unit( units, dtmp, internalUnit ); + + // Limit to reasonable size + if( textsize < 10 ) + textsize = 10; + + if( textsize > 3000 ) + textsize = 3000; + + return textsize; +} + + int WinEDA_GraphicTextCtrl::GetTextSize() { -int textsize; -double dtmp; - - m_FrameSize->GetValue().ToDouble(&dtmp); - textsize = (int)From_User_Unit( m_Units, - dtmp, - m_Internal_Unit); - // Limitation de la taille du texte a de valeurs raisonnables - if ( textsize < 10 ) textsize = 10; - if ( textsize > 3000 ) textsize = 3000; - return textsize; + return ParseSize( m_FrameSize->GetValue(), m_Internal_Unit, m_Units ); } -void WinEDA_GraphicTextCtrl::Enable(bool state) + +void WinEDA_GraphicTextCtrl::Enable( bool state ) { - m_FrameText->Enable(state); + m_FrameText->Enable( state ); } - /*****************************************************************/ /* Classe pour afficher et editer une coordonnée en INCHES ou MM */ /*****************************************************************/ -WinEDA_PositionCtrl::WinEDA_PositionCtrl(wxWindow *parent, const wxString & title, - const wxPoint & pos_to_edit, int units, wxBoxSizer * BoxSizer, - int internal_unit ) +WinEDA_PositionCtrl::WinEDA_PositionCtrl( wxWindow* parent, + const wxString& title, + const wxPoint& pos_to_edit, + int units, + wxBoxSizer* BoxSizer, + int internal_unit ) { -wxString text; + wxString text; - m_Units = units; - m_Internal_Unit = internal_unit; - if ( title.IsEmpty() ) text = _("Pos "); - else text = title; - text += _("X") + ReturnUnitSymbol(m_Units); - m_TextX = new wxStaticText(parent, -1, text ); - BoxSizer->Add(m_TextX, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5); - m_FramePosX = new wxTextCtrl(parent, -1, wxEmptyString, wxDefaultPosition ); - BoxSizer->Add(m_FramePosX, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5); + m_Units = units; + m_Internal_Unit = internal_unit; + if( title.IsEmpty() ) + text = _( "Pos " ); + else + text = title; + text += _( "X" ) + ReturnUnitSymbol( m_Units ); + m_TextX = new wxStaticText( parent, -1, text ); + + BoxSizer->Add( m_TextX, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP | wxADJUST_MINSIZE, 5 ); + m_FramePosX = new wxTextCtrl( parent, -1, wxEmptyString, wxDefaultPosition ); + + BoxSizer->Add( m_FramePosX, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 ); - if ( title.IsEmpty() ) text = _("Pos "); - else text = title; - text += _("Y") + ReturnUnitSymbol(m_Units); - m_TextY = new wxStaticText(parent, -1, text ); - BoxSizer->Add(m_TextY, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5); + if( title.IsEmpty() ) + text = _( "Pos " ); + else + text = title; + text += _( "Y" ) + ReturnUnitSymbol( m_Units ); + m_TextY = new wxStaticText( parent, -1, text ); - m_FramePosY = new wxTextCtrl(parent, -1, wxEmptyString ); - BoxSizer->Add(m_FramePosY, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5); - - SetValue(pos_to_edit.x, pos_to_edit.y); + BoxSizer->Add( m_TextY, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP | wxADJUST_MINSIZE, 5 ); + + m_FramePosY = new wxTextCtrl( parent, -1, wxEmptyString ); + + BoxSizer->Add( m_FramePosY, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 ); + + SetValue( pos_to_edit.x, pos_to_edit.y ); } WinEDA_PositionCtrl::~WinEDA_PositionCtrl() { - delete m_TextX; - delete m_TextY; - delete m_FramePosX; - delete m_FramePosY; + delete m_TextX; + delete m_TextY; + delete m_FramePosX; + delete m_FramePosY; } + /******************************************/ wxPoint WinEDA_PositionCtrl::GetValue() /******************************************/ + /* Retourne (en unites internes) les coordonnes entrees (en unites utilisateur) -*/ + */ { -wxPoint coord; -double value = 0; + wxPoint coord; + double value = 0; - m_FramePosX->GetValue().ToDouble(&value); - coord.x = From_User_Unit(m_Units, value, m_Internal_Unit); - m_FramePosY->GetValue().ToDouble(&value); - coord.y = From_User_Unit(m_Units, value, m_Internal_Unit); + m_FramePosX->GetValue().ToDouble( &value ); + coord.x = From_User_Unit( m_Units, value, m_Internal_Unit ); + m_FramePosY->GetValue().ToDouble( &value ); + coord.y = From_User_Unit( m_Units, value, m_Internal_Unit ); - return coord; + return coord; } /************************************************************/ -void WinEDA_PositionCtrl::Enable(bool x_win_on, bool y_win_on) +void WinEDA_PositionCtrl::Enable( bool x_win_on, bool y_win_on ) /************************************************************/ { - m_FramePosX->Enable(x_win_on); - m_FramePosY->Enable(y_win_on); + m_FramePosX->Enable( x_win_on ); + m_FramePosY->Enable( y_win_on ); } + /***********************************************************/ -void WinEDA_PositionCtrl::SetValue(int x_value, int y_value) +void WinEDA_PositionCtrl::SetValue( int x_value, int y_value ) /***********************************************************/ { -wxString msg; - - m_Pos_To_Edit.x = x_value; - m_Pos_To_Edit.y = y_value; - - msg = ReturnStringFromValue(m_Units, m_Pos_To_Edit.x, m_Internal_Unit); - m_FramePosX->Clear(); - m_FramePosX->SetValue(msg); - - msg = ReturnStringFromValue(m_Units, m_Pos_To_Edit.y, m_Internal_Unit); - m_FramePosY->Clear(); - m_FramePosY->SetValue(msg); + wxString msg; + + m_Pos_To_Edit.x = x_value; + m_Pos_To_Edit.y = y_value; + + msg = ReturnStringFromValue( m_Units, m_Pos_To_Edit.x, m_Internal_Unit ); + m_FramePosX->Clear(); + m_FramePosX->SetValue( msg ); + + msg = ReturnStringFromValue( m_Units, m_Pos_To_Edit.y, m_Internal_Unit ); + m_FramePosY->Clear(); + m_FramePosY->SetValue( msg ); } - /*******************/ - /* WinEDA_SizeCtrl */ - /*******************/ -WinEDA_SizeCtrl::WinEDA_SizeCtrl(wxWindow *parent, const wxString & title, - const wxSize & size_to_edit, - int units, wxBoxSizer * BoxSizer, - int internal_unit): - WinEDA_PositionCtrl(parent, title, - wxPoint(size_to_edit.x, size_to_edit.y), - units, BoxSizer, internal_unit) + +/*******************/ +/* WinEDA_SizeCtrl */ +/*******************/ +WinEDA_SizeCtrl::WinEDA_SizeCtrl( wxWindow* parent, const wxString& title, + const wxSize& size_to_edit, + int units, wxBoxSizer* BoxSizer, + int internal_unit ) : + WinEDA_PositionCtrl( parent, title, + wxPoint( size_to_edit.x, size_to_edit.y ), + units, BoxSizer, internal_unit ) { } + /*************************************/ wxSize WinEDA_SizeCtrl::GetValue() /*************************************/ { -wxPoint pos = WinEDA_PositionCtrl::GetValue(); -wxSize size; - size.x = pos.x; - size.y = pos.y; - return size; + wxPoint pos = WinEDA_PositionCtrl::GetValue(); + wxSize size; + + size.x = pos.x; + size.y = pos.y; + return size; } @@ -270,110 +333,127 @@ wxSize size; /***********************************************************************/ /* Unites: - si units = 0 : unite = inch - si units = 1 : unite = mm - si units >1 : affichage direct -*/ -WinEDA_ValueCtrl::WinEDA_ValueCtrl(wxWindow *parent, const wxString & title, - int value, int units, wxBoxSizer *BoxSizer, - int internal_unit ) + * si units = 0 : unite = inch + * si units = 1 : unite = mm + * si units >1 : affichage direct + */ +WinEDA_ValueCtrl::WinEDA_ValueCtrl( wxWindow* parent, const wxString& title, + int value, int units, wxBoxSizer* BoxSizer, + int internal_unit ) { -wxString label = title; + wxString label = title; - m_Units = units; - m_Internal_Unit = internal_unit; - m_Value = value; - label += ReturnUnitSymbol(m_Units); + m_Units = units; + m_Internal_Unit = internal_unit; + m_Value = value; + label += ReturnUnitSymbol( m_Units ); - m_Text = new wxStaticText(parent, -1, label); - BoxSizer->Add(m_Text, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5); - -wxString stringvalue = ReturnStringFromValue(m_Units, m_Value,m_Internal_Unit); - m_ValueCtrl = new wxTextCtrl(parent, -1, stringvalue); - BoxSizer->Add(m_ValueCtrl, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5); + m_Text = new wxStaticText( parent, -1, label ); + + BoxSizer->Add( m_Text, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP | wxADJUST_MINSIZE, 5 ); + + wxString stringvalue = ReturnStringFromValue( m_Units, m_Value, m_Internal_Unit ); + m_ValueCtrl = new wxTextCtrl( parent, -1, stringvalue ); + + BoxSizer->Add( m_ValueCtrl, + 0, + wxGROW | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT | wxBOTTOM, + 5 ); } + WinEDA_ValueCtrl::~WinEDA_ValueCtrl() { - delete m_ValueCtrl; - delete m_Text; + delete m_ValueCtrl; + delete m_Text; } + /***********************************/ int WinEDA_ValueCtrl::GetValue() /***********************************/ { -int coord; -wxString txtvalue = m_ValueCtrl->GetValue(); + int coord; + wxString txtvalue = m_ValueCtrl->GetValue(); - coord = ReturnValueFromString(m_Units, txtvalue, m_Internal_Unit); - return coord; + coord = ReturnValueFromString( m_Units, txtvalue, m_Internal_Unit ); + return coord; } + /********************************************/ -void WinEDA_ValueCtrl::SetValue(int new_value) +void WinEDA_ValueCtrl::SetValue( int new_value ) /********************************************/ { -wxString buffer; - m_Value = new_value; + wxString buffer; - buffer = ReturnStringFromValue(m_Units, m_Value, m_Internal_Unit); - m_ValueCtrl->SetValue(buffer); + m_Value = new_value; + + buffer = ReturnStringFromValue( m_Units, m_Value, m_Internal_Unit ); + m_ValueCtrl->SetValue( buffer ); } + /* Active ou desactive la frame: */ -void WinEDA_ValueCtrl::Enable(bool enbl) +void WinEDA_ValueCtrl::Enable( bool enbl ) { - m_ValueCtrl->Enable(enbl); - m_Text->Enable(enbl); + m_ValueCtrl->Enable( enbl ); + m_Text->Enable( enbl ); } + /***************************************************************/ /* Classe pour afficher et editer une valeur en double flottant*/ /***************************************************************/ -WinEDA_DFloatValueCtrl::WinEDA_DFloatValueCtrl(wxWindow *parent, const wxString & title, - double value, wxBoxSizer * BoxSizer ) +WinEDA_DFloatValueCtrl::WinEDA_DFloatValueCtrl( wxWindow* parent, const wxString& title, + double value, wxBoxSizer* BoxSizer ) { -wxString buffer; -wxString label = title; + wxString buffer; + wxString label = title; - m_Value = value; + m_Value = value; - m_Text = new wxStaticText(parent, -1, label ); - BoxSizer->Add(m_Text, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5); + m_Text = new wxStaticText( parent, -1, label ); - buffer.Printf(wxT("%lf"), m_Value); - m_ValueCtrl = new wxTextCtrl(parent, -1, buffer ); - BoxSizer->Add(m_ValueCtrl, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5); + BoxSizer->Add( m_Text, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 ); + + buffer.Printf( wxT( "%lf" ), m_Value ); + m_ValueCtrl = new wxTextCtrl( parent, -1, buffer ); + + BoxSizer->Add( m_ValueCtrl, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 ); } + WinEDA_DFloatValueCtrl::~WinEDA_DFloatValueCtrl() { - delete m_ValueCtrl; - delete m_Text; + delete m_ValueCtrl; + delete m_Text; } + double WinEDA_DFloatValueCtrl::GetValue() { -double coord = 0; + double coord = 0; - m_ValueCtrl->GetValue().ToDouble(&coord); - return coord; + m_ValueCtrl->GetValue().ToDouble( &coord ); + return coord; } -void WinEDA_DFloatValueCtrl::SetValue(double new_value) + +void WinEDA_DFloatValueCtrl::SetValue( double new_value ) { -wxString buffer; - m_Value = new_value; + wxString buffer; - buffer.Printf( wxT("%lf"), m_Value); - m_ValueCtrl->SetValue(buffer); + m_Value = new_value; + + buffer.Printf( wxT( "%lf" ), m_Value ); + m_ValueCtrl->SetValue( buffer ); } + /* Active ou desactive la frame: */ -void WinEDA_DFloatValueCtrl::Enable(bool enbl) +void WinEDA_DFloatValueCtrl::Enable( bool enbl ) { - m_ValueCtrl->Enable(enbl); - m_Text->Enable(enbl); + m_ValueCtrl->Enable( enbl ); + m_Text->Enable( enbl ); } - diff --git a/eeschema/component_class.cpp b/eeschema/component_class.cpp index 040c30348a..400077a20d 100644 --- a/eeschema/component_class.cpp +++ b/eeschema/component_class.cpp @@ -683,7 +683,8 @@ int SCH_COMPONENT::GetRotationMiroir() { if( memcmp( TempMat, m_Transform, sizeof(MatNormal) ) == 0 ) { - found = TRUE; break; + found = TRUE; + break; } SetRotationMiroir( CMP_ROTATE_COUNTERCLOCKWISE ); } @@ -697,7 +698,8 @@ int SCH_COMPONENT::GetRotationMiroir() { if( memcmp( TempMat, m_Transform, sizeof(MatNormal) ) == 0 ) { - found = TRUE; break; + found = TRUE; + break; } SetRotationMiroir( CMP_ROTATE_COUNTERCLOCKWISE ); } @@ -712,7 +714,8 @@ int SCH_COMPONENT::GetRotationMiroir() { if( memcmp( TempMat, m_Transform, sizeof(MatNormal) ) == 0 ) { - found = TRUE; break; + found = TRUE; + break; } SetRotationMiroir( CMP_ROTATE_COUNTERCLOCKWISE ); } @@ -726,7 +729,8 @@ int SCH_COMPONENT::GetRotationMiroir() } else { - wxBell(); return CMP_NORMAL; + wxBell(); + return CMP_NORMAL; } } diff --git a/eeschema/component_class.h b/eeschema/component_class.h index 0a5fb7737f..7b4d76632d 100644 --- a/eeschema/component_class.h +++ b/eeschema/component_class.h @@ -193,6 +193,12 @@ public: */ void AddField( const SCH_CMP_FIELD& aField ); + void SetFields( const SCH_CMP_FIELDS& aFields ) + { + m_Fields = aFields; // vector copying, length is changed possibly + } + + /** * Function GetFieldCount * returns the number of fields in this component. diff --git a/eeschema/dialog_edit_component_in_schematic.cpp b/eeschema/dialog_edit_component_in_schematic.cpp index e65427a2ac..4c75ac4ef8 100644 --- a/eeschema/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialog_edit_component_in_schematic.cpp @@ -15,6 +15,9 @@ #include "dialog_edit_component_in_schematic.h" +int DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::s_SelectedRow; + + /**********************************************************************/ void InstallCmpeditFrame( WinEDA_SchematicFrame* parent, wxPoint& pos, SCH_COMPONENT* aComponent ) @@ -35,8 +38,6 @@ void InstallCmpeditFrame( WinEDA_SchematicFrame* parent, wxPoint& pos, frame->InitBuffers( aComponent ); -// frame->Layout(); - frame->ShowModal(); frame->Destroy(); } @@ -45,54 +46,12 @@ void InstallCmpeditFrame( WinEDA_SchematicFrame* parent, wxPoint& pos, parent->DrawPanel->m_IgnoreMouseEvents = FALSE; } - -#if 0 -/*********************************************************************/ -void SCH_CMP_FIELD::Place( WinEDA_SchematicFrame* frame, wxDC* DC ) -/*********************************************************************/ -{ - frame->DrawPanel->ManageCurseur = NULL; - frame->DrawPanel->ForceCloseManageCurseur = NULL; - - SCH_COMPONENT* component = (SCH_COMPONENT*) m_Parent; - - // save old component in undo list - if( g_ItemToUndoCopy && g_ItemToUndoCopy->Type() == component->Type() ) - { - component->SwapData( (SCH_COMPONENT*) g_ItemToUndoCopy ); - - frame->SaveCopyInUndoList( component, IS_CHANGED ); - - component->SwapData( (SCH_COMPONENT*) g_ItemToUndoCopy ); - } - - m_AddExtraText = 0; - if( m_FieldId == REFERENCE ) - { - EDA_LibComponentStruct* part; - - part = FindLibPart( component->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); - if( part ) - { - if( part->m_UnitCount > 1 ) - m_AddExtraText = 1; - } - } - - Draw( frame->DrawPanel, DC, wxPoint(0,0), GR_DEFAULT_DRAWMODE ); - m_Flags = 0; - frame->GetScreen()->SetCurItem( NULL ); - frame->GetScreen()->SetModify(); -} -#endif - - DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::DIALOG_EDIT_COMPONENT_IN_SCHEMATIC( wxWindow* parent ) : DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP( parent ) { m_Parent = (WinEDA_SchematicFrame*) parent; - m_SelectedRow = 0; + m_LibEntry = 0; wxListItem columnLabel; @@ -104,9 +63,18 @@ DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::DIALOG_EDIT_COMPONENT_IN_SCHEMATIC( wxWindow columnLabel.SetText( _("Value") ); fieldListCtrl->InsertColumn( 1, columnLabel ); - // these must go here late in the game. - fieldListCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE ); - fieldListCtrl->SetColumnWidth( 1, wxLIST_AUTOSIZE ); + wxString label = _( "Size" ) + ReturnUnitSymbol( g_UnitMetric ); + textSizeLabel->SetLabel( label ); + + label = _( "Pos " ); + label += _( "X" ); + label += ReturnUnitSymbol( g_UnitMetric ); + posXLabel->SetLabel( label ); + + label = _( "Pos " ); + label += _( "Y" ); + label += ReturnUnitSymbol( g_UnitMetric ); + posYLabel->SetLabel( label ); copySelectedFieldToPanel(); @@ -117,7 +85,9 @@ DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::DIALOG_EDIT_COMPONENT_IN_SCHEMATIC( wxWindow void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnListItemDeselected( wxListEvent& event ) { D(printf("OnListItemDeselected()\n");) - copyPanelToSelectedField(); + + if( !copyPanelToSelectedField() ) + event.Skip(); // do not go to the next row } @@ -125,315 +95,22 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnListItemSelected( wxListEvent& event { D(printf("OnListItemSelected()\n");) - m_SelectedRow = event.GetIndex(); + // remember the selected row, statically + s_SelectedRow = event.GetIndex(); copySelectedFieldToPanel(); } -void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::setSelectedFieldNdx( int aFieldNdx ) +void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnCancelButtonClick( wxCommandEvent& event ) { - fieldListCtrl->SetItemState( aFieldNdx, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); - fieldListCtrl->EnsureVisible( aFieldNdx ); -} - - -int DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::getSelectedFieldNdx() -{ - return m_SelectedRow; -} - - -#if 0 -/*****************************************************************************/ -void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::SetInitCmp( wxCommandEvent& event ) -/*****************************************************************************/ - -/* Replace le composant en position normale, dimensions et positions - * fields comme definies en librairie - */ -{ - EDA_LibComponentStruct* Entry; - - if( m_Cmp == NULL ) - return; - - Entry = FindLibPart( m_Cmp->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); - - if( Entry == NULL ) - return; - - wxClientDC dc( m_Parent->DrawPanel ); - m_Parent->DrawPanel->PrepareGraphicContext( &dc ); - - RedrawOneStruct( m_Parent->DrawPanel, &dc, m_Cmp, g_XorMode ); - - /* Mise aux valeurs par defaut des champs et orientation */ - m_Cmp->GetField( REFERENCE )->m_Pos.x = - Entry->m_Prefix.m_Pos.x + m_Cmp->m_Pos.x; - - m_Cmp->GetField( REFERENCE )->m_Pos.y = - Entry->m_Prefix.m_Pos.y + m_Cmp->m_Pos.y; - - m_Cmp->GetField( REFERENCE )->m_Orient = Entry->m_Prefix.m_Orient; - m_Cmp->GetField( REFERENCE )->m_Size = Entry->m_Prefix.m_Size; - m_Cmp->GetField( REFERENCE )->m_HJustify = Entry->m_Prefix.m_HJustify; - m_Cmp->GetField( REFERENCE )->m_VJustify = Entry->m_Prefix.m_VJustify; - - m_Cmp->GetField( VALUE )->m_Pos.x = - Entry->m_Name.m_Pos.x + m_Cmp->m_Pos.x; - - m_Cmp->GetField( VALUE )->m_Pos.y = - Entry->m_Name.m_Pos.y + m_Cmp->m_Pos.y; - - m_Cmp->GetField( VALUE )->m_Orient = Entry->m_Name.m_Orient; - m_Cmp->GetField( VALUE )->m_Size = Entry->m_Name.m_Size; - m_Cmp->GetField( VALUE )->m_HJustify = Entry->m_Name.m_HJustify; - m_Cmp->GetField( VALUE )->m_VJustify = Entry->m_Name.m_VJustify; - - m_Cmp->SetRotationMiroir( CMP_NORMAL ); - - m_Parent->GetScreen()->SetModify(); - - RedrawOneStruct( m_Parent->DrawPanel, &dc, m_Cmp, GR_DEFAULT_DRAWMODE ); EndModal( 1 ); } -#endif -/*******************************************************************************/ -void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::InitBuffers( SCH_COMPONENT* aComponent ) -/*******************************************************************************/ +void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyPanelToOptions() { - m_Cmp = aComponent; - - // copy all the fields to a work area - m_FieldsBuf = aComponent->m_Fields; - - m_FieldsBuf[REFERENCE].m_Text = m_Cmp->GetRef( m_Parent->GetSheet() ); - - for( int ii = 0; ii < aComponent->GetFieldCount(); ++ii ) - { - // make the editable field position relative to the component - m_FieldsBuf[ii].m_Pos -= m_Cmp->m_Pos; - - setRowItem( ii, m_FieldsBuf[ii] ); - } - - setSelectedFieldNdx( REFERENCE ); -} - - -void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::setRowItem( int aFieldNdx, const SCH_CMP_FIELD& aField ) -{ - wxASSERT( aFieldNdx >= 0 ); - - // insert blanks if aFieldNdx is referencing a yet to be defined row - while( aFieldNdx >= fieldListCtrl->GetItemCount() ) - { - long ndx = fieldListCtrl->InsertItem( fieldListCtrl->GetItemCount(), wxEmptyString ); - - wxASSERT( ndx >= 0 ); - - fieldListCtrl->SetItem( ndx, 1, wxEmptyString ); - } - - fieldListCtrl->SetItem( aFieldNdx, 0, aField.m_Name ); - fieldListCtrl->SetItem( aFieldNdx, 1, aField.m_Text ); - - // recompute the column widths here, after setting texts - fieldListCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE ); - fieldListCtrl->SetColumnWidth( 1, wxLIST_AUTOSIZE ); -} - - - -/****************************************************************/ -void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copySelectedFieldToPanel() -/****************************************************************/ -{ - unsigned fieldNdx = getSelectedFieldNdx(); - - if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too - return; - - SCH_CMP_FIELD& field = m_FieldsBuf[fieldNdx]; - - fieldNameTextCtrl->SetValue( field.m_Name ); - - // if fieldNdx == REFERENCE, VALUE, FOOTPRINT, or DATASHEET, then disable editing - fieldNameTextCtrl->Enable( fieldNdx >= FIELD1 ); - - fieldValueTextCtrl->SetValue( field.m_Text ); - -/* - if( fieldNdx == VALUE && m_LibEntry && m_LibEntry->m_Options == ENTRY_POWER ) - m_FieldTextCtrl->Enable( FALSE ); -*/ - - showCheckBox->SetValue( !(field.m_Attributs & TEXT_NO_VISIBLE) ); - - // If the field value is empty and the position is zero, we set the - // initial position as a small offset from the ref field, and orient - // it the same as the ref field. That is likely to put it at least - // close to the desired position. - if( field.m_Pos == wxPoint( 0, 0 ) && field.m_Text.IsEmpty() ) - { - wxString dim; - - // @todo look at the dedicated position control for this. - dim.Printf( wxT("%d"), m_FieldsBuf[REFERENCE].m_Pos.x + (fieldNdx-FIELD1+1)*100 ); - posXTextCtrl->SetValue( dim ); - - dim.Printf( wxT("%d"), m_FieldsBuf[REFERENCE].m_Pos.y + (fieldNdx-FIELD1+1)*100 ); - posYTextCtrl->SetValue( dim ); - } - else - { - wxString dim; - - dim.Printf( wxT("%d"), field.m_Pos.x ); - posXTextCtrl->SetValue( dim ); - - dim.Printf( wxT("%d"), field.m_Pos.y ); - posYTextCtrl->SetValue( dim ); - } - - rotateCheckBox->SetValue( field.m_Orient == TEXT_ORIENT_VERT ); - -#if 0 - - m_FieldNameCtrl->SetValue( m_FieldName[fieldNdx] ); - - m_FieldTextCtrl->SetValue( m_FieldText[fieldNdx] ); - m_FieldTextCtrl->SetValue( m_FieldSize[fieldNdx] ); -#endif -} - - -/*****************************************************************/ -void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyPanelToSelectedField() -/*****************************************************************/ -{ - unsigned fieldNdx = getSelectedFieldNdx(); - - if( fieldNdx >= m_FieldsBuf.size() ) - return; - - SCH_CMP_FIELD& field = m_FieldsBuf[fieldNdx]; - - field.m_Name = fieldNameTextCtrl->GetValue(); - field.m_Text = fieldValueTextCtrl->GetValue(); - -// field.m_Size = - -// m_FieldPosition[id] = m_FieldPositionCtrl->GetValue(); -// m_FieldSize[id] = m_FieldTextCtrl->GetTextSize(); -} - - -#if 0 - -/*************************************************************/ -void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::fillTableModel() -/*************************************************************/ -{ -} - - -/**********************************************************/ -void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::buildPanelBasic() -/**********************************************************/ - -/* create the basic panel for component properties editing - */ -{ - int Nb_Max_Unit = m_SelectUnit->GetCount(); - int ii; - - int nb_units = m_LibEntry ? MAX( m_LibEntry->m_UnitCount, 1 ) : 0; - - // Disable non existant units selection buttons - for( ii = nb_units; ii < Nb_Max_Unit; ii++ ) - { - m_SelectUnit->Enable( ii, FALSE ); - } - - if( m_Cmp->m_Multi <= Nb_Max_Unit ) - m_SelectUnit->SetSelection( m_Cmp->m_Multi - 1 ); - - ii = m_Cmp->GetRotationMiroir() & ~(CMP_MIROIR_X | CMP_MIROIR_Y); - - if( ii == CMP_ORIENT_90 ) - m_OrientUnit->SetSelection( 1 ); - else if( ii == CMP_ORIENT_180 ) - m_OrientUnit->SetSelection( 2 ); - else if( ii == CMP_ORIENT_270 ) - m_OrientUnit->SetSelection( 3 ); - - ii = m_Cmp->GetRotationMiroir() & (CMP_MIROIR_X | CMP_MIROIR_Y); - if( ii == CMP_MIROIR_X ) - m_MirrorUnit->SetSelection( 1 ); - else if( ii == CMP_MIROIR_Y ) - m_MirrorUnit->SetSelection( 2 ); - - // Positionnement de la selection normal/convert - if( m_Cmp->m_Convert > 1 ) - m_ConvertButt->SetValue( TRUE ); - - if( (m_LibEntry == NULL) || LookForConvertPart( m_LibEntry ) <= 1 ) - { - m_ConvertButt->Enable( FALSE ); - } - - // Show the "Parts Locked" option: - if( !m_LibEntry || !m_LibEntry->m_UnitSelectionLocked ) - { - m_MsgPartLocked->Show( false ); - } - - // Positionnement de la reference en librairie - m_RefInLib->SetValue( m_Cmp->m_ChipName ); -} - - -/*************************************************************************/ -void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::selectNewField( wxCommandEvent& event ) -/*************************************************************************/ - -/* called when changing the current field selected - * Save the current field settings in buffer and display the new one - */ -{ - CopyPanelFieldToData(); - m_CurrentFieldId = m_FieldSelection->GetSelection(); - CopyDataToPanelField(); -} - - -/***********************************************************************************/ -void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::ComponentPropertiesAccept( wxCommandEvent& event ) -/***********************************************************************************/ - -/* Update the new parameters for the current edited component - */ -{ - wxPoint cmp_pos = m_Cmp->m_Pos; - wxClientDC dc( m_Parent->DrawPanel ); - wxString newname; - - /* save old cmp in undo list if not already in edit, or moving ... */ - if( m_Cmp->m_Flags == 0 ) - m_Parent->SaveCopyInUndoList( m_Cmp, IS_CHANGED ); - - CopyPanelFieldToData(); - - m_Parent->DrawPanel->PrepareGraphicContext( &dc ); - - - RedrawOneStruct( m_Parent->DrawPanel, &dc, m_Cmp, g_XorMode ); - - newname = m_RefInLib->GetValue(); + wxString newname = chipnameTextCtrl->GetValue(); newname.MakeUpper(); newname.Replace( wxT( " " ), wxT( "_" ) ); @@ -455,20 +132,20 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::ComponentPropertiesAccept( wxCommandEve } // Mise a jour de la representation: - if( m_ConvertButt->IsEnabled() ) - (m_ConvertButt->GetValue() == TRUE) ? - m_Cmp->m_Convert = 2 : m_Cmp->m_Convert = 1; + if( convertCheckBox->IsEnabled() ) + { + m_Cmp->m_Convert = convertCheckBox->GetValue() ? 2 : 1; + } //Set the part selection in multiple part per pakcage if( m_Cmp->m_Multi ) { - int unit_selection = m_SelectUnit->GetSelection() + 1; + int unit_selection = unitChoice->GetCurrentSelection() + 1; m_Cmp->SetUnitSelection( m_Parent->GetSheet(), unit_selection ); m_Cmp->m_Multi = unit_selection; } - //Mise a jour de l'orientation: - switch( m_OrientUnit->GetSelection() ) + switch( orientationRadioBox->GetSelection() ) { case 0: m_Cmp->SetRotationMiroir( CMP_ORIENT_0 ); @@ -487,7 +164,8 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::ComponentPropertiesAccept( wxCommandEve break; } - switch( m_MirrorUnit->GetSelection() ) + int mirror = mirrorRadioBox->GetSelection(); + switch( mirror ) { case 0: break; @@ -500,53 +178,353 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::ComponentPropertiesAccept( wxCommandEve m_Cmp->SetRotationMiroir( CMP_MIROIR_Y ); break; } +} - // Mise a jour des textes (update the texts) - for( int ii = REFERENCE; ii < NUMBER_OF_FIELDS; ii++ ) +void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnOKButtonClick( wxCommandEvent& event ) +{ + if( !copyPanelToSelectedField() ) + return; + + copyPanelToOptions(); + + /* save old cmp in undo list if not already in edit, or moving ... */ + if( m_Cmp->m_Flags == 0 ) + m_Parent->SaveCopyInUndoList( m_Cmp, IS_CHANGED ); + + // change all field positions from relative to absolute + for( unsigned i=0; iSetRef(m_Parent->GetSheet(), m_FieldText[ii]); - } - else if( ii == VALUE ) // la valeur ne peut etre vide et ne peut etre change sur un POWER - { - EDA_LibComponentStruct* Entry = FindLibPart( m_Cmp->m_ChipName.GetData( - ), wxEmptyString, FIND_ROOT ); - if( Entry && (Entry->m_Options == ENTRY_POWER) ) - m_Cmp->GetField( ii )->m_Text = m_Cmp->m_ChipName; - else if( !m_FieldText[ii].IsEmpty() ) - { - m_Cmp->GetField( ii )->m_Text = m_FieldText[ii]; - } - } - else - m_Cmp->GetField( ii )->m_Text = m_FieldText[ii]; - - if( ii >= FIELD1 && m_FieldName[ii] != ReturnDefaultFieldName( ii ) ) - m_Cmp->GetField( ii )->m_Name = m_FieldName[ii]; - else - m_Cmp->GetField( ii )->m_Name.Empty(); - - m_Cmp->GetField( ii )->m_Size.x = - m_Cmp->GetField( ii )->m_Size.y = m_FieldSize[ii]; - if( m_FieldFlags[ii] ) - m_Cmp->GetField( ii )->m_Attributs &= ~TEXT_NO_VISIBLE; - else - m_Cmp->GetField( ii )->m_Attributs |= TEXT_NO_VISIBLE; - m_Cmp->GetField( ii )->m_Orient = m_FieldOrient[ii] ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ; - m_Cmp->GetField( ii )->m_Pos = m_FieldPosition[ii]; - m_Cmp->GetField( ii )->m_Pos.x += cmp_pos.x; - m_Cmp->GetField( ii )->m_Pos.y += cmp_pos.y; + m_FieldsBuf[i].m_Pos += m_Cmp->m_Pos; } + // delete any fields with no name + for( unsigned i=FIELD1; im_ChipName.GetData(), wxEmptyString, FIND_ROOT ); + + if( entry && entry->m_Options == ENTRY_POWER ) + m_FieldsBuf[VALUE].m_Text = m_Cmp->m_ChipName; + + // copy all the fields back, and change the length of m_Fields. + m_Cmp->SetFields( m_FieldsBuf ); + m_Parent->GetScreen()->SetModify(); - RedrawOneStruct( m_Parent->DrawPanel, &dc, m_Cmp, GR_DEFAULT_DRAWMODE ); - m_Parent->TestDanglingEnds( m_Parent->GetScreen()->EEDrawList, &dc ); + m_Parent->TestDanglingEnds( m_Parent->GetScreen()->EEDrawList, NULL ); + + m_Parent->DrawPanel->Refresh( TRUE ); EndModal( 0 ); } + +void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::setSelectedFieldNdx( int aFieldNdx ) +{ + /* deselect old selection, but I think this is done by single selection flag within fieldListCtrl + fieldListCtrl->SetItemState( s_SelectedRow, 0, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED); + */ + + if( aFieldNdx >= (int) m_FieldsBuf.size() ) + aFieldNdx = m_FieldsBuf.size() - 1; + + if( aFieldNdx < 0 ) + aFieldNdx = 0; + + fieldListCtrl->SetItemState( aFieldNdx, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); + fieldListCtrl->EnsureVisible( aFieldNdx ); + + s_SelectedRow = aFieldNdx; +} + + +int DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::getSelectedFieldNdx() +{ + return s_SelectedRow; +} + + +/*******************************************************************************/ +void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::InitBuffers( SCH_COMPONENT* aComponent ) +/*******************************************************************************/ +{ + m_Cmp = aComponent; + + m_LibEntry = FindLibPart( m_Cmp->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); + +#if 0 && defined(DEBUG) + for( int i=0; iGetFieldCount(); ++i ) + { + printf("Orig[%d] (x=%d, y=%d)\n", i, aComponent->m_Fields[i].m_Pos.x, + aComponent->m_Fields[i].m_Pos.y ); + } #endif + + // copy all the fields to a work area + m_FieldsBuf = aComponent->m_Fields; + +#if 0 && defined(DEBUG) + for( unsigned i=0; iGetRef( m_Parent->GetSheet() ); + + for( unsigned i=0; im_Pos; + + setRowItem( i, m_FieldsBuf[i] ); + } + +#if 0 && defined(DEBUG) + for( unsigned i=0; iSetFocus(); + + // resume editing at the last row edited, last time dialog was up. + setSelectedFieldNdx( s_SelectedRow ); +} + + +void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::setRowItem( int aFieldNdx, const SCH_CMP_FIELD& aField ) +{ + wxASSERT( aFieldNdx >= 0 ); + + // insert blanks if aFieldNdx is referencing a "yet to be defined" row + while( aFieldNdx >= fieldListCtrl->GetItemCount() ) + { + long ndx = fieldListCtrl->InsertItem( fieldListCtrl->GetItemCount(), wxEmptyString ); + + wxASSERT( ndx >= 0 ); + + fieldListCtrl->SetItem( ndx, 1, wxEmptyString ); + } + + fieldListCtrl->SetItem( aFieldNdx, 0, aField.m_Name ); + fieldListCtrl->SetItem( aFieldNdx, 1, aField.m_Text ); + + // recompute the column widths here, after setting texts + fieldListCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE ); + fieldListCtrl->SetColumnWidth( 1, wxLIST_AUTOSIZE ); +} + + +/****************************************************************/ +void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copySelectedFieldToPanel() +/****************************************************************/ +{ + unsigned fieldNdx = getSelectedFieldNdx(); + + if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too + return; + + SCH_CMP_FIELD& field = m_FieldsBuf[fieldNdx]; + + showCheckBox->SetValue( !(field.m_Attributs & TEXT_NO_VISIBLE) ); + + rotateCheckBox->SetValue( field.m_Orient == TEXT_ORIENT_VERT ); + + fieldNameTextCtrl->SetValue( field.m_Name ); + + // if fieldNdx == REFERENCE, VALUE, FOOTPRINT, or DATASHEET, then disable editing + // fieldNameTextCtrl->Enable( fieldNdx >= FIELD1 ); + fieldNameTextCtrl->SetEditable( fieldNdx >= FIELD1 ); + + fieldValueTextCtrl->SetValue( field.m_Text ); + + if( fieldNdx == VALUE && m_LibEntry && m_LibEntry->m_Options == ENTRY_POWER ) + fieldValueTextCtrl->Enable( FALSE ); + + textSizeTextCtrl->SetValue( + WinEDA_GraphicTextCtrl::FormatSize( EESCHEMA_INTERNAL_UNIT, g_UnitMetric, field.m_Size.x ) ); + + wxPoint coord = field.m_Pos; + wxPoint zero = -m_Cmp->m_Pos; // relative zero + + // If the field value is empty and the position is at relative zero, we set the + // initial position as a small offset from the ref field, and orient + // it the same as the ref field. That is likely to put it at least + // close to the desired position. + if( coord == zero && field.m_Text.IsEmpty() ) + { + rotateCheckBox->SetValue( m_FieldsBuf[REFERENCE].m_Orient == TEXT_ORIENT_VERT ); + + coord.x = m_FieldsBuf[REFERENCE].m_Pos.x + (fieldNdx-FIELD1+1)*100; + coord.y = m_FieldsBuf[REFERENCE].m_Pos.y + (fieldNdx-FIELD1+1)*100; + + // coord can compute negative if field is < FIELD1, e.g. FOOTPRINT. + // That is ok, we basically don't want all the new empty fields on + // top of each other. + } + + wxString coordText = ReturnStringFromValue( g_UnitMetric, coord.x, EESCHEMA_INTERNAL_UNIT ); + posXTextCtrl->SetValue( coordText ); + + coordText = ReturnStringFromValue( g_UnitMetric, coord.y, EESCHEMA_INTERNAL_UNIT ); + posYTextCtrl->SetValue( coordText ); +} + + +/*****************************************************************/ +bool DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyPanelToSelectedField() +/*****************************************************************/ +{ + unsigned fieldNdx = getSelectedFieldNdx(); + + if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too + return true; + + SCH_CMP_FIELD& field = m_FieldsBuf[fieldNdx]; + + if( showCheckBox->GetValue() ) + field.m_Attributs &= ~TEXT_NO_VISIBLE; + else + field.m_Attributs |= TEXT_NO_VISIBLE; + + if( rotateCheckBox->GetValue() ) + field.m_Orient = TEXT_ORIENT_VERT; + else + field.m_Orient = TEXT_ORIENT_HORIZ; + + rotateCheckBox->SetValue( field.m_Orient == TEXT_ORIENT_VERT ); + + field.m_Name = fieldNameTextCtrl->GetValue(); + field.m_Text = fieldValueTextCtrl->GetValue(); + + setRowItem( fieldNdx, field ); // update fieldListCtrl + + field.m_Size.x = WinEDA_GraphicTextCtrl::ParseSize( textSizeTextCtrl->GetValue(), EESCHEMA_INTERNAL_UNIT, g_UnitMetric ); + field.m_Size.y = field.m_Size.x; + + double value; + + posXTextCtrl->GetValue().ToDouble( &value ); + field.m_Pos.x = From_User_Unit( g_UnitMetric, value, EESCHEMA_INTERNAL_UNIT ); + + posYTextCtrl->GetValue().ToDouble( &value ); + field.m_Pos.y = From_User_Unit( g_UnitMetric, value, EESCHEMA_INTERNAL_UNIT ); + + return true; +} + + +void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyOptionsToPanel() +{ + int choiceCount = unitChoice->GetCount(); + + if( m_Cmp->m_Multi <= choiceCount ) + unitChoice->SetSelection( m_Cmp->m_Multi - 1 ); + + int orientation = m_Cmp->GetRotationMiroir() & ~(CMP_MIROIR_X | CMP_MIROIR_Y); + + // if we don't change it, the default selection of the radio box is "0". + if( orientation == CMP_ORIENT_90 ) + orientationRadioBox->SetSelection( 1 ); + else if( orientation == CMP_ORIENT_180 ) + orientationRadioBox->SetSelection( 2 ); + else if( orientation == CMP_ORIENT_270 ) + orientationRadioBox->SetSelection( 3 ); + + int mirror = m_Cmp->GetRotationMiroir() & (CMP_MIROIR_X | CMP_MIROIR_Y); + + if( mirror == CMP_MIROIR_X ) + { + mirrorRadioBox->SetSelection( 1 ); + D(printf("mirror=X,1\n");) + } + else if( mirror == CMP_MIROIR_Y ) + { + mirrorRadioBox->SetSelection( 2 ); + D(printf("mirror=Y,2\n");) + } + + // Positionnement de la selection normal/convert + if( m_Cmp->m_Convert > 1 ) + convertCheckBox->SetValue( true ); + + if( m_LibEntry == NULL || LookForConvertPart( m_LibEntry ) <= 1 ) + { + convertCheckBox->Enable( false ); + } + + // Show the "Parts Locked" option? + if( !m_LibEntry || !m_LibEntry->m_UnitSelectionLocked ) + { + D(printf("partsAreLocked->false\n");) + partsAreLockedLabel->Show( false ); + } + + // Positionnement de la reference en librairie + chipnameTextCtrl->SetValue( m_Cmp->m_ChipName ); +} + + +/*****************************************************************************/ +void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::SetInitCmp( wxCommandEvent& event ) +/*****************************************************************************/ +{ + EDA_LibComponentStruct* entry; + + if( m_Cmp == NULL ) + return; + + entry = FindLibPart( m_Cmp->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); + + if( entry == NULL ) + return; + + wxClientDC dc( m_Parent->DrawPanel ); + m_Parent->DrawPanel->PrepareGraphicContext( &dc ); + + RedrawOneStruct( m_Parent->DrawPanel, &dc, m_Cmp, g_XorMode ); + + /* Mise aux valeurs par defaut des champs et orientation */ + m_Cmp->GetField( REFERENCE )->m_Pos.x = + entry->m_Prefix.m_Pos.x + m_Cmp->m_Pos.x; + m_Cmp->GetField( REFERENCE )->m_Pos.y = + entry->m_Prefix.m_Pos.y + m_Cmp->m_Pos.y; + m_Cmp->GetField( REFERENCE )->m_Orient = entry->m_Prefix.m_Orient; + m_Cmp->GetField( REFERENCE )->m_Size = entry->m_Prefix.m_Size; + m_Cmp->GetField( REFERENCE )->m_HJustify = entry->m_Prefix.m_HJustify; + m_Cmp->GetField( REFERENCE )->m_VJustify = entry->m_Prefix.m_VJustify; + + m_Cmp->GetField( VALUE )->m_Pos.x = + entry->m_Name.m_Pos.x + m_Cmp->m_Pos.x; + m_Cmp->GetField( VALUE )->m_Pos.y = + entry->m_Name.m_Pos.y + m_Cmp->m_Pos.y; + m_Cmp->GetField( VALUE )->m_Orient = entry->m_Name.m_Orient; + m_Cmp->GetField( VALUE )->m_Size = entry->m_Name.m_Size; + m_Cmp->GetField( VALUE )->m_HJustify = entry->m_Name.m_HJustify; + m_Cmp->GetField( VALUE )->m_VJustify = entry->m_Name.m_VJustify; + + m_Cmp->SetRotationMiroir( CMP_NORMAL ); + + m_Parent->GetScreen()->SetModify(); + + RedrawOneStruct( m_Parent->DrawPanel, &dc, m_Cmp, GR_DEFAULT_DRAWMODE ); + EndModal( 1 ); +} + diff --git a/eeschema/dialog_edit_component_in_schematic.fbp b/eeschema/dialog_edit_component_in_schematic.fbp index 8b4a1d4f41..ed8b886bf1 100644 --- a/eeschema/dialog_edit_component_in_schematic.fbp +++ b/eeschema/dialog_edit_component_in_schematic.fbp @@ -198,7 +198,7 @@ orientationRadioBox protected - 0 + 3 wxRA_SPECIFY_COLS @@ -267,7 +267,7 @@ mirrorRadioBox protected - 1 + 0 wxRA_SPECIFY_COLS @@ -334,7 +334,7 @@ 32 - chipnameTxtControl + chipnameTextCtrl protected @@ -381,7 +381,7 @@ - 12 + 8 wxALL 0 @@ -436,6 +436,61 @@ + + 8 + wxALL|wxEXPAND + 0 + + + + 1 + + + 0 + wxID_ANY + Parts are locked + + + partsAreLockedLabel + protected + + + + + + + wxFILTER_NONE + wxDefaultValidator + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + @@ -453,7 +508,7 @@ 8 wxALL|wxEXPAND - 4 + 5 wxID_ANY @@ -1094,7 +1149,7 @@ 5 wxALL|wxEXPAND 0 - + textSizeBoxSizer wxVERTICAL @@ -1516,7 +1571,7 @@ - + SetInitCmp @@ -1575,11 +1630,11 @@ stdDialogButtonSizer protected - + OnCancelButtonClick - + OnOKButtonClick diff --git a/eeschema/dialog_edit_component_in_schematic.h b/eeschema/dialog_edit_component_in_schematic.h index c66d4497f7..ffbd63b91a 100644 --- a/eeschema/dialog_edit_component_in_schematic.h +++ b/eeschema/dialog_edit_component_in_schematic.h @@ -16,7 +16,7 @@ class DIALOG_EDIT_COMPONENT_IN_SCHEMATIC : public DIALOG_EDIT_COMPONENT_IN_SCHEM SCH_COMPONENT* m_Cmp; EDA_LibComponentStruct* m_LibEntry; - int m_SelectedRow; + static int s_SelectedRow; /// a copy of the edited component's SCH_CMP_FIELDs SCH_CMP_FIELDS m_FieldsBuf; @@ -36,17 +36,24 @@ class DIALOG_EDIT_COMPONENT_IN_SCHEMATIC : public DIALOG_EDIT_COMPONENT_IN_SCHEM /** * Function copyPanelToSelectedField * copies the values displayed on the panel fields to the currently selected field + * @return bool - true if all fields are OK, else false if the user has put + * bad data into a field, and this value can be used to deny a row change. */ - void copyPanelToSelectedField(); + bool copyPanelToSelectedField(); + void copyOptionsToPanel(); - void fillTableModel(); + void copyPanelToOptions(); void setRowItem( int aFieldNdx, const SCH_CMP_FIELD& aField ); // event handlers void OnListItemDeselected( wxListEvent& event ); void OnListItemSelected( wxListEvent& event ); + void OnCancelButtonClick( wxCommandEvent& event ); + void OnOKButtonClick( wxCommandEvent& event ); + void SetInitCmp( wxCommandEvent& event ); + protected: diff --git a/eeschema/dialog_edit_component_in_schematic_fbp.cpp b/eeschema/dialog_edit_component_in_schematic_fbp.cpp index 37061636c9..1db8d77c5e 100644 --- a/eeschema/dialog_edit_component_in_schematic_fbp.cpp +++ b/eeschema/dialog_edit_component_in_schematic_fbp.cpp @@ -39,7 +39,7 @@ DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP( wxString orientationRadioBoxChoices[] = { _("0"), _("+90"), _("180"), _("-90") }; int orientationRadioBoxNChoices = sizeof( orientationRadioBoxChoices ) / sizeof( wxString ); orientationRadioBox = new wxRadioBox( this, wxID_ANY, _("Orientation (Degrees)"), wxDefaultPosition, wxDefaultSize, orientationRadioBoxNChoices, orientationRadioBoxChoices, 1, wxRA_SPECIFY_COLS ); - orientationRadioBox->SetSelection( 0 ); + orientationRadioBox->SetSelection( 3 ); orientationRadioBox->SetToolTip( _("Select if the component is to be rotated when drawn") ); orientationSizer->Add( orientationRadioBox, 1, wxALL, 8 ); @@ -52,7 +52,7 @@ DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP( wxString mirrorRadioBoxChoices[] = { _("Normal"), _("Mirror ---"), _("Mirror |") }; int mirrorRadioBoxNChoices = sizeof( mirrorRadioBoxChoices ) / sizeof( wxString ); mirrorRadioBox = new wxRadioBox( this, wxID_ANY, _("Mirror"), wxDefaultPosition, wxDefaultSize, mirrorRadioBoxNChoices, mirrorRadioBoxChoices, 1, wxRA_SPECIFY_COLS ); - mirrorRadioBox->SetSelection( 1 ); + mirrorRadioBox->SetSelection( 0 ); mirrorRadioBox->SetToolTip( _("Pick the graphical transformation to be used when displaying the component, if any") ); mirrorSizer->Add( mirrorRadioBox, 1, wxALL, 8 ); @@ -62,18 +62,22 @@ DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP( wxStaticBoxSizer* chipnameSizer; chipnameSizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Chip Name") ), wxHORIZONTAL ); - chipnameTxtControl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); - chipnameTxtControl->SetMaxLength( 32 ); - chipnameTxtControl->SetToolTip( _("The name of the symbol in the library from which this component came") ); + chipnameTextCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + chipnameTextCtrl->SetMaxLength( 32 ); + chipnameTextCtrl->SetToolTip( _("The name of the symbol in the library from which this component came") ); - chipnameSizer->Add( chipnameTxtControl, 1, wxALL|wxEXPAND, 5 ); + chipnameSizer->Add( chipnameTextCtrl, 1, wxALL|wxEXPAND, 5 ); optionsSizer->Add( chipnameSizer, 0, wxEXPAND|wxLEFT|wxRIGHT|wxTOP, 8 ); convertCheckBox = new wxCheckBox( this, wxID_ANY, _("Convert"), wxDefaultPosition, wxDefaultSize, 0 ); convertCheckBox->SetToolTip( _("No Friggin Idea what this is!") ); - optionsSizer->Add( convertCheckBox, 0, wxALL, 12 ); + optionsSizer->Add( convertCheckBox, 0, wxALL, 8 ); + + partsAreLockedLabel = new wxStaticText( this, wxID_ANY, _("Parts are locked"), wxDefaultPosition, wxDefaultSize, 0 ); + partsAreLockedLabel->Wrap( -1 ); + optionsSizer->Add( partsAreLockedLabel, 0, wxALL|wxEXPAND, 8 ); upperSizer->Add( optionsSizer, 0, wxALIGN_TOP|wxALL|wxEXPAND, 5 ); @@ -101,7 +105,7 @@ DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP( gridStaticBoxSizer->Add( moveUpButton, 0, wxALL|wxEXPAND, 5 ); - fieldsSizer->Add( gridStaticBoxSizer, 4, wxALL|wxEXPAND, 8 ); + fieldsSizer->Add( gridStaticBoxSizer, 5, wxALL|wxEXPAND, 8 ); wxBoxSizer* fieldEditBoxSizer; fieldEditBoxSizer = new wxBoxSizer( wxVERTICAL ); @@ -223,6 +227,9 @@ DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP( // Connect Events fieldListCtrl->Connect( wxEVT_COMMAND_LIST_ITEM_DESELECTED, wxListEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::OnListItemDeselected ), NULL, this ); fieldListCtrl->Connect( wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::OnListItemSelected ), NULL, this ); + defaultsButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::SetInitCmp ), NULL, this ); + stdDialogButtonSizerCancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::OnCancelButtonClick ), NULL, this ); + stdDialogButtonSizerOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::OnOKButtonClick ), NULL, this ); } DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::~DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP() @@ -230,4 +237,7 @@ DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::~DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP( // Disconnect Events fieldListCtrl->Disconnect( wxEVT_COMMAND_LIST_ITEM_DESELECTED, wxListEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::OnListItemDeselected ), NULL, this ); fieldListCtrl->Disconnect( wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::OnListItemSelected ), NULL, this ); + defaultsButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::SetInitCmp ), NULL, this ); + stdDialogButtonSizerCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::OnCancelButtonClick ), NULL, this ); + stdDialogButtonSizerOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::OnOKButtonClick ), NULL, this ); } diff --git a/eeschema/dialog_edit_component_in_schematic_fbp.h b/eeschema/dialog_edit_component_in_schematic_fbp.h index c0c9c26172..b74aa150eb 100644 --- a/eeschema/dialog_edit_component_in_schematic_fbp.h +++ b/eeschema/dialog_edit_component_in_schematic_fbp.h @@ -21,9 +21,9 @@ #include #include #include +#include #include #include -#include #include /////////////////////////////////////////////////////////////////////////// @@ -40,8 +40,9 @@ class DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP : public wxDialog wxChoice* unitChoice; wxRadioBox* orientationRadioBox; wxRadioBox* mirrorRadioBox; - wxTextCtrl* chipnameTxtControl; + wxTextCtrl* chipnameTextCtrl; wxCheckBox* convertCheckBox; + wxStaticText* partsAreLockedLabel; wxListCtrl* fieldListCtrl; wxButton* addFieldButton; wxButton* deleteFieldButton; @@ -68,6 +69,9 @@ class DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP : public wxDialog // Virtual event handlers, overide them in your derived class virtual void OnListItemDeselected( wxListEvent& event ){ event.Skip(); } virtual void OnListItemSelected( wxListEvent& event ){ event.Skip(); } + virtual void SetInitCmp( wxCommandEvent& event ){ event.Skip(); } + virtual void OnCancelButtonClick( wxCommandEvent& event ){ event.Skip(); } + virtual void OnOKButtonClick( wxCommandEvent& event ){ event.Skip(); } public: diff --git a/include/wxstruct.h b/include/wxstruct.h index cd09a373ac..0ee1e30aac 100644 --- a/include/wxstruct.h +++ b/include/wxstruct.h @@ -469,6 +469,14 @@ public: void SetFocus() { m_FrameText->SetFocus(); } void SetValue( const wxString& value ); void SetValue( int value ); + + /** + * Function FormatSize + * formats a string containing the size in the desired units. + */ + static wxString FormatSize( int internalUnit, int units, int textSize ); + + static int ParseSize( const wxString& sizeText, int internalUnit, int units ); };