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
|
|
|
*
|
2022-08-30 11:03:40 +00:00
|
|
|
* Copyright (C) 2020-2022 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>
|
2022-09-19 16:09:59 +00:00
|
|
|
#include <units_provider.h>
|
2021-06-06 14:41:02 +00:00
|
|
|
#include <kiid.h>
|
2020-09-21 10:36:07 +00:00
|
|
|
#include <reporter.h>
|
2022-01-01 06:04:08 +00:00
|
|
|
#include <math/vector2d.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;
|
2021-06-06 14:41:02 +00:00
|
|
|
class EDA_ITEM;
|
|
|
|
class EDA_DRAW_FRAME;
|
2018-03-20 02:25:55 +00:00
|
|
|
|
2023-08-13 18:44:31 +00:00
|
|
|
namespace RC_JSON
|
|
|
|
{
|
|
|
|
struct VIOLATION;
|
|
|
|
}
|
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.
|
2020-10-07 13:15:31 +00:00
|
|
|
*
|
2020-03-16 11:05:01 +00:00
|
|
|
* 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;
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
virtual int GetCount( int aSeverity = -1 ) const = 0;
|
2020-03-16 11:05:01 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-07 13:15:31 +00:00
|
|
|
* Retrieve a RC_ITEM by index.
|
2020-03-16 11:05:01 +00:00
|
|
|
*/
|
2021-03-06 09:27:41 +00:00
|
|
|
virtual std::shared_ptr<RC_ITEM> GetItem( int aIndex ) const = 0;
|
2020-03-16 11:05:01 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-07 13:15:31 +00:00
|
|
|
* Remove (and optionally deletes) the indexed item from the list.
|
2020-03-29 19:02:23 +00:00
|
|
|
* @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;
|
|
|
|
|
|
|
|
virtual ~RC_ITEMS_PROVIDER() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-10-07 13:15:31 +00:00
|
|
|
* A holder for a rule check item, DRC in Pcbnew or ERC in Eeschema.
|
|
|
|
*
|
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
|
|
|
{
|
2020-09-25 18:27:56 +00:00
|
|
|
public:
|
|
|
|
typedef std::vector<KIID> KIIDS;
|
2020-10-07 13:15:31 +00:00
|
|
|
|
2020-06-20 14:36:16 +00:00
|
|
|
RC_ITEM() :
|
|
|
|
m_errorCode( 0 ),
|
2020-09-25 18:27:56 +00:00
|
|
|
m_parent( nullptr )
|
2009-07-06 18:02:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-12-18 17:19:15 +00:00
|
|
|
RC_ITEM( const std::shared_ptr<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;
|
2023-12-18 17:19:15 +00:00
|
|
|
m_ids = aItem->m_ids;
|
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
|
|
|
|
2022-01-22 22:44:46 +00:00
|
|
|
void SetItems( const KIIDS& aIds ) { m_ids = aIds; }
|
2020-09-25 18:27:56 +00:00
|
|
|
|
2021-06-06 14:41:02 +00:00
|
|
|
void AddItem( EDA_ITEM* aItem );
|
2020-09-25 18:27:56 +00:00
|
|
|
|
2020-10-14 10:06:04 +00:00
|
|
|
void SetItems( const EDA_ITEM* aItem, const EDA_ITEM* bItem = nullptr,
|
2021-06-06 14:41:02 +00:00
|
|
|
const EDA_ITEM* cItem = nullptr, const EDA_ITEM* dItem = nullptr );
|
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-09-25 18:27:56 +00:00
|
|
|
m_ids.clear();
|
2020-10-07 13:15:31 +00:00
|
|
|
|
2020-09-25 18:27:56 +00:00
|
|
|
m_ids.push_back( aItem );
|
|
|
|
m_ids.push_back( bItem );
|
|
|
|
m_ids.push_back( cItem );
|
|
|
|
m_ids.push_back( dItem );
|
2020-02-28 00:05:40 +00:00
|
|
|
}
|
|
|
|
|
2022-04-08 10:37:27 +00:00
|
|
|
virtual KIID GetMainItemID() const { return m_ids.size() > 0 ? m_ids[0] : niluuid; }
|
|
|
|
virtual KIID GetAuxItemID() const { return m_ids.size() > 1 ? m_ids[1] : niluuid; }
|
|
|
|
virtual KIID GetAuxItem2ID() const { return m_ids.size() > 2 ? m_ids[2] : niluuid; }
|
|
|
|
virtual KIID GetAuxItem3ID() const { return m_ids.size() > 3 ? m_ids[3] : niluuid; }
|
|
|
|
|
|
|
|
std::vector<KIID> GetIDs() const { return m_ids; }
|
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
|
|
|
/**
|
2020-10-07 13:15:31 +00:00
|
|
|
* Translate 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.
|
|
|
|
*/
|
2022-09-19 16:09:59 +00:00
|
|
|
virtual wxString ShowReport( UNITS_PROVIDER* aUnitsProvider, SEVERITY aSeverity,
|
2020-04-24 13:36:10 +00:00
|
|
|
const std::map<KIID, EDA_ITEM*>& aItemMap ) const;
|
2009-07-06 18:02:26 +00:00
|
|
|
|
2023-08-13 18:44:31 +00:00
|
|
|
/**
|
|
|
|
* Translate this object into an RC_JSON::VIOLATION object
|
|
|
|
*
|
|
|
|
* @param aViolation is the violation to be populated by info from this item
|
|
|
|
* @param aUnitsProvider is the units provider that will be used to output coordinates
|
|
|
|
* @param aSeverity is the severity of this item
|
|
|
|
* @param aItemMap is a map allowing the lookup of items from KIIDs
|
|
|
|
*
|
|
|
|
* @return None
|
|
|
|
*/
|
|
|
|
virtual void GetJsonViolation( RC_JSON::VIOLATION& aViolation, UNITS_PROVIDER* aUnitsProvider,
|
|
|
|
SEVERITY aSeverity, const std::map<KIID, EDA_ITEM*>& aItemMap ) const;
|
|
|
|
|
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
|
|
|
/**
|
2022-08-30 11:03:40 +00:00
|
|
|
* @return the error message describing the specific details of a RC_ITEM. For instance,
|
|
|
|
* "Clearance violation (netclass '100ohm' clearance 0.4000mm; actual 0.3200mm)"
|
2020-04-24 18:56:44 +00:00
|
|
|
*/
|
|
|
|
virtual wxString GetErrorMessage() const;
|
2009-07-06 18:02:26 +00:00
|
|
|
|
2022-08-30 11:03:40 +00:00
|
|
|
/**
|
|
|
|
* @return the error text for the class of error of this RC_ITEM represents. For instance,
|
|
|
|
* "Clearance violation".
|
|
|
|
*/
|
2020-06-08 02:19:46 +00:00
|
|
|
wxString GetErrorText() const
|
|
|
|
{
|
|
|
|
return wxGetTranslation( m_errorTitle );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString GetSettingsKey() const
|
|
|
|
{
|
|
|
|
return m_settingsKey;
|
|
|
|
}
|
|
|
|
|
2021-08-17 14:37:33 +00:00
|
|
|
virtual wxString GetViolatingRuleDesc() const
|
|
|
|
{
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
2020-12-21 15:17:52 +00:00
|
|
|
protected:
|
2024-01-25 17:30:22 +00:00
|
|
|
static wxString getSeverityString( SEVERITY aSeverity );
|
|
|
|
|
2020-12-21 15:17:52 +00:00
|
|
|
int m_errorCode; ///< The error code's numeric value
|
|
|
|
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
|
|
|
|
MARKER_BASE* m_parent; ///< The marker this item belongs to, if any
|
|
|
|
|
2022-01-22 22:44:46 +00:00
|
|
|
KIIDS m_ids;
|
2020-12-21 15:17:52 +00:00
|
|
|
|
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
|
|
|
|
2023-12-18 17:19:15 +00:00
|
|
|
RC_TREE_NODE( RC_TREE_NODE* aParent, const std::shared_ptr<RC_ITEM>& aRcItem, NODE_TYPE aType ) :
|
2020-03-16 11:05:01 +00:00
|
|
|
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;
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<RC_ITEM> m_RcItem;
|
2020-03-16 11:05:01 +00:00
|
|
|
|
|
|
|
RC_TREE_NODE* m_Parent;
|
|
|
|
std::vector<RC_TREE_NODE*> m_Children;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-01-10 08:15:26 +00:00
|
|
|
class RC_TREE_MODEL : public wxDataViewModel, public wxEvtHandler
|
2020-03-16 11:05:01 +00:00
|
|
|
{
|
|
|
|
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 );
|
|
|
|
|
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();
|
|
|
|
|
2022-08-30 11:03:40 +00:00
|
|
|
void Update( std::shared_ptr<RC_ITEMS_PROVIDER> aProvider, int aSeverities );
|
2020-03-16 11:05:01 +00:00
|
|
|
|
|
|
|
void ExpandAll();
|
|
|
|
|
2020-12-01 22:35:11 +00:00
|
|
|
void PrevMarker();
|
|
|
|
void NextMarker();
|
2021-10-05 22:33:30 +00:00
|
|
|
void SelectMarker( const MARKER_BASE* aMarker );
|
|
|
|
void CenterMarker( const MARKER_BASE* aMarker );
|
2020-12-01 22:35:11 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
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.
|
|
|
|
*/
|
2022-01-22 22:44:46 +00:00
|
|
|
void GetValue( wxVariant& aVariant, wxDataViewItem const& aItem,
|
|
|
|
unsigned int aCol ) const override;
|
2020-03-16 11:05:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by the wxDataView to edit an item's content.
|
|
|
|
*/
|
2022-01-22 22:44:46 +00:00
|
|
|
bool SetValue( wxVariant const& aVariant, wxDataViewItem const& aItem,
|
|
|
|
unsigned int aCol ) override
|
2020-03-16 11:05:01 +00:00
|
|
|
{
|
|
|
|
// Editing not supported
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-07 13:15:31 +00:00
|
|
|
* Called by the wxDataView to fetch an item's formatting. Return true if the
|
2020-03-16 11:05:01 +00:00
|
|
|
* item has non-default attributes.
|
|
|
|
*/
|
2022-01-22 22:44:46 +00:00
|
|
|
bool GetAttr( wxDataViewItem const& aItem, unsigned int aCol,
|
|
|
|
wxDataViewItemAttr& aAttr ) const override;
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
void ValueChanged( const RC_TREE_NODE* aNode );
|
2020-03-16 11:05:01 +00:00
|
|
|
|
|
|
|
void DeleteCurrentItem( bool aDeep );
|
2020-08-04 00:41:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes the current item or all items. If all, \a aIncludeExclusions determines
|
|
|
|
* whether or not exclusions are also deleted.
|
|
|
|
*/
|
|
|
|
void DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, bool aDeep );
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2023-01-21 23:25:40 +00:00
|
|
|
protected:
|
2023-08-13 18:44:31 +00:00
|
|
|
void rebuildModel( std::shared_ptr<RC_ITEMS_PROVIDER> aProvider, int aSeverities );
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2022-08-30 11:03:40 +00:00
|
|
|
EDA_DRAW_FRAME* m_editFrame;
|
|
|
|
wxDataViewCtrl* m_view;
|
|
|
|
int m_severities;
|
|
|
|
std::shared_ptr<RC_ITEMS_PROVIDER> m_rcItemsProvider;
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2022-08-30 11:03:40 +00:00
|
|
|
std::vector<RC_TREE_NODE*> m_tree; // I own this
|
2020-03-16 11:05:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // RC_ITEM_H
|