Added VIEW::DataReference() for sharing data with another VIEW instance

This commit is contained in:
Maciej Suminski 2018-07-05 08:35:50 +02:00
parent 1411e1f73a
commit 17205b4599
3 changed files with 42 additions and 27 deletions

View File

@ -295,7 +295,8 @@ VIEW::VIEW( bool aIsDynamic ) :
m_reverseDrawOrder( false )
{
m_boundary.SetMaximum();
m_allItems.reserve( 32768 );
m_allItems.reset( new std::vector<VIEW_ITEM*> );
m_allItems->reserve( 32768 );
// Redraw everything at the beginning
MarkDirty();
@ -306,13 +307,13 @@ VIEW::VIEW( bool aIsDynamic ) :
// silkscreen, pads, vias, etc.
for( int i = 0; i < VIEW_MAX_LAYERS; i++ )
AddLayer( i );
sortLayers();
}
VIEW::~VIEW()
{
for( LAYER_MAP::value_type& l : m_layers )
delete l.second.items;
}
@ -321,15 +322,13 @@ void VIEW::AddLayer( int aLayer, bool aDisplayOnly )
if( m_layers.find( aLayer ) == m_layers.end() )
{
m_layers[aLayer] = VIEW_LAYER();
m_layers[aLayer].items.reset( new VIEW_RTREE() );
m_layers[aLayer].id = aLayer;
m_layers[aLayer].items = new VIEW_RTREE();
m_layers[aLayer].renderingOrder = aLayer;
m_layers[aLayer].visible = true;
m_layers[aLayer].displayOnly = aDisplayOnly;
m_layers[aLayer].target = TARGET_CACHED;
}
sortLayers();
}
@ -349,7 +348,7 @@ void VIEW::Add( VIEW_ITEM* aItem, int aDrawPriority )
aItem->ViewGetLayers( layers, layers_count );
aItem->viewPrivData()->saveLayers( layers, layers_count );
m_allItems.push_back( aItem );
m_allItems->push_back( aItem );
for( int i = 0; i < layers_count; ++i )
{
@ -374,11 +373,11 @@ void VIEW::Remove( VIEW_ITEM* aItem )
return;
wxASSERT( viewData->m_view == this );
auto item = std::find( m_allItems.begin(), m_allItems.end(), aItem );
auto item = std::find( m_allItems->begin(), m_allItems->end(), aItem );
if( item != m_allItems.end() )
if( item != m_allItems->end() )
{
m_allItems.erase( item );
m_allItems->erase( item );
viewData->clearUpdateFlags();
}
@ -694,7 +693,7 @@ void VIEW::ReorderLayerData( std::unordered_map<int, int> aReorderMap )
{
LAYER_MAP new_map;
for( auto it : m_layers )
for( const auto& it : m_layers )
{
int orig_idx = it.first;
VIEW_LAYER layer = it.second;
@ -715,7 +714,7 @@ void VIEW::ReorderLayerData( std::unordered_map<int, int> aReorderMap )
m_layers = new_map;
for( VIEW_ITEM* item : m_allItems )
for( VIEW_ITEM* item : *m_allItems )
{
auto viewData = item->viewPrivData();
@ -788,7 +787,7 @@ void VIEW::UpdateAllLayersColor()
{
GAL_UPDATE_CONTEXT ctx( m_gal );
for( VIEW_ITEM* item : m_allItems )
for( VIEW_ITEM* item : *m_allItems )
{
auto viewData = item->viewPrivData();
@ -919,7 +918,7 @@ void VIEW::UpdateAllLayersOrder()
{
GAL_UPDATE_CONTEXT ctx( m_gal );
for( VIEW_ITEM* item : m_allItems )
for( VIEW_ITEM* item : *m_allItems )
{
auto viewData = item->viewPrivData();
@ -1099,7 +1098,7 @@ void VIEW::Clear()
{
BOX2I r;
r.SetMaximum();
m_allItems.clear();
m_allItems->clear();
for( LAYER_MAP_ITER i = m_layers.begin(); i != m_layers.end(); ++i )
i->second.items->RemoveAll();
@ -1404,7 +1403,7 @@ void VIEW::UpdateItems()
{
GAL_UPDATE_CONTEXT ctx( m_gal );
for( VIEW_ITEM* item : m_allItems )
for( VIEW_ITEM* item : *m_allItems )
{
auto viewData = item->viewPrivData();
@ -1423,7 +1422,7 @@ void VIEW::UpdateItems()
void VIEW::UpdateAllItems( int aUpdateFlags )
{
for( VIEW_ITEM* item : m_allItems )
for( VIEW_ITEM* item : *m_allItems )
{
auto viewData = item->viewPrivData();
@ -1438,7 +1437,7 @@ void VIEW::UpdateAllItems( int aUpdateFlags )
void VIEW::UpdateAllItemsConditionally( int aUpdateFlags,
std::function<bool( VIEW_ITEM* )> aCondition )
{
for( VIEW_ITEM* item : m_allItems )
for( VIEW_ITEM* item : *m_allItems )
{
if( aCondition( item ) )
{
@ -1490,6 +1489,16 @@ const BOX2I VIEW::CalculateExtents()
}
std::unique_ptr<VIEW> VIEW::DataReference() const
{
auto ret = std::make_unique<VIEW>();
ret->m_allItems = m_allItems;
ret->m_layers = m_layers;
ret->sortLayers();
return ret;
}
void VIEW::SetVisible( VIEW_ITEM* aItem, bool aIsVisible )
{
auto viewData = aItem->viewPrivData();

View File

@ -140,7 +140,7 @@ void SCH_VIEW::ShowPreview( bool aShow )
void SCH_VIEW::ClearHiddenFlags()
{
for( auto item : m_allItems )
for( auto item : *m_allItems )
Hide ( item, false );
}

View File

@ -65,8 +65,6 @@ public:
typedef std::pair<VIEW_ITEM*, int> LAYER_ITEM_PAIR;
static const int VIEW_MAX_LAYERS = 512; ///< maximum number of layers that may be shown
/**
* Constructor.
* @param aIsDynamic decides whether we are creating a static or a dynamic VIEW.
@ -429,14 +427,12 @@ public:
inline bool IsLayerVisible( int aLayer ) const
{
wxASSERT( aLayer < (int) m_layers.size() );
return m_layers.at( aLayer ).visible;
}
inline void SetLayerDisplayOnly( int aLayer, bool aDisplayOnly = true )
{
wxASSERT( aLayer < (int) m_layers.size() );
m_layers[aLayer].displayOnly = aDisplayOnly;
}
@ -449,7 +445,6 @@ public:
inline void SetLayerTarget( int aLayer, RENDER_TARGET aTarget )
{
wxASSERT( aLayer < (int) m_layers.size() );
m_layers[aLayer].target = aTarget;
}
@ -699,12 +694,20 @@ public:
std::shared_ptr<VIEW_OVERLAY> MakeOverlay();
/**
* Returns a new VIEW object that shares the same set of VIEW_ITEMs and LAYERs.
* GAL, PAINTER and other properties are left uninitialized.
*/
std::unique_ptr<VIEW> DataReference() const;
static constexpr int VIEW_MAX_LAYERS = 512; ///< maximum number of layers that may be shown
protected:
struct VIEW_LAYER
{
bool visible; ///< is the layer to be rendered?
bool displayOnly; ///< is the layer display only?
VIEW_RTREE* items; ///< R-tree indexing all items on this layer.
std::shared_ptr<VIEW_RTREE> items; ///< R-tree indexing all items on this layer.
int renderingOrder; ///< rendering order of this layer
int id; ///< layer ID
RENDER_TARGET target; ///< where the layer should be rendered
@ -811,6 +814,9 @@ protected:
/// Contains set of possible displayed layers and its properties
LAYER_MAP m_layers;
/// Flat list of all items
std::shared_ptr<std::vector<VIEW_ITEM*>> m_allItems;
/// Sorted list of pointers to members of m_layers
LAYER_ORDER m_orderedLayers;
@ -855,8 +861,6 @@ protected:
static const int TOP_LAYER_MODIFIER;
/// Flat list of all items
std::vector<VIEW_ITEM*> m_allItems;
/// Flag to respect draw priority when drawing items
bool m_useDrawPriority;
@ -865,6 +869,8 @@ protected:
/// Flag to reverse the draw order when using draw priority
bool m_reverseDrawOrder;
VIEW( const VIEW& ) = delete;
};
} // namespace KIGFX