comparison Framework/Scene2D/Scene2D.cpp @ 602:03c4b998fcd0

display scene positions in the basic sample
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 29 Apr 2019 14:40:01 +0200
parents 6129b1e5ba42
children d9c0a66304cb
comparison
equal deleted inserted replaced
600:6129b1e5ba42 602:03c4b998fcd0
24 #include <Core/OrthancException.h> 24 #include <Core/OrthancException.h>
25 25
26 26
27 namespace OrthancStone 27 namespace OrthancStone
28 { 28 {
29 class Scene2D::Item
30 {
31 private:
32 std::auto_ptr<ISceneLayer> layer_;
33 uint64_t identifier_;
34
35 public:
36 Item(ISceneLayer* layer,
37 uint64_t identifier) :
38 layer_(layer),
39 identifier_(identifier)
40 {
41 if (layer == NULL)
42 {
43 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
44 }
45 }
46
47 ISceneLayer& GetLayer() const
48 {
49 assert(layer_.get() != NULL);
50 return *layer_;
51 }
52
53 uint64_t GetIdentifier() const
54 {
55 return identifier_;
56 }
57 };
58
59
29 Scene2D::Scene2D(const Scene2D& other) : 60 Scene2D::Scene2D(const Scene2D& other) :
30 sceneToCanvas_(other.sceneToCanvas_), 61 sceneToCanvas_(other.sceneToCanvas_),
31 canvasToScene_(other.canvasToScene_) 62 canvasToScene_(other.canvasToScene_),
63 layerCounter_(0)
32 { 64 {
33 for (Content::const_iterator it = other.content_.begin(); 65 for (Content::const_iterator it = other.content_.begin();
34 it != other.content_.end(); ++it) 66 it != other.content_.end(); ++it)
35 { 67 {
36 content_[it->first] = it->second->Clone(); 68 content_[it->first] = new Item(it->second->GetLayer().Clone(), layerCounter_++);
37 } 69 }
38 } 70 }
39 71
40 72
41 Scene2D::~Scene2D() 73 Scene2D::~Scene2D()
50 82
51 83
52 void Scene2D::SetLayer(int depth, 84 void Scene2D::SetLayer(int depth,
53 ISceneLayer* layer) // Takes ownership 85 ISceneLayer* layer) // Takes ownership
54 { 86 {
55 std::auto_ptr<ISceneLayer> protection(layer); 87 std::auto_ptr<Item> item(new Item(layer, layerCounter_++));
56 88
57 if (layer == NULL) 89 if (layer == NULL)
58 { 90 {
59 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); 91 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
60 } 92 }
61 93
62 Content::iterator found = content_.find(depth); 94 Content::iterator found = content_.find(depth);
63 95
64 if (found == content_.end()) 96 if (found == content_.end())
65 { 97 {
66 content_[depth] = protection.release(); 98 content_[depth] = item.release();
67 } 99 }
68 else 100 else
69 { 101 {
70 assert(found->second != NULL); 102 assert(found->second != NULL);
71 delete found->second; 103 delete found->second;
72 found->second = protection.release(); 104 found->second = item.release();
73 } 105 }
74 } 106 }
75 107
76 108
77 void Scene2D::DeleteLayer(int depth) 109 void Scene2D::DeleteLayer(int depth)
85 content_.erase(found); 117 content_.erase(found);
86 } 118 }
87 } 119 }
88 120
89 121
122 bool Scene2D::HasLayer(int depth) const
123 {
124 return (content_.find(depth) != content_.end());
125 }
126
127
128 ISceneLayer& Scene2D::GetLayer(int depth) const
129 {
130 Content::const_iterator found = content_.find(depth);
131
132 if (found == content_.end())
133 {
134 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
135 }
136 else
137 {
138 assert(found->second != NULL);
139 return found->second->GetLayer();
140 }
141 }
142
143
90 void Scene2D::Apply(IVisitor& visitor) const 144 void Scene2D::Apply(IVisitor& visitor) const
91 { 145 {
92 for (Content::const_iterator it = content_.begin(); 146 for (Content::const_iterator it = content_.begin();
93 it != content_.end(); ++it) 147 it != content_.end(); ++it)
94 { 148 {
95 assert(it->second != NULL); 149 assert(it->second != NULL);
96 visitor.Visit(*it->second, it->first); 150 visitor.Visit(it->second->GetLayer(), it->second->GetIdentifier(), it->first);
97 } 151 }
98 } 152 }
99 153
100 154
101 void Scene2D::SetSceneToCanvasTransform(const AffineTransform2D& transform) 155 void Scene2D::SetSceneToCanvasTransform(const AffineTransform2D& transform)
117 it != content_.end(); ++it) 171 it != content_.end(); ++it)
118 { 172 {
119 assert(it->second != NULL); 173 assert(it->second != NULL);
120 174
121 Extent2D tmp; 175 Extent2D tmp;
122 if (it->second->GetBoundingBox(tmp)) 176 if (it->second->GetLayer().GetBoundingBox(tmp))
123 { 177 {
124 extent.Union(tmp); 178 extent.Union(tmp);
125 } 179 }
126 } 180 }
127 181