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

724 {
725  SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
726  SCH_ITEM* item = screen->GetCurItem();
727  SCH_EDIT_FRAME* parent = (SCH_EDIT_FRAME*) aPanel->GetParent();
728 
729  parent->SetRepeatItem( NULL );
730  screen->SetCurItem( NULL );
731 
732  if( item == NULL ) /* no current item */
733  return;
734 
735  if( item->IsNew() )
736  {
737  delete item;
738  item = NULL;
739  }
740  else
741  {
742  SCH_ITEM* oldItem = parent->GetUndoItem();
743 
744  SCH_ITEM* currentItem;
745 
746  // Items that are children of other objects are undone by swapping the contents
747  // of the parent items.
748  if( (item->Type() == SCH_SHEET_PIN_T) || (item->Type() == SCH_FIELD_T) )
749  {
750  currentItem = (SCH_ITEM*) item->GetParent();
751  }
752  else
753  {
754  currentItem = item;
755  }
756 
757  wxCHECK_RET( oldItem != NULL && currentItem->Type() == oldItem->Type(),
758  wxT( "Cannot restore undefined or bad last schematic item." ) );
759 
760  // Never delete existing item, because it can be referenced by an undo/redo command
761  // Just restore its data
762  currentItem->SwapData( oldItem );
763 
764  // Erase the wire representation before the 'normal' view is drawn.
765  if ( item->IsWireImage() )
766  item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
767 
768  item->ClearFlags();
769  }
770 
771  aPanel->Refresh();
772 }
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:1295
Schematic editor (Eeschema) main window.
Definition: schframe.h:118
void SetRepeatItem(SCH_ITEM *aItem)
Clone aItem and owns that clone in this container.
Definition: schframe.cpp:471
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().
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:174
void SetCurItem(SCH_ITEM *aItem)
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 684 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().

686 {
687  SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
688  SCH_ITEM* item = screen->GetCurItem();
689 
690  wxCHECK_RET( (item != NULL), wxT( "Cannot move invalid schematic item." ) );
691 
692  SCH_COMPONENT* cmp = NULL;
693 
694  if( item->Type() == SCH_COMPONENT_T )
695  cmp = static_cast< SCH_COMPONENT* >( item );
696 
697 #ifndef USE_WX_OVERLAY
698  // Erase the current item at its current position.
699  if( aErase )
700  {
701  if( cmp ) // Use fast mode (do not draw pin texts)
702  cmp->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, COLOR4D::UNSPECIFIED, false );
703  else
704  item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
705  }
706 #endif
707 
708  wxPoint cpos = aPanel->GetParent()->GetCrossHairPosition();
709  cpos -= item->GetStoredPos();
710 
711  item->SetPosition( cpos );
712 
713  // Draw the item item at it's new position.
714  item->SetWireImage(); // While moving, the item may choose to render differently
715 
716  if( cmp ) // Use fast mode (do not draw pin texts)
717  cmp->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, COLOR4D::UNSPECIFIED, false );
718  else
719  item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
720 }
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
Return 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.