From a0597c46148a38fbe387c0bfe560ee646dec16c8 Mon Sep 17 00:00:00 2001 From: Cirilo Bernardo Date: Wed, 9 Dec 2015 16:43:30 +1100 Subject: [PATCH] GUI improvements including interactive update of model orientation/position --- .../3d_cache/dialogs/panel_prev_model.cpp | 198 +++++++++++++----- 3d-viewer/3d_cache/dialogs/panel_prev_model.h | 3 + 3d-viewer/3d_class.cpp | 23 +- .../3d_model_viewer/c3d_model_viewer.cpp | 34 +-- .../3d_render_raytracing/shapes3D/cbbox.cpp | 3 +- cvpcb/cvpcb.cpp | 3 +- .../dialog_edit_module_for_BoardEditor.cpp | 2 + .../dialog_edit_module_for_Modedit.cpp | 4 + pcbnew/pcbnew.cpp | 3 +- 9 files changed, 184 insertions(+), 89 deletions(-) diff --git a/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp b/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp index aaa920a6ce..41a009148a 100644 --- a/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp +++ b/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -63,6 +64,15 @@ static void checkRotation( double& rot ) enum { ID_SET_DIR = wxID_LAST + 1, ID_CFG_PATHS, + ID_SCALEX, + ID_SCALEY, + ID_SCALEZ, + ID_ROTX, + ID_ROTY, + ID_ROTZ, + ID_OFFX, + ID_OFFY, + ID_OFFZ, ID_3D_ISO, ID_3D_UPDATE, ID_3D_LEFT, @@ -76,6 +86,15 @@ enum { wxBEGIN_EVENT_TABLE( PANEL_PREV_3D, wxPanel) EVT_SIZE( PANEL_PREV_3D::resize ) EVT_CHOICE( ID_SET_DIR, PANEL_PREV_3D::SetRootDir ) + EVT_TEXT_ENTER( ID_SCALEX, PANEL_PREV_3D::updateOrientation ) + EVT_TEXT_ENTER( ID_SCALEY, PANEL_PREV_3D::updateOrientation ) + EVT_TEXT_ENTER( ID_SCALEZ, PANEL_PREV_3D::updateOrientation ) + EVT_TEXT_ENTER( ID_ROTX, PANEL_PREV_3D::updateOrientation ) + EVT_TEXT_ENTER( ID_ROTY, PANEL_PREV_3D::updateOrientation ) + EVT_TEXT_ENTER( ID_ROTZ, PANEL_PREV_3D::updateOrientation ) + EVT_TEXT_ENTER( ID_OFFX, PANEL_PREV_3D::updateOrientation ) + EVT_TEXT_ENTER( ID_OFFY, PANEL_PREV_3D::updateOrientation ) + EVT_TEXT_ENTER( ID_OFFZ, PANEL_PREV_3D::updateOrientation ) EVT_BUTTON( ID_CFG_PATHS, PANEL_PREV_3D::Cfg3DPaths ) EVT_BUTTON( ID_3D_ISO, PANEL_PREV_3D::View3DISO ) EVT_BUTTON( ID_3D_UPDATE, PANEL_PREV_3D::View3DUpdate ) @@ -95,6 +114,15 @@ PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent, bool hasFileSelector ) : m_FileDlg = NULL; canvas = NULL; model = NULL; + xscale = NULL; + yscale = NULL; + zscale = NULL; + xrot = NULL; + yrot = NULL; + zrot = NULL; + xoff = NULL; + yoff = NULL; + zoff = NULL; wxBoxSizer* mainBox = new wxBoxSizer( wxVERTICAL ); @@ -120,6 +148,13 @@ PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent, bool hasFileSelector ) : hboxDirChoice->Add( cfgPaths, 0, wxALL, 5 ); } + wxFloatingPointValidator< float > valScale( 6 ); + valScale.SetRange( 0.001, 100 ); + wxFloatingPointValidator< float > valRotate( 6 ); + valRotate.SetRange( -180.0, 180.0 ); + wxFloatingPointValidator< float > valOffset( 6 ); + + wxStaticBoxSizer* vbScale = new wxStaticBoxSizer( wxVERTICAL, this, _( "Scale" ) ); wxStaticBoxSizer* vbRotate = new wxStaticBoxSizer( wxVERTICAL, this, _( "Rotation" ) ); wxStaticBoxSizer* vbOffset = new wxStaticBoxSizer( wxVERTICAL, this, _( "Offset (inches)" ) ); @@ -134,12 +169,12 @@ PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent, bool hasFileSelector ) : wxStaticText* txtS1 = new wxStaticText( modScale, -1, wxT( "X:" ) ); wxStaticText* txtS2 = new wxStaticText( modScale, -1, wxT( "Y:" ) ); wxStaticText* txtS3 = new wxStaticText( modScale, -1, wxT( "Z:" ) ); - xscale = new wxTextCtrl( modScale, -1, "1.0", wxDefaultPosition, wxDefaultSize, - wxTE_PROCESS_ENTER ); - yscale = new wxTextCtrl( modScale, -1, "1.0", wxDefaultPosition, wxDefaultSize, - wxTE_PROCESS_ENTER ); - zscale = new wxTextCtrl( modScale, -1, "1.0", wxDefaultPosition, wxDefaultSize, - wxTE_PROCESS_ENTER ); + xscale = new wxTextCtrl( modScale, ID_SCALEX, "1.0", wxDefaultPosition, wxDefaultSize, + wxTE_PROCESS_ENTER, valScale ); + yscale = new wxTextCtrl( modScale, ID_SCALEY, "1.0", wxDefaultPosition, wxDefaultSize, + wxTE_PROCESS_ENTER, valScale ); + zscale = new wxTextCtrl( modScale, ID_SCALEZ, "1.0", wxDefaultPosition, wxDefaultSize, + wxTE_PROCESS_ENTER, valScale ); xscale->SetMaxLength( 9 ); yscale->SetMaxLength( 9 ); zscale->SetMaxLength( 9 ); @@ -156,15 +191,15 @@ PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent, bool hasFileSelector ) : wxBoxSizer* hbR1 = new wxBoxSizer( wxHORIZONTAL ); wxBoxSizer* hbR2 = new wxBoxSizer( wxHORIZONTAL ); wxBoxSizer* hbR3 = new wxBoxSizer( wxHORIZONTAL ); - wxStaticText* txtR1 = new wxStaticText( modRotate, -1, wxT( "X:" ) ); - wxStaticText* txtR2 = new wxStaticText( modRotate, -1, wxT( "Y:" ) ); - wxStaticText* txtR3 = new wxStaticText( modRotate, -1, wxT( "Z:" ) ); - xrot = new wxTextCtrl( modRotate, -1, "0.0", wxDefaultPosition, wxDefaultSize, - wxTE_PROCESS_ENTER ); - yrot = new wxTextCtrl( modRotate, -1, "0.0", wxDefaultPosition, wxDefaultSize, - wxTE_PROCESS_ENTER ); - zrot = new wxTextCtrl( modRotate, -1, "0.0", wxDefaultPosition, wxDefaultSize, - wxTE_PROCESS_ENTER ); + wxStaticText* txtR1 = new wxStaticText( modRotate, ID_ROTX, wxT( "X:" ) ); + wxStaticText* txtR2 = new wxStaticText( modRotate, ID_ROTY, wxT( "Y:" ) ); + wxStaticText* txtR3 = new wxStaticText( modRotate, ID_ROTZ, wxT( "Z:" ) ); + xrot = new wxTextCtrl( modRotate, ID_ROTX, "0.0", wxDefaultPosition, wxDefaultSize, + wxTE_PROCESS_ENTER, valRotate ); + yrot = new wxTextCtrl( modRotate, ID_ROTY, "0.0", wxDefaultPosition, wxDefaultSize, + wxTE_PROCESS_ENTER, valRotate ); + zrot = new wxTextCtrl( modRotate, ID_ROTZ, "0.0", wxDefaultPosition, wxDefaultSize, + wxTE_PROCESS_ENTER, valRotate ); xrot->SetMaxLength( 9 ); yrot->SetMaxLength( 9 ); zrot->SetMaxLength( 9 ); @@ -184,12 +219,12 @@ PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent, bool hasFileSelector ) : wxStaticText* txtO1 = new wxStaticText( modOffset, -1, wxT( "X:" ) ); wxStaticText* txtO2 = new wxStaticText( modOffset, -1, wxT( "Y:" ) ); wxStaticText* txtO3 = new wxStaticText( modOffset, -1, wxT( "Z:" ) ); - xoff = new wxTextCtrl( modOffset, -1, "0.0", wxDefaultPosition, wxDefaultSize, - wxTE_PROCESS_ENTER ); - yoff = new wxTextCtrl( modOffset, -1, "0.0", wxDefaultPosition, wxDefaultSize, - wxTE_PROCESS_ENTER ); - zoff = new wxTextCtrl( modOffset, -1, "0.0", wxDefaultPosition, wxDefaultSize, - wxTE_PROCESS_ENTER ); + xoff = new wxTextCtrl( modOffset, ID_OFFX, "0.0", wxDefaultPosition, wxDefaultSize, + wxTE_PROCESS_ENTER, valOffset ); + yoff = new wxTextCtrl( modOffset, ID_OFFY, "0.0", wxDefaultPosition, wxDefaultSize, + wxTE_PROCESS_ENTER, valOffset ); + zoff = new wxTextCtrl( modOffset, ID_OFFZ, "0.0", wxDefaultPosition, wxDefaultSize, + wxTE_PROCESS_ENTER, valOffset ); xoff->SetMaxLength( 9 ); yoff->SetMaxLength( 9 ); zoff->SetMaxLength( 9 ); @@ -443,29 +478,7 @@ void PANEL_PREV_3D::GetModelData( S3D_INFO* aModel ) SGPOINT rotation; SGPOINT offset; - xscale->GetValue().ToDouble( &scale.x ); - yscale->GetValue().ToDouble( &scale.y ); - zscale->GetValue().ToDouble( &scale.z ); - - if( 0.001 > scale.x || 0.001 > scale.y || 0.001 > scale.z ) - { - std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; - std::cerr << " * [INFO] invalid scale values; setting all to 1.0\n"; - scale.x = 1.0; - scale.y = 1.0; - scale.z = 1.0; - } - - xrot->GetValue().ToDouble( &rotation.x ); - yrot->GetValue().ToDouble( &rotation.y ); - zrot->GetValue().ToDouble( &rotation.z ); - checkRotation( rotation.x ); - checkRotation( rotation.y ); - checkRotation( rotation.z ); - - xoff->GetValue().ToDouble( &offset.x ); - yoff->GetValue().ToDouble( &offset.y ); - zoff->GetValue().ToDouble( &offset.z ); + getOrientationVars( scale, rotation, offset ); aModel->scale = scale; aModel->offset = offset; @@ -487,17 +500,17 @@ void PANEL_PREV_3D::GetModelData( S3D_INFO* aModel ) void PANEL_PREV_3D::SetModelData( S3D_INFO const* aModel ) { - xscale->SetValue( wxString::FromDouble( aModel->scale.x ) ); - yscale->SetValue( wxString::FromDouble( aModel->scale.y ) ); - zscale->SetValue( wxString::FromDouble( aModel->scale.z ) ); + xscale->ChangeValue( wxString::FromDouble( aModel->scale.x ) ); + yscale->ChangeValue( wxString::FromDouble( aModel->scale.y ) ); + zscale->ChangeValue( wxString::FromDouble( aModel->scale.z ) ); - xrot->SetValue( wxString::FromDouble( aModel->rotation.x ) ); - yrot->SetValue( wxString::FromDouble( aModel->rotation.y ) ); - zrot->SetValue( wxString::FromDouble( aModel->rotation.z ) ); + xrot->ChangeValue( wxString::FromDouble( aModel->rotation.x ) ); + yrot->ChangeValue( wxString::FromDouble( aModel->rotation.y ) ); + zrot->ChangeValue( wxString::FromDouble( aModel->rotation.z ) ); - xoff->SetValue( wxString::FromDouble( aModel->offset.x ) ); - yoff->SetValue( wxString::FromDouble( aModel->offset.y ) ); - zoff->SetValue( wxString::FromDouble( aModel->offset.z ) ); + xoff->ChangeValue( wxString::FromDouble( aModel->offset.x ) ); + yoff->ChangeValue( wxString::FromDouble( aModel->offset.y ) ); + zoff->ChangeValue( wxString::FromDouble( aModel->offset.z ) ); modelInfo = *aModel; UpdateModelName( aModel->filename ); @@ -556,7 +569,11 @@ void PANEL_PREV_3D::UpdateModelName( wxString const& aModelName ) std::cout << "[3dv] Update Model: painting black\n"; #endif if( NULL != canvas ) + { canvas->Clear3DModel(); + canvas->Refresh(); + canvas->Update(); + } if( model ) S3D::Destroy3DModel( &model ); @@ -644,3 +661,78 @@ void PANEL_PREV_3D::resize( wxSizeEvent &event ) return; } + + +void PANEL_PREV_3D::updateOrientation( wxCommandEvent &event ) +{ + // note: process even if the canvas is NULL since the user may + // edit the filename to provide a valid file + SGPOINT scale; + SGPOINT rotation; + SGPOINT offset; + + getOrientationVars( scale, rotation, offset ); + + modelInfo.scale = scale; + modelInfo.offset = offset; + modelInfo.rotation = rotation; + + if( NULL == canvas ) + return; + + canvas->Clear3DModel(); + + if( model ) + S3D::Destroy3DModel( &model ); + + SGPOINT rot; + SGPOINT trans; + + model = m_ModelManager->Prepare( &modelInfo, rot, trans ); + + if( model ) + { + canvas->Set3DModel( *model ); + canvas->Refresh(); + canvas->Update(); + } + + return; +} + + +void PANEL_PREV_3D::getOrientationVars( SGPOINT& scale, SGPOINT& rotation, SGPOINT& offset ) +{ + if( NULL == xscale || NULL == yscale || NULL == zscale + || NULL == xrot || NULL == yrot || NULL == zrot + || NULL == xoff || NULL == yoff || NULL == zoff ) + { + return; + } + + xscale->GetValue().ToDouble( &scale.x ); + yscale->GetValue().ToDouble( &scale.y ); + zscale->GetValue().ToDouble( &scale.z ); + + if( 0.001 > scale.x || 0.001 > scale.y || 0.001 > scale.z ) + { + std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; + std::cerr << " * [INFO] invalid scale values; setting all to 1.0\n"; + scale.x = 1.0; + scale.y = 1.0; + scale.z = 1.0; + } + + xrot->GetValue().ToDouble( &rotation.x ); + yrot->GetValue().ToDouble( &rotation.y ); + zrot->GetValue().ToDouble( &rotation.z ); + checkRotation( rotation.x ); + checkRotation( rotation.y ); + checkRotation( rotation.z ); + + xoff->GetValue().ToDouble( &offset.x ); + yoff->GetValue().ToDouble( &offset.y ); + zoff->GetValue().ToDouble( &offset.z ); + + return; +} diff --git a/3d-viewer/3d_cache/dialogs/panel_prev_model.h b/3d-viewer/3d_cache/dialogs/panel_prev_model.h index e429596eab..371e52b0df 100644 --- a/3d-viewer/3d_cache/dialogs/panel_prev_model.h +++ b/3d-viewer/3d_cache/dialogs/panel_prev_model.h @@ -91,6 +91,9 @@ private: private: void updateDirChoiceList( void ); void resize( wxSizeEvent &event ); + void updateOrientation( wxCommandEvent &event ); + + void getOrientationVars( SGPOINT& scale, SGPOINT& rotation, SGPOINT& offset ); wxDECLARE_EVENT_TABLE(); }; diff --git a/3d-viewer/3d_class.cpp b/3d-viewer/3d_class.cpp index b8728d9a56..452e512cfc 100644 --- a/3d-viewer/3d_class.cpp +++ b/3d-viewer/3d_class.cpp @@ -30,6 +30,11 @@ #include "3d_viewer.h" #include "3d_struct.h" #include "modelparsers.h" +#include +#include <3d_cache.h> +#include <3d_filename_resolver.h> + +extern KIWAY* TheKiway; void S3D_MASTER::Insert( S3D_MATERIAL* aMaterial ) @@ -136,22 +141,8 @@ void S3D_MASTER::SetShape3DName( const wxString& aShapeName ) else m_Shape3DFullFilename = m_Shape3DName; - wxFileName fnFull( m_Shape3DFullFilename ); - - if( !( fnFull.IsAbsolute() || m_Shape3DFullFilename.StartsWith( wxT(".") ) ) ) - { - wxString default_path; - wxGetEnv( KISYS3DMOD, &default_path ); - - if( !( default_path.IsEmpty() ) ) - { - - if( !default_path.EndsWith( wxT("/") ) && !default_path.EndsWith( wxT("\\") ) ) - default_path += wxT("/"); - - m_Shape3DFullFilename = default_path + m_Shape3DFullFilename; - } - } + m_Shape3DFullFilename = TheKiway->Prj().Get3DCacheManager()->GetResolver() + ->ResolvePath( m_Shape3DFullFilename ); return; } diff --git a/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp b/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp index 2899c0dc70..871f9c32bb 100644 --- a/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp +++ b/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp @@ -247,26 +247,26 @@ void C3D_MODEL_VIEWER::OnPaint( wxPaintEvent &event ) glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); - ogl_set_arrow_material(); - - glColor3f( 0.9f, 0.0f, 0.0f ); - OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), - SFVEC3F( RANGE_SCALE_3D / 1.0f, 0.0f, 0.0f ), - 0.2f ); - - glColor3f( 0.0f, 0.9f, 0.0f ); - OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), - SFVEC3F( 0.0f, RANGE_SCALE_3D / 1.0f, 0.0f ), - 0.2f ); - - glColor3f( 0.0f, 0.0f, 0.9f ); - OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), - SFVEC3F( 0.0f, 0.0f, RANGE_SCALE_3D / 1.0f ), - 0.2f ); - // Render Model if( m_ogl_3dmodel ) { + ogl_set_arrow_material(); + + glColor3f( 0.9f, 0.0f, 0.0f ); + OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), + SFVEC3F( RANGE_SCALE_3D / 1.0f, 0.0f, 0.0f ), + 0.2f ); + + glColor3f( 0.0f, 0.9f, 0.0f ); + OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), + SFVEC3F( 0.0f, RANGE_SCALE_3D / 1.0f, 0.0f ), + 0.2f ); + + glColor3f( 0.0f, 0.0f, 0.9f ); + OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), + SFVEC3F( 0.0f, 0.0f, RANGE_SCALE_3D / 1.0f ), + 0.2f ); + glPushMatrix(); double modelunit_to_3d_units_factor = m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB; diff --git a/3d-viewer/3d_rendering/3d_render_raytracing/shapes3D/cbbox.cpp b/3d-viewer/3d_rendering/3d_render_raytracing/shapes3D/cbbox.cpp index f771e95c94..00ba7debad 100644 --- a/3d-viewer/3d_rendering/3d_render_raytracing/shapes3D/cbbox.cpp +++ b/3d-viewer/3d_rendering/3d_render_raytracing/shapes3D/cbbox.cpp @@ -348,7 +348,8 @@ void CBBOX::ApplyTransformation( glm::mat4 aTransformMatrix ) void CBBOX::ApplyTransformationAA( glm::mat4 aTransformMatrix ) { - wxASSERT( IsInitialized() ); + // XXX - CB - commented out because it spams the legacy renderer + // wxASSERT( IsInitialized() ); // apply the transformation matrix for each of vertices of the bounding box // and make a union with all vertices diff --git a/cvpcb/cvpcb.cpp b/cvpcb/cvpcb.cpp index 4680410fef..dc3d9c42ac 100644 --- a/cvpcb/cvpcb.cpp +++ b/cvpcb/cvpcb.cpp @@ -34,7 +34,6 @@ #include #include #include -#include <3d_viewer.h> #include #include @@ -56,6 +55,7 @@ const wxString EquFileExtension( wxT( "equ" ) ); // Wildcard for schematic retroannotation (import footprint names in schematic): const wxString EquFilesWildcard( _( "Component/footprint equ files (*.equ)|*.equ" ) ); +KIWAY* TheKiway = NULL; namespace CV { @@ -78,6 +78,7 @@ static struct IFACE : public KIFACE_I case FRAME_CVPCB: { CVPCB_MAINFRAME* frame = new CVPCB_MAINFRAME( aKiway, aParent ); + TheKiway = aKiway; return frame; } break; diff --git a/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp b/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp index eaa1ca775a..79aecee122 100644 --- a/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp +++ b/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp @@ -483,6 +483,8 @@ void DIALOG_MODULE_BOARD_EDITOR::Edit3DShapeFileName() delete m_Shapes3D_list[idx]; m_Shapes3D_list[idx] = new3DShape; + Transfert3DValuesToDisplay( m_Shapes3D_list[idx] ); + return; } diff --git a/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp b/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp index 5075fae14e..b430935bfa 100644 --- a/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp +++ b/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp @@ -349,6 +349,10 @@ void DIALOG_MODULE_MODULE_EDITOR::Edit3DShapeFileName() new3DShape->SetShape3DName( filename ); delete m_shapes3D_list[idx]; m_shapes3D_list[idx] = new3DShape; + + Transfert3DValuesToDisplay( m_shapes3D_list[idx] ); + + return; } diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index 0abbd00038..11a271ea13 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -53,7 +53,6 @@ #include #include #include -#include <3d_viewer.h> #include #include #include @@ -95,6 +94,7 @@ wxString g_DocModulesFileName = wxT( "footprints_doc/footprints.pdf" ); DLIST g_CurrentTrackList; bool g_DumpZonesWhenFilling = false; +KIWAY* TheKiway = NULL; namespace PCB { @@ -118,6 +118,7 @@ static struct IFACE : public KIFACE_I { case FRAME_PCB: frame = dynamic_cast< wxWindow* >( new PCB_EDIT_FRAME( aKiway, aParent ) ); + TheKiway = aKiway; #if defined( KICAD_SCRIPTING ) // give the scripting helpers access to our frame