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>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <class_base_screen.h>
|
|
|
|
#include <drawtxt.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <wxstruct.h>
|
|
|
|
#include <appl_wxstruct.h>
|
2012-04-01 20:51:56 +00:00
|
|
|
#include <kicad_string.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <worksheet.h>
|
|
|
|
#include <class_title_block.h>
|
|
|
|
#include <build_version.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2013-05-19 19:35:49 +00:00
|
|
|
// include data which defines the shape of a title block
|
|
|
|
// and frame references
|
2013-05-21 07:18:25 +00:00
|
|
|
#include <worksheet_shape_builder.h>
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
#if defined(KICAD_GOST)
|
2013-05-19 19:35:49 +00:00
|
|
|
#include "title_block_shapes_gost.h"
|
2013-03-27 20:38:20 +00:00
|
|
|
#else
|
2013-05-19 19:35:49 +00:00
|
|
|
#include "title_block_shapes.h"
|
2013-03-27 20:38:20 +00:00
|
|
|
#endif
|
2008-03-04 14:27:48 +00:00
|
|
|
|
2013-05-22 08:45:25 +00:00
|
|
|
void DrawPageLayout( wxDC* aDC, EDA_DRAW_PANEL * aCanvas,
|
|
|
|
const PAGE_INFO& aPageInfo,
|
|
|
|
const wxString& aPaperFormat,
|
|
|
|
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 );
|
|
|
|
|
|
|
|
drawList.BuildWorkSheetGraphicList(
|
|
|
|
aPaperFormat, aFullSheetName, aFileName,
|
|
|
|
aTitleBlock, aSheetCount, aSheetNumber,
|
|
|
|
aLineColor, aTextColor );
|
|
|
|
|
|
|
|
// 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
|
|
|
wxString paper = pageInfo.GetType();
|
|
|
|
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,
|
|
|
|
paper, aFilename, GetScreenDesc(), t_block,
|
|
|
|
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
|
|
|
{
|
2008-03-04 14:27:48 +00:00
|
|
|
wxString msg;
|
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
msg << GetScreen()->m_ScreenNumber << wxT( "/" )
|
2012-05-27 00:19:12 +00:00
|
|
|
<< GetScreen()->m_NumberOfScreens;
|
2008-03-04 14:27:48 +00:00
|
|
|
return msg;
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|