From 1b108afd0b2d0a7c424393f2078637e3e23cf2fd Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 16 Mar 2022 12:31:45 +0100 Subject: [PATCH] Specctra import/export: fix some issues (tested only with FreeRouter): - Handling of locked tracks - Locked tracks are now exported with attribute "fix". - Incorrect view cleaning - Fix memory leak. From master branch. --- pcbnew/specctra_import_export/specctra.cpp | 2 +- pcbnew/specctra_import_export/specctra.h | 6 +- .../specctra_export.cpp | 10 ++- .../specctra_import.cpp | 62 ++++++++++++++++--- 4 files changed, 65 insertions(+), 15 deletions(-) diff --git a/pcbnew/specctra_import_export/specctra.cpp b/pcbnew/specctra_import_export/specctra.cpp index 1c5f102b2f..565aedd16d 100644 --- a/pcbnew/specctra_import_export/specctra.cpp +++ b/pcbnew/specctra_import_export/specctra.cpp @@ -3,7 +3,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2007-2011 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2007-2021 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2007-2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/pcbnew/specctra_import_export/specctra.h b/pcbnew/specctra_import_export/specctra.h index 8183539905..fccc2cd715 100644 --- a/pcbnew/specctra_import_export/specctra.h +++ b/pcbnew/specctra_import_export/specctra.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2007-2013 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2007-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2007-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -3962,13 +3962,13 @@ private: /** * Create a #TRACK form the #PATH and #BOARD info. */ - PCB_TRACK* makeTRACK( PATH* aPath, int aPointIndex, int aNetcode ); + PCB_TRACK* makeTRACK( WIRE* wire, PATH* aPath, int aPointIndex, int aNetcode ); /** * Instantiate a KiCad #VIA on the heap and initializes it with internal * values consistent with the given #PADSTACK, #POINT, and netcode. */ - PCB_VIA* makeVIA( PADSTACK* aPadstack, const POINT& aPoint, int aNetCode, + PCB_VIA* makeVIA( WIRE_VIA*aVia, PADSTACK* aPadstack, const POINT& aPoint, int aNetCode, int aViaDrillDefault ); //--------------------------------------------------------- diff --git a/pcbnew/specctra_import_export/specctra_export.cpp b/pcbnew/specctra_import_export/specctra_export.cpp index 793b026151..4cdeb05bef 100644 --- a/pcbnew/specctra_import_export/specctra_export.cpp +++ b/pcbnew/specctra_import_export/specctra_export.cpp @@ -1694,7 +1694,10 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) wiring->wires.push_back( wire ); wire->net_id = netname; - wire->wire_type = T_protect; // @todo, this should be configurable + if( track->IsLocked() ) + wire->wire_type = T_fix; // tracks with fix property are not returnned in .ses files + else + wire->wire_type = T_route; // could be T_protect LAYER_NUM kiLayer = track->GetLayer(); int pcbLayer = m_kicadLayer2pcb[kiLayer]; @@ -1753,7 +1756,10 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) dsnVia->net_id = TO_UTF8( net->GetNetname() ); - dsnVia->via_type = T_protect; // @todo, this should be configurable + if( via->IsLocked() ) + dsnVia->via_type = T_fix; // vias with fix property are not returnned in .ses files + else + dsnVia->via_type = T_route; // could be T_protect } } diff --git a/pcbnew/specctra_import_export/specctra_import.cpp b/pcbnew/specctra_import_export/specctra_import.cpp index 28df3d7a67..9612ed8845 100644 --- a/pcbnew/specctra_import_export/specctra_import.cpp +++ b/pcbnew/specctra_import_export/specctra_import.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2007-2013 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2007 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2007-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -57,6 +57,14 @@ bool PCB_EDIT_FRAME::ImportSpecctraSession( const wxString& fullFileName ) // todo: use undo/redo feature ClearUndoRedoList(); + // Remove existing tracks from view. They will be readded later after loading + // new tracks. + if( GetCanvas() ) // clear view: + { + for( PCB_TRACK* track : GetBoard()->Tracks() ) + GetCanvas()->GetView()->Remove( track ); + } + SPECCTRA_DB db; LOCALE_IO toggle; @@ -157,7 +165,7 @@ static wxPoint mapPt( const POINT& aPoint, UNIT_RES* aResolution ) } -PCB_TRACK* SPECCTRA_DB::makeTRACK( PATH* aPath, int aPointIndex, int aNetcode ) +PCB_TRACK* SPECCTRA_DB::makeTRACK( WIRE* wire, PATH* aPath, int aPointIndex, int aNetcode ) { int layerNdx = findLayerName( aPath->layer_id ); @@ -175,11 +183,19 @@ PCB_TRACK* SPECCTRA_DB::makeTRACK( PATH* aPath, int aPointIndex, int aNetcode ) track->SetWidth( scale( aPath->aperture_width, m_routeResolution ) ); track->SetNetCode( aNetcode ); + // a track can be locked. + // However specctra as 4 types, none is exactly the same as our locked option + // wire->wire_type = T_fix, T_route, T_normal or T_protect + // fix and protect could be used as lock option + // but protect is returned for all tracks having initially the route or protect property + if( wire->wire_type == T_fix ) + track->SetLocked( true ); + return track; } -PCB_VIA* SPECCTRA_DB::makeVIA( PADSTACK* aPadstack, const POINT& aPoint, int aNetCode, +PCB_VIA* SPECCTRA_DB::makeVIA( WIRE_VIA*aVia, PADSTACK* aPadstack, const POINT& aPoint, int aNetCode, int aViaDrillDefault ) { PCB_VIA* via = 0; @@ -311,6 +327,15 @@ PCB_VIA* SPECCTRA_DB::makeVIA( PADSTACK* aPadstack, const POINT& aPoint, int aNe wxASSERT( via ); via->SetNetCode( aNetCode ); + + // a via can be locked. + // However specctra as 4 types, none is exactly the same as our locked option + // aVia->via_type = T_fix, T_route, T_normal or T_protect + // fix and protect could be used as lock option + // but protect is returned for all tracks having initially the route or protect property + if( aVia->via_type == T_fix ) + via->SetLocked( true ); + return via; } @@ -331,13 +356,32 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) if( !m_session->route->library ) THROW_IO_ERROR( _("Session file is missing the \"library_out\" section") ); - // delete all the old tracks and vias - aBoard->Tracks().clear(); + // delete all the old tracks and vias but save locked tracks/vias + // they will be re-added later + std::vector locked; + + while( !aBoard->Tracks().empty() ) + { + PCB_TRACK* track = aBoard->Tracks().back(); + aBoard->Tracks().pop_back(); + + if( track->IsLocked() ) + locked.push_back( track ); + else + delete track; + } aBoard->DeleteMARKERs(); buildLayerMaps( aBoard ); + // Add locked tracks: because they are exported as Fix tracks, they are not + // in .ses file. + for( PCB_TRACK* track: locked ) + { + aBoard->Add( track ); + } + if( m_session->placement ) { // Walk the PLACEMENT object's COMPONENTs list, and for each PLACE within @@ -452,9 +496,9 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) { PATH* path = (PATH*) wire->shape; - for( unsigned pt=0; ptpoints.size()-1; ++pt ) + for( unsigned pt=0; pt < path->points.size()-1; ++pt ) { - PCB_TRACK* track = makeTRACK( path, pt, netoutCode ); + PCB_TRACK* track = makeTRACK( wire, path, pt, netoutCode ); aBoard->Add( track ); } } @@ -506,9 +550,9 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) int via_drill_default = netclass->GetViaDrill(); - for( unsigned v=0; vvertexes.size(); ++v ) + for( unsigned v = 0; v < wire_via->vertexes.size(); ++v ) { - PCB_VIA* via = makeVIA( padstack, wire_via->vertexes[v], netCode, + PCB_VIA* via = makeVIA( wire_via, padstack, wire_via->vertexes[v], netCode, via_drill_default ); aBoard->Add( via ); }