25 #include <wx/colordlg.h> 26 #include <wx/colour.h> 27 #include <wx/filename.h> 28 #include <wx/string.h> 29 #include <wx/wupdlock.h> 30 #include <wx/clipbrd.h> 88 m_mainToolBar(
nullptr ),
90 m_currentCamera( m_trackBallCamera ),
93 wxLogTrace( m_logTrace,
"EDA_3D_VIEWER::EDA_3D_VIEWER %s", aTitle );
95 m_disable_ray_tracing =
false;
96 m_aboutTitle =
_(
"KiCad 3D Viewer" );
104 static const int status_dims[4] = { -1, 170, 130, 130 };
106 wxStatusBar *status_bar = CreateStatusBar(
arrayDim( status_dims ) );
107 SetStatusWidths(
arrayDim( status_dims ), status_dims );
111 aParent->GetBoard(), m_boardAdapter, m_currentCamera,
112 Prj().Get3DCacheManager() );
115 LoadSettings( config );
118 loadCommonSettings();
126 m_canvas->SetEventDispatcher( m_toolDispatcher );
131 m_toolManager->InitTools();
135 if(
EDA_3D_CONTROLLER* ctrlTool = GetToolManager()->GetTool<EDA_3D_CONTROLLER>() )
136 ctrlTool->SetRotationIncrement( config->m_Camera.rotation_increment );
139 m_toolManager->InvokeTool(
"3DViewer.Control" );
142 ReCreateMainToolbar();
144 m_infoBar =
new WX_INFOBAR(
this, &m_auimgr );
146 m_auimgr.SetManagedWindow(
this );
148 m_auimgr.AddPane( m_mainToolBar,
EDA_PANE().HToolbar().Name(
"MainToolbar" ).Top().Layer( 6 ) );
149 m_auimgr.AddPane( m_infoBar,
EDA_PANE().InfoBar().Name(
"InfoBar" ).Top().Layer(1) );
150 m_auimgr.AddPane( m_canvas,
EDA_PANE().Canvas().Name(
"DrawFrame" ).
Center() );
157 m_auimgr.GetPane(
"InfoBar" ).Hide();
160 m_canvas->SetInfoBar( m_infoBar );
161 m_canvas->SetStatusBar( status_bar );
166 m_canvas->SetFocus();
190 #define MaterialCheck( x ) ACTION_CONDITIONS().Check( cond.MaterialMode( x ) ) 191 #define FlagCheck( x ) ACTION_CONDITIONS().Check( cond.Flag( x ) ) 192 #define GridSizeCheck( x ) ACTION_CONDITIONS().Check( cond.GridSize( x ) ) 194 auto raytracingCondition = [
this](
const SELECTION& aSel )
235 auto orthoCondition =
263 if( aForceImmediateRedraw )
287 wxLogTrace(
m_logTrace,
"EDA_3D_VIEWER::Exit3DFrame" );
295 wxLogTrace(
m_logTrace,
"EDA_3D_VIEWER::OnCloseWindow" );
311 int id =
event.GetId();
312 bool isChecked =
event.IsChecked();
314 wxLogTrace(
m_logTrace,
"EDA_3D_VIEWER::Process_Special_Functions id %d isChecked %d",
383 wxFAIL_MSG(
"Invalid event in EDA_3D_VIEWER::Process_Special_Functions()" );
398 wxLogTrace(
m_logTrace,
"EDA_3D_VIEWER::OnRenderEngineSelection type %s ",
409 wxLogTrace(
m_logTrace,
"EDA_3D_VIEWER::%s disabling ray tracing.", __WXFUNCTION__ );
418 wxLogTrace(
m_logTrace,
"EDA_3D_VIEWER::OnActivate" );
420 if( aEvent.GetActive() &&
m_canvas )
452 wxLogTrace(
m_logTrace,
"EDA_3D_VIEWER::LoadSettings" );
459 aTarget.r = aColor.
r;
460 aTarget.g = aColor.
g;
461 aTarget.b = aColor.
b;
462 aTarget.a = aColor.
a;
497 sphericalCoord.x = glm::clamp( sphericalCoord.x, 0.0f, 1.0f );
498 sphericalCoord.y = glm::clamp( sphericalCoord.y, 0.0f, 2.0f );
503 #define TRANSFER_SETTING( flag, field ) m_boardAdapter.SetFlag( flag, cfg->m_Render.field ) 513 opengl_thickness_disableOnMove );
567 "EDA_3D_VIEWER::LoadSettings render setting Ray Trace" :
568 "EDA_3D_VIEWER::LoadSettings render setting OpenGL" );
578 #undef TRANSFER_SETTING 589 wxLogTrace(
m_logTrace,
"EDA_3D_VIEWER::SaveSettings" );
604 SFVEC4F newSFVEC4Fcolor(
float(
colors->GetColor( aTarget ).r ),
605 float(
colors->GetColor( aTarget ).g ),
606 float(
colors->GetColor( aTarget ).b ),
607 float(
colors->GetColor( aTarget ).a ) );
609 if( aSource != newSFVEC4Fcolor )
610 colors->SetColor( aTarget,
COLOR4D( aSource.r, aSource.g, aSource.b,
623 Pgm().GetSettingsManager().SaveColorSettings(
colors,
"3d_viewer" );
626 "EDA_3D_VIEWER::SaveSettings render setting Ray Trace" :
627 "EDA_3D_VIEWER::SaveSettings render setting OpenGL" );
635 aTarget =
COLOR4D( aSource.r, aSource.g, aSource.b, 1.0 );
642 for(
size_t i = 0; i < cfg->m_Render.raytrace_lightColor.size(); ++i )
646 cfg->m_Render.raytrace_lightElevation[i] =
648 cfg->m_Render.raytrace_lightAzimuth[i] =
660 cfg->m_Render.raytrace_recursivelevel_refractions =
662 cfg->m_Render.raytrace_recursivelevel_reflections =
665 #define TRANSFER_SETTING( field, flag ) cfg->m_Render.field = m_boardAdapter.GetFlag( flag ) 678 cfg->m_Camera.rotation_increment = ctrlTool->GetRotationIncrement();
713 #undef TRANSFER_SETTING 730 wxString colorName = stckpItem->GetColor();
732 if( colorName.StartsWith(
"#" ) )
734 color.Set( colorName );
740 if( stdColors[i].m_ColorName == colorName )
750 switch( stckpItem->GetBrdLayerId() )
787 wxLogTrace(
m_logTrace,
"EDA_3D_VIEWER::CommonSettingsChanged" );
803 wxString fullFileName;
804 bool fmt_is_jpeg =
false;
821 wxFileDialog dlg(
this,
_(
"3D Image File Name" ),
824 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
826 if( dlg.ShowModal() == wxID_CANCEL )
836 wxFileName fn = fullFileName;
838 if( !fn.IsDirWritable() )
842 msg.Printf(
_(
"Insufficient permissions required to save file\n%s" ), fullFileName );
843 wxMessageBox( msg,
_(
"Error" ), wxOK | wxICON_ERROR,
this );
858 wxWindowUpdateLocker noUpdates(
this );
860 wxImage screenshotImage;
867 wxBitmap bitmap( screenshotImage );
871 if( wxTheClipboard->Open() )
873 wxBitmapDataObject* dobjBmp =
new wxBitmapDataObject( bitmap );
875 if( !wxTheClipboard->SetData( dobjBmp ) )
876 wxMessageBox(
_(
"Failed to copy image to clipboard" ) );
878 wxTheClipboard->Flush();
880 wxTheClipboard->Close();
885 if( !screenshotImage.SaveFile( fullFileName,
886 fmt_is_jpeg ? wxBITMAP_TYPE_JPEG : wxBITMAP_TYPE_PNG ) )
887 wxMessageBox(
_(
"Can't save file" ) );
889 screenshotImage.Destroy();
897 wxLogTrace(
m_logTrace,
"EDA_3D_VIEWER::RenderEngineChanged()" );
906 bool aAllowOpacityControl,
915 if( picker.ShowModal() != wxID_OK )
920 if( newcolor == oldcolor )
923 aColor.
r = newcolor.
r;
924 aColor.g = newcolor.
g;
925 aColor.b = newcolor.
b;
926 aColor.a = newcolor.
a;
960 "Saturated Green" ) );
963 "Red Light Orange" ) );
969 "Green blue (dark)" ) );
1015 "FR4 natural, dark" ) );
1025 true,
colors[0].m_Color ) )
1045 false,
colors[0].m_Color ) )
1058 wxCHECK_RET(
m_canvas,
"Cannot load settings to null canvas" );
Use a gray shading based on diffuse material.
void AnimationEnabledSet(bool aAnimationEnabled)
Enable or disable camera animation when switching to a pre-defined view.
void ResetToDefaults()
Resets all parameters to default values.
int raytrace_nrsamples_reflections
GRID3D_TYPE GetGridType() const noexcept
Get the current grid.
SFVEC4F GetColor(COLOR4D aColor) const
bool Set3DCopperColorFromUser()
Set the copper color from a set of colors.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
int m_RtShadowSampleCount
SFVEC4F m_SilkScreenColorBot
in realistic mode: SilkScreen color ( bot )
PROJECTION_TYPE GetProjection()
const std::string JpegFileExtension
static TOOL_ACTION show10mmGrid
static TOOL_ACTION materialCAD
this class manage the layers needed to make a physical board they are solder mask,...
virtual void SaveSettings(APP_SETTINGS_BASE *aCfg)
Save common frame parameters to a configuration data file.
static TOOL_ACTION showBoundingBoxes
bool Set3DSolderMaskColorFromUser()
Set the solder mask color from a set of colors.
void SetAntiAliasingMode(ANTIALIASING_MODE aAAmode)
Set the current antialiasing mode value.
int raytrace_nrsamples_refractions
float raytrace_spread_shadows
void SetFlag(DISPLAY3D_FLG aFlag, bool aState)
Set the status of a flag.
SFVEC4F m_SolderMaskColorTop
in realistic mode: solder mask color ( top )
LAYER_3D_ID
3D Viewer virtual layers for color settings
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
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.
std::vector< SFVEC2F > m_RtLightSphericalCoords
Implement a canvas based on a wxGLCanvas.
bool IsReloadRequestPending() const
Query if there is a pending reload request.
SFVEC4F m_BoardBodyColor
in realistic mode: FR4 board color
SFVEC4F m_SolderPasteColor
in realistic mode: solder paste color
static TOOL_ACTION showRefractions
int GetColorStandardListCount()
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
void SynchroniseColoursWithBoard()
A class to handle a custom color (predefined color) for the color picker dialog.
KIGFX::COLOR4D raytrace_lightColorTop
SFVEC4F m_SolderMaskColorBot
in realistic mode: solder mask color ( bot )
wxString JpegFileWildcard()
void SetGridType(GRID3D_TYPE aGridType) noexcept
Set the current grid.
Manage TOOL_ACTION objects.
std::vector< CUSTOM_COLOR_ITEM > CUSTOM_COLORS_LIST
void Request_refresh(bool aRedrawImmediately=true)
Schedule a refresh update of the canvas.
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
void Exit3DFrame(wxCommandEvent &event)
Called when user press the File->Exit.
SFVEC3F m_RtCameraLightColor
void loadCommonSettings()
Load configuration from common settings.
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
void MovingSpeedMultiplierSet(int aMovingSpeedMultiplier)
Set the camera animation moving speed multiplier option.
Use only diffuse material properties.
RENDER_ENGINE GetRenderEngine() const noexcept
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
void OnActivate(wxActivateEvent &event)
static TOOL_ACTION antiAliasing
BOARD_ADAPTER m_boardAdapter
BOARD_STACKUP & GetStackupDescriptor()
void OnDisableRayTracing(wxCommandEvent &aEvent)
int m_RtRecursiveReflectionCount
float m_RtSpreadReflections
SFVEC4F m_BgColorTop
background top color
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
#define TRANSFER_SETTING(flag, field)
const BITMAP_OPAQUE icon_3d_xpm[1]
Use all material properties from model file.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
void RenderEngineChanged()
Notify that the render engine was changed.
bool Set3DSilkScreenColorFromUser()
Set the silkscreen color from a set of colors.
MATERIAL_MODE GetMaterialMode() const noexcept
SFVEC3F m_RtLightColorTop
std::vector< int > raytrace_lightElevation
void SetMaterialMode(MATERIAL_MODE aMaterialMode) noexcept
bool AnimationEnabledGet() const
Return whether camera animation is enabled when switching to a pre-defined view.
Definition of file extensions used in Kicad.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
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.
void OnCloseWindow(wxCloseEvent &event)
SFVEC4F m_BgColorBot
background bottom color
bool Set3DColorFromUser(SFVEC4F &aColor, const wxString &aTitle, CUSTOM_COLORS_LIST *aPredefinedColors, bool aAllowOpacityControl=false, KIGFX::COLOR4D aDefaultColor=KIGFX::COLOR4D(1.0, 1.0, 1.0, 1.0))
Get a SFVEC3D from a color dialog.
static TOOL_ACTION materialNormal
void ReCreateMainToolbar()
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
int m_RtRecursiveRefractionCount
static TOOL_ACTION addFloor
std::vector< SFVEC3F > m_RtLightColor
static TOOL_ACTION showAxis
KIGFX::COLOR4D raytrace_lightColorCamera
Handle actions that are shared between different applications.
bool Set3DSolderPasteColorFromUser()
Set the solder mask color from a set of colors.
this class manage one layer needed to make a physical board it can be a solder mask,...
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...
int raytrace_nrsamples_shadows
const std::vector< BOARD_STACKUP_ITEM * > & GetList() const
void SetRenderEngine(RENDER_ENGINE aRenderEngine) noexcept
wxString PngFileWildcard()
void RenderEngineChanged()
RenderEngineChanged - Update toolbar icon and call canvas RenderEngineChanged.
int raytrace_recursivelevel_reflections
static TOOL_ACTION materialDiffuse
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:
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
void GetScreenshot(wxImage &aDstImage)
Request a screenshot and output it to the aDstImage.
int MovingSpeedMultiplierGet() const
Return the current camera animation moving speed multiplier option.
float raytrace_spread_refractions
static TOOL_ACTION proceduralTextures
static TOOL_ACTION show2_5mmGrid
static TOOL_ACTION show1mmGrid
Declaration of the eda_3d_viewer class.
Board layer functions and definitions.
wxFileName m_defaultSaveScreenshotFileName
ANTIALIASING_MODE GetAntiAliasingMode() const
Get the current antialiasing mode value.
Information pertinent to a Pcbnew printed circuit board.
float raytrace_spread_reflections
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
SFVEC4F m_CopperColor
in realistic mode: copper color
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
The base frame for deriving all KiCad main window classes.
void OnRenderEngineSelection(wxCommandEvent &event)
static TOOL_ACTION postProcessing
PCB_BASE_FRAME * Parent() const
KIGFX::COLOR4D GetColor()
const FAB_LAYER_COLOR * GetColorStandardList()
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 OnSetFocus(wxFocusEvent &event)
void ReloadRequest(BOARD *aBoard=nullptr, S3D_CACHE *aCachePointer=nullptr)
Color settings are a bit different than most of the settings objects in that there can be more than o...
static TOOL_ACTION showReflections
SFVEC4F m_SilkScreenColorTop
in realistic mode: SilkScreen color ( top )
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard.
KIGFX::COLOR4D raytrace_lightColorBottom
static TOOL_ACTION toggleOrtho
SFVEC3F m_RtLightColorBottom
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification that common settings are updated.
KIGFX::COLOR4D opengl_selection_color
void NewDisplay(bool aForceImmediateRedraw=false)
Reload and refresh (rebuild) the 3D scene.
static TOOL_ACTION renderShadows
EVT_TOOL_RANGE(ID_START_COMMAND_3D, ID_MENU_COMMAND_END, EDA_3D_VIEWER::Process_Special_Functions) EDA_3D_VIEWER
std::vector< int > raytrace_lightAzimuth
#define RANGE_SCALE_3D
This defines the range that all coord will have to be rendered.
#define QUALIFIED_VIEWER3D_FRAMENAME(parent)
int m_RtReflectionSampleCount
static VRML_COLOR colors[VRML_COLOR_LAST]
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
bool m_disable_ray_tracing
bool Set3DBoardBodyColorFromUser()
Set the copper color from a set of colors.
void ReloadRequest()
Request reloading the 3D view.
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
void Process_Special_Functions(wxCommandEvent &event)
A color representation with 4 components: red, green, blue, alpha.
void takeScreenshot(wxCommandEvent &event)
Create a Screenshot of the current 3D view.