2013-05-28 12:54:59 -04:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2020-08-18 10:17:16 -04:00
|
|
|
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-05-28 12:54:59 -04: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-12 20:44:19 -05: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 17:53:01 +01:00
|
|
|
#include <kiway_express.h>
|
2019-11-03 17:14:21 +00:00
|
|
|
#include <pcb_layer_box_selector.h>
|
2012-01-22 22:33:36 -06:00
|
|
|
#include <pcbnew_id.h>
|
2020-06-16 11:15:14 -07:00
|
|
|
#include <ratsnest/ratsnest_data.h>
|
2020-01-12 20:44:19 -05:00
|
|
|
#include <settings/color_settings.h>
|
2014-07-09 13:50:27 +02:00
|
|
|
#include <tool/tool_manager.h>
|
2017-02-21 13:42:08 +01:00
|
|
|
#include <tools/pcb_actions.h>
|
2020-09-29 23:29:58 -04:00
|
|
|
#include <widgets/appearance_controls.h>
|
2020-01-12 20:44:19 -05:00
|
|
|
#include <widgets/lib_tree.h>
|
2012-05-09 19:37:25 +02:00
|
|
|
|
2016-06-29 12:23:11 +02:00
|
|
|
using namespace std::placeholders;
|
2014-07-09 15:10:32 +02:00
|
|
|
|
2011-09-23 09:57:12 -04: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 15:28:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-10 20:31:52 +00:00
|
|
|
void FOOTPRINT_EDIT_FRAME::LoadFootprintFromLibrary( LIB_ID aFPID)
|
2018-10-15 15:28:53 +01:00
|
|
|
{
|
2019-01-18 17:24:40 +01:00
|
|
|
bool is_last_fp_from_brd = IsCurrentFPFromBoard();
|
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
MODULE* footprint = LoadFootprint( aFPID );
|
2018-10-15 15:28:53 +01:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
if( !footprint )
|
2010-06-14 22:16:47 +02:00
|
|
|
return;
|
|
|
|
|
2018-10-15 15:28:53 +01:00
|
|
|
if( !Clear_Pcb( true ) )
|
|
|
|
return;
|
|
|
|
|
2019-06-13 18:28:55 +01:00
|
|
|
GetCanvas()->GetViewControls()->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false );
|
2020-11-10 20:31:52 +00:00
|
|
|
AddFootprintToBoard( footprint );
|
2018-10-15 15:28:53 +01:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
footprint->ClearFlags();
|
2019-05-30 17:15:57 -07: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 15:28:53 +01: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 15:28:53 +01:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
if( ref->GetLength() == 0 )
|
|
|
|
ref->SetText( wxT( "Ref**" ) );
|
2018-10-15 15:28:53 +01:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
val->SetType( FP_TEXT::TEXT_is_VALUE ); // just in case ...
|
2018-10-15 15:28:53 +01:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
if( val->GetLength() == 0 )
|
|
|
|
val->SetText( wxT( "Val**" ) );
|
2018-10-15 15:28:53 +01: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 15:34:19 +01:00
|
|
|
Update3DView( true );
|
2018-10-15 15:28:53 +01:00
|
|
|
|
|
|
|
GetScreen()->ClrModify();
|
|
|
|
|
2020-11-10 20:11:53 +00:00
|
|
|
UpdateView();
|
2019-06-13 18:28:55 +01:00
|
|
|
GetCanvas()->Refresh();
|
2018-10-24 21:14:36 +01:00
|
|
|
|
2019-06-04 00:50:44 +01:00
|
|
|
// Update the save items if needed.
|
2019-01-18 17:24:40 +01:00
|
|
|
if( is_last_fp_from_brd )
|
2019-06-04 00:50:44 +01:00
|
|
|
{
|
|
|
|
ReCreateMenuBar();
|
2019-01-18 17:24:40 +01:00
|
|
|
ReCreateHToolbar();
|
2019-06-04 00:50:44 +01:00
|
|
|
}
|
2019-01-18 17:24:40 +01:00
|
|
|
|
2018-10-24 21:14:36 +01: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 11:32:51 -06:00
|
|
|
|
2019-09-04 17:18:42 +01:00
|
|
|
class BASIC_FOOTPRINT_INFO : public FOOTPRINT_INFO
|
|
|
|
{
|
|
|
|
public:
|
2020-11-13 02:09:34 +00:00
|
|
|
BASIC_FOOTPRINT_INFO( MODULE* aFootprint )
|
2019-09-04 17:18:42 +01: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 17:18:42 +01:00
|
|
|
m_loaded = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-11-13 02:09:34 +00:00
|
|
|
void FOOTPRINT_EDIT_FRAME::editFootprintProperties( MODULE* aFootprint )
|
2018-09-13 16:39:14 +01:00
|
|
|
{
|
2020-11-13 02:09:34 +00:00
|
|
|
LIB_ID oldFPID = aFootprint->GetFPID();
|
2018-09-13 16:39:14 +01:00
|
|
|
|
2020-11-13 02:09:34 +00:00
|
|
|
DIALOG_FOOTPRINT_FP_EDITOR dialog( this, aFootprint );
|
2018-09-13 16:39:14 +01:00
|
|
|
dialog.ShowModal();
|
|
|
|
|
2019-09-04 17:18:42 +01:00
|
|
|
// Update library tree
|
2020-11-13 02:09:34 +00:00
|
|
|
BASIC_FOOTPRINT_INFO footprintInfo( aFootprint );
|
2019-09-04 17:18:42 +01:00
|
|
|
wxDataViewItem treeItem = m_adapter->FindItem( oldFPID );
|
2019-09-06 15:37:26 +02:00
|
|
|
|
2020-08-18 10:17:16 -04: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 15:37:26 +02: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 15:37:26 +02:00
|
|
|
}
|
2019-09-04 17:18:42 +01:00
|
|
|
|
2018-09-14 00:39:40 +01:00
|
|
|
updateTitle(); // in case of a name change...
|
2019-09-04 17:18:42 +01:00
|
|
|
|
|
|
|
UpdateMsgPanel();
|
2018-09-13 16:39:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-29 00:23:58 +01:00
|
|
|
void FOOTPRINT_EDIT_FRAME::OnEditItemRequest( BOARD_ITEM* aItem )
|
2018-01-31 14:54:31 +01:00
|
|
|
{
|
2019-05-28 01:00:33 +01:00
|
|
|
switch( aItem->Type() )
|
2018-01-31 14:54:31 +01:00
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
case PCB_PAD_T:
|
|
|
|
ShowPadPropertiesDialog( static_cast<PAD*>( aItem ));
|
2018-01-31 14:54:31 +01:00
|
|
|
break;
|
|
|
|
|
2019-05-28 01:00:33 +01:00
|
|
|
case PCB_MODULE_T:
|
|
|
|
editFootprintProperties( (MODULE*) aItem );
|
2019-06-13 18:28:55 +01:00
|
|
|
GetCanvas()->Refresh();
|
2018-01-31 14:54:31 +01:00
|
|
|
break;
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
case PCB_FP_TEXT_T:
|
|
|
|
ShowTextPropertiesDialog( aItem );
|
2019-05-28 01:00:33 +01:00
|
|
|
break;
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
case PCB_FP_SHAPE_T :
|
|
|
|
ShowGraphicItemPropertiesDialog( aItem );
|
2018-01-31 14:54:31 +01:00
|
|
|
break;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
case PCB_FP_ZONE_T:
|
2019-10-26 17:49:29 +02:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zone = static_cast<ZONE*>( aItem );
|
|
|
|
bool success = false;
|
|
|
|
ZONE_SETTINGS zoneSettings;
|
2020-08-09 12:22:09 +01:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
zoneSettings << *static_cast<ZONE*>( aItem );
|
2020-08-09 12:22:09 +01:00
|
|
|
|
2020-09-21 19:32:07 -04:00
|
|
|
if( zone->GetIsRuleArea() )
|
2019-10-26 17:49:29 +02:00
|
|
|
{
|
2020-09-21 19:32:07 -04:00
|
|
|
success = InvokeRuleAreaEditor( this, &zoneSettings );
|
2020-08-09 12:22:09 +01:00
|
|
|
}
|
|
|
|
else if( zone->IsOnCopperLayer() )
|
|
|
|
{
|
|
|
|
success = InvokeCopperZonesEditor( this, &zoneSettings );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
success = InvokeNonCopperZonesEditor( this, &zoneSettings );
|
|
|
|
}
|
2019-10-26 17:49:29 +02:00
|
|
|
|
2020-08-09 12:22:09 +01: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 17:49:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-01-31 14:54:31 +01:00
|
|
|
default:
|
2019-10-26 17:49:29 +02:00
|
|
|
wxASSERT( 0 );
|
2019-05-28 01:00:33 +01:00
|
|
|
break;
|
2018-01-31 14:54:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-28 01:00:33 +01:00
|
|
|
|
2017-08-04 14:43:02 +02:00
|
|
|
COLOR4D FOOTPRINT_EDIT_FRAME::GetGridColor()
|
2013-04-11 20:29:56 +02:00
|
|
|
{
|
2020-05-16 13:15:43 -04:00
|
|
|
return GetColorSettings()->GetColor( LAYER_GRID );
|
2013-04-11 20:29:56 +02:00
|
|
|
}
|
|
|
|
|
2014-07-09 11:22:43 +02:00
|
|
|
|
2017-03-12 23:19:33 -04:00
|
|
|
void FOOTPRINT_EDIT_FRAME::SetActiveLayer( PCB_LAYER_ID aLayer )
|
2014-07-09 11:59:23 +02:00
|
|
|
{
|
|
|
|
PCB_BASE_FRAME::SetActiveLayer( aLayer );
|
|
|
|
|
2020-09-29 23:29:58 -04:00
|
|
|
m_appearancePanel->OnLayerChanged();
|
2015-01-07 20:07:15 +01:00
|
|
|
|
2019-08-27 21:27:39 -07:00
|
|
|
m_toolManager->RunAction( PCB_ACTIONS::layerChanged ); // notify other tools
|
|
|
|
GetCanvas()->SetFocus(); // allow capture of hotkeys
|
2019-06-13 18:28:55 +01:00
|
|
|
GetCanvas()->SetHighContrastLayer( aLayer );
|
|
|
|
GetCanvas()->Refresh();
|
2014-07-09 11:59:23 +02:00
|
|
|
}
|
2017-10-19 23:15:48 +02: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 18:28:55 +01:00
|
|
|
GetCanvas()->GetViewControls()->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false );
|
2020-11-10 20:31:52 +00:00
|
|
|
ImportFootprint( aFileSet[ 0 ] );
|
2017-10-19 23:15:48 +02:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
if( GetBoard()->GetFirstFootprint() )
|
|
|
|
GetBoard()->GetFirstFootprint()->ClearFlags();
|
2017-10-19 23:15:48 +02:00
|
|
|
|
|
|
|
GetScreen()->ClrModify();
|
|
|
|
Zoom_Automatique( false );
|
2019-06-13 18:28:55 +01:00
|
|
|
GetCanvas()->Refresh();
|
2017-10-19 23:15:48 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-08-19 17:53:01 +01: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:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|