KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_select_3d_model.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2016 Mario Luzeiro <[email protected]>
5 * Copyright (C) 2016 Cirilo Bernardo <[email protected]>
6 * Copyright (C) 2017-2024 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26
27#include <set>
29#include "project.h"
30#include "3d_cache/3d_info.h"
31#include "3d_cache/3d_cache.h"
35#include <filename_resolver.h>
36#include <pcbnew/footprint.h>
37#include <wx_filename.h>
38
39#include <wx/filedlg.h>
40
41#include <kiplatform/ui.h>
42
43
45 FP_3DMODEL* aModelItem, wxString& prevModelSelectDir,
46 int& prevModelWildcard ) :
48 m_model( aModelItem ),
49 m_cache( aCacheManager ),
50 m_resolver( aCacheManager ? aCacheManager->GetResolver() : nullptr ),
51 m_previousDir( prevModelSelectDir ),
52 m_modelViewer( nullptr )
53{
55 OGL_ATT_LIST::GetAttributesList( ANTIALIASING_MODE::AA_8X ),
56 m_cache );
57 m_modelViewer->SetMinSize( wxSize( 400, -1 ) );
58 m_Sizer3Dviewer->Add( m_modelViewer, 1, wxEXPAND|wxRIGHT, 5 );
59
60 // create the filter list
61 if( NULL != m_cache )
62 {
63 std::list< wxString > const* fl = m_cache->GetFileFilters();
64 std::list< wxString >::const_iterator sL = fl->begin();
65
66 // The files filter string build from list of loaded plugins:
67 wxString filter;
68
69 // The files filter extensions only build from list of loaded plugins:
70 wxString ext_list;
71
72 while( sL != fl->end() )
73 {
74 if( !filter.IsEmpty() )
75 filter.Append( "|" );
76
77 filter.Append( *sL );
78
79 if( !ext_list.IsEmpty() )
80 ext_list.Append( ";" );
81
82 wxString ext = sL->AfterLast( '|' );
83
84 if( ext.Len() > 3 ) // Skip *.*
85 ext_list.Append( ext );
86
87 ++sL;
88 }
89
90 if( !filter.empty() )
91 {
92 if( !ext_list.empty() )
93 {
94 wxString full_filter;
95 full_filter.Printf( _( "All supported files (%s)" ), ext_list );
96 full_filter << '|' << ext_list << '|' << filter;
97 m_FileTree->SetFilter( full_filter );
98 }
99 else
100 {
101 m_FileTree->SetFilter( filter );
102 }
103 }
104 else
105 {
106 m_FileTree->SetFilter( wxFileSelectorDefaultWildcardStr );
107 }
108
109 if( prevModelWildcard >= 0 && prevModelWildcard < (int)fl->size() )
110 {
111 m_FileTree->SetFilterIndex( prevModelWildcard );
112 }
113 else
114 {
115 prevModelWildcard = 0;
116 m_FileTree->SetFilterIndex( 0 );
117 }
118 }
119 else
120 {
121 m_FileTree->SetFilter( wxFileSelectorDefaultWildcardStr );
122 prevModelWildcard = 0;
123 m_FileTree->SetFilterIndex( 0 );
124 }
125
126 // Fix the filter box on the file selector widget so that it always shows the start of
127 // the filter string in the combobox. Otherwise it will only show the end of the string,
128 // which is empty for all but the all supported filters option.
129 wxChoice* filterBox = m_FileTree->GetFilterListCtrl();
131
132 m_FileTree->SetPath( m_previousDir );
134
135 m_modelViewer->Refresh();
136 m_modelViewer->SetFocus();
137
139}
140
141
143{
144 if( !m_model || !m_FileTree )
145 return true;
146
147 m_model->m_Scale.x = 1.0;
148 m_model->m_Scale.y = 1.0;
149 m_model->m_Scale.z = 1.0;
150
151 m_model->m_Rotation.x = 0.0;
152 m_model->m_Rotation.y = 0.0;
153 m_model->m_Rotation.z = 0.0;
154
156 m_model->m_Filename.clear();
157
158 wxString name = m_FileTree->GetFilePath();
159
160 if( name.empty() )
161 return true;
162
163 m_previousDir = m_FileTree->GetPath();
164
165 // file selection mode: retrieve the filename and specify a
166 // path relative to one of the config paths
167 wxFileName fname = m_FileTree->GetFilePath();
168 fname.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS );
169 m_model->m_Filename = m_resolver->ShortenPath( fname.GetFullPath() );
170
171 return true;
172}
173
174
175void DIALOG_SELECT_3DMODEL::OnSelectionChanged( wxCommandEvent& event )
176{
177 if( m_modelViewer )
178 m_modelViewer->Set3DModel( m_FileTree->GetFilePath() );
179}
180
181
182void DIALOG_SELECT_3DMODEL::OnFileActivated( wxCommandEvent& event )
183{
184 if( m_modelViewer )
185 m_modelViewer->Set3DModel( m_FileTree->GetFilePath() );
186
187 EmulateButtonClickIfPresent( wxID_OK );
188}
189
190
191void DIALOG_SELECT_3DMODEL::SetRootDir( wxCommandEvent& event )
192{
193 if( m_FileTree && m_dirChoices->GetSelection() > 0 )
194 {
195 m_FileTree->SetPath( m_dirChoices->GetString( m_dirChoices->GetSelection() ) );
196 m_FileTree->UnselectAll(); // Ensure no unwanted selection
197 }
198}
199
200
201void DIALOG_SELECT_3DMODEL::Cfg3DPaths( wxCommandEvent& event )
202{
203 DIALOG_CONFIGURE_PATHS dlg( this );
204
205 if( dlg.ShowQuasiModal() == wxID_OK )
207}
208
209
211{
212 if( !m_FileTree || !m_resolver || !m_dirChoices )
213 return;
214
215 std::list< SEARCH_PATH > const* md = m_resolver->GetPaths();
216 std::list< SEARCH_PATH >::const_iterator sL = md->begin();
217 std::set< wxString > cl;
218 wxString prjDir;
219
220 // extract the current project dir
221 if( sL != md->end() )
222 {
223 prjDir = sL->m_Pathexp;
224 ++sL;
225 }
226
227 while( sL != md->end() )
228 {
229 if( !sL->m_Pathexp.empty() && sL->m_Pathexp.compare( prjDir ) )
230 cl.insert( sL->m_Pathexp );
231
232 ++sL;
233 }
234
235 if( !cl.empty() )
236 {
237 unsigned int choice = 0;
238 m_dirChoices->Clear();
239 m_dirChoices->Append( "" ); //Insert a blank string at the beginning to allow selection
240
241 if( !prjDir.empty() )
242 {
243 m_dirChoices->Append( prjDir );
244
245 if( prjDir == m_FileTree->GetPath() )
246 choice = 1;
247 }
248
249 std::set< wxString >::const_iterator sI = cl.begin();
250
251 while( sI != cl.end() )
252 {
253 if( *sI == m_FileTree->GetPath() )
254 choice = m_dirChoices->GetCount();
255
256 m_dirChoices->Append( *sI );
257 ++sI;
258 }
259
260 m_dirChoices->SetSelection( choice );
261 }
262
263 return;
264}
defines the basic data associated with a single 3D model.
const char * name
Definition: DXF_plotter.cpp:57
void OnSelectionChanged(wxCommandEvent &event) override
DIALOG_SELECT_3DMODEL(wxWindow *aParent, S3D_CACHE *aCacheManager, FP_3DMODEL *aModelItem, wxString &prevModelSelectDir, int &prevModelWildcard)
void SetRootDir(wxCommandEvent &event) override
FILENAME_RESOLVER * m_resolver
EDA_3D_MODEL_VIEWER * m_modelViewer
void OnFileActivated(wxCommandEvent &event) override
void Cfg3DPaths(wxCommandEvent &event) override
bool TransferDataFromWindow() override
Class DIALOG_SELECT_3D_MODEL_BASE.
int ShowQuasiModal()
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Implement a canvas based on a wxGLCanvas.
void Set3DModel(const S3DMODEL &a3DModel)
Set this model to be displayed.
const std::list< SEARCH_PATH > * GetPaths() const
Return a pointer to the internal path list; the items in:load.
wxString ShortenPath(const wxString &aFullPathName)
Produce a relative path based on the existing search directories or returns the same path if the path...
VECTOR3D m_Offset
3D model offset (mm)
Definition: footprint.h:100
VECTOR3D m_Rotation
3D model rotation (degrees)
Definition: footprint.h:99
VECTOR3D m_Scale
3D model scaling factor (dimensionless)
Definition: footprint.h:98
wxString m_Filename
The 3D shape filename in 3D library.
Definition: footprint.h:102
static const wxGLAttributes GetAttributesList(ANTIALIASING_MODE aAntiAliasingMode, bool aAlpha=false)
Get a list of attributes to pass to wxGLCanvas.
Cache for storing the 3D shapes.
Definition: 3d_cache.h:55
std::list< wxString > const * GetFileFilters() const
Return the list of file filters retrieved from the plugins.
Definition: 3d_cache.cpp:517
T y
Definition: vector3.h:63
T z
Definition: vector3.h:64
T x
Definition: vector3.h:62
#define _(s)
Implements a model viewer canvas.
void EllipsizeChoiceBox(wxChoice *aChoice)
Configure a wxChoice control to ellipsize the shown text in the button with the ellipses placed at th...
Definition: wxgtk/ui.cpp:154
Declaration of the cogl_att_list class.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().
Definition: wx_filename.h:39