Solvespace
170 строк · 6.0 Кб
1//-----------------------------------------------------------------------------
2// The View menu, stuff to snap to certain special views of the model, and to
3// display our current view of the model to the user.
4//
5// Copyright 2008-2013 Jonathan Westhues.
6//-----------------------------------------------------------------------------
7#include "solvespace.h"
8
9void TextWindow::ShowEditView() {
10Printf(true, "%Ft3D VIEW PARAMETERS%E");
11
12Printf(true, "%Bd %Ftoverall scale factor%E");
13Printf(false, "%Ba %# px/%s %Fl%Ll%f[edit]%E",
14SS.GW.scale * SS.MmPerUnit(),
15SS.UnitName(),
16&ScreenChangeViewScale);
17Printf(false, "%Bd %Fl%Ll%fset to full scale%E",
18&ScreenChangeViewToFullScale);
19Printf(false, "");
20
21Printf(false, "%Bd %Ftorigin (maps to center of screen)%E");
22Printf(false, "%Ba (%s, %s, %s) %Fl%Ll%f[edit]%E",
23SS.MmToString(-SS.GW.offset.x).c_str(),
24SS.MmToString(-SS.GW.offset.y).c_str(),
25SS.MmToString(-SS.GW.offset.z).c_str(),
26&ScreenChangeViewOrigin);
27Printf(false, "");
28
29Vector n = (SS.GW.projRight).Cross(SS.GW.projUp);
30Printf(false, "%Bd %Ftprojection onto screen%E");
31Printf(false, "%Ba %Ftright%E (%3, %3, %3) %Fl%Ll%f[edit]%E",
32CO(SS.GW.projRight),
33&ScreenChangeViewProjection);
34Printf(false, "%Bd %Ftup%E (%3, %3, %3)", CO(SS.GW.projUp));
35Printf(false, "%Ba %Ftout%E (%3, %3, %3)", CO(n));
36Printf(false, "");
37
38Printf(false, "%Ft perspective factor (0 for parallel)%E");
39Printf(false, "%Ba %# %Fl%Ll%f%D[change]%E",
40SS.cameraTangent*1000,
41&ScreenChangeCameraTangent, 0);
42
43Printf(false, "");
44Printf(false, "%Ft light direction intensity");
45for(int i = 0; i < 2; i++) {
46Printf(false, "%Bp #%d (%2,%2,%2)%Fl%D%f%Ll[c]%E "
47"%2 %Fl%D%f%Ll[c]%E",
48(i & 1) ? 'd' : 'a', i,
49CO(SS.lightDir[i]), i, &ScreenChangeLightDirection,
50SS.lightIntensity[i], i, &ScreenChangeLightIntensity);
51}
52Printf(false, "%Ba ambient lighting %2 %Fl%f%Ll[c]%E",
53SS.ambientIntensity, &ScreenChangeLightAmbient);
54
55Printf(false, "");
56Printf(false, "%Ft explode distance%E");
57Printf(false, "%Ba %s %Fl%Ll%f%D[change]%E",
58SS.MmToString(SS.explodeDistance).c_str(),
59&ScreenChangeExplodeDistance, 0);
60
61}
62
63void TextWindow::ScreenChangeViewScale(int link, uint32_t v) {
64SS.TW.edit.meaning = Edit::VIEW_SCALE;
65SS.TW.ShowEditControl(3, ssprintf("%.3f", SS.GW.scale * SS.MmPerUnit()));
66}
67
68void TextWindow::ScreenChangeViewToFullScale(int link, uint32_t v) {
69SS.GW.scale = SS.GW.window->GetPixelDensity() / 25.4;
70}
71
72void TextWindow::ScreenChangeViewOrigin(int link, uint32_t v) {
73std::string edit_value =
74ssprintf("%s, %s, %s",
75SS.MmToString(-SS.GW.offset.x, true).c_str(),
76SS.MmToString(-SS.GW.offset.y, true).c_str(),
77SS.MmToString(-SS.GW.offset.z, true).c_str());
78
79SS.TW.edit.meaning = Edit::VIEW_ORIGIN;
80SS.TW.ShowEditControl(3, edit_value);
81}
82
83void TextWindow::ScreenChangeViewProjection(int link, uint32_t v) {
84std::string edit_value =
85ssprintf("%.3f, %.3f, %.3f", CO(SS.GW.projRight));
86SS.TW.edit.meaning = Edit::VIEW_PROJ_RIGHT;
87SS.TW.ShowEditControl(10, edit_value);
88}
89
90void TextWindow::ScreenChangeLightDirection(int link, uint32_t v) {
91SS.TW.ShowEditControl(8, ssprintf("%.2f, %.2f, %.2f", CO(SS.lightDir[v])));
92SS.TW.edit.meaning = Edit::LIGHT_DIRECTION;
93SS.TW.edit.i = v;
94}
95
96void TextWindow::ScreenChangeLightIntensity(int link, uint32_t v) {
97SS.TW.ShowEditControl(31, ssprintf("%.2f", SS.lightIntensity[v]));
98SS.TW.edit.meaning = Edit::LIGHT_INTENSITY;
99SS.TW.edit.i = v;
100}
101
102void TextWindow::ScreenChangeLightAmbient(int link, uint32_t v) {
103SS.TW.ShowEditControl(31, ssprintf("%.2f", SS.ambientIntensity));
104SS.TW.edit.meaning = Edit::LIGHT_AMBIENT;
105SS.TW.edit.i = 0;
106}
107
108void TextWindow::ScreenChangeCameraTangent(int link, uint32_t v) {
109SS.TW.ShowEditControl(3, ssprintf("%.3f", 1000*SS.cameraTangent));
110SS.TW.edit.meaning = Edit::CAMERA_TANGENT;
111}
112
113void TextWindow::ScreenChangeExplodeDistance(int link, uint32_t v) {
114SS.TW.ShowEditControl(3, SS.MmToString(SS.explodeDistance, true));
115SS.TW.edit.meaning = Edit::EXPLODE_DISTANCE;
116}
117
118bool TextWindow::EditControlDoneForView(const std::string &s) {
119switch(edit.meaning) {
120case Edit::VIEW_SCALE: {
121Expr *e = Expr::From(s, /*popUpError=*/true);
122if(e) {
123double v = e->Eval() / SS.MmPerUnit();
124if(v > LENGTH_EPS) {
125SS.GW.scale = v;
126} else {
127Error(_("Scale cannot be zero or negative."));
128}
129}
130break;
131}
132
133case Edit::VIEW_ORIGIN: {
134Vector pt;
135if(sscanf(s.c_str(), "%lf, %lf, %lf", &pt.x, &pt.y, &pt.z) == 3) {
136pt = pt.ScaledBy(SS.MmPerUnit());
137SS.GW.offset = pt.ScaledBy(-1);
138} else {
139Error(_("Bad format: specify x, y, z"));
140}
141break;
142}
143
144case Edit::VIEW_PROJ_RIGHT:
145case Edit::VIEW_PROJ_UP: {
146Vector pt;
147if(sscanf(s.c_str(), "%lf, %lf, %lf", &pt.x, &pt.y, &pt.z) != 3) {
148Error(_("Bad format: specify x, y, z"));
149break;
150}
151if(edit.meaning == Edit::VIEW_PROJ_RIGHT) {
152SS.GW.projRight = pt;
153SS.GW.NormalizeProjectionVectors();
154edit.meaning = Edit::VIEW_PROJ_UP;
155HideEditControl();
156ShowEditControl(10, ssprintf("%.3f, %.3f, %.3f", CO(SS.GW.projUp)),
157editControl.halfRow + 2);
158edit.showAgain = true;
159} else {
160SS.GW.projUp = pt;
161SS.GW.NormalizeProjectionVectors();
162}
163break;
164}
165
166default:
167return false;
168}
169return true;
170}
171
172