KiCad PCB EDA Suite
sheet.cpp File Reference
#include <fctsys.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <base_units.h>
#include <kiface_i.h>
#include <project.h>
#include <wildcards_and_files_ext.h>
#include <schframe.h>
#include <sch_legacy_plugin.h>
#include <sch_sheet.h>
#include <sch_sheet_path.h>
#include <dialogs/dialog_sch_sheet_props.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 357 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().

358 {
359  SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
360  SCH_ITEM* item = screen->GetCurItem();
361 
362  SCH_EDIT_FRAME* parent = (SCH_EDIT_FRAME*) aPanel->GetParent();
363 
364  if( (item == NULL) || (item->Type() != SCH_SHEET_T) || (parent == NULL) )
365  return;
366 
367  parent->SetRepeatItem( NULL );
368 
369  item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
370 
371  if( item->IsNew() )
372  {
373  delete item;
374  }
375  else if( item->IsMoving() || item->IsResized() )
376  {
377  screen->Remove( item );
378  delete item;
379 
380  item = parent->GetUndoItem();
381 
382  wxCHECK_RET( item != NULL, wxT( "Cannot restore undefined last sheet item." ) );
383 
384  screen->Append( item );
385  // the owner of item is no more parent, this is the draw list of screen:
386  parent->SetUndoItem( NULL );
387 
388  item->Draw( aPanel, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
389  item->ClearFlags();
390  }
391  else
392  {
393  item->ClearFlags();
394  }
395 
396  screen->SetCurItem( NULL );
397 }
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:51
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
bool IsMoving() const
Definition: base_struct.h:232
bool IsResized() const
Definition: base_struct.h:236
bool IsNew() const
Definition: base_struct.h:230
SCH_ITEM * GetUndoItem() const
Definition: schframe.h:1295
Schematic editor (Eeschema) main window.
Definition: schframe.h:118
void Remove(SCH_ITEM *aItem)
Remove aItem from the schematic associated with this screen.
Definition: sch_screen.cpp:170
void SetRepeatItem(SCH_ITEM *aItem)
Clone aItem and owns that clone in this container.
Definition: schframe.cpp:471
SCH_ITEM * GetCurItem() const
Return the currently selected SCH_ITEM, overriding BASE_SCREEN::GetCurItem().
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:174
#define GR_DEFAULT_DRAWMODE
Definition: general.h:70
void Append(SCH_ITEM *aItem)
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
void SetUndoItem(const SCH_ITEM *aItem)
Clone aItem which can be used to restore the state of the item being edited when the user cancels the...
Definition: schframe.cpp:591
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 315 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().

317 {
318  BASE_SCREEN* screen = aPanel->GetScreen();
319  SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( screen->GetCurItem() );
320 
321  if( sheet == nullptr ) // Be sure we are using the right object
322  return;
323 
324  if( aErase )
325  sheet->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
326 
327  wxPoint pos = sheet->GetPosition();
328 
329  int width = aPanel->GetParent()->GetCrossHairPosition().x - pos.x;
330  int height = aPanel->GetParent()->GetCrossHairPosition().y - pos.y;
331 
332  // If the sheet doesn't have any pins, clamp the minimum size to the default values.
333  width = ( width < MIN_SHEET_WIDTH ) ? MIN_SHEET_WIDTH : width;
334  height = ( height < MIN_SHEET_HEIGHT ) ? MIN_SHEET_HEIGHT : height;
335 
336  if( sheet->HasPins() )
337  {
338  int gridSizeX = KiROUND( screen->GetGridSize().x );
339  int gridSizeY = KiROUND( screen->GetGridSize().y );
340 
341  // If the sheet has pins, use the pin positions to clamp the minimum width and height.
342  height = ( height < sheet->GetMinHeight() + gridSizeY ) ?
343  sheet->GetMinHeight() + gridSizeY : height;
344  width = ( width < sheet->GetMinWidth() + gridSizeX ) ?
345  sheet->GetMinWidth() + gridSizeX : width;
346  }
347 
348  wxPoint grid = aPanel->GetParent()->GetNearestGridPosition(
349  wxPoint( pos.x + width, pos.y + height ) );
350  sheet->Resize( wxSize( grid.x - pos.x, grid.y - pos.y ) );
351 
352  sheet->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
353 }
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:106
EDA_ITEM * GetCurItem() const
int GetMinHeight() const
Return the minimum height that the sheet can be resized based on the sheet pin positions.
Definition: sch_sheet.cpp:300
#define MIN_SHEET_WIDTH
Definition: sch_sheet.h:47
bool HasPins()
Definition: sch_sheet.h:374
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:174
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_sheet.h:540
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
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:425
wxPoint GetNearestGridPosition(const wxPoint &aPosition, wxRealPoint *aGridSize=NULL) const
Function GetNearestGridPosition returns the nearest aGridSize location to aPosition.
int GetMinWidth() const
Return the minimum width of the sheet based on the widths of the sheet pin text.
Definition: sch_sheet.cpp:260
const wxRealPoint & GetGridSize() const
Return the grid size of the currently selected grid.
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:187
#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:720