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