Line |
Branch |
Exec |
Source |
1 |
|
|
// Copyright (c) 2019, Joseph Mirabel |
2 |
|
|
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr) |
3 |
|
|
// |
4 |
|
|
// This file is part of gepetto-viewer. |
5 |
|
|
// gepetto-viewer is free software: you can redistribute it |
6 |
|
|
// and/or modify it under the terms of the GNU Lesser General Public |
7 |
|
|
// License as published by the Free Software Foundation, either version |
8 |
|
|
// 3 of the License, or (at your option) any later version. |
9 |
|
|
// |
10 |
|
|
// gepetto-viewer is distributed in the hope that it will be |
11 |
|
|
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty |
12 |
|
|
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 |
|
|
// General Lesser Public License for more details. You should have |
14 |
|
|
// received a copy of the GNU Lesser General Public License along with |
15 |
|
|
// gepetto-viewer. If not, see <http://www.gnu.org/licenses/>. |
16 |
|
|
|
17 |
|
|
#include <gepetto/viewer/node-visitor.h> |
18 |
|
|
#include <gepetto/viewer/node.h> |
19 |
|
|
|
20 |
|
|
namespace gepetto { |
21 |
|
|
namespace viewer { |
22 |
|
|
class IsDirtyVisitor : public NodeVisitor { |
23 |
|
|
public: |
24 |
|
✗ |
IsDirtyVisitor() : NodeVisitor(true), isDirty_(false) {} |
25 |
|
|
|
26 |
|
✗ |
~IsDirtyVisitor() {} |
27 |
|
|
|
28 |
|
✗ |
bool valid(Node& node) { |
29 |
|
✗ |
if (isDirty_) return false; |
30 |
|
✗ |
return NodeVisitor::valid(node); |
31 |
|
|
} |
32 |
|
|
|
33 |
|
✗ |
void apply(Node& node) { |
34 |
|
✗ |
isDirty_ = node.isDirty(); |
35 |
|
✗ |
if (isDirty_) return; |
36 |
|
|
// Invisible nodes must be considered, otherwise they do not |
37 |
|
|
// disappear when they become invisible. Their children can be discarded. |
38 |
|
✗ |
if (node.getVisibilityMode() == VISIBILITY_OFF) return; |
39 |
|
✗ |
NodeVisitor::apply(node); |
40 |
|
|
} |
41 |
|
|
|
42 |
|
✗ |
bool isDirty() const { return isDirty_; } |
43 |
|
|
|
44 |
|
|
protected: |
45 |
|
|
bool isDirty_; |
46 |
|
|
}; /* class Node */ |
47 |
|
|
template <bool SetDirty> |
48 |
|
|
class SetDirtyVisitorTpl : public NodeVisitor { |
49 |
|
|
public: |
50 |
|
✗ |
SetDirtyVisitorTpl() : NodeVisitor(true) {} |
51 |
|
|
|
52 |
|
✗ |
~SetDirtyVisitorTpl() {} |
53 |
|
|
|
54 |
|
✗ |
void apply(Node& node) { |
55 |
|
✗ |
node.setDirty(SetDirty); |
56 |
|
✗ |
NodeVisitor::apply(node); |
57 |
|
|
} |
58 |
|
|
}; /* class Node */ |
59 |
|
|
typedef SetDirtyVisitorTpl<true> SetDirtyVisitor; |
60 |
|
|
typedef SetDirtyVisitorTpl<false> SetCleanVisitor; |
61 |
|
|
} /* namespace viewer */ |
62 |
|
|
} // namespace gepetto |
63 |
|
|
|