Skip to content

Commit

Permalink
v1.0 basic - fine tune
Browse files Browse the repository at this point in the history
  • Loading branch information
enocholumide committed Oct 7, 2017
1 parent c6a82f2 commit 0230d15
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 102 deletions.
Binary file modified Laserscan-to-dxf_v1.0_basic.jar
Binary file not shown.
1 change: 1 addition & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/tester/
/toolkit/
167 changes: 65 additions & 102 deletions src/tester/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import core.MemoryTextField;
import core.Point3D;
import core.RadioButton;
import toolkit.Toolset;

import javax.swing.JTextField;
import javax.swing.JButton;
Expand Down Expand Up @@ -279,12 +280,11 @@ public void actionPerformed(ActionEvent arg0) {
rdbtnOther.setBounds(6, 50, 60, 23);
delimeterButtonGroup.add(rdbtnOther);
delimeterAndSeparatorPanel.add(rdbtnOther);

rdbtnOther.addItemListener(new ItemListener() {

@Override
public void itemStateChanged(ItemEvent e) {

if (e.getStateChange() == ItemEvent.SELECTED) {
otherDelimeter.setEnabled(true);
otherDelimeter.setEditable(true);
Expand All @@ -307,28 +307,18 @@ else if (e.getStateChange() == ItemEvent.DESELECTED) {
otherDelimeter.getDocument().addDocumentListener(new DocumentListener() {

@Override
public void changedUpdate(DocumentEvent e) {
// TODO Auto-generated method stub

}
public void changedUpdate(DocumentEvent e) {}

@Override
public void insertUpdate(DocumentEvent e) {
// TODO Auto-generated method stub
//rdbtnOther.setUserData(otherDelimeter.getText());
public void insertUpdate(DocumentEvent e) {;
rdbtnOther.setActionCommand(otherDelimeter.getText());
}

@Override
public void removeUpdate(DocumentEvent e) {
// TODO Auto-generated method stub

}
public void removeUpdate(DocumentEvent e) {}

});



JPanel panel_7 = new JPanel();
panel_7.setToolTipText("<html>\r\nSpecify custom decimal separator<br>\r\ne.g.<br> \r\n50.02 -> point <br>\r\n50,02 -> comma<br>\r\n</html>");
panel_7.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Decimal separator", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
Expand Down Expand Up @@ -435,9 +425,9 @@ public void removeUpdate(DocumentEvent e) {

@Override
public void itemStateChanged(ItemEvent e) {
// TODO Auto-generated method stub

if (e.getStateChange() == ItemEvent.SELECTED) {
getDataInfo();
getDataStatistics();
} else if(e.getStateChange() == ItemEvent.DESELECTED) {

}
Expand Down Expand Up @@ -516,7 +506,7 @@ public void itemStateChanged(ItemEvent e) {
@Override
public void actionPerformed(ActionEvent e) {

createSCRFromPTS(ptsFile);
generateDXF(ptsFile);

}

Expand All @@ -526,13 +516,12 @@ public void actionPerformed(ActionEvent e) {

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
int returnVal = dirChooser.showOpenDialog(Converter.this);

if(returnVal == JFileChooser.APPROVE_OPTION) {
textOutputDir.setText(dirChooser.getCurrentDirectory().getAbsolutePath()+"\\"+fileChooser.getName(fileChooser.getSelectedFile())+".dxf");
}
}

});

btnUpload.addActionListener(new ActionListener() {
Expand All @@ -556,11 +545,8 @@ public void actionPerformed(ActionEvent arg0) {
btnDownload.setEnabled(true);
btnDownload.setForeground(SystemColor.textHighlightText);
btnDownload.setBackground(SystemColor.infoText);

setDataReader();


} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Expand All @@ -575,19 +561,15 @@ public void actionPerformed(ActionEvent arg0) {
fileChooser.setFileFilter(filter);
}

protected void getDataInfo() {

//------------------
double minX = 0.0;
double minY = 0.0;
double maxX = 0.0;
double maxY = 0.0;
//------------------
/**
* Computes the statistics of the data, mean, average etc
* Method not yet completed for the v1.0 basic. Therefore data statistics not yet available.
*/
private void getDataStatistics() {

List<Double> xValues = new ArrayList<Double>();
List<Double> yValues = new ArrayList<Double>();


if(reader!=null) {

while (true) {
Expand Down Expand Up @@ -634,8 +616,8 @@ protected void getDataInfo() {

}

System.out.println(xValues.get(findMinIndex(xValues)));
System.out.println(yValues.get(findMinIndex(yValues)));
System.out.println(xValues.get(Toolset.findMinIndex(xValues)));
System.out.println(yValues.get(Toolset.findMinIndex(yValues)));

/*this.minX.addToList(String.valueOf(minX));
this.minY.addToList(String.valueOf(minY));
Expand All @@ -649,58 +631,31 @@ protected void getDataInfo() {

}

public static <T extends Comparable<T>> int findMinIndex(final List<T> xs) {
int minIndex;
if (xs.isEmpty()) {
minIndex = -1;
} else {
final ListIterator<T> itr = xs.listIterator();
T min = itr.next(); // first element as the current minimum
minIndex = itr.previousIndex();
while (itr.hasNext()) {
final T curr = itr.next();
if (curr.compareTo(min) < 0) {
min = curr;
minIndex = itr.previousIndex();
}
}
}
return minIndex;
}

protected void setDataReader() {

FileReader isr = null;
try {
isr = new FileReader(ptsFile);
} catch (FileNotFoundException e) {
System.err.println("File not found in res; don't use any extension");
}

this.reader = new BufferedReader(isr);

}

protected void createSCRFromPTS(File ptsFile) {
/**
* Generates .dxf file
* @param inputFIle uploaded laserscan file.
*/
private void generateDXF(File inputFIle) {

long lStartTime = System.nanoTime();

//scrFile = new File(textField.getText()+".scr");
dxfFile = new File(textOutputDir.getText());

//BufferedWriter writer = null;
BufferedReader reader = null;
BufferedReader inputFileBufferedReader = null;
FileReader inputFileReader = null;

FileReader isr = null;
try {
isr = new FileReader(ptsFile);
inputFileReader = new FileReader(inputFIle);
} catch (FileNotFoundException e) {
System.err.println("File not found in res; don't use any extension");
System.err.println("Cannot read input file.");
JOptionPane.showMessageDialog(null, "Something went wrong!"
+ "\nCannot read input file", "Fatal error", JOptionPane.ERROR_MESSAGE);
}

reader = new BufferedReader(isr);


inputFileBufferedReader = new BufferedReader(inputFileReader);

String line;
boolean success = true;

Expand All @@ -712,11 +667,15 @@ protected void createSCRFromPTS(File ptsFile) {
writeDXFHeader();
dxf.write("\n0\nSECTION\n2\nENTITIES");

// Ignoring writing .scr file
// This was the first atemot before deciding to wrte dxf file directly
// Disabling it to reduce the processing time for writing the dxf file.

/*writer = new BufferedWriter(new FileWriter(scrFile));
writer.write("_MULTIPLE _POINT");
writer.newLine();*/

int start = 1;
int start = Integer.parseInt(startNumberChkbox.getTextField().getText());
int nextProcessedNumber = 0;
int intervalFactor = 0;

Expand All @@ -733,7 +692,7 @@ protected void createSCRFromPTS(File ptsFile) {


while (true) {
line = reader.readLine();
line = inputFileBufferedReader.readLine();

if( start <= count) {
if(count == nextProcessedNumber) {
Expand All @@ -752,15 +711,14 @@ protected void createSCRFromPTS(File ptsFile) {
Double.parseDouble(currentLine[0]),
Double.parseDouble(currentLine[1]),
Double.parseDouble(currentLine[2])
);
);
point.setColor(new Color(
Integer.parseInt(currentLine[3]),
Integer.parseInt(currentLine[4]),
Integer.parseInt(currentLine[5]),
Integer.parseInt(currentLine[6])));
Integer.parseInt(currentLine[6])
));

writeDXFPoint(point);

//System.out.println(nextProcessedNumber);
if(intervalIsSelected) {
nextProcessedNumber = count + intervalFactor;
Expand Down Expand Up @@ -793,16 +751,17 @@ protected void createSCRFromPTS(File ptsFile) {

} catch (IOException e) {
success = false;
System.err.println("Error reading the file");
e.printStackTrace();
//String[] error = e.getMessage().split("(");
System.err.println("Fata Error");
JOptionPane.showMessageDialog(null, "An error has occured.\nError: "
+ e.getMessage(), "System Error", JOptionPane.ERROR_MESSAGE);
}

finally{
try {
//System.out.println(processedPoints);
//writer.close();

// End dxf writer
// End dxf writer
dxf.write("\n0");
dxf.write("\nEOF");
dxf.close();
Expand All @@ -814,36 +773,40 @@ protected void createSCRFromPTS(File ptsFile) {
if(success) {

long lEndTime = System.nanoTime();
//time elapsed
long output = lEndTime - lStartTime;
long timeElapsed = lEndTime - lStartTime;

JOptionPane.showMessageDialog(null, "Operation Successful!"
+ "\nTotal of " + processedPoints + " points processed"
+ "\nElapsed time in milliseconds: " + output / 1000000, "Finished", JOptionPane.INFORMATION_MESSAGE);
+ "\nElapsed time in milliseconds: " + timeElapsed / 1000000, "Finished", JOptionPane.INFORMATION_MESSAGE);

if(openDxfCheckBox.isSelected()) {
try {
Desktop.getDesktop().open(this.dxfFile);
handleWindowClosingEvent();
if(Desktop.isDesktopSupported()) {
Desktop.getDesktop().open(this.dxfFile);
handleWindowClosingEvent();
}else {
JOptionPane.showMessageDialog(null, "Error: Cannot open dxf file.", "Error", JOptionPane.ERROR_MESSAGE);
}

} catch (IOException e) {
// TODO Auto-generated catch block

e.printStackTrace();
}
}

} else {
JOptionPane.showMessageDialog(null, "Something NOT Successful", "Error", JOptionPane.ERROR_MESSAGE);
}


}
}


/**
* Writes the header of the d.xf file. To be called once in the writing process.
*/
private void writeDXFHeader() {

try {
dxf.write("999");
dxf.write("\nDXF created from <PTS to Dxf Converter> by <Olumide Igbiloba>\n999\nAll rights reserved (c)2017");
dxf.write("\nDXF created from <Laserscan-to-dxf converter> by <Olumide Igbiloba>\n999\n(c)2017 All rights reserved");
dxf.write("\n0\nSECTION");
dxf.write("\n2\nHEADER");
dxf.write("\n9\n$ACADVER\n1");
Expand Down Expand Up @@ -882,12 +845,9 @@ private void writeDXFHeader() {
}
}

private void getNextIntervalPoint() {

}

/**
*
* Writes an instance of point to a dxf file
* @param point
*/
private void writeDXFPoint(Point3D point) {
Expand Down Expand Up @@ -919,7 +879,10 @@ private void writeDXFPoint(Point3D point) {
e.printStackTrace();
}
}


/**
* Closes the application.
*/
protected void handleWindowClosingEvent() {
// TODO Auto-generated method stub
dispose();
Expand Down
37 changes: 37 additions & 0 deletions src/toolkit/Toolset.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package toolkit;

import java.util.List;
import java.util.ListIterator;

/**
* General functions
* @author Olumide Igbiloba
*
*/
public class Toolset {

/**
* Finds minimum index in a list
* @param xs
* @return
*/
public static <T extends Comparable<T>> int findMinIndex(final List<T> xs) {
int minIndex;
if (xs.isEmpty()) {
minIndex = -1;
} else {
final ListIterator<T> itr = xs.listIterator();
T min = itr.next(); // first element as the current minimum
minIndex = itr.previousIndex();
while (itr.hasNext()) {
final T curr = itr.next();
if (curr.compareTo(min) < 0) {
min = curr;
minIndex = itr.previousIndex();
}
}
}
return minIndex;
}

}

0 comments on commit 0230d15

Please sign in to comment.