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
fca1ba67
Commit
fca1ba67
authored
May 01, 2014
by
Lorenzo Marcantonio
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Virtual split of TRACK/VIA::HitTest
parent
7b4b3297
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
57 deletions
+47
-57
class_track.cpp
pcbnew/class_track.cpp
+37
-55
class_track.h
pcbnew/class_track.h
+10
-2
No files found.
pcbnew/class_track.cpp
View file @
fca1ba67
...
...
@@ -1233,64 +1233,56 @@ void VIA::GetMsgPanelInfoBase( std::vector< MSG_PANEL_ITEM >& aList )
bool
TRACK
::
HitTest
(
const
wxPoint
&
aPosition
)
{
int
max_dist
=
m_Width
>>
1
;
return
TestSegmentHit
(
aPosition
,
m_Start
,
m_End
,
m_Width
/
2
);
}
if
(
Type
()
==
PCB_VIA_T
)
{
// rel_pos is aPosition relative to m_Start (or the center of the via)
wxPoint
rel_pos
=
aPosition
-
m_Start
;
double
dist
=
(
double
)
rel_pos
.
x
*
rel_pos
.
x
+
(
double
)
rel_pos
.
y
*
rel_pos
.
y
;
return
dist
<=
(
double
)
max_dist
*
max_dist
;
}
bool
VIA
::
HitTest
(
const
wxPoint
&
aPosition
)
{
int
max_dist
=
m_Width
/
2
;
return
TestSegmentHit
(
aPosition
,
m_Start
,
m_End
,
max_dist
);
// rel_pos is aPosition relative to m_Start (or the center of the via)
wxPoint
rel_pos
=
aPosition
-
m_Start
;
double
dist
=
(
double
)
rel_pos
.
x
*
rel_pos
.
x
+
(
double
)
rel_pos
.
y
*
rel_pos
.
y
;
return
dist
<=
(
double
)
max_dist
*
max_dist
;
}
bool
TRACK
::
HitTest
(
const
EDA_RECT
&
aRect
,
bool
aContained
,
int
aAccuracy
)
const
{
EDA_RECT
arect
=
aRect
;
arect
.
Inflate
(
aAccuracy
);
if
(
aContained
)
/* Tracks are a special case:
* they are considered inside the rect if one end is inside the rect */
return
arect
.
Contains
(
GetStart
()
)
||
arect
.
Contains
(
GetEnd
()
);
else
return
arect
.
Intersects
(
GetStart
(),
GetEnd
()
);
}
bool
VIA
::
HitTest
(
const
EDA_RECT
&
aRect
,
bool
aContained
,
int
aAccuracy
)
const
{
EDA_RECT
box
;
EDA_RECT
arect
=
aRect
;
arect
.
Inflate
(
aAccuracy
);
if
(
Type
()
==
PCB_VIA_T
)
{
box
.
SetOrigin
(
GetStart
()
);
box
.
Inflate
(
GetWidth
()
>>
1
);
box
.
SetOrigin
(
GetStart
()
);
box
.
Inflate
(
GetWidth
()
/
2
);
if
(
aContained
)
return
arect
.
Contains
(
box
);
else
return
arect
.
Intersects
(
box
);
}
if
(
aContained
)
return
arect
.
Contains
(
box
);
else
{
if
(
aContained
)
// Tracks are a specila case:
// they are considered inside the rect if one end
// is inside the rect
return
arect
.
Contains
(
GetStart
()
)
||
arect
.
Contains
(
GetEnd
()
);
else
return
arect
.
Intersects
(
GetStart
(),
GetEnd
()
);
}
return
arect
.
Intersects
(
box
);
}
VIA
*
TRACK
::
GetVia
(
const
wxPoint
&
aPosition
,
LAYER_NUM
aLayer
)
{
for
(
TRACK
*
track
=
this
;
track
;
track
=
track
->
Next
(
)
)
for
(
VIA
*
via
=
GetFirstVia
(
this
);
via
;
via
=
GetFirstVia
(
via
->
Next
()
)
)
{
if
(
track
->
Type
()
!=
PCB_VIA_T
)
continue
;
if
(
!
track
->
HitTest
(
aPosition
)
)
continue
;
if
(
track
->
GetState
(
BUSY
|
IS_DELETED
)
)
continue
;
if
(
(
aLayer
==
UNDEFINED_LAYER
)
||
(
track
->
IsOnLayer
(
aLayer
))
)
return
static_cast
<
VIA
*>
(
track
);
if
(
via
->
HitTest
(
aPosition
)
&&
!
via
->
GetState
(
BUSY
|
IS_DELETED
)
&&
((
aLayer
==
UNDEFINED_LAYER
)
||
(
via
->
IsOnLayer
(
aLayer
)))
)
return
via
;
}
return
NULL
;
...
...
@@ -1299,22 +1291,12 @@ VIA* TRACK::GetVia( const wxPoint& aPosition, LAYER_NUM aLayer)
VIA
*
TRACK
::
GetVia
(
TRACK
*
aEndTrace
,
const
wxPoint
&
aPosition
,
LAYER_MSK
aLayerMask
)
{
for
(
TRACK
*
trace
=
this
;
trace
;
trace
=
trace
->
Next
(
)
)
for
(
VIA
*
via
=
GetFirstVia
(
this
,
aEndTrace
);
via
;
via
=
GetFirstVia
(
via
->
Next
()
)
)
{
if
(
trace
->
Type
()
==
PCB_VIA_T
)
{
if
(
aPosition
==
trace
->
m_Start
)
{
if
(
trace
->
GetState
(
BUSY
|
IS_DELETED
)
==
0
)
{
if
(
aLayerMask
&
trace
->
GetLayerMask
()
)
return
static_cast
<
VIA
*>
(
trace
);
}
}
}
if
(
trace
==
aEndTrace
)
break
;
if
(
via
->
HitTest
(
aPosition
)
&&
!
via
->
GetState
(
BUSY
|
IS_DELETED
)
&&
(
aLayerMask
&
via
->
GetLayerMask
())
)
return
via
;
}
return
NULL
;
...
...
pcbnew/class_track.h
View file @
fca1ba67
...
...
@@ -228,7 +228,7 @@ public:
/** @copydoc BOARD_ITEM::HitTest(const EDA_RECT& aRect,
* bool aContained = true, int aAccuracy ) const
*/
bool
HitTest
(
const
EDA_RECT
&
aRect
,
bool
aContained
=
true
,
int
aAccuracy
=
0
)
const
;
virtual
bool
HitTest
(
const
EDA_RECT
&
aRect
,
bool
aContained
=
true
,
int
aAccuracy
=
0
)
const
;
/**
* Function GetVia
...
...
@@ -401,6 +401,10 @@ public:
const
wxPoint
&
GetPosition
()
const
{
return
m_Start
;
}
// was overload
void
SetPosition
(
const
wxPoint
&
aPoint
)
{
m_Start
=
aPoint
;
m_End
=
aPoint
;
}
// was overload
virtual
bool
HitTest
(
const
wxPoint
&
aPosition
);
virtual
bool
HitTest
(
const
EDA_RECT
&
aRect
,
bool
aContained
=
true
,
int
aAccuracy
=
0
)
const
;
wxString
GetClass
()
const
{
return
wxT
(
"VIA"
);
...
...
@@ -477,7 +481,11 @@ inline VIA *GetFirstVia( TRACK *aTrk, const TRACK *aStopPoint = NULL )
while
(
aTrk
&&
(
aTrk
!=
aStopPoint
)
&&
(
aTrk
->
Type
()
!=
PCB_VIA_T
)
)
aTrk
=
aTrk
->
Next
();
return
static_cast
<
VIA
*>
(
aTrk
);
// It could stop because of the stop point, not on a via
if
(
aTrk
&&
(
aTrk
->
Type
()
==
PCB_VIA_T
)
)
return
static_cast
<
VIA
*>
(
aTrk
);
else
return
NULL
;
}
#endif
/* CLASS_TRACK_H */
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