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 enum textbox {
59 };
60 
61 
63 {
64  initVars();
65  m_StructType = idType;
66  m_Parent = parent;
67 }
68 
69 
71 {
72  initVars();
73  m_StructType = idType;
74 }
75 
76 
78 {
79  initVars();
80  *this = base;
81 }
82 
83 
85 {
87  m_Parent = NULL; // Linked list: Link (parent struct)
88  m_Flags = 0; // flags for editions and other
89  m_Status = 0;
90  m_forceVisible = false; // true to override the visibility setting of the item.
91 }
92 
93 
95 {
97 
98  // If this a child object, then the parent modification state also needs to be set.
99  if( m_Parent )
101 }
102 
103 
105 {
106 #if defined(DEBUG)
107  printf( "Missing GetBoundingBox()\n" );
108  Show( 0, std::cout ); // tell me which classes still need GetBoundingBox support
109 #endif
110 
111  // return a zero-sized box per default. derived classes should override
112  // this
113  return EDA_RECT( wxPoint( 0, 0 ), wxSize( 0, 0 ) );
114 }
115 
116 
118 {
119  wxCHECK_MSG( false, NULL, wxT( "Clone not implemented in derived class " ) + GetClass() +
120  wxT( ". Bad programmer!" ) );
121 }
122 
123 
124 // see base_struct.h
125 // many classes inherit this method, be careful:
126 //TODO (snh): Fix this to use std::set instead of C-style vector
127 SEARCH_RESULT EDA_ITEM::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] )
128 {
129 #if 0 && defined(DEBUG)
130  std::cout << GetClass().mb_str() << ' ';
131 #endif
132 
133  if( IsType( scanTypes ) )
134  {
135  if( SEARCH_RESULT::QUIT == inspector( this, testData ) )
136  return SEARCH_RESULT::QUIT;
137  }
138 
140 }
141 
142 
143 wxString EDA_ITEM::GetSelectMenuText( EDA_UNITS aUnits ) const
144 {
145  wxFAIL_MSG( wxT( "GetSelectMenuText() was not overridden for schematic item type " ) +
146  GetClass() );
147 
148  return wxString( wxT( "Undefined menu text for " ) + GetClass() );
149 }
150 
151 
152 bool EDA_ITEM::Matches( const wxString& aText, wxFindReplaceData& aSearchData )
153 {
154  wxString text = aText;
155  wxString searchText = aSearchData.GetFindString();
156 
157  // Don't match if searching for replaceable item and the item doesn't support text replace.
158  if( (aSearchData.GetFlags() & FR_SEARCH_REPLACE) && !IsReplaceable() )
159  return false;
160 
161  if( aSearchData.GetFlags() & wxFR_WHOLEWORD )
162  return aText.IsSameAs( searchText, aSearchData.GetFlags() & wxFR_MATCHCASE );
163 
164  if( aSearchData.GetFlags() & FR_MATCH_WILDCARD )
165  {
166  if( aSearchData.GetFlags() & wxFR_MATCHCASE )
167  return text.Matches( searchText );
168 
169  return text.MakeUpper().Matches( searchText.MakeUpper() );
170  }
171 
172  if( aSearchData.GetFlags() & wxFR_MATCHCASE )
173  return aText.Find( searchText ) != wxNOT_FOUND;
174 
175  return text.MakeUpper().Find( searchText.MakeUpper() ) != wxNOT_FOUND;
176 }
177 
178 
179 bool EDA_ITEM::Replace( wxFindReplaceData& aSearchData, wxString& aText )
180 {
181  wxString searchString = (aSearchData.GetFlags() & wxFR_MATCHCASE) ? aText : aText.Upper();
182 
183  int result = searchString.Find( (aSearchData.GetFlags() & wxFR_MATCHCASE) ?
184  aSearchData.GetFindString() :
185  aSearchData.GetFindString().Upper() );
186 
187  if( result == wxNOT_FOUND )
188  return false;
189 
190  wxString prefix = aText.Left( result );
191  wxString suffix;
192 
193  if( aSearchData.GetFindString().length() + result < aText.length() )
194  suffix = aText.Right( aText.length() - ( aSearchData.GetFindString().length() + result ) );
195 
196  wxLogTrace( traceFindReplace, wxT( "Replacing '%s', prefix '%s', replace '%s', suffix '%s'." ),
197  GetChars( aText ), GetChars( prefix ), GetChars( aSearchData.GetReplaceString() ),
198  GetChars( suffix ) );
199 
200  aText = prefix + aSearchData.GetReplaceString() + suffix;
201 
202  return true;
203 }
204 
205 
206 bool EDA_ITEM::operator<( const EDA_ITEM& aItem ) const
207 {
208  wxFAIL_MSG( wxString::Format( wxT( "Less than operator not defined for item type %s." ),
209  GetChars( GetClass() ) ) );
210 
211  return false;
212 }
213 
215 {
216  // do not call initVars()
217 
218  m_StructType = aItem.m_StructType;
219  m_Flags = aItem.m_Flags;
220  m_Status = aItem.m_Status;
221  m_Parent = aItem.m_Parent;
223 
224  return *this;
225 }
226 
228 {
229  // Basic fallback
230  return BOX2I( VECTOR2I( GetBoundingBox().GetOrigin() ),
231  VECTOR2I( GetBoundingBox().GetSize() ) );
232 }
233 
234 
235 void EDA_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
236 {
237  // Basic fallback
238  aCount = 1;
239  aLayers[0] = 0;
240 }
241 
243 {
244  return dummy_xpm;
245 }
246 
247 #if defined(DEBUG)
248 
249 void EDA_ITEM::ShowDummy( std::ostream& os ) const
250 {
251  // XML output:
252  wxString s = GetClass();
253 
254  os << '<' << s.Lower().mb_str() << ">"
255  << " Need ::Show() override for this class "
256  << "</" << s.Lower().mb_str() << ">\n";
257 }
258 
259 
260 std::ostream& EDA_ITEM::NestedSpace( int nestLevel, std::ostream& os )
261 {
262  for( int i = 0; i<nestLevel; ++i )
263  os << " ";
264 
265  // number of spaces here controls indent per nest level
266 
267  return os;
268 }
269 
270 #endif
271 
272 
273 /******************/
274 /* Class EDA_RECT */
275 /******************/
276 
278 {
279  if( m_Size.y < 0 )
280  {
281  m_Size.y = -m_Size.y;
282  m_Pos.y -= m_Size.y;
283  }
284 
285  if( m_Size.x < 0 )
286  {
287  m_Size.x = -m_Size.x;
288  m_Pos.x -= m_Size.x;
289  }
290 }
291 
292 
293 void EDA_RECT::Move( const wxPoint& aMoveVector )
294 {
295  m_Pos += aMoveVector;
296 }
297 
298 
299 bool EDA_RECT::Contains( const wxPoint& aPoint ) const
300 {
301  wxPoint rel_pos = aPoint - m_Pos;
302  wxSize size = m_Size;
303 
304  if( size.x < 0 )
305  {
306  size.x = -size.x;
307  rel_pos.x += size.x;
308  }
309 
310  if( size.y < 0 )
311  {
312  size.y = -size.y;
313  rel_pos.y += size.y;
314  }
315 
316  return (rel_pos.x >= 0) && (rel_pos.y >= 0) && ( rel_pos.y <= size.y) && ( rel_pos.x <= size.x);
317 }
318 
319 
320 bool EDA_RECT::Contains( const EDA_RECT& aRect ) const
321 {
322  return Contains( aRect.GetOrigin() ) && Contains( aRect.GetEnd() );
323 }
324 
325 
326 bool EDA_RECT::Intersects( const wxPoint& aPoint1, const wxPoint& aPoint2 ) const
327 {
328  wxPoint point2, point4;
329 
330  if( Contains( aPoint1 ) || Contains( aPoint2 ) )
331  return true;
332 
333  point2.x = GetEnd().x;
334  point2.y = GetOrigin().y;
335  point4.x = GetOrigin().x;
336  point4.y = GetEnd().y;
337 
338  //Only need to test 3 sides since a straight line cant enter and exit on same side
339  if( SegmentIntersectsSegment( aPoint1, aPoint2, GetOrigin() , point2 ) )
340  return true;
341 
342  if( SegmentIntersectsSegment( aPoint1, aPoint2, point2 , GetEnd() ) )
343  return true;
344 
345  if( SegmentIntersectsSegment( aPoint1, aPoint2, GetEnd() , point4 ) )
346  return true;
347 
348  return false;
349 }
350 
351 
352 bool EDA_RECT::Intersects( const EDA_RECT& aRect ) const
353 {
354  if( !m_init )
355  return false;
356 
357  // this logic taken from wxWidgets' geometry.cpp file:
358  bool rc;
359  EDA_RECT me(*this);
360  EDA_RECT rect(aRect);
361  me.Normalize(); // ensure size is >= 0
362  rect.Normalize(); // ensure size is >= 0
363 
364  // calculate the left common area coordinate:
365  int left = std::max( me.m_Pos.x, rect.m_Pos.x );
366  // calculate the right common area coordinate:
367  int right = std::min( me.m_Pos.x + me.m_Size.x, rect.m_Pos.x + rect.m_Size.x );
368  // calculate the upper common area coordinate:
369  int top = std::max( me.m_Pos.y, aRect.m_Pos.y );
370  // calculate the lower common area coordinate:
371  int bottom = std::min( me.m_Pos.y + me.m_Size.y, rect.m_Pos.y + rect.m_Size.y );
372 
373  // if a common area exists, it must have a positive (null accepted) size
374  if( left <= right && top <= bottom )
375  rc = true;
376  else
377  rc = false;
378 
379  return rc;
380 }
381 
382 
383 bool EDA_RECT::Intersects( const EDA_RECT& aRect, double aRot ) const
384 {
385  if( !m_init )
386  return false;
387 
388  /* Most rectangles will be axis aligned.
389  * It is quicker to check for this case and pass the rect
390  * to the simpler intersection test
391  */
392 
393  // Prevent floating point comparison errors
394  static const double ROT_EPS = 0.000000001;
395 
396  static const double ROT_PARALLEL[] = { -3600, -1800, 0, 1800, 3600 };
397  static const double ROT_PERPENDICULAR[] = { -2700, -900, 0, 900, 2700 };
398 
399  NORMALIZE_ANGLE_POS<double>( aRot );
400 
401  // Test for non-rotated rectangle
402  for( int ii = 0; ii < 5; ii++ )
403  {
404  if( std::fabs( aRot - ROT_PARALLEL[ii] ) < ROT_EPS )
405  {
406  return Intersects( aRect );
407  }
408  }
409 
410  // Test for rectangle rotated by multiple of 90 degrees
411  for( int jj = 0; jj < 4; jj++ )
412  {
413  if( std::fabs( aRot - ROT_PERPENDICULAR[jj] ) < ROT_EPS )
414  {
415  EDA_RECT rotRect;
416 
417  // Rotate the supplied rect by 90 degrees
418  rotRect.SetOrigin( aRect.Centre() );
419  rotRect.Inflate( aRect.GetHeight(), aRect.GetWidth() );
420  return Intersects( rotRect );
421  }
422  }
423 
424  /* There is some non-orthogonal rotation.
425  * There are three cases to test:
426  * A) One point of this rect is inside the rotated rect
427  * B) One point of the rotated rect is inside this rect
428  * C) One of the sides of the rotated rect intersect this
429  */
430 
431  wxPoint corners[4];
432 
433  /* Test A : Any corners exist in rotated rect? */
434 
435  corners[0] = m_Pos;
436  corners[1] = m_Pos + wxPoint( m_Size.x, 0 );
437  corners[2] = m_Pos + wxPoint( m_Size.x, m_Size.y );
438  corners[3] = m_Pos + wxPoint( 0, m_Size.y );
439 
440  wxPoint rCentre = aRect.Centre();
441 
442  for( int i = 0; i < 4; i++ )
443  {
444  wxPoint delta = corners[i] - rCentre;
445  RotatePoint( &delta, -aRot );
446  delta += rCentre;
447 
448  if( aRect.Contains( delta ) )
449  {
450  return true;
451  }
452  }
453 
454  /* Test B : Any corners of rotated rect exist in this one? */
455  int w = aRect.GetWidth() / 2;
456  int h = aRect.GetHeight() / 2;
457 
458  // Construct corners around center of shape
459  corners[0] = wxPoint( -w, -h );
460  corners[1] = wxPoint( w, -h );
461  corners[2] = wxPoint( w, h );
462  corners[3] = wxPoint( -w, h );
463 
464  // Rotate and test each corner
465  for( int j=0; j<4; j++ )
466  {
467  RotatePoint( &corners[j], aRot );
468  corners[j] += rCentre;
469 
470  if( Contains( corners[j] ) )
471  {
472  return true;
473  }
474  }
475 
476  /* Test C : Any sides of rotated rect intersect this */
477 
478  if( Intersects( corners[0], corners[1] ) ||
479  Intersects( corners[1], corners[2] ) ||
480  Intersects( corners[2], corners[3] ) ||
481  Intersects( corners[3], corners[0] ) )
482  {
483  return true;
484  }
485 
486 
487  return false;
488 }
489 
490 
491 const wxPoint EDA_RECT::ClosestPointTo( const wxPoint& aPoint ) const
492 {
493  EDA_RECT me( *this );
494 
495  me.Normalize(); // ensure size is >= 0
496 
497  // Determine closest point to the circle centre within this rect
498  int nx = std::max( me.GetLeft(), std::min( aPoint.x, me.GetRight() ) );
499  int ny = std::max( me.GetTop(), std::min( aPoint.y, me.GetBottom() ) );
500 
501  return wxPoint( nx, ny );
502 }
503 
504 
505 const wxPoint EDA_RECT::FarthestPointTo( const wxPoint& aPoint ) const
506 {
507  EDA_RECT me( *this );
508 
509  me.Normalize(); // ensure size is >= 0
510 
511  int fx = std::max( std::abs( aPoint.x - me.GetLeft() ), std::abs( aPoint.x - me.GetRight() ) );
512  int fy = std::max( std::abs( aPoint.y - me.GetTop() ), std::abs( aPoint.y - me.GetBottom() ) );
513 
514  return wxPoint( fx, fy );
515 }
516 
517 
518 bool EDA_RECT::IntersectsCircle( const wxPoint& aCenter, const int aRadius ) const
519 {
520  if( !m_init )
521  return false;
522 
523  wxPoint closest = ClosestPointTo( aCenter );
524 
525  double dx = aCenter.x - closest.x;
526  double dy = aCenter.y - closest.y;
527 
528  double r = (double) aRadius;
529 
530  return ( dx * dx + dy * dy ) <= ( r * r );
531 }
532 
533 
534 bool EDA_RECT::IntersectsCircleEdge( const wxPoint& aCenter, const int aRadius, const int aWidth ) const
535 {
536  if( !m_init )
537  return false;
538 
539  EDA_RECT me( *this );
540  me.Normalize(); // ensure size is >= 0
541 
542  // Test if the circle intersects at all
543  if( !IntersectsCircle( aCenter, aRadius + aWidth / 2 ) )
544  {
545  return false;
546  }
547 
548  wxPoint farpt = FarthestPointTo( aCenter );
549  // Farthest point must be further than the inside of the line
550  double fx = (double) farpt.x;
551  double fy = (double) farpt.y;
552 
553  double r = (double) aRadius - (double) aWidth / 2;
554 
555  return ( fx * fx + fy * fy ) > ( r * r );
556 }
557 
558 
560 {
561  Inflate( aDelta, aDelta );
562  return *this;
563 }
564 
565 
566 EDA_RECT& EDA_RECT::Inflate( wxCoord dx, wxCoord dy )
567 {
568  if( m_Size.x >= 0 )
569  {
570  if( m_Size.x < -2 * dx )
571  {
572  // Don't allow deflate to eat more width than we have,
573  m_Pos.x += m_Size.x / 2;
574  m_Size.x = 0;
575  }
576  else
577  {
578  // The inflate is valid.
579  m_Pos.x -= dx;
580  m_Size.x += 2 * dx;
581  }
582  }
583  else // size.x < 0:
584  {
585  if( m_Size.x > -2 * dx )
586  {
587  // Don't allow deflate to eat more width than we have,
588  m_Pos.x -= m_Size.x / 2;
589  m_Size.x = 0;
590  }
591  else
592  {
593  // The inflate is valid.
594  m_Pos.x += dx;
595  m_Size.x -= 2 * dx; // m_Size.x <0: inflate when dx > 0
596  }
597  }
598 
599  if( m_Size.y >= 0 )
600  {
601  if( m_Size.y < -2 * dy )
602  {
603  // Don't allow deflate to eat more height than we have,
604  m_Pos.y += m_Size.y / 2;
605  m_Size.y = 0;
606  }
607  else
608  {
609  // The inflate is valid.
610  m_Pos.y -= dy;
611  m_Size.y += 2 * dy;
612  }
613  }
614  else // size.y < 0:
615  {
616  if( m_Size.y > 2 * dy )
617  {
618  // Don't allow deflate to eat more height than we have,
619  m_Pos.y -= m_Size.y / 2;
620  m_Size.y = 0;
621  }
622  else
623  {
624  // The inflate is valid.
625  m_Pos.y += dy;
626  m_Size.y -= 2 * dy; // m_Size.y <0: inflate when dy > 0
627  }
628  }
629 
630  return *this;
631 }
632 
633 
634 void EDA_RECT::Merge( const EDA_RECT& aRect )
635 {
636  if( !m_init )
637  {
638  if( aRect.IsValid() )
639  {
640  m_Pos = aRect.GetPosition();
641  m_Size = aRect.GetSize();
642  m_init = true;
643  }
644  return;
645  }
646 
647  Normalize(); // ensure width and height >= 0
648  EDA_RECT rect = aRect;
649  rect.Normalize(); // ensure width and height >= 0
650  wxPoint end = GetEnd();
651  wxPoint rect_end = rect.GetEnd();
652 
653  // Change origin and size in order to contain the given rect
654  m_Pos.x = std::min( m_Pos.x, rect.m_Pos.x );
655  m_Pos.y = std::min( m_Pos.y, rect.m_Pos.y );
656  end.x = std::max( end.x, rect_end.x );
657  end.y = std::max( end.y, rect_end.y );
658  SetEnd( end );
659 }
660 
661 
662 void EDA_RECT::Merge( const wxPoint& aPoint )
663 {
664  if( !m_init )
665  {
666  m_Pos = aPoint;
667  m_Size = wxSize( 0, 0 );
668  return;
669  }
670 
671  Normalize(); // ensure width and height >= 0
672 
673  wxPoint end = GetEnd();
674  // Change origin and size in order to contain the given rect
675  m_Pos.x = std::min( m_Pos.x, aPoint.x );
676  m_Pos.y = std::min( m_Pos.y, aPoint.y );
677  end.x = std::max( end.x, aPoint.x );
678  end.y = std::max( end.y, aPoint.y );
679  SetEnd( end );
680 }
681 
682 
683 double EDA_RECT::GetArea() const
684 {
685  return (double) GetWidth() * (double) GetHeight();
686 }
687 
688 
689 EDA_RECT EDA_RECT::Common( const EDA_RECT& aRect ) const
690 {
691  EDA_RECT r;
692 
693  if( Intersects( aRect ) )
694  {
695  wxPoint originA( std::min( GetOrigin().x, GetEnd().x ),
696  std::min( GetOrigin().y, GetEnd().y ) );
697  wxPoint originB( std::min( aRect.GetOrigin().x, aRect.GetEnd().x ),
698  std::min( aRect.GetOrigin().y, aRect.GetEnd().y ) );
699  wxPoint endA( std::max( GetOrigin().x, GetEnd().x ),
700  std::max( GetOrigin().y, GetEnd().y ) );
701  wxPoint endB( std::max( aRect.GetOrigin().x, aRect.GetEnd().x ),
702  std::max( aRect.GetOrigin().y, aRect.GetEnd().y ) );
703 
704  r.SetOrigin( wxPoint( std::max( originA.x, originB.x ), std::max( originA.y, originB.y ) ) );
705  r.SetEnd ( wxPoint( std::min( endA.x, endB.x ), std::min( endA.y, endB.y ) ) );
706  }
707 
708  return r;
709 }
710 
711 
712 const EDA_RECT EDA_RECT::GetBoundingBoxRotated( wxPoint aRotCenter, double aAngle )
713 {
714  wxPoint corners[4];
715 
716  // Build the corners list
717  corners[0] = GetOrigin();
718  corners[2] = GetEnd();
719  corners[1].x = corners[0].x;
720  corners[1].y = corners[2].y;
721  corners[3].x = corners[2].x;
722  corners[3].y = corners[0].y;
723 
724  // Rotate all corners, to find the bounding box
725  for( int ii = 0; ii < 4; ii ++ )
726  RotatePoint( &corners[ii], aRotCenter, aAngle );
727 
728  // Find the corners bounding box
729  wxPoint start = corners[0];
730  wxPoint end = corners[0];
731 
732  for( int ii = 1; ii < 4; ii ++ )
733  {
734  start.x = std::min( start.x, corners[ii].x);
735  start.y = std::min( start.y, corners[ii].y);
736  end.x = std::max( end.x, corners[ii].x);
737  end.y = std::max( end.y, corners[ii].y);
738  }
739 
740  EDA_RECT bbox;
741  bbox.SetOrigin( start );
742  bbox.SetEnd( end );
743 
744  return bbox;
745 }
EDA_UNITS
Definition: common.h:184
void SetModified()
Definition: base_struct.cpp:94
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:183
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:178
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:108
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:116
wxSize m_Size
Definition: eda_rect.h:48
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:257
#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:179
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:286
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:62
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:101
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
Flag bits for editing and other uses.
Definition: base_struct.h:189
virtual bool IsReplaceable() const
Function IsReplaceable.
Definition: base_struct.h:517
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:166
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.
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:54
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
Set to true to override the visibility setting of the item.
Definition: base_struct.h:186
virtual BITMAP_DEF GetMenuImage() const
Function GetMenuImage returns a pointer to an image to be used in menus.
void initVars()
Definition: base_struct.cpp:84
virtual bool Matches(wxFindReplaceData &aSearchData, void *aAuxData)
Function Matches compares the item against the search criteria in aSearchData.
Definition: base_struct.h:473
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.
textbox
Definition: base_struct.cpp:57