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

381 {
382  SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
383  SCH_ITEM* item = screen->GetCurItem();
384 
385  SCH_EDIT_FRAME* parent = (SCH_EDIT_FRAME*) aPanel->GetParent();
386 
387  if( (item == NULL) || (item->Type() != SCH_SHEET_T) || (parent == NULL) )
388  return;
389 
390  parent->SetRepeatItem( NULL );
391 
392  item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
393 
394  if( item->IsNew() )
395  {
396  delete item;
397  }
398  else if( item->IsMoving() || item->IsResized() )
399  {
400  screen->Remove( item );
401  delete item;
402 
403  item = parent->GetUndoItem();
404 
405  wxCHECK_RET( item != NULL, wxT( "Cannot restore undefined last sheet item." ) );
406 
407  screen->Append( item );
408  // the owner of item is no more parent, this is the draw list of screen:
409  parent->SetUndoItem( NULL );
410 
411  item->Draw( aPanel, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
412  item->ClearFlags();
413  }
414  else
415  {
416  item->ClearFlags();
417  }
418 
419  screen->SetCurItem( NULL );
420 }
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:73
KICAD_T Type() const
Function Type()
Definition: base_struct.h:227
bool IsMoving() const
Definition: base_struct.h:247
bool IsResized() const
Definition: base_struct.h:251
bool IsNew() const
Definition: base_struct.h:245
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:181
#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:194
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:283
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 338 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().

340 {
341  BASE_SCREEN* screen = aPanel->GetScreen();
342  SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( screen->GetCurItem() );
343 
344  if( sheet == nullptr ) // Be sure we are using the right object
345  return;
346 
347  if( aErase )
348  sheet->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
349 
350  wxPoint pos = sheet->GetPosition();
351 
352  int width = aPanel->GetParent()->GetCrossHairPosition().x - pos.x;
353  int height = aPanel->GetParent()->GetCrossHairPosition().y - pos.y;
354 
355  // If the sheet doesn't have any pins, clamp the minimum size to the default values.
356  width = ( width < MIN_SHEET_WIDTH ) ? MIN_SHEET_WIDTH : width;
357  height = ( height < MIN_SHEET_HEIGHT ) ? MIN_SHEET_HEIGHT : height;
358 
359  if( sheet->HasPins() )
360  {
361  int gridSizeX = KiROUND( screen->GetGridSize().x );
362  int gridSizeY = KiROUND( screen->GetGridSize().y );
363 
364  // If the sheet has pins, use the pin positions to clamp the minimum width and height.
365  height = ( height < sheet->GetMinHeight() + gridSizeY ) ?
366  sheet->GetMinHeight() + gridSizeY : height;
367  width = ( width < sheet->GetMinWidth() + gridSizeX ) ?
368  sheet->GetMinWidth() + gridSizeX : width;
369  }
370 
371  wxPoint grid = aPanel->GetParent()->GetNearestGridPosition(
372  wxPoint( pos.x + width, pos.y + height ) );
373  sheet->Resize( wxSize( grid.x - pos.x, grid.y - pos.y ) );
374 
375  sheet->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
376 }
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:73
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
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: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 ...)
Definition: base_screen.h:76
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:181
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: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.
Definition: base_screen.h:410
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:194
#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