Added --no-virtual option to suppress inclusion of 3D models from components with the virtual attribute

This commit is contained in:
Cirilo Bernardo 2016-09-18 10:25:10 +10:00 committed by Wayne Stambaugh
parent 375741eeaa
commit a9cb10c947
5 changed files with 67 additions and 15 deletions

View File

@ -47,6 +47,7 @@ private:
bool m_overwrite;
bool m_useGridOrigin;
bool m_useDrillOrigin;
bool m_includeVirtual;
wxString m_filename;
double m_xOrigin;
double m_yOrigin;
@ -54,23 +55,26 @@ private:
static const wxCmdLineEntryDesc cmdLineDesc[] =
{
{ wxCMD_LINE_OPTION, "f", NULL, "input file name",
{ wxCMD_LINE_PARAM, NULL, NULL, _( "pcb_file" ),
wxCMD_LINE_VAL_STRING, wxCMD_LINE_OPTION_MANDATORY },
#ifdef SUPPORTS_IGES
{ wxCMD_LINE_SWITCH, "i", NULL, "IGES output (default STEP)",
wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
#endif
{ wxCMD_LINE_SWITCH, "w", NULL, "overwrite output file",
{ 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_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_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_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)",
{ wxCMD_LINE_OPTION, "y", NULL, _( "Y origin of board (pcbnew coordinate system)" ),
wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_SWITCH, "h", NULL, "display this message",
{ wxCMD_LINE_SWITCH, NULL, "no-virtual",
_( "exclude 3D models for components with 'virtual' attribute" ),
wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_SWITCH, "h", NULL, _( "display this message" ),
wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
{ wxCMD_LINE_NONE }
};
@ -87,6 +91,7 @@ bool KICAD2MCAD::OnInit()
m_overwrite = false;
m_useGridOrigin = false;
m_useDrillOrigin = false;
m_includeVirtual = true;
m_xOrigin = 0.0;
m_yOrigin = 0.0;
@ -121,12 +126,21 @@ bool KICAD2MCAD::OnCmdLineParsed( wxCmdLineParser& parser )
if( parser.Found( "d" ) )
m_useDrillOrigin = true;
if( parser.Found( "no-virtual" ) )
m_includeVirtual = false;
parser.Found( "x", &m_xOrigin );
parser.Found( "y", &m_yOrigin );
wxString fname;
parser.Found( "f", &fname );
m_filename = fname;
if( parser.GetParamCount() < 1 )
{
parser.Usage();
return false;
}
m_filename = parser.GetParam( 0 );
return true;
}
@ -170,7 +184,7 @@ int KICAD2MCAD::OnRun()
try
{
pcb.ComposePCB();
pcb.ComposePCB( m_includeVirtual );
#ifdef SUPPORTS_IGES
if( m_fmtIGES )

View File

@ -39,6 +39,7 @@ KICADMODULE::KICADMODULE()
{
m_side = LAYER_NONE;
m_rotation = 0.0;
m_virtual = false;
return;
}
@ -104,6 +105,8 @@ bool KICADMODULE::Read( SEXPR::SEXPR* aEntry )
result = result && parseLayer( child );
else if( symname == "at" )
result = result && parsePosition( child );
else if( symname == "attr" )
result = result && parseAttribute( child );
else if( symname == "fp_text" )
result = result && parseText( child );
else if( symname == "fp_arc" )
@ -198,6 +201,31 @@ bool KICADMODULE::parsePosition( SEXPR::SEXPR* data )
}
bool KICADMODULE::parseAttribute( SEXPR::SEXPR* data )
{
if( data->GetNumberOfChildren() < 2 )
{
std::ostringstream ostr;
ostr << "* corrupt module in PCB file; attribute cannot be parsed\n";
wxLogMessage( "%s\n", ostr.str().c_str() );
return false;
}
SEXPR::SEXPR* child = data->GetChild( 1 );
std::string text;
if( child->IsSymbol() )
text = child->GetSymbol();
else if( child->IsString() )
text = child->GetString();
if( text == "virtual" )
m_virtual = true;
return true;
}
bool KICADMODULE::parseText( SEXPR::SEXPR* data )
{
// we're only interested in the Reference Designator
@ -250,7 +278,8 @@ bool KICADMODULE::parsePad( SEXPR::SEXPR* data )
}
bool KICADMODULE::ComposePCB( class PCBMODEL* aPCB, S3D_RESOLVER* resolver, DOUBLET aOrigin )
bool KICADMODULE::ComposePCB( class PCBMODEL* aPCB, S3D_RESOLVER* resolver,
DOUBLET aOrigin, bool aComposeVirtual )
{
// translate pads and curves to final position and append to PCB.
double dlim = (double)std::numeric_limits< float >::epsilon();
@ -322,6 +351,12 @@ bool KICADMODULE::ComposePCB( class PCBMODEL* aPCB, S3D_RESOLVER* resolver, DOUB
}
if( m_virtual )
std::cerr << "This is a virtual component, aComposeVirtual == " << (aComposeVirtual ? "true" : "false" ) << "\n";
if( m_virtual && !aComposeVirtual )
return hasdata;
DOUBLET newpos( posX, posY );
for( auto i : m_models )

View File

@ -51,6 +51,7 @@ private:
bool parseCurve( SEXPR::SEXPR* data, CURVE_TYPE aCurveType );
bool parseLayer( SEXPR::SEXPR* data );
bool parsePosition( SEXPR::SEXPR* data );
bool parseAttribute( SEXPR::SEXPR* data );
bool parseText( SEXPR::SEXPR* data );
bool parsePad( SEXPR::SEXPR* data );
@ -58,6 +59,7 @@ private:
std::string m_refdes;
DOUBLET m_position;
double m_rotation; // rotation (radians)
bool m_virtual; // true for a vitual (usually mechanical) component
std::vector< KICADPAD* > m_pads;
std::vector< KICADCURVE* > m_curves;
@ -69,7 +71,8 @@ public:
bool Read( SEXPR::SEXPR* aEntry );
bool ComposePCB( class PCBMODEL* aPCB, S3D_RESOLVER* resolver, DOUBLET aOrigin );
bool ComposePCB( class PCBMODEL* aPCB, S3D_RESOLVER* resolver,
DOUBLET aOrigin, bool aComposeVirtual = true );
};
#endif // KICADMODULE_H

View File

@ -398,7 +398,7 @@ bool KICADPCB::parseCurve( SEXPR::SEXPR* data, CURVE_TYPE aCurveType )
}
bool KICADPCB::ComposePCB()
bool KICADPCB::ComposePCB( bool aComposeVirtual )
{
if( m_pcb )
return true;
@ -451,7 +451,7 @@ bool KICADPCB::ComposePCB()
}
for( auto i : m_modules )
i->ComposePCB( m_pcb, &m_resolver, origin );
i->ComposePCB( m_pcb, &m_resolver, origin, aComposeVirtual );
if( !m_pcb->CreatePCB() )
{

View File

@ -95,7 +95,7 @@ public:
}
bool ReadFile( const wxString& aFileName );
bool ComposePCB();
bool ComposePCB( bool aComposeVirtual = true );
bool WriteSTEP( const wxString& aFileName, bool aOverwrite );
#ifdef SUPPORTS_IGES
bool WriteIGES( const wxString& aFileName, bool aOverwrite );