26#include <wx/filename.h>
29#include <wx/wupdlock.h>
30#include <wx/clipbrd.h>
31#include <wx/filedlg.h>
91 const wxString& aTitle,
long style ) :
95 m_currentCamera( m_trackBallCamera ),
98 wxLogTrace( m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::EDA_3D_VIEWER_FRAME %s" ), aTitle );
100 m_disable_ray_tracing =
false;
101 m_aboutTitle =
_HKI(
"KiCad 3D Viewer" );
109 static const int status_dims[5] = { -1, 170, 130, 130, 130 };
111 wxStatusBar *status_bar = CreateStatusBar(
arrayDim( status_dims ) );
112 SetStatusWidths(
arrayDim( status_dims ), status_dims );
119 m_boardAdapter, m_currentCamera,
125 loadCommonSettings();
127 m_appearancePanel->SetUserViewports(
Prj().GetProjectFile().m_Viewports3D );
135 m_canvas->SetEventDispatcher( m_toolDispatcher );
140 m_toolManager->InitTools();
144 if(
EDA_3D_CONTROLLER* ctrlTool = GetToolManager()->GetTool<EDA_3D_CONTROLLER>() )
148 m_toolManager->InvokeTool(
"3DViewer.Control" );
156 m_infoBar =
new WX_INFOBAR(
this, &m_auimgr );
158 m_auimgr.SetManagedWindow(
this );
160 m_auimgr.AddPane( m_tbTopMain,
EDA_PANE().HToolbar().Name( wxS(
"TopMainToolbar" ) )
162 m_auimgr.AddPane( m_infoBar,
EDA_PANE().InfoBar().Name( wxS(
"InfoBar" ) )
164 m_auimgr.AddPane( m_appearancePanel,
EDA_PANE().Name(
"LayersManager" )
166 .Caption(
_(
"Appearance" ) ).PaneBorder(
false )
167 .MinSize( 180, -1 ).BestSize( 190, -1 ) );
168 m_auimgr.AddPane( m_canvas,
EDA_PANE().Canvas().Name( wxS(
"DrawFrame" ) )
171 wxAuiPaneInfo& layersManager = m_auimgr.GetPane(
"LayersManager" );
183 m_auimgr.GetPane( wxS(
"InfoBar" ) ).Hide();
186 m_canvas->SetInfoBar( m_infoBar );
187 m_canvas->SetStatusBar( status_bar );
191 m_spaceMouse = std::make_unique<NL_3D_VIEWER_PLUGIN>( m_canvas );
193 catch(
const std::system_error& e )
195 wxLogTrace( wxT(
"KI_TRACE_NAVLIB" ), e.what() );
201 m_canvas->SetFocus();
223#define GridSizeCheck( x ) ACTION_CONDITIONS().Check( cond.GridSize( x ) )
245 auto show_NotInPosfile =
305 static bool s_presetSwitcherShown =
false;
306 static bool s_viewportSwitcherShown =
false;
313 if( wxGetKeyState( WXK_TAB ) )
315 if( ( aEvent.GetEventType() == wxEVT_CHAR || aEvent.GetEventType() == wxEVT_CHAR_HOOK )
316 &&
static_cast<wxKeyEvent&
>( aEvent ).GetKeyCode() == WXK_TAB )
327 for( wxString& str : mru )
330 str =
_(
"Follow PCB Editor" );
332 str =
_(
"Follow PCB Plot Settings" );
337 s_presetSwitcherShown =
true;
339 s_presetSwitcherShown =
false;
343 if( idx >= 0 && idx < (
int) mru.size() )
355 if( this->IsActive() )
359 if( viewportMRU.size() > 0 )
363 s_viewportSwitcherShown =
true;
365 s_viewportSwitcherShown =
false;
369 if( idx >= 0 && idx < (
int) viewportMRU.size() )
378 return wxFrame::TryBefore( aEvent );
410 if(
m_canvas && aForceImmediateRedraw )
434 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::Exit3DFrame" ) );
442 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::OnCloseWindow" ) );
446 if(
m_auimgr.GetPane( wxS(
"LayersManager" ) ).IsShown() )
447 m_auimgr.GetPane( wxS(
"LayersManager" ) ).Show(
false );
459 int id =
event.GetId();
460 bool isChecked =
event.IsChecked();
462 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::Process_Special_Functions id %d "
488 wxFAIL_MSG( wxT(
"Invalid event in EDA_3D_VIEWER_FRAME::Process_Special_Functions()" ) );
496 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::%s disabling ray tracing." ),
506 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::OnActivate" ) );
508 if( aEvent.GetActive() &&
m_canvas )
543 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::LoadSettings" ) );
561 wxString legacyColorsPresetName =
_(
"legacy colors" );
565 if( !cfg->
FindPreset( legacyColorsPresetName ) )
590 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::SaveSettings" ) );
593 wxT(
"EDA_3D_VIEWER_FRAME::SaveSettings render setting Ray Trace" )
595 wxT(
"EDA_3D_VIEWER_FRAME::SaveSettings render setting OpenGL" ) );
613 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::CommonSettingsChanged" ) );
632 SetTitle(
_(
"3D Viewer" ) );
638 lm_pane_info.Caption(
_(
"Appearance" ) );
641 SetStatusText( wxEmptyString,
ACTIVITY );
650 wxAuiPaneInfo& layersManager =
m_auimgr.GetPane(
"LayersManager" );
678 wxString fullFileName;
679 bool fmt_is_jpeg =
false;
681 if( aFormat == EDA_3D_VIEWER_EXPORT_FORMAT::JPEG )
684 if( aFormat != EDA_3D_VIEWER_EXPORT_FORMAT::CLIPBOARD )
687 const wxString wildcard =
697 wxFileDialog dlg(
this,
_(
"3D Image File Name" ),
700 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
702 if( dlg.ShowModal() == wxID_CANCEL )
712 wxFileName fn = fullFileName;
714 if( !fn.IsDirWritable() )
718 msg.Printf(
_(
"Insufficient permissions to save file '%s'." ), fullFileName );
719 wxMessageBox( msg,
_(
"Error" ), wxOK | wxICON_ERROR,
this );
739 wxWindowUpdateLocker noUpdates(
this );
741 wxImage screenshotImage;
748 if( aFormat == EDA_3D_VIEWER_EXPORT_FORMAT::CLIPBOARD )
750 wxBitmap bitmap( screenshotImage );
754 if( wxTheClipboard->Open() )
756 wxBitmapDataObject* dobjBmp =
new wxBitmapDataObject( bitmap );
758 if( !wxTheClipboard->SetData( dobjBmp ) )
759 wxMessageBox(
_(
"Failed to copy image to clipboard" ) );
761 wxTheClipboard->Flush();
763 wxTheClipboard->Close();
768 if( !screenshotImage.SaveFile( fullFileName,
769 fmt_is_jpeg ? wxBITMAP_TYPE_JPEG : wxBITMAP_TYPE_PNG ) )
770 wxMessageBox(
_(
"Can't save file" ) );
772 screenshotImage.Destroy();
779 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::RenderEngineChanged()" ) );
788 wxCHECK_RET(
m_canvas, wxT(
"Cannot load settings to null canvas" ) );
@ ID_MENU3D_RESET_DEFAULTS
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...
void CommonSettingsChanged()
std::vector< VIEWPORT3D > GetUserViewports() const
Return a list of viewports created by the user.
void ApplyViewport(const wxString &aPresetName)
const wxArrayString & GetViewportsMRU()
void ApplyLayerPreset(const wxString &aPresetName)
const wxArrayString & GetLayerPresetsMRU()
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
void InitSettings(REPORTER *aStatusReporter, REPORTER *aWarningReporter)
Function to be called by the render when it need to reload the settings for the board.
void SetBoard(BOARD *aBoard) noexcept
Set current board to be rendered.
EDA_3D_VIEWER_SETTINGS * m_Cfg
void SetProject(PROJECT *aProject, bool aReferenceOnly=false)
Link a board to a given project.
PROJECTION_TYPE GetProjection()
Handle actions that are shared between different applications.
static TOOL_ACTION showLayersManager
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 toggleRaytacing
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 DoRePaint()
The actual function to repaint the canvas.
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.
Handle view actions for various 3D canvases.
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 CommonSettingsChanged(int aFlags) override
Notification that common settings are updated.
void applySettings(EDA_3D_VIEWER_SETTINGS *aSettings)
PCB_BASE_FRAME * Parent() const
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 OnActivate(wxActivateEvent &event)
bool TryBefore(wxEvent &aEvent) override
void Exit3DFrame(wxCommandEvent &event)
Called when user press the File->Exit.
BOARD_ADAPTER m_boardAdapter
void ToggleAppearanceManager()
std::unique_ptr< NL_3D_VIEWER_PLUGIN > m_spaceMouse
void RenderEngineChanged()
RenderEngineChanged - Update toolbar icon and call canvas RenderEngineChanged.
void Process_Special_Functions(wxCommandEvent &event)
void OnCloseWindow(wxCloseEvent &event)
void ShowChangedLanguage() override
void ReloadRequest()
Request reloading the 3D view.
wxFileName m_defaultSaveScreenshotFileName
BOARD_ADAPTER & GetAdapter()
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void loadCommonSettings()
Load configuration from common settings.
void TakeScreenshot(EDA_3D_VIEWER_EXPORT_FORMAT aFormat)
Create a Screenshot of the current 3D view.
void handleIconizeEvent(wxIconizeEvent &aEvent) override
Handle a window iconize event.
LAYER_PRESET_3D * FindPreset(const wxString &aName)
std::vector< LAYER_PRESET_3D > m_LayerPresets
virtual void handleIconizeEvent(wxIconizeEvent &aEvent)
Handle a window iconize event.
APPEARANCE_CONTROLS_3D * m_appearancePanel
void CommonSettingsChanged(int aFlags) override
Notification event that some of the common (suite-wide) settings have changed.
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
SETTINGS_MANAGER * GetSettingsManager() const
virtual void RecreateToolbars()
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
virtual void SaveSettings(APP_SETTINGS_BASE *aCfg)
Save common frame parameters to a configuration data file.
static KIGFX::VC_SETTINGS GetVcSettings()
Gets a populated View Controls settings object dervived from our program settings.
Specialization of the wxAuiPaneInfo class for KiCad panels.
void SetVcSettings(const KIGFX::VC_SETTINGS &aVcSettings)
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...
static const wxGLAttributes GetAttributesList(ANTIALIASING_MODE aAntiAliasingMode, bool aAlpha=false)
Get a list of attributes to pass to wxGLCanvas.
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
virtual COMMON_SETTINGS * GetCommonSettings() const
virtual SETTINGS_MANAGER & GetSettingsManager() const
std::vector< VIEWPORT3D > m_Viewports3D
List of stored viewports (pos + zoom)
static S3D_CACHE * Get3DCacheManager(PROJECT *aProject, bool updateProjDir=false)
Return a pointer to an instance of the 3D cache manager.
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
virtual PROJECT_FILE & GetProjectFile() const
T * GetToolbarSettings(const wxString &aFilename)
Return a handle to the given toolbar settings.
T * GetAppSettings(const wxString &aFilename)
Return a handle to the a given settings by type.
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.
EDA_3D_VIEWER_EXPORT_FORMAT
#define FOLLOW_PLOT_SETTINGS
#define LEGACY_PRESET_FLAG
#define QUALIFIED_VIEWER3D_FRAMENAME(parent)
#define VIEWPORT_SWITCH_KEY
#define PRESET_SWITCH_KEY
static const std::string JpegFileExtension
static const std::string PngFileExtension
static wxString PngFileWildcard()
static 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.
PGM_BASE & Pgm()
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 ...
ACTION_CONDITIONS & Check(const SELECTION_CONDITION &aCondition)
double rotation_increment
int moving_speed_multiplier
bool show_footprints_normal
ANTIALIASING_MODE opengl_AA_mode
bool show_footprints_virtual
bool show_footprints_not_in_posfile
bool highlight_on_rollover
bool show_footprints_insert
Definition of file extensions used in Kicad.
void SetAuiPaneSize(wxAuiManager &aManager, wxAuiPaneInfo &aPane, int aWidth, int aHeight)
Sets the size of an AUI pane, working around http://trac.wxwidgets.org/ticket/13180.