KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue25978_operating_point_voltages.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <advanced_config.h>
23#include <connection_graph.h>
25#include <eeschema_helpers.h>
27#include <sch_label.h>
28#include <sch_line.h>
29#include <sch_painter.h>
30#include <sch_screen.h>
31#include <schematic.h>
32#include <scoped_set_reset.h>
33#include <sim/operating_point.h>
34#include <view/view.h>
35
36#include <algorithm>
37#include <limits>
38
39
40BOOST_AUTO_TEST_SUITE( OperatingPointVoltages )
41
42BOOST_AUTO_TEST_CASE( BothEnginesAssignVoltageToLongestWire )
43{
44 auto& enabled = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() ).m_ConnectivityEngine;
45 SCOPED_SET_RESET restore( enabled, enabled );
46
47 for( bool published : { false, true } )
48 {
49 BOOST_TEST_CONTEXT( "published=" << published )
50 {
51 enabled = published;
52 wxString path =
53 wxString::FromUTF8( KI_TEST::GetEeschemaTestDataDir() ) + wxS( "issue25198/SVG-Test.kicad_sch" );
54 std::unique_ptr<SCHEMATIC> schematic( EESCHEMA_HELPERS::LoadSchematic( path, true, false ) );
55 BOOST_REQUIRE( schematic );
56 SCH_SCREEN* screen = schematic->RootScreen();
57 auto* longest = new SCH_LINE( VECTOR2I( 100000, 100000 ), LAYER_WIRE );
58 longest->SetEndPoint( { 500000, 100000 } );
59 screen->Append( longest );
60 auto* shorter = new SCH_LINE( longest->GetEndPoint(), LAYER_WIRE );
61 shorter->SetEndPoint( { 550000, 100000 } );
62 screen->Append( shorter );
63 screen->Append( new SCH_LABEL( longest->GetStartPoint(), wxS( "OP_TEST" ) ) );
64 schematic->RebuildConnectivity();
65
66 const auto name = longest->GetConnectionName( &schematic->CurrentSheet() );
68 wxString spiceName = *name;
70 spiceName.MakeLower();
71 schematic->SetOperatingPoint( spiceName, 12.345 );
72 const auto& settings = schematic->Settings();
73 const wxString expected =
74 schematic->GetOperatingPoint( *name, settings.m_OPO_VPrecision, settings.m_OPO_VRange );
75 BOOST_REQUIRE( expected != wxS( "?" ) && expected != wxS( "--" ) && !expected.IsEmpty() );
76
77 if( published )
78 {
79 BOOST_REQUIRE( !schematic->Connectivity().GetNetMap().empty() );
80 BOOST_CHECK( schematic->ConnectionGraph()->GetNetMap().empty() );
81 }
82
83 std::vector<SCH_LINE*> changed;
85 [&]( SCH_LINE* aWire )
86 {
87 changed.push_back( aWire );
88 } );
89 BOOST_CHECK_EQUAL( longest->GetOperatingPoint(), expected );
90 BOOST_CHECK( shorter->GetOperatingPoint().IsEmpty() );
91 BOOST_REQUIRE_EQUAL( changed.size(), 1u );
92 BOOST_CHECK( changed[0] == longest );
93
94 // The voltage layer is present; data assignment must not depend on its visibility.
95 const auto layers = longest->ViewGetLayers();
96 BOOST_CHECK( std::find( layers.begin(), layers.end(), LAYER_OP_VOLTAGES ) != layers.end() );
97 KIGFX::SCH_PAINTER painter( nullptr );
98 KIGFX::VIEW view;
99 view.SetPainter( &painter );
100 const double lod = longest->ViewGetLOD( LAYER_OP_VOLTAGES, &view );
101 BOOST_CHECK( lod != std::numeric_limits<double>::max() );
102 BOOST_CHECK_LT( lod, 1.0 );
103
104 longest->SetOperatingPoint( wxEmptyString );
105 changed.clear();
106 schematic->SetOperatingPoint( spiceName, 0.0 );
108 [&]( SCH_LINE* aWire )
109 {
110 changed.push_back( aWire );
111 } );
112 BOOST_CHECK( !longest->GetOperatingPoint().IsEmpty() );
113 BOOST_CHECK_EQUAL( changed.size(), 1u );
114
115 longest->SetOperatingPoint( wxEmptyString );
116 changed.clear();
117 schematic->ClearOperatingPoints();
119 [&]( SCH_LINE* aWire )
120 {
121 changed.push_back( aWire );
122 } );
123 BOOST_CHECK( longest->GetOperatingPoint().IsEmpty() );
124 BOOST_CHECK( changed.empty() );
125 }
126 }
127}
128
const char * name
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
static SCHEMATIC * LoadSchematic(const wxString &aFileName, bool aSetActive, bool aForceDefaultProject, PROJECT *aProject=nullptr, bool aCalculateConnectivity=true, REPORTER *aRootReporter=nullptr)
Contains methods for drawing schematic-specific items.
Definition sch_painter.h:66
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:68
void SetPainter(PAINTER *aPainter)
Set the painter object used by the view for drawing VIEW_ITEM objects.
Definition view.h:232
static void ConvertToSpiceMarkup(wxString *aNetName)
Convert an escaped schematic net name to SPICE, preserving literal slashes when mapping ground names.
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:39
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
RAII class that sets an value at construction and resets it to the original value at destruction.
bool m_ConnectivityEngine
Use the schematic connectivity engine instead of CONNECTION_GRAPH.
@ LAYER_WIRE
Definition layer_ids.h:483
@ LAYER_OP_VOLTAGES
Definition layer_ids.h:532
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
void UpdateOperatingPointVoltages(SCHEMATIC &aSchematic, const std::function< void(SCH_LINE *)> &aOnChanged)
Assign loaded operating-point voltages to the longest wire in each connected net portion.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_REQUIRE_EQUAL(rows.size(), 1)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_SUITE_END()
std::string path
VECTOR3I expected(15, 30, 45)
BOOST_TEST_CONTEXT("Test Clearance")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708