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