2017-02-01 18:55:51 +00:00
|
|
|
/* ========================================================================
|
|
|
|
* PlantUML : a free UML diagram generator
|
|
|
|
* ========================================================================
|
|
|
|
*
|
2019-01-16 18:34:41 +00:00
|
|
|
* (C) Copyright 2009-2020, Arnaud Roques
|
2017-02-01 18:55:51 +00:00
|
|
|
*
|
|
|
|
* Project Info: http://plantuml.com
|
|
|
|
*
|
2017-03-15 19:13:31 +00:00
|
|
|
* If you like this project or if you find it useful, you can support us at:
|
|
|
|
*
|
|
|
|
* http://plantuml.com/patreon (only 1$ per month!)
|
|
|
|
* http://plantuml.com/paypal
|
|
|
|
*
|
2017-02-01 18:55:51 +00:00
|
|
|
* This file is part of PlantUML.
|
|
|
|
*
|
|
|
|
* PlantUML is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* PlantUML distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
|
|
* License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Original Author: Arnaud Roques
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2020-02-18 21:24:31 +00:00
|
|
|
package net.sourceforge.plantuml.project;
|
2017-02-01 18:55:51 +00:00
|
|
|
|
2019-04-21 20:40:01 +00:00
|
|
|
import java.awt.geom.Dimension2D;
|
|
|
|
import java.awt.geom.Rectangle2D;
|
2017-02-01 18:55:51 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.util.ArrayList;
|
2018-04-06 20:36:30 +00:00
|
|
|
import java.util.Collection;
|
2020-11-21 17:33:24 +00:00
|
|
|
import java.util.Collections;
|
2017-02-26 16:26:11 +00:00
|
|
|
import java.util.HashMap;
|
2017-02-01 18:55:51 +00:00
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2019-02-09 21:56:24 +00:00
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
2017-02-01 18:55:51 +00:00
|
|
|
|
2019-04-21 20:40:01 +00:00
|
|
|
import net.sourceforge.plantuml.AnnotatedWorker;
|
|
|
|
import net.sourceforge.plantuml.Dimension2DDouble;
|
2017-02-01 18:55:51 +00:00
|
|
|
import net.sourceforge.plantuml.FileFormatOption;
|
2018-01-28 22:08:15 +00:00
|
|
|
import net.sourceforge.plantuml.Scale;
|
2019-04-21 20:40:01 +00:00
|
|
|
import net.sourceforge.plantuml.SkinParam;
|
|
|
|
import net.sourceforge.plantuml.TitledDiagram;
|
|
|
|
import net.sourceforge.plantuml.UmlDiagramType;
|
2020-12-01 21:39:27 +00:00
|
|
|
import net.sourceforge.plantuml.UseStyle;
|
2020-09-30 20:57:58 +00:00
|
|
|
import net.sourceforge.plantuml.WithSprite;
|
2019-02-09 21:56:24 +00:00
|
|
|
import net.sourceforge.plantuml.command.CommandExecutionResult;
|
2017-02-01 18:55:51 +00:00
|
|
|
import net.sourceforge.plantuml.core.DiagramDescription;
|
|
|
|
import net.sourceforge.plantuml.core.ImageData;
|
2020-08-25 17:24:17 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.Display;
|
2019-04-21 20:40:01 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.InnerStrategy;
|
|
|
|
import net.sourceforge.plantuml.graphic.StringBounder;
|
2017-02-01 18:55:51 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.TextBlock;
|
2020-02-18 21:24:31 +00:00
|
|
|
import net.sourceforge.plantuml.project.core.Moment;
|
|
|
|
import net.sourceforge.plantuml.project.core.MomentImpl;
|
|
|
|
import net.sourceforge.plantuml.project.core.PrintScale;
|
|
|
|
import net.sourceforge.plantuml.project.core.Resource;
|
|
|
|
import net.sourceforge.plantuml.project.core.Task;
|
|
|
|
import net.sourceforge.plantuml.project.core.TaskAttribute;
|
|
|
|
import net.sourceforge.plantuml.project.core.TaskCode;
|
|
|
|
import net.sourceforge.plantuml.project.core.TaskImpl;
|
|
|
|
import net.sourceforge.plantuml.project.core.TaskInstant;
|
|
|
|
import net.sourceforge.plantuml.project.core.TaskSeparator;
|
2020-09-19 15:43:24 +00:00
|
|
|
import net.sourceforge.plantuml.project.draw.FingerPrint;
|
2020-02-18 21:24:31 +00:00
|
|
|
import net.sourceforge.plantuml.project.draw.ResourceDraw;
|
|
|
|
import net.sourceforge.plantuml.project.draw.TaskDraw;
|
2020-03-18 10:50:02 +00:00
|
|
|
import net.sourceforge.plantuml.project.draw.TaskDrawDiamond;
|
2020-02-18 21:24:31 +00:00
|
|
|
import net.sourceforge.plantuml.project.draw.TaskDrawRegular;
|
|
|
|
import net.sourceforge.plantuml.project.draw.TaskDrawSeparator;
|
|
|
|
import net.sourceforge.plantuml.project.draw.TimeHeader;
|
|
|
|
import net.sourceforge.plantuml.project.draw.TimeHeaderDaily;
|
2020-03-18 10:50:02 +00:00
|
|
|
import net.sourceforge.plantuml.project.draw.TimeHeaderMonthly;
|
2020-02-18 21:24:31 +00:00
|
|
|
import net.sourceforge.plantuml.project.draw.TimeHeaderSimple;
|
|
|
|
import net.sourceforge.plantuml.project.draw.TimeHeaderWeekly;
|
2020-08-25 17:24:17 +00:00
|
|
|
import net.sourceforge.plantuml.project.lang.CenterBorderColor;
|
2020-03-18 10:50:02 +00:00
|
|
|
import net.sourceforge.plantuml.project.time.Day;
|
|
|
|
import net.sourceforge.plantuml.project.time.DayOfWeek;
|
2020-02-18 21:24:31 +00:00
|
|
|
import net.sourceforge.plantuml.project.timescale.TimeScale;
|
2020-05-07 14:12:08 +00:00
|
|
|
import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft;
|
2021-01-08 01:56:09 +00:00
|
|
|
import net.sourceforge.plantuml.style.PName;
|
|
|
|
import net.sourceforge.plantuml.style.SName;
|
|
|
|
import net.sourceforge.plantuml.style.Style;
|
|
|
|
import net.sourceforge.plantuml.style.StyleSignature;
|
2019-04-21 20:40:01 +00:00
|
|
|
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
|
2017-02-01 18:55:51 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
|
2020-12-06 21:43:09 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.ImageParameter;
|
2019-04-21 20:40:01 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.MinMax;
|
2017-02-01 18:55:51 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.UGraphic;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UTranslate;
|
2020-03-18 10:50:02 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.color.ColorMapperIdentity;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.color.HColor;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.color.HColorSet;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
|
2017-02-01 18:55:51 +00:00
|
|
|
|
2020-09-30 20:57:58 +00:00
|
|
|
public class GanttDiagram extends TitledDiagram implements ToTaskDraw, WithSprite {
|
2017-02-01 18:55:51 +00:00
|
|
|
|
2020-11-21 17:33:24 +00:00
|
|
|
private final Map<Task, TaskDraw> draws = new LinkedHashMap<Task, TaskDraw>();
|
2017-02-01 18:55:51 +00:00
|
|
|
private final Map<TaskCode, Task> tasks = new LinkedHashMap<TaskCode, Task>();
|
2017-02-26 16:26:11 +00:00
|
|
|
private final Map<String, Task> byShortName = new HashMap<String, Task>();
|
2017-02-01 18:55:51 +00:00
|
|
|
private final List<GanttConstraint> constraints = new ArrayList<GanttConstraint>();
|
2020-03-18 10:50:02 +00:00
|
|
|
private final HColorSet colorSet = HColorSet.instance();
|
2020-02-18 21:24:31 +00:00
|
|
|
|
2020-11-21 17:33:24 +00:00
|
|
|
private final OpenClose openClose = new OpenClose();
|
2020-02-18 21:24:31 +00:00
|
|
|
|
|
|
|
private final Map<String, Resource> resources = new LinkedHashMap<String, Resource>();
|
2020-03-18 10:50:02 +00:00
|
|
|
private final Map<Day, HColor> colorDays = new HashMap<Day, HColor>();
|
2021-01-08 03:16:04 +00:00
|
|
|
private final Map<DayOfWeek, HColor> colorDaysOfWeek = new HashMap<DayOfWeek, HColor>();
|
2020-03-18 10:50:02 +00:00
|
|
|
private final Map<Day, String> nameDays = new HashMap<Day, String>();
|
2020-02-18 21:24:31 +00:00
|
|
|
|
|
|
|
private PrintScale printScale = PrintScale.DAILY;
|
2020-03-18 10:50:02 +00:00
|
|
|
private Day today;
|
2020-11-21 17:33:24 +00:00
|
|
|
private double totalHeightWithoutFooter;
|
2020-09-30 20:57:58 +00:00
|
|
|
private Day min = Day.create(0);
|
|
|
|
private Day max;
|
2017-02-26 16:26:11 +00:00
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
private Day printStart;
|
|
|
|
private Day printEnd;
|
2017-02-01 18:55:51 +00:00
|
|
|
|
2021-01-10 20:52:19 +00:00
|
|
|
private HColor linksColor = null;
|
2020-08-25 17:24:17 +00:00
|
|
|
|
2017-02-01 18:55:51 +00:00
|
|
|
public DiagramDescription getDescription() {
|
2017-03-12 17:22:02 +00:00
|
|
|
return new DiagramDescription("(Project)");
|
2017-02-01 18:55:51 +00:00
|
|
|
}
|
|
|
|
|
2021-01-10 20:52:19 +00:00
|
|
|
public GanttDiagram() {
|
|
|
|
super(UmlDiagramType.GANTT);
|
2020-08-25 17:24:17 +00:00
|
|
|
}
|
|
|
|
|
2018-04-06 20:36:30 +00:00
|
|
|
private int horizontalPages = 1;
|
|
|
|
private int verticalPages = 1;
|
|
|
|
|
|
|
|
final public int getHorizontalPages() {
|
|
|
|
return horizontalPages;
|
|
|
|
}
|
|
|
|
|
|
|
|
final public void setHorizontalPages(int horizontalPages) {
|
|
|
|
this.horizontalPages = horizontalPages;
|
|
|
|
}
|
|
|
|
|
|
|
|
final public int getVerticalPages() {
|
|
|
|
return verticalPages;
|
|
|
|
}
|
|
|
|
|
|
|
|
final public void setVerticalPages(int verticalPages) {
|
|
|
|
this.verticalPages = verticalPages;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getNbImages() {
|
|
|
|
return this.horizontalPages * this.verticalPages;
|
|
|
|
}
|
|
|
|
|
|
|
|
public final int getDpi(FileFormatOption fileFormatOption) {
|
|
|
|
return 96;
|
|
|
|
}
|
|
|
|
|
2017-02-01 18:55:51 +00:00
|
|
|
@Override
|
2017-04-19 18:30:16 +00:00
|
|
|
protected ImageData exportDiagramNow(OutputStream os, int index, FileFormatOption fileFormatOption, long seed)
|
2017-02-01 18:55:51 +00:00
|
|
|
throws IOException {
|
2018-01-28 22:08:15 +00:00
|
|
|
final Scale scale = getScale();
|
2017-02-01 18:55:51 +00:00
|
|
|
|
2020-05-07 14:12:08 +00:00
|
|
|
final int margin1;
|
|
|
|
final int margin2;
|
2020-12-01 21:39:27 +00:00
|
|
|
if (UseStyle.useBetaStyle()) {
|
2020-05-07 14:12:08 +00:00
|
|
|
margin1 = SkinParam.zeroMargin(0);
|
|
|
|
margin2 = SkinParam.zeroMargin(0);
|
|
|
|
} else {
|
|
|
|
margin1 = 0;
|
|
|
|
margin2 = 0;
|
|
|
|
}
|
2018-01-28 22:08:15 +00:00
|
|
|
final double dpiFactor = scale == null ? 1 : scale.getScale(100, 100);
|
2020-12-06 21:43:09 +00:00
|
|
|
final ClockwiseTopRightBottomLeft margins = ClockwiseTopRightBottomLeft.margin1margin2(margin1, margin2);
|
|
|
|
final ImageParameter imageParameter = new ImageParameter(new ColorMapperIdentity(), false, null, dpiFactor,
|
|
|
|
getMetadata(), "", margins, null);
|
2019-04-21 20:40:01 +00:00
|
|
|
|
2020-12-06 21:43:09 +00:00
|
|
|
final ImageBuilder imageBuilder = ImageBuilder.build(imageParameter);
|
|
|
|
|
|
|
|
final StringBounder stringBounder = fileFormatOption.getDefaultStringBounder(getSkinParam());
|
|
|
|
TextBlock result = getTextBlock(stringBounder);
|
|
|
|
result = new AnnotatedWorker(this, getSkinParam(), stringBounder).addAdd(result);
|
2017-11-20 16:10:36 +00:00
|
|
|
imageBuilder.setUDrawable(result);
|
2017-02-01 18:55:51 +00:00
|
|
|
|
2017-04-19 18:30:16 +00:00
|
|
|
return imageBuilder.writeImageTOBEMOVED(fileFormatOption, seed, os);
|
2017-02-01 18:55:51 +00:00
|
|
|
}
|
|
|
|
|
2020-02-18 21:24:31 +00:00
|
|
|
public void setPrintScale(PrintScale printScale) {
|
|
|
|
this.printScale = printScale;
|
|
|
|
}
|
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
private boolean isHidden(Task task) {
|
2020-04-05 15:13:04 +00:00
|
|
|
if (printStart == null || task instanceof TaskSeparator) {
|
2020-03-18 10:50:02 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (task.getEnd().compareTo(min) < 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (task.getStart().compareTo(max) > 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-09-19 15:43:24 +00:00
|
|
|
private TextBlockBackcolored getTextBlock(StringBounder stringBounder) {
|
2020-02-18 21:24:31 +00:00
|
|
|
if (printStart == null) {
|
|
|
|
initMinMax();
|
|
|
|
} else {
|
2020-09-30 20:57:58 +00:00
|
|
|
this.min = printStart;
|
|
|
|
this.max = printEnd;
|
2020-02-18 21:24:31 +00:00
|
|
|
}
|
2020-11-21 17:33:24 +00:00
|
|
|
final TimeHeader timeHeader = getTimeHeader();
|
2020-09-19 15:43:24 +00:00
|
|
|
initTaskAndResourceDraws(timeHeader.getTimeScale(), timeHeader.getFullHeaderHeight(), stringBounder);
|
2019-04-21 20:40:01 +00:00
|
|
|
return new TextBlockBackcolored() {
|
|
|
|
|
2017-02-01 18:55:51 +00:00
|
|
|
public void drawU(UGraphic ug) {
|
2020-11-21 17:33:24 +00:00
|
|
|
timeHeader.drawTimeHeader(ug, totalHeightWithoutFooter);
|
2020-02-18 21:24:31 +00:00
|
|
|
drawConstraints(ug, timeHeader.getTimeScale());
|
|
|
|
drawTasksRect(ug);
|
|
|
|
drawTasksTitle(ug);
|
2020-05-17 21:15:50 +00:00
|
|
|
drawResources(ug);
|
2020-11-21 17:33:24 +00:00
|
|
|
if (showFootbox) {
|
|
|
|
timeHeader.drawTimeFooter(ug.apply(UTranslate.dy(totalHeightWithoutFooter)));
|
|
|
|
}
|
2017-02-01 18:55:51 +00:00
|
|
|
}
|
2019-04-21 20:40:01 +00:00
|
|
|
|
|
|
|
public Rectangle2D getInnerPosition(String member, StringBounder stringBounder, InnerStrategy strategy) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Dimension2D calculateDimension(StringBounder stringBounder) {
|
2020-02-18 21:24:31 +00:00
|
|
|
final double xmin = timeHeader.getTimeScale().getStartingPosition(min);
|
|
|
|
final double xmax = timeHeader.getTimeScale().getEndingPosition(max);
|
2020-11-21 17:33:24 +00:00
|
|
|
return new Dimension2DDouble(xmax - xmin, getTotalHeight(timeHeader));
|
2019-04-21 20:40:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public MinMax getMinMax(StringBounder stringBounder) {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
public HColor getBackcolor() {
|
2019-04-21 20:40:01 +00:00
|
|
|
return null;
|
|
|
|
}
|
2017-02-01 18:55:51 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-21 17:33:24 +00:00
|
|
|
private TimeHeader getTimeHeader() {
|
|
|
|
if (openClose.getCalendar() == null) {
|
|
|
|
return new TimeHeaderSimple(min, max);
|
|
|
|
} else if (printScale == PrintScale.WEEKLY) {
|
2021-01-10 20:52:19 +00:00
|
|
|
return new TimeHeaderWeekly(openClose.getCalendar(), min, max, openClose, colorDays, colorDaysOfWeek,
|
|
|
|
nameDays);
|
2020-11-21 17:33:24 +00:00
|
|
|
} else if (printScale == PrintScale.MONTHLY) {
|
2021-01-10 20:52:19 +00:00
|
|
|
return new TimeHeaderMonthly(openClose.getCalendar(), min, max, openClose, colorDays, colorDaysOfWeek,
|
|
|
|
nameDays);
|
2020-11-21 17:33:24 +00:00
|
|
|
} else {
|
2021-01-10 20:52:19 +00:00
|
|
|
return new TimeHeaderDaily(openClose.getCalendar(), min, max, openClose, colorDays, colorDaysOfWeek,
|
|
|
|
nameDays, printStart, printEnd);
|
2020-11-21 17:33:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private double getTotalHeight(TimeHeader timeHeader) {
|
|
|
|
if (showFootbox) {
|
|
|
|
return totalHeightWithoutFooter + timeHeader.getTimeFooterHeight();
|
|
|
|
}
|
|
|
|
return totalHeightWithoutFooter;
|
|
|
|
}
|
|
|
|
|
2020-02-18 21:24:31 +00:00
|
|
|
private void drawTasksRect(UGraphic ug) {
|
|
|
|
for (Task task : tasks.values()) {
|
2020-11-21 17:33:24 +00:00
|
|
|
if (isHidden(task)) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-03-18 10:50:02 +00:00
|
|
|
final TaskDraw draw = draws.get(task);
|
2020-09-30 20:57:58 +00:00
|
|
|
final UTranslate move = UTranslate.dy(draw.getY());
|
2020-02-18 21:24:31 +00:00
|
|
|
draw.drawU(ug.apply(move));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void drawConstraints(final UGraphic ug, TimeScale timeScale) {
|
|
|
|
for (GanttConstraint constraint : constraints) {
|
2020-03-18 10:50:02 +00:00
|
|
|
if (printStart != null && constraint.isHidden(min, max)) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-01-10 20:52:19 +00:00
|
|
|
constraint.getUDrawable(timeScale, getLinkColor(), this).drawU(ug);
|
2018-04-06 20:36:30 +00:00
|
|
|
}
|
2021-01-10 20:52:19 +00:00
|
|
|
|
2017-03-12 17:22:02 +00:00
|
|
|
}
|
|
|
|
|
2021-01-08 01:56:09 +00:00
|
|
|
private HColor getLinkColor() {
|
2021-01-10 20:52:19 +00:00
|
|
|
if (linksColor == null) {
|
|
|
|
final Style styleArrow = getDefaultStyleDefinitionArrow().getMergedStyle(getCurrentStyleBuilder());
|
|
|
|
return styleArrow.value(PName.LineColor).asColor(colorSet);
|
|
|
|
}
|
|
|
|
return linksColor;
|
2021-01-08 01:56:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public StyleSignature getDefaultStyleDefinitionArrow() {
|
|
|
|
return StyleSignature.of(SName.root, SName.element, SName.ganttDiagram, SName.arrow);
|
|
|
|
}
|
|
|
|
|
2020-02-18 21:24:31 +00:00
|
|
|
private void drawTasksTitle(final UGraphic ug1) {
|
|
|
|
for (Task task : tasks.values()) {
|
2020-03-18 10:50:02 +00:00
|
|
|
if (isHidden(task)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
final TaskDraw draw = draws.get(task);
|
2020-09-30 20:57:58 +00:00
|
|
|
final UTranslate move = UTranslate.dy(draw.getY());
|
2020-02-18 21:24:31 +00:00
|
|
|
draw.drawTitle(ug1.apply(move));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void drawResources(UGraphic ug) {
|
|
|
|
for (Resource res : resources.values()) {
|
|
|
|
final ResourceDraw draw = res.getResourceDraw();
|
2020-03-18 10:50:02 +00:00
|
|
|
final UTranslate move = UTranslate.dy(draw.getY());
|
2020-02-18 21:24:31 +00:00
|
|
|
draw.drawU(ug.apply(move));
|
|
|
|
}
|
2018-04-06 20:36:30 +00:00
|
|
|
}
|
|
|
|
|
2018-12-22 11:11:40 +00:00
|
|
|
public void closeDayOfWeek(DayOfWeek day) {
|
2020-11-21 17:33:24 +00:00
|
|
|
openClose.close(day);
|
2018-12-22 11:11:40 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
public void closeDayAsDate(Day day) {
|
2020-11-21 17:33:24 +00:00
|
|
|
openClose.close(day);
|
2018-12-22 11:11:40 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
public void openDayAsDate(Day day) {
|
2020-11-21 17:33:24 +00:00
|
|
|
openClose.open(day);
|
2018-12-22 11:11:40 +00:00
|
|
|
}
|
|
|
|
|
2020-09-19 15:43:24 +00:00
|
|
|
private void initTaskAndResourceDraws(TimeScale timeScale, double headerHeight, StringBounder stringBounder) {
|
2020-09-30 20:57:58 +00:00
|
|
|
double y = headerHeight;
|
2017-02-26 16:26:11 +00:00
|
|
|
for (Task task : tasks.values()) {
|
2018-04-06 20:36:30 +00:00
|
|
|
final TaskDraw draw;
|
|
|
|
if (task instanceof TaskSeparator) {
|
2020-08-25 17:24:17 +00:00
|
|
|
draw = new TaskDrawSeparator(((TaskSeparator) task).getName(), timeScale, y, min, max);
|
2018-04-06 20:36:30 +00:00
|
|
|
} else {
|
2020-03-18 10:50:02 +00:00
|
|
|
final TaskImpl tmp = (TaskImpl) task;
|
|
|
|
if (tmp.isDiamond()) {
|
2020-08-25 17:24:17 +00:00
|
|
|
draw = new TaskDrawDiamond(timeScale, y, tmp.getPrettyDisplay(), getStart(tmp), getSkinParam(),
|
|
|
|
task, this);
|
2020-03-18 10:50:02 +00:00
|
|
|
} else {
|
|
|
|
final boolean oddStart = printStart != null && min.compareTo(getStart(tmp)) == 0;
|
|
|
|
final boolean oddEnd = printStart != null && max.compareTo(getEnd(tmp)) == 0;
|
2020-08-25 17:24:17 +00:00
|
|
|
draw = new TaskDrawRegular(timeScale, y, tmp.getPrettyDisplay(), getStart(tmp), getEnd(tmp),
|
2020-11-21 17:33:24 +00:00
|
|
|
oddStart, oddEnd, getSkinParam(), task, this, getConstraints(task));
|
2020-03-18 10:50:02 +00:00
|
|
|
}
|
2020-08-25 17:24:17 +00:00
|
|
|
draw.setColorsAndCompletion(tmp.getColors(), tmp.getCompletion(), tmp.getUrl(), tmp.getNote());
|
|
|
|
}
|
|
|
|
if (task.getRow() == null) {
|
2020-09-30 20:57:58 +00:00
|
|
|
y += draw.getHeightTask();
|
2018-04-06 20:36:30 +00:00
|
|
|
}
|
2020-03-18 10:50:02 +00:00
|
|
|
draws.put(task, draw);
|
2018-04-06 20:36:30 +00:00
|
|
|
}
|
2020-09-30 20:57:58 +00:00
|
|
|
while (magicPushOnce(stringBounder)) {
|
|
|
|
//
|
2020-09-19 15:43:24 +00:00
|
|
|
}
|
2020-09-30 20:57:58 +00:00
|
|
|
if (lastY(stringBounder) != 0) {
|
|
|
|
y = lastY(stringBounder);
|
|
|
|
for (Resource res : resources.values()) {
|
|
|
|
final ResourceDraw draw = new ResourceDraw(this, res, timeScale, y, min, max);
|
|
|
|
res.setTaskDraw(draw);
|
|
|
|
y += draw.getHeight();
|
|
|
|
}
|
|
|
|
}
|
2020-11-21 17:33:24 +00:00
|
|
|
this.totalHeightWithoutFooter = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
private Collection<GanttConstraint> getConstraints(Task task) {
|
|
|
|
final List<GanttConstraint> result = new ArrayList<GanttConstraint>();
|
|
|
|
for (GanttConstraint constraint : constraints) {
|
|
|
|
if (constraint.isOn(task)) {
|
|
|
|
result.add(constraint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Collections.unmodifiableCollection(result);
|
2020-09-19 15:43:24 +00:00
|
|
|
}
|
2018-04-06 20:36:30 +00:00
|
|
|
|
2020-09-30 20:57:58 +00:00
|
|
|
private double lastY(StringBounder stringBounder) {
|
2020-11-21 17:33:24 +00:00
|
|
|
double result = 0;
|
2020-09-19 15:43:24 +00:00
|
|
|
for (TaskDraw td : draws.values()) {
|
2020-11-21 17:33:24 +00:00
|
|
|
result = Math.max(result, td.getY() + td.getHeightMax(stringBounder));
|
2020-09-30 20:57:58 +00:00
|
|
|
}
|
2020-11-21 17:33:24 +00:00
|
|
|
return result;
|
2020-09-19 15:43:24 +00:00
|
|
|
}
|
|
|
|
|
2020-09-30 20:57:58 +00:00
|
|
|
private boolean magicPushOnce(StringBounder stringBounder) {
|
2020-09-19 15:43:24 +00:00
|
|
|
final List<FingerPrint> notes = new ArrayList<FingerPrint>();
|
|
|
|
for (TaskDraw td : draws.values()) {
|
|
|
|
final FingerPrint taskPrint = td.getFingerPrint();
|
|
|
|
for (FingerPrint note : notes) {
|
|
|
|
final double deltaY = note.overlap(taskPrint);
|
|
|
|
if (deltaY > 0) {
|
|
|
|
pushIncluding(td, deltaY);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final FingerPrint fingerPrintNote = td.getFingerPrintNote(stringBounder);
|
|
|
|
if (fingerPrintNote != null) {
|
|
|
|
notes.add(fingerPrintNote);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void pushIncluding(TaskDraw first, double deltaY) {
|
|
|
|
boolean skipping = true;
|
2020-09-30 20:57:58 +00:00
|
|
|
if (first.getTrueRow() != null) {
|
|
|
|
first = first.getTrueRow();
|
|
|
|
}
|
2020-09-19 15:43:24 +00:00
|
|
|
for (TaskDraw td : draws.values()) {
|
2021-01-08 01:56:09 +00:00
|
|
|
if (td == first) {
|
2020-09-19 15:43:24 +00:00
|
|
|
skipping = false;
|
2021-01-08 01:56:09 +00:00
|
|
|
}
|
|
|
|
if (skipping) {
|
2020-09-19 15:43:24 +00:00
|
|
|
continue;
|
2021-01-08 01:56:09 +00:00
|
|
|
}
|
2020-09-30 20:57:58 +00:00
|
|
|
td.pushMe(deltaY + 1);
|
2020-09-19 15:43:24 +00:00
|
|
|
}
|
|
|
|
|
2017-02-26 16:26:11 +00:00
|
|
|
}
|
|
|
|
|
2020-09-30 20:57:58 +00:00
|
|
|
private Day getStart(final TaskImpl tmp) {
|
2020-03-18 10:50:02 +00:00
|
|
|
if (printStart == null) {
|
|
|
|
return tmp.getStart();
|
|
|
|
}
|
2020-09-30 20:57:58 +00:00
|
|
|
return Day.max(min, tmp.getStart());
|
2020-03-18 10:50:02 +00:00
|
|
|
}
|
|
|
|
|
2020-09-30 20:57:58 +00:00
|
|
|
private Day getEnd(final TaskImpl tmp) {
|
2020-03-18 10:50:02 +00:00
|
|
|
if (printStart == null) {
|
|
|
|
return tmp.getEnd();
|
|
|
|
}
|
2020-09-30 20:57:58 +00:00
|
|
|
return Day.min(max, tmp.getEnd());
|
2020-03-18 10:50:02 +00:00
|
|
|
}
|
|
|
|
|
2017-02-26 16:26:11 +00:00
|
|
|
private void initMinMax() {
|
2018-11-26 18:46:22 +00:00
|
|
|
if (tasks.size() == 0) {
|
|
|
|
max = min.increment();
|
|
|
|
} else {
|
2019-03-29 22:14:07 +00:00
|
|
|
max = null;
|
2018-11-26 18:46:22 +00:00
|
|
|
for (Task task : tasks.values()) {
|
|
|
|
if (task instanceof TaskSeparator) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-09-30 20:57:58 +00:00
|
|
|
final Day start = task.getStart();
|
|
|
|
final Day end = task.getEnd();
|
2018-11-26 18:46:22 +00:00
|
|
|
// if (min.compareTo(start) > 0) {
|
|
|
|
// min = start;
|
|
|
|
// }
|
2019-03-29 22:14:07 +00:00
|
|
|
if (max == null || max.compareTo(end) < 0) {
|
2018-11-26 18:46:22 +00:00
|
|
|
max = end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-21 17:33:24 +00:00
|
|
|
if (openClose.getCalendar() != null) {
|
2020-03-18 10:50:02 +00:00
|
|
|
for (Day d : colorDays.keySet()) {
|
2020-09-30 20:57:58 +00:00
|
|
|
if (d.compareTo(max) > 0) {
|
|
|
|
max = d;
|
2018-11-26 18:46:22 +00:00
|
|
|
}
|
2018-04-06 20:36:30 +00:00
|
|
|
}
|
2020-03-18 10:50:02 +00:00
|
|
|
for (Day d : nameDays.keySet()) {
|
2020-09-30 20:57:58 +00:00
|
|
|
if (d.compareTo(max) > 0) {
|
|
|
|
max = d;
|
2018-11-26 18:46:22 +00:00
|
|
|
}
|
2017-02-26 16:26:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
public Day getThenDate() {
|
|
|
|
Day result = getStartingDate();
|
|
|
|
for (Day d : colorDays.keySet()) {
|
2018-11-26 18:46:22 +00:00
|
|
|
if (d.compareTo(result) > 0) {
|
|
|
|
result = d;
|
|
|
|
}
|
|
|
|
}
|
2020-03-18 10:50:02 +00:00
|
|
|
for (Day d : nameDays.keySet()) {
|
2018-11-26 18:46:22 +00:00
|
|
|
if (d.compareTo(result) > 0) {
|
|
|
|
result = d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-02-26 16:26:11 +00:00
|
|
|
public Task getExistingTask(String id) {
|
|
|
|
if (id == null) {
|
|
|
|
throw new IllegalArgumentException();
|
|
|
|
}
|
|
|
|
Task result = byShortName.get(id);
|
|
|
|
if (result != null) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
final TaskCode code = new TaskCode(id);
|
|
|
|
return tasks.get(code);
|
|
|
|
}
|
|
|
|
|
2020-08-25 17:24:17 +00:00
|
|
|
public GanttConstraint forceTaskOrder(Task task1, Task task2) {
|
2018-04-06 20:36:30 +00:00
|
|
|
final TaskInstant end1 = new TaskInstant(task1, TaskAttribute.END);
|
|
|
|
task2.setStart(end1.getInstantPrecise());
|
2020-08-25 17:24:17 +00:00
|
|
|
final GanttConstraint result = new GanttConstraint(end1, new TaskInstant(task2, TaskAttribute.START));
|
|
|
|
addContraint(result);
|
|
|
|
return result;
|
2018-04-06 20:36:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Task getOrCreateTask(String codeOrShortName, String shortName, boolean linkedToPrevious) {
|
2017-02-26 16:26:11 +00:00
|
|
|
if (codeOrShortName == null) {
|
|
|
|
throw new IllegalArgumentException();
|
|
|
|
}
|
|
|
|
Task result = shortName == null ? null : byShortName.get(shortName);
|
|
|
|
if (result != null) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = byShortName.get(codeOrShortName);
|
|
|
|
if (result != null) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
final TaskCode code = new TaskCode(codeOrShortName);
|
|
|
|
result = tasks.get(code);
|
2017-02-01 18:55:51 +00:00
|
|
|
if (result == null) {
|
2018-04-06 20:36:30 +00:00
|
|
|
Task previous = null;
|
|
|
|
if (linkedToPrevious) {
|
|
|
|
previous = getLastCreatedTask();
|
|
|
|
}
|
2020-11-21 17:33:24 +00:00
|
|
|
result = new TaskImpl(code, openClose);
|
2017-02-01 18:55:51 +00:00
|
|
|
tasks.put(code, result);
|
2017-02-26 16:26:11 +00:00
|
|
|
if (byShortName != null) {
|
|
|
|
byShortName.put(shortName, result);
|
|
|
|
}
|
2018-04-06 20:36:30 +00:00
|
|
|
if (previous != null) {
|
2020-08-25 17:24:17 +00:00
|
|
|
forceTaskOrder(previous, result);
|
2018-04-06 20:36:30 +00:00
|
|
|
}
|
2017-02-01 18:55:51 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-04-06 20:36:30 +00:00
|
|
|
private Task getLastCreatedTask() {
|
|
|
|
final List<Task> all = new ArrayList<Task>(tasks.values());
|
|
|
|
for (int i = all.size() - 1; i >= 0; i--) {
|
|
|
|
if (all.get(i) instanceof TaskImpl) {
|
|
|
|
return all.get(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addSeparator(String comment) {
|
|
|
|
TaskSeparator separator = new TaskSeparator(comment, tasks.size());
|
|
|
|
tasks.put(separator.getCode(), separator);
|
|
|
|
}
|
|
|
|
|
2017-02-01 18:55:51 +00:00
|
|
|
public void addContraint(GanttConstraint constraint) {
|
|
|
|
constraints.add(constraint);
|
|
|
|
}
|
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
public HColorSet getIHtmlColorSet() {
|
2017-02-01 18:55:51 +00:00
|
|
|
return colorSet;
|
|
|
|
}
|
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
public void setStartingDate(Day start) {
|
2020-11-21 17:33:24 +00:00
|
|
|
openClose.setCalendar(start);
|
2020-09-30 20:57:58 +00:00
|
|
|
this.min = start;
|
2017-02-26 16:26:11 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
public Day getStartingDate() {
|
2020-11-21 17:33:24 +00:00
|
|
|
return openClose.getCalendar();
|
2017-11-20 16:10:36 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
public Day getStartingDate(int nday) {
|
2020-11-21 17:33:24 +00:00
|
|
|
if (openClose.getCalendar() == null) {
|
2019-02-09 21:56:24 +00:00
|
|
|
return null;
|
|
|
|
}
|
2020-11-21 17:33:24 +00:00
|
|
|
return openClose.getCalendar().addDays(nday);
|
2019-02-09 21:56:24 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 18:46:22 +00:00
|
|
|
public int daysInWeek() {
|
2020-11-21 17:33:24 +00:00
|
|
|
return openClose.daysInWeek();
|
2018-11-26 18:46:22 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
public boolean isOpen(Day day) {
|
2020-11-21 17:33:24 +00:00
|
|
|
return openClose.getLoadAt(day) > 0;
|
2018-06-25 19:05:58 +00:00
|
|
|
}
|
|
|
|
|
2021-01-10 20:52:19 +00:00
|
|
|
public boolean affectResource(Task result, String description) {
|
2019-02-09 21:56:24 +00:00
|
|
|
final Pattern p = Pattern.compile("([^:]+)(:(\\d+))?");
|
|
|
|
final Matcher m = p.matcher(description);
|
|
|
|
if (m.find() == false) {
|
|
|
|
throw new IllegalArgumentException();
|
|
|
|
}
|
|
|
|
final Resource resource = getResource(m.group(1));
|
|
|
|
int percentage = 100;
|
|
|
|
if (m.group(3) != null) {
|
|
|
|
percentage = Integer.parseInt(m.group(3));
|
|
|
|
}
|
2021-01-10 20:52:19 +00:00
|
|
|
if (percentage == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-02-09 21:56:24 +00:00
|
|
|
result.addResource(resource, percentage);
|
2021-01-10 20:52:19 +00:00
|
|
|
return true;
|
2018-04-06 20:36:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Resource getResource(String resourceName) {
|
|
|
|
Resource resource = resources.get(resourceName);
|
|
|
|
if (resource == null) {
|
2020-11-21 17:33:24 +00:00
|
|
|
resource = new Resource(resourceName);
|
2018-04-06 20:36:30 +00:00
|
|
|
}
|
|
|
|
resources.put(resourceName, resource);
|
|
|
|
return resource;
|
|
|
|
}
|
|
|
|
|
2020-09-30 20:57:58 +00:00
|
|
|
public int getLoadForResource(Resource res, Day i) {
|
2018-04-06 20:36:30 +00:00
|
|
|
int result = 0;
|
|
|
|
for (Task task : tasks.values()) {
|
|
|
|
if (task instanceof TaskSeparator) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
final TaskImpl task2 = (TaskImpl) task;
|
|
|
|
result += task2.loadForResource(res, i);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-11-26 18:46:22 +00:00
|
|
|
public Moment getExistingMoment(String id) {
|
|
|
|
Moment result = getExistingTask(id);
|
|
|
|
if (result == null) {
|
2020-03-18 10:50:02 +00:00
|
|
|
Day start = null;
|
|
|
|
Day end = null;
|
|
|
|
for (Map.Entry<Day, String> ent : nameDays.entrySet()) {
|
2018-11-26 18:46:22 +00:00
|
|
|
if (ent.getValue().equalsIgnoreCase(id) == false) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
start = min(start, ent.getKey());
|
|
|
|
end = max(end, ent.getKey());
|
|
|
|
}
|
|
|
|
if (start != null) {
|
2020-09-30 20:57:58 +00:00
|
|
|
result = new MomentImpl(start, end);
|
2018-11-26 18:46:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
private Day min(Day d1, Day d2) {
|
2018-11-26 18:46:22 +00:00
|
|
|
if (d1 == null) {
|
|
|
|
return d2;
|
|
|
|
}
|
|
|
|
if (d1.compareTo(d2) > 0) {
|
|
|
|
return d2;
|
|
|
|
}
|
|
|
|
return d1;
|
|
|
|
}
|
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
private Day max(Day d1, Day d2) {
|
2018-11-26 18:46:22 +00:00
|
|
|
if (d1 == null) {
|
|
|
|
return d2;
|
|
|
|
}
|
|
|
|
if (d1.compareTo(d2) < 0) {
|
|
|
|
return d2;
|
|
|
|
}
|
|
|
|
return d1;
|
|
|
|
}
|
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
public void colorDay(Day day, HColor color) {
|
2018-06-25 19:05:58 +00:00
|
|
|
colorDays.put(day, color);
|
|
|
|
}
|
|
|
|
|
2021-01-08 03:16:04 +00:00
|
|
|
public void colorDay(DayOfWeek day, HColor color) {
|
|
|
|
colorDaysOfWeek.put(day, color);
|
|
|
|
}
|
2021-01-10 20:52:19 +00:00
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
public void nameDay(Day day, String name) {
|
2018-06-25 19:05:58 +00:00
|
|
|
nameDays.put(day, name);
|
|
|
|
}
|
|
|
|
|
2020-08-25 17:24:17 +00:00
|
|
|
public void setTodayColors(CenterBorderColor colors) {
|
2019-02-09 21:56:24 +00:00
|
|
|
if (today == null) {
|
2020-03-18 10:50:02 +00:00
|
|
|
this.today = Day.today();
|
2019-02-09 21:56:24 +00:00
|
|
|
}
|
|
|
|
colorDay(today, colors.getCenter());
|
|
|
|
}
|
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
public CommandExecutionResult setToday(Day date) {
|
2019-02-09 21:56:24 +00:00
|
|
|
this.today = date;
|
|
|
|
return CommandExecutionResult.ok();
|
|
|
|
}
|
|
|
|
|
2019-03-29 22:14:07 +00:00
|
|
|
public CommandExecutionResult deleteTask(Task task) {
|
2020-08-25 17:24:17 +00:00
|
|
|
task.setColors(new CenterBorderColor(HColorUtils.WHITE, HColorUtils.BLACK));
|
2019-03-29 22:14:07 +00:00
|
|
|
return CommandExecutionResult.ok();
|
|
|
|
}
|
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
public void setPrintInterval(Day start, Day end) {
|
2020-02-18 21:24:31 +00:00
|
|
|
this.printStart = start;
|
|
|
|
this.printEnd = end;
|
|
|
|
}
|
|
|
|
|
2020-08-25 17:24:17 +00:00
|
|
|
public void setLinksColor(HColor color) {
|
|
|
|
this.linksColor = color;
|
|
|
|
}
|
|
|
|
|
|
|
|
public TaskDraw getTaskDraw(Task task) {
|
|
|
|
return draws.get(task);
|
|
|
|
}
|
|
|
|
|
|
|
|
public CommandExecutionResult addNote(Display note) {
|
|
|
|
Task last = null;
|
|
|
|
for (Task current : tasks.values())
|
|
|
|
last = current;
|
|
|
|
if (last == null) {
|
|
|
|
return CommandExecutionResult.error("No task defined");
|
|
|
|
}
|
|
|
|
last.setNote(note);
|
|
|
|
return CommandExecutionResult.ok();
|
|
|
|
}
|
|
|
|
|
2020-11-21 17:33:24 +00:00
|
|
|
public LoadPlanable getDefaultPlan() {
|
|
|
|
return openClose;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean showFootbox = true;
|
|
|
|
|
|
|
|
public void setShowFootbox(boolean footbox) {
|
|
|
|
this.showFootbox = footbox;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-01-10 20:52:19 +00:00
|
|
|
}
|