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