Repository navigation
Expand file tree
/
Copy pathOccSceneManager.cpp
More file actions
169 lines (144 loc) · 3.48 KB
/
Copy pathOccSceneManager.cpp
File metadata and controls
169 lines (144 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include "OccSceneManager.h"
#include <iostream>
#include <AIS_Shape.hxx>
#include <AIS_ViewCube.hxx>
#include <Graphic3d_TransformPers.hxx>
#include <Message.hxx>
#include <Quantity_Color.hxx>
#include <V3d_View.hxx>
namespace geotoys
{
OccSceneManager::OccSceneManager(QObject *parent)
: QObject(parent)
, viewcube_visible_(true)
{
}
OccSceneManager::~OccSceneManager()
{
clearAllShapes();
}
void OccSceneManager::setContext(const Handle(AIS_InteractiveContext) & context)
{
context_ = context;
}
void OccSceneManager::setView(const Handle(V3d_View) & view)
{
view_ = view;
}
bool OccSceneManager::addShape(const std::string &id, const TopoDS_Shape &shape,
const Quantity_Color &color, bool display)
{
if (context_.IsNull())
{
std::cerr << "Context is null, cannot add shape:" << id << std::endl;
return false;
}
auto it = shapes_.find(id);
if (it != shapes_.end())
{
removeShape(id);
}
Handle(AIS_Shape) aisShape = new AIS_Shape(shape);
aisShape->SetColor(color);
shapes_[id] = aisShape;
if (display)
{
context_->Display(aisShape, AIS_Shaded, 0, false);
}
view_->Invalidate();
view_->InvalidateImmediate();
std::cout << "Added shape:" << id << std::endl;
return true;
}
bool OccSceneManager::removeShape(const std::string &id)
{
auto it = shapes_.find(id);
if (it == shapes_.end())
{
return false;
}
Handle(AIS_Shape) shape = it->second;
if (!context_.IsNull() && !shape.IsNull())
{
context_->Erase(shape, false);
context_->Remove(shape, false);
if (!view_.IsNull())
{
view_->Invalidate();
view_->InvalidateImmediate();
}
}
shapes_.erase(it);
std::cout << "Removed shape:" << id << std::endl;
return true;
}
bool OccSceneManager::updateShape(const std::string &id,
const TopoDS_Shape &shape)
{
auto it = shapes_.find(id);
if (it == shapes_.end())
{
return addShape(id, shape, Quantity_NOC_YELLOW, true);
}
Handle(AIS_Shape) aisShape = it->second;
if (!aisShape.IsNull())
{
aisShape->SetShape(shape);
context_->Redisplay(aisShape, false);
return true;
}
return false;
}
bool OccSceneManager::setShapeColor(const std::string &id,
const Quantity_Color &color)
{
auto it = shapes_.find(id);
if (it == shapes_.end())
{
return false;
}
Handle(AIS_Shape) shape = it->second;
if (!shape.IsNull())
{
shape->SetColor(color);
if (!context_.IsNull())
{
context_->Update(shape, false);
}
return true;
}
return false;
}
Handle(AIS_Shape) OccSceneManager::getShape(const std::string &id) const
{
auto it = shapes_.find(id);
if (it != shapes_.end())
{
return it->second;
}
return Handle(AIS_Shape)();
}
std::vector<std::string> OccSceneManager::getAllShapeIds() const
{
std::vector<std::string> ids;
ids.reserve(shapes_.size());
for (const auto &pair : shapes_)
{
ids.push_back(pair.first);
}
return ids;
}
void OccSceneManager::clearAllShapes()
{
if (!context_.IsNull())
{
context_->RemoveAll(false);
// 强制更新视图
if (!view_.IsNull())
{
view_->InvalidateImmediate();
}
}
shapes_.clear();
}
} // namespace geotoys