Fix minor coding style issues

This commit is contained in:
jean-pierre charras 2017-11-03 09:41:48 +01:00
parent 4e391ef21c
commit 08a9dc01c5
4 changed files with 143 additions and 58 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2017 Oliver Walters * Copyright (C) 2017 Oliver Walters
* Copyright (C) 2017 KiCad Developers, see CHANGELOG.TXT for contributors. * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2017 Oliver Walters * Copyright (C) 2017 Oliver Walters
* Copyright (C) 2017 KiCad Developers, see CHANGELOG.TXT for contributors. * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -30,6 +30,7 @@
static const wxColor ROW_COLOUR_ITEM_CHANGED( 200, 0, 0 ); static const wxColor ROW_COLOUR_ITEM_CHANGED( 200, 0, 0 );
static const wxColor ROW_COLOUR_MULTIPLE_ITEMS( 60, 90, 200 ); static const wxColor ROW_COLOUR_MULTIPLE_ITEMS( 60, 90, 200 );
/** /**
* Convert BOM_TABLE_ROW -> wxDataViewItem * Convert BOM_TABLE_ROW -> wxDataViewItem
*/ */
@ -38,6 +39,7 @@ static wxDataViewItem RowToItem( BOM_TABLE_ROW const* aRow )
return wxDataViewItem( const_cast<void*>( static_cast<void const*>( aRow ) ) ); return wxDataViewItem( const_cast<void*>( static_cast<void const*>( aRow ) ) );
} }
/** /**
* Convert wxDataViewItem -> BOM_TABEL_ROW * Convert wxDataViewItem -> BOM_TABEL_ROW
*/ */
@ -53,15 +55,14 @@ static BOM_TABLE_ROW const* ItemToRow( wxDataViewItem aItem )
} }
} }
BOM_FIELD_VALUES::BOM_FIELD_VALUES( wxString aRefDes, FIELD_VALUE_MAP* aTemplate ) : BOM_FIELD_VALUES::BOM_FIELD_VALUES( wxString aRefDes, FIELD_VALUE_MAP* aTemplate ) :
m_refDes( aRefDes ), m_refDes( aRefDes ),
m_templateValues( aTemplate ) m_templateValues( aTemplate )
{ {
} }
/**
* Return the current value for the provided field ID
*/
bool BOM_FIELD_VALUES::GetFieldValue( unsigned int aFieldId, wxString& aValue ) const bool BOM_FIELD_VALUES::GetFieldValue( unsigned int aFieldId, wxString& aValue ) const
{ {
auto search = m_currentValues.find( aFieldId ); auto search = m_currentValues.find( aFieldId );
@ -74,9 +75,7 @@ bool BOM_FIELD_VALUES::GetFieldValue( unsigned int aFieldId, wxString& aValue )
return true; return true;
} }
/**
* Return the backup value for the provided field ID
*/
bool BOM_FIELD_VALUES::GetBackupValue( unsigned int aFieldId, wxString& aValue ) const bool BOM_FIELD_VALUES::GetBackupValue( unsigned int aFieldId, wxString& aValue ) const
{ {
auto search = m_backupValues.find( aFieldId ); auto search = m_backupValues.find( aFieldId );
@ -89,9 +88,7 @@ bool BOM_FIELD_VALUES::GetBackupValue( unsigned int aFieldId, wxString& aValue )
return true; return true;
} }
/**
* Return the template value for a provided field ID (if it exists)
*/
bool BOM_FIELD_VALUES::GetTemplateValue( unsigned int aFieldId, wxString& aValue ) const bool BOM_FIELD_VALUES::GetTemplateValue( unsigned int aFieldId, wxString& aValue ) const
{ {
if( !m_templateValues ) if( !m_templateValues )
@ -107,21 +104,18 @@ bool BOM_FIELD_VALUES::GetTemplateValue( unsigned int aFieldId, wxString& aValue
return true; return true;
} }
/**
* Set the value for the provided field ID void BOM_FIELD_VALUES::SetFieldValue( unsigned int aFieldId, const wxString& aValue,
* Field value is set under any of the following conditions: bool aOverwrite )
* - param aOverwrite is true
* - There is no current value
* - The current value is empty
*/
void BOM_FIELD_VALUES::SetFieldValue( unsigned int aFieldId, wxString aValue, bool aOverwrite )
{ {
if( aOverwrite || m_currentValues.count( aFieldId ) == 0 || m_currentValues[aFieldId].IsEmpty() ) if( aOverwrite || m_currentValues.count( aFieldId ) == 0 ||
m_currentValues[aFieldId].IsEmpty() )
{ {
m_currentValues[aFieldId] = aValue; m_currentValues[aFieldId] = aValue;
} }
} }
bool BOM_FIELD_VALUES::HasValueChanged( unsigned int aFieldId) const bool BOM_FIELD_VALUES::HasValueChanged( unsigned int aFieldId) const
{ {
wxString currentValue, backupValue; wxString currentValue, backupValue;
@ -132,6 +126,7 @@ bool BOM_FIELD_VALUES::HasValueChanged( unsigned int aFieldId) const
return currentValue.Cmp( backupValue ) != 0; return currentValue.Cmp( backupValue ) != 0;
} }
void BOM_FIELD_VALUES::RevertChanges( unsigned int aFieldId ) void BOM_FIELD_VALUES::RevertChanges( unsigned int aFieldId )
{ {
wxString backupValue; wxString backupValue;
@ -149,10 +144,12 @@ void BOM_FIELD_VALUES::SetBackupPoint()
} }
} }
BOM_TABLE_ROW::BOM_TABLE_ROW() : m_columnList( nullptr ) BOM_TABLE_ROW::BOM_TABLE_ROW() : m_columnList( nullptr )
{ {
} }
/** /**
* Update cell attributes based on parameters of the cell * Update cell attributes based on parameters of the cell
* Default implementation highlights cells that have been altered * Default implementation highlights cells that have been altered
@ -172,6 +169,7 @@ bool BOM_TABLE_ROW::GetAttr( unsigned int aFieldId, wxDataViewItemAttr& aAttr )
return false; return false;
} }
bool BOM_TABLE_ROW::HasChanged() const bool BOM_TABLE_ROW::HasChanged() const
{ {
if( !m_columnList ) if( !m_columnList )
@ -188,6 +186,7 @@ bool BOM_TABLE_ROW::HasChanged() const
return false; return false;
} }
/** /**
* Create a new group (which contains one or more components) * Create a new group (which contains one or more components)
*/ */
@ -196,6 +195,7 @@ BOM_TABLE_GROUP::BOM_TABLE_GROUP( BOM_COLUMN_LIST* aColumnList )
m_columnList = aColumnList; m_columnList = aColumnList;
} }
bool BOM_TABLE_GROUP::GetAttr( unsigned int aFieldId, wxDataViewItemAttr& aAttr ) const bool BOM_TABLE_GROUP::GetAttr( unsigned int aFieldId, wxDataViewItemAttr& aAttr ) const
{ {
if( GetFieldValue( aFieldId ).Cmp( ROW_MULT_ITEMS ) == 0 ) if( GetFieldValue( aFieldId ).Cmp( ROW_MULT_ITEMS ) == 0 )
@ -208,6 +208,7 @@ bool BOM_TABLE_GROUP::GetAttr( unsigned int aFieldId, wxDataViewItemAttr& aAttr
return BOM_TABLE_ROW::GetAttr( aFieldId, aAttr ); return BOM_TABLE_ROW::GetAttr( aFieldId, aAttr );
} }
/** /**
* Return the value associated with a given field in the group. * Return the value associated with a given field in the group.
* Some fields require special attention. * Some fields require special attention.
@ -223,10 +224,12 @@ wxString BOM_TABLE_GROUP::GetFieldValue( unsigned int aFieldId ) const
case BOM_COL_ID_QUANTITY: case BOM_COL_ID_QUANTITY:
value = wxString::Format( "%u", (unsigned int) GroupSize() ); value = wxString::Format( "%u", (unsigned int) GroupSize() );
break; break;
// REFERENCE field returns consolidated list of references // REFERENCE field returns consolidated list of references
case BOM_COL_ID_REFERENCE: case BOM_COL_ID_REFERENCE:
value = wxJoin( GetReferences(), ' ' ); value = wxJoin( GetReferences(), ' ' );
break; break;
// Otherwise, return component data // Otherwise, return component data
default: default:
if( Components.size() == 0 ) if( Components.size() == 0 )
@ -259,6 +262,7 @@ wxString BOM_TABLE_GROUP::GetFieldValue( unsigned int aFieldId ) const
return value; return value;
} }
/** /**
* Set the value of a field in a group * Set the value of a field in a group
* The new value is pushed to all components that are children of this group * The new value is pushed to all components that are children of this group
@ -275,6 +279,7 @@ bool BOM_TABLE_GROUP::SetFieldValue( unsigned int aFieldId, const wxString aValu
return result; return result;
} }
/** /**
* Determines if a given component matches against a particular field. * Determines if a given component matches against a particular field.
* *
@ -302,11 +307,13 @@ bool BOM_TABLE_GROUP::TestField( BOM_COLUMN* aField, BOM_TABLE_COMPONENT* aCompo
// These fields should NOT be compared (return True) // These fields should NOT be compared (return True)
case BOM_COL_ID_QUANTITY: case BOM_COL_ID_QUANTITY:
return true; return true;
// Reference matching is done only on prefix // Reference matching is done only on prefix
case BOM_COL_ID_REFERENCE: case BOM_COL_ID_REFERENCE:
componentValue = aComponent->GetPrefix(); componentValue = aComponent->GetPrefix();
comparisonValue = Components[0]->GetPrefix(); comparisonValue = Components[0]->GetPrefix();
break; break;
default: default:
componentValue = aComponent->GetFieldValue( aField->Id() ); componentValue = aComponent->GetFieldValue( aField->Id() );
comparisonValue = Components[0]->GetFieldValue( aField->Id() ); comparisonValue = Components[0]->GetFieldValue( aField->Id() );
@ -318,6 +325,7 @@ bool BOM_TABLE_GROUP::TestField( BOM_COLUMN* aField, BOM_TABLE_COMPONENT* aCompo
return result; return result;
} }
/** /**
* Add a new component to the group. * Add a new component to the group.
* It is assumed at this stage that the component is a good match for the group. * It is assumed at this stage that the component is a good match for the group.
@ -378,6 +386,7 @@ unsigned int BOM_TABLE_GROUP::GetChildren( wxDataViewItemArray& aChildren ) cons
return aChildren.size(); return aChildren.size();
} }
/** /**
* Test if any components in this group have a new value in the provided field * Test if any components in this group have a new value in the provided field
* @param aField is the field to test * @param aField is the field to test
@ -409,6 +418,7 @@ bool BOM_TABLE_GROUP::HasValueChanged( BOM_COLUMN* aField ) const
return changed; return changed;
} }
/** /**
* Return a list of (ordered) references * Return a list of (ordered) references
* for all the components in this group * for all the components in this group
@ -435,6 +445,7 @@ wxArrayString BOM_TABLE_GROUP::GetReferences( bool aSort ) const
return refs; return refs;
} }
/** /**
* Compare two references (e.g. "R100", "R19") and perform a 'natural' sort * Compare two references (e.g. "R100", "R19") and perform a 'natural' sort
* This sorting must preserve numerical order rather than alphabetical * This sorting must preserve numerical order rather than alphabetical
@ -488,6 +499,7 @@ int BOM_TABLE_GROUP::SortReferences( const wxString& aFirst, const wxString& aSe
return (int) (numFirst - numSecond); return (int) (numFirst - numSecond);
} }
/** /**
* Compare two VALUE fields. * Compare two VALUE fields.
* A value field can reasonably be expected to be one of: * A value field can reasonably be expected to be one of:
@ -511,6 +523,7 @@ int BOM_TABLE_GROUP::SortValues( const wxString& aFirst, const wxString& aSecond
return aFirst.CmpNoCase( aSecond ); return aFirst.CmpNoCase( aSecond );
} }
/** /**
* Create a new COMPONENT row * Create a new COMPONENT row
* Each COMPONENT row is associated with a single component item. * Each COMPONENT row is associated with a single component item.
@ -524,6 +537,7 @@ BOM_TABLE_COMPONENT::BOM_TABLE_COMPONENT( BOM_TABLE_GROUP* aParent,
m_fieldValues = aFieldValues; m_fieldValues = aFieldValues;
} }
/** /**
* Try to add a unit to this component * Try to add a unit to this component
* If the references match, it will be added * If the references match, it will be added
@ -547,9 +561,11 @@ bool BOM_TABLE_COMPONENT::AddUnit( SCH_REFERENCE aUnit )
case BOM_COL_ID_QUANTITY: case BOM_COL_ID_QUANTITY:
value = wxEmptyString; value = wxEmptyString;
break; break;
case BOM_COL_ID_DESCRIPTION: case BOM_COL_ID_DESCRIPTION:
value = cmp->GetAliasDescription(); value = cmp->GetAliasDescription();
break; break;
case BOM_COL_ID_DATASHEET: case BOM_COL_ID_DATASHEET:
value = cmp->GetField( DATASHEET )->GetText(); value = cmp->GetField( DATASHEET )->GetText();
if( value.IsEmpty() ) if( value.IsEmpty() )
@ -557,12 +573,15 @@ bool BOM_TABLE_COMPONENT::AddUnit( SCH_REFERENCE aUnit )
value = cmp->GetAliasDocumentation(); value = cmp->GetAliasDocumentation();
} }
break; break;
case BOM_COL_ID_REFERENCE: case BOM_COL_ID_REFERENCE:
value = aUnit.GetRef(); value = aUnit.GetRef();
break; break;
case BOM_COL_ID_VALUE: case BOM_COL_ID_VALUE:
value = cmp->GetField( VALUE )->GetText(); value = cmp->GetField( VALUE )->GetText();
break; break;
case BOM_COL_ID_FOOTPRINT: case BOM_COL_ID_FOOTPRINT:
value = cmp->GetField( FOOTPRINT )->GetText(); value = cmp->GetField( FOOTPRINT )->GetText();
break; break;
@ -595,8 +614,10 @@ wxString BOM_TABLE_COMPONENT::GetFieldValue( unsigned int aFieldId ) const
{ {
case BOM_COL_ID_QUANTITY: case BOM_COL_ID_QUANTITY:
return wxEmptyString; return wxEmptyString;
case BOM_COL_ID_REFERENCE: case BOM_COL_ID_REFERENCE:
return GetReference(); return GetReference();
default: default:
break; break;
} }
@ -614,6 +635,7 @@ wxString BOM_TABLE_COMPONENT::GetFieldValue( unsigned int aFieldId ) const
return value; return value;
} }
/** /**
* Set the value of a field in the component * Set the value of a field in the component
* @param aFieldId is the unique ID of the field to update * @param aFieldId is the unique ID of the field to update
@ -631,17 +653,17 @@ bool BOM_TABLE_COMPONENT::SetFieldValue( unsigned int aFieldId, const wxString a
return false; return false;
} }
/**
* Return the prefix of a component e.g. "R23" -> "R"
*/
wxString BOM_TABLE_COMPONENT::GetPrefix() const wxString BOM_TABLE_COMPONENT::GetPrefix() const
{ {
// Return the prefix of a component e.g. "R23" -> "R"
if( Units.size() == 0 ) if( Units.size() == 0 )
return wxEmptyString; return wxEmptyString;
return Units[0].GetComp()->GetPrefix(); return Units[0].GetComp()->GetPrefix();
} }
/** /**
* Return the reference of a component e.g. "R23" * Return the reference of a component e.g. "R23"
*/ */
@ -653,6 +675,7 @@ wxString BOM_TABLE_COMPONENT::GetReference() const
return Units[0].GetRef(); return Units[0].GetRef();
} }
/** /**
* Determines if the given field has been changed for this component * Determines if the given field has been changed for this component
*/ */
@ -666,6 +689,7 @@ bool BOM_TABLE_COMPONENT::HasValueChanged( BOM_COLUMN* aField ) const
return m_fieldValues->HasValueChanged( aField->Id() ); return m_fieldValues->HasValueChanged( aField->Id() );
} }
/** /**
* If any changes have been made to this component, * If any changes have been made to this component,
* they are now applied to the schematic component * they are now applied to the schematic component
@ -694,16 +718,19 @@ void BOM_TABLE_COMPONENT::ApplyFieldChanges()
case BOM_COL_ID_REFERENCE: case BOM_COL_ID_REFERENCE:
case BOM_COL_ID_QUANTITY: case BOM_COL_ID_QUANTITY:
continue; continue;
// Special field considerations // Special field considerations
case BOM_COL_ID_FOOTPRINT: case BOM_COL_ID_FOOTPRINT:
field = cmp->GetField( FOOTPRINT ); field = cmp->GetField( FOOTPRINT );
break; break;
case BOM_COL_ID_VALUE: case BOM_COL_ID_VALUE:
field = cmp->GetField( VALUE ); field = cmp->GetField( VALUE );
break; break;
case BOM_COL_ID_DATASHEET: case BOM_COL_ID_DATASHEET:
field = cmp->GetField( DATASHEET ); field = cmp->GetField( DATASHEET );
break; break;
default: default:
// Find the field by name (but ignore default fields) // Find the field by name (but ignore default fields)
field = cmp->FindField( column->Title(), false ); field = cmp->FindField( column->Title(), false );
@ -726,6 +753,7 @@ void BOM_TABLE_COMPONENT::ApplyFieldChanges()
} }
} }
/** /**
* Revert the displayed fields for this component * Revert the displayed fields for this component
* to their original values (matching the schematic data) * to their original values (matching the schematic data)
@ -747,6 +775,7 @@ void BOM_TABLE_COMPONENT::RevertFieldChanges()
} }
} }
BOM_TABLE_MODEL::BOM_TABLE_MODEL() : BOM_TABLE_MODEL::BOM_TABLE_MODEL() :
m_widget( nullptr ), m_widget( nullptr ),
m_sortingColumn( BOM_COL_ID_REFERENCE ), m_sortingColumn( BOM_COL_ID_REFERENCE ),
@ -755,6 +784,7 @@ BOM_TABLE_MODEL::BOM_TABLE_MODEL() :
//TODO //TODO
} }
/** /**
* Create a container for the BOM_TABLE_MODEL * Create a container for the BOM_TABLE_MODEL
* This is required for reference counting by wxDataViewCtrl * This is required for reference counting by wxDataViewCtrl
@ -768,11 +798,13 @@ BOM_TABLE_MODEL::MODEL_PTR BOM_TABLE_MODEL::Create()
return container; return container;
} }
BOM_TABLE_MODEL::~BOM_TABLE_MODEL() BOM_TABLE_MODEL::~BOM_TABLE_MODEL()
{ {
//TODO //TODO
} }
wxDataViewColumn* BOM_TABLE_MODEL::AddColumn( BOM_COLUMN* aColumn, int aPosition ) wxDataViewColumn* BOM_TABLE_MODEL::AddColumn( BOM_COLUMN* aColumn, int aPosition )
{ {
static const unsigned int flags = wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE; static const unsigned int flags = wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE;
@ -838,6 +870,7 @@ wxDataViewColumn* BOM_TABLE_MODEL::AddColumn( BOM_COLUMN* aColumn, int aPosition
return column; return column;
} }
/** /**
* Gracefully remove the given column from the wxDataViewCtrl * Gracefully remove the given column from the wxDataViewCtrl
* Removing columns individually prevents bad redraw of entire table * Removing columns individually prevents bad redraw of entire table
@ -861,6 +894,7 @@ bool BOM_TABLE_MODEL::RemoveColumn( BOM_COLUMN* aColumn )
return false; return false;
} }
/** /**
* Attach the MODEL to a particular VIEW * Attach the MODEL to a particular VIEW
* This function causes the view to be updated appropriately * This function causes the view to be updated appropriately
@ -891,6 +925,7 @@ void BOM_TABLE_MODEL::AttachTo( wxDataViewCtrl* aView )
aView->Update(); aView->Update();
} }
/** /**
* Return the total number of components displayed by the model * Return the total number of components displayed by the model
*/ */
@ -907,11 +942,13 @@ unsigned int BOM_TABLE_MODEL::ComponentCount() const
return count; return count;
} }
void BOM_TABLE_MODEL::ClearColumns() void BOM_TABLE_MODEL::ClearColumns()
{ {
ColumnList.Clear(); ColumnList.Clear();
} }
/** /**
* Add default columns to the table * Add default columns to the table
* These columns are ALWAYS available in the table * These columns are ALWAYS available in the table
@ -959,6 +996,7 @@ void BOM_TABLE_MODEL::AddDefaultColumns()
true, true ) ); true, true ) );
} }
/** /**
* Extract field data from all components * Extract field data from all components
* Compiles an inclusive list of all field names from all components * Compiles an inclusive list of all field names from all components
@ -1019,6 +1057,7 @@ void BOM_TABLE_MODEL::AddComponentFields( SCH_COMPONENT* aCmp )
} }
} }
/** /**
* Add a list of component items to the BOM manager * Add a list of component items to the BOM manager
* Creates consolidated groups of components as required * Creates consolidated groups of components as required
@ -1118,6 +1157,7 @@ void BOM_TABLE_MODEL::SetComponents( SCH_REFERENCE_LIST aRefs, const TEMPLATE_FI
SetBackupPoint(); SetBackupPoint();
} }
void BOM_TABLE_MODEL::SetBackupPoint() void BOM_TABLE_MODEL::SetBackupPoint()
{ {
// Mark backup locations for all values // Mark backup locations for all values
@ -1127,6 +1167,7 @@ void BOM_TABLE_MODEL::SetBackupPoint()
} }
} }
/** /**
* Recalculate grouping of components and reload table * Recalculate grouping of components and reload table
**/ **/
@ -1178,6 +1219,7 @@ void BOM_TABLE_MODEL::ReloadTable()
} }
} }
/** /**
* Return a string array of data from a given row * Return a string array of data from a given row
*/ */
@ -1209,12 +1251,11 @@ wxArrayString BOM_TABLE_MODEL::GetRowData( unsigned int aRow, std::vector<BOM_CO
return row; return row;
} }
/** /**
* Get the value of a particular item in the model * Get the value of a particular item in the model
*/ */
void BOM_TABLE_MODEL::GetValue( void BOM_TABLE_MODEL::GetValue( wxVariant& aVariant, const wxDataViewItem& aItem,
wxVariant& aVariant,
const wxDataViewItem& aItem,
unsigned int aFieldId ) const unsigned int aFieldId ) const
{ {
auto row = ItemToRow( aItem ); auto row = ItemToRow( aItem );
@ -1225,12 +1266,11 @@ void BOM_TABLE_MODEL::GetValue(
} }
} }
/** /**
* Set the value of a particular item in the model * Set the value of a particular item in the model
*/ */
bool BOM_TABLE_MODEL::SetValue( bool BOM_TABLE_MODEL::SetValue( const wxVariant& aVariant, const wxDataViewItem& aItem,
const wxVariant& aVariant,
const wxDataViewItem& aItem,
unsigned int aFieldId ) unsigned int aFieldId )
{ {
if( !aItem.IsOk() || !m_widget ) if( !aItem.IsOk() || !m_widget )
@ -1272,6 +1312,7 @@ bool BOM_TABLE_MODEL::SetValue(
return false; return false;
} }
/** /**
* Return the parent item for a given item in the model. * Return the parent item for a given item in the model.
* If no parent is found (or the item is invalid) return an invalid item. * If no parent is found (or the item is invalid) return an invalid item.
@ -1290,6 +1331,7 @@ wxDataViewItem BOM_TABLE_MODEL::GetParent( const wxDataViewItem& aItem ) const
return wxDataViewItem(); return wxDataViewItem();
} }
/** /**
* Returns true if the supplied item has children * Returns true if the supplied item has children
*/ */
@ -1305,12 +1347,12 @@ bool BOM_TABLE_MODEL::IsContainer( const wxDataViewItem& aItem ) const
return true; return true;
} }
/** /**
* Push all children of the supplied item into the list * Push all children of the supplied item into the list
* If the supplied item is invalid, push all the top-level items * If the supplied item is invalid, push all the top-level items
*/ */
unsigned int BOM_TABLE_MODEL::GetChildren( unsigned int BOM_TABLE_MODEL::GetChildren( const wxDataViewItem& aItem,
const wxDataViewItem& aItem,
wxDataViewItemArray& aChildren ) const wxDataViewItemArray& aChildren ) const
{ {
auto row = aItem.IsOk() ? ItemToRow( aItem ) : nullptr; auto row = aItem.IsOk() ? ItemToRow( aItem ) : nullptr;
@ -1331,6 +1373,7 @@ unsigned int BOM_TABLE_MODEL::GetChildren(
} }
} }
bool BOM_TABLE_MODEL::GetAttr( const wxDataViewItem& aItem, bool BOM_TABLE_MODEL::GetAttr( const wxDataViewItem& aItem,
unsigned int aFieldId, unsigned int aFieldId,
wxDataViewItemAttr& aAttr ) const wxDataViewItemAttr& aAttr ) const
@ -1341,12 +1384,11 @@ bool BOM_TABLE_MODEL::GetAttr( const wxDataViewItem& aItem,
{ {
return row->GetAttr( aFieldId, aAttr ); return row->GetAttr( aFieldId, aAttr );
} }
else
{
return false; return false;
}
} }
/** /**
* Custom comparison function for improved column sorting * Custom comparison function for improved column sorting
* Alphanumeric sorting is not sufficient for correct ordering of some fields * Alphanumeric sorting is not sufficient for correct ordering of some fields
@ -1383,9 +1425,11 @@ int BOM_TABLE_MODEL::Compare( const wxDataViewItem& aItem1,
case BOM_COL_ID_REFERENCE: case BOM_COL_ID_REFERENCE:
result = BOM_TABLE_GROUP::SortReferences( strVal1, strVal2 ); result = BOM_TABLE_GROUP::SortReferences( strVal1, strVal2 );
break; break;
case BOM_COL_ID_VALUE: case BOM_COL_ID_VALUE:
result = BOM_TABLE_GROUP::SortValues( strVal1, strVal2 ); result = BOM_TABLE_GROUP::SortValues( strVal1, strVal2 );
break; break;
// These columns are sorted numerically // These columns are sorted numerically
case BOM_COL_ID_QUANTITY: case BOM_COL_ID_QUANTITY:
if( strVal1.ToLong( &numVal1 ) && strVal2.ToLong( &numVal2 ) ) if( strVal1.ToLong( &numVal1 ) && strVal2.ToLong( &numVal2 ) )
@ -1397,6 +1441,7 @@ int BOM_TABLE_MODEL::Compare( const wxDataViewItem& aItem1,
result = strVal1.Cmp( strVal2 ); result = strVal1.Cmp( strVal2 );
} }
break; break;
default: default:
// Default comparison (no special case) // Default comparison (no special case)
result = strVal1.Cmp( strVal2 ); result = strVal1.Cmp( strVal2 );
@ -1427,6 +1472,7 @@ int BOM_TABLE_MODEL::Compare( const wxDataViewItem& aItem1,
return result; return result;
} }
/** /**
* Revert all component data back to the original values. * Revert all component data back to the original values.
* The table view is updated accordingly * The table view is updated accordingly
@ -1461,6 +1507,7 @@ void BOM_TABLE_MODEL::RevertFieldChanges()
} }
} }
/** /**
* Apply all outstanding field changes. * Apply all outstanding field changes.
* This is performed only when the window is closed * This is performed only when the window is closed
@ -1485,6 +1532,7 @@ void BOM_TABLE_MODEL::ApplyFieldChanges()
} }
} }
/** /**
* Tests if any component values in the table have been altered * Tests if any component values in the table have been altered
*/ */
@ -1510,6 +1558,7 @@ bool BOM_TABLE_MODEL::HaveFieldsChanged() const
return false; return false;
} }
/** /**
* Returns a list of only those components that have been changed * Returns a list of only those components that have been changed
*/ */
@ -1540,6 +1589,7 @@ std::vector<SCH_REFERENCE> BOM_TABLE_MODEL::GetChangedComponents()
return components; return components;
} }
/** /**
* Returns a count of the components that have been changed * Returns a count of the components that have been changed
*/ */

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2017 Oliver Walters * Copyright (C) 2017 Oliver Walters
* Copyright (C) 2017 KiCad Developers, see CHANGELOG.TXT for contributors. * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -60,11 +60,38 @@ class BOM_FIELD_VALUES
public: public:
BOM_FIELD_VALUES( wxString aRefDes, FIELD_VALUE_MAP* aTemplate ); BOM_FIELD_VALUES( wxString aRefDes, FIELD_VALUE_MAP* aTemplate );
/**
* Return the current value for the provided field ID
* @return true if the field exists
* @param aFieldId = the field index
* @param aValue = a string to return the field value
*/
bool GetFieldValue( unsigned int aFieldId, wxString& aValue ) const; bool GetFieldValue( unsigned int aFieldId, wxString& aValue ) const;
/**
* Return the backup value for the provided field ID
* @return true if the field exists
* @param aFieldId = the field index
* @param aValue = a string to return the field backup value
*/
bool GetBackupValue( unsigned int aFieldId, wxString& aValue ) const; bool GetBackupValue( unsigned int aFieldId, wxString& aValue ) const;
/**
* Return the template value for a provided field ID (if it exists)
* @return true if the field exists
* @param aFieldId = the field index
* @param aValue = a string to return the field template value
*/
bool GetTemplateValue( unsigned int aFieldId, wxString& aValue ) const; bool GetTemplateValue( unsigned int aFieldId, wxString& aValue ) const;
void SetFieldValue( unsigned int aFieldId, wxString aValue, bool aOverwrite = false ); /**
* Set the value for the provided field ID
* Field value is set under any of the following conditions:
* - param aOverwrite is true
* - There is no current value
* - The current value is empty
*/
void SetFieldValue( unsigned int aFieldId, const wxString& aValue, bool aOverwrite = false );
wxString GetReference() const { return m_refDes; } wxString GetReference() const { return m_refDes; }
@ -139,47 +166,47 @@ protected:
class BOM_TABLE_GROUP : public BOM_TABLE_ROW class BOM_TABLE_GROUP : public BOM_TABLE_ROW
{ {
public: public:
// List of components stored in this group /// List of components stored in this group
std::vector<BOM_TABLE_COMPONENT*> Components; std::vector<BOM_TABLE_COMPONENT*> Components;
BOM_TABLE_GROUP( BOM_COLUMN_LIST* aColumnList ); BOM_TABLE_GROUP( BOM_COLUMN_LIST* aColumnList );
virtual ~BOM_TABLE_GROUP() {} virtual ~BOM_TABLE_GROUP() {}
// Set display properties for a group row /// Set display properties for a group row
virtual bool GetAttr( unsigned int aFieldId, wxDataViewItemAttr& aAttr ) const override; virtual bool GetAttr( unsigned int aFieldId, wxDataViewItemAttr& aAttr ) const override;
// Get group row value /// Get group row value
virtual wxString GetFieldValue( unsigned int aFieldId ) const override; virtual wxString GetFieldValue( unsigned int aFieldId ) const override;
// Set group row value /// Set group row value
virtual bool SetFieldValue( unsigned int aFieldId, const wxString aValue, bool aOverwrite = false ) override; virtual bool SetFieldValue( unsigned int aFieldId, const wxString aValue, bool aOverwrite = false ) override;
// Attempt to add a new component to the group /// Attempt to add a new component to the group
bool AddComponent( BOM_TABLE_COMPONENT* aComponent ); bool AddComponent( BOM_TABLE_COMPONENT* aComponent );
// Test if this group should display children /// Test if this group should display children
virtual bool HasChildren() const override { return Components.size() > 1; } virtual bool HasChildren() const override { return Components.size() > 1; }
// Return a list of children items of this group /// Return a list of children items of this group
virtual unsigned int GetChildren( wxDataViewItemArray& aChildren ) const override; virtual unsigned int GetChildren( wxDataViewItemArray& aChildren ) const override;
// Test if any children have changed /// Test if any children have changed
virtual bool HasValueChanged( BOM_COLUMN* aField ) const override; virtual bool HasValueChanged( BOM_COLUMN* aField ) const override;
// Return the number of child items in this group /// Return the number of child items in this group
unsigned int GroupSize( void ) const { return Components.size(); } unsigned int GroupSize( void ) const { return Components.size(); }
// Return a sorted, concatenated list of references /// Return a sorted, concatenated list of references
wxArrayString GetReferences( bool aSort = true ) const; wxArrayString GetReferences( bool aSort = true ) const;
// Function for sorting two reference strings /// Function for sorting two reference strings
static int SortReferences( const wxString& aFirst, const wxString& aSecond ); static int SortReferences( const wxString& aFirst, const wxString& aSecond );
// Function for sorting two value strings /// Function for sorting two value strings
static int SortValues( const wxString& aFirst, const wxString& aSecond ); static int SortValues( const wxString& aFirst, const wxString& aSecond );
protected: protected:
// Test if a particular field matches against another component /// Test if a particular field matches against another component
bool TestField( BOM_COLUMN* aField, BOM_TABLE_COMPONENT* aComponent ) const; bool TestField( BOM_COLUMN* aField, BOM_TABLE_COMPONENT* aComponent ) const;
}; };
@ -199,9 +226,12 @@ public:
virtual bool HasValueChanged( BOM_COLUMN* aField ) const override; virtual bool HasValueChanged( BOM_COLUMN* aField ) const override;
// Return the reference of the first unit (all units must be the same /// Return the reference of the first unit (all units must be the same
wxString GetReference() const; wxString GetReference() const;
/**
* @return the prefix of a component e.g. "R23" returns "R"
*/
wxString GetPrefix() const; wxString GetPrefix() const;
void ApplyFieldChanges(); void ApplyFieldChanges();

View File

@ -47,6 +47,7 @@ void InvokeDialogCreateBOMEditor( SCH_EDIT_FRAME* aCaller )
dlg.ShowQuasiModal(); dlg.ShowQuasiModal();
} }
DIALOG_BOM_EDITOR::DIALOG_BOM_EDITOR( SCH_EDIT_FRAME* parent ) : DIALOG_BOM_EDITOR::DIALOG_BOM_EDITOR( SCH_EDIT_FRAME* parent ) :
DIALOG_BOM_EDITOR_BASE( parent ), DIALOG_BOM_EDITOR_BASE( parent ),
m_parent( parent ) m_parent( parent )
@ -342,7 +343,6 @@ void DIALOG_BOM_EDITOR::LoadColumnNames()
void DIALOG_BOM_EDITOR::ReloadColumns() void DIALOG_BOM_EDITOR::ReloadColumns()
{ {
m_bom->AttachTo( m_bomView ); m_bom->AttachTo( m_bomView );
UpdateTitle(); UpdateTitle();
} }
@ -352,14 +352,15 @@ void DIALOG_BOM_EDITOR::OnColumnItemToggled( wxDataViewEvent& event )
wxDataViewItem item = event.GetItem(); wxDataViewItem item = event.GetItem();
int row = m_columnListCtrl->ItemToRow( item ); int row = m_columnListCtrl->ItemToRow( item );
int col = event.GetColumn(); int col = event.GetColumn();
if( row == wxNOT_FOUND || row < 0 || row >= (int) m_bom->ColumnCount() ) return; if( row == wxNOT_FOUND || row < 0 || row >= (int) m_bom->ColumnCount() )
return;
BOM_COLUMN* bomColumn = m_bom->ColumnList.GetColumnByIndex( row ); BOM_COLUMN* bomColumn = m_bom->ColumnList.GetColumnByIndex( row );
if( nullptr == bomColumn ) return; if( nullptr == bomColumn )
return;
bool bValue = m_columnListCtrl->GetToggleValue( row, col ); bool bValue = m_columnListCtrl->GetToggleValue( row, col );
@ -367,6 +368,7 @@ void DIALOG_BOM_EDITOR::OnColumnItemToggled( wxDataViewEvent& event )
{ {
default: default:
break; break;
case 1: // Column visibility case 1: // Column visibility
bomColumn->SetVisible( bValue ); bomColumn->SetVisible( bValue );
@ -380,6 +382,7 @@ void DIALOG_BOM_EDITOR::OnColumnItemToggled( wxDataViewEvent& event )
m_bom->RemoveColumn( bomColumn ); m_bom->RemoveColumn( bomColumn );
} }
break; break;
case 2: // Column used to sort case 2: // Column used to sort
bomColumn->SetUsedToSort( bValue ); bomColumn->SetUsedToSort( bValue );
m_bom->ReloadTable(); m_bom->ReloadTable();
@ -427,6 +430,7 @@ void DIALOG_BOM_EDITOR::OnRegroupComponents( wxCommandEvent& event )
Update(); Update();
} }
void DIALOG_BOM_EDITOR::OnApplyFieldChanges( wxCommandEvent& event ) void DIALOG_BOM_EDITOR::OnApplyFieldChanges( wxCommandEvent& event )
{ {
ApplyAllChanges(); ApplyAllChanges();
@ -446,6 +450,7 @@ void DIALOG_BOM_EDITOR::OnRevertFieldChanges( wxCommandEvent& event )
} }
} }
// Called when a cell is left-clicked // Called when a cell is left-clicked
void DIALOG_BOM_EDITOR::OnTableItemActivated( wxDataViewEvent& event ) void DIALOG_BOM_EDITOR::OnTableItemActivated( wxDataViewEvent& event )
{ {