KiCad PCB EDA Suite
schedit.cpp File Reference
#include <fctsys.h>
#include <kiway.h>
#include <gr_basic.h>
#include <pgm_base.h>
#include <class_drawpanel.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>

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)
 

Function Documentation

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

Definition at line 729 of file schedit.cpp.

References EDA_ITEM::ClearFlags(), SCH_ITEM::Draw(), g_XorMode, SCH_SCREEN::GetCurItem(), EDA_DRAW_PANEL::GetParent(), EDA_ITEM::GetParent(), EDA_DRAW_PANEL::GetScreen(), SCH_EDIT_FRAME::GetUndoItem(), EDA_ITEM::IsNew(), EDA_ITEM::IsWireImage(), EDA_DRAW_PANEL::Refresh(), SCH_FIELD_T, SCH_SHEET_PIN_T, SCH_SCREEN::SetCurItem(), SCH_EDIT_FRAME::SetRepeatItem(), SCH_ITEM::SwapData(), and EDA_ITEM::Type().

Referenced by SCH_EDIT_FRAME::PrepareMoveItem().

730 {
731  SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
732  SCH_ITEM* item = screen->GetCurItem();
733  SCH_EDIT_FRAME* parent = (SCH_EDIT_FRAME*) aPanel->GetParent();
734 
735  parent->SetRepeatItem( NULL );
736  screen->SetCurItem( NULL );
737 
738  if( item == NULL ) /* no current item */
739  return;
740 
741  if( item->IsNew() )
742  {
743  delete item;
744  item = NULL;
745  }
746  else
747  {
748  SCH_ITEM* oldItem = parent->GetUndoItem();
749 
750  SCH_ITEM* currentItem;
751 
752  // Items that are children of other objects are undone by swapping the contents
753  // of the parent items.
754  if( (item->Type() == SCH_SHEET_PIN_T) || (item->Type() == SCH_FIELD_T) )
755  {
756  currentItem = (SCH_ITEM*) item->GetParent();
757  }
758  else
759  {
760  currentItem = item;
761  }
762 
763  wxCHECK_RET( oldItem != NULL && currentItem->Type() == oldItem->Type(),
764  wxT( "Cannot restore undefined or bad last schematic item." ) );
765 
766  // Never delete existing item, because it can be referenced by an undo/redo command
767  // Just restore its data
768  currentItem->SwapData( oldItem );
769 
770  // Erase the wire representation before the 'normal' view is drawn.
771  if ( item->IsWireImage() )
772  item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
773 
774  item->ClearFlags();
775  }
776 
777  aPanel->Refresh();
778 }
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:73
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:338
bool IsNew() const
Definition: base_struct.h:227
EDA_ITEM * GetParent() const
Definition: base_struct.h:219
SCH_ITEM * GetUndoItem() const
Schematic editor (Eeschema) main window.
void SetRepeatItem(SCH_ITEM *aItem)
Clone aItem and owns that clone in this container.
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:174
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:180
void SetCurItem(SCH_ITEM *aItem)
Sets the currently selected object, m_CurrentItem.
Definition: sch_screen.h:182
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:193
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:265
bool IsWireImage() const
Definition: base_struct.h:231
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
virtual void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, GR_DRAWMODE aDrawMode, COLOR4D aColor=COLOR4D::UNSPECIFIED)=0
Function Draw Draw a schematic item.
static void moveItemWithMouseCursor ( EDA_DRAW_PANEL aPanel,
wxDC *  aDC,
const wxPoint aPosition,
bool  aErase 
)
static

Definition at line 690 of file schedit.cpp.

References SCH_ITEM::Draw(), SCH_COMPONENT::Draw(), g_XorMode, EDA_DRAW_FRAME::GetCrossHairPosition(), SCH_SCREEN::GetCurItem(), EDA_DRAW_PANEL::GetParent(), EDA_DRAW_PANEL::GetScreen(), SCH_ITEM::GetStoredPos(), SCH_COMPONENT_T, SCH_ITEM::SetPosition(), EDA_ITEM::SetWireImage(), and EDA_ITEM::Type().

Referenced by SCH_EDIT_FRAME::PrepareMoveItem().

692 {
693  SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
694  SCH_ITEM* item = screen->GetCurItem();
695 
696  wxCHECK_RET( (item != NULL), wxT( "Cannot move invalid schematic item." ) );
697 
698  SCH_COMPONENT* cmp = NULL;
699 
700  if( item->Type() == SCH_COMPONENT_T )
701  cmp = static_cast< SCH_COMPONENT* >( item );
702 
703 #ifndef USE_WX_OVERLAY
704  // Erase the current item at its current position.
705  if( aErase )
706  {
707  if( cmp ) // Use fast mode (do not draw pin texts)
708  cmp->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, COLOR4D::UNSPECIFIED, false );
709  else
710  item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
711  }
712 #endif
713 
714  wxPoint cpos = aPanel->GetParent()->GetCrossHairPosition();
715  cpos -= item->GetStoredPos();
716 
717  item->SetPosition( cpos );
718 
719  // Draw the item item at it's new position.
720  item->SetWireImage(); // While moving, the item may choose to render differently
721 
722  if( cmp ) // Use fast mode (do not draw pin texts)
723  cmp->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, COLOR4D::UNSPECIFIED, false );
724  else
725  item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
726 }
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:73
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
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:174
void SetWireImage()
Definition: base_struct.h:237
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:180
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, GR_DRAWMODE aDrawMode, COLOR4D aColor=COLOR4D::UNSPECIFIED) override
Function Draw Draw a schematic item.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:193
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition 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...
virtual void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, GR_DRAWMODE aDrawMode, COLOR4D aColor=COLOR4D::UNSPECIFIED)=0
Function Draw Draw a schematic item.