2019-05-20 10:23:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
2020-03-26 11:02:59 +00:00
|
|
|
* Copyright (C) 2013-2020 CERN
|
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
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2021-07-29 09:47:43 +00:00
|
|
|
#include <layer_ids.h>
|
2019-05-20 10:23:32 +00:00
|
|
|
#include <page_info.h>
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_proxy_view_item.h>
|
|
|
|
#include <drawing_sheet/ds_draw_item.h>
|
|
|
|
#include <drawing_sheet/ds_data_item.h>
|
|
|
|
#include <drawing_sheet/ds_painter.h>
|
2020-10-24 14:45:37 +00:00
|
|
|
#include <project.h>
|
2019-05-20 10:23:32 +00:00
|
|
|
#include <view/view.h>
|
|
|
|
|
|
|
|
using namespace KIGFX;
|
|
|
|
|
2023-06-12 21:33:55 +00:00
|
|
|
DS_PROXY_VIEW_ITEM::DS_PROXY_VIEW_ITEM( const EDA_IU_SCALE& aIuScale, const PAGE_INFO* aPageInfo,
|
2022-09-20 14:25:03 +00:00
|
|
|
const PROJECT* aProject, const TITLE_BLOCK* aTitleBlock,
|
|
|
|
const std::map<wxString, wxString>* aProperties ) :
|
2019-05-26 15:36:40 +00:00
|
|
|
EDA_ITEM( NOT_USED ), // this item is never added to a BOARD so it needs no type
|
2023-06-12 21:33:55 +00:00
|
|
|
m_iuScale( aIuScale ),
|
2019-05-26 15:36:40 +00:00
|
|
|
m_titleBlock( aTitleBlock ),
|
|
|
|
m_pageInfo( aPageInfo ),
|
2020-10-18 20:30:37 +00:00
|
|
|
m_pageNumber( "1" ),
|
2020-01-13 01:44:19 +00:00
|
|
|
m_sheetCount( 1 ),
|
2020-10-25 09:02:07 +00:00
|
|
|
m_isFirstPage( false ),
|
2020-03-26 11:02:59 +00:00
|
|
|
m_project( aProject ),
|
2022-09-20 14:25:03 +00:00
|
|
|
m_properties( aProperties ),
|
2021-02-22 16:37:43 +00:00
|
|
|
m_colorLayer( LAYER_DRAWINGSHEET ),
|
2022-03-24 14:10:47 +00:00
|
|
|
m_pageBorderColorLayer( LAYER_PAGE_LIMITS )
|
2019-05-26 15:36:40 +00:00
|
|
|
{
|
|
|
|
}
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
const BOX2I DS_PROXY_VIEW_ITEM::ViewBBox() const
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
|
|
|
BOX2I bbox;
|
|
|
|
|
2023-06-12 21:33:55 +00:00
|
|
|
if( m_pageInfo )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
|
|
|
bbox.SetOrigin( VECTOR2I( 0, 0 ) );
|
2023-06-12 21:33:55 +00:00
|
|
|
bbox.SetEnd( VECTOR2I( m_iuScale.MilsToIU( m_pageInfo->GetWidthMils() ),
|
|
|
|
m_iuScale.MilsToIU( m_pageInfo->GetHeightMils() ) ) );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bbox.SetMaximum();
|
|
|
|
}
|
|
|
|
|
|
|
|
return bbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-20 14:25:03 +00:00
|
|
|
void DS_PROXY_VIEW_ITEM::buildDrawList( VIEW* aView,
|
|
|
|
const std::map<wxString, wxString>* aProperties,
|
|
|
|
DS_DRAW_ITEM_LIST* aDrawList ) const
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2020-05-02 23:06:43 +00:00
|
|
|
RENDER_SETTINGS* settings = aView->GetPainter()->GetSettings();
|
|
|
|
wxString fileName( m_fileName.c_str(), wxConvUTF8 );
|
|
|
|
wxString sheetName( m_sheetName.c_str(), wxConvUTF8 );
|
2022-04-09 14:38:47 +00:00
|
|
|
wxString sheetPath( m_sheetPath.c_str(), wxConvUTF8 );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2021-02-22 16:37:43 +00:00
|
|
|
aDrawList->SetDefaultPenSize( (int) settings->GetDrawingSheetLineWidth() );
|
2020-10-18 20:30:37 +00:00
|
|
|
aDrawList->SetIsFirstPage( m_isFirstPage );
|
|
|
|
aDrawList->SetPageNumber( m_pageNumber );
|
2020-05-02 23:06:43 +00:00
|
|
|
aDrawList->SetSheetCount( m_sheetCount );
|
|
|
|
aDrawList->SetFileName( fileName );
|
|
|
|
aDrawList->SetSheetName( sheetName );
|
2022-04-09 14:38:47 +00:00
|
|
|
aDrawList->SetSheetPath( sheetPath );
|
2022-06-10 13:09:22 +00:00
|
|
|
aDrawList->SetSheetLayer( settings->GetLayerName() );
|
2020-05-02 23:06:43 +00:00
|
|
|
aDrawList->SetProject( m_project );
|
2022-09-20 14:25:03 +00:00
|
|
|
aDrawList->SetProperties( aProperties );
|
2020-05-02 23:06:43 +00:00
|
|
|
|
2021-02-22 16:37:43 +00:00
|
|
|
aDrawList->BuildDrawItemsList( *m_pageInfo, *m_titleBlock );
|
2020-05-02 23:06:43 +00:00
|
|
|
}
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2020-05-02 23:06:43 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_PROXY_VIEW_ITEM::ViewDraw( int aLayer, VIEW* aView ) const
|
2020-05-02 23:06:43 +00:00
|
|
|
{
|
|
|
|
GAL* gal = aView->GetGAL();
|
|
|
|
RENDER_SETTINGS* settings = aView->GetPainter()->GetSettings();
|
2023-06-12 21:33:55 +00:00
|
|
|
DS_DRAW_ITEM_LIST drawList( m_iuScale );
|
2020-05-02 23:06:43 +00:00
|
|
|
|
2022-09-20 14:25:03 +00:00
|
|
|
buildDrawList( aView, m_properties, &drawList );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
// Draw the title block normally even if the view is flipped
|
|
|
|
bool flipped = gal->IsFlippedX();
|
|
|
|
|
|
|
|
if( flipped )
|
|
|
|
{
|
|
|
|
gal->Save();
|
2023-06-12 21:33:55 +00:00
|
|
|
gal->Translate( VECTOR2D( m_iuScale.MilsToIU( m_pageInfo->GetWidthMils() ), 0 ) );
|
2019-05-20 10:23:32 +00:00
|
|
|
gal->Scale( VECTOR2D( -1.0, 1.0 ) );
|
|
|
|
}
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_PAINTER ws_painter( gal );
|
|
|
|
auto ws_settings = static_cast<DS_RENDER_SETTINGS*>( ws_painter.GetSettings() );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
ws_settings->SetNormalColor( settings->GetLayerColor( m_colorLayer ) );
|
2019-05-20 10:23:32 +00:00
|
|
|
ws_settings->SetSelectedColor( settings->GetLayerColor( LAYER_SELECT_OVERLAY ) );
|
|
|
|
ws_settings->SetBrightenedColor( settings->GetLayerColor( LAYER_BRIGHTENED ) );
|
2020-08-07 21:12:10 +00:00
|
|
|
ws_settings->SetPageBorderColor( settings->GetLayerColor( m_pageBorderColorLayer ) );
|
2022-10-22 20:32:10 +00:00
|
|
|
ws_settings->SetDefaultFont( settings->GetDefaultFont() );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2021-05-30 22:56:24 +00:00
|
|
|
// Draw all the components that make the drawing sheet
|
2023-05-27 15:30:12 +00:00
|
|
|
BOX2I viewport( aView->GetViewport().GetOrigin(), aView->GetViewport().GetSize() );
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
for( DS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
|
2023-05-27 15:30:12 +00:00
|
|
|
{
|
|
|
|
if( viewport.Intersects( item->GetApproxBBox() ) )
|
|
|
|
ws_painter.Draw( item, LAYER_DRAWINGSHEET );
|
|
|
|
}
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
// Draw gray line that outlines the sheet size
|
|
|
|
if( settings->GetShowPageLimits() )
|
2023-06-12 21:33:55 +00:00
|
|
|
ws_painter.DrawBorder( m_pageInfo, m_iuScale.IU_PER_MILS );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
if( flipped )
|
|
|
|
gal->Restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_PROXY_VIEW_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
|
|
|
aCount = 1;
|
2021-02-22 16:37:43 +00:00
|
|
|
aLayers[0] = LAYER_DRAWINGSHEET;
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool DS_PROXY_VIEW_ITEM::HitTestDrawingSheetItems( VIEW* aView, const VECTOR2I& aPosition )
|
2020-05-02 23:06:43 +00:00
|
|
|
{
|
|
|
|
int accuracy = (int) aView->ToWorld( 5.0 ); // five pixels at current zoom
|
2023-06-12 21:33:55 +00:00
|
|
|
DS_DRAW_ITEM_LIST drawList( m_iuScale );
|
2020-05-02 23:06:43 +00:00
|
|
|
|
2022-09-20 14:25:03 +00:00
|
|
|
buildDrawList( aView, m_properties, &drawList );
|
2020-05-02 23:06:43 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
for( DS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
|
2020-05-02 23:06:43 +00:00
|
|
|
{
|
|
|
|
if( item->HitTest( aPosition, accuracy ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|