Hi, Quick refactor to allow use of BRIGHT_BOX from GerbView
Best, Jon
From 527b2cd85e0ef9249e552577cfe07054b363cc88 Mon Sep 17 00:00:00 2001 From: Jon Evans <j...@craftyjon.com> 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 + common/tool/bright_box.cpp | 64 ++++++++++++++++++++++++++ include/tool/bright_box.h | 99 +++++++++++++++++++++++++++++++++++++++++ pcbnew/CMakeLists.txt | 2 +- pcbnew/tools/bright_box.cpp | 72 ------------------------------ pcbnew/tools/bright_box.h | 87 ------------------------------------ pcbnew/tools/pcb_bright_box.cpp | 63 ++++++++++++++++++++++++++ pcbnew/tools/pcb_bright_box.h | 48 ++++++++++++++++++++ pcbnew/tools/selection_tool.cpp | 4 +- 9 files changed, 278 insertions(+), 162 deletions(-) create mode 100644 common/tool/bright_box.cpp create mode 100644 include/tool/bright_box.h delete mode 100644 pcbnew/tools/bright_box.cpp delete mode 100644 pcbnew/tools/bright_box.h 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 ce319cd..8a7c27e 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -318,6 +318,7 @@ set( COMMON_SRCS tool/tool_menu.cpp tool/conditional_menu.cpp tool/selection_conditions.cpp + tool/bright_box.cpp geometry/seg.cpp geometry/shape.cpp diff --git a/common/tool/bright_box.cpp b/common/tool/bright_box.cpp new file mode 100644 index 0000000..d5f0fcd --- /dev/null +++ b/common/tool/bright_box.cpp @@ -0,0 +1,64 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2013 CERN + * @author Maciej Suminski <maciej.sumin...@cern.ch> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include <tool/bright_box.h> +#include <gal/graphics_abstraction_layer.h> +#include <class_track.h> + +using namespace KIGFX; + +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_lineWidth( LINE_WIDTH ), + m_color( BOX_COLOR ) +{ +} + + +void BRIGHT_BOX::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const +{ + if( !m_item ) + return; + + auto gal = aView->GetGAL(); + + gal->SetIsStroke( true ); + gal->SetIsFill( false ); + gal->SetLineWidth( m_lineWidth ); + gal->SetStrokeColor( m_color ); + + BOX2I box = m_item->ViewBBox(); + + gal->DrawRectangle( box.GetOrigin(), box.GetOrigin() + box.GetSize() ); +} + + +void BRIGHT_BOX::SetItem( EDA_ITEM* aItem ) +{ + m_item = aItem; +} diff --git a/include/tool/bright_box.h b/include/tool/bright_box.h new file mode 100644 index 0000000..9e177cf --- /dev/null +++ b/include/tool/bright_box.h @@ -0,0 +1,99 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2013 CERN + * @author Maciej Suminski <maciej.sumin...@cern.ch> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __BRIGHT_BOX_H +#define __BRIGHT_BOX_H + +#include <math/box2.h> +#include <view/view.h> +#include <base_struct.h> +#include <layers_id_colors_and_visibility.h> +#include <gal/color4d.h> + +/** + * Class BRIGHT_BOX + * + * Draws a decoration to indicate a brightened item. + */ +class BRIGHT_BOX : public EDA_ITEM +{ +public: + BRIGHT_BOX(); + ~BRIGHT_BOX() {} + + virtual const BOX2I ViewBBox() const override + { + BOX2I bb; bb.SetMaximum(); + return bb; + + if( !m_item ) + return BOX2I(); + + return m_item->ViewBBox(); + } + + void ViewDraw( int aLayer, KIGFX::VIEW* aView ) const override; + + void ViewGetLayers( int aLayers[], int& aCount ) const override + { + aLayers[0] = ITEM_GAL_LAYER( GP_OVERLAY ); + aCount = 1; + } + +#if defined(DEBUG) + void Show( int x, std::ostream& st ) const override + { + } +#endif + + /** Get class name + * @return string "BRIGHT_BOX" + */ + virtual wxString GetClass() const override + { + return wxT( "BRIGHT_BOX" ); + } + + void SetItem( EDA_ITEM* aItem ); + + 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; + + EDA_ITEM* m_item; + double m_lineWidth; + KIGFX::COLOR4D m_color; +}; + +#endif diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 53b8bcd..239902a 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/bright_box.cpp b/pcbnew/tools/bright_box.cpp deleted file mode 100644 index 2e52634..0000000 --- a/pcbnew/tools/bright_box.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2013 CERN - * @author Maciej Suminski <maciej.sumin...@cern.ch> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include "bright_box.h" -#include <gal/graphics_abstraction_layer.h> -#include <class_track.h> - -using namespace KIGFX; - -const double BRIGHT_BOX::LINE_WIDTH = 100000.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 ) -{ -} - - -void BRIGHT_BOX::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const -{ - if( !m_item ) - return; - - auto gal = aView->GetGAL(); - - gal->SetIsStroke( true ); - gal->SetIsFill( false ); - gal->SetLineWidth( LINE_WIDTH ); - gal->SetStrokeColor( BOX_COLOR ); - - - if( m_item->Type() == PCB_TRACE_T ) - { - const TRACK* track = static_cast<const TRACK*>( m_item ); - - gal->DrawSegment( track->GetStart(), track->GetEnd(), track->GetWidth() ); - } - else - { - BOX2I box = m_item->ViewBBox(); - - gal->DrawRectangle( box.GetOrigin(), box.GetOrigin() + box.GetSize() ); - } -} - - -void BRIGHT_BOX::SetItem( BOARD_ITEM* aItem ) -{ - m_item = aItem; -} diff --git a/pcbnew/tools/bright_box.h b/pcbnew/tools/bright_box.h deleted file mode 100644 index c4e2a19..0000000 --- a/pcbnew/tools/bright_box.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2013 CERN - * @author Maciej Suminski <maciej.sumin...@cern.ch> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#ifndef __BRIGHT_BOX_H -#define __BRIGHT_BOX_H - -#include <math/box2.h> -#include <view/view.h> -#include <class_board_item.h> -#include <layers_id_colors_and_visibility.h> -#include <gal/color4d.h> - -/** - * Class BRIGHT_BOX - * - * Draws a decoration to indicate a brightened item. - */ -class BRIGHT_BOX : public EDA_ITEM -{ -public: - BRIGHT_BOX(); - ~BRIGHT_BOX() {} - - virtual const BOX2I ViewBBox() const override - { - BOX2I bb; bb.SetMaximum(); - return bb; - - if( !m_item ) - return BOX2I(); - - return m_item->ViewBBox(); - } - - void ViewDraw( int aLayer, KIGFX::VIEW* aView ) const override; - - void ViewGetLayers( int aLayers[], int& aCount ) const override - { - aLayers[0] = ITEM_GAL_LAYER( GP_OVERLAY ); - aCount = 1; - } - -#if defined(DEBUG) - void Show( int x, std::ostream& st ) const override - { - } -#endif - - /** Get class name - * @return string "BRIGHT_BOX" - */ - virtual wxString GetClass() const override - { - return wxT( "BRIGHT_BOX" ); - } - - void SetItem( BOARD_ITEM* aItem ); - -private: - static const KIGFX::COLOR4D BOX_COLOR; - static const double LINE_WIDTH; - - BOARD_ITEM* m_item; -}; - -#endif diff --git a/pcbnew/tools/pcb_bright_box.cpp b/pcbnew/tools/pcb_bright_box.cpp new file mode 100644 index 0000000..08f9402 --- /dev/null +++ b/pcbnew/tools/pcb_bright_box.cpp @@ -0,0 +1,63 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2013 CERN + * @author Maciej Suminski <maciej.sumin...@cern.ch> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "pcb_bright_box.h" +#include <gal/graphics_abstraction_layer.h> +#include <class_track.h> + +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<const TRACK*>( 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 0000000..f331a07 --- /dev/null +++ b/pcbnew/tools/pcb_bright_box.h @@ -0,0 +1,48 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2013 CERN + * @author Maciej Suminski <maciej.sumin...@cern.ch> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __PCB_BRIGHT_BOX_H +#define __PCB_BRIGHT_BOX_H + +#include <tool/bright_box.h> + +/** + * 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 a3e1e41..1ce875b 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -53,7 +53,7 @@ using namespace std::placeholders; #include <ratsnest_data.h> #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 ); -- 2.7.4
_______________________________________________ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp