Commit 40b1196c authored by THEBAULT Antoine's avatar THEBAULT Antoine
Browse files

add the one step function

parent ee71350c
/application/
/scheme.fxml
/storSim/
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="529.0" prefWidth="626.0" scaleShape="false" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Main">
<children>
<TextField fx:id="textField" layoutX="218.0" layoutY="77.0" prefHeight="31.0" prefWidth="55.0" />
<Label layoutX="27.0" layoutY="82.0" text="Enter the number of steps :" />
<Button layoutX="280.0" layoutY="77.0" mnemonicParsing="false" onAction="#startSim" text="Ok" />
<MenuBar prefHeight="32.0" prefWidth="626.0">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" onAction="#loadFile" text="Load file" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit" />
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
<Button layoutX="27.0" layoutY="40.0" mnemonicParsing="false" onAction="#oneStep" text="Step" />
<TitledPane fx:id="transitionsPane" animated="false" layoutX="27.0" layoutY="125.0" prefHeight="374.0" prefWidth="283.0" text="transitions">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</TitledPane>
<TitledPane fx:id="placesPane" animated="false" layoutX="329.0" layoutY="125.0" prefHeight="374.0" prefWidth="283.0" text="places">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</TitledPane>
</children>
<opaqueInsets>
<Insets />
</opaqueInsets>
</Pane>
package application;
import java.io.File;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Rectangle2D;
import javafx.stage.FileChooser;
import javafx.stage.Screen;
import javafx.stage.Stage;
import storSim.sim;
import javafx.scene.Parent;
import javafx.scene.Scene;
/*import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;*/
import javafx.scene.control.TextField;
/**
* load the xml file scheme.fxml which contains the user interface
* control the events which can occur on the interface
* display the user interface
*/
public class Main extends Application {
Stage primaryStage;
/**the file of the network to be loaded for the simulation*/
File netFile;
/**get the textfield which contains the number of steps to simulate*/
@FXML
TextField textField;
/**load the file of the petrinet to simulate*/
@FXML
private void loadFile(ActionEvent event) {
event.consume();
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open Resource File");
netFile = fileChooser.showOpenDialog(primaryStage);
}
/**start the simulation after Ok is clicked and the number of steps is provided*/
@FXML
private void startSim(ActionEvent event) {
event.consume();
System.out.println("start");
int steps = Integer.parseInt(textField.getText());
String netFileUrl = netFile.getAbsolutePath();
sim.main(steps, netFileUrl);
}
@FXML
private void oneStep(ActionEvent event) {
event.consume();
String netFileUrl = netFile.getAbsolutePath();
sim.oneStep(netFileUrl);
}
/**load the start interface*/
@Override
public void start(Stage primaryStage) {
public void start(Stage stage) {
try {
/*BorderPane root = new BorderPane();
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
String javaVersion = System.getProperty("java.version");
String javafxVersion = System.getProperty("javafx.version");
Label l = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
scene = new Scene(new StackPane(l), 640, 480);
primaryStage.setScene(scene);
primaryStage.show();*/
primaryStage = stage;
//load the xml file of the user interface
primaryStage.setScene(new Scene((Parent) JfxUtils.loadFxml("../scheme.fxml"), 1024, 968));
primaryStage.setScene(new Scene((Parent) JfxUtils.loadFxml("../scheme.fxml"), 1024, 800));
//set up the width and height of the window
Rectangle2D bounds = Screen.getPrimary().getVisualBounds();
primaryStage.setWidth(bounds.getWidth());
//primaryStage.setWidth(bounds.getWidth());
primaryStage.setHeight(bounds.getHeight());
primaryStage.setTitle("StorSim");
......@@ -51,4 +88,5 @@ public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
}
......@@ -6,11 +6,37 @@
<?import javafx.scene.layout.*?>
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="381.0" prefWidth="413.0" scaleShape="false" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller">
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="529.0" prefWidth="626.0" scaleShape="false" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Main">
<children>
<TextField fx:id="textField" layoutX="215.0" layoutY="19.0" prefHeight="31.0" prefWidth="55.0" />
<Label layoutX="27.0" layoutY="24.0" text="Enter the number of steps :" />
<Button layoutX="280.0" layoutY="19.0" mnemonicParsing="false" onAction="#start" text="Ok" />
<TextField fx:id="textField" layoutX="218.0" layoutY="77.0" prefHeight="31.0" prefWidth="55.0" />
<Label layoutX="27.0" layoutY="82.0" text="Enter the number of steps :" />
<Button layoutX="280.0" layoutY="77.0" mnemonicParsing="false" onAction="#startSim" text="Ok" />
<MenuBar prefHeight="32.0" prefWidth="626.0">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" onAction="#loadFile" text="Load file" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit" />
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
<Button layoutX="27.0" layoutY="40.0" mnemonicParsing="false" onAction="#oneStep" text="Step" />
<TitledPane fx:id="transitionsPane" animated="false" layoutX="27.0" layoutY="125.0" prefHeight="374.0" prefWidth="283.0" text="transitions">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</TitledPane>
<TitledPane fx:id="placesPane" animated="false" layoutX="329.0" layoutY="125.0" prefHeight="374.0" prefWidth="283.0" text="places">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</TitledPane>
</children>
<opaqueInsets>
<Insets />
......
......@@ -10,9 +10,7 @@ public class sim {
// currently : number of blocked transitions at each step
long simtot; // total of blocked transitions during the simulation
long elapsedTime;
static sim s = null;
sim(int nb, String fname){
nbsteps=nb;
......@@ -46,18 +44,28 @@ public class sim {
}
public static void oneStep (String netFileUrl) {
if (s==null) {
s=new sim(1, netFileUrl);
// read a net from a file
s.n.drop();
}
s.move();
s.simtot += s.n.blocked.size();
s.siminfo.add(s.n.blocked.size());
}
public static void main(int step) {
public static void main(int steps, String netFileUrl) {
// TODO Auto-generated method stub
sim s=new sim(step,"reseau2.net");
s=new sim(steps, netFileUrl);
// read a net from a file
s.n.drop();
long beg = System.currentTimeMillis();
for(int i=1;i<10000;i++){
//for(int i=1;i<10000;i++){
for(int i=1;i<=steps;i++){
s.move();
//s.n.drop();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment