Don't lose model filepath when writing spin boxes back.

Also renames a bunch of stuff to be clearer.

Fixes: lp:1782753
* https://bugs.launchpad.net/kicad/+bug/1782753
This commit is contained in:
Jeff Young 2018-07-20 21:56:12 +01:00
parent 87f72c3d97
commit ea3ef1eb87
4 changed files with 53 additions and 54 deletions

View File

@ -40,7 +40,7 @@
PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent, PCB_BASE_FRAME* aFrame, MODULE* aModule,
std::vector<MODULE_3D_SETTINGS> *aParentInfoList ) :
std::vector<MODULE_3D_SETTINGS> *aParentModelList ) :
PANEL_PREV_3D_BASE( aParent, wxID_ANY )
{
m_userUnits = aFrame->GetUserUnits();
@ -50,10 +50,10 @@ PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent, PCB_BASE_FRAME* aFrame, MODULE*
// Initialize the color settings to draw the board and the footprint
m_dummyBoard->SetColorsSettings( &aFrame->Settings().Colors() );
m_parentInfoList = aParentInfoList;
m_parentModelList = aParentModelList;
m_copyModule = new MODULE( *aModule );
m_dummyBoard->Add( m_copyModule );
m_dummyModule = new MODULE( *aModule );
m_dummyBoard->Add( m_dummyModule );
// Set 3d viewer configuration for preview
m_settings3Dviewer = new CINFO3D_VISU();
@ -80,7 +80,7 @@ PANEL_PREV_3D::~PANEL_PREV_3D()
void PANEL_PREV_3D::initPanel()
{
m_dummyBoard = new BOARD();
m_currentSelectedIdx = -1;
m_selected = -1;
// Set the bitmap of 3D view buttons:
m_bpvTop->SetBitmap( KiBitmap( axis3d_top_xpm ) );
@ -155,12 +155,12 @@ wxString PANEL_PREV_3D::formatOffsetValue( double aValue )
}
void PANEL_PREV_3D::SetModelDataIdx( int idx )
void PANEL_PREV_3D::SetSelectedModel( int idx )
{
if( m_parentInfoList && idx >= 0 && idx < (int) m_parentInfoList->size() )
if( m_parentModelList && idx >= 0 && idx < (int) m_parentModelList->size() )
{
m_currentSelectedIdx = idx;
const MODULE_3D_SETTINGS& modelInfo = m_parentInfoList->at( idx );
m_selected = idx;
const MODULE_3D_SETTINGS& modelInfo = m_parentModelList->at( (unsigned) m_selected );
// Use ChangeValue() instead of SetValue(). It's not the user making the change, so we
// don't want to generate wxEVT_GRID_CELL_CHANGED events.
@ -179,7 +179,7 @@ void PANEL_PREV_3D::SetModelDataIdx( int idx )
}
else
{
m_currentSelectedIdx = -1;
m_selected = -1;
xscale->ChangeValue( wxEmptyString );
yscale->ChangeValue( wxEmptyString );
@ -198,27 +198,25 @@ void PANEL_PREV_3D::SetModelDataIdx( int idx )
void PANEL_PREV_3D::updateOrientation( wxCommandEvent &event )
{
MODULE_3D_SETTINGS modelInfo;
modelInfo.m_Scale.x = DoubleValueFromString( UNSCALED_UNITS, xscale->GetValue() );
modelInfo.m_Scale.y = DoubleValueFromString( UNSCALED_UNITS, yscale->GetValue() );
modelInfo.m_Scale.z = DoubleValueFromString( UNSCALED_UNITS, zscale->GetValue() );
modelInfo.m_Rotation.x = rotationFromString( xrot->GetValue() );
modelInfo.m_Rotation.y = rotationFromString( yrot->GetValue() );
modelInfo.m_Rotation.z = rotationFromString( zrot->GetValue() );
modelInfo.m_Offset.x = DoubleValueFromString( m_userUnits, xoff->GetValue() ) / IU_PER_MM;
modelInfo.m_Offset.y = DoubleValueFromString( m_userUnits, yoff->GetValue() ) / IU_PER_MM;
modelInfo.m_Offset.z = DoubleValueFromString( m_userUnits, zoff->GetValue() ) / IU_PER_MM;
if( m_currentSelectedIdx >= 0 )
if( m_parentModelList && m_selected >= 0 && m_selected < (int) m_parentModelList->size() )
{
// This will update the parent list with the new data
m_parentInfoList->at( m_currentSelectedIdx ) = modelInfo;
// Write settings back to the parent
MODULE_3D_SETTINGS* modelInfo = &m_parentModelList->at( (unsigned) m_selected );
// It will update the copy model in the preview board
UpdateModelInfoList( false );
modelInfo->m_Scale.x = DoubleValueFromString( UNSCALED_UNITS, xscale->GetValue() );
modelInfo->m_Scale.y = DoubleValueFromString( UNSCALED_UNITS, yscale->GetValue() );
modelInfo->m_Scale.z = DoubleValueFromString( UNSCALED_UNITS, zscale->GetValue() );
modelInfo->m_Rotation.x = rotationFromString( xrot->GetValue() );
modelInfo->m_Rotation.y = rotationFromString( yrot->GetValue() );
modelInfo->m_Rotation.z = rotationFromString( zrot->GetValue() );
modelInfo->m_Offset.x = DoubleValueFromString( m_userUnits, xoff->GetValue() ) / IU_PER_MM;
modelInfo->m_Offset.y = DoubleValueFromString( m_userUnits, yoff->GetValue() ) / IU_PER_MM;
modelInfo->m_Offset.z = DoubleValueFromString( m_userUnits, zoff->GetValue() ) / IU_PER_MM;
// Update the dummy module for the preview
UpdateDummyModule( false );
}
}
@ -363,16 +361,17 @@ void PANEL_PREV_3D::onMouseWheelOffset( wxMouseEvent& event )
}
void PANEL_PREV_3D::UpdateModelInfoList( bool aReloadRequired )
void PANEL_PREV_3D::UpdateDummyModule( bool aReloadRequired )
{
auto moduleModelList = &m_copyModule->Models();
m_dummyModule->Models().clear();
moduleModelList->clear();
for( size_t i = 0; i < m_parentInfoList->size(); ++i )
for( size_t i = 0; i < m_parentModelList->size(); ++i )
{
if( m_parentInfoList->at( i ).m_Preview )
moduleModelList->insert( moduleModelList->end(), m_parentInfoList->at( i ) );
if( m_parentModelList->at( i ).m_Preview )
{
m_dummyModule->Models().insert( m_dummyModule->Models().end(),
m_parentModelList->at( i ) );
}
}
if( aReloadRequired )

View File

@ -73,7 +73,7 @@ class PANEL_PREV_3D: public PANEL_PREV_3D_BASE
{
public:
PANEL_PREV_3D( wxWindow* aParent, PCB_BASE_FRAME* aFrame, MODULE* aModule,
std::vector<MODULE_3D_SETTINGS> *aParentInfoList );
std::vector<MODULE_3D_SETTINGS> *aParentModelList );
~PANEL_PREV_3D();
@ -82,10 +82,10 @@ private:
CINFO3D_VISU* m_settings3Dviewer;
BOARD* m_dummyBoard;
MODULE* m_copyModule;
MODULE* m_dummyModule;
std::vector<MODULE_3D_SETTINGS>* m_parentInfoList;
int m_currentSelectedIdx; /// Index into m_parentInfoList
std::vector<MODULE_3D_SETTINGS>* m_parentModelList;
int m_selected; /// Index into m_parentInfoList
EDA_UNITS_T m_userUnits;
@ -180,16 +180,16 @@ private:
public:
/**
* @brief SetModelDataIdx - Sets the currently selected index in the infolist so that the
* scale/rotation/offset controls can be updated.
* @brief SetModelDataIdx - Sets the currently selected index in the model list so that
* the scale/rotation/offset controls can be updated.
*/
void SetModelDataIdx( int idx );
void SetSelectedModel( int idx );
/**
* @brief UpdateModelInfoList - copy shapes from the current shape list which are flagged
* for preview to the copy of module that is on the preview dummy board
*/
void UpdateModelInfoList( bool aRelaodRequired = true );
void UpdateDummyModule( bool aRelaodRequired = true );
};
#endif // PANEL_PREV_MODEL_H

View File

@ -384,7 +384,7 @@ void DIALOG_FOOTPRINT_BOARD_EDITOR::select3DModel( int aModelIdx )
if( m_modelsGrid->GetNumberRows() )
m_modelsGrid->SelectRow( aModelIdx );
m_PreviewPane->SetModelDataIdx( aModelIdx );
m_PreviewPane->SetSelectedModel( aModelIdx );
}
@ -428,7 +428,7 @@ void DIALOG_FOOTPRINT_BOARD_EDITOR::On3DModelCellChanged( wxGridEvent& aEvent )
m_shapes3D_list[ aEvent.GetRow() ].m_Preview = previewValue == wxT( "1" );
}
m_PreviewPane->UpdateModelInfoList();
m_PreviewPane->UpdateDummyModule();
}
@ -442,7 +442,7 @@ void DIALOG_FOOTPRINT_BOARD_EDITOR::OnRemove3DModel( wxCommandEvent& )
m_modelsGrid->DeleteRows( idx );
select3DModel( idx ); // will clamp idx within bounds
m_PreviewPane->UpdateModelInfoList();
m_PreviewPane->UpdateDummyModule();
}
}
@ -503,7 +503,7 @@ void DIALOG_FOOTPRINT_BOARD_EDITOR::OnAdd3DModel( wxCommandEvent& )
m_modelsGrid->SetCellValue( idx, 0, filename );
m_modelsGrid->SetCellValue( idx, 1, wxT( "1" ) );
m_PreviewPane->UpdateModelInfoList();
m_PreviewPane->UpdateDummyModule();
}
@ -743,7 +743,7 @@ void DIALOG_FOOTPRINT_BOARD_EDITOR::OnDeleteField( wxCommandEvent& )
void DIALOG_FOOTPRINT_BOARD_EDITOR::Cfg3DPath( wxCommandEvent& )
{
if( S3D::Configure3DPaths( this, Prj().Get3DCacheManager()->GetResolver() ) )
m_PreviewPane->UpdateModelInfoList();
m_PreviewPane->UpdateDummyModule();
}

View File

@ -308,7 +308,7 @@ void DIALOG_FOOTPRINT_FP_EDITOR::select3DModel( int aModelIdx )
if( m_modelsGrid->GetNumberRows() )
m_modelsGrid->SelectRow( aModelIdx );
m_PreviewPane->SetModelDataIdx( aModelIdx );
m_PreviewPane->SetSelectedModel( aModelIdx );
}
@ -352,7 +352,7 @@ void DIALOG_FOOTPRINT_FP_EDITOR::On3DModelCellChanged( wxGridEvent& aEvent )
m_shapes3D_list[ aEvent.GetRow() ].m_Preview = previewValue == wxT( "1" );
}
m_PreviewPane->UpdateModelInfoList();
m_PreviewPane->UpdateDummyModule();
}
@ -366,7 +366,7 @@ void DIALOG_FOOTPRINT_FP_EDITOR::OnRemove3DModel( wxCommandEvent& )
m_modelsGrid->DeleteRows( idx );
select3DModel( idx ); // will clamp idx within bounds
m_PreviewPane->UpdateModelInfoList();
m_PreviewPane->UpdateDummyModule();
}
}
@ -427,7 +427,7 @@ void DIALOG_FOOTPRINT_FP_EDITOR::OnAdd3DModel( wxCommandEvent& )
m_modelsGrid->SetCellValue( idx, 0, filename );
m_modelsGrid->SetCellValue( idx, 1, wxT( "1" ) );
m_PreviewPane->UpdateModelInfoList();
m_PreviewPane->UpdateDummyModule();
}
@ -641,7 +641,7 @@ void DIALOG_FOOTPRINT_FP_EDITOR::OnDeleteField( wxCommandEvent& event )
void DIALOG_FOOTPRINT_FP_EDITOR::Cfg3DPath( wxCommandEvent& event )
{
if( S3D::Configure3DPaths( this, Prj().Get3DCacheManager()->GetResolver() ) )
m_PreviewPane->UpdateModelInfoList();
m_PreviewPane->UpdateDummyModule();
}