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

This commit is contained in:
Maciej Suminski 2013-08-06 09:31:08 +02:00
parent 8753bef2fa
commit f193e389ec
7 changed files with 212 additions and 226 deletions

View File

@ -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 );
}

View File

@ -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();

View File

@ -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 Highlighted
* Function Brightened
* 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 Highlighted( double aFactor ) const
COLOR4D Brightened( double aFactor ) const
{
return COLOR4D( r * ( 1.0 - aFactor ) + aFactor,
g * ( 1.0 - aFactor ) + aFactor,

View File

@ -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

View File

@ -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].Highlighted( m_highlightFactor );
m_layerColorsHi[i] = m_layerColors[i].Brightened( 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++ )
{
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_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,
@ -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 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 )
return m_pcbSettings->m_hiContrastColor;
// For item layers (vias, texts, and so on)
if( aLayer >= NB_LAYERS )
return getItemColor( aLayer - NB_LAYERS, aNetCode, aHighlighted );
return getItemColor( aLayer - NB_LAYERS, aNetCode, aSelected );
// Highlight per item basis
if( aHighlighted )
if( aSelected )
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 aHighlighted ) const
const COLOR4D& PCB_PAINTER::getItemColor( int aItemType, int aNetCode, bool aSelected ) const
{
// Highlight per item basis
if( aHighlighted )
if( aSelected )
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->ViewIsHighlighted() );
COLOR4D labelColor = getLayerColor( aLayer, 0, aTrack->ViewIsHighlighted() );
aTrack->IsSelected() );
COLOR4D labelColor = getLayerColor( aLayer, 0, aTrack->IsSelected() );
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->ViewIsHighlighted() );
color = getLayerColor( aLayer, netNumber, aTrack->IsSelected() );
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->ViewIsHighlighted() );
color = getLayerColor( aLayer, aVia->GetNet(), aVia->IsSelected() );
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->ViewIsHighlighted() );
COLOR4D labelColor = getLayerColor( aLayer, 0, aPad->ViewIsHighlighted() );
aPad->IsSelected() );
COLOR4D labelColor = getLayerColor( aLayer, 0, aPad->IsSelected() );
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->ViewIsHighlighted() );
color = getLayerColor( aLayer, aPad->GetNet(), aPad->IsSelected() );
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->ViewIsHighlighted() );
COLOR4D color = getLayerColor( aSegment->GetLayer(), 0, aSegment->IsSelected() );
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->ViewIsHighlighted() );
COLOR4D strokeColor = getLayerColor( aText->GetLayer(), 0, aText->IsSelected() );
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->ViewIsHighlighted() );
COLOR4D strokeColor = getLayerColor( aLayer, 0, aText->IsSelected() );
VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y);
double orientation = aText->GetDrawRotation() * M_PI / 1800.0;
m_gal->PushDepth();
if(aText->ViewIsHighlighted())
if(aText->IsSelected())
{
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->ViewIsHighlighted() );
aZone->IsSelected() );
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->ViewIsHighlighted() );
aDimension->IsSelected() );
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->ViewIsHighlighted() );
COLOR4D strokeColor = getLayerColor( aTarget->GetLayer(), 0, aTarget->IsSelected() );
VECTOR2D position( aTarget->GetPosition() );
double size, radius;

View File

@ -41,12 +41,10 @@
using namespace KiGfx;
using boost::optional;
SELECTION_TOOL::SELECTION_TOOL() :
TOOL_INTERACTIVE( "pcbnew.InteractiveSelection" )
{
m_selArea = new SELECTION_AREA;
}
@ -63,6 +61,7 @@ void SELECTION_TOOL::Reset()
Go( &SELECTION_TOOL::Main, TOOL_EVENT( TC_Command, TA_ActivateTool, GetName() ) ); //"pcbnew.InteractiveSelection"));
}
int SELECTION_TOOL::Main( TOOL_EVENT& aEvent )
{
@ -85,26 +84,29 @@ int SELECTION_TOOL::Main(TOOL_EVENT& aEvent)
return 0;
}
void SELECTION_TOOL::toggleSelection( BOARD_ITEM* aItem, bool aAdditive )
{
if( m_selectedItems.find( aItem ) != m_selectedItems.end() )
{
aItem->ViewSetHighlighted(false);
aItem->ClearSelected();
m_selectedItems.erase( aItem );
} else {
} else
{
if( !aAdditive )
clearSelection();
aItem->ViewSetHighlighted(true);
aItem->SetSelected();
m_selectedItems.insert( aItem );
}
}
void SELECTION_TOOL::clearSelection()
{
BOOST_FOREACH(BOARD_ITEM* item, m_selectedItems)
{
item->ViewSetHighlighted(false);
item->ClearSelected();
}
m_selectedItems.clear();
@ -118,7 +120,8 @@ void SELECTION_TOOL::selectSingle( const VECTOR2I &aWhere, bool aAdditive )
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())
{
@ -126,9 +129,11 @@ void SELECTION_TOOL::selectSingle( const VECTOR2I &aWhere, bool aAdditive )
if( !aAdditive )
clearSelection();
break;
case 1:
toggleSelection( collector[0], aAdditive );
break;
default:
item = disambiguationMenu( &collector );
if( item )
@ -141,7 +146,8 @@ 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 )
{
@ -149,8 +155,7 @@ BOARD_ITEM* SELECTION_TOOL::pickSmallestComponent( GENERAL_COLLECTOR* aCollector
return NULL;
}
// all are modules, now find smallest MODULE
// All are modules, now find smallest MODULE
int minDim = 0x7FFFFFFF;
int minNdx = 0;
@ -173,11 +178,12 @@ BOARD_ITEM* SELECTION_TOOL::pickSmallestComponent( GENERAL_COLLECTOR* aCollector
return ( *aCollector )[minNdx];
}
void SELECTION_TOOL::handleHighlight( const VECTOR2D& aP )
{
}
void SELECTION_TOOL::selectMultiple()
{
OPT_TOOL_EVENT evt;
@ -197,7 +203,6 @@ void SELECTION_TOOL::selectMultiple()
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 );
@ -210,7 +215,6 @@ void SELECTION_TOOL::selectMultiple()
}
}
v->Remove( m_selArea );
}
@ -237,39 +241,36 @@ BOARD_ITEM *SELECTION_TOOL::disambiguationMenu ( GENERAL_COLLECTOR *aCollector )
while( evt = Wait() )
{
if( evt->Action() == TA_ContextMenuUpdate )
{
if( current )
current->ViewSetHighlighted(false);
current->ClearSelected();
int id = *evt->GetCommandId();
if( id >= 0 )
{
current = ( *aCollector )[id];
current->ViewSetHighlighted(true);
current->SetSelected();
} else
current = NULL;
} else if(evt->Action() == TA_ContextMenuChoice ) {
} else if( evt->Action() == TA_ContextMenuChoice )
{
optional<int> id = evt->GetCommandId();
if( current )
current->ViewSetHighlighted(false);
current->ClearSelected();
if( id && ( *id >= 0 ) )
{
current = ( *aCollector )[*id];
current->ViewSetHighlighted(true);
current->SetSelected();
return current;
}
return NULL;
}
}
return NULL;

View File

@ -36,7 +36,7 @@ class GENERAL_COLLECTOR;
/**
* Class SELECTION_AREA
* Class SELECTION_TOOL
*
* Our sample selection tool: currently supports:
* - pick single objects (click LMB)