comparison Framework/Radiography/RadiographyScene.cpp @ 1199:922d2e61aa5d

RadiograpyScene: can now remove any layer + new key wrappers for Delete/Backspace
author Alain Mazy <alain@mazy.be>
date Thu, 28 Nov 2019 18:28:15 +0100
parents a5f2a6b04a31
children 54cbffabdc45 ab958fd99b07
comparison
equal deleted inserted replaced
1197:a34ba19d2060 1199:922d2e61aa5d
134 134
135 std::auto_ptr<RadiographyLayer> raii(layer); 135 std::auto_ptr<RadiographyLayer> raii(layer);
136 136
137 // LOG(INFO) << "Registering layer: " << countLayers_; 137 // LOG(INFO) << "Registering layer: " << countLayers_;
138 138
139 size_t index = countLayers_++; 139 size_t index = nextLayerIndex_++;
140 raii->SetIndex(index); 140 raii->SetIndex(index);
141 layers_[index] = raii.release(); 141 layers_[index] = raii.release();
142 142
143 BroadcastMessage(GeometryChangedMessage(*this, *layer)); 143 BroadcastMessage(GeometryChangedMessage(*this, *layer));
144 BroadcastMessage(ContentChangedMessage(*this, *layer)); 144 BroadcastMessage(ContentChangedMessage(*this, *layer));
163 } 163 }
164 164
165 RadiographyScene::RadiographyScene(MessageBroker& broker) : 165 RadiographyScene::RadiographyScene(MessageBroker& broker) :
166 IObserver(broker), 166 IObserver(broker),
167 IObservable(broker), 167 IObservable(broker),
168 countLayers_(0), 168 nextLayerIndex_(0),
169 hasWindowing_(false), 169 hasWindowing_(false),
170 windowingCenter_(0), // Dummy initialization 170 windowingCenter_(0), // Dummy initialization
171 windowingWidth_(0) // Dummy initialization 171 windowingWidth_(0) // Dummy initialization
172 { 172 {
173 } 173 }
219 { 219 {
220 assert(found->second != NULL); 220 assert(found->second != NULL);
221 delete found->second; 221 delete found->second;
222 222
223 layers_.erase(found); 223 layers_.erase(found);
224 countLayers_--;
225 224
226 LOG(INFO) << "Removing layer, there are now : " << countLayers_ << " layers"; 225 LOG(INFO) << "Removing layer, there are now : " << layers_.size() << " layers";
227 226
228 BroadcastMessage(RadiographyScene::LayerRemovedMessage(*this, layerIndex)); 227 BroadcastMessage(RadiographyScene::LayerRemovedMessage(*this, layerIndex));
229 } 228 }
230 } 229 }
231 230
292 if (geometry != NULL) 291 if (geometry != NULL)
293 { 292 {
294 alpha->SetGeometry(*geometry); 293 alpha->SetGeometry(*geometry);
295 } 294 }
296 295
297 return RegisterLayer(alpha.release()); 296 RadiographyLayer& registeredLayer = RegisterLayer(alpha.release());
297
298 BroadcastMessage(RadiographyScene::LayerEditedMessage(*this, registeredLayer));
299 return registeredLayer;
298 } 300 }
299 301
300 302
301 RadiographyLayer& RadiographyScene::LoadTestBlock(unsigned int width, 303 RadiographyLayer& RadiographyScene::LoadTestBlock(unsigned int width,
302 unsigned int height, 304 unsigned int height,
511 const AffineTransform2D& viewTransform, 513 const AffineTransform2D& viewTransform,
512 ImageInterpolation interpolation, 514 ImageInterpolation interpolation,
513 bool applyWindowing) const 515 bool applyWindowing) const
514 { 516 {
515 // Render layers in the background-to-foreground order 517 // Render layers in the background-to-foreground order
516 for (size_t index = 0; index < countLayers_; index++) 518 for (size_t index = 0; index < nextLayerIndex_; index++)
517 { 519 {
518 Layers::const_iterator it = layers_.find(index); 520 Layers::const_iterator it = layers_.find(index);
519 if (it != layers_.end()) 521 if (it != layers_.end())
520 { 522 {
521 assert(it->second != NULL); 523 assert(it->second != NULL);
528 bool RadiographyScene::LookupLayer(size_t& index /* out */, 530 bool RadiographyScene::LookupLayer(size_t& index /* out */,
529 double x, 531 double x,
530 double y) const 532 double y) const
531 { 533 {
532 // Render layers in the foreground-to-background order 534 // Render layers in the foreground-to-background order
533 for (size_t i = countLayers_; i > 0; i--) 535 for (size_t i = nextLayerIndex_; i > 0; i--)
534 { 536 {
535 index = i - 1; 537 index = i - 1;
536 Layers::const_iterator it = layers_.find(index); 538 Layers::const_iterator it = layers_.find(index);
537 if (it != layers_.end()) 539 if (it != layers_.end())
538 { 540 {