2017-11-20 16:14:25 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright 2017 Jean-Pierre Charras, jp.charras@wanadoo.fr
|
2021-02-24 13:48:02 +00:00
|
|
|
* Copyright 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-11-20 16:14:25 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-06-14 18:00:08 +00:00
|
|
|
* @file eeschema/dialogs/dialog_edit_symbols_libid.cpp
|
|
|
|
* @brief Dialog to remap library id of symbols to another library id
|
2017-11-20 16:14:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2020-05-05 16:52:17 +00:00
|
|
|
#include <confirm.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2017-11-20 16:14:25 +00:00
|
|
|
#include <sch_reference_list.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2017-11-23 18:48:49 +00:00
|
|
|
#include <symbol_lib_table.h>
|
2020-05-05 16:52:17 +00:00
|
|
|
#include <trace_helpers.h>
|
2018-06-28 17:19:31 +00:00
|
|
|
#include <widgets/wx_grid.h>
|
2017-11-20 16:14:25 +00:00
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
#include <dialog_edit_symbols_libid_base.h>
|
2018-06-28 17:19:31 +00:00
|
|
|
#include <wx/tokenzr.h>
|
2020-10-18 17:22:15 +00:00
|
|
|
#include <wx/choicdlg.h>
|
|
|
|
#include <wx/dcclient.h>
|
2019-03-04 11:02:12 +00:00
|
|
|
#include <grid_tricks.h>
|
2018-09-29 16:18:55 +00:00
|
|
|
#include <widgets/grid_text_button_helpers.h>
|
2021-12-16 14:39:58 +00:00
|
|
|
#include <kiplatform/ui.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2021-06-30 10:53:04 +00:00
|
|
|
|
2017-12-16 13:50:37 +00:00
|
|
|
|
2017-11-20 16:14:25 +00:00
|
|
|
#define COL_REFS 0
|
|
|
|
#define COL_CURR_LIBID 1
|
|
|
|
#define COL_NEW_LIBID 2
|
|
|
|
|
2018-06-28 17:19:31 +00:00
|
|
|
// a re-implementation of wxGridCellAutoWrapStringRenderer to allow workaround to autorowsize bug
|
|
|
|
class GRIDCELL_AUTOWRAP_STRINGRENDERER : public wxGridCellAutoWrapStringRenderer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int GetHeight( wxDC& aDC, wxGrid* aGrid, int aRow, int aCol );
|
|
|
|
|
|
|
|
wxGridCellRenderer *Clone() const override
|
|
|
|
{ return new GRIDCELL_AUTOWRAP_STRINGRENDERER; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
// HELPER ROUTINES UNCHANGED FROM wxWidgets IMPLEMENTATION
|
|
|
|
|
2021-03-21 17:31:23 +00:00
|
|
|
wxArrayString GetTextLines( wxGrid& grid, wxDC& dc, const wxGridCellAttr& attr,
|
|
|
|
const wxRect& rect, int row, int col );
|
2018-06-28 17:19:31 +00:00
|
|
|
|
|
|
|
// Helper methods of GetTextLines()
|
|
|
|
|
|
|
|
// Break a single logical line of text into several physical lines, all of
|
|
|
|
// which are added to the lines array. The lines are broken at maxWidth and
|
|
|
|
// the dc is used for measuring text extent only.
|
2021-03-21 17:31:23 +00:00
|
|
|
void BreakLine( wxDC& dc, const wxString& logicalLine, wxCoord maxWidth, wxArrayString& lines );
|
2018-06-28 17:19:31 +00:00
|
|
|
|
|
|
|
// Break a word, which is supposed to be wider than maxWidth, into several
|
|
|
|
// lines, which are added to lines array and the last, incomplete, of which
|
|
|
|
// is returned in line output parameter.
|
|
|
|
//
|
|
|
|
// Returns the width of the last line.
|
2021-03-21 17:31:23 +00:00
|
|
|
wxCoord BreakWord( wxDC& dc, const wxString& word, wxCoord maxWidth, wxArrayString& lines,
|
|
|
|
wxString& line );
|
2018-06-28 17:19:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// PRIVATE METHOD UNCHANGED FROM wxWidgets IMPLEMENTATION
|
2021-03-21 17:31:23 +00:00
|
|
|
wxArrayString GRIDCELL_AUTOWRAP_STRINGRENDERER::GetTextLines( wxGrid& grid, wxDC& dc,
|
|
|
|
const wxGridCellAttr& attr,
|
|
|
|
const wxRect& rect, int row, int col )
|
2018-06-28 17:19:31 +00:00
|
|
|
{
|
2020-11-24 22:16:41 +00:00
|
|
|
dc.SetFont( attr.GetFont() );
|
2018-06-28 17:19:31 +00:00
|
|
|
const wxCoord maxWidth = rect.GetWidth();
|
|
|
|
|
|
|
|
// Transform logical lines into physical ones, wrapping the longer ones.
|
2021-03-21 17:31:23 +00:00
|
|
|
const wxArrayString logicalLines = wxSplit( grid.GetCellValue( row, col ), '\n', '\0' );
|
2018-06-28 17:19:31 +00:00
|
|
|
|
|
|
|
// Trying to do anything if the column is hidden anyhow doesn't make sense
|
|
|
|
// and we run into problems in BreakLine() in this case.
|
2021-03-21 17:31:23 +00:00
|
|
|
if( maxWidth <= 0 )
|
2018-06-28 17:19:31 +00:00
|
|
|
return logicalLines;
|
|
|
|
|
|
|
|
wxArrayString physicalLines;
|
2021-03-21 17:31:23 +00:00
|
|
|
|
|
|
|
for( const wxString& line : logicalLines )
|
2018-06-28 17:19:31 +00:00
|
|
|
{
|
2021-03-21 17:31:23 +00:00
|
|
|
if( dc.GetTextExtent( line ).x > maxWidth )
|
2018-06-28 17:19:31 +00:00
|
|
|
{
|
|
|
|
// Line does not fit, break it up.
|
2021-03-21 17:31:23 +00:00
|
|
|
BreakLine( dc, line, maxWidth, physicalLines );
|
2018-06-28 17:19:31 +00:00
|
|
|
}
|
|
|
|
else // The entire line fits as is
|
|
|
|
{
|
2021-03-21 17:31:23 +00:00
|
|
|
physicalLines.push_back( line );
|
2018-06-28 17:19:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return physicalLines;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// PRIVATE METHOD UNCHANGED FROM wxWidgets IMPLEMENTATION
|
2021-03-21 17:31:23 +00:00
|
|
|
void GRIDCELL_AUTOWRAP_STRINGRENDERER::BreakLine( wxDC& dc, const wxString& logicalLine,
|
|
|
|
wxCoord maxWidth, wxArrayString& lines )
|
2018-06-28 17:19:31 +00:00
|
|
|
{
|
2021-03-21 17:31:23 +00:00
|
|
|
wxCoord lineWidth = 0;
|
2018-06-28 17:19:31 +00:00
|
|
|
wxString line;
|
|
|
|
|
|
|
|
// For each word
|
2021-03-21 17:31:23 +00:00
|
|
|
wxStringTokenizer wordTokenizer( logicalLine, wxS( " \t" ), wxTOKEN_RET_DELIMS );
|
|
|
|
|
|
|
|
while( wordTokenizer.HasMoreTokens() )
|
2018-06-28 17:19:31 +00:00
|
|
|
{
|
|
|
|
const wxString word = wordTokenizer.GetNextToken();
|
2021-03-21 17:31:23 +00:00
|
|
|
const wxCoord wordWidth = dc.GetTextExtent( word ).x;
|
|
|
|
|
|
|
|
if( lineWidth + wordWidth < maxWidth )
|
2018-06-28 17:19:31 +00:00
|
|
|
{
|
|
|
|
// Word fits, just add it to this line.
|
|
|
|
line += word;
|
|
|
|
lineWidth += wordWidth;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Word does not fit, check whether the word is itself wider that
|
|
|
|
// available width
|
2021-03-21 17:31:23 +00:00
|
|
|
if( wordWidth < maxWidth )
|
2018-06-28 17:19:31 +00:00
|
|
|
{
|
|
|
|
// Word can fit in a new line, put it at the beginning
|
|
|
|
// of the new line.
|
2021-03-21 17:31:23 +00:00
|
|
|
lines.push_back( line );
|
2018-06-28 17:19:31 +00:00
|
|
|
line = word;
|
|
|
|
lineWidth = wordWidth;
|
|
|
|
}
|
|
|
|
else // Word cannot fit in available width at all.
|
|
|
|
{
|
2021-03-21 17:31:23 +00:00
|
|
|
if( !line.empty() )
|
2018-06-28 17:19:31 +00:00
|
|
|
{
|
2021-03-21 17:31:23 +00:00
|
|
|
lines.push_back( line );
|
2018-06-28 17:19:31 +00:00
|
|
|
line.clear();
|
|
|
|
lineWidth = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Break it up in several lines.
|
2021-03-21 17:31:23 +00:00
|
|
|
lineWidth = BreakWord( dc, word, maxWidth, lines, line );
|
2018-06-28 17:19:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-21 17:31:23 +00:00
|
|
|
if( !line.empty() )
|
|
|
|
lines.push_back( line );
|
2018-06-28 17:19:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// PRIVATE METHOD UNCHANGED FROM wxWidgets IMPLEMENTATION
|
2021-03-21 17:31:23 +00:00
|
|
|
wxCoord GRIDCELL_AUTOWRAP_STRINGRENDERER::BreakWord( wxDC& dc, const wxString& word,
|
|
|
|
wxCoord maxWidth, wxArrayString& lines,
|
|
|
|
wxString& line )
|
2018-06-28 17:19:31 +00:00
|
|
|
{
|
|
|
|
wxArrayInt widths;
|
2021-03-21 17:31:23 +00:00
|
|
|
dc.GetPartialTextExtents( word, widths );
|
2018-06-28 17:19:31 +00:00
|
|
|
|
|
|
|
// TODO: Use binary search to find the first element > maxWidth.
|
|
|
|
const unsigned count = widths.size();
|
2021-03-21 17:31:23 +00:00
|
|
|
unsigned n;
|
|
|
|
|
|
|
|
for( n = 0; n < count; n++ )
|
2018-06-28 17:19:31 +00:00
|
|
|
{
|
2021-03-21 17:31:23 +00:00
|
|
|
if( widths[n] > maxWidth )
|
2018-06-28 17:19:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-03-21 17:31:23 +00:00
|
|
|
if( n == 0 )
|
2018-06-28 17:19:31 +00:00
|
|
|
{
|
|
|
|
// This is a degenerate case: the first character of the word is
|
|
|
|
// already wider than the available space, so we just can't show it
|
|
|
|
// completely and have to put the first character in this line.
|
|
|
|
n = 1;
|
|
|
|
}
|
|
|
|
|
2021-03-21 17:31:23 +00:00
|
|
|
lines.push_back( word.substr( 0, n ) );
|
2018-06-28 17:19:31 +00:00
|
|
|
|
|
|
|
// Check if the remainder of the string fits in one line.
|
|
|
|
//
|
|
|
|
// Unfortunately we can't use the existing partial text extents as the
|
|
|
|
// extent of the remainder may be different when it's rendered in a
|
|
|
|
// separate line instead of as part of the same one, so we have to
|
|
|
|
// recompute it.
|
2021-03-21 17:31:23 +00:00
|
|
|
const wxString rest = word.substr( n );
|
|
|
|
const wxCoord restWidth = dc.GetTextExtent( rest ).x;
|
2020-11-24 22:16:41 +00:00
|
|
|
|
2021-03-21 17:31:23 +00:00
|
|
|
if( restWidth <= maxWidth )
|
2018-06-28 17:19:31 +00:00
|
|
|
{
|
|
|
|
line = rest;
|
|
|
|
return restWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Break the rest of the word into lines.
|
|
|
|
//
|
|
|
|
// TODO: Perhaps avoid recursion? The code is simpler like this but using a
|
|
|
|
// loop in this function would probably be more efficient.
|
2021-03-21 17:31:23 +00:00
|
|
|
return BreakWord( dc, rest, maxWidth, lines, line );
|
2018-06-28 17:19:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-15 16:01:02 +00:00
|
|
|
#define GRID_CELL_MARGIN 4
|
2018-06-28 17:19:31 +00:00
|
|
|
|
|
|
|
int GRIDCELL_AUTOWRAP_STRINGRENDERER::GetHeight( wxDC& aDC, wxGrid* aGrid, int aRow, int aCol )
|
|
|
|
{
|
|
|
|
wxGridCellAttr* attr = aGrid->GetOrCreateCellAttr( aRow, aCol );
|
|
|
|
wxRect rect;
|
|
|
|
|
|
|
|
aDC.SetFont( attr->GetFont() );
|
|
|
|
rect.SetWidth( aGrid->GetColSize( aCol ) - ( 2 * GRID_CELL_MARGIN ) );
|
|
|
|
|
|
|
|
const size_t numLines = GetTextLines( *aGrid, aDC, *attr, rect, aRow, aCol ).size();
|
2019-08-15 16:01:02 +00:00
|
|
|
const int textHeight = numLines * aDC.GetCharHeight();
|
2018-06-28 17:19:31 +00:00
|
|
|
|
|
|
|
attr->DecRef();
|
|
|
|
|
|
|
|
return textHeight + ( 2 * GRID_CELL_MARGIN );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-21 17:31:23 +00:00
|
|
|
/**
|
|
|
|
* A helper to handle symbols to edit.
|
|
|
|
*/
|
2021-07-28 15:39:40 +00:00
|
|
|
class SYMBOL_CANDIDATE
|
2017-11-20 16:14:25 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-07-28 15:39:40 +00:00
|
|
|
SYMBOL_CANDIDATE( SCH_SYMBOL* aSymbol )
|
2017-11-20 16:14:25 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
m_Symbol = aSymbol;
|
|
|
|
m_InitialLibId = m_Symbol->GetLibId().Format();
|
2017-11-20 16:14:25 +00:00
|
|
|
m_Row = -1;
|
2017-11-21 17:06:37 +00:00
|
|
|
m_IsOrphan = false;
|
2017-12-04 09:20:05 +00:00
|
|
|
m_Screen = nullptr;
|
2017-11-20 16:14:25 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// Return a string like mylib:symbol_name from the #LIB_ID of the symbol.
|
2017-11-20 16:14:25 +00:00
|
|
|
wxString GetStringLibId()
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
return m_Symbol->GetLibId().GetUniStringLibId();
|
2017-11-20 16:14:25 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* m_Symbol; // the schematic symbol
|
2021-03-21 17:31:23 +00:00
|
|
|
int m_Row; // the row index in m_grid
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SCREEN* m_Screen; // the screen where m_Symbol lives
|
2021-03-21 17:31:23 +00:00
|
|
|
wxString m_Reference; // the schematic reference, only to display it in list
|
2021-06-14 18:00:08 +00:00
|
|
|
wxString m_InitialLibId; // the Lib Id of the symbol before any change.
|
|
|
|
bool m_IsOrphan; // true if a symbol has no corresponding symbol found in libs.
|
2017-11-20 16:14:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-06-14 18:00:08 +00:00
|
|
|
* Dialog to globally edit the #LIB_ID of groups if symbols having the same initial LIB_ID.
|
2020-05-05 16:52:17 +00:00
|
|
|
*
|
|
|
|
* This is useful when you want to:
|
2021-03-21 17:31:23 +00:00
|
|
|
* * move a symbol from a symbol library to another symbol library.
|
|
|
|
* * change the nickname of a library.
|
2021-06-14 18:00:08 +00:00
|
|
|
* * globally replace the symbol used by a group of symbols by another symbol.
|
2017-11-20 16:14:25 +00:00
|
|
|
*/
|
2021-06-14 18:00:08 +00:00
|
|
|
class DIALOG_EDIT_SYMBOLS_LIBID : public DIALOG_EDIT_SYMBOLS_LIBID_BASE
|
2017-11-20 16:14:25 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-06-14 18:00:08 +00:00
|
|
|
DIALOG_EDIT_SYMBOLS_LIBID( SCH_EDIT_FRAME* aParent );
|
|
|
|
~DIALOG_EDIT_SYMBOLS_LIBID() override;
|
2017-11-20 16:14:25 +00:00
|
|
|
|
2020-05-05 16:52:17 +00:00
|
|
|
SCH_EDIT_FRAME* GetParent();
|
|
|
|
|
2017-11-23 18:48:49 +00:00
|
|
|
bool IsSchematicModified() { return m_isModified; }
|
2017-11-20 16:14:25 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void initDlg();
|
|
|
|
|
2017-11-22 12:14:48 +00:00
|
|
|
/**
|
|
|
|
* Add a new row (new entry) in m_grid.
|
2021-03-21 17:31:23 +00:00
|
|
|
*
|
|
|
|
* @param aMarkRow set to true to use bold/italic font in column COL_CURR_LIBID.
|
|
|
|
* @param aReferences is the value of cell( aRowId, COL_REFS).
|
|
|
|
* @param aStrLibId is the value of cell( aRowId, COL_CURR_LIBID).
|
2017-11-22 12:14:48 +00:00
|
|
|
*/
|
2018-06-28 17:19:31 +00:00
|
|
|
void AddRowToGrid( bool aMarkRow, const wxString& aReferences, const wxString& aStrLibId );
|
2017-11-22 12:14:48 +00:00
|
|
|
|
2017-11-22 16:53:56 +00:00
|
|
|
/// returns true if all new lib id are valid
|
2017-11-20 16:14:25 +00:00
|
|
|
bool validateLibIds();
|
|
|
|
|
2021-03-21 17:31:23 +00:00
|
|
|
/**
|
|
|
|
* Run the lib browser and set the selected #LIB_ID for \a aRow.
|
|
|
|
*
|
|
|
|
* @param aRow is the row to edit.
|
|
|
|
* @return false if the command was aborted.
|
2017-11-23 09:39:52 +00:00
|
|
|
*/
|
|
|
|
bool setLibIdByBrowser( int aRow );
|
|
|
|
|
2021-03-21 17:31:23 +00:00
|
|
|
// Event handlers
|
2017-11-22 16:53:56 +00:00
|
|
|
|
2017-11-20 16:14:25 +00:00
|
|
|
// called on a right click or a left double click:
|
|
|
|
void onCellBrowseLib( wxGridEvent& event ) override;
|
2017-11-22 16:53:56 +00:00
|
|
|
|
|
|
|
// Cancel all changes, and close the dialog
|
2017-11-20 16:14:25 +00:00
|
|
|
void onCancel( wxCommandEvent& event ) override
|
|
|
|
{
|
2019-01-31 01:07:53 +00:00
|
|
|
// Just skipping the event doesn't work after the library browser was run
|
|
|
|
if( IsQuasiModal() )
|
|
|
|
EndQuasiModal( wxID_CANCEL );
|
|
|
|
else
|
|
|
|
event.Skip();
|
2017-11-20 16:14:25 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 18:48:49 +00:00
|
|
|
// Try to find a candidate for non existing symbols
|
|
|
|
void onClickOrphansButton( wxCommandEvent& event ) override;
|
|
|
|
|
2017-11-22 16:53:56 +00:00
|
|
|
// Automatically called when click on OK button
|
2017-11-20 16:14:25 +00:00
|
|
|
bool TransferDataFromWindow() override;
|
2018-06-28 17:19:31 +00:00
|
|
|
|
2021-12-16 14:39:58 +00:00
|
|
|
void AdjustGridColumns();
|
2018-06-28 17:19:31 +00:00
|
|
|
|
|
|
|
void OnSizeGrid( wxSizeEvent& event ) override;
|
2021-03-21 17:31:23 +00:00
|
|
|
|
|
|
|
bool m_isModified; // set to true if the schematic is modified
|
|
|
|
std::vector<int> m_OrphansRowIndexes; // list of rows containing orphan lib_id
|
|
|
|
|
2021-07-28 15:39:40 +00:00
|
|
|
std::vector<SYMBOL_CANDIDATE> m_symbols;
|
2021-03-21 17:31:23 +00:00
|
|
|
|
|
|
|
GRIDCELL_AUTOWRAP_STRINGRENDERER* m_autoWrapRenderer;
|
2017-11-20 16:14:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
DIALOG_EDIT_SYMBOLS_LIBID::DIALOG_EDIT_SYMBOLS_LIBID( SCH_EDIT_FRAME* aParent )
|
|
|
|
:DIALOG_EDIT_SYMBOLS_LIBID_BASE( aParent )
|
2017-11-20 16:14:25 +00:00
|
|
|
{
|
2018-06-28 17:19:31 +00:00
|
|
|
m_autoWrapRenderer = new GRIDCELL_AUTOWRAP_STRINGRENDERER;
|
|
|
|
|
2018-09-29 16:18:55 +00:00
|
|
|
m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
|
|
|
|
|
2017-11-20 16:14:25 +00:00
|
|
|
initDlg();
|
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2018-06-28 17:19:31 +00:00
|
|
|
}
|
2018-04-21 15:53:54 +00:00
|
|
|
|
2017-11-20 16:14:25 +00:00
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
DIALOG_EDIT_SYMBOLS_LIBID::~DIALOG_EDIT_SYMBOLS_LIBID()
|
2018-06-28 17:19:31 +00:00
|
|
|
{
|
2018-09-29 16:18:55 +00:00
|
|
|
// Delete the GRID_TRICKS.
|
|
|
|
m_grid->PopEventHandler( true );
|
|
|
|
|
2018-06-28 17:19:31 +00:00
|
|
|
m_autoWrapRenderer->DecRef();
|
2017-11-20 16:14:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
// A sort compare function to sort symbols list by LIB_ID and then reference.
|
2021-07-28 15:39:40 +00:00
|
|
|
static bool sort_by_libid( const SYMBOL_CANDIDATE& candidate1, const SYMBOL_CANDIDATE& candidate2 )
|
2017-11-20 16:14:25 +00:00
|
|
|
{
|
2021-06-14 18:00:08 +00:00
|
|
|
if( candidate1.m_Symbol->GetLibId() == candidate2.m_Symbol->GetLibId() )
|
|
|
|
return candidate1.m_Reference.Cmp( candidate2.m_Reference ) < 0;
|
2017-11-20 16:14:25 +00:00
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
return candidate1.m_Symbol->GetLibId() < candidate2.m_Symbol->GetLibId();
|
2017-11-20 16:14:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
void DIALOG_EDIT_SYMBOLS_LIBID::initDlg()
|
2017-11-20 16:14:25 +00:00
|
|
|
{
|
2018-06-28 17:19:31 +00:00
|
|
|
// Clear the FormBuilder rows
|
2021-08-10 11:59:53 +00:00
|
|
|
m_grid->ClearRows();
|
2018-06-28 17:19:31 +00:00
|
|
|
|
2017-11-22 16:53:56 +00:00
|
|
|
m_isModified = false;
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
// This option build the full symbol list.
|
|
|
|
// In complex hierarchies, the same symbol is in fact duplicated, but
|
2017-11-20 16:14:25 +00:00
|
|
|
// it is listed with different references (one by sheet instance)
|
2021-06-14 18:00:08 +00:00
|
|
|
// the list is larger and looks like it contains all symbols.
|
2020-05-13 02:00:37 +00:00
|
|
|
const SCH_SHEET_LIST& sheets = GetParent()->Schematic().GetSheets();
|
2017-11-20 16:14:25 +00:00
|
|
|
SCH_REFERENCE_LIST references;
|
2021-03-21 17:31:23 +00:00
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
// build the full list of symbols including symbol having no symbol in loaded libs
|
|
|
|
// (orphan symbols)
|
2021-03-21 17:31:23 +00:00
|
|
|
sheets.GetSymbols( references, /* include power symbols */ true,
|
2021-06-14 18:00:08 +00:00
|
|
|
/* include orphan symbols */ true );
|
2017-11-20 16:14:25 +00:00
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < references.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
SCH_REFERENCE& item = references[ii];
|
2021-07-28 15:39:40 +00:00
|
|
|
SYMBOL_CANDIDATE candidate( item.GetSymbol() );
|
2017-11-20 16:14:25 +00:00
|
|
|
candidate.m_Screen = item.GetSheetPath().LastScreen();
|
|
|
|
SCH_SHEET_PATH sheetpath = item.GetSheetPath();
|
2021-06-10 14:10:55 +00:00
|
|
|
candidate.m_Reference = candidate.m_Symbol->GetRef( &sheetpath );
|
|
|
|
int unitcount = candidate.m_Symbol->GetUnitCount();
|
2017-11-23 18:48:49 +00:00
|
|
|
candidate.m_IsOrphan = ( unitcount == 0 );
|
2021-06-10 14:10:55 +00:00
|
|
|
m_symbols.push_back( candidate );
|
2017-11-20 16:14:25 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( m_symbols.size() == 0 )
|
2017-11-20 16:14:25 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// now sort by lib id to create groups of items having the same lib id
|
2021-06-10 14:10:55 +00:00
|
|
|
std::sort( m_symbols.begin(), m_symbols.end(), sort_by_libid );
|
2017-11-20 16:14:25 +00:00
|
|
|
|
|
|
|
// Now, fill m_grid
|
2021-06-10 14:10:55 +00:00
|
|
|
wxString last_str_libid = m_symbols.front().GetStringLibId();
|
2017-11-20 16:14:25 +00:00
|
|
|
int row = 0;
|
|
|
|
wxString refs;
|
2019-08-27 03:40:30 +00:00
|
|
|
wxString last_ref;
|
2021-06-10 14:10:55 +00:00
|
|
|
bool mark_cell = m_symbols.front().m_IsOrphan;
|
2017-11-20 16:14:25 +00:00
|
|
|
|
2021-07-28 15:39:40 +00:00
|
|
|
for( SYMBOL_CANDIDATE& symbol : m_symbols )
|
2017-11-20 16:14:25 +00:00
|
|
|
{
|
2021-06-14 18:00:08 +00:00
|
|
|
wxString str_libid = symbol.GetStringLibId();
|
2017-11-20 16:14:25 +00:00
|
|
|
|
2017-11-22 12:14:48 +00:00
|
|
|
if( last_str_libid != str_libid )
|
2017-11-20 16:14:25 +00:00
|
|
|
{
|
2017-11-22 12:14:48 +00:00
|
|
|
// Add last group to grid
|
2018-06-28 17:19:31 +00:00
|
|
|
AddRowToGrid( mark_cell, refs, last_str_libid );
|
2017-11-20 16:14:25 +00:00
|
|
|
|
|
|
|
// prepare next entry
|
2021-06-14 18:00:08 +00:00
|
|
|
mark_cell = symbol.m_IsOrphan;
|
2017-11-20 16:14:25 +00:00
|
|
|
last_str_libid = str_libid;
|
|
|
|
refs.Empty();
|
|
|
|
row++;
|
|
|
|
}
|
2021-07-28 15:39:40 +00:00
|
|
|
else if( symbol.m_Reference == last_ref )
|
2019-08-27 03:40:30 +00:00
|
|
|
{
|
2021-06-14 18:00:08 +00:00
|
|
|
symbol.m_Row = row;
|
2019-08-27 03:40:30 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-07-28 15:39:40 +00:00
|
|
|
last_ref = symbol.m_Reference;
|
2017-11-20 16:14:25 +00:00
|
|
|
|
|
|
|
if( !refs.IsEmpty() )
|
2018-06-28 17:19:31 +00:00
|
|
|
refs += wxT( ", " );
|
2017-11-20 16:14:25 +00:00
|
|
|
|
2021-07-28 15:39:40 +00:00
|
|
|
refs += symbol.m_Reference;
|
2021-06-14 18:00:08 +00:00
|
|
|
symbol.m_Row = row;
|
2017-11-20 16:14:25 +00:00
|
|
|
}
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
// Add last symbol group:
|
2018-06-28 17:19:31 +00:00
|
|
|
AddRowToGrid( mark_cell, refs, last_str_libid );
|
2017-11-23 09:39:52 +00:00
|
|
|
|
|
|
|
// Allows only the selection by row
|
|
|
|
m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
|
2017-11-23 18:48:49 +00:00
|
|
|
|
|
|
|
m_buttonOrphanItems->Enable( m_OrphansRowIndexes.size() > 0 );
|
2017-12-24 15:04:02 +00:00
|
|
|
Layout();
|
2017-11-20 16:14:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
SCH_EDIT_FRAME* DIALOG_EDIT_SYMBOLS_LIBID::GetParent()
|
2020-05-05 16:52:17 +00:00
|
|
|
{
|
|
|
|
return dynamic_cast<SCH_EDIT_FRAME*>( wxDialog::GetParent() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
void DIALOG_EDIT_SYMBOLS_LIBID::AddRowToGrid( bool aMarkRow, const wxString& aReferences,
|
2021-07-16 20:13:26 +00:00
|
|
|
const wxString& aStrLibId )
|
2017-11-22 12:14:48 +00:00
|
|
|
{
|
2018-06-28 17:19:31 +00:00
|
|
|
int row = m_grid->GetNumberRows();
|
2017-11-23 18:48:49 +00:00
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
if( aMarkRow ) // An orphaned symbol exists, set m_AsOrphanCmp as true.
|
2018-06-28 17:19:31 +00:00
|
|
|
m_OrphansRowIndexes.push_back( row );
|
2017-11-22 12:14:48 +00:00
|
|
|
|
2018-06-28 17:19:31 +00:00
|
|
|
m_grid->AppendRows( 1 );
|
2017-11-22 12:14:48 +00:00
|
|
|
|
2021-07-28 15:39:40 +00:00
|
|
|
m_grid->SetCellValue( row, COL_REFS, UnescapeString( aReferences ) );
|
2017-11-22 12:14:48 +00:00
|
|
|
m_grid->SetReadOnly( row, COL_REFS );
|
|
|
|
|
2021-07-28 15:39:40 +00:00
|
|
|
m_grid->SetCellValue( row, COL_CURR_LIBID, UnescapeString( aStrLibId ) );
|
2017-11-22 12:14:48 +00:00
|
|
|
m_grid->SetReadOnly( row, COL_CURR_LIBID );
|
|
|
|
|
|
|
|
if( aMarkRow ) // A symbol is not existing in libraries: mark the cell
|
|
|
|
{
|
|
|
|
wxFont font = m_grid->GetDefaultCellFont();
|
|
|
|
font.MakeBold();
|
|
|
|
font.MakeItalic();
|
|
|
|
m_grid->SetCellFont( row, COL_CURR_LIBID, font );
|
|
|
|
}
|
|
|
|
|
2018-06-28 17:19:31 +00:00
|
|
|
m_grid->SetCellRenderer( row, COL_REFS, m_autoWrapRenderer->Clone() );
|
|
|
|
|
|
|
|
// wxWidgets' AutoRowHeight fails when used with wxGridCellAutoWrapStringRenderer
|
|
|
|
// (fixed in 2014, but didn't get in to wxWidgets 3.0.2)
|
|
|
|
wxClientDC dc( this );
|
|
|
|
m_grid->SetRowSize( row, m_autoWrapRenderer->GetHeight( dc, m_grid, row, COL_REFS ) );
|
2018-09-29 16:18:55 +00:00
|
|
|
|
|
|
|
// set new libid column browse button
|
|
|
|
wxGridCellAttr* attr = new wxGridCellAttr;
|
2021-07-28 15:39:40 +00:00
|
|
|
attr->SetEditor( new GRID_CELL_SYMBOL_ID_EDITOR( this, UnescapeString( aStrLibId ) ) );
|
2019-01-31 01:07:53 +00:00
|
|
|
m_grid->SetAttr( row, COL_NEW_LIBID, attr );
|
2017-11-22 12:14:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-28 15:39:40 +00:00
|
|
|
wxString getLibIdValue( const WX_GRID* aGrid, int aRow, int aCol )
|
|
|
|
{
|
|
|
|
wxString rawValue = aGrid->GetCellValue( aRow, aCol );
|
2021-07-28 18:43:57 +00:00
|
|
|
|
|
|
|
if( rawValue.IsEmpty() )
|
|
|
|
return rawValue;
|
|
|
|
|
2021-07-28 15:39:40 +00:00
|
|
|
wxString itemName;
|
|
|
|
wxString libName = rawValue.BeforeFirst( ':', &itemName );
|
|
|
|
|
|
|
|
return EscapeString( libName, CTX_LIBID ) + ':' + EscapeString( itemName, CTX_LIBID );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
bool DIALOG_EDIT_SYMBOLS_LIBID::validateLibIds()
|
2017-11-20 16:14:25 +00:00
|
|
|
{
|
2018-08-15 13:29:19 +00:00
|
|
|
if( !m_grid->CommitPendingChanges() )
|
|
|
|
return false;
|
2018-06-28 17:19:31 +00:00
|
|
|
|
2017-11-20 16:14:25 +00:00
|
|
|
int row_max = m_grid->GetNumberRows() - 1;
|
|
|
|
|
|
|
|
for( int row = 0; row <= row_max; row++ )
|
|
|
|
{
|
2021-07-28 15:39:40 +00:00
|
|
|
wxString new_libid = getLibIdValue( m_grid, row, COL_NEW_LIBID );
|
2017-11-20 16:14:25 +00:00
|
|
|
|
|
|
|
if( new_libid.IsEmpty() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// a new lib id is found. validate this new value
|
|
|
|
LIB_ID id;
|
2020-12-17 23:32:23 +00:00
|
|
|
id.Parse( new_libid );
|
2017-11-20 16:14:25 +00:00
|
|
|
|
|
|
|
if( !id.IsValid() )
|
|
|
|
{
|
|
|
|
wxString msg;
|
2021-06-16 22:35:00 +00:00
|
|
|
msg.Printf( _( "Symbol library identifier %s is not valid." ), new_libid );
|
2017-11-20 16:14:25 +00:00
|
|
|
wxMessageBox( msg );
|
2018-06-28 17:19:31 +00:00
|
|
|
|
|
|
|
m_grid->SetFocus();
|
|
|
|
m_grid->MakeCellVisible( row, COL_NEW_LIBID );
|
|
|
|
m_grid->SetGridCursor( row, COL_NEW_LIBID );
|
|
|
|
|
|
|
|
m_grid->EnableCellEditControl( true );
|
|
|
|
m_grid->ShowCellEditControl();
|
|
|
|
|
2017-11-20 16:14:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
void DIALOG_EDIT_SYMBOLS_LIBID::onCellBrowseLib( wxGridEvent& event )
|
2017-11-20 16:14:25 +00:00
|
|
|
{
|
|
|
|
int row = event.GetRow();
|
2017-11-23 09:39:52 +00:00
|
|
|
m_grid->SelectRow( row ); // only for user, to show the selected line
|
2017-11-20 16:14:25 +00:00
|
|
|
|
2017-11-23 09:39:52 +00:00
|
|
|
setLibIdByBrowser( row );
|
|
|
|
|
|
|
|
}
|
2017-11-20 16:14:25 +00:00
|
|
|
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
void DIALOG_EDIT_SYMBOLS_LIBID::onClickOrphansButton( wxCommandEvent& event )
|
2017-11-23 18:48:49 +00:00
|
|
|
{
|
2021-07-28 15:39:40 +00:00
|
|
|
std::vector<wxString> libs = Prj().SchSymbolLibTable()->GetLogicalLibs();
|
2017-11-23 18:48:49 +00:00
|
|
|
wxArrayString aliasNames;
|
2017-12-16 13:50:37 +00:00
|
|
|
wxArrayString candidateSymbNames;
|
2017-11-23 18:48:49 +00:00
|
|
|
|
|
|
|
unsigned fixesCount = 0;
|
|
|
|
|
|
|
|
// Try to find a candidate for non existing symbols in any loaded library
|
2020-07-13 13:16:21 +00:00
|
|
|
for( int orphanRow : m_OrphansRowIndexes )
|
2017-11-23 18:48:49 +00:00
|
|
|
{
|
2021-07-28 15:39:40 +00:00
|
|
|
wxString orphanLibid = getLibIdValue( m_grid, orphanRow, COL_CURR_LIBID );
|
2020-07-13 13:16:21 +00:00
|
|
|
int grid_row_idx = orphanRow; //row index in m_grid for the current item
|
2017-11-23 18:48:49 +00:00
|
|
|
|
2018-07-26 14:38:30 +00:00
|
|
|
LIB_ID curr_libid;
|
2020-12-17 23:32:23 +00:00
|
|
|
curr_libid.Parse( orphanLibid, true );
|
2021-07-28 15:39:40 +00:00
|
|
|
wxString symbolName = curr_libid.GetLibItemName();
|
2021-03-21 17:31:23 +00:00
|
|
|
|
2017-12-16 13:50:37 +00:00
|
|
|
// number of full LIB_ID candidates (because we search for a symbol name
|
2021-03-21 17:31:23 +00:00
|
|
|
// inside all available libraries, perhaps the same symbol name can be found
|
2017-12-16 13:50:37 +00:00
|
|
|
// in more than one library, giving ambiguity
|
|
|
|
int libIdCandidateCount = 0;
|
|
|
|
candidateSymbNames.Clear();
|
2017-11-23 18:48:49 +00:00
|
|
|
|
2018-07-26 14:38:30 +00:00
|
|
|
// now try to find a candidate
|
2021-07-28 15:39:40 +00:00
|
|
|
for( const wxString &lib : libs )
|
2017-11-23 18:48:49 +00:00
|
|
|
{
|
|
|
|
aliasNames.Clear();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Prj().SchSymbolLibTable()->EnumerateSymbolLib( lib, aliasNames );
|
|
|
|
}
|
2018-04-18 07:10:29 +00:00
|
|
|
catch( const IO_ERROR& ) {} // ignore, it is handled below
|
2017-11-23 18:48:49 +00:00
|
|
|
|
|
|
|
if( aliasNames.IsEmpty() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Find a symbol name in symbols inside this library:
|
2021-07-28 15:39:40 +00:00
|
|
|
int index = aliasNames.Index( symbolName );
|
2017-11-23 18:48:49 +00:00
|
|
|
|
|
|
|
if( index != wxNOT_FOUND )
|
|
|
|
{
|
|
|
|
// a candidate is found!
|
2017-12-16 13:50:37 +00:00
|
|
|
libIdCandidateCount++;
|
2021-07-28 15:39:40 +00:00
|
|
|
wxString newLibid = lib + ':' + symbolName;
|
2017-12-16 13:50:37 +00:00
|
|
|
|
|
|
|
// Uses the first found. Most of time, it is alone.
|
|
|
|
// Others will be stored in a candidate list
|
|
|
|
if( libIdCandidateCount <= 1 )
|
|
|
|
{
|
2021-07-28 15:39:40 +00:00
|
|
|
m_grid->SetCellValue( grid_row_idx, COL_NEW_LIBID, UnescapeString( newLibid ) );
|
2017-12-16 13:50:37 +00:00
|
|
|
candidateSymbNames.Add( m_grid->GetCellValue( grid_row_idx, COL_NEW_LIBID ) );
|
|
|
|
fixesCount++;
|
|
|
|
}
|
|
|
|
else // Store other candidates for later selection
|
|
|
|
{
|
2021-07-28 15:39:40 +00:00
|
|
|
candidateSymbNames.Add( UnescapeString( newLibid ) );
|
2017-12-16 13:50:37 +00:00
|
|
|
}
|
2017-11-23 18:48:49 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-16 13:50:37 +00:00
|
|
|
|
|
|
|
// If more than one LIB_ID candidate, ask for selection between candidates:
|
|
|
|
if( libIdCandidateCount > 1 )
|
|
|
|
{
|
|
|
|
// Mainly for user: select the row being edited
|
|
|
|
m_grid->SelectRow( grid_row_idx );
|
|
|
|
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Available Candidates for %s " ),
|
|
|
|
m_grid->GetCellValue( grid_row_idx, COL_CURR_LIBID ) );
|
|
|
|
|
|
|
|
wxSingleChoiceDialog dlg ( this, msg,
|
2021-07-16 20:13:26 +00:00
|
|
|
wxString::Format( _( "Candidates count %d " ),
|
|
|
|
libIdCandidateCount ),
|
|
|
|
candidateSymbNames );
|
2017-12-16 13:50:37 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
m_grid->SetCellValue( grid_row_idx, COL_NEW_LIBID, dlg.GetStringSelection() );
|
|
|
|
}
|
2017-11-23 18:48:49 +00:00
|
|
|
}
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
if( fixesCount < m_OrphansRowIndexes.size() ) // Not all orphan symbols are fixed.
|
2017-11-23 18:48:49 +00:00
|
|
|
{
|
2018-12-11 17:56:20 +00:00
|
|
|
wxMessageBox( wxString::Format( _( "%u link(s) mapped, %u not found" ),
|
|
|
|
fixesCount,
|
|
|
|
(unsigned) m_OrphansRowIndexes.size() - fixesCount ) );
|
2017-11-23 18:48:49 +00:00
|
|
|
}
|
|
|
|
else
|
2021-07-16 20:13:26 +00:00
|
|
|
{
|
2017-11-23 18:48:49 +00:00
|
|
|
wxMessageBox( wxString::Format( _( "All %u link(s) resolved" ), fixesCount ) );
|
2021-07-16 20:13:26 +00:00
|
|
|
}
|
2017-11-23 18:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
bool DIALOG_EDIT_SYMBOLS_LIBID::setLibIdByBrowser( int aRow )
|
2017-11-23 09:39:52 +00:00
|
|
|
{
|
|
|
|
#if 0
|
2017-11-23 18:48:49 +00:00
|
|
|
// Use dialog symbol selector to choose a symbol
|
2017-11-23 09:39:52 +00:00
|
|
|
SCH_BASE_FRAME::HISTORY_LIST dummy;
|
2021-07-16 20:13:26 +00:00
|
|
|
SCH_BASE_FRAME::PICKED_SYMBOL sel = m_frame->SelectComponentFromLibrary( nullptr, dummy, true,
|
2020-11-07 14:31:50 +00:00
|
|
|
0, 0, false );
|
2017-11-23 09:39:52 +00:00
|
|
|
#else
|
2017-11-23 18:48:49 +00:00
|
|
|
// Use library viewer to choose a symbol
|
2020-12-17 23:32:23 +00:00
|
|
|
LIB_ID preselected;
|
2021-07-28 15:39:40 +00:00
|
|
|
wxString current = getLibIdValue( m_grid, aRow, COL_NEW_LIBID );
|
2019-01-31 01:07:53 +00:00
|
|
|
|
|
|
|
if( current.IsEmpty() )
|
2021-07-28 15:39:40 +00:00
|
|
|
current = getLibIdValue( m_grid, aRow, COL_CURR_LIBID );
|
2019-01-31 01:07:53 +00:00
|
|
|
|
|
|
|
if( !current.IsEmpty() )
|
2020-12-17 23:32:23 +00:00
|
|
|
preselected.Parse( current, true );
|
2019-01-31 01:07:53 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
PICKED_SYMBOL sel = GetParent()->PickSymbolFromLibBrowser( this, nullptr, preselected, 0, 0 );
|
2017-11-23 09:39:52 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if( sel.LibId.empty() ) // command aborted
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( !sel.LibId.IsValid() ) // Should not occur
|
|
|
|
{
|
|
|
|
wxMessageBox( _( "Invalid symbol library identifier" ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-20 16:14:25 +00:00
|
|
|
wxString new_libid;
|
|
|
|
new_libid = sel.LibId.Format();
|
|
|
|
|
2021-07-28 15:39:40 +00:00
|
|
|
m_grid->SetCellValue( aRow, COL_NEW_LIBID, UnescapeString( new_libid ) );
|
2017-11-20 16:14:25 +00:00
|
|
|
|
2017-11-23 09:39:52 +00:00
|
|
|
return true;
|
2017-11-20 16:14:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
bool DIALOG_EDIT_SYMBOLS_LIBID::TransferDataFromWindow()
|
2017-11-20 16:14:25 +00:00
|
|
|
{
|
|
|
|
if( !validateLibIds() )
|
|
|
|
return false;
|
|
|
|
|
2021-06-30 10:53:04 +00:00
|
|
|
auto getName = []( const LIB_ID& aLibId )
|
|
|
|
{
|
|
|
|
return UnescapeString( aLibId.GetLibItemName().wx_str() );
|
|
|
|
};
|
|
|
|
|
2017-11-20 16:14:25 +00:00
|
|
|
int row_max = m_grid->GetNumberRows() - 1;
|
|
|
|
|
|
|
|
for( int row = 0; row <= row_max; row++ )
|
|
|
|
{
|
2021-07-28 15:39:40 +00:00
|
|
|
wxString new_libid = getLibIdValue( m_grid, row, COL_NEW_LIBID );
|
2017-11-20 16:14:25 +00:00
|
|
|
|
2021-07-28 15:39:40 +00:00
|
|
|
if( new_libid.IsEmpty() || new_libid == getLibIdValue( m_grid, row, COL_CURR_LIBID ) )
|
2017-11-20 16:14:25 +00:00
|
|
|
continue;
|
|
|
|
|
2019-08-15 16:01:02 +00:00
|
|
|
// A new lib id is found and was already validated.
|
2017-11-20 16:14:25 +00:00
|
|
|
LIB_ID id;
|
2020-12-17 23:32:23 +00:00
|
|
|
id.Parse( new_libid, true );
|
2017-11-20 16:14:25 +00:00
|
|
|
|
2021-07-28 15:39:40 +00:00
|
|
|
for( SYMBOL_CANDIDATE& candidate : m_symbols )
|
2017-11-20 16:14:25 +00:00
|
|
|
{
|
2021-06-14 18:00:08 +00:00
|
|
|
if( candidate.m_Row != row )
|
2017-11-20 16:14:25 +00:00
|
|
|
continue;
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* symbol = nullptr;
|
2020-05-05 16:52:17 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
symbol = Prj().SchSymbolLibTable()->LoadSymbol( id );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2021-06-26 11:33:37 +00:00
|
|
|
msg.Printf( _( "Error loading symbol %s from library %s.\n\n%s" ),
|
2020-05-05 16:52:17 +00:00
|
|
|
id.GetLibItemName().wx_str(),
|
|
|
|
id.GetLibNickname().wx_str(),
|
|
|
|
ioe.What() );
|
|
|
|
|
|
|
|
DisplayError( this, msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( symbol == nullptr )
|
|
|
|
continue;
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
GetParent()->SaveCopyInUndoList( candidate.m_Screen, candidate.m_Symbol,
|
|
|
|
UNDO_REDO::CHANGED, m_isModified );
|
2020-07-13 13:16:21 +00:00
|
|
|
m_isModified = true;
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
candidate.m_Screen->Remove( candidate.m_Symbol );
|
|
|
|
SCH_FIELD* value = candidate.m_Symbol->GetField( VALUE_FIELD );
|
2019-08-15 16:01:02 +00:00
|
|
|
|
|
|
|
// If value is a proxy for the itemName then make sure it gets updated
|
2021-06-30 10:53:04 +00:00
|
|
|
if( getName( candidate.m_Symbol->GetLibId() ) == value->GetText() )
|
|
|
|
candidate.m_Symbol->SetValue( getName( id ) );
|
2019-08-15 16:01:02 +00:00
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
candidate.m_Symbol->SetLibId( id );
|
|
|
|
candidate.m_Symbol->SetLibSymbol( symbol->Flatten().release() );
|
|
|
|
candidate.m_Screen->Append( candidate.m_Symbol );
|
|
|
|
candidate.m_Screen->SetContentModified();
|
2021-02-18 09:37:48 +00:00
|
|
|
|
|
|
|
if ( m_checkBoxUpdateFields->IsChecked() )
|
2021-04-09 16:10:40 +00:00
|
|
|
{
|
2021-06-14 18:00:08 +00:00
|
|
|
candidate.m_Symbol->UpdateFields( nullptr,
|
|
|
|
false, /* update style */
|
|
|
|
false, /* update ref */
|
|
|
|
false, /* update other fields */
|
|
|
|
false, /* reset ref */
|
2021-07-16 20:13:26 +00:00
|
|
|
true /* reset other fields */ );
|
2021-04-09 16:10:40 +00:00
|
|
|
}
|
2017-11-20 16:14:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-16 14:39:58 +00:00
|
|
|
void DIALOG_EDIT_SYMBOLS_LIBID::AdjustGridColumns()
|
2018-06-28 17:19:31 +00:00
|
|
|
{
|
|
|
|
// Account for scroll bars
|
2021-12-16 14:39:58 +00:00
|
|
|
int width = KIPLATFORM::UI::GetUnobscuredSize( m_grid ).x;
|
2018-06-28 17:19:31 +00:00
|
|
|
|
2021-12-16 14:39:58 +00:00
|
|
|
int colWidth = width / 3;
|
2018-09-29 16:18:55 +00:00
|
|
|
|
|
|
|
m_grid->SetColSize( COL_REFS, colWidth );
|
2021-12-16 14:39:58 +00:00
|
|
|
width -= colWidth;
|
2018-09-29 16:18:55 +00:00
|
|
|
|
|
|
|
colWidth = 0;
|
2021-03-21 17:31:23 +00:00
|
|
|
|
2018-09-29 16:18:55 +00:00
|
|
|
for( int row = 0; row < m_grid->GetNumberRows(); ++row )
|
|
|
|
{
|
|
|
|
wxString cellValue = m_grid->GetCellValue( row, COL_CURR_LIBID );
|
2020-10-25 16:41:38 +00:00
|
|
|
colWidth = std::max( colWidth, KIUI::GetTextSize( cellValue, m_grid ).x );
|
2018-09-29 16:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
colWidth += 20;
|
|
|
|
m_grid->SetColSize( COL_CURR_LIBID, colWidth );
|
2021-12-16 14:39:58 +00:00
|
|
|
width -= colWidth;
|
2018-09-29 16:18:55 +00:00
|
|
|
|
|
|
|
colWidth = 0;
|
2021-03-21 17:31:23 +00:00
|
|
|
|
2018-09-29 16:18:55 +00:00
|
|
|
for( int row = 0; row < m_grid->GetNumberRows(); ++row )
|
|
|
|
{
|
|
|
|
wxString cellValue = m_grid->GetCellValue( row, COL_NEW_LIBID );
|
2020-10-25 16:41:38 +00:00
|
|
|
colWidth = std::max( colWidth, KIUI::GetTextSize( cellValue, m_grid ).x );
|
2018-09-29 16:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
colWidth += 20;
|
2021-12-16 14:39:58 +00:00
|
|
|
m_grid->SetColSize( COL_NEW_LIBID, std::max( colWidth, width ) );
|
2018-06-28 17:19:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
void DIALOG_EDIT_SYMBOLS_LIBID::OnSizeGrid( wxSizeEvent& event )
|
2018-06-28 17:19:31 +00:00
|
|
|
{
|
2021-12-16 14:39:58 +00:00
|
|
|
AdjustGridColumns();
|
2018-06-28 17:19:31 +00:00
|
|
|
|
|
|
|
wxClientDC dc( this );
|
|
|
|
|
|
|
|
// wxWidgets' AutoRowHeight fails when used with wxGridCellAutoWrapStringRenderer
|
|
|
|
for( int row = 0; row < m_grid->GetNumberRows(); ++row )
|
|
|
|
m_grid->SetRowSize( row, m_autoWrapRenderer->GetHeight( dc, m_grid, row, COL_REFS ) );
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
bool InvokeDialogEditSymbolsLibId( SCH_EDIT_FRAME* aCaller )
|
2017-11-20 16:14:25 +00:00
|
|
|
{
|
2018-01-01 12:17:06 +00:00
|
|
|
// This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal
|
|
|
|
// frame. Therefore this dialog as a modal frame parent, MUST be run under
|
|
|
|
// quasimodal mode for the quasimodal frame support to work. So don't use
|
|
|
|
// the QUASIMODAL macros here.
|
2021-06-14 18:00:08 +00:00
|
|
|
DIALOG_EDIT_SYMBOLS_LIBID dlg( aCaller );
|
2021-07-16 20:13:26 +00:00
|
|
|
|
|
|
|
// DO NOT use ShowModal() here, otherwise the library browser will not work properly.
|
2018-01-01 12:17:06 +00:00
|
|
|
dlg.ShowQuasiModal();
|
2017-11-20 16:14:25 +00:00
|
|
|
|
2017-11-23 18:48:49 +00:00
|
|
|
return dlg.IsSchematicModified();
|
2017-12-24 15:04:02 +00:00
|
|
|
}
|