2012-12-29 09:54:25 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
|
|
|
|
* Copyright (C) 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
|
2021-07-19 23:56:05 +00:00
|
|
|
* Copyright (C) 2012-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-12-29 09:54:25 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file pcad2kicad_common.cpp
|
|
|
|
*/
|
|
|
|
|
2021-06-04 00:28:40 +00:00
|
|
|
#include <pcad/pcad2kicad_common.h>
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
#include <common.h>
|
2015-05-15 12:49:11 +00:00
|
|
|
#include <convert_to_biu.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2021-06-04 00:28:40 +00:00
|
|
|
#include <xnode.h>
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2021-06-04 00:28:40 +00:00
|
|
|
#include <wx/regex.h>
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
namespace PCAD2KICAD {
|
|
|
|
|
2016-02-27 17:33:38 +00:00
|
|
|
// PCAD stroke font average ratio of width to size
|
2017-12-12 18:21:44 +00:00
|
|
|
const double TEXT_WIDTH_TO_SIZE_AVERAGE = 0.5;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2016-02-27 17:33:38 +00:00
|
|
|
// PCAD proportions of stroke font
|
2017-12-12 18:21:44 +00:00
|
|
|
const double STROKE_HEIGHT_TO_SIZE = 0.656;
|
|
|
|
const double STROKE_WIDTH_TO_SIZE = 0.69;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2017-12-12 18:21:44 +00:00
|
|
|
// TrueType font
|
|
|
|
const double TRUETYPE_HEIGHT_TO_SIZE = 0.585;
|
|
|
|
const double TRUETYPE_WIDTH_TO_SIZE = 0.585;
|
|
|
|
const double TRUETYPE_THICK_PER_HEIGHT = 0.073;
|
|
|
|
const double TRUETYPE_BOLD_THICK_MUL = 1.6;
|
2017-12-10 09:21:43 +00:00
|
|
|
const long TRUETYPE_BOLD_MIN_WEIGHT = 700;
|
2016-02-24 11:56:40 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2012-12-29 09:54:25 +00:00
|
|
|
wxString GetWord( wxString* aStr )
|
|
|
|
{
|
|
|
|
wxString result = wxEmptyString;
|
|
|
|
|
|
|
|
*aStr = aStr->Trim( false );
|
|
|
|
|
|
|
|
if( aStr->Len() == 0 )
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if( (*aStr)[0] == wxT( '"' ) )
|
|
|
|
{
|
|
|
|
result += (*aStr)[0];
|
|
|
|
*aStr = aStr->Mid( 1 ); // remove Frot apostrofe
|
|
|
|
|
|
|
|
while( aStr->Len() > 0 && (*aStr)[0] != wxT( '"' ) )
|
|
|
|
{
|
|
|
|
result += (*aStr)[0];
|
|
|
|
*aStr = aStr->Mid( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aStr->Len() > 0 && (*aStr)[0] == wxT( '"' ) )
|
|
|
|
{
|
|
|
|
result += (*aStr)[0];
|
|
|
|
*aStr = aStr->Mid( 1 ); // remove ending apostrophe
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while( aStr->Len() > 0
|
|
|
|
&& !( (*aStr)[0] == wxT( ' ' )
|
|
|
|
|| (*aStr)[0] == wxT( '(' )
|
|
|
|
|| (*aStr)[0] == wxT( ')' ) ) )
|
|
|
|
{
|
|
|
|
result += (*aStr)[0];
|
|
|
|
*aStr = aStr->Mid( 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result.Trim( true );
|
|
|
|
result.Trim( false );
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
XNODE* FindPinMap( XNODE* aNode )
|
|
|
|
{
|
|
|
|
XNODE* result, * lNode;
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
result = nullptr;
|
2012-12-29 09:54:25 +00:00
|
|
|
lNode = FindNode( aNode, wxT( "attachedPattern" ) );
|
|
|
|
|
|
|
|
if( lNode )
|
|
|
|
result = FindNode( lNode, wxT( "padPinMap" ) );
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
double StrToDoublePrecisionUnits( const wxString& aStr, char aAxe,
|
|
|
|
const wxString& aActualConversion )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
wxString ls;
|
|
|
|
double i;
|
|
|
|
char u;
|
|
|
|
|
|
|
|
ls = aStr;
|
|
|
|
ls.Trim( true );
|
|
|
|
ls.Trim( false );
|
|
|
|
|
|
|
|
if( ls.Len() > 0 )
|
|
|
|
{
|
|
|
|
u = ls[ls.Len() - 1];
|
|
|
|
|
|
|
|
while( ls.Len() > 0
|
|
|
|
&& !( ls[ls.Len() - 1] == wxT( '.' )
|
|
|
|
|| ls[ls.Len() - 1] == wxT( ',' )
|
|
|
|
|| (ls[ls.Len() - 1] >= wxT( '0' ) && ls[ls.Len() - 1] <= wxT( '9' ) ) ) )
|
|
|
|
{
|
|
|
|
ls = ls.Left( ls.Len() - 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
while( ls.Len() > 0
|
|
|
|
&& !( ls[0] == wxT( '-' )
|
|
|
|
|| ls[0] == wxT( '+' )
|
|
|
|
|| ls[0] == wxT( '.' )
|
|
|
|
|| ls[0] == wxT( ',' )
|
|
|
|
|| (ls[0] >= wxT( '0' ) && ls[0] <= wxT( '9' ) ) ) )
|
|
|
|
{
|
|
|
|
ls = ls.Mid( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( u == wxT( 'm' ) )
|
|
|
|
{
|
2020-07-12 13:26:36 +00:00
|
|
|
ls.ToCDouble( &i );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2012-12-29 09:54:25 +00:00
|
|
|
#ifdef PCAD2KICAD_SCALE_SCH_TO_INCH_GRID
|
2013-06-12 19:43:22 +00:00
|
|
|
if( aActualConversion == wxT( "SCH" )
|
|
|
|
|| aActualConversion == wxT( "SCHLIB" ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
i = i * (0.0254 / 0.025);
|
|
|
|
#endif
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2012-12-29 09:54:25 +00:00
|
|
|
i = Millimeter2iu( i );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-12 13:26:36 +00:00
|
|
|
ls.ToCDouble( &i );
|
2022-04-21 08:01:21 +00:00
|
|
|
i *= IU_PER_MILS;
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2012-12-29 09:54:25 +00:00
|
|
|
i = 0.0;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
if( ( aActualConversion == wxT( "PCB" ) || aActualConversion == wxT( "SCH" ) )
|
|
|
|
&& aAxe == wxT( 'Y' ) )
|
|
|
|
return -i;
|
|
|
|
else
|
|
|
|
return i; // Y axe is mirrored compared to P-Cad
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
int StrToIntUnits( const wxString& aStr, char aAxe, const wxString& aActualConversion )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
return KiROUND( StrToDoublePrecisionUnits( aStr, aAxe, aActualConversion ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
wxString GetAndCutWordWithMeasureUnits( wxString* aStr, const wxString& aDefaultMeasurementUnit )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2015-11-04 08:48:34 +00:00
|
|
|
wxString result;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
aStr->Trim( false );
|
|
|
|
result = wxEmptyString;
|
|
|
|
|
|
|
|
// value
|
|
|
|
while( aStr->Len() > 0 && (*aStr)[0] != wxT( ' ' ) )
|
|
|
|
{
|
|
|
|
result += (*aStr)[0];
|
|
|
|
*aStr = aStr->Mid( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
aStr->Trim( false );
|
|
|
|
|
|
|
|
// if there is also measurement unit
|
|
|
|
while( aStr->Len() > 0
|
|
|
|
&& ( ( (*aStr)[0] >= wxT( 'a' ) && (*aStr)[0] <= wxT( 'z' ) )
|
|
|
|
|| ( (*aStr)[0] >= wxT( 'A' ) && (*aStr)[0] <= wxT( 'Z' ) ) ) )
|
|
|
|
{
|
|
|
|
result += (*aStr)[0];
|
|
|
|
*aStr = aStr->Mid( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
// and if not, add default....
|
|
|
|
if( result.Len() > 0
|
|
|
|
&& ( result[result.Len() - 1] == wxT( '.' )
|
|
|
|
|| result[result.Len() - 1] == wxT( ',' )
|
|
|
|
|| (result[result.Len() - 1] >= wxT( '0' )
|
|
|
|
&& result[result.Len() - 1] <= wxT( '9' ) ) ) )
|
|
|
|
{
|
|
|
|
result += aDefaultMeasurementUnit;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
int StrToInt1Units( const wxString& aStr )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
double num, precision = 10;
|
|
|
|
|
2020-07-12 13:26:36 +00:00
|
|
|
aStr.ToCDouble( &num );
|
2012-12-29 09:54:25 +00:00
|
|
|
return KiROUND( num * precision );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-27 12:22:27 +00:00
|
|
|
wxString ValidateName( const wxString& aName )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2021-07-27 12:22:27 +00:00
|
|
|
wxString retv = aName;
|
|
|
|
retv.Replace( wxT( " " ), wxT( "_" ) );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2021-07-27 12:22:27 +00:00
|
|
|
return retv;
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-27 12:22:27 +00:00
|
|
|
wxString ValidateReference( const wxString& aRef )
|
2017-12-10 08:12:10 +00:00
|
|
|
{
|
|
|
|
wxRegEx reRef;
|
|
|
|
reRef.Compile( wxT( "^[[:digit:]][[:digit:]]*$" ) );
|
|
|
|
|
2021-07-27 12:22:27 +00:00
|
|
|
wxString retv = aRef;
|
2017-12-10 08:12:10 +00:00
|
|
|
|
2021-07-27 12:22:27 +00:00
|
|
|
if( reRef.Matches( retv ) )
|
|
|
|
retv.Prepend( wxT( '.' ) );
|
|
|
|
|
|
|
|
return retv;
|
2017-12-10 08:12:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-27 12:22:27 +00:00
|
|
|
void SetWidth( const wxString& aStr, const wxString& aDefaultMeasurementUnit, int* aWidth,
|
2017-09-23 09:20:10 +00:00
|
|
|
const wxString& aActualConversion )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2021-07-27 12:22:27 +00:00
|
|
|
wxString tmp = aStr;
|
|
|
|
|
|
|
|
*aWidth = StrToIntUnits( GetAndCutWordWithMeasureUnits( &tmp, aDefaultMeasurementUnit ),
|
2021-07-19 23:56:05 +00:00
|
|
|
wxT( ' ' ), aActualConversion );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-27 12:22:27 +00:00
|
|
|
void SetHeight( const wxString& aStr, const wxString& aDefaultMeasurementUnit, int* aHeight,
|
2017-09-23 09:20:10 +00:00
|
|
|
const wxString& aActualConversion )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2021-07-27 12:22:27 +00:00
|
|
|
wxString tmp = aStr;
|
|
|
|
|
|
|
|
*aHeight = StrToIntUnits( GetAndCutWordWithMeasureUnits( &tmp, aDefaultMeasurementUnit ),
|
2021-07-19 23:56:05 +00:00
|
|
|
wxT( ' ' ), aActualConversion );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-27 12:22:27 +00:00
|
|
|
void SetPosition( const wxString& aStr, const wxString& aDefaultMeasurementUnit, int* aX, int* aY,
|
2017-09-23 09:20:10 +00:00
|
|
|
const wxString& aActualConversion )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2021-07-27 12:22:27 +00:00
|
|
|
wxString tmp = aStr;
|
|
|
|
|
|
|
|
*aX = StrToIntUnits( GetAndCutWordWithMeasureUnits( &tmp, aDefaultMeasurementUnit ),
|
2021-07-19 23:56:05 +00:00
|
|
|
wxT( 'X' ), aActualConversion );
|
2021-07-27 12:22:27 +00:00
|
|
|
*aY = StrToIntUnits( GetAndCutWordWithMeasureUnits( &tmp, aDefaultMeasurementUnit ),
|
2021-07-19 23:56:05 +00:00
|
|
|
wxT( 'Y' ), aActualConversion );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-27 12:22:27 +00:00
|
|
|
void SetDoublePrecisionPosition( const wxString& aStr, const wxString& aDefaultMeasurementUnit,
|
|
|
|
double* aX, double* aY, const wxString& aActualConversion )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2021-07-27 12:22:27 +00:00
|
|
|
wxString tmp = aStr;
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
*aX = StrToDoublePrecisionUnits(
|
2021-07-27 12:22:27 +00:00
|
|
|
GetAndCutWordWithMeasureUnits( &tmp, aDefaultMeasurementUnit ), wxT( 'X' ),
|
2021-07-19 23:56:05 +00:00
|
|
|
aActualConversion );
|
|
|
|
*aY = StrToDoublePrecisionUnits(
|
2021-07-27 12:22:27 +00:00
|
|
|
GetAndCutWordWithMeasureUnits( &tmp, aDefaultMeasurementUnit ), wxT( 'Y' ),
|
2021-07-19 23:56:05 +00:00
|
|
|
aActualConversion );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
2017-12-10 09:21:43 +00:00
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
TTEXT_JUSTIFY GetJustifyIdentificator( const wxString& aJustify )
|
2016-02-24 11:56:40 +00:00
|
|
|
{
|
|
|
|
TTEXT_JUSTIFY id;
|
|
|
|
|
2022-05-27 17:08:27 +00:00
|
|
|
if( aJustify.IsSameAs( wxT( "LowerCenter" ), false ) )
|
2016-02-24 11:56:40 +00:00
|
|
|
id = LowerCenter;
|
2022-05-27 17:08:27 +00:00
|
|
|
else if( aJustify.IsSameAs( wxT( "LowerRight" ), false ) )
|
2016-02-24 11:56:40 +00:00
|
|
|
id = LowerRight;
|
2022-05-27 17:08:27 +00:00
|
|
|
else if( aJustify.IsSameAs( wxT( "UpperLeft" ), false ) )
|
2016-02-24 11:56:40 +00:00
|
|
|
id = UpperLeft;
|
2022-05-27 17:08:27 +00:00
|
|
|
else if( aJustify.IsSameAs( wxT( "UpperCenter" ), false ) )
|
2016-02-24 11:56:40 +00:00
|
|
|
id = UpperCenter;
|
2022-05-27 17:08:27 +00:00
|
|
|
else if( aJustify.IsSameAs( wxT( "UpperRight" ), false ) )
|
2016-02-24 11:56:40 +00:00
|
|
|
id = UpperRight;
|
2022-05-27 17:08:27 +00:00
|
|
|
else if( aJustify.IsSameAs( wxT( "Left" ), false ) )
|
2016-02-24 11:56:40 +00:00
|
|
|
id = Left;
|
2022-05-27 17:08:27 +00:00
|
|
|
else if( aJustify.IsSameAs( wxT( "Center" ), false ) )
|
2016-02-24 11:56:40 +00:00
|
|
|
id = Center;
|
2022-05-27 17:08:27 +00:00
|
|
|
else if( aJustify.IsSameAs( wxT( "Right" ), false ) )
|
2016-02-24 11:56:40 +00:00
|
|
|
id = Right;
|
|
|
|
else
|
|
|
|
id = LowerLeft;
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2017-12-10 09:21:43 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
void SetTextParameters( XNODE* aNode, TTEXTVALUE* aTextValue,
|
|
|
|
const wxString& aDefaultMeasurementUnit, const wxString& aActualConversion )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
XNODE* tNode;
|
|
|
|
wxString str;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
tNode = FindNode( aNode, wxT( "pt" ) );
|
|
|
|
|
|
|
|
if( tNode )
|
2021-07-19 23:56:05 +00:00
|
|
|
SetPosition( tNode->GetNodeContent(), aDefaultMeasurementUnit, &aTextValue->textPositionX,
|
|
|
|
&aTextValue->textPositionY, aActualConversion );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
tNode = FindNode( aNode, wxT( "rotation" ) );
|
|
|
|
|
|
|
|
if( tNode )
|
|
|
|
{
|
|
|
|
str = tNode->GetNodeContent();
|
|
|
|
str.Trim( false );
|
2022-01-18 02:05:59 +00:00
|
|
|
aTextValue->textRotation = EDA_ANGLE( StrToInt1Units( str ), TENTHS_OF_A_DEGREE_T );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
2017-12-10 07:10:17 +00:00
|
|
|
else
|
|
|
|
{
|
2022-01-18 02:05:59 +00:00
|
|
|
aTextValue->textRotation = ANGLE_0;
|
2017-12-10 07:10:17 +00:00
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
str = FindNodeGetContent( aNode, wxT( "isVisible" ) );
|
|
|
|
|
2022-05-27 17:08:27 +00:00
|
|
|
if( str.IsSameAs( wxT( "True" ), false ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
aTextValue->textIsVisible = 1;
|
2017-12-10 07:10:17 +00:00
|
|
|
else
|
2012-12-29 09:54:25 +00:00
|
|
|
aTextValue->textIsVisible = 0;
|
|
|
|
|
2016-02-24 11:56:40 +00:00
|
|
|
str = FindNodeGetContent( aNode, wxT( "justify" ) );
|
|
|
|
aTextValue->justify = GetJustifyIdentificator( str );
|
|
|
|
|
|
|
|
str = FindNodeGetContent( aNode, wxT( "isFlipped" ) );
|
|
|
|
|
2022-05-27 17:08:27 +00:00
|
|
|
if( str.IsSameAs( wxT( "True" ), false ) )
|
2016-02-24 11:56:40 +00:00
|
|
|
aTextValue->mirror = 1;
|
2017-12-10 07:10:17 +00:00
|
|
|
else
|
|
|
|
aTextValue->mirror = 0;
|
2016-02-24 11:56:40 +00:00
|
|
|
|
2012-12-29 09:54:25 +00:00
|
|
|
tNode = FindNode( aNode, wxT( "textStyleRef" ) );
|
|
|
|
|
|
|
|
if( tNode )
|
|
|
|
SetFontProperty( tNode, aTextValue, aDefaultMeasurementUnit, aActualConversion );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
void SetFontProperty( XNODE* aNode, TTEXTVALUE* aTextValue, const wxString& aDefaultMeasurementUnit,
|
2017-09-23 09:20:10 +00:00
|
|
|
const wxString& aActualConversion )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
wxString n, propValue;
|
|
|
|
|
|
|
|
aNode->GetAttribute( wxT( "Name" ), &n );
|
|
|
|
|
|
|
|
while( aNode->GetName() != wxT( "www.lura.sk" ) )
|
|
|
|
aNode = aNode->GetParent();
|
|
|
|
|
|
|
|
aNode = FindNode( aNode, wxT( "library" ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2012-12-29 09:54:25 +00:00
|
|
|
if( aNode )
|
|
|
|
aNode = FindNode( aNode, wxT( "textStyleDef" ) );
|
|
|
|
|
2017-12-10 09:21:43 +00:00
|
|
|
while( aNode )
|
|
|
|
{
|
|
|
|
aNode->GetAttribute( wxT( "Name" ), &propValue );
|
|
|
|
propValue.Trim( false );
|
|
|
|
propValue.Trim( true );
|
|
|
|
|
|
|
|
if( propValue == n )
|
|
|
|
break;
|
|
|
|
|
|
|
|
aNode = aNode->GetNext();
|
|
|
|
}
|
|
|
|
|
2012-12-29 09:54:25 +00:00
|
|
|
if( aNode )
|
|
|
|
{
|
2017-12-10 09:21:43 +00:00
|
|
|
wxString fontType;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2017-12-10 09:21:43 +00:00
|
|
|
propValue = FindNodeGetContent( aNode, wxT( "textStyleDisplayTType" ) );
|
2022-05-27 17:08:27 +00:00
|
|
|
aTextValue->isTrueType = ( propValue.IsSameAs( wxT( "True" ), false ) );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2017-12-10 09:21:43 +00:00
|
|
|
aNode = FindNode( aNode, wxT( "font" ) );
|
|
|
|
fontType = FindNodeGetContent( aNode, wxT( "fontType" ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2022-05-27 17:08:27 +00:00
|
|
|
if( ( aTextValue->isTrueType && !fontType.IsSameAs( wxT( "TrueType" ), false ) ) ||
|
|
|
|
( !aTextValue->isTrueType && !fontType.IsSameAs( wxT( "Stroke" ), false ) ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
aNode = aNode->GetNext();
|
|
|
|
|
|
|
|
if( aNode )
|
|
|
|
{
|
2017-12-12 18:21:44 +00:00
|
|
|
if( aTextValue->isTrueType )
|
2017-12-10 09:21:43 +00:00
|
|
|
{
|
|
|
|
propValue = FindNodeGetContent( aNode, wxT( "fontItalic" ) );
|
2022-05-27 17:08:27 +00:00
|
|
|
aTextValue->isItalic = propValue.IsSameAs( wxT( "True" ), false );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2017-12-10 09:21:43 +00:00
|
|
|
propValue = FindNodeGetContent( aNode, wxT( "fontWeight" ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2017-12-10 09:21:43 +00:00
|
|
|
if( propValue != wxEmptyString )
|
|
|
|
{
|
|
|
|
long fontWeight;
|
|
|
|
|
|
|
|
propValue.ToLong( &fontWeight );
|
|
|
|
aTextValue->isBold = ( fontWeight >= TRUETYPE_BOLD_MIN_WEIGHT );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XNODE* lNode;
|
|
|
|
|
|
|
|
lNode = FindNode( aNode, wxT( "fontHeight" ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2017-12-10 09:21:43 +00:00
|
|
|
if( lNode )
|
|
|
|
SetHeight( lNode->GetNodeContent(), aDefaultMeasurementUnit,
|
|
|
|
&aTextValue->textHeight, aActualConversion );
|
|
|
|
|
2017-12-12 18:21:44 +00:00
|
|
|
if( aTextValue->isTrueType )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2017-12-12 18:21:44 +00:00
|
|
|
aTextValue->textstrokeWidth = TRUETYPE_THICK_PER_HEIGHT * aTextValue->textHeight;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2017-12-10 09:21:43 +00:00
|
|
|
if( aTextValue->isBold )
|
2017-12-12 18:21:44 +00:00
|
|
|
aTextValue->textstrokeWidth *= TRUETYPE_BOLD_THICK_MUL;
|
2017-12-10 09:21:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lNode = FindNode( aNode, wxT( "strokeWidth" ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2017-12-10 09:21:43 +00:00
|
|
|
if( lNode )
|
|
|
|
SetWidth( lNode->GetNodeContent(), aDefaultMeasurementUnit,
|
|
|
|
&aTextValue->textstrokeWidth, aActualConversion );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-10 09:21:43 +00:00
|
|
|
|
2016-02-27 17:33:38 +00:00
|
|
|
void SetTextJustify( EDA_TEXT* aText, TTEXT_JUSTIFY aJustify )
|
|
|
|
{
|
|
|
|
switch( aJustify )
|
|
|
|
{
|
|
|
|
case LowerLeft:
|
2021-12-28 22:13:54 +00:00
|
|
|
aText->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
|
|
|
aText->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2016-02-27 17:33:38 +00:00
|
|
|
break;
|
|
|
|
case LowerCenter:
|
2021-12-28 22:13:54 +00:00
|
|
|
aText->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
|
|
|
aText->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
2016-02-27 17:33:38 +00:00
|
|
|
break;
|
|
|
|
case LowerRight:
|
2021-12-28 22:13:54 +00:00
|
|
|
aText->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
|
|
|
aText->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
2016-02-27 17:33:38 +00:00
|
|
|
break;
|
|
|
|
case UpperLeft:
|
2021-12-28 22:13:54 +00:00
|
|
|
aText->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
|
|
|
aText->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2016-02-27 17:33:38 +00:00
|
|
|
break;
|
|
|
|
case UpperCenter:
|
2021-12-28 22:13:54 +00:00
|
|
|
aText->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
|
|
|
aText->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
2016-02-27 17:33:38 +00:00
|
|
|
break;
|
|
|
|
case UpperRight:
|
2021-12-28 22:13:54 +00:00
|
|
|
aText->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
|
|
|
aText->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
2016-02-27 17:33:38 +00:00
|
|
|
break;
|
|
|
|
case Left:
|
2021-12-28 22:13:54 +00:00
|
|
|
aText->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
|
|
|
aText->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2016-02-27 17:33:38 +00:00
|
|
|
break;
|
|
|
|
case Center:
|
2021-12-28 22:13:54 +00:00
|
|
|
aText->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
|
|
|
aText->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
2016-02-27 17:33:38 +00:00
|
|
|
break;
|
|
|
|
case Right:
|
2021-12-28 22:13:54 +00:00
|
|
|
aText->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
|
|
|
aText->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
2016-02-27 17:33:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-10 09:21:43 +00:00
|
|
|
|
2016-02-24 11:56:40 +00:00
|
|
|
int CalculateTextLengthSize( TTEXTVALUE* aText )
|
|
|
|
{
|
|
|
|
return KiROUND( (double) aText->text.Len() *
|
2016-02-27 17:33:38 +00:00
|
|
|
(double) aText->textHeight * TEXT_WIDTH_TO_SIZE_AVERAGE );
|
2016-02-24 11:56:40 +00:00
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2017-12-10 09:21:43 +00:00
|
|
|
|
2016-02-24 11:56:40 +00:00
|
|
|
void CorrectTextPosition( TTEXTVALUE* aValue )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2016-02-24 11:56:40 +00:00
|
|
|
int cm = aValue->mirror ? -1 : 1;
|
|
|
|
int cl = KiROUND( (double) CalculateTextLengthSize( aValue ) / 2.0 );
|
|
|
|
int ch = KiROUND( (double) aValue->textHeight / 2.0 );
|
2017-12-11 18:34:50 +00:00
|
|
|
int posX = 0;
|
|
|
|
int posY = 0;
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( aValue->justify == LowerLeft || aValue->justify == Left || aValue->justify == UpperLeft )
|
2017-12-11 18:34:50 +00:00
|
|
|
posX += cl * cm;
|
2021-07-19 23:56:05 +00:00
|
|
|
else if( aValue->justify == LowerRight || aValue->justify == Right ||
|
2017-12-11 18:34:50 +00:00
|
|
|
aValue->justify == UpperRight )
|
|
|
|
posX -= cl * cm;
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( aValue->justify == LowerLeft || aValue->justify == LowerCenter ||
|
2017-12-11 18:34:50 +00:00
|
|
|
aValue->justify == LowerRight )
|
|
|
|
posY -= ch;
|
2021-07-19 23:56:05 +00:00
|
|
|
else if( aValue->justify == UpperLeft || aValue->justify == UpperCenter ||
|
2017-12-11 18:34:50 +00:00
|
|
|
aValue->justify == UpperRight )
|
|
|
|
posY += ch;
|
|
|
|
|
|
|
|
RotatePoint( &posX, &posY, aValue->textRotation );
|
|
|
|
|
|
|
|
aValue->correctedPositionX = aValue->textPositionX + posX;
|
|
|
|
aValue->correctedPositionY = aValue->textPositionY + posY;
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2016-02-27 17:33:38 +00:00
|
|
|
void SetTextSizeFromStrokeFontHeight( EDA_TEXT* aText, int aTextHeight )
|
|
|
|
{
|
2017-12-12 18:21:44 +00:00
|
|
|
aText->SetTextSize( wxSize( KiROUND( aTextHeight * STROKE_WIDTH_TO_SIZE ),
|
|
|
|
KiROUND( aTextHeight * STROKE_HEIGHT_TO_SIZE ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SetTextSizeFromTrueTypeFontHeight( EDA_TEXT* aText, int aTextHeight )
|
|
|
|
{
|
|
|
|
aText->SetTextSize( wxSize( KiROUND( aTextHeight * TRUETYPE_WIDTH_TO_SIZE ),
|
|
|
|
KiROUND( aTextHeight * TRUETYPE_HEIGHT_TO_SIZE ) ) );
|
2016-02-27 17:33:38 +00:00
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
XNODE* FindNode( XNODE* aChild, const wxString& aTag )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
aChild = aChild->GetChildren();
|
|
|
|
|
|
|
|
while( aChild )
|
|
|
|
{
|
2022-05-27 17:08:27 +00:00
|
|
|
if( aChild->GetName().IsSameAs( aTag, false ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
return aChild;
|
|
|
|
|
|
|
|
aChild = aChild->GetNext();
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
return nullptr;
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
wxString FindNodeGetContent( XNODE* aChild, const wxString& aTag )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
wxString str = wxEmptyString;
|
|
|
|
|
|
|
|
aChild = FindNode( aChild, aTag );
|
|
|
|
|
|
|
|
if( aChild )
|
|
|
|
{
|
|
|
|
str = aChild->GetNodeContent();
|
|
|
|
str.Trim( false );
|
|
|
|
str.Trim( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2012-12-29 09:54:25 +00:00
|
|
|
void InitTTextValue( TTEXTVALUE* aTextValue )
|
|
|
|
{
|
|
|
|
aTextValue->text = wxEmptyString;
|
|
|
|
aTextValue->textPositionX = 0;
|
|
|
|
aTextValue->textPositionY = 0;
|
2022-01-18 02:05:59 +00:00
|
|
|
aTextValue->textRotation = ANGLE_0;
|
2012-12-29 09:54:25 +00:00
|
|
|
aTextValue->textHeight = 0;
|
|
|
|
aTextValue->textstrokeWidth = 0;
|
|
|
|
aTextValue->textIsVisible = 0;
|
|
|
|
aTextValue->mirror = 0;
|
|
|
|
aTextValue->textUnit = 0;
|
|
|
|
aTextValue->correctedPositionX = 0;
|
|
|
|
aTextValue->correctedPositionY = 0;
|
2016-02-24 11:56:40 +00:00
|
|
|
aTextValue->justify = LowerLeft;
|
2017-12-10 09:21:43 +00:00
|
|
|
aTextValue->isBold = false;
|
|
|
|
aTextValue->isItalic = false;
|
2017-12-12 18:21:44 +00:00
|
|
|
aTextValue->isTrueType = false;
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace PCAD2KICAD
|