2013-05-19 19:35:49 +00:00
|
|
|
/**
|
|
|
|
* @file worksheet.cpp
|
|
|
|
* @brief Common code to draw the title block and frame references
|
|
|
|
* @note it should include title_block_shape_gost.h or title_block_shape.h
|
|
|
|
* which defines most of draw shapes, and contains a part of the draw code
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2013 KiCad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
2013-05-25 09:01:44 +00:00
|
|
|
#include <appl_wxstruct.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <class_base_screen.h>
|
|
|
|
#include <drawtxt.h>
|
|
|
|
#include <wxstruct.h>
|
|
|
|
#include <worksheet.h>
|
|
|
|
#include <class_title_block.h>
|
2013-05-25 09:01:44 +00:00
|
|
|
#include <build_version.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2013-05-21 07:18:25 +00:00
|
|
|
#include <worksheet_shape_builder.h>
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2013-05-30 19:32:00 +00:00
|
|
|
static const wxString productName = wxT( "KiCad E.D.A. " );
|
|
|
|
|
|
|
|
|
2013-05-22 08:45:25 +00:00
|
|
|
void DrawPageLayout( wxDC* aDC, EDA_DRAW_PANEL * aCanvas,
|
|
|
|
const PAGE_INFO& aPageInfo,
|
|
|
|
const wxString &aFullSheetName,
|
|
|
|
const wxString& aFileName,
|
|
|
|
TITLE_BLOCK& aTitleBlock,
|
|
|
|
int aSheetCount, int aSheetNumber,
|
|
|
|
int aPenWidth, double aScalar,
|
|
|
|
EDA_COLOR_T aLineColor, EDA_COLOR_T aTextColor )
|
|
|
|
{
|
|
|
|
GRSetDrawMode( aDC, GR_COPY );
|
|
|
|
WS_DRAW_ITEM_LIST drawList;
|
|
|
|
|
|
|
|
wxPoint LTmargin( aPageInfo.GetLeftMarginMils(), aPageInfo.GetTopMarginMils() );
|
|
|
|
wxPoint RBmargin( aPageInfo.GetRightMarginMils(), aPageInfo.GetBottomMarginMils() );
|
|
|
|
wxSize pagesize = aPageInfo.GetSizeMils();
|
|
|
|
|
|
|
|
drawList.SetMargins( LTmargin, RBmargin );
|
|
|
|
drawList.SetPenSize( aPenWidth );
|
|
|
|
drawList.SetMilsToIUfactor( aScalar );
|
|
|
|
drawList.SetPageSize( pagesize );
|
2013-05-24 08:59:40 +00:00
|
|
|
drawList.SetSheetNumber( aSheetNumber );
|
|
|
|
drawList.SetSheetCount( aSheetCount );
|
2013-05-22 08:45:25 +00:00
|
|
|
|
|
|
|
drawList.BuildWorkSheetGraphicList(
|
2013-05-25 09:01:44 +00:00
|
|
|
aPageInfo.GetType(), aFullSheetName, aFileName,
|
2013-05-24 08:59:40 +00:00
|
|
|
aTitleBlock, aLineColor, aTextColor );
|
2013-05-22 08:45:25 +00:00
|
|
|
|
|
|
|
// Draw item list
|
|
|
|
for( WS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item;
|
|
|
|
item = drawList.GetNext() )
|
|
|
|
{
|
|
|
|
switch( item->GetType() )
|
|
|
|
{
|
|
|
|
case WS_DRAW_ITEM_BASE::wsg_line:
|
|
|
|
{
|
|
|
|
WS_DRAW_ITEM_LINE* line = (WS_DRAW_ITEM_LINE*) item;
|
|
|
|
GRLine( aCanvas ? aCanvas->GetClipBox() : NULL, aDC,
|
|
|
|
line->GetStart(), line->GetEnd(),
|
|
|
|
line->GetPenWidth(), line->GetColor() );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WS_DRAW_ITEM_BASE::wsg_rect:
|
|
|
|
{
|
|
|
|
WS_DRAW_ITEM_RECT* rect = (WS_DRAW_ITEM_RECT*) item;
|
|
|
|
GRRect( aCanvas ? aCanvas->GetClipBox() : NULL, aDC,
|
|
|
|
rect->GetStart().x, rect->GetStart().y,
|
|
|
|
rect->GetEnd().x, rect->GetEnd().y,
|
|
|
|
rect->GetPenWidth(), rect->GetColor() );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WS_DRAW_ITEM_BASE::wsg_text:
|
|
|
|
{
|
|
|
|
WS_DRAW_ITEM_TEXT* text = (WS_DRAW_ITEM_TEXT*) item;
|
|
|
|
DrawGraphicText( aCanvas, aDC, text->GetTextPosition(),
|
|
|
|
text->GetColor(), text->GetText(),
|
|
|
|
text->GetOrientation(), text->GetSize(),
|
|
|
|
text->GetHorizJustify(), text->GetVertJustify(),
|
|
|
|
text->GetPenWidth(), text->IsItalic(), text->IsBold() );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WS_DRAW_ITEM_BASE::wsg_poly:
|
|
|
|
{
|
|
|
|
WS_DRAW_ITEM_POLYGON* poly = (WS_DRAW_ITEM_POLYGON*) item;
|
|
|
|
GRPoly( aCanvas ? aCanvas->GetClipBox() : NULL, aDC,
|
|
|
|
poly->m_Corners.size(), &poly->m_Corners[0],
|
2013-05-23 16:38:17 +00:00
|
|
|
poly->IsFilled() ? FILLED_SHAPE : NO_FILL,
|
|
|
|
poly->GetPenWidth(),
|
2013-05-22 08:45:25 +00:00
|
|
|
poly->GetColor(), poly->GetColor() );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-19 19:35:49 +00:00
|
|
|
|
2013-05-22 08:45:25 +00:00
|
|
|
void EDA_DRAW_FRAME::DrawWorkSheet( wxDC* aDC, BASE_SCREEN* aScreen, int aLineWidth,
|
2012-08-29 16:59:50 +00:00
|
|
|
double aScalar, const wxString &aFilename )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-12-14 20:03:15 +00:00
|
|
|
if( !m_showBorderAndTitleBlock )
|
2008-03-04 14:27:48 +00:00
|
|
|
return;
|
|
|
|
|
2011-12-22 21:57:50 +00:00
|
|
|
const PAGE_INFO& pageInfo = GetPageSettings();
|
|
|
|
wxSize pageSize = pageInfo.GetSizeMils();
|
|
|
|
|
2008-03-04 14:27:48 +00:00
|
|
|
// if not printing, draw the page limits:
|
2012-04-16 01:25:26 +00:00
|
|
|
if( !aScreen->m_IsPrinting && g_ShowPageLimits )
|
2008-03-04 14:27:48 +00:00
|
|
|
{
|
2012-04-16 01:25:26 +00:00
|
|
|
GRSetDrawMode( aDC, GR_COPY );
|
|
|
|
GRRect( m_canvas->GetClipBox(), aDC, 0, 0,
|
|
|
|
pageSize.x * aScalar, pageSize.y * aScalar, aLineWidth,
|
2009-04-05 20:49:15 +00:00
|
|
|
g_DrawBgColor == WHITE ? LIGHTGRAY : DARKDARKGRAY );
|
2008-03-04 14:27:48 +00:00
|
|
|
}
|
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
TITLE_BLOCK t_block = GetTitleBlock();
|
2013-05-22 08:45:25 +00:00
|
|
|
EDA_COLOR_T color = RED;
|
2012-03-26 21:45:05 +00:00
|
|
|
|
2013-05-22 08:45:25 +00:00
|
|
|
DrawPageLayout( aDC, m_canvas, pageInfo,
|
2013-05-25 09:01:44 +00:00
|
|
|
aFilename, GetScreenDesc(), t_block,
|
2013-05-22 08:45:25 +00:00
|
|
|
aScreen->m_NumberOfScreens, aScreen->m_ScreenNumber,
|
|
|
|
aLineWidth, aScalar, color, color );
|
2012-03-26 21:45:05 +00:00
|
|
|
}
|
2011-12-22 21:57:50 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
|
2012-09-02 12:06:47 +00:00
|
|
|
const wxString EDA_DRAW_FRAME::GetXYSheetReferences( const wxPoint& aPosition ) const
|
2008-07-31 15:30:57 +00:00
|
|
|
{
|
2011-12-22 21:57:50 +00:00
|
|
|
const PAGE_INFO& pageInfo = GetPageSettings();
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2011-12-22 21:57:50 +00:00
|
|
|
int ii;
|
|
|
|
int xg, yg;
|
|
|
|
int ipas;
|
|
|
|
int gxpas, gypas;
|
|
|
|
int refx, refy;
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
// Upper left corner
|
|
|
|
refx = pageInfo.GetLeftMarginMils();
|
|
|
|
refy = pageInfo.GetTopMarginMils();
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2011-12-22 21:57:50 +00:00
|
|
|
// lower right corner
|
|
|
|
xg = pageInfo.GetSizeMils().x - pageInfo.GetRightMarginMils();
|
|
|
|
yg = pageInfo.GetSizeMils().y - pageInfo.GetBottomMarginMils();
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2011-12-22 21:57:50 +00:00
|
|
|
// Get the Y axis identifier (A symbol A ... Z)
|
2012-04-01 20:51:56 +00:00
|
|
|
if( aPosition.y < refy || aPosition.y > yg ) // Outside of Y limits
|
2008-07-31 15:30:57 +00:00
|
|
|
msg << wxT( "?" );
|
|
|
|
else
|
|
|
|
{
|
2011-12-22 21:57:50 +00:00
|
|
|
ipas = ( yg - refy ) / PAS_REF; // ipas = Y count sections
|
|
|
|
gypas = ( yg - refy ) / ipas; // gypas = Y section size
|
2009-11-23 15:16:50 +00:00
|
|
|
ii = ( aPosition.y - refy ) / gypas;
|
2008-07-31 15:30:57 +00:00
|
|
|
msg.Printf( wxT( "%c" ), 'A' + ii );
|
|
|
|
}
|
|
|
|
|
2011-12-22 21:57:50 +00:00
|
|
|
// Get the X axis identifier (A number 1 ... n)
|
2012-04-01 20:51:56 +00:00
|
|
|
if( aPosition.x < refx || aPosition.x > xg ) // Outside of X limits
|
2008-07-31 15:30:57 +00:00
|
|
|
msg << wxT( "?" );
|
|
|
|
else
|
|
|
|
{
|
2011-12-22 21:57:50 +00:00
|
|
|
ipas = ( xg - refx ) / PAS_REF; // ipas = X count sections
|
|
|
|
gxpas = ( xg - refx ) / ipas; // gxpas = X section size
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
ii = ( aPosition.x - refx ) / gxpas;
|
2008-07-31 15:30:57 +00:00
|
|
|
msg << ii + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
wxString EDA_DRAW_FRAME::GetScreenDesc()
|
2008-02-12 21:12:46 +00:00
|
|
|
{
|
2013-05-27 09:17:37 +00:00
|
|
|
// Virtual function, in basic function, returns
|
|
|
|
// an empty string.
|
|
|
|
return wxEmptyString;
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
2012-04-01 20:51:56 +00:00
|
|
|
|
2013-05-25 09:01:44 +00:00
|
|
|
// returns the full text corresponding to the aTextbase,
|
|
|
|
// after replacing format symbols by the corresponding value
|
|
|
|
wxString WS_DRAW_ITEM_LIST::BuildFullText( const wxString& aTextbase )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
/* Known formats
|
|
|
|
* %% = replaced by %
|
|
|
|
* %K = Kicad version
|
|
|
|
* %Z = paper format name (A4, USLetter)
|
|
|
|
* %Y = company name
|
|
|
|
* %D = date
|
|
|
|
* %R = revision
|
|
|
|
* %S = sheet number
|
|
|
|
* %N = number of sheets
|
|
|
|
* %Cx = comment (x = 0 to 9 to identify the comment)
|
|
|
|
* %F = filename
|
|
|
|
* %P = sheet path (sheet full name)
|
|
|
|
* %T = title
|
|
|
|
*/
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < aTextbase.Len(); ii++ )
|
|
|
|
{
|
|
|
|
if( aTextbase[ii] != '%' )
|
|
|
|
{
|
|
|
|
msg << aTextbase[ii];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ii++;
|
|
|
|
if( ii >= aTextbase.Len() )
|
|
|
|
break;
|
|
|
|
|
|
|
|
wxChar format = aTextbase[ii];
|
|
|
|
switch( format )
|
|
|
|
{
|
|
|
|
case '%':
|
|
|
|
msg += '%';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'D':
|
|
|
|
msg += m_titleBlock->GetDate();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'R':
|
|
|
|
msg += m_titleBlock->GetRevision();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'K':
|
2013-05-30 19:32:00 +00:00
|
|
|
msg += productName + wxGetApp().GetAppName();
|
2013-05-25 09:01:44 +00:00
|
|
|
msg += wxT( " " ) + GetBuildVersion();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'Z':
|
|
|
|
msg += *m_paperFormat;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'S':
|
|
|
|
msg << m_sheetNumber;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'N':
|
|
|
|
msg << m_sheetCount;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'F':
|
|
|
|
{
|
|
|
|
wxFileName fn( *m_fileName );
|
|
|
|
msg += fn.GetFullName();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'P':
|
|
|
|
msg += *m_sheetFullName;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'Y':
|
|
|
|
msg = m_titleBlock->GetCompany();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'T':
|
|
|
|
msg += m_titleBlock->GetTitle();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'C':
|
|
|
|
format = aTextbase[++ii];
|
|
|
|
switch( format )
|
|
|
|
{
|
|
|
|
case '1':
|
|
|
|
msg += m_titleBlock->GetComment1();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '2':
|
|
|
|
msg += m_titleBlock->GetComment2();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '3':
|
|
|
|
msg += m_titleBlock->GetComment3();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '4':
|
|
|
|
msg += m_titleBlock->GetComment4();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2012-04-01 20:51:56 +00:00
|
|
|
|
|
|
|
void TITLE_BLOCK::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
|
|
|
|
throw( IO_ERROR )
|
|
|
|
{
|
|
|
|
// Don't write the title block information if there is nothing to write.
|
2013-05-23 18:45:23 +00:00
|
|
|
if( !m_title.IsEmpty() || !m_date.IsEmpty() || !m_revision.IsEmpty()
|
2012-04-01 20:51:56 +00:00
|
|
|
|| !m_company.IsEmpty() || !m_comment1.IsEmpty() || !m_comment2.IsEmpty()
|
|
|
|
|| !m_comment3.IsEmpty() || !m_comment4.IsEmpty() )
|
|
|
|
{
|
2013-05-23 18:45:23 +00:00
|
|
|
aFormatter->Print( aNestLevel, "(title_block\n" );
|
2012-04-01 20:51:56 +00:00
|
|
|
|
|
|
|
if( !m_title.IsEmpty() )
|
2012-06-09 17:00:13 +00:00
|
|
|
aFormatter->Print( aNestLevel+1, "(title %s)\n",
|
|
|
|
aFormatter->Quotew( m_title ).c_str() );
|
2012-04-01 20:51:56 +00:00
|
|
|
|
|
|
|
if( !m_date.IsEmpty() )
|
2012-06-09 17:00:13 +00:00
|
|
|
aFormatter->Print( aNestLevel+1, "(date %s)\n",
|
|
|
|
aFormatter->Quotew( m_date ).c_str() );
|
2012-04-01 20:51:56 +00:00
|
|
|
|
|
|
|
if( !m_revision.IsEmpty() )
|
2012-06-09 17:00:13 +00:00
|
|
|
aFormatter->Print( aNestLevel+1, "(rev %s)\n",
|
|
|
|
aFormatter->Quotew( m_revision ).c_str() );
|
2012-04-01 20:51:56 +00:00
|
|
|
|
|
|
|
if( !m_company.IsEmpty() )
|
2012-06-09 17:00:13 +00:00
|
|
|
aFormatter->Print( aNestLevel+1, "(company %s)\n",
|
|
|
|
aFormatter->Quotew( m_company ).c_str() );
|
2012-04-01 20:51:56 +00:00
|
|
|
|
|
|
|
if( !m_comment1.IsEmpty() )
|
2012-06-09 17:00:13 +00:00
|
|
|
aFormatter->Print( aNestLevel+1, "(comment 1 %s)\n",
|
|
|
|
aFormatter->Quotew( m_comment1 ).c_str() );
|
2012-04-01 20:51:56 +00:00
|
|
|
|
|
|
|
if( !m_comment2.IsEmpty() )
|
2012-06-09 17:00:13 +00:00
|
|
|
aFormatter->Print( aNestLevel+1, "(comment 2 %s)\n",
|
|
|
|
aFormatter->Quotew( m_comment2 ).c_str() );
|
2012-04-01 20:51:56 +00:00
|
|
|
|
|
|
|
if( !m_comment3.IsEmpty() )
|
2012-06-09 17:00:13 +00:00
|
|
|
aFormatter->Print( aNestLevel+1, "(comment 3 %s)\n",
|
|
|
|
aFormatter->Quotew( m_comment3 ).c_str() );
|
2012-04-01 20:51:56 +00:00
|
|
|
|
|
|
|
if( !m_comment4.IsEmpty() )
|
2012-06-09 17:00:13 +00:00
|
|
|
aFormatter->Print( aNestLevel+1, "(comment 4 %s)\n",
|
|
|
|
aFormatter->Quotew( m_comment4 ).c_str() );
|
2012-04-01 20:51:56 +00:00
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
aFormatter->Print( aNestLevel, ")\n\n" );
|
2012-04-01 20:51:56 +00:00
|
|
|
}
|
|
|
|
}
|