2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file gen_modules_placefile.cpp
|
|
|
|
*/
|
2012-02-15 10:41:16 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2018-02-03 20:28:21 +00:00
|
|
|
* Copyright (C) 2015-2018 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-02-15 10:41:16 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* 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 write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/*
|
2007-08-23 04:28:46 +00:00
|
|
|
* 1 - create ascii files for automatic placement of smd components
|
|
|
|
* 2 - create a module report (pos and module descr) (ascii file)
|
|
|
|
*/
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <gestfich.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
#include <pgm_base.h>
|
2018-02-17 16:27:59 +00:00
|
|
|
#include <bitmaps.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <build_version.h>
|
|
|
|
#include <macros.h>
|
2014-09-08 11:07:54 +00:00
|
|
|
#include <reporter.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
|
|
|
|
#include <pcbnew.h>
|
2012-02-16 20:03:33 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2015-05-01 15:01:09 +00:00
|
|
|
#include <kiface_i.h>
|
2015-06-16 12:20:42 +00:00
|
|
|
#include <wx_html_report_panel.h>
|
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
|
2018-02-16 16:52:19 +00:00
|
|
|
#include <dialog_gen_footprint_position_file_base.h>
|
2015-02-22 15:42:13 +00:00
|
|
|
/*
|
2016-04-26 12:16:16 +00:00
|
|
|
* The ASCII format of the kicad place file is:
|
2015-02-22 15:42:13 +00:00
|
|
|
* ### Module positions - created on 04/12/2012 15:24:24 ###
|
|
|
|
* ### Printed by Pcbnew version pcbnew (2012-11-30 BZR 3828)-testing
|
|
|
|
* ## Unit = inches, Angle = deg.
|
|
|
|
* or
|
|
|
|
* ## Unit = mm, Angle = deg.
|
|
|
|
* ## Side : top
|
|
|
|
* or
|
|
|
|
* ## Side : bottom
|
|
|
|
* or
|
|
|
|
* ## Side : all
|
2016-02-12 11:50:42 +00:00
|
|
|
* # Ref Val Package PosX PosY Rot Side
|
2015-02-22 15:42:13 +00:00
|
|
|
* C123 0,1uF/50V SM0603 1.6024 -2.6280 180.0 Front
|
|
|
|
* C124 0,1uF/50V SM0603 1.6063 -2.7579 180.0 Front
|
|
|
|
* C125 0,1uF/50V SM0603 1.6010 -2.8310 180.0 Front
|
|
|
|
* ## End
|
|
|
|
*/
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2016-04-26 12:16:16 +00:00
|
|
|
#define PLACEFILE_UNITS_KEY wxT( "PlaceFileUnits" )
|
|
|
|
#define PLACEFILE_OPT_KEY wxT( "PlaceFileOpts" )
|
|
|
|
#define PLACEFILE_FORMAT_KEY wxT( "PlaceFileFormat" )
|
2015-05-01 15:01:09 +00:00
|
|
|
|
2010-01-05 08:48:49 +00:00
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
#define PCB_BACK_SIDE 0
|
|
|
|
#define PCB_FRONT_SIDE 1
|
|
|
|
#define PCB_BOTH_SIDES 2
|
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
class LIST_MOD // An helper class used to build a list of useful footprints.
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MODULE* m_Module; // Link to the actual footprint
|
2014-01-18 09:07:05 +00:00
|
|
|
wxString m_Reference; // Its schematic reference
|
|
|
|
wxString m_Value; // Its schematic value
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_NUM m_Layer; // its side (B_Cu, or F_Cu)
|
2012-02-15 10:41:16 +00:00
|
|
|
};
|
|
|
|
|
2012-04-05 18:27:56 +00:00
|
|
|
|
|
|
|
/**
|
2018-07-07 16:46:23 +00:00
|
|
|
* The dialog to create footprint position files and choose options (one or 2 files, units
|
|
|
|
* and force all SMD footprints in list)
|
2012-02-15 10:41:16 +00:00
|
|
|
*/
|
2018-02-16 19:26:55 +00:00
|
|
|
class DIALOG_GEN_FOOTPRINT_POSITION : public DIALOG_GEN_FOOTPRINT_POSITION_BASE
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-02-16 19:26:55 +00:00
|
|
|
DIALOG_GEN_FOOTPRINT_POSITION( PCB_EDIT_FRAME * aParent ):
|
|
|
|
DIALOG_GEN_FOOTPRINT_POSITION_BASE( aParent ),
|
2012-04-05 18:27:56 +00:00
|
|
|
m_parent( aParent ),
|
|
|
|
m_plotOpts( aParent->GetPlotSettings() )
|
2012-02-15 10:41:16 +00:00
|
|
|
{
|
2015-06-19 08:55:37 +00:00
|
|
|
m_reporter = &m_messagesPanel->Reporter();
|
2015-05-01 15:01:09 +00:00
|
|
|
initDialog();
|
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
// We use a sdbSizer to get platform-dependent ordering of the action buttons, but
|
|
|
|
// that requires us to correct the button labels here.
|
|
|
|
m_sdbSizer1OK->SetLabel( _( "Generate Position File" ) );
|
|
|
|
m_sdbSizer1Cancel->SetLabel( _( "Close" ) );
|
|
|
|
m_sdbSizer1->Layout();
|
|
|
|
|
|
|
|
m_sdbSizer1OK->SetDefault();
|
|
|
|
|
2015-05-01 15:01:09 +00:00
|
|
|
GetSizer()->SetSizeHints(this);
|
|
|
|
Centre();
|
2012-02-15 10:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-04-05 18:27:56 +00:00
|
|
|
PCB_EDIT_FRAME* m_parent;
|
|
|
|
PCB_PLOT_PARAMS m_plotOpts;
|
2015-05-01 15:01:09 +00:00
|
|
|
wxConfigBase* m_config;
|
2015-06-16 12:20:42 +00:00
|
|
|
REPORTER* m_reporter;
|
2012-04-05 18:27:56 +00:00
|
|
|
|
|
|
|
static int m_unitsOpt;
|
|
|
|
static int m_fileOpt;
|
2016-04-26 12:16:16 +00:00
|
|
|
static int m_fileFormat;
|
2012-04-05 18:27:56 +00:00
|
|
|
|
2017-07-25 19:14:31 +00:00
|
|
|
void initDialog();
|
2016-09-24 18:53:15 +00:00
|
|
|
void OnOutputDirectoryBrowseClicked( wxCommandEvent& event ) override;
|
2018-02-17 16:27:59 +00:00
|
|
|
void OnGenerate( wxCommandEvent& event ) override;
|
2012-02-15 10:41:16 +00:00
|
|
|
|
|
|
|
bool CreateFiles();
|
|
|
|
|
|
|
|
// accessors to options:
|
|
|
|
wxString GetOutputDirectory()
|
|
|
|
{
|
|
|
|
return m_outputDirectoryName->GetValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UnitsMM()
|
|
|
|
{
|
|
|
|
return m_radioBoxUnits->GetSelection() == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OneFileOnly()
|
|
|
|
{
|
|
|
|
return m_radioBoxFilesCount->GetSelection() == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ForceAllSmd()
|
|
|
|
{
|
2018-07-07 16:46:23 +00:00
|
|
|
return m_forceSMDOpt->GetValue();
|
2012-02-15 10:41:16 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
2012-04-05 18:27:56 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
// Static members to remember choices
|
2018-02-16 19:26:55 +00:00
|
|
|
int DIALOG_GEN_FOOTPRINT_POSITION::m_unitsOpt = 0;
|
|
|
|
int DIALOG_GEN_FOOTPRINT_POSITION::m_fileOpt = 0;
|
|
|
|
int DIALOG_GEN_FOOTPRINT_POSITION::m_fileFormat = 0;
|
2012-02-15 10:41:16 +00:00
|
|
|
|
2015-02-22 15:42:13 +00:00
|
|
|
// Use standard board side name. do not translate them,
|
|
|
|
// they are keywords in place file
|
|
|
|
const wxString frontSideName = wxT( "top" );
|
|
|
|
const wxString backSideName = wxT( "bottom" );
|
|
|
|
|
2018-02-16 19:26:55 +00:00
|
|
|
void DIALOG_GEN_FOOTPRINT_POSITION::initDialog()
|
2012-02-15 10:41:16 +00:00
|
|
|
{
|
2018-02-28 09:44:22 +00:00
|
|
|
m_browseButton->SetBitmap( KiBitmap( folder_xpm ) );
|
2018-02-17 16:27:59 +00:00
|
|
|
|
2015-05-01 15:01:09 +00:00
|
|
|
m_config = Kiface().KifaceSettings();
|
|
|
|
m_config->Read( PLACEFILE_UNITS_KEY, &m_unitsOpt, 1 );
|
|
|
|
m_config->Read( PLACEFILE_OPT_KEY, &m_fileOpt, 0 );
|
2016-04-26 12:16:16 +00:00
|
|
|
m_config->Read( PLACEFILE_FORMAT_KEY, &m_fileFormat, 0 );
|
2015-05-01 15:01:09 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
// Output directory
|
2012-04-05 18:27:56 +00:00
|
|
|
m_outputDirectoryName->SetValue( m_plotOpts.GetOutputDirectory() );
|
2012-02-15 10:41:16 +00:00
|
|
|
m_radioBoxUnits->SetSelection( m_unitsOpt );
|
|
|
|
m_radioBoxFilesCount->SetSelection( m_fileOpt );
|
2016-04-26 12:16:16 +00:00
|
|
|
m_rbFormat->SetSelection( m_fileFormat );
|
2012-02-15 10:41:16 +00:00
|
|
|
|
2018-02-17 16:27:59 +00:00
|
|
|
// Update sizes and sizers:
|
|
|
|
m_messagesPanel->MsgPanelSetMinSize( wxSize( -1, 160 ) );
|
|
|
|
GetSizer()->SetSizeHints( this );
|
2012-02-15 10:41:16 +00:00
|
|
|
}
|
|
|
|
|
2018-02-16 19:26:55 +00:00
|
|
|
void DIALOG_GEN_FOOTPRINT_POSITION::OnOutputDirectoryBrowseClicked( wxCommandEvent& event )
|
2012-02-15 10:41:16 +00:00
|
|
|
{
|
|
|
|
// Build the absolute path of current output plot directory
|
|
|
|
// to preselect it when opening the dialog.
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
wxString path = Prj().AbsolutePath( m_outputDirectoryName->GetValue() );
|
2012-02-15 10:41:16 +00:00
|
|
|
|
|
|
|
wxDirDialog dirDialog( this, _( "Select Output Directory" ), path );
|
|
|
|
|
|
|
|
if( dirDialog.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
|
|
|
|
|
2017-11-02 17:18:57 +00:00
|
|
|
wxMessageDialog dialog( this, _( "Use a relative path?"),
|
2012-02-15 10:41:16 +00:00
|
|
|
_( "Plot Output Directory" ),
|
|
|
|
wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
|
|
|
|
|
|
|
|
if( dialog.ShowModal() == wxID_YES )
|
|
|
|
{
|
2012-08-29 16:59:50 +00:00
|
|
|
wxString boardFilePath = ( (wxFileName) m_parent->GetBoard()->GetFileName()).GetPath();
|
2012-02-15 10:41:16 +00:00
|
|
|
|
|
|
|
if( !dirName.MakeRelativeTo( boardFilePath ) )
|
|
|
|
wxMessageBox( _( "Cannot make path relative (target volume different from board file volume)!" ),
|
|
|
|
_( "Plot Output Directory" ), wxOK | wxICON_ERROR );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_outputDirectoryName->SetValue( dirName.GetFullPath() );
|
|
|
|
}
|
|
|
|
|
2018-02-17 16:27:59 +00:00
|
|
|
void DIALOG_GEN_FOOTPRINT_POSITION::OnGenerate( wxCommandEvent& event )
|
2012-02-15 10:41:16 +00:00
|
|
|
{
|
|
|
|
m_unitsOpt = m_radioBoxUnits->GetSelection();
|
|
|
|
m_fileOpt = m_radioBoxFilesCount->GetSelection();
|
2016-04-26 12:16:16 +00:00
|
|
|
m_fileFormat = m_rbFormat->GetSelection();
|
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
|
2015-05-01 15:01:09 +00:00
|
|
|
m_config->Write( PLACEFILE_UNITS_KEY, m_unitsOpt );
|
|
|
|
m_config->Write( PLACEFILE_OPT_KEY, m_fileOpt );
|
2016-04-26 12:16:16 +00:00
|
|
|
m_config->Write( PLACEFILE_FORMAT_KEY, m_fileFormat );
|
2015-05-01 15:01:09 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
// Set output directory and replace backslashes with forward ones
|
|
|
|
// (Keep unix convention in cfg files)
|
|
|
|
wxString dirStr;
|
|
|
|
dirStr = m_outputDirectoryName->GetValue();
|
|
|
|
dirStr.Replace( wxT( "\\" ), wxT( "/" ) );
|
2012-04-05 18:27:56 +00:00
|
|
|
|
|
|
|
m_plotOpts.SetOutputDirectory( dirStr );
|
|
|
|
m_parent->SetPlotSettings( m_plotOpts );
|
2012-02-15 10:41:16 +00:00
|
|
|
|
|
|
|
CreateFiles();
|
2016-04-26 12:16:16 +00:00
|
|
|
|
|
|
|
// the dialog is not closed here.
|
2012-02-15 10:41:16 +00:00
|
|
|
}
|
|
|
|
|
2012-04-05 18:27:56 +00:00
|
|
|
|
2018-02-16 19:26:55 +00:00
|
|
|
bool DIALOG_GEN_FOOTPRINT_POSITION::CreateFiles()
|
2012-02-15 10:41:16 +00:00
|
|
|
{
|
|
|
|
BOARD * brd = m_parent->GetBoard();
|
|
|
|
wxFileName fn;
|
|
|
|
wxString msg;
|
|
|
|
bool singleFile = OneFileOnly();
|
2016-04-26 12:16:16 +00:00
|
|
|
bool useCSVfmt = m_fileFormat == 1;
|
2012-02-15 10:41:16 +00:00
|
|
|
int fullcount = 0;
|
|
|
|
|
2013-11-27 19:38:59 +00:00
|
|
|
// Count the footprints to place, do not yet create a file
|
|
|
|
int fpcount = m_parent->DoGenFootprintsPositionFile( wxEmptyString, UnitsMM(),
|
2016-04-26 12:16:16 +00:00
|
|
|
ForceAllSmd(), PCB_BOTH_SIDES,
|
|
|
|
useCSVfmt );
|
2013-11-27 19:38:59 +00:00
|
|
|
if( fpcount == 0)
|
|
|
|
{
|
2015-11-17 16:18:00 +00:00
|
|
|
wxMessageBox( _( "No footprint for automated placement." ) );
|
2013-11-27 19:38:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-08 11:07:54 +00:00
|
|
|
// Create output directory if it does not exist (also transform it in
|
2016-04-26 12:16:16 +00:00
|
|
|
// absolute path). Bail if it fails
|
2014-09-08 11:07:54 +00:00
|
|
|
wxFileName outputDir = wxFileName::DirName( m_plotOpts.GetOutputDirectory() );
|
|
|
|
wxString boardFilename = m_parent->GetBoard()->GetFileName();
|
|
|
|
|
2015-06-16 12:20:42 +00:00
|
|
|
m_reporter = &m_messagesPanel->Reporter();
|
|
|
|
|
|
|
|
if( !EnsureFileDirectoryExists( &outputDir, boardFilename, m_reporter ) )
|
2014-09-08 11:07:54 +00:00
|
|
|
{
|
|
|
|
msg.Printf( _( "Could not write plot files to folder \"%s\"." ),
|
|
|
|
GetChars( outputDir.GetPath() ) );
|
|
|
|
DisplayError( this, msg );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-29 16:59:50 +00:00
|
|
|
fn = m_parent->GetBoard()->GetFileName();
|
2014-09-08 11:07:54 +00:00
|
|
|
fn.SetPath( outputDir.GetPath() );
|
2012-02-15 10:41:16 +00:00
|
|
|
|
|
|
|
// Create the the Front or Top side placement file,
|
|
|
|
// or the single file
|
2016-02-12 11:50:42 +00:00
|
|
|
int side = PCB_FRONT_SIDE;
|
2013-11-27 19:38:59 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
if( singleFile )
|
|
|
|
{
|
2016-02-12 11:50:42 +00:00
|
|
|
side = PCB_BOTH_SIDES;
|
2012-05-03 18:37:56 +00:00
|
|
|
fn.SetName( fn.GetName() + wxT( "-" ) + wxT("all") );
|
2012-02-15 10:41:16 +00:00
|
|
|
}
|
2013-11-27 19:38:59 +00:00
|
|
|
else
|
2015-02-22 15:42:13 +00:00
|
|
|
fn.SetName( fn.GetName() + wxT( "-" ) + frontSideName );
|
2012-02-15 10:41:16 +00:00
|
|
|
|
2016-04-26 12:16:16 +00:00
|
|
|
|
|
|
|
if( useCSVfmt )
|
|
|
|
{
|
|
|
|
fn.SetName( fn.GetName() + wxT( "-" ) + FootprintPlaceFileExtension );
|
|
|
|
fn.SetExt( wxT( "csv" ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fn.SetExt( FootprintPlaceFileExtension );
|
2012-02-15 10:41:16 +00:00
|
|
|
|
2013-11-27 19:38:59 +00:00
|
|
|
fpcount = m_parent->DoGenFootprintsPositionFile( fn.GetFullPath(), UnitsMM(),
|
2016-04-26 12:16:16 +00:00
|
|
|
ForceAllSmd(), side, useCSVfmt );
|
2012-02-15 10:41:16 +00:00
|
|
|
if( fpcount < 0 )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Unable to create \"%s\"." ), GetChars( fn.GetFullPath() ) );
|
2012-02-15 10:41:16 +00:00
|
|
|
wxMessageBox( msg );
|
2015-06-16 12:20:42 +00:00
|
|
|
m_reporter->Report( msg, REPORTER::RPT_ERROR );
|
2012-02-15 10:41:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( singleFile )
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Place file: \"%s\"." ), GetChars( fn.GetFullPath() ) );
|
2012-02-15 10:41:16 +00:00
|
|
|
else
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Front side (top side) place file: \"%s\"." ),
|
2013-04-10 07:23:20 +00:00
|
|
|
GetChars( fn.GetFullPath() ) );
|
2015-06-16 12:20:42 +00:00
|
|
|
m_reporter->Report( msg, REPORTER::RPT_INFO );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2015-06-16 12:20:42 +00:00
|
|
|
msg.Printf( _( "Component count: %d." ), fpcount );
|
|
|
|
m_reporter->Report( msg, REPORTER::RPT_INFO );
|
2012-02-15 10:41:16 +00:00
|
|
|
|
|
|
|
if( singleFile )
|
2015-06-16 12:20:42 +00:00
|
|
|
{
|
2016-04-21 07:32:29 +00:00
|
|
|
m_reporter->Report( _( "Component Placement File generation OK." ), REPORTER::RPT_ACTION );
|
2012-02-15 10:41:16 +00:00
|
|
|
return true;
|
2015-06-16 12:20:42 +00:00
|
|
|
}
|
2012-02-15 10:41:16 +00:00
|
|
|
|
|
|
|
// Create the Back or Bottom side placement file
|
|
|
|
fullcount = fpcount;
|
2016-02-12 11:50:42 +00:00
|
|
|
side = PCB_BACK_SIDE;
|
2012-08-29 16:59:50 +00:00
|
|
|
fn = brd->GetFileName();
|
2014-09-08 11:07:54 +00:00
|
|
|
fn.SetPath( outputDir.GetPath() );
|
2015-02-22 15:42:13 +00:00
|
|
|
fn.SetName( fn.GetName() + wxT( "-" ) + backSideName );
|
2016-04-26 12:16:16 +00:00
|
|
|
|
|
|
|
if( useCSVfmt )
|
|
|
|
{
|
|
|
|
fn.SetName( fn.GetName() + wxT( "-" ) + FootprintPlaceFileExtension );
|
|
|
|
fn.SetExt( wxT( "csv" ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fn.SetExt( FootprintPlaceFileExtension );
|
2012-02-15 10:41:16 +00:00
|
|
|
|
|
|
|
fpcount = m_parent->DoGenFootprintsPositionFile( fn.GetFullPath(), UnitsMM(),
|
2016-04-26 12:16:16 +00:00
|
|
|
ForceAllSmd(), side, useCSVfmt );
|
2012-02-15 10:41:16 +00:00
|
|
|
|
|
|
|
if( fpcount < 0 )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Unable to create file \"%s\"." ), GetChars( fn.GetFullPath() ) );
|
2015-06-16 12:20:42 +00:00
|
|
|
m_reporter->Report( msg, REPORTER::RPT_ERROR );
|
2012-02-15 10:41:16 +00:00
|
|
|
wxMessageBox( msg );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display results
|
|
|
|
if( !singleFile )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Back side (bottom side) place file: \"%s\"." ), GetChars( fn.GetFullPath() ) );
|
2015-06-16 12:20:42 +00:00
|
|
|
m_reporter->Report( msg, REPORTER::RPT_INFO );
|
|
|
|
|
|
|
|
msg.Printf( _( "Component count: %d." ), fpcount );
|
|
|
|
|
|
|
|
m_reporter->Report( msg, REPORTER::RPT_INFO );
|
2012-02-15 10:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !singleFile )
|
|
|
|
{
|
|
|
|
fullcount += fpcount;
|
2015-06-16 12:20:42 +00:00
|
|
|
msg.Printf( _( "Full component count: %d\n" ), fullcount );
|
|
|
|
m_reporter->Report( msg, REPORTER::RPT_INFO );
|
2012-02-15 10:41:16 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 07:32:29 +00:00
|
|
|
m_reporter->Report( _( "Component Placement File generation OK." ), REPORTER::RPT_ACTION );
|
2015-06-16 12:20:42 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Defined values to write coordinates using inches or mm:
|
2012-05-03 18:37:56 +00:00
|
|
|
static const double conv_unit_inch = 0.001 / IU_PER_MILS ; // units = INCHES
|
2012-02-15 10:41:16 +00:00
|
|
|
static const char unit_text_inch[] = "## Unit = inches, Angle = deg.\n";
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
static const double conv_unit_mm = 1.0 / IU_PER_MM; // units = mm
|
2012-02-15 10:41:16 +00:00
|
|
|
static const char unit_text_mm[] = "## Unit = mm, Angle = deg.\n";
|
++PCBNew
* Removed Pcb_Frame argument from BOARD() constructor, since it precludes
having a BOARD being edited by more than one editor, it was a bad design.
And this meant removing m_PcbFrame from BOARD.
* removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame
* Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp
* added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance
* a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed,
such as dialog_mask_clearance, dialog_drc, etc.
* Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it
with build_version.h's #define BOARD_FILE_VERSION, although there may be a
better place for this constant.
* Made the public functions in PARAM_CFG_ARRAY be type const.
void SaveParam(..) const and void ReadParam(..) const
* PARAM_CFG_BASE now has virtual destructor since we have various way of
destroying the derived class and boost::ptr_vector must be told about this.
* Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use
an automatic PARAM_CFG_ARRAY which is on the stack.\
* PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array,
since it has to access the current BOARD and the BOARD can change.
Remember BOARD_DESIGN_SETTINGS are now in the BOARD.
* Made the m_BoundingBox member private, this was a brutally hard task,
and indicative of the lack of commitment to accessors and object oriented
design on the part of KiCad developers. We must do better.
Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox().
* Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
|
|
|
|
2012-02-11 18:54:36 +00:00
|
|
|
static wxPoint File_Place_Offset; // Offset coordinates for generated file.
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
|
2012-02-11 18:54:36 +00:00
|
|
|
// Sort function use by GenereModulesPosition()
|
2012-02-15 10:41:16 +00:00
|
|
|
// sort is made by side (layer) top layer first
|
|
|
|
// then by reference increasing order
|
|
|
|
static bool sortFPlist( const LIST_MOD& ref, const LIST_MOD& tst )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2012-02-15 10:41:16 +00:00
|
|
|
if( ref.m_Layer == tst.m_Layer )
|
2019-03-02 13:20:53 +00:00
|
|
|
return StrNumCmp( ref.m_Reference, tst.m_Reference ) < 0;
|
2008-10-01 23:35:31 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
return ref.m_Layer > tst.m_Layer;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-23 18:11:36 +00:00
|
|
|
/**
|
2012-02-15 10:41:16 +00:00
|
|
|
* Helper function HasNonSMDPins
|
2008-04-23 18:11:36 +00:00
|
|
|
* returns true if the given module has any non smd pins, such as through hole
|
|
|
|
* and therefore cannot be placed automatically.
|
|
|
|
*/
|
|
|
|
static bool HasNonSMDPins( MODULE* aModule )
|
|
|
|
{
|
|
|
|
D_PAD* pad;
|
|
|
|
|
2017-04-25 09:06:24 +00:00
|
|
|
for( pad = aModule->PadsList(); pad; pad = pad->Next() )
|
2008-04-23 18:11:36 +00:00
|
|
|
{
|
2015-08-23 19:40:33 +00:00
|
|
|
if( pad->GetAttribute() != PAD_ATTRIB_SMD )
|
2008-04-23 18:11:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
void PCB_EDIT_FRAME::GenFootprintsPositionFile( wxCommandEvent& event )
|
|
|
|
{
|
2018-02-16 19:26:55 +00:00
|
|
|
DIALOG_GEN_FOOTPRINT_POSITION dlg( this );
|
2012-02-15 10:41:16 +00:00
|
|
|
dlg.ShowModal();
|
|
|
|
}
|
2008-04-23 18:11:36 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
/*
|
|
|
|
* Creates a footprint position file
|
|
|
|
* aSide = 0 -> Back (bottom) side)
|
|
|
|
* aSide = 1 -> Front (top) side)
|
|
|
|
* aSide = 2 -> both sides
|
2015-02-23 13:03:20 +00:00
|
|
|
* if aFullFileName is empty, the file is not created, only the
|
2013-11-27 19:38:59 +00:00
|
|
|
* count of footprints to place is returned
|
2012-02-15 10:41:16 +00:00
|
|
|
*/
|
|
|
|
int PCB_EDIT_FRAME::DoGenFootprintsPositionFile( const wxString& aFullFileName,
|
|
|
|
bool aUnitsMM,
|
2016-04-26 12:16:16 +00:00
|
|
|
bool aForceSmdItems, int aSide,
|
|
|
|
bool aFormatCSV )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2016-02-12 11:50:42 +00:00
|
|
|
MODULE* footprint;
|
|
|
|
|
2016-07-11 03:09:18 +00:00
|
|
|
// Minimal text lengths:
|
2016-02-12 11:50:42 +00:00
|
|
|
int lenRefText = 8;
|
|
|
|
int lenValText = 8;
|
|
|
|
int lenPkgText = 16;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
File_Place_Offset = GetAuxOrigin();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
// Calculating the number of useful footprints (CMS attribute, not VIRTUAL)
|
|
|
|
int footprintCount = 0;
|
2008-04-23 18:11:36 +00:00
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
// Select units:
|
|
|
|
double conv_unit = aUnitsMM ? conv_unit_mm : conv_unit_inch;
|
|
|
|
const char *unit_text = aUnitsMM ? unit_text_mm : unit_text_inch;
|
|
|
|
|
|
|
|
// Build and sort the list of footprints alphabetically
|
|
|
|
std::vector<LIST_MOD> list;
|
|
|
|
list.reserve( footprintCount );
|
|
|
|
|
|
|
|
for( footprint = GetBoard()->m_Modules; footprint; footprint = footprint->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2016-02-12 11:50:42 +00:00
|
|
|
if( aSide != PCB_BOTH_SIDES )
|
2012-02-15 10:41:16 +00:00
|
|
|
{
|
2016-02-12 11:50:42 +00:00
|
|
|
if( footprint->GetLayer() == B_Cu && aSide == PCB_FRONT_SIDE)
|
2012-02-15 10:41:16 +00:00
|
|
|
continue;
|
2016-02-12 11:50:42 +00:00
|
|
|
if( footprint->GetLayer() == F_Cu && aSide == PCB_BACK_SIDE)
|
2012-02-15 10:41:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
if( footprint->GetAttributes() & MOD_VIRTUAL )
|
2008-04-23 18:11:36 +00:00
|
|
|
{
|
2016-02-12 11:50:42 +00:00
|
|
|
DBG( printf( "skipping footprint %s because it's virtual\n",
|
|
|
|
TO_UTF8( footprint->GetReference() ) );)
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
2008-04-23 18:11:36 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
if( ( footprint->GetAttributes() & MOD_CMS ) == 0 )
|
2008-04-23 18:11:36 +00:00
|
|
|
{
|
2016-02-12 11:50:42 +00:00
|
|
|
if( aForceSmdItems ) // true to fix a bunch of mis-labeled footprints:
|
2008-04-23 18:11:36 +00:00
|
|
|
{
|
2016-02-12 11:50:42 +00:00
|
|
|
if( !HasNonSMDPins( footprint ) )
|
2012-02-15 10:41:16 +00:00
|
|
|
{
|
2016-02-12 11:50:42 +00:00
|
|
|
// all footprint's pins are SMD, mark the part for pick and place
|
|
|
|
footprint->SetAttributes( footprint->GetAttributes() | MOD_CMS );
|
2012-02-15 10:41:16 +00:00
|
|
|
OnModify();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-10 08:47:42 +00:00
|
|
|
DBG(printf( "skipping %s because its attribute is not CMS and it has non SMD pins\n",
|
2016-02-12 11:50:42 +00:00
|
|
|
TO_UTF8(footprint->GetReference()) ) );
|
2012-02-15 10:41:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-04-23 18:11:36 +00:00
|
|
|
}
|
2012-12-06 21:53:00 +00:00
|
|
|
else
|
|
|
|
continue;
|
2008-04-23 18:11:36 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
footprintCount++;
|
|
|
|
|
|
|
|
LIST_MOD item;
|
|
|
|
item.m_Module = footprint;
|
|
|
|
item.m_Reference = footprint->GetReference();
|
|
|
|
item.m_Value = footprint->GetValue();
|
|
|
|
item.m_Layer = footprint->GetLayer();
|
|
|
|
list.push_back( item );
|
|
|
|
|
|
|
|
lenRefText = std::max( lenRefText, int(item.m_Reference.length()) );
|
|
|
|
lenValText = std::max( lenValText, int(item.m_Value.length()) );
|
2017-07-24 19:02:59 +00:00
|
|
|
lenPkgText = std::max( lenPkgText, int(item.m_Module->GetFPID().GetLibItemName().length()) );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2013-11-27 19:38:59 +00:00
|
|
|
if( aFullFileName.IsEmpty() )
|
2016-02-12 11:50:42 +00:00
|
|
|
return footprintCount;
|
2013-11-27 19:38:59 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
FILE * file = wxFopen( aFullFileName, wxT( "wt" ) );
|
|
|
|
if( file == NULL )
|
|
|
|
return -1;
|
2011-02-27 23:25:07 +00:00
|
|
|
|
2012-12-06 21:53:00 +00:00
|
|
|
if( list.size() > 1 )
|
2012-02-15 10:41:16 +00:00
|
|
|
sort( list.begin(), list.end(), sortFPlist );
|
|
|
|
|
2012-12-06 21:53:00 +00:00
|
|
|
// Switch the locale to standard C (needed to print floating point numbers)
|
|
|
|
LOCALE_IO toggle;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2016-04-26 12:16:16 +00:00
|
|
|
if( aFormatCSV )
|
|
|
|
{
|
|
|
|
wxChar csv_sep = ',';
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2016-04-26 12:16:16 +00:00
|
|
|
// Set first line:;
|
|
|
|
fprintf( file, "Ref%cVal%cPackage%cPosX%cPosY%cRot%cSide\n",
|
|
|
|
csv_sep, csv_sep, csv_sep, csv_sep, csv_sep, csv_sep );
|
2011-02-27 23:25:07 +00:00
|
|
|
|
2016-04-26 12:16:16 +00:00
|
|
|
for( int ii = 0; ii < footprintCount; ii++ )
|
|
|
|
{
|
|
|
|
wxPoint footprint_pos;
|
|
|
|
footprint_pos = list[ii].m_Module->GetPosition();
|
|
|
|
footprint_pos -= File_Place_Offset;
|
|
|
|
|
|
|
|
LAYER_NUM layer = list[ii].m_Module->GetLayer();
|
|
|
|
wxASSERT( layer == F_Cu || layer == B_Cu );
|
|
|
|
|
2018-02-03 20:28:21 +00:00
|
|
|
wxString line = "\"" + list[ii].m_Reference;
|
|
|
|
line << "\"" << csv_sep;
|
|
|
|
line << "\"" << list[ii].m_Value;
|
|
|
|
line << "\"" << csv_sep;
|
|
|
|
line << "\"" << list[ii].m_Module->GetFPID().GetLibItemName().wx_str();
|
|
|
|
line << "\"" << csv_sep;
|
2016-04-26 12:16:16 +00:00
|
|
|
|
|
|
|
line << wxString::Format( "%f%c%f%c%f",
|
|
|
|
footprint_pos.x * conv_unit, csv_sep,
|
|
|
|
// Keep the Y axis oriented from bottom to top,
|
|
|
|
// ( change y coordinate sign )
|
|
|
|
-footprint_pos.y * conv_unit, csv_sep,
|
|
|
|
list[ii].m_Module->GetOrientation() / 10.0 );
|
|
|
|
line << csv_sep;
|
|
|
|
|
|
|
|
line << ( (layer == F_Cu ) ? frontSideName : backSideName );
|
|
|
|
line << '\n';
|
|
|
|
|
|
|
|
fputs( TO_UTF8( line ), file );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Write file header
|
|
|
|
fprintf( file, "### Module positions - created on %s ###\n", TO_UTF8( DateAndTime() ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2016-04-26 12:16:16 +00:00
|
|
|
wxString Title = Pgm().App().GetAppName() + wxT( " " ) + GetBuildVersion();
|
|
|
|
fprintf( file, "### Printed by Pcbnew version %s\n", TO_UTF8( Title ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2016-04-26 12:16:16 +00:00
|
|
|
fputs( unit_text, file );
|
2015-02-23 13:03:20 +00:00
|
|
|
|
2016-04-26 12:16:16 +00:00
|
|
|
fputs( "## Side : ", file );
|
2015-02-23 13:03:20 +00:00
|
|
|
|
2016-04-26 12:16:16 +00:00
|
|
|
if( aSide == PCB_BACK_SIDE )
|
|
|
|
fputs( TO_UTF8( backSideName ), file );
|
|
|
|
else if( aSide == PCB_FRONT_SIDE )
|
|
|
|
fputs( TO_UTF8( frontSideName ), file );
|
|
|
|
else
|
|
|
|
fputs( "All", file );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2016-04-26 12:16:16 +00:00
|
|
|
fputs( "\n", file );
|
|
|
|
|
|
|
|
fprintf(file, "%-*s %-*s %-*s %9.9s %9.9s %8.8s %s\n",
|
|
|
|
int(lenRefText), "# Ref",
|
|
|
|
int(lenValText), "Val",
|
|
|
|
int(lenPkgText), "Package",
|
|
|
|
"PosX", "PosY", "Rot", "Side" );
|
|
|
|
|
|
|
|
for( int ii = 0; ii < footprintCount; ii++ )
|
|
|
|
{
|
|
|
|
wxPoint footprint_pos;
|
|
|
|
footprint_pos = list[ii].m_Module->GetPosition();
|
|
|
|
footprint_pos -= File_Place_Offset;
|
|
|
|
|
|
|
|
LAYER_NUM layer = list[ii].m_Module->GetLayer();
|
|
|
|
wxASSERT( layer == F_Cu || layer == B_Cu );
|
|
|
|
|
2018-03-20 16:55:31 +00:00
|
|
|
if( layer == B_Cu )
|
|
|
|
footprint_pos.x = - footprint_pos.x;
|
|
|
|
|
|
|
|
wxString ref = list[ii].m_Reference;
|
|
|
|
wxString val = list[ii].m_Value;
|
|
|
|
wxString pkg = list[ii].m_Module->GetFPID().GetLibItemName();
|
|
|
|
ref.Replace( wxT( " " ), wxT( "_" ) );
|
|
|
|
val.Replace( wxT( " " ), wxT( "_" ) );
|
|
|
|
pkg.Replace( wxT( " " ), wxT( "_" ) );
|
2016-04-26 12:16:16 +00:00
|
|
|
fprintf(file, "%-*s %-*s %-*s %9.4f %9.4f %8.4f %s\n",
|
|
|
|
lenRefText, TO_UTF8( ref ),
|
|
|
|
lenValText, TO_UTF8( val ),
|
|
|
|
lenPkgText, TO_UTF8( pkg ),
|
|
|
|
footprint_pos.x * conv_unit,
|
|
|
|
// Keep the coordinates in the first quadrant,
|
|
|
|
// (i.e. change y sign
|
|
|
|
-footprint_pos.y * conv_unit,
|
|
|
|
list[ii].m_Module->GetOrientation() / 10.0,
|
|
|
|
(layer == F_Cu ) ? TO_UTF8( frontSideName ) : TO_UTF8( backSideName ));
|
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2016-04-26 12:16:16 +00:00
|
|
|
// Write EOF
|
|
|
|
fputs( "## End\n", file );
|
|
|
|
}
|
2008-10-01 16:00:35 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
fclose( file );
|
2016-02-12 11:50:42 +00:00
|
|
|
return footprintCount;
|
2012-02-15 10:41:16 +00:00
|
|
|
}
|
2008-10-01 16:00:35 +00:00
|
|
|
|
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
void PCB_EDIT_FRAME::GenFootprintsReport( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxFileName fn;
|
2008-10-01 23:35:31 +00:00
|
|
|
|
2012-08-29 16:59:50 +00:00
|
|
|
wxString boardFilePath = ( (wxFileName) GetBoard()->GetFileName()).GetPath();
|
2012-02-15 10:41:16 +00:00
|
|
|
wxDirDialog dirDialog( this, _( "Select Output Directory" ), boardFilePath );
|
2008-10-01 23:35:31 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
if( dirDialog.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
2008-10-01 23:35:31 +00:00
|
|
|
|
2012-08-29 16:59:50 +00:00
|
|
|
fn = GetBoard()->GetFileName();
|
2012-02-15 10:41:16 +00:00
|
|
|
fn.SetPath( dirDialog.GetPath() );
|
|
|
|
fn.SetExt( wxT( "rpt" ) );
|
2008-10-01 16:05:20 +00:00
|
|
|
|
2018-02-02 15:56:09 +00:00
|
|
|
bool unitMM = GetUserUnits() != INCHES;
|
2016-02-12 11:50:42 +00:00
|
|
|
bool success = DoGenFootprintsReport( fn.GetFullPath(), unitMM );
|
2008-10-01 16:00:35 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
wxString msg;
|
|
|
|
if( success )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Footprint report file created:\n\"%s\"" ),
|
2012-02-15 10:41:16 +00:00
|
|
|
GetChars( fn.GetFullPath() ) );
|
2014-11-02 12:44:57 +00:00
|
|
|
wxMessageBox( msg, _( "Footprint Report" ), wxICON_INFORMATION );
|
2012-02-15 10:41:16 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
else
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Unable to create \"%s\"" ), GetChars( fn.GetFullPath() ) );
|
2012-02-15 10:41:16 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/* Print a module report.
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2012-02-15 10:41:16 +00:00
|
|
|
bool PCB_EDIT_FRAME::DoGenFootprintsReport( const wxString& aFullFilename, bool aUnitsMM )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2015-11-04 08:48:34 +00:00
|
|
|
wxString msg;
|
2007-08-23 04:28:46 +00:00
|
|
|
FILE* rptfile;
|
|
|
|
wxPoint module_pos;
|
|
|
|
|
|
|
|
File_Place_Offset = wxPoint( 0, 0 );
|
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
rptfile = wxFopen( aFullFilename, wxT( "wt" ) );
|
2011-02-27 23:25:07 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( rptfile == NULL )
|
2012-02-15 10:41:16 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Select units:
|
|
|
|
double conv_unit = aUnitsMM ? conv_unit_mm : conv_unit_inch;
|
|
|
|
const char *unit_text = aUnitsMM ? unit_text_mm : unit_text_inch;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
LOCALE_IO toggle;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2012-02-11 18:54:36 +00:00
|
|
|
// Generate header file comments.)
|
2016-02-12 11:50:42 +00:00
|
|
|
fprintf( rptfile, "## Footprint report - date %s\n", TO_UTF8( DateAndTime() ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
wxString Title = Pgm().App().GetAppName() + wxT( " " ) + GetBuildVersion();
|
2016-02-12 11:50:42 +00:00
|
|
|
fprintf( rptfile, "## Created by Pcbnew version %s\n", TO_UTF8( Title ) );
|
2012-02-11 18:54:36 +00:00
|
|
|
fputs( unit_text, rptfile );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
fputs( "\n$BeginDESCRIPTION\n", rptfile );
|
|
|
|
|
++PCBNew
* Removed Pcb_Frame argument from BOARD() constructor, since it precludes
having a BOARD being edited by more than one editor, it was a bad design.
And this meant removing m_PcbFrame from BOARD.
* removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame
* Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp
* added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance
* a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed,
such as dialog_mask_clearance, dialog_drc, etc.
* Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it
with build_version.h's #define BOARD_FILE_VERSION, although there may be a
better place for this constant.
* Made the public functions in PARAM_CFG_ARRAY be type const.
void SaveParam(..) const and void ReadParam(..) const
* PARAM_CFG_BASE now has virtual destructor since we have various way of
destroying the derived class and boost::ptr_vector must be told about this.
* Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use
an automatic PARAM_CFG_ARRAY which is on the stack.\
* PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array,
since it has to access the current BOARD and the BOARD can change.
Remember BOARD_DESIGN_SETTINGS are now in the BOARD.
* Made the m_BoundingBox member private, this was a brutally hard task,
and indicative of the lack of commitment to accessors and object oriented
design on the part of KiCad developers. We must do better.
Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox().
* Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
|
|
|
EDA_RECT bbbox = GetBoard()->ComputeBoundingBox();
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
fputs( "\n$BOARD\n", rptfile );
|
++PCBNew
* Removed Pcb_Frame argument from BOARD() constructor, since it precludes
having a BOARD being edited by more than one editor, it was a bad design.
And this meant removing m_PcbFrame from BOARD.
* removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame
* Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp
* added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance
* a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed,
such as dialog_mask_clearance, dialog_drc, etc.
* Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it
with build_version.h's #define BOARD_FILE_VERSION, although there may be a
better place for this constant.
* Made the public functions in PARAM_CFG_ARRAY be type const.
void SaveParam(..) const and void ReadParam(..) const
* PARAM_CFG_BASE now has virtual destructor since we have various way of
destroying the derived class and boost::ptr_vector must be told about this.
* Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use
an automatic PARAM_CFG_ARRAY which is on the stack.\
* PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array,
since it has to access the current BOARD and the BOARD can change.
Remember BOARD_DESIGN_SETTINGS are now in the BOARD.
* Made the m_BoundingBox member private, this was a brutally hard task,
and indicative of the lack of commitment to accessors and object oriented
design on the part of KiCad developers. We must do better.
Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox().
* Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
fprintf( rptfile, "upper_left_corner %9.6f %9.6f\n",
|
++PCBNew
* Removed Pcb_Frame argument from BOARD() constructor, since it precludes
having a BOARD being edited by more than one editor, it was a bad design.
And this meant removing m_PcbFrame from BOARD.
* removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame
* Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp
* added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance
* a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed,
such as dialog_mask_clearance, dialog_drc, etc.
* Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it
with build_version.h's #define BOARD_FILE_VERSION, although there may be a
better place for this constant.
* Made the public functions in PARAM_CFG_ARRAY be type const.
void SaveParam(..) const and void ReadParam(..) const
* PARAM_CFG_BASE now has virtual destructor since we have various way of
destroying the derived class and boost::ptr_vector must be told about this.
* Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use
an automatic PARAM_CFG_ARRAY which is on the stack.\
* PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array,
since it has to access the current BOARD and the BOARD can change.
Remember BOARD_DESIGN_SETTINGS are now in the BOARD.
* Made the m_BoundingBox member private, this was a brutally hard task,
and indicative of the lack of commitment to accessors and object oriented
design on the part of KiCad developers. We must do better.
Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox().
* Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
|
|
|
bbbox.GetX() * conv_unit,
|
|
|
|
bbbox.GetY() * conv_unit );
|
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
fprintf( rptfile, "lower_right_corner %9.6f %9.6f\n",
|
++PCBNew
* Removed Pcb_Frame argument from BOARD() constructor, since it precludes
having a BOARD being edited by more than one editor, it was a bad design.
And this meant removing m_PcbFrame from BOARD.
* removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame
* Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp
* added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance
* a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed,
such as dialog_mask_clearance, dialog_drc, etc.
* Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it
with build_version.h's #define BOARD_FILE_VERSION, although there may be a
better place for this constant.
* Made the public functions in PARAM_CFG_ARRAY be type const.
void SaveParam(..) const and void ReadParam(..) const
* PARAM_CFG_BASE now has virtual destructor since we have various way of
destroying the derived class and boost::ptr_vector must be told about this.
* Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use
an automatic PARAM_CFG_ARRAY which is on the stack.\
* PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array,
since it has to access the current BOARD and the BOARD can change.
Remember BOARD_DESIGN_SETTINGS are now in the BOARD.
* Made the m_BoundingBox member private, this was a brutally hard task,
and indicative of the lack of commitment to accessors and object oriented
design on the part of KiCad developers. We must do better.
Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox().
* Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
|
|
|
bbbox.GetRight() * conv_unit,
|
|
|
|
bbbox.GetBottom() * conv_unit );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
fputs( "$EndBOARD\n\n", rptfile );
|
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
for( MODULE* Module = GetBoard()->m_Modules; Module; Module = Module->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2016-02-12 11:50:42 +00:00
|
|
|
fprintf( rptfile, "$MODULE %s\n", EscapedUTF8( Module->GetReference() ).c_str() );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
fprintf( rptfile, "reference %s\n", EscapedUTF8( Module->GetReference() ).c_str() );
|
|
|
|
fprintf( rptfile, "value %s\n", EscapedUTF8( Module->GetValue() ).c_str() );
|
|
|
|
fprintf( rptfile, "footprint %s\n",
|
|
|
|
EscapedUTF8( FROM_UTF8( Module->GetFPID().Format().c_str() ) ).c_str() );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
msg = wxT( "attribut" );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
if( Module->GetAttributes() & MOD_VIRTUAL )
|
|
|
|
msg += wxT( " virtual" );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
if( Module->GetAttributes() & MOD_CMS )
|
|
|
|
msg += wxT( " smd" );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
if( ( Module->GetAttributes() & (MOD_VIRTUAL | MOD_CMS) ) == 0 )
|
|
|
|
msg += wxT( " none" );
|
2012-02-19 04:02:19 +00:00
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
msg += wxT( "\n" );
|
|
|
|
fputs( TO_UTF8( msg ), rptfile );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
module_pos = Module->GetPosition();
|
|
|
|
module_pos.x -= File_Place_Offset.x;
|
|
|
|
module_pos.y -= File_Place_Offset.y;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
fprintf( rptfile, "position %9.6f %9.6f orientation %.2f\n",
|
|
|
|
module_pos.x * conv_unit,
|
|
|
|
module_pos.y * conv_unit,
|
|
|
|
Module->GetOrientation() / 10.0 );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
if( Module->GetLayer() == F_Cu )
|
|
|
|
fputs( "layer front\n", rptfile );
|
|
|
|
else if( Module->GetLayer() == B_Cu )
|
|
|
|
fputs( "layer back\n", rptfile );
|
|
|
|
else
|
|
|
|
fputs( "layer other\n", rptfile );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2017-04-25 09:06:24 +00:00
|
|
|
for( D_PAD* pad = Module->PadsList(); pad != NULL; pad = pad->Next() )
|
2016-02-12 11:50:42 +00:00
|
|
|
{
|
2017-08-11 09:22:13 +00:00
|
|
|
fprintf( rptfile, "$PAD \"%s\"\n", TO_UTF8( pad->GetName() ) );
|
2016-02-12 11:50:42 +00:00
|
|
|
int layer = 0;
|
2012-02-19 04:02:19 +00:00
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
if( pad->GetLayerSet()[B_Cu] )
|
|
|
|
layer = 1;
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
if( pad->GetLayerSet()[F_Cu] )
|
|
|
|
layer |= 2;
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
static const char* layer_name[4] = { "nocopper", "back", "front", "both" };
|
|
|
|
fprintf( rptfile, "Shape %s Layer %s\n", TO_UTF8( pad->ShowPadShape() ), layer_name[layer] );
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
fprintf( rptfile, "position %9.6f %9.6f size %9.6f %9.6f orientation %.2f\n",
|
|
|
|
pad->GetPos0().x * conv_unit, pad->GetPos0().y * conv_unit,
|
|
|
|
pad->GetSize().x * conv_unit, pad->GetSize().y * conv_unit,
|
|
|
|
(pad->GetOrientation() - Module->GetOrientation()) / 10.0 );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
fprintf( rptfile, "drill %9.6f\n", pad->GetDrillSize().x * conv_unit );
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
fprintf( rptfile, "shape_offset %9.6f %9.6f\n",
|
|
|
|
pad->GetOffset().x * conv_unit,
|
|
|
|
pad->GetOffset().y * conv_unit );
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
fprintf( rptfile, "$EndPAD\n" );
|
2012-04-17 01:35:43 +00:00
|
|
|
}
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2016-02-12 11:50:42 +00:00
|
|
|
fprintf( rptfile, "$EndMODULE %s\n\n", TO_UTF8 (Module->GetReference() ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2012-02-11 18:54:36 +00:00
|
|
|
// Generate EOF.
|
2007-08-23 04:28:46 +00:00
|
|
|
fputs( "$EndDESCRIPTION\n", rptfile );
|
|
|
|
fclose( rptfile );
|
2011-02-27 23:25:07 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|