2019-05-20 10:23:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-06-12 21:33:55 +00:00
|
|
|
* Copyright (C) 2018-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-05-20 10:23:32 +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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-10-13 05:04:31 +00:00
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
#include <view/view.h>
|
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <view/wx_view_controls.h>
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_proxy_view_item.h>
|
|
|
|
#include <drawing_sheet/ds_data_item.h>
|
|
|
|
#include <drawing_sheet/ds_data_model.h>
|
|
|
|
#include <drawing_sheet/ds_painter.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <pgm_base.h>
|
2020-03-26 11:02:59 +00:00
|
|
|
#include <kiway.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <settings/settings_manager.h>
|
2019-05-20 10:23:32 +00:00
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
|
|
|
|
2020-10-13 05:04:31 +00:00
|
|
|
#include "pl_draw_panel_gal.h"
|
|
|
|
#include "pl_editor_frame.h"
|
|
|
|
#include "pl_editor_settings.h"
|
|
|
|
#include "tools/pl_actions.h"
|
|
|
|
#include "tools/pl_selection_tool.h"
|
2020-12-02 17:33:59 +00:00
|
|
|
#include <zoom_defines.h>
|
2019-05-24 10:11:18 +00:00
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
using namespace std::placeholders;
|
|
|
|
|
|
|
|
|
|
|
|
PL_DRAW_PANEL_GAL::PL_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
|
|
|
|
const wxPoint& aPosition, const wxSize& aSize,
|
|
|
|
KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
|
|
|
|
EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
|
|
|
|
{
|
|
|
|
m_view = new KIGFX::VIEW( true );
|
|
|
|
m_view->SetGAL( m_gal );
|
|
|
|
|
2022-09-17 00:45:14 +00:00
|
|
|
GetGAL()->SetWorldUnitLength( 1.0/drawSheetIUScale.IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
m_painter = std::make_unique<KIGFX::DS_PAINTER>( m_gal );
|
2020-03-06 04:06:11 +00:00
|
|
|
|
2020-08-02 17:42:35 +00:00
|
|
|
SETTINGS_MANAGER& settingsManager = Pgm().GetSettingsManager();
|
|
|
|
PL_EDITOR_SETTINGS* cfg = settingsManager.GetAppSettings<PL_EDITOR_SETTINGS>();
|
|
|
|
m_painter->GetSettings()->LoadColors( settingsManager.GetColorSettings( cfg->m_ColorTheme ) );
|
2020-03-06 04:06:11 +00:00
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
m_view->SetPainter( m_painter.get() );
|
2020-12-02 17:33:59 +00:00
|
|
|
// This fixes the zoom in and zoom out limits
|
|
|
|
m_view->SetScaleLimits( ZOOM_MAX_LIMIT_PLEDITOR, ZOOM_MIN_LIMIT_PLEDITOR );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
setDefaultLayerDeps();
|
|
|
|
|
2021-02-22 16:37:43 +00:00
|
|
|
m_view->SetLayerVisible( LAYER_DRAWINGSHEET, true );
|
|
|
|
m_view->SetLayerVisible( LAYER_DRAWINGSHEET_PAGE1, true );
|
|
|
|
m_view->SetLayerVisible( LAYER_DRAWINGSHEET_PAGEn, false );
|
2019-05-24 13:37:55 +00:00
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PL_DRAW_PANEL_GAL::~PL_DRAW_PANEL_GAL()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
void PL_DRAW_PANEL_GAL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
|
|
|
|
std::vector<MSG_PANEL_ITEM>& aList )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-30 22:56:24 +00:00
|
|
|
void PL_DRAW_PANEL_GAL::DisplayDrawingSheet()
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2019-05-24 10:11:18 +00:00
|
|
|
PL_SELECTION_TOOL* selTool = m_edaFrame->GetToolManager()->GetTool<PL_SELECTION_TOOL>();
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_MODEL& model = DS_DATA_MODEL::GetTheInstance();
|
2019-05-24 10:11:18 +00:00
|
|
|
|
|
|
|
selTool->GetSelection().Clear();
|
2019-05-20 10:23:32 +00:00
|
|
|
m_view->Clear();
|
|
|
|
|
2020-07-16 22:54:12 +00:00
|
|
|
m_pageDrawItem.reset();
|
|
|
|
|
2022-09-16 23:25:07 +00:00
|
|
|
model.SetupDrawEnvironment( m_edaFrame->GetPageSettings(), drawSheetIUScale.IU_PER_MILS );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2021-02-22 16:37:43 +00:00
|
|
|
// To show the formatted texts instead of raw texts in drawing sheet editor, we need
|
2021-02-22 23:47:17 +00:00
|
|
|
// a dummy DS_DRAW_ITEM_LIST.
|
2023-06-12 21:33:55 +00:00
|
|
|
DS_DRAW_ITEM_LIST dummy( drawSheetIUScale );
|
2023-01-18 01:16:57 +00:00
|
|
|
dummy.SetPaperFormat( m_edaFrame->GetPageSettings().GetType() );
|
2019-06-15 16:15:29 +00:00
|
|
|
dummy.SetTitleBlock( &m_edaFrame->GetTitleBlock() );
|
2020-03-26 11:02:59 +00:00
|
|
|
dummy.SetProject( &m_edaFrame->Prj() );
|
2019-06-15 16:15:29 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
for( DS_DATA_ITEM* dataItem : model.GetItems() )
|
2019-06-15 16:15:29 +00:00
|
|
|
dataItem->SyncDrawItems( &dummy, m_view );
|
2019-05-24 10:11:18 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
// Build and add a DS_DRAW_ITEM_PAGE to show the page limits and the corner position
|
2019-06-07 10:42:28 +00:00
|
|
|
// of the selected corner for coord origin of new items
|
2021-02-22 23:47:17 +00:00
|
|
|
// Not also this item has no peer in DS_DATA_MODEL list.
|
2019-06-07 10:42:28 +00:00
|
|
|
const int penWidth = 0; // This value is to use the default thickness line
|
2022-09-16 11:33:56 +00:00
|
|
|
constexpr double markerSize = drawSheetIUScale.mmToIU( 5 );
|
2021-02-22 23:47:17 +00:00
|
|
|
m_pageDrawItem = std::make_unique<DS_DRAW_ITEM_PAGE>( penWidth, markerSize );
|
2020-07-16 22:54:12 +00:00
|
|
|
m_view->Add( m_pageDrawItem.get() );
|
2019-06-07 10:42:28 +00:00
|
|
|
|
2019-05-24 10:11:18 +00:00
|
|
|
selTool->RebuildSelection();
|
2019-05-31 10:05:16 +00:00
|
|
|
|
|
|
|
// Gives a reasonable boundary to the view area
|
|
|
|
// Otherwise scroll bars are not usable
|
2021-05-30 22:56:24 +00:00
|
|
|
// A full size = 2 * page size allows a margin around the drawing sheet.
|
2019-05-31 10:05:16 +00:00
|
|
|
// (Note: no need to have a large working area: nothing can be drawn outside th page size).
|
|
|
|
double size_x = m_edaFrame->GetPageSizeIU().x;
|
|
|
|
double size_y = m_edaFrame->GetPageSizeIU().y;
|
2021-09-16 09:55:21 +00:00
|
|
|
BOX2D boundary( VECTOR2D( -size_x/4 , -size_y/4 ), VECTOR2D( size_x * 1.5, size_y * 1.5) );
|
2019-05-31 10:05:16 +00:00
|
|
|
m_view->SetBoundary( boundary );
|
|
|
|
|
2020-07-16 22:54:12 +00:00
|
|
|
m_pageDrawItem->SetPageSize( m_edaFrame->GetPageSizeIU() );
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I originCoord = static_cast<PL_EDITOR_FRAME*>( m_edaFrame )->ReturnCoordOriginCorner();
|
2020-07-16 22:54:12 +00:00
|
|
|
m_pageDrawItem->SetMarkerPos( originCoord );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PL_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType )
|
|
|
|
{
|
|
|
|
bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
|
|
|
|
|
|
|
|
setDefaultLayerDeps();
|
|
|
|
|
2022-09-17 00:45:14 +00:00
|
|
|
GetGAL()->SetWorldUnitLength( 1.0/drawSheetIUScale.IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PL_DRAW_PANEL_GAL::setDefaultLayerDeps()
|
|
|
|
{
|
|
|
|
for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
|
|
|
|
m_view->SetLayerTarget( i, KIGFX::TARGET_NONCACHED );
|
|
|
|
|
2021-02-22 16:37:43 +00:00
|
|
|
m_view->SetLayerDisplayOnly( LAYER_DRAWINGSHEET );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
m_view->SetLayerTarget( LAYER_SELECT_OVERLAY, KIGFX::TARGET_OVERLAY );
|
|
|
|
m_view->SetLayerDisplayOnly( LAYER_SELECT_OVERLAY );
|
|
|
|
|
|
|
|
m_view->SetLayerTarget( LAYER_GP_OVERLAY, KIGFX::TARGET_OVERLAY );
|
|
|
|
m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PL_DRAW_PANEL_GAL::SetTopLayer( int aLayer )
|
|
|
|
{
|
|
|
|
m_view->ClearTopLayers();
|
|
|
|
m_view->SetTopLayer( aLayer );
|
|
|
|
|
|
|
|
m_view->SetTopLayer( LAYER_SELECT_OVERLAY );
|
|
|
|
|
|
|
|
m_view->SetTopLayer( LAYER_GP_OVERLAY );
|
|
|
|
|
|
|
|
m_view->UpdateAllLayersOrder();
|
|
|
|
}
|
|
|
|
|