1
/***************************************************************************
2
* Copyright (c) 2004 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"
25
#include <Inventor/draggers/SoTrackballDragger.h>
26
#include <Inventor/manips/SoTransformerManip.h>
27
#include <Inventor/nodes/SoAntiSquish.h>
28
#include <Inventor/nodes/SoDrawStyle.h>
29
#include <Inventor/nodes/SoIndexedFaceSet.h>
30
#include <Inventor/nodes/SoMaterial.h>
31
#include <Inventor/nodes/SoMaterialBinding.h>
32
#include <Inventor/nodes/SoSeparator.h>
33
#include <Inventor/nodes/SoSurroundScale.h>
36
#include <Base/Console.h>
37
#include <Gui/SoFCSelection.h>
39
#include <Mod/Mesh/App/Core/Iterator.h>
40
#include <Mod/Mesh/App/MeshFeature.h>
42
#include "ViewProviderTransformDemolding.h"
46
using MeshCore::MeshFacetIterator;
47
using MeshCore::MeshGeomFacet;
48
using MeshCore::MeshKernel;
49
using namespace MeshGui;
52
PROPERTY_SOURCE(MeshGui::ViewProviderMeshTransformDemolding, MeshGui::ViewProviderMesh)
55
ViewProviderMeshTransformDemolding::ViewProviderMeshTransformDemolding()
58
pcTrackballDragger = new SoTrackballDragger;
59
pcTrackballDragger->ref();
60
pcTransformDrag = nullptr;
65
ViewProviderMeshTransformDemolding::~ViewProviderMeshTransformDemolding()
67
pcTrackballDragger->unref();
70
void ViewProviderMeshTransformDemolding::attach(App::DocumentObject* pcFeat)
72
// creates the standard viewing modes
73
ViewProviderMesh::attach(pcFeat);
75
SoGroup* pcDemoldRoot = new SoGroup();
77
SoDrawStyle* pcFlatStyle = new SoDrawStyle();
78
pcFlatStyle->style = SoDrawStyle::FILLED;
79
pcDemoldRoot->addChild(pcFlatStyle);
82
SoSeparator* surroundsep = new SoSeparator;
84
SoSurroundScale* ss = new SoSurroundScale;
85
ss->numNodesUpToReset = 1;
86
ss->numNodesUpToContainer = 2;
87
surroundsep->addChild(ss);
89
SoAntiSquish* antisquish = new SoAntiSquish;
90
antisquish->sizing = SoAntiSquish::AVERAGE_DIMENSION;
91
surroundsep->addChild(antisquish);
93
pcTrackballDragger->addValueChangedCallback(sValueChangedCallback, this);
94
pcTrackballDragger->addFinishCallback(sDragEndCallback, this);
95
surroundsep->addChild(pcTrackballDragger);
97
pcTransformDrag = new SoTransform();
100
SoMaterialBinding* pcMatBinding = new SoMaterialBinding;
102
pcMatBinding->value = SoMaterialBinding::PER_FACE_INDEXED;
103
pcColorMat = new SoMaterial;
104
pcColorMat->diffuseColor.set1Value(0, 1, 1, 0);
105
pcColorMat->diffuseColor.set1Value(1, 1, 0, 0);
106
pcColorMat->diffuseColor.set1Value(2, 0, 1, 0);
108
pcDemoldRoot->addChild(surroundsep);
109
pcDemoldRoot->addChild(pcTransformDrag);
110
pcDemoldRoot->addChild(pcColorMat);
111
pcDemoldRoot->addChild(pcMatBinding);
112
pcDemoldRoot->addChild(pcHighlight);
114
// adding to the switch
115
addDisplayMaskMode(pcDemoldRoot, "Demold");
118
calcMaterialIndex(SbRotation());
119
// getting center point
120
center = static_cast<Feature*>(pcObject)->Mesh.getValue().getKernel().GetBoundBox().GetCenter();
123
void ViewProviderMeshTransformDemolding::calcNormalVector()
125
const MeshKernel& cMesh = static_cast<Feature*>(pcObject)->Mesh.getValue().getKernel();
127
MeshFacetIterator cFIt(cMesh);
128
for (cFIt.Init(); cFIt.More(); cFIt.Next()) {
129
const MeshGeomFacet& rFace = *cFIt;
131
Base::Vector3f norm(rFace.GetNormal());
132
normalVector.emplace_back(norm.x, norm.y, norm.z);
136
void ViewProviderMeshTransformDemolding::calcMaterialIndex(const SbRotation& rot)
142
for (auto it = normalVector.begin(); it != normalVector.end(); ++it, i++) {
143
rot.multVec(*it, result);
147
void ViewProviderMeshTransformDemolding::sValueChangedCallback(void* This, SoDragger*)
149
static_cast<ViewProviderMeshTransformDemolding*>(This)->valueChangedCallback();
152
void ViewProviderMeshTransformDemolding::sDragEndCallback(void* This, SoDragger*)
154
static_cast<ViewProviderMeshTransformDemolding*>(This)->DragEndCallback();
157
void ViewProviderMeshTransformDemolding::DragEndCallback()
159
SbRotation rot = pcTrackballDragger->rotation.getValue();
160
calcMaterialIndex(rot);
162
Base::Console().Log("View: Finish dragging\n");
165
void ViewProviderMeshTransformDemolding::valueChangedCallback()
168
SbRotation rot = pcTrackballDragger->rotation.getValue();
170
temp.setTransform(SbVec3f(0, 0, 0), // no transformation
171
rot, // rotation from the dragger
172
SbVec3f(1, 1, 1), // no scaling
173
SbRotation(), // no scaling orientation
174
SbVec3f(center.x, center.y, center.z)); // center of rotation
175
pcTransformDrag->setMatrix(temp);
178
void ViewProviderMeshTransformDemolding::setDisplayMode(const char* ModeName)
180
if (strcmp("Demold", ModeName) == 0) {
181
setDisplayMaskMode("Demold");
183
ViewProviderMesh::setDisplayMode(ModeName);
186
const char* ViewProviderMeshTransformDemolding::getDefaultDisplayMode() const
191
std::vector<std::string> ViewProviderMeshTransformDemolding::getDisplayModes() const
193
std::vector<std::string> StrList = ViewProviderMesh::getDisplayModes();
194
StrList.emplace_back("Demold");