Mercurial > hg > orthanc-stone
comparison Framework/Widgets/LayerWidget.cpp @ 251:192e6e349e69 am-2
first usage of new message system (in SDL only)
author | am@osimis.io |
---|---|
date | Mon, 02 Jul 2018 18:13:46 +0200 |
parents | 26e3bfe30e66 |
children | 40b21c1f8b8d |
comparison
equal
deleted
inserted
replaced
250:5e642859267e | 251:192e6e349e69 |
---|---|
11 * | 11 * |
12 * This program is distributed in the hope that it will be useful, but | 12 * This program is distributed in the hope that it will be useful, but |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Affero General Public License for more details. | 15 * Affero General Public License for more details. |
16 * | 16 * |
17 * You should have received a copy of the GNU Affero General Public License | 17 * You should have received a copy of the GNU Affero General Public License |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | 19 **/ |
20 | 20 |
21 | 21 |
53 delete renderers_[index]; | 53 delete renderers_[index]; |
54 renderers_[index] = NULL; | 54 renderers_[index] = NULL; |
55 countMissing_++; | 55 countMissing_++; |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 public: | 59 public: |
60 Scene(const CoordinateSystem3D& slice, | 60 Scene(const CoordinateSystem3D& slice, |
61 double thickness, | 61 double thickness, |
62 size_t countLayers) : | 62 size_t countLayers) : |
63 slice_(slice), | 63 slice_(slice), |
182 // TODO Drawing circles makes WebAssembly crash! | 182 // TODO Drawing circles makes WebAssembly crash! |
183 cairo_arc(cr, 0, 0, 5.0 / view.GetZoom(), 0, 2 * M_PI); | 183 cairo_arc(cr, 0, 0, 5.0 / view.GetZoom(), 0, 2 * M_PI); |
184 #endif | 184 #endif |
185 | 185 |
186 cairo_set_line_width(cr, 2.0 / view.GetZoom()); | 186 cairo_set_line_width(cr, 2.0 / view.GetZoom()); |
187 cairo_set_source_rgb(cr, 1, 1, 1); | 187 cairo_set_source_rgb(cr, 1, 1, 1); |
188 cairo_stroke_preserve(cr); | 188 cairo_stroke_preserve(cr); |
189 cairo_set_source_rgb(cr, 1, 0, 0); | 189 cairo_set_source_rgb(cr, 1, 0, 0); |
190 cairo_fill(cr); | 190 cairo_fill(cr); |
191 } | 191 } |
192 | 192 |
213 } | 213 } |
214 else | 214 else |
215 { | 215 { |
216 double z = (slice_.ProjectAlongNormal(slice.GetOrigin()) - | 216 double z = (slice_.ProjectAlongNormal(slice.GetOrigin()) - |
217 slice_.ProjectAlongNormal(slice_.GetOrigin())); | 217 slice_.ProjectAlongNormal(slice_.GetOrigin())); |
218 | 218 |
219 if (z < 0) | 219 if (z < 0) |
220 { | 220 { |
221 z = -z; | 221 z = -z; |
222 } | 222 } |
223 | 223 |
247 assert(index < layers_.size() && | 247 assert(index < layers_.size() && |
248 layers_[index] == &layer); | 248 layers_[index] == &layer); |
249 return true; | 249 return true; |
250 } | 250 } |
251 } | 251 } |
252 | 252 |
253 | 253 |
254 void LayerWidget::GetLayerExtent(Extent2D& extent, | 254 void LayerWidget::GetLayerExtent(Extent2D& extent, |
255 ILayerSource& source) const | 255 ILayerSource& source) const |
256 { | 256 { |
257 extent.Reset(); | 257 extent.Reset(); |
266 extent.AddPoint(x, y); | 266 extent.AddPoint(x, y); |
267 } | 267 } |
268 } | 268 } |
269 } | 269 } |
270 | 270 |
271 | 271 |
272 Extent2D LayerWidget::GetSceneExtent() | 272 Extent2D LayerWidget::GetSceneExtent() |
273 { | 273 { |
274 Extent2D sceneExtent; | 274 Extent2D sceneExtent; |
275 | 275 |
276 for (size_t i = 0; i < layers_.size(); i++) | 276 for (size_t i = 0; i < layers_.size(); i++) |
357 } | 357 } |
358 } | 358 } |
359 } | 359 } |
360 | 360 |
361 | 361 |
362 LayerWidget::LayerWidget() : | 362 LayerWidget::LayerWidget(MessageBroker& broker) : |
363 IObserver(broker), | |
363 started_(false) | 364 started_(false) |
364 { | 365 { |
365 SetBackgroundCleared(true); | 366 SetBackgroundCleared(true); |
366 } | 367 } |
367 | 368 |
386 layers_.push_back(layer); | 387 layers_.push_back(layer); |
387 styles_.push_back(RenderStyle()); | 388 styles_.push_back(RenderStyle()); |
388 layersIndex_[layer] = index; | 389 layersIndex_[layer] = index; |
389 | 390 |
390 ResetPendingScene(); | 391 ResetPendingScene(); |
391 layer->Register(*this); | 392 layer->RegisterObserver(*this); |
392 | 393 |
393 ResetChangedLayers(); | 394 ResetChangedLayers(); |
394 | 395 |
395 return index; | 396 return index; |
396 } | 397 } |
410 delete layers_[index]; | 411 delete layers_[index]; |
411 layers_[index] = layer; | 412 layers_[index] = layer; |
412 layersIndex_[layer] = index; | 413 layersIndex_[layer] = index; |
413 | 414 |
414 ResetPendingScene(); | 415 ResetPendingScene(); |
415 layer->Register(*this); | 416 layer->RegisterObserver(*this); |
416 | 417 |
417 InvalidateLayer(index); | 418 InvalidateLayer(index); |
418 } | 419 } |
419 | 420 |
420 | 421 |
477 | 478 |
478 InvalidateAllLayers(); // TODO Removing this line avoid loading twice the image in WASM | 479 InvalidateAllLayers(); // TODO Removing this line avoid loading twice the image in WASM |
479 } | 480 } |
480 } | 481 } |
481 | 482 |
482 | 483 void LayerWidget::HandleMessage(IObservable& from, const IMessage& message) |
483 void LayerWidget::NotifyGeometryReady(const ILayerSource& source) | 484 { |
485 switch (message.GetType()) { | |
486 case MessageType_GeometryReady: | |
487 OnGeometryReady(dynamic_cast<ILayerSource&>(from)); | |
488 break; | |
489 case MessageType_GeometryError: | |
490 LOG(ERROR) << "Cannot get geometry"; | |
491 break; | |
492 case MessageType_ContentChanged: | |
493 OnContentChanged(dynamic_cast<ILayerSource&>(from)); | |
494 break; | |
495 case MessageType_SliceChanged: | |
496 OnSliceChanged(dynamic_cast<ILayerSource&>(from), dynamic_cast<const ILayerSource::SliceChangedMessage&>(message).slice); | |
497 break; | |
498 case MessageType_LayerReady: | |
499 { | |
500 const ILayerSource::LayerReadyMessage& layerReadyMessage = dynamic_cast<const ILayerSource::LayerReadyMessage&>(message); | |
501 OnLayerReady(layerReadyMessage.layer, | |
502 dynamic_cast<ILayerSource&>(from), | |
503 layerReadyMessage.slice, | |
504 layerReadyMessage.isError); | |
505 }; break; | |
506 default: | |
507 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
508 } | |
509 } | |
510 | |
511 void LayerWidget::OnGeometryReady(const ILayerSource& source) | |
484 { | 512 { |
485 size_t i; | 513 size_t i; |
486 if (LookupLayer(i, source)) | 514 if (LookupLayer(i, source)) |
487 { | 515 { |
488 LOG(INFO) << "Geometry ready for layer " << i; | 516 LOG(INFO) << "Geometry ready for layer " << i; |
490 changedLayers_[i] = true; | 518 changedLayers_[i] = true; |
491 //layers_[i]->ScheduleLayerCreation(slice_); | 519 //layers_[i]->ScheduleLayerCreation(slice_); |
492 } | 520 } |
493 } | 521 } |
494 | 522 |
495 | |
496 void LayerWidget::NotifyGeometryError(const ILayerSource& source) | |
497 { | |
498 LOG(ERROR) << "Cannot get geometry"; | |
499 } | |
500 | |
501 | |
502 void LayerWidget::InvalidateAllLayers() | 523 void LayerWidget::InvalidateAllLayers() |
503 { | 524 { |
504 for (size_t i = 0; i < layers_.size(); i++) | 525 for (size_t i = 0; i < layers_.size(); i++) |
505 { | 526 { |
506 assert(layers_[i] != NULL); | 527 assert(layers_[i] != NULL); |
523 | 544 |
524 //layers_[layer]->ScheduleLayerCreation(slice_); | 545 //layers_[layer]->ScheduleLayerCreation(slice_); |
525 } | 546 } |
526 | 547 |
527 | 548 |
528 void LayerWidget::NotifyContentChange(const ILayerSource& source) | 549 void LayerWidget::OnContentChanged(const ILayerSource& source) |
529 { | 550 { |
530 size_t index; | 551 size_t index; |
531 if (LookupLayer(index, source)) | 552 if (LookupLayer(index, source)) |
532 { | 553 { |
533 InvalidateLayer(index); | 554 InvalidateLayer(index); |
534 } | 555 } |
535 } | 556 } |
536 | 557 |
537 | 558 |
538 void LayerWidget::NotifySliceChange(const ILayerSource& source, | 559 void LayerWidget::OnSliceChanged(const ILayerSource& source, |
539 const Slice& slice) | 560 const Slice& slice) |
540 { | 561 { |
541 if (slice.ContainsPlane(slice_)) | 562 if (slice.ContainsPlane(slice_)) |
542 { | 563 { |
543 size_t index; | 564 size_t index; |
544 if (LookupLayer(index, source)) | 565 if (LookupLayer(index, source)) |
547 } | 568 } |
548 } | 569 } |
549 } | 570 } |
550 | 571 |
551 | 572 |
552 void LayerWidget::NotifyLayerReady(std::auto_ptr<ILayerRenderer>& renderer, | 573 void LayerWidget::OnLayerReady(std::auto_ptr<ILayerRenderer>& renderer, |
553 const ILayerSource& source, | 574 const ILayerSource& source, |
554 const CoordinateSystem3D& slice, | 575 const CoordinateSystem3D& slice, |
555 bool isError) | 576 bool isError) |
556 { | 577 { |
557 size_t index; | 578 size_t index; |
558 if (LookupLayer(index, source)) | 579 if (LookupLayer(index, source)) |
559 { | 580 { |
560 if (isError) | 581 if (isError) |