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