Commit 5944f4c4 authored by jean-pierre charras's avatar jean-pierre charras

Pcbnew: gen drill functions: morecode cleanup

parent 259d9a02
/////////////////////////////////////////////////////////////////////////////
// Name: dialog_gendrill.cpp // Name: dialog_gendrill.cpp
// Author: jean-pierre Charras // Author: jean-pierre Charras
// Licence: GPL // Licence: GPL
...@@ -50,7 +48,7 @@ DIALOG_GENDRILL::DIALOG_GENDRILL( WinEDA_PcbFrame* parent ) : ...@@ -50,7 +48,7 @@ DIALOG_GENDRILL::DIALOG_GENDRILL( WinEDA_PcbFrame* parent ) :
// Static members of DIALOG_GENDRILL // Static members of DIALOG_GENDRILL
int DIALOG_GENDRILL:: m_UnitDrillIsInch = true; int DIALOG_GENDRILL:: m_UnitDrillIsInch = true;
int DIALOG_GENDRILL:: m_ZerosFormat = DECIMAL_FORMAT; int DIALOG_GENDRILL:: m_ZerosFormat = EXCELLON_WRITER::DECIMAL_FORMAT;
bool DIALOG_GENDRILL::m_MinimalHeader = false; bool DIALOG_GENDRILL::m_MinimalHeader = false;
bool DIALOG_GENDRILL::m_Mirror = true; bool DIALOG_GENDRILL::m_Mirror = true;
bool DIALOG_GENDRILL::m_DrillOriginIsAuxAxis = false; bool DIALOG_GENDRILL::m_DrillOriginIsAuxAxis = false;
...@@ -96,7 +94,7 @@ void DIALOG_GENDRILL::InitDisplayParams( void ) ...@@ -96,7 +94,7 @@ void DIALOG_GENDRILL::InitDisplayParams( void )
m_Choice_Unit->SetSelection( m_UnitDrillIsInch ? 1 : 0 ); m_Choice_Unit->SetSelection( m_UnitDrillIsInch ? 1 : 0 );
m_Choice_Precision->SetSelection( m_PrecisionFormat ); m_Choice_Precision->SetSelection( m_PrecisionFormat );
m_Choice_Zeros_Format->SetSelection( m_ZerosFormat ); m_Choice_Zeros_Format->SetSelection( m_ZerosFormat );
if( m_ZerosFormat == DECIMAL_FORMAT ) if( m_ZerosFormat == EXCELLON_WRITER::DECIMAL_FORMAT )
m_Choice_Precision->Enable( false ); m_Choice_Precision->Enable( false );
UpdatePrecisionOptions( ); UpdatePrecisionOptions( );
...@@ -209,7 +207,8 @@ void DIALOG_GENDRILL::OnSelDrillUnitsSelected( wxCommandEvent& event ) ...@@ -209,7 +207,8 @@ void DIALOG_GENDRILL::OnSelDrillUnitsSelected( wxCommandEvent& event )
void DIALOG_GENDRILL::OnOkClick( wxCommandEvent& event ) void DIALOG_GENDRILL::OnOkClick( wxCommandEvent& event )
{ {
GenDrillOrReportFiles( ); GenDrillAndReportFiles( );
EndModal( wxID_OK);
} }
...@@ -220,7 +219,7 @@ void DIALOG_GENDRILL::OnOkClick( wxCommandEvent& event ) ...@@ -220,7 +219,7 @@ void DIALOG_GENDRILL::OnOkClick( wxCommandEvent& event )
void DIALOG_GENDRILL::OnCancelClick( wxCommandEvent& event ) void DIALOG_GENDRILL::OnCancelClick( wxCommandEvent& event )
{ {
UpdateConfig(); /* Save drill options: */ UpdateConfig(); /* Save drill options: */
event.Skip(); // Process the default cancel event (close dialog) EndModal( wxID_CANCEL); // Process the default cancel event (close dialog)
} }
...@@ -248,7 +247,7 @@ void DIALOG_GENDRILL::UpdatePrecisionOptions( ) ...@@ -248,7 +247,7 @@ void DIALOG_GENDRILL::UpdatePrecisionOptions( )
m_Choice_Precision->SetString( 0, precisionListForMetric[0].GetPrecisionString() ); m_Choice_Precision->SetString( 0, precisionListForMetric[0].GetPrecisionString() );
m_Choice_Precision->SetString( 1, precisionListForMetric[1].GetPrecisionString() ); m_Choice_Precision->SetString( 1, precisionListForMetric[1].GetPrecisionString() );
} }
if( m_Choice_Zeros_Format->GetSelection()==DECIMAL_FORMAT ) if( m_Choice_Zeros_Format->GetSelection() == EXCELLON_WRITER::DECIMAL_FORMAT )
m_Choice_Precision->Enable( false ); m_Choice_Precision->Enable( false );
else else
m_Choice_Precision->Enable( true ); m_Choice_Precision->Enable( true );
......
///////////////////////////////////////////////////////////////////////////// /**
*@file dialog_gendrill.h
*/
// Name: dialog_gendrill.h /*
// Author: jean-pierre Charras * This program source code file is part of KICAD, a free EDA CAD application.
// Created: 2010 apr 30 *
// Licence: GPL * Copyright (C) 1992-2010 Jean_Pierre Charras <jp.charras@iut.ujf-grenoble.fr>
///////////////////////////////////////////////////////////////////////////// * Copyright (C) 1992-2010 Kicad Developers, see change_log.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
* 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
*/
#ifndef _DIALOG_GENDRILL_H_ #ifndef _DIALOG_GENDRILL_H_
#define _DIALOG_GENDRILL_H_ #define _DIALOG_GENDRILL_H_
...@@ -14,15 +34,15 @@ ...@@ -14,15 +34,15 @@
class DIALOG_GENDRILL : public DIALOG_GENDRILL_BASE class DIALOG_GENDRILL : public DIALOG_GENDRILL_BASE
{ {
public: public:
static int m_UnitDrillIsInch; static int m_UnitDrillIsInch;
static int m_ZerosFormat; static int m_ZerosFormat;
static int m_PrecisionFormat; static int m_PrecisionFormat;
static bool m_MinimalHeader; static bool m_MinimalHeader;
static bool m_Mirror; static bool m_Mirror;
static bool m_DrillOriginIsAuxAxis; /* Axis selection (main / auxiliary) static bool m_DrillOriginIsAuxAxis; /* Axis selection (main / auxiliary)
* for drill origin coordinates */ * for drill origin coordinates */
DRILL_PRECISION m_Precision; // Selected precision for drill files DRILL_PRECISION m_Precision; // Selected precision for drill files
wxPoint m_FileDrillOffset; // Drill offset: 0,0 for absolute coordiantes, or auxialry axis origin wxPoint m_FileDrillOffset; // Drill offset: 0,0 for absolute coordiantes, or auxialry axis origin
private: private:
WinEDA_PcbFrame* m_Parent; WinEDA_PcbFrame* m_Parent;
...@@ -35,30 +55,33 @@ public: DIALOG_GENDRILL( WinEDA_PcbFrame* parent ); ...@@ -35,30 +55,33 @@ public: DIALOG_GENDRILL( WinEDA_PcbFrame* parent );
~DIALOG_GENDRILL(); ~DIALOG_GENDRILL();
private: private:
// Initialises member variables // Initialises member variables
void initDialog(); void initDialog();
void InitDisplayParams( void ); void InitDisplayParams( void );
// event functions // event functions
void OnSelDrillUnitsSelected( wxCommandEvent& event ); void OnSelDrillUnitsSelected( wxCommandEvent& event );
void OnSelZerosFmtSelected( wxCommandEvent& event ); void OnSelZerosFmtSelected( wxCommandEvent& event );
void OnOkClick( wxCommandEvent& event ); void OnOkClick( wxCommandEvent& event );
void OnCancelClick( wxCommandEvent& event ); void OnCancelClick( wxCommandEvent& event );
// Specific functions: // Specific functions:
void SetParams( void ); void SetParams( void );
void GenDrillOrReportFiles(); void GenDrillAndReportFiles();
void GenDrillMap( const wxString aFileName, void GenDrillMap( const wxString aFileName,
std::vector<HOLE_INFO>& aHoleListBuffer, std::vector<HOLE_INFO>& aHoleListBuffer,
std::vector<DRILL_TOOL>& aToolListBuffer, std::vector<DRILL_TOOL>& aToolListBuffer,
int format ); int format );
void UpdatePrecisionOptions( ); void UpdatePrecisionOptions();
void UpdateConfig(); void UpdateConfig();
void Write_Excellon_Header( FILE* aFile, bool aMinimalHeader, zeros_fmt aFormat ); void GenDrillReport( const wxString aFileName );
void GenDrillReport( const wxString aFileName ); int Create_Drill_File_EXCELLON( FILE* aFile,
int Create_Drill_File_EXCELLON( FILE* aFile, wxPoint aOffset,
wxPoint aOffset, std::vector<HOLE_INFO>& aHoleListBuffer,
std::vector<HOLE_INFO>& aHoleListBuffer, std::vector<DRILL_TOOL>& aToolListBuffer );
std::vector<DRILL_TOOL>& aToolListBuffer ); int Gen_Liste_Tools( std::vector<DRILL_TOOL>& buffer, bool print_header );
int Gen_Liste_Tools( std::vector<DRILL_TOOL>& buffer, bool print_header );
/** /**
* Return the selected format for coordinates, if not decimal * Return the selected format for coordinates, if not decimal
*/ */
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
#include "fctsys.h" #include "fctsys.h"
using namespace std;
#include <algorithm> // sort #include <algorithm> // sort
#include <vector> #include <vector>
...@@ -42,7 +40,6 @@ static bool CmpHoleDiameterValue( const HOLE_INFO& a, const HOLE_INFO& b ) ...@@ -42,7 +40,6 @@ static bool CmpHoleDiameterValue( const HOLE_INFO& a, const HOLE_INFO& b )
* @param aToolListBuffer : the std::vector<DRILL_TOOL> to fill with tools to use * @param aToolListBuffer : the std::vector<DRILL_TOOL> to fill with tools to use
* @param aFirstLayer = first layer to consider. if < 0 aFirstLayer is ignored (used to creates report file) * @param aFirstLayer = first layer to consider. if < 0 aFirstLayer is ignored (used to creates report file)
* @param aLastLayer = last layer to consider. if < 0 aLastLayer is ignored * @param aLastLayer = last layer to consider. if < 0 aLastLayer is ignored
* @param aLastLayer = last layer to consider. if < 0 aLastLayer is ignored
* @param aExcludeThroughHoles : if true, exclude through holes ( pads and vias through ) * @param aExcludeThroughHoles : if true, exclude through holes ( pads and vias through )
*/ */
void Build_Holes_List( BOARD* aPcb, void Build_Holes_List( BOARD* aPcb,
......
This diff is collapsed.
...@@ -9,11 +9,10 @@ ...@@ -9,11 +9,10 @@
class DRILL_TOOL class DRILL_TOOL
{ {
public: public:
int m_Diameter; // the diameter of the used tool (for oblong, the smaller size) int m_Diameter; // the diameter of the used tool (for oblong, the smaller size)
int m_TotalCount; // how many times it is used (round and oblong) int m_TotalCount; // how many times it is used (round and oblong)
int m_OvalCount; // oblong count int m_OvalCount; // oblong count
public: public: DRILL_TOOL( int diametre )
DRILL_TOOL( int diametre )
{ {
m_TotalCount = 0; m_TotalCount = 0;
m_OvalCount = 0; m_OvalCount = 0;
...@@ -32,7 +31,7 @@ public: ...@@ -32,7 +31,7 @@ public:
int m_Hole_SizeY; // hole size y for oblong holes int m_Hole_SizeY; // hole size y for oblong holes
int m_Hole_Orient; // Hole rotation (= pad rotation) for oblong holes int m_Hole_Orient; // Hole rotation (= pad rotation) for oblong holes
int m_Hole_Shape; // hole shape: round (0) or oval (1) int m_Hole_Shape; // hole shape: round (0) or oval (1)
int m_Hole_Pos_X; // hole position X int m_Hole_Pos_X; // hole position X
int m_Hole_Pos_Y; // hole position Y int m_Hole_Pos_Y; // hole position Y
int m_Hole_Bottom_Layer; // hole starting layer (usually copper) int m_Hole_Bottom_Layer; // hole starting layer (usually copper)
int m_Hole_Top_Layer; // hole ending layer (usually component): m_Hole_First_Layer < m_Hole_Last_Layer int m_Hole_Top_Layer; // hole ending layer (usually component): m_Hole_First_Layer < m_Hole_Last_Layer
...@@ -40,39 +39,123 @@ public: ...@@ -40,39 +39,123 @@ public:
/* the DRILL_PRECISION helper class to handle drill precision format in excellon files /* the DRILL_PRECISION helper class to handle drill precision format in excellon files
*/ */
class DRILL_PRECISION class DRILL_PRECISION
{ {
public: public:
int m_lhs; // Left digit number (integer value of coordinates) int m_lhs; // Left digit number (integer value of coordinates)
int m_rhs; // Right digit number (deciam value of coordinates) int m_rhs; // Right digit number (deciam value of coordinates)
public: public: DRILL_PRECISION( int l = 2, int r = 4 )
DRILL_PRECISION( int l = 2, int r = 4)
{ {
m_lhs = l; m_rhs = r; m_lhs = l; m_rhs = r;
} }
wxString GetPrecisionString() wxString GetPrecisionString()
{ {
wxString text; wxString text;
text << m_lhs << wxT(":") << m_rhs;
text << m_lhs << wxT( ":" ) << m_rhs;
return text; return text;
} }
}; };
/* zeros format */
enum zeros_fmt { // A helper class to create Excellon drill files
DECIMAL_FORMAT, class EXCELLON_WRITER
SUPPRESS_LEADING, {
SUPPRESS_TRAILING, public:
KEEP_ZEROS enum zeros_fmt {
}; // Zero format in coordinates
DECIMAL_FORMAT,
SUPPRESS_LEADING,
SUPPRESS_TRAILING,
KEEP_ZEROS
};
wxPoint m_Offset; // offset coordinates
bool m_ShortHeader; // true to generate the smallest header (strip comments)
private:
FILE* m_file; // The output file
BOARD* m_pcb;
bool m_minimalHeader; // True to use minimal haeder
// in excellon file (strip comments)
bool m_unitsDecimal; // true = decimal, false = inches
zeros_fmt m_zeroFormat; // the zero format option for output file
DRILL_PRECISION m_precision; // The current coordinate precision (not used in decimat format)
double m_conversionUnits; // scaling factor to convert the board unites to Excellon units
// (i.e inches or mm)
bool m_mirror;
wxPoint m_offset; // Drill offset ooordinates
std::vector<HOLE_INFO>* m_holeListBuffer; // Buffer containing holes
std::vector<DRILL_TOOL>* m_toolListBuffer; // Buffer containing tools
public: EXCELLON_WRITER( BOARD* aPcb, FILE* aFile,
wxPoint aOffset,
std::vector<HOLE_INFO>* aHoleListBuffer,
std::vector<DRILL_TOOL>* aToolListBuffer )
{
m_file = aFile;
m_pcb = aPcb;
m_zeroFormat = DECIMAL_FORMAT;
m_holeListBuffer = aHoleListBuffer;
m_toolListBuffer = aToolListBuffer;
m_conversionUnits = 0.0001;
m_unitsDecimal = false;
m_mirror = false;
m_minimalHeader = false;
}
~EXCELLON_WRITER()
{
}
/**
* SetFormat
* Initialize internal parameters to match the given format
* @param aMetric = true for metric coordinates, false for imperial units
* @param aZerosFmt = DECIMAL_FORMAT, SUPPRESS_LEADING, SUPPRESS_TRAILING, KEEP_ZEROS
* @param aLeftDigits = number of digits for integer part of coordinates
* @param aRightDigits = number of digits for mantissa part of coordinates
*/
void SetFormat( bool aMetric, zeros_fmt aZerosFmt, int aLeftDigits, int aRightDigits );
/**
* SetOptions
* Initialize internal parameters to match drill options
* @param aMetric = true for metric coordinates, false for imperial units
* @param aZerosFmt = DECIMAL_FORMAT, SUPPRESS_LEADING, SUPPRESS_TRAILING, KEEP_ZEROS
* @param aLeftDigits = number of digits for integer part of coordinates
* @param aRightDigits = number of digits for mantissa part of coordinates
*/
void SetOptions( bool aMirror, bool aMinimalHeader, wxPoint aOffset )
{
m_mirror = aMirror;
m_offset = aOffset;
m_minimalHeader = aMinimalHeader;
}
/**
* CreateDrillFile
* Creates an Excellon drill file
* @return hole count
*/
int CreateDrillFile();
private:
void WriteHeader();
void WriteEndOfFile();
void WriteCoordinates( char* aLine, double aCoordX, double aCoordY );
};
/** /**
* Function BuildHolesList * Function BuildHolesList
* Create the list of holes and tools for a given board * Create the list of holes and tools for a given board
* The list is sorted by incraesin drill values * The list is sorted by increasing drill values
* Only holes from aFirstLayer to aLastLayer copper layers are listed (for vias, because pad holes are always through holes) * Only holes from aFirstLayer to aLastLayer copper layers are listed (for vias, because pad holes are always through holes)
* @param Pcb : the given board * @param Pcb : the given board
* @param aHoleListBuffer : the std::vector<HOLE_INFO> to fill with pcb holes info * @param aHoleListBuffer : the std::vector<HOLE_INFO> to fill with pcb holes info
...@@ -81,32 +164,32 @@ enum zeros_fmt { ...@@ -81,32 +164,32 @@ enum zeros_fmt {
* @param aLastLayer = last layer to consider. if < 0 aLastLayer is ignored * @param aLastLayer = last layer to consider. if < 0 aLastLayer is ignored
* @param aExcludeThroughHoles : if true, exclude through holes ( pads and vias through ) * @param aExcludeThroughHoles : if true, exclude through holes ( pads and vias through )
*/ */
void Build_Holes_List( BOARD* Pcb, std::vector<HOLE_INFO>& aHoleListBuffer, void Build_Holes_List( BOARD* Pcb, std::vector<HOLE_INFO>& aHoleListBuffer,
std::vector<DRILL_TOOL>& aToolListBuffer, std::vector<DRILL_TOOL>& aToolListBuffer,
int aFirstLayer, int aLastLayer, bool aExcludeThroughHoles ); int aFirstLayer, int aLastLayer, bool aExcludeThroughHoles );
void GenDrillMapFile( BOARD* aPcb, void GenDrillMapFile( BOARD* aPcb,
FILE* aFile, FILE* aFile,
const wxString& aFullFileName, const wxString& aFullFileName,
Ki_PageDescr *aSheet, Ki_PageDescr* aSheet,
std::vector<HOLE_INFO> aHoleListBuffer, std::vector<HOLE_INFO> aHoleListBuffer,
std::vector<DRILL_TOOL> aToolListBuffer, std::vector<DRILL_TOOL> aToolListBuffer,
bool aUnit_Drill_is_Inch, bool aUnit_Drill_is_Inch,
int format, const wxPoint& auxoffset ); int format, const wxPoint& auxoffset );
void Gen_Drill_PcbMap( BOARD* aPcb, PLOTTER* plotter, void Gen_Drill_PcbMap( BOARD* aPcb, PLOTTER* plotter,
std::vector<HOLE_INFO>& aHoleListBuffer, std::vector<HOLE_INFO>& aHoleListBuffer,
std::vector<DRILL_TOOL>& aToolListBuffer); std::vector<DRILL_TOOL>& aToolListBuffer );
/* /*
* Create a list of drill values and drill count * Create a list of drill values and drill count
* there is only one report for all drill files even when buried or blinds vias exist * there is only one report for all drill files even when buried or blinds vias exist
*/ */
void GenDrillReportFile( FILE* aFile, BOARD * aPcb, const wxString& aBoardFilename, void GenDrillReportFile( FILE* aFile, BOARD* aPcb, const wxString& aBoardFilename,
bool aUnit_Drill_is_Inch, bool aUnit_Drill_is_Inch,
std::vector<HOLE_INFO> & aHoleListBuffer, std::vector<HOLE_INFO>& aHoleListBuffer,
std::vector<DRILL_TOOL>& aToolListBuffer std::vector<DRILL_TOOL>& aToolListBuffer
); );
#endif // #ifndef _GENDRILL_H_ #endif // #ifndef _GENDRILL_H_
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