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.

94 lines
3.0 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 <drawing_sheet/ds_proxy_undo_item.h>
  24. #include <drawing_sheet/ds_data_item.h>
  25. #include <drawing_sheet/ds_data_model.h>
  26. #include <view/view.h>
  27. #include <eda_draw_frame.h>
  28. #include <macros.h>
  29. using namespace KIGFX;
  30. DS_PROXY_UNDO_ITEM::DS_PROXY_UNDO_ITEM( const EDA_DRAW_FRAME* aFrame ) :
  31. EDA_ITEM( aFrame ? WS_PROXY_UNDO_ITEM_PLUS_T : WS_PROXY_UNDO_ITEM_T ),
  32. m_selectedDataItem( INT_MAX ),
  33. m_selectedDrawItem( INT_MAX )
  34. {
  35. if( aFrame )
  36. {
  37. m_pageInfo = aFrame->GetPageSettings();
  38. m_titleBlock = aFrame->GetTitleBlock();
  39. }
  40. DS_DATA_MODEL& model = DS_DATA_MODEL::GetTheInstance();
  41. model.SaveInString( &m_layoutSerialization );
  42. for( size_t ii = 0; ii < model.GetItems().size(); ++ii )
  43. {
  44. DS_DATA_ITEM* dataItem = model.GetItem( ii );
  45. for( size_t jj = 0; jj < dataItem->GetDrawItems().size(); ++jj )
  46. {
  47. DS_DRAW_ITEM_BASE* drawItem = dataItem->GetDrawItems()[ jj ];
  48. if( drawItem->IsSelected() )
  49. {
  50. m_selectedDataItem = ii;
  51. m_selectedDrawItem = jj;
  52. break;
  53. }
  54. }
  55. }
  56. }
  57. void DS_PROXY_UNDO_ITEM::Restore( EDA_DRAW_FRAME* aFrame, KIGFX::VIEW* aView )
  58. {
  59. if( Type() == WS_PROXY_UNDO_ITEM_PLUS_T )
  60. {
  61. aFrame->SetPageSettings( m_pageInfo );
  62. aFrame->SetTitleBlock( m_titleBlock );
  63. }
  64. DS_DATA_MODEL::GetTheInstance().SetPageLayout( TO_UTF8( m_layoutSerialization ) );
  65. if( aView )
  66. {
  67. aView->Clear();
  68. for( int ii = 0; ii < (int)DS_DATA_MODEL::GetTheInstance().GetItems().size(); ++ii )
  69. {
  70. DS_DATA_ITEM* dataItem = DS_DATA_MODEL::GetTheInstance().GetItem( ii );
  71. dataItem->SyncDrawItems( nullptr, aView );
  72. if( ii == m_selectedDataItem && m_selectedDrawItem < (int)dataItem->GetDrawItems().size() )
  73. {
  74. DS_DRAW_ITEM_BASE* drawItem = dataItem->GetDrawItems()[ m_selectedDrawItem ];
  75. drawItem->SetSelected();
  76. }
  77. }
  78. }
  79. }