From b326756ddd7eee426d7d0e93a485ec30b6fbb5fd Mon Sep 17 00:00:00 2001 From: ?? ? <ulysseskao@ximple.com.tw> Date: Tue, 20 Apr 2010 19:27:20 +0800 Subject: [PATCH] dgn7 write function for complex chain --- xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 102 insertions(+), 5 deletions(-) diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java index e82fc83..91f0198 100644 --- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java +++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java @@ -13,11 +13,11 @@ import com.ximple.util.DgnUtility; /** - * Record + * FileRecord * * @author Ulysses * @version 0.1 - * @since 2006/5/18 �W�� 11:14:50 + * @since 2006/5/18 �W�� 11:14:50 */ public class Element { public static final int CONSTRUCTION_CLASS = 0; @@ -36,8 +36,9 @@ protected short[] raw; protected byte attrOffset = 0; protected ByteBuffer rawBuffer; + protected boolean newElement = false; - public Element(byte[] raw) { + Element(byte[] raw) { // this.raw = raw; this.raw = new short[raw.length / 2]; rawBuffer = ByteBuffer.wrap(raw); @@ -47,6 +48,13 @@ public int getLineStyle() { return (raw[17] & 0x0007); + } + + protected void setLineStyle(int value) { + if (value > -1 && value < 8) + raw[17] = (short) ((raw[17] & 0xfff8) | (value & 0x0007)); + else + new IllegalArgumentException("Out of Range!"); } public Envelope getRange() { @@ -92,6 +100,10 @@ return (short) ((raw[0] >>> 7) & 0x0001) == 1; } + protected void setComponentElement(boolean value) { + raw[0] = (short) ((raw[0] & 0xff7f) | (value ? 0x0080 : 0x0)); + } + public boolean removeUserAttributeData(int iLinkageId) { return true; } @@ -104,12 +116,27 @@ return (short) ((raw[0] >>> 15) & 0x0001) == 1; } + protected void setDeleted(boolean value) { + raw[0] = (short) ((raw[0] & 0x7fff) | ((((value) ? 1 : 0) << 15) & 0x8000)); + } + public int getColorIndex() { return ((raw[17] >>> 8) & 0x00ff); } + protected void setColorIndex(int value) { + if (value > -1 && value < 256) + { + raw[17] = (short) ((raw[17] & 0x00ff) | (value << 8 & 0xff00)); + } else new IllegalArgumentException("Out of Range!"); + } + public int getType() { return ((raw[0] >>> 8) & 0x007f); + } + + protected void setType(int value) { + raw[0] = (short) ((raw[0] & 0x80ff) | (value << 8) & 0x3f00); } public ElementType getElementType() { @@ -231,7 +258,7 @@ public Exception() { } - // Constructs an Record.Exception with no detail message. + // Constructs an ElementRecord.Exception with no detail message. public Exception(String oStrMessage) { super(oStrMessage); } @@ -263,7 +290,7 @@ return elementType; } - public Object read(ByteBuffer buffer, short signature, int length) { + public Element read(ByteBuffer buffer, short signature, int length) { byte[] dst = new byte[length]; try { buffer.get(dst, 4, dst.length - 4); @@ -306,4 +333,74 @@ return new Element(raw); } } + + public static final class FileRecord { + int length; + int number = 0; + int offset; // Relative to the whole file + int start = 0; // Relative to the current loaded buffer + short signature = 0; + + /** + * The minimum X value. + */ + public double minX; + + /** + * The minimum Y value. + */ + public double minY; + + /** + * The minimum Z value. + */ + public double minZ; + + /** + * The maximum X value. + */ + public double maxX; + + /** + * The maximum Y value. + */ + public double maxY; + + /** + * The maximum Z value. + */ + public double maxZ; + + // ElementType type; + int end = 0; // Relative to the whole file + Object element = null; + IElementHandler handler; + ByteBuffer buffer; + + public Object element() { + if (element == null) { + buffer.position(start); + buffer.order(ByteOrder.LITTLE_ENDIAN); + + if (handler == null) { + return null; + } + + element = handler.read(buffer, signature, length); + } + + return element; + } + + public int offset() { + return offset; + } + + /** + * A summary of the record. + */ + public String toString() { + return "FileRecord " + number + " length " + length + " bounds " + minX + "," + minY + " " + maxX + "," + maxY; + } + } } -- Gitblit v0.0.0-SNAPSHOT