2014-02-14 08:05:04 +00:00
|
|
|
/* -*- c++ -*-
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
|
2017-03-08 17:00:07 +00:00
|
|
|
* Copyright (C) 2017 Chris Pavlina <pavlina.chris@gmail.com>
|
2017-02-19 02:39:55 +00:00
|
|
|
* Copyright (C) 2014-2017 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"
|
2017-03-06 14:50:48 +00:00
|
|
|
#include <cmp_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
|
|
|
|
2017-04-10 14:22:41 +00:00
|
|
|
class COMPONENT_TREE;
|
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;
|
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:
|
|
|
|
*
|
|
|
|
* - Adapter: CMP_TREE_MODEL_ADAPTER in eeschema/cmp_tree_model_adapter.h
|
|
|
|
* - Model: CMP_TREE_NODE and descendants in eeschema/cmp_tree_model.h
|
|
|
|
*
|
|
|
|
* Because everything is tied together in the adapter class, see that file
|
|
|
|
* for thorough documentation. A simple example usage follows:
|
|
|
|
*
|
|
|
|
* // Create the adapter class
|
2017-07-16 15:31:33 +00:00
|
|
|
* auto adapter( CMP_TREE_MODEL_ADAPTER::Create( Prj().SchLibs() ) );
|
2017-03-06 14:50:48 +00:00
|
|
|
*
|
|
|
|
* // Perform any configuration of adapter properties here
|
|
|
|
* adapter->SetPreselectNode( "TL072", 2 );
|
|
|
|
*
|
|
|
|
* // Initialize model from PART_LIBs
|
|
|
|
* for( PART_LIB& lib: *libs )
|
|
|
|
* adapter->AddLibrary( lib );
|
|
|
|
*
|
|
|
|
* // Create and display dialog
|
|
|
|
* DIALOG_CHOOSE_COMPONENT dlg( this, title, adapter, 1 );
|
|
|
|
* bool selected = ( dlg.ShowModal() != wxID_CANCEL );
|
|
|
|
*
|
|
|
|
* // Receive part
|
|
|
|
* if( selected )
|
|
|
|
* {
|
|
|
|
* int unit;
|
|
|
|
* LIB_ALIAS* alias = dlg.GetSelectedAlias( &unit );
|
|
|
|
* do_something( alias, unit );
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
*/
|
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.
|
|
|
|
* @param aAdapter CMP_TREE_MODEL_ADAPTER::PTR. See CMP_TREE_MODEL_ADAPTER
|
|
|
|
* for documentation.
|
|
|
|
* @param aDeMorganConvert preferred deMorgan conversion
|
|
|
|
* (TODO: should happen in dialog)
|
2017-03-23 00:59:25 +00:00
|
|
|
* @param aAllowFieldEdits if false, all functions that allow the user to edit
|
|
|
|
* fields (currently just footprint selection) will not be available.
|
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,
|
2017-03-23 00:59:25 +00:00
|
|
|
CMP_TREE_MODEL_ADAPTER::PTR& aAdapter, int aDeMorganConvert, bool aAllowFieldEdits );
|
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.
|
2014-02-24 10:52:08 +00:00
|
|
|
* @return the alias that has been selected, or NULL if there is none.
|
2014-02-14 08:05:04 +00:00
|
|
|
*/
|
2017-04-10 14:22:41 +00:00
|
|
|
LIB_ALIAS* GetSelectedAlias( int* aUnit = nullptr ) const;
|
2014-02-14 08:05:04 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
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 );
|
|
|
|
void OnCloseTimer( wxTimerEvent& aEvent );
|
2017-03-23 00:59:25 +00:00
|
|
|
void OnProgressTimer( wxTimerEvent& aEvent );
|
2014-02-14 08:05:04 +00:00
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
void OnSchViewDClick( wxMouseEvent& aEvent );
|
|
|
|
void OnSchViewPaint( wxPaintEvent& aEvent );
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Look up the footprint for a given alias and display it.
|
|
|
|
*/
|
|
|
|
void ShowFootprintFor( LIB_ALIAS* aAlias );
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
/**
|
|
|
|
* Display the given footprint by name.
|
|
|
|
*/
|
|
|
|
void ShowFootprint( wxString const& aName );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Populate the footprint selector for a given alias.
|
|
|
|
*
|
|
|
|
* @param aAlias alias, or null to clear
|
|
|
|
*/
|
|
|
|
void PopulateFootprintSelector( LIB_ALIAS* aAlias );
|
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
/**
|
|
|
|
* Display a given component into the schematic symbol preview.
|
|
|
|
*/
|
|
|
|
void RenderPreview( LIB_PART* aComponent, int aUnit );
|
2017-02-19 02:39:55 +00:00
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
wxTimer* m_dbl_click_timer;
|
|
|
|
wxPanel* m_sch_view_ctrl;
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
FOOTPRINT_SELECT_WIDGET* m_fp_sel_ctrl;
|
2017-03-10 19:11:41 +00:00
|
|
|
FOOTPRINT_PREVIEW_WIDGET* m_fp_view_ctrl;
|
2017-04-10 14:22:41 +00:00
|
|
|
COMPONENT_TREE* m_tree;
|
2017-03-08 17:00:07 +00:00
|
|
|
|
|
|
|
SCH_BASE_FRAME* m_parent;
|
2017-03-23 00:59:25 +00:00
|
|
|
int m_deMorganConvert;
|
|
|
|
bool m_allow_field_edits;
|
|
|
|
bool m_external_browser_requested;
|
|
|
|
wxString m_fp_override;
|
|
|
|
|
|
|
|
static FOOTPRINT_ASYNC_LOADER m_fp_loader;
|
|
|
|
static std::unique_ptr<FOOTPRINT_LIST> m_fp_list;
|
|
|
|
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 */
|