Move weak-reference stuff to UUIDs.
This commit is contained in:
parent
c7ec110fba
commit
c5077aeb97
|
@ -2,7 +2,7 @@
|
|||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2007 Dick Hollenbeck, dick@softplc.com
|
||||
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 2018-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
|
||||
|
@ -36,29 +36,22 @@ class BOARD_ITEM;
|
|||
/**
|
||||
* DRC_ITEM
|
||||
* is a holder for a DRC (in Pcbnew) or ERC (in Eeschema) error item.
|
||||
* It is generated when two objects are too close (DRC)
|
||||
* or two connected objects (pins) have incompatible electrical types (ERC).
|
||||
* There are holders for information on two items. The
|
||||
* information held is the board coordinate and the MenuText for each item.
|
||||
* Also held is the type of error by number and the location of the MARKER.
|
||||
* A function is provided to translate that number into text.
|
||||
* Some errors involve only one item (item with an incorrect param) so
|
||||
* m_hasSecondItem is set to false in this case.
|
||||
* There are holders for information on two EDA_ITEMs. Some errors involve only one item
|
||||
* (item with an incorrect param) so m_hasSecondItem is set to false in this case.
|
||||
*/
|
||||
class DRC_ITEM
|
||||
{
|
||||
protected:
|
||||
int m_ErrorCode; // the error code's numeric value
|
||||
wxString m_MainText; // text for the first BOARD_ITEM or SCH_ITEM
|
||||
wxString m_AuxiliaryText; // text for the second BOARD_ITEM or SCH_ITEM
|
||||
wxPoint m_MainPosition; // the location of the first (or main ) BOARD_ITEM or SCH_ITEM.
|
||||
wxPoint m_AuxiliaryPosition; // the location of the second BOARD_ITEM or SCH_ITEM
|
||||
bool m_hasSecondItem; // true when 2 items create a DRC/ERC error, false if only one item
|
||||
wxString m_MainText; // text for the first EDA_ITEM
|
||||
wxString m_AuxiliaryText; // text for the second EDA_ITEM
|
||||
wxPoint m_MainPosition; // the location of the first EDA_ITEM
|
||||
wxPoint m_AuxiliaryPosition; // the location of the second EDA_ITEM
|
||||
bool m_hasSecondItem; // true when 2 items create a DRC/ERC error
|
||||
bool m_noCoordinate;
|
||||
|
||||
MARKER_BASE* m_parent; // The marker this item belongs to, if any
|
||||
void* m_mainItemWeakRef; // search the current BOARD_ITEMs or SCH_ITEMs for a match
|
||||
void* m_auxItemWeakRef; // search the current BOARD_ITEMs or SCH_ITEMs for a match
|
||||
KIID m_mainItemUuid;
|
||||
KIID m_auxItemUuid;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -68,8 +61,8 @@ public:
|
|||
m_hasSecondItem = false;
|
||||
m_noCoordinate = false;
|
||||
m_parent = nullptr;
|
||||
m_mainItemWeakRef = nullptr;
|
||||
m_auxItemWeakRef = nullptr;
|
||||
m_mainItemUuid = niluuid;
|
||||
m_auxItemUuid = niluuid;
|
||||
}
|
||||
|
||||
DRC_ITEM( EDA_UNITS aUnits, int aErrorCode, EDA_ITEM* aMainItem, const wxPoint& aMainPos,
|
||||
|
@ -83,14 +76,12 @@ public:
|
|||
SetData( aUnits, aErrorCode, aMainItem, aMainPos );
|
||||
}
|
||||
|
||||
|
||||
DRC_ITEM( int aErrorCode, const wxString& aMainText )
|
||||
{
|
||||
SetData( aErrorCode, aMainText, wxPoint() );
|
||||
SetShowNoCoordinate();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function SetData
|
||||
* initialize all data in item
|
||||
|
@ -111,13 +102,13 @@ public:
|
|||
m_hasSecondItem = bAuxiliaryItem != nullptr;
|
||||
m_noCoordinate = false;
|
||||
m_parent = nullptr;
|
||||
m_mainItemUuid = aMainItem->m_Uuid;
|
||||
|
||||
if( m_hasSecondItem )
|
||||
{
|
||||
m_AuxiliaryText = bAuxiliaryItem->GetSelectMenuText( aUnits );
|
||||
|
||||
// Weak references (void*). One must search the BOARD_ITEMS or SCH_ITEMS for a match.
|
||||
m_mainItemWeakRef = aMainItem;
|
||||
m_auxItemWeakRef = bAuxiliaryItem;
|
||||
m_auxItemUuid = bAuxiliaryItem->m_Uuid;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -130,7 +121,8 @@ public:
|
|||
* @param bAuxiliaryPos = position the second item
|
||||
*/
|
||||
void SetData( int aErrorCode, const wxString& aMainText, const wxPoint& aMainPos,
|
||||
const wxString& bAuxiliaryText = wxEmptyString, const wxPoint& bAuxiliaryPos = wxPoint() )
|
||||
const wxString& bAuxiliaryText = wxEmptyString,
|
||||
const wxPoint& bAuxiliaryPos = wxPoint() )
|
||||
{
|
||||
m_ErrorCode = aErrorCode;
|
||||
m_MainText = aMainText;
|
||||
|
@ -140,9 +132,8 @@ public:
|
|||
m_hasSecondItem = bAuxiliaryText.Length();
|
||||
m_noCoordinate = false;
|
||||
m_parent = nullptr;
|
||||
|
||||
m_mainItemWeakRef = nullptr;
|
||||
m_auxItemWeakRef = nullptr;
|
||||
m_mainItemUuid = niluuid;
|
||||
m_auxItemUuid = niluuid;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -156,12 +147,10 @@ public:
|
|||
m_AuxiliaryText = aAuxiliaryText;
|
||||
m_AuxiliaryPosition = aAuxiliaryPos;
|
||||
m_hasSecondItem = true;
|
||||
|
||||
m_auxItemWeakRef = nullptr;
|
||||
m_auxItemUuid = niluuid;
|
||||
}
|
||||
|
||||
void SetParent( MARKER_BASE* aMarker ) { m_parent = aMarker; }
|
||||
|
||||
MARKER_BASE* GetParent() const { return m_parent; }
|
||||
|
||||
bool HasSecondItem() const { return m_hasSecondItem; }
|
||||
|
@ -182,24 +171,18 @@ public:
|
|||
|
||||
/**
|
||||
* Function ShowHtml
|
||||
* translates this object into a fragment of HTML suitable for the
|
||||
* wxWidget's wxHtmlListBox class.
|
||||
* translates this object into a fragment of HTML suitable for the wxHtmlListBox class.
|
||||
* @return wxString - the html text.
|
||||
*/
|
||||
wxString ShowHtml( EDA_UNITS aUnits ) const;
|
||||
|
||||
/**
|
||||
* Function ShowReport
|
||||
* translates this object into a text string suitable for saving
|
||||
* to disk in a report.
|
||||
* translates this object into a text string suitable for saving to disk in a report.
|
||||
* @return wxString - the simple multi-line report text.
|
||||
*/
|
||||
wxString ShowReport( EDA_UNITS aUnits ) const;
|
||||
|
||||
/**
|
||||
* Function GetErrorCode
|
||||
* returns the error code.
|
||||
*/
|
||||
int GetErrorCode() const
|
||||
{
|
||||
return m_ErrorCode;
|
||||
|
@ -211,35 +194,15 @@ public:
|
|||
*/
|
||||
wxString GetErrorText() const;
|
||||
|
||||
const wxString& GetTextA() const
|
||||
{
|
||||
return m_MainText;
|
||||
}
|
||||
|
||||
|
||||
const wxString& GetTextB() const
|
||||
{
|
||||
return m_AuxiliaryText;
|
||||
}
|
||||
|
||||
|
||||
const wxPoint& GetPointA() const
|
||||
{
|
||||
return m_MainPosition;
|
||||
}
|
||||
|
||||
|
||||
const wxPoint& GetPointB() const
|
||||
{
|
||||
return m_AuxiliaryPosition;
|
||||
}
|
||||
const wxString& GetTextA() const { return m_MainText; }
|
||||
const wxString& GetTextB() const { return m_AuxiliaryText; }
|
||||
|
||||
const wxPoint& GetPointA() const { return m_MainPosition; }
|
||||
const wxPoint& GetPointB() const { return m_AuxiliaryPosition; }
|
||||
|
||||
/**
|
||||
* Function ShowCoord
|
||||
* formats a coordinate or position to text.
|
||||
* @param aPos The position to format
|
||||
* @return wxString - The formated string
|
||||
*/
|
||||
static wxString ShowCoord( EDA_UNITS aUnits, const wxPoint& aPos );
|
||||
};
|
||||
|
|
|
@ -700,40 +700,47 @@ void BOARD::DeleteZONEOutlines()
|
|||
}
|
||||
|
||||
|
||||
BOARD_ITEM* BOARD::GetItem( void* aWeakReference )
|
||||
BOARD_ITEM* BOARD::GetItem( const KIID& aID )
|
||||
{
|
||||
if( aID == niluuid )
|
||||
return nullptr;
|
||||
|
||||
for( TRACK* track : Tracks() )
|
||||
if( track == aWeakReference )
|
||||
if( track->m_Uuid == aID )
|
||||
return track;
|
||||
|
||||
for( MODULE* module : Modules() )
|
||||
{
|
||||
if( module == aWeakReference )
|
||||
if( module->m_Uuid == aID )
|
||||
return module;
|
||||
|
||||
for( D_PAD* pad : module->Pads() )
|
||||
if( pad == aWeakReference )
|
||||
if( pad->m_Uuid == aID )
|
||||
return pad;
|
||||
|
||||
if( &module->Reference() == aWeakReference )
|
||||
if( module->Reference().m_Uuid == aID )
|
||||
return &module->Reference();
|
||||
|
||||
if( &module->Value() == aWeakReference )
|
||||
if( module->Value().m_Uuid == aID )
|
||||
return &module->Value();
|
||||
|
||||
for( BOARD_ITEM* drawing : module->GraphicalItems() )
|
||||
if( drawing == aWeakReference )
|
||||
if( drawing->m_Uuid == aID )
|
||||
return drawing;
|
||||
}
|
||||
|
||||
for( ZONE_CONTAINER* zone : Zones() )
|
||||
if( zone == aWeakReference )
|
||||
if( zone->m_Uuid == aID )
|
||||
return zone;
|
||||
|
||||
for( BOARD_ITEM* drawing : Drawings() )
|
||||
if( drawing == aWeakReference )
|
||||
if( drawing->m_Uuid == aID )
|
||||
return drawing;
|
||||
|
||||
for( MARKER_PCB* marker : m_markers )
|
||||
if( marker->m_Uuid == aID )
|
||||
return marker;
|
||||
|
||||
// Not found; weak reference has been deleted.
|
||||
if( !g_DeletedItem )
|
||||
g_DeletedItem = new DELETED_BOARD_ITEM();
|
||||
|
|
|
@ -291,7 +291,7 @@ public:
|
|||
m_modules.clear();
|
||||
}
|
||||
|
||||
BOARD_ITEM* GetItem( void* aWeakReference );
|
||||
BOARD_ITEM* GetItem( const KIID& aID );
|
||||
|
||||
/**
|
||||
* Function GetConnectivity()
|
||||
|
|
|
@ -323,7 +323,7 @@ bool DIALOG_DRC_CONTROL::focusOnItem( const DRC_ITEM* aItem )
|
|||
toolmgr->RunAction( PCB_ACTIONS::selectItem, true, marker );
|
||||
}
|
||||
|
||||
m_brdEditor->FocusOnLocation( pos, true );
|
||||
m_brdEditor->FocusOnLocation( pos );
|
||||
m_brdEditor->GetCanvas()->Refresh();
|
||||
|
||||
return true;
|
||||
|
@ -398,7 +398,7 @@ void DIALOG_DRC_CONTROL::doSelectionMenu( const DRC_ITEM* aItem )
|
|||
BOARD_ITEM* selection = items.GetCount() ? items[0] : nullptr;
|
||||
|
||||
if( selection && ( selection == first || selection == second ) )
|
||||
m_brdEditor->FocusOnLocation( selection->GetPosition(), true );
|
||||
m_brdEditor->FocusOnLocation( selection->GetPosition() );
|
||||
|
||||
m_brdEditor->GetCanvas()->Refresh();
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
|
||||
#include <fctsys.h>
|
||||
#include <common.h>
|
||||
|
||||
#include <pcbnew.h>
|
||||
#include "wx/html/m_templ.h"
|
||||
#include "wx/html/styleparams.h"
|
||||
#include <drc/drc.h>
|
||||
#include <drc_item.h>
|
||||
#include <class_board.h>
|
||||
|
@ -209,17 +209,23 @@ wxString DRC_ITEM::ShowHtml( EDA_UNITS aUnits ) const
|
|||
|
||||
// an html fragment for the entire message in the listbox. feel free
|
||||
// to add color if you want:
|
||||
return wxString::Format( wxT( "<b>%s</b><br> %s: %s<br> %s: %s" ),
|
||||
return wxString::Format( wxT( "<b>%s</b><br>"
|
||||
"<kidiv id='%s'> %s: %s</kidiv><br>"
|
||||
"<kidiv id='%s'> %s: %s</kidiv>" ),
|
||||
errText,
|
||||
m_mainItemUuid.AsString(),
|
||||
ShowCoord( aUnits, m_MainPosition ),
|
||||
mainText,
|
||||
m_auxItemUuid.AsString(),
|
||||
ShowCoord( aUnits, m_AuxiliaryPosition ),
|
||||
auxText );
|
||||
}
|
||||
else
|
||||
{
|
||||
return wxString::Format( wxT( "<b>%s</b><br> %s: %s" ),
|
||||
return wxString::Format( wxT( "<b>%s</b><br>"
|
||||
"<kidiv id='%s'> %s: %s</kidiv>" ),
|
||||
errText,
|
||||
m_mainItemUuid.AsString(),
|
||||
ShowCoord( aUnits, m_MainPosition ),
|
||||
mainText );
|
||||
}
|
||||
|
@ -251,12 +257,13 @@ wxString DRC_ITEM::ShowReport( EDA_UNITS aUnits ) const
|
|||
|
||||
BOARD_ITEM* DRC_ITEM::GetMainItem( BOARD* aBoard ) const
|
||||
{
|
||||
return aBoard->GetItem( m_mainItemWeakRef );
|
||||
return aBoard->GetItem( m_mainItemUuid );
|
||||
}
|
||||
|
||||
|
||||
BOARD_ITEM* DRC_ITEM::GetAuxiliaryItem( BOARD* aBoard ) const
|
||||
{
|
||||
return aBoard->GetItem( m_auxItemWeakRef );
|
||||
return aBoard->GetItem( m_auxItemUuid );
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue