Commit cbec733d authored by Maciej Suminski's avatar Maciej Suminski

Refactored code responsible for high contrast mode. Now it allows to have more...

Refactored code responsible for high contrast mode. Now it allows to have more than one layer on the top.
Selecting layer using the dropdown list on the toolbar influences the layer displayed in high contrast mode.
parent 20c86db7
...@@ -39,11 +39,6 @@ ...@@ -39,11 +39,6 @@
using namespace KiGfx; using namespace KiGfx;
// Static constants
const int VIEW::VIEW_MAX_LAYERS = 64;
// Top layer depth
const int VIEW::TOP_LAYER = -1;
void VIEW::AddLayer( int aLayer, bool aDisplayOnly ) void VIEW::AddLayer( int aLayer, bool aDisplayOnly )
{ {
if( m_layers.find( aLayer ) == m_layers.end() ) if( m_layers.find( aLayer ) == m_layers.end() )
...@@ -140,14 +135,12 @@ int VIEW::Query( const BOX2I& aRect, std::vector<LayerItemPair>& aResult ) ...@@ -140,14 +135,12 @@ int VIEW::Query( const BOX2I& aRect, std::vector<LayerItemPair>& aResult )
VIEW::VIEW( bool aIsDynamic ) : VIEW::VIEW( bool aIsDynamic ) :
m_enableTopLayer( false ), m_enableOrderModifier( false ),
m_scale ( 1.0 ), m_scale ( 1.0 ),
m_painter( NULL ), m_painter( NULL ),
m_gal( NULL ), m_gal( NULL ),
m_dynamic( aIsDynamic ) m_dynamic( aIsDynamic )
{ {
// By default there is no layer on the top
m_topLayer.enabled = false;
} }
...@@ -395,63 +388,75 @@ void VIEW::ChangeLayerDepth( int aLayer, int aDepth ) ...@@ -395,63 +388,75 @@ void VIEW::ChangeLayerDepth( int aLayer, int aDepth )
} }
void VIEW::SetTopLayer( int aLayer ) void VIEW::SetTopLayer( int aLayer, bool aEnabled )
{ {
// Restore previous order if( aEnabled )
if( m_topLayer.enabled )
{ {
m_layers[m_topLayer.id].renderingOrder = m_topLayer.renderingOrder; if( m_topLayers.count( aLayer ) == 1 )
ChangeLayerDepth( m_topLayer.id, m_topLayer.renderingOrder ); return;
}
if( aLayer >= 0 && aLayer < VIEW_MAX_LAYERS ) m_topLayers.insert( aLayer );
// Move the layer closer to front
if( m_enableOrderModifier )
m_layers[aLayer].renderingOrder += TOP_LAYER_MODIFIER;
}
else
{ {
// Save settings, so it can be restored later if( m_topLayers.count( aLayer ) == 0 )
m_topLayer.renderingOrder = m_layers[aLayer].renderingOrder; return;
m_topLayer.id = m_layers[aLayer].id;
// Apply new settings only if the option is enabled m_topLayers.erase( aLayer );
if( m_enableTopLayer )
{
m_layers[aLayer].renderingOrder = TOP_LAYER;
ChangeLayerDepth( aLayer, TOP_LAYER );
}
// Set the flag saying that settings stored in m_topLayer are valid // Restore the previous rendering order
m_topLayer.enabled = true; if( m_enableOrderModifier )
m_layers[aLayer].renderingOrder -= TOP_LAYER_MODIFIER;
}
}
void VIEW::EnableTopLayer( bool aEnable )
{
if( aEnable == m_enableOrderModifier ) return;
m_enableOrderModifier = aEnable;
std::set<unsigned int>::iterator it;
if( aEnable )
{
for( it = m_topLayers.begin(); it != m_topLayers.end(); ++it )
m_layers[*it].renderingOrder += TOP_LAYER_MODIFIER;
} }
else else
{ {
// There are no valid settings in m_topLayer for( it = m_topLayers.begin(); it != m_topLayers.end(); ++it )
m_topLayer.enabled = false; m_layers[*it].renderingOrder -= TOP_LAYER_MODIFIER;
} }
sortLayers();
} }
void VIEW::EnableTopLayer( bool aEnable ) void VIEW::ClearTopLayers()
{ {
if( aEnable == m_enableTopLayer ) return; std::set<unsigned int>::iterator it;
// Use stored settings only if applicable if( m_enableOrderModifier )
// (topLayer.enabled == false means there are no valid settings stored)
if( m_topLayer.enabled )
{ {
if( aEnable ) // Restore the previous rendering order for layers that were marked as top
{ for( it = m_topLayers.begin(); it != m_topLayers.end(); ++it )
m_layers[m_topLayer.id].renderingOrder = TOP_LAYER; m_layers[*it].renderingOrder -= TOP_LAYER_MODIFIER;
ChangeLayerDepth( m_topLayer.id, TOP_LAYER );
}
else
{
m_layers[m_topLayer.id].renderingOrder = m_topLayer.renderingOrder;
ChangeLayerDepth( m_topLayer.id, m_topLayer.renderingOrder );
}
} }
m_topLayers.clear();
}
void VIEW::UpdateAllLayersOrder()
{
sortLayers(); sortLayers();
m_enableTopLayer = aEnable; BOOST_FOREACH( LayerMap::value_type& l, m_layers )
{
ChangeLayerDepth( l.first, l.second.renderingOrder );
}
} }
...@@ -513,7 +518,7 @@ void VIEW::redrawRect( const BOX2I& aRect ) ...@@ -513,7 +518,7 @@ void VIEW::redrawRect( const BOX2I& aRect )
{ {
drawItem drawFunc( this, l ); drawItem drawFunc( this, l );
m_gal->SetLayerDepth( static_cast<double>( l->renderingOrder ) ); m_gal->SetLayerDepth( l->renderingOrder );
l->items->Query( aRect, drawFunc ); l->items->Query( aRect, drawFunc );
l->isDirty = false; l->isDirty = false;
} }
...@@ -703,7 +708,7 @@ void VIEW::RecacheAllItems( bool aImmediately ) ...@@ -703,7 +708,7 @@ void VIEW::RecacheAllItems( bool aImmediately )
if( l->cached ) if( l->cached )
{ {
m_gal->SetLayerDepth( (double) l->renderingOrder ); m_gal->SetLayerDepth( l->renderingOrder );
recacheLayer visitor( this, m_gal, l->id, aImmediately ); recacheLayer visitor( this, m_gal, l->id, aImmediately );
l->items->Query( r, visitor ); l->items->Query( r, visitor );
} }
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#define __VIEW_H #define __VIEW_H
#include <vector> #include <vector>
#include <set>
#include <boost/unordered/unordered_map.hpp> #include <boost/unordered/unordered_map.hpp>
#include <math/box2.h> #include <math/box2.h>
...@@ -305,7 +306,7 @@ public: ...@@ -305,7 +306,7 @@ public:
* @param aLayer: the layer or -1 in case when no particular layer should * @param aLayer: the layer or -1 in case when no particular layer should
* be displayed on the top. * be displayed on the top.
*/ */
void SetTopLayer( int aLayer ); void SetTopLayer( int aLayer, bool aEnabled = true );
/** /**
* Function EnableTopLayer() * Function EnableTopLayer()
...@@ -316,6 +317,20 @@ public: ...@@ -316,6 +317,20 @@ public:
*/ */
void EnableTopLayer( bool aEnable ); void EnableTopLayer( bool aEnable );
/**
* Function ClearTopLayers()
* Removes all layers from the on-the-top set (they are no longer displayed over the rest of
* layers).
*/
void ClearTopLayers();
/**
* Function UpdateLayerOrder()
* Does everything that is needed to apply the rendering order of layers. It has to be called
* after modification of renderingOrder field of LAYER.
*/
void UpdateAllLayersOrder();
/** /**
* Function Redraw() * Function Redraw()
* Immediately redraws the whole view. * Immediately redraws the whole view.
...@@ -344,8 +359,7 @@ public: ...@@ -344,8 +359,7 @@ public:
*/ */
bool IsDynamic() const { return m_dynamic; } bool IsDynamic() const { return m_dynamic; }
static const int VIEW_MAX_LAYERS; ///* maximum number of layers that may be shown static const int VIEW_MAX_LAYERS = 64; ///* maximum number of layers that may be shown
static const int TOP_LAYER; ///* layer number for displaying items on the top
private: private:
struct VIEW_LAYER struct VIEW_LAYER
...@@ -377,11 +391,8 @@ private: ...@@ -377,11 +391,8 @@ private:
struct updateItemsColor; struct updateItemsColor;
struct changeItemsDepth; struct changeItemsDepth;
///* Saves current top layer settings in order to restore it when it's not top anymore ///* Whether to use rendering order modifier or not
VIEW_LAYER m_topLayer; bool m_enableOrderModifier;
///* Whether to use top layer settings or not
bool m_enableTopLayer;
///* Redraws contents within rect aRect ///* Redraws contents within rect aRect
void redrawRect( const BOX2I& aRect ); void redrawRect( const BOX2I& aRect );
...@@ -412,6 +423,9 @@ private: ...@@ -412,6 +423,9 @@ private:
/// Sorted list of pointers to members of m_layers. /// Sorted list of pointers to members of m_layers.
LayerOrder m_orderedLayers; LayerOrder m_orderedLayers;
/// Stores set of layers that are displayed on the top
std::set<unsigned int> m_topLayers;
/// Center point of the VIEW (the point at which we are looking at) /// Center point of the VIEW (the point at which we are looking at)
VECTOR2D m_center; VECTOR2D m_center;
...@@ -427,6 +441,9 @@ private: ...@@ -427,6 +441,9 @@ private:
/// Dynamic VIEW (eg. display PCB in window) allows changes once it is built, /// Dynamic VIEW (eg. display PCB in window) allows changes once it is built,
/// static (eg. image/PDF) - does not. /// static (eg. image/PDF) - does not.
bool m_dynamic; bool m_dynamic;
/// Rendering order modifier for layers that are marked as top layers
static const int TOP_LAYER_MODIFIER = -VIEW_MAX_LAYERS;
}; };
} // namespace KiGfx } // namespace KiGfx
......
...@@ -133,13 +133,7 @@ protected: ...@@ -133,13 +133,7 @@ protected:
* will change the currently active layer to \a aLayer and also * will change the currently active layer to \a aLayer and also
* update the PCB_LAYER_WIDGET. * update the PCB_LAYER_WIDGET.
*/ */
void setActiveLayer( LAYER_NUM aLayer, bool doLayerWidgetUpdate = true ) void setActiveLayer( LAYER_NUM aLayer, bool doLayerWidgetUpdate = true );
{
( (PCB_SCREEN*) GetScreen() )->m_Active_Layer = aLayer;
if( doLayerWidgetUpdate )
syncLayerWidgetLayer();
}
/** /**
* Function getActiveLayer * Function getActiveLayer
......
...@@ -258,13 +258,9 @@ void PCB_BASE_FRAME::SetBoard( BOARD* aBoard ) ...@@ -258,13 +258,9 @@ void PCB_BASE_FRAME::SetBoard( BOARD* aBoard )
view->SetLayerVisible( ITEM_GAL_LAYER( i ), m_Pcb->IsElementVisible( i ) ); view->SetLayerVisible( ITEM_GAL_LAYER( i ), m_Pcb->IsElementVisible( i ) );
} }
view->SetTopLayer( m_Pcb->GetLayer() );
view->RecacheAllItems( true ); view->RecacheAllItems( true );
if( m_galCanvasActive ) if( m_galCanvasActive )
{
m_galCanvas->Refresh(); m_galCanvas->Refresh();
}
} }
} }
......
...@@ -356,21 +356,10 @@ bool PCB_LAYER_WIDGET::OnLayerSelect( LAYER_NUM aLayer ) ...@@ -356,21 +356,10 @@ bool PCB_LAYER_WIDGET::OnLayerSelect( LAYER_NUM aLayer )
// false from this function. // false from this function.
myframe->setActiveLayer( aLayer, false ); myframe->setActiveLayer( aLayer, false );
// Set display settings for high contrast mode
KiGfx::VIEW* view = myframe->GetGalCanvas()->GetView();
view->GetPainter()->GetSettings()->SetActiveLayer( aLayer );
view->UpdateAllLayersColor();
view->SetTopLayer( aLayer );
if( m_alwaysShowActiveCopperLayer ) if( m_alwaysShowActiveCopperLayer )
OnLayerSelected(); OnLayerSelected();
else if(DisplayOpt.ContrastModeDisplay) else if( DisplayOpt.ContrastModeDisplay )
{ myframe->GetCanvas()->Refresh();
if( myframe->IsGalCanvasActive() )
myframe->GetGalCanvas()->Refresh();
else
myframe->GetCanvas()->Refresh();
}
return true; return true;
} }
......
...@@ -232,16 +232,27 @@ void PCB_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event ) ...@@ -232,16 +232,27 @@ void PCB_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event )
break; break;
case ID_TB_OPTIONS_SHOW_HIGH_CONTRAST_MODE: case ID_TB_OPTIONS_SHOW_HIGH_CONTRAST_MODE:
{
DisplayOpt.ContrastModeDisplay = state; DisplayOpt.ContrastModeDisplay = state;
// Apply new display options to the GAL canvas (this is faster than recaching) // Apply new display options to the GAL canvas (this is faster than recaching)
settings->LoadDisplayOptions( DisplayOpt ); settings->LoadDisplayOptions( DisplayOpt );
m_galCanvas->GetView()->EnableTopLayer( state );
m_galCanvas->GetView()->UpdateAllLayersColor(); KiGfx::VIEW* view = m_galCanvas->GetView();
LAYER_NUM layer = getActiveLayer();
view->GetPainter()->GetSettings()->SetActiveLayer( layer );
view->UpdateAllLayersColor();
view->EnableTopLayer( state );
view->ClearTopLayers();
view->SetTopLayer( layer );
view->UpdateAllLayersOrder();
if( !IsGalCanvasActive() ) if( !IsGalCanvasActive() )
m_canvas->Refresh(); m_canvas->Refresh();
break; break;
}
case ID_TB_OPTIONS_SHOW_EXTRA_VERTICAL_TOOLBAR_MICROWAVE: case ID_TB_OPTIONS_SHOW_EXTRA_VERTICAL_TOOLBAR_MICROWAVE:
m_show_microwave_tools = state; m_show_microwave_tools = state;
......
...@@ -56,6 +56,8 @@ ...@@ -56,6 +56,8 @@
#include <dialog_helpers.h> #include <dialog_helpers.h>
#include <dialog_plot.h> #include <dialog_plot.h>
#include <convert_from_iu.h> #include <convert_from_iu.h>
#include <view/view.h>
#include <painter.h>
#if defined(KICAD_SCRIPTING) || defined(KICAD_SCRIPTING_WXPYTHON) #if defined(KICAD_SCRIPTING) || defined(KICAD_SCRIPTING_WXPYTHON)
...@@ -741,6 +743,31 @@ bool PCB_EDIT_FRAME::IsMicroViaAcceptable( void ) ...@@ -741,6 +743,31 @@ bool PCB_EDIT_FRAME::IsMicroViaAcceptable( void )
} }
void PCB_EDIT_FRAME::setActiveLayer( LAYER_NUM aLayer, bool doLayerWidgetUpdate )
{
( (PCB_SCREEN*) GetScreen() )->m_Active_Layer = aLayer;
// Set display settings for high contrast mode
KiGfx::VIEW* view = m_galCanvas->GetView();
if( DisplayOpt.ContrastModeDisplay )
{
view->GetPainter()->GetSettings()->SetActiveLayer( aLayer );
view->UpdateAllLayersColor();
view->ClearTopLayers();
view->SetTopLayer( aLayer );
view->UpdateAllLayersOrder();
if( m_galCanvasActive )
m_galCanvas->Refresh();
}
if( doLayerWidgetUpdate )
syncLayerWidgetLayer();
}
void PCB_EDIT_FRAME::syncLayerWidgetLayer() void PCB_EDIT_FRAME::syncLayerWidgetLayer()
{ {
m_Layers->SelectLayer( getActiveLayer() ); m_Layers->SelectLayer( getActiveLayer() );
......
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