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 709 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().

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 
715  parent->SetRepeatItem( NULL );
716  screen->SetCurItem( NULL );
717 
718  if( item == NULL ) /* no current item */
719  return;
720 
721  if( item->IsNew() )
722  {
723  delete item;
724  item = NULL;
725  }
726  else
727  {
728  SCH_ITEM* oldItem = parent->GetUndoItem();
729 
730  SCH_ITEM* currentItem;
731 
732  // Items that are children of other objects are undone by swapping the contents
733  // of the parent items.
734  if( (item->Type() == SCH_SHEET_PIN_T) || (item->Type() == SCH_FIELD_T) )
735  {
736  currentItem = (SCH_ITEM*) item->GetParent();
737  }
738  else
739  {
740  currentItem = item;
741  }
742 
743  wxCHECK_RET( oldItem != NULL && currentItem->Type() == oldItem->Type(),
744  wxT( "Cannot restore undefined or bad last schematic item." ) );
745 
746  // Never delete existing item, because it can be referenced by an undo/redo command
747  // Just restore its data
748  currentItem->SwapData( oldItem );
749 
750  // Erase the wire representation before the 'normal' view is drawn.
751  if ( item->IsWireImage() )
752  item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
753 
754  item->ClearFlags();
755  }
756 
757  aPanel->Refresh();
758 }
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:73
KICAD_T Type() const
Function Type()
Definition: base_struct.h:227
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:339
bool IsNew() const
Definition: base_struct.h:245
EDA_ITEM * GetParent() const
Definition: base_struct.h:237
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:181
void SetCurItem(SCH_ITEM *aItem)
Sets the currently selected object, m_CurrentItem.
Definition: sch_screen.h:182
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:194
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:283
bool IsWireImage() const
Definition: base_struct.h:249
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 670 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().

672 {
673  SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
674  SCH_ITEM* item = screen->GetCurItem();
675 
676  wxCHECK_RET( (item != NULL), wxT( "Cannot move invalid schematic item." ) );
677 
678  SCH_COMPONENT* cmp = NULL;
679 
680  if( item->Type() == SCH_COMPONENT_T )
681  cmp = static_cast< SCH_COMPONENT* >( item );
682 
683 #ifndef USE_WX_OVERLAY
684  // Erase the current item at its current position.
685  if( aErase )
686  {
687  if( cmp ) // Use fast mode (do not draw pin texts)
688  cmp->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, COLOR4D::UNSPECIFIED, false );
689  else
690  item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
691  }
692 #endif
693 
694  wxPoint cpos = aPanel->GetParent()->GetCrossHairPosition();
695  cpos -= item->GetStoredPos();
696 
697  item->SetPosition( cpos );
698 
699  // Draw the item item at it's new position.
700  item->SetWireImage(); // While moving, the item may choose to render differently
701 
702  if( cmp ) // Use fast mode (do not draw pin texts)
703  cmp->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, COLOR4D::UNSPECIFIED, false );
704  else
705  item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
706 }
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:73
KICAD_T Type() const
Function Type()
Definition: base_struct.h:227
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:255
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:181
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:194
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.