From c8584436b42a9e4a0713812fc3803d4ac0e1c66a Mon Sep 17 00:00:00 2001 From: dickelbeck Date: Thu, 7 Feb 2008 06:49:16 +0000 Subject: [PATCH] specctra import work --- pcbnew/initpcb.cpp | 2 +- pcbnew/ioascii.cpp | 1 + pcbnew/specctra.h | 13 +++++- pcbnew/specctra_export.cpp | 11 +---- pcbnew/specctra_import.cpp | 96 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 112 insertions(+), 11 deletions(-) diff --git a/pcbnew/initpcb.cpp b/pcbnew/initpcb.cpp index 5a31ac2fec..cd219ddcd1 100644 --- a/pcbnew/initpcb.cpp +++ b/pcbnew/initpcb.cpp @@ -119,7 +119,7 @@ bool WinEDA_BasePcbFrame::Clear_Pcb( bool query ) if( query && GetScreen()->IsModify() ) { - if( m_Pcb->m_Drawings ||m_Pcb->m_Modules + if( m_Pcb->m_Drawings || m_Pcb->m_Modules || m_Pcb->m_Track || m_Pcb->m_Zone ) { if( !IsOK( this, _( "Current Board will be lost ?" ) ) ) diff --git a/pcbnew/ioascii.cpp b/pcbnew/ioascii.cpp index 477c60e8e8..5c48874245 100644 --- a/pcbnew/ioascii.cpp +++ b/pcbnew/ioascii.cpp @@ -844,6 +844,7 @@ int WinEDA_PcbFrame::ReadPcbFile( wxDC* DC, FILE* File, bool Append ) ZONE_CONTAINER * zone_descr = new ZONE_CONTAINER(m_Pcb); zone_descr->ReadDescr( File, &LineNum ); m_Pcb->Add(zone_descr); + continue; } if( strnicmp( Line, "$MODULE", 7 ) == 0 ) diff --git a/pcbnew/specctra.h b/pcbnew/specctra.h index 2ddcaa8b6d..05fed3f659 100644 --- a/pcbnew/specctra.h +++ b/pcbnew/specctra.h @@ -1782,6 +1782,7 @@ public: i->Format( out, nestLevel ); } }; +typedef boost::ptr_vector COMPONENTS; class PLACEMENT : public ELEM @@ -1792,7 +1793,6 @@ class PLACEMENT : public ELEM DSN_T flip_style; - typedef boost::ptr_vector COMPONENTS; COMPONENTS components; public: @@ -3812,6 +3812,17 @@ public: * @param aBoard The BOARD to convert to a PCB. */ void FromBOARD( BOARD* aBoard ); + + + /** + * Function FromSESSION + * adds the entire SESSION info to a BOARD but does not write it out. The + * the BOARD given to this function will have all its tracks and via's replaced, + * and all its components are subject to being moved. + * + * @param aBoard The BOARD to merge the SESSION information into. + */ + void FromSESSION( BOARD* aBoard ) throw( IOError ); /** diff --git a/pcbnew/specctra_export.cpp b/pcbnew/specctra_export.cpp index 2b5b6426c9..e6658b3ec0 100644 --- a/pcbnew/specctra_export.cpp +++ b/pcbnew/specctra_export.cpp @@ -63,13 +63,6 @@ void WinEDA_PcbFrame::ExportToSpecctra( wxCommandEvent& event ) if( fullFileName == wxEmptyString ) return; - // prepare the EQUIPOTs - if( !( m_Pcb->m_Status_Pcb & NET_CODES_OK ) ) - { - //m_Pcb->m_Status_Pcb &= ~(LISTE_PAD_OK); - recalcule_pad_net_code(); - } - SPECCTRA_DB db; bool ok = true; wxString errorText; @@ -172,8 +165,8 @@ static POINT mapPt( const wxPoint& pt ) /** * Function findPOINT * searches the list of POINT_PAIRS for a matching end to the given POINT. - * @return int - 0 if no match, or + one based index of a POINT_PAIR with a matching ".start", - * or a - one based index of a POINT_PAIR with a matching ".end". + * @return int - 0 if no match, or positive one based index of a POINT_PAIR with a matching ".start", + * or a negated one based index of a POINT_PAIR with a matching ".end". */ static int findPOINT( const POINT& pt, const POINT_PAIR source[], int count ) { diff --git a/pcbnew/specctra_import.cpp b/pcbnew/specctra_import.cpp index 0942f27d04..cbcc4203cb 100644 --- a/pcbnew/specctra_import.cpp +++ b/pcbnew/specctra_import.cpp @@ -34,17 +34,113 @@ #include "specctra.h" +#include "common.h" // IsOK() & EDA_FileSelector() + using namespace DSN; void WinEDA_PcbFrame::ImportSpecctraDesign( wxCommandEvent& event ) { + if( !Clear_Pcb( true ) ) + return; } void WinEDA_PcbFrame::ImportSpecctraSession( wxCommandEvent& event ) { + if( GetScreen()->IsModify() ) + { + if( !IsOK( this, _( "Board Modified: Continue ?" ) ) ) + return; + } + + wxString sessionExt( wxT( ".ses" ) ); + wxString fileName = GetScreen()->m_FileName; + wxString mask = wxT( "*" ) + sessionExt; + + ChangeFileNameExt( fileName, sessionExt ); + + fileName = EDA_FileSelector( _( "Merge Specctra Session file:" ), + wxEmptyString, + fileName, + sessionExt, + mask, + this, + wxFD_OPEN, + FALSE ); + + if( fileName == wxEmptyString ) + return; + + SPECCTRA_DB db; + + try + { + db.LoadSESSION( fileName ); + db.FromSESSION( m_Pcb ); + } + catch( IOError ioe ) + { + DisplayError( this, ioe.errorText ); + return; + } + + m_SelTrackWidthBox_Changed = TRUE; + m_SelViaSizeBox_Changed = TRUE; + + GetScreen()->SetModify(); + m_Pcb->m_Status_Pcb = 0; + + Affiche_Message( wxString( _("Session file imported and merged OK.")) ); + + DrawPanel->Refresh( TRUE ); } + +namespace DSN { + +// no UI code in this function, throw exception to report problems to the +// UI handler: void WinEDA_PcbFrame::ImportSpecctraSession( wxCommandEvent& event ) + +void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) throw( IOError ) +{ + wxASSERT( session ); + + // delete all the old tracks and vias + aBoard->m_Track->DeleteStructList(); + aBoard->m_Track = NULL; + aBoard->m_NbSegmTrack = 0; + + aBoard->DeleteMARKERs(); + + + if( !session->placement ) + ThrowIOError( _("Session file is missing the \"placement\" section") ); + + if( !session->route ) + ThrowIOError( _("Session file is missing the \"routes\" section") ); + + if( !session->route->library ) + ThrowIOError( _("Session file is missing the \"library_out\" section") ); + + + // Walk the PLACEMENT object's components list. + COMPONENTS& components = session->placement->components; + for( COMPONENTS::iterator i=components.begin(); i!=components.end(); ++i ) + { + // reposition and re-orient each component and put on correct side of the board. + } + + // Walk the NET_OUTs and create tracks and vias anew. + NET_OUTS& net_outs = session->route->net_outs; + for( NET_OUTS::iterator i=net_outs.begin(); i!=net_outs.end(); ++i ) + { + // create a track or via and position it. + } +} + + +} // namespace DSN +