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
6c3968a1
Commit
6c3968a1
authored
Oct 06, 2009
by
charras
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code easier to understand
parent
c974c42d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
46 deletions
+71
-46
class_libentry.cpp
eeschema/class_libentry.cpp
+52
-0
class_libentry.h
eeschema/class_libentry.h
+15
-0
locate.cpp
eeschema/locate.cpp
+4
-46
No files found.
eeschema/class_libentry.cpp
View file @
6c3968a1
...
@@ -1168,6 +1168,18 @@ void LIB_COMPONENT::MirrorSelectedItemsH( const wxPoint& center )
...
@@ -1168,6 +1168,18 @@ void LIB_COMPONENT::MirrorSelectedItemsH( const wxPoint& center )
}
}
/**
* Locate a draw object.
*
* @param unit - Unit number of draw item.
* @param convert - Body style of draw item.
* @param type - Draw object type, set to 0 to search for any type.
* @param pt - Coordinate for hit testing.
*
* @return LIB_DRAW_ITEM - Pointer the the draw object if found.
* Otherwise NULL.
*/
LIB_DRAW_ITEM
*
LIB_COMPONENT
::
LocateDrawItem
(
int
unit
,
int
convert
,
LIB_DRAW_ITEM
*
LIB_COMPONENT
::
LocateDrawItem
(
int
unit
,
int
convert
,
KICAD_T
type
,
const
wxPoint
&
pt
)
KICAD_T
type
,
const
wxPoint
&
pt
)
{
{
...
@@ -1201,6 +1213,46 @@ LIB_DRAW_ITEM* LIB_COMPONENT::LocateDrawItem( int unit, int convert,
...
@@ -1201,6 +1213,46 @@ LIB_DRAW_ITEM* LIB_COMPONENT::LocateDrawItem( int unit, int convert,
return
NULL
;
return
NULL
;
}
}
/** Function HitTest (overlaid)
* @return true if the point aPosRef is near this object
* @param aPosRef = a wxPoint to test
* @param aThreshold = max distance to this object (usually the half
* thickness of a line)
* @param aTransMat = the transform matrix
*
* @return LIB_DRAW_ITEM - Pointer the the draw object if found.
* Otherwise NULL.
*/
LIB_DRAW_ITEM
*
LIB_COMPONENT
::
LocateDrawItem
(
int
unit
,
int
convert
,
KICAD_T
type
,
const
wxPoint
&
pt
,
const
int
aTransMat
[
2
][
2
]
)
{
/* we use LocateDrawItem( int unit, int convert, KICAD_T type, const wxPoint& pt )
* to search items.
* because this function uses DefaultTransformMatrix as orient/mirror matrix
* we temporary copy aTransMat in DefaultTransformMatrix
*/
LIB_DRAW_ITEM
*
item
;
int
matrix
[
2
][
2
];
for
(
int
ii
=
0
;
ii
<
2
;
ii
++
)
{
for
(
int
jj
=
0
;
jj
<
2
;
jj
++
)
{
matrix
[
ii
][
jj
]
=
aTransMat
[
ii
][
jj
];
EXCHG
(
matrix
[
ii
][
jj
],
DefaultTransformMatrix
[
ii
][
jj
]);
}
}
item
=
LocateDrawItem
(
unit
,
convert
,
type
,
pt
);
//Restore matrix
for
(
int
ii
=
0
;
ii
<
2
;
ii
++
)
{
for
(
int
jj
=
0
;
jj
<
2
;
jj
++
)
{
EXCHG
(
matrix
[
ii
][
jj
],
DefaultTransformMatrix
[
ii
][
jj
]);
}
}
return
item
;
}
void
LIB_COMPONENT
::
SetPartCount
(
int
count
)
void
LIB_COMPONENT
::
SetPartCount
(
int
count
)
{
{
...
...
eeschema/class_libentry.h
View file @
6c3968a1
...
@@ -356,6 +356,21 @@ public:
...
@@ -356,6 +356,21 @@ public:
LIB_DRAW_ITEM
*
LocateDrawItem
(
int
unit
,
int
convert
,
KICAD_T
type
,
LIB_DRAW_ITEM
*
LocateDrawItem
(
int
unit
,
int
convert
,
KICAD_T
type
,
const
wxPoint
&
pt
);
const
wxPoint
&
pt
);
/**
* Locate a draw object (overlaid)
*
* @param unit - Unit number of draw item.
* @param convert - Body style of draw item.
* @param type - Draw object type, set to 0 to search for any type.
* @param pt - Coordinate for hit testing.
* @param aTransMat = the transform matrix
*
* @return LIB_DRAW_ITEM - Pointer the the draw object if found.
* Otherwise NULL.
*/
LIB_DRAW_ITEM
*
LocateDrawItem
(
int
unit
,
int
convert
,
KICAD_T
type
,
const
wxPoint
&
pt
,
const
int
aTransMat
[
2
][
2
]
);
/**
/**
* Return a reference to the draw item list.
* Return a reference to the draw item list.
*
*
...
...
eeschema/locate.cpp
View file @
6c3968a1
...
@@ -686,38 +686,6 @@ Hierarchical_PIN_Sheet_Struct* LocateSheetLabel( DrawSheetStruct* Sheet,
...
@@ -686,38 +686,6 @@ Hierarchical_PIN_Sheet_Struct* LocateSheetLabel( DrawSheetStruct* Sheet,
return
NULL
;
return
NULL
;
}
}
/* helper function used to locate graphics items in a lib component (in library space)
* to a given location given in schematic space
* in schematic space, a component is an image of the lib component, rotated and mirorred
* by its mirror/rotation matrix
* this function calculates the invert matrix of the mirror/rotation matrix
* it is used to calculate the position in in library space from
* the position in schematic space of a test point, corresponding to a given component
*/
bool
InvertMatrix
(
int
aSource
[
2
][
2
],
int
aDest
[
2
][
2
]
)
{
/* for a source matrix (a,b, c,d) a, if the first line, and cd the second line
* the invert matrix is 1/det * comatrix
* det = ad-bc
* comatrix = (d,-b, -c,a)
* a = aSource[0][0]
* b = aSource[0][1]
* c = aSource[1][0]
* d = aSource[1][1]
* in eeschema, values are 1, 0 or -1 only and we can use integers only
*/
bool
success
=
true
;
int
det
=
aSource
[
0
][
0
]
*
aSource
[
1
][
1
]
-
aSource
[
0
][
1
]
*
aSource
[
1
][
0
];
wxASSERT
(
det
);
if
(
det
==
0
)
// Should not occur with eeschema matrix transform
det
=
1
;
aDest
[
0
][
0
]
=
aSource
[
1
][
1
]
/
det
;
aDest
[
0
][
1
]
=
-
aSource
[
0
][
1
]
/
det
;
aDest
[
1
][
0
]
=
-
aSource
[
1
][
0
]
/
det
;
aDest
[
1
][
1
]
=
aSource
[
0
][
0
]
/
det
;
return
success
;
}
LibDrawPin
*
LocateAnyPin
(
SCH_ITEM
*
DrawList
,
const
wxPoint
&
RefPos
,
LibDrawPin
*
LocateAnyPin
(
SCH_ITEM
*
DrawList
,
const
wxPoint
&
RefPos
,
SCH_COMPONENT
**
libpart
)
SCH_COMPONENT
**
libpart
)
...
@@ -738,24 +706,14 @@ LibDrawPin* LocateAnyPin( SCH_ITEM* DrawList, const wxPoint& RefPos,
...
@@ -738,24 +706,14 @@ LibDrawPin* LocateAnyPin( SCH_ITEM* DrawList, const wxPoint& RefPos,
if
(
Entry
==
NULL
)
if
(
Entry
==
NULL
)
continue
;
continue
;
/* we use LocateDrawItem to locate pns. but this function suppose a component
/* we use LocateDrawItem to locate pns. but this function suppose a component
* at 0,0 location
, in normal orientation/mirror
* at 0,0 location
* So we must calculate the ref position
in component space
* So we must calculate the ref position
relative to the component
*/
*/
// Calculate the position relative to the component (in library space the component is at location 0,0)
wxPoint
libPos
=
RefPos
-
schItem
->
m_Pos
;
wxPoint
libPos
=
RefPos
-
schItem
->
m_Pos
;
// Calculate the equivalent position of the test point for a normal orient component
int
itransMat
[
2
][
2
];
InvertMatrix
(
schItem
->
m_Transform
,
itransMat
);
libPos
=
TransformCoordinate
(
itransMat
,
libPos
);
// LocateDrawItem uses DefaultTransformMatrix as matrix orientation of the component
// so we must recalculate libPos for this orientation before calling LocateDrawItem
InvertMatrix
(
DefaultTransformMatrix
,
itransMat
);
libPos
=
TransformCoordinate
(
itransMat
,
libPos
);
wxPoint
schPos
=
TransformCoordinate
(
schItem
->
m_Transform
,
libPos
);
Pin
=
(
LibDrawPin
*
)
Entry
->
LocateDrawItem
(
schItem
->
m_Multi
,
Pin
=
(
LibDrawPin
*
)
Entry
->
LocateDrawItem
(
schItem
->
m_Multi
,
schItem
->
m_Convert
,
schItem
->
m_Convert
,
COMPONENT_PIN_DRAW_TYPE
,
COMPONENT_PIN_DRAW_TYPE
,
libPos
);
libPos
,
schItem
->
m_Transform
);
if
(
Pin
)
if
(
Pin
)
break
;
break
;
}
}
...
...
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