| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2023 Werner Mayer <wmayer[at]users.sourceforge.net> * |
| 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 <Inventor/fields/SoSFColor.h> |
| 25 |
#include <Inventor/nodes/SoDirectionalLight.h> |
| 26 |
#include <Inventor/nodes/SoOrthographicCamera.h> |
| 27 |
#include <Inventor/nodes/SoPerspectiveCamera.h> |
| 28 |
|
| 29 |
|
| 30 |
#include <Base/Builder3D.h> |
| 31 |
#include <Base/Color.h> |
| 32 |
|
| 33 |
#include "NaviCube.h" |
| 34 |
#include "Navigation/NavigationStyle.h" |
| 35 |
#include "SoFCSelectionAction.h" |
| 36 |
#include "View3DSettings.h" |
| 37 |
#include "View3DInventorViewer.h" |
| 38 |
|
| 39 |
#include <Base/Tools.h> |
| 40 |
|
| 41 |
using namespace Gui; |
| 42 |
|
| 43 |
View3DSettings::View3DSettings(ParameterGrp::handle hGrp, View3DInventorViewer* view) |
| 44 |
: hGrp(hGrp) |
| 45 |
, hLightSourcesGrp(hGrp->GetGroup("LightSources")) |
| 46 |
, _viewers {view} |
| 47 |
{ |
| 48 |
hGrp->Attach(this); |
| 49 |
hLightSourcesGrp->Attach(this); |
| 50 |
} |
| 51 |
|
| 52 |
View3DSettings::View3DSettings(ParameterGrp::handle hGrp, const std::vector<View3DInventorViewer*>& view) |
| 53 |
: hGrp(hGrp) |
| 54 |
, hLightSourcesGrp(hGrp->GetGroup("LightSources")) |
| 55 |
, _viewers(view) |
| 56 |
{ |
| 57 |
hGrp->Attach(this); |
| 58 |
hLightSourcesGrp->Attach(this); |
| 59 |
} |
| 60 |
|
| 61 |
View3DSettings::~View3DSettings() |
| 62 |
{ |
| 63 |
hGrp->Detach(this); |
| 64 |
hLightSourcesGrp->Detach(this); |
| 65 |
} |
| 66 |
|
| 67 |
int View3DSettings::stopAnimatingIfDeactivated() const |
| 68 |
{ |
| 69 |
long defaultTimeout = 3000; |
| 70 |
return hGrp->GetInt("stopAnimatingIfDeactivated", defaultTimeout); |
| 71 |
} |
| 72 |
|
| 73 |
void View3DSettings::applySettings() |
| 74 |
{ |
| 75 |
// apply the user settings |
| 76 |
OnChange(*hGrp, "EyeDistance"); |
| 77 |
OnChange(*hGrp, "CornerCoordSystem"); |
| 78 |
OnChange(*hGrp, "CornerCoordSystemSize"); |
| 79 |
OnChange(*hGrp, "AxisLetterColor"); |
| 80 |
OnChange(*hGrp, "ShowAxisCross"); |
| 81 |
OnChange(*hGrp, "UseNavigationAnimations"); |
| 82 |
OnChange(*hGrp, "UseSpinningAnimations"); |
| 83 |
OnChange(*hGrp, "Gradient"); |
| 84 |
OnChange(*hGrp, "RadialGradient"); |
| 85 |
OnChange(*hGrp, "BackgroundColor"); |
| 86 |
OnChange(*hGrp, "BackgroundColor2"); |
| 87 |
OnChange(*hGrp, "BackgroundColor3"); |
| 88 |
OnChange(*hGrp, "BackgroundColor4"); |
| 89 |
OnChange(*hGrp, "UseBackgroundColorMid"); |
| 90 |
OnChange(*hGrp, "ShowFPS"); |
| 91 |
OnChange(*hGrp, "ShowNaviCube"); |
| 92 |
OnChange(*hGrp, "AxisXColor"); |
| 93 |
OnChange(*hGrp, "AxisYColor"); |
| 94 |
OnChange(*hGrp, "AxisZColor"); |
| 95 |
OnChange(*hGrp, "UseVBO"); |
| 96 |
OnChange(*hGrp, "RenderCache"); |
| 97 |
OnChange(*hGrp, "Orthographic"); |
| 98 |
OnChange(*hGrp, "NavigationStyle"); |
| 99 |
OnChange(*hGrp, "OrbitStyle"); |
| 100 |
OnChange(*hGrp, "Sensitivity"); |
| 101 |
OnChange(*hGrp, "ResetCursorPosition"); |
| 102 |
OnChange(*hGrp, "DimensionsVisible"); |
| 103 |
OnChange(*hGrp, "Dimensions3dVisible"); |
| 104 |
OnChange(*hGrp, "DimensionsDeltaVisible"); |
| 105 |
OnChange(*hGrp, "PickRadius"); |
| 106 |
OnChange(*hGrp, "TransparentObjectRenderType"); |
| 107 |
|
| 108 |
auto lightSourcesGrp = hGrp->GetGroup("LightSources"); |
| 109 |
OnChange(*lightSourcesGrp, "EnableHeadlight"); |
| 110 |
OnChange(*lightSourcesGrp, "HeadlightColor"); |
| 111 |
OnChange(*lightSourcesGrp, "HeadlightDirection"); |
| 112 |
OnChange(*lightSourcesGrp, "HeadlightIntensity"); |
| 113 |
OnChange(*lightSourcesGrp, "EnableBacklight"); |
| 114 |
OnChange(*lightSourcesGrp, "BacklightColor"); |
| 115 |
OnChange(*lightSourcesGrp, "BacklightDirection"); |
| 116 |
OnChange(*lightSourcesGrp, "BacklightIntensity"); |
| 117 |
OnChange(*lightSourcesGrp, "EnableFillLight"); |
| 118 |
OnChange(*lightSourcesGrp, "FillLightColor"); |
| 119 |
OnChange(*lightSourcesGrp, "FillLightDirection"); |
| 120 |
OnChange(*lightSourcesGrp, "FillLightIntensity"); |
| 121 |
OnChange(*lightSourcesGrp, "AmbientLightColor"); |
| 122 |
OnChange(*lightSourcesGrp, "AmbientLightIntensity"); |
| 123 |
} |
| 124 |
|
| 125 |
void View3DSettings::OnChange(ParameterGrp::SubjectType& rCaller, ParameterGrp::MessageType Reason) |
| 126 |
{ |
| 127 |
const ParameterGrp& rGrp = static_cast<ParameterGrp&>(rCaller); |
| 128 |
if (strcmp(Reason, "EnableHeadlight") == 0) { |
| 129 |
bool enable = rGrp.GetBool("EnableHeadlight", true); |
| 130 |
for (auto _viewer : _viewers) { |
| 131 |
_viewer->setHeadlightEnabled(enable); |
| 132 |
} |
| 133 |
} |
| 134 |
else if (strcmp(Reason, "HeadlightColor") == 0) { |
| 135 |
unsigned long headlight = rGrp.GetUnsigned("HeadlightColor", 0xFFFFFFFF); // default color |
| 136 |
// (white) |
| 137 |
float transparency; |
| 138 |
SbColor headlightColor; |
| 139 |
headlightColor.setPackedValue((uint32_t)headlight, transparency); |
| 140 |
for (auto _viewer : _viewers) { |
| 141 |
_viewer->getHeadlight()->color.setValue(headlightColor); |
| 142 |
} |
| 143 |
} |
| 144 |
else if (strcmp(Reason, "HeadlightDirection") == 0) { |
| 145 |
try { |
| 146 |
std::string pos = rGrp.GetASCII("HeadlightDirection", defaultHeadLightDirection); |
| 147 |
if (!pos.empty()) { |
| 148 |
Base::Vector3f dir = Base::stringToVector(pos); |
| 149 |
for (auto _viewer : _viewers) { |
| 150 |
_viewer->getHeadlight()->direction.setValue(dir.x, dir.y, dir.z); |
| 151 |
} |
| 152 |
} |
| 153 |
} |
| 154 |
catch (const std::exception&) { |
| 155 |
// ignore exception |
| 156 |
} |
| 157 |
} |
| 158 |
else if (strcmp(Reason, "HeadlightIntensity") == 0) { |
| 159 |
long value = rGrp.GetInt("HeadlightIntensity", 90); |
| 160 |
for (auto _viewer : _viewers) { |
| 161 |
_viewer->getHeadlight()->intensity.setValue(Base::fromPercent(value)); |
| 162 |
} |
| 163 |
} |
| 164 |
else if (strcmp(Reason, "EnableBacklight") == 0) { |
| 165 |
for (auto _viewer : _viewers) { |
| 166 |
_viewer->setBacklightEnabled(rGrp.GetBool("EnableBacklight", true)); |
| 167 |
} |
| 168 |
} |
| 169 |
else if (strcmp(Reason, "BacklightColor") == 0) { |
| 170 |
unsigned long backlight = rGrp.GetUnsigned("BacklightColor", 0xF5F5EEFF); |
| 171 |
float transparency; |
| 172 |
SbColor backlightColor; |
| 173 |
backlightColor.setPackedValue((uint32_t)backlight, transparency); |
| 174 |
for (auto _viewer : _viewers) { |
| 175 |
_viewer->getBacklight()->color.setValue(backlightColor); |
| 176 |
} |
| 177 |
} |
| 178 |
else if (strcmp(Reason, "BacklightDirection") == 0) { |
| 179 |
try { |
| 180 |
std::string pos = rGrp.GetASCII("BacklightDirection", defaultBackLightDirection); |
| 181 |
if (!pos.empty()) { |
| 182 |
Base::Vector3f dir = Base::stringToVector(pos); |
| 183 |
for (auto _viewer : _viewers) { |
| 184 |
_viewer->getBacklight()->direction.setValue(dir.x, dir.y, dir.z); |
| 185 |
} |
| 186 |
} |
| 187 |
} |
| 188 |
catch (const std::exception&) { |
| 189 |
// ignore exception |
| 190 |
} |
| 191 |
} |
| 192 |
else if (strcmp(Reason, "BacklightIntensity") == 0) { |
| 193 |
long value = rGrp.GetInt("BacklightIntensity", 60); |
| 194 |
for (auto _viewer : _viewers) { |
| 195 |
_viewer->getBacklight()->intensity.setValue(Base::fromPercent(value)); |
| 196 |
} |
| 197 |
} |
| 198 |
else if (strcmp(Reason, "EnableFillLight") == 0) { |
| 199 |
for (auto _viewer : _viewers) { |
| 200 |
_viewer->setFillLightEnabled(rGrp.GetBool("EnableFillLight", true)); |
| 201 |
} |
| 202 |
} |
| 203 |
else if (strcmp(Reason, "FillLightColor") == 0) { |
| 204 |
unsigned long backlight = rGrp.GetUnsigned("FillLightColor", 0xE6FAFFFF); // default color |
| 205 |
// (white) |
| 206 |
float transparency; |
| 207 |
SbColor backlightColor; |
| 208 |
backlightColor.setPackedValue((uint32_t)backlight, transparency); |
| 209 |
for (auto _viewer : _viewers) { |
| 210 |
_viewer->getFillLight()->color.setValue(backlightColor); |
| 211 |
} |
| 212 |
} |
| 213 |
else if (strcmp(Reason, "FillLightDirection") == 0) { |
| 214 |
try { |
| 215 |
std::string pos = rGrp.GetASCII("FillLightDirection", defaultFillLightDirection); |
| 216 |
if (!pos.empty()) { |
| 217 |
Base::Vector3f dir = Base::stringToVector(pos); |
| 218 |
for (auto _viewer : _viewers) { |
| 219 |
_viewer->getFillLight()->direction.setValue(dir.x, dir.y, dir.z); |
| 220 |
} |
| 221 |
} |
| 222 |
} |
| 223 |
catch (const std::exception&) { |
| 224 |
// ignore exception |
| 225 |
} |
| 226 |
} |
| 227 |
else if (strcmp(Reason, "FillLightIntensity") == 0) { |
| 228 |
long value = rGrp.GetInt("FillLightIntensity", 40); |
| 229 |
for (auto _viewer : _viewers) { |
| 230 |
_viewer->getFillLight()->intensity.setValue(Base::fromPercent(value)); |
| 231 |
} |
| 232 |
} |
| 233 |
else if (strcmp(Reason, "AmbientLightColor") == 0) { |
| 234 |
unsigned long color = rGrp.GetUnsigned("AmbientLightColor", 0xFFFFFFFF); |
| 235 |
float transparency; |
| 236 |
SbColor backlightColor; |
| 237 |
backlightColor.setPackedValue((uint32_t)color, transparency); |
| 238 |
for (auto _viewer : _viewers) { |
| 239 |
_viewer->getEnvironment()->ambientColor.setValue(backlightColor); |
| 240 |
} |
| 241 |
} |
| 242 |
else if (strcmp(Reason, "AmbientLightIntensity") == 0) { |
| 243 |
long value = rGrp.GetInt("AmbientLightIntensity", 20); |
| 244 |
for (auto _viewer : _viewers) { |
| 245 |
_viewer->getEnvironment()->ambientIntensity.setValue(Base::fromPercent(value)); |
| 246 |
} |
| 247 |
} |
| 248 |
else if (strcmp(Reason, "EnablePreselection") == 0) { |
| 249 |
const ParameterGrp& rclGrp = ((ParameterGrp&)rCaller); |
| 250 |
SoFCEnablePreselectionAction cAct(rclGrp.GetBool("EnablePreselection", true)); |
| 251 |
for (auto _viewer : _viewers) { |
| 252 |
cAct.apply(_viewer->getSceneGraph()); |
| 253 |
} |
| 254 |
} |
| 255 |
else if (strcmp(Reason, "EnableSelection") == 0) { |
| 256 |
const ParameterGrp& rclGrp = ((ParameterGrp&)rCaller); |
| 257 |
SoFCEnableSelectionAction cAct(rclGrp.GetBool("EnableSelection", true)); |
| 258 |
for (auto _viewer : _viewers) { |
| 259 |
cAct.apply(_viewer->getSceneGraph()); |
| 260 |
} |
| 261 |
} |
| 262 |
else if (strcmp(Reason, "HighlightColor") == 0) { |
| 263 |
float transparency; |
| 264 |
SbColor highlightColor(0.8f, 0.1f, 0.1f); |
| 265 |
auto highlight = (unsigned long)(highlightColor.getPackedValue()); |
| 266 |
highlight = rGrp.GetUnsigned("HighlightColor", highlight); |
| 267 |
highlightColor.setPackedValue((uint32_t)highlight, transparency); |
| 268 |
SoSFColor col; |
| 269 |
col.setValue(highlightColor); |
| 270 |
SoFCHighlightColorAction cAct(col); |
| 271 |
for (auto _viewer : _viewers) { |
| 272 |
cAct.apply(_viewer->getSceneGraph()); |
| 273 |
} |
| 274 |
} |
| 275 |
else if (strcmp(Reason, "SelectionColor") == 0) { |
| 276 |
float transparency; |
| 277 |
SbColor selectionColor(0.1f, 0.8f, 0.1f); |
| 278 |
auto selection = (unsigned long)(selectionColor.getPackedValue()); |
| 279 |
selection = rGrp.GetUnsigned("SelectionColor", selection); |
| 280 |
selectionColor.setPackedValue((uint32_t)selection, transparency); |
| 281 |
SoSFColor col; |
| 282 |
col.setValue(selectionColor); |
| 283 |
SoFCSelectionColorAction cAct(col); |
| 284 |
for (auto _viewer : _viewers) { |
| 285 |
cAct.apply(_viewer->getSceneGraph()); |
| 286 |
} |
| 287 |
} |
| 288 |
else if (strcmp(Reason, "NavigationStyle") == 0) { |
| 289 |
if (!ignoreNavigationStyle) { |
| 290 |
// check whether the simple or the full mouse model is used |
| 291 |
std::string model |
| 292 |
= rGrp.GetASCII("NavigationStyle", CADNavigationStyle::getClassTypeId().getName()); |
| 293 |
Base::Type type = Base::Type::fromName(model.c_str()); |
| 294 |
for (auto _viewer : _viewers) { |
| 295 |
_viewer->setNavigationType(type); |
| 296 |
} |
| 297 |
} |
| 298 |
} |
| 299 |
else if (strcmp(Reason, "OrbitStyle") == 0) { |
| 300 |
int style = rGrp.GetInt("OrbitStyle", 4); |
| 301 |
for (auto _viewer : _viewers) { |
| 302 |
_viewer->navigationStyle()->setOrbitStyle(NavigationStyle::OrbitStyle(style)); |
| 303 |
} |
| 304 |
} |
| 305 |
else if (strcmp(Reason, "Sensitivity") == 0) { |
| 306 |
float val = rGrp.GetFloat("Sensitivity", 2.0f); |
| 307 |
for (auto _viewer : _viewers) { |
| 308 |
_viewer->navigationStyle()->setSensitivity(val); |
| 309 |
} |
| 310 |
} |
| 311 |
else if (strcmp(Reason, "ResetCursorPosition") == 0) { |
| 312 |
bool on = rGrp.GetBool("ResetCursorPosition", false); |
| 313 |
for (auto _viewer : _viewers) { |
| 314 |
_viewer->navigationStyle()->setResetCursorPosition(on); |
| 315 |
} |
| 316 |
} |
| 317 |
else if (strcmp(Reason, "InvertZoom") == 0) { |
| 318 |
bool on = rGrp.GetBool("InvertZoom", true); |
| 319 |
for (auto _viewer : _viewers) { |
| 320 |
_viewer->navigationStyle()->setZoomInverted(on); |
| 321 |
} |
| 322 |
} |
| 323 |
else if (strcmp(Reason, "ZoomAtCursor") == 0) { |
| 324 |
bool on = rGrp.GetBool("ZoomAtCursor", true); |
| 325 |
for (auto _viewer : _viewers) { |
| 326 |
_viewer->navigationStyle()->setZoomAtCursor(on); |
| 327 |
} |
| 328 |
} |
| 329 |
else if (strcmp(Reason, "ZoomStep") == 0) { |
| 330 |
float val = rGrp.GetFloat("ZoomStep", 0.0f); |
| 331 |
for (auto _viewer : _viewers) { |
| 332 |
_viewer->navigationStyle()->setZoomStep(val); |
| 333 |
} |
| 334 |
} |
| 335 |
else if (strcmp(Reason, "RotationMode") == 0) { |
| 336 |
long mode = rGrp.GetInt("RotationMode", 1); |
| 337 |
for (auto _viewer : _viewers) { |
| 338 |
if (mode == 0) { |
| 339 |
_viewer->navigationStyle()->setRotationCenterMode( |
| 340 |
NavigationStyle::RotationCenterMode::WindowCenter |
| 341 |
); |
| 342 |
} |
| 343 |
else if (mode == 1) { |
| 344 |
_viewer->navigationStyle()->setRotationCenterMode( |
| 345 |
NavigationStyle::RotationCenterMode::ScenePointAtCursor |
| 346 |
| NavigationStyle::RotationCenterMode::FocalPointAtCursor |
| 347 |
); |
| 348 |
} |
| 349 |
else if (mode == 2) { |
| 350 |
_viewer->navigationStyle()->setRotationCenterMode( |
| 351 |
NavigationStyle::RotationCenterMode::ScenePointAtCursor |
| 352 |
| NavigationStyle::RotationCenterMode::BoundingBoxCenter |
| 353 |
); |
| 354 |
} |
| 355 |
} |
| 356 |
} |
| 357 |
else if (strcmp(Reason, "EyeDistance") == 0) { |
| 358 |
for (auto _viewer : _viewers) { |
| 359 |
_viewer->getSoRenderManager()->setStereoOffset(rGrp.GetFloat("EyeDistance", 5.0)); |
| 360 |
} |
| 361 |
} |
| 362 |
else if (strcmp(Reason, "CornerCoordSystem") == 0) { |
| 363 |
for (auto _viewer : _viewers) { |
| 364 |
_viewer->setFeedbackVisibility(rGrp.GetBool("CornerCoordSystem", true)); |
| 365 |
} |
| 366 |
} |
| 367 |
else if (strcmp(Reason, "CornerCoordSystemSize") == 0) { |
| 368 |
for (auto _viewer : _viewers) { |
| 369 |
_viewer->setFeedbackSize(rGrp.GetInt("CornerCoordSystemSize", 10)); |
| 370 |
} |
| 371 |
} |
| 372 |
else if (strcmp(Reason, "AxisLetterColor") == 0) { |
| 373 |
unsigned long backlight = rGrp.GetUnsigned("AxisLetterColor", 0x00000000); // default color |
| 374 |
// (black) |
| 375 |
float transparency; |
| 376 |
SbColor color; |
| 377 |
color.setPackedValue((uint32_t)backlight, transparency); |
| 378 |
for (auto _viewer : _viewers) { |
| 379 |
_viewer->setAxisLetterColor(color); |
| 380 |
} |
| 381 |
} |
| 382 |
else if (strcmp(Reason, "ShowAxisCross") == 0) { |
| 383 |
for (auto _viewer : _viewers) { |
| 384 |
_viewer->setAxisCross(rGrp.GetBool("ShowAxisCross", false)); |
| 385 |
} |
| 386 |
} |
| 387 |
else if (strcmp(Reason, "UseNavigationAnimations") == 0) { |
| 388 |
for (auto _viewer : _viewers) { |
| 389 |
_viewer->setAnimationEnabled(rGrp.GetBool("UseNavigationAnimations", true)); |
| 390 |
} |
| 391 |
} |
| 392 |
else if (strcmp(Reason, "UseSpinningAnimations") == 0) { |
| 393 |
for (auto _viewer : _viewers) { |
| 394 |
_viewer->setSpinningAnimationEnabled(rGrp.GetBool("UseSpinningAnimations", false)); |
| 395 |
} |
| 396 |
} |
| 397 |
else if (strcmp(Reason, "Gradient") == 0 || strcmp(Reason, "RadialGradient") == 0) { |
| 398 |
View3DInventorViewer::Background background = View3DInventorViewer::Background::NoGradient; |
| 399 |
if (rGrp.GetBool("Gradient", true)) { |
| 400 |
background = View3DInventorViewer::Background::LinearGradient; |
| 401 |
} |
| 402 |
else if (rGrp.GetBool("RadialGradient", false)) { |
| 403 |
background = View3DInventorViewer::Background::RadialGradient; |
| 404 |
} |
| 405 |
for (auto _viewer : _viewers) { |
| 406 |
_viewer->setGradientBackground(background); |
| 407 |
} |
| 408 |
} |
| 409 |
else if (strcmp(Reason, "ShowFPS") == 0) { |
| 410 |
for (auto _viewer : _viewers) { |
| 411 |
_viewer->setEnabledFPSCounter(rGrp.GetBool("ShowFPS", false)); |
| 412 |
} |
| 413 |
} |
| 414 |
else if (strcmp(Reason, "ShowNaviCube") == 0) { |
| 415 |
for (auto _viewer : _viewers) { |
| 416 |
_viewer->setEnabledNaviCube(rGrp.GetBool("ShowNaviCube", true)); |
| 417 |
} |
| 418 |
} |
| 419 |
else if (strcmp(Reason, "AxisXColor") == 0 || strcmp(Reason, "AxisYColor") == 0 |
| 420 |
|| strcmp(Reason, "AxisZColor") == 0) { |
| 421 |
for (auto _viewer : _viewers) { |
| 422 |
_viewer->updateColors(); |
| 423 |
} |
| 424 |
} |
| 425 |
else if (strcmp(Reason, "UseVBO") == 0) { |
| 426 |
if (!ignoreVBO) { |
| 427 |
for (auto _viewer : _viewers) { |
| 428 |
_viewer->setEnabledVBO(rGrp.GetBool("UseVBO", false)); |
| 429 |
} |
| 430 |
} |
| 431 |
} |
| 432 |
else if (strcmp(Reason, "RenderCache") == 0) { |
| 433 |
if (!ignoreRenderCache) { |
| 434 |
for (auto _viewer : _viewers) { |
| 435 |
_viewer->setRenderCache(rGrp.GetInt("RenderCache", 0)); |
| 436 |
} |
| 437 |
} |
| 438 |
} |
| 439 |
else if (strcmp(Reason, "Orthographic") == 0) { |
| 440 |
// check whether a perspective or orthogrphic camera should be set |
| 441 |
if (rGrp.GetBool("Orthographic", true)) { |
| 442 |
for (auto _viewer : _viewers) { |
| 443 |
_viewer->setCameraType(SoOrthographicCamera::getClassTypeId()); |
| 444 |
} |
| 445 |
} |
| 446 |
else { |
| 447 |
for (auto _viewer : _viewers) { |
| 448 |
_viewer->setCameraType(SoPerspectiveCamera::getClassTypeId()); |
| 449 |
} |
| 450 |
} |
| 451 |
} |
| 452 |
else if (strcmp(Reason, "DimensionsVisible") == 0) { |
| 453 |
if (!ignoreDimensions) { |
| 454 |
if (rGrp.GetBool("DimensionsVisible", true)) { |
| 455 |
for (auto _viewer : _viewers) { |
| 456 |
_viewer->turnAllDimensionsOn(); |
| 457 |
} |
| 458 |
} |
| 459 |
else { |
| 460 |
for (auto _viewer : _viewers) { |
| 461 |
_viewer->turnAllDimensionsOff(); |
| 462 |
} |
| 463 |
} |
| 464 |
} |
| 465 |
} |
| 466 |
else if (strcmp(Reason, "Dimensions3dVisible") == 0) { |
| 467 |
if (!ignoreDimensions) { |
| 468 |
if (rGrp.GetBool("Dimensions3dVisible", true)) { |
| 469 |
for (auto _viewer : _viewers) { |
| 470 |
_viewer->turn3dDimensionsOn(); |
| 471 |
} |
| 472 |
} |
| 473 |
else { |
| 474 |
for (auto _viewer : _viewers) { |
| 475 |
_viewer->turn3dDimensionsOff(); |
| 476 |
} |
| 477 |
} |
| 478 |
} |
| 479 |
} |
| 480 |
else if (strcmp(Reason, "DimensionsDeltaVisible") == 0) { |
| 481 |
if (!ignoreDimensions) { |
| 482 |
if (rGrp.GetBool("DimensionsDeltaVisible", true)) { |
| 483 |
for (auto _viewer : _viewers) { |
| 484 |
_viewer->turnDeltaDimensionsOn(); |
| 485 |
} |
| 486 |
} |
| 487 |
else { |
| 488 |
for (auto _viewer : _viewers) { |
| 489 |
_viewer->turnDeltaDimensionsOff(); |
| 490 |
} |
| 491 |
} |
| 492 |
} |
| 493 |
} |
| 494 |
else if (strcmp(Reason, "PickRadius") == 0) { |
| 495 |
for (auto _viewer : _viewers) { |
| 496 |
_viewer->setPickRadius(rGrp.GetFloat("PickRadius", 5.0f)); |
| 497 |
} |
| 498 |
} |
| 499 |
else if (strcmp(Reason, "TransparentObjectRenderType") == 0) { |
| 500 |
if (!ignoreTransparent) { |
| 501 |
long renderType = rGrp.GetInt("TransparentObjectRenderType", 0); |
| 502 |
if (renderType == 0) { |
| 503 |
for (auto _viewer : _viewers) { |
| 504 |
_viewer->getSoRenderManager() |
| 505 |
->getGLRenderAction() |
| 506 |
->setTransparentDelayedObjectRenderType(SoGLRenderAction::ONE_PASS); |
| 507 |
} |
| 508 |
} |
| 509 |
else if (renderType == 1) { |
| 510 |
for (auto _viewer : _viewers) { |
| 511 |
_viewer->getSoRenderManager()->getGLRenderAction()->setTransparentDelayedObjectRenderType( |
| 512 |
SoGLRenderAction::NONSOLID_SEPARATE_BACKFACE_PASS |
| 513 |
); |
| 514 |
} |
| 515 |
} |
| 516 |
} |
| 517 |
} |
| 518 |
else { |
| 519 |
unsigned long col1 = rGrp.GetUnsigned("BackgroundColor", 3940932863UL); |
| 520 |
unsigned long col2 = rGrp.GetUnsigned("BackgroundColor2", 859006463UL); // default color |
| 521 |
// (dark blue) |
| 522 |
unsigned long col3 = rGrp.GetUnsigned("BackgroundColor3", 2880160255UL); // default color |
| 523 |
// (blue/grey) |
| 524 |
unsigned long col4 = rGrp.GetUnsigned("BackgroundColor4", 1869583359UL); // default color |
| 525 |
// (blue/grey) |
| 526 |
float r1, g1, b1, r2, g2, b2, r3, g3, b3, r4, g4, b4; |
| 527 |
r1 = ((col1 >> 24) & 0xff) / 255.0; |
| 528 |
g1 = ((col1 >> 16) & 0xff) / 255.0; |
| 529 |
b1 = ((col1 >> 8) & 0xff) / 255.0; |
| 530 |
r2 = ((col2 >> 24) & 0xff) / 255.0; |
| 531 |
g2 = ((col2 >> 16) & 0xff) / 255.0; |
| 532 |
b2 = ((col2 >> 8) & 0xff) / 255.0; |
| 533 |
r3 = ((col3 >> 24) & 0xff) / 255.0; |
| 534 |
g3 = ((col3 >> 16) & 0xff) / 255.0; |
| 535 |
b3 = ((col3 >> 8) & 0xff) / 255.0; |
| 536 |
r4 = ((col4 >> 24) & 0xff) / 255.0; |
| 537 |
g4 = ((col4 >> 16) & 0xff) / 255.0; |
| 538 |
b4 = ((col4 >> 8) & 0xff) / 255.0; |
| 539 |
for (auto _viewer : _viewers) { |
| 540 |
_viewer->setBackgroundColor(QColor::fromRgbF(r1, g1, b1)); |
| 541 |
if (!rGrp.GetBool("UseBackgroundColorMid", false)) { |
| 542 |
_viewer->setGradientBackgroundColor(SbColor(r2, g2, b2), SbColor(r3, g3, b3)); |
| 543 |
} |
| 544 |
else { |
| 545 |
_viewer->setGradientBackgroundColor( |
| 546 |
SbColor(r2, g2, b2), |
| 547 |
SbColor(r3, g3, b3), |
| 548 |
SbColor(r4, g4, b4) |
| 549 |
); |
| 550 |
} |
| 551 |
} |
| 552 |
} |
| 553 |
} |
| 554 |
|
| 555 |
// ---------------------------------------------------------------------------- |
| 556 |
|
| 557 |
NaviCubeSettings::NaviCubeSettings(ParameterGrp::handle hGrp, View3DInventorViewer* view) |
| 558 |
: hGrp(hGrp) |
| 559 |
, _viewer(view) |
| 560 |
{ |
| 561 |
connectParameterChanged = hGrp->Manager()->signalParamChanged.connect( |
| 562 |
[this](ParameterGrp*, ParameterGrp::ParamType, const char* Name, const char*) { |
| 563 |
parameterChanged(Name); |
| 564 |
} |
| 565 |
); |
| 566 |
} |
| 567 |
|
| 568 |
NaviCubeSettings::~NaviCubeSettings() |
| 569 |
{ |
| 570 |
connectParameterChanged.disconnect(); |
| 571 |
} |
| 572 |
|
| 573 |
void NaviCubeSettings::applySettings() |
| 574 |
{ |
| 575 |
parameterChanged("BaseColor"); |
| 576 |
parameterChanged("EmphaseColor"); |
| 577 |
parameterChanged("HiliteColor"); |
| 578 |
parameterChanged("CornerNaviCube"); |
| 579 |
parameterChanged("OffsetX"); // Updates OffsetY too |
| 580 |
parameterChanged("CubeSize"); |
| 581 |
parameterChanged("ChamferSize"); |
| 582 |
parameterChanged("NaviRotateToNearest"); |
| 583 |
parameterChanged("NaviStepByTurn"); |
| 584 |
parameterChanged("BorderWidth"); |
| 585 |
parameterChanged("FontZoom"); |
| 586 |
parameterChanged("FontString"); |
| 587 |
parameterChanged("FontWeight"); |
| 588 |
parameterChanged("FontStretch"); |
| 589 |
parameterChanged("ShowCS"); |
| 590 |
parameterChanged("InactiveOpacity"); |
| 591 |
parameterChanged("TextFront"); // Updates all labels |
| 592 |
} |
| 593 |
|
| 594 |
void NaviCubeSettings::parameterChanged(const char* Name) |
| 595 |
{ |
| 596 |
if (Name == nullptr) { |
| 597 |
return; |
| 598 |
} |
| 599 |
NaviCube* nc = _viewer->getNaviCube(); |
| 600 |
if (strcmp(Name, "CornerNaviCube") == 0) { |
| 601 |
nc->setCorner(static_cast<NaviCube::Corner>(hGrp->GetInt("CornerNaviCube", 1))); |
| 602 |
} |
| 603 |
else if (strcmp(Name, "OffsetX") == 0 || strcmp(Name, "OffsetY") == 0) { |
| 604 |
nc->setOffset(hGrp->GetInt("OffsetX", 0), hGrp->GetInt("OffsetY", 0)); |
| 605 |
} |
| 606 |
else if (strcmp(Name, "ChamferSize") == 0) { |
| 607 |
nc->setChamfer(hGrp->GetFloat("ChamferSize", 0.12f)); |
| 608 |
} |
| 609 |
else if (strcmp(Name, "CubeSize") == 0) { |
| 610 |
nc->setSize(hGrp->GetInt("CubeSize", 132)); |
| 611 |
} |
| 612 |
else if (strcmp(Name, "NaviRotateToNearest") == 0) { |
| 613 |
nc->setNaviRotateToNearest(hGrp->GetBool("NaviRotateToNearest", true)); |
| 614 |
} |
| 615 |
else if (strcmp(Name, "NaviStepByTurn") == 0) { |
| 616 |
nc->setNaviStepByTurn(hGrp->GetInt("NaviStepByTurn", 8)); |
| 617 |
} |
| 618 |
else if (strcmp(Name, "FontZoom") == 0) { |
| 619 |
nc->setFontZoom(hGrp->GetFloat("FontZoom", 0.3)); |
| 620 |
} |
| 621 |
else if (strcmp(Name, "FontString") == 0) { |
| 622 |
nc->setFont(hGrp->GetASCII("FontString")); |
| 623 |
} |
| 624 |
else if (strcmp(Name, "FontWeight") == 0) { |
| 625 |
nc->setFontWeight(hGrp->GetInt("FontWeight", 0)); |
| 626 |
} |
| 627 |
else if (strcmp(Name, "FontStretch") == 0) { |
| 628 |
nc->setFontStretch(hGrp->GetInt("FontStretch", 0)); |
| 629 |
} |
| 630 |
else if (strcmp(Name, "BaseColor") == 0) { |
| 631 |
unsigned long col = hGrp->GetUnsigned("BaseColor", 3806916544); |
| 632 |
nc->setBaseColor(Base::Color::fromPackedRGBA<QColor>(col)); |
| 633 |
// update default contrast colors |
| 634 |
parameterChanged("EmphaseColor"); |
| 635 |
} |
| 636 |
else if (strcmp(Name, "EmphaseColor") == 0) { |
| 637 |
Base::Color bc((uint32_t)hGrp->GetUnsigned("BaseColor", 3806916544)); |
| 638 |
unsigned long d = bc.r + bc.g + bc.b >= 1.5f ? 255 : 4294967295; |
| 639 |
unsigned long col = hGrp->GetUnsigned("EmphaseColor", d); |
| 640 |
nc->setEmphaseColor(Base::Color::fromPackedRGBA<QColor>(col)); |
| 641 |
} |
| 642 |
else if (strcmp(Name, "HiliteColor") == 0) { |
| 643 |
unsigned long col = hGrp->GetUnsigned("HiliteColor", 2867003391); |
| 644 |
nc->setHiliteColor(Base::Color::fromPackedRGBA<QColor>(col)); |
| 645 |
} |
| 646 |
else if (strcmp(Name, "BorderWidth") == 0) { |
| 647 |
nc->setBorderWidth(hGrp->GetFloat("BorderWidth", 1.1)); |
| 648 |
} |
| 649 |
else if (strcmp(Name, "ShowCS") == 0) { |
| 650 |
nc->setShowCS(hGrp->GetBool("ShowCS", true)); |
| 651 |
} |
| 652 |
else if (strcmp(Name, "InactiveOpacity") == 0) { |
| 653 |
float opacity = static_cast<float>(hGrp->GetInt("InactiveOpacity", 50)) / 100; |
| 654 |
nc->setInactiveOpacity(opacity); |
| 655 |
} |
| 656 |
else if (strcmp(Name, "TextTop") == 0 || strcmp(Name, "TextBottom") == 0 |
| 657 |
|| strcmp(Name, "TextFront") == 0 || strcmp(Name, "TextRear") == 0 |
| 658 |
|| strcmp(Name, "TextLeft") == 0 || strcmp(Name, "TextRight") == 0) { |
| 659 |
std::vector<std::string> labels; |
| 660 |
QByteArray frontByteArray = tr("FRONT").toUtf8(); |
| 661 |
labels.push_back(hGrp->GetASCII("TextFront", frontByteArray.constData())); |
| 662 |
QByteArray topByteArray = tr("TOP").toUtf8(); |
| 663 |
labels.push_back(hGrp->GetASCII("TextTop", topByteArray.constData())); |
| 664 |
QByteArray rightByteArray = tr("RIGHT").toUtf8(); |
| 665 |
labels.push_back(hGrp->GetASCII("TextRight", rightByteArray.constData())); |
| 666 |
QByteArray rearByteArray = tr("REAR").toUtf8(); |
| 667 |
labels.push_back(hGrp->GetASCII("TextRear", rearByteArray.constData())); |
| 668 |
QByteArray bottomByteArray = tr("BOTTOM").toUtf8(); |
| 669 |
labels.push_back(hGrp->GetASCII("TextBottom", bottomByteArray.constData())); |
| 670 |
QByteArray leftByteArray = tr("LEFT").toUtf8(); |
| 671 |
labels.push_back(hGrp->GetASCII("TextLeft", leftByteArray.constData())); |
| 672 |
nc->setNaviCubeLabels(labels); |
| 673 |
} |
| 674 |
_viewer->getSoRenderManager()->scheduleRedraw(); |
| 675 |
} |