2011-11-17 01:06:08 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-03-02 17:29:18 +00:00
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
2019-05-27 09:06:34 +00:00
|
|
|
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-11-17 01:06:08 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
/**
|
2012-04-12 21:31:31 +00:00
|
|
|
* @brief Implementation of EDA_ITEM base class for KiCad.
|
2011-09-30 18:15:37 +00:00
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2019-05-30 13:33:59 +00:00
|
|
|
#include <deque>
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <macros.h>
|
2012-04-01 20:51:56 +00:00
|
|
|
#include <kicad_string.h>
|
2018-01-29 15:39:40 +00:00
|
|
|
#include <eda_base_frame.h>
|
2018-01-29 10:37:29 +00:00
|
|
|
#include <base_screen.h>
|
2016-10-18 15:39:28 +00:00
|
|
|
#include <bitmaps.h>
|
2018-04-13 13:58:25 +00:00
|
|
|
#include <trace_helpers.h>
|
2019-05-27 09:06:34 +00:00
|
|
|
#include <eda_rect.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2011-11-17 01:06:08 +00:00
|
|
|
#include "../eeschema/dialogs/dialog_schematic_find.h"
|
|
|
|
|
2013-10-27 18:21:53 +00:00
|
|
|
|
2016-10-18 15:39:28 +00:00
|
|
|
static const unsigned char dummy_png[] = {
|
|
|
|
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
|
|
|
|
0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0xf3, 0xff,
|
|
|
|
0x61, 0x00, 0x00, 0x00, 0x5f, 0x49, 0x44, 0x41, 0x54, 0x38, 0xcb, 0x63, 0xf8, 0xff, 0xff, 0x3f,
|
|
|
|
0x03, 0x25, 0x98, 0x61, 0x68, 0x1a, 0x00, 0x04, 0x46, 0x40, 0xfc, 0x02, 0x88, 0x45, 0x41, 0x1c,
|
|
|
|
0x76, 0x20, 0xfe, 0x01, 0xc4, 0xbe, 0x24, 0x18, 0x60, 0x01, 0xc4, 0x20, 0x86, 0x04, 0x88, 0xc3,
|
|
|
|
0x01, 0xe5, 0x04, 0x0c, 0xb8, 0x01, 0x37, 0x81, 0xf8, 0x04, 0x91, 0xf8, 0x0a, 0x54, 0x8f, 0x06,
|
|
|
|
0xb2, 0x01, 0x9b, 0x81, 0x78, 0x02, 0x91, 0x78, 0x05, 0x54, 0x8f, 0xca, 0xe0, 0x08, 0x03, 0x36,
|
|
|
|
0xa8, 0xbf, 0xec, 0xc8, 0x32, 0x80, 0xcc, 0x84, 0x04, 0x0a, 0xbc, 0x1d, 0x40, 0x2c, 0xc8, 0x30,
|
|
|
|
0xf4, 0x33, 0x13, 0x00, 0x6b, 0x1a, 0x46, 0x7b, 0x68, 0xe7, 0x0f, 0x0b, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const BITMAP_OPAQUE dummy_xpm[1] = {{ dummy_png, sizeof( dummy_png ), "dummy_xpm" }};
|
|
|
|
|
2013-10-27 18:21:53 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
enum textbox {
|
2007-08-04 20:05:54 +00:00
|
|
|
ID_TEXTBOX_LIST = 8010
|
2007-05-06 16:03:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM::EDA_ITEM( EDA_ITEM* parent, KICAD_T idType )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2015-01-20 12:06:44 +00:00
|
|
|
initVars();
|
2007-08-04 20:05:54 +00:00
|
|
|
m_StructType = idType;
|
2009-11-23 15:16:50 +00:00
|
|
|
m_Parent = parent;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM::EDA_ITEM( KICAD_T idType )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2015-01-20 12:06:44 +00:00
|
|
|
initVars();
|
2007-08-04 20:05:54 +00:00
|
|
|
m_StructType = idType;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM::EDA_ITEM( const EDA_ITEM& base )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2015-01-20 12:06:44 +00:00
|
|
|
initVars();
|
2016-05-31 08:27:52 +00:00
|
|
|
*this = base;
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-20 12:06:44 +00:00
|
|
|
void EDA_ITEM::initVars()
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-08-04 20:05:54 +00:00
|
|
|
m_StructType = TYPE_NOT_INIT;
|
2008-11-24 06:53:43 +00:00
|
|
|
Pnext = NULL; // Linked list: Link (next struct)
|
|
|
|
Pback = NULL; // Linked list: Link (previous struct)
|
|
|
|
m_Parent = NULL; // Linked list: Link (parent struct)
|
|
|
|
m_List = NULL; // I am not on any list yet
|
|
|
|
m_Flags = 0; // flags for editions and other
|
2011-12-18 15:26:09 +00:00
|
|
|
SetTimeStamp( 0 ); // Time stamp used for logical links
|
2007-08-04 20:05:54 +00:00
|
|
|
m_Status = 0;
|
2011-12-18 15:26:09 +00:00
|
|
|
m_forceVisible = false; // true to override the visibility setting of the item.
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void EDA_ITEM::SetModified()
|
2010-12-07 16:10:42 +00:00
|
|
|
{
|
2013-03-30 19:55:26 +00:00
|
|
|
SetFlags( IS_CHANGED );
|
2010-12-07 16:10:42 +00:00
|
|
|
|
|
|
|
// If this a child object, then the parent modification state also needs to be set.
|
|
|
|
if( m_Parent )
|
|
|
|
m_Parent->SetModified();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-22 16:54:01 +00:00
|
|
|
const EDA_RECT EDA_ITEM::GetBoundingBox() const
|
|
|
|
{
|
|
|
|
#if defined(DEBUG)
|
|
|
|
printf( "Missing GetBoundingBox()\n" );
|
|
|
|
Show( 0, std::cout ); // tell me which classes still need GetBoundingBox support
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// return a zero-sized box per default. derived classes should override
|
|
|
|
// this
|
|
|
|
return EDA_RECT( wxPoint( 0, 0 ), wxSize( 0, 0 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-12 08:37:05 +00:00
|
|
|
EDA_ITEM* EDA_ITEM::Clone() const
|
|
|
|
{
|
2012-03-17 14:39:27 +00:00
|
|
|
wxCHECK_MSG( false, NULL, wxT( "Clone not implemented in derived class " ) + GetClass() +
|
|
|
|
wxT( ". Bad programmer!" ) );
|
2011-12-12 08:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-09 21:15:08 +00:00
|
|
|
// see base_struct.h
|
|
|
|
// many classes inherit this method, be careful:
|
2019-05-31 02:30:28 +00:00
|
|
|
//TODO(snh): Fix this to use std::set instead of C-style vector
|
2016-07-12 19:05:54 +00:00
|
|
|
SEARCH_RESULT EDA_ITEM::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] )
|
2007-08-09 21:15:08 +00:00
|
|
|
{
|
2009-04-29 12:10:15 +00:00
|
|
|
#if 0 && defined(DEBUG)
|
2008-03-15 10:24:32 +00:00
|
|
|
std::cout << GetClass().mb_str() << ' ';
|
2007-08-24 03:40:04 +00:00
|
|
|
#endif
|
2008-03-13 16:44:14 +00:00
|
|
|
|
2019-04-30 13:54:32 +00:00
|
|
|
if( IsType( scanTypes ) )
|
2007-08-09 21:15:08 +00:00
|
|
|
{
|
2019-04-30 13:54:32 +00:00
|
|
|
if( SEARCH_QUIT == inspector( this, testData ) )
|
|
|
|
return SEARCH_QUIT;
|
2007-08-09 21:15:08 +00:00
|
|
|
}
|
|
|
|
|
2008-03-13 16:44:14 +00:00
|
|
|
return SEARCH_CONTINUE;
|
2007-08-09 21:15:08 +00:00
|
|
|
}
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
wxString EDA_ITEM::GetSelectMenuText( EDA_UNITS_T aUnits ) const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
|
|
|
wxFAIL_MSG( wxT( "GetSelectMenuText() was not overridden for schematic item type " ) +
|
|
|
|
GetClass() );
|
|
|
|
|
|
|
|
return wxString( wxT( "Undefined menu text for " ) + GetClass() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-17 01:06:08 +00:00
|
|
|
bool EDA_ITEM::Matches( const wxString& aText, wxFindReplaceData& aSearchData )
|
|
|
|
{
|
|
|
|
wxString text = aText;
|
|
|
|
wxString searchText = aSearchData.GetFindString();
|
|
|
|
|
|
|
|
// Don't match if searching for replaceable item and the item doesn't support text replace.
|
|
|
|
if( (aSearchData.GetFlags() & FR_SEARCH_REPLACE) && !IsReplaceable() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( aSearchData.GetFlags() & wxFR_WHOLEWORD )
|
|
|
|
return aText.IsSameAs( searchText, aSearchData.GetFlags() & wxFR_MATCHCASE );
|
|
|
|
|
|
|
|
if( aSearchData.GetFlags() & FR_MATCH_WILDCARD )
|
|
|
|
{
|
|
|
|
if( aSearchData.GetFlags() & wxFR_MATCHCASE )
|
|
|
|
return text.Matches( searchText );
|
|
|
|
|
|
|
|
return text.MakeUpper().Matches( searchText.MakeUpper() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aSearchData.GetFlags() & wxFR_MATCHCASE )
|
|
|
|
return aText.Find( searchText ) != wxNOT_FOUND;
|
|
|
|
|
|
|
|
return text.MakeUpper().Find( searchText.MakeUpper() ) != wxNOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-13 15:37:33 +00:00
|
|
|
bool EDA_ITEM::Replace( wxFindReplaceData& aSearchData, wxString& aText )
|
|
|
|
{
|
|
|
|
wxCHECK_MSG( IsReplaceable(), false,
|
|
|
|
wxT( "Attempt to replace text in <" ) + GetClass() + wxT( "> item." ) );
|
|
|
|
|
2014-09-01 15:28:29 +00:00
|
|
|
wxString searchString = (aSearchData.GetFlags() & wxFR_MATCHCASE) ? aText : aText.Upper();
|
2013-10-27 18:21:53 +00:00
|
|
|
|
|
|
|
int result = searchString.Find( (aSearchData.GetFlags() & wxFR_MATCHCASE) ?
|
|
|
|
aSearchData.GetFindString() :
|
|
|
|
aSearchData.GetFindString().Upper() );
|
|
|
|
|
|
|
|
if( result == wxNOT_FOUND )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
wxString prefix = aText.Left( result );
|
|
|
|
wxString suffix;
|
|
|
|
|
|
|
|
if( aSearchData.GetFindString().length() + result < aText.length() )
|
|
|
|
suffix = aText.Right( aText.length() - ( aSearchData.GetFindString().length() + result ) );
|
|
|
|
|
|
|
|
wxLogTrace( traceFindReplace, wxT( "Replacing '%s', prefix '%s', replace '%s', suffix '%s'." ),
|
|
|
|
GetChars( aText ), GetChars( prefix ), GetChars( aSearchData.GetReplaceString() ),
|
|
|
|
GetChars( suffix ) );
|
|
|
|
|
|
|
|
aText = prefix + aSearchData.GetReplaceString() + suffix;
|
|
|
|
|
|
|
|
return true;
|
2011-12-13 15:37:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
bool EDA_ITEM::operator<( const EDA_ITEM& aItem ) const
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "Less than operator not defined for item type %s." ),
|
|
|
|
GetChars( GetClass() ) ) );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-09 20:26:55 +00:00
|
|
|
EDA_ITEM& EDA_ITEM::operator=( const EDA_ITEM& aItem )
|
|
|
|
{
|
2016-05-31 08:27:52 +00:00
|
|
|
// do not call initVars()
|
|
|
|
|
|
|
|
m_StructType = aItem.m_StructType;
|
|
|
|
m_Flags = aItem.m_Flags;
|
|
|
|
m_Status = aItem.m_Status;
|
|
|
|
m_Parent = aItem.m_Parent;
|
|
|
|
m_forceVisible = aItem.m_forceVisible;
|
|
|
|
|
|
|
|
// A copy of an item cannot have the same time stamp as the original item.
|
|
|
|
SetTimeStamp( GetNewTimeStamp() );
|
|
|
|
|
|
|
|
// do not copy list related fields (Pnext, Pback, m_List)
|
2012-01-09 20:26:55 +00:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
Introduction of Graphics Abstraction Layer based rendering for pcbnew.
New classes:
- VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.)
- VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes).
- EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL).
- GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries.
- WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc.
- PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods.
- STROKE_FONT - Implements stroke font drawing using GAL methods.
Most important changes to Kicad original code:
* EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects.
* EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime.
* There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew)
* Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom.
* Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime.
* Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods.
* Removed tools/class_painter.h, as now it is extended and included in source code.
Build changes:
* GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL.
* When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required.
* GAL-related code is compiled into a static library (common/libgal).
* Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad
Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS).
More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
2013-04-02 06:54:03 +00:00
|
|
|
const BOX2I EDA_ITEM::ViewBBox() const
|
|
|
|
{
|
|
|
|
// Basic fallback
|
|
|
|
return BOX2I( VECTOR2I( GetBoundingBox().GetOrigin() ),
|
|
|
|
VECTOR2I( GetBoundingBox().GetSize() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
|
|
|
// Basic fallback
|
|
|
|
aCount = 1;
|
|
|
|
aLayers[0] = 0;
|
|
|
|
}
|
|
|
|
|
2016-10-18 15:39:28 +00:00
|
|
|
BITMAP_DEF EDA_ITEM::GetMenuImage() const
|
|
|
|
{
|
|
|
|
return dummy_xpm;
|
|
|
|
}
|
Introduction of Graphics Abstraction Layer based rendering for pcbnew.
New classes:
- VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.)
- VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes).
- EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL).
- GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries.
- WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc.
- PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods.
- STROKE_FONT - Implements stroke font drawing using GAL methods.
Most important changes to Kicad original code:
* EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects.
* EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime.
* There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew)
* Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom.
* Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime.
* Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods.
* Removed tools/class_painter.h, as now it is extended and included in source code.
Build changes:
* GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL.
* When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required.
* GAL-related code is compiled into a static library (common/libgal).
* Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad
Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS).
More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
2013-04-02 06:54:03 +00:00
|
|
|
|
2009-04-29 12:10:15 +00:00
|
|
|
#if defined(DEBUG)
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2011-12-14 17:25:42 +00:00
|
|
|
void EDA_ITEM::ShowDummy( std::ostream& os ) const
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2008-04-22 16:38:23 +00:00
|
|
|
// XML output:
|
2008-03-13 16:44:14 +00:00
|
|
|
wxString s = GetClass();
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2011-12-14 17:25:42 +00:00
|
|
|
os << '<' << s.Lower().mb_str() << ">"
|
|
|
|
<< " Need ::Show() override for this class "
|
|
|
|
<< "</" << s.Lower().mb_str() << ">\n";
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
|
|
|
|
2008-03-13 16:44:14 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
std::ostream& EDA_ITEM::NestedSpace( int nestLevel, std::ostream& os )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2008-03-15 10:24:32 +00:00
|
|
|
for( int i = 0; i<nestLevel; ++i )
|
2008-12-16 19:44:57 +00:00
|
|
|
os << " ";
|
|
|
|
|
|
|
|
// number of spaces here controls indent per nest level
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2008-03-15 10:24:32 +00:00
|
|
|
#endif
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2008-12-16 19:44:57 +00:00
|
|
|
/******************/
|
2011-03-29 19:33:07 +00:00
|
|
|
/* Class EDA_RECT */
|
2008-12-16 19:44:57 +00:00
|
|
|
/******************/
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
void EDA_RECT::Normalize()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-04 20:05:54 +00:00
|
|
|
if( m_Size.y < 0 )
|
|
|
|
{
|
|
|
|
m_Size.y = -m_Size.y;
|
|
|
|
m_Pos.y -= m_Size.y;
|
|
|
|
}
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
if( m_Size.x < 0 )
|
|
|
|
{
|
|
|
|
m_Size.x = -m_Size.x;
|
|
|
|
m_Pos.x -= m_Size.x;
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
void EDA_RECT::Move( const wxPoint& aMoveVector )
|
2009-11-28 09:24:37 +00:00
|
|
|
{
|
|
|
|
m_Pos += aMoveVector;
|
|
|
|
}
|
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
bool EDA_RECT::Contains( const wxPoint& aPoint ) const
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-12-20 17:44:25 +00:00
|
|
|
wxPoint rel_pos = aPoint - m_Pos;
|
2009-04-29 12:10:15 +00:00
|
|
|
wxSize size = m_Size;
|
2007-08-04 20:05:54 +00:00
|
|
|
|
|
|
|
if( size.x < 0 )
|
|
|
|
{
|
2008-03-15 10:24:32 +00:00
|
|
|
size.x = -size.x;
|
2010-12-20 17:44:25 +00:00
|
|
|
rel_pos.x += size.x;
|
2007-08-04 20:05:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( size.y < 0 )
|
|
|
|
{
|
2008-03-15 10:24:32 +00:00
|
|
|
size.y = -size.y;
|
2010-12-20 17:44:25 +00:00
|
|
|
rel_pos.y += size.y;
|
2007-08-04 20:05:54 +00:00
|
|
|
}
|
2008-03-13 16:44:14 +00:00
|
|
|
|
2010-12-20 17:44:25 +00:00
|
|
|
return (rel_pos.x >= 0) && (rel_pos.y >= 0) && ( rel_pos.y <= size.y) && ( rel_pos.x <= size.x);
|
2010-12-10 19:47:44 +00:00
|
|
|
}
|
|
|
|
|
2011-06-07 15:29:01 +00:00
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
bool EDA_RECT::Contains( const EDA_RECT& aRect ) const
|
2010-12-10 19:47:44 +00:00
|
|
|
{
|
2010-12-21 15:13:09 +00:00
|
|
|
return Contains( aRect.GetOrigin() ) && Contains( aRect.GetEnd() );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2013-09-21 18:09:41 +00:00
|
|
|
bool EDA_RECT::Intersects( const wxPoint& aPoint1, const wxPoint& aPoint2 ) const
|
|
|
|
{
|
|
|
|
wxPoint point2, point4;
|
|
|
|
|
|
|
|
if( Contains( aPoint1 ) || Contains( aPoint2 ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
point2.x = GetEnd().x;
|
|
|
|
point2.y = GetOrigin().y;
|
|
|
|
point4.x = GetOrigin().x;
|
|
|
|
point4.y = GetEnd().y;
|
|
|
|
|
|
|
|
//Only need to test 3 sides since a straight line cant enter and exit on same side
|
|
|
|
if( SegmentIntersectsSegment( aPoint1, aPoint2, GetOrigin() , point2 ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( SegmentIntersectsSegment( aPoint1, aPoint2, point2 , GetEnd() ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( SegmentIntersectsSegment( aPoint1, aPoint2, GetEnd() , point4 ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
bool EDA_RECT::Intersects( const EDA_RECT& aRect ) const
|
2008-03-13 16:44:14 +00:00
|
|
|
{
|
|
|
|
// this logic taken from wxWidgets' geometry.cpp file:
|
2008-05-17 19:10:36 +00:00
|
|
|
bool rc;
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT me(*this);
|
|
|
|
EDA_RECT rect(aRect);
|
2010-12-20 17:44:25 +00:00
|
|
|
me.Normalize(); // ensure size is >= 0
|
|
|
|
rect.Normalize(); // ensure size is >= 0
|
|
|
|
|
|
|
|
// calculate the left common area coordinate:
|
2012-09-22 11:19:37 +00:00
|
|
|
int left = std::max( me.m_Pos.x, rect.m_Pos.x );
|
2010-12-20 17:44:25 +00:00
|
|
|
// calculate the right common area coordinate:
|
2012-09-22 11:19:37 +00:00
|
|
|
int right = std::min( me.m_Pos.x + me.m_Size.x, rect.m_Pos.x + rect.m_Size.x );
|
2010-12-20 17:44:25 +00:00
|
|
|
// calculate the upper common area coordinate:
|
2012-09-22 11:19:37 +00:00
|
|
|
int top = std::max( me.m_Pos.y, aRect.m_Pos.y );
|
2010-12-20 17:44:25 +00:00
|
|
|
// calculate the lower common area coordinate:
|
2012-09-22 11:19:37 +00:00
|
|
|
int bottom = std::min( me.m_Pos.y + me.m_Size.y, rect.m_Pos.y + rect.m_Size.y );
|
2010-12-20 17:44:25 +00:00
|
|
|
|
|
|
|
// if a common area exists, it must have a positive (null accepted) size
|
|
|
|
if( left <= right && top <= bottom )
|
2008-05-17 19:10:36 +00:00
|
|
|
rc = true;
|
|
|
|
else
|
|
|
|
rc = false;
|
|
|
|
|
|
|
|
return rc;
|
2008-03-13 16:44:14 +00:00
|
|
|
}
|
|
|
|
|
2017-05-10 09:40:49 +00:00
|
|
|
|
2017-04-23 00:06:56 +00:00
|
|
|
bool EDA_RECT::Intersects( const EDA_RECT& aRect, double aRot ) const
|
|
|
|
{
|
|
|
|
/* Most rectangles will be axis aligned.
|
|
|
|
* It is quicker to check for this case and pass the rect
|
|
|
|
* to the simpler intersection test
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Prevent floating point comparison errors
|
|
|
|
static const double ROT_EPS = 0.000000001;
|
|
|
|
|
|
|
|
static const double ROT_PARALLEL[] = { -3600, -1800, 0, 1800, 3600 };
|
|
|
|
static const double ROT_PERPENDICULAR[] = { -2700, -900, 0, 900, 2700 };
|
|
|
|
|
|
|
|
NORMALIZE_ANGLE_POS<double>( aRot );
|
|
|
|
|
|
|
|
// Test for non-rotated rectangle
|
2017-05-10 09:40:49 +00:00
|
|
|
for( int ii = 0; ii < 5; ii++ )
|
2017-04-23 00:06:56 +00:00
|
|
|
{
|
|
|
|
if( std::fabs( aRot - ROT_PARALLEL[ii] ) < ROT_EPS )
|
|
|
|
{
|
|
|
|
return Intersects( aRect );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test for rectangle rotated by multiple of 90 degrees
|
2017-05-10 09:40:49 +00:00
|
|
|
for( int jj = 0; jj < 4; jj++ )
|
2017-04-23 00:06:56 +00:00
|
|
|
{
|
|
|
|
if( std::fabs( aRot - ROT_PERPENDICULAR[jj] ) < ROT_EPS )
|
|
|
|
{
|
|
|
|
EDA_RECT rotRect;
|
|
|
|
|
|
|
|
// Rotate the supplied rect by 90 degrees
|
|
|
|
rotRect.SetOrigin( aRect.Centre() );
|
|
|
|
rotRect.Inflate( aRect.GetHeight(), aRect.GetWidth() );
|
|
|
|
return Intersects( rotRect );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* There is some non-orthogonal rotation.
|
|
|
|
* There are three cases to test:
|
|
|
|
* A) One point of this rect is inside the rotated rect
|
|
|
|
* B) One point of the rotated rect is inside this rect
|
|
|
|
* C) One of the sides of the rotated rect intersect this
|
|
|
|
*/
|
|
|
|
|
|
|
|
wxPoint corners[4];
|
|
|
|
|
|
|
|
/* Test A : Any corners exist in rotated rect? */
|
|
|
|
|
|
|
|
corners[0] = m_Pos;
|
|
|
|
corners[1] = m_Pos + wxPoint( m_Size.x, 0 );
|
|
|
|
corners[2] = m_Pos + wxPoint( m_Size.x, m_Size.y );
|
|
|
|
corners[3] = m_Pos + wxPoint( 0, m_Size.y );
|
|
|
|
|
|
|
|
wxPoint rCentre = aRect.Centre();
|
|
|
|
|
2017-05-10 09:40:49 +00:00
|
|
|
for( int i = 0; i < 4; i++ )
|
2017-04-23 00:06:56 +00:00
|
|
|
{
|
|
|
|
wxPoint delta = corners[i] - rCentre;
|
|
|
|
RotatePoint( &delta, -aRot );
|
|
|
|
delta += rCentre;
|
|
|
|
|
|
|
|
if( aRect.Contains( delta ) )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test B : Any corners of rotated rect exist in this one? */
|
|
|
|
int w = aRect.GetWidth() / 2;
|
|
|
|
int h = aRect.GetHeight() / 2;
|
|
|
|
|
|
|
|
// Construct corners around center of shape
|
|
|
|
corners[0] = wxPoint( -w, -h );
|
|
|
|
corners[1] = wxPoint( w, -h );
|
|
|
|
corners[2] = wxPoint( w, h );
|
|
|
|
corners[3] = wxPoint( -w, h );
|
|
|
|
|
|
|
|
// Rotate and test each corner
|
|
|
|
for( int j=0; j<4; j++ )
|
|
|
|
{
|
|
|
|
RotatePoint( &corners[j], aRot );
|
|
|
|
corners[j] += rCentre;
|
|
|
|
|
|
|
|
if( Contains( corners[j] ) )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test C : Any sides of rotated rect intersect this */
|
|
|
|
|
|
|
|
if( Intersects( corners[0], corners[1] ) ||
|
|
|
|
Intersects( corners[1], corners[2] ) ||
|
|
|
|
Intersects( corners[2], corners[3] ) ||
|
|
|
|
Intersects( corners[3], corners[0] ) )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-10 09:40:49 +00:00
|
|
|
|
2017-04-20 14:53:57 +00:00
|
|
|
const wxPoint EDA_RECT::ClosestPointTo( const wxPoint& aPoint ) const
|
|
|
|
{
|
2017-05-10 09:40:49 +00:00
|
|
|
EDA_RECT me( *this );
|
2017-04-20 14:53:57 +00:00
|
|
|
|
|
|
|
me.Normalize(); // ensure size is >= 0
|
|
|
|
|
|
|
|
// Determine closest point to the circle centre within this rect
|
|
|
|
int nx = std::max( me.GetLeft(), std::min( aPoint.x, me.GetRight() ) );
|
|
|
|
int ny = std::max( me.GetTop(), std::min( aPoint.y, me.GetBottom() ) );
|
|
|
|
|
|
|
|
return wxPoint( nx, ny );
|
|
|
|
}
|
|
|
|
|
2017-05-10 09:40:49 +00:00
|
|
|
|
2017-04-20 14:53:57 +00:00
|
|
|
const wxPoint EDA_RECT::FarthestPointTo( const wxPoint& aPoint ) const
|
|
|
|
{
|
2017-05-10 09:40:49 +00:00
|
|
|
EDA_RECT me( *this );
|
2017-04-20 14:53:57 +00:00
|
|
|
|
|
|
|
me.Normalize(); // ensure size is >= 0
|
|
|
|
|
|
|
|
int fx = std::max( std::abs( aPoint.x - me.GetLeft() ), std::abs( aPoint.x - me.GetRight() ) );
|
|
|
|
int fy = std::max( std::abs( aPoint.y - me.GetTop() ), std::abs( aPoint.y - me.GetBottom() ) );
|
|
|
|
|
|
|
|
return wxPoint( fx, fy );
|
|
|
|
}
|
|
|
|
|
2017-05-10 09:40:49 +00:00
|
|
|
|
2017-04-20 14:53:57 +00:00
|
|
|
bool EDA_RECT::IntersectsCircle( const wxPoint& aCenter, const int aRadius ) const
|
|
|
|
{
|
|
|
|
wxPoint closest = ClosestPointTo( aCenter );
|
|
|
|
|
|
|
|
double dx = aCenter.x - closest.x;
|
|
|
|
double dy = aCenter.y - closest.y;
|
|
|
|
|
|
|
|
double r = (double) aRadius;
|
|
|
|
|
|
|
|
return ( dx * dx + dy * dy ) <= ( r * r );
|
|
|
|
}
|
|
|
|
|
2017-05-10 09:40:49 +00:00
|
|
|
|
2017-04-20 14:53:57 +00:00
|
|
|
bool EDA_RECT::IntersectsCircleEdge( const wxPoint& aCenter, const int aRadius, const int aWidth ) const
|
|
|
|
{
|
2017-05-10 09:40:49 +00:00
|
|
|
EDA_RECT me( *this );
|
2017-04-20 14:53:57 +00:00
|
|
|
me.Normalize(); // ensure size is >= 0
|
|
|
|
|
|
|
|
// Test if the circle intersects at all
|
|
|
|
if( !IntersectsCircle( aCenter, aRadius + aWidth / 2 ) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-10 11:34:51 +00:00
|
|
|
wxPoint farpt = FarthestPointTo( aCenter );
|
2017-04-20 14:53:57 +00:00
|
|
|
// Farthest point must be further than the inside of the line
|
2017-05-10 11:34:51 +00:00
|
|
|
double fx = (double) farpt.x;
|
|
|
|
double fy = (double) farpt.y;
|
2017-04-20 14:53:57 +00:00
|
|
|
|
|
|
|
double r = (double) aRadius - (double) aWidth / 2;
|
|
|
|
|
|
|
|
return ( fx * fx + fy * fy ) > ( r * r );
|
|
|
|
}
|
2008-03-13 16:44:14 +00:00
|
|
|
|
2017-05-10 09:40:49 +00:00
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT& EDA_RECT::Inflate( int aDelta )
|
2009-10-21 19:16:25 +00:00
|
|
|
{
|
|
|
|
Inflate( aDelta, aDelta );
|
2009-10-23 14:35:24 +00:00
|
|
|
return *this;
|
2009-10-21 19:16:25 +00:00
|
|
|
}
|
|
|
|
|
2008-03-18 11:53:52 +00:00
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT& EDA_RECT::Inflate( wxCoord dx, wxCoord dy )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-03-18 11:53:52 +00:00
|
|
|
if( m_Size.x >= 0 )
|
2007-08-04 20:05:54 +00:00
|
|
|
{
|
2008-03-18 11:53:52 +00:00
|
|
|
if( m_Size.x < -2 * dx )
|
|
|
|
{
|
|
|
|
// Don't allow deflate to eat more width than we have,
|
|
|
|
m_Pos.x += m_Size.x / 2;
|
|
|
|
m_Size.x = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The inflate is valid.
|
|
|
|
m_Pos.x -= dx;
|
|
|
|
m_Size.x += 2 * dx;
|
|
|
|
}
|
2007-08-04 20:05:54 +00:00
|
|
|
}
|
2008-03-18 11:53:52 +00:00
|
|
|
else // size.x < 0:
|
2007-08-04 20:05:54 +00:00
|
|
|
{
|
2008-03-18 11:53:52 +00:00
|
|
|
if( m_Size.x > -2 * dx )
|
|
|
|
{
|
|
|
|
// Don't allow deflate to eat more width than we have,
|
|
|
|
m_Pos.x -= m_Size.x / 2;
|
|
|
|
m_Size.x = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The inflate is valid.
|
|
|
|
m_Pos.x += dx;
|
|
|
|
m_Size.x -= 2 * dx; // m_Size.x <0: inflate when dx > 0
|
|
|
|
}
|
2007-08-04 20:05:54 +00:00
|
|
|
}
|
|
|
|
|
2008-03-18 11:53:52 +00:00
|
|
|
if( m_Size.y >= 0 )
|
2007-08-04 20:05:54 +00:00
|
|
|
{
|
2008-03-18 11:53:52 +00:00
|
|
|
if( m_Size.y < -2 * dy )
|
|
|
|
{
|
|
|
|
// Don't allow deflate to eat more height than we have,
|
|
|
|
m_Pos.y += m_Size.y / 2;
|
|
|
|
m_Size.y = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The inflate is valid.
|
|
|
|
m_Pos.y -= dy;
|
|
|
|
m_Size.y += 2 * dy;
|
|
|
|
}
|
2007-08-04 20:05:54 +00:00
|
|
|
}
|
2008-03-18 11:53:52 +00:00
|
|
|
else // size.y < 0:
|
2007-08-04 20:05:54 +00:00
|
|
|
{
|
2008-03-18 11:53:52 +00:00
|
|
|
if( m_Size.y > 2 * dy )
|
|
|
|
{
|
|
|
|
// Don't allow deflate to eat more height than we have,
|
|
|
|
m_Pos.y -= m_Size.y / 2;
|
|
|
|
m_Size.y = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The inflate is valid.
|
|
|
|
m_Pos.y += dy;
|
|
|
|
m_Size.y -= 2 * dy; // m_Size.y <0: inflate when dy > 0
|
|
|
|
}
|
2007-08-04 20:05:54 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
void EDA_RECT::Merge( const EDA_RECT& aRect )
|
2008-03-15 10:24:32 +00:00
|
|
|
{
|
|
|
|
Normalize(); // ensure width and height >= 0
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT rect = aRect;
|
2008-03-15 10:24:32 +00:00
|
|
|
rect.Normalize(); // ensure width and height >= 0
|
2009-04-29 12:10:15 +00:00
|
|
|
wxPoint end = GetEnd();
|
2008-03-18 11:53:52 +00:00
|
|
|
wxPoint rect_end = rect.GetEnd();
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2008-03-16 04:47:43 +00:00
|
|
|
// Change origin and size in order to contain the given rect
|
2012-09-22 11:19:37 +00:00
|
|
|
m_Pos.x = std::min( m_Pos.x, rect.m_Pos.x );
|
|
|
|
m_Pos.y = std::min( m_Pos.y, rect.m_Pos.y );
|
|
|
|
end.x = std::max( end.x, rect_end.x );
|
|
|
|
end.y = std::max( end.y, rect_end.y );
|
2008-03-15 10:24:32 +00:00
|
|
|
SetEnd( end );
|
|
|
|
}
|
2010-11-17 18:41:20 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
void EDA_RECT::Merge( const wxPoint& aPoint )
|
2010-11-17 18:41:20 +00:00
|
|
|
{
|
|
|
|
Normalize(); // ensure width and height >= 0
|
|
|
|
|
|
|
|
wxPoint end = GetEnd();
|
|
|
|
// Change origin and size in order to contain the given rect
|
2012-09-22 11:19:37 +00:00
|
|
|
m_Pos.x = std::min( m_Pos.x, aPoint.x );
|
|
|
|
m_Pos.y = std::min( m_Pos.y, aPoint.y );
|
|
|
|
end.x = std::max( end.x, aPoint.x );
|
|
|
|
end.y = std::max( end.y, aPoint.y );
|
2010-11-17 18:41:20 +00:00
|
|
|
SetEnd( end );
|
|
|
|
}
|
2011-03-25 19:16:05 +00:00
|
|
|
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
double EDA_RECT::GetArea() const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
|
|
|
return (double) GetWidth() * (double) GetHeight();
|
|
|
|
}
|
2013-11-05 17:12:27 +00:00
|
|
|
|
2015-07-30 11:49:35 +00:00
|
|
|
|
|
|
|
EDA_RECT EDA_RECT::Common( const EDA_RECT& aRect ) const
|
|
|
|
{
|
|
|
|
EDA_RECT r;
|
|
|
|
|
|
|
|
if( Intersects( aRect ) )
|
|
|
|
{
|
|
|
|
wxPoint originA( std::min( GetOrigin().x, GetEnd().x ),
|
|
|
|
std::min( GetOrigin().y, GetEnd().y ) );
|
|
|
|
wxPoint originB( std::min( aRect.GetOrigin().x, aRect.GetEnd().x ),
|
|
|
|
std::min( aRect.GetOrigin().y, aRect.GetEnd().y ) );
|
|
|
|
wxPoint endA( std::max( GetOrigin().x, GetEnd().x ),
|
|
|
|
std::max( GetOrigin().y, GetEnd().y ) );
|
|
|
|
wxPoint endB( std::max( aRect.GetOrigin().x, aRect.GetEnd().x ),
|
|
|
|
std::max( aRect.GetOrigin().y, aRect.GetEnd().y ) );
|
|
|
|
|
|
|
|
r.SetOrigin( wxPoint( std::max( originA.x, originB.x ), std::max( originA.y, originB.y ) ) );
|
|
|
|
r.SetEnd ( wxPoint( std::min( endA.x, endB.x ), std::min( endA.y, endB.y ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
const EDA_RECT EDA_RECT::GetBoundingBoxRotated( wxPoint aRotCenter, double aAngle )
|
2013-11-05 17:12:27 +00:00
|
|
|
{
|
|
|
|
wxPoint corners[4];
|
|
|
|
|
|
|
|
// Build the corners list
|
|
|
|
corners[0] = GetOrigin();
|
|
|
|
corners[2] = GetEnd();
|
|
|
|
corners[1].x = corners[0].x;
|
|
|
|
corners[1].y = corners[2].y;
|
|
|
|
corners[3].x = corners[2].x;
|
|
|
|
corners[3].y = corners[0].y;
|
|
|
|
|
|
|
|
// Rotate all corners, to find the bounding box
|
|
|
|
for( int ii = 0; ii < 4; ii ++ )
|
|
|
|
RotatePoint( &corners[ii], aRotCenter, aAngle );
|
|
|
|
|
|
|
|
// Find the corners bounding box
|
|
|
|
wxPoint start = corners[0];
|
|
|
|
wxPoint end = corners[0];
|
|
|
|
|
|
|
|
for( int ii = 1; ii < 4; ii ++ )
|
|
|
|
{
|
|
|
|
start.x = std::min( start.x, corners[ii].x);
|
|
|
|
start.y = std::min( start.y, corners[ii].y);
|
|
|
|
end.x = std::max( end.x, corners[ii].x);
|
|
|
|
end.y = std::max( end.y, corners[ii].y);
|
|
|
|
}
|
|
|
|
|
|
|
|
EDA_RECT bbox;
|
|
|
|
bbox.SetOrigin( start );
|
|
|
|
bbox.SetEnd( end );
|
|
|
|
|
|
|
|
return bbox;
|
|
|
|
}
|