KiCad PCB EDA Suite
sheet.cpp File Reference
#include <fctsys.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <schframe.h>
#include <base_units.h>
#include <kiface_i.h>
#include <sch_sheet.h>
#include <sch_sheet_path.h>
#include <dialogs/dialog_sch_sheet_props.h>
#include <wildcards_and_files_ext.h>
#include <project.h>

Go to the source code of this file.

Functions

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

Function Documentation

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

Definition at line 308 of file sheet.cpp.

References SCH_SCREEN::Append(), EDA_ITEM::ClearFlags(), SCH_ITEM::Draw(), g_XorMode, SCH_SCREEN::GetCurItem(), EDA_DRAW_PANEL::GetParent(), EDA_DRAW_PANEL::GetScreen(), SCH_EDIT_FRAME::GetUndoItem(), GR_DEFAULT_DRAWMODE, EDA_ITEM::IsMoving(), EDA_ITEM::IsNew(), EDA_ITEM::IsResized(), SCH_SCREEN::Remove(), SCH_SHEET_T, SCH_SCREEN::SetCurItem(), SCH_EDIT_FRAME::SetRepeatItem(), SCH_EDIT_FRAME::SetUndoItem(), and EDA_ITEM::Type().

Referenced by SCH_EDIT_FRAME::CreateSheet(), and SCH_EDIT_FRAME::ReSizeSheet().

309 {
310  SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
311  SCH_ITEM* item = screen->GetCurItem();
312 
313  SCH_EDIT_FRAME* parent = (SCH_EDIT_FRAME*) aPanel->GetParent();
314 
315  if( (item == NULL) || (item->Type() != SCH_SHEET_T) || (parent == NULL) )
316  return;
317 
318  parent->SetRepeatItem( NULL );
319 
320  item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
321 
322  if( item->IsNew() )
323  {
324  delete item;
325  }
326  else if( item->IsMoving() || item->IsResized() )
327  {
328  screen->Remove( item );
329  delete item;
330 
331  item = parent->GetUndoItem();
332 
333  wxCHECK_RET( item != NULL, wxT( "Cannot restore undefined last sheet item." ) );
334 
335  screen->Append( item );
336  // the owner of item is no more parent, this is the draw list of screen:
337  parent->SetUndoItem( NULL );
338 
339  item->Draw( aPanel, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
340  item->ClearFlags();
341  }
342  else
343  {
344  item->ClearFlags();
345  }
346 
347  screen->SetCurItem( NULL );
348 }
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:51
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
bool IsMoving() const
Definition: base_struct.h:218
bool IsResized() const
Definition: base_struct.h:222
bool IsNew() const
Definition: base_struct.h:216
SCH_ITEM * GetUndoItem() const
Definition: schframe.h:1309
Schematic editor (Eeschema) main window.
Definition: schframe.h:117
void Remove(SCH_ITEM *aItem)
Function Remove removes aItem from the schematic associated with this screen.
Definition: sch_screen.cpp:158
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().
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:175
#define GR_DEFAULT_DRAWMODE
Definition: general.h:70
void Append(SCH_ITEM *aItem)
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
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 resizeSheetWithMouseCursor ( EDA_DRAW_PANEL aPanel,
wxDC *  aDC,
const wxPoint aPosition,
bool  aErase 
)
static

Definition at line 269 of file sheet.cpp.

References SCH_SHEET::Draw(), g_XorMode, EDA_DRAW_FRAME::GetCrossHairPosition(), BASE_SCREEN::GetCurItem(), BASE_SCREEN::GetGridSize(), SCH_SHEET::GetMinHeight(), SCH_SHEET::GetMinWidth(), EDA_DRAW_FRAME::GetNearestGridPosition(), EDA_DRAW_PANEL::GetParent(), SCH_SHEET::GetPosition(), EDA_DRAW_PANEL::GetScreen(), SCH_SHEET::HasPins(), KiROUND(), MIN_SHEET_HEIGHT, MIN_SHEET_WIDTH, SCH_SHEET::Resize(), wxPoint::x, and wxPoint::y.

Referenced by SCH_EDIT_FRAME::CreateSheet(), and SCH_EDIT_FRAME::ReSizeSheet().

271 {
272  BASE_SCREEN* screen = aPanel->GetScreen();
273  SCH_SHEET* sheet = (SCH_SHEET*) screen->GetCurItem();
274 
275  if( aErase )
276  sheet->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
277 
278  wxPoint pos = sheet->GetPosition();
279 
280  int width = aPanel->GetParent()->GetCrossHairPosition().x - sheet->GetPosition().x;
281  int height = aPanel->GetParent()->GetCrossHairPosition().y - sheet->GetPosition().y;
282 
283  // If the sheet doesn't have any pins, clamp the minimum size to the default values.
284  width = ( width < MIN_SHEET_WIDTH ) ? MIN_SHEET_WIDTH : width;
285  height = ( height < MIN_SHEET_HEIGHT ) ? MIN_SHEET_HEIGHT : height;
286 
287  if( sheet->HasPins() )
288  {
289  int gridSizeX = KiROUND( screen->GetGridSize().x );
290  int gridSizeY = KiROUND( screen->GetGridSize().y );
291 
292  // If the sheet has pins, use the pin positions to clamp the minimum height.
293  height = ( height < sheet->GetMinHeight() + gridSizeY ) ?
294  sheet->GetMinHeight() + gridSizeY : height;
295  width = ( width < sheet->GetMinWidth() + gridSizeX ) ?
296  sheet->GetMinWidth() + gridSizeX : width;
297  }
298 
299  wxPoint grid = aPanel->GetParent()->GetNearestGridPosition(
300  wxPoint( pos.x + width, pos.y + height ) );
301  sheet->Resize( wxSize( grid.x - pos.x, grid.y - pos.y ) );
302 
303  sheet->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
304 }
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:51
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
EDA_ITEM * GetCurItem() const
int GetMinHeight() const
Function GetMinHeight returns the minimum height that the sheet can be resized based on the sheet pin...
Definition: sch_sheet.cpp:478
#define MIN_SHEET_WIDTH
Definition: sch_sheet.h:47
bool HasPins()
Definition: sch_sheet.h:388
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:175
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_sheet.h:582
Class SCH_SHEET is the sheet symbol placed in a schematic, and is the entry point for a sub schematic...
Definition: sch_sheet.h:216
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_sheet.cpp:583
wxPoint GetNearestGridPosition(const wxPoint &aPosition, wxRealPoint *aGridSize=NULL) const
Function GetNearestGridPosition returns the nearest aGridSize location to aPosition.
int GetMinWidth() const
Function GetMinWidth returns the minimum width of the sheet based on the widths of the sheet pin text...
Definition: sch_sheet.cpp:444
const wxRealPoint & GetGridSize() const
Return the grid size of the currently selected grid.
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:188
#define MIN_SHEET_HEIGHT
Definition: sch_sheet.h:48
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
void Resize(const wxSize &aSize)
Resize this sheet to aSize and adjust all of the labels accordingly.
Definition: sch_sheet.cpp:924