| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2002 Jürgen Riegel <[email protected]> * |
| 3 |
* * |
| 4 |
* This file is part of the FreeCAD CAx development system. * |
| 5 |
* * |
| 6 |
* This library is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Library General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 |
* GNU Library General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Library General Public * |
| 17 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 18 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 19 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 20 |
* * |
| 21 |
***************************************************************************/ |
| 22 |
|
| 23 |
|
| 24 |
#include <QApplication> |
| 25 |
#include <QMessageBox> |
| 26 |
#include <QOffscreenSurface> |
| 27 |
#include <QOpenGLContext> |
| 28 |
#include <QSurfaceFormat> |
| 29 |
|
| 30 |
|
| 31 |
#include <App/Application.h> |
| 32 |
#include <Base/Parameter.h> |
| 33 |
#include <Base/Tools.h> |
| 34 |
#include <Gui/Multisample.h> |
| 35 |
#include <Gui/View3DInventorViewer.h> |
| 36 |
#include <Gui/ViewParams.h> |
| 37 |
|
| 38 |
#include "DlgSettings3DViewImp.h" |
| 39 |
#include "ui_DlgSettings3DView.h" |
| 40 |
|
| 41 |
|
| 42 |
using namespace Gui::Dialog; |
| 43 |
|
| 44 |
/* TRANSLATOR Gui::Dialog::DlgSettings3DViewImp */ |
| 45 |
|
| 46 |
DlgSettings3DViewImp::DlgSettings3DViewImp(QWidget* parent) |
| 47 |
: PreferencePage(parent) |
| 48 |
, ui(new Ui_DlgSettings3DView) |
| 49 |
{ |
| 50 |
ui->setupUi(this); |
| 51 |
addAntiAliasing(); |
| 52 |
} |
| 53 |
|
| 54 |
DlgSettings3DViewImp::~DlgSettings3DViewImp() = default; |
| 55 |
|
| 56 |
void DlgSettings3DViewImp::saveSettings() |
| 57 |
{ |
| 58 |
saveAntiAliasing(); |
| 59 |
saveRenderCache(); |
| 60 |
saveMarkerSize(); |
| 61 |
|
| 62 |
ui->comboTransparentRender->onSave(); |
| 63 |
ui->CheckBox_CornerCoordSystem->onSave(); |
| 64 |
ui->SpinBox_CornerCoordSystemSize->onSave(); |
| 65 |
ui->CheckBox_ShowAxisCross->onSave(); |
| 66 |
ui->CheckBox_ShowFPS->onSave(); |
| 67 |
ui->CheckBox_use_SW_OpenGL->onSave(); |
| 68 |
ui->CheckBox_useVBO->onSave(); |
| 69 |
ui->FloatSpinBox_EyeDistance->onSave(); |
| 70 |
ui->FloatSpinBox_DatumScale->onSave(); |
| 71 |
ui->axisLetterColor->onSave(); |
| 72 |
ui->radioPerspective->onSave(); |
| 73 |
ui->radioOrthographic->onSave(); |
| 74 |
ui->xAxisColor->onSave(); |
| 75 |
ui->yAxisColor->onSave(); |
| 76 |
ui->zAxisColor->onSave(); |
| 77 |
} |
| 78 |
|
| 79 |
void DlgSettings3DViewImp::loadSettings() |
| 80 |
{ |
| 81 |
ui->CheckBox_CornerCoordSystem->onRestore(); |
| 82 |
ui->SpinBox_CornerCoordSystemSize->onRestore(); |
| 83 |
ui->CheckBox_ShowAxisCross->onRestore(); |
| 84 |
ui->CheckBox_ShowFPS->onRestore(); |
| 85 |
ui->CheckBox_use_SW_OpenGL->onRestore(); |
| 86 |
ui->CheckBox_useVBO->onRestore(); |
| 87 |
ui->FloatSpinBox_EyeDistance->onRestore(); |
| 88 |
ui->FloatSpinBox_DatumScale->onRestore(); |
| 89 |
ui->axisLetterColor->onRestore(); |
| 90 |
ui->radioPerspective->onRestore(); |
| 91 |
ui->radioOrthographic->onRestore(); |
| 92 |
ui->comboTransparentRender->onRestore(); |
| 93 |
ui->xAxisColor->onRestore(); |
| 94 |
ui->yAxisColor->onRestore(); |
| 95 |
ui->zAxisColor->onRestore(); |
| 96 |
|
| 97 |
loadAntiAliasing(); |
| 98 |
loadRenderCache(); |
| 99 |
loadMarkerSize(); |
| 100 |
} |
| 101 |
|
| 102 |
void DlgSettings3DViewImp::addAntiAliasing() |
| 103 |
{ |
| 104 |
ui->comboAliasing->clear(); |
| 105 |
|
| 106 |
// Do the samples checks only once |
| 107 |
static std::vector<std::pair<QString, AntiAliasing>> modes; |
| 108 |
static bool formatCheck = true; |
| 109 |
if (formatCheck) { |
| 110 |
formatCheck = false; |
| 111 |
|
| 112 |
Multisample check; |
| 113 |
modes = check.supported(); |
| 114 |
} |
| 115 |
|
| 116 |
for (const auto& it : modes) { |
| 117 |
ui->comboAliasing->addItem(it.first, int(it.second)); |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
void DlgSettings3DViewImp::saveAntiAliasing() |
| 122 |
{ |
| 123 |
int index = ui->comboAliasing->currentIndex(); |
| 124 |
int aliasing = ui->comboAliasing->itemData(index).toInt(); |
| 125 |
Multisample::writeMSAAToSettings(static_cast<AntiAliasing>(aliasing)); |
| 126 |
} |
| 127 |
|
| 128 |
void DlgSettings3DViewImp::loadAntiAliasing() |
| 129 |
{ |
| 130 |
int aliasing = int(Multisample::readMSAAFromSettings()); |
| 131 |
int index = ui->comboAliasing->findData(aliasing); |
| 132 |
if (index != -1) { |
| 133 |
ui->comboAliasing->setCurrentIndex(index); |
| 134 |
} |
| 135 |
|
| 136 |
// connect after setting current item of the combo box |
| 137 |
connect( |
| 138 |
ui->comboAliasing, |
| 139 |
qOverload<int>(&QComboBox::currentIndexChanged), |
| 140 |
this, |
| 141 |
&DlgSettings3DViewImp::onAliasingChanged |
| 142 |
); |
| 143 |
} |
| 144 |
|
| 145 |
void DlgSettings3DViewImp::saveRenderCache() |
| 146 |
{ |
| 147 |
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( |
| 148 |
"User parameter:BaseApp/Preferences/View" |
| 149 |
); |
| 150 |
|
| 151 |
int cache = ui->renderCache->currentIndex(); |
| 152 |
hGrp->SetInt("RenderCache", cache); |
| 153 |
} |
| 154 |
|
| 155 |
void DlgSettings3DViewImp::loadRenderCache() |
| 156 |
{ |
| 157 |
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( |
| 158 |
"User parameter:BaseApp/Preferences/View" |
| 159 |
); |
| 160 |
|
| 161 |
long cache = hGrp->GetInt("RenderCache", 0); |
| 162 |
ui->renderCache->setCurrentIndex(int(cache)); |
| 163 |
} |
| 164 |
|
| 165 |
void DlgSettings3DViewImp::saveMarkerSize() |
| 166 |
{ |
| 167 |
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( |
| 168 |
"User parameter:BaseApp/Preferences/View" |
| 169 |
); |
| 170 |
|
| 171 |
QVariant const& vBoxMarkerSize = ui->boxMarkerSize->itemData(ui->boxMarkerSize->currentIndex()); |
| 172 |
hGrp->SetInt("MarkerSize", vBoxMarkerSize.toInt()); |
| 173 |
} |
| 174 |
|
| 175 |
void DlgSettings3DViewImp::loadMarkerSize() |
| 176 |
{ |
| 177 |
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( |
| 178 |
"User parameter:BaseApp/Preferences/View" |
| 179 |
); |
| 180 |
|
| 181 |
// NOLINTBEGIN |
| 182 |
int marker = hGrp->GetInt("MarkerSize", 9L); |
| 183 |
ui->boxMarkerSize->addItem(tr("5px"), QVariant(5)); |
| 184 |
ui->boxMarkerSize->addItem(tr("7px"), QVariant(7)); |
| 185 |
ui->boxMarkerSize->addItem(tr("9px"), QVariant(9)); |
| 186 |
ui->boxMarkerSize->addItem(tr("11px"), QVariant(11)); |
| 187 |
ui->boxMarkerSize->addItem(tr("13px"), QVariant(13)); |
| 188 |
ui->boxMarkerSize->addItem(tr("15px"), QVariant(15)); |
| 189 |
ui->boxMarkerSize->addItem(tr("20px"), QVariant(20)); |
| 190 |
ui->boxMarkerSize->addItem(tr("25px"), QVariant(25)); |
| 191 |
ui->boxMarkerSize->addItem(tr("30px"), QVariant(30)); |
| 192 |
marker = ui->boxMarkerSize->findData(QVariant(marker)); |
| 193 |
if (marker < 0) { |
| 194 |
marker = 2; |
| 195 |
} |
| 196 |
ui->boxMarkerSize->setCurrentIndex(marker); |
| 197 |
// NOLINTEND |
| 198 |
} |
| 199 |
|
| 200 |
void DlgSettings3DViewImp::resetSettingsToDefaults() |
| 201 |
{ |
| 202 |
ParameterGrp::handle hGrp; |
| 203 |
hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); |
| 204 |
// reset "AntiAliasing" parameter |
| 205 |
hGrp->RemoveInt("AntiAliasing"); |
| 206 |
// reset "RenderCache" parameter |
| 207 |
hGrp->RemoveInt("RenderCache"); |
| 208 |
// reset "MarkerSize" parameter |
| 209 |
hGrp->RemoveInt("MarkerSize"); |
| 210 |
|
| 211 |
// finally reset all the parameters associated to Gui::Pref* widgets |
| 212 |
PreferencePage::resetSettingsToDefaults(); |
| 213 |
} |
| 214 |
|
| 215 |
/** |
| 216 |
* Sets the strings of the subwidgets using the current language. |
| 217 |
*/ |
| 218 |
void DlgSettings3DViewImp::changeEvent(QEvent* e) |
| 219 |
{ |
| 220 |
if (e->type() == QEvent::LanguageChange) { |
| 221 |
ui->comboAliasing->blockSignals(true); |
| 222 |
int aliasing = ui->comboAliasing->currentIndex(); |
| 223 |
ui->retranslateUi(this); |
| 224 |
addAntiAliasing(); |
| 225 |
ui->comboAliasing->setCurrentIndex(aliasing); |
| 226 |
ui->comboAliasing->blockSignals(false); |
| 227 |
} |
| 228 |
else { |
| 229 |
PreferencePage::changeEvent(e); |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
void DlgSettings3DViewImp::onAliasingChanged(int index) |
| 234 |
{ |
| 235 |
if (index < 0 || !isVisible()) { |
| 236 |
return; |
| 237 |
} |
| 238 |
|
| 239 |
// Show this message only once per application session to reduce |
| 240 |
// annoyance when showing it too often. |
| 241 |
static bool showMsg = true; |
| 242 |
if (showMsg) { |
| 243 |
showMsg = false; |
| 244 |
QMessageBox::information( |
| 245 |
this, |
| 246 |
tr("Anti-aliasing"), |
| 247 |
tr("Open a new viewer or restart %1 to apply anti-aliasing changes.") |
| 248 |
.arg(qApp->applicationName()) |
| 249 |
); |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
#include "moc_DlgSettings3DViewImp.cpp" |