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_struct.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->Move( 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  // JEY TODO: IsMoving checks can go away after seleciton model is fully implemented...
239  else if( aItem->IsMoving() )
240  {
241  return color.Brightened( 0.5 );
242  }
243  else if( aItem->IsHighlighted() )
244  {
245  if ( aOnBackgroundLayer )
246  return COLOR4D( color.GetBrightness(), 0.0, 0.0, 0.3 );
247  else
248  return COLOR4D( 1.0, 0.3, 0.3, 1.0 );
249  }
250 
251  return color;
252 }
253 
254 
255 void SCH_PAINTER::draw( LIB_PART *aPart, int aLayer, bool aDrawFields, int aUnit, int aConvert )
256 {
257  if( !aUnit )
258  aUnit = m_schSettings.m_ShowUnit;
259 
260  if( !aConvert )
261  aConvert = m_schSettings.m_ShowConvert;
262 
263  for( auto& item : aPart->GetDrawItems() )
264  {
265  if( !aDrawFields && item.Type() == LIB_FIELD_T )
266  continue;
267 
268  if( aUnit && item.GetUnit() && aUnit != item.GetUnit() )
269  continue;
270 
271  if( aConvert && item.GetConvert() && aConvert != item.GetConvert() )
272  continue;
273 
274  Draw( &item, aLayer );
275  }
276 }
277 
278 
279 void SCH_PAINTER::draw( LIB_ALIAS *aAlias, int aLayer )
280 {
281  LIB_PART* comp = aAlias->GetPart();
282 
283  draw( comp, aLayer, false );
284 
285  LIB_FIELDS fields;
286  comp->GetFields( fields );
287 
288  if( !aAlias->IsRoot() )
289  {
290  fields[ VALUE ].SetText( aAlias->GetName() );
291  fields[ DATASHEET ].SetText( aAlias->GetDocFileName() );
292  }
293 
294  for( LIB_FIELD& field : fields )
295  draw( &field, aLayer );
296 }
297 
298 
299 static VECTOR2D mapCoords( const wxPoint& aCoord )
300 {
301  return VECTOR2D( aCoord.x, -aCoord.y );
302 }
303 
304 
305 void SCH_PAINTER::triLine( const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c )
306 {
307  m_gal->DrawLine( a, b );
308  m_gal->DrawLine( b, c );
309 }
310 
311 
312 bool SCH_PAINTER::setColors( const LIB_ITEM* aItem, int aLayer )
313 {
314  if( aLayer == LAYER_DEVICE_BACKGROUND && aItem->GetFillMode() == FILLED_WITH_BG_BODYCOLOR )
315  {
317 
318  // These actions place the item over others, so allow a modest transparency here
319  if( aItem->IsMoving() || aItem->IsDragging() || aItem->IsResized() )
320  color = color.WithAlpha( 0.75 );
321 
322  m_gal->SetIsFill( true );
324 
325  m_gal->SetIsStroke( false );
326  return true;
327  }
328  else if( aLayer == LAYER_DEVICE )
329  {
330  COLOR4D color = getRenderColor( aItem, LAYER_DEVICE, false );
331 
332  // These actions place the item over others, so allow a modest transparency here
333  if( aItem->IsMoving() || aItem->IsDragging() || aItem->IsResized() )
334  color = color.WithAlpha( 0.75 );
335 
337  m_gal->SetIsFill( aItem->GetFillMode() == FILLED_SHAPE );
339 
340  if( aItem->GetPenSize() > 0 )
341  {
342  m_gal->SetIsStroke( true );
343  m_gal->SetLineWidth( aItem->GetPenSize() );
344  }
345  else
346  m_gal->SetIsStroke( false );
347 
348  return true;
349  }
350 
351  return false;
352 }
353 
354 
355 void SCH_PAINTER::draw( LIB_RECTANGLE *aRect, int aLayer )
356 {
357  if( !isUnitAndConversionShown( aRect ) )
358  return;
359 
360  if( setColors( aRect, aLayer ) )
361  m_gal->DrawRectangle( mapCoords( aRect->GetPosition() ), mapCoords( aRect->GetEnd() ) );
362 
363 }
364 
365 
366 void SCH_PAINTER::draw( LIB_CIRCLE *aCircle, int aLayer )
367 {
368  if( !isUnitAndConversionShown( aCircle ) )
369  return;
370 
371  if( setColors( aCircle, aLayer ) )
372  m_gal->DrawCircle( mapCoords( aCircle->GetPosition() ), aCircle->GetRadius() );
373 }
374 
375 
376 void SCH_PAINTER::draw( LIB_ARC *aArc, int aLayer )
377 {
378  if( !isUnitAndConversionShown( aArc ) )
379  return;
380 
381  int sai = aArc->GetFirstRadiusAngle();
382  int eai = aArc->GetSecondRadiusAngle();
383 
384  if( TRANSFORM().MapAngles( &sai, &eai ) )
385  std::swap( sai, eai );
386 
387  double sa = (double) sai * M_PI / 1800.0;
388  double ea = (double) eai * M_PI / 1800.0 ;
389 
390  VECTOR2D pos = mapCoords( aArc->GetPosition() );
391 
392  if( setColors( aArc, aLayer ) )
393  m_gal->DrawArc( pos, aArc->GetRadius(), sa, ea );
394 }
395 
396 
397 void SCH_PAINTER::draw( LIB_POLYLINE *aLine, int aLayer )
398 {
399  if( !isUnitAndConversionShown( aLine ) )
400  return;
401 
402  const std::vector<wxPoint>& pts = aLine->GetPolyPoints();
403  std::deque<VECTOR2D> vtx;
404 
405  for( auto p : pts )
406  vtx.push_back( mapCoords( p ) );
407 
408  if( setColors( aLine, aLayer ) )
409  m_gal->DrawPolygon( vtx );
410 }
411 
412 
413 void SCH_PAINTER::draw( LIB_FIELD *aField, int aLayer )
414 {
415  // Must check layer as fields are sometimes drawn by their parent rather than
416  // directly from the view.
417  int layers[KIGFX::VIEW::VIEW_MAX_LAYERS], layers_count;
418  aField->ViewGetLayers( layers, layers_count );
419 
420  if( aLayer != layers[0] )
421  return;
422 
423  if( !isUnitAndConversionShown( aField ) )
424  return;
425 
426  auto color = getRenderColor( aField, aLayer, false );
427 
428  if( !aField->IsVisible() )
429  {
432  else
433  return;
434  }
435 
436  int linewidth = aField->GetPenSize();
437 
438  m_gal->SetLineWidth( linewidth );
439  m_gal->SetIsFill( false );
440  m_gal->SetIsStroke( true );
442  m_gal->SetGlyphSize( VECTOR2D( aField->GetTextSize() ) );
443  m_gal->SetFontItalic( aField->IsItalic() );
444 
446  m_gal->SetVerticalJustify( aField->GetVertJustify( ) );
447 
448  auto pos = mapCoords( aField->GetPosition() );
449  double orient = aField->GetTextAngleRadians();
450 
451  m_gal->StrokeText( aField->GetText(), pos, orient );
452 
453  // Draw the umbilical line
454  if( aField->IsMoving() && m_schSettings.m_ShowUmbilicals )
455  {
457  m_gal->SetStrokeColor( COLOR4D( 0.0, 0.0, 1.0, 1.0 ) );
458  m_gal->DrawLine( pos, wxPoint( 0, 0 ) );
459  }
460 }
461 
462 
463 void SCH_PAINTER::draw( LIB_TEXT *aText, int aLayer )
464 {
465  if( !isUnitAndConversionShown( aText ) )
466  return;
467 
468  auto color = getRenderColor( aText, LAYER_DEVICE, false );
469 
470  if( !aText->IsVisible() )
471  {
474  else
475  return;
476  }
477 
478  int linewidth = aText->GetPenSize();
479  EDA_RECT bBox = aText->GetBoundingBox();
480  bBox.RevertYAxis();
481  VECTOR2D pos = mapCoords( bBox.Centre() );
482  double orient = aText->GetTextAngleRadians();
483 
486  m_gal->SetLineWidth( linewidth );
487  m_gal->SetIsFill( false );
488  m_gal->SetIsStroke( true );
490  m_gal->SetGlyphSize( VECTOR2D( aText->GetTextSize() ) );
491  m_gal->SetFontBold( aText->IsBold() );
492  m_gal->SetFontItalic( aText->IsItalic() );
493  m_gal->StrokeText( aText->GetText(), pos, orient );
494 }
495 
496 
497 static int InternalPinDecoSize( const LIB_PIN &aPin )
498 {
499  return aPin.GetNameTextSize() != 0 ? aPin.GetNameTextSize() / 2 : aPin.GetNumberTextSize() / 2;
500 }
501 
502 
503 // Utility for getting the size of the 'external' pin decorators (as a radius)
504 // i.e. the negation circle, the polarity 'slopes' and the nonlogic marker
505 static int ExternalPinDecoSize( const LIB_PIN &aPin )
506 {
507  return aPin.GetNumberTextSize() / 2;
508 }
509 
510 
511 // Draw the target (an open circle) for a pin which has no connection or is being
512 // moved.
513 static void drawPinDanglingSymbol( GAL* aGal, const VECTOR2I& aPos, const COLOR4D& aColor )
514 {
515  aGal->SetIsStroke( true );
516  aGal->SetIsFill( false );
517  aGal->SetStrokeColor( aColor );
518 
519  aGal->SetLineWidth ( 1.0 );
520  aGal->DrawCircle( aPos, TARGET_PIN_RADIUS );
521 }
522 
523 
524 void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer )
525 {
526  if( aLayer != LAYER_DEVICE )
527  return;
528 
529  if( !isUnitAndConversionShown( aPin ) )
530  return;
531 
532  VECTOR2I pos = mapCoords( aPin->GetPosition() );
533  COLOR4D color = getRenderColor( aPin, LAYER_PIN, false );
534 
535  if( !aPin->IsVisible() )
536  {
538  {
540  }
541  else
542  {
543  if( ( aPin->GetFlags() & IS_DANGLING ) && aPin->IsPowerConnection() )
545 
546  return;
547  }
548  }
549 
550  VECTOR2I p0, dir;
551  int len = aPin->GetLength();
552  int width = aPin->GetPenSize();
553  int shape = aPin->GetShape();
554  int orient = aPin->GetOrientation();
555 
556  switch( orient )
557  {
558  case PIN_UP:
559  p0 = VECTOR2I( pos.x, pos.y - len );
560  dir = VECTOR2I(0, 1);
561  break;
562  case PIN_DOWN:
563  p0 = VECTOR2I( pos.x, pos.y + len );
564  dir = VECTOR2I(0, -1);
565  break;
566  case PIN_LEFT:
567  p0 = VECTOR2I( pos.x - len, pos.y );
568  dir = VECTOR2I(1, 0);
569  break;
570  case PIN_RIGHT:
571  p0 = VECTOR2I( pos.x + len, pos.y );
572  dir = VECTOR2I(-1, 0);
573  break;
574  }
575 
576  VECTOR2D pc;
577 
578  m_gal->SetIsStroke( true );
579  m_gal->SetIsFill( false );
580  m_gal->SetLineWidth( width );
582  m_gal->SetFontBold( false );
583  m_gal->SetFontItalic( false );
584 
585  const int radius = ExternalPinDecoSize( *aPin );
586  const int diam = radius*2;
587  const int clock_size = InternalPinDecoSize( *aPin );
588 
589  if( shape == PINSHAPE_INVERTED )
590  {
591  m_gal->DrawCircle( p0 + dir * radius, radius );
592  m_gal->DrawLine( p0 + dir * ( diam ), pos );
593  }
594  else if( shape == PINSHAPE_FALLING_EDGE_CLOCK )
595  {
596  pc = p0 + dir * clock_size ;
597 
598  triLine( p0 + VECTOR2D( dir.y, -dir.x) * clock_size,
599  pc,
600  p0 + VECTOR2D( -dir.y, dir.x) * clock_size );
601 
602  m_gal->DrawLine( pos, pc );
603  }
604  else
605  {
606  m_gal->DrawLine( p0, pos );
607  }
608 
609  if( shape == PINSHAPE_CLOCK )
610  {
611  if (!dir.y)
612  {
613  triLine( p0 + VECTOR2D( 0, clock_size ),
614  p0 + VECTOR2D( -dir.x * clock_size, 0 ),
615  p0 + VECTOR2D( 0, -clock_size ) );
616  }
617  else
618  {
619  triLine( p0 + VECTOR2D( clock_size, 0 ),
620  p0 + VECTOR2D( 0, -dir.y * clock_size ),
621  p0 + VECTOR2D( -clock_size, 0 ) );
622  }
623  }
624 
625  if( shape == PINSHAPE_INPUT_LOW )
626  {
627  if(!dir.y)
628  {
629  triLine( p0 + VECTOR2D(dir.x, 0) * diam,
630  p0 + VECTOR2D(dir.x, -1) * diam,
631  p0 );
632  }
633  else /* MapX1 = 0 */
634  {
635  triLine( p0 + VECTOR2D( 0, dir.y) * diam,
636  p0 + VECTOR2D(-1, dir.y) * diam,
637  p0 );
638  }
639  }
640 
641  if( shape == PINSHAPE_OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
642  {
643  if( !dir.y ) // Horizontal pin
644  m_gal->DrawLine( p0 - VECTOR2D( 0, diam ), p0 + VECTOR2D( dir.x, 0 ) * diam );
645  else // Vertical pin
646  m_gal->DrawLine( p0 - VECTOR2D( diam, 0 ), p0 + VECTOR2D( 0, dir.y ) * diam );
647  }
648 
649  if( shape == PINSHAPE_NONLOGIC ) /* NonLogic pin symbol */
650  {
651  m_gal->DrawLine( p0 - VECTOR2D( dir.x + dir.y, dir.y - dir.x ) * radius,
652  p0 + VECTOR2D( dir.x + dir.y, dir.y - dir.x ) * radius );
653  m_gal->DrawLine( p0 - VECTOR2D( dir.x - dir.y, dir.x + dir.y ) * radius,
654  p0 + VECTOR2D( dir.x - dir.y, dir.x + dir.y ) * radius );
655  }
656 
657  if( aPin->GetType() == PIN_NC ) // Draw a N.C. symbol
658  {
659  m_gal->DrawLine( pos + VECTOR2D( -1, -1 ) * TARGET_PIN_RADIUS,
660  pos + VECTOR2D( 1, 1 ) * TARGET_PIN_RADIUS );
661  m_gal->DrawLine( pos + VECTOR2D( 1, -1 ) * TARGET_PIN_RADIUS ,
662  pos + VECTOR2D( -1, 1 ) * TARGET_PIN_RADIUS );
663 
664  aPin->ClearFlags( IS_DANGLING ); // PIN_NC pin type is always not connected and dangling.
665  }
666 
667  if( ( aPin->GetFlags() & IS_DANGLING ) && ( aPin->IsVisible() || aPin->IsPowerConnection() ) )
669 
670  // Draw the labels
671 
672  LIB_PART* libEntry = aPin->GetParent();
673  int textOffset = libEntry->GetPinNameOffset();
674 
675  int nameLineWidth = aPin->GetPenSize();
676  nameLineWidth = Clamp_Text_PenSize( nameLineWidth, aPin->GetNameTextSize(), false );
677  int numLineWidth = aPin->GetPenSize();
678  numLineWidth = Clamp_Text_PenSize( numLineWidth, aPin->GetNumberTextSize(), false );
679 
680  #define PIN_TEXT_MARGIN 4
681 
682  // Four locations around a pin where text can be drawn
683  enum { INSIDE = 0, OUTSIDE, ABOVE, BELOW };
684  int size[4] = { 0, 0, 0, 0 };
685  int thickness[4] = { numLineWidth, numLineWidth, numLineWidth, numLineWidth };
686  COLOR4D colour[4];
687  wxString text[4];
688 
689  // TextOffset > 0 means pin NAMES on inside, pin NUMBERS above and nothing below
690  if( textOffset )
691  {
692  size [INSIDE] = libEntry->ShowPinNames() ? aPin->GetNameTextSize() : 0;
693  thickness[INSIDE] = nameLineWidth;
694  colour [INSIDE] = getRenderColor( aPin, LAYER_PINNAM, false );
695  text [INSIDE] = aPin->GetName();
696 
697  size [ABOVE] = libEntry->ShowPinNumbers() ? aPin->GetNumberTextSize() : 0;
698  thickness[ABOVE] = numLineWidth;
699  colour [ABOVE] = getRenderColor( aPin, LAYER_PINNUM, false );
700  text [ABOVE] = aPin->GetNumber();
701  }
702  // Otherwise pin NAMES go above and pin NUMBERS go below
703  else
704  {
705  size [ABOVE] = libEntry->ShowPinNames() ? aPin->GetNameTextSize() : 0;
706  thickness[ABOVE] = nameLineWidth;
707  colour [ABOVE] = getRenderColor( aPin, LAYER_PINNAM, false );
708  text [ABOVE] = aPin->GetName();
709 
710  size [BELOW] = libEntry->ShowPinNumbers() ? aPin->GetNumberTextSize() : 0;
711  thickness[BELOW] = numLineWidth;
712  colour [BELOW] = getRenderColor( aPin, LAYER_PINNUM, false );
713  text [BELOW] = aPin->GetNumber();
714  }
715 
717  {
718  size [OUTSIDE] = std::max( aPin->GetNameTextSize() * 3 / 4, Millimeter2iu( 0.7 ) );
719  thickness[OUTSIDE] = size[OUTSIDE] / 6;
720  colour [OUTSIDE] = getRenderColor( aPin, LAYER_NOTES, false );
721  text [OUTSIDE] = aPin->GetElectricalTypeName();
722  }
723 
724  if( !aPin->IsVisible() )
725  {
726  for( COLOR4D& c : colour )
728  }
729 
730  int insideOffset = textOffset;
731  int outsideOffset = 10;
732  int aboveOffset = PIN_TEXT_MARGIN + ( thickness[ABOVE] + GetDefaultLineThickness() ) / 2;
733  int belowOffset = PIN_TEXT_MARGIN + ( thickness[BELOW] + GetDefaultLineThickness() ) / 2;
734 
735  #define SET_DC( i ) \
736  m_gal->SetGlyphSize( VECTOR2D( size[i], size[i] ) ); \
737  m_gal->SetLineWidth( thickness[i] ); \
738  m_gal->SetStrokeColor( colour[i] );
739 
740  switch( orient )
741  {
742  case PIN_LEFT:
743  if( size[INSIDE] )
744  {
745  SET_DC( INSIDE );
748  m_gal->StrokeText( text[INSIDE], pos + VECTOR2D( -insideOffset - len, 0 ), 0 );
749  }
750  if( size[OUTSIDE] )
751  {
752  SET_DC( OUTSIDE );
755  m_gal->StrokeText( text[OUTSIDE], pos + VECTOR2D( outsideOffset, 0 ), 0 );
756  }
757  if( size[ABOVE] )
758  {
759  SET_DC( ABOVE );
762  m_gal->StrokeText( text[ABOVE], pos + VECTOR2D( -len / 2.0, -aboveOffset ), 0 );
763  }
764  if( size[BELOW] )
765  {
766  SET_DC( BELOW );
769  m_gal->StrokeText( text[BELOW], pos + VECTOR2D( -len / 2.0, belowOffset ), 0 );
770  }
771  break;
772 
773  case PIN_RIGHT:
774  if( size[INSIDE] )
775  {
776  SET_DC( INSIDE );
780  m_gal->StrokeText( text[INSIDE], pos + VECTOR2D( insideOffset + len, 0 ), 0 );
781  }
782  if( size[OUTSIDE] )
783  {
784  SET_DC( OUTSIDE );
787  m_gal->StrokeText( text[OUTSIDE], pos + VECTOR2D( -outsideOffset, 0 ), 0 );
788  }
789  if( size[ABOVE] )
790  {
791  SET_DC( ABOVE );
794  m_gal->StrokeText( text[ABOVE], pos + VECTOR2D( len / 2.0, -aboveOffset ), 0 );
795  }
796  if( size[BELOW] )
797  {
798  SET_DC( BELOW );
801  m_gal->StrokeText( text[BELOW], pos + VECTOR2D( len / 2.0, belowOffset ), 0 );
802  }
803  break;
804 
805  case PIN_DOWN:
806  if( size[INSIDE] )
807  {
808  SET_DC( INSIDE );
811  m_gal->StrokeText ( text[INSIDE], pos + VECTOR2D( 0, insideOffset + len ), M_PI / 2);
812  }
813  if( size[OUTSIDE] )
814  {
815  SET_DC( OUTSIDE );
818  m_gal->StrokeText ( text[OUTSIDE], pos + VECTOR2D( 0, -outsideOffset ), M_PI / 2);
819  }
820  if( size[ABOVE] )
821  {
822  SET_DC( ABOVE );
825  m_gal->StrokeText( text[ABOVE], pos + VECTOR2D( -aboveOffset, len / 2.0 ), M_PI / 2 );
826  }
827  if( size[BELOW] )
828  {
829  SET_DC( BELOW );
832  m_gal->StrokeText( text[BELOW], pos + VECTOR2D( belowOffset, len / 2.0 ), M_PI / 2 );
833  }
834  break;
835 
836  case PIN_UP:
837  if( size[INSIDE] )
838  {
839  SET_DC( INSIDE );
842  m_gal->StrokeText ( text[INSIDE], pos + VECTOR2D( 0, -insideOffset - len ), M_PI / 2);
843  }
844  if( size[OUTSIDE] )
845  {
846  SET_DC( OUTSIDE );
849  m_gal->StrokeText ( text[OUTSIDE], pos + VECTOR2D( 0, outsideOffset ), M_PI / 2);
850  }
851  if( size[ABOVE] )
852  {
853  SET_DC( ABOVE );
856  m_gal->StrokeText( text[ABOVE], pos + VECTOR2D( -aboveOffset, -len / 2.0 ), M_PI / 2 );
857  }
858  if( size[BELOW] )
859  {
860  SET_DC( BELOW );
863  m_gal->StrokeText( text[BELOW], pos + VECTOR2D( belowOffset, -len / 2.0 ), M_PI / 2 );
864  }
865  break;
866 
867  default:
868  wxFAIL_MSG( "Unknown pin orientation" );
869  }
870 }
871 
872 
873 void SCH_PAINTER::draw( LIB_BEZIER *aCurve, int aLayer )
874 {
875  if( !isUnitAndConversionShown( aCurve ) )
876  return;
877 
878  if( setColors( aCurve, aLayer ) )
879  {
880  BEZIER_POLY poly ( aCurve->GetPoints() );
881  std::vector<wxPoint> pts;
882  std::deque<VECTOR2D> pts_xformed;
883  poly.GetPoly( pts );
884 
885  for( const auto &p : pts )
886  {
887  pts_xformed.push_back( mapCoords( p ) );
888  }
889 
890  m_gal->DrawPolygon( pts_xformed );
891  }
892 }
893 
894 
895 // Draw the target (an open square) for a wire or label which has no connection or is
896 // being moved.
897 static void drawDanglingSymbol( GAL* aGal, const wxPoint& aPos )
898 {
899  wxPoint radius( DANGLING_SYMBOL_SIZE, DANGLING_SYMBOL_SIZE );
900 
901  aGal->SetIsStroke( true );
902  aGal->SetIsFill( false );
903  aGal->SetLineWidth ( 1.0 );
904 
905  aGal->DrawRectangle( aPos - radius, aPos + radius );
906 }
907 
908 
909 void SCH_PAINTER::draw( SCH_JUNCTION *aJct, int aLayer )
910 {
911  COLOR4D color;
912  auto conn = aJct->Connection( *g_CurrentSheet );
913 
914  if( conn && conn->IsBus() )
915  color = getRenderColor( aJct, LAYER_BUS, false );
916  else
917  color = getRenderColor( aJct, LAYER_JUNCTION, false );
918 
919  m_gal->SetIsStroke(true);
920  m_gal->SetIsFill(true);
924 }
925 
926 
927 void SCH_PAINTER::draw( SCH_LINE *aLine, int aLayer )
928 {
929  COLOR4D color = getRenderColor( aLine, aLine->GetLayer(), false );
930 
931  int width = aLine->GetPenSize();
932 
933  m_gal->SetIsStroke( true );
935  m_gal->SetLineWidth( width );
936 
937  if( aLine->GetLineStyle() <= PLOTDASHTYPE_SOLID )
938  {
939  m_gal->DrawLine( aLine->GetStartPoint(), aLine->GetEndPoint() );
940  }
941  else
942  {
943  VECTOR2D start = aLine->GetStartPoint();
944  VECTOR2D end = aLine->GetEndPoint();
945 
946  EDA_RECT clip( (wxPoint)start, wxSize( end.x - start.x, end.y - start.y ) );
947  clip.Normalize();
948 
949  double theta = atan2( end.y - start.y, end.x - start.x );
950  double strokes[] = { 1.0, DASH_GAP_LEN( width ), 1.0, DASH_GAP_LEN( width ) };
951 
952  switch( aLine->GetLineStyle() )
953  {
954  default:
955  case PLOTDASHTYPE_DASH:
956  strokes[0] = strokes[2] = DASH_MARK_LEN( width );
957  break;
958  case PLOTDASHTYPE_DOT:
959  strokes[0] = strokes[2] = DOT_MARK_LEN( width );
960  break;
962  strokes[0] = DASH_MARK_LEN( width );
963  strokes[2] = DOT_MARK_LEN( width );
964  break;
965  }
966 
967  for( size_t i = 0; i < 10000; ++i )
968  {
969  // Calculations MUST be done in doubles to keep from accumulating rounding
970  // errors as we go.
971  VECTOR2D next( start.x + strokes[ i % 4 ] * cos( theta ),
972  start.y + strokes[ i % 4 ] * sin( theta ) );
973 
974  // Drawing each segment can be done rounded to ints.
975  wxPoint segStart( KiROUND( start.x ), KiROUND( start.y ) );
976  wxPoint segEnd( KiROUND( next.x ), KiROUND( next.y ) );
977 
978  if( ClipLine( &clip, segStart.x, segStart.y, segEnd.x, segEnd.y ) )
979  break;
980  else if( i % 2 == 0 )
981  m_gal->DrawLine( segStart, segEnd );
982 
983  start = next;
984  }
985  }
986 
987  if( aLine->IsStartDangling() )
989 
990  if( aLine->IsEndDangling() )
992 }
993 
994 
995 void SCH_PAINTER::draw( SCH_TEXT *aText, int aLayer )
996 {
997  SCH_CONNECTION* conn = aText->Connection( *g_CurrentSheet );
998  COLOR4D color;
999 
1000  switch( aText->Type() )
1001  {
1002  case SCH_SHEET_PIN_T: color = getRenderColor( aText, LAYER_SHEETLABEL, false ); break;
1003  case SCH_HIER_LABEL_T: color = getRenderColor( aText, LAYER_HIERLABEL, false ); break;
1004  case SCH_GLOBAL_LABEL_T: color = getRenderColor( aText, LAYER_GLOBLABEL, false ); break;
1005  case SCH_LABEL_T: color = getRenderColor( aText, LAYER_LOCLABEL, false ); break;
1006  default: color = getRenderColor( aText, LAYER_NOTES, false ); break;
1007  }
1008 
1009  if( conn && conn->IsBus() )
1010  color = getRenderColor( aText, LAYER_BUS, false );
1011 
1012  if( !aText->IsVisible() )
1013  {
1016  else
1017  return;
1018  }
1019 
1021 
1022  if( aText->IsDangling() )
1023  drawDanglingSymbol( m_gal, aText->GetTextPos() );
1024 
1025  wxPoint text_offset = aText->GetTextPos() + aText->GetSchematicTextOffset();
1026  int linewidth = aText->GetPenSize();
1027  wxString shownText( aText->GetShownText() );
1028 
1029  if( !shownText.IsEmpty() )
1030  {
1031  m_gal->SetIsFill( false );
1032  m_gal->SetIsStroke( true );
1033  m_gal->SetTextAttributes( aText );
1034  m_gal->SetLineWidth( linewidth );
1035  m_gal->StrokeText( shownText, text_offset, aText->GetTextAngleRadians() );
1036  }
1037 }
1038 
1039 
1040 static void orientPart( LIB_PART* part, int orientation )
1041 {
1042  struct ORIENT
1043  {
1044  int flag;
1045  int n_rots;
1046  int mirror_x;
1047  int mirror_y;
1048  }
1049  orientations[] =
1050  {
1051  { CMP_ORIENT_0, 0, 0, 0 },
1052  { CMP_ORIENT_90, 1, 0, 0 },
1053  { CMP_ORIENT_180, 2, 0, 0 },
1054  { CMP_ORIENT_270, 3, 0, 0 },
1055  { CMP_MIRROR_X + CMP_ORIENT_0, 0, 1, 0 },
1056  { CMP_MIRROR_X + CMP_ORIENT_90, 1, 1, 0 },
1057  { CMP_MIRROR_Y, 0, 0, 1 },
1058  { CMP_MIRROR_X + CMP_ORIENT_270, 3, 1, 0 },
1059  { CMP_MIRROR_Y + CMP_ORIENT_0, 0, 0, 1 },
1060  { CMP_MIRROR_Y + CMP_ORIENT_90, 1, 0, 1 },
1061  { CMP_MIRROR_Y + CMP_ORIENT_180, 2, 0, 1 },
1062  { CMP_MIRROR_Y + CMP_ORIENT_270, 3, 0, 1 }
1063  };
1064 
1065  ORIENT o = orientations[ 0 ];
1066 
1067  for( auto& i : orientations )
1068  {
1069  if( i.flag == orientation )
1070  {
1071  o = i;
1072  break;
1073  }
1074  }
1075 
1076  for( auto& item : part->GetDrawItems() )
1077  {
1078  for( int i = 0; i < o.n_rots; i++ )
1079  item.Rotate( wxPoint(0, 0 ), true );
1080 
1081  if( o.mirror_x )
1082  item.MirrorVertical( wxPoint( 0, 0 ) );
1083 
1084  if( o.mirror_y )
1085  item.MirrorHorizontal( wxPoint( 0, 0 ) );
1086  }
1087 }
1088 
1089 
1090 void SCH_PAINTER::draw( SCH_COMPONENT *aComp, int aLayer )
1091 {
1092  PART_SPTR originalPartSptr = aComp->GetPartRef().lock();
1093 
1094  // Use dummy part if the actual couldn't be found (or couldn't be locked).
1095  LIB_PART* originalPart = originalPartSptr ? originalPartSptr.get() : dummy();
1096 
1097  // Copy the source so we can re-orient and translate it.
1098  LIB_PART tempPart( *originalPart );
1099 
1100  tempPart.SetFlags( aComp->GetFlags() );
1101 
1102  orientPart( &tempPart, aComp->GetOrientation());
1103 
1104  for( auto& tempItem : tempPart.GetDrawItems() )
1105  tempItem.Move( tempItem.GetPosition() + (wxPoint) mapCoords( aComp->GetPosition() ) );
1106 
1107  // Copy the pin info from the component to the temp pins
1108  LIB_PINS tempPins;
1109  tempPart.GetPins( tempPins, aComp->GetUnit(), aComp->GetConvert() );
1110  const SCH_PINS& compPins = aComp->GetPins();
1111 
1112  for( unsigned i = 0; i < tempPins.size() && i < compPins.size(); ++ i )
1113  {
1114  LIB_PIN* tempPin = tempPins[ i ];
1115  const SCH_PIN& compPin = compPins[ i ];
1116 
1117  tempPin->ClearFlags();
1118  tempPin->SetFlags( compPin.GetFlags() ); // SELECTED, HIGHLIGHTED, BRIGHTENED
1119 
1120  if( compPin.IsDangling() )
1121  tempPin->SetFlags( IS_DANGLING );
1122  }
1123 
1124  draw( &tempPart, aLayer, false, aComp->GetUnit(), aComp->GetConvert() );
1125 
1126  // The fields are SCH_COMPONENT-specific and so don't need to be copied/
1127  // oriented/translated.
1128  std::vector<SCH_FIELD*> fields;
1129  aComp->GetFields( fields, false );
1130 
1131  for( SCH_FIELD* field : fields )
1132  {
1133  if( !field->IsMoving() )
1134  draw( field, aLayer );
1135  }
1136 }
1137 
1138 
1139 void SCH_PAINTER::draw( SCH_FIELD *aField, int aLayer )
1140 {
1141  COLOR4D color;
1142  SCH_COMPONENT* parentComponent = (SCH_COMPONENT*) aField->GetParent();
1143 
1144  switch( aField->GetId() )
1145  {
1146  case REFERENCE: color = getRenderColor( aField, LAYER_REFERENCEPART, false ); break;
1147  case VALUE: color = getRenderColor( aField, LAYER_VALUEPART, false ); break;
1148  default: color = getRenderColor( aField, LAYER_FIELDS, false ); break;
1149  }
1150 
1151  if( !aField->IsVisible() )
1152  {
1155  else
1156  return;
1157  }
1158 
1159  if( aField->IsVoid() )
1160  return;
1161 
1162  // Calculate the text orientation according to the component orientation.
1163  int orient = (int) aField->GetTextAngle();
1164 
1165  if( parentComponent->GetTransform().y1 ) // Rotate component 90 degrees.
1166  {
1167  if( orient == TEXT_ANGLE_HORIZ )
1168  orient = TEXT_ANGLE_VERT;
1169  else
1170  orient = TEXT_ANGLE_HORIZ;
1171  }
1172 
1173  /* Calculate the text justification, according to the component
1174  * orientation/mirror this is a bit complicated due to cumulative
1175  * calculations:
1176  * - numerous cases (mirrored or not, rotation)
1177  * - the DrawGraphicText function recalculate also H and H justifications
1178  * according to the text orientation.
1179  * - When a component is mirrored, the text is not mirrored and
1180  * justifications are complicated to calculate
1181  * so the more easily way is to use no justifications ( Centered text )
1182  * and use GetBoundaryBox to know the text coordinate considered as centered
1183  */
1184  EDA_RECT boundaryBox = aField->GetBoundingBox();
1185  wxPoint textpos = boundaryBox.Centre();
1186  int lineWidth = aField->GetPenSize();
1187 
1191  m_gal->SetIsFill( false );
1192  m_gal->SetIsStroke( true );
1193  m_gal->SetGlyphSize( VECTOR2D( aField->GetTextSize() ) );
1194  m_gal->SetFontBold( aField->IsBold() );
1195  m_gal->SetFontItalic( aField->IsItalic() );
1196  m_gal->SetTextMirrored( aField->IsMirrored() );
1197  m_gal->SetLineWidth( lineWidth );
1198  m_gal->StrokeText( aField->GetFullyQualifiedText(), textpos, orient == TEXT_ANGLE_VERT ? M_PI/2 : 0 );
1199 
1200  // Draw the umbilical line
1201  if( aField->IsMoving() )
1202  {
1204  m_gal->SetStrokeColor( COLOR4D( 0.0, 0.0, 1.0, 1.0 ) );
1205  m_gal->DrawLine( textpos, parentComponent->GetPosition() );
1206  }
1207 }
1208 
1209 
1210 void SCH_PAINTER::draw( SCH_GLOBALLABEL *aLabel, int aLayer )
1211 {
1212  auto color = getRenderColor( aLabel, LAYER_GLOBLABEL, false );
1214  int width = aLabel->GetThickness() ? aLabel->GetThickness() : GetDefaultLineThickness();
1215 
1216  std::vector<wxPoint> pts;
1217  std::deque<VECTOR2D> pts2;
1218 
1219  aLabel->CreateGraphicShape( pts, aLabel->GetTextPos() );
1220 
1221  for( auto p : pts )
1222  pts2.emplace_back( VECTOR2D( p.x, p.y ) );
1223 
1224  m_gal->SetIsFill( true );
1225  m_gal->SetFillColor( back_color );
1226  m_gal->SetIsStroke( true );
1227  m_gal->SetLineWidth( width );
1229  m_gal->DrawPolyline( pts2 );
1230 
1231  draw( static_cast<SCH_TEXT*>( aLabel ), aLayer );
1232 }
1233 
1234 
1235 void SCH_PAINTER::draw( SCH_HIERLABEL *aLabel, int aLayer )
1236 {
1237  auto color = getRenderColor( aLabel, LAYER_SHEETLABEL, false );
1239  int width = aLabel->GetThickness() ? aLabel->GetThickness() : GetDefaultLineThickness();
1240 
1241  auto conn = aLabel->Connection( *g_CurrentSheet );
1242 
1243  if( conn && conn->IsBus() )
1244  color = getRenderColor( aLabel, LAYER_BUS, false );
1245 
1246  std::vector<wxPoint> pts;
1247  std::deque<VECTOR2D> pts2;
1248 
1249  aLabel->CreateGraphicShape( pts, aLabel->GetTextPos() );
1250 
1251  for( auto p : pts )
1252  pts2.emplace_back( VECTOR2D( p.x, p.y ) );
1253 
1254  m_gal->SetIsFill( true );
1255  m_gal->SetFillColor( back_color );
1256  m_gal->SetIsStroke( true );
1257  m_gal->SetLineWidth( width );
1259  m_gal->DrawPolyline( pts2 );
1260 
1261  draw( static_cast<SCH_TEXT*>( aLabel ), aLayer );
1262 }
1263 
1264 void SCH_PAINTER::draw( SCH_SHEET *aSheet, int aLayer )
1265 {
1266  VECTOR2D pos = aSheet->GetPosition();
1267  VECTOR2D size = aSheet->GetSize();
1268 
1269  if( aLayer == LAYER_SHEET_BACKGROUND )
1270  {
1271  m_gal->SetIsStroke( false );
1272 
1273  if( aSheet->IsMoving() ) // Gives a filled background when moving for a better look
1274  {
1275  // Select a fill color working well with black and white background color,
1276  // both in Opengl and Cairo
1277  m_gal->SetFillColor( COLOR4D( 0.1, 0.5, 0.5, 0.3 ) );
1278  m_gal->SetIsFill( true );
1279  }
1280  else
1281  {
1282  // Could be modified later, when sheets can have their own fill color
1283  return;
1284  }
1285 
1286  m_gal->DrawRectangle( pos, pos + size );
1287  }
1288  else if( aLayer == LAYER_SHEET )
1289  {
1291  m_gal->SetIsStroke( true );
1292 
1293  m_gal->SetIsFill( false );
1294  m_gal->SetLineWidth( aSheet->GetPenSize() );
1295 
1296  m_gal->DrawRectangle( pos, pos + size );
1297 
1298  VECTOR2D pos_sheetname = aSheet->GetSheetNamePosition();
1299  VECTOR2D pos_filename = aSheet->GetFileNamePosition();
1300  double nameAngle = 0.0;
1301 
1302  if( aSheet->IsVerticalOrientation() )
1303  nameAngle = -M_PI/2;
1304 
1306 
1307  auto text = wxT( "Sheet: " ) + aSheet->GetName();
1308 
1311 
1312  auto txtSize = aSheet->GetSheetNameSize();
1313 
1314  m_gal->SetGlyphSize( VECTOR2D( txtSize, txtSize ) );
1315  m_gal->SetFontBold( false );
1316  m_gal->SetFontItalic( false );
1317 
1318  m_gal->StrokeText( text, pos_sheetname, nameAngle );
1319 
1320  txtSize = aSheet->GetFileNameSize();
1321  m_gal->SetGlyphSize( VECTOR2D( txtSize, txtSize ) );
1324 
1325  text = wxT( "File: " ) + aSheet->GetFileName();
1326  m_gal->StrokeText( text, pos_filename, nameAngle );
1327  }
1328  else if( aLayer == LAYER_HIERLABEL )
1329  {
1330  for( auto& sheetPin : aSheet->GetPins() )
1331  {
1332  if( !sheetPin.IsMoving() )
1333  {
1334  // For aesthetic reasons, the SHEET_PIN is drawn with a small offset
1335  // of width / 2
1336  int width = aSheet->GetPenSize();
1337  wxPoint initial_pos = sheetPin.GetTextPos();
1338  wxPoint offset_pos = initial_pos;
1339 
1340  switch( sheetPin.GetEdge() )
1341  {
1342  case SCH_SHEET_PIN::SHEET_TOP_SIDE: offset_pos.y -= width / 2; break;
1343  case SCH_SHEET_PIN::SHEET_BOTTOM_SIDE: offset_pos.y += width / 2; break;
1344  case SCH_SHEET_PIN::SHEET_RIGHT_SIDE: offset_pos.x -= width / 2; break;
1345  case SCH_SHEET_PIN::SHEET_LEFT_SIDE: offset_pos.x += width / 2; break;
1346  default: break;
1347  }
1348 
1349  sheetPin.SetTextPos( offset_pos );
1350  draw( static_cast<SCH_HIERLABEL*>( &sheetPin ), aLayer );
1351  m_gal->DrawLine( offset_pos, initial_pos );
1352  sheetPin.SetTextPos( initial_pos );
1353  }
1354  }
1355  }
1356 }
1357 
1358 
1359 void SCH_PAINTER::draw( SCH_NO_CONNECT *aNC, int aLayer )
1360 {
1361  int delta = aNC->GetSize() / 2;
1362  int width = GetDefaultLineThickness();
1363 
1364  COLOR4D color = getRenderColor( aNC, LAYER_NOCONNECT, false );
1365 
1367  m_gal->SetIsStroke( true );
1368  m_gal->SetIsFill( false );
1369  m_gal->SetLineWidth( width );
1370 
1371  VECTOR2D p = aNC->GetPosition();
1372 
1373  m_gal->DrawLine( p + VECTOR2D( -delta, -delta ), p + VECTOR2D( delta, delta ) );
1374  m_gal->DrawLine( p + VECTOR2D( -delta, delta ), p + VECTOR2D( delta, -delta ) );
1375 }
1376 
1377 
1378 void SCH_PAINTER::draw( SCH_BUS_ENTRY_BASE *aEntry, int aLayer )
1379 {
1380  COLOR4D color = aEntry->Type() == SCH_BUS_BUS_ENTRY_T
1381  ? getRenderColor( aEntry, LAYER_BUS, false )
1382  : getRenderColor( aEntry, LAYER_WIRE, false );
1383 
1385  m_gal->SetIsStroke( true );
1386  m_gal->SetLineWidth( aEntry->GetPenSize() );
1387  m_gal->SetIsFill( false );
1388 
1389  VECTOR2D pos = aEntry->GetPosition();
1390  VECTOR2D endPos = aEntry->m_End();
1391 
1392  m_gal->DrawLine( pos, endPos );
1393 
1394  // Draw dangling symbols:
1395  m_gal->SetLineWidth ( 1.0 );
1396 
1397  if( aEntry->IsDanglingStart() )
1399 
1400  if( aEntry->IsDanglingEnd() )
1402 }
1403 
1404 
1405 void SCH_PAINTER::draw( SCH_BITMAP *aBitmap, int aLayer )
1406 {
1407  m_gal->Save();
1408  m_gal->Translate( aBitmap->GetPosition() );
1409 
1410  // When the image scale factor is not 1.0, we need to modify the actual
1411  // as the image scale factor is similar to a local zoom
1412  double img_scale = aBitmap->GetImageScale();
1413 
1414  if( img_scale != 1.0 )
1415  m_gal->Scale( VECTOR2D( img_scale, img_scale ) );
1416 
1417  m_gal->DrawBitmap( *aBitmap->GetImage() );
1418 
1419  m_gal->Restore();
1420 }
1421 
1422 
1423 void SCH_PAINTER::draw( SCH_MARKER *aMarker, int aLayer )
1424 {
1425  SHAPE_LINE_CHAIN polygon;
1426  aMarker->ShapeToPolygon( polygon );
1427 
1429 
1432 
1433  m_gal->Save();
1434  m_gal->Translate( aMarker->GetPosition() );
1435  m_gal->SetFillColor( color );
1436  m_gal->SetIsFill( true );
1437  m_gal->SetIsStroke( false );
1438  m_gal->DrawPolygon( polygon );
1439  m_gal->Restore();
1440 }
1441 
1442 
1443 }; // 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...
#define TEXT_ANGLE_HORIZ
Definition of the SCH_SHEET class for Eeschema.
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:191
Class SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:56
COLOR4D GetLineColor() const
Definition: sch_line.cpp:243
#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:209
bool IsMirrored() const
Definition: eda_text.h:197
SCH_SHEET_PINS & GetPins()
Definition: sch_sheet.h:333
name of datasheet
virtual bool IsDangling() const override
Definition: sch_text.h:179
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:76
float m_outlineWidth
Line width used when drawing outlines.
Definition: painter.h:287
bool IsSelected() const
Definition: base_struct.h:227
wxPoint GetEnd() const
#define TEXT_ANGLE_VERT
virtual 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:220
Base schematic object class definition.
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:57
Define a symbol library graphical text item.
Definition: lib_text.h:44
int GetOrientation() const
Definition: lib_pin.h:207
LIB_PART * GetParent() const
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_marker.h:101
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:194
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:221
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:182
int GetId() const
Definition: sch_field.h:89
static int InternalPinDecoSize(const LIB_PIN &aPin)
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_circle.h:85
virtual wxPoint GetSchematicTextOffset() const
Definition: sch_text.cpp:145
#define DASH_MARK_LEN(aLineWidth)
bool IsBrightened() const
Definition: base_struct.h:230
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:172
virtual const wxString GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:148
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:232
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:156
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:82
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:68
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:354
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:188
const std::vector< wxPoint > & GetPolyPoints() const
Definition: lib_polyline.h:67
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:274
int y1
Definition: transform.h:49
bool ShowPinNames()
int GetPenSize() const override
Definition: lib_pin.cpp:565
int GetSecondRadiusAngle() const
Definition: lib_arc.h:140
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:381
int GetUnit() const
#define VALUE
int GetUnit() const
int GetSheetNameSize() const
Definition: sch_sheet.h:270
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.
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:208
wxString GetName() const
Definition: sch_sheet.h:266
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:103
wxString const GetElectricalTypeName() const
return a translated string for messages giving the electrical type of the pin.
Definition: lib_pin.h:261
const wxString & GetName() const
Definition: lib_pin.h:152
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:161
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:233
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:845
#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:348
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:102
wxPoint m_End() const
int GetNameTextSize() const
Definition: lib_pin.h:178
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:545
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.
void SetEndPosition(const wxPoint &aPosition)
Definition: lib_rectangle.h:66
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:208
int GetRadius() const
Definition: lib_arc.h:132
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_pin.h:438
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.
void Move(const wxPoint &aPosition) override
Move a draw object to aPosition.
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:210
double GetTextAngleRadians() const
Definition: eda_text.h:185
void Normalize()
Function Normalize ensures that the height ant width are positive.
const wxString & GetNumber() const
Definition: lib_pin.h:180
void CreateGraphicShape(std::vector< wxPoint > &aPoints, const wxPoint &Pos) override
Calculate the graphic shape (a polygon) associated to the text.
Definition: sch_text.cpp:1085
ELECTRICAL_PINTYPE GetType() const
Get the electrical type of the pin.
Definition: lib_pin.h:237
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:62
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:205
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:41
#define IS_DANGLING
indicates a pin is dangling
Definition: base_struct.h:144
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
const EDA_RECT GetBoundingBox() const override
Definition: lib_text.cpp:285
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:160
void SetText(const wxString &aText) override
Sets the text item string to aText.
Definition: lib_text.cpp:319
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:258
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:72
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:242
int GetFirstRadiusAngle() const
Definition: lib_arc.h:136
void SetGlyphSize(const VECTOR2D aGlyphSize)
Set the font glyph size.
int GetPenSize() const override
Function GetPenSize virtual pure.
Definition: sch_line.cpp:296
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:153
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.
Definition of the SCH_FIELD class for Eeschema.
#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:287
int GetLineStyle() const
Definition: sch_line.cpp:269
static void drawDanglingSymbol(GAL *aGal, const wxPoint &aPos)
Implementation of the label properties dialog.
wxSize GetSize()
Definition: sch_sheet.h:280
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_rectangle.h:90
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:115
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:80