-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d11826b
commit b52b752
Showing
12 changed files
with
365 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/org/nschmidt/ldparteditor/data/BinaryDataRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* MIT - License | ||
Copyright (c) 2012 - this year, Nils Schmidt | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | ||
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | ||
package org.nschmidt.ldparteditor.data; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.nschmidt.ldparteditor.logger.NLogger; | ||
|
||
class BinaryDataRegistry { | ||
|
||
private final Map<String, GDataBinary> fileNameToMetaTagMap = new HashMap<>(); | ||
private final Map<String, byte[]> fileNameToBinaryMap = new HashMap<>(); | ||
|
||
public boolean hasFile(String filename) { | ||
return fileNameToMetaTagMap.containsKey(filename) | ||
|| fileNameToBinaryMap.containsKey(filename); | ||
} | ||
|
||
public byte[] getFileBytes(String filename) { | ||
if (fileNameToBinaryMap.containsKey(filename)) { | ||
return fileNameToBinaryMap.getOrDefault(filename, new byte[0]); | ||
} | ||
|
||
final GDataBinary dataMetaTag = fileNameToMetaTagMap.get(filename); | ||
final byte[] binary = dataMetaTag.loadBinary(); | ||
fileNameToBinaryMap.put(filename, binary); | ||
fileNameToMetaTagMap.remove(filename); | ||
|
||
return binary; | ||
} | ||
|
||
public void addData(GDataBinary dataMetaTag) { | ||
NLogger.debug(BinaryDataRegistry.class, "Register binary !DATA: {0}", dataMetaTag); //$NON-NLS-1$ | ||
// "0 !DATA " has a length of 8 | ||
final String filename = dataMetaTag.toString().substring(8); | ||
NLogger.debug(BinaryDataRegistry.class, "The filename is: {0}", filename); //$NON-NLS-1$ | ||
fileNameToMetaTagMap.put(filename, dataMetaTag); | ||
fileNameToBinaryMap.remove(filename); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
/* MIT - License | ||
Copyright (c) 2012 - this year, Nils Schmidt | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | ||
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | ||
package org.nschmidt.ldparteditor.data; | ||
|
||
import java.util.Base64; | ||
import java.util.Map; | ||
import java.util.regex.Pattern; | ||
|
||
import org.nschmidt.ldparteditor.composite.Composite3D; | ||
import org.nschmidt.ldparteditor.helper.math.ThreadsafeHashMap; | ||
import org.nschmidt.ldparteditor.helper.math.ThreadsafeSortedMap; | ||
import org.nschmidt.ldparteditor.logger.NLogger; | ||
|
||
/** | ||
* Holds binary base64 encoded data | ||
*/ | ||
public final class GDataBinary extends GData { | ||
|
||
private final DatFile df; | ||
|
||
public GDataBinary(String text, DatFile df, GData1 parent) { | ||
super(parent); | ||
this.df = df; | ||
this.text = text; | ||
this.df.getBinaryData().addData(this); | ||
} | ||
|
||
public byte[] loadBinary() { | ||
final Pattern whitespace = Pattern.compile("\\s+"); //$NON-NLS-1$ | ||
final StringBuilder base64Sb = new StringBuilder(); | ||
|
||
GData gd = this.next; | ||
while (gd != null) { | ||
final String line = whitespace.matcher(gd.toString()).replaceAll(" ").trim(); //$NON-NLS-1$ | ||
if (line.startsWith("0 !: ")) { //$NON-NLS-1$ | ||
final String encodedSubstring = line.substring(5); | ||
base64Sb.append(encodedSubstring); | ||
} else if (line.length() > 0) { | ||
break; | ||
} | ||
|
||
gd = gd.next; | ||
} | ||
|
||
final String encodedString = base64Sb.toString(); | ||
|
||
try { | ||
return Base64.getDecoder().decode(encodedString); | ||
} catch (IllegalArgumentException iae) { | ||
NLogger.debug(GDataBinary.class, iae); | ||
} | ||
|
||
return new byte[0]; | ||
} | ||
|
||
@Override | ||
public void drawGL20(Composite3D c3d) { | ||
// Implementation is not required. | ||
} | ||
|
||
@Override | ||
public void drawGL20RandomColours(Composite3D c3d) { | ||
// Implementation is not required. | ||
} | ||
|
||
@Override | ||
public void drawGL20BFC(Composite3D c3d) { | ||
// Implementation is not required. | ||
} | ||
|
||
@Override | ||
public void drawGL20BFCuncertified(Composite3D c3d) { | ||
// Implementation is not required. | ||
} | ||
|
||
@Override | ||
public void drawGL20BFCbackOnly(Composite3D c3d) { | ||
// Implementation is not required. | ||
} | ||
|
||
@Override | ||
public void drawGL20BFCcolour(Composite3D c3d) { | ||
// Implementation is not required. | ||
} | ||
|
||
@Override | ||
public void drawGL20WhileAddCondlines(Composite3D c3d) { | ||
// Implementation is not required. | ||
} | ||
|
||
@Override | ||
public void drawGL20CoplanarityHeatmap(Composite3D c3d) { | ||
// Implementation is not required. | ||
} | ||
|
||
@Override | ||
public void drawGL20Wireframe(Composite3D c3d) { | ||
// Implementation is not required. | ||
} | ||
|
||
@Override | ||
public void drawGL20BFCtextured(Composite3D c3d) { | ||
// Implementation is not required. | ||
} | ||
|
||
@Override | ||
public int type() { | ||
return 11; | ||
} | ||
|
||
@Override | ||
String getNiceString() { | ||
return text; | ||
} | ||
|
||
@Override | ||
public String inlinedString(BFC bfc, GColour colour) { | ||
return text; | ||
} | ||
|
||
@Override | ||
public String transformAndColourReplace(String colour, Matrix matrix) { | ||
return text; | ||
} | ||
|
||
@Override | ||
public void getBFCorientationMap(Map<GData,BFC> map) { | ||
// Implementation is not required. | ||
} | ||
|
||
@Override | ||
public void getBFCorientationMapNOCERTIFY(Map<GData, BFC> map) { | ||
// Implementation is not required. | ||
} | ||
|
||
@Override | ||
public void getBFCorientationMapNOCLIP(Map<GData, BFC> map) { | ||
// Implementation is not required. | ||
} | ||
|
||
@Override | ||
public void getVertexNormalMap(GDataState state, ThreadsafeSortedMap<Vertex, float[]> vertexLinkedToNormalCACHE, ThreadsafeHashMap<GData, float[]> dataLinkedToNormalCACHE, VM00Base vm) { | ||
// Implementation is not required. | ||
} | ||
|
||
@Override | ||
public void getVertexNormalMapNOCERTIFY(GDataState state, ThreadsafeSortedMap<Vertex, float[]> vertexLinkedToNormalCACHE, ThreadsafeHashMap<GData, float[]> dataLinkedToNormalCACHE, VM00Base vm) { | ||
// Implementation is not required. | ||
} | ||
|
||
@Override | ||
public void getVertexNormalMapNOCLIP(GDataState state, ThreadsafeSortedMap<Vertex, float[]> vertexLinkedToNormalCACHE, ThreadsafeHashMap<GData, float[]> dataLinkedToNormalCACHE, VM00Base vm) { | ||
// Implementation is not required. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/org/nschmidt/ldparteditor/helper/compositetext/DataMetacommandExporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.nschmidt.ldparteditor.helper.compositetext; | ||
|
||
/* MIT - License | ||
Copyright (c) 2012 - this year, Nils Schmidt | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | ||
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | ||
|
||
import org.nschmidt.ldparteditor.data.DatFile; | ||
import org.nschmidt.ldparteditor.data.GData; | ||
import org.nschmidt.ldparteditor.data.GDataBinary; | ||
import org.nschmidt.ldparteditor.helper.math.HashBiMap; | ||
|
||
/** | ||
* Exports !DATA meta-commands to a file (PNG only) | ||
*/ | ||
public enum DataMetacommandExporter { | ||
INSTANCE; | ||
|
||
/** | ||
* Exports selected !DATA meta-commands to a file (PNG only) | ||
* | ||
* @param lineStart | ||
* start line number to export | ||
* @param lineEnd | ||
* end line number to export | ||
* @param datFile | ||
*/ | ||
public static void export(int lineStart, int lineEnd, DatFile datFile) { | ||
HashBiMap<Integer, GData> dpl = datFile.getDrawPerLineNoClone(); | ||
lineEnd++; | ||
for (int line = lineStart; line < lineEnd; line++) { | ||
final GData data = dpl.getValue(line); | ||
if (data instanceof GDataBinary gd) { | ||
// TODO Needs implementation! | ||
System.out.println(data); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.