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