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 <schframe.h>
#include <kicad_device_context.h>
#include <hotkeys_basic.h>
#include <general.h>
#include <eeschema_id.h>
#include <protos.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 732 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().

733 {
734  SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
735  SCH_ITEM* item = screen->GetCurItem();
736  SCH_EDIT_FRAME* parent = (SCH_EDIT_FRAME*) aPanel->GetParent();
737 
738  parent->SetRepeatItem( NULL );
739  screen->SetCurItem( NULL );
740 
741  if( item == NULL ) /* no current item */
742  return;
743 
744  if( item->IsNew() )
745  {
746  delete item;
747  item = NULL;
748  }
749  else
750  {
751  SCH_ITEM* oldItem = parent->GetUndoItem();
752 
753  SCH_ITEM* currentItem;
754 
755  // Items that are children of other objects are undone by swapping the contents
756  // of the parent items.
757  if( (item->Type() == SCH_SHEET_PIN_T) || (item->Type() == SCH_FIELD_T) )
758  {
759  currentItem = (SCH_ITEM*) item->GetParent();
760  }
761  else
762  {
763  currentItem = item;
764  }
765 
766  wxCHECK_RET( oldItem != NULL && currentItem->Type() == oldItem->Type(),
767  wxT( "Cannot restore undefined or bad last schematic item." ) );
768 
769  // Never delete existing item, because it can be referenced by an undo/redo command
770  // Just restore its data
771  currentItem->SwapData( oldItem );
772 
773  // Erase the wire representation before the 'normal' view is drawn.
774  if ( item->IsWireImage() )
775  item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
776 
777  item->ClearFlags();
778  }
779 
780  aPanel->Refresh();
781 }
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:51
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Definition: draw_panel.cpp:326
bool IsNew() const
Definition: base_struct.h:216
EDA_ITEM * GetParent() const
Definition: base_struct.h:208
SCH_ITEM * GetUndoItem() const
Definition: schframe.h:1310
Schematic editor (Eeschema) main window.
Definition: schframe.h:117
void SetRepeatItem(SCH_ITEM *aItem)
Function SetRepeatItem clones aItem and owns that clone in this container.
Definition: schframe.cpp:460
virtual void SwapData(SCH_ITEM *aItem)
Function SwapData swap the internal data structures aItem with the schematic item.
SCH_ITEM * GetCurItem() const
Function GetCurItem returns the currently selected SCH_ITEM, overriding BASE_SCREEN::GetCurItem().
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:175
void SetCurItem(SCH_ITEM *aItem)
Function SetCurItem sets the currently selected object, m_CurrentItem.
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:188
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:254
bool IsWireImage() const
Definition: base_struct.h:220
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 693 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().

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