Commit 0a68744e authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Eeschema: Add better dialog to edit an existing field of the current edited component.

parent 718b2565
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -50,7 +50,7 @@ set(EESCHEMA_SRCS
    dialogs/dialog_edit_label_base.cpp
    dialogs/dialog_edit_label_base.cpp
    dialogs/dialog_edit_libentry_fields_in_lib.cpp
    dialogs/dialog_edit_libentry_fields_in_lib.cpp
    dialogs/dialog_edit_libentry_fields_in_lib_base.cpp
    dialogs/dialog_edit_libentry_fields_in_lib_base.cpp
    dialogs/dialog_lib_edit_one_field.cpp
    dialogs/dialog_edit_one_field.cpp
    dialogs/dialog_eeschema_config.cpp
    dialogs/dialog_eeschema_config.cpp
    dialogs/dialog_eeschema_config_fbp.cpp
    dialogs/dialog_eeschema_config_fbp.cpp
    dialogs/dialog_eeschema_options_base.cpp
    dialogs/dialog_eeschema_options_base.cpp
+120 −76
Original line number Original line Diff line number Diff line
/**
/**
 * @file dialog_lib_edit_one_field.cpp
 * @file dialog_lib_edit_one_field.cpp
 * @brief dialog to editing  fields ( not graphic texts) in components.
 * @brief dialog to editing a field ( not a graphic text) in current component.
 */
 */


/*
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 *
 * Copyright (C) 2012 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2004-2012 KiCad Developers, see change_log.txt for contributors.
 * Copyright (C) 2004-2012 KiCad Developers, see change_log.txt for contributors.
 *
 *
 * This program is free software; you can redistribute it and/or
 * This program is free software; you can redistribute it and/or
@@ -31,31 +31,18 @@
#include <common.h>
#include <common.h>


#include <general.h>
#include <general.h>
#include <libeditframe.h>
#include <sch_base_frame.h>
#include <sch_component.h>
#include <sch_component.h>
#include <template_fieldnames.h>
#include <template_fieldnames.h>
#include <class_libentry.h>
#include <class_libentry.h>
#include <lib_field.h>
#include <lib_field.h>
#include <sch_component.h>
#include <template_fieldnames.h>


#include <dialog_lib_edit_one_field.h>
#include <dialog_edit_one_field.h>




DIALOG_LIB_EDIT_ONE_FIELD::DIALOG_LIB_EDIT_ONE_FIELD( LIB_EDIT_FRAME* aParent,
void DIALOG_EDIT_ONE_FIELD::initDlg_base( )
                                                      const wxString& aTitle,
                                                      LIB_FIELD* aField ) :
    DIALOG_LIB_EDIT_TEXT_BASE( aParent )
{
    m_parent = aParent;
    m_field = aField;
    SetTitle( aTitle );
    initDlg();

    GetSizer()->SetSizeHints(this);
    Centre();
}


void DIALOG_LIB_EDIT_ONE_FIELD::initDlg( )
{
{
    wxString msg;
    wxString msg;


@@ -65,30 +52,17 @@ void DIALOG_LIB_EDIT_ONE_FIELD::initDlg( )
    m_CommonConvert->Show(false);
    m_CommonConvert->Show(false);
    m_CommonUnit->Show(false);
    m_CommonUnit->Show(false);


    if ( m_field )
    msg = ReturnStringFromValue( g_UserUnit, m_textsize,
    {
        msg = ReturnStringFromValue( g_UserUnit, m_field->m_Size.x,
                                 m_parent->GetInternalUnits() );
                                 m_parent->GetInternalUnits() );
    m_TextSize->SetValue( msg );
    m_TextSize->SetValue( msg );
        m_TextValue->SetValue( m_field->m_Text );


        if( m_field->GetOrientation() == TEXT_ORIENT_VERT )
    if( m_textorient == TEXT_ORIENT_VERT )
        m_Orient->SetValue( true );
        m_Orient->SetValue( true );


        if( m_field->GetOrientation() == TEXT_ORIENT_VERT )
    m_Invisible->SetValue( m_text_invisible );
            m_Orient->SetValue( true );
    m_TextShapeOpt->SetSelection( m_textshape );

        m_Invisible->SetValue( m_field->IsVisible() ? false : true);

        int shape = 0;
        if( m_field->m_Italic )
            shape = 1;
        if( m_field->m_Bold )
            shape |= 2;


        m_TextShapeOpt->SetSelection( shape );
    switch ( m_textHjustify )

        switch ( m_field->m_HJustify )
    {
    {
        case GR_TEXT_HJUSTIFY_LEFT:
        case GR_TEXT_HJUSTIFY_LEFT:
            m_TextHJustificationOpt->SetSelection( 0 );
            m_TextHJustificationOpt->SetSelection( 0 );
@@ -104,7 +78,7 @@ void DIALOG_LIB_EDIT_ONE_FIELD::initDlg( )


    }
    }


        switch ( m_field->m_VJustify )
    switch ( m_textVjustify )
    {
    {
    case GR_TEXT_VJUSTIFY_BOTTOM:
    case GR_TEXT_VJUSTIFY_BOTTOM:
        m_TextVJustificationOpt->SetSelection( 0 );
        m_TextVJustificationOpt->SetSelection( 0 );
@@ -118,7 +92,6 @@ void DIALOG_LIB_EDIT_ONE_FIELD::initDlg( )
        m_TextVJustificationOpt->SetSelection( 2 );
        m_TextVJustificationOpt->SetSelection( 2 );
        break;
        break;
    }
    }
    }


    msg = m_TextSizeText->GetLabel() + ReturnUnitSymbol();
    msg = m_TextSizeText->GetLabel() + ReturnUnitSymbol();
    m_TextSizeText->SetLabel( msg );
    m_TextSizeText->SetLabel( msg );
@@ -127,38 +100,80 @@ void DIALOG_LIB_EDIT_ONE_FIELD::initDlg( )
}
}




void DIALOG_LIB_EDIT_ONE_FIELD::OnCancelClick( wxCommandEvent& event )
void DIALOG_LIB_EDIT_ONE_FIELD::initDlg( )
{
{
    EndModal(wxID_CANCEL);
    m_textsize = m_field->m_Size.x;
}
    m_TextValue->SetValue( m_field->m_Text );


    m_textorient = m_field->GetOrientation();


/* Updates the different parameters for the component being edited */
    m_text_invisible = m_field->IsVisible() ? false : true;
void DIALOG_LIB_EDIT_ONE_FIELD::OnOkClick( wxCommandEvent& event )

{
    m_textshape = 0;
    EndModal(wxID_OK);
    if( m_field->m_Italic )
        m_textshape = 1;
    if( m_field->m_Bold )
        m_textshape |= 2;

    m_textHjustify = m_field->m_HJustify;
    m_textVjustify =  m_field->m_VJustify;

    initDlg_base( );
}
}


wxString DIALOG_LIB_EDIT_ONE_FIELD::GetTextField()
wxString DIALOG_LIB_EDIT_ONE_FIELD::GetTextField()
{
{
    wxString line = m_TextValue->GetValue();
    wxString line = m_TextValue->GetValue();
    // Spaces are not allowed in fields, so replace them by '_'
    line.Replace( wxT( " " ), wxT( "_" ) );
    line.Replace( wxT( " " ), wxT( "_" ) );
    return line;
    return line;
};
};


void DIALOG_LIB_EDIT_ONE_FIELD::TransfertDataToField()
void DIALOG_EDIT_ONE_FIELD::TransfertDataToField()
{
{

    m_textorient = m_Orient->GetValue() ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ;
    int orientation = m_Orient->GetValue() ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ;
    wxString msg = m_TextSize->GetValue();
    wxString msg = m_TextSize->GetValue();
    int textSize = ReturnValueFromString( g_UserUnit, msg, m_parent->GetInternalUnits() );
    m_textsize = ReturnValueFromString( g_UserUnit, msg, m_parent->GetInternalUnits() );


    if( m_field )
    switch( m_TextHJustificationOpt->GetSelection() )
    {
    {
    case 0:
        m_textHjustify = GR_TEXT_HJUSTIFY_LEFT;
        break;

    case 1:
        m_textHjustify = GR_TEXT_HJUSTIFY_CENTER;
        break;

    case 2:
        m_textHjustify = GR_TEXT_HJUSTIFY_RIGHT;
        break;
    }

    switch( m_TextVJustificationOpt->GetSelection() )
    {
    case 0:
        m_textVjustify = GR_TEXT_VJUSTIFY_BOTTOM;
        break;

    case 1:
        m_textVjustify = GR_TEXT_VJUSTIFY_CENTER;
        break;

    case 2:
        m_textVjustify = GR_TEXT_VJUSTIFY_TOP;
        break;
    }
}

void DIALOG_LIB_EDIT_ONE_FIELD::TransfertDataToField()
{
    DIALOG_EDIT_ONE_FIELD::TransfertDataToField();

    m_field->SetText( GetTextField() );
    m_field->SetText( GetTextField() );


        m_field->m_Size.x = m_field->m_Size.y = textSize;
    m_field->m_Size.x = m_field->m_Size.y = m_textsize;
        m_field->m_Orient = orientation;
    m_field->m_Orient = m_textorient;


    if( m_Invisible->GetValue() )
    if( m_Invisible->GetValue() )
        m_field->m_Attributs |= TEXT_NO_VISIBLE;
        m_field->m_Attributs |= TEXT_NO_VISIBLE;
@@ -175,34 +190,63 @@ void DIALOG_LIB_EDIT_ONE_FIELD::TransfertDataToField()
    else
    else
        m_field->m_Bold = false;
        m_field->m_Bold = false;


        switch( m_TextHJustificationOpt->GetSelection() )
    m_field->m_HJustify = m_textHjustify;
    m_field->m_VJustify = m_textVjustify;
}


void DIALOG_SCH_EDIT_ONE_FIELD::initDlg( )
{
{
        case 0:
    m_textsize = m_field->m_Size.x;
            m_field->m_HJustify = GR_TEXT_HJUSTIFY_LEFT;
    m_TextValue->SetValue( m_field->m_Text );
            break;
    m_textorient = m_field->GetOrientation();
    m_text_invisible = m_field->IsVisible() ? false : true;


        case 1:
    m_textshape = 0;
            m_field->m_HJustify = GR_TEXT_HJUSTIFY_CENTER;
    if( m_field->m_Italic )
            break;
        m_textshape = 1;
    if( m_field->m_Bold )
        m_textshape |= 2;


        case 2:
    m_textHjustify = m_field->m_HJustify;
            m_field->m_HJustify = GR_TEXT_HJUSTIFY_RIGHT;
    m_textVjustify =  m_field->m_VJustify;
            break;

    initDlg_base( );
}
}


        switch( m_TextVJustificationOpt->GetSelection() )

wxString DIALOG_SCH_EDIT_ONE_FIELD::GetTextField()
{
{
        case 0:
    wxString line = m_TextValue->GetValue();
            m_field->m_VJustify = GR_TEXT_VJUSTIFY_BOTTOM;
    line.Trim( true );
            break;
    line.Trim( false );
    return line;
};


        case 1:
void DIALOG_SCH_EDIT_ONE_FIELD::TransfertDataToField()
            m_field->m_VJustify = GR_TEXT_VJUSTIFY_CENTER;
{
            break;
    DIALOG_EDIT_ONE_FIELD::TransfertDataToField();


        case 2:
    m_field->SetText( GetTextField() );
            m_field->m_VJustify = GR_TEXT_VJUSTIFY_TOP;

            break;
    m_field->m_Size.x = m_field->m_Size.y = m_textsize;
        }
    m_field->m_Orient = m_textorient;
    }

    if( m_Invisible->GetValue() )
        m_field->m_Attributs |= TEXT_NO_VISIBLE;
    else
        m_field->m_Attributs &= ~TEXT_NO_VISIBLE;

    if( ( m_TextShapeOpt->GetSelection() & 1 ) != 0 )
        m_field->m_Italic = true;
    else
        m_field->m_Italic = false;

    if( ( m_TextShapeOpt->GetSelection() & 2 ) != 0 )
        m_field->m_Bold = true;
    else
        m_field->m_Bold = false;

    m_field->m_HJustify = m_textHjustify;
    m_field->m_VJustify = m_textVjustify;
}
}
+130 −0
Original line number Original line Diff line number Diff line

#ifndef _DIALOG_EDIT_ONE_FIELD_H_
#define _DIALOG_EDIT_ONE_FIELD_H_

/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2004-2012 KiCad Developers, see change_log.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

#include <dialog_lib_edit_text_base.h>


class SCH_BASE_FRAME;
class LIB_FIELD;
class SCH_FIELD;

// Basic class to edit a field: a schematic or a lib component field
class DIALOG_EDIT_ONE_FIELD : public DIALOG_LIB_EDIT_TEXT_BASE
{
protected:
    SCH_BASE_FRAME* m_parent;
    int m_textshape;
    int m_textsize;
    int m_textorient;
    EDA_TEXT_HJUSTIFY_T m_textHjustify;
    EDA_TEXT_VJUSTIFY_T m_textVjustify;
    bool m_text_invisible;

public:
    DIALOG_EDIT_ONE_FIELD( SCH_BASE_FRAME* aParent, const wxString& aTitle ):
        DIALOG_LIB_EDIT_TEXT_BASE( aParent )
    {
        m_parent = aParent;
        SetTitle( aTitle );
    }

    ~DIALOG_EDIT_ONE_FIELD() {};
    virtual void TransfertDataToField();

    void SetTextField( const wxString& aText )
    {
         m_TextValue->SetValue( aText );
    }

protected:
    void initDlg_base( );
    void OnOkClick( wxCommandEvent& aEvent )
    {
        EndModal(wxID_OK);
    }

    void OnCancelClick( wxCommandEvent& aEvent )
    {
        EndModal(wxID_CANCEL);
    }
};


// Class to edit a lib component field
class DIALOG_LIB_EDIT_ONE_FIELD : public DIALOG_EDIT_ONE_FIELD
{
private:
    LIB_FIELD* m_field;

public:
    DIALOG_LIB_EDIT_ONE_FIELD( SCH_BASE_FRAME* aParent, const wxString& aTitle,
                               LIB_FIELD* aField ):
        DIALOG_EDIT_ONE_FIELD( aParent, aTitle )
    {
        m_field = aField;
        initDlg();
        GetSizer()->SetSizeHints(this);
        Centre();
    }

    ~DIALOG_LIB_EDIT_ONE_FIELD() {};

    void TransfertDataToField();
    wxString GetTextField();

private:
    void initDlg( );
};

// Class to edit a schematic component field
class DIALOG_SCH_EDIT_ONE_FIELD : public DIALOG_EDIT_ONE_FIELD
{
private:
    SCH_FIELD* m_field;

public:
    DIALOG_SCH_EDIT_ONE_FIELD( SCH_BASE_FRAME* aParent,
                               const wxString& aTitle, SCH_FIELD* aField ):
        DIALOG_EDIT_ONE_FIELD( aParent, aTitle )
    {
        m_field = aField;
        initDlg();
        GetSizer()->SetSizeHints(this);
        Centre();
    }
    ~DIALOG_SCH_EDIT_ONE_FIELD() {};

    void TransfertDataToField();
    wxString GetTextField();

private:
    void initDlg( );
};


#endif    // _DIALOG_EDIT_ONE_FIELD_H_
+0 −32
Original line number Original line Diff line number Diff line

#ifndef _DIALOG_LIB_EDIT_ONE_FIELD_H_
#define _DIALOG_LIB_EDIT_ONE_FIELD_H_


#include <dialog_lib_edit_text_base.h>


class LIB_EDIT_FRAME;
class LIB_FIELD;


class DIALOG_LIB_EDIT_ONE_FIELD : public DIALOG_LIB_EDIT_TEXT_BASE
{
private:
    LIB_EDIT_FRAME* m_parent;
    LIB_FIELD* m_field;

public:
    DIALOG_LIB_EDIT_ONE_FIELD( LIB_EDIT_FRAME* aParent, const wxString& aTitle, LIB_FIELD* aField );
    ~DIALOG_LIB_EDIT_ONE_FIELD() {};
    void TransfertDataToField();
    wxString GetTextField();

private:
    void initDlg( );
    void OnOkClick( wxCommandEvent& aEvent );
    void OnCancelClick( wxCommandEvent& aEvent );
};


#endif    // _DIALOG_LIB_EDIT_ONE_FIELD_H_
+26 −21
Original line number Original line Diff line number Diff line
@@ -39,6 +39,8 @@
#include <class_library.h>
#include <class_library.h>
#include <sch_component.h>
#include <sch_component.h>


#include <dialog_edit_one_field.h>



void SCH_EDIT_FRAME::EditComponentFieldText( SCH_FIELD* aField, wxDC* aDC )
void SCH_EDIT_FRAME::EditComponentFieldText( SCH_FIELD* aField, wxDC* aDC )
{
{
@@ -79,67 +81,70 @@ create a new power component with the new value." ), GetChars( entry->GetName()
    wxString title;
    wxString title;
    title.Printf( _( "Edit %s Field" ), GetChars( aField->GetName() ) );
    title.Printf( _( "Edit %s Field" ), GetChars( aField->GetName() ) );


    wxTextEntryDialog dlg( this, wxEmptyString , title, newtext );
//    wxTextEntryDialog dlg( this, wxEmptyString , title, newtext );
    if( aField->GetText().IsEmpty() )  // Means the field was not already in use
    {
        aField->m_Pos = component->GetPosition();
        aField->m_Size.x = aField->m_Size.y = m_TextFieldSize;
    }
    DIALOG_SCH_EDIT_ONE_FIELD dlg( this, title, aField );

    int response = dlg.ShowModal();
    int response = dlg.ShowModal();


    m_canvas->MoveCursorToCrossHair();
    m_canvas->MoveCursorToCrossHair();
    m_canvas->SetIgnoreMouseEvents( false );
    m_canvas->SetIgnoreMouseEvents( false );
    newtext = dlg.GetValue( );
    newtext = dlg.GetTextField( );
    newtext.Trim( true );
    newtext.Trim( false );


    if ( response != wxID_OK || newtext == aField->GetText() )
    if ( response != wxID_OK )
        return;  // canceled by user
        return;  // canceled by user


    aField->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
    // make some tests

    bool can_update = true;
    if( !newtext.IsEmpty() )
    if( !newtext.IsEmpty() )
    {
    {
        if( aField->GetText().IsEmpty() )  // Means the field was not already in use
        {
            aField->m_Pos = component->GetPosition();
            aField->m_Size.x = aField->m_Size.y = m_TextFieldSize;
        }

        if( fieldNdx == REFERENCE )
        if( fieldNdx == REFERENCE )
        {
        {
            // Test is reference is acceptable:
            // Test is reference is acceptable:
            if( SCH_COMPONENT::IsReferenceStringValid( newtext ) )
            if( SCH_COMPONENT::IsReferenceStringValid( newtext ) )
            {
            {
                component->SetRef( m_CurrentSheet, newtext );
                component->SetRef( m_CurrentSheet, newtext );
                aField->SetText( newtext );
            }
            }
            else
            else
            {
            {
                DisplayError( this, _( "Illegal reference string!  No change" ) );
                DisplayError( this, _( "Illegal reference string!  No change" ) );
                can_update = false;
            }
            }
        }
        }
        else
        {
            aField->m_Text = newtext;
        }
    }
    }
    else
    else
    {
    {
        if( fieldNdx == REFERENCE )
        if( fieldNdx == REFERENCE )
        {
        {
            DisplayError( this, _( "The reference field cannot be empty!  No change" ) );
            DisplayError( this, _( "The reference field cannot be empty!  No change" ) );
            can_update = false;
        }
        }
        else if( fieldNdx == VALUE )
        else if( fieldNdx == VALUE )
        {
        {
            DisplayError( this, _( "The value field cannot be empty!  No change" ) );
            DisplayError( this, _( "The value field cannot be empty!  No change" ) );
            can_update = false;
        }
        }
        else
        else
        {
        {
            aField->m_Text = wxT( "~" );
            dlg.SetTextField( wxT( "~" ) );
        }
        }
    }
    }


    if( can_update )
    {
        aField->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
        dlg.TransfertDataToField();
        aField->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
        aField->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
    component->DisplayInfo( this );
        OnModify();
        OnModify();
    }
    }


    component->DisplayInfo( this );
}



void SCH_EDIT_FRAME::RotateField( SCH_FIELD* aField, wxDC* aDC )
void SCH_EDIT_FRAME::RotateField( SCH_FIELD* aField, wxDC* aDC )
{
{
Loading