1
/***************************************************************************
2
* Copyright (c) 2010 Werner Mayer <wmayer[at]users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
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. *
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. *
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 *
21
***************************************************************************/
23
#include "PreCompiled.h"
26
# include <Inventor/nodes/SoMaterial.h>
29
#include <App/PropertyStandard.h>
31
#include "ViewProviderBuilder.h"
32
#include "SoFCSelection.h"
38
std::map<Base::Type, Base::Type> ViewProviderBuilder::_prop_to_view;
40
ViewProviderBuilder::ViewProviderBuilder() = default;
42
ViewProviderBuilder::~ViewProviderBuilder() = default;
44
void ViewProviderBuilder::add(const Base::Type& prop, const Base::Type& view)
46
_prop_to_view[prop] = view;
49
ViewProvider* ViewProviderBuilder::create(const Base::Type& type)
51
std::map<Base::Type, Base::Type>::iterator it = _prop_to_view.find(type);
52
if (it != _prop_to_view.end())
53
return static_cast<ViewProvider*>(it->second.createInstance());
57
Gui::SoFCSelection* ViewProviderBuilder::createSelection()
59
auto sel = new Gui::SoFCSelection();
62
ParameterGrp::handle hGrp = Gui::WindowParameter::getDefaultParameter()->GetGroup("View");
63
bool enablePre = hGrp->GetBool("EnablePreselection", true);
64
bool enableSel = hGrp->GetBool("EnableSelection", true);
66
sel->highlightMode = Gui::SoFCSelection::OFF;
69
// Search for a user defined value with the current color as default
70
SbColor highlightColor = sel->colorHighlight.getValue();
71
auto highlight = (unsigned long)(highlightColor.getPackedValue());
72
highlight = hGrp->GetUnsigned("HighlightColor", highlight);
73
highlightColor.setPackedValue((uint32_t)highlight, transparency);
74
sel->colorHighlight.setValue(highlightColor);
77
sel->selectionMode = Gui::SoFCSelection::SEL_OFF;
80
// Do the same with the selection color
81
SbColor selectionColor = sel->colorSelection.getValue();
82
auto selection = (unsigned long)(selectionColor.getPackedValue());
83
selection = hGrp->GetUnsigned("SelectionColor", selection);
84
selectionColor.setPackedValue((uint32_t)selection, transparency);
85
sel->colorSelection.setValue(selectionColor);
91
// --------------------------------------
93
ViewProviderColorBuilder::ViewProviderColorBuilder() = default;
95
ViewProviderColorBuilder::~ViewProviderColorBuilder() = default;
97
void ViewProviderColorBuilder::buildNodes(const App::Property* prop, std::vector<SoNode*>& node) const
99
const auto color = static_cast<const App::PropertyColorList*>(prop);
100
const std::vector<App::Color>& val = color->getValues();
103
auto material = new SoMaterial();
104
material->diffuseColor.setNum(val.size());
106
SbColor* colors = material->diffuseColor.startEditing();
107
for (const auto & it : val) {
108
colors[i].setValue(it.r, it.g, it.b);
111
material->diffuseColor.finishEditing();
112
node.push_back(material);