KiCad PCB EDA Suite
schedit.cpp File Reference
#include <fctsys.h>
#include <kiway.h>
#include <gr_basic.h>
#include <pgm_base.h>
#include <sch_draw_panel.h>
#include <confirm.h>
#include <eda_doc.h>
#include <sch_edit_frame.h>
#include <kicad_device_context.h>
#include <hotkeys_basic.h>
#include <general.h>
#include <eeschema_id.h>
#include <list_operations.h>
#include <class_library.h>
#include <sch_bus_entry.h>
#include <sch_marker.h>
#include <sch_component.h>
#include <sch_junction.h>
#include <sch_line.h>
#include <sch_sheet.h>
#include <sch_sheet_path.h>
#include <sch_view.h>

Go to the source code of this file.

Functions

static void moveItemWithMouseCursor (EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool aErase)
 
static void abortMoveItem (EDA_DRAW_PANEL *aPanel, wxDC *aDC)
 Callback function called when aborting a move item with mouse cursor command. More...
 

Function Documentation

static void abortMoveItem ( EDA_DRAW_PANEL aPanel,
wxDC *  aDC 
)
static

Callback function called when aborting a move item with mouse cursor command.

Definition at line 709 of file schedit.cpp.

References EDA_ITEM::ClearFlags(), SCH_SCREEN::GetCurItem(), EDA_DRAW_PANEL::GetParent(), EDA_ITEM::GetParent(), EDA_DRAW_PANEL::GetScreen(), SCH_EDIT_FRAME::GetUndoItem(), SCH_DRAW_PANEL::GetView(), EDA_ITEM::IsNew(), EDA_DRAW_PANEL::Refresh(), SCH_BASE_FRAME::RefreshItem(), SCH_FIELD_T, SCH_SHEET_PIN_T, SCH_SCREEN::SetCurItem(), SCH_EDIT_FRAME::SetRepeatItem(), SCH_ITEM::SwapData(), SCH_SCREEN::TestDanglingEnds(), and EDA_ITEM::Type().

Referenced by SCH_EDIT_FRAME::PrepareMoveItem().

710 {
711  SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
712  SCH_ITEM* item = screen->GetCurItem();
713  SCH_EDIT_FRAME* parent = (SCH_EDIT_FRAME*) aPanel->GetParent();
714  auto panel = static_cast<SCH_DRAW_PANEL*>( aPanel );
715  auto view = panel->GetView();
716 
717  parent->SetRepeatItem( NULL );
718  screen->SetCurItem( NULL );
719  view->ClearPreview();
720  view->ClearHiddenFlags();
721 
722  if( item == NULL ) /* no current item */
723  return;
724 
725  if( item->IsNew() )
726  {
727  delete item;
728  }
729  else
730  {
731  SCH_ITEM* oldItem = parent->GetUndoItem();
732 
733  SCH_ITEM* currentItem;
734 
735  // Items that are children of other objects are undone by swapping the contents
736  // of the parent items.
737  if( (item->Type() == SCH_SHEET_PIN_T) || (item->Type() == SCH_FIELD_T) )
738  currentItem = (SCH_ITEM*) item->GetParent();
739  else
740  currentItem = item;
741 
742  wxCHECK_RET( oldItem != NULL && currentItem->Type() == oldItem->Type(),
743  wxT( "Cannot restore undefined or bad last schematic item." ) );
744 
745  // Never delete existing item, because it can be referenced by an undo/redo command
746  // Just restore its data
747  currentItem->SwapData( oldItem );
748  view->Hide( item, false );
749  item->ClearFlags();
750 
751  // for items managed by their parent, we have to refresh
752  // the parent drawings (scheet or symbol)
753  if( currentItem != item )
754  parent->RefreshItem( currentItem );
755  }
756 
757  screen->TestDanglingEnds();
758  aPanel->Refresh();
759 }
virtual BASE_SCREEN * GetScreen()=0
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
bool IsNew() const
Definition: base_struct.h:219
EDA_ITEM * GetParent() const
Definition: base_struct.h:211
SCH_ITEM * GetUndoItem() const
Schematic editor (Eeschema) main window.
void SetRepeatItem(SCH_ITEM *aItem)
Clone aItem and owns that clone in this container.
virtual EDA_DRAW_FRAME * GetParent() const =0
virtual void SwapData(SCH_ITEM *aItem)
Function SwapData swap the internal data structures aItem with the schematic item.
SCH_ITEM * GetCurItem() const
Return the currently selected SCH_ITEM, overriding BASE_SCREEN::GetCurItem().
Definition: sch_screen.h:196
KIGFX::SCH_VIEW * GetView() const
void RefreshItem(SCH_ITEM *aItem, bool isAddOrDelete=false)
Mark an item for refresh.
bool TestDanglingEnds()
Test all of the connectable objects in the schematic for unused connection points.
Definition: sch_screen.cpp:910
void SetCurItem(SCH_ITEM *aItem)
Sets the currently selected object, m_CurrentItem.
Definition: sch_screen.h:204
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:257
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
static void moveItemWithMouseCursor ( EDA_DRAW_PANEL aPanel,
wxDC *  aDC,
const wxPoint aPosition,
bool  aErase 
)
static

Definition at line 680 of file schedit.cpp.

References EDA_ITEM::Clone(), EDA_DRAW_FRAME::GetCrossHairPosition(), SCH_SCREEN::GetCurItem(), EDA_DRAW_PANEL::GetParent(), EDA_DRAW_PANEL::GetScreen(), SCH_ITEM::GetStoredPos(), SCH_DRAW_PANEL::GetView(), SCH_BITMAP_T, SCH_ITEM::SetPosition(), KIGFX::TARGET_NONCACHED, and EDA_ITEM::Type().

Referenced by SCH_EDIT_FRAME::PrepareMoveItem().

682 {
683  SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
684  SCH_ITEM* item = screen->GetCurItem();
685  auto panel = static_cast<SCH_DRAW_PANEL*>( aPanel );
686  auto view = panel->GetView();
687 
688  wxCHECK_RET( (item != NULL), wxT( "Cannot move invalid schematic item." ) );
689 
690  wxPoint cpos = aPanel->GetParent()->GetCrossHairPosition();
691  cpos -= item->GetStoredPos();
692 
693  item->SetPosition( cpos );
694 
695  view->Hide( item );
696  view->ClearPreview();
697  view->AddToPreview( item->Clone() );
698 
699  // Needed when moving a bitmap image to avoid ugly rendering and artifacts,
700  // because a bitmap is drawn only as non cached
701  if( item->Type() == SCH_BITMAP_T )
702  view->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
703 }
virtual BASE_SCREEN * GetScreen()=0
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
Auxiliary rendering target (noncached)
Definition: definitions.h:42
virtual EDA_DRAW_FRAME * GetParent() const =0
wxPoint & GetStoredPos()
virtual void SetPosition(const wxPoint &aPosition)=0
Function SetPosition set the schematic item position to aPosition.
SCH_ITEM * GetCurItem() const
Return the currently selected SCH_ITEM, overriding BASE_SCREEN::GetCurItem().
Definition: sch_screen.h:196
KIGFX::SCH_VIEW * GetView() const
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...