bugfix in delete pipeline in ui, changed pipelines to be a list instead of a hashmap, ui renaming

- changed pipeline delete message to be Can not remove the only pipeline!
- duplicate pipeline window will display current pipeline on open
- duplicate windows button changed from discard to cancel
This commit is contained in:
ori agranat
2019-10-25 15:02:17 +03:00
parent dfe88d8df5
commit ec117e9884
15 changed files with 71 additions and 54 deletions

View File

@@ -9,6 +9,8 @@ import edu.wpi.cscore.*;
import edu.wpi.first.cameraserver.CameraServer;
import org.opencv.core.Mat;
import java.nio.channels.Pipe;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@@ -42,7 +44,7 @@ public class Camera {
private CameraValues camVals;
private CamVideoMode camVideoMode;
private int currentPipelineIndex;
private HashMap<Integer, Pipeline> pipelines;
private List<Pipeline> pipelines;
public Camera(String cameraName) {
this(cameraName, DEFAULT_FOV);
@@ -57,18 +59,16 @@ public class Camera {
}
public Camera(String cameraName, UsbCameraInfo usbCamInfo, double fov, StreamDivisor divisor) {
this(cameraName, usbCamInfo, fov, new HashMap<>(), 0, divisor);
this(cameraName, usbCamInfo, fov, new ArrayList<>(), 0, divisor);
}
public Camera(String cameraName, double fov, int videoModeIndex, StreamDivisor divisor) {
this(cameraName, fov, new HashMap<>(), videoModeIndex, divisor);
}
public Camera(String cameraName, double fov, HashMap<Integer, Pipeline> pipelines, int videoModeIndex, StreamDivisor divisor) {
public Camera(String cameraName, double fov, List<Pipeline> pipelines, int videoModeIndex, StreamDivisor divisor) {
this(cameraName, CameraManager.AllUsbCameraInfosByName.get(cameraName), fov, pipelines, videoModeIndex, divisor);
}
public Camera(String cameraName, UsbCameraInfo usbCamInfo, double fov, HashMap<Integer, Pipeline> pipelines, int videoModeIndex, StreamDivisor divisor) {
public Camera(String cameraName, double fov, int videoModeIndex, StreamDivisor divisor) {
this(cameraName, fov, new ArrayList<>(), videoModeIndex, divisor);
}
public Camera(String cameraName, UsbCameraInfo usbCamInfo, double fov, List<Pipeline> pipelines, int videoModeIndex, StreamDivisor divisor) {
FOV = fov;
name = cameraName;
@@ -140,28 +140,20 @@ public class Camera {
ServerHandler.sendFullSettings();
}
}
public void addPipeline() {
addPipeline(pipelines.size());
Pipeline p = new Pipeline();
p.nickname = "New pipeline " + pipelines.size();
addPipeline(p);
}
public void addPipeline(Pipeline p){
this.pipelines.add(p);
}
public void addPipeline(Pipeline pipeline) {
int newPipelineIndex = pipelines.size();
addPipeline(newPipelineIndex, pipeline);
public void deletePipeline(int index) {
pipelines.remove(index);
}
private void addPipeline(int pipelineNumber) {
if (pipelines.containsKey(pipelineNumber)) return;
pipelines.put(pipelineNumber, new Pipeline());
}
private void addPipeline(int pipelineIndex, Pipeline pipeline) {
if (pipelines.containsKey(pipelineIndex)) return;
pipelines.put(pipelineIndex, pipeline);
}
public void deleteCurrentPipeline() {
pipelines.remove(getCurrentPipelineIndex());
public void deletePipeline() {
deletePipeline(getCurrentPipelineIndex());
}
public Pipeline getCurrentPipeline() {
@@ -189,12 +181,12 @@ public class Camera {
streamDivisor = StreamDivisor.values()[divisor];
}
public HashMap<Integer, Pipeline> getPipelines() {
public List<Pipeline> getPipelines() {
return pipelines;
}
public List<String> getPipelinesNickname(){
var pipelines = getPipelines();
return pipelines.values().stream().map(pipeline -> pipeline.nickname).collect(Collectors.toList());
return pipelines.stream().map(pipeline -> pipeline.nickname).collect(Collectors.toList());
}
public CamVideoMode getVideoMode() {

View File

@@ -2,13 +2,17 @@ package com.chameleonvision.vision.camera;
import com.chameleonvision.vision.Pipeline;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.MapType;
import com.fasterxml.jackson.databind.type.ArrayType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.google.gson.*;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class CameraDeserializer implements JsonDeserializer<Camera> {
@Override
@@ -21,12 +25,12 @@ public class CameraDeserializer implements JsonDeserializer<Camera> {
var divisor = StreamDivisor.values()[jsonObj.get("streamDivisor").getAsInt()];
var pipelines = jsonObj.get("pipelines");
HashMap<Integer, Pipeline> actualPipelines = new HashMap<>();
List<Pipeline> actualPipelines = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
TypeFactory typeFactory = mapper.getTypeFactory();
MapType mapType = typeFactory.constructMapType(HashMap.class, Integer.class, Pipeline.class);
JavaType arrayType = typeFactory.constructCollectionType(List.class, Pipeline.class);
try {
actualPipelines = mapper.readValue(pipelines.toString(), mapType);
actualPipelines = mapper.readValue(pipelines.toString(), arrayType);
} catch (JsonProcessingException e) {
e.printStackTrace();
}

View File

@@ -116,8 +116,9 @@ public class CameraManager {
}
public static void setCurrentPipeline(int pipelineNumber) throws CameraException {
if (!getCurrentCamera().getPipelines().containsKey(pipelineNumber))
if (pipelineNumber >= getCurrentCamera().getPipelines().size()){
throw new CameraException(CameraException.CameraExceptionType.BAD_PIPELINE);
}
getCurrentCamera().setCurrentPipelineIndex(pipelineNumber);
SettingsManager.updatePipelineSetting(pipelineNumber);
}

View File

@@ -78,8 +78,9 @@ public class VisionProcess implements Runnable {
private void pipelineListener(EntryNotification entryNotification) {
var ntPipelineIndex = (int) entryNotification.value.getDouble();
if (camera.getPipelines().containsKey(ntPipelineIndex)) {
// camera.setEntryNotification.value.getString());
if (ntPipelineIndex >= camera.getPipelines().size()){
ntPipelineEntry.setNumber(camera.getCurrentPipelineIndex());
} else{
var pipeline = camera.getCurrentPipeline();
camera.setCurrentPipelineIndex(ntPipelineIndex);
try {
@@ -96,8 +97,6 @@ public class VisionProcess implements Runnable {
ServerHandler.sendFullSettings();
}
} else {
ntPipelineEntry.setNumber(camera.getCurrentPipelineIndex());
}
}