Mercurial > hg > orthanc-stone
changeset 379:2308fe0b0b05
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 06 Nov 2018 14:41:36 +0100 |
parents | 814fa32e2fcc |
children | ba5ad93f935a |
files | Framework/Layers/ILayerSource.h Framework/Layers/LayerSourceBase.cpp Framework/Widgets/LayerWidget.cpp |
diffstat | 3 files changed, 60 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Layers/ILayerSource.h Tue Nov 06 14:21:02 2018 +0100 +++ b/Framework/Layers/ILayerSource.h Tue Nov 06 14:41:36 2018 +0100 @@ -33,37 +33,69 @@ class ILayerSource : public IObservable { public: - - typedef OriginMessage<MessageType_LayerSource_GeometryReady, ILayerSource> GeometryReadyMessage; - typedef OriginMessage<MessageType_LayerSource_GeometryError, ILayerSource> GeometryErrorMessage; + typedef OriginMessage<MessageType_LayerSource_GeometryReady, ILayerSource> GeometryReadyMessage; + typedef OriginMessage<MessageType_LayerSource_GeometryError, ILayerSource> GeometryErrorMessage; typedef OriginMessage<MessageType_LayerSource_ContentChanged, ILayerSource> ContentChangedMessage; - struct SliceChangedMessage : public OriginMessage<MessageType_LayerSource_SliceChanged, ILayerSource> + class SliceChangedMessage : public OriginMessage<MessageType_LayerSource_SliceChanged, ILayerSource> { + private: const Slice& slice_; - SliceChangedMessage(ILayerSource& origin, const Slice& slice) - : OriginMessage(origin), - slice_(slice) + + public: + SliceChangedMessage(ILayerSource& origin, + const Slice& slice) : + OriginMessage(origin), + slice_(slice) { } - }; - struct LayerReadyMessage : public OriginMessage<MessageType_LayerSource_LayerReady, ILayerSource> + const Slice& GetSlice() const + { + return slice_; + } + }; + + + class LayerReadyMessage : public OriginMessage<MessageType_LayerSource_LayerReady, ILayerSource> { - std::auto_ptr<ILayerRenderer>& renderer_; + private: + std::auto_ptr<ILayerRenderer> renderer_; const CoordinateSystem3D& slice_; bool isError_; + public: LayerReadyMessage(ILayerSource& origin, - std::auto_ptr<ILayerRenderer>& layer, + ILayerRenderer* renderer, // Takes ownership => TODO Remove this! const CoordinateSystem3D& slice, - bool isError // TODO Shouldn't this be separate as NotifyLayerError? - ) - : OriginMessage(origin), - renderer_(layer), - slice_(slice), - isError_(isError) + bool isError // TODO => create NotifyLayerError + ) : + OriginMessage(origin), + renderer_(renderer), + slice_(slice), + isError_(isError) + { + } + + // TODO - Remove this function + std::auto_ptr<ILayerRenderer>& GetRendererRaw() { + return renderer_; + } + + const ILayerRenderer& GetRenderer() const + { + return *renderer_; + } + + const CoordinateSystem3D& GetSlice() const + { + return slice_; + } + + bool IsError() const + { + return isError_; } };
--- a/Framework/Layers/LayerSourceBase.cpp Tue Nov 06 14:21:02 2018 +0100 +++ b/Framework/Layers/LayerSourceBase.cpp Tue Nov 06 14:41:36 2018 +0100 @@ -49,8 +49,7 @@ const CoordinateSystem3D& slice, bool isError) { - std::auto_ptr<ILayerRenderer> renderer(layer); - EmitMessage(ILayerSource::LayerReadyMessage(*this, renderer, slice, isError)); + EmitMessage(ILayerSource::LayerReadyMessage(*this, layer, slice, isError)); } void LayerSourceBase::NotifyImageReady(const Orthanc::ImageAccessor& image, @@ -59,5 +58,4 @@ { EmitMessage(ILayerSource::ImageReadyMessage(*this, image, imageQuality, slice)); } - }
--- a/Framework/Widgets/LayerWidget.cpp Tue Nov 06 14:21:02 2018 +0100 +++ b/Framework/Widgets/LayerWidget.cpp Tue Nov 06 14:41:36 2018 +0100 @@ -562,13 +562,14 @@ { InvalidateLayer(index); } + EmitMessage(LayerWidget::ContentChangedMessage(*this)); } void LayerWidget::OnSliceChanged(const ILayerSource::SliceChangedMessage& message) { - if (message.slice_.ContainsPlane(slice_)) + if (message.GetSlice().ContainsPlane(slice_)) { size_t index; if (LookupLayer(index, message.GetOrigin())) @@ -576,6 +577,7 @@ InvalidateLayer(index); } } + EmitMessage(LayerWidget::ContentChangedMessage(*this)); } @@ -585,7 +587,7 @@ size_t index; if (LookupLayer(index, message.GetOrigin())) { - if (message.isError_) + if (message.IsError()) { LOG(ERROR) << "Using error renderer on layer " << index; } @@ -594,11 +596,14 @@ LOG(INFO) << "Renderer ready for layer " << index; } - if (message.renderer_.get() != NULL) + // TODO -- REMOVE THIS UGLY STUFF + ILayerSource::LayerReadyMessage& ugly = const_cast<ILayerSource::LayerReadyMessage&>(message); + + if (ugly.GetRendererRaw().get() != NULL) { - UpdateLayer(index, message.renderer_.release(), message.slice_); + UpdateLayer(index, ugly.GetRendererRaw().release(), message.GetSlice()); } - else if (message.isError_) + else if (message.IsError()) { // TODO //UpdateLayer(index, new SliceOutlineRenderer(slice), slice);