25#include <wx/filename.h>
28#include <wx/wupdlock.h>
29#include <wx/clipbrd.h>
30#include <wx/filedlg.h>
35#include "wx/generic/textdlgg.h"
89 const wxString& aTitle,
long style ) :
92 m_mainToolBar(
nullptr ), m_canvas(
nullptr ), m_currentCamera( m_trackBallCamera ),
93 m_viewportsLabel(
nullptr ),
94 m_cbViewports(
nullptr ),
97 wxLogTrace( m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::EDA_3D_VIEWER_FRAME %s" ), aTitle );
99 m_disable_ray_tracing =
false;
100 m_aboutTitle =
_HKI(
"KiCad 3D Viewer" );
108 static const int status_dims[4] = { -1, 170, 130, 130 };
110 wxStatusBar *status_bar = CreateStatusBar(
arrayDim( status_dims ) );
111 SetStatusWidths(
arrayDim( status_dims ), status_dims );
118 m_boardAdapter, m_currentCamera,
Prj().Get3DCacheManager() );
121 loadCommonSettings();
123 SetUserViewports(
Prj().GetProjectFile().m_Viewports3D );
131 m_canvas->SetEventDispatcher( m_toolDispatcher );
136 m_toolManager->InitTools();
140 if(
EDA_3D_CONTROLLER* ctrlTool = GetToolManager()->GetTool<EDA_3D_CONTROLLER>() )
144 m_toolManager->InvokeTool(
"3DViewer.Control" );
147 ReCreateMainToolbar();
149 m_infoBar =
new WX_INFOBAR(
this, &m_auimgr );
151 m_auimgr.SetManagedWindow(
this );
153 m_auimgr.AddPane( m_mainToolBar,
EDA_PANE().HToolbar().Name( wxS(
"MainToolbar" ) ).Top().Layer( 6 ) );
154 m_auimgr.AddPane( m_infoBar,
EDA_PANE().InfoBar().Name( wxS(
"InfoBar" ) ).Top().Layer( 1 ) );
155 m_auimgr.AddPane( m_canvas,
EDA_PANE().Canvas().Name( wxS(
"DrawFrame" ) ).Center() );
162 m_auimgr.GetPane( wxS(
"InfoBar" ) ).Hide();
165 m_canvas->SetInfoBar( m_infoBar );
166 m_canvas->SetStatusBar( status_bar );
175 catch(
const std::system_error& e )
177 wxLogTrace( wxT(
"KI_TRACE_NAVLIB" ), e.what() );
184 m_canvas->SetFocus();
186 m_cbViewports->Connect( wxEVT_COMMAND_CHOICE_SELECTED,
189 m_cbViewports->Connect( wxEVT_UPDATE_UI,
222#define GridSizeCheck( x ) ACTION_CONDITIONS().Check( cond.GridSize( x ) )
244 auto show_NotInPosfile =
295 static bool s_viewportSwitcherShown =
false;
302 if( wxGetKeyState( WXK_TAB ) )
304 if( ( aEvent.GetEventType() == wxEVT_CHAR || aEvent.GetEventType() == wxEVT_CHAR_HOOK )
305 &&
static_cast<wxKeyEvent&
>( aEvent ).GetKeyCode() == WXK_TAB )
310 if( this->IsActive() )
316 s_viewportSwitcherShown =
true;
317 switcher.ShowModal();
318 s_viewportSwitcherShown =
false;
331 return wxFrame::TryBefore( aEvent );
361 if( aForceImmediateRedraw )
385 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::Exit3DFrame" ) );
393 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::OnCloseWindow" ) );
405 int id =
event.GetId();
406 bool isChecked =
event.IsChecked();
408 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::Process_Special_Functions id %d "
442 wxFAIL_MSG( wxT(
"Invalid event in EDA_3D_VIEWER_FRAME::Process_Special_Functions()" ) );
450 std::vector<VIEWPORT3D> ret;
452 for(
const std::pair<const wxString, VIEWPORT3D>& pair :
m_viewports )
453 ret.emplace_back( pair.second );
463 for(
const VIEWPORT3D& viewport : aViewportList )
479 if( idx >= 0 && idx < m_cbViewports->GetCount() - 3 )
510 if( index >= 0 && index < count - 3 )
514 wxCHECK( viewport, );
518 else if( index == count - 2 )
523 wxTextEntryDialog dlg(
this,
_(
"Viewport name:" ),
_(
"Save Viewport" ),
name );
525 if( dlg.ShowModal() != wxID_OK )
535 name = dlg.GetValue();
556 else if( index == count - 1 )
559 wxArrayString headers;
560 std::vector<wxArrayString> items;
562 headers.Add(
_(
"Viewports" ) );
564 for( std::pair<const wxString, VIEWPORT3D>& pair :
m_viewports )
567 item.Add( pair.first );
568 items.emplace_back( item );
574 if( dlg.ShowModal() == wxID_OK )
579 if( idx != wxNOT_FOUND )
604 if( index >= 0 && index < count - 3 )
608 wxCHECK( viewport, );
621 if( old_engine == RENDER_ENGINE::OPENGL )
622 engine = RENDER_ENGINE::RAYTRACING;
624 engine = RENDER_ENGINE::OPENGL;
626 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::OnRenderEngineSelection type %s " ),
627 engine == RENDER_ENGINE::RAYTRACING ? wxT(
"raytracing" ) : wxT(
"realtime" ) );
629 if( old_engine != engine )
636 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::%s disabling ray tracing." ),
646 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::OnActivate" ) );
648 if( aEvent.GetActive() &&
m_canvas )
690 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::LoadSettings" ) );
714 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::SaveSettings" ) );
717 wxT(
"EDA_3D_VIEWER_FRAME::SaveSettings render setting Ray Trace" )
719 wxT(
"EDA_3D_VIEWER_FRAME::SaveSettings render setting OpenGL" ) );
728 cfg->m_Camera.rotation_increment = ctrlTool->GetRotationIncrement();
735 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::CommonSettingsChanged" ) );
752 wxString fullFileName;
753 bool fmt_is_jpeg =
false;
770 wxFileDialog dlg(
this,
_(
"3D Image File Name" ),
773 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
775 if( dlg.ShowModal() == wxID_CANCEL )
785 wxFileName fn = fullFileName;
787 if( !fn.IsDirWritable() )
791 msg.Printf(
_(
"Insufficient permissions to save file '%s'." ), fullFileName );
792 wxMessageBox( msg,
_(
"Error" ), wxOK | wxICON_ERROR,
this );
807 wxWindowUpdateLocker noUpdates(
this );
809 wxImage screenshotImage;
816 wxBitmap bitmap( screenshotImage );
820 if( wxTheClipboard->Open() )
822 wxBitmapDataObject* dobjBmp =
new wxBitmapDataObject( bitmap );
824 if( !wxTheClipboard->SetData( dobjBmp ) )
825 wxMessageBox(
_(
"Failed to copy image to clipboard" ) );
827 wxTheClipboard->Flush();
829 wxTheClipboard->Close();
834 if( !screenshotImage.SaveFile( fullFileName,
835 fmt_is_jpeg ? wxBITMAP_TYPE_JPEG : wxBITMAP_TYPE_PNG ) )
836 wxMessageBox(
_(
"Can't save file" ) );
838 screenshotImage.Destroy();
845 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::RenderEngineChanged()" ) );
854 wxCHECK_RET(
m_canvas, wxT(
"Cannot load settings to null canvas" ) );
RENDER_ENGINE
Render engine mode.
@ ID_TOOL_SCREENCOPY_TOCLIBBOARD
@ ID_MENU3D_RESET_DEFAULTS
@ ID_MENU_SCREENCOPY_JPEG
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
constexpr EDA_IU_SCALE unityScale
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
#define RANGE_SCALE_3D
This defines the range that all coord will have to be rendered.
Manage TOOL_ACTION objects.
void SetConditions(const TOOL_ACTION &aAction, const ACTION_CONDITIONS &aConditions)
Set the conditions the UI elements for activating a specific tool action should use for determining t...
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
EDA_3D_VIEWER_SETTINGS * m_Cfg
PROJECTION_TYPE GetProjection()
const glm::mat4 & GetViewMatrix() const
void SetViewMatrix(glm::mat4 aViewMatrix)
Set the affine matrix to be applied to a transformation camera.
Handle actions that are shared between different applications.
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
static TOOL_ACTION showNotInPosFile
static TOOL_ACTION showTHT
static TOOL_ACTION noGrid
static TOOL_ACTION show2_5mmGrid
static TOOL_ACTION show1mmGrid
static TOOL_ACTION showDNP
static TOOL_ACTION toggleOrtho
static TOOL_ACTION show10mmGrid
static TOOL_ACTION show5mmGrid
static TOOL_ACTION showSMD
static TOOL_ACTION showVirtual
static TOOL_ACTION showBBoxes
static TOOL_ACTION showAxis
Implement a canvas based on a wxGLCanvas.
int GetMovingSpeedMultiplier() const
void SetProjectionMode(int aMode)
void SetAnimationEnabled(bool aEnable)
Enable or disable camera animation when switching to a pre-defined view.
int GetProjectionMode() const
void RenderRaytracingRequest()
Request to render the current view in Raytracing mode.
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Set a dispatcher that processes events and forwards them to tools.
bool IsReloadRequestPending() const
Query if there is a pending reload request.
bool GetAnimationEnabled() const
void ReloadRequest(BOARD *aBoard=nullptr, S3D_CACHE *aCachePointer=nullptr)
void GetScreenshot(wxImage &aDstImage)
Request a screenshot and output it to the aDstImage.
void SetMovingSpeedMultiplier(int aMultiplier)
Set the camera animation moving speed multiplier option.
void RenderEngineChanged()
Notify that the render engine was changed.
void Request_refresh(bool aRedrawImmediately=true)
Schedule a refresh update of the canvas.
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard.
void OnSetFocus(wxFocusEvent &event)
void onDisableRayTracing(wxCommandEvent &aEvent)
void takeScreenshot(wxCommandEvent &event)
Create a Screenshot of the current 3D view.
void onViewportChanged(wxCommandEvent &aEvent)
PCB_BASE_FRAME * Parent() const
void SetUserViewports(std::vector< VIEWPORT3D > &aViewportList)
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
void NewDisplay(bool aForceImmediateRedraw=false)
Reload and refresh (rebuild) the 3D scene.
bool m_disable_ray_tracing
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
void onUpdateViewportsCb(wxUpdateUIEvent &aEvent)
void OnActivate(wxActivateEvent &event)
bool TryBefore(wxEvent &aEvent) override
void Exit3DFrame(wxCommandEvent &event)
Called when user press the File->Exit.
BOARD_ADAPTER m_boardAdapter
void RenderEngineChanged()
RenderEngineChanged - Update toolbar icon and call canvas RenderEngineChanged.
void Process_Special_Functions(wxCommandEvent &event)
void OnCloseWindow(wxCloseEvent &event)
void ReCreateMainToolbar()
void ReloadRequest()
Request reloading the 3D view.
wxFileName m_defaultSaveScreenshotFileName
VIEWPORT3D * m_lastSelectedViewport
void onRenderEngineSelection(wxCommandEvent &event)
std::map< wxString, VIEWPORT3D > m_viewports
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
NL_3D_VIEWER_PLUGIN * m_spaceMouse
void applyViewport(const wxString &aViewportName)
switch to a given predefined 3D viewport
wxArrayString m_viewportMRU
void loadCommonSettings()
Load configuration from common settings.
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification that common settings are updated.
std::vector< VIEWPORT3D > GetUserViewports() const
void handleIconizeEvent(wxIconizeEvent &aEvent) override
Handle a window iconize event.
virtual void handleIconizeEvent(wxIconizeEvent &aEvent)
Handle a window iconize event.
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
SETTINGS_MANAGER * GetSettingsManager() const
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
virtual void SaveSettings(APP_SETTINGS_BASE *aCfg)
Save common frame parameters to a configuration data file.
virtual void RegisterUIUpdateHandler(int aID, const ACTION_CONDITIONS &aConditions) override
Register a UI update handler for the control with ID aID.
wxString GetTextSelection(int aColumn=0)
Return the selected text from aColumn in the wxListCtrl in the dialog.
void SetListLabel(const wxString &aLabel)
Specialization of the wxAuiPaneInfo class for KiCad panels.
void SetScaleFactor(double aFactor)
Set the canvas scale factor, probably for a hi-DPI display.
void ResetToDefaults()
Resets all parameters to default values.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
The class that implements the public interface to the SpaceMouse plug-in.
void SetFocus(bool aFocus=true)
Set the connection to the 3Dconnexion driver to the focus state so that 3DMouse data is routed here.
static const int * GetAttributesList(ANTIALIASING_MODE aAntiAliasingMode)
Get a list of attributes to pass to wxGLCanvas.
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
std::vector< VIEWPORT3D > m_Viewports3D
List of stored viewports (pos + zoom)
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
virtual PROJECT_FILE & GetProjectFile() const
T * GetAppSettings()
Returns a handle to the a given settings by type If the settings have already been loaded,...
A modified version of the wxInfoBar class that allows us to:
EVT_TOOL_RANGE(ID_START_COMMAND_3D, ID_MENU_COMMAND_END, EDA_3D_VIEWER_FRAME::Process_Special_Functions) EDA_3D_VIEWER_FRAME
Declaration of the eda_3d_viewer class.
#define QUALIFIED_VIEWER3D_FRAMENAME(parent)
#define VIEWPORT_SWITCH_KEY
bool m_Use3DConnexionDriver
Use the 3DConnexion Driver.
const std::string JpegFileExtension
const std::string PngFileExtension
wxString PngFileWildcard()
wxString JpegFileWildcard()
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
Declaration of the NL_3D_VIEWER_PLUGIN class.
ANTIALIASING_MODE
Anti-aliasing options.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
double rotation_increment
int moving_speed_multiplier
bool show_footprints_normal
ANTIALIASING_MODE opengl_AA_mode
bool show_footprints_virtual
bool opengl_show_model_bbox
bool show_footprints_not_in_posfile
bool show_footprints_insert
Definition of file extensions used in Kicad.