Commit f193e389 authored by Maciej Suminski's avatar Maciej Suminski

Moved highlighted flag from VIEW_ITEM to EDA_ITEM. Added brightened and selected flag to EDA_ITEM.

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