/
Cosmetic.cpp
287 lines (253 loc) · 9.08 KB
/
Cosmetic.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
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/***************************************************************************
* Copyright (c) 2019 WandererFan <wandererfan@gmail.com> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library 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 Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <TopoDS_Edge.hxx>
# include <gp_Pnt.hxx>
# include <BRepBuilderAPI_MakeEdge.hxx>
#endif // #ifndef _PreComp_
#include <Base/Console.h>
#include <Base/Exception.h>
#include <Base/Parameter.h>
#include <Base/Tools2D.h>
#include <Base/Vector3D.h>
#include <App/Application.h>
#include <App/Material.h>
#include "DrawUtil.h"
#include "Geometry.h"
#include "Cosmetic.h"
using namespace TechDraw;
CosmeticVertex::CosmeticVertex()
{
pageLocation = Base::Vector3d(0.0, 0.0, 0.0);
modelLocation = Base::Vector3d(0.0, 0.0, 0.0);
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->
GetGroup("Preferences")->GetGroup("Mod/TechDraw/Decorations");
App::Color fcColor;
fcColor.setPackedValue(hGrp->GetUnsigned("VertexColor", 0x00000000));
linkGeom = -1;
color = fcColor;
size = 3.0;
style = 1;
visible = true;
}
CosmeticVertex::CosmeticVertex(Base::Vector3d loc)
{
pageLocation = loc;
modelLocation = loc;
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->
GetGroup("Preferences")->GetGroup("Mod/TechDraw/Decorations");
App::Color fcColor;
fcColor.setPackedValue(hGrp->GetUnsigned("VertexColor", 0xff000000));
linkGeom = -1;
color = fcColor;
//TODO: size = hGrp->getFloat("VertexSize",30.0);
size = 30.0;
style = 1; //TODO: implement styled vertexes
visible = true;
}
std::string CosmeticVertex::toCSV(void) const
{
std::stringstream ss;
ss << pageLocation.x << "," <<
pageLocation.y << "," <<
pageLocation.z << "," <<
modelLocation.x << "," <<
modelLocation.y << "," <<
modelLocation.z << "," <<
linkGeom << "," <<
color.asHexString() << "," <<
size << "," <<
style << "," <<
visible <<
std::endl;
return ss.str();
}
bool CosmeticVertex::fromCSV(std::string& lineSpec)
{
unsigned int maxCells = 11;
if (lineSpec.length() == 0) {
Base::Console().Message( "CosmeticVertex::fromCSV - lineSpec empty\n");
return false;
}
std::vector<std::string> values = split(lineSpec);
if (values.size() < maxCells) {
Base::Console().Message( "CosmeticVertex::fromCSV(%s) invalid CSV entry\n",lineSpec.c_str() );
return false;
}
double x = atof(values[0].c_str());
double y = atof(values[1].c_str());
double z = atof(values[2].c_str());
pageLocation = Base::Vector3d (x,y,z);
x = atof(values[3].c_str());
y = atof(values[4].c_str());
z = atof(values[5].c_str());
modelLocation = Base::Vector3d (x,y,z);
linkGeom = atoi(values[6].c_str());
color.fromHexString(values[7]);
size = atof(values[8].c_str());
style = atoi(values[9].c_str());
visible = atoi(values[10].c_str());
return true;
}
std::vector<std::string> CosmeticVertex::split(std::string csvLine)
{
// Base::Console().Message("CV::split - csvLine: %s\n",csvLine.c_str());
std::vector<std::string> result;
std::stringstream lineStream(csvLine);
std::string cell;
while(std::getline(lineStream,cell, ','))
{
result.push_back(cell);
}
return result;
}
void CosmeticVertex::dump(char* title)
{
Base::Console().Message("CV::dump - %s \n",title);
Base::Console().Message("CV::dump - %s \n",toCSV().c_str());
}
//******************************************
CosmeticEdge::CosmeticEdge()
{
geometry = new TechDrawGeometry::BaseGeom();
linkGeom = -1;
color = getDefEdgeColor();
width = getDefEdgeWidth();
style = getDefEdgeStyle();
visible = true;
}
CosmeticEdge::CosmeticEdge(Base::Vector3d p1, Base::Vector3d p2)
{
gp_Pnt gp1(p1.x,p1.y,p1.z);
gp_Pnt gp2(p2.x,p2.y,p2.z);
TopoDS_Edge e = BRepBuilderAPI_MakeEdge(gp1, gp2);
geometry = TechDrawGeometry::BaseGeom::baseFactory(e);
linkGeom = -1;
color = getDefEdgeColor();
width = getDefEdgeWidth();
style = getDefEdgeStyle();
visible = true;
}
CosmeticEdge::CosmeticEdge(TopoDS_Edge e)
{
geometry = TechDrawGeometry::BaseGeom::baseFactory(e);
linkGeom = -1;
color = getDefEdgeColor();
width = getDefEdgeWidth();
style = getDefEdgeStyle();
visible = true;
}
double CosmeticEdge::getDefEdgeWidth()
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->
GetGroup("Preferences")->GetGroup("Mod/TechDraw/Decorations");
std::string lgName = hGrp->GetASCII("LineGroup","FC 0.70mm");
auto lg = TechDraw::LineGroup::lineGroupFactory(lgName);
double width = lg->getWeight("Graphic");
delete lg;
return width;
}
App::Color CosmeticEdge::getDefEdgeColor()
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors");
App::Color fcColor;
fcColor.setPackedValue(hGrp->GetUnsigned("NormalColor", 0x00000000));
return fcColor;
}
int CosmeticEdge::getDefEdgeStyle()
{
return 1;
}
std::string CosmeticEdge::toCSV(void) const
{
std::stringstream ss;
Base::Vector3d start, end;
if (geometry != nullptr) {
Base::Vector2d p2d = geometry->getStartPoint();
start = Base::Vector3d(p2d.x, p2d.y, 0.0);
p2d = geometry->getEndPoint();
end = Base::Vector3d(p2d.x, p2d.y, 0.0);
}
ss << start.x << "," <<
start.y << "," <<
start.z << "," <<
end.x << "," <<
end.y << "," <<
end.z << "," <<
linkGeom << "," <<
color.asHexString() << "," <<
width << "," <<
style << "," <<
visible <<
std::endl;
return ss.str();
}
bool CosmeticEdge::fromCSV(std::string& lineSpec)
{
unsigned int maxCells = 11;
if (lineSpec.length() == 0) {
Base::Console().Message( "CosmeticEdge::fromCSV - lineSpec empty\n");
return false;
}
std::vector<std::string> values = split(lineSpec);
Base::Console().Message("CE::fromCSV - values: %d\n",values.size());
if (values.size() < maxCells) {
Base::Console().Message( "CosmeticEdge::fromCSV(%s) invalid CSV entry\n",lineSpec.c_str() );
return false;
}
Base::Vector3d start, end;
double x = atof(values[0].c_str());
double y = atof(values[1].c_str());
double z = atof(values[2].c_str());
start = Base::Vector3d (x,y,z);
x = atof(values[3].c_str());
y = atof(values[4].c_str());
z = atof(values[5].c_str());
end = Base::Vector3d (x,y,z);
linkGeom = atoi(values[6].c_str());
color.fromHexString(values[7]);
width = atof(values[8].c_str());
style = atoi(values[9].c_str());
visible = atoi(values[10].c_str());
return true;
}
//duplicate of CV routine. make static? or base class?
std::vector<std::string> CosmeticEdge::split(std::string csvLine)
{
Base::Console().Message("CE::split - csvLine: %s\n",csvLine.c_str());
std::vector<std::string> result;
std::stringstream lineStream(csvLine);
std::string cell;
while(std::getline(lineStream,cell, ','))
{
result.push_back(cell);
}
return result;
}
//duplicate of CV routine. make static? or base class?
void CosmeticEdge::dump(char* title)
{
Base::Console().Message("CE::dump - %s \n",title);
Base::Console().Message("CE::dump - %s \n",toCSV().c_str());
}