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 <sch_edit_frame.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 394 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().

395 {
396  SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
397  SCH_ITEM* item = screen->GetCurItem();
398 
399  SCH_EDIT_FRAME* parent = (SCH_EDIT_FRAME*) aPanel->GetParent();
400 
401  if( (item == NULL) || (item->Type() != SCH_SHEET_T) || (parent == NULL) )
402  return;
403 
404  parent->SetRepeatItem( NULL );
405 
406  item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
407 
408  if( item->IsNew() )
409  {
410  delete item;
411  }
412  else if( item->IsMoving() || item->IsResized() )
413  {
414  screen->Remove( item );
415  delete item;
416 
417  item = parent->GetUndoItem();
418 
419  wxCHECK_RET( item != NULL, wxT( "Cannot restore undefined last sheet item." ) );
420 
421  screen->Append( item );
422  // the owner of item is no more parent, this is the draw list of screen:
423  parent->SetUndoItem( NULL );
424 
425  item->Draw( aPanel, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
426  item->ClearFlags();
427  }
428  else
429  {
430  item->ClearFlags();
431  }
432 
433  screen->SetCurItem( NULL );
434 }
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:73
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
bool IsMoving() const
Definition: base_struct.h:229
bool IsResized() const
Definition: base_struct.h:233
bool IsNew() const
Definition: base_struct.h:227
SCH_ITEM * GetUndoItem() const
Schematic editor (Eeschema) main window.
void Remove(SCH_ITEM *aItem)
Remove aItem from the schematic associated with this screen.
Definition: sch_screen.cpp:169
void SetRepeatItem(SCH_ITEM *aItem)
Clone aItem and owns that clone in this container.
SCH_ITEM * GetCurItem() const
Return the currently selected SCH_ITEM, overriding BASE_SCREEN::GetCurItem().
Definition: sch_screen.h:174
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:180
#define GR_DEFAULT_DRAWMODE
Definition: general.h:70
void Append(SCH_ITEM *aItem)
Definition: sch_screen.h:140
void SetCurItem(SCH_ITEM *aItem)
Sets the currently selected object, m_CurrentItem.
Definition: sch_screen.h:182
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:193
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:265
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...
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 352 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().

354 {
355  BASE_SCREEN* screen = aPanel->GetScreen();
356  SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( screen->GetCurItem() );
357 
358  if( sheet == nullptr ) // Be sure we are using the right object
359  return;
360 
361  if( aErase )
362  sheet->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
363 
364  wxPoint pos = sheet->GetPosition();
365 
366  int width = aPanel->GetParent()->GetCrossHairPosition().x - pos.x;
367  int height = aPanel->GetParent()->GetCrossHairPosition().y - pos.y;
368 
369  // If the sheet doesn't have any pins, clamp the minimum size to the default values.
370  width = ( width < MIN_SHEET_WIDTH ) ? MIN_SHEET_WIDTH : width;
371  height = ( height < MIN_SHEET_HEIGHT ) ? MIN_SHEET_HEIGHT : height;
372 
373  if( sheet->HasPins() )
374  {
375  int gridSizeX = KiROUND( screen->GetGridSize().x );
376  int gridSizeY = KiROUND( screen->GetGridSize().y );
377 
378  // If the sheet has pins, use the pin positions to clamp the minimum width and height.
379  height = ( height < sheet->GetMinHeight() + gridSizeY ) ?
380  sheet->GetMinHeight() + gridSizeY : height;
381  width = ( width < sheet->GetMinWidth() + gridSizeX ) ?
382  sheet->GetMinWidth() + gridSizeX : width;
383  }
384 
385  wxPoint grid = aPanel->GetParent()->GetNearestGridPosition(
386  wxPoint( pos.x + width, pos.y + height ) );
387  sheet->Resize( wxSize( grid.x - pos.x, grid.y - pos.y ) );
388 
389  sheet->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
390 }
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:73
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:106
EDA_ITEM * GetCurItem() const
Definition: base_screen.h:233
int GetMinHeight() const
Return the minimum height that the sheet can be resized based on the sheet pin positions.
Definition: sch_sheet.cpp:301
#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 ...)
Definition: base_screen.h:76
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:180
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_sheet.h:547
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:426
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:261
const wxRealPoint & GetGridSize() const
Return the grid size of the currently selected grid.
Definition: base_screen.h:410
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:193
#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:721