# HG changeset patch # User Sebastien Jodogne # Date 1575740737 -3600 # Node ID 37bc7f115f81cfcad57c54acf1aa8f1683b884e3 # Parent 21c2b0eee53cfa43cae6542539d6d645b2dc5508# Parent 04fd875b91f400e3e4d71b3333f27ef79908b961 integration mainline->broker diff -r 21c2b0eee53c -r 37bc7f115f81 Applications/Samples/SingleFrameEditorApplication.h --- 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); } diff -r 21c2b0eee53c -r 37bc7f115f81 Framework/Deprecated/Widgets/WorldSceneWidget.cpp --- 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 diff -r 21c2b0eee53c -r 37bc7f115f81 Framework/Radiography/RadiographyScene.cpp --- 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(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 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()); diff -r 21c2b0eee53c -r 37bc7f115f81 Framework/Radiography/RadiographyScene.h --- 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); diff -r 21c2b0eee53c -r 37bc7f115f81 Framework/Radiography/RadiographySceneReader.cpp --- 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(jsonLayer["foreground"].asUInt()), &geometry); + scene_.LoadText(jsonLayer["text"].asString(), jsonLayer["font"].asString(), jsonLayer["fontSize"].asUInt(), static_cast(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(jsonLayer["foreground"].asUInt()), &geometry); + scene_.LoadText(jsonLayer["text"].asString(), jsonLayer["font"].asString(), jsonLayer["fontSize"].asUInt(), static_cast(jsonLayer["foreground"].asUInt()), &geometry, false); } else if (jsonLayer["type"].asString() == "alpha") { diff -r 21c2b0eee53c -r 37bc7f115f81 Framework/Radiography/RadiographySceneWriter.cpp --- 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(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) diff -r 21c2b0eee53c -r 37bc7f115f81 Framework/Radiography/RadiographyTextLayer.cpp --- 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 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); } } diff -r 21c2b0eee53c -r 37bc7f115f81 Framework/Radiography/RadiographyTextLayer.h --- 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 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; } }; } diff -r 21c2b0eee53c -r 37bc7f115f81 Framework/Radiography/RadiographyWidget.cpp --- 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) diff -r 21c2b0eee53c -r 37bc7f115f81 Framework/Radiography/RadiographyWidget.h --- 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 + public ObserverBase, + public IObservable { + public: + ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, SelectionChangedMessage, RadiographyWidget); + private: boost::shared_ptr scene_; std::auto_ptr floatBuffer_; @@ -73,10 +77,7 @@ void Select(size_t layer); - void Unselect() - { - hasSelection_ = false; - } + void Unselect(); template bool SelectLayerByType(size_t index = 0);