From 68961c82fd2f4632549f85c864c443480971c4a1 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 2 Jul 2013 14:02:42 +0200 Subject: [PATCH] Added possibility to change display modes of zones. --- pcbnew/dialogs/dialog_general_options.cpp | 18 ++++- pcbnew/pcb_painter.cpp | 90 +++++++++++++++++++---- pcbnew/pcb_painter.h | 10 ++- 3 files changed, 97 insertions(+), 21 deletions(-) diff --git a/pcbnew/dialogs/dialog_general_options.cpp b/pcbnew/dialogs/dialog_general_options.cpp index 6c46cd1579..63bb4960df 100644 --- a/pcbnew/dialogs/dialog_general_options.cpp +++ b/pcbnew/dialogs/dialog_general_options.cpp @@ -202,17 +202,29 @@ void PCB_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event ) case ID_TB_OPTIONS_SHOW_ZONES: DisplayOpt.DisplayZonesMode = 0; - m_canvas->Refresh(); +#ifdef KICAD_GAL + recache = true; + if( !IsGalCanvasActive() ) +#endif /* KICAD_GAL */ + m_canvas->Refresh(); break; case ID_TB_OPTIONS_SHOW_ZONES_DISABLE: DisplayOpt.DisplayZonesMode = 1; - m_canvas->Refresh(); +#ifdef KICAD_GAL + recache = true; + if( !IsGalCanvasActive() ) +#endif /* KICAD_GAL */ + m_canvas->Refresh(); break; case ID_TB_OPTIONS_SHOW_ZONES_OUTLINES_ONLY: DisplayOpt.DisplayZonesMode = 2; - m_canvas->Refresh(); +#ifdef KICAD_GAL + recache = true; + if( !IsGalCanvasActive() ) +#endif /* KICAD_GAL */ + m_canvas->Refresh(); break; case ID_TB_OPTIONS_SHOW_VIAS_SKETCH: diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 3b7598c1af..1697d05442 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -84,6 +84,21 @@ void PCB_RENDER_SETTINGS::LoadDisplayOptions( const DISPLAY_OPTIONS& aOptions ) m_sketchModeSelect[PADS_VISIBLE] = !aOptions.DisplayPadFill; m_sketchModeSelect[VIAS_VISIBLE] = !aOptions.DisplayViaFill; m_sketchModeSelect[TRACKS_VISIBLE] = !aOptions.DisplayPcbTrackFill; + + switch( aOptions.DisplayZonesMode ) + { + case 0: + m_displayZoneMode = DZ_SHOW_FILLED; + break; + + case 1: + m_displayZoneMode = DZ_HIDE_FILLED; + break; + + case 2: + m_displayZoneMode = DZ_SHOW_OUTLINED; + break; + } } @@ -487,25 +502,60 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer ) void PCB_PAINTER::draw( const ZONE_CONTAINER* aContainer ) { - std::vector polyPoints = aContainer->GetFilledPolysList().GetList(); - if( polyPoints.size() == 0 ) // Nothing to draw - return; - - COLOR4D fillColor = getLayerColor( aContainer->GetLayer(), aContainer->GetNet() ); - std::vector::iterator polyIterator; + COLOR4D color = getLayerColor( aContainer->GetLayer(), aContainer->GetNet() ); std::deque corners; - int fillMode = aContainer->GetFillMode(); + PCB_RENDER_SETTINGS::DisplayZonesMode displayMode = m_pcbSettings->m_displayZoneMode; - m_gal->SetFillColor( fillColor ); - m_gal->SetStrokeColor( fillColor ); - m_gal->SetIsFill( !fillMode ); + // Draw the outline + m_gal->SetStrokeColor( color ); + m_gal->SetIsFill( false ); m_gal->SetIsStroke( true ); - m_gal->SetLineWidth( aContainer->GetThermalReliefCopperBridge() / 2.0 ); + m_gal->SetLineWidth( m_pcbSettings->m_outlineWidth ); - // FIXME implement hatch mode - - if( fillMode == 0 ) + const CPolyLine* outline = aContainer->Outline(); + for( int i = 0; i < outline->GetCornersCount(); ++i ) { + corners.push_back( VECTOR2D( outline->GetPos( i ) ) ); + } + // The last point for closing the polyline + corners.push_back( VECTOR2D( outline->GetPos( 0 ) ) ); + m_gal->DrawPolyline( corners ); + corners.clear(); + + // Draw the outline's hatch lines + std::vector::const_iterator hatch, hatch_end; + for( hatch = outline->m_HatchLines.begin(), hatch_end = outline->m_HatchLines.end(); + hatch != hatch_end; ++hatch ) + { + const VECTOR2D start = VECTOR2D( hatch->m_Start ); + const VECTOR2D end = VECTOR2D( hatch->m_End ); + + m_gal->DrawLine( start, end ); + } + + // Draw the filling + if( displayMode != PCB_RENDER_SETTINGS::DZ_HIDE_FILLED ) + { + const std::vector polyPoints = aContainer->GetFilledPolysList().GetList(); + if( polyPoints.size() == 0 ) // Nothing to draw + return; + + // Set up drawing options + m_gal->SetFillColor( color ); + m_gal->SetLineWidth( aContainer->GetThermalReliefCopperBridge() / 2.0 ); + + if( displayMode == PCB_RENDER_SETTINGS::DZ_SHOW_FILLED ) + { + m_gal->SetIsFill( true ); + m_gal->SetIsStroke( true ); + } + else if( displayMode == PCB_RENDER_SETTINGS::DZ_SHOW_OUTLINED ) + { + m_gal->SetIsFill( false ); + m_gal->SetIsStroke( true ); + } + + std::vector::const_iterator polyIterator; for( polyIterator = polyPoints.begin(); polyIterator != polyPoints.end(); polyIterator++ ) { // Find out all of polygons and then draw them @@ -513,8 +563,16 @@ void PCB_PAINTER::draw( const ZONE_CONTAINER* aContainer ) if( polyIterator->end_contour ) { - m_gal->DrawPolygon( corners ); - m_gal->DrawPolyline( corners ); + if( displayMode == PCB_RENDER_SETTINGS::DZ_SHOW_FILLED ) + { + m_gal->DrawPolygon( corners ); + m_gal->DrawPolyline( corners ); + } + else if( displayMode == PCB_RENDER_SETTINGS::DZ_SHOW_OUTLINED ) + { + m_gal->DrawPolyline( corners ); + } + corners.clear(); } } diff --git a/pcbnew/pcb_painter.h b/pcbnew/pcb_painter.h index 6d1c630801..20a5d4fe67 100644 --- a/pcbnew/pcb_painter.h +++ b/pcbnew/pcb_painter.h @@ -61,7 +61,6 @@ class STROKE_FONT; class PCB_RENDER_SETTINGS : public RENDER_SETTINGS { public: - friend class PCB_PAINTER; enum ClearanceMode { @@ -70,6 +69,12 @@ public: CL_TRACKS = 0x4 }; + enum DisplayZonesMode { + DZ_HIDE_FILLED = 0, + DZ_SHOW_FILLED, + DZ_SHOW_OUTLINED + }; + PCB_RENDER_SETTINGS(); /// @copydoc RENDER_SETTINGS::Update() @@ -87,7 +92,6 @@ public: void LoadDisplayOptions( const DISPLAY_OPTIONS& aOptions ); protected: - /// Colors for all layers (including special, highlighted & darkened versions) COLOR4D m_layerColors [NB_LAYERS]; COLOR4D m_layerColorsHi [NB_LAYERS]; @@ -101,6 +105,8 @@ protected: bool m_sketchModeSelect[END_PCB_VISIBLE_LIST]; bool m_visibleLayers [NB_LAYERS]; bool m_visibleItems [END_PCB_VISIBLE_LIST]; + + DisplayZonesMode m_displayZoneMode; };