Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Javafx #136

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ if(build_simulator_java)

include 'snobot_sim_utilities'
include 'snobot_sim_gui'
include 'snobot_sim_gui_javafx'
include 'snobot_sim_joysticks'
include 'snobot_sim_example_robot'

Expand Down
3 changes: 2 additions & 1 deletion snobot_sim_gui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ dependencies {


// 3rd Party
native3rdPartyDeps 'net.java.jinput:jinput:2.0.9'
compile 'net.java.jinput:jinput:2.0.9'
wpilibNativeDeps 'net.java.jinput:jinput:2.0.9:natives-all'
compile 'jfree:jcommon:1.0.16'
compile 'jfree:jfreechart:1.0.13'
compile 'org.apache.logging.log4j:log4j-api:2.12.0'
Expand Down
128 changes: 128 additions & 0 deletions snobot_sim_gui_javafx/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@

evaluationDependsOn(':snobot_sim_utilities')
evaluationDependsOn(':sim_adx_family')
evaluationDependsOn(':sim_extension_navx')

ext
{
baseId = "snobot_sim_gui_javafx"
}

apply from: "${rootDir}/common/base_java_script.gradle"

configurations {
native3rdPartyDeps
compile.extendsFrom(native3rdPartyDeps)
}

configurations.maybeCreate("wpilibNativeDeps")
dependencies {

compile "org.openjfx:javafx-base:11:win"
compile "org.openjfx:javafx-graphics:11:win"
compile "org.openjfx:javafx-controls:11:win"
compile "org.openjfx:javafx-fxml:11:win"

// WPILib
compile 'edu.wpi.first.wpilibj:wpilibj-java:' + allwpilibVersion()
compile 'edu.wpi.first.wpiutil:wpiutil-java:' + getWpiUtilVersion()
compile 'edu.wpi.first.cscore:cscore-java:' + getCsCoreVersion()
runtime 'edu.wpi.first.cscore:cscore-jni:' + getCsCoreVersion() + ':all'
compile 'edu.wpi.first.ntcore:ntcore-java:' + getNtCoreVersion()
runtime 'edu.wpi.first.ntcore:ntcore-jni:' + getNtCoreVersion() + ':all'
runtime 'edu.wpi.first.hal:hal-jni:' + allwpilibVersion() + ':all'
compile 'org.opencv:opencv-java:' + getWpilibOpencvVersion()
runtime 'org.opencv:opencv-jni:' + getWpilibOpencvVersion() + ':all'

// 3rd Party
compile 'net.java.jinput:jinput:2.0.9'
wpilibNativeDeps 'net.java.jinput:jinput:2.0.9:natives-all'
compile 'jfree:jcommon:1.0.16'
compile 'jfree:jfreechart:1.0.13'
compile 'org.apache.logging.log4j:log4j-api:2.11.0'
compile 'org.apache.logging.log4j:log4j-core:2.11.0'
compile 'org.yaml:snakeyaml:1.18'
compile 'com.miglayout:miglayout-swing:4.2'
//compile 'org.python:jython:2.7.1b3'

// Internal
compile project(":snobot_sim_utilities")
compile project(":snobot_sim_joysticks")

if(build_simulator_cpp)
{
compile project(":snobot_sim_jni")
wpilibNativeDeps project(':snobot_sim_jni').packageNativeFiles.outputs.files
}

if(build_simulator_java)
{
compile project(":snobot_sim_java")
wpilibNativeDeps project(':sim_extension_navx').packageNativeFiles.outputs.files
wpilibNativeDeps project(':sim_adx_family').packageNativeFiles.outputs.files
}

// Test
testCompile 'org.junit.jupiter:junit-jupiter-api:5.2.0'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.2.0'
testRuntime 'org.junit.platform:junit-platform-launcher:1.2.0'
runtime 'com.snobot.simulator:ctre_sim_override:' + getCtreSimVersion() + ':all'
runtime 'com.snobot.simulator:rev_simulator:' + getRevRoboticsSimVersion() + ':all'
}

apply from: "${rootDir}/common/extract_native_libraries.gradle"
test.dependsOn extract_wpilib


task unzipNativeLibraries(type: Copy) {

configurations.native3rdPartyDeps.each {
from zipTree(it)
into "build/native_libs"
include "**/*.dll"
include "**/*.lib"
include "**/*.pdb"
include "**/*.so*"
include "**/*.a"
include "**/*.dylib*"
}

includeEmptyDirs = false

}

eclipse.classpath.file {
whenMerged { classpath ->
classpath.entries.each {
if(it.path.contains("jinput") && !it.path.contains("natives")) {
it.setNativeLibraryLocation("snobot_sim_gui_javafx/build/native_libs")
}
}
}
}

build.dependsOn unzipNativeLibraries

if(build_simulator_cpp)
{
compileJava.dependsOn(":snobot_sim_jni:build")
}
if(build_simulator_java)
{
compileJava.dependsOn(":snobot_sim_java:build")
}

sourceSets.main.java.srcDir "${buildDir}/generated/java/"
compileJava {
apply from: "${rootDir}/common/create_version_file.gradle"
createJavaVersion("com/snobot/simulator", "SnobotSimGuiVersion", "com.snobot.simulator", getVersionName())
}

clean {
delete "src/main/java/com/snobot/simulator/SnobotSimGuiVersion.java"
}


spotbugs {
ignoreFailures = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.snobot.simulator;

import com.snobot.simulator.config.v1.SimulatorConfigReaderV1;
import com.snobot.simulator.robot_container.IRobotClassContainer;

/**
* Base class for a custom simulator.
*
* @author PJ
*
*/
public class BaseSimulator implements ISimulatorUpdater
{
private final SimulatorConfigReaderV1 mConfigReader;
private String mConfigFile;

protected BaseSimulator()
{
mConfigReader = new SimulatorConfigReaderV1();
}

public boolean loadConfig(String aConfigFile)
{
mConfigFile = aConfigFile;
return mConfigReader.loadConfig(mConfigFile);
}


@Override
public void update()
{
// Nothing to do
}

@Override
public void setRobot(IRobotClassContainer aRobot)
{
// Nothing to do
}

public String getConfigFile()
{
return mConfigFile;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.snobot.simulator;

import com.snobot.simulator.wrapper_accessors.DataAccessorFactory;
import com.snobot.simulator.wrapper_accessors.java.JavaDataAccessor;

/**
* Helper class that sets up the data accessor abstraction layer
*
* @author PJ
*
*/
public final class DefaultDataAccessorFactory
{
private static final boolean sINITIALIZED = false;

private DefaultDataAccessorFactory()
{

}

public static void initalize()
{
if (!sINITIALIZED)
{
DataAccessorFactory.setAccessor(new JavaDataAccessor());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.snobot.simulator;

import com.snobot.simulator.robot_container.IRobotClassContainer;

public interface ISimulatorUpdater
{

public abstract void update();

public abstract void setRobot(IRobotClassContainer aRobot);
}
22 changes: 22 additions & 0 deletions snobot_sim_gui_javafx/src/main/java/com/snobot/simulator/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.snobot.simulator;

import com.sun.javafx.application.LauncherImpl;

public final class Main
{
private Main()
{

}

public static void main(String[] aArgs)
{
DefaultDataAccessorFactory.initalize();

// JavaFX 11+ uses GTK3 by default, and has problems on some display
// servers
// This flag forces JavaFX to use GTK2
// System.setProperty("jdk.gtk.version", "2");
LauncherImpl.launchApplication(SimulatorApplication.class, SimulatorPreloader.class, aArgs);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.snobot.simulator;

import java.io.File;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;

import com.snobot.simulator.robot_container.CppRobotContainer;
import com.snobot.simulator.robot_container.IRobotClassContainer;
import com.snobot.simulator.robot_container.JavaRobotContainer;

import edu.wpi.first.networktables.NetworkTableInstance;

public final class RobotContainerFactory
{
private RobotContainerFactory()
{

}

public static IRobotClassContainer createRobotContainer(File aConfigDirectory, String aRobotType, String aRobotClassName)
throws ReflectiveOperationException
{
LogManager.getLogger(RobotContainerFactory.class).log(Level.INFO, "Starting Robot Code");

IRobotClassContainer mRobot;

if (aRobotType == null || "java".equals(aRobotType))
{
mRobot = new JavaRobotContainer(aRobotClassName);
}
else if ("cpp".equals(aRobotType))
{
mRobot = new CppRobotContainer(aRobotClassName);
}
else
{
throw new RuntimeException("Unsupported robot type " + aRobotType);
}

mRobot.constructRobot();

// Change the network table preferences path. Need to start
// the robot, stop the server and restart it
NetworkTableInstance inst = NetworkTableInstance.getDefault();
inst.stopServer();
inst.startServer(aConfigDirectory.toString() + "/networktables.ini");

return mRobot;
}
}
Loading