Skip to content

Commit

Permalink
Merge pull request #110 from TH3steven/dev
Browse files Browse the repository at this point in the history
One last pull request
  • Loading branch information
TH3steven authored Jun 25, 2016
2 parents 57bb892 + c3bd014 commit 7972cbb
Show file tree
Hide file tree
Showing 50 changed files with 1,451 additions and 1,432 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
/target/
/*.iml
.pmd
.eclipse-pmd
.eclipse-pmd
/snapShots/
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>nl.tudelft</groupId>
<artifactId>Context-TFP</artifactId>
<version>0.8.1</version>
<version>1.0</version>
<name>Team Free Pizza</name>
<description>TU Delft Contextproject Multi-Media 2016 from Team Free Pizza</description>

Expand Down
76 changes: 30 additions & 46 deletions src/main/java/nl/tudelft/contextproject/ContextTFP.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,22 @@
import javafx.scene.image.Image;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import nl.tudelft.contextproject.camera.Camera;
import nl.tudelft.contextproject.camera.CameraConnection;
import nl.tudelft.contextproject.camera.LiveCameraConnection;
import nl.tudelft.contextproject.camera.MockedCameraConnection;
import nl.tudelft.contextproject.databaseConnection.DatabaseConnection;
import nl.tudelft.contextproject.gui.AlertDialog;
import nl.tudelft.contextproject.gui.MenuController;
import nl.tudelft.contextproject.saveLoad.ApplicationSettings;
import nl.tudelft.contextproject.script.Script;
import nl.tudelft.contextproject.script.Shot;
import uk.co.caprica.vlcj.discovery.NativeDiscovery;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

/**
* This is the main file for the Multi-Media Contextproject of Team Free Pizza.
* This is the main file for the Multimedia Contextproject of Team Free Pizza.
* The main purpose of this project is to allow PolyCast Productions B.V. to
* easily control their cameras and to improve their digital environment.
* easily digitize their script and to improve their digital environment.
*
* <p>This file should be used to initialize the program.
*
Expand All @@ -41,7 +39,7 @@
* @since 0.1
*/
public class ContextTFP extends Application {

private static boolean hasVLC;
private static BorderPane rootLayout;
private static Script script;
Expand All @@ -55,23 +53,26 @@ public void start(Stage pStage) throws Exception {
primaryStage.minWidthProperty().set(800);
primaryStage.minHeightProperty().set(575);
primaryStage.getIcons().add(new Image(ContextTFP.class.getResourceAsStream("/icon.png")));

// Create the script to be used by the application.
script = new Script(new ArrayList<Shot>());

// Statically initialise ApplicationSettings class.

// Statically initialize ApplicationSettings class.
File dir = new File("src/main/resources/snapShots");
if (!dir.exists()) {
dir.mkdir();
}
ApplicationSettings.getInstance();

initRootLayout();

new Thread(() -> initVLCj()).start();
new Thread(() -> initCameraConnections()).start();


MenuController.show();
}

/**
* Initialises the root layout of the application.
* Initializes the root layout of the application.
*/
public void initRootLayout() {
try {
Expand All @@ -88,38 +89,22 @@ public void initRootLayout() {
} catch (IOException ex) {
ex.printStackTrace();
}

try {
DatabaseConnection.getInstance().resetCounter();
} catch (Exception e1) {
//If we can't reset the counter, just ignore it.
}
Platform.exit();
System.exit(0);
});
} catch (IOException e) {
e.printStackTrace();
}
}

/**
* Initialises the camera connections for every loaded camera.
* If an IP was loaded for a camera, then it will check if it
* can make a connection to this camera. If it can, then it will
* set its connection to a LiveCameraConnection. If it cannot,
* then it sets a MockedCameraConnection.
*/
public void initCameraConnections() {
ApplicationSettings settings = ApplicationSettings.getInstance();
for (Camera cam : Camera.getAllCameras()) {
String camIp = settings.getCameraIP(cam.getNumber());
if (camIp != null && !camIp.equals("")) {
CameraConnection connect = new LiveCameraConnection(camIp);
if (connect.setUpConnection()) {
cam.setConnection(connect);
break;
}
}
cam.setConnection(new MockedCameraConnection());
}
}


/**
* Tries to load VLC using the VLC native discovery tactic.
* Tries to load VLC using the VLC native discovery tactics.
* If it cannot find VLC installed, it will ask for the location of the
* VLC installation.
*/
Expand All @@ -138,7 +123,6 @@ public void initVLCj() {

/**
* The main class of the project. Calling this method will start the program.
*
* @param args Environment arguments for the main method.
*/
public static void main(String[] args) {
Expand All @@ -147,16 +131,14 @@ public static void main(String[] args) {

/**
* Get method for the primary stage of the application.
*
* @return The main stage
* @return The main stage.
*/
public Stage getPrimaryStage() {
return primaryStage;
}

/**
* Get the active script used by the application.
*
* @return The script.
*/
public static Script getScript() {
Expand All @@ -165,7 +147,6 @@ public static Script getScript() {

/**
* Sets the active script used by the application.
*
* @param script The script to be used.
*/
public static void setScript(Script script) {
Expand All @@ -174,13 +155,16 @@ public static void setScript(Script script) {

/**
* Retrieves the root layout of the application.
*
* @return The root layout
*/
public static BorderPane getRootLayout() {
return rootLayout;
}


/**
* Checks of the user has VLC.
* @return True if the program could find VLC.
*/
public static boolean hasVLC() {
return hasVLC;
}
Expand Down
51 changes: 45 additions & 6 deletions src/main/java/nl/tudelft/contextproject/camera/Camera.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.HashMap;
import java.util.Objects;
import java.util.Observable;
import java.util.concurrent.ConcurrentHashMap;

/**
* This class represents a camera. Every camera has its
Expand All @@ -20,16 +21,16 @@ public class Camera extends Observable {
* Dummy camera with camId -1.
*/
public static final Camera DUMMY;
private static final HashMap<Integer, Camera> CAMERAS = new HashMap<Integer, Camera>();

private static final ConcurrentHashMap<Integer, Camera> CAMERAS = new ConcurrentHashMap<Integer, Camera>();
private static int numCams = 0;

private CameraConnection connection;
private CameraSettings camSet;
private HashMap<Integer, Preset> presets;

private int camId;

static {
DUMMY = new Camera();
DUMMY.camId = -1;
Expand Down Expand Up @@ -101,6 +102,9 @@ public int getNumber() {
* @return Camera settings.
*/
public CameraSettings getSettings() {
if (hasConnection()) {
camSet = connection.getCurrentCameraSettings();
}
return camSet;
}

Expand All @@ -110,9 +114,13 @@ public CameraSettings getSettings() {
*/
public void setSettings(CameraSettings settings) {
if (hasConnection() && connection.isConnected()) {
camSet = settings;
camSet.setPan(settings.getPan());
camSet.setTilt(settings.getTilt());
camSet.setZoom(settings.getZoom());
camSet.setFocus(settings.getFocus());

setChanged();
notifyObservers(settings);
notifyObservers(camSet);
}
}

Expand Down Expand Up @@ -334,6 +342,37 @@ public void absFocus(int value) {
setChanged();
notifyObservers();
}

/**
* Makes the camera start panning and tilting in the specified direction
*
* @param panSpeed Should be between -100 and 100, where 0 is stop,
* -100 is maximum speed towards the left and 100 is maximum speed
* towards the right.
* @param tiltSpeed Should be between -100 and 100, where 0 is stop,
* -100 is maximum speed downwards and 100 is maximum speed upwards.
*/
public void panTiltStart(int panSpeed, int tiltSpeed) {
if (hasConnection()) {
connection.panTiltStart(panSpeed, tiltSpeed);
}

setChanged();
notifyObservers();
}

/**
* Makes the camera stop panning and tilting in the specified direction.
*/
public void panTiltStop() {
if (hasConnection()) {
connection.panTiltStop();
}
camSet = getSettings();

setChanged();
notifyObservers();
}

/**
* Adds a preset to the camera, if there is not already
Expand Down Expand Up @@ -422,7 +461,7 @@ public int hashCode() {
public Collection<Preset> getAllPresets() {
return presets.values();
}

@Override
public String toString() {
return this.equals(DUMMY) ? "None" : String.valueOf(camId + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,21 @@ public abstract class CameraConnection implements Observer {
protected abstract boolean relFocus(int offset);

/**
* Takes a snapshot of the image present on a camera and stores the image
* at a chosen location.
*
* @param imageLocation The location to which the captured image is stored.
* Makes the camera start panning and tilting in the specified direction
*
* @param panSpeed Should be between 1 and 99, where 50 is stop,
* 1 is maximum speed towards the left and 99 is maximum speed
* towards the right.
* @param tiltSpeed Should be between 1 and 99, where 50 is stop,
* 1 is maximum speed downwards and 99 is maximum speed upwards.
* @return True iff the operation was performed successfully
*/
protected abstract boolean panTiltStart(int panSpeed, int tiltSpeed);

/**
* Makes the camera stop panning and tilting in the specified direction
*
* @return True iff the command was sent and received successfully.
*/
public abstract void snapShot(String imageLocation);
protected abstract boolean panTiltStop();
}
Loading

0 comments on commit 7972cbb

Please sign in to comment.