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 <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, int aWidth, PLOT_DASH_TYPE aStyle, const COLOR4D &aColor)
 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 at line 88 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 98 of file sch_sexpr_plugin.cpp.

99 {
100  wxCHECK_RET( aItem && aItem->IsFillable(), "Invalid fill item." );
101 
102  const char* fillType;
103 
104  switch( aItem->GetFillMode() )
105  {
106  case FILLED_SHAPE: fillType = "outline"; break;
107  case FILLED_WITH_BG_BODYCOLOR: fillType = "background"; break;
108  case NO_FILL:
110  default:
111  fillType = "none";
112  }
113 
114  aFormatter.Print( aNestLevel, "(fill (type %s))", fillType );
115 }
#define KI_FALLTHROUGH
FILL_T GetFillMode() const
Definition: lib_item.h:301
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,
int  aWidth,
PLOT_DASH_TYPE  aStyle,
const COLOR4D aColor 
)
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 300 of file sch_sexpr_plugin.cpp.

302 {
303  wxASSERT( aFormatter != nullptr );
304 
305  aFormatter->Print( aNestLevel, "(stroke (width %s) (type %s) (color %d %d %d %s))",
306  FormatInternalUnits( aWidth ).c_str(),
307  TO_UTF8( getLineStyleToken( aStyle ) ),
308  KiROUND( aColor.r * 255.0 ),
309  KiROUND( aColor.g * 255.0 ),
310  KiROUND( aColor.b * 255.0 ),
311  Double2Str( aColor.a ).c_str() );
312 }
double g
Green component.
Definition: color4d.h:303
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:304
double a
Alpha component.
Definition: color4d.h:305
static wxString getLineStyleToken(PLOT_DASH_TYPE aStyle)
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:61
#define TO_UTF8(wxstring)
double r
Red component.
Definition: color4d.h:302
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:531

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

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

◆ getLineStyleToken()

static wxString getLineStyleToken ( PLOT_DASH_TYPE  aStyle)
static

Definition at line 258 of file sch_sexpr_plugin.cpp.

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

References DASH, DASHDOT, DOT, and SOLID.

Referenced by formatStroke().

◆ getPinAngle()

static float getPinAngle ( int  aOrientation)
static

Definition at line 202 of file sch_sexpr_plugin.cpp.

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

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 118 of file sch_sexpr_plugin.cpp.

119 {
120  switch( aType )
121  {
123  return SCHEMATIC_LEXER::TokenName( T_input );
124 
126  return SCHEMATIC_LEXER::TokenName( T_output );
127 
129  return SCHEMATIC_LEXER::TokenName( T_bidirectional );
130 
132  return SCHEMATIC_LEXER::TokenName( T_tri_state );
133 
135  return SCHEMATIC_LEXER::TokenName( T_passive );
136 
138  return SCHEMATIC_LEXER::TokenName( T_unspecified );
139 
141  return SCHEMATIC_LEXER::TokenName( T_power_in );
142 
144  return SCHEMATIC_LEXER::TokenName( T_power_out );
145 
147  return SCHEMATIC_LEXER::TokenName( T_open_collector );
148 
150  return SCHEMATIC_LEXER::TokenName( T_open_emitter );
151 
153  return SCHEMATIC_LEXER::TokenName( T_unconnected );
154 
155  default:
156  wxFAIL_MSG( "Missing symbol library pin connection type" );
157  }
158 
159  return emptyString;
160 }
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 163 of file sch_sexpr_plugin.cpp.

164 {
165  switch( aShape )
166  {
168  return SCHEMATIC_LEXER::TokenName( T_line );
169 
171  return SCHEMATIC_LEXER::TokenName( T_inverted );
172 
174  return SCHEMATIC_LEXER::TokenName( T_clock );
175 
177  return SCHEMATIC_LEXER::TokenName( T_inverted_clock );
178 
180  return SCHEMATIC_LEXER::TokenName( T_input_low );
181 
183  return SCHEMATIC_LEXER::TokenName( T_clock_low );
184 
186  return SCHEMATIC_LEXER::TokenName( T_output_low );
187 
189  return SCHEMATIC_LEXER::TokenName( T_edge_clock_high );
190 
192  return SCHEMATIC_LEXER::TokenName( T_non_logic );
193 
194  default:
195  wxFAIL_MSG( "Missing symbol library pin shape type" );
196  }
197 
198  return emptyString;
199 }
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 240 of file sch_sexpr_plugin.cpp.

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

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 226 of file sch_sexpr_plugin.cpp.

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

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 275 of file sch_sexpr_plugin.cpp.

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

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