From 174856bac50ffcac41a84236004880faec52c474 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 10 Apr 2020 22:48:48 +0100 Subject: [PATCH] Promote 3D model "preview" flag to a persisted "show" flag. Fixes https://gitlab.com/kicad/code/kicad/issues/2061 --- .../3d_cache/dialogs/3d_cache_dialogs.cpp | 20 ++----- 3d-viewer/3d_cache/dialogs/panel_prev_3d.cpp | 2 +- .../c3d_render_createscene_ogl_legacy.cpp | 2 +- .../c3d_render_createscene.cpp | 59 ++++++++++--------- pcbnew/class_module.h | 4 +- .../dialog_edit_footprint_for_BoardEditor.cpp | 10 ++-- .../dialog_edit_footprint_for_fp_editor.cpp | 10 ++-- pcbnew/kicad_plugin.cpp | 5 +- pcbnew/pcb_parser.cpp | 29 +++++---- 9 files changed, 72 insertions(+), 69 deletions(-) diff --git a/3d-viewer/3d_cache/dialogs/3d_cache_dialogs.cpp b/3d-viewer/3d_cache/dialogs/3d_cache_dialogs.cpp index f01ad0944f..7ba1b634bf 100644 --- a/3d-viewer/3d_cache/dialogs/3d_cache_dialogs.cpp +++ b/3d-viewer/3d_cache/dialogs/3d_cache_dialogs.cpp @@ -2,6 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015-2016 Cirilo Bernardo + * Copyright (C) 2020 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 @@ -21,33 +22,22 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include - #include "3d_info.h" #include "3d_cache.h" -#include "plugins/3dapi/ifsg_api.h" #include "3d_cache_dialogs.h" #include "dialog_configure_paths.h" #include "dlg_select_3dmodel.h" -bool S3D::Select3DModel( wxWindow* aParent, S3D_CACHE* aCache, - wxString& prevModelSelectDir, int& prevModelWildcard, MODULE_3D_SETTINGS* aModel ) +bool S3D::Select3DModel( wxWindow* aParent, S3D_CACHE* aCache, wxString& prevModelSelectDir, + int& prevModelWildcard, MODULE_3D_SETTINGS* aModel ) { if( NULL == aModel ) return false; - DLG_SELECT_3DMODEL* dm = new DLG_SELECT_3DMODEL( aParent, aCache, aModel, - prevModelSelectDir, prevModelWildcard ); + DLG_SELECT_3DMODEL dm( aParent, aCache, aModel, prevModelSelectDir, prevModelWildcard ); - if( wxID_OK == dm->ShowModal() ) - { - delete dm; - return true; - } - - delete dm; - return false; + return dm.ShowModal() == wxID_OK; } diff --git a/3d-viewer/3d_cache/dialogs/panel_prev_3d.cpp b/3d-viewer/3d_cache/dialogs/panel_prev_3d.cpp index a1bb6bfb2d..cf42d5e7b5 100644 --- a/3d-viewer/3d_cache/dialogs/panel_prev_3d.cpp +++ b/3d-viewer/3d_cache/dialogs/panel_prev_3d.cpp @@ -400,7 +400,7 @@ void PANEL_PREV_3D::UpdateDummyModule( bool aReloadRequired ) for( MODULE_3D_SETTINGS& model : *m_parentModelList) { - if( model.m_Preview ) + if( model.m_Show ) m_dummyModule->Models().push_back( model ); } diff --git a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_createscene_ogl_legacy.cpp b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_createscene_ogl_legacy.cpp index 3901bf1a0f..5b2cf58aec 100644 --- a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_createscene_ogl_legacy.cpp +++ b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_createscene_ogl_legacy.cpp @@ -912,7 +912,7 @@ void C3D_RENDER_OGL_LEGACY::load_3D_models( REPORTER *aStatusTextReporter ) while( sM != eM ) { - if( !sM->m_Filename.empty() ) + if( sM->m_Show && !sM->m_Filename.empty() ) { if( aStatusTextReporter ) { diff --git a/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp b/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp index 6932f4898d..838efc7049 100644 --- a/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp +++ b/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp @@ -1303,46 +1303,49 @@ void C3D_RENDER_RAYTRACING::load_3D_models() // Get the list of model files for this model + S3D_CACHE* cacheMgr = m_boardAdapter.Get3DCacheManager(); auto sM = module->Models().begin(); auto eM = module->Models().end(); while( sM != eM ) { - // get it from cache - const S3DMODEL *modelPtr = - m_boardAdapter.Get3DCacheManager()->GetModel( sM->m_Filename ); - - // only add it if the return is not NULL - if( modelPtr ) + if( sM->m_Show && !sM->m_Filename.empty() ) { - glm::mat4 modelMatrix = moduleMatrix; + // get it from cache + const S3DMODEL *modelPtr = cacheMgr->GetModel( sM->m_Filename ); - modelMatrix = glm::translate( modelMatrix, - SFVEC3F( sM->m_Offset.x, - sM->m_Offset.y, - sM->m_Offset.z ) ); + // only add it if the return is not NULL + if( modelPtr ) + { + glm::mat4 modelMatrix = moduleMatrix; - modelMatrix = glm::rotate( modelMatrix, - (float)-( sM->m_Rotation.z / 180.0f ) * - glm::pi(), - SFVEC3F( 0.0f, 0.0f, 1.0f ) ); + modelMatrix = glm::translate( modelMatrix, + SFVEC3F( sM->m_Offset.x, + sM->m_Offset.y, + sM->m_Offset.z ) ); - modelMatrix = glm::rotate( modelMatrix, - (float)-( sM->m_Rotation.y / 180.0f ) * - glm::pi(), - SFVEC3F( 0.0f, 1.0f, 0.0f ) ); + modelMatrix = glm::rotate( modelMatrix, + (float)-( sM->m_Rotation.z / 180.0f ) * + glm::pi(), + SFVEC3F( 0.0f, 0.0f, 1.0f ) ); - modelMatrix = glm::rotate( modelMatrix, - (float)-( sM->m_Rotation.x / 180.0f ) * - glm::pi(), - SFVEC3F( 1.0f, 0.0f, 0.0f ) ); + modelMatrix = glm::rotate( modelMatrix, + (float)-( sM->m_Rotation.y / 180.0f ) * + glm::pi(), + SFVEC3F( 0.0f, 1.0f, 0.0f ) ); - modelMatrix = glm::scale( modelMatrix, - SFVEC3F( sM->m_Scale.x, - sM->m_Scale.y, - sM->m_Scale.z ) ); + modelMatrix = glm::rotate( modelMatrix, + (float)-( sM->m_Rotation.x / 180.0f ) * + glm::pi(), + SFVEC3F( 1.0f, 0.0f, 0.0f ) ); - add_3D_models( modelPtr, modelMatrix ); + modelMatrix = glm::scale( modelMatrix, + SFVEC3F( sM->m_Scale.x, + sM->m_Scale.y, + sM->m_Scale.z ) ); + + add_3D_models( modelPtr, modelMatrix ); + } } ++sM; diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index ede4268175..b7edf66f68 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -85,7 +85,7 @@ class MODULE_3D_SETTINGS m_Scale { 1, 1, 1 }, m_Rotation { 0, 0, 0 }, m_Offset { 0, 0, 0 }, - m_Preview( true ) + m_Show( true ) { } @@ -98,7 +98,7 @@ class MODULE_3D_SETTINGS VECTOR3D m_Rotation; ///< 3D model rotation (degrees) VECTOR3D m_Offset; ///< 3D model offset (mm) wxString m_Filename; ///< The 3D shape filename in 3D library - bool m_Preview; ///< Include module in 3D preview + bool m_Show; ///< Include module in rendering }; DECL_DEQ_FOR_SWIG( PADS, D_PAD* ) diff --git a/pcbnew/dialogs/dialog_edit_footprint_for_BoardEditor.cpp b/pcbnew/dialogs/dialog_edit_footprint_for_BoardEditor.cpp index 25202c6eb5..28fe14a7e0 100644 --- a/pcbnew/dialogs/dialog_edit_footprint_for_BoardEditor.cpp +++ b/pcbnew/dialogs/dialog_edit_footprint_for_BoardEditor.cpp @@ -377,7 +377,7 @@ bool DIALOG_FOOTPRINT_BOARD_EDITOR::TransferDataToWindow() m_modelsGrid->AppendRows( 1 ); int row = m_modelsGrid->GetNumberRows() - 1; m_modelsGrid->SetCellValue( row, 0, origPath ); - m_modelsGrid->SetCellValue( row, 1, model.m_Preview ? wxT( "1" ) : wxT( "0" ) ); + m_modelsGrid->SetCellValue( row, 1, model.m_Show ? wxT( "1" ) : wxT( "0" ) ); } select3DModel( 0 ); // will clamp idx within bounds @@ -487,9 +487,9 @@ void DIALOG_FOOTPRINT_BOARD_EDITOR::On3DModelCellChanged( wxGridEvent& aEvent ) } else if( aEvent.GetCol() == 1 ) { - wxString previewValue = m_modelsGrid->GetCellValue( aEvent.GetRow(), 1 ); + wxString showValue = m_modelsGrid->GetCellValue( aEvent.GetRow(), 1 ); - m_shapes3D_list[ aEvent.GetRow() ].m_Preview = previewValue == wxT( "1" ); + m_shapes3D_list[ aEvent.GetRow() ].m_Show = ( showValue == wxT( "1" ) ); } m_PreviewPane->UpdateDummyModule(); @@ -564,7 +564,7 @@ void DIALOG_FOOTPRINT_BOARD_EDITOR::OnAdd3DModel( wxCommandEvent& ) model.m_Filename.Replace( "\\", "/" ); #endif - model.m_Preview = true; + model.m_Show = true; m_shapes3D_list.push_back( model ); int idx = m_modelsGrid->GetNumberRows(); @@ -583,7 +583,7 @@ void DIALOG_FOOTPRINT_BOARD_EDITOR::OnAdd3DRow( wxCommandEvent& ) MODULE_3D_SETTINGS model; - model.m_Preview = true; + model.m_Show = true; m_shapes3D_list.push_back( model ); int row = m_modelsGrid->GetNumberRows(); diff --git a/pcbnew/dialogs/dialog_edit_footprint_for_fp_editor.cpp b/pcbnew/dialogs/dialog_edit_footprint_for_fp_editor.cpp index 6ee1570f59..046349fe1f 100644 --- a/pcbnew/dialogs/dialog_edit_footprint_for_fp_editor.cpp +++ b/pcbnew/dialogs/dialog_edit_footprint_for_fp_editor.cpp @@ -301,7 +301,7 @@ bool DIALOG_FOOTPRINT_FP_EDITOR::TransferDataToWindow() m_modelsGrid->AppendRows( 1 ); int row = m_modelsGrid->GetNumberRows() - 1; m_modelsGrid->SetCellValue( row, 0, origPath ); - m_modelsGrid->SetCellValue( row, 1, model.m_Preview ? wxT( "1" ) : wxT( "0" ) ); + m_modelsGrid->SetCellValue( row, 1, model.m_Show ? wxT( "1" ) : wxT( "0" ) ); } select3DModel( 0 ); // will clamp idx within bounds @@ -392,9 +392,9 @@ void DIALOG_FOOTPRINT_FP_EDITOR::On3DModelCellChanged( wxGridEvent& aEvent ) } else if( aEvent.GetCol() == 1 ) { - wxString previewValue = m_modelsGrid->GetCellValue( aEvent.GetRow(), 1 ); + wxString showValue = m_modelsGrid->GetCellValue( aEvent.GetRow(), 1 ); - m_shapes3D_list[ aEvent.GetRow() ].m_Preview = previewValue == wxT( "1" ); + m_shapes3D_list[ aEvent.GetRow() ].m_Show = ( showValue == wxT( "1" ) ); } m_PreviewPane->UpdateDummyModule(); @@ -470,7 +470,7 @@ void DIALOG_FOOTPRINT_FP_EDITOR::OnAdd3DModel( wxCommandEvent& ) model.m_Filename.Replace( "\\", "/" ); #endif - model.m_Preview = true; + model.m_Show = true; m_shapes3D_list.push_back( model ); int idx = m_modelsGrid->GetNumberRows(); @@ -489,7 +489,7 @@ void DIALOG_FOOTPRINT_FP_EDITOR::OnAdd3DRow( wxCommandEvent& ) MODULE_3D_SETTINGS model; - model.m_Preview = true; + model.m_Show = true; m_shapes3D_list.push_back( model ); int row = m_modelsGrid->GetNumberRows(); diff --git a/pcbnew/kicad_plugin.cpp b/pcbnew/kicad_plugin.cpp index 2a57b58b11..41096768cc 100644 --- a/pcbnew/kicad_plugin.cpp +++ b/pcbnew/kicad_plugin.cpp @@ -1156,8 +1156,9 @@ void PCB_IO::format( MODULE* aModule, int aNestLevel ) const { if( !bs3D->m_Filename.IsEmpty() ) { - m_out->Print( aNestLevel+1, "(model %s\n", - m_out->Quotew( bs3D->m_Filename ).c_str() ); + m_out->Print( aNestLevel+1, "(model %s%s\n", + m_out->Quotew( bs3D->m_Filename ).c_str(), + bs3D->m_Show ? "" : " hide" ); /* Write 3D model offset in mm * 4.0.x wrote "at" which was actually in inches diff --git a/pcbnew/pcb_parser.cpp b/pcbnew/pcb_parser.cpp index ff05894593..982a9879ed 100644 --- a/pcbnew/pcb_parser.cpp +++ b/pcbnew/pcb_parser.cpp @@ -386,10 +386,8 @@ MODULE_3D_SETTINGS* PCB_PARSER::parse3DModel() for( token = NextTok(); token != T_RIGHT; token = NextTok() ) { - if( token != T_LEFT ) - Expecting( T_LEFT ); - - token = NextTok(); + if( token == T_LEFT ) + token = NextTok(); switch( token ) { @@ -409,7 +407,13 @@ MODULE_3D_SETTINGS* PCB_PARSER::parse3DModel() n3D->m_Offset.x = parseDouble( "x value" ) * 25.4f; n3D->m_Offset.y = parseDouble( "y value" ) * 25.4f; n3D->m_Offset.z = parseDouble( "z value" ) * 25.4f; - NeedRIGHT(); + + NeedRIGHT(); // xyz + NeedRIGHT(); // at + break; + + case T_hide: + n3D->m_Show = false; break; case T_offset: @@ -425,7 +429,9 @@ MODULE_3D_SETTINGS* PCB_PARSER::parse3DModel() n3D->m_Offset.x = parseDouble( "x value" ); n3D->m_Offset.y = parseDouble( "y value" ); n3D->m_Offset.z = parseDouble( "z value" ); - NeedRIGHT(); + + NeedRIGHT(); // xyz + NeedRIGHT(); // offset break; case T_scale: @@ -438,7 +444,9 @@ MODULE_3D_SETTINGS* PCB_PARSER::parse3DModel() n3D->m_Scale.x = parseDouble( "x value" ); n3D->m_Scale.y = parseDouble( "y value" ); n3D->m_Scale.z = parseDouble( "z value" ); - NeedRIGHT(); + + NeedRIGHT(); // xyz + NeedRIGHT(); // scale break; case T_rotate: @@ -451,14 +459,15 @@ MODULE_3D_SETTINGS* PCB_PARSER::parse3DModel() n3D->m_Rotation.x = parseDouble( "x value" ); n3D->m_Rotation.y = parseDouble( "y value" ); n3D->m_Rotation.z = parseDouble( "z value" ); - NeedRIGHT(); + + NeedRIGHT(); // xyz + NeedRIGHT(); // rotate break; default: - Expecting( "at, offset, scale, or rotate" ); + Expecting( "at, hide, offset, scale, or rotate" ); } - NeedRIGHT(); } return n3D;