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;
}
}
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);
}
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();
}
}
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);
}
}
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;
}
}
Aggregations