From 1a4a3400baf83c234a4de96cd4d10e663698eb94 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Wed, 28 Jul 2021 20:22:57 +0100 Subject: [PATCH] Split the footprint 3d model panel into its own class This allows it to be shared by both the PCB editor properties dialog and the fpeditor dialog. --- pcbnew/CMakeLists.txt | 2 + .../dialog_footprint_properties_fp_editor.cpp | 406 ++------------ .../dialog_footprint_properties_fp_editor.h | 32 +- ...og_footprint_properties_fp_editor_base.cpp | 87 --- ...og_footprint_properties_fp_editor_base.fbp | 501 ------------------ ...alog_footprint_properties_fp_editor_base.h | 14 - .../dialogs/panel_fp_properties_3d_model.cpp | 429 +++++++++++++++ pcbnew/dialogs/panel_fp_properties_3d_model.h | 97 ++++ .../panel_fp_properties_3d_model_base.cpp | 111 ++++ .../panel_fp_properties_3d_model_base.fbp | 499 +++++++++++++++++ .../panel_fp_properties_3d_model_base.h | 65 +++ 11 files changed, 1253 insertions(+), 990 deletions(-) create mode 100644 pcbnew/dialogs/panel_fp_properties_3d_model.cpp create mode 100644 pcbnew/dialogs/panel_fp_properties_3d_model.h create mode 100644 pcbnew/dialogs/panel_fp_properties_3d_model_base.cpp create mode 100644 pcbnew/dialogs/panel_fp_properties_3d_model_base.fbp create mode 100644 pcbnew/dialogs/panel_fp_properties_3d_model_base.h diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index db17479910..d23be7e580 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -155,6 +155,8 @@ set( PCBNEW_DIALOGS dialogs/panel_fp_editor_color_settings.cpp dialogs/panel_fp_editor_defaults.cpp dialogs/panel_fp_editor_defaults_base.cpp + dialogs/panel_fp_properties_3d_model.cpp + dialogs/panel_fp_properties_3d_model_base.cpp dialogs/panel_pcbnew_action_plugins.cpp dialogs/panel_pcbnew_action_plugins_base.cpp dialogs/panel_pcbnew_color_settings.cpp diff --git a/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp b/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp index b6bc2e6ac2..45938cf4e5 100644 --- a/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp +++ b/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp @@ -39,6 +39,8 @@ #include #include #include +#include +#include "3d_rendering/legacy/3d_model.h" #include "filename_resolver.h" #include #include "3d_cache/dialogs/panel_preview_3d_model.h" @@ -51,28 +53,25 @@ // Remember the last open page during session. -int DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::m_page = 0; -enum MODELS_TABLE_COLUMNS -{ - COL_PROBLEM = 0, - COL_FILENAME = 1, - COL_SHOWN = 2 -}; +NOTEBOOK_PAGES DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::m_page = NOTEBOOK_PAGES::PAGE_GENERAL; + DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR( FOOTPRINT_EDIT_FRAME* aParent, FOOTPRINT* aFootprint ) : DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE( aParent ), + m_frame( aParent ), + m_footprint( aFootprint ), m_netClearance( aParent, m_NetClearanceLabel, m_NetClearanceCtrl, m_NetClearanceUnits ), m_solderMask( aParent, m_SolderMaskMarginLabel, m_SolderMaskMarginCtrl, m_SolderMaskMarginUnits ), m_solderPaste( aParent, m_SolderPasteMarginLabel, m_SolderPasteMarginCtrl, - m_SolderPasteMarginUnits ), - m_inSelect( false ) + m_SolderPasteMarginUnits ) { - m_frame = aParent; - m_footprint = aFootprint; + // Create the 3D models page + m_3dPanel = new PANEL_FP_PROPERTIES_3D_MODEL( m_frame, m_footprint, this, m_NoteBook ); + m_NoteBook->AddPage( m_3dPanel, _("3D Models"), false ); m_texts = new FP_TEXT_GRID_TABLE( m_units, m_frame ); @@ -81,7 +80,7 @@ DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR( m_delayedFocusGrid = nullptr; m_delayedFocusRow = -1; m_delayedFocusColumn = -1; - m_delayedFocusPage = -1; + m_delayedFocusPage = NOTEBOOK_PAGES::PAGE_UNKNOWN; // Give an icon wxIcon icon; @@ -90,51 +89,14 @@ DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR( // Give a bit more room for combobox editors m_itemsGrid->SetDefaultRowSize( m_itemsGrid->GetDefaultRowSize() + 4 ); - m_modelsGrid->SetDefaultRowSize( m_modelsGrid->GetDefaultRowSize() + 4 ); m_itemsGrid->SetTable( m_texts ); m_itemsGrid->PushEventHandler( new GRID_TRICKS( m_itemsGrid ) ); - GRID_TRICKS* trick = new GRID_TRICKS( m_modelsGrid ); - trick->SetTooltipEnable( COL_PROBLEM ); - - m_modelsGrid->PushEventHandler( trick ); // Show/hide columns according to the user's preference m_itemsGrid->ShowHideColumns( m_frame->GetSettings()->m_FootprintTextShownColumns ); - PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings(); - - if( cfg->m_lastFootprint3dDir.IsEmpty() ) - { - wxGetEnv( KICAD6_3DMODEL_DIR, &cfg->m_lastFootprint3dDir ); - } - - // Icon showing warning/error information - wxGridCellAttr* attr = new wxGridCellAttr; - attr->SetReadOnly(); - m_modelsGrid->SetColAttr( COL_PROBLEM, attr ); - - // Filename - attr = new wxGridCellAttr; - attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, m_modelsGrid, &cfg->m_lastFootprint3dDir, - "*.*", true, Prj().GetProjectPath() ) ); - m_modelsGrid->SetColAttr( COL_FILENAME, attr ); - - // Show checkbox - attr = new wxGridCellAttr; - attr->SetRenderer( new wxGridCellBoolRenderer() ); - attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS - attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); - m_modelsGrid->SetColAttr( COL_SHOWN, attr ); - m_modelsGrid->SetWindowStyleFlag( m_modelsGrid->GetWindowStyle() & ~wxHSCROLL ); - - aParent->Prj().Get3DCacheManager()->GetResolver()->SetProgramBase( &Pgm() ); - - m_previewPane = new PANEL_PREVIEW_3D_MODEL( m_Panel3D, m_frame, m_footprint, &m_shapes3D_list ); - - bLowerSizer3D->Add( m_previewPane, 1, wxEXPAND, 5 ); - m_FootprintNameCtrl->SetValidator( FOOTPRINT_NAME_VALIDATOR() ); // Set font sizes @@ -150,34 +112,34 @@ DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR( m_staticTextInfoValNeg->SetFont( infoFont ); m_staticTextInfoValPos->SetFont( infoFont ); - if( m_page >= 0 ) + if( static_cast( m_page ) >= 0 ) m_NoteBook->SetSelection( (unsigned) m_page ); - if( m_page == 0 ) + if( m_page == NOTEBOOK_PAGES::PAGE_GENERAL ) { m_delayedFocusGrid = m_itemsGrid; m_delayedFocusRow = 0; m_delayedFocusColumn = 0; - m_delayedFocusPage = 0; + m_delayedFocusPage = NOTEBOOK_PAGES::PAGE_GENERAL; } - else if ( m_page == 1 ) + else if( m_page == NOTEBOOK_PAGES::PAGE_CLEARANCES ) + { SetInitialFocus( m_NetClearanceCtrl ); - else + } +/* else { m_delayedFocusGrid = m_modelsGrid; m_delayedFocusRow = 0; m_delayedFocusColumn = 0; - m_delayedFocusPage = 2; + m_delayedFocusPage = NOTEBOOK_PAGES::PAGE_3D_MODELS; } + */ m_sdbSizerStdButtonsOK->SetDefault(); // Configure button logos m_bpAdd->SetBitmap( KiBitmap( BITMAPS::small_plus ) ); m_bpDelete->SetBitmap( KiBitmap( BITMAPS::small_trash ) ); - m_button3DShapeAdd->SetBitmap( KiBitmap( BITMAPS::small_plus ) ); - m_button3DShapeBrowse->SetBitmap( KiBitmap( BITMAPS::small_folder ) ); - m_button3DShapeRemove->SetBitmap( KiBitmap( BITMAPS::small_trash ) ); // wxFormBuilder doesn't include this event... m_itemsGrid->Connect( wxEVT_GRID_CELL_CHANGING, @@ -202,17 +164,11 @@ DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::~DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR() // Delete the GRID_TRICKS. m_itemsGrid->PopEventHandler( true ); - m_modelsGrid->PopEventHandler( true ); - - // free the memory used by all models, otherwise models which were - // browsed but not used would consume memory - Prj().Get3DCacheManager()->FlushCache( false ); - // the GL canvas has to be visible before it is destroyed - m_page = m_NoteBook->GetSelection(); - m_NoteBook->SetSelection( 1 ); + m_page = static_cast( m_NoteBook->GetSelection() ); - delete m_previewPane; + // the GL canvas on the 3D models page has to be visible before it is destroyed + m_NoteBook->SetSelection( static_cast( NOTEBOOK_PAGES::PAGE_3D_MODELS ) ); } @@ -232,7 +188,7 @@ bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataToWindow() if( !m_PanelGeneral->TransferDataToWindow() ) return false; - if( !m_Panel3D->TransferDataToWindow() ) + if( !m_3dPanel->TransferDataToWindow() ) return false; // Module Texts @@ -306,40 +262,9 @@ bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataToWindow() } // 3D Settings + m_3dPanel->ReloadModelsFromFootprint(); - wxString default_path; - wxGetEnv( KICAD6_3DMODEL_DIR, &default_path ); - -#ifdef __WINDOWS__ - default_path.Replace( wxT( "/" ), wxT( "\\" ) ); -#endif - - m_shapes3D_list.clear(); - m_modelsGrid->DeleteRows( 0, m_modelsGrid->GetNumberRows() ); - - wxString origPath, alias, shortPath; - FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver(); - - for( const FP_3DMODEL& model : m_footprint->Models() ) - { - m_shapes3D_list.push_back( model ); - origPath = model.m_Filename; - - if( res && res->SplitAlias( origPath, alias, shortPath ) ) - origPath = alias + wxT( ":" ) + shortPath; - - m_modelsGrid->AppendRows( 1 ); - int row = m_modelsGrid->GetNumberRows() - 1; - m_modelsGrid->SetCellValue( row, COL_FILENAME, origPath ); - m_modelsGrid->SetCellValue( row, COL_SHOWN, model.m_Show ? wxT( "1" ) : wxT( "0" ) ); - - // Must be after the filename is set - updateValidateStatus( row ); - } - - select3DModel( 0 ); // will clamp idx within bounds - m_previewPane->UpdateDummyFootprint(); - + // Items grid for( int col = 0; col < m_itemsGrid->GetNumberCols(); col++ ) { // Adjust min size to the column label size @@ -364,7 +289,6 @@ bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataToWindow() } m_itemsGrid->SetRowLabelSize( m_itemsGrid->GetVisibleWidth( -1, true, true, true ) ); - m_modelsGrid->SetColSize( COL_SHOWN, m_modelsGrid->GetVisibleWidth( COL_SHOWN, true, false, false ) ); Layout(); adjustGridColumns( m_itemsGrid->GetRect().GetWidth() ); @@ -373,192 +297,6 @@ bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataToWindow() } -void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::select3DModel( int aModelIdx ) -{ - m_inSelect = true; - - aModelIdx = std::max( 0, aModelIdx ); - aModelIdx = std::min( aModelIdx, m_modelsGrid->GetNumberRows() - 1 ); - - if( m_modelsGrid->GetNumberRows() ) - { - m_modelsGrid->SelectRow( aModelIdx ); - m_modelsGrid->SetGridCursor( aModelIdx, COL_FILENAME ); - } - - m_previewPane->SetSelectedModel( aModelIdx ); - - m_inSelect = false; -} - - -void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::On3DModelSelected( wxGridEvent& aEvent ) -{ - if( !m_inSelect ) - select3DModel( aEvent.GetRow() ); -} - - -void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::On3DModelCellChanged( wxGridEvent& aEvent ) -{ - if( aEvent.GetCol() == COL_FILENAME ) - { - bool hasAlias = false; - FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver(); - wxString filename = m_modelsGrid->GetCellValue( aEvent.GetRow(), COL_FILENAME ); - - filename.Replace( "\n", "" ); - filename.Replace( "\r", "" ); - filename.Replace( "\t", "" ); - - if( filename.empty() || !res->ValidateFileName( filename, hasAlias ) ) - { - m_delayedErrorMessage = wxString::Format( _( "Invalid filename: %s" ), filename ); - m_delayedFocusGrid = m_modelsGrid; - m_delayedFocusRow = aEvent.GetRow(); - m_delayedFocusColumn = aEvent.GetCol(); - m_delayedFocusPage = 2; - aEvent.Veto(); - } - - // if the user has specified an alias in the name then prepend ':' - if( hasAlias ) - filename.insert( 0, wxT( ":" ) ); - -#ifdef __WINDOWS__ - // In KiCad files, filenames and paths are stored using Unix notation - filename.Replace( wxT( "\\" ), wxT( "/" ) ); -#endif - - m_shapes3D_list[ aEvent.GetRow() ].m_Filename = filename; - m_modelsGrid->SetCellValue( aEvent.GetRow(), COL_FILENAME, filename ); - - updateValidateStatus( aEvent.GetRow() ); - } - else if( aEvent.GetCol() == COL_SHOWN ) - { - wxString showValue = m_modelsGrid->GetCellValue( aEvent.GetRow(), COL_SHOWN ); - - m_shapes3D_list[ aEvent.GetRow() ].m_Show = ( showValue == wxT( "1" ) ); - } - - m_previewPane->UpdateDummyFootprint(); -} - - -void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnRemove3DModel( wxCommandEvent& ) -{ - if( !m_modelsGrid->CommitPendingChanges() ) - return; - - int idx = m_modelsGrid->GetGridCursorRow(); - - if( idx >= 0 && m_modelsGrid->GetNumberRows() && !m_shapes3D_list.empty() ) - { - m_shapes3D_list.erase( m_shapes3D_list.begin() + idx ); - m_modelsGrid->DeleteRows( idx ); - - select3DModel( idx ); // will clamp idx within bounds - m_previewPane->UpdateDummyFootprint(); - } -} - - -void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnAdd3DModel( wxCommandEvent& ) -{ - if( !m_modelsGrid->CommitPendingChanges() ) - return; - - int selected = m_modelsGrid->GetGridCursorRow(); - - PROJECT& prj = Prj(); - FP_3DMODEL model; - - wxString initialpath = prj.GetRString( PROJECT::VIEWER_3D_PATH ); - wxString sidx = prj.GetRString( PROJECT::VIEWER_3D_FILTER_INDEX ); - int filter = 0; - - // If the PROJECT::VIEWER_3D_PATH hasn't been set yet, use the KICAD6_3DMODEL_DIR environment - // variable and fall back to the project path if necessary. - if( initialpath.IsEmpty() ) - { - if( !wxGetEnv( "KICAD6_3DMODEL_DIR", &initialpath ) || initialpath.IsEmpty() ) - initialpath = prj.GetProjectPath(); - } - - if( !sidx.empty() ) - { - long tmp; - sidx.ToLong( &tmp ); - - if( tmp > 0 && tmp <= INT_MAX ) - filter = (int) tmp; - } - - if( !S3D::Select3DModel( this, Prj().Get3DCacheManager(), initialpath, filter, &model ) - || model.m_Filename.empty() ) - { - select3DModel( selected ); - return; - } - - prj.SetRString( PROJECT::VIEWER_3D_PATH, initialpath ); - sidx = wxString::Format( wxT( "%i" ), filter ); - prj.SetRString( PROJECT::VIEWER_3D_FILTER_INDEX, sidx ); - FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver(); - wxString alias; - wxString shortPath; - wxString filename = model.m_Filename; - - if( res && res->SplitAlias( filename, alias, shortPath ) ) - filename = alias + wxT( ":" ) + shortPath; - -#ifdef __WINDOWS__ - // In KiCad files, filenames and paths are stored using Unix notation - model.m_Filename.Replace( "\\", "/" ); -#endif - - model.m_Show = true; - m_shapes3D_list.push_back( model ); - - int idx = m_modelsGrid->GetNumberRows(); - m_modelsGrid->AppendRows( 1 ); - m_modelsGrid->SetCellValue( idx, COL_FILENAME, filename ); - m_modelsGrid->SetCellValue( idx, COL_SHOWN, wxT( "1" ) ); - - updateValidateStatus( idx ); - - select3DModel( idx ); - m_previewPane->UpdateDummyFootprint(); -} - - -void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnAdd3DRow( wxCommandEvent& ) -{ - if( !m_modelsGrid->CommitPendingChanges() ) - return; - - FP_3DMODEL model; - - model.m_Show = true; - m_shapes3D_list.push_back( model ); - - int row = m_modelsGrid->GetNumberRows(); - m_modelsGrid->AppendRows( 1 ); - m_modelsGrid->SetCellValue( row, COL_SHOWN, wxT( "1" ) ); - m_modelsGrid->SetCellValue( row, COL_PROBLEM, "" ); - - select3DModel( row ); - - m_modelsGrid->SetFocus(); - m_modelsGrid->MakeCellVisible( row, COL_FILENAME ); - m_modelsGrid->SetGridCursor( row, COL_FILENAME ); - - m_modelsGrid->EnableCellEditControl( true ); - m_modelsGrid->ShowCellEditControl(); -} - - bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::checkFootprintName( const wxString& aFootprintName ) { if( aFootprintName.IsEmpty() ) @@ -577,59 +315,6 @@ bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::checkFootprintName( const wxString& } -void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::updateValidateStatus( int aRow ) -{ - int icon = 0; - wxString errStr; - - switch( validateModelExists( m_modelsGrid->GetCellValue( aRow, COL_FILENAME) ) ) - { - case MODEL_VALIDATE_ERRORS::MODEL_NO_ERROR: - icon = 0; - errStr = ""; - break; - - case MODEL_VALIDATE_ERRORS::RESOLVE_FAIL: - icon = wxICON_ERROR; - errStr = _( "File not found" ); - break; - - case MODEL_VALIDATE_ERRORS::OPEN_FAIL: - icon = wxICON_ERROR; - errStr = _( "Unable to open file" ); - break; - - default: - icon = wxICON_ERROR; - errStr = _( "Unknown error" ); - break; - } - - m_modelsGrid->SetCellValue( aRow, COL_PROBLEM, errStr ); - m_modelsGrid->SetCellRenderer( aRow, COL_PROBLEM, - new GRID_CELL_STATUS_ICON_RENDERER( icon ) ); -} - - -MODEL_VALIDATE_ERRORS DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::validateModelExists( const wxString& aFilename ) -{ - FILENAME_RESOLVER* resolv = Prj().Get3DFilenameResolver(); - - if( !resolv ) - return MODEL_VALIDATE_ERRORS::RESOLVE_FAIL; - - wxString fullPath = resolv->ResolvePath( aFilename ); - - if( fullPath.IsEmpty() ) - return MODEL_VALIDATE_ERRORS::RESOLVE_FAIL; - - if( wxFileName::IsFileReadable( fullPath ) ) - return MODEL_VALIDATE_ERRORS::MODEL_NO_ERROR; - else - return MODEL_VALIDATE_ERRORS::OPEN_FAIL; -} - - bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::Validate() { if( !m_itemsGrid->CommitPendingChanges() ) @@ -647,7 +332,7 @@ bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::Validate() m_NoteBook->SetSelection( 0 ); m_delayedFocusCtrl = m_FootprintNameCtrl; - m_delayedFocusPage = 0; + m_delayedFocusPage = NOTEBOOK_PAGES::PAGE_GENERAL; return false; } @@ -689,7 +374,8 @@ bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataFromWindow() if( !m_itemsGrid->CommitPendingChanges() ) return false; - if( !m_modelsGrid->CommitPendingChanges() ) + // This only commits the editor, model updating is done below + if( !m_3dPanel->TransferDataFromWindow() ) return false; auto view = m_frame->GetCanvas()->GetView(); @@ -795,9 +481,11 @@ bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataFromWindow() case 3: m_footprint->SetZoneConnection( ZONE_CONNECTION::NONE ); break; } - std::list* draw3D = &m_footprint->Models(); - draw3D->clear(); - draw3D->insert( draw3D->end(), m_shapes3D_list.begin(), m_shapes3D_list.end() ); + // Copy the models from the panel to the footprint + std::vector& panelList = m_3dPanel->GetModelList(); + std::list* fpList = &m_footprint->Models(); + fpList->clear(); + fpList->insert( fpList->end(), panelList.begin(), panelList.end() ); commit.Push( _( "Modify footprint properties" ) ); @@ -888,18 +576,10 @@ void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnDeleteField( wxCommandEvent& event } -void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::Cfg3DPath( wxCommandEvent& event ) -{ - if( S3D::Configure3DPaths( this, Prj().Get3DCacheManager()->GetResolver() ) ) - m_previewPane->UpdateDummyFootprint(); -} - - void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::adjustGridColumns( int aWidth ) { // Account for scroll bars int itemsWidth = aWidth - ( m_itemsGrid->GetSize().x - m_itemsGrid->GetClientSize().x ); - int modelsWidth = aWidth - ( m_modelsGrid->GetSize().x - m_modelsGrid->GetClientSize().x ); itemsWidth -= m_itemsGrid->GetRowLabelSize(); @@ -912,16 +592,14 @@ void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::adjustGridColumns( int aWidth ) m_itemsGrid->GetVisibleWidth( 0, true, false, false ) ) ); } - int width = modelsWidth - m_modelsGrid->GetColSize( COL_SHOWN ) - - m_modelsGrid->GetColSize( COL_PROBLEM ) - 5; - - m_modelsGrid->SetColSize( COL_FILENAME, width ); + // Update the width of the 3D panel + m_3dPanel->AdjustGridColumnWidths( aWidth ); } void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnUpdateUI( wxUpdateUIEvent& event ) { - if( !m_itemsGrid->IsCellEditControlShown() && !m_modelsGrid->IsCellEditControlShown() ) + if( !m_itemsGrid->IsCellEditControlShown() ) adjustGridColumns( m_itemsGrid->GetRect().GetWidth() ); if( m_itemsGrid->IsCellEditControlShown() ) @@ -934,12 +612,12 @@ void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnUpdateUI( wxUpdateUIEvent& event ) // b) show the correct notebook page in the background before the error dialog comes up // when triggered from an OK or a notebook page change - if( m_delayedFocusPage >= 0 ) + if( static_cast( m_delayedFocusPage ) >= 0 ) { - if( m_NoteBook->GetSelection() != m_delayedFocusPage ) - m_NoteBook->SetSelection( (unsigned) m_delayedFocusPage ); + if( m_NoteBook->GetSelection() != static_cast( m_delayedFocusPage ) ) + m_NoteBook->SetSelection( static_cast( m_delayedFocusPage ) ); - m_delayedFocusPage = -1; + m_delayedFocusPage = NOTEBOOK_PAGES::PAGE_UNKNOWN; } if( !m_delayedErrorMessage.IsEmpty() ) @@ -975,8 +653,6 @@ void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnUpdateUI( wxUpdateUIEvent& event ) m_delayedFocusRow = -1; m_delayedFocusColumn = -1; } - - m_button3DShapeRemove->Enable( m_modelsGrid->GetNumberRows() > 0 ); } diff --git a/pcbnew/dialogs/dialog_footprint_properties_fp_editor.h b/pcbnew/dialogs/dialog_footprint_properties_fp_editor.h index c07a5f7c4e..aea266c05b 100644 --- a/pcbnew/dialogs/dialog_footprint_properties_fp_editor.h +++ b/pcbnew/dialogs/dialog_footprint_properties_fp_editor.h @@ -32,15 +32,16 @@ #include -class PANEL_PREVIEW_3D_MODEL; class FOOTPRINT_EDIT_FRAME; +class PANEL_FP_PROPERTIES_3D_MODEL; -enum class MODEL_VALIDATE_ERRORS +enum class NOTEBOOK_PAGES { - MODEL_NO_ERROR, - RESOLVE_FAIL, - OPEN_FAIL + PAGE_UNKNOWN = -1, + PAGE_GENERAL = 0, + PAGE_CLEARANCES = 1, + PAGE_3D_MODELS = 2 }; class DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR : public DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE @@ -56,12 +57,6 @@ public: private: // virtual event functions - void On3DModelSelected( wxGridEvent& ) override; - void On3DModelCellChanged( wxGridEvent& aEvent ) override; - void OnRemove3DModel( wxCommandEvent& event ) override; - void OnAdd3DModel( wxCommandEvent& event ) override; - void OnAdd3DRow( wxCommandEvent& event ) override; - void Cfg3DPath( wxCommandEvent& event ) override; void OnGridSize( wxSizeEvent& event ) override; void OnFootprintNameText( wxCommandEvent& event ) override; void OnGridCellChanging( wxGridEvent& event ); @@ -69,21 +64,15 @@ private: void OnDeleteField( wxCommandEvent& event ) override; void OnUpdateUI( wxUpdateUIEvent& event ) override; - void updateValidateStatus( int aRow ); - - MODEL_VALIDATE_ERRORS validateModelExists( const wxString& aFilename ); - bool checkFootprintName( const wxString& aFootprintName ); - void select3DModel( int aModelIdx ); - void adjustGridColumns( int aWidth ); private: FOOTPRINT_EDIT_FRAME* m_frame; FOOTPRINT* m_footprint; - static int m_page; // remember the last open page during session + static NOTEBOOK_PAGES m_page; // remember the last open page during session FP_TEXT_GRID_TABLE* m_texts; @@ -91,18 +80,15 @@ private: UNIT_BINDER m_solderMask; UNIT_BINDER m_solderPaste; - std::vector m_shapes3D_list; - PANEL_PREVIEW_3D_MODEL* m_previewPane; - wxControl* m_delayedFocusCtrl; - int m_delayedFocusPage; + NOTEBOOK_PAGES m_delayedFocusPage; WX_GRID* m_delayedFocusGrid; int m_delayedFocusRow; int m_delayedFocusColumn; wxString m_delayedErrorMessage; - bool m_inSelect; + PANEL_FP_PROPERTIES_3D_MODEL* m_3dPanel; }; diff --git a/pcbnew/dialogs/dialog_footprint_properties_fp_editor_base.cpp b/pcbnew/dialogs/dialog_footprint_properties_fp_editor_base.cpp index ada23c1bac..15d759a3e2 100644 --- a/pcbnew/dialogs/dialog_footprint_properties_fp_editor_base.cpp +++ b/pcbnew/dialogs/dialog_footprint_properties_fp_editor_base.cpp @@ -332,81 +332,6 @@ DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITO m_PanelClearances->Layout(); bSizerPanelClearances->Fit( m_PanelClearances ); m_NoteBook->AddPage( m_PanelClearances, _("Clearance Overrides and Settings"), false ); - m_Panel3D = new wxPanel( m_NoteBook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); - bSizerMain3D = new wxBoxSizer( wxVERTICAL ); - - wxStaticBoxSizer* sbSizer3; - sbSizer3 = new wxStaticBoxSizer( new wxStaticBox( m_Panel3D, wxID_ANY, wxEmptyString ), wxVERTICAL ); - - m_modelsGrid = new WX_GRID( sbSizer3->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_SIMPLE ); - - // Grid - m_modelsGrid->CreateGrid( 3, 3 ); - m_modelsGrid->EnableEditing( true ); - m_modelsGrid->EnableGridLines( false ); - m_modelsGrid->EnableDragGridSize( false ); - m_modelsGrid->SetMargins( 0, 0 ); - - // Columns - m_modelsGrid->SetColSize( 0, 20 ); - m_modelsGrid->SetColSize( 1, 650 ); - m_modelsGrid->SetColSize( 2, 65 ); - m_modelsGrid->EnableDragColMove( false ); - m_modelsGrid->EnableDragColSize( false ); - m_modelsGrid->SetColLabelSize( 22 ); - m_modelsGrid->SetColLabelValue( 0, wxEmptyString ); - m_modelsGrid->SetColLabelValue( 1, _("3D Model(s)") ); - m_modelsGrid->SetColLabelValue( 2, _("Show") ); - m_modelsGrid->SetColLabelAlignment( wxALIGN_LEFT, wxALIGN_CENTER ); - - // Rows - m_modelsGrid->EnableDragRowSize( false ); - m_modelsGrid->SetRowLabelSize( 0 ); - m_modelsGrid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); - - // Label Appearance - - // Cell Defaults - m_modelsGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP ); - sbSizer3->Add( m_modelsGrid, 1, wxEXPAND|wxLEFT|wxRIGHT, 5 ); - - wxBoxSizer* bSizer3DButtons; - bSizer3DButtons = new wxBoxSizer( wxHORIZONTAL ); - - m_button3DShapeAdd = new wxBitmapButton( sbSizer3->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( -1,-1 ), wxBU_AUTODRAW|0 ); - bSizer3DButtons->Add( m_button3DShapeAdd, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); - - m_button3DShapeBrowse = new wxBitmapButton( sbSizer3->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( -1,-1 ), wxBU_AUTODRAW|0 ); - bSizer3DButtons->Add( m_button3DShapeBrowse, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); - - - bSizer3DButtons->Add( 20, 0, 0, 0, 5 ); - - m_button3DShapeRemove = new wxBitmapButton( sbSizer3->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( -1,-1 ), wxBU_AUTODRAW|0 ); - bSizer3DButtons->Add( m_button3DShapeRemove, 0, wxALIGN_CENTER_VERTICAL, 5 ); - - - bSizer3DButtons->Add( 0, 0, 1, wxEXPAND, 5 ); - - m_buttonConfig3DPaths = new wxButton( sbSizer3->GetStaticBox(), wxID_ANY, _("Configure Paths..."), wxDefaultPosition, wxDefaultSize, 0 ); - bSizer3DButtons->Add( m_buttonConfig3DPaths, 0, wxALL, 5 ); - - - sbSizer3->Add( bSizer3DButtons, 0, wxEXPAND, 5 ); - - - bSizerMain3D->Add( sbSizer3, 4, wxEXPAND|wxRIGHT|wxLEFT, 5 ); - - bLowerSizer3D = new wxBoxSizer( wxHORIZONTAL ); - - - bSizerMain3D->Add( bLowerSizer3D, 11, wxEXPAND, 5 ); - - - m_Panel3D->SetSizer( bSizerMain3D ); - m_Panel3D->Layout(); - bSizerMain3D->Fit( m_Panel3D ); - m_NoteBook->AddPage( m_Panel3D, _("3D Models"), false ); m_GeneralBoxSizer->Add( m_NoteBook, 1, wxEXPAND|wxRIGHT|wxLEFT, 5 ); @@ -437,12 +362,6 @@ DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITO m_bpAdd->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE::OnAddField ), NULL, this ); m_bpDelete->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE::OnDeleteField ), NULL, this ); m_FootprintNameCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE::OnFootprintNameText ), NULL, this ); - m_modelsGrid->Connect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE::On3DModelCellChanged ), NULL, this ); - m_modelsGrid->Connect( wxEVT_GRID_SELECT_CELL, wxGridEventHandler( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE::On3DModelSelected ), NULL, this ); - m_button3DShapeAdd->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE::OnAdd3DRow ), NULL, this ); - m_button3DShapeBrowse->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE::OnAdd3DModel ), NULL, this ); - m_button3DShapeRemove->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE::OnRemove3DModel ), NULL, this ); - m_buttonConfig3DPaths->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE::Cfg3DPath ), NULL, this ); } DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE::~DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE() @@ -454,11 +373,5 @@ DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE::~DIALOG_FOOTPRINT_PROPERTIES_FP_EDIT m_bpAdd->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE::OnAddField ), NULL, this ); m_bpDelete->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE::OnDeleteField ), NULL, this ); m_FootprintNameCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE::OnFootprintNameText ), NULL, this ); - m_modelsGrid->Disconnect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE::On3DModelCellChanged ), NULL, this ); - m_modelsGrid->Disconnect( wxEVT_GRID_SELECT_CELL, wxGridEventHandler( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE::On3DModelSelected ), NULL, this ); - m_button3DShapeAdd->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE::OnAdd3DRow ), NULL, this ); - m_button3DShapeBrowse->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE::OnAdd3DModel ), NULL, this ); - m_button3DShapeRemove->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE::OnRemove3DModel ), NULL, this ); - m_buttonConfig3DPaths->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE::Cfg3DPath ), NULL, this ); } diff --git a/pcbnew/dialogs/dialog_footprint_properties_fp_editor_base.fbp b/pcbnew/dialogs/dialog_footprint_properties_fp_editor_base.fbp index df7eabd4b7..61bcf2ad36 100644 --- a/pcbnew/dialogs/dialog_footprint_properties_fp_editor_base.fbp +++ b/pcbnew/dialogs/dialog_footprint_properties_fp_editor_base.fbp @@ -2788,507 +2788,6 @@ - - - 3D Models - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 - - 1 - m_Panel3D - 1 - - - protected - 1 - - Resizable - 1 - - - 0 - - - - wxTAB_TRAVERSAL - - - bSizerMain3D - wxVERTICAL - protected - - 5 - wxEXPAND|wxRIGHT|wxLEFT - 4 - - wxID_ANY - - - sbSizer3 - wxVERTICAL - 1 - none - - 5 - wxEXPAND|wxLEFT|wxRIGHT - 1 - - 1 - 1 - 1 - 1 - - - - - 0 - 0 - - - - 1 - - - wxALIGN_LEFT - - wxALIGN_TOP - 0 - 1 - wxALIGN_LEFT - 22 - "" "3D Model(s)" "Show" - wxALIGN_CENTER - 3 - 20,650,65 - - 1 - 0 - Dock - 0 - Left - 0 - 0 - 0 - 0 - 1 - 1 - - 1 - - - 0 - 0 - 0 - wxID_ANY - - - - 0 - 0 - - 0 - - - 0 - - 1 - m_modelsGrid - 1 - - - protected - 1 - - Resizable - wxALIGN_CENTER - 0 - - wxALIGN_CENTER - - 3 - 1 - - WX_GRID; widgets/wx_grid.h; forward_declare - 0 - - - - wxBORDER_SIMPLE - On3DModelCellChanged - On3DModelSelected - - - - 5 - wxEXPAND - 0 - - - bSizer3DButtons - wxHORIZONTAL - none - - 5 - wxALIGN_CENTER_VERTICAL|wxLEFT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - - 1 - 0 - 1 - - 1 - - 0 - 0 - - Dock - 0 - Left - 1 - - 1 - - - 0 - 0 - wxID_ANY - Add 3D Model - - 0 - - 0 - - - 0 - - 1 - m_button3DShapeAdd - 1 - - - protected - 1 - - - - Resizable - 1 - -1,-1 - - ; forward_declare - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - OnAdd3DRow - - - - 5 - wxALIGN_CENTER_VERTICAL|wxLEFT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - - 1 - 0 - 1 - - 1 - - 0 - 0 - - Dock - 0 - Left - 1 - - 1 - - - 0 - 0 - wxID_ANY - Browse - - 0 - - 0 - - - 0 - - 1 - m_button3DShapeBrowse - 1 - - - protected - 1 - - - - Resizable - 1 - -1,-1 - - ; forward_declare - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - OnAdd3DModel - - - - 5 - - 0 - - 0 - protected - 20 - - - - 5 - wxALIGN_CENTER_VERTICAL - 0 - - 1 - 1 - 1 - 1 - - - - - - - - - 1 - 0 - 1 - - 1 - - 0 - 0 - - Dock - 0 - Left - 1 - - 1 - - - 0 - 0 - wxID_ANY - Remove 3D Model - - 0 - - 0 - - - 0 - - 1 - m_button3DShapeRemove - 1 - - - protected - 1 - - - - Resizable - 1 - -1,-1 - - ; forward_declare - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - OnRemove3DModel - - - - 5 - wxEXPAND - 1 - - 0 - protected - 0 - - - - 5 - wxALL - 0 - - 1 - 1 - 1 - 1 - - - - - - - - - 1 - 0 - 1 - - 1 - - 0 - 0 - - Dock - 0 - Left - 1 - - 1 - - - 0 - 0 - wxID_ANY - Configure Paths... - - 0 - - 0 - - - 0 - - 1 - m_buttonConfig3DPaths - 1 - - - protected - 1 - - - - Resizable - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - Cfg3DPath - - - - - - - - 5 - wxEXPAND - 11 - - - bLowerSizer3D - wxHORIZONTAL - protected - - - - - diff --git a/pcbnew/dialogs/dialog_footprint_properties_fp_editor_base.h b/pcbnew/dialogs/dialog_footprint_properties_fp_editor_base.h index 620689f95c..4194291d07 100644 --- a/pcbnew/dialogs/dialog_footprint_properties_fp_editor_base.h +++ b/pcbnew/dialogs/dialog_footprint_properties_fp_editor_base.h @@ -90,14 +90,6 @@ class DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE : public DIALOG_SHIM wxStaticText* m_staticTextInfoPaste; wxStaticText* m_staticText16; wxChoice* m_ZoneConnectionChoice; - wxPanel* m_Panel3D; - wxBoxSizer* bSizerMain3D; - WX_GRID* m_modelsGrid; - wxBitmapButton* m_button3DShapeAdd; - wxBitmapButton* m_button3DShapeBrowse; - wxBitmapButton* m_button3DShapeRemove; - wxButton* m_buttonConfig3DPaths; - wxBoxSizer* bLowerSizer3D; wxStdDialogButtonSizer* m_sdbSizerStdButtons; wxButton* m_sdbSizerStdButtonsOK; wxButton* m_sdbSizerStdButtonsCancel; @@ -109,12 +101,6 @@ class DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE : public DIALOG_SHIM virtual void OnAddField( wxCommandEvent& event ) { event.Skip(); } virtual void OnDeleteField( wxCommandEvent& event ) { event.Skip(); } virtual void OnFootprintNameText( wxCommandEvent& event ) { event.Skip(); } - virtual void On3DModelCellChanged( wxGridEvent& event ) { event.Skip(); } - virtual void On3DModelSelected( wxGridEvent& event ) { event.Skip(); } - virtual void OnAdd3DRow( wxCommandEvent& event ) { event.Skip(); } - virtual void OnAdd3DModel( wxCommandEvent& event ) { event.Skip(); } - virtual void OnRemove3DModel( wxCommandEvent& event ) { event.Skip(); } - virtual void Cfg3DPath( wxCommandEvent& event ) { event.Skip(); } public: diff --git a/pcbnew/dialogs/panel_fp_properties_3d_model.cpp b/pcbnew/dialogs/panel_fp_properties_3d_model.cpp new file mode 100644 index 0000000000..5765e95f84 --- /dev/null +++ b/pcbnew/dialogs/panel_fp_properties_3d_model.cpp @@ -0,0 +1,429 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 2015 Dick Hollenbeck, dick@softplc.com + * Copyright (C) 2008 Wayne Stambaugh + * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors. + * + * 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 +#include <3d_viewer/eda_3d_viewer.h> +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "filename_resolver.h" +#include +#include "3d_cache/dialogs/panel_preview_3d_model.h" +#include "3d_cache/dialogs/3d_cache_dialogs.h" +#include +#include + +enum MODELS_TABLE_COLUMNS +{ + COL_PROBLEM = 0, + COL_FILENAME = 1, + COL_SHOWN = 2 +}; + +PANEL_FP_PROPERTIES_3D_MODEL::PANEL_FP_PROPERTIES_3D_MODEL( + FOOTPRINT_EDIT_FRAME* aFrame, FOOTPRINT* aFootprint, DIALOG_SHIM* aDialogParent, + wxWindow* aParent, wxWindowID aId, const wxPoint& aPos, const wxSize& aSize, long aStyle, + const wxString& aName ) : + PANEL_FP_PROPERTIES_3D_MODEL_BASE( aParent, aId, aPos, aSize, aStyle, aName ), + m_parentDialog( aDialogParent ), + m_frame( aFrame ), + m_footprint( aFootprint ), + m_inSelect( false ) +{ + m_modelsGrid->SetDefaultRowSize( m_modelsGrid->GetDefaultRowSize() + 4 ); + + GRID_TRICKS* trick = new GRID_TRICKS( m_modelsGrid ); + trick->SetTooltipEnable( COL_PROBLEM ); + + m_modelsGrid->PushEventHandler( trick ); + + // Get the last 3D directory + PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings(); + + if( cfg->m_lastFootprint3dDir.IsEmpty() ) + wxGetEnv( KICAD6_3DMODEL_DIR, &cfg->m_lastFootprint3dDir ); + + // Icon showing warning/error information + wxGridCellAttr* attr = new wxGridCellAttr; + attr->SetReadOnly(); + m_modelsGrid->SetColAttr( COL_PROBLEM, attr ); + + // Filename + attr = new wxGridCellAttr; + attr->SetEditor( new GRID_CELL_PATH_EDITOR( m_parentDialog, m_modelsGrid, &cfg->m_lastFootprint3dDir, + "*.*", true, m_frame->Prj().GetProjectPath() ) ); + m_modelsGrid->SetColAttr( COL_FILENAME, attr ); + + // Show checkbox + attr = new wxGridCellAttr; + attr->SetRenderer( new wxGridCellBoolRenderer() ); + attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS + attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); + m_modelsGrid->SetColAttr( COL_SHOWN, attr ); + m_modelsGrid->SetWindowStyleFlag( m_modelsGrid->GetWindowStyle() & ~wxHSCROLL ); + + m_frame->Prj().Get3DCacheManager()->GetResolver()->SetProgramBase( &Pgm() ); + + m_previewPane = new PANEL_PREVIEW_3D_MODEL( this, m_frame, m_footprint, &m_shapes3D_list ); + + bLowerSizer3D->Add( m_previewPane, 1, wxEXPAND, 5 ); + + // Configure button logos + m_button3DShapeAdd->SetBitmap( KiBitmap( BITMAPS::small_plus ) ); + m_button3DShapeBrowse->SetBitmap( KiBitmap( BITMAPS::small_folder ) ); + m_button3DShapeRemove->SetBitmap( KiBitmap( BITMAPS::small_trash ) ); +} + + +PANEL_FP_PROPERTIES_3D_MODEL::~PANEL_FP_PROPERTIES_3D_MODEL() +{ + // Delete the GRID_TRICKS. + m_modelsGrid->PopEventHandler( true ); + + // free the memory used by all models, otherwise models which were + // browsed but not used would consume memory + m_frame->Prj().Get3DCacheManager()->FlushCache( false ); + + delete m_previewPane; +} + + +bool PANEL_FP_PROPERTIES_3D_MODEL::TransferDataFromWindow() +{ + // Only commit changes in the editor, not the models + // The container dialog is responsible for moving the new models into + // the footprint inside a commit. + if( !m_modelsGrid->CommitPendingChanges() ) + return false; + + return true; +} + + +void PANEL_FP_PROPERTIES_3D_MODEL::ReloadModelsFromFootprint() +{ + wxString default_path; + wxGetEnv( KICAD6_3DMODEL_DIR, &default_path ); + +#ifdef __WINDOWS__ + default_path.Replace( wxT( "/" ), wxT( "\\" ) ); +#endif + + m_shapes3D_list.clear(); + m_modelsGrid->DeleteRows( 0, m_modelsGrid->GetNumberRows() ); + + wxString origPath, alias, shortPath; + FILENAME_RESOLVER* res = m_frame->Prj().Get3DCacheManager()->GetResolver(); + + for( const FP_3DMODEL& model : m_footprint->Models() ) + { + m_shapes3D_list.push_back( model ); + origPath = model.m_Filename; + + if( res && res->SplitAlias( origPath, alias, shortPath ) ) + origPath = alias + wxT( ":" ) + shortPath; + + m_modelsGrid->AppendRows( 1 ); + int row = m_modelsGrid->GetNumberRows() - 1; + m_modelsGrid->SetCellValue( row, COL_FILENAME, origPath ); + m_modelsGrid->SetCellValue( row, COL_SHOWN, model.m_Show ? wxT( "1" ) : wxT( "0" ) ); + + // Must be after the filename is set + updateValidateStatus( row ); + } + + select3DModel( 0 ); // will clamp idx within bounds + m_previewPane->UpdateDummyFootprint(); + + m_modelsGrid->SetColSize( COL_SHOWN, m_modelsGrid->GetVisibleWidth( COL_SHOWN, true, false, false ) ); + + Layout(); +} + + +void PANEL_FP_PROPERTIES_3D_MODEL::select3DModel( int aModelIdx ) +{ + m_inSelect = true; + + aModelIdx = std::max( 0, aModelIdx ); + aModelIdx = std::min( aModelIdx, m_modelsGrid->GetNumberRows() - 1 ); + + if( m_modelsGrid->GetNumberRows() ) + { + m_modelsGrid->SelectRow( aModelIdx ); + m_modelsGrid->SetGridCursor( aModelIdx, COL_FILENAME ); + } + + m_previewPane->SetSelectedModel( aModelIdx ); + + m_inSelect = false; +} + + +void PANEL_FP_PROPERTIES_3D_MODEL::On3DModelSelected( wxGridEvent& aEvent ) +{ + if( !m_inSelect ) + select3DModel( aEvent.GetRow() ); +} + + +void PANEL_FP_PROPERTIES_3D_MODEL::On3DModelCellChanged( wxGridEvent& aEvent ) +{ + if( aEvent.GetCol() == COL_FILENAME ) + { + bool hasAlias = false; + FILENAME_RESOLVER* res = m_frame->Prj().Get3DCacheManager()->GetResolver(); + wxString filename = m_modelsGrid->GetCellValue( aEvent.GetRow(), COL_FILENAME ); + + filename.Replace( "\n", "" ); + filename.Replace( "\r", "" ); + filename.Replace( "\t", "" ); + + if( filename.empty() || !res->ValidateFileName( filename, hasAlias ) ) + aEvent.Veto(); + + // if the user has specified an alias in the name then prepend ':' + if( hasAlias ) + filename.insert( 0, wxT( ":" ) ); + +#ifdef __WINDOWS__ + // In KiCad files, filenames and paths are stored using Unix notation + filename.Replace( wxT( "\\" ), wxT( "/" ) ); +#endif + + m_shapes3D_list[ aEvent.GetRow() ].m_Filename = filename; + m_modelsGrid->SetCellValue( aEvent.GetRow(), COL_FILENAME, filename ); + + updateValidateStatus( aEvent.GetRow() ); + } + else if( aEvent.GetCol() == COL_SHOWN ) + { + wxString showValue = m_modelsGrid->GetCellValue( aEvent.GetRow(), COL_SHOWN ); + + m_shapes3D_list[ aEvent.GetRow() ].m_Show = ( showValue == wxT( "1" ) ); + } + + m_previewPane->UpdateDummyFootprint(); +} + + +void PANEL_FP_PROPERTIES_3D_MODEL::OnRemove3DModel( wxCommandEvent& ) +{ + if( !m_modelsGrid->CommitPendingChanges() ) + return; + + int idx = m_modelsGrid->GetGridCursorRow(); + + if( idx >= 0 && m_modelsGrid->GetNumberRows() && !m_shapes3D_list.empty() ) + { + m_shapes3D_list.erase( m_shapes3D_list.begin() + idx ); + m_modelsGrid->DeleteRows( idx ); + + select3DModel( idx ); // will clamp idx within bounds + m_previewPane->UpdateDummyFootprint(); + } +} + + +void PANEL_FP_PROPERTIES_3D_MODEL::OnAdd3DModel( wxCommandEvent& ) +{ + if( !m_modelsGrid->CommitPendingChanges() ) + return; + + int selected = m_modelsGrid->GetGridCursorRow(); + + PROJECT& prj = m_frame->Prj(); + FP_3DMODEL model; + + wxString initialpath = prj.GetRString( PROJECT::VIEWER_3D_PATH ); + wxString sidx = prj.GetRString( PROJECT::VIEWER_3D_FILTER_INDEX ); + int filter = 0; + + // If the PROJECT::VIEWER_3D_PATH hasn't been set yet, use the KICAD6_3DMODEL_DIR environment + // variable and fall back to the project path if necessary. + if( initialpath.IsEmpty() ) + { + if( !wxGetEnv( "KICAD6_3DMODEL_DIR", &initialpath ) || initialpath.IsEmpty() ) + initialpath = prj.GetProjectPath(); + } + + if( !sidx.empty() ) + { + long tmp; + sidx.ToLong( &tmp ); + + if( tmp > 0 && tmp <= INT_MAX ) + filter = (int) tmp; + } + + if( !S3D::Select3DModel( this, m_frame->Prj().Get3DCacheManager(), initialpath, filter, &model ) + || model.m_Filename.empty() ) + { + select3DModel( selected ); + return; + } + + prj.SetRString( PROJECT::VIEWER_3D_PATH, initialpath ); + sidx = wxString::Format( wxT( "%i" ), filter ); + prj.SetRString( PROJECT::VIEWER_3D_FILTER_INDEX, sidx ); + FILENAME_RESOLVER* res = m_frame->Prj().Get3DCacheManager()->GetResolver(); + wxString alias; + wxString shortPath; + wxString filename = model.m_Filename; + + if( res && res->SplitAlias( filename, alias, shortPath ) ) + filename = alias + wxT( ":" ) + shortPath; + +#ifdef __WINDOWS__ + // In KiCad files, filenames and paths are stored using Unix notation + model.m_Filename.Replace( "\\", "/" ); +#endif + + model.m_Show = true; + m_shapes3D_list.push_back( model ); + + int idx = m_modelsGrid->GetNumberRows(); + m_modelsGrid->AppendRows( 1 ); + m_modelsGrid->SetCellValue( idx, COL_FILENAME, filename ); + m_modelsGrid->SetCellValue( idx, COL_SHOWN, wxT( "1" ) ); + + updateValidateStatus( idx ); + + select3DModel( idx ); + m_previewPane->UpdateDummyFootprint(); +} + + +void PANEL_FP_PROPERTIES_3D_MODEL::OnAdd3DRow( wxCommandEvent& ) +{ + if( !m_modelsGrid->CommitPendingChanges() ) + return; + + FP_3DMODEL model; + + model.m_Show = true; + m_shapes3D_list.push_back( model ); + + int row = m_modelsGrid->GetNumberRows(); + m_modelsGrid->AppendRows( 1 ); + m_modelsGrid->SetCellValue( row, COL_SHOWN, wxT( "1" ) ); + m_modelsGrid->SetCellValue( row, COL_PROBLEM, "" ); + + select3DModel( row ); + + m_modelsGrid->SetFocus(); + m_modelsGrid->MakeCellVisible( row, COL_FILENAME ); + m_modelsGrid->SetGridCursor( row, COL_FILENAME ); + + m_modelsGrid->EnableCellEditControl( true ); + m_modelsGrid->ShowCellEditControl(); +} + + +void PANEL_FP_PROPERTIES_3D_MODEL::updateValidateStatus( int aRow ) +{ + int icon = 0; + wxString errStr; + + switch( validateModelExists( m_modelsGrid->GetCellValue( aRow, COL_FILENAME) ) ) + { + case MODEL_VALIDATE_ERRORS::MODEL_NO_ERROR: + icon = 0; + errStr = ""; + break; + + case MODEL_VALIDATE_ERRORS::RESOLVE_FAIL: + icon = wxICON_ERROR; + errStr = _( "File not found" ); + break; + + case MODEL_VALIDATE_ERRORS::OPEN_FAIL: + icon = wxICON_ERROR; + errStr = _( "Unable to open file" ); + break; + + default: + icon = wxICON_ERROR; + errStr = _( "Unknown error" ); + break; + } + + m_modelsGrid->SetCellValue( aRow, COL_PROBLEM, errStr ); + m_modelsGrid->SetCellRenderer( aRow, COL_PROBLEM, + new GRID_CELL_STATUS_ICON_RENDERER( icon ) ); +} + + +MODEL_VALIDATE_ERRORS PANEL_FP_PROPERTIES_3D_MODEL::validateModelExists( const wxString& aFilename ) +{ + FILENAME_RESOLVER* resolv = m_frame->Prj().Get3DFilenameResolver(); + + if( !resolv ) + return MODEL_VALIDATE_ERRORS::RESOLVE_FAIL; + + wxString fullPath = resolv->ResolvePath( aFilename ); + + if( fullPath.IsEmpty() ) + return MODEL_VALIDATE_ERRORS::RESOLVE_FAIL; + + if( wxFileName::IsFileReadable( fullPath ) ) + return MODEL_VALIDATE_ERRORS::MODEL_NO_ERROR; + else + return MODEL_VALIDATE_ERRORS::OPEN_FAIL; +} + + +void PANEL_FP_PROPERTIES_3D_MODEL::Cfg3DPath( wxCommandEvent& event ) +{ + if( S3D::Configure3DPaths( this, m_frame->Prj().Get3DCacheManager()->GetResolver() ) ) + m_previewPane->UpdateDummyFootprint(); +} + + +void PANEL_FP_PROPERTIES_3D_MODEL::AdjustGridColumnWidths( int aWidth ) +{ + // Account for scroll bars + int modelsWidth = aWidth - ( m_modelsGrid->GetSize().x - m_modelsGrid->GetClientSize().x ); + + int width = modelsWidth - m_modelsGrid->GetColSize( COL_SHOWN ) + - m_modelsGrid->GetColSize( COL_PROBLEM ) - 5; + + m_modelsGrid->SetColSize( COL_FILENAME, width ); +} + + +void PANEL_FP_PROPERTIES_3D_MODEL::OnUpdateUI( wxUpdateUIEvent& event ) +{ + m_button3DShapeRemove->Enable( m_modelsGrid->GetNumberRows() > 0 ); +} diff --git a/pcbnew/dialogs/panel_fp_properties_3d_model.h b/pcbnew/dialogs/panel_fp_properties_3d_model.h new file mode 100644 index 0000000000..7a0b5db2d2 --- /dev/null +++ b/pcbnew/dialogs/panel_fp_properties_3d_model.h @@ -0,0 +1,97 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2010-2015 Jean-Pierre Charras, jean-pierre.charras at wanadoo.fr + * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. + * + * 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 + */ + +#ifndef PANEL_FP_PROPERTIES_3D_MODEL_H_ +#define PANEL_FP_PROPERTIES_3D_MODEL_H_ + +#include +#include +#include + +class DIALOG_SHIM; +class FOOTPRINT_EDIT_FRAME; +class PANEL_PREVIEW_3D_MODEL; + +enum class MODEL_VALIDATE_ERRORS +{ + MODEL_NO_ERROR, + RESOLVE_FAIL, + OPEN_FAIL +}; + +class PANEL_FP_PROPERTIES_3D_MODEL : public PANEL_FP_PROPERTIES_3D_MODEL_BASE +{ + +public: + + PANEL_FP_PROPERTIES_3D_MODEL( FOOTPRINT_EDIT_FRAME* aFrame, FOOTPRINT* aFootprint, + DIALOG_SHIM* aDialogParent, wxWindow* aParent, + wxWindowID aId = wxID_ANY, + const wxPoint& aPos = wxDefaultPosition, + const wxSize& aSize = wxDefaultSize, + long aStyle = wxTAB_TRAVERSAL, + const wxString& aName = wxEmptyString ); + + ~PANEL_FP_PROPERTIES_3D_MODEL() override; + + bool TransferDataFromWindow() override; + + void ReloadModelsFromFootprint(); + + void AdjustGridColumnWidths( int aWidth ); + + std::vector& GetModelList() + { + return m_shapes3D_list; + } + +private: + // virtual event functions + void On3DModelSelected( wxGridEvent& ) override; + void On3DModelCellChanged( wxGridEvent& aEvent ) override; + void OnRemove3DModel( wxCommandEvent& event ) override; + void OnAdd3DModel( wxCommandEvent& event ) override; + void OnAdd3DRow( wxCommandEvent& event ) override; + void Cfg3DPath( wxCommandEvent& event ) override; + + void OnUpdateUI( wxUpdateUIEvent& event ) override; + + void updateValidateStatus( int aRow ); + + MODEL_VALIDATE_ERRORS validateModelExists( const wxString& aFilename ); + + void select3DModel( int aModelIdx ); + +private: + DIALOG_SHIM* m_parentDialog; + FOOTPRINT_EDIT_FRAME* m_frame; + FOOTPRINT* m_footprint; + + std::vector m_shapes3D_list; + PANEL_PREVIEW_3D_MODEL* m_previewPane; + + bool m_inSelect; +}; + +#endif // PANEL_FP_PROPERTIES_3D_MODEL_H_ diff --git a/pcbnew/dialogs/panel_fp_properties_3d_model_base.cpp b/pcbnew/dialogs/panel_fp_properties_3d_model_base.cpp new file mode 100644 index 0000000000..d918e939f2 --- /dev/null +++ b/pcbnew/dialogs/panel_fp_properties_3d_model_base.cpp @@ -0,0 +1,111 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Oct 26 2018) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "widgets/wx_grid.h" + +#include "panel_fp_properties_3d_model_base.h" + +/////////////////////////////////////////////////////////////////////////// + +PANEL_FP_PROPERTIES_3D_MODEL_BASE::PANEL_FP_PROPERTIES_3D_MODEL_BASE( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) : wxPanel( parent, id, pos, size, style, name ) +{ + bSizerMain3D = new wxBoxSizer( wxVERTICAL ); + + wxStaticBoxSizer* sbSizer3; + sbSizer3 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, wxEmptyString ), wxVERTICAL ); + + m_modelsGrid = new WX_GRID( sbSizer3->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_SIMPLE ); + + // Grid + m_modelsGrid->CreateGrid( 3, 3 ); + m_modelsGrid->EnableEditing( true ); + m_modelsGrid->EnableGridLines( false ); + m_modelsGrid->EnableDragGridSize( false ); + m_modelsGrid->SetMargins( 0, 0 ); + + // Columns + m_modelsGrid->SetColSize( 0, 20 ); + m_modelsGrid->SetColSize( 1, 650 ); + m_modelsGrid->SetColSize( 2, 65 ); + m_modelsGrid->EnableDragColMove( false ); + m_modelsGrid->EnableDragColSize( false ); + m_modelsGrid->SetColLabelSize( 22 ); + m_modelsGrid->SetColLabelValue( 0, wxEmptyString ); + m_modelsGrid->SetColLabelValue( 1, _("3D Model(s)") ); + m_modelsGrid->SetColLabelValue( 2, _("Show") ); + m_modelsGrid->SetColLabelAlignment( wxALIGN_LEFT, wxALIGN_CENTER ); + + // Rows + m_modelsGrid->EnableDragRowSize( false ); + m_modelsGrid->SetRowLabelSize( 0 ); + m_modelsGrid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); + + // Label Appearance + + // Cell Defaults + m_modelsGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP ); + sbSizer3->Add( m_modelsGrid, 1, wxEXPAND|wxLEFT|wxRIGHT, 5 ); + + wxBoxSizer* bSizer3DButtons; + bSizer3DButtons = new wxBoxSizer( wxHORIZONTAL ); + + m_button3DShapeAdd = new wxBitmapButton( sbSizer3->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( -1,-1 ), wxBU_AUTODRAW|0 ); + bSizer3DButtons->Add( m_button3DShapeAdd, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); + + m_button3DShapeBrowse = new wxBitmapButton( sbSizer3->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( -1,-1 ), wxBU_AUTODRAW|0 ); + bSizer3DButtons->Add( m_button3DShapeBrowse, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); + + + bSizer3DButtons->Add( 20, 0, 0, 0, 5 ); + + m_button3DShapeRemove = new wxBitmapButton( sbSizer3->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( -1,-1 ), wxBU_AUTODRAW|0 ); + bSizer3DButtons->Add( m_button3DShapeRemove, 0, wxALIGN_CENTER_VERTICAL, 5 ); + + + bSizer3DButtons->Add( 0, 0, 1, wxEXPAND, 5 ); + + m_buttonConfig3DPaths = new wxButton( sbSizer3->GetStaticBox(), wxID_ANY, _("Configure Paths..."), wxDefaultPosition, wxDefaultSize, 0 ); + bSizer3DButtons->Add( m_buttonConfig3DPaths, 0, wxALL, 5 ); + + + sbSizer3->Add( bSizer3DButtons, 0, wxEXPAND, 5 ); + + + bSizerMain3D->Add( sbSizer3, 4, wxEXPAND|wxRIGHT|wxLEFT, 5 ); + + bLowerSizer3D = new wxBoxSizer( wxHORIZONTAL ); + + + bSizerMain3D->Add( bLowerSizer3D, 11, wxEXPAND, 5 ); + + + this->SetSizer( bSizerMain3D ); + this->Layout(); + bSizerMain3D->Fit( this ); + + // Connect Events + this->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( PANEL_FP_PROPERTIES_3D_MODEL_BASE::OnUpdateUI ) ); + m_modelsGrid->Connect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( PANEL_FP_PROPERTIES_3D_MODEL_BASE::On3DModelCellChanged ), NULL, this ); + m_modelsGrid->Connect( wxEVT_GRID_SELECT_CELL, wxGridEventHandler( PANEL_FP_PROPERTIES_3D_MODEL_BASE::On3DModelSelected ), NULL, this ); + m_button3DShapeAdd->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_FP_PROPERTIES_3D_MODEL_BASE::OnAdd3DRow ), NULL, this ); + m_button3DShapeBrowse->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_FP_PROPERTIES_3D_MODEL_BASE::OnAdd3DModel ), NULL, this ); + m_button3DShapeRemove->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_FP_PROPERTIES_3D_MODEL_BASE::OnRemove3DModel ), NULL, this ); + m_buttonConfig3DPaths->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_FP_PROPERTIES_3D_MODEL_BASE::Cfg3DPath ), NULL, this ); +} + +PANEL_FP_PROPERTIES_3D_MODEL_BASE::~PANEL_FP_PROPERTIES_3D_MODEL_BASE() +{ + // Disconnect Events + this->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( PANEL_FP_PROPERTIES_3D_MODEL_BASE::OnUpdateUI ) ); + m_modelsGrid->Disconnect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( PANEL_FP_PROPERTIES_3D_MODEL_BASE::On3DModelCellChanged ), NULL, this ); + m_modelsGrid->Disconnect( wxEVT_GRID_SELECT_CELL, wxGridEventHandler( PANEL_FP_PROPERTIES_3D_MODEL_BASE::On3DModelSelected ), NULL, this ); + m_button3DShapeAdd->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_FP_PROPERTIES_3D_MODEL_BASE::OnAdd3DRow ), NULL, this ); + m_button3DShapeBrowse->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_FP_PROPERTIES_3D_MODEL_BASE::OnAdd3DModel ), NULL, this ); + m_button3DShapeRemove->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_FP_PROPERTIES_3D_MODEL_BASE::OnRemove3DModel ), NULL, this ); + m_buttonConfig3DPaths->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_FP_PROPERTIES_3D_MODEL_BASE::Cfg3DPath ), NULL, this ); + +} diff --git a/pcbnew/dialogs/panel_fp_properties_3d_model_base.fbp b/pcbnew/dialogs/panel_fp_properties_3d_model_base.fbp new file mode 100644 index 0000000000..7f05c5b7ee --- /dev/null +++ b/pcbnew/dialogs/panel_fp_properties_3d_model_base.fbp @@ -0,0 +1,499 @@ + + + + + + C++ + 1 + source_name + 0 + 0 + res + UTF-8 + connect + panel_fp_properties_3d_model_base + 1000 + none + + 1 + panel_fp_properties_3d_model + + . + + 1 + 1 + 1 + 1 + UI + 0 + 0 + + 0 + wxAUI_MGR_DEFAULT + + + 1 + 1 + impl_virtual + + + 0 + wxID_ANY + + + PANEL_FP_PROPERTIES_3D_MODEL_BASE + + + + + + + wxTAB_TRAVERSAL + OnUpdateUI + + + bSizerMain3D + wxVERTICAL + protected + + 5 + wxEXPAND|wxRIGHT|wxLEFT + 4 + + wxID_ANY + + + sbSizer3 + wxVERTICAL + 1 + none + + 5 + wxEXPAND|wxLEFT|wxRIGHT + 1 + + 1 + 1 + 1 + 1 + + + + + 0 + 0 + + + + 1 + + + wxALIGN_LEFT + + wxALIGN_TOP + 0 + 1 + wxALIGN_LEFT + 22 + "" "3D Model(s)" "Show" + wxALIGN_CENTER + 3 + 20,650,65 + + 1 + 0 + Dock + 0 + Left + 0 + 0 + 0 + 0 + 1 + 1 + + 1 + + + 0 + 0 + 0 + wxID_ANY + + + + 0 + 0 + + 0 + + + 0 + + 1 + m_modelsGrid + 1 + + + protected + 1 + + Resizable + wxALIGN_CENTER + 0 + + wxALIGN_CENTER + + 3 + 1 + + WX_GRID; widgets/wx_grid.h; forward_declare + 0 + + + + wxBORDER_SIMPLE + On3DModelCellChanged + On3DModelSelected + + + + 5 + wxEXPAND + 0 + + + bSizer3DButtons + wxHORIZONTAL + none + + 5 + wxALIGN_CENTER_VERTICAL|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_ANY + Add 3D Model + + 0 + + 0 + + + 0 + + 1 + m_button3DShapeAdd + 1 + + + protected + 1 + + + + Resizable + 1 + -1,-1 + + ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + OnAdd3DRow + + + + 5 + wxALIGN_CENTER_VERTICAL|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_ANY + Browse + + 0 + + 0 + + + 0 + + 1 + m_button3DShapeBrowse + 1 + + + protected + 1 + + + + Resizable + 1 + -1,-1 + + ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + OnAdd3DModel + + + + 5 + + 0 + + 0 + protected + 20 + + + + 5 + wxALIGN_CENTER_VERTICAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_ANY + Remove 3D Model + + 0 + + 0 + + + 0 + + 1 + m_button3DShapeRemove + 1 + + + protected + 1 + + + + Resizable + 1 + -1,-1 + + ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + OnRemove3DModel + + + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_ANY + Configure Paths... + + 0 + + 0 + + + 0 + + 1 + m_buttonConfig3DPaths + 1 + + + protected + 1 + + + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + Cfg3DPath + + + + + + + + 5 + wxEXPAND + 11 + + + bLowerSizer3D + wxHORIZONTAL + protected + + + + + + diff --git a/pcbnew/dialogs/panel_fp_properties_3d_model_base.h b/pcbnew/dialogs/panel_fp_properties_3d_model_base.h new file mode 100644 index 0000000000..cd5b784f2b --- /dev/null +++ b/pcbnew/dialogs/panel_fp_properties_3d_model_base.h @@ -0,0 +1,65 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Oct 26 2018) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include +#include +class WX_GRID; + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +/// Class PANEL_FP_PROPERTIES_3D_MODEL_BASE +/////////////////////////////////////////////////////////////////////////////// +class PANEL_FP_PROPERTIES_3D_MODEL_BASE : public wxPanel +{ + private: + + protected: + wxBoxSizer* bSizerMain3D; + WX_GRID* m_modelsGrid; + wxBitmapButton* m_button3DShapeAdd; + wxBitmapButton* m_button3DShapeBrowse; + wxBitmapButton* m_button3DShapeRemove; + wxButton* m_buttonConfig3DPaths; + wxBoxSizer* bLowerSizer3D; + + // Virtual event handlers, overide them in your derived class + virtual void OnUpdateUI( wxUpdateUIEvent& event ) { event.Skip(); } + virtual void On3DModelCellChanged( wxGridEvent& event ) { event.Skip(); } + virtual void On3DModelSelected( wxGridEvent& event ) { event.Skip(); } + virtual void OnAdd3DRow( wxCommandEvent& event ) { event.Skip(); } + virtual void OnAdd3DModel( wxCommandEvent& event ) { event.Skip(); } + virtual void OnRemove3DModel( wxCommandEvent& event ) { event.Skip(); } + virtual void Cfg3DPath( wxCommandEvent& event ) { event.Skip(); } + + + public: + + PANEL_FP_PROPERTIES_3D_MODEL_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); + ~PANEL_FP_PROPERTIES_3D_MODEL_BASE(); + +}; +