2017-04-02 12:09:01 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Oliver Walters
|
2018-01-07 03:37:49 +00:00
|
|
|
* Copyright (C) 2017-2018 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-04-02 12:09:01 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <wx/msgdlg.h>
|
2018-04-17 10:34:48 +00:00
|
|
|
#include <wx/grid.h>
|
2017-04-02 12:09:01 +00:00
|
|
|
|
|
|
|
#include <confirm.h>
|
2018-04-17 10:34:48 +00:00
|
|
|
#include <bitmaps.h>
|
|
|
|
#include <grid_tricks.h>
|
|
|
|
#include <kicad_string.h>
|
2017-04-02 12:09:01 +00:00
|
|
|
|
|
|
|
#include <build_version.h>
|
|
|
|
#include <general.h>
|
|
|
|
#include <class_library.h>
|
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
#include <sch_edit_frame.h>
|
|
|
|
#include <sch_reference_list.h>
|
2018-05-22 11:50:57 +00:00
|
|
|
#include <kiface_i.h>
|
2018-04-17 10:34:48 +00:00
|
|
|
|
2018-02-09 16:35:45 +00:00
|
|
|
#include "dialog_fields_editor_global.h"
|
2017-04-02 12:09:01 +00:00
|
|
|
|
|
|
|
|
2018-05-12 22:04:11 +00:00
|
|
|
enum GROUP_TYPE
|
|
|
|
{
|
|
|
|
GROUP_SINGLETON,
|
|
|
|
GROUP_COLLAPSED,
|
2018-05-13 11:06:46 +00:00
|
|
|
GROUP_COLLAPSED_DURING_SORT,
|
2018-05-12 22:04:11 +00:00
|
|
|
GROUP_EXPANDED,
|
|
|
|
CHILD_ITEM
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DATA_MODEL_ROW
|
|
|
|
{
|
|
|
|
DATA_MODEL_ROW( SCH_REFERENCE aFirstReference, GROUP_TYPE aType )
|
|
|
|
{
|
|
|
|
m_Refs.push_back( aFirstReference );
|
|
|
|
m_Flag = aType;
|
|
|
|
}
|
|
|
|
|
|
|
|
GROUP_TYPE m_Flag;
|
|
|
|
std::vector<SCH_REFERENCE> m_Refs;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
#define FIELD_NAME_COLUMN 0
|
|
|
|
#define SHOW_FIELD_COLUMN 1
|
|
|
|
#define GROUP_BY_COLUMN 2
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-05-12 22:04:11 +00:00
|
|
|
#define QUANTITY_COLUMN ( GetNumberCols() - 1 )
|
|
|
|
|
2018-04-26 14:45:28 +00:00
|
|
|
#ifdef __WXMAC__
|
2018-04-26 10:09:41 +00:00
|
|
|
#define CHECKBOX_COLUMN_MARGIN 5
|
2018-04-26 14:45:28 +00:00
|
|
|
#else
|
|
|
|
#define CHECKBOX_COLUMN_MARGIN 15
|
2018-04-26 10:09:41 +00:00
|
|
|
#endif
|
|
|
|
|
2017-05-08 10:41:46 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
// Indicator that multiple values exist in child rows
|
|
|
|
#define ROW_MULT_ITEMS wxString( "< ... >" )
|
2017-05-08 10:41:46 +00:00
|
|
|
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
class FIELDS_EDITOR_GRID_DATA_MODEL : public wxGridTableBase
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
// The data model is fundamentally m_componentRefs X m_fieldNames.
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-05-22 11:50:57 +00:00
|
|
|
SCH_EDIT_FRAME* m_frame;
|
2018-04-17 10:34:48 +00:00
|
|
|
SCH_REFERENCE_LIST m_componentRefs;
|
2018-06-05 19:59:58 +00:00
|
|
|
bool m_edited;
|
2018-04-17 10:34:48 +00:00
|
|
|
std::vector<wxString> m_fieldNames;
|
2018-05-13 11:06:46 +00:00
|
|
|
int m_sortColumn;
|
|
|
|
bool m_sortAscending;
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
// However, the grid view can vary in two ways:
|
|
|
|
// 1) the componentRefs can be grouped into fewer rows
|
|
|
|
// 2) some columns can be hidden
|
|
|
|
//
|
|
|
|
// We handle (1) here (ie: a table row maps to a group, and the table is rebuilt
|
|
|
|
// when the groupings change), and we let the wxGrid handle (2) (ie: the number
|
|
|
|
// of columns is constant but are hidden/shown by the wxGrid control).
|
2017-05-02 17:51:02 +00:00
|
|
|
|
2018-05-12 22:04:11 +00:00
|
|
|
std::vector< DATA_MODEL_ROW > m_rows;
|
2017-12-05 12:51:09 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
// Data store
|
|
|
|
// A map of compID : fieldSet, where fieldSet is a map of fieldName : fieldValue
|
|
|
|
std::map< timestamp_t, std::map<wxString, wxString> > m_dataStore;
|
2017-05-03 06:24:45 +00:00
|
|
|
|
2018-05-13 11:06:46 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
public:
|
2018-05-22 11:50:57 +00:00
|
|
|
FIELDS_EDITOR_GRID_DATA_MODEL( SCH_EDIT_FRAME* aFrame, SCH_REFERENCE_LIST& aComponentList ) :
|
|
|
|
m_frame( aFrame ),
|
2018-06-04 17:48:17 +00:00
|
|
|
m_componentRefs( aComponentList ),
|
2018-06-05 19:59:58 +00:00
|
|
|
m_edited( false ),
|
2018-06-04 17:48:17 +00:00
|
|
|
m_sortAscending( false )
|
2018-04-17 10:34:48 +00:00
|
|
|
{
|
|
|
|
m_componentRefs.SplitReferences();
|
|
|
|
}
|
2018-03-09 01:44:20 +00:00
|
|
|
|
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
void AddColumn( const wxString& aFieldName )
|
2017-05-03 06:24:45 +00:00
|
|
|
{
|
2018-04-17 10:34:48 +00:00
|
|
|
m_fieldNames.push_back( aFieldName );
|
2017-05-03 06:24:45 +00:00
|
|
|
|
2018-04-17 14:05:15 +00:00
|
|
|
for( unsigned i = 0; i < m_componentRefs.GetCount(); ++i )
|
2018-04-17 10:34:48 +00:00
|
|
|
{
|
|
|
|
SCH_COMPONENT* comp = m_componentRefs[ i ].GetComp();
|
|
|
|
timestamp_t compID = comp->GetTimeStamp();
|
2017-05-03 06:24:45 +00:00
|
|
|
|
2018-05-22 11:50:57 +00:00
|
|
|
m_dataStore[ compID ][ aFieldName ] = comp->GetFieldText( aFieldName, m_frame );
|
2018-04-17 10:34:48 +00:00
|
|
|
}
|
2017-05-03 06:24:45 +00:00
|
|
|
}
|
|
|
|
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
int GetNumberRows() override { return m_rows.size(); }
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
// Columns are fieldNames + quantity column
|
|
|
|
int GetNumberCols() override { return m_fieldNames.size() + 1; }
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
wxString GetColLabelValue( int aCol ) override
|
|
|
|
{
|
|
|
|
if( aCol == QUANTITY_COLUMN )
|
|
|
|
return _T( "Qty" );
|
|
|
|
else
|
|
|
|
return m_fieldNames[ aCol ];
|
|
|
|
}
|
2017-05-08 10:41:46 +00:00
|
|
|
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
bool IsEmptyCell( int aRow, int aCol ) override
|
|
|
|
{
|
|
|
|
return false; // don't allow adjacent cell overflow, even if we are actually empty
|
|
|
|
}
|
2017-05-08 10:41:46 +00:00
|
|
|
|
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
wxString GetValue( int aRow, int aCol ) override
|
2017-05-08 10:41:46 +00:00
|
|
|
{
|
2018-05-13 11:06:46 +00:00
|
|
|
if( aCol == REFERENCE )
|
|
|
|
{
|
|
|
|
// Poor-man's tree controls
|
|
|
|
if( m_rows[ aRow ].m_Flag == GROUP_COLLAPSED )
|
|
|
|
return wxT( "> " ) + GetValue( m_rows[ aRow ], aCol );
|
|
|
|
else if (m_rows[ aRow ].m_Flag == GROUP_EXPANDED )
|
|
|
|
return wxT( "v " ) + GetValue( m_rows[ aRow ], aCol );
|
|
|
|
else if( m_rows[ aRow ].m_Flag == CHILD_ITEM )
|
|
|
|
return wxT( " " ) + GetValue( m_rows[ aRow ], aCol );
|
|
|
|
else
|
|
|
|
return wxT( " " ) + GetValue( m_rows[ aRow ], aCol );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return GetValue( m_rows[ aRow ], aCol );
|
2018-04-17 10:34:48 +00:00
|
|
|
}
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2018-05-19 15:25:28 +00:00
|
|
|
std::vector<SCH_REFERENCE> GetRowReferences( int aRow )
|
|
|
|
{
|
2018-06-12 18:15:04 +00:00
|
|
|
wxCHECK( aRow < (int)m_rows.size(), std::vector<SCH_REFERENCE>() );
|
2018-05-19 15:25:28 +00:00
|
|
|
return m_rows[ aRow ].m_Refs;
|
|
|
|
}
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2018-05-12 22:04:11 +00:00
|
|
|
wxString GetValue( DATA_MODEL_ROW& group, int aCol )
|
2018-04-17 10:34:48 +00:00
|
|
|
{
|
2018-05-13 11:06:46 +00:00
|
|
|
std::vector<SCH_REFERENCE> references;
|
|
|
|
wxString fieldValue;
|
2017-05-08 10:41:46 +00:00
|
|
|
|
2018-05-12 22:04:11 +00:00
|
|
|
for( const auto& ref : group.m_Refs )
|
2018-04-17 10:34:48 +00:00
|
|
|
{
|
|
|
|
if( aCol == REFERENCE || aCol == QUANTITY_COLUMN )
|
|
|
|
{
|
2018-05-13 11:06:46 +00:00
|
|
|
references.push_back( ref );
|
2018-04-17 10:34:48 +00:00
|
|
|
}
|
|
|
|
else // Other columns are either a single value or ROW_MULTI_ITEMS
|
|
|
|
{
|
|
|
|
timestamp_t compID = ref.GetComp()->GetTimeStamp();
|
|
|
|
|
2018-05-12 22:04:11 +00:00
|
|
|
if( &ref == &group.m_Refs.front() )
|
2018-04-17 10:34:48 +00:00
|
|
|
fieldValue = m_dataStore[ compID ][ m_fieldNames[ aCol ] ];
|
|
|
|
else if ( fieldValue != m_dataStore[ compID ][ m_fieldNames[ aCol ] ] )
|
|
|
|
return ROW_MULT_ITEMS;
|
|
|
|
}
|
|
|
|
}
|
2017-05-08 10:41:46 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
if( aCol == REFERENCE || aCol == QUANTITY_COLUMN )
|
|
|
|
{
|
|
|
|
// Remove duplicates (other units of multi-unit parts)
|
2018-05-13 11:06:46 +00:00
|
|
|
auto logicalEnd = std::unique( references.begin(), references.end(),
|
|
|
|
[]( const SCH_REFERENCE& l, const SCH_REFERENCE& r )
|
2018-05-11 09:32:54 +00:00
|
|
|
{
|
2018-05-13 11:06:46 +00:00
|
|
|
// If unannotated then we can't tell what units belong together
|
|
|
|
// so we have to leave them all
|
|
|
|
if( l.GetRefNumber() == wxT( "?" ) )
|
2018-05-11 09:32:54 +00:00
|
|
|
return false;
|
|
|
|
|
2018-05-13 11:06:46 +00:00
|
|
|
return( l.GetRef() == r.GetRef() && l.GetRefNumber() == r.GetRefNumber() );
|
2018-05-11 09:32:54 +00:00
|
|
|
} );
|
2018-05-13 11:06:46 +00:00
|
|
|
references.erase( logicalEnd, references.end() );
|
2018-04-17 10:34:48 +00:00
|
|
|
}
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
if( aCol == REFERENCE )
|
|
|
|
{
|
2018-05-13 11:06:46 +00:00
|
|
|
fieldValue = SCH_REFERENCE_LIST::Shorthand( references );
|
2018-04-17 10:34:48 +00:00
|
|
|
}
|
|
|
|
else if( aCol == QUANTITY_COLUMN )
|
|
|
|
{
|
2018-05-13 11:06:46 +00:00
|
|
|
fieldValue = wxString::Format( wxT( "%d" ), ( int )references.size() );
|
2018-04-17 10:34:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return fieldValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SetValue( int aRow, int aCol, const wxString &aValue ) override
|
2017-05-08 10:41:46 +00:00
|
|
|
{
|
2018-04-17 10:34:48 +00:00
|
|
|
if( aCol == REFERENCE || aCol == QUANTITY_COLUMN )
|
|
|
|
return; // Can't modify references or quantity
|
|
|
|
|
2018-05-12 22:04:11 +00:00
|
|
|
DATA_MODEL_ROW& rowGroup = m_rows[ aRow ];
|
2018-04-17 10:34:48 +00:00
|
|
|
wxString fieldName = m_fieldNames[ aCol ];
|
|
|
|
|
2018-05-12 22:04:11 +00:00
|
|
|
for( const auto& ref : rowGroup.m_Refs )
|
2018-04-17 10:34:48 +00:00
|
|
|
m_dataStore[ ref.GetComp()->GetTimeStamp() ][ fieldName ] = aValue;
|
2018-06-05 19:59:58 +00:00
|
|
|
|
|
|
|
m_edited = true;
|
2017-05-08 10:41:46 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2018-05-12 22:04:11 +00:00
|
|
|
static bool cmp( const DATA_MODEL_ROW& lhGroup, const DATA_MODEL_ROW& rhGroup,
|
2018-04-17 10:34:48 +00:00
|
|
|
FIELDS_EDITOR_GRID_DATA_MODEL* dataModel, int sortCol, bool ascending )
|
|
|
|
{
|
|
|
|
// Empty rows always go to the bottom, whether ascending or descending
|
2018-05-12 22:04:11 +00:00
|
|
|
if( lhGroup.m_Refs.size() == 0 )
|
2018-04-17 10:34:48 +00:00
|
|
|
return true;
|
2018-05-12 22:04:11 +00:00
|
|
|
else if( rhGroup.m_Refs.size() == 0 )
|
2018-04-17 10:34:48 +00:00
|
|
|
return false;
|
2017-04-18 14:10:17 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
bool retVal;
|
2017-04-18 14:10:17 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
// Primary sort key is sortCol; secondary is always REFERENCE (column 0)
|
2017-12-29 15:44:33 +00:00
|
|
|
|
2018-05-12 22:04:11 +00:00
|
|
|
wxString lhs = dataModel->GetValue( (DATA_MODEL_ROW&) lhGroup, sortCol );
|
|
|
|
wxString rhs = dataModel->GetValue( (DATA_MODEL_ROW&) rhGroup, sortCol );
|
2017-05-08 10:41:46 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
if( lhs == rhs || sortCol == REFERENCE )
|
|
|
|
{
|
2018-05-12 22:04:11 +00:00
|
|
|
wxString lhRef = lhGroup.m_Refs[ 0 ].GetRef() + lhGroup.m_Refs[ 0 ].GetRefNumber();
|
|
|
|
wxString rhRef = rhGroup.m_Refs[ 0 ].GetRef() + rhGroup.m_Refs[ 0 ].GetRefNumber();
|
2018-04-17 10:34:48 +00:00
|
|
|
retVal = RefDesStringCompare( lhRef, rhRef ) < 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
retVal = ValueStringCompare( lhs, rhs ) < 0;
|
2017-04-18 14:10:17 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
if( ascending )
|
|
|
|
return retVal;
|
|
|
|
else
|
|
|
|
return !retVal;
|
|
|
|
}
|
2017-04-02 12:09:01 +00:00
|
|
|
|
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
void Sort( int aColumn, bool ascending )
|
|
|
|
{
|
|
|
|
if( aColumn < 0 )
|
|
|
|
aColumn = 0;
|
|
|
|
|
2018-05-13 11:06:46 +00:00
|
|
|
m_sortColumn = aColumn;
|
|
|
|
m_sortAscending = ascending;
|
|
|
|
|
|
|
|
CollapseForSort();
|
2018-05-12 22:04:11 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
std::sort( m_rows.begin(), m_rows.end(),
|
2018-05-13 11:06:46 +00:00
|
|
|
[ this ]( const DATA_MODEL_ROW& lhs, const DATA_MODEL_ROW& rhs ) -> bool
|
2018-04-17 10:34:48 +00:00
|
|
|
{
|
2018-05-13 11:06:46 +00:00
|
|
|
return cmp( lhs, rhs, this, m_sortColumn, m_sortAscending );
|
2018-04-17 10:34:48 +00:00
|
|
|
} );
|
2018-05-13 11:06:46 +00:00
|
|
|
|
|
|
|
ExpandAfterSort();
|
2018-04-17 10:34:48 +00:00
|
|
|
}
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2017-04-18 14:10:17 +00:00
|
|
|
|
2018-05-12 22:04:11 +00:00
|
|
|
bool unitMatch( const SCH_REFERENCE& lhRef, const SCH_REFERENCE& rhRef )
|
2017-05-08 10:41:46 +00:00
|
|
|
{
|
2018-05-12 22:04:11 +00:00
|
|
|
// If items are unannotated then we can't tell if they're units of the same
|
|
|
|
// component or not
|
2018-05-13 20:47:47 +00:00
|
|
|
if( lhRef.GetRefNumber() == wxT( "?" ) )
|
2018-04-17 10:34:48 +00:00
|
|
|
return false;
|
2017-04-18 14:10:17 +00:00
|
|
|
|
2018-05-12 22:04:11 +00:00
|
|
|
return ( lhRef.GetRef() == rhRef.GetRef() && lhRef.GetRefNumber() == rhRef.GetRefNumber() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool groupMatch( const SCH_REFERENCE& lhRef, const SCH_REFERENCE& rhRef,
|
|
|
|
wxDataViewListCtrl* fieldsCtrl )
|
|
|
|
{
|
2018-04-17 10:34:48 +00:00
|
|
|
bool matchFound = false;
|
2017-04-18 14:10:17 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
// First check the reference column. This can be done directly out of the
|
|
|
|
// SCH_REFERENCEs as the references can't be edited in the grid.
|
|
|
|
if( fieldsCtrl->GetToggleValue( REFERENCE, GROUP_BY_COLUMN ) )
|
|
|
|
{
|
|
|
|
// if we're grouping by reference, then only the prefix must match
|
|
|
|
if( lhRef.GetRef() != rhRef.GetRef() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
matchFound = true;
|
|
|
|
}
|
2017-04-18 14:10:17 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
timestamp_t lhRefID = lhRef.GetComp()->GetTimeStamp();
|
|
|
|
timestamp_t rhRefID = rhRef.GetComp()->GetTimeStamp();
|
|
|
|
|
|
|
|
// Now check all the other columns. This must be done out of the dataStore
|
|
|
|
// for the refresh button to work after editing.
|
|
|
|
for( int i = REFERENCE + 1; i < fieldsCtrl->GetItemCount(); ++i )
|
2017-05-08 10:41:46 +00:00
|
|
|
{
|
2018-04-17 10:34:48 +00:00
|
|
|
if( !fieldsCtrl->GetToggleValue( i, GROUP_BY_COLUMN ) )
|
|
|
|
continue;
|
2017-04-18 14:10:17 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
wxString fieldName = fieldsCtrl->GetTextValue( i, FIELD_NAME_COLUMN );
|
2017-04-18 14:10:17 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
if( m_dataStore[ lhRefID ][ fieldName ] != m_dataStore[ rhRefID ][ fieldName ] )
|
|
|
|
return false;
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
matchFound = true;
|
|
|
|
}
|
2017-04-18 14:10:17 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
return matchFound;
|
2017-05-08 10:41:46 +00:00
|
|
|
}
|
2017-04-16 06:43:59 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
|
|
|
|
void RebuildRows( wxCheckBox* groupComponentsBox, wxDataViewListCtrl* fieldsCtrl )
|
2017-05-08 10:41:46 +00:00
|
|
|
{
|
2018-04-17 19:23:26 +00:00
|
|
|
if ( GetView() )
|
|
|
|
{
|
|
|
|
// Commit any pending in-place edits before the row gets moved out from under
|
|
|
|
// the editor.
|
|
|
|
GetView()->DisableCellEditControl();
|
|
|
|
|
|
|
|
wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, m_rows.size() );
|
|
|
|
GetView()->ProcessTableMessage( msg );
|
|
|
|
}
|
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
m_rows.clear();
|
2017-04-18 14:10:17 +00:00
|
|
|
|
2018-04-17 14:05:15 +00:00
|
|
|
for( unsigned i = 0; i < m_componentRefs.GetCount(); ++i )
|
2018-04-17 10:34:48 +00:00
|
|
|
{
|
2018-05-12 22:04:11 +00:00
|
|
|
SCH_REFERENCE ref = m_componentRefs[ i ];
|
2018-04-17 10:34:48 +00:00
|
|
|
bool matchFound = false;
|
|
|
|
|
2018-05-12 22:04:11 +00:00
|
|
|
// See if we already have a row which this component fits into
|
|
|
|
for( auto& row : m_rows )
|
2018-04-17 10:34:48 +00:00
|
|
|
{
|
2018-05-12 22:04:11 +00:00
|
|
|
// all group members must have identical refs so just use the first one
|
|
|
|
SCH_REFERENCE rowRef = row.m_Refs[ 0 ];
|
|
|
|
|
|
|
|
if( unitMatch( ref, rowRef ) )
|
2018-04-17 10:34:48 +00:00
|
|
|
{
|
|
|
|
matchFound = true;
|
2018-05-12 22:04:11 +00:00
|
|
|
row.m_Refs.push_back( ref );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (groupComponentsBox->GetValue() && groupMatch( ref, rowRef, fieldsCtrl ) )
|
|
|
|
{
|
|
|
|
matchFound = true;
|
|
|
|
row.m_Refs.push_back( ref );
|
|
|
|
row.m_Flag = GROUP_COLLAPSED;
|
2018-04-17 10:34:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !matchFound )
|
2018-05-12 22:04:11 +00:00
|
|
|
m_rows.push_back( DATA_MODEL_ROW( ref, GROUP_SINGLETON ) );
|
2018-04-17 10:34:48 +00:00
|
|
|
}
|
|
|
|
|
2018-04-17 19:23:26 +00:00
|
|
|
if ( GetView() )
|
|
|
|
{
|
|
|
|
wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_rows.size() );
|
|
|
|
GetView()->ProcessTableMessage( msg );
|
|
|
|
}
|
2017-05-08 10:41:46 +00:00
|
|
|
}
|
2017-04-18 14:10:17 +00:00
|
|
|
|
|
|
|
|
2018-05-12 22:04:11 +00:00
|
|
|
void ExpandRow( int aRow )
|
|
|
|
{
|
|
|
|
std::vector<DATA_MODEL_ROW> children;
|
|
|
|
|
|
|
|
for( auto& ref : m_rows[ aRow ].m_Refs )
|
|
|
|
{
|
|
|
|
bool matchFound = false;
|
|
|
|
|
|
|
|
// See if we already have a child group which this component fits into
|
|
|
|
for( auto& child : children )
|
|
|
|
{
|
|
|
|
// group members are by definition all matching, so just check
|
|
|
|
// against the first member
|
|
|
|
if( unitMatch( ref, child.m_Refs[ 0 ] ) )
|
|
|
|
{
|
|
|
|
matchFound = true;
|
|
|
|
child.m_Refs.push_back( ref );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !matchFound )
|
|
|
|
children.push_back( DATA_MODEL_ROW( ref, CHILD_ITEM ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( children.size() < 2 )
|
|
|
|
return;
|
|
|
|
|
2018-05-13 11:06:46 +00:00
|
|
|
std::sort( children.begin(), children.end(),
|
|
|
|
[ this ] ( const DATA_MODEL_ROW& lhs, const DATA_MODEL_ROW& rhs ) -> bool
|
|
|
|
{
|
|
|
|
return cmp( lhs, rhs, this, m_sortColumn, m_sortAscending );
|
|
|
|
} );
|
|
|
|
|
2018-05-12 22:04:11 +00:00
|
|
|
m_rows[ aRow ].m_Flag = GROUP_EXPANDED;
|
|
|
|
m_rows.insert( m_rows.begin() + aRow + 1, children.begin(), children.end() );
|
|
|
|
|
|
|
|
wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, aRow, children.size() );
|
|
|
|
GetView()->ProcessTableMessage( msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CollapseRow( int aRow )
|
|
|
|
{
|
|
|
|
auto firstChild = m_rows.begin() + aRow + 1;
|
|
|
|
auto afterLastChild = firstChild;
|
|
|
|
int deleted = 0;
|
|
|
|
|
|
|
|
while( afterLastChild != m_rows.end() && afterLastChild->m_Flag == CHILD_ITEM )
|
|
|
|
{
|
|
|
|
deleted++;
|
|
|
|
afterLastChild++;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_rows[ aRow ].m_Flag = GROUP_COLLAPSED;
|
|
|
|
m_rows.erase( firstChild, afterLastChild );
|
|
|
|
|
|
|
|
wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aRow + 1, deleted );
|
|
|
|
GetView()->ProcessTableMessage( msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ExpandCollapseRow( int aRow )
|
|
|
|
{
|
|
|
|
DATA_MODEL_ROW& group = m_rows[ aRow ];
|
|
|
|
|
|
|
|
if( group.m_Flag == GROUP_COLLAPSED )
|
|
|
|
ExpandRow( aRow );
|
|
|
|
else if( group.m_Flag == GROUP_EXPANDED )
|
|
|
|
CollapseRow( aRow );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-13 11:06:46 +00:00
|
|
|
void CollapseForSort()
|
2018-05-12 22:04:11 +00:00
|
|
|
{
|
2018-05-13 06:56:17 +00:00
|
|
|
for( size_t i = 0; i < m_rows.size(); ++i )
|
2018-05-12 22:04:11 +00:00
|
|
|
{
|
|
|
|
if( m_rows[ i ].m_Flag == GROUP_EXPANDED )
|
2018-05-13 11:06:46 +00:00
|
|
|
{
|
2018-05-12 22:04:11 +00:00
|
|
|
CollapseRow( i );
|
2018-05-13 11:06:46 +00:00
|
|
|
m_rows[ i ].m_Flag = GROUP_COLLAPSED_DURING_SORT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ExpandAfterSort()
|
|
|
|
{
|
2018-05-16 16:14:06 +00:00
|
|
|
for( size_t i = 0; i < m_rows.size(); ++i )
|
2018-05-13 11:06:46 +00:00
|
|
|
{
|
|
|
|
if( m_rows[ i ].m_Flag == GROUP_COLLAPSED_DURING_SORT )
|
|
|
|
ExpandRow( i );
|
2018-05-12 22:04:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-22 11:50:57 +00:00
|
|
|
void ApplyData()
|
2018-04-17 10:34:48 +00:00
|
|
|
{
|
2018-04-17 14:05:15 +00:00
|
|
|
for( unsigned i = 0; i < m_componentRefs.GetCount(); ++i )
|
2018-04-17 10:34:48 +00:00
|
|
|
{
|
|
|
|
SCH_COMPONENT* comp = m_componentRefs[ i ].GetComp();
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-05-22 11:50:57 +00:00
|
|
|
m_frame->SetCurrentSheet( m_componentRefs[ i ].GetSheetPath() );
|
|
|
|
m_frame->SaveCopyInUndoList( comp, UR_CHANGED, true );
|
2017-05-08 10:41:46 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
std::map<wxString, wxString>& fieldStore = m_dataStore[ comp->GetTimeStamp() ];
|
|
|
|
|
2018-05-23 20:34:56 +00:00
|
|
|
for( std::pair<wxString, wxString> srcData : fieldStore )
|
2018-04-17 10:34:48 +00:00
|
|
|
{
|
2018-05-23 20:34:56 +00:00
|
|
|
wxString srcName = srcData.first;
|
|
|
|
wxString srcValue = srcData.second;
|
|
|
|
SCH_FIELD* destField = comp->FindField( srcName );
|
2018-04-19 17:55:16 +00:00
|
|
|
|
2018-05-29 21:46:13 +00:00
|
|
|
if( !destField && !srcValue.IsEmpty() )
|
2018-05-23 20:34:56 +00:00
|
|
|
destField = comp->AddField( SCH_FIELD( wxPoint( 0, 0 ), -1, comp, srcName ) );
|
2018-04-19 17:55:16 +00:00
|
|
|
|
2018-05-23 20:34:56 +00:00
|
|
|
if( destField )
|
|
|
|
destField->SetText( srcValue );
|
2018-04-17 10:34:48 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-05 19:59:58 +00:00
|
|
|
|
|
|
|
m_edited = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsEdited()
|
|
|
|
{
|
|
|
|
return m_edited;
|
2018-04-17 10:34:48 +00:00
|
|
|
}
|
|
|
|
};
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
DIALOG_FIELDS_EDITOR_GLOBAL::DIALOG_FIELDS_EDITOR_GLOBAL( SCH_EDIT_FRAME* parent ) :
|
|
|
|
DIALOG_FIELDS_EDITOR_GLOBAL_BASE( parent ),
|
2018-05-22 11:50:57 +00:00
|
|
|
m_config( Kiface().KifaceSettings() ),
|
2018-04-17 10:34:48 +00:00
|
|
|
m_parent( parent )
|
2017-04-02 12:09:01 +00:00
|
|
|
{
|
2018-04-17 10:34:48 +00:00
|
|
|
// Get all components from the list of schematic sheets
|
|
|
|
SCH_SHEET_LIST sheets( g_RootSheet );
|
|
|
|
sheets.GetComponents( m_componentRefs, false );
|
|
|
|
|
|
|
|
m_bRefresh->SetBitmap( KiBitmap( refresh_xpm ) );
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-04-23 17:23:09 +00:00
|
|
|
m_fieldsCtrl->AppendTextColumn( _( "Field" ), wxDATAVIEW_CELL_INERT, 0, wxALIGN_LEFT, 0 );
|
|
|
|
m_fieldsCtrl->AppendToggleColumn( _( "Show" ), wxDATAVIEW_CELL_ACTIVATABLE, 0, wxALIGN_CENTER, 0 );
|
|
|
|
m_fieldsCtrl->AppendToggleColumn( _( "Group By" ), wxDATAVIEW_CELL_ACTIVATABLE, 0, wxALIGN_CENTER, 0 );
|
|
|
|
|
2018-04-26 17:00:25 +00:00
|
|
|
// SetWidth( wxCOL_WIDTH_AUTOSIZE ) fails here on GTK, so we calculate the title sizes and
|
|
|
|
// set the column widths ourselves.
|
2018-04-26 10:09:41 +00:00
|
|
|
auto column = m_fieldsCtrl->GetColumn( SHOW_FIELD_COLUMN );
|
|
|
|
m_showColWidth = GetTextSize( column->GetTitle(), m_fieldsCtrl ).x + CHECKBOX_COLUMN_MARGIN;
|
|
|
|
column->SetWidth( m_showColWidth );
|
|
|
|
|
|
|
|
column = m_fieldsCtrl->GetColumn( GROUP_BY_COLUMN );
|
|
|
|
m_groupByColWidth = GetTextSize( column->GetTitle(), m_fieldsCtrl ).x + CHECKBOX_COLUMN_MARGIN;
|
|
|
|
column->SetWidth( m_groupByColWidth );
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
// The fact that we're a list should keep the control from reserving space for the
|
|
|
|
// expander buttons... but it doesn't. Fix by forcing the indent to 0.
|
|
|
|
m_fieldsCtrl->SetIndent( 0 );
|
|
|
|
|
2018-05-22 11:50:57 +00:00
|
|
|
m_dataModel = new FIELDS_EDITOR_GRID_DATA_MODEL( m_parent, m_componentRefs );
|
2018-04-17 10:34:48 +00:00
|
|
|
|
|
|
|
LoadFieldNames(); // loads rows into m_fieldsCtrl and columns into m_dataModel
|
|
|
|
|
2018-04-26 10:09:41 +00:00
|
|
|
// Now that the fields are loaded we can set the initial location of the splitter
|
2018-04-26 17:00:25 +00:00
|
|
|
// based on the list width. Again, SetWidth( wxCOL_WIDTH_AUTOSIZE ) fails us on GTK.
|
|
|
|
int nameColWidth = 0;
|
2018-04-29 13:45:11 +00:00
|
|
|
|
|
|
|
for( int row = 0; row < m_fieldsCtrl->GetItemCount(); ++row )
|
2018-04-26 17:00:25 +00:00
|
|
|
{
|
|
|
|
const wxString& fieldName = m_fieldsCtrl->GetTextValue( row, FIELD_NAME_COLUMN );
|
|
|
|
nameColWidth = std::max( nameColWidth, GetTextSize( fieldName, m_fieldsCtrl ).x );
|
|
|
|
}
|
2018-04-29 13:45:11 +00:00
|
|
|
|
2018-04-26 17:00:25 +00:00
|
|
|
m_fieldsCtrl->GetColumn( FIELD_NAME_COLUMN )->SetWidth( nameColWidth );
|
|
|
|
m_splitter1->SetSashPosition( nameColWidth + m_showColWidth + m_groupByColWidth + 40 );
|
2018-04-26 10:09:41 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
m_dataModel->RebuildRows( m_groupComponentsBox, m_fieldsCtrl );
|
|
|
|
m_dataModel->Sort( 0, true );
|
|
|
|
|
|
|
|
m_grid->UseNativeColHeader( true );
|
|
|
|
m_grid->SetTable( m_dataModel, true );
|
|
|
|
|
2018-05-22 18:23:50 +00:00
|
|
|
// sync m_grid's column visiblities to Show checkboxes in m_fieldsCtrl
|
|
|
|
for( int i = 0; i < m_fieldsCtrl->GetItemCount(); ++i )
|
|
|
|
{
|
|
|
|
if( m_fieldsCtrl->GetToggleValue( i, 1 ) )
|
|
|
|
m_grid->ShowCol( i );
|
|
|
|
else
|
|
|
|
m_grid->HideCol( i );
|
|
|
|
}
|
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
// add Cut, Copy, and Paste to wxGrid
|
|
|
|
m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
|
|
|
|
|
|
|
|
// give a bit more room for editing
|
|
|
|
m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 2 );
|
|
|
|
|
2018-05-11 11:32:12 +00:00
|
|
|
// set reference column attributes
|
|
|
|
wxGridCellAttr* attr = new wxGridCellAttr;
|
|
|
|
attr->SetReadOnly();
|
|
|
|
m_grid->SetColAttr( 0, attr );
|
|
|
|
m_grid->SetColMinimalWidth( 0, 100 );
|
|
|
|
|
|
|
|
// set quantities column attributes
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetReadOnly();
|
|
|
|
m_grid->SetColAttr( m_dataModel->GetColsCount() - 1, attr );
|
|
|
|
m_grid->SetColFormatNumber( m_dataModel->GetColsCount() - 1 );
|
|
|
|
m_grid->SetColMinimalWidth( m_dataModel->GetColsCount() - 1, 50 );
|
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
m_grid->AutoSizeColumns( false );
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
m_grid->SetGridCursor( 0, 1 );
|
|
|
|
m_grid->SetFocus();
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
m_sdbSizer1OK->SetDefault();
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-04-18 18:30:37 +00:00
|
|
|
FinishDialogSettings();
|
|
|
|
SetSizeInDU( 600, 300 );
|
2018-04-17 10:34:48 +00:00
|
|
|
Center();
|
|
|
|
|
|
|
|
// Connect Events
|
|
|
|
m_grid->Connect( wxEVT_GRID_COL_SORT, wxGridEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL::OnColSort ), NULL, this );
|
2017-04-02 12:09:01 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
DIALOG_FIELDS_EDITOR_GLOBAL::~DIALOG_FIELDS_EDITOR_GLOBAL()
|
2017-04-02 12:09:01 +00:00
|
|
|
{
|
2018-04-17 10:34:48 +00:00
|
|
|
// Disconnect Events
|
|
|
|
m_grid->Disconnect( wxEVT_GRID_COL_SORT, wxGridEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL::OnColSort ), NULL, this );
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
// Delete the GRID_TRICKS.
|
|
|
|
m_grid->PopEventHandler( true );
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
// we gave ownership of m_dataModel to the wxGrid...
|
2017-04-02 12:09:01 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
bool DIALOG_FIELDS_EDITOR_GLOBAL::TransferDataFromWindow()
|
2017-04-02 12:09:01 +00:00
|
|
|
{
|
2018-04-17 10:34:48 +00:00
|
|
|
// Commit any pending in-place edits and close the editor
|
|
|
|
m_grid->DisableCellEditControl();
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
if( !wxDialog::TransferDataFromWindow() )
|
|
|
|
return false;
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
SCH_SHEET_PATH currentSheet = m_parent->GetCurrentSheet();
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-05-22 11:50:57 +00:00
|
|
|
m_dataModel->ApplyData();
|
2018-04-17 10:34:48 +00:00
|
|
|
m_parent->OnModify();
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
// Reset the view to where we left the user
|
|
|
|
m_parent->SetCurrentSheet( currentSheet );
|
|
|
|
m_parent->Refresh();
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
return true;
|
2017-04-02 12:09:01 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2018-05-22 11:50:57 +00:00
|
|
|
void DIALOG_FIELDS_EDITOR_GLOBAL::AddField( const wxString& aName,
|
2018-05-19 15:47:39 +00:00
|
|
|
bool defaultShow, bool defaultSortBy )
|
2017-04-02 12:09:01 +00:00
|
|
|
{
|
2018-05-22 11:50:57 +00:00
|
|
|
m_dataModel->AddColumn( aName );
|
2018-04-17 10:34:48 +00:00
|
|
|
|
2018-05-22 11:50:57 +00:00
|
|
|
wxVector<wxVariant> fieldsCtrlRow;
|
2018-04-17 10:34:48 +00:00
|
|
|
|
2018-05-19 15:47:39 +00:00
|
|
|
m_config->Read("SymbolFieldEditor/Show/" + aName, &defaultShow);
|
|
|
|
m_config->Read("SymbolFieldEditor/GroupBy/" + aName, &defaultSortBy);
|
|
|
|
|
2018-05-22 11:50:57 +00:00
|
|
|
fieldsCtrlRow.push_back( wxVariant( aName ) );
|
2018-05-19 15:47:39 +00:00
|
|
|
fieldsCtrlRow.push_back( wxVariant( defaultShow ) );
|
|
|
|
fieldsCtrlRow.push_back( wxVariant( defaultSortBy ) );
|
2018-04-17 10:34:48 +00:00
|
|
|
|
2018-05-22 11:50:57 +00:00
|
|
|
m_fieldsCtrl->AppendItem( fieldsCtrlRow );
|
2017-04-02 12:09:01 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
/**
|
|
|
|
* Constructs the rows of m_fieldsCtrl and the columns of m_dataModel from a union of all
|
|
|
|
* field names in use.
|
|
|
|
*/
|
|
|
|
void DIALOG_FIELDS_EDITOR_GLOBAL::LoadFieldNames()
|
2017-04-02 12:09:01 +00:00
|
|
|
{
|
2018-05-19 15:47:39 +00:00
|
|
|
std::set<wxString> userFieldNames;
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-04-17 14:05:15 +00:00
|
|
|
for( unsigned i = 0; i < m_componentRefs.GetCount(); ++i )
|
2018-04-17 10:34:48 +00:00
|
|
|
{
|
|
|
|
SCH_COMPONENT* comp = m_componentRefs[ i ].GetComp();
|
|
|
|
|
|
|
|
for( int j = MANDATORY_FIELDS; j < comp->GetFieldCount(); ++j )
|
2018-05-19 15:47:39 +00:00
|
|
|
userFieldNames.insert( comp->GetField( j )->GetName() );
|
2018-04-17 10:34:48 +00:00
|
|
|
}
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-05-19 15:47:39 +00:00
|
|
|
AddField( _( "Reference" ), true, true );
|
|
|
|
AddField( _( "Value" ), true, true );
|
|
|
|
AddField( _( "Footprint" ), true, true );
|
|
|
|
AddField( _( "Datasheet" ), true, false );
|
2018-04-17 10:34:48 +00:00
|
|
|
|
2018-05-19 15:47:39 +00:00
|
|
|
for( auto fieldName : userFieldNames )
|
|
|
|
AddField( fieldName, true, false );
|
|
|
|
|
|
|
|
for( auto templateFieldName : m_parent->GetTemplateFieldNames() )
|
|
|
|
AddField( templateFieldName.m_Name, false, false );
|
2018-04-17 10:34:48 +00:00
|
|
|
}
|
2017-04-02 12:09:01 +00:00
|
|
|
|
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
void DIALOG_FIELDS_EDITOR_GLOBAL::OnColumnItemToggled( wxDataViewEvent& event )
|
|
|
|
{
|
|
|
|
wxDataViewItem item = event.GetItem();
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
int row = m_fieldsCtrl->ItemToRow( item );
|
|
|
|
int col = event.GetColumn();
|
2017-04-02 12:09:01 +00:00
|
|
|
|
|
|
|
switch ( col )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
2017-11-03 08:41:48 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
case SHOW_FIELD_COLUMN:
|
2018-05-19 15:47:39 +00:00
|
|
|
{
|
|
|
|
bool value = m_fieldsCtrl->GetToggleValue( row, col );
|
|
|
|
wxString fieldName = m_fieldsCtrl->GetTextValue( row, FIELD_NAME_COLUMN );
|
|
|
|
m_config->Write( "SymbolFieldEditor/Show/" + fieldName, value );
|
|
|
|
|
|
|
|
if( value )
|
2018-04-17 10:34:48 +00:00
|
|
|
m_grid->ShowCol( row );
|
2017-04-02 12:09:01 +00:00
|
|
|
else
|
2018-04-17 10:34:48 +00:00
|
|
|
m_grid->HideCol( row ); // grid's columns map to fieldsCtrl's rows
|
2017-04-02 12:09:01 +00:00
|
|
|
break;
|
2018-05-19 15:47:39 +00:00
|
|
|
}
|
2017-11-03 08:41:48 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
case GROUP_BY_COLUMN:
|
2018-05-19 15:47:39 +00:00
|
|
|
{
|
|
|
|
bool value = m_fieldsCtrl->GetToggleValue( row, col );
|
|
|
|
wxString fieldName = m_fieldsCtrl->GetTextValue( row, FIELD_NAME_COLUMN );
|
|
|
|
m_config->Write( "SymbolFieldEditor/GroupBy/" + fieldName, value );
|
2018-04-17 10:34:48 +00:00
|
|
|
m_dataModel->RebuildRows( m_groupComponentsBox, m_fieldsCtrl );
|
|
|
|
m_dataModel->Sort( m_grid->GetSortingColumn(), m_grid->IsSortOrderAscending() );
|
2018-05-19 15:47:39 +00:00
|
|
|
m_grid->ForceRefresh();
|
2017-05-08 10:41:46 +00:00
|
|
|
break;
|
2017-04-02 12:09:01 +00:00
|
|
|
}
|
2018-05-19 15:47:39 +00:00
|
|
|
}
|
2017-04-02 12:09:01 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2018-02-09 16:35:45 +00:00
|
|
|
void DIALOG_FIELDS_EDITOR_GLOBAL::OnGroupComponentsToggled( wxCommandEvent& event )
|
2017-04-02 12:09:01 +00:00
|
|
|
{
|
2018-04-17 10:34:48 +00:00
|
|
|
m_dataModel->RebuildRows( m_groupComponentsBox, m_fieldsCtrl );
|
|
|
|
m_dataModel->Sort( m_grid->GetSortingColumn(), m_grid->IsSortOrderAscending() );
|
|
|
|
m_grid->ForceRefresh();
|
2017-04-18 09:25:02 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
void DIALOG_FIELDS_EDITOR_GLOBAL::OnColSort( wxGridEvent& aEvent )
|
2017-04-18 09:25:02 +00:00
|
|
|
{
|
2018-04-17 10:34:48 +00:00
|
|
|
int sortCol = aEvent.GetCol();
|
|
|
|
bool ascending;
|
|
|
|
|
|
|
|
// This is bonkers, but wxWidgets doesn't tell us ascending/descending in the
|
|
|
|
// event, and if we ask it will give us pre-event info.
|
|
|
|
if( m_grid->IsSortingBy( sortCol ) )
|
|
|
|
// same column; invert ascending
|
|
|
|
ascending = !m_grid->IsSortOrderAscending();
|
|
|
|
else
|
|
|
|
// different column; start with ascending
|
|
|
|
ascending = true;
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
m_dataModel->Sort( sortCol, ascending );
|
2017-04-02 12:09:01 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
void DIALOG_FIELDS_EDITOR_GLOBAL::OnTableValueChanged( wxGridEvent& event )
|
2017-04-02 12:09:01 +00:00
|
|
|
{
|
2018-04-17 10:34:48 +00:00
|
|
|
m_grid->ForceRefresh();
|
2017-04-02 12:09:01 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2018-02-09 16:35:45 +00:00
|
|
|
void DIALOG_FIELDS_EDITOR_GLOBAL::OnRegroupComponents( wxCommandEvent& event )
|
2017-04-02 12:09:01 +00:00
|
|
|
{
|
2018-04-17 10:34:48 +00:00
|
|
|
m_dataModel->RebuildRows( m_groupComponentsBox, m_fieldsCtrl );
|
|
|
|
m_dataModel->Sort( m_grid->GetSortingColumn(), m_grid->IsSortOrderAscending() );
|
|
|
|
m_grid->ForceRefresh();
|
2017-04-02 12:09:01 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 08:41:48 +00:00
|
|
|
|
2018-05-12 22:04:11 +00:00
|
|
|
void DIALOG_FIELDS_EDITOR_GLOBAL::OnTableCellClick( wxGridEvent& event )
|
|
|
|
{
|
|
|
|
if( event.GetCol() == REFERENCE )
|
2018-05-19 15:25:28 +00:00
|
|
|
{
|
|
|
|
m_dataModel->ExpandCollapseRow( event.GetRow() );
|
|
|
|
std::vector<SCH_REFERENCE> refs = m_dataModel->GetRowReferences( event.GetRow() );
|
|
|
|
|
|
|
|
// Focus eeschema view on the component selected in the dialog
|
|
|
|
if( refs.size() == 1 )
|
|
|
|
{
|
|
|
|
m_parent->FindComponentAndItem( refs[0].GetRef() + refs[0].GetRefNumber(),
|
|
|
|
true, FIND_COMPONENT_ONLY, wxEmptyString, false );
|
|
|
|
}
|
|
|
|
}
|
2018-05-12 22:04:11 +00:00
|
|
|
else
|
2018-05-19 15:25:28 +00:00
|
|
|
{
|
2018-05-12 22:04:11 +00:00
|
|
|
event.Skip();
|
2018-05-19 15:25:28 +00:00
|
|
|
}
|
2018-05-12 22:04:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
void DIALOG_FIELDS_EDITOR_GLOBAL::OnTableItemContextMenu( wxGridEvent& event )
|
2017-04-25 02:55:49 +00:00
|
|
|
{
|
|
|
|
/* TODO
|
2018-04-17 10:34:48 +00:00
|
|
|
* - Option to select footprint if FOOTPRINT column selected
|
2017-04-25 02:55:49 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
2017-06-07 16:43:28 +00:00
|
|
|
|
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
void DIALOG_FIELDS_EDITOR_GLOBAL::OnSizeFieldList( wxSizeEvent& event )
|
2017-04-25 02:55:49 +00:00
|
|
|
{
|
2018-04-23 17:23:09 +00:00
|
|
|
int nameColWidth = event.GetSize().GetX() - m_showColWidth - m_groupByColWidth - 8;
|
2018-04-17 10:34:48 +00:00
|
|
|
|
2018-05-04 14:43:59 +00:00
|
|
|
// GTK loses its head and messes these up when resizing the splitter bar:
|
2018-04-23 17:23:09 +00:00
|
|
|
m_fieldsCtrl->GetColumn( 1 )->SetWidth( m_showColWidth );
|
|
|
|
m_fieldsCtrl->GetColumn( 2 )->SetWidth( m_groupByColWidth );
|
2018-04-17 10:34:48 +00:00
|
|
|
|
2018-04-23 17:23:09 +00:00
|
|
|
m_fieldsCtrl->GetColumn( 0 )->SetWidth( nameColWidth );
|
2017-04-25 02:55:49 +00:00
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
2018-04-19 22:13:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_FIELDS_EDITOR_GLOBAL::OnSaveAndContinue( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
if( TransferDataFromWindow() )
|
|
|
|
{
|
|
|
|
wxCommandEvent dummyEvent;
|
|
|
|
m_parent->OnSaveProject( dummyEvent );
|
|
|
|
}
|
|
|
|
}
|
2018-06-05 19:59:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_FIELDS_EDITOR_GLOBAL::OnCancel( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_FIELDS_EDITOR_GLOBAL::OnClose( wxCloseEvent& event )
|
|
|
|
{
|
|
|
|
// Commit any pending in-place edits and close the editor
|
|
|
|
m_grid->DisableCellEditControl();
|
|
|
|
|
|
|
|
if( m_dataModel->IsEdited() )
|
|
|
|
{
|
|
|
|
switch( DisplayExitDialog( this, wxEmptyString ) )
|
|
|
|
{
|
|
|
|
case wxID_CANCEL:
|
|
|
|
event.Veto();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wxID_YES:
|
|
|
|
if( TransferDataFromWindow() )
|
|
|
|
event.Skip();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wxID_NO:
|
|
|
|
event.Skip();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-06-11 11:10:19 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
event.Skip();
|
|
|
|
}
|
2018-06-05 19:59:58 +00:00
|
|
|
}
|