25 #include <wx/filename.h> 26 #include <wx/msgdlg.h> 27 #include <wx/string.h> 28 #include <wx/wupdlock.h> 29 #include <wx/clipbrd.h> 30 #include <wx/filedlg.h> 31 #include <wx/treebook.h> 87 const wxString &aTitle,
long style ) :
90 m_mainToolBar(
nullptr ),
92 m_currentCamera( m_trackBallCamera ),
95 wxLogTrace( m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::EDA_3D_VIEWER_FRAME %s" ), aTitle );
97 m_disable_ray_tracing =
false;
98 m_aboutTitle =
_(
"KiCad 3D Viewer" );
106 static const int status_dims[4] = { -1, 170, 130, 130 };
108 wxStatusBar *status_bar = CreateStatusBar(
arrayDim( status_dims ) );
109 SetStatusWidths(
arrayDim( status_dims ), status_dims );
113 m_boardAdapter, m_currentCamera,
114 Prj().Get3DCacheManager() );
120 loadCommonSettings();
128 m_canvas->SetEventDispatcher( m_toolDispatcher );
133 m_toolManager->InitTools();
137 if(
EDA_3D_CONTROLLER* ctrlTool = GetToolManager()->GetTool<EDA_3D_CONTROLLER>() )
138 ctrlTool->SetRotationIncrement(
config->m_Camera.rotation_increment );
141 m_toolManager->InvokeTool(
"3DViewer.Control" );
144 ReCreateMainToolbar();
146 m_infoBar =
new WX_INFOBAR(
this, &m_auimgr );
148 m_auimgr.SetManagedWindow(
this );
150 m_auimgr.AddPane( m_mainToolBar,
EDA_PANE().HToolbar().Name(
"MainToolbar" ).Top().Layer( 6 ) );
151 m_auimgr.AddPane( m_infoBar,
EDA_PANE().InfoBar().Name(
"InfoBar" ).Top().Layer(1) );
152 m_auimgr.AddPane( m_canvas,
EDA_PANE().Canvas().Name(
"DrawFrame" ).
Center() );
159 m_auimgr.GetPane(
"InfoBar" ).Hide();
162 m_canvas->SetInfoBar( m_infoBar );
163 m_canvas->SetStatusBar( status_bar );
168 m_canvas->SetFocus();
192 #define FlagCheck( x ) ACTION_CONDITIONS().Check( cond.Flag( x ) ) 193 #define GridSizeCheck( x ) ACTION_CONDITIONS().Check( cond.GridSize( x ) ) 195 auto raytracingCondition =
218 auto orthoCondition =
236 book->AddPage(
new wxPanel( book ),
_(
"3D Viewer" ) );
260 if( aForceImmediateRedraw )
284 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::Exit3DFrame" ) );
292 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::OnCloseWindow" ) );
308 int id =
event.GetId();
309 bool isChecked =
event.IsChecked();
311 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::Process_Special_Functions id %d " 345 wxFAIL_MSG( wxT(
"Invalid event in EDA_3D_VIEWER_FRAME::Process_Special_Functions()" ) );
360 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::OnRenderEngineSelection type %s " ),
362 : wxT(
"realtime" ) );
371 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::%s disabling ray tracing." ),
381 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::OnActivate" ) );
383 if( aEvent.GetActive() &&
m_canvas )
415 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::LoadSettings" ) );
438 sphericalCoord.x = glm::clamp( sphericalCoord.x, 0.0f, 1.0f );
439 sphericalCoord.y = glm::clamp( sphericalCoord.y, 0.0f, 2.0f );
444 #define TRANSFER_SETTING( flag, field ) m_boardAdapter.SetFlag( flag, cfg->m_Render.field ) 508 wxT(
"EDA_3D_VIEWER_FRAME::LoadSettings render setting Ray Trace" )
510 wxT(
"EDA_3D_VIEWER_FRAME::LoadSettings render setting OpenGL" ) );
521 #undef TRANSFER_SETTING 532 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::SaveSettings" ) );
535 wxT(
"EDA_3D_VIEWER_FRAME::SaveSettings render setting Ray Trace" ) :
536 wxT(
"EDA_3D_VIEWER_FRAME::SaveSettings render setting OpenGL" ) );
543 aTarget =
COLOR4D( aSource.r, aSource.g, aSource.b, 1.0 );
550 for(
size_t i = 0; i < cfg->m_Render.raytrace_lightColor.size(); ++i )
554 cfg->m_Render.raytrace_lightElevation[i] =
556 cfg->m_Render.raytrace_lightAzimuth[i] =
568 cfg->m_Render.raytrace_recursivelevel_refractions =
570 cfg->m_Render.raytrace_recursivelevel_reflections =
573 #define TRANSFER_SETTING( field, flag ) cfg->m_Render.field = m_boardAdapter.GetFlag( flag ) 587 cfg->m_Camera.rotation_increment = ctrlTool->GetRotationIncrement();
622 #undef TRANSFER_SETTING 629 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::CommonSettingsChanged" ) );
645 wxString fullFileName;
646 bool fmt_is_jpeg =
false;
663 wxFileDialog dlg(
this,
_(
"3D Image File Name" ),
666 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
668 if( dlg.ShowModal() == wxID_CANCEL )
678 wxFileName fn = fullFileName;
680 if( !fn.IsDirWritable() )
684 msg.Printf(
_(
"Insufficient permissions to save file '%s'." ), fullFileName );
685 wxMessageBox( msg,
_(
"Error" ), wxOK | wxICON_ERROR,
this );
700 wxWindowUpdateLocker noUpdates(
this );
702 wxImage screenshotImage;
709 wxBitmap bitmap( screenshotImage );
713 if( wxTheClipboard->Open() )
715 wxBitmapDataObject* dobjBmp =
new wxBitmapDataObject( bitmap );
717 if( !wxTheClipboard->SetData( dobjBmp ) )
718 wxMessageBox(
_(
"Failed to copy image to clipboard" ) );
720 wxTheClipboard->Flush();
722 wxTheClipboard->Close();
727 if( !screenshotImage.SaveFile( fullFileName,
728 fmt_is_jpeg ? wxBITMAP_TYPE_JPEG : wxBITMAP_TYPE_PNG ) )
729 wxMessageBox(
_(
"Can't save file" ) );
731 screenshotImage.Destroy();
738 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_VIEWER_FRAME::RenderEngineChanged()" ) );
747 wxCHECK_RET(
m_canvas, wxT(
"Cannot load settings to null canvas" ) );
void ResetToDefaults()
Resets all parameters to default values.
int raytrace_nrsamples_reflections
GRID3D_TYPE GetGridType() const noexcept
Get the current grid.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
int GetMovingSpeedMultiplier() const
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
int m_RtShadowSampleCount
PROJECTION_TYPE GetProjection()
const std::string JpegFileExtension
static TOOL_ACTION show10mmGrid
#define TRANSFER_SETTING(flag, field)
virtual void SaveSettings(APP_SETTINGS_BASE *aCfg)
Save common frame parameters to a configuration data file.
BOARD_ADAPTER m_boardAdapter
void SetAntiAliasingMode(ANTIALIASING_MODE aAAmode)
Set the current antialiasing mode value.
int raytrace_nrsamples_refractions
SFVEC4F GetColor(const COLOR4D &aColor) const
PCB_BASE_FRAME * Parent() const
float raytrace_spread_shadows
void OnSetFocus(wxFocusEvent &event)
void ReCreateMainToolbar()
void SetFlag(DISPLAY3D_FLG aFlag, bool aState)
Set the status of a flag.
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
void SetProjectionMode(int aMode)
void Process_Special_Functions(wxCommandEvent &event)
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification that common settings are updated.
void OnDisableRayTracing(wxCommandEvent &aEvent)
virtual void RegisterUIUpdateHandler(int aID, const ACTION_CONDITIONS &aConditions) override
Register a UI update handler for the control with ID aID.
std::vector< SFVEC2F > m_RtLightSphericalCoords
Implement a canvas based on a wxGLCanvas.
bool IsReloadRequestPending() const
Query if there is a pending reload request.
void AddHotKeys(TOOL_MANAGER *aToolMgr)
KIGFX::COLOR4D raytrace_lightColorTop
wxString JpegFileWildcard()
void SetGridType(GRID3D_TYPE aGridType) noexcept
Set the current grid.
Manage TOOL_ACTION objects.
wxFileName m_defaultSaveScreenshotFileName
void loadCommonSettings()
Load configuration from common settings.
void Request_refresh(bool aRedrawImmediately=true)
Schedule a refresh update of the canvas.
void SetAnimationEnabled(bool aEnable)
Enable or disable camera animation when switching to a pre-defined view.
int moving_speed_multiplier
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
static const int * GetAttributesList(ANTIALIASING_MODE aAntiAliasingMode)
Get a list of attributes to pass to wxGLCanvas.
float m_RtSpreadRefractions
SFVEC3F m_RtCameraLightColor
static TOOL_ACTION showBBoxes
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
void InstallPreferences(PAGED_DIALOG *aParent, PANEL_HOTKEYS_EDITOR *aHotkeysPanel) override
Allow a frame to load its preference panels (if any) into the preferences dialog.
RENDER_ENGINE GetRenderEngine() const noexcept
wxTreebook * GetTreebook()
void OnCloseWindow(wxCloseEvent &event)
static TOOL_ACTION showSMD
static TOOL_ACTION showVirtual
int m_RtRecursiveReflectionCount
float m_RtSpreadReflections
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Set a dispatcher that processes events and forwards them to tools.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
static TOOL_ACTION show5mmGrid
bool m_disable_ray_tracing
static TOOL_ACTION showTHT
void NewDisplay(bool aForceImmediateRedraw=false)
Reload and refresh (rebuild) the 3D scene.
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
void RenderEngineChanged()
Notify that the render engine was changed.
MATERIAL_MODE GetMaterialMode() const noexcept
SFVEC3F m_RtLightColorTop
std::vector< int > raytrace_lightElevation
void SetMaterialMode(MATERIAL_MODE aMaterialMode) noexcept
Definition of file extensions used in Kicad.
int raytrace_recursivelevel_refractions
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
int m_RtRecursiveRefractionCount
std::vector< SFVEC3F > m_RtLightColor
static TOOL_ACTION showAxis
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
KIGFX::COLOR4D raytrace_lightColorCamera
Handle actions that are shared between different applications.
int m_RtRefractionSampleCount
Specialization of the wxAuiPaneInfo class for KiCad panels.
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 SetMovingSpeedMultiplier(int aMultiplier)
Set the camera animation moving speed multiplier option.
int raytrace_nrsamples_shadows
void SetRenderEngine(RENDER_ENGINE aRenderEngine) noexcept
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
wxString PngFileWildcard()
int raytrace_recursivelevel_reflections
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
A modified version of the wxInfoBar class that allows us to:
void GetScreenshot(wxImage &aDstImage)
Request a screenshot and output it to the aDstImage.
void takeScreenshot(wxCommandEvent &event)
Create a Screenshot of the current 3D view.
void ReloadRequest()
Request reloading the 3D view.
float raytrace_spread_refractions
static TOOL_ACTION show2_5mmGrid
static TOOL_ACTION show1mmGrid
int GetProjectionMode() const
ANTIALIASING_MODE GetAntiAliasingMode() const
Get the current antialiasing mode value.
float raytrace_spread_reflections
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
The base frame for deriving all KiCad main window classes.
bool GetAnimationEnabled() const
const std::string PngFileExtension
void SetScaleFactor(double aFactor)
Set the canvas scale factor, probably for a hi-DPI display.
std::vector< KIGFX::COLOR4D > raytrace_lightColor
RENDER_ENGINE
Render engine mode.
static TOOL_ACTION noGrid
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
SFVEC3F m_OpenGlSelectionColor
void ReloadRequest(BOARD *aBoard=nullptr, S3D_CACHE *aCachePointer=nullptr)
#define QUALIFIED_VIEWER3D_FRAMENAME(parent)
KIGFX::COLOR4D raytrace_lightColorBottom
EVT_TOOL_RANGE(ID_START_COMMAND_3D, ID_MENU_COMMAND_END, EDA_3D_VIEWER_FRAME::Process_Special_Functions) EDA_3D_VIEWER_FRAME
static TOOL_ACTION toggleOrtho
SFVEC3F m_RtLightColorBottom
KIGFX::COLOR4D opengl_selection_color
std::vector< int > raytrace_lightAzimuth
#define RANGE_SCALE_3D
This defines the range that all coord will have to be rendered.
int m_RtReflectionSampleCount
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
void OnRenderEngineSelection(wxCommandEvent &event)
void RenderEngineChanged()
RenderEngineChanged - Update toolbar icon and call canvas RenderEngineChanged.
void OnActivate(wxActivateEvent &event)
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
void Exit3DFrame(wxCommandEvent &event)
Called when user press the File->Exit.
A color representation with 4 components: red, green, blue, alpha.