FreeCAD

Форк
0
/
ViewProviderTransformDemolding.cpp 
196 строк · 7.0 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2004 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 <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>
34
#endif
35

36
#include <Base/Console.h>
37
#include <Gui/SoFCSelection.h>
38

39
#include <Mod/Mesh/App/Core/Iterator.h>
40
#include <Mod/Mesh/App/MeshFeature.h>
41

42
#include "ViewProviderTransformDemolding.h"
43

44

45
using Mesh::Feature;
46
using MeshCore::MeshFacetIterator;
47
using MeshCore::MeshGeomFacet;
48
using MeshCore::MeshKernel;
49
using namespace MeshGui;
50

51

52
PROPERTY_SOURCE(MeshGui::ViewProviderMeshTransformDemolding, MeshGui::ViewProviderMesh)
53

54

55
ViewProviderMeshTransformDemolding::ViewProviderMeshTransformDemolding()
56
{
57
    // NOLINTBEGIN
58
    pcTrackballDragger = new SoTrackballDragger;
59
    pcTrackballDragger->ref();
60
    pcTransformDrag = nullptr;
61
    pcColorMat = nullptr;
62
    // NOLINTEND
63
}
64

65
ViewProviderMeshTransformDemolding::~ViewProviderMeshTransformDemolding()
66
{
67
    pcTrackballDragger->unref();
68
}
69

70
void ViewProviderMeshTransformDemolding::attach(App::DocumentObject* pcFeat)
71
{
72
    // creates the standard viewing modes
73
    ViewProviderMesh::attach(pcFeat);
74

75
    SoGroup* pcDemoldRoot = new SoGroup();
76

77
    SoDrawStyle* pcFlatStyle = new SoDrawStyle();
78
    pcFlatStyle->style = SoDrawStyle::FILLED;
79
    pcDemoldRoot->addChild(pcFlatStyle);
80

81
    // dragger
82
    SoSeparator* surroundsep = new SoSeparator;
83

84
    SoSurroundScale* ss = new SoSurroundScale;
85
    ss->numNodesUpToReset = 1;
86
    ss->numNodesUpToContainer = 2;
87
    surroundsep->addChild(ss);
88

89
    SoAntiSquish* antisquish = new SoAntiSquish;
90
    antisquish->sizing = SoAntiSquish::AVERAGE_DIMENSION;
91
    surroundsep->addChild(antisquish);
92

93
    pcTrackballDragger->addValueChangedCallback(sValueChangedCallback, this);
94
    pcTrackballDragger->addFinishCallback(sDragEndCallback, this);
95
    surroundsep->addChild(pcTrackballDragger);
96

97
    pcTransformDrag = new SoTransform();
98

99

100
    SoMaterialBinding* pcMatBinding = new SoMaterialBinding;
101

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);
107

108
    pcDemoldRoot->addChild(surroundsep);
109
    pcDemoldRoot->addChild(pcTransformDrag);
110
    pcDemoldRoot->addChild(pcColorMat);
111
    pcDemoldRoot->addChild(pcMatBinding);
112
    pcDemoldRoot->addChild(pcHighlight);
113

114
    // adding to the switch
115
    addDisplayMaskMode(pcDemoldRoot, "Demold");
116

117
    calcNormalVector();
118
    calcMaterialIndex(SbRotation());
119
    // getting center point
120
    center = static_cast<Feature*>(pcObject)->Mesh.getValue().getKernel().GetBoundBox().GetCenter();
121
}
122

123
void ViewProviderMeshTransformDemolding::calcNormalVector()
124
{
125
    const MeshKernel& cMesh = static_cast<Feature*>(pcObject)->Mesh.getValue().getKernel();
126

127
    MeshFacetIterator cFIt(cMesh);
128
    for (cFIt.Init(); cFIt.More(); cFIt.Next()) {
129
        const MeshGeomFacet& rFace = *cFIt;
130

131
        Base::Vector3f norm(rFace.GetNormal());
132
        normalVector.emplace_back(norm.x, norm.y, norm.z);
133
    }
134
}
135

136
void ViewProviderMeshTransformDemolding::calcMaterialIndex(const SbRotation& rot)
137
{
138
    SbVec3f Up(0, 0, 1);
139
    SbVec3f result;
140

141
    int i = 0;
142
    for (auto it = normalVector.begin(); it != normalVector.end(); ++it, i++) {
143
        rot.multVec(*it, result);
144
    }
145
}
146

147
void ViewProviderMeshTransformDemolding::sValueChangedCallback(void* This, SoDragger*)
148
{
149
    static_cast<ViewProviderMeshTransformDemolding*>(This)->valueChangedCallback();
150
}
151

152
void ViewProviderMeshTransformDemolding::sDragEndCallback(void* This, SoDragger*)
153
{
154
    static_cast<ViewProviderMeshTransformDemolding*>(This)->DragEndCallback();
155
}
156

157
void ViewProviderMeshTransformDemolding::DragEndCallback()
158
{
159
    SbRotation rot = pcTrackballDragger->rotation.getValue();
160
    calcMaterialIndex(rot);
161

162
    Base::Console().Log("View: Finish dragging\n");
163
}
164

165
void ViewProviderMeshTransformDemolding::valueChangedCallback()
166
{
167
    SbMatrix temp;
168
    SbRotation rot = pcTrackballDragger->rotation.getValue();
169

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);
176
}
177

178
void ViewProviderMeshTransformDemolding::setDisplayMode(const char* ModeName)
179
{
180
    if (strcmp("Demold", ModeName) == 0) {
181
        setDisplayMaskMode("Demold");
182
    }
183
    ViewProviderMesh::setDisplayMode(ModeName);
184
}
185

186
const char* ViewProviderMeshTransformDemolding::getDefaultDisplayMode() const
187
{
188
    return "Demold";
189
}
190

191
std::vector<std::string> ViewProviderMeshTransformDemolding::getDisplayModes() const
192
{
193
    std::vector<std::string> StrList = ViewProviderMesh::getDisplayModes();
194
    StrList.emplace_back("Demold");
195
    return StrList;
196
}
197

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

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

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

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