void SCH_EDIT_FRAME::MoveItem( SCH_ITEM* aItem, wxDC* aDC ) { wxCHECK_RET( aItem != NULL, wxT( "Cannot move invalid schematic item" ) ); SetRepeatItem( NULL ); if( !aItem->IsNew() ) { if( (aItem->Type() == SCH_SHEET_PIN_T) || (aItem->Type() == SCH_FIELD_T) ) SetUndoItem( (SCH_ITEM*) aItem->GetParent() ); else SetUndoItem( aItem ); } aItem->SetFlags( IS_MOVED ); #ifdef USE_WX_OVERLAY this->Refresh(); this->Update(); #endif m_canvas->CrossHairOff( aDC ); if( aItem->Type() != SCH_SHEET_PIN_T ) SetCrossHairPosition( aItem->GetPosition() ); m_canvas->MoveCursorToCrossHair(); OnModify(); m_canvas->SetMouseCapture( moveItem, abortMoveItem ); GetScreen()->SetCurItem( aItem ); moveItem( m_canvas, aDC, wxDefaultPosition, true ); m_canvas->CrossHairOn( aDC ); }
void SCH_EDIT_FRAME::OnFindReplace( wxFindDialogEvent& aEvent ) { SCH_FIND_COLLECTOR_DATA data; bool warpCursor = !( aEvent.GetFlags() & FR_NO_WARP_CURSOR ); SCH_ITEM* item = (SCH_ITEM*) m_foundItems.GetItem( data ); wxCHECK_RET( item != NULL, wxT( "Invalid replace item in find collector list." ) ); wxLogTrace( traceFindReplace, wxT( "Replacing %s with %s in item %s" ), GetChars( aEvent.GetFindString() ), GetChars( aEvent.GetReplaceString() ), GetChars( m_foundItems.GetText() ) ); SCH_ITEM* undoItem = data.GetParent(); if( undoItem == NULL ) undoItem = item; SetUndoItem( undoItem ); if( m_foundItems.ReplaceItem() ) { OnModify(); SaveUndoItemInUndoList( undoItem ); RedrawScreen( data.GetPosition(), warpCursor ); } OnFindSchematicItem( aEvent ); if( aEvent.GetEventType() == wxEVT_COMMAND_FIND_REPLACE_ALL ) { while( ( item = (SCH_ITEM*) m_foundItems.GetItem( data ) ) != NULL ) { wxLogTrace( traceFindReplace, wxT( "Replacing %s with %s in item %s" ), GetChars( aEvent.GetFindString() ), GetChars( aEvent.GetReplaceString() ), GetChars( m_foundItems.GetText() ) ); SCH_ITEM* undoItem = data.GetParent(); // Don't save child items in undo list. if( undoItem == NULL ) undoItem = item; SetUndoItem( undoItem ); if( m_foundItems.ReplaceItem() ) { OnModify(); SaveUndoItemInUndoList( undoItem ); RedrawScreen( data.GetPosition(), warpCursor ); } OnFindSchematicItem( aEvent ); } } }
void SCH_EDIT_FRAME::PrepareMoveItem( SCH_ITEM* aItem, wxDC* aDC ) { wxCHECK_RET( aItem != NULL, wxT( "Cannot move invalid schematic item" ) ); SetRepeatItem( NULL ); if( !aItem->IsNew() ) { if( (aItem->Type() == SCH_SHEET_PIN_T) || (aItem->Type() == SCH_FIELD_T) ) SetUndoItem( (SCH_ITEM*) aItem->GetParent() ); else SetUndoItem( aItem ); } if( aItem->Type() == SCH_FIELD_T && aItem->GetParent()->Type() == SCH_COMPONENT_T ) { // Now that we're moving a field, they're no longer autoplaced. SCH_COMPONENT *parent = static_cast<SCH_COMPONENT*>( aItem->GetParent() ); parent->ClearFieldsAutoplaced(); } aItem->SetFlags( IS_MOVED ); // For some items, moving the cursor to anchor is not good // (for instance large hierarchical sheets od componants can have // the anchor position outside the canvas) // these items return IsMovableFromAnchorPoint() == false // For these items, do not wrap the cursor if( aItem->IsMovableFromAnchorPoint() ) { SetCrossHairPosition( aItem->GetPosition() ); m_canvas->MoveCursorToCrossHair(); aItem->SetStoredPos( wxPoint( 0,0 ) ); } else { // Round the point under the cursor to a multiple of the grid wxPoint cursorpos = GetCrossHairPosition() - aItem->GetPosition(); wxPoint gridsize = GetScreen()->GetGridSize(); cursorpos.x = ( cursorpos.x / gridsize.x ) * gridsize.x; cursorpos.y = ( cursorpos.y / gridsize.y ) * gridsize.y; aItem->SetStoredPos( cursorpos ); } OnModify(); GetScreen()->SetCurItem( aItem ); m_canvas->SetMouseCapture( moveItemWithMouseCursor, abortMoveItem ); m_canvas->Refresh(); }
void SCH_EDIT_FRAME::OrientComponent( COMPONENT_ORIENTATION_T aOrientation ) { SCH_SCREEN* screen = GetScreen(); SCH_ITEM* item = screen->GetCurItem(); SCH_COMPONENT* component = (SCH_COMPONENT*) item; GetCanvas()->MoveCursorToCrossHair(); if( item->GetFlags() == 0 ) SetUndoItem( item ); component->SetOrientation( aOrientation ); m_canvas->CrossHairOn( ); if( item->GetFlags() == 0 ) { addCurrentItemToScreen(); SchematicCleanUp(); } TestDanglingEnds(); RefreshItem( item ); if( item->GetFlags() == 0 ) OnModify(); }
void SCH_EDIT_FRAME::OrientComponent( COMPONENT_ORIENTATION_T aOrientation ) { SCH_SCREEN* screen = GetScreen(); SCH_ITEM* item = screen->GetCurItem(); wxCHECK_RET( item != NULL && item->Type() == SCH_COMPONENT_T, wxT( "Cannot change orientation of invalid schematic item." ) ); SCH_COMPONENT* component = (SCH_COMPONENT*) item; m_canvas->MoveCursorToCrossHair(); if( item->GetFlags() == 0 ) SetUndoItem( item ); INSTALL_UNBUFFERED_DC( dc, m_canvas ); component->SetOrientation( aOrientation ); m_canvas->CrossHairOn( &dc ); if( item->GetFlags() == 0 ) { addCurrentItemToList(); SchematicCleanUp( true ); } if( GetScreen()->TestDanglingEnds() ) m_canvas->Refresh(); OnModify(); }
void SCH_EDIT_FRAME::ReSizeSheet( SCH_SHEET* aSheet, wxDC* aDC ) { if( aSheet == NULL || aSheet->IsNew() ) return; wxCHECK_RET( aSheet->Type() == SCH_SHEET_T, wxString::Format( wxT( "Cannot perform sheet resize on %s object." ), GetChars( aSheet->GetClass() ) ) ); m_canvas->CrossHairOff( aDC ); SetCrossHairPosition( aSheet->GetResizePosition() ); m_canvas->MoveCursorToCrossHair(); m_canvas->CrossHairOn( aDC ); SetUndoItem( aSheet ); aSheet->SetFlags( IS_RESIZED ); m_canvas->SetMouseCapture( resizeSheetWithMouseCursor, ExitSheet ); m_canvas->CallMouseCapture( aDC, wxDefaultPosition, true ); if( aSheet->IsNew() ) // not already in edit, save a copy for undo/redo SetUndoItem( aSheet ); }
void SCH_EDIT_FRAME::PrepareMoveItem( SCH_ITEM* aItem, wxDC* aDC ) { wxCHECK_RET( aItem != NULL, wxT( "Cannot move invalid schematic item" ) ); SetRepeatItem( NULL ); if( !aItem->IsNew() ) { if( (aItem->Type() == SCH_SHEET_PIN_T) || (aItem->Type() == SCH_FIELD_T) ) SetUndoItem( (SCH_ITEM*) aItem->GetParent() ); else SetUndoItem( aItem ); } aItem->SetFlags( IS_MOVED ); // For some items, moving the cursor to anchor is not good // (for instance large hierarchical sheets od componants can have // the anchor position outside the canvas) // these items return IsMovableFromAnchorPoint() == false // For these items, do not wrap the cursor if( aItem->IsMovableFromAnchorPoint() ) { SetCrossHairPosition( aItem->GetPosition() ); m_canvas->MoveCursorToCrossHair(); aItem->SetStoredPos( wxPoint( 0,0 ) ); } else aItem->SetStoredPos( GetCrossHairPosition() - aItem->GetPosition() ); OnModify(); m_canvas->SetMouseCapture( moveItemWithMouseCursor, abortMoveItem ); GetScreen()->SetCurItem( aItem ); m_canvas->Refresh(); }
void SCH_EDIT_FRAME::StartMoveSheet( SCH_SHEET* aSheet, wxDC* aDC ) { if( ( aSheet == NULL ) || ( aSheet->Type() != SCH_SHEET_T ) ) return; m_canvas->CrossHairOff( aDC ); SetCrossHairPosition( aSheet->GetPosition() ); m_canvas->MoveCursorToCrossHair(); if( !aSheet->IsNew() ) SetUndoItem( aSheet ); aSheet->SetFlags( IS_MOVED ); m_canvas->SetMouseCapture( MoveOrResizeSheet, ExitSheet ); m_canvas->CallMouseCapture( aDC, wxDefaultPosition, true ); m_canvas->CrossHairOn( aDC ); }
/* * 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 ); }
void SCH_EDIT_FRAME::OnFindReplace( wxFindDialogEvent& aEvent ) { static int nextFoundIndex = 0; SCH_ITEM* item; SCH_SHEET_PATH* sheet; SCH_SHEET_LIST schematic( g_RootSheet ); SCH_FIND_COLLECTOR_DATA data; SCH_FIND_REPLACE_DATA searchCriteria; searchCriteria.SetFlags( aEvent.GetFlags() ); searchCriteria.SetFindString( aEvent.GetFindString() ); searchCriteria.SetReplaceString( aEvent.GetReplaceString() ); m_foundItems.SetReplaceString( aEvent.GetReplaceString() ); if( IsSearchCacheObsolete( searchCriteria ) ) { if( aEvent.GetFlags() & FR_CURRENT_SHEET_ONLY && g_RootSheet->CountSheets() > 1 ) { m_foundItems.Collect( searchCriteria, m_CurrentSheet ); } else { m_foundItems.Collect( searchCriteria ); } // Restore the next found index on cache refresh. Prevents single replace events // from starting back at the beginning of the cache. m_foundItems.SetFoundIndex( nextFoundIndex ); } if( aEvent.GetEventType() == wxEVT_COMMAND_FIND_REPLACE_ALL ) { while( ( item = (SCH_ITEM*) m_foundItems.GetItem( data ) ) != NULL ) { SCH_ITEM* undoItem = data.GetParent(); // Don't save child items in undo list. if( undoItem == NULL ) undoItem = item; SetUndoItem( undoItem ); sheet = schematic.GetSheetByPath( data.GetSheetPath() ); wxCHECK_RET( sheet != NULL, wxT( "Could not find sheet path " ) + data.GetSheetPath() ); if( m_foundItems.ReplaceItem( sheet ) ) { OnModify(); SaveUndoItemInUndoList( undoItem ); updateFindReplaceView( aEvent ); } m_foundItems.IncrementIndex(); if( m_foundItems.PassedEnd() ) break; } } else { item = (SCH_ITEM*) m_foundItems.GetItem( data ); wxCHECK_RET( item != NULL, wxT( "Invalid replace item in find collector list." ) ); SCH_ITEM* undoItem = data.GetParent(); if( undoItem == NULL ) undoItem = item; SetUndoItem( undoItem ); sheet = schematic.GetSheetByPath( data.GetSheetPath() ); wxCHECK_RET( sheet != NULL, wxT( "Could not find sheet path " ) + data.GetSheetPath() ); if( m_foundItems.ReplaceItem( sheet ) ) { OnModify(); SaveUndoItemInUndoList( undoItem ); updateFindReplaceView( aEvent ); } m_foundItems.IncrementIndex(); nextFoundIndex = m_foundItems.GetFoundIndex(); } // End the replace if we are at the end if the list. This prevents an infinite loop if // wrap search is selected and all of the items have been replaced with a value that // still satisfies the search criteria. if( m_foundItems.PassedEnd() ) aEvent.SetFlags( aEvent.GetFlags() & ~FR_REPLACE_ITEM_FOUND ); }