2019-08-26 10:57:07 +00:00
|
|
|
/*
|
2014-02-14 08:05:04 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
|
2022-04-16 22:55:19 +00:00
|
|
|
* Copyright (C) 2014-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-02-14 08:05:04 +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-10 14:10:55 +00:00
|
|
|
#ifndef DIALOG_CHOOSE_SYMBOL_H
|
|
|
|
#define DIALOG_CHOOSE_SYMBOL_H
|
2014-02-14 08:05:04 +00:00
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
#include "dialog_shim.h"
|
2018-07-27 20:47:51 +00:00
|
|
|
#include <symbol_tree_model_adapter.h>
|
2017-03-23 00:59:25 +00:00
|
|
|
#include <footprint_info.h>
|
2021-10-10 12:52:37 +00:00
|
|
|
#include <html_window.h>
|
2017-03-08 17:00:07 +00:00
|
|
|
|
2021-06-03 11:49:49 +00:00
|
|
|
class wxCheckBox;
|
2017-03-08 17:00:07 +00:00
|
|
|
class wxStaticBitmap;
|
|
|
|
class wxTextCtrl;
|
|
|
|
class wxStdDialogButtonSizer;
|
|
|
|
class wxDataViewCtrl;
|
|
|
|
class wxHtmlLinkEvent;
|
|
|
|
class wxPanel;
|
|
|
|
class wxChoice;
|
|
|
|
class wxButton;
|
|
|
|
class wxTimer;
|
2021-06-03 11:49:49 +00:00
|
|
|
class wxSplitterWindow;
|
2014-02-14 08:05:04 +00:00
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
class LIB_TREE;
|
2018-08-28 13:26:39 +00:00
|
|
|
class SYMBOL_PREVIEW_WIDGET;
|
2017-03-10 19:11:41 +00:00
|
|
|
class FOOTPRINT_PREVIEW_WIDGET;
|
2017-03-23 00:59:25 +00:00
|
|
|
class FOOTPRINT_SELECT_WIDGET;
|
2014-02-24 10:52:08 +00:00
|
|
|
class LIB_ALIAS;
|
2014-09-26 10:35:11 +00:00
|
|
|
class SCH_BASE_FRAME;
|
2018-08-28 13:26:39 +00:00
|
|
|
class SCH_DRAW_PANEL;
|
2014-02-14 08:05:04 +00:00
|
|
|
|
2017-03-06 14:50:48 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-08 18:30:14 +00:00
|
|
|
* Dialog class to select a symbol from the libraries. This is the master View class in a
|
|
|
|
* Model-View-Adapter (mediated MVC) architecture. The other pieces are in:
|
2017-03-06 14:50:48 +00:00
|
|
|
*
|
2021-06-10 14:10:55 +00:00
|
|
|
* - Adapter: SYM_TREE_MODEL_ADAPTER in common/cmp_tree_model_adapter.h
|
|
|
|
* - Model: SYM_TREE_NODE and descendants in common/cmp_tree_model.h
|
2017-03-06 14:50:48 +00:00
|
|
|
*
|
|
|
|
* Because everything is tied together in the adapter class, see that file
|
|
|
|
* for thorough documentation. A simple example usage follows:
|
|
|
|
*
|
|
|
|
* // Create the adapter class
|
2018-07-27 20:47:51 +00:00
|
|
|
* auto adapter( SYMBOL_TREE_MODEL_ADAPTER::Create( Prj().SchSymbolLibTable() ) );
|
2017-03-06 14:50:48 +00:00
|
|
|
*
|
|
|
|
* // Perform any configuration of adapter properties here
|
2017-09-15 14:17:44 +00:00
|
|
|
* adapter->SetPreselectNode( "LIB_NICKNAME", "SYMBO_NAME", 2 );
|
2017-03-06 14:50:48 +00:00
|
|
|
*
|
2017-09-15 14:17:44 +00:00
|
|
|
* // Initialize model from #SYMBOL_LIB_TABLE
|
|
|
|
* libNicknames = libs->GetLogicalLibs();
|
|
|
|
*
|
|
|
|
* for( auto nickname : libNicknames )
|
|
|
|
* adapter->AddLibrary( nickname );
|
2017-03-06 14:50:48 +00:00
|
|
|
*
|
|
|
|
* // Create and display dialog
|
2020-12-08 18:30:14 +00:00
|
|
|
* DIALOG_CHOOSE_SYMBOL dlg( this, title, adapter, 1 );
|
2017-03-06 14:50:48 +00:00
|
|
|
* bool selected = ( dlg.ShowModal() != wxID_CANCEL );
|
|
|
|
*
|
|
|
|
* // Receive part
|
|
|
|
* if( selected )
|
|
|
|
* {
|
|
|
|
* int unit;
|
2017-09-15 14:17:44 +00:00
|
|
|
* #LIB_ID id = dlg.GetSelectedAlias( &unit );
|
|
|
|
* do_something( id, unit );
|
2017-03-06 14:50:48 +00:00
|
|
|
* }
|
|
|
|
*
|
|
|
|
*/
|
2020-12-08 18:30:14 +00:00
|
|
|
class DIALOG_CHOOSE_SYMBOL : public DIALOG_SHIM
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-02-24 10:52:08 +00:00
|
|
|
/**
|
2021-05-05 21:41:51 +00:00
|
|
|
* Create dialog to choose symbol.
|
2014-02-24 10:52:08 +00:00
|
|
|
*
|
2017-03-06 14:50:48 +00:00
|
|
|
* @param aParent a SCH_BASE_FRAME parent window.
|
|
|
|
* @param aTitle Dialog title.
|
2021-06-10 14:10:55 +00:00
|
|
|
* @param aAdapter SYMBOL_TREE_MODEL_ADAPTER::PTR. See SYM_TREE_MODEL_ADAPTER
|
2017-03-06 14:50:48 +00:00
|
|
|
* for documentation.
|
2021-03-21 17:31:23 +00:00
|
|
|
* @param aDeMorganConvert preferred deMorgan conversion.
|
2017-03-06 14:50:48 +00:00
|
|
|
* (TODO: should happen in dialog)
|
2018-07-27 20:47:51 +00:00
|
|
|
* @param aAllowFieldEdits if false, all functions that allow the user to edit fields
|
|
|
|
* (currently just footprint selection) will not be available.
|
|
|
|
* @param aShowFootprints if false, all footprint preview and selection features are
|
|
|
|
* disabled. This forces aAllowFieldEdits false too.
|
2021-03-21 17:31:23 +00:00
|
|
|
* @param aAllowBrowser show a Select with Browser button.
|
2014-02-24 10:52:08 +00:00
|
|
|
*/
|
2020-12-08 18:30:14 +00:00
|
|
|
DIALOG_CHOOSE_SYMBOL( SCH_BASE_FRAME* aParent, const wxString& aTitle,
|
|
|
|
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& aAdapter,
|
|
|
|
int aDeMorganConvert, bool aAllowFieldEdits, bool aShowFootprints,
|
|
|
|
bool aAllowBrowser );
|
2014-02-14 08:05:04 +00:00
|
|
|
|
2020-12-08 18:30:14 +00:00
|
|
|
~DIALOG_CHOOSE_SYMBOL();
|
2017-03-23 15:52:05 +00:00
|
|
|
|
2017-04-10 14:22:41 +00:00
|
|
|
/**
|
2014-02-14 08:05:04 +00:00
|
|
|
* To be called after this dialog returns from ShowModal().
|
|
|
|
*
|
2021-06-14 18:00:08 +00:00
|
|
|
* For multi-unit symbols, if the user selects the symbol itself rather than picking
|
2021-05-05 21:41:51 +00:00
|
|
|
* an individual unit, 0 will be returned in aUnit.
|
|
|
|
* Beware that this is an invalid unit number - this should be replaced with whatever
|
|
|
|
* default is desired (usually 1).
|
2017-03-23 00:59:25 +00:00
|
|
|
*
|
2014-02-18 21:41:27 +00:00
|
|
|
* @param aUnit if not NULL, the selected unit is filled in here.
|
2017-09-15 14:17:44 +00:00
|
|
|
* @return the #LIB_ID of the symbol that has been selected.
|
2014-02-14 08:05:04 +00:00
|
|
|
*/
|
2017-09-15 14:17:44 +00:00
|
|
|
LIB_ID GetSelectedLibId( int* aUnit = nullptr ) const;
|
2014-02-14 08:05:04 +00:00
|
|
|
|
2019-10-29 05:06:39 +00:00
|
|
|
/**
|
|
|
|
* To be called after this dialog returns from ShowModal()
|
|
|
|
*
|
|
|
|
* In the case of multi-unit symbols, this preferences asks to iterate through
|
2021-03-21 17:31:23 +00:00
|
|
|
* all units of the symbol, one per click.
|
|
|
|
*
|
|
|
|
* @return The value of the dialog preference checkbox.
|
2019-10-29 05:06:39 +00:00
|
|
|
*/
|
2021-06-03 11:49:49 +00:00
|
|
|
bool GetUseAllUnits() const;
|
2019-10-29 05:06:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* To be called after this dialog returns from ShowModal()
|
|
|
|
*
|
|
|
|
* Keeps a new copy of the symbol on the mouse cursor, allowing the user to rapidly
|
2021-03-21 17:31:23 +00:00
|
|
|
* place multiple copies of the same symbol on their schematic.
|
2019-10-29 05:06:39 +00:00
|
|
|
*
|
2021-03-21 17:31:23 +00:00
|
|
|
* @return The value of the keep symbol preference checkbox.
|
2019-10-29 05:06:39 +00:00
|
|
|
*/
|
2021-06-03 11:49:49 +00:00
|
|
|
bool GetKeepSymbol() const;
|
2019-10-29 05:06:39 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
/**
|
|
|
|
* Get a list of fields edited by the user.
|
2021-03-21 17:31:23 +00:00
|
|
|
*
|
|
|
|
* @return vector of pairs; each.first = field ID, each.second = new value.
|
2017-03-23 00:59:25 +00:00
|
|
|
*/
|
2017-04-10 14:22:41 +00:00
|
|
|
std::vector<std::pair<int, wxString>> GetFields() const
|
|
|
|
{
|
|
|
|
return m_field_edits;
|
|
|
|
}
|
2017-03-23 00:59:25 +00:00
|
|
|
|
2021-03-21 17:31:23 +00:00
|
|
|
/**
|
2021-05-05 21:41:51 +00:00
|
|
|
* @return true if the user requested the symbol browser.
|
2014-02-14 08:05:04 +00:00
|
|
|
*/
|
2017-03-23 00:59:25 +00:00
|
|
|
bool IsExternalBrowserSelected() const
|
|
|
|
{
|
|
|
|
return m_external_browser_requested;
|
|
|
|
}
|
2014-02-14 08:05:04 +00:00
|
|
|
|
|
|
|
protected:
|
2017-03-08 17:00:07 +00:00
|
|
|
static constexpr int DblClickDelay = 100; // milliseconds
|
|
|
|
|
|
|
|
wxPanel* ConstructRightPanel( wxWindow* aParent );
|
2014-02-14 08:05:04 +00:00
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
void OnInitDialog( wxInitDialogEvent& aEvent );
|
2020-10-25 09:02:07 +00:00
|
|
|
void OnCharHook( wxKeyEvent& aEvt ) override;
|
2017-03-08 17:00:07 +00:00
|
|
|
void OnCloseTimer( wxTimerEvent& aEvent );
|
2018-07-27 20:47:51 +00:00
|
|
|
void OnUseBrowser( wxCommandEvent& aEvent );
|
2014-02-14 08:05:04 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
void OnFootprintSelected( wxCommandEvent& aEvent );
|
2017-06-25 21:13:39 +00:00
|
|
|
void OnComponentPreselected( wxCommandEvent& aEvent );
|
|
|
|
|
|
|
|
/**
|
2021-05-05 21:41:51 +00:00
|
|
|
* Handle the selection of an item. This is called when either the search box or the tree
|
|
|
|
* receive an Enter, or the tree receives a double click.
|
|
|
|
* If the item selected is a category, it is expanded or collapsed; if it is a symbol, the
|
|
|
|
* symbol is picked.
|
2017-06-25 21:13:39 +00:00
|
|
|
*/
|
|
|
|
void OnComponentSelected( wxCommandEvent& aEvent );
|
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
/**
|
2017-09-15 14:17:44 +00:00
|
|
|
* Look up the footprint for a given symbol specified in the #LIB_ID and display it.
|
2017-03-08 17:00:07 +00:00
|
|
|
*/
|
2021-07-27 12:22:27 +00:00
|
|
|
void ShowFootprintFor( const LIB_ID& aLibId );
|
2017-03-08 17:00:07 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
/**
|
|
|
|
* Display the given footprint by name.
|
|
|
|
*/
|
2021-07-27 12:22:27 +00:00
|
|
|
void ShowFootprint( const wxString& aFootprint );
|
2017-03-23 00:59:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Populate the footprint selector for a given alias.
|
|
|
|
*
|
2021-03-21 17:31:23 +00:00
|
|
|
* @param aLibId the #LIB_ID of the selection or invalid to clear.
|
2017-03-23 00:59:25 +00:00
|
|
|
*/
|
2021-07-27 12:22:27 +00:00
|
|
|
void PopulateFootprintSelector( const LIB_ID& aLibId );
|
2017-03-23 00:59:25 +00:00
|
|
|
|
2021-03-21 17:31:23 +00:00
|
|
|
public:
|
|
|
|
static std::mutex g_Mutex;
|
|
|
|
|
|
|
|
protected:
|
2022-04-16 22:55:19 +00:00
|
|
|
static wxString g_searchString;
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
wxTimer* m_dbl_click_timer;
|
2018-08-28 13:26:39 +00:00
|
|
|
SYMBOL_PREVIEW_WIDGET* m_symbol_preview;
|
2018-07-27 20:47:51 +00:00
|
|
|
wxButton* m_browser_button;
|
|
|
|
wxSplitterWindow* m_hsplitter;
|
|
|
|
wxSplitterWindow* m_vsplitter;
|
2017-03-08 17:00:07 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
FOOTPRINT_SELECT_WIDGET* m_fp_sel_ctrl;
|
2018-07-27 20:47:51 +00:00
|
|
|
FOOTPRINT_PREVIEW_WIDGET* m_fp_preview;
|
2019-10-29 05:06:39 +00:00
|
|
|
wxCheckBox* m_keepSymbol;
|
|
|
|
wxCheckBox* m_useUnits;
|
2018-08-28 13:26:39 +00:00
|
|
|
LIB_TREE* m_tree;
|
2021-10-10 12:52:37 +00:00
|
|
|
HTML_WINDOW* m_details;
|
2018-07-27 20:47:51 +00:00
|
|
|
|
|
|
|
SCH_BASE_FRAME* m_parent;
|
|
|
|
int m_deMorganConvert;
|
|
|
|
bool m_allow_field_edits;
|
|
|
|
bool m_show_footprints;
|
|
|
|
bool m_external_browser_requested;
|
|
|
|
wxString m_fp_override;
|
2017-03-23 00:59:25 +00:00
|
|
|
|
2018-03-25 12:48:13 +00:00
|
|
|
std::vector<std::pair<int, wxString>> m_field_edits;
|
2014-02-14 08:05:04 +00:00
|
|
|
};
|
2014-02-18 21:41:27 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
#endif /* DIALOG_CHOOSE_SYMBOL_H */
|