Mercurial > hg > orthanc-wsi
changeset 569:d8b367955b10 annotations
improvements
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Tue, 01 Sep 2026 21:05:06 +0200 |
| parents | 88cbe7ab5c23 |
| children | 90d017623910 |
| files | ViewerPlugin/Annotations/AnnotationsRestApi.cpp |
| diffstat | 1 files changed, 58 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/ViewerPlugin/Annotations/AnnotationsRestApi.cpp Tue Sep 01 20:51:08 2026 +0200 +++ b/ViewerPlugin/Annotations/AnnotationsRestApi.cpp Tue Sep 01 21:05:06 2026 +0200 @@ -112,6 +112,18 @@ return resourceId_; } + unsigned int GetFrameNumber() const + { + if (level_ == Orthanc::ResourceType_Instance) + { + return frameNumber_; + } + else + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + } + std::string GetInfoKey() const { return GetKeyPrefix() + "|info"; @@ -652,6 +664,26 @@ return dynamic_cast<ImportedLayer&>(importedLayers_.GetLayer(layerId)); } + LayersCollection& GetUserLayers() + { + return userLayers_; + } + + const LayersCollection& GetUserLayers() const + { + return userLayers_; + } + + LayersCollection& GetImportedLayers() + { + return importedLayers_; + } + + const LayersCollection& GetImportedLayers() const + { + return importedLayers_; + } + std::string CreateUserLayer() { static const uint8_t PALETTE[] = { @@ -683,26 +715,6 @@ return AddUserLayer(new UserLayer(color, name)); } - LayersCollection& GetUserLayers() - { - return userLayers_; - } - - const LayersCollection& GetUserLayers() const - { - return userLayers_; - } - - LayersCollection& GetImportedLayers() - { - return importedLayers_; - } - - const LayersCollection& GetImportedLayers() const - { - return importedLayers_; - } - virtual void Serialize(Json::Value& serialized) const ORTHANC_OVERRIDE { serialized = Json::objectValue; @@ -739,7 +751,6 @@ return boost::posix_time::second_clock::universal_time(); } - void Load() { Json::Value info; @@ -918,6 +929,11 @@ } } + const AnnotationsWorkspaceId& GetId() const + { + return id_; + } + std::string GetProjectName() { return projectInformation_.GetName(); @@ -1081,7 +1097,7 @@ // and that the layer is still shared with this user if (found->second->GetUserLayers().HasLayer(layer.GetId())) { - const UserLayer& authorLayer = dynamic_cast<const UserLayer&>(found->second->GetUserLayers().GetLayer(layer.GetId())); + const UserLayer& authorLayer = found->second->GetUserLayer(layer.GetId()); if (authorLayer.IsSharedWith(userId_)) { @@ -1258,8 +1274,8 @@ private: std::unique_ptr<IAuthenticatedUser> user_; Json::Value body_; - std::unique_ptr<AnnotationsWorkspaceId> workspaceId_; std::unique_ptr<CachedAnnotationsWorkspace> workspace_; + IAuthenticatedUser::ProjectRole role_; public: AnnotationsCommandContext(const OrthancPluginHttpRequest* request) @@ -1278,22 +1294,22 @@ } const std::string projectId = Orthanc::SerializationToolbox::ReadString(body_, "project", "" /* default project */); - const std::string level = Orthanc::SerializationToolbox::ReadString(body_, "level"); + const std::string levelString = Orthanc::SerializationToolbox::ReadString(body_, "level"); const std::string resourceId = Orthanc::SerializationToolbox::ReadString(body_, "resource"); unsigned int frameNumber = Orthanc::SerializationToolbox::ReadUnsignedInteger(body_, "frame", 0 /* default frame */); - workspaceId_.reset(new AnnotationsWorkspaceId(projectId, Orthanc::StringToResourceType(level.c_str()), resourceId, frameNumber)); + role_ = user_->GetRoleInProject(projectId); - IAuthenticatedUser::ProjectRole role = user_->GetRoleInProject(workspaceId_->GetProjectId()); - - if (role != IAuthenticatedUser::ProjectRole_Instructor && - role != IAuthenticatedUser::ProjectRole_Learner) + if (role_ != IAuthenticatedUser::ProjectRole_Instructor && + role_ != IAuthenticatedUser::ProjectRole_Learner) { throw Orthanc::OrthancException(Orthanc::ErrorCode_ForbiddenAccess, "User \"" + user_->Format() + - "\" is not instructor or learner of project \"" + workspaceId_->GetProjectId() + "\""); + "\" is not instructor or learner of project \"" + projectId + "\""); } - workspace_.reset(new CachedAnnotationsWorkspace(*workspaceId_)); + Orthanc::ResourceType level = Orthanc::StringToResourceType(levelString.c_str()); + AnnotationsWorkspaceId workspaceId(projectId, level, resourceId, frameNumber); + workspace_.reset(new CachedAnnotationsWorkspace(workspaceId)); } const IAuthenticatedUser& GetUser() const @@ -1302,10 +1318,15 @@ return *user_; } - const AnnotationsWorkspaceId& GetWorkspaceId() const + AnnotationsWorkspace& GetWorkspace() { - assert(workspaceId_.get() != NULL); - return *workspaceId_; + assert(workspace_.get() != NULL); + return workspace_->GetContent(); + } + + IAuthenticatedUser::ProjectRole GetUserRoleInProject() const + { + return role_; } std::string GetBodyString(const char* field) const @@ -1324,12 +1345,6 @@ return body_[field]; } } - - AnnotationsWorkspace& GetWorkspace() - { - assert(workspace_.get() != NULL); - return workspace_->GetContent(); - } }; @@ -1624,7 +1639,7 @@ Json::Value answer; { - CachedUserFeatures cached(context.GetWorkspaceId(), context.GetUser().GetAnnotatingId()); + CachedUserFeatures cached(context.GetWorkspace().GetId(), context.GetUser().GetAnnotatingId()); cached.GetFeatures().GetContent(answer[KEY_FEATURES]); } @@ -1646,7 +1661,7 @@ AnnotationsCommandContext context(request); { - CachedUserFeatures cached(context.GetWorkspaceId(), context.GetUser().GetAnnotatingId()); + CachedUserFeatures cached(context.GetWorkspace().GetId(), context.GetUser().GetAnnotatingId()); cached.GetFeatures().SetContent(context.GetBodyField(KEY_FEATURES)); } @@ -1862,7 +1877,7 @@ Json::Value authorFeatures; { - CachedUserFeatures author(context.GetWorkspaceId(), *it); + CachedUserFeatures author(context.GetWorkspace().GetId(), *it); author.GetFeatures().GetContent(authorFeatures); }
