Promote 3D model "preview" flag to a persisted "show" flag.

Fixes https://gitlab.com/kicad/code/kicad/issues/2061
This commit is contained in:
Jeff Young 2020-04-10 22:48:48 +01:00
parent 191d4daf53
commit 174856bac5
9 changed files with 72 additions and 69 deletions

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* 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 <wx/filename.h>
#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;
}

View File

@ -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 );
}

View File

@ -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 )
{

View File

@ -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<float>(),
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<float>(),
SFVEC3F( 0.0f, 1.0f, 0.0f ) );
modelMatrix = glm::rotate( modelMatrix,
(float)-( sM->m_Rotation.z / 180.0f ) *
glm::pi<float>(),
SFVEC3F( 0.0f, 0.0f, 1.0f ) );
modelMatrix = glm::rotate( modelMatrix,
(float)-( sM->m_Rotation.x / 180.0f ) *
glm::pi<float>(),
SFVEC3F( 1.0f, 0.0f, 0.0f ) );
modelMatrix = glm::rotate( modelMatrix,
(float)-( sM->m_Rotation.y / 180.0f ) *
glm::pi<float>(),
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<float>(),
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;

View File

@ -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* )

View File

@ -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();

View File

@ -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();

View File

@ -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

View File

@ -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;