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