Commit f0ba106e authored by dickelbeck's avatar dickelbeck

more amazing free software

parent 70fde0fd
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -3,32 +3,32 @@ ...@@ -3,32 +3,32 @@
* *
* Copyright (C) 2007-2008 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> * Copyright (C) 2007-2008 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2007 Kicad Developers, see change_log.txt for contributors. * Copyright (C) 2007 Kicad Developers, see change_log.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here: * along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license, * or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc., * or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
/* This source is a complement to specctra.cpp and implements the import of /* This source is a complement to specctra.cpp and implements the import of
a specctra session file (*.ses), and import of a specctra design file a specctra session file (*.ses), and import of a specctra design file
(*.dsn) file. The specification for the grammar of the specctra dsn file (*.dsn) file. The specification for the grammar of the specctra dsn file
used to develop this code is given here: used to develop this code is given here:
http://www.autotraxeda.com/docs/SPECCTRA/SPECCTRA.pdf http://www.autotraxeda.com/docs/SPECCTRA/SPECCTRA.pdf
Also see the comments at the top of the specctra.cpp file itself. Also see the comments at the top of the specctra.cpp file itself.
*/ */
...@@ -42,25 +42,30 @@ using namespace DSN; ...@@ -42,25 +42,30 @@ using namespace DSN;
void WinEDA_PcbFrame::ImportSpecctraDesign( wxCommandEvent& event ) void WinEDA_PcbFrame::ImportSpecctraDesign( wxCommandEvent& event )
{ {
/* @todo write this someday
if( !Clear_Pcb( true ) ) if( !Clear_Pcb( true ) )
return; return;
*/
} }
void WinEDA_PcbFrame::ImportSpecctraSession( wxCommandEvent& event ) void WinEDA_PcbFrame::ImportSpecctraSession( wxCommandEvent& event )
{ {
/*
if( GetScreen()->IsModify() ) if( GetScreen()->IsModify() )
{ {
if( !IsOK( this, _( "Board Modified: Continue ?" ) ) ) if( !IsOK( this, _( "Board Modified: Continue ?" ) ) )
return; return;
} }
*/
wxString sessionExt( wxT( ".ses" ) ); wxString sessionExt( wxT( ".ses" ) );
wxString fileName = GetScreen()->m_FileName; wxString fileName = GetScreen()->m_FileName;
wxString mask = wxT( "*" ) + sessionExt; wxString mask = wxT( "*" ) + sessionExt;
ChangeFileNameExt( fileName, sessionExt ); ChangeFileNameExt( fileName, sessionExt );
fileName = EDA_FileSelector( _( "Merge Specctra Session file:" ), fileName = EDA_FileSelector( _( "Merge Specctra Session file:" ),
wxEmptyString, wxEmptyString,
fileName, fileName,
...@@ -69,58 +74,83 @@ void WinEDA_PcbFrame::ImportSpecctraSession( wxCommandEvent& event ) ...@@ -69,58 +74,83 @@ void WinEDA_PcbFrame::ImportSpecctraSession( wxCommandEvent& event )
this, this,
wxFD_OPEN, wxFD_OPEN,
FALSE ); FALSE );
if( fileName == wxEmptyString ) if( fileName == wxEmptyString )
return; return;
SPECCTRA_DB db; SPECCTRA_DB db;
setlocale( LC_NUMERIC, "C" ); // Switch the locale to standard C setlocale( LC_NUMERIC, "C" ); // Switch the locale to standard C
try try
{ {
db.LoadSESSION( fileName ); db.LoadSESSION( fileName );
db.FromSESSION( m_Pcb ); db.FromSESSION( m_Pcb );
} }
catch( IOError ioe ) catch( IOError ioe )
{ {
setlocale( LC_NUMERIC, "" ); // Switch the locale to standard C setlocale( LC_NUMERIC, "" ); // revert to the current locale
DisplayError( this, ioe.errorText ); DisplayError( this, ioe.errorText );
return; return;
} }
setlocale( LC_NUMERIC, "" ); // Switch the locale to standard C setlocale( LC_NUMERIC, "" ); // revert to the current locale
m_SelTrackWidthBox_Changed = TRUE; m_SelTrackWidthBox_Changed = TRUE;
m_SelViaSizeBox_Changed = TRUE; m_SelViaSizeBox_Changed = TRUE;
GetScreen()->SetModify(); GetScreen()->SetModify();
m_Pcb->m_Status_Pcb = 0; m_Pcb->m_Status_Pcb = 0;
Affiche_Message( wxString( _("Session file imported and merged OK.")) ); Affiche_Message( wxString( _("Session file imported and merged OK.")) );
DrawPanel->Refresh( TRUE ); DrawPanel->Refresh( TRUE );
} }
namespace DSN { namespace DSN {
static wxPoint mapPt( const POINT& aPoint, double aResolution )
static wxPoint mapPt( const POINT& aPoint, UNIT_RES* aResolution )
{ {
wxPoint ret; wxPoint ret;
double resValue = aResolution->GetValue();
double factor; // multiply this times units to get mils for Kicad.
switch( aResolution->GetEngUnits() )
{
default:
case T_inch:
factor = 0.001;
break;
case T_mil:
factor = 1.0;
break;
case T_cm:
factor = 2.54/1000.0;
break;
case T_mm:
factor = 25.4/1000.0;
break;
case T_um:
factor = 25.4;
break;
}
// the factor of 10.0 is used to convert mils to deci-mils, the units // the factor of 10.0 is used to convert mils to deci-mils, the units
// used within Kicad. // used within Kicad.
ret.x = (int) (10.0 * aPoint.x / aResolution); factor *= 10.0;
ret.y = (int) -(10.0 * aPoint.y / aResolution);
ret.x = (int) (factor * aPoint.x / resValue);
ret.y = (int) -(factor * aPoint.y / resValue); // negate y coord
return ret; return ret;
} }
// no UI code in this function, throw exception to report problems to the
// no UI code in this function, throw exception to report problems to the
// UI handler: void WinEDA_PcbFrame::ImportSpecctraSession( wxCommandEvent& event ) // UI handler: void WinEDA_PcbFrame::ImportSpecctraSession( wxCommandEvent& event )
void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) throw( IOError ) void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) throw( IOError )
...@@ -129,7 +159,7 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) throw( IOError ) ...@@ -129,7 +159,7 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) throw( IOError )
if( !session ) if( !session )
ThrowIOError( _("Session file is missing the \"session\" section") ); ThrowIOError( _("Session file is missing the \"session\" section") );
if( !session->placement ) if( !session->placement )
ThrowIOError( _("Session file is missing the \"placement\" section") ); ThrowIOError( _("Session file is missing the \"placement\" section") );
...@@ -138,16 +168,16 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) throw( IOError ) ...@@ -138,16 +168,16 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) throw( IOError )
if( !session->route->library ) if( !session->route->library )
ThrowIOError( _("Session file is missing the \"library_out\" section") ); ThrowIOError( _("Session file is missing the \"library_out\" section") );
// delete all the old tracks and vias // delete all the old tracks and vias
aBoard->m_Track->DeleteStructList(); aBoard->m_Track->DeleteStructList();
aBoard->m_Track = NULL; aBoard->m_Track = NULL;
aBoard->m_NbSegmTrack = 0; aBoard->m_NbSegmTrack = 0;
aBoard->DeleteMARKERs(); aBoard->DeleteMARKERs();
// Walk the PLACEMENT object's COMPONENTs list, and for each PLACE within // Walk the PLACEMENT object's COMPONENTs list, and for each PLACE within
// each COMPONENT, reposition and re-orient each component and put on // each COMPONENT, reposition and re-orient each component and put on
// correct side of the board. // correct side of the board.
COMPONENTS& components = session->placement->components; COMPONENTS& components = session->placement->components;
for( COMPONENTS::iterator comp=components.begin(); comp!=components.end(); ++comp ) for( COMPONENTS::iterator comp=components.begin(); comp!=components.end(); ++comp )
...@@ -156,51 +186,62 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) throw( IOError ) ...@@ -156,51 +186,62 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) throw( IOError )
for( unsigned i=0; i<places.size(); ++i ) for( unsigned i=0; i<places.size(); ++i )
{ {
PLACE* place = &places[i]; // '&' even though places[] holds a pointer! PLACE* place = &places[i]; // '&' even though places[] holds a pointer!
wxString reference = CONV_FROM_UTF8( place->component_id.c_str() ); wxString reference = CONV_FROM_UTF8( place->component_id.c_str() );
MODULE* module = aBoard->FindModuleByReference( reference ); MODULE* module = aBoard->FindModuleByReference( reference );
if( !module ) if( !module )
{ {
wxString errorMsg; ThrowIOError(
errorMsg.Printf( _("Session file has 'reference' to non-existent component \"%s\""),
_("Session file has reference to non-existing component \"%s\""),
reference.GetData() ); reference.GetData() );
ThrowIOError( errorMsg );
} }
if( !place->hasVertex ) if( !place->hasVertex )
continue; continue;
double resolution = 100; //place->GetResolution(); UNIT_RES* resolution = place->GetUnits();
wxASSERT( resolution );
wxPoint newPos = mapPt( place->vertex, resolution ); wxPoint newPos = mapPt( place->vertex, resolution );
module->SetPosition( newPos ); module->SetPosition( newPos );
if( place->side == T_front ) if( place->side == T_front )
{ {
// convert from degrees to tenths of degrees used in Kicad. // convert from degrees to tenths of degrees used in Kicad.
int orientation = (int) (place->rotation * 10.0); int orientation = (int) (place->rotation * 10.0);
module->SetOrientation( orientation );
if( module->GetLayer() != CMP_N ) if( module->GetLayer() != CMP_N )
{
// module is on copper layer (back)
aBoard->Change_Side_Module( module, 0 ); aBoard->Change_Side_Module( module, 0 );
}
module->SetOrientation( orientation );
} }
else if( place->side == T_back ) else if( place->side == T_back )
{ {
int orientation = (int) (-place->rotation * 10.0 - 1800); int orientation = (place->rotation + 180.0) * 10.0;
module->SetOrientation( orientation );
if( module->GetLayer() != COPPER_LAYER_N ) if( module->GetLayer() != COPPER_LAYER_N )
{
// module is on component layer (front)
aBoard->Change_Side_Module( module, 0 ); aBoard->Change_Side_Module( module, 0 );
}
module->SetOrientation( orientation );
}
else
{
// as I write this, the LEXER *is* catching this, so we should never see below:
wxFAIL_MSG( wxT("DSN::LEXER did not catch an illegal side := 'back|front'") );
} }
} }
} }
// Walk the NET_OUTs and create tracks and vias anew. // Walk the NET_OUTs and create tracks and vias anew.
NET_OUTS& net_outs = session->route->net_outs; NET_OUTS& net_outs = session->route->net_outs;
for( NET_OUTS::iterator i=net_outs.begin(); i!=net_outs.end(); ++i ) for( NET_OUTS::iterator i=net_outs.begin(); i!=net_outs.end(); ++i )
{ {
// create a track or via and position it. // create a track or via and position it.
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment