mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-20 18:11:42 +00:00
Moving PageLayout editor to GAL canvas and modern toolset.
This commit is contained in:
parent
43a5bb72ca
commit
323bb0f8e1
common
CMakeLists.txt
dialogs
legacy_gal
legacy_wx
page_layout
page_layout_default_description.cpppage_layout_graphic_items.cpppage_layout_reader.cpptitle_block_shapes.cppworksheet_dataitem.cppworksheet_layout.cppworksheet_painter.cppworksheet_viewitem.cppws_draw_item.cpp
painter.cppplotters
tool
worksheet_viewitem.cppcvpcb
eeschema
dialogs
ee_collectors.hee_hotkeys.cppeeschema_config.cppfiles-io.cpplib_arc.cpplib_arc.hlib_bezier.cpplib_bezier.hlib_circle.cpplib_circle.hlib_draw_item.hlib_field.cpplib_field.hlib_polyline.cpplib_polyline.hlib_rectangle.cpplib_rectangle.hlib_text.cpplib_text.hlibedit
sch_base_frame.cppsch_base_frame.hsch_draw_panel.cppsch_draw_panel.hsch_eagle_plugin.cppsch_edit_frame.cppsch_edit_frame.hsch_field.cppsch_screen.cpptools
viewlib_frame.cppviewlib_frame.hviewlibs.cppgerbview
include
collector.h
core
draw_frame.hlegacy_gal
painter.hpcb_base_frame.htool
worksheet.hworksheet_dataitem.hworksheet_painter.hworksheet_viewitem.hws_draw_item.hpagelayout_editor
CMakeLists.txtblock.cppdesign_tree_frame.cppdesign_tree_frame.h
dialogs
dialog_new_dataitem.cppdialogs_for_printing.cppproperties_frame_base.cppproperties_frame_base.fbpproperties_frame_base.h
events_functions.cppfiles.cpphotkeys.cpphotkeys.hinvoke_pl_editor_dialog.hmenubar.cpponleftclick.cpponrightclick.cpppage_layout_writer.cpppl_draw_panel_gal.cpppl_draw_panel_gal.hpl_editor.cpppl_editor_config.cpppl_editor_frame.cpppl_editor_frame.hpl_editor_id.hpl_editor_layout.hpl_editor_screen.cpppl_editor_screen.hpl_editor_undo_redo.cppproperties_frame.cpptoolbars_pl_editor.cpptools
pcbnew
CMakeLists.txtblock_footprint_editor.cppfootprint_edit_frame.cppfootprint_edit_frame.hfootprint_editor_onclick.cppfootprint_viewer_frame.cppfootprint_viewer_frame.hfootprint_wizard_frame.hfootprint_wizard_frame_functions.cpppcb_draw_panel_gal.cpppcb_edit_frame.cpppcb_edit_frame.hpcb_screen.cpppcbnew_config.cpp
swig
tools
@ -36,7 +36,7 @@ set( GAL_SRCS
|
||||
newstroke_font.cpp
|
||||
painter.cpp
|
||||
text_utils.cpp
|
||||
worksheet_viewitem.cpp
|
||||
page_layout/worksheet_viewitem.cpp
|
||||
gal/color4d.cpp
|
||||
gal/gal_display_options.cpp
|
||||
gal/graphics_abstraction_layer.cpp
|
||||
@ -236,11 +236,10 @@ set( COMMON_WIDGET_SRCS
|
||||
)
|
||||
|
||||
set( COMMON_PAGE_LAYOUT_SRCS
|
||||
page_layout/title_block_shapes.cpp
|
||||
page_layout/worksheet_dataitem.cpp
|
||||
page_layout/worksheet_layout.cpp
|
||||
page_layout/page_layout_default_description.cpp
|
||||
page_layout/page_layout_graphic_items.cpp
|
||||
page_layout/ws_draw_item.cpp
|
||||
page_layout/page_layout_reader_keywords.cpp
|
||||
page_layout/page_layout_reader.cpp
|
||||
)
|
||||
@ -359,7 +358,7 @@ set( COMMON_SRCS
|
||||
utf8.cpp
|
||||
validators.cpp
|
||||
wildcards_and_files_ext.cpp
|
||||
worksheet.cpp
|
||||
page_layout/worksheet_painter.cpp
|
||||
wxdataviewctrl_helpers.cpp
|
||||
xnode.cpp
|
||||
)
|
||||
|
@ -35,7 +35,7 @@
|
||||
#include <class_drawpanel.h>
|
||||
#include <title_block.h>
|
||||
#include <draw_frame.h>
|
||||
#include <worksheet_shape_builder.h>
|
||||
#include <ws_draw_item.h>
|
||||
#include <base_screen.h>
|
||||
#include <wildcards_and_files_ext.h>
|
||||
|
||||
@ -47,7 +47,7 @@
|
||||
#include <general.h>
|
||||
#endif
|
||||
|
||||
#include <worksheet.h>
|
||||
#include <worksheet_painter.h>
|
||||
#include <dialog_page_settings.h>
|
||||
|
||||
#define MAX_PAGE_EXAMPLE_SIZE 200
|
||||
@ -665,7 +665,7 @@ void DIALOG_PAGES_SETTINGS::UpdatePageLayoutExample()
|
||||
DrawPageLayout( &memDC, NULL, pageDUMMY,
|
||||
emptyString, emptyString,
|
||||
m_tb, m_screen->m_NumberOfScreens,
|
||||
m_screen->m_ScreenNumber, 1, 1, DARKGRAY, RED );
|
||||
m_screen->m_ScreenNumber, 1, 1, DARKGRAY );
|
||||
|
||||
memDC.SelectObject( wxNullBitmap );
|
||||
m_PageLayoutExampleBitmap->SetBitmap( *m_page_bitmap );
|
||||
|
@ -45,7 +45,7 @@
|
||||
#include <tool/action_menu.h>
|
||||
#include <tool/actions.h>
|
||||
#include <wx/clipbrd.h>
|
||||
#include <worksheet_shape_builder.h>
|
||||
#include <ws_draw_item.h>
|
||||
#include <page_info.h>
|
||||
#include <title_block.h>
|
||||
#include <advanced_config.h>
|
||||
@ -728,6 +728,7 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable )
|
||||
}
|
||||
|
||||
galCanvas->SetEvtHandlerEnabled( aEnable );
|
||||
galCanvas->StartDrawing();
|
||||
|
||||
// Reset current tool on switch();
|
||||
SetNoToolSelected();
|
||||
@ -1030,12 +1031,6 @@ void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
|
||||
}
|
||||
|
||||
|
||||
void EDA_DRAW_FRAME::Window_Zoom( EDA_RECT& Rect )
|
||||
{
|
||||
wxFAIL_MSG( "Obsolete! Should go through COMMON_TOOLS." );
|
||||
}
|
||||
|
||||
|
||||
void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event )
|
||||
{
|
||||
wxFAIL_MSG( "Obsolete! Should go through COMMON_TOOLS." );
|
||||
@ -1196,19 +1191,22 @@ bool DrawPageOnClipboard( EDA_DRAW_FRAME* aFrame )
|
||||
|
||||
static const wxString productName = wxT( "KiCad E.D.A. " );
|
||||
|
||||
void DrawPageLayout( wxDC* aDC, EDA_RECT* aClipBox,
|
||||
void DrawPageLayout( wxDC* aDC,
|
||||
EDA_RECT* aClipBox,
|
||||
const PAGE_INFO& aPageInfo,
|
||||
const wxString &aFullSheetName,
|
||||
const wxString& aFileName,
|
||||
TITLE_BLOCK& aTitleBlock,
|
||||
int aSheetCount, int aSheetNumber,
|
||||
int aPenWidth, double aScalar,
|
||||
COLOR4D aColor, COLOR4D aAltColor,
|
||||
const wxString& aSheetLayer )
|
||||
const wxString& aFullSheetName,
|
||||
const wxString& aFileName,
|
||||
TITLE_BLOCK& aTitleBlock,
|
||||
int aSheetCount,
|
||||
int aSheetNumber,
|
||||
int aPenWidth,
|
||||
double aScalar,
|
||||
COLOR4D aColor,
|
||||
const wxString& aSheetLayer )
|
||||
{
|
||||
WS_DRAW_ITEM_LIST drawList;
|
||||
|
||||
drawList.SetPenSize( aPenWidth );
|
||||
drawList.SetDefaultPenSize( aPenWidth );
|
||||
drawList.SetMilsToIUfactor( aScalar );
|
||||
drawList.SetSheetNumber( aSheetNumber );
|
||||
drawList.SetSheetCount( aSheetCount );
|
||||
@ -1216,10 +1214,10 @@ void DrawPageLayout( wxDC* aDC, EDA_RECT* aClipBox,
|
||||
drawList.SetSheetName( aFullSheetName );
|
||||
drawList.SetSheetLayer( aSheetLayer );
|
||||
|
||||
drawList.BuildWorkSheetGraphicList( aPageInfo, aTitleBlock, aColor, aAltColor );
|
||||
drawList.BuildWorkSheetGraphicList( aPageInfo, aTitleBlock );
|
||||
|
||||
// Draw item list
|
||||
drawList.Draw( aClipBox, aDC );
|
||||
drawList.Draw( aClipBox, aDC, aColor );
|
||||
}
|
||||
|
||||
|
||||
@ -1254,7 +1252,7 @@ void EDA_DRAW_FRAME::DrawWorkSheet( wxDC* aDC, BASE_SCREEN* aScreen, int aLineWi
|
||||
|
||||
DrawPageLayout( aDC, m_canvas->GetClipBox(), pageInfo, GetScreenDesc(), aFilename, t_block,
|
||||
aScreen->m_NumberOfScreens, aScreen->m_ScreenNumber, aLineWidth, aScalar,
|
||||
color, color, aSheetLayer );
|
||||
color, aSheetLayer );
|
||||
|
||||
if( aScreen->m_IsPrinting && origin.y > 0 )
|
||||
{
|
||||
|
@ -67,7 +67,7 @@
|
||||
#include <menus_helpers.h>
|
||||
#include <page_info.h>
|
||||
#include <title_block.h>
|
||||
#include <worksheet_shape_builder.h>
|
||||
#include <ws_draw_item.h>
|
||||
|
||||
/**
|
||||
* Definition for enabling and disabling scroll bar setting trace output. See the
|
||||
@ -519,24 +519,9 @@ void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
|
||||
if( id < 0 || !( id < (int)m_zoomSelectBox->GetCount() ) )
|
||||
return;
|
||||
|
||||
if( IsGalCanvasActive() )
|
||||
{
|
||||
m_toolManager->RunAction( "common.Control.zoomPreset", true, id );
|
||||
UpdateStatusBar();
|
||||
m_galCanvas->Refresh();
|
||||
}
|
||||
else if( id == 0 ) // Auto zoom (Fit in Page)
|
||||
{
|
||||
Zoom_Automatique( true );
|
||||
m_canvas->Refresh();
|
||||
}
|
||||
else
|
||||
{
|
||||
double selectedZoom = GetScreen()->m_ZoomList[id-1];
|
||||
|
||||
if( GetScreen()->SetZoom( selectedZoom ) )
|
||||
RedrawScreen( GetScrollCenterPosition(), false );
|
||||
}
|
||||
m_toolManager->RunAction( "common.Control.zoomPreset", true, id );
|
||||
UpdateStatusBar();
|
||||
m_galCanvas->Refresh();
|
||||
}
|
||||
|
||||
|
||||
@ -847,8 +832,8 @@ void EDA_DRAW_FRAME::SetMsgPanel( const MSG_PANEL_ITEMS& aList )
|
||||
|
||||
ClearMsgPanel();
|
||||
|
||||
for( unsigned i = 0; i < aList.size(); i++ )
|
||||
m_messagePanel->AppendMessage( aList[i] );
|
||||
for( MSG_PANEL_ITEM item : aList )
|
||||
m_messagePanel->AppendMessage( item );
|
||||
}
|
||||
|
||||
|
||||
@ -1216,6 +1201,11 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable )
|
||||
m_canvas->SetEvtHandlerEnabled( !aEnable );
|
||||
GetGalCanvas()->SetEvtHandlerEnabled( aEnable );
|
||||
|
||||
if( aEnable )
|
||||
GetGalCanvas()->StartDrawing();
|
||||
else
|
||||
GetGalCanvas()->StopDrawing();
|
||||
|
||||
// Switch panes
|
||||
m_auimgr.GetPane( "DrawFrame" ).Show( !aEnable );
|
||||
m_auimgr.GetPane( "DrawFrameGal" ).Show( aEnable );
|
||||
@ -1624,6 +1614,7 @@ double EDA_DRAW_FRAME::bestZoom( double sizeX, double sizeY, double scaleFactor,
|
||||
}
|
||||
|
||||
|
||||
// JEY TODO: Obsolete; replace with ACTIONS::zoomFitScreen
|
||||
void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
|
||||
{
|
||||
BASE_SCREEN* screen = GetScreen();
|
||||
@ -1646,24 +1637,6 @@ void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
|
||||
}
|
||||
|
||||
|
||||
void EDA_DRAW_FRAME::Window_Zoom( EDA_RECT& Rect )
|
||||
{
|
||||
// Compute the best zoom
|
||||
Rect.Normalize();
|
||||
|
||||
wxSize size = m_canvas->GetClientSize();
|
||||
|
||||
// Use ceil to at least show the full rect
|
||||
double scalex = (double) Rect.GetSize().x / size.x;
|
||||
double bestscale = (double) Rect.GetSize().y / size.y;
|
||||
|
||||
bestscale = std::max( bestscale, scalex );
|
||||
|
||||
GetScreen()->SetScalingFactor( bestscale );
|
||||
RedrawScreen( Rect.Centre(), true );
|
||||
}
|
||||
|
||||
|
||||
void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event )
|
||||
{
|
||||
if( m_canvas == NULL )
|
||||
@ -2040,19 +2013,22 @@ bool DrawPageOnClipboard( EDA_DRAW_FRAME* aFrame )
|
||||
}
|
||||
|
||||
|
||||
void DrawPageLayout( wxDC* aDC, EDA_RECT* aClipBox,
|
||||
void DrawPageLayout( wxDC* aDC,
|
||||
EDA_RECT* aClipBox,
|
||||
const PAGE_INFO& aPageInfo,
|
||||
const wxString &aFullSheetName,
|
||||
const wxString& aFileName,
|
||||
TITLE_BLOCK& aTitleBlock,
|
||||
int aSheetCount, int aSheetNumber,
|
||||
int aPenWidth, double aScalar,
|
||||
COLOR4D aColor, COLOR4D aAltColor,
|
||||
const wxString& aSheetLayer )
|
||||
const wxString& aFullSheetName,
|
||||
const wxString& aFileName,
|
||||
TITLE_BLOCK& aTitleBlock,
|
||||
int aSheetCount,
|
||||
int aSheetNumber,
|
||||
int aPenWidth,
|
||||
double aScalar,
|
||||
COLOR4D aColor,
|
||||
const wxString& aSheetLayer )
|
||||
{
|
||||
WS_DRAW_ITEM_LIST drawList;
|
||||
|
||||
drawList.SetPenSize( aPenWidth );
|
||||
drawList.SetDefaultPenSize( aPenWidth );
|
||||
drawList.SetMilsToIUfactor( aScalar );
|
||||
drawList.SetSheetNumber( aSheetNumber );
|
||||
drawList.SetSheetCount( aSheetCount );
|
||||
@ -2060,11 +2036,10 @@ void DrawPageLayout( wxDC* aDC, EDA_RECT* aClipBox,
|
||||
drawList.SetSheetName( aFullSheetName );
|
||||
drawList.SetSheetLayer( aSheetLayer );
|
||||
|
||||
drawList.BuildWorkSheetGraphicList( aPageInfo,
|
||||
aTitleBlock, aColor, aAltColor );
|
||||
drawList.BuildWorkSheetGraphicList( aPageInfo, aTitleBlock );
|
||||
|
||||
// Draw item list
|
||||
drawList.Draw( aClipBox, aDC );
|
||||
drawList.Draw( aClipBox, aDC, aColor );
|
||||
}
|
||||
|
||||
|
||||
@ -2101,7 +2076,7 @@ void EDA_DRAW_FRAME::DrawWorkSheet( wxDC* aDC, BASE_SCREEN* aScreen, int aLineWi
|
||||
DrawPageLayout( aDC, m_canvas->GetClipBox(), pageInfo,
|
||||
GetScreenDesc(), aFilename, t_block,
|
||||
aScreen->m_NumberOfScreens, aScreen->m_ScreenNumber,
|
||||
aLineWidth, aScalar, color, color, aSheetLayer );
|
||||
aLineWidth, aScalar, color, aSheetLayer );
|
||||
|
||||
if( aScreen->m_IsPrinting && origin.y > 0 )
|
||||
{
|
||||
|
@ -115,7 +115,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <worksheet.h>
|
||||
#include <worksheet_painter.h>
|
||||
|
||||
// height of the band reference grid 2.0 mm
|
||||
// worksheet frame reference text size 1.3 mm
|
||||
|
@ -1,540 +0,0 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 1992-2013 Jean-Pierre Charras <jp.charras at wanadoo.fr>.
|
||||
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.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
|
||||
*/
|
||||
/**
|
||||
* @file page_layout_graphic_items.cpp
|
||||
* @brief description of graphic items and texts to build a title block
|
||||
*/
|
||||
|
||||
/*
|
||||
* the class WORKSHEET_DATAITEM (and WORKSHEET_DATAITEM_TEXT) defines
|
||||
* a basic shape of a page layout ( frame references and title block )
|
||||
* Basic shapes are line, rect and texts
|
||||
* the WORKSHEET_DATAITEM coordinates units is the mm, and are relative to
|
||||
* one of 4 page corners.
|
||||
*
|
||||
* These items cannot be drawn or plot "as this". they should be converted
|
||||
* to a "draw list" (WS_DRAW_ITEM_BASE and derived items)
|
||||
|
||||
* The list of these items is stored in a WORKSHEET_LAYOUT instance.
|
||||
*
|
||||
* When building the draw list:
|
||||
* the WORKSHEET_LAYOUT is used to create a WS_DRAW_ITEM_LIST
|
||||
* coordinates are converted to draw/plot coordinates.
|
||||
* texts are expanded if they contain format symbols.
|
||||
* Items with m_RepeatCount > 1 are created m_RepeatCount times
|
||||
*
|
||||
* the WORKSHEET_LAYOUT is created only once.
|
||||
* the WS_DRAW_ITEM_LIST is created each time the page layout is plotted/drawn
|
||||
*
|
||||
* the WORKSHEET_LAYOUT instance is created from a S expression which
|
||||
* describes the page layout (can be the default page layout or a custom file).
|
||||
*/
|
||||
|
||||
#include <fctsys.h>
|
||||
#include <eda_rect.h>
|
||||
#include <draw_graphic_text.h>
|
||||
#include <worksheet.h>
|
||||
#include <title_block.h>
|
||||
#include <worksheet_shape_builder.h>
|
||||
#include <worksheet_dataitem.h>
|
||||
#include <polygon_test_point_inside.h>
|
||||
|
||||
/* a helper function to calculate a marker size scaling factor from zoom level
|
||||
* when one need a "constant" size to draw an item whatever the zoom level
|
||||
* the scaling factor is clamped between 1.0 to 10.0 to avoid ugly drawings
|
||||
* when the factor is ti high (1.0 is the "actual" item size)
|
||||
* Note:
|
||||
* Only the page layout editor uses the marker size.
|
||||
* Other editors do not use or draw markers
|
||||
*/
|
||||
static double getScaleFromZoom( wxDC* aDC )
|
||||
{
|
||||
double x, y;
|
||||
aDC->GetUserScale( &x, &y );
|
||||
|
||||
double scale = (x + y ) / 2; // should be equal, but if not best we can do is average
|
||||
|
||||
double fscale = WORKSHEET_DATAITEM::m_WSunits2Iu * scale;
|
||||
double zscale = 20.0/ fscale; // The 20.0 factor is chosen for best results
|
||||
// (fix the zoom level to have a zscale > 1)
|
||||
|
||||
// clamp scaling factor:
|
||||
zscale = std::max( 1.0, zscale ); // never smaller than actual size
|
||||
zscale = std::min( 10.0, zscale ); // should be enough to make item visible
|
||||
|
||||
return zscale;
|
||||
}
|
||||
|
||||
|
||||
/* a helper function to draw graphic symbols at start point or end point of
|
||||
* an item.
|
||||
* The start point symbol is a filled rectangle
|
||||
* The start point symbol is a filled circle
|
||||
*/
|
||||
inline void drawMarker( EDA_RECT* aClipBox, wxDC* aDC,
|
||||
const wxPoint& aPos, int aSize, bool aEndPointShape = false )
|
||||
{
|
||||
int markerHalfSize = aSize/2;
|
||||
|
||||
if( aEndPointShape )
|
||||
GRFilledCircle( aClipBox, aDC, aPos.x, aPos.y, markerHalfSize,
|
||||
0, GREEN, GREEN );
|
||||
else
|
||||
GRFilledRect( aClipBox, aDC,
|
||||
aPos.x - markerHalfSize, aPos.y - markerHalfSize,
|
||||
aPos.x + markerHalfSize, aPos.y + markerHalfSize,
|
||||
0, GREEN, GREEN );
|
||||
}
|
||||
|
||||
|
||||
/* Draws the item list created by BuildWorkSheetGraphicList
|
||||
* aClipBox = the clipping rect, or NULL if no clipping
|
||||
* aDC = the current Device Context
|
||||
* The not selected items are drawn first (most of items)
|
||||
* The selected items are drawn after (usually 0 or 1)
|
||||
* to be sure they are seen, even for overlapping items
|
||||
*/
|
||||
void WS_DRAW_ITEM_LIST::Draw( EDA_RECT* aClipBox, wxDC* aDC )
|
||||
{
|
||||
// The not selected items are drawn first (most of items)
|
||||
for( WS_DRAW_ITEM_BASE* item = GetFirst(); item; item = GetNext() )
|
||||
{
|
||||
if( item->GetParent() && item->GetParent()->IsSelected() )
|
||||
continue;
|
||||
|
||||
item->DrawWsItem( aClipBox, aDC );
|
||||
}
|
||||
|
||||
// The selected items are drawn after (usually 0 or 1)
|
||||
int markerSize = WORKSHEET_DATAITEM::GetMarkerSizeUi( getScaleFromZoom( aDC ) );
|
||||
|
||||
for( WS_DRAW_ITEM_BASE* item = GetFirst(); item; item = GetNext() )
|
||||
{
|
||||
if( !item->GetParent() || !item->GetParent()->IsSelected() )
|
||||
continue;
|
||||
|
||||
item->DrawWsItem( aClipBox, aDC );
|
||||
|
||||
if( !markerSize )
|
||||
continue;
|
||||
|
||||
switch( item->GetType() )
|
||||
{
|
||||
case WS_DRAW_ITEM_BASE::wsg_line:
|
||||
{
|
||||
WS_DRAW_ITEM_LINE* line = (WS_DRAW_ITEM_LINE*) item;
|
||||
drawMarker( aClipBox, aDC, line->GetStart(), markerSize );
|
||||
drawMarker( aClipBox, aDC, line->GetEnd(), markerSize, true );
|
||||
}
|
||||
break;
|
||||
|
||||
case WS_DRAW_ITEM_BASE::wsg_rect:
|
||||
{
|
||||
WS_DRAW_ITEM_RECT* rect = (WS_DRAW_ITEM_RECT*) item;
|
||||
drawMarker( aClipBox, aDC, rect->GetStart(), markerSize );
|
||||
drawMarker( aClipBox, aDC, rect->GetEnd(), markerSize, true );
|
||||
}
|
||||
break;
|
||||
|
||||
case WS_DRAW_ITEM_BASE::wsg_text:
|
||||
{
|
||||
WS_DRAW_ITEM_TEXT* text = (WS_DRAW_ITEM_TEXT*) item;
|
||||
drawMarker( aClipBox, aDC, text->GetTextPos(), markerSize );
|
||||
}
|
||||
break;
|
||||
|
||||
case WS_DRAW_ITEM_BASE::wsg_poly:
|
||||
{
|
||||
WS_DRAW_ITEM_POLYGON* poly = (WS_DRAW_ITEM_POLYGON*) item;
|
||||
drawMarker( aClipBox, aDC, poly->GetPosition(), markerSize );
|
||||
}
|
||||
break;
|
||||
|
||||
case WS_DRAW_ITEM_BASE::wsg_bitmap:
|
||||
{
|
||||
WS_DRAW_ITEM_BITMAP* bitmap = (WS_DRAW_ITEM_BITMAP*) item;
|
||||
drawMarker( aClipBox, aDC, bitmap->GetPosition(), markerSize );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
WS_DRAW_ITEM_TEXT::WS_DRAW_ITEM_TEXT( WORKSHEET_DATAITEM* aParent,
|
||||
wxString& aText, wxPoint aPos, wxSize aSize,
|
||||
int aPenWidth, COLOR4D aColor,
|
||||
bool aItalic, bool aBold ) :
|
||||
WS_DRAW_ITEM_BASE( aParent, wsg_text, aColor ), EDA_TEXT( aText )
|
||||
{
|
||||
SetTextPos( aPos );
|
||||
SetTextSize( aSize );
|
||||
SetThickness( aPenWidth );
|
||||
SetItalic( aItalic );
|
||||
SetBold( aBold );
|
||||
}
|
||||
|
||||
|
||||
void WS_DRAW_ITEM_TEXT::DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset,
|
||||
GR_DRAWMODE aDrawMode, COLOR4D aColor )
|
||||
{
|
||||
Draw( aClipBox, aDC, aOffset,
|
||||
aColor == COLOR4D::UNSPECIFIED ? GetColor() : aColor,
|
||||
aDrawMode == UNSPECIFIED_DRAWMODE ? GR_COPY : aDrawMode,
|
||||
FILLED, COLOR4D::UNSPECIFIED );
|
||||
}
|
||||
|
||||
|
||||
bool WS_DRAW_ITEM_TEXT::HitTest( const wxPoint& aPosition) const
|
||||
{
|
||||
return EDA_TEXT::TextHitTest( aPosition, 0 );
|
||||
}
|
||||
|
||||
|
||||
bool WS_DRAW_ITEM_TEXT::HitTest( const EDA_RECT& aRect ) const
|
||||
{
|
||||
return EDA_TEXT::TextHitTest( aRect, 0, 0 );
|
||||
}
|
||||
|
||||
|
||||
bool WS_DRAW_ITEM_TEXT::HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition )
|
||||
{
|
||||
wxPoint pos = GetTextPos();
|
||||
int marker_size = WORKSHEET_DATAITEM::GetMarkerSizeUi( getScaleFromZoom( aDC ) );
|
||||
|
||||
if( std::abs( pos.x - aPosition.x) <= marker_size / 2 &&
|
||||
std::abs( pos.y - aPosition.y) <= marker_size / 2 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void WS_DRAW_ITEM_POLYGON::DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset,
|
||||
GR_DRAWMODE aDrawMode, COLOR4D aColor )
|
||||
{
|
||||
std::vector<wxPoint> points_moved;
|
||||
wxPoint *points;
|
||||
|
||||
if( aOffset.x || aOffset.y )
|
||||
{
|
||||
for( auto point: m_Corners )
|
||||
points_moved.push_back( point + aOffset );
|
||||
points = &points_moved[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
points = &m_Corners[0];
|
||||
}
|
||||
|
||||
auto color = ( aColor == COLOR4D::UNSPECIFIED ) ? GetColor() : aColor;
|
||||
|
||||
GRSetDrawMode( aDC, ( aDrawMode == UNSPECIFIED_DRAWMODE ? GR_COPY : aDrawMode ) );
|
||||
GRPoly( aClipBox, aDC,
|
||||
m_Corners.size(), points,
|
||||
IsFilled() ? FILLED_SHAPE : NO_FILL,
|
||||
GetPenWidth(),
|
||||
color, color );
|
||||
GRSetDrawMode( aDC, GR_COPY );
|
||||
}
|
||||
|
||||
|
||||
bool WS_DRAW_ITEM_POLYGON::HitTest( const wxPoint& aPosition) const
|
||||
{
|
||||
return TestPointInsidePolygon( &m_Corners[0],
|
||||
m_Corners.size(), aPosition );
|
||||
}
|
||||
|
||||
|
||||
bool WS_DRAW_ITEM_POLYGON::HitTest( const EDA_RECT& aRect ) const
|
||||
{
|
||||
// Intersection of two polygons is nontrivial. Test if the rectangle intersects
|
||||
// each line, instead.
|
||||
|
||||
if( m_Corners.size() < 2 )
|
||||
return false;
|
||||
|
||||
for( size_t i = 1; i < m_Corners.size(); ++i )
|
||||
{
|
||||
if( aRect.Intersects( m_Corners[i - 1], m_Corners[i] ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WS_DRAW_ITEM_POLYGON::HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition )
|
||||
{
|
||||
wxPoint pos = GetPosition();
|
||||
int marker_size = WORKSHEET_DATAITEM::GetMarkerSizeUi( getScaleFromZoom( aDC ) );
|
||||
|
||||
if( std::abs( pos.x - aPosition.x) <= marker_size / 2 &&
|
||||
std::abs( pos.y - aPosition.y) <= marker_size / 2 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void WS_DRAW_ITEM_RECT::DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset,
|
||||
GR_DRAWMODE aDrawMode, COLOR4D aColor )
|
||||
{
|
||||
GRSetDrawMode( aDC, ( aDrawMode == UNSPECIFIED_DRAWMODE ? GR_COPY : aDrawMode ) );
|
||||
GRRect( aClipBox, aDC,
|
||||
GetStart().x + aOffset.x, GetStart().y + aOffset.y,
|
||||
GetEnd().x + aOffset.x, GetEnd().y + aOffset.y,
|
||||
GetPenWidth(),
|
||||
( aColor == COLOR4D::UNSPECIFIED ) ? GetColor() : aColor );
|
||||
GRSetDrawMode( aDC, GR_COPY );
|
||||
}
|
||||
|
||||
|
||||
bool WS_DRAW_ITEM_RECT::HitTest( const wxPoint& aPosition ) const
|
||||
{
|
||||
int dist = GetPenWidth()/2;
|
||||
wxPoint start = GetStart();
|
||||
wxPoint end;
|
||||
end.x = GetEnd().x;
|
||||
end.y = start.y;
|
||||
|
||||
// Upper line
|
||||
if( TestSegmentHit( aPosition, start, end, dist ) )
|
||||
return true;
|
||||
|
||||
// Right line
|
||||
start = end;
|
||||
end.y = GetEnd().y;
|
||||
if( TestSegmentHit( aPosition, start, end, dist ) )
|
||||
return true;
|
||||
|
||||
// lower line
|
||||
start = end;
|
||||
end.x = GetStart().x;
|
||||
if( TestSegmentHit( aPosition, start, end, dist ) )
|
||||
return true;
|
||||
|
||||
// left line
|
||||
start = end;
|
||||
end = GetStart();
|
||||
if( TestSegmentHit( aPosition, start, end, dist ) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WS_DRAW_ITEM_RECT::HitTest( const EDA_RECT& aRect ) const
|
||||
{
|
||||
wxPoint start = GetStart();
|
||||
wxPoint end;
|
||||
end.x = GetEnd().x;
|
||||
end.y = start.y;
|
||||
|
||||
// Upper line
|
||||
if( aRect.Intersects( start, end ) )
|
||||
return true;
|
||||
|
||||
// Right line
|
||||
start = end;
|
||||
end.y = GetEnd().y;
|
||||
if( aRect.Intersects( start, end ) )
|
||||
return true;
|
||||
|
||||
// lower line
|
||||
start = end;
|
||||
end.x = GetStart().x;
|
||||
if( aRect.Intersects( start, end ) )
|
||||
return true;
|
||||
|
||||
// left line
|
||||
start = end;
|
||||
end = GetStart();
|
||||
if( aRect.Intersects( start, end ) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WS_DRAW_ITEM_RECT::HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition )
|
||||
{
|
||||
wxPoint dist = GetStart() - aPosition;
|
||||
int marker_size = WORKSHEET_DATAITEM::GetMarkerSizeUi( getScaleFromZoom( aDC ) );
|
||||
|
||||
if( std::abs( dist.x) <= marker_size / 2 &&
|
||||
std::abs( dist.y) <= marker_size / 2 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WS_DRAW_ITEM_RECT::HitTestEndPoint( wxDC *aDC, const wxPoint& aPosition )
|
||||
{
|
||||
wxPoint pos = GetEnd();
|
||||
int marker_size = WORKSHEET_DATAITEM::GetMarkerSizeUi( getScaleFromZoom( aDC ) );
|
||||
|
||||
int dist = (int) hypot( pos.x - aPosition.x, pos.y - aPosition.y );
|
||||
|
||||
if( dist <= marker_size / 2 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void WS_DRAW_ITEM_LINE::DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset,
|
||||
GR_DRAWMODE aDrawMode, COLOR4D aColor )
|
||||
{
|
||||
GRSetDrawMode( aDC, ( aDrawMode == UNSPECIFIED_DRAWMODE ) ? GR_COPY : aDrawMode );
|
||||
GRLine( aClipBox, aDC, GetStart() + aOffset, GetEnd() + aOffset,
|
||||
GetPenWidth(),
|
||||
( aColor == COLOR4D::UNSPECIFIED ) ? GetColor() : aColor );
|
||||
GRSetDrawMode( aDC, GR_COPY );
|
||||
}
|
||||
|
||||
|
||||
bool WS_DRAW_ITEM_LINE::HitTest( const wxPoint& aPosition) const
|
||||
{
|
||||
return TestSegmentHit( aPosition, GetStart(), GetEnd(), GetPenWidth()/2 );
|
||||
}
|
||||
|
||||
|
||||
bool WS_DRAW_ITEM_LINE::HitTest( const EDA_RECT& aRect ) const
|
||||
{
|
||||
return aRect.Intersects( GetStart(), GetEnd() );
|
||||
}
|
||||
|
||||
|
||||
bool WS_DRAW_ITEM_LINE::HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition )
|
||||
{
|
||||
wxPoint dist = GetStart() - aPosition;
|
||||
int marker_size = WORKSHEET_DATAITEM::GetMarkerSizeUi( getScaleFromZoom( aDC ) );
|
||||
|
||||
if( std::abs( dist.x) <= marker_size / 2 &&
|
||||
std::abs( dist.y) <= marker_size / 2 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WS_DRAW_ITEM_LINE::HitTestEndPoint( wxDC *aDC, const wxPoint& aPosition )
|
||||
{
|
||||
wxPoint dist = GetEnd() - aPosition;
|
||||
int marker_size = WORKSHEET_DATAITEM::GetMarkerSizeUi( getScaleFromZoom( aDC ) );
|
||||
|
||||
if( std::abs( dist.x) <= marker_size / 2 &&
|
||||
std::abs( dist.y) <= marker_size / 2 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void WS_DRAW_ITEM_LIST::Locate( wxDC* aDC, std::vector <WS_DRAW_ITEM_BASE*>& aList,
|
||||
const wxPoint& aPosition )
|
||||
{
|
||||
for( WS_DRAW_ITEM_BASE* item = GetFirst(); item; item = GetNext() )
|
||||
{
|
||||
item->m_Flags &= ~(LOCATE_STARTPOINT|LOCATE_ENDPOINT);
|
||||
bool found = false;
|
||||
|
||||
if( item->HitTestStartPoint ( aDC, aPosition ) )
|
||||
{
|
||||
item->m_Flags |= LOCATE_STARTPOINT;
|
||||
found = true;
|
||||
}
|
||||
|
||||
if( item->HitTestEndPoint ( aDC, aPosition ) )
|
||||
{
|
||||
item->m_Flags |= LOCATE_ENDPOINT;
|
||||
found = true;
|
||||
}
|
||||
|
||||
if( found || item->HitTest( aPosition ) )
|
||||
{
|
||||
aList.push_back( item );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void WS_DRAW_ITEM_BITMAP::DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset,
|
||||
GR_DRAWMODE aDrawMode, COLOR4D aColor )
|
||||
{
|
||||
WORKSHEET_DATAITEM_BITMAP* parent = (WORKSHEET_DATAITEM_BITMAP*)GetParent();
|
||||
|
||||
if( parent->m_ImageBitmap )
|
||||
{
|
||||
GRSetDrawMode( aDC, ( aDrawMode == UNSPECIFIED_DRAWMODE ) ? GR_COPY : aDrawMode );
|
||||
parent->m_ImageBitmap->DrawBitmap( aDC, m_pos + aOffset );
|
||||
GRSetDrawMode( aDC, GR_COPY );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool WS_DRAW_ITEM_BITMAP::HitTest( const wxPoint& aPosition) const
|
||||
{
|
||||
const WORKSHEET_DATAITEM_BITMAP* parent = static_cast<const WORKSHEET_DATAITEM_BITMAP*>( GetParent() );
|
||||
|
||||
if( parent->m_ImageBitmap == NULL )
|
||||
return false;
|
||||
|
||||
EDA_RECT rect = parent->m_ImageBitmap->GetBoundingBox();
|
||||
rect.Move( m_pos );
|
||||
return rect.Contains( aPosition );
|
||||
}
|
||||
|
||||
|
||||
bool WS_DRAW_ITEM_BITMAP::HitTest( const EDA_RECT& aRect ) const
|
||||
{
|
||||
const WORKSHEET_DATAITEM_BITMAP* parent = static_cast<const WORKSHEET_DATAITEM_BITMAP*>( GetParent() );
|
||||
|
||||
if( parent->m_ImageBitmap == NULL )
|
||||
return false;
|
||||
|
||||
EDA_RECT rect = parent->m_ImageBitmap->GetBoundingBox();
|
||||
rect.Move( m_pos );
|
||||
return rect.Intersects( aRect );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return true if the point aPosition is on the reference point of this item.
|
||||
*/
|
||||
bool WS_DRAW_ITEM_BITMAP::HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition )
|
||||
{
|
||||
wxPoint dist = m_pos - aPosition;
|
||||
int marker_size = WORKSHEET_DATAITEM::GetMarkerSizeUi( getScaleFromZoom( aDC ) );
|
||||
|
||||
if( std::abs( dist.x) <= marker_size / 2 &&
|
||||
std::abs( dist.y) <= marker_size / 2 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -31,8 +31,8 @@
|
||||
|
||||
#include <fctsys.h>
|
||||
#include <base_struct.h>
|
||||
#include <worksheet.h>
|
||||
#include <worksheet_shape_builder.h>
|
||||
#include <worksheet_painter.h>
|
||||
#include <ws_draw_item.h>
|
||||
#include <worksheet_dataitem.h>
|
||||
#include <page_layout_reader_lexer.h>
|
||||
|
||||
@ -115,16 +115,11 @@ PAGE_LAYOUT_READER_PARSER::PAGE_LAYOUT_READER_PARSER( const char* aLine, const w
|
||||
|
||||
void PAGE_LAYOUT_READER_PARSER::Parse( WORKSHEET_LAYOUT* aLayout )
|
||||
{
|
||||
T token;
|
||||
WORKSHEET_DATAITEM * item;
|
||||
WORKSHEET_DATAITEM* item;
|
||||
LOCALE_IO toggle;
|
||||
|
||||
LOCALE_IO toggle;
|
||||
|
||||
while( ( token = NextTok() ) != T_RIGHT )
|
||||
for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
||||
{
|
||||
if( token == T_EOF)
|
||||
break;
|
||||
|
||||
if( token == T_LEFT )
|
||||
token = NextTok();
|
||||
|
||||
@ -177,12 +172,8 @@ void PAGE_LAYOUT_READER_PARSER::Parse( WORKSHEET_LAYOUT* aLayout )
|
||||
|
||||
void PAGE_LAYOUT_READER_PARSER::parseSetup( WORKSHEET_LAYOUT* aLayout )
|
||||
{
|
||||
T token;
|
||||
while( ( token = NextTok() ) != T_RIGHT )
|
||||
for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
||||
{
|
||||
if( token == T_EOF)
|
||||
break;
|
||||
|
||||
switch( token )
|
||||
{
|
||||
case T_LEFT:
|
||||
@ -233,13 +224,8 @@ void PAGE_LAYOUT_READER_PARSER::parseSetup( WORKSHEET_LAYOUT* aLayout )
|
||||
|
||||
void PAGE_LAYOUT_READER_PARSER::parsePolygon( WORKSHEET_DATAITEM_POLYPOLYGON * aItem )
|
||||
{
|
||||
T token;
|
||||
|
||||
while( ( token = NextTok() ) != T_RIGHT )
|
||||
for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
||||
{
|
||||
if( token == T_EOF)
|
||||
break;
|
||||
|
||||
if( token == T_LEFT )
|
||||
token = NextTok();
|
||||
|
||||
@ -307,13 +293,9 @@ void PAGE_LAYOUT_READER_PARSER::parsePolygon( WORKSHEET_DATAITEM_POLYPOLYGON * a
|
||||
void PAGE_LAYOUT_READER_PARSER::parsePolyOutline( WORKSHEET_DATAITEM_POLYPOLYGON * aItem )
|
||||
{
|
||||
DPOINT corner;
|
||||
T token;
|
||||
|
||||
while( ( token = NextTok() ) != T_RIGHT )
|
||||
for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
||||
{
|
||||
if( token == T_EOF)
|
||||
break;
|
||||
|
||||
if( token == T_LEFT )
|
||||
token = NextTok();
|
||||
|
||||
@ -336,15 +318,11 @@ void PAGE_LAYOUT_READER_PARSER::parsePolyOutline( WORKSHEET_DATAITEM_POLYPOLYGON
|
||||
|
||||
void PAGE_LAYOUT_READER_PARSER::parseBitmap( WORKSHEET_DATAITEM_BITMAP * aItem )
|
||||
{
|
||||
T token;
|
||||
BITMAP_BASE* image = new BITMAP_BASE;
|
||||
aItem->m_ImageBitmap = image;
|
||||
|
||||
while( ( token = NextTok() ) != T_RIGHT )
|
||||
for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
||||
{
|
||||
if( token == T_EOF)
|
||||
break;
|
||||
|
||||
if( token == T_LEFT )
|
||||
token = NextTok();
|
||||
|
||||
@ -403,28 +381,24 @@ void PAGE_LAYOUT_READER_PARSER::parseBitmap( WORKSHEET_DATAITEM_BITMAP * aItem )
|
||||
void PAGE_LAYOUT_READER_PARSER::readPngdata( WORKSHEET_DATAITEM_BITMAP * aItem )
|
||||
{
|
||||
std::string tmp;
|
||||
T token;
|
||||
|
||||
while( ( token = NextTok() ) != T_RIGHT )
|
||||
for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
||||
{
|
||||
if( token == T_EOF)
|
||||
break;
|
||||
|
||||
if( token == T_LEFT )
|
||||
token = NextTok();
|
||||
|
||||
switch( token )
|
||||
{
|
||||
case T_data:
|
||||
NeedSYMBOLorNUMBER();
|
||||
tmp += CurStr();
|
||||
tmp += "\n";
|
||||
NeedRIGHT();
|
||||
break;
|
||||
case T_data:
|
||||
NeedSYMBOLorNUMBER();
|
||||
tmp += CurStr();
|
||||
tmp += "\n";
|
||||
NeedRIGHT();
|
||||
break;
|
||||
|
||||
default:
|
||||
Unexpected( CurText() );
|
||||
break;
|
||||
default:
|
||||
Unexpected( CurText() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -434,34 +408,19 @@ void PAGE_LAYOUT_READER_PARSER::readPngdata( WORKSHEET_DATAITEM_BITMAP * aItem )
|
||||
STRING_LINE_READER str_reader( tmp, wxT("Png kicad_wks data") );
|
||||
|
||||
if( ! aItem->m_ImageBitmap->LoadData( str_reader, msg ) )
|
||||
{
|
||||
wxLogMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PAGE_LAYOUT_READER_PARSER::readOption( WORKSHEET_DATAITEM * aItem )
|
||||
{
|
||||
T token;
|
||||
|
||||
while( ( token = NextTok() ) != T_RIGHT )
|
||||
for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
||||
{
|
||||
if( token == T_EOF)
|
||||
break;
|
||||
|
||||
switch( token )
|
||||
{
|
||||
case T_page1only:
|
||||
aItem->SetPage1Option( 1 );
|
||||
break;
|
||||
|
||||
case T_notonpage1:
|
||||
aItem->SetPage1Option( -1 );
|
||||
break;
|
||||
|
||||
default:
|
||||
Unexpected( CurText() );
|
||||
break;
|
||||
case T_page1only: aItem->SetPage1Option( FIRST_PAGE_ONLY ); break;
|
||||
case T_notonpage1: aItem->SetPage1Option( SUBSEQUENT_PAGES ); break;
|
||||
default: Unexpected( CurText() ); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -469,13 +428,8 @@ void PAGE_LAYOUT_READER_PARSER::readOption( WORKSHEET_DATAITEM * aItem )
|
||||
|
||||
void PAGE_LAYOUT_READER_PARSER::parseGraphic( WORKSHEET_DATAITEM * aItem )
|
||||
{
|
||||
T token;
|
||||
|
||||
while( ( token = NextTok() ) != T_RIGHT )
|
||||
for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
||||
{
|
||||
if( token == T_EOF)
|
||||
break;
|
||||
|
||||
if( token == T_LEFT )
|
||||
token = NextTok();
|
||||
else
|
||||
@ -544,13 +498,8 @@ void PAGE_LAYOUT_READER_PARSER::parseGraphic( WORKSHEET_DATAITEM * aItem )
|
||||
|
||||
void PAGE_LAYOUT_READER_PARSER::parseText( WORKSHEET_DATAITEM_TEXT* aItem )
|
||||
{
|
||||
T token;
|
||||
|
||||
while( ( token = NextTok() ) != T_RIGHT )
|
||||
for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
||||
{
|
||||
if( token == T_EOF)
|
||||
break;
|
||||
|
||||
if( token == T_LEFT )
|
||||
token = NextTok();
|
||||
|
||||
@ -607,22 +556,19 @@ void PAGE_LAYOUT_READER_PARSER::parseText( WORKSHEET_DATAITEM_TEXT* aItem )
|
||||
break;
|
||||
|
||||
case T_font:
|
||||
while( ( token = NextTok() ) != T_RIGHT )
|
||||
for( token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
||||
{
|
||||
if( token == T_EOF)
|
||||
break;
|
||||
|
||||
switch( token )
|
||||
{
|
||||
case T_LEFT:
|
||||
break;
|
||||
|
||||
case T_bold:
|
||||
aItem->SetBold( true );
|
||||
aItem->m_Bold = true;
|
||||
break;
|
||||
|
||||
case T_italic:
|
||||
aItem->SetItalic( true );
|
||||
aItem->m_Italic = true;
|
||||
break;
|
||||
|
||||
case T_size:
|
||||
@ -644,11 +590,8 @@ void PAGE_LAYOUT_READER_PARSER::parseText( WORKSHEET_DATAITEM_TEXT* aItem )
|
||||
break;
|
||||
|
||||
case T_justify:
|
||||
while( ( token = NextTok() ) != T_RIGHT )
|
||||
for( token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
||||
{
|
||||
if( token == T_EOF)
|
||||
break;
|
||||
|
||||
switch( token )
|
||||
{
|
||||
case T_center:
|
||||
@ -694,34 +637,18 @@ void PAGE_LAYOUT_READER_PARSER::parseText( WORKSHEET_DATAITEM_TEXT* aItem )
|
||||
// parse an expression like " 25 1 ltcorner)"
|
||||
void PAGE_LAYOUT_READER_PARSER::parseCoordinate( POINT_COORD& aCoord)
|
||||
{
|
||||
T token;
|
||||
|
||||
aCoord.m_Pos.x = parseDouble();
|
||||
aCoord.m_Pos.y = parseDouble();
|
||||
|
||||
while( ( token = NextTok() ) != T_RIGHT )
|
||||
for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
||||
{
|
||||
switch( token )
|
||||
{
|
||||
case T_ltcorner:
|
||||
aCoord.m_Anchor = LT_CORNER; // left top corner
|
||||
break;
|
||||
|
||||
case T_lbcorner:
|
||||
aCoord.m_Anchor = LB_CORNER; // left bottom corner
|
||||
break;
|
||||
|
||||
case T_rbcorner:
|
||||
aCoord.m_Anchor = RB_CORNER; // right bottom corner
|
||||
break;
|
||||
|
||||
case T_rtcorner:
|
||||
aCoord.m_Anchor = RT_CORNER; // right top corner
|
||||
break;
|
||||
|
||||
default:
|
||||
Unexpected( CurText() );
|
||||
break;
|
||||
case T_ltcorner: aCoord.m_Anchor = LT_CORNER; break;
|
||||
case T_lbcorner: aCoord.m_Anchor = LB_CORNER; break;
|
||||
case T_rbcorner: aCoord.m_Anchor = RB_CORNER; break;
|
||||
case T_rtcorner: aCoord.m_Anchor = RT_CORNER; break;
|
||||
default: Unexpected( CurText() ); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,258 +0,0 @@
|
||||
/**
|
||||
* @file title_block_shapes.cpp
|
||||
* @brief description of graphic items and texts to build a title block
|
||||
*/
|
||||
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 1992-2018 Jean-Pierre Charras <jp.charras at wanadoo.fr>.
|
||||
* Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.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
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* the class WORKSHEET_DATAITEM (and WORKSHEET_DATAITEM_TEXT) defines
|
||||
* a basic shape of a page layout ( frame references and title block )
|
||||
* Basic shapes are line, rect and texts
|
||||
* the WORKSHEET_DATAITEM coordinates units is the mm, and are relative to
|
||||
* one of 4 page corners.
|
||||
*
|
||||
* These items cannot be drawn or plot "as this". they should be converted
|
||||
* to a "draw list" (WS_DRAW_ITEM_BASE and derived items)
|
||||
|
||||
* The list of these items is stored in a WORKSHEET_LAYOUT instance.
|
||||
*
|
||||
* When building the draw list:
|
||||
* the WORKSHEET_LAYOUT is used to create a WS_DRAW_ITEM_LIST
|
||||
* coordinates are converted to draw/plot coordinates.
|
||||
* texts are expanded if they contain format symbols.
|
||||
* Items with m_RepeatCount > 1 are created m_RepeatCount times
|
||||
*
|
||||
* the WORKSHEET_LAYOUT is created only once.
|
||||
* the WS_DRAW_ITEM_LIST is created each time the page layout is plot/drawn
|
||||
*
|
||||
* the WORKSHEET_LAYOUT instance is created from a S expression which
|
||||
* describes the page layout (can be the default page layout or a custom file).
|
||||
*/
|
||||
|
||||
#include <fctsys.h>
|
||||
#include <draw_graphic_text.h>
|
||||
#include <page_info.h>
|
||||
#include <worksheet.h>
|
||||
#include <title_block.h>
|
||||
#include <worksheet_shape_builder.h>
|
||||
#include <worksheet_dataitem.h>
|
||||
|
||||
|
||||
void WS_DRAW_ITEM_LIST::BuildWorkSheetGraphicList(
|
||||
const PAGE_INFO& aPageInfo,
|
||||
const TITLE_BLOCK& aTitleBlock,
|
||||
COLOR4D aColor, COLOR4D aAltColor )
|
||||
{
|
||||
WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance();
|
||||
|
||||
#define milsTomm (25.4/1000)
|
||||
|
||||
m_titleBlock = &aTitleBlock;
|
||||
m_paperFormat = &aPageInfo.GetType();
|
||||
|
||||
wxPoint LTmargin( Mm2mils( pglayout.GetLeftMargin() ),
|
||||
Mm2mils( pglayout.GetTopMargin() ) );
|
||||
wxPoint RBmargin( Mm2mils( pglayout.GetRightMargin() ),
|
||||
Mm2mils( pglayout.GetBottomMargin() ) );
|
||||
|
||||
SetMargins( LTmargin, RBmargin );
|
||||
SetPageSize( aPageInfo.GetSizeMils() );
|
||||
|
||||
// Build the basic layout shape, if the layout list is empty
|
||||
if( pglayout.GetCount() == 0 && !pglayout.VoidListAllowed() )
|
||||
pglayout.SetPageLayout();
|
||||
|
||||
WORKSHEET_DATAITEM::m_WSunits2Iu = m_milsToIu / milsTomm;
|
||||
WORKSHEET_DATAITEM::m_Color = aColor; // the default color to draw items
|
||||
WORKSHEET_DATAITEM::m_AltColor = aAltColor; // an alternate color to draw items
|
||||
|
||||
// Left top corner position
|
||||
DPOINT lt_corner;
|
||||
lt_corner.x = pglayout.GetLeftMargin();
|
||||
lt_corner.y = pglayout.GetTopMargin();
|
||||
WORKSHEET_DATAITEM::m_LT_Corner = lt_corner;
|
||||
|
||||
// Right bottom corner position
|
||||
DPOINT rb_corner;
|
||||
rb_corner.x = (m_pageSize.x*milsTomm) - pglayout.GetRightMargin();
|
||||
rb_corner.y = (m_pageSize.y*milsTomm) - pglayout.GetBottomMargin();
|
||||
WORKSHEET_DATAITEM::m_RB_Corner = rb_corner;
|
||||
|
||||
WS_DRAW_ITEM_TEXT* gtext;
|
||||
int pensize;
|
||||
|
||||
for( unsigned ii = 0; ; ii++ )
|
||||
{
|
||||
WORKSHEET_DATAITEM* wsItem = pglayout.GetItem( ii );
|
||||
|
||||
if( wsItem == NULL )
|
||||
break;
|
||||
|
||||
// Generate it only if the page option allows this
|
||||
if( wsItem->GetPage1Option() < 0 // Not on page 1
|
||||
&& m_sheetNumber <= 1 )
|
||||
continue;
|
||||
|
||||
if( wsItem->GetPage1Option() > 0 // Only on page 1
|
||||
&& m_sheetNumber > 1 )
|
||||
continue;
|
||||
|
||||
COLOR4D color = wsItem->GetItemColor();
|
||||
|
||||
pensize = wsItem->GetPenSizeUi();
|
||||
|
||||
switch( wsItem->GetType() )
|
||||
{
|
||||
case WORKSHEET_DATAITEM::WS_TEXT:
|
||||
{
|
||||
WORKSHEET_DATAITEM_TEXT * wsText = (WORKSHEET_DATAITEM_TEXT*)wsItem;
|
||||
bool multilines = false;
|
||||
|
||||
if( wsText->m_SpecialMode )
|
||||
wsText->m_FullText = wsText->m_TextBase;
|
||||
else
|
||||
{
|
||||
wsText->m_FullText = BuildFullText( wsText->m_TextBase );
|
||||
multilines = wsText->ReplaceAntiSlashSequence();
|
||||
}
|
||||
|
||||
if( wsText->m_FullText.IsEmpty() )
|
||||
break;
|
||||
|
||||
if( pensize == 0 )
|
||||
pensize = m_penSize;
|
||||
|
||||
wsText->SetConstrainedTextSize();
|
||||
wxSize textsize;
|
||||
|
||||
textsize.x = KiROUND( wsText->m_ConstrainedTextSize.x
|
||||
* WORKSHEET_DATAITEM::m_WSunits2Iu );
|
||||
textsize.y = KiROUND( wsText->m_ConstrainedTextSize.y
|
||||
* WORKSHEET_DATAITEM::m_WSunits2Iu );
|
||||
|
||||
if( wsText->IsBold())
|
||||
pensize = GetPenSizeForBold( std::min( textsize.x, textsize.y ) );
|
||||
|
||||
for( int jj = 0; jj < wsText->m_RepeatCount; jj++)
|
||||
{
|
||||
if( jj && ! wsText->IsInsidePage( jj ) )
|
||||
continue;
|
||||
|
||||
gtext = new WS_DRAW_ITEM_TEXT( wsText, wsText->m_FullText,
|
||||
wsText->GetStartPosUi( jj ),
|
||||
textsize, pensize, color,
|
||||
wsText->IsItalic(),
|
||||
wsText->IsBold() );
|
||||
Append( gtext );
|
||||
gtext->SetMultilineAllowed( multilines );
|
||||
wsText->TransfertSetupToGraphicText( gtext );
|
||||
|
||||
// Increment label for the next text
|
||||
// (has no meaning for multiline texts)
|
||||
if( wsText->m_RepeatCount > 1 && !multilines )
|
||||
wsText->IncrementLabel( (jj+1)*wsText->m_IncrementLabel);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case WORKSHEET_DATAITEM::WS_SEGMENT:
|
||||
if( pensize == 0 )
|
||||
pensize = m_penSize;
|
||||
|
||||
for( int jj = 0; jj < wsItem->m_RepeatCount; jj++ )
|
||||
{
|
||||
if( jj && ! wsItem->IsInsidePage( jj ) )
|
||||
continue;
|
||||
Append( new WS_DRAW_ITEM_LINE( wsItem, wsItem->GetStartPosUi( jj ),
|
||||
wsItem->GetEndPosUi( jj ),
|
||||
pensize, color ) );
|
||||
}
|
||||
break;
|
||||
|
||||
case WORKSHEET_DATAITEM::WS_RECT:
|
||||
if( pensize == 0 )
|
||||
pensize = m_penSize;
|
||||
|
||||
for( int jj = 0; jj < wsItem->m_RepeatCount; jj++ )
|
||||
{
|
||||
if( jj && ! wsItem->IsInsidePage( jj ) )
|
||||
break;
|
||||
|
||||
Append( new WS_DRAW_ITEM_RECT( wsItem, wsItem->GetStartPosUi( jj ),
|
||||
wsItem->GetEndPosUi( jj ),
|
||||
pensize, color ) );
|
||||
}
|
||||
break;
|
||||
|
||||
case WORKSHEET_DATAITEM::WS_POLYPOLYGON:
|
||||
{
|
||||
WORKSHEET_DATAITEM_POLYPOLYGON * wspoly =
|
||||
(WORKSHEET_DATAITEM_POLYPOLYGON*) wsItem;
|
||||
for( int jj = 0; jj < wsItem->m_RepeatCount; jj++ )
|
||||
{
|
||||
if( jj && ! wsItem->IsInsidePage( jj ) )
|
||||
continue;
|
||||
|
||||
for( int kk = 0; kk < wspoly->GetPolyCount(); kk++ )
|
||||
{
|
||||
const bool fill = true;
|
||||
WS_DRAW_ITEM_POLYGON* poly = new WS_DRAW_ITEM_POLYGON( wspoly,
|
||||
wspoly->GetStartPosUi( jj ),
|
||||
fill, pensize, color );
|
||||
Append( poly );
|
||||
|
||||
// Create polygon outline
|
||||
unsigned ist = wspoly->GetPolyIndexStart( kk );
|
||||
unsigned iend = wspoly->GetPolyIndexEnd( kk );
|
||||
while( ist <= iend )
|
||||
poly->m_Corners.push_back(
|
||||
wspoly->GetCornerPositionUi( ist++, jj ) );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case WORKSHEET_DATAITEM::WS_BITMAP:
|
||||
|
||||
((WORKSHEET_DATAITEM_BITMAP*)wsItem)->SetPixelScaleFactor();
|
||||
|
||||
for( int jj = 0; jj < wsItem->m_RepeatCount; jj++ )
|
||||
{
|
||||
if( jj && ! wsItem->IsInsidePage( jj ) )
|
||||
continue;
|
||||
|
||||
Append( new WS_DRAW_ITEM_BITMAP( wsItem,
|
||||
wsItem->GetStartPosUi( jj ) ) );
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,3 @@
|
||||
/**
|
||||
* @file worksheet_dataitem.cpp
|
||||
* @brief description of graphic items and texts to build a title block
|
||||
*/
|
||||
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
@ -57,38 +52,89 @@
|
||||
#include <fctsys.h>
|
||||
#include <draw_graphic_text.h>
|
||||
#include <eda_rect.h>
|
||||
#include <worksheet.h>
|
||||
#include <worksheet_painter.h>
|
||||
#include <title_block.h>
|
||||
#include <worksheet_shape_builder.h>
|
||||
#include <ws_draw_item.h>
|
||||
#include <worksheet_dataitem.h>
|
||||
#include <view/view.h>
|
||||
|
||||
using KIGFX::COLOR4D;
|
||||
|
||||
|
||||
// Static members of class WORKSHEET_DATAITEM:
|
||||
double WORKSHEET_DATAITEM::m_WSunits2Iu = 1.0;
|
||||
double WORKSHEET_DATAITEM::m_WSunits2Iu = 1000.0;
|
||||
DPOINT WORKSHEET_DATAITEM::m_RB_Corner;
|
||||
DPOINT WORKSHEET_DATAITEM::m_LT_Corner;
|
||||
double WORKSHEET_DATAITEM::m_DefaultLineWidth = 0.0;
|
||||
DSIZE WORKSHEET_DATAITEM::m_DefaultTextSize( TB_DEFAULT_TEXTSIZE, TB_DEFAULT_TEXTSIZE );
|
||||
double WORKSHEET_DATAITEM::m_DefaultTextThickness = 0.0;
|
||||
bool WORKSHEET_DATAITEM::m_SpecialMode = false;
|
||||
COLOR4D WORKSHEET_DATAITEM::m_Color = COLOR4D( RED ); // the default color to draw items
|
||||
COLOR4D WORKSHEET_DATAITEM::m_AltColor = COLOR4D( RED ); // an alternate color to draw items
|
||||
COLOR4D WORKSHEET_DATAITEM::m_SelectedColor = COLOR4D( BROWN ); // the color to draw selected items
|
||||
|
||||
|
||||
// The constructor:
|
||||
WORKSHEET_DATAITEM::WORKSHEET_DATAITEM( WS_ItemType aType )
|
||||
WORKSHEET_DATAITEM::WORKSHEET_DATAITEM( WS_ITEM_TYPE aType )
|
||||
{
|
||||
m_pageOption = ALL_PAGES;
|
||||
m_type = aType;
|
||||
m_flags = 0;
|
||||
m_RepeatCount = 1;
|
||||
m_IncrementLabel = 1;
|
||||
m_LineWidth = 0;
|
||||
}
|
||||
|
||||
|
||||
void WORKSHEET_DATAITEM::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView )
|
||||
{
|
||||
int pensize = GetPenSizeUi();
|
||||
|
||||
if( pensize == 0 )
|
||||
pensize = aCollector ? aCollector->GetDefaultPenSize() : 0;
|
||||
|
||||
for( WS_DRAW_ITEM_BASE* item : m_drawItems )
|
||||
{
|
||||
if( aCollector )
|
||||
aCollector->Remove( item );
|
||||
|
||||
if( aView )
|
||||
aView->Remove( item );
|
||||
|
||||
delete item;
|
||||
}
|
||||
|
||||
m_drawItems.clear();
|
||||
|
||||
for( int jj = 0; jj < m_RepeatCount; jj++ )
|
||||
{
|
||||
if( jj && ! IsInsidePage( jj ) )
|
||||
continue;
|
||||
|
||||
if( m_type == WS_SEGMENT )
|
||||
{
|
||||
auto line = new WS_DRAW_ITEM_LINE( this, GetStartPosUi( jj ), GetEndPosUi( jj ),
|
||||
pensize );
|
||||
m_drawItems.push_back( line );
|
||||
|
||||
if( aCollector )
|
||||
aCollector->Append( line );
|
||||
|
||||
if( aView )
|
||||
aView->Add( line );
|
||||
}
|
||||
else if( m_type == WS_RECT )
|
||||
{
|
||||
auto rect = new WS_DRAW_ITEM_RECT( this, GetStartPosUi( jj ), GetEndPosUi( jj ),
|
||||
pensize );
|
||||
m_drawItems.push_back( rect );
|
||||
|
||||
if( aCollector )
|
||||
aCollector->Append( rect );
|
||||
|
||||
if( aView )
|
||||
aView->Add( rect );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// move item to aPosition
|
||||
// starting point is moved to aPosition
|
||||
// the Ending point is moved to a position which keeps the item size
|
||||
@ -112,6 +158,16 @@ void WORKSHEET_DATAITEM::MoveTo( DPOINT aPosition )
|
||||
|
||||
MoveStartPointTo( aPosition );
|
||||
MoveEndPointTo( endpos );
|
||||
|
||||
for( int jj = 0; jj < m_RepeatCount; jj++ )
|
||||
{
|
||||
if( jj && !IsInsidePage( jj ) )
|
||||
continue;
|
||||
|
||||
WS_DRAW_ITEM_BASE* drawItem = m_drawItems[ jj ];
|
||||
drawItem->SetPosition( GetStartPosUi( jj ) );
|
||||
drawItem->SetEnd( GetEndPosUi( jj ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -331,49 +387,15 @@ const wxString WORKSHEET_DATAITEM::GetClassName() const
|
||||
{
|
||||
case WS_TEXT: name = wxT( "Text" ); break;
|
||||
case WS_SEGMENT: name = wxT( "Line" ); break;
|
||||
case WS_RECT: name = wxT( "Rect" ); break;
|
||||
case WS_POLYPOLYGON: name = wxT( "Poly" ); break;
|
||||
case WS_BITMAP: name = wxT( "Bitmap" ); break;
|
||||
case WS_RECT: name = wxT( "Rectangle" ); break;
|
||||
case WS_POLYPOLYGON: name = wxT( "Imported Shape" ); break;
|
||||
case WS_BITMAP: name = wxT( "Image" ); break;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
/* return 0 if the item has no specific option for page 1
|
||||
* 1 if the item is only on page 1
|
||||
* -1 if the item is not on page 1
|
||||
*/
|
||||
int WORKSHEET_DATAITEM::GetPage1Option()
|
||||
{
|
||||
if(( m_flags & PAGE1OPTION) == PAGE1OPTION_NOTONPAGE1 )
|
||||
return -1;
|
||||
|
||||
if(( m_flags & PAGE1OPTION) == PAGE1OPTION_PAGE1ONLY )
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Set the option for page 1
|
||||
* aChoice = 0 if the item has no specific option for page 1
|
||||
* > 0 if the item is only on page 1
|
||||
* < 0 if the item is not on page 1
|
||||
*/
|
||||
void WORKSHEET_DATAITEM::SetPage1Option( int aChoice )
|
||||
{
|
||||
ClearFlags( PAGE1OPTION );
|
||||
|
||||
if( aChoice > 0 )
|
||||
SetFlags( PAGE1OPTION_PAGE1ONLY );
|
||||
|
||||
else if( aChoice < 0 )
|
||||
SetFlags( PAGE1OPTION_NOTONPAGE1 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
WORKSHEET_DATAITEM_POLYPOLYGON::WORKSHEET_DATAITEM_POLYPOLYGON() :
|
||||
WORKSHEET_DATAITEM( WS_POLYPOLYGON )
|
||||
{
|
||||
@ -381,8 +403,45 @@ WORKSHEET_DATAITEM_POLYPOLYGON::WORKSHEET_DATAITEM_POLYPOLYGON() :
|
||||
}
|
||||
|
||||
|
||||
const DPOINT WORKSHEET_DATAITEM_POLYPOLYGON::GetCornerPosition( unsigned aIdx,
|
||||
int aRepeat ) const
|
||||
void WORKSHEET_DATAITEM_POLYPOLYGON::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector,
|
||||
KIGFX::VIEW* aView )
|
||||
{
|
||||
for( WS_DRAW_ITEM_BASE* item : m_drawItems )
|
||||
delete item;
|
||||
|
||||
m_drawItems.clear();
|
||||
|
||||
for( int jj = 0; jj < m_RepeatCount; jj++ )
|
||||
{
|
||||
if( jj && !IsInsidePage( jj ) )
|
||||
continue;
|
||||
|
||||
for( int kk = 0; kk < GetPolyCount(); kk++ )
|
||||
{
|
||||
const bool fill = true;
|
||||
int pensize = GetPenSizeUi();
|
||||
auto poly = new WS_DRAW_ITEM_POLYGON( this, GetStartPosUi( jj ), fill, pensize );
|
||||
m_drawItems.push_back( poly );
|
||||
|
||||
if( aCollector )
|
||||
aCollector->Append( poly );
|
||||
|
||||
if( aView )
|
||||
aView->Add( poly );
|
||||
|
||||
// Create polygon outline
|
||||
unsigned ist = GetPolyIndexStart( kk );
|
||||
unsigned iend = GetPolyIndexEnd( kk );
|
||||
|
||||
while( ist <= iend )
|
||||
poly->m_Corners.push_back( GetCornerPositionUi( ist++, jj ) );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const DPOINT WORKSHEET_DATAITEM_POLYPOLYGON::GetCornerPosition( unsigned aIdx, int aRepeat ) const
|
||||
{
|
||||
DPOINT pos = m_Corners[aIdx];
|
||||
|
||||
@ -461,16 +520,67 @@ WORKSHEET_DATAITEM_TEXT::WORKSHEET_DATAITEM_TEXT( const wxString& aTextBase ) :
|
||||
m_IncrementLabel = 1;
|
||||
m_Hjustify = GR_TEXT_HJUSTIFY_LEFT;
|
||||
m_Vjustify = GR_TEXT_VJUSTIFY_CENTER;
|
||||
m_Italic = false;
|
||||
m_Bold = false;
|
||||
m_Orient = 0.0;
|
||||
m_LineWidth = 0.0; // 0.0 means use default value
|
||||
m_LineWidth = 0.0; // 0 means use default value
|
||||
}
|
||||
|
||||
|
||||
void WORKSHEET_DATAITEM_TEXT::TransfertSetupToGraphicText( WS_DRAW_ITEM_TEXT* aGText )
|
||||
void WORKSHEET_DATAITEM_TEXT::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView )
|
||||
{
|
||||
aGText->SetHorizJustify( m_Hjustify ) ;
|
||||
aGText->SetVertJustify( m_Vjustify );
|
||||
aGText->SetTextAngle( m_Orient * 10 ); // graphic text orient unit = 0.1 degree
|
||||
int pensize = GetPenSizeUi();
|
||||
bool multilines = false;
|
||||
|
||||
if( m_SpecialMode )
|
||||
m_FullText = m_TextBase;
|
||||
else
|
||||
{
|
||||
m_FullText = aCollector ? aCollector->BuildFullText( m_TextBase ) : wxEmptyString;
|
||||
multilines = ReplaceAntiSlashSequence();
|
||||
}
|
||||
|
||||
if( pensize == 0 )
|
||||
pensize = aCollector ? aCollector->GetDefaultPenSize() : 1;
|
||||
|
||||
SetConstrainedTextSize();
|
||||
wxSize textsize;
|
||||
|
||||
textsize.x = KiROUND( m_ConstrainedTextSize.x * WORKSHEET_DATAITEM::m_WSunits2Iu );
|
||||
textsize.y = KiROUND( m_ConstrainedTextSize.y * WORKSHEET_DATAITEM::m_WSunits2Iu );
|
||||
|
||||
if( m_Bold )
|
||||
pensize = GetPenSizeForBold( std::min( textsize.x, textsize.y ) );
|
||||
|
||||
for( WS_DRAW_ITEM_BASE* item : m_drawItems )
|
||||
delete item;
|
||||
|
||||
m_drawItems.clear();
|
||||
|
||||
for( int jj = 0; jj < m_RepeatCount; ++jj )
|
||||
{
|
||||
if( jj > 0 && !IsInsidePage( jj ) )
|
||||
continue;
|
||||
|
||||
auto text = new WS_DRAW_ITEM_TEXT( this, m_FullText, GetStartPosUi( jj ), textsize,
|
||||
pensize, m_Italic, m_Bold );
|
||||
m_drawItems.push_back( text );
|
||||
|
||||
if( aCollector )
|
||||
aCollector->Append( text );
|
||||
|
||||
if( aView )
|
||||
aView->Add( text );
|
||||
|
||||
text->SetHorizJustify( m_Hjustify ) ;
|
||||
text->SetVertJustify( m_Vjustify );
|
||||
text->SetTextAngle( m_Orient * 10 ); // graphic text orient unit = 0.1 degree
|
||||
text->SetMultilineAllowed( multilines );
|
||||
|
||||
// Increment label for the next text (has no meaning for multiline texts)
|
||||
if( m_RepeatCount > 1 && !multilines )
|
||||
IncrementLabel( ( jj + 1 ) * m_IncrementLabel );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -549,13 +659,12 @@ void WORKSHEET_DATAITEM_TEXT::SetConstrainedTextSize()
|
||||
int linewidth = 0;
|
||||
size_micron.x = KiROUND( m_ConstrainedTextSize.x * FSCALE );
|
||||
size_micron.y = KiROUND( m_ConstrainedTextSize.y * FSCALE );
|
||||
WS_DRAW_ITEM_TEXT dummy( WS_DRAW_ITEM_TEXT( this, this->m_FullText,
|
||||
wxPoint(0,0),
|
||||
size_micron,
|
||||
linewidth, BLACK,
|
||||
IsItalic(), IsBold() ) );
|
||||
WS_DRAW_ITEM_TEXT dummy( WS_DRAW_ITEM_TEXT( this, this->m_FullText, wxPoint( 0, 0 ),
|
||||
size_micron, linewidth, m_Italic, m_Bold ) );
|
||||
dummy.SetMultilineAllowed( true );
|
||||
TransfertSetupToGraphicText( &dummy );
|
||||
dummy.SetHorizJustify( m_Hjustify ) ;
|
||||
dummy.SetVertJustify( m_Vjustify );
|
||||
dummy.SetTextAngle( m_Orient * 10 );
|
||||
|
||||
EDA_RECT rect = dummy.GetTextBox();
|
||||
DSIZE size;
|
||||
@ -571,6 +680,30 @@ void WORKSHEET_DATAITEM_TEXT::SetConstrainedTextSize()
|
||||
}
|
||||
|
||||
|
||||
void WORKSHEET_DATAITEM_BITMAP::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView )
|
||||
{
|
||||
for( WS_DRAW_ITEM_BASE* item : m_drawItems )
|
||||
delete item;
|
||||
|
||||
m_drawItems.clear();
|
||||
|
||||
for( int jj = 0; jj < m_RepeatCount; jj++ )
|
||||
{
|
||||
if( jj && !IsInsidePage( jj ) )
|
||||
continue;
|
||||
|
||||
auto bitmap = new WS_DRAW_ITEM_BITMAP( this, GetStartPosUi( jj ) );
|
||||
m_drawItems.push_back( bitmap );
|
||||
|
||||
if( aCollector )
|
||||
aCollector->Append( bitmap );
|
||||
|
||||
if( aView )
|
||||
aView->Add( bitmap );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* set the pixel scale factor of the bitmap
|
||||
* this factor depend on the application internal unit
|
||||
* and the PPI bitmap factor
|
||||
|
@ -52,9 +52,9 @@
|
||||
#include <fctsys.h>
|
||||
#include <kiface_i.h>
|
||||
#include <draw_graphic_text.h>
|
||||
#include <worksheet.h>
|
||||
#include <worksheet_painter.h>
|
||||
#include <title_block.h>
|
||||
#include <worksheet_shape_builder.h>
|
||||
#include <ws_draw_item.h>
|
||||
#include <worksheet_dataitem.h>
|
||||
|
||||
|
||||
@ -121,43 +121,23 @@ void WORKSHEET_LAYOUT::SetBottomMargin( double aMargin )
|
||||
|
||||
void WORKSHEET_LAYOUT::ClearList()
|
||||
{
|
||||
for( unsigned ii = 0; ii < m_list.size(); ii++ )
|
||||
delete m_list[ii];
|
||||
for( WORKSHEET_DATAITEM* item : m_list )
|
||||
delete item;
|
||||
|
||||
m_list.clear();
|
||||
}
|
||||
|
||||
|
||||
void WORKSHEET_LAYOUT::Insert( WORKSHEET_DATAITEM* aItem, unsigned aIdx )
|
||||
void WORKSHEET_LAYOUT::Append( WORKSHEET_DATAITEM* aItem )
|
||||
{
|
||||
if ( aIdx >= GetCount() )
|
||||
Append( aItem );
|
||||
else
|
||||
m_list.insert( m_list.begin() + aIdx, aItem );
|
||||
m_list.push_back( aItem );
|
||||
}
|
||||
|
||||
|
||||
bool WORKSHEET_LAYOUT::Remove( unsigned aIdx )
|
||||
void WORKSHEET_LAYOUT::Remove( WORKSHEET_DATAITEM* aItem )
|
||||
{
|
||||
if ( aIdx >= GetCount() )
|
||||
return false;
|
||||
m_list.erase( m_list.begin() + aIdx );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool WORKSHEET_LAYOUT::Remove( WORKSHEET_DATAITEM* aItem )
|
||||
{
|
||||
unsigned idx = 0;
|
||||
|
||||
while( idx < m_list.size() )
|
||||
{
|
||||
if( m_list[idx] == aItem )
|
||||
break;
|
||||
|
||||
idx++;
|
||||
}
|
||||
|
||||
return Remove( idx );
|
||||
auto newEnd = std::remove( m_list.begin(), m_list.end(), aItem );
|
||||
m_list.erase( newEnd, m_list.end() );
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,14 +1,7 @@
|
||||
/**
|
||||
* @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-2016 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
@ -36,15 +29,47 @@
|
||||
#include <common.h>
|
||||
#include <base_screen.h>
|
||||
#include <draw_frame.h>
|
||||
#include <worksheet.h>
|
||||
#include <title_block.h>
|
||||
#include <build_version.h>
|
||||
#include <ws_draw_item.h>
|
||||
#include <gal/graphics_abstraction_layer.h>
|
||||
|
||||
#include <worksheet_shape_builder.h>
|
||||
#include <worksheet_painter.h>
|
||||
#include <worksheet_dataitem.h>
|
||||
|
||||
using namespace KIGFX;
|
||||
|
||||
static const wxString productName = wxT( "KiCad E.D.A. " );
|
||||
|
||||
WS_RENDER_SETTINGS::WS_RENDER_SETTINGS()
|
||||
{
|
||||
m_backgroundColor = COLOR4D( 1.0, 1.0, 1.0, 1.0 );
|
||||
m_normalColor = RED;
|
||||
m_selectedColor = m_normalColor.Brightened( 0.5 );
|
||||
m_brightenedColor = COLOR4D( 0.0, 1.0, 0.0, 0.9 );
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
const COLOR4D& WS_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer ) const
|
||||
{
|
||||
const EDA_ITEM* item = dynamic_cast<const EDA_ITEM*>( aItem );
|
||||
|
||||
if( item )
|
||||
{
|
||||
// Selection disambiguation
|
||||
if( item->IsBrightened() )
|
||||
return m_brightenedColor;
|
||||
|
||||
if( item->IsSelected() )
|
||||
return m_selectedColor;
|
||||
}
|
||||
|
||||
return m_normalColor;
|
||||
}
|
||||
|
||||
|
||||
// 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 )
|
||||
@ -209,3 +234,115 @@ void TITLE_BLOCK::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aCont
|
||||
aFormatter->Print( aNestLevel, ")\n\n" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool KIGFX::WORKSHEET_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer )
|
||||
{
|
||||
auto item = static_cast<const EDA_ITEM*>( aItem );
|
||||
|
||||
switch( item->Type() )
|
||||
{
|
||||
case WSG_LINE_T: draw( (WS_DRAW_ITEM_LINE*) item, aLayer ); break;
|
||||
case WSG_POLY_T: draw( (WS_DRAW_ITEM_POLYGON*) item, aLayer ); break;
|
||||
case WSG_RECT_T: draw( (WS_DRAW_ITEM_RECT*) item, aLayer ); break;
|
||||
case WSG_TEXT_T: draw( (WS_DRAW_ITEM_TEXT*) item, aLayer ); break;
|
||||
case WSG_BITMAP_T: draw( (WS_DRAW_ITEM_BITMAP*) item, aLayer ); break;
|
||||
default: return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void KIGFX::WORKSHEET_PAINTER::draw( const WS_DRAW_ITEM_LINE* aItem, int aLayer ) const
|
||||
{
|
||||
m_gal->SetIsStroke( true );
|
||||
m_gal->SetIsFill( false );
|
||||
m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
|
||||
m_gal->SetLineWidth( aItem->GetPenWidth() );
|
||||
m_gal->DrawLine( VECTOR2D( aItem->GetStart() ), VECTOR2D( aItem->GetEnd() ) );
|
||||
}
|
||||
|
||||
|
||||
void KIGFX::WORKSHEET_PAINTER::draw( const WS_DRAW_ITEM_RECT* aItem, int aLayer ) const
|
||||
{
|
||||
m_gal->SetIsStroke( true );
|
||||
m_gal->SetIsFill( false );
|
||||
m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
|
||||
m_gal->SetLineWidth( aItem->GetPenWidth() );
|
||||
m_gal->DrawRectangle( VECTOR2D( aItem->GetStart() ), VECTOR2D( aItem->GetEnd() ) );
|
||||
}
|
||||
|
||||
|
||||
void KIGFX::WORKSHEET_PAINTER::draw( const WS_DRAW_ITEM_POLYGON* aItem, int aLayer ) const
|
||||
{
|
||||
std::deque<VECTOR2D> corners;
|
||||
for( wxPoint point : aItem->m_Corners )
|
||||
{
|
||||
corners.push_back( VECTOR2D( point ) );
|
||||
}
|
||||
|
||||
if( aItem->IsFilled() )
|
||||
{
|
||||
m_gal->SetFillColor( m_renderSettings.GetColor( aItem, aLayer ) );
|
||||
m_gal->SetIsFill( true );
|
||||
m_gal->SetIsStroke( false );
|
||||
m_gal->DrawPolygon( corners );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
|
||||
m_gal->SetIsFill( false );
|
||||
m_gal->SetIsStroke( true );
|
||||
m_gal->SetLineWidth( aItem->GetPenWidth() );
|
||||
m_gal->DrawPolyline( corners );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void KIGFX::WORKSHEET_PAINTER::draw( const WS_DRAW_ITEM_TEXT* aItem, int aLayer ) const
|
||||
{
|
||||
VECTOR2D position( aItem->GetTextPos().x, aItem->GetTextPos().y );
|
||||
|
||||
m_gal->Save();
|
||||
m_gal->Translate( position );
|
||||
m_gal->Rotate( -aItem->GetTextAngle() * M_PI / 1800.0 );
|
||||
m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
|
||||
m_gal->SetLineWidth( aItem->GetThickness() );
|
||||
m_gal->SetTextAttributes( aItem );
|
||||
m_gal->StrokeText( aItem->GetShownText(), VECTOR2D( 0, 0 ), 0.0 );
|
||||
m_gal->Restore();
|
||||
}
|
||||
|
||||
|
||||
void KIGFX::WORKSHEET_PAINTER::draw( const WS_DRAW_ITEM_BITMAP* aItem, int aLayer ) const
|
||||
{
|
||||
m_gal->Save();
|
||||
VECTOR2D position = aItem->GetPosition();
|
||||
m_gal->Translate( position );
|
||||
auto* bitmap = static_cast<WORKSHEET_DATAITEM_BITMAP*>( aItem->GetPeer() );
|
||||
|
||||
// When the image scale factor is not 1.0, we need to modify the actual scale
|
||||
// as the image scale factor is similar to a local zoom
|
||||
double img_scale = bitmap->m_ImageBitmap->GetScale();
|
||||
|
||||
if( img_scale != 1.0 )
|
||||
m_gal->Scale( VECTOR2D( img_scale, img_scale ) );
|
||||
|
||||
m_gal->DrawBitmap( *bitmap->m_ImageBitmap );
|
||||
m_gal->Restore();
|
||||
}
|
||||
|
||||
|
||||
void KIGFX::WORKSHEET_PAINTER::DrawBorder( const PAGE_INFO* aPageInfo, int aScaleFactor ) const
|
||||
{
|
||||
VECTOR2D origin = VECTOR2D( 0.0, 0.0 );
|
||||
VECTOR2D end = VECTOR2D( aPageInfo->GetWidthMils() * aScaleFactor,
|
||||
aPageInfo->GetHeightMils() * aScaleFactor );
|
||||
|
||||
m_gal->SetIsStroke( true );
|
||||
// Use a gray color for the border color
|
||||
m_gal->SetStrokeColor( COLOR4D( 0.4, 0.4, 0.4, 1.0 ) );
|
||||
m_gal->SetIsFill( false );
|
||||
m_gal->DrawRectangle( origin, end );
|
||||
}
|
136
common/page_layout/worksheet_viewitem.cpp
Normal file
136
common/page_layout/worksheet_viewitem.cpp
Normal file
@ -0,0 +1,136 @@
|
||||
/*
|
||||
* This program source code file is part of KICAD, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2013-2018 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_viewitem.cpp
|
||||
* @brief Class that handles properties and drawing of worksheet layout.
|
||||
*/
|
||||
|
||||
#include <worksheet_viewitem.h>
|
||||
#include <ws_draw_item.h>
|
||||
#include <worksheet_dataitem.h>
|
||||
#include <gal/graphics_abstraction_layer.h>
|
||||
#include <painter.h>
|
||||
#include <layers_id_colors_and_visibility.h>
|
||||
#include <page_info.h>
|
||||
#include <view/view.h>
|
||||
#include <worksheet_painter.h>
|
||||
|
||||
using namespace KIGFX;
|
||||
|
||||
WORKSHEET_VIEWITEM::WORKSHEET_VIEWITEM( int aMils2IUscalefactor,
|
||||
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_mils2IUscalefactor( aMils2IUscalefactor ),
|
||||
m_titleBlock( aTitleBlock ), m_pageInfo( aPageInfo ), m_sheetNumber( 1 ), m_sheetCount( 1 ) {}
|
||||
|
||||
|
||||
void WORKSHEET_VIEWITEM::SetPageInfo( const PAGE_INFO* aPageInfo )
|
||||
{
|
||||
m_pageInfo = aPageInfo;
|
||||
}
|
||||
|
||||
|
||||
void WORKSHEET_VIEWITEM::SetTitleBlock( const TITLE_BLOCK* aTitleBlock )
|
||||
{
|
||||
m_titleBlock = aTitleBlock;
|
||||
}
|
||||
|
||||
|
||||
const BOX2I WORKSHEET_VIEWITEM::ViewBBox() const
|
||||
{
|
||||
BOX2I bbox;
|
||||
|
||||
if( m_pageInfo != NULL )
|
||||
{
|
||||
bbox.SetOrigin( VECTOR2I( 0, 0 ) );
|
||||
bbox.SetEnd( VECTOR2I( m_pageInfo->GetWidthMils() * m_mils2IUscalefactor,
|
||||
m_pageInfo->GetHeightMils() * m_mils2IUscalefactor ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
bbox.SetMaximum();
|
||||
}
|
||||
|
||||
return bbox;
|
||||
}
|
||||
|
||||
|
||||
void WORKSHEET_VIEWITEM::ViewDraw( int aLayer, VIEW* aView ) const
|
||||
{
|
||||
auto gal = aView->GetGAL();
|
||||
auto settings = aView->GetPainter()->GetSettings();
|
||||
wxString fileName( m_fileName.c_str(), wxConvUTF8 );
|
||||
wxString sheetName( m_sheetName.c_str(), wxConvUTF8 );
|
||||
WS_DRAW_ITEM_LIST drawList;
|
||||
|
||||
drawList.SetDefaultPenSize( (int) settings->GetWorksheetLineWidth() );
|
||||
// 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 );
|
||||
drawList.SetSheetNumber( m_sheetNumber );
|
||||
drawList.SetSheetCount( m_sheetCount );
|
||||
drawList.SetFileName( fileName );
|
||||
drawList.SetSheetName( sheetName );
|
||||
|
||||
drawList.BuildWorkSheetGraphicList( *m_pageInfo, *m_titleBlock );
|
||||
|
||||
// Draw the title block normally even if the view is flipped
|
||||
bool flipped = gal->IsFlippedX();
|
||||
|
||||
if( flipped )
|
||||
{
|
||||
gal->Save();
|
||||
gal->Translate( VECTOR2D( m_pageInfo->GetWidthMils() * m_mils2IUscalefactor, 0 ) );
|
||||
gal->Scale( VECTOR2D( -1.0, 1.0 ) );
|
||||
}
|
||||
|
||||
WORKSHEET_PAINTER ws_painter( gal );
|
||||
WS_RENDER_SETTINGS* ws_settings =static_cast<WS_RENDER_SETTINGS*>( ws_painter.GetSettings() );
|
||||
|
||||
ws_settings->SetNormalColor( settings->GetLayerColor( LAYER_WORKSHEET ) );
|
||||
ws_settings->SetSelectedColor( settings->GetLayerColor( LAYER_SELECT_OVERLAY ) );
|
||||
ws_settings->SetBrightenedColor( settings->GetLayerColor( LAYER_BRIGHTENED ) );
|
||||
|
||||
// Draw all the components that make the page layout
|
||||
for( WS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
|
||||
ws_painter.Draw( item, LAYER_WORKSHEET );
|
||||
|
||||
// Draw gray line that outlines the sheet size
|
||||
if( settings->GetShowPageLimits() )
|
||||
ws_painter.DrawBorder( m_pageInfo, m_mils2IUscalefactor );
|
||||
|
||||
if( flipped )
|
||||
gal->Restore();
|
||||
}
|
||||
|
||||
|
||||
void WORKSHEET_VIEWITEM::ViewGetLayers( int aLayers[], int& aCount ) const
|
||||
{
|
||||
aCount = 1;
|
||||
aLayers[0] = LAYER_WORKSHEET;
|
||||
}
|
||||
|
||||
|
420
common/page_layout/ws_draw_item.cpp
Normal file
420
common/page_layout/ws_draw_item.cpp
Normal file
@ -0,0 +1,420 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 1992-2013 Jean-Pierre Charras <jp.charras at wanadoo.fr>.
|
||||
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.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
|
||||
*/
|
||||
|
||||
/*
|
||||
* the class WORKSHEET_DATAITEM (and WORKSHEET_DATAITEM_TEXT) defines
|
||||
* a basic shape of a page layout ( frame references and title block )
|
||||
* Basic shapes are line, rect and texts
|
||||
* the WORKSHEET_DATAITEM coordinates units is the mm, and are relative to
|
||||
* one of 4 page corners.
|
||||
*
|
||||
* These items cannot be drawn or plot "as this". they should be converted
|
||||
* to a "draw list" (WS_DRAW_ITEM_BASE and derived items)
|
||||
|
||||
* The list of these items is stored in a WORKSHEET_LAYOUT instance.
|
||||
*
|
||||
* When building the draw list:
|
||||
* the WORKSHEET_LAYOUT is used to create a WS_DRAW_ITEM_LIST
|
||||
* coordinates are converted to draw/plot coordinates.
|
||||
* texts are expanded if they contain format symbols.
|
||||
* Items with m_RepeatCount > 1 are created m_RepeatCount times
|
||||
*
|
||||
* the WORKSHEET_LAYOUT is created only once.
|
||||
* the WS_DRAW_ITEM_LIST is created each time the page layout is plotted/drawn
|
||||
*
|
||||
* the WORKSHEET_LAYOUT instance is created from a S expression which
|
||||
* describes the page layout (can be the default page layout or a custom file).
|
||||
*/
|
||||
|
||||
#include <fctsys.h>
|
||||
#include <eda_rect.h>
|
||||
#include <draw_graphic_text.h>
|
||||
#include <ws_draw_item.h>
|
||||
#include <worksheet_dataitem.h>
|
||||
#include <base_units.h>
|
||||
#include <page_info.h>
|
||||
|
||||
// ============================ BASE CLASS ==============================
|
||||
|
||||
// A generic HitTest that can be used by some, but not all, sub-classes.
|
||||
bool WS_DRAW_ITEM_BASE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
|
||||
{
|
||||
EDA_RECT sel = aRect;
|
||||
|
||||
if ( aAccuracy )
|
||||
sel.Inflate( aAccuracy );
|
||||
|
||||
if( aContained )
|
||||
return sel.Contains( GetBoundingBox() );
|
||||
|
||||
return sel.Intersects( GetBoundingBox() );
|
||||
}
|
||||
|
||||
|
||||
void WS_DRAW_ITEM_BASE::GetMsgPanelInfo( EDA_UNITS_T aUnits, MSG_PANEL_ITEMS& aList )
|
||||
{
|
||||
wxString msg;
|
||||
WORKSHEET_DATAITEM* dataItem = GetPeer();
|
||||
|
||||
switch( dataItem->GetType() )
|
||||
{
|
||||
case WORKSHEET_DATAITEM::WS_SEGMENT:
|
||||
aList.push_back( MSG_PANEL_ITEM( _( "Line" ), msg, DARKCYAN ) );
|
||||
break;
|
||||
|
||||
case WORKSHEET_DATAITEM::WS_RECT:
|
||||
aList.push_back( MSG_PANEL_ITEM( _( "Rectangle" ), msg, DARKCYAN ) );
|
||||
break;
|
||||
|
||||
case WORKSHEET_DATAITEM::WS_TEXT:
|
||||
msg = static_cast<WS_DRAW_ITEM_TEXT*>( this )->GetShownText();
|
||||
aList.push_back( MSG_PANEL_ITEM( _( "Text" ), msg, DARKCYAN ) );
|
||||
break;
|
||||
|
||||
case WORKSHEET_DATAITEM::WS_POLYPOLYGON:
|
||||
aList.push_back( MSG_PANEL_ITEM( _( "Imported Shape" ), msg, DARKCYAN ) );
|
||||
break;
|
||||
|
||||
case WORKSHEET_DATAITEM::WS_BITMAP:
|
||||
aList.push_back( MSG_PANEL_ITEM( _( "Image" ), msg, DARKCYAN ) );
|
||||
break;
|
||||
}
|
||||
|
||||
switch( dataItem->GetPage1Option() )
|
||||
{
|
||||
case FIRST_PAGE_ONLY: msg = _( "First Page Only" ); break;
|
||||
case SUBSEQUENT_PAGES: msg = _( "Subsequent Pages" ); break;
|
||||
default: msg = _( "All Pages" ); break;
|
||||
}
|
||||
|
||||
aList.push_back( MSG_PANEL_ITEM( _( "First Page Option" ), msg, BROWN ) );
|
||||
|
||||
msg = MessageTextFromValue( UNSCALED_UNITS, dataItem->m_RepeatCount );
|
||||
aList.push_back( MSG_PANEL_ITEM( _( "Repeat Count" ), msg, BLUE ) );
|
||||
|
||||
msg = MessageTextFromValue( UNSCALED_UNITS, dataItem->m_IncrementLabel );
|
||||
aList.push_back( MSG_PANEL_ITEM( _( "Repeat Label Increment" ), msg, DARKGRAY ) );
|
||||
|
||||
msg.Printf( wxT( "(%s, %s)" ),
|
||||
MessageTextFromValue( aUnits, dataItem->m_IncrementVector.x ),
|
||||
MessageTextFromValue( aUnits, dataItem->m_IncrementVector.y ) );
|
||||
|
||||
aList.push_back( MSG_PANEL_ITEM( _( "Repeat Position Increment" ), msg, RED ) );
|
||||
|
||||
aList.push_back( MSG_PANEL_ITEM( _( "Comment" ), dataItem->m_Info, MAGENTA ) );
|
||||
}
|
||||
|
||||
|
||||
// ============================ TEXT ==============================
|
||||
|
||||
void WS_DRAW_ITEM_TEXT::DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset,
|
||||
GR_DRAWMODE aDrawMode, COLOR4D aColor )
|
||||
{
|
||||
Draw( aClipBox, aDC, aOffset, aColor, GR_COPY, FILLED, COLOR4D::UNSPECIFIED );
|
||||
}
|
||||
|
||||
|
||||
bool WS_DRAW_ITEM_TEXT::HitTest( const wxPoint& aPosition, int aAccuracy ) const
|
||||
{
|
||||
return EDA_TEXT::TextHitTest( aPosition, aAccuracy );
|
||||
}
|
||||
|
||||
|
||||
bool WS_DRAW_ITEM_TEXT::HitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy ) const
|
||||
{
|
||||
return EDA_TEXT::TextHitTest( aRect, aContains, aAccuracy );
|
||||
}
|
||||
|
||||
|
||||
wxString WS_DRAW_ITEM_TEXT::GetSelectMenuText( EDA_UNITS_T aUnits ) const
|
||||
{
|
||||
return wxString::Format( _( "Text %s at (%s, %s)" ),
|
||||
GetShownText(),
|
||||
MessageTextFromValue( aUnits, GetTextPos().x ),
|
||||
MessageTextFromValue( aUnits, GetTextPos().y ) );
|
||||
}
|
||||
|
||||
|
||||
// ============================ POLYGON ==============================
|
||||
|
||||
void WS_DRAW_ITEM_POLYGON::DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset,
|
||||
GR_DRAWMODE aDrawMode, COLOR4D aColor )
|
||||
{
|
||||
std::vector<wxPoint> points_moved;
|
||||
wxPoint *points;
|
||||
|
||||
if( aOffset.x || aOffset.y )
|
||||
{
|
||||
for( auto point: m_Corners )
|
||||
points_moved.push_back( point + aOffset );
|
||||
|
||||
points = &points_moved[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
points = &m_Corners[0];
|
||||
}
|
||||
|
||||
GRPoly( aClipBox, aDC, m_Corners.size(), points, IsFilled() ? FILLED_SHAPE : NO_FILL,
|
||||
GetPenWidth(), aColor, aColor );
|
||||
}
|
||||
|
||||
|
||||
bool WS_DRAW_ITEM_POLYGON::HitTest( const wxPoint& aPosition, int aAccuracy ) const
|
||||
{
|
||||
for( unsigned ii = 1; ii < m_Corners.size(); ii++ )
|
||||
{
|
||||
if( TestSegmentHit( aPosition, m_Corners[ii - 1], m_Corners[ii], aAccuracy ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WS_DRAW_ITEM_POLYGON::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
|
||||
{
|
||||
EDA_RECT sel = aRect;
|
||||
|
||||
if ( aAccuracy )
|
||||
sel.Inflate( aAccuracy );
|
||||
|
||||
if( aContained )
|
||||
return sel.Contains( GetBoundingBox() );
|
||||
|
||||
// Fast test: if rect is outside the polygon bounding box, then they cannot intersect
|
||||
if( !sel.Intersects( GetBoundingBox() ) )
|
||||
return false;
|
||||
|
||||
int count = m_Corners.size();
|
||||
|
||||
for( int ii = 0; ii < count; ii++ )
|
||||
{
|
||||
// Test if the point is within aRect
|
||||
if( sel.Contains( m_Corners[ ii ] ) )
|
||||
return true;
|
||||
|
||||
// Test if this edge intersects aRect
|
||||
if( sel.Intersects( m_Corners[ ii ], m_Corners[ (ii+1) % count ] ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
wxString WS_DRAW_ITEM_POLYGON::GetSelectMenuText( EDA_UNITS_T aUnits ) const
|
||||
{
|
||||
return wxString::Format( _( "Imported shape at (%s, %s)" ),
|
||||
MessageTextFromValue( aUnits, GetPosition().x ),
|
||||
MessageTextFromValue( aUnits, GetPosition().y ) );
|
||||
}
|
||||
|
||||
|
||||
// ============================ RECT ==============================
|
||||
|
||||
void WS_DRAW_ITEM_RECT::DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset,
|
||||
GR_DRAWMODE aDrawMode, COLOR4D aColor )
|
||||
{
|
||||
GRRect( aClipBox, aDC,
|
||||
GetStart().x + aOffset.x, GetStart().y + aOffset.y,
|
||||
GetEnd().x + aOffset.x, GetEnd().y + aOffset.y,
|
||||
GetPenWidth(), aColor );
|
||||
}
|
||||
|
||||
|
||||
bool WS_DRAW_ITEM_RECT::HitTest( const wxPoint& aPosition, int aAccuracy ) const
|
||||
{
|
||||
int dist = aAccuracy + ( GetPenWidth() / 2 );
|
||||
wxPoint start = GetStart();
|
||||
wxPoint end;
|
||||
end.x = GetEnd().x;
|
||||
end.y = start.y;
|
||||
|
||||
// Upper line
|
||||
if( TestSegmentHit( aPosition, start, end, dist ) )
|
||||
return true;
|
||||
|
||||
// Right line
|
||||
start = end;
|
||||
end.y = GetEnd().y;
|
||||
if( TestSegmentHit( aPosition, start, end, dist ) )
|
||||
return true;
|
||||
|
||||
// lower line
|
||||
start = end;
|
||||
end.x = GetStart().x;
|
||||
if( TestSegmentHit( aPosition, start, end, dist ) )
|
||||
return true;
|
||||
|
||||
// left line
|
||||
start = end;
|
||||
end = GetStart();
|
||||
if( TestSegmentHit( aPosition, start, end, dist ) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
wxString WS_DRAW_ITEM_RECT::GetSelectMenuText( EDA_UNITS_T aUnits ) const
|
||||
{
|
||||
return wxString::Format( _( "Rectangle from (%s, %s) to (%s, %s)" ),
|
||||
MessageTextFromValue( aUnits, GetStart().x ),
|
||||
MessageTextFromValue( aUnits, GetStart().y ),
|
||||
MessageTextFromValue( aUnits, GetEnd().x ),
|
||||
MessageTextFromValue( aUnits, GetEnd().y ) );
|
||||
}
|
||||
|
||||
|
||||
// ============================ LINE ==============================
|
||||
|
||||
void WS_DRAW_ITEM_LINE::DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset,
|
||||
GR_DRAWMODE aDrawMode, COLOR4D aColor )
|
||||
{
|
||||
GRLine( aClipBox, aDC, GetStart() + aOffset, GetEnd() + aOffset, GetPenWidth(), aColor );
|
||||
}
|
||||
|
||||
|
||||
bool WS_DRAW_ITEM_LINE::HitTest( const wxPoint& aPosition, int aAccuracy ) const
|
||||
{
|
||||
int mindist = aAccuracy + ( GetPenWidth() / 2 );
|
||||
return TestSegmentHit( aPosition, GetStart(), GetEnd(), mindist );
|
||||
}
|
||||
|
||||
|
||||
wxString WS_DRAW_ITEM_LINE::GetSelectMenuText( EDA_UNITS_T aUnits ) const
|
||||
{
|
||||
return wxString::Format( _( "Line from (%s, %s) to (%s, %s)" ),
|
||||
MessageTextFromValue( aUnits, GetStart().x ),
|
||||
MessageTextFromValue( aUnits, GetStart().y ),
|
||||
MessageTextFromValue( aUnits, GetEnd().x ),
|
||||
MessageTextFromValue( aUnits, GetEnd().y ) );
|
||||
}
|
||||
|
||||
|
||||
// ============== BITMAP ================
|
||||
|
||||
void WS_DRAW_ITEM_BITMAP::DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset,
|
||||
GR_DRAWMODE aDrawMode, COLOR4D aColor )
|
||||
{
|
||||
WORKSHEET_DATAITEM_BITMAP* bitmap = (WORKSHEET_DATAITEM_BITMAP*) GetPeer();
|
||||
|
||||
if( bitmap->m_ImageBitmap )
|
||||
{
|
||||
GRSetDrawMode( aDC, ( aDrawMode == UNSPECIFIED_DRAWMODE ) ? GR_COPY : aDrawMode );
|
||||
bitmap->m_ImageBitmap->DrawBitmap( aDC, m_pos + aOffset );
|
||||
GRSetDrawMode( aDC, GR_COPY );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const EDA_RECT WS_DRAW_ITEM_BITMAP::GetBoundingBox() const
|
||||
{
|
||||
auto* bitmap = static_cast<const WORKSHEET_DATAITEM_BITMAP*>( m_peer );
|
||||
EDA_RECT rect = bitmap->m_ImageBitmap->GetBoundingBox();
|
||||
|
||||
rect.Move( m_pos );
|
||||
return rect;
|
||||
}
|
||||
|
||||
|
||||
wxString WS_DRAW_ITEM_BITMAP::GetSelectMenuText( EDA_UNITS_T aUnits ) const
|
||||
{
|
||||
return wxString::Format( _( "Image at (%s, %s)" ),
|
||||
MessageTextFromValue( aUnits, GetPosition().x ),
|
||||
MessageTextFromValue( aUnits, GetPosition().y ) );
|
||||
}
|
||||
|
||||
|
||||
// ============================ LIST ==============================
|
||||
|
||||
#define MILS_TO_MM (25.4/1000)
|
||||
|
||||
|
||||
void WS_DRAW_ITEM_LIST::SetupDrawEnvironment( const PAGE_INFO& aPageInfo )
|
||||
{
|
||||
WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance();
|
||||
|
||||
// Left top corner position
|
||||
DPOINT lt_corner;
|
||||
lt_corner.x = pglayout.GetLeftMargin();
|
||||
lt_corner.y = pglayout.GetTopMargin();
|
||||
WORKSHEET_DATAITEM::m_LT_Corner = lt_corner;
|
||||
|
||||
// Right bottom corner position
|
||||
DPOINT rb_corner;
|
||||
rb_corner.x = ( aPageInfo.GetSizeMils().x * MILS_TO_MM ) - pglayout.GetRightMargin();
|
||||
rb_corner.y = ( aPageInfo.GetSizeMils().y * MILS_TO_MM ) - pglayout.GetBottomMargin();
|
||||
WORKSHEET_DATAITEM::m_RB_Corner = rb_corner;
|
||||
}
|
||||
|
||||
|
||||
void WS_DRAW_ITEM_LIST::BuildWorkSheetGraphicList( const PAGE_INFO& aPageInfo,
|
||||
const TITLE_BLOCK& aTitleBlock )
|
||||
{
|
||||
WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance();
|
||||
|
||||
m_titleBlock = &aTitleBlock;
|
||||
m_paperFormat = &aPageInfo.GetType();
|
||||
|
||||
wxPoint LTmargin( Mm2mils( pglayout.GetLeftMargin() ), Mm2mils( pglayout.GetTopMargin() ) );
|
||||
wxPoint RBmargin( Mm2mils( pglayout.GetRightMargin() ), Mm2mils( pglayout.GetBottomMargin() ) );
|
||||
|
||||
// Build the basic layout shape, if the layout list is empty
|
||||
if( pglayout.GetCount() == 0 && !pglayout.VoidListAllowed() )
|
||||
pglayout.SetPageLayout();
|
||||
|
||||
WORKSHEET_DATAITEM::m_WSunits2Iu = m_milsToIu / MILS_TO_MM;
|
||||
|
||||
SetupDrawEnvironment( aPageInfo );
|
||||
|
||||
for( WORKSHEET_DATAITEM* wsItem : pglayout.GetItems() )
|
||||
{
|
||||
// Generate it only if the page option allows this
|
||||
if( wsItem->GetPage1Option() == FIRST_PAGE_ONLY && m_sheetNumber != 1 )
|
||||
continue;
|
||||
else if( wsItem->GetPage1Option() == SUBSEQUENT_PAGES && m_sheetNumber == 1 )
|
||||
continue;
|
||||
|
||||
wsItem->SyncDrawItems( this, nullptr );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Draws the item list created by BuildWorkSheetGraphicList
|
||||
* aClipBox = the clipping rect, or NULL if no clipping
|
||||
* aDC = the current Device Context
|
||||
* The not selected items are drawn first (most of items)
|
||||
* The selected items are drawn after (usually 0 or 1)
|
||||
* to be sure they are seen, even for overlapping items
|
||||
*/
|
||||
void WS_DRAW_ITEM_LIST::Draw( EDA_RECT* aClipBox, wxDC* aDC, COLOR4D aColor )
|
||||
{
|
||||
for( WS_DRAW_ITEM_BASE* item = GetFirst(); item; item = GetNext() )
|
||||
item->DrawWsItem( aClipBox, aDC, aColor );
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,8 @@ void RENDER_SETTINGS::update()
|
||||
|
||||
|
||||
PAINTER::PAINTER( GAL* aGal ) :
|
||||
m_gal( aGal ), m_brightenedColor( 0.0, 1.0, 0.0, 0.9 )
|
||||
m_gal( aGal ),
|
||||
m_brightenedColor( 0.0, 1.0, 0.0, 0.9 )
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,3 @@
|
||||
/**
|
||||
* @file common_plot_functions.cpp
|
||||
* @brief Kicad: Common plotting functions
|
||||
*/
|
||||
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
@ -30,11 +25,11 @@
|
||||
#include <fctsys.h>
|
||||
#include <base_struct.h>
|
||||
#include <plotter.h>
|
||||
#include <worksheet.h>
|
||||
#include <worksheet_painter.h>
|
||||
#include <base_screen.h>
|
||||
#include <draw_graphic_text.h>
|
||||
#include <title_block.h>
|
||||
#include "worksheet_shape_builder.h"
|
||||
#include "ws_draw_item.h"
|
||||
#include "worksheet_dataitem.h"
|
||||
#include <wx/filename.h>
|
||||
|
||||
@ -44,35 +39,20 @@ wxString GetDefaultPlotExtension( PlotFormat aFormat )
|
||||
{
|
||||
switch( aFormat )
|
||||
{
|
||||
case PLOT_FORMAT_DXF:
|
||||
return DXF_PLOTTER::GetDefaultFileExtension();
|
||||
|
||||
case PLOT_FORMAT_POST:
|
||||
return PS_PLOTTER::GetDefaultFileExtension();
|
||||
|
||||
case PLOT_FORMAT_PDF:
|
||||
return PDF_PLOTTER::GetDefaultFileExtension();
|
||||
|
||||
case PLOT_FORMAT_HPGL:
|
||||
return HPGL_PLOTTER::GetDefaultFileExtension();
|
||||
|
||||
case PLOT_FORMAT_GERBER:
|
||||
return GERBER_PLOTTER::GetDefaultFileExtension();
|
||||
|
||||
case PLOT_FORMAT_SVG:
|
||||
return SVG_PLOTTER::GetDefaultFileExtension();
|
||||
|
||||
default:
|
||||
wxASSERT( false );
|
||||
return wxEmptyString;
|
||||
case PLOT_FORMAT_DXF: return DXF_PLOTTER::GetDefaultFileExtension();
|
||||
case PLOT_FORMAT_POST: return PS_PLOTTER::GetDefaultFileExtension();
|
||||
case PLOT_FORMAT_PDF: return PDF_PLOTTER::GetDefaultFileExtension();
|
||||
case PLOT_FORMAT_HPGL: return HPGL_PLOTTER::GetDefaultFileExtension();
|
||||
case PLOT_FORMAT_GERBER: return GERBER_PLOTTER::GetDefaultFileExtension();
|
||||
case PLOT_FORMAT_SVG: return SVG_PLOTTER::GetDefaultFileExtension();
|
||||
default: wxASSERT( false ); return wxEmptyString;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PlotWorkSheet( PLOTTER* plotter, const TITLE_BLOCK& aTitleBlock,
|
||||
const PAGE_INFO& aPageInfo,
|
||||
int aSheetNumber, int aNumberOfSheets,
|
||||
const PAGE_INFO& aPageInfo, int aSheetNumber, int aNumberOfSheets,
|
||||
const wxString &aSheetDesc, const wxString &aFilename )
|
||||
{
|
||||
/* Note: Page sizes values are given in mils
|
||||
@ -87,7 +67,7 @@ void PlotWorkSheet( PLOTTER* plotter, const TITLE_BLOCK& aTitleBlock,
|
||||
wxFileName fn( aFilename );
|
||||
|
||||
// Prepare plot parameters
|
||||
drawList.SetPenSize(PLOTTER::USE_DEFAULT_LINE_WIDTH );
|
||||
drawList.SetDefaultPenSize( PLOTTER::USE_DEFAULT_LINE_WIDTH );
|
||||
drawList.SetMilsToIUfactor( iusPerMil );
|
||||
drawList.SetSheetNumber( aSheetNumber );
|
||||
drawList.SetSheetCount( aNumberOfSheets );
|
||||
@ -95,18 +75,16 @@ void PlotWorkSheet( PLOTTER* plotter, const TITLE_BLOCK& aTitleBlock,
|
||||
drawList.SetSheetName( aSheetDesc );
|
||||
|
||||
|
||||
drawList.BuildWorkSheetGraphicList( aPageInfo,
|
||||
aTitleBlock, plotColor, plotColor );
|
||||
drawList.BuildWorkSheetGraphicList( aPageInfo, aTitleBlock );
|
||||
|
||||
// Draw item list
|
||||
for( WS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item;
|
||||
item = drawList.GetNext() )
|
||||
for( WS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
|
||||
{
|
||||
plotter->SetCurrentLineWidth( PLOTTER::USE_DEFAULT_LINE_WIDTH );
|
||||
|
||||
switch( item->GetType() )
|
||||
switch( item->Type() )
|
||||
{
|
||||
case WS_DRAW_ITEM_BASE::wsg_line:
|
||||
case WSG_LINE_T:
|
||||
{
|
||||
WS_DRAW_ITEM_LINE* line = (WS_DRAW_ITEM_LINE*) item;
|
||||
plotter->SetCurrentLineWidth( line->GetPenWidth() );
|
||||
@ -115,51 +93,48 @@ void PlotWorkSheet( PLOTTER* plotter, const TITLE_BLOCK& aTitleBlock,
|
||||
}
|
||||
break;
|
||||
|
||||
case WS_DRAW_ITEM_BASE::wsg_rect:
|
||||
case WSG_RECT_T:
|
||||
{
|
||||
WS_DRAW_ITEM_RECT* rect = (WS_DRAW_ITEM_RECT*) item;
|
||||
plotter->Rect( rect->GetStart(),
|
||||
rect->GetEnd(),
|
||||
NO_FILL,
|
||||
rect->GetPenWidth() );
|
||||
plotter->Rect( rect->GetStart(), rect->GetEnd(), NO_FILL, rect->GetPenWidth() );
|
||||
}
|
||||
break;
|
||||
|
||||
case WS_DRAW_ITEM_BASE::wsg_text:
|
||||
case WSG_TEXT_T:
|
||||
{
|
||||
WS_DRAW_ITEM_TEXT* text = (WS_DRAW_ITEM_TEXT*) item;
|
||||
plotter->Text( text->GetTextPos(), text->GetColor(),
|
||||
text->GetShownText(), text->GetTextAngle(),
|
||||
text->GetTextSize(),
|
||||
plotter->Text( text->GetTextPos(), plotColor, text->GetShownText(),
|
||||
text->GetTextAngle(), text->GetTextSize(),
|
||||
text->GetHorizJustify(), text->GetVertJustify(),
|
||||
text->GetPenWidth(),
|
||||
text->IsItalic(), text->IsBold(),
|
||||
text->GetPenWidth(), text->IsItalic(), text->IsBold(),
|
||||
text->IsMultilineAllowed() );
|
||||
}
|
||||
break;
|
||||
|
||||
case WS_DRAW_ITEM_BASE::wsg_poly:
|
||||
case WSG_POLY_T:
|
||||
{
|
||||
WS_DRAW_ITEM_POLYGON* poly = (WS_DRAW_ITEM_POLYGON*) item;
|
||||
plotter->PlotPoly( poly->m_Corners,
|
||||
poly->IsFilled() ? FILLED_SHAPE : NO_FILL,
|
||||
plotter->PlotPoly( poly->m_Corners, poly->IsFilled() ? FILLED_SHAPE : NO_FILL,
|
||||
poly->GetPenWidth() );
|
||||
}
|
||||
break;
|
||||
|
||||
case WS_DRAW_ITEM_BASE::wsg_bitmap:
|
||||
case WSG_BITMAP_T:
|
||||
{
|
||||
WS_DRAW_ITEM_BITMAP* bm = (WS_DRAW_ITEM_BITMAP*) item;
|
||||
WS_DRAW_ITEM_BITMAP* drawItem = (WS_DRAW_ITEM_BITMAP*) item;
|
||||
auto* bitmap = (WORKSHEET_DATAITEM_BITMAP*) drawItem->GetPeer();
|
||||
|
||||
WORKSHEET_DATAITEM_BITMAP* parent = (WORKSHEET_DATAITEM_BITMAP*)bm->GetParent();
|
||||
|
||||
if( parent->m_ImageBitmap == NULL )
|
||||
if( bitmap->m_ImageBitmap == NULL )
|
||||
break;
|
||||
|
||||
parent->m_ImageBitmap->PlotImage( plotter, bm->GetPosition(),
|
||||
plotColor, PLOTTER::USE_DEFAULT_LINE_WIDTH );
|
||||
bitmap->m_ImageBitmap->PlotImage( plotter, drawItem->GetPosition(), plotColor,
|
||||
PLOTTER::USE_DEFAULT_LINE_WIDTH );
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
wxFAIL_MSG( "PlotWorkSheet(): Unknown worksheet item." );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include "edit_constraints.h"
|
||||
#include "tool/edit_constraints.h"
|
||||
#include "tool/edit_points.h"
|
||||
|
||||
#include <geometry/seg.h>
|
||||
|
@ -1,247 +0,0 @@
|
||||
/*
|
||||
* This program source code file is part of KICAD, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2013-2018 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_viewitem.cpp
|
||||
* @brief Class that handles properties and drawing of worksheet layout.
|
||||
*/
|
||||
|
||||
#include <worksheet_viewitem.h>
|
||||
#include <worksheet_shape_builder.h>
|
||||
#include <worksheet_dataitem.h>
|
||||
#include <gal/graphics_abstraction_layer.h>
|
||||
#include <painter.h>
|
||||
#include <layers_id_colors_and_visibility.h>
|
||||
#include <page_info.h>
|
||||
#include <view/view.h>
|
||||
|
||||
using namespace KIGFX;
|
||||
|
||||
WORKSHEET_VIEWITEM::WORKSHEET_VIEWITEM( int aMils2IUscalefactor,
|
||||
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_mils2IUscalefactor( aMils2IUscalefactor ),
|
||||
m_titleBlock( aTitleBlock ), m_pageInfo( aPageInfo ), m_sheetNumber( 1 ), m_sheetCount( 1 ) {}
|
||||
|
||||
|
||||
void WORKSHEET_VIEWITEM::SetPageInfo( const PAGE_INFO* aPageInfo )
|
||||
{
|
||||
m_pageInfo = aPageInfo;
|
||||
}
|
||||
|
||||
|
||||
void WORKSHEET_VIEWITEM::SetTitleBlock( const TITLE_BLOCK* aTitleBlock )
|
||||
{
|
||||
m_titleBlock = aTitleBlock;
|
||||
}
|
||||
|
||||
|
||||
const BOX2I WORKSHEET_VIEWITEM::ViewBBox() const
|
||||
{
|
||||
BOX2I bbox;
|
||||
|
||||
if( m_pageInfo != NULL )
|
||||
{
|
||||
bbox.SetOrigin( VECTOR2I( 0, 0 ) );
|
||||
bbox.SetEnd( VECTOR2I( m_pageInfo->GetWidthMils() * m_mils2IUscalefactor,
|
||||
m_pageInfo->GetHeightMils() * m_mils2IUscalefactor ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
bbox.SetMaximum();
|
||||
}
|
||||
|
||||
return bbox;
|
||||
}
|
||||
|
||||
|
||||
void WORKSHEET_VIEWITEM::ViewDraw( int aLayer, VIEW* aView ) const
|
||||
{
|
||||
auto gal = aView->GetGAL();
|
||||
auto settings = aView->GetPainter()->GetSettings();
|
||||
wxString fileName( m_fileName.c_str(), wxConvUTF8 );
|
||||
wxString sheetName( m_sheetName.c_str(), wxConvUTF8 );
|
||||
WS_DRAW_ITEM_LIST drawList;
|
||||
|
||||
drawList.SetPenSize( settings->GetWorksheetLineWidth() );
|
||||
// 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 );
|
||||
drawList.SetSheetNumber( m_sheetNumber );
|
||||
drawList.SetSheetCount( m_sheetCount );
|
||||
drawList.SetFileName( fileName );
|
||||
drawList.SetSheetName( sheetName );
|
||||
|
||||
COLOR4D color = settings->GetColor( this, aLayer );
|
||||
drawList.BuildWorkSheetGraphicList( *m_pageInfo, *m_titleBlock, color, color );
|
||||
|
||||
// Draw the title block normally even if the view is flipped
|
||||
bool flipped = gal->IsFlippedX();
|
||||
|
||||
if( flipped )
|
||||
{
|
||||
gal->Save();
|
||||
gal->Translate( VECTOR2D( m_pageInfo->GetWidthMils() * m_mils2IUscalefactor, 0 ) );
|
||||
gal->Scale( VECTOR2D( -1.0, 1.0 ) );
|
||||
}
|
||||
|
||||
// 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 ), gal );
|
||||
break;
|
||||
|
||||
case WS_DRAW_ITEM_BASE::wsg_rect:
|
||||
draw( static_cast<const WS_DRAW_ITEM_RECT*>( item ), gal );
|
||||
break;
|
||||
|
||||
case WS_DRAW_ITEM_BASE::wsg_poly:
|
||||
draw( static_cast<const WS_DRAW_ITEM_POLYGON*>( item ), gal );
|
||||
break;
|
||||
|
||||
case WS_DRAW_ITEM_BASE::wsg_text:
|
||||
draw( static_cast<const WS_DRAW_ITEM_TEXT*>( item ), gal );
|
||||
break;
|
||||
|
||||
case WS_DRAW_ITEM_BASE::wsg_bitmap:
|
||||
draw( static_cast<const WS_DRAW_ITEM_BITMAP*>( item ), gal );
|
||||
break;
|
||||
}
|
||||
|
||||
item = drawList.GetNext();
|
||||
}
|
||||
|
||||
// Draw gray line that outlines the sheet size
|
||||
if( settings->GetShowPageLimits() )
|
||||
drawBorder( gal );
|
||||
|
||||
if( flipped )
|
||||
gal->Restore();
|
||||
}
|
||||
|
||||
|
||||
void WORKSHEET_VIEWITEM::ViewGetLayers( int aLayers[], int& aCount ) const
|
||||
{
|
||||
aCount = 1;
|
||||
aLayers[0] = LAYER_WORKSHEET;
|
||||
}
|
||||
|
||||
|
||||
void WORKSHEET_VIEWITEM::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_VIEWITEM::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_VIEWITEM::draw( const WS_DRAW_ITEM_POLYGON* aItem, GAL* aGal ) const
|
||||
{
|
||||
std::deque<VECTOR2D> corners;
|
||||
for( 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_VIEWITEM::draw( const WS_DRAW_ITEM_TEXT* aItem, GAL* aGal ) const
|
||||
{
|
||||
VECTOR2D position( aItem->GetTextPos().x, aItem->GetTextPos().y );
|
||||
|
||||
aGal->Save();
|
||||
aGal->Translate( position );
|
||||
aGal->Rotate( -aItem->GetTextAngle() * M_PI / 1800.0 );
|
||||
aGal->SetStrokeColor( COLOR4D( aItem->GetColor() ) );
|
||||
aGal->SetLineWidth( aItem->GetThickness() );
|
||||
aGal->SetTextAttributes( aItem );
|
||||
aGal->StrokeText( aItem->GetShownText(), VECTOR2D( 0, 0 ), 0.0 );
|
||||
aGal->Restore();
|
||||
}
|
||||
|
||||
|
||||
void WORKSHEET_VIEWITEM::draw( const WS_DRAW_ITEM_BITMAP* aItem, GAL* aGal ) const
|
||||
{
|
||||
aGal->Save();
|
||||
VECTOR2D position = aItem->GetPosition();
|
||||
aGal->Translate( position );
|
||||
WORKSHEET_DATAITEM_BITMAP* parent = static_cast<WORKSHEET_DATAITEM_BITMAP*>( aItem->GetParent() );
|
||||
|
||||
// When the image scale factor is not 1.0, we need to modify the actual scale
|
||||
// as the image scale factor is similar to a local zoom
|
||||
double img_scale = parent->m_ImageBitmap->GetScale();
|
||||
|
||||
if( img_scale != 1.0 )
|
||||
aGal->Scale( VECTOR2D( img_scale, img_scale ) );
|
||||
|
||||
aGal->DrawBitmap( *parent->m_ImageBitmap );
|
||||
aGal->Restore();
|
||||
}
|
||||
|
||||
|
||||
void WORKSHEET_VIEWITEM::drawBorder( GAL* aGal ) const
|
||||
{
|
||||
VECTOR2D origin = VECTOR2D( 0.0, 0.0 );
|
||||
VECTOR2D end = VECTOR2D( m_pageInfo->GetWidthMils() * m_mils2IUscalefactor,
|
||||
m_pageInfo->GetHeightMils() * m_mils2IUscalefactor );
|
||||
|
||||
aGal->SetIsStroke( true );
|
||||
// Use a gray color for the border color
|
||||
aGal->SetStrokeColor( COLOR4D( 0.4, 0.4, 0.4, 1.0 ) );
|
||||
aGal->SetIsFill( false );
|
||||
aGal->DrawRectangle( origin, end );
|
||||
}
|
@ -327,22 +327,6 @@ void DISPLAY_FOOTPRINTS_FRAME::ApplyDisplaySettingsToGAL()
|
||||
}
|
||||
|
||||
|
||||
void DISPLAY_FOOTPRINTS_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DISPLAY_FOOTPRINTS_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool DISPLAY_FOOTPRINTS_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool DISPLAY_FOOTPRINTS_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition,
|
||||
EDA_KEY aHotKey )
|
||||
{
|
||||
|
@ -108,9 +108,6 @@ public:
|
||||
*/
|
||||
COLOR4D GetGridColor() override;
|
||||
|
||||
void OnLeftClick( wxDC* DC, const wxPoint& MousePos ) override;
|
||||
void OnLeftDClick( wxDC* DC, const wxPoint& MousePos ) override;
|
||||
bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ) override;
|
||||
bool GeneralControl( wxDC* DC, const wxPoint& aPosition, EDA_KEY aHotKey = 0 ) override;
|
||||
void InstallOptionsDisplay( wxCommandEvent& event );
|
||||
MODULE* Get_Module( const wxString& CmpName );
|
||||
|
@ -31,7 +31,7 @@
|
||||
#include <pgm_base.h>
|
||||
#include <kiface_i.h>
|
||||
#include <bitmaps.h>
|
||||
#include <worksheet.h>
|
||||
#include <worksheet_painter.h>
|
||||
#include <sch_sheet.h>
|
||||
#include <dialog_plot_schematic.h>
|
||||
|
||||
|
@ -46,9 +46,7 @@ public:
|
||||
|
||||
EE_COLLECTOR( const KICAD_T* aScanTypes = EE_COLLECTOR::AllItems ) :
|
||||
m_Unit( 0 ),
|
||||
m_Convert( 0 ),
|
||||
m_Threshold( 0 ),
|
||||
m_MenuCancelled( false )
|
||||
m_Convert( 0 )
|
||||
{
|
||||
SetScanTypes( aScanTypes );
|
||||
}
|
||||
@ -108,11 +106,6 @@ public:
|
||||
public:
|
||||
int m_Unit; // Fixed symbol unit filter (for symbol editor)
|
||||
int m_Convert; // Fixed DeMorgan filter (for symbol editor)
|
||||
|
||||
int m_Threshold; // Hit-test threshold in internal units.
|
||||
|
||||
wxString m_MenuTitle; // The title of selection disambiguation menu (if needed)
|
||||
bool m_MenuCancelled; // Indicates selection disambiguation menu was cancelled
|
||||
};
|
||||
|
||||
|
||||
|
@ -400,7 +400,7 @@ bool SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
|
||||
if( aHotKey == 0 )
|
||||
return false;
|
||||
|
||||
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
|
||||
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
|
||||
|
||||
/* Convert lower to upper case (the usual toupper function has problem
|
||||
* with non ascii codes like function keys */
|
||||
|
@ -37,7 +37,7 @@
|
||||
#include <lib_edit_frame.h>
|
||||
#include <eeschema_config.h>
|
||||
#include <ee_hotkeys.h>
|
||||
#include <worksheet_shape_builder.h>
|
||||
#include <ws_draw_item.h>
|
||||
#include <class_library.h>
|
||||
#include <symbol_lib_table.h>
|
||||
#include <dialog_erc.h>
|
||||
|
@ -52,7 +52,7 @@
|
||||
#include <symbol_lib_table.h>
|
||||
#include <dialog_symbol_remap.h>
|
||||
#include <dialog_migrate_buses.h>
|
||||
#include <worksheet_shape_builder.h>
|
||||
#include <ws_draw_item.h>
|
||||
#include <connection_graph.h>
|
||||
|
||||
|
||||
|
@ -22,10 +22,6 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file lib_arc.cpp
|
||||
*/
|
||||
|
||||
#include <fctsys.h>
|
||||
#include <gr_basic.h>
|
||||
#include <macros.h>
|
||||
@ -434,73 +430,28 @@ BITMAP_DEF LIB_ARC::GetMenuImage() const
|
||||
}
|
||||
|
||||
|
||||
void LIB_ARC::BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aPosition )
|
||||
void LIB_ARC::BeginEdit( const wxPoint aPosition )
|
||||
{
|
||||
LIB_ITEM::BeginEdit( aEditMode, aPosition );
|
||||
|
||||
if( aEditMode == IS_NEW )
|
||||
{
|
||||
m_ArcStart = m_ArcEnd = aPosition;
|
||||
m_editState = m_lastEditState = 1;
|
||||
}
|
||||
else if( aEditMode == IS_MOVED )
|
||||
{
|
||||
m_initialPos = m_Pos;
|
||||
m_initialCursorPos = aPosition;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The arc center point has to be rotated with while adjusting the
|
||||
// start or end point, determine the side of this point and the distance
|
||||
// from the start / end point
|
||||
wxPoint middlePoint = wxPoint( (m_ArcStart.x + m_ArcEnd.x) / 2,
|
||||
(m_ArcStart.y + m_ArcEnd.y) / 2 );
|
||||
wxPoint centerVector = m_Pos - middlePoint;
|
||||
wxPoint startEndVector = twoPointVector( m_ArcStart, m_ArcEnd );
|
||||
m_editCenterDistance = EuclideanNorm( centerVector );
|
||||
|
||||
// Determine on which side is the center point
|
||||
m_editDirection = CrossProduct( startEndVector, centerVector ) ? 1 : -1;
|
||||
|
||||
// Drag either the start, end point or the outline
|
||||
if( HitTestPoints( m_ArcStart, aPosition, MINIMUM_SELECTION_DISTANCE ) )
|
||||
{
|
||||
m_editSelectPoint = ARC_STATUS_START;
|
||||
}
|
||||
else if( HitTestPoints( m_ArcEnd, aPosition, MINIMUM_SELECTION_DISTANCE ) )
|
||||
{
|
||||
m_editSelectPoint = ARC_STATUS_END;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_editSelectPoint = ARC_STATUS_OUTLINE;
|
||||
}
|
||||
|
||||
m_editState = 0;
|
||||
}
|
||||
m_ArcStart = m_ArcEnd = aPosition;
|
||||
m_editState = m_lastEditState = 1;
|
||||
}
|
||||
|
||||
|
||||
bool LIB_ARC::ContinueEdit( const wxPoint aPosition )
|
||||
{
|
||||
if( IsNew() )
|
||||
if( m_editState == 1 ) // Second position yields the arc segment length.
|
||||
{
|
||||
if( m_editState == 1 ) // Second position yields the arc segment length.
|
||||
{
|
||||
m_ArcEnd = aPosition;
|
||||
m_editState = 2;
|
||||
return true; // Need third position to calculate center point.
|
||||
}
|
||||
m_ArcEnd = aPosition;
|
||||
m_editState = 2;
|
||||
return true; // Need third position to calculate center point.
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void LIB_ARC::EndEdit( const wxPoint& aPosition )
|
||||
void LIB_ARC::EndEdit()
|
||||
{
|
||||
LIB_ITEM::EndEdit( aPosition );
|
||||
|
||||
m_lastEditState = 0;
|
||||
m_editState = 0;
|
||||
}
|
||||
@ -508,47 +459,39 @@ void LIB_ARC::EndEdit( const wxPoint& aPosition )
|
||||
|
||||
void LIB_ARC::CalcEdit( const wxPoint& aPosition )
|
||||
{
|
||||
if( IsNew() )
|
||||
if( m_editState == 1 )
|
||||
{
|
||||
if( m_editState == 1 )
|
||||
{
|
||||
m_ArcEnd = aPosition;
|
||||
}
|
||||
|
||||
if( m_editState != m_lastEditState )
|
||||
m_lastEditState = m_editState;
|
||||
|
||||
// Keep the arc center point up to date. Otherwise, there will be edit graphic
|
||||
// artifacts left behind from the initial draw.
|
||||
int dx, dy;
|
||||
int cX, cY;
|
||||
double angle;
|
||||
|
||||
cX = aPosition.x;
|
||||
cY = aPosition.y;
|
||||
|
||||
dx = m_ArcEnd.x - m_ArcStart.x;
|
||||
dy = m_ArcEnd.y - m_ArcStart.y;
|
||||
cX -= m_ArcStart.x;
|
||||
cY -= m_ArcStart.y;
|
||||
angle = ArcTangente( dy, dx );
|
||||
RotatePoint( &dx, &dy, angle ); /* The segment dx, dy is horizontal
|
||||
* -> Length = dx, dy = 0 */
|
||||
RotatePoint( &cX, &cY, angle );
|
||||
cX = dx / 2; /* cX, cY is on the median segment 0.0 a dx, 0 */
|
||||
|
||||
RotatePoint( &cX, &cY, -angle );
|
||||
cX += m_ArcStart.x;
|
||||
cY += m_ArcStart.y;
|
||||
m_Pos.x = cX;
|
||||
m_Pos.y = cY;
|
||||
CalcRadiusAngles();
|
||||
|
||||
}
|
||||
else if( IsMoving() )
|
||||
{
|
||||
MoveTo( m_initialPos + aPosition - m_initialCursorPos );
|
||||
m_ArcEnd = aPosition;
|
||||
}
|
||||
|
||||
if( m_editState != m_lastEditState )
|
||||
m_lastEditState = m_editState;
|
||||
|
||||
// Keep the arc center point up to date. Otherwise, there will be edit graphic
|
||||
// artifacts left behind from the initial draw.
|
||||
int dx, dy;
|
||||
int cX, cY;
|
||||
double angle;
|
||||
|
||||
cX = aPosition.x;
|
||||
cY = aPosition.y;
|
||||
|
||||
dx = m_ArcEnd.x - m_ArcStart.x;
|
||||
dy = m_ArcEnd.y - m_ArcStart.y;
|
||||
cX -= m_ArcStart.x;
|
||||
cY -= m_ArcStart.y;
|
||||
angle = ArcTangente( dy, dx );
|
||||
RotatePoint( &dx, &dy, angle ); /* The segment dx, dy is horizontal
|
||||
* -> Length = dx, dy = 0 */
|
||||
RotatePoint( &cX, &cY, angle );
|
||||
cX = dx / 2; /* cX, cY is on the median segment 0.0 a dx, 0 */
|
||||
|
||||
RotatePoint( &cX, &cY, -angle );
|
||||
cX += m_ArcStart.x;
|
||||
cY += m_ArcStart.y;
|
||||
m_Pos.x = cX;
|
||||
m_Pos.y = cY;
|
||||
CalcRadiusAngles();
|
||||
}
|
||||
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user