bool SELECTION_CONDITIONS::sameNetFunc( const SELECTION& aSelection ) { if( aSelection.Empty() ) return false; int netcode = -1; for( int i = 0; i < aSelection.Size(); ++i ) { const BOARD_CONNECTED_ITEM* item = dynamic_cast<const BOARD_CONNECTED_ITEM*>( aSelection.Item<EDA_ITEM>( i ) ); if( !item ) return false; if( netcode < 0 ) { netcode = item->GetNetCode(); if( netcode == NETINFO_LIST::UNCONNECTED ) return false; } else if( netcode != item->GetNetCode() ) { return false; } } return true; }
bool SELECTION_CONDITIONS::hasTypeFunc( const SELECTION& aSelection, KICAD_T aType ) { for( int i = 0; i < aSelection.Size(); ++i ) { if( aSelection.Item<EDA_ITEM>( i )->Type() == aType ) return true; } return false; }
bool POINT_EDITOR::addCornerCondition( const SELECTION& aSelection ) { if( aSelection.Size() != 1 ) return false; BOARD_ITEM* item = aSelection.Item<BOARD_ITEM>( 0 ); // Works only for zones and line segments return item->Type() == PCB_ZONE_AREA_T || ( ( item->Type() == PCB_LINE_T || item->Type() == PCB_MODULE_EDGE_T ) && static_cast<DRAWSEGMENT*>( item )->GetShape() == S_SEGMENT ); }
bool SELECTION_CONDITIONS::OnlyConnectedItems( const SELECTION& aSelection ) { if( aSelection.Empty() ) return false; for( int i = 0; i < aSelection.Size(); ++i ) { KICAD_T type = aSelection.Item<EDA_ITEM>( i )->Type(); if( type != PCB_PAD_T && type != PCB_VIA_T && type != PCB_TRACE_T && type != PCB_ZONE_T ) return false; } return true; }
wxPoint EDIT_TOOL::getModificationPoint( const SELECTION& aSelection ) { if( aSelection.Size() == 1 ) { return aSelection.Item<BOARD_ITEM>( 0 )->GetPosition() - m_offset; } else { // If EDIT_TOOL is not currently active then it means that the cursor position is not // updated, so we have to fetch the latest value if( m_toolMgr->GetCurrentToolId() != m_toolId ) m_cursor = getViewControls()->GetCursorPosition(); return wxPoint( m_cursor.x, m_cursor.y ); } }
bool SELECTION_CONDITIONS::sameLayerFunc( const SELECTION& aSelection ) { if( aSelection.Empty() ) return false; LSET layerSet; layerSet.set(); for( int i = 0; i < aSelection.Size(); ++i ) { const BOARD_ITEM* item = dynamic_cast<const BOARD_ITEM*>( aSelection.Item<EDA_ITEM>( i ) ); if( !item ) return false; layerSet &= item->GetLayerSet(); if( !layerSet.any() ) // there are no common layers left return false; } return true; }
bool SELECTION_CONDITIONS::onlyTypesFunc( const SELECTION& aSelection, const std::vector<KICAD_T>& aTypes ) { if( aSelection.Empty() ) return false; for( int i = 0; i < aSelection.Size(); ++i ) { bool valid = false; for( std::vector<KICAD_T>::const_iterator it = aTypes.begin(); it != aTypes.end(); ++it ) { if( aSelection.Item<EDA_ITEM>( i )->Type() == *it ) { valid = true; break; } } if( !valid ) return false; } return true; }
bool SELECTION_CONDITIONS::lessThanFunc( const SELECTION& aSelection, int aNumber ) { return aSelection.Size() < aNumber; }
bool SELECTION_CONDITIONS::countFunc( const SELECTION& aSelection, int aNumber ) { return aSelection.Size() == aNumber; }
int PCB_EDITOR_CONTROL::ZoneMerge( const TOOL_EVENT& aEvent ) { SELECTION selection = m_toolMgr->GetTool<SELECTION_TOOL>()->GetSelection(); BOARD* board = getModel<BOARD>(); RN_DATA* ratsnest = board->GetRatsnest(); KIGFX::VIEW* view = getView(); if( selection.Size() < 2 ) return 0; PICKED_ITEMS_LIST changes; int netcode = -1; // Loop through all combinations for( int ia1 = 0; ia1 < selection.Size() - 1; ++ia1 ) { ZONE_CONTAINER* curr_area = dynamic_cast<ZONE_CONTAINER*>( selection.Item<EDA_ITEM>( ia1 ) ); if( !curr_area ) continue; netcode = curr_area->GetNetCode(); EDA_RECT b1 = curr_area->Outline()->GetBoundingBox(); bool mod_ia1 = false; for( int ia2 = selection.Size() - 1; ia2 > ia1; --ia2 ) { ZONE_CONTAINER* area2 = dynamic_cast<ZONE_CONTAINER*>( selection.Item<EDA_ITEM>( ia2 ) ); if( !area2 ) continue; if( area2->GetNetCode() != netcode ) continue; if( curr_area->GetPriority() != area2->GetPriority() ) continue; if( curr_area->GetIsKeepout() != area2->GetIsKeepout() ) continue; if( curr_area->GetLayer() != area2->GetLayer() ) continue; EDA_RECT b2 = area2->Outline()->GetBoundingBox(); if( b1.Intersects( b2 ) ) { EDA_ITEM* backup = curr_area->Clone(); bool ret = board->TestAreaIntersection( curr_area, area2 ); if( ret && board->CombineAreas( &changes, curr_area, area2 ) ) { mod_ia1 = true; selection.items.RemovePicker( ia2 ); ITEM_PICKER picker( curr_area, UR_CHANGED ); picker.SetLink( backup ); changes.PushItem( picker ); } else { delete backup; } } } if( mod_ia1 ) --ia1; // if modified, we need to check it again } m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); m_frame->SaveCopyInUndoList( changes, UR_UNSPECIFIED ); for( unsigned i = 0; i < changes.GetCount(); ++i ) { ITEM_PICKER picker = changes.GetItemWrapper( i ); BOARD_ITEM* item = static_cast<BOARD_ITEM*>( picker.GetItem() ); if( picker.GetStatus() == UR_DELETED ) { view->Remove( item ); ratsnest->Remove( item ); } else if( picker.GetStatus() == UR_CHANGED ) { item->ViewUpdate( KIGFX::VIEW_ITEM::ALL ); m_toolMgr->RunAction( COMMON_ACTIONS::selectItem, true, item ); } } return 0; }