KiCad PCB EDA Suite
sheet.cpp File Reference
#include <fctsys.h>
#include <sch_draw_panel.h>
#include <confirm.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 <sch_view.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 360 of file sheet.cpp.

References SCH_BASE_FRAME::AddToScreen(), EDA_ITEM::ClearFlags(), KIGFX::SCH_VIEW::ClearPreview(), SCH_SCREEN::GetCurItem(), EDA_DRAW_PANEL::GetParent(), EDA_DRAW_PANEL::GetScreen(), SCH_EDIT_FRAME::GetUndoItem(), SCH_DRAW_PANEL::GetView(), EDA_ITEM::IsMoving(), EDA_ITEM::IsNew(), EDA_ITEM::IsResized(), SCH_BASE_FRAME::RemoveFromScreen(), 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().

361 {
362  SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
363  SCH_ITEM* item = screen->GetCurItem();
364 
365  SCH_EDIT_FRAME* parent = (SCH_EDIT_FRAME*) aPanel->GetParent();
366 
367  if( (item == NULL) || (item->Type() != SCH_SHEET_T) || (parent == NULL) )
368  return;
369 
370  parent->SetRepeatItem( NULL );
371 
372  if( item->IsNew() )
373  {
374  delete item;
375  }
376  else if( item->IsMoving() || item->IsResized() )
377  {
378  parent->RemoveFromScreen( item );
379  delete item;
380 
381  item = parent->GetUndoItem();
382 
383  wxCHECK_RET( item != NULL, wxT( "Cannot restore undefined last sheet item." ) );
384 
385  parent->AddToScreen( item );
386 
387  // the owner of item is no more parent, this is the draw list of screen:
388  parent->SetUndoItem( NULL );
389 
390  item->ClearFlags();
391  }
392  else
393  {
394  item->ClearFlags();
395  }
396 
397  auto panel = static_cast<SCH_DRAW_PANEL*>( aPanel );
398  auto view = panel->GetView();
399  view->ClearPreview();
400 
401  screen->SetCurItem( NULL );
402 }
virtual BASE_SCREEN * GetScreen()=0
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
bool IsMoving() const
Definition: base_struct.h:221
bool IsResized() const
Definition: base_struct.h:225
bool IsNew() const
Definition: base_struct.h:219
void RemoveFromScreen(SCH_ITEM *aItem)
Remove an item from the screen (and view)
SCH_ITEM * GetUndoItem() const
Schematic editor (Eeschema) main window.
void SetRepeatItem(SCH_ITEM *aItem)
Clone aItem and owns that clone in this container.
virtual EDA_DRAW_FRAME * GetParent() const =0
SCH_ITEM * GetCurItem() const
Return the currently selected SCH_ITEM, overriding BASE_SCREEN::GetCurItem().
Definition: sch_screen.h:196
void ClearPreview()
Definition: sch_view.cpp:98
KIGFX::SCH_VIEW * GetView() const
void AddToScreen(SCH_ITEM *aItem)
Add an item to the screen (and view)
void SetCurItem(SCH_ITEM *aItem)
Sets the currently selected object, m_CurrentItem.
Definition: sch_screen.h:204
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:257
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...
static void resizeSheetWithMouseCursor ( EDA_DRAW_PANEL aPanel,
wxDC *  aDC,
const wxPoint aPosition,
bool  aErase 
)
static

Definition at line 316 of file sheet.cpp.

References SCH_SHEET::Clone(), 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_DRAW_PANEL::GetView(), SCH_SHEET::HasPins(), KIGFX::VIEW::Hide(), 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().

318 {
319  BASE_SCREEN* screen = aPanel->GetScreen();
320  SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( screen->GetCurItem() );
321 
322  if( sheet == nullptr ) // Be sure we are using the right object
323  return;
324 
325  wxPoint pos = sheet->GetPosition();
326 
327  int width = aPanel->GetParent()->GetCrossHairPosition().x - pos.x;
328  int height = aPanel->GetParent()->GetCrossHairPosition().y - pos.y;
329 
330  // If the sheet doesn't have any pins, clamp the minimum size to the default values.
331  width = ( width < MIN_SHEET_WIDTH ) ? MIN_SHEET_WIDTH : width;
332  height = ( height < MIN_SHEET_HEIGHT ) ? MIN_SHEET_HEIGHT : height;
333 
334  if( sheet->HasPins() )
335  {
336  int gridSizeX = KiROUND( screen->GetGridSize().x );
337  int gridSizeY = KiROUND( screen->GetGridSize().y );
338 
339  // If the sheet has pins, use the pin positions to clamp the minimum width and height.
340  height = ( height < sheet->GetMinHeight() + gridSizeY ) ?
341  sheet->GetMinHeight() + gridSizeY : height;
342  width = ( width < sheet->GetMinWidth() + gridSizeX ) ?
343  sheet->GetMinWidth() + gridSizeX : width;
344  }
345 
346  wxPoint grid = aPanel->GetParent()->GetNearestGridPosition(
347  wxPoint( pos.x + width, pos.y + height ) );
348  sheet->Resize( wxSize( grid.x - pos.x, grid.y - pos.y ) );
349 
350  auto panel = static_cast<SCH_DRAW_PANEL*>( aPanel );
351  auto view = panel->GetView();
352 
353  view->Hide( sheet );
354  view->ClearPreview();
355  view->AddToPreview( sheet->Clone() );
356 }
virtual BASE_SCREEN * GetScreen()=0
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hides the item in the view (e.g.
Definition: view.cpp:1488
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
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
virtual EDA_DRAW_FRAME * GetParent() const =0
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
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_sheet.h:547
KIGFX::SCH_VIEW * GetView() const
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
wxPoint GetNearestGridPosition(const wxPoint &aPosition, wxRealPoint *aGridSize=NULL) const
Return the nearest aGridSize location to aPosition.
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_sheet.cpp:98
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
#define MIN_SHEET_HEIGHT
Definition: sch_sheet.h:48
wxPoint GetCrossHairPosition(bool aInvertY=false) const
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:736