FreeCAD

Форк
0
/
ViewProviderMeshFaceSet.cpp 
204 строки · 7.1 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2006 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
#ifndef _PreComp_
25
#include <algorithm>
26

27
#include <Inventor/nodes/SoBaseColor.h>
28
#include <Inventor/nodes/SoCoordinate3.h>
29
#include <Inventor/nodes/SoDrawStyle.h>
30
#include <Inventor/nodes/SoIndexedLineSet.h>
31
#include <Inventor/nodes/SoMaterial.h>
32
#include <Inventor/nodes/SoSeparator.h>
33
#endif
34

35
#include <App/Document.h>
36
#include <Gui/Selection.h>
37
#include <Gui/Window.h>
38
#include <Mod/Mesh/App/MeshFeature.h>
39
#include <Mod/Mesh/App/Core/Iterator.h>
40
#include <Mod/Mesh/App/Core/MeshKernel.h>
41

42
#include "ViewProviderMeshFaceSet.h"
43
#include "SoFCIndexedFaceSet.h"
44
#include "SoFCMeshObject.h"
45

46

47
using namespace MeshGui;
48

49
PROPERTY_SOURCE(MeshGui::ViewProviderMeshFaceSet, MeshGui::ViewProviderMesh)
50

51
ViewProviderMeshFaceSet::ViewProviderMeshFaceSet()
52
{
53
    // NOLINTBEGIN
54
    directRendering = false;
55
    triangleCount = 2500000;
56

57
    pcMeshNode = new SoFCMeshObjectNode;
58
    pcMeshNode->ref();
59
    pcMeshShape = new SoFCMeshObjectShape;
60
    pcMeshShape->ref();
61
    pcMeshCoord = new SoCoordinate3;
62
    pcMeshCoord->ref();
63
    pcMeshFaces = new SoFCIndexedFaceSet;
64
    pcMeshFaces->ref();
65

66
    // setup engine to notify 'pcMeshFaces' node about material changes.
67
    // When the affected nodes are deleted the engine will be deleted, too.
68
    SoFCMaterialEngine* engine = new SoFCMaterialEngine();
69
    engine->diffuseColor.connectFrom(&pcShapeMaterial->diffuseColor);
70
    pcMeshFaces->updateGLArray.connectFrom(&engine->trigger);
71
    // NOLINTEND
72
}
73

74
ViewProviderMeshFaceSet::~ViewProviderMeshFaceSet()
75
{
76
    pcMeshNode->unref();
77
    pcMeshShape->unref();
78
    pcMeshCoord->unref();
79
    pcMeshFaces->unref();
80
}
81

82
void ViewProviderMeshFaceSet::attach(App::DocumentObject* pcFeat)
83
{
84
    ViewProviderMesh::attach(pcFeat);
85

86
    pcShapeGroup->addChild(pcMeshCoord);
87
    pcShapeGroup->addChild(pcMeshFaces);
88

89
    // read the threshold from the preferences
90
    Base::Reference<ParameterGrp> hGrp =
91
        Gui::WindowParameter::getDefaultParameter()->GetGroup("Mod/Mesh");
92
    int size = hGrp->GetInt("RenderTriangleLimit", -1);
93
    if (size > 0) {
94
        pcMeshShape->renderTriangleLimit = (unsigned int)(pow(10.0F, size));
95
        static_cast<SoFCIndexedFaceSet*>(pcMeshFaces)->renderTriangleLimit =
96
            (unsigned int)(pow(10.0F, size));
97
    }
98
}
99

100
void ViewProviderMeshFaceSet::updateData(const App::Property* prop)
101
{
102
    ViewProviderMesh::updateData(prop);
103
    if (prop->is<Mesh::PropertyMeshKernel>()) {
104
        const Mesh::MeshObject* mesh =
105
            static_cast<const Mesh::PropertyMeshKernel*>(prop)->getValuePtr();
106

107
        bool direct = MeshRenderer::shouldRenderDirectly(mesh->countFacets() > this->triangleCount);
108
        if (direct) {
109
            this->pcMeshNode->mesh.setValue(mesh);
110
            // Needs to update internal bounding box caches
111
            this->pcMeshShape->touch();
112
            pcMeshCoord->point.setNum(0);
113
            pcMeshFaces->coordIndex.setNum(0);
114
        }
115
        else {
116
            ViewProviderMeshBuilder builder;
117
            builder.createMesh(prop, pcMeshCoord, pcMeshFaces);
118
            pcMeshFaces->invalidate();
119
        }
120

121
        if (direct != directRendering) {
122
            directRendering = direct;
123
            Gui::coinRemoveAllChildren(pcShapeGroup);
124

125
            if (directRendering) {
126
                pcShapeGroup->addChild(pcMeshNode);
127
                pcShapeGroup->addChild(pcMeshShape);
128
            }
129
            else {
130
                pcShapeGroup->addChild(pcMeshCoord);
131
                pcShapeGroup->addChild(pcMeshFaces);
132
            }
133
        }
134

135
        showOpenEdges(OpenEdges.getValue());
136
        std::vector<Mesh::FacetIndex> selection;
137
        mesh->getFacetsFromSelection(selection);
138
        if (selection.empty()) {
139
            unhighlightSelection();
140
        }
141
        else {
142
            highlightSelection();
143
        }
144
    }
145
}
146

147
void ViewProviderMeshFaceSet::showOpenEdges(bool show)
148
{
149
    if (pcOpenEdge) {
150
        // remove the node and destroy the data
151
        pcRoot->removeChild(pcOpenEdge);
152
        pcOpenEdge = nullptr;
153
    }
154

155
    if (show) {
156
        pcOpenEdge = new SoSeparator();
157
        pcOpenEdge->addChild(pcLineStyle);
158
        pcOpenEdge->addChild(pOpenColor);
159

160
        if (directRendering) {
161
            pcOpenEdge->addChild(pcMeshNode);
162
            pcOpenEdge->addChild(new SoFCMeshObjectBoundary);
163
        }
164
        else {
165
            pcOpenEdge->addChild(pcMeshCoord);
166
            SoIndexedLineSet* lines = new SoIndexedLineSet;
167
            pcOpenEdge->addChild(lines);
168

169
            // Build up the lines with indices to the list of vertices 'pcMeshCoord'
170
            int index = 0;
171
            const MeshCore::MeshKernel& rMesh =
172
                static_cast<Mesh::Feature*>(pcObject)->Mesh.getValue().getKernel();
173
            const MeshCore::MeshFacetArray& rFaces = rMesh.GetFacets();
174
            for (const auto& rFace : rFaces) {
175
                for (int i = 0; i < 3; i++) {
176
                    if (rFace._aulNeighbours[i] == MeshCore::FACET_INDEX_MAX) {
177
                        lines->coordIndex.set1Value(index++, rFace._aulPoints[i]);
178
                        lines->coordIndex.set1Value(index++, rFace._aulPoints[(i + 1) % 3]);
179
                        lines->coordIndex.set1Value(index++, SO_END_LINE_INDEX);
180
                    }
181
                }
182
            }
183
        }
184

185
        // add to the highlight node
186
        pcRoot->addChild(pcOpenEdge);
187
    }
188
}
189

190
SoShape* ViewProviderMeshFaceSet::getShapeNode() const
191
{
192
    if (directRendering) {
193
        return this->pcMeshShape;
194
    }
195
    return this->pcMeshFaces;
196
}
197

198
SoNode* ViewProviderMeshFaceSet::getCoordNode() const
199
{
200
    if (directRendering) {
201
        return this->pcMeshNode;
202
    }
203
    return this->pcMeshCoord;
204
}
205

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

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

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

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