1
/***************************************************************************
2
* Copyright (c) 2006 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"
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>
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>
42
#include "ViewProviderMeshFaceSet.h"
43
#include "SoFCIndexedFaceSet.h"
44
#include "SoFCMeshObject.h"
47
using namespace MeshGui;
49
PROPERTY_SOURCE(MeshGui::ViewProviderMeshFaceSet, MeshGui::ViewProviderMesh)
51
ViewProviderMeshFaceSet::ViewProviderMeshFaceSet()
54
directRendering = false;
55
triangleCount = 2500000;
57
pcMeshNode = new SoFCMeshObjectNode;
59
pcMeshShape = new SoFCMeshObjectShape;
61
pcMeshCoord = new SoCoordinate3;
63
pcMeshFaces = new SoFCIndexedFaceSet;
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);
74
ViewProviderMeshFaceSet::~ViewProviderMeshFaceSet()
82
void ViewProviderMeshFaceSet::attach(App::DocumentObject* pcFeat)
84
ViewProviderMesh::attach(pcFeat);
86
pcShapeGroup->addChild(pcMeshCoord);
87
pcShapeGroup->addChild(pcMeshFaces);
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);
94
pcMeshShape->renderTriangleLimit = (unsigned int)(pow(10.0F, size));
95
static_cast<SoFCIndexedFaceSet*>(pcMeshFaces)->renderTriangleLimit =
96
(unsigned int)(pow(10.0F, size));
100
void ViewProviderMeshFaceSet::updateData(const App::Property* prop)
102
ViewProviderMesh::updateData(prop);
103
if (prop->is<Mesh::PropertyMeshKernel>()) {
104
const Mesh::MeshObject* mesh =
105
static_cast<const Mesh::PropertyMeshKernel*>(prop)->getValuePtr();
107
bool direct = MeshRenderer::shouldRenderDirectly(mesh->countFacets() > this->triangleCount);
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);
116
ViewProviderMeshBuilder builder;
117
builder.createMesh(prop, pcMeshCoord, pcMeshFaces);
118
pcMeshFaces->invalidate();
121
if (direct != directRendering) {
122
directRendering = direct;
123
Gui::coinRemoveAllChildren(pcShapeGroup);
125
if (directRendering) {
126
pcShapeGroup->addChild(pcMeshNode);
127
pcShapeGroup->addChild(pcMeshShape);
130
pcShapeGroup->addChild(pcMeshCoord);
131
pcShapeGroup->addChild(pcMeshFaces);
135
showOpenEdges(OpenEdges.getValue());
136
std::vector<Mesh::FacetIndex> selection;
137
mesh->getFacetsFromSelection(selection);
138
if (selection.empty()) {
139
unhighlightSelection();
142
highlightSelection();
147
void ViewProviderMeshFaceSet::showOpenEdges(bool show)
150
// remove the node and destroy the data
151
pcRoot->removeChild(pcOpenEdge);
152
pcOpenEdge = nullptr;
156
pcOpenEdge = new SoSeparator();
157
pcOpenEdge->addChild(pcLineStyle);
158
pcOpenEdge->addChild(pOpenColor);
160
if (directRendering) {
161
pcOpenEdge->addChild(pcMeshNode);
162
pcOpenEdge->addChild(new SoFCMeshObjectBoundary);
165
pcOpenEdge->addChild(pcMeshCoord);
166
SoIndexedLineSet* lines = new SoIndexedLineSet;
167
pcOpenEdge->addChild(lines);
169
// Build up the lines with indices to the list of vertices 'pcMeshCoord'
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);
185
// add to the highlight node
186
pcRoot->addChild(pcOpenEdge);
190
SoShape* ViewProviderMeshFaceSet::getShapeNode() const
192
if (directRendering) {
193
return this->pcMeshShape;
195
return this->pcMeshFaces;
198
SoNode* ViewProviderMeshFaceSet::getCoordNode() const
200
if (directRendering) {
201
return this->pcMeshNode;
203
return this->pcMeshCoord;