Skip to content

Commit 6c11d42

Browse files
committed
Merge branch 'master' into build/osxTravisBuild
2 parents d3b6229 + 6861563 commit 6c11d42

File tree

16 files changed

+235
-88
lines changed

16 files changed

+235
-88
lines changed

core/src/main/java/edu/wpi/grip/core/GRIPCoreModule.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
109109

110110
bind(ConnectionValidator.class).to(Pipeline.class);
111111
bind(Source.SourceFactory.class).to(Source.SourceFactoryImpl.class);
112-
bind(CameraSource.FrameGrabberFactory.class).to(CameraSource.FrameGrabberFactoryImpl.class);
113112
install(new FactoryModuleBuilder()
114113
.implement(CameraSource.class, CameraSource.class)
115114
.build(CameraSource.Factory.class));

core/src/main/java/edu/wpi/grip/core/Main.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import edu.wpi.grip.core.operations.Operations;
1010
import edu.wpi.grip.core.operations.network.GRIPNetworkModule;
1111
import edu.wpi.grip.core.serialization.Project;
12+
import edu.wpi.grip.core.sources.GRIPSourcesHardwareModule;
1213
import edu.wpi.grip.generated.CVOperations;
1314

1415
import javax.inject.Inject;
@@ -30,7 +31,7 @@ public class Main {
3031

3132
@SuppressWarnings("PMD.SystemPrintln")
3233
public static void main(String[] args) throws IOException, InterruptedException {
33-
final Injector injector = Guice.createInjector(new GRIPCoreModule(), new GRIPNetworkModule());
34+
final Injector injector = Guice.createInjector(new GRIPCoreModule(), new GRIPNetworkModule(), new GRIPSourcesHardwareModule());
3435
injector.getInstance(Main.class).start(args);
3536
}
3637

core/src/main/java/edu/wpi/grip/core/Pipeline.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,13 @@ public void onSourceRemoved(SourceRemovedEvent event) {
232232
}
233233

234234
/**
235-
* Adds the step between two other steps.
236-
* @param stepToAdd The step to add to the pipeline
237-
* @param lower The step to be added above
238-
* @param higher The step to be added below
235+
* Finds the index between the two steps
236+
* @param lower The lower step
237+
* @param higher The higher step
238+
* @return The index that is in between the two of these steps
239239
*/
240-
public void addStepBetween(Step stepToAdd, @Nullable Step lower, @Nullable Step higher) {
241-
checkNotNull(stepToAdd, "The step to add cannot be null");
242-
int index = readStepsSafely(steps -> {
240+
private int indexBetween(@Nullable Step lower, @Nullable Step higher) {
241+
return readStepsSafely(steps -> {
243242
// If not in the list these can return -1
244243
int lowerIndex = steps.indexOf(lower);
245244
int upperIndex = steps.indexOf(higher);
@@ -259,9 +258,33 @@ public void addStepBetween(Step stepToAdd, @Nullable Step lower, @Nullable Step
259258
return steps.size();
260259
}
261260
});
261+
}
262+
263+
/**
264+
* Adds the step between two other steps.
265+
* @param stepToAdd The step to add to the pipeline
266+
* @param lower The step to be added above
267+
* @param higher The step to be added below
268+
*/
269+
public void addStepBetween(Step stepToAdd, @Nullable Step lower, @Nullable Step higher) {
270+
checkNotNull(stepToAdd, "The step to add cannot be null");
271+
final int index = indexBetween(lower, higher);
262272
addStep(index, stepToAdd);
263273
}
264274

275+
/**
276+
*
277+
* @param toMove The step to move
278+
* @param lower The lower step
279+
* @param higher The upper step
280+
*/
281+
public void moveStepBetween(Step toMove, @Nullable Step lower, @Nullable Step higher) {
282+
checkNotNull(toMove, "The step to move cannot be null");
283+
final int index = indexBetween(lower, higher);
284+
final int currentIndex = readStepsSafely(steps -> steps.indexOf(toMove));
285+
moveStep(toMove, index > currentIndex ? index - (currentIndex + 1 ) : index - currentIndex);
286+
}
287+
265288
public void addStep(int index, Step step) {
266289
checkNotNull(step, "The step can not be null");
267290
checkArgument(!step.removed(), "The step must not have been disabled already");
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package edu.wpi.grip.core.sources;
2+
3+
import com.google.inject.AbstractModule;
4+
5+
/**
6+
* Adds bindings for hardware that is required by {@link edu.wpi.grip.core.Source Sources}
7+
*/
8+
public class GRIPSourcesHardwareModule extends AbstractModule {
9+
@Override
10+
protected void configure() {
11+
bind(CameraSource.FrameGrabberFactory.class).to(CameraSource.FrameGrabberFactoryImpl.class);
12+
}
13+
}

core/src/test/java/edu/wpi/grip/core/PipelineTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,4 +335,34 @@ public void testAddBetweenStepsOutOfOrder() {
335335

336336
pipeline.addStepBetween(stepToAdd, upperStep, lowerStep);
337337
}
338+
339+
@Test
340+
public void testMoveStepToLeft() {
341+
final Step
342+
stepToMove = new MockStep(),
343+
lowerStep = new MockStep(),
344+
upperStep = new MockStep();
345+
pipeline.addStep(lowerStep);
346+
pipeline.addStep(upperStep);
347+
pipeline.addStep(stepToMove);
348+
pipeline.moveStepBetween(stepToMove, lowerStep, upperStep);
349+
350+
assertEquals("The step should have been moved within the pipeline",
351+
Arrays.asList(lowerStep, stepToMove, upperStep), pipeline.getSteps());
352+
}
353+
354+
@Test
355+
public void testMoveStepToRight() {
356+
final Step
357+
stepToMove = new MockStep(),
358+
lowerStep = new MockStep(),
359+
upperStep = new MockStep();
360+
pipeline.addStep(stepToMove);
361+
pipeline.addStep(lowerStep);
362+
pipeline.addStep(upperStep);
363+
pipeline.moveStepBetween(stepToMove, lowerStep, upperStep);
364+
365+
assertEquals("The step should have been moved within the pipeline",
366+
Arrays.asList(lowerStep, stepToMove, upperStep), pipeline.getSteps());
367+
}
338368
}

core/src/test/java/edu/wpi/grip/core/serialization/CompatibilityTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void tearDown() {
7676
}
7777

7878
@Test
79-
public void testFoo() throws Exception {
79+
public void testCompatibilityIsMaintained() throws Exception {
8080
assertEquals("The expected number of steps were not found", 50, pipeline.getSteps().size());
8181
assertEquals("The expected number of sources were not found", 2, pipeline.getSources().size());
8282
pipeline.clear();

core/src/test/java/edu/wpi/grip/core/sources/MockCameraSource.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,19 @@
22

33
import com.google.common.eventbus.EventBus;
44
import edu.wpi.grip.core.util.MockExceptionWitness;
5-
import org.bytedeco.javacv.FrameGrabber;
65

76
import java.io.IOException;
8-
import java.net.MalformedURLException;
97

108
public class MockCameraSource extends CameraSource {
119

1210
private boolean started = false;
1311

14-
static class FrameGrabberFactory implements CameraSource.FrameGrabberFactory {
15-
16-
@Override
17-
public FrameGrabber create(int deviceNumber) {
18-
return null;
19-
}
20-
21-
@Override
22-
public FrameGrabber create(String addressProperty) throws MalformedURLException {
23-
return null;
24-
}
25-
}
26-
2712
public MockCameraSource(EventBus eventBus, String address) throws IOException {
28-
super(eventBus, new FrameGrabberFactory(), MockExceptionWitness.MOCK_FACTORY, address);
13+
super(eventBus, new MockFrameGrabberFactory(), MockExceptionWitness.MOCK_FACTORY, address);
2914
}
3015

3116
public MockCameraSource(EventBus eventBus, int deviceNumber) throws IOException {
32-
super(eventBus, new FrameGrabberFactory(), MockExceptionWitness.MOCK_FACTORY, deviceNumber);
17+
super(eventBus, new MockFrameGrabberFactory(), MockExceptionWitness.MOCK_FACTORY, deviceNumber);
3318
}
3419

3520
@Override
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package edu.wpi.grip.core.sources;
2+
3+
import org.bytedeco.javacv.FrameGrabber;
4+
5+
import java.net.MalformedURLException;
6+
7+
/**
8+
* Frame Grabber Factory that mocks out the frame grabber that it returns
9+
*/
10+
public class MockFrameGrabberFactory implements CameraSource.FrameGrabberFactory {
11+
12+
@Override
13+
public FrameGrabber create(int deviceNumber) {
14+
return new SimpleMockFrameGrabber();
15+
}
16+
17+
@Override
18+
public FrameGrabber create(String addressProperty) throws MalformedURLException {
19+
return new SimpleMockFrameGrabber();
20+
}
21+
}

core/src/test/java/edu/wpi/grip/util/GRIPCoreTestModule.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import com.google.common.eventbus.SubscriberExceptionContext;
55
import edu.wpi.grip.core.GRIPCoreModule;
6+
import edu.wpi.grip.core.sources.CameraSource;
7+
import edu.wpi.grip.core.sources.MockFrameGrabberFactory;
68

79
import java.util.ArrayList;
810
import java.util.List;
@@ -68,6 +70,7 @@ public void tearDown() {
6870
@Override
6971
protected void configure() {
7072
assert setUp : "The GRIPCoreTestModule handler was not set up. Call 'setUp' before passing the injector";
73+
bind(CameraSource.FrameGrabberFactory.class).to(MockFrameGrabberFactory.class);
7174
super.configure();
7275
}
7376

ui/src/main/java/edu/wpi/grip/ui/Main.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import edu.wpi.grip.core.operations.Operations;
1414
import edu.wpi.grip.core.operations.network.GRIPNetworkModule;
1515
import edu.wpi.grip.core.serialization.Project;
16+
import edu.wpi.grip.core.sources.GRIPSourcesHardwareModule;
1617
import edu.wpi.grip.core.util.SafeShutdown;
1718
import edu.wpi.grip.generated.CVOperations;
1819
import edu.wpi.grip.ui.util.DPIUtility;
@@ -67,7 +68,7 @@ public void start(Stage stage) throws Exception {
6768
parameters.remove("--headless");
6869
} else {
6970
// Otherwise, run with both the core and UI modules, and show the JavaFX stage
70-
injector = Guice.createInjector(Modules.override(new GRIPCoreModule(), new GRIPNetworkModule()).with(new GRIPUIModule()));
71+
injector = Guice.createInjector(Modules.override(new GRIPCoreModule(), new GRIPNetworkModule(), new GRIPSourcesHardwareModule()).with(new GRIPUIModule()));
7172
injector.injectMembers(this);
7273

7374
root = FXMLLoader.load(Main.class.getResource("MainWindow.fxml"), null, null, injector::getInstance);

0 commit comments

Comments
 (0)