KiCad PCB EDA Suite
base_struct.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
29 #include <deque>
30 
31 #include <fctsys.h>
32 #include <trigo.h>
33 #include <common.h>
34 #include <macros.h>
35 #include <base_screen.h>
36 #include <bitmaps.h>
37 #include <trace_helpers.h>
38 #include <eda_rect.h>
39 
40 
41 static const unsigned char dummy_png[] = {
42  0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
43  0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0xf3, 0xff,
44  0x61, 0x00, 0x00, 0x00, 0x5f, 0x49, 0x44, 0x41, 0x54, 0x38, 0xcb, 0x63, 0xf8, 0xff, 0xff, 0x3f,
45  0x03, 0x25, 0x98, 0x61, 0x68, 0x1a, 0x00, 0x04, 0x46, 0x40, 0xfc, 0x02, 0x88, 0x45, 0x41, 0x1c,
46  0x76, 0x20, 0xfe, 0x01, 0xc4, 0xbe, 0x24, 0x18, 0x60, 0x01, 0xc4, 0x20, 0x86, 0x04, 0x88, 0xc3,
47  0x01, 0xe5, 0x04, 0x0c, 0xb8, 0x01, 0x37, 0x81, 0xf8, 0x04, 0x91, 0xf8, 0x0a, 0x54, 0x8f, 0x06,
48  0xb2, 0x01, 0x9b, 0x81, 0x78, 0x02, 0x91, 0x78, 0x05, 0x54, 0x8f, 0xca, 0xe0, 0x08, 0x03, 0x36,
49  0xa8, 0xbf, 0xec, 0xc8, 0x32, 0x80, 0xcc, 0x84, 0x04, 0x0a, 0xbc, 0x1d, 0x40, 0x2c, 0xc8, 0x30,
50  0xf4, 0x33, 0x13, 0x00, 0x6b, 0x1a, 0x46, 0x7b, 0x68, 0xe7, 0x0f, 0x0b, 0x00, 0x00, 0x00, 0x00,
51  0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
52 };
53 
54 static const BITMAP_OPAQUE dummy_xpm[1] = {{ dummy_png, sizeof( dummy_png ), "dummy_xpm" }};
55 
56 
57 EDA_ITEM::EDA_ITEM( EDA_ITEM* parent, KICAD_T idType ) :
58  m_StructType( idType ),
59  m_Status( 0 ),
60  m_Parent( parent ),
61  m_forceVisible( false ),
62  m_Flags( 0 )
63 { }
64 
65 
67  m_StructType( idType ),
68  m_Status( 0 ),
69  m_Parent( nullptr ),
70  m_forceVisible( false ),
71  m_Flags( 0 )
72 { }
73 
74 
75 EDA_ITEM::EDA_ITEM( const EDA_ITEM& base ) :
76  m_Uuid( base.m_Uuid ),
77  m_StructType( base.m_StructType ),
78  m_Status( base.m_Status ),
79  m_Parent( base.m_Parent ),
80  m_forceVisible( base.m_forceVisible ),
81  m_Flags( base.m_Flags )
82 { }
83 
84 
86 {
88 
89  // If this a child object, then the parent modification state also needs to be set.
90  if( m_Parent )
92 }
93 
94 
96 {
97 #if defined(DEBUG)
98  printf( "Missing GetBoundingBox()\n" );
99  Show( 0, std::cout ); // tell me which classes still need GetBoundingBox support
100 #endif
101 
102  // return a zero-sized box per default. derived classes should override
103  // this
104  return EDA_RECT( wxPoint( 0, 0 ), wxSize( 0, 0 ) );
105 }
106 
107 
109 {
110  wxCHECK_MSG( false, NULL, wxT( "Clone not implemented in derived class " ) + GetClass() +
111  wxT( ". Bad programmer!" ) );
112 }
113 
114 
115 // see base_struct.h
116 // many classes inherit this method, be careful:
117 //TODO (snh): Fix this to use std::set instead of C-style vector
118 SEARCH_RESULT EDA_ITEM::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] )
119 {
120 #if 0 && defined(DEBUG)
121  std::cout << GetClass().mb_str() << ' ';
122 #endif
123 
124  if( IsType( scanTypes ) )
125  {
126  if( SEARCH_RESULT::QUIT == inspector( this, testData ) )
127  return SEARCH_RESULT::QUIT;
128  }
129 
131 }
132 
133 
134 wxString EDA_ITEM::GetSelectMenuText( EDA_UNITS aUnits ) const
135 {
136  wxFAIL_MSG( wxT( "GetSelectMenuText() was not overridden for schematic item type " ) +
137  GetClass() );
138 
139  return wxString( wxT( "Undefined menu text for " ) + GetClass() );
140 }
141 
142 
143 bool EDA_ITEM::Matches( const wxString& aText, wxFindReplaceData& aSearchData )
144 {
145  wxString text = aText;
146  wxString searchText = aSearchData.GetFindString();
147 
148  // Don't match if searching for replaceable item and the item doesn't support text replace.
149  if( (aSearchData.GetFlags() & FR_SEARCH_REPLACE) && !IsReplaceable() )
150  return false;
151 
152  if( aSearchData.GetFlags() & wxFR_WHOLEWORD )
153  return aText.IsSameAs( searchText, aSearchData.GetFlags() & wxFR_MATCHCASE );
154 
155  if( aSearchData.GetFlags() & FR_MATCH_WILDCARD )
156  {
157  if( aSearchData.GetFlags() & wxFR_MATCHCASE )
158  return text.Matches( searchText );
159 
160  return text.MakeUpper().Matches( searchText.MakeUpper() );
161  }
162 
163  if( aSearchData.GetFlags() & wxFR_MATCHCASE )
164  return aText.Find( searchText ) != wxNOT_FOUND;
165 
166  return text.MakeUpper().Find( searchText.MakeUpper() ) != wxNOT_FOUND;
167 }
168 
169 
170 bool EDA_ITEM::Replace( wxFindReplaceData& aSearchData, wxString& aText )
171 {
172  wxString searchString = (aSearchData.GetFlags() & wxFR_MATCHCASE) ? aText : aText.Upper();
173 
174  int result = searchString.Find( (aSearchData.GetFlags() & wxFR_MATCHCASE) ?
175  aSearchData.GetFindString() :
176  aSearchData.GetFindString().Upper() );
177 
178  if( result == wxNOT_FOUND )
179  return false;
180 
181  wxString prefix = aText.Left( result );
182  wxString suffix;
183 
184  if( aSearchData.GetFindString().length() + result < aText.length() )
185  suffix = aText.Right( aText.length() - ( aSearchData.GetFindString().length() + result ) );
186 
187  wxLogTrace( traceFindReplace, wxT( "Replacing '%s', prefix '%s', replace '%s', suffix '%s'." ),
188  GetChars( aText ), GetChars( prefix ), GetChars( aSearchData.GetReplaceString() ),
189  GetChars( suffix ) );
190 
191  aText = prefix + aSearchData.GetReplaceString() + suffix;
192 
193  return true;
194 }
195 
196 
197 bool EDA_ITEM::operator<( const EDA_ITEM& aItem ) const
198 {
199  wxFAIL_MSG( wxString::Format( wxT( "Less than operator not defined for item type %s." ),
200  GetChars( GetClass() ) ) );
201 
202  return false;
203 }
204 
206 {
207  // do not call initVars()
208 
209  m_StructType = aItem.m_StructType;
210  m_Flags = aItem.m_Flags;
211  m_Status = aItem.m_Status;
212  m_Parent = aItem.m_Parent;
214 
215  return *this;
216 }
217 
219 {
220  // Basic fallback
221  return BOX2I( VECTOR2I( GetBoundingBox().GetOrigin() ),
222  VECTOR2I( GetBoundingBox().GetSize() ) );
223 }
224 
225 
226 void EDA_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
227 {
228  // Basic fallback
229  aCount = 1;
230  aLayers[0] = 0;
231 }
232 
234 {
235  return dummy_xpm;
236 }
237 
238 #if defined(DEBUG)
239 
240 void EDA_ITEM::ShowDummy( std::ostream& os ) const
241 {
242  // XML output:
243  wxString s = GetClass();
244 
245  os << '<' << s.Lower().mb_str() << ">"
246  << " Need ::Show() override for this class "
247  << "</" << s.Lower().mb_str() << ">\n";
248 }
249 
250 
251 std::ostream& EDA_ITEM::NestedSpace( int nestLevel, std::ostream& os )
252 {
253  for( int i = 0; i<nestLevel; ++i )
254  os << " ";
255 
256  // number of spaces here controls indent per nest level
257 
258  return os;
259 }
260 
261 #endif
262 
263 
264 /******************/
265 /* Class EDA_RECT */
266 /******************/
267 
269 {
270  if( m_Size.y < 0 )
271  {
272  m_Size.y = -m_Size.y;
273  m_Pos.y -= m_Size.y;
274  }
275 
276  if( m_Size.x < 0 )
277  {
278  m_Size.x = -m_Size.x;
279  m_Pos.x -= m_Size.x;
280  }
281 }
282 
283 
284 void EDA_RECT::Move( const wxPoint& aMoveVector )
285 {
286  m_Pos += aMoveVector;
287 }
288 
289 
290 bool EDA_RECT::Contains( const wxPoint& aPoint ) const
291 {
292  wxPoint rel_pos = aPoint - m_Pos;
293  wxSize size = m_Size;
294 
295  if( size.x < 0 )
296  {
297  size.x = -size.x;
298  rel_pos.x += size.x;
299  }
300 
301  if( size.y < 0 )
302  {
303  size.y = -size.y;
304  rel_pos.y += size.y;
305  }
306 
307  return (rel_pos.x >= 0) && (rel_pos.y >= 0) && ( rel_pos.y <= size.y) && ( rel_pos.x <= size.x);
308 }
309 
310 
311 bool EDA_RECT::Contains( const EDA_RECT& aRect ) const
312 {
313  return Contains( aRect.GetOrigin() ) && Contains( aRect.GetEnd() );
314 }
315 
316 
317 bool EDA_RECT::Intersects( const wxPoint& aPoint1, const wxPoint& aPoint2 ) const
318 {
319  wxPoint point2, point4;
320 
321  if( Contains( aPoint1 ) || Contains( aPoint2 ) )
322  return true;
323 
324  point2.x = GetEnd().x;
325  point2.y = GetOrigin().y;
326  point4.x = GetOrigin().x;
327  point4.y = GetEnd().y;
328 
329  //Only need to test 3 sides since a straight line cant enter and exit on same side
330  if( SegmentIntersectsSegment( aPoint1, aPoint2, GetOrigin() , point2 ) )
331  return true;
332 
333  if( SegmentIntersectsSegment( aPoint1, aPoint2, point2 , GetEnd() ) )
334  return true;
335 
336  if( SegmentIntersectsSegment( aPoint1, aPoint2, GetEnd() , point4 ) )
337  return true;
338 
339  return false;
340 }
341 
342 
343 bool EDA_RECT::Intersects( const EDA_RECT& aRect ) const
344 {
345  if( !m_init )
346  return false;
347 
348  // this logic taken from wxWidgets' geometry.cpp file:
349  bool rc;
350  EDA_RECT me(*this);
351  EDA_RECT rect(aRect);
352  me.Normalize(); // ensure size is >= 0
353  rect.Normalize(); // ensure size is >= 0
354 
355  // calculate the left common area coordinate:
356  int left = std::max( me.m_Pos.x, rect.m_Pos.x );
357  // calculate the right common area coordinate:
358  int right = std::min( me.m_Pos.x + me.m_Size.x, rect.m_Pos.x + rect.m_Size.x );
359  // calculate the upper common area coordinate:
360  int top = std::max( me.m_Pos.y, aRect.m_Pos.y );
361  // calculate the lower common area coordinate:
362  int bottom = std::min( me.m_Pos.y + me.m_Size.y, rect.m_Pos.y + rect.m_Size.y );
363 
364  // if a common area exists, it must have a positive (null accepted) size
365  if( left <= right && top <= bottom )
366  rc = true;
367  else
368  rc = false;
369 
370  return rc;
371 }
372 
373 
374 bool EDA_RECT::Intersects( const EDA_RECT& aRect, double aRot ) const
375 {
376  if( !m_init )
377  return false;
378 
379  /* Most rectangles will be axis aligned.
380  * It is quicker to check for this case and pass the rect
381  * to the simpler intersection test
382  */
383 
384  // Prevent floating point comparison errors
385  static const double ROT_EPS = 0.000000001;
386 
387  static const double ROT_PARALLEL[] = { -3600, -1800, 0, 1800, 3600 };
388  static const double ROT_PERPENDICULAR[] = { -2700, -900, 0, 900, 2700 };
389 
390  NORMALIZE_ANGLE_POS<double>( aRot );
391 
392  // Test for non-rotated rectangle
393  for( int ii = 0; ii < 5; ii++ )
394  {
395  if( std::fabs( aRot - ROT_PARALLEL[ii] ) < ROT_EPS )
396  {
397  return Intersects( aRect );
398  }
399  }
400 
401  // Test for rectangle rotated by multiple of 90 degrees
402  for( int jj = 0; jj < 4; jj++ )
403  {
404  if( std::fabs( aRot - ROT_PERPENDICULAR[jj] ) < ROT_EPS )
405  {
406  EDA_RECT rotRect;
407 
408  // Rotate the supplied rect by 90 degrees
409  rotRect.SetOrigin( aRect.Centre() );
410  rotRect.Inflate( aRect.GetHeight(), aRect.GetWidth() );
411  return Intersects( rotRect );
412  }
413  }
414 
415  /* There is some non-orthogonal rotation.
416  * There are three cases to test:
417  * A) One point of this rect is inside the rotated rect
418  * B) One point of the rotated rect is inside this rect
419  * C) One of the sides of the rotated rect intersect this
420  */
421 
422  wxPoint corners[4];
423 
424  /* Test A : Any corners exist in rotated rect? */
425 
426  corners[0] = m_Pos;
427  corners[1] = m_Pos + wxPoint( m_Size.x, 0 );
428  corners[2] = m_Pos + wxPoint( m_Size.x, m_Size.y );
429  corners[3] = m_Pos + wxPoint( 0, m_Size.y );
430 
431  wxPoint rCentre = aRect.Centre();
432 
433  for( int i = 0; i < 4; i++ )
434  {
435  wxPoint delta = corners[i] - rCentre;
436  RotatePoint( &delta, -aRot );
437  delta += rCentre;
438 
439  if( aRect.Contains( delta ) )
440  {
441  return true;
442  }
443  }
444 
445  /* Test B : Any corners of rotated rect exist in this one? */
446  int w = aRect.GetWidth() / 2;
447  int h = aRect.GetHeight() / 2;
448 
449  // Construct corners around center of shape
450  corners[0] = wxPoint( -w, -h );
451  corners[1] = wxPoint( w, -h );
452  corners[2] = wxPoint( w, h );
453  corners[3] = wxPoint( -w, h );
454 
455  // Rotate and test each corner
456  for( int j=0; j<4; j++ )
457  {
458  RotatePoint( &corners[j], aRot );
459  corners[j] += rCentre;
460 
461  if( Contains( corners[j] ) )
462  {
463  return true;
464  }
465  }
466 
467  /* Test C : Any sides of rotated rect intersect this */
468 
469  if( Intersects( corners[0], corners[1] ) ||
470  Intersects( corners[1], corners[2] ) ||
471  Intersects( corners[2], corners[3] ) ||
472  Intersects( corners[3], corners[0] ) )
473  {
474  return true;
475  }
476 
477 
478  return false;
479 }
480 
481 
482 const wxPoint EDA_RECT::ClosestPointTo( const wxPoint& aPoint ) const
483 {
484  EDA_RECT me( *this );
485 
486  me.Normalize(); // ensure size is >= 0
487 
488  // Determine closest point to the circle centre within this rect
489  int nx = std::max( me.GetLeft(), std::min( aPoint.x, me.GetRight() ) );
490  int ny = std::max( me.GetTop(), std::min( aPoint.y, me.GetBottom() ) );
491 
492  return wxPoint( nx, ny );
493 }
494 
495 
496 const wxPoint EDA_RECT::FarthestPointTo( const wxPoint& aPoint ) const
497 {
498  EDA_RECT me( *this );
499 
500  me.Normalize(); // ensure size is >= 0
501 
502  int fx = std::max( std::abs( aPoint.x - me.GetLeft() ), std::abs( aPoint.x - me.GetRight() ) );
503  int fy = std::max( std::abs( aPoint.y - me.GetTop() ), std::abs( aPoint.y - me.GetBottom() ) );
504 
505  return wxPoint( fx, fy );
506 }
507 
508 
509 bool EDA_RECT::IntersectsCircle( const wxPoint& aCenter, const int aRadius ) const
510 {
511  if( !m_init )
512  return false;
513 
514  wxPoint closest = ClosestPointTo( aCenter );
515 
516  double dx = aCenter.x - closest.x;
517  double dy = aCenter.y - closest.y;
518 
519  double r = (double) aRadius;
520 
521  return ( dx * dx + dy * dy ) <= ( r * r );
522 }
523 
524 
525 bool EDA_RECT::IntersectsCircleEdge( const wxPoint& aCenter, const int aRadius, const int aWidth ) const
526 {
527  if( !m_init )
528  return false;
529 
530  EDA_RECT me( *this );
531  me.Normalize(); // ensure size is >= 0
532 
533  // Test if the circle intersects at all
534  if( !IntersectsCircle( aCenter, aRadius + aWidth / 2 ) )
535  {
536  return false;
537  }
538 
539  wxPoint farpt = FarthestPointTo( aCenter );
540  // Farthest point must be further than the inside of the line
541  double fx = (double) farpt.x;
542  double fy = (double) farpt.y;
543 
544  double r = (double) aRadius - (double) aWidth / 2;
545 
546  return ( fx * fx + fy * fy ) > ( r * r );
547 }
548 
549 
551 {
552  Inflate( aDelta, aDelta );
553  return *this;
554 }
555 
556 
557 EDA_RECT& EDA_RECT::Inflate( wxCoord dx, wxCoord dy )
558 {
559  if( m_Size.x >= 0 )
560  {
561  if( m_Size.x < -2 * dx )
562  {
563  // Don't allow deflate to eat more width than we have,
564  m_Pos.x += m_Size.x / 2;
565  m_Size.x = 0;
566  }
567  else
568  {
569  // The inflate is valid.
570  m_Pos.x -= dx;
571  m_Size.x += 2 * dx;
572  }
573  }
574  else // size.x < 0:
575  {
576  if( m_Size.x > -2 * dx )
577  {
578  // Don't allow deflate to eat more width than we have,
579  m_Pos.x -= m_Size.x / 2;
580  m_Size.x = 0;
581  }
582  else
583  {
584  // The inflate is valid.
585  m_Pos.x += dx;
586  m_Size.x -= 2 * dx; // m_Size.x <0: inflate when dx > 0
587  }
588  }
589 
590  if( m_Size.y >= 0 )
591  {
592  if( m_Size.y < -2 * dy )
593  {
594  // Don't allow deflate to eat more height than we have,
595  m_Pos.y += m_Size.y / 2;
596  m_Size.y = 0;
597  }
598  else
599  {
600  // The inflate is valid.
601  m_Pos.y -= dy;
602  m_Size.y += 2 * dy;
603  }
604  }
605  else // size.y < 0:
606  {
607  if( m_Size.y > 2 * dy )
608  {
609  // Don't allow deflate to eat more height than we have,
610  m_Pos.y -= m_Size.y / 2;
611  m_Size.y = 0;
612  }
613  else
614  {
615  // The inflate is valid.
616  m_Pos.y += dy;
617  m_Size.y -= 2 * dy; // m_Size.y <0: inflate when dy > 0
618  }
619  }
620 
621  return *this;
622 }
623 
624 
625 void EDA_RECT::Merge( const EDA_RECT& aRect )
626 {
627  if( !m_init )
628  {
629  if( aRect.IsValid() )
630  {
631  m_Pos = aRect.GetPosition();
632  m_Size = aRect.GetSize();
633  m_init = true;
634  }
635  return;
636  }
637 
638  Normalize(); // ensure width and height >= 0
639  EDA_RECT rect = aRect;
640  rect.Normalize(); // ensure width and height >= 0
641  wxPoint end = GetEnd();
642  wxPoint rect_end = rect.GetEnd();
643 
644  // Change origin and size in order to contain the given rect
645  m_Pos.x = std::min( m_Pos.x, rect.m_Pos.x );
646  m_Pos.y = std::min( m_Pos.y, rect.m_Pos.y );
647  end.x = std::max( end.x, rect_end.x );
648  end.y = std::max( end.y, rect_end.y );
649  SetEnd( end );
650 }
651 
652 
653 void EDA_RECT::Merge( const wxPoint& aPoint )
654 {
655  if( !m_init )
656  {
657  m_Pos = aPoint;
658  m_Size = wxSize( 0, 0 );
659  m_init = true;
660  return;
661  }
662 
663  Normalize(); // ensure width and height >= 0
664 
665  wxPoint end = GetEnd();
666  // Change origin and size in order to contain the given rect
667  m_Pos.x = std::min( m_Pos.x, aPoint.x );
668  m_Pos.y = std::min( m_Pos.y, aPoint.y );
669  end.x = std::max( end.x, aPoint.x );
670  end.y = std::max( end.y, aPoint.y );
671  SetEnd( end );
672 }
673 
674 
675 double EDA_RECT::GetArea() const
676 {
677  return (double) GetWidth() * (double) GetHeight();
678 }
679 
680 
681 EDA_RECT EDA_RECT::Common( const EDA_RECT& aRect ) const
682 {
683  EDA_RECT r;
684 
685  if( Intersects( aRect ) )
686  {
687  wxPoint originA( std::min( GetOrigin().x, GetEnd().x ),
688  std::min( GetOrigin().y, GetEnd().y ) );
689  wxPoint originB( std::min( aRect.GetOrigin().x, aRect.GetEnd().x ),
690  std::min( aRect.GetOrigin().y, aRect.GetEnd().y ) );
691  wxPoint endA( std::max( GetOrigin().x, GetEnd().x ),
692  std::max( GetOrigin().y, GetEnd().y ) );
693  wxPoint endB( std::max( aRect.GetOrigin().x, aRect.GetEnd().x ),
694  std::max( aRect.GetOrigin().y, aRect.GetEnd().y ) );
695 
696  r.SetOrigin( wxPoint( std::max( originA.x, originB.x ), std::max( originA.y, originB.y ) ) );
697  r.SetEnd ( wxPoint( std::min( endA.x, endB.x ), std::min( endA.y, endB.y ) ) );
698  }
699 
700  return r;
701 }
702 
703 
704 const EDA_RECT EDA_RECT::GetBoundingBoxRotated( wxPoint aRotCenter, double aAngle )
705 {
706  wxPoint corners[4];
707 
708  // Build the corners list
709  corners[0] = GetOrigin();
710  corners[2] = GetEnd();
711  corners[1].x = corners[0].x;
712  corners[1].y = corners[2].y;
713  corners[3].x = corners[2].x;
714  corners[3].y = corners[0].y;
715 
716  // Rotate all corners, to find the bounding box
717  for( int ii = 0; ii < 4; ii ++ )
718  RotatePoint( &corners[ii], aRotCenter, aAngle );
719 
720  // Find the corners bounding box
721  wxPoint start = corners[0];
722  wxPoint end = corners[0];
723 
724  for( int ii = 1; ii < 4; ii ++ )
725  {
726  start.x = std::min( start.x, corners[ii].x);
727  start.y = std::min( start.y, corners[ii].y);
728  end.x = std::max( end.x, corners[ii].x);
729  end.y = std::max( end.y, corners[ii].y);
730  }
731 
732  EDA_RECT bbox;
733  bbox.SetOrigin( start );
734  bbox.SetEnd( end );
735 
736  return bbox;
737 }
EDA_UNITS
Definition: common.h:198
void SetModified()
Definition: base_struct.cpp:85
virtual SEARCH_RESULT Visit(INSPECTOR inspector, void *testData, const KICAD_T scanTypes[])
Function Visit may be re-implemented for each derived class in order to handle all the types given by...
BOX2< VECTOR2I > BOX2I
Definition: box2.h:521
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:174
void Move(const wxPoint &aMoveVector)
Function Move moves the rectangle by the aMoveVector.
bool operator<(const EDA_ITEM &aItem) const
Test if another item is less than this object.
const wxChar *const traceFindReplace
Flag to enable find and replace debug tracing.
void Merge(const EDA_RECT &aRect)
Function Merge modifies the position and size of the rectangle in order to contain aRect.
PNG memory record (file in memory).
Definition: bitmap_def.h:29
KICAD_T m_StructType
Run time identification, keep private so it can never be changed after a constructor sets it.
Definition: base_struct.h:170
static bool Replace(wxFindReplaceData &aSearchData, wxString &aText)
Helper function used in search and replace dialog Function Replace performs a text replace on aText u...
int GetTop() const
Definition: eda_rect.h:123
int GetLeft() const
Definition: eda_rect.h:122
int GetWidth() const
Definition: eda_rect.h:119
bool IntersectsCircle(const wxPoint &aCenter, const int aRadius) const
Function IntersectsCircle tests for a common area between a circle and this rectangle.
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:131
bool IntersectsCircleEdge(const wxPoint &aCenter, const int aRadius, const int aWidth) const
IntersectsCircleEdge Tests for intersection between this rect and the edge (radius) of a circle.
EDA_RECT Common(const EDA_RECT &aRect) const
Function Common returns the area that is common with another rectangle.
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
bool Contains(const wxPoint &aPoint) const
Function Contains.
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
This file contains miscellaneous commonly used macros and functions.
int GetBottom() const
Definition: eda_rect.h:124
bool SegmentIntersectsSegment(const wxPoint &a_p1_l1, const wxPoint &a_p2_l1, const wxPoint &a_p1_l2, const wxPoint &a_p2_l2, wxPoint *aIntersectionPoint=nullptr)
Test if two lines intersect.
Definition: trigo.cpp:61
const INSPECTOR_FUNC & INSPECTOR
Definition: base_struct.h:105
const wxPoint GetEnd() const
Definition: eda_rect.h:116
#define IS_CHANGED
std::function passed to nested users by ref, avoids copying std::function
Definition: base_struct.h:113
wxSize m_Size
Definition: eda_rect.h:48
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:232
#define NULL
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on.
const wxPoint GetOrigin() const
Definition: eda_rect.h:114
void SetEnd(int x, int y)
Definition: eda_rect.h:192
STATUS_FLAGS m_Status
Definition: base_struct.h:173
const wxPoint GetPosition() const
Definition: eda_rect.h:115
const EDA_RECT GetBoundingBoxRotated(wxPoint aRotCenter, double aAngle)
Function GetBoundingBoxRotated.
const wxPoint FarthestPointTo(const wxPoint &aPoint) const
Return the point in this rect that is farthest from the provided point.
int GetRight() const
Definition: eda_rect.h:121
wxLogTrace helper definitions.
virtual bool IsType(const KICAD_T aScanTypes[]) const
Function IsType Checks whether the item is one of the listed types.
Definition: base_struct.h:262
double GetArea() const
Function GetArea returns the area of the rectangle.
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Operator assignment is used to assign the members of aItem to another object.
int GetHeight() const
Definition: eda_rect.h:120
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType)
Definition: base_struct.cpp:57
void Normalize()
Function Normalize ensures that the height ant width are positive.
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:153
virtual wxString GetClass() const =0
Function GetClass returns the class name.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
bool m_init
Definition: eda_rect.h:49
virtual wxString GetSelectMenuText(EDA_UNITS aUnits) const
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
STATUS_FLAGS m_Flags
Definition: base_struct.h:176
virtual bool IsReplaceable() const
Function IsReplaceable.
Definition: base_struct.h:501
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
wxPoint m_Pos
Definition: eda_rect.h:47
static const BITMAP_OPAQUE dummy_xpm[1]
Definition: base_struct.cpp:54
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
The common library.
wxPoint Centre() const
Definition: eda_rect.h:62
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.
virtual const EDA_RECT GetBoundingBox() const
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: base_struct.cpp:95
bool IsValid() const
Definition: eda_rect.h:126
static const unsigned char dummy_png[]
Implementation of EDA_ITEM base class for KiCad.
Definition: base_struct.cpp:41
SEARCH_RESULT
Definition: base_struct.h:51
BASE_SCREEN class implementation.
virtual const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers.
bool m_forceVisible
Definition: base_struct.h:175
virtual BITMAP_DEF GetMenuImage() const
Function GetMenuImage returns a pointer to an image to be used in menus.
virtual bool Matches(wxFindReplaceData &aSearchData, void *aAuxData)
Function Matches compares the item against the search criteria in aSearchData.
Definition: base_struct.h:457
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
const wxSize GetSize() const
Definition: eda_rect.h:103
const wxPoint ClosestPointTo(const wxPoint &aPoint) const
Return the point in this rect that is closest to the provided point.