From 5a2d655c4ac6befc4bac7617d067418afecc89f2 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Sun, 11 Mar 2012 19:40:48 -0500 Subject: [PATCH] * Add PCB_EDIT_FRAME::syncLayerVisibilities(), PCB_LAYER_MANAGER::SyncLayerVisibilities(). * Save all visibilities, layer and render, in BOARD and restore on load. --- CHANGELOG.txt | 7 +++++ common/common.cpp | 14 +++++----- common/dialog_about/AboutDialog_main.cpp | 1 + include/common.h | 10 +++---- include/param_config.h | 10 +++++-- include/wxPcbStruct.h | 12 +++++++-- pcbnew/class_board.cpp | 15 +++++------ pcbnew/class_pcb_layer_widget.cpp | 28 ++++++++++++++++--- pcbnew/class_pcb_layer_widget.h | 8 ++++++ pcbnew/files.cpp | 9 ++++++- pcbnew/ioascii.cpp | 28 ++++++++++++++++++- pcbnew/kicad_plugin.cpp | 34 +++++++++++++++--------- pcbnew/layer_widget.cpp | 5 +++- pcbnew/layer_widget.h | 7 +++-- pcbnew/pcbframe.cpp | 6 +++++ 15 files changed, 145 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 5432d16da1..2ba941fb52 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,13 @@ KiCad ChangeLog 2012 Please add newer entries at the top, list the date and your name with email address. +2012-Mar-11 UPDATE Dick Hollenbeck +================================================================================ +++pcbnew + * Add PCB_EDIT_FRAME::syncLayerVisibilities, PCB_LAYER_MANAGER::SyncLayerVisibilities(). + * Save all visibilities, layer and render, in BOARD and restore on load. + + 2012-Feb-19 UPDATE Dick Hollenbeck ================================================================================ ++pcbnew diff --git a/common/common.cpp b/common/common.cpp index 1aaff80ff8..573e2ecf86 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -265,7 +265,7 @@ wxString ReturnStringFromValue( EDA_UNITS_T aUnit, int aValue, int aInternal_Uni value_to_print = To_User_Unit( aUnit, aValue, aInternal_Unit ); - /* Yet another 'if Pcbnew' :( */ + // Yet another 'if Pcbnew' :( StringValue.Printf( ( aInternal_Unit > 1000 ) ? wxT( "%.4f" ) : wxT( "%.3f" ), value_to_print ); @@ -293,12 +293,12 @@ int ReturnValueFromString( EDA_UNITS_T aUnit, const wxString& TextValue, int Int int Value; double dtmp = 0; - /* Acquire the 'right' decimal point separator */ + // Acquire the 'right' decimal point separator const struct lconv* lc = localeconv(); wxChar decimal_point = lc->decimal_point[0]; wxString buf( TextValue.Strip( wxString::both ) ); - /* Convert the period in decimal point */ + // Convert the period in decimal point buf.Replace( wxT( "." ), wxString( decimal_point, 1 ) ); // An ugly fix needed by WxWidgets 2.9.1 that sometimes @@ -306,7 +306,7 @@ int ReturnValueFromString( EDA_UNITS_T aUnit, const wxString& TextValue, int Int // TODO: remove this line if WxWidgets 2.9.2 fixes this issue buf.Replace( wxT( "," ), wxString( decimal_point, 1 ) ); - /* Find the end of the numeric part */ + // Find the end of the numeric part unsigned brk_point = 0; while( brk_point < buf.Len() ) @@ -321,10 +321,10 @@ int ReturnValueFromString( EDA_UNITS_T aUnit, const wxString& TextValue, int Int ++brk_point; } - /* Extract the numeric part */ + // Extract the numeric part buf.Left( brk_point ).ToDouble( &dtmp ); - /* Check the optional unit designator (2 ch significant) */ + // Check the optional unit designator (2 ch significant) wxString unit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 2 ).Lower() ); if( unit == wxT( "in" ) || unit == wxT( "\"" ) ) @@ -335,7 +335,7 @@ int ReturnValueFromString( EDA_UNITS_T aUnit, const wxString& TextValue, int Int { aUnit = MILLIMETRES; } - else if( unit == wxT( "mi" ) || unit == wxT( "th" ) ) /* Mils or thous */ + else if( unit == wxT( "mi" ) || unit == wxT( "th" ) ) // Mils or thous { aUnit = INCHES; dtmp /= 1000; diff --git a/common/dialog_about/AboutDialog_main.cpp b/common/dialog_about/AboutDialog_main.cpp index 1e69432959..6137148358 100644 --- a/common/dialog_about/AboutDialog_main.cpp +++ b/common/dialog_about/AboutDialog_main.cpp @@ -207,6 +207,7 @@ static void InitKiCadAboutNew( AboutAppInfo& info ) info.AddDeveloper( new Contributor( wxT( "Jean-Pierre Charras" ), wxT( "jean-pierre.charras@gipsa-lab.inpg.fr" ) ) ); info.AddDeveloper( new Contributor( wxT( "Dick Hollenbeck" ), wxT( "dick@softplc.com" ) ) ); + info.AddDeveloper( new Contributor( wxT( "Frank Bennett" ), wxT( "bennett78@lpbroadband.net" ) ) ); info.AddDeveloper( new Contributor( wxT( "Hauptmech" ), wxT( "hauptmech@gmail.com" ) ) ); info.AddDeveloper( new Contributor( wxT( "Jerry Jacobs" ), wxT( "xor.gate.engineering@gmail.com" ) ) ); diff --git a/include/common.h b/include/common.h index d50c5dbc43..c2eb72ca0a 100644 --- a/include/common.h +++ b/include/common.h @@ -155,7 +155,7 @@ public: /** * Function IsCustom - * returns true if the type is "User" + * returns true if the type is Custom */ bool IsCustom() const; @@ -196,8 +196,6 @@ public: const wxSize GetSizeIU() const { return wxSize( GetWidthIU(), GetHeightIU() ); } #endif -// wxPoint GetOffsetMils() const { return m_Offset; } - int GetLeftMarginMils() const { return m_left_margin; } int GetRightMarginMils() const { return m_right_margin; } int GetTopMarginMils() const { return m_top_margin; } @@ -268,12 +266,12 @@ private: }; -extern wxString g_ProductName; +extern wxString g_ProductName; /// Default user lib path can be left void, if the standard lib path is used -extern wxString g_UserLibDirBuffer; +extern wxString g_UserLibDirBuffer; -extern bool g_ShowPageLimits; ///< true to display the page limits +extern bool g_ShowPageLimits; ///< true to display the page limits /// Name of default configuration file. (kicad.pro) extern wxString g_Prj_Default_Config_FullFilename; diff --git a/include/param_config.h b/include/param_config.h index f526e6adfb..a1d83c5309 100644 --- a/include/param_config.h +++ b/include/param_config.h @@ -11,6 +11,8 @@ #include + + /** Type of parameter in the configuration file */ enum paramcfg_id { PARAM_INT, @@ -31,11 +33,15 @@ enum paramcfg_id { #define INT_MAXVAL 0x7FFFFFFF + /** * Class PARAM_CFG_BASE - * is a base class which establishes the virtual functions ReadParam and SaveParam, - * which are re-implemented by a number of base classes, and these function's + * is a base class which establishes the interface functions ReadParam and SaveParam, + * which are implemented by a number of derived classes, and these function's * doxygen comments are inherited also. + *

+ * See kicad.odt or kicad.pdf, chapter 2 : + * "Installation and configuration/Initialization of the default config". */ class PARAM_CFG_BASE { diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index 6d116236cf..4a173be08f 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -133,8 +133,8 @@ protected: /** * Function syncLayerWidgetLayer - * updates the currently "selected" layer within the PCB_LAYER_WIDGET. - * The currently active layer is defined by the return value of getActiveLayer(). + * updates the currently layer "selection" within the PCB_LAYER_WIDGET. + * The currently selected layer is defined by the return value of getActiveLayer(). *

* This function cannot be inline without including layer_widget.h in * here and we do not want to do that. @@ -150,6 +150,14 @@ protected: */ void syncRenderStates(); + /** + * Function syncLayerVisibilities + * updates each "Layer" checkbox in the layer widget according + * to each layer's current visibility determined by IsLayerVisible(), and is + * helpful immediately after loading a BOARD which may have state information in it. + */ + void syncLayerVisibilities(); + virtual void unitsChangeRefresh(); /** diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 2a00d8c0c8..1026464c9a 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -516,18 +516,15 @@ void BOARD::SetVisibleLayers( int aLayerMask ) } -// these are not tidy, since there are PCB_VISIBLEs that are not stored in the bitmap. - 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 - */ + // Call SetElementVisibility for each item + // to ensure specific calculations that can be needed by some items, + // just changing the visibility flags could be not sufficient. for( int ii = 0; ii < PCB_VISIBLE( END_PCB_VISIBLE_LIST ); ii++ ) { int item_mask = 1 << ii; - SetElementVisibility( ii, aMask & item_mask ); + SetElementVisibility( ii, bool( aMask & item_mask ) ); } } @@ -563,8 +560,8 @@ void BOARD::SetElementVisibility( int aPCB_VISIBLE, bool isEnabled ) { case RATSNEST_VISIBLE: - // we must clear or set the CH_VISIBLE flags to hide/show ratsnet - // because we have a tool to show hide ratsnest relative to a pad or a module + // we must clear or set the CH_VISIBLE flags to hide/show ratsnest + // because we have a tool to show/hide ratsnest relative to a pad or a module // so the hide/show option is a per item selection if( IsElementVisible( RATSNEST_VISIBLE ) ) { diff --git a/pcbnew/class_pcb_layer_widget.cpp b/pcbnew/class_pcb_layer_widget.cpp index e0268d1516..3cd7ec006b 100644 --- a/pcbnew/class_pcb_layer_widget.cpp +++ b/pcbnew/class_pcb_layer_widget.cpp @@ -46,7 +46,7 @@ #include -// this is a read only template that is copied and modified before adding to LAYER_WIDGET +/// This is a read only template that is copied and modified before adding to LAYER_WIDGET const LAYER_WIDGET::ROW PCB_LAYER_WIDGET::s_render_rows[] = { #define RR LAYER_WIDGET::ROW // Render Row abreviation to reduce source width @@ -221,8 +221,30 @@ void PCB_LAYER_WIDGET::SyncRenderStates() for( unsigned row=0; rowIsElementVisible( s_render_rows[row].id ) ); + int rowId = s_render_rows[row].id; + + // this does not fire a UI event + SetRenderState( rowId, board->IsElementVisible( rowId ) ); + } +} + + +void PCB_LAYER_WIDGET::SyncLayerVisibilities() +{ + BOARD* board = myframe->GetBoard(); + int count = GetLayerRowCount(); + + for( int row=0; rowGetId() ); + + // this does not fire a UI event + SetLayerVisible( layerId, board->IsLayerVisible( layerId ) ); } } diff --git a/pcbnew/class_pcb_layer_widget.h b/pcbnew/class_pcb_layer_widget.h index 10e10fbd80..13f3a85007 100644 --- a/pcbnew/class_pcb_layer_widget.h +++ b/pcbnew/class_pcb_layer_widget.h @@ -66,6 +66,14 @@ public: */ void SyncRenderStates(); + /** + * Function SyncLayerVisibilities + * updates each "Layer" checkbox in this layer widget according + * to each layer's current visibility determined by IsLayerVisible(), and is + * helpful immediately after loading a BOARD which may have state information in it. + */ + void SyncLayerVisibilities(); + /** * Function SetLayersManagerTabsText * Update the layer manager tabs labels diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index ea1bd2724c..bec5346e58 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -370,10 +370,17 @@ this file again." ) ); ReFillLayerWidget(); ReCreateLayerBox( NULL ); - syncLayerWidgetLayer(); + // upate the layer widget to match board visibility states, both layers and render columns. + syncLayerVisibilities(); + syncLayerWidgetLayer(); syncRenderStates(); + // Update the RATSNEST items, which were not loaded at the time + // BOARD::SetVisibleElements() was called from within any PLUGIN. + // See case RATSNEST_VISIBLE: in BOARD::SetElementVisibility() + GetBoard()->SetVisibleElements( GetBoard()->GetVisibleElements() ); + updateTraceWidthSelectBox(); updateViaSizeSelectBox(); diff --git a/pcbnew/ioascii.cpp b/pcbnew/ioascii.cpp index 1904d5ebc4..3203bf11ab 100644 --- a/pcbnew/ioascii.cpp +++ b/pcbnew/ioascii.cpp @@ -217,12 +217,25 @@ int PCB_BASE_FRAME::ReadGeneralDescrPcb( LINE_READER* aReader ) data = strtok( NULL, delims ); sscanf( data, "%X", &enabledLayers ); - // Setup layer visibility + // layer usage GetBoard()->SetEnabledLayers( enabledLayers ); + + // layer visibility equals layer usage, unless overridden later via "VisibleLayers" GetBoard()->SetVisibleLayers( enabledLayers ); continue; } + if( stricmp( data, "VisibleLayers" ) == 0 ) + { + int visibleLayers = -1; + + data = strtok( NULL, delims ); + sscanf( data, "%X", &visibleLayers ); + + GetBoard()->SetVisibleLayers( visibleLayers ); + continue; + } + if( strncmp( data, "Ly", 2 ) == 0 ) // Old format for Layer count { int Masque_Layer = 1, ii; @@ -634,7 +647,13 @@ int PCB_BASE_FRAME::ReadSetup( LINE_READER* aReader ) GetScreen()->m_GridOrigin.x = Ox; GetScreen()->m_GridOrigin.y = Oy; + continue; + } + if( stricmp( line, "VisibleElements" ) == 0 ) + { + int visibleElements = strtoul( data, 0, 16 ); + bds.SetVisibleElements( visibleElements ); continue; } #endif @@ -778,6 +797,8 @@ static int WriteSetup( FILE* aFile, PCB_EDIT_FRAME* aFrame, BOARD* aBoard ) aFrame->GetOriginAxisPosition().x, aFrame->GetOriginAxisPosition().y ); + fprintf( aFile, "VisibleElements %X\n", bds.GetVisibleElements() ); + STRING_FORMATTER sf; g_PcbPlotOptions.Format( &sf, 0 ); @@ -810,7 +831,12 @@ bool PCB_EDIT_FRAME::WriteGeneralDescrPcb( FILE* File ) fprintf( File, "Ly %8X\n", g_TabAllCopperLayerMask[NbLayers - 1] | ALL_NO_CU_LAYERS ); + fprintf( File, "EnabledLayers %08X\n", GetBoard()->GetEnabledLayers() ); + + if( GetBoard()->GetEnabledLayers() != GetBoard()->GetVisibleLayers() ) + fprintf( File, "VisibleLayers %08X\n", GetBoard()->GetVisibleLayers() ); + fprintf( File, "Links %d\n", GetBoard()->GetRatsnestsCount() ); fprintf( File, "NoConn %d\n", GetBoard()->m_NbNoconnect ); diff --git a/pcbnew/kicad_plugin.cpp b/pcbnew/kicad_plugin.cpp index 85dd0096a2..dc795eb99f 100644 --- a/pcbnew/kicad_plugin.cpp +++ b/pcbnew/kicad_plugin.cpp @@ -356,11 +356,19 @@ void KICAD_PLUGIN::loadGENERAL() { int enabledLayers = hexParse( line + SZ( "EnabledLayers" ) ); - // Setup layer visibility + // layer usage m_board->SetEnabledLayers( enabledLayers ); + + // layer visibility equals layer usage, unless overridden later via "VisibleLayers" m_board->SetVisibleLayers( enabledLayers ); } + else if( TESTLINE( "VisibleLayers" ) ) + { + int visibleLayers = hexParse( line + SZ( "VisibleLayers" ) ); + m_board->SetVisibleLayers( visibleLayers ); + } + else if( TESTLINE( "Ly" ) ) // Old format for Layer count { int layer_mask = hexParse( line + SZ( "Ly" ) ); @@ -607,18 +615,6 @@ void KICAD_PLUGIN::loadSETUP() } } - /* no more used - else if( TESTLINE( "TrackWidth" ) ) - { - } - else if( TESTLINE( "ViaSize" ) ) - { - } - else if( TESTLINE( "MicroViaSize" ) ) - { - } - */ - else if( TESTLINE( "TrackWidthList" ) ) { BIU tmp = biuParse( line + SZ( "TrackWidthList" ) ); @@ -794,6 +790,12 @@ void KICAD_PLUGIN::loadSETUP() */ } + else if( TESTLINE( "VisibleElements" ) ) + { + int visibleElements = hexParse( line + SZ( "VisibleElements" ) ); + bds.SetVisibleElements( visibleElements ); + } + else if( TESTLINE( "$EndSETUP" ) ) { m_board->SetDesignSettings( bds ); @@ -2765,6 +2767,10 @@ void KICAD_PLUGIN::saveGENERAL() const */ fprintf( m_fp, "EnabledLayers %08X\n", m_board->GetEnabledLayers() ); + + if( m_board->GetEnabledLayers() != m_board->GetVisibleLayers() ) + fprintf( m_fp, "VisibleLayers %08X\n", m_board->GetVisibleLayers() ); + fprintf( m_fp, "Links %d\n", m_board->GetRatsnestsCount() ); fprintf( m_fp, "NoConn %d\n", m_board->m_NbNoconnect ); @@ -2918,6 +2924,8 @@ void KICAD_PLUGIN::saveSETUP() const } */ + fprintf( m_fp, "VisibleElements %X\n", bds.GetVisibleElements() ); + fprintf( m_fp, "$EndSETUP\n\n" ); } diff --git a/pcbnew/layer_widget.cpp b/pcbnew/layer_widget.cpp index a3f3a21664..3f3a7a7440 100644 --- a/pcbnew/layer_widget.cpp +++ b/pcbnew/layer_widget.cpp @@ -200,6 +200,7 @@ wxBitmap LAYER_WIDGET::makeBitmap( int aColor ) return bitmap; } + wxBitmapButton* LAYER_WIDGET::makeColorButton( wxWindow* aParent, int aColor, int aID ) { // dynamically make a wxBitMap and brush it with the appropriate color, @@ -218,6 +219,7 @@ wxBitmapButton* LAYER_WIDGET::makeColorButton( wxWindow* aParent, int aColor, in return ret; } + void LAYER_WIDGET::OnLeftDownLayers( wxMouseEvent& event ) { int row; @@ -325,6 +327,7 @@ void LAYER_WIDGET::OnMiddleDownRenderColor( wxMouseEvent& event ) passOnFocus(); } + void LAYER_WIDGET::OnRenderCheckBox( wxCommandEvent& event ) { wxCheckBox* eventSource = (wxCheckBox*) event.GetEventObject(); @@ -457,7 +460,7 @@ void LAYER_WIDGET::insertRenderRow( int aRow, const ROW& aSpec ) else // == -1, no color selection wanted { // need a place holder within the sizer to keep grid full. - wxPanel* invisible = new wxPanel( m_RenderScrolledWindow ); + wxPanel* invisible = new wxPanel( m_RenderScrolledWindow, encodeId( col, aSpec.id ) ); m_RenderFlexGridSizer->wxSizer::Insert( index+col, invisible, 0, flags ); } diff --git a/pcbnew/layer_widget.h b/pcbnew/layer_widget.h index 82b885bb7b..a80f58e382 100644 --- a/pcbnew/layer_widget.h +++ b/pcbnew/layer_widget.h @@ -166,11 +166,12 @@ protected: /** * Function getLayerComp - * returns the component within the m_LayersFlexGridSizer at aRow and aCol - * or NULL if \a these parameters are out of range. + * returns the component within the m_LayersFlexGridSizer at @a aRow and @a aCol + * or NULL if these parameters are out of range. * * @param aRow is the row index * @param aColumn is the column + * @return wxWindow - the component installed within the sizer at given grid coordinate. */ wxWindow* getLayerComp( int aRow, int aColumn ); wxWindow* getRenderComp( int aRow, int aColumn ); @@ -278,7 +279,6 @@ public: AppendRenderRow( aRowsArray[row] ); } - /** * Function ClearRenderRows * empties out the render rows. @@ -419,5 +419,4 @@ public: //----------------------------------------------- }; - #endif // LAYERWIDGET_H_ diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index aef0669b73..790d5de0ed 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -653,6 +653,12 @@ void PCB_EDIT_FRAME::syncRenderStates() } +void PCB_EDIT_FRAME::syncLayerVisibilities() +{ + m_Layers->SyncLayerVisibilities(); +} + + void PCB_EDIT_FRAME::unitsChangeRefresh() { PCB_BASE_FRAME::unitsChangeRefresh(); // Update the grid size select box.