Skip to content

Commit

Permalink
feat: show leads in comments, import comments from walls
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1211 committed Jul 19, 2021
1 parent 5f02f97 commit 5033a95
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3780,11 +3780,13 @@ protected Void work() throws Exception {
boolean showCheckedLeads = getProjectModel().get(ProjectModel.showCheckedLeads);
setStatus("Updating lead index...");
MultiMap<StationKey, SurveyLead> index = new LinkedListMultiMap<>();
forEach(leads, lead -> {
Task.Iteratee<SurveyLead> leadHandler = lead -> {
if (lead.getStation() != null && (showCheckedLeads || !lead.isDone())) {
index.put(new StationKey(lead.getCave(), lead.getStation()), lead);
}
});
};
forEach(leads, leadHandler);
forEach(parsedProject.leads, leadHandler);
if (isCanceled()) {
return null;
}
Expand Down
160 changes: 87 additions & 73 deletions breakout-main/src/main/java/org/breakout/ImportWallsTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.andork.swing.async.SelfReportingTask;
import org.andork.unit.Angle;
import org.andork.unit.Length;
import org.andork.unit.UnitizedNumber;
import org.andork.util.StringUtils;
import org.andork.walls.WallsMessage;
import org.andork.walls.lst.StationPosition;
Expand Down Expand Up @@ -69,8 +68,8 @@ class ImportWallsTask extends SelfReportingTask<Void> {
private String currentTripName;
private MutableSurveyTrip currentTrip;
private final List<MutableSurveyRow> rowsInCurrentTrip = new ArrayList<>();
private final Map<String, MutableSurveyRow> rowsByFromStationName = new HashMap<>();
private final List<FixedStation> fixedStations = new ArrayList<>();

private void endCurrentTrip() {
if (!rowsInCurrentTrip.isEmpty()) {
ensureCurrentTrip();
Expand All @@ -90,7 +89,8 @@ private MutableSurveyTrip ensureCurrentTrip() {
if (currentUnits == null) {
throw new IllegalStateException("missing currentUnits");
}
currentTrip = new MutableSurveyTrip()
currentTrip =
new MutableSurveyTrip()
.setName(currentTripName)
.setDistanceUnit(currentUnits.getDUnit())
.setAngleUnit(currentUnits.getAUnit())
Expand All @@ -111,21 +111,30 @@ private MutableSurveyTrip ensureCurrentTrip() {
return currentTrip;
}

private static final List<Function<WallsUnits, ?>> tripDependentFields = Arrays.asList(
WallsUnits::getDUnit,
WallsUnits::getDecl, WallsUnits::getGrid,
WallsUnits::getIncd,
WallsUnits::getInca, WallsUnits::getIncab,
WallsUnits::getIncv, WallsUnits::getIncvb,
WallsUnits::getAUnit, WallsUnits::getAbUnit,
WallsUnits::getVUnit, WallsUnits::getVbUnit,
WallsUnits::isTypeabCorrected, WallsUnits::isTypevbCorrected);
private static final List<Function<WallsUnits, ?>> tripDependentFields =
Arrays
.asList(
WallsUnits::getDUnit,
WallsUnits::getDecl,
WallsUnits::getGrid,
WallsUnits::getIncd,
WallsUnits::getInca,
WallsUnits::getIncab,
WallsUnits::getIncv,
WallsUnits::getIncvb,
WallsUnits::getAUnit,
WallsUnits::getAbUnit,
WallsUnits::getVUnit,
WallsUnits::getVbUnit,
WallsUnits::isTypeabCorrected,
WallsUnits::isTypevbCorrected);

private void setCurrentUnits(WallsUnits units) {
if (currentUnits != units) {
if (units == null || currentUnits == null) {
endCurrentTrip();
} else {
}
else {
for (Function<WallsUnits, ?> field : tripDependentFields) {
if (!Objects.equals(field.apply(units), field.apply(currentUnits))) {
endCurrentTrip();
Expand Down Expand Up @@ -181,16 +190,19 @@ public void parsedVector(Vector vector) {
try {
if (vector.units.getVectorType() == VectorType.RECTANGULAR) {
vector.deriveCtFromRect();
} else {
}
else {
vector.applyHeightCorrections(this);
}
} catch (SegmentParseException e) {
}
catch (SegmentParseException e) {
errors.add(new ImportError(e));
throw new RuntimeException(e);
}

String fromStationName = vector.units.processStationName(vector.from);
MutableSurveyRow row = new MutableSurveyRow()
MutableSurveyRow row =
new MutableSurveyRow()
.setFromStation(fromStationName)
.setToStation(vector.units.processStationName(vector.to))
.setDistance(Objects.toString(vector.distance, null))
Expand All @@ -205,7 +217,6 @@ public void parsedVector(Vector vector) {
.setComment(vector.comment);
rowsInCurrentTrip.add(row);
rows.add(row);
rowsByFromStationName.put(fromStationName, row);
}

@Override
Expand All @@ -216,6 +227,9 @@ public void parsedDate(Date date) {

@Override
public void parsedNote(String station, String parsedNote) {
MutableSurveyRow row = new MutableSurveyRow().setFromStation(station).setComment(parsedNote);
rowsInCurrentTrip.add(row);
rows.add(row);
awaitingTripNameComment = false;
}

Expand All @@ -242,9 +256,11 @@ public ImportWallsTask(BreakoutMainView mainView, Iterable<Path> wallsFiles) {
String s = p.toString().toLowerCase();
if (s.endsWith(".srv")) {
surveyFiles.put(p, null);
} else if (s.endsWith(".lst")) {
}
else if (s.endsWith(".lst")) {
stationReportFiles.add(p);
} else if (s.endsWith(".wpj")) {
}
else if (s.endsWith(".wpj")) {
projFiles.add(p);
}
}
Expand All @@ -256,15 +272,18 @@ public ImportWallsTask(BreakoutMainView mainView, Iterable<Path> wallsFiles) {

private void putSurveyFiles(WallsProjectEntry entry) {
if (entry.isDetatched()) {
wallsVisitor.message(new WallsMessage(
"warning",
"Entry is detached and won't be imported: " + StringUtils.join(" -> ", entry.titlePath()),
entry.statusSegment()));
wallsVisitor
.message(
new WallsMessage(
"warning",
"Entry is detached and won't be imported: " + StringUtils.join(" -> ", entry.titlePath()),
entry.statusSegment()));
return;
}
if (entry.isSurvey()) {
surveyFiles.put(entry.absolutePath(), entry);
} else if (entry instanceof WallsProjectBook) {
}
else if (entry instanceof WallsProjectBook) {
((WallsProjectBook) entry).children().stream().forEach(this::putSurveyFiles);
}
}
Expand All @@ -279,26 +298,35 @@ protected Void workDuringDialog() throws Exception {
parseSurveyFiles();
parseStationReportFiles();

// applyFixedStationPositions();
// applyFixedStationPositions();

} catch (Exception ex) {
}
catch (Exception ex) {
if (ex instanceof SegmentParseException) {
errors.add(new ImportError((SegmentParseException) ex));
} else {
errors.add(new ImportError(
Severity.ERROR, "Unexpected error: " + ex.getLocalizedMessage(),
new Segment("", currentFile, 0, 0)));
}
else {
errors
.add(
new ImportError(
Severity.ERROR,
"Unexpected error: " + ex.getLocalizedMessage(),
new Segment("", currentFile, 0, 0)));
}
logger.log(Level.SEVERE, "Failed to import walls data", ex);
}

try {
newModel = new SurveyTableModel(ArrayLists.map(rows, row -> row.toImmutable()));
} catch (Exception ex) {
}
catch (Exception ex) {
newModel = new SurveyTableModel();
errors.add(new ImportError(
Severity.ERROR, "Unexpected error: " + ex.getLocalizedMessage(),
new Segment("", currentFile, 0, 0)));
errors
.add(
new ImportError(
Severity.ERROR,
"Unexpected error: " + ex.getLocalizedMessage(),
new Segment("", currentFile, 0, 0)));
logger.log(Level.SEVERE, "Failed to import walls data", ex);
}
OnEDT.onEDT(() -> {
Expand All @@ -322,7 +350,8 @@ protected Void workDuringDialog() throws Exception {
if (doImport) {
mainView.addSurveyRowsFrom(newModel);
logger.info(() -> "imported " + newModel.getRowCount() + " shots from walls data");
} else {
}
else {
logger.info("user canceled walls import");
}
});
Expand Down Expand Up @@ -367,7 +396,8 @@ private void parseSurveyFiles() throws SegmentParseException, IOException {
if (surveyEntry != null) {
setCurrentTripName(surveyEntry.absolutePath().getFileName().toString());
parser.parseSurveyEntry(surveyEntry);
} else {
}
else {
setCurrentTripName(file.getFileName().toString());
parser.parseFile(file.toFile());
}
Expand All @@ -391,48 +421,32 @@ private void parseStationReportFiles() throws IOException {
}

WallsStationReport report = parser.getReport();
SurveyTrip trip = new MutableSurveyTrip()
.setDatum(report.datum)
.setUtmZone(String.valueOf(report.utmZone))
.setName(null)
.setDistanceUnit(Length.meters)
.setAngleUnit(Angle.degrees)
.setOverrideFrontAzimuthUnit(Angle.degrees)
.setOverrideBackAzimuthUnit(Angle.degrees)
.setOverrideFrontInclinationUnit(Angle.degrees)
.setOverrideBackInclinationUnit(Angle.degrees)
.setBackAzimuthsCorrected(true)
.setBackInclinationsCorrected(true)
.toImmutable();

SurveyTrip trip =
new MutableSurveyTrip()
.setDatum(report.datum)
.setUtmZone(String.valueOf(report.utmZone))
.setName(null)
.setDistanceUnit(Length.meters)
.setAngleUnit(Angle.degrees)
.setOverrideFrontAzimuthUnit(Angle.degrees)
.setOverrideBackAzimuthUnit(Angle.degrees)
.setOverrideFrontInclinationUnit(Angle.degrees)
.setOverrideBackInclinationUnit(Angle.degrees)
.setBackAzimuthsCorrected(true)
.setBackInclinationsCorrected(true)
.toImmutable();

for (StationPosition station : report.stationPositions) {
MutableSurveyRow row = new MutableSurveyRow();
row.setTrip(trip);
row.setFromStation(station.getNameWithPrefix());
if (Double.isFinite(station.north)) row.setNorthing((report.utmSouth
? 1000000 - station.north
: station.north) + " m");
if (Double.isFinite(station.east)) row.setEasting(station.east + " m");
if (Double.isFinite(station.up)) row.setElevation(station.up + " m");
if (Double.isFinite(station.north))
row.setNorthing((report.utmSouth ? 1000000 - station.north : station.north) + " m");
if (Double.isFinite(station.east))
row.setEasting(station.east + " m");
if (Double.isFinite(station.up))
row.setElevation(station.up + " m");
rows.add(row);
}
}

private void applyFixedStationPositions() {
for (FixedStation station : fixedStations) {
if (!UnitizedNumber.isFinite(station.north) &&
!UnitizedNumber.isFinite(station.east) &&
!UnitizedNumber.isFinite(station.elevation)) {
continue;
}
String stationName = station.units.processStationName(station.name);
MutableSurveyRow row = rowsByFromStationName.get(stationName);
if (row == null) {
continue;
}
if (station.north != null) row.setNorthing(station.north.toString());
if (station.east != null) row.setEasting(station.east.toString());
if (station.elevation != null) row.setElevation(station.elevation.toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class CalcShot {
public CalcCrossSection fromCrossSection;
public CalcCrossSection toCrossSection;

public String comment;

public Collection<Triangle> splayTriangles;

public Iterable<float[]> vertices() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
public class CalcStation {
public String name;
public String cave;
public String comment;
public float date;
private CalcShot originatingShot;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ public void link(ParsedStation parsedFromStation, ParsedShot parsed, ParsedStati
fromStation.name = fromKey.station;
fromStation.cave = fromKey.cave;
fromStation.date = shot.date;
fromStation.comment = parsedFromStation.comment;
project.stations.put(fromKey, fromStation);
}
else {
Expand All @@ -498,6 +499,7 @@ public void link(ParsedStation parsedFromStation, ParsedShot parsed, ParsedStati
toStation.name = toKey.station;
toStation.cave = toKey.cave;
toStation.date = shot.date;
toStation.comment = parsedToStation.comment;
project.stations.put(toKey, toStation);
}
else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package org.breakout.model.parsed;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.breakout.model.ShotKey;
import org.breakout.model.raw.SurveyLead;

public class ParsedProject {
public final Map<String, ParsedCave> caves = new HashMap<>();
public final Map<ShotKey, ParsedShot> shots = new HashMap<>();
public final List<SurveyLead> leads = new ArrayList<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class ParsedStation {
public ParsedCrossSection crossSection;
public List<ParsedSplayShot> splays;
public List<SurveyLead> leads;
public String comment;

private BitSet flags;
private static final int IS_ENTRANCE = 0;
Expand Down
Loading

0 comments on commit 5033a95

Please sign in to comment.