KiCad PCB EDA Suite
Loading...
Searching...
No Matches
ds_data_model.cpp
Go to the documentation of this file.
1
/*
2
* This program source code file is part of KiCad, a free EDA CAD application.
3
*
4
* Copyright (C) 1992-2018 Jean-Pierre Charras <jp.charras at wanadoo.fr>.
5
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6
*
7
*
8
* This program is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU General Public License
10
* as published by the Free Software Foundation; either version 2
11
* of the License, or (at your option) any later version.
12
*
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
17
*
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20
*/
21
22
23
/*
24
* The WS_DATA_ITEM_* classes define the basic shapes of a drawing sheet (frame references
25
* and title block). The list of these items is stored in a DS_DATA_MODEL instance.
26
*
27
* These items cannot be drawn or plotted "as is". They must be converted to WS_DRAW_*
28
* types. When building the draw list:
29
* - the DS_DATA_MODEL is used to create a DS_DRAW_ITEM_LIST
30
* - coordinates are converted to draw/plot coordinates.
31
* - texts are expanded if they contain format symbols.
32
* - items with m_RepeatCount > 1 are created m_RepeatCount times.
33
*
34
* The DS_DATA_MODEL is created only once.
35
* The WS_DRAW_ITEM_*s are created and maintained by the PlEditor, but are created each time
36
* they're needed for drawing by the clients (Eeschema, Pcbnew, etc.)
37
*
38
* The DS_DATA_MODEL instance is created from a S expression which describes the drawing sheet
39
* (can be the default drawing sheet or a custom file). This format is also used for undo/redo
40
* storage (wrapped in a DS_PROXY_UNDO_ITEM).
41
*/
42
43
#include <
kiface_base.h
>
44
#include <
title_block.h
>
45
#include <
common.h
>
46
#include <
drawing_sheet/ds_data_item.h
>
47
#include <
drawing_sheet/ds_data_model.h
>
48
#include <
drawing_sheet/ds_painter.h
>
49
50
51
// The layout shape used in the application
52
// It is accessible by DS_DATA_MODEL::GetTheInstance()
53
static
DS_DATA_MODEL
wksTheInstance
;
54
static
DS_DATA_MODEL
*
wksAltInstance
=
nullptr
;
55
56
DS_DATA_MODEL::DS_DATA_MODEL
() :
57
m_WSunits2Iu
( 1000.0 ),
58
m_DefaultLineWidth
( 0.0 ),
59
m_DefaultTextSize
(
TB_DEFAULT_TEXTSIZE
,
TB_DEFAULT_TEXTSIZE
),
60
m_DefaultTextThickness
( 0.0 ),
61
m_EditMode
( false )
62
{
63
m_allowVoidList
=
false
;
64
m_fileFormatVersionAtLoad
= 0;
65
m_leftMargin
= 10.0;
// the left page margin in mm
66
m_rightMargin
= 10.0;
// the right page margin in mm
67
m_topMargin
= 10.0;
// the top page margin in mm
68
m_bottomMargin
= 10.0;
// the bottom page margin in mm
69
}
70
71
72
DS_DATA_MODEL
&
DS_DATA_MODEL::GetTheInstance
()
73
{
74
if
(
wksAltInstance
)
75
return
*
wksAltInstance
;
76
else
77
return
wksTheInstance
;
78
}
79
80
81
void
DS_DATA_MODEL::SetAltInstance
(
DS_DATA_MODEL
* aLayout )
82
{
83
wksAltInstance
= aLayout;
84
}
85
86
87
void
DS_DATA_MODEL::SetupDrawEnvironment
(
const
PAGE_INFO
& aPageInfo,
double
aMilsToIU )
88
{
89
#define MILS_TO_MM ( 25.4 / 1000 )
90
91
m_WSunits2Iu
= aMilsToIU /
MILS_TO_MM
;
92
93
// Left top corner position
94
VECTOR2D
lt_corner;
95
lt_corner.
x
=
GetLeftMargin
();
96
lt_corner.
y
=
GetTopMargin
();
97
m_LT_Corner
= lt_corner;
98
99
// Right bottom corner position
100
VECTOR2D
rb_corner;
101
rb_corner.
x
= ( aPageInfo.
GetSizeMils
().x *
MILS_TO_MM
) -
GetRightMargin
();
102
rb_corner.
y
= ( aPageInfo.
GetSizeMils
().y *
MILS_TO_MM
) -
GetBottomMargin
();
103
m_RB_Corner
= rb_corner;
104
}
105
106
107
void
DS_DATA_MODEL::ClearList
()
108
{
109
for
(
DS_DATA_ITEM
* item :
m_list
)
110
delete
item;
111
112
m_list
.clear();
113
}
114
115
116
void
DS_DATA_MODEL::Append
(
DS_DATA_ITEM
* aItem )
117
{
118
m_list
.push_back( aItem );
119
}
120
121
122
void
DS_DATA_MODEL::Remove
(
DS_DATA_ITEM
* aItem )
123
{
124
auto
newEnd = std::remove(
m_list
.begin(),
m_list
.end(), aItem );
125
m_list
.erase( newEnd,
m_list
.end() );
126
}
127
128
129
DS_DATA_ITEM
*
DS_DATA_MODEL::GetItem
(
unsigned
aIdx )
const
130
{
131
if
( aIdx <
m_list
.size() )
132
return
m_list
[aIdx];
133
else
134
return
nullptr
;
135
}
136
DS_DATA_ITEM
Drawing sheet structure type definitions.
Definition
ds_data_item.h:92
DS_DATA_MODEL
Handle the graphic items list to draw/plot the frame and title block.
Definition
ds_data_model.h:35
DS_DATA_MODEL::m_list
std::vector< DS_DATA_ITEM * > m_list
Definition
ds_data_model.h:183
DS_DATA_MODEL::GetRightMargin
double GetRightMargin()
Definition
ds_data_model.h:62
DS_DATA_MODEL::SetupDrawEnvironment
void SetupDrawEnvironment(const PAGE_INFO &aPageInfo, double aMilsToIU)
Definition
ds_data_model.cpp:87
DS_DATA_MODEL::m_DefaultTextSize
VECTOR2D m_DefaultTextSize
Definition
ds_data_model.h:174
DS_DATA_MODEL::GetTheInstance
static DS_DATA_MODEL & GetTheInstance()
Return the instance of DS_DATA_MODEL used in the application.
Definition
ds_data_model.cpp:72
DS_DATA_MODEL::GetTopMargin
double GetTopMargin()
Definition
ds_data_model.h:65
DS_DATA_MODEL::m_rightMargin
double m_rightMargin
Definition
ds_data_model.h:189
DS_DATA_MODEL::m_DefaultLineWidth
double m_DefaultLineWidth
Definition
ds_data_model.h:173
DS_DATA_MODEL::GetItem
DS_DATA_ITEM * GetItem(unsigned aIdx) const
Definition
ds_data_model.cpp:129
DS_DATA_MODEL::GetBottomMargin
double GetBottomMargin()
Definition
ds_data_model.h:68
DS_DATA_MODEL::DS_DATA_MODEL
DS_DATA_MODEL()
Definition
ds_data_model.cpp:56
DS_DATA_MODEL::m_bottomMargin
double m_bottomMargin
Definition
ds_data_model.h:191
DS_DATA_MODEL::GetLeftMargin
double GetLeftMargin()
Definition
ds_data_model.h:59
DS_DATA_MODEL::m_DefaultTextThickness
double m_DefaultTextThickness
Definition
ds_data_model.h:175
DS_DATA_MODEL::m_RB_Corner
VECTOR2D m_RB_Corner
Definition
ds_data_model.h:171
DS_DATA_MODEL::m_WSunits2Iu
double m_WSunits2Iu
Definition
ds_data_model.h:169
DS_DATA_MODEL::Append
void Append(DS_DATA_ITEM *aItem)
Definition
ds_data_model.cpp:116
DS_DATA_MODEL::m_allowVoidList
bool m_allowVoidList
Definition
ds_data_model.h:184
DS_DATA_MODEL::ClearList
void ClearList()
Erase the list of items.
Definition
ds_data_model.cpp:107
DS_DATA_MODEL::Remove
void Remove(DS_DATA_ITEM *aItem)
Definition
ds_data_model.cpp:122
DS_DATA_MODEL::m_LT_Corner
VECTOR2D m_LT_Corner
Definition
ds_data_model.h:172
DS_DATA_MODEL::m_leftMargin
double m_leftMargin
Definition
ds_data_model.h:188
DS_DATA_MODEL::m_topMargin
double m_topMargin
Definition
ds_data_model.h:190
DS_DATA_MODEL::SetAltInstance
static void SetAltInstance(DS_DATA_MODEL *aLayout=nullptr)
Set an alternate instance of DS_DATA_MODEL.
Definition
ds_data_model.cpp:81
DS_DATA_MODEL::m_EditMode
bool m_EditMode
Definition
ds_data_model.h:176
DS_DATA_MODEL::m_fileFormatVersionAtLoad
int m_fileFormatVersionAtLoad
Definition
ds_data_model.h:187
PAGE_INFO
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition
page_info.h:75
PAGE_INFO::GetSizeMils
const VECTOR2D & GetSizeMils() const
Definition
page_info.h:146
VECTOR2::x
T x
Definition
vector2d.h:75
VECTOR2::y
T y
Definition
vector2d.h:75
common.h
The common library.
ds_data_item.h
TB_DEFAULT_TEXTSIZE
#define TB_DEFAULT_TEXTSIZE
Definition
ds_data_item.h:31
MILS_TO_MM
#define MILS_TO_MM
wksAltInstance
static DS_DATA_MODEL * wksAltInstance
Definition
ds_data_model.cpp:54
wksTheInstance
static DS_DATA_MODEL wksTheInstance
Definition
ds_data_model.cpp:53
ds_data_model.h
ds_painter.h
kiface_base.h
title_block.h
VECTOR2D
VECTOR2< double > VECTOR2D
Definition
vector2d.h:682
src
common
drawing_sheet
ds_data_model.cpp
Generated on Fri Jun 26 2026 00:05:32 for KiCad PCB EDA Suite by
1.13.2