Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuation config #42

Merged
merged 2 commits into from
Dec 4, 2024
Merged
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
21 changes: 11 additions & 10 deletions IOT/config.ini
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
[adress]
broker=mqtt.iut-blagnac.fr
port=1883
topics=AM107/by-room/+/data,solaredge/blagnac/overview
sauvegarde=result.json
broker = mqtt.iut-blagnac.fr
port = 1883
topics = AM107/by-room/+/data,solaredge/blagnac/overview
sauvegarde = result.json

[donnees]
salles=E209,B112,E007,amphi1,E001,B108
donnees=temperature,co2
temps=60
salles = C001,B105,B002,amphi1
temps = 60
donnees = humidity,temperature,illumintation,infrared_and_visible

[seuil]
humidity=10,100
temperature=18.0,22.3
co2=120.0,990.0
humidity = 10,100
temperature = 18.0,22.3
co2 = 120.0,990.0

58 changes: 7 additions & 51 deletions JavaFxApp/JavaFxApp/appData.json
Original file line number Diff line number Diff line change
@@ -1,54 +1,10 @@
{
"roomNames": [
"B103",
"E101",
"E207",
"E209",
"B111",
"B234",
"B113",
"E104",
"E006",
"E003",
"B112",
"B217",
"C002",
"E001",
"B108",
"C102",
"E007",
"B203",
"amphi1",
"E208",
"E210",
"E106",
"E004",
"B001",
"B202",
"C004",
"Foyer-personnels",
"Local-velo",
"B201",
"C001",
"B109",
"B002",
"Salle-conseil",
"Foyer-etudiants-entrée",
"C101",
"B105",
"E100",
"C006",
"hall-amphi",
"E102",
"E103",
"B110",
"hall-entrée-principale",
"B106",
"B005",
"E105",
"B107"
],
"config": {
"winiFilePath": "C:\\Users\\Dell\\Documents\\Fichiers Persos\\Studies\\BUT Info\\S3\\SAÉS\\Temp\\sae-3-01-devapp-2024-2025-g1b4\\IOT"
"B103","E101","E207","E209","B111","B234","B113","E104","E006","E003","B112","B217","C002","E001","B108","C102","E007","B203","amphi1","E208","E210","E106","E004","B001","B202","C004","Foyer-personnels","Local-velo","B201","C001","B109","B002","Salle-conseil","Foyer-etudiants-entrée","C101","B105","E100","C006","hall-amphi","E102","E103","B110","hall-entrée-principale","B106","B005","E105","B107"],
"config":{
"winiFilePath":"./../../IOT/config.ini"
},
"communes": {
"selectedRooms":[]
}
}
}
6 changes: 1 addition & 5 deletions JavaFxApp/JavaFxApp/src/main/java/org/javafxapp/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@

public class Main {

// List des salles connues d'où collecter les données
public static List<String> knownRooms=new ArrayList<>();
static{
knownRooms.addAll(List.of(new String[]{"B005", "C105"}));
}

public static final String appDataPath="./appData.json";

public static void main(String[] args) {
MainMenu.main2(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,29 @@
import javafx.stage.Modality;
import javafx.stage.Stage;

import org.ini4j.Profile;
import org.ini4j.Wini;
import org.javafxapp.tools.JsonInteract;
import org.javafxapp.tools.StageManagement;
import org.javafxapp.view.ConfigFormViewController;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.javafxapp.tools.StageManagement;
import org.javafxapp.view.ConfigFormViewController;


public class ConfigForm {
private Stage configStage;
private ConfigFormViewController cFVM;
public ConfigForm(Stage appStage) {

this.roomChoice=new ArrayList<>();
this.dataChoice=new ArrayList<>();

try {
FXMLLoader loader = new FXMLLoader(ConfigFormViewController.class.getResource("configFormView.fxml"));
BorderPane root = loader.load();
Expand Down Expand Up @@ -52,30 +57,77 @@ public void doConfigFormDialog() {
JsonInteract jsInt=new JsonInteract();
try{
this.wini=new Wini(new File((String)jsInt.get("config.winiFilePath")));

loadRoomData:{
String data = wini.get("donnees", "salles");

if (data == null)
break loadRoomData;

String[] rooms = data.split(",");

if (rooms.length < 1)
break loadRoomData;

this.roomChoice.addAll(Arrays.asList(rooms));

}

String data=wini.get("donnees","donnees");

if(data!=null)
this.dataChoice.addAll(Arrays.asList(data.split(",")));

}catch(IOException e){
Alert alert=new Alert(Alert.AlertType.ERROR, "Le fichier de configuration(config.ini) est introuvable!! Vérifiez le chemin(appData.json)!!");
alert.show();
e.printStackTrace();
}

this.dataChoice=this.cFVM.displayDialog(this.wini);
if(!this.dataChoice.isEmpty())
this.dataChoice=this.cFVM.displayDialog(this.dataChoice);
if(!this.dataChoice.isEmpty() && !this.roomChoice.isEmpty())
this.alterConfigFile();
cFVM.displayDialog(wini);
}

private void alterConfigFile() {

public void openRoomPicker() {
RoomPicker rp=new RoomPicker(this.configStage);
rp.doRoomPickerDialog();
}

private void alterConfigFile() {
String choixDonnees=this.dataChoice.toString();
choixDonnees=choixDonnees.substring(1,choixDonnees.length()-1);

String choixSalles=this.roomChoice.toString();
choixSalles=choixSalles.substring(1,choixSalles.length()-1);

this.wini.put("donnees","donnees",choixDonnees.replaceAll("\\s",""));
this.wini.put("donnees","salles",choixSalles.replaceAll("\\s", ""));

try {
this.wini.store();
} catch (IOException e) {
Alert alert=new Alert(Alert.AlertType.ERROR,"Le fichier config n'a pas pu être modifié!!");
alert.show();
e.printStackTrace();
}
}

public void openRoomPicker() {
RoomPicker rp=new RoomPicker(this.configStage);
this.roomChoice=rp.doRoomPickerDialog(this.roomChoice);


private List<String> roomChoice;
private List<String> dataChoice;

private List<String> seuils;

public void getSeuilSelection(List<String> selectedData) {

loadData:{
Map<String,String> sec=wini.get("seuil");

for(Map.Entry<String,String> entry : sec.entrySet()){
System.out.println(entry.getKey() + " : " + entry.getValue());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class MainMenu extends Application {

private Stage appStage;
@Override
public void start(Stage stage) throws Exception {
public void start(Stage stage) {
this.appStage=stage;

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javafx.scene.layout.BorderPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import org.ini4j.Wini;
import org.javafxapp.tools.StageManagement;
import org.javafxapp.view.ConfigFormViewController;
import org.javafxapp.view.RoomPickerViewController;
Expand Down Expand Up @@ -38,7 +39,7 @@ public RoomPicker(Stage appStage) {
}
}

public List<String> doRoomPickerDialog() {
return this.rPVM.displayDialog();
public List<String> doRoomPickerDialog(List<String> rooms) {
return this.rPVM.displayDialog(rooms);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.javafxapp.Main;
import org.json.*;

public class JsonInteract {
Expand Down Expand Up @@ -41,7 +43,7 @@ public void properClose(){
this.appData.put("roomNames",this.alRoomData);

try {
Files.writeString(Paths.get("./appData.json"),this.appData.toString());
Files.writeString(Paths.get(Main.appDataPath),this.appData.toString());
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package org.javafxapp.view;

import impl.org.controlsfx.autocompletion.AutoCompletionTextFieldBinding;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.CheckBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import org.ini4j.Wini;
import org.javafxapp.controller.ConfigForm;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -32,17 +31,11 @@ public void initContext(Stage appStage, ConfigForm configForm) {
this.appStage.setOnCloseRequest(this::closeWindow);
this.selectedData=new ArrayList<>();
}
public List<String> displayDialog(List<String> data) {
this.selectedData=data;
if (!this.selectedData.isEmpty()) {

public List<String> displayDialog(Wini wini) {
loadData:{
String data=wini.get("donnees","donnees");
this.selectedData.addAll(Arrays.asList(data.split(",")));


if (this.selectedData.isEmpty())
break loadData;

ObservableList<Node> checkBoxes=this.getSelectChildren();
ObservableList<Node> checkBoxes = this.getAllCheckBoxes();
CheckBox checkBox;

for (Node nd : checkBoxes) {
Expand All @@ -56,14 +49,15 @@ public List<String> displayDialog(Wini wini) {
return this.selectedData;
}

private ObservableList<Node> getSelectChildren() {
ObservableList<Node> hBoxes= this.selection.getChildren();
ObservableList<Node> allChildren;
for(Node nd: hBoxes)
;
private ObservableList<Node> getAllCheckBoxes() {
ObservableList<Node> sons=this.selection.getChildren();
ObservableList<Node> grandSons=FXCollections.observableList(new ArrayList<>());

return null;
for(Node nd : sons)
if(nd instanceof HBox)
grandSons.addAll(((HBox)nd).getChildren());

return grandSons;
}

/**
Expand All @@ -85,8 +79,9 @@ public void properClose(){
}

private void getSelection() {
ObservableList<Node> checkBoxes = selection.getChildren();
ObservableList<Node> checkBoxes = this.getAllCheckBoxes();
CheckBox checkBox;
this.selectedData.clear();

for (Node nd : checkBoxes) {
checkBox=(CheckBox)nd;
Expand All @@ -102,7 +97,7 @@ private void getSelection() {
}

@FXML
HBox selection;
VBox selection;

@FXML
public void doOpenRoom(){
Expand All @@ -112,24 +107,19 @@ public void doOpenRoom(){
@FXML
public void doConfirm(){
this.getSelection();

this.conFormLoader.getSeuilSelection(this.selectedData);

this.properClose();
}

@FXML
public void doCancel(){
this.selectedData.clear();
this.properClose();
}

public static void main(String[] args) {
Wini wini= null;
try {
wini = new Wini(new File("C:\\Users\\Dell\\Documents\\Fichiers Persos\\Studies\\BUT Info\\S3\\SAÉS\\Temp\\sae-3-01-devapp-2024-2025-g1b4\\IOT\\config.ini"));
} catch (IOException e) {
throw new RuntimeException(e);
Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "Les modifications seront abandonnées!! Êtes-vous certain de vouloir annuler?");
alert.showAndWait();
if(alert.getResult()== ButtonType.OK) {
this.selectedData.clear();
this.properClose();
}

System.out.println(wini.get("donnees","donnees"));

}
}
Loading
Loading