2013-05-28 16:54:59 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2020-08-18 14:17:16 +00:00
|
|
|
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-05-28 16:54:59 +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
|
|
|
|
*/
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <confirm.h>
|
|
|
|
#include <dialog_edit_footprint_for_fp_editor.h>
|
|
|
|
#include <footprint_edit_frame.h>
|
|
|
|
#include <footprint_tree_pane.h>
|
|
|
|
#include <fp_lib_table.h>
|
|
|
|
#include <functional>
|
2018-08-19 16:53:01 +00:00
|
|
|
#include <kiway_express.h>
|
2019-11-03 17:14:21 +00:00
|
|
|
#include <pcb_layer_box_selector.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew_id.h>
|
2020-06-16 18:15:14 +00:00
|
|
|
#include <ratsnest/ratsnest_data.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <settings/color_settings.h>
|
2014-07-09 11:50:27 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2017-02-21 12:42:08 +00:00
|
|
|
#include <tools/pcb_actions.h>
|
2020-09-30 03:29:58 +00:00
|
|
|
#include <widgets/appearance_controls.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <widgets/lib_tree.h>
|
2012-05-09 17:37:25 +00:00
|
|
|
|
2016-06-29 10:23:11 +00:00
|
|
|
using namespace std::placeholders;
|
2014-07-09 13:10:32 +00:00
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2020-11-10 20:11:53 +00:00
|
|
|
void FOOTPRINT_EDIT_FRAME::LoadFootprintFromBoard( wxCommandEvent& event )
|
2009-05-21 17:42:42 +00:00
|
|
|
{
|
2020-11-07 14:31:50 +00:00
|
|
|
LoadFootprintFromBoard( NULL );
|
2018-10-15 14:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-10 20:31:52 +00:00
|
|
|
void FOOTPRINT_EDIT_FRAME::LoadFootprintFromLibrary( LIB_ID aFPID)
|
2018-10-15 14:28:53 +00:00
|
|
|
{
|
2019-01-18 16:24:40 +00:00
|
|
|
bool is_last_fp_from_brd = IsCurrentFPFromBoard();
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = LoadFootprint( aFPID );
|
2018-10-15 14:28:53 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
if( !footprint )
|
2010-06-14 20:16:47 +00:00
|
|
|
return;
|
|
|
|
|
2018-10-15 14:28:53 +00:00
|
|
|
if( !Clear_Pcb( true ) )
|
|
|
|
return;
|
|
|
|
|
2019-06-13 17:28:55 +00:00
|
|
|
GetCanvas()->GetViewControls()->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false );
|
2020-11-10 20:31:52 +00:00
|
|
|
AddFootprintToBoard( footprint );
|
2018-10-15 14:28:53 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
footprint->ClearFlags();
|
2019-05-31 00:15:57 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
// if either m_Reference or m_Value are gone, reinstall them -
|
|
|
|
// otherwise you cannot see what you are doing on board
|
|
|
|
FP_TEXT* ref = &footprint->Reference();
|
|
|
|
FP_TEXT* val = &footprint->Value();
|
2018-10-15 14:28:53 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
if( val && ref )
|
|
|
|
{
|
|
|
|
ref->SetType( FP_TEXT::TEXT_is_REFERENCE ); // just in case ...
|
2018-10-15 14:28:53 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
if( ref->GetLength() == 0 )
|
|
|
|
ref->SetText( wxT( "Ref**" ) );
|
2018-10-15 14:28:53 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
val->SetType( FP_TEXT::TEXT_is_VALUE ); // just in case ...
|
2018-10-15 14:28:53 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
if( val->GetLength() == 0 )
|
|
|
|
val->SetText( wxT( "Val**" ) );
|
2018-10-15 14:28:53 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 19:49:30 +00:00
|
|
|
if( m_zoomSelectBox->GetSelection() == 0 )
|
|
|
|
Zoom_Automatique( false );
|
2009-05-21 17:42:42 +00:00
|
|
|
|
2019-06-02 14:34:19 +00:00
|
|
|
Update3DView( true );
|
2018-10-15 14:28:53 +00:00
|
|
|
|
|
|
|
GetScreen()->ClrModify();
|
|
|
|
|
2020-11-10 20:11:53 +00:00
|
|
|
UpdateView();
|
2019-06-13 17:28:55 +00:00
|
|
|
GetCanvas()->Refresh();
|
2018-10-24 20:14:36 +00:00
|
|
|
|
2019-06-03 23:50:44 +00:00
|
|
|
// Update the save items if needed.
|
2019-01-18 16:24:40 +00:00
|
|
|
if( is_last_fp_from_brd )
|
2019-06-03 23:50:44 +00:00
|
|
|
{
|
|
|
|
ReCreateMenuBar();
|
2019-01-18 16:24:40 +00:00
|
|
|
ReCreateHToolbar();
|
2019-06-03 23:50:44 +00:00
|
|
|
}
|
2019-01-18 16:24:40 +00:00
|
|
|
|
2018-10-24 20:14:36 +00:00
|
|
|
m_treePane->GetLibTree()->ExpandLibId( aFPID );
|
|
|
|
m_treePane->GetLibTree()->CenterLibId( aFPID );
|
2019-11-26 21:38:57 +00:00
|
|
|
m_treePane->GetLibTree()->RefreshLibTree(); // update highlighting
|
2009-05-21 17:42:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-10 20:11:53 +00:00
|
|
|
void FOOTPRINT_EDIT_FRAME::SelectLayer( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2020-11-10 20:11:53 +00:00
|
|
|
SetActiveLayer( ToLAYER_ID( m_selLayerBox->GetLayerSelection() ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2020-11-10 20:11:53 +00:00
|
|
|
if( GetDisplayOptions().m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL )
|
|
|
|
GetCanvas()->Refresh();
|
|
|
|
}
|
2019-11-03 17:14:21 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2020-11-10 20:11:53 +00:00
|
|
|
void FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
SaveFootprintToBoard( true );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2011-11-24 17:32:51 +00:00
|
|
|
|
2019-09-04 16:18:42 +00:00
|
|
|
class BASIC_FOOTPRINT_INFO : public FOOTPRINT_INFO
|
|
|
|
{
|
|
|
|
public:
|
2020-11-13 15:15:52 +00:00
|
|
|
BASIC_FOOTPRINT_INFO( FOOTPRINT* aFootprint )
|
2019-09-04 16:18:42 +00:00
|
|
|
{
|
2020-11-13 02:09:34 +00:00
|
|
|
m_nickname = aFootprint->GetFPID().GetLibNickname().wx_str();
|
|
|
|
m_fpname = aFootprint->GetFPID().GetLibItemName().wx_str();
|
|
|
|
m_pad_count = aFootprint->GetPadCount( DO_NOT_INCLUDE_NPTH );
|
|
|
|
m_unique_pad_count = aFootprint->GetUniquePadCount( DO_NOT_INCLUDE_NPTH );
|
|
|
|
m_keywords = aFootprint->GetKeywords();
|
|
|
|
m_doc = aFootprint->GetDescription();
|
2019-09-04 16:18:42 +00:00
|
|
|
m_loaded = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void FOOTPRINT_EDIT_FRAME::editFootprintProperties( FOOTPRINT* aFootprint )
|
2018-09-13 15:39:14 +00:00
|
|
|
{
|
2020-11-13 02:09:34 +00:00
|
|
|
LIB_ID oldFPID = aFootprint->GetFPID();
|
2018-09-13 15:39:14 +00:00
|
|
|
|
2020-11-13 02:09:34 +00:00
|
|
|
DIALOG_FOOTPRINT_FP_EDITOR dialog( this, aFootprint );
|
2018-09-13 15:39:14 +00:00
|
|
|
dialog.ShowModal();
|
|
|
|
|
2019-09-04 16:18:42 +00:00
|
|
|
// Update library tree
|
2020-11-13 02:09:34 +00:00
|
|
|
BASIC_FOOTPRINT_INFO footprintInfo( aFootprint );
|
2019-09-04 16:18:42 +00:00
|
|
|
wxDataViewItem treeItem = m_adapter->FindItem( oldFPID );
|
2019-09-06 13:37:26 +00:00
|
|
|
|
2020-08-18 14:17:16 +00:00
|
|
|
if( treeItem.IsOk() ) // Can be not found in tree if the current footprint is imported
|
|
|
|
// from file therefore not yet in tree.
|
2019-09-06 13:37:26 +00:00
|
|
|
{
|
|
|
|
static_cast<LIB_TREE_NODE_LIB_ID*>( treeItem.GetID() )->Update( &footprintInfo );
|
2019-11-26 21:38:57 +00:00
|
|
|
m_treePane->GetLibTree()->RefreshLibTree();
|
2019-09-06 13:37:26 +00:00
|
|
|
}
|
2019-09-04 16:18:42 +00:00
|
|
|
|
2018-09-13 23:39:40 +00:00
|
|
|
updateTitle(); // in case of a name change...
|
2019-09-04 16:18:42 +00:00
|
|
|
|
|
|
|
UpdateMsgPanel();
|
2018-09-13 15:39:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-28 23:23:58 +00:00
|
|
|
void FOOTPRINT_EDIT_FRAME::OnEditItemRequest( BOARD_ITEM* aItem )
|
2018-01-31 13:54:31 +00:00
|
|
|
{
|
2019-05-28 00:00:33 +00:00
|
|
|
switch( aItem->Type() )
|
2018-01-31 13:54:31 +00:00
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
case PCB_PAD_T:
|
2020-11-13 15:15:52 +00:00
|
|
|
ShowPadPropertiesDialog( static_cast<PAD*>( aItem ) );
|
2018-01-31 13:54:31 +00:00
|
|
|
break;
|
|
|
|
|
2020-11-13 12:21:02 +00:00
|
|
|
case PCB_FOOTPRINT_T:
|
2020-11-13 15:15:52 +00:00
|
|
|
editFootprintProperties( static_cast<FOOTPRINT*>( aItem ) );
|
2019-06-13 17:28:55 +00:00
|
|
|
GetCanvas()->Refresh();
|
2018-01-31 13:54:31 +00:00
|
|
|
break;
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
case PCB_FP_TEXT_T:
|
|
|
|
ShowTextPropertiesDialog( aItem );
|
2019-05-28 00:00:33 +00:00
|
|
|
break;
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
case PCB_FP_SHAPE_T :
|
|
|
|
ShowGraphicItemPropertiesDialog( aItem );
|
2018-01-31 13:54:31 +00:00
|
|
|
break;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
case PCB_FP_ZONE_T:
|
2019-10-26 15:49:29 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zone = static_cast<ZONE*>( aItem );
|
|
|
|
bool success = false;
|
|
|
|
ZONE_SETTINGS zoneSettings;
|
2020-08-09 11:22:09 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
zoneSettings << *static_cast<ZONE*>( aItem );
|
2020-08-09 11:22:09 +00:00
|
|
|
|
2020-09-21 23:32:07 +00:00
|
|
|
if( zone->GetIsRuleArea() )
|
2019-10-26 15:49:29 +00:00
|
|
|
{
|
2020-09-21 23:32:07 +00:00
|
|
|
success = InvokeRuleAreaEditor( this, &zoneSettings );
|
2020-08-09 11:22:09 +00:00
|
|
|
}
|
|
|
|
else if( zone->IsOnCopperLayer() )
|
|
|
|
{
|
|
|
|
success = InvokeCopperZonesEditor( this, &zoneSettings );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
success = InvokeNonCopperZonesEditor( this, &zoneSettings );
|
|
|
|
}
|
2019-10-26 15:49:29 +00:00
|
|
|
|
2020-08-09 11:22:09 +00:00
|
|
|
if( success )
|
|
|
|
{
|
|
|
|
BOARD_COMMIT commit( this );
|
|
|
|
commit.Modify( zone );
|
|
|
|
commit.Push( _( "Edit Zone" ) );
|
2020-11-11 23:05:59 +00:00
|
|
|
zoneSettings.ExportSetting( *static_cast<ZONE*>( aItem ) );
|
2019-10-26 15:49:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-01-31 13:54:31 +00:00
|
|
|
default:
|
2019-10-26 15:49:29 +00:00
|
|
|
wxASSERT( 0 );
|
2019-05-28 00:00:33 +00:00
|
|
|
break;
|
2018-01-31 13:54:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-28 00:00:33 +00:00
|
|
|
|
2017-08-04 12:43:02 +00:00
|
|
|
COLOR4D FOOTPRINT_EDIT_FRAME::GetGridColor()
|
2013-04-11 18:29:56 +00:00
|
|
|
{
|
2020-05-16 17:15:43 +00:00
|
|
|
return GetColorSettings()->GetColor( LAYER_GRID );
|
2013-04-11 18:29:56 +00:00
|
|
|
}
|
|
|
|
|
2014-07-09 09:22:43 +00:00
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
void FOOTPRINT_EDIT_FRAME::SetActiveLayer( PCB_LAYER_ID aLayer )
|
2014-07-09 09:59:23 +00:00
|
|
|
{
|
|
|
|
PCB_BASE_FRAME::SetActiveLayer( aLayer );
|
|
|
|
|
2020-09-30 03:29:58 +00:00
|
|
|
m_appearancePanel->OnLayerChanged();
|
2015-01-07 19:07:15 +00:00
|
|
|
|
2019-08-28 04:27:39 +00:00
|
|
|
m_toolManager->RunAction( PCB_ACTIONS::layerChanged ); // notify other tools
|
|
|
|
GetCanvas()->SetFocus(); // allow capture of hotkeys
|
2019-06-13 17:28:55 +00:00
|
|
|
GetCanvas()->SetHighContrastLayer( aLayer );
|
|
|
|
GetCanvas()->Refresh();
|
2014-07-09 09:59:23 +00:00
|
|
|
}
|
2017-10-19 21:15:48 +00:00
|
|
|
|
|
|
|
bool FOOTPRINT_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
|
|
|
|
{
|
|
|
|
if( ! Clear_Pcb( true ) )
|
|
|
|
return false; // //this command is aborted
|
|
|
|
|
2019-06-13 17:28:55 +00:00
|
|
|
GetCanvas()->GetViewControls()->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false );
|
2020-11-10 20:31:52 +00:00
|
|
|
ImportFootprint( aFileSet[ 0 ] );
|
2017-10-19 21:15:48 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
if( GetBoard()->GetFirstFootprint() )
|
|
|
|
GetBoard()->GetFirstFootprint()->ClearFlags();
|
2017-10-19 21:15:48 +00:00
|
|
|
|
|
|
|
GetScreen()->ClrModify();
|
|
|
|
Zoom_Automatique( false );
|
2019-06-13 17:28:55 +00:00
|
|
|
GetCanvas()->Refresh();
|
2017-10-19 21:15:48 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-08-19 16:53:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINT_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
|
|
|
|
{
|
|
|
|
const std::string& payload = mail.GetPayload();
|
|
|
|
|
|
|
|
switch( mail.Command() )
|
|
|
|
{
|
|
|
|
case MAIL_FP_EDIT:
|
|
|
|
if( !payload.empty() )
|
|
|
|
{
|
|
|
|
wxFileName fpFileName( payload );
|
|
|
|
wxString libNickname;
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
FP_LIB_TABLE* libTable = Prj().PcbFootprintLibs();
|
|
|
|
const LIB_TABLE_ROW* libTableRow = libTable->FindRowByURI( fpFileName.GetPath() );
|
|
|
|
|
|
|
|
if( !libTableRow )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "The current configuration does not include the footprint library\n"
|
|
|
|
"\"%s\".\nUse Manage Footprint Libraries to edit the configuration." ),
|
|
|
|
fpFileName.GetPath() );
|
|
|
|
DisplayErrorMessage( this, _( "Library not found in footprint library table." ), msg );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
libNickname = libTableRow->GetNickName();
|
|
|
|
|
|
|
|
if( !libTable->HasLibrary( libNickname, true ) )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "The library with the nickname \"%s\" is not enabled\n"
|
|
|
|
"in the current configuration. Use Manage Footprint Libraries to\n"
|
|
|
|
"edit the configuration." ), libNickname );
|
|
|
|
DisplayErrorMessage( this, _( "Footprint library not enabled." ), msg );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
LIB_ID fpId( libNickname, fpFileName.GetName() );
|
|
|
|
|
|
|
|
if( m_treePane )
|
|
|
|
{
|
|
|
|
m_treePane->GetLibTree()->SelectLibId( fpId );
|
|
|
|
wxCommandEvent event( COMPONENT_SELECTED );
|
|
|
|
wxPostEvent( m_treePane, event );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|