2013-09-11 12:42:12 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 CERN
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2013-10-02 12:26:14 +00:00
|
|
|
* @file worksheet_viewitem.cpp
|
2013-09-11 12:42:12 +00:00
|
|
|
* @brief Class that handles properties and drawing of worksheet layout.
|
|
|
|
*/
|
|
|
|
|
2013-10-02 12:26:14 +00:00
|
|
|
#include <worksheet_viewitem.h>
|
2013-09-11 12:42:12 +00:00
|
|
|
#include <worksheet_shape_builder.h>
|
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
|
|
|
#include <painter.h>
|
|
|
|
#include <layers_id_colors_and_visibility.h>
|
2018-01-29 10:37:29 +00:00
|
|
|
#include <page_info.h>
|
2016-12-02 17:58:12 +00:00
|
|
|
#include <view/view.h>
|
2013-09-11 12:42:12 +00:00
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
using namespace KIGFX;
|
2013-09-11 12:42:12 +00:00
|
|
|
|
2018-06-01 07:11:43 +00:00
|
|
|
WORKSHEET_VIEWITEM::WORKSHEET_VIEWITEM( int aMils2IUscalefactor,
|
|
|
|
const PAGE_INFO* aPageInfo, const TITLE_BLOCK* aTitleBlock ) :
|
2013-09-11 12:42:12 +00:00
|
|
|
EDA_ITEM( NOT_USED ), // this item is never added to a BOARD so it needs no type
|
2018-06-01 07:11:43 +00:00
|
|
|
m_mils2IUscalefactor( aMils2IUscalefactor ),
|
2013-09-11 12:42:12 +00:00
|
|
|
m_titleBlock( aTitleBlock ), m_pageInfo( aPageInfo ), m_sheetNumber( 1 ), m_sheetCount( 1 ) {}
|
|
|
|
|
|
|
|
|
2013-10-02 12:26:14 +00:00
|
|
|
void WORKSHEET_VIEWITEM::SetPageInfo( const PAGE_INFO* aPageInfo )
|
2013-09-11 12:42:12 +00:00
|
|
|
{
|
|
|
|
m_pageInfo = aPageInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-02 12:26:14 +00:00
|
|
|
void WORKSHEET_VIEWITEM::SetTitleBlock( const TITLE_BLOCK* aTitleBlock )
|
2013-09-11 12:42:12 +00:00
|
|
|
{
|
|
|
|
m_titleBlock = aTitleBlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-02 12:26:14 +00:00
|
|
|
const BOX2I WORKSHEET_VIEWITEM::ViewBBox() const
|
2013-09-11 12:42:12 +00:00
|
|
|
{
|
|
|
|
BOX2I bbox;
|
|
|
|
|
|
|
|
if( m_pageInfo != NULL )
|
|
|
|
{
|
|
|
|
bbox.SetOrigin( VECTOR2I( 0, 0 ) );
|
2018-06-01 07:11:43 +00:00
|
|
|
bbox.SetEnd( VECTOR2I( m_pageInfo->GetWidthMils() * m_mils2IUscalefactor,
|
|
|
|
m_pageInfo->GetHeightMils() * m_mils2IUscalefactor ) );
|
2013-09-11 12:42:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bbox.SetMaximum();
|
|
|
|
}
|
|
|
|
|
|
|
|
return bbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-02 17:58:12 +00:00
|
|
|
void WORKSHEET_VIEWITEM::ViewDraw( int aLayer, VIEW* aView ) const
|
2013-09-11 12:42:12 +00:00
|
|
|
{
|
2016-12-02 17:58:12 +00:00
|
|
|
auto gal = aView->GetGAL();
|
|
|
|
auto settings = aView->GetPainter()->GetSettings();
|
2013-09-29 10:57:20 +00:00
|
|
|
wxString fileName( m_fileName.c_str(), wxConvUTF8 );
|
|
|
|
wxString sheetName( m_sheetName.c_str(), wxConvUTF8 );
|
2013-09-11 12:42:12 +00:00
|
|
|
WS_DRAW_ITEM_LIST drawList;
|
|
|
|
|
|
|
|
drawList.SetPenSize( settings->GetWorksheetLineWidth() );
|
2018-06-01 07:11:43 +00:00
|
|
|
// Adjust the scaling factor for worksheet items:
|
|
|
|
// worksheet items coordinates and sizes are stored in mils,
|
|
|
|
// and must be scaled to the same units as the caller
|
|
|
|
drawList.SetMilsToIUfactor( m_mils2IUscalefactor );
|
2013-09-11 12:42:12 +00:00
|
|
|
drawList.SetSheetNumber( m_sheetNumber );
|
|
|
|
drawList.SetSheetCount( m_sheetCount );
|
|
|
|
drawList.SetFileName( fileName );
|
|
|
|
drawList.SetSheetName( sheetName );
|
|
|
|
|
|
|
|
COLOR4D color = settings->GetColor( this, aLayer );
|
2017-02-20 16:57:41 +00:00
|
|
|
drawList.BuildWorkSheetGraphicList( *m_pageInfo, *m_titleBlock, color, color );
|
2013-09-11 12:42:12 +00:00
|
|
|
|
|
|
|
// Draw all the components that make the page layout
|
|
|
|
WS_DRAW_ITEM_BASE* item = drawList.GetFirst();
|
|
|
|
while( item )
|
|
|
|
{
|
|
|
|
switch( item->GetType() )
|
|
|
|
{
|
|
|
|
case WS_DRAW_ITEM_BASE::wsg_line:
|
2016-12-02 17:58:12 +00:00
|
|
|
draw( static_cast<const WS_DRAW_ITEM_LINE*>( item ), gal );
|
2013-09-11 12:42:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WS_DRAW_ITEM_BASE::wsg_rect:
|
2016-12-02 17:58:12 +00:00
|
|
|
draw( static_cast<const WS_DRAW_ITEM_RECT*>( item ), gal );
|
2013-09-11 12:42:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WS_DRAW_ITEM_BASE::wsg_poly:
|
2016-12-02 17:58:12 +00:00
|
|
|
draw( static_cast<const WS_DRAW_ITEM_POLYGON*>( item ), gal );
|
2013-09-11 12:42:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WS_DRAW_ITEM_BASE::wsg_text:
|
2016-12-02 17:58:12 +00:00
|
|
|
draw( static_cast<const WS_DRAW_ITEM_TEXT*>( item ), gal );
|
2013-09-11 12:42:12 +00:00
|
|
|
break;
|
2013-10-31 21:30:57 +00:00
|
|
|
|
|
|
|
case WS_DRAW_ITEM_BASE::wsg_bitmap:
|
|
|
|
break;
|
2013-09-11 12:42:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
item = drawList.GetNext();
|
|
|
|
}
|
2013-09-17 12:46:48 +00:00
|
|
|
|
|
|
|
// Draw gray line that outlines the sheet size
|
2018-07-01 08:24:57 +00:00
|
|
|
if( settings->GetShowPageLimits() )
|
|
|
|
drawBorder( gal );
|
2013-09-11 12:42:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-02 12:26:14 +00:00
|
|
|
void WORKSHEET_VIEWITEM::ViewGetLayers( int aLayers[], int& aCount ) const
|
2013-09-11 12:42:12 +00:00
|
|
|
{
|
|
|
|
aCount = 1;
|
2017-03-13 03:19:33 +00:00
|
|
|
aLayers[0] = LAYER_WORKSHEET;
|
2013-09-11 12:42:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-02 12:26:14 +00:00
|
|
|
void WORKSHEET_VIEWITEM::draw( const WS_DRAW_ITEM_LINE* aItem, GAL* aGal ) const
|
2013-09-11 12:42:12 +00:00
|
|
|
{
|
|
|
|
aGal->SetIsStroke( true );
|
|
|
|
aGal->SetIsFill( false );
|
|
|
|
aGal->SetStrokeColor( COLOR4D( aItem->GetColor() ) );
|
|
|
|
aGal->SetLineWidth( aItem->GetPenWidth() );
|
|
|
|
aGal->DrawLine( VECTOR2D( aItem->GetStart() ), VECTOR2D( aItem->GetEnd() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-02 12:26:14 +00:00
|
|
|
void WORKSHEET_VIEWITEM::draw( const WS_DRAW_ITEM_RECT* aItem, GAL* aGal ) const
|
2013-09-11 12:42:12 +00:00
|
|
|
{
|
|
|
|
aGal->SetIsStroke( true );
|
|
|
|
aGal->SetIsFill( false );
|
|
|
|
aGal->SetStrokeColor( COLOR4D( aItem->GetColor() ) );
|
|
|
|
aGal->SetLineWidth( aItem->GetPenWidth() );
|
|
|
|
aGal->DrawRectangle( VECTOR2D( aItem->GetStart() ), VECTOR2D( aItem->GetEnd() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-02 12:26:14 +00:00
|
|
|
void WORKSHEET_VIEWITEM::draw( const WS_DRAW_ITEM_POLYGON* aItem, GAL* aGal ) const
|
2013-09-11 12:42:12 +00:00
|
|
|
{
|
|
|
|
std::deque<VECTOR2D> corners;
|
2016-06-29 20:07:55 +00:00
|
|
|
for( wxPoint point : aItem->m_Corners )
|
2013-09-11 12:42:12 +00:00
|
|
|
{
|
|
|
|
corners.push_back( VECTOR2D( point ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aItem->IsFilled() )
|
|
|
|
{
|
|
|
|
aGal->SetFillColor( COLOR4D( aItem->GetColor() ) );
|
|
|
|
aGal->SetIsFill( true );
|
|
|
|
aGal->SetIsStroke( false );
|
|
|
|
aGal->DrawPolygon( corners );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aGal->SetStrokeColor( COLOR4D( aItem->GetColor() ) );
|
|
|
|
aGal->SetIsFill( false );
|
|
|
|
aGal->SetIsStroke( true );
|
|
|
|
aGal->SetLineWidth( aItem->GetPenWidth() );
|
|
|
|
aGal->DrawPolyline( corners );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-02 12:26:14 +00:00
|
|
|
void WORKSHEET_VIEWITEM::draw( const WS_DRAW_ITEM_TEXT* aItem, GAL* aGal ) const
|
2013-09-11 12:42:12 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
VECTOR2D position( aItem->GetTextPos().x, aItem->GetTextPos().y );
|
2013-09-11 12:42:12 +00:00
|
|
|
|
2014-09-08 12:06:01 +00:00
|
|
|
aGal->Save();
|
|
|
|
aGal->Translate( position );
|
2017-01-23 20:30:11 +00:00
|
|
|
aGal->Rotate( -aItem->GetTextAngle() * M_PI / 1800.0 );
|
2013-09-11 12:42:12 +00:00
|
|
|
aGal->SetStrokeColor( COLOR4D( aItem->GetColor() ) );
|
|
|
|
aGal->SetLineWidth( aItem->GetThickness() );
|
|
|
|
aGal->SetTextAttributes( aItem );
|
2014-09-13 18:15:45 +00:00
|
|
|
aGal->StrokeText( aItem->GetShownText(), VECTOR2D( 0, 0 ), 0.0 );
|
2014-09-08 12:06:01 +00:00
|
|
|
aGal->Restore();
|
2013-09-11 12:42:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-02 12:26:14 +00:00
|
|
|
void WORKSHEET_VIEWITEM::drawBorder( GAL* aGal ) const
|
2013-09-11 12:42:12 +00:00
|
|
|
{
|
|
|
|
VECTOR2D origin = VECTOR2D( 0.0, 0.0 );
|
|
|
|
VECTOR2D end = VECTOR2D( m_pageInfo->GetWidthMils() * 25400,
|
|
|
|
m_pageInfo->GetHeightMils() * 25400 );
|
|
|
|
|
|
|
|
aGal->SetIsStroke( true );
|
2016-02-09 08:23:24 +00:00
|
|
|
// Use a gray color for the border color
|
|
|
|
aGal->SetStrokeColor( COLOR4D( 0.4, 0.4, 0.4, 1.0 ) );
|
2013-09-11 12:42:12 +00:00
|
|
|
aGal->SetIsFill( false );
|
|
|
|
aGal->DrawRectangle( origin, end );
|
|
|
|
}
|