KiCad PCB EDA Suite
legacy_wx/eda_draw_frame.cpp File Reference
#include <fctsys.h>
#include <pgm_base.h>
#include <kiface_i.h>
#include <gr_basic.h>
#include <common.h>
#include <bitmaps.h>
#include <macros.h>
#include <id.h>
#include <class_drawpanel.h>
#include <base_screen.h>
#include <msgpanel.h>
#include <draw_frame.h>
#include <confirm.h>
#include <kicad_device_context.h>
#include <dialog_helpers.h>
#include <base_units.h>
#include <math/box2.h>
#include <lockfile.h>
#include <trace_helpers.h>
#include <wx/clipbrd.h>
#include <wx/fontdlg.h>
#include <wx/snglinst.h>
#include <view/view.h>
#include <view/view_controls.h>
#include <gal/graphics_abstraction_layer.h>
#include <tool/tool_manager.h>
#include <tool/tool_dispatcher.h>
#include <tool/actions.h>
#include <advanced_config.h>
#include <menus_helpers.h>
#include <page_info.h>
#include <title_block.h>
#include <worksheet_shape_builder.h>

Go to the source code of this file.

Macros

#define VIRT_MIN   (-MAX_AXIS/2.0)
 min X or Y coordinate in virtual space More...
 
#define VIRT_MAX   (MAX_AXIS/2.0)
 max X or Y coordinate in virtual space More...
 

Functions

static const wxString traceScrollSettings (wxT("KicadScrollSettings"))
 Definition for enabling and disabling scroll bar setting trace output. More...
 
static const wxString MaxUndoItemsEntry (wxT("DevelMaxUndoItems"))
 Integer to set the maximum number of undo items on the stack. More...
 
 EVT_MENU_RANGE (ID_POPUP_ZOOM_START_RANGE, ID_POPUP_ZOOM_END_RANGE, EDA_DRAW_FRAME::OnZoom) EVT_MENU_RANGE(ID_POPUP_GRID_LEVEL_1000
 
EDA_DRAW_FRAME::OnSelectGrid EVT_TOOL_RANGE (ID_TB_OPTIONS_SELECT_UNIT_MM, ID_TB_OPTIONS_SELECT_UNIT_INCH, EDA_DRAW_FRAME::OnSelectUnits) EVT_UPDATE_UI_RANGE(ID_TB_OPTIONS_SELECT_UNIT_MM
 
wxWindow * findDialog (wxWindowList &aList)
 
static bool DrawPageOnClipboard (EDA_DRAW_FRAME *aFrame)
 
void DrawPageLayout (wxDC *aDC, EDA_RECT *aClipBox, const PAGE_INFO &aPageInfo, const wxString &aFullSheetName, const wxString &aFileName, TITLE_BLOCK &aTitleBlock, int aSheetCount, int aSheetNumber, int aPenWidth, double aScalar, COLOR4D aColor, COLOR4D aAltColor, const wxString &aSheetLayer)
 Function DrawPageLayout is a core function to draw the page layout with the frame and the basic inscriptions. More...
 
static const wxString FirstRunShownKeyword (wxT("FirstRunShown"))
 

Variables

 ID_POPUP_GRID_USER
 
EDA_DRAW_FRAME::OnSelectGrid ID_TB_OPTIONS_SELECT_UNIT_INCH
 
static const double MAX_AXIS = INT_MAX - 100
 

Macro Definition Documentation

◆ VIRT_MAX

#define VIRT_MAX   (MAX_AXIS/2.0)

max X or Y coordinate in virtual space

Definition at line 1041 of file legacy_wx/eda_draw_frame.cpp.

◆ VIRT_MIN

#define VIRT_MIN   (-MAX_AXIS/2.0)

min X or Y coordinate in virtual space

Definition at line 1040 of file legacy_wx/eda_draw_frame.cpp.

Function Documentation

◆ DrawPageLayout()

void DrawPageLayout ( wxDC *  aDC,
EDA_RECT aClipBox,
const PAGE_INFO aPageInfo,
const wxString &  aFullSheetName,
const wxString &  aFileName,
TITLE_BLOCK aTitleBlock,
int  aSheetCount,
int  aSheetNumber,
int  aPenWidth,
double  aScalar,
COLOR4D  aColor,
COLOR4D  aAltColor,
const wxString &  aSheetLayer = wxEmptyString 
)

Function DrawPageLayout is a core function to draw the page layout with the frame and the basic inscriptions.

Parameters
aDCThe device context.
aClipBox= the clipping rect, or NULL if no clipping.
aPageInfofor margins and page size (in mils).
aFullSheetNameThe sheetpath (full sheet name), for basic inscriptions.
aFileNameThe file name, for basic inscriptions.
aTitleBlockThe sheet title block, for basic inscriptions.
aSheetCountThe number of sheets (for basic inscriptions).
aSheetNumberThe sheet number (for basic inscriptions).
aPenWidththe pen size The line width for drawing.
aScalarthe scale factor to convert from mils to internal units.
aColorThe color for drawing.
aAltColorThe color for items which need to be "hightlighted".
aSheetLayerThe layer from pcbnew.

Parameters used in aPageInfo

  • the size of the page layout.
  • the LTmargin The left top margin of the page layout.
  • the RBmargin The right bottom margin of the page layout.

Definition at line 2130 of file legacy_wx/eda_draw_frame.cpp.

2139 {
2140  WS_DRAW_ITEM_LIST drawList;
2141 
2142  drawList.SetPenSize( aPenWidth );
2143  drawList.SetMilsToIUfactor( aScalar );
2144  drawList.SetSheetNumber( aSheetNumber );
2145  drawList.SetSheetCount( aSheetCount );
2146  drawList.SetFileName( aFileName );
2147  drawList.SetSheetName( aFullSheetName );
2148  drawList.SetSheetLayer( aSheetLayer );
2149 
2150  drawList.BuildWorkSheetGraphicList( aPageInfo,
2151  aTitleBlock, aColor, aAltColor );
2152 
2153  // Draw item list
2154  drawList.Draw( aClipBox, aDC );
2155 }
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
void SetPenSize(int aPenSize)
Function SetPenSize Set the default pen size to draw/plot lines and texts.
void SetSheetLayer(const wxString &aSheetLayer)
Set the sheet layer to draw/plot.
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
void BuildWorkSheetGraphicList(const PAGE_INFO &aPageInfo, const TITLE_BLOCK &aTitleBlock, COLOR4D aColor, COLOR4D aAltColor)
Function BuildWorkSheetGraphicList is a core function for drawing or plotting the page layout with th...
void SetSheetCount(int aSheetCount)
Function SetSheetCount Set the value of the count of sheets, for basic inscriptions.
void SetMilsToIUfactor(double aScale)
Function SetMilsToIUfactor Set the scalar to convert pages units ( mils) to draw/plot units.
void SetSheetNumber(int aSheetNumber)
Function SetSheetNumber Set the value of the sheet number, for basic inscriptions.
void Draw(EDA_RECT *aClipBox, wxDC *aDC)
Draws the item list created by BuildWorkSheetGraphicList.

References WS_DRAW_ITEM_LIST::BuildWorkSheetGraphicList(), WS_DRAW_ITEM_LIST::Draw(), WS_DRAW_ITEM_LIST::SetFileName(), WS_DRAW_ITEM_LIST::SetMilsToIUfactor(), WS_DRAW_ITEM_LIST::SetPenSize(), WS_DRAW_ITEM_LIST::SetSheetCount(), WS_DRAW_ITEM_LIST::SetSheetLayer(), WS_DRAW_ITEM_LIST::SetSheetName(), and WS_DRAW_ITEM_LIST::SetSheetNumber().

◆ DrawPageOnClipboard()

bool DrawPageOnClipboard ( EDA_DRAW_FRAME aFrame)
static

Definition at line 2028 of file legacy_wx/eda_draw_frame.cpp.

2029 {
2030  bool DrawBlock = false;
2031  wxRect DrawArea;
2032  BASE_SCREEN* screen = aFrame->GetCanvas()->GetScreen();
2033 
2034  if( screen->IsBlockActive() )
2035  {
2036  DrawBlock = true;
2037  DrawArea.SetX( screen->m_BlockLocate.GetX() );
2038  DrawArea.SetY( screen->m_BlockLocate.GetY() );
2039  DrawArea.SetWidth( screen->m_BlockLocate.GetWidth() );
2040  DrawArea.SetHeight( screen->m_BlockLocate.GetHeight() );
2041  }
2042  else
2043  DrawArea.SetSize( aFrame->GetPageSizeIU() );
2044 
2045  // Calculate a reasonable dc size, in pixels, and the dc scale to fit
2046  // the drawings into the dc size
2047  // scale is the ratio resolution (in PPI) / internal units
2048  double ppi = 300; // Use 300 pixels per inch to create bitmap images on start
2049  double inch2Iu = 1000.0 * (double) screen->MilsToIuScalar();
2050  double scale = ppi / inch2Iu;
2051 
2052  wxSize dcsize = DrawArea.GetSize();
2053 
2054  int maxdim = std::max( dcsize.x, dcsize.y );
2055 
2056  // the max size in pixels of the bitmap used to byuild the sheet copy
2057  const int maxbitmapsize = 3000;
2058 
2059  while( int( maxdim * scale ) > maxbitmapsize )
2060  {
2061  ppi = ppi / 1.5;
2062  scale = ppi / inch2Iu;
2063  }
2064 
2065  dcsize.x *= scale;
2066  dcsize.y *= scale;
2067 
2068  // Set draw offset, zoom... to values needed to draw in the memory DC
2069  // after saving initial values:
2070  wxPoint tmp_startvisu = screen->m_StartVisu;
2071  double tmpzoom = screen->GetZoom();
2072  wxPoint old_org = screen->m_DrawOrg;
2073  screen->m_DrawOrg.x = screen->m_DrawOrg.y = 0;
2074  screen->m_StartVisu.x = screen->m_StartVisu.y = 0;
2075 
2076  screen->SetZoom( 1 ); // we use zoom = 1 in draw functions.
2077 
2078  wxMemoryDC dc;
2079  wxBitmap image( dcsize );
2080  dc.SelectObject( image );
2081 
2082  EDA_RECT tmp = *aFrame->GetCanvas()->GetClipBox();
2083  GRResetPenAndBrush( &dc );
2084  GRForceBlackPen( false );
2085  screen->m_IsPrinting = true;
2086  dc.SetUserScale( scale, scale );
2087 
2088  aFrame->GetCanvas()->SetClipBox( EDA_RECT( wxPoint( 0, 0 ),
2089  wxSize( 0x7FFFFF0, 0x7FFFFF0 ) ) );
2090 
2091  if( DrawBlock )
2092  {
2093  dc.SetClippingRegion( DrawArea );
2094  }
2095 
2096  dc.Clear();
2097  aFrame->GetCanvas()->EraseScreen( &dc );
2098  const LSET allLayersMask = LSET().set();
2099  aFrame->PrintPage( &dc, allLayersMask, false );
2100  screen->m_IsPrinting = false;
2101  aFrame->GetCanvas()->SetClipBox( tmp );
2102 
2103  bool success = true;
2104 
2105  if( wxTheClipboard->Open() )
2106  {
2107  // This data objects are held by the clipboard,
2108  // so do not delete them in the app.
2109  wxBitmapDataObject* clipbrd_data = new wxBitmapDataObject( image );
2110  wxTheClipboard->SetData( clipbrd_data );
2111  wxTheClipboard->Close();
2112  }
2113  else
2114  success = false;
2115 
2116  // Deselect Bitmap from DC in order to delete the MemoryDC safely
2117  // without deleting the bitmap
2118  dc.SelectObject( wxNullBitmap );
2119 
2120  GRForceBlackPen( false );
2121 
2122  screen->m_StartVisu = tmp_startvisu;
2123  screen->m_DrawOrg = old_org;
2124  screen->SetZoom( tmpzoom );
2125 
2126  return success;
2127 }
virtual BASE_SCREEN * GetScreen()=0
void GRResetPenAndBrush(wxDC *DC)
Definition: gr_basic.cpp:123
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
Definition: base_screen.h:214
bool IsBlockActive() const
Definition: base_screen.h:499
int GetX() const
Definition: eda_rect.h:109
double GetZoom() const
Function GetZoom returns the current "zoom factor", which is a measure of "internal units per device ...
Definition: base_screen.h:340
int GetWidth() const
Definition: eda_rect.h:117
virtual EDA_RECT * GetClipBox()
virtual const wxSize GetPageSizeIU() const =0
Works off of GetPageSettings() to return the size of the paper page in the internal units of this par...
void SetClipBox(const EDA_RECT &aRect)
wxPoint m_StartVisu
Coordinates in drawing units of the current view position (upper left corner of device)
Definition: base_screen.h:198
Class LSET is a set of PCB_LAYER_IDs.
virtual void PrintPage(wxDC *aDC, LSET aPrintMask, bool aPrintMirrorMode, void *aData=NULL)
Print the page pointed by current screen, set by the calling print function.
void GRForceBlackPen(bool flagforce)
Function GRForceBlackPen.
Definition: gr_basic.cpp:204
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:76
virtual int MilsToIuScalar()
Function MilsToIuScalar returns the scalar required to convert mils to internal units.
Definition: base_screen.h:245
virtual bool SetZoom(double iu_per_du)
Function SetZoom adjusts the current zoom factor.
virtual EDA_DRAW_PANEL * GetCanvas() const
Definition: draw_frame.h:395
bool m_IsPrinting
Definition: base_screen.h:220
int GetHeight() const
Definition: eda_rect.h:118
const int scale
#define max(a, b)
Definition: auxiliary.h:86
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
wxPoint m_DrawOrg
offsets for drawing the circuit on the screen
Definition: base_screen.h:183
int GetY() const
Definition: eda_rect.h:110
virtual void EraseScreen(wxDC *DC)
Function OnMouseWheel handles mouse wheel events.

References EDA_DRAW_PANEL::EraseScreen(), EDA_DRAW_FRAME::GetCanvas(), EDA_DRAW_PANEL::GetClipBox(), EDA_RECT::GetHeight(), EDA_DRAW_FRAME::GetPageSizeIU(), EDA_DRAW_PANEL::GetScreen(), EDA_RECT::GetWidth(), EDA_RECT::GetX(), EDA_RECT::GetY(), BASE_SCREEN::GetZoom(), GRForceBlackPen(), GRResetPenAndBrush(), BASE_SCREEN::IsBlockActive(), BASE_SCREEN::m_BlockLocate, BASE_SCREEN::m_DrawOrg, BASE_SCREEN::m_IsPrinting, BASE_SCREEN::m_StartVisu, max, BASE_SCREEN::MilsToIuScalar(), EDA_DRAW_FRAME::PrintPage(), scale, EDA_DRAW_PANEL::SetClipBox(), and BASE_SCREEN::SetZoom().

◆ EVT_MENU_RANGE()

◆ EVT_TOOL_RANGE()

◆ findDialog()

wxWindow* findDialog ( wxWindowList &  aList)

Definition at line 1945 of file legacy_wx/eda_draw_frame.cpp.

1946 {
1947  for( wxWindow* window : aList )
1948  {
1949  if( dynamic_cast<DIALOG_SHIM*>( window ) )
1950  return window;
1951  }
1952  return NULL;
1953 }

◆ FirstRunShownKeyword()

static const wxString FirstRunShownKeyword ( wxT("FirstRunShown")  )
static

◆ MaxUndoItemsEntry()

static const wxString MaxUndoItemsEntry ( wxT("DevelMaxUndoItems")  )
static

Integer to set the maximum number of undo items on the stack.

If zero, undo items are unlimited.

Present as:

  • SchematicFrameDevelMaxUndoItems (file: eeschema)
  • LibeditFrameDevelMaxUndoItems (file: eeschema)
  • PcbFrameDevelMaxUndoItems (file: pcbnew)
  • ModEditFrameDevelMaxUndoItems (file: pcbnew)

◆ traceScrollSettings()

static const wxString traceScrollSettings ( wxT("KicadScrollSettings")  )
static

Definition for enabling and disabling scroll bar setting trace output.

See the wxWidgets documentation on useing the WXTRACE environment variable.

Variable Documentation

◆ ID_POPUP_GRID_USER

ID_POPUP_GRID_USER

Definition at line 114 of file legacy_wx/eda_draw_frame.cpp.

◆ ID_TB_OPTIONS_SELECT_UNIT_INCH

EDA_DRAW_FRAME::OnSelectGrid ID_TB_OPTIONS_SELECT_UNIT_INCH

Definition at line 127 of file legacy_wx/eda_draw_frame.cpp.

◆ MAX_AXIS

const double MAX_AXIS = INT_MAX - 100
static

Definition at line 1038 of file legacy_wx/eda_draw_frame.cpp.