2011-10-19 20:32:21 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2013-02-11 18:50:55 +00:00
|
|
|
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2008-2013 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 2004-2013 KiCad Developers, see change_log.txt for contributors.
|
2011-10-19 20:32:21 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
/**
|
|
|
|
* @file edit_component_in_schematic.cpp
|
|
|
|
* @brief Schematic component editing code.
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
2015-02-21 09:46:44 +00:00
|
|
|
#include <schframe.h>
|
2013-01-12 17:32:24 +00:00
|
|
|
#include <msgpanel.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
|
|
|
#include <class_library.h>
|
|
|
|
#include <sch_component.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-02-22 14:04:48 +00:00
|
|
|
#include <dialog_edit_one_field.h>
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-06-03 11:16:08 +00:00
|
|
|
void SCH_EDIT_FRAME::EditComponentFieldText( SCH_FIELD* aField )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
wxCHECK_RET( aField != NULL && aField->Type() == SCH_FIELD_T,
|
2011-03-29 15:21:35 +00:00
|
|
|
wxT( "Cannot edit invalid schematic field." ) );
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2011-10-21 18:17:51 +00:00
|
|
|
int fieldNdx;
|
2011-03-25 19:16:05 +00:00
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) aField->GetParent();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
wxCHECK_RET( component != NULL && component->Type() == SCH_COMPONENT_T,
|
|
|
|
wxT( "Invalid schematic field parent item." ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
LIB_PART* part = Prj().SchLibs()->FindLibPart( component->GetPartName() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
wxCHECK_RET( part, wxT( "Library part for component <" ) +
|
|
|
|
component->GetPartName() + wxT( "> could not be found." ) );
|
2010-12-07 16:10:42 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
fieldNdx = aField->GetId();
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
// Save old component in undo list if not already in edit, or moving.
|
2011-03-25 19:16:05 +00:00
|
|
|
if( aField->GetFlags() == 0 )
|
|
|
|
SaveCopyInUndoList( component, UR_CHANGED );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-10-21 18:17:51 +00:00
|
|
|
// Don't use GetText() here. If the field is the reference designator and it's parent
|
|
|
|
// component has multiple parts, we don't want the part suffix added to the field.
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetIgnoreMouseEvents( true );
|
2010-07-20 10:30:40 +00:00
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
wxString title;
|
2011-12-07 18:47:59 +00:00
|
|
|
title.Printf( _( "Edit %s Field" ), GetChars( aField->GetName() ) );
|
2011-03-29 15:21:35 +00:00
|
|
|
|
2012-02-22 14:04:48 +00:00
|
|
|
DIALOG_SCH_EDIT_ONE_FIELD dlg( this, title, aField );
|
|
|
|
|
2015-03-23 11:45:31 +00:00
|
|
|
// Value fields of power components cannot be modified. This will grey out
|
|
|
|
// the text box and display an explanation.
|
|
|
|
if( fieldNdx == VALUE && part->IsPower() )
|
|
|
|
{
|
|
|
|
dlg.SetPowerWarning( true );
|
|
|
|
}
|
|
|
|
|
2014-10-14 20:39:25 +00:00
|
|
|
//The diag may invoke a kiway player for footprint fields
|
|
|
|
//so we must use a quasimodal
|
|
|
|
int response = dlg.ShowQuasiModal();
|
2011-03-29 15:21:35 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetIgnoreMouseEvents( false );
|
2015-02-20 19:04:32 +00:00
|
|
|
wxString newtext = dlg.GetTextField( );
|
2010-07-20 10:30:40 +00:00
|
|
|
|
2012-02-22 14:04:48 +00:00
|
|
|
if ( response != wxID_OK )
|
2011-03-29 15:21:35 +00:00
|
|
|
return; // canceled by user
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-02-22 14:04:48 +00:00
|
|
|
// make some tests
|
|
|
|
bool can_update = true;
|
2007-08-20 01:20:48 +00:00
|
|
|
if( !newtext.IsEmpty() )
|
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
if( fieldNdx == REFERENCE )
|
|
|
|
{
|
2012-06-03 11:16:08 +00:00
|
|
|
// Test if the reference string is valid:
|
2011-05-31 16:29:14 +00:00
|
|
|
if( SCH_COMPONENT::IsReferenceStringValid( newtext ) )
|
|
|
|
{
|
2011-12-08 21:05:43 +00:00
|
|
|
component->SetRef( m_CurrentSheet, newtext );
|
2011-05-31 16:29:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "Illegal reference string! No change" ) );
|
2012-02-22 14:04:48 +00:00
|
|
|
can_update = false;
|
2011-05-31 16:29:14 +00:00
|
|
|
}
|
2008-03-20 01:50:21 +00:00
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2009-11-03 13:26:31 +00:00
|
|
|
else
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
if( fieldNdx == REFERENCE )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
DisplayError( this, _( "The reference field cannot be empty! No change" ) );
|
2012-02-22 14:04:48 +00:00
|
|
|
can_update = false;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2015-03-23 11:45:31 +00:00
|
|
|
else if( fieldNdx == VALUE && ! part->IsPower() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2015-03-23 11:45:31 +00:00
|
|
|
// Note that power components also should not have empty value fields - but
|
|
|
|
// since the user is forbidden from changing the value field here, if it
|
|
|
|
// were to happen somehow, it'd be awfully confusing if an error were to
|
|
|
|
// be displayed!
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
DisplayError( this, _( "The value field cannot be empty! No change" ) );
|
2012-02-22 14:04:48 +00:00
|
|
|
can_update = false;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2015-03-23 11:45:31 +00:00
|
|
|
else if ( !( fieldNdx == VALUE && part->IsPower() ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2012-02-22 14:04:48 +00:00
|
|
|
dlg.SetTextField( wxT( "~" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-22 14:04:48 +00:00
|
|
|
if( can_update )
|
|
|
|
{
|
2015-03-23 11:45:31 +00:00
|
|
|
dlg.TransfertDataToField( /* aIncludeText = */ !( fieldNdx == VALUE && part->IsPower() ) );
|
2012-02-22 14:04:48 +00:00
|
|
|
OnModify();
|
2012-06-03 11:16:08 +00:00
|
|
|
m_canvas->Refresh();
|
2012-02-22 14:04:48 +00:00
|
|
|
}
|
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
MSG_PANEL_ITEMS items;
|
|
|
|
component->SetCurrentSheetPath( &GetCurrentSheet() );
|
|
|
|
component->GetMsgPanelInfo( items );
|
|
|
|
SetMsgPanel( items );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
void SCH_EDIT_FRAME::RotateField( SCH_FIELD* aField, wxDC* aDC )
|
2010-04-27 19:19:04 +00:00
|
|
|
{
|
2011-03-29 15:21:35 +00:00
|
|
|
wxCHECK_RET( aField != NULL && aField->Type() == SCH_FIELD_T && !aField->GetText().IsEmpty(),
|
|
|
|
wxT( "Cannot rotate invalid schematic field." ) );
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) aField->GetParent();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
// Save old component in undo list if not already in edit, or moving.
|
|
|
|
if( aField->GetFlags() == 0 )
|
|
|
|
SaveCopyInUndoList( component, UR_CHANGED );
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
aField->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
if( aField->GetOrientation() == TEXT_ORIENT_HORIZ )
|
|
|
|
aField->SetOrientation( TEXT_ORIENT_VERT );
|
2011-03-29 15:21:35 +00:00
|
|
|
else
|
2013-03-18 19:36:07 +00:00
|
|
|
aField->SetOrientation( TEXT_ORIENT_HORIZ );
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
aField->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2010-05-23 17:39:47 +00:00
|
|
|
OnModify();
|
2007-12-11 16:41:43 +00:00
|
|
|
}
|