2020-02-27 22:00:14 +00:00
|
|
|
/*
|
|
|
|
* 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/wupdlock.h>
|
2020-03-16 11:05:01 +00:00
|
|
|
#include <wx/dataview.h>
|
2020-02-28 00:05:40 +00:00
|
|
|
#include <widgets/ui_common.h>
|
2020-03-16 11:05:01 +00:00
|
|
|
#include <marker_base.h>
|
|
|
|
#include <eda_base_frame.h>
|
|
|
|
#include <rc_item.h>
|
|
|
|
#include <base_units.h>
|
2020-02-27 22:00:14 +00:00
|
|
|
|
|
|
|
#define WX_DATAVIEW_WINDOW_PADDING 6
|
|
|
|
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
wxString RC_ITEM::ShowCoord( EDA_UNITS aUnits, const wxPoint& aPos )
|
2020-02-27 22:00:14 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
return wxString::Format( "@(%s, %s)",
|
|
|
|
MessageTextFromValue( aUnits, aPos.x ),
|
|
|
|
MessageTextFromValue( aUnits, aPos.y ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString RC_ITEM::ShowReport( EDA_UNITS aUnits ) const
|
|
|
|
{
|
|
|
|
if( m_hasSecondItem )
|
|
|
|
{
|
|
|
|
return wxString::Format( wxT( "ErrType(%d): %s\n %s: %s\n %s: %s\n" ),
|
|
|
|
m_ErrorCode,
|
|
|
|
GetErrorText(),
|
|
|
|
ShowCoord( aUnits, m_MainPosition ),
|
|
|
|
m_MainText,
|
|
|
|
ShowCoord( aUnits, m_AuxPosition ),
|
|
|
|
m_AuxText );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return wxString::Format( wxT( "ErrType(%d): %s\n %s: %s\n" ),
|
|
|
|
m_ErrorCode,
|
|
|
|
GetErrorText(),
|
|
|
|
ShowCoord( aUnits, m_MainPosition ),
|
|
|
|
m_MainText );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KIID RC_TREE_MODEL::ToUUID( wxDataViewItem aItem )
|
|
|
|
{
|
|
|
|
const RC_TREE_NODE* node = RC_TREE_MODEL::ToNode( aItem );
|
2020-02-27 22:00:14 +00:00
|
|
|
|
|
|
|
if( node )
|
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
const RC_ITEM* rc_item = node->m_RcItem;
|
2020-02-27 22:00:14 +00:00
|
|
|
|
|
|
|
switch( node->m_Type )
|
|
|
|
{
|
2020-03-28 09:57:52 +00:00
|
|
|
case RC_TREE_NODE::MARKER:
|
|
|
|
// rc_item->GetParent() can be null, if the parent is not existing
|
|
|
|
// when a RC item has no corresponding ERC/DRC marker
|
|
|
|
if( rc_item->GetParent() )
|
|
|
|
return rc_item->GetParent()->GetUUID();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
case RC_TREE_NODE::MAIN_ITEM: return rc_item->GetMainItemID();
|
|
|
|
case RC_TREE_NODE::AUX_ITEM: return rc_item->GetAuxItemID();
|
2020-02-27 22:00:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
return niluuid;
|
2020-02-27 22:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
RC_TREE_MODEL::RC_TREE_MODEL( EDA_BASE_FRAME* aParentFrame, wxDataViewCtrl* aView ) :
|
|
|
|
m_editFrame( aParentFrame ),
|
|
|
|
m_view( aView ),
|
|
|
|
m_severities( 0 ),
|
|
|
|
m_rcItemsProvider( nullptr )
|
2020-02-27 22:00:14 +00:00
|
|
|
{
|
|
|
|
m_view->GetMainWindow()->Connect( wxEVT_SIZE,
|
2020-03-16 11:05:01 +00:00
|
|
|
wxSizeEventHandler( RC_TREE_MODEL::onSizeView ),
|
2020-02-27 22:00:14 +00:00
|
|
|
NULL, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
RC_TREE_MODEL::~RC_TREE_MODEL()
|
2020-02-27 22:00:14 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
delete m_rcItemsProvider;
|
2020-02-28 00:05:40 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( RC_TREE_NODE* topLevelNode : m_tree )
|
2020-03-06 16:23:05 +00:00
|
|
|
delete topLevelNode;
|
2020-02-27 22:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
void RC_TREE_MODEL::rebuildModel( RC_ITEMS_PROVIDER* aProvider, int aSeverities )
|
2020-02-27 22:00:14 +00:00
|
|
|
{
|
|
|
|
wxWindowUpdateLocker updateLock( m_view );
|
|
|
|
|
|
|
|
// Even with the updateLock, wxWidgets sometimes ties its knickers in
|
|
|
|
// a knot when trying to run a wxdataview_selection_changed_callback()
|
|
|
|
// on a row that has been deleted.
|
2020-03-04 18:04:14 +00:00
|
|
|
if( m_view )
|
|
|
|
m_view->UnselectAll();
|
2020-02-27 22:00:14 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
if( aProvider != m_rcItemsProvider )
|
2020-02-28 00:05:40 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
delete m_rcItemsProvider;
|
|
|
|
m_rcItemsProvider = aProvider;
|
2020-02-28 00:05:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( aSeverities != m_severities )
|
|
|
|
m_severities = aSeverities;
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
if( m_rcItemsProvider )
|
|
|
|
m_rcItemsProvider->SetSeverities( m_severities );
|
2020-02-28 00:05:40 +00:00
|
|
|
|
2020-02-27 22:00:14 +00:00
|
|
|
m_tree.clear();
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( int i = 0; m_rcItemsProvider && i < m_rcItemsProvider->GetCount(); ++i )
|
2020-02-27 22:00:14 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
RC_ITEM* drcItem = m_rcItemsProvider->GetItem( i );
|
2020-02-27 22:00:14 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
m_tree.push_back( new RC_TREE_NODE( nullptr, drcItem, RC_TREE_NODE::MARKER ) );
|
|
|
|
RC_TREE_NODE* n = m_tree.back();
|
2020-02-27 22:00:14 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
n->m_Children.push_back( new RC_TREE_NODE( n, drcItem, RC_TREE_NODE::MAIN_ITEM ) );
|
2020-02-27 22:00:14 +00:00
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
if( drcItem->GetAuxItemID() != niluuid )
|
2020-03-16 11:05:01 +00:00
|
|
|
n->m_Children.push_back( new RC_TREE_NODE( n, drcItem, RC_TREE_NODE::AUX_ITEM ) );
|
2020-02-27 22:00:14 +00:00
|
|
|
}
|
|
|
|
|
2020-03-11 09:46:08 +00:00
|
|
|
// Must be called after a significant change of items to force the
|
|
|
|
// wxDataViewModel to reread all of them, repopulating itself entirely.
|
|
|
|
Cleared();
|
|
|
|
|
2020-02-27 22:00:14 +00:00
|
|
|
#ifdef __WXGTK__
|
|
|
|
// The fastest method to update wxDataViewCtrl is to rebuild from
|
|
|
|
// scratch by calling Cleared(). Linux requires to reassociate model to
|
|
|
|
// display data, but Windows will create multiple associations.
|
|
|
|
// On MacOS, this crashes kicad. See https://gitlab.com/kicad/code/kicad/issues/3666
|
|
|
|
// and https://gitlab.com/kicad/code/kicad/issues/3653
|
|
|
|
m_view->AssociateModel( this );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
m_view->ClearColumns();
|
|
|
|
int width = m_view->GetMainWindow()->GetRect().GetWidth() - WX_DATAVIEW_WINDOW_PADDING;
|
|
|
|
m_view->AppendTextColumn( wxEmptyString, 0, wxDATAVIEW_CELL_INERT, width );
|
|
|
|
|
|
|
|
ExpandAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
void RC_TREE_MODEL::SetProvider( RC_ITEMS_PROVIDER* aProvider )
|
2020-02-28 00:05:40 +00:00
|
|
|
{
|
|
|
|
rebuildModel( aProvider, m_severities );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
void RC_TREE_MODEL::SetSeverities( int aSeverities )
|
2020-02-28 00:05:40 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
rebuildModel( m_rcItemsProvider, aSeverities );
|
2020-02-28 00:05:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
void RC_TREE_MODEL::ExpandAll()
|
2020-02-27 22:00:14 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
for( RC_TREE_NODE* topLevelNode : m_tree )
|
2020-03-06 16:23:05 +00:00
|
|
|
m_view->Expand( ToItem( topLevelNode ) );
|
2020-02-27 22:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
bool RC_TREE_MODEL::IsContainer( wxDataViewItem const& aItem ) const
|
2020-02-27 22:00:14 +00:00
|
|
|
{
|
|
|
|
if( ToNode( aItem ) == nullptr ) // must be tree root...
|
|
|
|
return true;
|
|
|
|
else
|
2020-03-16 11:05:01 +00:00
|
|
|
return ToNode( aItem )->m_Type == RC_TREE_NODE::MARKER;
|
2020-02-27 22:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
wxDataViewItem RC_TREE_MODEL::GetParent( wxDataViewItem const& aItem ) const
|
2020-02-27 22:00:14 +00:00
|
|
|
{
|
|
|
|
return ToItem( ToNode( aItem)->m_Parent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
unsigned int RC_TREE_MODEL::GetChildren( wxDataViewItem const& aItem,
|
2020-02-27 22:00:14 +00:00
|
|
|
wxDataViewItemArray& aChildren ) const
|
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
const RC_TREE_NODE* node = ToNode( aItem );
|
|
|
|
const std::vector<RC_TREE_NODE*>& children = node ? node->m_Children : m_tree;
|
2020-02-27 22:00:14 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( const RC_TREE_NODE* child: children )
|
2020-03-06 16:23:05 +00:00
|
|
|
aChildren.push_back( ToItem( child ) );
|
2020-02-27 22:00:14 +00:00
|
|
|
|
|
|
|
return children.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by the wxDataView to fetch an item's value.
|
|
|
|
*/
|
2020-03-16 11:05:01 +00:00
|
|
|
void RC_TREE_MODEL::GetValue( wxVariant& aVariant,
|
2020-02-27 22:00:14 +00:00
|
|
|
wxDataViewItem const& aItem,
|
|
|
|
unsigned int aCol ) const
|
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
const RC_TREE_NODE* node = ToNode( aItem );
|
|
|
|
const RC_ITEM* rcItem = node->m_RcItem;
|
2020-02-27 22:00:14 +00:00
|
|
|
|
|
|
|
switch( node->m_Type )
|
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
case RC_TREE_NODE::MARKER:
|
2020-02-28 00:05:40 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
bool excluded = rcItem->GetParent() && rcItem->GetParent()->IsExcluded();
|
|
|
|
bool error = m_editFrame->GetSeverity( rcItem->GetErrorCode() ) == RPT_SEVERITY_ERROR;
|
2020-02-28 00:05:40 +00:00
|
|
|
wxString prefix = wxString::Format( wxT( "%s%s" ),
|
2020-03-04 09:48:18 +00:00
|
|
|
excluded ? _( "Excluded " ) : wxString( "" ),
|
2020-02-28 00:05:40 +00:00
|
|
|
error ? _( "Error: " ) : _( "Warning: " ) );
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
aVariant = prefix + rcItem->GetErrorText();
|
2020-02-28 00:05:40 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
case RC_TREE_NODE::MAIN_ITEM:
|
|
|
|
aVariant = rcItem->GetMainText();
|
2020-02-28 00:05:40 +00:00
|
|
|
break;
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
case RC_TREE_NODE::AUX_ITEM:
|
|
|
|
aVariant = rcItem->GetAuxText();
|
2020-02-28 00:05:40 +00:00
|
|
|
break;
|
2020-02-27 22:00:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by the wxDataView to fetch an item's formatting. Return true iff the
|
|
|
|
* item has non-default attributes.
|
|
|
|
*/
|
2020-03-16 11:05:01 +00:00
|
|
|
bool RC_TREE_MODEL::GetAttr( wxDataViewItem const& aItem,
|
|
|
|
unsigned int aCol,
|
|
|
|
wxDataViewItemAttr& aAttr ) const
|
2020-02-27 22:00:14 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
const RC_TREE_NODE* node = ToNode( aItem );
|
2020-02-27 22:00:14 +00:00
|
|
|
wxASSERT( node );
|
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
bool ret = false;
|
2020-03-16 11:05:01 +00:00
|
|
|
bool heading = node->m_Type == RC_TREE_NODE::MARKER;
|
2020-02-28 00:05:40 +00:00
|
|
|
|
|
|
|
if( heading )
|
|
|
|
{
|
|
|
|
aAttr.SetBold( true );
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
if( node->m_RcItem->GetParent() && node->m_RcItem->GetParent()->IsExcluded() )
|
2020-02-28 00:05:40 +00:00
|
|
|
{
|
|
|
|
wxColour textColour = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXTEXT );
|
|
|
|
|
|
|
|
if( KIGFX::COLOR4D( textColour ).GetBrightness() > 0.5 )
|
|
|
|
aAttr.SetColour( textColour.ChangeLightness( heading ? 30 : 35 ) );
|
|
|
|
else
|
|
|
|
aAttr.SetColour( textColour.ChangeLightness( heading ? 170 : 165 ) );
|
|
|
|
|
|
|
|
aAttr.SetItalic( true ); // Strikethrough would be better, if wxWidgets supported it
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
void RC_TREE_MODEL::ValueChanged( RC_TREE_NODE* aNode )
|
2020-02-28 00:05:40 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
if( aNode->m_Type == RC_TREE_NODE::MAIN_ITEM || aNode->m_Type == RC_TREE_NODE::AUX_ITEM )
|
2020-02-27 22:00:14 +00:00
|
|
|
{
|
2020-02-28 00:05:40 +00:00
|
|
|
ValueChanged( aNode->m_Parent );
|
2020-02-27 22:00:14 +00:00
|
|
|
}
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
if( aNode->m_Type == RC_TREE_NODE::MARKER )
|
2020-02-28 00:05:40 +00:00
|
|
|
{
|
|
|
|
wxDataViewModel::ValueChanged( ToItem( aNode ), 0 );
|
|
|
|
|
|
|
|
for( auto & child : aNode->m_Children )
|
2020-03-06 16:23:05 +00:00
|
|
|
wxDataViewModel::ValueChanged( ToItem( child ), 0 );
|
2020-02-28 00:05:40 +00:00
|
|
|
}
|
2020-02-27 22:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
void RC_TREE_MODEL::DeleteCurrentItem( bool aDeep )
|
2020-02-27 22:00:14 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
RC_TREE_NODE* tree_node = ToNode( m_view->GetCurrentItem() );
|
|
|
|
const RC_ITEM* drc_item = tree_node ? tree_node->m_RcItem : nullptr;
|
2020-02-27 22:00:14 +00:00
|
|
|
|
|
|
|
if( !drc_item )
|
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( int i = 0; i < m_rcItemsProvider->GetCount(); ++i )
|
2020-02-27 22:00:14 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
if( m_rcItemsProvider->GetItem( i ) == drc_item )
|
2020-02-27 22:00:14 +00:00
|
|
|
{
|
2020-03-06 16:23:05 +00:00
|
|
|
wxDataViewItem markerItem = ToItem( m_tree[i] );
|
|
|
|
wxDataViewItemArray childItems;
|
|
|
|
wxDataViewItem parentItem = ToItem( m_tree[i]->m_Parent );
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( RC_TREE_NODE* child : m_tree[i]->m_Children )
|
2020-03-06 16:23:05 +00:00
|
|
|
{
|
|
|
|
childItems.push_back( ToItem( child ) );
|
|
|
|
delete child;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_tree[i]->m_Children.clear();
|
|
|
|
ItemsDeleted( markerItem, childItems );
|
|
|
|
|
|
|
|
delete m_tree[i];
|
2020-02-27 22:00:14 +00:00
|
|
|
m_tree.erase( m_tree.begin() + i );
|
2020-03-06 16:23:05 +00:00
|
|
|
ItemDeleted( parentItem, markerItem );
|
2020-02-27 22:00:14 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
m_rcItemsProvider->DeleteItem( i, aDeep );
|
2020-02-27 22:00:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
void RC_TREE_MODEL::DeleteAllItems()
|
2020-02-27 22:00:14 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
if( m_rcItemsProvider )
|
2020-02-27 22:00:14 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
m_rcItemsProvider->DeleteAllItems();
|
2020-02-27 22:00:14 +00:00
|
|
|
|
|
|
|
m_tree.clear();
|
|
|
|
Cleared();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
void RC_TREE_MODEL::onSizeView( wxSizeEvent& aEvent )
|
2020-02-27 22:00:14 +00:00
|
|
|
{
|
|
|
|
int width = m_view->GetMainWindow()->GetRect().GetWidth() - WX_DATAVIEW_WINDOW_PADDING;
|
|
|
|
|
|
|
|
if( m_view->GetColumnCount() > 0 )
|
|
|
|
m_view->GetColumn( 0 )->SetWidth( width );
|
2020-03-07 17:04:09 +00:00
|
|
|
|
|
|
|
// Pass size event to other widgets
|
|
|
|
aEvent.Skip();
|
2020-02-27 22:00:14 +00:00
|
|
|
}
|