KiCad PCB EDA Suite
WORKSHEET_LAYOUT Class Reference

WORKSHEET_LAYOUT handles the graphic items list to draw/plot the title block and other items (page references ... More...

#include <worksheet_shape_builder.h>

Public Member Functions

 WORKSHEET_LAYOUT ()
 
 ~WORKSHEET_LAYOUT ()
 
double GetLeftMargin ()
 
double GetRightMargin ()
 
double GetTopMargin ()
 
double GetBottomMargin ()
 
void SetLeftMargin (double aMargin)
 
void SetRightMargin (double aMargin)
 
void SetTopMargin (double aMargin)
 
void SetBottomMargin (double aMargin)
 
void AllowVoidList (bool Allow)
 In Kicad applications, a page layout description is needed So if the list is empty, a default description is loaded, the first time a page layout is drawn. More...
 
bool VoidListAllowed ()
 
void ClearList ()
 erase the list of items More...
 
void Save (const wxString &aFullFileName)
 Save the description in a file. More...
 
void SaveInString (wxString &aOutputString)
 Save the description in a buffer. More...
 
void Append (WORKSHEET_DATAITEM *aItem)
 Add an item to the list of items. More...
 
void Insert (WORKSHEET_DATAITEM *aItem, unsigned aIdx)
 Insert an item to the list of items at position aIdx. More...
 
bool Remove (unsigned aIdx)
 Remove the item to the list of items at position aIdx. More...
 
bool Remove (WORKSHEET_DATAITEM *aItem)
 Remove the item to the list of items at position aIdx. More...
 
int GetItemIndex (WORKSHEET_DATAITEM *aItem) const
 
WORKSHEET_DATAITEMGetItem (unsigned aIdx) const
 
unsigned GetCount () const
 
void SetDefaultLayout ()
 Fills the list with the default layout shape. More...
 
void SetPageLayout (const wxString &aFullFileName=wxEmptyString, bool Append=false)
 Populates the list with a custom layout, or the default layout, if no custom layout available. More...
 
void SetPageLayout (const char *aPageLayout, bool Append=false)
 Populates the list from a S expr description stored in a string. More...
 

Static Public Member Functions

static WORKSHEET_LAYOUTGetTheInstance ()
 static function: returns the instance of WORKSHEET_LAYOUT used in the application More...
 
static void SetAltInstance (WORKSHEET_LAYOUT *aLayout=NULL)
 static function: Set an alternate instance of WORKSHEET_LAYOUT mainly used in page setting dialog More...
 
static const wxString MakeShortFileName (const wxString &aFullFileName, const wxString &aProjectPath)
 
static const wxString MakeFullFileName (const wxString &aShortFileName, const wxString &aProjectPath)
 Static function. More...
 

Private Attributes

std::vector< WORKSHEET_DATAITEM * > m_list
 
bool m_allowVoidList
 
double m_leftMargin
 
double m_rightMargin
 
double m_topMargin
 
double m_bottomMargin
 

Detailed Description

WORKSHEET_LAYOUT handles the graphic items list to draw/plot the title block and other items (page references ...

Definition at line 604 of file worksheet_shape_builder.h.

Constructor & Destructor Documentation

WORKSHEET_LAYOUT::WORKSHEET_LAYOUT ( )

Definition at line 66 of file class_worksheet_layout.cpp.

References m_allowVoidList, m_bottomMargin, m_leftMargin, m_rightMargin, and m_topMargin.

67 {
68  m_allowVoidList = false;
69  m_leftMargin = 10.0; // the left page margin in mm
70  m_rightMargin = 10.0; // the right page margin in mm
71  m_topMargin = 10.0; // the top page margin in mm
72  m_bottomMargin = 10.0; // the bottom page margin in mm
73 }
WORKSHEET_LAYOUT::~WORKSHEET_LAYOUT ( )
inline

Definition at line 618 of file worksheet_shape_builder.h.

References ClearList().

618 {ClearList(); }
void ClearList()
erase the list of items

Member Function Documentation

void WORKSHEET_LAYOUT::AllowVoidList ( bool  Allow)
inline

In Kicad applications, a page layout description is needed So if the list is empty, a default description is loaded, the first time a page layout is drawn.

However, in page layout editor, an empty list is acceptable. AllowVoidList allows or not the empty list

Definition at line 652 of file worksheet_shape_builder.h.

Referenced by PL_EDITOR_FRAME::Files_io(), and PL_EDITOR_FRAME::PL_EDITOR_FRAME().

652 { m_allowVoidList = Allow; }
void WORKSHEET_LAYOUT::Append ( WORKSHEET_DATAITEM aItem)
inline

Add an item to the list of items.

Definition at line 680 of file worksheet_shape_builder.h.

Referenced by Insert().

681  {
682  m_list.push_back( aItem );
683  }
std::vector< WORKSHEET_DATAITEM * > m_list
void WORKSHEET_LAYOUT::ClearList ( )

erase the list of items

Definition at line 122 of file class_worksheet_layout.cpp.

References m_list.

Referenced by PL_EDITOR_FRAME::Files_io(), PL_EDITOR_FRAME::PL_EDITOR_FRAME(), SetDefaultLayout(), SetPageLayout(), and ~WORKSHEET_LAYOUT().

123 {
124  for( unsigned ii = 0; ii < m_list.size(); ii++ )
125  delete m_list[ii];
126  m_list.clear();
127 }
std::vector< WORKSHEET_DATAITEM * > m_list
double WORKSHEET_LAYOUT::GetBottomMargin ( )
inline
unsigned WORKSHEET_LAYOUT::GetCount ( ) const
inline
Returns
the item count

Definition at line 713 of file worksheet_shape_builder.h.

Referenced by WS_DRAW_ITEM_LIST::BuildWorkSheetGraphicList(), Insert(), PL_EDITOR_FRAME::RebuildDesignTree(), DESIGN_TREE_FRAME::ReCreateDesignTree(), and Remove().

713 { return m_list.size(); }
std::vector< WORKSHEET_DATAITEM * > m_list
WORKSHEET_DATAITEM * WORKSHEET_LAYOUT::GetItem ( unsigned  aIdx) const
Returns
the item from its index aIdx, or NULL if does not exist

Definition at line 180 of file class_worksheet_layout.cpp.

References m_list.

Referenced by WS_DRAW_ITEM_LIST::BuildWorkSheetGraphicList(), EVT_MENU_RANGE(), PL_EDITOR_FRAME::RebuildDesignTree(), DESIGN_TREE_FRAME::ReCreateDesignTree(), and PL_EDITOR_FRAME::RedrawActiveWindow().

181 {
182  if( aIdx < m_list.size() )
183  return m_list[aIdx];
184  else
185  return NULL;
186 }
std::vector< WORKSHEET_DATAITEM * > m_list
int WORKSHEET_LAYOUT::GetItemIndex ( WORKSHEET_DATAITEM aItem) const
Returns
the index of aItem, or -1 if does not exist

Definition at line 164 of file class_worksheet_layout.cpp.

References m_list.

Referenced by EVT_MENU_RANGE(), and DESIGN_TREE_FRAME::GetSelectedItemIndex().

165 {
166  unsigned idx = 0;
167  while( idx < m_list.size() )
168  {
169  if( m_list[idx] == aItem )
170  return (int) idx;
171 
172  idx++;
173  }
174 
175  return -1;
176 }
std::vector< WORKSHEET_DATAITEM * > m_list
double WORKSHEET_LAYOUT::GetLeftMargin ( )
inline
double WORKSHEET_LAYOUT::GetRightMargin ( )
inline
double WORKSHEET_LAYOUT::GetTopMargin ( )
inline
void WORKSHEET_LAYOUT::Insert ( WORKSHEET_DATAITEM aItem,
unsigned  aIdx 
)

Insert an item to the list of items at position aIdx.

Definition at line 130 of file class_worksheet_layout.cpp.

References Append(), GetCount(), and m_list.

Referenced by PL_EDITOR_FRAME::AddPageLayoutItem().

131 {
132  if ( aIdx >= GetCount() )
133  Append( aItem );
134  else
135  m_list.insert( m_list.begin() + aIdx, aItem );
136 }
void Append(WORKSHEET_DATAITEM *aItem)
Add an item to the list of items.
unsigned GetCount() const
std::vector< WORKSHEET_DATAITEM * > m_list
const wxString WORKSHEET_LAYOUT::MakeFullFileName ( const wxString &  aShortFileName,
const wxString &  aProjectPath 
)
static

Static function.

Returns
a full filename from a short filename.
Parameters
aShortFileName= the short filename, which can be a relative
aProjectPath= the curr project absolute path (can be empty) or absolute path, and can include env variable reference ( ${envvar} expression ) if the short filename path is relative, it is expected relative to the project path or (if aProjectPath is empty or if the file does not exist) relative to kicad.pro (in template) If aShortFileName is absolute return aShortFileName

Definition at line 218 of file class_worksheet_layout.cpp.

References ExpandEnvVarSubstitutions(), SEARCH_STACK::FindValidPath(), Kiface(), and KIFACE_I::KifaceSearch().

Referenced by SCH_EDIT_FRAME::LoadProjectFile(), PCB_EDIT_FRAME::LoadProjectSettings(), and DIALOG_PAGES_SETTINGS::SavePageSettings().

220 {
221  wxString fullFileName = ExpandEnvVarSubstitutions( aShortFileName );
222 
223  if( fullFileName.IsEmpty() )
224  return fullFileName;
225 
226  wxFileName fn = fullFileName;
227 
228  if( fn.IsAbsolute() )
229  return fullFileName;
230 
231  // the path is not absolute: search it in project path, and then in
232  // kicad valid paths
233  if( !aProjectPath.IsEmpty() )
234  {
235  fn.MakeAbsolute( aProjectPath );
236 
237  if( wxFileExists( fn.GetFullPath() ) )
238  return fn.GetFullPath();
239  }
240 
241  fn = fullFileName;
242  wxString name = Kiface().KifaceSearch().FindValidPath( fn.GetFullName() );
243 
244  if( !name.IsEmpty() )
245  fullFileName = name;
246 
247  return fullFileName;
248 }
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
SEARCH_STACK & KifaceSearch()
Only for DSO specific 'non-library' files.
Definition: kiface_i.h:125
const wxString ExpandEnvVarSubstitutions(const wxString &aString)
Function ExpandEnvVarSubstitutions replaces any environment variable references with their values...
Definition: common.cpp:254
wxString FindValidPath(const wxString &aFileName) const
Definition: search_stack.h:71
const wxString WORKSHEET_LAYOUT::MakeShortFileName ( const wxString &  aFullFileName,
const wxString &  aProjectPath 
)
static
Returns
a short filename from a full filename: if the path is the current project path, or if the path is the same as kicad.pro (in template), returns the shortname else do nothing and returns a full filename
Parameters
aFullFileName= the full filename, which can be a relative
aProjectPath= the curr project absolute path (can be empty)

Definition at line 189 of file class_worksheet_layout.cpp.

References SEARCH_STACK::FindValidPath(), Kiface(), and KIFACE_I::KifaceSearch().

Referenced by DIALOG_PAGES_SETTINGS::OnWksFileSelection().

191 {
192  wxString shortFileName = aFullFileName;
193  wxFileName fn = aFullFileName;
194 
195  if( fn.IsRelative() )
196  return shortFileName;
197 
198  if( ! aProjectPath.IsEmpty() && aFullFileName.StartsWith( aProjectPath ) )
199  {
200  fn.MakeRelativeTo( aProjectPath );
201  shortFileName = fn.GetFullPath();
202  return shortFileName;
203  }
204 
205  wxString fileName = Kiface().KifaceSearch().FindValidPath( fn.GetFullName() );
206 
207  if( !fileName.IsEmpty() )
208  {
209  fn = fileName;
210  shortFileName = fn.GetFullName();
211  return shortFileName;
212  }
213 
214  return shortFileName;
215 }
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
SEARCH_STACK & KifaceSearch()
Only for DSO specific 'non-library' files.
Definition: kiface_i.h:125
wxString FindValidPath(const wxString &aFileName) const
Definition: search_stack.h:71
bool WORKSHEET_LAYOUT::Remove ( unsigned  aIdx)

Remove the item to the list of items at position aIdx.

Definition at line 139 of file class_worksheet_layout.cpp.

References GetCount(), and m_list.

Referenced by abortMoveItem(), EVT_MENU_RANGE(), and Remove().

140 {
141  if ( aIdx >= GetCount() )
142  return false;
143  m_list.erase( m_list.begin() + aIdx );
144  return true;
145 }
unsigned GetCount() const
std::vector< WORKSHEET_DATAITEM * > m_list
bool WORKSHEET_LAYOUT::Remove ( WORKSHEET_DATAITEM aItem)

Remove the item to the list of items at position aIdx.

Definition at line 148 of file class_worksheet_layout.cpp.

References m_list, and Remove().

149 {
150  unsigned idx = 0;
151 
152  while( idx < m_list.size() )
153  {
154  if( m_list[idx] == aItem )
155  break;
156 
157  idx++;
158  }
159 
160  return Remove( idx );
161 }
bool Remove(unsigned aIdx)
Remove the item to the list of items at position aIdx.
std::vector< WORKSHEET_DATAITEM * > m_list
void WORKSHEET_LAYOUT::Save ( const wxString &  aFullFileName)

Save the description in a file.

Parameters
aFullFileNamethe filename of the file to created

Definition at line 148 of file page_layout_writer.cpp.

References WORKSHEET_LAYOUT_IO::Format().

Referenced by PL_EDITOR_FRAME::SavePageLayoutDescrFile().

149 {
150  WORKSHEET_LAYOUT_FILEIO writer( aFullFileName );
151  writer.Format( this );
152 }
void WORKSHEET_LAYOUT::SaveInString ( wxString &  aOutputString)

Save the description in a buffer.

Parameters
aOutputString= a wxString to store the S expr string

Definition at line 157 of file page_layout_writer.cpp.

References WORKSHEET_LAYOUT_IO::Format().

Referenced by PL_EDITOR_FRAME::GetLayoutFromRedoList(), PL_EDITOR_FRAME::GetLayoutFromUndoList(), and PL_EDITOR_FRAME::SaveCopyInUndoList().

158 {
159  WORKSHEET_LAYOUT_STRINGIO writer( aOutputString );
160  writer.Format( this );
161 }
void WORKSHEET_LAYOUT::SetAltInstance ( WORKSHEET_LAYOUT aLayout = NULL)
static

static function: Set an alternate instance of WORKSHEET_LAYOUT mainly used in page setting dialog

Parameters
aLayout= the alternate page layout. if null, restore the basic page layout

Definition at line 92 of file class_worksheet_layout.cpp.

Referenced by DIALOG_PAGES_SETTINGS::UpdatePageLayoutExample().

93 {
94  wksAltInstance = aLayout;
95 }
static WORKSHEET_LAYOUT * wksAltInstance
void WORKSHEET_LAYOUT::SetBottomMargin ( double  aMargin)

Definition at line 116 of file class_worksheet_layout.cpp.

References m_bottomMargin.

Referenced by PROPERTIES_FRAME::CopyPrmsFromPanelToGeneral().

117 {
118  m_bottomMargin = aMargin; // the bottom page margin in mm
119 }
void WORKSHEET_LAYOUT::SetDefaultLayout ( )

Fills the list with the default layout shape.

Definition at line 775 of file page_layout_reader.cpp.

References ClearList(), PAGE_LAYOUT_READER_PARSER::Parse(), and IO_ERROR::What().

Referenced by SetPageLayout().

776 {
777  ClearList();
778  PAGE_LAYOUT_READER_PARSER lp_parser( defaultPageLayout, wxT( "default page" ) );
779 
780  try
781  {
782  lp_parser.Parse( this );
783  }
784  catch( const IO_ERROR& ioe )
785  {
786  wxLogMessage( ioe.What() );
787  }
788 }
const char defaultPageLayout[]
void ClearList()
erase the list of items
Class PAGE_LAYOUT_READER_PARSER holds data and functions pertinent to parsing a S-expression file for...
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
void WORKSHEET_LAYOUT::SetLeftMargin ( double  aMargin)

Definition at line 98 of file class_worksheet_layout.cpp.

References m_leftMargin.

Referenced by PROPERTIES_FRAME::CopyPrmsFromPanelToGeneral().

99 {
100  m_leftMargin = aMargin; // the left page margin in mm
101 }
void WORKSHEET_LAYOUT::SetPageLayout ( const wxString &  aFullFileName = wxEmptyString,
bool  Append = false 
)

Populates the list with a custom layout, or the default layout, if no custom layout available.

Parameters
aFullFileName= the custom page layout description file. if empty, loads the file defined by KICAD_WKSFILE and if its is not defined, uses the default internal description
Append= if true: do not delete old layout, and load only aFullFileName.

Definition at line 817 of file page_layout_reader.cpp.

References ClearList(), PAGE_LAYOUT_READER_PARSER::Parse(), SetDefaultLayout(), and IO_ERROR::What().

Referenced by WS_DRAW_ITEM_LIST::BuildWorkSheetGraphicList(), PL_EDITOR_FRAME::Files_io(), PL_EDITOR_FRAME::GetLayoutFromRedoList(), PL_EDITOR_FRAME::GetLayoutFromUndoList(), PL_EDITOR_FRAME::InsertPageLayoutDescrFile(), PL_EDITOR_FRAME::LoadPageLayoutDescrFile(), SCH_EDIT_FRAME::LoadProjectFile(), PCB_EDIT_FRAME::LoadProjectSettings(), DIALOG_PAGES_SETTINGS::OnWksFileSelection(), PL_EDITOR_FRAME::PL_EDITOR_FRAME(), and DIALOG_PAGES_SETTINGS::SavePageSettings().

818 {
819  wxString fullFileName = aFullFileName;
820 
821  if( !Append )
822  {
823  if( fullFileName.IsEmpty() )
824  wxGetEnv( wxT( "KICAD_WKSFILE" ), &fullFileName );
825 
826  if( fullFileName.IsEmpty() || !wxFileExists( fullFileName ) )
827  {
828  #if 0
829  if( !fullFileName.IsEmpty() )
830  {
831  wxLogMessage( wxT("Page layout file <%s> not found"),
832  fullFileName.GetData() );
833  }
834  #endif
836  return;
837  }
838  }
839 
840  wxFile wksFile( fullFileName );
841 
842  if( ! wksFile.IsOpened() )
843  {
844  if( !Append )
846  return;
847  }
848 
849  int filelen = wksFile.Length();
850  char * buffer = new char[filelen+10];
851 
852  if( wksFile.Read( buffer, filelen ) != filelen )
853  wxLogMessage( _("The file <%s> was not fully read"),
854  fullFileName.GetData() );
855  else
856  {
857  buffer[filelen]=0;
858 
859  if( ! Append )
860  ClearList();
861 
862  PAGE_LAYOUT_READER_PARSER pl_parser( buffer, fullFileName );
863 
864  try
865  {
866  pl_parser.Parse( this );
867  }
868  catch( const IO_ERROR& ioe )
869  {
870  wxLogMessage( ioe.What() );
871  }
872  }
873 
874  delete[] buffer;
875 }
void SetDefaultLayout()
Fills the list with the default layout shape.
void Append(WORKSHEET_DATAITEM *aItem)
Add an item to the list of items.
void ClearList()
erase the list of items
Class PAGE_LAYOUT_READER_PARSER holds data and functions pertinent to parsing a S-expression file for...
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
void WORKSHEET_LAYOUT::SetPageLayout ( const char *  aPageLayout,
bool  Append = false 
)

Populates the list from a S expr description stored in a string.

Parameters
aPageLayout= the S expr string
AppendDo not delete old layout if true and append aPageLayout the existing one.
aPageLayout= the S expr string

Definition at line 794 of file page_layout_reader.cpp.

References ClearList(), PAGE_LAYOUT_READER_PARSER::Parse(), and IO_ERROR::What().

795 {
796  if( ! Append )
797  ClearList();
798 
799  PAGE_LAYOUT_READER_PARSER lp_parser( aPageLayout, wxT( "Sexpr_string" ) );
800 
801  try
802  {
803  lp_parser.Parse( this );
804  }
805  catch( const IO_ERROR& ioe )
806  {
807  wxLogMessage( ioe.What() );
808  }
809 }
void Append(WORKSHEET_DATAITEM *aItem)
Add an item to the list of items.
void ClearList()
erase the list of items
Class PAGE_LAYOUT_READER_PARSER holds data and functions pertinent to parsing a S-expression file for...
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
void WORKSHEET_LAYOUT::SetRightMargin ( double  aMargin)

Definition at line 104 of file class_worksheet_layout.cpp.

References m_rightMargin.

Referenced by PROPERTIES_FRAME::CopyPrmsFromPanelToGeneral().

105 {
106  m_rightMargin = aMargin; // the right page margin in mm
107 }
void WORKSHEET_LAYOUT::SetTopMargin ( double  aMargin)

Definition at line 110 of file class_worksheet_layout.cpp.

References m_topMargin.

Referenced by PROPERTIES_FRAME::CopyPrmsFromPanelToGeneral().

111 {
112  m_topMargin = aMargin; // the top page margin in mm
113 }
bool WORKSHEET_LAYOUT::VoidListAllowed ( )
inline
Returns
true if an empty list is allowed (mainly allowed for page layout editor).

Definition at line 658 of file worksheet_shape_builder.h.

References m_allowVoidList.

Referenced by WS_DRAW_ITEM_LIST::BuildWorkSheetGraphicList().

658 { return m_allowVoidList; }

Member Data Documentation

bool WORKSHEET_LAYOUT::m_allowVoidList
private

Definition at line 607 of file worksheet_shape_builder.h.

Referenced by VoidListAllowed(), and WORKSHEET_LAYOUT().

double WORKSHEET_LAYOUT::m_bottomMargin
private

Definition at line 614 of file worksheet_shape_builder.h.

Referenced by GetBottomMargin(), SetBottomMargin(), and WORKSHEET_LAYOUT().

double WORKSHEET_LAYOUT::m_leftMargin
private

Definition at line 611 of file worksheet_shape_builder.h.

Referenced by GetLeftMargin(), SetLeftMargin(), and WORKSHEET_LAYOUT().

std::vector<WORKSHEET_DATAITEM*> WORKSHEET_LAYOUT::m_list
private

Definition at line 606 of file worksheet_shape_builder.h.

Referenced by ClearList(), GetItem(), GetItemIndex(), Insert(), and Remove().

double WORKSHEET_LAYOUT::m_rightMargin
private

Definition at line 612 of file worksheet_shape_builder.h.

Referenced by GetRightMargin(), SetRightMargin(), and WORKSHEET_LAYOUT().

double WORKSHEET_LAYOUT::m_topMargin
private

Definition at line 613 of file worksheet_shape_builder.h.

Referenced by GetTopMargin(), SetTopMargin(), and WORKSHEET_LAYOUT().


The documentation for this class was generated from the following files: