From 082b8dd2a9b9873fcaf55b21dd06c580e3b894e1 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sat, 11 Mar 2017 00:46:03 -0500 Subject: [PATCH] Refactor BRIGHT_BOX to common so it can be used by other programs --- common/CMakeLists.txt | 1 + .../preview_items}/bright_box.cpp | 28 +++------ .../preview_items}/bright_box.h | 20 ++++-- pcbnew/CMakeLists.txt | 2 +- pcbnew/tools/pcb_bright_box.cpp | 62 +++++++++++++++++++ pcbnew/tools/pcb_bright_box.h | 47 ++++++++++++++ pcbnew/tools/selection_tool.cpp | 4 +- 7 files changed, 139 insertions(+), 25 deletions(-) rename {pcbnew/tools => common/preview_items}/bright_box.cpp (73%) rename {pcbnew/tools => include/preview_items}/bright_box.h (87%) create mode 100644 pcbnew/tools/pcb_bright_box.cpp create mode 100644 pcbnew/tools/pcb_bright_box.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index b0b3b66ffc..18ef011963 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -188,6 +188,7 @@ set( COMMON_PREVIEW_ITEMS_SRCS preview_items/ruler_item.cpp preview_items/simple_overlay_item.cpp preview_items/selection_area.cpp + preview_items/bright_box.cpp ) set( COMMON_SRCS diff --git a/pcbnew/tools/bright_box.cpp b/common/preview_items/bright_box.cpp similarity index 73% rename from pcbnew/tools/bright_box.cpp rename to common/preview_items/bright_box.cpp index 2e52634fdf..cc55dfa371 100644 --- a/pcbnew/tools/bright_box.cpp +++ b/common/preview_items/bright_box.cpp @@ -22,18 +22,20 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "bright_box.h" +#include #include #include using namespace KIGFX; -const double BRIGHT_BOX::LINE_WIDTH = 100000.0; +const double BRIGHT_BOX::LINE_WIDTH = 10000.0; const COLOR4D BRIGHT_BOX::BOX_COLOR = KIGFX::COLOR4D( 0.0, 1.0, 0.0, 1.0 ); BRIGHT_BOX::BRIGHT_BOX() : EDA_ITEM( NOT_USED ), // this item is never added to a BOARD so it needs no type - m_item( nullptr ) + m_item( nullptr ), + m_lineWidth( LINE_WIDTH ), + m_color( BOX_COLOR ) { } @@ -47,26 +49,16 @@ void BRIGHT_BOX::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const gal->SetIsStroke( true ); gal->SetIsFill( false ); - gal->SetLineWidth( LINE_WIDTH ); - gal->SetStrokeColor( BOX_COLOR ); + gal->SetLineWidth( m_lineWidth ); + gal->SetStrokeColor( m_color ); + BOX2I box = m_item->ViewBBox(); - if( m_item->Type() == PCB_TRACE_T ) - { - const TRACK* track = static_cast( m_item ); - - gal->DrawSegment( track->GetStart(), track->GetEnd(), track->GetWidth() ); - } - else - { - BOX2I box = m_item->ViewBBox(); - - gal->DrawRectangle( box.GetOrigin(), box.GetOrigin() + box.GetSize() ); - } + gal->DrawRectangle( box.GetOrigin(), box.GetOrigin() + box.GetSize() ); } -void BRIGHT_BOX::SetItem( BOARD_ITEM* aItem ) +void BRIGHT_BOX::SetItem( EDA_ITEM* aItem ) { m_item = aItem; } diff --git a/pcbnew/tools/bright_box.h b/include/preview_items/bright_box.h similarity index 87% rename from pcbnew/tools/bright_box.h rename to include/preview_items/bright_box.h index c4e2a19a5e..9e177cfca1 100644 --- a/pcbnew/tools/bright_box.h +++ b/include/preview_items/bright_box.h @@ -27,7 +27,7 @@ #include #include -#include +#include #include #include @@ -75,13 +75,25 @@ public: return wxT( "BRIGHT_BOX" ); } - void SetItem( BOARD_ITEM* aItem ); + void SetItem( EDA_ITEM* aItem ); -private: + void SetLineWidth( double aWidth ) + { + m_lineWidth = aWidth; + } + + void SetColor( KIGFX::COLOR4D aColor ) + { + m_color = aColor; + } + +protected: static const KIGFX::COLOR4D BOX_COLOR; static const double LINE_WIDTH; - BOARD_ITEM* m_item; + EDA_ITEM* m_item; + double m_lineWidth; + KIGFX::COLOR4D m_color; }; #endif diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 53b8bcd7f5..239902a905 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -291,7 +291,7 @@ set( PCBNEW_CLASS_SRCS tools/selection_tool.cpp tools/pcb_selection_conditions.cpp - tools/bright_box.cpp + tools/pcb_bright_box.cpp tools/edit_points.cpp tools/edit_constraints.cpp tools/point_editor.cpp diff --git a/pcbnew/tools/pcb_bright_box.cpp b/pcbnew/tools/pcb_bright_box.cpp new file mode 100644 index 0000000000..aee6462cbc --- /dev/null +++ b/pcbnew/tools/pcb_bright_box.cpp @@ -0,0 +1,62 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2017 KiCad Developers, see change_log.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "pcb_bright_box.h" +#include +#include + +using namespace KIGFX; + +const double PCB_BRIGHT_BOX::PCB_LINE_WIDTH = 100000.0; + + +PCB_BRIGHT_BOX::PCB_BRIGHT_BOX() : + BRIGHT_BOX() +{ + SetLineWidth( PCB_LINE_WIDTH ); +} + + +void PCB_BRIGHT_BOX::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const +{ + if( !m_item ) + return; + + if( m_item->Type() == PCB_TRACE_T ) + { + const TRACK* track = static_cast( m_item ); + + auto gal = aView->GetGAL(); + + gal->SetIsStroke( true ); + gal->SetIsFill( false ); + gal->SetLineWidth( m_lineWidth ); + gal->SetStrokeColor( m_color ); + + gal->DrawSegment( track->GetStart(), track->GetEnd(), track->GetWidth() ); + } + else + { + BRIGHT_BOX::ViewDraw( aLayer, aView ); + } +} diff --git a/pcbnew/tools/pcb_bright_box.h b/pcbnew/tools/pcb_bright_box.h new file mode 100644 index 0000000000..e057eb614d --- /dev/null +++ b/pcbnew/tools/pcb_bright_box.h @@ -0,0 +1,47 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2017 KiCad Developers, see change_log.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __PCB_BRIGHT_BOX_H +#define __PCB_BRIGHT_BOX_H + +#include + +/** + * Class PCB_BRIGHT_BOX + * + * Draws a decoration to indicate a brightened item. + */ +class PCB_BRIGHT_BOX : public BRIGHT_BOX +{ +public: + PCB_BRIGHT_BOX(); + ~PCB_BRIGHT_BOX() {} + + void ViewDraw( int aLayer, KIGFX::VIEW* aView ) const override; + +private: + static const double PCB_LINE_WIDTH; + +}; + +#endif diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index a3e1e41d43..1ce875b140 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -53,7 +53,7 @@ using namespace std::placeholders; #include #include "selection_tool.h" -#include "bright_box.h" +#include "pcb_bright_box.h" #include "pcb_actions.h" // Selection tool actions @@ -1136,7 +1136,7 @@ void SELECTION_TOOL::clearSelection() BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR* aCollector ) { BOARD_ITEM* current = NULL; - BRIGHT_BOX brightBox; + PCB_BRIGHT_BOX brightBox; CONTEXT_MENU menu; getView()->Add( &brightBox );