KiCad PCB EDA Suite
Loading...
Searching...
No Matches
idf_helpers.h
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) 2014-2017 Cirilo Bernardo
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef IDF_HELPERS_H
22#define IDF_HELPERS_H
23
24#include <wx/string.h>
25#include <iostream>
26#include <string>
27#include <io/idf/idf_common.h>
28
37#define TO_UTF8( wxstring ) ( (const char*) (wxstring).utf8_str() )
38
44static inline wxString From_UTF8( const char* cstring )
45{
46 wxString line = wxString::FromUTF8( cstring );
47
48 if( line.IsEmpty() ) // happens when cstring is not a valid UTF8 sequence
49 line = wxConvCurrent->cMB2WC( cstring ); // try to use locale conversion
50
51 return line;
52}
53
54
55#define ERROR_IDF std::cerr << "* " << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "(): "
56
57// minimum drill diameters / slot widths to be represented in the IDF output
58#define IDF_MIN_DIA_MM ( 0.001 )
59#define IDF_MIN_DIA_THOU ( 0.00039 )
60#define IDF_MIN_DIA_TNM ( 100 )
61
62// conversion from thou to mm
63#define IDF_THOU_TO_MM 0.0254
64// conversion from TNM to mm
65#define IDF_TNM_TO_MM 0.00001
66
67namespace IDF3
68{
69
83bool FetchIDFLine( std::istream& aModel, std::string& aLine, bool& isComment,
84 std::streampos& aFilePos );
85
86
97bool GetIDFString( const std::string& aLine, std::string& aIDFString, bool& hasQuotes,
98 int& aIndex );
99
107bool CompareToken( const char* aTokenString, const std::string& aInputString );
108
109
117bool ParseOwner( const std::string& aToken, IDF3::KEY_OWNER& aOwner );
118
119
127bool ParseIDFLayer( const std::string& aToken, IDF3::IDF_LAYER& aLayer );
128
129
137bool WriteLayersText( std::ostream& aBoardFile, IDF3::IDF_LAYER aLayer );
138
139
146std::string GetPlacementString( IDF3::IDF_PLACEMENT aPlacement );
147
148
155std::string GetLayerString( IDF3::IDF_LAYER aLayer );
156
157std::string GetOwnerString( IDF3::KEY_OWNER aOwner );
158}
159
160#endif // IDF_HELPERS_H
static wxString From_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition idf_helpers.h:44
std::string GetPlacementString(IDF3::IDF_PLACEMENT aPlacement)
Return a string representing the given IDF Placement type.
bool ParseIDFLayer(const std::string &aToken, IDF3::IDF_LAYER &aLayer)
Parse an input string for a valid IDF layer specification.
IDF_PLACEMENT
The placement status of a component.
Definition idf_common.h:188
bool GetIDFString(const std::string &aLine, std::string &aIDFString, bool &hasQuotes, int &aIndex)
Parse a line retrieved via FetchIDFLine() and returns the first IDF string found from the starting po...
std::string GetOwnerString(IDF3::KEY_OWNER aOwner)
bool FetchIDFLine(std::istream &aModel, std::string &aLine, bool &isComment, std::streampos &aFilePos)
Retrieve a single line from an IDF file and performs minimal processing.
bool CompareToken(const char *aTokenString, const std::string &aInputString)
Perform a case-insensitive comparison of a token string and an input string.
IDF_LAYER
The various IDF layer classes and groupings.
Definition idf_common.h:137
KEY_OWNER
The type of CAD which has ownership an object.
Definition idf_common.h:85
bool WriteLayersText(std::ostream &aBoardFile, IDF3::IDF_LAYER aLayer)
Write out text corresponding to the given IDF Layer type.
bool ParseOwner(const std::string &aToken, IDF3::KEY_OWNER &aOwner)
Parse the input string for a valid IDF Owner type.
std::string GetLayerString(IDF3::IDF_LAYER aLayer)
Return a string representing the given IDF Layer type.