1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/////////////////////////////////////////////////////////////////////////////
// Name: dialog_edit_label.cpp
// Author: jean-pierre Charras
// Modified by:
// Created: 18/12/2008 15:46:26
// Licence: GPL
/////////////////////////////////////////////////////////////////////////////
#include "fctsys.h"
#include "wx/valgen.h"
#include "wxEeschemaStruct.h"
#include "common.h"
#include "class_drawpanel.h"
#include "general.h"
#include "drawtxt.h"
#include "confirm.h"
#include "sch_text.h"
#include "dialog_edit_label.h"
/* Edit the properties of the text (Label, Global label, graphic text).. )
* pointed by "aTextStruct"
*/
void SCH_EDIT_FRAME::EditSchematicText( SCH_TEXT* aTextItem )
{
if( aTextItem == NULL )
return;
DialogLabelEditor dialog( this, aTextItem );
dialog.ShowModal();
}
DialogLabelEditor::DialogLabelEditor( SCH_EDIT_FRAME* aParent, SCH_TEXT* aTextItem ) :
DialogLabelEditor_Base( aParent )
{
m_Parent = aParent;
m_CurrentText = aTextItem;
InitDialog();
GetSizer()->SetSizeHints( this );
Layout();
Fit();
SetMinSize( GetBestSize() );
Centre();
}
void DialogLabelEditor::InitDialog()
{
wxString msg;
bool multiLine = false;
if( m_CurrentText->m_MultilineAllowed )
{
m_textLabel = m_textLabelMultiLine;
m_textLabelSingleLine->Show(false);
multiLine = true;
}
else
{
m_textLabel = m_textLabelSingleLine;
m_textLabelMultiLine->Show(false);
}
m_textLabel->SetValue( m_CurrentText->m_Text );
m_textLabel->SetFocus();
switch( m_CurrentText->Type() )
{
case SCH_GLOBAL_LABEL_T:
SetTitle( _( "Global Label Properties" ) );
break;
case SCH_HIERARCHICAL_LABEL_T:
SetTitle( _( "Hierarchical Label Properties" ) );
break;
case SCH_LABEL_T:
SetTitle( _( "Label Properties" ) );
break;
case SCH_SHEET_PIN_T:
SetTitle( _( "Hierarchical Sheet Pin Properties." ) );
break;
default:
SetTitle( _( "Text Properties" ) );
m_textLabel->Disconnect( wxEVT_COMMAND_TEXT_ENTER,
wxCommandEventHandler ( DialogLabelEditor::OnEnterKey ),
NULL, this );
break;
}
int MINTEXTWIDTH = 40; // M's are big characters, a few establish a lot of width
int max_len = 0;
if ( !multiLine )
{
max_len =m_CurrentText->m_Text.Length();
}
else
{
// calculate the length of the biggest line
// we cannot use the length of the entire text that has no meaning
int curr_len = MINTEXTWIDTH;
int imax = m_CurrentText->m_Text.Len();
for( int count = 0; count < imax; count++ )
{
if( m_CurrentText->m_Text[count] == '\n' ||
m_CurrentText->m_Text[count] == '\r' ) // new line
{
curr_len = 0;
}
else
{
curr_len++;
if ( max_len < curr_len )
max_len = curr_len;
}
}
}
if( max_len < MINTEXTWIDTH )
max_len = MINTEXTWIDTH;
wxString textWidth;
textWidth.Append( 'M', MINTEXTWIDTH );
EnsureTextCtrlWidth( m_textLabel, &textWidth );
// Set validators
m_TextOrient->SetSelection( m_CurrentText->GetOrientation() );
m_TextShape->SetSelection( m_CurrentText->m_Shape );
int style = 0;
if( m_CurrentText->m_Italic )
style = 1;
if( m_CurrentText->m_Bold )
style += 2;
m_TextStyle->SetSelection( style );
wxString units = ReturnUnitSymbol( g_UserUnit, wxT( "(%s)" ) );
msg = _( "H" ) + units + _( " x W" ) + units;
m_staticSizeUnits->SetLabel( msg );
msg = ReturnStringFromValue( g_UserUnit, m_CurrentText->m_Size.x,
m_Parent->m_InternalUnits );
m_TextSize->SetValue( msg );
if( m_CurrentText->Type() != SCH_GLOBAL_LABEL_T
&& m_CurrentText->Type() != SCH_HIERARCHICAL_LABEL_T )
{
m_TextShape->Show( false );
}
m_sdbSizer1OK->SetDefault();
}
/*!
* wxTE_PROCESS_ENTER event handler for m_textLabel
*/
void DialogLabelEditor::OnEnterKey( wxCommandEvent& aEvent )
{
TextPropertiesAccept( aEvent );
}
/*!
* wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
*/
void DialogLabelEditor::OnOkClick( wxCommandEvent& aEvent )
{
TextPropertiesAccept( aEvent );
}
/*!
* wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CANCEL
*/
void DialogLabelEditor::OnCancelClick( wxCommandEvent& aEvent )
{
m_Parent->DrawPanel->MoveCursorToCrossHair();
EndModal( wxID_CANCEL );
}
void DialogLabelEditor::TextPropertiesAccept( wxCommandEvent& aEvent )
{
wxString text;
int value;
/* save old text in undo list if not already in edit */
if( m_CurrentText->m_Flags == 0 )
m_Parent->SaveCopyInUndoList( m_CurrentText, UR_CHANGED );
m_Parent->DrawPanel->RefreshDrawingRect( m_CurrentText->GetBoundingBox() );
text = m_textLabel->GetValue();
if( !text.IsEmpty() )
m_CurrentText->m_Text = text;
else if( (m_CurrentText->m_Flags & IS_NEW) == 0 )
DisplayError( this, _( "Empty Text!" ) );
m_CurrentText->SetOrientation( m_TextOrient->GetSelection() );
text = m_TextSize->GetValue();
value = ReturnValueFromString( g_UserUnit, text, m_Parent->m_InternalUnits );
m_CurrentText->m_Size.x = m_CurrentText->m_Size.y = value;
if( m_TextShape )
m_CurrentText->m_Shape = m_TextShape->GetSelection();
int style = m_TextStyle->GetSelection();
if( ( style & 1 ) )
m_CurrentText->m_Italic = 1;
else
m_CurrentText->m_Italic = 0;
if( ( style & 2 ) )
{
m_CurrentText->m_Bold = true;
m_CurrentText->m_Thickness = GetPenSizeForBold( m_CurrentText->m_Size.x );
}
else
{
m_CurrentText->m_Bold = false;
m_CurrentText->m_Thickness = 0;
}
m_Parent->OnModify();
/* Make the text size as new default size if it is a new text */
if( (m_CurrentText->m_Flags & IS_NEW) != 0 )
g_DefaultTextLabelSize = m_CurrentText->m_Size.x;
m_Parent->DrawPanel->RefreshDrawingRect( m_CurrentText->GetBoundingBox() );
m_Parent->DrawPanel->MoveCursorToCrossHair();
EndModal( wxID_OK );
}