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-10-18 16:45:34 +00:00
|
|
|
#include <wx/settings.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>
|
2020-04-24 13:36:10 +00:00
|
|
|
#include <eda_draw_frame.h>
|
2020-03-16 11:05:01 +00:00
|
|
|
#include <rc_item.h>
|
2021-06-06 14:41:02 +00:00
|
|
|
#include <eda_item.h>
|
2020-03-16 11:05:01 +00:00
|
|
|
#include <base_units.h>
|
2020-02-27 22:00:14 +00:00
|
|
|
|
|
|
|
#define WX_DATAVIEW_WINDOW_PADDING 6
|
|
|
|
|
|
|
|
|
2020-04-24 18:56:44 +00:00
|
|
|
wxString RC_ITEM::GetErrorMessage() const
|
|
|
|
{
|
|
|
|
if( m_errorMessage.IsEmpty() )
|
2020-06-08 02:19:46 +00:00
|
|
|
return GetErrorText();
|
2020-04-24 18:56:44 +00:00
|
|
|
else
|
|
|
|
return m_errorMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-06 14:41:02 +00:00
|
|
|
void RC_ITEM::AddItem( EDA_ITEM* aItem )
|
|
|
|
{
|
|
|
|
m_ids.push_back( aItem->m_Uuid );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RC_ITEM::SetItems( const EDA_ITEM* aItem, const EDA_ITEM* bItem,
|
|
|
|
const EDA_ITEM* cItem, const EDA_ITEM* dItem )
|
|
|
|
{
|
|
|
|
m_ids.clear();
|
|
|
|
|
|
|
|
m_ids.push_back( aItem->m_Uuid );
|
|
|
|
|
|
|
|
if( bItem )
|
|
|
|
m_ids.push_back( bItem->m_Uuid );
|
|
|
|
|
|
|
|
if( cItem )
|
|
|
|
m_ids.push_back( cItem->m_Uuid );
|
|
|
|
|
|
|
|
if( dItem )
|
|
|
|
m_ids.push_back( dItem->m_Uuid );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-21 10:36:07 +00:00
|
|
|
wxString RC_ITEM::ShowReport( EDA_UNITS aUnits, SEVERITY aSeverity,
|
|
|
|
const std::map<KIID, EDA_ITEM*>& aItemMap ) const
|
2020-03-16 11:05:01 +00:00
|
|
|
{
|
2020-09-21 10:36:07 +00:00
|
|
|
wxString severity;
|
|
|
|
|
|
|
|
switch( aSeverity )
|
|
|
|
{
|
2020-09-21 11:18:46 +00:00
|
|
|
case RPT_SEVERITY_ERROR: severity = wxT( "Severity: error" ); break;
|
|
|
|
case RPT_SEVERITY_WARNING: severity = wxT( "Severity: warning" ); break;
|
|
|
|
case RPT_SEVERITY_ACTION: severity = wxT( "Severity: action" ); break;
|
|
|
|
case RPT_SEVERITY_INFO: severity = wxT( "Severity: info" ); break;
|
2020-09-21 10:36:07 +00:00
|
|
|
default: ;
|
|
|
|
};
|
|
|
|
|
|
|
|
if( m_parent && m_parent->IsExcluded() )
|
|
|
|
severity += wxT( " (excluded)" );
|
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
EDA_ITEM* mainItem = nullptr;
|
|
|
|
EDA_ITEM* auxItem = nullptr;
|
|
|
|
|
2020-09-25 18:27:56 +00:00
|
|
|
auto ii = aItemMap.find( GetMainItemID() );
|
2020-04-24 13:36:10 +00:00
|
|
|
|
2020-09-17 23:35:19 +00:00
|
|
|
if( ii != aItemMap.end() )
|
|
|
|
mainItem = ii->second;
|
|
|
|
|
2020-09-25 18:27:56 +00:00
|
|
|
ii = aItemMap.find( GetAuxItemID() );
|
2020-09-17 23:35:19 +00:00
|
|
|
|
|
|
|
if( ii != aItemMap.end() )
|
|
|
|
auxItem = ii->second;
|
2020-04-24 13:36:10 +00:00
|
|
|
|
2020-09-21 10:36:07 +00:00
|
|
|
// Note: some customers machine-process these. So:
|
|
|
|
// 1) don't translate
|
|
|
|
// 2) try not to re-order or change syntax
|
|
|
|
// 3) report numeric error code (which should be more stable) in addition to message
|
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
if( mainItem && auxItem )
|
2020-03-16 11:05:01 +00:00
|
|
|
{
|
2020-10-13 22:03:07 +00:00
|
|
|
return wxString::Format( wxT( "[%s]: %s %s\n %s: %s\n %s: %s\n" ),
|
|
|
|
GetSettingsKey(),
|
2020-04-24 18:56:44 +00:00
|
|
|
GetErrorMessage(),
|
2020-09-21 10:36:07 +00:00
|
|
|
severity,
|
2020-04-24 13:36:10 +00:00
|
|
|
ShowCoord( aUnits, mainItem->GetPosition() ),
|
|
|
|
mainItem->GetSelectMenuText( aUnits ),
|
|
|
|
ShowCoord( aUnits, auxItem->GetPosition() ),
|
|
|
|
auxItem->GetSelectMenuText( aUnits ) );
|
2020-03-16 11:05:01 +00:00
|
|
|
}
|
2020-04-24 13:36:10 +00:00
|
|
|
else if( mainItem )
|
2020-03-16 11:05:01 +00:00
|
|
|
{
|
2020-10-13 22:03:07 +00:00
|
|
|
return wxString::Format( wxT( "[%s]: %s %s\n %s: %s\n" ),
|
|
|
|
GetSettingsKey(),
|
2020-04-24 18:56:44 +00:00
|
|
|
GetErrorMessage(),
|
2020-09-21 10:36:07 +00:00
|
|
|
severity,
|
2020-04-24 13:36:10 +00:00
|
|
|
ShowCoord( aUnits, mainItem->GetPosition() ),
|
|
|
|
mainItem->GetSelectMenuText( aUnits ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-13 22:03:07 +00:00
|
|
|
return wxString::Format( wxT( "[%s]: %s %s\n" ),
|
|
|
|
GetSettingsKey(),
|
2020-09-21 10:36:07 +00:00
|
|
|
GetErrorMessage(),
|
|
|
|
severity );
|
2020-03-16 11:05:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-08-30 19:23:25 +00:00
|
|
|
if( node && node->m_RcItem )
|
2020-02-27 22:00:14 +00:00
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
const std::shared_ptr<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-06-17 12:46:50 +00:00
|
|
|
case RC_TREE_NODE::AUX_ITEM2: return rc_item->GetAuxItem2ID();
|
|
|
|
case RC_TREE_NODE::AUX_ITEM3: return rc_item->GetAuxItem3ID();
|
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-04-24 13:36:10 +00:00
|
|
|
RC_TREE_MODEL::RC_TREE_MODEL( EDA_DRAW_FRAME* aParentFrame, wxDataViewCtrl* aView ) :
|
2020-03-16 11:05:01 +00:00
|
|
|
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 );
|
|
|
|
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<RC_ITEM> selectedRcItem = nullptr;
|
2020-08-01 17:19:31 +00:00
|
|
|
|
2020-03-04 18:04:14 +00:00
|
|
|
if( m_view )
|
2020-08-01 17:19:31 +00:00
|
|
|
{
|
|
|
|
RC_TREE_NODE* selectedNode = ToNode( m_view->GetSelection() );
|
|
|
|
selectedRcItem = selectedNode ? selectedNode->m_RcItem : nullptr;
|
|
|
|
|
|
|
|
// Even with the updateLock, wxWidgets sometimes ties its knickers in a knot trying
|
|
|
|
// to run a wxdataview_selection_changed_callback() on a row that has been deleted.
|
2020-03-04 18:04:14 +00:00
|
|
|
m_view->UnselectAll();
|
2020-08-01 17:19:31 +00:00
|
|
|
}
|
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-08-30 13:45:12 +00:00
|
|
|
for( RC_TREE_NODE* topLevelNode : m_tree )
|
|
|
|
delete topLevelNode;
|
|
|
|
|
2020-02-27 22:00:14 +00:00
|
|
|
m_tree.clear();
|
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
// wxDataView::ExpandAll() pukes with large lists
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
if( m_rcItemsProvider )
|
|
|
|
count = std::min( 1000, m_rcItemsProvider->GetCount() );
|
|
|
|
|
|
|
|
for( int i = 0; i < count; ++i )
|
2020-02-27 22:00:14 +00:00
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<RC_ITEM> rcItem = m_rcItemsProvider->GetItem( i );
|
2020-02-27 22:00:14 +00:00
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
m_tree.push_back( new RC_TREE_NODE( nullptr, rcItem, RC_TREE_NODE::MARKER ) );
|
2020-03-16 11:05:01 +00:00
|
|
|
RC_TREE_NODE* n = m_tree.back();
|
2020-02-27 22:00:14 +00:00
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
if( rcItem->GetMainItemID() != niluuid )
|
|
|
|
n->m_Children.push_back( new RC_TREE_NODE( n, rcItem, RC_TREE_NODE::MAIN_ITEM ) );
|
2020-02-27 22:00:14 +00:00
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
if( rcItem->GetAuxItemID() != niluuid )
|
|
|
|
n->m_Children.push_back( new RC_TREE_NODE( n, rcItem, RC_TREE_NODE::AUX_ITEM ) );
|
|
|
|
|
|
|
|
if( rcItem->GetAuxItem2ID() != niluuid )
|
|
|
|
n->m_Children.push_back( new RC_TREE_NODE( n, rcItem, RC_TREE_NODE::AUX_ITEM2 ) );
|
|
|
|
|
|
|
|
if( rcItem->GetAuxItem3ID() != niluuid )
|
|
|
|
n->m_Children.push_back( new RC_TREE_NODE( n, rcItem, RC_TREE_NODE::AUX_ITEM3 ) );
|
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-08-01 17:19:31 +00:00
|
|
|
|
|
|
|
// Most annoyingly wxWidgets won't tell us the scroll position (and no, all the usual
|
|
|
|
// routines don't work), so we can only restore the scroll position based on a selection.
|
|
|
|
if( selectedRcItem )
|
|
|
|
{
|
|
|
|
for( RC_TREE_NODE* candidate : m_tree )
|
|
|
|
{
|
|
|
|
if( candidate->m_RcItem == selectedRcItem )
|
|
|
|
{
|
|
|
|
m_view->Select( ToItem( candidate ) );
|
|
|
|
m_view->EnsureVisible( ToItem( candidate ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-27 22:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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-04-24 13:36:10 +00:00
|
|
|
wxDataViewItem const& aItem,
|
|
|
|
unsigned int aCol ) const
|
2020-02-27 22:00:14 +00:00
|
|
|
{
|
2020-08-22 14:38:32 +00:00
|
|
|
const RC_TREE_NODE* node = ToNode( aItem );
|
|
|
|
const std::shared_ptr<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-06-17 12:46:50 +00:00
|
|
|
wxString prefix;
|
|
|
|
|
|
|
|
if( rcItem->GetParent() && rcItem->GetParent()->IsExcluded() )
|
|
|
|
prefix = _( "Excluded " );
|
|
|
|
|
|
|
|
switch( m_editFrame->GetSeverity( rcItem->GetErrorCode() ) )
|
|
|
|
{
|
|
|
|
case RPT_SEVERITY_ERROR: prefix += _( "Error: " ); break;
|
|
|
|
case RPT_SEVERITY_WARNING: prefix += _( "Warning: " ); break;
|
2020-12-15 15:20:58 +00:00
|
|
|
|
2020-12-16 23:54:53 +00:00
|
|
|
case RPT_SEVERITY_EXCLUSION:
|
2020-12-15 15:20:58 +00:00
|
|
|
case RPT_SEVERITY_UNDEFINED:
|
|
|
|
case RPT_SEVERITY_INFO:
|
|
|
|
case RPT_SEVERITY_ACTION:
|
|
|
|
case RPT_SEVERITY_IGNORE:
|
|
|
|
break;
|
2020-06-17 12:46:50 +00:00
|
|
|
}
|
2020-02-28 00:05:40 +00:00
|
|
|
|
2020-04-24 18:56:44 +00:00
|
|
|
aVariant = prefix + rcItem->GetErrorMessage();
|
2020-02-28 00:05:40 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
case RC_TREE_NODE::MAIN_ITEM:
|
2020-04-24 13:36:10 +00:00
|
|
|
{
|
|
|
|
EDA_ITEM* item = m_editFrame->GetItem( rcItem->GetMainItemID() );
|
2020-06-17 12:46:50 +00:00
|
|
|
aVariant = item->GetSelectMenuText( m_editFrame->GetUserUnits() );
|
2020-04-24 13:36:10 +00:00
|
|
|
}
|
2020-02-28 00:05:40 +00:00
|
|
|
break;
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
case RC_TREE_NODE::AUX_ITEM:
|
2020-04-24 13:36:10 +00:00
|
|
|
{
|
|
|
|
EDA_ITEM* item = m_editFrame->GetItem( rcItem->GetAuxItemID() );
|
2020-06-17 12:46:50 +00:00
|
|
|
aVariant = item->GetSelectMenuText( m_editFrame->GetUserUnits() );
|
|
|
|
}
|
|
|
|
break;
|
2020-04-24 13:36:10 +00:00
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
case RC_TREE_NODE::AUX_ITEM2:
|
|
|
|
{
|
|
|
|
EDA_ITEM* item = m_editFrame->GetItem( rcItem->GetAuxItem2ID() );
|
|
|
|
aVariant = item->GetSelectMenuText( m_editFrame->GetUserUnits() );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RC_TREE_NODE::AUX_ITEM3:
|
|
|
|
{
|
|
|
|
EDA_ITEM* item = m_editFrame->GetItem( rcItem->GetAuxItem3ID() );
|
|
|
|
aVariant = item->GetSelectMenuText( m_editFrame->GetUserUnits() );
|
2020-04-24 13:36:10 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
void RC_TREE_MODEL::ValueChanged( const 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 );
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
for( const RC_TREE_NODE* 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-08-04 10:50:39 +00:00
|
|
|
DeleteItems( true, true, aDeep );
|
2020-08-02 21:45:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-04 00:41:56 +00:00
|
|
|
void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, bool aDeep )
|
2020-08-02 21:45:06 +00:00
|
|
|
{
|
2021-03-06 09:27:41 +00:00
|
|
|
RC_TREE_NODE* current_node = ToNode( m_view->GetCurrentItem() );
|
2020-08-11 13:33:16 +00:00
|
|
|
const std::shared_ptr<RC_ITEM> current_item = current_node ? current_node->m_RcItem : nullptr;
|
2020-02-27 22:00:14 +00:00
|
|
|
|
2020-11-23 17:51:30 +00:00
|
|
|
/// Keep a vector of elements to free after wxWidgets is definitely done accessing them
|
|
|
|
std::vector<RC_TREE_NODE*> to_delete;
|
|
|
|
|
2020-08-04 00:41:56 +00:00
|
|
|
if( aCurrentOnly && !current_item )
|
2020-02-27 22:00:14 +00:00
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-21 20:42:27 +00:00
|
|
|
if( !m_rcItemsProvider )
|
|
|
|
return;
|
|
|
|
|
2020-09-23 17:42:35 +00:00
|
|
|
int lastGood = -1;
|
2020-12-04 13:38:38 +00:00
|
|
|
bool itemDeleted = false;
|
2020-09-23 17:42:35 +00:00
|
|
|
|
|
|
|
if( m_view )
|
2020-10-03 17:48:07 +00:00
|
|
|
{
|
2020-09-23 17:42:35 +00:00
|
|
|
m_view->UnselectAll();
|
2021-06-22 21:24:33 +00:00
|
|
|
wxSafeYield();
|
2020-10-03 17:48:07 +00:00
|
|
|
m_view->Freeze();
|
|
|
|
}
|
2020-09-23 17:42:35 +00:00
|
|
|
|
2020-08-02 21:45:06 +00:00
|
|
|
for( int i = m_rcItemsProvider->GetCount() - 1; i >= 0; --i )
|
2020-02-27 22:00:14 +00:00
|
|
|
{
|
2020-09-23 17:42:35 +00:00
|
|
|
std::shared_ptr<RC_ITEM> rcItem = m_rcItemsProvider->GetItem( i );
|
|
|
|
MARKER_BASE* marker = rcItem->GetParent();
|
|
|
|
bool excluded = marker ? marker->IsExcluded() : false;
|
2020-08-02 21:45:06 +00:00
|
|
|
|
2020-12-04 13:38:38 +00:00
|
|
|
if( aCurrentOnly && itemDeleted && lastGood >= 0 )
|
|
|
|
break;
|
|
|
|
|
2020-08-04 00:41:56 +00:00
|
|
|
if( aCurrentOnly && rcItem != current_item )
|
2020-09-23 17:42:35 +00:00
|
|
|
{
|
|
|
|
lastGood = i;
|
2020-08-04 00:41:56 +00:00
|
|
|
continue;
|
2020-09-23 17:42:35 +00:00
|
|
|
}
|
2020-08-04 00:41:56 +00:00
|
|
|
|
|
|
|
if( excluded && !aIncludeExclusions )
|
|
|
|
continue;
|
|
|
|
|
2020-10-28 10:44:18 +00:00
|
|
|
if( i < (int) m_tree.size() ) // Careful; tree is truncated for large datasets
|
2020-02-27 22:00:14 +00:00
|
|
|
{
|
2020-10-28 10:44:18 +00:00
|
|
|
wxDataViewItem markerItem = ToItem( m_tree[i] );
|
|
|
|
wxDataViewItemArray childItems;
|
|
|
|
wxDataViewItem parentItem = ToItem( m_tree[i]->m_Parent );
|
|
|
|
|
|
|
|
for( RC_TREE_NODE* child : m_tree[i]->m_Children )
|
|
|
|
{
|
|
|
|
childItems.push_back( ToItem( child ) );
|
2020-11-23 17:51:30 +00:00
|
|
|
to_delete.push_back( child );
|
2020-10-28 10:44:18 +00:00
|
|
|
}
|
2020-03-06 16:23:05 +00:00
|
|
|
|
2020-10-28 10:44:18 +00:00
|
|
|
m_tree[i]->m_Children.clear();
|
|
|
|
ItemsDeleted( markerItem, childItems );
|
2020-03-06 16:23:05 +00:00
|
|
|
|
2020-11-23 17:51:30 +00:00
|
|
|
to_delete.push_back( m_tree[i] );
|
2020-10-28 10:44:18 +00:00
|
|
|
m_tree.erase( m_tree.begin() + i );
|
|
|
|
ItemDeleted( parentItem, markerItem );
|
|
|
|
}
|
2020-03-06 16:23:05 +00:00
|
|
|
|
2020-08-04 00:41:56 +00:00
|
|
|
// Only deep delete the current item here; others will be done through the
|
|
|
|
// DeleteAllItems() call below, which is more efficient.
|
|
|
|
m_rcItemsProvider->DeleteItem( i, aDeep && aCurrentOnly );
|
2020-12-04 13:38:38 +00:00
|
|
|
|
|
|
|
if( lastGood > i )
|
|
|
|
lastGood--;
|
|
|
|
|
|
|
|
itemDeleted = true;
|
2020-08-04 00:41:56 +00:00
|
|
|
}
|
2020-02-27 22:00:14 +00:00
|
|
|
|
2020-09-23 17:42:35 +00:00
|
|
|
if( m_view && aCurrentOnly && lastGood >= 0 )
|
|
|
|
m_view->Select( ToItem( m_tree[ lastGood ] ) );
|
|
|
|
|
2020-11-23 17:51:30 +00:00
|
|
|
for( RC_TREE_NODE* item : to_delete )
|
|
|
|
delete( item );
|
|
|
|
|
2020-08-04 00:41:56 +00:00
|
|
|
if( !aCurrentOnly )
|
|
|
|
m_rcItemsProvider->DeleteAllItems( aIncludeExclusions, aDeep );
|
2020-10-03 17:48:07 +00:00
|
|
|
|
|
|
|
if( m_view )
|
|
|
|
m_view->Thaw();
|
2020-02-27 22:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-01 22:35:11 +00:00
|
|
|
void RC_TREE_MODEL::PrevMarker()
|
|
|
|
{
|
|
|
|
RC_TREE_NODE* currentNode = ToNode( m_view->GetCurrentItem() );
|
|
|
|
RC_TREE_NODE* prevMarker = nullptr;
|
|
|
|
|
|
|
|
while( currentNode && currentNode->m_Type != RC_TREE_NODE::MARKER )
|
|
|
|
currentNode = currentNode->m_Parent;
|
|
|
|
|
|
|
|
for( RC_TREE_NODE* candidate : m_tree )
|
|
|
|
{
|
|
|
|
if( candidate == currentNode )
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
prevMarker = candidate;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( prevMarker )
|
|
|
|
m_view->Select( ToItem( prevMarker ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RC_TREE_MODEL::NextMarker()
|
|
|
|
{
|
|
|
|
RC_TREE_NODE* currentNode = ToNode( m_view->GetCurrentItem() );
|
|
|
|
|
|
|
|
while( currentNode && currentNode->m_Type != RC_TREE_NODE::MARKER )
|
|
|
|
currentNode = currentNode->m_Parent;
|
|
|
|
|
|
|
|
RC_TREE_NODE* nextMarker = nullptr;
|
|
|
|
bool trigger = currentNode == nullptr;
|
|
|
|
|
|
|
|
for( RC_TREE_NODE* candidate : m_tree )
|
|
|
|
{
|
|
|
|
if( candidate == currentNode )
|
|
|
|
{
|
|
|
|
trigger = true;
|
|
|
|
}
|
|
|
|
else if( trigger )
|
|
|
|
{
|
|
|
|
nextMarker = candidate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( nextMarker )
|
|
|
|
m_view->Select( ToItem( nextMarker ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|