2019-05-25 00:34:44 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-08-14 08:28:07 +00:00
|
|
|
* Copyright (C) 2019 CERN
|
2020-12-17 13:12:18 +00:00
|
|
|
* Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-05-25 00:34:44 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <kiway.h>
|
|
|
|
#include <view/view.h>
|
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <bitmaps.h>
|
2020-12-17 13:12:18 +00:00
|
|
|
#include <dialogs/dialog_page_settings.h>
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_data_model.h>
|
|
|
|
#include <drawing_sheet/ds_painter.h>
|
2019-05-26 15:36:40 +00:00
|
|
|
|
2020-10-13 05:04:31 +00:00
|
|
|
#include "pl_editor_frame.h"
|
|
|
|
#include "pl_editor_id.h"
|
|
|
|
#include "properties_frame.h"
|
|
|
|
#include "tools/pl_actions.h"
|
|
|
|
#include "tools/pl_editor_control.h"
|
|
|
|
#include "tools/pl_selection_tool.h"
|
|
|
|
|
2020-12-17 13:12:18 +00:00
|
|
|
|
2019-05-25 00:34:44 +00:00
|
|
|
bool PL_EDITOR_CONTROL::Init()
|
|
|
|
{
|
|
|
|
m_frame = getEditFrame<PL_EDITOR_FRAME>();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PL_EDITOR_CONTROL::Reset( RESET_REASON aReason )
|
|
|
|
{
|
|
|
|
if( aReason == MODEL_RELOAD )
|
|
|
|
m_frame = getEditFrame<PL_EDITOR_FRAME>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PL_EDITOR_CONTROL::New( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
wxCommandEvent evt( wxEVT_NULL, wxID_NEW );
|
|
|
|
m_frame->Files_io( evt );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PL_EDITOR_CONTROL::Open( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
wxCommandEvent evt( wxEVT_NULL, wxID_OPEN );
|
|
|
|
m_frame->Files_io( evt );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PL_EDITOR_CONTROL::Save( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
wxCommandEvent evt( wxEVT_NULL, wxID_SAVE );
|
|
|
|
m_frame->Files_io( evt );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PL_EDITOR_CONTROL::SaveAs( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
wxCommandEvent evt( wxEVT_NULL, wxID_SAVEAS );
|
|
|
|
m_frame->Files_io( evt );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PL_EDITOR_CONTROL::PageSetup( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2020-07-13 11:21:40 +00:00
|
|
|
m_frame->SaveCopyInUndoList();
|
2019-05-26 15:36:40 +00:00
|
|
|
|
2022-09-16 23:25:07 +00:00
|
|
|
DIALOG_PAGES_SETTINGS dlg( m_frame, drawSheetIUScale.IU_PER_MILS,
|
2023-02-19 03:40:07 +00:00
|
|
|
VECTOR2I( MAX_PAGE_SIZE_EESCHEMA_MILS,
|
|
|
|
MAX_PAGE_SIZE_EESCHEMA_MILS ) );
|
2020-05-16 23:08:01 +00:00
|
|
|
dlg.SetWksFileName( m_frame->GetCurrentFileName() );
|
2019-05-26 15:36:40 +00:00
|
|
|
dlg.EnableWksFileNamePicker( false );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
{
|
|
|
|
// Nothing to roll back but we have to at least pop the stack
|
|
|
|
m_frame->RollbackFromUndo();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-06 23:07:46 +00:00
|
|
|
m_frame->OnModify();
|
2019-05-26 15:36:40 +00:00
|
|
|
m_frame->HardRedraw();
|
|
|
|
}
|
2019-05-25 00:34:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PL_EDITOR_CONTROL::Print( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_frame->ToPrinter( false );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PL_EDITOR_CONTROL::Plot( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
wxMessageBox( wxT( "Not yet available" ) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-14 18:14:41 +00:00
|
|
|
int PL_EDITOR_CONTROL::ShowInspector( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_frame->ShowDesignInspector();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-29 23:50:25 +00:00
|
|
|
int PL_EDITOR_CONTROL::TitleBlockDisplayMode( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
if( aEvent.IsAction( &PL_ACTIONS::layoutEditMode ) )
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_MODEL::GetTheInstance().m_EditMode = true;
|
2020-07-29 23:50:25 +00:00
|
|
|
else
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_MODEL::GetTheInstance().m_EditMode = false;
|
2020-07-29 23:50:25 +00:00
|
|
|
|
|
|
|
m_frame->HardRedraw();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-25 00:34:44 +00:00
|
|
|
int PL_EDITOR_CONTROL::UpdateMessagePanel( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
PL_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PL_SELECTION_TOOL>();
|
2019-06-08 21:48:22 +00:00
|
|
|
PL_SELECTION& selection = selTool->GetSelection();
|
2019-05-25 00:34:44 +00:00
|
|
|
|
2019-06-04 08:55:14 +00:00
|
|
|
// The Properties frame will be updated. Avoid flicker during update:
|
|
|
|
m_frame->GetPropertiesFrame()->Freeze();
|
|
|
|
|
2019-05-25 00:34:44 +00:00
|
|
|
if( selection.GetSize() == 1 )
|
|
|
|
{
|
|
|
|
EDA_ITEM* item = (EDA_ITEM*) selection.Front();
|
|
|
|
|
2021-09-26 23:22:32 +00:00
|
|
|
std::vector<MSG_PANEL_ITEM> msgItems;
|
2020-04-24 13:36:10 +00:00
|
|
|
item->GetMsgPanelInfo( m_frame, msgItems );
|
2019-05-25 00:34:44 +00:00
|
|
|
m_frame->SetMsgPanel( msgItems );
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_ITEM* dataItem = static_cast<DS_DRAW_ITEM_BASE*>( item )->GetPeer();
|
2019-05-25 00:34:44 +00:00
|
|
|
m_frame->GetPropertiesFrame()->CopyPrmsFromItemToPanel( dataItem );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-02 09:01:54 +00:00
|
|
|
m_frame->UpdateMsgPanelInfo();
|
2019-05-25 00:34:44 +00:00
|
|
|
m_frame->GetPropertiesFrame()->CopyPrmsFromItemToPanel( nullptr );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_frame->GetPropertiesFrame()->CopyPrmsFromGeneralToPanel();
|
|
|
|
|
2019-06-04 08:55:14 +00:00
|
|
|
// The Properties frame is updated. Reenable it:
|
|
|
|
m_frame->GetPropertiesFrame()->Thaw();
|
|
|
|
|
2019-05-25 00:34:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PL_EDITOR_CONTROL::setTransitions()
|
|
|
|
{
|
|
|
|
Go( &PL_EDITOR_CONTROL::New, ACTIONS::doNew.MakeEvent() );
|
|
|
|
Go( &PL_EDITOR_CONTROL::Open, ACTIONS::open.MakeEvent() );
|
|
|
|
Go( &PL_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() );
|
|
|
|
Go( &PL_EDITOR_CONTROL::SaveAs, ACTIONS::saveAs.MakeEvent() );
|
|
|
|
Go( &PL_EDITOR_CONTROL::Print, ACTIONS::print.MakeEvent() );
|
|
|
|
Go( &PL_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() );
|
|
|
|
|
2019-07-10 22:15:57 +00:00
|
|
|
Go( &PL_EDITOR_CONTROL::PageSetup, PL_ACTIONS::previewSettings.MakeEvent() );
|
|
|
|
Go( &PL_EDITOR_CONTROL::ShowInspector, PL_ACTIONS::showInspector.MakeEvent() );
|
2020-07-29 23:50:25 +00:00
|
|
|
Go( &PL_EDITOR_CONTROL::TitleBlockDisplayMode, PL_ACTIONS::layoutEditMode.MakeEvent() );
|
|
|
|
Go( &PL_EDITOR_CONTROL::TitleBlockDisplayMode, PL_ACTIONS::layoutNormalMode.MakeEvent() );
|
2019-05-25 00:34:44 +00:00
|
|
|
|
|
|
|
Go( &PL_EDITOR_CONTROL::UpdateMessagePanel, EVENTS::SelectedEvent );
|
|
|
|
Go( &PL_EDITOR_CONTROL::UpdateMessagePanel, EVENTS::UnselectedEvent );
|
|
|
|
Go( &PL_EDITOR_CONTROL::UpdateMessagePanel, EVENTS::ClearedEvent );
|
|
|
|
Go( &PL_EDITOR_CONTROL::UpdateMessagePanel, EVENTS::SelectedItemsModified );
|
|
|
|
}
|