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