KiCad PCB EDA Suite
view.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) 2013-2017 CERN
5  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  * @author Maciej Suminski <maciej.suminski@cern.ch>
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 <base_struct.h>
29 
30 #include <view/view.h>
31 #include <view/view_group.h>
32 #include <view/view_item.h>
33 #include <view/view_rtree.h>
34 #include <view/view_overlay.h>
35 
36 #include <gal/definitions.h>
38 #include <painter.h>
39 
40 #ifdef __WXDEBUG__
41 #include <profile.h>
42 #endif /* __WXDEBUG__ */
43 
44 namespace KIGFX {
45 
46 class VIEW;
47 
49 {
50 public:
52  m_view( nullptr ),
53  m_flags( KIGFX::VISIBLE ),
55  m_drawPriority( 0 ),
56  m_groups( nullptr ),
57  m_groupsSize( 0 ) {}
58 
60  {
61  deleteGroups();
62  }
63 
64  int getFlags() const
65  {
66  return m_flags;
67  }
68 
69 private:
70  friend class VIEW;
71 
79  void getLayers( int* aLayers, int& aCount ) const
80  {
81  int* layersPtr = aLayers;
82 
83  for( auto layer : m_layers )
84  *layersPtr++ = layer;
85 
86  aCount = m_layers.size();
87  }
88 
90  int m_flags;
93 
95  typedef std::pair<int, int> GroupPair;
96 
99  GroupPair* m_groups;
101 
109  int getGroup( int aLayer ) const
110  {
111  for( int i = 0; i < m_groupsSize; ++i )
112  {
113  if( m_groups[i].first == aLayer )
114  return m_groups[i].second;
115  }
116 
117  return -1;
118  }
119 
126  std::vector<int> getAllGroups() const
127  {
128  std::vector<int> groups( m_groupsSize );
129 
130  for( int i = 0; i < m_groupsSize; ++i )
131  {
132  groups[i] = m_groups[i].second;
133  }
134 
135  return groups;
136  }
137 
145  void setGroup( int aLayer, int aGroup )
146  {
147  // Look if there is already an entry for the layer
148  for( int i = 0; i < m_groupsSize; ++i )
149  {
150  if( m_groups[i].first == aLayer )
151  {
152  m_groups[i].second = aGroup;
153  return;
154  }
155  }
156 
157  // If there was no entry for the given layer - create one
158  GroupPair* newGroups = new GroupPair[m_groupsSize + 1];
159 
160  if( m_groupsSize > 0 )
161  {
162  std::copy( m_groups, m_groups + m_groupsSize, newGroups );
163  delete[] m_groups;
164  }
165 
166  m_groups = newGroups;
167  newGroups[m_groupsSize++] = GroupPair( aLayer, aGroup );
168  }
169 
170 
176  {
177  delete[] m_groups;
178  m_groups = nullptr;
179  m_groupsSize = 0;
180  }
181 
182 
189  inline bool storesGroups() const
190  {
191  return m_groupsSize > 0;
192  }
193 
194 
201  void reorderGroups( std::unordered_map<int, int> aReorderMap )
202  {
203  for( int i = 0; i < m_groupsSize; ++i )
204  {
205  int orig_layer = m_groups[i].first;
206  int new_layer = orig_layer;
207 
208  try
209  {
210  new_layer = aReorderMap.at( orig_layer );
211  }
212  catch( const std::out_of_range& ) {}
213 
214  m_groups[i].first = new_layer;
215  }
216  }
217 
218 
220  std::vector<int> m_layers;
221 
229  void saveLayers( int* aLayers, int aCount )
230  {
231  m_layers.clear();
232 
233  for( int i = 0; i < aCount; ++i )
234  {
235  // this fires on some eagle board after EAGLE_PLUGIN::Load()
236  wxASSERT( unsigned( aLayers[i] ) <= unsigned( VIEW::VIEW_MAX_LAYERS ) );
237 
238  m_layers.push_back( aLayers[i] );
239  }
240  }
241 
246  int requiredUpdate() const
247  {
248  return m_requiredUpdate;
249  }
250 
256  {
257  m_requiredUpdate = NONE;
258  }
259 
264  bool isRenderable() const
265  {
266  return m_flags == VISIBLE;
267  }
268 };
269 
270 
272 {
273  auto data = aItem->viewPrivData();
274 
275  if( !data )
276  return;
277 
278  if( data->m_view )
279  data->m_view->VIEW::Remove( aItem );
280 
281  delete data;
282 }
283 
284 
285 VIEW::VIEW( bool aIsDynamic ) :
286  m_enableOrderModifier( true ),
287  m_scale( 4.0 ),
288  m_minScale( 0.2 ), m_maxScale( 25000.0 ),
289  m_mirrorX( false ), m_mirrorY( false ),
290  m_painter( NULL ),
291  m_gal( NULL ),
292  m_dynamic( aIsDynamic ),
293  m_useDrawPriority( false ),
294  m_nextDrawPriority( 0 ),
295  m_reverseDrawOrder( false )
296 {
298  m_allItems.reset( new std::vector<VIEW_ITEM*> );
299  m_allItems->reserve( 32768 );
300 
301  // Redraw everything at the beginning
302  MarkDirty();
303 
304  // View uses layers to display EDA_ITEMs (item may be displayed on several layers, for example
305  // pad may be shown on pad, pad hole and solder paste layers). There are usual copper layers
306  // (eg. F.Cu, B.Cu, internal and so on) and layers for displaying objects such as texts,
307  // silkscreen, pads, vias, etc.
308  for( int i = 0; i < VIEW_MAX_LAYERS; i++ )
309  AddLayer( i );
310 
311  sortLayers();
312 }
313 
314 
316 {
317 }
318 
319 
320 void VIEW::AddLayer( int aLayer, bool aDisplayOnly )
321 {
322  if( m_layers.find( aLayer ) == m_layers.end() )
323  {
324  m_layers[aLayer] = VIEW_LAYER();
325  m_layers[aLayer].items.reset( new VIEW_RTREE() );
326  m_layers[aLayer].id = aLayer;
327  m_layers[aLayer].renderingOrder = aLayer;
328  m_layers[aLayer].visible = true;
329  m_layers[aLayer].displayOnly = aDisplayOnly;
330  m_layers[aLayer].target = TARGET_CACHED;
331  }
332 }
333 
334 
335 void VIEW::Add( VIEW_ITEM* aItem, int aDrawPriority )
336 {
337  int layers[VIEW_MAX_LAYERS], layers_count;
338 
339  if( aDrawPriority < 0 )
340  aDrawPriority = m_nextDrawPriority++;
341 
342  if( !aItem->m_viewPrivData )
343  aItem->m_viewPrivData = new VIEW_ITEM_DATA;
344 
345  aItem->m_viewPrivData->m_view = this;
346  aItem->m_viewPrivData->m_drawPriority = aDrawPriority;
347 
348  aItem->ViewGetLayers( layers, layers_count );
349  aItem->viewPrivData()->saveLayers( layers, layers_count );
350 
351  m_allItems->push_back( aItem );
352 
353  for( int i = 0; i < layers_count; ++i )
354  {
355  VIEW_LAYER& l = m_layers[layers[i]];
356  l.items->Insert( aItem );
357  MarkTargetDirty( l.target );
358  }
359 
360  SetVisible( aItem, true );
361  Update( aItem, KIGFX::INITIAL_ADD );
362 }
363 
364 
365 void VIEW::Remove( VIEW_ITEM* aItem )
366 {
367  if( !aItem )
368  return;
369 
370  auto viewData = aItem->viewPrivData();
371 
372  if( !viewData )
373  return;
374 
375  wxCHECK( viewData->m_view == this, /*void*/ );
376  auto item = std::find( m_allItems->begin(), m_allItems->end(), aItem );
377 
378  if( item != m_allItems->end() )
379  {
380  m_allItems->erase( item );
381  viewData->clearUpdateFlags();
382  }
383 
384  int layers[VIEW::VIEW_MAX_LAYERS], layers_count;
385  viewData->getLayers( layers, layers_count );
386 
387  for( int i = 0; i < layers_count; ++i )
388  {
389  VIEW_LAYER& l = m_layers[layers[i]];
390  l.items->Remove( aItem );
391  MarkTargetDirty( l.target );
392 
393  // Clear the GAL cache
394  int prevGroup = viewData->getGroup( layers[i] );
395 
396  if( prevGroup >= 0 )
397  m_gal->DeleteGroup( prevGroup );
398  }
399 
400  viewData->deleteGroups();
401  viewData->m_view = nullptr;
402 }
403 
404 
405 void VIEW::SetRequired( int aLayerId, int aRequiredId, bool aRequired )
406 {
407  wxCHECK( (unsigned) aLayerId < m_layers.size(), /*void*/ );
408  wxCHECK( (unsigned) aRequiredId < m_layers.size(), /*void*/ );
409 
410  if( aRequired )
411  m_layers[aLayerId].requiredLayers.insert( aRequiredId );
412  else
413  m_layers[aLayerId].requiredLayers.erase( aRequired );
414 }
415 
416 
417 // stupid C++... python lambda would do this in one line
418 template <class Container>
420 {
421  typedef typename Container::value_type item_type;
422 
423  queryVisitor( Container& aCont, int aLayer ) :
424  m_cont( aCont ), m_layer( aLayer )
425  {
426  }
427 
428  bool operator()( VIEW_ITEM* aItem )
429  {
430  if( aItem->viewPrivData()->getFlags() & VISIBLE )
431  m_cont.push_back( VIEW::LAYER_ITEM_PAIR( aItem, m_layer ) );
432 
433  return true;
434  }
435 
436  Container& m_cont;
437  int m_layer;
438 };
439 
440 
441 int VIEW::Query( const BOX2I& aRect, std::vector<LAYER_ITEM_PAIR>& aResult ) const
442 {
443  if( m_orderedLayers.empty() )
444  return 0;
445 
446  std::vector<VIEW_LAYER*>::const_reverse_iterator i;
447 
448  // execute queries in reverse direction, so that items that are on the top of
449  // the rendering stack are returned first.
450  for( i = m_orderedLayers.rbegin(); i != m_orderedLayers.rend(); ++i )
451  {
452  // ignore layers that do not contain actual items (i.e. the selection box, menus, floats)
453  if( ( *i )->displayOnly || !( *i )->visible )
454  continue;
455 
456  queryVisitor<std::vector<LAYER_ITEM_PAIR> > visitor( aResult, ( *i )->id );
457  ( *i )->items->Query( aRect, visitor );
458  }
459 
460  return aResult.size();
461 }
462 
463 
464 VECTOR2D VIEW::ToWorld( const VECTOR2D& aCoord, bool aAbsolute ) const
465 {
466  const MATRIX3x3D& matrix = m_gal->GetScreenWorldMatrix();
467 
468  if( aAbsolute )
469  return VECTOR2D( matrix * aCoord );
470  else
471  return VECTOR2D( matrix.GetScale().x * aCoord.x, matrix.GetScale().y * aCoord.y );
472 }
473 
474 
475 double VIEW::ToWorld( double aSize ) const
476 {
477  const MATRIX3x3D& matrix = m_gal->GetScreenWorldMatrix();
478 
479  return fabs( matrix.GetScale().x * aSize );
480 }
481 
482 
483 VECTOR2D VIEW::ToScreen( const VECTOR2D& aCoord, bool aAbsolute ) const
484 {
485  const MATRIX3x3D& matrix = m_gal->GetWorldScreenMatrix();
486 
487  if( aAbsolute )
488  return VECTOR2D( matrix * aCoord );
489  else
490  return VECTOR2D( matrix.GetScale().x * aCoord.x, matrix.GetScale().y * aCoord.y );
491 }
492 
493 
494 double VIEW::ToScreen( double aSize ) const
495 {
496  const MATRIX3x3D& matrix = m_gal->GetWorldScreenMatrix();
497 
498  return matrix.GetScale().x * aSize;
499 }
500 
501 
502 void VIEW::CopySettings( const VIEW* aOtherView )
503 {
504  wxASSERT_MSG( false, wxT( "This is not implemented" ) );
505 }
506 
507 
508 void VIEW::SetGAL( GAL* aGal )
509 {
510  bool recacheGroups = ( m_gal != nullptr ); // recache groups only if GAL is reassigned
511  m_gal = aGal;
512 
513  // clear group numbers, so everything is going to be recached
514  if( recacheGroups )
515  clearGroupCache();
516 
517  // every target has to be refreshed
518  MarkDirty();
519 
520  // force the new GAL to display the current viewport.
521  SetCenter( m_center );
522  SetScale( m_scale );
524 }
525 
526 
528 {
529  BOX2D rect;
530  VECTOR2D screenSize = m_gal->GetScreenPixelSize();
531 
532  rect.SetOrigin( ToWorld( VECTOR2D( 0, 0 ) ) );
533  rect.SetEnd( ToWorld( screenSize ) );
534 
535  return rect.Normalize();
536 }
537 
538 
539 void VIEW::SetViewport( const BOX2D& aViewport )
540 {
541  VECTOR2D ssize = ToWorld( m_gal->GetScreenPixelSize(), false );
542 
543  wxCHECK( ssize.x > 0 && ssize.y > 0, /*void*/ );
544 
545  VECTOR2D centre = aViewport.Centre();
546  VECTOR2D vsize = aViewport.GetSize();
547  double zoom = 1.0 / std::max( fabs( vsize.x / ssize.x ), fabs( vsize.y / ssize.y ) );
548 
549  SetCenter( centre );
550  SetScale( GetScale() * zoom );
551 }
552 
553 
554 void VIEW::SetMirror( bool aMirrorX, bool aMirrorY )
555 {
556  wxASSERT_MSG( !aMirrorY, _( "Mirroring for Y axis is not supported yet" ) );
557 
558  m_mirrorX = aMirrorX;
559  m_mirrorY = aMirrorY;
560  m_gal->SetFlip( aMirrorX, aMirrorY );
561 
562  // Redraw everything
563  MarkDirty();
564 }
565 
566 
567 void VIEW::SetScale( double aScale, const VECTOR2D& aAnchor )
568 {
569  VECTOR2D a = ToScreen( aAnchor );
570 
571  if( aScale < m_minScale )
573  else if( aScale > m_maxScale )
575  else
576  m_scale = aScale;
577 
580 
581  VECTOR2D delta = ToWorld( a ) - aAnchor;
582 
583  SetCenter( m_center - delta );
584 
585  // Redraw everything after the viewport has changed
586  MarkDirty();
587 }
588 
589 
590 void VIEW::SetCenter( const VECTOR2D& aCenter )
591 {
592  m_center = aCenter;
593 
594  if( !m_boundary.Contains( aCenter ) )
595  {
596  if( m_center.x < m_boundary.GetLeft() )
598  else if( aCenter.x > m_boundary.GetRight() )
600 
601  if( m_center.y < m_boundary.GetTop() )
603  else if( m_center.y > m_boundary.GetBottom() )
605  }
606 
609 
610  // Redraw everything after the viewport has changed
611  MarkDirty();
612 }
613 
614 
615 void VIEW::SetCenter( VECTOR2D aCenter, const BOX2D& occultingScreenRect )
616 {
617  BOX2D screenRect( VECTOR2D( 0, 0 ), m_gal->GetScreenPixelSize() );
618 
619  if( !screenRect.Intersects( occultingScreenRect ) )
620  {
621  SetCenter( aCenter );
622  return;
623  }
624 
625  BOX2D occultedRect = screenRect.Intersect( occultingScreenRect );
626  VECTOR2D offset( occultedRect.GetWidth() / 2, occultedRect.GetHeight() / 2 );
627 
628  double topExposed = occultedRect.GetTop() - screenRect.GetTop();
629  double bottomExposed = screenRect.GetBottom() - occultedRect.GetBottom();
630  double leftExposed = occultedRect.GetLeft() - screenRect.GetLeft();
631  double rightExposed = screenRect.GetRight() - occultedRect.GetRight();
632 
633  if( std::max( topExposed, bottomExposed ) > std::max( leftExposed, rightExposed ) )
634  {
635  if( topExposed > bottomExposed )
636  aCenter.y += ToWorld( occultedRect.GetHeight() / 2 );
637  else
638  aCenter.y -= ToWorld( occultedRect.GetHeight() / 2 );
639  }
640  else
641  {
642  if( leftExposed > rightExposed )
643  aCenter.x += ToWorld( occultedRect.GetWidth() / 2 );
644  else
645  aCenter.x -= ToWorld( occultedRect.GetWidth() / 2 );
646  }
647 
648  SetCenter( aCenter );
649 }
650 
651 
652 void VIEW::SetLayerOrder( int aLayer, int aRenderingOrder )
653 {
654  m_layers[aLayer].renderingOrder = aRenderingOrder;
655 
656  sortLayers();
657 }
658 
659 
660 int VIEW::GetLayerOrder( int aLayer ) const
661 {
662  return m_layers.at( aLayer ).renderingOrder;
663 }
664 
665 
666 void VIEW::SortLayers( int aLayers[], int& aCount ) const
667 {
668  int maxLay, maxOrd, maxIdx;
669 
670  for( int i = 0; i < aCount; ++i )
671  {
672  maxLay = aLayers[i];
673  maxOrd = GetLayerOrder( maxLay );
674  maxIdx = i;
675 
676  // Look for the max element in the range (j..aCount)
677  for( int j = i; j < aCount; ++j )
678  {
679  if( maxOrd < GetLayerOrder( aLayers[j] ) )
680  {
681  maxLay = aLayers[j];
682  maxOrd = GetLayerOrder( maxLay );
683  maxIdx = j;
684  }
685  }
686 
687  // Swap elements
688  aLayers[maxIdx] = aLayers[i];
689  aLayers[i] = maxLay;
690  }
691 }
692 
693 
694 void VIEW::ReorderLayerData( std::unordered_map<int, int> aReorderMap )
695 {
696  LAYER_MAP new_map;
697 
698  for( const auto& it : m_layers )
699  {
700  int orig_idx = it.first;
701  VIEW_LAYER layer = it.second;
702  int new_idx;
703 
704  try
705  {
706  new_idx = aReorderMap.at( orig_idx );
707  }
708  catch( const std::out_of_range& )
709  {
710  new_idx = orig_idx;
711  }
712 
713  layer.id = new_idx;
714  new_map[new_idx] = layer;
715  }
716 
717  m_layers = new_map;
718 
719  for( VIEW_ITEM* item : *m_allItems )
720  {
721  auto viewData = item->viewPrivData();
722 
723  if( !viewData )
724  continue;
725 
726  int layers[VIEW::VIEW_MAX_LAYERS], layers_count;
727 
728  item->ViewGetLayers( layers, layers_count );
729  viewData->saveLayers( layers, layers_count );
730 
731  viewData->reorderGroups( aReorderMap );
732 
733  viewData->m_requiredUpdate |= COLOR;
734  }
735 
736  UpdateItems();
737 }
738 
739 
741 {
742  updateItemsColor( int aLayer, PAINTER* aPainter, GAL* aGal ) :
743  layer( aLayer ), painter( aPainter ), gal( aGal )
744  {
745  }
746 
747  bool operator()( VIEW_ITEM* aItem )
748  {
749  // Obtain the color that should be used for coloring the item
750  const COLOR4D color = painter->GetSettings()->GetColor( aItem, layer );
751  int group = aItem->viewPrivData()->getGroup( layer );
752 
753  if( group >= 0 )
754  gal->ChangeGroupColor( group, color );
755 
756  return true;
757  }
758 
759  int layer;
762 };
763 
764 
765 void VIEW::UpdateLayerColor( int aLayer )
766 {
767  // There is no point in updating non-cached layers
768  if( !IsCached( aLayer ) )
769  return;
770 
771  BOX2I r;
772 
773  r.SetMaximum();
774 
775  if( m_gal->IsVisible() )
776  {
777  GAL_UPDATE_CONTEXT ctx( m_gal );
778 
779  updateItemsColor visitor( aLayer, m_painter, m_gal );
780  m_layers[aLayer].items->Query( r, visitor );
781  MarkTargetDirty( m_layers[aLayer].target );
782  }
783 }
784 
785 
787 {
788  if( m_gal->IsVisible() )
789  {
790  GAL_UPDATE_CONTEXT ctx( m_gal );
791 
792  for( VIEW_ITEM* item : *m_allItems )
793  {
794  auto viewData = item->viewPrivData();
795 
796  if( !viewData )
797  continue;
798 
799  int layers[VIEW::VIEW_MAX_LAYERS], layers_count;
800  viewData->getLayers( layers, layers_count );
801 
802  for( int i = 0; i < layers_count; ++i )
803  {
804  const COLOR4D color = m_painter->GetSettings()->GetColor( item, layers[i] );
805  int group = viewData->getGroup( layers[i] );
806 
807  if( group >= 0 )
808  m_gal->ChangeGroupColor( group, color );
809  }
810  }
811  }
812 
813  MarkDirty();
814 }
815 
816 
818 {
819  changeItemsDepth( int aLayer, int aDepth, GAL* aGal ) :
820  layer( aLayer ), depth( aDepth ), gal( aGal )
821  {
822  }
823 
824  bool operator()( VIEW_ITEM* aItem )
825  {
826  int group = aItem->viewPrivData()->getGroup( layer );
827 
828  if( group >= 0 )
829  gal->ChangeGroupDepth( group, depth );
830 
831  return true;
832  }
833 
834  int layer, depth;
836 };
837 
838 
839 int VIEW::GetTopLayer() const
840 {
841  if( m_topLayers.size() == 0 )
842  return 0;
843 
844  return *m_topLayers.begin();
845 }
846 
847 
848 void VIEW::SetTopLayer( int aLayer, bool aEnabled )
849 {
850  if( aEnabled )
851  {
852  if( m_topLayers.count( aLayer ) == 1 )
853  return;
854 
855  m_topLayers.insert( aLayer );
856 
857  // Move the layer closer to front
859  m_layers[aLayer].renderingOrder += TOP_LAYER_MODIFIER;
860  }
861  else
862  {
863  if( m_topLayers.count( aLayer ) == 0 )
864  return;
865 
866  m_topLayers.erase( aLayer );
867 
868  // Restore the previous rendering order
870  m_layers[aLayer].renderingOrder -= TOP_LAYER_MODIFIER;
871  }
872 }
873 
874 
875 void VIEW::EnableTopLayer( bool aEnable )
876 {
877  if( aEnable == m_enableOrderModifier )
878  return;
879 
880  m_enableOrderModifier = aEnable;
881 
882  std::set<unsigned int>::iterator it;
883 
884  if( aEnable )
885  {
886  for( it = m_topLayers.begin(); it != m_topLayers.end(); ++it )
887  m_layers[*it].renderingOrder += TOP_LAYER_MODIFIER;
888  }
889  else
890  {
891  for( it = m_topLayers.begin(); it != m_topLayers.end(); ++it )
892  m_layers[*it].renderingOrder -= TOP_LAYER_MODIFIER;
893  }
894 
897 }
898 
899 
901 {
902  std::set<unsigned int>::iterator it;
903 
905  {
906  // Restore the previous rendering order for layers that were marked as top
907  for( it = m_topLayers.begin(); it != m_topLayers.end(); ++it )
908  m_layers[*it].renderingOrder -= TOP_LAYER_MODIFIER;
909  }
910 
911  m_topLayers.clear();
912 }
913 
914 
916 {
917  sortLayers();
918 
919  if( m_gal->IsVisible() )
920  {
921  GAL_UPDATE_CONTEXT ctx( m_gal );
922 
923  for( VIEW_ITEM* item : *m_allItems )
924  {
925  auto viewData = item->viewPrivData();
926 
927  if( !viewData )
928  continue;
929 
930  int layers[VIEW::VIEW_MAX_LAYERS], layers_count;
931  viewData->getLayers( layers, layers_count );
932 
933  for( int i = 0; i < layers_count; ++i )
934  {
935  int group = viewData->getGroup( layers[i] );
936 
937  if( group >= 0 )
938  m_gal->ChangeGroupDepth( group, m_layers[layers[i]].renderingOrder );
939  }
940  }
941  }
942 
943  MarkDirty();
944 }
945 
946 
948 {
949  drawItem( VIEW* aView, int aLayer, bool aUseDrawPriority, bool aReverseDrawOrder ) :
950  view( aView ), layer( aLayer ),
951  useDrawPriority( aUseDrawPriority ),
952  reverseDrawOrder( aReverseDrawOrder )
953  {
954  }
955 
956  bool operator()( VIEW_ITEM* aItem )
957  {
958  wxCHECK( aItem->viewPrivData(), false );
959 
960  // Conditions that have to be fulfilled for an item to be drawn
961  bool drawCondition = aItem->viewPrivData()->isRenderable() &&
962  aItem->ViewGetLOD( layer, view ) < view->m_scale;
963  if( !drawCondition )
964  return true;
965 
966  if( useDrawPriority )
967  drawItems.push_back( aItem );
968  else
969  view->draw( aItem, layer );
970 
971  return true;
972  }
973 
975  {
976  if( reverseDrawOrder )
977  std::sort( drawItems.begin(), drawItems.end(),
978  []( VIEW_ITEM* a, VIEW_ITEM* b ) -> bool {
979  return b->viewPrivData()->m_drawPriority < a->viewPrivData()->m_drawPriority;
980  });
981  else
982  std::sort( drawItems.begin(), drawItems.end(),
983  []( VIEW_ITEM* a, VIEW_ITEM* b ) -> bool {
984  return a->viewPrivData()->m_drawPriority < b->viewPrivData()->m_drawPriority;
985  });
986 
987  for( auto item : drawItems )
988  view->draw( item, layer );
989  }
990 
992  int layer, layers[VIEW_MAX_LAYERS];
993  bool useDrawPriority, reverseDrawOrder;
994  std::vector<VIEW_ITEM*> drawItems;
995 };
996 
997 
998 void VIEW::redrawRect( const BOX2I& aRect )
999 {
1000  for( VIEW_LAYER* l : m_orderedLayers )
1001  {
1002  if( l->visible && IsTargetDirty( l->target ) && areRequiredLayersEnabled( l->id ) )
1003  {
1004  drawItem drawFunc( this, l->id, m_useDrawPriority, m_reverseDrawOrder );
1005 
1006  m_gal->SetTarget( l->target );
1007  m_gal->SetLayerDepth( l->renderingOrder );
1008  l->items->Query( aRect, drawFunc );
1009 
1010  if( m_useDrawPriority )
1011  drawFunc.deferredDraw();
1012  }
1013  }
1014 }
1015 
1016 
1017 void VIEW::draw( VIEW_ITEM* aItem, int aLayer, bool aImmediate )
1018 {
1019  auto viewData = aItem->viewPrivData();
1020 
1021  if( !viewData )
1022  return;
1023 
1024  if( IsCached( aLayer ) && !aImmediate )
1025  {
1026  // Draw using cached information or create one
1027  int group = viewData->getGroup( aLayer );
1028 
1029  if( group >= 0 )
1030  m_gal->DrawGroup( group );
1031  else
1032  Update( aItem );
1033  }
1034  else
1035  {
1036  // Immediate mode
1037  if( !m_painter->Draw( aItem, aLayer ) )
1038  aItem->ViewDraw( aLayer, this ); // Alternative drawing method
1039  }
1040 }
1041 
1042 
1043 void VIEW::draw( VIEW_ITEM* aItem, bool aImmediate )
1044 {
1045  int layers[VIEW_MAX_LAYERS], layers_count;
1046 
1047  aItem->ViewGetLayers( layers, layers_count );
1048 
1049  // Sorting is needed for drawing order dependent GALs (like Cairo)
1050  SortLayers( layers, layers_count );
1051 
1052  for( int i = 0; i < layers_count; ++i )
1053  {
1054  m_gal->SetLayerDepth( m_layers.at( layers[i] ).renderingOrder );
1055  draw( aItem, layers[i], aImmediate );
1056  }
1057 }
1058 
1059 
1060 void VIEW::draw( VIEW_GROUP* aGroup, bool aImmediate )
1061 {
1062  for( unsigned int i = 0; i < aGroup->GetSize(); i++)
1063  draw( aGroup->GetItem(i), aImmediate );
1064 }
1065 
1066 
1068 {
1069  recacheItem( VIEW* aView, GAL* aGal, int aLayer ) :
1070  view( aView ), gal( aGal ), layer( aLayer )
1071  {
1072  }
1073 
1074  bool operator()( VIEW_ITEM* aItem )
1075  {
1076  auto viewData = aItem->viewPrivData();
1077 
1078  if( !viewData )
1079  return false;
1080 
1081  // Remove previously cached group
1082  int group = viewData->getGroup( layer );
1083 
1084  if( group >= 0 )
1085  gal->DeleteGroup( group );
1086 
1087  viewData->setGroup( layer, -1 );
1088  view->Update( aItem );
1089 
1090  return true;
1091  }
1092 
1095  int layer;
1096 };
1097 
1098 
1100 {
1101  BOX2I r;
1102  r.SetMaximum();
1103  m_allItems->clear();
1104 
1105  for( LAYER_MAP_ITER i = m_layers.begin(); i != m_layers.end(); ++i )
1106  i->second.items->RemoveAll();
1107 
1108  m_nextDrawPriority = 0;
1109 
1110  m_gal->ClearCache();
1111 }
1112 
1113 
1115 {
1117  {
1118  // TARGET_CACHED and TARGET_NONCACHED have to be redrawn together, as they contain
1119  // layers that rely on each other (eg. netnames are noncached, but tracks - are cached)
1122 
1123  MarkDirty();
1124  }
1125 
1126  if( IsTargetDirty( TARGET_OVERLAY ) )
1127  {
1129  }
1130 }
1131 
1132 
1134 {
1135 #ifdef __WXDEBUG__
1136  PROF_COUNTER totalRealTime;
1137 #endif /* __WXDEBUG__ */
1138 
1139  VECTOR2D screenSize = m_gal->GetScreenPixelSize();
1140  BOX2I rect( ToWorld( VECTOR2D( 0, 0 ) ),
1141  ToWorld( screenSize ) - ToWorld( VECTOR2D( 0, 0 ) ) );
1142  rect.Normalize();
1143 
1144  redrawRect( rect );
1145 
1146  // All targets were redrawn, so nothing is dirty
1150 
1151 #ifdef __WXDEBUG__
1152  totalRealTime.Stop();
1153  wxLogTrace( "GAL_PROFILE", "VIEW::Redraw(): %.1f ms", totalRealTime.msecs() );
1154 #endif /* __WXDEBUG__ */
1155 }
1156 
1157 
1159 {
1160  return m_gal->GetScreenPixelSize();
1161 }
1162 
1163 
1165 {
1166  clearLayerCache( VIEW* aView ) :
1167  view( aView )
1168  {
1169  }
1170 
1171  bool operator()( VIEW_ITEM* aItem )
1172  {
1173  aItem->viewPrivData()->deleteGroups();
1174 
1175  return true;
1176  }
1177 
1179 };
1180 
1181 
1183 {
1184  BOX2I r;
1185 
1186  r.SetMaximum();
1187  clearLayerCache visitor( this );
1188 
1189  for( LAYER_MAP_ITER i = m_layers.begin(); i != m_layers.end(); ++i )
1190  {
1191  VIEW_LAYER* l = &( ( *i ).second );
1192  l->items->Query( r, visitor );
1193  }
1194 }
1195 
1196 
1197 void VIEW::invalidateItem( VIEW_ITEM* aItem, int aUpdateFlags )
1198 {
1199  if( aUpdateFlags & INITIAL_ADD )
1200  {
1201  // Don't update layers or bbox, since it was done in VIEW::Add()
1202  // Now that we have initialized, set flags to ALL for the code below
1203  aUpdateFlags = ALL;
1204  }
1205  else
1206  {
1207  // updateLayers updates geometry too, so we do not have to update both of them at the same time
1208  if( aUpdateFlags & LAYERS )
1209  {
1210  updateLayers( aItem );
1211  }
1212  else if( aUpdateFlags & GEOMETRY )
1213  {
1214  updateBbox( aItem );
1215  }
1216  }
1217 
1218  int layers[VIEW_MAX_LAYERS], layers_count;
1219  aItem->ViewGetLayers( layers, layers_count );
1220 
1221  // Iterate through layers used by the item and recache it immediately
1222  for( int i = 0; i < layers_count; ++i )
1223  {
1224  int layerId = layers[i];
1225 
1226  if( IsCached( layerId ) )
1227  {
1228  if( aUpdateFlags & ( GEOMETRY | LAYERS | REPAINT ) )
1229  updateItemGeometry( aItem, layerId );
1230  else if( aUpdateFlags & COLOR )
1231  updateItemColor( aItem, layerId );
1232  }
1233 
1234  // Mark those layers as dirty, so the VIEW will be refreshed
1235  MarkTargetDirty( m_layers[layerId].target );
1236  }
1237 
1238  aItem->viewPrivData()->clearUpdateFlags();
1239 }
1240 
1241 
1243 {
1244  int n = 0;
1245 
1246  m_orderedLayers.resize( m_layers.size() );
1247 
1248  for( LAYER_MAP_ITER i = m_layers.begin(); i != m_layers.end(); ++i )
1249  m_orderedLayers[n++] = &i->second;
1250 
1251  sort( m_orderedLayers.begin(), m_orderedLayers.end(), compareRenderingOrder );
1252 
1253  MarkDirty();
1254 }
1255 
1256 
1257 void VIEW::updateItemColor( VIEW_ITEM* aItem, int aLayer )
1258 {
1259  auto viewData = aItem->viewPrivData();
1260  wxCHECK( (unsigned) aLayer < m_layers.size(), /*void*/ );
1261  wxCHECK( IsCached( aLayer ), /*void*/ );
1262 
1263  if( !viewData )
1264  return;
1265 
1266  // Obtain the color that should be used for coloring the item on the specific layerId
1267  const COLOR4D color = m_painter->GetSettings()->GetColor( aItem, aLayer );
1268  int group = viewData->getGroup( aLayer );
1269 
1270  // Change the color, only if it has group assigned
1271  if( group >= 0 )
1272  m_gal->ChangeGroupColor( group, color );
1273 }
1274 
1275 
1276 void VIEW::updateItemGeometry( VIEW_ITEM* aItem, int aLayer )
1277 {
1278  auto viewData = aItem->viewPrivData();
1279  wxCHECK( (unsigned) aLayer < m_layers.size(), /*void*/ );
1280  wxCHECK( IsCached( aLayer ), /*void*/ );
1281 
1282  if( !viewData )
1283  return;
1284 
1285  VIEW_LAYER& l = m_layers.at( aLayer );
1286 
1287  m_gal->SetTarget( l.target );
1289 
1290  // Redraw the item from scratch
1291  int group = viewData->getGroup( aLayer );
1292 
1293  if( group >= 0 )
1294  m_gal->DeleteGroup( group );
1295 
1296  group = m_gal->BeginGroup();
1297  viewData->setGroup( aLayer, group );
1298 
1299  if( !m_painter->Draw( static_cast<EDA_ITEM*>( aItem ), aLayer ) )
1300  aItem->ViewDraw( aLayer, this ); // Alternative drawing method
1301 
1302  m_gal->EndGroup();
1303 }
1304 
1305 
1307 {
1308  int layers[VIEW_MAX_LAYERS], layers_count;
1309 
1310  aItem->ViewGetLayers( layers, layers_count );
1311 
1312  for( int i = 0; i < layers_count; ++i )
1313  {
1314  VIEW_LAYER& l = m_layers[layers[i]];
1315  l.items->Remove( aItem );
1316  l.items->Insert( aItem );
1317  MarkTargetDirty( l.target );
1318  }
1319 }
1320 
1321 
1323 {
1324  auto viewData = aItem->viewPrivData();
1325  int layers[VIEW_MAX_LAYERS], layers_count;
1326 
1327  if( !viewData )
1328  return;
1329 
1330  // Remove the item from previous layer set
1331  viewData->getLayers( layers, layers_count );
1332 
1333  for( int i = 0; i < layers_count; ++i )
1334  {
1335  VIEW_LAYER& l = m_layers[layers[i]];
1336  l.items->Remove( aItem );
1337  MarkTargetDirty( l.target );
1338 
1339  if( IsCached( l.id ) )
1340  {
1341  // Redraw the item from scratch
1342  int prevGroup = viewData->getGroup( layers[i] );
1343 
1344  if( prevGroup >= 0 )
1345  {
1346  m_gal->DeleteGroup( prevGroup );
1347  viewData->setGroup( l.id, -1 );
1348  }
1349  }
1350  }
1351 
1352  // Add the item to new layer set
1353  aItem->ViewGetLayers( layers, layers_count );
1354  viewData->saveLayers( layers, layers_count );
1355 
1356  for( int i = 0; i < layers_count; i++ )
1357  {
1358  VIEW_LAYER& l = m_layers[layers[i]];
1359  l.items->Insert( aItem );
1360  MarkTargetDirty( l.target );
1361  }
1362 }
1363 
1364 
1365 bool VIEW::areRequiredLayersEnabled( int aLayerId ) const
1366 {
1367  wxCHECK( (unsigned) aLayerId < m_layers.size(), false );
1368 
1369  std::set<int>::const_iterator it, it_end;
1370 
1371  for( it = m_layers.at( aLayerId ).requiredLayers.begin(),
1372  it_end = m_layers.at( aLayerId ).requiredLayers.end(); it != it_end; ++it )
1373  {
1374  // That is enough if just one layer is not enabled
1375  if( !m_layers.at( *it ).visible || !areRequiredLayersEnabled( *it ) )
1376  return false;
1377  }
1378 
1379  return true;
1380 }
1381 
1382 
1384 {
1385  BOX2I r;
1386 
1387  r.SetMaximum();
1388 
1389  for( LAYER_MAP_ITER i = m_layers.begin(); i != m_layers.end(); ++i )
1390  {
1391  VIEW_LAYER* l = &( ( *i ).second );
1392 
1393  if( IsCached( l->id ) )
1394  {
1395  recacheItem visitor( this, m_gal, l->id );
1396  l->items->Query( r, visitor );
1397  }
1398  }
1399 }
1400 
1401 
1403 {
1404  if( m_gal->IsVisible() )
1405  {
1406  GAL_UPDATE_CONTEXT ctx( m_gal );
1407 
1408  for( VIEW_ITEM* item : *m_allItems )
1409  {
1410  auto viewData = item->viewPrivData();
1411 
1412  if( !viewData )
1413  continue;
1414 
1415  if( viewData->m_requiredUpdate != NONE )
1416  {
1417  invalidateItem( item, viewData->m_requiredUpdate );
1418  viewData->m_requiredUpdate = NONE;
1419  }
1420  }
1421  }
1422 }
1423 
1424 
1425 void VIEW::UpdateAllItems( int aUpdateFlags )
1426 {
1427  for( VIEW_ITEM* item : *m_allItems )
1428  {
1429  auto viewData = item->viewPrivData();
1430 
1431  if( !viewData )
1432  continue;
1433 
1434  viewData->m_requiredUpdate |= aUpdateFlags;
1435  }
1436 }
1437 
1438 
1439 void VIEW::UpdateAllItemsConditionally( int aUpdateFlags,
1440  std::function<bool( VIEW_ITEM* )> aCondition )
1441 {
1442  for( VIEW_ITEM* item : *m_allItems )
1443  {
1444  if( aCondition( item ) )
1445  {
1446  auto viewData = item->viewPrivData();
1447 
1448  if( !viewData )
1449  continue;
1450 
1451  viewData->m_requiredUpdate |= aUpdateFlags;
1452  }
1453  }
1454 }
1455 
1456 
1457 std::unique_ptr<VIEW> VIEW::DataReference() const
1458 {
1459  auto ret = std::make_unique<VIEW>();
1460  ret->m_allItems = m_allItems;
1461  ret->m_layers = m_layers;
1462  ret->sortLayers();
1463  return ret;
1464 }
1465 
1466 
1467 void VIEW::SetVisible( VIEW_ITEM* aItem, bool aIsVisible )
1468 {
1469  auto viewData = aItem->viewPrivData();
1470 
1471  if( !viewData )
1472  return;
1473 
1474  bool cur_visible = viewData->m_flags & VISIBLE;
1475 
1476  if( cur_visible != aIsVisible )
1477  {
1478  if( aIsVisible )
1479  viewData->m_flags |= VISIBLE;
1480  else
1481  viewData->m_flags &= ~VISIBLE;
1482 
1483  Update( aItem, APPEARANCE | COLOR );
1484  }
1485 }
1486 
1487 
1488 void VIEW::Hide( VIEW_ITEM* aItem, bool aHide )
1489 {
1490  auto viewData = aItem->viewPrivData();
1491 
1492  if( !viewData )
1493  return;
1494 
1495  if( !( viewData->m_flags & VISIBLE ) )
1496  return;
1497 
1498  if( aHide )
1499  viewData->m_flags |= HIDDEN;
1500  else
1501  viewData->m_flags &= ~HIDDEN;
1502 
1503  Update( aItem, APPEARANCE );
1504 }
1505 
1506 
1507 bool VIEW::IsVisible( const VIEW_ITEM* aItem ) const
1508 {
1509  const auto viewData = aItem->viewPrivData();
1510 
1511  return viewData->m_flags & VISIBLE;
1512 }
1513 
1514 
1515 void VIEW::Update( VIEW_ITEM* aItem )
1516 {
1517  Update( aItem, ALL );
1518 }
1519 
1520 
1521 void VIEW::Update( VIEW_ITEM* aItem, int aUpdateFlags )
1522 {
1523  auto viewData = aItem->viewPrivData();
1524 
1525  if( !viewData )
1526  return;
1527 
1528  assert( aUpdateFlags != NONE );
1529 
1530  viewData->m_requiredUpdate |= aUpdateFlags;
1531 
1532 }
1533 
1534 
1535 std::shared_ptr<VIEW_OVERLAY> VIEW::MakeOverlay()
1536 {
1537  std::shared_ptr<VIEW_OVERLAY> overlay( new VIEW_OVERLAY );
1538 
1539  Add( overlay.get() );
1540  return overlay;
1541 }
1542 
1543 
1545 
1546 }
void Stop()
save the time when this function was called, and set the counter stane to stop
Definition: profile.h:82
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hides the item in the view (e.g.
Definition: view.cpp:1488
virtual void DrawGroup(int aGroupNumber)
Draw the stored group.
Layers have changed.
Definition: view_item.h:59
Item is visible (in general)
Definition: view_item.h:70
virtual int GetTopLayer() const
Definition: view.cpp:839
void deleteGroups()
Function deleteGroups() Removes all of the stored group ids.
Definition: view.cpp:175
VIEW_ITEM_DATA * m_viewPrivData
Definition: view_item.h:156
void SetViewport(const BOX2D &aViewport)
Function SetViewport() Sets the visible area of the VIEW.
Definition: view.cpp:539
void updateLayers(VIEW_ITEM *aItem)
Updates set of layers that an item occupies.
Definition: view.cpp:1322
void AddLayer(int aLayer, bool aDisplayOnly=false)
Function AddLayer() Adds a new layer to the view.
Definition: view.cpp:320
void UpdateAllItemsConditionally(int aUpdateFlags, std::function< bool(VIEW_ITEM *)> aCondition)
Updates items in the view according to the given flags and condition.
Definition: view.cpp:1439
void SetLayerOrder(int aLayer, int aRenderingOrder)
Function SetLayerOrder() Sets rendering order of a particular layer.
Definition: view.cpp:652
void SetRequired(int aLayerId, int aRequiredId, bool aRequired=true)
Function SetRequired() Marks the aRequiredId layer as required for the aLayerId layer.
Definition: view.cpp:405
void updateItemColor(VIEW_ITEM *aItem, int aLayer)
Updates colors that are used for an item to be drawn.
Definition: view.cpp:1257
bool m_useDrawPriority
Flat list of all items Flag to respect draw priority when drawing items.
Definition: view.h:860
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:58
virtual void DeleteGroup(int aGroupNumber)
Delete the group from the memory.
virtual void SetTopLayer(int aLayer, bool aEnabled=true)
Function SetTopLayer() Sets given layer to be displayed on the top or sets back the default order of ...
Definition: view.cpp:848
virtual int Query(const BOX2I &aRect, std::vector< LAYER_ITEM_PAIR > &aResult) const
Function Query() Finds all visible items that touch or are within the rectangle aRect.
Definition: view.cpp:441
virtual VIEW_ITEM * GetItem(unsigned int aIdx) const
Definition: view_group.cpp:86
static const int TOP_LAYER_MODIFIER
Rendering order modifier for layers that are marked as top layers.
Definition: view.h:856
void sortLayers()
Definition: view.cpp:1242
queryVisitor(Container &aCont, int aLayer)
Definition: view.cpp:423
bool Contains(const Vec &aPoint) const
Function Contains.
Definition: box2.h:149
int color
Definition: DXF_plotter.cpp:62
int getGroup(int aLayer) const
Function getGroup() Returns number of the group id for the given layer, or -1 in case it was not cach...
Definition: view.cpp:109
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Function ToWorld() Converts a screen space point/vector to a point/vector in world space coordinates...
Definition: view.cpp:464
void RecacheAllItems()
Function RecacheAllItems() Rebuilds GAL display lists.
Definition: view.cpp:1383
void UpdateAllItems(int aUpdateFlags)
Updates all items in the view according to the given flags.
Definition: view.cpp:1425
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:365
const MATRIX3x3D & GetScreenWorldMatrix() const
Get the screen <-> world transformation matrix.
void SetFlip(bool xAxis, bool yAxis)
Sets flipping of the screen.
GAL * m_gal
Gives interface to PAINTER, that is used to draw items.
Definition: view.h:846
coord_type GetRight() const
Definition: box2.h:197
virtual bool IsVisible() const
Returns true if the GAL canvas is visible on the screen.
std::set< unsigned int > m_topLayers
Stores set of layers that are displayed on the top.
Definition: view.h:819
void clearUpdateFlags()
Function clearUpdateFlags() Marks an item as already updated, so it is not going to be redrawn...
Definition: view.cpp:255
void UpdateAllLayersOrder()
Function UpdateLayerOrder() Does everything that is needed to apply the rendering order of layers...
Definition: view.cpp:915
No updates are required.
Definition: view_item.h:55
int requiredUpdate() const
Function viewRequiredUpdate() Returns current update flag for an item.
Definition: view.cpp:246
void SetMirror(bool aMirrorX, bool aMirrorY)
Function SetMirror() Controls the mirroring of the VIEW.
Definition: view.cpp:554
Class VIEW_ITEM - is an abstract base class for deriving all objects that can be added to a VIEW...
Definition: view_item.h:84
Visibility flag has changed.
Definition: view_item.h:56
bool isRenderable() const
Function isRenderable() Returns if the item should be drawn or not.
Definition: view.cpp:264
Item needs to be redrawn.
Definition: view_item.h:61
const Vec & GetSize() const
Definition: box2.h:187
virtual void ComputeWorldScreenMatrix()
Compute the world <-> screen transformation matrix.
The class PROF_COUNTER is a small class to help profiling.
Definition: profile.h:45
void SetScale(double aScale)
Function SetScale() Sets the scaling factor.
Definition: view.h:250
virtual void SetLayerDepth(double aLayerDepth)
Set the depth of the layer (position on the z-axis)
std::shared_ptr< VIEW_OVERLAY > MakeOverlay()
Definition: view.cpp:1535
virtual void EnableTopLayer(bool aEnable)
Function EnableTopLayer() Enables or disables display of the top layer.
Definition: view.cpp:875
void setGroup(int aLayer, int aGroup)
Function setGroup() Sets a group id for the item and the layer combination.
Definition: view.cpp:145
const MATRIX3x3D & GetWorldScreenMatrix() const
Get the world <-> screen transformation matrix.
coord_type GetTop() const
Definition: box2.h:202
static const int delta[8][2]
Definition: solve.cpp:112
VECTOR2D m_center
Center point of the VIEW (the point at which we are looking at)
Definition: view.h:822
VIEW * m_view
Current dynamic view the item is assigned to.
Definition: view.cpp:89
static constexpr int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:699
int getFlags() const
Definition: view.cpp:64
virtual const COLOR4D & GetColor(const VIEW_ITEM *aItem, int aLayer) const =0
Function GetColor Returns the color that should be used to draw the specific VIEW_ITEM on the specifi...
virtual void EndGroup()
End the group.
Auxiliary rendering target (noncached)
Definition: definitions.h:42
std::shared_ptr< std::vector< VIEW_ITEM * > > m_allItems
Flat list of all items.
Definition: view.h:813
coord_type GetWidth() const
Definition: box2.h:195
double m_minScale
Scale lower limit.
Definition: view.h:831
bool operator()(VIEW_ITEM *aItem)
Definition: view.cpp:1074
virtual void ChangeGroupColor(int aGroupNumber, const COLOR4D &aNewColor)
Changes the color used to draw the group.
drawItem(VIEW *aView, int aLayer, bool aUseDrawPriority, bool aReverseDrawOrder)
Definition: view.cpp:949
std::vector< int > getAllGroups() const
Function getAllGroups() Returns all group ids for the item (collected from all layers the item occupi...
Definition: view.cpp:126
void SortLayers(int aLayers[], int &aCount) const
Function SortLayers() Changes the order of given layer ids, so after sorting the order corresponds to...
Definition: view.cpp:666
Class PAINTER contains all the knowledge about how to draw graphical object onto any particular outpu...
Definition: painter.h:308
Container::value_type item_type
Definition: view.cpp:421
bool operator()(VIEW_ITEM *aItem)
Definition: view.cpp:824
clearLayerCache(VIEW *aView)
Definition: view.cpp:1166
Item is being added to the view.
Definition: view_item.h:60
VIEW_ITEM class definition.
int m_drawPriority
Order to draw this item in a layer, lowest first.
Definition: view.cpp:92
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:590
BOX2D GetViewport() const
Function GetViewport() Returns the current viewport visible area rectangle.
Definition: view.cpp:527
bool storesGroups() const
Function storesGroups() Returns information if the item uses at least one group id (ie...
Definition: view.cpp:189
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
virtual void Redraw()
Function Redraw() Immediately redraws the whole view.
Definition: view.cpp:1133
void MarkTargetDirty(int aTarget)
Function MarkTargetDirty() Sets or clears target &#39;dirty&#39; flag.
Definition: view.h:596
void Clear()
Function Clear() Removes all items from the view.
Definition: view.cpp:1099
int GetLayerOrder(int aLayer) const
Function GetLayerOrder() Returns rendering order of a particular layer.
Definition: view.cpp:660
virtual int BeginGroup()
Begin a group.
BOX2< Vec > & Normalize()
Function Normalize ensures that the height ant width are positive.
Definition: box2.h:127
virtual void ClearTarget(RENDER_TARGET aTarget)
Clears the target for rendering.
std::unordered_map< int, VIEW_LAYER > LAYER_MAP
Definition: view.h:714
void SetMaximum()
Definition: box2.h:71
virtual void ViewGetLayers(int aLayers[], int &aCount) const =0
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on...
bool m_mirrorX
Horizontal flip flag
Definition: view.h:837
void invalidateItem(VIEW_ITEM *aItem, int aUpdateFlags)
Function invalidateItem() Manages dirty flags & redraw queueing when updating an item.
Definition: view.cpp:1197
void reorderGroups(std::unordered_map< int, int > aReorderMap)
Reorders the stored groups (to facilitate reordering of layers)
Definition: view.cpp:201
coord_type GetBottom() const
Definition: box2.h:198
Class VIEW_RTREE - Implements an R-tree for fast spatial indexing of VIEW items.
Definition: view_rtree.h:41
bool IsTargetDirty(int aTarget) const
Function IsTargetDirty() Returns true if any of layers belonging to the target or the target itself s...
Definition: view.h:585
int id
layer ID
Definition: view.h:708
Items that may change while the view stays the same (noncached)
Definition: definitions.h:43
VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
LAYER_ORDER m_orderedLayers
Sorted list of pointers to members of m_layers.
Definition: view.h:816
void ReorderLayerData(std::unordered_map< int, int > aReorderMap)
Remaps the data between layer ids without invalidating that data.
Definition: view.cpp:694
void UpdateItems()
Function UpdateItems() Iterates through the list of items that asked for updating and updates them...
Definition: view.cpp:1402
void markTargetClean(int aTarget)
Definition: view.h:732
GroupPair * m_groups
Indexes of cached GAL display lists corresponding to the item (for every layer it occupies)...
Definition: view.cpp:99
void updateBbox(VIEW_ITEM *aItem)
Updates bounding box of an item.
Definition: view.cpp:1306
PAINTER * m_painter
PAINTER contains information how do draw items.
Definition: view.h:843
bool m_reverseDrawOrder
Flag to reverse the draw order when using draw priority.
Definition: view.h:866
changeItemsDepth(int aLayer, int aDepth, GAL *aGal)
Definition: view.cpp:819
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1521
int m_nextDrawPriority
The next sequential drawing priority.
Definition: view.h:863
void saveLayers(int *aLayers, int aCount)
Function saveLayers() Saves layers used by the item.
Definition: view.cpp:229
Vec Centre() const
Definition: box2.h:77
virtual unsigned int GetSize() const
Function GetSize() Returns the number of stored items.
Definition: view_group.cpp:80
void ClearTopLayers()
Function ClearTopLayers() Removes all layers from the on-the-top set (they are no longer displayed ov...
Definition: view.cpp:900
bool operator()(VIEW_ITEM *aItem)
Definition: view.cpp:956
virtual bool Draw(const VIEW_ITEM *aItem, int aLayer)=0
Function Draw Takes an instance of VIEW_ITEM and passes it to a function that know how to draw the it...
LAYER_MAP::iterator LAYER_MAP_ITER
Definition: view.h:715
void SetEnd(coord_type x, coord_type y)
Definition: box2.h:223
std::unique_ptr< VIEW > DataReference() const
Returns a new VIEW object that shares the same set of VIEW_ITEMs and LAYERs.
Definition: view.cpp:1457
const VECTOR2I & GetScreenPixelSize() const
Returns GAL canvas size in pixels.
void clearGroupCache()
Definition: view.cpp:1182
VIEW_ITEM_DATA * viewPrivData() const
Definition: view_item.h:148
double m_maxScale
Scale upper limit.
Definition: view.h:834
void UpdateLayerColor(int aLayer)
Function UpdateLayerColor() Applies the new coloring scheme held by RENDER_SETTINGS in case that it h...
Definition: view.cpp:765
coord_type GetHeight() const
Definition: box2.h:196
double msecs() const
Definition: profile.h:124
std::vector< VIEW_ITEM * > drawItems
Definition: view.cpp:994
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
bool operator()(VIEW_ITEM *aItem)
Definition: view.cpp:428
bool operator()(VIEW_ITEM *aItem)
Definition: view.cpp:747
void redrawRect(const BOX2I &aRect)
Definition: view.cpp:998
void updateItemGeometry(VIEW_ITEM *aItem, int aLayer)
Updates all informations needed to draw an item.
Definition: view.cpp:1276
Board layer functions and definitions.
Main rendering target (cached)
Definition: definitions.h:41
bool areRequiredLayersEnabled(int aLayerId) const
Checks if every layer required by the aLayerId layer is enabled.
Definition: view.cpp:1365
bool m_enableOrderModifier
Definition: view.h:807
#define max(a, b)
Definition: auxiliary.h:86
static void OnDestroy(VIEW_ITEM *aItem)
Definition: view.cpp:271
virtual void ViewDraw(int aLayer, VIEW *aView) const
Function ViewDraw() Draws the parts of the object belonging to layer aLayer.
Definition: view_item.h:116
BOX2D m_boundary
View boundaries.
Definition: view.h:828
void getLayers(int *aLayers, int &aCount) const
Function getLayers() Returns layer numbers used by the item.
Definition: view.cpp:79
bool IsCached(int aLayer) const
Returns true if the layer is cached.
Definition: view.h:603
std::pair< VIEW_ITEM *, int > LAYER_ITEM_PAIR
Definition: view.h:66
size_t i
Definition: json11.cpp:597
void draw(VIEW_ITEM *aItem, int aLayer, bool aImmediate=false)
Function draw() Draws an item, but on a specified layers.
Definition: view.cpp:1017
virtual unsigned int ViewGetLOD(int aLayer, VIEW *aView) const
Function ViewGetLOD() Returns the level of detail (LOD) of the item.
Definition: view_item.h:140
VECTOR2D ToScreen(const VECTOR2D &aCoord, bool aAbsolute=true) const
Function ToScreen() Converts a world space point/vector to a point/vector in screen space coordinates...
Definition: view.cpp:483
void SetOrigin(const Vec &pos)
Definition: box2.h:208
const VECTOR2I & GetScreenPixelSize() const
Function GetScreenPixelSize() Returns the size of the our rendering area, in pixels.
Definition: view.cpp:1158
void SetZoomFactor(double aZoomFactor)
Set the zoom factor of the scene.
virtual void ChangeGroupDepth(int aGroupNumber, int aDepth)
Changes the depth (Z-axis position) of the group.
bool m_mirrorY
Vertical flip flag
Definition: view.h:840
void ClearTargets()
Function ClearTargets() Clears targets that are marked as dirty.
Definition: view.cpp:1114
int m_flags
Visibility flags.
Definition: view.cpp:90
double GetScale() const
Function GetScale()
Definition: view.h:268
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Sets the item visibility.
Definition: view.cpp:1467
void CopySettings(const VIEW *aOtherView)
Function CopySettings() Copies layers and visibility settings from another view.
Definition: view.cpp:502
LAYER_MAP m_layers
Contains set of possible displayed layers and its properties.
Definition: view.h:810
double m_scale
Scale of displayed VIEW_ITEMs.
Definition: view.h:825
Position or shape has changed.
Definition: view_item.h:58
int renderingOrder
rendering order of this layer
Definition: view.h:707
void SetLookAtPoint(const VECTOR2D &aPoint)
Set the Point in world space to look at.
Container & m_cont
Definition: view.cpp:436
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:335
std::pair< int, int > GroupPair
Helper for storing cached items group ids
Definition: view.cpp:95
coord_type GetLeft() const
Definition: box2.h:201
virtual ~VIEW()
Definition: view.cpp:315
Basic classes for most KiCad items.
VIEW(bool aIsDynamic=true)
Constructor.
Definition: view.cpp:285
Class VIEW.
Definition: view.h:61
bool IsVisible(const VIEW_ITEM *aItem) const
Returns information if the item is visible (or not).
Definition: view.cpp:1507
void UpdateAllLayersColor()
Function UpdateAllLayersColor() Applies the new coloring scheme to all layers.
Definition: view.cpp:786
std::vector< int > m_layers
Stores layer numbers used by the item.
Definition: view.cpp:220
void SetGAL(GAL *aGal)
Function SetGAL() Assigns a rendering device for the VIEW.
Definition: view.cpp:508
int m_requiredUpdate
Flag required for updating.
Definition: view.cpp:91
recacheItem(VIEW *aView, GAL *aGal, int aLayer)
Definition: view.cpp:1069
static bool compareRenderingOrder(VIEW_LAYER *aI, VIEW_LAYER *aJ)
Determines rendering order of layers. Used in display order sorting function.
Definition: view.h:798
virtual void ClearCache()
Delete all data created during caching of graphic items.
virtual void SetTarget(RENDER_TARGET aTarget)
Sets the target for rendering.
void MarkDirty()
Function MarkDirty() Forces redraw of view on the next rendering.
Definition: view.h:621
updateItemsColor(int aLayer, PAINTER *aPainter, GAL *aGal)
Definition: view.cpp:742
VECTOR2< T > GetScale() const
Get the scale components of the matrix.
Definition: matrix3x3.h:269
Class GAL is the abstract interface for drawing on a 2D-surface.
Color has changed.
Definition: view_item.h:57
bool operator()(VIEW_ITEM *aItem)
Definition: view.cpp:1171
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
BOX2< Vec > Intersect(const BOX2< Vec > &aRect)
Function Intersect Returns the intersection of this with another rectangle.
Definition: box2.h:266
RENDER_TARGET target
where the layer should be rendered
Definition: view.h:709
std::shared_ptr< VIEW_RTREE > items
R-tree indexing all items on this layer.
Definition: view.h:706