Update message panel from PCB point editor and SCH drawing tools.

Fixes https://gitlab.com/kicad/code/kicad/issues/11186
This commit is contained in:
Jeff Young 2022-03-20 15:57:18 +00:00
parent 09d8ac7d7c
commit 4f62960334
17 changed files with 140 additions and 91 deletions

View File

@ -628,7 +628,7 @@ void EDA_SHAPE::ShapeGetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PA
break;
}
aList.emplace_back( _( "Line width" ), MessageTextFromValue( units, GetWidth() ) );
m_stroke.GetMsgPanelInfo( units, aList );
}

View File

@ -487,6 +487,21 @@ void EDA_TEXT::AddRenderCacheGlyph( const SHAPE_POLY_SET& aPoly )
}
wxString EDA_TEXT::ShortenedText() const
{
wxString tmp = GetText();
tmp.Replace( wxT( "\n" ), wxT( " " ) );
tmp.Replace( wxT( "\r" ), wxT( " " ) );
tmp.Replace( wxT( "\t" ), wxT( " " ) );
if( tmp.Length() > 54 )
tmp = tmp.Left( 52 ) + wxT( "..." );
return tmp;
}
wxString EDA_TEXT::ShortenedShownText() const
{
wxString tmp = GetShownText();

View File

@ -28,6 +28,7 @@
#include <geometry/geometry_utils.h>
#include <stroke_params.h>
#include <trigo.h>
#include <widgets/msgpanel.h>
using namespace STROKEPARAMS_T;
@ -173,7 +174,7 @@ void STROKE_PARAMS::Stroke( const SHAPE* aShape, PLOT_DASH_TYPE aLineStyle, int
}
static wxString getLineStyleToken( PLOT_DASH_TYPE aStyle )
wxString STROKE_PARAMS::GetLineStyleToken( PLOT_DASH_TYPE aStyle )
{
wxString token;
@ -191,6 +192,32 @@ static wxString getLineStyleToken( PLOT_DASH_TYPE aStyle )
}
void STROKE_PARAMS::GetMsgPanelInfo( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList,
bool aIncludeStyle, bool aIncludeWidth )
{
if( aIncludeStyle )
{
wxString lineStyle = _( "Default" );
for( const std::pair<const PLOT_DASH_TYPE, lineTypeStruct>& typeEntry : lineTypeNames )
{
if( typeEntry.first == GetPlotStyle() )
{
lineStyle = typeEntry.second.name;
break;
}
}
aList.emplace_back( _( "Line Style" ), lineStyle );
}
if( aIncludeWidth )
{
aList.emplace_back( _( "Line Width" ), MessageTextFromValue( aUnits, GetWidth() ) );
}
}
void STROKE_PARAMS::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel ) const
{
wxASSERT( aFormatter != nullptr );
@ -199,13 +226,13 @@ void STROKE_PARAMS::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel ) const
{
aFormatter->Print( aNestLevel, "(stroke (width %s) (type %s))",
FormatInternalUnits(GetWidth() ).c_str(),
TO_UTF8( getLineStyleToken( GetPlotStyle() ) ) );
TO_UTF8( GetLineStyleToken( GetPlotStyle() ) ) );
}
else
{
aFormatter->Print( aNestLevel, "(stroke (width %s) (type %s) (color %d %d %d %s))",
FormatInternalUnits(GetWidth() ).c_str(),
TO_UTF8( getLineStyleToken( GetPlotStyle() ) ),
TO_UTF8( GetLineStyleToken( GetPlotStyle() ) ),
KiROUND( GetColor().r * 255.0 ),
KiROUND( GetColor().g * 255.0 ),
KiROUND( GetColor().b * 255.0 ),
@ -293,3 +320,5 @@ double STROKE_PARAMS_PARSER::parseDouble( const char* aText )
return val;
}

View File

@ -363,15 +363,24 @@ void LIB_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOf
void LIB_TEXTBOX::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
{
EDA_UNITS units = aFrame->GetUserUnits();
// Don't use GetShownText() here; we want to show the user the variable references
aList.emplace_back( _( "Text Box" ), UnescapeString( GetText() ) );
aList.emplace_back( _( "Text Box" ), UnescapeString( ShortenedText() ) );
wxString textStyle[] = { _( "Normal" ), _( "Italic" ), _( "Bold" ), _( "Bold Italic" ) };
int style = IsBold() && IsItalic() ? 3 : IsBold() ? 2 : IsItalic() ? 1 : 0;
aList.emplace_back( _( "Style" ), textStyle[style] );
aList.emplace_back( _( "Text Size" ), MessageTextFromValue( aFrame->GetUserUnits(),
GetTextWidth() ) );
aList.emplace_back( _( "Text Size" ), MessageTextFromValue( units, GetTextWidth() ) );
wxString msg = MessageTextFromValue( units, std::abs( GetEnd().x - GetStart().x ) );
aList.emplace_back( _( "Box Width" ), msg );
msg = MessageTextFromValue( units, std::abs( GetEnd().y - GetStart().y ) );
aList.emplace_back( _( "Box Height" ), msg );
m_stroke.GetMsgPanelInfo( units, aList );
}

View File

@ -93,45 +93,6 @@ EDA_ITEM* SCH_LINE::Clone() const
}
/*
* Conversion between PLOT_DASH_TYPE values and style names displayed
*/
const std::map<PLOT_DASH_TYPE, const char*> lineStyleNames{
{ PLOT_DASH_TYPE::SOLID, "solid" },
{ PLOT_DASH_TYPE::DASH, "dashed" },
{ PLOT_DASH_TYPE::DASHDOT, "dash_dot" },
{ PLOT_DASH_TYPE::DOT, "dotted" },
};
const char* SCH_LINE::GetLineStyleName( PLOT_DASH_TYPE aStyle )
{
auto resultIt = lineStyleNames.find( aStyle );
//legacy behavior is to default to dash if there is no name
return resultIt == lineStyleNames.end() ? lineStyleNames.find( PLOT_DASH_TYPE::DASH )->second :
resultIt->second;
}
PLOT_DASH_TYPE SCH_LINE::GetLineStyleByName( const wxString& aStyleName )
{
PLOT_DASH_TYPE id = PLOT_DASH_TYPE::DEFAULT; // Default style id
//find the name by value
auto resultIt = std::find_if( lineStyleNames.begin(), lineStyleNames.end(),
[aStyleName]( const auto& it )
{
return it.second == aStyleName;
} );
if( resultIt != lineStyleNames.end() )
id = resultIt->first;
return id;
}
void SCH_LINE::Move( const VECTOR2I& aOffset )
{
if( aOffset != VECTOR2I( 0, 0 ) )
@ -926,12 +887,12 @@ void SCH_LINE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_IT
aList.emplace_back( _( "Line Type" ), msg );
if( GetLineStyle() != GetEffectiveLineStyle() )
msg = _( "from netclass" );
else
msg = GetLineStyleName( GetLineStyle() );
PLOT_DASH_TYPE lineStyle = GetLineStyle();
aList.emplace_back( _( "Line Style" ), msg );
if( GetEffectiveLineStyle() != lineStyle )
aList.emplace_back( _( "Line Style" ), _( "from netclass" ) );
else
m_stroke.GetMsgPanelInfo( aFrame->GetUserUnits(), aList, true, false );
SCH_CONNECTION* conn = nullptr;

View File

@ -149,14 +149,6 @@ public:
/// this might be set on the line or inherited from the line's netclass
PLOT_DASH_TYPE GetEffectiveLineStyle() const;
/// @return the style name from the style id
/// (mainly to write it in .sch file)
static const char* GetLineStyleName( PLOT_DASH_TYPE aStyle );
/// @return the style id from the style name
/// (mainly to read style from .sch file)
static PLOT_DASH_TYPE GetLineStyleByName( const wxString& aStyleName );
void SetLineColor( const COLOR4D& aColor );
void SetLineColor( const double r, const double g, const double b, const double a );

View File

@ -804,8 +804,15 @@ SCH_LINE* SCH_LEGACY_PLUGIN::loadWire( LINE_READER& aReader )
else if( buf == T_STYLE )
{
parseUnquotedString( buf, aReader, line, &line );
PLOT_DASH_TYPE style = SCH_LINE::GetLineStyleByName( buf );
wire->SetLineStyle( style );
if( buf == wxT( "solid" ) )
wire->SetLineStyle( PLOT_DASH_TYPE::SOLID );
else if( buf == wxT( "dashed" ) )
wire->SetLineStyle( PLOT_DASH_TYPE::DASH );
else if( buf == wxT( "dash_dot" ) )
wire->SetLineStyle( PLOT_DASH_TYPE::DASHDOT );
else if( buf == wxT( "dotted" ) )
wire->SetLineStyle( PLOT_DASH_TYPE::DOT );
}
else // should be the color parameter.
{
@ -1854,7 +1861,7 @@ void SCH_LEGACY_PLUGIN::saveLine( SCH_LINE* aLine )
if( aLine->GetLineStyle() != aLine->GetDefaultStyle() )
m_out->Print( 0, " %s %s", T_STYLE,
SCH_LINE::GetLineStyleName( aLine->GetLineStyle() ) );
TO_UTF8( STROKE_PARAMS::GetLineStyleToken( aLine->GetLineStyle() ) ) );
if( aLine->GetLineColor() != COLOR4D::UNSPECIFIED )
m_out->Print( 0, " %s",

View File

@ -443,7 +443,7 @@ void SCH_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_IT
wxString msg;
// Don't use GetShownText() here; we want to show the user the variable references
aList.emplace_back( _( "Graphic Text" ), UnescapeString( GetText() ) );
aList.emplace_back( _( "Graphic Text" ), UnescapeString( ShortenedText() ) );
wxString textStyle[] = { _( "Normal" ), _( "Italic" ), _( "Bold" ), _( "Bold Italic" ) };
int style = IsBold() && IsItalic() ? 3 : IsBold() ? 2 : IsItalic() ? 1 : 0;

View File

@ -366,13 +366,22 @@ void SCH_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground ) const
void SCH_TEXTBOX::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
{
EDA_UNITS units = aFrame->GetUserUnits();
// Don't use GetShownText() here; we want to show the user the variable references
aList.emplace_back( _( "Text Box" ), UnescapeString( GetText() ) );
aList.emplace_back( _( "Text Box" ), UnescapeString( ShortenedText() ) );
wxString textStyle[] = { _( "Normal" ), _( "Italic" ), _( "Bold" ), _( "Bold Italic" ) };
int style = IsBold() && IsItalic() ? 3 : IsBold() ? 2 : IsItalic() ? 1 : 0;
aList.emplace_back( _( "Style" ), textStyle[style] );
aList.emplace_back( _( "Text Size" ), MessageTextFromValue( aFrame->GetUserUnits(),
GetTextWidth() ) );
aList.emplace_back( _( "Text Size" ), MessageTextFromValue( units, GetTextWidth() ) );
wxString msg = MessageTextFromValue( units, std::abs( GetEnd().x - GetStart().x ) );
aList.emplace_back( _( "Box Width" ), msg );
msg = MessageTextFromValue( units, std::abs( GetEnd().y - GetStart().y ) );
aList.emplace_back( _( "Box Height" ), msg );
m_stroke.GetMsgPanelInfo( units, aList );
}

View File

@ -353,6 +353,7 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent )
{
symbol->SetPosition( cursorPos );
m_view->Update( symbol );
m_frame->SetMsgPanel( symbol );
}
else if( symbol && evt->IsAction( &ACTIONS::doDelete ) )
{
@ -575,6 +576,7 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
m_view->ClearPreview();
m_view->AddToPreview( image->Clone() );
m_view->RecacheAllItems(); // Bitmaps are cached in Opengl
m_frame->SetMsgPanel( image );
}
else if( image && evt->IsAction( &ACTIONS::doDelete ) )
{
@ -780,6 +782,7 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
previewItem->SetPosition( (wxPoint)cursorPos );
m_view->ClearPreview();
m_view->AddToPreview( previewItem->Clone() );
m_frame->SetMsgPanel( previewItem );
}
else if( evt->Category() == TC_COMMAND )
{
@ -1083,6 +1086,7 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
{
m_view->AddToPreview( aChild->Clone() );
} );
m_frame->SetMsgPanel( item );
};
auto cleanup =
@ -1462,6 +1466,7 @@ int SCH_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
item->CalcEdit( (wxPoint) cursorPos );
m_view->ClearPreview();
m_view->AddToPreview( item->Clone() );
m_frame->SetMsgPanel( item );
}
else if( evt->IsDblClick( BUT_LEFT ) && !item )
{
@ -1650,6 +1655,7 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent )
sizeSheet( sheet, cursorPos );
m_view->ClearPreview();
m_view->AddToPreview( sheet->Clone() );
m_frame->SetMsgPanel( sheet );
}
else if( evt->IsClick( BUT_RIGHT ) )
{

View File

@ -87,6 +87,11 @@ public:
*/
virtual const wxString& GetText() const { return m_text; }
/**
* Returns a shortened version (max 54 characters) of the shown text
*/
wxString ShortenedText() const;
/**
* Return the string actually shown after processing of the base text.
*
@ -96,7 +101,7 @@ public:
virtual wxString GetShownText( int aDepth = 0 ) const { return m_shown_text; }
/**
* Returns a shortened version (max 15 characters) of the shown text
* Returns a shortened version (max 36 characters) of the shown text
*/
wxString ShortenedShownText() const;

View File

@ -32,6 +32,7 @@
#include <stroke_params_lexer.h>
class STROKE_PARAMS_LEXER;
class MSG_PANEL_ITEM;
namespace KIGFX
{
@ -111,8 +112,13 @@ public:
void Format( OUTPUTFORMATTER* out, int nestLevel ) const;
void GetMsgPanelInfo( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList,
bool aIncludeStyle = true, bool aIncludeWidth = true );
// Helper functions
static wxString GetLineStyleToken( PLOT_DASH_TYPE aStyle );
static void Stroke( const SHAPE* aShape, PLOT_DASH_TYPE aLineStyle, int aWidth,
const KIGFX::RENDER_SETTINGS* aRenderSettings,
std::function<void( const VECTOR2I& a, const VECTOR2I& b )> aStroker );

View File

@ -213,8 +213,16 @@ void FP_TEXTBOX::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_
aList.emplace_back( _( "Angle" ), wxString::Format( "%g", GetTextAngle().AsDegrees() ) );
aList.emplace_back( _( "Thickness" ), MessageTextFromValue( units, GetTextThickness() ) );
aList.emplace_back( _( "Width" ), MessageTextFromValue( units, GetTextWidth() ) );
aList.emplace_back( _( "Height" ), MessageTextFromValue( units, GetTextHeight() ) );
aList.emplace_back( _( "Text Width" ), MessageTextFromValue( units, GetTextWidth() ) );
aList.emplace_back( _( "Text Height" ), MessageTextFromValue( units, GetTextHeight() ) );
wxString msg = MessageTextFromValue( units, std::abs( GetEnd().x - GetStart().x ) );
aList.emplace_back( _( "Box Width" ), msg );
msg = MessageTextFromValue( units, std::abs( GetEnd().y - GetStart().y ) );
aList.emplace_back( _( "Box Height" ), msg );
m_stroke.GetMsgPanelInfo( units, aList );
}

View File

@ -213,9 +213,17 @@ void PCB_TEXTBOX::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL
aList.emplace_back( _( "Mirror" ), IsMirrored() ? _( "Yes" ) : _( "No" ) );
aList.emplace_back( _( "Angle" ), wxString::Format( "%g", GetTextAngle().AsDegrees() ) );
aList.emplace_back( _( "Thickness" ), MessageTextFromValue( units, GetTextThickness() ) );
aList.emplace_back( _( "Width" ), MessageTextFromValue( units, GetTextWidth() ) );
aList.emplace_back( _( "Height" ), MessageTextFromValue( units, GetTextHeight() ) );
aList.emplace_back( _( "Text Thickness" ), MessageTextFromValue( units, GetTextThickness() ) );
aList.emplace_back( _( "Text Width" ), MessageTextFromValue( units, GetTextWidth() ) );
aList.emplace_back( _( "Text Height" ), MessageTextFromValue( units, GetTextHeight() ) );
wxString msg = MessageTextFromValue( units, std::abs( GetEnd().x - GetStart().x ) );
aList.emplace_back( _( "Box Width" ), msg );
msg = MessageTextFromValue( units, std::abs( GetEnd().y - GetStart().y ) );
aList.emplace_back( _( "Box Height" ), msg );
m_stroke.GetMsgPanelInfo( units, aList );
}

View File

@ -743,6 +743,8 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent )
m_controls->SetAutoPan( false );
m_controls->CaptureCursor( false );
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
if( selection().Empty() )
m_frame->SetMsgPanel( board() );
return 0;
@ -1195,6 +1197,8 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
m_view->Remove( &preview );
if( selection().Empty() )
m_frame->SetMsgPanel( board() );
return 0;
@ -1788,6 +1792,8 @@ bool DRAWING_TOOL::drawSegment( const std::string& aTool, PCB_SHAPE** aGraphic,
m_view->Remove( &twoPointAsst );
m_view->Remove( &preview );
if( selection().Empty() )
m_frame->SetMsgPanel( board() );
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
@ -2064,6 +2070,8 @@ bool DRAWING_TOOL::drawArc( const std::string& aTool, PCB_SHAPE** aGraphic, bool
preview.Remove( graphic );
m_view->Remove( &arcAsst );
m_view->Remove( &preview );
if( selection().Empty() )
m_frame->SetMsgPanel( board() );
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );

View File

@ -650,8 +650,6 @@ int PCB_POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
if( m_editPoints )
{
getView()->Remove( m_editPoints.get() );
finishItem();
m_editPoints.reset();
}
@ -1598,17 +1596,8 @@ void PCB_POINT_EDITOR::updateItem() const
}
getView()->Update( item );
}
void PCB_POINT_EDITOR::finishItem()
{
auto item = m_editPoints->GetParent();
if( !item )
return;
// TODO Refill edited zones when KiCad supports auto re-fill
frame()->SetMsgPanel( item );
}

View File

@ -74,9 +74,6 @@ private:
///< Update item's points with edit points.
void updateItem() const;
///< Apply the last changes to the edited item.
void finishItem();
/**
* Validate a polygon and displays a popup warning if invalid.
*