comparison OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.cpp @ 1976:d71acf30970a

fixed serialization of pixel probes
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 29 Oct 2022 13:02:21 +0200
parents 5a434f5889f8
children ba971d9082d3
comparison
equal deleted inserted replaced
1975:5a434f5889f8 1976:d71acf30970a
223 } 223 }
224 224
225 virtual void SignalMove(GeometricPrimitive& primitive, 225 virtual void SignalMove(GeometricPrimitive& primitive,
226 const Scene2D& scene) = 0; 226 const Scene2D& scene) = 0;
227 227
228 virtual void UpdateProbe(const Scene2D& scene) = 0;
229
228 virtual void Serialize(Json::Value& target) = 0; 230 virtual void Serialize(Json::Value& target) = 0;
229 }; 231 };
230 232
231 233
232 class AnnotationsSceneLayer::Handle : public GeometricPrimitive 234 class AnnotationsSceneLayer::Handle : public GeometricPrimitive
885 } 887 }
886 888
887 UpdateLabel(); 889 UpdateLabel();
888 } 890 }
889 891
892 virtual void UpdateProbe(const Scene2D& scene) ORTHANC_OVERRIDE
893 {
894 }
895
890 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE 896 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE
891 { 897 {
892 target = Json::objectValue; 898 target = Json::objectValue;
893 target[KEY_TYPE] = VALUE_SEGMENT; 899 target[KEY_TYPE] = VALUE_SEGMENT;
894 target[KEY_X1] = handle1_.GetCenter().GetX(); 900 target[KEY_X1] = handle1_.GetCenter().GetX();
927 private: 933 private:
928 int probedLayer_; 934 int probedLayer_;
929 Handle& handle_; 935 Handle& handle_;
930 Text& label_; 936 Text& label_;
931 937
932 void UpdateLabel(const Scene2D& scene) 938 public:
939 PixelProbeAnnotation(AnnotationsSceneLayer& that,
940 Units units,
941 const ScenePoint2D& p,
942 int probedLayer) :
943 Annotation(that, units),
944 probedLayer_(probedLayer),
945 handle_(AddTypedPrimitive<Handle>(new Handle(*this, p))),
946 label_(AddTypedPrimitive<Text>(new Text(that, *this)))
947 {
948 label_.SetColor(COLOR_TEXT);
949 }
950
951 Handle& GetHandle() const
952 {
953 return handle_;
954 }
955
956 virtual void SignalMove(GeometricPrimitive& primitive,
957 const Scene2D& scene) ORTHANC_OVERRIDE
958 {
959 UpdateProbe(scene);
960 }
961
962 virtual void UpdateProbe(const Scene2D& scene) ORTHANC_OVERRIDE
933 { 963 {
934 TextSceneLayer content; 964 TextSceneLayer content;
935 965
936 content.SetPosition(handle_.GetCenter().GetX(), handle_.GetCenter().GetY()); 966 content.SetPosition(handle_.GetCenter().GetX(), handle_.GetCenter().GetY());
937 content.SetAnchor(BitmapAnchor_CenterLeft); 967 content.SetAnchor(BitmapAnchor_CenterLeft);
960 } 990 }
961 991
962 label_.SetContent(content); 992 label_.SetContent(content);
963 } 993 }
964 994
965 public:
966 PixelProbeAnnotation(AnnotationsSceneLayer& that,
967 Units units,
968 const ScenePoint2D& p,
969 const Scene2D& scene,
970 int probedLayer) :
971 Annotation(that, units),
972 probedLayer_(probedLayer),
973 handle_(AddTypedPrimitive<Handle>(new Handle(*this, p))),
974 label_(AddTypedPrimitive<Text>(new Text(that, *this)))
975 {
976 label_.SetColor(COLOR_TEXT);
977 UpdateLabel(scene);
978 }
979
980 Handle& GetHandle() const
981 {
982 return handle_;
983 }
984
985 virtual void SignalMove(GeometricPrimitive& primitive,
986 const Scene2D& scene) ORTHANC_OVERRIDE
987 {
988 UpdateLabel(scene);
989 }
990
991 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE 995 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE
992 { 996 {
993 target = Json::objectValue; 997 target = Json::objectValue;
994 target[KEY_TYPE] = VALUE_PIXEL_PROBE; 998 target[KEY_TYPE] = VALUE_PIXEL_PROBE;
995 target[KEY_X] = handle_.GetCenter().GetX(); 999 target[KEY_X] = handle_.GetCenter().GetX();
1004 if (source.isMember(KEY_X) && 1008 if (source.isMember(KEY_X) &&
1005 source.isMember(KEY_Y) && 1009 source.isMember(KEY_Y) &&
1006 source[KEY_X].isNumeric() && 1010 source[KEY_X].isNumeric() &&
1007 source[KEY_Y].isNumeric()) 1011 source[KEY_Y].isNumeric())
1008 { 1012 {
1009 Scene2D dummyScene; // TODO
1010 new PixelProbeAnnotation(target, units, 1013 new PixelProbeAnnotation(target, units,
1011 ScenePoint2D(source[KEY_X].asDouble(), source[KEY_Y].asDouble()), 1014 ScenePoint2D(source[KEY_X].asDouble(), source[KEY_Y].asDouble()),
1012 dummyScene, probedLayer); 1015 probedLayer);
1013 } 1016 }
1014 else 1017 else
1015 { 1018 {
1016 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize a pixel probe"); 1019 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize a pixel probe");
1017 } 1020 }
1121 } 1124 }
1122 1125
1123 UpdateLabel(); 1126 UpdateLabel();
1124 } 1127 }
1125 1128
1129 virtual void UpdateProbe(const Scene2D& scene) ORTHANC_OVERRIDE
1130 {
1131 }
1132
1126 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE 1133 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE
1127 { 1134 {
1128 target = Json::objectValue; 1135 target = Json::objectValue;
1129 target[KEY_TYPE] = VALUE_ANGLE; 1136 target[KEY_TYPE] = VALUE_ANGLE;
1130 target[KEY_X1] = startHandle_.GetCenter().GetX(); 1137 target[KEY_X1] = startHandle_.GetCenter().GetX();
1271 } 1278 }
1272 1279
1273 UpdateLabel(); 1280 UpdateLabel();
1274 } 1281 }
1275 1282
1283 virtual void UpdateProbe(const Scene2D& scene) ORTHANC_OVERRIDE
1284 {
1285 }
1286
1276 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE 1287 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE
1277 { 1288 {
1278 target = Json::objectValue; 1289 target = Json::objectValue;
1279 target[KEY_TYPE] = VALUE_CIRCLE; 1290 target[KEY_TYPE] = VALUE_CIRCLE;
1280 target[KEY_X1] = handle1_.GetCenter().GetX(); 1291 target[KEY_X1] = handle1_.GetCenter().GetX();
1486 const ScenePoint2D& sceneClick, 1497 const ScenePoint2D& sceneClick,
1487 const Scene2D& scene, 1498 const Scene2D& scene,
1488 int probedLayer) : 1499 int probedLayer) :
1489 that_(that) 1500 that_(that)
1490 { 1501 {
1491 new PixelProbeAnnotation(that, units, sceneClick, scene, probedLayer); 1502 PixelProbeAnnotation* annotation = new PixelProbeAnnotation(that, units, sceneClick, probedLayer);
1503 annotation->UpdateProbe(scene);
1492 } 1504 }
1493 1505
1494 virtual void PointerMove(const PointerEvent& event, 1506 virtual void PointerMove(const PointerEvent& event,
1495 const Scene2D& scene) ORTHANC_OVERRIDE 1507 const Scene2D& scene) ORTHANC_OVERRIDE
1496 { 1508 {
1897 { 1909 {
1898 LOG(ERROR) << "Cannot unserialize unknown type of annotation: " << type; 1910 LOG(ERROR) << "Cannot unserialize unknown type of annotation: " << type;
1899 } 1911 }
1900 } 1912 }
1901 } 1913 }
1914
1915
1916 void AnnotationsSceneLayer::UpdateProbes(const Scene2D& scene)
1917 {
1918 for (Annotations::const_iterator it = annotations_.begin(); it != annotations_.end(); ++it)
1919 {
1920 assert(*it != NULL);
1921 (*it)->UpdateProbe(scene);
1922 }
1923 }
1902 } 1924 }