Search in sources :

Example 11 with Section

use of com.lowagie.text.Section in project vcell by virtualcell.

the class ITextWriter method writeGeometry.

// for now, the preferences for a geometry is a dummy.
public void writeGeometry(Geometry geom, FileOutputStream fos, PageFormat pageFormat, PublishPreferences preferences) throws Exception {
    if (geom == null || fos == null || pageFormat == null || preferences == null) {
        throw new IllegalArgumentException("One or more null params while publishing Geometry.");
    }
    try {
        createDocument(pageFormat);
        createDocWriter(fos);
        // Add metadata before you open the document...
        String name = geom.getName().trim();
        String userName = "Unknown";
        if (geom.getVersion() != null) {
            userName = geom.getVersion().getOwner().getName();
        }
        document.addTitle(name + "[owned by " + userName + "]");
        document.addCreator("Virtual Cell");
        document.addCreationDate();
        // writeWatermark(document, pageFormat);
        writeHeaderFooter("Geometry: " + name);
        document.open();
        // 
        Section introSection = null;
        int chapterNum = 1;
        Chapter geomChapter = new Chapter("Geometry", chapterNum++);
        introSection = geomChapter.addSection("General Info", geomChapter.numberDepth() + 1);
        writeMetadata(introSection, name, geom.getDescription(), userName, "Geometry");
        // title?
        Section geomSection = geomChapter.addSection("Geometry", geomChapter.numberDepth() + 1);
        writeGeom(geomSection, geom, null);
        document.add(geomChapter);
        document.close();
    } catch (DocumentException e) {
        System.err.println("Unable to publish BioModel.");
        e.printStackTrace();
        throw e;
    }
}
Also used : DocumentException(com.lowagie.text.DocumentException) Chapter(com.lowagie.text.Chapter) Section(com.lowagie.text.Section)

Example 12 with Section

use of com.lowagie.text.Section in project vcell by virtualcell.

the class ITextWriter method writeMathDescAsImages.

// container can be a chapter or a section of a chapter.
// MathDescription.description ignored.
// currently not used.
protected void writeMathDescAsImages(Section container, MathDescription mathDesc) throws DocumentException {
    if (mathDesc == null) {
        return;
    }
    Section mathDescSection = container.addSection("Math Description: " + mathDesc.getName(), container.depth() + 1);
    Section mathDescSubSection = null;
    Expression[] expArray = null;
    BufferedImage dummy = new BufferedImage(500, 50, BufferedImage.TYPE_3BYTE_BGR);
    int scale = 1;
    int viewableWidth = (int) (document.getPageSize().width() - document.leftMargin() - document.rightMargin());
    // add Constants
    Enumeration<Constant> constantsList = mathDesc.getConstants();
    while (constantsList.hasMoreElements()) {
        Constant constant = constantsList.nextElement();
        Expression exp = constant.getExpression();
        try {
            expArray = new Expression[] { Expression.assign(new Expression(constant.getName()), exp.flatten()) };
        } catch (ExpressionException ee) {
            System.err.println("Unable to process constant " + constant.getName() + " for publishing");
            ee.printStackTrace();
            continue;
        }
        try {
            Dimension dim = ExpressionCanvas.getExpressionImageSize(expArray, (Graphics2D) dummy.getGraphics());
            BufferedImage bufferedImage = new BufferedImage((int) dim.getWidth() * scale, (int) dim.getHeight() * scale, BufferedImage.TYPE_3BYTE_BGR);
            ExpressionCanvas.getExpressionAsImage(expArray, bufferedImage, scale);
            com.lowagie.text.Image expImage = com.lowagie.text.Image.getInstance(bufferedImage, null);
            expImage.setAlignment(com.lowagie.text.Image.ALIGN_LEFT);
            if (mathDescSubSection == null) {
                mathDescSubSection = mathDescSection.addSection("Constants", mathDescSection.depth() + 1);
            }
            if (viewableWidth < Math.floor(expImage.scaledWidth())) {
                expImage.scaleToFit(viewableWidth, expImage.plainHeight());
                System.out.println("Constant After scaling: " + expImage.scaledWidth());
            }
            mathDescSubSection.add(expImage);
        } catch (Exception e) {
            System.err.println("Unable to add structure mapping image to report.");
            e.printStackTrace();
        }
    }
    mathDescSubSection = null;
    // add functions
    Enumeration<Function> functionsList = mathDesc.getFunctions();
    while (functionsList.hasMoreElements()) {
        Function function = functionsList.nextElement();
        Expression exp = function.getExpression();
        try {
            expArray = new Expression[] { Expression.assign(new Expression(function.getName()), exp.flatten()) };
        } catch (ExpressionException ee) {
            System.err.println("Unable to process function " + function.getName() + " for publishing");
            ee.printStackTrace();
            continue;
        }
        try {
            Dimension dim = ExpressionCanvas.getExpressionImageSize(expArray, (Graphics2D) dummy.getGraphics());
            BufferedImage bufferedImage = new BufferedImage((int) dim.getWidth() * scale, (int) dim.getHeight() * scale, BufferedImage.TYPE_3BYTE_BGR);
            ExpressionCanvas.getExpressionAsImage(expArray, bufferedImage, scale);
            com.lowagie.text.Image expImage = com.lowagie.text.Image.getInstance(bufferedImage, null);
            expImage.setAlignment(com.lowagie.text.Image.ALIGN_LEFT);
            if (mathDescSubSection == null) {
                mathDescSubSection = mathDescSection.addSection("Functions", mathDescSection.depth() + 1);
            }
            if (viewableWidth < Math.floor(expImage.scaledWidth())) {
                expImage.scaleToFit(viewableWidth, expImage.height());
                System.out.println("Function After scaling: " + expImage.scaledWidth());
            }
            mathDescSubSection.add(expImage);
        } catch (Exception e) {
            System.err.println("Unable to add structure mapping image to report.");
            e.printStackTrace();
        }
    }
    writeSubDomainsEquationsAsImages(mathDescSection, mathDesc);
}
Also used : Constant(cbit.vcell.math.Constant) Dimension(java.awt.Dimension) Section(com.lowagie.text.Section) BufferedImage(java.awt.image.BufferedImage) ExpressionException(cbit.vcell.parser.ExpressionException) DocumentException(com.lowagie.text.DocumentException) ExpressionException(cbit.vcell.parser.ExpressionException) Function(cbit.vcell.math.Function) Expression(cbit.vcell.parser.Expression) SimulationContext(cbit.vcell.mapping.SimulationContext) GeometryContext(cbit.vcell.mapping.GeometryContext) ReactionContext(cbit.vcell.mapping.ReactionContext)

Example 13 with Section

use of com.lowagie.text.Section in project vcell by virtualcell.

the class ITextWriter method writeGeom.

// Section used can be a chapter or a section of one, based on the document type.
protected void writeGeom(Section container, Geometry geom, GeometryContext geomCont) throws Exception {
    try {
        Section geomSection = container.addSection("Geometry: " + geom.getName(), container.numberDepth() + 1);
        if (geom.getDimension() == 0) {
            Paragraph p = new Paragraph(new Phrase("Non spatial geometry."));
            p.setAlignment(Paragraph.ALIGN_CENTER);
            geomSection.add(p);
            return;
        }
        ByteArrayOutputStream bos = generateGeometryImage(geom);
        com.lowagie.text.Image geomImage = com.lowagie.text.Image.getInstance(java.awt.Toolkit.getDefaultToolkit().createImage(bos.toByteArray()), null);
        geomImage.setAlignment(Table.ALIGN_LEFT);
        geomSection.add(geomImage);
        // addImage(geomSection, bos);
        Table geomTable = getTable(2, 50, 1, 2, 2);
        geomTable.setAlignment(Table.ALIGN_LEFT);
        Extent extent = geom.getExtent();
        String extentStr = "(" + extent.getX() + ", " + extent.getY() + ", " + extent.getZ() + ")";
        Origin origin = geom.getOrigin();
        String originStr = "(" + origin.getX() + ", " + origin.getY() + ", " + origin.getZ() + ")";
        geomTable.addCell(createCell("Size", getFont()));
        geomTable.addCell(createCell(extentStr, getFont()));
        geomTable.addCell(createCell("Origin", getFont()));
        geomTable.addCell(createCell(originStr, getFont()));
        geomSection.add(geomTable);
    } catch (Exception e) {
        System.err.println("Unable to add geometry image to report.");
        e.printStackTrace();
    }
}
Also used : Origin(org.vcell.util.Origin) Table(com.lowagie.text.Table) Extent(org.vcell.util.Extent) Phrase(com.lowagie.text.Phrase) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SimulationContext(cbit.vcell.mapping.SimulationContext) GeometryContext(cbit.vcell.mapping.GeometryContext) ReactionContext(cbit.vcell.mapping.ReactionContext) Section(com.lowagie.text.Section) DocumentException(com.lowagie.text.DocumentException) ExpressionException(cbit.vcell.parser.ExpressionException) Paragraph(com.lowagie.text.Paragraph)

Example 14 with Section

use of com.lowagie.text.Section in project vcell by virtualcell.

the class ITextWriter method writeStructureMapping.

// boundary types ignored.
protected void writeStructureMapping(Section simContextSection, SimulationContext sc) throws DocumentException {
    GeometryContext gc = sc.getGeometryContext();
    if (gc == null) {
        return;
    }
    Section structMappSection = null;
    /*try {
			ByteArrayOutputStream bos = generateStructureMappingImage(sc);
			com.lowagie.text.Image structMapImage = com.lowagie.text.Image.getInstance(Toolkit.getDefaultToolkit().createImage(bos.toByteArray()), null);
			structMappSection = simContextSection.addSection("Structure Mapping For " + sc.getName(), simContextSection.numberDepth() + 1);
			structMappSection.add(structMapImage);
		} catch (Exception e) {
			System.err.println("Unable to add structure mapping image to report.");
			e.printStackTrace();
		}*/
    StructureMapping[] structMap = gc.getStructureMappings();
    Table structMapTable = null;
    ModelUnitSystem modelUnitSystem = sc.getModel().getUnitSystem();
    for (int i = 0; i < structMap.length; i++) {
        if (!(structMap[i] instanceof FeatureMapping)) {
            continue;
        }
        if (i == 0) {
            structMapTable = getTable(5, 100, 1, 3, 3);
            structMapTable.addCell(createCell("Structure Mapping", getBold(DEF_HEADER_FONT_SIZE), 5, 1, Element.ALIGN_CENTER, true));
            structMapTable.addCell(createHeaderCell("Structure", getBold(), 1));
            structMapTable.addCell(createHeaderCell("Subdomain", getBold(), 1));
            structMapTable.addCell(createHeaderCell("Resolved (T/F)", getBold(), 1));
            structMapTable.addCell(createHeaderCell("Surf/Vol", getBold(), 1));
            structMapTable.addCell(createHeaderCell("VolFract", getBold(), 1));
            structMapTable.endHeaders();
        }
        String structName = structMap[i].getStructure().getName();
        SubVolume subVol = (SubVolume) ((FeatureMapping) structMap[i]).getGeometryClass();
        String subDomain = "";
        if (subVol != null) {
            subDomain = subVol.getName();
        }
        // ((FeatureMapping)structMap[i]).getResolved();
        boolean isResolved = false;
        String surfVolStr = "", volFractStr = "";
        MembraneMapping mm = (MembraneMapping) gc.getStructureMapping(sc.getModel().getStructureTopology().getParentStructure(structMap[i].getStructure()));
        if (mm != null) {
            StructureMapping.StructureMappingParameter smp = mm.getSurfaceToVolumeParameter();
            if (smp != null) {
                Expression tempExp = smp.getExpression();
                VCUnitDefinition tempUnit = smp.getUnitDefinition();
                if (tempExp != null) {
                    surfVolStr = tempExp.infix();
                    if (tempUnit != null && !modelUnitSystem.getInstance_DIMENSIONLESS().compareEqual(tempUnit)) {
                        // no need to add '1' for dimensionless unit
                        surfVolStr += " " + tempUnit.getSymbolUnicode();
                    }
                }
            }
            smp = mm.getVolumeFractionParameter();
            if (smp != null) {
                Expression tempExp = smp.getExpression();
                VCUnitDefinition tempUnit = smp.getUnitDefinition();
                if (tempExp != null) {
                    volFractStr = tempExp.infix();
                    if (tempUnit != null && !modelUnitSystem.getInstance_DIMENSIONLESS().compareEqual(tempUnit)) {
                        volFractStr += " " + tempUnit.getSymbolUnicode();
                    }
                }
            }
        }
        structMapTable.addCell(createCell(structName, getFont()));
        structMapTable.addCell(createCell(subDomain, getFont()));
        structMapTable.addCell(createCell((isResolved ? " T " : " F "), getFont()));
        structMapTable.addCell(createCell(surfVolStr, getFont()));
        structMapTable.addCell(createCell(volFractStr, getFont()));
    }
    if (structMapTable != null) {
        if (structMappSection == null) {
            structMappSection = simContextSection.addSection("Structure Mapping For " + sc.getName(), simContextSection.numberDepth() + 1);
        }
        structMappSection.add(structMapTable);
    }
}
Also used : MembraneMapping(cbit.vcell.mapping.MembraneMapping) Table(com.lowagie.text.Table) Section(com.lowagie.text.Section) StructureMapping(cbit.vcell.mapping.StructureMapping) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) FeatureMapping(cbit.vcell.mapping.FeatureMapping) Expression(cbit.vcell.parser.Expression) SubVolume(cbit.vcell.geometry.SubVolume) GeometryContext(cbit.vcell.mapping.GeometryContext) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 15 with Section

use of com.lowagie.text.Section in project vcell by virtualcell.

the class ITextWriter method writeMathModel.

public void writeMathModel(MathModel mathModel, FileOutputStream fos, PageFormat pageFormat, PublishPreferences preferences) throws Exception {
    if (mathModel == null || fos == null || pageFormat == null || preferences == null) {
        throw new IllegalArgumentException("One or more null params while publishing MathModel.");
    }
    try {
        createDocument(pageFormat);
        createDocWriter(fos);
        // Add metadata before you open the document...
        String name = mathModel.getName().trim();
        String userName = "Unknown";
        if (mathModel.getVersion() != null) {
            userName = mathModel.getVersion().getOwner().getName();
        }
        document.addTitle(name + "[owned by " + userName + "]");
        document.addCreator("Virtual Cell");
        document.addCreationDate();
        // writeWatermark(document, pageFormat);
        writeHeaderFooter("MathModel: " + name);
        document.open();
        // 
        int chapterNum = 1;
        Section introSection = null;
        if (preferences.includeMathDesc()) {
            MathDescription mathDesc = mathModel.getMathDescription();
            Chapter mathDescChapter = new Chapter("Math Description", chapterNum++);
            introSection = mathDescChapter.addSection("General Info", mathDescChapter.numberDepth() + 1);
            writeMetadata(introSection, name, mathModel.getDescription(), userName, "MathModel");
            writeMathDescAsText(mathDescChapter, mathDesc);
            document.add(mathDescChapter);
        }
        if (preferences.includeSim()) {
            // unlike biomodels, simulations are chapters, not chapter sections.
            Simulation[] sims = mathModel.getSimulations();
            if (sims != null) {
                Chapter simChapter = new Chapter("Simulations", chapterNum++);
                if (introSection == null) {
                    introSection = simChapter.addSection("General Info", simChapter.numberDepth() + 1);
                    writeMetadata(introSection, name, mathModel.getDescription(), userName, "MathModel");
                }
                for (int i = 0; i < sims.length; i++) {
                    writeSimulation(simChapter, sims[i]);
                }
                document.add(simChapter);
            } else {
                System.err.println("Bad Request: No simulations to publish for Mathmodel: " + name);
            }
        }
        if (preferences.includeGeom()) {
            // unlike biomodels, geometry is a chapter, not a chapter section.
            Geometry geom = mathModel.getMathDescription().getGeometry();
            if (geom != null) {
                Chapter geomChapter = new Chapter("Geometry", chapterNum++);
                if (introSection == null) {
                    introSection = geomChapter.addSection("General Info", geomChapter.numberDepth() + 1);
                    writeMetadata(introSection, name, mathModel.getDescription(), userName, "MathModel");
                }
                writeGeom(geomChapter, geom, null);
                document.add(geomChapter);
            } else {
                System.err.println("Bad Request: No geometry to publish for Mathmodel: " + name);
            }
        }
        document.close();
    } catch (DocumentException e) {
        System.err.println("Unable to publish MathModel.");
        e.printStackTrace();
        throw e;
    }
}
Also used : Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) MathDescription(cbit.vcell.math.MathDescription) DocumentException(com.lowagie.text.DocumentException) Chapter(com.lowagie.text.Chapter) Section(com.lowagie.text.Section)

Aggregations

Section (com.lowagie.text.Section)15 Table (com.lowagie.text.Table)8 DocumentException (com.lowagie.text.DocumentException)7 Expression (cbit.vcell.parser.Expression)6 GeometryContext (cbit.vcell.mapping.GeometryContext)5 ReactionContext (cbit.vcell.mapping.ReactionContext)4 SimulationContext (cbit.vcell.mapping.SimulationContext)4 ExpressionException (cbit.vcell.parser.ExpressionException)4 Constant (cbit.vcell.math.Constant)3 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)3 Chapter (com.lowagie.text.Chapter)3 Geometry (cbit.vcell.geometry.Geometry)2 FeatureMapping (cbit.vcell.mapping.FeatureMapping)2 MembraneMapping (cbit.vcell.mapping.MembraneMapping)2 SpeciesContextSpecParameter (cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)2 StructureMapping (cbit.vcell.mapping.StructureMapping)2 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)2 Equation (cbit.vcell.math.Equation)2 FilamentRegionEquation (cbit.vcell.math.FilamentRegionEquation)2 FilamentSubDomain (cbit.vcell.math.FilamentSubDomain)2