2012-03-15 14:31:16 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
2023-12-22 22:19:57 +00:00
|
|
|
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-03-15 14:31:16 +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
|
|
|
|
*/
|
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_draw_panel.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <trigo.h>
|
2020-10-25 04:49:02 +00:00
|
|
|
#include <widgets/msgpanel.h>
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2018-12-19 14:07:07 +00:00
|
|
|
#include <base_units.h>
|
2020-06-08 02:19:46 +00:00
|
|
|
#include <erc_settings.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_marker.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2020-03-16 11:05:01 +00:00
|
|
|
#include <widgets/ui_common.h>
|
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <settings/settings_manager.h>
|
|
|
|
#include <settings/color_settings.h>
|
|
|
|
#include <erc_item.h>
|
2023-01-21 23:25:40 +00:00
|
|
|
#include <sch_screen.h>
|
2009-07-07 17:50:02 +00:00
|
|
|
|
2018-12-19 14:07:07 +00:00
|
|
|
/// Factor to convert the maker unit shape to internal units:
|
2022-09-16 11:33:56 +00:00
|
|
|
#define SCALING_FACTOR schIUScale.mmToIU( 0.15 )
|
2018-12-19 14:07:07 +00:00
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
SCH_MARKER::SCH_MARKER( std::shared_ptr<ERC_ITEM> aItem, const VECTOR2I& aPos ) :
|
2020-03-16 11:05:01 +00:00
|
|
|
SCH_ITEM( nullptr, SCH_MARKER_T ),
|
2020-04-24 13:36:10 +00:00
|
|
|
MARKER_BASE( SCALING_FACTOR, aItem, MARKER_BASE::MARKER_ERC )
|
2009-07-07 17:50:02 +00:00
|
|
|
{
|
2020-04-24 13:36:10 +00:00
|
|
|
if( m_rcItem )
|
|
|
|
m_rcItem->SetParent( this );
|
|
|
|
|
|
|
|
m_Pos = aPos;
|
2023-01-21 23:25:40 +00:00
|
|
|
|
|
|
|
m_isLegacyMarker = false;
|
2009-07-07 17:50:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-22 21:34:01 +00:00
|
|
|
SCH_MARKER::~SCH_MARKER()
|
|
|
|
{
|
|
|
|
if( m_rcItem )
|
|
|
|
m_rcItem->SetParent( nullptr );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
EDA_ITEM* SCH_MARKER::Clone() const
|
2010-12-21 15:13:09 +00:00
|
|
|
{
|
|
|
|
return new SCH_MARKER( *this );
|
2009-07-07 17:50:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-29 21:17:26 +00:00
|
|
|
void SCH_MARKER::SwapData( SCH_ITEM* aItem )
|
|
|
|
{
|
2024-02-09 20:03:15 +00:00
|
|
|
SCH_ITEM::SwapFlags( aItem );
|
|
|
|
|
|
|
|
SCH_MARKER* item = static_cast<SCH_MARKER*>( aItem );
|
|
|
|
|
|
|
|
std::swap( m_isLegacyMarker, item->m_isLegacyMarker );
|
|
|
|
std::swap( m_Pos, item->m_Pos );
|
|
|
|
|
|
|
|
std::swap( m_markerType, item->m_markerType );
|
|
|
|
std::swap( m_excluded, item->m_excluded );
|
|
|
|
std::swap( m_rcItem, item->m_rcItem );
|
|
|
|
|
|
|
|
std::swap( m_scalingFactor, item->m_scalingFactor );
|
|
|
|
std::swap( m_shapeBoundingBox, item->m_shapeBoundingBox );
|
|
|
|
|
2019-04-29 21:17:26 +00:00
|
|
|
std::swap( *((SCH_MARKER*) this), *((SCH_MARKER*) aItem ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-18 22:55:38 +00:00
|
|
|
wxString SCH_MARKER::Serialize() const
|
|
|
|
{
|
2023-01-21 23:25:40 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> erc = std::static_pointer_cast<ERC_ITEM>( m_rcItem );
|
|
|
|
wxString sheetSpecificPath, mainItemPath, auxItemPath;
|
|
|
|
|
|
|
|
if( erc->IsSheetSpecific() )
|
|
|
|
sheetSpecificPath = erc->GetSpecificSheetPath().Path().AsString();
|
|
|
|
|
|
|
|
if( erc->MainItemHasSheetPath() )
|
|
|
|
mainItemPath = erc->GetMainItemSheetPath().Path().AsString();
|
|
|
|
|
|
|
|
if( erc->AuxItemHasSheetPath() )
|
|
|
|
auxItemPath = erc->GetAuxItemSheetPath().Path().AsString();
|
|
|
|
|
|
|
|
return wxString::Format( wxT( "%s|%d|%d|%s|%s|%s|%s|%s" ), m_rcItem->GetSettingsKey(), m_Pos.x,
|
|
|
|
m_Pos.y, m_rcItem->GetMainItemID().AsString(),
|
|
|
|
m_rcItem->GetAuxItemID().AsString(), sheetSpecificPath, mainItemPath,
|
|
|
|
auxItemPath );
|
2020-11-18 22:55:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-06-06 10:31:22 +00:00
|
|
|
SCH_MARKER* SCH_MARKER::Deserialize( const SCH_SHEET_LIST& aSheetList, const wxString& data )
|
2020-11-18 22:55:38 +00:00
|
|
|
{
|
|
|
|
wxArrayString props = wxSplit( data, '|' );
|
2022-01-04 01:00:40 +00:00
|
|
|
VECTOR2I markerPos( (int) strtol( props[1].c_str(), nullptr, 10 ),
|
2020-11-18 22:55:38 +00:00
|
|
|
(int) strtol( props[2].c_str(), nullptr, 10 ) );
|
|
|
|
|
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( props[0] );
|
|
|
|
|
|
|
|
if( !ercItem )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
ercItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
|
|
|
|
|
2023-01-21 23:25:40 +00:00
|
|
|
bool isLegacyMarker = true;
|
|
|
|
|
|
|
|
// Deserialize sheet / item specific paths - we are not able to use the file version to determine
|
|
|
|
// if markers are legacy as there could be a file opened with a prior version but which has
|
|
|
|
// new markers - this code is called not just during schematic load, but also to match new
|
|
|
|
// ERC exceptions to exclusions.
|
|
|
|
if( props.size() == 8 )
|
|
|
|
{
|
|
|
|
isLegacyMarker = false;
|
|
|
|
|
|
|
|
if( !props[5].IsEmpty() )
|
|
|
|
{
|
|
|
|
KIID_PATH sheetSpecificKiidPath( props[5] );
|
|
|
|
std::optional<SCH_SHEET_PATH> sheetSpecificPath =
|
2024-06-06 10:31:22 +00:00
|
|
|
aSheetList.GetSheetPathByKIIDPath( sheetSpecificKiidPath, true );
|
2023-01-21 23:25:40 +00:00
|
|
|
if( sheetSpecificPath.has_value() )
|
|
|
|
ercItem->SetSheetSpecificPath( sheetSpecificPath.value() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !props[6].IsEmpty() )
|
|
|
|
{
|
|
|
|
KIID_PATH mainItemKiidPath( props[6] );
|
|
|
|
std::optional<SCH_SHEET_PATH> mainItemPath =
|
2024-06-06 10:31:22 +00:00
|
|
|
aSheetList.GetSheetPathByKIIDPath( mainItemKiidPath, true );
|
2023-01-21 23:25:40 +00:00
|
|
|
if( mainItemPath.has_value() )
|
|
|
|
{
|
|
|
|
if( props[7].IsEmpty() )
|
|
|
|
{
|
|
|
|
ercItem->SetItemsSheetPaths( mainItemPath.value() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
KIID_PATH auxItemKiidPath( props[7] );
|
|
|
|
std::optional<SCH_SHEET_PATH> auxItemPath =
|
2024-06-06 10:31:22 +00:00
|
|
|
aSheetList.GetSheetPathByKIIDPath( auxItemKiidPath, true );
|
2023-01-21 23:25:40 +00:00
|
|
|
|
|
|
|
if( auxItemPath.has_value() )
|
|
|
|
ercItem->SetItemsSheetPaths( mainItemPath.value(), auxItemPath.value() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, markerPos );
|
|
|
|
marker->SetIsLegacyMarker( isLegacyMarker );
|
|
|
|
|
|
|
|
return marker;
|
2020-11-18 22:55:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-07 17:50:02 +00:00
|
|
|
#if defined(DEBUG)
|
|
|
|
|
2011-12-14 17:25:42 +00:00
|
|
|
void SCH_MARKER::Show( int nestLevel, std::ostream& os ) const
|
2009-07-07 17:50:02 +00:00
|
|
|
{
|
|
|
|
// for now, make it look like XML:
|
2019-08-07 18:23:59 +00:00
|
|
|
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << GetPos() << "/>\n";
|
2009-07-07 17:50:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
void SCH_MARKER::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
2020-05-13 02:00:37 +00:00
|
|
|
wxCHECK_RET( Schematic(), "No SCHEMATIC set for SCH_MARKER!" );
|
|
|
|
|
2023-01-21 23:25:40 +00:00
|
|
|
// Don't display sheet-specific markers when SCH_SHEET_PATHs do not match
|
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = std::static_pointer_cast<ERC_ITEM>( GetRCItem() );
|
|
|
|
|
|
|
|
if( ercItem->IsSheetSpecific()
|
|
|
|
&& ( ercItem->GetSpecificSheetPath() != Schematic()->CurrentSheet() ) )
|
|
|
|
{
|
|
|
|
aCount = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aCount = 2;
|
|
|
|
|
2021-11-05 21:16:26 +00:00
|
|
|
if( IsExcluded() )
|
2020-03-16 11:05:01 +00:00
|
|
|
{
|
2021-11-05 21:16:26 +00:00
|
|
|
aLayers[0] = LAYER_ERC_EXCLUSION;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch( Schematic()->ErcSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case SEVERITY::RPT_SEVERITY_ERROR: aLayers[0] = LAYER_ERC_ERR; break;
|
|
|
|
case SEVERITY::RPT_SEVERITY_WARNING: aLayers[0] = LAYER_ERC_WARN; break;
|
|
|
|
}
|
2020-03-16 11:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aLayers[1] = LAYER_SELECTION_SHADOWS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_LAYER_ID SCH_MARKER::GetColorLayer() const
|
2009-07-07 17:50:02 +00:00
|
|
|
{
|
2020-02-28 00:05:40 +00:00
|
|
|
if( IsExcluded() )
|
2021-11-05 21:16:26 +00:00
|
|
|
return LAYER_ERC_EXCLUSION;
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
wxCHECK_MSG( Schematic(), LAYER_ERC_ERR, "No SCHEMATIC set for SCH_MARKER!" );
|
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
switch( Schematic()->ErcSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
|
2020-03-16 11:05:01 +00:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
case SEVERITY::RPT_SEVERITY_ERROR: return LAYER_ERC_ERR;
|
|
|
|
case SEVERITY::RPT_SEVERITY_WARNING: return LAYER_ERC_WARN;
|
|
|
|
}
|
2020-02-28 00:05:40 +00:00
|
|
|
}
|
2009-07-08 15:42:45 +00:00
|
|
|
|
2009-07-07 17:50:02 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
KIGFX::COLOR4D SCH_MARKER::getColor() const
|
2020-02-28 00:05:40 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
|
|
|
|
return colors->GetColor( GetColorLayer() );
|
2009-07-07 17:50:02 +00:00
|
|
|
}
|
|
|
|
|
2009-07-08 15:42:45 +00:00
|
|
|
|
2022-02-18 10:37:41 +00:00
|
|
|
SEVERITY SCH_MARKER::GetSeverity() const
|
|
|
|
{
|
|
|
|
if( IsExcluded() )
|
|
|
|
return RPT_SEVERITY_EXCLUSION;
|
|
|
|
|
|
|
|
ERC_ITEM* item = static_cast<ERC_ITEM*>( m_rcItem.get() );
|
|
|
|
|
|
|
|
return Schematic()->ErcSettings().GetSeverity( item->GetErrorCode() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_MARKER::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
|
2010-03-16 18:22:59 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
PrintMarker( aSettings, aOffset );
|
2010-03-16 18:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-05 02:40:38 +00:00
|
|
|
bool SCH_MARKER::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
|
2018-10-21 12:50:31 +00:00
|
|
|
{
|
2020-04-24 18:56:44 +00:00
|
|
|
return SCH_ITEM::Matches( m_rcItem->GetErrorMessage(), aSearchData );
|
2018-10-21 12:50:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I SCH_MARKER::GetBoundingBox() const
|
2009-07-08 15:42:45 +00:00
|
|
|
{
|
|
|
|
return GetBoundingBoxMarker();
|
|
|
|
}
|
|
|
|
|
2010-04-06 14:09:52 +00:00
|
|
|
|
2021-09-26 23:22:32 +00:00
|
|
|
void SCH_MARKER::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
|
2010-04-06 14:09:52 +00:00
|
|
|
{
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Electrical Rule Check Error" ), m_rcItem->GetErrorMessage() );
|
2010-04-06 14:09:52 +00:00
|
|
|
}
|
2010-09-05 17:01:48 +00:00
|
|
|
|
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS SCH_MARKER::GetMenuImage() const
|
2017-02-20 12:20:39 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
return BITMAPS::erc;
|
2017-02-20 12:20:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_MARKER::Rotate( const VECTOR2I& aCenter )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2020-12-15 22:32:02 +00:00
|
|
|
// Marker geometry isn't user-editable
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
void SCH_MARKER::MirrorVertically( int aCenter )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2020-12-15 22:32:02 +00:00
|
|
|
// Marker geometry isn't user-editable
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
void SCH_MARKER::MirrorHorizontally( int aCenter )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2020-12-15 22:32:02 +00:00
|
|
|
// Marker geometry isn't user-editable
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
2010-11-03 14:13:15 +00:00
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool SCH_MARKER::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2019-05-05 10:33:34 +00:00
|
|
|
return HitTestMarker( aPosition, aAccuracy );
|
2010-12-13 15:59:00 +00:00
|
|
|
}
|