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