Fix a Coverity warning (potential bug)

Prepare work to fix Bug #1495321 (clean code in dialog_select_pretty_lib, fix incorrect comments)
This commit is contained in:
jean-pierre charras 2015-09-26 08:46:25 +02:00
parent 78dc14c078
commit d957ef9f71
7 changed files with 141 additions and 43 deletions

View File

@ -537,13 +537,12 @@ void MoveMarkedItems( MODULE* module, wxPoint offset )
*/
void DeleteMarkedItems( MODULE* module )
{
BOARD_ITEM* next_item;
D_PAD* next_pad;
BOARD* board = module->GetBoard();
if( module == NULL )
return;
D_PAD* next_pad;
BOARD* board = module->GetBoard();
for( D_PAD* pad = module->Pads(); pad; pad = next_pad )
{
next_pad = pad->Next();
@ -557,6 +556,8 @@ void DeleteMarkedItems( MODULE* module )
pad->DeleteStructure();
}
BOARD_ITEM* next_item;
for( BOARD_ITEM* item = module->GraphicalItems(); item; item = next_item )
{
next_item = item->Next();

View File

@ -1,8 +1,8 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2014 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2015 KiCad Developers, see change_log.txt for contributors.
*
*
* This program is free software; you can redistribute it and/or
@ -30,6 +30,7 @@
* footprints are .kicad_mod files inside this folder
*/
#include <wildcards_and_files_ext.h>
#include <dialog_select_pretty_lib.h>
#include <project.h>
@ -52,3 +53,22 @@ void DIALOG_SELECT_PRETTY_LIB::OnSelectFolder( wxFileDirPickerEvent& event )
event.Skip();
}
const wxString DIALOG_SELECT_PRETTY_LIB::GetFullPrettyLibName()
{
wxFileName fn = m_libName->GetValue();
if( !fn.IsAbsolute() )
fn.MakeAbsolute( m_dirCtrl->GetPath() );
// Enforce the extension:
fn.SetExt( KiCadFootprintLibPathExtension );
return fn.GetFullPath();
}
void DIALOG_SELECT_PRETTY_LIB::OnOKButton( wxCommandEvent& event )
{
event.Skip();
}

View File

@ -43,10 +43,15 @@ public:
const wxString& aDefaultPath );
~DIALOG_SELECT_PRETTY_LIB() {};
const wxString GetPath() { return m_libName->GetValue(); }
/**
* @return the full .pretty lib name, which is an absolute path
*, ending wityh ".pretty"
*/
const wxString GetFullPrettyLibName();
private:
virtual void OnSelectFolder( wxFileDirPickerEvent& event );
virtual void OnOKButton( wxCommandEvent& event );
};

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jun 5 2014)
// C++ code generated with wxFormBuilder (version Jun 17 2015)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
@ -22,17 +22,21 @@ DIALOG_SELECT_PRETTY_LIB_BASE::DIALOG_SELECT_PRETTY_LIB_BASE( wxWindow* parent,
bSizerMain->Add( m_staticText, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
m_staticText3 = new wxStaticText( this, wxID_ANY, _("Path base:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText3->Wrap( -1 );
bSizerMain->Add( m_staticText3, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
m_dirCtrl = new wxDirPickerCtrl( this, wxID_ANY, wxEmptyString, _("Select a folder"), wxDefaultPosition, wxDefaultSize, wxDIRP_DEFAULT_STYLE );
bSizerMain->Add( m_dirCtrl, 0, wxALL|wxEXPAND, 5 );
bSizerMain->Add( m_dirCtrl, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
m_SizerNewLibName = new wxBoxSizer( wxVERTICAL );
m_staticTextDirname = new wxStaticText( this, wxID_ANY, _("Library Path (.pretty will be appended to folder)"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextDirname = new wxStaticText( this, wxID_ANY, _("Library folder (.pretty will be added to name, if missing)"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextDirname->Wrap( -1 );
m_SizerNewLibName->Add( m_staticTextDirname, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
m_libName = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
m_SizerNewLibName->Add( m_libName, 0, wxALL|wxEXPAND, 5 );
m_SizerNewLibName->Add( m_libName, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
bSizerMain->Add( m_SizerNewLibName, 0, wxEXPAND, 5 );
@ -58,11 +62,13 @@ DIALOG_SELECT_PRETTY_LIB_BASE::DIALOG_SELECT_PRETTY_LIB_BASE( wxWindow* parent,
// Connect Events
m_dirCtrl->Connect( wxEVT_COMMAND_DIRPICKER_CHANGED, wxFileDirPickerEventHandler( DIALOG_SELECT_PRETTY_LIB_BASE::OnSelectFolder ), NULL, this );
m_sdbSizerOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SELECT_PRETTY_LIB_BASE::OnOKButton ), NULL, this );
}
DIALOG_SELECT_PRETTY_LIB_BASE::~DIALOG_SELECT_PRETTY_LIB_BASE()
{
// Disconnect Events
m_dirCtrl->Disconnect( wxEVT_COMMAND_DIRPICKER_CHANGED, wxFileDirPickerEventHandler( DIALOG_SELECT_PRETTY_LIB_BASE::OnSelectFolder ), NULL, this );
m_sdbSizerOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SELECT_PRETTY_LIB_BASE::OnOKButton ), NULL, this );
}

View File

@ -178,7 +178,90 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="flag">wxTOP|wxRIGHT|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Path base:</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_staticText3</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<property name="wrap">-1</property>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxDirPickerCtrl" expanded="1">
<property name="BottomDockable">1</property>
@ -305,7 +388,7 @@
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Library Path (.pretty will be appended to folder)</property>
<property name="label">Library folder (.pretty will be added to name, if missing)</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
@ -358,7 +441,7 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="flag">wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxTextCtrl" expanded="1">
<property name="BottomDockable">1</property>
@ -551,7 +634,7 @@
<event name="OnContextHelpButtonClick"></event>
<event name="OnHelpButtonClick"></event>
<event name="OnNoButtonClick"></event>
<event name="OnOKButtonClick"></event>
<event name="OnOKButtonClick">OnOKButton</event>
<event name="OnSaveButtonClick"></event>
<event name="OnYesButtonClick"></event>
</object>

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jun 5 2014)
// C++ code generated with wxFormBuilder (version Jun 17 2015)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
@ -39,6 +39,7 @@ class DIALOG_SELECT_PRETTY_LIB_BASE : public DIALOG_SHIM
protected:
wxStaticText* m_staticText;
wxStaticText* m_staticText3;
wxDirPickerCtrl* m_dirCtrl;
wxBoxSizer* m_SizerNewLibName;
wxStaticText* m_staticTextDirname;
@ -50,6 +51,7 @@ class DIALOG_SELECT_PRETTY_LIB_BASE : public DIALOG_SHIM
// Virtual event handlers, overide them in your derived class
virtual void OnSelectFolder( wxFileDirPickerEvent& event ) { event.Skip(); }
virtual void OnOKButton( wxCommandEvent& event ) { event.Skip(); }
public:

View File

@ -76,7 +76,6 @@
#define FMT_MOD_DELETED _( "Footprint %s deleted from library '%s'" )
#define FMT_MOD_CREATE _( "New Footprint" )
#define FMT_NO_MODULES _( "No footprints to archive!" )
#define FMT_MOD_EXISTS _( "Footprint %s already exists in library '%s'" )
#define FMT_NO_REF_ABORTED _( "No footprint name defined." )
#define FMT_SELECT_LIB _( "Select Library" )
@ -387,23 +386,15 @@ bool FOOTPRINT_EDIT_FRAME::SaveCurrentModule( const wxString* aLibPath )
wxString FOOTPRINT_EDIT_FRAME::CreateNewLibrary()
{
wxFileName fn;
wxConfigBase* config = Kiface().KifaceSettings();
if( config )
{
wxString path;
config->Read( EXPORT_IMPORT_LASTPATH_KEY, &path );
fn.SetPath( path );
}
// Kicad cannot write legacy format libraries, only .pretty new format
// because the legacy format cannot handle current features.
// The lib is actually a directory
// The footprint library is actually a directory
wxString wildcard = wxGetTranslation( KiCadFootprintLibPathWildcard );
// prompt user for libPath
// wxDirDialog dlg( this, FMT_CREATE_LIB, fn.GetPath(), wxDD_DEFAULT_STYLE );
// prompt user for footprint library name, ending by ".pretty"
// Because there are constraints for the directory name to create,
// (the name should have the extension ".pretty", and the folder cannot be inside
// a footprint library), we do not use the standard wxDirDialog.
wxString initialPath = wxPathOnly( Prj().GetProjectFullName() );
DIALOG_SELECT_PRETTY_LIB dlg( this, initialPath );
@ -411,21 +402,11 @@ wxString FOOTPRINT_EDIT_FRAME::CreateNewLibrary()
if( dlg.ShowModal() != wxID_OK )
return wxEmptyString;
fn = dlg.GetPath();
wxString libPath = dlg.GetFullPrettyLibName();
if( config ) // Save file path without filename, save user typing.
{
config->Write( EXPORT_IMPORT_LASTPATH_KEY, fn.GetPath() );
}
// wildcard's filter index has legacy in position 0.
// We can save fp libs only using IO_MGR::KICAD format (.pretty libraries)
IO_MGR::PCB_FILE_T piType = IO_MGR::KICAD;
// wxFileDialog does not supply nor enforce the file extension, add it here.
fn.SetExt( KiCadFootprintLibPathExtension );
wxString libPath = fn.GetFullPath();
try
{
PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
@ -537,7 +518,7 @@ void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aNewModulesOnly )
{
if( GetBoard()->m_Modules == NULL )
{
DisplayInfoMessage( this, FMT_NO_MODULES );
DisplayInfoMessage( this, _( "No footprints to archive!" ) );
return;
}