2009-07-06 18:02:26 +00:00
|
|
|
/*
|
2011-09-30 18:15:37 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2009-07-06 18:02:26 +00:00
|
|
|
*
|
2020-03-16 11:05:01 +00:00
|
|
|
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2009-07-06 18:02:26 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
#ifndef RC_ITEM_H
|
|
|
|
#define RC_ITEM_H
|
2009-07-06 18:02:26 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
#include <wx/dataview.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <macros.h>
|
2018-04-10 10:52:12 +00:00
|
|
|
#include <base_struct.h>
|
2009-09-10 15:22:26 +00:00
|
|
|
|
2018-03-20 02:25:55 +00:00
|
|
|
class MARKER_BASE;
|
2020-03-16 11:05:01 +00:00
|
|
|
class EDA_BASE_FRAME;
|
|
|
|
class RC_ITEM;
|
2018-03-20 02:25:55 +00:00
|
|
|
|
2009-09-10 15:22:26 +00:00
|
|
|
|
2009-07-06 18:02:26 +00:00
|
|
|
/**
|
2020-03-16 11:05:01 +00:00
|
|
|
* Provide an abstract interface of a RC_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 RC_TREE_MODEL class without it knowing
|
|
|
|
* the actual architecture of the list.
|
|
|
|
*/
|
|
|
|
class RC_ITEMS_PROVIDER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void SetSeverities( int aSeverities ) = 0;
|
|
|
|
|
|
|
|
virtual int GetCount( int aSeverity = -1 ) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetItem
|
2020-03-29 19:02:23 +00:00
|
|
|
* retrieves a RC_ITEM by index.
|
2020-03-16 11:05:01 +00:00
|
|
|
*/
|
|
|
|
virtual RC_ITEM* GetItem( int aIndex ) = 0;
|
|
|
|
|
|
|
|
/**
|
2020-03-29 19:02:23 +00:00
|
|
|
* Function DeleteItem
|
|
|
|
* removes (and optionally deletes) the indexed item from the list.
|
|
|
|
* @param aDeep If true, the source item should be deleted as well as its entry in the list.
|
2020-03-16 11:05:01 +00:00
|
|
|
*/
|
|
|
|
virtual void DeleteItem( int aIndex, bool aDeep ) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function DeleteAllItems
|
|
|
|
* removes and deletes all the items in the list.
|
|
|
|
*/
|
|
|
|
virtual void DeleteAllItems() = 0;
|
|
|
|
|
|
|
|
virtual ~RC_ITEMS_PROVIDER() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RC_ITEM
|
2009-07-06 18:02:26 +00:00
|
|
|
* is a holder for a DRC (in Pcbnew) or ERC (in Eeschema) error item.
|
2020-04-24 13:36:10 +00:00
|
|
|
* RC_ITEMs can have zero, one, or two related EDA_ITEMs.
|
2009-07-06 18:02:26 +00:00
|
|
|
*/
|
2020-03-16 11:05:01 +00:00
|
|
|
class RC_ITEM
|
2009-07-06 18:02:26 +00:00
|
|
|
{
|
|
|
|
protected:
|
2020-04-24 13:36:10 +00:00
|
|
|
int m_errorCode; // the error code's numeric value
|
2020-06-08 02:19:46 +00:00
|
|
|
wxString m_errorMessage; ///< A message describing the details of this specific error
|
|
|
|
wxString m_errorTitle; ///< The string describing the type of error
|
|
|
|
wxString m_settingsKey; ///< The key used to describe this type of error in settings
|
2020-03-16 11:05:01 +00:00
|
|
|
MARKER_BASE* m_parent; // The marker this item belongs to, if any
|
|
|
|
KIID m_mainItemUuid;
|
|
|
|
KIID m_auxItemUuid;
|
2020-06-17 12:46:50 +00:00
|
|
|
KIID m_auxItem2Uuid;
|
|
|
|
KIID m_auxItem3Uuid;
|
2018-03-20 02:25:55 +00:00
|
|
|
|
2009-07-06 18:02:26 +00:00
|
|
|
public:
|
|
|
|
|
2020-06-20 14:36:16 +00:00
|
|
|
RC_ITEM() :
|
|
|
|
m_errorCode( 0 ),
|
|
|
|
m_parent( nullptr ),
|
|
|
|
m_mainItemUuid( NilUuid() ),
|
|
|
|
m_auxItemUuid( NilUuid() ),
|
|
|
|
m_auxItem2Uuid( NilUuid() ),
|
|
|
|
m_auxItem3Uuid( NilUuid() )
|
2009-07-06 18:02:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
RC_ITEM( RC_ITEM* aItem )
|
2019-06-01 16:49:33 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
m_errorCode = aItem->m_errorCode;
|
2020-04-24 13:36:10 +00:00
|
|
|
m_errorMessage = aItem->m_errorMessage;
|
2020-06-08 02:19:46 +00:00
|
|
|
m_errorTitle = aItem->m_errorTitle;
|
|
|
|
m_settingsKey = aItem->m_settingsKey;
|
|
|
|
m_parent = aItem->m_parent;
|
2020-03-16 11:05:01 +00:00
|
|
|
m_mainItemUuid = aItem->m_mainItemUuid;
|
2020-06-08 02:19:46 +00:00
|
|
|
m_auxItemUuid = aItem->m_auxItemUuid;
|
2020-06-17 12:46:50 +00:00
|
|
|
m_auxItem2Uuid = aItem->m_auxItem2Uuid;
|
|
|
|
m_auxItem3Uuid = aItem->m_auxItem3Uuid;
|
2019-06-01 16:49:33 +00:00
|
|
|
}
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
virtual ~RC_ITEM() { }
|
2019-03-28 19:30:51 +00:00
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
void SetErrorMessage( const wxString& aMessage ) { m_errorMessage = aMessage; }
|
2009-07-06 18:02:26 +00:00
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
void SetItems( EDA_ITEM* aItem, EDA_ITEM* bItem = nullptr, EDA_ITEM* cItem = nullptr,
|
|
|
|
EDA_ITEM* dItem = nullptr )
|
2020-02-28 00:05:40 +00:00
|
|
|
{
|
2020-04-24 13:36:10 +00:00
|
|
|
m_mainItemUuid = aItem->m_Uuid;
|
2020-02-28 00:05:40 +00:00
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
if( bItem )
|
|
|
|
m_auxItemUuid = bItem->m_Uuid;
|
2020-06-17 12:46:50 +00:00
|
|
|
|
|
|
|
if( cItem )
|
|
|
|
m_auxItem2Uuid = cItem->m_Uuid;
|
|
|
|
|
|
|
|
if( dItem )
|
|
|
|
m_auxItem3Uuid = dItem->m_Uuid;
|
2020-02-28 00:05:40 +00:00
|
|
|
}
|
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
void SetItems( const KIID& aItem, const KIID& bItem = niluuid, const KIID& cItem = niluuid,
|
|
|
|
const KIID& dItem = niluuid )
|
2020-02-28 00:05:40 +00:00
|
|
|
{
|
2020-04-24 13:36:10 +00:00
|
|
|
m_mainItemUuid = aItem;
|
|
|
|
m_auxItemUuid = bItem;
|
2020-06-17 12:46:50 +00:00
|
|
|
m_auxItem2Uuid = cItem;
|
|
|
|
m_auxItem3Uuid = dItem;
|
2020-02-28 00:05:40 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
KIID GetMainItemID() const { return m_mainItemUuid; }
|
|
|
|
KIID GetAuxItemID() const { return m_auxItemUuid; }
|
2020-06-17 12:46:50 +00:00
|
|
|
KIID GetAuxItem2ID() const { return m_auxItem2Uuid; }
|
|
|
|
KIID GetAuxItem3ID() const { return m_auxItem3Uuid; }
|
2009-07-08 15:42:45 +00:00
|
|
|
|
2018-03-20 02:25:55 +00:00
|
|
|
void SetParent( MARKER_BASE* aMarker ) { m_parent = aMarker; }
|
|
|
|
MARKER_BASE* GetParent() const { return m_parent; }
|
2009-07-06 18:02:26 +00:00
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
|
2009-07-06 18:02:26 +00:00
|
|
|
/**
|
|
|
|
* Function ShowReport
|
2020-02-24 17:23:53 +00:00
|
|
|
* translates this object into a text string suitable for saving to disk in a report.
|
2009-07-06 18:02:26 +00:00
|
|
|
* @return wxString - the simple multi-line report text.
|
|
|
|
*/
|
2020-04-24 13:36:10 +00:00
|
|
|
virtual wxString ShowReport( EDA_UNITS aUnits,
|
|
|
|
const std::map<KIID, EDA_ITEM*>& aItemMap ) const;
|
2009-07-06 18:02:26 +00:00
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
int GetErrorCode() const { return m_errorCode; }
|
|
|
|
void SetErrorCode( int aCode ) { m_errorCode = aCode; }
|
2009-07-06 18:02:26 +00:00
|
|
|
|
2020-04-24 18:56:44 +00:00
|
|
|
/**
|
|
|
|
* Function GetErrorMessage
|
|
|
|
* returns the error message of a RC_ITEM
|
|
|
|
*/
|
|
|
|
virtual wxString GetErrorMessage() const;
|
2009-07-06 18:02:26 +00:00
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
wxString GetErrorText() const
|
|
|
|
{
|
|
|
|
return wxGetTranslation( m_errorTitle );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString GetSettingsKey() const
|
|
|
|
{
|
|
|
|
return m_settingsKey;
|
|
|
|
}
|
|
|
|
|
2009-07-06 18:02:26 +00:00
|
|
|
/**
|
|
|
|
* Function ShowCoord
|
|
|
|
* formats a coordinate or position to text.
|
|
|
|
*/
|
2019-12-20 14:11:39 +00:00
|
|
|
static wxString ShowCoord( EDA_UNITS aUnits, const wxPoint& aPos );
|
2009-07-06 18:02:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
class RC_TREE_NODE
|
|
|
|
{
|
|
|
|
public:
|
2020-06-17 12:46:50 +00:00
|
|
|
enum NODE_TYPE { MARKER, MAIN_ITEM, AUX_ITEM, AUX_ITEM2, AUX_ITEM3 };
|
2020-03-16 11:05:01 +00:00
|
|
|
|
|
|
|
RC_TREE_NODE( RC_TREE_NODE* aParent, RC_ITEM* aRcItem, NODE_TYPE aType ) :
|
|
|
|
m_Type( aType ),
|
|
|
|
m_RcItem( aRcItem ),
|
|
|
|
m_Parent( aParent )
|
|
|
|
{}
|
|
|
|
|
|
|
|
~RC_TREE_NODE()
|
|
|
|
{
|
|
|
|
for( RC_TREE_NODE* child : m_Children )
|
|
|
|
delete child;
|
|
|
|
}
|
|
|
|
|
|
|
|
NODE_TYPE m_Type;
|
|
|
|
RC_ITEM* m_RcItem;
|
|
|
|
|
|
|
|
RC_TREE_NODE* m_Parent;
|
|
|
|
std::vector<RC_TREE_NODE*> m_Children;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class RC_TREE_MODEL : public wxDataViewModel, wxEvtHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static wxDataViewItem ToItem( RC_TREE_NODE const* aNode )
|
|
|
|
{
|
|
|
|
return wxDataViewItem( const_cast<void*>( static_cast<void const*>( aNode ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
static RC_TREE_NODE* ToNode( wxDataViewItem aItem )
|
|
|
|
{
|
|
|
|
return static_cast<RC_TREE_NODE*>( aItem.GetID() );
|
|
|
|
}
|
|
|
|
|
|
|
|
static KIID ToUUID( wxDataViewItem aItem );
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
2020-04-24 13:36:10 +00:00
|
|
|
RC_TREE_MODEL( EDA_DRAW_FRAME* aParentFrame, wxDataViewCtrl* aView );
|
2020-03-16 11:05:01 +00:00
|
|
|
|
|
|
|
~RC_TREE_MODEL();
|
|
|
|
|
|
|
|
void SetProvider( RC_ITEMS_PROVIDER* aProvider );
|
|
|
|
void SetSeverities( int aSeverities );
|
|
|
|
|
|
|
|
int GetDRCItemCount() const { return m_tree.size(); }
|
|
|
|
|
|
|
|
void ExpandAll();
|
|
|
|
|
|
|
|
bool IsContainer( wxDataViewItem const& aItem ) const override;
|
|
|
|
|
|
|
|
wxDataViewItem GetParent( wxDataViewItem const& aItem ) const override;
|
|
|
|
|
|
|
|
unsigned int GetChildren( wxDataViewItem const& aItem,
|
|
|
|
wxDataViewItemArray& aChildren ) const override;
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
unsigned int aCol ) const override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
|
|
|
wxDataViewItemAttr& aAttr ) const override;
|
|
|
|
|
|
|
|
void ValueChanged( RC_TREE_NODE* aNode );
|
|
|
|
|
|
|
|
void DeleteCurrentItem( bool aDeep );
|
|
|
|
void DeleteAllItems();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void rebuildModel( RC_ITEMS_PROVIDER* aProvider, int aSeverities );
|
|
|
|
void onSizeView( wxSizeEvent& aEvent );
|
|
|
|
|
|
|
|
private:
|
2020-04-24 13:36:10 +00:00
|
|
|
EDA_DRAW_FRAME* m_editFrame;
|
2020-03-16 11:05:01 +00:00
|
|
|
wxDataViewCtrl* m_view;
|
|
|
|
int m_severities;
|
|
|
|
RC_ITEMS_PROVIDER* m_rcItemsProvider; // I own this, but not its contents
|
|
|
|
|
|
|
|
std::vector<RC_TREE_NODE*> m_tree; // I own this
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // RC_ITEM_H
|