Mercurial > hg > orthanc-stone
annotate Framework/StoneException.h @ 923:6b81c5453382
RadiographyScene: avoid exporting to width+1 image size due to numerical noise in GetSceneExtent()
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Mon, 22 Jul 2019 14:28:56 +0200 |
parents | 101073b3e855 |
children | 1091b2adeb5a |
rev | line source |
---|---|
295
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
1 /** |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
2 * Stone of Orthanc |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
439 | 5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
295
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
6 * |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
11 * |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
16 * |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
19 **/ |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
20 |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
21 |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
22 #pragma once |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
23 |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
24 #include "Core/OrthancException.h" |
297 | 25 #include <boost/lexical_cast.hpp> |
295
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
26 |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
27 namespace OrthancStone |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
28 { |
297 | 29 enum ErrorCode |
30 { | |
31 ErrorCode_Success, | |
32 ErrorCode_OrthancError, // this StoneException is actually an OrthancException with an Orthanc error code | |
33 ErrorCode_ApplicationException, // this StoneException is specific to an application (and should have its own internal error code) | |
34 ErrorCode_NotImplemented, // case not implemented | |
307 | 35 |
297 | 36 ErrorCode_PromiseSingleSuccessHandler, // a Promise can only have a single success handler |
37 ErrorCode_PromiseSingleFailureHandler, // a Promise can only have a single failure handler | |
295
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
38 |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
307
diff
changeset
|
39 ErrorCode_CanOnlyAddOneLayerAtATime, |
307 | 40 ErrorCode_CommandJsonInvalidFormat, |
297 | 41 ErrorCode_Last |
42 }; | |
43 | |
44 | |
45 | |
46 class StoneException | |
47 { | |
48 protected: | |
49 OrthancStone::ErrorCode errorCode_; | |
50 | |
51 public: | |
52 explicit StoneException(ErrorCode errorCode) : | |
53 errorCode_(errorCode) | |
54 { | |
55 } | |
56 | |
57 ErrorCode GetErrorCode() const | |
58 { | |
59 return errorCode_; | |
60 } | |
61 | |
62 virtual const char* What() const | |
63 { | |
64 return "TODO: EnumerationToString for StoneException"; | |
65 } | |
66 }; | |
67 | |
68 class StoneOrthancException : public StoneException | |
69 { | |
70 protected: | |
71 Orthanc::OrthancException& orthancException_; | |
72 | |
73 public: | |
74 explicit StoneOrthancException(Orthanc::OrthancException& orthancException) : | |
75 StoneException(ErrorCode_OrthancError), | |
76 orthancException_(orthancException) | |
77 { | |
78 } | |
79 | |
80 Orthanc::ErrorCode GetOrthancErrorCode() const | |
81 { | |
82 return orthancException_.GetErrorCode(); | |
83 } | |
84 | |
85 virtual const char* What() const | |
86 { | |
87 return orthancException_.What(); | |
88 } | |
89 }; | |
90 | |
91 class StoneApplicationException : public StoneException | |
92 { | |
93 protected: | |
94 int applicationErrorCode_; | |
95 | |
96 public: | |
97 explicit StoneApplicationException(int applicationErrorCode) : | |
98 StoneException(ErrorCode_ApplicationException), | |
99 applicationErrorCode_(applicationErrorCode) | |
100 { | |
101 } | |
102 | |
103 int GetApplicationErrorCode() const | |
104 { | |
105 return applicationErrorCode_; | |
106 } | |
107 | |
108 virtual const char* What() const | |
109 { | |
110 return boost::lexical_cast<std::string>(applicationErrorCode_).c_str(); | |
111 } | |
112 }; | |
295
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
113 |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
114 } |
b04b13810540
unified CMakeLists.txt into a single file for WASM/Native + bootstrap Command (to rework) + doc
am@osimis.io
parents:
diff
changeset
|
115 |
722
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
116 // See https://isocpp.org/wiki/faq/misc-technical-issues#macros-with-multi-stmts |
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
117 // (or google "Multiple lines macro C++ faq lite" if link is dead) |
751
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
118 #define ORTHANC_ASSERT2(cond,streamChainMessage) \ |
722
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
119 if (!(cond)) { \ |
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
120 std::stringstream sst; \ |
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
121 sst << "Assertion failed. Condition = \"" #cond "\" Message = \"" << streamChainMessage << "\""; \ |
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
122 std::string sstr = sst.str(); \ |
738
8e31b174ab26
removing using namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
123 throw ::Orthanc::OrthancException(::Orthanc::ErrorCode_InternalError,sstr.c_str()); \ |
722
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
124 } else (void)0 |
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
125 |
751
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
126 #define ORTHANC_ASSERT1(cond) \ |
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
127 if (!(cond)) { \ |
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
128 std::stringstream sst; \ |
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
129 sst << "Assertion failed. Condition = \"" #cond "\""; \ |
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
130 std::string sstr = sst.str(); \ |
851
101073b3e855
Added namespace to ORTHANC_ASSERT macros
Benjamin Golinvaux <bgo@osimis.io>
parents:
761
diff
changeset
|
131 throw ::Orthanc::OrthancException(::Orthanc::ErrorCode_InternalError,sstr.c_str()); \ |
751
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
132 } else (void)0 |
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
133 |
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
134 # define ORTHANC_EXPAND( x ) x |
761
07adcffba38c
truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents:
754
diff
changeset
|
135 # define GET_ORTHANC_ASSERT(_1,_2,NAME,...) NAME |
751
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
136 # define ORTHANC_ASSERT(...) ORTHANC_EXPAND(GET_ORTHANC_ASSERT(__VA_ARGS__, ORTHANC_ASSERT2, ORTHANC_ASSERT1, UNUSED)(__VA_ARGS__)) |
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
137 |
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
138 /* |
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
139 Explanation: |
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
140 |
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
141 ORTHANC_ASSERT(a) |
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
142 ORTHANC_EXPAND(GET_ORTHANC_ASSERT(a, ORTHANC_ASSERT2, ORTHANC_ASSERT1, UNUSED)(a)) |
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
143 ORTHANC_EXPAND(ORTHANC_ASSERT1(a)) |
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
144 ORTHANC_ASSERT1(a) |
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
145 |
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
146 ORTHANC_ASSERT(a,b) |
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
147 ORTHANC_EXPAND(GET_ORTHANC_ASSERT(a, b, ORTHANC_ASSERT2, ORTHANC_ASSERT1, UNUSED)(a,b)) |
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
148 ORTHANC_EXPAND(ORTHANC_ASSERT2(a,b)) |
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
149 ORTHANC_ASSERT2(a,b) |
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
150 |
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
151 Note: ORTHANC_EXPAND is required for some older compilers (MS v100 cl.exe ) |
712ff6ff3c19
- undo redo now works fine for both measure tool creation commands
Benjamin Golinvaux <bgo@osimis.io>
parents:
722
diff
changeset
|
152 */ |
761
07adcffba38c
truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents:
754
diff
changeset
|
153 |
07adcffba38c
truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents:
754
diff
changeset
|
154 |
07adcffba38c
truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents:
754
diff
changeset
|
155 |
07adcffba38c
truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents:
754
diff
changeset
|
156 |
07adcffba38c
truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents:
754
diff
changeset
|
157 |
07adcffba38c
truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents:
754
diff
changeset
|
158 |