eeschema: Allow spaces in label names for multilabeling

This adds the functionality to add multiple labels to your schematic at
once by using spaces in the original label name.

Fixes: lp:1095113
* https://bugs.launchpad.net/kicad/+bug/1095113
This commit is contained in:
Seth Hillbrand 2019-06-19 23:20:33 -07:00
parent 57a60a32f5
commit 39c2745f55
7 changed files with 72 additions and 6 deletions

View File

@ -102,7 +102,7 @@ const int MAX_TEXTSIZE = INT_MAX;
DIALOG_LABEL_EDITOR::DIALOG_LABEL_EDITOR( SCH_EDIT_FRAME* aParent, SCH_TEXT* aTextItem ) :
DIALOG_LABEL_EDITOR_BASE( aParent ),
m_textSize( aParent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits, false ),
m_netNameValidator()
m_netNameValidator( true )
{
m_Parent = aParent;
m_CurrentText = aTextItem;
@ -146,6 +146,8 @@ DIALOG_LABEL_EDITOR::DIALOG_LABEL_EDITOR( SCH_EDIT_FRAME* aParent, SCH_TEXT* aTe
if( m_CurrentText->Type() != SCH_TEXT_T )
m_valueSingleLine->SetValidator( m_netNameValidator );
m_valueCombo->SetValidator( m_netNameValidator );
}
SetInitialFocus( m_activeTextCtrl );

View File

@ -35,6 +35,9 @@
#include <sch_text.h>
#include <eeschema_id.h>
#include <sch_view.h>
#include <wx/tokenzr.h>
#include "invoke_sch_dialog.h"
static PINSHEETLABEL_SHAPE lastGlobalLabelShape = NET_INPUT;
@ -42,12 +45,27 @@ static int lastTextOrientation = 0;
static bool lastTextBold = false;
static bool lastTextItalic = false;
static std::deque<std::unique_ptr<SCH_TEXT>> queuedTexts;
SCH_TEXT* SCH_EDIT_FRAME::GetNextNewText()
{
if( queuedTexts.empty() )
return nullptr;
auto next_text = std::move( queuedTexts.front() );
queuedTexts.pop_front();
return next_text.release();
}
SCH_TEXT* SCH_EDIT_FRAME::CreateNewText( int aType )
{
wxPoint cursorPos = (wxPoint) GetCanvas()->GetViewControls()->GetCursorPosition();
SCH_TEXT* textItem = nullptr;
queuedTexts.clear();
switch( aType )
{
case LAYER_NOTES:
@ -85,6 +103,19 @@ SCH_TEXT* SCH_EDIT_FRAME::CreateNewText( int aType )
return nullptr;
}
if( aType != LAYER_NOTES )
{
wxStringTokenizer tok( textItem->GetText(), wxDEFAULT_DELIMITERS, wxTOKEN_STRTOK );
textItem->SetText( tok.GetNextToken() );
while( tok.HasMoreTokens() )
{
std::unique_ptr<SCH_TEXT> nextitem( static_cast<SCH_TEXT*>( textItem->Clone() ) );
nextitem->SetText( tok.GetNextToken() );
queuedTexts.push_back( std::move( nextitem ) );
}
}
lastTextBold = textItem->IsBold();
lastTextItalic = textItem->IsItalic();
lastTextOrientation = textItem->GetLabelSpinStyle();

View File

@ -675,6 +675,12 @@ public:
SCH_JUNCTION* AddJunction( const wxPoint& aPos, bool aAppendToUndo = false,
bool aFinal = true );
/**
* Gets the next queued text item
* @return next SCH_TEXT* or nullptr if empty
*/
SCH_TEXT* GetNextNewText();
SCH_TEXT* CreateNewText( int aType );
/**

View File

@ -126,6 +126,7 @@ SCH_TEXT::SCH_TEXT( const SCH_TEXT& aText ) :
m_shape = aText.m_shape;
m_isDangling = aText.m_isDangling;
m_spin_style = aText.m_spin_style;
m_connectionType = aText.m_connectionType;
}

View File

@ -144,12 +144,19 @@ bool SCH_FIELD_VALIDATOR::Validate( wxWindow *aParent )
SCH_NETNAME_VALIDATOR::SCH_NETNAME_VALIDATOR( wxString *aVal ) :
wxValidator()
wxValidator(), m_allowSpaces( false )
{
}
SCH_NETNAME_VALIDATOR::SCH_NETNAME_VALIDATOR( const SCH_NETNAME_VALIDATOR& aValidator )
SCH_NETNAME_VALIDATOR::SCH_NETNAME_VALIDATOR( const SCH_NETNAME_VALIDATOR& aValidator ) :
m_allowSpaces( aValidator.m_allowSpaces )
{
}
SCH_NETNAME_VALIDATOR::SCH_NETNAME_VALIDATOR( bool aAllowSpaces ) :
wxValidator(), m_allowSpaces( aAllowSpaces )
{
}
@ -215,7 +222,7 @@ wxString SCH_NETNAME_VALIDATOR::IsValid( const wxString& str ) const
if( str.Contains( '\r' ) || str.Contains( '\n' ) )
return _( "Signal names cannot contain CR or LF characters" );
if( str.Contains( ' ' ) || str.Contains( '\t' ) )
if( !m_allowSpaces && ( str.Contains( ' ' ) || str.Contains( '\t' ) ) )
return _( "Signal names cannot contain spaces" );
return wxString();

View File

@ -72,8 +72,14 @@ class SCH_NETNAME_VALIDATOR : public wxValidator
public:
SCH_NETNAME_VALIDATOR( wxString *aVal = nullptr );
SCH_NETNAME_VALIDATOR( bool aAllowSpaces );
SCH_NETNAME_VALIDATOR( const SCH_NETNAME_VALIDATOR& aValidator );
void SetAllowSpaces( bool aAllowSpaces = true ) { m_allowSpaces = aAllowSpaces; }
bool GetAllowSpaces() const { return m_allowSpaces; }
bool Copy( const SCH_NETNAME_VALIDATOR& val );
virtual wxObject* Clone() const override { return new SCH_NETNAME_VALIDATOR( *this ); }
@ -91,6 +97,8 @@ protected:
// returns the error message if the contents of 'val' are invalid
virtual wxString IsValid( const wxString& aVal ) const;
private:
bool m_allowSpaces;
};
#endif // _SCH_VALIDATORS_H_

View File

@ -568,9 +568,20 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
{
item->ClearFlags( IS_MOVED );
m_frame->AddItemToScreenAndUndoList( (SCH_ITEM*) item );
item = nullptr;
item = m_frame->GetNextNewText();
if( item )
{
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
item->SetFlags( IS_NEW | IS_MOVED );
m_view->ClearPreview();
m_view->AddToPreview( item->Clone() );
m_selectionTool->AddItemToSel( item );
}
else
{
m_view->ClearPreview();
}
}
}
else if( evt->IsClick( BUT_RIGHT ) )