diff --git a/pcbnew/dialogs/dialog_footprint_properties.cpp b/pcbnew/dialogs/dialog_footprint_properties.cpp index 8206d6fbb3..0e0b07ed48 100644 --- a/pcbnew/dialogs/dialog_footprint_properties.cpp +++ b/pcbnew/dialogs/dialog_footprint_properties.cpp @@ -41,6 +41,8 @@ #include #include +#include + #include "3d_cache/dialogs/3d_cache_dialogs.h" #include "3d_cache/dialogs/panel_preview_3d_model.h" @@ -53,18 +55,19 @@ int DIALOG_FOOTPRINT_PROPERTIES::m_page = 0; // remember the last open page DIALOG_FOOTPRINT_PROPERTIES::DIALOG_FOOTPRINT_PROPERTIES( PCB_EDIT_FRAME* aParent, FOOTPRINT* aFootprint ) : DIALOG_FOOTPRINT_PROPERTIES_BASE( aParent ), + m_frame( aParent ), + m_footprint( aFootprint ), m_posX( aParent, m_XPosLabel, m_ModPositionX, m_XPosUnit ), m_posY( aParent, m_YPosLabel, m_ModPositionY, m_YPosUnit ), m_orientValidator( 3, &m_orientValue ), 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_initialFocus( true ), - m_inSelect( false ) + m_returnValue( FP_PROPS_CANCEL ) { - m_frame = aParent; - m_footprint = aFootprint; - m_returnValue = FP_PROPS_CANCEL; + // 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 ); // Configure display origin transforms m_posX.SetCoordType( ORIGIN_TRANSFORMS::ABS_X_COORD ); @@ -87,48 +90,19 @@ DIALOG_FOOTPRINT_PROPERTIES::DIALOG_FOOTPRINT_PROPERTIES( PCB_EDIT_FRAME* aParen // 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 ) ); - m_modelsGrid->PushEventHandler( new GRID_TRICKS( m_modelsGrid ) ); PCBNEW_SETTINGS* cfg = m_frame->GetPcbNewSettings(); // Show/hide text item columns according to the user's preference m_itemsGrid->ShowHideColumns( cfg->m_FootprintTextShownColumns ); - // Set up the 3D models grid - // Path selector - if( cfg->m_lastFootprint3dDir.IsEmpty() ) - { - wxGetEnv( KICAD6_3DMODEL_DIR, &cfg->m_lastFootprint3dDir ); - } - - wxGridCellAttr* attr = new wxGridCellAttr; - attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, m_modelsGrid, &cfg->m_lastFootprint3dDir, - "*.*", true, Prj().GetProjectPath() ) ); - m_modelsGrid->SetColAttr( 0, 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( 1, attr ); - m_modelsGrid->SetWindowStyleFlag( m_modelsGrid->GetWindowStyle() & ~wxHSCROLL ); - m_modelsGrid->SetSelectionMode( wxGrid::wxGridSelectRows ); - m_orientValidator.SetRange( -360.0, 360.0 ); m_OrientValueCtrl->SetValidator( m_orientValidator ); m_orientValidator.SetWindow( m_OrientValueCtrl ); - 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 ); - // Set font size for items showing long strings: wxFont infoFont = KIUI::GetInfoFont(); #if __WXMAC__ @@ -153,16 +127,10 @@ DIALOG_FOOTPRINT_PROPERTIES::DIALOG_FOOTPRINT_PROPERTIES( PCB_EDIT_FRAME* aParen m_delayedFocusRow = 0; m_delayedFocusColumn = 0; } - else if ( m_page == 1 ) + else if( m_page == 1 ) { SetInitialFocus( m_NetClearanceCtrl ); } - else - { - m_delayedFocusGrid = m_modelsGrid; - m_delayedFocusRow = 0; - m_delayedFocusColumn = 0; - } m_sdbSizerStdButtonsOK->SetDefault(); @@ -171,9 +139,6 @@ DIALOG_FOOTPRINT_PROPERTIES::DIALOG_FOOTPRINT_PROPERTIES( PCB_EDIT_FRAME* aParen // Configure button logos m_bpAdd->SetBitmap( KiBitmap( BITMAPS::small_plus ) ); m_bpDelete->SetBitmap( KiBitmap( BITMAPS::small_trash ) ); - m_buttonAdd->SetBitmap( KiBitmap( BITMAPS::small_plus ) ); - m_buttonBrowse->SetBitmap( KiBitmap( BITMAPS::small_folder ) ); - m_buttonRemove->SetBitmap( KiBitmap( BITMAPS::small_trash ) ); finishDialogSettings(); } @@ -189,7 +154,6 @@ DIALOG_FOOTPRINT_PROPERTIES::~DIALOG_FOOTPRINT_PROPERTIES() // 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 @@ -198,8 +162,6 @@ DIALOG_FOOTPRINT_PROPERTIES::~DIALOG_FOOTPRINT_PROPERTIES() // the GL canvas has to be visible before it is destroyed m_page = m_NoteBook->GetSelection(); m_NoteBook->SetSelection( 1 ); - - delete m_previewPane; } @@ -286,11 +248,11 @@ bool DIALOG_FOOTPRINT_PROPERTIES::TransferDataToWindow() if( !m_PanelGeneral->TransferDataToWindow() ) return false; - if( !m_Panel3D->TransferDataToWindow() ) + // Add the models to the panel + if( !m_3dPanel->TransferDataToWindow() ) return false; // Footprint Texts - m_texts->push_back( m_footprint->Reference() ); m_texts->push_back( m_footprint->Value() ); @@ -381,30 +343,6 @@ bool DIALOG_FOOTPRINT_PROPERTIES::TransferDataToWindow() case ZONE_CONNECTION::NONE: m_ZoneConnectionChoice->SetSelection( 3 ); break; } - // 3D Settings - 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, 0, origPath ); - m_modelsGrid->SetCellValue( row, 1, model.m_Show ? wxT( "1" ) : wxT( "0" ) ); - } - - select3DModel( 0 ); // will clamp idx within bounds - m_previewPane->UpdateDummyFootprint(); - // Show the footprint's FPID. m_tcLibraryID->SetValue( m_footprint->GetFPID().Format() ); @@ -431,7 +369,6 @@ bool DIALOG_FOOTPRINT_PROPERTIES::TransferDataToWindow() } m_itemsGrid->SetRowLabelSize( m_itemsGrid->GetVisibleWidth( -1, false, true, true ) ); - m_modelsGrid->SetColSize( 1, m_modelsGrid->GetVisibleWidth( 1, true, false, false ) ); Layout(); adjustGridColumns( m_itemsGrid->GetRect().GetWidth() ); @@ -440,185 +377,6 @@ bool DIALOG_FOOTPRINT_PROPERTIES::TransferDataToWindow() } -void DIALOG_FOOTPRINT_PROPERTIES::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, 0 ); - } - - m_previewPane->SetSelectedModel( aModelIdx ); - - m_inSelect = false; -} - - -void DIALOG_FOOTPRINT_PROPERTIES::On3DModelSelected( wxGridEvent& aEvent ) -{ - if( !m_inSelect ) - select3DModel( aEvent.GetRow() ); -} - - -void DIALOG_FOOTPRINT_PROPERTIES::On3DModelCellChanged( wxGridEvent& aEvent ) -{ - if( aEvent.GetCol() == 0 ) - { - bool hasAlias = false; - FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver(); - wxString filename = m_modelsGrid->GetCellValue( aEvent.GetRow(), 0 ); - - 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(); - 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(), 0, filename ); - } - else if( aEvent.GetCol() == 1 ) - { - wxString showValue = m_modelsGrid->GetCellValue( aEvent.GetRow(), 1 ); - - m_shapes3D_list[ aEvent.GetRow() ].m_Show = ( showValue == wxT( "1" ) ); - } - - m_previewPane->UpdateDummyFootprint(); -} - - -void DIALOG_FOOTPRINT_PROPERTIES::OnRemove3DModel( wxCommandEvent& ) -{ - m_modelsGrid->CommitPendingChanges( true /* quiet mode */ ); - - 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, 1 ); - - select3DModel( idx ); // will clamp idx within bounds - m_previewPane->UpdateDummyFootprint(); - } -} - - -void DIALOG_FOOTPRINT_PROPERTIES::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, 0, filename ); - m_modelsGrid->SetCellValue( idx, 1, wxT( "1" ) ); - - select3DModel( idx ); - m_previewPane->UpdateDummyFootprint(); -} - - -void DIALOG_FOOTPRINT_PROPERTIES::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, 1, wxT( "1" ) ); - - select3DModel( row ); - - m_modelsGrid->SetFocus(); - m_modelsGrid->MakeCellVisible( row, 0 ); - m_modelsGrid->SetGridCursor( row, 0 ); - - m_modelsGrid->EnableCellEditControl( true ); - m_modelsGrid->ShowCellEditControl(); -} - - bool DIALOG_FOOTPRINT_PROPERTIES::Validate() { if( !m_itemsGrid->CommitPendingChanges() ) @@ -661,7 +419,9 @@ bool DIALOG_FOOTPRINT_PROPERTIES::TransferDataFromWindow() if( !m_itemsGrid->CommitPendingChanges() ) return false; - if( !m_modelsGrid->CommitPendingChanges() ) + // This only commits the editor, model updating is done below so it is inside + // the commit + if( !m_3dPanel->TransferDataFromWindow() ) return false; auto view = m_frame->GetCanvas()->GetView(); @@ -774,9 +534,11 @@ bool DIALOG_FOOTPRINT_PROPERTIES::TransferDataFromWindow() if( change_layer ) m_footprint->Flip( m_footprint->GetPosition(), m_frame->Settings().m_FlipLeftRight ); - 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() ); // This is a simple edit, we must create an undo entry if( m_footprint->GetEditFlags() == 0 ) // i.e. not edited, or moved @@ -850,18 +612,10 @@ void DIALOG_FOOTPRINT_PROPERTIES::OnDeleteField( wxCommandEvent& ) } -void DIALOG_FOOTPRINT_PROPERTIES::Cfg3DPath( wxCommandEvent& ) -{ - if( S3D::Configure3DPaths( this, Prj().Get3DCacheManager()->GetResolver() ) ) - m_previewPane->UpdateDummyFootprint(); -} - - void DIALOG_FOOTPRINT_PROPERTIES::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(); @@ -874,13 +628,14 @@ void DIALOG_FOOTPRINT_PROPERTIES::adjustGridColumns( int aWidth ) m_itemsGrid->GetVisibleWidth( 0, true, false, false ) ) ); } - m_modelsGrid->SetColSize( 0, modelsWidth - m_modelsGrid->GetColSize( 1 ) - 6 ); + // Update the width of the 3D panel + m_3dPanel->AdjustGridColumnWidths( aWidth ); } void DIALOG_FOOTPRINT_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& ) { - if( !m_itemsGrid->IsCellEditControlShown() && !m_modelsGrid->IsCellEditControlShown() ) + if( !m_itemsGrid->IsCellEditControlShown() ) adjustGridColumns( m_itemsGrid->GetRect().GetWidth() ); // Handle a grid error. This is delayed to OnUpdateUI so that we can change focus @@ -930,8 +685,6 @@ void DIALOG_FOOTPRINT_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& ) } m_initialFocus = false; } - - m_buttonRemove->Enable( m_modelsGrid->GetNumberRows() > 0 ); } diff --git a/pcbnew/dialogs/dialog_footprint_properties.h b/pcbnew/dialogs/dialog_footprint_properties.h index 0d16fb46ec..9529d955d5 100644 --- a/pcbnew/dialogs/dialog_footprint_properties.h +++ b/pcbnew/dialogs/dialog_footprint_properties.h @@ -35,8 +35,7 @@ class PCB_EDIT_FRAME; -class PANEL_PREVIEW_3D_MODEL; - +class PANEL_FP_PROPERTIES_3D_MODEL; class DIALOG_FOOTPRINT_PROPERTIES: public DIALOG_FOOTPRINT_PROPERTIES_BASE { @@ -65,18 +64,12 @@ public: private: // virtual event functions - void On3DModelSelected( wxGridEvent& ) override; - void On3DModelCellChanged( wxGridEvent& aEvent ) override; - void OnRemove3DModel( wxCommandEvent& ) override; - void OnAdd3DModel( wxCommandEvent& ) override; - void OnAdd3DRow( wxCommandEvent& ) override; void EditFootprint( wxCommandEvent& ) override; void EditLibraryFootprint( wxCommandEvent& ) override; void UpdateFootprint( wxCommandEvent& ) override; void ChangeFootprint( wxCommandEvent& ) override; void FootprintOrientEvent( wxCommandEvent& ) override; void OnOtherOrientation( wxCommandEvent& aEvent ) override; - void Cfg3DPath( wxCommandEvent& ) override; void OnGridSize( wxSizeEvent& aEvent ) override; void OnAddField( wxCommandEvent& ) override; void OnDeleteField( wxCommandEvent& ) override; @@ -109,18 +102,16 @@ private: UNIT_BINDER m_solderMask; UNIT_BINDER m_solderPaste; - std::vector m_shapes3D_list; - PANEL_PREVIEW_3D_MODEL* m_previewPane; - wxString m_delayedErrorMessage; wxGrid* m_delayedFocusGrid; int m_delayedFocusRow; int m_delayedFocusColumn; bool m_initialFocus; - bool m_inSelect; std::vector m_macHack; enum FP_PROPS_RETVALUE m_returnValue; // the option that closed the dialog + + PANEL_FP_PROPERTIES_3D_MODEL* m_3dPanel; }; diff --git a/pcbnew/dialogs/dialog_footprint_properties_base.cpp b/pcbnew/dialogs/dialog_footprint_properties_base.cpp index e577a9a19f..93d5a83f77 100644 --- a/pcbnew/dialogs/dialog_footprint_properties_base.cpp +++ b/pcbnew/dialogs/dialog_footprint_properties_base.cpp @@ -431,81 +431,6 @@ DIALOG_FOOTPRINT_PROPERTIES_BASE::DIALOG_FOOTPRINT_PROPERTIES_BASE( wxWindow* pa m_PanelClearances->Layout(); bSizerPanelClearances->Fit( m_PanelClearances ); m_NoteBook->AddPage( m_PanelClearances, _("Clearance Overrides and Settings"), true ); - 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, 0 ); - - // Grid - m_modelsGrid->CreateGrid( 3, 2 ); - m_modelsGrid->EnableEditing( true ); - m_modelsGrid->EnableGridLines( true ); - m_modelsGrid->EnableDragGridSize( false ); - m_modelsGrid->SetMargins( 0, 0 ); - - // Columns - m_modelsGrid->SetColSize( 0, 650 ); - m_modelsGrid->SetColSize( 1, 65 ); - m_modelsGrid->EnableDragColMove( false ); - m_modelsGrid->EnableDragColSize( false ); - m_modelsGrid->SetColLabelSize( 24 ); - m_modelsGrid->SetColLabelValue( 0, _("3D Model(s)") ); - m_modelsGrid->SetColLabelValue( 1, _("Show") ); - m_modelsGrid->SetColLabelAlignment( wxALIGN_CENTER, 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 ); - m_modelsGrid->SetMinSize( wxSize( -1,56 ) ); - - sbSizer3->Add( m_modelsGrid, 1, wxALL|wxEXPAND, 5 ); - - wxBoxSizer* bSizer3DButtons; - bSizer3DButtons = new wxBoxSizer( wxHORIZONTAL ); - - m_buttonAdd = new wxBitmapButton( sbSizer3->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( -1,-1 ), wxBU_AUTODRAW|0 ); - bSizer3DButtons->Add( m_buttonAdd, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); - - m_buttonBrowse = new wxBitmapButton( sbSizer3->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( -1,-1 ), wxBU_AUTODRAW|0 ); - bSizer3DButtons->Add( m_buttonBrowse, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); - - - bSizer3DButtons->Add( 20, 0, 0, wxEXPAND, 5 ); - - m_buttonRemove = new wxBitmapButton( sbSizer3->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( -1,-1 ), wxBU_AUTODRAW|0 ); - bSizer3DButtons->Add( m_buttonRemove, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); - - - bSizer3DButtons->Add( 0, 0, 1, wxEXPAND, 5 ); - - m_buttonCfgPath = new wxButton( sbSizer3->GetStaticBox(), wxID_ANY, _("Configure Paths..."), wxDefaultPosition, wxDefaultSize, 0 ); - bSizer3DButtons->Add( m_buttonCfgPath, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT|wxRIGHT, 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 ); @@ -570,12 +495,6 @@ DIALOG_FOOTPRINT_PROPERTIES_BASE::DIALOG_FOOTPRINT_PROPERTIES_BASE( wxWindow* pa m_buttonExchange->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_BASE::ChangeFootprint ), NULL, this ); m_buttonModuleEditor->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_BASE::EditFootprint ), NULL, this ); m_button5->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_BASE::EditLibraryFootprint ), NULL, this ); - m_modelsGrid->Connect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_FOOTPRINT_PROPERTIES_BASE::On3DModelCellChanged ), NULL, this ); - m_modelsGrid->Connect( wxEVT_GRID_SELECT_CELL, wxGridEventHandler( DIALOG_FOOTPRINT_PROPERTIES_BASE::On3DModelSelected ), NULL, this ); - m_buttonAdd->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_BASE::OnAdd3DRow ), NULL, this ); - m_buttonBrowse->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_BASE::OnAdd3DModel ), NULL, this ); - m_buttonRemove->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_BASE::OnRemove3DModel ), NULL, this ); - m_buttonCfgPath->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_BASE::Cfg3DPath ), NULL, this ); } DIALOG_FOOTPRINT_PROPERTIES_BASE::~DIALOG_FOOTPRINT_PROPERTIES_BASE() @@ -597,11 +516,5 @@ DIALOG_FOOTPRINT_PROPERTIES_BASE::~DIALOG_FOOTPRINT_PROPERTIES_BASE() m_buttonExchange->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_BASE::ChangeFootprint ), NULL, this ); m_buttonModuleEditor->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_BASE::EditFootprint ), NULL, this ); m_button5->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_BASE::EditLibraryFootprint ), NULL, this ); - m_modelsGrid->Disconnect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_FOOTPRINT_PROPERTIES_BASE::On3DModelCellChanged ), NULL, this ); - m_modelsGrid->Disconnect( wxEVT_GRID_SELECT_CELL, wxGridEventHandler( DIALOG_FOOTPRINT_PROPERTIES_BASE::On3DModelSelected ), NULL, this ); - m_buttonAdd->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_BASE::OnAdd3DRow ), NULL, this ); - m_buttonBrowse->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_BASE::OnAdd3DModel ), NULL, this ); - m_buttonRemove->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_BASE::OnRemove3DModel ), NULL, this ); - m_buttonCfgPath->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_PROPERTIES_BASE::Cfg3DPath ), NULL, this ); } diff --git a/pcbnew/dialogs/dialog_footprint_properties_base.fbp b/pcbnew/dialogs/dialog_footprint_properties_base.fbp index 219edd05b5..6ddbbd3ada 100644 --- a/pcbnew/dialogs/dialog_footprint_properties_base.fbp +++ b/pcbnew/dialogs/dialog_footprint_properties_base.fbp @@ -3795,507 +3795,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 - wxALL|wxEXPAND - 1 - - 1 - 1 - 1 - 1 - - - - - 0 - 0 - - - - 1 - - - wxALIGN_LEFT - - wxALIGN_TOP - 0 - 1 - wxALIGN_CENTER - 24 - "3D Model(s)" "Show" - wxALIGN_CENTER - 2 - 650,65 - - 1 - 0 - Dock - 0 - Left - 0 - 0 - 0 - 0 - 1 - 1 - - 1 - - - 1 - 0 - 0 - wxID_ANY - - - - 0 - 0 - - 0 - - - 0 - -1,56 - 1 - m_modelsGrid - 1 - - - protected - 1 - - Resizable - wxALIGN_CENTER - 0 - - wxALIGN_CENTER - - 3 - 1 - - WX_GRID; widgets/wx_grid.h; forward_declare - 0 - - - - - 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,-1 - 1 - m_buttonAdd - 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,-1 - 1 - m_buttonBrowse - 1 - - - protected - 1 - - - - Resizable - 1 - -1,-1 - - ; forward_declare - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - OnAdd3DModel - - - - 5 - wxEXPAND - 0 - - 0 - protected - 20 - - - - 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 - Remove 3D Model - - 0 - - 0 - - - 0 - -1,-1 - 1 - m_buttonRemove - 1 - - - protected - 1 - - - - Resizable - 1 - -1,-1 - - ; forward_declare - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - OnRemove3DModel - - - - 5 - wxEXPAND - 1 - - 0 - protected - 0 - - - - 5 - wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT|wxRIGHT - 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_buttonCfgPath - 1 - - - protected - 1 - - - - Resizable - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - Cfg3DPath - - - - - - - - 5 - wxEXPAND - 11 - - - bLowerSizer3D - wxHORIZONTAL - protected - - - - - diff --git a/pcbnew/dialogs/dialog_footprint_properties_base.h b/pcbnew/dialogs/dialog_footprint_properties_base.h index c6c04cbe0c..0af9bf2183 100644 --- a/pcbnew/dialogs/dialog_footprint_properties_base.h +++ b/pcbnew/dialogs/dialog_footprint_properties_base.h @@ -109,14 +109,6 @@ class DIALOG_FOOTPRINT_PROPERTIES_BASE : public DIALOG_SHIM wxStaticText* m_staticTextInfoPaste; wxStaticText* m_staticText16; wxChoice* m_ZoneConnectionChoice; - wxPanel* m_Panel3D; - wxBoxSizer* bSizerMain3D; - WX_GRID* m_modelsGrid; - wxBitmapButton* m_buttonAdd; - wxBitmapButton* m_buttonBrowse; - wxBitmapButton* m_buttonRemove; - wxButton* m_buttonCfgPath; - wxBoxSizer* bLowerSizer3D; wxStaticText* m_libraryIDLabel; wxTextCtrl* m_tcLibraryID; wxStdDialogButtonSizer* m_sdbSizerStdButtons; @@ -136,12 +128,6 @@ class DIALOG_FOOTPRINT_PROPERTIES_BASE : public DIALOG_SHIM virtual void ChangeFootprint( wxCommandEvent& event ) { event.Skip(); } virtual void EditFootprint( wxCommandEvent& event ) { event.Skip(); } virtual void EditLibraryFootprint( 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/dialog_footprint_properties_fp_editor.cpp b/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp index 45938cf4e5..52aa913514 100644 --- a/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp +++ b/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp @@ -83,7 +83,7 @@ DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR( m_delayedFocusPage = NOTEBOOK_PAGES::PAGE_UNKNOWN; // Give an icon - wxIcon icon; + wxIcon icon; icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_modedit ) ); SetIcon( icon ); @@ -93,7 +93,6 @@ DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR( m_itemsGrid->SetTable( m_texts ); m_itemsGrid->PushEventHandler( new GRID_TRICKS( m_itemsGrid ) ); - // Show/hide columns according to the user's preference m_itemsGrid->ShowHideColumns( m_frame->GetSettings()->m_FootprintTextShownColumns ); @@ -126,14 +125,6 @@ DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR( { SetInitialFocus( m_NetClearanceCtrl ); } -/* else - { - m_delayedFocusGrid = m_modelsGrid; - m_delayedFocusRow = 0; - m_delayedFocusColumn = 0; - m_delayedFocusPage = NOTEBOOK_PAGES::PAGE_3D_MODELS; - } - */ m_sdbSizerStdButtonsOK->SetDefault(); @@ -188,11 +179,11 @@ bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataToWindow() if( !m_PanelGeneral->TransferDataToWindow() ) return false; + // Add the models to the panel if( !m_3dPanel->TransferDataToWindow() ) return false; - // Module Texts - + // Footprint Texts m_texts->push_back( m_footprint->Reference() ); m_texts->push_back( m_footprint->Value() ); @@ -204,7 +195,7 @@ bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataToWindow() m_texts->push_back( *textItem ); } - // notify the grid + // Notify the grid wxGridTableMessage tmsg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_texts->GetNumberRows() ); m_itemsGrid->ProcessTableMessage( tmsg ); @@ -247,23 +238,12 @@ bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataToWindow() switch( m_footprint->GetZoneConnection() ) { default: - case ZONE_CONNECTION::INHERITED: - m_ZoneConnectionChoice->SetSelection( 0 ); - break; - case ZONE_CONNECTION::FULL: - m_ZoneConnectionChoice->SetSelection( 1 ); - break; - case ZONE_CONNECTION::THERMAL: - m_ZoneConnectionChoice->SetSelection( 2 ); - break; - case ZONE_CONNECTION::NONE: - m_ZoneConnectionChoice->SetSelection( 3 ); - break; + case ZONE_CONNECTION::INHERITED: m_ZoneConnectionChoice->SetSelection( 0 ); break; + case ZONE_CONNECTION::FULL: m_ZoneConnectionChoice->SetSelection( 1 ); break; + case ZONE_CONNECTION::THERMAL: m_ZoneConnectionChoice->SetSelection( 2 ); break; + case ZONE_CONNECTION::NONE: m_ZoneConnectionChoice->SetSelection( 3 ); break; } - // 3D Settings - m_3dPanel->ReloadModelsFromFootprint(); - // Items grid for( int col = 0; col < m_itemsGrid->GetNumberCols(); col++ ) { @@ -374,7 +354,8 @@ bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataFromWindow() if( !m_itemsGrid->CommitPendingChanges() ) return false; - // This only commits the editor, model updating is done below + // This only commits the editor, model updating is done below so it is inside + // the commit if( !m_3dPanel->TransferDataFromWindow() ) return false; @@ -555,7 +536,9 @@ void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnDeleteField( wxCommandEvent& event int curRow = m_itemsGrid->GetGridCursorRow(); if( curRow < 0 ) + { return; + } else if( curRow < 2 ) { DisplayError( nullptr, _( "Reference and value are mandatory." ) ); @@ -589,7 +572,7 @@ void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::adjustGridColumns( int aWidth ) if( itemsWidth > 0 ) { m_itemsGrid->SetColSize( 0, std::max( itemsWidth, - m_itemsGrid->GetVisibleWidth( 0, true, false, false ) ) ); + m_itemsGrid->GetVisibleWidth( 0, true, false, false ) ) ); } // Update the width of the 3D panel @@ -602,11 +585,6 @@ void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnUpdateUI( wxUpdateUIEvent& event ) if( !m_itemsGrid->IsCellEditControlShown() ) adjustGridColumns( m_itemsGrid->GetRect().GetWidth() ); - if( m_itemsGrid->IsCellEditControlShown() ) - { - // Currently: nothing to do - } - // Handle a delayed focus. The delay allows us to: // a) change focus when the error was triggered from within a killFocus handler // b) show the correct notebook page in the background before the error dialog comes up diff --git a/pcbnew/dialogs/panel_fp_properties_3d_model.cpp b/pcbnew/dialogs/panel_fp_properties_3d_model.cpp index 5765e95f84..7a5c5378f7 100644 --- a/pcbnew/dialogs/panel_fp_properties_3d_model.cpp +++ b/pcbnew/dialogs/panel_fp_properties_3d_model.cpp @@ -52,7 +52,7 @@ enum MODELS_TABLE_COLUMNS }; PANEL_FP_PROPERTIES_3D_MODEL::PANEL_FP_PROPERTIES_3D_MODEL( - FOOTPRINT_EDIT_FRAME* aFrame, FOOTPRINT* aFootprint, DIALOG_SHIM* aDialogParent, + PCB_BASE_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 ), @@ -119,6 +119,12 @@ PANEL_FP_PROPERTIES_3D_MODEL::~PANEL_FP_PROPERTIES_3D_MODEL() } +bool PANEL_FP_PROPERTIES_3D_MODEL::TransferDataToWindow() +{ + ReloadModelsFromFootprint(); + return true; +} + bool PANEL_FP_PROPERTIES_3D_MODEL::TransferDataFromWindow() { // Only commit changes in the editor, not the models @@ -163,9 +169,9 @@ void PANEL_FP_PROPERTIES_3D_MODEL::ReloadModelsFromFootprint() updateValidateStatus( row ); } - select3DModel( 0 ); // will clamp idx within bounds - m_previewPane->UpdateDummyFootprint(); + select3DModel( 0 ); + m_previewPane->UpdateDummyFootprint(); m_modelsGrid->SetColSize( COL_SHOWN, m_modelsGrid->GetVisibleWidth( COL_SHOWN, true, false, false ) ); Layout(); @@ -210,6 +216,7 @@ void PANEL_FP_PROPERTIES_3D_MODEL::On3DModelCellChanged( wxGridEvent& aEvent ) filename.Replace( "\r", "" ); filename.Replace( "\t", "" ); + // The user is warned about failed validation through the updateValidateStatus call below if( filename.empty() || !res->ValidateFileName( filename, hasAlias ) ) aEvent.Veto(); diff --git a/pcbnew/dialogs/panel_fp_properties_3d_model.h b/pcbnew/dialogs/panel_fp_properties_3d_model.h index 7a0b5db2d2..a901f88e15 100644 --- a/pcbnew/dialogs/panel_fp_properties_3d_model.h +++ b/pcbnew/dialogs/panel_fp_properties_3d_model.h @@ -30,8 +30,8 @@ #include class DIALOG_SHIM; -class FOOTPRINT_EDIT_FRAME; class PANEL_PREVIEW_3D_MODEL; +class PCB_BASE_EDIT_FRAME; enum class MODEL_VALIDATE_ERRORS { @@ -45,7 +45,7 @@ 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, + PANEL_FP_PROPERTIES_3D_MODEL( PCB_BASE_EDIT_FRAME* aFrame, FOOTPRINT* aFootprint, DIALOG_SHIM* aDialogParent, wxWindow* aParent, wxWindowID aId = wxID_ANY, const wxPoint& aPos = wxDefaultPosition, @@ -55,6 +55,7 @@ public: ~PANEL_FP_PROPERTIES_3D_MODEL() override; + bool TransferDataToWindow() override; bool TransferDataFromWindow() override; void ReloadModelsFromFootprint(); @@ -84,14 +85,14 @@ private: void select3DModel( int aModelIdx ); private: - DIALOG_SHIM* m_parentDialog; - FOOTPRINT_EDIT_FRAME* m_frame; - FOOTPRINT* m_footprint; + DIALOG_SHIM* m_parentDialog; + PCB_BASE_EDIT_FRAME* m_frame; + FOOTPRINT* m_footprint; - std::vector m_shapes3D_list; - PANEL_PREVIEW_3D_MODEL* m_previewPane; + std::vector m_shapes3D_list; + PANEL_PREVIEW_3D_MODEL* m_previewPane; - bool m_inSelect; + bool m_inSelect; }; #endif // PANEL_FP_PROPERTIES_3D_MODEL_H_