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  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 
27 #include <sch_item.h>
28 
29 #include <lib_draw_item.h>
30 #include <lib_rectangle.h>
31 #include <lib_pin.h>
32 #include <lib_circle.h>
33 #include <lib_polyline.h>
34 #include <lib_arc.h>
35 #include <lib_field.h>
36 #include <lib_text.h>
37 #include <lib_bezier.h>
38 #include <sch_line.h>
39 #include <sch_component.h>
40 #include <sch_field.h>
41 #include <sch_junction.h>
42 #include <sch_text.h>
43 #include <sch_no_connect.h>
44 #include <sch_bus_entry.h>
45 #include <sch_bitmap.h>
46 #include <sch_sheet.h>
47 #include <draw_graphic_text.h>
49 #include <lib_edit_frame.h>
50 #include <plotter.h>
51 #include <template_fieldnames.h>
52 #include <class_libentry.h>
53 #include <class_library.h>
54 #include <sch_edit_frame.h>
55 #include <view/view.h>
57 #include <colors_design_settings.h>
58 #include <connection_graph.h>
60 #include <bezier_curves.h>
61 
62 #include "sch_painter.h"
63 
64 namespace KIGFX
65 {
66 
68  m_ShowUnit( 0 ), m_ShowConvert( 0 )
69 {
70  ImportLegacyColors( nullptr );
71 
72  m_ShowHiddenText = true;
73  m_ShowHiddenPins = true;
75  m_ShowUmbilicals = true;
76 }
77 
78 
80 {
81  for( int layer = SCH_LAYER_ID_START; layer < SCH_LAYER_ID_END; layer ++)
82  m_layerColors[ layer ] = ::GetLayerColor( static_cast<SCH_LAYER_ID>( layer ) );
83 
84  for( int layer = GAL_LAYER_ID_START; layer < GAL_LAYER_ID_END; layer ++)
85  m_layerColors[ layer ] = ::GetLayerColor( static_cast<SCH_LAYER_ID>( layer ) );
86 
88 }
89 
90 
91 const COLOR4D& SCH_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer ) const
92 {
93  return m_layerColors[ aLayer ];
94 }
95 
96 
109 static LIB_PART* dummy()
110 {
111  static LIB_PART* part;
112 
113  if( !part )
114  {
115  part = new LIB_PART( wxEmptyString );
116 
117  LIB_RECTANGLE* square = new LIB_RECTANGLE( part );
118 
119  square->MoveTo( wxPoint( -200, 200 ));
120  square->SetEndPosition( wxPoint( 200, -200 ) );
121 
122  LIB_TEXT* text = new LIB_TEXT( part );
123 
124  text->SetTextSize( wxSize( 150, 150 ) );
125  text->SetText( wxString( wxT( "??" ) ) );
126 
127  part->AddDrawItem( square );
128  part->AddDrawItem( text );
129  }
130 
131  return part;
132 }
133 
134 
136  KIGFX::PAINTER (aGal)
137 { }
138 
139 
140 #define HANDLE_ITEM( type_id, type_name ) \
141  case type_id: draw( (type_name *) item, aLayer ); break;
142 
143 
144 bool SCH_PAINTER::Draw( const VIEW_ITEM *aItem, int aLayer )
145 {
146  auto item2 = static_cast<const EDA_ITEM*>( aItem );
147  auto item = const_cast<EDA_ITEM*>( item2 );
148 
150 
151 #ifdef CONNECTIVITY_DEBUG
152 
153  auto sch_item = dynamic_cast<SCH_ITEM*>( item );
154  auto conn = sch_item ? sch_item->Connection( *g_CurrentSheet ) : nullptr;
155 
156  if( conn )
157  {
158  auto pos = item->GetBoundingBox().Centre();
159  auto label = conn->Name( true );
160 
164  m_gal->SetLineWidth( 2 );
165  m_gal->SetGlyphSize( VECTOR2D( 20, 20 ) );
166  m_gal->StrokeText( conn->Name( true ), pos, 0.0 );
167  }
168 
169 #endif
170 
171  switch( item->Type() )
172  {
198 
199  default: return false;
200  }
201 
202  return false;
203 }
204 
205 
207 {
208  if( m_schSettings.m_ShowUnit // showing a specific unit
209  && aItem->GetUnit() // item is unit-specific
210  && aItem->GetUnit() != m_schSettings.m_ShowUnit )
211  {
212  return false;
213  }
214 
215  if( m_schSettings.m_ShowConvert // showing a specific conversion
216  && aItem->GetConvert() // item is conversion-specific
217  && aItem->GetConvert() != m_schSettings.m_ShowConvert )
218  {
219  return false;
220  }
221 
222  return true;
223 }
224 
225 
226 COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM* aItem, int aLayer, bool aOnBackgroundLayer )
227 {
228  if( aItem->IsBrightened() )
230 
231  const SCH_LINE* line = dynamic_cast<const SCH_LINE*>( aItem );
232  COLOR4D color = line ? line->GetLineColor() : m_schSettings.GetLayerColor( aLayer );
233 
234  if( aItem->IsSelected() )
235  {
236  return color.Brightened( 0.5 );
237  }
238  else if( aItem->IsHighlighted() )
239  {
240  if ( aOnBackgroundLayer )
241  return COLOR4D( color.GetBrightness(), 0.0, 0.0, 0.3 );
242  else
243  return COLOR4D( 1.0, 0.3, 0.3, 1.0 );
244  }
245 
246  return color;
247 }
248 
249 
250 void SCH_PAINTER::draw( LIB_PART *aPart, int aLayer, bool aDrawFields, int aUnit, int aConvert )
251 {
252  if( !aUnit )
253  aUnit = m_schSettings.m_ShowUnit;
254 
255  if( !aConvert )
256  aConvert = m_schSettings.m_ShowConvert;
257 
258  for( auto& item : aPart->GetDrawItems() )
259  {
260  if( !aDrawFields && item.Type() == LIB_FIELD_T )
261  continue;
262 
263  if( aUnit && item.GetUnit() && aUnit != item.GetUnit() )
264  continue;
265 
266  if( aConvert && item.GetConvert() && aConvert != item.GetConvert() )
267  continue;
268 
269  Draw( &item, aLayer );
270  }
271 }
272 
273 
274 void SCH_PAINTER::draw( LIB_ALIAS *aAlias, int aLayer )
275 {
276  LIB_PART* comp = aAlias->GetPart();
277 
278  draw( comp, aLayer, false );
279 
280  LIB_FIELDS fields;
281  comp->GetFields( fields );
282 
283  if( !aAlias->IsRoot() )
284  {
285  fields[ VALUE ].SetText( aAlias->GetName() );
286  fields[ DATASHEET ].SetText( aAlias->GetDocFileName() );
287  }
288 
289  for( LIB_FIELD& field : fields )
290  draw( &field, aLayer );
291 }
292 
293 
294 static VECTOR2D mapCoords( const wxPoint& aCoord )
295 {
296  return VECTOR2D( aCoord.x, -aCoord.y );
297 }
298 
299 
300 void SCH_PAINTER::triLine( const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c )
301 {
302  m_gal->DrawLine( a, b );
303  m_gal->DrawLine( b, c );
304 }
305 
306 
307 bool SCH_PAINTER::setColors( const LIB_ITEM* aItem, int aLayer )
308 {
309  if( aLayer == LAYER_DEVICE_BACKGROUND && aItem->GetFillMode() == FILLED_WITH_BG_BODYCOLOR )
310  {
312 
313  // These actions place the item over others, so allow a modest transparency here
314  if( aItem->IsMoving() || aItem->IsDragging() || aItem->IsResized() )
315  color = color.WithAlpha( 0.75 );
316 
317  m_gal->SetIsFill( true );
319 
320  m_gal->SetIsStroke( false );
321  return true;
322  }
323  else if( aLayer == LAYER_DEVICE )
324  {
325  COLOR4D color = getRenderColor( aItem, LAYER_DEVICE, false );
326 
328  m_gal->SetIsFill( aItem->GetFillMode() == FILLED_SHAPE );
330 
331  if( aItem->GetPenSize() > 0 )
332  {
333  m_gal->SetIsStroke( true );
334  m_gal->SetLineWidth( aItem->GetPenSize() );
335  }
336  else
337  m_gal->SetIsStroke( false );
338 
339  return true;
340  }
341 
342  return false;
343 }
344 
345 
346 void SCH_PAINTER::draw( LIB_RECTANGLE *aRect, int aLayer )
347 {
348  if( !isUnitAndConversionShown( aRect ) )
349  return;
350 
351  if( setColors( aRect, aLayer ) )
352  m_gal->DrawRectangle( mapCoords( aRect->GetPosition() ), mapCoords( aRect->GetEnd() ) );
353 
354 }
355 
356 
357 void SCH_PAINTER::draw( LIB_CIRCLE *aCircle, int aLayer )
358 {
359  if( !isUnitAndConversionShown( aCircle ) )
360  return;
361 
362  if( setColors( aCircle, aLayer ) )
363  m_gal->DrawCircle( mapCoords( aCircle->GetPosition() ), aCircle->GetRadius() );
364 }
365 
366 
367 void SCH_PAINTER::draw( LIB_ARC *aArc, int aLayer )
368 {
369  if( !isUnitAndConversionShown( aArc ) )
370  return;
371 
372  int sai = aArc->GetFirstRadiusAngle();
373  int eai = aArc->GetSecondRadiusAngle();
374 
375  if( TRANSFORM().MapAngles( &sai, &eai ) )
376  std::swap( sai, eai );
377 
378  double sa = (double) sai * M_PI / 1800.0;
379  double ea = (double) eai * M_PI / 1800.0 ;
380 
381  VECTOR2D pos = mapCoords( aArc->GetPosition() );
382 
383  if( setColors( aArc, aLayer ) )
384  m_gal->DrawArc( pos, aArc->GetRadius(), sa, ea );
385 }
386 
387 
388 void SCH_PAINTER::draw( LIB_POLYLINE *aLine, int aLayer )
389 {
390  if( !isUnitAndConversionShown( aLine ) )
391  return;
392 
393  const std::vector<wxPoint>& pts = aLine->GetPolyPoints();
394  std::deque<VECTOR2D> vtx;
395 
396  for( auto p : pts )
397  vtx.push_back( mapCoords( p ) );
398 
399  if( setColors( aLine, aLayer ) )
400  m_gal->DrawPolygon( vtx );
401 }
402 
403 
404 void SCH_PAINTER::draw( LIB_FIELD *aField, int aLayer )
405 {
406  // Must check layer as fields are sometimes drawn by their parent rather than
407  // directly from the view.
408  int layers[KIGFX::VIEW::VIEW_MAX_LAYERS], layers_count;
409  aField->ViewGetLayers( layers, layers_count );
410 
411  if( aLayer != layers[0] )
412  return;
413 
414  if( !isUnitAndConversionShown( aField ) )
415  return;
416 
417  auto color = getRenderColor( aField, aLayer, false );
418 
419  if( !aField->IsVisible() )
420  {
423  else
424  return;
425  }
426 
427  int linewidth = aField->GetPenSize();
428 
429  m_gal->SetLineWidth( linewidth );
430  m_gal->SetIsFill( false );
431  m_gal->SetIsStroke( true );
433  m_gal->SetGlyphSize( VECTOR2D( aField->GetTextSize() ) );
434  m_gal->SetFontItalic( aField->IsItalic() );
435 
437  m_gal->SetVerticalJustify( aField->GetVertJustify( ) );
438 
439  auto pos = mapCoords( aField->GetPosition() );
440  double orient = aField->GetTextAngleRadians();
441 
442  m_gal->StrokeText( aField->GetText(), pos, orient );
443 
444  // Draw the umbilical line
445  if( aField->IsMoving() && m_schSettings.m_ShowUmbilicals )
446  {
448  m_gal->SetStrokeColor( COLOR4D( 0.0, 0.0, 1.0, 1.0 ) );
449  m_gal->DrawLine( pos, wxPoint( 0, 0 ) );
450  }
451 }
452 
453 
454 void SCH_PAINTER::draw( LIB_TEXT *aText, int aLayer )
455 {
456  if( !isUnitAndConversionShown( aText ) )
457  return;
458 
459  auto color = getRenderColor( aText, LAYER_DEVICE, false );
460 
461  if( !aText->IsVisible() )
462  {
465  else
466  return;
467  }
468 
469  int linewidth = aText->GetPenSize();
470  EDA_RECT bBox = aText->GetBoundingBox();
471  bBox.RevertYAxis();
472  VECTOR2D pos = mapCoords( bBox.Centre() );
473  double orient = aText->GetTextAngleRadians();
474 
477  m_gal->SetLineWidth( linewidth );
478  m_gal->SetIsFill( false );
479  m_gal->SetIsStroke( true );
481  m_gal->SetGlyphSize( VECTOR2D( aText->GetTextSize() ) );
482  m_gal->SetFontBold( aText->IsBold() );
483  m_gal->SetFontItalic( aText->IsItalic() );
484  m_gal->StrokeText( aText->GetText(), pos, orient );
485 }
486 
487 
488 static int InternalPinDecoSize( const LIB_PIN &aPin )
489 {
490  return aPin.GetNameTextSize() != 0 ? aPin.GetNameTextSize() / 2 : aPin.GetNumberTextSize() / 2;
491 }
492 
493 
494 // Utility for getting the size of the 'external' pin decorators (as a radius)
495 // i.e. the negation circle, the polarity 'slopes' and the nonlogic marker
496 static int ExternalPinDecoSize( const LIB_PIN &aPin )
497 {
498  return aPin.GetNumberTextSize() / 2;
499 }
500 
501 
502 // Draw the target (an open circle) for a pin which has no connection or is being
503 // moved.
504 static void drawPinDanglingSymbol( GAL* aGal, const VECTOR2I& aPos, const COLOR4D& aColor )
505 {
506  aGal->SetIsStroke( true );
507  aGal->SetIsFill( false );
508  aGal->SetStrokeColor( aColor );
509 
510  aGal->SetLineWidth ( 1.0 );
511  aGal->DrawCircle( aPos, TARGET_PIN_RADIUS );
512 }
513 
514 
515 void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer )
516 {
517  if( aLayer != LAYER_DEVICE )
518  return;
519 
520  if( !isUnitAndConversionShown( aPin ) )
521  return;
522 
523  VECTOR2I pos = mapCoords( aPin->GetPosition() );
524  COLOR4D color = getRenderColor( aPin, LAYER_PIN, false );
525 
526  if( !aPin->IsVisible() )
527  {
529  {
531  }
532  else
533  {
534  if( ( aPin->GetFlags() & IS_DANGLING ) && aPin->IsPowerConnection() )
536 
537  return;
538  }
539  }
540 
541  VECTOR2I p0, dir;
542  int len = aPin->GetLength();
543  int width = aPin->GetPenSize();
544  int shape = aPin->GetShape();
545  int orient = aPin->GetOrientation();
546 
547  switch( orient )
548  {
549  case PIN_UP:
550  p0 = VECTOR2I( pos.x, pos.y - len );
551  dir = VECTOR2I(0, 1);
552  break;
553  case PIN_DOWN:
554  p0 = VECTOR2I( pos.x, pos.y + len );
555  dir = VECTOR2I(0, -1);
556  break;
557  case PIN_LEFT:
558  p0 = VECTOR2I( pos.x - len, pos.y );
559  dir = VECTOR2I(1, 0);
560  break;
561  case PIN_RIGHT:
562  p0 = VECTOR2I( pos.x + len, pos.y );
563  dir = VECTOR2I(-1, 0);
564  break;
565  }
566 
567  VECTOR2D pc;
568 
569  m_gal->SetIsStroke( true );
570  m_gal->SetIsFill( false );
571  m_gal->SetLineWidth( width );
573  m_gal->SetFontBold( false );
574  m_gal->SetFontItalic( false );
575 
576  const int radius = ExternalPinDecoSize( *aPin );
577  const int diam = radius*2;
578  const int clock_size = InternalPinDecoSize( *aPin );
579 
580  if( shape == PINSHAPE_INVERTED )
581  {
582  m_gal->DrawCircle( p0 + dir * radius, radius );
583  m_gal->DrawLine( p0 + dir * ( diam ), pos );
584  }
585  else if( shape == PINSHAPE_FALLING_EDGE_CLOCK )
586  {
587  pc = p0 + dir * clock_size ;
588 
589  triLine( p0 + VECTOR2D( dir.y, -dir.x) * clock_size,
590  pc,
591  p0 + VECTOR2D( -dir.y, dir.x) * clock_size );
592 
593  m_gal->DrawLine( pos, pc );
594  }
595  else
596  {
597  m_gal->DrawLine( p0, pos );
598  }
599 
600  if( shape == PINSHAPE_CLOCK )
601  {
602  if (!dir.y)
603  {
604  triLine( p0 + VECTOR2D( 0, clock_size ),
605  p0 + VECTOR2D( -dir.x * clock_size, 0 ),
606  p0 + VECTOR2D( 0, -clock_size ) );
607  }
608  else
609  {
610  triLine( p0 + VECTOR2D( clock_size, 0 ),
611  p0 + VECTOR2D( 0, -dir.y * clock_size ),
612  p0 + VECTOR2D( -clock_size, 0 ) );
613  }
614  }
615 
616  if( shape == PINSHAPE_INPUT_LOW )
617  {
618  if(!dir.y)
619  {
620  triLine( p0 + VECTOR2D(dir.x, 0) * diam,
621  p0 + VECTOR2D(dir.x, -1) * diam,
622  p0 );
623  }
624  else /* MapX1 = 0 */
625  {
626  triLine( p0 + VECTOR2D( 0, dir.y) * diam,
627  p0 + VECTOR2D(-1, dir.y) * diam,
628  p0 );
629  }
630  }
631 
632  if( shape == PINSHAPE_OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
633  {
634  if( !dir.y ) // Horizontal pin
635  m_gal->DrawLine( p0 - VECTOR2D( 0, diam ), p0 + VECTOR2D( dir.x, 0 ) * diam );
636  else // Vertical pin
637  m_gal->DrawLine( p0 - VECTOR2D( diam, 0 ), p0 + VECTOR2D( 0, dir.y ) * diam );
638  }
639 
640  if( shape == PINSHAPE_NONLOGIC ) /* NonLogic pin symbol */
641  {
642  m_gal->DrawLine( p0 - VECTOR2D( dir.x + dir.y, dir.y - dir.x ) * radius,
643  p0 + VECTOR2D( dir.x + dir.y, dir.y - dir.x ) * radius );
644  m_gal->DrawLine( p0 - VECTOR2D( dir.x - dir.y, dir.x + dir.y ) * radius,
645  p0 + VECTOR2D( dir.x - dir.y, dir.x + dir.y ) * radius );
646  }
647 
648  if( aPin->GetType() == PIN_NC ) // Draw a N.C. symbol
649  {
650  m_gal->DrawLine( pos + VECTOR2D( -1, -1 ) * TARGET_PIN_RADIUS,
651  pos + VECTOR2D( 1, 1 ) * TARGET_PIN_RADIUS );
652  m_gal->DrawLine( pos + VECTOR2D( 1, -1 ) * TARGET_PIN_RADIUS ,
653  pos + VECTOR2D( -1, 1 ) * TARGET_PIN_RADIUS );
654 
655  aPin->ClearFlags( IS_DANGLING ); // PIN_NC pin type is always not connected and dangling.
656  }
657 
658  if( ( aPin->GetFlags() & IS_DANGLING ) && ( aPin->IsVisible() || aPin->IsPowerConnection() ) )
660 
661  // Draw the labels
662 
663  LIB_PART* libEntry = aPin->GetParent();
664  int textOffset = libEntry->GetPinNameOffset();
665 
666  int nameLineWidth = aPin->GetPenSize();
667  nameLineWidth = Clamp_Text_PenSize( nameLineWidth, aPin->GetNameTextSize(), false );
668  int numLineWidth = aPin->GetPenSize();
669  numLineWidth = Clamp_Text_PenSize( numLineWidth, aPin->GetNumberTextSize(), false );
670 
671  #define PIN_TEXT_MARGIN 4
672 
673  // Four locations around a pin where text can be drawn
674  enum { INSIDE = 0, OUTSIDE, ABOVE, BELOW };
675  int size[4] = { 0, 0, 0, 0 };
676  int thickness[4] = { numLineWidth, numLineWidth, numLineWidth, numLineWidth };
677  COLOR4D colour[4];
678  wxString text[4];
679 
680  // TextOffset > 0 means pin NAMES on inside, pin NUMBERS above and nothing below
681  if( textOffset )
682  {
683  size [INSIDE] = libEntry->ShowPinNames() ? aPin->GetNameTextSize() : 0;
684  thickness[INSIDE] = nameLineWidth;
685  colour [INSIDE] = getRenderColor( aPin, LAYER_PINNAM, false );
686  text [INSIDE] = aPin->GetName();
687 
688  size [ABOVE] = libEntry->ShowPinNumbers() ? aPin->GetNumberTextSize() : 0;
689  thickness[ABOVE] = numLineWidth;
690  colour [ABOVE] = getRenderColor( aPin, LAYER_PINNUM, false );
691  text [ABOVE] = aPin->GetNumber();
692  }
693  // Otherwise pin NAMES go above and pin NUMBERS go below
694  else
695  {
696  size [ABOVE] = libEntry->ShowPinNames() ? aPin->GetNameTextSize() : 0;
697  thickness[ABOVE] = nameLineWidth;
698  colour [ABOVE] = getRenderColor( aPin, LAYER_PINNAM, false );
699  text [ABOVE] = aPin->GetName();
700 
701  size [BELOW] = libEntry->ShowPinNumbers() ? aPin->GetNumberTextSize() : 0;
702  thickness[BELOW] = numLineWidth;
703  colour [BELOW] = getRenderColor( aPin, LAYER_PINNUM, false );
704  text [BELOW] = aPin->GetNumber();
705  }
706 
708  {
709  size [OUTSIDE] = std::max( aPin->GetNameTextSize() * 3 / 4, Millimeter2iu( 0.7 ) );
710  thickness[OUTSIDE] = size[OUTSIDE] / 6;
711  colour [OUTSIDE] = getRenderColor( aPin, LAYER_NOTES, false );
712  text [OUTSIDE] = aPin->GetElectricalTypeName();
713  }
714 
715  if( !aPin->IsVisible() )
716  {
717  for( COLOR4D& c : colour )
719  }
720 
721  int insideOffset = textOffset;
722  int outsideOffset = 10;
723  int aboveOffset = PIN_TEXT_MARGIN + ( thickness[ABOVE] + GetDefaultLineThickness() ) / 2;
724  int belowOffset = PIN_TEXT_MARGIN + ( thickness[BELOW] + GetDefaultLineThickness() ) / 2;
725 
726  #define SET_DC( i ) \
727  m_gal->SetGlyphSize( VECTOR2D( size[i], size[i] ) ); \
728  m_gal->SetLineWidth( thickness[i] ); \
729  m_gal->SetStrokeColor( colour[i] );
730 
731  switch( orient )
732  {
733  case PIN_LEFT:
734  if( size[INSIDE] )
735  {
736  SET_DC( INSIDE );
739  m_gal->StrokeText( text[INSIDE], pos + VECTOR2D( -insideOffset - len, 0 ), 0 );
740  }
741  if( size[OUTSIDE] )
742  {
743  SET_DC( OUTSIDE );
746  m_gal->StrokeText( text[OUTSIDE], pos + VECTOR2D( outsideOffset, 0 ), 0 );
747  }
748  if( size[ABOVE] )
749  {
750  SET_DC( ABOVE );
753  m_gal->StrokeText( text[ABOVE], pos + VECTOR2D( -len / 2.0, -aboveOffset ), 0 );
754  }
755  if( size[BELOW] )
756  {
757  SET_DC( BELOW );
760  m_gal->StrokeText( text[BELOW], pos + VECTOR2D( -len / 2.0, belowOffset ), 0 );
761  }
762  break;
763 
764  case PIN_RIGHT:
765  if( size[INSIDE] )
766  {
767  SET_DC( INSIDE );
771  m_gal->StrokeText( text[INSIDE], pos + VECTOR2D( insideOffset + len, 0 ), 0 );
772  }
773  if( size[OUTSIDE] )
774  {
775  SET_DC( OUTSIDE );
778  m_gal->StrokeText( text[OUTSIDE], pos + VECTOR2D( -outsideOffset, 0 ), 0 );
779  }
780  if( size[ABOVE] )
781  {
782  SET_DC( ABOVE );
785  m_gal->StrokeText( text[ABOVE], pos + VECTOR2D( len / 2.0, -aboveOffset ), 0 );
786  }
787  if( size[BELOW] )
788  {
789  SET_DC( BELOW );
792  m_gal->StrokeText( text[BELOW], pos + VECTOR2D( len / 2.0, belowOffset ), 0 );
793  }
794  break;
795 
796  case PIN_DOWN:
797  if( size[INSIDE] )
798  {
799  SET_DC( INSIDE );
802  m_gal->StrokeText ( text[INSIDE], pos + VECTOR2D( 0, insideOffset + len ), M_PI / 2);
803  }
804  if( size[OUTSIDE] )
805  {
806  SET_DC( OUTSIDE );
809  m_gal->StrokeText ( text[OUTSIDE], pos + VECTOR2D( 0, -outsideOffset ), M_PI / 2);
810  }
811  if( size[ABOVE] )
812  {
813  SET_DC( ABOVE );
816  m_gal->StrokeText( text[ABOVE], pos + VECTOR2D( -aboveOffset, len / 2.0 ), M_PI / 2 );
817  }
818  if( size[BELOW] )
819  {
820  SET_DC( BELOW );
823  m_gal->StrokeText( text[BELOW], pos + VECTOR2D( belowOffset, len / 2.0 ), M_PI / 2 );
824  }
825  break;
826 
827  case PIN_UP:
828  if( size[INSIDE] )
829  {
830  SET_DC( INSIDE );
833  m_gal->StrokeText ( text[INSIDE], pos + VECTOR2D( 0, -insideOffset - len ), M_PI / 2);
834  }
835  if( size[OUTSIDE] )
836  {
837  SET_DC( OUTSIDE );
840  m_gal->StrokeText ( text[OUTSIDE], pos + VECTOR2D( 0, outsideOffset ), M_PI / 2);
841  }
842  if( size[ABOVE] )
843  {
844  SET_DC( ABOVE );
847  m_gal->StrokeText( text[ABOVE], pos + VECTOR2D( -aboveOffset, -len / 2.0 ), M_PI / 2 );
848  }
849  if( size[BELOW] )
850  {
851  SET_DC( BELOW );
854  m_gal->StrokeText( text[BELOW], pos + VECTOR2D( belowOffset, -len / 2.0 ), M_PI / 2 );
855  }
856  break;
857 
858  default:
859  wxFAIL_MSG( "Unknown pin orientation" );
860  }
861 }
862 
863 
864 void SCH_PAINTER::draw( LIB_BEZIER *aCurve, int aLayer )
865 {
866  if( !isUnitAndConversionShown( aCurve ) )
867  return;
868 
869  if( setColors( aCurve, aLayer ) )
870  {
871  BEZIER_POLY poly ( aCurve->GetPoints() );
872  std::vector<wxPoint> pts;
873  std::deque<VECTOR2D> pts_xformed;
874  poly.GetPoly( pts );
875 
876  for( const auto &p : pts )
877  {
878  pts_xformed.push_back( mapCoords( p ) );
879  }
880 
881  m_gal->DrawPolygon( pts_xformed );
882  }
883 }
884 
885 
886 // Draw the target (an open square) for a wire or label which has no connection or is
887 // being moved.
888 static void drawDanglingSymbol( GAL* aGal, const wxPoint& aPos )
889 {
890  wxPoint radius( DANGLING_SYMBOL_SIZE, DANGLING_SYMBOL_SIZE );
891 
892  aGal->SetIsStroke( true );
893  aGal->SetIsFill( false );
894  aGal->SetLineWidth ( 1.0 );
895 
896  aGal->DrawRectangle( aPos - radius, aPos + radius );
897 }
898 
899 
900 void SCH_PAINTER::draw( SCH_JUNCTION *aJct, int aLayer )
901 {
902  COLOR4D color;
903  auto conn = aJct->Connection( *g_CurrentSheet );
904 
905  if( conn && conn->IsBus() )
906  color = getRenderColor( aJct, LAYER_BUS, false );
907  else
908  color = getRenderColor( aJct, LAYER_JUNCTION, false );
909 
910  m_gal->SetIsStroke(true);
911  m_gal->SetIsFill(true);
915 }
916 
917 
918 void SCH_PAINTER::draw( SCH_LINE *aLine, int aLayer )
919 {
920  COLOR4D color = getRenderColor( aLine, aLine->GetLayer(), false );
921 
922  int width = aLine->GetPenSize();
923 
924  m_gal->SetIsStroke( true );
926  m_gal->SetLineWidth( width );
927 
928  if( aLine->GetLineStyle() <= PLOTDASHTYPE_SOLID )
929  {
930  m_gal->DrawLine( aLine->GetStartPoint(), aLine->GetEndPoint() );
931  }
932  else
933  {
934  VECTOR2D start = aLine->GetStartPoint();
935  VECTOR2D end = aLine->GetEndPoint();
936 
937  EDA_RECT clip( (wxPoint)start, wxSize( end.x - start.x, end.y - start.y ) );
938  clip.Normalize();
939 
940  double theta = atan2( end.y - start.y, end.x - start.x );
941  double strokes[] = { 1.0, DASH_GAP_LEN( width ), 1.0, DASH_GAP_LEN( width ) };
942 
943  switch( aLine->GetLineStyle() )
944  {
945  default:
946  case PLOTDASHTYPE_DASH:
947  strokes[0] = strokes[2] = DASH_MARK_LEN( width );
948  break;
949  case PLOTDASHTYPE_DOT:
950  strokes[0] = strokes[2] = DOT_MARK_LEN( width );
951  break;
953  strokes[0] = DASH_MARK_LEN( width );
954  strokes[2] = DOT_MARK_LEN( width );
955  break;
956  }
957 
958  for( size_t i = 0; i < 10000; ++i )
959  {
960  // Calculations MUST be done in doubles to keep from accumulating rounding
961  // errors as we go.
962  VECTOR2D next( start.x + strokes[ i % 4 ] * cos( theta ),
963  start.y + strokes[ i % 4 ] * sin( theta ) );
964 
965  // Drawing each segment can be done rounded to ints.
966  wxPoint segStart( KiROUND( start.x ), KiROUND( start.y ) );
967  wxPoint segEnd( KiROUND( next.x ), KiROUND( next.y ) );
968 
969  if( ClipLine( &clip, segStart.x, segStart.y, segEnd.x, segEnd.y ) )
970  break;
971  else if( i % 2 == 0 )
972  m_gal->DrawLine( segStart, segEnd );
973 
974  start = next;
975  }
976  }
977 
978  if( aLine->IsStartDangling() )
980 
981  if( aLine->IsEndDangling() )
983 }
984 
985 
986 void SCH_PAINTER::draw( SCH_TEXT *aText, int aLayer )
987 {
988  SCH_CONNECTION* conn = aText->Connection( *g_CurrentSheet );
989  COLOR4D color;
990 
991  switch( aText->Type() )
992  {
993  case SCH_SHEET_PIN_T: color = getRenderColor( aText, LAYER_SHEETLABEL, false ); break;
994  case SCH_HIER_LABEL_T: color = getRenderColor( aText, LAYER_HIERLABEL, false ); break;
995  case SCH_GLOBAL_LABEL_T: color = getRenderColor( aText, LAYER_GLOBLABEL, false ); break;
996  case SCH_LABEL_T: color = getRenderColor( aText, LAYER_LOCLABEL, false ); break;
997  default: color = getRenderColor( aText, LAYER_NOTES, false ); break;
998  }
999 
1000  if( conn && conn->IsBus() )
1001  color = getRenderColor( aText, LAYER_BUS, false );
1002 
1003  if( !aText->IsVisible() )
1004  {
1007  else
1008  return;
1009  }
1010 
1012 
1013  if( aText->IsDangling() )
1014  drawDanglingSymbol( m_gal, aText->GetTextPos() );
1015 
1016  wxPoint text_offset = aText->GetTextPos() + aText->GetSchematicTextOffset();
1017  int linewidth = aText->GetPenSize();
1018  wxString shownText( aText->GetShownText() );
1019 
1020  if( !shownText.IsEmpty() )
1021  {
1022  m_gal->SetIsFill( false );
1023  m_gal->SetIsStroke( true );
1024  m_gal->SetTextAttributes( aText );
1025  m_gal->SetLineWidth( linewidth );
1026  m_gal->StrokeText( shownText, text_offset, aText->GetTextAngleRadians() );
1027  }
1028 }
1029 
1030 
1031 static void orientPart( LIB_PART* part, int orientation )
1032 {
1033  struct ORIENT
1034  {
1035  int flag;
1036  int n_rots;
1037  int mirror_x;
1038  int mirror_y;
1039  }
1040  orientations[] =
1041  {
1042  { CMP_ORIENT_0, 0, 0, 0 },
1043  { CMP_ORIENT_90, 1, 0, 0 },
1044  { CMP_ORIENT_180, 2, 0, 0 },
1045  { CMP_ORIENT_270, 3, 0, 0 },
1046  { CMP_MIRROR_X + CMP_ORIENT_0, 0, 1, 0 },
1047  { CMP_MIRROR_X + CMP_ORIENT_90, 1, 1, 0 },
1048  { CMP_MIRROR_Y, 0, 0, 1 },
1049  { CMP_MIRROR_X + CMP_ORIENT_270, 3, 1, 0 },
1050  { CMP_MIRROR_Y + CMP_ORIENT_0, 0, 0, 1 },
1051  { CMP_MIRROR_Y + CMP_ORIENT_90, 1, 0, 1 },
1052  { CMP_MIRROR_Y + CMP_ORIENT_180, 2, 0, 1 },
1053  { CMP_MIRROR_Y + CMP_ORIENT_270, 3, 0, 1 }
1054  };
1055 
1056  ORIENT o = orientations[ 0 ];
1057 
1058  for( auto& i : orientations )
1059  {
1060  if( i.flag == orientation )
1061  {
1062  o = i;
1063  break;
1064  }
1065  }
1066 
1067  for( auto& item : part->GetDrawItems() )
1068  {
1069  for( int i = 0; i < o.n_rots; i++ )
1070  item.Rotate( wxPoint(0, 0 ), true );
1071 
1072  if( o.mirror_x )
1073  item.MirrorVertical( wxPoint( 0, 0 ) );
1074 
1075  if( o.mirror_y )
1076  item.MirrorHorizontal( wxPoint( 0, 0 ) );
1077  }
1078 }
1079 
1080 
1081 void SCH_PAINTER::draw( SCH_COMPONENT *aComp, int aLayer )
1082 {
1083  PART_SPTR originalPartSptr = aComp->GetPartRef().lock();
1084 
1085  // Use dummy part if the actual couldn't be found (or couldn't be locked).
1086  LIB_PART* originalPart = originalPartSptr ? originalPartSptr.get() : dummy();
1087 
1088  // Copy the source so we can re-orient and translate it.
1089  LIB_PART tempPart( *originalPart );
1090 
1091  tempPart.SetFlags( aComp->GetFlags() );
1092 
1093  orientPart( &tempPart, aComp->GetOrientation());
1094 
1095  for( auto& tempItem : tempPart.GetDrawItems() )
1096  {
1097  tempItem.SetFlags( aComp->GetFlags() ); // SELECTED, HIGHLIGHTED, BRIGHTENED
1098  tempItem.MoveTo( tempItem.GetPosition() + (wxPoint) mapCoords( aComp->GetPosition()));
1099  }
1100 
1101  // Copy the pin info from the component to the temp pins
1102  LIB_PINS tempPins;
1103  tempPart.GetPins( tempPins, aComp->GetUnit(), aComp->GetConvert() );
1104  const SCH_PINS& compPins = aComp->GetPins();
1105 
1106  for( unsigned i = 0; i < tempPins.size() && i < compPins.size(); ++ i )
1107  {
1108  LIB_PIN* tempPin = tempPins[ i ];
1109  const SCH_PIN& compPin = compPins[ i ];
1110 
1111  tempPin->ClearFlags();
1112  tempPin->SetFlags( compPin.GetFlags() ); // SELECTED, HIGHLIGHTED, BRIGHTENED
1113 
1114  if( compPin.IsDangling() )
1115  tempPin->SetFlags( IS_DANGLING );
1116  }
1117 
1118  draw( &tempPart, aLayer, false, aComp->GetUnit(), aComp->GetConvert() );
1119 
1120  // The fields are SCH_COMPONENT-specific and so don't need to be copied/
1121  // oriented/translated.
1122  std::vector<SCH_FIELD*> fields;
1123  aComp->GetFields( fields, false );
1124 
1125  for( SCH_FIELD* field : fields )
1126  draw( field, aLayer );
1127 }
1128 
1129 
1130 void SCH_PAINTER::draw( SCH_FIELD *aField, int aLayer )
1131 {
1132  COLOR4D color;
1133  SCH_COMPONENT* parentComponent = (SCH_COMPONENT*) aField->GetParent();
1134 
1135  switch( aField->GetId() )
1136  {
1137  case REFERENCE: color = getRenderColor( aField, LAYER_REFERENCEPART, false ); break;
1138  case VALUE: color = getRenderColor( aField, LAYER_VALUEPART, false ); break;
1139  default: color = getRenderColor( aField, LAYER_FIELDS, false ); break;
1140  }
1141 
1142  if( !aField->IsVisible() )
1143  {
1146  else
1147  return;
1148  }
1149 
1150  if( aField->IsVoid() )
1151  return;
1152 
1153  // Calculate the text orientation according to the component orientation.
1154  int orient = (int) aField->GetTextAngle();
1155 
1156  if( parentComponent->GetTransform().y1 ) // Rotate component 90 degrees.
1157  {
1158  if( orient == TEXT_ANGLE_HORIZ )
1159  orient = TEXT_ANGLE_VERT;
1160  else
1161  orient = TEXT_ANGLE_HORIZ;
1162  }
1163 
1164  /* Calculate the text justification, according to the component
1165  * orientation/mirror this is a bit complicated due to cumulative
1166  * calculations:
1167  * - numerous cases (mirrored or not, rotation)
1168  * - the DrawGraphicText function recalculate also H and H justifications
1169  * according to the text orientation.
1170  * - When a component is mirrored, the text is not mirrored and
1171  * justifications are complicated to calculate
1172  * so the more easily way is to use no justifications ( Centered text )
1173  * and use GetBoundaryBox to know the text coordinate considered as centered
1174  */
1175  EDA_RECT boundaryBox = aField->GetBoundingBox();
1176  wxPoint textpos = boundaryBox.Centre();
1177  int lineWidth = aField->GetPenSize();
1178 
1182  m_gal->SetIsFill( false );
1183  m_gal->SetIsStroke( true );
1184  m_gal->SetGlyphSize( VECTOR2D( aField->GetTextSize() ) );
1185  m_gal->SetFontBold( aField->IsBold() );
1186  m_gal->SetFontItalic( aField->IsItalic() );
1187  m_gal->SetTextMirrored( aField->IsMirrored() );
1188  m_gal->SetLineWidth( lineWidth );
1189  m_gal->StrokeText( aField->GetFullyQualifiedText(), textpos, orient == TEXT_ANGLE_VERT ? M_PI/2 : 0 );
1190 
1191  // Draw the umbilical line
1192  if( aField->IsMoving() )
1193  {
1195  m_gal->SetStrokeColor( COLOR4D( 0.0, 0.0, 1.0, 1.0 ) );
1196  m_gal->DrawLine( textpos, parentComponent->GetPosition() );
1197  }
1198 }
1199 
1200 
1201 void SCH_PAINTER::draw( SCH_GLOBALLABEL *aLabel, int aLayer )
1202 {
1203  auto color = getRenderColor( aLabel, LAYER_GLOBLABEL, false );
1205  int width = aLabel->GetThickness() ? aLabel->GetThickness() : GetDefaultLineThickness();
1206 
1207  std::vector<wxPoint> pts;
1208  std::deque<VECTOR2D> pts2;
1209 
1210  aLabel->CreateGraphicShape( pts, aLabel->GetTextPos() );
1211 
1212  for( auto p : pts )
1213  pts2.emplace_back( VECTOR2D( p.x, p.y ) );
1214 
1215  m_gal->SetIsFill( true );
1216  m_gal->SetFillColor( back_color );
1217  m_gal->SetIsStroke( true );
1218  m_gal->SetLineWidth( width );
1220  m_gal->DrawPolyline( pts2 );
1221 
1222  draw( static_cast<SCH_TEXT*>( aLabel ), aLayer );
1223 }
1224 
1225 
1226 void SCH_PAINTER::draw( SCH_HIERLABEL *aLabel, int aLayer )
1227 {
1228  auto color = getRenderColor( aLabel, LAYER_SHEETLABEL, false );
1230  int width = aLabel->GetThickness() ? aLabel->GetThickness() : GetDefaultLineThickness();
1231 
1232  auto conn = aLabel->Connection( *g_CurrentSheet );
1233 
1234  if( conn && conn->IsBus() )
1235  color = getRenderColor( aLabel, LAYER_BUS, false );
1236 
1237  std::vector<wxPoint> pts;
1238  std::deque<VECTOR2D> pts2;
1239 
1240  aLabel->CreateGraphicShape( pts, aLabel->GetTextPos() );
1241 
1242  for( auto p : pts )
1243  pts2.emplace_back( VECTOR2D( p.x, p.y ) );
1244 
1245  m_gal->SetIsFill( true );
1246  m_gal->SetFillColor( back_color );
1247  m_gal->SetIsStroke( true );
1248  m_gal->SetLineWidth( width );
1250  m_gal->DrawPolyline( pts2 );
1251 
1252  draw( static_cast<SCH_TEXT*>( aLabel ), aLayer );
1253 }
1254 
1255 void SCH_PAINTER::draw( SCH_SHEET *aSheet, int aLayer )
1256 {
1257  VECTOR2D pos = aSheet->GetPosition();
1258  VECTOR2D size = aSheet->GetSize();
1259 
1260  if( aLayer == LAYER_SHEET_BACKGROUND )
1261  {
1262  m_gal->SetIsStroke( false );
1263 
1264  if( aSheet->IsMoving() ) // Gives a filled background when moving for a better look
1265  {
1266  // Select a fill color working well with black and white background color,
1267  // both in Opengl and Cairo
1268  m_gal->SetFillColor( COLOR4D( 0.1, 0.5, 0.5, 0.3 ) );
1269  m_gal->SetIsFill( true );
1270  }
1271  else
1272  {
1273  // Could be modified later, when sheets can have their own fill color
1274  return;
1275  }
1276 
1277  m_gal->DrawRectangle( pos, pos + size );
1278  }
1279  else if( aLayer == LAYER_SHEET )
1280  {
1281  m_gal->SetStrokeColor( getRenderColor( aSheet, LAYER_SHEET, false ) );
1282  m_gal->SetIsStroke( true );
1283 
1284  m_gal->SetIsFill( false );
1285  m_gal->SetLineWidth( aSheet->GetPenSize() );
1286 
1287  m_gal->DrawRectangle( pos, pos + size );
1288 
1289  VECTOR2D pos_sheetname = aSheet->GetSheetNamePosition();
1290  VECTOR2D pos_filename = aSheet->GetFileNamePosition();
1291  double nameAngle = 0.0;
1292 
1293  if( aSheet->IsVerticalOrientation() )
1294  nameAngle = -M_PI/2;
1295 
1296  m_gal->SetStrokeColor( getRenderColor( aSheet, LAYER_SHEETNAME, false ) );
1297 
1298  auto text = wxT( "Sheet: " ) + aSheet->GetName();
1299 
1302 
1303  auto txtSize = aSheet->GetSheetNameSize();
1304 
1305  m_gal->SetGlyphSize( VECTOR2D( txtSize, txtSize ) );
1306  m_gal->SetFontBold( false );
1307  m_gal->SetFontItalic( false );
1308 
1309  m_gal->StrokeText( text, pos_sheetname, nameAngle );
1310 
1311  txtSize = aSheet->GetFileNameSize();
1312  m_gal->SetGlyphSize( VECTOR2D( txtSize, txtSize ) );
1315 
1316  text = wxT( "File: " ) + aSheet->GetFileName();
1317  m_gal->StrokeText( text, pos_filename, nameAngle );
1318  }
1319  else if( aLayer == LAYER_HIERLABEL )
1320  {
1321  for( auto& sheetPin : aSheet->GetPins() )
1322  {
1323  // For aesthetic reasons, the SHEET_PIN is drawn with a small offset
1324  // of width / 2
1325  int width = aSheet->GetPenSize();
1326  wxPoint initial_pos = sheetPin.GetTextPos();
1327  wxPoint offset_pos = initial_pos;
1328 
1329  switch( sheetPin.GetEdge() )
1330  {
1331  case SCH_SHEET_PIN::SHEET_TOP_SIDE: offset_pos.y -= width / 2; break;
1332  case SCH_SHEET_PIN::SHEET_BOTTOM_SIDE: offset_pos.y += width / 2; break;
1333  case SCH_SHEET_PIN::SHEET_RIGHT_SIDE: offset_pos.x -= width / 2; break;
1334  case SCH_SHEET_PIN::SHEET_LEFT_SIDE: offset_pos.x += width / 2; break;
1335  default: break;
1336  }
1337 
1338  sheetPin.SetTextPos( offset_pos );
1339  draw( static_cast<SCH_HIERLABEL*>( &sheetPin ), aLayer );
1340  m_gal->DrawLine( offset_pos, initial_pos );
1341  sheetPin.SetTextPos( initial_pos );
1342  }
1343  }
1344 }
1345 
1346 
1347 void SCH_PAINTER::draw( SCH_NO_CONNECT *aNC, int aLayer )
1348 {
1349  int delta = aNC->GetSize() / 2;
1350  int width = GetDefaultLineThickness();
1351 
1352  COLOR4D color = getRenderColor( aNC, LAYER_NOCONNECT, false );
1353 
1355  m_gal->SetIsStroke( true );
1356  m_gal->SetIsFill( false );
1357  m_gal->SetLineWidth( width );
1358 
1359  VECTOR2D p = aNC->GetPosition();
1360 
1361  m_gal->DrawLine( p + VECTOR2D( -delta, -delta ), p + VECTOR2D( delta, delta ) );
1362  m_gal->DrawLine( p + VECTOR2D( -delta, delta ), p + VECTOR2D( delta, -delta ) );
1363 }
1364 
1365 
1366 void SCH_PAINTER::draw( SCH_BUS_ENTRY_BASE *aEntry, int aLayer )
1367 {
1368  COLOR4D color = aEntry->Type() == SCH_BUS_BUS_ENTRY_T
1369  ? getRenderColor( aEntry, LAYER_BUS, false )
1370  : getRenderColor( aEntry, LAYER_WIRE, false );
1371 
1373  m_gal->SetIsStroke( true );
1374  m_gal->SetLineWidth( aEntry->GetPenSize() );
1375  m_gal->SetIsFill( false );
1376 
1377  VECTOR2D pos = aEntry->GetPosition();
1378  VECTOR2D endPos = aEntry->m_End();
1379 
1380  m_gal->DrawLine( pos, endPos );
1381 
1382  // Draw dangling symbols:
1383  m_gal->SetLineWidth ( 1.0 );
1384 
1385  if( aEntry->IsDanglingStart() )
1387 
1388  if( aEntry->IsDanglingEnd() )
1390 }
1391 
1392 
1393 void SCH_PAINTER::draw( SCH_BITMAP *aBitmap, int aLayer )
1394 {
1395  m_gal->Save();
1396  m_gal->Translate( aBitmap->GetPosition() );
1397 
1398  // When the image scale factor is not 1.0, we need to modify the actual
1399  // as the image scale factor is similar to a local zoom
1400  double img_scale = aBitmap->GetImageScale();
1401 
1402  if( img_scale != 1.0 )
1403  m_gal->Scale( VECTOR2D( img_scale, img_scale ) );
1404 
1405  m_gal->DrawBitmap( *aBitmap->GetImage() );
1406 
1407  m_gal->Restore();
1408 }
1409 
1410 
1411 void SCH_PAINTER::draw( SCH_MARKER *aMarker, int aLayer )
1412 {
1413  SHAPE_LINE_CHAIN polygon;
1414  aMarker->ShapeToPolygon( polygon );
1415 
1417  : LAYER_ERC_WARN;
1418  COLOR4D color = getRenderColor( aMarker, layer, false );
1419 
1420  m_gal->Save();
1421  m_gal->Translate( aMarker->GetPosition() );
1422  m_gal->SetFillColor( color );
1423  m_gal->SetIsFill( true );
1424  m_gal->SetIsStroke( false );
1425  m_gal->DrawPolygon( polygon );
1426  m_gal->Restore();
1427 }
1428 
1429 
1430 }; // 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:177
#define TEXT_ANGLE_HORIZ
SCH_PAINTER(GAL *aGal)
CITER next(CITER it)
Definition: ptree.cpp:130
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
void SetFontItalic(const bool aItalic)
Set italic property of current font.
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList)
Draw a polyline.
bool IsBold() const
Definition: eda_text.h:190
Class SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:52
COLOR4D GetLineColor() const
Definition: sch_line.cpp:257
#define TARGET_BUSENTRY_RADIUS
Definition: sch_bus_entry.h:35
int GetPenSize() const override
Function GetPenSize virtual pure.
Definition: sch_field.cpp:135
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
Part library alias object definition.
int Clamp_Text_PenSize(int aPenSize, int aSize, bool aBold)
Function Clamp_Text_PenSize As a rule, pen width should not be >1/4em, otherwise the character will b...
bool setColors(const LIB_ITEM *aItem, int aLayer)
PART_REF & GetPartRef()
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:208
bool IsMirrored() const
Definition: eda_text.h:196
SCH_SHEET_PINS & GetPins()
Definition: sch_sheet.h:322
name of datasheet
int GetPinNameOffset()
int GetOrientation()
Get the display symbol orientation.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:57
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:118
wxPoint GetStartPoint() const
Definition: sch_line.h:90
float m_outlineWidth
Line width used when drawing outlines.
Definition: painter.h:287
bool IsSelected() const
Definition: base_struct.h:227
wxPoint GetEnd() const
Definition: lib_rectangle.h:97
#define TEXT_ANGLE_VERT
int GetPenSize() const override
Function GetPenSize virtual pure.
Definition: sch_text.cpp:297
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_field.h:215
Handle colors used to draw all items or layers.
wxPoint GetPosition() const override
Function GetPosition.
MARKER_SEVERITY GetErrorLevel() const
Definition: marker_base.h:175
COLOR4D m_layerColors[LAYER_ID_COUNT]
Colors for all layers (normal)
Definition: painter.h:263
std::vector< SCH_PIN > SCH_PINS
A container for several SCH_PIN items.
Definition: sch_component.h:51
Define a symbol library graphical text item.
Definition: lib_text.h:44
int GetOrientation() const
Definition: lib_pin.h:205
LIB_PART * GetParent() const
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_marker.h:93
void GetPoly(std::vector< wxPoint > &aOutput, int aMinSegLen=0)
Converts Bezier curve to a polygon.
virtual void SetTextAttributes(const EDA_TEXT *aText)
Loads attributes of the given text (bold/italic/underline/mirrored and so on).
bool IsVisible() const
Definition: eda_text.h:193
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:219
virtual void DrawArc(const VECTOR2D &aCenterPoint, double aRadius, double aStartAngle, double aEndAngle)
Draw an arc.
virtual const COLOR4D & GetColor(const VIEW_ITEM *aItem, int aLayer) const override
Function GetColor Returns the color that should be used to draw the specific VIEW_ITEM on the specifi...
Definition: sch_painter.cpp:91
#define DANGLING_SYMBOL_SIZE
Definition: general.h:45
COLOR4D getRenderColor(const EDA_ITEM *aItem, int aLayer, bool aOnBackgroundLayer)
bool IsMoving() const
Definition: base_struct.h:224
int color
Definition: DXF_plotter.cpp:62
Field object used in symbol libraries.
Definition: lib_field.h:59
int GetDefaultLineThickness()
Default line thickness used to draw/plot items having a default thickness line value (i....
FILL_T GetFillMode() const
virtual void DrawBitmap(const BITMAP_BASE &aBitmap)
Draw a bitmap image.
const COLOR4D & GetLayerColor(int aLayer) const
Function GetLayerColor Returns the color used to draw a layer.
Definition: painter.h:219
double GetTextAngle() const
Definition: eda_text.h:181
int GetId() const
Definition: sch_field.h:105
static int InternalPinDecoSize(const LIB_PIN &aPin)
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_circle.h:79
virtual wxPoint GetSchematicTextOffset() const
Definition: sch_text.cpp:145
#define DASH_MARK_LEN(aLineWidth)
void MoveTo(const wxPoint &aPosition) override
Move a draw object to aPosition.
bool IsBrightened() const
Definition: base_struct.h:230
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:171
virtual const wxString GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:147
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:231
Definition: lib_pin.h:55
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape.
Add new GAL layers here.
Class VIEW_ITEM - is an abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:84
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_bitmap.h:152
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
int GetPenSize() const override
Function GetPenSize virtual pure.
Definition: sch_sheet.cpp:383
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
void RevertYAxis()
Function RevertYAxis Mirror the rectangle from the X axis (negate Y pos and size)
Definition: eda_rect.h:144
bool IsDangling() const override
Definition: sch_pin.h:81
Field Reference of part, i.e. "IC21".
bool IsHighlighted() const
Definition: base_struct.h:229
static const int delta[8][2]
Definition: solve.cpp:112
#define SET_DC(i)
bool IsVoid() const
Function IsVoid returns true if the field is either empty or holds "~".
Definition: sch_field.cpp:299
bool IsDanglingEnd() const
Definition: sch_bus_entry.h:52
bool IsDragging() const
Definition: base_struct.h:225
const wxString & GetDocFileName() const
static constexpr int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:712
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:360
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:67
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:352
virtual void SetLineWidth(float aLineWidth)
Set the line width.
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populates a std::vector with SCH_FIELDs.
bool IsVisible() const
Definition: lib_field.h:165
Base class for a bus or wire entry.
Definition: sch_bus_entry.h:41
void AddDrawItem(LIB_ITEM *aItem)
Add a new draw aItem to the draw object list.
bool IsItalic() const
Definition: eda_text.h:187
const std::vector< wxPoint > & GetPolyPoints() const
Definition: lib_polyline.h:66
static int ExternalPinDecoSize(const LIB_PIN &aPin)
void GetPins(LIB_PINS &aList, int aUnit=0, int aConvert=0)
Return a list of pin object pointers from the draw item list.
int GetFileNameSize() const
Definition: sch_sheet.h:265
int y1
Definition: transform.h:49
bool ShowPinNames()
int GetPenSize() const override
Definition: lib_pin.cpp:549
int GetSecondRadiusAngle() const
Definition: lib_arc.h:123
bool IsRoot() const override
For symbols having aliases, IsRoot() indicates the principal item.
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:371
int GetUnit() const
#define VALUE
int GetUnit() const
int GetSheetNameSize() const
Definition: sch_sheet.h:262
Class PAINTER contains all the knowledge about how to draw graphical object onto any particular outpu...
Definition: painter.h:308
bool ShowPinNumbers()
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
virtual int GetPenSize() const
Function GetPenSize virtual pure.
Definition: sch_item.h:212
bool IsDanglingStart() const
Definition: sch_bus_entry.h:51
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:259
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:207
wxString GetName() const
Definition: sch_sheet.h:259
SCH_SHEET_PATH * g_CurrentSheet
With the new connectivity algorithm, many more places than before want to know what the current sheet...
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
BITMAP_BASE * GetImage()
Definition: sch_bitmap.h:65
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_junction.h:95
wxString const GetElectricalTypeName() const
return a translated string for messages giving the electrical type of the pin.
Definition: lib_pin.h:259
const wxString & GetName() const
Definition: lib_pin.h:150
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
TRANSFORM & GetTransform() const
Class LIB_ITEM definition.
bool IsEndDangling() const
Definition: sch_line.h:174
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:232
std::shared_ptr< LIB_PART > PART_SPTR
shared pointer to LIB_PART
bool IsResized() const
Definition: base_struct.h:228
int GetSize() const
#define DOT_MARK_LEN(aLineWidth)
void ShapeToPolygon(SHAPE_LINE_CHAIN &aPolygon) const
Returns the shape polygon in internal units in a SHAPE_LINE_CHAIN the coordinates are relatives to th...
Define a library symbol object.
static void drawPinDanglingSymbol(GAL *aGal, const VECTOR2I &aPos, const COLOR4D &aColor)
EDA_ITEM * GetParent() const
Definition: base_struct.h:214
const std::vector< wxPoint > & GetPoints() const
Definition: lib_bezier.h:76
void CreateGraphicShape(std::vector< wxPoint > &aPoints, const wxPoint &aPos) override
Calculate the graphic shape (a polygon) associated to the text.
Definition: sch_text.cpp:832
#define OUTSIDE
void triLine(const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c)
a few functions useful in geometry calculations.
bool IsVisible() const
Return the visibility status of the draw object.
Definition: lib_pin.h:346
LIB_PART * GetPart() const
Get the shared LIB_PART.
void SetTextMirrored(const bool aMirrored)
Set a mirrored property of text.
int GetRadius() const
Definition: lib_circle.h:96
wxPoint m_End() const
int GetNameTextSize() const
Definition: lib_pin.h:176
void SetVerticalJustify(const EDA_TEXT_VJUSTIFY_T aVerticalJustify)
Set the vertical justify for text drawing.
static VECTOR2D mapCoords(const wxPoint &aCoord)
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_sheet.h:530
int GetConvert() const
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:42
SCH_CONNECTION * Connection(const SCH_SHEET_PATH &aPath) const
Retrieves the connection associated with this object in the given sheet.
Definition: sch_item.cpp:127
void SetEndPosition(const wxPoint &aPosition)
Definition: lib_rectangle.h:64
wxPoint GetFileNamePosition()
Definition: sch_sheet.cpp:408
virtual void Scale(const VECTOR2D &aScale)
Scale the context.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:201
int GetRadius() const
Definition: lib_arc.h:117
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_pin.h:432
wxString GetFileName(void) const
Return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:627
static void orientPart(LIB_PART *part, int orientation)
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
Definition: sch_item.h:193
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.
int GetPenSize() const override
Definition: lib_text.cpp:204
double GetTextAngleRadians() const
Definition: eda_text.h:184
void Normalize()
Function Normalize ensures that the height ant width are positive.
const wxString & GetNumber() const
Definition: lib_pin.h:178
void CreateGraphicShape(std::vector< wxPoint > &aPoints, const wxPoint &Pos) override
Calculate the graphic shape (a polygon) associated to the text.
Definition: sch_text.cpp:1072
ELECTRICAL_PINTYPE GetType() const
Get the electrical type of the pin.
Definition: lib_pin.h:235
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
Bezier curves to polygon converter.
Definition: bezier_curves.h:35
COLOR4D m_backgroundColor
The background color.
Definition: painter.h:292
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_draw_item.h:61
void GetPins(std::vector< LIB_PIN * > &aPinsList)
Populate a vector with all the pins from the library object.
virtual int GetPenSize() const =0
int GetNumberTextSize() const
Definition: lib_pin.h:203
const wxString & GetName() const override
virtual void Restore()
Restore the context.
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList)
Draw a polygon.
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
#define IS_DANGLING
indicates a pin is dangling
Definition: base_struct.h:143
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
const EDA_RECT GetBoundingBox() const override
Definition: lib_text.cpp:279
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_field.cpp:236
#define max(a, b)
Definition: auxiliary.h:86
bool isUnitAndConversionShown(const LIB_ITEM *aItem)
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
Class SHAPE_LINE_CHAIN.
bool IsVerticalOrientation() const
Definition: sch_sheet.cpp:221
#define HANDLE_ITEM(type_id, type_name)
bool IsStartDangling() const
Definition: sch_line.h:173
void SetText(const wxString &aText) override
Sets the text item string to aText.
Definition: lib_text.cpp:313
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:250
double GetImageScale() const
Definition: sch_bitmap.h:94
wxPoint GetSheetNamePosition()
Definition: sch_sheet.cpp:389
size_t i
Definition: json11.cpp:597
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
const wxString GetFullyQualifiedText() const
Function GetFullyQualifiedText returns the fully qualified field text by allowing for the part suffix...
Definition: sch_field.cpp:80
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73
wxPoint GetPosition() const override
Function GetPosition.
#define DASH_GAP_LEN(aLineWidth)
#define TARGET_PIN_RADIUS
Definition: lib_pin.h:43
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:157
wxPoint Centre() const
Definition: eda_rect.h:60
Class COLORS_DESIGN_SETTINGS is a list of color settings for designs in Pcbnew.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:260
const wxPoint & GetTextPos() const
Definition: eda_text.h:241
int GetFirstRadiusAngle() const
Definition: lib_arc.h:120
void SetGlyphSize(const VECTOR2D aGlyphSize)
Set the font glyph size.
int GetPenSize() const override
Function GetPenSize virtual pure.
Definition: sch_line.cpp:310
int GetConvert() const
int GetPenSize() const override
Definition: lib_field.cpp:118
void draw(LIB_RECTANGLE *aRect, int aLayer)
virtual wxString GetShownText() const
Returns the string actually shown after processing of the base text.
Definition: eda_text.h:152
virtual void Save()
Save the context.
void SetHorizontalJustify(const EDA_TEXT_HJUSTIFY_T aHorizontalJustify)
Set the horizontal justify for text drawing.
Definition for part library class.
#define INSIDE
bool IsBus() const
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:261
void ImportLegacyColors(const COLORS_DESIGN_SETTINGS *aSettings) override
Function ImportLegacyColors Loads a list of color settings for layers.
Definition: sch_painter.cpp:79
static int GetEffectiveSymbolSize()
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
#define PIN_TEXT_MARGIN
int GetLength()
Definition: lib_pin.h:285
int GetLineStyle() const
Definition: sch_line.cpp:283
static void drawDanglingSymbol(GAL *aGal, const wxPoint &aPos)
Implementation of the label properties dialog.
wxSize GetSize()
Definition: sch_sheet.h:270
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_rectangle.h:84
SCH_RENDER_SETTINGS m_schSettings
Definition: sch_painter.h:169
void GetFields(LIB_FIELDS &aList)
Return a list of fields within this part.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:204
Class GAL is the abstract interface for drawing on a 2D-surface.
Class LIB_BEZIER defines bezier curve graphic body item.
Definition: lib_bezier.h:39
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_arc.h:103
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
wxPoint GetPosition() const override
Function GetPosition.
wxPoint GetEndPoint() const
Definition: sch_line.h:93