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.

194 lines
5.7 KiB

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