Preview fp edges & text while dragging in router.

Fixes https://gitlab.com/kicad/code/kicad/issues/5037
This commit is contained in:
Jeff Young 2020-08-01 14:20:08 +01:00
parent 91e00e14a9
commit d586495c0a
5 changed files with 96 additions and 76 deletions

View File

@ -320,11 +320,15 @@ VIEW::VIEW( bool aIsDynamic ) :
AddLayer( i );
sortLayers();
m_preview.reset( new KIGFX::VIEW_GROUP() );
Add( m_preview.get() );
}
VIEW::~VIEW()
{
Remove( m_preview.get() );
}
@ -1539,7 +1543,7 @@ void VIEW::Update( VIEW_ITEM* aItem )
void VIEW::Update( VIEW_ITEM* aItem, int aUpdateFlags )
{
auto viewData = aItem->viewPrivData();
VIEW_ITEM_DATA* viewData = aItem->viewPrivData();
if( !viewData )
return;
@ -1547,7 +1551,6 @@ void VIEW::Update( VIEW_ITEM* aItem, int aUpdateFlags )
assert( aUpdateFlags != NONE );
viewData->m_requiredUpdate |= aUpdateFlags;
}
@ -1560,6 +1563,38 @@ std::shared_ptr<VIEW_OVERLAY> VIEW::MakeOverlay()
}
void VIEW::ClearPreview()
{
m_preview->Clear();
for( EDA_ITEM* item : m_ownedItems )
delete item;
m_ownedItems.clear();
Update( m_preview.get() );
}
void VIEW::AddToPreview( EDA_ITEM* aItem, bool aTakeOwnership )
{
Hide( aItem, false );
m_preview->Add( aItem );
if( aTakeOwnership )
m_ownedItems.push_back( aItem );
SetVisible( m_preview.get(), true );
Hide( m_preview.get(), false );
Update( m_preview.get() );
}
void VIEW::ShowPreview( bool aShow )
{
SetVisible( m_preview.get(), aShow );
}
const int VIEW::TOP_LAYER_MODIFIER = -VIEW_MAX_LAYERS;
}

View File

@ -32,14 +32,9 @@
#include <view/wx_view_controls.h>
#include <ws_proxy_view_item.h>
#include <layers_id_colors_and_visibility.h>
#include <class_libentry.h>
#include <sch_sheet.h>
#include <sch_screen.h>
#include <sch_component.h>
#include <schematic.h>
#include <lib_pin.h>
#include <preview_items/selection_area.h>
#include <sch_edit_frame.h>
#include <sch_base_frame.h>
#include "sch_view.h"
@ -60,9 +55,6 @@ SCH_VIEW::SCH_VIEW( bool aIsDynamic, SCH_BASE_FRAME* aFrame ) :
double max_size = Mils2iu( MAX_PAGE_SIZE_MILS ) * 3.0;
m_boundary.SetOrigin( -max_size/4, -max_size/4 );
m_boundary.SetSize( max_size, max_size );
m_selectionArea.reset( new KIGFX::PREVIEW::SELECTION_AREA() );
m_preview.reset( new KIGFX::VIEW_GROUP() );
}
@ -112,12 +104,7 @@ void SCH_VIEW::DisplaySheet( SCH_SCREEN *aScreen )
ResizeSheetWorkingArea( aScreen );
m_selectionArea.reset( new KIGFX::PREVIEW::SELECTION_AREA() );
m_preview.reset( new KIGFX::VIEW_GROUP() );
Add( m_worksheet.get() );
Add( m_selectionArea.get() );
Add( m_preview.get() );
}
@ -172,43 +159,6 @@ void SCH_VIEW::DisplayComponent( LIB_PART* aPart )
Add( &item );
}
m_selectionArea.reset( new KIGFX::PREVIEW::SELECTION_AREA() );
m_preview.reset( new KIGFX::VIEW_GROUP() );
Add( m_selectionArea.get() );
Add( m_preview.get() );
}
void SCH_VIEW::ClearPreview()
{
m_preview->Clear();
for( auto item : m_ownedItems )
delete item;
m_ownedItems.clear();
Update( m_preview.get() );
}
void SCH_VIEW::AddToPreview( EDA_ITEM* aItem, bool aTakeOwnership )
{
Hide( aItem, false );
m_preview->Add( aItem );
if( aTakeOwnership )
m_ownedItems.push_back( aItem );
SetVisible( m_preview.get(), true );
Hide( m_preview.get(), false );
Update( m_preview.get() );
}
void SCH_VIEW::ShowPreview( bool aShow )
{
SetVisible( m_preview.get(), aShow );
}

View File

@ -84,11 +84,6 @@ public:
// Call it to set new draw area limits (max working and draw area size)
void ResizeSheetWorkingArea( SCH_SCREEN *aScreen );
void ClearPreview();
void AddToPreview( EDA_ITEM* aItem, bool aTakeOwnership = true );
void ShowPreview( bool aShow = true );
void SetScale( double aScale, VECTOR2D aAnchor = { 0, 0 } ) override;
/**
@ -104,10 +99,7 @@ private:
SCH_BASE_FRAME* m_frame; // The frame using this view. Can be null. Used mainly
// to know the sheet path name when drawing the page layout
std::unique_ptr<WS_PROXY_VIEW_ITEM> m_worksheet;
std::unique_ptr<KIGFX::PREVIEW::SELECTION_AREA> m_selectionArea;
std::unique_ptr<KIGFX::VIEW_GROUP> m_preview;
std::vector<EDA_ITEM *> m_ownedItems;
std::unique_ptr<WS_PROXY_VIEW_ITEM> m_worksheet;
};
}; // namespace

View File

@ -679,6 +679,11 @@ public:
std::shared_ptr<VIEW_OVERLAY> MakeOverlay();
void ClearPreview();
void AddToPreview( EDA_ITEM* aItem, bool aTakeOwnership = true );
void ShowPreview( bool aShow = true );
/**
* Returns a new VIEW object that shares the same set of VIEW_ITEMs and LAYERs.
* GAL, PAINTER and other properties are left uninitialized.
@ -727,6 +732,8 @@ protected:
struct changeItemsDepth;
struct extentsVisitor;
std::unique_ptr<KIGFX::VIEW_GROUP> m_preview;
std::vector<EDA_ITEM *> m_ownedItems;
///* Redraws contents within rect aRect
void redrawRect( const BOX2I& aRect );

View File

@ -20,27 +20,20 @@
*/
#include <wx/numdlg.h>
#include <core/optional.h>
#include <functional>
using namespace std::placeholders;
#include "class_board.h"
#include "class_module.h"
#include "class_pad.h"
#include <class_board.h>
#include <class_board_item.h>
#include <class_module.h>
#include <class_pad.h>
#include <pcb_edit_frame.h>
#include <id.h>
#include <macros.h>
#include <pcbnew_id.h>
#include <view/view_controls.h>
#include <pcb_layer_widget.h>
#include <pcb_painter.h>
#include <dialogs/dialog_pns_settings.h>
#include <dialogs/dialog_pns_diff_pair_dimensions.h>
#include <dialogs/dialog_track_via_size.h>
#include <base_units.h>
#include <confirm.h>
#include <bitmaps.h>
#include <collectors.h>
#include <tool/action_menu.h>
#include <tool/tool_manager.h>
#include <tool/grid_menu.h>
@ -1379,13 +1372,15 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent )
PNS::ITEM* startItem = nullptr;
PNS::ITEM_SET itemsToDrag;
const MODULE* module = nullptr;
if( item->Type() == PCB_MODULE_T )
{
const auto mod = static_cast<const MODULE*>(item);
for ( const auto p : mod->Pads() )
module = static_cast<const MODULE*>(item);
for( const D_PAD* pad : module->Pads() )
{
auto solid = m_router->GetWorld()->FindItemByParent( p );
PNS::ITEM* solid = m_router->GetWorld()->FindItemByParent( pad );
if( solid )
itemsToDrag.Add( solid );
@ -1441,6 +1436,35 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent )
{
updateEndItem( *evt );
m_router->Move( m_endSnapPoint, m_endItem );
if( module )
{
VECTOR2I offset = m_endSnapPoint - p;
BOARD_ITEM* previewItem;
view()->ClearPreview();
for( BOARD_ITEM* drawing : module->GraphicalItems() )
{
previewItem = static_cast<BOARD_ITEM*>( drawing->Clone() );
previewItem->Move( offset );
view()->Add( previewItem );
view()->AddToPreview( previewItem );
view()->Hide( drawing, true );
}
previewItem = static_cast<BOARD_ITEM*>( module->Reference().Clone() );
previewItem->Move( offset );
view()->Add( previewItem );
view()->AddToPreview( previewItem );
view()->Hide( &module->Reference() );
previewItem = static_cast<BOARD_ITEM*>( module->Value().Clone() );
previewItem->Move( offset );
view()->Add( previewItem );
view()->AddToPreview( previewItem );
view()->Hide( &module->Value() );
}
}
else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
{
@ -1450,6 +1474,18 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent )
}
}
if( module )
{
for( BOARD_ITEM* drawing : module->GraphicalItems() )
view()->Hide( drawing, false );
view()->Hide( &module->Reference(), false );
view()->Hide( &module->Value(), false );
view()->ClearPreview();
view()->ShowPreview( false );
}
if( m_router->RoutingInProgress() )
m_router->StopRouting();