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

732 {
733  SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
734  SCH_ITEM* item = screen->GetCurItem();
735  SCH_EDIT_FRAME* parent = (SCH_EDIT_FRAME*) aPanel->GetParent();
736 
737  parent->SetRepeatItem( NULL );
738  screen->SetCurItem( NULL );
739 
740  if( item == NULL ) /* no current item */
741  return;
742 
743  if( item->IsNew() )
744  {
745  delete item;
746  item = NULL;
747  }
748  else
749  {
750  SCH_ITEM* oldItem = parent->GetUndoItem();
751 
752  SCH_ITEM* currentItem;
753 
754  // Items that are children of other objects are undone by swapping the contents
755  // of the parent items.
756  if( (item->Type() == SCH_SHEET_PIN_T) || (item->Type() == SCH_FIELD_T) )
757  {
758  currentItem = (SCH_ITEM*) item->GetParent();
759  }
760  else
761  {
762  currentItem = item;
763  }
764 
765  wxCHECK_RET( oldItem != NULL && currentItem->Type() == oldItem->Type(),
766  wxT( "Cannot restore undefined or bad last schematic item." ) );
767 
768  // Never delete existing item, because it can be referenced by an undo/redo command
769  // Just restore its data
770  currentItem->SwapData( oldItem );
771 
772  // Erase the wire representation before the 'normal' view is drawn.
773  if ( item->IsWireImage() )
774  item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
775 
776  item->ClearFlags();
777  }
778 
779  aPanel->Refresh();
780 }
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:51
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
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:325
bool IsNew() const
Definition: base_struct.h:230
EDA_ITEM * GetParent() const
Definition: base_struct.h:222
SCH_ITEM * GetUndoItem() const
Definition: schframe.h:1316
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:467
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:174
void SetCurItem(SCH_ITEM *aItem)
Function SetCurItem sets the currently selected object, m_CurrentItem.
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:187
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:268
bool IsWireImage() const
Definition: base_struct.h:234
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 692 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().

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