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 #include <trigo.h>
30 #include <bezier_curves.h>
31 #include <symbol_library.h>
32 #include <connection_graph.h>
36 #include <gr_text.h>
37 #include <lib_shape.h>
38 #include <lib_field.h>
39 #include <lib_item.h>
40 #include <lib_pin.h>
41 #include <lib_text.h>
42 #include <math/util.h>
43 #include <plotters/plotter.h>
44 #include <sch_bitmap.h>
45 #include <sch_bus_entry.h>
46 #include <sch_symbol.h>
47 #include <sch_edit_frame.h>
48 #include <sch_field.h>
49 #include <sch_junction.h>
50 #include <sch_line.h>
51 #include <sch_marker.h>
52 #include <sch_no_connect.h>
53 #include <sch_sheet.h>
54 #include <sch_sheet_pin.h>
55 #include <sch_text.h>
56 #include <schematic.h>
58 #include <view/view.h>
59 #include <kiface_base.h>
60 #include <default_values.h>
61 #include <advanced_config.h>
62 #include <string_utils.h>
63 #include "sch_painter.h"
64 
65 namespace KIGFX
66 {
67 
69  m_IsSymbolEditor( false ),
70  m_ShowUnit( 0 ),
71  m_ShowConvert( 0 ),
72  m_ShowHiddenText( true ),
73  m_ShowHiddenPins( true ),
74  m_ShowPinsElectricalType( true ),
75  m_ShowDisabled( false ),
76  m_ShowGraphicsDisabled( false ),
77  m_ShowUmbilicals( true ),
78  m_OverrideItemColors( false ),
79  m_LabelSizeRatio( DEFAULT_LABEL_SIZE_RATIO ),
80  m_TextOffsetRatio( DEFAULT_TEXT_OFFSET_RATIO ),
81  m_DefaultWireThickness( DEFAULT_WIRE_WIDTH_MILS * IU_PER_MILS ),
82  m_DefaultBusThickness( DEFAULT_BUS_WIDTH_MILS * 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_SYMBOL* dummy()
134 {
135  static LIB_SYMBOL* symbol;
136 
137  if( !symbol )
138  {
139  symbol = new LIB_SYMBOL( wxEmptyString );
140 
141  LIB_SHAPE* square = new LIB_SHAPE( symbol, SHAPE_T::RECT );
142 
143  square->MoveTo( wxPoint( Mils2iu( -200 ), Mils2iu( 200 ) ) );
144  square->SetEnd( wxPoint( Mils2iu( 200 ), Mils2iu( -200 ) ) );
145 
146  LIB_TEXT* text = new LIB_TEXT( symbol );
147 
148  text->SetTextSize( wxSize( Mils2iu( 150 ), Mils2iu( 150 ) ) );
149  text->SetText( wxString( wxT( "??" ) ) );
150 
151  symbol->AddDrawItem( square );
152  symbol->AddDrawItem( text );
153  }
154 
155  return symbol;
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  const auto item = dynamic_cast<const EDA_ITEM*>( aItem );
172 
173  if( !item )
174  return false;
175 
176 #ifdef CONNECTIVITY_DEBUG
177 
178  auto sch_item = dynamic_cast<const SCH_ITEM*>( item );
179  auto conn = sch_item ? sch_item->Connection( *g_CurrentSheet ) : nullptr;
180 
181  if( conn )
182  {
183  auto pos = item->GetBoundingBox().Centre();
184  auto label = conn->Name( true );
185 
189  m_gal->SetLineWidth( Mils2ui( 2 ) );
190  m_gal->SetGlyphSize( VECTOR2D( Mils2ui( 20 ), Mils2ui( 20 ) ) );
191  m_gal->StrokeText( conn->Name( true ), pos, 0.0, 0 );
192  }
193 
194 #endif
195 
197  {
198  BOX2I box = item->GetBoundingBox();
199 
200  if( item->Type() == SCH_SYMBOL_T )
201  box = static_cast<const SCH_SYMBOL*>( item )->GetBodyBoundingBox();
202 
203  m_gal->SetIsFill( false );
204  m_gal->SetIsStroke( true );
205  m_gal->SetStrokeColor( item->IsSelected() ? COLOR4D( 1.0, 0.2, 0.2, 1 )
206  : COLOR4D( 0.2, 0.2, 0.2, 1 ) );
207  m_gal->SetLineWidth( Mils2iu( 3 ) );
208  m_gal->DrawRectangle( box.GetOrigin(), box.GetEnd() );
209  }
210 
211  switch( item->Type() )
212  {
233 
234  default: return false;
235  }
236 
237  return false;
238 }
239 
240 
242 {
243  if( m_schSettings.m_ShowUnit // showing a specific unit
244  && aItem->GetUnit() // item is unit-specific
245  && aItem->GetUnit() != m_schSettings.m_ShowUnit )
246  {
247  return false;
248  }
249 
250  if( m_schSettings.m_ShowConvert // showing a specific conversion
251  && aItem->GetConvert() // item is conversion-specific
252  && aItem->GetConvert() != m_schSettings.m_ShowConvert )
253  {
254  return false;
255  }
256 
257  return true;
258 }
259 
260 
262 {
263  const MATRIX3x3D& matrix = m_gal->GetScreenWorldMatrix();
264 
265  // For best visuals the selection width must be a cross between the zoom level and the
266  // default line width.
267  return (float) std::fabs( matrix.GetScale().x * 2.75 ) +
268  Mils2iu( eeconfig()->m_Selection.thickness );
269 }
270 
271 
272 COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM* aItem, int aLayer, bool aDrawingShadows ) const
273 {
275 
276  if( aItem->Type() == SCH_LINE_T )
277  {
278  COLOR4D lineColor = static_cast<const SCH_LINE*>( aItem )->GetLineColor();
279 
280  if( lineColor != COLOR4D::UNSPECIFIED )
281  color = lineColor;
282  }
283  else if( aItem->Type() == SCH_BUS_WIRE_ENTRY_T )
284  {
285  COLOR4D busEntryColor = static_cast<const SCH_BUS_WIRE_ENTRY*>( aItem )->GetStrokeColor();
286 
287  if( busEntryColor != COLOR4D::UNSPECIFIED )
288  color = busEntryColor;
289  }
290  else if( aItem->Type() == SCH_JUNCTION_T )
291  {
292  COLOR4D junctionColor = static_cast<const SCH_JUNCTION*>( aItem )->GetJunctionColor();
293 
294  if( junctionColor != COLOR4D::UNSPECIFIED )
295  color = junctionColor;
296  }
297  else if( aItem->Type() == SCH_SHEET_T )
298  {
299  SCH_SHEET* sheet = (SCH_SHEET*) aItem;
300 
302  color = m_schSettings.GetLayerColor( aLayer );
303  else if( aLayer == LAYER_SHEET )
304  color = sheet->GetBorderColor();
305  else if( aLayer == LAYER_SHEET_BACKGROUND )
306  color = sheet->GetBackgroundColor();
307 
308  if( color == COLOR4D::UNSPECIFIED )
309  color = m_schSettings.GetLayerColor( aLayer );
310  }
311 
312  if( aItem->IsBrightened() && !aDrawingShadows ) // Selection disambiguation, etc.
313  {
315 
316  if( aLayer == LAYER_DEVICE_BACKGROUND || aLayer == LAYER_SHEET_BACKGROUND )
317  color = color.WithAlpha( 0.2 );
318  }
319  else if( aItem->IsSelected() )
320  {
321  if( aDrawingShadows )
323  }
324 
326  || ( m_schSettings.m_ShowGraphicsDisabled && aItem->Type() != LIB_FIELD_T ) )
327  {
328  color = color.Darken( 0.5f );
329  }
330 
331  return color;
332 }
333 
334 
335 float SCH_PAINTER::getLineWidth( const LIB_ITEM* aItem, bool aDrawingShadows ) const
336 {
337  float width = (float) aItem->GetEffectivePenWidth( &m_schSettings );
338 
339  if( aItem->IsSelected() && aDrawingShadows )
340  width += getShadowWidth();
341 
342  return width;
343 }
344 
345 
346 float SCH_PAINTER::getLineWidth( const SCH_ITEM* aItem, bool aDrawingShadows ) const
347 {
348  wxCHECK( aItem, static_cast<float>( m_schSettings.m_DefaultWireThickness ) );
349 
350  float width = (float) aItem->GetPenWidth();
351 
352  if( aItem->IsSelected() && aDrawingShadows )
353  width += getShadowWidth();
354 
355  return std::max( width, 1.0f );
356 }
357 
358 
359 float SCH_PAINTER::getTextThickness( const SCH_TEXT* aItem, bool aDrawingShadows ) const
360 {
361  float width = (float) aItem->GetEffectiveTextPenWidth( m_schSettings.GetDefaultPenWidth() );
362 
363  if( aItem->IsSelected() && aDrawingShadows )
364  width += getShadowWidth();
365 
366  return width;
367 }
368 
369 
370 float SCH_PAINTER::getTextThickness( const SCH_FIELD* aItem, bool aDrawingShadows ) const
371 {
372  float width = (float) aItem->GetEffectiveTextPenWidth( m_schSettings.GetDefaultPenWidth() );
373 
374  if( aItem->IsSelected() && aDrawingShadows )
375  width += getShadowWidth();
376 
377  return width;
378 }
379 
380 
381 float SCH_PAINTER::getTextThickness( const LIB_FIELD* aItem, bool aDrawingShadows ) const
382 {
383  float width = (float) std::max( aItem->GetEffectiveTextPenWidth(),
385 
386  if( aItem->IsSelected() && aDrawingShadows )
387  width += getShadowWidth();
388 
389  return width;
390 }
391 
392 
393 float SCH_PAINTER::getTextThickness( const LIB_TEXT* aItem, bool aDrawingShadows ) const
394 {
395  float width = (float) std::max( aItem->GetEffectiveTextPenWidth(),
397 
398  if( aItem->IsSelected() && aDrawingShadows )
399  width += getShadowWidth();
400 
401  return width;
402 }
403 
404 
405 static VECTOR2D mapCoords( const wxPoint& aCoord )
406 {
407  return VECTOR2D( aCoord.x, -aCoord.y );
408 }
409 
410 
411 void SCH_PAINTER::strokeText( const wxString& aText, const VECTOR2D& aPosition, double aAngle )
412 {
413  m_gal->StrokeText( aText, VECTOR2D( aPosition.x, aPosition.y ), aAngle );
414 }
415 
416 
417 void SCH_PAINTER::boxText( const wxString& aText, const VECTOR2D& aPosition, double aAngle )
418 {
419  const STROKE_FONT& font = m_gal->GetStrokeFont();
420  VECTOR2D extents = font.ComputeStringBoundaryLimits( aText, m_gal->GetGlyphSize(),
421  m_gal->GetLineWidth() );
422  EDA_RECT box( (wxPoint) aPosition, wxSize( extents.x, extents.y ) );
423 
425  box.SetX( box.GetX() - ( box.GetWidth() / 2) );
427  box.SetX( box.GetX() - box.GetWidth() );
428 
430  box.SetY( box.GetY() - ( box.GetHeight() / 2) );
432  box.SetY( box.GetY() - box.GetHeight() );
433 
434  box.Normalize(); // Make h and v sizes always >= 0
435  box = box.GetBoundingBoxRotated((wxPoint) aPosition, RAD2DECIDEG( aAngle ) );
436  box.RevertYAxis();
437  m_gal->DrawRectangle( mapCoords( box.GetOrigin() ), mapCoords( box.GetEnd() ) );
438 }
439 
440 
441 void SCH_PAINTER::triLine( const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c )
442 {
443  m_gal->DrawLine( a, b );
444  m_gal->DrawLine( b, c );
445 }
446 
447 
448 void SCH_PAINTER::draw( const LIB_SYMBOL *aSymbol, int aLayer, bool aDrawFields, int aUnit, int aConvert )
449 {
450  if( !aUnit )
451  aUnit = m_schSettings.m_ShowUnit;
452 
453  if( !aConvert )
454  aConvert = m_schSettings.m_ShowConvert;
455 
456  std::unique_ptr< LIB_SYMBOL > tmpSymbol;
457  const LIB_SYMBOL* drawnSymbol = aSymbol;
458 
459  if( aSymbol->IsAlias() )
460  {
461  tmpSymbol = aSymbol->Flatten();
462  drawnSymbol = tmpSymbol.get();
463  }
464 
465  for( const LIB_ITEM& item : drawnSymbol->GetDrawItems() )
466  {
467  if( !aDrawFields && item.Type() == LIB_FIELD_T )
468  continue;
469 
470  if( aUnit && item.GetUnit() && aUnit != item.GetUnit() )
471  continue;
472 
473  if( aConvert && item.GetConvert() && aConvert != item.GetConvert() )
474  continue;
475 
476  Draw( &item, aLayer );
477  }
478 }
479 
480 
481 bool SCH_PAINTER::setDeviceColors( const LIB_ITEM* aItem, int aLayer )
482 {
483  const EDA_SHAPE* shape = dynamic_cast<const EDA_SHAPE*>( aItem );
484 
485  switch( aLayer )
486  {
488  if( aItem->IsSelected() )
489  {
490  m_gal->SetIsFill( false );
491  m_gal->SetIsStroke( true );
492  m_gal->SetLineWidth( getLineWidth( aItem, true ) );
493  m_gal->SetStrokeColor( getRenderColor( aItem, LAYER_DEVICE, true ) );
494  m_gal->SetFillColor( getRenderColor( aItem, LAYER_DEVICE, true ) );
495  return true;
496  }
497 
498  return false;
499 
501  if( shape && shape->GetFillType() == FILL_T::FILLED_WITH_BG_BODYCOLOR )
502  {
503  COLOR4D fillColor = getRenderColor( aItem, LAYER_DEVICE_BACKGROUND, false );
504 
506  m_gal->SetFillColor( fillColor );
507  m_gal->SetIsStroke( false );
508  return true;
509  }
510 
511  return false;
512 
513  case LAYER_DEVICE:
514  m_gal->SetIsFill( shape && shape->GetFillType() == FILL_T::FILLED_SHAPE );
515  m_gal->SetFillColor( getRenderColor( aItem, LAYER_DEVICE, false ) );
516 
517  if( aItem->GetPenWidth() >= 0 || !shape || !shape->IsFilled() )
518  {
519  m_gal->SetIsStroke( true );
520  m_gal->SetLineWidth( getLineWidth( aItem, false ) );
521  m_gal->SetStrokeColor( getRenderColor( aItem, LAYER_DEVICE, false ) );
522  }
523  else
524  {
525  m_gal->SetIsStroke( false );
526  }
527 
528  return true;
529 
530  default:
531  return false;
532  }
533 }
534 
535 
537 {
538  if( aLayer == LAYER_SELECTION_SHADOWS && eeconfig()->m_Selection.fill_shapes )
539  m_gal->SetIsFill( true );
540 }
541 
542 
543 void SCH_PAINTER::draw( const LIB_SHAPE *aShape, int aLayer )
544 {
545  if( !isUnitAndConversionShown( aShape ) )
546  return;
547 
548  if( setDeviceColors( aShape, aLayer ) )
549  {
550  fillIfSelection( aLayer );
551 
552  switch( aShape->GetShape() )
553  {
554  case SHAPE_T::ARC:
555  {
556  int startAngle;
557  int endAngle;
558  aShape->CalcArcAngles( startAngle, endAngle );
559 
560  TRANSFORM().MapAngles( &startAngle, &endAngle );
561 
562  m_gal->DrawArc( mapCoords( aShape->GetCenter() ), aShape->GetRadius(),
563  DECIDEG2RAD( startAngle ), DECIDEG2RAD( endAngle ) );
564  }
565  break;
566 
567  case SHAPE_T::CIRCLE:
568  m_gal->DrawCircle( mapCoords( aShape->GetPosition() ), aShape->GetRadius() );
569  break;
570 
571  case SHAPE_T::RECT:
572  m_gal->DrawRectangle( mapCoords( aShape->GetPosition() ),
573  mapCoords( aShape->GetEnd() ) );
574  break;
575 
576  case SHAPE_T::POLY:
577  {
578  const SHAPE_LINE_CHAIN poly = aShape->GetPolyShape().Outline( 0 );
579  std::deque<VECTOR2D> mappedPts;
580 
581  for( const VECTOR2I& pt : poly.CPoints() )
582  mappedPts.push_back( mapCoords( (wxPoint) pt ) );
583 
584  fillIfSelection( aLayer );
585  m_gal->DrawPolygon( mappedPts );
586  }
587  break;
588 
589  case SHAPE_T::BEZIER:
590  {
591  std::deque<VECTOR2D> mappedPts;
592 
593  for( const VECTOR2I &p : aShape->GetPolyShape().Outline( 0 ).CPoints() )
594  mappedPts.push_back( mapCoords( (wxPoint) p ) );
595 
596  m_gal->DrawPolygon( mappedPts );
597  }
598  break;
599 
600  default:
601  wxFAIL_MSG( "SCH_PAINTER::draw not implemented for " + aShape->SHAPE_T_asString() );
602  }
603  }
604 }
605 
606 
607 void SCH_PAINTER::draw( const LIB_FIELD *aField, int aLayer )
608 {
609  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
610 
611  if( drawingShadows && !aField->IsSelected() )
612  return;
613 
614  if( !isUnitAndConversionShown( aField ) )
615  return;
616 
617  // Must check layer as fields are sometimes drawn by their parent rather than
618  // directly from the view.
619  int layers[KIGFX::VIEW::VIEW_MAX_LAYERS];
620  int layers_count;
621  bool foundLayer = false;
622 
623  aField->ViewGetLayers( layers, layers_count );
624 
625  for( int i = 0; i < layers_count; ++i )
626  {
627  if( layers[i] == aLayer )
628  foundLayer = true;
629  }
630 
631  if( !foundLayer )
632  return;
633 
634  COLOR4D color = getRenderColor( aField, aLayer, drawingShadows );
635 
636  if( !( aField->IsVisible() || aField->IsForceVisible() ) )
637  {
639  color = getRenderColor( aField, LAYER_HIDDEN, drawingShadows );
640  else
641  return;
642  }
643 
644  m_gal->SetLineWidth( getTextThickness( aField, drawingShadows ) );
645  m_gal->SetIsFill( false );
646  m_gal->SetIsStroke( true );
648 
649  EDA_RECT bbox = aField->GetBoundingBox();
650  wxPoint textpos = bbox.Centre();
651 
652  if( drawingShadows && eeconfig()->m_Selection.text_as_box )
653  {
654  m_gal->SetIsFill( true );
656  m_gal->SetLineWidth( m_gal->GetLineWidth() * 0.5 );
657  bbox.RevertYAxis();
658 
659  m_gal->DrawRectangle( mapCoords( bbox.GetPosition() ), mapCoords( bbox.GetEnd() ) );
660  }
661  else
662  {
665  m_gal->SetGlyphSize( VECTOR2D( aField->GetTextSize() ) );
666  m_gal->SetFontItalic( aField->IsItalic() );
667 
668  strokeText( UnescapeString( aField->GetText() ), textpos, aField->GetTextAngleRadians() );
669  }
670 
671  // Draw the umbilical line
672  if( aField->IsMoving() && m_schSettings.m_ShowUmbilicals )
673  {
675  m_gal->SetStrokeColor( getRenderColor( aField, LAYER_SCHEMATIC_ANCHOR, drawingShadows ) );
676  m_gal->DrawLine( textpos, wxPoint( 0, 0 ) );
677  }
678 }
679 
680 
681 void SCH_PAINTER::draw( const LIB_TEXT *aText, int aLayer )
682 {
683  if( !isUnitAndConversionShown( aText ) )
684  return;
685 
686  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
687 
688  if( drawingShadows && !aText->IsSelected() )
689  return;
690 
691  COLOR4D color = getRenderColor( aText, LAYER_DEVICE, drawingShadows );
692 
693  if( !aText->IsVisible() )
694  {
696  color = getRenderColor( aText, LAYER_HIDDEN, drawingShadows );
697  else
698  return;
699  }
700 
701  EDA_RECT bBox = aText->GetBoundingBox();
702  bBox.RevertYAxis();
703  VECTOR2D pos = mapCoords( bBox.Centre() );
704  double orient = aText->GetTextAngleRadians();
705 
708  m_gal->SetLineWidth( getTextThickness( aText, drawingShadows ) );
709  m_gal->SetIsFill( false );
710  m_gal->SetIsStroke( true );
712  m_gal->SetGlyphSize( VECTOR2D( aText->GetTextSize() ) );
713  m_gal->SetFontBold( aText->IsBold() );
714  m_gal->SetFontItalic( aText->IsItalic() );
715  m_gal->SetFontUnderlined( false );
716  strokeText( aText->GetText(), pos, orient );
717 }
718 
719 
721 {
724 
725  return aPin.GetNameTextSize() != 0 ? aPin.GetNameTextSize() / 2 : aPin.GetNumberTextSize() / 2;
726 }
727 
728 
729 // Utility for getting the size of the 'external' pin decorators (as a radius)
730 // i.e. the negation circle, the polarity 'slopes' and the nonlogic marker
732 {
735 
736  return aPin.GetNumberTextSize() / 2;
737 }
738 
739 
740 // Draw the target (an open circle) for a pin which has no connection or is being moved.
741 void SCH_PAINTER::drawPinDanglingSymbol( const VECTOR2I& aPos, bool aDrawingShadows )
742 {
743  m_gal->SetIsFill( false );
744  m_gal->SetIsStroke( true );
745  m_gal->SetLineWidth( aDrawingShadows ? getShadowWidth()
747 
749 }
750 
751 
752 void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer )
753 {
754  if( !isUnitAndConversionShown( aPin ) )
755  return;
756 
757  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
758  bool dangling = m_schSettings.m_IsSymbolEditor || aPin->HasFlag( IS_DANGLING );
759 
760  if( drawingShadows && !aPin->IsSelected() )
761  return;
762 
763  VECTOR2I pos = mapCoords( aPin->GetPosition() );
764  COLOR4D color = getRenderColor( aPin, LAYER_PIN, drawingShadows );
765 
766  if( !aPin->IsVisible() )
767  {
769  {
770  color = getRenderColor( aPin, LAYER_HIDDEN, drawingShadows );
771  }
772  else
773  {
774  if( dangling && aPin->IsPowerConnection() )
775  drawPinDanglingSymbol( pos, drawingShadows );
776 
777  return;
778  }
779  }
780 
781  VECTOR2I p0;
782  VECTOR2I dir;
783  int len = aPin->GetLength();
784  int orient = aPin->GetOrientation();
785 
786  switch( orient )
787  {
788  case PIN_UP:
789  p0 = VECTOR2I( pos.x, pos.y - len );
790  dir = VECTOR2I( 0, 1 );
791  break;
792 
793  case PIN_DOWN:
794  p0 = VECTOR2I( pos.x, pos.y + len );
795  dir = VECTOR2I( 0, -1 );
796  break;
797 
798  case PIN_LEFT:
799  p0 = VECTOR2I( pos.x - len, pos.y );
800  dir = VECTOR2I( 1, 0 );
801  break;
802 
803  default:
804  case PIN_RIGHT:
805  p0 = VECTOR2I( pos.x + len, pos.y );
806  dir = VECTOR2I( -1, 0 );
807  break;
808  }
809 
810  VECTOR2D pc;
811 
812  m_gal->SetIsStroke( true );
813  m_gal->SetIsFill( false );
814  m_gal->SetLineWidth( getLineWidth( aPin, drawingShadows ) );
816  m_gal->SetFontBold( false );
817  m_gal->SetFontUnderlined( false );
818  m_gal->SetFontItalic( false );
819 
820  const int radius = externalPinDecoSize( *aPin );
821  const int diam = radius*2;
822  const int clock_size = internalPinDecoSize( *aPin );
823 
824  if( aPin->GetType() == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol
825  {
826  m_gal->DrawLine( p0, pos );
827 
828  m_gal->DrawLine( pos + VECTOR2D( -1, -1 ) * TARGET_PIN_RADIUS,
829  pos + VECTOR2D( 1, 1 ) * TARGET_PIN_RADIUS );
830  m_gal->DrawLine( pos + VECTOR2D( 1, -1 ) * TARGET_PIN_RADIUS ,
831  pos + VECTOR2D( -1, 1 ) * TARGET_PIN_RADIUS );
832 
833  aPin->ClearFlags( IS_DANGLING ); // PIN_NC pin type is always not connected and dangling.
834  }
835  else
836  {
837  switch( aPin->GetShape() )
838  {
840  m_gal->DrawLine( p0, pos );
841  break;
842 
844  m_gal->DrawCircle( p0 + dir * radius, radius );
845  m_gal->DrawLine( p0 + dir * ( diam ), pos );
846  break;
847 
849  pc = p0 - dir * clock_size ;
850 
851  triLine( p0 + VECTOR2D( dir.y, -dir.x) * clock_size,
852  pc,
853  p0 + VECTOR2D( -dir.y, dir.x) * clock_size );
854 
855  m_gal->DrawCircle( p0 + dir * radius, radius );
856  m_gal->DrawLine( p0 + dir * ( diam ), pos );
857  break;
858 
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  if( !dir.y )
868  {
869  triLine( p0 + VECTOR2D(dir.x, 0) * diam,
870  p0 + VECTOR2D(dir.x, -1) * diam,
871  p0 );
872  }
873  else /* MapX1 = 0 */
874  {
875  triLine( p0 + VECTOR2D( 0, dir.y) * diam,
876  p0 + VECTOR2D(-1, dir.y) * diam,
877  p0 );
878  }
879 
880  m_gal->DrawLine( p0, pos );
881  break;
882 
884  m_gal->DrawLine( p0, pos );
885 
886  if( !dir.y )
887  {
888  triLine( p0 + VECTOR2D( 0, clock_size ),
889  p0 + VECTOR2D( -dir.x * clock_size, 0 ),
890  p0 + VECTOR2D( 0, -clock_size ) );
891  }
892  else
893  {
894  triLine( p0 + VECTOR2D( clock_size, 0 ),
895  p0 + VECTOR2D( 0, -dir.y * clock_size ),
896  p0 + VECTOR2D( -clock_size, 0 ) );
897  }
898  break;
899 
901  m_gal->DrawLine( p0, pos );
902 
903  if( !dir.y )
904  {
905  triLine( p0 + VECTOR2D(dir.x, 0) * diam,
906  p0 + VECTOR2D(dir.x, -1) * diam,
907  p0 );
908  }
909  else /* MapX1 = 0 */
910  {
911  triLine( p0 + VECTOR2D( 0, dir.y) * diam,
912  p0 + VECTOR2D(-1, dir.y) * diam,
913  p0 );
914  }
915  break;
916 
917  case GRAPHIC_PINSHAPE::OUTPUT_LOW: // IEEE symbol "Active Low Output"
918  m_gal->DrawLine( p0, pos );
919 
920  if( !dir.y ) // Horizontal pin
921  m_gal->DrawLine( p0 - VECTOR2D( 0, diam ), p0 + VECTOR2D( dir.x, 0 ) * diam );
922  else // Vertical pin
923  m_gal->DrawLine( p0 - VECTOR2D( diam, 0 ), p0 + VECTOR2D( 0, dir.y ) * diam );
924  break;
925 
926  case GRAPHIC_PINSHAPE::NONLOGIC: // NonLogic pin symbol
927  m_gal->DrawLine( p0, pos );
928 
929  m_gal->DrawLine( p0 - VECTOR2D( dir.x + dir.y, dir.y - dir.x ) * radius,
930  p0 + VECTOR2D( dir.x + dir.y, dir.y - dir.x ) * radius );
931  m_gal->DrawLine( p0 - VECTOR2D( dir.x - dir.y, dir.x + dir.y ) * radius,
932  p0 + VECTOR2D( dir.x - dir.y, dir.x + dir.y ) * radius );
933  break;
934  }
935  }
936 
937 
938  if( dangling )
939  drawPinDanglingSymbol( pos, drawingShadows );
940 
941  LIB_SYMBOL* libEntry = aPin->GetParent();
942 
943  // Draw the labels
944  if( drawingShadows
945  && ( libEntry->Type() == LIB_SYMBOL_T || libEntry->IsSelected() )
947  {
948  return;
949  }
950 
951  float penWidth = (float) m_schSettings.GetDefaultPenWidth();
952  int textOffset = libEntry->GetPinNameOffset();
953  float nameStrokeWidth = getLineWidth( aPin, drawingShadows );
954  float numStrokeWidth = getLineWidth( aPin, drawingShadows );
955 
956  nameStrokeWidth = Clamp_Text_PenSize( nameStrokeWidth, aPin->GetNameTextSize(), false );
957  numStrokeWidth = Clamp_Text_PenSize( numStrokeWidth, aPin->GetNumberTextSize(), false );
958 
960 
961  // Four locations around a pin where text can be drawn
962  enum { INSIDE = 0, OUTSIDE, ABOVE, BELOW };
963  int size[4] = { 0, 0, 0, 0 };
964  float thickness[4] = { numStrokeWidth, numStrokeWidth, numStrokeWidth, numStrokeWidth };
965  COLOR4D colour[4];
966  wxString text[4];
967 
968  // TextOffset > 0 means pin NAMES on inside, pin NUMBERS above and nothing below
969  if( textOffset )
970  {
971  size [INSIDE] = libEntry->ShowPinNames() ? aPin->GetNameTextSize() : 0;
972  thickness[INSIDE] = nameStrokeWidth;
973  colour [INSIDE] = getRenderColor( aPin, LAYER_PINNAM, drawingShadows );
974  text [INSIDE] = aPin->GetShownName();
975 
976  size [ABOVE] = libEntry->ShowPinNumbers() ? aPin->GetNumberTextSize() : 0;
977  thickness[ABOVE] = numStrokeWidth;
978  colour [ABOVE] = getRenderColor( aPin, LAYER_PINNUM, drawingShadows );
979  text [ABOVE] = aPin->GetShownNumber();
980  }
981  // Otherwise pin NAMES go above and pin NUMBERS go below
982  else
983  {
984  size [ABOVE] = libEntry->ShowPinNames() ? aPin->GetNameTextSize() : 0;
985  thickness[ABOVE] = nameStrokeWidth;
986  colour [ABOVE] = getRenderColor( aPin, LAYER_PINNAM, drawingShadows );
987  text [ABOVE] = aPin->GetShownName();
988 
989  size [BELOW] = libEntry->ShowPinNumbers() ? aPin->GetNumberTextSize() : 0;
990  thickness[BELOW] = numStrokeWidth;
991  colour [BELOW] = getRenderColor( aPin, LAYER_PINNUM, drawingShadows );
992  text [BELOW] = aPin->GetShownNumber();
993  }
994 
996  {
997  size [OUTSIDE] = std::max( aPin->GetNameTextSize() * 3 / 4, Millimeter2iu( 0.7 ) );
998  thickness[OUTSIDE] = float( size[OUTSIDE] ) / 6.0F;
999  colour [OUTSIDE] = getRenderColor( aPin, LAYER_NOTES, drawingShadows );
1000  text [OUTSIDE] = aPin->GetElectricalTypeName();
1001  }
1002 
1003  if( !aPin->IsVisible() )
1004  {
1005  for( COLOR4D& c : colour )
1006  c = getRenderColor( aPin, LAYER_HIDDEN, drawingShadows );
1007  }
1008 
1009  float insideOffset = textOffset - thickness[INSIDE] / 2.0;
1010  float outsideOffset = 2 * Mils2iu( PIN_TEXT_MARGIN ) - thickness[OUTSIDE] / 2.0;
1011  float aboveOffset = Mils2iu( PIN_TEXT_MARGIN ) + ( thickness[ABOVE] + penWidth ) / 2.0;
1012  float belowOffset = Mils2iu( PIN_TEXT_MARGIN ) + ( thickness[BELOW] + penWidth ) / 2.0;
1013 
1014  if( dangling )
1015  outsideOffset += TARGET_PIN_RADIUS / 2.0;
1016 
1017  if( drawingShadows )
1018  {
1019  float shadowWidth = getShadowWidth();
1020 
1021  if( eeconfig()->m_Selection.text_as_box )
1022  {
1023  insideOffset -= thickness[INSIDE] / 2.0;
1024  outsideOffset -= thickness[OUTSIDE] / 2.0;
1025  aboveOffset -= thickness[ABOVE] + penWidth;
1026  belowOffset -= thickness[BELOW] + penWidth;
1027  }
1028 
1029  for( float& t : thickness )
1030  t += shadowWidth;
1031 
1032  insideOffset -= shadowWidth / 2.0;
1033  outsideOffset -= shadowWidth / 2.0;
1034  }
1035 
1036  auto setupDC =
1037  [&]( int i )
1038  {
1039  m_gal->SetGlyphSize( VECTOR2D( size[i], size[i] ) );
1040  m_gal->SetIsStroke( !( drawingShadows && eeconfig()->m_Selection.text_as_box ) );
1041  m_gal->SetLineWidth( thickness[i] );
1042  m_gal->SetStrokeColor( colour[i] );
1043  m_gal->SetIsFill( drawingShadows && eeconfig()->m_Selection.text_as_box );
1044  m_gal->SetFillColor( colour[i] );
1045  };
1046 
1047  auto drawText =
1048  [&]( const wxString& aText, const VECTOR2D& aPos, double aAngle )
1049  {
1050  if( aText.IsEmpty() )
1051  return;
1052 
1053  if( drawingShadows && eeconfig()->m_Selection.text_as_box )
1054  boxText( aText, aPos, aAngle );
1055  else
1056  strokeText( aText, aPos, aAngle );
1057  };
1058 
1059  switch( orient )
1060  {
1061  case PIN_LEFT:
1062  if( size[INSIDE] )
1063  {
1064  setupDC( INSIDE );
1067  drawText( text[INSIDE], pos + VECTOR2D( -insideOffset - len, 0 ), 0 );
1068  }
1069  if( size[OUTSIDE] )
1070  {
1071  setupDC( OUTSIDE );
1074  drawText( text[OUTSIDE], pos + VECTOR2D( outsideOffset, 0 ), 0 );
1075  }
1076  if( size[ABOVE] )
1077  {
1078  setupDC( ABOVE );
1081  drawText( text[ABOVE], pos + VECTOR2D( -len / 2.0, -aboveOffset ), 0 );
1082  }
1083  if( size[BELOW] )
1084  {
1085  setupDC( BELOW );
1088  drawText( text[BELOW], pos + VECTOR2D( -len / 2.0, belowOffset ), 0 );
1089  }
1090  break;
1091 
1092  case PIN_RIGHT:
1093  if( size[INSIDE] )
1094  {
1095  setupDC( INSIDE );
1099  drawText( text[INSIDE], pos + VECTOR2D( insideOffset + len, 0 ), 0 );
1100  }
1101  if( size[OUTSIDE] )
1102  {
1103  setupDC( OUTSIDE );
1106  drawText( text[OUTSIDE], pos + VECTOR2D( -outsideOffset, 0 ), 0 );
1107  }
1108  if( size[ABOVE] )
1109  {
1110  setupDC( ABOVE );
1113  drawText( text[ABOVE], pos + VECTOR2D( len / 2.0, -aboveOffset ), 0 );
1114  }
1115  if( size[BELOW] )
1116  {
1117  setupDC( BELOW );
1120  drawText( text[BELOW], pos + VECTOR2D( len / 2.0, belowOffset ), 0 );
1121  }
1122  break;
1123 
1124  case PIN_DOWN:
1125  if( size[INSIDE] )
1126  {
1127  setupDC( INSIDE );
1130  drawText( text[INSIDE], pos + VECTOR2D( 0, insideOffset + len ), M_PI / 2 );
1131  }
1132  if( size[OUTSIDE] )
1133  {
1134  setupDC( OUTSIDE );
1137  drawText( text[OUTSIDE], pos + VECTOR2D( 0, -outsideOffset ), M_PI / 2 );
1138  }
1139  if( size[ABOVE] )
1140  {
1141  setupDC( ABOVE );
1144  drawText( text[ABOVE], pos + VECTOR2D( -aboveOffset, len / 2.0 ), M_PI / 2 );
1145  }
1146  if( size[BELOW] )
1147  {
1148  setupDC( BELOW );
1151  drawText( text[BELOW], pos + VECTOR2D( belowOffset, len / 2.0 ), M_PI / 2 );
1152  }
1153  break;
1154 
1155  case PIN_UP:
1156  if( size[INSIDE] )
1157  {
1158  setupDC( INSIDE );
1161  drawText( text[INSIDE], pos + VECTOR2D( 0, -insideOffset - len ), M_PI / 2 );
1162  }
1163  if( size[OUTSIDE] )
1164  {
1165  setupDC( OUTSIDE );
1168  drawText( text[OUTSIDE], pos + VECTOR2D( 0, outsideOffset ), M_PI / 2 );
1169  }
1170  if( size[ABOVE] )
1171  {
1172  setupDC( ABOVE );
1175  drawText( text[ABOVE], pos + VECTOR2D( -aboveOffset, -len / 2.0 ), M_PI / 2 );
1176  }
1177  if( size[BELOW] )
1178  {
1179  setupDC( BELOW );
1182  drawText( text[BELOW], pos + VECTOR2D( belowOffset, -len / 2.0 ), M_PI / 2 );
1183  }
1184  break;
1185 
1186  default:
1187  wxFAIL_MSG( "Unknown pin orientation" );
1188  }
1189 }
1190 
1191 
1192 // Draw the target (an open square) for a wire or label which has no connection or is
1193 // being moved.
1194 void SCH_PAINTER::drawDanglingSymbol( const wxPoint& aPos, int aWidth, bool aDrawingShadows )
1195 {
1196  wxPoint radius( aWidth + Mils2iu( DANGLING_SYMBOL_SIZE / 2 ),
1197  aWidth + Mils2iu( DANGLING_SYMBOL_SIZE / 2 ) );
1198 
1199  m_gal->SetIsStroke( true );
1200  m_gal->SetIsFill( false );
1201  m_gal->SetLineWidth( aDrawingShadows ? getShadowWidth()
1203 
1204  m_gal->DrawRectangle( aPos - radius, aPos + radius );
1205 }
1206 
1207 
1208 void SCH_PAINTER::draw( const SCH_JUNCTION *aJct, int aLayer )
1209 {
1210  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1211 
1212  if( drawingShadows && !aJct->IsSelected() )
1213  return;
1214 
1215  COLOR4D color = getRenderColor( aJct, aJct->GetLayer(), drawingShadows );
1216 
1217  int junctionSize = aJct->GetEffectiveDiameter() / 2;
1218 
1219  if( junctionSize > 1 )
1220  {
1221  m_gal->SetIsStroke( drawingShadows );
1222  m_gal->SetLineWidth( getLineWidth( aJct, drawingShadows ) );
1224  m_gal->SetIsFill( !drawingShadows );
1225  m_gal->SetFillColor( color );
1226  m_gal->DrawCircle( aJct->GetPosition(), junctionSize );
1227  }
1228 }
1229 
1230 
1231 void SCH_PAINTER::draw( const SCH_LINE *aLine, int aLayer )
1232 {
1233  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1234 
1235  if( drawingShadows && !aLine->IsSelected() )
1236  return;
1237 
1238  COLOR4D color = getRenderColor( aLine, aLine->GetLayer(), drawingShadows );
1239  float width = getLineWidth( aLine, drawingShadows );
1240  PLOT_DASH_TYPE lineStyle = aLine->GetEffectiveLineStyle();
1241 
1242  m_gal->SetIsStroke( true );
1244  m_gal->SetLineWidth( width );
1245 
1246  if( lineStyle <= PLOT_DASH_TYPE::FIRST_TYPE || drawingShadows )
1247  {
1248  m_gal->DrawLine( aLine->GetStartPoint(), aLine->GetEndPoint() );
1249  }
1250  else
1251  {
1252  VECTOR2D start = aLine->GetStartPoint();
1253  VECTOR2D end = aLine->GetEndPoint();
1254 
1255  EDA_RECT clip( (wxPoint)start, wxSize( end.x - start.x, end.y - start.y ) );
1256  clip.Normalize();
1257 
1258  double theta = atan2( end.y - start.y, end.x - start.x );
1259  double strokes[] = { 1.0, dash_gap_len( width ), 1.0, dash_gap_len( width ) };
1260 
1261  switch( lineStyle )
1262  {
1263  default:
1264  case PLOT_DASH_TYPE::DASH:
1265  strokes[0] = strokes[2] = dash_mark_len( width );
1266  break;
1267  case PLOT_DASH_TYPE::DOT:
1268  strokes[0] = strokes[2] = dot_mark_len( width );
1269  break;
1271  strokes[0] = dash_mark_len( width );
1272  strokes[2] = dot_mark_len( width );
1273  break;
1274  }
1275 
1276  for( size_t i = 0; i < 10000; ++i )
1277  {
1278  // Calculations MUST be done in doubles to keep from accumulating rounding
1279  // errors as we go.
1280  VECTOR2D next( start.x + strokes[ i % 4 ] * cos( theta ),
1281  start.y + strokes[ i % 4 ] * sin( theta ) );
1282 
1283  // Drawing each segment can be done rounded to ints.
1284  wxPoint segStart( KiROUND( start.x ), KiROUND( start.y ) );
1285  wxPoint segEnd( KiROUND( next.x ), KiROUND( next.y ) );
1286 
1287  if( ClipLine( &clip, segStart.x, segStart.y, segEnd.x, segEnd.y ) )
1288  break;
1289  else if( i % 2 == 0 )
1290  m_gal->DrawLine( segStart, segEnd );
1291 
1292  start = next;
1293  }
1294  }
1295 
1296  if( aLine->IsStartDangling() && aLine->IsWire() )
1297  {
1298  drawDanglingSymbol( aLine->GetStartPoint(), getLineWidth( aLine, drawingShadows ),
1299  drawingShadows );
1300  }
1301 
1302  if( aLine->IsEndDangling() && aLine->IsWire() )
1303  {
1304  drawDanglingSymbol( aLine->GetEndPoint(), getLineWidth( aLine, drawingShadows ),
1305  drawingShadows );
1306  }
1307 }
1308 
1309 
1310 void SCH_PAINTER::draw( const SCH_TEXT *aText, int aLayer )
1311 {
1312  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1313 
1314  if( drawingShadows && !aText->IsSelected() )
1315  return;
1316 
1317  switch( aText->Type() )
1318  {
1319  case SCH_SHEET_PIN_T: aLayer = LAYER_SHEETLABEL; break;
1320  case SCH_HIER_LABEL_T: aLayer = LAYER_HIERLABEL; break;
1321  case SCH_GLOBAL_LABEL_T: aLayer = LAYER_GLOBLABEL; break;
1322  case SCH_LABEL_T: aLayer = LAYER_LOCLABEL; break;
1323  default: aLayer = LAYER_NOTES; break;
1324  }
1325 
1326  COLOR4D color = getRenderColor( aText, aLayer, drawingShadows );
1327 
1328  if( m_schematic )
1329  {
1330  SCH_CONNECTION* conn = aText->Connection();
1331 
1332  if( conn && conn->IsBus() )
1333  color = getRenderColor( aText, LAYER_BUS, drawingShadows );
1334  }
1335 
1336  if( !( aText->IsVisible() || aText->IsForceVisible() ) )
1337  {
1339  color = getRenderColor( aText, LAYER_HIDDEN, drawingShadows );
1340  else
1341  return;
1342  }
1343 
1344  m_gal->SetIsFill( false );
1345  m_gal->SetIsStroke( true );
1346  m_gal->SetLineWidth( getTextThickness( aText, drawingShadows ) );
1348  m_gal->SetTextAttributes( aText );
1349  m_gal->SetFontUnderlined( false );
1350 
1351  VECTOR2D text_offset = aText->GetTextPos() + aText->GetSchematicTextOffset( &m_schSettings );
1352  wxString shownText( aText->GetShownText() );
1353 
1354  if( drawingShadows )
1355  {
1357  {
1358  EDA_RECT bBox = aText->GetBoundingBox();
1359 
1360  m_gal->SetIsFill( true );
1361  m_gal->SetFillColor( color );
1362  m_gal->SetLineWidth( m_gal->GetLineWidth() * 0.5 );
1363  bBox.RevertYAxis();
1364 
1365  m_gal->DrawRectangle( mapCoords( bBox.GetPosition() ), mapCoords( bBox.GetEnd() ) );
1366  return;
1367  }
1368 
1369  switch( aText->GetLabelSpinStyle() )
1370  {
1371  case LABEL_SPIN_STYLE::LEFT: text_offset.x += getShadowWidth() / 2; break;
1372  case LABEL_SPIN_STYLE::UP: text_offset.y += getShadowWidth() / 2; break;
1373  case LABEL_SPIN_STYLE::RIGHT: text_offset.x -= getShadowWidth() / 2; break;
1374  case LABEL_SPIN_STYLE::BOTTOM: text_offset.y -= getShadowWidth() / 2; break;
1375  }
1376  }
1377 
1378  if( !shownText.IsEmpty() )
1379  {
1380  strokeText( shownText, text_offset, aText->GetTextAngleRadians() );
1381  }
1382 
1383  if( aText->IsDangling() )
1384  {
1385  drawDanglingSymbol( aText->GetTextPos(), Mils2iu( DANGLING_SYMBOL_SIZE / 2 ),
1386  drawingShadows );
1387  }
1388 
1389 }
1390 
1391 
1392 static void orientSymbol( LIB_SYMBOL* symbol, int orientation )
1393 {
1394  struct ORIENT
1395  {
1396  int flag;
1397  int n_rots;
1398  int mirror_x;
1399  int mirror_y;
1400  }
1401  orientations[] =
1402  {
1403  { SYM_ORIENT_0, 0, 0, 0 },
1404  { SYM_ORIENT_90, 1, 0, 0 },
1405  { SYM_ORIENT_180, 2, 0, 0 },
1406  { SYM_ORIENT_270, 3, 0, 0 },
1407  { SYM_MIRROR_X + SYM_ORIENT_0, 0, 1, 0 },
1408  { SYM_MIRROR_X + SYM_ORIENT_90, 1, 1, 0 },
1409  { SYM_MIRROR_Y, 0, 0, 1 },
1410  { SYM_MIRROR_X + SYM_ORIENT_270, 3, 1, 0 },
1411  { SYM_MIRROR_Y + SYM_ORIENT_0, 0, 0, 1 },
1412  { SYM_MIRROR_Y + SYM_ORIENT_90, 1, 0, 1 },
1413  { SYM_MIRROR_Y + SYM_ORIENT_180, 2, 0, 1 },
1414  { SYM_MIRROR_Y + SYM_ORIENT_270, 3, 0, 1 }
1415  };
1416 
1417  ORIENT o = orientations[ 0 ];
1418 
1419  for( auto& i : orientations )
1420  {
1421  if( i.flag == orientation )
1422  {
1423  o = i;
1424  break;
1425  }
1426  }
1427 
1428  for( auto& item : symbol->GetDrawItems() )
1429  {
1430  for( int i = 0; i < o.n_rots; i++ )
1431  item.Rotate( wxPoint(0, 0 ), true );
1432 
1433  if( o.mirror_x )
1434  item.MirrorVertical( wxPoint( 0, 0 ) );
1435 
1436  if( o.mirror_y )
1437  item.MirrorHorizontal( wxPoint( 0, 0 ) );
1438  }
1439 }
1440 
1441 
1442 void SCH_PAINTER::draw( SCH_SYMBOL* aSymbol, int aLayer )
1443 {
1444  int unit = aSymbol->GetUnitSelection( &m_schematic->CurrentSheet() );
1445  int convert = aSymbol->GetConvert();
1446 
1447  // Use dummy symbol if the actual couldn't be found (or couldn't be locked).
1448  LIB_SYMBOL* originalSymbol = aSymbol->GetLibSymbolRef() ?
1449  aSymbol->GetLibSymbolRef().get() : dummy();
1450  LIB_PINS originalPins;
1451  originalSymbol->GetPins( originalPins, unit, convert );
1452 
1453  // Copy the source so we can re-orient and translate it.
1454  LIB_SYMBOL tempSymbol( *originalSymbol );
1455  LIB_PINS tempPins;
1456  tempSymbol.GetPins( tempPins, unit, convert );
1457 
1458  tempSymbol.SetFlags( aSymbol->GetFlags() );
1459 
1460  orientSymbol( &tempSymbol, aSymbol->GetOrientation() );
1461 
1462  for( auto& tempItem : tempSymbol.GetDrawItems() )
1463  {
1464  tempItem.SetFlags( aSymbol->GetFlags() ); // SELECTED, HIGHLIGHTED, BRIGHTENED
1465  tempItem.MoveTo( tempItem.GetPosition() + (wxPoint) mapCoords( aSymbol->GetPosition() ) );
1466  }
1467 
1468  // Copy the pin info from the symbol to the temp pins
1469  for( unsigned i = 0; i < tempPins.size(); ++ i )
1470  {
1471  SCH_PIN* symbolPin = aSymbol->GetPin( originalPins[ i ] );
1472  LIB_PIN* tempPin = tempPins[ i ];
1473 
1474  tempPin->ClearFlags();
1475  tempPin->SetFlags( symbolPin->GetFlags() ); // SELECTED, HIGHLIGHTED, BRIGHTENED
1476 
1477  tempPin->SetName( symbolPin->GetShownName() );
1478  tempPin->SetType( symbolPin->GetType() );
1479  tempPin->SetShape( symbolPin->GetShape() );
1480 
1481  if( symbolPin->IsDangling() )
1482  tempPin->SetFlags( IS_DANGLING );
1483  }
1484 
1485  draw( &tempSymbol, aLayer, false, aSymbol->GetUnit(), aSymbol->GetConvert() );
1486 
1487  // The fields are SCH_SYMBOL-specific so don't need to be copied/oriented/translated
1488  for( const SCH_FIELD& field : aSymbol->GetFields() )
1489  draw( &field, aLayer );
1490 }
1491 
1492 
1493 void SCH_PAINTER::draw( const SCH_FIELD *aField, int aLayer )
1494 {
1495  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1496 
1497  if( drawingShadows && !aField->IsSelected() )
1498  return;
1499 
1500  aLayer = aField->GetLayer();
1501 
1502  COLOR4D color = getRenderColor( aField, aLayer, drawingShadows );
1503 
1504  if( !( aField->IsVisible() || aField->IsForceVisible() ) )
1505  {
1507  color = getRenderColor( aField, LAYER_HIDDEN, drawingShadows );
1508  else
1509  return;
1510  }
1511 
1512  if( aField->IsVoid() )
1513  return;
1514 
1515  if( drawingShadows && aField->GetParent()->IsSelected()
1517  {
1518  return;
1519  }
1520 
1521  bool underline = false;
1522 
1523  if( aField->IsHypertext() && ( aField->GetFlags() & IS_ROLLOVER ) > 0
1524  && !drawingShadows && !aField->IsMoving() )
1525  {
1526  color = PUREBLUE;
1527  underline = true;
1528  }
1529 
1530  // Calculate the text orientation according to the parent orientation.
1531  int orient = (int) aField->GetTextAngle();
1532 
1533  if( aField->GetParent() && aField->GetParent()->Type() == SCH_SYMBOL_T )
1534  {
1535  if( static_cast<SCH_SYMBOL*>( aField->GetParent() )->GetTransform().y1 )
1536  {
1537  // Rotate symbol 90 degrees.
1538  if( orient == TEXT_ANGLE_HORIZ )
1539  orient = TEXT_ANGLE_VERT;
1540  else
1541  orient = TEXT_ANGLE_HORIZ;
1542  }
1543  }
1544 
1545  /*
1546  * Calculate the text justification, according to the symbol orientation/mirror.
1547  * This is a bit complicated due to cumulative calculations:
1548  * - numerous cases (mirrored or not, rotation)
1549  * - the DrawGraphicText function recalculate also H and H justifications according to the
1550  * text orientation.
1551  * - when symbol is mirrored, the text is not mirrored and justifications are complicated
1552  * to calculate so the easier way is to use no justifications (centered text) and use
1553  * GetBoundingBox to know the text coordinate considered as centered
1554  */
1555  EDA_RECT bbox = aField->GetBoundingBox();
1556  wxPoint textpos = bbox.Centre();
1557 
1559  m_gal->SetIsStroke( true );
1560 
1561  if( drawingShadows && eeconfig()->m_Selection.text_as_box )
1562  {
1563  m_gal->SetIsFill( true );
1564  m_gal->SetFillColor( color );
1565  m_gal->SetLineWidth( m_gal->GetLineWidth() * 0.5 );
1566  bbox.RevertYAxis();
1567 
1568  m_gal->DrawRectangle( mapCoords( bbox.GetPosition() ), mapCoords( bbox.GetEnd() ) );
1569  }
1570  else
1571  {
1574  m_gal->SetIsFill( false );
1575  m_gal->SetGlyphSize( VECTOR2D( aField->GetTextSize() ) );
1576  m_gal->SetFontBold( aField->IsBold() );
1577  m_gal->SetFontItalic( aField->IsItalic() );
1578  m_gal->SetFontUnderlined( underline );
1579  m_gal->SetTextMirrored( aField->IsMirrored() );
1580  m_gal->SetLineWidth( getTextThickness( aField, drawingShadows ) );
1581 
1582  strokeText( aField->GetShownText(), textpos, orient == TEXT_ANGLE_VERT ? M_PI / 2 : 0 );
1583  }
1584 
1585  // Draw the umbilical line
1586  if( aField->IsMoving() )
1587  {
1588  wxPoint parentPos = aField->GetParentPosition();
1589 
1591  m_gal->SetStrokeColor( getRenderColor( aField, LAYER_SCHEMATIC_ANCHOR, drawingShadows ) );
1592  m_gal->DrawLine( textpos, parentPos );
1593  }
1594 }
1595 
1596 
1597 void SCH_PAINTER::draw( SCH_GLOBALLABEL *aLabel, int aLayer )
1598 {
1599  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1600 
1601  if( !drawingShadows || aLabel->IsSelected() )
1602  {
1603  COLOR4D color = getRenderColor( aLabel, LAYER_GLOBLABEL, drawingShadows );
1604 
1605  std::vector<wxPoint> pts;
1606  std::deque<VECTOR2D> pts2;
1607 
1608  aLabel->CreateGraphicShape( &m_schSettings, pts, aLabel->GetTextPos() );
1609 
1610  for( const wxPoint& p : pts )
1611  pts2.emplace_back( VECTOR2D( p.x, p.y ) );
1612 
1613  // The text is drawn inside the graphic shape.
1614  // On Cairo the graphic shape is filled by the background before drawing the text.
1615  // However if the text is selected, it is draw twice: first on LAYER_SELECTION_SHADOWS
1616  // and second on the text layer. The second must not erase the first drawing.
1617  bool fillBg = ( aLayer == LAYER_SELECTION_SHADOWS ) || !aLabel->IsSelected();
1618  m_gal->SetIsFill( fillBg );
1620  m_gal->SetIsStroke( true );
1621  m_gal->SetLineWidth( getTextThickness( aLabel, drawingShadows ) );
1623  m_gal->DrawPolyline( pts2 );
1624 
1625  draw( static_cast<SCH_TEXT*>( aLabel ), aLayer );
1626  }
1627 
1628  if( !drawingShadows || eeconfig()->m_Selection.draw_selected_children || !aLabel->IsSelected() )
1629  {
1630  draw( aLabel->GetIntersheetRefs(), aLayer );
1631  }
1632 }
1633 
1634 
1635 void SCH_PAINTER::draw( SCH_HIERLABEL *aLabel, int aLayer )
1636 {
1637  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1638 
1639  if( drawingShadows && !aLabel->IsSelected() )
1640  return;
1641 
1642  COLOR4D color = getRenderColor( aLabel, LAYER_HIERLABEL, drawingShadows );
1643 
1644  if( m_schematic )
1645  {
1646  SCH_CONNECTION* conn = aLabel->Connection();
1647 
1648  if( conn && conn->IsBus() )
1649  color = getRenderColor( aLabel, LAYER_BUS, drawingShadows );
1650  }
1651 
1652  std::vector<wxPoint> pts;
1653  std::deque<VECTOR2D> pts2;
1654 
1655  aLabel->CreateGraphicShape( &m_schSettings, pts, aLabel->GetTextPos() );
1656 
1657  for( const wxPoint& p : pts )
1658  pts2.emplace_back( VECTOR2D( p.x, p.y ) );
1659 
1660  m_gal->SetIsFill( true );
1662  m_gal->SetIsStroke( true );
1663  m_gal->SetLineWidth( getTextThickness( aLabel, drawingShadows ) );
1665  m_gal->DrawPolyline( pts2 );
1666 
1667  draw( static_cast<const SCH_TEXT*>( aLabel ), aLayer );
1668 }
1669 
1670 
1671 void SCH_PAINTER::draw( const SCH_SHEET *aSheet, int aLayer )
1672 {
1673  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1674 
1675  if( aLayer == LAYER_HIERLABEL || aLayer == LAYER_SELECTION_SHADOWS )
1676  {
1677  for( SCH_SHEET_PIN* sheetPin : aSheet->GetPins() )
1678  {
1679  if( drawingShadows && !aSheet->IsSelected() && !sheetPin->IsSelected() )
1680  continue;
1681 
1682  if( drawingShadows && aSheet->IsSelected()
1684  {
1685  break;
1686  }
1687 
1688  int width = std::max( aSheet->GetPenWidth(), m_schSettings.GetDefaultPenWidth() );
1689  wxPoint initial_pos = sheetPin->GetTextPos();
1690  wxPoint offset_pos = initial_pos;
1691 
1692  // For aesthetic reasons, the SHEET_PIN is drawn with a small offset of width / 2
1693  switch( sheetPin->GetEdge() )
1694  {
1695  case SHEET_SIDE::TOP: offset_pos.y += KiROUND( width / 2.0 ); break;
1696  case SHEET_SIDE::BOTTOM: offset_pos.y -= KiROUND( width / 2.0 ); break;
1697  case SHEET_SIDE::RIGHT: offset_pos.x -= KiROUND( width / 2.0 ); break;
1698  case SHEET_SIDE::LEFT: offset_pos.x += KiROUND( width / 2.0 ); break;
1699  default: break;
1700  }
1701 
1702  sheetPin->SetTextPos( offset_pos );
1703  draw( static_cast<SCH_HIERLABEL*>( sheetPin ), aLayer );
1704  m_gal->DrawLine( offset_pos, initial_pos );
1705  sheetPin->SetTextPos( initial_pos );
1706  }
1707  }
1708 
1709  VECTOR2D pos = aSheet->GetPosition();
1710  VECTOR2D size = aSheet->GetSize();
1711 
1712  if( aLayer == LAYER_SHEET_BACKGROUND )
1713  {
1715  m_gal->SetIsFill( true );
1716  m_gal->SetIsStroke( false );
1717 
1718  m_gal->DrawRectangle( pos, pos + size );
1719  }
1720 
1721  if( aLayer == LAYER_SHEET || aLayer == LAYER_SELECTION_SHADOWS )
1722  {
1723  m_gal->SetStrokeColor( getRenderColor( aSheet, LAYER_SHEET, drawingShadows ) );
1724  m_gal->SetIsStroke( true );
1725  m_gal->SetLineWidth( getLineWidth( aSheet, drawingShadows ) );
1726  m_gal->SetIsFill( false );
1727 
1728  m_gal->DrawRectangle( pos, pos + size );
1729 
1730  if( drawingShadows && !eeconfig()->m_Selection.draw_selected_children && aSheet->IsSelected() )
1731  return;
1732 
1733  for( const SCH_FIELD& field : aSheet->GetFields() )
1734  draw( &field, aLayer );
1735  }
1736 }
1737 
1738 
1739 void SCH_PAINTER::draw( const SCH_NO_CONNECT *aNC, int aLayer )
1740 {
1741  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1742 
1743  if( drawingShadows && !aNC->IsSelected() )
1744  return;
1745 
1746  m_gal->SetIsStroke( true );
1747  m_gal->SetLineWidth( getLineWidth( aNC, drawingShadows ) );
1748  m_gal->SetStrokeColor( getRenderColor( aNC, LAYER_NOCONNECT, drawingShadows ) );
1749  m_gal->SetIsFill( false );
1750 
1751  VECTOR2D p = aNC->GetPosition();
1752  int delta = std::max( aNC->GetSize(), m_schSettings.GetDefaultPenWidth() * 3 ) / 2;
1753 
1754  m_gal->DrawLine( p + VECTOR2D( -delta, -delta ), p + VECTOR2D( delta, delta ) );
1755  m_gal->DrawLine( p + VECTOR2D( -delta, delta ), p + VECTOR2D( delta, -delta ) );
1756 }
1757 
1758 
1759 void SCH_PAINTER::draw( const SCH_BUS_ENTRY_BASE *aEntry, int aLayer )
1760 {
1761  SCH_LAYER_ID layer = aEntry->Type() == SCH_BUS_WIRE_ENTRY_T ? LAYER_WIRE : LAYER_BUS;
1762  SCH_LINE line( wxPoint(), layer );
1763  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1764 
1765  if( drawingShadows && !aEntry->IsSelected() )
1766  return;
1767 
1768  if( aEntry->IsSelected() )
1769  line.SetSelected();
1770  else if( aEntry->IsBrightened() )
1771  line.SetBrightened();
1772 
1773  line.SetStartPoint( aEntry->GetPosition() );
1774  line.SetEndPoint( aEntry->GetEnd() );
1775  line.SetStroke( aEntry->GetStroke() );
1776  line.SetLineWidth( getLineWidth( aEntry, drawingShadows ) );
1777 
1778  COLOR4D color = getRenderColor( aEntry, LAYER_WIRE, drawingShadows );
1779 
1780  if( aEntry->Type() == SCH_BUS_BUS_ENTRY_T )
1781  color = getRenderColor( aEntry, LAYER_BUS, drawingShadows );
1782 
1783  line.SetLineColor( color );
1784  line.SetLineStyle( aEntry->GetStrokeStyle() );
1785 
1786  draw( &line, aLayer );
1787 
1788  m_gal->SetIsFill( false );
1789  m_gal->SetIsStroke( true );
1790  m_gal->SetLineWidth( drawingShadows ? getShadowWidth() : 1.0F );
1791 
1792  if( aEntry->IsDanglingStart() )
1793  {
1794  m_gal->DrawCircle( aEntry->GetPosition(),
1795  aEntry->GetPenWidth() + ( TARGET_BUSENTRY_RADIUS / 2 ) );
1796  }
1797 
1798  if( aEntry->IsDanglingEnd() )
1799  {
1800  m_gal->DrawCircle( aEntry->GetEnd(),
1801  aEntry->GetPenWidth() + ( TARGET_BUSENTRY_RADIUS / 2 ) );
1802  }
1803 }
1804 
1805 
1806 void SCH_PAINTER::draw( const SCH_BITMAP *aBitmap, int aLayer )
1807 {
1808  m_gal->Save();
1809  m_gal->Translate( aBitmap->GetPosition() );
1810 
1811  // When the image scale factor is not 1.0, we need to modify the actual as the image scale
1812  // factor is similar to a local zoom
1813  double img_scale = aBitmap->GetImageScale();
1814 
1815  if( img_scale != 1.0 )
1816  m_gal->Scale( VECTOR2D( img_scale, img_scale ) );
1817 
1818  if( aLayer == LAYER_DRAW_BITMAPS )
1819  {
1820  m_gal->DrawBitmap( *aBitmap->GetImage() );
1821  }
1822 
1823  if( aLayer == LAYER_SELECTION_SHADOWS )
1824  {
1825  if( aBitmap->IsSelected() || aBitmap->IsBrightened() )
1826  {
1827  COLOR4D color = getRenderColor( aBitmap, LAYER_DRAW_BITMAPS, true );
1828  m_gal->SetIsStroke( true );
1831  m_gal->SetIsFill( false );
1832 
1833  // Draws a bounding box.
1834  VECTOR2D bm_size( aBitmap->GetSize() );
1835  // bm_size is the actual image size in UI.
1836  // but m_gal scale was previously set to img_scale
1837  // so recalculate size relative to this image size.
1838  bm_size.x /= img_scale;
1839  bm_size.y /= img_scale;
1840  VECTOR2D origin( -bm_size.x / 2.0, -bm_size.y / 2.0 );
1841  VECTOR2D end = origin + bm_size;
1842 
1843  m_gal->DrawRectangle( origin, end );
1844  }
1845  }
1846 
1847  m_gal->Restore();
1848 }
1849 
1850 
1851 void SCH_PAINTER::draw( const SCH_MARKER *aMarker, int aLayer )
1852 {
1853  bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1854 
1855  if( drawingShadows && !aMarker->IsSelected() )
1856  return;
1857 
1858  COLOR4D color = getRenderColor( aMarker, aMarker->GetColorLayer(), drawingShadows );
1859 
1860  m_gal->Save();
1861  m_gal->Translate( aMarker->GetPosition() );
1862  m_gal->SetIsFill( !drawingShadows );
1863  m_gal->SetFillColor( color );
1864  m_gal->SetIsStroke( drawingShadows );
1865  m_gal->SetLineWidth( getLineWidth( aMarker, drawingShadows ) );
1867 
1868  SHAPE_LINE_CHAIN polygon;
1869  aMarker->ShapeToPolygon( polygon );
1870 
1871  m_gal->DrawPolygon( polygon );
1872  m_gal->Restore();
1873 }
1874 
1875 
1876 }; // 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.
const STROKE_FONT & GetStrokeFont() const
bool IsDangling() const override
Definition: sch_text.h:230
SCH_PAINTER(GAL *aGal)
CITER next(CITER it)
Definition: ptree.cpp:126
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
void CalcArcAngles(int &aStartAngle, int &aEndAngle) const
Definition: lib_shape.cpp:411
#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: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
#define DEFAULT_LABEL_SIZE_RATIO
The offset of the pin name string from the end of the pin in mils.
SCHEMATIC * m_schematic
Definition: sch_painter.h:198
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:706
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.
Auxiliary items (guides, rule, etc)
Definition: layer_ids.h:218
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
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:236
wxPoint GetStartPoint() const
Definition: sch_line.h:90
bool IsWire() const
Return true if the line is a wire.
Definition: sch_line.cpp:920
bool IsSelected() const
Definition: eda_item.h:123
const MATRIX3x3D & GetScreenWorldMatrix() const
Get the screen <-> world transformation matrix.
#define DEFAULT_WIRE_WIDTH_MILS
The default bus width in mils. (can be changed in preference menu)
void drawPinDanglingSymbol(const VECTOR2I &aPos, bool aDrawingShadows)
const Vec GetEnd() const
Definition: box2.h:178
#define DEFAULT_LINE_WIDTH_MILS
The default wire width in mils. (can be changed in preference menu)
wxPoint GetPosition() const override
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
int GetX() const
Definition: eda_rect.h:98
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
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 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:275
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:57
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:711
void SetFontBold(bool aBold)
Set bold property of current font.
bool ShowPinNumbers() const
Definition: lib_symbol.h:577
int GetWidth() const
Definition: eda_rect.h:109
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
double RAD2DECIDEG(double rad)
Definition: trigo.h:234
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 int GetEffectivePenWidth(const RENDER_SETTINGS *aSettings) const
Definition: lib_item.h:145
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:311
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:76
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
EDA_TEXT_HJUSTIFY_T GetHorizontalJustify() const
Return current text horizontal justification setting.
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:248
EESCHEMA_SETTINGS * eeconfig()
bool IsDangling() const override
Definition: sch_pin.h:85
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
Definition: lib_symbol.cpp:331
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.
wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: sch_field.cpp:105
void boxText(const wxString &aText, const VECTOR2D &aPosition, double aAngle)
bool IsVoid() const
Definition: sch_field.cpp:325
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:711
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:90
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 IsFilled() const
Definition: eda_shape.h:81
const VECTOR2D & GetGlyphSize() const
bool IsItalic() const
Definition: eda_text.h:180
PLOT_DASH_TYPE GetStrokeStyle() const
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:88
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:336
int GetUnit() const
Definition: lib_item.h:258
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:243
const wxPoint & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:122
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:67
#define IS_DANGLING
indicates a pin is dangling
bool IsDanglingStart() const
Definition: sch_bus_entry.h:47
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
void SetSelected()
Definition: eda_item.h:129
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
const std::vector< VECTOR2I > & CPoints() const
BITMAP_BASE * GetImage() const
Definition: sch_bitmap.h:54
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:324
#define DANGLING_SYMBOL_SIZE
< The size of the rectangle indicating an unconnected wire or label
wxPoint GetPosition() const override
Definition: sch_junction.h:92
wxString const GetElectricalTypeName() const
Definition: lib_pin.h:92
SHAPE_LINE_CHAIN & Outline(int aIndex)
virtual bool IsVisible() const
Definition: eda_text.h:186
constexpr double dot_mark_len(double aLineWidth)
Dashed and dotted line patterns.
const wxPoint GetOrigin() const
Definition: eda_rect.h:101
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
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:531
float GetDanglineSymbolThickness() const
Definition: sch_painter.h:95
void strokeText(const wxString &aText, const VECTOR2D &aPosition, double aRotationAngle)
Definition for symbol library class.
EDA_ITEM * GetParent() const
Definition: eda_item.h:115
bool ShowPinNames() const
Definition: lib_symbol.h:569
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:154
void SetX(int val)
Definition: eda_rect.h:158
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:1602
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:666
#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:193
bool IsVisible() const
Definition: lib_pin.h:97
GRAPHIC_PINSHAPE GetShape() const
Definition: sch_pin.cpp:122
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:65
to handle and draw images bitmaps
Definition: layer_ids.h:219
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_text.cpp:545
int GetNameTextSize() const
Definition: lib_pin.h:126
wxPoint GetCenter() const
Definition: lib_shape.h:89
VECTOR2D ComputeStringBoundaryLimits(const UTF8 &aText, const VECTOR2D &aGlyphSize, double aGlyphThickness) const
Compute the boundary limits of aText (the bounding box of all shapes).
constexpr double dash_gap_len(double aLineWidth)
wxString GetShownName() const
Definition: lib_pin.cpp:172
void SetVerticalJustify(const EDA_TEXT_VJUSTIFY_T aVerticalJustify)
Set the vertical justify for text drawing.
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:68
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:590
wxPoint GetPosition() const override
Definition: sch_sheet.h:380
void SetFontItalic(bool aItalic)
Set italic property of current font.
int GetConvert() const
Definition: lib_item.h:261
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.
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:40
int GetHeight() const
Definition: eda_rect.h:110
SHAPE_POLY_SET & GetPolyShape()
Definition: eda_shape.h:207
wxString UnescapeString(const wxString &aSource)
void SetGlyphSize(const VECTOR2D &aSize)
Set the font glyph size.
void SetY(int val)
Definition: eda_rect.h:164
virtual int GetPenWidth() const
Definition: sch_item.h:274
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
wxPoint GetPosition() const override
Definition: lib_pin.h:210
void draw(LIB_PIN *aPin, int aLayer)
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:257
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:413
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:156
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.
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:261
#define DEFAULT_BUS_WIDTH_MILS
The default noconnect size in mils.
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:1321
const EDA_RECT GetBoundingBox() const override
Definition: lib_text.cpp:376
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_field.cpp:266
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).
EDA_TEXT_VJUSTIFY_T GetVerticalJustify() const
Returns current text vertical justification setting.
wxSize GetSize() const
Definition: sch_sheet.h:105
Represent a polyline (an zero-thickness chain of connected line segments).
int internalPinDecoSize(const LIB_PIN &aPin)
#define IS_ROLLOVER
Rollover active. Used for hyperlink highlighting.
#define HANDLE_ITEM(type_id, type_name)
#define PIN_TEXT_MARGIN
Definition: lib_pin.cpp:38
SCH_PIN * GetPin(const wxString &number) const
Find a symbol pin by number.
Definition: sch_symbol.cpp:840
ELECTRICAL_PINTYPE GetType() const
Definition: sch_pin.cpp:113
bool IsStartDangling() const
Definition: sch_line.h:199
double GetImageScale() const
Definition: sch_bitmap.h:66
int GetEffectiveDiameter() const
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:383
double DECIDEG2RAD(double deg)
Definition: trigo.h:233
#define IU_PER_MILS
Definition: plotter.cpp:136
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
int GetY() const
Definition: eda_rect.h:99
#define TARGET_PIN_RADIUS
Definition: lib_pin.h:36
wxPoint GetPosition() const override
Definition: sch_symbol.h:644
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
constexpr int delta
#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
SHAPE_T GetShape() const
Definition: eda_shape.h:92
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
const EDA_RECT GetBoundingBoxRotated(const wxPoint &aRotCenter, double aAngle) const
Useful to calculate bounding box of rotated items, when rotation if not k*90 degrees.
Definition: eda_rect.cpp:513
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:121
int GetRadius() const
Definition: eda_shape.cpp:463
void SetDefaultPenWidth(int aWidth)
not connected (must be left open)
bool IsBus() const
wxPoint GetPosition() const override
Definition: lib_shape.h:86
wxPoint GetParentPosition() const
Definition: sch_field.cpp:763
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
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:182
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
Implement a stroke font drawing.
Definition: stroke_font.h:54
constexpr double dash_mark_len(double aLineWidth)
FILL_T GetFillType() const
Definition: eda_shape.h:79
#define DEFAULT_TEXT_OFFSET_RATIO
Ratio of the font height to space around global labels.
SCH_RENDER_SETTINGS m_schSettings
Definition: sch_painter.h:196
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
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