KiCad PCB EDA Suite
Loading...
Searching...
No Matches
ee_tool_utils.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 (C) 2024 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, you may find one here:
18
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19
* or you may search the http://www.gnu.org website for the version 2 license,
20
* or you may write to the Free Software Foundation, Inc.,
21
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22
*/
23
24
#include "
ee_tool_utils.h
"
25
26
#include <
sch_text.h
>
27
#include <
sch_field.h
>
28
#include <
sch_pin.h
>
29
#include <
sch_table.h
>
30
#include <
sch_tablecell.h
>
31
#include <
sch_textbox.h
>
32
33
#include <wx/arrstr.h>
34
35
wxString
GetSchItemAsText
(
const
SCH_ITEM
& aItem )
36
{
37
switch
( aItem.
Type
() )
38
{
39
case
SCH_TEXT_T
:
40
case
SCH_LABEL_T
:
41
case
SCH_HIER_LABEL_T
:
42
case
SCH_GLOBAL_LABEL_T
:
43
case
SCH_DIRECTIVE_LABEL_T
:
44
case
SCH_SHEET_PIN_T
:
45
{
46
const
SCH_TEXT
&
text
=
static_cast<
const
SCH_TEXT
&
>
( aItem );
47
return
text
.GetShownText(
true
);
48
}
49
case
SCH_FIELD_T
:
50
{
51
// Goes via EDA_TEXT
52
const
SCH_FIELD
& field =
static_cast<
const
SCH_FIELD
&
>
( aItem );
53
return
field.
GetShownText
(
true
);
54
}
55
case
SCH_TEXTBOX_T
:
56
case
SCH_TABLECELL_T
:
57
{
58
// Also EDA_TEXT
59
const
SCH_TEXTBOX
& textbox =
static_cast<
const
SCH_TEXTBOX
&
>
( aItem );
60
return
textbox.
GetShownText
(
true
);
61
}
62
case
SCH_PIN_T
:
63
{
64
// This is a choice - probably the name makes more sense than the number
65
// (or should it be name/number?)
66
const
SCH_PIN
&
pin
=
static_cast<
const
SCH_PIN
&
>
( aItem );
67
return
pin
.GetShownName();
68
}
69
case
SCH_TABLE_T
:
70
{
71
// A simple tabbed list of the cells seems like a place to start here
72
const
SCH_TABLE
& table =
static_cast<
const
SCH_TABLE
&
>
( aItem );
73
wxString s;
74
75
for
(
int
row = 0; row < table.
GetRowCount
(); ++row )
76
{
77
for
(
int
col = 0; col < table.
GetColCount
(); ++col )
78
{
79
const
SCH_TABLECELL
* cell = table.
GetCell
( row, col );
80
s << cell->
GetShownText
(
true
);
81
82
if
( col < table.
GetColCount
() - 1 )
83
{
84
s <<
'\t'
;
85
}
86
}
87
88
if
( row < table.
GetRowCount
() - 1 )
89
{
90
s <<
'\n'
;
91
}
92
}
93
return
s;
94
}
95
default
:
96
{
97
break
;
98
}
99
}
100
101
return
wxEmptyString;
102
};
103
104
105
wxString
GetSelectedItemsAsText
(
const
SELECTION
& aSel )
106
{
107
wxArrayString itemTexts;
108
109
for
(
EDA_ITEM
* item : aSel )
110
{
111
if
( item->IsSCH_ITEM() )
112
{
113
const
SCH_ITEM
& schItem =
static_cast<
const
SCH_ITEM
&
>
( *item );
114
wxString itemText =
GetSchItemAsText
( schItem );
115
116
itemText.Trim(
false
).Trim(
true
);
117
118
if
( !itemText.IsEmpty() )
119
{
120
itemTexts.Add( std::move( itemText ) );
121
}
122
}
123
}
124
125
return
wxJoin( itemTexts,
'\n'
,
'\0'
);
126
}
BITMAPS::text
@ text
BITMAPS::pin
@ pin
EDA_ITEM
A base class for most all the KiCad significant classes used in schematics and boards.
Definition:
eda_item.h:89
EDA_ITEM::Type
KICAD_T Type() const
Returns the type of object.
Definition:
eda_item.h:101
SCH_FIELD
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition:
sch_field.h:51
SCH_FIELD::GetShownText
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
Definition:
sch_field.cpp:209
SCH_ITEM
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition:
sch_item.h:166
SCH_PIN
Definition:
sch_pin.h:39
SCH_TABLECELL
Definition:
sch_tablecell.h:32
SCH_TABLE
Definition:
sch_table.h:33
SCH_TABLE::GetColCount
int GetColCount() const
Definition:
sch_table.h:104
SCH_TABLE::GetCell
SCH_TABLECELL * GetCell(int aRow, int aCol) const
Definition:
sch_table.h:131
SCH_TABLE::GetRowCount
int GetRowCount() const
Definition:
sch_table.h:106
SCH_TEXTBOX
Definition:
sch_textbox.h:36
SCH_TEXTBOX::GetShownText
virtual wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
Definition:
sch_textbox.cpp:344
SCH_TEXT
Definition:
sch_text.h:38
SELECTION
Definition:
selection.h:39
GetSelectedItemsAsText
wxString GetSelectedItemsAsText(const SELECTION &aSel)
Definition:
ee_tool_utils.cpp:105
GetSchItemAsText
wxString GetSchItemAsText(const SCH_ITEM &aItem)
Definition:
ee_tool_utils.cpp:35
ee_tool_utils.h
sch_field.h
sch_pin.h
sch_table.h
sch_tablecell.h
sch_text.h
sch_textbox.h
SCH_TABLE_T
@ SCH_TABLE_T
Definition:
typeinfo.h:165
SCH_TABLECELL_T
@ SCH_TABLECELL_T
Definition:
typeinfo.h:166
SCH_FIELD_T
@ SCH_FIELD_T
Definition:
typeinfo.h:150
SCH_DIRECTIVE_LABEL_T
@ SCH_DIRECTIVE_LABEL_T
Definition:
typeinfo.h:171
SCH_LABEL_T
@ SCH_LABEL_T
Definition:
typeinfo.h:167
SCH_HIER_LABEL_T
@ SCH_HIER_LABEL_T
Definition:
typeinfo.h:169
SCH_SHEET_PIN_T
@ SCH_SHEET_PIN_T
Definition:
typeinfo.h:173
SCH_TEXT_T
@ SCH_TEXT_T
Definition:
typeinfo.h:151
SCH_TEXTBOX_T
@ SCH_TEXTBOX_T
Definition:
typeinfo.h:152
SCH_GLOBAL_LABEL_T
@ SCH_GLOBAL_LABEL_T
Definition:
typeinfo.h:168
SCH_PIN_T
@ SCH_PIN_T
Definition:
typeinfo.h:153
src
eeschema
tools
ee_tool_utils.cpp
Generated on Fri Oct 25 2024 00:04:51 for KiCad PCB EDA Suite by
1.9.6