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