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

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

parent 76e2efed
......@@ -50,6 +50,7 @@ set(EESCHEMA_SRCS
dialogs/dialog_edit_label_base.cpp
dialogs/dialog_edit_libentry_fields_in_lib.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_fbp.cpp
dialogs/dialog_eeschema_options_base.cpp
......
/**
* @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;
}
}
}
#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_
/**
* @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_BASE( aParent )
{
m_Parent = aParent;
m_GraphicText = aText;
m_parent = aParent;
m_graphicText = aText;
initDlg();
GetSizer()->SetSizeHints(this);
......@@ -58,29 +58,32 @@ void DIALOG_LIB_EDIT_TEXT::initDlg( )
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,
m_Parent->GetInternalUnits() );
msg = ReturnStringFromValue( g_UserUnit, m_graphicText->m_Size.x,
m_parent->GetInternalUnits() );
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 );
if ( m_GraphicText->GetConvert() == 0 )
if ( m_graphicText->GetConvert() == 0 )
m_CommonConvert->SetValue( true );
if ( m_GraphicText->m_Orient == TEXT_ORIENT_VERT )
if ( m_graphicText->m_Orient == TEXT_ORIENT_VERT )
m_Orient->SetValue( true );
int shape = 0;
if ( m_GraphicText->m_Italic )
if ( m_graphicText->m_Italic )
shape = 1;
if ( m_GraphicText->m_Bold )
if ( m_graphicText->m_Bold )
shape |= 2;
m_TextShapeOpt->SetSelection( shape );
switch ( m_GraphicText->m_HJustify )
switch ( m_graphicText->m_HJustify )
{
case GR_TEXT_HJUSTIFY_LEFT:
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:
m_TextVJustificationOpt->SetSelection( 0 );
......@@ -113,15 +116,15 @@ void DIALOG_LIB_EDIT_TEXT::initDlg( )
}
else
{
msg = ReturnStringFromValue( g_UserUnit, m_Parent->m_textSize,
m_Parent->GetInternalUnits() );
msg = ReturnStringFromValue( g_UserUnit, m_parent->m_textSize,
m_parent->GetInternalUnits() );
m_TextSize->SetValue( msg );
if ( ! m_Parent->m_drawSpecificUnit )
if ( ! m_parent->m_drawSpecificUnit )
m_CommonUnit->SetValue( true );
if ( ! m_Parent->m_drawSpecificConvert )
if ( ! m_parent->m_drawSpecificConvert )
m_CommonConvert->SetValue( true );
if ( m_Parent->m_textOrientation == TEXT_ORIENT_VERT )
if ( m_parent->m_textOrientation == TEXT_ORIENT_VERT )
m_Orient->SetValue( true );
}
......@@ -144,75 +147,75 @@ void DIALOG_LIB_EDIT_TEXT::OnOkClick( wxCommandEvent& event )
wxString Line;
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();
m_Parent->m_textSize = ReturnValueFromString( g_UserUnit, msg, m_Parent->GetInternalUnits() );
m_Parent->m_drawSpecificConvert = m_CommonConvert->GetValue() ? false : true;
m_Parent->m_drawSpecificUnit = m_CommonUnit->GetValue() ? false : true;
m_parent->m_textSize = ReturnValueFromString( g_UserUnit, msg, m_parent->GetInternalUnits() );
m_parent->m_drawSpecificConvert = m_CommonConvert->GetValue() ? false : true;
m_parent->m_drawSpecificUnit = m_CommonUnit->GetValue() ? false : true;
if( m_GraphicText )
if( m_graphicText )
{
if( ! Line.IsEmpty() )
m_GraphicText->SetText( Line );
m_graphicText->SetText( Line );
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_Orient = m_Parent->m_textOrientation;
m_graphicText->m_Size.x = m_graphicText->m_Size.y = m_parent->m_textSize;
m_graphicText->m_Orient = m_parent->m_textOrientation;
if( m_Parent->m_drawSpecificUnit )
m_GraphicText->SetUnit( m_Parent->GetUnit() );
if( m_parent->m_drawSpecificUnit )
m_graphicText->SetUnit( m_parent->GetUnit() );
else
m_GraphicText->SetUnit( 0 );
m_graphicText->SetUnit( 0 );
if( m_Parent->m_drawSpecificConvert )
m_GraphicText->SetConvert( m_Parent->GetConvert() );
if( m_parent->m_drawSpecificConvert )
m_graphicText->SetConvert( m_parent->GetConvert() );
else
m_GraphicText->SetConvert( 0 );
m_graphicText->SetConvert( 0 );
if( ( m_TextShapeOpt->GetSelection() & 1 ) != 0 )
m_GraphicText->m_Italic = true;
m_graphicText->m_Italic = true;
else
m_GraphicText->m_Italic = false;
m_graphicText->m_Italic = false;
if( ( m_TextShapeOpt->GetSelection() & 2 ) != 0 )
m_GraphicText->m_Bold = true;
m_graphicText->m_Bold = true;
else
m_GraphicText->m_Bold = false;
m_graphicText->m_Bold = false;
switch( m_TextHJustificationOpt->GetSelection() )
{
case 0:
m_GraphicText->m_HJustify = GR_TEXT_HJUSTIFY_LEFT;
m_graphicText->m_HJustify = GR_TEXT_HJUSTIFY_LEFT;
break;
case 1:
m_GraphicText->m_HJustify = GR_TEXT_HJUSTIFY_CENTER;
m_graphicText->m_HJustify = GR_TEXT_HJUSTIFY_CENTER;
break;
case 2:
m_GraphicText->m_HJustify = GR_TEXT_HJUSTIFY_RIGHT;
m_graphicText->m_HJustify = GR_TEXT_HJUSTIFY_RIGHT;
break;
}
switch( m_TextVJustificationOpt->GetSelection() )
{
case 0:
m_GraphicText->m_VJustify = GR_TEXT_VJUSTIFY_BOTTOM;
m_graphicText->m_VJustify = GR_TEXT_VJUSTIFY_BOTTOM;
break;
case 1:
m_GraphicText->m_VJustify = GR_TEXT_VJUSTIFY_CENTER;
m_graphicText->m_VJustify = GR_TEXT_VJUSTIFY_CENTER;
break;
case 2:
m_GraphicText->m_VJustify = GR_TEXT_VJUSTIFY_TOP;
m_graphicText->m_VJustify = GR_TEXT_VJUSTIFY_TOP;
break;
}
}
if( m_Parent->GetDrawItem() )
m_Parent->GetDrawItem()->DisplayInfo( m_Parent );
if( m_parent->GetDrawItem() )
m_parent->GetDrawItem()->DisplayInfo( m_parent );
EndModal(wxID_OK);
}
......@@ -13,8 +13,8 @@ class LIB_TEXT;
class DIALOG_LIB_EDIT_TEXT : public DIALOG_LIB_EDIT_TEXT_BASE
{
private:
LIB_EDIT_FRAME* m_Parent;
LIB_TEXT* m_GraphicText;
LIB_EDIT_FRAME* m_parent;
LIB_TEXT* m_graphicText;
public:
DIALOG_LIB_EDIT_TEXT( LIB_EDIT_FRAME* aParent, LIB_TEXT* aText );
......
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Nov 17 2010)
// C++ code generated with wxFormBuilder (version Jun 30 2011)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
......@@ -68,6 +68,9 @@ DIALOG_LIB_EDIT_TEXT_BASE::DIALOG_LIB_EDIT_TEXT_BASE( wxWindow* parent, wxWindow
m_CommonConvert = new wxCheckBox( this, wxID_ANY, _("Common to convert"), wxDefaultPosition, wxDefaultSize, 0 );
sOptionsSizer->Add( m_CommonConvert, 0, wxALL|wxEXPAND, 5 );
m_Invisible = new wxCheckBox( this, wxID_ANY, _("Invisible"), wxDefaultPosition, wxDefaultSize, 0 );
sOptionsSizer->Add( m_Invisible, 0, wxALL, 5 );
bBottomtBoxSizer->Add( sOptionsSizer, 0, wxALL|wxEXPAND, 5 );
wxString m_TextShapeOptChoices[] = { _("Normal"), _("Italic"), _("Bold"), _("Bold Italic") };
......
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Nov 17 2010)
// C++ code generated with wxFormBuilder (version Jun 30 2011)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#ifndef __dialog_lib_edit_text_base__
#define __dialog_lib_edit_text_base__
#ifndef __DIALOG_LIB_EDIT_TEXT_BASE_H__
#define __DIALOG_LIB_EDIT_TEXT_BASE_H__
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/intl.h>
#include <wx/string.h>
#include <wx/stattext.h>
#include <wx/gdicmn.h>
......@@ -43,6 +44,7 @@ class DIALOG_LIB_EDIT_TEXT_BASE : public wxDialog
wxStaticLine* m_staticline1;
wxCheckBox* m_CommonUnit;
wxCheckBox* m_CommonConvert;
wxCheckBox* m_Invisible;
wxRadioBox* m_TextShapeOpt;
wxRadioBox* m_TextHJustificationOpt;
wxRadioBox* m_TextVJustificationOpt;
......@@ -62,4 +64,4 @@ class DIALOG_LIB_EDIT_TEXT_BASE : public wxDialog
};
#endif //__dialog_lib_edit_text_base__
#endif //__DIALOG_LIB_EDIT_TEXT_BASE_H__
......@@ -206,7 +206,7 @@ void LIB_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition )
case LIB_FIELD_T:
if( m_drawItem->GetFlags() == 0 )
{
EditField( DC, (LIB_FIELD*) m_drawItem );
EditField( (LIB_FIELD*) m_drawItem );
}
break;
......
......@@ -775,7 +775,7 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
if( m_drawItem->Type() == LIB_FIELD_T )
{
EditField( &dc, (LIB_FIELD*) m_drawItem );
EditField( (LIB_FIELD*) m_drawItem );
}
m_canvas->MoveCursorToCrossHair();
......@@ -992,7 +992,7 @@ void LIB_EDIT_FRAME::OnCreateNewPartFromExisting( wxCommandEvent& event )
INSTALL_UNBUFFERED_DC( dc, m_canvas );
m_canvas->CrossHairOff( &dc );
EditField( &dc, &m_component->GetValueField() );
EditField( &m_component->GetValueField() );
m_canvas->MoveCursorToCrossHair();
m_canvas->CrossHairOn( &dc );
}
......
......@@ -515,7 +515,7 @@ private:
void EditSymbolText( wxDC* DC, LIB_ITEM* DrawItem );
LIB_ITEM* LocateItemUsingCursor( const wxPoint& aPosition,
const KICAD_T aFilterList[] = LIB_COLLECTOR::AllItems );
void EditField( wxDC* DC, LIB_FIELD* Field );
void EditField( LIB_FIELD* Field );
public:
/**
......
......@@ -13,9 +13,10 @@
#include <libeditframe.h>
#include <class_library.h>
#include <template_fieldnames.h>
#include <dialog_lib_edit_one_field.h>
void LIB_EDIT_FRAME::EditField( wxDC* DC, LIB_FIELD* aField )
void LIB_EDIT_FRAME::EditField( LIB_FIELD* aField )
{
wxString text;
wxString title;
......@@ -36,19 +37,17 @@ void LIB_EDIT_FRAME::EditField( wxDC* DC, LIB_FIELD* aField )
}
else
{
caption = _( "Edit Field" );
caption.Printf( _( "Edit Field %s" ), GetChars( aField->GetName() ) );
title.Printf( _( "Enter a new value for the %s field." ),
GetChars( aField->GetName().Lower() ) );
}
wxTextEntryDialog dlg( this, title, caption, aField->m_Text );
DIALOG_LIB_EDIT_ONE_FIELD dlg( this, caption, aField );
if( dlg.ShowModal() != wxID_OK || dlg.GetValue() == aField->m_Text )
if( dlg.ShowModal() != wxID_OK )
return;
text = dlg.GetValue();
text.Replace( wxT( " " ), wxT( "_" ) );
text = dlg.GetTextField();
// Perform some controls:
if( ( aField->GetId() == REFERENCE || aField->GetId() == VALUE ) && text.IsEmpty ( ) )
......@@ -72,7 +71,7 @@ void LIB_EDIT_FRAME::EditField( wxDC* DC, LIB_FIELD* aField )
* the old one. Rename the component and remove any conflicting aliases to prevent name
* errors when updating the library.
*/
if( aField->GetId() == VALUE )
if( (aField->GetId() == VALUE) && ( text != aField->m_Text ) )
{
wxString msg;
......@@ -142,19 +141,12 @@ this component?" ),
}
if( !aField->InEditMode() )
{
SaveCopyInUndoList( parent );
( (LIB_ITEM*) aField )->Draw( m_canvas, DC, wxPoint( 0, 0 ), -1, g_XorMode,
&fieldText, DefaultTransform );
}
// Update field
dlg.TransfertDataToField();
if( !aField->InEditMode() )
{
fieldText = aField->GetFullText( m_unit );
( (LIB_ITEM*) aField )->Draw( m_canvas, DC, wxPoint( 0, 0 ), -1, g_XorMode,
&fieldText, DefaultTransform );
}
m_canvas->Refresh();
OnModify();
UpdateAliasSelectList();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment