2023-02-28 18:37:04 +00:00
|
|
|
#include <sch_reference_list.h>
|
|
|
|
#include <wx/grid.h>
|
|
|
|
|
|
|
|
// The field name in the data model (translated)
|
|
|
|
#define DISPLAY_NAME_COLUMN 0
|
|
|
|
// The field name's label for exporting (CSV, etc.)
|
|
|
|
#define LABEL_COLUMN 1
|
|
|
|
#define SHOW_FIELD_COLUMN 2
|
|
|
|
#define GROUP_BY_COLUMN 3
|
|
|
|
// The internal field name (untranslated)
|
|
|
|
#define FIELD_NAME_COLUMN 4
|
|
|
|
|
2023-03-27 20:48:37 +00:00
|
|
|
struct BOM_FIELD;
|
2023-03-15 00:03:57 +00:00
|
|
|
struct BOM_PRESET;
|
|
|
|
struct BOM_FMT_PRESET;
|
2023-02-28 18:37:04 +00:00
|
|
|
|
|
|
|
enum GROUP_TYPE
|
|
|
|
{
|
|
|
|
GROUP_SINGLETON,
|
|
|
|
GROUP_COLLAPSED,
|
|
|
|
GROUP_COLLAPSED_DURING_SORT,
|
|
|
|
GROUP_EXPANDED,
|
|
|
|
CHILD_ITEM
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct DATA_MODEL_ROW
|
|
|
|
{
|
|
|
|
DATA_MODEL_ROW( const SCH_REFERENCE& aFirstReference, GROUP_TYPE aType )
|
|
|
|
{
|
|
|
|
m_Refs.push_back( aFirstReference );
|
|
|
|
m_Flag = aType;
|
|
|
|
}
|
|
|
|
|
|
|
|
GROUP_TYPE m_Flag;
|
|
|
|
std::vector<SCH_REFERENCE> m_Refs;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct DATA_MODEL_COL
|
|
|
|
{
|
|
|
|
wxString m_fieldName;
|
|
|
|
wxString m_label;
|
|
|
|
bool m_userAdded;
|
|
|
|
bool m_show;
|
|
|
|
bool m_group;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class FIELDS_EDITOR_GRID_DATA_MODEL : public wxGridTableBase
|
|
|
|
{
|
|
|
|
public:
|
2023-03-15 00:03:57 +00:00
|
|
|
FIELDS_EDITOR_GRID_DATA_MODEL( SCH_REFERENCE_LIST& aSymbolsList ) :
|
|
|
|
m_symbolsList( aSymbolsList ), m_edited( false ), m_sortColumn( 0 ),
|
2023-03-30 14:17:09 +00:00
|
|
|
m_sortAscending( false ), m_groupingEnabled( false ), m_excludeDNP( false ),
|
|
|
|
m_includeExcluded( false )
|
2023-02-28 18:37:04 +00:00
|
|
|
{
|
|
|
|
m_symbolsList.SplitReferences();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddColumn( const wxString& aFieldName, const wxString& aLabel, bool aAddedByUser );
|
|
|
|
void RemoveColumn( int aCol );
|
|
|
|
void RenameColumn( int aCol, const wxString& newName );
|
2023-03-01 15:06:00 +00:00
|
|
|
void MoveColumn( int aCol, int aNewPos )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( aCol >= 0 && aCol < (int) m_cols.size(), "Invalid Column Number" );
|
|
|
|
std::swap( m_cols[aCol], m_cols[aNewPos] );
|
|
|
|
}
|
2023-02-28 18:37:04 +00:00
|
|
|
|
|
|
|
int GetNumberRows() override { return (int) m_rows.size(); }
|
|
|
|
int GetNumberCols() override { return (int) m_cols.size(); }
|
|
|
|
|
|
|
|
void SetColLabelValue( int aCol, const wxString& aLabel ) override
|
|
|
|
{
|
2023-03-01 15:06:00 +00:00
|
|
|
wxCHECK_RET( aCol >= 0 && aCol < (int) m_cols.size(), "Invalid Column Number" );
|
2023-02-28 18:37:04 +00:00
|
|
|
m_cols[aCol].m_label = aLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-01 15:06:00 +00:00
|
|
|
wxString GetColLabelValue( int aCol ) override
|
|
|
|
{
|
|
|
|
wxCHECK( aCol >= 0 && aCol < (int) m_cols.size(), wxString() );
|
|
|
|
return m_cols[aCol].m_label;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString GetColFieldName( int aCol )
|
|
|
|
{
|
|
|
|
wxCHECK( aCol >= 0 && aCol < (int) m_cols.size(), wxString() );
|
|
|
|
return m_cols[aCol].m_fieldName;
|
|
|
|
}
|
2023-02-28 18:37:04 +00:00
|
|
|
|
|
|
|
int GetFieldNameCol( wxString aFieldName );
|
|
|
|
|
2023-03-27 20:48:37 +00:00
|
|
|
const std::vector<BOM_FIELD> GetFieldsOrdered();
|
2023-02-28 18:37:04 +00:00
|
|
|
void SetFieldsOrder( const std::vector<wxString>& aNewOrder );
|
|
|
|
|
|
|
|
bool IsEmptyCell( int aRow, int aCol ) override
|
|
|
|
{
|
|
|
|
return false; // don't allow adjacent cell overflow, even if we are actually empty
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString GetValue( int aRow, int aCol ) override;
|
2023-03-15 00:03:57 +00:00
|
|
|
wxString GetValue( const DATA_MODEL_ROW& group, int aCol,
|
|
|
|
const wxString& refDelimiter = wxT( ", " ),
|
2023-03-30 14:17:09 +00:00
|
|
|
const wxString& refRangDelimiter = wxT( "-" ),
|
|
|
|
bool resolveVars = false );
|
|
|
|
wxString GetExportValue( int aRow, int aCol, const wxString& refDelimiter,
|
|
|
|
const wxString& refRangeDelimiter )
|
2023-03-03 13:43:40 +00:00
|
|
|
{
|
2023-03-30 14:17:09 +00:00
|
|
|
return GetValue( m_rows[aRow], aCol, refDelimiter, refRangeDelimiter, true );
|
2023-03-03 13:43:40 +00:00
|
|
|
}
|
2023-02-28 18:37:04 +00:00
|
|
|
void SetValue( int aRow, int aCol, const wxString& aValue ) override;
|
|
|
|
|
|
|
|
GROUP_TYPE GetRowFlags( int aRow ) { return m_rows[aRow].m_Flag; }
|
|
|
|
|
|
|
|
std::vector<SCH_REFERENCE> GetRowReferences( int aRow ) const
|
|
|
|
{
|
2023-03-01 15:06:00 +00:00
|
|
|
wxCHECK( aRow >= 0 && aRow < (int) m_rows.size(), std::vector<SCH_REFERENCE>() );
|
2023-02-28 18:37:04 +00:00
|
|
|
return m_rows[aRow].m_Refs;
|
|
|
|
}
|
|
|
|
|
2023-03-16 13:53:37 +00:00
|
|
|
bool ColIsReference( int aCol );
|
|
|
|
bool ColIsQuantity( int aCol );
|
2023-02-28 18:37:04 +00:00
|
|
|
|
2023-03-01 15:06:00 +00:00
|
|
|
void SetSorting( int aCol, bool ascending )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( aCol >= 0 && aCol < (int) m_cols.size(), "Invalid Column Number" );
|
|
|
|
m_sortColumn = aCol;
|
|
|
|
m_sortAscending = ascending;
|
|
|
|
}
|
2023-03-15 00:03:57 +00:00
|
|
|
int GetSortCol() { return m_sortColumn; }
|
|
|
|
bool GetSortAsc() { return m_sortAscending; }
|
2023-02-28 18:37:04 +00:00
|
|
|
|
2023-03-01 15:06:00 +00:00
|
|
|
void RebuildRows();
|
2023-02-28 18:37:04 +00:00
|
|
|
void ExpandRow( int aRow );
|
|
|
|
void CollapseRow( int aRow );
|
|
|
|
void ExpandCollapseRow( int aRow );
|
|
|
|
void CollapseForSort();
|
|
|
|
void ExpandAfterSort();
|
|
|
|
|
2023-03-15 00:03:57 +00:00
|
|
|
void ApplyData( std::function<void( SCH_SYMBOL&, SCH_SHEET_PATH& )> symbolChangeHandler );
|
2023-02-28 18:37:04 +00:00
|
|
|
|
|
|
|
bool IsEdited() { return m_edited; }
|
|
|
|
|
|
|
|
int GetDataWidth( int aCol );
|
|
|
|
|
2023-03-01 15:06:00 +00:00
|
|
|
void SetFilter( const wxString& aFilter ) { m_filter = aFilter; }
|
2023-03-15 00:03:57 +00:00
|
|
|
const wxString& GetFilter() { return m_filter; }
|
|
|
|
|
2023-03-01 15:06:00 +00:00
|
|
|
void SetGroupingEnabled( bool group ) { m_groupingEnabled = group; }
|
2023-03-15 00:03:57 +00:00
|
|
|
bool GetGroupingEnabled() { return m_groupingEnabled; }
|
|
|
|
|
2023-03-30 14:17:09 +00:00
|
|
|
/* These contradictorily named functions force including symbols that
|
|
|
|
* have the Exclude from BOM check box ticked. This is needed so we can view
|
|
|
|
* these parts in the symbol fields table dialog, while also excluding from the
|
|
|
|
* BOM export */
|
|
|
|
void SetIncludeExcludedFromBOM( bool include ) { m_includeExcluded = include; }
|
|
|
|
bool GetIncludeExcludedFromBOM() { return m_includeExcluded; }
|
|
|
|
|
|
|
|
void SetExcludeDNP( bool exclude ) { m_excludeDNP = exclude; }
|
|
|
|
bool GetExcludeDNP() { return m_excludeDNP; }
|
|
|
|
|
2023-03-01 15:06:00 +00:00
|
|
|
void SetGroupColumn( int aCol, bool group )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( aCol >= 0 && aCol < (int) m_cols.size(), "Invalid Column Number" );
|
|
|
|
m_cols[aCol].m_group = group;
|
|
|
|
}
|
2023-03-15 00:03:57 +00:00
|
|
|
bool GetGroupColumn( int aCol )
|
|
|
|
{
|
|
|
|
wxCHECK_MSG( aCol >= 0 && aCol < (int) m_cols.size(), false, "Invalid Column Number" );
|
|
|
|
return m_cols[aCol].m_group;
|
|
|
|
}
|
2023-03-01 15:06:00 +00:00
|
|
|
|
|
|
|
void SetShowColumn( int aCol, bool show )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( aCol >= 0 && aCol < (int) m_cols.size(), "Invalid Column Number" );
|
|
|
|
m_cols[aCol].m_show = show;
|
|
|
|
}
|
2023-03-15 00:03:57 +00:00
|
|
|
bool GetShowColumn( int aCol )
|
|
|
|
{
|
|
|
|
wxCHECK_MSG( aCol >= 0 && aCol < (int) m_cols.size(), false, "Invalid Column Number" );
|
|
|
|
return m_cols[aCol].m_show;
|
|
|
|
}
|
2023-03-01 15:06:00 +00:00
|
|
|
|
2023-03-15 00:03:57 +00:00
|
|
|
void ApplyBomPreset( const BOM_PRESET& preset );
|
2023-04-01 12:57:59 +00:00
|
|
|
BOM_PRESET GetBomSettings();
|
2023-03-09 15:54:57 +00:00
|
|
|
wxString Export( const BOM_FMT_PRESET& settings );
|
2023-03-03 13:43:40 +00:00
|
|
|
|
2023-02-28 18:37:04 +00:00
|
|
|
private:
|
|
|
|
static bool cmp( const DATA_MODEL_ROW& lhGroup, const DATA_MODEL_ROW& rhGroup,
|
|
|
|
FIELDS_EDITOR_GRID_DATA_MODEL* dataModel, int sortCol, bool ascending );
|
|
|
|
bool unitMatch( const SCH_REFERENCE& lhRef, const SCH_REFERENCE& rhRef );
|
2023-03-01 15:06:00 +00:00
|
|
|
bool groupMatch( const SCH_REFERENCE& lhRef, const SCH_REFERENCE& rhRef );
|
|
|
|
|
|
|
|
void Sort();
|
|
|
|
|
2023-02-28 18:37:04 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
SCH_REFERENCE_LIST m_symbolsList;
|
|
|
|
bool m_edited;
|
|
|
|
int m_sortColumn;
|
|
|
|
bool m_sortAscending;
|
2023-03-01 15:06:00 +00:00
|
|
|
wxString m_filter;
|
|
|
|
bool m_groupingEnabled;
|
2023-03-30 14:17:09 +00:00
|
|
|
bool m_excludeDNP;
|
|
|
|
bool m_includeExcluded;
|
2023-02-28 18:37:04 +00:00
|
|
|
|
|
|
|
std::vector<DATA_MODEL_COL> m_cols;
|
|
|
|
std::vector<DATA_MODEL_ROW> m_rows;
|
|
|
|
|
|
|
|
// Data store
|
|
|
|
// The data model is fundamentally m_componentRefs X m_fieldNames.
|
|
|
|
// A map of compID : fieldSet, where fieldSet is a map of fieldName : fieldValue
|
|
|
|
std::map<KIID, std::map<wxString, wxString>> m_dataStore;
|
|
|
|
};
|