Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
6850365d
Commit
6850365d
authored
Jul 15, 2011
by
Dick Hollenbeck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
encapsulate eeschema name encoding, by adding toUTFTildaText()
parent
cbb398e8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
76 deletions
+82
-76
sch_component.cpp
eeschema/sch_component.cpp
+82
-76
No files found.
eeschema/sch_component.cpp
View file @
6850365d
...
@@ -31,6 +31,33 @@
...
@@ -31,6 +31,33 @@
static
LIB_COMPONENT
*
DummyCmp
;
static
LIB_COMPONENT
*
DummyCmp
;
/**
* Function toUTFTildaText
* convert a wxString to UTF8 and replace any control characters with a ~,
* where a control character is one of the first ASCII values up to ' ' 32d.
*/
std
::
string
toUTFTildaText
(
const
wxString
&
txt
)
{
std
::
string
ret
=
TO_UTF8
(
txt
);
for
(
std
::
string
::
iterator
it
=
ret
.
begin
();
it
!=
ret
.
end
();
++
it
)
{
if
(
(
unsigned
char
)
*
it
<=
' '
)
*
it
=
'~'
;
/*
#if defined(KICAD_GOST)
if( *it == ' ' )
#else
if( (unsigned char) *it <= ' ' )
#endif
*it = '~';
*/
}
return
ret
;
}
/* Descr component <DUMMY> used when a component is not found in library,
/* Descr component <DUMMY> used when a component is not found in library,
* to draw a dummy shape
* to draw a dummy shape
* This component is a 400 mils square with the text ??
* This component is a 400 mils square with the text ??
...
@@ -716,9 +743,8 @@ void SCH_COMPONENT::ClearAnnotation( SCH_SHEET_PATH* aSheetPath )
...
@@ -716,9 +743,8 @@ void SCH_COMPONENT::ClearAnnotation( SCH_SHEET_PATH* aSheetPath )
void
SCH_COMPONENT
::
SetOrientation
(
int
aOrientation
)
void
SCH_COMPONENT
::
SetOrientation
(
int
aOrientation
)
{
{
TRANSFORM
temp
=
TRANSFORM
();
TRANSFORM
temp
=
TRANSFORM
();
bool
T
ransform
=
false
;
bool
t
ransform
=
false
;
switch
(
aOrientation
)
switch
(
aOrientation
)
{
{
...
@@ -733,28 +759,28 @@ void SCH_COMPONENT::SetOrientation( int aOrientation )
...
@@ -733,28 +759,28 @@ void SCH_COMPONENT::SetOrientation( int aOrientation )
temp
.
x1
=
temp
.
y2
=
0
;
temp
.
x1
=
temp
.
y2
=
0
;
temp
.
y1
=
1
;
temp
.
y1
=
1
;
temp
.
x2
=
-
1
;
temp
.
x2
=
-
1
;
T
ransform
=
true
;
t
ransform
=
true
;
break
;
break
;
case
CMP_ROTATE_COUNTERCLOCKWISE
:
// Rotate - (incremental rotation)
case
CMP_ROTATE_COUNTERCLOCKWISE
:
// Rotate - (incremental rotation)
temp
.
x1
=
temp
.
y2
=
0
;
temp
.
x1
=
temp
.
y2
=
0
;
temp
.
y1
=
-
1
;
temp
.
y1
=
-
1
;
temp
.
x2
=
1
;
temp
.
x2
=
1
;
T
ransform
=
true
;
t
ransform
=
true
;
break
;
break
;
case
CMP_MIRROR_Y
:
// Mirror Y (incremental rotation)
case
CMP_MIRROR_Y
:
// Mirror Y (incremental rotation)
temp
.
x1
=
-
1
;
temp
.
x1
=
-
1
;
temp
.
y2
=
1
;
temp
.
y2
=
1
;
temp
.
y1
=
temp
.
x2
=
0
;
temp
.
y1
=
temp
.
x2
=
0
;
T
ransform
=
true
;
t
ransform
=
true
;
break
;
break
;
case
CMP_MIRROR_X
:
// Mirror X (incremental rotation)
case
CMP_MIRROR_X
:
// Mirror X (incremental rotation)
temp
.
x1
=
1
;
temp
.
x1
=
1
;
temp
.
y2
=
-
1
;
temp
.
y2
=
-
1
;
temp
.
y1
=
temp
.
x2
=
0
;
temp
.
y1
=
temp
.
x2
=
0
;
T
ransform
=
TRUE
;
t
ransform
=
TRUE
;
break
;
break
;
case
CMP_ORIENT_90
:
case
CMP_ORIENT_90
:
...
@@ -814,12 +840,12 @@ void SCH_COMPONENT::SetOrientation( int aOrientation )
...
@@ -814,12 +840,12 @@ void SCH_COMPONENT::SetOrientation( int aOrientation )
break
;
break
;
default
:
default
:
T
ransform
=
FALSE
;
t
ransform
=
FALSE
;
wxMessageBox
(
wxT
(
"SetRotateMiroir() error: ill value"
)
);
wxMessageBox
(
wxT
(
"SetRotateMiroir() error: ill value"
)
);
break
;
break
;
}
}
if
(
T
ransform
)
if
(
t
ransform
)
{
{
/* The new matrix transform is the old matrix transform modified by the
/* The new matrix transform is the old matrix transform modified by the
* requested transformation, which is the temp transform (rot,
* requested transformation, which is the temp transform (rot,
...
@@ -921,8 +947,8 @@ void SCH_COMPONENT::Show( int nestLevel, std::ostream& os )
...
@@ -921,8 +947,8 @@ void SCH_COMPONENT::Show( int nestLevel, std::ostream& os )
bool
SCH_COMPONENT
::
Save
(
FILE
*
f
)
const
bool
SCH_COMPONENT
::
Save
(
FILE
*
f
)
const
{
{
int
ii
;
std
::
string
name1
;
char
Name1
[
256
],
Name2
[
256
]
;
std
::
string
name2
;
wxArrayString
reference_fields
;
wxArrayString
reference_fields
;
static
wxString
delimiters
(
wxT
(
" "
)
);
static
wxString
delimiters
(
wxT
(
" "
)
);
...
@@ -933,48 +959,28 @@ bool SCH_COMPONENT::Save( FILE* f ) const
...
@@ -933,48 +959,28 @@ bool SCH_COMPONENT::Save( FILE* f ) const
{
{
reference_fields
=
wxStringTokenize
(
m_PathsAndReferences
[
0
],
reference_fields
=
wxStringTokenize
(
m_PathsAndReferences
[
0
],
delimiters
);
delimiters
);
strncpy
(
Name1
,
TO_UTF8
(
reference_fields
[
1
]
),
sizeof
(
Name1
)
);
name1
=
toUTFTildaText
(
reference_fields
[
1
]
);
}
}
else
else
{
{
if
(
GetField
(
REFERENCE
)
->
m_Text
.
IsEmpty
()
)
if
(
GetField
(
REFERENCE
)
->
m_Text
.
IsEmpty
()
)
strncpy
(
Name1
,
TO_UTF8
(
m_prefix
),
sizeof
(
Name1
)
);
name1
=
toUTFTildaText
(
m_prefix
);
else
else
strncpy
(
Name1
,
TO_UTF8
(
GetField
(
REFERENCE
)
->
m_Text
),
sizeof
(
Name1
)
);
name1
=
toUTFTildaText
(
GetField
(
REFERENCE
)
->
m_Text
);
}
for
(
ii
=
0
;
ii
<
(
int
)
strlen
(
Name1
);
ii
++
)
{
#if defined(KICAD_GOST)
if
(
Name1
[
ii
]
==
' '
)
#else
if
(
Name1
[
ii
]
<=
' '
)
#endif
Name1
[
ii
]
=
'~'
;
}
}
if
(
!
m_ChipName
.
IsEmpty
()
)
if
(
!
m_ChipName
.
IsEmpty
()
)
{
{
strncpy
(
Name2
,
TO_UTF8
(
m_ChipName
),
sizeof
(
Name2
)
);
name2
=
toUTFTildaText
(
m_ChipName
);
for
(
ii
=
0
;
ii
<
(
int
)
strlen
(
Name2
);
ii
++
)
#if defined(KICAD_GOST)
if
(
Name2
[
ii
]
==
' '
)
#else
if
(
Name2
[
ii
]
<=
' '
)
#endif
Name2
[
ii
]
=
'~'
;
}
}
else
else
strncpy
(
Name2
,
NULL_STRING
,
sizeof
(
Name2
)
)
;
name2
=
NULL_STRING
;
if
(
fprintf
(
f
,
"$Comp
\n
"
)
==
EOF
)
if
(
fprintf
(
f
,
"$Comp
\n
"
)
==
EOF
)
return
false
;
return
false
;
if
(
fprintf
(
f
,
"L %s %s
\n
"
,
Name2
,
Name1
)
==
EOF
)
if
(
fprintf
(
f
,
"L %s %s
\n
"
,
name2
.
c_str
(),
name1
.
c_str
()
)
==
EOF
)
return
false
;
return
false
;
/* Generate unit number, convert and time stamp*/
/* Generate unit number, convert and time stamp*/
...
@@ -1063,8 +1069,8 @@ bool SCH_COMPONENT::Save( FILE* f ) const
...
@@ -1063,8 +1069,8 @@ bool SCH_COMPONENT::Save( FILE* f ) const
bool
SCH_COMPONENT
::
Load
(
LINE_READER
&
aLine
,
wxString
&
aErrorMsg
)
bool
SCH_COMPONENT
::
Load
(
LINE_READER
&
aLine
,
wxString
&
aErrorMsg
)
{
{
int
ii
;
int
ii
;
char
Name1
[
256
],
N
ame2
[
256
],
char
name1
[
256
],
n
ame2
[
256
],
Char1
[
256
],
Char2
[
256
],
C
har3
[
256
];
char1
[
256
],
char2
[
256
],
c
har3
[
256
];
int
newfmt
=
0
;
int
newfmt
=
0
;
char
*
ptcar
;
char
*
ptcar
;
wxString
fieldName
;
wxString
fieldName
;
...
@@ -1082,7 +1088,7 @@ bool SCH_COMPONENT::Load( LINE_READER& aLine, wxString& aErrorMsg )
...
@@ -1082,7 +1088,7 @@ bool SCH_COMPONENT::Load( LINE_READER& aLine, wxString& aErrorMsg )
line
=
aLine
.
Line
();
line
=
aLine
.
Line
();
}
}
if
(
sscanf
(
&
line
[
1
],
"%s %s"
,
Name1
,
N
ame2
)
!=
2
)
if
(
sscanf
(
&
line
[
1
],
"%s %s"
,
name1
,
n
ame2
)
!=
2
)
{
{
aErrorMsg
.
Printf
(
wxT
(
"EESchema Component descr error at line %d, aborted"
),
aErrorMsg
.
Printf
(
wxT
(
"EESchema Component descr error at line %d, aborted"
),
aLine
.
LineNumber
()
);
aLine
.
LineNumber
()
);
...
@@ -1090,16 +1096,16 @@ bool SCH_COMPONENT::Load( LINE_READER& aLine, wxString& aErrorMsg )
...
@@ -1090,16 +1096,16 @@ bool SCH_COMPONENT::Load( LINE_READER& aLine, wxString& aErrorMsg )
return
false
;
return
false
;
}
}
if
(
strcmp
(
N
ame1
,
NULL_STRING
)
!=
0
)
if
(
strcmp
(
n
ame1
,
NULL_STRING
)
!=
0
)
{
{
for
(
ii
=
0
;
ii
<
(
int
)
strlen
(
N
ame1
);
ii
++
)
for
(
ii
=
0
;
ii
<
(
int
)
strlen
(
n
ame1
);
ii
++
)
if
(
N
ame1
[
ii
]
==
'~'
)
if
(
n
ame1
[
ii
]
==
'~'
)
N
ame1
[
ii
]
=
' '
;
n
ame1
[
ii
]
=
' '
;
m_ChipName
=
FROM_UTF8
(
N
ame1
);
m_ChipName
=
FROM_UTF8
(
n
ame1
);
if
(
!
newfmt
)
if
(
!
newfmt
)
GetField
(
VALUE
)
->
m_Text
=
FROM_UTF8
(
N
ame1
);
GetField
(
VALUE
)
->
m_Text
=
FROM_UTF8
(
n
ame1
);
}
}
else
else
{
{
...
@@ -1109,31 +1115,31 @@ bool SCH_COMPONENT::Load( LINE_READER& aLine, wxString& aErrorMsg )
...
@@ -1109,31 +1115,31 @@ bool SCH_COMPONENT::Load( LINE_READER& aLine, wxString& aErrorMsg )
GetField
(
VALUE
)
->
m_Attributs
=
TEXT_NO_VISIBLE
;
GetField
(
VALUE
)
->
m_Attributs
=
TEXT_NO_VISIBLE
;
}
}
if
(
strcmp
(
N
ame2
,
NULL_STRING
)
!=
0
)
if
(
strcmp
(
n
ame2
,
NULL_STRING
)
!=
0
)
{
{
bool
isDigit
=
false
;
bool
isDigit
=
false
;
for
(
ii
=
0
;
ii
<
(
int
)
strlen
(
N
ame2
);
ii
++
)
for
(
ii
=
0
;
ii
<
(
int
)
strlen
(
n
ame2
);
ii
++
)
{
{
if
(
N
ame2
[
ii
]
==
'~'
)
if
(
n
ame2
[
ii
]
==
'~'
)
N
ame2
[
ii
]
=
' '
;
n
ame2
[
ii
]
=
' '
;
// get RefBase from this, too. store in
N
ame1.
// get RefBase from this, too. store in
n
ame1.
if
(
Name2
[
ii
]
>=
'0'
&&
N
ame2
[
ii
]
<=
'9'
)
if
(
name2
[
ii
]
>=
'0'
&&
n
ame2
[
ii
]
<=
'9'
)
{
{
isDigit
=
true
;
isDigit
=
true
;
N
ame1
[
ii
]
=
0
;
//null-terminate.
n
ame1
[
ii
]
=
0
;
//null-terminate.
}
}
if
(
!
isDigit
)
if
(
!
isDigit
)
{
{
Name1
[
ii
]
=
N
ame2
[
ii
];
name1
[
ii
]
=
n
ame2
[
ii
];
}
}
}
}
N
ame1
[
ii
]
=
0
;
//just in case
n
ame1
[
ii
]
=
0
;
//just in case
int
jj
;
int
jj
;
for
(
jj
=
0
;
jj
<
ii
&&
N
ame1
[
jj
]
==
' '
;
jj
++
)
for
(
jj
=
0
;
jj
<
ii
&&
n
ame1
[
jj
]
==
' '
;
jj
++
)
;
;
if
(
jj
==
ii
)
if
(
jj
==
ii
)
...
@@ -1143,13 +1149,13 @@ bool SCH_COMPONENT::Load( LINE_READER& aLine, wxString& aErrorMsg )
...
@@ -1143,13 +1149,13 @@ bool SCH_COMPONENT::Load( LINE_READER& aLine, wxString& aErrorMsg )
}
}
else
else
{
{
m_prefix
=
FROM_UTF8
(
&
N
ame1
[
jj
]
);
m_prefix
=
FROM_UTF8
(
&
n
ame1
[
jj
]
);
//printf("prefix: %s\n", TO_UTF8(component->m_prefix));
//printf("prefix: %s\n", TO_UTF8(component->m_prefix));
}
}
if
(
!
newfmt
)
if
(
!
newfmt
)
GetField
(
REFERENCE
)
->
m_Text
=
FROM_UTF8
(
N
ame2
);
GetField
(
REFERENCE
)
->
m_Text
=
FROM_UTF8
(
n
ame2
);
}
}
else
else
{
{
...
@@ -1200,20 +1206,20 @@ bool SCH_COMPONENT::Load( LINE_READER& aLine, wxString& aErrorMsg )
...
@@ -1200,20 +1206,20 @@ bool SCH_COMPONENT::Load( LINE_READER& aLine, wxString& aErrorMsg )
ptcar
=
line
+
2
;
ptcar
=
line
+
2
;
//copy the path.
//copy the path.
ii
=
ReadDelimitedText
(
N
ame1
,
ptcar
,
255
);
ii
=
ReadDelimitedText
(
n
ame1
,
ptcar
,
255
);
ptcar
+=
ii
+
1
;
ptcar
+=
ii
+
1
;
wxString
path
=
FROM_UTF8
(
N
ame1
);
wxString
path
=
FROM_UTF8
(
n
ame1
);
// copy the reference
// copy the reference
ii
=
ReadDelimitedText
(
N
ame1
,
ptcar
,
255
);
ii
=
ReadDelimitedText
(
n
ame1
,
ptcar
,
255
);
ptcar
+=
ii
+
1
;
ptcar
+=
ii
+
1
;
wxString
ref
=
FROM_UTF8
(
N
ame1
);
wxString
ref
=
FROM_UTF8
(
n
ame1
);
// copy the multi, if exists
// copy the multi, if exists
ii
=
ReadDelimitedText
(
N
ame1
,
ptcar
,
255
);
ii
=
ReadDelimitedText
(
n
ame1
,
ptcar
,
255
);
if
(
N
ame1
[
0
]
==
0
)
// Nothing read, put a default value
if
(
n
ame1
[
0
]
==
0
)
// Nothing read, put a default value
sprintf
(
N
ame1
,
"%d"
,
m_unit
);
sprintf
(
n
ame1
,
"%d"
,
m_unit
);
int
multi
=
atoi
(
N
ame1
);
int
multi
=
atoi
(
n
ame1
);
if
(
multi
<
0
||
multi
>
25
)
if
(
multi
<
0
||
multi
>
25
)
multi
=
1
;
multi
=
1
;
AddHierarchicalReference
(
path
,
ref
,
multi
);
AddHierarchicalReference
(
path
,
ref
,
multi
);
...
@@ -1279,13 +1285,13 @@ bool SCH_COMPONENT::Load( LINE_READER& aLine, wxString& aErrorMsg )
...
@@ -1279,13 +1285,13 @@ bool SCH_COMPONENT::Load( LINE_READER& aLine, wxString& aErrorMsg )
}
}
GetField
(
fieldNdx
)
->
m_Text
=
fieldText
;
GetField
(
fieldNdx
)
->
m_Text
=
fieldText
;
memset
(
Char3
,
0
,
sizeof
(
C
har3
)
);
memset
(
char3
,
0
,
sizeof
(
c
har3
)
);
if
(
(
ii
=
sscanf
(
ptcar
,
"%s %d %d %d %X %s %s"
,
C
har1
,
if
(
(
ii
=
sscanf
(
ptcar
,
"%s %d %d %d %X %s %s"
,
c
har1
,
&
GetField
(
fieldNdx
)
->
m_Pos
.
x
,
&
GetField
(
fieldNdx
)
->
m_Pos
.
x
,
&
GetField
(
fieldNdx
)
->
m_Pos
.
y
,
&
GetField
(
fieldNdx
)
->
m_Pos
.
y
,
&
GetField
(
fieldNdx
)
->
m_Size
.
x
,
&
GetField
(
fieldNdx
)
->
m_Size
.
x
,
&
GetField
(
fieldNdx
)
->
m_Attributs
,
&
GetField
(
fieldNdx
)
->
m_Attributs
,
Char2
,
C
har3
)
)
<
4
)
char2
,
c
har3
)
)
<
4
)
{
{
aErrorMsg
.
Printf
(
wxT
(
"Component Field error line %d, aborted"
),
aErrorMsg
.
Printf
(
wxT
(
"Component Field error line %d, aborted"
),
aLine
.
LineNumber
()
);
aLine
.
LineNumber
()
);
...
@@ -1298,24 +1304,24 @@ bool SCH_COMPONENT::Load( LINE_READER& aLine, wxString& aErrorMsg )
...
@@ -1298,24 +1304,24 @@ bool SCH_COMPONENT::Load( LINE_READER& aLine, wxString& aErrorMsg )
GetField
(
fieldNdx
)
->
m_Orient
=
TEXT_ORIENT_HORIZ
;
GetField
(
fieldNdx
)
->
m_Orient
=
TEXT_ORIENT_HORIZ
;
GetField
(
fieldNdx
)
->
m_Size
.
y
=
GetField
(
fieldNdx
)
->
m_Size
.
x
;
GetField
(
fieldNdx
)
->
m_Size
.
y
=
GetField
(
fieldNdx
)
->
m_Size
.
x
;
if
(
C
har1
[
0
]
==
'V'
)
if
(
c
har1
[
0
]
==
'V'
)
GetField
(
fieldNdx
)
->
m_Orient
=
TEXT_ORIENT_VERT
;
GetField
(
fieldNdx
)
->
m_Orient
=
TEXT_ORIENT_VERT
;
if
(
ii
>=
7
)
if
(
ii
>=
7
)
{
{
if
(
*
C
har2
==
'L'
)
if
(
*
c
har2
==
'L'
)
hjustify
=
GR_TEXT_HJUSTIFY_LEFT
;
hjustify
=
GR_TEXT_HJUSTIFY_LEFT
;
else
if
(
*
C
har2
==
'R'
)
else
if
(
*
c
har2
==
'R'
)
hjustify
=
GR_TEXT_HJUSTIFY_RIGHT
;
hjustify
=
GR_TEXT_HJUSTIFY_RIGHT
;
if
(
C
har3
[
0
]
==
'B'
)
if
(
c
har3
[
0
]
==
'B'
)
vjustify
=
GR_TEXT_VJUSTIFY_BOTTOM
;
vjustify
=
GR_TEXT_VJUSTIFY_BOTTOM
;
else
if
(
C
har3
[
0
]
==
'T'
)
else
if
(
c
har3
[
0
]
==
'T'
)
vjustify
=
GR_TEXT_VJUSTIFY_TOP
;
vjustify
=
GR_TEXT_VJUSTIFY_TOP
;
if
(
C
har3
[
1
]
==
'I'
)
if
(
c
har3
[
1
]
==
'I'
)
GetField
(
fieldNdx
)
->
m_Italic
=
true
;
GetField
(
fieldNdx
)
->
m_Italic
=
true
;
else
else
GetField
(
fieldNdx
)
->
m_Italic
=
false
;
GetField
(
fieldNdx
)
->
m_Italic
=
false
;
if
(
C
har3
[
2
]
==
'B'
)
if
(
c
har3
[
2
]
==
'B'
)
GetField
(
fieldNdx
)
->
m_Bold
=
true
;
GetField
(
fieldNdx
)
->
m_Bold
=
true
;
else
else
GetField
(
fieldNdx
)
->
m_Bold
=
false
;
GetField
(
fieldNdx
)
->
m_Bold
=
false
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment