@Override public void deleteNonSerializableGraphics() { if (models.isEmpty()) { return; } synchronized (models) { for (Graphic g : models) { if (!g.getLayer().getSerializable()) { g.removeAllPropertyChangeListener(); } } models.removeIf(g -> !g.getLayer().getSerializable()); layers.removeIf(l -> !l.getSerializable()); } }
@Override public boolean hasSerializableGraphics() { if (models.isEmpty()) { return false; } synchronized (models) { for (Graphic g : models) { /* * Exclude non serializable layer and graphics without points like NonEditableGraphic (not strictly the * jaxb serialization process that use the annotations from getModels()) */ if (g.getLayer().getSerializable() && !g.getPts().isEmpty()) { return true; } } } return false; }
private static void writeGraphics(GraphicModel model, Attributes attributes) { List<GraphicLayer> layers = model.getLayers(); Sequence annotationSeq = attributes.newSequence(Tag.GraphicAnnotationSequence, layers.size()); Sequence layerSeq = attributes.newSequence(Tag.GraphicLayerSequence, layers.size()); for (int i = 0; i < layers.size(); i++) { GraphicLayer layer = layers.get(i); if (layer.getSerializable()) { String layerName = layer.getType().name(); List<Graphic> graphics = getGraphicsByLayer(model, layer.getUuid()); Attributes l = new Attributes(2); l.setString(Tag.GraphicLayer, VR.CS, layerName); l.setInt(Tag.GraphicLayerOrder, VR.IS, i); float[] lab = PresentationStateReader .colorToLAB(Optional.ofNullable(MeasureTool.viewSetting.getLineColor()).orElse(Color.YELLOW)); if (lab != null) { l.setInt(Tag.GraphicLayerRecommendedDisplayCIELabValue, VR.US, CIELab.convertToDicomLab(lab)); } l.setString(Tag.GraphicLayerDescription, VR.LO, layer.toString()); layerSeq.add(l); Attributes a = new Attributes(2); a.setString(Tag.GraphicLayer, VR.CS, layerName); Sequence graphicSeq = a.newSequence(Tag.GraphicObjectSequence, graphics.size()); Sequence textSeq = a.newSequence(Tag.TextObjectSequence, graphics.size()); for (Graphic graphic : graphics) { buildDicomGraphic(graphic, graphicSeq, textSeq); } annotationSeq.add(a); } } }
public static GraphicModel getModelForSerialization(GraphicModel model, Point2D offset) { // Remove non serializable graphics XmlGraphicModel xmlModel = new XmlGraphicModel(); xmlModel.setReferencedSeries(model.getReferencedSeries()); for (Graphic g : model.getModels()) { if (g.getLayer().getSerializable() && !g.getPts().isEmpty()) { if (offset != null) { Graphic graphic = g.copy(); for (Point2D.Double p : graphic.getPts()) { p.x -= offset.getX(); p.y -= offset.getY(); } GraphicLabel label = g.getGraphicLabel(); graphic.buildShape(); if (label != null) { graphic.setLabel(label); } xmlModel.addGraphic(graphic); } else { xmlModel.addGraphic(g); } } } return xmlModel; }