void SCH_EDIT_FRAME::DeleteItem( SCH_ITEM* aItem, bool aAppend ) { wxCHECK_RET( aItem != NULL, wxT( "Cannot delete invalid item." ) ); wxCHECK_RET( !( aItem->GetFlags() & STRUCT_DELETED ), wxT( "Cannot delete item that is already deleted." ) ); // Here, aItem is not null. SCH_SCREEN* screen = GetScreen(); if( aItem->Type() == SCH_SHEET_PIN_T ) { // This item is attached to a node, and is not accessible by the global list directly. SCH_SHEET* sheet = (SCH_SHEET*) aItem->GetParent(); wxCHECK_RET( (sheet != NULL) && (sheet->Type() == SCH_SHEET_T), wxT( "Sheet label has invalid parent item." ) ); SaveCopyInUndoList( (SCH_ITEM*) sheet, UR_CHANGED, aAppend ); sheet->RemovePin( (SCH_SHEET_PIN*) aItem ); m_canvas->RefreshDrawingRect( sheet->GetBoundingBox() ); } else { PICKED_ITEMS_LIST itemsList; ITEM_PICKER picker( aItem, UR_DELETED ); aItem->SetFlags( STRUCT_DELETED ); itemsList.PushItem( picker ); screen->Remove( aItem ); if( aItem->IsConnectable() && aItem->Type() != SCH_JUNCTION_T ) { std::vector< wxPoint > pts; aItem->GetConnectionPoints( pts ); for( auto point : pts ) { SCH_ITEM* junction; if( !screen->IsJunctionNeeded( point ) && ( junction = screen->GetItem( point, 0, SCH_JUNCTION_T ) ) ) { ITEM_PICKER picker_juction( junction, UR_DELETED ); junction->SetFlags( STRUCT_DELETED ); itemsList.PushItem( picker_juction ); screen->Remove( junction ); } } } SaveCopyInUndoList( itemsList, UR_DELETED, aAppend ); m_canvas->RefreshDrawingRect( aItem->GetBoundingBox() ); } }
void SCH_EDIT_FRAME::DeleteItem( SCH_ITEM* aItem ) { wxCHECK_RET( aItem != NULL, wxT( "Cannot delete invalid item." ) ); // Here, aItem is not null. SCH_SCREEN* screen = GetScreen(); if( aItem->Type() == SCH_SHEET_PIN_T ) { // This iten is attached to a node, and is not accessible by the global list directly. SCH_SHEET* sheet = (SCH_SHEET*) aItem->GetParent(); wxCHECK_RET( (sheet != NULL) && (sheet->Type() == SCH_SHEET_T), wxT( "Sheet label has invalid parent item." ) ); SaveCopyInUndoList( (SCH_ITEM*) sheet, UR_CHANGED ); sheet->RemovePin( (SCH_SHEET_PIN*) aItem ); m_canvas->RefreshDrawingRect( sheet->GetBoundingBox() ); } else { screen->Remove( aItem ); SaveCopyInUndoList( aItem, UR_DELETED ); m_canvas->RefreshDrawingRect( aItem->GetBoundingBox() ); } }
/** * Function DeleteItemsInList * delete schematic items in aItemsList * deleted items are put in undo list */ void DeleteItemsInList( EDA_DRAW_PANEL* panel, PICKED_ITEMS_LIST& aItemsList ) { SCH_SCREEN* screen = (SCH_SCREEN*) panel->GetScreen(); SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) panel->GetParent(); PICKED_ITEMS_LIST itemsList; for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) { SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii ); ITEM_PICKER itemWrapper( item, UR_DELETED ); if( item->Type() == SCH_SHEET_PIN_T ) { /* this item is depending on a sheet, and is not in global list */ wxMessageBox( wxT( "DeleteItemsInList() err: unexpected SCH_SHEET_PIN_T" ) ); } else { screen->Remove( item ); /* Unlink the structure */ itemsList.PushItem( itemWrapper ); } } frame->SaveCopyInUndoList( itemsList, UR_DELETED ); }
void SCH_EDIT_FRAME::DeleteCurrentSegment( wxDC* DC ) { SCH_SCREEN* screen = GetScreen(); SetRepeatItem( NULL ); if( ( screen->GetCurItem() == NULL ) || !screen->GetCurItem()->IsNew() ) return; DrawSegment( m_canvas, DC, wxDefaultPosition, false ); screen->Remove( screen->GetCurItem() ); m_canvas->SetMouseCaptureCallback( NULL ); screen->SetCurItem( NULL ); }
// Complete sheet move. static void ExitSheet( EDA_DRAW_PANEL* aPanel, wxDC* aDC ) { SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen(); SCH_ITEM* item = screen->GetCurItem(); SCH_EDIT_FRAME* parent = (SCH_EDIT_FRAME*) aPanel->GetParent(); if( (item == NULL) || (item->Type() != SCH_SHEET_T) || (parent == NULL) ) return; parent->SetRepeatItem( NULL ); item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode ); if( item->IsNew() ) { delete item; } else if( item->IsMoving() || item->IsResized() ) { screen->Remove( item ); delete item; item = parent->GetUndoItem(); wxCHECK_RET( item != NULL, wxT( "Cannot restore undefined last sheet item." ) ); screen->Append( item ); // the owner of item is no more parent, this is the draw list of screen: parent->SetUndoItem( NULL ); item->Draw( aPanel, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); item->ClearFlags(); } else { item->ClearFlags(); } screen->SetCurItem( NULL ); }
bool SCH_EDIT_FRAME::AppendOneEEProject() { SCH_SCREEN* screen; wxString FullFileName; wxString msg; screen = GetScreen(); if( !screen ) { wxLogError( wxT("Document not ready, cannot import") ); return false; } // open file chooser dialog wxFileDialog dlg( this, _( "Import Schematic" ), wxGetCwd(), wxEmptyString, SchematicFileWildcard, wxFD_OPEN | wxFD_FILE_MUST_EXIST ); if( dlg.ShowModal() == wxID_CANCEL ) return false; FullFileName = dlg.GetPath(); wxFileName fn = FullFileName; if( fn.IsRelative() ) { fn.MakeAbsolute(); FullFileName = fn.GetFullPath(); } LoadCacheLibrary( FullFileName ); wxLogDebug( wxT( "Importing schematic " ) + FullFileName ); // load the project bool success = LoadOneEEFile( screen, FullFileName, true ); if( success ) { // load sub-sheets EDA_ITEM* bs = screen->GetDrawItems(); while( bs ) { // do not append hierarchical sheets if( bs->Type() == SCH_SHEET_T ) { screen->Remove( (SCH_SHEET*) bs ); } // clear annotation and init new time stamp for the new components else if( bs->Type() == SCH_COMPONENT_T ) { ( (SCH_COMPONENT*) bs )->SetTimeStamp( GetNewTimeStamp() ); ( (SCH_COMPONENT*) bs )->ClearAnnotation( NULL ); // Clear flags, which are set by these previous modifications: bs->ClearFlags(); } bs = bs->Next(); } } // redraw base screen (ROOT) if necessary GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId ); Zoom_Automatique( false ); SetSheetNumberAndCount(); m_canvas->Refresh( true ); return success; }
/* * OnConvertTextType is a command event handler to change a text type to an other one. * The new text, label, hierarchical label, or global label is created from the old text * The old text is deleted. * A tricky case is when the 'old" text is being edited (i.e. moving) * because we must create a new text, and prepare the undo/redo command data for this * change and the current move/edit command */ void SCH_EDIT_FRAME::OnConvertTextType( wxCommandEvent& aEvent ) { SCH_SCREEN* screen = GetScreen(); SCH_TEXT* text = (SCH_TEXT*) screen->GetCurItem(); wxCHECK_RET( (text != NULL) && text->CanIncrementLabel(), wxT( "Cannot convert text type." ) ); KICAD_T type; switch( aEvent.GetId() ) { case ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_LABEL: type = SCH_LABEL_T; break; case ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_GLABEL: type = SCH_GLOBAL_LABEL_T; break; case ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_HLABEL: type = SCH_HIERARCHICAL_LABEL_T; break; case ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_COMMENT: type = SCH_TEXT_T; break; default: wxFAIL_MSG( wxString::Format( wxT( "Invalid text type command ID %d." ), aEvent.GetId() ) ); return; } if( text->Type() == type ) return; SCH_TEXT* newtext; const wxPoint &position = text->GetPosition(); const wxString &txt = text->GetText(); switch( type ) { case SCH_LABEL_T: newtext = new SCH_LABEL( position, txt ); break; case SCH_GLOBAL_LABEL_T: newtext = new SCH_GLOBALLABEL( position, txt ); break; case SCH_HIERARCHICAL_LABEL_T: newtext = new SCH_HIERLABEL( position, txt ); break; case SCH_TEXT_T: newtext = new SCH_TEXT( position, txt ); break; default: newtext = NULL; wxFAIL_MSG( wxString::Format( wxT( "Cannot convert text type to %d" ), type ) ); return; } /* Copy the old text item settings to the new one. Justifications are not copied because * they are not used in labels. Justifications will be set to default value in the new * text item type. */ newtext->SetFlags( text->GetFlags() ); newtext->SetShape( text->GetShape() ); newtext->SetOrientation( text->GetOrientation() ); newtext->SetSize( text->GetSize() ); newtext->SetThickness( text->GetThickness() ); newtext->SetItalic( text->IsItalic() ); newtext->SetBold( text->IsBold() ); /* Save the new text in undo list if the old text was not itself a "new created text" * In this case, the old text is already in undo list as a deleted item. * Of course if the old text was a "new created text" the new text will be * put in undo list later, at the end of the current command (if not aborted) */ INSTALL_UNBUFFERED_DC( dc, m_canvas ); m_canvas->CrossHairOff( &dc ); // Erase schematic cursor text->Draw( m_canvas, &dc, wxPoint( 0, 0 ), g_XorMode ); // For an exiting item (i.e. already in list): // replace the existing item by the new text in list for( SCH_ITEM* item = screen->GetDrawItems(); item != NULL; item = item->Next() ) { if( item == text ) { screen->Remove( text ); screen->Append( newtext ); break; } } SetRepeatItem( NULL ); OnModify(); newtext->Draw( m_canvas, &dc, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); m_canvas->CrossHairOn( &dc ); // redraw schematic cursor // if the old item is the current schematic item, replace it by the new text: if( screen->GetCurItem() == text ) screen->SetCurItem( newtext ); if( text->IsNew() ) { // if the previous text is new, no undo command to prepare here // just delete this previous text. delete text; return; } // previous text is not new and we replace text by new text. // So this is equivalent to delete text and add newtext // If text if being currently edited (i.e. moved) // we also save the initial copy of text, and prepare undo command for new text modifications. // we must save it as modified text,if it is currently edited, then save as deleted text, // and replace text with newtext PICKED_ITEMS_LIST pickList; ITEM_PICKER picker( text, UR_CHANGED ); if( text->GetFlags() ) { // text is being edited, save initial text for undo command picker.SetLink( GetUndoItem() ); pickList.PushItem( picker ); // the owner of undoItem is no more "this", it is now "picker": SetUndoItem( NULL ); // save current newtext copy for undo/abort current command SetUndoItem( newtext ); } // Prepare undo command for delete old text picker.SetStatus( UR_DELETED ); picker.SetLink( NULL ); pickList.PushItem( picker ); // Prepare undo command for new text picker.SetStatus( UR_NEW ); picker.SetItem(newtext); pickList.PushItem( picker ); SaveCopyInUndoList( pickList, UR_UNSPECIFIED ); }