Mercurial > hg > orthanc-stone
changeset 1224:37bc7f115f81 broker
integration mainline->broker
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 07 Dec 2019 18:45:37 +0100 |
parents | 21c2b0eee53c (current diff) 04fd875b91f4 (diff) |
children | 16738485e457 |
files | Applications/Samples/SingleFrameEditorApplication.h Framework/Radiography/RadiographyScene.cpp Framework/Radiography/RadiographyScene.h Framework/Radiography/RadiographySceneReader.cpp Framework/Radiography/RadiographyTextLayer.h Framework/Radiography/RadiographyWidget.cpp Framework/Radiography/RadiographyWidget.h |
diffstat | 10 files changed, 67 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/Applications/Samples/SingleFrameEditorApplication.h Sat Dec 07 18:18:07 2019 +0100 +++ b/Applications/Samples/SingleFrameEditorApplication.h Sat Dec 07 18:45:37 2019 +0100 @@ -508,8 +508,8 @@ } { - RadiographyTextLayer::SetFont(Orthanc::EmbeddedResources::UBUNTU_FONT); - RadiographyLayer& layer = scene_->LoadText("Hello\nworld", 20, 128, NULL); + RadiographyTextLayer::RegisterFont("ubuntu", Orthanc::EmbeddedResources::UBUNTU_FONT); + RadiographyLayer& layer = scene_->LoadText("Hello\nworld", "ubuntu", 20, 128, NULL, false); layer.SetResizeable(true); }
--- a/Framework/Deprecated/Widgets/WorldSceneWidget.cpp Sat Dec 07 18:18:07 2019 +0100 +++ b/Framework/Deprecated/Widgets/WorldSceneWidget.cpp Sat Dec 07 18:45:37 2019 +0100 @@ -179,10 +179,8 @@ } else if (hasDefaultMouseEvents_) { - printf("has default mouse events\n"); if (touches.size() == 2) { - printf("2 touches !\n"); return new SceneMouseTracker(view_, new PanZoomMouseTracker(*this, touches)); } else
--- a/Framework/Radiography/RadiographyScene.cpp Sat Dec 07 18:18:07 2019 +0100 +++ b/Framework/Radiography/RadiographyScene.cpp Sat Dec 07 18:45:37 2019 +0100 @@ -295,11 +295,12 @@ RadiographyLayer& RadiographyScene::UpdateText(size_t layerIndex, const std::string& utf8, + const std::string& font, unsigned int fontSize, uint8_t foreground) { RadiographyTextLayer& textLayer = dynamic_cast<RadiographyTextLayer&>(GetLayer(layerIndex)); - textLayer.SetText(utf8, fontSize, foreground); + textLayer.SetText(utf8, font, fontSize, foreground); BroadcastMessage(RadiographyScene::ContentChangedMessage(*this, textLayer)); BroadcastMessage(RadiographyScene::LayerEditedMessage(*this, textLayer)); @@ -308,15 +309,27 @@ RadiographyLayer& RadiographyScene::LoadText(const std::string& utf8, + const std::string& font, unsigned int fontSize, uint8_t foreground, - RadiographyLayer::Geometry* geometry) + RadiographyLayer::Geometry* centerGeometry, + bool isCenterGeometry) { std::auto_ptr<RadiographyTextLayer> alpha(new RadiographyTextLayer(*this)); - alpha->SetText(utf8, fontSize, foreground); - if (geometry != NULL) + alpha->SetText(utf8, font, fontSize, foreground); + if (centerGeometry != NULL) { - alpha->SetGeometry(*geometry); + if (isCenterGeometry) + { + // modify geometry to reference the top left corner + double tlx = centerGeometry->GetPanX(); + double tly = centerGeometry->GetPanY(); + Extent2D textExtent = alpha->GetExtent(); + tlx = tlx - (textExtent.GetWidth() / 2) * centerGeometry->GetPixelSpacingX(); + tly = tly - (textExtent.GetHeight() / 2) * centerGeometry->GetPixelSpacingY(); + centerGeometry->SetPan(tlx, tly); + } + alpha->SetGeometry(*centerGeometry); } RadiographyLayer& registeredLayer = RegisterLayer(alpha.release());
--- a/Framework/Radiography/RadiographyScene.h Sat Dec 07 18:18:07 2019 +0100 +++ b/Framework/Radiography/RadiographyScene.h Sat Dec 07 18:45:37 2019 +0100 @@ -200,11 +200,14 @@ RadiographyPhotometricDisplayMode GetPreferredPhotomotricDisplayMode() const; RadiographyLayer& LoadText(const std::string& utf8, + const std::string& font, unsigned int fontSize, uint8_t foreground, - RadiographyLayer::Geometry* geometry); + RadiographyLayer::Geometry* geometry, + bool isCenterGeometry); RadiographyLayer& UpdateText(size_t layerIndex, + const std::string& font, const std::string& utf8, unsigned int fontSize, uint8_t foreground);
--- a/Framework/Radiography/RadiographySceneReader.cpp Sat Dec 07 18:18:07 2019 +0100 +++ b/Framework/Radiography/RadiographySceneReader.cpp Sat Dec 07 18:45:37 2019 +0100 @@ -98,7 +98,7 @@ else if (jsonLayer["type"].asString() == "text") { ReadLayerGeometry(geometry, jsonLayer); - scene_.LoadText(jsonLayer["text"].asString(), jsonLayer["fontSize"].asUInt(), static_cast<uint8_t>(jsonLayer["foreground"].asUInt()), &geometry); + scene_.LoadText(jsonLayer["text"].asString(), jsonLayer["font"].asString(), jsonLayer["fontSize"].asUInt(), static_cast<uint8_t>(jsonLayer["foreground"].asUInt()), &geometry, false); } else if (jsonLayer["type"].asString() == "alpha") { @@ -175,7 +175,7 @@ else if (jsonLayer["type"].asString() == "text") { ReadLayerGeometry(geometry, jsonLayer); - scene_.LoadText(jsonLayer["text"].asString(), jsonLayer["fontSize"].asUInt(), static_cast<uint8_t>(jsonLayer["foreground"].asUInt()), &geometry); + scene_.LoadText(jsonLayer["text"].asString(), jsonLayer["font"].asString(), jsonLayer["fontSize"].asUInt(), static_cast<uint8_t>(jsonLayer["foreground"].asUInt()), &geometry, false); } else if (jsonLayer["type"].asString() == "alpha") {
--- a/Framework/Radiography/RadiographySceneWriter.cpp Sat Dec 07 18:18:07 2019 +0100 +++ b/Framework/Radiography/RadiographySceneWriter.cpp Sat Dec 07 18:45:37 2019 +0100 @@ -62,8 +62,9 @@ { output["type"] = "text"; output["text"] = layer.GetText(); - output["fontSize"] = static_cast<unsigned int>(layer.GetFontSize()); - output["foreground"] = layer.GetForeground(); + output["font"] = layer.GetFont(); + output["fontSize"] = layer.GetFontSize(); + output["foreground"] = layer.GetForegroundGreyLevel(); } void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyMaskLayer& layer)
--- a/Framework/Radiography/RadiographyTextLayer.cpp Sat Dec 07 18:18:07 2019 +0100 +++ b/Framework/Radiography/RadiographyTextLayer.cpp Sat Dec 07 18:45:37 2019 +0100 @@ -26,27 +26,28 @@ namespace OrthancStone { - bool RadiographyTextLayer::fontHasBeenConfigured_ = false; - Orthanc::EmbeddedResources::FileResourceId RadiographyTextLayer::fontResourceId_; + std::map<std::string, Orthanc::EmbeddedResources::FileResourceId> RadiographyTextLayer::fonts_; void RadiographyTextLayer::SetText(const std::string& utf8, - unsigned int fontSize, - uint8_t foreground) + const std::string& font, + unsigned int fontSize, + uint8_t foregroundGreyLevel) { - if (!fontHasBeenConfigured_) + if (fonts_.find(font) == fonts_.end()) { - throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls, "No font has been loaded"); + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls, "The font has not been registered"); } text_ = utf8; + font_ = font; fontSize_ = fontSize; - foreground_ = foreground; + foregroundGreyLevel_ = foregroundGreyLevel; - SetAlpha(TextRenderer::Render(fontResourceId_, + SetAlpha(TextRenderer::Render(fonts_[font_], fontSize_, text_)); - SetForegroundValue(foreground * 256.0f); + SetForegroundValue(foregroundGreyLevel * 256.0f); } }
--- a/Framework/Radiography/RadiographyTextLayer.h Sat Dec 07 18:18:07 2019 +0100 +++ b/Framework/Radiography/RadiographyTextLayer.h Sat Dec 07 18:45:37 2019 +0100 @@ -31,38 +31,42 @@ { private: std::string text_; + std::string font_; unsigned int fontSize_; - uint8_t foreground_; + uint8_t foregroundGreyLevel_; - static bool fontHasBeenConfigured_; - static Orthanc::EmbeddedResources::FileResourceId fontResourceId_; + static std::map<std::string, Orthanc::EmbeddedResources::FileResourceId> fonts_; public: RadiographyTextLayer(const RadiographyScene& scene) : RadiographyAlphaLayer(scene) { } - void SetText(const std::string& utf8, unsigned int fontSize, uint8_t foreground); + void SetText(const std::string& utf8, const std::string& font, unsigned int fontSize, uint8_t foregroundGreyLevel); const std::string& GetText() const { return text_; } + const std::string& GetFont() const + { + return font_; + } + unsigned int GetFontSize() const { return fontSize_; } - uint8_t GetForeground() const + uint8_t GetForegroundGreyLevel() const { - return foreground_; + return foregroundGreyLevel_; } - static void SetFont(Orthanc::EmbeddedResources::FileResourceId fontResourceId) + static void RegisterFont(const std::string& name, Orthanc::EmbeddedResources::FileResourceId fontResourceId) { - fontResourceId_ = fontResourceId; - fontHasBeenConfigured_ = true; + fonts_[name] = fontResourceId; } }; }
--- a/Framework/Radiography/RadiographyWidget.cpp Sat Dec 07 18:18:07 2019 +0100 +++ b/Framework/Radiography/RadiographyWidget.cpp Sat Dec 07 18:45:37 2019 +0100 @@ -180,6 +180,15 @@ { hasSelection_ = true; selectedLayer_ = layer; + + NotifyContentChanged(); + BroadcastMessage(SelectionChangedMessage(*this)); + } + + void RadiographyWidget::Unselect() + { + hasSelection_ = false; + BroadcastMessage(SelectionChangedMessage(*this)); } bool RadiographyWidget::LookupSelectedLayer(size_t& layer)
--- a/Framework/Radiography/RadiographyWidget.h Sat Dec 07 18:18:07 2019 +0100 +++ b/Framework/Radiography/RadiographyWidget.h Sat Dec 07 18:45:37 2019 +0100 @@ -32,8 +32,12 @@ class RadiographyWidget : public Deprecated::WorldSceneWidget, - public ObserverBase<RadiographyWidget> + public ObserverBase<RadiographyWidget>, + public IObservable { + public: + ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, SelectionChangedMessage, RadiographyWidget); + private: boost::shared_ptr<RadiographyScene> scene_; std::auto_ptr<Orthanc::ImageAccessor> floatBuffer_; @@ -73,10 +77,7 @@ void Select(size_t layer); - void Unselect() - { - hasSelection_ = false; - } + void Unselect(); template<typename LayerType> bool SelectLayerByType(size_t index = 0);