2012-06-09 09:38:58 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2016-07-19 17:35:25 +00:00
|
|
|
* Copyright (C) 2016 Mario Luzeiro <mrluzeiro@ua.pt>
|
2018-01-14 13:24:58 +00:00
|
|
|
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2015-02-02 16:43:34 +00:00
|
|
|
* Copyright (C) 2015 Dick Hollenbeck, dick@softplc.com
|
2023-03-30 11:49:23 +00:00
|
|
|
* Copyright (C) 2004-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-06-09 09:38:58 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2021-08-05 12:03:59 +00:00
|
|
|
#include <3d_viewer/eda_3d_viewer_frame.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <bitmaps.h>
|
|
|
|
#include <board_commit.h>
|
|
|
|
#include <board_design_settings.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <confirm.h>
|
2020-12-17 13:12:18 +00:00
|
|
|
#include <dialogs/dialog_text_entry.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <filename_resolver.h>
|
|
|
|
#include <pcb_edit_frame.h>
|
|
|
|
#include <pcbnew_settings.h>
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
#include <pgm_base.h>
|
2023-09-28 03:15:54 +00:00
|
|
|
#include <project_pcb.h>
|
2021-12-16 14:39:58 +00:00
|
|
|
#include <kiplatform/ui.h>
|
2020-09-01 02:00:38 +00:00
|
|
|
#include <widgets/grid_text_button_helpers.h>
|
2017-11-23 13:05:26 +00:00
|
|
|
#include <widgets/text_ctrl_eval.h>
|
2022-12-13 20:47:28 +00:00
|
|
|
#include <widgets/std_bitmap_button.h>
|
2020-09-01 02:00:38 +00:00
|
|
|
#include <settings/settings_manager.h>
|
2021-07-28 19:54:20 +00:00
|
|
|
#include <panel_fp_properties_3d_model.h>
|
2022-12-13 20:47:28 +00:00
|
|
|
#include <dialogs/3d_cache_dialogs.h>
|
|
|
|
#include <dialogs/panel_preview_3d_model.h>
|
2020-10-14 23:37:26 +00:00
|
|
|
#include <dialog_footprint_properties.h>
|
2018-05-30 10:52:19 +00:00
|
|
|
|
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
int DIALOG_FOOTPRINT_PROPERTIES::m_page = 0; // remember the last open page during session
|
2017-04-04 14:05:01 +00:00
|
|
|
|
2020-09-01 02:00:38 +00:00
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
DIALOG_FOOTPRINT_PROPERTIES::DIALOG_FOOTPRINT_PROPERTIES( PCB_EDIT_FRAME* aParent,
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* aFootprint ) :
|
2021-06-19 17:28:45 +00:00
|
|
|
DIALOG_FOOTPRINT_PROPERTIES_BASE( aParent ),
|
2021-07-28 19:54:20 +00:00
|
|
|
m_frame( aParent ),
|
|
|
|
m_footprint( aFootprint ),
|
2021-06-19 17:28:45 +00:00
|
|
|
m_posX( aParent, m_XPosLabel, m_ModPositionX, m_XPosUnit ),
|
|
|
|
m_posY( aParent, m_YPosLabel, m_ModPositionY, m_YPosUnit ),
|
2021-12-05 21:56:55 +00:00
|
|
|
m_orientation( aParent, m_orientationLabel, m_orientationCtrl, nullptr ),
|
2021-06-19 17:28:45 +00:00
|
|
|
m_netClearance( aParent, m_NetClearanceLabel, m_NetClearanceCtrl, m_NetClearanceUnits ),
|
2021-08-06 14:26:08 +00:00
|
|
|
m_solderMask( aParent, m_SolderMaskMarginLabel, m_SolderMaskMarginCtrl,
|
|
|
|
m_SolderMaskMarginUnits ),
|
|
|
|
m_solderPaste( aParent, m_SolderPasteMarginLabel, m_SolderPasteMarginCtrl,
|
|
|
|
m_SolderPasteMarginUnits ),
|
|
|
|
m_solderPasteRatio( aParent, m_PasteMarginRatioLabel, m_PasteMarginRatioCtrl,
|
|
|
|
m_PasteMarginRatioUnits ),
|
2021-09-14 12:28:45 +00:00
|
|
|
m_returnValue( FP_PROPS_CANCEL ),
|
2022-10-11 23:38:01 +00:00
|
|
|
m_initialized( false ),
|
|
|
|
m_gridSize( 0, 0 ),
|
|
|
|
m_lastRequestedSize( 0, 0 )
|
2009-08-11 10:27:21 +00:00
|
|
|
{
|
2021-07-28 19:54:20 +00:00
|
|
|
// Create the 3D models page
|
|
|
|
m_3dPanel = new PANEL_FP_PROPERTIES_3D_MODEL( m_frame, m_footprint, this, m_NoteBook );
|
|
|
|
m_NoteBook->AddPage( m_3dPanel, _("3D Models"), false );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-07-06 14:41:29 +00:00
|
|
|
// Configure display origin transforms
|
|
|
|
m_posX.SetCoordType( ORIGIN_TRANSFORMS::ABS_X_COORD );
|
|
|
|
m_posY.SetCoordType( ORIGIN_TRANSFORMS::ABS_Y_COORD );
|
|
|
|
|
2023-06-13 16:56:24 +00:00
|
|
|
m_fields = new FP_TEXT_GRID_TABLE( m_frame, this );
|
2009-08-11 10:27:21 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
m_delayedErrorMessage = wxEmptyString;
|
|
|
|
m_delayedFocusGrid = nullptr;
|
|
|
|
m_delayedFocusRow = -1;
|
|
|
|
m_delayedFocusColumn = -1;
|
2021-08-04 14:47:41 +00:00
|
|
|
m_initialFocus = false;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2011-09-11 11:38:01 +00:00
|
|
|
// Give an icon
|
|
|
|
wxIcon icon;
|
2021-03-08 02:59:07 +00:00
|
|
|
icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_modedit ) );
|
2011-09-11 11:38:01 +00:00
|
|
|
SetIcon( icon );
|
2009-08-11 10:27:21 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
// Give a bit more room for combobox editors
|
|
|
|
m_itemsGrid->SetDefaultRowSize( m_itemsGrid->GetDefaultRowSize() + 4 );
|
|
|
|
|
2023-05-24 12:39:25 +00:00
|
|
|
m_itemsGrid->SetTable( m_fields );
|
2018-03-28 17:14:04 +00:00
|
|
|
m_itemsGrid->PushEventHandler( new GRID_TRICKS( m_itemsGrid ) );
|
|
|
|
|
|
|
|
// Show/hide text item columns according to the user's preference
|
2023-04-13 12:45:22 +00:00
|
|
|
if( PCBNEW_SETTINGS* cfg = m_frame->GetPcbNewSettings() )
|
|
|
|
m_itemsGrid->ShowHideColumns( cfg->m_FootprintTextShownColumns );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
2021-12-05 21:56:55 +00:00
|
|
|
m_orientation.SetUnits( EDA_UNITS::DEGREES );
|
|
|
|
m_orientation.SetPrecision( 3 );
|
|
|
|
|
|
|
|
// Set predefined rotations in combo dropdown, according to the locale floating point
|
|
|
|
// separator notation
|
|
|
|
double rot_list[] = { 0.0, 90.0, -90.0, 180.0 };
|
|
|
|
|
|
|
|
for( size_t ii = 0; ii < m_orientationCtrl->GetCount() && ii < 4; ++ii )
|
|
|
|
m_orientationCtrl->SetString( ii, wxString::Format( "%.1f", rot_list[ii] ) );
|
2016-04-10 12:59:23 +00:00
|
|
|
|
2020-05-05 13:20:44 +00:00
|
|
|
// Set font size for items showing long strings:
|
2021-09-11 19:07:33 +00:00
|
|
|
wxFont infoFont = KIUI::GetInfoFont( this );
|
2020-07-24 19:50:46 +00:00
|
|
|
m_libraryIDLabel->SetFont( infoFont );
|
2020-03-13 17:28:17 +00:00
|
|
|
m_tcLibraryID->SetFont( infoFont );
|
|
|
|
|
2019-08-21 14:31:52 +00:00
|
|
|
infoFont.SetStyle( wxFONTSTYLE_ITALIC );
|
2021-09-10 17:35:45 +00:00
|
|
|
m_staticTextInfoCopper->SetFont( infoFont );
|
|
|
|
m_staticTextInfoPaste->SetFont( infoFont );
|
2018-05-04 16:20:41 +00:00
|
|
|
|
2015-02-02 16:43:34 +00:00
|
|
|
m_NoteBook->SetSelection( m_page );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
|
|
|
if( m_page == 0 )
|
|
|
|
{
|
|
|
|
m_delayedFocusGrid = m_itemsGrid;
|
|
|
|
m_delayedFocusRow = 0;
|
|
|
|
m_delayedFocusColumn = 0;
|
|
|
|
}
|
2021-07-28 19:54:20 +00:00
|
|
|
else if( m_page == 1 )
|
2021-06-29 17:27:05 +00:00
|
|
|
{
|
2018-03-28 17:14:04 +00:00
|
|
|
SetInitialFocus( m_NetClearanceCtrl );
|
2021-06-29 17:27:05 +00:00
|
|
|
}
|
2018-03-28 17:14:04 +00:00
|
|
|
|
2021-08-06 14:26:08 +00:00
|
|
|
m_solderPaste.SetNegativeZero();
|
|
|
|
|
|
|
|
m_solderPasteRatio.SetUnits( EDA_UNITS::PERCENT );
|
|
|
|
m_solderPasteRatio.SetNegativeZero();
|
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
// Configure button logos
|
2023-10-21 18:56:19 +00:00
|
|
|
m_bpAdd->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
|
|
|
|
m_bpDelete->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
|
2009-08-11 10:27:21 +00:00
|
|
|
|
2023-07-09 11:19:43 +00:00
|
|
|
m_tcLibraryID->SetBackgroundColour( KIPLATFORM::UI::GetDialogBGColour() );
|
|
|
|
|
2022-02-26 16:38:41 +00:00
|
|
|
// We can't set the tab order through wxWidgets due to shortcomings in their mnemonics
|
|
|
|
// implementation on MSW
|
|
|
|
m_tabOrder = {
|
|
|
|
m_itemsGrid,
|
|
|
|
m_ModPositionX,
|
|
|
|
m_ModPositionY,
|
|
|
|
m_orientationCtrl,
|
|
|
|
m_BoardSideCtrl,
|
|
|
|
m_cbLocked,
|
|
|
|
m_componentType,
|
|
|
|
m_boardOnly,
|
|
|
|
m_excludeFromPosFiles,
|
|
|
|
m_excludeFromBOM,
|
|
|
|
m_noCourtyards,
|
2023-04-10 17:10:42 +00:00
|
|
|
m_cbDNP,
|
2022-02-26 16:38:41 +00:00
|
|
|
m_NetClearanceCtrl,
|
|
|
|
m_SolderMaskMarginCtrl,
|
|
|
|
m_allowSolderMaskBridges,
|
|
|
|
m_SolderPasteMarginCtrl,
|
|
|
|
m_PasteMarginRatioCtrl,
|
|
|
|
m_ZoneConnectionChoice
|
|
|
|
};
|
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons();
|
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2021-09-14 12:28:45 +00:00
|
|
|
m_initialized = true;
|
2018-03-28 17:14:04 +00:00
|
|
|
}
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2015-02-02 16:43:34 +00:00
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
DIALOG_FOOTPRINT_PROPERTIES::~DIALOG_FOOTPRINT_PROPERTIES()
|
2009-08-11 10:27:21 +00:00
|
|
|
{
|
2023-10-16 21:04:01 +00:00
|
|
|
PCBNEW_SETTINGS* cfg = nullptr;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
cfg = m_frame->GetPcbNewSettings();
|
|
|
|
}
|
|
|
|
catch( const std::runtime_error& e )
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( e.what() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( cfg )
|
|
|
|
{
|
2023-04-13 12:45:22 +00:00
|
|
|
cfg->m_FootprintTextShownColumns = m_itemsGrid->GetShownColumnsAsString();
|
2023-10-16 21:04:01 +00:00
|
|
|
}
|
2018-03-28 17:14:04 +00:00
|
|
|
|
|
|
|
// Prevents crash bug in wxGrid's d'tor
|
2023-05-24 12:39:25 +00:00
|
|
|
m_itemsGrid->DestroyTable( m_fields );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
|
|
|
// Delete the GRID_TRICKS.
|
|
|
|
m_itemsGrid->PopEventHandler( true );
|
2009-08-11 10:27:21 +00:00
|
|
|
|
2016-02-21 00:54:34 +00:00
|
|
|
// free the memory used by all models, otherwise models which were
|
|
|
|
// browsed but not used would consume memory
|
2023-09-28 03:15:54 +00:00
|
|
|
PROJECT_PCB::Get3DCacheManager( &Prj() )->FlushCache( false );
|
2016-02-21 00:54:34 +00:00
|
|
|
|
2016-06-14 10:08:35 +00:00
|
|
|
// the GL canvas has to be visible before it is destroyed
|
|
|
|
m_page = m_NoteBook->GetSelection();
|
|
|
|
m_NoteBook->SetSelection( 1 );
|
2009-11-04 19:08:08 +00:00
|
|
|
}
|
2009-08-11 10:27:21 +00:00
|
|
|
|
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
void DIALOG_FOOTPRINT_PROPERTIES::EditFootprint( wxCommandEvent& )
|
2009-08-11 10:27:21 +00:00
|
|
|
{
|
2021-03-01 20:36:18 +00:00
|
|
|
if( TransferDataFromWindow() )
|
|
|
|
{
|
|
|
|
m_returnValue = FP_PROPS_EDIT_BOARD_FP;
|
|
|
|
Close();
|
|
|
|
}
|
2018-10-15 14:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
void DIALOG_FOOTPRINT_PROPERTIES::EditLibraryFootprint( wxCommandEvent& )
|
2018-10-15 14:28:53 +00:00
|
|
|
{
|
2021-03-01 20:36:18 +00:00
|
|
|
if( TransferDataFromWindow() )
|
|
|
|
{
|
|
|
|
m_returnValue = FP_PROPS_EDIT_LIBRARY_FP;
|
|
|
|
Close();
|
|
|
|
}
|
2009-08-11 10:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
void DIALOG_FOOTPRINT_PROPERTIES::UpdateFootprint( wxCommandEvent& )
|
2018-01-12 19:36:15 +00:00
|
|
|
{
|
2021-03-01 20:36:18 +00:00
|
|
|
if( TransferDataFromWindow() )
|
|
|
|
{
|
|
|
|
m_returnValue = FP_PROPS_UPDATE_FP;
|
|
|
|
Close();
|
|
|
|
}
|
2018-01-12 19:36:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
void DIALOG_FOOTPRINT_PROPERTIES::ChangeFootprint( wxCommandEvent& )
|
2009-08-11 10:27:21 +00:00
|
|
|
{
|
2021-03-01 20:36:18 +00:00
|
|
|
if( TransferDataFromWindow() )
|
|
|
|
{
|
|
|
|
m_returnValue = FP_PROPS_CHANGE_FP;
|
|
|
|
Close();
|
|
|
|
}
|
2009-08-11 10:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
bool DIALOG_FOOTPRINT_PROPERTIES::TransferDataToWindow()
|
2018-03-28 17:14:04 +00:00
|
|
|
{
|
|
|
|
if( !wxDialog::TransferDataToWindow() )
|
|
|
|
return false;
|
2009-08-11 10:27:21 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
if( !m_PanelGeneral->TransferDataToWindow() )
|
|
|
|
return false;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-07-28 19:54:20 +00:00
|
|
|
// Add the models to the panel
|
|
|
|
if( !m_3dPanel->TransferDataToWindow() )
|
2018-03-28 17:14:04 +00:00
|
|
|
return false;
|
|
|
|
|
2023-05-24 12:39:25 +00:00
|
|
|
// Footprint Fields
|
|
|
|
for( PCB_FIELD* field : m_footprint->GetFields() )
|
|
|
|
m_fields->push_back( field );
|
2009-08-11 10:27:21 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
// notify the grid
|
2023-05-24 12:39:25 +00:00
|
|
|
wxGridTableMessage tmsg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
|
|
|
|
m_fields->GetNumberRows() );
|
2018-03-28 17:14:04 +00:00
|
|
|
m_itemsGrid->ProcessTableMessage( tmsg );
|
2009-08-11 10:27:21 +00:00
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
// Footprint Properties
|
2009-08-11 10:27:21 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
m_posX.SetValue( m_footprint->GetPosition().x );
|
|
|
|
m_posY.SetValue( m_footprint->GetPosition().y );
|
2009-08-11 10:27:21 +00:00
|
|
|
|
2020-03-13 17:28:17 +00:00
|
|
|
m_BoardSideCtrl->SetSelection( (m_footprint->GetLayer() == B_Cu) ? 1 : 0 );
|
|
|
|
|
2022-04-10 21:43:09 +00:00
|
|
|
EDA_ANGLE orientation = m_footprint->GetOrientation();
|
|
|
|
m_orientation.SetAngleValue( orientation.Normalize180() );
|
2012-08-21 10:45:54 +00:00
|
|
|
|
2021-12-05 21:56:55 +00:00
|
|
|
m_cbLocked->SetValue( m_footprint->IsLocked() );
|
|
|
|
m_cbLocked->SetToolTip( _( "Locked footprints cannot be freely moved and oriented on the "
|
|
|
|
"canvas and can only be selected when the 'Locked items' checkbox "
|
|
|
|
"is enabled in the selection filter." ) );
|
2009-08-11 10:27:21 +00:00
|
|
|
|
2020-11-13 02:09:34 +00:00
|
|
|
if( m_footprint->GetAttributes() & FP_THROUGH_HOLE )
|
2020-08-26 21:43:38 +00:00
|
|
|
m_componentType->SetSelection( 0 );
|
2020-11-13 02:09:34 +00:00
|
|
|
else if( m_footprint->GetAttributes() & FP_SMD )
|
2020-08-26 21:43:38 +00:00
|
|
|
m_componentType->SetSelection( 1 );
|
|
|
|
else
|
|
|
|
m_componentType->SetSelection( 2 );
|
|
|
|
|
2020-11-13 02:09:34 +00:00
|
|
|
m_boardOnly->SetValue( m_footprint->GetAttributes() & FP_BOARD_ONLY );
|
|
|
|
m_excludeFromPosFiles->SetValue( m_footprint->GetAttributes() & FP_EXCLUDE_FROM_POS_FILES );
|
|
|
|
m_excludeFromBOM->SetValue( m_footprint->GetAttributes() & FP_EXCLUDE_FROM_BOM );
|
2021-12-07 19:24:26 +00:00
|
|
|
m_noCourtyards->SetValue( m_footprint->GetAttributes() & FP_ALLOW_MISSING_COURTYARD );
|
2023-04-10 17:10:42 +00:00
|
|
|
m_cbDNP->SetValue( m_footprint->GetAttributes() & FP_DNP );
|
2013-03-04 12:08:35 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
// Local Clearances
|
2009-08-11 10:27:21 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
m_netClearance.SetValue( m_footprint->GetLocalClearance() );
|
|
|
|
m_solderMask.SetValue( m_footprint->GetLocalSolderMaskMargin() );
|
|
|
|
m_solderPaste.SetValue( m_footprint->GetLocalSolderPasteMargin() );
|
2021-08-06 14:26:08 +00:00
|
|
|
m_solderPasteRatio.SetDoubleValue( m_footprint->GetLocalSolderPasteMarginRatio() * 100.0 );
|
2021-08-12 16:58:30 +00:00
|
|
|
m_allowSolderMaskBridges->SetValue( m_footprint->GetAttributes() & FP_ALLOW_SOLDERMASK_BRIDGES );
|
2009-08-17 19:04:51 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
switch( m_footprint->GetZoneConnection() )
|
2009-08-17 19:04:51 +00:00
|
|
|
{
|
2018-03-28 17:14:04 +00:00
|
|
|
default:
|
2020-07-31 15:05:46 +00:00
|
|
|
case ZONE_CONNECTION::INHERITED: m_ZoneConnectionChoice->SetSelection( 0 ); break;
|
|
|
|
case ZONE_CONNECTION::FULL: m_ZoneConnectionChoice->SetSelection( 1 ); break;
|
|
|
|
case ZONE_CONNECTION::THERMAL: m_ZoneConnectionChoice->SetSelection( 2 ); break;
|
|
|
|
case ZONE_CONNECTION::NONE: m_ZoneConnectionChoice->SetSelection( 3 ); break;
|
2009-08-17 19:04:51 +00:00
|
|
|
}
|
2016-01-16 06:49:28 +00:00
|
|
|
|
2020-05-05 13:20:44 +00:00
|
|
|
// Show the footprint's FPID.
|
2019-11-16 17:09:48 +00:00
|
|
|
m_tcLibraryID->SetValue( m_footprint->GetFPID().Format() );
|
2020-03-13 17:28:17 +00:00
|
|
|
|
2019-02-02 04:03:45 +00:00
|
|
|
for( int col = 0; col < m_itemsGrid->GetNumberCols(); col++ )
|
2019-02-10 08:49:42 +00:00
|
|
|
{
|
2022-08-18 16:56:36 +00:00
|
|
|
m_itemsGrid->SetColMinimalWidth( col, m_itemsGrid->GetVisibleWidth( col, true, false ) );
|
|
|
|
|
2021-02-23 17:24:26 +00:00
|
|
|
// Adjust the column size.
|
2022-08-18 16:56:36 +00:00
|
|
|
int col_size = m_itemsGrid->GetVisibleWidth( col );
|
2019-02-10 08:49:42 +00:00
|
|
|
|
2021-02-23 17:24:26 +00:00
|
|
|
if( col == FPT_LAYER ) // This one's a drop-down. Check all possible values.
|
|
|
|
{
|
|
|
|
BOARD* board = m_footprint->GetBoard();
|
|
|
|
|
|
|
|
for( PCB_LAYER_ID layer : board->GetEnabledLayers().Seq() )
|
|
|
|
col_size = std::max( col_size, GetTextExtent( board->GetLayerName( layer ) ).x );
|
|
|
|
|
|
|
|
// And the swatch:
|
2019-02-10 08:49:42 +00:00
|
|
|
col_size += 20;
|
2021-02-23 17:24:26 +00:00
|
|
|
}
|
2019-02-10 08:49:42 +00:00
|
|
|
|
2019-02-17 14:09:35 +00:00
|
|
|
if( m_itemsGrid->IsColShown( col ) )
|
|
|
|
m_itemsGrid->SetColSize( col, col_size );
|
2019-02-10 08:49:42 +00:00
|
|
|
}
|
2019-02-02 04:03:45 +00:00
|
|
|
|
2023-05-24 12:39:25 +00:00
|
|
|
m_itemsGrid->SetRowLabelSize( 0 );
|
2019-02-02 04:03:45 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
Layout();
|
2021-12-16 14:39:58 +00:00
|
|
|
adjustGridColumns();
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
return true;
|
2009-08-11 10:27:21 +00:00
|
|
|
}
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
bool DIALOG_FOOTPRINT_PROPERTIES::Validate()
|
2016-04-10 12:59:23 +00:00
|
|
|
{
|
2018-08-15 13:29:19 +00:00
|
|
|
if( !m_itemsGrid->CommitPendingChanges() )
|
|
|
|
return false;
|
2018-03-28 17:14:04 +00:00
|
|
|
|
|
|
|
if( !DIALOG_SHIM::Validate() )
|
2016-04-10 12:59:23 +00:00
|
|
|
return false;
|
|
|
|
|
2022-10-05 16:42:03 +00:00
|
|
|
// Validate texts.
|
2023-05-24 12:39:25 +00:00
|
|
|
for( size_t i = 0; i < m_fields->size(); ++i )
|
2016-08-24 15:18:51 +00:00
|
|
|
{
|
2023-05-24 12:39:25 +00:00
|
|
|
PCB_FIELD* field = m_fields->at( i );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
2023-05-24 12:39:25 +00:00
|
|
|
// Check for missing field names.
|
|
|
|
if( field->GetName( false ).IsEmpty() )
|
2018-03-28 17:14:04 +00:00
|
|
|
{
|
2023-05-24 12:39:25 +00:00
|
|
|
m_delayedFocusGrid = m_itemsGrid;
|
|
|
|
m_delayedErrorMessage = wxString::Format( _( "Fields must have a name." ) );
|
|
|
|
m_delayedFocusColumn = FPT_NAME;
|
|
|
|
m_delayedFocusRow = i;
|
2022-10-05 16:42:03 +00:00
|
|
|
|
2023-05-24 12:39:25 +00:00
|
|
|
return false;
|
2022-10-05 16:42:03 +00:00
|
|
|
}
|
|
|
|
|
2023-06-03 15:59:00 +00:00
|
|
|
int minSize = pcbIUScale.MilsToIU( TEXT_MIN_SIZE_MILS );
|
|
|
|
int maxSize = pcbIUScale.MilsToIU( TEXT_MAX_SIZE_MILS );
|
2022-10-05 16:42:03 +00:00
|
|
|
int width = m_frame->ValueFromString( m_itemsGrid->GetCellValue( i, FPT_WIDTH ) );
|
2023-06-03 15:59:00 +00:00
|
|
|
int height = m_frame->ValueFromString( m_itemsGrid->GetCellValue( i, FPT_HEIGHT ) );
|
2022-10-05 16:42:03 +00:00
|
|
|
|
2023-06-03 15:59:00 +00:00
|
|
|
if( width < minSize )
|
2022-10-05 16:42:03 +00:00
|
|
|
{
|
2023-06-03 15:59:00 +00:00
|
|
|
wxString min = m_frame->StringFromValue( minSize, true );
|
2022-10-05 16:42:03 +00:00
|
|
|
|
|
|
|
m_itemsGrid->SetCellValue( i, FPT_WIDTH, min );
|
|
|
|
|
|
|
|
m_delayedFocusGrid = m_itemsGrid;
|
|
|
|
m_delayedErrorMessage = wxString::Format( _( "Text width must be at least %s." ), min );
|
|
|
|
m_delayedFocusColumn = FPT_WIDTH;
|
|
|
|
m_delayedFocusRow = i;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2023-06-03 15:59:00 +00:00
|
|
|
else if( width > maxSize )
|
2022-10-05 16:42:03 +00:00
|
|
|
{
|
2023-06-03 15:59:00 +00:00
|
|
|
wxString max = m_frame->StringFromValue( maxSize, true );
|
2022-10-05 16:42:03 +00:00
|
|
|
|
|
|
|
m_itemsGrid->SetCellValue( i, FPT_WIDTH, max );
|
|
|
|
|
|
|
|
m_delayedFocusGrid = m_itemsGrid;
|
|
|
|
m_delayedErrorMessage = wxString::Format( _( "Text width must be at most %s." ), max );
|
|
|
|
m_delayedFocusColumn = FPT_WIDTH;
|
|
|
|
m_delayedFocusRow = i;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-06-03 15:59:00 +00:00
|
|
|
if( height < minSize )
|
2022-10-05 16:42:03 +00:00
|
|
|
{
|
2023-06-03 15:59:00 +00:00
|
|
|
wxString min = m_frame->StringFromValue( minSize, true );
|
2022-10-05 16:42:03 +00:00
|
|
|
|
|
|
|
m_itemsGrid->SetCellValue( i, FPT_HEIGHT, min );
|
|
|
|
|
|
|
|
m_delayedFocusGrid = m_itemsGrid;
|
|
|
|
m_delayedErrorMessage = wxString::Format( _( "Text height must be at least %s." ), min );
|
|
|
|
m_delayedFocusColumn = FPT_HEIGHT;
|
|
|
|
m_delayedFocusRow = i;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2023-06-03 15:59:00 +00:00
|
|
|
else if( height > maxSize )
|
2022-10-05 16:42:03 +00:00
|
|
|
{
|
2023-06-03 15:59:00 +00:00
|
|
|
wxString max = m_frame->StringFromValue( maxSize, true );
|
2022-10-05 16:42:03 +00:00
|
|
|
|
|
|
|
m_itemsGrid->SetCellValue( i, FPT_HEIGHT, max );
|
|
|
|
|
|
|
|
m_delayedFocusGrid = m_itemsGrid;
|
|
|
|
m_delayedErrorMessage = wxString::Format( _( "Text height must be at most %s." ), max );
|
|
|
|
m_delayedFocusColumn = FPT_HEIGHT;
|
|
|
|
m_delayedFocusRow = i;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test for acceptable values for thickness and size and clamp if fails
|
2023-05-24 12:39:25 +00:00
|
|
|
int maxPenWidth = Clamp_Text_PenSize( field->GetTextThickness(), field->GetTextSize() );
|
2022-10-05 16:42:03 +00:00
|
|
|
|
2023-05-24 12:39:25 +00:00
|
|
|
if( field->GetTextThickness() > maxPenWidth )
|
2022-10-05 16:42:03 +00:00
|
|
|
{
|
|
|
|
wxString clamped = m_frame->StringFromValue( maxPenWidth, true );
|
|
|
|
|
|
|
|
m_itemsGrid->SetCellValue( i, FPT_THICKNESS, clamped );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
2018-11-12 17:07:22 +00:00
|
|
|
m_delayedFocusGrid = m_itemsGrid;
|
2022-10-05 16:42:03 +00:00
|
|
|
m_delayedErrorMessage = wxString::Format( _( "Text thickness is too large for the "
|
|
|
|
"text size.\n"
|
|
|
|
"It will be clamped at %s." ),
|
|
|
|
clamped );
|
|
|
|
m_delayedFocusColumn = FPT_THICKNESS;
|
2018-03-28 17:14:04 +00:00
|
|
|
m_delayedFocusRow = i;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-24 15:18:51 +00:00
|
|
|
}
|
2016-04-10 12:59:23 +00:00
|
|
|
|
2018-11-29 18:59:38 +00:00
|
|
|
if( !m_netClearance.Validate( 0, INT_MAX ) )
|
2018-03-28 17:14:04 +00:00
|
|
|
return false;
|
2016-04-10 12:59:23 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
bool DIALOG_FOOTPRINT_PROPERTIES::TransferDataFromWindow()
|
2009-08-11 10:27:21 +00:00
|
|
|
{
|
2018-03-28 17:14:04 +00:00
|
|
|
if( !Validate() )
|
|
|
|
return false;
|
2009-08-11 10:27:21 +00:00
|
|
|
|
2020-11-28 11:43:32 +00:00
|
|
|
if( !m_itemsGrid->CommitPendingChanges() )
|
2016-04-10 12:59:23 +00:00
|
|
|
return false;
|
|
|
|
|
2021-07-28 19:54:20 +00:00
|
|
|
// This only commits the editor, model updating is done below so it is inside
|
|
|
|
// the commit
|
|
|
|
if( !m_3dPanel->TransferDataFromWindow() )
|
2016-04-10 12:59:23 +00:00
|
|
|
return false;
|
2018-03-28 17:14:04 +00:00
|
|
|
|
2019-06-13 17:28:55 +00:00
|
|
|
auto view = m_frame->GetCanvas()->GetView();
|
2018-03-28 17:14:04 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
|
|
|
commit.Modify( m_footprint );
|
|
|
|
|
2023-05-24 12:39:25 +00:00
|
|
|
// Update fields
|
|
|
|
size_t i = 0;
|
2019-02-09 10:21:09 +00:00
|
|
|
|
2023-05-24 12:39:25 +00:00
|
|
|
for( PCB_FIELD* field : m_footprint->GetFields() )
|
2018-02-14 16:46:35 +00:00
|
|
|
{
|
2023-05-24 12:39:25 +00:00
|
|
|
// copy grid table entries till we run out, then delete any remaining texts
|
|
|
|
if( i < m_fields->size() )
|
|
|
|
field = m_fields->at( i++ );
|
|
|
|
else
|
|
|
|
field->DeleteStructure();
|
2018-02-14 16:46:35 +00:00
|
|
|
}
|
|
|
|
|
2023-06-20 14:31:13 +00:00
|
|
|
// if there are still grid table entries, create new fields for them
|
2023-05-24 12:39:25 +00:00
|
|
|
while( i < m_fields->size() )
|
2009-08-11 10:27:21 +00:00
|
|
|
{
|
2023-06-20 14:31:13 +00:00
|
|
|
view->Add( m_footprint->AddField( *m_fields->at( i++ ) ) );
|
2009-08-11 10:27:21 +00:00
|
|
|
}
|
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
// Initialize masks clearances
|
2018-03-28 17:14:04 +00:00
|
|
|
m_footprint->SetLocalClearance( m_netClearance.GetValue() );
|
|
|
|
m_footprint->SetLocalSolderMaskMargin( m_solderMask.GetValue() );
|
|
|
|
m_footprint->SetLocalSolderPasteMargin( m_solderPaste.GetValue() );
|
2021-08-06 14:26:08 +00:00
|
|
|
m_footprint->SetLocalSolderPasteMarginRatio( m_solderPasteRatio.GetDoubleValue() / 100.0 );
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2012-02-24 23:23:46 +00:00
|
|
|
switch( m_ZoneConnectionChoice->GetSelection() )
|
|
|
|
{
|
|
|
|
default:
|
2020-08-26 21:43:38 +00:00
|
|
|
case 0: m_footprint->SetZoneConnection( ZONE_CONNECTION::INHERITED ); break;
|
|
|
|
case 1: m_footprint->SetZoneConnection( ZONE_CONNECTION::FULL ); break;
|
|
|
|
case 2: m_footprint->SetZoneConnection( ZONE_CONNECTION::THERMAL ); break;
|
|
|
|
case 3: m_footprint->SetZoneConnection( ZONE_CONNECTION::NONE ); break;
|
2012-02-24 23:23:46 +00:00
|
|
|
}
|
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
// Set Footprint Position
|
2023-02-19 03:40:07 +00:00
|
|
|
VECTOR2I pos( m_posX.GetValue(), m_posY.GetValue() );
|
2020-10-14 23:37:26 +00:00
|
|
|
m_footprint->SetPosition( pos );
|
2021-12-05 21:56:55 +00:00
|
|
|
m_footprint->SetLocked( m_cbLocked->GetValue() );
|
2009-08-11 10:27:21 +00:00
|
|
|
|
2020-08-26 21:43:38 +00:00
|
|
|
int attributes = 0;
|
|
|
|
|
|
|
|
switch( m_componentType->GetSelection() )
|
2009-08-11 10:27:21 +00:00
|
|
|
{
|
2020-11-13 02:09:34 +00:00
|
|
|
case 0: attributes |= FP_THROUGH_HOLE; break;
|
|
|
|
case 1: attributes |= FP_SMD; break;
|
|
|
|
default: break;
|
2009-08-11 10:27:21 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 21:43:38 +00:00
|
|
|
if( m_boardOnly->GetValue() )
|
2020-11-13 02:09:34 +00:00
|
|
|
attributes |= FP_BOARD_ONLY;
|
2020-08-26 21:43:38 +00:00
|
|
|
|
|
|
|
if( m_excludeFromPosFiles->GetValue() )
|
2020-11-13 02:09:34 +00:00
|
|
|
attributes |= FP_EXCLUDE_FROM_POS_FILES;
|
2020-08-26 21:43:38 +00:00
|
|
|
|
|
|
|
if( m_excludeFromBOM->GetValue() )
|
2020-11-13 02:09:34 +00:00
|
|
|
attributes |= FP_EXCLUDE_FROM_BOM;
|
2020-08-26 21:43:38 +00:00
|
|
|
|
2023-04-10 17:10:42 +00:00
|
|
|
if( m_cbDNP->GetValue() )
|
|
|
|
attributes |= FP_DNP;
|
|
|
|
|
2021-12-07 19:24:26 +00:00
|
|
|
if( m_noCourtyards->GetValue() )
|
|
|
|
attributes |= FP_ALLOW_MISSING_COURTYARD;
|
|
|
|
|
2021-08-12 16:58:30 +00:00
|
|
|
if( m_allowSolderMaskBridges->GetValue() )
|
|
|
|
attributes |= FP_ALLOW_SOLDERMASK_BRIDGES;
|
|
|
|
|
2020-08-26 21:43:38 +00:00
|
|
|
m_footprint->SetAttributes( attributes );
|
|
|
|
|
2022-04-10 21:43:09 +00:00
|
|
|
EDA_ANGLE orient = m_orientation.GetAngleValue().Normalize();
|
2011-12-22 13:28:11 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
if( m_footprint->GetOrientation() != orient )
|
2022-01-13 19:32:00 +00:00
|
|
|
m_footprint->Rotate( m_footprint->GetPosition(), orient - m_footprint->GetOrientation() );
|
2010-05-03 15:24:54 +00:00
|
|
|
|
|
|
|
// Set component side, that also have effect on the fields positions on board
|
2012-01-22 17:20:22 +00:00
|
|
|
bool change_layer = false;
|
2018-08-15 13:29:53 +00:00
|
|
|
if( m_BoardSideCtrl->GetSelection() == 0 ) // layer req = COMPONENT
|
2010-05-03 15:24:54 +00:00
|
|
|
{
|
2018-03-28 17:14:04 +00:00
|
|
|
if( m_footprint->GetLayer() == B_Cu )
|
2012-01-22 17:20:22 +00:00
|
|
|
change_layer = true;
|
2010-05-03 15:24:54 +00:00
|
|
|
}
|
2018-03-28 17:14:04 +00:00
|
|
|
else if( m_footprint->GetLayer() == F_Cu )
|
2012-01-22 17:20:22 +00:00
|
|
|
change_layer = true;
|
2010-05-03 15:24:54 +00:00
|
|
|
|
|
|
|
if( change_layer )
|
2022-07-24 15:49:46 +00:00
|
|
|
m_footprint->Flip( m_footprint->GetPosition(), m_frame->GetPcbNewSettings()->m_FlipLeftRight );
|
2016-08-05 19:30:23 +00:00
|
|
|
|
2021-07-28 19:54:20 +00:00
|
|
|
// Copy the models from the panel to the footprint
|
|
|
|
std::vector<FP_3DMODEL>& panelList = m_3dPanel->GetModelList();
|
2021-07-11 11:49:36 +00:00
|
|
|
std::vector<FP_3DMODEL>* fpList = &m_footprint->Models();
|
2021-07-28 19:54:20 +00:00
|
|
|
fpList->clear();
|
|
|
|
fpList->insert( fpList->end(), panelList.begin(), panelList.end() );
|
2009-08-11 10:27:21 +00:00
|
|
|
|
2018-06-22 13:05:11 +00:00
|
|
|
// This is a simple edit, we must create an undo entry
|
2019-04-22 08:58:06 +00:00
|
|
|
if( m_footprint->GetEditFlags() == 0 ) // i.e. not edited, or moved
|
2020-10-14 23:37:26 +00:00
|
|
|
commit.Push( _( "Modify footprint properties" ) );
|
2009-08-11 10:27:21 +00:00
|
|
|
|
2020-12-07 17:28:06 +00:00
|
|
|
m_returnValue = FP_PROPS_OK;
|
2016-04-10 12:59:23 +00:00
|
|
|
return true;
|
2009-08-11 10:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
void DIALOG_FOOTPRINT_PROPERTIES::OnAddField( wxCommandEvent& )
|
2009-08-11 10:27:21 +00:00
|
|
|
{
|
2018-08-15 13:29:19 +00:00
|
|
|
if( !m_itemsGrid->CommitPendingChanges() )
|
|
|
|
return;
|
|
|
|
|
2023-06-13 13:47:36 +00:00
|
|
|
int fieldId = (int) m_fields->size();
|
|
|
|
PCB_FIELD* newField =
|
|
|
|
new PCB_FIELD( m_footprint, m_fields->size(),
|
|
|
|
TEMPLATE_FIELDNAME::GetDefaultFieldName( fieldId, DO_TRANSLATE ) );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
2023-05-24 12:39:25 +00:00
|
|
|
newField->SetVisible( false );
|
2023-06-13 13:47:36 +00:00
|
|
|
newField->SetLayer( m_footprint->GetLayer() == F_Cu ? F_Fab : B_Fab );
|
|
|
|
newField->SetFPRelativePosition( { 0, 0 } );
|
2023-05-24 12:39:25 +00:00
|
|
|
newField->StyleFromSettings( m_frame->GetDesignSettings() );
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2023-05-24 12:39:25 +00:00
|
|
|
m_fields->push_back( newField );
|
2018-01-14 13:24:58 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
// notify the grid
|
2023-05-24 12:39:25 +00:00
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
|
2018-03-28 17:14:04 +00:00
|
|
|
m_itemsGrid->ProcessTableMessage( msg );
|
|
|
|
|
|
|
|
m_itemsGrid->SetFocus();
|
2023-05-24 12:39:25 +00:00
|
|
|
m_itemsGrid->MakeCellVisible( m_fields->size() - 1, 0 );
|
|
|
|
m_itemsGrid->SetGridCursor( m_fields->size() - 1, 0 );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
|
|
|
m_itemsGrid->EnableCellEditControl( true );
|
|
|
|
m_itemsGrid->ShowCellEditControl();
|
2009-08-11 10:27:21 +00:00
|
|
|
}
|
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
void DIALOG_FOOTPRINT_PROPERTIES::OnDeleteField( wxCommandEvent& )
|
2009-08-11 10:27:21 +00:00
|
|
|
{
|
2021-12-12 17:27:40 +00:00
|
|
|
if( !m_itemsGrid->CommitPendingChanges() )
|
|
|
|
return;
|
2018-08-15 13:29:19 +00:00
|
|
|
|
2021-12-12 17:27:40 +00:00
|
|
|
wxArrayInt selectedRows = m_itemsGrid->GetSelectedRows();
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2021-12-12 17:27:40 +00:00
|
|
|
if( selectedRows.empty() && m_itemsGrid->GetGridCursorRow() >= 0 )
|
|
|
|
selectedRows.push_back( m_itemsGrid->GetGridCursorRow() );
|
|
|
|
|
|
|
|
if( selectedRows.empty() )
|
2018-03-28 17:14:04 +00:00
|
|
|
return;
|
2021-12-12 17:27:40 +00:00
|
|
|
|
|
|
|
for( int row : selectedRows )
|
2018-03-28 17:14:04 +00:00
|
|
|
{
|
2023-05-24 12:39:25 +00:00
|
|
|
if( row < MANDATORY_FIELDS )
|
2021-12-12 17:27:40 +00:00
|
|
|
{
|
2023-05-24 12:39:25 +00:00
|
|
|
DisplayError( this, wxString::Format( _( "The first %d fields are mandatory." ),
|
|
|
|
MANDATORY_FIELDS ) );
|
2021-12-12 17:27:40 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-03-28 17:14:04 +00:00
|
|
|
}
|
|
|
|
|
2023-05-24 12:39:25 +00:00
|
|
|
m_itemsGrid->CommitPendingChanges( true /* quiet mode */ );
|
|
|
|
m_itemsGrid->ClearSelection();
|
|
|
|
|
2021-12-12 17:27:40 +00:00
|
|
|
// Reverse sort so deleting a row doesn't change the indexes of the other rows.
|
|
|
|
selectedRows.Sort( []( int* first, int* second ) { return *second - *first; } );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
2021-12-12 17:27:40 +00:00
|
|
|
for( int row : selectedRows )
|
2018-03-28 17:14:04 +00:00
|
|
|
{
|
2023-05-24 12:39:25 +00:00
|
|
|
m_fields->erase( m_fields->begin() + row );
|
2021-12-12 17:27:40 +00:00
|
|
|
|
|
|
|
// notify the grid
|
2023-05-24 12:39:25 +00:00
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
|
2021-12-12 17:27:40 +00:00
|
|
|
m_itemsGrid->ProcessTableMessage( msg );
|
|
|
|
|
|
|
|
if( m_itemsGrid->GetNumberRows() > 0 )
|
|
|
|
{
|
|
|
|
m_itemsGrid->MakeCellVisible( std::max( 0, row-1 ), m_itemsGrid->GetGridCursorCol() );
|
|
|
|
m_itemsGrid->SetGridCursor( std::max( 0, row-1 ), m_itemsGrid->GetGridCursorCol() );
|
|
|
|
}
|
2018-03-28 17:14:04 +00:00
|
|
|
}
|
2009-08-11 10:27:21 +00:00
|
|
|
}
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
|
2016-02-27 23:17:58 +00:00
|
|
|
|
2021-12-16 14:39:58 +00:00
|
|
|
void DIALOG_FOOTPRINT_PROPERTIES::adjustGridColumns()
|
2018-03-28 17:14:04 +00:00
|
|
|
{
|
|
|
|
// Account for scroll bars
|
2021-12-16 14:39:58 +00:00
|
|
|
int itemsWidth = KIPLATFORM::UI::GetUnobscuredSize( m_itemsGrid ).x;
|
2018-03-28 17:14:04 +00:00
|
|
|
|
|
|
|
itemsWidth -= m_itemsGrid->GetRowLabelSize();
|
|
|
|
|
2023-05-24 12:39:25 +00:00
|
|
|
for( int i = 0; i < m_itemsGrid->GetNumberCols(); i++ )
|
|
|
|
{
|
|
|
|
if( i == 1 )
|
|
|
|
continue;
|
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
itemsWidth -= m_itemsGrid->GetColSize( i );
|
2023-05-24 12:39:25 +00:00
|
|
|
}
|
2018-03-28 17:14:04 +00:00
|
|
|
|
2023-05-24 12:39:25 +00:00
|
|
|
m_itemsGrid->SetColSize(
|
|
|
|
1, std::max( itemsWidth, m_itemsGrid->GetVisibleWidth( 0, true, false ) ) );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
2021-07-28 19:54:20 +00:00
|
|
|
// Update the width of the 3D panel
|
2021-12-16 14:39:58 +00:00
|
|
|
m_3dPanel->AdjustGridColumnWidths();
|
2018-03-28 17:14:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
void DIALOG_FOOTPRINT_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& )
|
2018-03-28 17:14:04 +00:00
|
|
|
{
|
2021-09-14 12:28:45 +00:00
|
|
|
if( !m_initialized )
|
|
|
|
return;
|
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
// Handle a grid error. This is delayed to OnUpdateUI so that we can change focus
|
|
|
|
// even when the original validation was triggered from a killFocus event, and so
|
|
|
|
// that the corresponding notebook page can be shown in the background when triggered
|
|
|
|
// from an OK.
|
|
|
|
if( m_delayedFocusRow >= 0 )
|
|
|
|
{
|
2018-10-13 23:06:41 +00:00
|
|
|
// We will re-enter this routine if an error dialog is displayed, so make sure we
|
|
|
|
// zero out our member variables first.
|
|
|
|
wxGrid* grid = m_delayedFocusGrid;
|
|
|
|
int row = m_delayedFocusRow;
|
|
|
|
int col = m_delayedFocusColumn;
|
|
|
|
wxString msg = m_delayedErrorMessage;
|
|
|
|
|
|
|
|
m_delayedFocusGrid = nullptr;
|
|
|
|
m_delayedFocusRow = -1;
|
|
|
|
m_delayedFocusColumn = -1;
|
|
|
|
m_delayedErrorMessage = wxEmptyString;
|
|
|
|
|
2018-11-12 17:07:22 +00:00
|
|
|
if( !msg.IsEmpty() )
|
2018-03-28 17:14:04 +00:00
|
|
|
{
|
|
|
|
// Do not use DisplayErrorMessage(); it screws up window order on Mac
|
|
|
|
DisplayError( nullptr, msg );
|
|
|
|
}
|
|
|
|
|
2018-10-13 23:06:41 +00:00
|
|
|
grid->SetFocus();
|
|
|
|
grid->MakeCellVisible( row, col );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
2019-02-15 00:26:45 +00:00
|
|
|
// Selecting the first grid item only makes sense for the
|
|
|
|
// items grid
|
|
|
|
if( !m_initialFocus || grid == m_itemsGrid )
|
2018-10-13 23:06:41 +00:00
|
|
|
{
|
2019-02-15 00:26:45 +00:00
|
|
|
grid->SetGridCursor( row, col );
|
2023-05-24 12:39:25 +00:00
|
|
|
|
|
|
|
if( !( col == 0 && row < MANDATORY_FIELDS ) )
|
|
|
|
grid->EnableCellEditControl( true );
|
|
|
|
|
2019-02-15 00:26:45 +00:00
|
|
|
grid->ShowCellEditControl();
|
|
|
|
|
|
|
|
if( grid == m_itemsGrid && row == 0 && col == 0 )
|
|
|
|
{
|
|
|
|
auto referenceEditor = grid->GetCellEditor( 0, 0 );
|
2020-01-13 15:22:26 +00:00
|
|
|
|
|
|
|
if( auto textEntry = dynamic_cast<wxTextEntry*>( referenceEditor->GetControl() ) )
|
2020-10-25 16:41:38 +00:00
|
|
|
KIUI::SelectReferenceNumber( textEntry );
|
2020-01-13 15:22:26 +00:00
|
|
|
|
2019-02-15 00:26:45 +00:00
|
|
|
referenceEditor->DecRef();
|
|
|
|
}
|
2018-10-13 23:06:41 +00:00
|
|
|
}
|
2019-02-15 00:26:45 +00:00
|
|
|
m_initialFocus = false;
|
2018-03-28 17:14:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
void DIALOG_FOOTPRINT_PROPERTIES::OnGridSize( wxSizeEvent& aEvent )
|
2018-03-28 17:14:04 +00:00
|
|
|
{
|
2022-10-11 23:38:01 +00:00
|
|
|
wxSize new_size = aEvent.GetSize();
|
|
|
|
|
|
|
|
if( ( !m_itemsGrid->IsCellEditControlShown() || m_lastRequestedSize != new_size )
|
|
|
|
&& m_gridSize != new_size )
|
2021-11-13 10:12:08 +00:00
|
|
|
{
|
2022-10-11 23:38:01 +00:00
|
|
|
m_gridSize = new_size;
|
|
|
|
|
|
|
|
// A trick to fix a cosmetic issue: when, in m_itemsGrid, a layer selector widget has
|
|
|
|
// the focus (is activated in column 6) when resizing the grid, the widget is not moved.
|
|
|
|
// So just change the widget having the focus in this case
|
|
|
|
if( m_NoteBook->GetSelection() == 0 && !m_itemsGrid->HasFocus() )
|
|
|
|
{
|
|
|
|
int col = m_itemsGrid->GetGridCursorCol();
|
2021-11-13 10:12:08 +00:00
|
|
|
|
2022-10-11 23:38:01 +00:00
|
|
|
if( col == 6 ) // a layer selector widget can be activated
|
|
|
|
m_itemsGrid->SetFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
adjustGridColumns();
|
2021-11-13 10:12:08 +00:00
|
|
|
}
|
|
|
|
|
2022-10-11 23:38:01 +00:00
|
|
|
// We store this value to check whether the dialog is changing size. This might indicate
|
|
|
|
// that the user is scaling the dialog with an editor shown. Some editors do not close
|
|
|
|
// (at least on GTK) when the user drags a dialog corner
|
|
|
|
m_lastRequestedSize = new_size;
|
2018-03-28 17:14:04 +00:00
|
|
|
|
2022-10-11 23:38:01 +00:00
|
|
|
// Always propagate for a grid repaint (needed if the height changes, as well as width)
|
2018-03-28 17:14:04 +00:00
|
|
|
aEvent.Skip();
|
2022-10-11 23:38:01 +00:00
|
|
|
|
2016-02-27 23:17:58 +00:00
|
|
|
}
|
2019-03-07 16:21:49 +00:00
|
|
|
|
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
void DIALOG_FOOTPRINT_PROPERTIES::OnPageChange( wxNotebookEvent& aEvent )
|
2020-03-26 11:02:59 +00:00
|
|
|
{
|
|
|
|
int page = aEvent.GetSelection();
|
|
|
|
|
|
|
|
// Shouldn't be necessary, but is on at least OSX
|
|
|
|
if( page >= 0 )
|
|
|
|
m_NoteBook->ChangeSelection( (unsigned) page );
|
|
|
|
}
|
|
|
|
|
|
|
|
|