From 607ec762d32d19530acf21798cb2708fdca88d61 Mon Sep 17 00:00:00 2001 From: charras Date: Sat, 30 Jan 2010 20:17:56 +0000 Subject: [PATCH] Code cleaning and more about work items visibility --- gerbview/lay2plot.cpp | 1 - include/pcbstruct.h | 1 - include/wxPcbStruct.h | 33 ++++++++++++++-- pcbnew/class_board.cpp | 3 +- pcbnew/classpcb.cpp | 1 - pcbnew/dialog_display_options.cpp | 7 ++-- pcbnew/dialog_display_options.h | 5 +-- pcbnew/dialog_general_options.cpp | 9 ++--- pcbnew/files.cpp | 11 ++++-- pcbnew/pcbframe.cpp | 63 +++++++++++++------------------ pcbnew/pcbnew_config.cpp | 12 +++--- pcbnew/print_board_functions.cpp | 3 +- 12 files changed, 81 insertions(+), 68 deletions(-) diff --git a/gerbview/lay2plot.cpp b/gerbview/lay2plot.cpp index 5c9c5c6680..a205093877 100644 --- a/gerbview/lay2plot.cpp +++ b/gerbview/lay2plot.cpp @@ -20,7 +20,6 @@ void Print_PcbItems(BOARD * Pcb, wxDC *DC, int drawmode, int printmasklayer) DisplayOpt.DisplayPadFill = FILLED; DisplayOpt.DisplayViaFill = FILLED; DisplayOpt.DisplayPadNum = 0; - DisplayOpt.DisplayPadNoConn = 0; DisplayOpt.DisplayPadIsol = 0; DisplayOpt.DisplayPcbTrackFill = FILLED; DisplayOpt.ShowTrackClearanceMode = DO_NOT_SHOW_CLEARANCE; diff --git a/include/pcbstruct.h b/include/pcbstruct.h index d5ff45ad19..fd51ed3aa4 100644 --- a/include/pcbstruct.h +++ b/include/pcbstruct.h @@ -101,7 +101,6 @@ public: bool DisplayPadFill; bool DisplayViaFill; bool DisplayPadNum; - bool DisplayPadNoConn; bool DisplayPadIsol; int DisplayModEdge; diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index fb3ff299ef..8150ebed07 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -96,11 +96,8 @@ protected: *

* This function cannot be inline without including layer_widget.h in * here and we do not want to do that. - * @param aRenderOnly: true to update render only, false (default) for full update - * if aRenderOnly = true, the page displayed by the layer manager is not changed - * if aRenderOnly = false, the page displayed after update is the layers list */ - void syncLayerWidget(bool aRenderOnly = false); + void syncLayerWidget( ); /** * Function syncLayerBox @@ -186,6 +183,34 @@ public: void ReCreateMenuBar(); WinEDAChoiceBox* ReCreateLayerBox( WinEDA_Toolbar* parent ); + /** + * Function IsElementVisible + * tests whether a given element category is visible. Keep this as an + * inline function. + * @param aPCB_VISIBLE is from the enum by the same name + * @return bool - true if the element is visible. + * @see enum PCB_VISIBLE + */ + bool IsElementVisible( int aPCB_VISIBLE ) + { + return GetBoard()->IsElementVisible( aPCB_VISIBLE ); + } + + /** + * Function SetElementVisibility + * changes the visibility of an element category + * @param aPCB_VISIBLE is from the enum by the same name + * @param aNewState = The new visibility state of the element category + * @see enum PCB_VISIBLE + */ + void SetElementVisibility( int aPCB_VISIBLE, bool aNewState ); + + /** + * Function SetVisibleAlls + * Set the status of all visible element categories and layers to VISIBLE + */ + void SetVisibleAlls( ); + /** * Function ReFillLayerWidget * changes out all the layers in m_Layers and may be called upon diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index d008690be0..cfc5ce226b 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -392,6 +392,7 @@ void BOARD::SetVisibleElements( int aMask ) { /* Call SetElementVisibility for each item, * to ensure specific calculations that can be needed by some items + * just change the visibility flags could be not sufficient */ for( int ii = 0; ii < PCB_VISIBLE(END_PCB_VISIBLE_LIST); ii++ ) { @@ -408,9 +409,7 @@ void BOARD::SetVisibleAlls( ) * to ensure specific calculations that can be needed by some items */ for( int ii = 0; ii < PCB_VISIBLE(END_PCB_VISIBLE_LIST); ii++ ) - { SetElementVisibility( ii, true ); - } } diff --git a/pcbnew/classpcb.cpp b/pcbnew/classpcb.cpp index 2f66a99c87..8daa8ed42b 100644 --- a/pcbnew/classpcb.cpp +++ b/pcbnew/classpcb.cpp @@ -146,7 +146,6 @@ DISPLAY_OPTIONS::DISPLAY_OPTIONS() DisplayPadFill = FILLED; DisplayViaFill = FILLED; DisplayPadNum = true; - DisplayPadNoConn = true; DisplayPadIsol = true; DisplayModEdge = true; diff --git a/pcbnew/dialog_display_options.cpp b/pcbnew/dialog_display_options.cpp index 23e9ac29d9..9d15714ef9 100644 --- a/pcbnew/dialog_display_options.cpp +++ b/pcbnew/dialog_display_options.cpp @@ -29,7 +29,7 @@ void WinEDA_PcbFrame::InstallDisplayOptionsDialog( wxCommandEvent& aEvent ) /*******************************************************************************/ -Dialog_Display_Options::Dialog_Display_Options( WinEDA_BasePcbFrame* parent ) : +Dialog_Display_Options::Dialog_Display_Options( WinEDA_PcbFrame* parent ) : DialogDisplayOptions_base(parent) /*******************************************************************************/ { @@ -81,7 +81,7 @@ void Dialog_Display_Options::init() m_OptDisplayModEdges->SetSelection( DisplayOpt.DisplayModEdge ); m_OptDisplayPadClearence->SetValue( DisplayOpt.DisplayPadIsol ); m_OptDisplayPadNumber->SetValue( DisplayOpt.DisplayPadNum ); - m_OptDisplayPadNoConn->SetValue( DisplayOpt.DisplayPadNoConn ); + m_OptDisplayPadNoConn->SetValue( m_Parent->IsElementVisible( PCB_VISIBLE(NO_CONNECTS_VISIBLE) ) ); m_OptDisplayDrawings->SetSelection( DisplayOpt.DisplayDrawItems ); m_ShowNetNamesOption->SetSelection( DisplayOpt.DisplayNetNamesMode); @@ -152,7 +152,8 @@ void Dialog_Display_Options::OnOkClick(wxCommandEvent& event) m_Parent->m_DisplayPadNum = DisplayOpt.DisplayPadNum = m_OptDisplayPadNumber->GetValue(); - DisplayOpt.DisplayPadNoConn = m_OptDisplayPadNoConn->GetValue(); + m_Parent->SetElementVisibility( PCB_VISIBLE(NO_CONNECTS_VISIBLE), + m_OptDisplayPadNoConn->GetValue()); DisplayOpt.DisplayDrawItems = m_OptDisplayDrawings->GetSelection(); DisplayOpt.DisplayNetNamesMode = m_ShowNetNamesOption->GetSelection(); diff --git a/pcbnew/dialog_display_options.h b/pcbnew/dialog_display_options.h index 281418cb51..74040491ca 100644 --- a/pcbnew/dialog_display_options.h +++ b/pcbnew/dialog_display_options.h @@ -6,13 +6,12 @@ class Dialog_Display_Options : public DialogDisplayOptions_base { private: - WinEDA_BasePcbFrame* m_Parent; + WinEDA_PcbFrame* m_Parent; void init(); public: - Dialog_Display_Options( WinEDA_BasePcbFrame* parent ); - Dialog_Display_Options(WinEDA_BasePcbFrame*, wxWindow*); + Dialog_Display_Options( WinEDA_PcbFrame* parent ); ~Dialog_Display_Options( ) { }; void OnOkClick( wxCommandEvent& event ); void OnCancelClick( wxCommandEvent& event ); diff --git a/pcbnew/dialog_general_options.cpp b/pcbnew/dialog_general_options.cpp index bbe4a6b8c5..fd596519aa 100644 --- a/pcbnew/dialog_general_options.cpp +++ b/pcbnew/dialog_general_options.cpp @@ -98,7 +98,7 @@ void Dialog_GeneralOptions::OnOkClick( wxCommandEvent& event ) Drc_On = m_DrcOn->GetValue(); if( m_Board->IsElementVisible(RATSNEST_VISIBLE) != m_ShowGlobalRatsnest->GetValue() ) { - m_Board->SetElementVisibility(RATSNEST_VISIBLE, m_ShowGlobalRatsnest->GetValue() ); + m_Parent->SetElementVisibility(RATSNEST_VISIBLE, m_ShowGlobalRatsnest->GetValue() ); m_Parent->DrawPanel->Refresh( ); } g_Show_Module_Ratsnest = m_ShowModuleRatsnest->GetValue(); @@ -159,20 +159,17 @@ void WinEDA_PcbFrame::OnSelectOptionToolbar( wxCommandEvent& event ) break; case ID_TB_OPTIONS_SHOW_GRID: - GetBoard()->SetElementVisibility(GRID_VISIBLE, state); - syncLayerWidget( true ); + SetElementVisibility(GRID_VISIBLE, state); DrawPanel->Refresh(); break; case ID_TB_OPTIONS_SHOW_RATSNEST: - GetBoard()->SetElementVisibility(RATSNEST_VISIBLE, state); - syncLayerWidget( true ); + SetElementVisibility(RATSNEST_VISIBLE, state); DrawPanel->Refresh( ); break; case ID_TB_OPTIONS_SHOW_MODULE_RATSNEST: g_Show_Module_Ratsnest = state; // TODO: use the visibility list - syncLayerWidget( true ); break; case ID_TB_OPTIONS_SELECT_UNIT_MM: diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 376955035a..aa71e9d021 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -245,11 +245,16 @@ this file again.")); /* Rebuild the new pad list (for drc and ratsnet control ...) */ GetBoard()->m_Status_Pcb = 0; - /* Reset the layers and items visibility flag when loading a new config + /* Reset the items visibility flag when loading a new config * Because it could creates SERIOUS mistakes for the user, - * if some enabled layers or items are not visible after loading a board... + * if board items are not visible after loading a board... + * Grid and ratsnest can be left to their previous state */ - GetBoard()->m_BoardSettings->SetVisibleAlls( ); + bool showGrid = IsElementVisible(GRID_VISIBLE); + bool showRats = IsElementVisible(RATSNEST_VISIBLE); + SetVisibleAlls( ); + SetElementVisibility(GRID_VISIBLE, showGrid); + SetElementVisibility(RATSNEST_VISIBLE, showRats); // Update info shown by the horizontal toolbars GetBoard()->SetCurrentNetClass( NETCLASS::Default ); diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 6e30047efc..68ace32de3 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -85,9 +85,6 @@ public: PCB_LAYER_WIDGET( WinEDA_PcbFrame* aParent, wxWindow* aFocusOwner, int aPointSize = 10 ); void ReFill(); - // Update Show/hide checkbox state in render page - // must be called when a Show/hide option is changed outside the layer manager - void RenderSynchronize( ); //---------------- void OnLayerColorChange( int aLayer, int aColor ); @@ -318,34 +315,6 @@ void PCB_LAYER_WIDGET::ReFill() // m_Layers->Thaw(); } -// Update the checkboxes state of each row of the render. -void PCB_LAYER_WIDGET::RenderSynchronize( ) -{ - BOARD* brd = myframe->GetBoard(); - wxSizerItemList& sizerslist = m_RenderFlexGridSizer->GetChildren(); - - for( unsigned ii=0; ii< PCB_VISIBLE(END_PCB_VISIBLE_LIST); ++ii ) - { - unsigned idx = ii * m_RenderFlexGridSizer->GetCols(); - // idx points the first size of a m_RenderFlexGridSizer row - // the checkbox to update is managed by the second sizer - idx = idx + 1; - if( idx >= sizerslist.size() ) - break; // Should not occur - - // Get the sizer that manages the check box to update - wxSizerItem * sizer = sizerslist[idx]; - // Get the checkbox and update its state. - wxCheckBox* cb = (wxCheckBox*)sizer->GetWindow(); - if( cb ) - { - // Calculate the visible item id - int id = getDecodedId(cb->GetId()); - cb->SetValue(brd->IsElementVisible(id)); - } - } -} - //------------------------------------------------ void PCB_LAYER_WIDGET::OnLayerColorChange( int aLayer, int aColor ) @@ -854,7 +823,6 @@ void WinEDA_PcbFrame::ShowDesignRulesEditor( wxCommandEvent& event ) if( returncode == wxID_OK ) // New rules, or others changes. { ReCreateLayerBox( NULL ); - // ReFillLayerWidget(); why? GetScreen()->SetModify(); } } @@ -905,10 +873,33 @@ void WinEDA_PcbFrame::SaveSettings() } -void WinEDA_PcbFrame::syncLayerWidget( bool aRenderOnly) +void WinEDA_PcbFrame::syncLayerWidget( ) { - if( ! aRenderOnly ) - m_Layers->SelectLayer( getActiveLayer() ); - m_Layers->RenderSynchronize( ); + m_Layers->SelectLayer( getActiveLayer() ); } +/** + * Function SetElementVisibility + * changes the visibility of an element category + * @param aPCB_VISIBLE is from the enum by the same name + * @param aNewState = The new visibility state of the element category + * @see enum PCB_VISIBLE + */ +void WinEDA_PcbFrame::SetElementVisibility( int aPCB_VISIBLE, bool aNewState ) +{ + GetBoard()->SetElementVisibility( aPCB_VISIBLE, aNewState ); + m_Layers->SetRenderState( aPCB_VISIBLE, aNewState ); +} + +/** + * Function SetVisibleAlls + * Set the status of all visible element categories and layers to VISIBLE + */ +void WinEDA_PcbFrame::SetVisibleAlls( ) +{ + GetBoard()->SetVisibleAlls( ); + for( int ii = 0; ii < PCB_VISIBLE(END_PCB_VISIBLE_LIST); ii++ ) + m_Layers->SetRenderState( ii, true ); +} + + diff --git a/pcbnew/pcbnew_config.cpp b/pcbnew/pcbnew_config.cpp index 5d97ca409d..1b05b4eefc 100644 --- a/pcbnew/pcbnew_config.cpp +++ b/pcbnew/pcbnew_config.cpp @@ -194,13 +194,11 @@ bool WinEDA_PcbFrame::Read_Config( const wxString& projectFileName ) * if board items are not visible after loading a board... * Grid and ratsnest can be left to their previous state */ - bool showGrid = GetBoard()->IsElementVisible(GRID_VISIBLE); - bool showRats = GetBoard()->IsElementVisible(RATSNEST_VISIBLE); - GetBoard()->SetVisibleAlls( ); - GetBoard()->SetElementVisibility(GRID_VISIBLE, showGrid); - GetBoard()->SetElementVisibility(RATSNEST_VISIBLE, showRats); - - DisplayOpt.DisplayPadNoConn = true; + bool showGrid = IsElementVisible(GRID_VISIBLE); + bool showRats = IsElementVisible(RATSNEST_VISIBLE); + SetVisibleAlls( ); + SetElementVisibility(GRID_VISIBLE, showGrid); + SetElementVisibility(RATSNEST_VISIBLE, showRats); return TRUE; } diff --git a/pcbnew/print_board_functions.cpp b/pcbnew/print_board_functions.cpp index 8400b6a64d..72606a001d 100644 --- a/pcbnew/print_board_functions.cpp +++ b/pcbnew/print_board_functions.cpp @@ -62,7 +62,7 @@ void WinEDA_DrawPanel::PrintPage( wxDC* aDC, frame->m_DisplayPadFill = DisplayOpt.DisplayPadFill; frame->m_DisplayViaFill = DisplayOpt.DisplayViaFill; frame->m_DisplayPadNum = DisplayOpt.DisplayPadNum = false; - DisplayOpt.DisplayPadNoConn = false; + bool nctmp = frame->GetBoard()->IsElementVisible(NO_CONNECTS_VISIBLE); DisplayOpt.DisplayPadIsol = false; DisplayOpt.DisplayModEdge = FILLED; DisplayOpt.DisplayModText = FILLED; @@ -190,6 +190,7 @@ void WinEDA_DrawPanel::PrintPage( wxDC* aDC, frame->m_DisplayPadFill = DisplayOpt.DisplayPadFill; frame->m_DisplayViaFill = DisplayOpt.DisplayViaFill; frame->m_DisplayPadNum = DisplayOpt.DisplayPadNum; + frame->GetBoard()->SetElementVisibility(NO_CONNECTS_VISIBLE, nctmp); }