KiCad PCB EDA Suite
sch_painter.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) 2014 CERN
5  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
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 
25 
26 #include <sch_item_struct.h>
27 
28 #include <lib_draw_item.h>
29 #include <lib_rectangle.h>
30 #include <lib_pin.h>
31 #include <lib_circle.h>
32 #include <lib_polyline.h>
33 #include <lib_arc.h>
34 #include <lib_field.h>
35 #include <lib_text.h>
36 #include <sch_line.h>
37 #include <sch_component.h>
38 #include <sch_field.h>
39 #include <sch_junction.h>
40 #include <sch_text.h>
41 #include <sch_no_connect.h>
42 #include <sch_bus_entry.h>
43 #include <sch_bitmap.h>
44 #include <draw_graphic_text.h>
46 #include <lib_edit_frame.h>
47 #include <plotter.h>
48 #include <template_fieldnames.h>
49 #include <class_libentry.h>
50 #include <class_library.h>
51 #include <sch_edit_frame.h>
52 #include <view/view.h>
54 #include <colors_design_settings.h>
55 
56 #include "sch_painter.h"
57 
58 namespace KIGFX
59 {
60 
62  m_ShowUnit( 0 ),
63  m_ShowConvert( 0 )
64 {
65  ImportLegacyColors( nullptr );
66 }
67 
68 
70 {
71  for( int layer = SCH_LAYER_ID_START; layer < SCH_LAYER_ID_END; layer ++)
72  m_layerColors[ layer ] = ::GetLayerColor( static_cast<SCH_LAYER_ID>( layer ) );
73 
74  for( int layer = GAL_LAYER_ID_START; layer < GAL_LAYER_ID_END; layer ++)
75  m_layerColors[ layer ] = ::GetLayerColor( static_cast<SCH_LAYER_ID>( layer ) );
76 
78 }
79 
80 
81 const COLOR4D& SCH_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer ) const
82 {
83  return m_layerColors[ aLayer ];
84 }
85 
86 
87 static COLOR4D selectedBrightening( const COLOR4D& aColor )
88 {
89  return aColor.Brightened( 0.5 );
90 }
91 
92 
105 static LIB_PART* dummy()
106 {
107  static LIB_PART* part;
108 
109  if( !part )
110  {
111  part = new LIB_PART( wxEmptyString );
112 
113  LIB_RECTANGLE* square = new LIB_RECTANGLE( part );
114 
115  square->Move( wxPoint( -200, 200 ) );
116  square->SetEndPosition( wxPoint( 200, -200 ) );
117 
118  LIB_TEXT* text = new LIB_TEXT( part );
119 
120  text->SetTextSize( wxSize( 150, 150 ) );
121  text->SetText( wxString( wxT( "??" ) ) );
122 
123  part->AddDrawItem( square );
124  part->AddDrawItem( text );
125  }
126 
127  return part;
128 }
129 
130 
132  KIGFX::PAINTER (aGal)
133 { }
134 
135 
136 #define HANDLE_ITEM( type_id, type_name ) \
137  case type_id: draw( (type_name *) item, aLayer ); break;
138 
139 
140 bool SCH_PAINTER::Draw( const VIEW_ITEM *aItem, int aLayer )
141 {
142  auto item2 = static_cast<const EDA_ITEM*>( aItem );
143  auto item = const_cast<EDA_ITEM*>( item2 );
144 
146 
147  switch( item->Type() )
148  {
173 
174  default: return false;
175  }
176 
177  return false;
178 }
179 
180 
182 {
183  if( m_schSettings.m_ShowUnit // showing a specific unit
184  && aItem->GetUnit() // item is unit-specific
185  && aItem->GetUnit() != m_schSettings.m_ShowUnit )
186  {
187  return false;
188  }
189 
190  if( m_schSettings.m_ShowConvert // showing a specific conversion
191  && aItem->GetConvert() // item is conversion-specific
192  && aItem->GetConvert() != m_schSettings.m_ShowConvert )
193  {
194  return false;
195  }
196 
197  return true;
198 }
199 
200 
201 void SCH_PAINTER::draw( LIB_PART *aComp, int aLayer, bool aDrawFields, int aUnit, int aConvert,
202  std::vector<bool>* danglingPinFlags )
203 {
204  if( !aUnit )
205  aUnit = m_schSettings.m_ShowUnit;
206 
207  if( !aConvert )
208  aConvert = m_schSettings.m_ShowConvert;
209 
210  size_t pinIndex = 0;
211 
212  for( auto& item : aComp->GetDrawItems() )
213  {
214  if( !aDrawFields && item.Type() == LIB_FIELD_T )
215  continue;
216 
217  if( aUnit && item.GetUnit() && aUnit != item.GetUnit() )
218  continue;
219 
220  if( aConvert && item.GetConvert() && aConvert != item.GetConvert() )
221  continue;
222 
223  if( item.Type() == LIB_PIN_T )
224  {
225  auto pin = static_cast<LIB_PIN*>( &item );
226  bool dangling = true;
227 
228  if( danglingPinFlags && pinIndex < danglingPinFlags->size() )
229  dangling = (*danglingPinFlags)[ pinIndex ];
230 
231  draw( pin, aLayer, dangling, aComp->IsMoving() );
232  pinIndex++;
233  }
234  else
235  Draw( &item, aLayer );
236  }
237 }
238 
239 
240 void SCH_PAINTER::draw( LIB_ALIAS *aAlias, int aLayer )
241 {
242  LIB_PART* comp = aAlias->GetPart();
243 
244  draw( comp, aLayer, false );
245 
246  LIB_FIELDS fields;
247  comp->GetFields( fields );
248 
249  if( !aAlias->IsRoot() )
250  {
251  fields[ VALUE ].SetText( aAlias->GetName() );
252  fields[ DATASHEET ].SetText( aAlias->GetDocFileName() );
253  }
254 
255  for( LIB_FIELD& field : fields )
256  draw( &field, aLayer );
257 }
258 
259 
260 static VECTOR2D mapCoords( const wxPoint& aCoord )
261 {
262  return VECTOR2D( aCoord.x, -aCoord.y );
263 }
264 
265 
266 void SCH_PAINTER::triLine( const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c )
267 {
268  m_gal->DrawLine( a, b );
269  m_gal->DrawLine( b, c );
270 }
271 
272 
273 bool SCH_PAINTER::setColors( const LIB_ITEM* aItem, int aLayer )
274 {
275  if( aLayer == LAYER_DEVICE_BACKGROUND && aItem->GetFillMode() == FILLED_WITH_BG_BODYCOLOR )
276  {
278 
279  if( aItem->IsMoving() || ( aItem->GetParent() && aItem->GetParent()->IsMoving() ) )
280  color = selectedBrightening( color );
281 
282  m_gal->SetIsFill( true );
283  m_gal->SetFillColor( color );
284 
285  m_gal->SetIsStroke( false );
286  return true;
287  }
288  else if( aLayer == LAYER_DEVICE )
289  {
291 
292  if( aItem->IsMoving() || ( aItem->GetParent() && aItem->GetParent()->IsMoving() ) )
293  color = selectedBrightening( color );
294 
295  m_gal->SetIsStroke( true );
296  m_gal->SetStrokeColor( color );
297  m_gal->SetLineWidth( aItem->GetPenSize() );
298 
299  m_gal->SetIsFill( aItem->GetFillMode() == FILLED_SHAPE );
300  m_gal->SetFillColor( color );
301  return true;
302  }
303 
304  return false;
305 }
306 
307 
308 void SCH_PAINTER::draw( LIB_RECTANGLE *aRect, int aLayer )
309 {
310  if( !isUnitAndConversionShown( aRect ) )
311  return;
312 
313  if( setColors( aRect, aLayer ) )
314  m_gal->DrawRectangle( mapCoords( aRect->GetPosition() ), mapCoords( aRect->GetEnd() ) );
315 
316 }
317 
318 
319 void SCH_PAINTER::draw( LIB_CIRCLE *aCircle, int aLayer )
320 {
321  if( !isUnitAndConversionShown( aCircle ) )
322  return;
323 
324  if( setColors( aCircle, aLayer ) )
325  m_gal->DrawCircle( mapCoords( aCircle->GetPosition() ), aCircle->GetRadius() );
326 }
327 
328 
329 void SCH_PAINTER::draw( LIB_ARC *aArc, int aLayer )
330 {
331  if( !isUnitAndConversionShown( aArc ) )
332  return;
333 
334  int sai = aArc->GetFirstRadiusAngle();
335  int eai = aArc->GetSecondRadiusAngle();
336 
337  if( TRANSFORM().MapAngles( &sai, &eai ) )
338  std::swap( sai, eai );
339 
340  double sa = (double) sai * M_PI / 1800.0;
341  double ea = (double) eai * M_PI / 1800.0 ;
342 
343  VECTOR2D pos = mapCoords( aArc->GetPosition() );
344 
345  if( setColors( aArc, aLayer ) )
346  m_gal->DrawArc( pos, aArc->GetRadius(), sa, ea );
347 }
348 
349 
350 void SCH_PAINTER::draw( LIB_POLYLINE *aLine, int aLayer )
351 {
352  if( !isUnitAndConversionShown( aLine ) )
353  return;
354 
355  const std::vector<wxPoint>& pts = aLine->GetPolyPoints();
356  std::deque<VECTOR2D> vtx;
357 
358  for( auto p : pts )
359  vtx.push_back( mapCoords( p ) );
360 
361  if( setColors( aLine, aLayer ) )
362  m_gal->DrawPolygon( vtx );
363 }
364 
365 
366 void SCH_PAINTER::draw( LIB_FIELD *aField, int aLayer )
367 {
368  // Must check layer as fields are sometimes drawn by their parent rather than
369  // directly from the view.
370  int layers[KIGFX::VIEW::VIEW_MAX_LAYERS], layers_count;
371  aField->ViewGetLayers( layers, layers_count );
372 
373  if( aLayer != layers[0] )
374  return;
375 
376  if( !isUnitAndConversionShown( aField ) )
377  return;
378 
379  COLOR4D color = aField->GetDefaultColor();
380 
381  if( aField->IsMoving() || ( aField->GetParent() && aField->GetParent()->IsMoving() ) )
382  color = selectedBrightening( color );
383 
384  if( !aField->IsVisible() )
385  {
388  else
389  return;
390  }
391 
392  int linewidth = aField->GetPenSize();
393 
394  m_gal->SetLineWidth( linewidth );
395  m_gal->SetIsFill( false );
396  m_gal->SetIsStroke( true );
397  m_gal->SetStrokeColor( color );
398  m_gal->SetGlyphSize( VECTOR2D( aField->GetTextSize() ) );
399 
401  m_gal->SetVerticalJustify( aField->GetVertJustify( ) );
402 
403  auto pos = mapCoords( aField->GetPosition() );
404  double orient = aField->GetTextAngleRadians();
405 
406  m_gal->StrokeText( aField->GetText(), pos, orient );
407 
408  // Draw the umbilical line
409  if( aField->IsMoving() && m_schSettings.m_ShowUmbilicals )
410  {
412  m_gal->SetStrokeColor( COLOR4D( 0.0, 0.0, 1.0, 1.0 ) );
413  m_gal->DrawLine( pos, wxPoint( 0, 0 ) );
414  }
415 }
416 
417 
418 void SCH_PAINTER::draw( LIB_TEXT *aText, int aLayer )
419 {
420  if( !isUnitAndConversionShown( aText ) )
421  return;
422 
424 
425  if( aText->IsMoving() || ( aText->GetParent() && aText->GetParent()->IsMoving() ) )
426  color = selectedBrightening( color );
427 
428  if( !aText->IsVisible() )
429  {
432  else
433  return;
434  }
435 
436  int linewidth = aText->GetPenSize();
437  EDA_RECT bBox = aText->GetBoundingBox();
438  bBox.RevertYAxis();
439  VECTOR2D pos = mapCoords( bBox.Centre() );
440  double orient = aText->GetTextAngleRadians();
441 
444  m_gal->SetLineWidth( linewidth );
445  m_gal->SetIsFill( false );
446  m_gal->SetIsStroke( true );
447  m_gal->SetStrokeColor( color );
448  m_gal->SetGlyphSize( VECTOR2D( aText->GetTextSize() ) );
449  m_gal->SetFontBold( aText->IsBold() );
450  m_gal->SetFontItalic( aText->IsItalic() );
451  m_gal->StrokeText( aText->GetText(), pos, orient );
452 }
453 
454 
455 static int InternalPinDecoSize( const LIB_PIN &aPin )
456 {
457  return aPin.GetNameTextSize() != 0 ? aPin.GetNameTextSize() / 2 : aPin.GetNumberTextSize() / 2;
458 }
459 
460 
461 // Utility for getting the size of the 'external' pin decorators (as a radius)
462 // i.e. the negation circle, the polarity 'slopes' and the nonlogic marker
463 static int ExternalPinDecoSize( const LIB_PIN &aPin )
464 {
465  return aPin.GetNumberTextSize() / 2;
466 }
467 
468 
469 // Draw the target (an open circle) for a pin which has no connection or is being
470 // moved.
471 static void drawPinDanglingSymbol( GAL* aGal, const VECTOR2I& aPos, const COLOR4D& aColor )
472 {
473  aGal->SetIsStroke( true );
474  aGal->SetIsFill( false );
475  aGal->SetStrokeColor( aColor );
476 
477  aGal->SetLineWidth ( 1.0 );
478  aGal->DrawCircle( aPos, TARGET_PIN_RADIUS );
479 }
480 
481 
482 void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer, bool isDangling, bool isMoving )
483 {
484  if( aLayer != LAYER_DEVICE )
485  return;
486 
487  if( !isUnitAndConversionShown( aPin ) )
488  return;
489 
490  if( aPin->IsMoving() )
491  isMoving = true;
492 
494  VECTOR2I pos = mapCoords( aPin->GetPosition() );
495 
496  if( isMoving )
497  color = selectedBrightening( color );
498 
499  if( !aPin->IsVisible() )
500  {
502  {
504  }
505  else
506  {
507  if( isDangling && aPin->IsPowerConnection() )
508  drawPinDanglingSymbol( m_gal, pos, color );
509 
510  return;
511  }
512  }
513 
514  VECTOR2I p0, dir;
515  int len = aPin->GetLength();
516  int width = aPin->GetPenSize();
517  int shape = aPin->GetShape();
518  int orient = aPin->GetOrientation();
519 
520  switch( orient )
521  {
522  case PIN_UP:
523  p0 = VECTOR2I( pos.x, pos.y - len );
524  dir = VECTOR2I(0, 1);
525  break;
526  case PIN_DOWN:
527  p0 = VECTOR2I( pos.x, pos.y + len );
528  dir = VECTOR2I(0, -1);
529  break;
530  case PIN_LEFT:
531  p0 = VECTOR2I( pos.x - len, pos.y );
532  dir = VECTOR2I(1, 0);
533  break;
534  case PIN_RIGHT:
535  p0 = VECTOR2I( pos.x + len, pos.y );
536  dir = VECTOR2I(-1, 0);
537  break;
538  }
539 
540  VECTOR2D pc;
541 
542  m_gal->SetIsStroke( true );
543  m_gal->SetIsFill( false );
544  m_gal->SetLineWidth( width );
545  m_gal->SetStrokeColor( color );
546  m_gal->SetFontBold( false );
547  m_gal->SetFontItalic( false );
548 
549  const int radius = ExternalPinDecoSize( *aPin );
550  const int diam = radius*2;
551  const int clock_size = InternalPinDecoSize( *aPin );
552 
553  if( shape == PINSHAPE_INVERTED )
554  {
555  m_gal->DrawCircle( p0 + dir * radius, radius );
556  m_gal->DrawLine( p0 + dir * ( diam ), pos );
557  }
558  else if( shape == PINSHAPE_FALLING_EDGE_CLOCK )
559  {
560  pc = p0 + dir * clock_size ;
561 
562  triLine( p0 + VECTOR2D( dir.y, -dir.x) * clock_size,
563  pc,
564  p0 + VECTOR2D( -dir.y, dir.x) * clock_size );
565 
566  m_gal->DrawLine( pos, pc );
567  }
568  else
569  {
570  m_gal->DrawLine( p0, pos );
571  }
572 
573  if( shape == PINSHAPE_CLOCK )
574  {
575  if (!dir.y)
576  {
577  triLine( p0 + VECTOR2D( 0, clock_size ),
578  p0 + VECTOR2D( -dir.x * clock_size, 0 ),
579  p0 + VECTOR2D( 0, -clock_size ) );
580  }
581  else
582  {
583  triLine( p0 + VECTOR2D( clock_size, 0 ),
584  p0 + VECTOR2D( 0, -dir.y * clock_size ),
585  p0 + VECTOR2D( -clock_size, 0 ) );
586  }
587  }
588 
589  if( shape == PINSHAPE_INPUT_LOW )
590  {
591  if(!dir.y)
592  {
593  triLine( p0 + VECTOR2D(dir.x, 0) * diam,
594  p0 + VECTOR2D(dir.x, -1) * diam,
595  p0 );
596  }
597  else /* MapX1 = 0 */
598  {
599  triLine( p0 + VECTOR2D( 0, dir.y) * diam,
600  p0 + VECTOR2D(-1, dir.y) * diam,
601  p0 );
602  }
603  }
604 
605  if( shape == PINSHAPE_OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
606  {
607  if( !dir.y ) // Horizontal pin
608  m_gal->DrawLine( p0 - VECTOR2D( 0, diam ), p0 + VECTOR2D( dir.x, 0 ) * diam );
609  else // Vertical pin
610  m_gal->DrawLine( p0 - VECTOR2D( diam, 0 ), p0 + VECTOR2D( 0, dir.y ) * diam );
611  }
612 
613  if( shape == PINSHAPE_NONLOGIC ) /* NonLogic pin symbol */
614  {
615  m_gal->DrawLine( p0 - VECTOR2D( dir.x + dir.y, dir.y - dir.x ) * radius,
616  p0 + VECTOR2D( dir.x + dir.y, dir.y - dir.x ) * radius );
617  m_gal->DrawLine( p0 - VECTOR2D( dir.x - dir.y, dir.x + dir.y ) * radius,
618  p0 + VECTOR2D( dir.x - dir.y, dir.x + dir.y ) * radius );
619  }
620 
621  if( aPin->GetType() == PIN_NC ) // Draw a N.C. symbol
622  {
623  m_gal->DrawLine( pos + VECTOR2D( -1, -1 ) * TARGET_PIN_RADIUS,
624  pos + VECTOR2D( 1, 1 ) * TARGET_PIN_RADIUS );
625  m_gal->DrawLine( pos + VECTOR2D( 1, -1 ) * TARGET_PIN_RADIUS ,
626  pos + VECTOR2D( -1, 1 ) * TARGET_PIN_RADIUS );
627  }
628 
629  if( isDangling && ( aPin->IsVisible() || aPin->IsPowerConnection() ) )
630  drawPinDanglingSymbol( m_gal, pos, color );
631 
632  // Draw the labels
633 
634  LIB_PART* libEntry = aPin->GetParent();
635  int textOffset = libEntry->GetPinNameOffset();
636 
637  int nameLineWidth = aPin->GetPenSize();
638  nameLineWidth = Clamp_Text_PenSize( nameLineWidth, aPin->GetNameTextSize(), false );
639  int numLineWidth = aPin->GetPenSize();
640  numLineWidth = Clamp_Text_PenSize( numLineWidth, aPin->GetNumberTextSize(), false );
641 
642  #define PIN_TEXT_MARGIN 4
643 
644  // Four locations around a pin where text can be drawn
645  enum { INSIDE = 0, OUTSIDE, ABOVE, BELOW };
646  int size[4] = { 0, 0, 0, 0 };
647  int thickness[4] = { numLineWidth, numLineWidth, numLineWidth, numLineWidth };
648  COLOR4D colour[4];
649  wxString text[4];
650 
651  // TextOffset > 0 means pin NAMES on inside, pin NUMBERS above and nothing below
652  if( textOffset )
653  {
654  size [INSIDE] = libEntry->ShowPinNames() ? aPin->GetNameTextSize() : 0;
655  thickness[INSIDE] = nameLineWidth;
657  text [INSIDE] = aPin->GetName();
658 
659  size [ABOVE] = libEntry->ShowPinNumbers() ? aPin->GetNumberTextSize() : 0;
660  thickness[ABOVE] = numLineWidth;
661  colour [ABOVE] = m_schSettings.GetLayerColor( LAYER_PINNUM );
662  text [ABOVE] = aPin->GetNumber();
663  }
664  // Otherwise pin NAMES go above and pin NUMBERS go below
665  else
666  {
667  size [ABOVE] = libEntry->ShowPinNames() ? aPin->GetNameTextSize() : 0;
668  thickness[ABOVE] = nameLineWidth;
669  colour [ABOVE] = m_schSettings.GetLayerColor( LAYER_PINNAM );
670  text [ABOVE] = aPin->GetName();
671 
672  size [BELOW] = libEntry->ShowPinNumbers() ? aPin->GetNumberTextSize() : 0;
673  thickness[BELOW] = numLineWidth;
674  colour [BELOW] = m_schSettings.GetLayerColor( LAYER_PINNUM );
675  text [BELOW] = aPin->GetNumber();
676  }
677 
679  {
680  size [OUTSIDE] = std::max( aPin->GetNameTextSize() * 3 / 4, Millimeter2iu( 0.7 ) );
681  thickness[OUTSIDE] = size[OUTSIDE] / 6;
683  text [OUTSIDE] = aPin->GetElectricalTypeName();
684  }
685 
686  if( !aPin->IsVisible() )
687  {
688  for( COLOR4D& c : colour )
690  }
691  else if( isMoving )
692  {
693  for( COLOR4D& c : colour )
694  c = selectedBrightening( c );
695  }
696 
697  int insideOffset = textOffset;
698  int outsideOffset = 10;
699  int aboveOffset = PIN_TEXT_MARGIN + ( thickness[ABOVE] + GetDefaultLineThickness() ) / 2;
700  int belowOffset = PIN_TEXT_MARGIN + ( thickness[BELOW] + GetDefaultLineThickness() ) / 2;
701 
702  #define SET_DC( i ) \
703  m_gal->SetGlyphSize( VECTOR2D( size[i], size[i] ) ); \
704  m_gal->SetLineWidth( thickness[i] ); \
705  m_gal->SetStrokeColor( colour[i] );
706 
707  switch( orient )
708  {
709  case PIN_LEFT:
710  if( size[INSIDE] )
711  {
712  SET_DC( INSIDE );
715  m_gal->StrokeText( text[INSIDE], pos + VECTOR2D( -insideOffset - len, 0 ), 0 );
716  }
717  if( size[OUTSIDE] )
718  {
719  SET_DC( OUTSIDE );
722  m_gal->StrokeText( text[OUTSIDE], pos + VECTOR2D( outsideOffset, 0 ), 0 );
723  }
724  if( size[ABOVE] )
725  {
726  SET_DC( ABOVE );
729  m_gal->StrokeText( text[ABOVE], pos + VECTOR2D( -len / 2.0, -aboveOffset ), 0 );
730  }
731  if( size[BELOW] )
732  {
733  SET_DC( BELOW );
736  m_gal->StrokeText( text[BELOW], pos + VECTOR2D( -len / 2.0, belowOffset ), 0 );
737  }
738  break;
739 
740  case PIN_RIGHT:
741  if( size[INSIDE] )
742  {
743  SET_DC( INSIDE );
747  m_gal->StrokeText( text[INSIDE], pos + VECTOR2D( insideOffset + len, 0 ), 0 );
748  }
749  if( size[OUTSIDE] )
750  {
751  SET_DC( OUTSIDE );
754  m_gal->StrokeText( text[OUTSIDE], pos + VECTOR2D( -outsideOffset, 0 ), 0 );
755  }
756  if( size[ABOVE] )
757  {
758  SET_DC( ABOVE );
761  m_gal->StrokeText( text[ABOVE], pos + VECTOR2D( len / 2.0, -aboveOffset ), 0 );
762  }
763  if( size[BELOW] )
764  {
765  SET_DC( BELOW );
768  m_gal->StrokeText( text[BELOW], pos + VECTOR2D( len / 2.0, belowOffset ), 0 );
769  }
770  break;
771 
772  case PIN_DOWN:
773  if( size[INSIDE] )
774  {
775  SET_DC( INSIDE );
778  m_gal->StrokeText ( text[INSIDE], pos + VECTOR2D( 0, insideOffset + len ), M_PI / 2);
779  }
780  if( size[OUTSIDE] )
781  {
782  SET_DC( OUTSIDE );
785  m_gal->StrokeText ( text[OUTSIDE], pos + VECTOR2D( 0, -outsideOffset ), M_PI / 2);
786  }
787  if( size[ABOVE] )
788  {
789  SET_DC( ABOVE );
792  m_gal->StrokeText( text[ABOVE], pos + VECTOR2D( -aboveOffset, len / 2.0 ), M_PI / 2 );
793  }
794  if( size[BELOW] )
795  {
796  SET_DC( BELOW );
799  m_gal->StrokeText( text[BELOW], pos + VECTOR2D( belowOffset, len / 2.0 ), M_PI / 2 );
800  }
801  break;
802 
803  case PIN_UP:
804  if( size[INSIDE] )
805  {
806  SET_DC( INSIDE );
809  m_gal->StrokeText ( text[INSIDE], pos + VECTOR2D( 0, -insideOffset - len ), M_PI / 2);
810  }
811  if( size[OUTSIDE] )
812  {
813  SET_DC( OUTSIDE );
816  m_gal->StrokeText ( text[OUTSIDE], pos + VECTOR2D( 0, outsideOffset ), M_PI / 2);
817  }
818  if( size[ABOVE] )
819  {
820  SET_DC( ABOVE );
823  m_gal->StrokeText( text[ABOVE], pos + VECTOR2D( -aboveOffset, -len / 2.0 ), M_PI / 2 );
824  }
825  if( size[BELOW] )
826  {
827  SET_DC( BELOW );
830  m_gal->StrokeText( text[BELOW], pos + VECTOR2D( belowOffset, -len / 2.0 ), M_PI / 2 );
831  }
832  break;
833 
834  default:
835  wxFAIL_MSG( "Unknown pin orientation" );
836  }
837 }
838 
839 
840 // Draw the target (an open square) for a wire or label which has no connection or is
841 // being moved.
842 static void drawDanglingSymbol( GAL* aGal, const wxPoint& aPos )
843 {
845 
846  aGal->SetIsStroke( true );
847  aGal->SetIsFill( false );
848  aGal->SetLineWidth ( 1.0 );
849 
850  aGal->DrawRectangle( aPos - radius, aPos + radius );
851 }
852 
853 
854 void SCH_PAINTER::draw( SCH_JUNCTION *aJct, int aLayer )
855 {
857 
858  if( aJct->GetState( BRIGHTENED ) )
860  else if( aJct->IsMoving() )
861  color = selectedBrightening( color );
862 
863  m_gal->SetIsStroke(true);
864  m_gal->SetIsFill(true);
865  m_gal->SetStrokeColor( color );
866  m_gal->SetFillColor( color );
868 }
869 
870 
871 void SCH_PAINTER::draw( SCH_LINE *aLine, int aLayer )
872 {
873  COLOR4D color = aLine->GetLineColor();
874 
875  if( aLine->GetState( BRIGHTENED ) )
877  else if( aLine->IsMoving() )
878  color = selectedBrightening( color );
879 
880  int width = aLine->GetPenSize();
881 
882  m_gal->SetIsStroke( true );
883  m_gal->SetStrokeColor(color);
884  m_gal->SetLineWidth( width );
885 
886  if( aLine->GetLineStyle() <= PLOTDASHTYPE_SOLID )
887  {
888  m_gal->DrawLine( aLine->GetStartPoint(), aLine->GetEndPoint() );
889  }
890  else
891  {
892  VECTOR2D start = aLine->GetStartPoint();
893  VECTOR2D end = aLine->GetEndPoint();
894 
895  EDA_RECT clip( wxPoint( start.x, start.y ), wxSize( end.x - start.x, end.y - start.y ) );
896  clip.Normalize();
897 
898  double theta = atan2( end.y - start.y, end.x - start.x );
899  double strokes[] = { 1.0, DASH_GAP_LEN( width ), 1.0, DASH_GAP_LEN( width ) };
900 
901  switch( aLine->GetLineStyle() )
902  {
903  default:
904  case PLOTDASHTYPE_DASH:
905  strokes[0] = strokes[2] = DASH_MARK_LEN( width );
906  break;
907  case PLOTDASHTYPE_DOT:
908  strokes[0] = strokes[2] = DOT_MARK_LEN( width );
909  break;
911  strokes[0] = DASH_MARK_LEN( width );
912  strokes[2] = DOT_MARK_LEN( width );
913  break;
914  }
915 
916  for( size_t i = 0; i < 10000; ++i )
917  {
918  // Calculations MUST be done in doubles to keep from accumulating rounding
919  // errors as we go.
920  VECTOR2D next( start.x + strokes[ i % 4 ] * cos( theta ),
921  start.y + strokes[ i % 4 ] * sin( theta ) );
922 
923  // Drawing each segment can be done rounded to ints.
924  wxPoint segStart( KiROUND( start.x ), KiROUND( start.y ) );
925  wxPoint segEnd( KiROUND( next.x ), KiROUND( next.y ) );
926 
927  if( ClipLine( &clip, segStart.x, segStart.y, segEnd.x, segEnd.y ) )
928  break;
929  else if( i % 2 == 0 )
930  m_gal->DrawLine( segStart, segEnd );
931 
932  start = next;
933  }
934  }
935 
936  if( aLine->IsStartDangling() )
938 
939  if( aLine->IsEndDangling() )
941 }
942 
943 
944 void SCH_PAINTER::draw( SCH_TEXT *aText, int aLayer )
945 {
946  COLOR4D color;
947 
948  switch( aText->Type() )
949  {
953  case SCH_LABEL_T: color = m_schSettings.GetLayerColor( LAYER_LOCLABEL ); break;
954  default: color = m_schSettings.GetLayerColor( LAYER_NOTES ); break;
955  }
956 
957  if( aText->GetState( BRIGHTENED ) )
959  if( aText->IsMoving() )
960  color = selectedBrightening( color );
961 
962  if( !aText->IsVisible() )
963  {
966  else
967  return;
968  }
969 
970  m_gal->SetStrokeColor( color );
971 
972  if( aText->IsDangling() )
973  drawDanglingSymbol( m_gal, aText->GetTextPos() );
974 
975  wxPoint text_offset = aText->GetTextPos() + aText->GetSchematicTextOffset();
976  int linewidth = aText->GetPenSize();
977  wxString shownText( aText->GetShownText() );
978 
979  if( !shownText.IsEmpty() )
980  {
981  m_gal->SetIsFill( false );
982  m_gal->SetIsStroke( true );
983  m_gal->SetTextAttributes( aText );
984  m_gal->SetLineWidth( linewidth );
985  m_gal->StrokeText( shownText, text_offset, aText->GetTextAngleRadians() );
986  }
987 }
988 
989 
990 static void orientComponent( LIB_PART *part, int orientation )
991 {
992  struct ORIENT
993  {
994  int flag;
995  int n_rots;
996  int mirror_x;
997  int mirror_y;
998  }
999  orientations[] =
1000  {
1001  { CMP_ORIENT_0, 0, 0, 0 },
1002  { CMP_ORIENT_90, 1, 0, 0 },
1003  { CMP_ORIENT_180, 2, 0, 0 },
1004  { CMP_ORIENT_270, 3, 0, 0 },
1005  { CMP_MIRROR_X + CMP_ORIENT_0, 0, 1, 0 },
1006  { CMP_MIRROR_X + CMP_ORIENT_90, 1, 1, 0 },
1007  { CMP_MIRROR_Y, 0, 0, 1 },
1008  { CMP_MIRROR_X + CMP_ORIENT_270, 3, 1, 0 },
1009  { CMP_MIRROR_Y + CMP_ORIENT_0, 0, 0, 1 },
1010  { CMP_MIRROR_Y + CMP_ORIENT_90, 1, 0, 1 },
1011  { CMP_MIRROR_Y + CMP_ORIENT_180, 2, 0, 1 },
1012  { CMP_MIRROR_Y + CMP_ORIENT_270, 3, 0, 1 }
1013  };
1014 
1015  ORIENT o = orientations[ 0 ];
1016 
1017  for( auto& i : orientations )
1018  {
1019  if( i.flag == orientation )
1020  {
1021  o = i;
1022  break;
1023  }
1024  }
1025 
1026  for( auto& item : part->GetDrawItems() )
1027  {
1028  for( int i = 0; i < o.n_rots; i++ )
1029  item.Rotate( wxPoint(0, 0 ), true );
1030 
1031  if( o.mirror_x )
1032  item.MirrorVertical( wxPoint( 0, 0 ) );
1033 
1034  if( o.mirror_y )
1035  item.MirrorHorizontal( wxPoint( 0, 0 ) );
1036  }
1037 }
1038 
1039 
1040 void SCH_PAINTER::draw( SCH_COMPONENT *aComp, int aLayer )
1041 {
1042  PART_SPTR part = aComp->GetPartRef().lock();
1043 
1044  // Use dummy part if the actual couldn't be found (or couldn't be locked).
1045  // In either case copy it so we can re-orient and translate it.
1046  std::unique_ptr<LIB_PART> temp( new LIB_PART( part ? *part.get() : *dummy() ) );
1047 
1048  if( aComp->IsMoving() )
1049  temp->SetFlags( IS_MOVED );
1050 
1051  orientComponent( temp.get(), aComp->GetOrientation() );
1052 
1053  for( auto& item : temp->GetDrawItems() )
1054  {
1055  auto rp = aComp->GetPosition();
1056  auto ip = item.GetPosition();
1057  item.Move( wxPoint( rp.x + ip.x, ip.y - rp.y ) );
1058  }
1059 
1060  draw( temp.get(), aLayer, false,
1061  aComp->GetUnit(), aComp->GetConvert(), aComp->GetDanglingPinFlags() );
1062 
1063  // The fields are SCH_COMPONENT-specific and so don't need to be copied/
1064  // oriented/translated.
1065  std::vector<SCH_FIELD*> fields;
1066  aComp->GetFields( fields, false );
1067 
1068  for( SCH_FIELD* field : fields )
1069  {
1070  if( !field->IsMoving() )
1071  draw( field, aLayer );
1072  }
1073 }
1074 
1075 
1076 void SCH_PAINTER::draw( SCH_FIELD *aField, int aLayer )
1077 {
1078  COLOR4D color;
1079  SCH_COMPONENT* parentComponent = (SCH_COMPONENT*) aField->GetParent();
1080 
1081  switch( aField->GetId() )
1082  {
1083  case REFERENCE: color = m_schSettings.GetLayerColor( LAYER_REFERENCEPART ); break;
1084  case VALUE: color = m_schSettings.GetLayerColor( LAYER_VALUEPART ); break;
1085  default: color = m_schSettings.GetLayerColor( LAYER_FIELDS ); break;
1086  }
1087 
1088  if( aField->IsMoving() || ( aField->GetParent() && aField->GetParent()->IsMoving() ) )
1089  color = selectedBrightening( color );
1090 
1091  if( !aField->IsVisible() )
1092  {
1095  else
1096  return;
1097  }
1098 
1099  if( aField->IsVoid() )
1100  return;
1101 
1102  // Calculate the text orientation according to the component orientation.
1103  int orient = (int) aField->GetTextAngle();
1104 
1105  if( parentComponent->GetTransform().y1 ) // Rotate component 90 degrees.
1106  {
1107  if( orient == TEXT_ANGLE_HORIZ )
1108  orient = TEXT_ANGLE_VERT;
1109  else
1110  orient = TEXT_ANGLE_HORIZ;
1111  }
1112 
1113  /* Calculate the text justification, according to the component
1114  * orientation/mirror this is a bit complicated due to cumulative
1115  * calculations:
1116  * - numerous cases (mirrored or not, rotation)
1117  * - the DrawGraphicText function recalculate also H and H justifications
1118  * according to the text orientation.
1119  * - When a component is mirrored, the text is not mirrored and
1120  * justifications are complicated to calculate
1121  * so the more easily way is to use no justifications ( Centered text )
1122  * and use GetBoundaryBox to know the text coordinate considered as centered
1123  */
1124  EDA_RECT boundaryBox = aField->GetBoundingBox();
1125  wxPoint textpos = boundaryBox.Centre();
1126  int lineWidth = aField->GetPenSize();
1127 
1130  m_gal->SetStrokeColor( color );
1131  m_gal->SetIsFill( false );
1132  m_gal->SetIsStroke( true );
1133  m_gal->SetGlyphSize( VECTOR2D( aField->GetTextSize() ) );
1134  m_gal->SetFontBold( aField->IsBold() );
1135  m_gal->SetFontItalic( aField->IsItalic() );
1136  m_gal->SetTextMirrored( aField->IsMirrored() );
1137  m_gal->SetLineWidth( lineWidth );
1138  m_gal->StrokeText( aField->GetFullyQualifiedText(), textpos, orient == TEXT_ANGLE_VERT ? M_PI/2 : 0 );
1139 
1140  // Draw the umbilical line
1141  if( aField->IsMoving() )
1142  {
1144  m_gal->SetStrokeColor( COLOR4D( 0.0, 0.0, 1.0, 1.0 ) );
1145  m_gal->DrawLine( textpos, parentComponent->GetPosition() );
1146  }
1147 }
1148 
1149 
1150 void SCH_PAINTER::draw( SCH_GLOBALLABEL *aLabel, int aLayer )
1151 {
1153  int width = aLabel->GetThickness() ? aLabel->GetThickness() : GetDefaultLineThickness();
1154 
1155  if( aLabel->GetState( BRIGHTENED ) )
1157  if( aLabel->IsMoving() )
1158  color = selectedBrightening( color );
1159 
1160  std::vector<wxPoint> pts;
1161  std::deque<VECTOR2D> pts2;
1162 
1163  aLabel->CreateGraphicShape( pts, aLabel->GetTextPos() );
1164 
1165  for( auto p : pts )
1166  pts2.emplace_back( VECTOR2D( p.x, p.y ) );
1167 
1168  m_gal->SetIsFill( false );
1169  m_gal->SetIsStroke( true );
1170  m_gal->SetLineWidth( width );
1171  m_gal->SetStrokeColor( color );
1172  m_gal->DrawPolyline( pts2 );
1173 
1174  draw( static_cast<SCH_TEXT*>( aLabel ), aLayer );
1175 }
1176 
1177 
1178 void SCH_PAINTER::draw( SCH_HIERLABEL *aLabel, int aLayer )
1179 {
1181  int width = aLabel->GetThickness() ? aLabel->GetThickness() : GetDefaultLineThickness();
1182 
1183  if( aLabel->GetState( BRIGHTENED ) )
1185  if( aLabel->IsMoving() )
1186  color = selectedBrightening( color );
1187 
1188  std::vector<wxPoint> pts;
1189  std::deque<VECTOR2D> pts2;
1190 
1191  aLabel->CreateGraphicShape( pts, aLabel->GetTextPos() );
1192 
1193  for( auto p : pts )
1194  pts2.emplace_back( VECTOR2D( p.x, p.y ) );
1195 
1196  m_gal->SetIsFill( false );
1197  m_gal->SetIsStroke( true );
1198  m_gal->SetLineWidth( width );
1199  m_gal->SetStrokeColor( color );
1200  m_gal->DrawPolyline( pts2 );
1201 
1202  draw( static_cast<SCH_TEXT*>( aLabel ), aLayer );
1203 }
1204 
1205 void SCH_PAINTER::draw( SCH_SHEET *aSheet, int aLayer )
1206 {
1207  VECTOR2D pos = aSheet->GetPosition();
1208  VECTOR2D size = aSheet->GetSize();
1209 
1210  if( aLayer == LAYER_SHEET_BACKGROUND )
1211  {
1212  m_gal->SetIsStroke( false );
1213 
1214  if( aSheet->IsMoving() ) // Gives a filled background when moving for a better look
1215  {
1216  // Select a fill color working well with black and white background color,
1217  // both in Opengl and Cairo
1218  m_gal->SetFillColor( COLOR4D( 0.1, 0.5, 0.5, 0.3 ) );
1219  m_gal->SetIsFill( true );
1220  }
1221  else
1222  {
1223  // Could be modified later, when sheets can have their own fill color
1224  return;
1225  }
1226 
1227  m_gal->DrawRectangle( pos, pos + size );
1228  }
1229  else if( aLayer == LAYER_SHEET )
1230  {
1232  m_gal->SetIsStroke( true );
1233 
1234  m_gal->SetIsFill( false );
1235  m_gal->SetLineWidth( aSheet->GetPenSize() );
1236 
1237  m_gal->DrawRectangle( pos, pos + size );
1238 
1239  VECTOR2D pos_sheetname = aSheet->GetSheetNamePosition();
1240  VECTOR2D pos_filename = aSheet->GetFileNamePosition();
1241  double nameAngle = 0.0;
1242 
1243  if( aSheet->IsVerticalOrientation() )
1244  nameAngle = -M_PI/2;
1245 
1247 
1248  auto text = wxT( "Sheet: " ) + aSheet->GetName();
1249 
1252 
1253  auto txtSize = aSheet->GetSheetNameSize();
1254 
1255  m_gal->SetGlyphSize( VECTOR2D( txtSize, txtSize ) );
1256  m_gal->SetFontBold( false );
1257  m_gal->SetFontItalic( false );
1258 
1259  m_gal->StrokeText( text, pos_sheetname, nameAngle );
1260 
1261  txtSize = aSheet->GetFileNameSize();
1262  m_gal->SetGlyphSize( VECTOR2D( txtSize, txtSize ) );
1265 
1266  text = wxT( "File: " ) + aSheet->GetFileName();
1267  m_gal->StrokeText( text, pos_filename, nameAngle );
1268 
1269  for( auto& sheetPin : aSheet->GetPins() )
1270  {
1271  if( !sheetPin.IsMoving() )
1272  draw( static_cast<SCH_HIERLABEL*>( &sheetPin ), aLayer );
1273  }
1274  }
1275 }
1276 
1277 
1278 void SCH_PAINTER::draw( SCH_NO_CONNECT *aNC, int aLayer )
1279 {
1280  int delta = aNC->GetSize() / 2;
1281  int width = GetDefaultLineThickness();
1282 
1284  m_gal->SetIsStroke( true );
1285  m_gal->SetIsFill( false );
1286  m_gal->SetLineWidth( width );
1287 
1288  VECTOR2D p = aNC->GetPosition();
1289 
1290  m_gal->DrawLine( p + VECTOR2D( -delta, -delta ), p + VECTOR2D( delta, delta ) );
1291  m_gal->DrawLine( p + VECTOR2D( -delta, delta ), p + VECTOR2D( delta, -delta ) );
1292 }
1293 
1294 
1295 void SCH_PAINTER::draw( SCH_BUS_ENTRY_BASE *aEntry, int aLayer )
1296 {
1297  COLOR4D color = aEntry->Type() == SCH_BUS_BUS_ENTRY_T ?
1300 
1301  if( aEntry->IsMoving() )
1302  color = selectedBrightening( color );
1303 
1304  m_gal->SetStrokeColor( color );
1305  m_gal->SetIsStroke( true );
1306  m_gal->SetLineWidth( aEntry->GetPenSize() );
1307  m_gal->SetIsFill( false );
1308 
1309  VECTOR2D pos = aEntry->GetPosition();
1310  VECTOR2D endPos = aEntry->m_End();
1311 
1312  m_gal->DrawLine( pos, endPos );
1313 
1314  // Draw dangling symbols:
1315  m_gal->SetLineWidth ( 1.0 );
1316 
1317  if( aEntry->IsDanglingStart() )
1319 
1320  if( aEntry->IsDanglingEnd() )
1322 }
1323 
1324 
1325 void SCH_PAINTER::draw( SCH_BITMAP *aBitmap, int aLayer )
1326 {
1327  m_gal->Save();
1328  m_gal->Translate( aBitmap->GetPosition() );
1329 
1330  // When the image scale factor is not 1.0, we need to modify the actual
1331  // as the image scale factor is similar to a local zoom
1332  double img_scale = aBitmap->GetImageScale();
1333 
1334  if( img_scale != 1.0 )
1335  m_gal->Scale( VECTOR2D( img_scale, img_scale ) );
1336 
1337  m_gal->DrawBitmap( *aBitmap->GetImage() );
1338 
1339  m_gal->Restore();
1340 }
1341 
1342 
1343 void SCH_PAINTER::draw( SCH_MARKER *aMarker, int aLayer )
1344 {
1345  const int scale = aMarker->m_ScalingFactor;
1346 
1347  // If you are changing this, update the bounding box as well
1348  const VECTOR2D arrow[] =
1349  {
1350  VECTOR2D( 0 * scale, 0 * scale ),
1351  VECTOR2D( 8 * scale, 1 * scale ),
1352  VECTOR2D( 4 * scale, 3 * scale ),
1353  VECTOR2D( 13 * scale, 8 * scale ),
1354  VECTOR2D( 9 * scale, 9 * scale ),
1355  VECTOR2D( 8 * scale, 13 * scale ),
1356  VECTOR2D( 3 * scale, 4 * scale ),
1357  VECTOR2D( 1 * scale, 8 * scale ),
1358  VECTOR2D( 0 * scale, 0 * scale )
1359  };
1360 
1362 
1365 
1366  m_gal->Save();
1367  m_gal->Translate( aMarker->GetPosition() );
1368  m_gal->SetFillColor( color );
1369  m_gal->SetIsFill( true );
1370  m_gal->SetIsStroke( false );
1371  m_gal->DrawPolygon( arrow, sizeof( arrow ) / sizeof( VECTOR2D ) );
1372  m_gal->Restore();
1373 }
1374 
1375 
1376 }; // namespace KIGFX
virtual bool Draw(const VIEW_ITEM *, int) override
Function Draw Takes an instance of VIEW_ITEM and passes it to a function that know how to draw the it...
#define TEXT_ANGLE_HORIZ
SCH_PAINTER(GAL *aGal)
CITER next(CITER it)
Definition: ptree.cpp:130
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
void SetFontItalic(const bool aItalic)
Set italic property of current font.
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList)
Draw a polyline.
Class SCH_FIELD instances are attached to a component and provide a place for the component&#39;s value...
Definition: sch_field.h:56
#define TARGET_BUSENTRY_RADIUS
Definition: sch_bus_entry.h:35
int GetPenSize() const override
Function GetPenSize virtual pure.
Definition: sch_field.cpp:101
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
Part library alias object definition.
bool IsMoving() const
Definition: base_struct.h:221
int Clamp_Text_PenSize(int aPenSize, int aSize, bool aBold)
Function Clamp_Text_PenSize As a rule, pen width should not be >1/4em, otherwise the character will b...
bool setColors(const LIB_ITEM *aItem, int aLayer)
bool IsDanglingEnd() const
Definition: sch_bus_entry.h:52
FILL_T GetFillMode() const
PART_REF & GetPartRef()
TRANSFORM & GetTransform() const
SCH_SHEET_PINS & GetPins()
Definition: sch_sheet.h:334
name of datasheet
int GetSecondRadiusAngle() const
Definition: lib_arc.h:146
std::vector< bool > * GetDanglingPinFlags()
virtual bool IsDangling() const override
Definition: sch_text.h:177
int GetPinNameOffset()
const wxPoint & GetTextPos() const
Definition: eda_text.h:237
int GetOrientation()
Get the display symbol orientation.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:58
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
bool IsItalic() const
Definition: eda_text.h:183
float m_outlineWidth
Line width used when drawing outlines.
Definition: painter.h:287
#define TEXT_ANGLE_VERT
virtual int GetPenSize() const override
Function GetPenSize virtual pure.
Definition: sch_text.cpp:289
int GetUnit() const
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_field.h:221
Base schematic object class definition.
Handle colors used to draw all items or layers.
wxPoint GetPosition() const override
Function GetPosition.
COLOR4D m_layerColors[LAYER_ID_COUNT]
Colors for all layers (normal)
Definition: painter.h:263
Define a symbol library graphical text item.
Definition: lib_text.h:44
COLOR4D GetLineColor() const
Definition: sch_line.cpp:243
int GetId() const
Definition: sch_field.h:87
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_marker.h:106
virtual void SetTextAttributes(const EDA_TEXT *aText)
Loads attributes of the given text (bold/italic/underline/mirrored and so on).
const wxString GetFullyQualifiedText() const
Function GetFullyQualifiedText returns the fully qualified field text by allowing for the part suffix...
Definition: sch_field.cpp:80
virtual void DrawArc(const VECTOR2D &aCenterPoint, double aRadius, double aStartAngle, double aEndAngle)
Draw an arc.
virtual const COLOR4D & GetColor(const VIEW_ITEM *aItem, int aLayer) const override
Function GetColor Returns the color that should be used to draw the specific VIEW_ITEM on the specifi...
Definition: sch_painter.cpp:81
#define DANGLING_SYMBOL_SIZE
Definition: general.h:43
int color
Definition: DXF_plotter.cpp:62
Field object used in symbol libraries.
Definition: lib_field.h:59
int GetDefaultLineThickness()
Default line thickness used to draw/plot items having a default thickness line value (i...
Class VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
virtual void DrawBitmap(const BITMAP_BASE &aBitmap)
Draw a bitmap image.
EDA_ITEM * GetParent() const
Definition: base_struct.h:211
bool IsVoid() const
Function IsVoid returns true if the field is either empty or holds "~".
Definition: sch_field.h:116
static int InternalPinDecoSize(const LIB_PIN &aPin)
const std::vector< wxPoint > & GetPolyPoints() const
Definition: lib_polyline.h:68
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_circle.h:86
wxString const GetElectricalTypeName() const
return a translated string for messages giving the electrical type of the pin.
Definition: lib_pin.h:275
#define DASH_MARK_LEN(aLineWidth)
wxPoint GetEndPoint() const
Definition: sch_line.h:80
wxPoint m_End() const
static void orientComponent(LIB_PART *part, int orientation)
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:227
Definition: lib_pin.h:55
int GetFirstRadiusAngle() const
Definition: lib_arc.h:142
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape.
Add new GAL layers here.
Class VIEW_ITEM - is an abstract base class for deriving all objects that can be added to a VIEW...
Definition: view_item.h:84
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_bitmap.h:157
COLOR4D GetDefaultColor() override
Definition: lib_field.cpp:416
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
int GetNameTextSize() const
Definition: lib_pin.h:192
int GetState(int type) const
Definition: base_struct.h:240
int GetPenSize() const override
Function GetPenSize virtual pure.
Definition: sch_sheet.cpp:383
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
int GetOrientation() const
Definition: lib_pin.h:221
void RevertYAxis()
Function RevertYAxis Mirror the rectangle from the X axis (negate Y pos and size) ...
Definition: eda_rect.h:144
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:203
const COLOR4D & GetLayerColor(int aLayer) const
Function GetLayerColor Returns the color used to draw a layer.
Definition: painter.h:219
Field Reference of part, i.e. "IC21".
static const int delta[8][2]
Definition: solve.cpp:112
#define SET_DC(i)
int GetNumberTextSize() const
Definition: lib_pin.h:219
static constexpr int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:699
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg...
Definition: painter.h:360
double GetTextAngle() const
Definition: eda_text.h:177
bool IsBold() const
Definition: eda_text.h:186
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:67
const wxString & GetNumber() const
Definition: lib_pin.h:194
virtual void SetLineWidth(float aLineWidth)
Set the line width.
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:167
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populates a std::vector with SCH_FIELDs.
wxPoint GetStartPoint() const
Definition: sch_line.h:76
Base class for a bus or wire entry.
Definition: sch_bus_entry.h:41
void AddDrawItem(LIB_ITEM *aItem)
Add a new draw aItem to the draw object list.
const wxString & GetName() const
Definition: lib_pin.h:166
virtual wxString GetShownText() const
Returns the string actually shown after processing of the base text.
Definition: eda_text.h:148
static int ExternalPinDecoSize(const LIB_PIN &aPin)
int GetConvert() const
int y1
Definition: transform.h:49
bool ShowPinNames()
COLOR4D Brightened(double aFactor) const
Function Brightened Returns a color that is brighter by a given factor, without modifying object...
Definition: color4d.h:201
int GetPenSize() const override
Definition: lib_pin.cpp:564
int GetSheetNameSize() const
Definition: sch_sheet.h:271
bool IsRoot() const override
For symbols having aliases, IsRoot() indicates the principal item.
void SetFontBold(const bool aBold)
Set bold property of current font.
void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on...
Definition: lib_field.cpp:403
MARKER_SEVERITY GetErrorLevel() const
Definition: marker_base.h:152
Class PAINTER contains all the knowledge about how to draw graphical object onto any particular outpu...
Definition: painter.h:308
bool ShowPinNumbers()
LIB_PART * GetParent() const
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
BITMAP_BASE * GetImage()
Definition: sch_bitmap.h:65
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
static COLOR4D selectedBrightening(const COLOR4D &aColor)
Definition: sch_painter.cpp:87
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_junction.h:103
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Class LIB_ITEM definition.
virtual void StrokeText(const wxString &aText, const VECTOR2D &aPosition, double aRotationAngle)
Draws a vector type text using preloaded Newstroke font.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:143
std::shared_ptr< LIB_PART > PART_SPTR
shared pointer to LIB_PART
ELECTRICAL_PINTYPE GetType() const
Get the electrical type of the pin.
Definition: lib_pin.h:251
#define DOT_MARK_LEN(aLineWidth)
wxPoint GetEnd() const
Define a library symbol object.
static void drawPinDanglingSymbol(GAL *aGal, const VECTOR2I &aPos, const COLOR4D &aColor)
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:138
int m_ScalingFactor
Scaling factor for m_Size and m_Corners (can set the physical size)
Definition: marker_base.h:55
void CreateGraphicShape(std::vector< wxPoint > &aPoints, const wxPoint &aPos) override
Calculate the graphic shape (a polygon) associated to the text.
Definition: sch_text.cpp:835
int GetRadius() const
Definition: lib_arc.h:138
#define OUTSIDE
void triLine(const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c)
int GetFileNameSize() const
Definition: sch_sheet.h:275
a few functions useful in geometry calculations.
void SetTextMirrored(const bool aMirrored)
Set a mirrored property of text.
int GetUnit() const
wxPoint Centre() const
Definition: eda_rect.h:60
void SetVerticalJustify(const EDA_TEXT_VJUSTIFY_T aVerticalJustify)
Set the vertical justify for text drawing.
bool IsVisible() const
Return the visibility status of the draw object.
Definition: lib_pin.h:362
static VECTOR2D mapCoords(const wxPoint &aCoord)
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_sheet.h:547
int GetLineStyle() const
Definition: sch_line.cpp:269
wxString GetFileName(void) const
Return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:661
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:42
void SetEndPosition(const wxPoint &aPosition)
Definition: lib_rectangle.h:67
wxPoint GetFileNamePosition()
Definition: sch_sheet.cpp:408
virtual void Scale(const VECTOR2D &aScale)
Scale the context.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
LIB_PART * GetPart() const
Get the shared LIB_PART.
double GetImageScale() const
Definition: sch_bitmap.h:94
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_pin.h:463
void Move(const wxPoint &aPosition) override
Move a draw object to aPosition.
bool ClipLine(const EDA_RECT *aClipBox, int &x1, int &y1, int &x2, int &y2)
Test if any part of a line falls within the bounds of a rectangle.
int GetPenSize() const override
Definition: lib_text.cpp:213
void Normalize()
Function Normalize ensures that the height ant width are positive.
const wxString & GetDocFileName() const
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:204
void CreateGraphicShape(std::vector< wxPoint > &aPoints, const wxPoint &Pos) override
Calculate the graphic shape (a polygon) associated to the text.
Definition: sch_text.cpp:1096
int GetRadius() const
Definition: lib_circle.h:103
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
Definition the SCH_COMPONENT class for Eeschema.
COLOR4D m_backgroundColor
The background color.
Definition: painter.h:292
virtual int GetPenSize() const =0
const int scale
bool IsDanglingStart() const
Definition: sch_bus_entry.h:51
const wxString & GetName() const override
virtual void Restore()
Restore the context.
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList)
Draw a polygon.
Segment description base class to describe items which have 2 end points (track, wire, draw line ...)
Definition: sch_line.h:41
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
const EDA_RECT GetBoundingBox() const override
Definition: lib_text.cpp:312
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
Definition: sch_field.cpp:252
bool IsVisible() const
Definition: lib_field.h:166
#define max(a, b)
Definition: auxiliary.h:86
bool isUnitAndConversionShown(const LIB_ITEM *aItem)
bool IsEndDangling() const
Definition: sch_line.h:162
bool IsMirrored() const
Definition: eda_text.h:192
bool IsVisible() const
Definition: eda_text.h:189
#define HANDLE_ITEM(type_id, type_name)
void SetText(const wxString &aText) override
Sets the text item string to aText.
Definition: lib_text.cpp:350
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:259
wxPoint GetSheetNamePosition()
Definition: sch_sheet.cpp:389
size_t i
Definition: json11.cpp:597
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
wxPoint GetPosition() const override
Function GetPosition.
virtual wxPoint GetSchematicTextOffset() const
Definition: sch_text.cpp:144
#define DASH_GAP_LEN(aLineWidth)
#define TARGET_PIN_RADIUS
Definition: lib_pin.h:43
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
bool IsVerticalOrientation() const
Definition: sch_sheet.cpp:221
Class COLORS_DESIGN_SETTINGS is a list of color settings for designs in Pcbnew.
bool IsPowerConnection() const
Return whether this pin forms an implicit power connection: i.e., is hidden and of type POWER_IN...
Definition: lib_pin.h:368
Definition of class LIB_EDIT_FRAME.
void SetGlyphSize(const VECTOR2D aGlyphSize)
Set the font glyph size.
int GetPenSize() const override
Function GetPenSize virtual pure.
Definition: sch_line.cpp:296
int GetPenSize() const override
Definition: lib_field.cpp:110
bool IsStartDangling() const
Definition: sch_line.h:161
const wxSize & GetTextSize() const
Definition: eda_text.h:228
virtual void Save()
Save the context.
void SetHorizontalJustify(const EDA_TEXT_HJUSTIFY_T aHorizontalJustify)
Set the horizontal justify for text drawing.
Definition for part library class.
Definition of the SCH_FIELD class for Eeschema.
void draw(LIB_RECTANGLE *, int)
#define INSIDE
int GetSize() const
double GetTextAngleRadians() const
Definition: eda_text.h:180
void ImportLegacyColors(const COLORS_DESIGN_SETTINGS *aSettings) override
Function ImportLegacyColors Loads a list of color settings for layers.
Definition: sch_painter.cpp:69
static int GetEffectiveSymbolSize()
wxString GetName() const
Definition: sch_sheet.h:267
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
#define PIN_TEXT_MARGIN
int GetLength()
Definition: lib_pin.h:301
#define VALUE
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:235
static void drawDanglingSymbol(GAL *aGal, const wxPoint &aPos)
Implementation of the label properties dialog.
wxSize GetSize()
Definition: sch_sheet.h:281
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_rectangle.h:91
SCH_RENDER_SETTINGS m_schSettings
Definition: sch_painter.h:165
void GetFields(LIB_FIELDS &aList)
Return a list of fields within this part.
Class GAL is the abstract interface for drawing on a 2D-surface.
virtual int GetPenSize() const
Function GetPenSize virtual pure.
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_arc.h:121
int GetConvert() const
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
wxPoint GetPosition() const override
Function GetPosition.
#define IS_MOVED
Item being moved.
Definition: base_struct.h:113