mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-19 23:31:40 +00:00
Reduce dependency on dynamic_cast.
(3DViewer crosses compile boundaries when run from CvPCB.)
This commit is contained in:
parent
9b4c1024c9
commit
7a4b3602b9
3d-viewer
3d_canvas
3d_rendering/opengl
3d_viewer
dialogs
common/gal
@ -526,13 +526,4 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class EDA_3D_BOARD_HOLDER
|
||||
{
|
||||
public:
|
||||
virtual BOARD_ADAPTER& GetAdapter() = 0;
|
||||
virtual CAMERA& GetCurrentCamera() = 0;
|
||||
|
||||
virtual ~EDA_3D_BOARD_HOLDER() {};
|
||||
};
|
||||
|
||||
#endif // BOARD_ADAPTER_H
|
||||
|
@ -91,7 +91,7 @@ EDA_3D_CANVAS::EDA_3D_CANVAS( wxWindow* aParent, const wxGLAttributes& aGLAttrib
|
||||
BOARD_ADAPTER& aBoardAdapter, CAMERA& aCamera,
|
||||
S3D_CACHE* a3DCachePointer ) :
|
||||
HIDPI_GL_3D_CANVAS( EDA_DRAW_PANEL_GAL::GetVcSettings(), aCamera, aParent, aGLAttribs,
|
||||
wxID_ANY, wxDefaultPosition,
|
||||
EDA_3D_CANVAS_ID, wxDefaultPosition,
|
||||
wxDefaultSize, wxFULL_REPAINT_ON_RESIZE ),
|
||||
m_eventDispatcher( nullptr ),
|
||||
m_parentStatusBar( nullptr ),
|
||||
|
@ -42,6 +42,8 @@ class RENDER_3D_RAYTRACE_GL;
|
||||
class RENDER_3D_OPENGL;
|
||||
|
||||
|
||||
static wxWindowID EDA_3D_CANVAS_ID = wxID_HIGHEST + 1321;
|
||||
|
||||
/**
|
||||
* Implement a canvas based on a wxGLCanvas
|
||||
*/
|
||||
|
@ -898,9 +898,7 @@ void RENDER_3D_OPENGL::Load3dModelsIfNeeded()
|
||||
if( m_3dModelMap.size() > 0 )
|
||||
return;
|
||||
|
||||
wxFrame* frame = dynamic_cast<EDA_3D_VIEWER_FRAME*>( m_canvas->GetParent() );
|
||||
|
||||
if( frame )
|
||||
if( wxFrame* frame = dynamic_cast<wxFrame*>( m_canvas->GetParent() ) )
|
||||
{
|
||||
STATUSBAR_REPORTER activityReporter( frame->GetStatusBar(),
|
||||
(int) EDA_3D_VIEWER_STATUSBAR::ACTIVITY );
|
||||
|
@ -60,7 +60,7 @@ enum EDA_3D_VIEWER_STATUSBAR
|
||||
/**
|
||||
* Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard
|
||||
*/
|
||||
class EDA_3D_VIEWER_FRAME : public EDA_3D_BOARD_HOLDER, public KIWAY_PLAYER
|
||||
class EDA_3D_VIEWER_FRAME : public KIWAY_PLAYER
|
||||
{
|
||||
public:
|
||||
EDA_3D_VIEWER_FRAME( KIWAY* aKiway, PCB_BASE_FRAME* aParent, const wxString& aTitle,
|
||||
@ -100,8 +100,8 @@ public:
|
||||
|
||||
void Redraw();
|
||||
|
||||
BOARD_ADAPTER& GetAdapter() override { return m_boardAdapter; }
|
||||
CAMERA& GetCurrentCamera() override { return m_currentCamera; }
|
||||
BOARD_ADAPTER& GetAdapter() { return m_boardAdapter; }
|
||||
CAMERA& GetCurrentCamera() { return m_currentCamera; }
|
||||
|
||||
EDA_3D_CANVAS* GetCanvas() { return m_canvas; }
|
||||
|
||||
|
@ -69,27 +69,30 @@ bool EDA_3D_CONTROLLER::Init()
|
||||
|
||||
void EDA_3D_CONTROLLER::Reset( RESET_REASON aReason )
|
||||
{
|
||||
TOOLS_HOLDER* holder = m_toolMgr->GetToolHolder();
|
||||
|
||||
wxASSERT( holder );
|
||||
|
||||
m_canvas = nullptr;
|
||||
m_boardAdapter = nullptr;
|
||||
m_camera = nullptr;
|
||||
|
||||
if( holder )
|
||||
TOOLS_HOLDER* holder = m_toolMgr->GetToolHolder();
|
||||
|
||||
wxCHECK( holder, /* void */ );
|
||||
wxCHECK( holder->GetToolCanvas()->GetId() == EDA_3D_CANVAS_ID, /* void */ );
|
||||
|
||||
m_canvas = static_cast<EDA_3D_CANVAS*>( holder->GetToolCanvas() );
|
||||
|
||||
if( EDA_BASE_FRAME* frame = dynamic_cast<EDA_BASE_FRAME*>( holder ) )
|
||||
{
|
||||
m_canvas = dynamic_cast<EDA_3D_CANVAS*>( holder->GetToolCanvas() );
|
||||
wxCHECK( frame->GetFrameType() == FRAME_PCB_DISPLAY3D, /* void */ );
|
||||
|
||||
EDA_3D_BOARD_HOLDER* holder3d = dynamic_cast<EDA_3D_BOARD_HOLDER*>( holder );
|
||||
m_boardAdapter = &static_cast<EDA_3D_VIEWER_FRAME*>( frame )->GetAdapter();
|
||||
m_camera = &static_cast<EDA_3D_VIEWER_FRAME*>( frame )->GetCurrentCamera();
|
||||
}
|
||||
else if( wxWindow* previewWindow = dynamic_cast<wxWindow*>( holder ) )
|
||||
{
|
||||
wxCHECK( previewWindow->GetId() == PANEL_PREVIEW_3D_MODEL_ID, /* void */ );
|
||||
|
||||
wxASSERT( holder3d );
|
||||
|
||||
if( holder3d )
|
||||
{
|
||||
m_boardAdapter = &holder3d->GetAdapter();
|
||||
m_camera = &holder3d->GetCurrentCamera();
|
||||
}
|
||||
m_boardAdapter = &static_cast<PANEL_PREVIEW_3D_MODEL*>( holder )->GetAdapter();
|
||||
m_camera = &static_cast<PANEL_PREVIEW_3D_MODEL*>( holder )->GetCurrentCamera();
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,10 +120,13 @@ int EDA_3D_CONTROLLER::Main( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
if( evt->IsCancelInteractive() )
|
||||
{
|
||||
wxWindow* canvas = m_toolMgr->GetToolHolder()->GetToolCanvas();
|
||||
wxWindow* canvas = m_toolMgr->GetToolHolder()->GetToolCanvas();
|
||||
KIWAY_HOLDER* parent = dynamic_cast<KIWAY_HOLDER*>( wxGetTopLevelParent( canvas ) );
|
||||
|
||||
if( DIALOG_SHIM* dialog = dynamic_cast<DIALOG_SHIM*>( wxGetTopLevelParent( canvas ) ) )
|
||||
if( parent && parent->GetType() == KIWAY_HOLDER::DIALOG )
|
||||
{
|
||||
DIALOG_SHIM* dialog = static_cast<DIALOG_SHIM*>( parent );
|
||||
|
||||
if( dialog->IsQuasiModal() )
|
||||
dialog->EndQuasiModal( wxID_CANCEL );
|
||||
else
|
||||
@ -197,8 +203,10 @@ int EDA_3D_CONTROLLER::SetMaterial( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
m_boardAdapter->m_Cfg->m_Render.material_mode = aEvent.Parameter<MATERIAL_MODE>();
|
||||
|
||||
if( auto* viewer = dynamic_cast<EDA_3D_VIEWER_FRAME*>( m_toolMgr->GetToolHolder() ) )
|
||||
viewer->NewDisplay( true );
|
||||
EDA_BASE_FRAME* frame = dynamic_cast<EDA_BASE_FRAME*>( m_toolMgr->GetToolHolder() );
|
||||
|
||||
if( frame && frame->GetFrameType() == FRAME_PCB_DISPLAY3D )
|
||||
static_cast<EDA_3D_VIEWER_FRAME*>( frame )->NewDisplay( true );
|
||||
else
|
||||
m_canvas->Request_refresh();
|
||||
|
||||
@ -229,8 +237,10 @@ int EDA_3D_CONTROLLER::ToggleVisibility( const TOOL_EVENT& aEvent )
|
||||
appearanceManager->OnLayerVisibilityChanged( layer, !visibilityFlags.test( layer ) );
|
||||
};
|
||||
|
||||
if( auto viewer = dynamic_cast<EDA_3D_VIEWER_FRAME*>( m_toolMgr->GetToolHolder() ) )
|
||||
appearanceManager = viewer->GetAppearanceManager();
|
||||
EDA_BASE_FRAME* frame = dynamic_cast<EDA_BASE_FRAME*>( m_toolMgr->GetToolHolder() );
|
||||
|
||||
if( frame && frame->GetFrameType() == FRAME_PCB_DISPLAY3D )
|
||||
appearanceManager = static_cast<EDA_3D_VIEWER_FRAME*>( frame )->GetAppearanceManager();
|
||||
|
||||
if( appearanceManager )
|
||||
{
|
||||
@ -256,8 +266,10 @@ int EDA_3D_CONTROLLER::ToggleVisibility( const TOOL_EVENT& aEvent )
|
||||
|
||||
int EDA_3D_CONTROLLER::ToggleLayersManager( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
if( auto* viewer = dynamic_cast<EDA_3D_VIEWER_FRAME*>( m_toolMgr->GetToolHolder() ) )
|
||||
viewer->ToggleAppearanceManager();
|
||||
EDA_BASE_FRAME* frame = dynamic_cast<EDA_BASE_FRAME*>( m_toolMgr->GetToolHolder() );
|
||||
|
||||
if( frame && frame->GetFrameType() == FRAME_PCB_DISPLAY3D )
|
||||
static_cast<EDA_3D_VIEWER_FRAME*>( frame )->ToggleAppearanceManager();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@
|
||||
PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL( wxWindow* aParent, PCB_BASE_FRAME* aFrame,
|
||||
FOOTPRINT* aFootprint,
|
||||
std::vector<FP_3DMODEL>* aParentModelList ) :
|
||||
PANEL_PREVIEW_3D_MODEL_BASE( aParent, wxID_ANY ),
|
||||
PANEL_PREVIEW_3D_MODEL_BASE( aParent, PANEL_PREVIEW_3D_MODEL_ID ),
|
||||
m_parentFrame( aFrame ),
|
||||
m_previewPane( nullptr ),
|
||||
m_infobar( nullptr ),
|
||||
@ -652,6 +652,8 @@ void PANEL_PREVIEW_3D_MODEL::UpdateDummyFootprint( bool aReloadRequired )
|
||||
|
||||
void PANEL_PREVIEW_3D_MODEL::onModify()
|
||||
{
|
||||
if( DIALOG_SHIM* dlg = dynamic_cast<DIALOG_SHIM*>( wxGetTopLevelParent( this ) ) )
|
||||
dlg->OnModify();
|
||||
KIWAY_HOLDER* kiwayHolder = dynamic_cast<KIWAY_HOLDER*>( wxGetTopLevelParent( this ) );
|
||||
|
||||
if( kiwayHolder && kiwayHolder->GetType() == KIWAY_HOLDER::DIALOG )
|
||||
static_cast<DIALOG_SHIM*>( kiwayHolder )->OnModify();
|
||||
}
|
@ -64,7 +64,9 @@ class BOARD_ADAPTER;
|
||||
class FOOTPRINT;
|
||||
class NL_FOOTPRINT_PROPERTIES_PLUGIN;
|
||||
|
||||
class PANEL_PREVIEW_3D_MODEL: public EDA_3D_BOARD_HOLDER, public TOOLS_HOLDER, public PANEL_PREVIEW_3D_MODEL_BASE
|
||||
static wxWindowID PANEL_PREVIEW_3D_MODEL_ID = wxID_HIGHEST + 1244;
|
||||
|
||||
class PANEL_PREVIEW_3D_MODEL: public TOOLS_HOLDER, public PANEL_PREVIEW_3D_MODEL_BASE
|
||||
{
|
||||
public:
|
||||
PANEL_PREVIEW_3D_MODEL( wxWindow* aParent, PCB_BASE_FRAME* aFrame, FOOTPRINT* aFootprint,
|
||||
@ -80,8 +82,8 @@ public:
|
||||
|
||||
wxWindow* GetToolCanvas() const override { return m_previewPane; }
|
||||
|
||||
BOARD_ADAPTER& GetAdapter() override { return m_boardAdapter; }
|
||||
CAMERA& GetCurrentCamera() override { return m_currentCamera; }
|
||||
BOARD_ADAPTER& GetAdapter() { return m_boardAdapter; }
|
||||
CAMERA& GetCurrentCamera() { return m_currentCamera; }
|
||||
|
||||
/**
|
||||
* Set the currently selected index in the model list so that the scale/rotation/offset
|
||||
|
@ -29,10 +29,10 @@ const float HIDPI_GL_3D_CANVAS::m_delta_move_step_factor = 0.7f;
|
||||
|
||||
HIDPI_GL_3D_CANVAS::HIDPI_GL_3D_CANVAS( const KIGFX::VC_SETTINGS& aVcSettings, CAMERA& aCamera,
|
||||
wxWindow* aParent, const wxGLAttributes& aGLAttribs,
|
||||
wxWindowID, const wxPoint& aPos,
|
||||
wxWindowID aId, const wxPoint& aPos,
|
||||
const wxSize& aSize, long aStyle, const wxString& aName,
|
||||
const wxPalette& aPalette ) :
|
||||
HIDPI_GL_CANVAS( aVcSettings, aParent, aGLAttribs, wxID_ANY, aPos, aSize, aStyle, aName, aPalette ),
|
||||
HIDPI_GL_CANVAS( aVcSettings, aParent, aGLAttribs, aId, aPos, aSize, aStyle, aName, aPalette ),
|
||||
m_mouse_is_moving( false ),
|
||||
m_mouse_was_moved( false ),
|
||||
m_camera_is_moving( false ),
|
||||
|
Loading…
Reference in New Issue
Block a user