Commit 718b2565 authored by jean-pierre charras's avatar jean-pierre charras
Browse files

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

parent 76e2efed
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -50,6 +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_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
+208 −0
Original line number Original line Diff line number Diff line
/**
 * @file dialog_lib_edit_one_field.cpp
 * @brief dialog to editing  fields ( not graphic texts) in components.
 */

/*
 * 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) 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 <fctsys.h>
#include <common.h>

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

#include <dialog_lib_edit_one_field.h>


DIALOG_LIB_EDIT_ONE_FIELD::DIALOG_LIB_EDIT_ONE_FIELD( LIB_EDIT_FRAME* aParent,
                                                      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;

    m_TextValue->SetFocus();

    // Disable options for graphic text edition, not existing in fields
    m_CommonConvert->Show(false);
    m_CommonUnit->Show(false);

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

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

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

        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_field->m_HJustify )
        {
            case GR_TEXT_HJUSTIFY_LEFT:
                m_TextHJustificationOpt->SetSelection( 0 );
                break;

            case GR_TEXT_HJUSTIFY_CENTER:
                m_TextHJustificationOpt->SetSelection( 1 );
                break;

            case GR_TEXT_HJUSTIFY_RIGHT:
                m_TextHJustificationOpt->SetSelection( 2 );
                break;

        }

        switch ( m_field->m_VJustify )
        {
        case GR_TEXT_VJUSTIFY_BOTTOM:
            m_TextVJustificationOpt->SetSelection( 0 );
            break;

        case GR_TEXT_VJUSTIFY_CENTER:
            m_TextVJustificationOpt->SetSelection( 1 );
            break;

        case GR_TEXT_VJUSTIFY_TOP:
            m_TextVJustificationOpt->SetSelection( 2 );
            break;
        }
    }

    msg = m_TextSizeText->GetLabel() + ReturnUnitSymbol();
    m_TextSizeText->SetLabel( msg );

    m_sdbSizerButtonsOK->SetDefault();
}


void DIALOG_LIB_EDIT_ONE_FIELD::OnCancelClick( wxCommandEvent& event )
{
    EndModal(wxID_CANCEL);
}


/* Updates the different parameters for the component being edited */
void DIALOG_LIB_EDIT_ONE_FIELD::OnOkClick( wxCommandEvent& event )
{
    EndModal(wxID_OK);
}

wxString DIALOG_LIB_EDIT_ONE_FIELD::GetTextField()
{
    wxString line = m_TextValue->GetValue();
    line.Replace( wxT( " " ), wxT( "_" ) );
    return line;
};

void DIALOG_LIB_EDIT_ONE_FIELD::TransfertDataToField()
{

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

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

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

        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;

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

        case 1:
            m_field->m_HJustify = GR_TEXT_HJUSTIFY_CENTER;
            break;

        case 2:
            m_field->m_HJustify = GR_TEXT_HJUSTIFY_RIGHT;
            break;
        }

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

        case 1:
            m_field->m_VJustify = GR_TEXT_VJUSTIFY_CENTER;
            break;

        case 2:
            m_field->m_VJustify = GR_TEXT_VJUSTIFY_TOP;
            break;
        }
    }
}
+32 −0
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_
+49 −46
Original line number Original line Diff line number Diff line
/**
/**
 * @file dialog_lib_edit_text.cpp
 * @file dialog_lib_edit_text.cpp
 * @brief dialog to editing graphic texts (not fields) in bodu components.
 * @brief dialog to editing graphic texts (not fields) in body components.
 */
 */


/*
/*
@@ -43,8 +43,8 @@
DIALOG_LIB_EDIT_TEXT::DIALOG_LIB_EDIT_TEXT( LIB_EDIT_FRAME* aParent, LIB_TEXT* aText ) :
DIALOG_LIB_EDIT_TEXT::DIALOG_LIB_EDIT_TEXT( LIB_EDIT_FRAME* aParent, LIB_TEXT* aText ) :
    DIALOG_LIB_EDIT_TEXT_BASE( aParent )
    DIALOG_LIB_EDIT_TEXT_BASE( aParent )
{
{
    m_Parent = aParent;
    m_parent = aParent;
    m_GraphicText = aText;
    m_graphicText = aText;
    initDlg();
    initDlg();


    GetSizer()->SetSizeHints(this);
    GetSizer()->SetSizeHints(this);
@@ -58,29 +58,32 @@ void DIALOG_LIB_EDIT_TEXT::initDlg( )


    m_TextValue->SetFocus();
    m_TextValue->SetFocus();


    if ( m_GraphicText )
    // Disable options for fieldedition, not existing in  graphic text
    m_Invisible->Show(false);

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


        if ( m_GraphicText->GetUnit() == 0 )
        if ( m_graphicText->GetUnit() == 0 )
            m_CommonUnit->SetValue( true );
            m_CommonUnit->SetValue( true );
        if ( m_GraphicText->GetConvert() == 0 )
        if ( m_graphicText->GetConvert() == 0 )
            m_CommonConvert->SetValue( true );
            m_CommonConvert->SetValue( true );
        if ( m_GraphicText->m_Orient == TEXT_ORIENT_VERT )
        if ( m_graphicText->m_Orient == TEXT_ORIENT_VERT )
            m_Orient->SetValue( true );
            m_Orient->SetValue( true );


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


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


        switch ( m_GraphicText->m_HJustify )
        switch ( m_graphicText->m_HJustify )
        {
        {
            case GR_TEXT_HJUSTIFY_LEFT:
            case GR_TEXT_HJUSTIFY_LEFT:
                m_TextHJustificationOpt->SetSelection( 0 );
                m_TextHJustificationOpt->SetSelection( 0 );
@@ -96,7 +99,7 @@ void DIALOG_LIB_EDIT_TEXT::initDlg( )


        }
        }


        switch ( m_GraphicText->m_VJustify )
        switch ( m_graphicText->m_VJustify )
        {
        {
        case GR_TEXT_VJUSTIFY_BOTTOM:
        case GR_TEXT_VJUSTIFY_BOTTOM:
            m_TextVJustificationOpt->SetSelection( 0 );
            m_TextVJustificationOpt->SetSelection( 0 );
@@ -113,15 +116,15 @@ void DIALOG_LIB_EDIT_TEXT::initDlg( )
    }
    }
    else
    else
    {
    {
        msg = ReturnStringFromValue( g_UserUnit, m_Parent->m_textSize,
        msg = ReturnStringFromValue( g_UserUnit, m_parent->m_textSize,
                                     m_Parent->GetInternalUnits() );
                                     m_parent->GetInternalUnits() );
        m_TextSize->SetValue( msg );
        m_TextSize->SetValue( msg );


        if ( ! m_Parent->m_drawSpecificUnit )
        if ( ! m_parent->m_drawSpecificUnit )
            m_CommonUnit->SetValue( true );
            m_CommonUnit->SetValue( true );
        if ( ! m_Parent->m_drawSpecificConvert )
        if ( ! m_parent->m_drawSpecificConvert )
            m_CommonConvert->SetValue( true );
            m_CommonConvert->SetValue( true );
        if ( m_Parent->m_textOrientation == TEXT_ORIENT_VERT )
        if ( m_parent->m_textOrientation == TEXT_ORIENT_VERT )
            m_Orient->SetValue( true );
            m_Orient->SetValue( true );
    }
    }


@@ -144,75 +147,75 @@ void DIALOG_LIB_EDIT_TEXT::OnOkClick( wxCommandEvent& event )
    wxString Line;
    wxString Line;


    Line = m_TextValue->GetValue();
    Line = m_TextValue->GetValue();
    m_Parent->m_textOrientation = m_Orient->GetValue() ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ;
    m_parent->m_textOrientation = m_Orient->GetValue() ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ;
    wxString msg = m_TextSize->GetValue();
    wxString msg = m_TextSize->GetValue();
    m_Parent->m_textSize = ReturnValueFromString( g_UserUnit, msg, m_Parent->GetInternalUnits() );
    m_parent->m_textSize = ReturnValueFromString( g_UserUnit, msg, m_parent->GetInternalUnits() );
    m_Parent->m_drawSpecificConvert = m_CommonConvert->GetValue() ? false : true;
    m_parent->m_drawSpecificConvert = m_CommonConvert->GetValue() ? false : true;
    m_Parent->m_drawSpecificUnit = m_CommonUnit->GetValue() ? false : true;
    m_parent->m_drawSpecificUnit = m_CommonUnit->GetValue() ? false : true;


    if( m_GraphicText )
    if( m_graphicText )
    {
    {
        if( ! Line.IsEmpty() )
        if( ! Line.IsEmpty() )
            m_GraphicText->SetText( Line );
            m_graphicText->SetText( Line );
        else
        else
            m_GraphicText->SetText( wxT( "[null]" ) );
            m_graphicText->SetText( wxT( "[null]" ) );


        m_GraphicText->m_Size.x = m_GraphicText->m_Size.y = m_Parent->m_textSize;
        m_graphicText->m_Size.x = m_graphicText->m_Size.y = m_parent->m_textSize;
        m_GraphicText->m_Orient = m_Parent->m_textOrientation;
        m_graphicText->m_Orient = m_parent->m_textOrientation;


        if( m_Parent->m_drawSpecificUnit )
        if( m_parent->m_drawSpecificUnit )
            m_GraphicText->SetUnit( m_Parent->GetUnit() );
            m_graphicText->SetUnit( m_parent->GetUnit() );
        else
        else
            m_GraphicText->SetUnit( 0 );
            m_graphicText->SetUnit( 0 );


        if( m_Parent->m_drawSpecificConvert )
        if( m_parent->m_drawSpecificConvert )
            m_GraphicText->SetConvert( m_Parent->GetConvert() );
            m_graphicText->SetConvert( m_parent->GetConvert() );
        else
        else
            m_GraphicText->SetConvert( 0 );
            m_graphicText->SetConvert( 0 );


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


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


        switch( m_TextHJustificationOpt->GetSelection() )
        switch( m_TextHJustificationOpt->GetSelection() )
        {
        {
        case 0:
        case 0:
            m_GraphicText->m_HJustify = GR_TEXT_HJUSTIFY_LEFT;
            m_graphicText->m_HJustify = GR_TEXT_HJUSTIFY_LEFT;
            break;
            break;


        case 1:
        case 1:
            m_GraphicText->m_HJustify = GR_TEXT_HJUSTIFY_CENTER;
            m_graphicText->m_HJustify = GR_TEXT_HJUSTIFY_CENTER;
            break;
            break;


        case 2:
        case 2:
            m_GraphicText->m_HJustify = GR_TEXT_HJUSTIFY_RIGHT;
            m_graphicText->m_HJustify = GR_TEXT_HJUSTIFY_RIGHT;
            break;
            break;
        }
        }


        switch( m_TextVJustificationOpt->GetSelection() )
        switch( m_TextVJustificationOpt->GetSelection() )
        {
        {
        case 0:
        case 0:
            m_GraphicText->m_VJustify = GR_TEXT_VJUSTIFY_BOTTOM;
            m_graphicText->m_VJustify = GR_TEXT_VJUSTIFY_BOTTOM;
            break;
            break;


        case 1:
        case 1:
            m_GraphicText->m_VJustify = GR_TEXT_VJUSTIFY_CENTER;
            m_graphicText->m_VJustify = GR_TEXT_VJUSTIFY_CENTER;
            break;
            break;


        case 2:
        case 2:
            m_GraphicText->m_VJustify = GR_TEXT_VJUSTIFY_TOP;
            m_graphicText->m_VJustify = GR_TEXT_VJUSTIFY_TOP;
            break;
            break;
        }
        }
    }
    }


    if( m_Parent->GetDrawItem() )
    if( m_parent->GetDrawItem() )
        m_Parent->GetDrawItem()->DisplayInfo( m_Parent );
        m_parent->GetDrawItem()->DisplayInfo( m_parent );


    EndModal(wxID_OK);
    EndModal(wxID_OK);
}
}
+2 −2
Original line number Original line Diff line number Diff line
@@ -13,8 +13,8 @@ class LIB_TEXT;
class DIALOG_LIB_EDIT_TEXT : public DIALOG_LIB_EDIT_TEXT_BASE
class DIALOG_LIB_EDIT_TEXT : public DIALOG_LIB_EDIT_TEXT_BASE
{
{
private:
private:
    LIB_EDIT_FRAME* m_Parent;
    LIB_EDIT_FRAME* m_parent;
    LIB_TEXT* m_GraphicText;
    LIB_TEXT* m_graphicText;


public:
public:
    DIALOG_LIB_EDIT_TEXT( LIB_EDIT_FRAME* aParent, LIB_TEXT* aText );
    DIALOG_LIB_EDIT_TEXT( LIB_EDIT_FRAME* aParent, LIB_TEXT* aText );
Loading