diff --git a/3d-viewer/3d_cache/dialogs/3d_cache_dialogs.cpp b/3d-viewer/3d_cache/dialogs/3d_cache_dialogs.cpp index f9ebd5816b..d4f4cb1b1f 100644 --- a/3d-viewer/3d_cache/dialogs/3d_cache_dialogs.cpp +++ b/3d-viewer/3d_cache/dialogs/3d_cache_dialogs.cpp @@ -28,7 +28,7 @@ #include "plugins/3dapi/ifsg_api.h" #include "3d_cache_dialogs.h" #include "dlg_3d_pathconfig.h" -#include "dialog_select_3dmodel.h" +#include "dlg_select_3dmodel.h" bool S3D::Select3DModel( wxWindow* aParent, S3D_CACHE* aCache, @@ -37,33 +37,11 @@ bool S3D::Select3DModel( wxWindow* aParent, S3D_CACHE* aCache, if( NULL == aModel ) return false; - // set the default values to ensure reasonable settings - // even if the user cancels the operation - aModel->scale.x = 1.0; - aModel->scale.y = 1.0; - aModel->scale.z = 1.0; - - aModel->rotation.x = 0.0; - aModel->rotation.y = 0.0; - aModel->rotation.z = 0.0; - - aModel->offset = aModel->rotation; - aModel->filename.empty(); - - DLG_SEL_3DMODEL* dm = new DLG_SEL_3DMODEL( aParent, aCache, + DLG_SELECT_3DMODEL* dm = new DLG_SELECT_3DMODEL( aParent, aCache, aModel, prevModelSelectDir, prevModelWildcard ); if( wxID_OK == dm->ShowModal() ) { - // retrieve the data entry for the 3D model - dm->GetModelData( aModel ); - - // remember the previous settings - prevModelWildcard = dm->GetFilterIndex(); - wxFileName name( dm->GetPath() ); - name.Normalize(); - prevModelSelectDir = name.GetPath(); - delete dm; return true; } diff --git a/3d-viewer/3d_cache/dialogs/dialog_select_3dmodel.cpp b/3d-viewer/3d_cache/dialogs/dialog_select_3dmodel.cpp deleted file mode 100644 index 9915564064..0000000000 --- a/3d-viewer/3d_cache/dialogs/dialog_select_3dmodel.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2015 Cirilo Bernardo - * - * 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 - */ - -#include -#include "3d_cache.h" -#include "dialog_select_3dmodel.h" -#include "panel_prev_model.h" - -static S3D_CACHE* mm = NULL; -static wxFileDialog* fm = NULL; - -static wxWindow* mkPreviewPanel( wxWindow* aParent ) -{ - PANEL_PREV_3D* pp = new PANEL_PREV_3D( aParent, true ); - pp->SetModelManager( mm ); - pp->SetFileSelectorDlg( fm ); - - // ensure reasonable defaults when the dialog starts - S3D_INFO mdat; - mdat.scale.x = 1.0; - mdat.scale.y = 1.0; - mdat.scale.z = 1.0; - pp->SetModelData( &mdat ); - - return (wxWindow*)pp; -} - - -DLG_SEL_3DMODEL::DLG_SEL_3DMODEL( wxWindow* aParent, S3D_CACHE* aManager, - const wxString& aDefaultDir, int aFilterIndex ) - : wxFileDialog( aParent, _( "Select a 3D Model" ), aDefaultDir ) -{ - m_manager = aManager; - mm = aManager; - fm = this; - - long ws = GetWindowStyleFlag(); - ws |= wxFD_FILE_MUST_EXIST; - SetWindowStyleFlag( ws ); - SetExtraControlCreator( mkPreviewPanel ); - - if( NULL != m_manager ) - { - std::list< wxString > const* fl = m_manager->GetFileFilters(); - std::list< wxString >::const_iterator sL = fl->begin(); - std::list< wxString >::const_iterator eL = fl->end(); - wxString filter; - - while( sL != eL ) - { - filter.Append( *sL ); - - ++sL; - - if( sL != eL ) - filter.Append( wxT( "|" ) ); - - } - - if( !filter.empty() ) - SetWildcard( filter ); - - if( aFilterIndex >= 0 && aFilterIndex < (int)fl->size() ) - SetFilterIndex( aFilterIndex ); - } - - return; -} - - -void DLG_SEL_3DMODEL::GetModelData( S3D_INFO* aModel ) -{ - PANEL_PREV_3D* pp = (PANEL_PREV_3D*)GetExtraControl(); - - if( pp ) - pp->GetModelData( aModel ); - - return; -} diff --git a/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig.cpp b/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig.cpp index c28984ac64..69472a2f10 100644 --- a/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig.cpp +++ b/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig.cpp @@ -22,6 +22,7 @@ */ +#include #include "3d_cache/dialogs/dlg_3d_pathconfig.h" #include "3d_cache/3d_filename_resolver.h" diff --git a/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig_base.cpp b/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig_base.cpp index f50aaf4b71..30744b3357 100644 --- a/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig_base.cpp +++ b/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig_base.cpp @@ -9,7 +9,7 @@ /////////////////////////////////////////////////////////////////////////// -DLG_3D_PATH_CONFIG_BASE::DLG_3D_PATH_CONFIG_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) +DLG_3D_PATH_CONFIG_BASE::DLG_3D_PATH_CONFIG_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style ) { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); @@ -79,6 +79,7 @@ DLG_3D_PATH_CONFIG_BASE::DLG_3D_PATH_CONFIG_BASE( wxWindow* parent, wxWindowID i this->SetSizer( bSizer1 ); this->Layout(); + bSizer1->Fit( this ); this->Centre( wxBOTH ); diff --git a/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig_base.fbp b/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig_base.fbp index 7fc9bde394..b14d9eb7b4 100644 --- a/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig_base.fbp +++ b/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig_base.fbp @@ -26,7 +26,7 @@ UI 0 0 - + 0 wxAUI_MGR_DEFAULT @@ -44,15 +44,14 @@ DLG_3D_PATH_CONFIG_BASE - 593,300 - wxDEFAULT_FRAME_STYLE - DIALOG_SHIM; dialog_shim.h + + wxDEFAULT_DIALOG_STYLE + 3D Search Path Configuration - wxTAB_TRAVERSAL - 1 + @@ -68,6 +67,7 @@ + diff --git a/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig_base.h b/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig_base.h index 102aac1ad4..4c4f92b300 100644 --- a/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig_base.h +++ b/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig_base.h @@ -11,9 +11,6 @@ #include #include #include -class DIALOG_SHIM; - -#include "dialog_shim.h" #include #include #include @@ -22,7 +19,7 @@ class DIALOG_SHIM; #include #include #include -#include +#include /////////////////////////////////////////////////////////////////////////// @@ -30,7 +27,7 @@ class DIALOG_SHIM; /////////////////////////////////////////////////////////////////////////////// /// Class DLG_3D_PATH_CONFIG_BASE /////////////////////////////////////////////////////////////////////////////// -class DLG_3D_PATH_CONFIG_BASE : public DIALOG_SHIM +class DLG_3D_PATH_CONFIG_BASE : public wxDialog { private: @@ -52,8 +49,7 @@ class DLG_3D_PATH_CONFIG_BASE : public DIALOG_SHIM public: - DLG_3D_PATH_CONFIG_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("3D Search Path Configuration"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 593,300 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL ); - + DLG_3D_PATH_CONFIG_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("3D Search Path Configuration"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE ); ~DLG_3D_PATH_CONFIG_BASE(); }; diff --git a/3d-viewer/3d_cache/dialogs/dlg_select_3dmodel.cpp b/3d-viewer/3d_cache/dialogs/dlg_select_3dmodel.cpp new file mode 100644 index 0000000000..82358363da --- /dev/null +++ b/3d-viewer/3d_cache/dialogs/dlg_select_3dmodel.cpp @@ -0,0 +1,212 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2016 Cirilo Bernardo + * + * 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 + */ + + +#include "dlg_select_3dmodel.h" +#include "project.h" +#include "3d_cache/3d_info.h" +#include "3d_cache/3d_cache.h" +#include "3d_cache/dialogs/panel_prev_model.h" + +#define ID_FILE_TREE 1000 + +wxBEGIN_EVENT_TABLE( DLG_SELECT_3DMODEL, wxDialog ) + EVT_DIRCTRL_SELECTIONCHANGED( ID_FILE_TREE, DLG_SELECT_3DMODEL::OnSelectionChanged ) + EVT_DIRCTRL_FILEACTIVATED( ID_FILE_TREE, DLG_SELECT_3DMODEL::OnFileActivated ) +wxEND_EVENT_TABLE() + + +DLG_SELECT_3DMODEL::DLG_SELECT_3DMODEL( wxWindow* aParent, S3D_CACHE* aCacheManager, + S3D_INFO* aModelItem, wxString& prevModelSelectDir, int& prevModelWildcard ) : + wxDialog( aParent, wxID_ANY, _( "Select 3D Model" ), wxDefaultPosition, + wxSize( 500,200 ), wxCAPTION | wxRESIZE_BORDER | wxCLOSE_BOX + | wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxSYSTEM_MENU ), + m_model( aModelItem ), m_cache( aCacheManager ), m_previousDir( prevModelSelectDir ), + m_previousFilterIndex( prevModelWildcard ) +{ + this->SetSizeHints( wxSize( 500,200 ), wxDefaultSize ); + + if( NULL != m_cache ) + m_resolver = m_cache->GetResolver(); + else + m_resolver = NULL; + + wxBoxSizer* bSizer1; + bSizer1 = new wxBoxSizer( wxVERTICAL ); + + wxBoxSizer* bSizer2; + bSizer2 = new wxBoxSizer( wxVERTICAL ); + + // set to NULL to avoid segfaults when m_FileTree is instantiated + // and wxGenericDirCtrl events are posted + m_preview = NULL; + + m_FileTree = new wxGenericDirCtrl( this, ID_FILE_TREE, wxEmptyString, wxDefaultPosition, + wxSize( 500,300 ), wxDIRCTRL_3D_INTERNAL | wxDIRCTRL_EDIT_LABELS + | wxDIRCTRL_SELECT_FIRST | wxDIRCTRL_SHOW_FILTERS|wxSUNKEN_BORDER, wxEmptyString, 0 ); + + + m_FileTree->ShowHidden( false ); + m_FileTree->SetMinSize( wxSize( 500,150 ) ); + m_FileTree->SetLabel( wxT( "3D_MODEL_SELECTOR" ) ); + + if( prevModelSelectDir.empty() ) + { + if( NULL != m_resolver ) + { + const std::list< S3D_ALIAS >* ap = m_resolver->GetPaths(); + + if( !ap->empty() ) + { + prevModelSelectDir = ap->front().m_pathexp; + m_FileTree->SetPath( prevModelSelectDir ); + m_FileTree->GetPath(); + } + } + } + else + { + m_FileTree->SetPath( prevModelSelectDir ); + m_FileTree->GetPath(); + } + + bSizer2->Add( m_FileTree, 1, wxEXPAND | wxALL, 5 ); + + + bSizer1->Add( bSizer2, 1, wxEXPAND, 5 ); + + // m_preview must me instantiated after m_FileTree or else it will not + // function as desired due to the constructor depending on the existence + // of m_FileTree to determine the previewer's configuration + wxBoxSizer* previewSizer; + previewSizer = new wxBoxSizer( wxVERTICAL ); + m_preview = new PANEL_PREV_3D( this, m_cache ); + previewSizer->Add( m_preview, 1, wxEXPAND | wxALL, 5 ); + bSizer1->Add( previewSizer, 2, wxEXPAND, 5 ); + + // create the filter list + if( NULL != m_cache ) + { + std::list< wxString > const* fl = m_cache->GetFileFilters(); + std::list< wxString >::const_iterator sL = fl->begin(); + std::list< wxString >::const_iterator eL = fl->end(); + wxString filter; + + while( sL != eL ) + { + filter.Append( *sL ); + + ++sL; + + if( sL != eL ) + filter.Append( wxT( "|" ) ); + + } + + if( !filter.empty() ) + m_FileTree->SetFilter( filter ); + else + m_FileTree->SetFilter( wxT( "*.*" ) ); + + if( prevModelWildcard >= 0 && prevModelWildcard < (int)fl->size() ) + m_FileTree->SetFilterIndex( prevModelWildcard ); + else + { + prevModelWildcard = 0; + m_FileTree->SetFilterIndex( 0 ); + } + } + else + { + m_FileTree->SetFilter( wxT( "*.*" ) ); + prevModelWildcard = 0; + m_FileTree->SetFilterIndex( 0 ); + } + + wxButton* btn_OK = new wxButton( this, wxID_OK, _T( "OK" ) ); + wxButton* btn_Cancel = new wxButton( this, wxID_CANCEL, _T( "Cancel" ) ); + + wxSizer* hSizer1 = new wxBoxSizer( wxHORIZONTAL ); + + hSizer1->Add( btn_OK, 0, wxALL | wxALIGN_RIGHT, 5 ); + hSizer1->Add( btn_Cancel, 0, wxALL | wxALIGN_RIGHT, 5 ); + bSizer1->Add( hSizer1, 0 ); + + this->SetSizerAndFit( bSizer1 ); + this->Layout(); + + this->Centre( wxBOTH ); +} + + +bool DLG_SELECT_3DMODEL::TransferDataFromWindow() +{ + if( NULL == m_model || NULL == m_FileTree ) + return true; + + m_model->scale.x = 1.0; + m_model->scale.y = 1.0; + m_model->scale.z = 1.0; + + m_model->rotation.x = 0.0; + m_model->rotation.y = 0.0; + m_model->rotation.z = 0.0; + + m_model->offset = m_model->rotation; + m_model->filename.empty(); + + wxString fname = m_FileTree->GetFilePath(); + + if( fname.empty() ) + return true; + + m_previousDir = m_FileTree->GetPath(); + m_previousFilterIndex = m_FileTree->GetFilterIndex(); + + m_preview->GetModelData( m_model ); + + return true; +} + + +void DLG_SELECT_3DMODEL::OnSelectionChanged( wxTreeEvent& event ) +{ + if( NULL != m_preview ) + m_preview->UpdateModelName( m_FileTree->GetFilePath() ); + + event.Skip(); + return; +} + + +void DLG_SELECT_3DMODEL::OnFileActivated( wxTreeEvent& event ) +{ + if( NULL != m_preview ) + m_preview->UpdateModelName( m_FileTree->GetFilePath() ); + + event.Skip(); + SetEscapeId( wxID_OK ); + Close(); + + return; +} diff --git a/3d-viewer/3d_cache/dialogs/dialog_select_3dmodel.h b/3d-viewer/3d_cache/dialogs/dlg_select_3dmodel.h similarity index 51% rename from 3d-viewer/3d_cache/dialogs/dialog_select_3dmodel.h rename to 3d-viewer/3d_cache/dialogs/dlg_select_3dmodel.h index b87c007553..a4f3fc3855 100644 --- a/3d-viewer/3d_cache/dialogs/dialog_select_3dmodel.h +++ b/3d-viewer/3d_cache/dialogs/dlg_select_3dmodel.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2015 Cirilo Bernardo + * Copyright (C) 2016 Cirilo Bernardo * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -22,30 +22,47 @@ */ /** - * @file dialog_select_3dmodel.h + * @file dlg_select_3dmodel.h * creates a dialog to select 3D model files */ -#ifndef DIALOG_SELECT_3DMODEL_H -#define DIALOG_SELECT_3DMODEL_H + +#ifndef DLG_SELECT_3DMODEL_H +#define DLG_SELECT_3DMODEL_H #include -#include +#include +#include +#include -class S3D_CACHE; struct S3D_INFO; +class S3D_CACHE; +class S3D_FILENAME_RESOLVER; +class PANEL_PREV_3D; +//class wxGenericDirCtrl; -class DLG_SEL_3DMODEL : public wxFileDialog +class DLG_SELECT_3DMODEL : public wxDialog { private: - S3D_CACHE* m_manager; + S3D_INFO* m_model; // data for the selected model + S3D_CACHE* m_cache; // cache manager + S3D_FILENAME_RESOLVER* m_resolver; // 3D filename resolver + + wxString& m_previousDir; + int& m_previousFilterIndex; + + wxGenericDirCtrl* m_FileTree; + PANEL_PREV_3D* m_preview; public: - DLG_SEL_3DMODEL( wxWindow* aParent, S3D_CACHE* aManager, - const wxString& aDefaultDir, int aFilterIndex ); + DLG_SELECT_3DMODEL( wxWindow* aParent, S3D_CACHE* aCacheManager, S3D_INFO* aModelItem, + wxString& prevModelSelectDir, int& prevModelWildcard ); - // Retrieve model data - void GetModelData( S3D_INFO* aModel ); + bool TransferDataFromWindow(); + void OnSelectionChanged( wxTreeEvent& event ); + void OnFileActivated( wxTreeEvent& event ); + + wxDECLARE_EVENT_TABLE(); }; -#endif // DIALOG_SELECT_3DMODEL_H +#endif // DLG_SELECT_3DMODEL_H diff --git a/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp b/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp index 3236e834b5..3bc7aae036 100644 --- a/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp +++ b/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp @@ -31,13 +31,15 @@ #include #include #include +#include #include #include + +#include "project.h" #include "3d_cache.h" #include "3d_info.h" #include "3d_filename_resolver.h" #include "plugins/3dapi/ifsg_api.h" - #include "panel_prev_model.h" #include "dialog_select_3dmodel.h" #include "3d_cache_dialogs.h" @@ -107,11 +109,14 @@ wxBEGIN_EVENT_TABLE( PANEL_PREV_3D, wxPanel) wxEND_EVENT_TABLE() -PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent, bool hasFileSelector ) : - wxPanel( aParent, -1 ) +PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent, S3D_CACHE* aCacheManager ) : + wxPanel( aParent, -1 ), m_ModelManager( aCacheManager ) { - m_ModelManager = NULL; - m_FileDlg = NULL; + if( NULL != m_ModelManager ) + m_resolver = m_ModelManager->GetResolver(); + else + m_resolver = NULL; + canvas = NULL; model = NULL; xscale = NULL; @@ -130,19 +135,19 @@ PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent, bool hasFileSelector ) : wxBoxSizer* hboxDirChoice = NULL; dirChoices = NULL; - if( hasFileSelector ) + m_FileTree = NULL; + + if( NULL != aParent ) + m_FileTree = (wxGenericDirCtrl*) + aParent->FindWindowByLabel( wxT( "3D_MODEL_SELECTOR" ), aParent ); + + if( NULL != m_FileTree ) { hboxDirChoice = new wxBoxSizer( wxHORIZONTAL ); dirChoices = new wxChoice( this, ID_SET_DIR, wxDefaultPosition, wxSize( 320, 20 ) ); dirChoices->SetMinSize( wxSize( 320, 12 ) ); -#ifdef _WIN32 - // Note: On Win32 the native selector box will truncate text - // if the text is too long. - dirChoices->SetMinSize( wxSize( 450, -1 ) ); -#endif - wxStaticText* stDirChoice = new wxStaticText( this, -1, _( "Paths:" ) ); wxButton* usePath = new wxButton( this, ID_SET_DIR, _( "Change" ) ); wxButton* cfgPaths = new wxButton( this, ID_CFG_PATHS, _( "Configure Paths" ) ); @@ -298,18 +303,23 @@ PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent, bool hasFileSelector ) : mainBox->Add( vbox, 1, wxEXPAND | wxALL, 5 ); - if( hasFileSelector ) + if( NULL != m_FileTree ) { - // NOTE: if/when the FIle Selector preview is implemented + // NOTE: if/when the File Selector preview is implemented // we may need to hide the orientation boxes to ensure the // users have sufficient display area for the browser. // hbox->Hide( vboxOrient, true ); // XXX - // NOTE: for now we always suppress the preview and model orientation // panels while in the file selector - mainBox->Hide( vbox, true ); + //mainBox->Hide( vbox, true ); + + hbox->Hide( vboxOrient, true ); + vboxPrev->Hide( hbBT, true ); + vboxPrev->Hide( hbBB, true ); } + updateDirChoiceList(); SetSizerAndFit( mainBox ); Centre(); @@ -332,45 +342,32 @@ PANEL_PREV_3D::~PANEL_PREV_3D() } -void PANEL_PREV_3D::SetModelManager( S3D_CACHE* aModelManager ) -{ - m_ModelManager = aModelManager; - updateDirChoiceList(); - return; -} - - -void PANEL_PREV_3D::SetFileSelectorDlg( wxFileDialog* aFileDlg ) -{ - m_FileDlg = aFileDlg; - updateDirChoiceList(); - return; -} - - void PANEL_PREV_3D::updateDirChoiceList( void ) { - if( NULL == m_FileDlg || NULL == m_ModelManager || NULL == dirChoices ) + if( NULL == m_FileTree || NULL == m_ModelManager || NULL == dirChoices ) return; - std::list< S3D_ALIAS > const* md = m_ModelManager->GetResolver()->GetPaths(); - std::list< S3D_ALIAS >::const_iterator sL = md->begin(); - std::list< S3D_ALIAS >::const_iterator eL = md->end(); - std::vector< wxString > cl; - - while( sL != eL ) + if( NULL != m_resolver ) { - if( !sL->m_pathexp.empty() && !sL->m_duplicate ) - cl.push_back( sL->m_pathexp ); + std::list< S3D_ALIAS > const* md = m_resolver->GetPaths(); + std::list< S3D_ALIAS >::const_iterator sL = md->begin(); + std::list< S3D_ALIAS >::const_iterator eL = md->end(); + std::vector< wxString > cl; - ++sL; - } + while( sL != eL ) + { + if( !sL->m_pathexp.empty() && !sL->m_duplicate ) + cl.push_back( sL->m_pathexp ); - if( !cl.empty() ) - { - dirChoices->Clear(); - dirChoices->Append( (int)cl.size(), &cl[0] ); - dirChoices->Select( 0 ); + ++sL; + } + + if( !cl.empty() ) + { + dirChoices->Clear(); + dirChoices->Append( (int)cl.size(), &cl[0] ); + dirChoices->Select( 0 ); + } } return; @@ -379,10 +376,10 @@ void PANEL_PREV_3D::updateDirChoiceList( void ) void PANEL_PREV_3D::SetRootDir( wxCommandEvent& event ) { - if( !m_FileDlg ) + if( !m_FileTree ) return; - m_FileDlg->SetDirectory( dirChoices->GetString( dirChoices->GetSelection() ) ); + m_FileTree->SetPath( dirChoices->GetString( dirChoices->GetSelection() ) ); return; } @@ -390,13 +387,8 @@ void PANEL_PREV_3D::SetRootDir( wxCommandEvent& event ) void PANEL_PREV_3D::Cfg3DPaths( wxCommandEvent& event ) { - if( !m_FileDlg || !m_ModelManager ) - return; - - if( S3D::Configure3DPaths( this, m_ModelManager->GetResolver() ) ) + if( S3D::Configure3DPaths( this, m_resolver ) ) updateDirChoiceList(); - - return; } @@ -414,9 +406,9 @@ void PANEL_PREV_3D::View3DUpdate( wxCommandEvent& event ) std::cout << "Update 3D View\n"; // update the model filename if appropriate - if( NULL != m_FileDlg ) + if( NULL != m_FileTree ) { - wxString modelName = m_FileDlg->GetCurrentlySelectedFilename(); + wxString modelName = m_FileTree->GetFilePath(); UpdateModelName( modelName ); } @@ -482,7 +474,7 @@ void PANEL_PREV_3D::GetModelData( S3D_INFO* aModel ) // panel is not embedded in a file selector dialog. This conditional // execution should be removed once the cross-platform issues are // fixed. - if( NULL == m_FileDlg ) + if( NULL == m_FileTree ) { SGPOINT scale; SGPOINT rotation; @@ -496,14 +488,14 @@ void PANEL_PREV_3D::GetModelData( S3D_INFO* aModel ) } // return if we are not in file selection mode - if( NULL == m_FileDlg ) + if( NULL == m_FileTree ) return; // file selection mode: retrieve the filename and specify a // path relative to one of the config paths - wxFileName fname = m_FileDlg->GetPath(); + wxFileName fname = m_FileTree->GetFilePath(); fname.Normalize(); - aModel->filename = m_ModelManager->GetResolver()->ShortenPath( fname.GetFullPath() ); + aModel->filename = m_resolver->ShortenPath( fname.GetFullPath() ); return; } @@ -523,7 +515,6 @@ void PANEL_PREV_3D::SetModelData( S3D_INFO const* aModel ) yoff->SetValue( wxString::FromDouble( aModel->offset.y ) ); zoff->SetValue( wxString::FromDouble( aModel->offset.z ) ); - modelInfo = *aModel; UpdateModelName( aModel->filename ); return; @@ -534,6 +525,8 @@ void PANEL_PREV_3D::UpdateModelName( wxString const& aModelName ) { bool newModel = false; + modelInfo.filename = aModelName; + // if the model name is a directory simply clear the current model if( aModelName.empty() || wxFileName::DirExists( aModelName ) ) { @@ -543,11 +536,7 @@ void PANEL_PREV_3D::UpdateModelName( wxString const& aModelName ) else { wxString newModelFile; - - if( m_ModelManager ) - newModelFile = m_ModelManager->GetResolver()->ResolvePath( aModelName ); - else if( wxFileName::FileExists( aModelName ) ) - newModelFile = aModelName; + newModelFile = m_resolver->ResolvePath( aModelName ); if( newModelFile.empty() ) { @@ -592,7 +581,10 @@ void PANEL_PREV_3D::UpdateModelName( wxString const& aModelName ) return; } - model = m_ModelManager->GetModel( modelInfo.filename ); + if( NULL != m_ModelManager ) + model = m_ModelManager->GetModel( modelInfo.filename ); + else + model = NULL; if( NULL == model ) { @@ -685,7 +677,10 @@ void PANEL_PREV_3D::updateOrientation( wxCommandEvent &event ) canvas->Clear3DModel(); - model = m_ModelManager->GetModel( modelInfo.filename ); + if( NULL != m_ModelManager ) + model = m_ModelManager->GetModel( modelInfo.filename ); + else + model = NULL; if( model ) { diff --git a/3d-viewer/3d_cache/dialogs/panel_prev_model.h b/3d-viewer/3d_cache/dialogs/panel_prev_model.h index 1aae21e017..500836e29c 100644 --- a/3d-viewer/3d_cache/dialogs/panel_prev_model.h +++ b/3d-viewer/3d_cache/dialogs/panel_prev_model.h @@ -40,17 +40,17 @@ #include "plugins/3dapi/c3dmodel.h" #include "3d_cache/3d_info.h" -class S3D_CACHE; +class S3D_CACHE; +class S3D_FILENAME_RESOLVER; class C3D_MODEL_VIEWER; +class wxGenericDirCtrl; class PANEL_PREV_3D : public wxPanel { public: - PANEL_PREV_3D( wxWindow* aParent, bool hasFileSelector = false ); + PANEL_PREV_3D( wxWindow* aParent, S3D_CACHE* aCacheManager ); ~PANEL_PREV_3D(); - void SetModelManager( S3D_CACHE* aModelManager ); - void SetFileSelectorDlg( wxFileDialog* aFileDlg ); void SetRootDir( wxCommandEvent& event ); void Cfg3DPaths( wxCommandEvent& event ); // 3D views @@ -72,7 +72,8 @@ public: private: wxString currentModelFile; S3D_CACHE* m_ModelManager; - wxFileDialog* m_FileDlg; + S3D_FILENAME_RESOLVER* m_resolver; + wxGenericDirCtrl* m_FileTree; wxChoice* dirChoices; wxTextCtrl* xscale; wxTextCtrl* yscale; diff --git a/3d-viewer/CMakeLists.txt b/3d-viewer/CMakeLists.txt index bdd1b32094..74845fae9b 100644 --- a/3d-viewer/CMakeLists.txt +++ b/3d-viewer/CMakeLists.txt @@ -56,7 +56,7 @@ set(3D-VIEWER_SRCS ${DIR_DLG}/3d_cache_dialogs.cpp ${DIR_DLG}/dlg_3d_pathconfig_base.cpp ${DIR_DLG}/dlg_3d_pathconfig.cpp - ${DIR_DLG}/dialog_select_3dmodel.cpp + ${DIR_DLG}/dlg_select_3dmodel.cpp ${DIR_DLG}/panel_prev_model.cpp 3d_model_viewer/c3d_model_viewer.cpp 3d_rendering/3d_render_ogl_legacy/c_ogl_3dmodel.cpp diff --git a/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp b/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp index bf38f54a96..a12f4c1395 100644 --- a/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp +++ b/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp @@ -70,8 +70,7 @@ DIALOG_MODULE_BOARD_EDITOR::DIALOG_MODULE_BOARD_EDITOR( PCB_EDIT_FRAME* aParent icon.CopyFromBitmap( KiBitmap( icon_modedit_xpm ) ); SetIcon( icon ); - m_PreviewPane = new PANEL_PREV_3D( m_Panel3D, false ); - m_PreviewPane->SetModelManager( Prj().Get3DCacheManager() ); + m_PreviewPane = new PANEL_PREV_3D( m_Panel3D, aParent->Prj().Get3DCacheManager() ); bLowerSizer3D->Add( m_PreviewPane, 1, wxEXPAND, 5 ); InitModeditProperties(); diff --git a/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp b/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp index 37b07ee88e..fe72ebec54 100644 --- a/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp +++ b/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp @@ -70,8 +70,7 @@ DIALOG_MODULE_MODULE_EDITOR::DIALOG_MODULE_MODULE_EDITOR( FOOTPRINT_EDIT_FRAME* icon.CopyFromBitmap( KiBitmap( icon_modedit_xpm ) ); SetIcon( icon ); - m_PreviewPane = new PANEL_PREV_3D( m_Panel3D, false ); - m_PreviewPane->SetModelManager( Prj().Get3DCacheManager() ); + m_PreviewPane = new PANEL_PREV_3D( m_Panel3D, aParent->Prj().Get3DCacheManager() ); bLowerSizer3D->Add( m_PreviewPane, 1, wxEXPAND, 5 ); m_FootprintNameCtrl->SetValidator( FILE_NAME_CHAR_VALIDATOR() );