Implement rollover highlighting for Eeschema delete tool.
This commit is contained in:
parent
7cfe19d9fd
commit
9e464f9f5b
|
@ -54,24 +54,6 @@ const KICAD_T EE_COLLECTOR::EditableItems[] = {
|
|||
};
|
||||
|
||||
|
||||
const KICAD_T EE_COLLECTOR::RotatableItems[] = {
|
||||
SCH_TEXT_T,
|
||||
SCH_LABEL_T,
|
||||
SCH_GLOBAL_LABEL_T,
|
||||
SCH_HIER_LABEL_T,
|
||||
SCH_FIELD_T,
|
||||
SCH_COMPONENT_T,
|
||||
SCH_SHEET_PIN_T,
|
||||
SCH_SHEET_T,
|
||||
SCH_BITMAP_T,
|
||||
SCH_BUS_BUS_ENTRY_T,
|
||||
SCH_BUS_WIRE_ENTRY_T,
|
||||
SCH_LINE_T,
|
||||
SCH_JUNCTION_T,
|
||||
EOT
|
||||
};
|
||||
|
||||
|
||||
const KICAD_T EE_COLLECTOR::ComponentsOnly[] = {
|
||||
SCH_COMPONENT_T,
|
||||
EOT
|
||||
|
|
|
@ -40,7 +40,6 @@ class EE_COLLECTOR : public COLLECTOR
|
|||
public:
|
||||
static const KICAD_T AllItems[];
|
||||
static const KICAD_T EditableItems[];
|
||||
static const KICAD_T RotatableItems[];
|
||||
static const KICAD_T ComponentsOnly[];
|
||||
static const KICAD_T SheetsOnly[];
|
||||
|
||||
|
|
|
@ -227,7 +227,7 @@ COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM* aItem, int aLayer, bool aOn
|
|||
{
|
||||
COLOR4D color = m_schSettings.GetLayerColor( aLayer );
|
||||
|
||||
if( aItem->IsBrightened() )
|
||||
if( aItem->IsBrightened() && !aOnBackgroundLayer )
|
||||
color = m_schSettings.GetLayerColor( LAYER_BRIGHTENED );
|
||||
else if( aItem->Type() == SCH_LINE_T )
|
||||
color = static_cast<const SCH_LINE*>( aItem )->GetLineColor();
|
||||
|
|
|
@ -38,25 +38,23 @@ EE_PICKER_TOOL::EE_PICKER_TOOL()
|
|||
int EE_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
||||
int finalize_state = WAIT_CANCEL;
|
||||
int finalize_state = WAIT_CANCEL;
|
||||
|
||||
setControls();
|
||||
|
||||
while( TOOL_EVENT* evt = Wait() )
|
||||
{
|
||||
VECTOR2I cursorPos = controls->GetCursorPosition( !evt->Modifier( MD_ALT ) );
|
||||
VECTOR2D cursorPos = controls->GetCursorPosition( !evt->Modifier( MD_ALT ) );
|
||||
|
||||
if( evt->IsClick( BUT_LEFT ) )
|
||||
{
|
||||
bool getNext = false;
|
||||
|
||||
m_picked = cursorPos;
|
||||
|
||||
if( m_clickHandler )
|
||||
{
|
||||
try
|
||||
{
|
||||
getNext = (*m_clickHandler)( *m_picked );
|
||||
getNext = (*m_clickHandler)( cursorPos );
|
||||
}
|
||||
catch( std::exception& e )
|
||||
{
|
||||
|
@ -75,6 +73,21 @@ int EE_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
|
|||
setControls();
|
||||
}
|
||||
|
||||
else if( evt->IsMotion() )
|
||||
{
|
||||
if( m_motionHandler )
|
||||
{
|
||||
try
|
||||
{
|
||||
(*m_motionHandler)( cursorPos );
|
||||
}
|
||||
catch( std::exception& e )
|
||||
{
|
||||
std::cerr << "EE_PICKER_TOOL motion handler error: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
|
||||
{
|
||||
if( m_cancelHandler )
|
||||
|
@ -135,7 +148,6 @@ void EE_PICKER_TOOL::resetPicker()
|
|||
m_cursorCapture = false;
|
||||
m_autoPanning = false;
|
||||
|
||||
m_picked = NULLOPT;
|
||||
m_clickHandler = NULLOPT;
|
||||
m_cancelHandler = NULLOPT;
|
||||
m_finalizeHandler = NULLOPT;
|
||||
|
|
|
@ -39,6 +39,7 @@ public:
|
|||
|
||||
///> Event handler types.
|
||||
typedef std::function<bool(const VECTOR2D&)> CLICK_HANDLER;
|
||||
typedef std::function<void(const VECTOR2D&)> MOTION_HANDLER;
|
||||
typedef std::function<void(void)> CANCEL_HANDLER;
|
||||
typedef std::function<void(const int&)> FINALIZE_HANDLER;
|
||||
|
||||
|
@ -77,6 +78,16 @@ public:
|
|||
m_clickHandler = aHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function SetMotionHandler()
|
||||
* Sets a handler for mouse motion. Used for roll-over highlighting.
|
||||
*/
|
||||
inline void SetMotionHandler( MOTION_HANDLER aHandler )
|
||||
{
|
||||
assert( !m_motionHandler );
|
||||
m_motionHandler = aHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function SetCancelHandler()
|
||||
* Sets a handler for cancel events (ESC or context-menu Cancel).
|
||||
|
@ -112,10 +123,9 @@ private:
|
|||
bool m_autoPanning;
|
||||
|
||||
OPT<CLICK_HANDLER> m_clickHandler;
|
||||
OPT<MOTION_HANDLER> m_motionHandler;
|
||||
OPT<CANCEL_HANDLER> m_cancelHandler;
|
||||
OPT<FINALIZE_HANDLER> m_finalizeHandler;
|
||||
|
||||
OPT<VECTOR2D> m_picked;
|
||||
};
|
||||
|
||||
#endif /* EE_PICKER_TOOL_H */
|
||||
|
|
|
@ -317,9 +317,27 @@ bool SCH_EDIT_TOOL::Init()
|
|||
}
|
||||
|
||||
|
||||
const KICAD_T rotatableItems[] = {
|
||||
SCH_TEXT_T,
|
||||
SCH_LABEL_T,
|
||||
SCH_GLOBAL_LABEL_T,
|
||||
SCH_HIER_LABEL_T,
|
||||
SCH_FIELD_T,
|
||||
SCH_COMPONENT_T,
|
||||
SCH_SHEET_PIN_T,
|
||||
SCH_SHEET_T,
|
||||
SCH_BITMAP_T,
|
||||
SCH_BUS_BUS_ENTRY_T,
|
||||
SCH_BUS_WIRE_ENTRY_T,
|
||||
SCH_LINE_T,
|
||||
SCH_JUNCTION_T,
|
||||
EOT
|
||||
};
|
||||
|
||||
|
||||
int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::RotatableItems );
|
||||
EE_SELECTION& selection = m_selectionTool->RequestSelection( rotatableItems );
|
||||
|
||||
if( selection.GetSize() == 0 )
|
||||
return 0;
|
||||
|
@ -489,7 +507,7 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
|
|||
|
||||
int SCH_EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::RotatableItems );
|
||||
EE_SELECTION& selection = m_selectionTool->RequestSelection( rotatableItems );
|
||||
|
||||
if( selection.GetSize() == 0 )
|
||||
return 0;
|
||||
|
@ -669,24 +687,25 @@ int SCH_EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
|
|||
}
|
||||
|
||||
|
||||
static KICAD_T duplicatableItems[] =
|
||||
{
|
||||
SCH_JUNCTION_T,
|
||||
SCH_LINE_T,
|
||||
SCH_BUS_BUS_ENTRY_T,
|
||||
SCH_BUS_WIRE_ENTRY_T,
|
||||
SCH_TEXT_T,
|
||||
SCH_LABEL_T,
|
||||
SCH_GLOBAL_LABEL_T,
|
||||
SCH_HIER_LABEL_T,
|
||||
SCH_NO_CONNECT_T,
|
||||
SCH_SHEET_T,
|
||||
SCH_COMPONENT_T,
|
||||
EOT
|
||||
};
|
||||
|
||||
|
||||
int SCH_EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
static KICAD_T duplicatableItems[] =
|
||||
{
|
||||
SCH_JUNCTION_T,
|
||||
SCH_LINE_T,
|
||||
SCH_BUS_BUS_ENTRY_T,
|
||||
SCH_BUS_WIRE_ENTRY_T,
|
||||
SCH_TEXT_T,
|
||||
SCH_LABEL_T,
|
||||
SCH_GLOBAL_LABEL_T,
|
||||
SCH_HIER_LABEL_T,
|
||||
SCH_NO_CONNECT_T,
|
||||
SCH_SHEET_T,
|
||||
SCH_COMPONENT_T,
|
||||
EOT
|
||||
};
|
||||
|
||||
EE_SELECTION& selection = m_selectionTool->RequestSelection( duplicatableItems );
|
||||
|
||||
if( selection.GetSize() == 0 )
|
||||
|
@ -827,10 +846,29 @@ int SCH_EDIT_TOOL::RepeatDrawItem( const TOOL_EVENT& aEvent )
|
|||
}
|
||||
|
||||
|
||||
static KICAD_T deletableItems[] =
|
||||
{
|
||||
SCH_MARKER_T,
|
||||
SCH_JUNCTION_T,
|
||||
SCH_LINE_T,
|
||||
SCH_BUS_BUS_ENTRY_T,
|
||||
SCH_BUS_WIRE_ENTRY_T,
|
||||
SCH_TEXT_T,
|
||||
SCH_LABEL_T,
|
||||
SCH_GLOBAL_LABEL_T,
|
||||
SCH_HIER_LABEL_T,
|
||||
SCH_NO_CONNECT_T,
|
||||
SCH_SHEET_T,
|
||||
SCH_SHEET_PIN_T,
|
||||
SCH_COMPONENT_T,
|
||||
EOT
|
||||
};
|
||||
|
||||
|
||||
int SCH_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
SCH_SCREEN* screen = m_frame->GetScreen();
|
||||
auto items = m_selectionTool->RequestSelection().GetItems();
|
||||
auto items = m_selectionTool->RequestSelection( deletableItems ).GetItems();
|
||||
bool appendToUndo = false;
|
||||
|
||||
if( items.empty() )
|
||||
|
@ -890,45 +928,73 @@ int SCH_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent )
|
|||
}
|
||||
|
||||
|
||||
static bool deleteItem( SCH_BASE_FRAME* aFrame, const VECTOR2D& aPosition )
|
||||
{
|
||||
EE_SELECTION_TOOL* selectionTool = aFrame->GetToolManager()->GetTool<EE_SELECTION_TOOL>();
|
||||
wxCHECK( selectionTool, false );
|
||||
|
||||
aFrame->GetToolManager()->RunAction( EE_ACTIONS::clearSelection, true );
|
||||
|
||||
EDA_ITEM* item = selectionTool->SelectPoint( aPosition );
|
||||
SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( item );
|
||||
|
||||
if( sch_item && sch_item->IsLocked() )
|
||||
{
|
||||
STATUS_TEXT_POPUP statusPopup( aFrame );
|
||||
statusPopup.SetText( _( "Item locked." ) );
|
||||
statusPopup.PopupFor( 2000 );
|
||||
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
|
||||
return true;
|
||||
}
|
||||
|
||||
if( item )
|
||||
aFrame->GetToolManager()->RunAction( EE_ACTIONS::doDelete, true );
|
||||
|
||||
return true;
|
||||
}
|
||||
#define HITTEST_THRESHOLD_PIXELS 5
|
||||
|
||||
|
||||
int SCH_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
||||
|
||||
m_frame->SetTool( aEvent.GetCommandStr().get() );
|
||||
Activate();
|
||||
|
||||
EE_PICKER_TOOL* picker = m_toolMgr->GetTool<EE_PICKER_TOOL>();
|
||||
wxCHECK( picker, 0 );
|
||||
m_pickerItem = nullptr;
|
||||
|
||||
picker->SetClickHandler( [this] ( const VECTOR2D& aPosition ) -> bool {
|
||||
if( m_pickerItem )
|
||||
{
|
||||
SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( m_pickerItem );
|
||||
|
||||
if( sch_item && sch_item->IsLocked() )
|
||||
{
|
||||
STATUS_TEXT_POPUP statusPopup( m_frame );
|
||||
statusPopup.SetText( _( "Item locked." ) );
|
||||
statusPopup.PopupFor( 2000 );
|
||||
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
|
||||
return true;
|
||||
}
|
||||
|
||||
EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
||||
selectionTool->AddItemToSel( m_pickerItem, true );
|
||||
m_toolMgr->RunAction( EE_ACTIONS::doDelete, true );
|
||||
m_pickerItem = nullptr;
|
||||
}
|
||||
|
||||
return true;
|
||||
} );
|
||||
|
||||
picker->SetMotionHandler( [this] ( const VECTOR2D& aPos ) {
|
||||
EE_COLLECTOR collector;
|
||||
collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
|
||||
collector.Collect( m_frame->GetScreen()->GetDrawItems(), deletableItems, (wxPoint) aPos );
|
||||
EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
|
||||
|
||||
if( m_pickerItem != item )
|
||||
{
|
||||
EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
||||
|
||||
if( m_pickerItem )
|
||||
selectionTool->UnbrightenItem( m_pickerItem );
|
||||
|
||||
m_pickerItem = item;
|
||||
|
||||
if( m_pickerItem )
|
||||
selectionTool->BrightenItem( m_pickerItem );
|
||||
}
|
||||
} );
|
||||
|
||||
picker->SetCancelHandler( [this] () {
|
||||
m_frame->ClearToolStack();
|
||||
} );
|
||||
|
||||
picker->SetClickHandler( std::bind( deleteItem, m_frame, std::placeholders::_1 ) );
|
||||
picker->SetCancelHandler( [this]() { m_frame->ClearToolStack(); } );
|
||||
picker->Activate();
|
||||
Wait();
|
||||
|
||||
if( m_pickerItem )
|
||||
m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ class SCH_EDIT_TOOL : public EE_TOOL_BASE<SCH_EDIT_FRAME>
|
|||
{
|
||||
public:
|
||||
SCH_EDIT_TOOL();
|
||||
~SCH_EDIT_TOOL() { }
|
||||
~SCH_EDIT_TOOL() override { }
|
||||
|
||||
/// @copydoc TOOL_INTERACTIVE::Init()
|
||||
bool Init() override;
|
||||
|
@ -69,6 +69,9 @@ public:
|
|||
private:
|
||||
///> Sets up handlers for various events.
|
||||
void setTransitions() override;
|
||||
|
||||
private:
|
||||
EDA_ITEM* m_pickerItem;
|
||||
};
|
||||
|
||||
#endif //KICAD_SCH_EDIT_TOOL_H
|
||||
|
|
Loading…
Reference in New Issue