You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
5.8 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2019 CERN
  5. * Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <kiway.h>
  25. #include <view/view.h>
  26. #include <tool/tool_manager.h>
  27. #include <confirm.h>
  28. #include <bitmaps.h>
  29. #include <dialogs/dialog_page_settings.h>
  30. #include <drawing_sheet/ds_data_model.h>
  31. #include <drawing_sheet/ds_painter.h>
  32. #include "pl_editor_frame.h"
  33. #include "pl_editor_id.h"
  34. #include "properties_frame.h"
  35. #include "tools/pl_actions.h"
  36. #include "tools/pl_editor_control.h"
  37. #include "tools/pl_selection_tool.h"
  38. bool PL_EDITOR_CONTROL::Init()
  39. {
  40. m_frame = getEditFrame<PL_EDITOR_FRAME>();
  41. return true;
  42. }
  43. void PL_EDITOR_CONTROL::Reset( RESET_REASON aReason )
  44. {
  45. if( aReason == MODEL_RELOAD )
  46. m_frame = getEditFrame<PL_EDITOR_FRAME>();
  47. }
  48. int PL_EDITOR_CONTROL::New( const TOOL_EVENT& aEvent )
  49. {
  50. wxCommandEvent evt( wxEVT_NULL, wxID_NEW );
  51. m_frame->Files_io( evt );
  52. return 0;
  53. }
  54. int PL_EDITOR_CONTROL::Open( const TOOL_EVENT& aEvent )
  55. {
  56. wxCommandEvent evt( wxEVT_NULL, wxID_OPEN );
  57. m_frame->Files_io( evt );
  58. return 0;
  59. }
  60. int PL_EDITOR_CONTROL::Save( const TOOL_EVENT& aEvent )
  61. {
  62. wxCommandEvent evt( wxEVT_NULL, wxID_SAVE );
  63. m_frame->Files_io( evt );
  64. return 0;
  65. }
  66. int PL_EDITOR_CONTROL::SaveAs( const TOOL_EVENT& aEvent )
  67. {
  68. wxCommandEvent evt( wxEVT_NULL, wxID_SAVEAS );
  69. m_frame->Files_io( evt );
  70. return 0;
  71. }
  72. int PL_EDITOR_CONTROL::PageSetup( const TOOL_EVENT& aEvent )
  73. {
  74. m_frame->SaveCopyInUndoList();
  75. DIALOG_PAGES_SETTINGS dlg( m_frame, drawSheetIUScale.IU_PER_MILS,
  76. VECTOR2I( MAX_PAGE_SIZE_EESCHEMA_MILS,
  77. MAX_PAGE_SIZE_EESCHEMA_MILS ) );
  78. dlg.SetWksFileName( m_frame->GetCurrentFileName() );
  79. dlg.EnableWksFileNamePicker( false );
  80. if( dlg.ShowModal() != wxID_OK )
  81. {
  82. // Nothing to roll back but we have to at least pop the stack
  83. m_frame->RollbackFromUndo();
  84. }
  85. else
  86. {
  87. m_frame->OnModify();
  88. m_frame->HardRedraw();
  89. }
  90. return 0;
  91. }
  92. int PL_EDITOR_CONTROL::Print( const TOOL_EVENT& aEvent )
  93. {
  94. m_frame->ToPrinter( false );
  95. return 0;
  96. }
  97. int PL_EDITOR_CONTROL::Plot( const TOOL_EVENT& aEvent )
  98. {
  99. wxMessageBox( wxT( "Not yet available" ) );
  100. return 0;
  101. }
  102. int PL_EDITOR_CONTROL::ShowInspector( const TOOL_EVENT& aEvent )
  103. {
  104. m_frame->ShowDesignInspector();
  105. return 0;
  106. }
  107. int PL_EDITOR_CONTROL::TitleBlockDisplayMode( const TOOL_EVENT& aEvent )
  108. {
  109. if( aEvent.IsAction( &PL_ACTIONS::layoutEditMode ) )
  110. DS_DATA_MODEL::GetTheInstance().m_EditMode = true;
  111. else
  112. DS_DATA_MODEL::GetTheInstance().m_EditMode = false;
  113. m_frame->HardRedraw();
  114. return 0;
  115. }
  116. int PL_EDITOR_CONTROL::UpdateMessagePanel( const TOOL_EVENT& aEvent )
  117. {
  118. PL_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PL_SELECTION_TOOL>();
  119. PL_SELECTION& selection = selTool->GetSelection();
  120. // The Properties frame will be updated. Avoid flicker during update:
  121. m_frame->GetPropertiesFrame()->Freeze();
  122. if( selection.GetSize() == 1 )
  123. {
  124. EDA_ITEM* item = (EDA_ITEM*) selection.Front();
  125. std::vector<MSG_PANEL_ITEM> msgItems;
  126. item->GetMsgPanelInfo( m_frame, msgItems );
  127. m_frame->SetMsgPanel( msgItems );
  128. DS_DATA_ITEM* dataItem = static_cast<DS_DRAW_ITEM_BASE*>( item )->GetPeer();
  129. m_frame->GetPropertiesFrame()->CopyPrmsFromItemToPanel( dataItem );
  130. }
  131. else
  132. {
  133. m_frame->UpdateMsgPanelInfo();
  134. m_frame->GetPropertiesFrame()->CopyPrmsFromItemToPanel( nullptr );
  135. }
  136. m_frame->GetPropertiesFrame()->CopyPrmsFromGeneralToPanel();
  137. // The Properties frame is updated. Reenable it:
  138. m_frame->GetPropertiesFrame()->Thaw();
  139. return 0;
  140. }
  141. void PL_EDITOR_CONTROL::setTransitions()
  142. {
  143. Go( &PL_EDITOR_CONTROL::New, ACTIONS::doNew.MakeEvent() );
  144. Go( &PL_EDITOR_CONTROL::Open, ACTIONS::open.MakeEvent() );
  145. Go( &PL_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() );
  146. Go( &PL_EDITOR_CONTROL::SaveAs, ACTIONS::saveAs.MakeEvent() );
  147. Go( &PL_EDITOR_CONTROL::Print, ACTIONS::print.MakeEvent() );
  148. Go( &PL_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() );
  149. Go( &PL_EDITOR_CONTROL::PageSetup, PL_ACTIONS::previewSettings.MakeEvent() );
  150. Go( &PL_EDITOR_CONTROL::ShowInspector, PL_ACTIONS::showInspector.MakeEvent() );
  151. Go( &PL_EDITOR_CONTROL::TitleBlockDisplayMode, PL_ACTIONS::layoutEditMode.MakeEvent() );
  152. Go( &PL_EDITOR_CONTROL::TitleBlockDisplayMode, PL_ACTIONS::layoutNormalMode.MakeEvent() );
  153. Go( &PL_EDITOR_CONTROL::UpdateMessagePanel, EVENTS::SelectedEvent );
  154. Go( &PL_EDITOR_CONTROL::UpdateMessagePanel, EVENTS::UnselectedEvent );
  155. Go( &PL_EDITOR_CONTROL::UpdateMessagePanel, EVENTS::ClearedEvent );
  156. Go( &PL_EDITOR_CONTROL::UpdateMessagePanel, EVENTS::SelectedItemsModified );
  157. }