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  * Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 
28 #include <sch_item.h>
29 
30 #include <bezier_curves.h>
31 #include <class_libentry.h>
32 #include <class_library.h>
33 #include <connection_graph.h>
37 #include <gr_text.h>
38 #include <lib_arc.h>
39 #include <lib_bezier.h>
40 #include <lib_circle.h>
41 #include <lib_field.h>
42 #include <lib_item.h>
43 #include <lib_pin.h>
44 #include <lib_polyline.h>
45 #include <lib_rectangle.h>
46 #include <lib_text.h>
47 #include <math/util.h>
48 #include <plotter.h>
49 #include <sch_bitmap.h>
50 #include <sch_bus_entry.h>
51 #include <sch_component.h>
52 #include <sch_edit_frame.h>
53 #include <sch_field.h>
54 #include <sch_junction.h>
55 #include <sch_line.h>
56 #include <sch_marker.h>
57 #include <sch_no_connect.h>
58 #include <sch_sheet.h>
59 #include <sch_text.h>
60 #include <schematic.h>
62 #include <view/view.h>
63 #include <kiface_i.h>
64 #include <default_values.h>
65 #include <advanced_config.h>
66 #include "sch_painter.h"
67 
68 namespace KIGFX
69 {
70 
72  m_ShowUnit( 0 ),
73  m_ShowConvert( 0 ),
74  m_ShowHiddenText( true ),
75  m_ShowHiddenPins( true ),
76  m_ShowPinsElectricalType( true ),
77  m_ShowDisabled( false ),
78  m_ShowUmbilicals( true ),
79  m_OverrideItemColors( false ),
80  m_TextOffsetRatio( 0.08 ),
81  m_DefaultWireThickness( DEFAULT_WIRE_THICKNESS * IU_PER_MILS ),
82  m_DefaultBusThickness( DEFAULT_BUS_THICKNESS * IU_PER_MILS ),
83  m_PinSymbolSize( DEFAULT_TEXT_SIZE * IU_PER_MILS / 2 ),
84  m_JunctionSize( DEFAULT_JUNCTION_DIAM * IU_PER_MILS )
85 {
87 
89 }
90 
91 
93 {
94  for( int layer = SCH_LAYER_ID_START; layer < SCH_LAYER_ID_END; layer ++)
95  m_layerColors[ layer ] = aSettings->GetColor( layer );
96 
97  for( int layer = GAL_LAYER_ID_START; layer < GAL_LAYER_ID_END; layer ++)
98  m_layerColors[ layer ] = aSettings->GetColor( layer );
99 
101 
103 
105 }
106 
107 
108 COLOR4D SCH_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer ) const
109 {
110  return m_layerColors[ aLayer ];
111 }
112 
113 
115 {
116  return dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
117 }
118 
119 
133 static LIB_PART* dummy()
134 {
135  static LIB_PART* part;
136 
137  if( !part )
138  {
139  part = new LIB_PART( wxEmptyString );
140 
141  LIB_RECTANGLE* square = new LIB_RECTANGLE( part );
142 
143  square->MoveTo( wxPoint( Mils2iu( -200 ), Mils2iu( 200 ) ) );
144  square->SetEndPosition( wxPoint( Mils2iu( 200 ), Mils2iu( -200 ) ) );
145 
146  LIB_TEXT* text = new LIB_TEXT( part );
147 
148  text->SetTextSize( wxSize( Mils2iu( 150 ), Mils2iu( 150 ) ) );
149  text->SetText( wxString( wxT( "??" ) ) );
150 
151  part->AddDrawItem( square );
152  part->AddDrawItem( text );
153  }
154 
155  return part;
156 }
157 
158 
160  KIGFX::PAINTER( aGal ),
161  m_schematic( nullptr )
162 { }
163 
164 
165 #define HANDLE_ITEM( type_id, type_name ) \
166  case type_id: draw( (type_name *) item, aLayer ); break
167 
168 
169 bool SCH_PAINTER::Draw( const VIEW_ITEM *aItem, int aLayer )
170 {
171  auto item2 = dynamic_cast<const EDA_ITEM*>( aItem );
172  auto item = const_cast<EDA_ITEM*>( item2 );
173 
174  if( !item2 )
175  return false;
176 
177 #ifdef CONNECTIVITY_DEBUG
178 
179  auto sch_item = dynamic_cast<SCH_ITEM*>( item );
180  auto conn = sch_item ? sch_item->Connection( *g_CurrentSheet ) : nullptr;
181 
182  if( conn )
183  {
184  auto pos = item->GetBoundingBox().Centre();
185  auto label = conn->Name( true );
186 
190  m_gal->SetLineWidth( Mils2ui( 2 ) );
191  m_gal->SetGlyphSize( VECTOR2D( Mils2ui( 20 ), Mils2ui( 20 ) ) );
192  m_gal->StrokeText( conn->Name( true ), pos, 0.0, 0 );
193  }
194 
195 #endif
196 
197  switch( item->Type() )
198  {
223 
224  default: return false;
225  }
226 
227  return false;
228 }
229 
230 
232 {
233  if( m_schSettings.m_ShowUnit // showing a specific unit
234  && aItem->GetUnit() // item is unit-specific
235  && aItem->GetUnit() != m_schSettings.m_ShowUnit )
236  {
237  return false;
238  }
239 
240  if( m_schSettings.m_ShowConvert // showing a specific conversion
241  && aItem->GetConvert() // item is conversion-specific
242  && aItem->GetConvert() != m_schSettings.m_ShowConvert )
243  {
244  return false;
245  }
246 
247  return true;
248 }
249 
250 
252 {
253  const MATRIX3x3D& matrix = m_gal->GetScreenWorldMatrix();
254 
255  // For best visuals the selection width must be a cross between the zoom level and the
256  // default line width.
257  return (float) fabs( matrix.GetScale().x * 2.75 ) + Mils2iu( eeconfig()->m_Selection.thickness );
258 }
259 
260 
261 COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM* aItem, int aLayer, bool aDrawingShadows )
262 {
264 
265  if( aItem->Type() == SCH_LINE_T )
266  {
267  COLOR4D lineColor = static_cast<const SCH_LINE*>( aItem )->GetLineColor();
268 
269  if( lineColor != COLOR4D::UNSPECIFIED )
270  color = lineColor;
271  }
272  else if( aItem->Type() == SCH_BUS_WIRE_ENTRY_T )
273  {
274  COLOR4D busEntryColor = static_cast<const SCH_BUS_WIRE_ENTRY*>( aItem )->GetStrokeColor();
275 
276  if( busEntryColor != COLOR4D::UNSPECIFIED )
277  color = busEntryColor;
278  }
279  else if( aItem->Type() == SCH_JUNCTION_T )
280  {
281  COLOR4D junctionColor = static_cast<const SCH_JUNCTION*>( aItem )->GetColor();
282 
283  if( junctionColor != COLOR4D::UNSPECIFIED )
284  color = junctionColor;
285  }
286  else if( aItem->Type() == SCH_SHEET_T )
287  {
288  SCH_SHEET* sheet = (SCH_SHEET*) aItem;
289 
291  color = m_schSettings.GetLayerColor( aLayer );
292  else if( aLayer == LAYER_SHEET )
293  color = sheet->GetBorderColor();
294  else if( aLayer == LAYER_SHEET_BACKGROUND )
295  color = sheet->GetBackgroundColor();
296 
297  if( color == COLOR4D::UNSPECIFIED )
298  color = m_schSettings.GetLayerColor( aLayer );
299  }
300 
301  if( aItem->IsBrightened() && !aDrawingShadows ) // Selection disambiguation, etc.
302  {
304 
305  if( aLayer == LAYER_DEVICE_BACKGROUND || aLayer == LAYER_SHEET_BACKGROUND )
306  color = color.WithAlpha( 0.2 );
307  }
308  else if( aItem->IsSelected() )
309  {
310  if( aDrawingShadows )
312  }
313 
315  color = color.Darken( 0.5f );
316 
317  return color;
318 }
319 
320 
321 float SCH_PAINTER::getLineWidth( const LIB_ITEM* aItem, bool aDrawingShadows )
322 {
323  float width = (float) std::max( aItem->GetPenWidth(), m_schSettings.GetDefaultPenWidth() );
324 
325  if( aItem->IsSelected() && aDrawingShadows )
326  width += getShadowWidth();
327 
328  return width;
329 }
330 
331 
332 float SCH_PAINTER::getLineWidth( const SCH_ITEM* aItem, bool aDrawingShadows )
333 {
334  wxCHECK( aItem, static_cast<float>( m_schSettings.m_DefaultWireThickness ) );
335 
336  float width = (float) aItem->GetPenWidth();
337 
338  if( aItem->IsSelected() && aDrawingShadows )
339  width += getShadowWidth();
340 
341  return std::max( width, 1.0f );
342 }
343 
344 
345 float SCH_PAINTER::getTextThickness( const SCH_TEXT* aItem, bool aDrawingShadows )
346 {
347  float width = (float) aItem->GetEffectiveTextPenWidth( m_schSettings.GetDefaultPenWidth() );
348 
349  if( aItem->IsSelected() && aDrawingShadows )
350  width += getShadowWidth();
351 
352  return width;
353 }
354 
355 
356 float SCH_PAINTER::getTextThickness( const SCH_FIELD* aItem, bool aDrawingShadows )
357 {
358  float width = (float) aItem->GetEffectiveTextPenWidth( m_schSettings.GetDefaultPenWidth() );
359 
360  if( aItem->IsSelected() && aDrawingShadows )
361  width += getShadowWidth();
362 
363  return width;
364 }
365 
366 
367 float SCH_PAINTER::getTextThickness( const LIB_FIELD* aItem, bool aDrawingShadows )
368 {
369  float width = (float) std::max( aItem->GetEffectiveTextPenWidth(),
371 
372  if( aItem->IsSelected() && aDrawingShadows )
373  width += getShadowWidth();
374 
375  return width;
376 }
377 
378 
379 float SCH_PAINTER::getTextThickness( const LIB_TEXT* aItem, bool aDrawingShadows )
380 {
381  float width = (float) std::max( aItem->GetEffectiveTextPenWidth(),
383 
384  if( aItem->IsSelected() && aDrawingShadows )
385  width += getShadowWidth();
386 
387  return width;
388 }
389 
390 
391 void SCH_PAINTER::strokeText( const wxString& aText, const VECTOR2D& aPosition, double aAngle )
392 {
393  m_gal->StrokeText( aText, aPosition, aAngle );
394 }
395 
396 
397 void SCH_PAINTER::draw( LIB_PART *aPart, int aLayer, bool aDrawFields, int aUnit, int aConvert )
398 {
399  if( !aUnit )
400  aUnit = m_schSettings.m_ShowUnit;
401 
402  if( !aConvert )
403  aConvert = m_schSettings.m_ShowConvert;
404 
405  std::unique_ptr< LIB_PART > tmpPart;
406  LIB_PART* drawnPart = aPart;
407 
408  if( aPart->IsAlias() )
409  {
410  tmpPart = aPart->Flatten();
411  drawnPart = tmpPart.get();
412  }
413 
414  for( auto& item : drawnPart->GetDrawItems() )
415  {
416  if( !aDrawFields && item.Type() == LIB_FIELD_T )
417  continue;
418 
419  if( aUnit && item.GetUnit() && aUnit != item.GetUnit() )
420  continue;
421 
422  if( aConvert && item.GetConvert() && aConvert != item.GetConvert() )
423  continue;
424 
425  Draw( &item, aLayer );
426  }
427 }
428 
429 
430 static VECTOR2D mapCoords( const wxPoint& aCoord )
431 {
432  return VECTOR2D( aCoord.x, -aCoord.y );
433 }
434 
435 
436 void SCH_PAINTER::triLine( const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c )
437 {
438  m_gal->DrawLine( a, b );
439  m_gal->DrawLine( b, c );
440 }
441 
442 
443 bool SCH_PAINTER::setDeviceColors( const LIB_ITEM* aItem, int aLayer )
444 {
445  switch( aLayer )
446  {
448  if( aItem->IsSelected() )
449  {
450  m_gal->SetIsFill( false );
451  m_gal->SetIsStroke( true );
452  m_gal->SetLineWidth( getLineWidth( aItem, true ) );
453  m_gal->SetStrokeColor( getRenderColor( aItem, LAYER_DEVICE, true ) );
454  m_gal->SetFillColor( getRenderColor( aItem, LAYER_DEVICE, true ) );
455  return true;
456  }
457 
458  return false;
459 
461  if( aItem->GetFillMode() == FILLED_WITH_BG_BODYCOLOR )
462  {
463  COLOR4D fillColor = getRenderColor( aItem, LAYER_DEVICE_BACKGROUND, false );
464 
465  // These actions place the item over others, so allow a modest transparency here
466  if( aItem->IsMoving() || aItem->IsDragging() || aItem->IsResized() )
467  fillColor = fillColor.WithAlpha( 0.75 );
468 
470  m_gal->SetFillColor( fillColor );
471  m_gal->SetIsStroke( false );
472  return true;
473  }
474 
475  return false;
476 
477  case LAYER_DEVICE:
478  m_gal->SetIsFill( aItem->GetFillMode() == FILLED_SHAPE );
479  m_gal->SetFillColor( getRenderColor( aItem, LAYER_DEVICE, false ) );
480 
481  if( aItem->GetPenWidth() > 0 || aItem->GetFillMode() == NO_FILL )
482  {
483  m_gal->SetIsStroke( true );
484  m_gal->SetLineWidth( getLineWidth( aItem, false ) );
485  m_gal->SetStrokeColor( getRenderColor( aItem, LAYER_DEVICE, false ) );
486  }
487  else
488  {
489  m_gal->SetIsStroke( false );
490  }
491 
492  return true;
493 
494  default:
495  return false;
496  }
497 }
498 
499 
501 {
502  if( aLayer == LAYER_SELECTION_SHADOWS && eeconfig()->m_Selection.fill_shapes )
503  m_gal->SetIsFill( true );
504 }
505 
506 
507 void SCH_PAINTER::draw( LIB_RECTANGLE *aRect, int aLayer )
508 {
509  if( !isUnitAndConversionShown( aRect ) )
510  return;
511 
512  if( setDeviceColors( aRect, aLayer ) )
513  {
514  fillIfSelection( aLayer );
515  m_gal->DrawRectangle( mapCoords( aRect->GetPosition() ), mapCoords( aRect->GetEnd() ) );
516  }
517 }
518 
519 
520 void SCH_PAINTER::draw( LIB_CIRCLE *aCircle, int aLayer )
521 {
522  if( !isUnitAndConversionShown( aCircle ) )
523  return;
524 
525  if( setDeviceColors( aCircle, aLayer ) )
526  {
527  fillIfSelection( aLayer );
528  m_gal->DrawCircle( mapCoords( aCircle->GetPosition() ), aCircle->GetRadius() );
529  }
530 }
531 
532 
533 void SCH_PAINTER::draw( LIB_ARC *aArc, int aLayer )
534 {
535  if( !isUnitAndConversionShown( aArc ) )
536  return;
537 
538  if( setDeviceColors( aArc, aLayer ) )
539  {
540  int sai = aArc->GetFirstRadiusAngle();
541  int eai = aArc->GetSecondRadiusAngle();
542 
553  if( !TRANSFORM().MapAngles( &sai, &eai ) )
554  {
555  LIB_ARC new_arc( *aArc );
556 
557  new_arc.SetStart( aArc->GetEnd() );
558  new_arc.SetEnd( aArc->GetStart() );
559  new_arc.CalcRadiusAngles();
560  sai = new_arc.GetFirstRadiusAngle();
561  eai = new_arc.GetSecondRadiusAngle();
562  TRANSFORM().MapAngles( &sai, &eai );
563  }
564 
565  double sa = (double) sai * M_PI / 1800.0;
566  double ea = (double) eai * M_PI / 1800.0 ;
567 
568  VECTOR2D pos = mapCoords( aArc->GetPosition() );
569 
570  m_gal->DrawArc( pos, aArc->GetRadius(), sa, ea );
571  }
572 }
573 
574 
575 void SCH_PAINTER::draw( LIB_POLYLINE *aLine, int aLayer )
576 {
577  if( !isUnitAndConversionShown( aLine ) )
578  return;
579 
580  if( setDeviceColors( aLine, aLayer ) )
581  {
582  const std::vector<wxPoint>& pts = aLine->GetPolyPoints();
583  std::deque<VECTOR2D> vtx;
584 
585  for( auto p : pts )
586  vtx.push_back( mapCoords( p ) );
587 
588  fillIfSelection( aLayer );
589  m_gal->DrawPolygon( vtx );
590  }
591 }
592 
593 
594 void SCH_PAINTER::draw( LIB_FIELD *aField, int aLayer )
595 {
596  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
597 
598  if( drawingShadows && !aField->IsSelected() )
599  return;
600 
601  if( !isUnitAndConversionShown( aField ) )
602  return;
603 
604  // Must check layer as fields are sometimes drawn by their parent rather than
605  // directly from the view.
606  int layers[KIGFX::VIEW::VIEW_MAX_LAYERS];
607  int layers_count;
608  bool foundLayer = false;
609 
610  aField->ViewGetLayers( layers, layers_count );
611 
612  for( int i = 0; i < layers_count; ++i )
613  {
614  if( layers[i] == aLayer )
615  foundLayer = true;
616  }
617 
618  if( !foundLayer )
619  return;
620 
621  COLOR4D color = getRenderColor( aField, aLayer, drawingShadows );
622 
623  if( !( aField->IsVisible() || aField->IsForceVisible() ) )
624  {
626  color = getRenderColor( aField, LAYER_HIDDEN, drawingShadows );
627  else
628  return;
629  }
630 
631  m_gal->SetLineWidth( getTextThickness( aField, drawingShadows ) );
632  m_gal->SetIsFill( false );
633  m_gal->SetIsStroke( true );
635 
636  auto pos = mapCoords( aField->GetPosition() );
637 
638  if( drawingShadows && eeconfig()->m_Selection.text_as_box )
639  {
640  EDA_RECT boundaryBox = aField->GetBoundingBox();
641 
642  m_gal->SetIsFill( true );
644  m_gal->SetLineWidth( m_gal->GetLineWidth() * 0.5 );
645  boundaryBox.RevertYAxis();
646 
647  m_gal->DrawRectangle( mapCoords( boundaryBox.GetPosition() ),
648  mapCoords( boundaryBox.GetEnd() ) );
649  }
650  else
651  {
652  m_gal->SetGlyphSize( VECTOR2D( aField->GetTextSize() ) );
653  m_gal->SetFontItalic( aField->IsItalic() );
654 
657 
658  double orient = aField->GetTextAngleRadians();
659 
660  strokeText( aField->GetText(), pos, orient );
661  }
662 
663  // Draw the umbilical line
664  if( aField->IsMoving() && m_schSettings.m_ShowUmbilicals )
665  {
667  m_gal->SetStrokeColor( COLOR4D( 0.0, 0.0, 1.0, 1.0 ) );
668  m_gal->DrawLine( pos, wxPoint( 0, 0 ) );
669  }
670 }
671 
672 
673 void SCH_PAINTER::draw( LIB_TEXT *aText, int aLayer )
674 {
675  if( !isUnitAndConversionShown( aText ) )
676  return;
677 
678  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
679 
680  if( drawingShadows && !aText->IsSelected() )
681  return;
682 
683  COLOR4D color = getRenderColor( aText, LAYER_DEVICE, drawingShadows );
684 
685  if( !aText->IsVisible() )
686  {
688  color = getRenderColor( aText, LAYER_HIDDEN, drawingShadows );
689  else
690  return;
691  }
692 
693  EDA_RECT bBox = aText->GetBoundingBox();
694  bBox.RevertYAxis();
695  VECTOR2D pos = mapCoords( bBox.Centre() );
696  double orient = aText->GetTextAngleRadians();
697 
700  m_gal->SetLineWidth( getTextThickness( aText, drawingShadows ) );
701  m_gal->SetIsFill( false );
702  m_gal->SetIsStroke( true );
704  m_gal->SetGlyphSize( VECTOR2D( aText->GetTextSize() ) );
705  m_gal->SetFontBold( aText->IsBold() );
706  m_gal->SetFontItalic( aText->IsItalic() );
707  strokeText( aText->GetText(), pos, orient );
708 }
709 
710 
712 {
715 
716  return aPin.GetNameTextSize() != 0 ? aPin.GetNameTextSize() / 2 : aPin.GetNumberTextSize() / 2;
717 }
718 
719 
720 // Utility for getting the size of the 'external' pin decorators (as a radius)
721 // i.e. the negation circle, the polarity 'slopes' and the nonlogic marker
723 {
726 
727  return aPin.GetNumberTextSize() / 2;
728 }
729 
730 
731 // Draw the target (an open circle) for a pin which has no connection or is being moved.
732 void SCH_PAINTER::drawPinDanglingSymbol( const VECTOR2I& aPos, bool aDrawingShadows )
733 {
734  m_gal->SetIsFill( false );
735  m_gal->SetIsStroke( true );
736  m_gal->SetLineWidth( aDrawingShadows ? getShadowWidth()
738 
740 }
741 
742 
743 void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer )
744 {
745  if( !isUnitAndConversionShown( aPin ) )
746  return;
747 
748  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
749 
750  if( drawingShadows && !aPin->IsSelected() )
751  return;
752 
753  VECTOR2I pos = mapCoords( aPin->GetPosition() );
754  COLOR4D color = getRenderColor( aPin, LAYER_PIN, drawingShadows );
755 
756  if( !aPin->IsVisible() )
757  {
759  {
760  color = getRenderColor( aPin, LAYER_HIDDEN, drawingShadows );
761  }
762  else
763  {
764  if( aPin->HasFlag( IS_DANGLING ) && aPin->IsPowerConnection() )
765  drawPinDanglingSymbol( pos, drawingShadows );
766 
767  return;
768  }
769  }
770 
771  VECTOR2I p0;
772  VECTOR2I dir;
773  int len = aPin->GetLength();
774  int orient = aPin->GetOrientation();
775 
776  switch( orient )
777  {
778  case PIN_UP:
779  p0 = VECTOR2I( pos.x, pos.y - len );
780  dir = VECTOR2I( 0, 1 );
781  break;
782 
783  case PIN_DOWN:
784  p0 = VECTOR2I( pos.x, pos.y + len );
785  dir = VECTOR2I( 0, -1 );
786  break;
787 
788  case PIN_LEFT:
789  p0 = VECTOR2I( pos.x - len, pos.y );
790  dir = VECTOR2I( 1, 0 );
791  break;
792 
793  default:
794  case PIN_RIGHT:
795  p0 = VECTOR2I( pos.x + len, pos.y );
796  dir = VECTOR2I( -1, 0 );
797  break;
798  }
799 
800  VECTOR2D pc;
801 
802  m_gal->SetIsStroke( true );
803  m_gal->SetIsFill( false );
804  m_gal->SetLineWidth( getLineWidth( aPin, drawingShadows ) );
806  m_gal->SetFontBold( false );
807  m_gal->SetFontItalic( false );
808 
809  const int radius = externalPinDecoSize( *aPin );
810  const int diam = radius*2;
811  const int clock_size = internalPinDecoSize( *aPin );
812 
813  if( aPin->GetType() == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol
814  {
815  m_gal->DrawLine( p0, pos );
816 
817  m_gal->DrawLine( pos + VECTOR2D( -1, -1 ) * TARGET_PIN_RADIUS,
818  pos + VECTOR2D( 1, 1 ) * TARGET_PIN_RADIUS );
819  m_gal->DrawLine( pos + VECTOR2D( 1, -1 ) * TARGET_PIN_RADIUS ,
820  pos + VECTOR2D( -1, 1 ) * TARGET_PIN_RADIUS );
821 
822  aPin->ClearFlags( IS_DANGLING ); // PIN_NC pin type is always not connected and dangling.
823  }
824  else
825  {
826  switch( aPin->GetShape() )
827  {
829  m_gal->DrawLine( p0, pos );
830  break;
831 
833  m_gal->DrawCircle( p0 + dir * radius, radius );
834  m_gal->DrawLine( p0 + dir * ( diam ), pos );
835  break;
836 
838  pc = p0 - dir * clock_size ;
839 
840  triLine( p0 + VECTOR2D( dir.y, -dir.x) * clock_size,
841  pc,
842  p0 + VECTOR2D( -dir.y, dir.x) * clock_size );
843 
844  m_gal->DrawCircle( p0 + dir * radius, radius );
845  m_gal->DrawLine( p0 + dir * ( diam ), pos );
846  break;
847 
850  pc = p0 - dir * clock_size ;
851 
852  triLine( p0 + VECTOR2D( dir.y, -dir.x) * clock_size,
853  pc,
854  p0 + VECTOR2D( -dir.y, dir.x) * clock_size );
855 
856  if( !dir.y )
857  {
858  triLine( p0 + VECTOR2D(dir.x, 0) * diam,
859  p0 + VECTOR2D(dir.x, -1) * diam,
860  p0 );
861  }
862  else /* MapX1 = 0 */
863  {
864  triLine( p0 + VECTOR2D( 0, dir.y) * diam,
865  p0 + VECTOR2D(-1, dir.y) * diam,
866  p0 );
867  }
868 
869  m_gal->DrawLine( p0, pos );
870  break;
871 
873  m_gal->DrawLine( p0, pos );
874 
875  if( !dir.y )
876  {
877  triLine( p0 + VECTOR2D( 0, clock_size ),
878  p0 + VECTOR2D( -dir.x * clock_size, 0 ),
879  p0 + VECTOR2D( 0, -clock_size ) );
880  }
881  else
882  {
883  triLine( p0 + VECTOR2D( clock_size, 0 ),
884  p0 + VECTOR2D( 0, -dir.y * clock_size ),
885  p0 + VECTOR2D( -clock_size, 0 ) );
886  }
887  break;
888 
890  m_gal->DrawLine( p0, pos );
891 
892  if( !dir.y )
893  {
894  triLine( p0 + VECTOR2D(dir.x, 0) * diam,
895  p0 + VECTOR2D(dir.x, -1) * diam,
896  p0 );
897  }
898  else /* MapX1 = 0 */
899  {
900  triLine( p0 + VECTOR2D( 0, dir.y) * diam,
901  p0 + VECTOR2D(-1, dir.y) * diam,
902  p0 );
903  }
904  break;
905 
906  case GRAPHIC_PINSHAPE::OUTPUT_LOW: // IEEE symbol "Active Low Output"
907  m_gal->DrawLine( p0, pos );
908 
909  if( !dir.y ) // Horizontal pin
910  m_gal->DrawLine( p0 - VECTOR2D( 0, diam ), p0 + VECTOR2D( dir.x, 0 ) * diam );
911  else // Vertical pin
912  m_gal->DrawLine( p0 - VECTOR2D( diam, 0 ), p0 + VECTOR2D( 0, dir.y ) * diam );
913  break;
914 
915  case GRAPHIC_PINSHAPE::NONLOGIC: // NonLogic pin symbol
916  m_gal->DrawLine( p0, pos );
917 
918  m_gal->DrawLine( p0 - VECTOR2D( dir.x + dir.y, dir.y - dir.x ) * radius,
919  p0 + VECTOR2D( dir.x + dir.y, dir.y - dir.x ) * radius );
920  m_gal->DrawLine( p0 - VECTOR2D( dir.x - dir.y, dir.x + dir.y ) * radius,
921  p0 + VECTOR2D( dir.x - dir.y, dir.x + dir.y ) * radius );
922  break;
923  }
924  }
925 
926 
927  if( aPin->HasFlag( IS_DANGLING ) && ( aPin->IsVisible() || aPin->IsPowerConnection() ) )
928  drawPinDanglingSymbol( pos, drawingShadows );
929 
930  LIB_PART* libEntry = aPin->GetParent();
931 
932  // Draw the labels
933  if( drawingShadows && ( libEntry->Type() == LIB_PART_T || libEntry->IsSelected() )
935  return;
936 
937  int textOffset = libEntry->GetPinNameOffset();
938 
939  float nameLineWidth = getLineWidth( aPin, drawingShadows );
940  nameLineWidth = Clamp_Text_PenSize( nameLineWidth, aPin->GetNameTextSize(), false );
941  float numLineWidth = getLineWidth( aPin, drawingShadows );
942  numLineWidth = Clamp_Text_PenSize( numLineWidth, aPin->GetNumberTextSize(), false );
943 
944  #define PIN_TEXT_MARGIN 4.0
945 
946  // Four locations around a pin where text can be drawn
947  enum { INSIDE = 0, OUTSIDE, ABOVE, BELOW };
948  int size[4] = { 0, 0, 0, 0 };
949  float thickness[4] = { numLineWidth, numLineWidth, numLineWidth, numLineWidth };
950  COLOR4D colour[4];
951  wxString text[4];
952 
953  // TextOffset > 0 means pin NAMES on inside, pin NUMBERS above and nothing below
954  if( textOffset )
955  {
956  size [INSIDE] = libEntry->ShowPinNames() ? aPin->GetNameTextSize() : 0;
957  thickness[INSIDE] = nameLineWidth;
958  colour [INSIDE] = getRenderColor( aPin, LAYER_PINNAM, drawingShadows );
959  text [INSIDE] = aPin->GetName();
960 
961  size [ABOVE] = libEntry->ShowPinNumbers() ? aPin->GetNumberTextSize() : 0;
962  thickness[ABOVE] = numLineWidth;
963  colour [ABOVE] = getRenderColor( aPin, LAYER_PINNUM, drawingShadows );
964  text [ABOVE] = aPin->GetNumber();
965  }
966  // Otherwise pin NAMES go above and pin NUMBERS go below
967  else
968  {
969  size [ABOVE] = libEntry->ShowPinNames() ? aPin->GetNameTextSize() : 0;
970  thickness[ABOVE] = nameLineWidth;
971  colour [ABOVE] = getRenderColor( aPin, LAYER_PINNAM, drawingShadows );
972  text [ABOVE] = aPin->GetName();
973 
974  size [BELOW] = libEntry->ShowPinNumbers() ? aPin->GetNumberTextSize() : 0;
975  thickness[BELOW] = numLineWidth;
976  colour [BELOW] = getRenderColor( aPin, LAYER_PINNUM, drawingShadows );
977  text [BELOW] = aPin->GetNumber();
978  }
979 
981  {
982  size [OUTSIDE] = std::max( aPin->GetNameTextSize() * 3 / 4, Millimeter2iu( 0.7 ) );
983  thickness[OUTSIDE] = float( size[OUTSIDE] ) / 6.0F;
984  colour [OUTSIDE] = getRenderColor( aPin, LAYER_NOTES, drawingShadows );
985  text [OUTSIDE] = aPin->GetElectricalTypeName();
986  }
987 
988  if( !aPin->IsVisible() )
989  {
990  for( COLOR4D& c : colour )
991  c = getRenderColor( aPin, LAYER_HIDDEN, drawingShadows );
992  }
993 
994  int insideOffset = textOffset;
995  int outsideOffset = 10;
996  float lineThickness = (float) m_schSettings.GetDefaultPenWidth();
997  float aboveOffset = Mils2iu( PIN_TEXT_MARGIN ) + ( thickness[ABOVE] + lineThickness ) / 2.0;
998  float belowOffset = Mils2iu( PIN_TEXT_MARGIN ) + ( thickness[BELOW] + lineThickness ) / 2.0;
999 
1000  if( drawingShadows )
1001  {
1002  for( float& t : thickness )
1003  t += getShadowWidth();
1004 
1005  insideOffset -= KiROUND( getShadowWidth() / 2 );
1006  outsideOffset -= KiROUND( getShadowWidth() / 2 );
1007  }
1008 
1009  #define SET_DC( i ) \
1010  m_gal->SetGlyphSize( VECTOR2D( size[i], size[i] ) ); \
1011  m_gal->SetLineWidth( thickness[i] ); \
1012  m_gal->SetStrokeColor( colour[i] )
1013 
1014  switch( orient )
1015  {
1016  case PIN_LEFT:
1017  if( size[INSIDE] )
1018  {
1019  SET_DC( INSIDE );
1022  strokeText( text[INSIDE], pos + VECTOR2D( -insideOffset - len, 0 ), 0 );
1023  }
1024  if( size[OUTSIDE] )
1025  {
1026  SET_DC( OUTSIDE );
1029  strokeText( text[OUTSIDE], pos + VECTOR2D( outsideOffset, 0 ), 0 );
1030  }
1031  if( size[ABOVE] )
1032  {
1033  SET_DC( ABOVE );
1036  strokeText( text[ABOVE], pos + VECTOR2D( -len / 2.0, -aboveOffset ), 0 );
1037  }
1038  if( size[BELOW] )
1039  {
1040  SET_DC( BELOW );
1043  strokeText( text[BELOW], pos + VECTOR2D( -len / 2.0, belowOffset ), 0 );
1044  }
1045  break;
1046 
1047  case PIN_RIGHT:
1048  if( size[INSIDE] )
1049  {
1050  SET_DC( INSIDE );
1054  strokeText( text[INSIDE], pos + VECTOR2D( insideOffset + len, 0 ), 0 );
1055  }
1056  if( size[OUTSIDE] )
1057  {
1058  SET_DC( OUTSIDE );
1061  strokeText( text[OUTSIDE], pos + VECTOR2D( -outsideOffset, 0 ), 0 );
1062  }
1063  if( size[ABOVE] )
1064  {
1065  SET_DC( ABOVE );
1068  strokeText( text[ABOVE], pos + VECTOR2D( len / 2.0, -aboveOffset ), 0 );
1069  }
1070  if( size[BELOW] )
1071  {
1072  SET_DC( BELOW );
1075  strokeText( text[BELOW], pos + VECTOR2D( len / 2.0, belowOffset ), 0 );
1076  }
1077  break;
1078 
1079  case PIN_DOWN:
1080  if( size[INSIDE] )
1081  {
1082  SET_DC( INSIDE );
1085  strokeText( text[INSIDE], pos + VECTOR2D( 0, insideOffset + len ), M_PI / 2 );
1086  }
1087  if( size[OUTSIDE] )
1088  {
1089  SET_DC( OUTSIDE );
1092  strokeText( text[OUTSIDE], pos + VECTOR2D( 0, -outsideOffset ), M_PI / 2 );
1093  }
1094  if( size[ABOVE] )
1095  {
1096  SET_DC( ABOVE );
1099  strokeText( text[ABOVE], pos + VECTOR2D( -aboveOffset, len / 2.0 ), M_PI / 2 );
1100  }
1101  if( size[BELOW] )
1102  {
1103  SET_DC( BELOW );
1106  strokeText( text[BELOW], pos + VECTOR2D( belowOffset, len / 2.0 ), M_PI / 2 );
1107  }
1108  break;
1109 
1110  case PIN_UP:
1111  if( size[INSIDE] )
1112  {
1113  SET_DC( INSIDE );
1116  strokeText( text[INSIDE], pos + VECTOR2D( 0, -insideOffset - len ), M_PI / 2 );
1117  }
1118  if( size[OUTSIDE] )
1119  {
1120  SET_DC( OUTSIDE );
1123  strokeText( text[OUTSIDE], pos + VECTOR2D( 0, outsideOffset ), M_PI / 2 );
1124  }
1125  if( size[ABOVE] )
1126  {
1127  SET_DC( ABOVE );
1130  strokeText( text[ABOVE], pos + VECTOR2D( -aboveOffset, -len / 2.0 ), M_PI / 2 );
1131  }
1132  if( size[BELOW] )
1133  {
1134  SET_DC( BELOW );
1137  strokeText( text[BELOW], pos + VECTOR2D( belowOffset, -len / 2.0 ), M_PI / 2 );
1138  }
1139  break;
1140 
1141  default:
1142  wxFAIL_MSG( "Unknown pin orientation" );
1143  }
1144 }
1145 
1146 
1147 void SCH_PAINTER::draw( LIB_BEZIER *aCurve, int aLayer )
1148 {
1149  if( !isUnitAndConversionShown( aCurve ) )
1150  return;
1151 
1152  if( setDeviceColors( aCurve, aLayer ) )
1153  {
1154  BEZIER_POLY poly ( aCurve->GetPoints() );
1155  std::vector<wxPoint> pts;
1156  std::deque<VECTOR2D> pts_xformed;
1157  poly.GetPoly( pts );
1158 
1159  for( const auto &p : pts )
1160  pts_xformed.push_back( mapCoords( p ) );
1161 
1162  m_gal->DrawPolygon( pts_xformed );
1163  }
1164 }
1165 
1166 
1167 // Draw the target (an open square) for a wire or label which has no connection or is
1168 // being moved.
1169 void SCH_PAINTER::drawDanglingSymbol( const wxPoint& aPos, int aWidth, bool aDrawingShadows )
1170 {
1171  wxPoint radius( aWidth + Mils2iu( DANGLING_SYMBOL_SIZE / 2 ),
1172  aWidth + Mils2iu( DANGLING_SYMBOL_SIZE /2 ) );
1173 
1174  m_gal->SetIsStroke( true );
1175  m_gal->SetIsFill( false );
1176  m_gal->SetLineWidth( aDrawingShadows ? getShadowWidth()
1178 
1179  m_gal->DrawRectangle( aPos - radius, aPos + radius );
1180 }
1181 
1182 
1183 void SCH_PAINTER::draw( SCH_JUNCTION *aJct, int aLayer )
1184 {
1185  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1186 
1187  if( drawingShadows && !aJct->IsSelected() )
1188  return;
1189 
1190  COLOR4D color = getRenderColor( aJct, aJct->GetLayer(), drawingShadows );
1191 
1192  int junctionSize = aJct->GetDiameter() / 2;
1193 
1194  m_gal->SetIsStroke( drawingShadows );
1195  m_gal->SetLineWidth( getLineWidth( aJct, drawingShadows ) );
1197  m_gal->SetIsFill( !drawingShadows );
1198  m_gal->SetFillColor( color );
1199  m_gal->DrawCircle( aJct->GetPosition(), junctionSize );
1200 }
1201 
1202 
1203 void SCH_PAINTER::draw( SCH_LINE *aLine, int aLayer )
1204 {
1205  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1206 
1207  if( drawingShadows && !aLine->IsSelected() )
1208  return;
1209 
1210  COLOR4D color = getRenderColor( aLine, aLine->GetLayer(), drawingShadows );
1211  float width = getLineWidth( aLine, drawingShadows );
1212  PLOT_DASH_TYPE lineStyle = aLine->GetEffectiveLineStyle();
1213 
1214  m_gal->SetIsStroke( true );
1216  m_gal->SetLineWidth( width );
1217 
1218  if( lineStyle <= PLOT_DASH_TYPE::FIRST_TYPE || drawingShadows )
1219  {
1220  m_gal->DrawLine( aLine->GetStartPoint(), aLine->GetEndPoint() );
1221  }
1222  else
1223  {
1224  VECTOR2D start = aLine->GetStartPoint();
1225  VECTOR2D end = aLine->GetEndPoint();
1226 
1227  EDA_RECT clip( (wxPoint)start, wxSize( end.x - start.x, end.y - start.y ) );
1228  clip.Normalize();
1229 
1230  double theta = atan2( end.y - start.y, end.x - start.x );
1231  double strokes[] = { 1.0, DASH_GAP_LEN( width ), 1.0, DASH_GAP_LEN( width ) };
1232 
1233  switch( lineStyle )
1234  {
1235  default:
1236  case PLOT_DASH_TYPE::DASH:
1237  strokes[0] = strokes[2] = DASH_MARK_LEN( width );
1238  break;
1239  case PLOT_DASH_TYPE::DOT:
1240  strokes[0] = strokes[2] = DOT_MARK_LEN( width );
1241  break;
1243  strokes[0] = DASH_MARK_LEN( width );
1244  strokes[2] = DOT_MARK_LEN( width );
1245  break;
1246  }
1247 
1248  for( size_t i = 0; i < 10000; ++i )
1249  {
1250  // Calculations MUST be done in doubles to keep from accumulating rounding
1251  // errors as we go.
1252  VECTOR2D next( start.x + strokes[ i % 4 ] * cos( theta ),
1253  start.y + strokes[ i % 4 ] * sin( theta ) );
1254 
1255  // Drawing each segment can be done rounded to ints.
1256  wxPoint segStart( KiROUND( start.x ), KiROUND( start.y ) );
1257  wxPoint segEnd( KiROUND( next.x ), KiROUND( next.y ) );
1258 
1259  if( ClipLine( &clip, segStart.x, segStart.y, segEnd.x, segEnd.y ) )
1260  break;
1261  else if( i % 2 == 0 )
1262  m_gal->DrawLine( segStart, segEnd );
1263 
1264  start = next;
1265  }
1266  }
1267 
1268  if( aLine->IsStartDangling() )
1269  drawDanglingSymbol( aLine->GetStartPoint(), getLineWidth( aLine, drawingShadows ),
1270  drawingShadows );
1271 
1272  if( aLine->IsEndDangling() )
1273  drawDanglingSymbol( aLine->GetEndPoint(), getLineWidth( aLine, drawingShadows ),
1274  drawingShadows );
1275 }
1276 
1277 
1278 void SCH_PAINTER::draw( SCH_TEXT *aText, int aLayer )
1279 {
1280  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1281 
1282  if( drawingShadows && !aText->IsSelected() )
1283  return;
1284 
1285  switch( aText->Type() )
1286  {
1287  case SCH_SHEET_PIN_T: aLayer = LAYER_SHEETLABEL; break;
1288  case SCH_HIER_LABEL_T: aLayer = LAYER_HIERLABEL; break;
1289  case SCH_GLOBAL_LABEL_T: aLayer = LAYER_GLOBLABEL; break;
1290  case SCH_LABEL_T: aLayer = LAYER_LOCLABEL; break;
1291  default: aLayer = LAYER_NOTES; break;
1292  }
1293 
1294  COLOR4D color = getRenderColor( aText, aLayer, drawingShadows );
1295 
1296  if( m_schematic )
1297  {
1298  SCH_CONNECTION* conn = aText->Connection( m_schematic->CurrentSheet() );
1299 
1300  if( conn && conn->IsBus() )
1301  color = getRenderColor( aText, LAYER_BUS, drawingShadows );
1302  }
1303 
1304  if( !( aText->IsVisible() || aText->IsForceVisible() ) )
1305  {
1307  color = getRenderColor( aText, LAYER_HIDDEN, drawingShadows );
1308  else
1309  return;
1310  }
1311 
1312  m_gal->SetIsFill( false );
1313  m_gal->SetIsStroke( true );
1314  m_gal->SetLineWidth( getTextThickness( aText, drawingShadows ) );
1316  m_gal->SetTextAttributes( aText );
1317 
1318  VECTOR2D text_offset = aText->GetTextPos() + aText->GetSchematicTextOffset( &m_schSettings );
1319  wxString shownText( aText->GetShownText() );
1320 
1321  if( drawingShadows )
1322  {
1324  {
1325  EDA_RECT bBox = aText->GetBoundingBox();
1326 
1327  m_gal->SetIsFill( true );
1328  m_gal->SetFillColor( color );
1329  m_gal->SetLineWidth( m_gal->GetLineWidth() * 0.5 );
1330  bBox.RevertYAxis();
1331 
1332  m_gal->DrawRectangle( mapCoords( bBox.GetPosition() ), mapCoords( bBox.GetEnd() ) );
1333  return;
1334  }
1335 
1336  switch( aText->GetLabelSpinStyle() )
1337  {
1338  case LABEL_SPIN_STYLE::LEFT: text_offset.x += getShadowWidth() / 2; break;
1339  case LABEL_SPIN_STYLE::UP: text_offset.y += getShadowWidth() / 2; break;
1340  case LABEL_SPIN_STYLE::RIGHT: text_offset.x -= getShadowWidth() / 2; break;
1341  case LABEL_SPIN_STYLE::BOTTOM: text_offset.y -= getShadowWidth() / 2; break;
1342  }
1343  }
1344 
1345  if( !shownText.IsEmpty() )
1346  {
1347  strokeText( shownText, text_offset, aText->GetTextAngleRadians() );
1348  }
1349 
1350  if( aText->IsDangling() )
1351  {
1352  drawDanglingSymbol( aText->GetTextPos(), Mils2iu( DANGLING_SYMBOL_SIZE / 2 ),
1353  drawingShadows );
1354  }
1355 }
1356 
1357 
1358 static void orientPart( LIB_PART* part, int orientation )
1359 {
1360  struct ORIENT
1361  {
1362  int flag;
1363  int n_rots;
1364  int mirror_x;
1365  int mirror_y;
1366  }
1367  orientations[] =
1368  {
1369  { CMP_ORIENT_0, 0, 0, 0 },
1370  { CMP_ORIENT_90, 1, 0, 0 },
1371  { CMP_ORIENT_180, 2, 0, 0 },
1372  { CMP_ORIENT_270, 3, 0, 0 },
1373  { CMP_MIRROR_X + CMP_ORIENT_0, 0, 1, 0 },
1374  { CMP_MIRROR_X + CMP_ORIENT_90, 1, 1, 0 },
1375  { CMP_MIRROR_Y, 0, 0, 1 },
1376  { CMP_MIRROR_X + CMP_ORIENT_270, 3, 1, 0 },
1377  { CMP_MIRROR_Y + CMP_ORIENT_0, 0, 0, 1 },
1378  { CMP_MIRROR_Y + CMP_ORIENT_90, 1, 0, 1 },
1379  { CMP_MIRROR_Y + CMP_ORIENT_180, 2, 0, 1 },
1380  { CMP_MIRROR_Y + CMP_ORIENT_270, 3, 0, 1 }
1381  };
1382 
1383  ORIENT o = orientations[ 0 ];
1384 
1385  for( auto& i : orientations )
1386  {
1387  if( i.flag == orientation )
1388  {
1389  o = i;
1390  break;
1391  }
1392  }
1393 
1394  for( auto& item : part->GetDrawItems() )
1395  {
1396  for( int i = 0; i < o.n_rots; i++ )
1397  item.Rotate( wxPoint(0, 0 ), true );
1398 
1399  if( o.mirror_x )
1400  item.MirrorVertical( wxPoint( 0, 0 ) );
1401 
1402  if( o.mirror_y )
1403  item.MirrorHorizontal( wxPoint( 0, 0 ) );
1404  }
1405 }
1406 
1407 
1408 void SCH_PAINTER::draw( SCH_COMPONENT *aComp, int aLayer )
1409 {
1410  int unit = aComp->GetUnitSelection( &m_schematic->CurrentSheet() );
1411  int convert = aComp->GetConvert();
1412 
1413  // Use dummy part if the actual couldn't be found (or couldn't be locked).
1414  LIB_PART* originalPart = aComp->GetPartRef() ? aComp->GetPartRef().get() : dummy();
1415  LIB_PINS originalPins;
1416  originalPart->GetPins( originalPins, unit, convert );
1417 
1418  // Copy the source so we can re-orient and translate it.
1419  LIB_PART tempPart( *originalPart );
1420  LIB_PINS tempPins;
1421  tempPart.GetPins( tempPins, unit, convert );
1422 
1423  tempPart.SetFlags( aComp->GetFlags() );
1424 
1425  orientPart( &tempPart, aComp->GetOrientation() );
1426 
1427  for( auto& tempItem : tempPart.GetDrawItems() )
1428  {
1429  tempItem.SetFlags( aComp->GetFlags() ); // SELECTED, HIGHLIGHTED, BRIGHTENED
1430  tempItem.MoveTo( tempItem.GetPosition() + (wxPoint) mapCoords( aComp->GetPosition() ) );
1431  }
1432 
1433  // Copy the pin info from the component to the temp pins
1434  for( unsigned i = 0; i < tempPins.size(); ++ i )
1435  {
1436  SCH_PIN* compPin = aComp->GetPin( originalPins[ i ] );
1437  LIB_PIN* tempPin = tempPins[ i ];
1438 
1439  tempPin->ClearFlags();
1440  tempPin->SetFlags( compPin->GetFlags() ); // SELECTED, HIGHLIGHTED, BRIGHTENED
1441 
1442  tempPin->SetName( compPin->GetName() );
1443  tempPin->SetType( compPin->GetType() );
1444  tempPin->SetShape( compPin->GetShape() );
1445 
1446  if( compPin->IsDangling() )
1447  tempPin->SetFlags( IS_DANGLING );
1448  }
1449 
1450  draw( &tempPart, aLayer, false, aComp->GetUnit(), aComp->GetConvert() );
1451 
1452  // The fields are SCH_COMPONENT-specific so don't need to be copied/oriented/translated
1453  for( SCH_FIELD& field : aComp->GetFields() )
1454  draw( &field, aLayer );
1455 }
1456 
1457 
1458 void SCH_PAINTER::draw( SCH_FIELD *aField, int aLayer )
1459 {
1460  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1461 
1462  if( drawingShadows && !aField->IsSelected() )
1463  return;
1464 
1465  aLayer = aField->GetLayer();
1466 
1467  COLOR4D color = getRenderColor( aField, aLayer, drawingShadows );
1468 
1469  if( !( aField->IsVisible() || aField->IsForceVisible() ) )
1470  {
1472  color = getRenderColor( aField, LAYER_HIDDEN, drawingShadows );
1473  else
1474  return;
1475  }
1476 
1477  if( aField->IsVoid() )
1478  return;
1479 
1480  if( drawingShadows && aField->GetParent()->IsSelected()
1482  {
1483  return;
1484  }
1485 
1486  // Calculate the text orientation according to the parent orientation.
1487  int orient = (int) aField->GetTextAngle();
1488 
1489  if( aField->GetParent() && aField->GetParent()->Type() == SCH_COMPONENT_T )
1490  {
1491  if( static_cast<SCH_COMPONENT*>( aField->GetParent() )->GetTransform().y1 )
1492  {
1493  // Rotate component 90 degrees.
1494  if( orient == TEXT_ANGLE_HORIZ )
1495  orient = TEXT_ANGLE_VERT;
1496  else
1497  orient = TEXT_ANGLE_HORIZ;
1498  }
1499  }
1500 
1501  /* Calculate the text justification, according to the component orientation/mirror.
1502  * This is a bit complicated due to cumulative calculations:
1503  * - numerous cases (mirrored or not, rotation)
1504  * - the DrawGraphicText function recalculate also H and H justifications according to the
1505  * text orientation.
1506  * - When a component is mirrored, the text is not mirrored and justifications are
1507  * complicated to calculate
1508  * so the easier way is to use no justifications (centered text) and use GetBoundingBox
1509  * to know the text coordinate considered as centered
1510  */
1511  EDA_RECT boundaryBox = aField->GetBoundingBox();
1512  wxPoint textpos = boundaryBox.Centre();
1513 
1515  m_gal->SetIsStroke( true );
1516 
1517  if( drawingShadows && eeconfig()->m_Selection.text_as_box )
1518  {
1519  m_gal->SetIsFill( true );
1520  m_gal->SetFillColor( color );
1521  m_gal->SetLineWidth( m_gal->GetLineWidth() * 0.5 );
1522  boundaryBox.RevertYAxis();
1523 
1524  m_gal->DrawRectangle( mapCoords( boundaryBox.GetPosition() ),
1525  mapCoords( boundaryBox.GetEnd() ) );
1526  }
1527  else
1528  {
1531  m_gal->SetIsFill( false );
1532  m_gal->SetGlyphSize( VECTOR2D( aField->GetTextSize() ) );
1533  m_gal->SetFontBold( aField->IsBold() );
1534  m_gal->SetFontItalic( aField->IsItalic() );
1535  m_gal->SetTextMirrored( aField->IsMirrored() );
1536  m_gal->SetLineWidth( getTextThickness( aField, drawingShadows ) );
1537 
1538  strokeText( aField->GetShownText(), textpos, orient == TEXT_ANGLE_VERT ? M_PI / 2 : 0 );
1539  }
1540 
1541  // Draw the umbilical line
1542  if( aField->IsMoving() )
1543  {
1544  wxPoint parentPos = aField->GetParentPosition();
1545 
1547  m_gal->SetStrokeColor( COLOR4D( 0.0, 0.0, 1.0, 1.0 ) );
1548  m_gal->DrawLine( textpos, parentPos );
1549  }
1550 }
1551 
1552 
1553 void SCH_PAINTER::draw( SCH_GLOBALLABEL *aLabel, int aLayer )
1554 {
1555  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1556 
1557  if( drawingShadows && !aLabel->IsSelected() )
1558  return;
1559 
1560  COLOR4D color = getRenderColor( aLabel, LAYER_GLOBLABEL, drawingShadows );
1561 
1562  std::vector<wxPoint> pts;
1563  std::deque<VECTOR2D> pts2;
1564 
1565  aLabel->CreateGraphicShape( &m_schSettings, pts, aLabel->GetTextPos() );
1566 
1567  for( auto p : pts )
1568  pts2.emplace_back( VECTOR2D( p.x, p.y ) );
1569 
1570  // the text is drawn inside the graphic shape.
1571  // On Cairo the graphic shape is filled by the background
1572  // before drawing the text ().
1573  // However if the text is selected, it is draw twice:
1574  // first, on LAYER_SELECTION_SHADOWS
1575  // second, on the text layer.
1576  // the second must not erase the first drawing.
1577  bool fillBg = ( aLayer == LAYER_SELECTION_SHADOWS ) || !aLabel->IsSelected();
1578  m_gal->SetIsFill( fillBg );
1580  m_gal->SetIsStroke( true );
1581  m_gal->SetLineWidth( getTextThickness( aLabel, drawingShadows ) );
1583  m_gal->DrawPolyline( pts2 );
1584 
1585  draw( static_cast<SCH_TEXT*>( aLabel ), aLayer );
1586 }
1587 
1588 
1589 void SCH_PAINTER::draw( SCH_HIERLABEL *aLabel, int aLayer )
1590 {
1591  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1592 
1593  if( drawingShadows && !aLabel->IsSelected() )
1594  return;
1595 
1596  COLOR4D color = getRenderColor( aLabel, LAYER_SHEETLABEL, drawingShadows );
1597 
1598  if( m_schematic )
1599  {
1600  SCH_CONNECTION* conn = aLabel->Connection( m_schematic->CurrentSheet() );
1601 
1602  if( conn && conn->IsBus() )
1603  color = getRenderColor( aLabel, LAYER_BUS, drawingShadows );
1604  }
1605 
1606  std::vector<wxPoint> pts;
1607  std::deque<VECTOR2D> pts2;
1608 
1609  aLabel->CreateGraphicShape( &m_schSettings, pts, aLabel->GetTextPos() );
1610 
1611  for( auto p : pts )
1612  pts2.emplace_back( VECTOR2D( p.x, p.y ) );
1613 
1614  m_gal->SetIsFill( true );
1616  m_gal->SetIsStroke( true );
1617  m_gal->SetLineWidth( getTextThickness( aLabel, drawingShadows ) );
1619  m_gal->DrawPolyline( pts2 );
1620 
1621  draw( static_cast<SCH_TEXT*>( aLabel ), aLayer );
1622 }
1623 
1624 void SCH_PAINTER::draw( SCH_SHEET *aSheet, int aLayer )
1625 {
1626  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1627 
1628  if( aLayer == LAYER_HIERLABEL || aLayer == LAYER_SELECTION_SHADOWS )
1629  {
1630  for( SCH_SHEET_PIN* sheetPin : aSheet->GetPins() )
1631  {
1632  if( drawingShadows && !aSheet->IsSelected() && !sheetPin->IsSelected() )
1633  continue;
1634 
1635  if( drawingShadows && aSheet->IsSelected()
1637  {
1638  break;
1639  }
1640 
1641  int width = std::max( aSheet->GetPenWidth(), m_schSettings.GetDefaultPenWidth() );
1642  wxPoint initial_pos = sheetPin->GetTextPos();
1643  wxPoint offset_pos = initial_pos;
1644 
1645  // For aesthetic reasons, the SHEET_PIN is drawn with a small offset of width / 2
1646  switch( sheetPin->GetEdge() )
1647  {
1648  case SHEET_TOP_SIDE: offset_pos.y += KiROUND( width / 2.0 ); break;
1649  case SHEET_BOTTOM_SIDE: offset_pos.y -= KiROUND( width / 2.0 ); break;
1650  case SHEET_RIGHT_SIDE: offset_pos.x -= KiROUND( width / 2.0 ); break;
1651  case SHEET_LEFT_SIDE: offset_pos.x += KiROUND( width / 2.0 ); break;
1652  default: break;
1653  }
1654 
1655  sheetPin->SetTextPos( offset_pos );
1656  draw( static_cast<SCH_HIERLABEL*>( sheetPin ), aLayer );
1657  m_gal->DrawLine( offset_pos, initial_pos );
1658  sheetPin->SetTextPos( initial_pos );
1659  }
1660  }
1661 
1662  VECTOR2D pos = aSheet->GetPosition();
1663  VECTOR2D size = aSheet->GetSize();
1664 
1665  if( aLayer == LAYER_SHEET_BACKGROUND )
1666  {
1668  m_gal->SetIsFill( true );
1669  m_gal->SetIsStroke( false );
1670 
1671  m_gal->DrawRectangle( pos, pos + size );
1672  }
1673 
1674  if( aLayer == LAYER_SHEET || aLayer == LAYER_SELECTION_SHADOWS )
1675  {
1676  m_gal->SetStrokeColor( getRenderColor( aSheet, LAYER_SHEET, drawingShadows ) );
1677  m_gal->SetIsStroke( true );
1678  m_gal->SetLineWidth( getLineWidth( aSheet, drawingShadows ) );
1679  m_gal->SetIsFill( false );
1680 
1681  m_gal->DrawRectangle( pos, pos + size );
1682 
1683  if( drawingShadows && !eeconfig()->m_Selection.draw_selected_children && aSheet->IsSelected() )
1684  return;
1685 
1686  for( SCH_FIELD& field : aSheet->GetFields() )
1687  draw( &field, aLayer );
1688  }
1689 }
1690 
1691 
1692 void SCH_PAINTER::draw( SCH_NO_CONNECT *aNC, int aLayer )
1693 {
1694  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1695 
1696  if( drawingShadows && !aNC->IsSelected() )
1697  return;
1698 
1699  m_gal->SetIsStroke( true );
1700  m_gal->SetLineWidth( getLineWidth( aNC, drawingShadows ) );
1701  m_gal->SetStrokeColor( getRenderColor( aNC, LAYER_NOCONNECT, drawingShadows ) );
1702  m_gal->SetIsFill( false );
1703 
1704  VECTOR2D p = aNC->GetPosition();
1705  int delta = std::max( aNC->GetSize(), m_schSettings.GetDefaultPenWidth() * 3 ) / 2;
1706 
1707  m_gal->DrawLine( p + VECTOR2D( -delta, -delta ), p + VECTOR2D( delta, delta ) );
1708  m_gal->DrawLine( p + VECTOR2D( -delta, delta ), p + VECTOR2D( delta, -delta ) );
1709 }
1710 
1711 
1712 void SCH_PAINTER::draw( SCH_BUS_ENTRY_BASE *aEntry, int aLayer )
1713 {
1714  SCH_LINE line;
1715  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1716 
1717  if( drawingShadows && !aEntry->IsSelected() )
1718  return;
1719 
1720  line.SetLayer( aEntry->Type() == SCH_BUS_WIRE_ENTRY_T ? LAYER_WIRE : LAYER_BUS );
1721 
1722  if( aEntry->IsSelected() )
1723  line.SetSelected();
1724  else if( aEntry->IsBrightened() )
1725  line.SetBrightened();
1726 
1727  line.SetStartPoint( aEntry->GetPosition() );
1728  line.SetEndPoint( aEntry->GetEnd() );
1729  line.SetStroke( aEntry->GetStroke() );
1730 
1731  COLOR4D color = getRenderColor( aEntry, LAYER_WIRE, drawingShadows );
1732 
1733  if( aEntry->Type() == SCH_BUS_BUS_ENTRY_T )
1734  color = getRenderColor( aEntry, LAYER_BUS, drawingShadows );
1735 
1736  line.SetLineColor( color );
1737  line.SetLineStyle( aEntry->GetStrokeStyle() );
1738 
1739  draw( &line, aLayer );
1740 
1741  m_gal->SetIsFill( false );
1742  m_gal->SetIsStroke( true );
1743  m_gal->SetLineWidth( drawingShadows ? getShadowWidth() : 1.0F );
1744 
1745  if( aEntry->IsDanglingStart() )
1746  m_gal->DrawCircle( aEntry->GetPosition(),
1747  aEntry->GetPenWidth() + ( TARGET_BUSENTRY_RADIUS / 2 ) );
1748 
1749  if( aEntry->IsDanglingEnd() )
1750  m_gal->DrawCircle( aEntry->GetEnd(),
1751  aEntry->GetPenWidth() + ( TARGET_BUSENTRY_RADIUS / 2 ) );
1752 }
1753 
1754 
1755 void SCH_PAINTER::draw( SCH_BITMAP *aBitmap, int aLayer )
1756 {
1757  m_gal->Save();
1758  m_gal->Translate( aBitmap->GetPosition() );
1759 
1760  // When the image scale factor is not 1.0, we need to modify the actual as the image scale
1761  // factor is similar to a local zoom
1762  double img_scale = aBitmap->GetImageScale();
1763 
1764  if( img_scale != 1.0 )
1765  m_gal->Scale( VECTOR2D( img_scale, img_scale ) );
1766 
1767  if( aLayer == LAYER_DRAW_BITMAPS )
1768  {
1769  m_gal->DrawBitmap( *aBitmap->GetImage() );
1770  }
1771 
1772  if( aLayer == LAYER_SELECTION_SHADOWS )
1773  {
1774  if( aBitmap->IsSelected() || aBitmap->IsBrightened() )
1775  {
1776  COLOR4D color = getRenderColor( aBitmap, LAYER_DRAW_BITMAPS, true );
1777  m_gal->SetIsStroke( true );
1780  m_gal->SetIsFill( false );
1781 
1782  // Draws a bounding box.
1783  VECTOR2D bm_size( aBitmap->GetSize() );
1784  // bm_size is the actual image size in UI.
1785  // but m_gal scale was previously set to img_scale
1786  // so recalculate size relative to this image size.
1787  bm_size.x /= img_scale;
1788  bm_size.y /= img_scale;
1789  VECTOR2D origin( -bm_size.x / 2.0, -bm_size.y / 2.0 );
1790  VECTOR2D end = origin + bm_size;
1791 
1792  m_gal->DrawRectangle( origin, end );
1793  }
1794  }
1795 
1796  m_gal->Restore();
1797 }
1798 
1799 
1800 void SCH_PAINTER::draw( SCH_MARKER *aMarker, int aLayer )
1801 {
1802  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1803 
1804  if( drawingShadows && !aMarker->IsSelected() )
1805  return;
1806 
1807  COLOR4D color = getRenderColor( aMarker, aMarker->GetColorLayer(), drawingShadows );
1808 
1809  m_gal->Save();
1810  m_gal->Translate( aMarker->GetPosition() );
1811  m_gal->SetIsFill( !drawingShadows );
1812  m_gal->SetFillColor( color );
1813  m_gal->SetIsStroke( drawingShadows );
1814  m_gal->SetLineWidth( getLineWidth( aMarker, drawingShadows ) );
1816 
1817  SHAPE_LINE_CHAIN polygon;
1818  aMarker->ShapeToPolygon( polygon );
1819 
1820  m_gal->DrawPolygon( polygon );
1821  m_gal->Restore();
1822 }
1823 
1824 
1825 }; // 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...
bool IsDangling() const override
Definition: sch_text.h:304
SCH_PAINTER(GAL *aGal)
CITER next(CITER it)
Definition: ptree.cpp:126
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.
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: common.h:185
bool IsBold() const
Definition: eda_text.h:183
virtual int GetPenWidth() const =0
SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:52
SCHEMATIC * m_schematic
Definition: sch_painter.h:206
float GetLineWidth() const
Get the line width.
#define TARGET_BUSENTRY_RADIUS
Definition: sch_bus_entry.h:37
void drawDanglingSymbol(const wxPoint &aPos, int aWidth, bool aDrawingShadows)
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:200
bool IsMirrored() const
Definition: eda_text.h:189
int GetPinNameOffset()
SCH_LAYER_ID GetColorLayer() const
Definition: sch_marker.cpp:95
int GetOrientation()
Get the display symbol orientation.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
wxPoint GetStartPoint() const
Definition: sch_line.h:94
bool IsSelected() const
Definition: base_struct.h:203
wxPoint GetEnd() const
Definition: lib_rectangle.h:87
const MATRIX3x3D & GetScreenWorldMatrix() const
Get the screen <-> world transformation matrix.
void drawPinDanglingSymbol(const VECTOR2I &aPos, bool aDrawingShadows)
wxPoint GetPosition() const override
Definition: lib_field.h:180
wxPoint GetPosition() const override
to handle and draw images bitmaps
COLOR4D m_layerColors[LAYER_ID_COUNT]
Define a symbol library graphical text item.
Definition: lib_text.h:40
int GetOrientation() const
Definition: lib_pin.h:125
virtual STROKE_PARAMS GetStroke() const override
Definition: sch_bus_entry.h:78
static constexpr double IU_PER_MM
Mock up a conversion function.
LIB_PART * GetParent() const
Definition: lib_item.h:182
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_item.h:55
wxPoint GetPosition() const override
Definition: sch_marker.h:101
void GetPoly(std::vector< wxPoint > &aOutput, int aMinSegLen=0)
Converts Bezier curve to a polygon.
void SetShape(GRAPHIC_PINSHAPE aShape)
Definition: lib_pin.h:129
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:186
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:128
virtual void DrawArc(const VECTOR2D &aCenterPoint, double aRadius, double aStartAngle, double aEndAngle)
Draw an arc.
virtual wxPoint GetSchematicTextOffset(RENDER_SETTINGS *aSettings) const
Definition: sch_text.cpp:157
bool IsMoving() const
Definition: base_struct.h:200
int color
Definition: DXF_plotter.cpp:61
Field object used in symbol libraries.
Definition: lib_field.h:59
bool setDeviceColors(const LIB_ITEM *aItem, int aLayer)
double square(double x)
FILL_T GetFillMode() const
Definition: lib_item.h:301
void SetBrightened()
Definition: base_struct.h:209
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.
double GetTextAngle() const
Definition: eda_text.h:174
wxPoint GetPosition() const override
Definition: lib_circle.h:72
COLOR4D WithAlpha(double aAlpha) const
Function WithAlpha Returns a colour with the same colour, but the given alpha.
Definition: color4d.h:307
SCH_PIN * GetPin(const wxString &number)
Find a symbol pin by number.
void CalcRadiusAngles()
Calculate the radius and angle of an arc using the start, end, and center points.
Definition: lib_arc.cpp:539
int GetDiameter() const
#define DASH_MARK_LEN(aLineWidth)
KIGFX::COLOR4D GetBorderColor() const
Definition: sch_sheet.h:290
bool IsBrightened() const
Definition: base_struct.h:205
virtual COLOR4D GetColor(const VIEW_ITEM *aItem, int aLayer) const override
Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer using curr...
#define DEFAULT_JUNCTION_DIAM
The default bus and wire enty size in mils.
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:238
Definition: lib_pin.h:50
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: lib_field.cpp:315
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape.
Add new GAL layers here.
VIEW_ITEM - is an abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:85
wxPoint GetPosition() const override
Definition: sch_bitmap.h:140
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
void RevertYAxis()
Function RevertYAxis Mirror the rectangle from the X axis (negate Y pos and size)
Definition: eda_rect.h:209
EESCHEMA_SETTINGS * eeconfig()
bool IsDangling() const override
Definition: sch_pin.h:94
#define TEXT_ANGLE_VERT
Definition: common.h:186
VECTOR2< T > GetScale() const
Get the scale components of the matrix.
Definition: matrix3x3.h:269
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.
#define SET_DC(i)
COLOR4D getRenderColor(const EDA_ITEM *aItem, int aLayer, bool aDrawingShadows)
wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: sch_field.cpp:102
bool IsVoid() const
Function IsVoid returns true if the field is either empty or holds "~".
Definition: sch_field.cpp:311
void fillIfSelection(int aLayer)
bool IsDanglingEnd() const
Definition: sch_bus_entry.h:56
bool IsDragging() const
Definition: base_struct.h:201
static constexpr int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:697
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:110
The base class for drawable items used by schematic library components.
Definition: lib_item.h:61
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:230
int GetEffectiveTextPenWidth(int aDefaultWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultWidth.
Definition: eda_text.cpp:157
virtual void SetLineWidth(float aLineWidth)
Set the line width.
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition: color4d.h:372
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populates a std::vector with SCH_FIELDs.
void SetEndPoint(const wxPoint &aPosition)
Definition: sch_line.h:98
KIGFX::COLOR4D GetBackgroundColor() const
Definition: sch_sheet.h:293
Base class for a bus or wire entry.
Definition: sch_bus_entry.h:43
void AddDrawItem(LIB_ITEM *aItem)
Add a new draw aItem to the draw object list.
bool IsItalic() const
Definition: eda_text.h:180
const std::vector< wxPoint > & GetPolyPoints() const
Definition: lib_polyline.h:60
PLOT_DASH_TYPE GetStrokeStyle() const
void GetPins(LIB_PINS &aList, int aUnit=0, int aConvert=0)
Return a list of pin object pointers from the draw item list.
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:268
bool ShowPinNames()
int GetSecondRadiusAngle() const
Definition: lib_arc.h:109
const wxPoint GetEnd() const
Definition: eda_rect.h:116
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:340
int GetUnit() const
Definition: lib_item.h:295
int GetUnit() const
PAINTER contains all the knowledge about how to draw graphical object onto any particular output devi...
Definition: painter.h:58
void SetLineStyle(const PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:237
bool ShowPinNumbers()
void SetType(ELECTRICAL_PINTYPE aType)
Definition: lib_pin.h:135
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
wxSize GetSize() const
Definition: sch_bitmap.cpp:125
int Clamp_Text_PenSize(int aPenSize, int aSize, bool aBold)
Function Clamp_Text_PenSize Don't allow text to become cluttered up in its own fatness.
Definition: gr_text.cpp:72
Auxiliary items (guides, rule, etc)
bool IsDanglingStart() const
Definition: sch_bus_entry.h:55
void SetEnd(const wxPoint &aPoint)
Definition: lib_arc.h:115
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:232
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:199
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
BITMAP_BASE * GetImage()
Definition: sch_bitmap.h:59
void SetSelected()
Definition: base_struct.h:208
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
#define DANGLING_SYMBOL_SIZE
wxPoint GetPosition() const override
Definition: sch_junction.h:95
wxString const GetElectricalTypeName() const
Definition: lib_pin.h:142
const wxString & GetName() const
Definition: lib_pin.h:156
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
bool IsEndDangling() const
Definition: sch_line.h:195
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:239
int GetPenWidth() const override
Definition: sch_sheet.cpp:491
const wxPoint GetPosition() const
Definition: eda_rect.h:115
void SetStartPoint(const wxPoint &aPosition)
Definition: sch_line.h:95
void SetLayer(SCH_LAYER_ID aLayer)
Set the layer this item is on.
Definition: sch_item.h:286
bool IsResized() const
Definition: base_struct.h:204
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
int GetSize() const
wxPoint GetStart() const
Definition: lib_arc.h:111
#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.
void strokeText(const wxString &aText, const VECTOR2D &aPosition, double aRotationAngle)
EDA_ITEM * GetParent() const
Definition: base_struct.h:195
const std::vector< wxPoint > & GetPoints() const
Definition: lib_bezier.h:68
#define OUTSIDE
void triLine(const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c)
a few functions useful in geometry calculations.
#define F(x, y, z)
Definition: md5_hash.cpp:15
LABEL_SPIN_STYLE GetLabelSpinStyle() const
Definition: sch_text.h:234
void SetLineColor(const COLOR4D &aColor)
Definition: sch_line.cpp:187
bool IsVisible() const
Definition: lib_pin.h:147
GRAPHIC_PINSHAPE GetShape() const
Definition: sch_pin.cpp:83
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:84
void SetTextMirrored(const bool aMirrored)
Set a mirrored property of text.
int GetRadius() const
Definition: lib_circle.h:88
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_text.cpp:438
void CreateGraphicShape(RENDER_SETTINGS *aRenderSettings, std::vector< wxPoint > &aPoints, const wxPoint &aPos) override
Calculate the graphic shape (a polygon) associated to the text.
Definition: sch_text.cpp:908
std::unique_ptr< LIB_PART > & GetPartRef()
float getTextThickness(const SCH_TEXT *aItem, bool aDrawingShadows)
int GetNameTextSize() const
Definition: lib_pin.h:174
std::unique_ptr< LIB_PART > Flatten() const
Return a flattened symbol inheritance to the caller.
void SetVerticalJustify(const EDA_TEXT_VJUSTIFY_T aVerticalJustify)
Set the vertical justify for text drawing.
static VECTOR2D mapCoords(const wxPoint &aCoord)
wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: sch_text.cpp:483
wxPoint GetPosition() const override
Definition: sch_sheet.h:567
int GetConvert() const
Definition: lib_item.h:298
#define DEFAULT_LINE_THICKNESS
The default wire width in mils. (can be changed in preference menu)
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:42
SCH_CONNECTION * Connection(const SCH_SHEET_PATH &aPath) const
Retrieve the connection associated with this object in the given sheet.
Definition: sch_item.cpp:150
virtual int GetPenWidth() const
Definition: sch_item.h:296
virtual void Scale(const VECTOR2D &aScale)
Scale the context.
double m_MinPlotPenWidth
Sets an absolute minimum pen width for plotting.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:216
PLOT_DASH_TYPE
Enum for choosing dashed line type.
Definition: plotter.h:87
#define DEFAULT_BUS_THICKNESS
The default noconnect size in mils.
int GetRadius() const
Definition: lib_arc.h:103
wxPoint GetPosition() const override
Definition: lib_pin.h:254
static void orientPart(LIB_PART *part, int orientation)
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:279
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:362
double GetTextAngleRadians() const
Definition: eda_text.h:177
void Normalize()
Function Normalize ensures that the height ant width are positive.
int externalPinDecoSize(const LIB_PIN &aPin)
const wxString & GetNumber() const
Definition: lib_pin.h:165
ELECTRICAL_PINTYPE GetType() const
Definition: lib_pin.h:134
void LoadColors(const COLOR_SETTINGS *aSettings) override
Definition: sch_painter.cpp:92
COLOR4D GetColor(int aLayer) const
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
Bezier curves to polygon converter.
Definition: bezier_curves.h:35
virtual void SetStroke(const STROKE_PARAMS &aStroke) override
Definition: sch_line.h:129
bool IsForceVisible() const
Definition: base_struct.h:286
int GetNumberTextSize() const
Definition: lib_pin.h:177
virtual void Restore()
Restore the context.
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList)
Draw a polygon.
void SetName(const wxString &aName)
Definition: lib_pin.h:157
PLOT_DASH_TYPE GetEffectiveLineStyle() const
Definition: sch_line.cpp:255
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
#define IS_DANGLING
indicates a pin is dangling
Definition: base_struct.h:145
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
const EDA_RECT GetBoundingBox() const override
Definition: lib_text.cpp:360
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_field.cpp:252
int GetLength() const
Definition: lib_pin.h:131
bool isUnitAndConversionShown(const LIB_ITEM *aItem)
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
SHAPE_LINE_CHAIN.
int internalPinDecoSize(const LIB_PIN &aPin)
#define HANDLE_ITEM(type_id, type_name)
#define DEFAULT_WIRE_THICKNESS
The default bus width in mils. (can be changed in preference menu)
ELECTRICAL_PINTYPE GetType() const
Definition: sch_pin.cpp:74
bool IsStartDangling() const
Definition: sch_line.h:194
double GetImageScale() const
Definition: sch_bitmap.h:71
bool IsAlias() const
wxPoint GetEnd() const
Definition: lib_arc.h:114
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
Schematic symbol object.
Definition: sch_component.h:80
float getLineWidth(const LIB_ITEM *aItem, bool aDrawingShadows)
wxPoint GetPosition() const override
#define IU_PER_MILS
Definition: plotter.cpp:138
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
#define DASH_GAP_LEN(aLineWidth)
#define TARGET_PIN_RADIUS
Definition: lib_pin.h:38
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
wxPoint Centre() const
Definition: eda_rect.h:62
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:233
int GetDefaultPenWidth() const
Color settings are a bit different than most of the settings objects in that there can be more than o...
const wxPoint & GetTextPos() const
Definition: eda_text.h:248
int GetFirstRadiusAngle() const
Definition: lib_arc.h:106
void SetGlyphSize(const VECTOR2D aGlyphSize)
Set the font glyph size.
void SetStart(const wxPoint &aPoint)
Definition: lib_arc.h:112
#define DEFAULT_TEXT_SIZE
The offset of the pin name string from the end of the pin in mils.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers of advanced config.
void CreateGraphicShape(RENDER_SETTINGS *aSettings, std::vector< wxPoint > &aPoints, const wxPoint &Pos) override
Calculate the graphic shape (a polygon) associated to the text.
Definition: sch_text.cpp:1124
bool GetOverrideSchItemColors() const
int GetConvert() const
void draw(LIB_RECTANGLE *aRect, int aLayer)
virtual void Save()
Save the context.
void SetHorizontalJustify(const EDA_TEXT_HJUSTIFY_T aHorizontalJustify)
Set the horizontal justify for text drawing.
bool MapAngles(int *aAngle1, int *aAngle2) const
Calculate new angles according to the transform.
Definition: transform.cpp:81
Definition for part library class.
bool HasFlag(STATUS_FLAGS aFlag)
Definition: base_struct.h:235
#define INSIDE
void SetDefaultPenWidth(int aWidth)
not connected (must be left open)
bool IsBus() const
wxPoint GetParentPosition() const
Definition: sch_field.cpp:619
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:234
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
#define PIN_TEXT_MARGIN
static constexpr int Millimeter2iu(double mm)
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:194
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:127
wxSize GetSize()
Definition: sch_sheet.h:284
int GetUnitSelection(const SCH_SHEET_PATH *aSheet) const
wxPoint GetPosition() const override
Definition: lib_rectangle.h:74
wxString GetName() const
Definition: sch_pin.cpp:65
SCH_RENDER_SETTINGS m_schSettings
Definition: sch_painter.h:204
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193
Class GAL is the abstract interface for drawing on a 2D-surface.
wxPoint GetEnd() const
Define a bezier curve graphic body item.
Definition: lib_bezier.h:34
wxPoint GetPosition() const override
Definition: lib_arc.h:90
SCH_SHEET_PATH & CurrentSheet() const
Definition: schematic.h:119
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99
wxPoint GetPosition() const override
wxPoint GetEndPoint() const
Definition: sch_line.h:97