Bail on 45º text in pin conflicts map.

Fixes https://gitlab.com/kicad/code/kicad/issues/5515
This commit is contained in:
Jeff Young 2020-10-18 20:27:04 +01:00
parent 2e50723781
commit dd53b9c399
5 changed files with 11 additions and 226 deletions

View File

@ -234,7 +234,6 @@ set( COMMON_WIDGET_SRCS
widgets/widget_hotkey_list.cpp
widgets/wx_busy_indicator.cpp
widgets/wx_grid.cpp
widgets/wx_angle_text.cpp
widgets/wx_aui_dock_art.cpp
)

View File

@ -1,113 +0,0 @@
/*
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 2020 Kicad Developers, see AUTHORS.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 <wx/wx.h>
#include <widgets/wx_angle_text.h>
#include <eda_rect.h>
WX_ANGLE_TEXT::WX_ANGLE_TEXT( wxWindow* aParent, wxWindowID aId, const wxString& aLabel,
const wxPoint& aPos, double aAngle ) :
wxPanel( aParent, aId, aPos, wxDefaultSize ),
m_label( aLabel ),
m_angle( aAngle )
{
wxFont font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
font.SetPointSize( font.GetPointSize() + 2 ); // rotated text looks visually smaller
SetFont( font );
// Measure the size of the text
wxClientDC dc( this );
dc.SetFont( font );
wxSize size = dc.GetTextExtent( m_label );
wxPoint pos = GetPosition();
EDA_RECT rect( wxPoint( 0, 0 ), size );
EDA_RECT bbox = rect.GetBoundingBoxRotated( rect.GetPosition(), m_angle );
pos.y += bbox.GetTop() + ( rect.GetBottom() - bbox.GetBottom() );
size.y = bbox.GetHeight();
size.x = bbox.GetWidth();
Move( pos );
SetSize( size );
Bind( wxEVT_ERASE_BACKGROUND, &WX_ANGLE_TEXT::OnEraseBackground, this );
Bind( wxEVT_PAINT, &WX_ANGLE_TEXT::OnPaint, this );
}
void WX_ANGLE_TEXT::OnEraseBackground( wxEraseEvent& WXUNUSED( aEvent ) )
{
// NOP so that we don't erase other labels which intersect
}
void WX_ANGLE_TEXT::OnPaint( wxPaintEvent& WXUNUSED( aEvent ) )
{
wxPaintDC dc( this );
dc.SetFont( GetFont() );
dc.SetTextForeground( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT ) );
dc.SetTextBackground( wxTransparentColor );
dc.SetBackgroundMode( wxTRANSPARENT );
dc.SetBackground( *wxTRANSPARENT_BRUSH );
wxSize size = dc.GetTextExtent( m_label );
EDA_RECT rect( wxPoint( 0, 0 ), size );
EDA_RECT bbox = rect.GetBoundingBoxRotated( rect.GetPosition(), m_angle );
wxPoint pos( 0, -bbox.GetTop() );
dc.DrawRotatedText( m_label, pos, m_angle / 10 );
}
EDA_RECT WX_ANGLE_TEXT::GetBoundingBox( wxWindow* aWindow, const wxString& aLabel, double aAngle )
{
wxSize size = WX_ANGLE_TEXT::GetTextSize( aWindow, aLabel );
EDA_RECT rect( wxPoint( 0, 0 ), size );
return rect.GetBoundingBoxRotated( rect.GetPosition(), aAngle );
}
wxSize WX_ANGLE_TEXT::GetTextSize( wxWindow* aWindow, const wxString& aLabel )
{
// Create the font used for the text
wxFont font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
#ifdef __WXMAC__
// Rotated text looks visually smaller on OSX...
font.SetPointSize( font.GetPointSize() + 2 );
#elif __WXGTK3__
// TODO: needs testing...
#else
// ... but larger on MSW
font.SetPointSize( font.GetPointSize() - 2 );
#endif
// Measure the size of the text
wxClientDC dc( aWindow );
dc.SetFont( font );
return dc.GetTextExtent( aLabel );
}

View File

@ -1,64 +0,0 @@
/*
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 2020 Kicad Developers, see AUTHORS.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
*/
#ifndef _WX_ANGLE_TEXT_
#define _WX_ANGLE_TEXT_
#include <eda_rect.h>
#include <wx/panel.h>
class WX_ANGLE_TEXT : public wxPanel
{
public:
WX_ANGLE_TEXT( wxWindow* aParent, wxWindowID aId, const wxString& aLabel,
const wxPoint& aPos, double aAngle );
/**
* Get the bounding box that this angled text will take up on a certain window.
*
* @param aWindow is the wxWindow the text will go on
* @param aLabel is the text string
* @param aAngle is the angle of the text
*/
static EDA_RECT GetBoundingBox( wxWindow* aWindow, const wxString& aLabel, double aAngle );
/**
* Get the height and width of the unrotated text string that is created for this control.
* This will include any modifications done to the font.
*
* @param aWindow is the wxWindow the text will go on
* @param aLabel is the text string
*/
static wxSize GetTextSize( wxWindow* aWindow, const wxString& aLabel );
protected:
void OnEraseBackground( wxEraseEvent& WXUNUSED( aEvent ) );
void OnPaint( wxPaintEvent& WXUNUSED( aEvent ) );
wxString m_label;
double m_angle;
};
#endif /*_WX_ANGLE_TEXT_*/

View File

@ -25,7 +25,6 @@
#include <sch_edit_frame.h>
#include <kiface_i.h>
#include <bitmaps.h>
#include <reporter.h>
#include <wildcards_and_files_ext.h>
#include <schematic.h>
#include <connection_graph.h>
@ -34,7 +33,7 @@
#include <panel_setup_pinmap.h>
#include <erc.h>
#include <id.h>
#include <widgets/wx_angle_text.h>
#include <wx/statline.h>
// Control identifiers for events
@ -70,14 +69,6 @@ void PANEL_SETUP_PINMAP::ResetPanel()
}
#ifdef __WXMAC__
#define COL_LABEL_PLATFORM_FUDGE wxPoint( 5, 0 )
#elif __WXGTK3__
#define COL_LABEL_PLATFORM_FUDGE wxPoint( 0, 0 ) // TODO: needs testing...
#else
#define COL_LABEL_PLATFORM_FUDGE wxPoint( 0, 2 )
#endif
void PANEL_SETUP_PINMAP::reBuildMatrixPanel()
{
// Try to know the size of bitmap button used in drc matrix
@ -85,16 +76,8 @@ void PANEL_SETUP_PINMAP::reBuildMatrixPanel()
wxSize bmapSize = dummy->GetSize();
delete dummy;
wxPoint pos;
// Get the text size for the angled text
EDA_RECT bbox = WX_ANGLE_TEXT::GetBoundingBox( m_matrixPanel, CommentERC_V[0], 450 );
wxSize txtSize = WX_ANGLE_TEXT::GetTextSize( m_matrixPanel, CommentERC_V[0] );
bmapSize.y = std::max( bmapSize.y, txtSize.y );
// compute the Y pos interval:
pos.y = bbox.GetHeight();
wxSize charSize = GetTextSize( "X", m_matrixPanel );
wxPoint pos( 0, charSize.y * 2 );
wxStaticText* text;
if( !m_initialized )
@ -106,7 +89,7 @@ void PANEL_SETUP_PINMAP::reBuildMatrixPanel()
{
int y = pos.y + (ii * bmapSize.y);
text = new wxStaticText( m_matrixPanel, -1, CommentERC_H[ii],
wxPoint( 5, y + ( bmapSize.y / 2 ) - ( txtSize.y / 2 ) ) );
wxPoint( 5, y + ( bmapSize.y / 2 ) - ( 12 / 2 ) ) );
labels.push_back( text );
int x = text->GetRect().GetRight();
@ -139,11 +122,13 @@ void PANEL_SETUP_PINMAP::reBuildMatrixPanel()
if( ( ii == jj ) && !m_initialized )
{
wxPoint txtpos;
txtpos.x = x + ( bmapSize.x / 2 ) - ( sqrt( 2 ) * txtSize.y / 2 );
txtpos.y = y - txtSize.y;
txtpos += COL_LABEL_PLATFORM_FUDGE;
new WX_ANGLE_TEXT( m_matrixPanel, wxID_ANY, CommentERC_V[ii], txtpos, 450 );
wxPoint textPos( x + KiROUND( bmapSize.x / 2 ) - KiROUND( charSize.x / 2 ),
y - charSize.y * 2 );
new wxStaticText( m_matrixPanel, wxID_ANY, CommentERC_V[ii], textPos );
wxPoint calloutPos( x + KiROUND( bmapSize.x / 2 ) - 2,
y - charSize.y );
new wxStaticText( m_matrixPanel, wxID_ANY, "|", calloutPos );
}
int event_id = ID_MATRIX_0 + ii + ( jj * ELECTRICAL_PINTYPES_TOTAL );
@ -162,27 +147,6 @@ void PANEL_SETUP_PINMAP::reBuildMatrixPanel()
}
bool PANEL_SETUP_PINMAP::Show( bool show )
{
wxPanel::Show( show );
// For some reason the angle text doesn't get drawn if the paint events are fired while
// it's not the active tab.
if( show )
{
for( wxWindow* win : m_matrixPanel->GetChildren() )
{
WX_ANGLE_TEXT* angleText = dynamic_cast<WX_ANGLE_TEXT*>( win );
if( angleText )
angleText->Refresh();
}
}
return true;
}
void PANEL_SETUP_PINMAP::setDRCMatrixButtonState( wxBitmapButton *aButton, PIN_ERROR aState )
{
BITMAP_DEF bitmap_butt = nullptr;

View File

@ -48,7 +48,6 @@ private:
public:
PANEL_SETUP_PINMAP( wxWindow* aWindow, SCH_EDIT_FRAME* aParent );
bool Show( bool show ) override;
void ImportSettingsFrom( PIN_ERROR aPinMap[][ELECTRICAL_PINTYPES_TOTAL] );
void ResetPanel() override;