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
f193e389
Commit
f193e389
authored
Aug 06, 2013
by
Maciej Suminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved highlighted flag from VIEW_ITEM to EDA_ITEM. Added brightened and selected flag to EDA_ITEM.
parent
8753bef2
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
224 additions
and
238 deletions
+224
-238
view_item.cpp
common/view/view_item.cpp
+0
-7
base_struct.h
include/base_struct.h
+13
-0
color4d.h
include/gal/color4d.h
+4
-4
view_item.h
include/view/view_item.h
+1
-23
pcb_painter.cpp
pcbnew/pcb_painter.cpp
+26
-25
selection_tool.cpp
pcbnew/tools/selection_tool.cpp
+163
-162
selection_tool.h
pcbnew/tools/selection_tool.h
+17
-17
No files found.
common/view/view_item.cpp
View file @
f193e389
...
...
@@ -136,10 +136,3 @@ bool VIEW_ITEM::storesGroups() const
{
return
(
m_groupsSize
>
0
);
}
void
VIEW_ITEM
::
ViewSetHighlighted
(
bool
aIsHighlighted
)
{
m_highlighted
=
aIsHighlighted
;
ViewUpdate
(
APPEARANCE
|
GEOMETRY
);
}
include/base_struct.h
View file @
f193e389
...
...
@@ -387,6 +387,9 @@ public:
#define END_ONPAD (1 << 23) ///< Pcbnew: flag set for track segment ending on a pad
#define BUSY (1 << 24) ///< Pcbnew: flag indicating that the structure has
///< already been edited, in some functions
#define HIGHLIGHTED (1 << 25) ///< item is drawn in normal colors, when the rest is darkened
#define BRIGHTENED (1 << 26) ///< item is drawn with a bright contour
#define EDA_ITEM_ALL_FLAGS -1
typedef
unsigned
STATUS_FLAGS
;
...
...
@@ -466,6 +469,16 @@ public:
inline
bool
IsDragging
()
const
{
return
m_Flags
&
IS_DRAGGED
;
}
inline
bool
IsSelected
()
const
{
return
m_Flags
&
SELECTED
;
}
inline
bool
IsResized
()
const
{
return
m_Flags
&
IS_RESIZED
;
}
inline
bool
IsHighlighted
()
const
{
return
m_Flags
&
HIGHLIGHTED
;
}
inline
bool
IsBrightened
()
const
{
return
m_Flags
&
BRIGHTENED
;
}
inline
void
SetBrightened
()
{
SetFlags
(
BRIGHTENED
);
ViewUpdate
(
APPEARANCE
);
}
inline
void
SetSelected
()
{
SetFlags
(
SELECTED
);
ViewUpdate
(
APPEARANCE
);
}
inline
void
SetHighlighted
()
{
SetFlags
(
HIGHLIGHTED
);
ViewUpdate
(
APPEARANCE
|
GEOMETRY
);
}
inline
void
ClearSelected
()
{
ClearFlags
(
SELECTED
);
ViewUpdate
(
APPEARANCE
);
}
inline
void
ClearHighlighted
()
{
ClearFlags
(
HIGHLIGHTED
);
ViewUpdate
(
APPEARANCE
);
}
inline
void
ClearBrightened
()
{
ClearFlags
(
BRIGHTENED
);
ViewUpdate
(
APPEARANCE
|
GEOMETRY
);
}
void
SetModified
();
...
...
include/gal/color4d.h
View file @
f193e389
...
...
@@ -75,12 +75,12 @@ public:
#endif
/* WX_COMPATIBLITY */
/**
* Function
Highlight
* Function
Brighten
* Makes the color brighter by a given factor.
* @param aFactor Specifies how bright the color should become (valid values: 0.0 .. 1.0).
* @return COLOR4D& Brightened color.
*/
COLOR4D
&
Highlight
(
double
aFactor
)
COLOR4D
&
Brighten
(
double
aFactor
)
{
r
=
r
*
(
1
.
0
-
aFactor
)
+
aFactor
;
g
=
g
*
(
1
.
0
-
aFactor
)
+
aFactor
;
...
...
@@ -119,12 +119,12 @@ public:
}
/**
* Function
Highlight
ed
* Function
Brighten
ed
* Returns a color that is brighter by a given factor, without modifying object.
* @param aFactor Specifies how bright the color should become (valid values: 0.0 .. 1.0).
* @return COLOR4D Highlightedd color.
*/
COLOR4D
Highlight
ed
(
double
aFactor
)
const
COLOR4D
Brighten
ed
(
double
aFactor
)
const
{
return
COLOR4D
(
r
*
(
1
.
0
-
aFactor
)
+
aFactor
,
g
*
(
1
.
0
-
aFactor
)
+
aFactor
,
...
...
include/view/view_item.h
View file @
f193e389
...
...
@@ -67,8 +67,7 @@ public:
ALL
=
0xff
};
VIEW_ITEM
()
:
m_view
(
NULL
),
m_visible
(
true
),
m_highlighted
(
false
),
m_groups
(
NULL
),
m_groupsSize
(
0
)
{}
VIEW_ITEM
()
:
m_view
(
NULL
),
m_visible
(
true
),
m_groups
(
NULL
),
m_groupsSize
(
0
)
{}
/**
* Destructor. For dynamic views, removes the item from the view.
...
...
@@ -135,25 +134,6 @@ public:
return
m_visible
;
}
/**
* Function ViewSetHighlighted()
* Sets the item highlight.
*
* @param aIsHighlighted: whether the item is highlighted (on all layers), or not.
*/
void
ViewSetHighlighted
(
bool
aIsHighlighted
=
true
);
/**
* Function ViewIsHighlighted()
* Returns if the item is highlighted (or not).
*
* @return when true, the item should be displayed as highlighted.
*/
bool
ViewIsHighlighted
()
const
{
return
m_highlighted
;
}
/**
* Function ViewGetLOD()
* Returns the level of detail of the item. A level of detail is the minimal VIEW scale that
...
...
@@ -191,7 +171,6 @@ protected:
*
* @param aView[]: dynamic VIEW instance the item is being added to.
*/
void
viewAssign
(
VIEW
*
aView
)
{
// release the item from a previously assigned dynamic view (if there is any)
...
...
@@ -202,7 +181,6 @@ protected:
VIEW
*
m_view
;
///* Current dynamic view the item is assigned to.
bool
m_visible
;
///* Are we visible in the current dynamic VIEW.
bool
m_highlighted
;
///* Should item be drawn as highlighted
private
:
///* Helper for storing cached items group ids
...
...
pcbnew/pcb_painter.cpp
View file @
f193e389
...
...
@@ -143,17 +143,17 @@ void PCB_RENDER_SETTINGS::Update()
for
(
int
i
=
0
;
i
<
NB_LAYERS
;
i
++
)
{
m_layerColors
[
i
].
a
=
m_layerOpacity
;
m_layerColorsHi
[
i
]
=
m_layerColors
[
i
].
Highlight
ed
(
m_highlightFactor
);
m_layerColorsHi
[
i
]
=
m_layerColors
[
i
].
Brighten
ed
(
m_highlightFactor
);
m_layerColorsDark
[
i
]
=
m_layerColors
[
i
].
Darkened
(
1.0
-
m_highlightFactor
);
m_layerColorsSel
[
i
]
=
m_layerColors
[
i
].
Highlight
ed
(
m_selectFactor
);
m_layerColorsSel
[
i
]
=
m_layerColors
[
i
].
Brighten
ed
(
m_selectFactor
);
}
for
(
int
i
=
0
;
i
<
END_PCB_VISIBLE_LIST
;
i
++
)
{
m_itemColors
[
i
].
a
=
m_layerOpacity
;
m_itemColorsHi
[
i
]
=
m_itemColors
[
i
].
Highlight
ed
(
m_highlightFactor
);
m_itemColorsHi
[
i
]
=
m_itemColors
[
i
].
Brighten
ed
(
m_highlightFactor
);
m_itemColorsDark
[
i
]
=
m_itemColors
[
i
].
Darkened
(
1.0
-
m_highlightFactor
);
m_itemColorsSel
[
i
]
=
m_itemColors
[
i
].
Highlight
ed
(
m_selectFactor
);
m_itemColorsSel
[
i
]
=
m_itemColors
[
i
].
Brighten
ed
(
m_selectFactor
);
}
m_hiContrastColor
=
COLOR4D
(
m_hiContrastFactor
,
m_hiContrastFactor
,
m_hiContrastFactor
,
...
...
@@ -176,22 +176,23 @@ const COLOR4D& PCB_PAINTER::GetColor( const VIEW_ITEM* aItem, int aLayer )
if
(
item
)
netCode
=
item
->
GetNet
();
return
getLayerColor
(
aLayer
,
netCode
,
aItem
->
ViewIsHighlighted
()
);
return
getLayerColor
(
aLayer
,
netCode
,
static_cast
<
const
BOARD_ITEM
*>
(
aItem
)
->
IsSelected
()
);
}
const
COLOR4D
&
PCB_PAINTER
::
getLayerColor
(
int
aLayer
,
int
aNetCode
,
bool
a
Highligh
ted
)
const
const
COLOR4D
&
PCB_PAINTER
::
getLayerColor
(
int
aLayer
,
int
aNetCode
,
bool
a
Selec
ted
)
const
{
// Return grayish color for non-highlighte
z
d layers in the high contrast mode
// Return grayish color for non-highlighted layers in the high contrast mode
if
(
m_pcbSettings
->
m_hiContrastEnabled
&&
m_pcbSettings
->
m_activeLayers
.
count
(
aLayer
)
==
0
)
return
m_pcbSettings
->
m_hiContrastColor
;
// For item layers (vias, texts, and so on)
if
(
aLayer
>=
NB_LAYERS
)
return
getItemColor
(
aLayer
-
NB_LAYERS
,
aNetCode
,
a
Highligh
ted
);
return
getItemColor
(
aLayer
-
NB_LAYERS
,
aNetCode
,
a
Selec
ted
);
// Highlight per item basis
if
(
a
Highligh
ted
)
if
(
a
Selec
ted
)
return
m_pcbSettings
->
m_layerColorsHi
[
aLayer
];
// Single net highlight mode
...
...
@@ -208,10 +209,10 @@ const COLOR4D& PCB_PAINTER::getLayerColor( int aLayer, int aNetCode, bool aHighl
}
const
COLOR4D
&
PCB_PAINTER
::
getItemColor
(
int
aItemType
,
int
aNetCode
,
bool
a
Highligh
ted
)
const
const
COLOR4D
&
PCB_PAINTER
::
getItemColor
(
int
aItemType
,
int
aNetCode
,
bool
a
Selec
ted
)
const
{
// Highlight per item basis
if
(
a
Highligh
ted
)
if
(
a
Selec
ted
)
return
m_pcbSettings
->
m_itemColorsHi
[
aItemType
];
if
(
m_pcbSettings
->
m_highlightEnabled
)
...
...
@@ -308,8 +309,8 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer )
// Set a proper color for the label
color
=
getLayerColor
(
aTrack
->
GetLayer
(),
aTrack
->
GetNet
(),
aTrack
->
ViewIsHighligh
ted
()
);
COLOR4D
labelColor
=
getLayerColor
(
aLayer
,
0
,
aTrack
->
ViewIsHighligh
ted
()
);
aTrack
->
IsSelec
ted
()
);
COLOR4D
labelColor
=
getLayerColor
(
aLayer
,
0
,
aTrack
->
IsSelec
ted
()
);
if
(
color
.
GetBrightness
()
>
0.5
)
m_gal
->
SetStrokeColor
(
labelColor
.
Inverted
()
);
...
...
@@ -329,7 +330,7 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer )
else
if
(
IsCopperLayer
(
aLayer
))
{
// Draw a regular track
color
=
getLayerColor
(
aLayer
,
netNumber
,
aTrack
->
ViewIsHighligh
ted
()
);
color
=
getLayerColor
(
aLayer
,
netNumber
,
aTrack
->
IsSelec
ted
()
);
m_gal
->
SetStrokeColor
(
color
);
m_gal
->
SetIsStroke
(
true
);
...
...
@@ -368,7 +369,7 @@ void PCB_PAINTER::draw( const SEGVIA* aVia, int aLayer )
else
return
;
color
=
getLayerColor
(
aLayer
,
aVia
->
GetNet
(),
aVia
->
ViewIsHighligh
ted
()
);
color
=
getLayerColor
(
aLayer
,
aVia
->
GetNet
(),
aVia
->
IsSelec
ted
()
);
if
(
m_pcbSettings
->
m_sketchModeSelect
[
VIAS_VISIBLE
]
)
{
...
...
@@ -448,8 +449,8 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
// Set a proper color for the label
color
=
getLayerColor
(
aPad
->
GetParent
()
->
GetLayer
(),
aPad
->
GetNet
(),
aPad
->
ViewIsHighligh
ted
()
);
COLOR4D
labelColor
=
getLayerColor
(
aLayer
,
0
,
aPad
->
ViewIsHighligh
ted
()
);
aPad
->
IsSelec
ted
()
);
COLOR4D
labelColor
=
getLayerColor
(
aLayer
,
0
,
aPad
->
IsSelec
ted
()
);
if
(
color
.
GetBrightness
()
>
0.5
)
m_gal
->
SetStrokeColor
(
labelColor
.
Inverted
()
);
...
...
@@ -494,7 +495,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
return
;
}
color
=
getLayerColor
(
aLayer
,
aPad
->
GetNet
(),
aPad
->
ViewIsHighligh
ted
()
);
color
=
getLayerColor
(
aLayer
,
aPad
->
GetNet
(),
aPad
->
IsSelec
ted
()
);
if
(
m_pcbSettings
->
m_sketchModeSelect
[
PADS_VISIBLE
]
)
{
// Outline mode
...
...
@@ -617,7 +618,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
void
PCB_PAINTER
::
draw
(
const
DRAWSEGMENT
*
aSegment
)
{
COLOR4D
color
=
getLayerColor
(
aSegment
->
GetLayer
(),
0
,
aSegment
->
ViewIsHighligh
ted
()
);
COLOR4D
color
=
getLayerColor
(
aSegment
->
GetLayer
(),
0
,
aSegment
->
IsSelec
ted
()
);
m_gal
->
SetIsFill
(
false
);
m_gal
->
SetIsStroke
(
true
);
...
...
@@ -691,7 +692,7 @@ void PCB_PAINTER::draw( const TEXTE_PCB* aText )
if
(
aText
->
GetText
().
Length
()
==
0
)
return
;
COLOR4D
strokeColor
=
getLayerColor
(
aText
->
GetLayer
(),
0
,
aText
->
ViewIsHighligh
ted
()
);
COLOR4D
strokeColor
=
getLayerColor
(
aText
->
GetLayer
(),
0
,
aText
->
IsSelec
ted
()
);
VECTOR2D
position
(
aText
->
GetTextPosition
().
x
,
aText
->
GetTextPosition
().
y
);
double
orientation
=
aText
->
GetOrientation
()
*
M_PI
/
1800.0
;
...
...
@@ -707,13 +708,13 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer )
if
(
aText
->
GetLength
()
==
0
)
return
;
COLOR4D
strokeColor
=
getLayerColor
(
aLayer
,
0
,
aText
->
ViewIsHighligh
ted
()
);
COLOR4D
strokeColor
=
getLayerColor
(
aLayer
,
0
,
aText
->
IsSelec
ted
()
);
VECTOR2D
position
(
aText
->
GetTextPosition
().
x
,
aText
->
GetTextPosition
().
y
);
double
orientation
=
aText
->
GetDrawRotation
()
*
M_PI
/
1800.0
;
m_gal
->
PushDepth
();
if
(
aText
->
ViewIsHighligh
ted
())
if
(
aText
->
IsSelec
ted
())
{
EDA_RECT
bb
(
aText
->
GetBoundingBox
());
VECTOR2D
s
(
bb
.
GetOrigin
());
...
...
@@ -741,7 +742,7 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer )
void
PCB_PAINTER
::
draw
(
const
ZONE_CONTAINER
*
aZone
)
{
COLOR4D
color
=
getLayerColor
(
aZone
->
GetLayer
(),
aZone
->
GetNet
(),
aZone
->
ViewIsHighligh
ted
()
);
aZone
->
IsSelec
ted
()
);
std
::
deque
<
VECTOR2D
>
corners
;
PCB_RENDER_SETTINGS
::
DisplayZonesMode
displayMode
=
m_pcbSettings
->
m_displayZoneMode
;
...
...
@@ -811,7 +812,7 @@ void PCB_PAINTER::draw( const ZONE_CONTAINER* aZone )
void
PCB_PAINTER
::
draw
(
const
DIMENSION
*
aDimension
)
{
COLOR4D
strokeColor
=
getLayerColor
(
aDimension
->
GetLayer
(),
0
,
aDimension
->
ViewIsHighligh
ted
()
);
aDimension
->
IsSelec
ted
()
);
m_gal
->
SetStrokeColor
(
strokeColor
);
m_gal
->
SetIsFill
(
false
);
...
...
@@ -834,7 +835,7 @@ void PCB_PAINTER::draw( const DIMENSION* aDimension )
void
PCB_PAINTER
::
draw
(
const
PCB_TARGET
*
aTarget
)
{
COLOR4D
strokeColor
=
getLayerColor
(
aTarget
->
GetLayer
(),
0
,
aTarget
->
ViewIsHighligh
ted
()
);
COLOR4D
strokeColor
=
getLayerColor
(
aTarget
->
GetLayer
(),
0
,
aTarget
->
IsSelec
ted
()
);
VECTOR2D
position
(
aTarget
->
GetPosition
()
);
double
size
,
radius
;
...
...
pcbnew/tools/selection_tool.cpp
View file @
f193e389
...
...
@@ -41,99 +41,104 @@
using
namespace
KiGfx
;
using
boost
::
optional
;
SELECTION_TOOL
::
SELECTION_TOOL
()
:
TOOL_INTERACTIVE
(
"pcbnew.InteractiveSelection"
)
{
m_selArea
=
new
SELECTION_AREA
;
}
TOOL_INTERACTIVE
(
"pcbnew.InteractiveSelection"
)
{
m_selArea
=
new
SELECTION_AREA
;
}
SELECTION_TOOL
::~
SELECTION_TOOL
()
{
if
(
m_selArea
)
delete
m_selArea
;
if
(
m_selArea
)
delete
m_selArea
;
}
void
SELECTION_TOOL
::
Reset
()
{
// the tool launches upon reception of activate ("pcbnew.InteractiveSelection")
Go
(
&
SELECTION_TOOL
::
Main
,
TOOL_EVENT
(
TC_Command
,
TA_ActivateTool
,
GetName
())
);
//"pcbnew.InteractiveSelection"));
// the tool launches upon reception of activate ("pcbnew.InteractiveSelection")
Go
(
&
SELECTION_TOOL
::
Main
,
TOOL_EVENT
(
TC_Command
,
TA_ActivateTool
,
GetName
()
)
);
//"pcbnew.InteractiveSelection"));
}
int
SELECTION_TOOL
::
Main
(
TOOL_EVENT
&
aEvent
)
int
SELECTION_TOOL
::
Main
(
TOOL_EVENT
&
aEvent
)
{
// Main loop: keep receiving events
while
(
OPT_TOOL_EVENT
evt
=
Wait
()
)
{
if
(
evt
->
IsCancel
()
)
return
0
;
// single click? Select single object
if
(
evt
->
IsClick
(
MB_Left
)
)
selectSingle
(
evt
->
Position
(),
evt
->
Modifier
(
MB_ModShift
)
);
// drag with LMB? Select multiple objects (or at least draw a selection box)
if
(
evt
->
IsDrag
(
MB_Left
)
)
selectMultiple
();
}
return
0
;
// Main loop: keep receiving events
while
(
OPT_TOOL_EVENT
evt
=
Wait
()
)
{
if
(
evt
->
IsCancel
()
)
return
0
;
// single click? Select single object
if
(
evt
->
IsClick
(
MB_Left
)
)
selectSingle
(
evt
->
Position
(),
evt
->
Modifier
(
MB_ModShift
)
);
// drag with LMB? Select multiple objects (or at least draw a selection box)
if
(
evt
->
IsDrag
(
MB_Left
)
)
selectMultiple
();
}
return
0
;
}
void
SELECTION_TOOL
::
toggleSelection
(
BOARD_ITEM
*
aItem
,
bool
aAdditive
)
void
SELECTION_TOOL
::
toggleSelection
(
BOARD_ITEM
*
aItem
,
bool
aAdditive
)
{
if
(
m_selectedItems
.
find
(
aItem
)
!=
m_selectedItems
.
end
())
if
(
m_selectedItems
.
find
(
aItem
)
!=
m_selectedItems
.
end
()
)
{
aItem
->
ClearSelected
();
m_selectedItems
.
erase
(
aItem
);
}
else
{
aItem
->
ViewSetHighlighted
(
false
);
m_selectedItems
.
erase
(
aItem
);
}
else
{
if
(
!
aAdditive
)
clearSelection
();
aItem
->
ViewSetHighlighted
(
true
);
m_selectedItems
.
insert
(
aItem
);
if
(
!
aAdditive
)
clearSelection
();
aItem
->
SetSelected
();
m_selectedItems
.
insert
(
aItem
);
}
}
void
SELECTION_TOOL
::
clearSelection
()
void
SELECTION_TOOL
::
clearSelection
()
{
BOOST_FOREACH
(
BOARD_ITEM
*
item
,
m_selectedItems
)
BOOST_FOREACH
(
BOARD_ITEM
*
item
,
m_selectedItems
)
{
item
->
ViewSetHighlighted
(
false
);
}
item
->
ClearSelected
(
);
}
m_selectedItems
.
clear
();
m_selectedItems
.
clear
();
}
void
SELECTION_TOOL
::
selectSingle
(
const
VECTOR2I
&
aWhere
,
bool
aAdditive
)
{
BOARD
*
pcb
=
getModel
<
BOARD
>
(
PCB_T
);
BOARD_ITEM
*
item
;
BOARD
*
pcb
=
getModel
<
BOARD
>
(
PCB_T
);
BOARD_ITEM
*
item
;
GENERAL_COLLECTORS_GUIDE
guide
=
getEditFrame
<
PCB_EDIT_FRAME
>
()
->
GetCollectorsGuide
();
GENERAL_COLLECTOR
collector
;
collector
.
Collect
(
pcb
,
GENERAL_COLLECTOR
::
AllBoardItems
,
wxPoint
(
aWhere
.
x
,
aWhere
.
y
),
guide
);
collector
.
Collect
(
pcb
,
GENERAL_COLLECTOR
::
AllBoardItems
,
wxPoint
(
aWhere
.
x
,
aWhere
.
y
),
guide
);
switch
(
collector
.
GetCount
())
{
case
0
:
if
(
!
aAdditive
)
clearSelection
();
break
;
case
1
:
toggleSelection
(
collector
[
0
],
aAdditive
);
break
;
default
:
item
=
disambiguationMenu
(
&
collector
);
if
(
item
)
toggleSelection
(
item
,
aAdditive
);
break
;
case
0
:
if
(
!
aAdditive
)
clearSelection
();
break
;
case
1
:
toggleSelection
(
collector
[
0
],
aAdditive
);
break
;
default
:
item
=
disambiguationMenu
(
&
collector
);
if
(
item
)
toggleSelection
(
item
,
aAdditive
);
break
;
}
}
...
...
@@ -141,27 +146,27 @@ void SELECTION_TOOL::selectSingle( const VECTOR2I &aWhere, bool aAdditive )
BOARD_ITEM
*
SELECTION_TOOL
::
pickSmallestComponent
(
GENERAL_COLLECTOR
*
aCollector
)
{
int
count
=
aCollector
->
GetPrimaryCount
();
// try to use preferred layer
if
(
0
==
count
)
count
=
aCollector
->
GetCount
();
if
(
0
==
count
)
count
=
aCollector
->
GetCount
();
for
(
int
i
=
0
;
i
<
count
;
++
i
)
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
if
(
(
*
aCollector
)[
i
]
->
Type
()
!=
PCB_MODULE_T
)
if
(
(
*
aCollector
)[
i
]
->
Type
()
!=
PCB_MODULE_T
)
return
NULL
;
}
// all are modules, now find smallest MODULE
// All are modules, now find smallest MODULE
int
minDim
=
0x7FFFFFFF
;
int
minNdx
=
0
;
for
(
int
i
=
0
;
i
<
count
;
++
i
)
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
MODULE
*
module
=
(
MODULE
*
)
(
*
aCollector
)[
i
];
MODULE
*
module
=
(
MODULE
*
)
(
*
aCollector
)[
i
];
int
lx
=
module
->
GetBoundingBox
().
GetWidth
();
int
ly
=
module
->
GetBoundingBox
().
GetHeight
();
int
lx
=
module
->
GetBoundingBox
().
GetWidth
();
int
ly
=
module
->
GetBoundingBox
().
GetHeight
();
int
lmin
=
std
::
min
(
lx
,
ly
);
int
lmin
=
std
::
min
(
lx
,
ly
);
if
(
lmin
<
minDim
)
{
...
...
@@ -170,107 +175,103 @@ BOARD_ITEM* SELECTION_TOOL::pickSmallestComponent( GENERAL_COLLECTOR* aCollector
}
}
return
(
*
aCollector
)[
minNdx
];
return
(
*
aCollector
)[
minNdx
];
}
void
SELECTION_TOOL
::
handleHighlight
(
const
VECTOR2D
&
aP
)
{
}
void
SELECTION_TOOL
::
selectMultiple
()
{
OPT_TOOL_EVENT
evt
;
VIEW
*
v
=
getView
();
v
->
Add
(
m_selArea
);
while
(
evt
=
Wait
())
{
if
(
evt
->
IsCancel
())
break
;
if
(
evt
->
IsDrag
(
MB_Left
))
{
m_selArea
->
SetOrigin
(
evt
->
DragOrigin
()
);
m_selArea
->
SetEnd
(
evt
->
Position
()
);
m_selArea
->
ViewSetVisible
(
true
);
m_selArea
->
ViewUpdate
(
VIEW_ITEM
::
APPEARANCE
|
VIEW_ITEM
::
GEOMETRY
);
v
->
SetLayerVisible
(
SELECTION_AREA
::
SelectionLayer
);
v
->
SetLayerOrder
(
SELECTION_AREA
::
SelectionLayer
,
1000
);
v
->
SetLayerTarget
(
SELECTION_AREA
::
SelectionLayer
,
TARGET_OVERLAY
);
}
if
(
evt
->
IsMouseUp
(
MB_Left
))
{
m_selArea
->
ViewSetVisible
(
false
);
break
;
}
}
v
->
Remove
(
m_selArea
);
OPT_TOOL_EVENT
evt
;
VIEW
*
v
=
getView
();
v
->
Add
(
m_selArea
);
while
(
evt
=
Wait
()
)
{
if
(
evt
->
IsCancel
()
)
break
;
if
(
evt
->
IsDrag
(
MB_Left
)
)
{
m_selArea
->
SetOrigin
(
evt
->
DragOrigin
()
);
m_selArea
->
SetEnd
(
evt
->
Position
()
);
m_selArea
->
ViewSetVisible
(
true
);
m_selArea
->
ViewUpdate
(
VIEW_ITEM
::
APPEARANCE
|
VIEW_ITEM
::
GEOMETRY
);
v
->
SetLayerVisible
(
SELECTION_AREA
::
SelectionLayer
);
v
->
SetLayerOrder
(
SELECTION_AREA
::
SelectionLayer
,
1000
);
v
->
SetLayerTarget
(
SELECTION_AREA
::
SelectionLayer
,
TARGET_OVERLAY
);
}
if
(
evt
->
IsMouseUp
(
MB_Left
)
)
{
m_selArea
->
ViewSetVisible
(
false
);
break
;
}
}
v
->
Remove
(
m_selArea
);
}
BOARD_ITEM
*
SELECTION_TOOL
::
disambiguationMenu
(
GENERAL_COLLECTOR
*
aCollector
)
BOARD_ITEM
*
SELECTION_TOOL
::
disambiguationMenu
(
GENERAL_COLLECTOR
*
aCollector
)
{
CONTEXT_MENU
cmenu
;
OPT_TOOL_EVENT
evt
;
BOARD_ITEM
*
current
=
NULL
;
cmenu
.
SetTitle
(
_
(
"Clarify selection"
));
int
limit
=
std
::
min
(
10
,
aCollector
->
GetCount
()
);
for
(
int
i
=
0
;
i
<
limit
;
++
i
)
{
wxString
text
;
BOARD_ITEM
*
item
=
(
*
aCollector
)
[
i
];
text
=
item
->
GetSelectMenuText
();
cmenu
.
Add
(
text
,
i
);
}
SetContextMenu
(
&
cmenu
,
CMENU_NOW
);
while
(
evt
=
Wait
())
{
if
(
evt
->
Action
()
==
TA_ContextMenuUpdate
)
{
if
(
current
)
current
->
ViewSetHighlighted
(
false
);
int
id
=
*
evt
->
GetCommandId
();
if
(
id
>=
0
)
{
current
=
(
*
aCollector
)
[
id
];
current
->
ViewSetHighlighted
(
true
);
}
else
current
=
NULL
;
}
else
if
(
evt
->
Action
()
==
TA_ContextMenuChoice
)
{
optional
<
int
>
id
=
evt
->
GetCommandId
();
if
(
current
)
current
->
ViewSetHighlighted
(
false
);
if
(
id
&&
(
*
id
>=
0
))
{
current
=
(
*
aCollector
)
[
*
id
];
current
->
ViewSetHighlighted
(
true
);
return
current
;
}
return
NULL
;
}
}
return
NULL
;
}
\ No newline at end of file
CONTEXT_MENU
cmenu
;
OPT_TOOL_EVENT
evt
;
BOARD_ITEM
*
current
=
NULL
;
cmenu
.
SetTitle
(
_
(
"Clarify selection"
)
);
int
limit
=
std
::
min
(
10
,
aCollector
->
GetCount
()
);
for
(
int
i
=
0
;
i
<
limit
;
++
i
)
{
wxString
text
;
BOARD_ITEM
*
item
=
(
*
aCollector
)[
i
];
text
=
item
->
GetSelectMenuText
();
cmenu
.
Add
(
text
,
i
);
}
SetContextMenu
(
&
cmenu
,
CMENU_NOW
);
while
(
evt
=
Wait
()
)
{
if
(
evt
->
Action
()
==
TA_ContextMenuUpdate
)
{
if
(
current
)
current
->
ClearSelected
();
int
id
=
*
evt
->
GetCommandId
();
if
(
id
>=
0
)
{
current
=
(
*
aCollector
)[
id
];
current
->
SetSelected
();
}
else
current
=
NULL
;
}
else
if
(
evt
->
Action
()
==
TA_ContextMenuChoice
)
{
optional
<
int
>
id
=
evt
->
GetCommandId
();
if
(
current
)
current
->
ClearSelected
();
if
(
id
&&
(
*
id
>=
0
)
)
{
current
=
(
*
aCollector
)[
*
id
];
current
->
SetSelected
();
return
current
;
}
return
NULL
;
}
}
return
NULL
;
}
pcbnew/tools/selection_tool.h
View file @
f193e389
...
...
@@ -36,7 +36,7 @@ class GENERAL_COLLECTOR;
/**
* Class SELECTION_
AREA
* Class SELECTION_
TOOL
*
* Our sample selection tool: currently supports:
* - pick single objects (click LMB)
...
...
@@ -48,24 +48,24 @@ class GENERAL_COLLECTOR;
class
SELECTION_TOOL
:
public
TOOL_INTERACTIVE
{
public
:
SELECTION_TOOL
();
~
SELECTION_TOOL
();
public
:
SELECTION_TOOL
();
~
SELECTION_TOOL
();
void
Reset
();
int
Main
(
TOOL_EVENT
&
aEvent
);
void
Reset
();
int
Main
(
TOOL_EVENT
&
aEvent
);
private
:
void
selectSingle
(
const
VECTOR2I
&
aWhere
,
bool
aAdditive
);
void
selectMultiple
();
void
handleHighlight
(
const
VECTOR2D
&
aP
);
BOARD_ITEM
*
disambiguationMenu
(
GENERAL_COLLECTOR
*
aItems
);
BOARD_ITEM
*
pickSmallestComponent
(
GENERAL_COLLECTOR
*
aCollector
);
void
toggleSelection
(
BOARD_ITEM
*
aItem
,
bool
aAdditive
);
void
clearSelection
();
std
::
set
<
BOARD_ITEM
*>
m_selectedItems
;
SELECTION_AREA
*
m_selArea
;
private
:
void
selectSingle
(
const
VECTOR2I
&
aWhere
,
bool
aAdditive
);
void
selectMultiple
();
void
handleHighlight
(
const
VECTOR2D
&
aP
);
BOARD_ITEM
*
disambiguationMenu
(
GENERAL_COLLECTOR
*
aItems
);
BOARD_ITEM
*
pickSmallestComponent
(
GENERAL_COLLECTOR
*
aCollector
);
void
toggleSelection
(
BOARD_ITEM
*
aItem
,
bool
aAdditive
);
void
clearSelection
();
std
::
set
<
BOARD_ITEM
*>
m_selectedItems
;
SELECTION_AREA
*
m_selArea
;
};
#endif
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