public void constructDialog() {
    sim.disableGUIComponents();

    String fileEnding = ".guiConf";
    if (dataFileChooser.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
      try {
        chosenFile = dataFileChooser.getSelectedFile();

        String filename = chosenFile.getName();

        if (!filename.endsWith(fileEnding)) {
          filename = filename.concat(fileEnding);

          if (!chosenFile.getName().equals(filename)) {
            File newChosenFile = new File(chosenFile.getParent(), filename);

            chosenFile = newChosenFile;
          }
        }

        Writer output = null;

        output = new BufferedWriter(new FileWriter(chosenFile));
        output.write(writeGUIConfig());

        output.close();
        System.out.println("Your file has been written");
      } catch (Exception e) {
        System.err.println("Error While Writting/Saving Gui Configuration File");
        e.printStackTrace();
      }
    }

    sim.enableGUIComponents();
  }
  protected void setupTest(DRCRobotModel robotModel)
      throws SimulationExceededMaximumTimeException, InterruptedException {
    boolean runMultiThreaded = false;
    setupTrack(runMultiThreaded, robotModel);
    FullHumanoidRobotModel fullRobotModel = robotModel.createFullRobotModel();
    pushRobotController =
        new PushRobotController(
            drcFlatGroundWalkingTrack.getDrcSimulation().getRobot(), fullRobotModel);

    if (VISUALIZE_FORCE) {
      drcFlatGroundWalkingTrack
          .getSimulationConstructionSet()
          .addYoGraphic(pushRobotController.getForceVisualizer());
    }

    SimulationConstructionSet scs = drcFlatGroundWalkingTrack.getSimulationConstructionSet();
    BooleanYoVariable enable =
        (BooleanYoVariable) scs.getVariable("PushRecoveryControlModule", "enablePushRecovery");

    // enable push recovery
    enable.set(true);

    for (RobotSide robotSide : RobotSide.values) {
      String prefix = fullRobotModel.getFoot(robotSide).getName();
      scs.getVariable(prefix + "FootControlModule", prefix + "State");
      @SuppressWarnings("unchecked")
      final EnumYoVariable<WalkingStateEnum> walkingState =
          (EnumYoVariable<WalkingStateEnum>)
              scs.getVariable("WalkingHighLevelHumanoidController", "walkingState");
      doubleSupportStartConditions.put(
          robotSide, new DoubleSupportStartCondition(walkingState, robotSide));
    }
  }
  public SimplePendulumSimulation() {
    SimplePendulumRobot robot = new SimplePendulumRobot();
    robot.setController(new SimplePendulumController(robot));

    SimulationConstructionSetParameters parameters = new SimulationConstructionSetParameters();
    parameters.setDataBufferSize(32000);

    sim = new SimulationConstructionSet(robot, parameters);
    sim.setDT(DT, 20);
    sim.setGroundVisible(true);
    sim.setCameraPosition(0, -9.0, 0.6);
    sim.setCameraFix(0.0, 0.0, 0.70);

    sim.setSimulateDuration(60.0); // sets the simulation duration to 60 seconds

    Thread myThread = new Thread(sim);
    myThread.start();
  }
  @Ignore("Needs to be improved")
  @ContinuousIntegrationTest(estimatedDuration = 67.1)
  @Test(timeout = 340000)
  public void testMultiStepForwardAndContinueWalking()
      throws SimulationExceededMaximumTimeException, InterruptedException,
          ControllerFailureException {
    BambooTools.reportTestStartedMessage(simulationTestingParameters.getShowWindows());
    setupTest(getRobotModel());
    SimulationConstructionSet scs = drcFlatGroundWalkingTrack.getSimulationConstructionSet();
    setForwardPushParameters();
    Vector3d forceDirection = new Vector3d(1.0, 0.0, 0.0);
    blockingSimulationRunner = new BlockingSimulationRunner(scs, 1000.0);
    BooleanYoVariable walk =
        (BooleanYoVariable) scs.getVariable("ComponentBasedFootstepDataMessageGenerator", "walk");

    // disable walking
    walk.set(false);
    blockingSimulationRunner.simulateAndBlock(4.0);

    // push the robot
    pushRobotController.applyForceDelayed(
        pushCondition, PUSH_DELAY, forceDirection, forceMagnitude, forceDuration);

    // simulate for a little while longer
    blockingSimulationRunner.simulateAndBlock(forceDuration + 6.0);

    // re-enable walking
    walk.set(true);
    blockingSimulationRunner.simulateAndBlock(6.0);

    Point3d center = new Point3d(0.0, 0.0, 0.8882009563211146);
    Vector3d plusMinusVector =
        new Vector3d(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, 0.5);
    BoundingBox3d boundingBox =
        BoundingBox3d.createUsingCenterAndPlusMinusVector(center, plusMinusVector);
    DRCSimulationTestHelper.assertRobotsRootJointIsInBoundingBox(
        boundingBox, drcFlatGroundWalkingTrack.getDrcSimulation().getRobot());

    createVideo(scs);
    BambooTools.reportTestFinishedMessage(simulationTestingParameters.getShowWindows());
  }
  public static void addCube(
      double cubeX, double cubeY, double cubeSize, Color color, SimulationConstructionSet scs) {
    final double CUBE_HEIGHT = 0.001;
    // Make cubes a tiny bit smaller so they don't blend together.
    cubeSize *= 0.9;

    Graphics3DObject linkGraphics = new Graphics3DObject();
    linkGraphics.translate(new Vector3d(cubeX, cubeY, CUBE_HEIGHT));
    linkGraphics.addCube(
        cubeSize, cubeSize, cubeSize, new YoAppearanceRGBColor(new Color3f(color), 0.0));

    scs.addStaticLinkGraphics(linkGraphics);
  }
 private FloatingJoint getRootJoint(SimulationConstructionSet scs0) {
   Joint firstRootJoint = scs0.getRobots()[0].getRootJoints().get(0);
   if (firstRootJoint instanceof FloatingJoint) return (FloatingJoint) firstRootJoint;
   throw new RuntimeException("first root joint is not a floating joint: " + firstRootJoint);
 }
  public StewartPlatformSimulation() {
    StewartPlatformRobot StewartPlatform = new StewartPlatformRobot("StewartPlatform");
    StewartPlatform.setController(
        new StewartPlatformController(StewartPlatform, "stewartPlatformSimulation"));
    sim = new SimulationConstructionSet(StewartPlatform);

    StewartPlatform.setGravity(0.0); // -9.81);

    // StewartPlatform View:
    // sim.setCameraFix(45.0,0.0,18.0);
    // sim.setCameraPosition(-64.0,100.0,8.0);

    sim.setDT(0.0004, 50);

    sim.setCameraTracking(false, true, true, false);
    sim.setCameraDolly(false, true, true, false);

    // Set up some graphs and entry boxes:

    sim.setupGraph(new String[] {"q_platform_x", "q_d_x"});
    sim.setupGraph(new String[] {"q_platform_y", "q_d_y"});
    sim.setupGraph(new String[] {"q_platform_z", "q_d_z"});

    sim.setupGraph(new String[] {"q_yaw", "q_d_yaw"});
    sim.setupGraph(new String[] {"q_roll", "q_d_roll"});
    sim.setupGraph(new String[] {"q_pitch", "q_d_pitch"});

    // sim.setupGraph("q_ball_z");
    // sim.setupGraph(new String[]{"qd_ball_x", "qd_ball_z"} );

    // sim.setupEntryBox("k_loop");
    // sim.setupEntryBox("b_loop");
    // sim.setupEntryBox("Fx");
    // sim.setupEntryBox("Fy");
    // sim.setupEntryBox("Fz");

    // sim.setupEntryBox("q_d_x");sim.setupEntryBox("q_d_y");sim.setupEntryBox("q_d_z");
    // sim.setupEntryBox("k_x");sim.setupEntryBox("k_y");sim.setupEntryBox("k_z");
    // sim.setupEntryBox("b_x");sim.setupEntryBox("b_y");sim.setupEntryBox("b_z");

    sim.setupEntryBox("x_amp");
    sim.setupEntryBox("y_amp");
    sim.setupEntryBox("z_amp");
    sim.setupEntryBox("x_freq");
    sim.setupEntryBox("y_freq");
    sim.setupEntryBox("z_freq");
    sim.setupEntryBox("y_phase");

    // Start the simulation
    Thread myThread = new Thread(sim);
    myThread.start();
  }
  public GraphArrayWindow(
      AllCommandsExecutor allCommandsExecutor,
      SimulationConstructionSet sim,
      GUIEnablerAndDisabler guiEnablerAndDisabler,
      ConfigurationList configurationList,
      GraphGroupList graphGroupList,
      String graphGroupName,
      GraphConfigurationList graphConfigurationList,
      SelectedVariableHolder selectedVariableHolder,
      DataBuffer dataBuffer,
      StandardGUIActions mainGUIActions,
      int screenID,
      Point windowLocation,
      Dimension windowSize,
      boolean maximizeWindow) {
    this.configurationList = configurationList;
    this.graphGroupList = graphGroupList;
    this.graphConfigurationList = graphConfigurationList;

    GraphicsConfiguration configurationToUse = null;
    GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] devices = graphicsEnvironment.getScreenDevices();
    for (int j = 0; j < devices.length; j++) {
      // GraphicsDevice graphicsDevice = devices[j];
      if (devices[j].toString().indexOf("screen=" + screenID) >= 0)
        configurationToUse = devices[j].getDefaultConfiguration();
    }

    String windowName;

    if (graphGroupName != null) {
      windowName = "Graph Window: " + graphGroupName;
      this.name = graphGroupName;
    } else {
      windowName = "Graph Window";
      this.name = "Unnamed";
    }

    frame = new JFrame(windowName, configurationToUse);
    frame.setName(windowName);
    myGraphArrayPanel = new GraphArrayPanel(selectedVariableHolder, dataBuffer, frame);

    windowGUIActions = new StandardGUIActions();

    SaveGraphConfigurationDialogConstructor saveGraphConfigurationDialogConstructor =
        new SaveGraphConfigurationDialogGenerator(guiEnablerAndDisabler, frame, myGraphArrayPanel);

    LoadGraphGroupDialogConstructor loadGraphGroupDialogConstructor =
        new LoadGraphGroupDialogGenerator(
            sim, sim.getStandardSimulationGUI(), this, frame, myGraphArrayPanel);

    PrintGraphsDialogConstructor printGraphsDialogConstructor =
        new PrintGraphsDialogGenerator(myGraphArrayPanel);

    ExportGraphsToFileConstructor exportGraphsToFileConstructor;
    if (USE_CSV_INSTEAD_OF_MATLAB) {
      exportGraphsToFileConstructor =
          new CsvExportGraphsToFileGenerator(
              sim, frame, myGraphArrayPanel, sim.getStandardSimulationGUI());
    } else {
      exportGraphsToFileConstructor =
          new MatlabExportGraphsToFileGenerator(
              sim, frame, myGraphArrayPanel, sim.getStandardSimulationGUI());
    }

    windowGUIActions.createGraphWindowActions(
        mainGUIActions,
        myGraphArrayPanel,
        saveGraphConfigurationDialogConstructor,
        loadGraphGroupDialogConstructor,
        printGraphsDialogConstructor,
        exportGraphsToFileConstructor);
    JPanel buttonPanel = windowGUIActions.createGraphWindowButtons();
    JMenuBar menuBar = windowGUIActions.createGraphWindowMenus();

    frame.setJMenuBar(menuBar);

    frame.getContentPane().add(buttonPanel, "South");

    JPanel graphArrayAndButtonPanel = new JPanel(new java.awt.BorderLayout());
    graphArrayAndButtonPanel.add("Center", myGraphArrayPanel);

    JPanel graphButtonPanel = myGraphArrayPanel.createGraphButtonPanel();
    graphArrayAndButtonPanel.add("South", graphButtonPanel);

    frame.getContentPane().add(graphArrayAndButtonPanel);

    this.selectGraphGroup(graphGroupName);

    if (windowLocation != null) frame.setLocation(windowLocation);

    frame.pack();

    if (maximizeWindow) {
      frame.setExtendedState(Frame.MAXIMIZED_BOTH);
    } else if (windowSize != null) frame.setSize(windowSize);

    frame.setVisible(true);
  }