FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
solvespace/src/solvespace.h at master · ppd/solvespace · GitHub
ppd
solvespace
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
solvespace
/
src
/
solvespace.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
836 lines (730 loc) · 26.2 KB
Breadcrumbs
solvespace
/
src
/
solvespace.h
Copy path
File metadata and controls
836 lines (730 loc) · 26.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
//
-----------------------------------------------------------------------------
//
All declarations not grouped specially elsewhere.
//
//
Copyright 2008-2013 Jonathan Westhues.
//
-----------------------------------------------------------------------------
#
ifndef
SOLVESPACE_H
#
define
SOLVESPACE_H
#
include
"
resource.h
"
#
include
"
platform/platform.h
"
#
include
"
platform/gui.h
"
#
include
<
cctype
>
#
include
<
climits
>
#
include
<
cmath
>
#
include
<
csetjmp
>
#
include
<
cstdarg
>
#
include
<
cstddef
>
#
include
<
cstdint
>
#
include
<
cstdio
>
#
include
<
cstdlib
>
#
include
<
cstring
>
#
include
<
algorithm
>
#
include
<
chrono
>
#
include
<
functional
>
#
include
<
locale
>
#
include
<
map
>
#
include
<
memory
>
#
include
<
set
>
#
include
<
sstream
>
#
include
<
string
>
#
include
<
unordered_map
>
#
include
<
unordered_set
>
#
include
<
vector
>
#
define
EIGEN_NO_DEBUG
#
undef
Success
#
include
<
Eigen/SparseCore
>
//
We declare these in advance instead of simply using FT_Library
//
(defined as typedef FT_LibraryRec_* FT_Library) because including
//
freetype.h invokes indescribable horrors and we would like to avoid
//
doing that every time we include solvespace.h.
struct
FT_LibraryRec_
;
struct
FT_FaceRec_
;
typedef
struct
_cairo
cairo_t
;
typedef
struct
_cairo_surface
cairo_surface_t
;
//
The few floating-point equality comparisons in SolveSpace have been
//
carefully considered, so we disable the -Wfloat-equal warning for them
#
ifdef
__clang__
#
define
EXACT
(
expr
) \
(
_Pragma
(
"
clang diagnostic push
"
) \
_Pragma
(
"
clang diagnostic ignored
\"
-Wfloat-equal
\"
"
) \
(expr) \
_Pragma(
"
clang diagnostic pop
"
))
#
else
#
define
EXACT
(
expr
) (expr)
#
endif
//
Debugging functions
#
if
defined(__GNUC__)
#
define
ssassert
(
condition, message
) \
do
{ \
if
(
__builtin_expect
((condition),
true
) ==
false
) { \
SolveSpace::AssertFailure
(__FILE__, __LINE__, __func__, #condition, message); \
__builtin_unreachable
(); \
} \
}
while
(
0
)
#
else
#
define
ssassert
(
condition, message
) \
do
{ \
if
((condition) ==
false
) { \
SolveSpace::AssertFailure
(__FILE__, __LINE__, __func__, #condition, message); \
abort
(); \
} \
}
while
(
0
)
#
endif
#
define
dbp
SolveSpace::Platform::DebugPrint
#
define
DBPTRI
(
tri
) \
dbp
(
"
tri: (%.3f %.3f %.3f) (%.3f %.3f %.3f) (%.3f %.3f %.3f)
"
, \
CO
((tri).a), CO((tri).b), CO((tri).c))
namespace SolveSpace {
using
std::min;
using
std::max;
using
std::swap;
using
std::fabs;
[[noreturn]]
void
AssertFailure
(
const
char
*file,
unsigned
line,
const
char
*function,
const
char
*condition,
const
char
*message);
#
if
defined(__GNUC__)
__attribute__
((
__format__
(__printf__,
1
,
2
)))
#
endif
std::string
ssprintf
(
const
char
*fmt, ...);
inline
bool
IsReasonable
(
double
x) {
return
std::isnan
(x) || x >
1e11
|| x < -
1e11
;
}
inline
int
WRAP
(
int
v,
int
n) {
//
Clamp it to the range [0, n)
while
(v >= n) v -= n;
while
(v <
0
) v += n;
return
v;
}
inline
double
WRAP_NOT_0
(
double
v,
double
n) {
//
Clamp it to the range (0, n]
while
(v > n) v -= n;
while
(v <=
0
) v += n;
return
v;
}
inline
double
WRAP_SYMMETRIC
(
double
v,
double
n) {
//
Clamp it to the range (-n/2, n/2]
while
(v > n/
2
) v -= n;
while
(v <= -n/
2
) v += n;
return
v;
}
#
define
CO
(
v
) (v).x, (v).y, (v).z
static
constexpr
double
ANGLE_COS_EPS
=
1e-6
;
static
constexpr
double
LENGTH_EPS
=
1e-6
;
static
constexpr
double
VERY_POSITIVE
=
1e10
;
static
constexpr
double
VERY_NEGATIVE
= -
1e10
;
using
Platform::AllocTemporary;
using
Platform::FreeAllTemporary;
class
Expr
;
class
ExprVector
;
class
ExprQuaternion
;
class
RgbaColor
;
enum
class
Command
:
uint32_t
;
enum
class
Unit
:
uint32_t
{
MM
=
0
,
INCHES
,
METERS
,
FEET_INCHES
};
template
<
class
Key
,
class
T
>
using
handle_map = std::map<Key, T>;
class
Group
;
class
SSurface
;
#
include
"
dsc.h
"
#
include
"
polygon.h
"
#
include
"
srf/surface.h
"
#
include
"
render/render.h
"
class
Entity
;
class
hEntity
;
class
Param
;
class
hParam
;
typedef
IdList<Entity,hEntity> EntityList;
typedef
IdList<Param,hParam> ParamList;
enum
class
SolveResult
:
uint32_t
{
OKAY
=
0
,
DIDNT_CONVERGE
=
10
,
REDUNDANT_OKAY
=
11
,
REDUNDANT_DIDNT_CONVERGE
=
12
,
TOO_MANY_UNKNOWNS
=
20
};
#
include
"
sketch.h
"
#
include
"
ui.h
"
#
include
"
expr.h
"
//
Utility functions that are provided in the platform-independent code.
class
utf8_iterator
: std::iterator<std::forward_iterator_tag,
char32_t
> {
const
char
*p, *n;
public:
utf8_iterator
(
const
char
*p) : p(p), n(
NULL
) {}
bool
operator
==(
const
utf8_iterator &i)
const
{
return
p==i.
p
; }
bool
operator
!=(
const
utf8_iterator &i)
const
{
return
p!=i.
p
; }
ptrdiff_t
operator
- (
const
utf8_iterator &i)
const
{
return
p -i.
p
; }
utf8_iterator&
operator
++() { **
this
; p=n; n=
NULL
;
return
*
this
; }
utf8_iterator
operator
++(
int
) { utf8_iterator
t
(*
this
);
operator
++();
return
t; }
char32_t
operator
*();
const
char
*
ptr
()
const
{
return
p; }
};
class
ReadUTF8
{
const
std::string &str;
public:
ReadUTF8
(
const
std::string &str) : str(str) {}
utf8_iterator
begin
()
const
{
return
utf8_iterator
(&str[
0
]); }
utf8_iterator
end
()
const
{
return
utf8_iterator
(&str[
0
] + str.
length
()); }
};
#
define
arraylen
(
x
) (
sizeof
((x))/
sizeof
((x)[
0
]))
#
define
PI
(
3.1415926535897931
)
void
MakeMatrix
(
double
*mat,
double
a11,
double
a12,
double
a13,
double
a14,
double
a21,
double
a22,
double
a23,
double
a24,
double
a31,
double
a32,
double
a33,
double
a34,
double
a41,
double
a42,
double
a43,
double
a44);
void
MultMatrix
(
double
*mata,
double
*matb,
double
*matr);
int64_t
GetMilliseconds
();
void
Message
(
const
char
*fmt, ...);
void
MessageAndRun
(std::function<
void
()> onDismiss,
const
char
*fmt, ...);
void
Error
(
const
char
*fmt, ...);
class
System
{
public:
enum
{
MAX_UNKNOWNS
=
2048
};
EntityList entity;
ParamList param;
IdList<Equation,hEquation> eq;
//
A list of parameters that are being dragged; these are the ones that
//
we should put as close as possible to their initial positions.
List<hParam> dragged;
enum
{
//
In general, the tag indicates the subsys that a variable/equation
//
has been assigned to; these are exceptions for variables:
VAR_SUBSTITUTED
=
10000
,
VAR_DOF_TEST
=
10001
,
//
and for equations:
EQ_SUBSTITUTED
=
20000
};
//
The system Jacobian matrix
struct
{
//
The corresponding equation for each row
std::vector<Equation *> eq;
//
The corresponding parameter for each column
std::vector<hParam> param;
//
We're solving AX = B
int
m, n;
struct
{
//
This only observes the Expr - does not own them!
Eigen::SparseMatrix<Expr *> sym;
Eigen::SparseMatrix<
double
> num;
} A;
Eigen::VectorXd scale;
Eigen::VectorXd X;
struct
{
//
This only observes the Expr - does not own them!
std::vector<Expr *> sym;
Eigen::VectorXd num;
} B;
} mat;
static
const
double
CONVERGE_TOLERANCE
;
int
CalculateRank
();
bool
TestRank
(
int
*dof =
NULL
);
static
bool
SolveLinearSystem
(
const
Eigen::SparseMatrix<
double
> &A,
const
Eigen::VectorXd &B, Eigen::VectorXd *X);
bool
SolveLeastSquares
();
bool
WriteJacobian
(
int
tag);
void
EvalJacobian
();
void
WriteEquationsExceptFor
(hConstraint hc, Group *g);
void
FindWhichToRemoveToFixJacobian
(Group *g, List<hConstraint> *bad,
bool
forceDofCheck);
void
SolveBySubstitution
();
bool
IsDragged
(hParam p);
bool
NewtonSolve
(
int
tag);
void
MarkParamsFree
(
bool
findFree);
SolveResult
Solve
(Group *g,
int
*rank =
NULL
,
int
*dof =
NULL
,
List<hConstraint> *bad =
NULL
,
bool
andFindBad =
false
,
bool
andFindFree =
false
,
bool
forceDofCheck =
false
);
SolveResult
SolveRank
(Group *g,
int
*rank =
NULL
,
int
*dof =
NULL
,
List<hConstraint> *bad =
NULL
,
bool
andFindBad =
false
,
bool
andFindFree =
false
);
void
Clear
();
Param *
GetLastParamSubstitution
(Param *p);
void
SubstituteParamsByLast
(Expr *e);
void
SortSubstitutionByDragged
(Param *p);
};
#
include
"
ttf.h
"
class
StepFileWriter
{
public:
void
ExportSurfacesTo
(
const
Platform::Path &filename);
void
WriteHeader
();
void
WriteProductHeader
();
int
ExportCurve
(SBezier *sb);
int
ExportCurveLoop
(SBezierLoop *loop,
bool
inner);
void
ExportSurface
(SSurface *ss, SBezierList *sbl);
void
WriteWireframe
();
void
WriteFooter
();
List<
int
> curves;
List<
int
> advancedFaces;
FILE
*f;
int
id;
};
class
VectorFileWriter
{
protected:
Vector u, v, n, origin;
double
cameraTan, scale;
public:
FILE
*f;
Platform::Path filename;
Vector ptMin, ptMax;
static
double
MmToPts
(
double
mm);
static
VectorFileWriter *
ForFile
(
const
Platform::Path &filename);
void
SetModelviewProjection
(
const
Vector &u,
const
Vector &v,
const
Vector &n,
const
Vector &origin,
double
cameraTan,
double
scale);
Vector
Transform
(Vector &pos)
const
;
void
OutputLinesAndMesh
(SBezierLoopSetSet *sblss, SMesh *sm);
void
BezierAsPwl
(SBezier *sb);
void
BezierAsNonrationalCubic
(SBezier *sb,
int
depth=
0
);
virtual
void
StartPath
(RgbaColor strokeRgb,
double
lineWidth,
bool
filled, RgbaColor fillRgb, hStyle hs) = 0;
virtual
void
FinishPath
(RgbaColor strokeRgb,
double
lineWidth,
bool
filled, RgbaColor fillRgb, hStyle hs) = 0;
virtual
void
Bezier
(SBezier *sb) = 0;
virtual
void
Triangle
(STriangle *tr) = 0;
virtual
bool
OutputConstraints
(IdList<Constraint,hConstraint> *) {
return
false
; }
virtual
void
Background
(RgbaColor color) = 0;
virtual
void
StartFile
() = 0;
virtual
void
FinishAndCloseFile
() = 0;
virtual
bool
HasCanvasSize
()
const
= 0;
virtual
bool
CanOutputMesh
()
const
= 0;
};
class
DxfFileWriter
:
public
VectorFileWriter
{
public:
struct
BezierPath
{
std::vector<SBezier *> beziers;
};
std::vector<BezierPath> paths;
IdList<Constraint,hConstraint> *constraint;
static
const
char
*
lineTypeName
(StipplePattern stippleType);
bool
OutputConstraints
(IdList<Constraint,hConstraint> *constraint)
override
;
void
StartPath
( RgbaColor strokeRgb,
double
lineWidth,
bool
filled, RgbaColor fillRgb, hStyle hs)
override
;
void
FinishPath
(RgbaColor strokeRgb,
double
lineWidth,
bool
filled, RgbaColor fillRgb, hStyle hs)
override
;
void
Triangle
(STriangle *tr)
override
;
void
Bezier
(SBezier *sb)
override
;
void
Background
(RgbaColor color)
override
;
void
StartFile
()
override
;
void
FinishAndCloseFile
()
override
;
bool
HasCanvasSize
()
const
override
{
return
false
; }
bool
CanOutputMesh
()
const
override
{
return
false
; }
bool
NeedToOutput
(Constraint *c);
};
class
EpsFileWriter
:
public
VectorFileWriter
{
public:
Vector prevPt;
void
MaybeMoveTo
(Vector s, Vector f);
void
StartPath
( RgbaColor strokeRgb,
double
lineWidth,
bool
filled, RgbaColor fillRgb, hStyle hs)
override
;
void
FinishPath
(RgbaColor strokeRgb,
double
lineWidth,
bool
filled, RgbaColor fillRgb, hStyle hs)
override
;
void
Triangle
(STriangle *tr)
override
;
void
Bezier
(SBezier *sb)
override
;
void
Background
(RgbaColor color)
override
;
void
StartFile
()
override
;
void
FinishAndCloseFile
()
override
;
bool
HasCanvasSize
()
const
override
{
return
true
; }
bool
CanOutputMesh
()
const
override
{
return
true
; }
};
class
PdfFileWriter
:
public
VectorFileWriter
{
public:
uint32_t
xref[
10
];
uint32_t
bodyStart;
Vector prevPt;
void
MaybeMoveTo
(Vector s, Vector f);
void
StartPath
( RgbaColor strokeRgb,
double
lineWidth,
bool
filled, RgbaColor fillRgb, hStyle hs)
override
;
void
FinishPath
(RgbaColor strokeRgb,
double
lineWidth,
bool
filled, RgbaColor fillRgb, hStyle hs)
override
;
void
Triangle
(STriangle *tr)
override
;
void
Bezier
(SBezier *sb)
override
;
void
Background
(RgbaColor color)
override
;
void
StartFile
()
override
;
void
FinishAndCloseFile
()
override
;
bool
HasCanvasSize
()
const
override
{
return
true
; }
bool
CanOutputMesh
()
const
override
{
return
true
; }
};
class
SvgFileWriter
:
public
VectorFileWriter
{
public:
Vector prevPt;
void
MaybeMoveTo
(Vector s, Vector f);
void
StartPath
( RgbaColor strokeRgb,
double
lineWidth,
bool
filled, RgbaColor fillRgb, hStyle hs)
override
;
void
FinishPath
(RgbaColor strokeRgb,
double
lineWidth,
bool
filled, RgbaColor fillRgb, hStyle hs)
override
;
void
Triangle
(STriangle *tr)
override
;
void
Bezier
(SBezier *sb)
override
;
void
Background
(RgbaColor color)
override
;
void
StartFile
()
override
;
void
FinishAndCloseFile
()
override
;
bool
HasCanvasSize
()
const
override
{
return
true
; }
bool
CanOutputMesh
()
const
override
{
return
true
; }
};
class
HpglFileWriter
:
public
VectorFileWriter
{
public:
static
double
MmToHpglUnits
(
double
mm);
void
StartPath
( RgbaColor strokeRgb,
double
lineWidth,
bool
filled, RgbaColor fillRgb, hStyle hs)
override
;
void
FinishPath
(RgbaColor strokeRgb,
double
lineWidth,
bool
filled, RgbaColor fillRgb, hStyle hs)
override
;
void
Triangle
(STriangle *tr)
override
;
void
Bezier
(SBezier *sb)
override
;
void
Background
(RgbaColor color)
override
;
void
StartFile
()
override
;
void
FinishAndCloseFile
()
override
;
bool
HasCanvasSize
()
const
override
{
return
false
; }
bool
CanOutputMesh
()
const
override
{
return
false
; }
};
class
Step2dFileWriter
:
public
VectorFileWriter
{
StepFileWriter sfw;
void
StartPath
( RgbaColor strokeRgb,
double
lineWidth,
bool
filled, RgbaColor fillRgb, hStyle hs)
override
;
void
FinishPath
(RgbaColor strokeRgb,
double
lineWidth,
bool
filled, RgbaColor fillRgb, hStyle hs)
override
;
void
Triangle
(STriangle *tr)
override
;
void
Bezier
(SBezier *sb)
override
;
void
Background
(RgbaColor color)
override
;
void
StartFile
()
override
;
void
FinishAndCloseFile
()
override
;
bool
HasCanvasSize
()
const
override
{
return
false
; }
bool
CanOutputMesh
()
const
override
{
return
false
; }
};
class
GCodeFileWriter
:
public
VectorFileWriter
{
public:
SEdgeList sel;
void
StartPath
( RgbaColor strokeRgb,
double
lineWidth,
bool
filled, RgbaColor fillRgb, hStyle hs)
override
;
void
FinishPath
(RgbaColor strokeRgb,
double
lineWidth,
bool
filled, RgbaColor fillRgb, hStyle hs)
override
;
void
Triangle
(STriangle *tr)
override
;
void
Bezier
(SBezier *sb)
override
;
void
Background
(RgbaColor color)
override
;
void
StartFile
()
override
;
void
FinishAndCloseFile
()
override
;
bool
HasCanvasSize
()
const
override
{
return
false
; }
bool
CanOutputMesh
()
const
override
{
return
false
; }
};
#
ifdef
LIBRARY
#
define
ENTITY
EntityBase
#
define
CONSTRAINT
ConstraintBase
#
else
#
define
ENTITY
Entity
#
define
CONSTRAINT
Constraint
#
endif
class
Sketch
{
public:
//
These are user-editable, and define the sketch.
IdList<Group,hGroup> group;
List<hGroup> groupOrder;
IdList<
CONSTRAINT
,hConstraint> constraint;
IdList<Request,hRequest> request;
IdList<Style,hStyle> style;
//
These are generated from the above.
IdList<
ENTITY
,hEntity> entity;
IdList<Param,hParam> param;
inline
CONSTRAINT
*
GetConstraint
(hConstraint h)
{
return
constraint.
FindById
(h); }
inline
ENTITY
*
GetEntity
(hEntity h) {
return
entity.
FindById
(h); }
inline
Param *
GetParam
(hParam h) {
return
param.
FindById
(h); }
inline
Request *
GetRequest
(hRequest h) {
return
request.
FindById
(h); }
inline
Group *
GetGroup
(hGroup h) {
return
group.
FindById
(h); }
//
Styles are handled a bit differently.
void
Clear
();
BBox
CalculateEntityBBox
(
bool
includingInvisible);
Group *
GetRunningMeshGroupFor
(hGroup h);
};
#
undef
ENTITY
#
undef
CONSTRAINT
class
SolveSpaceUI
{
public:
TextWindow *pTW;
TextWindow &
TW
;
GraphicsWindow
GW
;
//
The state for undo/redo
typedef
struct
UndoState
{
IdList<Group,hGroup> group;
List<hGroup> groupOrder;
IdList<Request,hRequest> request;
IdList<Constraint,hConstraint> constraint;
IdList<Param,hParam> param;
IdList<Style,hStyle> style;
hGroup activeGroup;
void
Clear
() {
group.
Clear
();
request.
Clear
();
constraint.
Clear
();
param.
Clear
();
style.
Clear
();
}
} UndoState;
enum
{
MAX_UNDO
=
100
};
typedef
struct
{
UndoState d[
MAX_UNDO
];
int
cnt;
int
write;
} UndoStack;
UndoStack undo;
UndoStack redo;
std::map<Platform::Path, std::shared_ptr<Pixmap>, Platform::PathLess> images;
bool
ReloadLinkedImage
(
const
Platform::Path &saveFile, Platform::Path *filename,
bool
canCancel);
void
UndoEnableMenus
();
void
UndoRemember
();
void
UndoUndo
();
void
UndoRedo
();
void
PushFromCurrentOnto
(UndoStack *uk);
void
PopOntoCurrentFrom
(UndoStack *uk);
void
UndoClearState
(UndoState *ut);
void
UndoClearStack
(UndoStack *uk);
//
Little bits of extra configuration state
enum
{
MODEL_COLORS
=
8
};
RgbaColor modelColor[
MODEL_COLORS
];
Vector lightDir[
2
];
double
lightIntensity[
2
];
double
ambientIntensity;
double
chordTol;
double
chordTolCalculated;
int
maxSegments;
double
exportChordTol;
int
exportMaxSegments;
int
timeoutRedundantConstr;
//
milliseconds
double
cameraTangent;
double
gridSpacing;
double
exportScale;
double
exportOffset;
bool
fixExportColors;
bool
exportBackgroundColor;
bool
drawBackFaces;
bool
showContourAreas;
bool
checkClosedContour;
bool
turntableNav;
bool
immediatelyEditDimension;
bool
automaticLineConstraints;
bool
showToolbar;
Platform::Path screenshotFile;
RgbaColor backgroundColor;
bool
exportShadedTriangles;
bool
exportPwlCurves;
bool
exportCanvasSizeAuto;
bool
exportMode;
struct
{
double
left;
double
right;
double
bottom;
double
top;
} exportMargin;
struct
{
double
width;
double
height;
double
dx;
double
dy;
} exportCanvas;
struct
{
double
depth;
double
safeHeight;
int
passes;
double
feed;
double
plungeFeed;
}
gCode
;
Unit viewUnits;
int
afterDecimalMm;
int
afterDecimalInch;
int
afterDecimalDegree;
bool
useSIPrefixes;
int
autosaveInterval;
//
in minutes
bool
explode;
double
explodeDistance;
std::string
MmToString
(
double
v,
bool
editable=
false
);
std::string
MmToStringSI
(
double
v,
int
dim =
0
);
std::string
DegreeToString
(
double
v);
double
ExprToMm
(Expr *e);
double
StringToMm
(
const
std::string &s);
const
char
*
UnitName
();
double
MmPerUnit
();
int
UnitDigitsAfterDecimal
();
void
SetUnitDigitsAfterDecimal
(
int
v);
double
ChordTolMm
();
double
ExportChordTolMm
();
int
GetMaxSegments
();
bool
usePerspectiveProj;
double
CameraTangent
();
//
Some stuff relating to the tangent arcs created non-parametrically
//
as special requests.
double
tangentArcRadius;
bool
tangentArcManual;
bool
tangentArcModify;
//
The platform-dependent code calls this before entering the msg loop
void
Init
();
void
Exit
();
//
File load/save routines, including the additional files that get
//
loaded when we have link groups.
FILE
*fh;
void
AfterNewFile
();
void
AddToRecentList
(
const
Platform::Path &filename);
Platform::Path saveFile;
bool
fileLoadError;
bool
unsaved;
typedef
struct
{
char
type;
const
char
*desc;
char
fmt;
void
*ptr;
} SaveTable;
static
const
SaveTable
SAVED
[];
void
SaveUsingTable
(
const
Platform::Path &filename,
int
type);
void
LoadUsingTable
(
const
Platform::Path &filename,
char
*key,
char
*val);
struct
{
Group g;
Request r;
Entity e;
Param p;
Constraint c;
Style s;
} sv;
static
void
MenuFile
(Command id);
void
Autosave
();
void
RemoveAutosave
();
static
constexpr
size_t
MAX_RECENT
=
8
;
static
constexpr
const
char
*
SKETCH_EXT
=
"
slvs
"
;
static
constexpr
const
char
*
BACKUP_EXT
=
"
slvs~
"
;
std::vector<Platform::Path> recentFiles;
bool
Load
(
const
Platform::Path &filename);
bool
GetFilenameAndSave
(
bool
saveAs);
bool
OkayToStartNewFile
();
hGroup
CreateDefaultDrawingGroup
();
void
UpdateWindowTitles
();
void
ClearExisting
();
void
NewFile
();
bool
SaveToFile
(
const
Platform::Path &filename);
bool
LoadAutosaveFor
(
const
Platform::Path &filename);
bool
LoadFromFile
(
const
Platform::Path &filename,
bool
canCancel =
false
);
void
UpgradeLegacyData
();
bool
LoadEntitiesFromFile
(
const
Platform::Path &filename, EntityList *le,
SMesh *m, SShell *sh);
bool
LoadEntitiesFromSlvs
(
const
Platform::Path &filename, EntityList *le,
SMesh *m, SShell *sh);
bool
ReloadAllLinked
(
const
Platform::Path &filename,
bool
canCancel =
false
);
//
And the various export options
void
ExportAsPngTo
(
const
Platform::Path &filename);
void
ExportMeshTo
(
const
Platform::Path &filename);
void
ExportMeshAsStlTo
(
FILE
*f, SMesh *sm);
void
ExportMeshAsObjTo
(
FILE
*
fObj
,
FILE
*
fMtl
, SMesh *sm);
void
ExportMeshAsThreeJsTo
(
FILE
*f,
const
Platform::Path &filename,
SMesh *sm, SOutlineList *sol);
void
ExportMeshAsVrmlTo
(
FILE
*f,
const
Platform::Path &filename, SMesh *sm);
void
ExportViewOrWireframeTo
(
const
Platform::Path &filename,
bool
exportWireframe);
void
ExportSectionTo
(
const
Platform::Path &filename);
void
ExportWireframeCurves
(SEdgeList *sel, SBezierList *sbl,
VectorFileWriter *out);
void
ExportLinesAndMesh
(SEdgeList *sel, SBezierList *sbl, SMesh *sm,
Vector u, Vector v,
Vector n, Vector origin,
double
cameraTan,
VectorFileWriter *out);
static
void
MenuAnalyze
(Command id);
//
Additional display stuff
struct
{
SContour path;
hEntity point;
} traced;
SEdgeList nakedEdges;
struct
{
bool
draw;
Vector ptA;
Vector ptB;
} extraLine;
struct
{
bool
draw, showOrigin;
Vector pt, u, v;
} justExportedInfo;
struct
{
bool
draw;
bool
dirty;
Vector position;
} centerOfMass;
class
Clipboard
{
public:
List<ClipboardRequest> r;
List<Constraint> c;
void
Clear
();
bool
ContainsEntity
(hEntity old);
hEntity
NewEntityFor
(hEntity old);
};
Clipboard clipboard;
void
MarkGroupDirty
(hGroup hg,
bool
onlyThis =
false
);
void
MarkGroupDirtyByEntity
(hEntity he);
//
Consistency checking on the sketch: stuff with missing dependencies
//
will get deleted automatically.
struct
{
int
requests;
int
groups;
int
constraints;
int
nonTrivialConstraints;
} deleted;
bool
GroupExists
(hGroup hg);
bool
PruneOrphans
();
bool
EntityExists
(hEntity he);
bool
GroupsInOrder
(hGroup before, hGroup after);
bool
PruneGroups
(hGroup hg);
bool
PruneRequests
(hGroup hg);
bool
PruneConstraints
(hGroup hg);
static
void
ShowNakedEdges
(
bool
reportOnlyWhenNotOkay);
enum
class
Generate
:
uint32_t
{
DIRTY
,
ALL
,
REGEN
,
UNTIL_ACTIVE
,
};
void
GenerateAll
(Generate type = Generate::
DIRTY
,
bool
andFindFree =
false
,
bool
genForBBox =
false
);
void
SolveGroup
(hGroup hg,
bool
andFindFree);
void
SolveGroupAndReport
(hGroup hg,
bool
andFindFree);
SolveResult
TestRankForGroup
(hGroup hg,
int
*rank =
NULL
);
void
WriteEqSystemForGroup
(hGroup hg);
void
MarkDraggedParams
();
void
ForceReferences
();
void
UpdateCenterOfMass
();
bool
ActiveGroupsOkay
();
//
The system to be solved.
System *pSys;
System &sys;
//
All the TrueType fonts in memory
TtfFontList fonts;
//
Everything has been pruned, so we know there's no dangling references
//
to entities that don't exist. Before that, we mustn't try to display
//
the sketch!
bool
allConsistent;
bool
scheduledGenerateAll;
bool
scheduledShowTW;
Platform::TimerRef refreshTimer;
Platform::TimerRef autosaveTimer;
void
Refresh
();
void
ScheduleShowTW
();
void
ScheduleGenerateAll
();
void
ScheduleAutosave
();
static
void
MenuHelp
(Command id);
void
Clear
();
//
We allocate TW and sys on the heap to work around an MSVC problem
//
where it puts zero-initialized global data in the binary (~30M of zeroes)
//
in release builds.
SolveSpaceUI
()
: pTW(
new
TextWindow()),
TW
(*pTW),
pSys
(
new
System()), sys(*pSys) {}
~SolveSpaceUI
() {
delete
pTW;
delete
pSys;
}
};
void
ImportDxf
(
const
Platform::Path &file);
void
ImportDwg
(
const
Platform::Path &file);
bool
LinkIDF
(
const
Platform::Path &filename, EntityList *le, SMesh *m, SShell *sh);
bool
LinkStl
(
const
Platform::Path &filename, EntityList *le, SMesh *m, SShell *sh);
extern
SolveSpaceUI
SS
;
extern
Sketch
SK
;
}
#
ifndef
__OBJC__
using
namespace
SolveSpace
;
#
endif
#endif
Back
|
FazBrowse Home
|
New Git URL