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(), and PAGE_LAYOUT_READER_PARSER::Parse().

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
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(), WORKSHEET_LAYOUT_IO::Format(), 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(), KIFACE_I::KifaceSearch(), and name.

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:127
const wxString ExpandEnvVarSubstitutions(const wxString &aString)
Function ExpandEnvVarSubstitutions replaces any environment variable references with their values...
Definition: common.cpp:254
const char * name
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:127
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 143 of file page_layout_writer.cpp.

References WORKSHEET_LAYOUT_IO::Format().

Referenced by PL_EDITOR_FRAME::SavePageLayoutDescrFile().

144 {
145  WORKSHEET_LAYOUT_FILEIO writer( aFullFileName );
146  writer.Format( this );
147 }
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 152 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().

153 {
154  WORKSHEET_LAYOUT_STRINGIO writer( aOutputString );
155  writer.Format( this );
156 }
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(), and PAGE_LAYOUT_READER_PARSER::parseSetup().

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 761 of file page_layout_reader.cpp.

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

Referenced by SetPageLayout().

762 {
763  ClearList();
764  PAGE_LAYOUT_READER_PARSER lp_parser( defaultPageLayout, wxT( "default page" ) );
765 
766  try
767  {
768  lp_parser.Parse( this );
769  }
770  catch( const IO_ERROR& ioe )
771  {
772  wxLogMessage( ioe.What() );
773  }
774 }
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(), and PAGE_LAYOUT_READER_PARSER::parseSetup().

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

804 {
805  wxString fullFileName = aFullFileName;
806 
807  if( !Append )
808  {
809  if( fullFileName.IsEmpty() )
810  wxGetEnv( wxT( "KICAD_WKSFILE" ), &fullFileName );
811 
812  if( fullFileName.IsEmpty() || !wxFileExists( fullFileName ) )
813  {
814  #if 0
815  if( !fullFileName.IsEmpty() )
816  {
817  wxLogMessage( wxT("Page layout file <%s> not found"),
818  fullFileName.GetData() );
819  }
820  #endif
822  return;
823  }
824  }
825 
826  wxFile wksFile( fullFileName );
827 
828  if( ! wksFile.IsOpened() )
829  {
830  if( !Append )
832  return;
833  }
834 
835  int filelen = wksFile.Length();
836  char * buffer = new char[filelen+10];
837 
838  if( wksFile.Read( buffer, filelen ) != filelen )
839  wxLogMessage( _("The file <%s> was not fully read"),
840  fullFileName.GetData() );
841  else
842  {
843  buffer[filelen]=0;
844 
845  if( ! Append )
846  ClearList();
847 
848  PAGE_LAYOUT_READER_PARSER pl_parser( buffer, fullFileName );
849 
850  try
851  {
852  pl_parser.Parse( this );
853  }
854  catch( const IO_ERROR& ioe )
855  {
856  wxLogMessage( ioe.What() );
857  }
858  }
859 
860  delete[] buffer;
861 }
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 780 of file page_layout_reader.cpp.

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

781 {
782  if( ! Append )
783  ClearList();
784 
785  PAGE_LAYOUT_READER_PARSER lp_parser( aPageLayout, wxT( "Sexpr_string" ) );
786 
787  try
788  {
789  lp_parser.Parse( this );
790  }
791  catch( const IO_ERROR& ioe )
792  {
793  wxLogMessage( ioe.What() );
794  }
795 }
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(), and PAGE_LAYOUT_READER_PARSER::parseSetup().

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(), and PAGE_LAYOUT_READER_PARSER::parseSetup().

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: