From c7e7014b148d9a5c667a3bb3c04b95a7c8161a38 Mon Sep 17 00:00:00 2001 From: dickelbeck Date: Thu, 14 Feb 2008 15:34:40 +0000 Subject: [PATCH] module flip reverting on exception --- pcbnew/specctra.h | 16 ++++++++++++-- pcbnew/specctra_export.cpp | 44 +++++++++++++++++++++++++++++--------- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/pcbnew/specctra.h b/pcbnew/specctra.h index 8a0bef086b..81eba79858 100644 --- a/pcbnew/specctra.h +++ b/pcbnew/specctra.h @@ -3578,6 +3578,8 @@ class SPECCTRA_DB : public OUTPUTFORMATTER std::string quote_char; + bool modulesAreFlipped; + STRINGFORMATTER sf; STRINGS layerIds; ///< indexed by PCB layer number @@ -3822,6 +3824,11 @@ class SPECCTRA_DB : public OUTPUTFORMATTER nets.clear(); } + /** + * Function flipMODULEs + * flips the modules which are on the back side of the board to the front. + */ + void flipMODULEs( BOARD* aBoard ); //---------------------------------------------------------- @@ -3850,6 +3857,7 @@ public: session = 0; fp = 0; quote_char += '"'; + modulesAreFlipped = false; } virtual ~SPECCTRA_DB() @@ -3957,7 +3965,6 @@ public: */ void FromBOARD( BOARD* aBoard ) throw( IOError ); - /** * Function FromSESSION * adds the entire SESSION info to a BOARD but does not write it out. The @@ -3968,7 +3975,6 @@ public: */ void FromSESSION( BOARD* aBoard ) throw( IOError ); - /** * Function ExportSESSION * writes the internal SESSION instance out as a SPECTRA DSN format file. @@ -3976,6 +3982,12 @@ public: * @param aFilename The file to save to. */ void ExportSESSION( wxString aFilename ); + + /** + * Function RevertMODULEs + * flips the modules which were on the back side of the board back to the back. + */ + void RevertMODULEs( BOARD* aBoard ); }; diff --git a/pcbnew/specctra_export.cpp b/pcbnew/specctra_export.cpp index 330c503ba9..ffc101d0ce 100644 --- a/pcbnew/specctra_export.cpp +++ b/pcbnew/specctra_export.cpp @@ -97,6 +97,11 @@ void WinEDA_PcbFrame::ExportToSpecctra( wxCommandEvent& event ) setlocale( LC_NUMERIC, "" ); // revert to the current locale + // this is called in FromBOARD() too, but if it throws an exception, that call + // does not happen, so call it again just in case here. + db.RevertMODULEs( m_Pcb ); + + // The two calls below to BOARD::Change_Side_Module(), both set the // modified flag, yet their actions cancel each other out, so it should // be ok to clear the modify flag. @@ -727,15 +732,7 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) throw( IOError ) // DSN Images (=Kicad MODULES and pads) must be presented from the // top view. So we temporarily flip any modules which are on the back // side of the board to the front, and record this in the MODULE's flag field. - for( MODULE* module = aBoard->m_Modules; module; module = module->Next() ) - { - module->flag = 0; - if( module->GetLayer() == COPPER_LAYER_N ) - { - aBoard->Change_Side_Module( module, NULL ); - module->flag = 1; - } - } + flipMODULEs( aBoard ); //---------------------------------------------------- { @@ -1220,7 +1217,32 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) throw( IOError ) } - //----------------------------------------------------- + //--------------------------------------------------- + + RevertMODULEs( aBoard ); +} + + +void SPECCTRA_DB::flipMODULEs( BOARD* aBoard ) +{ + for( MODULE* module = aBoard->m_Modules; module; module = module->Next() ) + { + module->flag = 0; + if( module->GetLayer() == COPPER_LAYER_N ) + { + aBoard->Change_Side_Module( module, NULL ); + module->flag = 1; + } + } + + modulesAreFlipped = true; +} + + +void SPECCTRA_DB::RevertMODULEs( BOARD* aBoard ) +{ + if( !modulesAreFlipped ) + return; // DSN Images (=Kicad MODULES and pads) must be presented from the // top view. Restore those that were flipped. @@ -1232,6 +1254,8 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) throw( IOError ) module->flag = 0; } } + + modulesAreFlipped = false; }