From 54940002f91f605753353084d7333dad16cd2e27 Mon Sep 17 00:00:00 2001 From: Cirilo Bernardo Date: Mon, 18 Jan 2016 19:53:35 +1100 Subject: [PATCH] Implemented 3D search path configuration GUI --- 3d-viewer/3d_cache/3d_filename_resolver.cpp | 67 ++-- .../3d_cache/dialogs/dlg_3d_pathconfig.cpp | 24 +- .../dialogs/dlg_3d_pathconfig_base.cpp | 12 +- .../dialogs/dlg_3d_pathconfig_base.fbp | 287 +++++++++--------- .../3d_cache/dialogs/dlg_3d_pathconfig_base.h | 2 +- 5 files changed, 228 insertions(+), 164 deletions(-) diff --git a/3d-viewer/3d_cache/3d_filename_resolver.cpp b/3d-viewer/3d_cache/3d_filename_resolver.cpp index f904a12932..c731598839 100644 --- a/3d-viewer/3d_cache/3d_filename_resolver.cpp +++ b/3d-viewer/3d_cache/3d_filename_resolver.cpp @@ -150,20 +150,10 @@ bool S3D_FILENAME_RESOLVER::createPathList( void ) lpath.m_description = _( "Current project directory" ); m_Paths.push_back( lpath ); - if( wxGetEnv( wxT( "KISYS3DMOD" ), &kmod ) && !kmod.empty() ) - { - wxFileName tmp( kmod ); - wxString kpath = tmp.GetFullPath(); - - if( tmp.Normalize() && lpath.m_pathexp.Cmp( kpath ) ) - { - lpath.m_alias = wxT( "KISYS3DMOD" ); - lpath.m_pathvar = wxT( "${KISYS3DMOD}" ); - lpath.m_pathexp = kpath; - lpath.m_description = _( "Legacy 3D environment path" ); - addPath( lpath ); - } - } + lpath.m_alias = wxT( "KISYS3DMOD" ); + lpath.m_pathvar = wxT( "${KISYS3DMOD}" ); + lpath.m_description = _( "Legacy 3D environment path" ); + addPath( lpath ); if( !m_ConfigDir.empty() ) readPathList(); @@ -499,6 +489,10 @@ bool S3D_FILENAME_RESOLVER::readPathList( void ) if( !getHollerith( cfgLine, idx, al.m_alias ) ) continue; + // never add on KISYS3DMOD from a config file + if( !al.m_alias.Cmp( wxT( "KISYS3DMOD" ) ) ) + continue; + if( !getHollerith( cfgLine, idx, al.m_pathvar ) ) continue; @@ -524,16 +518,40 @@ bool S3D_FILENAME_RESOLVER::writePathList( void ) std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; wxString errmsg = _( "3D configuration directory is unknown" ); std::cerr << " * " << errmsg.ToUTF8() << "\n"; + wxMessageBox( errmsg, _T( "Write 3D search path list" ) ); + return false; } - if( m_Paths.empty() || 1 == m_Paths.size() ) - return false; - wxFileName cfgpath( m_ConfigDir, S3D_RESOLVER_CONFIG ); wxString cfgname = cfgpath.GetFullPath(); std::ofstream cfgFile; + if( m_Paths.empty() || 1 == m_Paths.size() ) + { + wxMessageDialog md( NULL, + _T( "3D search path list is empty;\ncontinue to write empty file?" ), + _T( "Write 3D search path list" ), wxYES_NO ); + + if( md.ShowModal() == wxID_YES ) + { + cfgFile.open( cfgname.ToUTF8(), std::ios_base::trunc ); + + if( !cfgFile.is_open() ) + { + wxMessageBox( _T( "Could not open configuration file" ), + _T( "Write 3D search path list" ) ); + + return false; + } + + cfgFile.close(); + return true; + } + + return false; + } + cfgFile.open( cfgname.ToUTF8(), std::ios_base::trunc ); if( !cfgFile.is_open() ) @@ -541,6 +559,9 @@ bool S3D_FILENAME_RESOLVER::writePathList( void ) std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; wxString errmsg = _( "could not open configuration file " ); std::cerr << " * " << errmsg.ToUTF8() << " '" << cfgname.ToUTF8() << "'\n"; + wxMessageBox( _T( "Could not open configuration file" ), + _T( "Write 3D search path list" ) ); + return false; } @@ -554,6 +575,13 @@ bool S3D_FILENAME_RESOLVER::writePathList( void ) while( sPL != ePL ) { + // never write the KISYS3DMOD entry + if( !sPL->m_alias.Cmp( wxT( "KISYS3DMOD") ) ) + { + ++sPL; + continue; + } + tstr = sPL->m_alias.ToUTF8(); cfgFile << "\"" << tstr.size() << ":" << tstr << "\","; tstr = sPL->m_pathvar.ToUTF8(); @@ -567,7 +595,12 @@ bool S3D_FILENAME_RESOLVER::writePathList( void ) cfgFile.close(); if( bad ) + { + wxMessageBox( _T( "Problems writing configuration file" ), + _T( "Write 3D search path list" ) ); + return false; + } return true; } diff --git a/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig.cpp b/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig.cpp index 6660c3b74e..b364401765 100644 --- a/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig.cpp +++ b/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig.cpp @@ -29,6 +29,10 @@ DLG_3D_PATH_CONFIG::DLG_3D_PATH_CONFIG( wxWindow* aParent, S3D_FILENAME_RESOLVER DLG_3D_PATH_CONFIG_BASE( aParent ), m_resolver( aResolver ) { m_Aliases->EnableEditing( true ); + m_Aliases->SetColMinimalWidth( 0, 80 ); + m_Aliases->SetColMinimalWidth( 1, 300 ); + m_Aliases->SetColMinimalWidth( 2, 120 ); + m_Aliases->SetColMinimalAcceptableWidth( 80 ); if( m_resolver ) { @@ -42,10 +46,10 @@ DLG_3D_PATH_CONFIG::DLG_3D_PATH_CONFIG( wxWindow* aParent, S3D_FILENAME_RESOLVER if( listsize > 0 ) m_curdir = rpaths->front().m_pathexp; - if( listsize < 2 ) + if( listsize < 3 ) return; - listsize = listsize - 1 - m_Aliases->GetNumberRows(); + listsize = listsize - 2 - m_Aliases->GetNumberRows(); // note: if the list allocation fails we have bigger problems // and there is no point in trying to notify the user here @@ -56,7 +60,9 @@ DLG_3D_PATH_CONFIG::DLG_3D_PATH_CONFIG( wxWindow* aParent, S3D_FILENAME_RESOLVER std::list< S3D_ALIAS >::const_iterator eL = rpaths->end(); int nitems = 0; - // skip the first entry which is always the current project dir + // skip the first 2 entries which are always the current project dir + // and KISYS3DMOD + ++sL; ++sL; wxGridCellTextEditor* pEdAlias; @@ -74,10 +80,9 @@ DLG_3D_PATH_CONFIG::DLG_3D_PATH_CONFIG( wxWindow* aParent, S3D_FILENAME_RESOLVER ++sL; } - m_Aliases->AutoSizeColumns(); + m_Aliases->AutoSize(); } - Layout(); Fit(); SetMinSize( GetSize() ); @@ -88,7 +93,12 @@ DLG_3D_PATH_CONFIG::DLG_3D_PATH_CONFIG( wxWindow* aParent, S3D_FILENAME_RESOLVER bool DLG_3D_PATH_CONFIG::TransferDataFromWindow() { if( NULL == m_resolver ) + { + wxMessageBox( _T( "[BUG] No valid resolver; data will not be updated" ), + _T( "Update 3D search path list" ) ); + return false; + } std::vector alist; S3D_ALIAS alias; @@ -129,6 +139,8 @@ void DLG_3D_PATH_CONFIG::OnAddAlias( wxCommandEvent& event ) pEdAlias->SetValidator( m_aliasValidator ); pEdAlias->DecRef(); m_Aliases->SelectRow( ni, false ); + m_Aliases->AutoSize(); + Fit(); // TODO: set the editors on any newly created rows } @@ -164,6 +176,8 @@ void DLG_3D_PATH_CONFIG::OnDelAlias( wxCommandEvent& event ) ni = m_Aliases->GetNumberRows() - 1; m_Aliases->SelectRow( ni, false ); + m_Aliases->AutoSize(); + Fit(); } else { 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 a81e45db31..f50aaf4b71 100644 --- a/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig_base.cpp +++ b/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig_base.cpp @@ -16,6 +16,9 @@ DLG_3D_PATH_CONFIG_BASE::DLG_3D_PATH_CONFIG_BASE( wxWindow* parent, wxWindowID i wxBoxSizer* bSizer1; bSizer1 = new wxBoxSizer( wxVERTICAL ); + wxBoxSizer* bSizer3; + bSizer3 = new wxBoxSizer( wxHORIZONTAL ); + m_Aliases = new wxGrid( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); // Grid @@ -26,7 +29,6 @@ DLG_3D_PATH_CONFIG_BASE::DLG_3D_PATH_CONFIG_BASE( wxWindow* parent, wxWindowID i m_Aliases->SetMargins( 0, 0 ); // Columns - m_Aliases->AutoSizeColumns(); m_Aliases->EnableDragColMove( false ); m_Aliases->EnableDragColSize( true ); m_Aliases->SetColLabelSize( 30 ); @@ -36,7 +38,8 @@ DLG_3D_PATH_CONFIG_BASE::DLG_3D_PATH_CONFIG_BASE( wxWindow* parent, wxWindowID i m_Aliases->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); // Rows - m_Aliases->EnableDragRowSize( true ); + m_Aliases->AutoSizeRows(); + m_Aliases->EnableDragRowSize( false ); m_Aliases->SetRowLabelSize( 80 ); m_Aliases->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); @@ -44,7 +47,10 @@ DLG_3D_PATH_CONFIG_BASE::DLG_3D_PATH_CONFIG_BASE( wxWindow* parent, wxWindowID i // Cell Defaults m_Aliases->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP ); - bSizer1->Add( m_Aliases, 0, wxALL, 5 ); + bSizer3->Add( m_Aliases, 1, wxALL|wxEXPAND, 5 ); + + + bSizer1->Add( bSizer3, 1, wxEXPAND, 5 ); wxBoxSizer* bSizer2; bSizer2 = new wxBoxSizer( wxHORIZONTAL ); 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 f3eeec9b47..7fc9bde394 100644 --- a/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig_base.fbp +++ b/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig_base.fbp @@ -95,145 +95,156 @@ none 5 - wxALL - 0 - - 1 - 1 - 1 - 1 - - - - - 1 - 0 - - - - 1 - - - wxALIGN_LEFT - - wxALIGN_TOP - 0 - 1 - wxALIGN_CENTRE - 30 - "Alias" "Path" "Description" - wxALIGN_CENTRE - 3 - - - 1 - 0 - Dock - 0 - Left - 0 - 1 - 0 - 1 - 1 - 1 - - 1 - - - 1 - 0 - 0 - wxID_ANY - - - - 0 - 0 - - 0 - - - 0 + wxEXPAND + 1 + - 1 - m_Aliases - 1 - - - protected - 1 - - Resizable - wxALIGN_CENTRE - 80 - - wxALIGN_CENTRE - - 1 - 1 - - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + bSizer3 + wxHORIZONTAL + none + + 5 + wxALL|wxEXPAND + 1 + + 1 + 1 + 1 + 1 + + + + + 0 + 1 + + + + 1 + + + wxALIGN_LEFT + + wxALIGN_TOP + 0 + 1 + wxALIGN_CENTRE + 30 + "Alias" "Path" "Description" + wxALIGN_CENTRE + 3 + + + 1 + 0 + Dock + 0 + Left + 0 + 1 + 0 + 0 + 1 + 1 + + 1 + + + 1 + 0 + 0 + wxID_ANY + + + + 0 + 0 + + 0 + + + 0 + + 1 + m_Aliases + 1 + + + protected + 1 + + Resizable + wxALIGN_CENTRE + 80 + + wxALIGN_CENTRE + + 1 + 1 + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 b5ccf3e880..102aac1ad4 100644 --- a/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig_base.h +++ b/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig_base.h @@ -20,8 +20,8 @@ class DIALOG_SHIM; #include #include #include -#include #include +#include #include ///////////////////////////////////////////////////////////////////////////