Commit f3765a32 authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Fix minor issues. Fix some outdated and broken BOM python scripts. Add info in BOM python scripts.

BOM dialog: remove a not very useful button, and merge its function with an other (not perfect, need more work)
Add message box to show info added in BOM python scripts (See scripts/bom-in-python/README-bom.txt about this info)
parent 479af2a7
Loading
Loading
Loading
Loading
+105 −8
Original line number Diff line number Diff line
@@ -69,7 +69,6 @@ public:

private:
    void parsePlugin() throw( IO_ERROR, PARSE_ERROR );

};

// PCB_PLOT_PARAMS_PARSER
@@ -175,7 +174,6 @@ private:
    void OnCancelClick( wxCommandEvent& event );
    void OnHelp( wxCommandEvent& event );
    void OnAddPlugin( wxCommandEvent& event );
    void OnChoosePlugin( wxCommandEvent& event );
    void OnRemovePlugin( wxCommandEvent& event );
    void OnEditPlugin( wxCommandEvent& event );
    void OnCommandLineEdited( wxCommandEvent& event );
@@ -183,6 +181,18 @@ private:

    void pluginInit();
    void installPluginsList();
    wxString getPluginFileName();

    /**
     * display (when exists) the text found between the keyword "@package"
     * and the end of comment block (""" in python", --> in xml)
     */
    void displayPluginInfo( FILE * aFile, const wxString& aFilename );

    /**
     * Browse plugin files, and set m_CommandStringCtrl field
     */
    void choosePlugin();
};

// Create and show DIALOG_BOM.
@@ -215,12 +225,14 @@ DIALOG_BOM::~DIALOG_BOM()

    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() ) );
@@ -272,6 +284,7 @@ void DIALOG_BOM::OnPluginSelected( wxCommandEvent& event )
    pluginInit();
}

#include <wx/ffile.h>
void DIALOG_BOM::pluginInit()
{
    int ii = m_lbPlugins->GetSelection();
@@ -285,8 +298,67 @@ void DIALOG_BOM::pluginInit()

    m_textCtrlName->SetValue( m_plugins[2 * ii] );
    m_textCtrlCommand->SetValue( m_plugins[(2 * ii)+1] );

    wxString pluginName = getPluginFileName();

    if( pluginName.IsEmpty() )
        return;

    FILE* pluginFile = wxFopen( pluginName, "rt" );

    if( pluginFile == NULL )
    {
        wxString msg;
        msg.Printf( _( "Failed to open file '%s'" ), GetChars( pluginName ) );
        DisplayError( this, msg );
        return;
    }

    displayPluginInfo( pluginFile, pluginName );
}

/* display (when exists) the text found between the keyword "@package"
 * and the end of comment block (""" in python", --> in xml)
 */
void DIALOG_BOM::displayPluginInfo( FILE * aFile, const wxString& aFilename )
{
    m_Messages->Clear();

    // display (when exists) the text found between the keyword "@package"
    // and the end of comment block (""" in python", --> in xml)

    wxString data;
    wxFFile fdata( aFile );        // dtor will close the file

    if( !fdata.ReadAll( &data ) )
        return;

    wxString header( wxT( "@package" ) );
    wxString endsection( wxT( "-->" ) );        // For xml

    wxFileName fn( aFilename );

    if( fn.GetExt().IsSameAs( wxT("py"), false ) )
        endsection = wxT( "\"\"\"" );

    // Extract substring between @package and """
    int strstart = data.Find( header );

    if( strstart == wxNOT_FOUND )
        return;

    strstart += header.Length();
    int strend = data.find( endsection, strstart );

    if( strend == wxNOT_FOUND)
        return;

    // Remove emty line if any
    while( data[strstart] < ' ' )
            strstart++;

    m_Messages->SetValue( data.SubString( strstart, strend-1 ) );
}

/**
 * Function RunPlugin
@@ -351,7 +423,7 @@ void DIALOG_BOM::OnRemovePlugin( wxCommandEvent& event )
void DIALOG_BOM::OnAddPlugin( wxCommandEvent& event )
{
    // Creates a new plugin entry
    wxString name = wxGetTextFromUser( _("Plugin") );
    wxString name = wxGetTextFromUser( _("Plugin name in plugin list") );

    if( name.IsEmpty() )
        return;
@@ -361,7 +433,7 @@ void DIALOG_BOM::OnAddPlugin( wxCommandEvent& event )
    {
        if( name == m_plugins[ii] )
        {
            wxMessageBox( _("This plugin already exists. Abort") );
            wxMessageBox( _("This name already exists. Abort") );
            return;
        }
    }
@@ -370,13 +442,16 @@ void DIALOG_BOM::OnAddPlugin( wxCommandEvent& event )
    m_plugins.Add( wxEmptyString );
    m_lbPlugins->Append( name );
    m_lbPlugins->SetSelection( m_lbPlugins->GetCount() - 1 );

    choosePlugin();

    pluginInit();
}

/*
 * Browse plugin files, and set m_CommandStringCtrl field
 */
void DIALOG_BOM::OnChoosePlugin( wxCommandEvent& event )
void DIALOG_BOM::choosePlugin()
{
    wxString mask = wxT( "*" );
#ifndef __WXMAC__
@@ -417,13 +492,14 @@ void DIALOG_BOM::OnChoosePlugin( wxCommandEvent& event )
    m_textCtrlCommand->SetValue( cmdLine );
}

void DIALOG_BOM::OnEditPlugin( wxCommandEvent& event )

wxString DIALOG_BOM::getPluginFileName()
{
    wxString    pluginName, cmdline;
    wxString pluginName;

    // Try to find the plugin name.
    // This is possible if the name ends by .py or .xsl
    cmdline = m_textCtrlCommand->GetValue();
    wxString cmdline = m_textCtrlCommand->GetValue();
    int pos = -1;

    if( (pos = cmdline.Find( wxT(".py") )) != wxNOT_FOUND )
@@ -449,9 +525,30 @@ void DIALOG_BOM::OnEditPlugin( wxCommandEvent& event )

            // extract the name
            if( jj >= 0 )
            {
                eos = cmdline[jj];

                if( eos == ' '|| eos == '\"' )  // do not include delimiters
                    jj++;

                pluginName = cmdline.SubString( jj, pos );
            }
        }
    }

    return pluginName;
}

void DIALOG_BOM::OnEditPlugin( wxCommandEvent& event )
{
    wxString    pluginName = getPluginFileName();

    if( pluginName.Length() <= 2 )      // if name != ""
    {
        wxMessageBox( _("Plugin file name not found. Cannot edit plugin file") );
        return;
    }

    AddDelimiterString( pluginName );
    wxString    editorname = Pgm().GetEditorName();

+7 −4
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@ BEGIN_EVENT_TABLE( DIALOG_BOM_BASE, DIALOG_SHIM )
	EVT_BUTTON( wxID_CANCEL, DIALOG_BOM_BASE::_wxFB_OnCancelClick )
	EVT_BUTTON( ID_HELP, DIALOG_BOM_BASE::_wxFB_OnHelp )
	EVT_BUTTON( ID_ADD_PLUGIN, DIALOG_BOM_BASE::_wxFB_OnAddPlugin )
	EVT_BUTTON( wxID_BROWSE_PLUGINS, DIALOG_BOM_BASE::_wxFB_OnChoosePlugin )
	EVT_BUTTON( ID_REMOVEL_PLUGIN, DIALOG_BOM_BASE::_wxFB_OnRemovePlugin )
	EVT_BUTTON( wxID_ANY, DIALOG_BOM_BASE::_wxFB_OnEditPlugin )
	EVT_TEXT( ID_CMDLINE, DIALOG_BOM_BASE::_wxFB_OnCommandLineEdited )
@@ -72,9 +71,6 @@ DIALOG_BOM_BASE::DIALOG_BOM_BASE( wxWindow* parent, wxWindowID id, const wxStrin
	m_buttonAddPlugin = new wxButton( this, ID_ADD_PLUGIN, _("Add Plugin"), wxDefaultPosition, wxDefaultSize, 0 );
	bRightSizer->Add( m_buttonAddPlugin, 0, wxALIGN_CENTER_HORIZONTAL|wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 );
	
	m_buttonBrowsePlugin = new wxButton( this, wxID_BROWSE_PLUGINS, _("Set Plugin Cmd"), wxDefaultPosition, wxDefaultSize, 0 );
	bRightSizer->Add( m_buttonBrowsePlugin, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 );
	
	m_buttonDelPlugin = new wxButton( this, ID_REMOVEL_PLUGIN, _("Remove Plugin"), wxDefaultPosition, wxDefaultSize, 0 );
	bRightSizer->Add( m_buttonDelPlugin, 0, wxALIGN_CENTER_HORIZONTAL|wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 );
	
@@ -103,6 +99,13 @@ DIALOG_BOM_BASE::DIALOG_BOM_BASE( wxWindow* parent, wxWindowID id, const wxStrin
	
	bMainSizer->Add( bbottomSizer, 0, wxEXPAND, 5 );
	
	m_staticTextInfo = new wxStaticText( this, wxID_ANY, _("Plugin Info:"), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticTextInfo->Wrap( -1 );
	bMainSizer->Add( m_staticTextInfo, 0, wxRIGHT|wxLEFT, 5 );
	
	m_Messages = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY );
	bMainSizer->Add( m_Messages, 1, wxALL|wxEXPAND, 5 );
	
	
	this->SetSizer( bMainSizer );
	this->Layout();
+175 −89

File changed.

Preview size limit exceeded, changes collapsed.

+3 −5
Original line number Diff line number Diff line
@@ -44,7 +44,6 @@ class DIALOG_BOM_BASE : public DIALOG_SHIM
		void _wxFB_OnCancelClick( wxCommandEvent& event ){ OnCancelClick( event ); }
		void _wxFB_OnHelp( wxCommandEvent& event ){ OnHelp( event ); }
		void _wxFB_OnAddPlugin( wxCommandEvent& event ){ OnAddPlugin( event ); }
		void _wxFB_OnChoosePlugin( wxCommandEvent& event ){ OnChoosePlugin( event ); }
		void _wxFB_OnRemovePlugin( wxCommandEvent& event ){ OnRemovePlugin( event ); }
		void _wxFB_OnEditPlugin( wxCommandEvent& event ){ OnEditPlugin( event ); }
		void _wxFB_OnCommandLineEdited( wxCommandEvent& event ){ OnCommandLineEdited( event ); }
@@ -57,7 +56,6 @@ class DIALOG_BOM_BASE : public DIALOG_SHIM
			ID_CREATE_BOM,
			ID_HELP,
			ID_ADD_PLUGIN,
			wxID_BROWSE_PLUGINS,
			ID_REMOVEL_PLUGIN,
			ID_CMDLINE
		};
@@ -71,11 +69,12 @@ class DIALOG_BOM_BASE : public DIALOG_SHIM
		wxButton* m_buttonHelp;
		wxStaticLine* m_staticline2;
		wxButton* m_buttonAddPlugin;
		wxButton* m_buttonBrowsePlugin;
		wxButton* m_buttonDelPlugin;
		wxButton* m_buttonEdit;
		wxStaticText* m_staticTextCmd;
		wxTextCtrl* m_textCtrlCommand;
		wxStaticText* m_staticTextInfo;
		wxTextCtrl* m_Messages;
		
		// Virtual event handlers, overide them in your derived class
		virtual void OnPluginSelected( wxCommandEvent& event ) { event.Skip(); }
@@ -84,7 +83,6 @@ class DIALOG_BOM_BASE : public DIALOG_SHIM
		virtual void OnCancelClick( wxCommandEvent& event ) { event.Skip(); }
		virtual void OnHelp( wxCommandEvent& event ) { event.Skip(); }
		virtual void OnAddPlugin( wxCommandEvent& event ) { event.Skip(); }
		virtual void OnChoosePlugin( wxCommandEvent& event ) { event.Skip(); }
		virtual void OnRemovePlugin( wxCommandEvent& event ) { event.Skip(); }
		virtual void OnEditPlugin( wxCommandEvent& event ) { event.Skip(); }
		virtual void OnCommandLineEdited( wxCommandEvent& event ) { event.Skip(); }
@@ -92,7 +90,7 @@ class DIALOG_BOM_BASE : public DIALOG_SHIM
	
	public:
		
		DIALOG_BOM_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Bill of Material"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 404,315 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); 
		DIALOG_BOM_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Bill of Material"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 409,393 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); 
		~DIALOG_BOM_BASE();
	
};
+2 −2
Original line number Diff line number Diff line
@@ -381,7 +381,7 @@ bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST * aConnectedItemsList

    NETLIST_EXPORT_TOOL helper( aConnectedItemsList, Prj().SchLibs() );

    bool open_file = aFormat < NET_TYPE_CUSTOM1;
    bool open_file = (aFormat < NET_TYPE_CUSTOM1) && (aFormat >= 0);
    if( (aFormat == NET_TYPE_PCBNEW) && (aNetlistOptions & NET_PCBNEW_USE_NEW_FORMAT ) )
        open_file = false;

@@ -390,7 +390,7 @@ bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST * aConnectedItemsList
        if( ( f = wxFopen( aFullFileName, wxT( "wt" ) ) ) == NULL )
        {
            wxString msg;
            msg.Printf( _( "Failed to create file <%s>" ),
            msg.Printf( _( "Failed to create file '%s'" ),
                        GetChars( aFullFileName ) );
            DisplayError( this, msg );
            return false;
Loading