3D Viewer: fix screenshot file extension bug with GTK+

Append the appropriate file extension to the file name if the file name
does not have a file extension.  This is a know issue with the GTK+ file
dialog.

Make the last 3D viewer screenshot last file used code more coherent.

Add the 3D viewer main frame trace string to the trace environment
variables doxygen group.

Doxygen comment and other minor code cleaning.

Fixes lp:1804980

https://bugs.launchpad.net/bugs/1804980
This commit is contained in:
Wayne Stambaugh 2018-12-08 08:20:32 -05:00
parent a40cff18d3
commit c7998cfc23
4 changed files with 73 additions and 57 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -31,6 +31,7 @@
#include "../3d_viewer_id.h"
#include <project.h>
#include <gestfich.h>
#include <wildcards_and_files_ext.h>
#include <wx/colordlg.h>
#include <wx/colourdata.h>
#include <lru_cache.h>
@ -40,11 +41,13 @@
#include <bitmaps.h>
#include <pgm_base.h>
/**
* Trace mask used to enable or disable the trace output of this class.
* The debug output can be turned on by setting the WXTRACE environment variable to
* "KI_TRACE_EDA_3D_VIEWER". See the wxWidgets documentation on wxLogTrace for
* more information.
* Flag to enable 3D viewer main frame window debug tracing.
*
* Use "KI_TRACE_EDA_3D_VIEWER" to enable.
*
* @ingroup trace_env_vars
*/
const wxChar * EDA_3D_VIEWER::m_logTrace = wxT( "KI_TRACE_EDA_3D_VIEWER" );
@ -150,7 +153,7 @@ EDA_3D_VIEWER::EDA_3D_VIEWER( KIWAY *aKiway, PCB_BASE_FRAME *aParent,
wxDefaultPosition, wxDefaultSize,
style, VIEWER3D_FRAMENAME )
{
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER::EDA_3D_VIEWER %s" ), aTitle );
wxLogTrace( m_logTrace, "EDA_3D_VIEWER::EDA_3D_VIEWER %s", aTitle );
m_canvas = NULL;
@ -194,7 +197,8 @@ EDA_3D_VIEWER::EDA_3D_VIEWER( KIWAY *aKiway, PCB_BASE_FRAME *aParent,
m_mainToolBar->EnableTool( ID_RENDER_CURRENT_VIEW,
(m_settings.RenderEngineGet() == RENDER_ENGINE_OPENGL_LEGACY) );
m_mainToolBar->Connect( wxEVT_KEY_DOWN, wxKeyEventHandler( EDA_3D_VIEWER::OnKeyEvent ), NULL, this );
m_mainToolBar->Connect( wxEVT_KEY_DOWN, wxKeyEventHandler( EDA_3D_VIEWER::OnKeyEvent ),
NULL, this );
// Fixes bug in Windows (XP and possibly others) where the canvas requires the focus
// in order to receive mouse events. Otherwise, the user has to click somewhere on
@ -237,7 +241,7 @@ void EDA_3D_VIEWER::NewDisplay( bool aForceImmediateRedraw )
void EDA_3D_VIEWER::Exit3DFrame( wxCommandEvent &event )
{
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER::Exit3DFrame" ) );
wxLogTrace( m_logTrace, "EDA_3D_VIEWER::Exit3DFrame" );
Close( true );
}
@ -245,7 +249,7 @@ void EDA_3D_VIEWER::Exit3DFrame( wxCommandEvent &event )
void EDA_3D_VIEWER::OnCloseWindow( wxCloseEvent &event )
{
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER::OnCloseWindow" ) );
wxLogTrace( m_logTrace, "EDA_3D_VIEWER::OnCloseWindow" );
if( m_canvas )
m_canvas->Close();
@ -266,7 +270,7 @@ void EDA_3D_VIEWER::Process_Special_Functions( wxCommandEvent &event )
bool isChecked = event.IsChecked();
wxLogTrace( m_logTrace,
wxT( "EDA_3D_VIEWER::Process_Special_Functions id:%d isChecked:%d" ),
"EDA_3D_VIEWER::Process_Special_Functions id:%d isChecked:%d",
id, isChecked );
if( m_canvas == NULL )
@ -340,7 +344,8 @@ void EDA_3D_VIEWER::Process_Special_Functions( wxCommandEvent &event )
return;
case ID_MENU3D_BGCOLOR_BOTTOM_SELECTION:
if( Set3DColorFromUser( m_settings.m_BgColorBot, _( "Background Color, Bottom" ), nullptr ) )
if( Set3DColorFromUser( m_settings.m_BgColorBot, _( "Background Color, Bottom" ),
nullptr ) )
{
if( m_settings.RenderEngineGet() == RENDER_ENGINE_OPENGL_LEGACY )
m_canvas->Request_refresh();
@ -529,7 +534,7 @@ void EDA_3D_VIEWER::Process_Special_Functions( wxCommandEvent &event )
return;
default:
wxLogMessage( wxT( "EDA_3D_VIEWER::Process_Special_Functions() error: unknown command %d" ), id );
wxLogMessage( "EDA_3D_VIEWER::Process_Special_Functions() error: unknown command %d", id );
return;
}
}
@ -542,7 +547,7 @@ void EDA_3D_VIEWER::On3DGridSelection( wxCommandEvent &event )
wxASSERT( id < ID_MENU3D_GRID_END );
wxASSERT( id > ID_MENU3D_GRID );
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER::On3DGridSelection id:%d" ), id );
wxLogTrace( m_logTrace, "EDA_3D_VIEWER::On3DGridSelection id:%d", id );
switch( id )
{
@ -567,7 +572,7 @@ void EDA_3D_VIEWER::On3DGridSelection( wxCommandEvent &event )
break;
default:
wxLogMessage( wxT( "EDA_3D_VIEWER::On3DGridSelection() error: unknown command %d" ), id );
wxLogMessage( "EDA_3D_VIEWER::On3DGridSelection() error: unknown command %d", id );
return;
}
@ -583,7 +588,7 @@ void EDA_3D_VIEWER::OnRenderEngineSelection( wxCommandEvent &event )
wxASSERT( id < ID_MENU3D_ENGINE_END );
wxASSERT( id > ID_MENU3D_ENGINE );
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER::OnRenderEngineSelection id:%d" ), id );
wxLogTrace( m_logTrace, "EDA_3D_VIEWER::OnRenderEngineSelection id:%d", id );
const RENDER_ENGINE old_engine = m_settings.RenderEngineGet();
@ -600,7 +605,7 @@ void EDA_3D_VIEWER::OnRenderEngineSelection( wxCommandEvent &event )
break;
default:
wxLogMessage( wxT( "EDA_3D_VIEWER::OnRenderEngineSelection() error: unknown command %d" ), id );
wxLogMessage( "EDA_3D_VIEWER::OnRenderEngineSelection() error: unknown command %d", id );
return;
}
@ -623,7 +628,7 @@ void EDA_3D_VIEWER::ProcessZoom( wxCommandEvent &event )
{
int id = event.GetId();
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER::ProcessZoom id:%d" ), id );
wxLogTrace( m_logTrace, "EDA_3D_VIEWER::ProcessZoom id:%d", id );
if( m_canvas == NULL )
return;
@ -647,7 +652,7 @@ void EDA_3D_VIEWER::ProcessZoom( wxCommandEvent &event )
break;
default:
wxLogMessage( wxT( "EDA_3D_VIEWER::ProcessZoom() error: unknown command %d" ), id );
wxLogMessage( "EDA_3D_VIEWER::ProcessZoom() error: unknown command %d", id );
return;
}
@ -657,7 +662,7 @@ void EDA_3D_VIEWER::ProcessZoom( wxCommandEvent &event )
void EDA_3D_VIEWER::OnActivate( wxActivateEvent &event )
{
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER::OnActivate" ) );
wxLogTrace( m_logTrace, "EDA_3D_VIEWER::OnActivate" );
if( m_canvas )
{
@ -688,7 +693,7 @@ void EDA_3D_VIEWER::LoadSettings( wxConfigBase *aCfg )
{
EDA_BASE_FRAME::LoadSettings( aCfg );
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER::LoadSettings" ) );
wxLogTrace( m_logTrace, "EDA_3D_VIEWER::LoadSettings" );
aCfg->Read( keyBgColor_Red, &m_settings.m_BgColorBot.r, 0.4 );
aCfg->Read( keyBgColor_Green, &m_settings.m_BgColorBot.g, 0.4 );
@ -809,7 +814,7 @@ void EDA_3D_VIEWER::SaveSettings( wxConfigBase *aCfg )
{
EDA_BASE_FRAME::SaveSettings( aCfg );
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER::SaveSettings" ) );
wxLogTrace( m_logTrace, "EDA_3D_VIEWER::SaveSettings" );
aCfg->Write( keyBgColor_Red, m_settings.m_BgColorBot.r );
aCfg->Write( keyBgColor_Green, m_settings.m_BgColorBot.g );
@ -878,14 +883,14 @@ void EDA_3D_VIEWER::SaveSettings( wxConfigBase *aCfg )
void EDA_3D_VIEWER::OnLeftClick( wxDC *DC, const wxPoint &MousePos )
{
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER::OnLeftClick" ) );
wxLogTrace( m_logTrace, "EDA_3D_VIEWER::OnLeftClick" );
// Do nothing
}
void EDA_3D_VIEWER::OnRightClick( const wxPoint &MousePos, wxMenu *PopMenu )
{
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER::OnRightClick" ) );
wxLogTrace( m_logTrace, "EDA_3D_VIEWER::OnRightClick" );
// Do nothing
}
@ -901,7 +906,7 @@ void EDA_3D_VIEWER::OnKeyEvent( wxKeyEvent& event )
void EDA_3D_VIEWER::RedrawActiveWindow( wxDC *DC, bool EraseBg )
{
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER::RedrawActiveWindow" ) );
wxLogTrace( m_logTrace, "EDA_3D_VIEWER::RedrawActiveWindow" );
// Do nothing
}
@ -917,24 +922,29 @@ void EDA_3D_VIEWER::takeScreenshot( wxCommandEvent& event )
if( event.GetId() != ID_TOOL_SCREENCOPY_TOCLIBBOARD )
{
// Remember path between saves during this session only.
static wxFileName fn;
const wxString file_ext = fmt_is_jpeg ? wxT( "jpg" ) : wxT( "png" );
const wxString mask = wxT( "*." ) + file_ext;
const wxString wildcard = fmt_is_jpeg ? JpegFileWildcard() : PngFileWildcard();
const wxString ext = fmt_is_jpeg ? JpegFileExtension : PngFileExtension;
// First time path is set to the project path.
if( !fn.IsOk() )
fn = Parent()->Prj().GetProjectFullName();
if( !m_defaultSaveScreenshotFileName.IsOk() )
m_defaultSaveScreenshotFileName = Parent()->Prj().GetProjectFullName();
fn.SetExt( file_ext );
m_defaultSaveScreenshotFileName.SetExt( ext );
fullFileName = EDA_FILE_SELECTOR( _( "3D Image File Name:" ), fn.GetPath(),
m_defaultSaveScreenshotFileName, file_ext, mask, this,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT, true );
wxFileDialog dlg( this, _( "3D Image File Name" ),
m_defaultSaveScreenshotFileName.GetPath(),
m_defaultSaveScreenshotFileName.GetFullName(), wildcard,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
if( fullFileName.IsEmpty() )
if( dlg.ShowModal() == wxID_CANCEL )
return;
fn = fullFileName;
m_defaultSaveScreenshotFileName = dlg.GetPath();
if( m_defaultSaveScreenshotFileName.GetExt().IsEmpty() )
m_defaultSaveScreenshotFileName.SetExt( ext );
fullFileName = m_defaultSaveScreenshotFileName.GetFullPath();
// Be sure the screen area destroyed by the file dialog is redrawn
// before making a screen copy.
@ -1040,14 +1050,17 @@ bool EDA_3D_VIEWER::Set3DSolderMaskColorFromUser()
definedColors.push_back( CUSTOM_COLOR_ITEM( 20/255.0, 51/255.0, 36/255.0, "Green" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 91/255.0, 168/255.0, 12/255.0, "Light Green" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 13/255.0, 104/255.0, 11/255.0, "Saturated Green" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 13/255.0, 104/255.0, 11/255.0,
"Saturated Green" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 181/255.0, 19/255.0, 21/255.0, "Red" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 239/255.0, 53/255.0, 41/255.0, "Red Light Orange" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 239/255.0, 53/255.0, 41/255.0,
"Red Light Orange" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 210/255.0, 40/255.0, 14/255.0, "Red 2" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 2/255.0, 59/255.0, 162/255.0, "Blue" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 54/255.0, 79/255.0, 116/255.0, "Light blue 1" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 61/255.0, 85/255.0, 130/255.0, "Light blue 2" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 21/255.0, 70/255.0, 80/255.0, "Green blue (dark)" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 21/255.0, 70/255.0, 80/255.0,
"Green blue (dark)" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 11/255.0, 11/255.0, 11/255.0, "Black" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 245/255.0, 245/255.0, 245/255.0, "White" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 119/255.0, 31/255.0, 91/255.0, "Purple" ) );
@ -1087,7 +1100,8 @@ bool EDA_3D_VIEWER::Set3DBoardBodyColorFromUser()
{
CUSTOM_COLORS_LIST definedColors;
definedColors.push_back( CUSTOM_COLOR_ITEM( 51/255.0, 43/255.0, 22/255.0, "FR4 natural, dark" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 51/255.0, 43/255.0, 22/255.0,
"FR4 natural, dark" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 109/255.0, 116/255.0, 75/255.0, "FR4 natural" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 78/255.0, 14/255.0, 5/255.0, "brown/red" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 146/255.0, 99/255.0, 47/255.0, "brown 1" ) );

View File

@ -3,8 +3,8 @@
*
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -44,7 +44,6 @@
#define VIEWER3D_FRAMENAME wxT( "Viewer3DFrameName" )
/**
* Class EDA_3D_VIEWER
* Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard
*/
class EDA_3D_VIEWER : public KIWAY_PLAYER
@ -85,30 +84,25 @@ class EDA_3D_VIEWER : public KIWAY_PLAYER
void NewDisplay( bool aForceImmediateRedraw = false );
/**
* Function SetDefaultFileName
* Set the default file name (eg: to be suggested to a screenshot)
* @param aFn = file name to assign
*/
void SetDefaultFileName( const wxString &aFn )
void SetDefaultFileName( const wxString& aFn )
{
wxFileName fn( aFn );
m_defaultSaveScreenshotFileName = fn.GetName();
m_defaultSaveScreenshotFileName = aFn;
}
/**
* Function GetDefaultFileName
* @return the default suggested file name
*/
const wxString &GetDefaultFileName() const { return m_defaultSaveScreenshotFileName; }
const wxFileName& GetDefaultFileName() const { return m_defaultSaveScreenshotFileName; }
/**
* Function GetSettings
* @return current settings
*/
CINFO3D_VISU &GetSettings() { return m_settings; }
/**
* Function Set3DColorFromUser
* Get a SFVEC3D from a wx colour dialog
* @param aColor is the SFVEC3D to change
* @param aTitle is the title displayed in the colordialog selector
@ -121,7 +115,6 @@ class EDA_3D_VIEWER : public KIWAY_PLAYER
CUSTOM_COLORS_LIST* aPredefinedColors );
/**
* Function Set3DSolderMaskColorFromUser
* Set the solder mask color from a set of colors
* @return true if a new color is chosen, false if
* no change or aborted by user
@ -129,7 +122,6 @@ class EDA_3D_VIEWER : public KIWAY_PLAYER
bool Set3DSolderMaskColorFromUser();
/**
* Function Set3DSolderPasteColorFromUser
* Set the solder mask color from a set of colors
* @return true if a new color is chosen, false if
* no change or aborted by user
@ -137,7 +129,6 @@ class EDA_3D_VIEWER : public KIWAY_PLAYER
bool Set3DSolderPasteColorFromUser();
/**
* Function Set3DCopperColorFromUser
* Set the copper color from a set of colors
* @return true if a new color is chosen, false if
* no change or aborted by user
@ -145,7 +136,6 @@ class EDA_3D_VIEWER : public KIWAY_PLAYER
bool Set3DCopperColorFromUser();
/**
* Function Set3DBoardBodyBodyColorFromUser
* Set the copper color from a set of colors
* @return true if a new color is chosen, false if
* no change or aborted by user
@ -153,7 +143,6 @@ class EDA_3D_VIEWER : public KIWAY_PLAYER
bool Set3DBoardBodyColorFromUser();
/**
* Function Set3DSilkScreenColorFromUser
* Set the silkscreen color from a set of colors
* @return true if a new color is chosen, false if
* no change or aborted by user
@ -206,7 +195,6 @@ class EDA_3D_VIEWER : public KIWAY_PLAYER
void RedrawActiveWindow( wxDC *DC, bool EraseBg );
/**
* Function TakeScreenshot
* Create a Screenshot of the current 3D view.
* Output file format is png or jpeg, or image is copied to the clipboard
*/
@ -224,7 +212,7 @@ class EDA_3D_VIEWER : public KIWAY_PLAYER
/**
* Filename to propose for save a screenshot
*/
wxString m_defaultSaveScreenshotFileName;
wxFileName m_defaultSaveScreenshotFileName;
/**
* The canvas where the openGL context will be rendered

View File

@ -103,6 +103,9 @@ const std::string GedaPcbFootprintLibFileExtension( "fp" );
const std::string SpecctraDsnFileExtension( "dsn" );
const std::string IpcD356FileExtension( "d356" );
const std::string PngFileExtension( "png" );
const std::string JpegFileExtension( "jpg" );
const wxString AllFilesWildcard( _( "All files (*)|*" ) );
@ -379,3 +382,10 @@ wxString PngFileWildcard()
{
return _( "PNG file (*.png)|*." ) + FormatWildcardExt( "png" );
}
wxString JpegFileWildcard()
{
return _( "Jpeg file (*.jpg *.jpeg)|*." ) + FormatWildcardExt( "jpg" ) + ";*." +
FormatWildcardExt( "jpeg" );
}

View File

@ -85,6 +85,9 @@ extern const std::string KiCadLib3DShapesPathExtension;
extern const std::string SpecctraDsnFileExtension;
extern const std::string IpcD356FileExtension;
extern const std::string PngFileExtension;
extern const std::string JpegFileExtension;
/**
* @}
*/
@ -150,6 +153,7 @@ extern wxString SpecctraDsnFileWildcard();
extern wxString IpcD356FileWildcard();
extern wxString WorkbookFileWildcard();
extern wxString PngFileWildcard();
extern wxString JpegFileWildcard();
/**
* @}