KiCad PCB EDA Suite
Loading...
Searching...
No Matches
export_gencad.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2016 Jean-Pierre Charras, [email protected]
5 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright (C) 2012 Wayne Stambaugh <[email protected]>
7 * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
31#include <board.h>
33#include <confirm.h>
35#include <pcb_edit_frame.h>
36#include <project/project_file.h> // LAST_PATH_TYPE
37
39
40
41/* Driver function: processing starts here */
42void PCB_EDIT_FRAME::ExportToGenCAD( wxCommandEvent& aEvent )
43{
44 // Build default output file name
45 wxString path = GetLastPath( LAST_PATH_GENCAD );
46
47 if( path.IsEmpty() )
48 {
49 wxFileName brdFile = GetBoard()->GetFileName();
50 brdFile.SetExt( wxT( "cad" ) );
51 path = brdFile.GetFullPath();
52 }
53
54 DIALOG_GENCAD_EXPORT_OPTIONS optionsDialog( this, path );
55
56 if( optionsDialog.ShowModal() == wxID_CANCEL )
57 return;
58
59 path = optionsDialog.GetFileName();
61
62 // Get options
63 bool flipBottomPads = optionsDialog.GetOption( FLIP_BOTTOM_PADS );
64 bool uniquePinName = optionsDialog.GetOption( UNIQUE_PIN_NAMES );
65 bool individualShapes = optionsDialog.GetOption( INDIVIDUAL_SHAPES );
66 bool storeOriginCoords = optionsDialog.GetOption( STORE_ORIGIN_COORDS );
67
68 // No idea on *why* this should be needed... maybe to fix net names?
69 Compile_Ratsnest( true );
70
71 GENCAD_EXPORTER exporter( GetBoard() );
72
73 // This is the export origin (the auxiliary axis)
74 VECTOR2I GencadOffset;
76 GencadOffset.x = optionsDialog.GetOption( USE_AUX_ORIGIN ) ? auxOrigin.x : 0;
77 GencadOffset.y = optionsDialog.GetOption( USE_AUX_ORIGIN ) ? auxOrigin.y : 0;
78
79 exporter.SetPlotOffet( GencadOffset );
80 exporter.FlipBottomPads( flipBottomPads );
81 exporter.UsePinNamesUnique( uniquePinName );
82 exporter.UseIndividualShapes( individualShapes );
83 exporter.StoreOriginCoordsInFile( storeOriginCoords );
84
85 bool success = exporter.WriteFile( path );
86
87 if( !success )
88 {
89 DisplayError( this, wxString::Format( _( "Failed to create file '%s'." ), path ) );
90 return;
91 }
92}
93
const VECTOR2I & GetAuxOrigin()
const wxString & GetFileName() const
Definition: board.h:327
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:890
bool GetOption(GENCAD_EXPORT_OPT aOption) const
Return all export settings.
int ShowModal() override
void UseIndividualShapes(bool aUnique)
Make pad shapes unique.
void UsePinNamesUnique(bool aUnique)
Make pin names unique.
void StoreOriginCoordsInFile(bool aStore)
Store coord origin in genCAD file.
void FlipBottomPads(bool aFlip)
Flip pad shapes on the bottom side.
void SetPlotOffet(VECTOR2I aOffset)
Set the coordinates offet when exporting items.
bool WriteFile(const wxString &aFullFileName)
Export a genCAD file.
BOARD * GetBoard() const
void Compile_Ratsnest(bool aDisplayStatus)
Create the entire board ratsnest.
Definition: ratsnest.cpp:35
void SetLastPath(LAST_PATH_TYPE aType, const wxString &aLastPath)
Set the path of the last file successfully read.
wxString GetLastPath(LAST_PATH_TYPE aType)
Get the last path for a particular type.
void ExportToGenCAD(wxCommandEvent &event)
Create a file in GenCAD 1.4 format from the current board.
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:170
This file is part of the common library.
#define _(s)
@ LAST_PATH_GENCAD
Definition: project_file.h:55