Solvespace

Форк
0
/
view.cpp 
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

9
void TextWindow::ShowEditView() {
10
    Printf(true, "%Ft3D VIEW PARAMETERS%E");
11

12
    Printf(true,  "%Bd %Ftoverall scale factor%E");
13
    Printf(false, "%Ba   %# px/%s %Fl%Ll%f[edit]%E",
14
        SS.GW.scale * SS.MmPerUnit(),
15
        SS.UnitName(),
16
        &ScreenChangeViewScale);
17
    Printf(false, "%Bd   %Fl%Ll%fset to full scale%E",
18
        &ScreenChangeViewToFullScale);
19
    Printf(false, "");
20

21
    Printf(false, "%Bd %Ftorigin (maps to center of screen)%E");
22
    Printf(false, "%Ba   (%s, %s, %s) %Fl%Ll%f[edit]%E",
23
        SS.MmToString(-SS.GW.offset.x).c_str(),
24
        SS.MmToString(-SS.GW.offset.y).c_str(),
25
        SS.MmToString(-SS.GW.offset.z).c_str(),
26
        &ScreenChangeViewOrigin);
27
    Printf(false, "");
28

29
    Vector n = (SS.GW.projRight).Cross(SS.GW.projUp);
30
    Printf(false, "%Bd %Ftprojection onto screen%E");
31
    Printf(false, "%Ba   %Ftright%E (%3, %3, %3) %Fl%Ll%f[edit]%E",
32
        CO(SS.GW.projRight),
33
        &ScreenChangeViewProjection);
34
    Printf(false, "%Bd   %Ftup%E    (%3, %3, %3)", CO(SS.GW.projUp));
35
    Printf(false, "%Ba   %Ftout%E   (%3, %3, %3)", CO(n));
36
    Printf(false, "");
37

38
    Printf(false, "%Ft perspective factor (0 for parallel)%E");
39
    Printf(false, "%Ba   %# %Fl%Ll%f%D[change]%E",
40
        SS.cameraTangent*1000,
41
        &ScreenChangeCameraTangent, 0);
42

43
    Printf(false, "");
44
    Printf(false, "%Ft light direction               intensity");
45
    for(int i = 0; i < 2; i++) {
46
        Printf(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,
49
            CO(SS.lightDir[i]), i, &ScreenChangeLightDirection,
50
            SS.lightIntensity[i], i, &ScreenChangeLightIntensity);
51
    }
52
    Printf(false, "%Ba         ambient lighting     %2 %Fl%f%Ll[c]%E",
53
        SS.ambientIntensity, &ScreenChangeLightAmbient);
54

55
    Printf(false, "");
56
    Printf(false, "%Ft explode distance%E");
57
    Printf(false, "%Ba   %s %Fl%Ll%f%D[change]%E",
58
        SS.MmToString(SS.explodeDistance).c_str(),
59
        &ScreenChangeExplodeDistance, 0);
60

61
}
62

63
void TextWindow::ScreenChangeViewScale(int link, uint32_t v) {
64
    SS.TW.edit.meaning = Edit::VIEW_SCALE;
65
    SS.TW.ShowEditControl(3, ssprintf("%.3f", SS.GW.scale * SS.MmPerUnit()));
66
}
67

68
void TextWindow::ScreenChangeViewToFullScale(int link, uint32_t v) {
69
    SS.GW.scale = SS.GW.window->GetPixelDensity() / 25.4;
70
}
71

72
void TextWindow::ScreenChangeViewOrigin(int link, uint32_t v) {
73
    std::string edit_value =
74
        ssprintf("%s, %s, %s",
75
            SS.MmToString(-SS.GW.offset.x, true).c_str(),
76
            SS.MmToString(-SS.GW.offset.y, true).c_str(),
77
            SS.MmToString(-SS.GW.offset.z, true).c_str());
78

79
    SS.TW.edit.meaning = Edit::VIEW_ORIGIN;
80
    SS.TW.ShowEditControl(3, edit_value);
81
}
82

83
void TextWindow::ScreenChangeViewProjection(int link, uint32_t v) {
84
    std::string edit_value =
85
        ssprintf("%.3f, %.3f, %.3f", CO(SS.GW.projRight));
86
    SS.TW.edit.meaning = Edit::VIEW_PROJ_RIGHT;
87
    SS.TW.ShowEditControl(10, edit_value);
88
}
89

90
void TextWindow::ScreenChangeLightDirection(int link, uint32_t v) {
91
    SS.TW.ShowEditControl(8, ssprintf("%.2f, %.2f, %.2f", CO(SS.lightDir[v])));
92
    SS.TW.edit.meaning = Edit::LIGHT_DIRECTION;
93
    SS.TW.edit.i = v;
94
}
95

96
void TextWindow::ScreenChangeLightIntensity(int link, uint32_t v) {
97
    SS.TW.ShowEditControl(31, ssprintf("%.2f", SS.lightIntensity[v]));
98
    SS.TW.edit.meaning = Edit::LIGHT_INTENSITY;
99
    SS.TW.edit.i = v;
100
}
101

102
void TextWindow::ScreenChangeLightAmbient(int link, uint32_t v) {
103
    SS.TW.ShowEditControl(31, ssprintf("%.2f", SS.ambientIntensity));
104
    SS.TW.edit.meaning = Edit::LIGHT_AMBIENT;
105
    SS.TW.edit.i = 0;
106
}
107

108
void TextWindow::ScreenChangeCameraTangent(int link, uint32_t v) {
109
    SS.TW.ShowEditControl(3, ssprintf("%.3f", 1000*SS.cameraTangent));
110
    SS.TW.edit.meaning = Edit::CAMERA_TANGENT;
111
}
112

113
void TextWindow::ScreenChangeExplodeDistance(int link, uint32_t v) {
114
    SS.TW.ShowEditControl(3, SS.MmToString(SS.explodeDistance, true));
115
    SS.TW.edit.meaning = Edit::EXPLODE_DISTANCE;
116
}
117

118
bool TextWindow::EditControlDoneForView(const std::string &s) {
119
    switch(edit.meaning) {
120
        case Edit::VIEW_SCALE: {
121
            Expr *e = Expr::From(s, /*popUpError=*/true);
122
            if(e) {
123
                double v =  e->Eval() / SS.MmPerUnit();
124
                if(v > LENGTH_EPS) {
125
                    SS.GW.scale = v;
126
                } else {
127
                    Error(_("Scale cannot be zero or negative."));
128
                }
129
            }
130
            break;
131
        }
132

133
        case Edit::VIEW_ORIGIN: {
134
            Vector pt;
135
            if(sscanf(s.c_str(), "%lf, %lf, %lf", &pt.x, &pt.y, &pt.z) == 3) {
136
                pt = pt.ScaledBy(SS.MmPerUnit());
137
                SS.GW.offset = pt.ScaledBy(-1);
138
            } else {
139
                Error(_("Bad format: specify x, y, z"));
140
            }
141
            break;
142
        }
143

144
        case Edit::VIEW_PROJ_RIGHT:
145
        case Edit::VIEW_PROJ_UP: {
146
            Vector pt;
147
            if(sscanf(s.c_str(), "%lf, %lf, %lf", &pt.x, &pt.y, &pt.z) != 3) {
148
                Error(_("Bad format: specify x, y, z"));
149
                break;
150
            }
151
            if(edit.meaning == Edit::VIEW_PROJ_RIGHT) {
152
                SS.GW.projRight = pt;
153
                SS.GW.NormalizeProjectionVectors();
154
                edit.meaning = Edit::VIEW_PROJ_UP;
155
                HideEditControl();
156
                ShowEditControl(10, ssprintf("%.3f, %.3f, %.3f", CO(SS.GW.projUp)),
157
                                editControl.halfRow + 2);
158
                edit.showAgain = true;
159
            } else {
160
                SS.GW.projUp = pt;
161
                SS.GW.NormalizeProjectionVectors();
162
            }
163
            break;
164
        }
165

166
        default:
167
            return false;
168
    }
169
    return true;
170
}
171

172

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.