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

◆ abortMoveItem()

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 693 of file schedit.cpp.

694 {
695  SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
696  SCH_ITEM* item = screen->GetCurItem();
697  SCH_EDIT_FRAME* parent = (SCH_EDIT_FRAME*) aPanel->GetParent();
698  auto panel = static_cast<SCH_DRAW_PANEL*>( aPanel );
699  auto view = panel->GetView();
700 
701  parent->SetRepeatItem( NULL );
702  screen->SetCurItem( NULL );
703  view->ClearPreview();
704  view->ClearHiddenFlags();
705 
706  if( item == NULL ) /* no current item */
707  return;
708 
709  if( item->IsNew() )
710  {
711  delete item;
712  }
713  else
714  {
715  SCH_ITEM* oldItem = parent->GetUndoItem();
716 
717  SCH_ITEM* currentItem;
718 
719  // Items that are children of other objects are undone by swapping the contents
720  // of the parent items.
721  if( (item->Type() == SCH_SHEET_PIN_T) || (item->Type() == SCH_FIELD_T) )
722  currentItem = (SCH_ITEM*) item->GetParent();
723  else
724  currentItem = item;
725 
726  wxCHECK_RET( oldItem != NULL && currentItem->Type() == oldItem->Type(),
727  wxT( "Cannot restore undefined or bad last schematic item." ) );
728 
729  // Never delete existing item, because it can be referenced by an undo/redo command
730  // Just restore its data
731 
732  view->Remove( currentItem );
733  currentItem->SwapData( oldItem );
734  item->ClearFlags();
735  view->Add( currentItem );
736  view->Hide( item, false );
737  }
738 
739  screen->TestDanglingEnds();
740  aPanel->Refresh();
741 }
virtual BASE_SCREEN * GetScreen()=0
SCH_ITEM * GetUndoItem() const
Schematic editor (Eeschema) main window.
SCH_ITEM * GetCurItem() const
Return the currently selected SCH_ITEM, overriding BASE_SCREEN::GetCurItem().
Definition: sch_screen.h:196
void SetRepeatItem(SCH_ITEM *aItem)
Clone aItem and owns that clone in this container.
bool IsNew() const
Definition: base_struct.h:219
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.
EDA_ITEM * GetParent() const
Definition: base_struct.h:211
bool TestDanglingEnds()
Test all of the connectable objects in the schematic for unused connection points.
Definition: sch_screen.cpp:912
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...
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201

References EDA_ITEM::ClearFlags(), SCH_SCREEN::GetCurItem(), EDA_DRAW_PANEL::GetParent(), EDA_ITEM::GetParent(), EDA_DRAW_PANEL::GetScreen(), SCH_EDIT_FRAME::GetUndoItem(), EDA_ITEM::IsNew(), EDA_DRAW_PANEL::Refresh(), 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().

◆ moveItemWithMouseCursor()

static void moveItemWithMouseCursor ( EDA_DRAW_PANEL aPanel,
wxDC *  aDC,
const wxPoint &  aPosition,
bool  aErase 
)
static

Definition at line 664 of file schedit.cpp.

666 {
667  SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
668  SCH_ITEM* item = screen->GetCurItem();
669  auto panel = static_cast<SCH_DRAW_PANEL*>( aPanel );
670  auto view = panel->GetView();
671 
672  wxCHECK_RET( (item != NULL), wxT( "Cannot move invalid schematic item." ) );
673 
674  wxPoint cpos = aPanel->GetParent()->GetCrossHairPosition();
675  cpos -= item->GetStoredPos();
676 
677  item->SetPosition( cpos );
678 
679  view->Hide( item );
680  view->ClearPreview();
681  view->AddToPreview( item->Clone() );
682 
683  // Needed when moving a bitmap image to avoid ugly rendering and artifacts,
684  // because a bitmap is drawn only as non cached
685  if( item->Type() == SCH_BITMAP_T )
686  view->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
687 }
virtual BASE_SCREEN * GetScreen()=0
SCH_ITEM * GetCurItem() const
Return the currently selected SCH_ITEM, overriding BASE_SCREEN::GetCurItem().
Definition: sch_screen.h:196
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:49
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.
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201

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

Referenced by SCH_EDIT_FRAME::PrepareMoveItem().