From 323bb0f8e14bee0a69cd417ba2a30dc2869a0ada Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 20 May 2019 11:23:32 +0100 Subject: [PATCH] Moving PageLayout editor to GAL canvas and modern toolset. --- common/CMakeLists.txt | 7 +- common/dialogs/dialog_page_settings.cpp | 6 +- common/legacy_gal/eda_draw_frame.cpp | 36 +- common/legacy_wx/eda_draw_frame.cpp | 79 +- .../page_layout_default_description.cpp | 2 +- .../page_layout/page_layout_graphic_items.cpp | 540 ---- common/page_layout/page_layout_reader.cpp | 143 +- common/page_layout/title_block_shapes.cpp | 258 -- common/page_layout/worksheet_dataitem.cpp | 259 +- common/page_layout/worksheet_layout.cpp | 40 +- .../worksheet_painter.cpp} | 157 +- common/page_layout/worksheet_viewitem.cpp | 136 + common/page_layout/ws_draw_item.cpp | 420 +++ common/painter.cpp | 3 +- common/plotters/common_plot_functions.cpp | 91 +- common/tool/edit_constraints.cpp | 2 +- common/worksheet_viewitem.cpp | 247 -- cvpcb/display_footprints_frame.cpp | 16 - cvpcb/display_footprints_frame.h | 3 - eeschema/dialogs/dialog_plot_schematic.cpp | 2 +- eeschema/ee_collectors.h | 9 +- eeschema/ee_hotkeys.cpp | 2 +- eeschema/eeschema_config.cpp | 2 +- eeschema/files-io.cpp | 2 +- eeschema/lib_arc.cpp | 135 +- eeschema/lib_arc.h | 15 +- eeschema/lib_bezier.cpp | 47 +- eeschema/lib_bezier.h | 16 +- eeschema/lib_circle.cpp | 35 +- eeschema/lib_circle.h | 13 +- eeschema/lib_draw_item.h | 35 +- eeschema/lib_field.cpp | 83 +- eeschema/lib_field.h | 15 +- eeschema/lib_polyline.cpp | 157 +- eeschema/lib_polyline.h | 10 +- eeschema/lib_rectangle.cpp | 50 +- eeschema/lib_rectangle.h | 16 +- eeschema/lib_text.cpp | 69 +- eeschema/lib_text.h | 17 +- eeschema/libedit/lib_edit_frame.cpp | 11 - eeschema/libedit/lib_edit_frame.h | 8 +- eeschema/libedit/libedit.cpp | 28 - eeschema/sch_base_frame.cpp | 68 - eeschema/sch_base_frame.h | 6 - eeschema/sch_draw_panel.cpp | 18 - eeschema/sch_draw_panel.h | 5 - eeschema/sch_eagle_plugin.cpp | 2 +- eeschema/sch_edit_frame.cpp | 70 +- eeschema/sch_edit_frame.h | 3 +- eeschema/sch_field.cpp | 2 - eeschema/sch_screen.cpp | 8 +- eeschema/tools/ee_point_editor.h | 8 +- eeschema/tools/lib_drawing_tools.cpp | 9 +- eeschema/tools/sch_edit_tool.cpp | 2 +- eeschema/viewlib_frame.cpp | 1 - eeschema/viewlib_frame.h | 4 +- eeschema/viewlibs.cpp | 17 - gerbview/block.cpp | 3 - gerbview/gbr_screen.cpp | 6 +- gerbview/gerbview_frame.h | 1 - include/collector.h | 33 +- include/core/typeinfo.h | 11 +- include/draw_frame.h | 5 +- include/legacy_gal/class_drawpanel.h | 134 - include/painter.h | 4 +- include/pcb_base_frame.h | 3 - {common => include}/tool/edit_constraints.h | 0 {common => include}/tool/edit_points.h | 0 include/tool/selection.h | 1 - include/worksheet.h | 72 - include/worksheet_dataitem.h | 177 +- include/worksheet_painter.h | 167 ++ include/worksheet_viewitem.h | 10 - ...rksheet_shape_builder.h => ws_draw_item.h} | 427 ++- pagelayout_editor/CMakeLists.txt | 12 +- pagelayout_editor/block.cpp | 253 -- pagelayout_editor/design_tree_frame.cpp | 291 -- pagelayout_editor/design_tree_frame.h | 108 - .../dialogs/dialog_new_dataitem.cpp | 78 +- .../dialogs/dialogs_for_printing.cpp | 2 +- .../dialogs/properties_frame_base.cpp | 309 +- .../dialogs/properties_frame_base.fbp | 2567 +++++------------ .../dialogs/properties_frame_base.h | 21 +- pagelayout_editor/events_functions.cpp | 267 +- pagelayout_editor/files.cpp | 5 +- pagelayout_editor/hotkeys.cpp | 114 +- pagelayout_editor/hotkeys.h | 5 +- pagelayout_editor/invoke_pl_editor_dialog.h | 4 - pagelayout_editor/menubar.cpp | 106 +- pagelayout_editor/onleftclick.cpp | 77 - pagelayout_editor/onrightclick.cpp | 140 - pagelayout_editor/page_layout_writer.cpp | 29 +- pagelayout_editor/pl_draw_panel_gal.cpp | 120 + pagelayout_editor/pl_draw_panel_gal.h | 56 + pagelayout_editor/pl_editor.cpp | 70 +- pagelayout_editor/pl_editor_config.cpp | 18 - pagelayout_editor/pl_editor_frame.cpp | 329 +-- pagelayout_editor/pl_editor_frame.h | 134 +- pagelayout_editor/pl_editor_id.h | 13 +- pagelayout_editor/pl_editor_layout.h | 12 +- pagelayout_editor/pl_editor_screen.cpp | 23 +- pagelayout_editor/pl_editor_screen.h | 3 +- pagelayout_editor/pl_editor_undo_redo.cpp | 16 +- pagelayout_editor/properties_frame.cpp | 140 +- pagelayout_editor/toolbars_pl_editor.cpp | 86 +- pagelayout_editor/tools/pl_actions.cpp | 52 + pagelayout_editor/tools/pl_actions.h | 88 + pagelayout_editor/tools/pl_drawing_tools.cpp | 374 +++ pagelayout_editor/tools/pl_drawing_tools.h | 70 + pagelayout_editor/tools/pl_edit_tool.cpp | 397 +++ pagelayout_editor/tools/pl_edit_tool.h | 91 + pagelayout_editor/tools/pl_picker_tool.cpp | 186 ++ pagelayout_editor/tools/pl_picker_tool.h | 132 + pagelayout_editor/tools/pl_point_editor.cpp | 428 +++ pagelayout_editor/tools/pl_point_editor.h | 99 + pagelayout_editor/tools/pl_selection_tool.cpp | 757 +++++ pagelayout_editor/tools/pl_selection_tool.h | 216 ++ pagelayout_editor/tools/selection.cpp | 106 + pcbnew/CMakeLists.txt | 2 +- pcbnew/block_footprint_editor.cpp | 4 - pcbnew/footprint_edit_frame.cpp | 7 +- pcbnew/footprint_edit_frame.h | 6 - pcbnew/footprint_editor_onclick.cpp | 5 - pcbnew/footprint_viewer_frame.cpp | 11 - pcbnew/footprint_viewer_frame.h | 4 - pcbnew/footprint_wizard_frame.h | 4 - pcbnew/footprint_wizard_frame_functions.cpp | 19 - pcbnew/pcb_draw_panel_gal.cpp | 4 +- pcbnew/pcb_edit_frame.cpp | 7 +- pcbnew/pcb_edit_frame.h | 1 - pcbnew/pcb_screen.cpp | 18 +- pcbnew/pcbnew_config.cpp | 4 +- pcbnew/swig/pcbnew_scripting_helpers.cpp | 9 - pcbnew/swig/pcbnew_scripting_helpers.h | 2 - pcbnew/tools/edit_tool.cpp | 4 +- pcbnew/tools/pcb_editor_control.cpp | 10 +- pcbnew/tools/pcbnew_control.cpp | 6 +- ...picker_tool.cpp => pcbnew_picker_tool.cpp} | 20 +- .../{picker_tool.h => pcbnew_picker_tool.h} | 6 +- pcbnew/tools/position_relative_tool.cpp | 4 +- pcbnew/tools/selection.cpp | 6 - 141 files changed, 6099 insertions(+), 6967 deletions(-) delete mode 100644 common/page_layout/page_layout_graphic_items.cpp delete mode 100644 common/page_layout/title_block_shapes.cpp rename common/{worksheet.cpp => page_layout/worksheet_painter.cpp} (54%) create mode 100644 common/page_layout/worksheet_viewitem.cpp create mode 100644 common/page_layout/ws_draw_item.cpp delete mode 100644 common/worksheet_viewitem.cpp rename {common => include}/tool/edit_constraints.h (100%) rename {common => include}/tool/edit_points.h (100%) delete mode 100644 include/worksheet.h create mode 100644 include/worksheet_painter.h rename include/{worksheet_shape_builder.h => ws_draw_item.h} (58%) delete mode 100644 pagelayout_editor/block.cpp delete mode 100644 pagelayout_editor/design_tree_frame.cpp delete mode 100644 pagelayout_editor/design_tree_frame.h delete mode 100644 pagelayout_editor/onleftclick.cpp delete mode 100644 pagelayout_editor/onrightclick.cpp create mode 100644 pagelayout_editor/pl_draw_panel_gal.cpp create mode 100644 pagelayout_editor/pl_draw_panel_gal.h create mode 100644 pagelayout_editor/tools/pl_actions.cpp create mode 100644 pagelayout_editor/tools/pl_actions.h create mode 100644 pagelayout_editor/tools/pl_drawing_tools.cpp create mode 100644 pagelayout_editor/tools/pl_drawing_tools.h create mode 100644 pagelayout_editor/tools/pl_edit_tool.cpp create mode 100644 pagelayout_editor/tools/pl_edit_tool.h create mode 100644 pagelayout_editor/tools/pl_picker_tool.cpp create mode 100644 pagelayout_editor/tools/pl_picker_tool.h create mode 100644 pagelayout_editor/tools/pl_point_editor.cpp create mode 100644 pagelayout_editor/tools/pl_point_editor.h create mode 100644 pagelayout_editor/tools/pl_selection_tool.cpp create mode 100644 pagelayout_editor/tools/pl_selection_tool.h create mode 100644 pagelayout_editor/tools/selection.cpp rename pcbnew/tools/{picker_tool.cpp => pcbnew_picker_tool.cpp} (87%) rename pcbnew/tools/{picker_tool.h => pcbnew_picker_tool.h} (97%) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 74b5f67526..87832b9a84 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -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 ) diff --git a/common/dialogs/dialog_page_settings.cpp b/common/dialogs/dialog_page_settings.cpp index 60f53321cd..613c339e4b 100644 --- a/common/dialogs/dialog_page_settings.cpp +++ b/common/dialogs/dialog_page_settings.cpp @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include @@ -47,7 +47,7 @@ #include #endif -#include +#include #include #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 ); diff --git a/common/legacy_gal/eda_draw_frame.cpp b/common/legacy_gal/eda_draw_frame.cpp index f7408d35b7..a08aaaf5cf 100644 --- a/common/legacy_gal/eda_draw_frame.cpp +++ b/common/legacy_gal/eda_draw_frame.cpp @@ -45,7 +45,7 @@ #include #include #include -#include +#include #include #include #include @@ -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 ) { diff --git a/common/legacy_wx/eda_draw_frame.cpp b/common/legacy_wx/eda_draw_frame.cpp index 35088a3749..1d37ab38ba 100644 --- a/common/legacy_wx/eda_draw_frame.cpp +++ b/common/legacy_wx/eda_draw_frame.cpp @@ -67,7 +67,7 @@ #include #include #include -#include +#include /** * 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 ) { diff --git a/common/page_layout/page_layout_default_description.cpp b/common/page_layout/page_layout_default_description.cpp index 1f70406bc5..02cf79b654 100644 --- a/common/page_layout/page_layout_default_description.cpp +++ b/common/page_layout/page_layout_default_description.cpp @@ -115,7 +115,7 @@ * */ -#include +#include // height of the band reference grid 2.0 mm // worksheet frame reference text size 1.3 mm diff --git a/common/page_layout/page_layout_graphic_items.cpp b/common/page_layout/page_layout_graphic_items.cpp deleted file mode 100644 index 4adf03b5d1..0000000000 --- a/common/page_layout/page_layout_graphic_items.cpp +++ /dev/null @@ -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 . - * 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 -#include -#include -#include -#include -#include -#include -#include - -/* 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 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 & 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( 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( 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; -} - diff --git a/common/page_layout/page_layout_reader.cpp b/common/page_layout/page_layout_reader.cpp index 98466e048e..09573b2280 100644 --- a/common/page_layout/page_layout_reader.cpp +++ b/common/page_layout/page_layout_reader.cpp @@ -31,8 +31,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -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; } } } diff --git a/common/page_layout/title_block_shapes.cpp b/common/page_layout/title_block_shapes.cpp deleted file mode 100644 index 72f75d28f1..0000000000 --- a/common/page_layout/title_block_shapes.cpp +++ /dev/null @@ -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 . - * 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 -#include -#include -#include -#include -#include -#include - - -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; - - } - } -} - diff --git a/common/page_layout/worksheet_dataitem.cpp b/common/page_layout/worksheet_dataitem.cpp index 22473ba713..eba4fed699 100644 --- a/common/page_layout/worksheet_dataitem.cpp +++ b/common/page_layout/worksheet_dataitem.cpp @@ -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 #include #include -#include +#include #include -#include +#include #include +#include 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 diff --git a/common/page_layout/worksheet_layout.cpp b/common/page_layout/worksheet_layout.cpp index 1416bc57fb..c2609a7a88 100644 --- a/common/page_layout/worksheet_layout.cpp +++ b/common/page_layout/worksheet_layout.cpp @@ -52,9 +52,9 @@ #include #include #include -#include +#include #include -#include +#include #include @@ -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() ); } diff --git a/common/worksheet.cpp b/common/page_layout/worksheet_painter.cpp similarity index 54% rename from common/worksheet.cpp rename to common/page_layout/worksheet_painter.cpp index 3ee478e393..bb86c39a82 100644 --- a/common/worksheet.cpp +++ b/common/page_layout/worksheet_painter.cpp @@ -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 #include #include -#include #include #include +#include +#include -#include +#include +#include +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( 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( 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 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( 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 ); +} diff --git a/common/page_layout/worksheet_viewitem.cpp b/common/page_layout/worksheet_viewitem.cpp new file mode 100644 index 0000000000..3e328810c0 --- /dev/null +++ b/common/page_layout/worksheet_viewitem.cpp @@ -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 + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +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_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; +} + + diff --git a/common/page_layout/ws_draw_item.cpp b/common/page_layout/ws_draw_item.cpp new file mode 100644 index 0000000000..066ef0c563 --- /dev/null +++ b/common/page_layout/ws_draw_item.cpp @@ -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 . + * 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 +#include +#include +#include +#include +#include +#include + +// ============================ 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( 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 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( 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 ); +} + + diff --git a/common/painter.cpp b/common/painter.cpp index a404cff6a3..caa7a3e47a 100644 --- a/common/painter.cpp +++ b/common/painter.cpp @@ -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 ) { } diff --git a/common/plotters/common_plot_functions.cpp b/common/plotters/common_plot_functions.cpp index db049a855a..127c16a767 100644 --- a/common/plotters/common_plot_functions.cpp +++ b/common/plotters/common_plot_functions.cpp @@ -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 #include #include -#include +#include #include #include #include -#include "worksheet_shape_builder.h" +#include "ws_draw_item.h" #include "worksheet_dataitem.h" #include @@ -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; } } } diff --git a/common/tool/edit_constraints.cpp b/common/tool/edit_constraints.cpp index 78a7a7c97f..e46ad49032 100644 --- a/common/tool/edit_constraints.cpp +++ b/common/tool/edit_constraints.cpp @@ -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 diff --git a/common/worksheet_viewitem.cpp b/common/worksheet_viewitem.cpp deleted file mode 100644 index 97a1fd6e55..0000000000 --- a/common/worksheet_viewitem.cpp +++ /dev/null @@ -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 - * - * 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 -#include -#include -#include -#include -#include -#include -#include - -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( item ), gal ); - break; - - case WS_DRAW_ITEM_BASE::wsg_rect: - draw( static_cast( item ), gal ); - break; - - case WS_DRAW_ITEM_BASE::wsg_poly: - draw( static_cast( item ), gal ); - break; - - case WS_DRAW_ITEM_BASE::wsg_text: - draw( static_cast( item ), gal ); - break; - - case WS_DRAW_ITEM_BASE::wsg_bitmap: - draw( static_cast( 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 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( 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 ); -} diff --git a/cvpcb/display_footprints_frame.cpp b/cvpcb/display_footprints_frame.cpp index 843cb3b14e..d7dc6d5a71 100644 --- a/cvpcb/display_footprints_frame.cpp +++ b/cvpcb/display_footprints_frame.cpp @@ -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 ) { diff --git a/cvpcb/display_footprints_frame.h b/cvpcb/display_footprints_frame.h index 037520afb4..7a8d41b3ca 100644 --- a/cvpcb/display_footprints_frame.h +++ b/cvpcb/display_footprints_frame.h @@ -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 ); diff --git a/eeschema/dialogs/dialog_plot_schematic.cpp b/eeschema/dialogs/dialog_plot_schematic.cpp index add96ff631..0469c780f2 100644 --- a/eeschema/dialogs/dialog_plot_schematic.cpp +++ b/eeschema/dialogs/dialog_plot_schematic.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include diff --git a/eeschema/ee_collectors.h b/eeschema/ee_collectors.h index 25b41568aa..8b6f4e1434 100644 --- a/eeschema/ee_collectors.h +++ b/eeschema/ee_collectors.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 }; diff --git a/eeschema/ee_hotkeys.cpp b/eeschema/ee_hotkeys.cpp index 22fb4d1131..b64fd418c0 100644 --- a/eeschema/ee_hotkeys.cpp +++ b/eeschema/ee_hotkeys.cpp @@ -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 */ diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index e6c657b884..16947fe35b 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 582a4aa514..08220ddd91 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -52,7 +52,7 @@ #include #include #include -#include +#include #include diff --git a/eeschema/lib_arc.cpp b/eeschema/lib_arc.cpp index d54d4fd05a..014d35de9a 100644 --- a/eeschema/lib_arc.cpp +++ b/eeschema/lib_arc.cpp @@ -22,10 +22,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file lib_arc.cpp - */ - #include #include #include @@ -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(); } diff --git a/eeschema/lib_arc.h b/eeschema/lib_arc.h index 28ab0d5ca8..adbb3b6eb8 100644 --- a/eeschema/lib_arc.h +++ b/eeschema/lib_arc.h @@ -22,12 +22,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file lib_arc.h - */ - -#ifndef _LIB_ARC_H_ -#define _LIB_ARC_H_ +#ifndef LIB_ARC_H +#define LIB_ARC_H #include @@ -89,10 +85,10 @@ public: int GetPenSize() const override; - void BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aStartPoint ) override; + void BeginEdit( const wxPoint aStartPoint ) override; void CalcEdit( const wxPoint& aPosition ) override; bool ContinueEdit( const wxPoint aNextPoint ) override; - void EndEdit( const wxPoint& aPosition ) override; + void EndEdit() override; void Offset( const wxPoint& aOffset ) override; @@ -104,7 +100,6 @@ public: void MirrorHorizontal( const wxPoint& aCenter ) override; void MirrorVertical( const wxPoint& aCenter ) override; - void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override; void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill, @@ -155,4 +150,4 @@ private: }; -#endif // _LIB_ARC_H_ +#endif // LIB_ARC_H diff --git a/eeschema/lib_bezier.cpp b/eeschema/lib_bezier.cpp index 61453b2a10..a67d71ec06 100644 --- a/eeschema/lib_bezier.cpp +++ b/eeschema/lib_bezier.cpp @@ -21,10 +21,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file lib_bezier.cpp - */ - #include #include #include @@ -104,9 +100,7 @@ bool LIB_BEZIER::Inside( EDA_RECT& aRect ) const void LIB_BEZIER::MoveTo( const wxPoint& aPosition ) { if ( !m_PolyPoints.size() ) - { m_PolyPoints.push_back( wxPoint(0, 0) ); - } Offset( aPosition - m_PolyPoints[ 0 ] ); } @@ -114,9 +108,7 @@ void LIB_BEZIER::MoveTo( const wxPoint& aPosition ) const wxPoint LIB_BEZIER::GetOffset() const { if ( !m_PolyPoints.size() ) - { return wxPoint(0, 0); - } return m_PolyPoints[0]; } @@ -167,19 +159,11 @@ void LIB_BEZIER::Rotate( const wxPoint& aCenter, bool aRotateCCW ) { int rot_angle = aRotateCCW ? -900 : 900; - size_t i, imax = m_PolyPoints.size(); + for( wxPoint& point : m_PolyPoints ) + RotatePoint( &point, aCenter, rot_angle ); - for( i = 0; i < imax; i++ ) - { - RotatePoint( &m_PolyPoints[i], aCenter, rot_angle ); - } - - imax = m_BezierPoints.size(); - - for( i = 0; i < imax; i++ ) - { - RotatePoint( &m_BezierPoints[i], aCenter, rot_angle ); - } + for( wxPoint& bezierPoint : m_BezierPoints ) + RotatePoint( &bezierPoint, aCenter, rot_angle ); } @@ -191,9 +175,8 @@ void LIB_BEZIER::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill, static std::vector< wxPoint > cornerList; cornerList.clear(); - for( unsigned ii = 0; ii < m_PolyPoints.size(); ii++ ) + for( wxPoint pos : m_PolyPoints ) { - wxPoint pos = m_PolyPoints[ii]; pos = aTransform.TransformCoordinate( pos ) + aOffset; cornerList.push_back( pos ); } @@ -211,7 +194,7 @@ void LIB_BEZIER::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill, { pen_size = std::max( 0, pen_size ); aPlotter->SetColor( GetLayerColor( LAYER_DEVICE ) ); - aPlotter->PlotPoly( cornerList, already_filled ? NO_FILL : m_Fill, GetPenSize() ); + aPlotter->PlotPoly( cornerList, already_filled ? NO_FILL : m_Fill, pen_size ); } } @@ -240,9 +223,8 @@ void LIB_BEZIER::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& PolyPointsTraslated.clear(); - for( unsigned int i = 0; i < m_PolyPoints.size() ; i++ ) - PolyPointsTraslated.push_back( aTransform.TransformCoordinate( m_PolyPoints[i] ) + - aOffset ); + for( wxPoint& point : m_PolyPoints ) + PolyPointsTraslated.push_back( aTransform.TransformCoordinate( point ) + aOffset ); FILL_T fill = aData ? NO_FILL : m_Fill; @@ -250,17 +232,17 @@ void LIB_BEZIER::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& if( fill == FILLED_WITH_BG_BODYCOLOR ) { - GRPoly( clipbox, aDC, m_PolyPoints.size(), &PolyPointsTraslated[0], 1, GetPenSize(), + GRPoly( clipbox, aDC, m_PolyPoints.size(), &PolyPointsTraslated[0], true, GetPenSize(), bgColor, bgColor ); } else if( fill == FILLED_SHAPE ) { - GRPoly( clipbox, aDC, m_PolyPoints.size(), &PolyPointsTraslated[0], 1, GetPenSize(), + GRPoly( clipbox, aDC, m_PolyPoints.size(), &PolyPointsTraslated[0], true, GetPenSize(), color, color ); } else { - GRPoly( clipbox, aDC, m_PolyPoints.size(), &PolyPointsTraslated[0], 0, GetPenSize(), + GRPoly( clipbox, aDC, m_PolyPoints.size(), &PolyPointsTraslated[0], false, GetPenSize(), color, color ); } } @@ -363,8 +345,11 @@ void LIB_BEZIER::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITE aList.push_back( MSG_PANEL_ITEM( _( "Line Width" ), msg, BLUE ) ); - msg.Printf( wxT( "(%d, %d, %d, %d)" ), bBox.GetOrigin().x, - bBox.GetOrigin().y, bBox.GetEnd().x, bBox.GetEnd().y ); + msg.Printf( wxT( "(%d, %d, %d, %d)" ), + bBox.GetOrigin().x, + bBox.GetOrigin().y, + bBox.GetEnd().x, + bBox.GetEnd().y ); aList.push_back( MSG_PANEL_ITEM( _( "Bounding Box" ), msg, BROWN ) ); } diff --git a/eeschema/lib_bezier.h b/eeschema/lib_bezier.h index 0a8350d59d..5271a768f4 100644 --- a/eeschema/lib_bezier.h +++ b/eeschema/lib_bezier.h @@ -22,12 +22,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file lib_bezier.h - */ - -#ifndef _LIB_BEZIER_H_ -#define _LIB_BEZIER_H_ +#ifndef LIB_BEZIER_H +#define LIB_BEZIER_H #include @@ -73,10 +69,7 @@ public: */ unsigned GetCornerCount() const { return m_PolyPoints.size(); } - const std::vector< wxPoint >& GetPoints() const - { - return m_BezierPoints; - } + const std::vector< wxPoint >& GetPoints() const { return m_BezierPoints; } bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override; bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override; @@ -91,7 +84,6 @@ public: void MirrorHorizontal( const wxPoint& aCenter ) override; void MirrorVertical( const wxPoint& aCenter ) override; - void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override; void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill, @@ -119,4 +111,4 @@ private: }; -#endif // _LIB_BEZIER_H_ +#endif // LIB_BEZIER_H diff --git a/eeschema/lib_circle.cpp b/eeschema/lib_circle.cpp index 2b0bce2dfa..8a5bb4ecf7 100644 --- a/eeschema/lib_circle.cpp +++ b/eeschema/lib_circle.cpp @@ -22,11 +22,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file lib_circle.cpp - * @brief LIB_CIRCLE class implementation. - */ - #include #include #include @@ -249,8 +244,11 @@ void LIB_CIRCLE::GetMsgPanelInfo( EDA_UNITS_T aUnits, MSG_PANEL_ITEMS& aList ) msg = MessageTextFromValue( aUnits, GetRadius(), true ); aList.push_back( MSG_PANEL_ITEM( _( "Radius" ), msg, RED ) ); - msg.Printf( wxT( "(%d, %d, %d, %d)" ), bBox.GetOrigin().x, - bBox.GetOrigin().y, bBox.GetEnd().x, bBox.GetEnd().y ); + msg.Printf( wxT( "(%d, %d, %d, %d)" ), + bBox.GetOrigin().x, + bBox.GetOrigin().y, + bBox.GetEnd().x, + bBox.GetEnd().y ); aList.push_back( MSG_PANEL_ITEM( _( "Bounding Box" ), msg, BROWN ) ); } @@ -271,30 +269,13 @@ BITMAP_DEF LIB_CIRCLE::GetMenuImage() const } -void LIB_CIRCLE::BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aPosition ) +void LIB_CIRCLE::BeginEdit( const wxPoint aPosition ) { - LIB_ITEM::BeginEdit( aEditMode, aPosition ); - - if( aEditMode == IS_NEW ) - { - m_Pos = m_initialPos = aPosition; - } - else if( aEditMode == IS_MOVED ) - { - m_initialPos = m_Pos; - m_initialCursorPos = aPosition; - } + m_Pos = m_initialPos = aPosition; } void LIB_CIRCLE::CalcEdit( const wxPoint& aPosition ) { - if( IsNew() ) - { - SetEnd( aPosition ); - } - else if( IsMoving() ) - { - MoveTo( m_initialPos + aPosition - m_initialCursorPos ); - } + SetEnd( aPosition ); } diff --git a/eeschema/lib_circle.h b/eeschema/lib_circle.h index a9f90fdbbb..c5b858e62f 100644 --- a/eeschema/lib_circle.h +++ b/eeschema/lib_circle.h @@ -22,12 +22,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file lib_circle.h - */ - -#ifndef _LIB_CIRCLE_H_ -#define _LIB_CIRCLE_H_ +#ifndef LIB_CIRCLE_H +#define LIB_CIRCLE_H #include @@ -67,7 +63,7 @@ public: void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList ) override; - void BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aStartPoint ) override; + void BeginEdit( const wxPoint aStartPoint ) override; void CalcEdit( const wxPoint& aPosition ) override; void Offset( const wxPoint& aOffset ) override; @@ -83,7 +79,6 @@ public: void MirrorHorizontal( const wxPoint& aCenter ) override; void MirrorVertical( const wxPoint& aCenter ) override; - void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override; void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill, @@ -115,4 +110,4 @@ private: }; -#endif // _LIB_CIRCLE_H_ +#endif // LIB_CIRCLE_H diff --git a/eeschema/lib_draw_item.h b/eeschema/lib_draw_item.h index e4cd708552..992fa4531b 100644 --- a/eeschema/lib_draw_item.h +++ b/eeschema/lib_draw_item.h @@ -130,51 +130,34 @@ public: virtual wxString GetTypeName() = 0; /** - * Begin an editing a component library draw item in \a aEditMode at \a aPosition. + * Begin drawing a component library draw item at \a aPosition. * - * This is used to start an editing action such as resize or move a draw object. * It typically would be called on a left click when a draw tool is selected in - * the component library editor and one of the graphics tools is selected. It - * allows the draw item to maintain it's own internal state while it is being - * edited. Call AbortEdit() to quit the editing mode. + * the component library editor and one of the graphics tools is selected. * - * @param aEditMode The editing mode being performed. See base_struct.h for a list - * of mode flags. - * @param aPosition The position in drawing coordinates where the editing mode was - * started. This may or may not be required depending on the item - * being edited and the edit mode. + * @param aPosition The position in drawing coordinates where the drawing was started. + * May or may not be required depending on the item being drawn. */ - virtual void BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aPosition ) - { - SetFlags( aEditMode ); - } + virtual void BeginEdit( const wxPoint aPosition ) {} /** * Continue an edit in progress at \a aPosition. * - * This is used to perform the next action while editing a draw item. This would be + * This is used to perform the next action while drawing an item. This would be * called for each additional left click when the mouse is captured while the item - * is being edited. + * is being drawn. * * @param aPosition The position of the mouse left click in drawing coordinates. * @return True if additional mouse clicks are required to complete the edit in progress. */ - virtual bool ContinueEdit( const wxPoint aPosition ) - { - return false; - } + virtual bool ContinueEdit( const wxPoint aPosition ) { return false; } /** * End an object editing action. * * This is used to end or abort an edit action in progress initiated by BeginEdit(). - * - * @param aPosition The position of the last edit event in drawing coordinates. */ - virtual void EndEdit( const wxPoint& aPosition ) - { - ClearEditFlags(); - } + virtual void EndEdit() {} /** * Calculates the attributes of an item at \a aPosition when it is being edited. diff --git a/eeschema/lib_field.cpp b/eeschema/lib_field.cpp index b9a87803da..5efef785c2 100644 --- a/eeschema/lib_field.cpp +++ b/eeschema/lib_field.cpp @@ -22,10 +22,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file lib_field.cpp - */ - #include #include #include @@ -74,7 +70,7 @@ LIB_FIELD::~LIB_FIELD() } -void LIB_FIELD::operator=( const LIB_FIELD& field ) +LIB_FIELD& LIB_FIELD::operator=( const LIB_FIELD& field ) { m_id = field.m_id; m_Text = field.m_Text; @@ -82,6 +78,8 @@ void LIB_FIELD::operator=( const LIB_FIELD& field ) m_Parent = field.m_Parent; SetEffects( field ); + + return *this; } @@ -94,9 +92,6 @@ void LIB_FIELD::Init( int id ) SetTextAngle( TEXT_ANGLE_HORIZ ); // constructor already did this. - m_rotate = false; - m_updateText = false; - // fields in RAM must always have names, because we are trying to get // less dependent on field ids and more dependent on names. // Plus assumptions are made in the field editors. @@ -303,7 +298,7 @@ void LIB_FIELD::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill, /* Calculate the text orientation, according to the component * orientation/mirror */ - int orient = GetTextAngle(); + int orient = (int) GetTextAngle(); if( aTransform.y1 ) // Rotate component 90 deg. { @@ -394,14 +389,7 @@ COLOR4D LIB_FIELD::GetDefaultColor() void LIB_FIELD::Rotate() { - if( InEditMode() ) - { - m_rotate = true; - } - else - { - SetTextAngle( GetTextAngle() == TEXT_ANGLE_VERT ? TEXT_ANGLE_HORIZ : TEXT_ANGLE_VERT ); - } + SetTextAngle( GetTextAngle() == TEXT_ANGLE_VERT ? TEXT_ANGLE_HORIZ : TEXT_ANGLE_VERT ); } @@ -452,22 +440,7 @@ void LIB_FIELD::SetName( const wxString& aName ) void LIB_FIELD::SetText( const wxString& aText ) { - if( aText == GetText() ) - return; - - wxString oldValue( m_Text ); - wxString newValue( aText ); - - if( InEditMode() ) - { - m_Text = oldValue; - m_savedText = newValue; - m_updateText = true; - } - else - { - m_Text = newValue; - } + m_Text = aText; } @@ -477,53 +450,15 @@ wxString LIB_FIELD::GetSelectMenuText( EDA_UNITS_T aUnits ) const } -void LIB_FIELD::BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aPosition ) +void LIB_FIELD::BeginEdit( const wxPoint aPosition ) { - LIB_ITEM::BeginEdit( aEditMode, aPosition ); - - if( aEditMode == IS_MOVED ) - { - m_initialPos = GetTextPos(); - m_initialCursorPos = aPosition; - } - else - { - SetTextPos( aPosition ); - } -} - - -void LIB_FIELD::EndEdit( const wxPoint& aPosition ) -{ - LIB_ITEM::EndEdit( aPosition ); - - m_rotate = false; - m_updateText = false; + SetTextPos( aPosition ); } void LIB_FIELD::CalcEdit( const wxPoint& aPosition ) { - if( m_rotate ) - { - SetTextAngle( GetTextAngle() == TEXT_ANGLE_VERT ? TEXT_ANGLE_HORIZ : TEXT_ANGLE_VERT ); - m_rotate = false; - } - - if( m_updateText ) - { - std::swap( m_Text, m_savedText ); - m_updateText = false; - } - - if( IsNew() ) - { - SetTextPos( aPosition ); - } - else if( IsMoving() ) - { - MoveTo( m_initialPos + aPosition - m_initialCursorPos ); - } + SetTextPos( aPosition ); } diff --git a/eeschema/lib_field.h b/eeschema/lib_field.h index 060132ae3d..0f7d468876 100644 --- a/eeschema/lib_field.h +++ b/eeschema/lib_field.h @@ -61,10 +61,6 @@ class LIB_FIELD : public LIB_ITEM, public EDA_TEXT int m_id; ///< @see enum NumFieldType wxString m_name; ///< Name (not the field text value itself, that is .m_Text) - wxString m_savedText; ///< Temporary storage for the string when editing. - bool m_rotate; ///< Flag to indicate a rotation occurred while editing. - bool m_updateText; ///< Flag to indicate text change occurred while editing. - /** * Draw the field. *

@@ -137,7 +133,6 @@ public: void SetName( const wxString& aName ); int GetId() const { return m_id; } - void SetId( int aId ) { m_id = aId; } int GetPenSize( ) const override; @@ -159,18 +154,13 @@ public: void ViewGetLayers( int aLayers[], int& aCount ) const override; - /** - * @return true is this field is visible, false if flagged invisible - */ - bool IsVisible() const { return EDA_TEXT::IsVisible(); } // why needed? - const EDA_RECT GetBoundingBox() const override; void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList ) override; bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override; - void operator=( const LIB_FIELD& field ); + LIB_FIELD& operator=( const LIB_FIELD& field ); /** * Return the text of a field. @@ -188,8 +178,7 @@ public: COLOR4D GetDefaultColor() override; - void BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aStartPoint ) override; - void EndEdit( const wxPoint& aPosition ) override; + void BeginEdit( const wxPoint aStartPoint ) override; void Rotate() override; diff --git a/eeschema/lib_polyline.cpp b/eeschema/lib_polyline.cpp index b67458c7d6..3e8e1cc340 100644 --- a/eeschema/lib_polyline.cpp +++ b/eeschema/lib_polyline.cpp @@ -22,10 +22,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file lib_polyline.cpp - */ - #include #include #include @@ -41,13 +37,12 @@ #include -LIB_POLYLINE::LIB_POLYLINE( LIB_PART* aParent ) : +LIB_POLYLINE::LIB_POLYLINE( LIB_PART* aParent ) : LIB_ITEM( LIB_POLYLINE_T, aParent ) { m_Fill = NO_FILL; m_Width = 0; m_isFillable = true; - m_ModifyIndex = 0; } @@ -81,16 +76,16 @@ int LIB_POLYLINE::compare( const LIB_ITEM& aOther ) const void LIB_POLYLINE::Offset( const wxPoint& aOffset ) { - for( size_t i = 0; i < m_PolyPoints.size(); i++ ) - m_PolyPoints[i] += aOffset; + for( wxPoint& point : m_PolyPoints ) + point += aOffset; } bool LIB_POLYLINE::Inside( EDA_RECT& aRect ) const { - for( size_t i = 0; i < m_PolyPoints.size(); i++ ) + for( const wxPoint& point : m_PolyPoints ) { - if( aRect.Contains( m_PolyPoints[i].x, -m_PolyPoints[i].y ) ) + if( aRect.Contains( point.x, -point.y ) ) return true; } @@ -106,35 +101,28 @@ void LIB_POLYLINE::MoveTo( const wxPoint& aPosition ) void LIB_POLYLINE::MirrorHorizontal( const wxPoint& aCenter ) { - size_t i, imax = m_PolyPoints.size(); - - for( i = 0; i < imax; i++ ) + for( wxPoint& point : m_PolyPoints ) { - m_PolyPoints[i].x -= aCenter.x; - m_PolyPoints[i].x *= -1; - m_PolyPoints[i].x += aCenter.x; + point.x -= aCenter.x; + point.x *= -1; + point.x += aCenter.x; } } void LIB_POLYLINE::MirrorVertical( const wxPoint& aCenter ) { - size_t i, imax = m_PolyPoints.size(); - - for( i = 0; i < imax; i++ ) + for( wxPoint& point : m_PolyPoints ) { - m_PolyPoints[i].y -= aCenter.y; - m_PolyPoints[i].y *= -1; - m_PolyPoints[i].y += aCenter.y; + point.y -= aCenter.y; + point.y *= -1; + point.y += aCenter.y; } } void LIB_POLYLINE::Rotate( const wxPoint& aCenter, bool aRotateCCW ) { - int rot_angle = aRotateCCW ? -900 : 900; - size_t i, imax = m_PolyPoints.size(); - - for( i = 0; i < imax; i++ ) - RotatePoint( &m_PolyPoints[i], aCenter, rot_angle ); + for( wxPoint& point : m_PolyPoints ) + RotatePoint( &point, aCenter, aRotateCCW ? -900 : 900 ); } @@ -146,9 +134,8 @@ void LIB_POLYLINE::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill, static std::vector< wxPoint > cornerList; cornerList.clear(); - for( unsigned ii = 0; ii < m_PolyPoints.size(); ii++ ) + for( wxPoint pos : m_PolyPoints ) { - wxPoint pos = m_PolyPoints[ii]; pos = aTransform.TransformCoordinate( pos ) + aOffset; cornerList.push_back( pos ); } @@ -372,127 +359,35 @@ BITMAP_DEF LIB_POLYLINE::GetMenuImage() const } -void LIB_POLYLINE::BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aPosition ) +void LIB_POLYLINE::BeginEdit( const wxPoint aPosition ) { - LIB_ITEM::BeginEdit( aEditMode, aPosition ); - - if( aEditMode == IS_NEW ) - { - m_PolyPoints.push_back( aPosition ); // Start point of first segment. - m_PolyPoints.push_back( aPosition ); // End point of first segment. - } - else if( aEditMode == IS_RESIZED ) - { - // Drag one edge point of the polyline - // Find the nearest edge point to be dragged - wxPoint startPoint = m_PolyPoints[0]; - - // Begin with the first list point as nearest point - int index = 0; - m_ModifyIndex = 0; - m_initialPos = startPoint; - - // First distance is the current minimum distance - int distanceMin = (aPosition - startPoint).x * (aPosition - startPoint).x - + (aPosition - startPoint).y * (aPosition - startPoint).y; - - wxPoint prevPoint = startPoint; - - // Find the right index of the point to be dragged - for( wxPoint point : m_PolyPoints ) - { - int distancePoint = (aPosition - point).x * (aPosition - point).x + - (aPosition - point).y * (aPosition - point).y; - - if( distancePoint < distanceMin ) - { - // Save point. - m_initialPos = point; - m_ModifyIndex = index; - distanceMin = distancePoint; - } - - // check middle of an edge - wxPoint offset = ( aPosition + aPosition - point - prevPoint ); - distancePoint = ( offset.x * offset.x + offset.y * offset.y ) / 4 + 1; - - if( distancePoint < distanceMin ) - { - // Save point. - m_initialPos = point; - m_ModifyIndex = -index; // negative indicates new vertex is to be inserted - distanceMin = distancePoint; - } - - prevPoint = point; - index++; - } - } - else if( aEditMode == IS_MOVED ) - { - m_initialCursorPos = aPosition; - m_initialPos = m_PolyPoints[0]; - } + m_PolyPoints.push_back( aPosition ); // Start point of first segment. + m_PolyPoints.push_back( aPosition ); // End point of first segment. } bool LIB_POLYLINE::ContinueEdit( const wxPoint aPosition ) { - if( IsNew() ) - { - // do not add zero length segments - if( m_PolyPoints[m_PolyPoints.size() - 2] != m_PolyPoints.back() ) - m_PolyPoints.push_back( aPosition ); + // do not add zero length segments + if( m_PolyPoints[m_PolyPoints.size() - 2] != m_PolyPoints.back() ) + m_PolyPoints.push_back( aPosition ); - return true; - } - - return false; + return true; } -void LIB_POLYLINE::EndEdit( const wxPoint& aPosition ) +void LIB_POLYLINE::EndEdit() { - LIB_ITEM::EndEdit( aPosition ); - // do not include last point twice - if( m_Flags == IS_NEW && 2 < m_PolyPoints.size() ) + if( m_PolyPoints.size() > 2 ) { if( m_PolyPoints[ m_PolyPoints.size() - 2 ] == m_PolyPoints.back() ) m_PolyPoints.pop_back(); } - - if( (m_Flags == IS_RESIZED) && (m_PolyPoints.size() > 2) ) // do not delete last two points... keep it alive - { - if( ( m_ModifyIndex > 0 && m_PolyPoints[ m_ModifyIndex ] == - m_PolyPoints[ m_ModifyIndex - 1 ] ) - || ( m_ModifyIndex < (int) m_PolyPoints.size() - 1 - && m_PolyPoints[ m_ModifyIndex ] == m_PolyPoints[ m_ModifyIndex + 1 ] ) ) - { - m_PolyPoints.erase( m_PolyPoints.begin() + m_ModifyIndex ); // delete a point on this - } - } } void LIB_POLYLINE::CalcEdit( const wxPoint& aPosition ) { - if( IsNew() ) - { - m_PolyPoints[ GetCornerCount() - 1 ] = aPosition; - } - else if( IsResized() ) - { - if( m_ModifyIndex < 0 ) // negative indicates new vertex is to be inserted - { - m_ModifyIndex = -m_ModifyIndex; - m_PolyPoints.insert( m_PolyPoints.begin() + m_ModifyIndex, aPosition ); - } - - m_PolyPoints[ m_ModifyIndex ] = aPosition; - } - else if( IsMoving() ) - { - MoveTo( m_initialPos + aPosition - m_initialCursorPos ); - } + m_PolyPoints[ GetCornerCount() - 1 ] = aPosition; } diff --git a/eeschema/lib_polyline.h b/eeschema/lib_polyline.h index 46997d9253..c083cdc1f7 100644 --- a/eeschema/lib_polyline.h +++ b/eeschema/lib_polyline.h @@ -22,10 +22,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file lib_polyline.h - */ - #ifndef _LIB_POLYLINE_H_ #define _LIB_POLYLINE_H_ @@ -37,8 +33,6 @@ class LIB_POLYLINE : public LIB_ITEM int m_Width; // Line width std::vector m_PolyPoints; // list of points (>= 2) - int m_ModifyIndex; // Index of the polyline point to modify - void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, void* aData, const TRANSFORM& aTransform ) override; @@ -87,10 +81,10 @@ public: void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList ) override; - void BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aStartPoint ) override; + void BeginEdit( const wxPoint aStartPoint ) override; void CalcEdit( const wxPoint& aPosition ) override; bool ContinueEdit( const wxPoint aNextPoint ) override; - void EndEdit( const wxPoint& aPosition ) override; + void EndEdit() override; void Offset( const wxPoint& aOffset ) override; diff --git a/eeschema/lib_rectangle.cpp b/eeschema/lib_rectangle.cpp index bc5af21817..3370fc009c 100644 --- a/eeschema/lib_rectangle.cpp +++ b/eeschema/lib_rectangle.cpp @@ -22,10 +22,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file lib_rectangle.cpp - */ - #include #include #include @@ -47,9 +43,6 @@ LIB_RECTANGLE::LIB_RECTANGLE( LIB_PART* aParent ) : m_Width = 0; m_Fill = NO_FILL; m_isFillable = true; - m_isHeightLocked = false; - m_isWidthLocked = false; - m_isStartPointSelected = false; } @@ -173,13 +166,10 @@ int LIB_RECTANGLE::GetPenSize() const void LIB_RECTANGLE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, void* aData, const TRANSFORM& aTransform ) { - wxPoint pt1, pt2; - COLOR4D color = GetLayerColor( LAYER_DEVICE ); COLOR4D bgColor = GetLayerColor( LAYER_DEVICE_BACKGROUND ); - - pt1 = aTransform.TransformCoordinate( m_Pos ) + aOffset; - pt2 = aTransform.TransformCoordinate( m_End ) + aOffset; + wxPoint pt1 = aTransform.TransformCoordinate( m_Pos ) + aOffset; + wxPoint pt2 = aTransform.TransformCoordinate( m_End ) + aOffset; FILL_T fill = aData ? NO_FILL : m_Fill; @@ -195,11 +185,9 @@ void LIB_RECTANGLE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoin void LIB_RECTANGLE::GetMsgPanelInfo( EDA_UNITS_T aUnits, MSG_PANEL_ITEMS& aList ) { - wxString msg; - LIB_ITEM::GetMsgPanelInfo( aUnits, aList ); - msg = MessageTextFromValue( aUnits, m_Width, true ); + wxString msg = MessageTextFromValue( aUnits, m_Width, true ); aList.push_back( MSG_PANEL_ITEM( _( "Line Width" ), msg, BLUE ) ); } @@ -277,39 +265,13 @@ BITMAP_DEF LIB_RECTANGLE::GetMenuImage() const } -void LIB_RECTANGLE::BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aPosition ) +void LIB_RECTANGLE::BeginEdit( const wxPoint aPosition ) { - LIB_ITEM::BeginEdit( aEditMode, aPosition ); - - if( aEditMode == IS_NEW ) - { - m_Pos = m_End = aPosition; - } - else if( aEditMode == IS_MOVED ) - { - m_initialPos = m_Pos; - m_initialCursorPos = aPosition; - } -} - - -void LIB_RECTANGLE::EndEdit( const wxPoint& aPosition ) -{ - LIB_ITEM::EndEdit( aPosition ); - - m_isHeightLocked = false; - m_isWidthLocked = false; + m_Pos = m_End = aPosition; } void LIB_RECTANGLE::CalcEdit( const wxPoint& aPosition ) { - if( IsNew() ) - { - m_End = aPosition; - } - else if( IsMoving() ) - { - MoveTo( m_initialPos + aPosition - m_initialCursorPos ); - } + m_End = aPosition; } diff --git a/eeschema/lib_rectangle.h b/eeschema/lib_rectangle.h index 54cebfed79..a317ccbd33 100644 --- a/eeschema/lib_rectangle.h +++ b/eeschema/lib_rectangle.h @@ -22,12 +22,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file lib_rectangle.h - */ - -#ifndef _LIB_RECTANGLE_H_ -#define _LIB_RECTANGLE_H_ +#ifndef LIB_RECTANGLE_H +#define LIB_RECTANGLE_H #include @@ -37,9 +33,6 @@ class LIB_RECTANGLE : public LIB_ITEM wxPoint m_End; // Rectangle end point. wxPoint m_Pos; // Rectangle start point. int m_Width; // Line width - bool m_isWidthLocked; // Flag: Keep width locked - bool m_isHeightLocked; // Flag: Keep height locked - bool m_isStartPointSelected; // Flag: is the upper left edge selected? void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, void* aData, const TRANSFORM& aTransform ) override; @@ -71,9 +64,8 @@ public: void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList ) override; - void BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aStartPoint ) override; + void BeginEdit( const wxPoint aStartPoint ) override; void CalcEdit( const wxPoint& aPosition ) override; - void EndEdit( const wxPoint& aPosition ) override; void Offset( const wxPoint& aOffset ) override; @@ -117,4 +109,4 @@ private: }; -#endif // _LIB_RECTANGLE_H_ +#endif // LIB_RECTANGLE_H diff --git a/eeschema/lib_text.cpp b/eeschema/lib_text.cpp index 290163a922..be8f4844a1 100644 --- a/eeschema/lib_text.cpp +++ b/eeschema/lib_text.cpp @@ -47,8 +47,6 @@ LIB_TEXT::LIB_TEXT( LIB_PART * aParent ) : EDA_TEXT() { SetTextSize( wxSize( 50, 50 ) ); - m_rotate = false; - m_updateText = false; } @@ -303,27 +301,13 @@ const EDA_RECT LIB_TEXT::GetBoundingBox() const void LIB_TEXT::Rotate() { - if( InEditMode() ) - m_rotate = true; - else - SetTextAngle( GetTextAngle() == TEXT_ANGLE_VERT ? TEXT_ANGLE_HORIZ : TEXT_ANGLE_VERT ); + SetTextAngle( GetTextAngle() == TEXT_ANGLE_VERT ? TEXT_ANGLE_HORIZ : TEXT_ANGLE_VERT ); } void LIB_TEXT::SetText( const wxString& aText ) { - if( aText == m_Text ) - return; - - if( InEditMode() ) - { - m_savedText = aText; - m_updateText = true; - } - else - { - m_Text = aText; - } + m_Text = aText; } @@ -339,56 +323,13 @@ BITMAP_DEF LIB_TEXT::GetMenuImage() const } -void LIB_TEXT::BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aPosition ) +void LIB_TEXT::BeginEdit( const wxPoint aPosition ) { - LIB_ITEM::BeginEdit( aEditMode, aPosition ); - - if( aEditMode == IS_MOVED ) - { - m_initialPos = GetTextPos(); - m_initialCursorPos = aPosition; - } - else - { - SetTextPos( aPosition ); - } -} - - -void LIB_TEXT::EndEdit( const wxPoint& aPosition ) -{ - LIB_ITEM::EndEdit( aPosition ); - - m_rotate = false; - m_updateText = false; + SetTextPos( aPosition ); } void LIB_TEXT::CalcEdit( const wxPoint& aPosition ) { - DBG(printf("textCalcEdit %d %d\n", aPosition.x, aPosition.y );) - - if( m_rotate ) - { - SetTextAngle( GetTextAngle() == TEXT_ANGLE_VERT ? TEXT_ANGLE_HORIZ : TEXT_ANGLE_VERT ); - m_rotate = false; - } - - if( m_updateText ) - { - std::swap( m_Text, m_savedText ); - m_updateText = false; - } - - if( IsNew() ) - { - SetTextPos( aPosition ); - } - else if( IsMoving() ) - { - MoveTo( m_initialPos + aPosition - m_initialCursorPos ); - DBG(printf("%p: move %d %d\n", this, GetPosition().x, GetPosition().y );) - } - - DBG(printf("%p: move2 %d %d\n", this, GetPosition().x, GetPosition().y );) + SetTextPos( aPosition ); } diff --git a/eeschema/lib_text.h b/eeschema/lib_text.h index ac58b2628b..f19bbfd7cf 100644 --- a/eeschema/lib_text.h +++ b/eeschema/lib_text.h @@ -22,12 +22,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file lib_text.h - */ - -#ifndef _LIB_TEXT_H_ -#define _LIB_TEXT_H_ +#ifndef LIB_TEXT_H +#define LIB_TEXT_H #include #include @@ -43,10 +39,6 @@ */ class LIB_TEXT : public LIB_ITEM, public EDA_TEXT { - wxString m_savedText; ///< Temporary storage for the string when editing. - bool m_rotate; ///< Flag to indicate a rotation occurred while editing. - bool m_updateText; ///< Flag to indicate text change occurred while editing. - void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, void* aData, const TRANSFORM& aTransform ) override; @@ -97,9 +89,8 @@ public: void Rotate() override; - void BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aStartPoint ) override; + void BeginEdit( const wxPoint aStartPoint ) override; void CalcEdit( const wxPoint& aPosition ) override; - void EndEdit( const wxPoint& aPosition ) override; void Offset( const wxPoint& aOffset ) override; @@ -144,4 +135,4 @@ private: }; -#endif // _LIB_TEXT_H_ +#endif // LIB_TEXT_H diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp index 5e7925d202..3767b6ec2a 100644 --- a/eeschema/libedit/lib_edit_frame.cpp +++ b/eeschema/libedit/lib_edit_frame.cpp @@ -196,9 +196,6 @@ LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); - if( m_canvas ) - m_canvas->SetEnableBlockCommands( true ); - m_libMgr = new LIB_MANAGER( *this ); SyncLibraries( true ); m_treePane = new SYMBOL_TREE_PANE( this, m_libMgr ); @@ -1072,17 +1069,9 @@ bool LIB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KE if( aHotKey ) keyHandled = GeneralControlKeyMovement( aHotKey, &pos, true ); - if( GetToolId() == ID_NO_TOOL_SELECTED ) - m_canvas->CrossHairOff( aDC ); - else - m_canvas->CrossHairOn( aDC ); - GetGalCanvas()->GetViewControls()->SetSnapping( false ); SetCrossHairPosition( pos, false ); - if( m_canvas->IsMouseCaptured() ) - m_canvas->CallMouseCapture( aDC, aPosition, true ); - if( aHotKey && OnHotKey( aDC, aHotKey, aPosition, NULL ) ) keyHandled = true; diff --git a/eeschema/libedit/lib_edit_frame.h b/eeschema/libedit/lib_edit_frame.h index f217634ba1..0e2218afa5 100644 --- a/eeschema/libedit/lib_edit_frame.h +++ b/eeschema/libedit/lib_edit_frame.h @@ -313,18 +313,12 @@ public: */ void RedrawComponent( wxDC* aDC, wxPoint aOffset ); - /** - * Redraw the current component loaded in library editor, an axes - * Display reference like in schematic (a reference U is shown U? or U?A) - * update status bar and info shown in the bottom of the window - */ - void RedrawActiveWindow( wxDC* DC, bool EraseBg ) override; + void RedrawActiveWindow( wxDC* DC, bool EraseBg ) override { /* OBSOLETE */ } void OnCloseWindow( wxCloseEvent& Event ); void ReCreateHToolbar() override; void ReCreateVToolbar() override; void ReCreateOptToolbar(); - bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ) override { return true; } double BestZoom() override; // Returns the best zoom ///> @copydoc EDA_DRAW_FRAME::GetHotKeyDescription() diff --git a/eeschema/libedit/libedit.cpp b/eeschema/libedit/libedit.cpp index afeaecbf98..b7e0a239ed 100644 --- a/eeschema/libedit/libedit.cpp +++ b/eeschema/libedit/libedit.cpp @@ -289,34 +289,6 @@ void LIB_EDIT_FRAME::RedrawComponent( wxDC* aDC, wxPoint aOffset ) } -void LIB_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) -{ - if( GetScreen() == NULL ) - return; - - m_canvas->DrawBackGround( DC ); - - RedrawComponent( DC, wxPoint( 0, 0 ) ); - -#ifdef USE_WX_OVERLAY - if( IsShown() ) - { - m_overlay.Reset(); - wxDCOverlay overlaydc( m_overlay, (wxWindowDC*)DC ); - overlaydc.Clear(); - } -#endif - - if( m_canvas->IsMouseCaptured() ) - m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); - - m_canvas->DrawCrossHair( DC ); - - updateTitle(); - UpdateStatusBar(); -} - - void LIB_EDIT_FRAME::OnSaveAll( wxCommandEvent& event ) { saveAllLibraries( false ); diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp index 14910f86e1..8506f6ec6c 100644 --- a/eeschema/sch_base_frame.cpp +++ b/eeschema/sch_base_frame.cpp @@ -368,74 +368,6 @@ bool SCH_BASE_FRAME::saveSymbolLibTables( bool aGlobal, bool aProject ) } -// Set the zoom level to show the contents of the view. -void SCH_BASE_FRAME::Zoom_Automatique( bool aWarpPointer ) -{ - EDA_DRAW_PANEL_GAL* galCanvas = GetGalCanvas(); - KIGFX::VIEW* view = GetGalCanvas()->GetView(); - - BOX2I bBox = GetDocumentExtents(); - - VECTOR2D scrollbarSize = VECTOR2D( galCanvas->GetSize() - galCanvas->GetClientSize() ); - VECTOR2D screenSize = view->ToWorld( galCanvas->GetClientSize(), false ); - - if( bBox.GetWidth() == 0 || bBox.GetHeight() == 0 ) - bBox = galCanvas->GetDefaultViewBBox(); - - VECTOR2D vsize = bBox.GetSize(); - double scale = view->GetScale() / std::max( fabs( vsize.x / screenSize.x ), - fabs( vsize.y / screenSize.y ) ); - - // Reserve a 10% margin around component bounding box. - double margin_scale_factor = 1.1; - - // Leave 20% for library editors & viewers - if( IsType( FRAME_PCB_MODULE_VIEWER ) || IsType( FRAME_PCB_MODULE_VIEWER_MODAL ) - || IsType( FRAME_SCH_VIEWER ) || IsType( FRAME_SCH_VIEWER_MODAL ) - || IsType( FRAME_SCH_LIB_EDITOR ) || IsType( FRAME_PCB_MODULE_EDITOR ) ) - { - margin_scale_factor = 1.2; - } - - scale /= margin_scale_factor; - - GetScreen()->SetScalingFactor( 1 / scale ); - - view->SetScale( scale ); - view->SetCenter( bBox.Centre() ); - - // Take scrollbars into account - VECTOR2D worldScrollbarSize = view->ToWorld( scrollbarSize, false ); - view->SetCenter( view->GetCenter() + worldScrollbarSize / 2.0 ); - galCanvas->Refresh(); -} - - -// Set the zoom level to show the area of aRect -void SCH_BASE_FRAME::Window_Zoom( EDA_RECT& aRect ) -{ - KIGFX::VIEW* view = GetGalCanvas()->GetView(); - BOX2I selectionBox ( aRect.GetPosition(), aRect.GetSize() ); - - VECTOR2D screenSize = view->ToWorld( GetGalCanvas()->GetClientSize(), false ); - - if( selectionBox.GetWidth() == 0 || selectionBox.GetHeight() == 0 ) - return; - - VECTOR2D vsize = selectionBox.GetSize(); - double scale; - double ratio = std::max( fabs( vsize.x / screenSize.x ), fabs( vsize.y / screenSize.y ) ); - - scale = view->GetScale() / ratio; - - GetScreen()->SetScalingFactor( 1 / scale ); - - view->SetScale( scale ); - view->SetCenter( selectionBox.Centre() ); - GetGalCanvas()->Refresh(); -} - - void SCH_BASE_FRAME::RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointer ) { KIGFX::GAL* gal = GetCanvas()->GetGAL(); diff --git a/eeschema/sch_base_frame.h b/eeschema/sch_base_frame.h index 507ce90a20..43db1157f7 100644 --- a/eeschema/sch_base_frame.h +++ b/eeschema/sch_base_frame.h @@ -310,12 +310,6 @@ public: const LIB_ID& aPreselectedLibid, int aUnit, int aConvert ); - - virtual void Zoom_Automatique( bool aWarpPointer ) override; - - /* Set the zoom level to show the area Rect */ - virtual void Window_Zoom( EDA_RECT& aRect ) override; - virtual void RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointer ) override; virtual void RedrawScreen2( const wxPoint& posBefore ) override; diff --git a/eeschema/sch_draw_panel.cpp b/eeschema/sch_draw_panel.cpp index 10967f5f18..e5f21abe0c 100644 --- a/eeschema/sch_draw_panel.cpp +++ b/eeschema/sch_draw_panel.cpp @@ -98,12 +98,6 @@ SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId, // launching a editor from a double click made in another frame) m_ignoreNextLeftButtonRelease = true; - m_mouseCaptureCallback = NULL; - m_endMouseCaptureCallback = NULL; - - m_enableBlockCommands = false; - m_minDragEventCount = 0; - m_cursorLevel = 0; m_PrintIsMirrored = false; @@ -246,18 +240,6 @@ EDA_DRAW_FRAME* SCH_DRAW_PANEL::GetParent() const } -void SCH_DRAW_PANEL::CrossHairOff( wxDC* DC ) -{ - m_viewControls->ShowCursor( false ); -} - - -void SCH_DRAW_PANEL::CrossHairOn( wxDC* DC ) -{ - m_viewControls->ShowCursor( true ); -} - - void SCH_DRAW_PANEL::MoveCursorToCrossHair() { GetViewControls()->WarpCursor( GetParent()->GetCrossHairPosition(), true ); diff --git a/eeschema/sch_draw_panel.h b/eeschema/sch_draw_panel.h index 3c6d048a63..24c6ac51bc 100644 --- a/eeschema/sch_draw_panel.h +++ b/eeschema/sch_draw_panel.h @@ -52,11 +52,6 @@ public: BASE_SCREEN* GetScreen() override; virtual EDA_DRAW_FRAME* GetParent() const override; - virtual void CrossHairOff( wxDC* DC=nullptr ) override; - - // Show the cross hair. - virtual void CrossHairOn( wxDC* DC=nullptr ) override; - virtual void MoveCursorToCrossHair() override; KIGFX::SCH_VIEW* GetView() const { return view(); } diff --git a/eeschema/sch_eagle_plugin.cpp b/eeschema/sch_eagle_plugin.cpp index 159b78ccf1..3754dda01a 100644 --- a/eeschema/sch_eagle_plugin.cpp +++ b/eeschema/sch_eagle_plugin.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 2ccc7ae790..2a0a33e324 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -324,9 +324,6 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ): SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); - if( m_canvas ) - m_canvas->SetEnableBlockCommands( true ); - setupTools(); ReCreateMenuBar(); ReCreateHToolbar(); @@ -423,23 +420,11 @@ void SCH_EDIT_FRAME::SaveCopyForRepeatItem( SCH_ITEM* aItem ) // that item may be deleted, such as part of a line concatonation or other. // So simply always keep a copy of the object which is to be repeated. - SCH_ITEM* old = m_item_to_repeat; - SCH_ITEM* cur = aItem; + delete m_item_to_repeat; - if( cur != old ) - { - if( cur ) - { - aItem = (SCH_ITEM*) cur->Clone(); - - // Clone() preserves the flags, we want 'em cleared. - aItem->ClearFlags(); - } - - m_item_to_repeat = aItem; - - delete old; - } + m_item_to_repeat = (SCH_ITEM*) aItem->Clone(); + // Clone() preserves the flags, we want 'em cleared. + m_item_to_repeat->ClearFlags(); } @@ -461,20 +446,16 @@ void SCH_EDIT_FRAME::SetSheetNumberAndCount() { wxString sheetpath = sheetList[i].Path(); - if( sheetpath == current_sheetpath ) // Current sheet path found + if( sheetpath == current_sheetpath ) // Current sheet path found break; - SheetNumber++; /* Not found, increment sheet - * number before this current - * path */ + SheetNumber++; // Not found, increment before this current path } g_CurrentSheet->SetPageNumber( SheetNumber ); for( screen = s_list.GetFirst(); screen != NULL; screen = s_list.GetNext() ) - { screen->m_NumberOfScreens = sheet_count; - } GetScreen()->m_ScreenNumber = SheetNumber; } @@ -503,9 +484,7 @@ wxString SCH_EDIT_FRAME::GetScreenDesc() const void SCH_EDIT_FRAME::CreateScreens() { if( g_RootSheet == NULL ) - { g_RootSheet = new SCH_SHEET(); - } if( g_RootSheet->GetScreen() == NULL ) { @@ -558,30 +537,11 @@ void SCH_EDIT_FRAME::HardRedraw() } -/* - * Redraws only the active window which is assumed to be whole visible. - */ -void SCH_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) -{ - if( GetScreen() == NULL ) - return; - - if( m_canvas->IsMouseCaptured() ) - m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); - - // Display the sheet filename, and the sheet path, for non root sheets - UpdateTitle(); -} - - void SCH_EDIT_FRAME::SaveUndoItemInUndoList( SCH_ITEM* aItem, bool aAppend ) { - wxCHECK_RET( aItem != NULL, - wxT( "Cannot swap undo item structures. Bad programmer!." ) ); - wxCHECK_RET( m_undoItem != NULL, - wxT( "Cannot swap undo item structures. Bad programmer!." ) ); - wxCHECK_RET( aItem->Type() == m_undoItem->Type(), - wxT( "Cannot swap undo item structures. Bad programmer!." ) ); + wxCHECK_RET( aItem != NULL, wxT( "Cannot swap undo item structures." ) ); + wxCHECK_RET( m_undoItem != NULL, wxT( "Cannot swap undo item structures." ) ); + wxCHECK_RET( aItem->Type() == m_undoItem->Type(), wxT( "Cannot swap undo item structures." ) ); aItem->SwapData( m_undoItem ); SaveCopyInUndoList( aItem, UR_CHANGED, aAppend ); @@ -940,8 +900,7 @@ void SCH_EDIT_FRAME::OnNewProject( wxCommandEvent& event ) { wxString pro_dir = m_mruPath; - wxFileDialog dlg( this, _( "New Schematic" ), pro_dir, - wxEmptyString, SchematicFileWildcard(), + wxFileDialog dlg( this, _( "New Schematic" ), pro_dir, wxEmptyString, SchematicFileWildcard(), wxFD_SAVE ); if( dlg.ShowModal() != wxID_CANCEL ) @@ -971,8 +930,7 @@ void SCH_EDIT_FRAME::OnLoadProject( wxCommandEvent& event ) { wxString pro_dir = m_mruPath; - wxFileDialog dlg( this, _( "Open Schematic" ), pro_dir, - wxEmptyString, SchematicFileWildcard(), + wxFileDialog dlg( this, _( "Open Schematic" ), pro_dir, wxEmptyString, SchematicFileWildcard(), wxFD_OPEN | wxFD_FILE_MUST_EXIST ); if( dlg.ShowModal() != wxID_CANCEL ) @@ -992,8 +950,10 @@ void SCH_EDIT_FRAME::OnOpenPcbnew( wxCommandEvent& event ) kicad_board.SetExt( PcbFileExtension ); wxFileName legacy_board( kicad_board ); legacy_board.SetExt( LegacyPcbFileExtension ); - wxFileName& boardfn = ( !legacy_board.FileExists() || kicad_board.FileExists() ) ? - kicad_board : legacy_board; + wxFileName& boardfn = legacy_board; + + if( !legacy_board.FileExists() || kicad_board.FileExists() ) + boardfn = kicad_board; if( Kiface().IsSingle() ) { diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index b8b4a798e0..57cc9d627d 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -300,7 +300,7 @@ public: void LoadSettings( wxConfigBase* aCfg ) override; void SaveSettings( wxConfigBase* aCfg ) override; - void RedrawActiveWindow( wxDC* DC, bool EraseBg ) override; + void RedrawActiveWindow( wxDC* DC, bool EraseBg ) override { /* OBSOLETE */ } void CreateScreens(); void ReCreateHToolbar() override; @@ -331,7 +331,6 @@ public: void KiwayMailIn( KIWAY_EXPRESS& aEvent ) override; - bool OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) override { return true; } double BestZoom() override; /** diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 3d91793d97..b246c72f1a 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -308,8 +308,6 @@ bool SCH_FIELD::IsVoid() const void SCH_FIELD::Place( SCH_EDIT_FRAME* frame, wxDC* DC ) { - frame->GetCanvas()->SetMouseCapture( NULL, NULL ); - SCH_COMPONENT* component = (SCH_COMPONENT*) GetParent(); // save old cmp in undo list diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 782bf4ef63..d5af57e3f7 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -110,11 +110,11 @@ SCH_SCREEN::SCH_SCREEN( KIWAY* aKiway ) : SetZoom( 32 ); - for( unsigned i = 0; i < arrayDim( SchematicZoomList ); i++ ) - m_ZoomList.push_back( SchematicZoomList[i] ); + for( unsigned zoom : SchematicZoomList ) + m_ZoomList.push_back( zoom ); - for( unsigned i = 0; i < arrayDim( SchematicGridList ); i++ ) - AddGrid( SchematicGridList[i] ); + for( GRID_TYPE grid : SchematicGridList ) + AddGrid( grid ); // Set the default grid size, now that the grid list is populated SetGrid( wxRealPoint( 50, 50 ) ); diff --git a/eeschema/tools/ee_point_editor.h b/eeschema/tools/ee_point_editor.h index 27dbd4155f..f8c68f21a7 100644 --- a/eeschema/tools/ee_point_editor.h +++ b/eeschema/tools/ee_point_editor.h @@ -21,8 +21,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef SCH_POINT_EDITOR_H -#define SCH_POINT_EDITOR_H +#ifndef EE_POINT_EDITOR_H +#define EE_POINT_EDITOR_H #include #include @@ -32,7 +32,7 @@ class EE_SELECTION_TOOL; class SCH_BASE_FRAME; /** - * Class SCH_POINT_EDITOR + * Class EE_POINT_EDITOR * * Tool that displays edit points allowing to modify items by dragging the points. */ @@ -101,4 +101,4 @@ private: std::shared_ptr m_editPoints; }; -#endif // SCH_POINT_EDITOR_H +#endif // EE_POINT_EDITOR_H diff --git a/eeschema/tools/lib_drawing_tools.cpp b/eeschema/tools/lib_drawing_tools.cpp index 7ed9db0520..894cd83098 100644 --- a/eeschema/tools/lib_drawing_tools.cpp +++ b/eeschema/tools/lib_drawing_tools.cpp @@ -285,6 +285,8 @@ int LIB_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) m_frame->SetToolID( ID_LIBEDIT_BODY_LINE_BUTT, wxCURSOR_PENCIL, _( "Draw Lines" ) ); else if( aEvent.IsAction( &EE_ACTIONS::drawSymbolRectangle ) ) m_frame->SetToolID( ID_LIBEDIT_BODY_RECT_BUTT, wxCURSOR_PENCIL, _( "Draw Rectangle" ) ); + else + wxCHECK_MSG( false, 0, "Unknown action in LIB_DRAWING_TOOLS::DrawShape()" ); m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); getViewControls()->ShowCursor( true ); @@ -329,12 +331,12 @@ int LIB_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) case ID_LIBEDIT_BODY_CIRCLE_BUTT: item = new LIB_CIRCLE( part ); break; case ID_LIBEDIT_BODY_LINE_BUTT: item = new LIB_POLYLINE( part ); break; case ID_LIBEDIT_BODY_RECT_BUTT: item = new LIB_RECTANGLE( part ); break; - default: wxFAIL_MSG( "LIB_DRAWING_TOOLS:DrawShape(): unknown tool" ); } item->SetWidth( LIB_EDIT_FRAME::g_LastLineWidth ); item->SetFillMode( LIB_EDIT_FRAME::g_LastFillStyle ); - item->BeginEdit( IS_NEW, wxPoint( cursorPos.x, -cursorPos.y ) ); + item->SetFlags( IS_NEW ); + item->BeginEdit( wxPoint( cursorPos.x, -cursorPos.y ) ); if( m_frame->m_DrawSpecificUnit ) item->SetUnit( m_frame->GetUnit() ); @@ -353,7 +355,8 @@ int LIB_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) || evt->IsAction( &EE_ACTIONS::finishDrawing ) || !item->ContinueEdit( wxPoint( cursorPos.x, -cursorPos.y ) ) ) { - item->EndEdit( wxPoint( cursorPos.x, -cursorPos.y ) ); + item->EndEdit(); + item->ClearEditFlags(); m_view->ClearPreview(); m_frame->SaveCopyInUndoList( part ); diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 670d25775a..a6ccc4646e 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -154,7 +154,7 @@ TOOL_ACTION EE_ACTIONS::pinTable( "eeschema.InteractiveEdit.pinTable", _( "Pin Table..." ), _( "Displays pin table for bulk editing of pins" ), pin_table_xpm ); -TOOL_ACTION EE_ACTIONS::doDelete( "eeschema.InteractiveEdit.doDelete", +TOOL_ACTION EE_ACTIONS::doDelete( "eeschema.InteractiveEdit.delete", AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_DELETE ), _( "Delete" ), _( "Deletes selected item(s)" ), delete_xpm ); diff --git a/eeschema/viewlib_frame.cpp b/eeschema/viewlib_frame.cpp index a302d2631b..25a7064f6f 100644 --- a/eeschema/viewlib_frame.cpp +++ b/eeschema/viewlib_frame.cpp @@ -855,7 +855,6 @@ bool LIB_VIEW_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KE GeneralControlKeyMovement( aHotKey, &pos, true ); // Update cursor position. - m_canvas->CrossHairOn( aDC ); SetCrossHairPosition( pos, true ); if( aHotKey ) diff --git a/eeschema/viewlib_frame.h b/eeschema/viewlib_frame.h index a2f316ff9e..ab22f570a7 100644 --- a/eeschema/viewlib_frame.h +++ b/eeschema/viewlib_frame.h @@ -84,14 +84,13 @@ public: bool ReCreateListCmp(); void DisplayLibInfos(); - void RedrawActiveWindow( wxDC* DC, bool EraseBg ) override; + void RedrawActiveWindow( wxDC* DC, bool EraseBg ) override { /* OBSOLETE */ } void OnCloseWindow( wxCloseEvent& Event ); void CloseLibraryViewer( wxCommandEvent& event ); void ReCreateHToolbar() override; void ReCreateVToolbar() override; void ReCreateMenuBar() override; - void OnLeftClick( wxDC* DC, const wxPoint& MousePos ) override; double BestZoom() override; void ClickOnLibList( wxCommandEvent& event ); void ClickOnCmpList( wxCommandEvent& event ); @@ -162,7 +161,6 @@ private: */ virtual void OnActivate( wxActivateEvent& event ) override; - bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ) override; void DClickOnCmpList( wxCommandEvent& event ); void onUpdateAltBodyStyleButton( wxUpdateUIEvent& aEvent ); diff --git a/eeschema/viewlibs.cpp b/eeschema/viewlibs.cpp index b6777d4892..e0871f8902 100644 --- a/eeschema/viewlibs.cpp +++ b/eeschema/viewlibs.cpp @@ -156,17 +156,6 @@ void LIB_VIEW_FRAME::onSelectSymbolUnit( wxCommandEvent& aEvent ) } -void LIB_VIEW_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) -{ -} - - -bool LIB_VIEW_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ) -{ - return true; -} - - void LIB_VIEW_FRAME::DisplayLibInfos() { if( m_libList && !m_libList->IsEmpty() && !m_libraryName.IsEmpty() ) @@ -179,9 +168,3 @@ void LIB_VIEW_FRAME::DisplayLibInfos() } } - -void LIB_VIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) -{ - DisplayLibInfos(); - UpdateStatusBar(); -} diff --git a/gerbview/block.cpp b/gerbview/block.cpp index 3220d8c7b5..7810d070bc 100644 --- a/gerbview/block.cpp +++ b/gerbview/block.cpp @@ -134,9 +134,6 @@ bool GERBVIEW_FRAME::HandleBlockEnd( wxDC* DC ) false ); } - if( zoom_command ) - Window_Zoom( GetScreen()->m_BlockLocate ); - return nextcmd ; } diff --git a/gerbview/gbr_screen.cpp b/gerbview/gbr_screen.cpp index f8d186ef0b..6ce3260fa1 100644 --- a/gerbview/gbr_screen.cpp +++ b/gerbview/gbr_screen.cpp @@ -33,10 +33,8 @@ #include -#define MIL_GRID( x ) wxRealPoint( x * IU_PER_MILS,\ - x * IU_PER_MILS) -#define MM_GRID( x ) wxRealPoint( x * IU_PER_MM,\ - x * IU_PER_MM ) +#define MIL_GRID( x ) wxRealPoint( x * IU_PER_MILS, x * IU_PER_MILS) +#define MM_GRID( x ) wxRealPoint( x * IU_PER_MM, x * IU_PER_MM ) /** diff --git a/gerbview/gerbview_frame.h b/gerbview/gerbview_frame.h index ae0a97b1a9..af5932bb47 100644 --- a/gerbview/gerbview_frame.h +++ b/gerbview/gerbview_frame.h @@ -232,7 +232,6 @@ public: void ReCreateMenuBar() override; void OnLeftClick( wxDC* aDC, const wxPoint& aMousePos ) override; void OnLeftDClick( wxDC* aDC, const wxPoint& aMousePos ) override; - bool OnRightClick( const wxPoint& aMousePos, wxMenu* aPopMenu ) override { return true; } void OnUpdateSelectZoom( wxUpdateUIEvent& aEvent ); double BestZoom() override; void UpdateStatusBar() override; diff --git a/include/collector.h b/include/collector.h index 6ec895b67d..1c0a5dbf4a 100644 --- a/include/collector.h +++ b/include/collector.h @@ -55,36 +55,35 @@ class EDA_ITEM; class COLLECTOR { protected: - /// a class common bridge into the polymorphic Inspect() - INSPECTOR_FUNC m_inspector; - - /// Which object types to scan - const KICAD_T* m_ScanTypes; - - /// A place to hold collected objects without taking ownership of their memory. std::vector m_List; - /// A point to test against, and that was used to make the collection. - wxPoint m_RefPos; + const KICAD_T* m_ScanTypes; + INSPECTOR_FUNC m_inspector; + wxPoint m_RefPos; // Reference position used to generate the collection. + EDA_RECT m_RefBox; // Selection rectangle used to generate the collection. - /// A bounding box to test against, and that was used to make the collection. - EDA_RECT m_RefBox; + timestamp_t m_TimeAtCollection; // The time at which the collection was made. - /// The time at which the collection was made. - timestamp_t m_TimeAtCollection; +public: + 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 public: COLLECTOR() : + m_ScanTypes( 0 ), // Inspect() is virtual so calling it from a class common inspector preserves polymorphism. - m_inspector( [=] ( EDA_ITEM* aItem, void* aTestData ) { return this->Inspect( aItem, aTestData ); } ) + m_inspector( [=] ( EDA_ITEM* aItem, void* aTestData ) { return this->Inspect( aItem, aTestData ); } ), + m_TimeAtCollection( 0 ), + m_Threshold( 0 ), + m_MenuCancelled( false ) { - m_ScanTypes = 0; - m_TimeAtCollection = 0; } virtual ~COLLECTOR() {} - virtual SEARCH_RESULT Inspect( EDA_ITEM* aItem, void* aTestData ) = 0; + virtual SEARCH_RESULT Inspect( EDA_ITEM* aItem, void* aTestData ) { return SEARCH_QUIT; }; using ITER = std::vector::iterator; using CITER = std::vector::const_iterator; diff --git a/include/core/typeinfo.h b/include/core/typeinfo.h index 27cb620aca..6a46fe79ab 100644 --- a/include/core/typeinfo.h +++ b/include/core/typeinfo.h @@ -165,7 +165,7 @@ enum KICAD_T LIB_FIELD_T, /* - * For GerbView: items type: + * For GerbView: item types: */ GERBER_LAYOUT_T, GERBER_DRAW_ITEM_T, @@ -173,8 +173,15 @@ enum KICAD_T GERBER_IMAGE_T, /* - * for Pl_Editor, in undo/redo commands + * For Pl_Editor: item types: */ + WSG_LINE_T, + WSG_RECT_T, + WSG_POLY_T, + WSG_TEXT_T, + WSG_BITMAP_T, + + // serialized layout used in undo/redo commands TYPE_PL_EDITOR_LAYOUT, /* diff --git a/include/draw_frame.h b/include/draw_frame.h index fcf16d7389..4196c28df2 100644 --- a/include/draw_frame.h +++ b/include/draw_frame.h @@ -715,9 +715,6 @@ public: */ virtual void Zoom_Automatique( bool aWarpPointer ); - /* Set the zoom level to show the area Rect */ - virtual void Window_Zoom( EDA_RECT& Rect ); - /** Return the zoom level which displays the full page on screen */ virtual double BestZoom() = 0; @@ -755,7 +752,7 @@ public: virtual void RedrawActiveWindow( wxDC* DC, bool EraseBg ) = 0; virtual void OnLeftClick( wxDC* DC, const wxPoint& MousePos ) {} virtual void OnLeftDClick( wxDC* DC, const wxPoint& MousePos ) {} - virtual bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ) = 0; + virtual bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ) { return true; } virtual void ToolOnRightClick( wxCommandEvent& event ); void AdjustScrollBars( const wxPoint& aCenterPosition ); diff --git a/include/legacy_gal/class_drawpanel.h b/include/legacy_gal/class_drawpanel.h index 8851e39183..0db0715c33 100644 --- a/include/legacy_gal/class_drawpanel.h +++ b/include/legacy_gal/class_drawpanel.h @@ -6,22 +6,8 @@ #include #include -/** - * Mouse capture callback function prototype. - */ - class BASE_SCREEN; -class EDA_DRAW_PANEL; - -typedef void ( *MOUSE_CAPTURE_CALLBACK )( EDA_DRAW_PANEL* aPanel, wxDC* aDC, - const wxPoint& aPosition, bool aErase ); - -/** - * End mouse capture callback function prototype. - */ -typedef void ( *END_MOUSE_CAPTURE_CALLBACK )( EDA_DRAW_PANEL* aPanel, wxDC* aDC ); - class EDA_DRAW_PANEL { @@ -55,31 +41,10 @@ protected: */ bool m_ignoreNextLeftButtonRelease; ///< Ignore the next mouse left button release when true. - bool m_enableBlockCommands; ///< True enables block commands. - - /** - * Count the drag events. Used to filter mouse moves before starting a - * block command. A block command can be started only if - * MinDragEventCount > MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND in order to avoid - * spurious block commands. - */ - int m_minDragEventCount; - /// True when drawing in mirror mode. Used by the draw arc function, because arcs /// are oriented, and in mirror mode, orientations are reversed. bool m_PrintIsMirrored; - /// Mouse capture move callback function. - MOUSE_CAPTURE_CALLBACK m_mouseCaptureCallback; - - /// Abort mouse capture callback function. - END_MOUSE_CAPTURE_CALLBACK m_endMouseCaptureCallback; - - /// useful to avoid false start block in certain cases - /// (like switch from a sheet to another sheet - /// >= 0 (or >= n) if a block can start - int m_canStartBlock; - int m_doubleClickInterval; public: @@ -95,12 +60,7 @@ public: m_enableAutoPan( false ), m_ignoreMouseEvents( false ), m_ignoreNextLeftButtonRelease( false ), - m_enableBlockCommands( true ), - m_minDragEventCount( 5 ), m_PrintIsMirrored( false ), - m_mouseCaptureCallback( nullptr ), - m_endMouseCaptureCallback( nullptr ), - m_canStartBlock( true ), m_doubleClickInterval( 0 ) {}; @@ -145,13 +105,9 @@ public: void SetIgnoreLeftButtonReleaseEvent( bool aIgnore ) { m_ignoreNextLeftButtonRelease = aIgnore; } - void SetEnableBlockCommands( bool aEnable ) { m_enableBlockCommands = aEnable; } - bool GetPrintMirrored() const { return m_PrintIsMirrored; } void SetPrintMirrored( bool aMirror ) { m_PrintIsMirrored = aMirror; } - void SetCanStartBlock( int aStartBlock ) { m_canStartBlock = aStartBlock; } - /** * Function DrawBackGround * @param DC = current Device Context @@ -191,18 +147,6 @@ public: */ virtual void DrawGridAxis( wxDC* aDC, GR_DRAWMODE aDrawMode, const wxPoint& aGridOrigin ) { printf("EDA_DRAW_PANEL:Unimplemented4\n"); }; - /** - * Function DeviceToLogical - * converts \a aRect from device to drawing (logical) coordinates. - *

- * \a aRect must be in scrolled device units. - *

- * @param aRect The rectangle to convert. - * @param aDC The device context used for the conversion. - * @return A rectangle converted to drawing units. - */ - virtual wxRect DeviceToLogical( const wxRect& aRect, wxDC& aDC ) { printf("EDA_DRAW_PANEL:Unimplemented5\n");wxASSERT(false); return wxRect(); }; - /* Mouse and keys events */ /** @@ -295,84 +239,6 @@ public: */ virtual void MoveCursor( const wxPoint& aPosition ) { printf("EDA_DRAW_PANEL:Unimplemented17\n"); };; - /* Cursor functions */ - /** - * Function DrawCrossHair - * draws the user cross hair. - *

- * The user cross hair is not the mouse cursor although they may be at the same screen - * position. The mouse cursor is still render by the OS. This is a drawn cross hair - * that is used to snap to grid when grid snapping is enabled. This is as an indicator - * to where the next user action will take place. - *

- * @param aDC - the device context to draw the cursor - * @param aColor - the color to draw the cursor - */ - virtual void DrawCrossHair( wxDC* aDC=nullptr, COLOR4D aColor = COLOR4D::WHITE ) { printf("EDA_DRAW_PANEL:Unimplemented18\n"); };; - - // Hide the cross hair. - virtual void CrossHairOff( wxDC* DC=nullptr ) { printf("EDA_DRAW_PANEL:Unimplemented19\n"); };; - - // Show the cross hair. - virtual void CrossHairOn( wxDC* DC=nullptr ) { printf("EDA_DRAW_PANEL:Unimplemented20\n"); };; - - /** - * Function SetMouseCapture - * sets the mouse capture and end mouse capture callbacks to \a aMouseCaptureCallback - * and \a aEndMouseCaptureCallback respectively. - */ - virtual void SetMouseCapture( MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback, - END_MOUSE_CAPTURE_CALLBACK aEndMouseCaptureCallback ) - { - m_mouseCaptureCallback = aMouseCaptureCallback; - m_endMouseCaptureCallback = aEndMouseCaptureCallback; - } - - - virtual void SetMouseCaptureCallback( MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback ) - { - m_mouseCaptureCallback = aMouseCaptureCallback; - } - - - /** - * Function EndMouseCapture - * ends mouse a capture. - * - * Check to see if the cursor is being managed for block or editing commands and release it. - * @param aId The command ID to restore or -1 to keep the current command ID. - * @param aCursorId The wxWidgets stock cursor ID to set the cursor to or -1 to keep the - * current cursor. - * @param aTitle The tool message to display in the status bar or wxEmptyString to clear - * the message. - * @param aCallEndFunc Call the abort mouse capture callback if true. - */ - virtual void EndMouseCapture( int aId = -1, int aCursorId = -1, - const wxString& aTitle = wxEmptyString, - bool aCallEndFunc = true ) { printf("EDA_DRAW_PANEL:Unimplemented21\n"); wxASSERT(false); };; - - inline bool IsMouseCaptured() const { return m_mouseCaptureCallback != NULL; } - - /** - * Function CallMouseCapture - * calls the mouse capture callback. - * - * @param aDC A point to a wxDC object to perform any drawing upon. - * @param aPosition A referecnce to a wxPoint object containing the current cursor - * position. - * @param aErase True indicates the item being drawn should be erase before drawing - * it a \a aPosition. - */ - virtual void CallMouseCapture( wxDC* aDC, const wxPoint& aPosition, bool aErase ) { printf("EDA_DRAW_PANEL:Unimplemented22\n"); wxASSERT(false); };; - - /** - * Function CallEndMouseCapture - * calls the end mouse capture callback. - * - * @param aDC A point to a wxDC object to perform any drawing upon. - */ - virtual void CallEndMouseCapture( wxDC* aDC ) { printf("EDA_DRAW_PANEL:Unimplemented23\n"); wxASSERT(false); };; - virtual void Refresh( bool eraseBackground = true, const wxRect* rect = NULL ) {} virtual wxWindow* GetWindow() = 0; diff --git a/include/painter.h b/include/painter.h index 4c66f9a559..4fdb5eebdc 100644 --- a/include/painter.h +++ b/include/painter.h @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include @@ -64,7 +64,7 @@ public: * Loads a list of color settings for layers. * @param aSettings is a list of color settings. */ - virtual void ImportLegacyColors( const COLORS_DESIGN_SETTINGS* aSettings ) = 0; + virtual void ImportLegacyColors( const COLORS_DESIGN_SETTINGS* aSettings ) { } /** * Function SetActiveLayer diff --git a/include/pcb_base_frame.h b/include/pcb_base_frame.h index 919429c226..41914dfac5 100644 --- a/include/pcb_base_frame.h +++ b/include/pcb_base_frame.h @@ -200,9 +200,6 @@ public: virtual void OnCloseWindow( wxCloseEvent& Event ) = 0; virtual void RedrawActiveWindow( wxDC* DC, bool EraseBg ) override { } virtual void ReCreateOptToolbar() { } - virtual void OnLeftClick( wxDC* DC, const wxPoint& MousePos ) override = 0; - virtual void OnLeftDClick( wxDC* DC, const wxPoint& MousePos ) override = 0; - virtual bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ) override = 0; virtual void ShowChangedLanguage() override; virtual void ReCreateMenuBar() override; virtual void SetToolID( int aId, int aCursor, const wxString& aToolMsg ) override; diff --git a/common/tool/edit_constraints.h b/include/tool/edit_constraints.h similarity index 100% rename from common/tool/edit_constraints.h rename to include/tool/edit_constraints.h diff --git a/common/tool/edit_points.h b/include/tool/edit_points.h similarity index 100% rename from common/tool/edit_points.h rename to include/tool/edit_points.h diff --git a/include/tool/selection.h b/include/tool/selection.h index 7180479cfd..9ab99e9d35 100644 --- a/include/tool/selection.h +++ b/include/tool/selection.h @@ -142,7 +142,6 @@ public: EDA_RECT GetBoundingBox() const; EDA_ITEM* GetTopLeftItem( bool onlyModules = false ) const; - EDA_ITEM* GetTopLeftModule() const; EDA_ITEM* operator[]( const size_t aIdx ) const { diff --git a/include/worksheet.h b/include/worksheet.h deleted file mode 100644 index 15f6c9183f..0000000000 --- a/include/worksheet.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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. - * - * 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 - */ - -// For page and paper size, values are in 1/1000 inch - -#ifndef WORKSHEET_H_ -#define WORKSHEET_H_ - -#include -#include - -// Forward declarations: -class EDA_DRAW_PANEL; -class EDA_RECT; -class TITLE_BLOCK; - -using KIGFX::COLOR4D; - -/** - * Function DrawPageLayout is a core function to draw the page layout with - * the frame and the basic inscriptions. - * @param aDC The device context. - * @param aClipBox = the clipping rect, or NULL if no clipping. - * @param aPageInfo for margins and page size (in mils). - * @param aFullSheetName The sheetpath (full sheet name), for basic inscriptions. - * @param aFileName The file name, for basic inscriptions. - * @param aTitleBlock The sheet title block, for basic inscriptions. - * @param aSheetCount The number of sheets (for basic inscriptions). - * @param aSheetNumber The sheet number (for basic inscriptions). - * @param aPenWidth the pen size The line width for drawing. - * @param aScalar the scale factor to convert from mils to internal units. - * @param aColor The color for drawing. - * @param aAltColor The color for items which need to be "hightlighted". - * @param aSheetLayer The layer from pcbnew. - * - * Parameters used in aPageInfo - * - the size of the page layout. - * - the LTmargin The left top margin of the page layout. - * - the RBmargin The right bottom margin of the page layout. - */ -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 = wxEmptyString ); - - -#endif // WORKSHEET_H_ diff --git a/include/worksheet_dataitem.h b/include/worksheet_dataitem.h index 5b31feeae2..4268e3e76a 100644 --- a/include/worksheet_dataitem.h +++ b/include/worksheet_dataitem.h @@ -33,33 +33,17 @@ #include #include #include +#include +#include "ws_draw_item.h" class WS_DRAW_ITEM_TEXT; // Forward declaration #define TB_DEFAULT_TEXTSIZE 1.5 // default worksheet text size in mm -// Text attributes set in m_flags (ORed bits) -#define USE_BOLD 1 // has meaning for texts -#define USE_THICK_LINE 1 // equivalent to bold for lines -#define USE_ITALIC (1<<1) // has meaning for texts -#define USE_ALT_COLOR (1<<2) -#define SELECTED_STATE (1<<3) // When set, use the hight light color to draw item -#define NEW_ITEM (1<<4) // Set for new items which can be deleted - // by an abort command -#define LOCATE_STARTPOINT (1<<5) // Used in locate function:set by locate function - // if the start point is located -#define LOCATE_ENDPOINT (1<<6) // Used in locate function:set by locate function - // if the end point is located -#define PAGE1OPTION (3<<7) // flag to manage items drawn or not drawn only - // on page 1: NONE = item on all pages -#define PAGE1OPTION_NONE (0<<7) // NONE = item on all pages -#define PAGE1OPTION_PAGE1ONLY (1<<7) // = item only on page 1 -#define PAGE1OPTION_NOTONPAGE1 (2<<7) // = item on all pages but page 1 - // A coordinate is relative to a page corner. // Any of the 4 corners can be a reference. // The default is the right bottom corner -enum corner_anchor +enum CORNER_ANCHOR { RB_CORNER, // right bottom corner RT_CORNER, // right top corner @@ -67,6 +51,13 @@ enum corner_anchor LT_CORNER, // left top corner }; +enum PAGE_OPTION +{ + ALL_PAGES, + FIRST_PAGE_ONLY, + SUBSEQUENT_PAGES +}; + // a coordinate point // The position is always relative to the corner anchor // Note the coordinate is from the anchor point @@ -78,7 +69,8 @@ public: int m_Anchor; public: POINT_COORD() { m_Anchor = RB_CORNER; } - POINT_COORD( DPOINT aPos, enum corner_anchor aAnchor = RB_CORNER ) + + POINT_COORD( DPOINT aPos, enum CORNER_ANCHOR aAnchor = RB_CORNER ) { m_Pos = aPos; m_Anchor = aAnchor; @@ -96,7 +88,7 @@ public: class WORKSHEET_DATAITEM { public: - enum WS_ItemType { + enum WS_ITEM_TYPE { WS_TEXT, WS_SEGMENT, WS_RECT, @@ -105,8 +97,10 @@ public: }; protected: - WS_ItemType m_type; - int m_flags; + WS_ITEM_TYPE m_type; + PAGE_OPTION m_pageOption; + + std::vector m_drawItems; public: wxString m_Name; // a item name used in page layout @@ -140,25 +134,23 @@ public: static bool m_SpecialMode; // Used in page layout editor // When set to true, base texts // instead of full texts are displayed - static COLOR4D m_Color; // the default color to draw items - static COLOR4D m_AltColor; // an alternate color to draw items - static COLOR4D m_SelectedColor; // the color to draw selected items - // (used in page layout editor - - public: - WORKSHEET_DATAITEM( WS_ItemType aType ); + WORKSHEET_DATAITEM( WS_ITEM_TYPE aType ); virtual ~WORKSHEET_DATAITEM() {} - void SetStart( double aPosx, double aPosy, enum corner_anchor aAnchor = RB_CORNER ) + const std::vector& GetDrawItems() const { return m_drawItems; } + + virtual void SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView ); + + void SetStart( double aPosx, double aPosy, enum CORNER_ANCHOR aAnchor = RB_CORNER ) { m_Pos.m_Pos.x = aPosx; m_Pos.m_Pos.y = aPosy; m_Pos.m_Anchor = aAnchor; } - void SetEnd( double aPosx, double aPosy, enum corner_anchor aAnchor = RB_CORNER ) + void SetEnd( double aPosx, double aPosy, enum CORNER_ANCHOR aAnchor = RB_CORNER ) { m_End.m_Pos.x = aPosx; m_End.m_Pos.y = aPosy; @@ -166,10 +158,7 @@ public: } // Accessors: - WS_ItemType GetType() const { return m_type; } - int GetFlags() const { return m_flags; } - void SetFlags( int aMask ) { m_flags |= aMask; } - void ClearFlags( int aMask ) { m_flags &= ~aMask; } + WS_ITEM_TYPE GetType() const { return m_type; } /** * @return true if the item has a end point (segment; rect) @@ -177,20 +166,8 @@ public: */ virtual bool HasEndPoint() { return true; } - /** - * @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 GetPage1Option(); - - /** - * Set the option for page 1 - * @param 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 SetPage1Option( int aChoice ); + PAGE_OPTION GetPage1Option() const { return m_pageOption; } + void SetPage1Option( PAGE_OPTION aChoice ) { m_pageOption = aChoice; } // Coordinate handling const wxPoint GetStartPosUi( int ii = 0 ) const; @@ -205,17 +182,6 @@ public: return KiROUND( m_DefaultLineWidth * m_WSunits2Iu ); } - /** @return the size of markers used in page layout editor to draw - * the anchor points of selected items. - * @param aZoomScale is a scaling factor that can be used to adjust - * the final marker size depending on zoom level - */ - static int GetMarkerSizeUi( double aZoomScale = 1.0 ) - { - #define MARKER_DRAW_SIZE 0.5 // Is a value choosen for a suitable size on screen - return KiROUND( MARKER_DRAW_SIZE * m_WSunits2Iu * aZoomScale ); - } - /** * move item to a new position * @param aPosition = the new position of item, in mm @@ -264,54 +230,25 @@ public: virtual bool IsInsidePage( int ii ) const; const wxString GetClassName() const; - - /** - * @return true if the selected state on ON - */ - bool IsSelected() { return (m_flags & SELECTED_STATE) != 0; } - - /** - * Function SetSelected - * Toggles on/off the selected flag (used in editing functions) - * @param aState = the flag value - */ - void SetSelected( bool aState ) - { - if( aState ) - m_flags |= SELECTED_STATE; - else - m_flags &= ~SELECTED_STATE; - } - - bool UseAltColor() {return m_flags & USE_ALT_COLOR; } - - COLOR4D GetItemColor() - { - if( IsSelected() ) - return m_SelectedColor; - - if( UseAltColor() ) - return m_AltColor; - - return m_Color; - } }; class WORKSHEET_DATAITEM_POLYPOLYGON : public WORKSHEET_DATAITEM { public: - double m_Orient; // Orientation in degrees - std::vector m_Corners; // corner list + double m_Orient; // Orientation in degrees + std::vector m_Corners; // corner list private: std::vector m_polyIndexEnd; // index of the last point of each polygon - DPOINT m_minCoord; // min coord of corners, relative to m_Pos - DPOINT m_maxCoord; // max coord of corners, relative to m_Pos + DPOINT m_minCoord; // min coord of corners, relative to m_Pos + DPOINT m_maxCoord; // max coord of corners, relative to m_Pos public: WORKSHEET_DATAITEM_POLYPOLYGON( ); + void SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView ) override; + virtual int GetPenSizeUi() override { return KiROUND( m_LineWidth * m_WSunits2Iu ); @@ -395,6 +332,8 @@ public: double m_Orient; // Orientation in degrees EDA_TEXT_HJUSTIFY_T m_Hjustify; EDA_TEXT_VJUSTIFY_T m_Vjustify; + bool m_Italic; + bool m_Bold; DSIZE m_TextSize; DSIZE m_BoundingBoxSize; // When not null, this is the max // size of the full text. @@ -408,6 +347,8 @@ public: public: WORKSHEET_DATAITEM_TEXT( const wxString& aTextBase ); + void SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView ) override; + /** * @return false (no end point) */ @@ -427,12 +368,6 @@ public: */ void MoveTo( DPOINT aPosition ); - /** - * transfert the text justification and orientation - * to aGText - */ - void TransfertSetupToGraphicText( WS_DRAW_ITEM_TEXT* aGText ); - /** * Try to build text wihich is an increment of m_TextBase * has meaning only if m_TextBase is a basic text (one char) @@ -461,42 +396,6 @@ public: * @return true if the EOL symbol is found or is inserted (multiline text) */ bool ReplaceAntiSlashSequence(); - - /** - * @return true is a bold font should be selected - */ - bool IsBold() { return (m_flags & USE_BOLD) != 0; } - - /** - * Function SetBold - * Toggles on/off the bold option flag - * @param aState = the bold option value - */ - void SetBold( bool aState ) - { - if( aState ) - m_flags |= USE_BOLD; - else - m_flags &= ~USE_BOLD; - } - - /** - * @return true is an italic font should be selected - */ - bool IsItalic() const { return (m_flags & USE_ITALIC) != 0; } - - /** - * Function SetItalic - * Toggles on/off the italic option flag - * @param aState = the italic option value - */ - void SetItalic( bool aState ) - { - if( aState ) - m_flags |= USE_ITALIC; - else - m_flags &= ~USE_ITALIC; - } }; @@ -513,6 +412,8 @@ public: m_ImageBitmap = aImage; } + void SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView ) override; + /** * @return false (no end point) */ diff --git a/include/worksheet_painter.h b/include/worksheet_painter.h new file mode 100644 index 0000000000..f0ab32ef7a --- /dev/null +++ b/include/worksheet_painter.h @@ -0,0 +1,167 @@ +/* + * 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. + * + * 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 + */ + +// For page and paper size, values are in 1/1000 inch + +#ifndef WORKSHEET_PAINTER_H +#define WORKSHEET_PAINTER_H + +#include +#include +#include + +// Forward declarations: +class EDA_DRAW_PANEL; +class EDA_RECT; +class TITLE_BLOCK; + +using KIGFX::COLOR4D; + +namespace KIGFX +{ + +/** + * Class WS_RENDER_SETTINGS + * Stores page-layout-specific render settings. + */ +class WS_RENDER_SETTINGS : public RENDER_SETTINGS +{ +public: + friend class WORKSHEET_PAINTER; + + WS_RENDER_SETTINGS(); + + /// @copydoc RENDER_SETTINGS::GetColor() + virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const override; + + inline bool IsBackgroundDark() const override + { + auto luma = m_backgroundColor.GetBrightness(); + return luma < 0.5; + } + + const COLOR4D& GetBackgroundColor() override { return m_backgroundColor; } + void SetBackgroundColor( const COLOR4D& aColor ) override { m_backgroundColor = aColor; } + + void SetNormalColor( const COLOR4D& aColor ) { m_normalColor = aColor; } + void SetSelectedColor( const COLOR4D& aColor ) { m_selectedColor = aColor; } + void SetBrightenedColor( const COLOR4D& aColor ) { m_brightenedColor = aColor; } + + const COLOR4D& GetGridColor() override + { + m_gridColor = IsBackgroundDark() ? DARKGRAY : LIGHTGRAY; + return m_gridColor; + } + + const COLOR4D& GetCursorColor() override + { + m_cursorColor = IsBackgroundDark() ? WHITE : BLACK; + return m_cursorColor; + } + +private: + COLOR4D m_normalColor; + COLOR4D m_selectedColor; + COLOR4D m_brightenedColor; + + COLOR4D m_gridColor; + COLOR4D m_cursorColor; +}; + + +/** + * Class WORKSHEET_PAINTER + * Contains methods for drawing worksheet items. + */ +class WORKSHEET_PAINTER : public PAINTER +{ +public: + WORKSHEET_PAINTER( GAL* aGal ) : + PAINTER( aGal ) + { } + + /// @copydoc PAINTER::Draw() + virtual bool Draw( const VIEW_ITEM*, int ) override; + + void DrawBorder( const PAGE_INFO* aPageInfo, int aScaleFactor ) const; + + /// @copydoc PAINTER::ApplySettings() + virtual void ApplySettings( const RENDER_SETTINGS* aSettings ) override + { + m_renderSettings = *static_cast( aSettings ); + } + + /// @copydoc PAINTER::GetSettings() + virtual RENDER_SETTINGS* GetSettings() override { return &m_renderSettings; } + +private: + void draw( const WS_DRAW_ITEM_LINE* aItem, int aLayer ) const; + void draw( const WS_DRAW_ITEM_RECT* aItem, int aLayer ) const; + void draw( const WS_DRAW_ITEM_POLYGON* aItem, int aLayer ) const; + void draw( const WS_DRAW_ITEM_TEXT* aItem, int aLayer ) const; + void draw( const WS_DRAW_ITEM_BITMAP* aItem, int aLayer ) const; + +private: + WS_RENDER_SETTINGS m_renderSettings; +}; + +} // namespace KIGFX + + +/** + * Function DrawPageLayout is a core function to draw the page layout with + * the frame and the basic inscriptions. + * @param aDC The device context. + * @param aClipBox = the clipping rect, or NULL if no clipping. + * @param aPageInfo for margins and page size (in mils). + * @param aFullSheetName The sheetpath (full sheet name), for basic inscriptions. + * @param aFileName The file name, for basic inscriptions. + * @param aTitleBlock The sheet title block, for basic inscriptions. + * @param aSheetCount The number of sheets (for basic inscriptions). + * @param aSheetNumber The sheet number (for basic inscriptions). + * @param aPenWidth the pen size The line width for drawing. + * @param aScalar the scale factor to convert from mils to internal units. + * @param aColor The color for drawing. + * @param aAltColor The color for items which need to be "hightlighted". + * @param aSheetLayer The layer from pcbnew. + * + * Parameters used in aPageInfo + * - the size of the page layout. + * - the LTmargin The left top margin of the page layout. + * - the RBmargin The right bottom margin of the page layout. + */ +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, + const wxString& aSheetLayer = wxEmptyString ); + + +#endif // WORKSHEET_PAINTER_H diff --git a/include/worksheet_viewitem.h b/include/worksheet_viewitem.h index c2edb866d8..a1d11fbfa4 100644 --- a/include/worksheet_viewitem.h +++ b/include/worksheet_viewitem.h @@ -158,16 +158,6 @@ protected: /// Sheets count number displayed in the title block. int m_sheetCount; - - // Functions for drawing items that makes a worksheet - void draw( const WS_DRAW_ITEM_LINE* aItem, GAL* aGal ) const; - void draw( const WS_DRAW_ITEM_RECT* aItem, GAL* aGal ) const; - void draw( const WS_DRAW_ITEM_POLYGON* aItem, GAL* aGal ) const; - void draw( const WS_DRAW_ITEM_TEXT* aItem, GAL* aGal ) const; - void draw( const WS_DRAW_ITEM_BITMAP* aItem, GAL* aGal ) const; - - /// Draws a border that determines the page size. - void drawBorder( GAL* aGal ) const; }; } diff --git a/include/worksheet_shape_builder.h b/include/ws_draw_item.h similarity index 58% rename from include/worksheet_shape_builder.h rename to include/ws_draw_item.h index a9418b4667..9d7319571a 100644 --- a/include/worksheet_shape_builder.h +++ b/include/ws_draw_item.h @@ -22,117 +22,84 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file worksheet_shape_builder.h - * @brief classes and function to generate graphics to plt or draw titles blocks - * and frame references - */ - -#ifndef WORKSHEET_SHAPE_BUILDER_H -#define WORKSHEET_SHAPE_BUILDER_H +#ifndef WS_DRAW_ITEM_H +#define WS_DRAW_ITEM_H #include #include #include #include +#include "msgpanel.h" -class WORKSHEET_DATAITEM; // Forward declaration +class WORKSHEET_DATAITEM; class TITLE_BLOCK; class PAGE_INFO; #define TB_DEFAULT_TEXTSIZE 1.5 // default worksheet text size in mm /* - * Helper classes to handle basic graphic items used to raw/plot + * Helper classes to handle basic graphic items used to draw/plot * title blocks and frame references * segments * rect * polygons (for logos) * graphic texts - * bitmaps, also for logos, but they cannot be plot by SVG, GERBER - * and HPGL plotters (In this case, only the bounding box is plotted) + * bitmaps, also for logos, but they cannot be plot by SVG, GERBER or HPGL plotters (in + * which case only the bounding box is plotted) */ -class WS_DRAW_ITEM_BASE // This basic class, not directly usable. +class WS_DRAW_ITEM_BASE : public EDA_ITEM // This basic class, not directly usable. { -public: - enum WS_DRAW_TYPE { - wsg_line, wsg_rect, wsg_poly, wsg_text, wsg_bitmap - }; - int m_Flags; // temporary flgs used in page layout editor - // to locate the item; - protected: - WS_DRAW_TYPE m_type; // wsg_line, wsg_rect, wsg_poly, wsg_text - COLOR4D m_color; - WORKSHEET_DATAITEM* m_parent; // an unique identifier, used as link + WORKSHEET_DATAITEM* m_peer; // an unique identifier, used as link // to the parent WORKSHEET_DATAITEM item, // in page layout editor - WS_DRAW_ITEM_BASE( WORKSHEET_DATAITEM* aParent, - WS_DRAW_TYPE aType, COLOR4D aColor ) + WS_DRAW_ITEM_BASE( WORKSHEET_DATAITEM* aPeer, KICAD_T aType ) : + EDA_ITEM( aType ) { - m_type = aType; - m_color = aColor; - m_parent = aParent; + m_peer = aPeer; m_Flags = 0; } public: virtual ~WS_DRAW_ITEM_BASE() {} - // Accessors: - COLOR4D GetColor() const { return m_color; } - WS_DRAW_TYPE GetType() const { return m_type; }; + WORKSHEET_DATAITEM* GetPeer() const { return m_peer; } - WORKSHEET_DATAITEM* GetParent() const { return m_parent; } + virtual const wxPoint GetPosition() const = 0; + virtual void SetPosition( wxPoint aPos ) = 0; + virtual void SetEnd( wxPoint aPos ) { /* not all types will need this */ } /** The function to draw a WS_DRAW_ITEM */ - virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC) + virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, COLOR4D aColor ) { wxPoint offset( 0, 0 ); - DrawWsItem( aClipBox, aDC, offset, UNSPECIFIED_DRAWMODE, COLOR4D::UNSPECIFIED ); + DrawWsItem( aClipBox, aDC, offset, UNSPECIFIED_DRAWMODE, aColor ); } /// More advanced version of DrawWsItem. This is what must be /// defined in the derived type. virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset, - GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) = 0; + GR_DRAWMODE aDrawMode, COLOR4D aColor ) = 0; + + bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override + { + // This is just here to prevent annoying compiler warnings about hidden overloaded + // virtual functions + return EDA_ITEM::HitTest( aPosition, aAccuracy ); + } /** - * Abstract function: should exist for derived items - * return true if the point aPosition is on the item - */ - virtual bool HitTest( const wxPoint& aPosition) const = 0; - - /** - * Abstract function: should exist for derived items + * Virtual function * return true if the rect aRect intersects on the item */ - virtual bool HitTest( const EDA_RECT& aRect ) const = 0; + bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override; - /** - * Abstract function: should exist for derived items - * return true if the point aPosition is near the starting point of this item, - * for items defined by 2 points (segments, rect) - * or the position of the item, for items having only one point - * (texts or polygons) - * the maxi dist is WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 - */ - virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) = 0; - - /** - * return true if the point aPosition is near the ending point of this item - * This is avirtual function which should be overriden for items defien by - * 2 points - * the maxi dist is WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 - */ - virtual bool HitTestEndPoint( wxDC *aDC, const wxPoint& aPosition) - { - return false; - } + void GetMsgPanelInfo( EDA_UNITS_T aUnits, MSG_PANEL_ITEMS& aList ) override; }; + // This class draws a thick segment class WS_DRAW_ITEM_LINE : public WS_DRAW_ITEM_BASE { @@ -141,49 +108,42 @@ class WS_DRAW_ITEM_LINE : public WS_DRAW_ITEM_BASE int m_penWidth; public: - WS_DRAW_ITEM_LINE( WORKSHEET_DATAITEM* aParent, - wxPoint aStart, wxPoint aEnd, - int aPenWidth, COLOR4D aColor ) : - WS_DRAW_ITEM_BASE( aParent, wsg_line, aColor ) + WS_DRAW_ITEM_LINE( WORKSHEET_DATAITEM* aPeer, wxPoint aStart, wxPoint aEnd, int aPenWidth ) : + WS_DRAW_ITEM_BASE( aPeer, WSG_LINE_T ) { m_start = aStart; m_end = aEnd; m_penWidth = aPenWidth; } + virtual wxString GetClass() const override { return wxT( "WS_DRAW_ITEM_LINE" ); } + // Accessors: int GetPenWidth() const { return m_penWidth; } const wxPoint& GetStart() const { return m_start; } + void SetStart( wxPoint aPos ) { m_start = aPos; } const wxPoint& GetEnd() const { return m_end; } + void SetEnd( wxPoint aPos ) override { m_end = aPos; } + + const wxPoint GetPosition() const override { return GetStart(); } + void SetPosition( wxPoint aPos ) override { SetStart( aPos ); } /** The function to draw a WS_DRAW_ITEM_LINE */ - virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset, - GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) override; + void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset, GR_DRAWMODE aDrawMode, + COLOR4D aColor ) override; /** * Virtual function * return true if the point aPosition is on the line */ - virtual bool HitTest( const wxPoint& aPosition) const override; + bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override; - /** - * Virtual function - * return true if the rect aRect intersects on the item - */ - virtual bool HitTest( const EDA_RECT& aRect ) const override; + wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override; - /** - * return true if the point aPosition is on the starting point of this item. - */ - virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) override; - - /** - * return true if the point aPosition is on the ending point of this item - * This is avirtual function which should be overriden for items defien by - * 2 points - */ - virtual bool HitTestEndPoint( wxDC *aDC, const wxPoint& aPosition ) override; +#if defined(DEBUG) + void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } +#endif }; // This class draws a polygon @@ -199,83 +159,90 @@ public: std::vector m_Corners; public: - WS_DRAW_ITEM_POLYGON( WORKSHEET_DATAITEM* aParent, wxPoint aPos, - bool aFill, int aPenWidth, COLOR4D aColor ) : - WS_DRAW_ITEM_BASE( aParent, wsg_poly, aColor ) + WS_DRAW_ITEM_POLYGON( WORKSHEET_DATAITEM* aPeer, wxPoint aPos, bool aFill, int aPenWidth ) : + WS_DRAW_ITEM_BASE( aPeer, WSG_POLY_T ) { m_penWidth = aPenWidth; m_fill = aFill; m_pos = aPos; } + virtual wxString GetClass() const override { return wxT( "WS_DRAW_ITEM_POLYGON" ); } + // Accessors: int GetPenWidth() const { return m_penWidth; } bool IsFilled() const { return m_fill; } - const wxPoint GetPosition() const { return m_pos; } + const wxPoint GetPosition() const override { return m_pos; } + void SetPosition( wxPoint aPos ) override { m_pos = aPos; } /** The function to draw a WS_DRAW_ITEM_POLYGON */ - virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset, - GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) override; + void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset, GR_DRAWMODE aDrawMode, + COLOR4D aColor ) override; /** * Virtual function * return true if the point aPosition is inside one polygon */ - virtual bool HitTest( const wxPoint& aPosition) const override; + bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override; /** * Virtual function * return true if the rect aRect intersects on the item */ - virtual bool HitTest( const EDA_RECT& aRect ) const override; + bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override; - /** - * return true if the point aPosition is on the starting point of this item. - */ - virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) override; + wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override; + +#if defined(DEBUG) + void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } +#endif }; // This class draws a not filled rectangle with thick segment -class WS_DRAW_ITEM_RECT : public WS_DRAW_ITEM_LINE +class WS_DRAW_ITEM_RECT : public WS_DRAW_ITEM_BASE { + wxPoint m_start; // start point of line/rect + wxPoint m_end; // end point + int m_penWidth; + public: - WS_DRAW_ITEM_RECT( WORKSHEET_DATAITEM* aParent, - wxPoint aStart, wxPoint aEnd, - int aPenWidth, COLOR4D aColor ) : - WS_DRAW_ITEM_LINE( aParent, aStart, aEnd, aPenWidth, aColor ) + WS_DRAW_ITEM_RECT( WORKSHEET_DATAITEM* aPeer, wxPoint aStart, wxPoint aEnd, int aPenWidth ) : + WS_DRAW_ITEM_BASE( aPeer, WSG_RECT_T ) { - m_type = wsg_rect; + m_start = aStart; + m_end = aEnd; + m_penWidth = aPenWidth; } + virtual wxString GetClass() const override { return wxT( "WS_DRAW_ITEM_RECT" ); } + + // Accessors: + int GetPenWidth() const { return m_penWidth; } + const wxPoint& GetStart() const { return m_start; } + void SetStart( wxPoint aPos ) { m_start = aPos; } + const wxPoint& GetEnd() const { return m_end; } + void SetEnd( wxPoint aPos ) override { m_end = aPos; } + + const wxPoint GetPosition() const override { return GetStart(); } + void SetPosition( wxPoint aPos ) override { SetStart( aPos ); } + /** The function to draw a WS_DRAW_ITEM_RECT */ - virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset, - GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) override; + void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset, GR_DRAWMODE aDrawMode, + COLOR4D aColor ) override; /** * Virtual function * return true if the point aPosition is on one edge of the rectangle */ - virtual bool HitTest( const wxPoint& aPosition) const override; + bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override; - /** - * Virtual function - * return true if the rect aRect intersects on the item - */ - virtual bool HitTest( const EDA_RECT& aRect ) const override; + wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override; - /** - * return true if the point aPosition is on the starting point of this item. - */ - virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) override; - - /** - * return true if the point aPosition is on the ending point of this item - * This is avirtual function which should be overriden for items defien by - * 2 points - */ - virtual bool HitTestEndPoint( wxDC *aDC, const wxPoint& aPosition ) override; +#if defined(DEBUG) + void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } +#endif }; // This class draws a graphic text. @@ -284,15 +251,24 @@ public: class WS_DRAW_ITEM_TEXT : public WS_DRAW_ITEM_BASE, public EDA_TEXT { public: - WS_DRAW_ITEM_TEXT( WORKSHEET_DATAITEM* aParent, - wxString& aText, wxPoint aPos, wxSize aSize, - int aPenWidth, COLOR4D aColor, - bool aItalic = false, bool aBold = false ); + WS_DRAW_ITEM_TEXT( WORKSHEET_DATAITEM* aPeer, wxString& aText, wxPoint aPos, wxSize aSize, + int aPenWidth, bool aItalic = false, bool aBold = false ) : + WS_DRAW_ITEM_BASE( aPeer, WSG_TEXT_T), + EDA_TEXT( aText ) + { + SetTextPos( aPos ); + SetTextSize( aSize ); + SetThickness( aPenWidth ); + SetItalic( aItalic ); + SetBold( aBold ); + } + + virtual wxString GetClass() const override { return wxT( "WS_DRAW_ITEM_TEXT" ); } /** The function to draw a WS_DRAW_ITEM_TEXT */ - virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset, - GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) override; + void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset, GR_DRAWMODE aDrawMode, + COLOR4D aColor ) override; // Accessors: int GetPenWidth() { return GetThickness(); } @@ -302,22 +278,26 @@ public: EDA_TEXT::SetTextAngle( NormalizeAngle360Min( aAngle ) ); } + const wxPoint GetPosition() const override { return GetTextPos(); } + void SetPosition( wxPoint aPos ) override { SetTextPos( aPos ); } + /** * Virtual function - * return true if the point aPosition is on the text + * return true if the point aPosition is inside one polygon */ - virtual bool HitTest( const wxPoint& aPosition) const override; + bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override; /** * Virtual function * return true if the rect aRect intersects on the item */ - virtual bool HitTest( const EDA_RECT& aRect ) const override; + bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override; - /** - * return true if the point aPosition is on the starting point of this item. - */ - virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) override; + wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override; + +#if defined(DEBUG) + void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } +#endif }; // This class draws a bitmap. @@ -326,42 +306,36 @@ class WS_DRAW_ITEM_BITMAP : public WS_DRAW_ITEM_BASE wxPoint m_pos; // position of reference point public: - WS_DRAW_ITEM_BITMAP( WORKSHEET_DATAITEM* aParent, wxPoint aPos ) - :WS_DRAW_ITEM_BASE( aParent, wsg_bitmap, COLOR4D::UNSPECIFIED ) + WS_DRAW_ITEM_BITMAP( WORKSHEET_DATAITEM* aPeer, wxPoint aPos ) : + WS_DRAW_ITEM_BASE( aPeer, WSG_BITMAP_T ) { m_pos = aPos; } - WS_DRAW_ITEM_BITMAP() - :WS_DRAW_ITEM_BASE( NULL, wsg_bitmap, COLOR4D::UNSPECIFIED ) + WS_DRAW_ITEM_BITMAP() : + WS_DRAW_ITEM_BASE( nullptr, WSG_BITMAP_T ) { } ~WS_DRAW_ITEM_BITMAP() {} + virtual wxString GetClass() const override { return wxT( "WS_DRAW_ITEM_BITMAP" ); } + + const wxPoint GetPosition() const override { return m_pos; } + void SetPosition( wxPoint aPos ) override { m_pos = aPos; } + /** The function to draw a WS_DRAW_ITEM_BITMAP */ - virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset, - GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) override; + void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset, GR_DRAWMODE aDrawMode, + COLOR4D aColor ) override; - /** - * Virtual function - * return true if the point aPosition is on bitmap - */ - virtual bool HitTest( const wxPoint& aPosition) const override; + const EDA_RECT GetBoundingBox() const override; - /** - * Virtual function - * return true if the rect aRect intersects on the item - */ - virtual bool HitTest( const EDA_RECT& aRect ) const override; + wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override; - /** - * return true if the point aPosition is on the reference point of this item. - */ - virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) override; - - const wxPoint GetPosition() const { return m_pos; } +#if defined(DEBUG) + void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } +#endif }; /* @@ -375,9 +349,6 @@ class WS_DRAW_ITEM_LIST protected: std::vector m_graphicList; // Items to draw/plot unsigned m_idx; // for GetFirst, GetNext functions - wxPoint m_LTmargin; // The left top margin in mils of the page layout. - wxPoint m_RBmargin; // The right bottom margin in mils of the page layout. - wxSize m_pageSize; // the page size in mils double m_milsToIu; // the scalar to convert pages units ( mils) // to draw/plot units. int m_penSize; // The default line width for drawings. @@ -407,13 +378,13 @@ public: ~WS_DRAW_ITEM_LIST() { - for( unsigned ii = 0; ii < m_graphicList.size(); ii++ ) - delete m_graphicList[ii]; + // Items in the m_graphicList are owned by their respective WORKSHEET_DATAITEMs. + // for( WS_DRAW_ITEM_BASE* item : m_graphicList ) + // delete item; } /** * Set the filename to draw/plot - * @param aFileName = the text to display by the "filename" format */ void SetFileName( const wxString& aFileName ) { @@ -422,7 +393,6 @@ public: /** * Set the sheet name to draw/plot - * @param aSheetName = the text to draw/plot by the "sheetname" format */ void SetSheetName( const wxString& aSheetName ) { @@ -431,44 +401,27 @@ public: /** * Set the sheet layer to draw/plot - * @param aSheetLayer = the text to draw/plot by the "sheetlayer" format */ void SetSheetLayer( const wxString& aSheetLayer ) { m_sheetLayer = &aSheetLayer; } - /** Function SetPenSize - * Set the default pen size to draw/plot lines and texts - * @param aPenSize the thickness of lines - */ - void SetPenSize( int aPenSize ) - { - m_penSize = aPenSize; - } + void SetDefaultPenSize( int aPenSize ) { m_penSize = aPenSize; } + int GetDefaultPenSize() const { return m_penSize; } - /** Function SetMilsToIUfactor - * Set the scalar to convert pages units ( mils) to draw/plot units - * @param aScale the conversion factor + /** + * Function SetMilsToIUfactor + * Set the scalar to convert pages units (mils) to draw/plot units */ void SetMilsToIUfactor( double aScale ) { m_milsToIu = aScale; } - /** Function SetPageSize - * Set the size of the page layout - * @param aPageSize size (in mils) of the page layout. - */ - void SetPageSize( const wxSize& aPageSize ) - { - m_pageSize = aPageSize; - } - /** * Function SetSheetNumber * Set the value of the sheet number, for basic inscriptions - * @param aSheetNumber the number to display. */ void SetSheetNumber( int aSheetNumber ) { @@ -478,30 +431,23 @@ public: /** * Function SetSheetCount * Set the value of the count of sheets, for basic inscriptions - * @param aSheetCount the number of esheets to display. */ void SetSheetCount( int aSheetCount ) { m_sheetCount = aSheetCount; } - /** Function SetMargins - * Set the left top margin and the right bottom margin - * of the page layout - * @param aLTmargin The left top margin of the page layout. - * @param aRBmargin The right bottom margin of the page layout. - */ - void SetMargins( const wxPoint& aLTmargin, const wxPoint& aRBmargin ) - { - m_LTmargin = aLTmargin; - m_RBmargin = aRBmargin; - } - void Append( WS_DRAW_ITEM_BASE* aItem ) { m_graphicList.push_back( aItem ); } + void Remove( WS_DRAW_ITEM_BASE* aItem ) + { + auto newEnd = std::remove( m_graphicList.begin(), m_graphicList.end(), aItem ); + m_graphicList.erase( newEnd, m_graphicList.end() ); + } + WS_DRAW_ITEM_BASE* GetFirst() { m_idx = 0; @@ -527,21 +473,23 @@ public: *aList = m_graphicList; } + /** + * Sets up the WORKSHEET_DATAITEM globals for generating drawItems. + */ + static void SetupDrawEnvironment( const PAGE_INFO& aPageInfo ); + /** * Draws the item list created by BuildWorkSheetGraphicList * @param aClipBox = the clipping rect, or NULL if no clipping * @param aDC = the current Device Context */ - void Draw( EDA_RECT* aClipBox, wxDC* aDC ); + void Draw( EDA_RECT* aClipBox, wxDC* aDC, COLOR4D aColor ); /** - * Function BuildWorkSheetGraphicList is a core function for - * drawing or plotting the page layout with - * the frame and the basic inscriptions. - * It populates the list of basic graphic items to draw or plot. - * currently lines, rect, polygons and texts - * before calling this function, some parameters should be initialized: - * by calling: + * Function BuildWorkSheetGraphicList is a core function for drawing or plotting the + * page layout with the frame and the basic inscriptions. + * + * Before calling this function, some parameters should be initialized by calling: * SetPenSize( aPenWidth ); * SetMilsToIUfactor( aScalar ); * SetSheetNumber( aSheetNumber ); @@ -552,11 +500,10 @@ public: * @param aPageInfo The PAGE_INFO, for page size, margins... * @param aTitleBlock The sheet title block, for basic inscriptions. * @param aColor The color for drawing. - * @param aAltColor The color for items which need to be "hightlighted". + * @param aAltColor The color for items which need to be "highlighted". */ - void BuildWorkSheetGraphicList( const PAGE_INFO& aPageInfo, - const TITLE_BLOCK& aTitleBlock, - COLOR4D aColor, COLOR4D aAltColor ); + void BuildWorkSheetGraphicList( const PAGE_INFO& aPageInfo, const TITLE_BLOCK& aTitleBlock ); + /** * Function BuildFullText * returns the full text corresponding to the aTextbase, @@ -586,13 +533,6 @@ public: * @return the text, after replacing the format symbols by the actual value */ wxString BuildFullText( const wxString& aTextbase ); - - /** - * Locate graphic items in m_graphicList at location aPosition - * @param aList = the list of items found - * @param aPosition the position (in user units) to locate items - */ - void Locate(wxDC* aDC, std::vector & aList, const wxPoint& aPosition); }; @@ -617,16 +557,14 @@ public: ~WORKSHEET_LAYOUT() {ClearList(); } /** - * static function: returns the instance of WORKSHEET_LAYOUT - * used in the application + * static function: returns the instance of WORKSHEET_LAYOUT used in the application */ static WORKSHEET_LAYOUT& GetTheInstance(); /** * static function: Set an alternate instance of WORKSHEET_LAYOUT * mainly used in page setting dialog - * @param aLayout = the alternate page layout. - * if null, restore the basic page layout + * @param aLayout = the alternate page layout; if null restore the basic page layout */ static void SetAltInstance( WORKSHEET_LAYOUT* aLayout = NULL ); @@ -673,28 +611,8 @@ public: */ void SaveInString( wxString& aOutputString ); - /** - * Add an item to the list of items - */ - void Append( WORKSHEET_DATAITEM* aItem ) - { - m_list.push_back( aItem ); - } - - /** - *Insert an item to the list of items at position aIdx - */ - void Insert( WORKSHEET_DATAITEM* aItem, unsigned aIdx ); - - /** - *Remove the item to the list of items at position aIdx - */ - bool Remove( unsigned aIdx ); - - /** - *Remove the item to the list of items at position aIdx - */ - bool Remove( WORKSHEET_DATAITEM* aItem ); + void Append( WORKSHEET_DATAITEM* aItem ); + void Remove( WORKSHEET_DATAITEM* aItem ); /** * @return the index of aItem, or -1 if does not exist @@ -706,19 +624,17 @@ public: */ WORKSHEET_DATAITEM* GetItem( unsigned aIdx ) const; + /** + * @return a reference to the items. + */ + std::vector& GetItems() { return m_list; } + /** * @return the item count */ unsigned GetCount() const { return m_list.size(); } - /** - * Fills the list with the default layout shape - */ void SetDefaultLayout(); - - /** - * Fills the list with an empty layout shape - */ void SetEmptyLayout(); /** @@ -740,8 +656,7 @@ public: * @param Append = if true: do not delete old layout, and load only aFullFileName. */ - void SetPageLayout( const wxString& aFullFileName = wxEmptyString, - bool Append = false ); + void SetPageLayout( const wxString& aFullFileName = wxEmptyString, bool Append = false ); /** * Populates the list from a S expr description stored in a string @@ -751,7 +666,7 @@ public: @param aSource is the layout source description. */ void SetPageLayout( const char* aPageLayout, bool aAppend = false, - const wxString& aSource = wxT( "Sexpr_string" ) ); + const wxString& aSource = wxT( "Sexpr_string" ) ); /** * @return a short filename from a full filename: @@ -779,4 +694,4 @@ public: const wxString& aProjectPath ); }; -#endif // WORKSHEET_SHAPE_BUILDER_H +#endif // WS_DRAW_ITEM_H diff --git a/pagelayout_editor/CMakeLists.txt b/pagelayout_editor/CMakeLists.txt index 67d321c4e7..c0ceaa651d 100644 --- a/pagelayout_editor/CMakeLists.txt +++ b/pagelayout_editor/CMakeLists.txt @@ -20,12 +20,9 @@ set( PL_EDITOR_SRCS dialogs/dialog_new_dataitem.cpp pl_editor_screen.cpp pl_editor_layout.cpp - design_tree_frame.cpp events_functions.cpp controle.cpp files.cpp - onleftclick.cpp - onrightclick.cpp page_layout_writer.cpp pl_editor_config.cpp pl_editor_frame.cpp @@ -34,7 +31,14 @@ set( PL_EDITOR_SRCS hotkeys.cpp menubar.cpp toolbars_pl_editor.cpp - block.cpp + + tools/pl_actions.cpp + tools/pl_selection_tool.cpp + tools/pl_drawing_tools.cpp + tools/pl_edit_tool.cpp + tools/pl_picker_tool.cpp + tools/pl_point_editor.cpp + tools/selection.cpp ) set( PL_EDITOR_EXTRA_SRCS diff --git a/pagelayout_editor/block.cpp b/pagelayout_editor/block.cpp deleted file mode 100644 index 2226b53f37..0000000000 --- a/pagelayout_editor/block.cpp +++ /dev/null @@ -1,253 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 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 pagelayout_editor/block.cpp - * @brief Block operations - */ - - -#include -#include -#include -#include -#include -#include - - -static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, - bool erase ); - -static void DrawMovingItems( EDA_DRAW_PANEL* aPanel, wxDC* aDC ); - -static void ConfigureDrawList( WS_DRAW_ITEM_LIST* aDrawList, - PL_EDITOR_SCREEN* aScreen, PL_EDITOR_FRAME* aFrame ); - - -static void ConfigureDrawList( WS_DRAW_ITEM_LIST* aDrawList, - PL_EDITOR_SCREEN* aScreen, PL_EDITOR_FRAME* aFrame ) -{ - aDrawList->SetPenSize( 0 ); - aDrawList->SetMilsToIUfactor( IU_PER_MILS ); - aDrawList->SetSheetNumber( aScreen->m_ScreenNumber ); - aDrawList->SetSheetCount( aScreen->m_NumberOfScreens ); - aDrawList->SetFileName( aFrame->GetCurrFileName() ); - aDrawList->SetSheetName( aFrame->GetScreenDesc() ); - aDrawList->BuildWorkSheetGraphicList( aFrame->GetPageSettings(), - aFrame->GetTitleBlock(), RED, RED ); -} - - -int PL_EDITOR_FRAME::BlockCommand( EDA_KEY key ) -{ - int cmd = 0; - - switch( key ) - { - default: - cmd = key & 0x255; - break; - - case 0: - cmd = BLOCK_MOVE; - break; - - case GR_KB_SHIFT: - case GR_KB_CTRL: - case GR_KB_SHIFTCTRL: - case GR_KB_ALT: - break; - - case MOUSE_MIDDLE: - cmd = BLOCK_ZOOM; - break; - } - - return cmd; -} - - -void PL_EDITOR_FRAME::HandleBlockPlace( wxDC* DC ) -{ - wxASSERT( m_canvas->IsMouseCaptured() ); - - GetScreen()->m_BlockLocate.SetState( STATE_BLOCK_STOP ); - - switch( GetScreen()->m_BlockLocate.GetCommand() ) - { - case BLOCK_MOVE: /* Move */ - if( m_canvas->IsMouseCaptured() ) - m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); - - Block_Move( DC ); - GetScreen()->m_BlockLocate.ClearItemsList(); - break; - - default: - wxFAIL_MSG( wxT("HandleBlockPlace: Unexpected block command") ); - break; - } - - m_canvas->EndMouseCapture( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString, false ); - GetScreen()->SetModify(); - GetScreen()->ClearBlockCommand(); - - wxASSERT( GetScreen()->m_BlockLocate.GetCount() == 0 ); - - DisplayToolMsg( wxEmptyString ); -} - - -bool PL_EDITOR_FRAME::HandleBlockEnd( wxDC* DC ) -{ - bool nextcmd = false; - bool zoom_command = false; - - if( m_canvas->IsMouseCaptured() ) - - switch( GetScreen()->m_BlockLocate.GetCommand() ) - { - case BLOCK_MOVE: /* Move */ - GetScreen()->m_BlockLocate.SetState( STATE_BLOCK_MOVE ); - nextcmd = true; - m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); - m_canvas->SetMouseCaptureCallback( DrawMovingBlockOutlines ); - m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); - break; - - case BLOCK_ZOOM: /* Window Zoom */ - zoom_command = true; - break; - - default: - break; - } - - if( ! nextcmd ) - { - GetScreen()->ClearBlockCommand(); - m_canvas->EndMouseCapture( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString, - false ); - } - - if( zoom_command ) - Window_Zoom( GetScreen()->m_BlockLocate ); - - return nextcmd ; -} - - -static void DrawMovingItems( EDA_DRAW_PANEL* aPanel, wxDC* aDC ) -{ - auto screen = static_cast( aPanel->GetScreen() ); - auto frame = static_cast( aPanel->GetParent() ); - - // Get items - std::vector items; - WS_DRAW_ITEM_LIST drawList; - ConfigureDrawList( &drawList, screen, frame ); - drawList.GetAllItems( &items ); - - // Draw items - for( auto item: items ) - { - if( item->HitTest( screen->m_BlockLocate ) ) - { - item->DrawWsItem( NULL, aDC, screen->m_BlockLocate.GetMoveVector(), - g_XorMode, g_GhostColor ); - } - } -} - - -/* Traces the outline of the block structures of a repositioning move - */ -static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPositon, - bool aErase ) -{ - auto screen = aPanel->GetScreen(); - auto block = &screen->m_BlockLocate; - - if( aErase ) - { - block->Draw( aPanel, aDC, block->GetMoveVector(), g_XorMode, block->GetColor() ); - DrawMovingItems( aPanel, aDC ); - } - - block->SetMoveVector( aPanel->GetParent()->GetCrossHairPosition() - block->GetLastCursorPosition() ); - block->Draw( aPanel, aDC, block->GetMoveVector(), g_XorMode, block->GetColor() ); - DrawMovingItems( aPanel, aDC ); -} - - -void PL_EDITOR_FRAME::Block_Move( wxDC* DC ) -{ - auto screen = static_cast( GetScreen() ); - - wxPoint delta; - wxPoint oldpos; - - oldpos = GetCrossHairPosition(); - m_canvas->SetMouseCaptureCallback( NULL ); - - SetCrossHairPosition( oldpos ); - m_canvas->MoveCursorToCrossHair(); - GetScreen()->SetModify(); - GetScreen()->m_BlockLocate.Normalize(); - - // Calculate displacement vectors. - delta = GetScreen()->m_BlockLocate.GetMoveVector(); - - // Get the items - std::vector items; - WS_DRAW_ITEM_LIST drawList; - ConfigureDrawList( &drawList, screen, this ); - drawList.GetAllItems( &items ); - - // Move items in block - SaveCopyInUndoList(); - - for( auto item: items ) - { - auto parent = item->GetParent(); - - if( parent ) - parent->ClearFlags( FLAG1 ); - } - - for( auto item: items ) - { - if( item->HitTest( screen->m_BlockLocate ) ) - { - auto data_item = item->GetParent(); - - if( data_item && !( data_item->GetFlags() & FLAG1 ) ) - { - data_item->SetFlags( FLAG1 ); - data_item->MoveToUi( data_item->GetStartPosUi() + delta ); - } - } - } - - m_canvas->Refresh( true ); -} diff --git a/pagelayout_editor/design_tree_frame.cpp b/pagelayout_editor/design_tree_frame.cpp deleted file mode 100644 index bbee18cb03..0000000000 --- a/pagelayout_editor/design_tree_frame.cpp +++ /dev/null @@ -1,291 +0,0 @@ -/** - * @file design_tree_frame.cpp - */ - -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2013 CERN - * @author Jean-Pierre Charras, jp.charras at wanadoo.fr - * - * 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 - */ - -#include -#include -#include -#include -#include -#include -#include - -/* XPM - * This bitmap is used to show item types - */ -static const char* root_xpm[] = -{ - "12 12 2 1", - " c None", - "x c #008080", - " xxxx ", - " xxx ", - " xxx ", - " xxx ", - "xxxxxxxxxxx ", - "xxxxxxxxxxxx", - "xxxxxxxxxxx ", - " xxx ", - " xxx ", - " xxx ", - " xxxx ", - " " -}; - -static const char* line_xpm[] = -{ - "12 12 2 1", - " c None", - "x c #008080", - "xx ", - "xx ", - "xx ", - "xx ", - "xx ", - "xx ", - "xx ", - "xx ", - "xx ", - "xx ", - "xxxxxxxxxxxx", - "xxxxxxxxxxxx" -}; - -static const char* rect_xpm[] = -{ - "12 12 2 1", - " c None", - "x c #000080", - "xxxxxxxxxxxx", - "xxxxxxxxxxxx", - "xx xx", - "xx xx", - "xx xx", - "xx xx", - "xx xx", - "xx xx", - "xx xx", - "xx xx", - "xxxxxxxxxxxx", - "xxxxxxxxxxxx" -}; - -static const char* text_xpm[] = -{ - "12 12 2 1", - " c None", - "x c #800000", - " xxxxxxxxxx ", - "xxxxxxxxxxxx", - "xx xx xx", - " xx ", - " xx ", - " xx ", - " xx ", - " xx ", - " xx ", - " xx ", - " xxxx ", - " xxxxxx " -}; - -static const char* poly_xpm[] = -{ - "12 12 2 1", - " c None", - "x c #008000", - " xx ", - " xxxx ", - " xxxxxx ", - " xxxxxxxx ", - " xxxxxxxxxx ", - "xxxxxxxxxxxx", - "xxxxxxxxxxxx", - " xxxxxxxxxx ", - " xxxxxxxx ", - " xxxxxx ", - " xxxx ", - " xx " -}; - -static const char* img_xpm[] = -{ - "12 12 2 1", - " c None", - "x c #800000", - " xx ", - " xxxxxx ", - " xx xx ", - "xx xx", - "xx xx", - " xx xx ", - " xxxxxx ", - " xx ", - " xx ", - " xx ", - " xx ", - " xx " -}; - -// Event table: - - -DESIGN_TREE_FRAME::DESIGN_TREE_FRAME( PL_EDITOR_FRAME* aParent ) : - wxTreeCtrl( aParent, ID_DESIGN_TREE_FRAME ) -{ - // icons size is not know (depending on they are built) - // so get it: - wxSize iconsize; - wxBitmap root_bm( root_xpm ); - - iconsize.x = root_bm.GetWidth(); - iconsize.y = root_bm.GetHeight(); - - // Make an image list containing small icons - m_imageList = new wxImageList( iconsize.x, iconsize.y, true, 6 ); - - m_imageList->Add( root_bm ); // root symbol - m_imageList->Add( wxBitmap( line_xpm ) ); // line item - m_imageList->Add( wxBitmap( rect_xpm ) ); // rect item - m_imageList->Add( wxBitmap( text_xpm ) ); // text item - m_imageList->Add( wxBitmap( poly_xpm ) ); // poly item - m_imageList->Add( wxBitmap( img_xpm ) ); // bitmap item - - SetImageList( m_imageList ); -} - - -DESIGN_TREE_FRAME::~DESIGN_TREE_FRAME() -{ - delete m_imageList; -} - - -wxSize DESIGN_TREE_FRAME::GetMinSize() const -{ - return wxSize( 100, -1 ); -} - - -void DESIGN_TREE_FRAME::ReCreateDesignTree() -{ - wxWindowUpdateLocker dummy(this); // Avoid flicker when rebuilding the tree - - DeleteAllItems(); - - const WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance(); - - // root tree: - wxFileName fn( ((PL_EDITOR_FRAME*) GetParent())->GetCurrFileName() ); - wxTreeItemId rootitem; - - if( fn.GetName().IsEmpty() ) - rootitem = AddRoot( wxT( "" ), 0, 0 ); - else - rootitem = AddRoot( fn.GetName(), 0, 0 ); - - SetItemBold( rootitem, true ); - - // Now adding all current items - for( unsigned ii = 0; ii < pglayout.GetCount(); ii++ ) - { - WORKSHEET_DATAITEM* item = pglayout.GetItem( ii ); - int img = 0; - switch( item->GetType() ) - { - case WORKSHEET_DATAITEM::WS_SEGMENT: img = 1; break; - case WORKSHEET_DATAITEM::WS_RECT: img = 2; break; - case WORKSHEET_DATAITEM::WS_TEXT: img = 3; break; - case WORKSHEET_DATAITEM::WS_POLYPOLYGON: img = 4; break; - case WORKSHEET_DATAITEM::WS_BITMAP: img = 5; break; - } - wxTreeItemId cell= AppendItem( rootitem, item->m_Name, img, img ); - DESIGN_TREE_ITEM_DATA* data = new DESIGN_TREE_ITEM_DATA( item ); - SetItemData( cell, data ); - } - - Expand( rootitem ); -} - - -// Select the tree item corresponding to the WORKSHEET_DATAITEM aItem -void DESIGN_TREE_FRAME::SelectCell( WORKSHEET_DATAITEM* aItem ) -{ - wxTreeItemId rootcell = GetRootItem(); - wxTreeItemIdValue cookie; - - wxTreeItemId cell = GetFirstChild( rootcell, cookie ); - - while( cell.IsOk() ) - { - DESIGN_TREE_ITEM_DATA* data = (DESIGN_TREE_ITEM_DATA*) GetItemData( cell ); - - if( data->GetItem() == aItem ) - { - SelectItem( cell ); - return; - } - - cell = GetNextChild( rootcell, cookie ); - } -} - -//return the page layout item managed by the cell -WORKSHEET_DATAITEM* DESIGN_TREE_FRAME::GetPageLayoutItem( wxTreeItemId aCell ) const -{ - DESIGN_TREE_ITEM_DATA* data = (DESIGN_TREE_ITEM_DATA*) GetItemData( aCell ); - if( data ) - return data->GetItem(); - else - return NULL; -} - -/* return the page layout item managed by the selected cell (or NULL) - */ -WORKSHEET_DATAITEM* DESIGN_TREE_FRAME::GetPageLayoutSelectedItem() const -{ - wxTreeItemId cell; - cell = GetSelection(); - - if( cell.IsOk() ) - return GetPageLayoutItem( cell ); - - return NULL; -} - -/* return the page layout item index managed by the selected cell (or -1) - */ -int DESIGN_TREE_FRAME::GetSelectedItemIndex() -{ - WORKSHEET_DATAITEM*item = GetPageLayoutSelectedItem(); - - if( item == NULL ) - return -1; - - WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance(); - return pglayout.GetItemIndex( item ); -} diff --git a/pagelayout_editor/design_tree_frame.h b/pagelayout_editor/design_tree_frame.h deleted file mode 100644 index 3676695668..0000000000 --- a/pagelayout_editor/design_tree_frame.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2013 CERN - * @author Jean-Pierre Charras, jp.charras at wanadoo.fr - * - * 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 design_tree_frame.h - */ - -#ifndef _DESIGN_TREE_FRAME_H -#define _DESIGN_TREE_FRAME_H - -#include - -#include - -class WORKSHEET_DATAITEM; - -/** class DESIGN_TREE_ITEM - * Handle one item for the page layoiut design - */ -class DESIGN_TREE_ITEM_DATA : public wxTreeItemData -{ -private: - WORKSHEET_DATAITEM* m_wsItem; // the page layout item owned by me - -public: - - DESIGN_TREE_ITEM_DATA( WORKSHEET_DATAITEM* aItem = NULL ) - { - m_wsItem = aItem; - } - - /** @return the item managed by the cell - */ - WORKSHEET_DATAITEM* GetItem() const - { - return m_wsItem; - } - - /** Set the link to the item managed by the cell - */ - void SetItem( WORKSHEET_DATAITEM* aItem ) - { - m_wsItem = aItem; - } -}; - - -/** - * Class DESIGN_TREE_FRAME is the left window showing the list of items - */ - -class DESIGN_TREE_FRAME : protected wxTreeCtrl -{ - friend class PL_EDITOR_FRAME; - -private: - wxImageList* m_imageList; - -public: - DESIGN_TREE_FRAME( PL_EDITOR_FRAME* aParent ); - ~DESIGN_TREE_FRAME(); - - void ReCreateDesignTree(); - wxSize GetMinSize() const override; - - /** @return the page layout item managed by the cell - */ - WORKSHEET_DATAITEM* GetPageLayoutItem(wxTreeItemId aCell) const; - - /** @return the page layout item managed by the selected cell (or NULL) - */ - WORKSHEET_DATAITEM* GetPageLayoutSelectedItem() const; - - /** @return the page layout item index managed by the selected cell (or -1) - */ - int GetSelectedItemIndex(); - - // Select the tree item corresponding to the WORKSHEET_DATAITEM aItem - void SelectCell( WORKSHEET_DATAITEM* aItem ); - - void SelectCell( const wxTreeItemId &aTreeItem, bool aSelect=true ) - { - SelectItem( aTreeItem, aSelect ); - } -}; - -#endif /* _DESIGN_TREE_FRAME_H */ diff --git a/pagelayout_editor/dialogs/dialog_new_dataitem.cpp b/pagelayout_editor/dialogs/dialog_new_dataitem.cpp index 4b15def907..f7c5b308c8 100644 --- a/pagelayout_editor/dialogs/dialog_new_dataitem.cpp +++ b/pagelayout_editor/dialogs/dialog_new_dataitem.cpp @@ -1,8 +1,3 @@ -/** - * @file dialog_new_dataitem.cpp - * @brief a dialog called on creating a new plage layout data item. -*/ - /* * This program source code file is part of KiCad, a free EDA CAD application. * @@ -35,6 +30,7 @@ #include #include + class DIALOG_NEW_DATAITEM : public DIALOG_NEW_DATAITEM_BASE { WORKSHEET_DATAITEM* m_item; @@ -55,8 +51,8 @@ int InvokeDialogNewItem( PL_EDITOR_FRAME* aCaller, WORKSHEET_DATAITEM* aItem ) return dlg.ShowModal(); } -DIALOG_NEW_DATAITEM::DIALOG_NEW_DATAITEM( PL_EDITOR_FRAME* aCaller, - WORKSHEET_DATAITEM* aItem ) + +DIALOG_NEW_DATAITEM::DIALOG_NEW_DATAITEM( PL_EDITOR_FRAME* aCaller, WORKSHEET_DATAITEM* aItem ) : DIALOG_NEW_DATAITEM_BASE( aCaller ) { m_item = aItem; @@ -92,10 +88,10 @@ void DIALOG_NEW_DATAITEM::OnOKClick( wxCommandEvent& event ) switch( m_choiceCornerPos->GetSelection() ) { - case 2: m_item->m_Pos.m_Anchor = RB_CORNER; break; - case 0: m_item->m_Pos.m_Anchor = RT_CORNER; break; - case 3: m_item->m_Pos.m_Anchor = LB_CORNER; break; - case 1: m_item->m_Pos.m_Anchor = LT_CORNER; break; + case 2: m_item->m_Pos.m_Anchor = RB_CORNER; break; + case 0: m_item->m_Pos.m_Anchor = RT_CORNER; break; + case 3: m_item->m_Pos.m_Anchor = LB_CORNER; break; + case 1: m_item->m_Pos.m_Anchor = LT_CORNER; break; } // Import End point @@ -109,10 +105,10 @@ void DIALOG_NEW_DATAITEM::OnOKClick( wxCommandEvent& event ) switch( m_choiceCornerEnd->GetSelection() ) { - case 2: m_item->m_End.m_Anchor = RB_CORNER; break; - case 0: m_item->m_End.m_Anchor = RT_CORNER; break; - case 3: m_item->m_End.m_Anchor = LB_CORNER; break; - case 1: m_item->m_End.m_Anchor = LT_CORNER; break; + case 2: m_item->m_End.m_Anchor = RB_CORNER; break; + case 0: m_item->m_End.m_Anchor = RT_CORNER; break; + case 3: m_item->m_End.m_Anchor = LB_CORNER; break; + case 1: m_item->m_End.m_Anchor = LT_CORNER; break; } EndModal( wxID_OK); @@ -123,20 +119,20 @@ void DIALOG_NEW_DATAITEM::initDlg() // Disable useless widgets, depending on WORKSHEET_DATAITEM type switch( m_item->GetType() ) { - case WORKSHEET_DATAITEM::WS_SEGMENT: - case WORKSHEET_DATAITEM::WS_RECT: - m_textCtrlText->Enable( false ); - break; + case WORKSHEET_DATAITEM::WS_SEGMENT: + case WORKSHEET_DATAITEM::WS_RECT: + m_textCtrlText->Enable( false ); + break; - case WORKSHEET_DATAITEM::WS_BITMAP: - case WORKSHEET_DATAITEM::WS_POLYPOLYGON: - m_textCtrlText->Enable( false ); - // fall through - case WORKSHEET_DATAITEM::WS_TEXT: - m_textCtrlEndX->Enable( false ); - m_textCtrlEndY->Enable( false ); - m_choiceCornerEnd->Enable( false ); - break; + case WORKSHEET_DATAITEM::WS_BITMAP: + case WORKSHEET_DATAITEM::WS_POLYPOLYGON: + m_textCtrlText->Enable( false ); + // fall through + case WORKSHEET_DATAITEM::WS_TEXT: + m_textCtrlEndX->Enable( false ); + m_textCtrlEndY->Enable( false ); + m_choiceCornerEnd->Enable( false ); + break; } wxString msg; @@ -146,16 +142,13 @@ void DIALOG_NEW_DATAITEM::initDlg() m_textCtrlPosX->SetValue( msg ); msg.Printf( wxT("%.3f"), m_item->m_Pos.m_Pos.y ); m_textCtrlPosY->SetValue( msg ); + switch( m_item->m_Pos.m_Anchor ) { - case RB_CORNER: // right bottom corner - m_choiceCornerPos->SetSelection( 2 ); break; - case RT_CORNER: // right top corner - m_choiceCornerPos->SetSelection( 0 ); break; - case LB_CORNER: // left bottom corner - m_choiceCornerPos->SetSelection( 3 ); break; - case LT_CORNER: // left top corner - m_choiceCornerPos->SetSelection( 1 ); break; + case RB_CORNER: m_choiceCornerPos->SetSelection( 2 ); break; + case RT_CORNER: m_choiceCornerPos->SetSelection( 0 ); break; + case LB_CORNER: m_choiceCornerPos->SetSelection( 3 ); break; + case LT_CORNER: m_choiceCornerPos->SetSelection( 1 ); break; } // End point @@ -163,16 +156,13 @@ void DIALOG_NEW_DATAITEM::initDlg() m_textCtrlEndX->SetValue( msg ); msg.Printf( wxT("%.3f"), m_item->m_End.m_Pos.y ); m_textCtrlEndY->SetValue( msg ); + switch( m_item->m_End.m_Anchor ) { - case RB_CORNER: // right bottom corner - m_choiceCornerEnd->SetSelection( 2 ); break; - case RT_CORNER: // right top corner - m_choiceCornerEnd->SetSelection( 0 ); break; - case LB_CORNER: // left bottom corner - m_choiceCornerEnd->SetSelection( 3 ); break; - case LT_CORNER: // left top corner - m_choiceCornerEnd->SetSelection( 1 ); break; + case RB_CORNER: m_choiceCornerEnd->SetSelection( 2 ); break; + case RT_CORNER: m_choiceCornerEnd->SetSelection( 0 ); break; + case LB_CORNER: m_choiceCornerEnd->SetSelection( 3 ); break; + case LT_CORNER: m_choiceCornerEnd->SetSelection( 1 ); break; } if( m_item->GetType() == WORKSHEET_DATAITEM::WS_TEXT ) diff --git a/pagelayout_editor/dialogs/dialogs_for_printing.cpp b/pagelayout_editor/dialogs/dialogs_for_printing.cpp index d4fb803ae0..27ee1486ea 100644 --- a/pagelayout_editor/dialogs/dialogs_for_printing.cpp +++ b/pagelayout_editor/dialogs/dialogs_for_printing.cpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/pagelayout_editor/dialogs/properties_frame_base.cpp b/pagelayout_editor/dialogs/properties_frame_base.cpp index f6db8b8fef..9a289da650 100644 --- a/pagelayout_editor/dialogs/properties_frame_base.cpp +++ b/pagelayout_editor/dialogs/properties_frame_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Jul 11 2018) +// C++ code generated with wxFormBuilder (version Dec 30 2017) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -23,44 +23,23 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c wxBoxSizer* bSizerButt; bSizerButt = new wxBoxSizer( wxHORIZONTAL ); - wxBoxSizer* bSizerType; - bSizerType = new wxBoxSizer( wxVERTICAL ); - - m_staticTextType = new wxStaticText( m_swItemProperties, wxID_ANY, _("Type:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextType = new wxStaticText( m_swItemProperties, wxID_ANY, _("Type"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextType->Wrap( -1 ); - m_staticTextType->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false, wxEmptyString ) ); + m_staticTextType->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString ) ); - bSizerType->Add( m_staticTextType, 0, wxLEFT|wxRIGHT, 5 ); + bSizerButt->Add( m_staticTextType, 1, wxLEFT|wxRIGHT, 5 ); - m_textCtrlType = new wxTextCtrl( m_swItemProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY ); - bSizerType->Add( m_textCtrlType, 0, wxRIGHT|wxLEFT, 5 ); - - - bSizerButt->Add( bSizerType, 0, 0, 5 ); - - wxBoxSizer* bSizerPageOpt; - bSizerPageOpt = new wxBoxSizer( wxVERTICAL ); - - m_staticTextPageOpt = new wxStaticText( m_swItemProperties, wxID_ANY, _("Page 1 option:"), wxDefaultPosition, wxDefaultSize, 0 ); - m_staticTextPageOpt->Wrap( -1 ); - m_staticTextPageOpt->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString ) ); - - bSizerPageOpt->Add( m_staticTextPageOpt, 0, wxLEFT|wxRIGHT, 5 ); - - wxString m_choicePageOptChoices[] = { _("None"), _("Page 1 only"), _("Not on page 1") }; + wxString m_choicePageOptChoices[] = { _("Show on all pages"), _("First page only"), _("Subsequent pages only") }; int m_choicePageOptNChoices = sizeof( m_choicePageOptChoices ) / sizeof( wxString ); m_choicePageOpt = new wxChoice( m_swItemProperties, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_choicePageOptNChoices, m_choicePageOptChoices, 0 ); m_choicePageOpt->SetSelection( 2 ); - bSizerPageOpt->Add( m_choicePageOpt, 0, wxRIGHT|wxLEFT, 5 ); + bSizerButt->Add( m_choicePageOpt, 0, wxEXPAND|wxRIGHT|wxLEFT, 5 ); - bSizerButt->Add( bSizerPageOpt, 0, 0, 5 ); - - - bSizerMain->Add( bSizerButt, 0, 0, 5 ); + bSizerMain->Add( bSizerButt, 0, wxEXPAND, 5 ); m_staticline5 = new wxStaticLine( m_swItemProperties, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); - bSizerMain->Add( m_staticline5, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 ); + bSizerMain->Add( m_staticline5, 0, wxTOP|wxRIGHT|wxLEFT|wxEXPAND, 5 ); m_SizerTextOptions = new wxBoxSizer( wxVERTICAL ); @@ -69,59 +48,58 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c m_SizerTextOptions->Add( m_staticTextText, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); m_textCtrlText = new wxTextCtrl( m_swItemProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE ); - m_SizerTextOptions->Add( m_textCtrlText, 1, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 ); + m_SizerTextOptions->Add( m_textCtrlText, 1, wxEXPAND|wxRIGHT|wxLEFT, 5 ); wxBoxSizer* bSizerFontOpt; bSizerFontOpt = new wxBoxSizer( wxVERTICAL ); wxFlexGridSizer* fgSizer1; - fgSizer1 = new wxFlexGridSizer( 0, 3, 0, 0 ); + fgSizer1 = new wxFlexGridSizer( 0, 4, 0, 0 ); fgSizer1->SetFlexibleDirection( wxBOTH ); fgSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); - m_staticTextHjust = new wxStaticText( m_swItemProperties, wxID_ANY, _("Horizontal align:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextHjust = new wxStaticText( m_swItemProperties, wxID_ANY, _("H align:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextHjust->Wrap( -1 ); - fgSizer1->Add( m_staticTextHjust, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); + fgSizer1->Add( m_staticTextHjust, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 ); wxString m_choiceHjustifyChoices[] = { _("Left"), _("Center"), _("Right") }; int m_choiceHjustifyNChoices = sizeof( m_choiceHjustifyChoices ) / sizeof( wxString ); m_choiceHjustify = new wxChoice( m_swItemProperties, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_choiceHjustifyNChoices, m_choiceHjustifyChoices, 0 ); m_choiceHjustify->SetSelection( 0 ); - fgSizer1->Add( m_choiceHjustify, 0, wxEXPAND|wxALL, 5 ); + fgSizer1->Add( m_choiceHjustify, 0, wxEXPAND|wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + + fgSizer1->Add( 0, 0, 1, wxEXPAND|wxRIGHT|wxLEFT, 10 ); m_checkBoxBold = new wxCheckBox( m_swItemProperties, wxID_ANY, _("Bold"), wxDefaultPosition, wxDefaultSize, 0 ); - fgSizer1->Add( m_checkBoxBold, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 ); + fgSizer1->Add( m_checkBoxBold, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - m_staticTextVjust = new wxStaticText( m_swItemProperties, wxID_ANY, _("Vertical align:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextVjust = new wxStaticText( m_swItemProperties, wxID_ANY, _("V align:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextVjust->Wrap( -1 ); - fgSizer1->Add( m_staticTextVjust, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); + fgSizer1->Add( m_staticTextVjust, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 5 ); wxString m_choiceVjustifyChoices[] = { _("Top"), _("Center"), _("Bottom") }; int m_choiceVjustifyNChoices = sizeof( m_choiceVjustifyChoices ) / sizeof( wxString ); m_choiceVjustify = new wxChoice( m_swItemProperties, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_choiceVjustifyNChoices, m_choiceVjustifyChoices, 0 ); m_choiceVjustify->SetSelection( 1 ); - fgSizer1->Add( m_choiceVjustify, 0, wxEXPAND|wxALL, 5 ); + fgSizer1->Add( m_choiceVjustify, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 ); + + + fgSizer1->Add( 0, 0, 1, wxEXPAND|wxRIGHT|wxLEFT, 5 ); m_checkBoxItalic = new wxCheckBox( m_swItemProperties, wxID_ANY, _("Italic"), wxDefaultPosition, wxDefaultSize, 0 ); - fgSizer1->Add( m_checkBoxItalic, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 ); + fgSizer1->Add( m_checkBoxItalic, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - bSizerFontOpt->Add( fgSizer1, 1, wxEXPAND, 5 ); + bSizerFontOpt->Add( fgSizer1, 0, wxEXPAND, 5 ); - m_SizerTextOptions->Add( bSizerFontOpt, 0, wxEXPAND, 5 ); - - m_staticline81 = new wxStaticLine( m_swItemProperties, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); - m_SizerTextOptions->Add( m_staticline81, 0, wxEXPAND | wxALL, 5 ); - - m_staticTextSizeInfo = new wxStaticText( m_swItemProperties, wxID_ANY, _("Set to 0 to use default values"), wxDefaultPosition, wxDefaultSize, 0 ); - m_staticTextSizeInfo->Wrap( -1 ); - m_SizerTextOptions->Add( m_staticTextSizeInfo, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); + m_SizerTextOptions->Add( bSizerFontOpt, 0, wxEXPAND|wxBOTTOM, 5 ); wxFlexGridSizer* fgSizer2; - fgSizer2 = new wxFlexGridSizer( 0, 4, 0, 0 ); + fgSizer2 = new wxFlexGridSizer( 0, 5, 0, 0 ); fgSizer2->AddGrowableCol( 0 ); - fgSizer2->AddGrowableCol( 2 ); + fgSizer2->AddGrowableCol( 3 ); fgSizer2->SetFlexibleDirection( wxBOTH ); fgSizer2->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); @@ -130,6 +108,9 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c fgSizer2->Add( m_staticTexTsizeX, 0, wxRIGHT|wxLEFT, 5 ); + fgSizer2->Add( 0, 0, 0, wxEXPAND, 5 ); + + fgSizer2->Add( 0, 0, 1, wxEXPAND, 5 ); m_staticTextTsizeY = new wxStaticText( m_swItemProperties, wxID_ANY, _("Text height:"), wxDefaultPosition, wxDefaultSize, 0 ); @@ -137,7 +118,7 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c fgSizer2->Add( m_staticTextTsizeY, 0, wxRIGHT|wxLEFT, 5 ); - fgSizer2->Add( 0, 0, 1, wxEXPAND, 5 ); + fgSizer2->Add( 0, 0, 0, wxEXPAND, 5 ); m_textCtrlTextSizeX = new wxTextCtrl( m_swItemProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizer2->Add( m_textCtrlTextSizeX, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 5 ); @@ -146,6 +127,9 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c m_units1->Wrap( -1 ); fgSizer2->Add( m_units1, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxBOTTOM, 5 ); + + fgSizer2->Add( 0, 0, 1, wxEXPAND|wxRIGHT|wxLEFT, 5 ); + m_textCtrlTextSizeY = new wxTextCtrl( m_swItemProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizer2->Add( m_textCtrlTextSizeY, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 5 ); @@ -153,36 +137,26 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c m_units11->Wrap( -1 ); fgSizer2->Add( m_units11, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxBOTTOM|wxRIGHT, 5 ); - m_staticTextConstraints = new wxStaticText( m_swItemProperties, wxID_ANY, _("Constraints:"), wxDefaultPosition, wxDefaultSize, 0 ); - m_staticTextConstraints->Wrap( -1 ); - fgSizer2->Add( m_staticTextConstraints, 0, wxLEFT|wxRIGHT|wxTOP, 5 ); - - - fgSizer2->Add( 0, 0, 1, wxEXPAND, 5 ); - - - fgSizer2->Add( 0, 0, 1, wxEXPAND, 5 ); - - - fgSizer2->Add( 0, 0, 1, wxEXPAND, 5 ); - m_staticTextConstraintX = new wxStaticText( m_swItemProperties, wxID_ANY, _("Maximum width:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextConstraintX->Wrap( -1 ); m_staticTextConstraintX->SetToolTip( _("Set to 0 to disable this constraint") ); - fgSizer2->Add( m_staticTextConstraintX, 0, wxRIGHT|wxLEFT, 5 ); + fgSizer2->Add( m_staticTextConstraintX, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); fgSizer2->Add( 0, 0, 1, wxEXPAND, 5 ); + + fgSizer2->Add( 0, 0, 0, wxEXPAND, 5 ); + m_staticTextConstraintY = new wxStaticText( m_swItemProperties, wxID_ANY, _("Maximum height:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextConstraintY->Wrap( -1 ); m_staticTextConstraintY->SetToolTip( _("Set to 0 to disable this constraint") ); - fgSizer2->Add( m_staticTextConstraintY, 0, wxRIGHT|wxLEFT, 5 ); + fgSizer2->Add( m_staticTextConstraintY, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); - fgSizer2->Add( 0, 0, 1, wxEXPAND, 5 ); + fgSizer2->Add( 0, 0, 0, wxEXPAND, 5 ); m_textCtrlConstraintX = new wxTextCtrl( m_swItemProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizer2->Add( m_textCtrlConstraintX, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 5 ); @@ -191,6 +165,9 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c m_units111->Wrap( -1 ); fgSizer2->Add( m_units111, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxBOTTOM, 5 ); + + fgSizer2->Add( 0, 0, 1, wxEXPAND, 5 ); + m_textCtrlConstraintY = new wxTextCtrl( m_swItemProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizer2->Add( m_textCtrlConstraintY, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 5 ); @@ -199,86 +176,85 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c fgSizer2->Add( m_units1111, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxBOTTOM|wxRIGHT, 5 ); - m_SizerTextOptions->Add( fgSizer2, 1, wxEXPAND, 5 ); + m_SizerTextOptions->Add( fgSizer2, 0, wxEXPAND, 5 ); + + m_staticTextSizeInfo = new wxStaticText( m_swItemProperties, wxID_ANY, _("Set to 0 to use default values"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextSizeInfo->Wrap( -1 ); + m_SizerTextOptions->Add( m_staticTextSizeInfo, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 ); m_staticline6 = new wxStaticLine( m_swItemProperties, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); m_SizerTextOptions->Add( m_staticline6, 0, wxEXPAND|wxRIGHT|wxLEFT, 5 ); - bSizerMain->Add( m_SizerTextOptions, 0, wxEXPAND, 5 ); - - m_buttonOK = new wxButton( m_swItemProperties, wxID_ANY, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 ); - m_buttonOK->SetDefault(); + bSizerMain->Add( m_SizerTextOptions, 1, wxEXPAND, 5 ); + m_buttonOK = new wxButton( m_swItemProperties, wxID_ANY, _("Apply"), wxDefaultPosition, wxDefaultSize, 0 ); + m_buttonOK->SetDefault(); bSizerMain->Add( m_buttonOK, 0, wxALL|wxEXPAND, 5 ); m_staticline8 = new wxStaticLine( m_swItemProperties, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); - bSizerMain->Add( m_staticline8, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); + bSizerMain->Add( m_staticline8, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 ); m_staticTextComment = new wxStaticText( m_swItemProperties, wxID_ANY, _("Comment:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextComment->Wrap( -1 ); - bSizerMain->Add( m_staticTextComment, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); + bSizerMain->Add( m_staticTextComment, 0, wxRIGHT|wxLEFT, 5 ); m_textCtrlComment = new wxTextCtrl( m_swItemProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); bSizerMain->Add( m_textCtrlComment, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 ); m_staticline2 = new wxStaticLine( m_swItemProperties, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); - bSizerMain->Add( m_staticline2, 0, wxEXPAND|wxRIGHT|wxLEFT, 5 ); + bSizerMain->Add( m_staticline2, 0, wxRIGHT|wxLEFT|wxEXPAND, 5 ); wxBoxSizer* bSizerPos; bSizerPos = new wxBoxSizer( wxHORIZONTAL ); wxFlexGridSizer* fgSizer3; - fgSizer3 = new wxFlexGridSizer( 0, 2, 0, 0 ); - fgSizer3->AddGrowableCol( 0 ); - fgSizer3->SetFlexibleDirection( wxBOTH ); + fgSizer3 = new wxFlexGridSizer( 0, 3, 0, 0 ); + fgSizer3->AddGrowableCol( 1 ); + fgSizer3->SetFlexibleDirection( wxHORIZONTAL ); fgSizer3->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); - m_staticTextPosX = new wxStaticText( m_swItemProperties, wxID_ANY, _("Start X:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextPosX = new wxStaticText( m_swItemProperties, wxID_ANY, _("X:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextPosX->Wrap( -1 ); - fgSizer3->Add( m_staticTextPosX, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); - - - fgSizer3->Add( 0, 0, 1, wxEXPAND, 5 ); + fgSizer3->Add( m_staticTextPosX, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); m_textCtrlPosX = new wxTextCtrl( m_swItemProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); - fgSizer3->Add( m_textCtrlPosX, 1, wxEXPAND|wxBOTTOM|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 ); + fgSizer3->Add( m_textCtrlPosX, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM, 5 ); m_units12 = new wxStaticText( m_swItemProperties, wxID_ANY, _("mm"), wxDefaultPosition, wxDefaultSize, 0 ); m_units12->Wrap( -1 ); fgSizer3->Add( m_units12, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxBOTTOM, 5 ); - m_staticTextPosY = new wxStaticText( m_swItemProperties, wxID_ANY, _("Start Y:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextPosY = new wxStaticText( m_swItemProperties, wxID_ANY, _("Y:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextPosY->Wrap( -1 ); - fgSizer3->Add( m_staticTextPosY, 0, wxRIGHT|wxLEFT, 5 ); - - - fgSizer3->Add( 0, 0, 1, wxEXPAND, 5 ); + fgSizer3->Add( m_staticTextPosY, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 ); m_textCtrlPosY = new wxTextCtrl( m_swItemProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); - fgSizer3->Add( m_textCtrlPosY, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); + fgSizer3->Add( m_textCtrlPosY, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM, 5 ); m_units121 = new wxStaticText( m_swItemProperties, wxID_ANY, _("mm"), wxDefaultPosition, wxDefaultSize, 0 ); m_units121->Wrap( -1 ); - fgSizer3->Add( m_units121, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT, 5 ); + fgSizer3->Add( m_units121, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxBOTTOM, 5 ); - bSizerPos->Add( fgSizer3, 1, wxEXPAND|wxRIGHT, 5 ); + bSizerPos->Add( fgSizer3, 0, wxEXPAND|wxTOP|wxBOTTOM|wxRIGHT, 5 ); wxBoxSizer* bSizer6; bSizer6 = new wxBoxSizer( wxVERTICAL ); - m_staticTextOrgPos = new wxStaticText( m_swItemProperties, wxID_ANY, _("Origin:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextOrgPos = new wxStaticText( m_swItemProperties, wxID_ANY, _("From:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextOrgPos->Wrap( -1 ); bSizer6->Add( m_staticTextOrgPos, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); - m_comboBoxCornerPos = new wxComboBox( m_swItemProperties, wxID_ANY, _("Lower Right"), wxDefaultPosition, wxDefaultSize, 0, NULL, 0 ); + m_comboBoxCornerPos = new wxComboBox( m_swItemProperties, wxID_ANY, _("Lower Right"), wxDefaultPosition, wxSize( -1,-1 ), 0, NULL, 0 ); m_comboBoxCornerPos->Append( _("Upper Right") ); m_comboBoxCornerPos->Append( _("Upper Left") ); m_comboBoxCornerPos->Append( _("Lower Right") ); m_comboBoxCornerPos->Append( _("Lower Left") ); m_comboBoxCornerPos->SetSelection( 2 ); - bSizer6->Add( m_comboBoxCornerPos, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 ); + m_comboBoxCornerPos->SetMinSize( wxSize( 132,-1 ) ); + + bSizer6->Add( m_comboBoxCornerPos, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 ); bSizerPos->Add( bSizer6, 0, wxALIGN_CENTER_VERTICAL, 5 ); @@ -289,84 +265,74 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c m_SizerEndPosition = new wxBoxSizer( wxHORIZONTAL ); wxFlexGridSizer* fgSizer4; - fgSizer4 = new wxFlexGridSizer( 0, 2, 0, 0 ); - fgSizer4->AddGrowableCol( 0 ); - fgSizer4->SetFlexibleDirection( wxBOTH ); + fgSizer4 = new wxFlexGridSizer( 0, 3, 0, 0 ); + fgSizer4->AddGrowableCol( 1 ); + fgSizer4->SetFlexibleDirection( wxHORIZONTAL ); fgSizer4->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); - m_staticTextEndX = new wxStaticText( m_swItemProperties, wxID_ANY, _("End X:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextEndX = new wxStaticText( m_swItemProperties, wxID_ANY, _("X:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextEndX->Wrap( -1 ); - fgSizer4->Add( m_staticTextEndX, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); - - - fgSizer4->Add( 0, 0, 1, wxEXPAND, 5 ); + fgSizer4->Add( m_staticTextEndX, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); m_textCtrlEndX = new wxTextCtrl( m_swItemProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); - fgSizer4->Add( m_textCtrlEndX, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 5 ); + fgSizer4->Add( m_textCtrlEndX, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM, 5 ); m_units1211 = new wxStaticText( m_swItemProperties, wxID_ANY, _("mm"), wxDefaultPosition, wxDefaultSize, 0 ); m_units1211->Wrap( -1 ); fgSizer4->Add( m_units1211, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxBOTTOM, 5 ); - m_staticTextEndY = new wxStaticText( m_swItemProperties, wxID_ANY, _("End Y:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextEndY = new wxStaticText( m_swItemProperties, wxID_ANY, _("Y:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextEndY->Wrap( -1 ); - fgSizer4->Add( m_staticTextEndY, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); - - - fgSizer4->Add( 0, 0, 1, wxEXPAND, 5 ); + fgSizer4->Add( m_staticTextEndY, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); m_textCtrlEndY = new wxTextCtrl( m_swItemProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); - fgSizer4->Add( m_textCtrlEndY, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 5 ); + fgSizer4->Add( m_textCtrlEndY, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM, 5 ); m_units12111 = new wxStaticText( m_swItemProperties, wxID_ANY, _("mm"), wxDefaultPosition, wxDefaultSize, 0 ); m_units12111->Wrap( -1 ); fgSizer4->Add( m_units12111, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxBOTTOM, 5 ); - m_SizerEndPosition->Add( fgSizer4, 1, wxEXPAND|wxRIGHT, 5 ); + m_SizerEndPosition->Add( fgSizer4, 0, wxEXPAND|wxRIGHT, 5 ); wxBoxSizer* bSizer61; bSizer61 = new wxBoxSizer( wxVERTICAL ); - m_staticTextOrgEnd = new wxStaticText( m_swItemProperties, wxID_ANY, _("Origin:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextOrgEnd = new wxStaticText( m_swItemProperties, wxID_ANY, _("From:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextOrgEnd->Wrap( -1 ); bSizer61->Add( m_staticTextOrgEnd, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); - m_comboBoxCornerEnd = new wxComboBox( m_swItemProperties, wxID_ANY, _("Lower Left"), wxDefaultPosition, wxDefaultSize, 0, NULL, 0 ); + m_comboBoxCornerEnd = new wxComboBox( m_swItemProperties, wxID_ANY, _("Lower Left"), wxDefaultPosition, wxSize( -1,-1 ), 0, NULL, 0 ); m_comboBoxCornerEnd->Append( _("Upper Right") ); m_comboBoxCornerEnd->Append( _("Upper Left") ); m_comboBoxCornerEnd->Append( _("Lower Right") ); m_comboBoxCornerEnd->Append( _("Lower Left") ); m_comboBoxCornerEnd->SetSelection( 3 ); - bSizer61->Add( m_comboBoxCornerEnd, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 ); + m_comboBoxCornerEnd->SetMinSize( wxSize( 132,-1 ) ); + + bSizer61->Add( m_comboBoxCornerEnd, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 ); m_SizerEndPosition->Add( bSizer61, 0, wxALIGN_CENTER_VERTICAL, 5 ); - bSizerMain->Add( m_SizerEndPosition, 0, wxEXPAND, 5 ); + bSizerMain->Add( m_SizerEndPosition, 0, wxTOP|wxBOTTOM|wxEXPAND, 5 ); m_SizerLineThickness = new wxBoxSizer( wxHORIZONTAL ); - wxBoxSizer* bSizerThickness; - bSizerThickness = new wxBoxSizer( wxVERTICAL ); - - m_staticTextThickness = new wxStaticText( m_swItemProperties, wxID_ANY, _("Thickness:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextThickness = new wxStaticText( m_swItemProperties, wxID_ANY, _("Line width:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextThickness->Wrap( -1 ); - bSizerThickness->Add( m_staticTextThickness, 0, wxLEFT|wxRIGHT, 5 ); + m_SizerLineThickness->Add( m_staticTextThickness, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 ); m_textCtrlThickness = new wxTextCtrl( m_swItemProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); - bSizerThickness->Add( m_textCtrlThickness, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 ); + m_SizerLineThickness->Add( m_textCtrlThickness, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT, 5 ); - - m_SizerLineThickness->Add( bSizerThickness, 0, wxEXPAND, 5 ); - - m_staticTextInfoThickness = new wxStaticText( m_swItemProperties, wxID_ANY, _("Set to 0 to use default"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextInfoThickness = new wxStaticText( m_swItemProperties, wxID_ANY, _("Set to 0 for default"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextInfoThickness->Wrap( -1 ); - m_SizerLineThickness->Add( m_staticTextInfoThickness, 0, wxALIGN_CENTER|wxALL, 5 ); + m_SizerLineThickness->Add( m_staticTextInfoThickness, 0, wxALIGN_CENTER|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - bSizerMain->Add( m_SizerLineThickness, 0, 0, 5 ); + bSizerMain->Add( m_SizerLineThickness, 0, wxTOP|wxBOTTOM, 5 ); m_SizerRotAndPPI = new wxBoxSizer( wxVERTICAL ); @@ -380,35 +346,31 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c m_staticTextRot = new wxStaticText( m_swItemProperties, wxID_ANY, _("Rotation:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextRot->Wrap( -1 ); - fgSizerRotAndPPI->Add( m_staticTextRot, 0, wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 ); + fgSizerRotAndPPI->Add( m_staticTextRot, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); m_textCtrlRotation = new wxTextCtrl( m_swItemProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); - fgSizerRotAndPPI->Add( m_textCtrlRotation, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxLEFT|wxRIGHT, 5 ); + fgSizerRotAndPPI->Add( m_textCtrlRotation, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT, 5 ); m_staticTextBitmapPPI = new wxStaticText( m_swItemProperties, wxID_ANY, _("Bitmap PPI:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextBitmapPPI->Wrap( -1 ); - fgSizerRotAndPPI->Add( m_staticTextBitmapPPI, 0, wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 ); + fgSizerRotAndPPI->Add( m_staticTextBitmapPPI, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); m_textCtrlBitmapPPI = new wxTextCtrl( m_swItemProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); - fgSizerRotAndPPI->Add( m_textCtrlBitmapPPI, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxLEFT|wxRIGHT, 5 ); + fgSizerRotAndPPI->Add( m_textCtrlBitmapPPI, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT, 5 ); - m_SizerRotAndPPI->Add( fgSizerRotAndPPI, 1, wxEXPAND, 5 ); + m_SizerRotAndPPI->Add( fgSizerRotAndPPI, 0, wxEXPAND, 5 ); bSizerMain->Add( m_SizerRotAndPPI, 0, wxEXPAND, 5 ); m_staticline4 = new wxStaticLine( m_swItemProperties, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); - bSizerMain->Add( m_staticline4, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 ); - - m_staticTextRepeatPrms = new wxStaticText( m_swItemProperties, wxID_ANY, _("Repeat parameters:"), wxDefaultPosition, wxDefaultSize, 0 ); - m_staticTextRepeatPrms->Wrap( -1 ); - bSizerMain->Add( m_staticTextRepeatPrms, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); + bSizerMain->Add( m_staticline4, 0, wxTOP|wxRIGHT|wxLEFT|wxEXPAND, 5 ); wxFlexGridSizer* fgSizer8; - fgSizer8 = new wxFlexGridSizer( 0, 4, 0, 0 ); + fgSizer8 = new wxFlexGridSizer( 0, 5, 0, 0 ); fgSizer8->AddGrowableCol( 0 ); - fgSizer8->AddGrowableCol( 2 ); + fgSizer8->AddGrowableCol( 3 ); fgSizer8->SetFlexibleDirection( wxBOTH ); fgSizer8->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); @@ -417,32 +379,41 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c fgSizer8->Add( m_staticTextRepeatCnt, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); + fgSizer8->Add( 0, 0, 0, wxEXPAND, 5 ); + + fgSizer8->Add( 0, 0, 1, wxEXPAND, 5 ); - m_staticTextInclabel = new wxStaticText( m_swItemProperties, wxID_ANY, _("Text Increment:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextInclabel = new wxStaticText( m_swItemProperties, wxID_ANY, _("Step text:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextInclabel->Wrap( -1 ); fgSizer8->Add( m_staticTextInclabel, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); - fgSizer8->Add( 0, 0, 1, wxEXPAND, 5 ); + fgSizer8->Add( 0, 0, 0, wxEXPAND, 5 ); m_textCtrlRepeatCount = new wxTextCtrl( m_swItemProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); - fgSizer8->Add( m_textCtrlRepeatCount, 0, wxRIGHT|wxLEFT|wxEXPAND, 5 ); + fgSizer8->Add( m_textCtrlRepeatCount, 0, wxEXPAND|wxLEFT, 5 ); + + + fgSizer8->Add( 0, 0, 0, wxEXPAND, 5 ); fgSizer8->Add( 0, 0, 1, wxEXPAND, 5 ); m_textCtrlTextIncrement = new wxTextCtrl( m_swItemProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); - fgSizer8->Add( m_textCtrlTextIncrement, 0, wxRIGHT|wxLEFT|wxEXPAND, 5 ); + fgSizer8->Add( m_textCtrlTextIncrement, 0, wxEXPAND|wxLEFT, 5 ); - fgSizer8->Add( 0, 0, 1, wxEXPAND, 5 ); + fgSizer8->Add( 0, 0, 0, wxEXPAND, 5 ); m_staticTextStepX = new wxStaticText( m_swItemProperties, wxID_ANY, _("Step X:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextStepX->Wrap( -1 ); fgSizer8->Add( m_staticTextStepX, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); + fgSizer8->Add( 0, 0, 0, wxEXPAND, 5 ); + + fgSizer8->Add( 0, 0, 1, wxEXPAND, 5 ); m_staticTextStepY = new wxStaticText( m_swItemProperties, wxID_ANY, _("Step Y:"), wxDefaultPosition, wxDefaultSize, 0 ); @@ -450,15 +421,18 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c fgSizer8->Add( m_staticTextStepY, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); - fgSizer8->Add( 0, 0, 1, wxEXPAND, 5 ); + fgSizer8->Add( 0, 0, 0, wxEXPAND, 5 ); - m_textCtrlStepX = new wxTextCtrl( m_swItemProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + m_textCtrlStepX = new wxTextCtrl( m_swItemProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( -1,-1 ), 0 ); fgSizer8->Add( m_textCtrlStepX, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 5 ); m_units121111 = new wxStaticText( m_swItemProperties, wxID_ANY, _("mm"), wxDefaultPosition, wxDefaultSize, 0 ); m_units121111->Wrap( -1 ); fgSizer8->Add( m_units121111, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxBOTTOM|wxRIGHT, 5 ); + + fgSizer8->Add( 0, 0, 1, wxEXPAND|wxLEFT, 5 ); + m_textCtrlStepY = new wxTextCtrl( m_swItemProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizer8->Add( m_textCtrlStepY, 0, wxEXPAND|wxBOTTOM|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 ); @@ -467,7 +441,7 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c fgSizer8->Add( m_units1211111, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxBOTTOM|wxRIGHT, 5 ); - bSizerMain->Add( fgSizer8, 1, wxEXPAND, 5 ); + bSizerMain->Add( fgSizer8, 0, wxEXPAND, 5 ); m_swItemProperties->SetSizer( bSizerMain ); @@ -487,9 +461,9 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c bSizerGeneralOpts1->Add( m_staticTextDefVal, 0, wxALL, 5 ); wxFlexGridSizer* fgSizer5; - fgSizer5 = new wxFlexGridSizer( 0, 4, 0, 0 ); + fgSizer5 = new wxFlexGridSizer( 0, 5, 0, 0 ); fgSizer5->AddGrowableCol( 0 ); - fgSizer5->AddGrowableCol( 2 ); + fgSizer5->AddGrowableCol( 3 ); fgSizer5->SetFlexibleDirection( wxBOTH ); fgSizer5->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); @@ -498,6 +472,9 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c fgSizer5->Add( m_staticTextDefTsX, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); + fgSizer5->Add( 0, 0, 1, wxEXPAND, 5 ); + + fgSizer5->Add( 0, 0, 1, wxEXPAND, 5 ); m_staticTextDefTsY = new wxStaticText( m_swGeneralOpts, wxID_ANY, _("Text height:"), wxDefaultPosition, wxDefaultSize, 0 ); @@ -514,6 +491,9 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c m_units14->Wrap( -1 ); fgSizer5->Add( m_units14, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxBOTTOM|wxRIGHT, 5 ); + + fgSizer5->Add( 0, 0, 1, wxEXPAND, 5 ); + m_textCtrlDefaultTextSizeY = new wxTextCtrl( m_swGeneralOpts, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizer5->Add( m_textCtrlDefaultTextSizeY, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 5 ); @@ -526,6 +506,9 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c fgSizer5->Add( m_staticTextDefLineW, 0, wxEXPAND|wxLEFT|wxRIGHT|wxTOP, 5 ); + fgSizer5->Add( 0, 0, 1, wxEXPAND, 5 ); + + fgSizer5->Add( 0, 0, 1, wxEXPAND, 5 ); m_staticText22 = new wxStaticText( m_swGeneralOpts, wxID_ANY, _("Text thickness:"), wxDefaultPosition, wxDefaultSize, 0 ); @@ -542,6 +525,9 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c m_staticText221->Wrap( -1 ); fgSizer5->Add( m_staticText221, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxBOTTOM|wxRIGHT, 5 ); + + fgSizer5->Add( 0, 0, 1, wxEXPAND|wxRIGHT, 5 ); + m_textCtrlDefaultTextThickness = new wxTextCtrl( m_swGeneralOpts, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizer5->Add( m_textCtrlDefaultTextThickness, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 5 ); @@ -562,7 +548,7 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c bSizerGeneralOpts->Add( m_buttonDefault, 0, wxALL|wxEXPAND, 5 ); m_staticline9 = new wxStaticLine( m_swGeneralOpts, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); - bSizerGeneralOpts->Add( m_staticline9, 0, wxEXPAND | wxALL, 5 ); + bSizerGeneralOpts->Add( m_staticline9, 0, wxALL, 5 ); wxBoxSizer* bSizerGeneraMargins; bSizerGeneraMargins = new wxBoxSizer( wxVERTICAL ); @@ -572,9 +558,9 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c bSizerGeneraMargins->Add( m_staticTextMargins, 0, wxALL, 5 ); wxFlexGridSizer* fgSizer6; - fgSizer6 = new wxFlexGridSizer( 0, 4, 0, 0 ); + fgSizer6 = new wxFlexGridSizer( 0, 5, 0, 0 ); fgSizer6->AddGrowableCol( 0 ); - fgSizer6->AddGrowableCol( 2 ); + fgSizer6->AddGrowableCol( 3 ); fgSizer6->SetFlexibleDirection( wxBOTH ); fgSizer6->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); @@ -583,6 +569,9 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c fgSizer6->Add( m_staticTextLeftMargin, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); + fgSizer6->Add( 0, 0, 1, wxEXPAND, 5 ); + + fgSizer6->Add( 0, 0, 1, wxEXPAND, 5 ); m_staticTextDefRightMargin = new wxStaticText( m_swGeneralOpts, wxID_ANY, _("Right:"), wxDefaultPosition, wxDefaultSize, 0 ); @@ -599,6 +588,9 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c m_units142->Wrap( -1 ); fgSizer6->Add( m_units142, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxRIGHT, 5 ); + + fgSizer6->Add( 0, 0, 1, wxEXPAND|wxRIGHT, 5 ); + m_textCtrlRightMargin = new wxTextCtrl( m_swGeneralOpts, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizer6->Add( m_textCtrlRightMargin, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); @@ -611,6 +603,9 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c fgSizer6->Add( m_staticTextTopMargin, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); + fgSizer6->Add( 0, 0, 1, wxEXPAND, 5 ); + + fgSizer6->Add( 0, 0, 1, wxEXPAND, 5 ); m_staticTextBottomMargin = new wxStaticText( m_swGeneralOpts, wxID_ANY, _("Bottom:"), wxDefaultPosition, wxDefaultSize, 0 ); @@ -627,6 +622,9 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c m_units1431->Wrap( -1 ); fgSizer6->Add( m_units1431, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxBOTTOM|wxRIGHT, 5 ); + + fgSizer6->Add( 0, 0, 1, wxEXPAND, 5 ); + m_textCtrlDefaultBottomMargin = new wxTextCtrl( m_swGeneralOpts, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizer6->Add( m_textCtrlDefaultBottomMargin, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 5 ); @@ -638,11 +636,10 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c bSizerGeneraMargins->Add( fgSizer6, 1, wxEXPAND, 5 ); - bSizerGeneralOpts->Add( bSizerGeneraMargins, 0, wxEXPAND, 5 ); - - m_buttonGeneralOptsOK = new wxButton( m_swGeneralOpts, wxID_ANY, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 ); - m_buttonGeneralOptsOK->SetDefault(); + bSizerGeneralOpts->Add( bSizerGeneraMargins, 0, wxEXPAND|wxBOTTOM, 15 ); + m_buttonGeneralOptsOK = new wxButton( m_swGeneralOpts, wxID_ANY, _("Apply"), wxDefaultPosition, wxDefaultSize, 0 ); + m_buttonGeneralOptsOK->SetDefault(); bSizerGeneralOpts->Add( m_buttonGeneralOptsOK, 0, wxALL|wxEXPAND, 5 ); diff --git a/pagelayout_editor/dialogs/properties_frame_base.fbp b/pagelayout_editor/dialogs/properties_frame_base.fbp index 5d6a367773..d0a9f8c479 100644 --- a/pagelayout_editor/dialogs/properties_frame_base.fbp +++ b/pagelayout_editor/dialogs/properties_frame_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -14,7 +14,6 @@ properties_frame_base 1000 none - 1 properties_frame @@ -43,26 +42,19 @@ PANEL_PROPERTIES_BASE - 371,864 + 340,775 wxTAB_TRAVERSAL - + - - - - - - - @@ -148,14 +140,7 @@ - - - - - - - @@ -237,14 +222,7 @@ wxHSCROLL|wxTAB_TRAVERSAL|wxVSCROLL - - - - - - - @@ -274,415 +252,189 @@ none 5 - + wxEXPAND 0 bSizerButt wxHORIZONTAL none - + 5 - - 0 - + wxLEFT|wxRIGHT + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + ,90,90,-1,70,0 + 0 + 0 + wxID_ANY + Type + + 0 + + + 0 - bSizerType - wxVERTICAL - none - - 5 - wxLEFT|wxRIGHT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - ,90,92,-1,70,0 - 0 - 0 - wxID_ANY - Type: - 0 - - 0 - - - 0 - - 1 - m_staticTextType - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - - - -1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxRIGHT|wxLEFT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - 0 - - 0 - - 1 - m_textCtrlType - 1 - - - protected - 1 - - Resizable - 1 - - wxTE_READONLY - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + 1 + m_staticTextType + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + - + 5 - + wxEXPAND|wxRIGHT|wxLEFT 0 - + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + "Show on all pages" "First page only" "Subsequent pages only" + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 - bSizerPageOpt - wxVERTICAL - none - - 5 - wxLEFT|wxRIGHT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - ,90,90,-1,70,0 - 0 - 0 - wxID_ANY - Page 1 option: - 0 - - 0 - - - 0 - - 1 - m_staticTextPageOpt - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - - - -1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxRIGHT|wxLEFT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - "None" "Page 1 only" "Not on page 1" - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 - - 1 - m_choicePageOpt - 1 - - - protected - 1 - - Resizable - 2 - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + 1 + m_choicePageOpt + 1 + + + protected + 1 + + Resizable + 2 + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 - wxEXPAND|wxTOP|wxRIGHT|wxLEFT + wxTOP|wxRIGHT|wxLEFT|wxEXPAND 0 1 @@ -736,14 +488,7 @@ - - - - - - - @@ -771,7 +516,7 @@ 5 wxEXPAND - 0 + 1 m_SizerTextOptions @@ -810,7 +555,6 @@ 0 wxID_ANY Text: - 0 0 @@ -836,14 +580,7 @@ -1 - - - - - - - @@ -870,7 +607,7 @@ 5 - wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND + wxEXPAND|wxRIGHT|wxLEFT 1 1 @@ -930,14 +667,7 @@ - - - - - - - @@ -966,21 +696,21 @@ - + 5 - wxEXPAND + wxEXPAND|wxBOTTOM 0 - + bSizerFontOpt wxVERTICAL none - + 5 wxEXPAND - 1 - - 3 + 0 + + 4 wxBOTH @@ -993,7 +723,7 @@ 0 5 - wxALIGN_CENTER_VERTICAL|wxLEFT + wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT 0 1 @@ -1023,8 +753,7 @@ 0 0 wxID_ANY - Horizontal align: - 0 + H align: 0 @@ -1050,14 +779,7 @@ -1 - - - - - - - @@ -1084,7 +806,7 @@ 5 - wxEXPAND|wxALL + wxEXPAND|wxALL|wxALIGN_CENTER_VERTICAL 0 1 @@ -1144,14 +866,7 @@ - - - - - - - @@ -1177,9 +892,19 @@ + + 10 + wxEXPAND|wxRIGHT|wxLEFT + 1 + + 0 + protected + 0 + + 5 - wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT + wxALIGN_CENTER_VERTICAL|wxALL 0 1 @@ -1239,14 +964,7 @@ - - - - - - - @@ -1274,7 +992,7 @@ 5 - wxALIGN_CENTER_VERTICAL|wxLEFT + wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT 0 1 @@ -1304,8 +1022,7 @@ 0 0 wxID_ANY - Vertical align: - 0 + V align: 0 @@ -1331,14 +1048,7 @@ -1 - - - - - - - @@ -1365,7 +1075,7 @@ 5 - wxEXPAND|wxALL + wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL 0 1 @@ -1425,14 +1135,7 @@ - - - - - - - @@ -1460,7 +1163,17 @@ 5 - wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT + wxEXPAND|wxRIGHT|wxLEFT + 1 + + 0 + protected + 0 + + + + 5 + wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT 0 1 @@ -1520,14 +1233,7 @@ - - - - - - - @@ -1557,193 +1263,14 @@ - - 5 - wxEXPAND | wxALL - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 - - 1 - m_staticline81 - 1 - - - protected - 1 - - Resizable - 1 - - wxLI_HORIZONTAL - ; forward_declare - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxTOP|wxRIGHT|wxLEFT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Set to 0 to use default values - 0 - - 0 - - - 0 - - 1 - m_staticTextSizeInfo - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - - - -1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + 5 wxEXPAND - 1 - - 4 + 0 + + 5 wxBOTH - 0,2 + 0,3 0 @@ -1785,7 +1312,6 @@ 0 wxID_ANY Text width: - 0 0 @@ -1811,14 +1337,7 @@ -1 - - - - - - - @@ -1846,13 +1365,23 @@ 5 wxEXPAND - 1 + 0 0 protected 0 + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + 5 wxRIGHT|wxLEFT @@ -1886,7 +1415,6 @@ 0 wxID_ANY Text height: - 0 0 @@ -1912,14 +1440,7 @@ -1 - - - - - - - @@ -1947,7 +1468,7 @@ 5 wxEXPAND - 1 + 0 0 protected @@ -2016,14 +1537,7 @@ - - - - - - - @@ -2085,7 +1599,6 @@ 0 wxID_ANY mm - 0 0 @@ -2111,14 +1624,7 @@ -1 - - - - - - - @@ -2143,6 +1649,16 @@ + + 5 + wxEXPAND|wxRIGHT|wxLEFT + 1 + + 0 + protected + 0 + + 5 wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT @@ -2205,14 +1721,7 @@ - - - - - - - @@ -2274,7 +1783,6 @@ 0 wxID_ANY mm - 0 0 @@ -2300,14 +1808,7 @@ -1 - - - - - - - @@ -2334,128 +1835,7 @@ 5 - wxLEFT|wxRIGHT|wxTOP - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Constraints: - 0 - - 0 - - - 0 - - 1 - m_staticTextConstraints - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - - - -1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxEXPAND - 1 - - 0 - protected - 0 - - - - 5 - wxEXPAND - 1 - - 0 - protected - 0 - - - - 5 - wxEXPAND - 1 - - 0 - protected - 0 - - - - 5 - wxRIGHT|wxLEFT + wxTOP|wxRIGHT|wxLEFT 0 1 @@ -2486,7 +1866,6 @@ 0 wxID_ANY Maximum width: - 0 0 @@ -2512,14 +1891,7 @@ -1 - - - - - - - @@ -2544,10 +1916,20 @@ - + 5 wxEXPAND 1 + + 0 + protected + 0 + + + + 5 + wxEXPAND + 0 0 protected @@ -2556,7 +1938,7 @@ 5 - wxRIGHT|wxLEFT + wxTOP|wxRIGHT|wxLEFT 0 1 @@ -2587,7 +1969,6 @@ 0 wxID_ANY Maximum height: - 0 0 @@ -2613,14 +1994,7 @@ -1 - - - - - - - @@ -2648,7 +2022,7 @@ 5 wxEXPAND - 1 + 0 0 protected @@ -2717,14 +2091,7 @@ - - - - - - - @@ -2786,7 +2153,6 @@ 0 wxID_ANY mm - 0 0 @@ -2812,14 +2178,7 @@ -1 - - - - - - - @@ -2844,6 +2203,16 @@ + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + 5 wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT @@ -2906,14 +2275,7 @@ - - - - - - - @@ -2975,7 +2337,6 @@ 0 wxID_ANY mm - 0 0 @@ -3001,14 +2362,7 @@ -1 - - - - - - - @@ -3035,6 +2389,89 @@ + + 5 + wxBOTTOM|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Set to 0 to use default values + + 0 + + + 0 + + 1 + m_staticTextSizeInfo + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + 5 wxEXPAND|wxRIGHT|wxLEFT @@ -3091,14 +2528,7 @@ - - - - - - - @@ -3140,31 +2570,25 @@ - 1 0 1 1 - 1 0 - Dock 0 Left 1 1 - 0 0 wxID_ANY - Accept - - 0 + Apply 0 @@ -3179,8 +2603,6 @@ protected 1 - - Resizable 1 @@ -3195,15 +2617,8 @@ - - - - - - OnAcceptPrms - @@ -3230,7 +2645,7 @@ 5 - wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT + wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND 0 1 @@ -3284,14 +2699,7 @@ - - - - - - - @@ -3318,7 +2726,7 @@ 5 - wxTOP|wxRIGHT|wxLEFT + wxRIGHT|wxLEFT 0 1 @@ -3349,7 +2757,6 @@ 0 wxID_ANY Comment: - 0 0 @@ -3375,14 +2782,7 @@ -1 - - - - - - - @@ -3469,14 +2869,7 @@ - - - - - - - @@ -3507,7 +2900,7 @@ 5 - wxEXPAND|wxRIGHT|wxLEFT + wxRIGHT|wxLEFT|wxEXPAND 0 1 @@ -3561,14 +2954,7 @@ - - - - - - - @@ -3602,14 +2988,14 @@ bSizerPos wxHORIZONTAL none - + 5 - wxEXPAND|wxRIGHT - 1 - - 2 - wxBOTH - 0 + wxEXPAND|wxTOP|wxBOTTOM|wxRIGHT + 0 + + 3 + wxHORIZONTAL + 1 0 @@ -3620,7 +3006,7 @@ 0 5 - wxTOP|wxRIGHT|wxLEFT + wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT 0 1 @@ -3650,8 +3036,7 @@ 0 0 wxID_ANY - Start X: - 0 + X: 0 @@ -3677,14 +3062,7 @@ -1 - - - - - - - @@ -3711,18 +3089,8 @@ 5 - wxEXPAND - 1 - - 0 - protected - 0 - - - - 5 - wxEXPAND|wxBOTTOM|wxLEFT|wxALIGN_CENTER_VERTICAL - 1 + wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM + 0 1 1 @@ -3781,14 +3149,7 @@ - - - - - - - @@ -3850,7 +3211,6 @@ 0 wxID_ANY mm - 0 0 @@ -3876,14 +3236,7 @@ -1 - - - - - - - @@ -3910,7 +3263,7 @@ 5 - wxRIGHT|wxLEFT + wxBOTTOM|wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL 0 1 @@ -3940,8 +3293,7 @@ 0 0 wxID_ANY - Start Y: - 0 + Y: 0 @@ -3967,14 +3319,7 @@ -1 - - - - - - - @@ -4001,17 +3346,7 @@ 5 - wxEXPAND - 1 - - 0 - protected - 0 - - - - 5 - wxEXPAND|wxALIGN_CENTER_VERTICAL|wxLEFT + wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM 0 1 @@ -4071,14 +3406,7 @@ - - - - - - - @@ -4109,7 +3437,7 @@ 5 - wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT + wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxBOTTOM 0 1 @@ -4140,7 +3468,6 @@ 0 wxID_ANY mm - 0 0 @@ -4166,14 +3493,7 @@ -1 - - - - - - - @@ -4200,11 +3520,11 @@ - + 5 wxALIGN_CENTER_VERTICAL 0 - + bSizer6 wxVERTICAL @@ -4241,8 +3561,7 @@ 0 0 wxID_ANY - Origin: - 0 + From: 0 @@ -4268,14 +3587,7 @@ -1 - - - - - - - @@ -4302,7 +3614,7 @@ 5 - wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND + wxBOTTOM|wxRIGHT|wxLEFT 0 1 @@ -4338,7 +3650,7 @@ 0 - + 132,-1 1 m_comboBoxCornerPos 1 @@ -4350,7 +3662,7 @@ Resizable 2 1 - + -1,-1 0 @@ -4363,14 +3675,7 @@ - - - - - - - @@ -4406,21 +3711,21 @@ 5 - wxEXPAND + wxTOP|wxBOTTOM|wxEXPAND 0 m_SizerEndPosition wxHORIZONTAL protected - + 5 wxEXPAND|wxRIGHT - 1 - - 2 - wxBOTH - 0 + 0 + + 3 + wxHORIZONTAL + 1 0 @@ -4431,7 +3736,7 @@ 0 5 - wxTOP|wxRIGHT|wxLEFT + wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT 0 1 @@ -4461,8 +3766,7 @@ 0 0 wxID_ANY - End X: - 0 + X: 0 @@ -4488,14 +3792,7 @@ -1 - - - - - - - @@ -4522,17 +3819,7 @@ 5 - wxEXPAND - 1 - - 0 - protected - 0 - - - - 5 - wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT + wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM 0 1 @@ -4592,14 +3879,7 @@ - - - - - - - @@ -4661,7 +3941,6 @@ 0 wxID_ANY mm - 0 0 @@ -4687,14 +3966,7 @@ -1 - - - - - - - @@ -4721,7 +3993,7 @@ 5 - wxTOP|wxRIGHT|wxLEFT + wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT 0 1 @@ -4751,8 +4023,7 @@ 0 0 wxID_ANY - End Y: - 0 + Y: 0 @@ -4778,14 +4049,7 @@ -1 - - - - - - - @@ -4812,17 +4076,7 @@ 5 - wxEXPAND - 1 - - 0 - protected - 0 - - - - 5 - wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT + wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM 0 1 @@ -4882,14 +4136,7 @@ - - - - - - - @@ -4951,7 +4198,6 @@ 0 wxID_ANY mm - 0 0 @@ -4977,14 +4223,7 @@ -1 - - - - - - - @@ -5011,11 +4250,11 @@ - + 5 wxALIGN_CENTER_VERTICAL 0 - + bSizer61 wxVERTICAL @@ -5052,8 +4291,7 @@ 0 0 wxID_ANY - Origin: - 0 + From: 0 @@ -5079,14 +4317,7 @@ -1 - - - - - - - @@ -5113,7 +4344,7 @@ 5 - wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND + wxBOTTOM|wxRIGHT|wxLEFT 0 1 @@ -5149,7 +4380,7 @@ 0 - + 132,-1 1 m_comboBoxCornerEnd 1 @@ -5161,7 +4392,7 @@ Resizable 3 1 - + -1,-1 0 @@ -5174,14 +4405,7 @@ - - - - - - - @@ -5217,216 +4441,16 @@ 5 - + wxTOP|wxBOTTOM 0 m_SizerLineThickness wxHORIZONTAL protected - - 5 - wxEXPAND - 0 - - - bSizerThickness - wxVERTICAL - none - - 5 - wxLEFT|wxRIGHT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Thickness: - 0 - - 0 - - - 0 - - 1 - m_staticTextThickness - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - - - -1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxBOTTOM|wxRIGHT|wxLEFT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - 0 - - 0 - - 1 - m_textCtrlThickness - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxALIGN_CENTER|wxALL + wxBOTTOM|wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL 0 1 @@ -5456,8 +4480,181 @@ 0 0 wxID_ANY - Set to 0 to use default - 0 + Line width: + + 0 + + + 0 + + 1 + m_staticTextThickness + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + 0 + + 0 + + 1 + m_textCtrlThickness + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALIGN_CENTER|wxBOTTOM|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Set to 0 for default 0 @@ -5483,14 +4680,7 @@ -1 - - - - - - - @@ -5582,14 +4772,7 @@ - - - - - - - @@ -5614,11 +4797,11 @@ - + 5 wxEXPAND - 1 - + 0 + 2 wxBOTH @@ -5632,7 +4815,7 @@ 0 5 - wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL + wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT 0 1 @@ -5663,7 +4846,6 @@ 0 wxID_ANY Rotation: - 0 0 @@ -5689,14 +4871,7 @@ -1 - - - - - - - @@ -5723,7 +4898,7 @@ 5 - wxALIGN_CENTER_VERTICAL|wxALL|wxLEFT|wxRIGHT + wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT 0 1 @@ -5783,14 +4958,7 @@ - - - - - - - @@ -5821,7 +4989,7 @@ 5 - wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL + wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT 0 1 @@ -5852,7 +5020,6 @@ 0 wxID_ANY Bitmap PPI: - 0 0 @@ -5878,14 +5045,7 @@ -1 - - - - - - - @@ -5912,7 +5072,7 @@ 5 - wxALIGN_CENTER_VERTICAL|wxALL|wxLEFT|wxRIGHT + wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT 0 1 @@ -5972,14 +5132,7 @@ - - - - - - - @@ -6014,7 +5167,7 @@ 5 - wxEXPAND|wxTOP|wxRIGHT|wxLEFT + wxTOP|wxRIGHT|wxLEFT|wxEXPAND 0 1 @@ -6068,105 +5221,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxTOP|wxRIGHT|wxLEFT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Repeat parameters: - 0 - - 0 - - - 0 - - 1 - m_staticTextRepeatPrms - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - - - -1 - - - - - - - - @@ -6194,11 +5249,11 @@ 5 wxEXPAND - 1 + 0 - 4 + 5 wxBOTH - 0,2 + 0,3 0 @@ -6240,7 +5295,6 @@ 0 wxID_ANY Repeat count: - 0 0 @@ -6266,14 +5320,7 @@ -1 - - - - - - - @@ -6301,13 +5348,23 @@ 5 wxEXPAND - 1 + 0 0 protected 0 + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + 5 wxTOP|wxRIGHT|wxLEFT @@ -6340,8 +5397,7 @@ 0 0 wxID_ANY - Text Increment: - 0 + Step text: 0 @@ -6367,14 +5423,7 @@ -1 - - - - - - - @@ -6402,7 +5451,7 @@ 5 wxEXPAND - 1 + 0 0 protected @@ -6411,7 +5460,7 @@ 5 - wxRIGHT|wxLEFT|wxEXPAND + wxEXPAND|wxLEFT 0 1 @@ -6471,14 +5520,7 @@ - - - - - - - @@ -6510,16 +5552,26 @@ 5 wxEXPAND - 1 + 0 0 protected 0 + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + 5 - wxRIGHT|wxLEFT|wxEXPAND + wxEXPAND|wxLEFT 0 1 @@ -6579,14 +5631,7 @@ - - - - - - - @@ -6618,7 +5663,7 @@ 5 wxEXPAND - 1 + 0 0 protected @@ -6658,7 +5703,6 @@ 0 wxID_ANY Step X: - 0 0 @@ -6684,14 +5728,7 @@ -1 - - - - - - - @@ -6719,13 +5756,23 @@ 5 wxEXPAND - 1 + 0 0 protected 0 + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + 5 wxTOP|wxRIGHT|wxLEFT @@ -6759,7 +5806,6 @@ 0 wxID_ANY Step Y: - 0 0 @@ -6785,14 +5831,7 @@ -1 - - - - - - - @@ -6820,7 +5859,7 @@ 5 wxEXPAND - 1 + 0 0 protected @@ -6865,7 +5904,7 @@ 0 0 - + -1,-1 1 m_textCtrlStepX 1 @@ -6876,7 +5915,7 @@ Resizable 1 - + -1,-1 0 @@ -6889,14 +5928,7 @@ - - - - - - - @@ -6958,7 +5990,6 @@ 0 wxID_ANY mm - 0 0 @@ -6984,14 +6015,7 @@ -1 - - - - - - - @@ -7016,6 +6040,16 @@ + + 5 + wxEXPAND|wxLEFT + 1 + + 0 + protected + 0 + + 5 wxEXPAND|wxBOTTOM|wxLEFT|wxALIGN_CENTER_VERTICAL @@ -7078,14 +6112,7 @@ - - - - - - - @@ -7147,7 +6174,6 @@ 0 wxID_ANY mm - 0 0 @@ -7173,14 +6199,7 @@ -1 - - - - - - - @@ -7267,14 +6286,7 @@ wxHSCROLL|wxTAB_TRAVERSAL|wxVSCROLL - - - - - - - @@ -7344,7 +6356,6 @@ 0 wxID_ANY Default Values: - 0 0 @@ -7370,14 +6381,7 @@ -1 - - - - - - - @@ -7407,9 +6411,9 @@ wxEXPAND 1 - 4 + 5 wxBOTH - 0,2 + 0,3 0 @@ -7451,7 +6455,6 @@ 0 wxID_ANY Text width: - 0 0 @@ -7477,14 +6480,7 @@ -1 - - - - - - - @@ -7519,6 +6515,16 @@ 0 + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + 5 wxTOP|wxRIGHT|wxLEFT @@ -7552,7 +6558,6 @@ 0 wxID_ANY Text height: - 0 0 @@ -7578,14 +6583,7 @@ -1 - - - - - - - @@ -7682,14 +6680,7 @@ - - - - - - - @@ -7751,7 +6742,6 @@ 0 wxID_ANY mm - 0 0 @@ -7777,14 +6767,7 @@ -1 - - - - - - - @@ -7809,6 +6792,16 @@ + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + 5 wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT @@ -7871,14 +6864,7 @@ - - - - - - - @@ -7940,7 +6926,6 @@ 0 wxID_ANY mm - 0 0 @@ -7966,14 +6951,7 @@ -1 - - - - - - - @@ -8031,7 +7009,6 @@ 0 wxID_ANY Line thickness: - 0 0 @@ -8057,14 +7034,7 @@ -1 - - - - - - - @@ -8099,6 +7069,16 @@ 0 + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + 5 wxEXPAND|wxLEFT|wxRIGHT|wxTOP @@ -8132,7 +7112,6 @@ 0 wxID_ANY Text thickness: - 0 0 @@ -8158,14 +7137,7 @@ -1 - - - - - - - @@ -8262,14 +7234,7 @@ - - - - - - - @@ -8331,7 +7296,6 @@ 0 wxID_ANY mm - 0 0 @@ -8357,14 +7321,7 @@ -1 - - - - - - - @@ -8389,6 +7346,16 @@ + + 5 + wxEXPAND|wxRIGHT + 1 + + 0 + protected + 0 + + 5 wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT @@ -8451,14 +7418,7 @@ - - - - - - - @@ -8487,11 +7447,11 @@ - + 5 wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT 0 - + 1 1 1 @@ -8520,7 +7480,6 @@ 0 wxID_ANY mm - 0 0 @@ -8546,14 +7505,7 @@ -1 - - - - - - - @@ -8607,31 +7559,25 @@ - 1 0 1 1 - 0 0 - Dock 0 Left 1 1 - 0 0 wxID_ANY Set to Default - - 0 0 @@ -8646,8 +7592,6 @@ protected 1 - - Resizable 1 @@ -8662,15 +7606,8 @@ - - - - - - OnSetDefaultValues - @@ -8697,7 +7634,7 @@ 5 - wxEXPAND | wxALL + wxALL 0 1 @@ -8751,14 +7688,7 @@ - - - - - - - @@ -8784,8 +7714,8 @@ - 5 - wxEXPAND + 15 + wxEXPAND|wxBOTTOM 0 @@ -8825,7 +7755,6 @@ 0 wxID_ANY Page Margins: - 0 0 @@ -8851,14 +7780,7 @@ -1 - - - - - - - @@ -8888,9 +7810,9 @@ wxEXPAND 1 - 4 + 5 wxBOTH - 0,2 + 0,3 0 @@ -8932,7 +7854,6 @@ 0 wxID_ANY Left: - 0 0 @@ -8958,14 +7879,7 @@ -1 - - - - - - - @@ -9000,6 +7914,16 @@ 0 + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + 5 wxTOP|wxRIGHT|wxLEFT @@ -9033,7 +7957,6 @@ 0 wxID_ANY Right: - 0 0 @@ -9059,14 +7982,7 @@ -1 - - - - - - - @@ -9163,14 +8079,7 @@ - - - - - - - @@ -9232,7 +8141,6 @@ 0 wxID_ANY mm - 0 0 @@ -9258,14 +8166,7 @@ -1 - - - - - - - @@ -9290,6 +8191,16 @@ + + 5 + wxEXPAND|wxRIGHT + 1 + + 0 + protected + 0 + + 5 wxEXPAND|wxALIGN_CENTER_VERTICAL|wxLEFT @@ -9352,14 +8263,7 @@ - - - - - - - @@ -9421,7 +8325,6 @@ 0 wxID_ANY mm - 0 0 @@ -9447,14 +8350,7 @@ -1 - - - - - - - @@ -9512,7 +8408,6 @@ 0 wxID_ANY Top: - 0 0 @@ -9538,14 +8433,7 @@ -1 - - - - - - - @@ -9570,6 +8458,16 @@ + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + 5 wxEXPAND @@ -9613,7 +8511,6 @@ 0 wxID_ANY Bottom: - 0 0 @@ -9639,14 +8536,7 @@ -1 - - - - - - - @@ -9743,14 +8633,7 @@ - - - - - - - @@ -9812,7 +8695,6 @@ 0 wxID_ANY mm - 0 0 @@ -9838,14 +8720,7 @@ -1 - - - - - - - @@ -9870,6 +8745,16 @@ + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + 5 wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT @@ -9932,14 +8817,7 @@ - - - - - - - @@ -10001,7 +8879,6 @@ 0 wxID_ANY mm - 0 0 @@ -10027,14 +8904,7 @@ -1 - - - - - - - @@ -10078,31 +8948,25 @@ - 1 0 1 1 - 1 0 - Dock 0 Left 1 1 - 0 0 wxID_ANY - Accept - - 0 + Apply 0 @@ -10117,8 +8981,6 @@ protected 1 - - Resizable 1 @@ -10133,15 +8995,8 @@ - - - - - - OnAcceptPrms - diff --git a/pagelayout_editor/dialogs/properties_frame_base.h b/pagelayout_editor/dialogs/properties_frame_base.h index 39282a0cc9..f3abdd7734 100644 --- a/pagelayout_editor/dialogs/properties_frame_base.h +++ b/pagelayout_editor/dialogs/properties_frame_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Jul 11 2018) +// C++ code generated with wxFormBuilder (version Dec 30 2017) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -17,17 +17,17 @@ #include #include #include -#include -#include #include +#include #include +#include #include -#include -#include -#include #include #include #include +#include +#include +#include #include #include @@ -44,8 +44,6 @@ class PANEL_PROPERTIES_BASE : public wxPanel wxNotebook* m_notebook; wxScrolledWindow* m_swItemProperties; wxStaticText* m_staticTextType; - wxTextCtrl* m_textCtrlType; - wxStaticText* m_staticTextPageOpt; wxChoice* m_choicePageOpt; wxStaticLine* m_staticline5; wxBoxSizer* m_SizerTextOptions; @@ -57,21 +55,19 @@ class PANEL_PROPERTIES_BASE : public wxPanel wxStaticText* m_staticTextVjust; wxChoice* m_choiceVjustify; wxCheckBox* m_checkBoxItalic; - wxStaticLine* m_staticline81; - wxStaticText* m_staticTextSizeInfo; wxStaticText* m_staticTexTsizeX; wxStaticText* m_staticTextTsizeY; wxTextCtrl* m_textCtrlTextSizeX; wxStaticText* m_units1; wxTextCtrl* m_textCtrlTextSizeY; wxStaticText* m_units11; - wxStaticText* m_staticTextConstraints; wxStaticText* m_staticTextConstraintX; wxStaticText* m_staticTextConstraintY; wxTextCtrl* m_textCtrlConstraintX; wxStaticText* m_units111; wxTextCtrl* m_textCtrlConstraintY; wxStaticText* m_units1111; + wxStaticText* m_staticTextSizeInfo; wxStaticLine* m_staticline6; wxButton* m_buttonOK; wxStaticLine* m_staticline8; @@ -106,7 +102,6 @@ class PANEL_PROPERTIES_BASE : public wxPanel wxStaticText* m_staticTextBitmapPPI; wxTextCtrl* m_textCtrlBitmapPPI; wxStaticLine* m_staticline4; - wxStaticText* m_staticTextRepeatPrms; wxStaticText* m_staticTextRepeatCnt; wxStaticText* m_staticTextInclabel; wxTextCtrl* m_textCtrlRepeatCount; @@ -155,7 +150,7 @@ class PANEL_PROPERTIES_BASE : public wxPanel public: - PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 371,864 ), long style = wxTAB_TRAVERSAL ); + PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 340,775 ), long style = wxTAB_TRAVERSAL ); ~PANEL_PROPERTIES_BASE(); }; diff --git a/pagelayout_editor/events_functions.cpp b/pagelayout_editor/events_functions.cpp index ece1298b19..196cb960de 100644 --- a/pagelayout_editor/events_functions.cpp +++ b/pagelayout_editor/events_functions.cpp @@ -40,22 +40,15 @@ #include #include #include -#include +#include #include -#include -#include #include #include +#include BEGIN_EVENT_TABLE( PL_EDITOR_FRAME, EDA_DRAW_FRAME ) EVT_CLOSE( PL_EDITOR_FRAME::OnCloseWindow ) - - // Desing tree event: - EVT_TREE_SEL_CHANGED( ID_DESIGN_TREE_FRAME, PL_EDITOR_FRAME::OnTreeSelection ) - EVT_TREE_ITEM_MIDDLE_CLICK( ID_DESIGN_TREE_FRAME, PL_EDITOR_FRAME::OnTreeMiddleClick ) - EVT_TREE_ITEM_RIGHT_CLICK( ID_DESIGN_TREE_FRAME, PL_EDITOR_FRAME::OnTreeRightClick ) - // Menu Files: EVT_MENU( wxID_NEW, PL_EDITOR_FRAME::Files_io ) EVT_MENU( wxID_OPEN, PL_EDITOR_FRAME::Files_io ) @@ -73,36 +66,21 @@ BEGIN_EVENT_TABLE( PL_EDITOR_FRAME, EDA_DRAW_FRAME ) // menu Preferences EVT_MENU( ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST, PL_EDITOR_FRAME::Process_Config ) EVT_MENU( wxID_PREFERENCES, PL_EDITOR_FRAME::Process_Config ) - EVT_MENU( ID_MENU_SWITCH_BGCOLOR, PL_EDITOR_FRAME::Process_Config ) - EVT_MENU( ID_MENU_GRID_ONOFF, PL_EDITOR_FRAME::Process_Config ) EVT_TOOL( wxID_DELETE, PL_EDITOR_FRAME::Process_Special_Functions ) - EVT_TOOL( wxID_UNDO, PL_EDITOR_FRAME::GetLayoutFromUndoList ) - EVT_TOOL( wxID_REDO, PL_EDITOR_FRAME::GetLayoutFromRedoList ) EVT_TOOL( wxID_PRINT, PL_EDITOR_FRAME::ToPrinter ) EVT_TOOL( wxID_PREVIEW, PL_EDITOR_FRAME::ToPrinter ) EVT_TOOL( ID_SHEET_SET, PL_EDITOR_FRAME::Process_Special_Functions ) EVT_TOOL( ID_SHOW_REAL_MODE, PL_EDITOR_FRAME::OnSelectTitleBlockDisplayMode ) EVT_TOOL( ID_SHOW_PL_EDITOR_MODE, PL_EDITOR_FRAME::OnSelectTitleBlockDisplayMode ) - EVT_TOOL( ID_NO_TOOL_SELECTED, PL_EDITOR_FRAME::Process_Special_Functions ) - EVT_TOOL( ID_ZOOM_SELECTION, PL_EDITOR_FRAME::Process_Special_Functions ) EVT_CHOICE( ID_SELECT_COORDINATE_ORIGIN, PL_EDITOR_FRAME::OnSelectCoordOriginCorner) EVT_CHOICE( ID_SELECT_PAGE_NUMBER, PL_EDITOR_FRAME::Process_Special_Functions) - // the ID_NO_TOOL_SELECTED id TOOL does not existing currently, but the right click - // popup menu can generate this event. - EVT_TOOL( ID_NO_TOOL_SELECTED, PL_EDITOR_FRAME::Process_Special_Functions ) - EVT_TOOL( ID_POPUP_CANCEL_CURRENT_COMMAND, PL_EDITOR_FRAME::Process_Special_Functions ) - EVT_MENU_RANGE( ID_POPUP_START_RANGE, ID_POPUP_END_RANGE, PL_EDITOR_FRAME::Process_Special_Functions ) - EVT_UPDATE_UI( ID_NO_TOOL_SELECTED, PL_EDITOR_FRAME::OnUpdateSelectTool ) - - EVT_UPDATE_UI( ID_ZOOM_SELECTION, PL_EDITOR_FRAME::OnUpdateSelectTool ) EVT_UPDATE_UI( ID_SHOW_REAL_MODE, PL_EDITOR_FRAME::OnUpdateTitleBlockDisplayNormalMode ) EVT_UPDATE_UI( ID_SHOW_PL_EDITOR_MODE, PL_EDITOR_FRAME::OnUpdateTitleBlockDisplaySpecialMode ) - END_EVENT_TABLE() @@ -110,28 +88,11 @@ END_EVENT_TABLE() */ void PL_EDITOR_FRAME::Process_Special_Functions( wxCommandEvent& event ) { - int id = event.GetId(); - int idx; - wxString msg; - WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance(); - WORKSHEET_DATAITEM* item = NULL; wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); cmd.SetEventObject( this ); - switch( id ) + switch( event.GetId() ) { - case ID_NO_TOOL_SELECTED: - SetNoToolSelected(); - break; - - case ID_ZOOM_SELECTION: - // This tool is located on the main toolbar: switch it on or off on click - if( GetToolId() != ID_ZOOM_SELECTION ) - SetToolID( ID_ZOOM_SELECTION, wxCURSOR_MAGNIFIER, _( "Zoom to selection" ) ); - else - SetNoToolSelected(); - break; - case ID_SELECT_PAGE_NUMBER: m_canvas->Refresh(); break; @@ -149,192 +110,15 @@ void PL_EDITOR_FRAME::Process_Special_Functions( wxCommandEvent& event ) } break; - case ID_POPUP_CANCEL_CURRENT_COMMAND: - if( m_canvas->IsMouseCaptured() ) - { - m_canvas->EndMouseCapture(); - SetToolID( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString ); - } - else - { - SetNoToolSelected(); - } - break; - - case ID_POPUP_DESIGN_TREE_ITEM_DELETE: - case ID_POPUP_ITEM_DELETE: - case wxID_DELETE: - // Delete item, and select the previous item - item = m_treePagelayout->GetPageLayoutSelectedItem(); - - if( item == NULL ) - break; - - SaveCopyInUndoList(); - idx = pglayout.GetItemIndex( item ); - pglayout.Remove( item ); - RebuildDesignTree(); - - if( id == ID_POPUP_DESIGN_TREE_ITEM_DELETE ) - { - item = pglayout.GetItem( (unsigned) (idx-1) ); - - if( item ) - m_treePagelayout->SelectCell( item ); - } - - item = NULL; - OnModify(); - m_canvas->Refresh(); - break; - - case ID_POPUP_ITEM_ADD_LINE: - SaveCopyInUndoList(); - idx = m_treePagelayout->GetSelectedItemIndex(); - item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_SEGMENT, idx ); - - if( InvokeDialogNewItem( this, item ) == wxID_CANCEL ) - { - RemoveLastCommandInUndoList(); - pglayout.Remove( item ); - RebuildDesignTree(); - item = NULL; - } - else - { - // Put the new item in move mode, after putting the cursor - // on the start point: - wxPoint position = item->GetStartPosUi(); - SetCrossHairPosition( position, false ); - position = GetCrossHairPosition(); - - if( m_canvas->IsPointOnDisplay( position ) ) - m_canvas->MoveCursorToCrossHair(); - else - RedrawScreen( position, true ); - - item->SetFlags( NEW_ITEM ); - MoveItem( item ); - } - break; - - case ID_POPUP_ITEM_ADD_RECT: - SaveCopyInUndoList(); - idx = m_treePagelayout->GetSelectedItemIndex(); - item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_RECT, idx ); - - if( InvokeDialogNewItem( this, item ) == wxID_CANCEL ) - { - RemoveLastCommandInUndoList(); - pglayout.Remove( item ); - RebuildDesignTree(); - item = NULL; - } - else - { - // Put the new item in move mode, after putting the cursor - // on the start point: - wxPoint position = item->GetStartPosUi(); - SetCrossHairPosition( position, false ); - position = GetCrossHairPosition(); - - if( m_canvas->IsPointOnDisplay( position ) ) - m_canvas->MoveCursorToCrossHair(); - else - RedrawScreen( position, true ); - - item->SetFlags( NEW_ITEM ); - MoveItem( item ); - } - break; - - case ID_POPUP_ITEM_ADD_TEXT: - SaveCopyInUndoList(); - idx = m_treePagelayout->GetSelectedItemIndex(); - item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_TEXT, idx ); - if( InvokeDialogNewItem( this, item ) == wxID_CANCEL ) - { - RemoveLastCommandInUndoList(); - pglayout.Remove( item ); - RebuildDesignTree(); - item = NULL; - } - else - { - // Put the new text in move mode: - item->SetFlags( NEW_ITEM | LOCATE_STARTPOINT ); - MoveItem( item ); - } - break; - - case ID_POPUP_ITEM_ADD_BITMAP: - SaveCopyInUndoList(); - idx = m_treePagelayout->GetSelectedItemIndex(); - item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_BITMAP, idx ); - if( item && InvokeDialogNewItem( this, item ) == wxID_CANCEL ) - { - RemoveLastCommandInUndoList(); - pglayout.Remove( item ); - RebuildDesignTree(); - item = NULL; - } - if( item ) - { - // Put the new text in move mode: - item->SetFlags( NEW_ITEM | LOCATE_STARTPOINT ); - MoveItem( item ); - } - break; - case ID_POPUP_ITEM_APPEND_PAGE_LAYOUT: cmd.SetId( ID_APPEND_DESCR_FILE ); wxPostEvent( this, cmd ); break; - case ID_POPUP_ITEM_PLACE: - item = GetScreen()->GetCurItem(); - PlaceItem( item ); - break; - - case ID_POPUP_ITEM_PLACE_CANCEL: - if( m_canvas->IsMouseCaptured() ) - m_canvas->EndMouseCapture(); - break; - - case ID_POPUP_ITEM_MOVE_START_POINT: - item = m_treePagelayout->GetPageLayoutSelectedItem(); - // Ensure flags are properly set - item->ClearFlags( LOCATE_ENDPOINT ); - item->SetFlags( LOCATE_STARTPOINT ); - MoveItem( item ); - break; - - case ID_POPUP_ITEM_MOVE_END_POINT: - item = m_treePagelayout->GetPageLayoutSelectedItem(); - // Ensure flags are properly set - item->ClearFlags( LOCATE_STARTPOINT ); - item->SetFlags( LOCATE_ENDPOINT ); - MoveItem( item ); - break; - - case ID_POPUP_ITEM_MOVE: - item = m_treePagelayout->GetPageLayoutSelectedItem(); - item->ClearFlags( LOCATE_ENDPOINT|LOCATE_STARTPOINT ); - MoveItem( item ); - break; - default: wxMessageBox( wxT( "PL_EDITOR_FRAME::Process_Special_Functions error" ) ); break; } - - if( item ) - { - OnModify(); - m_propertiesPagelayout->CopyPrmsFromItemToPanel( item ); - m_treePagelayout->SelectCell( item ); - } - } @@ -342,7 +126,6 @@ void PL_EDITOR_FRAME::Process_Special_Functions( wxCommandEvent& event ) * Function moveItem: called when the mouse cursor is moving * moves the item currently selected (or the start point or the end point) * to the cursor position - */ DPOINT initialPosition; // The initial position of the item to move, in mm wxPoint initialPositionUi; // The initial position of the item to move, in Ui wxPoint initialCursorPosition; // The initial position of the cursor @@ -382,11 +165,9 @@ static void moveItem( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPositio } -/* * Function abortMoveItem: called when an item is currently moving, * and when the user aborts the move command. * Restores the initial position of the item - */ static void abortMoveItem( EDA_DRAW_PANEL* aPanel, wxDC* aDC ) { PL_EDITOR_SCREEN* screen = (PL_EDITOR_SCREEN*) aPanel->GetScreen(); @@ -398,7 +179,6 @@ static void abortMoveItem( EDA_DRAW_PANEL* aPanel, wxDC* aDC ) plframe->RemoveLastCommandInUndoList(); WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance(); pglayout.Remove( item ); - plframe->RebuildDesignTree(); } else { @@ -454,10 +234,8 @@ void PL_EDITOR_FRAME::MoveItem( WORKSHEET_DATAITEM* aItem ) } -/** * Save in Undo list the layout, and place an item being moved. * @param aItem is the item moved -*/ void PL_EDITOR_FRAME::PlaceItem( WORKSHEET_DATAITEM* aItem ) { DPOINT currStartPos = aItem->GetStartPos(); @@ -486,6 +264,7 @@ void PL_EDITOR_FRAME::PlaceItem( WORKSHEET_DATAITEM* aItem ) m_canvas->SetMouseCapture( NULL, NULL ); GetScreen()->SetCurItem( NULL ); } +*/ /* called when the user select one of the 4 page corner as corner @@ -563,40 +342,6 @@ void PL_EDITOR_FRAME::ToPrinter(wxCommandEvent& event) } -void PL_EDITOR_FRAME::OnTreeSelection( wxTreeEvent& event ) -{ - WORKSHEET_DATAITEM* item = GetSelectedItem(); - - if( item ) - m_propertiesPagelayout->CopyPrmsFromItemToPanel( item ); - - m_canvas->Refresh(); -} - - -void PL_EDITOR_FRAME::OnTreeMiddleClick( wxTreeEvent& event ) -{ -} - - -extern void AddNewItemsCommand( wxMenu* aMainMenu ); - - -void PL_EDITOR_FRAME::OnTreeRightClick( wxTreeEvent& event ) -{ - m_treePagelayout->SelectCell( event.GetItem() ); - - wxMenu popMenu; - AddNewItemsCommand( &popMenu ); - - popMenu.AppendSeparator(); - AddMenuItem( &popMenu, ID_POPUP_DESIGN_TREE_ITEM_DELETE, _( "Delete" ), - KiBitmap( delete_xpm ) ); - - PopupMenu( &popMenu ); -} - - void PL_EDITOR_FRAME::OnUpdateTitleBlockDisplayNormalMode( wxUpdateUIEvent& event ) { event.Check( WORKSHEET_DATAITEM::m_SpecialMode == false ); @@ -609,7 +354,3 @@ void PL_EDITOR_FRAME::OnUpdateTitleBlockDisplaySpecialMode( wxUpdateUIEvent& eve } -void PL_EDITOR_FRAME::OnUpdateSelectTool( wxUpdateUIEvent& aEvent ) -{ - aEvent.Check( GetToolId() == aEvent.GetId() ); -} diff --git a/pagelayout_editor/files.cpp b/pagelayout_editor/files.cpp index 547da52ecc..360a3a8064 100644 --- a/pagelayout_editor/files.cpp +++ b/pagelayout_editor/files.cpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include @@ -70,7 +70,7 @@ void PL_EDITOR_FRAME::OnFileHistory( wxCommandEvent& event ) } } - m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); + m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT ); ::wxSetWorkingDirectory( ::wxPathOnly( filename ) ); if( LoadPageLayoutDescrFile( filename ) ) @@ -133,7 +133,6 @@ void PL_EDITOR_FRAME::Files_io( wxCommandEvent& event ) else { GetScreen()->SetModify(); - RebuildDesignTree(); m_canvas->Refresh(); msg.Printf( _( "File \"%s\" inserted" ), GetChars( filename ) ); SetStatusText( msg ); diff --git a/pagelayout_editor/hotkeys.cpp b/pagelayout_editor/hotkeys.cpp index fcc318b949..84062a85c2 100644 --- a/pagelayout_editor/hotkeys.cpp +++ b/pagelayout_editor/hotkeys.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2013 CERN - * Copyright (C) 2016-2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2016-2019 KiCad Developers, see AUTHORS.txt for contributors. * @author Jean-Pierre Charras, jp.charras at wanadoo.fr * * This program is free software; you can redistribute it and/or @@ -23,10 +23,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file pagelayout_editor/hotkeys.cpp - */ - #include #include #include @@ -34,7 +30,6 @@ #include #include -#include #include #include #include @@ -70,24 +65,17 @@ static EDA_HOTKEY HkMouseLeftClick( _HKI( "Mouse Left Click" ), HK_LEFT_CLICK, W static EDA_HOTKEY HkMouseLeftDClick( _HKI( "Mouse Left Double Click" ), HK_LEFT_DCLICK, WXK_END, 0 ); -static EDA_HOTKEY HkResetLocalCoord( _HKI( "Reset Local Coordinates" ), - HK_RESET_LOCAL_COORD, ' ' ); -static EDA_HOTKEY HkZoomAuto( _HKI( "Zoom Auto" ), HK_ZOOM_AUTO, WXK_HOME, ID_ZOOM_PAGE ); -static EDA_HOTKEY HkZoomCenter( _HKI( "Zoom Center" ), HK_ZOOM_CENTER, WXK_F4, - ID_POPUP_ZOOM_CENTER ); -static EDA_HOTKEY HkZoomRedraw( _HKI( "Zoom Redraw" ), HK_ZOOM_REDRAW, WXK_F3, ID_ZOOM_REDRAW ); -static EDA_HOTKEY HkZoomOut( _HKI( "Zoom Out" ), HK_ZOOM_OUT, WXK_F2, ID_KEY_ZOOM_OUT ); -static EDA_HOTKEY HkZoomIn( _HKI( "Zoom In" ), HK_ZOOM_IN, WXK_F1, ID_KEY_ZOOM_IN ); -static EDA_HOTKEY HkZoomSelection( _HKI( "Zoom to Selection" ), HK_ZOOM_SELECTION, - GR_KB_CTRL + WXK_F5, ID_ZOOM_SELECTION ); -static EDA_HOTKEY HkHelp( _HKI( "List Hotkeys" ), HK_HELP, GR_KB_CTRL + WXK_F1 ); -static EDA_HOTKEY HkMoveItem( _HKI( "Move Item" ), HK_MOVE_ITEM, 'M', ID_POPUP_ITEM_MOVE ); -static EDA_HOTKEY HkPlaceItem( _HKI( "Place Item" ), HK_PLACE_ITEM, 'P', ID_POPUP_ITEM_PLACE ); -static EDA_HOTKEY HkMoveStartPoint( _HKI( "Move Start Point" ), HK_MOVE_START_POINT, 'S', - ID_POPUP_ITEM_MOVE_START_POINT ); -static EDA_HOTKEY HkMoveEndPoint( _HKI( "Move End Point" ), HK_MOVE_END_POINT, 'E', - ID_POPUP_ITEM_MOVE_END_POINT ); -static EDA_HOTKEY HkDeleteItem( _HKI( "Delete Item" ), HK_DELETE_ITEM, WXK_DELETE, (int) wxID_DELETE ); +static EDA_HOTKEY HkResetLocalCoord( _HKI( "Reset Local Coordinates" ), HK_RESET_LOCAL_COORD, ' ' ); +static EDA_HOTKEY HkZoomAuto( _HKI( "Zoom Auto" ), HK_ZOOM_AUTO, WXK_HOME ); +static EDA_HOTKEY HkZoomCenter( _HKI( "Zoom Center" ), HK_ZOOM_CENTER, WXK_F4 ); +static EDA_HOTKEY HkZoomRedraw( _HKI( "Zoom Redraw" ), HK_ZOOM_REDRAW, WXK_F3 ); +static EDA_HOTKEY HkZoomOut( _HKI( "Zoom Out" ), HK_ZOOM_OUT, WXK_F2 ); +static EDA_HOTKEY HkZoomIn( _HKI( "Zoom In" ), HK_ZOOM_IN, WXK_F1 ); +static EDA_HOTKEY HkZoomSelection( _HKI( "Zoom to Selection" ), HK_ZOOM_SELECTION, + GR_KB_CTRL + WXK_F5 ); +static EDA_HOTKEY HkHelp( _HKI( "List Hotkeys" ), HK_HELP, GR_KB_CTRL + WXK_F1 ); +static EDA_HOTKEY HkMoveItem( _HKI( "Move Item" ), HK_MOVE, 'M' ); +static EDA_HOTKEY HkDeleteItem( _HKI( "Delete Item" ), HK_DELETE_ITEM, WXK_DELETE ); // Common: hotkeys_basic.h static EDA_HOTKEY HkUndo( _HKI( "Undo" ), HK_UNDO, GR_KB_CTRL + 'Z', (int) wxID_UNDO ); @@ -115,9 +103,7 @@ EDA_HOTKEY* s_Common_Hotkey_List[] = EDA_HOTKEY* s_PlEditor_Hotkey_List[] = { - &HkMoveItem, &HkMoveStartPoint, - &HkMoveEndPoint, - &HkPlaceItem, + &HkMoveItem, &HkDeleteItem, NULL }; @@ -149,10 +135,9 @@ EDA_HOTKEY* PL_EDITOR_FRAME::GetHotKeyDescription( int aCommand ) const } -bool PL_EDITOR_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, - const wxPoint& aPosition, EDA_ITEM* aItem ) +bool PL_EDITOR_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosition, + EDA_ITEM* aItem ) { - bool busy = GetScreen()->GetCurItem() != NULL; wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); cmd.SetEventObject( this ); @@ -169,8 +154,6 @@ bool PL_EDITOR_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, if( HK_Descr == NULL ) return false; - WORKSHEET_DATAITEM* item; - switch( HK_Descr->m_Idcommand ) { case HK_NOT_FOUND: @@ -210,44 +193,6 @@ bool PL_EDITOR_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, GetEventHandler()->ProcessEvent( cmd ); break; - case HK_UNDO: - case HK_REDO: - if( busy ) - break; - cmd.SetId( HK_Descr->m_IdMenuEvent ); - GetEventHandler()->ProcessEvent( cmd ); - break; - - case HK_ZOOM_IN: - cmd.SetId( ID_POPUP_ZOOM_IN ); - GetEventHandler()->ProcessEvent( cmd ); - break; - - case HK_ZOOM_OUT: - cmd.SetId( ID_POPUP_ZOOM_OUT ); - GetEventHandler()->ProcessEvent( cmd ); - break; - - case HK_ZOOM_REDRAW: - cmd.SetId( ID_ZOOM_REDRAW ); - GetEventHandler()->ProcessEvent( cmd ); - break; - - case HK_ZOOM_CENTER: - cmd.SetId( ID_POPUP_ZOOM_CENTER ); - GetEventHandler()->ProcessEvent( cmd ); - break; - - case HK_ZOOM_AUTO: - cmd.SetId( ID_ZOOM_PAGE ); - GetEventHandler()->ProcessEvent( cmd ); - break; - - case HK_ZOOM_SELECTION: - cmd.SetId( ID_ZOOM_SELECTION ); - GetEventHandler()->ProcessEvent( cmd ); - break; - case HK_RESET_LOCAL_COORD: // Reset the relative coord GetScreen()->m_O_Curseur = GetCrossHairPosition(); break; @@ -265,35 +210,6 @@ bool PL_EDITOR_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, SetGridOrigin( GetCrossHairPosition() ); break; - case HK_MOVE_ITEM: - case HK_MOVE_START_POINT: - case HK_MOVE_END_POINT: - case HK_DELETE_ITEM: - if( busy ) - break; - - if( (item = Locate( aDC, aPosition ) ) == NULL ) - break; - - // Only rect and lines have a end point. - if( HK_Descr->m_Idcommand == HK_MOVE_END_POINT && !item->HasEndPoint() ) - break; - - if( m_treePagelayout->GetPageLayoutSelectedItem() != item ) - m_treePagelayout->SelectCell( item ); - - cmd.SetId( HK_Descr->m_IdMenuEvent ); - GetEventHandler()->ProcessEvent( cmd ); - break; - - case HK_PLACE_ITEM: - if( busy ) - { - cmd.SetId( HK_Descr->m_IdMenuEvent ); - GetEventHandler()->ProcessEvent( cmd ); - } - break; - default: wxMessageBox( wxT( "Unknown hotkey" ) ); return false; diff --git a/pagelayout_editor/hotkeys.h b/pagelayout_editor/hotkeys.h index ba0f48f3f2..ca1a2eeb07 100644 --- a/pagelayout_editor/hotkeys.h +++ b/pagelayout_editor/hotkeys.h @@ -35,10 +35,7 @@ // see also enum common_hotkey_id_command in hotkeys_basic.h // for shared hotkeys id enum hotkey_id_command { - HK_MOVE_ITEM = HK_COMMON_END, - HK_MOVE_START_POINT, - HK_MOVE_END_POINT, - HK_PLACE_ITEM, + HK_MOVE = HK_COMMON_END, HK_DELETE_ITEM }; diff --git a/pagelayout_editor/invoke_pl_editor_dialog.h b/pagelayout_editor/invoke_pl_editor_dialog.h index ecd4b96cbe..1031019af4 100644 --- a/pagelayout_editor/invoke_pl_editor_dialog.h +++ b/pagelayout_editor/invoke_pl_editor_dialog.h @@ -1,7 +1,3 @@ -/** - * @file invoke_pl_editor_dialog.h - */ - /* * This program source code file is part of KiCad, a free EDA CAD application. * diff --git a/pagelayout_editor/menubar.cpp b/pagelayout_editor/menubar.cpp index b6186bcbca..300a9990d7 100644 --- a/pagelayout_editor/menubar.cpp +++ b/pagelayout_editor/menubar.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2016-2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2016-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2013 CERN * @author Jean-Pierre Charras, jp.charras at wanadoo.fr * @@ -23,16 +23,14 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file pagelayout_editor/menubar.cpp - * @brief (Re)Create the main menubar for Pl_Editor - */ - - #include #include #include - +#include +#include +#include +#include +#include #include "hotkeys.h" #include "pl_editor_frame.h" #include "pl_editor_id.h" @@ -40,6 +38,7 @@ void PL_EDITOR_FRAME::ReCreateMenuBar() { + PL_SELECTION_TOOL* selTool = m_toolManager->GetTool(); // wxWidgets handles the Mac Application menu behind the scenes, but that means // we always have to start from scratch with a new wxMenuBar. wxMenuBar* oldMenuBar = GetMenuBar(); @@ -103,72 +102,57 @@ void PL_EDITOR_FRAME::ReCreateMenuBar() // Edit Menu: - wxMenu* editMenu = new wxMenu; + CONDITIONAL_MENU* editMenu = new CONDITIONAL_MENU( false, selTool ); - msg = AddHotkeyName( _( "Undo" ), PlEditorHotkeysDescr, HK_UNDO ); - AddMenuItem( editMenu, wxID_UNDO, msg, wxEmptyString, KiBitmap( undo_xpm ) ); + auto enableUndoCondition = [ this ] ( const SELECTION& sel ) { + return GetScreen() && GetScreen()->GetUndoCommandCount() != 0; + }; + auto enableRedoCondition = [ this ] ( const SELECTION& sel ) { + return GetScreen() && GetScreen()->GetRedoCommandCount() != 0; + }; - msg = AddHotkeyName( _( "Redo" ), PlEditorHotkeysDescr, HK_REDO ); - AddMenuItem( editMenu, wxID_REDO, msg, wxEmptyString, KiBitmap( redo_xpm ) ); + editMenu->AddItem( ACTIONS::undo, enableUndoCondition ); + editMenu->AddItem( ACTIONS::redo, enableRedoCondition ); - editMenu->AppendSeparator(); - - msg = AddHotkeyName( _( "Delete" ), PlEditorHotkeysDescr, HK_DELETE_ITEM ); - AddMenuItem( editMenu, wxID_DELETE, msg, wxEmptyString, KiBitmap( delete_xpm ) ); + editMenu->AddSeparator(); + editMenu->AddItem( PL_ACTIONS::doDelete, SELECTION_CONDITIONS::MoreThan( 0 ) ); // View Menu: - wxMenu* viewMenu = new wxMenu; + CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, selTool ); - msg = AddHotkeyName( _( "Zoom In" ), PlEditorHotkeysDescr, HK_ZOOM_IN, IS_ACCELERATOR ); - AddMenuItem( viewMenu, ID_ZOOM_IN, msg, wxEmptyString, KiBitmap( zoom_in_xpm ) ); + auto whiteBackgroundCondition = [ this ] ( const SELECTION& aSel ) { + return GetDrawBgColor() == WHITE; + }; + auto gridShownCondition = [ this ] ( const SELECTION& aSel ) { + return IsGridVisible(); + }; + auto fullCrosshairCondition = [ this ] ( const SELECTION& aSel ) { + return GetGalDisplayOptions().m_fullscreenCursor; + }; - msg = AddHotkeyName( _( "Zoom Out" ), PlEditorHotkeysDescr, HK_ZOOM_OUT, IS_ACCELERATOR ); - AddMenuItem( viewMenu, ID_ZOOM_OUT, msg, wxEmptyString, KiBitmap( zoom_out_xpm ) ); - - msg = AddHotkeyName( _( "Zoom to Fit" ), PlEditorHotkeysDescr, HK_ZOOM_AUTO ); - AddMenuItem( viewMenu, ID_ZOOM_PAGE, msg, wxEmptyString, KiBitmap( zoom_fit_in_page_xpm ) ); - - msg = AddHotkeyName( _( "Zoom to Selection" ), PlEditorHotkeysDescr, HK_ZOOM_SELECTION ); - AddMenuItem( viewMenu, ID_ZOOM_SELECTION, msg, wxEmptyString, KiBitmap( zoom_area_xpm ), wxITEM_CHECK ); - - viewMenu->AppendSeparator(); - - AddMenuItem( viewMenu, ID_MENU_SWITCH_BGCOLOR, - GetDrawBgColor() == WHITE ? _( "&Background Black" ) : _( "&Background White" ), - wxEmptyString, KiBitmap( palette_xpm ) ); - - AddMenuItem( viewMenu, ID_MENU_GRID_ONOFF, - IsGridVisible() ? _( "Hide &Grid" ) : _( "Show &Grid" ), - wxEmptyString, KiBitmap( grid_xpm ) ); - - viewMenu->AppendSeparator(); - - msg = AddHotkeyName( _( "Redraw View" ), PlEditorHotkeysDescr, HK_ZOOM_REDRAW ); - AddMenuItem( viewMenu, ID_ZOOM_REDRAW, msg, wxEmptyString, KiBitmap( zoom_redraw_xpm ) ); + viewMenu->AddSeparator(); + viewMenu->AddItem( ACTIONS::zoomInCenter, SELECTION_CONDITIONS::ShowAlways ); + viewMenu->AddItem( ACTIONS::zoomOutCenter, SELECTION_CONDITIONS::ShowAlways ); + viewMenu->AddItem( ACTIONS::zoomFitScreen, SELECTION_CONDITIONS::ShowAlways ); + viewMenu->AddItem( ACTIONS::zoomTool, SELECTION_CONDITIONS::ShowAlways ); + viewMenu->AddItem( ACTIONS::zoomRedraw, SELECTION_CONDITIONS::ShowAlways ); + viewMenu->AddSeparator(); + viewMenu->AddCheckItem( PL_ACTIONS::toggleBackground, whiteBackgroundCondition ); + viewMenu->AddCheckItem( ACTIONS::toggleGrid, gridShownCondition ); + viewMenu->AddCheckItem( ACTIONS::toggleCursorStyle, fullCrosshairCondition ); // Place Menu: - wxMenu* placeMenu = new wxMenu; + CONDITIONAL_MENU* placeMenu = new CONDITIONAL_MENU( false, selTool ); - AddMenuItem( placeMenu, ID_POPUP_ITEM_ADD_LINE, _( "&Line..." ), - wxEmptyString, KiBitmap( add_dashed_line_xpm ) ); - - AddMenuItem( placeMenu, ID_POPUP_ITEM_ADD_RECT, _( "&Rectangle..." ), - wxEmptyString, KiBitmap( add_rectangle_xpm ) ); - - AddMenuItem( placeMenu, ID_POPUP_ITEM_ADD_TEXT, _( "&Text..." ), - wxEmptyString, KiBitmap( text_xpm ) ); - - AddMenuItem( placeMenu, ID_POPUP_ITEM_ADD_BITMAP, _( "&Bitmap..." ), - wxEmptyString, KiBitmap( image_xpm ) ); - - placeMenu->AppendSeparator(); - - AddMenuItem( placeMenu, ID_APPEND_DESCR_FILE, _( "&Append Existing Page Layout Design File..." ), - _( "Append an existing page layout design file to current file" ), - KiBitmap( pagelayout_load_xpm ) ); + placeMenu->AddItem( PL_ACTIONS::drawLine, SELECTION_CONDITIONS::ShowAlways ); + placeMenu->AddItem( PL_ACTIONS::drawRectangle, SELECTION_CONDITIONS::ShowAlways ); + placeMenu->AddItem( PL_ACTIONS::placeText, SELECTION_CONDITIONS::ShowAlways ); + placeMenu->AddItem( PL_ACTIONS::placeImage, SELECTION_CONDITIONS::ShowAlways ); + placeMenu->AddSeparator(); + placeMenu->AddItem( PL_ACTIONS::appendImportedWorksheet, SELECTION_CONDITIONS::ShowAlways ); // Menu for preferences wxMenu* preferencesMenu = new wxMenu; diff --git a/pagelayout_editor/onleftclick.cpp b/pagelayout_editor/onleftclick.cpp deleted file mode 100644 index 3cdcc7d570..0000000000 --- a/pagelayout_editor/onleftclick.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/** - * @file pagelayout_editor/onleftclick.cpp - * @brief functions called on left or double left click mouse event - */ - -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2013 CERN - * - * 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 - */ - - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -/* Process the command triggered by the left button of the mouse when a tool - * is already selected. - */ -void PL_EDITOR_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) -{ - WORKSHEET_DATAITEM* item = GetScreen()->GetCurItem(); - - if( item ) // An item is currently in edit: place it - { - PlaceItem( item ); - m_propertiesPagelayout->CopyPrmsFromItemToPanel( item ); - m_canvas->Refresh(); - return; - } - - item = m_treePagelayout->GetPageLayoutSelectedItem(); - WORKSHEET_DATAITEM* newitem = Locate( aDC, aPosition ); - - if( newitem == NULL ) - return; - - if( newitem != item ) - { - item = newitem; - m_treePagelayout->SelectCell( item ); - m_canvas->Refresh(); - } -} - - -/* Called on a double click of left mouse button. - */ -void PL_EDITOR_FRAME::OnLeftDClick( wxDC* aDC, const wxPoint& aPosition ) -{ - // Currently: no nothing -} diff --git a/pagelayout_editor/onrightclick.cpp b/pagelayout_editor/onrightclick.cpp deleted file mode 100644 index 320fa09bd1..0000000000 --- a/pagelayout_editor/onrightclick.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/** - * @file pagelayout_editor/onrightclick.cpp - * @brief functions called on rigth click mouse event -*/ - -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2013 CERN - * - * 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 - */ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -// Helper function to add menuitems relative to items creation -void AddNewItemsCommand( wxMenu* aMainMenu ) -{ - AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_LINE, _( "Add Line..." ), - KiBitmap( add_dashed_line_xpm ) ); - AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_RECT, _( "Add Rectangle..." ), - KiBitmap( add_rectangle_xpm ) ); - AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_TEXT, _( "Add Text..." ), - KiBitmap( text_xpm ) ); - AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_BITMAP, _( "Add Bitmap..." ), - KiBitmap( image_xpm ) ); - AddMenuItem( aMainMenu, ID_POPUP_ITEM_APPEND_PAGE_LAYOUT, - _( "Append Existing Page Layout Design File..." ), - KiBitmap( pagelayout_load_xpm ) ); -} - -/* Prepare the right-click pullup menu. - * The menu already has a list of zoom commands. - */ -bool PL_EDITOR_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* aPopMenu ) -{ - bool busy = GetScreen()->GetCurItem() != NULL; - bool blockActive = GetScreen()->IsBlockActive(); - wxString msg; - - if( blockActive ) - { - - AddMenuItem( aPopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND, _( "Cancel Block" ), - KiBitmap( cancel_xpm ) ); - aPopMenu->AppendSeparator(); - return true; - } - - // If the tool ID_ZOOM_SELECTION is currently in use, add a close command menu - if( GetToolId() == ID_ZOOM_SELECTION && !busy ) - { - AddMenuItem( aPopMenu, ID_POPUP_CLOSE_CURRENT_TOOL, _( "End Tool" ), - KiBitmap( cursor_xpm ) ); - aPopMenu->AppendSeparator(); - } - - if( ! busy ) // No item currently edited - { - INSTALL_UNBUFFERED_DC( dc, m_canvas ); - WORKSHEET_DATAITEM* old_item = m_treePagelayout->GetPageLayoutSelectedItem(); - WORKSHEET_DATAITEM* item = Locate( &dc, aPosition ); - - if( item && old_item != item ) - { - m_treePagelayout->SelectCell( item ); - m_canvas->Refresh(); - } - - // Add menus to edit and delete the item - if( item ) - { - if( (item->GetFlags() & LOCATE_STARTPOINT) ) - { - msg = AddHotkeyName( _( "Move Start Point" ), PlEditorHotkeysDescr, - HK_MOVE_START_POINT ); - AddMenuItem( aPopMenu, ID_POPUP_ITEM_MOVE_START_POINT, msg, - KiBitmap( move_xpm ) ); - } - - if( (item->GetFlags() & LOCATE_ENDPOINT ) ) - { - msg = AddHotkeyName( _( "Move End Point" ), PlEditorHotkeysDescr, - HK_MOVE_END_POINT ); - AddMenuItem( aPopMenu, ID_POPUP_ITEM_MOVE_END_POINT, msg, - KiBitmap( move_xpm ) ); - } - - msg = AddHotkeyName( _( "Move Item" ), PlEditorHotkeysDescr, HK_MOVE_ITEM ); - AddMenuItem( aPopMenu, ID_POPUP_ITEM_MOVE, msg, KiBitmap( move_xpm ) ); - aPopMenu->AppendSeparator(); - - msg = AddHotkeyName( _( "Delete" ), PlEditorHotkeysDescr, HK_DELETE_ITEM ); - AddMenuItem( aPopMenu, ID_POPUP_ITEM_DELETE, msg, KiBitmap( delete_xpm ) ); - aPopMenu->AppendSeparator(); - } - } - else // An item is currently in edit - { - msg = AddHotkeyName( _( "Place Item" ), PlEditorHotkeysDescr, HK_PLACE_ITEM ); - AddMenuItem( aPopMenu, ID_POPUP_ITEM_PLACE, msg, KiBitmap( move_xpm ) ); - AddMenuItem( aPopMenu, ID_POPUP_ITEM_PLACE_CANCEL, _( "Cancel" ), KiBitmap( cancel_xpm ) ); - aPopMenu->AppendSeparator(); - } - - if( ! busy ) - { - AddNewItemsCommand( aPopMenu ); - aPopMenu->AppendSeparator(); - } - - return true; -} diff --git a/pagelayout_editor/page_layout_writer.cpp b/pagelayout_editor/page_layout_writer.cpp index 88b679c414..a7fb2ec242 100644 --- a/pagelayout_editor/page_layout_writer.cpp +++ b/pagelayout_editor/page_layout_writer.cpp @@ -31,8 +31,8 @@ #include #include -#include -#include +#include +#include #include #include #include @@ -240,7 +240,7 @@ void WORKSHEET_LAYOUT_IO::format( WORKSHEET_DATAITEM_TEXT* aItem, int aNestLevel bool write_size = aItem->m_TextSize.x != 0.0 || aItem->m_TextSize.y != 0.0; bool write_thickness = aItem->m_LineWidth != 0.0; - if( write_thickness || write_size || aItem->IsBold() || aItem->IsItalic() ) + if( write_thickness || write_size || aItem->m_Bold || aItem->m_Italic ) { m_out->Print( 0, " (%s", getTokenName( T_font ) ); @@ -256,10 +256,10 @@ void WORKSHEET_LAYOUT_IO::format( WORKSHEET_DATAITEM_TEXT* aItem, int aNestLevel double2Str(aItem->m_TextSize.x ).c_str(), double2Str(aItem->m_TextSize.y ).c_str() ); } - if( aItem->IsBold() ) + if( aItem->m_Bold ) m_out->Print( 0, " %s", getTokenName( T_bold ) ); - if( aItem->IsItalic() ) + if( aItem->m_Italic ) m_out->Print( 0, " %s", getTokenName( T_italic ) ); m_out->Print( 0, ")" ); @@ -453,19 +453,8 @@ void WORKSHEET_LAYOUT_IO::formatRepeatParameters( WORKSHEET_DATAITEM* aItem ) co void WORKSHEET_LAYOUT_IO::formatOptions( WORKSHEET_DATAITEM* aItem ) const { - switch( aItem->GetPage1Option() ) - { - default: - case 0: - break; - - case 1: - m_out->Print( 0, " (%s %s)", getTokenName( T_option ), - getTokenName(T_page1only ) ); - break; - - case -1: - m_out->Print( 0, " (%s %s)", getTokenName( T_option ), getTokenName( T_notonpage1 ) ); - break; - } + if( aItem->GetPage1Option() == FIRST_PAGE_ONLY ) + m_out->Print( 0, " (%s %s)", getTokenName( T_option ), getTokenName(T_page1only ) ); + else if( aItem->GetPage1Option() == SUBSEQUENT_PAGES ) + m_out->Print( 0, " (%s %s)", getTokenName( T_option ), getTokenName( T_notonpage1 ) ); } diff --git a/pagelayout_editor/pl_draw_panel_gal.cpp b/pagelayout_editor/pl_draw_panel_gal.cpp new file mode 100644 index 0000000000..6f6f2811cc --- /dev/null +++ b/pagelayout_editor/pl_draw_panel_gal.cpp @@ -0,0 +1,120 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 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 3 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, see . + */ + +#include "pl_draw_panel_gal.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +using namespace std::placeholders; + + +PL_DRAW_PANEL_GAL::PL_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId, + const wxPoint& aPosition, const wxSize& aSize, + KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) : + EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType ) +{ + m_view = new KIGFX::VIEW( true ); + m_view->SetGAL( m_gal ); + + GetGAL()->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ ); + + m_painter.reset( new KIGFX::WORKSHEET_PAINTER( m_gal ) ); + m_view->SetPainter( m_painter.get() ); + + setDefaultLayerDeps(); + + m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this ); +} + + +PL_DRAW_PANEL_GAL::~PL_DRAW_PANEL_GAL() +{ +} + + +void PL_DRAW_PANEL_GAL::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector& aList ) +{ +} + + +void PL_DRAW_PANEL_GAL::DisplayWorksheet() +{ + m_edaFrame->GetToolManager()->RunAction( PL_ACTIONS::clearSelection, true ); + m_view->Clear(); + + WS_DRAW_ITEM_LIST::SetupDrawEnvironment( m_edaFrame->GetPageSettings() ); + + for( WORKSHEET_DATAITEM* dataItem : WORKSHEET_LAYOUT::GetTheInstance().GetItems() ) + dataItem->SyncDrawItems( nullptr, m_view ); +} + + +bool PL_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType ) +{ + bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType ); + + // The next onPaint event will call m_view->UpdateItems() that is very time consumming + // after switching to opengl. Clearing m_view and rebuild it is much faster + if( aGalType == GAL_TYPE_OPENGL ) + m_view->Clear(); + + setDefaultLayerDeps(); + + GetGAL()->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ ); + + return rv; +} + + +void PL_DRAW_PANEL_GAL::setDefaultLayerDeps() +{ + for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ ) + m_view->SetLayerTarget( i, KIGFX::TARGET_NONCACHED ); + + m_view->SetLayerDisplayOnly( LAYER_WORKSHEET ); + + m_view->SetLayerTarget( LAYER_SELECT_OVERLAY, KIGFX::TARGET_OVERLAY ); + m_view->SetLayerDisplayOnly( LAYER_SELECT_OVERLAY ); + + m_view->SetLayerTarget( LAYER_GP_OVERLAY, KIGFX::TARGET_OVERLAY ); + m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY ); +} + + +void PL_DRAW_PANEL_GAL::SetTopLayer( int aLayer ) +{ + m_view->ClearTopLayers(); + m_view->SetTopLayer( aLayer ); + + m_view->SetTopLayer( LAYER_SELECT_OVERLAY ); + + m_view->SetTopLayer( LAYER_GP_OVERLAY ); + + m_view->UpdateAllLayersOrder(); +} + diff --git a/pagelayout_editor/pl_draw_panel_gal.h b/pagelayout_editor/pl_draw_panel_gal.h new file mode 100644 index 0000000000..d81bdf1548 --- /dev/null +++ b/pagelayout_editor/pl_draw_panel_gal.h @@ -0,0 +1,56 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2017 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 3 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, see . + */ + +#ifndef PL_DRAW_PANEL_GAL_H +#define PL_DRAW_PANEL_GAL_H + +#include +#include +#include + + +class PL_DRAW_PANEL_GAL : public EDA_DRAW_PANEL_GAL +{ +public: + PL_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId, const wxPoint& aPosition, + const wxSize& aSize, KIGFX::GAL_DISPLAY_OPTIONS& aOptions, + GAL_TYPE aGalType = GAL_TYPE_OPENGL ); + + virtual ~PL_DRAW_PANEL_GAL(); + + ///> @copydoc EDA_DRAW_PANEL_GAL::GetMsgPanelInfo() + void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector& aList ) override; + + void DisplayWorksheet(); + + bool SwitchBackend( GAL_TYPE aGalType ) override; + + ///> @copydoc EDA_DRAW_PANEL_GAL::SetTopLayer + virtual void SetTopLayer( int aLayer ) override; + +protected: + ///> Sets rendering targets & dependencies for layers. + void setDefaultLayerDeps(); + + ///> Currently used worksheet + std::unique_ptr m_worksheet; +}; + + +#endif /* PL_DRAW_PANEL_GAL_H */ diff --git a/pagelayout_editor/pl_editor.cpp b/pagelayout_editor/pl_editor.cpp index 760f225e63..fce0b776fe 100644 --- a/pagelayout_editor/pl_editor.cpp +++ b/pagelayout_editor/pl_editor.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include @@ -132,71 +132,3 @@ void IFACE::OnKifaceEnd() { end_common(); } - - -#if 0 -bool MYFACE::OnKifaceStart( PGM_BASE* aProgram ) - -{ - wxFileName fn; - - InitEDA_Appl( wxT( "pl_editor" ), APP_PL_EDITOR_T ); - - if( m_Checker && m_Checker->IsAnotherRunning() ) - { - if( !IsOK( NULL, _( "pl_editor is already running. Continue?" ) ) ) - return false; - } - - // read current setup and reopen last directory if no filename to open in - // command line - bool reopenLastUsedDirectory = argc == 1; - GetSettings( reopenLastUsedDirectory ); - - // Must be called before creating the main frame in order to - // display the real hotkeys in menus or tool tips - ReadHotkeyConfig( PL_EDITOR_FRAME_NAME, s_PlEditor_Hotkeys_Descr ); - - PL_EDITOR_FRAME * frame = new PL_EDITOR_FRAME( NULL, wxT( "PlEditorFrame" ), wxPoint( 0, 0 ), wxSize( 600, 400 ) ); - - // frame title: - frame->SetTitle( GetTitle() + wxT( " " ) + GetBuildVersion() ); - - SetTopWindow( frame ); - frame->Show( true ); - frame->Zoom_Automatique( true ); // Zoom fit in frame - frame->GetScreen()->m_FirstRedraw = false; - - - bool descrLoaded = false; - if( argc > 1 ) - { - fn = argv[1]; - - if( fn.IsOk() ) - { - bool success = frame->LoadPageLayoutDescrFile( fn.GetFullPath() ); - if( !success ) - { - wxString msg; - msg.Printf( _("Error when loading file \"%s\""), - fn.GetFullPath().GetData() ); - wxMessageBox( msg ); - } - else - { - descrLoaded = true; - frame->OnNewPageLayout(); - } - } - } - - if( !descrLoaded ) - { - WORKSHEET_LAYOUT::GetTheInstance().SetPageLayout(); - frame->OnNewPageLayout(); - } - - return true; -} -#endif diff --git a/pagelayout_editor/pl_editor_config.cpp b/pagelayout_editor/pl_editor_config.cpp index 7b171cdf40..a9d9de8860 100644 --- a/pagelayout_editor/pl_editor_config.cpp +++ b/pagelayout_editor/pl_editor_config.cpp @@ -47,24 +47,6 @@ void PL_EDITOR_FRAME::Process_Config( wxCommandEvent& event ) switch( id ) { - case ID_MENU_SWITCH_BGCOLOR: - if( GetDrawBgColor() == WHITE ) - SetDrawBgColor( BLACK ); - else - SetDrawBgColor( WHITE ); - - GetMenuBar()->SetLabel( ID_MENU_SWITCH_BGCOLOR, - GetDrawBgColor() == WHITE ? _( "&Background Black" ) : _( "&Background White" ) ); - m_canvas->Refresh(); - break; - - case ID_MENU_GRID_ONOFF: - SetGridVisibility( ! IsGridVisible() ); - GetMenuBar()->SetLabel( ID_MENU_GRID_ONOFF, - IsGridVisible() ? _( "Hide &Grid" ) : _( "Show &Grid" ) ); - m_canvas->Refresh(); - break; - case wxID_PREFERENCES: ShowPreferences( PlEditorHotkeysDescr, PlEditorHotkeysDescr, wxT( "pl_editor" ) ); break; diff --git a/pagelayout_editor/pl_editor_frame.cpp b/pagelayout_editor/pl_editor_frame.cpp index a98316469f..7112a5eeb7 100644 --- a/pagelayout_editor/pl_editor_frame.cpp +++ b/pagelayout_editor/pl_editor_frame.cpp @@ -23,36 +23,40 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file pl_editor_frame.cpp - */ - #include #include -#include -#include -#include #include #include #include #include - #include #include +#include #include #include -#include +#include #include -#include #include - +#include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) : - EDA_DRAW_FRAME( aKiway, aParent, FRAME_PL_EDITOR, wxT( "PlEditorFrame" ), - wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, PL_EDITOR_FRAME_NAME ) + EDA_DRAW_FRAME( aKiway, aParent, FRAME_PL_EDITOR, wxT( "PlEditorFrame" ), + wxDefaultPosition, wxDefaultSize, + KICAD_DEFAULT_DRAWFRAME_STYLE, PL_EDITOR_FRAME_NAME ) { m_UserUnits = MILLIMETRES; m_zoomLevelCoeff = 290.0; // Adjusted to roughly displays zoom level = 1 @@ -63,35 +67,47 @@ PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) : m_showAxis = false; // true to show X and Y axis on screen m_showGridAxis = true; m_showBorderAndTitleBlock = true; // true for reference drawings. - m_hotkeysDescrList = PlEditorHotkeysDescr; + m_hotkeysDescrList = PlEditorHotkeysDescr; m_originSelectChoice = 0; SetDrawBgColor( WHITE ); // default value, user option (WHITE/BLACK) + WORKSHEET_DATAITEM::m_SpecialMode = true; SetShowPageLimits( true ); m_AboutTitle = "PlEditor"; - m_designTreeWidth = 150; m_propertiesFrameWidth = 200; - if( m_canvas ) - m_canvas->SetEnableBlockCommands( true ); - // Give an icon wxIcon icon; icon.CopyFromBitmap( KiBitmap( icon_pagelayout_editor_xpm ) ); SetIcon( icon ); - wxSize pageSizeIU = GetPageLayout().GetPageSettings().GetSizeIU(); - SetScreen( new PL_EDITOR_SCREEN( pageSizeIU ) ); + + // Create GAL canvas +#ifdef __WXMAC__ + // Cairo renderer doesn't handle Retina displays + m_canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL; +#else + m_canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO; +#endif + + auto* drawPanel = new PL_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_FrameSize, + GetGalDisplayOptions(), m_canvasType ); + SetGalCanvas( drawPanel ); LoadSettings( config() ); SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); - if( ! GetScreen()->GridExists( m_LastGridSizeId + ID_POPUP_GRID_LEVEL_1000 ) ) + wxSize pageSizeIU = GetPageLayout().GetPageSettings().GetSizeIU(); + SetScreen( new PL_EDITOR_SCREEN( pageSizeIU ) ); + + if( !GetScreen()->GridExists( m_LastGridSizeId + ID_POPUP_GRID_LEVEL_1000 ) ) m_LastGridSizeId = ID_POPUP_GRID_LEVEL_1MM - ID_POPUP_GRID_LEVEL_1000; GetScreen()->SetGrid( m_LastGridSizeId + ID_POPUP_GRID_LEVEL_1000 ); + setupTools(); ReCreateMenuBar(); ReCreateHToolbar(); + ReCreateVToolbar(); wxWindow* stsbar = GetStatusBar(); int dims[] = { @@ -124,19 +140,22 @@ PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) : m_auimgr.SetArtProvider( new EDA_DOCKART( this ) ); m_propertiesPagelayout = new PROPERTIES_FRAME( this ); - m_treePagelayout = new DESIGN_TREE_FRAME( this ); + // Horizontal items; layers 4 - 6 m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) ); m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) ); - m_auimgr.AddPane( m_treePagelayout, EDA_PANE().Palette().Name( "Design" ).Left().Layer(1) - .Caption( _( "Design" ) ).MinSize( m_treePagelayout->GetMinSize() ) - .BestSize( m_designTreeWidth, -1 ) ); - m_auimgr.AddPane( m_propertiesPagelayout, EDA_PANE().Palette().Name( "Props" ).Right().Layer(1) + // Vertical items; layers 1 - 3 + m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( "ToolsToolbar" ).Right().Layer(1) ); + + m_auimgr.AddPane( m_propertiesPagelayout, EDA_PANE().Palette().Name( "Props" ).Right().Layer(2) .Caption( _( "Properties" ) ).MinSize( m_propertiesPagelayout->GetMinSize() ) .BestSize( m_propertiesFrameWidth, -1 ) ); m_auimgr.AddPane( m_canvas, EDA_PANE().Canvas().Name( "DrawFrame" ).Center() ); + m_auimgr.AddPane( GetGalCanvas(), EDA_PANE().Canvas().Name( "DrawFrameGal" ).Center().Hide() ); + + UseGalCanvas( true ); m_auimgr.Update(); @@ -152,8 +171,29 @@ PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) : } -PL_EDITOR_FRAME::~PL_EDITOR_FRAME() +void PL_EDITOR_FRAME::setupTools() { + // Create the manager and dispatcher & route draw panel events to the dispatcher + m_toolManager = new TOOL_MANAGER; + m_toolManager->SetEnvironment( nullptr, GetGalCanvas()->GetView(), + GetGalCanvas()->GetViewControls(), this ); + m_actions = new PL_ACTIONS(); + m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions ); + + GetGalCanvas()->SetEventDispatcher( m_toolDispatcher ); + + // Register tools + m_toolManager->RegisterTool( new COMMON_TOOLS ); + m_toolManager->RegisterTool( new ZOOM_TOOL ); + m_toolManager->RegisterTool( new PL_SELECTION_TOOL ); + m_toolManager->RegisterTool( new PL_DRAWING_TOOLS ); + m_toolManager->RegisterTool( new PL_EDIT_TOOL ); + m_toolManager->RegisterTool( new PL_POINT_EDITOR ); + m_toolManager->RegisterTool( new PL_PICKER_TOOL ); + m_toolManager->InitTools(); + + // Run the selection tool, it is supposed to be always active + m_toolManager->InvokeTool( "plEditor.InteractiveSelection" ); } @@ -163,12 +203,7 @@ bool PL_EDITOR_FRAME::OpenProjectFiles( const std::vector& aFileSet, i if( !LoadPageLayoutDescrFile( fn ) ) { - wxString msg = wxString::Format( - _( "Error when loading file \"%s\"" ), - GetChars( fn ) - ); - - wxMessageBox( msg ); + wxMessageBox( wxString::Format( _( "Error when loading file \"%s\"" ), fn ) ); return false; } else @@ -205,11 +240,18 @@ void PL_EDITOR_FRAME::OnCloseWindow( wxCloseEvent& Event ) } +const BOX2I PL_EDITOR_FRAME::GetDocumentExtents() const +{ + BOX2I rv( VECTOR2I( 0, 0 ), GetPageLayout().GetPageSettings().GetSizeIU() ); + return rv; +} + + double PL_EDITOR_FRAME::BestZoom() { double sizeX = (double) GetPageLayout().GetPageSettings().GetWidthIU(); double sizeY = (double) GetPageLayout().GetPageSettings().GetHeightIU(); - wxPoint centre( sizeX / 2, sizeY / 2 ); + wxPoint centre( KiROUND( sizeX / 2 ), KiROUND( sizeY / 2 ) ); // The sheet boundary already affords us some margin, so add only an // additional 5%. @@ -219,7 +261,6 @@ double PL_EDITOR_FRAME::BestZoom() } -static const wxChar designTreeWidthKey[] = wxT( "DesignTreeWidth" ); static const wxChar propertiesFrameWidthKey[] = wxT( "PropertiesFrameWidth" ); static const wxChar cornerOriginChoiceKey[] = wxT( "CornerOriginChoice" ); static const wxChar blackBgColorKey[] = wxT( "BlackBgColor" ); @@ -229,7 +270,6 @@ void PL_EDITOR_FRAME::LoadSettings( wxConfigBase* aCfg ) { EDA_DRAW_FRAME::LoadSettings( aCfg ); - aCfg->Read( designTreeWidthKey, &m_designTreeWidth, 100); aCfg->Read( propertiesFrameWidthKey, &m_propertiesFrameWidth, 150); aCfg->Read( cornerOriginChoiceKey, &m_originSelectChoice ); bool tmp; @@ -242,10 +282,8 @@ void PL_EDITOR_FRAME::SaveSettings( wxConfigBase* aCfg ) { EDA_DRAW_FRAME::SaveSettings( aCfg ); - m_designTreeWidth = m_treePagelayout->GetSize().x; m_propertiesFrameWidth = m_propertiesPagelayout->GetSize().x; - aCfg->Write( designTreeWidthKey, m_designTreeWidth); aCfg->Write( propertiesFrameWidthKey, m_propertiesFrameWidth); aCfg->Write( cornerOriginChoiceKey, m_originSelectChoice ); aCfg->Write( blackBgColorKey, GetDrawBgColor() == BLACK ); @@ -377,29 +415,18 @@ void PL_EDITOR_FRAME::UpdateStatusBar() switch( GetUserUnits() ) { - case INCHES: // Should not be used in page layout editor - SetStatusText( _("inches"), 5 ); - break; - - case MILLIMETRES: - SetStatusText( _("mm"), 5 ); - break; - - case UNSCALED_UNITS: - SetStatusText( wxEmptyString, 5 ); - break; - - case DEGREES: - wxASSERT( false ); - break; + case INCHES: SetStatusText( _("inches"), 5 ); break; + case MILLIMETRES: SetStatusText( _("mm"), 5 ); break; + case UNSCALED_UNITS: SetStatusText( wxEmptyString, 5 ); break; + case DEGREES: wxASSERT( false ); break; } wxString line; // Display page size - #define milsTomm (25.4/1000) + #define MILS_TO_MM (25.4/1000) DSIZE size = GetPageSettings().GetSizeMils(); - size = size * milsTomm; + size = size * MILS_TO_MM; line.Printf( pagesizeformatter, size.x, size.y ); SetStatusText( line, 0 ); @@ -424,8 +451,7 @@ void PL_EDITOR_FRAME::UpdateStatusBar() } -void PL_EDITOR_FRAME::PrintPage( wxDC* aDC, LSET aPrintMasklayer, - bool aPrintMirrorMode, void * aData ) +void PL_EDITOR_FRAME::PrintPage( wxDC* aDC, LSET , bool , void * ) { GetScreen()-> m_ScreenNumber = GetPageNumberOption() ? 1 : 2; DrawWorkSheet( aDC, GetScreen(), 0, IU_PER_MILS, wxEmptyString ); @@ -434,7 +460,7 @@ void PL_EDITOR_FRAME::PrintPage( wxDC* aDC, LSET aPrintMasklayer, void PL_EDITOR_FRAME::RedrawActiveWindow( wxDC* aDC, bool aEraseBg ) { - + // JEY TODO: probably obsolete unless called for print.... GetScreen()-> m_ScreenNumber = GetPageNumberOption() ? 1 : 2; if( aEraseBg ) @@ -442,26 +468,18 @@ void PL_EDITOR_FRAME::RedrawActiveWindow( wxDC* aDC, bool aEraseBg ) m_canvas->DrawBackGround( aDC ); - const WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance(); - WORKSHEET_DATAITEM* selecteditem = GetSelectedItem(); + WS_DRAW_ITEM_LIST& drawList = GetPageLayout().GetDrawItems(); - // the color to draw selected items - if( GetDrawBgColor() == WHITE ) - WORKSHEET_DATAITEM::m_SelectedColor = DARKCYAN; - else - WORKSHEET_DATAITEM::m_SelectedColor = YELLOW; + drawList.SetDefaultPenSize( 0 ); + drawList.SetMilsToIUfactor( IU_PER_MILS ); + drawList.SetSheetNumber( GetScreen()->m_ScreenNumber ); + drawList.SetSheetCount( GetScreen()->m_NumberOfScreens ); + drawList.SetFileName( GetCurrFileName() ); + drawList.SetSheetName( GetScreenDesc() ); + drawList.SetSheetLayer( wxEmptyString ); - for( unsigned ii = 0; ; ii++ ) - { - WORKSHEET_DATAITEM* item = pglayout.GetItem( ii ); - - if( item == NULL ) - break; - - item->SetSelected( item == selecteditem ); - } - - DrawWorkSheet( aDC, GetScreen(), 0, IU_PER_MILS, GetCurrFileName() ); + // Draw item list + drawList.Draw( m_canvas->GetClipBox(), aDC, DARKMAGENTA ); #ifdef USE_WX_OVERLAY if( IsShown() ) @@ -482,52 +500,15 @@ void PL_EDITOR_FRAME::RedrawActiveWindow( wxDC* aDC, bool aEraseBg ) } -void PL_EDITOR_FRAME::RebuildDesignTree() +void PL_EDITOR_FRAME::HardRedraw() { - const WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance(); - int rectId = 0; - int lineId = 0; - int textId = 0; - int polyId = 0; - int bitmapId = 0; - - for( unsigned ii = 0; ii < pglayout.GetCount(); ii++ ) - { - WORKSHEET_DATAITEM* item = pglayout.GetItem( ii ); - switch( item->GetType() ) - { - case WORKSHEET_DATAITEM::WS_TEXT: - item->m_Name = wxString::Format( wxT( "text%d:%s" ), ++textId, - GetChars(item->GetClassName()) ); - break; - - case WORKSHEET_DATAITEM:: WS_SEGMENT: - item->m_Name = wxString::Format( wxT( "segm%d:%s" ), ++lineId, - GetChars(item->GetClassName()) ); - break; - - case WORKSHEET_DATAITEM::WS_RECT: - item->m_Name = wxString::Format( wxT( "rect%d:%s" ), ++rectId, - GetChars(item->GetClassName()) ); - break; - - case WORKSHEET_DATAITEM::WS_POLYPOLYGON: - item->m_Name = wxString::Format( wxT( "poly%d:%s" ), ++polyId, - GetChars(item->GetClassName()) ); - break; - - case WORKSHEET_DATAITEM::WS_BITMAP: - item->m_Name = wxString::Format( wxT( "bm%d:%s" ), ++bitmapId, - GetChars(item->GetClassName()) ); - break; - } - } - - m_treePagelayout->ReCreateDesignTree(); + static_cast( GetGalCanvas() )->DisplayWorksheet(); + m_propertiesPagelayout->CopyPrmsFromGeneralToPanel(); + m_canvas->Refresh(); } -WORKSHEET_DATAITEM * PL_EDITOR_FRAME::AddPageLayoutItem( int aType, int aIdx ) +WORKSHEET_DATAITEM* PL_EDITOR_FRAME::AddPageLayoutItem( int aType ) { WORKSHEET_DATAITEM * item = NULL; @@ -552,8 +533,7 @@ WORKSHEET_DATAITEM * PL_EDITOR_FRAME::AddPageLayoutItem( int aType, int aIdx ) case WORKSHEET_DATAITEM::WS_BITMAP: { wxFileDialog fileDlg( this, _( "Choose Image" ), wxEmptyString, wxEmptyString, - _( "Image Files " ) + wxImage::GetImageExtWildcard(), - wxFD_OPEN ); + _( "Image Files " ) + wxImage::GetImageExtWildcard(), wxFD_OPEN ); if( fileDlg.ShowModal() != wxID_OK ) return NULL; @@ -562,7 +542,7 @@ WORKSHEET_DATAITEM * PL_EDITOR_FRAME::AddPageLayoutItem( int aType, int aIdx ) if( !wxFileExists( fullFilename ) ) { - wxMessageBox( _( "Couldn't load image from \"%s\"" ), GetChars( fullFilename ) ); + wxMessageBox( _( "Couldn't load image from \"%s\"" ), fullFilename ); break; } @@ -570,8 +550,7 @@ WORKSHEET_DATAITEM * PL_EDITOR_FRAME::AddPageLayoutItem( int aType, int aIdx ) if( !image->ReadImageFile( fullFilename ) ) { - wxMessageBox( _( "Couldn't load image from \"%s\"" ), - GetChars( fullFilename ) ); + wxMessageBox( _( "Couldn't load image from \"%s\"" ), fullFilename ); delete image; break; } @@ -584,102 +563,8 @@ WORKSHEET_DATAITEM * PL_EDITOR_FRAME::AddPageLayoutItem( int aType, int aIdx ) if( item == NULL ) return NULL; - WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance(); - pglayout.Insert( item, aIdx ); - RebuildDesignTree(); - - return item; -} - - -WORKSHEET_DATAITEM * PL_EDITOR_FRAME::GetSelectedItem() -{ - WORKSHEET_DATAITEM* item = m_treePagelayout->GetPageLayoutSelectedItem(); - return item; -} - - -WORKSHEET_DATAITEM* PL_EDITOR_FRAME::Locate( wxDC* aDC, const wxPoint& aPosition ) -{ - const PAGE_INFO& pageInfo = GetPageSettings(); - TITLE_BLOCK t_block = GetTitleBlock(); - COLOR4D color = COLOR4D( RED ); // Needed, not used - PL_EDITOR_SCREEN* screen = (PL_EDITOR_SCREEN*) GetScreen(); - - screen-> m_ScreenNumber = GetPageNumberOption() ? 1 : 2; - - WS_DRAW_ITEM_LIST drawList; - drawList.SetPenSize( 0 ); - drawList.SetMilsToIUfactor( IU_PER_MILS ); - drawList.SetSheetNumber( screen->m_ScreenNumber ); - drawList.SetSheetCount( screen->m_NumberOfScreens ); - drawList.SetFileName( GetCurrFileName() ); - // GetScreenDesc() returns a temporary string. Store it to avoid issues. - wxString descr = GetScreenDesc(); - drawList.SetSheetName( descr ); - - drawList.BuildWorkSheetGraphicList( pageInfo, t_block, color, color ); - - // locate items. - // We do not use here the COLLECTOR classes in use in pcbnew and eeschema - // because the locate requirements are very basic. - std::vector list; - drawList.Locate( aDC, list, aPosition ); - - if( list.size() == 0 ) - return NULL; - - WS_DRAW_ITEM_BASE* drawitem = list[0]; - - // Choose item in list if more than 1 item - if( list.size() > 1 ) - { - wxArrayString choices; - wxString text; - wxPoint cursPos = GetCrossHairPosition(); - - for( unsigned ii = 0; ii < list.size(); ++ii ) - { - drawitem = list[ii]; - text = drawitem->GetParent()->m_Name; - - if( (drawitem->m_Flags & (LOCATE_STARTPOINT|LOCATE_ENDPOINT)) - == (LOCATE_STARTPOINT|LOCATE_ENDPOINT) ) - text << wxT( " " ) << _( "(start or end point)" ); - else - { - if( (drawitem->m_Flags & LOCATE_STARTPOINT) ) - text << wxT( " " ) << _( "(start point)" ); - - if( (drawitem->m_Flags & LOCATE_ENDPOINT) ) - text << wxT( " " ) << _( "(end point)" ); - } - - if( ! drawitem->GetParent()->m_Info.IsEmpty() ) - text << wxT( " \"" ) << drawitem->GetParent()->m_Info << wxT( "\"" ); - - choices.Add( text ); - } - - int selection = wxGetSingleChoiceIndex ( wxEmptyString, - _( "Selection Clarification" ), - choices, this ); - if( selection < 0 ) - return NULL; - - SetCrossHairPosition( cursPos ); - m_canvas->MoveCursorToCrossHair(); - drawitem = list[selection]; - } - - WORKSHEET_DATAITEM* item = drawitem->GetParent(); - item->ClearFlags( LOCATE_STARTPOINT|LOCATE_ENDPOINT ); - - if( (drawitem->m_Flags & LOCATE_STARTPOINT) ) - item->SetFlags( LOCATE_STARTPOINT ); - - if( (drawitem->m_Flags & LOCATE_ENDPOINT) ) - item->SetFlags( LOCATE_ENDPOINT ); + WORKSHEET_LAYOUT::GetTheInstance().Append( item ); + item->SyncDrawItems( nullptr, GetGalCanvas()->GetView() ); return item; } @@ -689,9 +574,11 @@ void PL_EDITOR_FRAME::OnNewPageLayout() { GetScreen()->ClearUndoRedoList(); GetScreen()->ClrModify(); + + static_cast( GetGalCanvas() )->DisplayWorksheet(); + m_propertiesPagelayout->CopyPrmsFromGeneralToPanel(); - RebuildDesignTree(); - Zoom_Automatique( false ); + m_toolManager->RunAction( ACTIONS::zoomFitScreen, true ); m_canvas->Refresh(); } diff --git a/pagelayout_editor/pl_editor_frame.h b/pagelayout_editor/pl_editor_frame.h index f8bdce8e96..bc1c49625e 100644 --- a/pagelayout_editor/pl_editor_frame.h +++ b/pagelayout_editor/pl_editor_frame.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2013 CERN - * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2016-2019 KiCad Developers, see AUTHORS.txt for contributors. * @author Jean-Pierre Charras, jp.charras at wanadoo.fr * * This program is free software; you can redistribute it and/or @@ -23,10 +23,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file pl_editor_frame.h - */ - #ifndef _PL_EDITOR_FRAME_H #define _PL_EDITOR_FRAME_H @@ -38,7 +34,6 @@ #include class PROPERTIES_FRAME; -class DESIGN_TREE_FRAME; class WORKSHEET_DATAITEM; @@ -51,7 +46,6 @@ class PL_EDITOR_FRAME : public EDA_DRAW_FRAME { PL_EDITOR_LAYOUT m_pageLayout; - int m_designTreeWidth; // the last width (in pixels) of m_treePagelayout int m_propertiesFrameWidth; // the last width (in pixels) of m_propertiesPagelayout wxChoice* m_originSelectBox; // Corner origin choice for coordinates @@ -65,7 +59,6 @@ class PL_EDITOR_FRAME : public EDA_DRAW_FRAME protected: /// The last filename chosen to be proposed to the user wxString m_lastFileName; - DESIGN_TREE_FRAME* m_treePagelayout; PROPERTIES_FRAME* m_propertiesPagelayout; private: @@ -74,7 +67,9 @@ private: public: PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ); - ~PL_EDITOR_FRAME(); + ~PL_EDITOR_FRAME() {} + + PROPERTIES_FRAME* GetPropertiesFrame() { return m_propertiesPagelayout; } bool OpenProjectFiles( const std::vector& aFileSet, int aCtl ) override; @@ -102,6 +97,9 @@ public: void OnCloseWindow( wxCloseEvent& Event ); + // The Tool Framework initalization + void setupTools(); + // Virtual basic functions: void RedrawActiveWindow( wxDC* DC, bool EraseBg ) override; void ReCreateHToolbar() override; @@ -163,17 +161,14 @@ public: void ReCreateOptToolbar(); void ReCreateMenuBar() override; - void OnLeftClick( wxDC* aDC, const wxPoint& aMousePos ) override; - void OnLeftDClick( wxDC* aDC, const wxPoint& aMousePos ) override; - bool OnRightClick( const wxPoint& aMousePos, wxMenu* aPopMenu ) override; double BestZoom() override; - // Events created by clicking on the design tree list: - void OnTreeSelection( wxTreeEvent& event ); - void OnTreeMiddleClick( wxTreeEvent& event ); - void OnTreeRightClick( wxTreeEvent& event ); + void SyncMenusAndToolbars() override; const PL_EDITOR_LAYOUT& GetPageLayout() const { return m_pageLayout; } + PL_EDITOR_LAYOUT& GetPageLayout() { return m_pageLayout; } + + const BOX2I GetDocumentExtents() const override; /** * Page layout editor can show the title block using a page number @@ -192,7 +187,7 @@ public: * Displays the short filename (if exists) loaded file * on the caption of the main window */ - void UpdateTitleAndInfo(); + void UpdateTitleAndInfo(); /** * Populates the applicatios settings list. @@ -202,20 +197,19 @@ public: * source code (mainly in dialogs). If you need to define a configuration * setting that need to be loaded at run time, this is the place to define it. */ - PARAM_CFG_ARRAY& GetConfigurationSettings( void ); + PARAM_CFG_ARRAY& GetConfigurationSettings(); void LoadSettings( wxConfigBase* aCfg ) override; void SaveSettings( wxConfigBase* aCfg ) override; - void Process_Special_Functions( wxCommandEvent& event ); - void OnSelectOptionToolbar( wxCommandEvent& event ); + void Process_Special_Functions( wxCommandEvent& event ); /** * called when the user select one of the 4 page corner as corner * reference (or the left top paper corner) */ - void OnSelectCoordOriginCorner( wxCommandEvent& event ); + void OnSelectCoordOriginCorner( wxCommandEvent& event ); /** * Toggle the display mode between the normal mode and the editor mode: @@ -225,53 +219,16 @@ public: * In editor mode, the format symbols in texts are not replaced * by the actual text, and therefore format symbols are displayed. */ - void OnSelectTitleBlockDisplayMode( wxCommandEvent& event ); + void OnSelectTitleBlockDisplayMode( wxCommandEvent& event ); void OnUpdateTitleBlockDisplayNormalMode( wxUpdateUIEvent& event ); void OnUpdateTitleBlockDisplaySpecialMode( wxUpdateUIEvent& event ); - void OnUpdateSelectTool( wxUpdateUIEvent& aEvent ); - - /** - * Function BlockCommand - * returns the block command (BLOCK_MOVE, BLOCK_COPY...) corresponding to - * the \a aKey (ALT, SHIFT ALT ..) - */ - virtual int BlockCommand( EDA_KEY key ) override; - - /** - * Function HandleBlockPlace - * handles the block place command. - */ - virtual void HandleBlockPlace( wxDC* DC ) override; - - /** - * Function HandleBlockEnd( ) - * handles the end of a block command, - * It is called at the end of the definition of the area of a block. - * Depending on the current block command, this command is executed - * or parameters are initialized to prepare a call to HandleBlockPlace - * in GetScreen()->m_BlockLocate - * - * @return false if no item selected, or command finished, - * true if some items found and HandleBlockPlace must be called later. - */ - virtual bool HandleBlockEnd( wxDC* DC ) override; - - /** - * Function Block_Move - * moves all items within the selected block. - * New location is determined by the current offset from the selected - * block's original location. - * - * @param DC A device context to draw on. - */ - void Block_Move( wxDC* DC ); /** * Function OnQuit * called on request of application quit */ - void OnQuit( wxCommandEvent& event ); + void OnQuit( wxCommandEvent& event ); ///> @copydoc EDA_DRAW_FRAME::GetHotKeyDescription() EDA_HOTKEY* GetHotKeyDescription( int aCommand ) const override; @@ -285,26 +242,26 @@ public: * @param aPosition The cursor position in logical (drawing) units. * @param aItem = NULL or pointer on a EDA_ITEM under the mouse cursor */ - bool OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosition, EDA_ITEM* aItem = NULL ) override; + bool OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosition, + EDA_ITEM* aItem = NULL ) override; - void Process_Settings( wxCommandEvent& event ); - void Process_Config( wxCommandEvent& event ); + void Process_Config( wxCommandEvent& event ); /** * Function ToPlotter * Open a dialog frame to create plot and drill files * relative to the current board */ - void ToPlotter( wxCommandEvent& event ); + void ToPlotter( wxCommandEvent& event ); /** * Function ToPrinter * Open a dialog frame to print layers */ - void ToPrinter( wxCommandEvent& event ); + void ToPrinter( wxCommandEvent& event ); - void Files_io( wxCommandEvent& event ); - bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey = 0 ) override; + void Files_io( wxCommandEvent& event ); + bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey = 0 ) override; /** Virtual function PrintPage * used to print a page @@ -313,8 +270,8 @@ public: * @param aPrintMirrorMode = not used here (Set when printing in mirror mode) * @param aData = a pointer on an auxiliary data (not always used, NULL if not used) */ - virtual void PrintPage( wxDC* aDC, LSET aPrintMasklayer, - bool aPrintMirrorMode, void * aData ) override; + virtual void PrintPage( wxDC* aDC, LSET aPrintMasklayer, bool aPrintMirrorMode, + void * aData ) override; void OnFileHistory( wxCommandEvent& event ); @@ -331,11 +288,9 @@ public: void SetCurrFileName( const wxString& aName ); /** - * Function RebuildDesignTree - * Re creates the design graphic tree list items, - * and ensures each item has an unique name + * Refresh the library tree and redraw the window */ - void RebuildDesignTree(); + void HardRedraw() override; /** * Function AddPageLayoutItem @@ -345,32 +300,7 @@ public: * @param aIdx = the position in list to insert the new item. * @return a reference to the new item */ - WORKSHEET_DATAITEM * AddPageLayoutItem( int aType, int aIdx = -1 ); - - /** - * Function GetSelectedItem - * @return the current selected item, or NULL - */ - WORKSHEET_DATAITEM * GetSelectedItem(); - - /** - * Function Locate - * @return the page layout item found at position aPosition - * @param aPosition = the position (in user units) of the reference point - */ - WORKSHEET_DATAITEM *Locate( wxDC* aDC, const wxPoint& aPosition ); - - /** - * Initialize a move item command - * @param aItem is the item to move - */ - void MoveItem( WORKSHEET_DATAITEM* aItem ); - - /** - * Save in Undo list the layout, and place an item being moved. - * @param aItem is the item moved - */ - void PlaceItem( WORKSHEET_DATAITEM* aItem ); + WORKSHEET_DATAITEM* AddPageLayoutItem( int aType ); /** * Must be called after a change @@ -391,19 +321,19 @@ public: * - Place the current edited layout in undo list * - Get the previous version of the current edited layput */ - void GetLayoutFromRedoList( wxCommandEvent& event ); + void GetLayoutFromRedoList(); /** Undo the last edit: * - Place the current layout in Redo list * - Get the previous version of the current edited layout */ - void GetLayoutFromUndoList( wxCommandEvent& event ); + void GetLayoutFromUndoList(); /** * Remove the last command in Undo List. * Used to clean the Undo stack after a cancel command */ - void RemoveLastCommandInUndoList(); + void RollbackFromUndo(); protected: bool saveCurrentPageLayout(); diff --git a/pagelayout_editor/pl_editor_id.h b/pagelayout_editor/pl_editor_id.h index f18aaa7c0a..c33b41ca6e 100644 --- a/pagelayout_editor/pl_editor_id.h +++ b/pagelayout_editor/pl_editor_id.h @@ -45,8 +45,6 @@ enum pl_editor_ids ID_PL_EDITOR_SHOW_SOURCE, ID_MENU_PL_EDITOR_SELECT_PREFERED_EDITOR, - ID_MENU_SWITCH_BGCOLOR, - ID_MENU_GRID_ONOFF, ID_DESIGN_TREE_FRAME, ID_SHOW_REAL_MODE, @@ -56,13 +54,16 @@ enum pl_editor_ids ID_APPEND_DESCR_FILE, + ID_PL_MOVE_TOOL, + ID_PL_LINE_TOOL, + ID_PL_RECTANGLE_TOOL, + ID_PL_TEXT_TOOL, + ID_PL_IMAGE_TOOL, + ID_PL_DELETE_TOOL, + ID_POPUP_START_RANGE, ID_POPUP_ITEM_DELETE, ID_POPUP_DESIGN_TREE_ITEM_DELETE, - ID_POPUP_ITEM_ADD_LINE, - ID_POPUP_ITEM_ADD_RECT, - ID_POPUP_ITEM_ADD_TEXT, - ID_POPUP_ITEM_ADD_BITMAP, ID_POPUP_ITEM_APPEND_PAGE_LAYOUT, ID_POPUP_ITEM_MOVE, ID_POPUP_ITEM_PLACE, diff --git a/pagelayout_editor/pl_editor_layout.h b/pagelayout_editor/pl_editor_layout.h index 724adb5d24..5eb4f6b883 100644 --- a/pagelayout_editor/pl_editor_layout.h +++ b/pagelayout_editor/pl_editor_layout.h @@ -31,13 +31,13 @@ #include #include #include +#include class EDA_DRAW_PANEL; /** * Class PL_EDITOR_LAYOUT - * holds list of GERBER_DRAW_ITEM currently loaded. */ class PL_EDITOR_LAYOUT { @@ -46,6 +46,8 @@ private: PAGE_INFO m_paper; TITLE_BLOCK m_titles; + WS_DRAW_ITEM_LIST m_drawItemList; + public: PL_EDITOR_LAYOUT(); ~PL_EDITOR_LAYOUT(); @@ -56,7 +58,7 @@ public: m_paper = aPageSettings; } - const wxPoint& GetAuxOrigin() const + const wxPoint& GetAuxOrigin() const { static wxPoint zero( 0, 0 ); return zero; @@ -67,6 +69,11 @@ public: return m_titles; } + WS_DRAW_ITEM_LIST& GetDrawItems() + { + return m_drawItemList; + } + void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) { m_titles = aTitleBlock; @@ -90,7 +97,6 @@ public: #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ) const; - #endif }; diff --git a/pagelayout_editor/pl_editor_screen.cpp b/pagelayout_editor/pl_editor_screen.cpp index 72566e9d96..dbf757c97f 100644 --- a/pagelayout_editor/pl_editor_screen.cpp +++ b/pagelayout_editor/pl_editor_screen.cpp @@ -1,10 +1,8 @@ -/** - * @file pl_editor_screen.cpp - */ /* * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2013 CERN + * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. * @author Jean-Pierre Charras, jp.charras at wanadoo.fr * * This program is free software; you can redistribute it and/or @@ -33,7 +31,7 @@ #include -#define MM_GRID( x ) wxRealPoint( x * IU_PER_MM, x * IU_PER_MM ) +#define MM_GRID( x ) wxRealPoint( x * IU_PER_MM, x * IU_PER_MM ) #define ZOOM_FACTOR( x ) ( x * IU_PER_MM / 1000 ) @@ -80,11 +78,11 @@ static GRID_TYPE pl_editorGridList[] = PL_EDITOR_SCREEN::PL_EDITOR_SCREEN( const wxSize& aPageSizeIU ) : BASE_SCREEN( SCREEN_T ) { - for( unsigned i = 0; i < arrayDim( pl_editorZoomList ); ++i ) - m_ZoomList.push_back( pl_editorZoomList[i] ); + for( double zoom : pl_editorZoomList ) + m_ZoomList.push_back( zoom ); - for( unsigned i = 0; i < arrayDim( pl_editorGridList ); ++i ) - AddGrid( pl_editorGridList[i] ); + for( GRID_TYPE grid : pl_editorGridList ) + AddGrid( grid ); // pl_editor uses the same frame position as schematic and board editors m_Center = false; @@ -92,8 +90,6 @@ PL_EDITOR_SCREEN::PL_EDITOR_SCREEN( const wxSize& aPageSizeIU ) : // Set the working grid size to a reasonable value SetGrid( MM_GRID( 1.0 ) ); - SetZoom( ZOOM_FACTOR( 350 ) ); // a default value for zoom - InitDataPoints( aPageSizeIU ); m_NumberOfScreens = 2; } @@ -105,18 +101,13 @@ PL_EDITOR_SCREEN::~PL_EDITOR_SCREEN() } -// virtual function int PL_EDITOR_SCREEN::MilsToIuScalar() { return (int)IU_PER_MILS; } -/* Virtual function needed by classes derived from BASE_SCREEN - * this is a virtual pure function in BASE_SCREEN - */ -void PL_EDITOR_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, - int aItemCount ) +void PL_EDITOR_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount ) { if( aItemCount == 0 ) return; diff --git a/pagelayout_editor/pl_editor_screen.h b/pagelayout_editor/pl_editor_screen.h index c9e86af57d..1b0dfbfd9b 100644 --- a/pagelayout_editor/pl_editor_screen.h +++ b/pagelayout_editor/pl_editor_screen.h @@ -54,15 +54,14 @@ public: * Function ClearUndoORRedoList * virtual pure in BASE_SCREEN, so it must be defined here */ - void ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount = -1 ) override; + /** * Function GetCurItem * returns the currently selected WORKSHEET_DATAITEM, overriding * BASE_SCREEN::GetCurItem(). * @return WORKSHEET_DATAITEM* - the one selected, or NULL. */ - WORKSHEET_DATAITEM* GetCurItem() const { return (WORKSHEET_DATAITEM*) BASE_SCREEN::GetCurItem(); diff --git a/pagelayout_editor/pl_editor_undo_redo.cpp b/pagelayout_editor/pl_editor_undo_redo.cpp index 9ae111bbf3..3951162162 100644 --- a/pagelayout_editor/pl_editor_undo_redo.cpp +++ b/pagelayout_editor/pl_editor_undo_redo.cpp @@ -1,12 +1,8 @@ -/** - * @file pl_editor_undo_redo.cpp - * @brief page layout editor: undo and redo functions - */ - /* * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2013 CERN + * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. * @author Jean-Pierre Charras, jp.charras at wanadoo.fr * * This program is free software; you can redistribute it and/or @@ -30,7 +26,7 @@ #include #include #include -#include +#include #include @@ -87,7 +83,7 @@ void PL_EDITOR_FRAME::SaveCopyInUndoList() * - Place the current edited layout in undo list * - Get previous version of the current edited layput */ -void PL_EDITOR_FRAME::GetLayoutFromRedoList( wxCommandEvent& event ) +void PL_EDITOR_FRAME::GetLayoutFromRedoList() { if ( GetScreen()->GetRedoCommandCount() <= 0 ) return; @@ -110,7 +106,6 @@ void PL_EDITOR_FRAME::GetLayoutFromRedoList( wxCommandEvent& event ) delete copyItem; OnModify(); - RebuildDesignTree(); m_canvas->Refresh(); } @@ -119,7 +114,7 @@ void PL_EDITOR_FRAME::GetLayoutFromRedoList( wxCommandEvent& event ) * - Place the current layout in Redo list * - Get previous version of the current edited layout */ -void PL_EDITOR_FRAME::GetLayoutFromUndoList( wxCommandEvent& event ) +void PL_EDITOR_FRAME::GetLayoutFromUndoList() { if ( GetScreen()->GetUndoCommandCount() <= 0 ) return; @@ -141,14 +136,13 @@ void PL_EDITOR_FRAME::GetLayoutFromUndoList( wxCommandEvent& event ) delete copyItem; OnModify(); - RebuildDesignTree(); m_canvas->Refresh(); } /* Remove the last command in Undo List. * Used to clean the uUndo stack after a cancel command */ -void PL_EDITOR_FRAME::RemoveLastCommandInUndoList() +void PL_EDITOR_FRAME::RollbackFromUndo() { if ( GetScreen()->GetUndoCommandCount() <= 0 ) return; diff --git a/pagelayout_editor/properties_frame.cpp b/pagelayout_editor/properties_frame.cpp index 16fe8ad359..a81002a947 100644 --- a/pagelayout_editor/properties_frame.cpp +++ b/pagelayout_editor/properties_frame.cpp @@ -1,11 +1,8 @@ -/** - * @file properties_frame.cpp - */ - /* * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2013 CERN + * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. * @author Jean-Pierre Charras, jp.charras at wanadoo.fr * * This program is free software; you can redistribute it and/or @@ -28,14 +25,21 @@ #include #include -#include +#include #include #include +#include +#include PROPERTIES_FRAME::PROPERTIES_FRAME( PL_EDITOR_FRAME* aParent ): PANEL_PROPERTIES_BASE( aParent ) { m_parent = aParent; + + wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ); + infoFont.SetSymbolicSize( wxFONTSIZE_SMALL ); + m_staticTextSizeInfo->SetFont( infoFont ); + m_staticTextInfoThickness->SetFont( infoFont ); } @@ -43,6 +47,7 @@ PROPERTIES_FRAME::~PROPERTIES_FRAME() { } + wxSize PROPERTIES_FRAME::GetMinSize() const { return wxSize( 150, -1 ); @@ -113,29 +118,22 @@ bool PROPERTIES_FRAME::CopyPrmsFromPanelToGeneral() return true; } + // Data transfert from item to widgets in properties frame void PROPERTIES_FRAME::CopyPrmsFromItemToPanel( WORKSHEET_DATAITEM* aItem ) { wxString msg; // Set parameters common to all WORKSHEET_DATAITEM types - m_textCtrlType->SetValue( aItem->GetClassName() ); + m_staticTextType->SetLabel( aItem->GetClassName() ); m_textCtrlComment->SetValue( aItem->m_Info ); switch( aItem->GetPage1Option() ) { - default: - case 0: - m_choicePageOpt->SetSelection( 0 ); - break; - - case 1: - m_choicePageOpt->SetSelection( 1 ); - break; - - case -1: - m_choicePageOpt->SetSelection( 2 ); - break; + default: + case ALL_PAGES: m_choicePageOpt->SetSelection( 0 ); break; + case FIRST_PAGE_ONLY: m_choicePageOpt->SetSelection( 1 ); break; + case SUBSEQUENT_PAGES: m_choicePageOpt->SetSelection( 2 ); break; } // Position/ start point @@ -146,14 +144,10 @@ void PROPERTIES_FRAME::CopyPrmsFromItemToPanel( WORKSHEET_DATAITEM* aItem ) switch( aItem->m_Pos.m_Anchor ) { - case RB_CORNER: // right bottom corner - m_comboBoxCornerPos->SetSelection( 2 ); break; - case RT_CORNER: // right top corner - m_comboBoxCornerPos->SetSelection( 0 ); break; - case LB_CORNER: // left bottom corner - m_comboBoxCornerPos->SetSelection( 3 ); break; - case LT_CORNER: // left top corner - m_comboBoxCornerPos->SetSelection( 1 ); break; + case RB_CORNER: m_comboBoxCornerPos->SetSelection( 2 ); break; + case RT_CORNER: m_comboBoxCornerPos->SetSelection( 0 ); break; + case LB_CORNER: m_comboBoxCornerPos->SetSelection( 3 ); break; + case LT_CORNER: m_comboBoxCornerPos->SetSelection( 1 ); break; } // End point @@ -164,14 +158,10 @@ void PROPERTIES_FRAME::CopyPrmsFromItemToPanel( WORKSHEET_DATAITEM* aItem ) switch( aItem->m_End.m_Anchor ) { - case RB_CORNER: // right bottom corner - m_comboBoxCornerEnd->SetSelection( 2 ); break; - case RT_CORNER: // right top corner - m_comboBoxCornerEnd->SetSelection( 0 ); break; - case LB_CORNER: // left bottom corner - m_comboBoxCornerEnd->SetSelection( 3 ); break; - case LT_CORNER: // left top corner - m_comboBoxCornerEnd->SetSelection( 1 ); break; + case RB_CORNER: m_comboBoxCornerEnd->SetSelection( 2 ); break; + case RT_CORNER: m_comboBoxCornerEnd->SetSelection( 0 ); break; + case LB_CORNER: m_comboBoxCornerEnd->SetSelection( 3 ); break; + case LT_CORNER: m_comboBoxCornerEnd->SetSelection( 1 ); break; } msg.Printf( wxT("%.3f"), aItem->m_LineWidth ); @@ -206,19 +196,21 @@ void PROPERTIES_FRAME::CopyPrmsFromItemToPanel( WORKSHEET_DATAITEM* aItem ) m_textCtrlConstraintY->SetValue( msg ); // Font Options - m_checkBoxBold->SetValue( item->IsBold() ); - m_checkBoxItalic->SetValue( item->IsItalic() ); + m_checkBoxBold->SetValue( item->m_Bold ); + m_checkBoxItalic->SetValue( item->m_Italic ); + switch( item->m_Hjustify ) { - case GR_TEXT_HJUSTIFY_LEFT: m_choiceHjustify->SetSelection( 0 ); break; - case GR_TEXT_HJUSTIFY_CENTER: m_choiceHjustify->SetSelection( 1 ); break; - case GR_TEXT_HJUSTIFY_RIGHT: m_choiceHjustify->SetSelection( 2 ); break; + case GR_TEXT_HJUSTIFY_LEFT: m_choiceHjustify->SetSelection( 0 ); break; + case GR_TEXT_HJUSTIFY_CENTER: m_choiceHjustify->SetSelection( 1 ); break; + case GR_TEXT_HJUSTIFY_RIGHT: m_choiceHjustify->SetSelection( 2 ); break; } + switch( item->m_Vjustify ) { - case GR_TEXT_VJUSTIFY_TOP: m_choiceVjustify->SetSelection( 0 ); break; - case GR_TEXT_VJUSTIFY_CENTER: m_choiceVjustify->SetSelection( 1 ); break; - case GR_TEXT_VJUSTIFY_BOTTOM: m_choiceVjustify->SetSelection( 2 ); break; + case GR_TEXT_VJUSTIFY_TOP: m_choiceVjustify->SetSelection( 0 ); break; + case GR_TEXT_VJUSTIFY_CENTER: m_choiceVjustify->SetSelection( 1 ); break; + case GR_TEXT_VJUSTIFY_BOTTOM: m_choiceVjustify->SetSelection( 2 ); break; } // Text size @@ -306,18 +298,24 @@ void PROPERTIES_FRAME::CopyPrmsFromItemToPanel( WORKSHEET_DATAITEM* aItem ) m_swItemProperties->Refresh(); } + // Event function called by clicking on the OK button void PROPERTIES_FRAME::OnAcceptPrms( wxCommandEvent& event ) { + PL_SELECTION_TOOL* selTool = m_parent->GetToolManager()->GetTool(); + SELECTION& selection = selTool->GetSelection(); + m_parent->SaveCopyInUndoList(); - WORKSHEET_DATAITEM* item = m_parent->GetSelectedItem(); - if( item ) + WS_DRAW_ITEM_BASE* drawItem = (WS_DRAW_ITEM_BASE*) selection.Front(); + + if( drawItem ) { - CopyPrmsFromPanelToItem( item ); + WORKSHEET_DATAITEM* dataItem = drawItem->GetPeer(); + CopyPrmsFromPanelToItem( dataItem ); // Be sure what is displayed is what is set for item // (mainly, texts can be modified if they contain "\n") - CopyPrmsFromItemToPanel( item ); + CopyPrmsFromItemToPanel( dataItem ); } CopyPrmsFromPanelToGeneral(); @@ -329,6 +327,7 @@ void PROPERTIES_FRAME::OnAcceptPrms( wxCommandEvent& event ) m_parent->GetCanvas()->Refresh(); } + void PROPERTIES_FRAME::OnSetDefaultValues( wxCommandEvent& event ) { WORKSHEET_DATAITEM::m_DefaultTextSize = @@ -355,18 +354,10 @@ bool PROPERTIES_FRAME::CopyPrmsFromPanelToItem( WORKSHEET_DATAITEM* aItem ) switch( m_choicePageOpt->GetSelection() ) { - default: - case 0: - aItem->SetPage1Option( 0 ); - break; - - case 1: - aItem->SetPage1Option( 1 ); - break; - - case 2: - aItem->SetPage1Option( -1 ); - break; + default: + case 0: aItem->SetPage1Option( ALL_PAGES ); break; + case 1: aItem->SetPage1Option( FIRST_PAGE_ONLY ); break; + case 2: aItem->SetPage1Option( SUBSEQUENT_PAGES ); break; } // Import thickness @@ -382,10 +373,10 @@ bool PROPERTIES_FRAME::CopyPrmsFromPanelToItem( WORKSHEET_DATAITEM* aItem ) switch( m_comboBoxCornerPos->GetSelection() ) { - case 2: aItem->m_Pos.m_Anchor = RB_CORNER; break; - case 0: aItem->m_Pos.m_Anchor = RT_CORNER; break; - case 3: aItem->m_Pos.m_Anchor = LB_CORNER; break; - case 1: aItem->m_Pos.m_Anchor = LT_CORNER; break; + case 2: aItem->m_Pos.m_Anchor = RB_CORNER; break; + case 0: aItem->m_Pos.m_Anchor = RT_CORNER; break; + case 3: aItem->m_Pos.m_Anchor = LB_CORNER; break; + case 1: aItem->m_Pos.m_Anchor = LT_CORNER; break; } // Import End point @@ -397,10 +388,10 @@ bool PROPERTIES_FRAME::CopyPrmsFromPanelToItem( WORKSHEET_DATAITEM* aItem ) switch( m_comboBoxCornerEnd->GetSelection() ) { - case 2: aItem->m_End.m_Anchor = RB_CORNER; break; - case 0: aItem->m_End.m_Anchor = RT_CORNER; break; - case 3: aItem->m_End.m_Anchor = LB_CORNER; break; - case 1: aItem->m_End.m_Anchor = LT_CORNER; break; + case 2: aItem->m_End.m_Anchor = RB_CORNER; break; + case 0: aItem->m_End.m_Anchor = RT_CORNER; break; + case 3: aItem->m_End.m_Anchor = LB_CORNER; break; + case 1: aItem->m_End.m_Anchor = LT_CORNER; break; } // Import Repeat prms @@ -425,20 +416,21 @@ bool PROPERTIES_FRAME::CopyPrmsFromPanelToItem( WORKSHEET_DATAITEM* aItem ) msg.ToLong( &itmp ); item->m_IncrementLabel = itmp; - item->SetBold( m_checkBoxBold->IsChecked() ); - item->SetItalic( m_checkBoxItalic->IsChecked() ); + item->m_Bold = m_checkBoxBold->IsChecked(); + item->m_Italic = m_checkBoxItalic->IsChecked(); switch( m_choiceHjustify->GetSelection() ) { - case 0: item->m_Hjustify = GR_TEXT_HJUSTIFY_LEFT; break; - case 1: item->m_Hjustify = GR_TEXT_HJUSTIFY_CENTER; break; - case 2: item->m_Hjustify = GR_TEXT_HJUSTIFY_RIGHT; break; + case 0: item->m_Hjustify = GR_TEXT_HJUSTIFY_LEFT; break; + case 1: item->m_Hjustify = GR_TEXT_HJUSTIFY_CENTER; break; + case 2: item->m_Hjustify = GR_TEXT_HJUSTIFY_RIGHT; break; } + switch( m_choiceVjustify->GetSelection() ) { - case 0: item->m_Vjustify = GR_TEXT_VJUSTIFY_TOP; break; - case 1: item->m_Vjustify = GR_TEXT_VJUSTIFY_CENTER; break; - case 2: item->m_Vjustify = GR_TEXT_VJUSTIFY_BOTTOM; break; + case 0: item->m_Vjustify = GR_TEXT_VJUSTIFY_TOP; break; + case 1: item->m_Vjustify = GR_TEXT_VJUSTIFY_CENTER; break; + case 2: item->m_Vjustify = GR_TEXT_VJUSTIFY_BOTTOM; break; } msg = m_textCtrlRotation->GetValue(); diff --git a/pagelayout_editor/toolbars_pl_editor.cpp b/pagelayout_editor/toolbars_pl_editor.cpp index 0578c75f48..fe7a334330 100644 --- a/pagelayout_editor/toolbars_pl_editor.cpp +++ b/pagelayout_editor/toolbars_pl_editor.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2016-2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2016-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2013 CERN * @author Jean-Pierre Charras, jp.charras at wanadoo.fr * @@ -19,21 +19,17 @@ * with this program. If not, see . */ -/** - * @file toolbars_pl_editor.cpp - * @brief Build tool bars - */ - #include #include #include #include +#include #include #include #include -void PL_EDITOR_FRAME::ReCreateHToolbar( void ) +void PL_EDITOR_FRAME::ReCreateHToolbar() { if( m_mainToolBar ) m_mainToolBar->Clear(); @@ -61,38 +57,15 @@ void PL_EDITOR_FRAME::ReCreateHToolbar( void ) _( "Print page layout" ) ); KiScaledSeparator( m_mainToolBar, this ); - - m_mainToolBar->AddTool( wxID_DELETE, wxEmptyString, KiScaledBitmap( delete_xpm, this ), - _( "Delete selected item" ) ); + m_mainToolBar->Add( ACTIONS::undo ); + m_mainToolBar->Add( ACTIONS::redo ); KiScaledSeparator( m_mainToolBar, this ); - - m_mainToolBar->AddTool( wxID_UNDO, wxEmptyString, - KiScaledBitmap( undo_xpm, this ), _( "Undo" ) ); - - m_mainToolBar->AddTool( wxID_REDO, wxEmptyString, - KiScaledBitmap( redo_xpm, this ), _( "Redo" ) ); - - // Standard Zoom controls: - // JEY TODO: move to COMMON_TOOLS.... - m_mainToolBar->AddSeparator(); - msg = AddHotkeyName( _( "Redraw view" ), PlEditorHotkeysDescr, HK_ZOOM_REDRAW, IS_COMMENT ); - m_mainToolBar->AddTool( ID_ZOOM_REDRAW, wxEmptyString, - KiScaledBitmap( zoom_redraw_xpm, this ), msg ); - - msg = AddHotkeyName( _( "Zoom in" ), PlEditorHotkeysDescr, HK_ZOOM_IN, IS_COMMENT ); - m_mainToolBar->AddTool( ID_ZOOM_IN, wxEmptyString, KiScaledBitmap( zoom_in_xpm, this ), msg ); - - msg = AddHotkeyName( _( "Zoom out" ), PlEditorHotkeysDescr, HK_ZOOM_OUT, IS_COMMENT ); - m_mainToolBar->AddTool( ID_ZOOM_OUT, wxEmptyString, KiScaledBitmap( zoom_out_xpm, this ), msg ); - - msg = AddHotkeyName( _( "Zoom to fit page" ), PlEditorHotkeysDescr, HK_ZOOM_AUTO, IS_COMMENT ); - m_mainToolBar->AddTool( ID_ZOOM_PAGE, wxEmptyString, - KiScaledBitmap( zoom_fit_in_page_xpm, this ), msg ); - - // Zoom-to-selection - m_mainToolBar->AddTool( ID_ZOOM_SELECTION, wxEmptyString, KiScaledBitmap( zoom_area_xpm, this ), - _( "Zoom to selection" ), wxITEM_CHECK ); + m_mainToolBar->Add( ACTIONS::zoomRedraw ); + m_mainToolBar->Add( ACTIONS::zoomInCenter ); + m_mainToolBar->Add( ACTIONS::zoomOutCenter ); + m_mainToolBar->Add( ACTIONS::zoomFitScreen ); + m_mainToolBar->Add( ACTIONS::zoomTool, ACTION_TOOLBAR::TOGGLE ); // Display mode switch KiScaledSeparator( m_mainToolBar, this ); @@ -119,8 +92,7 @@ void PL_EDITOR_FRAME::ReCreateHToolbar( void ) }; m_originSelectBox = new wxChoice( m_mainToolBar, ID_SELECT_COORDINATE_ORIGIN, - wxDefaultPosition, wxDefaultSize, - 5, choiceList ); + wxDefaultPosition, wxDefaultSize, 5, choiceList ); m_mainToolBar->AddControl( m_originSelectBox ); m_originSelectBox->SetToolTip( _("Origin of coordinates displayed to the status bar") ); @@ -140,8 +112,7 @@ void PL_EDITOR_FRAME::ReCreateHToolbar( void ) }; m_pageSelectBox = new wxChoice( m_mainToolBar, ID_SELECT_PAGE_NUMBER, - wxDefaultPosition, wxDefaultSize, - 2, pageList ); + wxDefaultPosition, wxDefaultSize, 2, pageList ); m_mainToolBar->AddControl( m_pageSelectBox ); m_pageSelectBox->SetToolTip( _("Simulate page 1 or other pages to show how items\n"\ "which are not on all page are displayed") ); @@ -153,7 +124,7 @@ void PL_EDITOR_FRAME::ReCreateHToolbar( void ) } -void PL_EDITOR_FRAME::ReCreateVToolbar( void ) +void PL_EDITOR_FRAME::ReCreateVToolbar() { if( m_drawToolBar ) m_drawToolBar->Clear(); @@ -161,15 +132,38 @@ void PL_EDITOR_FRAME::ReCreateVToolbar( void ) m_drawToolBar = new ACTION_TOOLBAR( this, ID_V_TOOLBAR, wxDefaultPosition, wxDefaultSize, KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL ); - // Set up toolbar - m_drawToolBar->AddTool( ID_NO_TOOL_SELECTED, wxEmptyString, - KiScaledBitmap( cursor_xpm, this ) ); + m_drawToolBar->Add( PL_ACTIONS::selectionTool, ACTION_TOOLBAR::TOGGLE ); + KiScaledSeparator( m_drawToolBar, this ); + m_drawToolBar->Add( PL_ACTIONS::drawLine, ACTION_TOOLBAR::TOGGLE ); + m_drawToolBar->Add( PL_ACTIONS::drawRectangle, ACTION_TOOLBAR::TOGGLE ); + m_drawToolBar->Add( PL_ACTIONS::placeText, ACTION_TOOLBAR::TOGGLE ); + m_drawToolBar->Add( PL_ACTIONS::placeImage, ACTION_TOOLBAR::TOGGLE ); + + KiScaledSeparator( m_drawToolBar, this ); + m_drawToolBar->Add( PL_ACTIONS::deleteItemCursor, ACTION_TOOLBAR::TOGGLE ); m_drawToolBar->Realize(); } -void PL_EDITOR_FRAME::ReCreateOptToolbar( void ) +void PL_EDITOR_FRAME::ReCreateOptToolbar() { } + + +void PL_EDITOR_FRAME::SyncMenusAndToolbars() +{ + m_mainToolBar->Toggle( ACTIONS::undo, GetScreen() && GetScreen()->GetUndoCommandCount() > 0 ); + m_mainToolBar->Toggle( ACTIONS::redo, GetScreen() && GetScreen()->GetRedoCommandCount() > 0 ); + m_mainToolBar->Toggle( ACTIONS::zoomTool, GetToolId() == ID_ZOOM_SELECTION ); + m_mainToolBar->Refresh(); + + m_drawToolBar->Toggle( PL_ACTIONS::selectionTool, GetToolId() == ID_NO_TOOL_SELECTED ); + m_drawToolBar->Toggle( PL_ACTIONS::drawLine, GetToolId() == ID_PL_LINE_TOOL ); + m_drawToolBar->Toggle( PL_ACTIONS::drawRectangle, GetToolId() == ID_PL_RECTANGLE_TOOL ); + m_drawToolBar->Toggle( PL_ACTIONS::placeText, GetToolId() == ID_PL_TEXT_TOOL ); + m_drawToolBar->Toggle( PL_ACTIONS::placeImage, GetToolId() == ID_PL_IMAGE_TOOL ); + m_drawToolBar->Toggle( PL_ACTIONS::deleteItemCursor, GetToolId() == ID_PL_DELETE_TOOL ); + m_drawToolBar->Refresh(); +} diff --git a/pagelayout_editor/tools/pl_actions.cpp b/pagelayout_editor/tools/pl_actions.cpp new file mode 100644 index 0000000000..1e9f6fe064 --- /dev/null +++ b/pagelayout_editor/tools/pl_actions.cpp @@ -0,0 +1,52 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 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 + */ + +#include +#include +#include +#include +#include "pl_actions.h" + + +TOOL_ACTION PL_ACTIONS::refreshPreview( "plEditor.EditorControl.refreshPreview", + AS_GLOBAL, 0, "", "" ); + +TOOL_ACTION PL_ACTIONS::toggleBackground( "plEditor.EditorControl.ToggleBackground", + AS_GLOBAL, 0, + _( "Background White" ), _( "Switch between white and black background" ), + palette_xpm ); + + +OPT PL_ACTIONS::TranslateLegacyId( int aId ) +{ + switch( aId ) + { + case ID_MOUSE_CLICK: + return ACTIONS::cursorClick.MakeEvent(); + + case ID_MOUSE_DOUBLECLICK: + return ACTIONS::cursorDblClick.MakeEvent(); + } + + return OPT(); +} diff --git a/pagelayout_editor/tools/pl_actions.h b/pagelayout_editor/tools/pl_actions.h new file mode 100644 index 0000000000..de547d4483 --- /dev/null +++ b/pagelayout_editor/tools/pl_actions.h @@ -0,0 +1,88 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 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 + */ + +#ifndef PL_ACTIONS_H +#define PL_ACTIONS_H + +#include +#include +#include + +class TOOL_EVENT; +class TOOL_MANAGER; + +/** + * Class PL_ACTIONS + * + * Gathers all the actions that are shared by tools. The instance of PL_ACTIONS is created + * inside of ACTION_MANAGER object that registers the actions. + */ +class PL_ACTIONS : public ACTIONS +{ +public: + // Selection Tool + /// Activation of the selection tool + static TOOL_ACTION selectionActivate; + + /// Clears the current selection + static TOOL_ACTION clearSelection; + + /// Selects an item (specified as the event parameter). + static TOOL_ACTION addItemToSel; + static TOOL_ACTION removeItemFromSel; + + /// Selects a list of items (specified as the event parameter) + static TOOL_ACTION addItemsToSel; + static TOOL_ACTION removeItemsFromSel; + + /// Runs a selection menu to select from a list of items + static TOOL_ACTION selectionMenu; + + // Tools + static TOOL_ACTION selectionTool; + static TOOL_ACTION pickerTool; + static TOOL_ACTION placeText; + static TOOL_ACTION placeImage; + static TOOL_ACTION drawRectangle; + static TOOL_ACTION drawLine; + static TOOL_ACTION addText; + static TOOL_ACTION addImage; + static TOOL_ACTION addRectangle; + static TOOL_ACTION addLine; + static TOOL_ACTION appendImportedWorksheet; + + // Editing + static TOOL_ACTION move; + static TOOL_ACTION doDelete; // <<<<<<<< move to actions.h + + // Miscellaneous + static TOOL_ACTION deleteItemCursor; + static TOOL_ACTION refreshPreview; + static TOOL_ACTION toggleBackground; + + ///> @copydoc COMMON_ACTIONS::TranslateLegacyId() + virtual OPT TranslateLegacyId( int aId ) override; +}; + + +#endif diff --git a/pagelayout_editor/tools/pl_drawing_tools.cpp b/pagelayout_editor/tools/pl_drawing_tools.cpp new file mode 100644 index 0000000000..9cf410eb11 --- /dev/null +++ b/pagelayout_editor/tools/pl_drawing_tools.cpp @@ -0,0 +1,374 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 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 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +// Drawing tool actions +TOOL_ACTION PL_ACTIONS::drawLine( "plEditor.InteractiveDrawing.drawLine", + AS_GLOBAL, 0, + _( "Add Line" ), _( "Add a line" ), + add_graphical_segments_xpm, AF_ACTIVATE ); + +TOOL_ACTION PL_ACTIONS::drawRectangle( "plEditor.InteractiveDrawing.drawRectangle", + AS_GLOBAL, 0, + _( "Add Rectangle" ), _( "Add a rectangle" ), + add_rectangle_xpm, AF_ACTIVATE ); + +TOOL_ACTION PL_ACTIONS::placeText( "plEditor.InteractiveDrawing.placeText", + AS_GLOBAL, 0, + _( "Add Text" ), _( "Add a text item" ), + text_xpm, AF_ACTIVATE ); + +TOOL_ACTION PL_ACTIONS::placeImage( "plEditor.InteractiveDrawing.placeImage", + AS_GLOBAL, 0, + _( "Add Bitmap" ), _( "Add a bitmap image" ), + image_xpm, AF_ACTIVATE ); + +TOOL_ACTION PL_ACTIONS::addLine( "plEditor.InteractiveDrawing.addLine", + AS_GLOBAL, 0, + _( "Add Line" ), _( "Add a line" ), + add_dashed_line_xpm, AF_ACTIVATE ); + +TOOL_ACTION PL_ACTIONS::addRectangle( "plEditor.InteractiveDrawing.addRectangle", + AS_GLOBAL, 0, + _( "Add Rectangle" ), _( "Add a rectangle" ), + add_rectangle_xpm, AF_ACTIVATE ); + +TOOL_ACTION PL_ACTIONS::addText( "plEditor.InteractiveDrawing.addText", + AS_GLOBAL, 0, + _( "Add Text" ), _( "Add a text item" ), + text_xpm, AF_ACTIVATE ); + +TOOL_ACTION PL_ACTIONS::addImage( "plEditor.InteractiveDrawing.addImage", + AS_GLOBAL, 0, + _( "Add Bitmap" ), _( "Add a bitmap image" ), + image_xpm, AF_ACTIVATE ); + +TOOL_ACTION PL_ACTIONS::appendImportedWorksheet( "plEditor.InteractiveDrawing.appendWorksheet", + AS_GLOBAL, 0, + _( "Append Existing Page Layout File..." ), + _( "Append an existing page layout design file to current file" ), + pagelayout_load_xpm, AF_ACTIVATE ); + + +PL_DRAWING_TOOLS::PL_DRAWING_TOOLS() : + TOOL_INTERACTIVE( "plEditor.InteractiveDrawing" ), + m_frame( nullptr ), + m_selectionTool( nullptr ), + m_menu( *this ) +{ +} + + +bool PL_DRAWING_TOOLS::Init() +{ + m_frame = getEditFrame(); + m_selectionTool = m_toolMgr->GetTool(); + + auto& ctxMenu = m_menu.GetMenu(); + + // cancel current tool goes in main context menu at the top if present + ctxMenu.AddItem( ACTIONS::cancelInteractive, SELECTION_CONDITIONS::ShowAlways, 1 ); + ctxMenu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1 ); + + // Finally, add the standard zoom/grid items + m_menu.AddStandardSubMenus( m_frame ); + + return true; +} + + +void PL_DRAWING_TOOLS::Reset( RESET_REASON aReason ) +{ + if( aReason == MODEL_RELOAD ) + m_frame = getEditFrame(); +} + + +int PL_DRAWING_TOOLS::PlaceItem( const TOOL_EVENT& aEvent ) +{ + bool isText; + bool isImmediate = false; + + if( aEvent.IsAction( &PL_ACTIONS::placeText ) ) + { + isText = true; + m_frame->SetToolID( ID_PL_TEXT_TOOL, wxCURSOR_PENCIL, _( "Add text" ) ); + } + else if( aEvent.IsAction( &PL_ACTIONS::placeImage ) ) + { + isText = false; + m_frame->SetToolID( ID_PL_IMAGE_TOOL, wxCURSOR_PENCIL, _( "Add image" ) ); + } + else if( aEvent.IsAction( & PL_ACTIONS::addText ) ) + { + isText = true; + isImmediate = true; + } + else if( aEvent.IsAction( & PL_ACTIONS::addImage ) ) + { + isText = false; + isImmediate = true; + } + else + wxCHECK_MSG( false, 0, "Unknown action in PL_DRAWING_TOOLS::PlaceItem()" ); + + VECTOR2I cursorPos; + WS_DRAW_ITEM_BASE* item = nullptr; + + m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true ); + getViewControls()->ShowCursor( true ); + + Activate(); + + // Main loop: keep receiving events + while( OPT_TOOL_EVENT evt = Wait() ) + { + cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) ); + + if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) ) + { + if( item ) + { + m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true ); + delete item; + item = nullptr; + + // There's nothing to roll-back, but we still need to pop the undo stack + m_frame->RollbackFromUndo(); + + if( !evt->IsActivate() && !isImmediate ) + continue; + } + + break; + } + + else if( evt->IsClick( BUT_LEFT ) || ( isImmediate && !item ) ) + { + // First click creates... + if( !item ) + { + m_frame->SaveCopyInUndoList(); + + m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true ); + + WORKSHEET_DATAITEM* dataItem; + dataItem = m_frame->AddPageLayoutItem( isText ? WORKSHEET_DATAITEM::WS_TEXT + : WORKSHEET_DATAITEM::WS_BITMAP ); + item = dataItem->GetDrawItems()[0]; + item->SetFlags( IS_NEW | IS_MOVED ); + m_selectionTool->AddItemToSel( item ); + } + + // ... and second click places: + else + { + item->GetPeer()->MoveStartPointToUi( (wxPoint) cursorPos ); + item->SetPosition( item->GetPeer()->GetStartPosUi( 0 ) ); + item->ClearEditFlags(); + getView()->Update( item ); + + item = nullptr; + + m_frame->OnModify(); + + if( isImmediate ) + break; + } + } + else if( evt->IsClick( BUT_RIGHT ) ) + { + // Warp after context menu only if dragging... + if( !item ) + m_toolMgr->VetoContextMenuMouseWarp(); + + m_menu.ShowContextMenu( m_selectionTool->GetSelection() ); + } + + else if( item && ( evt->IsAction( &PL_ACTIONS::refreshPreview ) || evt->IsMotion() ) ) + { + item->GetPeer()->MoveStartPointToUi( (wxPoint) cursorPos ); + item->SetPosition( item->GetPeer()->GetStartPosUi( 0 ) ); + getView()->Update( item ); + } + + // Enable autopanning and cursor capture only when there is an item to be placed + getViewControls()->SetAutoPan( !!item ); + getViewControls()->CaptureCursor( !!item ); + } + + m_frame->SetNoToolSelected(); + + return 0; +} + + +int PL_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) +{ + // We might be running as the same shape in another co-routine. Make sure that one + // gets whacked. + m_toolMgr->DeactivateTool(); + + bool isDrawLine; + bool isImmediate = false; + + if( aEvent.IsAction( &PL_ACTIONS::drawLine ) ) + { + isDrawLine = true; + m_frame->SetToolID( ID_PL_LINE_TOOL, wxCURSOR_PENCIL, _( "Draw line" ) ); + } + else if( aEvent.IsAction( &PL_ACTIONS::drawRectangle ) ) + { + isDrawLine = false; + m_frame->SetToolID( ID_PL_RECTANGLE_TOOL, wxCURSOR_PENCIL, _( "Draw rectangle" ) ); + } + else if( aEvent.IsAction( &PL_ACTIONS::addLine ) ) + { + isDrawLine = true; + isImmediate = true; + } + else if( aEvent.IsAction( &PL_ACTIONS::addRectangle ) ) + { + isDrawLine = false; + isImmediate = true; + } + else + wxCHECK_MSG( false, 0, "Unknown action in PL_DRAWING_TOOLS::DrawShape()" ); + + m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true ); + getViewControls()->ShowCursor( true ); + + Activate(); + + WS_DRAW_ITEM_BASE* item = nullptr; + + // Main loop: keep receiving events + while( auto evt = Wait() ) + { + VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) ); + + if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) ) + { + m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true ); + + if( item ) + { + WORKSHEET_LAYOUT::GetTheInstance().Remove( item->GetPeer() ); + item = nullptr; + + if( !evt->IsActivate() && !isImmediate ) + continue; + } + + break; + } + + else if( evt->IsClick( BUT_LEFT ) || ( isImmediate && !item ) ) + { + if( !item ) // start drawing + { + m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true ); + + WORKSHEET_DATAITEM::WS_ITEM_TYPE dataType; + + if( isDrawLine ) + dataType = WORKSHEET_DATAITEM::WS_SEGMENT; + else + dataType = WORKSHEET_DATAITEM::WS_RECT; + + WORKSHEET_DATAITEM* dataItem = m_frame->AddPageLayoutItem( dataType ); + dataItem->MoveToUi( (wxPoint) cursorPos ); + + item = dataItem->GetDrawItems()[0]; + item->SetFlags( IS_NEW ); + m_selectionTool->AddItemToSel( item ); + } + else // finish drawing + { + item->ClearEditFlags(); + item = nullptr; + + m_frame->OnModify(); + + if( isImmediate ) + break; + } + } + + else if( evt->IsAction( &PL_ACTIONS::refreshPreview ) || evt->IsMotion() ) + { + if( item ) + { + item->GetPeer()->MoveEndPointToUi( (wxPoint) cursorPos ); + item->SetEnd( item->GetPeer()->GetEndPosUi( 0 ) ); + getView()->Update( item ); + } + } + + else if( evt->IsClick( BUT_RIGHT ) ) + { + // Warp after context menu only if dragging... + if( !item ) + m_toolMgr->VetoContextMenuMouseWarp(); + + m_menu.ShowContextMenu( m_selectionTool->GetSelection() ); + } + + // Enable autopanning and cursor capture only when there is a shape being drawn + getViewControls()->SetAutoPan( !!item ); + getViewControls()->CaptureCursor( !!item ); + } + + m_frame->SetNoToolSelected(); + + return 0; +} + + +void PL_DRAWING_TOOLS::setTransitions() +{ + Go( &PL_DRAWING_TOOLS::DrawShape, PL_ACTIONS::drawLine.MakeEvent() ); + Go( &PL_DRAWING_TOOLS::DrawShape, PL_ACTIONS::addLine.MakeEvent() ); + Go( &PL_DRAWING_TOOLS::DrawShape, PL_ACTIONS::drawRectangle.MakeEvent() ); + Go( &PL_DRAWING_TOOLS::DrawShape, PL_ACTIONS::addRectangle.MakeEvent() ); + Go( &PL_DRAWING_TOOLS::PlaceItem, PL_ACTIONS::placeText.MakeEvent() ); + Go( &PL_DRAWING_TOOLS::PlaceItem, PL_ACTIONS::addText.MakeEvent() ); + Go( &PL_DRAWING_TOOLS::PlaceItem, PL_ACTIONS::placeImage.MakeEvent() ); + Go( &PL_DRAWING_TOOLS::PlaceItem, PL_ACTIONS::addImage.MakeEvent() ); +} diff --git a/pagelayout_editor/tools/pl_drawing_tools.h b/pagelayout_editor/tools/pl_drawing_tools.h new file mode 100644 index 0000000000..ec769a0633 --- /dev/null +++ b/pagelayout_editor/tools/pl_drawing_tools.h @@ -0,0 +1,70 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 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 + */ + +#ifndef PL_DRAWING_TOOLS_H +#define PL_DRAWING_TOOLS_H + +#include +#include +#include + +class PL_EDITOR_FRAME; +class PL_SELECTION_TOOL; + + +/** + * Class PL_DRAWING_TOOLS + * + * Tool responsible for drawing/placing items (lines, rectangles, text, etc.) + */ + +class PL_DRAWING_TOOLS : public TOOL_INTERACTIVE +{ +public: + PL_DRAWING_TOOLS(); + ~PL_DRAWING_TOOLS() {} + + /// @copydoc TOOL_INTERACTIVE::Init() + bool Init() override; + + /// @copydoc TOOL_INTERACTIVE::Reset() + void Reset( RESET_REASON aReason ) override; + + TOOL_MENU& GetToolMenu() { return m_menu; } + + int DrawShape( const TOOL_EVENT& aEvent ); + int PlaceItem( const TOOL_EVENT& aEvent ); + +private: + ///> Sets up handlers for various events. + void setTransitions() override; + +private: + PL_EDITOR_FRAME* m_frame; + PL_SELECTION_TOOL* m_selectionTool; + + /// Menu model displayed by the tool. + TOOL_MENU m_menu; +}; + +#endif /* PL_DRAWING_TOOLS_H */ diff --git a/pagelayout_editor/tools/pl_edit_tool.cpp b/pagelayout_editor/tools/pl_edit_tool.cpp new file mode 100644 index 0000000000..5ba71f15e4 --- /dev/null +++ b/pagelayout_editor/tools/pl_edit_tool.cpp @@ -0,0 +1,397 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 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 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +TOOL_ACTION PL_ACTIONS::move( "plEditor.InteractiveEdit.move", + AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_MOVE ), + _( "Move" ), _( "Moves the selected item(s)" ), + move_xpm, AF_ACTIVATE ); + +TOOL_ACTION PL_ACTIONS::deleteItemCursor( "plEditor.InteractiveEdit.deleteTool", + AS_GLOBAL, 0, + _( "Delete Items" ), _( "Delete clicked items" ), + delete_xpm, AF_ACTIVATE ); + +TOOL_ACTION PL_ACTIONS::doDelete( "plEditor.InteractiveEdit.delete", + AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_DELETE ), + _( "Delete" ), _( "Deletes selected item(s)" ), + delete_xpm ); + + +PL_EDIT_TOOL::PL_EDIT_TOOL() : + TOOL_INTERACTIVE( "plEditor.InteractiveEdit" ), + m_frame( nullptr ), + m_selectionTool( nullptr ), + m_menu( *this ) +{ +} + + +bool PL_EDIT_TOOL::Init() +{ + m_frame = getEditFrame(); + m_selectionTool = m_toolMgr->GetTool(); + + wxASSERT_MSG( m_selectionTool, "plEditor.InteractiveSelection tool is not available" ); + + CONDITIONAL_MENU& ctxMenu = m_menu.GetMenu(); + + // cancel current tool goes in main context menu at the top if present + ctxMenu.AddItem( ACTIONS::cancelInteractive, SELECTION_CONDITIONS::ShowAlways, 1 ); + + ctxMenu.AddSeparator( SELECTION_CONDITIONS::NotEmpty ); + ctxMenu.AddItem( PL_ACTIONS::doDelete, SELECTION_CONDITIONS::NotEmpty, 200 ); + + // Finally, add the standard zoom/grid items + m_menu.AddStandardSubMenus( m_frame ); + + // + // Add editing actions to the selection tool menu + // + CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu(); + + selToolMenu.AddItem( PL_ACTIONS::doDelete, SELECTION_CONDITIONS::NotEmpty, 200 ); + + return true; +} + + +void PL_EDIT_TOOL::Reset( RESET_REASON aReason ) +{ + if( aReason == MODEL_RELOAD ) + m_frame = getEditFrame(); +} + + +int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) +{ + KIGFX::VIEW_CONTROLS* controls = getViewControls(); + + controls->SetSnapping( true ); + VECTOR2I originalCursorPos = controls->GetCursorPosition(); + + // Be sure that there is at least one item that we can move. If there's no selection try + // looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection). + SELECTION& selection = m_selectionTool->RequestSelection(); + bool unselect = selection.IsHover(); + + if( selection.Empty() ) + return 0; + + m_frame->SetToolID( ID_PL_MOVE_TOOL, wxCURSOR_DEFAULT, _( "Move Items" ) ); + + Activate(); + controls->ShowCursor( true ); + controls->SetAutoPan( true ); + + bool restore_state = false; + bool chain_commands = false; + OPT_TOOL_EVENT evt = aEvent; + VECTOR2I prevPos; + + if( !selection.Front()->IsNew() ) + m_frame->SaveCopyInUndoList(); + + // Main loop: keep receiving events + do + { + controls->SetSnapping( !evt->Modifier( MD_ALT ) ); + + if( evt->IsAction( &PL_ACTIONS::move ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT ) + || evt->IsAction( &PL_ACTIONS::refreshPreview ) ) + { + //------------------------------------------------------------------------ + // Start a move operation + // + if( !m_moveInProgress ) + { + // Apply any initial offset in case we're coming from a previous command. + // + for( EDA_ITEM* item : selection ) + moveItem( item, m_moveOffset ); + + // Set up the starting position and move/drag offset + // + m_cursor = controls->GetCursorPosition(); + + if( selection.HasReferencePoint() ) + { + VECTOR2I delta = m_cursor - selection.GetReferencePoint(); + + // Drag items to the current cursor position + for( EDA_ITEM* item : selection ) + moveItem( item, delta ); + + selection.SetReferencePoint( m_cursor ); + } + else if( selection.Size() == 1 ) + { + // Set the current cursor position to the first dragged item origin, + // so the movement vector can be computed later + updateModificationPoint( selection ); + m_cursor = originalCursorPos; + } + else + { + updateModificationPoint( selection ); + } + + controls->SetCursorPosition( m_cursor, false ); + + prevPos = m_cursor; + controls->SetAutoPan( true ); + m_moveInProgress = true; + } + + //------------------------------------------------------------------------ + // Follow the mouse + // + m_cursor = controls->GetCursorPosition(); + VECTOR2I delta( m_cursor - prevPos ); + selection.SetReferencePoint( m_cursor ); + + m_moveOffset += delta; + prevPos = m_cursor; + + for( EDA_ITEM* item : selection ) + moveItem( item, delta ); + + m_toolMgr->PostEvent( EVENTS::SelectedItemsModified ); + } + //------------------------------------------------------------------------ + // Handle cancel + // + else if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) ) + { + if( m_moveInProgress ) + restore_state = true; + + break; + } + //------------------------------------------------------------------------ + // Handle TOOL_ACTION special cases + // + else if( evt->Action() == TA_UNDO_REDO_PRE ) + { + unselect = true; + break; + } + else if( evt->Category() == TC_COMMAND ) + { + if( evt->IsAction( &PL_ACTIONS::doDelete ) ) + { + // Exit on a remove operation; there is no further processing for removed items. + break; + } + } + //------------------------------------------------------------------------ + // Handle context menu + // + else if( evt->IsClick( BUT_RIGHT ) ) + { + m_menu.ShowContextMenu( m_selectionTool->GetSelection() ); + } + //------------------------------------------------------------------------ + // Handle drop + // + else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) + { + break; // Finish + } + + } while( ( evt = Wait() ) ); //Should be assignment not equality test + + controls->ForceCursorPosition( false ); + controls->ShowCursor( false ); + controls->SetSnapping( false ); + controls->SetAutoPan( false ); + + if( !chain_commands ) + m_moveOffset = { 0, 0 }; + + m_moveInProgress = false; + m_frame->SetNoToolSelected(); + + selection.ClearReferencePoint(); + + for( auto item : selection ) + item->ClearEditFlags(); + + if( unselect ) + m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true ); + + if( restore_state ) + m_frame->RollbackFromUndo(); + else + m_frame->OnModify(); + + return 0; +} + + +void PL_EDIT_TOOL::moveItem( EDA_ITEM* aItem, VECTOR2I aDelta ) +{ + WS_DRAW_ITEM_BASE* drawItem = static_cast( aItem ); + WORKSHEET_DATAITEM* dataItem = drawItem->GetPeer(); + + dataItem->MoveToUi( dataItem->GetStartPosUi() + (wxPoint) aDelta ); + + for( WS_DRAW_ITEM_BASE* item : dataItem->GetDrawItems() ) + { + // Remove/add is better than update as it handles rtree re-adjustment + getView()->Remove( item ); + getView()->Add( item ); + item->SetFlags( IS_MOVED ); + } +} + + +bool PL_EDIT_TOOL::updateModificationPoint( SELECTION& aSelection ) +{ + if( m_moveInProgress && aSelection.HasReferencePoint() ) + return false; + + // When there is only one item selected, the reference point is its position... + if( aSelection.Size() == 1 ) + { + WS_DRAW_ITEM_BASE* item = static_cast( aSelection.Front() ); + aSelection.SetReferencePoint( item->GetPosition() ); + } + // ...otherwise modify items with regard to the grid-snapped cursor position + else + { + m_cursor = getViewControls()->GetCursorPosition( true ); + aSelection.SetReferencePoint( m_cursor ); + } + + return true; +} + + +int PL_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent ) +{ + SELECTION& selection = m_selectionTool->RequestSelection(); + + if( selection.Size() == 0 ) + return 0; + + m_frame->SaveCopyInUndoList(); + + while( selection.Front() ) + { + WS_DRAW_ITEM_BASE* drawItem = static_cast( selection.Front() ); + WORKSHEET_DATAITEM* dataItem = drawItem->GetPeer(); + WORKSHEET_LAYOUT::GetTheInstance().Remove( dataItem ); + + for( WS_DRAW_ITEM_BASE* item : dataItem->GetDrawItems() ) + { + // Note: repeat items won't be selected but must be removed & deleted + + if( item->IsSelected() ) + m_selectionTool->RemoveItemFromSel( item ); + + getView()->Remove( item ); + delete item; + } + + delete dataItem; + } + + m_frame->OnModify(); + + return 0; +} + + +static bool deleteItem( PL_EDITOR_FRAME* aFrame, const VECTOR2D& aPosition ) +{ + PL_SELECTION_TOOL* selectionTool = aFrame->GetToolManager()->GetTool(); + wxCHECK( selectionTool, false ); + + aFrame->GetToolManager()->RunAction( PL_ACTIONS::clearSelection, true ); + + EDA_ITEM* item = selectionTool->SelectPoint( aPosition ); + + if( item ) + aFrame->GetToolManager()->RunAction( PL_ACTIONS::doDelete, true ); + + return true; +} + + +int PL_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent ) +{ + Activate(); + + PL_PICKER_TOOL* picker = m_toolMgr->GetTool(); + wxCHECK( picker, 0 ); + + m_frame->SetToolID( ID_PL_DELETE_TOOL, wxCURSOR_BULLSEYE, _( "Delete item" ) ); + picker->SetClickHandler( std::bind( deleteItem, m_frame, std::placeholders::_1 ) ); + picker->Activate(); + Wait(); + + return 0; +} + + +int PL_EDIT_TOOL::Undo( const TOOL_EVENT& aEvent ) +{ + m_frame->GetLayoutFromUndoList(); + return 0; +} + + +int PL_EDIT_TOOL::Redo( const TOOL_EVENT& aEvent ) +{ + m_frame->GetLayoutFromRedoList(); + return 0; +} + + +void PL_EDIT_TOOL::setTransitions() +{ + Go( &PL_EDIT_TOOL::Main, PL_ACTIONS::move.MakeEvent() ); + + Go( &PL_EDIT_TOOL::DoDelete, PL_ACTIONS::doDelete.MakeEvent() ); + Go( &PL_EDIT_TOOL::DeleteItemCursor, PL_ACTIONS::deleteItemCursor.MakeEvent() ); + + Go( &PL_EDIT_TOOL::Undo, ACTIONS::undo.MakeEvent() ); + Go( &PL_EDIT_TOOL::Redo, ACTIONS::redo.MakeEvent() ); +} diff --git a/pagelayout_editor/tools/pl_edit_tool.h b/pagelayout_editor/tools/pl_edit_tool.h new file mode 100644 index 0000000000..5a9aaa27f6 --- /dev/null +++ b/pagelayout_editor/tools/pl_edit_tool.h @@ -0,0 +1,91 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 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 + */ + +#ifndef PL_EDIT_TOOL_H +#define PL_EDIT_TOOL_H + +#include +#include + + +class PL_EDITOR_FRAME; +class PL_SELECTION_TOOL; + + +class PL_EDIT_TOOL : public TOOL_INTERACTIVE +{ +public: + PL_EDIT_TOOL(); + ~PL_EDIT_TOOL() {} + + /// @copydoc TOOL_INTERACTIVE::Init() + bool Init() override; + + /// @copydoc TOOL_INTERACTIVE::Reset() + void Reset( RESET_REASON aReason ) override; + + /// The "move" event loop + int Main( const TOOL_EVENT& aEvent ); + + int Undo( const TOOL_EVENT& aEvent ); + int Redo( const TOOL_EVENT& aEvent ); + + /** + * Function DoDelete() + * + * Deletes the selected items, or the item under the cursor. + */ + int DoDelete( const TOOL_EVENT& aEvent ); + + ///> Runs the deletion tool. + int DeleteItemCursor( const TOOL_EVENT& aEvent ); + +private: + void moveItem( EDA_ITEM* aItem, VECTOR2I aDelta ); + + ///> Returns the right modification point (e.g. for rotation), depending on the number of + ///> selected items. + bool updateModificationPoint( SELECTION& aSelection ); + + ///> Sets up handlers for various events. + void setTransitions() override; + +private: + PL_EDITOR_FRAME* m_frame; + PL_SELECTION_TOOL* m_selectionTool; + + /// Menu model displayed by the tool. + TOOL_MENU m_menu; + + ///> Flag determining if anything is being dragged right now + bool m_moveInProgress; + + ///> Used for chaining commands + VECTOR2I m_moveOffset; + + ///> Last cursor position (needed for getModificationPoint() to avoid changes + ///> of edit reference point). + VECTOR2I m_cursor; +}; + +#endif //PL_EDIT_TOOL_H diff --git a/pagelayout_editor/tools/pl_picker_tool.cpp b/pagelayout_editor/tools/pl_picker_tool.cpp new file mode 100644 index 0000000000..5e7945df09 --- /dev/null +++ b/pagelayout_editor/tools/pl_picker_tool.cpp @@ -0,0 +1,186 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 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 + */ + +#include +#include +#include +#include +#include +#include + +TOOL_ACTION PL_ACTIONS::pickerTool( "plEditor.Picker", AS_GLOBAL, 0, "", "", NULL, AF_ACTIVATE ); + + +PL_PICKER_TOOL::PL_PICKER_TOOL() : + TOOL_INTERACTIVE( "plEditor.Picker" ), + m_frame( nullptr ), + m_menu( *this ), + m_cursorCapture( false ), + m_autoPanning( false ) +{ + resetPicker(); +} + + +bool PL_PICKER_TOOL::Init() +{ + m_frame = getEditFrame(); + + auto& ctxMenu = m_menu.GetMenu(); + + // cancel current tool goes in main context menu at the top if present + ctxMenu.AddItem( ACTIONS::cancelInteractive, SELECTION_CONDITIONS::ShowAlways, 1 ); + ctxMenu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1 ); + + // Finally, add the standard zoom/grid items + m_menu.AddStandardSubMenus( m_frame ); + + return true; +} + + +void PL_PICKER_TOOL::Reset( RESET_REASON aReason ) +{ + m_cursorCapture = false; + m_autoPanning = false; +} + + +int PL_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) +{ + KIGFX::VIEW_CONTROLS* controls = getViewControls(); + int finalize_state = WAIT_CANCEL; + + setControls(); + + while( OPT_TOOL_EVENT evt = Wait() ) + { + VECTOR2I cursorPos = controls->GetCursorPosition( !evt->Modifier( MD_ALT ) ); + + if( evt->IsClick( BUT_LEFT ) ) + { + bool getNext = false; + + m_picked = cursorPos; + + if( m_clickHandler ) + { + try + { + getNext = (*m_clickHandler)( *m_picked ); + } + catch( std::exception& e ) + { + std::cerr << "PL_PICKER_TOOL click handler error: " << e.what() << std::endl; + finalize_state = EXCEPTION_CANCEL; + break; + } + } + + if( !getNext ) + { + finalize_state = CLICK_CANCEL; + break; + } + else + setControls(); + } + + else if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) ) + { + if( m_cancelHandler ) + { + try + { + (*m_cancelHandler)(); + } + catch( std::exception& e ) + { + std::cerr << "PL_PICKER_TOOL cancel handler error: " << e.what() << std::endl; + } + } + + // Activating a new tool may have alternate finalization from canceling the current tool + if( evt->IsActivate() ) + finalize_state = END_ACTIVATE; + else + finalize_state = EVT_CANCEL; + + break; + } + else if( evt->IsClick( BUT_RIGHT ) ) + { + // TODO... + // m_menu.ShowContextMenu(); + } + else + { + m_toolMgr->PassEvent(); + } + } + + if( m_finalizeHandler ) + { + try + { + (*m_finalizeHandler)( finalize_state ); + } + catch( std::exception& e ) + { + std::cerr << "PL_PICKER_TOOL finalize handler error: " << e.what() << std::endl; + } + } + + resetPicker(); + controls->ForceCursorPosition( false ); + getEditFrame()->SetNoToolSelected(); + + return 0; +} + + +void PL_PICKER_TOOL::setTransitions() +{ + Go( &PL_PICKER_TOOL::Main, PL_ACTIONS::pickerTool.MakeEvent() ); +} + + +void PL_PICKER_TOOL::resetPicker() +{ + m_cursorCapture = false; + m_autoPanning = false; + + m_picked = NULLOPT; + m_clickHandler = NULLOPT; + m_cancelHandler = NULLOPT; + m_finalizeHandler = NULLOPT; +} + + +void PL_PICKER_TOOL::setControls() +{ + KIGFX::VIEW_CONTROLS* controls = getViewControls(); + + controls->CaptureCursor( m_cursorCapture ); + controls->SetAutoPan( m_autoPanning ); +} diff --git a/pagelayout_editor/tools/pl_picker_tool.h b/pagelayout_editor/tools/pl_picker_tool.h new file mode 100644 index 0000000000..4643d12810 --- /dev/null +++ b/pagelayout_editor/tools/pl_picker_tool.h @@ -0,0 +1,132 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 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 + */ + +#ifndef PL_PICKER_TOOL_H +#define PL_PICKER_TOOL_H + +#include +#include +#include + +class PL_EDITOR_FRAME; + + +class PL_PICKER_TOOL : public TOOL_INTERACTIVE +{ +public: + PL_PICKER_TOOL(); + ~PL_PICKER_TOOL() {} + + /// @copydoc TOOL_INTERACTIVE::Init() + bool Init() override; + + /// @copydoc TOOL_INTERACTIVE::Reset() + void Reset( RESET_REASON aReason ) override; + + ///> Event handler types. + typedef std::function CLICK_HANDLER; + typedef std::function CANCEL_HANDLER; + typedef std::function FINALIZE_HANDLER; + + enum pickerEndState + { + WAIT_CANCEL, + CLICK_CANCEL, + END_ACTIVATE, + EVT_CANCEL, + EXCEPTION_CANCEL + }; + + ///> Main event loop. + int Main( const TOOL_EVENT& aEvent ); + + /** + * Function SetAutoPanning() + * Sets autopanning mode for the period when the tool is active. + */ + inline void SetAutoPanning( bool aEnable ) { m_autoPanning = aEnable; } + + /** + * Function SetAutoPanning() + * Toggles cursor capture mode for the period when the tool is active. + */ + inline void SetCursorCapture( bool aEnable ) { m_cursorCapture = aEnable; } + + /** + * Function SetClickHandler() + * Sets a handler for mouse click event. Handler may decide to receive further click by + * returning true. + */ + inline void SetClickHandler( CLICK_HANDLER aHandler ) + { + assert( !m_clickHandler ); + m_clickHandler = aHandler; + } + + /** + * Function SetCancelHandler() + * Sets a handler for cancel events (ESC or context-menu Cancel). + */ + inline void SetCancelHandler( CANCEL_HANDLER aHandler ) + { + assert( !m_cancelHandler ); + m_cancelHandler = aHandler; + } + + /** + * Function SetFinalizeHandler() + * Sets a handler for the finalize event. Takes the state of the exit from the Main loop + */ + inline void SetFinalizeHandler( FINALIZE_HANDLER aHandler ) + { + assert( !m_finalizeHandler ); + m_finalizeHandler = aHandler; + } + +private: + ///> Reinitializes tool to its initial state. + void resetPicker(); + + ///> Applies the requested VIEW_CONTROLS settings. + void setControls(); + + ///> @copydoc TOOL_INTERACTIVE::setTransitions(); + void setTransitions() override; + +private: + PL_EDITOR_FRAME* m_frame; + + /// Menu model displayed by the tool. + TOOL_MENU m_menu; + + bool m_cursorCapture; + bool m_autoPanning; + + OPT m_clickHandler; + OPT m_cancelHandler; + OPT m_finalizeHandler; + + OPT m_picked; +}; + +#endif /* PL_PICKER_TOOL_H */ diff --git a/pagelayout_editor/tools/pl_point_editor.cpp b/pagelayout_editor/tools/pl_point_editor.cpp new file mode 100644 index 0000000000..7cf68f8c63 --- /dev/null +++ b/pagelayout_editor/tools/pl_point_editor.cpp @@ -0,0 +1,428 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 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 + */ + +#include +using namespace std::placeholders; + +#include "pl_point_editor.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + + +// Few constants to avoid using bare numbers for point indices +enum RECTANGLE_POINTS +{ + RECT_TOPLEFT, RECT_TOPRIGHT, RECT_BOTLEFT, RECT_BOTRIGHT +}; + +enum LINE_POINTS +{ + LINE_START, LINE_END +}; + +class EDIT_POINTS_FACTORY +{ +public: + static std::shared_ptr Make( EDA_ITEM* aItem ) + { + std::shared_ptr points = std::make_shared( aItem ); + + if( !aItem ) + return points; + + // Generate list of edit points based on the item type + switch( aItem->Type() ) + { + case WSG_LINE_T: + { + WS_DRAW_ITEM_LINE* line = (WS_DRAW_ITEM_LINE*) aItem; + points->AddPoint( line->GetStart() ); + points->AddPoint( line->GetEnd() ); + break; + } + case WSG_RECT_T: + { + WS_DRAW_ITEM_RECT* rect = (WS_DRAW_ITEM_RECT*) aItem; + wxPoint topLeft = rect->GetStart(); + wxPoint botRight = rect->GetEnd(); + + points->AddPoint( (VECTOR2I) topLeft ); + points->AddPoint( VECTOR2I( botRight.x, topLeft.y ) ); + points->AddPoint( VECTOR2I( topLeft.x, botRight.y ) ); + points->AddPoint( (VECTOR2I) botRight ); + break; + } + default: + points.reset(); + break; + } + + return points; + } + +private: + EDIT_POINTS_FACTORY() {}; +}; + + +PL_POINT_EDITOR::PL_POINT_EDITOR() : + TOOL_INTERACTIVE( "plEditor.PointEditor" ), + m_editedPoint( nullptr ) +{ +} + + +void PL_POINT_EDITOR::Reset( RESET_REASON aReason ) +{ + if( aReason == MODEL_RELOAD ) + { + // Init variables used by every drawing tool + m_frame = getEditFrame(); + } + + m_editPoints.reset(); +} + + +bool PL_POINT_EDITOR::Init() +{ + m_frame = getEditFrame(); + m_selectionTool = m_toolMgr->GetTool(); + return true; +} + + +void PL_POINT_EDITOR::updateEditedPoint( const TOOL_EVENT& aEvent ) +{ + EDIT_POINT* point = m_editedPoint; + + if( aEvent.IsMotion() ) + { + point = m_editPoints->FindPoint( aEvent.Position(), getView() ); + } + else if( aEvent.IsDrag( BUT_LEFT ) ) + { + point = m_editPoints->FindPoint( aEvent.DragOrigin(), getView() ); + } + + if( m_editedPoint != point ) + setEditedPoint( point ); +} + + +int PL_POINT_EDITOR::Main( const TOOL_EVENT& aEvent ) +{ + static KICAD_T pointTypes[] = { WSG_LINE_T, WSG_RECT_T, EOT }; + + if( !m_selectionTool ) + return 0; + + const SELECTION& selection = m_selectionTool->GetSelection(); + + if( selection.Size() != 1 || !selection.Front()->IsType( pointTypes ) ) + return 0; + + Activate(); + + KIGFX::VIEW_CONTROLS* controls = getViewControls(); + KIGFX::VIEW* view = getView(); + int savedToolID = m_frame->GetToolId(); + wxString savedToolMsg = m_frame->GetToolMsg(); + EDA_ITEM* item = (EDA_ITEM*) selection.Front(); + + controls->ShowCursor( true ); + + m_editPoints = EDIT_POINTS_FACTORY::Make( item ); + + if( !m_editPoints ) + return 0; + + view->Add( m_editPoints.get() ); + setEditedPoint( nullptr ); + bool inDrag = false; + bool modified = false; + + // Main loop: keep receiving events + while( OPT_TOOL_EVENT evt = Wait() ) + { + if( !m_editPoints + || evt->Matches( EVENTS::ClearedEvent ) + || evt->Matches( EVENTS::UnselectedEvent ) + || evt->Matches( EVENTS::SelectedEvent ) ) + { + break; + } + + if ( !inDrag ) + updateEditedPoint( *evt ); + + if( evt->IsDrag( BUT_LEFT ) && m_editedPoint ) + { + m_frame->SetToolID( ID_DRAG_POINT, -1, _( "Drag Point" ) ); + + if( !inDrag ) + { + m_frame->SaveCopyInUndoList(); + controls->ForceCursorPosition( false ); + inDrag = true; + modified = true; + } + + m_editedPoint->SetPosition( controls->GetCursorPosition( !evt->Modifier( MD_ALT ) ) ); + + updateItem(); + updatePoints(); + } + + else if( evt->IsMouseUp( BUT_LEFT ) ) + { + controls->SetAutoPan( false ); + m_frame->SetToolID( savedToolID, -1, savedToolMsg ); + + inDrag = false; + + m_toolMgr->PassEvent(); + } + + else if( evt->IsCancel() ) + { + if( inDrag ) // Restore the last change + { + m_frame->RollbackFromUndo(); + modified = false; + } + + m_frame->SetToolID( savedToolID, -1, savedToolMsg ); + break; + } + + else + { + m_toolMgr->PassEvent(); + } + + controls->SetAutoPan( inDrag ); + controls->CaptureCursor( inDrag ); + } + + controls->SetAutoPan( false ); + controls->CaptureCursor( false ); + m_frame->SetToolID( savedToolID, -1, savedToolMsg ); + + if( m_editPoints ) + { + view->Remove( m_editPoints.get() ); + + if( modified ) + m_frame->OnModify(); + + m_editPoints.reset(); + m_frame->GetCanvas()->Refresh(); + } + + return 0; +} + + +void pinEditedCorner( int editedPointIndex, int minWidth, int minHeight, VECTOR2I& topLeft, + VECTOR2I& topRight, VECTOR2I& botLeft, VECTOR2I& botRight ) +{ + switch( editedPointIndex ) + { + case RECT_TOPLEFT: + // pin edited point within opposite corner + topLeft.x = std::min( topLeft.x, botRight.x - minWidth ); + topLeft.y = std::min( topLeft.y, botRight.y - minHeight ); + + // push edited point edges to adjacent corners + topRight.y = topLeft.y; + botLeft.x = topLeft.x; + + break; + + case RECT_TOPRIGHT: + // pin edited point within opposite corner + topRight.x = std::max( topRight.x, botLeft.x + minWidth ); + topRight.y = std::min( topRight.y, botLeft.y - minHeight ); + + // push edited point edges to adjacent corners + topLeft.y = topRight.y; + botRight.x = topRight.x; + + break; + + case RECT_BOTLEFT: + // pin edited point within opposite corner + botLeft.x = std::min( botLeft.x, topRight.x - minWidth ); + botLeft.y = std::max( botLeft.y, topRight.y + minHeight ); + + // push edited point edges to adjacent corners + botRight.y = botLeft.y; + topLeft.x = botLeft.x; + + break; + + case RECT_BOTRIGHT: + // pin edited point within opposite corner + botRight.x = std::max( botRight.x, topLeft.x + minWidth ); + botRight.y = std::max( botRight.y, topLeft.y + minHeight ); + + // push edited point edges to adjacent corners + botLeft.y = botRight.y; + topRight.x = botRight.x; + + break; + } +} + + +void PL_POINT_EDITOR::updateItem() const +{ + EDA_ITEM* item = m_editPoints->GetParent(); + + if( !item ) + return; + + switch( item->Type() ) + { + case WSG_LINE_T: + { + WS_DRAW_ITEM_LINE* line = (WS_DRAW_ITEM_LINE*) item; + + line->SetStart( (wxPoint) m_editPoints->Point( LINE_START ).GetPosition() ); + line->SetEnd( (wxPoint) m_editPoints->Point( LINE_END ).GetPosition() ); + break; + } + + case WSG_RECT_T: + { + WS_DRAW_ITEM_RECT* rect = (WS_DRAW_ITEM_RECT*) item; + VECTOR2I topLeft = m_editPoints->Point( RECT_TOPLEFT ).GetPosition(); + VECTOR2I topRight = m_editPoints->Point( RECT_TOPRIGHT ).GetPosition(); + VECTOR2I botLeft = m_editPoints->Point( RECT_BOTLEFT ).GetPosition(); + VECTOR2I botRight = m_editPoints->Point( RECT_BOTRIGHT ).GetPosition(); + + pinEditedCorner( getEditedPointIndex(), Mils2iu( 1 ), Mils2iu( 1 ), + topLeft, topRight, botLeft, botRight ); + + rect->SetStart( (wxPoint) topLeft ); + rect->SetEnd( (wxPoint) botRight ); + break; + } + + default: + break; + } + + getView()->Update( item ); + m_frame->SetMsgPanel( item ); +} + + +void PL_POINT_EDITOR::updatePoints() +{ + if( !m_editPoints ) + return; + + EDA_ITEM* item = m_editPoints->GetParent(); + + if( !item ) + return; + + switch( item->Type() ) + { + case WSG_LINE_T: + { + WS_DRAW_ITEM_LINE* line = (WS_DRAW_ITEM_LINE*) item; + + m_editPoints->Point( LINE_START ).SetPosition( line->GetStart() ); + m_editPoints->Point( LINE_END ).SetPosition( line->GetEnd() ); + break; + } + + case WSG_RECT_T: + { + WS_DRAW_ITEM_RECT* rect = (WS_DRAW_ITEM_RECT*) item; + wxPoint topLeft = rect->GetPosition(); + wxPoint botRight = rect->GetEnd(); + + m_editPoints->Point( RECT_TOPLEFT ).SetPosition( (VECTOR2I) topLeft ); + m_editPoints->Point( RECT_TOPRIGHT ).SetPosition( VECTOR2I( botRight.x, topLeft.y ) ); + m_editPoints->Point( RECT_BOTLEFT ).SetPosition( VECTOR2I( topLeft.x, botRight.y ) ); + m_editPoints->Point( RECT_BOTRIGHT ).SetPosition( (VECTOR2I) botRight ); + break; + } + + default: + break; + } + + getView()->Update( m_editPoints.get() ); +} + + +void PL_POINT_EDITOR::setEditedPoint( EDIT_POINT* aPoint ) +{ + KIGFX::VIEW_CONTROLS* controls = getViewControls(); + + if( aPoint ) + { + controls->ForceCursorPosition( true, aPoint->GetPosition() ); + controls->ShowCursor( true ); + } + else + { + controls->ShowCursor( false ); + controls->ForceCursorPosition( false ); + } + + m_editedPoint = aPoint; +} + + +int PL_POINT_EDITOR::modifiedSelection( const TOOL_EVENT& aEvent ) +{ + updatePoints(); + return 0; +} + + +void PL_POINT_EDITOR::setTransitions() +{ + Go( &PL_POINT_EDITOR::Main, EVENTS::SelectedEvent ); + Go( &PL_POINT_EDITOR::modifiedSelection, EVENTS::SelectedItemsModified ); +} + + diff --git a/pagelayout_editor/tools/pl_point_editor.h b/pagelayout_editor/tools/pl_point_editor.h new file mode 100644 index 0000000000..c84a58c1e0 --- /dev/null +++ b/pagelayout_editor/tools/pl_point_editor.h @@ -0,0 +1,99 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 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 + */ + +#ifndef PL_POINT_EDITOR_H +#define PL_POINT_EDITOR_H + +#include +#include +#include +#include + +class PL_SELECTION_TOOL; +class PL_EDITOR_FRAME; + +/** + * Class PL_POINT_EDITOR + * + * Tool that displays edit points allowing to modify items by dragging the points. + */ +class PL_POINT_EDITOR : public TOOL_INTERACTIVE +{ +public: + PL_POINT_EDITOR(); + + /// @copydoc TOOL_INTERACTIVE::Reset() + void Reset( RESET_REASON aReason ) override; + + /// @copydoc TOOL_INTERACTIVE::Init() + bool Init() override; + + int Main( const TOOL_EVENT& aEvent ); + + ///> Sets up handlers for various events. + void setTransitions() override; + +private: + ///> Updates item's points with edit points. + void updateItem() const; + + ///> Updates edit points with item's points. + void updatePoints(); + + ///> Updates which point is being edited. + void updateEditedPoint( const TOOL_EVENT& aEvent ); + + ///> Sets the current point being edited. NULL means none. + void setEditedPoint( EDIT_POINT* aPoint ); + + ///> Returns true if aPoint is the currently modified point. + inline bool isModified( const EDIT_POINT& aPoint ) const + { + return m_editedPoint == &aPoint; + } + + inline int getEditedPointIndex() const + { + for( unsigned i = 0; i < m_editPoints->PointsSize(); ++i ) + { + if( m_editedPoint == &m_editPoints->Point( i ) ) + return i; + } + + return wxNOT_FOUND; + } + + int modifiedSelection( const TOOL_EVENT& aEvent ); + +private: + PL_EDITOR_FRAME* m_frame; + PL_SELECTION_TOOL* m_selectionTool; + + ///> Currently edited point, NULL if there is none. + EDIT_POINT* m_editedPoint; + + ///> Currently available edit points. + std::shared_ptr m_editPoints; +}; + +#endif // PL_POINT_EDITOR_H diff --git a/pagelayout_editor/tools/pl_selection_tool.cpp b/pagelayout_editor/tools/pl_selection_tool.cpp new file mode 100644 index 0000000000..1543473c1a --- /dev/null +++ b/pagelayout_editor/tools/pl_selection_tool.cpp @@ -0,0 +1,757 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 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 + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pl_selection_tool.h" + +/** + * The maximum number of items in the clarify selection context menu. The current + * setting of 40 is arbitrary. + */ +#define MAX_SELECT_ITEM_IDS 40 + + +// Selection tool actions +TOOL_ACTION PL_ACTIONS::selectionActivate( "plEditor.InteractiveSelection", + AS_GLOBAL, 0, "", "", // No description, not shown anywhere + nullptr, AF_ACTIVATE ); + +TOOL_ACTION PL_ACTIONS::selectionTool( "plEditor.InteractiveSelection.selectionTool", + AS_GLOBAL, 0, _( "Select item(s)" ), "", + cursor_xpm, AF_ACTIVATE ); + +TOOL_ACTION PL_ACTIONS::selectionMenu( "plEditor.InteractiveSelection.SelectionMenu", + AS_GLOBAL, 0, "", "" ); // No description, it is not supposed to be shown anywhere + +TOOL_ACTION PL_ACTIONS::addItemToSel( "plEditor.InteractiveSelection.AddItemToSel", + AS_GLOBAL, 0, "", "" ); // No description, it is not supposed to be shown anywhere + +TOOL_ACTION PL_ACTIONS::addItemsToSel( "plEditor.InteractiveSelection.AddItemsToSel", + AS_GLOBAL, 0, "", "" ); // No description, it is not supposed to be shown anywhere + +TOOL_ACTION PL_ACTIONS::removeItemFromSel( "plEditor.InteractiveSelection.RemoveItemFromSel", + AS_GLOBAL, 0, "", "" ); // No description, it is not supposed to be shown anywhere + +TOOL_ACTION PL_ACTIONS::removeItemsFromSel( "plEditor.InteractiveSelection.RemoveItemsFromSel", + AS_GLOBAL, 0, "", "" ); // No description, it is not supposed to be shown anywhere + +TOOL_ACTION PL_ACTIONS::clearSelection( "plEditor.InteractiveSelection.ClearSelection", + AS_GLOBAL, 0, "", "" ); // No description, it is not supposed to be shown anywhere + + +SELECTION_CONDITION PL_CONDITIONS::Idle = [] (const SELECTION& aSelection ) +{ + return ( !aSelection.Front() || aSelection.Front()->GetEditFlags() == 0 ); +}; + + +#define HITTEST_THRESHOLD_PIXELS 5 + + +PL_SELECTION_TOOL::PL_SELECTION_TOOL() : + TOOL_INTERACTIVE( "plEditor.InteractiveSelection" ), + m_frame( nullptr ), + m_additive( false ), + m_subtractive( false ), + m_multiple( false ), + m_skip_heuristics( false ), + m_menu( *this ) +{ +} + + +bool PL_SELECTION_TOOL::Init() +{ + m_frame = getEditFrame(); + + auto& menu = m_menu.GetMenu(); + + menu.AddSeparator( PL_CONDITIONS::Idle, 200 ); + menu.AddItem( PL_ACTIONS::addLine, PL_CONDITIONS::Idle, 250 ); + menu.AddItem( PL_ACTIONS::addRectangle, PL_CONDITIONS::Idle, 250 ); + menu.AddItem( PL_ACTIONS::addText, PL_CONDITIONS::Idle, 250 ); + menu.AddItem( PL_ACTIONS::addImage, PL_CONDITIONS::Idle, 250 ); + menu.AddItem( PL_ACTIONS::appendImportedWorksheet, PL_CONDITIONS::Idle, 250 ); + + menu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1000 ); + m_menu.AddStandardSubMenus( m_frame ); + + return true; +} + + +void PL_SELECTION_TOOL::Reset( RESET_REASON aReason ) +{ + if( aReason == MODEL_RELOAD ) + m_frame = getEditFrame(); +} + + +int PL_SELECTION_TOOL::UpdateMenu( const TOOL_EVENT& aEvent ) +{ + ACTION_MENU* actionMenu = aEvent.Parameter(); + CONDITIONAL_MENU* conditionalMenu = dynamic_cast( actionMenu ); + + if( conditionalMenu ) + conditionalMenu->Evaluate( m_selection ); + + if( actionMenu ) + actionMenu->UpdateAll(); + + return 0; +} + + +int PL_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) +{ + // Main loop: keep receiving events + while( OPT_TOOL_EVENT evt = Wait() ) + { + // Should selected items be added to the current selection or + // become the new selection (discarding previously selected items) + m_additive = evt->Modifier( MD_SHIFT ); + + // Should selected items be REMOVED from the current selection? + // This will be ignored if the SHIFT modifier is pressed + m_subtractive = !m_additive && evt->Modifier( MD_CTRL ); + + // Is the user requesting that the selection list include all possible + // items without removing less likely selection candidates + m_skip_heuristics = !!evt->Modifier( MD_ALT ); + + // Single click? Select single object + if( evt->IsClick( BUT_LEFT ) ) + { + // If no modifier keys are pressed, clear the selection + if( !m_additive ) + ClearSelection(); + + SelectPoint( evt->Position()); + } + + // right click? if there is any object - show the context menu + else if( evt->IsClick( BUT_RIGHT ) ) + { + bool selectionCancelled = false; + + if( m_selection.Empty() ) + { + SelectPoint( evt->Position(), &selectionCancelled ); + m_selection.SetIsHover( true ); + } + + if( !selectionCancelled ) + m_menu.ShowContextMenu( m_selection ); + } + + // double click? Display the properties window + else if( evt->IsDblClick( BUT_LEFT ) ) + { + // No double-click actions currently defined + } + + // drag with LMB? Select multiple objects (or at least draw a selection box) or drag them + else if( evt->IsDrag( BUT_LEFT ) ) + { + if( m_additive || m_subtractive || m_selection.Empty() ) + { + selectMultiple(); + } + else + { + // Check if dragging has started within any of selected items bounding box + if( selectionContains( evt->Position() ) ) + { + // Yes -> run the move tool and wait till it finishes + m_toolMgr->InvokeTool( "plEditor.InteractiveEdit" ); + } + else + { + // No -> clear the selection list + ClearSelection(); + } + } + } + + else if( evt->IsAction( &ACTIONS::cancelInteractive ) || evt->IsCancel() ) + { + ClearSelection(); + } + + else if( evt->Action() == TA_UNDO_REDO_PRE ) + { + ClearSelection(); + } + + else if( evt->Action() == TA_CONTEXT_MENU_CLOSED ) + { + m_menu.CloseContextMenu( evt ); + } + } + + // This tool is supposed to be active forever + assert( false ); + + return 0; +} + + +SELECTION& PL_SELECTION_TOOL::GetSelection() +{ + return m_selection; +} + + +EDA_ITEM* PL_SELECTION_TOOL::SelectPoint( const VECTOR2I& aWhere, bool* aSelectionCancelledFlag ) +{ + int threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) ); + + // locate items. + COLLECTOR collector; + + for( WORKSHEET_DATAITEM* dataItem : WORKSHEET_LAYOUT::GetTheInstance().GetItems() ) + { + for( WS_DRAW_ITEM_BASE* drawItem : dataItem->GetDrawItems() ) + { + if( drawItem->HitTest( (wxPoint) aWhere, threshold ) ) + collector.Append( drawItem ); + } + } + + bool anyCollected = collector.GetCount() != 0; + + m_selection.ClearReferencePoint(); + + // Apply some ugly heuristics to avoid disambiguation menus whenever possible + if( collector.GetCount() > 1 && !m_skip_heuristics ) + { + guessSelectionCandidates( collector, aWhere ); + } + + // If still more than one item we're going to have to ask the user. + if( collector.GetCount() > 1 ) + { + collector.m_MenuTitle = _( "Clarify Selection" ); + + // Must call selectionMenu via RunAction() to avoid event-loop contention + m_toolMgr->RunAction( PL_ACTIONS::selectionMenu, true, &collector ); + + if( collector.m_MenuCancelled ) + { + if( aSelectionCancelledFlag ) + *aSelectionCancelledFlag = true; + + return nullptr; + } + } + + if( collector.GetCount() == 1 ) + { + EDA_ITEM* item = collector[ 0 ]; + + toggleSelection( item ); + return item; + } + + if( !m_additive && anyCollected ) + ClearSelection(); + + return nullptr; +} + + +void PL_SELECTION_TOOL::guessSelectionCandidates( COLLECTOR& collector, const VECTOR2I& aPos ) +{ + // There are certain conditions that can be handled automatically. + + // Prefer an exact hit to a sloppy one + for( int i = 0; collector.GetCount() == 2 && i < 2; ++i ) + { + EDA_ITEM* item = collector[ i ]; + EDA_ITEM* other = collector[ ( i + 1 ) % 2 ]; + + if( item->HitTest( (wxPoint) aPos, 0 ) && !other->HitTest( (wxPoint) aPos, 0 ) ) + collector.Remove( other ); + } +} + + +SELECTION& PL_SELECTION_TOOL::RequestSelection() +{ + // If nothing is selected do a hover selection + if( m_selection.Empty() ) + { + VECTOR2D cursorPos = getViewControls()->GetCursorPosition( true ); + + ClearSelection(); + SelectPoint( cursorPos ); + m_selection.SetIsHover( true ); + } + + return m_selection; +} + + +bool PL_SELECTION_TOOL::selectMultiple() +{ + bool cancelled = false; // Was the tool cancelled while it was running? + m_multiple = true; // Multiple selection mode is active + KIGFX::VIEW* view = getView(); + + KIGFX::PREVIEW::SELECTION_AREA area; + view->Add( &area ); + + while( OPT_TOOL_EVENT evt = Wait() ) + { + if( evt->IsAction( &ACTIONS::cancelInteractive ) || evt->IsActivate() || evt->IsCancel() ) + { + cancelled = true; + break; + } + + if( evt->IsDrag( BUT_LEFT ) ) + { + // Start drawing a selection box + area.SetOrigin( evt->DragOrigin() ); + area.SetEnd( evt->Position() ); + area.SetAdditive( m_additive ); + area.SetSubtractive( m_subtractive ); + + view->SetVisible( &area, true ); + view->Update( &area ); + getViewControls()->SetAutoPan( true ); + } + + if( evt->IsMouseUp( BUT_LEFT ) ) + { + getViewControls()->SetAutoPan( false ); + + // End drawing the selection box + view->SetVisible( &area, false ); + + int width = area.GetEnd().x - area.GetOrigin().x; + int height = area.GetEnd().y - area.GetOrigin().y; + + /* Selection mode depends on direction of drag-selection: + * Left > Right : Select objects that are fully enclosed by selection + * Right > Left : Select objects that are crossed by selection + */ + bool windowSelection = width >= 0 ? true : false; + + // Construct an EDA_RECT to determine EDA_ITEM selection + EDA_RECT selectionRect( (wxPoint)area.GetOrigin(), wxSize( width, height ) ); + + selectionRect.Normalize(); + + for( WORKSHEET_DATAITEM* dataItem : WORKSHEET_LAYOUT::GetTheInstance().GetItems() ) + { + for( WS_DRAW_ITEM_BASE* item : dataItem->GetDrawItems() ) + { + if( item->HitTest( selectionRect, windowSelection ) ) + { + if( m_subtractive ) + unselect( item ); + else + select( item ); + } + } + } + + // Inform other potentially interested tools + if( !m_selection.Empty() ) + m_toolMgr->ProcessEvent( EVENTS::SelectedEvent ); + + break; // Stop waiting for events + } + } + + getViewControls()->SetAutoPan( false ); + + // Stop drawing the selection box + view->Remove( &area ); + m_multiple = false; // Multiple selection mode is inactive + + if( !cancelled ) + m_selection.ClearReferencePoint(); + + return cancelled; +} + + +int PL_SELECTION_TOOL::AddItemToSel( const TOOL_EVENT& aEvent ) +{ + AddItemToSel( aEvent.Parameter() ); + return 0; +} + + +void PL_SELECTION_TOOL::AddItemToSel( EDA_ITEM* aItem, bool aQuietMode ) +{ + if( aItem ) + { + select( aItem ); + + // Inform other potentially interested tools + if( !aQuietMode ) + m_toolMgr->ProcessEvent( EVENTS::SelectedEvent ); + } +} + + +int PL_SELECTION_TOOL::AddItemsToSel( const TOOL_EVENT& aEvent ) +{ + AddItemsToSel( aEvent.Parameter(), false ); + return 0; +} + + +void PL_SELECTION_TOOL::AddItemsToSel( EDA_ITEMS* aList, bool aQuietMode ) +{ + if( aList ) + { + for( EDA_ITEM* item : *aList ) + select( item ); + + // Inform other potentially interested tools + if( !aQuietMode ) + m_toolMgr->ProcessEvent( EVENTS::SelectedEvent ); + } +} + + +int PL_SELECTION_TOOL::RemoveItemFromSel( const TOOL_EVENT& aEvent ) +{ + RemoveItemFromSel( aEvent.Parameter() ); + return 0; +} + + +void PL_SELECTION_TOOL::RemoveItemFromSel( EDA_ITEM* aItem, bool aQuietMode ) +{ + if( aItem ) + { + unselect( aItem ); + + // Inform other potentially interested tools + if( !aQuietMode ) + m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent ); + } +} + + +int PL_SELECTION_TOOL::RemoveItemsFromSel( const TOOL_EVENT& aEvent ) +{ + RemoveItemsFromSel( aEvent.Parameter(), false ); + return 0; +} + + +void PL_SELECTION_TOOL::RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode ) +{ + if( aList ) + { + for( EDA_ITEM* item : *aList ) + unselect( item ); + + // Inform other potentially interested tools + if( !aQuietMode ) + m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent ); + } +} + + +int PL_SELECTION_TOOL::ClearSelection( const TOOL_EVENT& aEvent ) +{ + ClearSelection(); + + return 0; +} + + +int PL_SELECTION_TOOL::SelectionMenu( const TOOL_EVENT& aEvent ) +{ + COLLECTOR* collector = aEvent.Parameter(); + + if( !doSelectionMenu( collector ) ) + collector->m_MenuCancelled = true; + + return 0; +} + + +bool PL_SELECTION_TOOL::doSelectionMenu( COLLECTOR* aCollector ) +{ + EDA_ITEM* current = nullptr; + ACTION_MENU menu; + + int limit = std::min( MAX_SELECT_ITEM_IDS, aCollector->GetCount() ); + + for( int i = 0; i < limit; ++i ) + { + wxString text; + EDA_ITEM* item = ( *aCollector )[i]; + text = item->GetSelectMenuText( m_frame->GetUserUnits() ); + + wxString menuText = wxString::Format("&%d. %s", i + 1, text ); + menu.Add( menuText, i + 1, item->GetMenuImage() ); + } + + if( aCollector->m_MenuTitle.Length() ) + menu.SetTitle( aCollector->m_MenuTitle ); + + menu.SetIcon( info_xpm ); + menu.DisplayTitle( true ); + SetContextMenu( &menu, CMENU_NOW ); + + while( OPT_TOOL_EVENT evt = Wait() ) + { + if( evt->Action() == TA_CONTEXT_MENU_UPDATE ) + { + if( current ) + unhighlight( current, BRIGHTENED ); + + int id = *evt->GetCommandId(); + + // User has pointed an item, so show it in a different way + if( id > 0 && id <= limit ) + { + current = ( *aCollector )[id - 1]; + highlight( current, BRIGHTENED ); + } + else + { + current = NULL; + } + } + else if( evt->Action() == TA_CONTEXT_MENU_CHOICE ) + { + if( current ) + unhighlight( current, BRIGHTENED ); + + OPT id = evt->GetCommandId(); + + // User has selected an item, so this one will be returned + if( id && ( *id > 0 ) ) + current = ( *aCollector )[*id - 1]; + else + current = NULL; + + break; + } + + getView()->UpdateItems(); + m_frame->GetCanvas()->Refresh(); + } + + if( current ) + { + unhighlight( current, BRIGHTENED ); + + getView()->UpdateItems(); + m_frame->GetCanvas()->Refresh(); + + aCollector->Empty(); + aCollector->Append( current ); + return true; + } + + return false; +} + + +void PL_SELECTION_TOOL::ClearSelection() +{ + if( m_selection.Empty() ) + return; + + while( m_selection.GetSize() ) + unhighlight( (EDA_ITEM*) m_selection.Front(), SELECTED, &m_selection ); + + getView()->Update( &m_selection ); + + m_selection.SetIsHover( false ); + m_selection.ClearReferencePoint(); + + // Inform other potentially interested tools + m_toolMgr->ProcessEvent( EVENTS::ClearedEvent ); +} + + +void PL_SELECTION_TOOL::toggleSelection( EDA_ITEM* aItem ) +{ + if( aItem->IsSelected() ) + { + unselect( aItem ); + + // Inform other potentially interested tools + m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent ); + } + else + { + if( !m_additive ) + ClearSelection(); + + select( aItem ); + + // Inform other potentially interested tools + m_toolMgr->ProcessEvent( EVENTS::SelectedEvent ); + } + + if( m_frame ) + m_frame->GetGalCanvas()->ForceRefresh(); +} + + +void PL_SELECTION_TOOL::select( EDA_ITEM* aItem ) +{ + highlight( aItem, SELECTED, &m_selection ); +} + + +void PL_SELECTION_TOOL::unselect( EDA_ITEM* aItem ) +{ + unhighlight( aItem, SELECTED, &m_selection ); +} + + +void PL_SELECTION_TOOL::highlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup ) +{ + if( aMode == SELECTED ) + aItem->SetSelected(); + else if( aMode == BRIGHTENED ) + aItem->SetBrightened(); + + if( aGroup ) + aGroup->Add( aItem ); + + getView()->Update( aItem ); +} + + +void PL_SELECTION_TOOL::unhighlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup ) +{ + if( aMode == SELECTED ) + aItem->ClearSelected(); + else if( aMode == BRIGHTENED ) + aItem->ClearBrightened(); + + if( aGroup ) + aGroup->Remove( aItem ); + + getView()->Update( aItem ); +} + + +bool PL_SELECTION_TOOL::selectionContains( const VECTOR2I& aPoint ) const +{ + const unsigned GRIP_MARGIN = 20; + VECTOR2I margin = getView()->ToWorld( VECTOR2I( GRIP_MARGIN, GRIP_MARGIN ), false ); + + // Check if the point is located within any of the currently selected items bounding boxes + for( auto item : m_selection ) + { + BOX2I itemBox = item->ViewBBox(); + itemBox.Inflate( margin.x, margin.y ); // Give some margin for gripping an item + + if( itemBox.Contains( aPoint ) ) + return true; + } + + return false; +} + + +int PL_SELECTION_TOOL::UpdateMessagePanel( const TOOL_EVENT& aEvent ) +{ + PL_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); + SELECTION& selection = selTool->GetSelection(); + + if( selection.GetSize() == 1 ) + { + EDA_ITEM* item = (EDA_ITEM*) selection.Front(); + + MSG_PANEL_ITEMS msgItems; + item->GetMsgPanelInfo( m_frame->GetUserUnits(), msgItems ); + m_frame->SetMsgPanel( msgItems ); + + WORKSHEET_DATAITEM* dataItem = static_cast( item )->GetPeer(); + m_frame->GetPropertiesFrame()->CopyPrmsFromItemToPanel( dataItem ); + } + else + { + m_frame->ClearMsgPanel(); + + m_frame->GetPropertiesFrame()->CopyPrmsFromGeneralToPanel(); + } + + return 0; +} + + +int PL_SELECTION_TOOL::ToggleBackgroundColor( const TOOL_EVENT& aEvent ) +{ + m_frame->SetDrawBgColor( m_frame->GetDrawBgColor() == WHITE ? BLACK : WHITE ); + m_frame->GetCanvas()->Refresh(); + + return 0; +} + + +void PL_SELECTION_TOOL::setTransitions() +{ + Go( &PL_SELECTION_TOOL::UpdateMenu, ACTIONS::updateMenu.MakeEvent() ); + + Go( &PL_SELECTION_TOOL::Main, PL_ACTIONS::selectionActivate.MakeEvent() ); + Go( &PL_SELECTION_TOOL::ClearSelection, PL_ACTIONS::clearSelection.MakeEvent() ); + + Go( &PL_SELECTION_TOOL::AddItemToSel, PL_ACTIONS::addItemToSel.MakeEvent() ); + Go( &PL_SELECTION_TOOL::AddItemsToSel, PL_ACTIONS::addItemsToSel.MakeEvent() ); + Go( &PL_SELECTION_TOOL::RemoveItemFromSel, PL_ACTIONS::removeItemFromSel.MakeEvent() ); + Go( &PL_SELECTION_TOOL::RemoveItemsFromSel, PL_ACTIONS::removeItemsFromSel.MakeEvent() ); + Go( &PL_SELECTION_TOOL::SelectionMenu, PL_ACTIONS::selectionMenu.MakeEvent() ); + + Go( &PL_SELECTION_TOOL::UpdateMessagePanel, EVENTS::SelectedEvent ); + Go( &PL_SELECTION_TOOL::UpdateMessagePanel, EVENTS::UnselectedEvent ); + Go( &PL_SELECTION_TOOL::UpdateMessagePanel, EVENTS::ClearedEvent ); + Go( &PL_SELECTION_TOOL::UpdateMessagePanel, EVENTS::SelectedItemsModified ); + + Go( &PL_SELECTION_TOOL::ToggleBackgroundColor, PL_ACTIONS::toggleBackground.MakeEvent() ); +} + + diff --git a/pagelayout_editor/tools/pl_selection_tool.h b/pagelayout_editor/tools/pl_selection_tool.h new file mode 100644 index 0000000000..da9715a881 --- /dev/null +++ b/pagelayout_editor/tools/pl_selection_tool.h @@ -0,0 +1,216 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 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 + */ + +#ifndef PL_SELECTION_TOOL_H +#define PL_SELECTION_TOOL_H + +#include +#include +#include +#include + +class PL_EDITOR_FRAME; +class SCH_ITEM; +class COLLECTOR; + +namespace KIGFX +{ + class GAL; +} + + +class PL_CONDITIONS : public SELECTION_CONDITIONS +{ +public: + static SELECTION_CONDITION Idle; +}; + + +class PL_SELECTION_TOOL : public TOOL_INTERACTIVE +{ +public: + PL_SELECTION_TOOL(); + ~PL_SELECTION_TOOL() { } + + /// @copydoc TOOL_BASE::Init() + bool Init() override; + + /// @copydoc TOOL_INTERACTIVE::Reset() + void Reset( RESET_REASON aReason ) override; + + int UpdateMenu( const TOOL_EVENT& aEvent ); + + /** + * Function Main() + * + * The main loop. + */ + int Main( const TOOL_EVENT& aEvent ); + + /** + * Function GetSelection() + * + * Returns the set of currently selected items. + */ + SELECTION& GetSelection(); + + inline TOOL_MENU& GetToolMenu() { return m_menu; } + + /** + * Function RequestSelection() + * + * Returns either an existing selection (filtered), or the selection at the current + * cursor if the existing selection is empty. + */ + SELECTION& RequestSelection(); + + /** + * Function selectPoint() + * Selects an item pointed by the parameter aWhere. If there is more than one item at that + * place, there is a menu displayed that allows one to choose the item. + * + * @param aWhere is the place where the item should be selected. + * @param aSelectionCancelledFlag allows the function to inform its caller that a selection + * was cancelled (for instance, by clicking outside of the disambiguation menu). + */ + EDA_ITEM* SelectPoint( const VECTOR2I& aWhere, bool* aSelectionCancelledFlag = nullptr ); + + int AddItemToSel( const TOOL_EVENT& aEvent ); + void AddItemToSel( EDA_ITEM* aItem, bool aQuietMode = false ); + int AddItemsToSel( const TOOL_EVENT& aEvent ); + void AddItemsToSel( EDA_ITEMS* aList, bool aQuietMode = false ); + + int RemoveItemFromSel( const TOOL_EVENT& aEvent ); + void RemoveItemFromSel( EDA_ITEM* aItem, bool aQuietMode = false ); + int RemoveItemsFromSel( const TOOL_EVENT& aEvent ); + void RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode = false ); + + ///> Clear current selection event handler. + int ClearSelection( const TOOL_EVENT& aEvent ); + + void ClearSelection(); + + /** + * Function SelectionMenu() + * Shows a popup menu to trim the COLLECTOR passed as aEvent's parameter down to a single + * item. + * + * NOTE: this routine DOES NOT modify the selection. + */ + int SelectionMenu( const TOOL_EVENT& aEvent ); + + int UpdateMessagePanel( const TOOL_EVENT& aEvent ); + + // Move to PL_EDITOR_CONTROL when there are enough control actions to make it worthwhile + int ToggleBackgroundColor( const TOOL_EVENT& aEvent ); + +private: + /** + * Function selectMultiple() + * Handles drawing a selection box that allows one to select many items at + * the same time. + * + * @return true if the function was cancelled (i.e. CancelEvent was received). + */ + bool selectMultiple(); + + /** + * Apply heuristics to try and determine a single object when multiple are found under the + * cursor. + */ + void guessSelectionCandidates( COLLECTOR& collector, const VECTOR2I& aWhere ); + + /** + * Allows the selection of a single item from a list via pop-up menu. The items are + * highlighted on the canvas when hovered in the menu. The collector is trimmed to + * the picked item. + * @return true if an item was picked + */ + bool doSelectionMenu( COLLECTOR* aItems ); + + /** + * Function toggleSelection() + * Changes selection status of a given item. + * + * @param aItem is the item to have selection status changed. + */ + void toggleSelection( EDA_ITEM* aItem ); + + /** + * Function select() + * Takes necessary action mark an item as selected. + * + * @param aItem is an item to be selected. + */ + void select( EDA_ITEM* aItem ); + + /** + * Function unselect() + * Takes necessary action mark an item as unselected. + * + * @param aItem is an item to be unselected. + */ + void unselect( EDA_ITEM* aItem ); + + /** + * Function highlight() + * Highlights the item visually. + * @param aItem is an item to be be highlighted. + * @param aHighlightMode should be either SELECTED or BRIGHTENED + * @param aGroup is the group to add the item to in the BRIGHTENED mode. + */ + void highlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ); + + /** + * Function unhighlight() + * Unhighlights the item visually. + * @param aItem is an item to be be highlighted. + * @param aHighlightMode should be either SELECTED or BRIGHTENED + * @param aGroup is the group to remove the item from. + */ + void unhighlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ); + + /** + * Function selectionContains() + * Checks if the given point is placed within any of selected items' bounding box. + * + * @return True if the given point is contained in any of selected items' bouding box. + */ + bool selectionContains( const VECTOR2I& aPoint ) const; + + ///> Sets up handlers for various events. + void setTransitions() override; + +private: + PL_EDITOR_FRAME* m_frame; // Pointer to the parent frame + SELECTION m_selection; // Current state of selection + + bool m_additive; // Items should be added to selection (instead of replacing) + bool m_subtractive; // Items should be removed from selection + bool m_multiple; // Multiple selection mode is active + bool m_skip_heuristics; // Heuristics are not allowed when choosing item under cursor + + TOOL_MENU m_menu; +}; + +#endif //PL_SELECTION_TOOL_H diff --git a/pagelayout_editor/tools/selection.cpp b/pagelayout_editor/tools/selection.cpp new file mode 100644 index 0000000000..747578c1bf --- /dev/null +++ b/pagelayout_editor/tools/selection.cpp @@ -0,0 +1,106 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2019 KiCad Developers, see CHANGELOG.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 + */ + +#include + +#include +#include +#include + +VECTOR2I SELECTION::GetPosition() const +{ + return static_cast( GetBoundingBox().GetPosition() ); +} + + +VECTOR2I SELECTION::GetCenter() const +{ + return static_cast( GetBoundingBox().Centre() ); +} + + +EDA_RECT SELECTION::GetBoundingBox() const +{ + EDA_RECT bbox; + + bbox = Front()->GetBoundingBox(); + auto i = m_items.begin(); + ++i; + + for( ; i != m_items.end(); ++i ) + bbox.Merge( (*i)->GetBoundingBox() ); + + return bbox; +} + + +EDA_ITEM* SELECTION::GetTopLeftItem( bool onlyModules ) const +{ + WS_DRAW_ITEM_BASE* topLeftItem = nullptr; + EDA_RECT topLeftItemBB; + + // find the leftmost (smallest x coord) and highest (smallest y with the smallest x) item in the selection + for( auto item : m_items ) + { + WS_DRAW_ITEM_BASE* currentItem = static_cast( item ); + EDA_RECT currentItemBB = currentItem->GetBoundingBox(); + + if( topLeftItem == nullptr ) + { + topLeftItem = currentItem; + topLeftItemBB = currentItemBB; + } + else if( currentItemBB.GetLeft() < topLeftItemBB.GetLeft() ) + { + topLeftItem = currentItem; + topLeftItemBB = currentItemBB; + } + else if( topLeftItemBB.GetLeft() == currentItemBB.GetLeft() + && currentItemBB.GetTop() < topLeftItemBB.GetTop() ) + { + topLeftItem = currentItem; + topLeftItemBB = currentItemBB; + } + } + + return static_cast( topLeftItem ); +} + + +const BOX2I SELECTION::ViewBBox() const +{ + BOX2I r; + r.SetMaximum(); + return r; +} + + +const KIGFX::VIEW_GROUP::ITEMS SELECTION::updateDrawList() const +{ + std::vector items; + + for( auto item : m_items ) + items.push_back( item ); + + return items; +} diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 2c1524d9e7..38d9965245 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -331,7 +331,7 @@ set( PCBNEW_CLASS_SRCS tools/pcb_selection_conditions.cpp tools/pcb_tool_base.cpp tools/pcbnew_control.cpp - tools/picker_tool.cpp + tools/pcbnew_picker_tool.cpp tools/placement_tool.cpp tools/point_editor.cpp tools/position_relative_tool.cpp diff --git a/pcbnew/block_footprint_editor.cpp b/pcbnew/block_footprint_editor.cpp index 3e17154839..df1761893c 100644 --- a/pcbnew/block_footprint_editor.cpp +++ b/pcbnew/block_footprint_editor.cpp @@ -259,10 +259,6 @@ bool FOOTPRINT_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) OnModify(); break; - case BLOCK_ZOOM: // Window Zoom - Window_Zoom( GetScreen()->m_BlockLocate ); - break; - case BLOCK_ABORT: break; diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index 4df45283db..ca2ff48adf 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -74,7 +74,7 @@ #include "tools/pcbnew_control.h" #include "tools/footprint_editor_tools.h" #include "tools/placement_tool.h" -#include "tools/picker_tool.h" +#include "tools/pcbnew_picker_tool.h" #include "tools/pad_tool.h" #include "tools/pcb_actions.h" @@ -276,9 +276,6 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, m_Layers->SelectLayer( F_SilkS ); m_Layers->OnLayerSelected(); - if( m_canvas ) - m_canvas->SetEnableBlockCommands( true ); - m_auimgr.SetManagedWindow( this ); m_auimgr.SetArtProvider( new EDA_DOCKART( this ) ); @@ -974,7 +971,7 @@ void FOOTPRINT_EDIT_FRAME::setupTools() m_toolManager->RegisterTool( new PCBNEW_CONTROL ); m_toolManager->RegisterTool( new MODULE_EDITOR_TOOLS ); m_toolManager->RegisterTool( new ALIGN_DISTRIBUTE_TOOL ); - m_toolManager->RegisterTool( new PICKER_TOOL ); + m_toolManager->RegisterTool( new PCBNEW_PICKER_TOOL ); m_toolManager->RegisterTool( new POSITION_RELATIVE_TOOL ); m_toolManager->GetTool()->SetEditModules( true ); diff --git a/pcbnew/footprint_edit_frame.h b/pcbnew/footprint_edit_frame.h index ee70e50b07..af373eb9db 100644 --- a/pcbnew/footprint_edit_frame.h +++ b/pcbnew/footprint_edit_frame.h @@ -133,12 +133,6 @@ public: */ void OnLeftDClick( wxDC* DC, const wxPoint& MousePos ) override; - /** - * Handle the right mouse click in the footprint editor. - * - * Create the pop up menu. After this menu is built, the standard ZOOM menu is added - */ - bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ) override; /** * @brief (Re)Create the menubar for the module editor frame diff --git a/pcbnew/footprint_editor_onclick.cpp b/pcbnew/footprint_editor_onclick.cpp index 4f3324c0ae..edfd273b05 100644 --- a/pcbnew/footprint_editor_onclick.cpp +++ b/pcbnew/footprint_editor_onclick.cpp @@ -207,11 +207,6 @@ void FOOTPRINT_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) } -bool FOOTPRINT_EDIT_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ) -{ - return true; -} - /* * Called on a mouse left button double click */ diff --git a/pcbnew/footprint_viewer_frame.cpp b/pcbnew/footprint_viewer_frame.cpp index 5a98a65bf7..97561ad087 100644 --- a/pcbnew/footprint_viewer_frame.cpp +++ b/pcbnew/footprint_viewer_frame.cpp @@ -738,17 +738,6 @@ void FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList( wxCommandEvent& event ) } -void FOOTPRINT_VIEWER_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) -{ -} - - -bool FOOTPRINT_VIEWER_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ) -{ - return true; -} - - void FOOTPRINT_VIEWER_FRAME::UpdateTitle() { wxString title; diff --git a/pcbnew/footprint_viewer_frame.h b/pcbnew/footprint_viewer_frame.h index 3bf3ea117e..efa1b96b60 100644 --- a/pcbnew/footprint_viewer_frame.h +++ b/pcbnew/footprint_viewer_frame.h @@ -128,7 +128,6 @@ private: void ReCreateVToolbar() override; void ReCreateMenuBar() override; - void OnLeftClick( wxDC* DC, const wxPoint& MousePos ) override; void ClickOnLibList( wxCommandEvent& event ); void ClickOnFootprintList( wxCommandEvent& event ); void DClickOnFootprintList( wxCommandEvent& event ); @@ -182,8 +181,6 @@ private: */ void SelectAndViewFootprint( int aMode ); - bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ) override; - /** * Function Show3D_Frame (virtual) * displays 3D view of the footprint (module) being edited. @@ -203,7 +200,6 @@ private: * Virtual functions, not used here, but needed by PCB_BASE_FRAME * (virtual pure functions ) */ - void OnLeftDClick( wxDC*, const wxPoint& ) override {} void SaveCopyInUndoList( BOARD_ITEM*, UNDO_REDO_T, const wxPoint& ) override {} void SaveCopyInUndoList( const PICKED_ITEMS_LIST&, UNDO_REDO_T, const wxPoint &) override {} diff --git a/pcbnew/footprint_wizard_frame.h b/pcbnew/footprint_wizard_frame.h index f6ba3adcb7..12d726544f 100644 --- a/pcbnew/footprint_wizard_frame.h +++ b/pcbnew/footprint_wizard_frame.h @@ -179,7 +179,6 @@ private: void OnCloseWindow( wxCloseEvent& Event ) override; void ReCreateHToolbar() override; void ReCreateVToolbar() override; - void OnLeftClick( wxDC* DC, const wxPoint& MousePos ) override; void ClickOnPageList( wxCommandEvent& event ); void OnSetRelativeOffset( wxCommandEvent& event ); @@ -218,8 +217,6 @@ private: */ void ParametersUpdated( wxGridEvent& event ); - bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ) override; - /** * Function Show3D_Frame (virtual) * displays 3D view of the footprint (module) being edited. @@ -239,7 +236,6 @@ private: * Virtual functions, not used here, but needed by PCB_BASE_FRAME * (virtual pure functions ) */ - void OnLeftDClick( wxDC*, const wxPoint& ) override {} void SaveCopyInUndoList( BOARD_ITEM*, UNDO_REDO_T, const wxPoint& ) override {} void SaveCopyInUndoList( const PICKED_ITEMS_LIST&, UNDO_REDO_T, const wxPoint& ) override {} diff --git a/pcbnew/footprint_wizard_frame_functions.cpp b/pcbnew/footprint_wizard_frame_functions.cpp index a1faa742af..6b6183514b 100644 --- a/pcbnew/footprint_wizard_frame_functions.cpp +++ b/pcbnew/footprint_wizard_frame_functions.cpp @@ -76,25 +76,6 @@ void FOOTPRINT_WIZARD_FRAME::Process_Special_Functions( wxCommandEvent& event ) } -/* Function OnLeftClick - * Captures a left click event in the dialog - * - */ -void FOOTPRINT_WIZARD_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) -{ -} - - -/* Function OnRightClick - * Captures a right click event in the dialog - * - */ -bool FOOTPRINT_WIZARD_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ) -{ - return true; -} - - /* Displays the name of the current opened library in the caption */ void FOOTPRINT_WIZARD_FRAME::DisplayWizardInfos() { diff --git a/pcbnew/pcb_draw_panel_gal.cpp b/pcbnew/pcb_draw_panel_gal.cpp index 5c01530bc2..6e35654813 100644 --- a/pcbnew/pcb_draw_panel_gal.cpp +++ b/pcbnew/pcb_draw_panel_gal.cpp @@ -237,8 +237,8 @@ void PCB_DRAW_PANEL_GAL::SetHighContrastLayer( PCB_LAYER_ID aLayer ) LAYER_RATSNEST, LAYER_CURSOR }; - for( unsigned int i = 0; i < sizeof( layers ) / sizeof( LAYER_NUM ); ++i ) - rSettings->SetActiveLayer( layers[i] ); + for( unsigned int i : layers ) + rSettings->SetActiveLayer( i ); // Pads should be shown too if( aLayer == B_Cu ) diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 2516d648d5..f08e633297 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -68,7 +68,7 @@ #include #include #include -#include +#include #include #include #include @@ -333,9 +333,6 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : GetScreen()->AddGrid( m_UserGridSize, EDA_UNITS_T::UNSCALED_UNITS, ID_POPUP_GRID_USER ); GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId ); - if( m_canvas ) - m_canvas->SetEnableBlockCommands( true ); - setupTools(); ReCreateMenuBar(); ReCreateHToolbar(); @@ -534,7 +531,7 @@ void PCB_EDIT_FRAME::setupTools() m_toolManager->RegisterTool( new COMMON_TOOLS ); m_toolManager->RegisterTool( new SELECTION_TOOL ); m_toolManager->RegisterTool( new ZOOM_TOOL ); - m_toolManager->RegisterTool( new PICKER_TOOL ); + m_toolManager->RegisterTool( new PCBNEW_PICKER_TOOL ); m_toolManager->RegisterTool( new ROUTER_TOOL ); m_toolManager->RegisterTool( new LENGTH_TUNER_TOOL ); m_toolManager->RegisterTool( new EDIT_TOOL ); diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index 15cef04a9c..e208c8dd9e 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -660,7 +660,6 @@ public: /* mouse functions events: */ void OnLeftClick( wxDC* DC, const wxPoint& MousePos ) override; void OnLeftDClick( wxDC* DC, const wxPoint& MousePos ) override; - bool OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) override { return true; } void OnSelectOptionToolbar( wxCommandEvent& event ); void OnFlipPcbView( wxCommandEvent& event ); diff --git a/pcbnew/pcb_screen.cpp b/pcbnew/pcb_screen.cpp index ebbc66a189..af685daffb 100644 --- a/pcbnew/pcb_screen.cpp +++ b/pcbnew/pcb_screen.cpp @@ -40,10 +40,8 @@ #define ZOOM_FACTOR( x ) ( x * IU_PER_MILS / 10 ) -#define DMIL_GRID( x ) wxRealPoint( x * IU_PER_MILS / 10,\ - x * IU_PER_MILS / 10 ) -#define MM_GRID( x ) wxRealPoint( x * IU_PER_MM,\ - x * IU_PER_MM ) +#define DMIL_GRID( x ) wxRealPoint( x * IU_PER_MILS / 10, x * IU_PER_MILS / 10 ) +#define MM_GRID( x ) wxRealPoint( x * IU_PER_MM, x * IU_PER_MM ) /** @@ -56,8 +54,6 @@ Zoom 5 and 10 can create artefacts when drawing (integer overflow in low level graphic functions ) */ -#define DEFAULT_ZOOM ZOOM_FACTOR( 120 ) - static const double pcbZoomList[] = { ZOOM_FACTOR( 0.035 ), @@ -160,11 +156,11 @@ static GRID_TYPE pcbGridList[] = PCB_SCREEN::PCB_SCREEN( const wxSize& aPageSizeIU ) : BASE_SCREEN( SCREEN_T ) { - for( unsigned i = 0; i < arrayDim( pcbZoomList ); ++i ) - m_ZoomList.push_back( pcbZoomList[i] ); + for( double zoom : pcbZoomList ) + m_ZoomList.push_back( zoom ); - for( unsigned i = 0; i < arrayDim( pcbGridList ); ++i ) - AddGrid( pcbGridList[i] ); + for( GRID_TYPE grid : pcbGridList ) + AddGrid( grid ); // Set the working grid size to a reasonable value (in 1/10000 inch) SetGrid( DMIL_GRID( 500 ) ); @@ -173,8 +169,6 @@ PCB_SCREEN::PCB_SCREEN( const wxSize& aPageSizeIU ) : m_Route_Layer_TOP = F_Cu; // default layers pair for vias (bottom to top) m_Route_Layer_BOTTOM = B_Cu; - SetZoom( DEFAULT_ZOOM ); // a default value for zoom - InitDataPoints( aPageSizeIU ); } diff --git a/pcbnew/pcbnew_config.cpp b/pcbnew/pcbnew_config.cpp index dba18874d3..c70612be4a 100644 --- a/pcbnew/pcbnew_config.cpp +++ b/pcbnew/pcbnew_config.cpp @@ -41,13 +41,13 @@ #include #include #include -#include +#include #include #include #include #include #include -#include +#include #include #include #include diff --git a/pcbnew/swig/pcbnew_scripting_helpers.cpp b/pcbnew/swig/pcbnew_scripting_helpers.cpp index 8109823e2a..7b863419c1 100644 --- a/pcbnew/swig/pcbnew_scripting_helpers.cpp +++ b/pcbnew/swig/pcbnew_scripting_helpers.cpp @@ -171,15 +171,6 @@ void Refresh() } -void WindowZoom( int xl, int yl, int width, int height ) -{ - EDA_RECT Rect( wxPoint( xl, yl ), wxSize( width, height ) ); - - if( s_PcbEditFrame ) - s_PcbEditFrame->Window_Zoom( Rect ); -} - - void UpdateUserInterface() { if( s_PcbEditFrame ) diff --git a/pcbnew/swig/pcbnew_scripting_helpers.h b/pcbnew/swig/pcbnew_scripting_helpers.h index f8090d2862..7bc7d48382 100644 --- a/pcbnew/swig/pcbnew_scripting_helpers.h +++ b/pcbnew/swig/pcbnew_scripting_helpers.h @@ -92,8 +92,6 @@ bool ArchiveModulesOnBoard( */ void Refresh(); -void WindowZoom( int xl, int yl, int width, int height ); - /** * Update the layer manager and other widgets from the board setup * (layer and items visibility, colors ...) diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index b69b033d4f..d7912bdd73 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -54,7 +54,7 @@ using namespace std::placeholders; #include "pcb_actions.h" #include "selection_tool.h" #include "edit_tool.h" -#include "picker_tool.h" +#include "pcbnew_picker_tool.h" #include "grid_helper.h" #include "kicad_clipboard.h" #include "pcbnew_control.h" @@ -1429,7 +1429,7 @@ int EDIT_TOOL::editFootprintInFpEditor( const TOOL_EVENT& aEvent ) bool EDIT_TOOL::pickCopyReferencePoint( VECTOR2I& aP ) { STATUS_TEXT_POPUP statusPopup( frame() ); - PICKER_TOOL* picker = m_toolMgr->GetTool(); + PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool(); bool picking = true; bool retVal = true; diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index c8fed496a8..a8c290b4f8 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -35,7 +35,7 @@ #include "edit_tool.h" #include "selection_tool.h" #include "drawing_tool.h" -#include "picker_tool.h" +#include "pcbnew_picker_tool.h" #include #include @@ -920,7 +920,7 @@ int PCB_EDITOR_CONTROL::DrillOrigin( const TOOL_EVENT& aEvent ) { Activate(); - PICKER_TOOL* picker = m_toolMgr->GetTool(); + PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool(); assert( picker ); m_frame->SetToolID( ID_PCB_PLACE_OFFSET_COORD_BUTT, wxCURSOR_HAND, _( "Adjust zero" ) ); @@ -1101,7 +1101,7 @@ int PCB_EDITOR_CONTROL::HighlightNetCursor( const TOOL_EVENT& aEvent ) Activate(); - PICKER_TOOL* picker = m_toolMgr->GetTool(); + PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool(); assert( picker ); m_frame->SetToolID( ID_PCB_HIGHLIGHT_BUTT, wxCURSOR_HAND, _( "Highlight net" ) ); @@ -1167,7 +1167,7 @@ int PCB_EDITOR_CONTROL::LocalRatsnestTool( const TOOL_EVENT& aEvent ) { Activate(); - auto picker = m_toolMgr->GetTool(); + auto picker = m_toolMgr->GetTool(); auto board = getModel(); wxASSERT( picker ); wxASSERT( board ); @@ -1178,7 +1178,7 @@ int PCB_EDITOR_CONTROL::LocalRatsnestTool( const TOOL_EVENT& aEvent ) picker->SetFinalizeHandler( [ board ]( int aCondition ){ auto vis = board->IsElementVisible( LAYER_RATSNEST ); - if( aCondition != PICKER_TOOL::END_ACTIVATE ) + if( aCondition != PCBNEW_PICKER_TOOL::END_ACTIVATE ) { for( auto mod : board->Modules() ) for( auto pad : mod->Pads() ) diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 74c7ac25a2..6d2df3cf9a 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -28,7 +28,7 @@ #include "pcb_actions.h" #include "selection_tool.h" #include "edit_tool.h" -#include "picker_tool.h" +#include "pcbnew_picker_tool.h" #include "pcb_editor_control.h" #include "grid_helper.h" @@ -592,7 +592,7 @@ int PCBNEW_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent ) { Activate(); - PICKER_TOOL* picker = m_toolMgr->GetTool(); + PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool(); wxCHECK( picker, 0 ); // TODO it will not check the toolbar button in module editor, as it uses a different ID.. @@ -654,7 +654,7 @@ int PCBNEW_CONTROL::DeleteItemCursor( const TOOL_EVENT& aEvent ) { Activate(); - PICKER_TOOL* picker = m_toolMgr->GetTool(); + PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool(); wxCHECK( picker, 0 ); m_frame->SetToolID( m_editModules ? ID_MODEDIT_DELETE_TOOL : ID_PCB_DELETE_ITEM_BUTT, diff --git a/pcbnew/tools/picker_tool.cpp b/pcbnew/tools/pcbnew_picker_tool.cpp similarity index 87% rename from pcbnew/tools/picker_tool.cpp rename to pcbnew/tools/pcbnew_picker_tool.cpp index dc4ee681b7..e65302ce05 100644 --- a/pcbnew/tools/picker_tool.cpp +++ b/pcbnew/tools/pcbnew_picker_tool.cpp @@ -22,7 +22,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "picker_tool.h" +#include "pcbnew_picker_tool.h" #include "pcb_actions.h" #include "grid_helper.h" #include @@ -33,14 +33,14 @@ TOOL_ACTION PCB_ACTIONS::pickerTool( "pcbnew.Picker", AS_GLOBAL, 0, "", "", NULL, AF_ACTIVATE ); -PICKER_TOOL::PICKER_TOOL() +PCBNEW_PICKER_TOOL::PCBNEW_PICKER_TOOL() : PCB_TOOL_BASE( "pcbnew.Picker" ) { reset(); } -int PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) +int PCBNEW_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) { KIGFX::VIEW_CONTROLS* controls = getViewControls(); GRID_HELPER grid( frame() ); @@ -70,7 +70,7 @@ int PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) } catch( std::exception& e ) { - std::cerr << "PICKER_TOOL click handler error: " << e.what() << std::endl; + std::cerr << "PCBNEW_PICKER_TOOL clickHandler error: " << e.what() << std::endl; finalize_state = EXCEPTION_CANCEL; break; } @@ -95,7 +95,7 @@ int PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) } catch( std::exception& e ) { - std::cerr << "PICKER_TOOL cancel handler error: " << e.what() << std::endl; + std::cerr << "PCBNEW_PICKER_TOOL cancelHandler error: " << e.what() << std::endl; } } @@ -126,7 +126,7 @@ int PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) } catch( std::exception& e ) { - std::cerr << "PICKER_TOOL finalize handler error: " << e.what() << std::endl; + std::cerr << "PCBNEW_PICKER_TOOL finalizeHandler error: " << e.what() << std::endl; } } @@ -138,13 +138,13 @@ int PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) } -void PICKER_TOOL::setTransitions() +void PCBNEW_PICKER_TOOL::setTransitions() { - Go( &PICKER_TOOL::Main, PCB_ACTIONS::pickerTool.MakeEvent() ); + Go( &PCBNEW_PICKER_TOOL::Main, PCB_ACTIONS::pickerTool.MakeEvent() ); } -void PICKER_TOOL::reset() +void PCBNEW_PICKER_TOOL::reset() { m_cursorCapture = false; m_autoPanning = false; @@ -157,7 +157,7 @@ void PICKER_TOOL::reset() } -void PICKER_TOOL::setControls() +void PCBNEW_PICKER_TOOL::setControls() { KIGFX::VIEW_CONTROLS* controls = getViewControls(); diff --git a/pcbnew/tools/picker_tool.h b/pcbnew/tools/pcbnew_picker_tool.h similarity index 97% rename from pcbnew/tools/picker_tool.h rename to pcbnew/tools/pcbnew_picker_tool.h index 19a1130331..1891294e9a 100644 --- a/pcbnew/tools/picker_tool.h +++ b/pcbnew/tools/pcbnew_picker_tool.h @@ -31,11 +31,11 @@ /** * @brief Generic tool for picking a point. */ -class PICKER_TOOL : public PCB_TOOL_BASE +class PCBNEW_PICKER_TOOL : public PCB_TOOL_BASE { public: - PICKER_TOOL(); - ~PICKER_TOOL() {} + PCBNEW_PICKER_TOOL(); + ~PCBNEW_PICKER_TOOL() {} ///> Event handler types. typedef std::function CLICK_HANDLER; diff --git a/pcbnew/tools/position_relative_tool.cpp b/pcbnew/tools/position_relative_tool.cpp index c9700f273c..bd964ed59e 100644 --- a/pcbnew/tools/position_relative_tool.cpp +++ b/pcbnew/tools/position_relative_tool.cpp @@ -28,7 +28,7 @@ using namespace std::placeholders; #include "pcb_actions.h" #include "selection_tool.h" #include "edit_tool.h" -#include "picker_tool.h" +#include "pcbnew_picker_tool.h" #include #include @@ -140,7 +140,7 @@ int POSITION_RELATIVE_TOOL::SelectPositionRelativeItem( const TOOL_EVENT& aEvent { Activate(); - PICKER_TOOL* picker = m_toolMgr->GetTool(); + PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool(); STATUS_TEXT_POPUP statusPopup( frame() ); bool picking = true; diff --git a/pcbnew/tools/selection.cpp b/pcbnew/tools/selection.cpp index b883232059..e12d6a3d34 100644 --- a/pcbnew/tools/selection.cpp +++ b/pcbnew/tools/selection.cpp @@ -123,12 +123,6 @@ EDA_ITEM* SELECTION::GetTopLeftItem( bool onlyModules ) const } -EDA_ITEM* SELECTION::GetTopLeftModule() const -{ - return GetTopLeftItem( true ); -} - - const BOX2I SELECTION::ViewBBox() const { BOX2I r;