comparison Framework/StoneInitialization.cpp @ 1187:092ec2a225ad broker

dealing with locales in Qt
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 22 Nov 2019 14:31:42 +0100
parents ad4e21df4e40
children 358461330978
comparison
equal deleted inserted replaced
1186:3284c3fd96ad 1187:092ec2a225ad
23 23
24 #if !defined(ORTHANC_ENABLE_SDL) 24 #if !defined(ORTHANC_ENABLE_SDL)
25 # error Macro ORTHANC_ENABLE_SDL must be defined 25 # error Macro ORTHANC_ENABLE_SDL must be defined
26 #endif 26 #endif
27 27
28 #if !defined(ORTHANC_ENABLE_QT)
29 # error Macro ORTHANC_ENABLE_QT must be defined
30 #endif
31
28 #if !defined(ORTHANC_ENABLE_SSL) 32 #if !defined(ORTHANC_ENABLE_SSL)
29 # error Macro ORTHANC_ENABLE_SSL must be defined 33 # error Macro ORTHANC_ENABLE_SSL must be defined
30 #endif 34 #endif
31 35
32 #if !defined(ORTHANC_ENABLE_CURL) 36 #if !defined(ORTHANC_ENABLE_CURL)
42 46
43 #if ORTHANC_ENABLE_SDL == 1 47 #if ORTHANC_ENABLE_SDL == 1
44 # include "Viewport/SdlWindow.h" 48 # include "Viewport/SdlWindow.h"
45 #endif 49 #endif
46 50
51 #if ORTHANC_ENABLE_QT == 1
52 # include <QCoreApplication>
53 #endif
54
47 #if ORTHANC_ENABLE_CURL == 1 55 #if ORTHANC_ENABLE_CURL == 1
48 # include <Core/HttpClient.h> 56 # include <Core/HttpClient.h>
49 #endif 57 #endif
50 58
51 #if ORTHANC_ENABLE_DCMTK == 1 59 #if ORTHANC_ENABLE_DCMTK == 1
54 62
55 #include "Toolbox/LinearAlgebra.h" 63 #include "Toolbox/LinearAlgebra.h"
56 64
57 #include <Core/OrthancException.h> 65 #include <Core/OrthancException.h>
58 #include <Core/Toolbox.h> 66 #include <Core/Toolbox.h>
67
68 #include <locale>
59 69
60 70
61 namespace OrthancStone 71 namespace OrthancStone
62 { 72 {
63 #if ORTHANC_ENABLE_LOGGING_PLUGIN == 1 73 #if ORTHANC_ENABLE_LOGGING_PLUGIN == 1
92 # else 102 # else
93 OFLog::configure(OFLogger::OFF_LOG_LEVEL); 103 OFLog::configure(OFLogger::OFF_LOG_LEVEL);
94 # endif 104 # endif
95 #endif 105 #endif
96 106
107 /**
108 * This call is necessary to make "boost::lexical_cast<>" work in
109 * a consistent way in the presence of "double" or "float", and of
110 * a numeric locale that replaces dot (".") by comma (",") as the
111 * decimal separator.
112 * https://stackoverflow.com/a/18981514/881731
113 **/
114 std::locale::global(std::locale::classic());
115
97 { 116 {
98 // Run-time check of locale settings after Qt has been initialized 117 // Run-time checks of locale settings, to be run after Qt has
99 OrthancStone::Vector v; 118 // been initialized, as Qt changes locale settings
100 if (!OrthancStone::LinearAlgebra::ParseVector(v, "1.3671875\\-1.3671875") || 119
101 v.size() != 2 || 120 #if ORTHANC_ENABLE_QT == 1
102 !OrthancStone::LinearAlgebra::IsNear(1.3671875f, v[0]) || 121 if (QCoreApplication::instance() == NULL)
103 !OrthancStone::LinearAlgebra::IsNear(-1.3671875f, v[1]))
104 { 122 {
105 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, 123 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls,
106 "Error in the locale settings, giving up"); 124 "Qt must be initialized before Stone");
125 }
126 #endif
127
128 {
129 OrthancStone::Vector v;
130 if (!OrthancStone::LinearAlgebra::ParseVector(v, "1.3671875\\-1.3671875") ||
131 v.size() != 2 ||
132 !OrthancStone::LinearAlgebra::IsNear(1.3671875f, v[0]) ||
133 !OrthancStone::LinearAlgebra::IsNear(-1.3671875f, v[1]))
134 {
135 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
136 "Error in the locale settings, giving up");
137 }
138 }
139
140 {
141 Json::Value dicomweb = Json::objectValue;
142 dicomweb["00280030"] = Json::objectValue;
143 dicomweb["00280030"]["vr"] = "DS";
144 dicomweb["00280030"]["Value"] = Json::arrayValue;
145 dicomweb["00280030"]["Value"].append(1.2f);
146 dicomweb["00280030"]["Value"].append(-1.5f);
147
148 Orthanc::DicomMap source;
149 source.FromDicomWeb(dicomweb);
150
151 std::string s;
152 OrthancStone::Vector v;
153 if (!source.LookupStringValue(s, Orthanc::DICOM_TAG_PIXEL_SPACING, false) ||
154 !OrthancStone::LinearAlgebra::ParseVector(v, s) ||
155 v.size() != 2 ||
156 !OrthancStone::LinearAlgebra::IsNear(1.2f, v[0]) ||
157 !OrthancStone::LinearAlgebra::IsNear(-1.5f, v[1]))
158 {
159 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
160 "Error in the locale settings, giving up");
161 }
107 } 162 }
108 } 163 }
109 164
110 #if ORTHANC_ENABLE_SDL == 1 165 #if ORTHANC_ENABLE_SDL == 1
111 OrthancStone::SdlWindow::GlobalInitialize(); 166 OrthancStone::SdlWindow::GlobalInitialize();