Search in sources :

Example 1 with ReactionCartoon

use of cbit.vcell.graph.ReactionCartoon in project vcell by virtualcell.

the class ITextWriter method generateDocReactionsImage.

public static BufferedImage generateDocReactionsImage(Model model, Integer width) throws Exception {
    // if (model == null || !isValidResolutionSetting(resolution)) {
    // throw new IllegalArgumentException("Invalid parameters for generating reactions image for  model: " + model.getName());
    // }
    ReactionCartoon rcartoon = new ReactionCartoonFull();
    rcartoon.setModel(model);
    StructureSuite structureSuite = new AllStructureSuite(new Model.Owner() {

        @Override
        public Model getModel() {
            return model;
        }
    });
    rcartoon.setStructureSuite(structureSuite);
    rcartoon.refreshAll();
    // dummy settings to get the real dimensions.
    BufferedImage dummyBufferedImage = new BufferedImage(DEF_IMAGE_WIDTH, DEF_IMAGE_HEIGHT, BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D dummyGraphics = (Graphics2D) dummyBufferedImage.getGraphics();
    Dimension prefDim = rcartoon.getPreferedCanvasSize(dummyGraphics);
    dummyGraphics.dispose();
    // double width = prefDim.getWidth();
    // double height = prefDim.getHeight();
    double widthHeightRatio = (double) prefDim.getWidth() / (double) prefDim.getHeight();
    if (width == null) {
        width = ITextWriter.DEF_IMAGE_WIDTH;
    }
    int height = (int) ((double) width / widthHeightRatio);
    // int MAX_IMAGE_HEIGHT = 532;
    // if (width < ITextWriter.DEF_IMAGE_WIDTH) {
    // width = ITextWriter.DEF_IMAGE_WIDTH;
    // }
    // height= height * width/prefDim.getWidth();
    // if (height < ITextWriter.DEF_IMAGE_HEIGHT) {
    // height = ITextWriter.DEF_IMAGE_HEIGHT;
    // } else if (height > MAX_IMAGE_HEIGHT) {
    // height = MAX_IMAGE_HEIGHT;
    // }
    // width= width * height/prefDim.getHeight();
    Dimension newDim = new Dimension((int) width, (int) height);
    rcartoon.getResizeManager().setZoomPercent((int) (100 * width / prefDim.getWidth()));
    BufferedImage bufferedImage = new BufferedImage(newDim.width, newDim.height, BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D g = (Graphics2D) bufferedImage.getGraphics();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    GraphContainerLayoutReactions containerLayout = new GraphContainerLayoutReactions();
    containerLayout.layout(rcartoon, g, prefDim);
    rcartoon.paint(g);
    g.dispose();
    return bufferedImage;
}
Also used : AllStructureSuite(cbit.vcell.graph.structures.AllStructureSuite) StructureSuite(cbit.vcell.graph.structures.StructureSuite) Dimension(java.awt.Dimension) GraphContainerLayoutReactions(cbit.gui.graph.GraphContainerLayoutReactions) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) ReactionCartoon(cbit.vcell.graph.ReactionCartoon) MathModel(cbit.vcell.mathmodel.MathModel) IndexColorModel(java.awt.image.IndexColorModel) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel) ReactionCartoonFull(cbit.vcell.graph.ReactionCartoonFull) AllStructureSuite(cbit.vcell.graph.structures.AllStructureSuite)

Example 2 with ReactionCartoon

use of cbit.vcell.graph.ReactionCartoon in project vcell by virtualcell.

the class ReactionCartoonTool method deleteReactionsAndSpecies.

public static void deleteReactionsAndSpecies(Component requester, ReactionStep[] reactionStepArr, SpeciesContext[] speciesContextArr) throws Exception, UserCancelException {
    if ((speciesContextArr == null && reactionStepArr == null) || (reactionStepArr == null && speciesContextArr != null && speciesContextArr.length == 0) || (speciesContextArr == null && reactionStepArr != null && reactionStepArr.length == 0) || (speciesContextArr != null && speciesContextArr.length == 0 && reactionStepArr != null && reactionStepArr.length == 0)) {
        return;
    }
    int rxCount = (reactionStepArr != null ? reactionStepArr.length : 0);
    int speciesCount = (speciesContextArr != null ? speciesContextArr.length : 0);
    boolean bHasBoth = speciesCount > 0 && rxCount > 0;
    ReactionCartoon rxCartoon = null;
    if (requester instanceof GraphPane && ((GraphPane) requester).getGraphModel() instanceof ReactionCartoon) {
        rxCartoon = (ReactionCartoon) (((GraphPane) requester).getGraphModel());
    } else if (requester instanceof ReactionCartoonEditorPanel) {
        rxCartoon = ((ReactionCartoonEditorPanel) requester).getReactionCartoon();
    } else {
        throw new IllegalArgumentException("ReactionCartoonTool.deleteSpeciesContext not implemented for type '" + requester.getClass().getName() + "'");
    }
    DeleteSpeciesInfo deleteSpeciesInfo = null;
    final String DETAILS = "Details...";
    while (true) {
        String response = DialogUtils.showWarningDialog(requester, RXSPECIES_DELETE + " " + (bHasBoth ? "Reactions and Species." : (rxCount > 0 ? "Reactions." : (speciesCount > 0 ? "Species." : ""))), RXSPECIES_DELETE + " " + (bHasBoth ? rxCount + " Reactions and " + speciesCount + " Species." : (rxCount > 0 ? rxCount + " Reactions." : (speciesCount > 0 ? speciesCount + " Species." : ""))), new String[] { RXSPECIES_DELETE, DETAILS, RXSPECIES_CANCEL }, RXSPECIES_DELETE);
        if (response == null || response.equals(RXSPECIES_CANCEL)) {
            throw UserCancelException.CANCEL_GENERIC;
        }
        deleteSpeciesInfo = (deleteSpeciesInfo == null ? detailsDeleteSpecies(requester, speciesContextArr, reactionStepArr, rxCartoon) : deleteSpeciesInfo);
        if (response.equals(DETAILS)) {
            TableListResult tableListResult = showDeleteDetails(requester, deleteSpeciesInfo, reactionStepArr, false);
        // if(!tableListResult.selectedOption.equals(RXSPECIES_BACK)){
        // //if(!tableListResult.selectedOption.equals((bCut?RXSPECIES_CUT:RXSPECIES_DELETE))){
        // throw UserCancelException.CANCEL_GENERIC;
        // }
        } else {
            break;
        }
    }
    if (deleteSpeciesInfo != null) {
        for (Boolean errors : deleteSpeciesInfo.getbUnresolvableHashMap().values()) {
            if (errors) {
                while (true) {
                    String response = DialogUtils.showWarningDialog(requester, "Error warning.", "Warning: 1 or more SpeciesContexts have Model references that could cause Model corruption if " + RXSPECIES_DELETE + ".", new String[] { DETAILS, RXSPECIES_CANCEL }, DETAILS);
                    if (response == null || response.equals(RXSPECIES_CANCEL)) {
                        throw UserCancelException.CANCEL_GENERIC;
                    }
                    showDeleteDetails(requester, deleteSpeciesInfo, reactionStepArr, true);
                }
            }
        }
    }
    if (reactionStepArr != null) {
        for (int i = 0; i < reactionStepArr.length; i += 1) {
            rxCartoon.getModel().removeReactionStep(reactionStepArr[i]);
        }
    }
    if (deleteSpeciesInfo != null) {
        // remove all ReactionParticipants ("lines" between reaction and species in "Reaction Diagram") that have this speciesContext before deleting SpeciesContext
        for (SpeciesContext objSpeciesContext : deleteSpeciesInfo.getRxPartHashMap().keySet()) {
            if (deleteSpeciesInfo.getbUnresolvableHashMap().get(objSpeciesContext)) {
                continue;
            }
            Iterator<ReactionParticipant> iterRxPart = deleteSpeciesInfo.getRxPartHashMap().get(objSpeciesContext).iterator();
            while (iterRxPart.hasNext()) {
                ReactionParticipant objRxPart = iterRxPart.next();
                if (rxCartoon.getObjects().contains(objRxPart)) {
                    // Reaction delete may have already removed
                    objRxPart.getReactionStep().removeReactionParticipant(objRxPart);
                }
            }
        }
        // remove the SpeciesContext
        for (int i = 0; i < speciesContextArr.length; i++) {
            if (deleteSpeciesInfo.getbUnresolvableHashMap().get(speciesContextArr[i])) {
                continue;
            }
            if (rxCartoon.getObjects().contains(speciesContextArr[i])) {
                // Reaction delete may have already removed
                rxCartoon.getModel().removeSpeciesContext(speciesContextArr[i]);
            }
        }
    }
}
Also used : TableListResult(org.vcell.util.gui.DialogUtils.TableListResult) SpeciesContext(cbit.vcell.model.SpeciesContext) GraphPane(cbit.gui.graph.gui.GraphPane) Point(java.awt.Point) ReactionCartoon(cbit.vcell.graph.ReactionCartoon) ReactionParticipant(cbit.vcell.model.ReactionParticipant)

Aggregations

ReactionCartoon (cbit.vcell.graph.ReactionCartoon)2 GraphContainerLayoutReactions (cbit.gui.graph.GraphContainerLayoutReactions)1 GraphPane (cbit.gui.graph.gui.GraphPane)1 BioModel (cbit.vcell.biomodel.BioModel)1 ReactionCartoonFull (cbit.vcell.graph.ReactionCartoonFull)1 AllStructureSuite (cbit.vcell.graph.structures.AllStructureSuite)1 StructureSuite (cbit.vcell.graph.structures.StructureSuite)1 MathModel (cbit.vcell.mathmodel.MathModel)1 Model (cbit.vcell.model.Model)1 ReactionParticipant (cbit.vcell.model.ReactionParticipant)1 SpeciesContext (cbit.vcell.model.SpeciesContext)1 Dimension (java.awt.Dimension)1 Graphics2D (java.awt.Graphics2D)1 Point (java.awt.Point)1 BufferedImage (java.awt.image.BufferedImage)1 IndexColorModel (java.awt.image.IndexColorModel)1 TableListResult (org.vcell.util.gui.DialogUtils.TableListResult)1