forked from Heeks/heekscad-old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNiceTextCtrl.cpp
159 lines (142 loc) · 3.11 KB
/
NiceTextCtrl.cpp
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
// NiceTextCtrl.cpp
// Copyright (c) 2010, Dan Heeks
// This program is released under the BSD license. See the file COPYING for details.
#include <stdafx.h>
#include "NiceTextCtrl.h"
#include "ObjList.h"
CDoubleCtrl::CDoubleCtrl(wxWindow* parent, wxWindowID id, double factor)
:wxTextCtrl(parent, id), m_factor(factor)
{
}
double CDoubleCtrl::GetValue()
{
double value = 0.0;
if(!wxTextCtrl::GetValue().ToDouble(&value))return 0.0;
else return value / m_factor;
}
wxString CDoubleCtrl::DoubleToString(double value)
{
#ifdef UNICODE
std::wostringstream _value;
#else
std::ostringstream _value;
#endif
_value.imbue(std::locale("C"));
_value<<std::setprecision(10);
_value << value * m_factor;
return(_value.str().c_str());
}
void CDoubleCtrl::SetValue(double value)
{
wxTextCtrl::SetValue(DoubleToString(value));
}
#ifdef HEEKSCAD
#define VIEW_UNITS (wxGetApp().m_view_units)
#else
#define VIEW_UNITS (heeksCAD->GetViewUnits())
#endif
CLengthCtrl::CLengthCtrl(wxWindow* parent, wxWindowID id)
:CDoubleCtrl(parent, id, 1/VIEW_UNITS)
{
}
CObjectIdsCtrl::CObjectIdsCtrl(wxWindow* parent, wxWindowID id)
:wxTextCtrl(parent, id)
{
}
#ifdef OP_SKETCHES_AS_CHILDREN
void CObjectIdsCtrl::GetAddChildren(HeeksObj* object, int group_type)
{
#ifdef HEEKSCAD
wxGetApp().CreateUndoPoint();
#else
heeksCAD->CreateUndoPoint();
#endif
((ObjList*)object)->Clear();
wxString str = wxTextCtrl::GetValue();
wxString s = _T("");
unsigned int len = str.Len();
for(unsigned int i = 0; i <= len; i++)
{
if(i == len || str[i] == _T(' '))
{
long id = 0;
if(s.ToLong(&id))
{
if(id != 0)
{
#ifdef HEEKSCAD
HeeksObj *child = wxGetApp().GetIDObject( group_type, id );
#else
HeeksObj *child = heeksCAD->GetIDObject( group_type, id );
#endif
if (child != NULL)
{
object->Add( child, NULL );
}
}
}
s = _T("");
}
else
{
s.Append(str[i]);
}
}
#ifdef HEEKSCAD
wxGetApp().Changed();
#else
heeksCAD->Changed();
#endif
}
void CObjectIdsCtrl::SetFromChildren(HeeksObj* object, int group_type)
{
wxString str;
int i = 0;
for (HeeksObj *child = object->GetFirstChild(); child != NULL; child = object->GetNextChild())
{
if(child->GetIDGroupType() == group_type)
{
if(i != 0)str.Append(_T(" "));
str.Append(wxString::Format(_T("%d"), child->GetID()));
i++;
}
}
wxTextCtrl::SetValue(str);
}
#else
void CObjectIdsCtrl::GetIDList(std::list<int> &id_list)
{
wxString str = wxTextCtrl::GetValue();
wxString s = _T("");
unsigned int len = str.Len();
for(unsigned int i = 0; i <= len; i++)
{
if(i == len || str[i] == _T(' '))
{
long id = 0;
if(s.ToLong(&id))
{
if(id != 0)id_list.push_back(id);
}
s = _T("");
}
else
{
s.Append(str[i]);
}
}
}
void CObjectIdsCtrl::SetFromIDList(std::list<int> &id_list)
{
wxString str;
int i = 0;
for (std::list<int>::iterator It = id_list.begin(); It != id_list.end(); It++)
{
int id = *It;
if(i != 0)str.Append(_T(" "));
str.Append(wxString::Format(_T("%d"), id));
i++;
}
wxTextCtrl::SetValue(str);
}
#endif