View Javadoc
1   /******************************************************************************
2    * PosterManager.java - Setup for building Posters
3    * 
4    * PicMan - The BuckoSoft Picture Manager in Java
5    * Copyright(c) 2012 - Dick Balaska
6    * 
7    */
8   package com.buckosoft.PicMan.business;
9   
10  import java.util.LinkedList;
11  import java.util.List;
12  
13  import org.apache.commons.logging.Log;
14  import org.apache.commons.logging.LogFactory;
15  
16  import com.buckosoft.PicMan.domain.ContactParams;
17  import com.buckosoft.PicMan.domain.Mosaic;
18  import com.buckosoft.PicMan.domain.Pic;
19  import com.buckosoft.PicMan.domain.Poster;
20  import com.buckosoft.PicMan.domain.PosterParams;
21  
22  
23  /**Poster Manager.  Setup to get Posters built.
24   * <pre>
25   *     +------ Paper Width * DPI ----- +
26   * +---+    L     Overspray     R      +----+
27   * +-+      L       Margin      R        +--+
28   *   +--------   Project Width ----------+</pre>
29   * <ul>
30   * <li> jpeg size is PaperWidth*DPI + Overspray LR
31   * <li> Project Width = jpeg size - Margin LR
32   * <li> Use the calibration sheet to determine values for Overspray and Margin
33   * <li> My working values PrintableWidth = PaperWidth*DPI + OL+OR -ML-MR
34   * <li> = x =  
35   * </ul>
36   * @author Dick Balaska
37   * @since 2012/08/17
38   * @version $Revision: 1.1 $ <br> $Date: 2013/12/26 01:26:08 $
39   * @see <a href="http://cvs.buckosoft.com/Projects/java/PicMan/PicMan/src/com/buckosoft/PicMan/business/PosterManager.java">PosterManager.java</a>
40   */
41  public class PosterManager {
42  	private final Log log = LogFactory.getLog(getClass());
43  
44  	private	PicManFacade	pmf;
45  	
46  	/** Set the reference to the primary PicMan api.
47  	 * @param pmf The one and only PicManFacade
48  	 */
49  	public	void setPicMan(PicManFacade pmf) {
50  		this.pmf = pmf;
51  	}
52  
53  	/** Construct a PosterParams from this Poster
54  	 * @param poster The Poster to use as our basis
55  	 * @return a new PosterParams
56  	 */
57  	public PosterParams getPosterParams(Poster poster) {
58  		PosterParams pp = new PosterParams();
59  		pp.setPoster(poster);
60  		pp.setEngineName("Poster");
61  		pp.setSetName(poster.getName());
62  		pp.setOutputDirectory(poster.getOutputPath());
63  		return(pp);
64  	}
65  
66  	/** Calculate the parameters to build this Poster
67  	 * @param pp The PosterParams to fill out.
68  	 */
69  	public void determineProjectBuild(PosterParams pp) {
70  		Poster p = pp.getPoster();
71  		Mosaic m = pmf.getDB().getMosaic(p.getMasterMid());
72  		if (m != null) {
73  			Pic pic = pmf.getDB().getPic(m.getMasterPic());
74  			if (pic != null) {
75  				pp.getMasterPicXY().x = pic.getWidth();
76  				pp.getMasterPicXY().y = pic.getHeight();
77  			} else {
78  				return;
79  			}
80  		} else {
81  			return;
82  		}
83  		// get the number of inches needed
84  		p.setProjectWidth (pp.getMasterPicXY().x * p.getMultiplier() / p.getDpi());
85  		p.setProjectHeight(pp.getMasterPicXY().y * p.getMultiplier() / p.getDpi());
86  		log.debug("Project w/h = " + p.getProjectWidth() + "/" + p.getProjectHeight());
87  		// get the number of sheets in the project
88  		pp.getSheetsXY().x = (int)(p.getProjectWidth() / p.getPaperWidth())+1;
89  		pp.getSheetsXY().y = (int)(p.getProjectHeight() / p.getPaperHeight())+1;
90  
91  		int pixelsPerPageX = (int)(p.getPaperWidth() *p.getDpi()+p.getOverSprayL()+p.getOverSprayR()-p.getMarginL()-p.getMarginR());
92  		int pixelsPerPageY = (int)(p.getPaperHeight()*p.getDpi()+p.getOverSprayT()+p.getOverSprayB()-p.getMarginT()-p.getMarginB());
93  		// get the starting offset
94  		pp.getGeneratedOffsetXY().x = -(int)(((pp.getSheetsXY().x*pixelsPerPageX)  - (p.getProjectWidth()*p.getDpi()))  / 2.0); 
95  		pp.getGeneratedOffsetXY().y = -(int)(((pp.getSheetsXY().y*pixelsPerPageY) - (p.getProjectHeight()*p.getDpi())) / 2.0);
96  		log.debug("GenXY = " + pp.getGeneratedOffsetXY().x + "/" + pp.getGeneratedOffsetXY().y);
97  	}
98  	
99  	/** Given a Poster, chop it up into several PosterParams and submit them to the BatchManager for construction
100 	 * @param p The Poster to build
101 	 * @throws CloneNotSupportedException Yeah, not really.
102 	 */
103 	public void buildPoster(Poster p, boolean calibration) throws CloneNotSupportedException {
104 		PosterParams pp = getPosterParams(p);
105 		determineProjectBuild(pp);
106 		List<ContactParams> spinList = new LinkedList<ContactParams>();
107 		if (calibration) {
108 			pp.setCalibration();
109 			spinList.add(pp);
110 		} else {
111 			int pixelsPerPageX = (int)(p.getPaperWidth() *p.getDpi()+p.getOverSprayL()+p.getOverSprayR()-p.getMarginL()-p.getMarginR());
112 			int pixelsPerPageY = (int)(p.getPaperHeight()*p.getDpi()+p.getOverSprayT()+p.getOverSprayB()-p.getMarginT()-p.getMarginB());
113 			int sheet=-1;
114 			for (int y=0; y<pp.getSheetsXY().y; y++) {
115 				for (int x=0; x<pp.getSheetsXY().x; x++) {
116 					sheet++;
117 					PosterParams pp0 = pp.clone();
118 					pp0.getSheetXY().x = x;
119 					pp0.getSheetXY().y = y;
120 					pp0.getGeneratedOffsetXY().x = pp.getGeneratedOffsetXY().x + (x * pixelsPerPageX);
121 					pp0.getGeneratedOffsetXY().y = pp.getGeneratedOffsetXY().y + (y * pixelsPerPageY);
122 					log.debug("sheet-" + sheet + " " + x + "/" + y + " genXY = " +  pp0.getGeneratedOffsetXY().x + "/" + pp0.getGeneratedOffsetXY().y);
123 					pp0.setContactNumber(y*pp.getSheetsXY().x+x);
124 //					if (sheet<6)
125 //						continue;
126 					spinList.add(pp0);
127 				}
128 			}
129 		}
130 		pmf.getBatchManager().getContactManager().addSpin(spinList);
131 	}
132 }