2011-10-19 20:32:21 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 2004-2011 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
|
|
|
|
*/
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
/**
|
|
|
|
* @file edit_label.cpp
|
|
|
|
* @brief Label, global label and text creation and editing.
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <base_struct.h>
|
|
|
|
#include <drawtxt.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <wxEeschemaStruct.h>
|
|
|
|
#include <kicad_device_context.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
|
|
|
#include <protos.h>
|
|
|
|
#include <sch_text.h>
|
|
|
|
#include <eeschema_id.h>
|
2010-11-10 15:30:12 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-04-05 14:46:51 +00:00
|
|
|
static int lastGlobalLabelShape = (int) NET_INPUT;
|
|
|
|
static int lastTextOrientation = 0;
|
|
|
|
static bool lastTextBold = false;
|
|
|
|
static bool lastTextItalic = false;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2011-03-03 01:58:12 +00:00
|
|
|
void SCH_EDIT_FRAME::ChangeTextOrient( SCH_TEXT* aTextItem, wxDC* aDC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-04-05 14:46:51 +00:00
|
|
|
wxCHECK_RET( (aTextItem != NULL) && aTextItem->CanIncrementLabel(),
|
|
|
|
wxT( "Invalid schematic text item." ) );
|
2009-06-26 12:52:24 +00:00
|
|
|
|
2011-04-05 14:46:51 +00:00
|
|
|
int orient = ( aTextItem->GetOrientation() + 1 ) & 3;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
// Save current text orientation in undo list if is not already in edit.
|
|
|
|
if( aTextItem->GetFlags() == 0 )
|
|
|
|
SaveCopyInUndoList( aTextItem, UR_CHANGED );
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->CrossHairOff( aDC );
|
|
|
|
aTextItem->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
|
2011-03-25 19:16:05 +00:00
|
|
|
aTextItem->SetOrientation( orient );
|
2011-03-03 01:58:12 +00:00
|
|
|
OnModify();
|
2011-12-22 13:28:11 +00:00
|
|
|
aTextItem->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
|
|
|
|
m_canvas->CrossHairOn( aDC );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-03 01:58:12 +00:00
|
|
|
SCH_TEXT* SCH_EDIT_FRAME::CreateNewText( wxDC* aDC, int aType )
|
2009-12-06 18:04:41 +00:00
|
|
|
{
|
2011-03-03 01:58:12 +00:00
|
|
|
SCH_TEXT* textItem = NULL;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-01-12 21:47:54 +00:00
|
|
|
m_itemToRepeat = NULL;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-03 01:58:12 +00:00
|
|
|
switch( aType )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
case LAYER_NOTES:
|
2011-03-03 01:58:12 +00:00
|
|
|
textItem = new SCH_TEXT( GetScreen()->GetCrossHairPosition() );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_LOCLABEL:
|
2011-03-03 01:58:12 +00:00
|
|
|
textItem = new SCH_LABEL( GetScreen()->GetCrossHairPosition() );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2008-03-20 01:50:21 +00:00
|
|
|
case LAYER_HIERLABEL:
|
2011-03-03 01:58:12 +00:00
|
|
|
textItem = new SCH_HIERLABEL( GetScreen()->GetCrossHairPosition() );
|
2011-12-08 15:45:01 +00:00
|
|
|
textItem->SetShape( lastGlobalLabelShape );
|
2008-02-12 21:12:46 +00:00
|
|
|
break;
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
case LAYER_GLOBLABEL:
|
2011-03-03 01:58:12 +00:00
|
|
|
textItem = new SCH_GLOBALLABEL( GetScreen()->GetCrossHairPosition() );
|
2011-12-08 15:45:01 +00:00
|
|
|
textItem->SetShape( lastGlobalLabelShape );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-12-08 20:12:46 +00:00
|
|
|
DisplayError( this, wxT( "SCH_EDIT_FRAME::CreateNewText() Internal error" ) );
|
2007-09-13 11:28:58 +00:00
|
|
|
return NULL;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-03-03 01:58:12 +00:00
|
|
|
textItem->m_Bold = lastTextBold;
|
|
|
|
textItem->m_Italic = lastTextItalic;
|
|
|
|
textItem->SetOrientation( lastTextOrientation );
|
2012-09-28 17:47:41 +00:00
|
|
|
textItem->m_Size.x = textItem->m_Size.y = GetDefaultLabelSize();
|
2011-03-03 01:58:12 +00:00
|
|
|
textItem->SetFlags( IS_NEW | IS_MOVED );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
textItem->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
|
2011-03-03 01:58:12 +00:00
|
|
|
EditSchematicText( textItem );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-03 01:58:12 +00:00
|
|
|
if( textItem->m_Text.IsEmpty() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-03-03 01:58:12 +00:00
|
|
|
SAFE_DELETE( textItem );
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-03-03 01:58:12 +00:00
|
|
|
lastTextBold = textItem->m_Bold;
|
|
|
|
lastTextItalic = textItem->m_Italic;
|
|
|
|
lastTextOrientation = textItem->GetOrientation();
|
2010-03-16 18:22:59 +00:00
|
|
|
|
2011-04-05 14:46:51 +00:00
|
|
|
if( (aType == SCH_GLOBAL_LABEL_T) || (aType == SCH_HIERARCHICAL_LABEL_T) )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
lastGlobalLabelShape = textItem->GetShape();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
textItem->Draw( m_canvas, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
2011-10-19 20:32:21 +00:00
|
|
|
MoveItem( (SCH_ITEM*) textItem, aDC );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-03 01:58:12 +00:00
|
|
|
return textItem;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2011-10-19 20:32:21 +00:00
|
|
|
|
2011-09-01 16:31:16 +00:00
|
|
|
/*
|
|
|
|
* OnConvertTextType is a command event handler to change a text type to an other one.
|
|
|
|
* The new text, label, hierarchical label, or global label is created from the old text
|
|
|
|
* The old text is deleted.
|
|
|
|
* A tricky case is when the 'old" text is being edited (i.e. moving)
|
|
|
|
* because we must create a new text, and prepare the undo/redo command data for this
|
|
|
|
* change and the current move/edit command
|
|
|
|
*/
|
2011-03-03 01:58:12 +00:00
|
|
|
void SCH_EDIT_FRAME::OnConvertTextType( wxCommandEvent& aEvent )
|
2010-03-16 18:22:59 +00:00
|
|
|
{
|
2011-03-03 01:58:12 +00:00
|
|
|
SCH_SCREEN* screen = GetScreen();
|
|
|
|
SCH_TEXT* text = (SCH_TEXT*) screen->GetCurItem();
|
|
|
|
|
|
|
|
wxCHECK_RET( (text != NULL) && text->CanIncrementLabel(),
|
|
|
|
wxT( "Cannot convert text type." ) );
|
|
|
|
|
|
|
|
KICAD_T type;
|
|
|
|
|
|
|
|
switch( aEvent.GetId() )
|
|
|
|
{
|
|
|
|
case ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_LABEL:
|
|
|
|
type = SCH_LABEL_T;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_GLABEL:
|
|
|
|
type = SCH_GLOBAL_LABEL_T;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_HLABEL:
|
|
|
|
type = SCH_HIERARCHICAL_LABEL_T;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_COMMENT:
|
|
|
|
type = SCH_TEXT_T;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "Invalid text type command ID %d." ),
|
|
|
|
aEvent.GetId() ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( text->Type() == type )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
|
2008-03-20 01:50:21 +00:00
|
|
|
SCH_TEXT* newtext;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-03 01:58:12 +00:00
|
|
|
switch( type )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_LABEL_T:
|
2011-03-03 01:58:12 +00:00
|
|
|
newtext = new SCH_LABEL( text->m_Pos, text->m_Text );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_GLOBAL_LABEL_T:
|
2011-03-03 01:58:12 +00:00
|
|
|
newtext = new SCH_GLOBALLABEL( text->m_Pos, text->m_Text );
|
2008-03-20 01:50:21 +00:00
|
|
|
break;
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_HIERARCHICAL_LABEL_T:
|
2011-03-03 01:58:12 +00:00
|
|
|
newtext = new SCH_HIERLABEL( text->m_Pos, text->m_Text );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_TEXT_T:
|
2011-03-03 01:58:12 +00:00
|
|
|
newtext = new SCH_TEXT( text->m_Pos, text->m_Text );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2007-09-13 11:28:58 +00:00
|
|
|
newtext = NULL;
|
2011-03-03 01:58:12 +00:00
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "Cannot convert text type to %d" ), type ) );
|
2007-09-13 11:28:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-03 01:58:12 +00:00
|
|
|
/* Copy the old text item settings to the new one. Justifications are not copied because
|
|
|
|
* they are not used in labels. Justifications will be set to default value in the new
|
|
|
|
* text item type.
|
2009-06-26 12:52:24 +00:00
|
|
|
*/
|
2011-04-05 14:46:51 +00:00
|
|
|
newtext->SetFlags( text->GetFlags() );
|
2011-12-08 15:45:01 +00:00
|
|
|
newtext->SetShape( text->GetShape() );
|
2011-03-03 01:58:12 +00:00
|
|
|
newtext->SetOrientation( text->GetOrientation() );
|
|
|
|
newtext->m_Size = text->m_Size;
|
|
|
|
newtext->m_Thickness = text->m_Thickness;
|
|
|
|
newtext->m_Italic = text->m_Italic;
|
|
|
|
newtext->m_Bold = text->m_Bold;
|
2007-09-13 11:28:58 +00:00
|
|
|
|
2010-11-26 11:55:34 +00:00
|
|
|
/* Save the new text in undo list if the old text was not itself a "new created text"
|
|
|
|
* In this case, the old text is already in undo list as a deleted item.
|
2009-11-03 13:26:31 +00:00
|
|
|
* Of course if the old text was a "new created text" the new text will be
|
2010-11-26 11:55:34 +00:00
|
|
|
* put in undo list later, at the end of the current command (if not aborted)
|
2007-09-13 11:28:58 +00:00
|
|
|
*/
|
2011-04-05 14:46:51 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
INSTALL_UNBUFFERED_DC( dc, m_canvas );
|
|
|
|
m_canvas->CrossHairOff( &dc ); // Erase schematic cursor
|
|
|
|
text->Draw( m_canvas, &dc, wxPoint( 0, 0 ), g_XorMode );
|
2011-04-05 14:46:51 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
screen->Remove( text );
|
|
|
|
screen->Append( newtext );
|
2011-08-31 14:59:20 +00:00
|
|
|
m_itemToRepeat = NULL;
|
2011-04-05 14:46:51 +00:00
|
|
|
OnModify();
|
2011-12-22 13:28:11 +00:00
|
|
|
newtext->Draw( m_canvas, &dc, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
|
|
|
m_canvas->CrossHairOn( &dc ); // redraw schematic cursor
|
2011-04-05 14:46:51 +00:00
|
|
|
|
2012-08-02 13:23:53 +00:00
|
|
|
// if the old item is the current schematic item, replace it by the new text:
|
|
|
|
if( screen->GetCurItem() == text )
|
|
|
|
screen->SetCurItem( newtext );
|
|
|
|
|
2011-08-31 14:59:20 +00:00
|
|
|
if( text->IsNew() )
|
2007-09-13 11:28:58 +00:00
|
|
|
{
|
2011-08-31 14:59:20 +00:00
|
|
|
// if the previous text is new, no undo command to prepare here
|
2011-09-01 16:31:16 +00:00
|
|
|
// just delete this previous text.
|
2011-08-31 14:59:20 +00:00
|
|
|
delete text;
|
|
|
|
return;
|
2007-09-13 11:28:58 +00:00
|
|
|
}
|
2011-08-31 14:59:20 +00:00
|
|
|
|
|
|
|
// previous text is not new and we replace text by new text.
|
|
|
|
// So this is equivalent to delete text and add newtext
|
|
|
|
// If text if being currently edited (i.e. moved)
|
|
|
|
// we also save the initial copy of text, and prepare undo command for new text modifications.
|
|
|
|
// we must save it as modified text (if currently beeing edited), then deleted text,
|
|
|
|
// and replace text with newtext
|
|
|
|
PICKED_ITEMS_LIST pickList;
|
|
|
|
ITEM_PICKER picker( text, UR_CHANGED );
|
2011-10-19 20:32:21 +00:00
|
|
|
|
2011-08-31 14:59:20 +00:00
|
|
|
if( text->GetFlags() )
|
2008-03-20 01:50:21 +00:00
|
|
|
{
|
2011-09-01 16:31:16 +00:00
|
|
|
// text is being edited, save initial text for undo command
|
2011-08-31 14:59:20 +00:00
|
|
|
picker.SetLink( GetUndoItem() );
|
|
|
|
pickList.PushItem( picker );
|
2011-10-19 20:32:21 +00:00
|
|
|
|
2011-09-01 16:31:16 +00:00
|
|
|
// the owner of undoItem is no more "this", it is now "picker":
|
2011-08-31 14:59:20 +00:00
|
|
|
SetUndoItem( NULL );
|
2011-10-19 20:32:21 +00:00
|
|
|
|
2011-09-01 16:31:16 +00:00
|
|
|
// save current newtext copy for undo/abort current command
|
|
|
|
SetUndoItem( newtext );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2011-08-31 14:59:20 +00:00
|
|
|
|
|
|
|
// Prepare undo command for delete old text
|
2012-02-05 13:02:46 +00:00
|
|
|
picker.SetStatus( UR_DELETED );
|
2011-08-31 14:59:20 +00:00
|
|
|
picker.SetLink( NULL );
|
|
|
|
pickList.PushItem( picker );
|
|
|
|
|
|
|
|
// Prepare undo command for new text
|
2012-02-05 13:02:46 +00:00
|
|
|
picker.SetStatus( UR_NEW );
|
2011-08-31 14:59:20 +00:00
|
|
|
picker.SetItem(newtext);
|
|
|
|
pickList.PushItem( picker );
|
|
|
|
|
|
|
|
SaveCopyInUndoList( pickList, UR_UNSPECIFIED );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2011-07-03 18:51:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Function to increment bus label members numbers,
|
|
|
|
* i.e. when a text is ending with a number, adds
|
|
|
|
* <RepeatDeltaLabel> to this number
|
|
|
|
*/
|
|
|
|
void IncrementLabelMember( wxString& name )
|
|
|
|
{
|
|
|
|
int ii, nn;
|
|
|
|
long number = 0;
|
|
|
|
|
|
|
|
ii = name.Len() - 1; nn = 0;
|
|
|
|
|
|
|
|
if( !isdigit( name.GetChar( ii ) ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
while( (ii >= 0) && isdigit( name.GetChar( ii ) ) )
|
|
|
|
{
|
|
|
|
ii--; nn++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ii++; /* digits are starting at ii position */
|
|
|
|
wxString litt_number = name.Right( nn );
|
|
|
|
|
|
|
|
if( litt_number.ToLong( &number ) )
|
|
|
|
{
|
|
|
|
number += g_RepeatDeltaLabel;
|
|
|
|
name.Remove( ii ); name << number;
|
|
|
|
}
|
|
|
|
}
|