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,25 +136,33 @@ bool SCH_EDIT_TOOL::Init()
wxASSERT_MSG( drawingTools, "eeshema.InteractiveDrawing tool is not available" );
auto sheetTool = [ this ] ( const SELECTION& aSel ) {
auto sheetTool =
[ this ] ( const SELECTION& aSel )
{
return ( m_frame->IsCurrentTool( EE_ACTIONS::drawSheet ) );
};
auto anyTextTool = [ 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 ) {
auto duplicateCondition =
[] ( const SELECTION& aSel )
{
if( SCH_LINE_WIRE_BUS_TOOL::IsDrawingLineWireOrBus( aSel ) )
return false;
return true;
};
auto orientCondition = [] ( const SELECTION& aSel ) {
auto orientCondition =
[] ( const SELECTION& aSel )
{
if( aSel.Empty() )
return false;
@ -179,47 +187,42 @@ bool SCH_EDIT_TOOL::Init()
}
};
auto propertiesCondition = []( const SELECTION& aSel ) {
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;
auto item = static_cast<EDA_ITEM*>( aSel.Front() );
EDA_ITEM* 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_COMPONENT_T:
case SCH_SHEET_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;
}
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();
} );
// Only graphic lines support properties in the file format
return true;
}
default:
return true;
return false;
}
};
@ -1231,7 +1234,10 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::EditableItems );
if( selection.Empty() )
{
m_toolMgr->RunAction( ACTIONS::pageSettings );
return 0;
}
SCH_ITEM* item = (SCH_ITEM*) selection.Front();

View File

@ -123,14 +123,18 @@ bool EDIT_TOOL::Init()
m_selectionTool = static_cast<SELECTION_TOOL*>( m_toolMgr->FindTool( "pcbnew.InteractiveSelection" ) );
wxASSERT_MSG( m_selectionTool, "pcbnew.InteractiveSelection tool is not available" );
auto editingModuleCondition = [ this ] ( const SELECTION& aSelection ) {
auto editingModuleCondition =
[ this ] ( const SELECTION& aSelection )
{
return m_editModules;
};
auto singleModuleCondition = SELECTION_CONDITIONS::OnlyType( PCB_MODULE_T )
&& SELECTION_CONDITIONS::Count( 1 );
auto noActiveToolCondition = [ this ] ( const SELECTION& aSelection ) {
auto noActiveToolCondition =
[ this ] ( const SELECTION& aSelection )
{
return frame()->ToolStackIsEmpty();
};
@ -146,7 +150,7 @@ bool EDIT_TOOL::Init()
menu.AddItem( PCB_ACTIONS::rotateCw, SELECTION_CONDITIONS::NotEmpty );
menu.AddItem( PCB_ACTIONS::flip, 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 ) );
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 );
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
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.Front() );