Added options to use Drill or Grid origin for outptu STEP file
This commit is contained in:
parent
231b08e58f
commit
11a44388ee
|
@ -45,6 +45,8 @@ private:
|
|||
bool m_fmtIGES;
|
||||
#endif
|
||||
bool m_overwrite;
|
||||
bool m_useGridOrigin;
|
||||
bool m_useDrillOrigin;
|
||||
wxString m_filename;
|
||||
double m_xOrigin;
|
||||
double m_yOrigin;
|
||||
|
@ -60,6 +62,10 @@ static const wxCmdLineEntryDesc cmdLineDesc[] =
|
|||
#endif
|
||||
{ wxCMD_LINE_SWITCH, "w", NULL, "overwrite output file",
|
||||
wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
|
||||
{ wxCMD_LINE_SWITCH, "d", NULL, "Use Drill Origin for output origin",
|
||||
wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
|
||||
{ wxCMD_LINE_SWITCH, "o", NULL, "Use Grid Origin for output origin",
|
||||
wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
|
||||
{ wxCMD_LINE_OPTION, "x", NULL, "X origin of board",
|
||||
wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL },
|
||||
{ wxCMD_LINE_OPTION, "y", NULL, "Y origin of board (pcbnew coordinate system)",
|
||||
|
@ -79,6 +85,8 @@ bool KICAD2MCAD::OnInit()
|
|||
m_fmtIGES = false;
|
||||
#endif
|
||||
m_overwrite = false;
|
||||
m_useGridOrigin = false;
|
||||
m_useDrillOrigin = false;
|
||||
m_xOrigin = 0.0;
|
||||
m_yOrigin = 0.0;
|
||||
|
||||
|
@ -107,6 +115,12 @@ bool KICAD2MCAD::OnCmdLineParsed( wxCmdLineParser& parser )
|
|||
if( parser.Found( "w" ) )
|
||||
m_overwrite = true;
|
||||
|
||||
if( parser.Found( "o" ) )
|
||||
m_useGridOrigin = true;
|
||||
|
||||
if( parser.Found( "d" ) )
|
||||
m_useDrillOrigin = true;
|
||||
|
||||
parser.Found( "x", &m_xOrigin );
|
||||
parser.Found( "y", &m_yOrigin );
|
||||
|
||||
|
@ -146,6 +160,12 @@ int KICAD2MCAD::OnRun()
|
|||
|
||||
if( pcb.ReadFile( m_filename ) )
|
||||
{
|
||||
if( m_useDrillOrigin )
|
||||
pcb.UseDrillOrigin( true );
|
||||
|
||||
if( m_useGridOrigin )
|
||||
pcb.UseGridOrigin( true );
|
||||
|
||||
bool res;
|
||||
|
||||
try
|
||||
|
|
|
@ -86,6 +86,10 @@ KICADPCB::KICADPCB()
|
|||
m_resolver.Set3DConfigDir( cfgdir.GetPath() );
|
||||
m_thickness = 1.6;
|
||||
m_pcb = NULL;
|
||||
m_useGridOrigin = false;
|
||||
m_useDrillOrigin = false;
|
||||
m_hasGridOrigin = false;
|
||||
m_hasDrillOrigin = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -239,6 +243,8 @@ bool KICADPCB::parsePCB( SEXPR::SEXPR* data )
|
|||
|
||||
if( symname == "general" )
|
||||
result = result && parseGeneral( child );
|
||||
else if( symname == "setup" )
|
||||
result = result && parseSetup( child );
|
||||
else if( symname == "module" )
|
||||
result = result && parseModule( child );
|
||||
else if( symname == "gr_arc" )
|
||||
|
@ -295,6 +301,66 @@ bool KICADPCB::parseGeneral( SEXPR::SEXPR* data )
|
|||
}
|
||||
|
||||
|
||||
bool KICADPCB::parseSetup( SEXPR::SEXPR* data )
|
||||
{
|
||||
size_t nc = data->GetNumberOfChildren();
|
||||
SEXPR::SEXPR* child = NULL;
|
||||
|
||||
for( size_t i = 1; i < nc; ++i )
|
||||
{
|
||||
child = data->GetChild( i );
|
||||
|
||||
if( !child->IsList() )
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
ostr << "* corrupt PCB file: '" << m_filename << "'\n";
|
||||
wxLogMessage( "%s\n", ostr.str().c_str() );
|
||||
return false;
|
||||
}
|
||||
|
||||
// at the moment only the Grid and Drill origins are of interest in
|
||||
// the setup section
|
||||
if( child->GetChild( 0 )->GetSymbol() == "grid_origin" )
|
||||
{
|
||||
if( child->GetNumberOfChildren() != 3 )
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
ostr << "* corrupt PCB file: '" << m_filename << "'\n";
|
||||
ostr << "* grid_origin has " << child->GetNumberOfChildren();
|
||||
ostr << " children (expected: 3)\n";
|
||||
wxLogMessage( "%s\n", ostr.str().c_str() );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
m_gridOrigin.x = child->GetChild( 1 )->GetDouble();
|
||||
m_gridOrigin.y = child->GetChild( 2 )->GetDouble();
|
||||
m_hasGridOrigin = true;
|
||||
}
|
||||
else if( child->GetChild( 0 )->GetSymbol() == "aux_axis_origin" )
|
||||
{
|
||||
if( child->GetNumberOfChildren() != 3 )
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
ostr << "* corrupt PCB file: '" << m_filename << "'\n";
|
||||
ostr << "* aux_axis_origin has " << child->GetNumberOfChildren();
|
||||
ostr << " children (expected: 3)\n";
|
||||
wxLogMessage( "%s\n", ostr.str().c_str() );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
m_drillOrigin.x = child->GetChild( 1 )->GetDouble();
|
||||
m_drillOrigin.y = child->GetChild( 2 )->GetDouble();
|
||||
m_hasDrillOrigin = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool KICADPCB::parseModule( SEXPR::SEXPR* data )
|
||||
{
|
||||
KICADMODULE* mp = new KICADMODULE();
|
||||
|
@ -346,6 +412,23 @@ bool KICADPCB::ComposePCB()
|
|||
return false;
|
||||
}
|
||||
|
||||
DOUBLET origin;
|
||||
|
||||
// Determine the coordinate system reference:
|
||||
// Precedence of reference point is Drill Origin > Grid Origin > User Offset
|
||||
if( m_useDrillOrigin && m_hasDrillOrigin )
|
||||
{
|
||||
origin = m_drillOrigin;
|
||||
}
|
||||
else if( m_useGridOrigin && m_hasDrillOrigin )
|
||||
{
|
||||
origin = m_gridOrigin;
|
||||
}
|
||||
else
|
||||
{
|
||||
origin = m_origin;
|
||||
}
|
||||
|
||||
m_pcb = new PCBMODEL();
|
||||
m_pcb->SetPCBThickness( m_thickness );
|
||||
|
||||
|
@ -356,10 +439,10 @@ bool KICADPCB::ComposePCB()
|
|||
|
||||
// adjust the coordinate system
|
||||
KICADCURVE lcurve = *i;
|
||||
lcurve.m_start.y = -( lcurve.m_start.y - m_origin.y );
|
||||
lcurve.m_end.y = -( lcurve.m_end.y - m_origin.y );
|
||||
lcurve.m_start.x -= m_origin.x;
|
||||
lcurve.m_end.x -= m_origin.x;
|
||||
lcurve.m_start.y = -( lcurve.m_start.y - origin.y );
|
||||
lcurve.m_end.y = -( lcurve.m_end.y - origin.y );
|
||||
lcurve.m_start.x -= origin.x;
|
||||
lcurve.m_end.x -= origin.x;
|
||||
|
||||
if( CURVE_ARC == lcurve.m_form )
|
||||
lcurve.m_angle = -lcurve.m_angle;
|
||||
|
@ -368,7 +451,7 @@ bool KICADPCB::ComposePCB()
|
|||
}
|
||||
|
||||
for( auto i : m_modules )
|
||||
i->ComposePCB( m_pcb, &m_resolver, m_origin );
|
||||
i->ComposePCB( m_pcb, &m_resolver, origin );
|
||||
|
||||
if( !m_pcb->CreatePCB() )
|
||||
{
|
||||
|
|
|
@ -55,6 +55,13 @@ private:
|
|||
std::string m_filename;
|
||||
PCBMODEL* m_pcb;
|
||||
DOUBLET m_origin;
|
||||
DOUBLET m_gridOrigin;
|
||||
DOUBLET m_drillOrigin;
|
||||
bool m_useGridOrigin;
|
||||
bool m_useDrillOrigin;
|
||||
// set to TRUE if the origin was actually parsed
|
||||
bool m_hasGridOrigin;
|
||||
bool m_hasDrillOrigin;
|
||||
|
||||
// PCB parameters/entities
|
||||
double m_thickness;
|
||||
|
@ -63,6 +70,7 @@ private:
|
|||
|
||||
bool parsePCB( SEXPR::SEXPR* data );
|
||||
bool parseGeneral( SEXPR::SEXPR* data );
|
||||
bool parseSetup( SEXPR::SEXPR* data );
|
||||
bool parseModule( SEXPR::SEXPR* data );
|
||||
bool parseCurve( SEXPR::SEXPR* data, CURVE_TYPE aCurveType );
|
||||
|
||||
|
@ -76,6 +84,16 @@ public:
|
|||
m_origin.y = aYOrigin;
|
||||
}
|
||||
|
||||
void UseGridOrigin( bool aUseOrigin )
|
||||
{
|
||||
m_useGridOrigin = aUseOrigin;
|
||||
}
|
||||
|
||||
void UseDrillOrigin( bool aUseOrigin )
|
||||
{
|
||||
m_useDrillOrigin = aUseOrigin;
|
||||
}
|
||||
|
||||
bool ReadFile( const wxString& aFileName );
|
||||
bool ComposePCB();
|
||||
bool WriteSTEP( const wxString& aFileName, bool aOverwrite );
|
||||
|
|
Loading…
Reference in New Issue