1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2018-2021 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef SYMBOL_PREVIEW_WIDGET_H
21 #define SYMBOL_PREVIEW_WIDGET_H
22 
23 #include <wx/panel.h>
24 #include <kiway.h>
25 #include <gal/gal_display_options.h>
26 #include <class_draw_panel_gal.h>
27 
28 
29 class LIB_ID;
30 class LIB_SYMBOL;
31 class wxStaticText;
32 class wxSizer;
33 
34 
35 class SYMBOL_PREVIEW_WIDGET: public wxPanel
36 {
37 public:
38 
39     /**
40      * Construct a symbol preview widget.
41      *
42      * @param aParent - parent window
43      * @param aKiway - an active Kiway instance
44      * @param aCanvasType = the type of canvas (GAL_TYPE_OPENGL or GAL_TYPE_CAIRO only)
45      */
46     SYMBOL_PREVIEW_WIDGET( wxWindow* aParent, KIWAY& aKiway,
47                            EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType );
48 
49     ~SYMBOL_PREVIEW_WIDGET() override;
50 
51     /**
52      * Set the contents of the status label and display it.
53      */
54     void SetStatusText( const wxString& aText );
55 
56     /**
57      * Set the currently displayed symbol.
58      */
59     void DisplaySymbol( const LIB_ID& aSymbolID, int aUnit, int aConvert = 0 );
60 
61     void DisplayPart( LIB_SYMBOL* aSymbol, int aUnit, int aConvert = 0 );
62 
63 private:
64     void onSize( wxSizeEvent& aEvent );
65 
66     void fitOnDrawArea();    // set the view scale to fit the item on screen and center
67 
68     KIWAY&                     m_kiway;
69 
70     KIGFX::GAL_DISPLAY_OPTIONS m_galDisplayOptions;
71     EDA_DRAW_PANEL_GAL*        m_preview;
72 
73     wxStaticText*              m_status;
74     wxPanel*                   m_statusPanel;
75     wxSizer*                   m_statusSizer;
76     wxSizer*                   m_outerSizer;
77 
78     /**
79      * A local copy of the #LIB_SYMBOL to display on the canvas.
80      */
81     LIB_SYMBOL*                m_previewItem;
82 
83     /// The bounding box of the current item
84     BOX2I                      m_itemBBox;
85 };
86 
87 
88 #endif // SYMBOL_PREVIEW_WIDGET_H
89