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>
|
2019-08-26 10:57:07 +00:00
|
|
|
* Copyright (C) 2014-2019 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
|
|
|
|
*/
|
2014-02-18 21:41:27 +00:00
|
|
|
#ifndef DIALOG_CHOOSE_COMPONENT_H
|
|
|
|
#define DIALOG_CHOOSE_COMPONENT_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>
|
2017-03-08 17:00:07 +00:00
|
|
|
|
|
|
|
class wxStaticBitmap;
|
|
|
|
class wxTextCtrl;
|
|
|
|
class wxStdDialogButtonSizer;
|
|
|
|
class wxDataViewCtrl;
|
|
|
|
class wxHtmlWindow;
|
|
|
|
class wxHtmlLinkEvent;
|
|
|
|
class wxPanel;
|
|
|
|
class wxChoice;
|
|
|
|
class wxButton;
|
|
|
|
class wxTimer;
|
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;
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
class LIB_PART;
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* Dialog class to select a component from the libraries. This is the master
|
|
|
|
* View class in a Model-View-Adapter (mediated MVC) architecture. The other
|
|
|
|
* pieces are in:
|
|
|
|
*
|
2018-07-27 20:47:51 +00:00
|
|
|
* - Adapter: CMP_TREE_MODEL_ADAPTER in common/cmp_tree_model_adapter.h
|
|
|
|
* - Model: CMP_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
|
|
|
|
* DIALOG_CHOOSE_COMPONENT dlg( this, title, adapter, 1 );
|
|
|
|
* 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
|
|
|
* }
|
|
|
|
*
|
|
|
|
*/
|
2017-03-08 17:00:07 +00:00
|
|
|
class DIALOG_CHOOSE_COMPONENT : public DIALOG_SHIM
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-02-24 10:52:08 +00:00
|
|
|
/**
|
|
|
|
* Create dialog to choose component.
|
|
|
|
*
|
2017-03-06 14:50:48 +00:00
|
|
|
* @param aParent a SCH_BASE_FRAME parent window.
|
|
|
|
* @param aTitle Dialog title.
|
2018-07-27 20:47:51 +00:00
|
|
|
* @param aAdapter SYMBOL_TREE_MODEL_ADAPTER::PTR. See CMP_TREE_MODEL_ADAPTER
|
2017-03-06 14:50:48 +00:00
|
|
|
* for documentation.
|
|
|
|
* @param aDeMorganConvert preferred deMorgan conversion
|
|
|
|
* (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.
|
|
|
|
* @param aAllowBrowser show a Select with Browser button
|
2014-02-24 10:52:08 +00:00
|
|
|
*/
|
2014-09-26 10:35:11 +00:00
|
|
|
DIALOG_CHOOSE_COMPONENT( SCH_BASE_FRAME* aParent, const wxString& aTitle,
|
2018-07-27 20:47:51 +00:00
|
|
|
SYMBOL_TREE_MODEL_ADAPTER::PTR& aAdapter, int aDeMorganConvert,
|
|
|
|
bool aAllowFieldEdits, bool aShowFootprints, bool aAllowBrowser );
|
2014-02-14 08:05:04 +00:00
|
|
|
|
2017-03-23 15:52:05 +00:00
|
|
|
~DIALOG_CHOOSE_COMPONENT();
|
|
|
|
|
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().
|
|
|
|
*
|
2017-03-23 00:59:25 +00:00
|
|
|
* For multi-unit components, if the user selects the component itself
|
|
|
|
* rather than picking 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).
|
|
|
|
*
|
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
|
|
|
|
* all units of the symbol, one per click
|
|
|
|
* @return The value of the dialog preference checkbox
|
|
|
|
*/
|
|
|
|
bool GetUseAllUnits() const { return m_useUnits->GetValue(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* place multiple copies of the same symbol on their schematic
|
|
|
|
*
|
|
|
|
* @return The value of the keep symbol preference checkbox
|
|
|
|
*/
|
|
|
|
bool GetKeepSymbol() const { return m_keepSymbol->GetValue(); }
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
/**
|
|
|
|
* Get a list of fields edited by the user.
|
|
|
|
* @return vector of pairs; each.first = field ID, each.second = new value
|
|
|
|
*/
|
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
|
|
|
|
2014-02-14 08:05:04 +00:00
|
|
|
/** Function IsExternalBrowserSelected
|
|
|
|
*
|
2014-02-24 10:52:08 +00:00
|
|
|
* @return true, iff the user pressed the thumbnail view of the component to
|
|
|
|
* launch the component 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
|
|
|
|
2018-04-16 22:18:02 +00:00
|
|
|
static std::mutex g_Mutex;
|
|
|
|
|
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 );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 component, the component is picked.
|
|
|
|
*/
|
|
|
|
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
|
|
|
*/
|
2017-09-15 14:17:44 +00:00
|
|
|
void ShowFootprintFor( LIB_ID const& aLibId );
|
2017-03-08 17:00:07 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
/**
|
|
|
|
* Display the given footprint by name.
|
|
|
|
*/
|
2017-09-15 14:17:44 +00:00
|
|
|
void ShowFootprint( wxString const& aFootprint );
|
2017-03-23 00:59:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Populate the footprint selector for a given alias.
|
|
|
|
*
|
2017-09-15 14:17:44 +00:00
|
|
|
* @param aLibId the #LIB_ID of the selection or invalid to clear
|
2017-03-23 00:59:25 +00:00
|
|
|
*/
|
2017-09-15 14:17:44 +00:00
|
|
|
void PopulateFootprintSelector( LIB_ID const& aLibId );
|
2017-03-23 00:59:25 +00:00
|
|
|
|
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;
|
2019-08-06 06:18:51 +00:00
|
|
|
wxHtmlWindow* 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
|
|
|
|
|
|
|
#endif /* DIALOG_CHOOSE_COMPONENT_H */
|