FreeCAD

Форк
0
/
ViewProviderBuilder.cpp 
113 строк · 4.6 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2010 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
#include "PreCompiled.h"
24

25
#ifndef _PreComp_
26
# include <Inventor/nodes/SoMaterial.h>
27
#endif
28

29
#include <App/PropertyStandard.h>
30

31
#include "ViewProviderBuilder.h"
32
#include "SoFCSelection.h"
33
#include "Window.h"
34

35

36
using namespace Gui;
37

38
std::map<Base::Type, Base::Type> ViewProviderBuilder::_prop_to_view;
39

40
ViewProviderBuilder::ViewProviderBuilder() = default;
41

42
ViewProviderBuilder::~ViewProviderBuilder() = default;
43

44
void ViewProviderBuilder::add(const Base::Type& prop, const Base::Type& view)
45
{
46
    _prop_to_view[prop] = view;
47
}
48

49
ViewProvider* ViewProviderBuilder::create(const Base::Type& type)
50
{
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());
54
    return nullptr;
55
}
56

57
Gui::SoFCSelection* ViewProviderBuilder::createSelection()
58
{
59
    auto sel = new Gui::SoFCSelection();
60

61
    float transparency;
62
    ParameterGrp::handle hGrp = Gui::WindowParameter::getDefaultParameter()->GetGroup("View");
63
    bool enablePre = hGrp->GetBool("EnablePreselection", true);
64
    bool enableSel = hGrp->GetBool("EnableSelection", true);
65
    if (!enablePre) {
66
        sel->highlightMode = Gui::SoFCSelection::OFF;
67
    }
68
    else {
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);
75
    }
76
    if (!enableSel) {
77
        sel->selectionMode = Gui::SoFCSelection::SEL_OFF;
78
    }
79
    else {
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);
86
    }
87

88
    return sel;
89
}
90

91
// --------------------------------------
92

93
ViewProviderColorBuilder::ViewProviderColorBuilder() = default;
94

95
ViewProviderColorBuilder::~ViewProviderColorBuilder() = default;
96

97
void ViewProviderColorBuilder::buildNodes(const App::Property* prop, std::vector<SoNode*>& node) const
98
{
99
    const auto color = static_cast<const App::PropertyColorList*>(prop);
100
    const std::vector<App::Color>& val = color->getValues();
101
    unsigned long i=0;
102

103
    auto material = new SoMaterial();
104
    material->diffuseColor.setNum(val.size());
105

106
    SbColor* colors = material->diffuseColor.startEditing();
107
    for (const auto & it : val) {
108
        colors[i].setValue(it.r, it.g, it.b);
109
        i++;
110
    }
111
    material->diffuseColor.finishEditing();
112
    node.push_back(material);
113
}
114

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

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

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

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