void SIM_PLOT_FRAME::StartSimulation()
{
    STRING_FORMATTER formatter;
    SIM_PLOT_PANEL* plotPanel = CurrentPlot();

    if( !m_settingsDlg )
        m_settingsDlg = new DIALOG_SIM_SETTINGS( this );

    m_simConsole->Clear();
    updateNetlistExporter();

    if( plotPanel )
        m_exporter->SetSimCommand( m_plots[plotPanel].m_simCommand );

    if( !m_exporter->Format( &formatter, m_settingsDlg->GetNetlistOptions() ) )
    {
        DisplayError( this, _( "There were errors during netlist export, aborted." ) );
        return;
    }

    if( m_exporter->GetSimType() == ST_UNKNOWN )
    {
        DisplayInfoMessage( this, _( "You need to select the simulation settings first." ) );
        return;
    }

    m_simulator->LoadNetlist( formatter.GetString() );
    updateTuners();
    applyTuners();
    m_simulator->Run();
}
Beispiel #2
0
void LIB_EDIT_FRAME::OnCopyCutPart( wxCommandEvent& aEvent )
{
    int dummyUnit;
    LIB_ID libId = m_treePane->GetLibTree()->GetSelectedLibId( &dummyUnit );
    LIB_PART* part = m_libMgr->GetBufferedPart( libId.GetLibItemName(), libId.GetLibNickname() );

    if( !part )
        return;

    STRING_FORMATTER formatter;
    SCH_LEGACY_PLUGIN::FormatPart( part, formatter );

    auto clipboard = wxTheClipboard;
    wxClipboardLocker clipboardLock( clipboard );

    if( !clipboardLock || !clipboard->IsOpened() )
        return;

    auto data = new wxTextDataObject( wxString( formatter.GetString().c_str(), wxConvUTF8 ) );
    clipboard->SetData( data );

    clipboard->Flush();

    if( aEvent.GetId() == ID_LIBEDIT_CUT_PART )
        OnRemovePart( aEvent );
}
void SCH_EDIT_FRAME::sendNetlist()
{
    NETLIST_OBJECT_LIST* net_atoms = BuildNetListBase();

    NETLIST_EXPORTER_KICAD exporter( net_atoms, Prj().SchLibs() );

    STRING_FORMATTER    formatter;

    // @todo : trim GNL_ALL down to minimum for CVPCB
    exporter.Format( &formatter, GNL_ALL );

    Kiway().ExpressMail( FRAME_CVPCB,
        MAIL_EESCHEMA_NETLIST,
        formatter.GetString(),  // an abbreviated "kicad" (s-expr) netlist
        this
        );
}
int main( int argc, char** argv )
{
    if( argc != 2 )
    {
        usage();
    }

    FILE*   fp = fopen( argv[1], "r" );
    if( !fp )
    {
        fprintf( stderr, "Unable to open '%s'\n", argv[1] );
        usage();
    }

    static const KEYWORD empty_keywords[1] = {};

    DSNLEXER   lexer( empty_keywords, 0, fp, FROM_UTF8( argv[1] ) );

    try
    {
        PTREE   doc;

#if 0
        using namespace boost::property_tree;

        read_xml( argv[1], doc, xml_parser::trim_whitespace | xml_parser::no_comments );
#else
        Scan( &doc, &lexer );
#endif

#if 1
        STRING_FORMATTER sf;
        Format( &sf, 0, 0, doc );
        printf( "%s", sf.GetString().c_str() );
#else
        // writing the unchanged ptree in file2.xml
        boost::property_tree::xml_writer_settings<char> settings( ' ', 2 );
        write_xml( "/tmp/output.xml", doc, std::locale(), settings );
#endif

    }
    catch( const IO_ERROR& ioe )
    {
        fprintf( stderr, "%s\n", TO_UTF8( ioe.errorText ) );
    }
}
DIALOG_BOM::~DIALOG_BOM()
{
    // Save the plugin descriptions in config.
    // the config stores only one string.
    // plugins are saved inside a S expr:
    // ( plugins
    //    ( plugin "plugin name" (cmd "command line") )
    //     ....
    // )

    STRING_FORMATTER writer;
    writer.Print( 0, "(plugins" );

    for( unsigned ii = 0; ii < m_plugins.GetCount(); ii += 2 )
    {
        writer.Print( 1, "(plugin %s (cmd %s))",
                      writer.Quotew( m_plugins[ii] ).c_str(),
                      writer.Quotew( m_plugins[ii+1] ).c_str() );
    }

    writer.Print( 0, ")" );

    wxString list( FROM_UTF8( writer.GetString().c_str() ) );

    m_config->Write( BOM_PLUGINS_KEY, list );

    wxString active_plugin_name = m_lbPlugins->GetStringSelection( );
    m_config->Write( BOM_PLUGIN_SELECTED_KEY, active_plugin_name );

}
// If LIB_TABLE::Test() is conditioned on DEBUG being defined, build with
// CMAKE_BUILD_TYPE=Debug, otherwise don't worry about it, because it will work
// on any CMAKE_BUILD_TYPE, including Release.
void LIB_TABLE::Test()
{
    SCH_LIB_TABLE_LEXER  slr(
        "(lib_table \n"
        "  (lib (logical www)           (type http)     (full_uri http://kicad.org/libs)    (options \"\"))\n"
        "  (lib (logical meparts)       (type dir)      (full_uri /tmp/eeschema-lib)        (options useVersioning))\n"
//        "  (lib (logical meparts)       (type dir)      (full_uri /tmp/eeschema-lib)        (options \"\"))\n"
        "  (lib (logical old-project)   (type schematic)(full_uri /tmp/old-schematic.sch)   (options \"\"))\n"
        ")\n"
        ,

        wxT( "inline text" )        // source
        );

    // read the "( lib_table" pair of tokens
    slr.NextTok();
    slr.NextTok();

    // parse the rest of input to slr
    Parse( &slr );

    STRING_FORMATTER    sf;

    // format this whole table into sf, it will be sorted by logicalName.
    Format( &sf, 0 );

    printf( "test 'Parse() <-> Format()' round tripping:\n" );
    printf( "%s", sf.GetString().c_str() );

    printf( "\ntest a lookup of 'www':\n" );
    const LIB_TABLE::ROW* www = FindRow( "www" );
    if( www )
    {
        // found, print it just to prove it.
        sf.Clear();

        www->Format( &sf, 1 );
        printf( "%s", sf.GetString().c_str() );
    }
    else
        printf( "not found\n" );

    printf( "\nlist of logical libraries:\n" );

    STRINGS logNames = GetLogicalLibs();
    for( STRINGS::const_iterator it = logNames.begin(); it!=logNames.end();  ++it )
    {
        printf( "logicalName: %s\n", it->c_str() );
    }

    // find a part
    LPID    lpid( "meparts:tigers/ears" );

    PART*   part = LookupPart( lpid );

    sf.Clear();
    part->Format( &sf, 0, 0 );

    printf( "%s", sf.GetString().c_str() );
}
void SCH_EDIT_FRAME::backAnnotateFootprints( const std::string& aChangedSetOfReferences )
    throw( IO_ERROR, boost::bad_pointer )
{
    // Build a flat list of components in schematic:
    SCH_REFERENCE_LIST  refs;
    SCH_SHEET_LIST      sheets( g_RootSheet );
    bool                isChanged = false;

    sheets.GetComponents( Prj().SchLibs(), refs, false );

    DSNLEXER    lexer( aChangedSetOfReferences, FROM_UTF8( __func__ ) );
    PTREE       doc;

    try
    {
        Scan( &doc, &lexer );

#if defined(DEBUG) && 0
        STRING_FORMATTER sf;
        Format( &sf, 0, 0, doc );
        printf( "%s: '%s'\n", __func__, sf.GetString().c_str() );
#endif

        CPTREE& back_anno = doc.get_child( "back_annotation" );
        wxString footprint;

        for( PTREE::const_iterator ref = back_anno.begin();  ref != back_anno.end();  ++ref )
        {
            wxASSERT( ref->first == "ref" );

            wxString reference = (UTF8&) ref->second.front().first;

            // Ensure the "fpid" node contains a footprint name,
            // and get it if exists
            if( ref->second.get_child( "fpid" ).size() )
            {
                wxString tmp = (UTF8&) ref->second.get_child( "fpid" ).front().first;
                footprint = tmp;
            }
            else
                footprint.Empty();

            // DBG( printf( "%s: ref:%s  fpid:%s\n", __func__, TO_UTF8( reference ), TO_UTF8( footprint ) ); )

            // Search the component in the flat list
            for( unsigned ii = 0;  ii < refs.GetCount();  ++ii )
            {
                if( reference == refs[ii].GetRef() )
                {
                    // We have found a candidate.
                    // Note: it can be not unique (multiple parts per package)
                    // So we *do not* stop the search here
                    SCH_COMPONENT*  component = refs[ii].GetComp();
                    SCH_FIELD*      fpfield   = component->GetField( FOOTPRINT );
                    const wxString& oldfp = fpfield->GetText();

                    if( !oldfp && fpfield->IsVisible() )
                    {
                        fpfield->SetVisible( false );
                    }

                    // DBG( printf("%s: ref:%s  fpid:%s\n", __func__, TO_UTF8( refs[ii].GetRef() ), TO_UTF8( footprint ) );)
                    if( oldfp != footprint )
                        isChanged = true;

                    fpfield->SetText( footprint );
                }
            }
        }
    }
    catch( const PTREE_ERROR& ex )
    {
        // remap the exception to something the caller is likely to understand.
        THROW_IO_ERROR( ex.what() );
    }

    if( isChanged )
        OnModify();
}
 ~WORKSHEET_LAYOUT_STRINGIO()
 {
     m_output = FROM_UTF8( m_writer->GetString().c_str() );
     delete m_writer;
 }