Added drawing of worksheet layout.

This commit is contained in:
Maciej Suminski 2013-09-11 14:42:12 +02:00
parent e2f5b2779f
commit 90a3b97c2f
8 changed files with 410 additions and 15 deletions

View File

@ -32,6 +32,7 @@ set(GAL_SRCS
# Common part
drawpanel_gal.cpp
painter.cpp
worksheet_item.cpp
gal/graphics_abstraction_layer.cpp
gal/stroke_font.cpp
gal/color4d.cpp
@ -156,13 +157,13 @@ set(COMMON_SRCS
system/fcontext.s
tool/tool_base.cpp
tool/tool_manager.cpp
tool/tool_dispatcher.cpp
tool/tool_event.cpp
tool/tool_interactive.cpp
tool/context_menu.cpp
)
tool/tool_base.cpp
tool/tool_manager.cpp
tool/tool_dispatcher.cpp
tool/tool_event.cpp
tool/tool_interactive.cpp
tool/context_menu.cpp
)
add_library(common STATIC ${COMMON_SRCS})

View File

@ -32,13 +32,14 @@ using namespace KiGfx;
RENDER_SETTINGS::RENDER_SETTINGS()
{
// Set the default initial values
m_highlightFactor = 0.5;
m_selectFactor = 0.5;
m_layerOpacity = 0.8;
m_highlightEnabled = false;
m_hiContrastEnabled = false;
m_hiContrastFactor = 0.2;
m_outlineWidth = 1;
m_highlightFactor = 0.5;
m_selectFactor = 0.5;
m_layerOpacity = 0.8;
m_highlightEnabled = false;
m_hiContrastEnabled = false;
m_hiContrastFactor = 0.2;
m_outlineWidth = 1;
m_worksheetLineWidth = 100000;
// Store the predefined colors used in KiCad in format used by GAL
for( int i = 0; i < NBCOLORS; i++ )

205
common/worksheet_item.cpp Normal file
View File

@ -0,0 +1,205 @@
/*
* 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
*/
/**
* @file worksheet_item.cpp
* @brief Class that handles properties and drawing of worksheet layout.
*/
#include <worksheet_item.h>
#include <worksheet_shape_builder.h>
#include <gal/graphics_abstraction_layer.h>
#include <painter.h>
#include <layers_id_colors_and_visibility.h>
#include <boost/foreach.hpp>
using namespace KiGfx;
WORKSHEET_ITEM::WORKSHEET_ITEM( const std::string& aFileName, const std::string& aSheetName,
const PAGE_INFO* aPageInfo, const TITLE_BLOCK* aTitleBlock ) :
EDA_ITEM( NOT_USED ), // this item is never added to a BOARD so it needs no type
m_fileName( aFileName ), m_sheetName( aSheetName ),
m_titleBlock( aTitleBlock ), m_pageInfo( aPageInfo ), m_sheetNumber( 1 ), m_sheetCount( 1 ) {}
void WORKSHEET_ITEM::SetPageInfo( const PAGE_INFO* aPageInfo )
{
m_pageInfo = aPageInfo;
ViewUpdate( GEOMETRY );
}
void WORKSHEET_ITEM::SetTitleBlock( const TITLE_BLOCK* aTitleBlock )
{
m_titleBlock = aTitleBlock;
ViewUpdate( GEOMETRY );
}
const BOX2I WORKSHEET_ITEM::ViewBBox() const
{
BOX2I bbox;
if( m_pageInfo != NULL )
{
bbox.SetOrigin( VECTOR2I( 0, 0 ) );
bbox.SetEnd( VECTOR2I( m_pageInfo->GetWidthMils() * 25400,
m_pageInfo->GetHeightMils() * 25400 ) );
}
else
{
bbox.SetMaximum();
}
return bbox;
}
void WORKSHEET_ITEM::ViewDraw( int aLayer, GAL* aGal, const BOX2I& aVisibleArea ) const
{
RENDER_SETTINGS* settings = m_view->GetPainter()->GetSettings();
wxString fileName( m_fileName );
wxString sheetName( m_sheetName );
WS_DRAW_ITEM_LIST drawList;
drawList.SetPenSize( settings->GetWorksheetLineWidth() );
// Sorry,but I don't get this multi #ifdef from include/convert_to_biu.h, so here goes a magic
// number. IU_PER_MILS should be 25400 (as in a different compiltion unit), but somehow
// it equals 1 in this case..
drawList.SetMilsToIUfactor( 25400 /* IU_PER_MILS */ );
drawList.SetSheetNumber( m_sheetNumber );
drawList.SetSheetCount( m_sheetCount );
drawList.SetFileName( fileName );
drawList.SetSheetName( sheetName );
COLOR4D color = settings->GetColor( this, aLayer );
EDA_COLOR_T edaColor = ColorFindNearest( color.r * 255, color.g * 255, color.b * 255 );
drawList.BuildWorkSheetGraphicList( *m_pageInfo, *m_titleBlock, edaColor, edaColor );
// Draw gray line that outlines the sheet size
drawBorder( aGal );
// 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:
draw( static_cast<const WS_DRAW_ITEM_LINE*>( item ), aGal );
break;
case WS_DRAW_ITEM_BASE::wsg_rect:
draw( static_cast<const WS_DRAW_ITEM_RECT*>( item ), aGal );
break;
case WS_DRAW_ITEM_BASE::wsg_poly:
draw( static_cast<const WS_DRAW_ITEM_POLYGON*>( item ), aGal );
break;
case WS_DRAW_ITEM_BASE::wsg_text:
draw( static_cast<const WS_DRAW_ITEM_TEXT*>( item ), aGal );
break;
}
item = drawList.GetNext();
}
}
void WORKSHEET_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
{
aCount = 1;
aLayers[0] = ITEM_GAL_LAYER( WORKSHEET );
}
void WORKSHEET_ITEM::draw( const WS_DRAW_ITEM_LINE* aItem, GAL* aGal ) const
{
aGal->SetIsStroke( true );
aGal->SetIsFill( false );
aGal->SetStrokeColor( COLOR4D( aItem->GetColor() ) );
aGal->SetLineWidth( aItem->GetPenWidth() );
aGal->DrawLine( VECTOR2D( aItem->GetStart() ), VECTOR2D( aItem->GetEnd() ) );
}
void WORKSHEET_ITEM::draw( const WS_DRAW_ITEM_RECT* aItem, GAL* aGal ) const
{
aGal->SetIsStroke( true );
aGal->SetIsFill( false );
aGal->SetStrokeColor( COLOR4D( aItem->GetColor() ) );
aGal->SetLineWidth( aItem->GetPenWidth() );
aGal->DrawRectangle( VECTOR2D( aItem->GetStart() ), VECTOR2D( aItem->GetEnd() ) );
}
void WORKSHEET_ITEM::draw( const WS_DRAW_ITEM_POLYGON* aItem, GAL* aGal ) const
{
std::deque<VECTOR2D> corners;
BOOST_FOREACH( wxPoint point, aItem->m_Corners )
{
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 );
}
}
void WORKSHEET_ITEM::draw( const WS_DRAW_ITEM_TEXT* aItem, GAL* aGal ) const
{
VECTOR2D position( aItem->GetTextPosition().x, aItem->GetTextPosition().y );
aGal->SetStrokeColor( COLOR4D( aItem->GetColor() ) );
aGal->SetLineWidth( aItem->GetThickness() );
aGal->SetTextAttributes( aItem );
aGal->StrokeText( std::string( aItem->GetText().mb_str() ), position, 0.0 );
}
void WORKSHEET_ITEM::drawBorder( GAL* aGal ) const
{
VECTOR2D origin = VECTOR2D( 0.0, 0.0 );
VECTOR2D end = VECTOR2D( m_pageInfo->GetWidthMils() * 25400,
m_pageInfo->GetHeightMils() * 25400 );
aGal->SetIsStroke( true );
aGal->SetIsFill( false );
aGal->SetStrokeColor( COLOR4D( 0.5, 0.5, 0.5, 1.0 ) );
aGal->DrawRectangle( origin, end );
}

View File

@ -241,6 +241,7 @@ enum PCB_VISIBLE
PADS_NETNAMES_VISIBLE,
SELECTION,
WORKSHEET,
GP_OVERLAY, // General purpose overlay
END_PCB_VISIBLE_LIST // sentinel
@ -290,7 +291,8 @@ const LAYER_NUM GalLayerOrder[] =
ITEM_GAL_LAYER( LAYER_1_NETNAMES_VISIBLE ), LAYER_N_BACK,
ADHESIVE_N_BACK, SOLDERPASTE_N_BACK, SILKSCREEN_N_BACK,
ITEM_GAL_LAYER( MOD_TEXT_BK_VISIBLE )
ITEM_GAL_LAYER( MOD_TEXT_BK_VISIBLE ),
ITEM_GAL_LAYER( WORKSHEET )
};
/**

View File

@ -32,6 +32,7 @@
#include <gal/color4d.h>
#include <colors.h>
#include <worksheet_shape_builder.h>
#include <boost/shared_ptr.hpp>
class EDA_ITEM;
@ -123,6 +124,11 @@ public:
*/
virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const = 0;
float GetWorksheetLineWidth() const
{
return m_worksheetLineWidth;
}
protected:
/**
* Function update
@ -147,6 +153,7 @@ protected:
float m_selectFactor; ///< Specifies how color of selected items is changed
float m_layerOpacity; ///< Determines opacity of all layers
float m_outlineWidth; ///< Line width used when drawing outlines
float m_worksheetLineWidth; ///< Line width used when drawing worksheet
/// Map of colors that were usually used for display
std::map<EDA_COLOR_T, COLOR4D> m_legacyColorMap;

163
include/worksheet_item.h Normal file
View File

@ -0,0 +1,163 @@
/*
* 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
*/
/**
* @file worksheet_item.h
* @brief Class that handles properties and drawing of worksheet layout.
*/
#ifndef WORKSHEET_ITEM_H
#define WORKSHEET_ITEM_H
#include <base_struct.h>
class BOARD;
class PAGE_INFO;
class TITLE_BLOCK;
class WS_DRAW_ITEM_LINE;
class WS_DRAW_ITEM_RECT;
class WS_DRAW_ITEM_POLYGON;
class WS_DRAW_ITEM_TEXT;
namespace KiGfx
{
class GAL;
class WORKSHEET_ITEM : public EDA_ITEM
{
public:
WORKSHEET_ITEM( const std::string& aFileName, const std::string& aSheetName,
const PAGE_INFO* aPageInfo, const TITLE_BLOCK* aTitleBlock );
~WORKSHEET_ITEM() {}
/**
* Function SetFileName()
* Sets the file name displayed in the title block.
*
* @param aFileName is the new file name.
*/
void SetFileName( const std::string& aFileName )
{
m_fileName = aFileName;
ViewUpdate( GEOMETRY );
}
/**
* Function SetSheetName()
* Sets the sheet name displayed in the title block.
*
* @param aSheetName is the new sheet name.
*/
void SetSheetName( const std::string& aSheetName )
{
m_sheetName = aSheetName;
ViewUpdate( GEOMETRY );
}
/**
* Function SetPageInfo()
* Changes the PAGE_INFO object used to draw the worksheet.
*
* @param aPageInfo is the new PAGE_INFO object.
*/
void SetPageInfo( const PAGE_INFO* aPageInfo );
/**
* Function SetTitleBlock()
* Changes the TITLE_BLOCK object used to draw the worksheet.
*
* @param aTitleBlock is the new TITLE_BLOCK object.
*/
void SetTitleBlock( const TITLE_BLOCK* aTitleBlock );
/**
* Function SetSheetNumber()
* Changes the sheet number displayed in the title block.
*
* @param aSheetNumber is the new sheet number.
*/
void SetSheetNumber( int aSheetNumber )
{
m_sheetNumber = aSheetNumber;
ViewUpdate( GEOMETRY );
}
/**
* Function SetSheetCount()
* Changes the sheets count number displayed in the title block.
*
* @param aSheetCount is the new sheets count number.
*/
void SetSheetCount( int aSheetCount )
{
m_sheetCount = aSheetCount;
ViewUpdate( GEOMETRY );
}
/// @copydoc VIEW_ITEM::ViewBBox()
const BOX2I ViewBBox() const;
/// @copydoc VIEW_ITEM::ViewDraw()
void ViewDraw( int aLayer, GAL* aGal, const BOX2I& aVisibleArea ) const;
/// @copydoc VIEW_ITEM::ViewGetLayers()
void ViewGetLayers( int aLayers[], int& aCount ) const;
/// @copydoc EDA_ITEM::Show()
void Show( int x, std::ostream& st ) const
{
}
protected:
/// File name displayed in the title block
std::string m_fileName;
/// Sheet name displayed in the title block
std::string m_sheetName;
/// Title block that contains properties of the title block displayed in the worksheet.
const TITLE_BLOCK* m_titleBlock;
/// Worksheet page information.
const PAGE_INFO* m_pageInfo;
/// Sheet number displayed in the title block.
int m_sheetNumber;
/// Sheets count number displayed in the title block.
int m_sheetCount;
// Functions for drawing items that makes a worksheet
void draw( const WS_DRAW_ITEM_LINE* aItem, GAL* aGal ) const;
void draw( const WS_DRAW_ITEM_RECT* aItem, GAL* aGal ) const;
void draw( const WS_DRAW_ITEM_POLYGON* aItem, GAL* aGal ) const;
void draw( const WS_DRAW_ITEM_TEXT* aItem, GAL* aGal ) const;
/// Draws a border that determines the page size.
void drawBorder( GAL* aGal ) const;
};
}
#endif /* WORKSHEET_ITEM_H */

View File

@ -53,6 +53,7 @@
#include <math/vector2d.h>
#include <trigo.h>
#include <pcb_painter.h>
#include <worksheet_item.h>
#include <tool/tool_manager.h>
#include <tool/tool_dispatcher.h>
@ -202,6 +203,20 @@ void PCB_BASE_FRAME::ViewReloadBoard( const BOARD* aBoard ) const
view->Add( zone );
}
// Add an entry for the worksheet layout
KiGfx::WORKSHEET_ITEM* worksheet = new KiGfx::WORKSHEET_ITEM(
std::string( aBoard->GetFileName().mb_str() ),
std::string( GetScreenDesc().mb_str() ),
&GetPageSettings(), &GetTitleBlock() );
BASE_SCREEN* screen = GetScreen();
if( screen != NULL )
{
worksheet->SetSheetNumber( GetScreen()->m_ScreenNumber );
worksheet->SetSheetCount( GetScreen()->m_NumberOfScreens );
}
view->Add( worksheet );
view->RecacheAllItems( true );
if( m_galCanvasActive )

View File

@ -75,6 +75,7 @@ void PCB_RENDER_SETTINGS::ImportLegacyColors( COLORS_DESIGN_SETTINGS* aSettings
m_layerColors[ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE )] = COLOR4D( 0.8, 0.8, 0.8, 0.7 );
m_layerColors[ITEM_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE )] = COLOR4D( 0.8, 0.8, 0.8, 0.7 );
m_layerColors[ITEM_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE )] = COLOR4D( 0.8, 0.8, 0.8, 0.7 );
m_layerColors[ITEM_GAL_LAYER( WORKSHEET )] = COLOR4D( 0.5, 0.0, 0.0, 1.0 );
// Netnames for copper layers
for( LAYER_NUM layer = FIRST_COPPER_LAYER; layer <= LAST_COPPER_LAYER; ++layer )