Skip to content

Commit b496f6a

Browse files
U354706U354706
authored andcommitted
18/09/2021 : Possibilité de créer des formules à partir de calibration
1 parent 8e81625 commit b496f6a

17 files changed

Lines changed: 566 additions & 73 deletions

images/icon_selectMap_24.png

483 Bytes
Loading

resources/news.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
<html>
22

3+
<b><font size =+1><font color=blue># 16/09/2021 : Version V1.5</font></b>
4+
<ul>
5+
<li>Possibilit&eacute; de cr&eacute;er une formule &agrave; partir d'un param&egrave;tre de calibration
6+
<li>Correction de bugs
7+
</ul>
8+
9+
<hr align=center size=1 width="100%">
10+
311
<b><font size =+1><font color=blue># 29/08/2021 : Version V1.4</font></b>
412
<ul>
513
<li>Remplacement des fichiers de configuration *.cfg par un format xml

resources/notice.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@ Quelques notes sur l'utilisation :
1414
- défilement de la plage de temps une fois zoomée : bouton "ctrl" + bouton gauche souris + déplacement gauche/droite
1515
- le bouton "Synchroniser les axes des abcisses" permet d'avoir la même plage de temps sur toutes les fenêtres
1616

17+
- fichiers de calibration (*.map) :
18+
- il est possible d'ouvrir plusieurs fichiers dans l'arborescence
19+
- un menu contextuel s'ouvre en faisant un click droit sur un fichier map ou une variable (export du fichier map sous diverses formes)
20+
- les paramètres de calibration sont éditables de manière analytique ou graphique
21+
1722
- formules : elles seront enregistrées avec le fichier de oonfiguration
1823
- ex : #RPM(tr/min)#/120, les "#" sont importants pour que les variables soient bien détectées.
24+
- il est possible de se servir d'un parmètre de calibration, par exemple : TABLE2D{Avance base,RPM(tr/min),Intake_manifold_P(mbar)}
1925

2026
- conditions : elles permettent de mettre en surbrillance certaines zones de l'acquisitions
2127
- ex : #RPM(tr/min)#>4000 && #Throttle_angle()#==90
2228
- opérateurs utilisés : && (ET), || (OU), <, <=, >, >=, == (EGALE), != (NON EGALE)
23-
29+
30+
2431
Certaines fonctionnalités sont encore en cours de codage donc il y a des petits bugs trainent, n'hésitez pas à recharger le log si quelque chose ne se passent pas correctement.
2532

2633
Bug ou demande d'évolution ==> kraillon26@gmail.com

src/calib/MapCal.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public final class MapCal {
5252
private final String name;
5353
private final List<Variable> listVariable;
5454
private MdbData mdbData;
55+
private boolean usedByFormula = false;
5556

5657
public MapCal(File mapFile) {
5758
this.name = mapFile.getName().replace(".map", "");
@@ -115,11 +116,33 @@ public MdbData getMdbData() {
115116
return mdbData;
116117
}
117118

119+
public boolean isUsedByFormula() {
120+
return usedByFormula;
121+
}
122+
123+
public void setUsedByFormula(boolean usedByFormula) {
124+
this.usedByFormula = usedByFormula;
125+
}
126+
127+
@Override
128+
public String toString() {
129+
return this.name;
130+
}
131+
118132
public List<Variable> getListVariable() {
119133
Collections.sort(listVariable);
120134
return listVariable;
121135
}
122136

137+
public final Variable getVariable(String name) {
138+
for (Variable var : listVariable) {
139+
if (name.equals(var.getName())) {
140+
return var;
141+
}
142+
}
143+
return null;
144+
}
145+
123146
public static final boolean toCdfx(List<Variable> listVariable, final File file) {
124147

125148
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();

src/calib/Variable.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,19 @@ public final class Variable extends Observable implements Comparable<Variable> {
2323
private Object[] newValues;
2424
private VariableInfo infos;
2525

26+
private String[] args;
27+
2628
public Variable(List<String> data, MdbData mdbData) {
2729
this.name = data.get(0).substring(1, data.get(0).length() - 1);
2830
this.infos = mdbData.getInfos().get(this.name);
2931

3032
// System.out.println(this.name);
3133

3234
build(data);
35+
36+
if ("Avance base".equals(name)) {
37+
args = new String[] { "RPM(tr/min)", "Intake_manifold_P(mbar)" };
38+
}
3339
}
3440

3541
public String getName() {
@@ -45,6 +51,10 @@ public String toString() {
4551
return this.name;
4652
}
4753

54+
public String[] getArgs() {
55+
return args;
56+
}
57+
4858
public boolean isTextValue() {
4959
return this.infos != null ? this.infos.getTypeVar() == 1 : false;
5060
}
@@ -88,15 +98,7 @@ public final double getResolution() {
8898
return this.infos != null ? 1.0 / this.infos.getFactor() : 1.0 / 32768.0;
8999
}
90100

91-
public final boolean checkResolution(Object value) {
92-
double div = (Double.parseDouble(value.toString())) / getResolution();
93-
int rnd = (int) ((Double.parseDouble(value.toString())) / getResolution());
94-
double res = div - rnd;
95-
// return div - rnd == 0;
96-
return true;
97-
}
98-
99-
public boolean checkDim() {
101+
public final boolean checkDim() {
100102

101103
if (infos != null) {
102104
switch (this.type) {
@@ -118,15 +120,15 @@ public boolean checkDim() {
118120
return true;
119121
}
120122

121-
public Object getValue(boolean modifiedVar, int... coord) {
123+
public final Object getValue(boolean modifiedVar, int... coord) {
122124
int idx = coord[1] + dimX * coord[0];
123125
if (!modifiedVar) {
124126
return this.values[idx];
125127
}
126128
return this.newValues[idx];
127129
}
128130

129-
public void setValue(boolean newVal, Object value, int... coord) {
131+
public final void setValue(boolean newVal, Object value, int... coord) {
130132
int idx = coord[1] + dimX * coord[0];
131133
if (!newVal) {
132134
this.values[idx] = value;
@@ -136,7 +138,7 @@ public void setValue(boolean newVal, Object value, int... coord) {
136138

137139
}
138140

139-
public void backToRefValue() {
141+
public final void backToRefValue() {
140142
this.newValues = null;
141143
setChanged();
142144
notifyObservers();
@@ -339,7 +341,6 @@ public int compareTo(Variable var) {
339341
public final Object saturateValue(Object value) {
340342
if (value instanceof Number) {
341343
double val = ((Number) value).doubleValue();
342-
// double valWithResol = Utilitaire.applyResolution(val, getResolution());
343344
Double saturatedVal = Math.max(Math.min(val, getMax()), getMin());
344345
return saturatedVal;
345346
}

src/dialog/DialManageFormula.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ public DialManageFormula(final Ihm ihm) {
8080

8181
@Override
8282
public void actionPerformed(ActionEvent arg0) {
83+
84+
if (listModel.isEmpty()) {
85+
return;
86+
}
87+
8388
int res = JOptionPane.showConfirmDialog(null, "Voulez-vous supprimer cette formule?", "Question", JOptionPane.YES_NO_OPTION);
8489
if (res == JOptionPane.YES_OPTION) {
8590
ihm.deleteMeasure(listFormula.getSelectedValue());

src/dialog/DialNewFormula.java

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
import org.jfree.data.xy.XYSeries;
3636
import org.jfree.data.xy.XYSeriesCollection;
3737

38+
import calib.MapCal;
39+
import calib.Variable;
3840
import gui.Ihm;
41+
import gui.MapView;
3942
import log.Formula;
4043
import log.Measure;
4144

@@ -123,11 +126,36 @@ public boolean canImport(TransferSupport support) {
123126
@Override
124127
public boolean importData(TransferSupport supp) {
125128
Transferable t = supp.getTransferable();
129+
126130
String data = "";
127131
try {
128132
data = (String) t.getTransferData(DataFlavor.stringFlavor);
129133

130-
if (!data.equals(Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null).getTransferData(DataFlavor.stringFlavor))) {
134+
MapView mapView = ((Ihm) DialNewFormula.this.getParent()).getMapView();
135+
136+
Variable var = null;
137+
138+
if (mapView != null && mapView.isVisible()) {
139+
140+
MapCal calib = mapView.findSelectedCal();
141+
142+
if (calib != null && calib.isUsedByFormula()) {
143+
var = calib.getVariable(data);
144+
} else {
145+
int res = JOptionPane.showConfirmDialog(null,
146+
"La fichier \"" + calib + "\"" + " n'a pas \u00e9t\u00e9 défini comme r\u00e9f\u00e9rence, le faire?", "INFO",
147+
JOptionPane.YES_NO_OPTION);
148+
if (res == JOptionPane.YES_OPTION) {
149+
mapView.setCalForFormula(calib.getName());
150+
var = calib.getVariable(data);
151+
} else {
152+
return false;
153+
}
154+
}
155+
}
156+
157+
if (!data.equals(Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null).getTransferData(DataFlavor.stringFlavor))
158+
&& var == null) {
131159
data = "#" + data + "#";
132160
}
133161

@@ -139,7 +167,13 @@ public boolean importData(TransferSupport supp) {
139167
e.printStackTrace();
140168
}
141169

142-
formulaText.insert(data, formulaText.getCaretPosition());
170+
int caretPosition = formulaText.getCaretPosition();
171+
172+
if (checkAccolades(caretPosition)) {
173+
formulaText.insert(data.replace("#", ""), formulaText.getCaretPosition());
174+
} else {
175+
formulaText.insert(data, formulaText.getCaretPosition());
176+
}
143177

144178
return true;
145179
}
@@ -191,7 +225,7 @@ public boolean importData(TransferSupport supp) {
191225
@Override
192226
public void actionPerformed(ActionEvent arg0) {
193227

194-
Formula newFormula = new Formula(txtName.getText(), txtUnit.getText(), formulaText.getText(), ihm.getLog());
228+
Formula newFormula = new Formula(txtName.getText(), txtUnit.getText(), formulaText.getText(), ihm.getLog(), ihm.getSelectedCal());
195229
if (ihm.getLog() != null && newFormula.isValid()) {
196230
XYSeriesCollection dataset = (XYSeriesCollection) chartPanel.getChart().getXYPlot().getDataset();
197231
XYSeries serie = dataset.getSeries(0);
@@ -224,7 +258,7 @@ public void actionPerformed(ActionEvent arg0) {
224258
public void actionPerformed(ActionEvent arg0) {
225259

226260
if (formula == null) {
227-
Formula newFormula = new Formula(txtName.getText(), txtUnit.getText(), formulaText.getText(), ihm.getLog());
261+
Formula newFormula = new Formula(txtName.getText(), txtUnit.getText(), formulaText.getText(), ihm.getLog(), ihm.getSelectedCal());
228262
if (!ihm.getListFormula().contains(newFormula)) {
229263
if (newFormula.isValid()) {
230264
ihm.addMeasure(newFormula);
@@ -237,7 +271,7 @@ public void actionPerformed(ActionEvent arg0) {
237271
formula.setName(txtName.getText());
238272
formula.setUnit(txtUnit.getText());
239273
formula.setExpression(formulaText.getText());
240-
formula.calculate(ihm.getLog());
274+
formula.calculate(ihm.getLog(), ihm.getSelectedCal());
241275
dispose();
242276
}
243277

@@ -273,12 +307,42 @@ public void actionPerformed(ActionEvent arg0) {
273307
setVisible(true);
274308
}
275309

310+
private boolean checkAccolades(int caretPosition) {
311+
312+
final char accoladeOuvrante = '{';
313+
final char accoladeFermante = '}';
314+
315+
final String text = formulaText.getText();
316+
final int textLength = text.length();
317+
318+
if (text.isEmpty() || textLength == caretPosition || caretPosition == 0) {
319+
return false;
320+
}
321+
322+
int idx1 = caretPosition;
323+
int idx2 = caretPosition;
324+
325+
do {
326+
if (text.charAt(idx1--) == accoladeOuvrante) {
327+
break;
328+
}
329+
} while (idx1 == 0);
330+
331+
do {
332+
if (text.charAt(idx2++) == accoladeFermante) {
333+
break;
334+
}
335+
} while (idx2 == textLength - 1);
336+
337+
return idx2 > idx1 && idx1 != 0 && idx2 != textLength - 1;
338+
}
339+
276340
private final JPanel createPad() {
277-
String[] tab_string = new String[] { "^", "sqrt()", "cos()", "sin()", "tan()", "+", "-", "*", "/", ".", "0", "1", "2", "3", "4", "5", "6",
278-
"7", "8", "9" };
341+
String[] tab_string = new String[] { "SCALAIRE{}", "TABLE1D{,}", "TABLE2D{,,}", "^", "sqrt()", "cos()", "sin()", "tan()", "+", "-", "*", "/",
342+
".", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
279343
JButton[] tab_button = new JButton[tab_string.length];
280344

281-
JPanel pad = new JPanel(new GridLayout(4, 5));
345+
JPanel pad = new JPanel(new GridLayout(6, 5));
282346

283347
for (int i = 0; i < tab_string.length; i++) {
284348
tab_button[i] = new JButton(tab_string[i]);
@@ -296,6 +360,13 @@ public void actionPerformed(ActionEvent e) {
296360
String str = ((JButton) e.getSource()).getText();
297361
formulaText.insert(str, formulaText.getCaretPosition());
298362

363+
int caretPosition = formulaText.getCaretPosition();
364+
365+
if (str.indexOf('(') > -1 || str.indexOf('{') > -1) {
366+
caretPosition--;
367+
}
368+
formulaText.requestFocusInWindow();
369+
formulaText.setCaretPosition(caretPosition);
299370
}
300371

301372
}

src/dialog/DialogProperties.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import javax.swing.JColorChooser;
2525
import javax.swing.JComboBox;
2626
import javax.swing.JDialog;
27+
import javax.swing.JOptionPane;
2728
import javax.swing.JPanel;
2829
import javax.swing.JScrollPane;
2930
import javax.swing.JTable;
@@ -157,6 +158,7 @@ public Dimension getPreferredScrollableViewportSize() {
157158
XYItemRenderer renderer;
158159

159160
final DecimalFormat formatter = new DecimalFormat();
161+
formatter.setGroupingUsed(false);
160162
DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols();
161163
decimalFormatSymbols.setDecimalSeparator('.');
162164
formatter.setDecimalFormatSymbols(decimalFormatSymbols);
@@ -211,10 +213,12 @@ public final void updatePlot(ChartView chartView, XYPlot xyPlot) {
211213
double lowerBound = Double.parseDouble(splitRange[0]);
212214
double upperBound = Double.parseDouble(splitRange[1]);
213215
Range newRange = new Range(lowerBound, upperBound);
214-
if (!xyPlot.getDomainAxis().getRange().equals(newRange)) {
216+
if (!xyPlot.getDomainAxis().getRange().equals(newRange) && upperBound - lowerBound > 0) {
215217
xyPlot.getDomainAxis().setRange(newRange);
216218
}
217219
} catch (NumberFormatException e) {
220+
JOptionPane.showMessageDialog(this, "Il y a un probl\u00e8me de synthaxe sur les valeurs min/max de l'axe X.", "Erreur",
221+
JOptionPane.ERROR_MESSAGE);
218222
}
219223
}
220224

@@ -228,10 +232,12 @@ public final void updatePlot(ChartView chartView, XYPlot xyPlot) {
228232
double lowerBound = Double.parseDouble(splitRange[0]);
229233
double upperBound = Double.parseDouble(splitRange[1]);
230234
Range newRange = new Range(lowerBound, upperBound);
231-
if (!axis.getRange().equals(newRange)) {
235+
if (!axis.getRange().equals(newRange) && upperBound - lowerBound > 0) {
232236
axis.setRange(newRange);
233237
}
234238
} catch (NumberFormatException e) {
239+
JOptionPane.showMessageDialog(this, "Il y a un probl\u00e8me de synthaxe sur les valeurs min/max de l'axe Y.", "Erreur",
240+
JOptionPane.ERROR_MESSAGE);
235241
}
236242
}
237243
}

0 commit comments

Comments
 (0)