2020-02-24 23:17:30 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef KICAD_DRC_TREE_MODEL_H
|
|
|
|
#define KICAD_DRC_TREE_MODEL_H
|
|
|
|
|
|
|
|
#include <drc/drc.h>
|
2020-02-28 00:05:40 +00:00
|
|
|
#include <widgets/ui_common.h>
|
2020-02-24 23:17:30 +00:00
|
|
|
|
|
|
|
|
2020-02-27 22:00:14 +00:00
|
|
|
#define WX_DATAVIEW_WINDOW_PADDING 6
|
|
|
|
|
|
|
|
|
2020-02-24 23:17:30 +00:00
|
|
|
/**
|
|
|
|
* Provide an abstract interface of a DRC_ITEM* list manager. The details
|
|
|
|
* of the actual list architecture are hidden from the caller. Any class
|
|
|
|
* that implements this interface can then be used by a DRC_TREE_MODEL class without
|
|
|
|
* it knowing the actual architecture of the list.
|
|
|
|
*/
|
|
|
|
class DRC_ITEMS_PROVIDER
|
|
|
|
{
|
|
|
|
public:
|
2020-02-28 00:05:40 +00:00
|
|
|
virtual void SetSeverities( int aSeverities ) = 0;
|
|
|
|
|
|
|
|
virtual int GetCount( int aSeverity = -1 ) = 0;
|
2020-02-24 23:17:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetItem
|
|
|
|
* retrieves a DRC_ITEM by pointer. The actual item remains owned by the
|
|
|
|
* list container.
|
|
|
|
* @param aIndex The 0 based index into the list of the desired item.
|
|
|
|
* @return const DRC_ITEM* - the desired item or NULL if aIndex is out of range.
|
|
|
|
*/
|
2020-02-28 00:05:40 +00:00
|
|
|
virtual DRC_ITEM* GetItem( int aIndex ) = 0;
|
2020-02-24 23:17:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function DeleteItems
|
|
|
|
* removes and deletes desired item from the list.
|
2020-02-28 00:05:40 +00:00
|
|
|
* @param aIndex The 0 based index into the list of the desired item which is to be deleted.
|
|
|
|
* @param aDeep If true, the source item should be deleted as well as the filtered item.
|
2020-02-24 23:17:30 +00:00
|
|
|
*/
|
2020-02-28 00:05:40 +00:00
|
|
|
virtual void DeleteItem( int aIndex, bool aDeep ) = 0;
|
2020-02-24 23:17:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function DeleteAllItems
|
|
|
|
* removes and deletes all the items in the list.
|
|
|
|
*/
|
|
|
|
virtual void DeleteAllItems() = 0;
|
|
|
|
|
|
|
|
virtual ~DRC_ITEMS_PROVIDER() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BOARD_DRC_ITEMS_PROVIDER
|
|
|
|
* is an implementation of the interface named DRC_ITEM_LIST which uses a BOARD instance
|
|
|
|
* to fulfill the interface. No ownership is taken of the BOARD.
|
|
|
|
*/
|
|
|
|
class BOARD_DRC_ITEMS_PROVIDER : public DRC_ITEMS_PROVIDER
|
|
|
|
{
|
2020-02-28 00:05:40 +00:00
|
|
|
private:
|
|
|
|
BOARD* m_board;
|
|
|
|
|
|
|
|
int m_severities;
|
|
|
|
std::vector<MARKER_PCB*> m_filteredMarkers;
|
2020-02-24 23:17:30 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
BOARD_DRC_ITEMS_PROVIDER( BOARD* aBoard ) :
|
2020-02-28 00:05:40 +00:00
|
|
|
m_board( aBoard ),
|
|
|
|
m_severities( 0 )
|
2020-02-24 23:17:30 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
void SetSeverities( int aSeverities ) override
|
2020-02-24 23:17:30 +00:00
|
|
|
{
|
2020-02-28 00:05:40 +00:00
|
|
|
m_severities = aSeverities;
|
|
|
|
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
|
|
|
|
|
|
|
m_filteredMarkers.clear();
|
|
|
|
|
|
|
|
for( MARKER_PCB* marker : m_board->Markers() )
|
|
|
|
{
|
|
|
|
int markerSeverity;
|
|
|
|
|
|
|
|
if( marker->IsExcluded() )
|
2020-03-04 09:48:18 +00:00
|
|
|
markerSeverity = RPT_SEVERITY_EXCLUSION;
|
2020-02-28 00:05:40 +00:00
|
|
|
else
|
|
|
|
markerSeverity = bds.GetSeverity( marker->GetReporter().GetErrorCode() );
|
|
|
|
|
|
|
|
if( markerSeverity & m_severities )
|
|
|
|
m_filteredMarkers.push_back( marker );
|
|
|
|
}
|
2020-02-24 23:17:30 +00:00
|
|
|
}
|
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
int GetCount( int aSeverity = -1 ) override
|
2020-02-24 23:17:30 +00:00
|
|
|
{
|
2020-02-28 00:05:40 +00:00
|
|
|
if( aSeverity < 0 )
|
|
|
|
return m_filteredMarkers.size();
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
|
|
|
|
|
|
|
for( MARKER_PCB* marker : m_board->Markers() )
|
|
|
|
{
|
|
|
|
int markerSeverity;
|
|
|
|
|
|
|
|
if( marker->IsExcluded() )
|
2020-03-04 09:48:18 +00:00
|
|
|
markerSeverity = RPT_SEVERITY_EXCLUSION;
|
2020-02-28 00:05:40 +00:00
|
|
|
else
|
|
|
|
markerSeverity = bds.GetSeverity( marker->GetReporter().GetErrorCode() );
|
|
|
|
|
|
|
|
if( markerSeverity == aSeverity )
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
DRC_ITEM* GetItem( int aIndex ) override
|
|
|
|
{
|
|
|
|
MARKER_PCB* marker = m_filteredMarkers[ aIndex ];
|
2020-02-24 23:17:30 +00:00
|
|
|
|
|
|
|
return marker ? &marker->GetReporter() : nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
void DeleteItem( int aIndex, bool aDeep ) override
|
2020-02-24 23:17:30 +00:00
|
|
|
{
|
2020-02-28 00:05:40 +00:00
|
|
|
MARKER_PCB* marker = m_filteredMarkers[ aIndex ];
|
|
|
|
m_filteredMarkers.erase( m_filteredMarkers.begin() + aIndex );
|
2020-02-24 23:17:30 +00:00
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
if( aDeep )
|
2020-02-24 23:17:30 +00:00
|
|
|
m_board->Delete( marker );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeleteAllItems() override
|
|
|
|
{
|
|
|
|
m_board->DeleteMARKERs();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* VECTOR_DRC_ITEMS_PROVIDER
|
|
|
|
* is an implementation of the interface named DRC_ITEMS_PROVIDER which uses a vector
|
|
|
|
* of pointers to DRC_ITEMs to fulfill the interface. No ownership is taken of the
|
|
|
|
* vector.
|
|
|
|
*/
|
|
|
|
class VECTOR_DRC_ITEMS_PROVIDER : public DRC_ITEMS_PROVIDER
|
|
|
|
{
|
2020-02-28 00:05:40 +00:00
|
|
|
PCB_BASE_FRAME* m_frame;
|
|
|
|
std::vector<DRC_ITEM*>* m_sourceVector; // owns its DRC_ITEMs
|
|
|
|
|
|
|
|
int m_severities;
|
|
|
|
std::vector<DRC_ITEM*> m_filteredVector; // does not own its DRC_ITEMs
|
2020-02-24 23:17:30 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
VECTOR_DRC_ITEMS_PROVIDER( PCB_BASE_FRAME* aFrame, std::vector<DRC_ITEM*>* aList ) :
|
|
|
|
m_frame( aFrame ),
|
|
|
|
m_sourceVector( aList ),
|
|
|
|
m_severities( 0 )
|
2020-02-24 23:17:30 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
void SetSeverities( int aSeverities ) override
|
2020-02-24 23:17:30 +00:00
|
|
|
{
|
2020-02-28 00:05:40 +00:00
|
|
|
m_severities = aSeverities;
|
|
|
|
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_frame->GetBoard()->GetDesignSettings();
|
|
|
|
|
|
|
|
m_filteredVector.clear();
|
|
|
|
|
|
|
|
if( m_sourceVector )
|
|
|
|
{
|
|
|
|
for( DRC_ITEM* item : *m_sourceVector )
|
|
|
|
{
|
|
|
|
if( bds.GetSeverity( item->GetErrorCode() ) & aSeverities )
|
|
|
|
m_filteredVector.push_back( item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetCount( int aSeverity = -1 ) override
|
|
|
|
{
|
|
|
|
if( aSeverity < 0 )
|
|
|
|
return m_filteredVector.size();
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_frame->GetBoard()->GetDesignSettings();
|
|
|
|
|
|
|
|
if( m_sourceVector )
|
|
|
|
{
|
|
|
|
for( DRC_ITEM* item : *m_sourceVector )
|
|
|
|
{
|
|
|
|
if( bds.GetSeverity( item->GetErrorCode() ) == aSeverity )
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
2020-02-24 23:17:30 +00:00
|
|
|
}
|
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
DRC_ITEM* GetItem( int aIndex ) override
|
2020-02-24 23:17:30 +00:00
|
|
|
{
|
2020-02-28 00:05:40 +00:00
|
|
|
return (m_filteredVector)[aIndex];
|
2020-02-24 23:17:30 +00:00
|
|
|
}
|
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
void DeleteItem( int aIndex, bool aDeep ) override
|
2020-02-24 23:17:30 +00:00
|
|
|
{
|
2020-02-28 00:05:40 +00:00
|
|
|
DRC_ITEM* item = m_filteredVector[aIndex];
|
|
|
|
m_filteredVector.erase( m_filteredVector.begin() + aIndex );
|
|
|
|
|
|
|
|
if( aDeep )
|
|
|
|
{
|
2020-03-04 09:48:18 +00:00
|
|
|
for( size_t i = 0; i < m_sourceVector->size(); ++i )
|
2020-02-28 00:05:40 +00:00
|
|
|
{
|
|
|
|
if( m_sourceVector->at( i ) == item )
|
|
|
|
{
|
|
|
|
delete item;
|
|
|
|
m_sourceVector->erase( m_sourceVector->begin() + i );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-24 23:17:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DeleteAllItems() override
|
|
|
|
{
|
2020-02-28 00:05:40 +00:00
|
|
|
if( m_sourceVector )
|
2020-02-24 23:17:30 +00:00
|
|
|
{
|
2020-02-28 00:05:40 +00:00
|
|
|
for( DRC_ITEM* item : *m_sourceVector )
|
2020-02-24 23:17:30 +00:00
|
|
|
delete item;
|
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
m_sourceVector->clear();
|
2020-02-24 23:17:30 +00:00
|
|
|
}
|
2020-02-28 00:05:40 +00:00
|
|
|
|
|
|
|
m_filteredVector.clear(); // no ownership of DRC_ITEM pointers
|
2020-02-24 23:17:30 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
/**
|
|
|
|
* RATSNEST_DRC_ITEMS_PROVIDER
|
|
|
|
*/
|
|
|
|
class RATSNEST_DRC_ITEMS_PROVIDER : public VECTOR_DRC_ITEMS_PROVIDER
|
|
|
|
{
|
|
|
|
// TODO: for now this is just a vector, but we need to map it to some board-level
|
|
|
|
// data-structure so that deleting/excluding things can do a deep delete/exclusion
|
|
|
|
// which will be reflected in the ratsnest....
|
|
|
|
public:
|
|
|
|
RATSNEST_DRC_ITEMS_PROVIDER( PCB_BASE_FRAME* aFrame, std::vector<DRC_ITEM*>* aList ) :
|
|
|
|
VECTOR_DRC_ITEMS_PROVIDER( aFrame, aList )
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-02-24 23:17:30 +00:00
|
|
|
class DRC_TREE_NODE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum NODE_TYPE { MARKER, MAIN_ITEM, AUX_ITEM };
|
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
DRC_TREE_NODE( DRC_TREE_NODE* aParent, DRC_ITEM* aDrcItem, NODE_TYPE aType ) :
|
2020-02-24 23:17:30 +00:00
|
|
|
m_Type( aType ),
|
|
|
|
m_Parent( aParent ),
|
|
|
|
m_DrcItem( aDrcItem )
|
|
|
|
{}
|
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
NODE_TYPE m_Type;
|
|
|
|
DRC_TREE_NODE* m_Parent;
|
2020-02-24 23:17:30 +00:00
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
DRC_ITEM* m_DrcItem;
|
2020-02-27 22:00:14 +00:00
|
|
|
|
|
|
|
std::vector<std::unique_ptr<DRC_TREE_NODE>> m_Children;
|
2020-02-24 23:17:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-02-27 22:00:14 +00:00
|
|
|
class DRC_TREE_MODEL : public wxDataViewModel, wxEvtHandler
|
2020-02-24 23:17:30 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static wxDataViewItem ToItem( DRC_TREE_NODE const* aNode )
|
|
|
|
{
|
|
|
|
return wxDataViewItem( const_cast<void*>( static_cast<void const*>( aNode ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
static DRC_TREE_NODE* ToNode( wxDataViewItem aItem )
|
|
|
|
{
|
|
|
|
return static_cast<DRC_TREE_NODE*>( aItem.GetID() );
|
|
|
|
}
|
|
|
|
|
2020-02-27 22:00:14 +00:00
|
|
|
static BOARD_ITEM* ToBoardItem( BOARD* aBoard, wxDataViewItem aItem );
|
2020-02-24 23:17:30 +00:00
|
|
|
|
|
|
|
public:
|
2020-02-28 00:05:40 +00:00
|
|
|
DRC_TREE_MODEL( PCB_BASE_FRAME* aParentFrame, wxDataViewCtrl* aView );
|
2020-02-24 23:17:30 +00:00
|
|
|
|
2020-02-27 22:00:14 +00:00
|
|
|
~DRC_TREE_MODEL();
|
2020-02-26 17:34:25 +00:00
|
|
|
|
2020-02-27 22:00:14 +00:00
|
|
|
void SetProvider( DRC_ITEMS_PROVIDER* aProvider );
|
2020-02-28 00:05:40 +00:00
|
|
|
void SetSeverities( int aSeverities );
|
2020-02-24 23:17:30 +00:00
|
|
|
|
|
|
|
int GetDRCItemCount() const { return m_tree.size(); }
|
|
|
|
|
2020-02-27 22:00:14 +00:00
|
|
|
void ExpandAll();
|
2020-02-24 23:17:30 +00:00
|
|
|
|
2020-02-27 22:00:14 +00:00
|
|
|
bool IsContainer( wxDataViewItem const& aItem ) const override;
|
2020-02-24 23:17:30 +00:00
|
|
|
|
2020-02-27 22:00:14 +00:00
|
|
|
wxDataViewItem GetParent( wxDataViewItem const& aItem ) const override;
|
2020-02-24 23:17:30 +00:00
|
|
|
|
|
|
|
unsigned int GetChildren( wxDataViewItem const& aItem,
|
2020-02-27 22:00:14 +00:00
|
|
|
wxDataViewItemArray& aChildren ) const override;
|
2020-02-24 23:17:30 +00:00
|
|
|
|
|
|
|
// Simple, single-text-column model
|
|
|
|
unsigned int GetColumnCount() const override { return 1; }
|
|
|
|
wxString GetColumnType( unsigned int aCol ) const override { return "string"; }
|
|
|
|
bool HasContainerColumns( wxDataViewItem const& aItem ) const override { return true; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by the wxDataView to fetch an item's value.
|
|
|
|
*/
|
|
|
|
void GetValue( wxVariant& aVariant,
|
|
|
|
wxDataViewItem const& aItem,
|
2020-02-27 22:00:14 +00:00
|
|
|
unsigned int aCol ) const override;
|
2020-02-24 23:17:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by the wxDataView to edit an item's content.
|
|
|
|
*/
|
|
|
|
bool SetValue( wxVariant const& aVariant,
|
|
|
|
wxDataViewItem const& aItem,
|
|
|
|
unsigned int aCol ) override
|
|
|
|
{
|
|
|
|
// Editing not supported
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by the wxDataView to fetch an item's formatting. Return true iff the
|
|
|
|
* item has non-default attributes.
|
|
|
|
*/
|
|
|
|
bool GetAttr( wxDataViewItem const& aItem,
|
|
|
|
unsigned int aCol,
|
2020-02-27 22:00:14 +00:00
|
|
|
wxDataViewItemAttr& aAttr ) const override;
|
2020-02-24 23:17:30 +00:00
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
void ValueChanged( DRC_TREE_NODE* aNode );
|
|
|
|
|
|
|
|
void DeleteCurrentItem( bool aDeep );
|
2020-02-27 22:00:14 +00:00
|
|
|
void DeleteAllItems();
|
2020-02-25 15:21:50 +00:00
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
private:
|
|
|
|
void rebuildModel( DRC_ITEMS_PROVIDER* aProvider, int aSeverities );
|
2020-02-27 22:00:14 +00:00
|
|
|
void onSizeView( wxSizeEvent& aEvent );
|
2020-02-24 23:17:30 +00:00
|
|
|
|
|
|
|
private:
|
2020-02-28 00:05:40 +00:00
|
|
|
PCB_BASE_FRAME* m_parentFrame;
|
2020-02-27 22:00:14 +00:00
|
|
|
wxDataViewCtrl* m_view;
|
2020-02-28 00:05:40 +00:00
|
|
|
int m_severities;
|
2020-02-27 22:00:14 +00:00
|
|
|
DRC_ITEMS_PROVIDER* m_drcItemsProvider; // I own this, but not its contents
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<DRC_TREE_NODE>> m_tree; // I own this
|
2020-02-24 23:17:30 +00:00
|
|
|
};
|
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
|
2020-02-24 23:17:30 +00:00
|
|
|
#endif //KICAD_DRC_TREE_MODEL_H
|