Edit worksheet properties when no other selection is available.

Fixes https://gitlab.com/kicad/code/kicad/issues/4044
This commit is contained in:
Jeff Young 2020-04-21 00:24:29 +01:00
parent 60cad7d526
commit f113370e1e
2 changed files with 106 additions and 92 deletions

View File

@ -136,92 +136,95 @@ bool SCH_EDIT_TOOL::Init()
wxASSERT_MSG( drawingTools, "eeshema.InteractiveDrawing tool is not available" ); wxASSERT_MSG( drawingTools, "eeshema.InteractiveDrawing tool is not available" );
auto sheetTool = [ this ] ( const SELECTION& aSel ) { auto sheetTool =
return ( m_frame->IsCurrentTool( EE_ACTIONS::drawSheet ) ); [ this ] ( const SELECTION& aSel )
};
auto anyTextTool = [ this ] ( const SELECTION& aSel ) {
return ( m_frame->IsCurrentTool( EE_ACTIONS::placeLabel )
|| m_frame->IsCurrentTool( EE_ACTIONS::placeGlobalLabel )
|| m_frame->IsCurrentTool( EE_ACTIONS::placeHierLabel )
|| m_frame->IsCurrentTool( EE_ACTIONS::placeSchematicText ) );
};
auto duplicateCondition = [] ( const SELECTION& aSel ) {
if( SCH_LINE_WIRE_BUS_TOOL::IsDrawingLineWireOrBus( aSel ) )
return false;
return true;
};
auto orientCondition = [] ( const SELECTION& aSel ) {
if( aSel.Empty() )
return false;
if( SCH_LINE_WIRE_BUS_TOOL::IsDrawingLineWireOrBus( aSel ) )
return false;
SCH_ITEM* item = (SCH_ITEM*) aSel.Front();
if( aSel.GetSize() > 1 )
return true;
switch( item->Type() )
{
case SCH_MARKER_T:
case SCH_JUNCTION_T:
case SCH_NO_CONNECT_T:
case SCH_LINE_T:
case SCH_PIN_T:
return false;
default:
return true;
}
};
auto propertiesCondition = []( const SELECTION& aSel ) {
if( aSel.GetSize() != 1
&& !( aSel.GetSize() >= 1 && aSel.Front()->Type() == SCH_LINE_T
&& aSel.AreAllItemsIdentical() ) )
return false;
auto item = static_cast<EDA_ITEM*>( aSel.Front() );
switch( item->Type() )
{
case SCH_MARKER_T:
case SCH_JUNCTION_T:
case SCH_NO_CONNECT_T:
case SCH_BUS_WIRE_ENTRY_T:
case SCH_BUS_BUS_ENTRY_T:
case SCH_SHEET_PIN_T:
case SCH_PIN_T:
return false;
case SCH_LINE_T:
{
const std::deque<EDA_ITEM*> items = aSel.GetItems();
if( !std::all_of( items.begin(), items.end(),
[&]( const EDA_ITEM* selItem )
{
const SCH_LINE* line = dynamic_cast<const SCH_LINE*>( selItem );
if ( line == nullptr )
{
wxLogWarning(
"Non-line object encountered in selection, this shouldn't have bypassed the preceeding check" );
return false;
}
return line->IsGraphicLine();
} ) )
{ {
return false; return ( m_frame->IsCurrentTool( EE_ACTIONS::drawSheet ) );
} };
// Only graphic lines support properties in the file format auto anyTextTool =
return true; [ this ] ( const SELECTION& aSel )
} {
default: return ( m_frame->IsCurrentTool( EE_ACTIONS::placeLabel )
return true; || m_frame->IsCurrentTool( EE_ACTIONS::placeGlobalLabel )
} || m_frame->IsCurrentTool( EE_ACTIONS::placeHierLabel )
}; || m_frame->IsCurrentTool( EE_ACTIONS::placeSchematicText ) );
};
auto duplicateCondition =
[] ( const SELECTION& aSel )
{
if( SCH_LINE_WIRE_BUS_TOOL::IsDrawingLineWireOrBus( aSel ) )
return false;
return true;
};
auto orientCondition =
[] ( const SELECTION& aSel )
{
if( aSel.Empty() )
return false;
if( SCH_LINE_WIRE_BUS_TOOL::IsDrawingLineWireOrBus( aSel ) )
return false;
SCH_ITEM* item = (SCH_ITEM*) aSel.Front();
if( aSel.GetSize() > 1 )
return true;
switch( item->Type() )
{
case SCH_MARKER_T:
case SCH_JUNCTION_T:
case SCH_NO_CONNECT_T:
case SCH_LINE_T:
case SCH_PIN_T:
return false;
default:
return true;
}
};
auto propertiesCondition =
[]( const SELECTION& aSel )
{
if( aSel.GetSize() == 0 )
return true; // Show worksheet properties
if( aSel.GetSize() != 1
&& !( aSel.GetSize() >= 1 && aSel.Front()->Type() == SCH_LINE_T
&& aSel.AreAllItemsIdentical() ) )
return false;
EDA_ITEM* item = static_cast<EDA_ITEM*>( aSel.Front() );
switch( item->Type() )
{
case SCH_COMPONENT_T:
case SCH_SHEET_T:
case SCH_SHEET_PIN_T:
case SCH_TEXT_T:
case SCH_LABEL_T:
case SCH_GLOBAL_LABEL_T:
case SCH_HIER_LABEL_T:
case SCH_FIELD_T:
case SCH_BITMAP_T:
return aSel.GetSize() == 1;
case SCH_LINE_T:
return std::all_of( aSel.GetItems().begin(), aSel.GetItems().end(),
[&]( EDA_ITEM* selItem )
{
SCH_LINE* line = dynamic_cast<SCH_LINE*>( selItem );
return line && line->IsGraphicLine();
} );
default:
return false;
}
};
static KICAD_T toLabelTypes[] = { SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_TEXT_T, EOT }; static KICAD_T toLabelTypes[] = { SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_TEXT_T, EOT };
auto toLabelCondition = E_C::Count( 1 ) && E_C::OnlyTypes( toLabelTypes ); auto toLabelCondition = E_C::Count( 1 ) && E_C::OnlyTypes( toLabelTypes );
@ -1231,7 +1234,10 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::EditableItems ); EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::EditableItems );
if( selection.Empty() ) if( selection.Empty() )
{
m_toolMgr->RunAction( ACTIONS::pageSettings );
return 0; return 0;
}
SCH_ITEM* item = (SCH_ITEM*) selection.Front(); SCH_ITEM* item = (SCH_ITEM*) selection.Front();

View File

@ -123,16 +123,20 @@ bool EDIT_TOOL::Init()
m_selectionTool = static_cast<SELECTION_TOOL*>( m_toolMgr->FindTool( "pcbnew.InteractiveSelection" ) ); m_selectionTool = static_cast<SELECTION_TOOL*>( m_toolMgr->FindTool( "pcbnew.InteractiveSelection" ) );
wxASSERT_MSG( m_selectionTool, "pcbnew.InteractiveSelection tool is not available" ); wxASSERT_MSG( m_selectionTool, "pcbnew.InteractiveSelection tool is not available" );
auto editingModuleCondition = [ this ] ( const SELECTION& aSelection ) { auto editingModuleCondition =
return m_editModules; [ this ] ( const SELECTION& aSelection )
}; {
return m_editModules;
};
auto singleModuleCondition = SELECTION_CONDITIONS::OnlyType( PCB_MODULE_T ) auto singleModuleCondition = SELECTION_CONDITIONS::OnlyType( PCB_MODULE_T )
&& SELECTION_CONDITIONS::Count( 1 ); && SELECTION_CONDITIONS::Count( 1 );
auto noActiveToolCondition = [ this ] ( const SELECTION& aSelection ) { auto noActiveToolCondition =
return frame()->ToolStackIsEmpty(); [ this ] ( const SELECTION& aSelection )
}; {
return frame()->ToolStackIsEmpty();
};
// Add context menu entries that are displayed when selection tool is active // Add context menu entries that are displayed when selection tool is active
CONDITIONAL_MENU& menu = m_selectionTool->GetToolMenu().GetMenu(); CONDITIONAL_MENU& menu = m_selectionTool->GetToolMenu().GetMenu();
@ -146,7 +150,7 @@ bool EDIT_TOOL::Init()
menu.AddItem( PCB_ACTIONS::rotateCw, SELECTION_CONDITIONS::NotEmpty ); menu.AddItem( PCB_ACTIONS::rotateCw, SELECTION_CONDITIONS::NotEmpty );
menu.AddItem( PCB_ACTIONS::flip, SELECTION_CONDITIONS::NotEmpty ); menu.AddItem( PCB_ACTIONS::flip, SELECTION_CONDITIONS::NotEmpty );
menu.AddItem( ACTIONS::doDelete, SELECTION_CONDITIONS::NotEmpty ); menu.AddItem( ACTIONS::doDelete, SELECTION_CONDITIONS::NotEmpty );
menu.AddItem( PCB_ACTIONS::properties, SELECTION_CONDITIONS::Count( 1 ) menu.AddItem( PCB_ACTIONS::properties, SELECTION_CONDITIONS::LessThan( 2 )
|| SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ); || SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) );
menu.AddItem( PCB_ACTIONS::moveExact, SELECTION_CONDITIONS::NotEmpty ); menu.AddItem( PCB_ACTIONS::moveExact, SELECTION_CONDITIONS::NotEmpty );
@ -586,7 +590,11 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
DIALOG_TRACK_VIA_PROPERTIES dlg( editFrame, selection, *m_commit ); DIALOG_TRACK_VIA_PROPERTIES dlg( editFrame, selection, *m_commit );
dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
} }
else if( selection.Size() == 1 ) // Properties are displayed when there is only one item selected else if( selection.Size() == 0 )
{
m_toolMgr->RunAction( ACTIONS::pageSettings );
}
else if( selection.Size() == 1 )
{ {
// Display properties dialog // Display properties dialog
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.Front() ); BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.Front() );