Refactor BRIGHT_BOX to common so it can be used by other programs

This commit is contained in:
Jon Evans 2017-03-11 00:46:03 -05:00 committed by Maciej Suminski
parent 0a55d8e053
commit 082b8dd2a9
7 changed files with 139 additions and 25 deletions

View File

@ -188,6 +188,7 @@ set( COMMON_PREVIEW_ITEMS_SRCS
preview_items/ruler_item.cpp preview_items/ruler_item.cpp
preview_items/simple_overlay_item.cpp preview_items/simple_overlay_item.cpp
preview_items/selection_area.cpp preview_items/selection_area.cpp
preview_items/bright_box.cpp
) )
set( COMMON_SRCS set( COMMON_SRCS

View File

@ -22,18 +22,20 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#include "bright_box.h" #include <preview_items/bright_box.h>
#include <gal/graphics_abstraction_layer.h> #include <gal/graphics_abstraction_layer.h>
#include <class_track.h> #include <class_track.h>
using namespace KIGFX; 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 ); const COLOR4D BRIGHT_BOX::BOX_COLOR = KIGFX::COLOR4D( 0.0, 1.0, 0.0, 1.0 );
BRIGHT_BOX::BRIGHT_BOX() : BRIGHT_BOX::BRIGHT_BOX() :
EDA_ITEM( NOT_USED ), // this item is never added to a BOARD so it needs no type 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->SetIsStroke( true );
gal->SetIsFill( false ); gal->SetIsFill( false );
gal->SetLineWidth( LINE_WIDTH ); gal->SetLineWidth( m_lineWidth );
gal->SetStrokeColor( BOX_COLOR ); gal->SetStrokeColor( m_color );
BOX2I box = m_item->ViewBBox();
if( m_item->Type() == PCB_TRACE_T ) gal->DrawRectangle( box.GetOrigin(), box.GetOrigin() + box.GetSize() );
{
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 ) void BRIGHT_BOX::SetItem( EDA_ITEM* aItem )
{ {
m_item = aItem; m_item = aItem;
} }

View File

@ -27,7 +27,7 @@
#include <math/box2.h> #include <math/box2.h>
#include <view/view.h> #include <view/view.h>
#include <class_board_item.h> #include <base_struct.h>
#include <layers_id_colors_and_visibility.h> #include <layers_id_colors_and_visibility.h>
#include <gal/color4d.h> #include <gal/color4d.h>
@ -75,13 +75,25 @@ public:
return wxT( "BRIGHT_BOX" ); 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 KIGFX::COLOR4D BOX_COLOR;
static const double LINE_WIDTH; static const double LINE_WIDTH;
BOARD_ITEM* m_item; EDA_ITEM* m_item;
double m_lineWidth;
KIGFX::COLOR4D m_color;
}; };
#endif #endif

View File

@ -291,7 +291,7 @@ set( PCBNEW_CLASS_SRCS
tools/selection_tool.cpp tools/selection_tool.cpp
tools/pcb_selection_conditions.cpp tools/pcb_selection_conditions.cpp
tools/bright_box.cpp tools/pcb_bright_box.cpp
tools/edit_points.cpp tools/edit_points.cpp
tools/edit_constraints.cpp tools/edit_constraints.cpp
tools/point_editor.cpp tools/point_editor.cpp

View File

@ -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 <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 );
}
}

View File

@ -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 <preview_items/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

View File

@ -53,7 +53,7 @@ using namespace std::placeholders;
#include <ratsnest_data.h> #include <ratsnest_data.h>
#include "selection_tool.h" #include "selection_tool.h"
#include "bright_box.h" #include "pcb_bright_box.h"
#include "pcb_actions.h" #include "pcb_actions.h"
// Selection tool actions // Selection tool actions
@ -1136,7 +1136,7 @@ void SELECTION_TOOL::clearSelection()
BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR* aCollector ) BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR* aCollector )
{ {
BOARD_ITEM* current = NULL; BOARD_ITEM* current = NULL;
BRIGHT_BOX brightBox; PCB_BRIGHT_BOX brightBox;
CONTEXT_MENU menu; CONTEXT_MENU menu;
getView()->Add( &brightBox ); getView()->Add( &brightBox );