Set IS_NEW flag on new images. And a bunch of cleanup of dead code.

This commit is contained in:
Jeff Young 2019-05-03 09:48:53 +01:00
parent 21b315f2af
commit bcdc3ad90a
11 changed files with 56 additions and 208 deletions

View File

@ -89,10 +89,7 @@ bool DIALOG_SCH_EDIT_SHEET_PIN::TransferDataToWindow()
bool DIALOG_SCH_EDIT_SHEET_PIN::TransferDataFromWindow()
{
if( !m_sheetPin->IsNew() )
{
m_frame->SaveCopyInUndoList( (SCH_ITEM*) m_sheetPin->GetParent(), UR_CHANGED );
m_frame->GetScreen()->SetCurItem( nullptr );
}
m_sheetPin->SetText( m_textName->GetValue() );
m_sheetPin->SetTextSize( wxSize( m_textWidth.GetValue(), m_textHeight.GetValue() ) );

View File

@ -37,13 +37,13 @@ void SetSchItemParent( SCH_ITEM* Struct, SCH_SCREEN* Screen );
* Routine to create a new copy of given struct.
* The new object is not put in draw list (not linked)
*
* @param aDrawStruct = the SCH_ITEM to duplicate
* @param aClone (default = false)
* @param aItem = the SCH_ITEM to duplicate
* @param doClone (default = false)
* if true duplicate also some parameters that must be unique
* (timestamp and sheet name)
* aClone must be false. use true only is undo/redo duplications
*/
SCH_ITEM* DuplicateStruct( SCH_ITEM* aDrawStruct, bool aClone = false );
SCH_ITEM* DuplicateItem( SCH_ITEM* aItem, bool doClone = false );
#endif /* LIST_OPERATIONS_H */

View File

@ -128,23 +128,6 @@ void SCH_EDIT_FRAME::CheckConnections( SELECTION& aSelection, bool aUndoAppend )
}
void SCH_EDIT_FRAME::DeleteItemsInList( PICKED_ITEMS_LIST& aItemsList, bool aAppend )
{
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
{
SCH_ITEM* item = static_cast<SCH_ITEM*>( aItemsList.GetPickedItem( ii ) );
if( item->GetEditFlags() & STRUCT_DELETED )
continue;
DeleteItem( item, aAppend );
aAppend = true;
}
GetScreen()->ClearDrawingState();
}
void SCH_EDIT_FRAME::DeleteItem( SCH_ITEM* aItem, bool aAppend )
{
wxCHECK_RET( aItem != NULL, wxT( "Cannot delete invalid item." ) );
@ -187,105 +170,34 @@ void SCH_EDIT_FRAME::DeleteItem( SCH_ITEM* aItem, bool aAppend )
}
void SCH_EDIT_FRAME::DuplicateItemsInList( SCH_SCREEN* screen, PICKED_ITEMS_LIST& aItemsList,
const wxPoint& aMoveVector )
SCH_ITEM* DuplicateItem( SCH_ITEM* aItem, bool doClone )
{
SCH_ITEM* olditem;
SCH_ITEM* newitem;
wxCHECK_MSG( aItem != NULL, NULL, "Cannot duplicate NULL schematic item! Bad programmer." );
if( aItemsList.GetCount() == 0 )
return;
SCH_ITEM* newItem = (SCH_ITEM*) aItem->Clone();
// Keep track of existing sheet paths. Duplicate block can modify this list
bool hasSheetCopied = false;
SCH_SHEET_LIST initial_sheetpathList( g_RootSheet );
if( doClone )
newItem->SetTimeStamp( aItem->GetTimeStamp() );
newItem->ClearFlags( SELECTED | HIGHLIGHTED | BRIGHTENED );
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
if( newItem->Type() == SCH_COMPONENT_T )
{
olditem = static_cast<SCH_ITEM*>( aItemsList.GetPickedItem( ii ) );
newitem = DuplicateStruct( olditem );
newitem->Move( aMoveVector );
aItemsList.SetPickedItem( newitem, ii );
aItemsList.SetPickedItemStatus( UR_NEW, ii );
switch( newitem->Type() )
{
case SCH_JUNCTION_T:
case SCH_LINE_T:
case SCH_BUS_BUS_ENTRY_T:
case SCH_BUS_WIRE_ENTRY_T:
case SCH_TEXT_T:
case SCH_LABEL_T:
case SCH_GLOBAL_LABEL_T:
case SCH_HIER_LABEL_T:
case SCH_SHEET_PIN_T:
case SCH_MARKER_T:
case SCH_NO_CONNECT_T:
default:
break;
case SCH_SHEET_T:
{
SCH_SHEET* sheet = (SCH_SHEET*) newitem;
// Duplicate sheet names and sheet time stamps are not valid. Use a time stamp
// based sheet name and update the time stamp for each sheet in the block.
timestamp_t timeStamp = GetNewTimeStamp();
sheet->SetName( wxString::Format( wxT( "sheet%8.8lX" ), (unsigned long)timeStamp ) );
sheet->SetTimeStamp( timeStamp );
hasSheetCopied = true;
break;
}
case SCH_COMPONENT_T:
( (SCH_COMPONENT*) newitem )->SetTimeStamp( GetNewTimeStamp() );
( (SCH_COMPONENT*) newitem )->ClearAnnotation( NULL );
break;
}
SetSchItemParent( newitem, screen );
AddToScreen( newitem );
}
if( hasSheetCopied )
{
// We clear annotation of new sheet paths.
// Annotation of new components added in current sheet is already cleared.
SCH_SCREENS screensList( g_RootSheet );
screensList.ClearAnnotationOfNewSheetPaths( initial_sheetpathList );
}
}
SCH_ITEM* DuplicateStruct( SCH_ITEM* aDrawStruct, bool aClone )
{
wxCHECK_MSG( aDrawStruct != NULL, NULL,
wxT( "Cannot duplicate NULL schematic item! Bad programmer." ) );
SCH_ITEM* NewDrawStruct = (SCH_ITEM*) aDrawStruct->Clone();
if( aClone )
NewDrawStruct->SetTimeStamp( aDrawStruct->GetTimeStamp() );
NewDrawStruct->ClearFlags( SELECTED | HIGHLIGHTED | BRIGHTENED );
if( NewDrawStruct->Type() == SCH_COMPONENT_T )
{
SCH_PINS& pins = static_cast<SCH_COMPONENT*>( NewDrawStruct )->GetPins();
for( SCH_PIN& pin : pins )
for( SCH_PIN& pin : static_cast<SCH_COMPONENT*>( newItem )->GetPins() )
pin.ClearFlags( SELECTED | HIGHLIGHTED | BRIGHTENED );
std::vector<SCH_FIELD*> fields;
static_cast<SCH_COMPONENT*>( NewDrawStruct )->GetFields( fields, false );
static_cast<SCH_COMPONENT*>( newItem )->GetFields( fields, false );
for( SCH_FIELD* field : fields )
field->ClearFlags( SELECTED | HIGHLIGHTED | BRIGHTENED );
}
// JEY TODO: sheets and sheet pins?
return NewDrawStruct;
if( newItem->Type() == SCH_SHEET_T )
{
for( SCH_SHEET_PIN& pin : static_cast<SCH_SHEET*>( newItem )->GetPins() )
pin.ClearFlags( SELECTED | HIGHLIGHTED | BRIGHTENED );
}
return newItem;
}

View File

@ -1213,9 +1213,7 @@ void SCH_EDIT_FRAME::AddItemToScreenAndUndoList( SCH_ITEM* aItem, bool aUndoAppe
{
if( !EditSheet( (SCH_SHEET*)aItem, g_CurrentSheet, &doClearAnnotation ) )
{
screen->SetCurItem( NULL );
delete aItem;
return;
}
@ -1269,10 +1267,6 @@ void SCH_EDIT_FRAME::AddItemToScreenAndUndoList( SCH_ITEM* aItem, bool aUndoAppe
aItem->ClearFlags( aItem->GetEditFlags() );
screen->SetModify();
screen->SetCurItem( NULL );
m_canvas->SetMouseCapture( NULL, NULL );
m_canvas->EndMouseCapture();
RefreshItem( aItem );
if( !aItem->IsMoving() && aItem->IsConnectable() )

View File

@ -970,15 +970,6 @@ public:
*/
void DeleteItem( SCH_ITEM* aItem, bool aAppend = false );
/**
* Removes all items (and unused junctions that connect to them) and saves
* each in the undo list
*
* @param aItemsList The list of items to delete
* @param aAppend True if we are updating a previous commit
*/
void DeleteItemsInList( PICKED_ITEMS_LIST& aItemsList, bool aAppend = false );
/**
* Removes a given junction and heals any wire segments under the junction
*
@ -1267,9 +1258,6 @@ public:
void ShowChangedLanguage() override;
void DuplicateItemsInList( SCH_SCREEN* screen, PICKED_ITEMS_LIST& aItemsList,
const wxPoint& aMoveVector );
virtual void SetScreen( BASE_SCREEN* aScreen ) override;
virtual const BOX2I GetDocumentExtents() const override;

View File

@ -315,8 +315,7 @@ void SCH_FIELD::Place( SCH_EDIT_FRAME* frame, wxDC* DC )
// save old cmp in undo list
frame->SaveUndoItemInUndoList( component );
ClearFlags();
frame->GetScreen()->SetCurItem( NULL );
ClearFlags( GetEditFlags() );
frame->OnModify();
}

View File

@ -129,7 +129,7 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( SCH_ITEM* aItem,
switch( aCommandType )
{
case UR_CHANGED: /* Create a copy of item */
itemWrapper.SetLink( DuplicateStruct( aItem, true ) );
itemWrapper.SetLink( DuplicateItem( aItem, true ) );
commandToUndo->PushItem( itemWrapper );
break;
@ -218,7 +218,7 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList,
* If this link is not null, the copy is already done
*/
if( commandToUndo->GetPickedItemLink( ii ) == NULL )
commandToUndo->SetPickedItemLink( DuplicateStruct( item, true ), ii );
commandToUndo->SetPickedItemLink( DuplicateItem( item, true ), ii );
wxASSERT( commandToUndo->GetPickedItemLink( ii ) );
break;

View File

@ -282,15 +282,14 @@ int SCH_DRAWING_TOOL::doPlaceComponent( SCH_COMPONENT* aComponent, SCHLIB_FILTER
if( aComponent )
{
m_toolMgr->RunAction( SCH_ACTIONS::clearSelection, true );
getModel<SCH_SCREEN>()->SetCurItem( nullptr );
m_view->ClearPreview();
delete aComponent;
aComponent = nullptr;
}
else
break;
if( evt->IsActivate() ) // now finish unconditionally
if( !evt->IsActivate() )
continue;
}
break;
}
else if( evt->IsClick( BUT_LEFT ) )
@ -317,6 +316,7 @@ int SCH_DRAWING_TOOL::doPlaceComponent( SCH_COMPONENT* aComponent, SCHLIB_FILTER
continue;
aComponent = new SCH_COMPONENT( *part, g_CurrentSheet, sel, (wxPoint) cursorPos );
aComponent->SetFlags( IS_NEW | IS_MOVED );
// Be sure the link to the corresponding LIB_PART is OK:
aComponent->Resolve( *m_frame->Prj().SchSymbolLibTable() );
@ -324,10 +324,7 @@ int SCH_DRAWING_TOOL::doPlaceComponent( SCH_COMPONENT* aComponent, SCHLIB_FILTER
if( m_frame->GetAutoplaceFields() )
aComponent->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false );
aComponent->SetFlags( IS_NEW | IS_MOVED );
m_frame->SetRepeatItem( aComponent );
m_frame->GetScreen()->SetCurItem( aComponent );
m_view->ClearPreview();
m_view->AddToPreview( aComponent->Clone() );
@ -412,15 +409,14 @@ int SCH_DRAWING_TOOL::PlaceImage( const TOOL_EVENT& aEvent )
if( image )
{
m_toolMgr->RunAction( SCH_ACTIONS::clearSelection, true );
getModel<SCH_SCREEN>()->SetCurItem( nullptr );
m_view->ClearPreview();
delete image;
image = nullptr;
}
else
break;
if( evt->IsActivate() ) // now finish unconditionally
if( !evt->IsActivate() )
continue;
}
break;
}
else if( evt->IsClick( BUT_LEFT ) )
@ -453,9 +449,10 @@ int SCH_DRAWING_TOOL::PlaceImage( const TOOL_EVENT& aEvent )
continue;
}
image->SetFlags( IS_MOVED );
image->SetFlags( IS_NEW | IS_MOVED );
m_frame->SetRepeatItem( image );
m_frame->GetScreen()->SetCurItem( image );
m_view->ClearPreview();
m_view->AddToPreview( image->Clone() );
m_selectionTool->AddItemToSel( image );
@ -572,7 +569,6 @@ int SCH_DRAWING_TOOL::doSingleClickPlace( KICAD_T aType )
m_frame->AddItemToScreenAndUndoList( item );
m_frame->SetRepeatItem( item );
m_frame->GetScreen()->SetCurItem( item );
m_frame->SchematicCleanUp();
m_frame->TestDanglingEnds();
@ -655,15 +651,14 @@ int SCH_DRAWING_TOOL::doTwoClickPlace( KICAD_T aType )
if( item )
{
m_toolMgr->RunAction( SCH_ACTIONS::clearSelection, true );
getModel<SCH_SCREEN>()->SetCurItem( nullptr );
m_view->ClearPreview();
delete item;
item = nullptr;
}
else
break;
if( evt->IsActivate() ) // now finish unconditionally
if( !evt->IsActivate() )
continue;
}
break;
}
else if( evt->IsClick( BUT_LEFT ) )
@ -818,44 +813,41 @@ int SCH_DRAWING_TOOL::doDrawSheet( SCH_SHEET *aSheet )
if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) )
{
m_view->ClearPreview();
m_toolMgr->RunAction( SCH_ACTIONS::clearSelection, true );
m_frame->GetScreen()->SetCurItem( nullptr );
m_view->ClearPreview();
if( m_frame->GetToolId() == ID_POPUP_SCH_RESIZE_SHEET )
{
m_frame->RollbackSchematicFromUndo();
break; // resize sheet is a single-shot command, not a reusable tool
// resize sheet is a single-shot command, when we're done we're done
}
else if( aSheet )
{
delete aSheet;
aSheet = nullptr;
}
else
break;
if( evt->IsActivate() )
break; // exit unconditionally
if( !evt->IsActivate() )
continue;
}
break;
}
else if( evt->IsClick( BUT_LEFT ) || evt->IsAction( &SCH_ACTIONS::finishSheet ) )
{
if( !aSheet && !evt->IsAction( &SCH_ACTIONS::finishSheet ) )
{
aSheet = new SCH_SHEET( (wxPoint) cursorPos );
aSheet->SetFlags( IS_NEW | IS_RESIZED );
aSheet->SetTimeStamp( GetNewTimeStamp() );
aSheet->SetParent( m_frame->GetScreen() );
aSheet->SetScreen( NULL );
sizeSheet( aSheet, cursorPos );
m_frame->SetRepeatItem( nullptr );
m_selectionTool->AddItemToSel( aSheet );
m_view->ClearPreview();
m_view->AddToPreview( aSheet->Clone() );
m_frame->SetRepeatItem( nullptr );
m_frame->GetScreen()->SetCurItem( aSheet );
}
else if( aSheet )
{
@ -865,12 +857,10 @@ int SCH_DRAWING_TOOL::doDrawSheet( SCH_SHEET *aSheet )
{
m_view->Hide( aSheet, false );
m_frame->RefreshItem( aSheet );
m_frame->OnModify();
}
aSheet = nullptr;
m_frame->GetScreen()->SetCurItem( nullptr );
if( m_frame->GetToolId() == ID_POPUP_SCH_RESIZE_SHEET )
break; // resize sheet is a single-shot command; when we're done we're done

View File

@ -1213,7 +1213,7 @@ int SCH_EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
for( unsigned ii = 0; ii < selection.GetSize(); ++ii )
{
SCH_ITEM* oldItem = static_cast<SCH_ITEM*>( selection.GetItem( ii ) );
SCH_ITEM* newItem = DuplicateStruct( oldItem );
SCH_ITEM* newItem = DuplicateItem( oldItem );
newItems.push_back( newItem );
newItem->SetFlags( IS_NEW );
@ -1362,7 +1362,6 @@ int SCH_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent )
m_frame->DeleteItem( item, ii > 0 );
}
m_frame->GetScreen()->SetCurItem( nullptr );
m_frame->SetRepeatItem( nullptr );
m_frame->TestDanglingEnds();

View File

@ -516,10 +516,6 @@ int SCH_LINE_DRAWING_TOOL::doDrawSegments( int aType, SCH_LINE* aSegment )
m_view->ClearPreview();
m_view->ShowPreview( false );
// Clear flags used in edit functions.
screen->ClearDrawingState();
screen->SetCurItem( nullptr );
if( !evt->IsActivate() )
continue;
}
@ -591,8 +587,8 @@ int SCH_LINE_DRAWING_TOOL::doDrawSegments( int aType, SCH_LINE* aSegment )
aSegment->SetFlags( IS_NEW | IS_MOVED );
aSegment->SetStartPoint( cursorPos );
s_wires.PushBack( aSegment );
m_selectionTool->AddItemToSel( aSegment, true /*quiet mode*/ );
screen->SetCurItem( aSegment );
}
}
@ -706,8 +702,8 @@ SCH_LINE* SCH_LINE_DRAWING_TOOL::startSegments( int aType, const wxPoint& aPos )
segment->SetFlags( IS_NEW | IS_MOVED );
s_wires.PushBack( segment );
m_selectionTool->AddItemToSel( segment, true /*quiet mode*/ );
m_frame->GetScreen()->SetCurItem( segment );
// We need 2 segments to go from a given start pin to an end point when the
// horizontal and vertical lines only switch is on.
@ -716,8 +712,8 @@ SCH_LINE* SCH_LINE_DRAWING_TOOL::startSegments( int aType, const wxPoint& aPos )
segment = new SCH_LINE( *segment );
segment->SetFlags( IS_NEW | IS_MOVED );
s_wires.PushBack( segment );
m_selectionTool->AddItemToSel( segment, true /*quiet mode*/ );
m_frame->GetScreen()->SetCurItem( segment );
}
return segment;
@ -878,8 +874,6 @@ void SCH_LINE_DRAWING_TOOL::finishSegments()
m_frame->TestDanglingEnds();
m_frame->GetScreen()->ClearDrawingState();
m_frame->GetScreen()->SetCurItem( nullptr );
m_frame->OnModify();
}

View File

@ -396,7 +396,6 @@ SCH_ITEM* SCH_SELECTION_TOOL::SelectPoint( const VECTOR2I& aWhere, const KICAD_T
if( aSelectionCancelledFlag )
*aSelectionCancelledFlag = true;
m_frame->GetScreen()->SetCurItem( nullptr );
return nullptr;
}
}
@ -571,14 +570,6 @@ bool SCH_SELECTION_TOOL::selectMultiple()
}
}
if( m_frame )
{
if( m_selection.Size() == 1 )
m_frame->GetScreen()->SetCurItem( static_cast<SCH_ITEM*>( m_selection.Front() ) );
else
m_frame->GetScreen()->SetCurItem( nullptr );
}
// Inform other potentially interested tools
if( !m_selection.Empty() )
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
@ -654,10 +645,11 @@ int SCH_SELECTION_TOOL::SelectConnection( const TOOL_EVENT& aEvent )
{
if( item->GetFlags() & CANDIDATE )
select( item );
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
}
if( m_selection.GetSize() > 1 )
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
return 0;
}
@ -871,9 +863,6 @@ void SCH_SELECTION_TOOL::clearSelection()
m_selection.SetIsHover( false );
m_selection.ClearReferencePoint();
if( m_frame )
m_frame->GetScreen()->SetCurItem( nullptr );
// Inform other potentially interested tools
m_toolMgr->ProcessEvent( EVENTS::ClearedEvent );
}
@ -911,20 +900,6 @@ void SCH_SELECTION_TOOL::toggleSelection( SCH_ITEM* aItem, bool aForce )
void SCH_SELECTION_TOOL::select( SCH_ITEM* aItem )
{
highlight( aItem, SELECTED, &m_selection );
if( m_frame )
{
if( m_selection.Size() == 1 )
{
// Set as the current item, so the information about selection is displayed
m_frame->GetScreen()->SetCurItem( aItem );
}
else if( m_selection.Size() == 2 ) // Check only for 2, so it will not be
{ // called for every next selected item
// If multiple items are selected, do not show the information about the selected item
m_frame->GetScreen()->SetCurItem( nullptr );
}
}
}