2007-06-05 12:10:51 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2008-02-29 15:31:32 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
// Name: dialog_build_BOM.cpp
|
|
|
|
// Author: jean-pierre Charras
|
2008-02-29 15:31:32 +00:00
|
|
|
// Modified by:
|
2009-03-12 15:24:52 +00:00
|
|
|
// Licence: GPL
|
2007-06-05 12:10:51 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "program.h"
|
|
|
|
#include "libcmp.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "netlist.h"
|
|
|
|
|
2009-03-12 15:24:52 +00:00
|
|
|
#include "wx/valgen.h"
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "dialog_build_BOM.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "protos.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Local variables */
|
2008-02-29 15:31:32 +00:00
|
|
|
static bool s_ListByRef = TRUE;
|
|
|
|
static bool s_ListByValue = TRUE;
|
|
|
|
static bool s_ListWithSubCmponents;
|
|
|
|
static bool s_ListHierarchicalPinByName;
|
|
|
|
static bool s_ListBySheet;
|
2009-03-12 15:24:52 +00:00
|
|
|
static bool s_BrowseCreatedList;
|
2008-02-29 15:31:32 +00:00
|
|
|
static int s_OutputFormOpt;
|
|
|
|
static int s_OutputSeparatorOpt;
|
|
|
|
static bool s_Add_FpField_state;
|
|
|
|
static bool s_Add_F1_state;
|
|
|
|
static bool s_Add_F2_state;
|
|
|
|
static bool s_Add_F3_state;
|
|
|
|
static bool s_Add_F4_state;
|
|
|
|
static bool s_Add_F5_state;
|
|
|
|
static bool s_Add_F6_state;
|
|
|
|
static bool s_Add_F7_state;
|
|
|
|
static bool s_Add_F8_state;
|
2009-03-12 15:24:52 +00:00
|
|
|
static bool s_Add_Alls_state;
|
|
|
|
|
2008-02-29 15:31:32 +00:00
|
|
|
static bool* s_AddFieldList[] = {
|
|
|
|
&s_Add_FpField_state,
|
|
|
|
&s_Add_F1_state,
|
|
|
|
&s_Add_F2_state,
|
|
|
|
&s_Add_F3_state,
|
|
|
|
&s_Add_F4_state,
|
|
|
|
&s_Add_F5_state,
|
|
|
|
&s_Add_F6_state,
|
|
|
|
&s_Add_F7_state,
|
|
|
|
&s_Add_F8_state,
|
2009-03-12 15:24:52 +00:00
|
|
|
&s_Add_Alls_state,
|
2008-02-29 15:31:32 +00:00
|
|
|
NULL
|
2007-07-02 12:48:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-02-29 15:31:32 +00:00
|
|
|
#define OPTION_BOM_FORMAT wxT( "BomFormat" )
|
2009-03-12 15:24:52 +00:00
|
|
|
#define OPTION_BOM_LAUNCH_BROWSER wxT( "BomLaunchBrowser" )
|
2008-02-29 15:31:32 +00:00
|
|
|
#define OPTION_BOM_SEPARATOR wxT( "BomExportSeparator" )
|
|
|
|
#define OPTION_BOM_ADD_FIELD wxT( "BomAddField" )
|
2007-07-02 12:48:10 +00:00
|
|
|
|
|
|
|
/* list of separators used in bom export to spreadsheet
|
2007-10-13 05:56:37 +00:00
|
|
|
* (selected by s_OutputSeparatorOpt, and s_OutputSeparatorOpt radiobox)
|
|
|
|
*/
|
2007-07-02 12:48:10 +00:00
|
|
|
static char s_ExportSeparator[] = ("\t;,.");
|
2008-02-29 15:31:32 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*!
|
2009-03-12 15:24:52 +00:00
|
|
|
* DIALOG_BUILD_BOM dialog type definition
|
2007-06-05 12:10:51 +00:00
|
|
|
*/
|
|
|
|
|
2008-02-29 15:31:32 +00:00
|
|
|
|
2009-03-12 15:24:52 +00:00
|
|
|
DIALOG_BUILD_BOM::DIALOG_BUILD_BOM( WinEDA_DrawFrame* parent ):
|
|
|
|
DIALOG_BUILD_BOM_BASE(parent)
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-03-12 15:24:52 +00:00
|
|
|
m_Config = wxGetApp().m_EDA_Config;
|
2009-03-15 02:51:24 +00:00
|
|
|
wxASSERT( m_Config != NULL );
|
2008-12-08 15:27:13 +00:00
|
|
|
|
2008-02-29 15:31:32 +00:00
|
|
|
m_Parent = parent;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-03-12 15:24:52 +00:00
|
|
|
Init( );
|
2008-02-29 15:31:32 +00:00
|
|
|
|
2008-04-30 11:52:34 +00:00
|
|
|
if (GetSizer())
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-04-30 11:52:34 +00:00
|
|
|
GetSizer()->SetSizeHints(this);
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
Centre();
|
|
|
|
}
|
|
|
|
|
2008-02-29 15:31:32 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*!
|
2009-03-12 15:24:52 +00:00
|
|
|
* Init Controls for DIALOG_BUILD_BOM
|
2007-06-05 12:10:51 +00:00
|
|
|
*/
|
|
|
|
|
2009-03-12 15:24:52 +00:00
|
|
|
void DIALOG_BUILD_BOM::Init()
|
2008-02-29 15:31:32 +00:00
|
|
|
{
|
2009-03-12 15:24:52 +00:00
|
|
|
SetFocus();
|
2008-02-29 15:31:32 +00:00
|
|
|
|
2009-03-12 15:24:52 +00:00
|
|
|
/* Get options */
|
|
|
|
s_OutputFormOpt = m_Config->Read( OPTION_BOM_FORMAT, (long) 0 );
|
|
|
|
s_BrowseCreatedList = m_Config->Read( OPTION_BOM_LAUNCH_BROWSER, (long) 0 );
|
|
|
|
s_OutputSeparatorOpt = m_Config->Read( OPTION_BOM_SEPARATOR, (long) 0 );
|
|
|
|
long addfields = m_Config->Read( OPTION_BOM_ADD_FIELD, (long) 0 );
|
|
|
|
for( int ii = 0, bitmask = 1; s_AddFieldList[ii] != NULL; ii++ )
|
|
|
|
{
|
|
|
|
if( (addfields & bitmask) )
|
|
|
|
*s_AddFieldList[ii] = true;
|
|
|
|
else
|
|
|
|
*s_AddFieldList[ii] = false;
|
2007-10-13 05:56:37 +00:00
|
|
|
|
2009-03-12 15:24:52 +00:00
|
|
|
bitmask <<= 1;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
// Set validators
|
2008-04-30 11:52:34 +00:00
|
|
|
m_ListCmpbyRefItems->SetValidator( wxGenericValidator(& s_ListByRef) );
|
|
|
|
m_ListSubCmpItems->SetValidator( wxGenericValidator(& s_ListWithSubCmponents) );
|
|
|
|
m_ListCmpbyValItems->SetValidator( wxGenericValidator(& s_ListByValue) );
|
|
|
|
m_GenListLabelsbyVal->SetValidator( wxGenericValidator(& s_ListHierarchicalPinByName) );
|
|
|
|
m_GenListLabelsbySheet->SetValidator( wxGenericValidator(& s_ListBySheet) );
|
|
|
|
m_OutputFormCtrl->SetValidator( wxGenericValidator(& s_OutputFormOpt) );
|
|
|
|
m_OutputSeparatorCtrl->SetValidator( wxGenericValidator(& s_OutputSeparatorOpt) );
|
2009-03-12 15:24:52 +00:00
|
|
|
m_GetListBrowser->SetValidator( wxGenericValidator(& s_BrowseCreatedList) );
|
2008-04-30 11:52:34 +00:00
|
|
|
m_AddFootprintField->SetValidator( wxGenericValidator(& s_Add_FpField_state) );
|
|
|
|
m_AddField1->SetValidator( wxGenericValidator(& s_Add_F1_state) );
|
|
|
|
m_AddField2->SetValidator( wxGenericValidator(& s_Add_F2_state) );
|
|
|
|
m_AddField3->SetValidator( wxGenericValidator(& s_Add_F3_state) );
|
|
|
|
m_AddField4->SetValidator( wxGenericValidator(& s_Add_F4_state) );
|
|
|
|
m_AddField5->SetValidator( wxGenericValidator(& s_Add_F5_state) );
|
|
|
|
m_AddField6->SetValidator( wxGenericValidator(& s_Add_F6_state) );
|
|
|
|
m_AddField7->SetValidator( wxGenericValidator(& s_Add_F7_state) );
|
|
|
|
m_AddField8->SetValidator( wxGenericValidator(& s_Add_F8_state) );
|
2009-03-12 15:24:52 +00:00
|
|
|
m_AddAllFields->SetValidator( wxGenericValidator(& s_Add_Alls_state) );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-03-12 15:24:52 +00:00
|
|
|
m_OutputFormCtrl->SetSelection( s_OutputFormOpt );
|
|
|
|
m_OutputSeparatorCtrl->SetSelection( s_OutputSeparatorOpt );
|
2008-02-29 15:31:32 +00:00
|
|
|
|
2009-03-12 15:24:52 +00:00
|
|
|
// Enable/disable options:
|
|
|
|
wxCommandEvent dummy;
|
|
|
|
OnRadioboxSelectFormatSelected( dummy );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2007-10-13 05:56:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* wxEVT_COMMAND_RADIOBOX_SELECTED event handler for ID_RADIOBOX_SELECT_FORMAT
|
|
|
|
*/
|
|
|
|
|
2009-03-12 15:24:52 +00:00
|
|
|
void DIALOG_BUILD_BOM::OnRadioboxSelectFormatSelected( wxCommandEvent& event )
|
2007-10-13 05:56:37 +00:00
|
|
|
{
|
2008-02-29 15:31:32 +00:00
|
|
|
if( m_OutputFormCtrl->GetSelection() == 1 )
|
2008-05-15 13:29:59 +00:00
|
|
|
{
|
2008-02-29 15:31:32 +00:00
|
|
|
m_OutputSeparatorCtrl->Enable( true );
|
2008-05-15 13:29:59 +00:00
|
|
|
m_ListCmpbyValItems->Enable( false );
|
|
|
|
m_GenListLabelsbyVal->Enable( false );
|
|
|
|
m_GenListLabelsbySheet->Enable( false );
|
|
|
|
}
|
2008-02-29 15:31:32 +00:00
|
|
|
else
|
2008-05-15 13:29:59 +00:00
|
|
|
{
|
2008-02-29 15:31:32 +00:00
|
|
|
m_OutputSeparatorCtrl->Enable( false );
|
2008-05-15 13:29:59 +00:00
|
|
|
m_ListCmpbyValItems->Enable( true );
|
|
|
|
m_GenListLabelsbyVal->Enable( true );
|
|
|
|
m_GenListLabelsbySheet->Enable( true );
|
|
|
|
}
|
2007-10-13 05:56:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-03-12 15:24:52 +00:00
|
|
|
* wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
|
2007-10-13 05:56:37 +00:00
|
|
|
*/
|
|
|
|
|
2009-03-12 15:24:52 +00:00
|
|
|
void DIALOG_BUILD_BOM::OnOkClick( wxCommandEvent& event )
|
2007-10-13 05:56:37 +00:00
|
|
|
{
|
2008-05-15 13:29:59 +00:00
|
|
|
char ExportSeparatorSymbol = s_ExportSeparator[0];
|
|
|
|
if( m_OutputSeparatorCtrl->GetSelection() > 0 )
|
|
|
|
ExportSeparatorSymbol = s_ExportSeparator[m_OutputSeparatorCtrl->GetSelection()];
|
|
|
|
|
|
|
|
bool ExportFileType = m_OutputFormCtrl->GetSelection() == 0 ? false : true;
|
2008-05-15 15:59:11 +00:00
|
|
|
|
2008-05-15 13:29:59 +00:00
|
|
|
SavePreferences();
|
|
|
|
|
|
|
|
Create_BOM_Lists( ExportFileType, m_ListSubCmpItems->GetValue(),
|
|
|
|
ExportSeparatorSymbol, m_GetListBrowser->GetValue());
|
2007-10-13 05:56:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/*!
|
2007-10-13 05:56:37 +00:00
|
|
|
* wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CANCEL
|
2007-06-05 12:10:51 +00:00
|
|
|
*/
|
|
|
|
|
2009-03-12 15:24:52 +00:00
|
|
|
void DIALOG_BUILD_BOM::OnCancelClick( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-10-13 05:56:37 +00:00
|
|
|
EndModal( -1 );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-10-13 05:56:37 +00:00
|
|
|
|
|
|
|
/**************************************************/
|
2009-03-12 15:24:52 +00:00
|
|
|
void DIALOG_BUILD_BOM::SavePreferences()
|
2007-10-13 05:56:37 +00:00
|
|
|
/**************************************************/
|
|
|
|
{
|
2009-04-06 10:56:17 +00:00
|
|
|
wxASSERT( m_Config != NULL );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2008-02-29 15:31:32 +00:00
|
|
|
// Determine current settings of "List items" and "Options" checkboxes
|
|
|
|
// (NOTE: These 6 settings are restored when the dialog box is next
|
|
|
|
// invoked, but are *not* still saved after EESchema is next shut down.)
|
|
|
|
s_ListByRef = m_ListCmpbyRefItems->GetValue();
|
|
|
|
s_ListWithSubCmponents = m_ListSubCmpItems->GetValue();
|
|
|
|
s_ListByValue = m_ListCmpbyValItems->GetValue();
|
|
|
|
s_ListHierarchicalPinByName = m_GenListLabelsbyVal->GetValue();
|
|
|
|
s_ListBySheet = m_GenListLabelsbySheet->GetValue();
|
2009-03-12 15:24:52 +00:00
|
|
|
s_BrowseCreatedList = m_GetListBrowser->GetValue();
|
|
|
|
|
|
|
|
// (aved in config ):
|
2008-02-29 15:31:32 +00:00
|
|
|
|
|
|
|
// Determine current settings of both radiobutton groups
|
|
|
|
s_OutputFormOpt = m_OutputFormCtrl->GetSelection();
|
|
|
|
s_OutputSeparatorOpt = m_OutputSeparatorCtrl->GetSelection();
|
|
|
|
if( s_OutputSeparatorOpt < 0 )
|
|
|
|
s_OutputSeparatorOpt = 0;
|
|
|
|
|
2008-05-15 15:59:11 +00:00
|
|
|
// Determine current settings of all "Fields to add" checkboxes
|
|
|
|
s_Add_FpField_state = m_AddFootprintField->GetValue();
|
2008-02-29 15:31:32 +00:00
|
|
|
s_Add_F1_state = m_AddField1->GetValue();
|
|
|
|
s_Add_F2_state = m_AddField2->GetValue();
|
|
|
|
s_Add_F3_state = m_AddField3->GetValue();
|
|
|
|
s_Add_F4_state = m_AddField4->GetValue();
|
|
|
|
s_Add_F5_state = m_AddField5->GetValue();
|
|
|
|
s_Add_F6_state = m_AddField6->GetValue();
|
|
|
|
s_Add_F7_state = m_AddField7->GetValue();
|
|
|
|
s_Add_F8_state = m_AddField8->GetValue();
|
2009-03-12 15:24:52 +00:00
|
|
|
s_Add_Alls_state = m_AddAllFields->GetValue();
|
2008-02-29 15:31:32 +00:00
|
|
|
|
|
|
|
// Now save current settings of both radiobutton groups
|
2009-03-12 15:24:52 +00:00
|
|
|
m_Config->Write( OPTION_BOM_FORMAT, (long) s_OutputFormOpt );
|
|
|
|
m_Config->Write( OPTION_BOM_SEPARATOR, (long) s_OutputSeparatorOpt );
|
|
|
|
m_Config->Write( OPTION_BOM_LAUNCH_BROWSER, (long) s_BrowseCreatedList );
|
2008-02-29 15:31:32 +00:00
|
|
|
|
2008-05-15 15:59:11 +00:00
|
|
|
// Now save current settings of all "Fields to add" checkboxes
|
2008-02-29 15:31:32 +00:00
|
|
|
long addfields = 0;
|
|
|
|
for( int ii = 0, bitmask = 1; s_AddFieldList[ii] != NULL; ii++ )
|
|
|
|
{
|
|
|
|
if( *s_AddFieldList[ii] )
|
|
|
|
addfields |= bitmask;
|
|
|
|
bitmask <<= 1;
|
|
|
|
}
|
|
|
|
|
2009-03-12 15:24:52 +00:00
|
|
|
m_Config->Write( OPTION_BOM_ADD_FIELD, addfields );
|
2007-10-13 05:56:37 +00:00
|
|
|
}
|