KiCad PCB EDA Suite
sch_sexpr_plugin.cpp File Reference
#include <algorithm>
#include <boost/algorithm/string/join.hpp>
#include <cctype>
#include <wx/base64.h>
#include <wx/mstream.h>
#include <wx/filename.h>
#include <wx/tokenzr.h>
#include <advanced_config.h>
#include <build_version.h>
#include <gal/color4d.h>
#include <pgm_base.h>
#include <gr_text.h>
#include <kiway.h>
#include <kicad_string.h>
#include <richio.h>
#include <core/typeinfo.h>
#include <plotter.h>
#include <properties.h>
#include <trace_helpers.h>
#include <sch_bitmap.h>
#include <sch_bus_entry.h>
#include <sch_component.h>
#include <sch_edit_frame.h>
#include <sch_junction.h>
#include <sch_line.h>
#include <sch_marker.h>
#include <sch_no_connect.h>
#include <sch_text.h>
#include <sch_sheet.h>
#include <schematic.h>
#include <bus_alias.h>
#include <sch_sexpr_plugin.h>
#include <template_fieldnames.h>
#include <sch_screen.h>
#include <class_libentry.h>
#include <class_library.h>
#include <lib_arc.h>
#include <lib_bezier.h>
#include <lib_circle.h>
#include <lib_field.h>
#include <lib_pin.h>
#include <lib_polyline.h>
#include <lib_rectangle.h>
#include <lib_text.h>
#include <pin_shape.h>
#include <pin_type.h>
#include <eeschema_id.h>
#include <sch_file_versions.h>
#include <schematic_lexer.h>
#include <sch_reference_list.h>
#include <sch_sexpr_parser.h>
#include <symbol_lib_table.h>
#include <confirm.h>
#include <ee_selection.h>
#include <default_values.h>

Go to the source code of this file.

Classes

class  SCH_SEXPR_PLUGIN_CACHE
 A cache assistant for the part library portion of the SCH_PLUGIN API, and only for the SCH_SEXPR_PLUGIN, so therefore is private to this implementation file, i.e. More...
 

Macros

#define wxUSE_BASE64   1
 
#define SCH_PARSE_ERROR(text, reader, pos)
 
#define MIME_BASE64_LENGTH   76
 

Functions

static void formatFill (const LIB_ITEM *aItem, OUTPUTFORMATTER &aFormatter, int aNestLevel)
 Fill token formatting helper. More...
 
static const char * getPinElectricalTypeToken (ELECTRICAL_PINTYPE aType)
 
static const char * getPinShapeToken (GRAPHIC_PINSHAPE aShape)
 
static float getPinAngle (int aOrientation)
 
static const char * getSheetPinShapeToken (PINSHEETLABEL_SHAPE aShape)
 
static double getSheetPinAngle (SHEET_SIDE aSide)
 
static wxString getLineStyleToken (PLOT_DASH_TYPE aStyle)
 
static const char * getTextTypeToken (KICAD_T aType)
 
static void formatStroke (OUTPUTFORMATTER *aFormatter, int aNestLevel, const STROKE_PARAMS &aStroke)
 Write stroke definition to aFormatter. More...
 

Variables

static const char * emptyString = ""
 

Macro Definition Documentation

◆ MIME_BASE64_LENGTH

#define MIME_BASE64_LENGTH   76

◆ SCH_PARSE_ERROR

#define SCH_PARSE_ERROR (   text,
  reader,
  pos 
)
Value:
THROW_PARSE_ERROR( text, reader.GetSource(), reader.Line(), \
reader.LineNumber(), pos - reader.Line() )
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:162

Definition at line 89 of file sch_sexpr_plugin.cpp.

◆ wxUSE_BASE64

#define wxUSE_BASE64   1

Definition at line 28 of file sch_sexpr_plugin.cpp.

Function Documentation

◆ formatFill()

static void formatFill ( const LIB_ITEM aItem,
OUTPUTFORMATTER aFormatter,
int  aNestLevel 
)
static

Fill token formatting helper.

Definition at line 99 of file sch_sexpr_plugin.cpp.

100 {
101  wxCHECK_RET( aItem && aItem->IsFillable(), "Invalid fill item." );
102 
103  const char* fillType;
104 
105  switch( aItem->GetFillMode() )
106  {
107  case FILLED_SHAPE: fillType = "outline"; break;
108  case FILLED_WITH_BG_BODYCOLOR: fillType = "background"; break;
109  case NO_FILL:
111  default:
112  fillType = "none";
113  }
114 
115  aFormatter.Print( aNestLevel, "(fill (type %s))", fillType );
116 }
FILL_T GetFillMode() const
Definition: lib_item.h:301
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition: macros.h:88
bool IsFillable() const
Check if draw object can be filled.
Definition: lib_item.h:292
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404

References FILLED_SHAPE, FILLED_WITH_BG_BODYCOLOR, LIB_ITEM::GetFillMode(), LIB_ITEM::IsFillable(), KI_FALLTHROUGH, NO_FILL, and OUTPUTFORMATTER::Print().

Referenced by SCH_SEXPR_PLUGIN_CACHE::saveArc(), SCH_SEXPR_PLUGIN_CACHE::saveBezier(), SCH_SEXPR_PLUGIN_CACHE::saveCircle(), SCH_SEXPR_PLUGIN_CACHE::savePolyLine(), and SCH_SEXPR_PLUGIN_CACHE::saveRectangle().

◆ formatStroke()

static void formatStroke ( OUTPUTFORMATTER aFormatter,
int  aNestLevel,
const STROKE_PARAMS aStroke 
)
static

Write stroke definition to aFormatter.

This only writes the stroke definition if aWidth, aStyle and aColor are not the default setting or are not defined.

Parameters
aFormatterA pointer to the OUTPUTFORMATTER object to write to.
aNestLevelThe nest level to indent the stroke definition.
aWidthThe stroke line width in internal units.
aStyleThe stroke line style.
aColorThe stroke line color.

Definition at line 301 of file sch_sexpr_plugin.cpp.

303 {
304  wxASSERT( aFormatter != nullptr );
305 
306  aFormatter->Print( aNestLevel, "(stroke (width %s) (type %s) (color %d %d %d %s))",
307  FormatInternalUnits( aStroke.GetWidth() ).c_str(),
308  TO_UTF8( getLineStyleToken( aStroke.GetType() ) ),
309  KiROUND( aStroke.GetColor().r * 255.0 ),
310  KiROUND( aStroke.GetColor().g * 255.0 ),
311  KiROUND( aStroke.GetColor().b * 255.0 ),
312  Double2Str( aStroke.GetColor().a ).c_str() );
313 }
double g
Green component.
Definition: color4d.h:367
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:62
double b
Blue component.
Definition: color4d.h:368
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:100
double a
Alpha component.
Definition: color4d.h:369
static wxString getLineStyleToken(PLOT_DASH_TYPE aStyle)
int GetWidth() const
Definition: sch_item.h:169
COLOR4D GetColor() const
Definition: sch_item.h:175
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
PLOT_DASH_TYPE GetType() const
Definition: sch_item.h:172
double r
Red component.
Definition: color4d.h:366
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:560

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, Double2Str(), FormatInternalUnits(), KIGFX::COLOR4D::g, STROKE_PARAMS::GetColor(), getLineStyleToken(), STROKE_PARAMS::GetType(), STROKE_PARAMS::GetWidth(), KiROUND(), OUTPUTFORMATTER::Print(), KIGFX::COLOR4D::r, and TO_UTF8.

Referenced by SCH_SEXPR_PLUGIN::saveBusEntry(), SCH_SEXPR_PLUGIN::saveLine(), and SCH_SEXPR_PLUGIN::saveSheet().

◆ getLineStyleToken()

static wxString getLineStyleToken ( PLOT_DASH_TYPE  aStyle)
static

Definition at line 259 of file sch_sexpr_plugin.cpp.

260 {
261  wxString token;
262 
263  switch( aStyle )
264  {
265  case PLOT_DASH_TYPE::DASH: token = "dash"; break;
266  case PLOT_DASH_TYPE::DOT: token = "dot"; break;
267  case PLOT_DASH_TYPE::DASHDOT: token = "dash_dot"; break;
269  default: token = "solid"; break;
270  }
271 
272  return token;
273 }

References DASH, DASHDOT, DOT, and SOLID.

Referenced by formatStroke().

◆ getPinAngle()

static float getPinAngle ( int  aOrientation)
static

Definition at line 203 of file sch_sexpr_plugin.cpp.

204 {
205  switch( aOrientation )
206  {
207  case PIN_RIGHT:
208  return 0.0;
209 
210  case PIN_LEFT:
211  return 180.0;
212 
213  case PIN_UP:
214  return 90.0;
215 
216  case PIN_DOWN:
217  return 270.0;
218 
219  default:
220  wxFAIL_MSG( "Missing symbol library pin orientation type" );
221 
222  return 0.0;
223  }
224 }
Definition: lib_pin.h:55

References PIN_DOWN, PIN_LEFT, PIN_RIGHT, and PIN_UP.

Referenced by SCH_SEXPR_PLUGIN_CACHE::savePin().

◆ getPinElectricalTypeToken()

static const char* getPinElectricalTypeToken ( ELECTRICAL_PINTYPE  aType)
static

Definition at line 119 of file sch_sexpr_plugin.cpp.

120 {
121  switch( aType )
122  {
124  return SCHEMATIC_LEXER::TokenName( T_input );
125 
127  return SCHEMATIC_LEXER::TokenName( T_output );
128 
130  return SCHEMATIC_LEXER::TokenName( T_bidirectional );
131 
133  return SCHEMATIC_LEXER::TokenName( T_tri_state );
134 
136  return SCHEMATIC_LEXER::TokenName( T_passive );
137 
139  return SCHEMATIC_LEXER::TokenName( T_unspecified );
140 
142  return SCHEMATIC_LEXER::TokenName( T_power_in );
143 
145  return SCHEMATIC_LEXER::TokenName( T_power_out );
146 
148  return SCHEMATIC_LEXER::TokenName( T_open_collector );
149 
151  return SCHEMATIC_LEXER::TokenName( T_open_emitter );
152 
154  return SCHEMATIC_LEXER::TokenName( T_unconnected );
155 
156  default:
157  wxFAIL_MSG( "Missing symbol library pin connection type" );
158  }
159 
160  return emptyString;
161 }
power input (GND, VCC for ICs). Must be connected to a power output.
pin for passive components: must be connected, and can be connected to any pin
unknown electrical properties: creates always a warning when connected
static const char * emptyString
usual pin input: must be connected
input or output (like port for a microprocessor)
not connected (must be left open)
output of a regulator: intended to be connected to power input pins

References emptyString, PT_BIDI, PT_INPUT, PT_NC, PT_OPENCOLLECTOR, PT_OPENEMITTER, PT_OUTPUT, PT_PASSIVE, PT_POWER_IN, PT_POWER_OUT, PT_TRISTATE, and PT_UNSPECIFIED.

Referenced by SCH_SEXPR_PLUGIN_CACHE::savePin().

◆ getPinShapeToken()

static const char* getPinShapeToken ( GRAPHIC_PINSHAPE  aShape)
static

Definition at line 164 of file sch_sexpr_plugin.cpp.

165 {
166  switch( aShape )
167  {
169  return SCHEMATIC_LEXER::TokenName( T_line );
170 
172  return SCHEMATIC_LEXER::TokenName( T_inverted );
173 
175  return SCHEMATIC_LEXER::TokenName( T_clock );
176 
178  return SCHEMATIC_LEXER::TokenName( T_inverted_clock );
179 
181  return SCHEMATIC_LEXER::TokenName( T_input_low );
182 
184  return SCHEMATIC_LEXER::TokenName( T_clock_low );
185 
187  return SCHEMATIC_LEXER::TokenName( T_output_low );
188 
190  return SCHEMATIC_LEXER::TokenName( T_edge_clock_high );
191 
193  return SCHEMATIC_LEXER::TokenName( T_non_logic );
194 
195  default:
196  wxFAIL_MSG( "Missing symbol library pin shape type" );
197  }
198 
199  return emptyString;
200 }
static const char * emptyString

References CLOCK, CLOCK_LOW, emptyString, FALLING_EDGE_CLOCK, INPUT_LOW, INVERTED, INVERTED_CLOCK, LINE, NONLOGIC, and OUTPUT_LOW.

Referenced by SCH_SEXPR_PLUGIN_CACHE::savePin().

◆ getSheetPinAngle()

static double getSheetPinAngle ( SHEET_SIDE  aSide)
static

Definition at line 241 of file sch_sexpr_plugin.cpp.

242 {
243  double retv;
244 
245  switch( aSide )
246  {
248  case SHEET_LEFT_SIDE: retv = 180.0; break;
249  case SHEET_RIGHT_SIDE: retv = 0.0; break;
250  case SHEET_TOP_SIDE: retv = 90.0; break;
251  case SHEET_BOTTOM_SIDE: retv = 270.0; break;
252  default: wxFAIL; retv = 0.0; break;
253  }
254 
255  return retv;
256 }

References SHEET_BOTTOM_SIDE, SHEET_LEFT_SIDE, SHEET_RIGHT_SIDE, SHEET_TOP_SIDE, and SHEET_UNDEFINED_SIDE.

Referenced by SCH_SEXPR_PLUGIN::saveSheet().

◆ getSheetPinShapeToken()

static const char* getSheetPinShapeToken ( PINSHEETLABEL_SHAPE  aShape)
static

Definition at line 227 of file sch_sexpr_plugin.cpp.

228 {
229  switch( aShape )
230  {
231  case PINSHEETLABEL_SHAPE::PS_INPUT: return SCHEMATIC_LEXER::TokenName( T_input );
232  case PINSHEETLABEL_SHAPE::PS_OUTPUT: return SCHEMATIC_LEXER::TokenName( T_output );
233  case PINSHEETLABEL_SHAPE::PS_BIDI: return SCHEMATIC_LEXER::TokenName( T_bidirectional );
234  case PINSHEETLABEL_SHAPE::PS_TRISTATE: return SCHEMATIC_LEXER::TokenName( T_tri_state );
235  case PINSHEETLABEL_SHAPE::PS_UNSPECIFIED: return SCHEMATIC_LEXER::TokenName( T_passive );
236  default: wxFAIL; return SCHEMATIC_LEXER::TokenName( T_passive );
237  }
238 }

References PS_BIDI, PS_INPUT, PS_OUTPUT, PS_TRISTATE, and PS_UNSPECIFIED.

Referenced by SCH_SEXPR_PLUGIN::saveSheet(), and SCH_SEXPR_PLUGIN::saveText().

◆ getTextTypeToken()

static const char* getTextTypeToken ( KICAD_T  aType)
static

Definition at line 276 of file sch_sexpr_plugin.cpp.

277 {
278  switch( aType )
279  {
280  case SCH_TEXT_T: return SCHEMATIC_LEXER::TokenName( T_text );
281  case SCH_LABEL_T: return SCHEMATIC_LEXER::TokenName( T_label );
282  case SCH_GLOBAL_LABEL_T: return SCHEMATIC_LEXER::TokenName( T_global_label );
283  case SCH_HIER_LABEL_T: return SCHEMATIC_LEXER::TokenName( T_hierarchical_label );
284  default: wxFAIL; return SCHEMATIC_LEXER::TokenName( T_text );
285  }
286 }

References SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_LABEL_T, and SCH_TEXT_T.

Referenced by SCH_SEXPR_PLUGIN::saveText().

Variable Documentation

◆ emptyString

const char* emptyString = ""
static