2019-05-25 11:05:39 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2021-06-08 17:47:06 +00:00
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-05-25 11:05:39 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
#ifndef DS_DATA_MODEL_H
|
|
|
|
#define DS_DATA_MODEL_H
|
2019-05-25 11:05:39 +00:00
|
|
|
|
|
|
|
#include <math/vector2d.h>
|
|
|
|
#include <eda_text.h>
|
|
|
|
#include <bitmap_base.h>
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
class DS_DATA_ITEM;
|
2020-10-13 05:04:31 +00:00
|
|
|
class PAGE_INFO;
|
2019-05-25 11:05:39 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Handle the graphic items list to draw/plot the frame and title block.
|
2019-05-25 11:05:39 +00:00
|
|
|
*/
|
2021-02-22 23:47:17 +00:00
|
|
|
class DS_DATA_MODEL
|
2019-05-25 11:05:39 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_MODEL();
|
|
|
|
|
|
|
|
~DS_DATA_MODEL()
|
2019-05-25 13:56:52 +00:00
|
|
|
{
|
|
|
|
ClearList();
|
|
|
|
}
|
2019-05-25 11:05:39 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-22 23:47:17 +00:00
|
|
|
* static function: returns the instance of DS_DATA_MODEL used in the application
|
2019-05-25 11:05:39 +00:00
|
|
|
*/
|
2021-02-22 23:47:17 +00:00
|
|
|
static DS_DATA_MODEL& GetTheInstance();
|
2019-05-25 11:05:39 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-22 23:47:17 +00:00
|
|
|
* Set an alternate instance of DS_DATA_MODEL.
|
2020-12-21 23:42:21 +00:00
|
|
|
*
|
2021-05-30 22:56:24 +00:00
|
|
|
* @param aLayout the alternate drawing sheet; if null restore the default drawing sheet
|
2019-05-25 11:05:39 +00:00
|
|
|
*/
|
2021-07-15 19:26:35 +00:00
|
|
|
static void SetAltInstance( DS_DATA_MODEL* aLayout = nullptr );
|
2019-05-25 11:05:39 +00:00
|
|
|
|
2021-06-10 22:39:03 +00:00
|
|
|
int GetFileFormatVersionAtLoad() { return m_fileFormatVersionAtLoad; }
|
|
|
|
void SetFileFormatVersionAtLoad( int aVersion ) { m_fileFormatVersionAtLoad = aVersion; }
|
|
|
|
|
2019-05-25 11:05:39 +00:00
|
|
|
double GetLeftMargin() { return m_leftMargin; }
|
2019-05-25 13:56:52 +00:00
|
|
|
void SetLeftMargin( double aMargin ) { m_leftMargin = aMargin; }
|
|
|
|
|
2019-05-25 11:05:39 +00:00
|
|
|
double GetRightMargin() { return m_rightMargin; }
|
2019-05-25 13:56:52 +00:00
|
|
|
void SetRightMargin( double aMargin ) { m_rightMargin = aMargin; }
|
|
|
|
|
2019-05-25 11:05:39 +00:00
|
|
|
double GetTopMargin() { return m_topMargin; }
|
2019-05-25 13:56:52 +00:00
|
|
|
void SetTopMargin( double aMargin ) { m_topMargin = aMargin; }
|
|
|
|
|
2019-05-25 11:05:39 +00:00
|
|
|
double GetBottomMargin() { return m_bottomMargin; }
|
2019-05-25 13:56:52 +00:00
|
|
|
void SetBottomMargin( double aMargin ) { m_bottomMargin = aMargin; }
|
2019-05-25 11:05:39 +00:00
|
|
|
|
2019-05-25 13:56:52 +00:00
|
|
|
void SetupDrawEnvironment( const PAGE_INFO& aPageInfo, double aMilsToIU );
|
2019-05-25 11:05:39 +00:00
|
|
|
|
|
|
|
/**
|
2021-05-30 22:56:24 +00:00
|
|
|
* In KiCad applications, a drawing sheet is needed
|
|
|
|
* So if the list is empty, a default drawing sheet is loaded, the first time it is drawn.
|
2021-02-22 16:37:43 +00:00
|
|
|
* However, in drawing sheet editor an empty list is acceptable.
|
2019-05-25 11:05:39 +00:00
|
|
|
* AllowVoidList allows or not the empty list
|
|
|
|
*/
|
|
|
|
void AllowVoidList( bool Allow ) { m_allowVoidList = Allow; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true if an empty list is allowed
|
|
|
|
*/
|
|
|
|
bool VoidListAllowed() { return m_allowVoidList; }
|
|
|
|
|
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Erase the list of items.
|
2019-05-25 11:05:39 +00:00
|
|
|
*/
|
|
|
|
void ClearList();
|
|
|
|
|
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Save the description in a file.
|
|
|
|
*
|
|
|
|
* @param aFullFileName the filename of the file to created.
|
2019-05-25 11:05:39 +00:00
|
|
|
*/
|
|
|
|
void Save( const wxString& aFullFileName );
|
|
|
|
|
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Save the description in a buffer.
|
|
|
|
*
|
|
|
|
* @param aOutputString is a wxString to store the S expr string
|
2019-05-25 11:05:39 +00:00
|
|
|
*/
|
2021-06-09 09:47:14 +00:00
|
|
|
void SaveInString( wxString* aOutputString );
|
2019-05-25 11:05:39 +00:00
|
|
|
|
2019-05-26 18:35:20 +00:00
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Fill the given string with an S-expr serialization of the WS_DATA_ITEMs.
|
2019-05-26 18:35:20 +00:00
|
|
|
*/
|
2021-06-09 09:47:14 +00:00
|
|
|
void SaveInString( std::vector<DS_DATA_ITEM*>& aItemsList, wxString* aOutputString );
|
2019-05-26 18:35:20 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void Append( DS_DATA_ITEM* aItem );
|
|
|
|
void Remove( DS_DATA_ITEM* aItem );
|
2019-05-25 11:05:39 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* @return the index of aItem, or -1 if does not exist.
|
2019-05-25 11:05:39 +00:00
|
|
|
*/
|
2021-02-22 23:47:17 +00:00
|
|
|
int GetItemIndex( DS_DATA_ITEM* aItem ) const;
|
2019-05-25 11:05:39 +00:00
|
|
|
|
|
|
|
/**
|
Fix source comment/doc typos (follow-up)
Found via `codespell -q 3 -S *.po,./thirdparty -L aactual,acount,aline,alocation,alog,anormal,anumber,aother,apoints,aparent,aray,dout,einstance,modul,ot,overide,serie,te,,tesselate,tesselator,tht`
2021-07-03 22:37:31 +00:00
|
|
|
* @return is the item from its index \a aIdx, or NULL if does not exist.
|
2019-05-25 11:05:39 +00:00
|
|
|
*/
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_ITEM* GetItem( unsigned aIdx ) const;
|
2019-05-25 11:05:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return a reference to the items.
|
|
|
|
*/
|
2021-02-22 23:47:17 +00:00
|
|
|
std::vector<DS_DATA_ITEM*>& GetItems() { return m_list; }
|
2019-05-25 11:05:39 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* @return the item count.
|
2019-05-25 11:05:39 +00:00
|
|
|
*/
|
|
|
|
unsigned GetCount() const { return m_list.size(); }
|
|
|
|
|
|
|
|
void SetDefaultLayout();
|
|
|
|
void SetEmptyLayout();
|
|
|
|
|
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Return a string containing the empty layout shape.
|
2019-05-25 11:05:39 +00:00
|
|
|
*/
|
|
|
|
static wxString EmptyLayout();
|
|
|
|
|
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Return a string containing the empty layout shape.
|
2019-05-25 11:05:39 +00:00
|
|
|
*/
|
|
|
|
static wxString DefaultLayout();
|
|
|
|
|
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Populates the list with a custom layout or the default layout if no custom layout
|
|
|
|
* is available.
|
|
|
|
*
|
2021-05-30 22:56:24 +00:00
|
|
|
* @param aFullFileName is the custom drawing sheet file. If empty, load the file defined by
|
|
|
|
* KICAD_WKSFILE and if its not defined, the default internal drawing
|
|
|
|
* sheet.
|
2020-12-21 23:42:21 +00:00
|
|
|
* @param Append if true: do not delete old layout, and load only \a aFullFileName.
|
2019-05-25 11:05:39 +00:00
|
|
|
*/
|
2021-05-01 17:17:39 +00:00
|
|
|
bool LoadDrawingSheet( const wxString& aFullFileName = wxEmptyString, bool Append = false );
|
2019-05-25 11:05:39 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Populate the list from a S expr description stored in a string.
|
|
|
|
*
|
|
|
|
* @param aPageLayout is the S expr string.
|
|
|
|
* @param aAppend Do not delete old layout if true and append \a aPageLayout the existing
|
|
|
|
* one.
|
2019-05-25 11:05:39 +00:00
|
|
|
@param aSource is the layout source description.
|
|
|
|
*/
|
|
|
|
void SetPageLayout( const char* aPageLayout, bool aAppend = false,
|
|
|
|
const wxString& aSource = wxT( "Sexpr_string" ) );
|
|
|
|
|
|
|
|
/**
|
2021-09-23 15:44:39 +00:00
|
|
|
* Resolve a path which might be project-relative or contain env variable references.
|
|
|
|
*/
|
|
|
|
static const wxString ResolvePath( const wxString& aPath, const wxString& aProjectPath );
|
2020-12-21 23:42:21 +00:00
|
|
|
|
|
|
|
double m_WSunits2Iu; // conversion factor between
|
|
|
|
// ws units (mils) and draw/plot units
|
|
|
|
DPOINT m_RB_Corner; // coordinates of the right bottom corner (in mm)
|
|
|
|
DPOINT m_LT_Corner; // coordinates of the left top corner (in mm)
|
|
|
|
double m_DefaultLineWidth; // Used when object line width is 0
|
|
|
|
DSIZE m_DefaultTextSize; // Used when object text size is 0
|
|
|
|
double m_DefaultTextThickness; // Used when object text stroke width is 0
|
2021-02-22 16:37:43 +00:00
|
|
|
bool m_EditMode; // Used in drawing sheet editor to toggle variable substitution
|
2020-12-21 23:42:21 +00:00
|
|
|
// In normal mode (m_EditMode = false) the %format is
|
|
|
|
// replaced by the corresponding text.
|
|
|
|
// In edit mode (m_EditMode = true) the %format is
|
|
|
|
// displayed "as this"
|
|
|
|
|
|
|
|
private:
|
2021-02-22 23:47:17 +00:00
|
|
|
std::vector <DS_DATA_ITEM*> m_list;
|
2021-05-30 22:56:24 +00:00
|
|
|
bool m_allowVoidList; // If false, the default drawing sheet will be loaded the
|
|
|
|
// first time DS_DRAW_ITEM_LIST::BuildDrawItemsList is run
|
|
|
|
// (useful mainly for drawing sheet editor)
|
2021-06-10 22:39:03 +00:00
|
|
|
int m_fileFormatVersionAtLoad;
|
2020-12-21 23:42:21 +00:00
|
|
|
double m_leftMargin; // the left page margin in mm
|
|
|
|
double m_rightMargin; // the right page margin in mm
|
|
|
|
double m_topMargin; // the top page margin in mm
|
|
|
|
double m_bottomMargin; // the bottom page margin in mm
|
2019-05-25 11:05:39 +00:00
|
|
|
};
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
#endif // DS_DATA_MODEL_H
|