KiCad PCB EDA Suite
edit_bitmap.cpp File Reference
#include <fctsys.h>
#include <class_drawpanel.h>
#include <schframe.h>
#include <sch_bitmap.h>
#include <dialog_image_editor.h>

Go to the source code of this file.

Functions

static void abortMoveBitmap (EDA_DRAW_PANEL *aPanel, wxDC *aDC)
 
static void moveBitmap (EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool aErase)
 

Function Documentation

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

Definition at line 37 of file edit_bitmap.cpp.

References EDA_ITEM::ClearFlags(), SCH_SCREEN::GetCurItem(), EDA_DRAW_PANEL::GetParent(), EDA_DRAW_PANEL::GetScreen(), SCH_EDIT_FRAME::GetUndoItem(), EDA_ITEM::IsNew(), EDA_DRAW_PANEL::Refresh(), SCH_BITMAP_T, SCH_SCREEN::SetCurItem(), SCH_EDIT_FRAME::SetRepeatItem(), SCH_EDIT_FRAME::SetUndoItem(), SCH_BITMAP::SwapData(), and EDA_ITEM::Type().

Referenced by SCH_EDIT_FRAME::CreateNewImage(), moveBitmap(), and SCH_EDIT_FRAME::MoveImage().

38 {
39  SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
40  SCH_BITMAP* item = (SCH_BITMAP*) screen->GetCurItem();
41  SCH_EDIT_FRAME* parent = (SCH_EDIT_FRAME*) aPanel->GetParent();
42 
43  parent->SetRepeatItem( NULL );
44 
45  if( item == NULL ) /* no current item */
46  return;
47 
48  if( item->IsNew() )
49  {
50  delete item;
51  item = NULL;
52  }
53  else // Move command on an existing text item, restore the data of the original.
54  {
55  item->ClearFlags();
56 
57  SCH_BITMAP * olditem = (SCH_BITMAP*) parent->GetUndoItem();
58 
59  wxCHECK_RET( olditem != NULL && item->Type() == olditem->Type() &&
60  item->Type() == SCH_BITMAP_T,
61  wxT( "Cannot restore undefined last text item." ) );
62 
63  // Never delete existing item, because it can be referenced by an undo/redo command
64  // Just restore its data
65  item->SwapData( olditem );
66  parent->SetUndoItem( NULL );
67  }
68 
69  screen->SetCurItem( item );
70  aPanel->Refresh();
71 }
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
SCH_ITEM * GetUndoItem() const
Definition: schframe.h:1311
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:459
SCH_ITEM * GetCurItem() const
Function GetCurItem returns the currently selected SCH_ITEM, overriding BASE_SCREEN::GetCurItem().
void SwapData(SCH_ITEM *aItem) override
Function SwapData swap the internal data structures aItem with the schematic item.
Definition: sch_bitmap.cpp:125
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
void SetUndoItem(const SCH_ITEM *aItem)
Function SetUndoItem clones aItem which can be used to restore the state of the item being edited whe...
Definition: schframe.cpp:579
static void moveBitmap ( EDA_DRAW_PANEL aPanel,
wxDC *  aDC,
const wxPoint aPosition,
bool  aErase 
)
static

Definition at line 73 of file edit_bitmap.cpp.

References abortMoveBitmap(), EDA_ITEM::ClearFlags(), SCH_BITMAP::Draw(), SCH_BITMAP::GetBoundingBox(), EDA_DRAW_FRAME::GetCrossHairPosition(), SCH_SCREEN::GetCurItem(), EDA_ITEM::GetFlags(), EDA_DRAW_PANEL::GetParent(), EDA_DRAW_PANEL::GetScreen(), GR_DEFAULT_DRAWMODE, EDA_RECT::Inflate(), EDA_DRAW_PANEL::RefreshDrawingRect(), EDA_ITEM::SetFlags(), EDA_DRAW_PANEL::SetMouseCapture(), and SCH_BITMAP::SetPosition().

Referenced by SCH_EDIT_FRAME::CreateNewImage(), and SCH_EDIT_FRAME::MoveImage().

74 {
75  SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
76  SCH_BITMAP* image = (SCH_BITMAP*) screen->GetCurItem();
77 
78  if( aErase )
79  {
80  // Erase the current bitmap at its current position.
81  // Note also items flagged IS_MOVING are not drawn,
82  // and if image is new, it is not yet il draw list
83  // so image is erased from screen
84  EDA_RECT dirty = image->GetBoundingBox();
85  dirty.Inflate( 4 ); // Give a margin
86  aPanel->SetMouseCapture( NULL, NULL ); // Avoid loop in redraw panel
87 
88  STATUS_FLAGS flgs = image->GetFlags();
89  image->ClearFlags();
90  aPanel->RefreshDrawingRect( dirty );
91  image->SetFlags( flgs );
93  }
94 
95  // Draw the bitmap at it's new position.
96  image->SetPosition( aPanel->GetParent()->GetCrossHairPosition() );
97  image->Draw( aPanel, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
98 }
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:255
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.
Definition: sch_bitmap.cpp:193
static void moveBitmap(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool aErase)
Definition: edit_bitmap.cpp:73
void RefreshDrawingRect(const EDA_RECT &aRect, bool aEraseBackground=true)
Function RefreshDrawingRect redraws the contents of aRect in drawing units.
Definition: draw_panel.cpp:306
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
Definition: sch_bitmap.cpp:183
static void abortMoveBitmap(EDA_DRAW_PANEL *aPanel, wxDC *aDC)
Definition: edit_bitmap.cpp:37
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:253
SCH_ITEM * GetCurItem() const
Function GetCurItem returns the currently selected SCH_ITEM, overriding BASE_SCREEN::GetCurItem().
unsigned STATUS_FLAGS
Definition: base_struct.h:144
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:175
#define GR_DEFAULT_DRAWMODE
Definition: general.h:69
Class EDA_RECT handles the component boundary box.
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:188
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:254
void SetMouseCapture(MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback, END_MOUSE_CAPTURE_CALLBACK aEndMouseCaptureCallback)
Function SetMouseCapture sets the mouse capture and end mouse capture callbacks to aMouseCaptureCallb...
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
void SetPosition(const wxPoint &aPosition) override
Function SetPosition set the schematic item position to aPosition.
Definition: sch_bitmap.h:137
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.