diff --git a/common/gal/cairo/cairo_gal.cpp b/common/gal/cairo/cairo_gal.cpp index 9938df5d3e..4bc1d59c87 100644 --- a/common/gal/cairo/cairo_gal.cpp +++ b/common/gal/cairo/cairo_gal.cpp @@ -801,6 +801,24 @@ void CAIRO_GAL::DrawGroup( int aGroupNumber ) } +void CAIRO_GAL::ChangeGroupColor( int aGroupNumber, const COLOR4D& aNewColor ) +{ + storePath(); + + for( Group::iterator it = groups[aGroupNumber].begin(); + it != groups[aGroupNumber].end(); ++it ) + { + if( it->command == CMD_SET_FILLCOLOR || it->command == CMD_SET_STROKECOLOR ) + { + it->arguments[0] = aNewColor.r; + it->arguments[1] = aNewColor.g; + it->arguments[2] = aNewColor.b; + it->arguments[3] = aNewColor.a; + } + } +} + + void CAIRO_GAL::Flush() { storePath(); diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 462bf30f55..69944a5daf 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -1628,6 +1628,13 @@ void OPENGL_GAL::DrawGroup( int aGroupNumber ) } +void OPENGL_GAL::ChangeGroupColor( int aGroupNumber, const COLOR4D& aNewColor ) +{ + vboItems[aGroupNumber]->ChangeColor( aNewColor ); + vboNeedsUpdate = true; +} + + void OPENGL_GAL::computeUnitCircle() { displayListCircle = glGenLists( 1 ); diff --git a/common/gal/opengl/vbo_item.cpp b/common/gal/opengl/vbo_item.cpp index 28d83f5895..4d6132403b 100644 --- a/common/gal/opengl/vbo_item.cpp +++ b/common/gal/opengl/vbo_item.cpp @@ -79,18 +79,17 @@ VBO_VERTEX* VBO_ITEM::GetVertices() void VBO_ITEM::ChangeColor( const COLOR4D& aColor ) { - wxASSERT_MSG( false, wxT( "This was not tested yet" ) ); - if( m_isDirty ) Finish(); - // Point to color of vertices VBO_VERTEX* vertexPtr = GetVertices(); - const GLfloat newColor[] = { aColor.r, aColor.g, aColor.b, aColor.a }; for( unsigned int i = 0; i < m_size; ++i ) { - memcpy( &vertexPtr->r, newColor, ColorByteSize ); + vertexPtr->r = aColor.r; + vertexPtr->g = aColor.g; + vertexPtr->b = aColor.b; + vertexPtr->a = aColor.a; // Move on to the next vertex vertexPtr++; diff --git a/common/view/view.cpp b/common/view/view.cpp index 680ae1e719..07114f8eaa 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -307,6 +307,55 @@ void VIEW::SetLayerOrder( int aLayer, int aRenderingOrder ) } +struct VIEW::updateItemsColor +{ + updateItemsColor( int aLayer, PAINTER* aPainter, GAL* aGal ) : + layer( aLayer ), painter( aPainter), gal( aGal ) + { + } + + void operator()( VIEW_ITEM* aItem ) + { + // Obtain the color that should be used for coloring the item + const COLOR4D color = painter->GetColor( aItem, layer ); + int group = aItem->getGroup( layer ); + + gal->ChangeGroupColor( group, color ); + } + + int layer; + PAINTER* painter; + GAL* gal; +}; + + +void VIEW::UpdateLayerColor( int aLayer ) +{ + BOX2I r; + + r.SetMaximum(); + + updateItemsColor visitor( aLayer, m_painter, m_gal ); + m_layers[aLayer].items->Query( r, visitor ); +} + + +void VIEW::UpdateAllLayersColor() +{ + BOX2I r; + + r.SetMaximum(); + + for( LayerMapIter i = m_layers.begin(); i != m_layers.end(); ++i ) + { + VIEW_LAYER* l = &( ( *i ).second ); + updateItemsColor visitor( l->id, m_painter, m_gal ); + + l->items->Query( r, visitor ); + } +} + + void VIEW::SetTopLayer( int aLayer ) { // Restore previous order @@ -561,13 +610,13 @@ void VIEW::clearGroupCache() BOX2I r; r.SetMaximum(); + clearItemCache visitor( this ); for( LayerMapIter i = m_layers.begin(); i != m_layers.end(); ++i ) { VIEW_LAYER* l = & ( ( *i ).second ); - clearItemCache visitor( this ); l->items->Query( r, visitor ); - }; + } } diff --git a/include/gal/cairo/cairo_gal.h b/include/gal/cairo/cairo_gal.h index 582db3b654..0af3c173fd 100644 --- a/include/gal/cairo/cairo_gal.h +++ b/include/gal/cairo/cairo_gal.h @@ -209,6 +209,9 @@ public: /// @copydoc GAL::DrawGroup() virtual void DrawGroup( int aGroupNumber ); + /// @copydoc GAL::ChangeGroupColor() + virtual void ChangeGroupColor( int aGroupNumber, const COLOR4D& aNewColor ); + /// @copydoc GAL::DeleteGroup() virtual void DeleteGroup( int aGroupNumber ); diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h index e7524a65e1..8a8cbb2036 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -363,6 +363,14 @@ public: */ virtual void DrawGroup( int aGroupNumber ) = 0; + /** + * @brief Changes the color used to draw the group. + * + * @param aGroupNumber is the group number. + * @param aNewColor is the new color. + */ + virtual void ChangeGroupColor( int aGroupNumber, const COLOR4D& aNewColor ) = 0; + /** * @brief Delete the group from the memory. * diff --git a/include/gal/opengl/opengl_gal.h b/include/gal/opengl/opengl_gal.h index 77acc3a1f8..9db405d7a5 100644 --- a/include/gal/opengl/opengl_gal.h +++ b/include/gal/opengl/opengl_gal.h @@ -234,6 +234,9 @@ public: /// @copydoc GAL::DrawGroup() virtual void DrawGroup( int aGroupNumber ); + /// @copydoc GAL::ChangeGroupColor() + virtual void ChangeGroupColor( int aGroupNumber, const COLOR4D& aNewColor ); + /// @copydoc GAL::DeleteGroup() virtual void DeleteGroup( int aGroupNumber ); diff --git a/include/painter.h b/include/painter.h index d043dff2c8..f4ac232821 100644 --- a/include/painter.h +++ b/include/painter.h @@ -82,7 +82,7 @@ public: * (eg. highlighted, so it differs from other layers). * @param aLayerId is a layer number that should be displayed in a specific mode. */ - void SetActiveLayer( int aLayerId ) + inline void SetActiveLayer( int aLayerId ) { m_activeLayer = aLayerId; } @@ -94,7 +94,7 @@ public: * @param aNetCode is optional and if specified, turns on higlighting only for the net with * number given as the parameter. */ - void SetHighlight( bool aEnabled, int aNetcode = -1 ) + inline void SetHighlight( bool aEnabled, int aNetcode = -1 ) { m_highlightEnabled = aEnabled; @@ -107,7 +107,7 @@ public: * Turns on/off high contrast display mode. * @param aEnabled determines if high contrast display mode should be enabled or not. */ - void SetHighContrast( bool aEnabled ) + inline void SetHighContrast( bool aEnabled ) { m_hiContrastEnabled = aEnabled; } @@ -200,7 +200,7 @@ public: /** * Function Draw - * Takes an instance of EDA_ITEM and passes it to a function that know how to draw the item. + * Takes an instance of VIEW_ITEM and passes it to a function that know how to draw the item. * @param aItem is an item to be drawn. * @param aLayer tells which layer is currently rendered so that draw functions * may know what to draw (eg. for pads there are separate layers for holes, because they @@ -208,8 +208,17 @@ public: */ virtual bool Draw( const VIEW_ITEM* aItem, int aLayer ) = 0; -protected: + /** + * Function GetColor + * Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer + * using currently used render settings. + * @param aItem is the VIEW_ITEM. + * @param aLayer is the layer. + * @return The color. + */ + virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) = 0; +protected: /** * Function getLayerColor * is used for obtaining color that should be used for specific layer/net diff --git a/include/view/view.h b/include/view/view.h index 45e7645671..9577537dda 100644 --- a/include/view/view.h +++ b/include/view/view.h @@ -61,8 +61,8 @@ public: /** * Constructor. - * @param aIsDynamic: decides whether we are creating a static or a dynamic VIEW. - * @param aUseGroups: fixme + * @param aIsDynamic decides whether we are creating a static or a dynamic VIEW. + * @param aUseGroups tells if items added to the VIEW should be stored in groups. */ VIEW( bool aIsDynamic = true, bool aUseGroups = false ); @@ -116,7 +116,7 @@ public: * Returns the GAL this view is using to draw graphical primitives. * @return Pointer to the currently used GAL instance. */ - GAL* GetGAL() const { return m_gal; } + GAL* GetGAL() const { return m_gal; } /** * Function SetPainter() @@ -264,6 +264,21 @@ public: */ void SetLayerOrder( int aLayer, int aRenderingOrder ); + /** + * Function UpdateLayerColor() + * Applies the new coloring scheme held by RENDER_SETTINGS in case that it has changed. + * @param aLayer is a number of the layer to be updated. + * @see RENDER_SETTINGS + */ + void UpdateLayerColor( int aLayer ); + + /** + * Function UpdateAllLayersColor() + * Applies the new coloring scheme to all layers. The used scheme is held by RENDER_SETTINGS. + * @see RENDER_SETTINGS + */ + void UpdateAllLayersColor(); + /** * Function SetTopLayer() * Sets given layer to be displayed on the top or sets back the default order of layers. @@ -313,7 +328,6 @@ public: static const int TOP_LAYER; ///* layer number for displaying items on the top private: - struct VIEW_LAYER { bool enabled; ///* is the layer to be rendered? @@ -338,6 +352,7 @@ private: struct unlinkItem; struct recacheItem; struct drawItem; + struct updateItemsColor; ///* Saves current top layer settings in order to restore it when it's not top anymore VIEW_LAYER m_topLayer; @@ -346,18 +361,18 @@ private: bool m_enableTopLayer; ///* Redraws contents within rect aRect - void redrawRect( const BOX2I& aRect ); + void redrawRect( const BOX2I& aRect ); ///* Manages dirty flags & redraw queueing when updating an item. Called internally /// via VIEW_ITEM::ViewUpdate() - void invalidateItem( VIEW_ITEM* aItem, int aUpdateFlags ); + void invalidateItem( VIEW_ITEM* aItem, int aUpdateFlags ); ///* Sorts m_orderedLayers when layer rendering order has changed - void sortLayers(); + void sortLayers(); ///* Clears cached GAL group numbers (*ONLY* numbers stored in VIEW_ITEMs, not group objects ///* used by GAL) - void clearGroupCache(); + void clearGroupCache(); /// Determines rendering order of layers. Used in display order sorting function. static bool compareRenderingOrder( VIEW_LAYER* i, VIEW_LAYER* j ) diff --git a/pcbnew/dialogs/dialog_general_options.cpp b/pcbnew/dialogs/dialog_general_options.cpp index 4634dd8c8b..0303401896 100644 --- a/pcbnew/dialogs/dialog_general_options.cpp +++ b/pcbnew/dialogs/dialog_general_options.cpp @@ -161,6 +161,12 @@ void PCB_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event ) { int id = event.GetId(); bool state = event.IsChecked(); +#ifdef KICAD_GAL + KiGfx::PCB_PAINTER* painter = + static_cast ( m_galCanvas->GetView()->GetPainter() ); + KiGfx::PCB_RENDER_SETTINGS* settings = + static_cast ( painter->GetSettings() ); +#endif /* KICAD_GAL */ switch( id ) { @@ -221,9 +227,14 @@ void PCB_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event ) case ID_TB_OPTIONS_SHOW_HIGH_CONTRAST_MODE: DisplayOpt.ContrastModeDisplay = state; #ifdef KICAD_GAL + // Apply new display options to the GAL canvas + settings->LoadDisplayOptions( DisplayOpt ); m_galCanvas->GetView()->EnableTopLayer( state ); + m_galCanvas->GetView()->UpdateAllLayersColor(); + + if( !IsGalCanvasActive() ) #endif /* KICAD_GAL */ - m_canvas->Refresh(); + m_canvas->Refresh(); break; case ID_TB_OPTIONS_SHOW_EXTRA_VERTICAL_TOOLBAR_MICROWAVE: @@ -250,16 +261,7 @@ void PCB_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event ) } #ifdef KICAD_GAL - // Apply new display options to the GAL canvas - KiGfx::PCB_PAINTER* painter = - static_cast ( m_galCanvas->GetView()->GetPainter() ); - KiGfx::PCB_RENDER_SETTINGS* settings = - static_cast ( painter->GetSettings() ); - settings->LoadDisplayOptions( DisplayOpt ); - if( IsGalCanvasActive() ) - { m_galCanvas->Refresh(); - } -#endif +#endif /* KICAD_GAL */ } diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index c8591208d7..e0cb774058 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -117,6 +117,19 @@ PCB_PAINTER::PCB_PAINTER( GAL* aGal ) : } +const COLOR4D& PCB_PAINTER::GetColor( const VIEW_ITEM* aItem, int aLayer ) +{ + int netCode = 0; + + // Try to obtain the netcode for the item + const BOARD_CONNECTED_ITEM* item = dynamic_cast( aItem ); + if( item ) + netCode = item->GetNet(); + + return getLayerColor( aLayer, netCode ); +} + + const COLOR4D& PCB_PAINTER::getLayerColor( int aLayer, int aNetCode ) const { if( m_pcbSettings->m_hiContrastEnabled && m_pcbSettings->m_activeLayer != aLayer ) @@ -211,7 +224,7 @@ bool PCB_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer ) break; default: - // Painter does not knowNetwork: how to draw the object + // Painter does not know how to draw the object return false; break; } diff --git a/pcbnew/pcb_painter.h b/pcbnew/pcb_painter.h index e20c0008db..6d1c630801 100644 --- a/pcbnew/pcb_painter.h +++ b/pcbnew/pcb_painter.h @@ -126,8 +126,10 @@ public: m_pcbSettings = dynamic_cast ( aSettings ); } -protected: + /// @copydoc PAINTER::GetColor() + virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ); +protected: PCB_RENDER_SETTINGS* m_pcbSettings; /// @copydoc PAINTER::getLayerColor()