Revision 33
org.gvsig.dxf/tags/org.gvsig.dxf-2.0.19/org.gvsig.dxf.lib/src/main/java/org/gvsig/dxf/io/DataSource.java | ||
---|---|---|
1 |
/* |
|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications. |
|
3 |
* |
|
4 |
* Copyright (C) 2004-5. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
19 |
* |
|
20 |
* For more information, contact: |
|
21 |
* |
|
22 |
* cresques@gmail.com |
|
23 |
*/ |
|
24 |
package org.gvsig.dxf.io; |
|
25 |
|
|
26 |
import java.util.Hashtable; |
|
27 |
|
|
28 |
|
|
29 |
/** |
|
30 |
* Origen de datos. Unidad, volumen de red, etc. |
|
31 |
* |
|
32 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es> |
|
33 |
*/ |
|
34 |
public class DataSource { |
|
35 |
private static int counter = 0; |
|
36 |
private static Hashtable units = new Hashtable(); |
|
37 |
String path = null; |
|
38 |
String name = null; |
|
39 |
|
|
40 |
public DataSource(String path, String name) { |
|
41 |
this.path = path; |
|
42 |
this.name = name; |
|
43 |
units.put(name, this); |
|
44 |
} |
|
45 |
|
|
46 |
public String getName() { |
|
47 |
return name; |
|
48 |
} |
|
49 |
|
|
50 |
public String getPath() { |
|
51 |
return path; |
|
52 |
} |
|
53 |
|
|
54 |
public static DataSource getDSFromName(String name) { |
|
55 |
if (name.indexOf("[") >= 0) { |
|
56 |
name = name.substring(name.indexOf("[") + 1); |
|
57 |
} |
|
58 |
|
|
59 |
if (name.indexOf("]") >= 0) { |
|
60 |
name = name.substring(0, name.indexOf("]")); |
|
61 |
} |
|
62 |
|
|
63 |
DataSource ds = (DataSource) units.get(name); |
|
64 |
|
|
65 |
return ds; |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* Sustituye en el path el nombre de la unidad por su path real. |
|
70 |
* |
|
71 |
* @param path |
|
72 |
* @return |
|
73 |
*/ |
|
74 |
public static String normalize(String path) { |
|
75 |
if (path.indexOf("[") >= 0) { |
|
76 |
DataSource ds = DataSource.getDSFromName(path); |
|
77 |
|
|
78 |
if (ds == null) { |
|
79 |
return null; |
|
80 |
} |
|
81 |
|
|
82 |
path = path.substring(0, path.indexOf("[")) + ds.getPath() + |
|
83 |
path.substring(path.indexOf("]") + 1); |
|
84 |
|
|
85 |
} |
|
86 |
|
|
87 |
return path; |
|
88 |
} |
|
89 |
|
|
90 |
public String toString() { |
|
91 |
return "[" + counter + "]"; |
|
92 |
} |
|
93 |
} |
org.gvsig.dxf/tags/org.gvsig.dxf-2.0.19/org.gvsig.dxf.lib/src/main/java/org/gvsig/dxf/io/GeoFile.java | ||
---|---|---|
1 |
/* |
|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications. |
|
3 |
* |
|
4 |
* Copyright (C) 2004-5. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
19 |
* |
|
20 |
* For more information, contact: |
|
21 |
* |
|
22 |
* cresques@gmail.com |
|
23 |
*/ |
|
24 |
package org.gvsig.dxf.io; |
|
25 |
|
|
26 |
import java.awt.geom.AffineTransform; |
|
27 |
import java.util.Date; |
|
28 |
|
|
29 |
import org.cresques.cts.ICoordTrans; |
|
30 |
import org.cresques.cts.IProjection; |
|
31 |
import org.cresques.geo.Projected; |
|
32 |
import org.cresques.px.Extent; |
|
33 |
import org.gvsig.dxf.px.IObjList; |
|
34 |
|
|
35 |
|
|
36 |
/** |
|
37 |
* Ancestro de todos los formatos geogr?ficos |
|
38 |
* |
|
39 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador |
|
40 |
*/ |
|
41 |
public abstract class GeoFile implements Projected, Extent.Has { |
|
42 |
IProjection proj = null; |
|
43 |
/** |
|
44 |
* Extent completo del raster. Este contiene las coordenadas reales tanto |
|
45 |
* para un raster rotado como sin rotar. Este extent coincide con requestExtent |
|
46 |
* cuando el raster no tiene rotaci?n. |
|
47 |
*/ |
|
48 |
protected Extent extent = null; |
|
49 |
/** |
|
50 |
* Este es el extent sobre el que se ajusta una petici?n para que esta no exceda el |
|
51 |
* extent m?ximo del raster. Para un raster sin rotar ser? igual al extent |
|
52 |
* pero para un raster rotado ser? igual al extent del raster como si no |
|
53 |
* tuviera rotaci?n. Esto ha de ser as? ya que la rotaci?n solo se hace sobre la |
|
54 |
* vista y las peticiones han de hacerse en coordenadas de la imagen sin shearing |
|
55 |
* aplicado. |
|
56 |
*/ |
|
57 |
protected Extent requestExtent = null; |
|
58 |
/** |
|
59 |
* Esto corresponde a la transformaci?n del extent de la imagen. Se calcula a partir del extent |
|
60 |
* guardado en el fichero .rmf asociado a la imagen. En caso de que no exista este fichero no habr? |
|
61 |
* transformaci?n |
|
62 |
*/ |
|
63 |
protected AffineTransform transformRMF = null; |
|
64 |
/** |
|
65 |
* Esto corresponde a la transformaci?n del extent de la imagen. Se calcula a partir del extent |
|
66 |
* guardado en el fichero .tfw asociado a la imagen o en la cabecera de la misma. |
|
67 |
*/ |
|
68 |
protected AffineTransform transformTFW = null; |
|
69 |
|
|
70 |
|
|
71 |
protected boolean rmfExists = false; |
|
72 |
long fileSize = 0; |
|
73 |
protected long bytesReaded = 0; |
|
74 |
protected long lineCnt = 0; |
|
75 |
String name; |
|
76 |
|
|
77 |
public GeoFile() { |
|
78 |
} |
|
79 |
|
|
80 |
public GeoFile(IProjection p, String n) { |
|
81 |
proj = p; |
|
82 |
name = n; |
|
83 |
|
|
84 |
if (name != null) { |
|
85 |
name = DataSource.normalize(name); |
|
86 |
} |
|
87 |
extent = new Extent(); |
|
88 |
transformRMF = new AffineTransform(); |
|
89 |
transformTFW = new AffineTransform(); |
|
90 |
} |
|
91 |
|
|
92 |
public String getName() { |
|
93 |
return name; |
|
94 |
} |
|
95 |
|
|
96 |
public void setName(String n) { |
|
97 |
name = n; |
|
98 |
} |
|
99 |
|
|
100 |
public long getFileSize() { |
|
101 |
return fileSize; |
|
102 |
} |
|
103 |
|
|
104 |
public void setFileSize(long sz) { |
|
105 |
fileSize = sz; |
|
106 |
} |
|
107 |
|
|
108 |
public IProjection getProjection() { |
|
109 |
return proj; |
|
110 |
} |
|
111 |
|
|
112 |
public void setProjection(IProjection p) { |
|
113 |
proj = p; |
|
114 |
} |
|
115 |
|
|
116 |
abstract public void reProject(ICoordTrans rp); |
|
117 |
|
|
118 |
/** |
|
119 |
* Extent completo del raster. Este contiene las coordenadas reales tanto |
|
120 |
* para un raster rotado como sin rotar. Este extent coincide con requestExtent |
|
121 |
* cuando el raster no tiene rotaci?n. |
|
122 |
* @return Extent |
|
123 |
*/ |
|
124 |
public Extent getExtent() { |
|
125 |
return extent; |
|
126 |
} |
|
127 |
|
|
128 |
/** |
|
129 |
* Este es el extent sobre el que se ajusta una petici?n para que esta no exceda el |
|
130 |
* extent m?ximo del raster. Para un raster sin rotar ser? igual al extent |
|
131 |
* pero para un raster rotado ser? igual al extent del raster como si no |
|
132 |
* tuviera rotaci?n. Esto ha de ser as? ya que la rotaci?n solo se hace sobre la |
|
133 |
* vista y las peticiones han de hacerse en coordenadas de la imagen sin shearing |
|
134 |
* aplicado. |
|
135 |
* @return Extent |
|
136 |
*/ |
|
137 |
public Extent getExtentForRequest() { |
|
138 |
return requestExtent; |
|
139 |
} |
|
140 |
|
|
141 |
abstract public GeoFile load() throws Exception; |
|
142 |
|
|
143 |
abstract public void close(); |
|
144 |
|
|
145 |
abstract public IObjList getObjects(); |
|
146 |
|
|
147 |
/** |
|
148 |
* Filtra espacios en blanco. Deja solo uno por |
|
149 |
*/ |
|
150 |
public static String filterWS(String buf) { |
|
151 |
boolean lastCharWhite = false; |
|
152 |
String str = ""; |
|
153 |
buf = buf.trim(); |
|
154 |
|
|
155 |
for (int i = 0; i < buf.length(); i++) { |
|
156 |
char c = buf.charAt(i); |
|
157 |
|
|
158 |
if (Character.isWhitespace(c)) { |
|
159 |
if (lastCharWhite) { |
|
160 |
continue; |
|
161 |
} |
|
162 |
|
|
163 |
lastCharWhite = true; |
|
164 |
c = ' '; |
|
165 |
} else { |
|
166 |
lastCharWhite = false; |
|
167 |
} |
|
168 |
|
|
169 |
str += c; |
|
170 |
} |
|
171 |
|
|
172 |
return str; |
|
173 |
} |
|
174 |
|
|
175 |
protected long getTime() { |
|
176 |
return (new Date()).getTime(); |
|
177 |
} |
|
178 |
} |
org.gvsig.dxf/tags/org.gvsig.dxf-2.0.19/org.gvsig.dxf.lib/src/main/java/org/gvsig/dxf/io/FileFolder.java | ||
---|---|---|
1 |
/* |
|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications. |
|
3 |
* |
|
4 |
* Copyright (C) 2004-5. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
19 |
* |
|
20 |
* For more information, contact: |
|
21 |
* |
|
22 |
* cresques@gmail.com |
|
23 |
*/ |
|
24 |
package org.gvsig.dxf.io; |
|
25 |
|
|
26 |
|
|
27 |
/** |
|
28 |
* |
|
29 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador |
|
30 |
*/ |
|
31 |
abstract public class FileFolder { |
|
32 |
static String[] supportedFolders = { "zip://" }; |
|
33 |
|
|
34 |
abstract public int count(); |
|
35 |
|
|
36 |
/** |
|
37 |
* Analiza un nombre de fichero en formato zip://zipname.zip?file.ext |
|
38 |
* @param urlName |
|
39 |
*/ |
|
40 |
public static boolean isUrl(String name) { |
|
41 |
String str = name.substring(0, 6); |
|
42 |
str.toLowerCase(); |
|
43 |
|
|
44 |
for (int i = 0; i < supportedFolders.length; i++) |
|
45 |
if (str.compareTo(supportedFolders[i]) == 0) { |
|
46 |
return true; |
|
47 |
} |
|
48 |
|
|
49 |
return false; |
|
50 |
} |
|
51 |
} |
org.gvsig.dxf/tags/org.gvsig.dxf-2.0.19/org.gvsig.dxf.lib/src/main/java/org/gvsig/dxf/io/DxfGroup.java | ||
---|---|---|
1 |
/* |
|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications. |
|
3 |
* |
|
4 |
* Copyright (C) 2004-5. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
19 |
* |
|
20 |
* For more information, contact: |
|
21 |
* |
|
22 |
* cresques@gmail.com |
|
23 |
*/ |
|
24 |
package org.gvsig.dxf.io; |
|
25 |
|
|
26 |
import java.io.BufferedReader; |
|
27 |
import java.io.IOException; |
|
28 |
import java.text.DecimalFormat; |
|
29 |
import java.text.DecimalFormatSymbols; |
|
30 |
import java.util.Locale; |
|
31 |
|
|
32 |
|
|
33 |
/** |
|
34 |
* Grupo Dxf (code, data). Auxiliar para leer ficheros dxf |
|
35 |
* |
|
36 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es> |
|
37 |
* @author "Michel Michaud" (code from) |
|
38 |
*/ |
|
39 |
public class DxfGroup { |
|
40 |
/* |
|
41 |
def get_group(handle): |
|
42 |
_code = int(handle.readline()) |
|
43 |
_dfun = get_data_type(_code) |
|
44 |
_data = _dfun(handle.readline()) |
|
45 |
return (_code, _data) |
|
46 |
*/ |
|
47 |
private static final DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US); |
|
48 |
private static final DecimalFormat[] decimalFormats = new DecimalFormat[] { |
|
49 |
new DecimalFormat("#0", |
|
50 |
dfs), |
|
51 |
new DecimalFormat("#0.0", |
|
52 |
dfs), |
|
53 |
new DecimalFormat("#0.00", |
|
54 |
dfs), |
|
55 |
new DecimalFormat("#0.000", |
|
56 |
dfs), |
|
57 |
new DecimalFormat("#0.0000", |
|
58 |
dfs), |
|
59 |
new DecimalFormat("#0.00000", |
|
60 |
dfs), |
|
61 |
new DecimalFormat("#0.000000", |
|
62 |
dfs), |
|
63 |
new DecimalFormat("#0.0000000", |
|
64 |
dfs), |
|
65 |
new DecimalFormat("#0.00000000", |
|
66 |
dfs), |
|
67 |
new DecimalFormat("#0.000000000", |
|
68 |
dfs), |
|
69 |
new DecimalFormat("#0.0000000000", |
|
70 |
dfs), |
|
71 |
new DecimalFormat("#0.00000000000", |
|
72 |
dfs), |
|
73 |
new DecimalFormat("#0.000000000000", |
|
74 |
dfs) |
|
75 |
}; |
|
76 |
int code; |
|
77 |
Object data; |
|
78 |
|
|
79 |
/** |
|
80 |
* Constructor por defecto. |
|
81 |
*/ |
|
82 |
public DxfGroup() { |
|
83 |
code = -1; |
|
84 |
data = null; |
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* Constructor habitual. Representa una entidad individual dentro del DXF |
|
89 |
* @param code, �ndice del dato dentro del DxfGroup |
|
90 |
* @param data, el propio dato que queda almacenado en el DxfGroup |
|
91 |
*/ |
|
92 |
public DxfGroup(int code, String data) { |
|
93 |
this.code = code; |
|
94 |
this.data = data; |
|
95 |
} |
|
96 |
|
|
97 |
/** |
|
98 |
* Lee una entidad del DXF y la empaqueta en un DxfGroup. |
|
99 |
* @param fi, BufferedReader mediante el cual accedemos al DXF |
|
100 |
* @return DxfGroup con la informaci�n procedente del DXF |
|
101 |
* @throws NumberFormatException |
|
102 |
* @throws IOException |
|
103 |
*/ |
|
104 |
public static DxfGroup read(BufferedReader fi) |
|
105 |
throws NumberFormatException, IOException { |
|
106 |
DxfGroup grp = null; |
|
107 |
String txt = fi.readLine(); |
|
108 |
|
|
109 |
if (txt != null) { |
|
110 |
if (!txt.equals("")) { |
|
111 |
grp = new DxfGroup(); |
|
112 |
grp.code = Integer.parseInt(txt.trim()); |
|
113 |
grp.readData(fi); |
|
114 |
} else { |
|
115 |
// Se trata de una linea en blanco y no se hace nada. |
|
116 |
} |
|
117 |
} |
|
118 |
|
|
119 |
return grp; |
|
120 |
} |
|
121 |
|
|
122 |
/** |
|
123 |
* Devuelve el code |
|
124 |
* @return |
|
125 |
*/ |
|
126 |
public int getCode() { |
|
127 |
return code; |
|
128 |
} |
|
129 |
|
|
130 |
/** |
|
131 |
* Devuelve data |
|
132 |
* @return |
|
133 |
*/ |
|
134 |
public Object getData() { |
|
135 |
return data; |
|
136 |
} |
|
137 |
|
|
138 |
/** |
|
139 |
* Lee un dato individual dentro de un DxfGroup |
|
140 |
* @param fi, BufferedReader |
|
141 |
* @throws IOException |
|
142 |
*/ |
|
143 |
private void readData(BufferedReader fi) throws IOException { |
|
144 |
String txt = fi.readLine().trim(); |
|
145 |
|
|
146 |
if ((0 <= code) && (code <= 9)) { |
|
147 |
data = txt; //_dfun = string_data |
|
148 |
} else if ((10 <= code) && (code <= 59)) { |
|
149 |
data = new Double(Double.parseDouble(txt)); //_dfun = float_data |
|
150 |
} else if ((60 <= code) && (code <= 79)) { |
|
151 |
try { |
|
152 |
data = new Integer(Integer.parseInt(txt)); //_dfun = int_data // 16-bit int |
|
153 |
} catch (java.lang.NumberFormatException e) { |
|
154 |
data = new Integer((int) Double.parseDouble(txt)); |
|
155 |
} |
|
156 |
} else if ((90 <= code) && (code <= 99)) { |
|
157 |
data = new Integer(Integer.parseInt(txt)); //_dfun = int_data // 32-bit int |
|
158 |
} else if (code == 100) { |
|
159 |
data = txt; //_dfun = unicode_data |
|
160 |
} else if (code == 102) { |
|
161 |
// Fran: Comentado para ganar velocidad. |
|
162 |
//System.err. ("Dxf: codigo " + code + " no implementado."); //_dfun = unicode_data |
|
163 |
} else if (code == 105) { |
|
164 |
data = txt; |
|
165 |
; //_dfun = handle_data |
|
166 |
} else if ((110 <= code) && (code <= 139)) { |
|
167 |
data = new Double(Double.parseDouble(txt)); //_dfun = float_data // not in dxf spec |
|
168 |
} else if ((140 <= code) && (code <= 149)) { // says 147 in dxf spec |
|
169 |
data = new Double(Double.parseDouble(txt)); //_dfun = float_data |
|
170 |
} else if ((170 <= code) && (code <= 179)) { // says 175 in dxf spec |
|
171 |
data = new Integer(Integer.parseInt(txt)); //_dfun = int_data // 16-bit int |
|
172 |
} else if ((210 <= code) && (code <= 239)) { |
|
173 |
data = new Double(Double.parseDouble(txt)); //_dfun = float_data // del TEXT procendente de exportacion de microstation |
|
174 |
} else if ((270 <= code) && (code <= 279)) { |
|
175 |
data = new Integer(Integer.parseInt(txt)); //_dfun = int_data // not in dxf spec |
|
176 |
} else if ((280 <= code) && (code <= 289)) { |
|
177 |
data = new Integer(Integer.parseInt(txt)); //_dfun = int_data // 8-bit int |
|
178 |
} else if ((290 <= code) && (code <= 299)) { |
|
179 |
data = new Boolean(Boolean.getBoolean(txt)); //_dfun = bool_data |
|
180 |
} else if ((300 <= code) && (code <= 309)) { |
|
181 |
data = txt; //_dfun = string_data |
|
182 |
} else if ((310 <= code) && (code <= 319)) { |
|
183 |
//_dfun = bin_data |
|
184 |
//throw new IOException("Dxf: codigo "+code+" no implementado."); |
|
185 |
} else if ((320 <= code) && (code <= 329)) { |
|
186 |
//_dfun = handle_data |
|
187 |
//throw new IOException("Dxf: codigo "+code+" no implementado."); |
|
188 |
} else if ((330 <= code) && (code <= 369)) { |
|
189 |
// Fran: Comentado para ganar velocidad. |
|
190 |
//System.err. ("Dxf: codigo " + code + " no implementado."); //_dfun = hex_data |
|
191 |
} else if ((370 <= code) && (code <= 379)) { |
|
192 |
data = new Integer(Integer.parseInt(txt)); //_dfun = int_data // 8-bit int |
|
193 |
} else if ((380 <= code) && (code <= 389)) { |
|
194 |
data = new Integer(Integer.parseInt(txt)); //_dfun = int_data // 8-bit int |
|
195 |
} else if ((390 <= code) && (code <= 399)) { |
|
196 |
data = txt; //_dfun = handle_data |
|
197 |
} else if ((400 <= code) && (code <= 409)) { |
|
198 |
data = new Integer(Integer.parseInt(txt)); //_dfun = int_data // 16-bit int |
|
199 |
} else if ((410 <= code) && (code <= 419)) { |
|
200 |
data = txt; //_dfun = string_data |
|
201 |
} else if (code == 999) { |
|
202 |
data = txt; //_dfun = string_data // comment |
|
203 |
} else if ((1000 <= code) && (code <= 1009)) { |
|
204 |
data = txt; //_dfun = string_data |
|
205 |
} else if ((1010 <= code) && (code <= 1059)) { |
|
206 |
data = new Double(Double.parseDouble(txt)); //_dfun = float_data |
|
207 |
} else if ((1060 <= code) && (code <= 1070)) { |
|
208 |
data = new Integer(Integer.parseInt(txt)); //_dfun = int_data // 16-bit int |
|
209 |
} else if (code == 1071) { |
|
210 |
data = new Integer(Integer.parseInt(txt)); //_dfun = int_data # 32-bit int |
|
211 |
} else { |
|
212 |
throw new IOException("DxfReader: c�digo " + code + |
|
213 |
" desconocido."); |
|
214 |
|
|
215 |
//raise ValueError, "Unexpected code: %d" % code |
|
216 |
} |
|
217 |
|
|
218 |
//return _dfun |
|
219 |
} |
|
220 |
|
|
221 |
/** |
|
222 |
* Permite comparar dos objetos de la clase DxfGroup |
|
223 |
* @param c, code |
|
224 |
* @param s, data |
|
225 |
* @return boolean |
|
226 |
*/ |
|
227 |
public boolean equals(int c, String s) { |
|
228 |
if ((c == code) && (s.compareTo((String) data) == 0)) { |
|
229 |
return true; |
|
230 |
} |
|
231 |
|
|
232 |
return false; |
|
233 |
} |
|
234 |
|
|
235 |
/** |
|
236 |
* Devuelve un dato concreto en forma de String tabulado |
|
237 |
* @param code |
|
238 |
* @return String |
|
239 |
*/ |
|
240 |
public static String int34car(int code) { |
|
241 |
if (code < 10) { |
|
242 |
return " " + Integer.toString(code); |
|
243 |
} else if (code < 100) { |
|
244 |
return " " + Integer.toString(code); |
|
245 |
} else { |
|
246 |
return Integer.toString(code); |
|
247 |
} |
|
248 |
} |
|
249 |
|
|
250 |
/** |
|
251 |
* Devuelve un dato concreto en forma de String tabulado |
|
252 |
* @param value |
|
253 |
* @return String |
|
254 |
*/ |
|
255 |
public static String int6car(int value) { |
|
256 |
String s = " " + Integer.toString(value); |
|
257 |
|
|
258 |
return s.substring(s.length() - 6, s.length()); |
|
259 |
} |
|
260 |
|
|
261 |
/** |
|
262 |
* Convierte a String un dato del DxfGroup |
|
263 |
* @param code |
|
264 |
* @param value |
|
265 |
* @return String |
|
266 |
*/ |
|
267 |
public static String toString(int code, String value) { |
|
268 |
return int34car(code) + "\r\n" + value + "\r\n"; |
|
269 |
} |
|
270 |
|
|
271 |
/** |
|
272 |
* Convierte a String un dato del DxfGroup |
|
273 |
* @param code |
|
274 |
* @param value |
|
275 |
* @return String |
|
276 |
*/ |
|
277 |
public static String toString(int code, int value) { |
|
278 |
return int34car(code) + "\r\n" + int6car(value) + "\r\n"; |
|
279 |
} |
|
280 |
|
|
281 |
/** |
|
282 |
* Convierte a String un dato del DxfGroup |
|
283 |
* @param code |
|
284 |
* @param value |
|
285 |
* @param decimalPartLength |
|
286 |
* @return String |
|
287 |
*/ |
|
288 |
public static String toString(int code, float value, int decimalPartLength) { |
|
289 |
return int34car(code) + "\r\n" + |
|
290 |
decimalFormats[decimalPartLength].format((double) value) + |
|
291 |
"\r\n"; |
|
292 |
} |
|
293 |
|
|
294 |
/** |
|
295 |
* Convierte a String un dato del DxfGroup |
|
296 |
* @param code |
|
297 |
* @param value |
|
298 |
* @param decimalPartLength |
|
299 |
* @return String |
|
300 |
*/ |
|
301 |
public static String toString(int code, double value, int decimalPartLength) { |
|
302 |
return int34car(code) + "\r\n" + |
|
303 |
decimalFormats[decimalPartLength].format(value) + "\r\n"; |
|
304 |
} |
|
305 |
|
|
306 |
/** |
|
307 |
* Convierte a String un dato del DxfGroup |
|
308 |
* @param code |
|
309 |
* @param value |
|
310 |
* @return String |
|
311 |
*/ |
|
312 |
public static String toString(int code, Object value) { |
|
313 |
if (value instanceof String) { |
|
314 |
return toString(code, (String) value); |
|
315 |
} else if (value instanceof Integer) { |
|
316 |
return toString(code, ((Integer) value).intValue()); |
|
317 |
} else if (value instanceof Double) { |
|
318 |
return toString(code, ((Double) value).floatValue(), 3); |
|
319 |
} else if (value instanceof Double) { |
|
320 |
return toString(code, ((Double) value).doubleValue(), 6); |
|
321 |
} else { |
|
322 |
return toString(code, value.toString()); |
|
323 |
} |
|
324 |
} |
|
325 |
|
|
326 |
/** |
|
327 |
* Convierte a String un dato del DxfGroup |
|
328 |
*/ |
|
329 |
public String toString() { |
|
330 |
return toString(code, data); |
|
331 |
} |
|
332 |
|
|
333 |
/** |
|
334 |
* jmorell: Permite rellenar los datos. �til en la escritura de DXFs. |
|
335 |
* @param data The data to set. |
|
336 |
*/ |
|
337 |
public void setData(Object data) { |
|
338 |
this.data = data; |
|
339 |
} |
|
340 |
|
|
341 |
/** |
|
342 |
* jmorell: Permite rellenar los c�digos. �til en la escritura de DXFs. |
|
343 |
* @param code The code to set. |
|
344 |
*/ |
|
345 |
public void setCode(int code) { |
|
346 |
this.code = code; |
|
347 |
} |
|
348 |
} |
org.gvsig.dxf/tags/org.gvsig.dxf-2.0.19/org.gvsig.dxf.lib/src/main/java/org/gvsig/dxf/io/ZipFileFolder.java | ||
---|---|---|
1 |
/* |
|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications. |
|
3 |
* |
|
4 |
* Copyright (C) 2004-5. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
19 |
* |
|
20 |
* For more information, contact: |
|
21 |
* |
|
22 |
* cresques@gmail.com |
|
23 |
*/ |
|
24 |
package org.gvsig.dxf.io; |
|
25 |
|
|
26 |
import java.io.IOException; |
|
27 |
import java.io.InputStream; |
|
28 |
import java.util.Enumeration; |
|
29 |
import java.util.zip.ZipEntry; |
|
30 |
import java.util.zip.ZipFile; |
|
31 |
|
|
32 |
|
|
33 |
/** |
|
34 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador |
|
35 |
*/ |
|
36 |
public class ZipFileFolder extends FileFolder { |
|
37 |
String zName = null; |
|
38 |
public ZipFile file = null; |
|
39 |
|
|
40 |
public ZipFileFolder() { |
|
41 |
super(); |
|
42 |
} |
|
43 |
|
|
44 |
/** |
|
45 |
* Constructor. |
|
46 |
* |
|
47 |
* @param fname |
|
48 |
*/ |
|
49 |
public ZipFileFolder(String fName) throws IOException { |
|
50 |
fName = DataSource.normalize(fName); |
|
51 |
|
|
52 |
if (isUrl(fName)) { |
|
53 |
zName = getZName(fName); |
|
54 |
} else { |
|
55 |
zName = fName; |
|
56 |
} |
|
57 |
|
|
58 |
file = new ZipFile(zName); |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* Analiza un nombre de fichero en formato zip://zipname.zip?file.ext |
|
63 |
* @param urlName |
|
64 |
*/ |
|
65 |
public static boolean isUrl(String name) { |
|
66 |
String str = name.substring(0, 3); |
|
67 |
str.toLowerCase(); |
|
68 |
|
|
69 |
if (str.compareTo("zip") == 0) { |
|
70 |
return true; |
|
71 |
} |
|
72 |
|
|
73 |
return false; |
|
74 |
} |
|
75 |
|
|
76 |
private String getZName(String urlName) { |
|
77 |
return urlName.substring(6, urlName.indexOf("?")); |
|
78 |
} |
|
79 |
|
|
80 |
private String getFName(String urlName) { |
|
81 |
return urlName.substring(urlName.indexOf("?") + 1); |
|
82 |
} |
|
83 |
|
|
84 |
public ZipEntry getZipEntry(String fName) throws IOException { |
|
85 |
InputStream is = null; |
|
86 |
|
|
87 |
if (isUrl(fName)) { |
|
88 |
fName = getFName(fName); |
|
89 |
} |
|
90 |
|
|
91 |
return file.getEntry(fName); |
|
92 |
} |
|
93 |
|
|
94 |
public InputStream getInputStream(String fName) throws IOException { |
|
95 |
return file.getInputStream(getZipEntry(fName)); |
|
96 |
} |
|
97 |
|
|
98 |
public InputStream getInputStream(ZipEntry ze) throws IOException { |
|
99 |
return file.getInputStream(ze); |
|
100 |
} |
|
101 |
|
|
102 |
public int count() { |
|
103 |
return file.size(); |
|
104 |
} |
|
105 |
|
|
106 |
public Enumeration entries() { |
|
107 |
return file.entries(); |
|
108 |
} |
|
109 |
} |
org.gvsig.dxf/tags/org.gvsig.dxf-2.0.19/org.gvsig.dxf.lib/src/main/java/org/gvsig/dxf/io/DxfFile.java | ||
---|---|---|
1 |
/* |
|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications. |
|
3 |
* |
|
4 |
* Copyright (C) 2004-5. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
19 |
* |
|
20 |
* For more information, contact: |
|
21 |
* |
|
22 |
* cresques@gmail.com |
|
23 |
*/ |
|
24 |
package org.gvsig.dxf.io; |
|
25 |
|
|
26 |
import java.io.BufferedReader; |
|
27 |
import java.io.FileReader; |
|
28 |
import java.io.FileWriter; |
|
29 |
import java.io.IOException; |
|
30 |
import java.io.InputStream; |
|
31 |
import java.io.InputStreamReader; |
|
32 |
import java.io.Reader; |
|
33 |
import java.util.Date; |
|
34 |
import java.util.Hashtable; |
|
35 |
import java.util.Vector; |
|
36 |
|
|
37 |
import org.cresques.cts.ICoordTrans; |
|
38 |
import org.cresques.cts.IProjection; |
|
39 |
import org.cresques.geo.Projected; |
|
40 |
import org.cresques.px.Extent; |
|
41 |
import org.gvsig.dxf.px.IObjList; |
|
42 |
import org.gvsig.dxf.px.dxf.DxfEntityMaker; |
|
43 |
import org.gvsig.dxf.px.dxf.DxfHeaderManager; |
|
44 |
import org.gvsig.dxf.px.dxf.DxfHeaderVariables; |
|
45 |
import org.slf4j.Logger; |
|
46 |
import org.slf4j.LoggerFactory; |
|
47 |
|
|
48 |
/** |
|
49 |
* Clase que representa un fichero en formato DXF. Contiene los interfaces y m�todos |
|
50 |
* necesarios para acceder a la informaci�n almacenada en su interior. |
|
51 |
* |
|
52 |
* @author jmorell |
|
53 |
*/ |
|
54 |
public class DxfFile extends GeoFile { |
|
55 |
|
|
56 |
public static Logger logger = LoggerFactory.getLogger(DxfFile.class); |
|
57 |
|
|
58 |
private boolean cadFlag = true; |
|
59 |
|
|
60 |
long lineNr = 0; |
|
61 |
|
|
62 |
String buf = null; |
|
63 |
|
|
64 |
BufferedReader fi; |
|
65 |
long l = 0; |
|
66 |
int count = 0; |
|
67 |
DxfGroup grp = null; |
|
68 |
|
|
69 |
EntityFactory entityMaker = null; |
|
70 |
VarSettings headerManager; |
|
71 |
private boolean dxf3DFlag; |
|
72 |
|
|
73 |
/** |
|
74 |
* Crea los objetos en el Modelo correspondiente. |
|
75 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es> |
|
76 |
*/ |
|
77 |
public interface EntityFactory extends Projected { |
|
78 |
|
|
79 |
/** |
|
80 |
* Permite saber si se est�n a�adiendo elementos a un bloque |
|
81 |
* @param booleano que indica si se est�n a�adiendo elementos a un bloque |
|
82 |
*/ |
|
83 |
public void setAddingToBlock(boolean a); |
|
84 |
|
|
85 |
/** |
|
86 |
* Crea una nueva capa partiendo de la informaci�n almacenada en el DXF |
|
87 |
* @param DxfGroupVector con informaci�n para la construcci�n de la nueva capa |
|
88 |
* @throws Exception |
|
89 |
*/ |
|
90 |
public void createLayer(DxfGroupVector v) throws Exception ; |
|
91 |
|
|
92 |
/** |
|
93 |
* Crea una nueva polil�nea partiendo de la informaci�n almacenada en el DXF |
|
94 |
* @param DxfGroupVector con informaci�n para la construcci�n de la nueva polil�nea |
|
95 |
* @throws Exception |
|
96 |
*/ |
|
97 |
public void createPolyline(DxfGroupVector v) throws Exception ; |
|
98 |
|
|
99 |
/** |
|
100 |
* A�ade un v�rtice a la polil�nea que se est� creando |
|
101 |
* @param DxfGroupVector con la informaci�n necesaria para la adici�n del v�rtice |
|
102 |
* @throws Exception |
|
103 |
*/ |
|
104 |
public void addVertex(DxfGroupVector v) throws Exception ; |
|
105 |
|
|
106 |
/** |
|
107 |
* Fin de secuencia |
|
108 |
* @throws Exception |
|
109 |
*/ |
|
110 |
public void endSeq() throws Exception ; |
|
111 |
|
|
112 |
/** |
|
113 |
* Crea una nueva LwPolyline partiendo de la informaci�n almacenada en el DXF |
|
114 |
* @param DxfGroupVector con informaci�n para la construcci�n de la nueva polil�nea |
|
115 |
* @throws Exception |
|
116 |
*/ |
|
117 |
public void createLwPolyline(DxfGroupVector v) throws Exception ; |
|
118 |
|
|
119 |
/** |
|
120 |
* Crea una nueva l�nea partiendo de la informaci�n almacenada en el DXF |
|
121 |
* @param DxfGroupVector con informaci�n para la construcci�n de la nueva l�nea |
|
122 |
* @throws Exception |
|
123 |
*/ |
|
124 |
public void createLine(DxfGroupVector v) throws Exception ; |
|
125 |
|
|
126 |
/** |
|
127 |
* Crea un nuevo texto partiendo de la informaci�n almacenada en el DXF |
|
128 |
* @param DxfGroupVector con informaci�n para la construcci�n del nuevo texto |
|
129 |
* @throws Exception |
|
130 |
*/ |
|
131 |
public void createText(DxfGroupVector v) throws Exception ; |
|
132 |
|
|
133 |
/** |
|
134 |
* Crea un nuevo MText partiendo de la informaci�n almacenada en el DXF |
|
135 |
* @param DxfGroupVector con informaci�n para la construcci�n del nuevo MText |
|
136 |
* @throws Exception |
|
137 |
*/ |
|
138 |
public void createMText(DxfGroupVector v) throws Exception ; |
|
139 |
|
|
140 |
/** |
|
141 |
* Crea un nuevo punto partiendo de la informaci�n almacenada en el DXF |
|
142 |
* @param DxfGroupVector con informaci�n para la construcci�n del nuevo punto |
|
143 |
* @throws Exception |
|
144 |
*/ |
|
145 |
public void createPoint(DxfGroupVector v) throws Exception ; |
|
146 |
|
|
147 |
/** |
|
148 |
* Crea un nuevo c�rculo partiendo de la informaci�n almacenada en el DXF |
|
149 |
* @param DxfGroupVector con informaci�n para la construcci�n del nuevo c�rculo |
|
150 |
* @throws Exception |
|
151 |
*/ |
|
152 |
public void createCircle(DxfGroupVector v) throws Exception ; |
|
153 |
|
|
154 |
/** |
|
155 |
* Crea una nueva elipse partiendo de la informaci�n almacenada en el DXF |
|
156 |
* @param DxfGroupVector con informaci�n para la construcci�n de la nueva elipse |
|
157 |
* @throws Exception |
|
158 |
*/ |
|
159 |
public void createEllipse(DxfGroupVector v) throws Exception ; |
|
160 |
|
|
161 |
/** |
|
162 |
* Crea un nuevo arco partiendo de la informaci�n almacenada en el DXF |
|
163 |
* @param DxfGroupVector con informaci�n para la construcci�n del nuevo arco |
|
164 |
* @throws Exception |
|
165 |
*/ |
|
166 |
public void createArc(DxfGroupVector v) throws Exception ; |
|
167 |
|
|
168 |
/** |
|
169 |
* Crea un nuevo punto de inserci�n partiendo de la informaci�n almacenada en el DXF |
|
170 |
* @param DxfGroupVector con informaci�n para la construcci�n del nuevo punto de inserci�n |
|
171 |
* @throws Exception |
|
172 |
*/ |
|
173 |
public void createInsert(DxfGroupVector v) throws Exception ; |
|
174 |
|
|
175 |
/** |
|
176 |
* Crea un nuevo s�lido 2D partiendo de la informaci�n almacenada en el DXF |
|
177 |
* @param DxfGroupVector con informaci�n para la construcci�n del nuevo s�lido |
|
178 |
* @throws Exception |
|
179 |
*/ |
|
180 |
public void createSolid(DxfGroupVector v) throws Exception ; |
|
181 |
|
|
182 |
/** |
|
183 |
* Crea un nuevo Spline partiendo de la informaci�n almacenada en el DXF |
|
184 |
* @param DxfGroupVector con informaci�n para la construcci�n del nuevo Spline |
|
185 |
* @throws Exception |
|
186 |
*/ |
|
187 |
public void createSpline(DxfGroupVector v) throws Exception ; |
|
188 |
|
|
189 |
/** |
|
190 |
* Construye la definici�n de un nuevo atributo partiendo de la informaci�n almacenada en el DXF |
|
191 |
* @param DxfGroupVector con informaci�n para la construcci�n de la definici�n del nuevo atributo |
|
192 |
* @throws Exception |
|
193 |
*/ |
|
194 |
public void createAttdef(DxfGroupVector v) throws Exception ; |
|
195 |
|
|
196 |
/** |
|
197 |
* Crea un nuevo atributo partiendo de la informaci�n almacenada en el DXF |
|
198 |
* @param DxfGroupVector con informaci�n para la creaci�n del nuevo atributo |
|
199 |
* @throws Exception |
|
200 |
*/ |
|
201 |
public void createAttrib(DxfGroupVector v) throws Exception ; |
|
202 |
|
|
203 |
/** |
|
204 |
* Crea un bloque |
|
205 |
* @param DxfGroupVector con informaci�n para la creaci�n del nuevo elemento |
|
206 |
* @throws Exception |
|
207 |
*/ |
|
208 |
public void createBlock(DxfGroupVector v) throws Exception ; |
|
209 |
|
|
210 |
/** |
|
211 |
* Fin de la definici�n de un bloqe |
|
212 |
* @param DxfGroupVector con informaci�n referente al final de un bloque |
|
213 |
* @throws Exception |
|
214 |
*/ |
|
215 |
public void endBlk(DxfGroupVector v) throws Exception ; |
|
216 |
|
|
217 |
/** |
|
218 |
* Gestiona los bloques que no se han tratado en la primera vuelta |
|
219 |
*/ |
|
220 |
void testBlocks(); |
|
221 |
|
|
222 |
/** |
|
223 |
* Devuelve el extent |
|
224 |
* @return el extent |
|
225 |
*/ |
|
226 |
public Extent getExtent(); |
|
227 |
|
|
228 |
/** |
|
229 |
* Devuelve la lista de bloques |
|
230 |
* @return la lista de bloques |
|
231 |
*/ |
|
232 |
public Vector getBlkList(); |
|
233 |
|
|
234 |
/** |
|
235 |
* Permite la gesti�n de los atributos almacenados en unn DXF |
|
236 |
* @return un Vector con la lista de atributos |
|
237 |
*/ |
|
238 |
public Vector getAttributes(); |
|
239 |
|
|
240 |
/** |
|
241 |
* Borra los atributos repetidos |
|
242 |
*/ |
|
243 |
public void depureAttributes(); |
|
244 |
|
|
245 |
/** |
|
246 |
* Devuelve los objetos almacenados en el DXF |
|
247 |
* @return IObjList con los objetos procedentes del DXF |
|
248 |
*/ |
|
249 |
public IObjList getObjects(); |
|
250 |
|
|
251 |
/** |
|
252 |
* Permite saber si se trata de un fichero DXF en 2D o en 3D |
|
253 |
* @return booleano que indica si se trata de un fichero DXF 3D |
|
254 |
*/ |
|
255 |
public boolean isDxf3DFile(); |
|
256 |
}; |
|
257 |
|
|
258 |
/** |
|
259 |
* Establece el estado de las variables propias de un DXF que est�n definidas |
|
260 |
* en la secci�n HEADER. Por ejemplo, la versi�n del DXF. |
|
261 |
* @author jmorell (jose.morell@gmail.com) |
|
262 |
* @version 15-dic-2004 |
|
263 |
*/ |
|
264 |
public interface VarSettings { |
|
265 |
|
|
266 |
/** |
|
267 |
* Establece la versi�n de Autocad en la que fue generado el DXF. |
|
268 |
* @param informaci�n de base |
|
269 |
* @throws Exception |
|
270 |
*/ |
|
271 |
public void setAcadVersion(DxfGroupVector v) throws Exception ; |
|
272 |
|
|
273 |
/** |
|
274 |
* Devuelve la versi�n de Autocad en la que fue generado el DXF. |
|
275 |
* @return |
|
276 |
*/ |
|
277 |
public String getAcadVersion(); |
|
278 |
|
|
279 |
/** |
|
280 |
* Devuelve el estado de las variables propias de un DXF |
|
281 |
* @return |
|
282 |
*/ |
|
283 |
public DxfHeaderVariables getDxfHeaderVars(); |
|
284 |
public boolean isWritedDxf3D(); |
|
285 |
public void loadMinZFromHeader(double d); |
|
286 |
public void loadMaxZFromHeader(double d); |
|
287 |
}; |
|
288 |
|
|
289 |
/** |
|
290 |
* Constructor de la clase |
|
291 |
* @param proj, la proyecci�n cartogr�fica |
|
292 |
* @param name, el path absoluto hasta el fichero DXF |
|
293 |
* @param maker, el interface que permite la construcci�n de las entidades procedentes del DXF |
|
294 |
*/ |
|
295 |
public DxfFile(IProjection proj, String name, EntityFactory maker) { |
|
296 |
super(proj, name); |
|
297 |
entityMaker = maker; |
|
298 |
headerManager = new DxfHeaderManager(); |
|
299 |
} |
|
300 |
|
|
301 |
/** |
|
302 |
* Constructor de la clase que adem�s incorpora la capacidad de leer una porci�n del HEADER |
|
303 |
* @param proj, la proyecci�n cartogr�fica |
|
304 |
* @param name, el path absoluto hasta el fichero DXF |
|
305 |
* @param maker, el interface que permite la construcci�n de las entidades procedentes del DXF |
|
306 |
* @param dxfVars, el interface que permite la lectura del HEADER de un DXF |
|
307 |
*/ |
|
308 |
public DxfFile(IProjection proj, String name, EntityFactory maker, VarSettings dxfVars) { |
|
309 |
super(proj, name); |
|
310 |
entityMaker = maker; |
|
311 |
headerManager = dxfVars; |
|
312 |
} |
|
313 |
|
|
314 |
/** |
|
315 |
* Carga un fichero en formato DXF |
|
316 |
* @throws Exception |
|
317 |
*/ |
|
318 |
public GeoFile load() throws Exception { |
|
319 |
logger.debug("Dxf: Cargando " + name + " ..."); |
|
320 |
if (ZipFileFolder.isUrl(name)) { |
|
321 |
ZipFileFolder zFolder = new ZipFileFolder(name); |
|
322 |
InputStream is = zFolder.getInputStream(name); |
|
323 |
return load(new InputStreamReader(is)); |
|
324 |
} else |
|
325 |
return load(new FileReader(name)); |
|
326 |
|
|
327 |
} |
|
328 |
|
|
329 |
/** |
|
330 |
* Carga un fichero en formato DXF tomando un Reader como par�metro |
|
331 |
* @param fr, Reader que se le pasa como par�metro |
|
332 |
* @return devuelve un objeto GeoFile, padre de DxfFile |
|
333 |
* @throws Exception |
|
334 |
* @throws Exception |
|
335 |
*/ |
|
336 |
public GeoFile load(Reader fr) throws Exception { |
|
337 |
logger.debug("Dxf: Cargando '"+name+"' ..."); |
|
338 |
fi = new BufferedReader(fr); |
|
339 |
while ((grp = readGrp()) != null) { |
|
340 |
l+=2; |
|
341 |
|
|
342 |
if (grp.equals(0, "EOF")) break; |
|
343 |
if (grp.equals(0, "SECTION")) |
|
344 |
readSection(); |
|
345 |
} |
|
346 |
fi.close(); |
|
347 |
extent.add(entityMaker.getExtent()); |
|
348 |
logger.debug("Dxf: '"+name+"' cargado. ("+l+" l�neas)."); |
|
349 |
this.lineNr = l; |
|
350 |
return this; |
|
351 |
} |
|
352 |
|
|
353 |
/** |
|
354 |
* El fichero DXF se divide en grupos. Este m�todo permite leer cada grupo individualmente |
|
355 |
* @return devuelve la informaci�n del DXF en forma de objetos de la clase DxfGroup |
|
356 |
* @throws NumberFormatException |
|
357 |
* @throws IOException |
|
358 |
*/ |
|
359 |
private DxfGroup readGrp() throws NumberFormatException, IOException { |
|
360 |
DxfGroup g = DxfGroup.read(fi); |
|
361 |
if (g != null) l += 2; |
|
362 |
/*if (g.code == 8) |
|
363 |
if (((String) g.data).length() < 1) { |
|
364 |
logger.error("a que un layer no puede ser ''?"); |
|
365 |
System.exit(1); |
|
366 |
}*/ |
|
367 |
return g; |
|
368 |
} |
|
369 |
|
|
370 |
/** |
|
371 |
* El fichero DXF se divide en varias secciones. Este m�todo se encarga de leer cada |
|
372 |
* una de ellas |
|
373 |
* @throws NumberFormatException |
|
374 |
* @throws Exception |
|
375 |
*/ |
|
376 |
private void readSection() throws NumberFormatException, Exception { |
|
377 |
while (true) { |
|
378 |
grp = readGrp(); |
|
379 |
logger.debug("-1:"+grp); |
|
380 |
if (grp.code == 2) |
|
381 |
if (((String) grp.data).compareTo("HEADER") == 0) |
|
382 |
readHeader(); |
|
383 |
else if (((String) grp.data).compareTo("CLASSES") == 0) |
|
384 |
readAnySection(); |
|
385 |
else if (((String) grp.data).compareTo("TABLES") == 0) |
|
386 |
readTables(); |
|
387 |
else if (((String) grp.data).compareTo("BLOCKS") == 0) |
|
388 |
readBlocks(); |
|
389 |
else if (((String) grp.data).compareTo("ENTITIES") == 0) |
|
390 |
readEntities(); |
|
391 |
else if (((String) grp.data).compareTo("OBJECTS") == 0) |
|
392 |
readAnySection(); |
|
393 |
else { |
|
394 |
logger.debug("DxfRead: Seccion "+grp.data); |
|
395 |
readAnySection(); |
|
396 |
} |
|
397 |
else |
|
398 |
logger.debug("Dxf: Codigo/Seccion desconocidos" + grp); |
|
399 |
if (grp.equals(0, "EOF")) break; |
|
400 |
if (grp.equals(0, "ENDSEC")) break; |
|
401 |
} |
|
402 |
} |
|
403 |
|
|
404 |
/** |
|
405 |
* Habilita la lectura de la secci�n de TABLES |
|
406 |
* @throws NumberFormatException |
|
407 |
* @throws Exception |
|
408 |
*/ |
|
409 |
private void readTables() throws NumberFormatException, Exception { |
|
410 |
logger.debug("Dxf: Seccion TABLAS, linea "+ l+ "grp ="+ grp); |
|
411 |
int layerCnt = 0; |
|
412 |
String tableAct = "NONAME"; |
|
413 |
|
|
414 |
Hashtable tables = new Hashtable(); |
|
415 |
Vector table = new Vector(); |
|
416 |
DxfGroupVector v = new DxfGroupVector(); |
|
417 |
|
|
418 |
grp = readGrp(); |
|
419 |
// logger.debug("0:"+grp); |
|
420 |
while (true) { |
|
421 |
if (grp.code == 0) { |
|
422 |
String data = (String) grp.getData(); |
|
423 |
if (data.compareTo("ENDSEC") == 0 || data.compareTo("EOF") == 0) |
|
424 |
break; |
|
425 |
else if (data.compareTo("ENDTAB") == 0) { |
|
426 |
tables.put(tableAct, table); |
|
427 |
table = new Vector(); |
|
428 |
grp = readGrp(); |
|
429 |
// logger.debug("1:"+grp); |
|
430 |
|
|
431 |
/**/if (tableAct.compareTo("LAYER") == 0 && v.size()>0) { |
|
432 |
entityMaker.createLayer(v); |
|
433 |
logger.debug("Dxf: Layer "+v.getDataAsString(2)); |
|
434 |
layerCnt++; |
|
435 |
v.clear(); |
|
436 |
}/**/ |
|
437 |
continue; |
|
438 |
} else { |
|
439 |
if (table.size()==1) { |
|
440 |
tableAct = v.getDataAsString(2); |
|
441 |
logger.debug("Dxf: Tabla "+tableAct); |
|
442 |
} else |
|
443 |
if (tableAct.compareTo("LAYER") == 0 && v.size()>0) { |
|
444 |
entityMaker.createLayer(v); |
|
445 |
logger.debug("Dxf: Layer "+v.getDataAsString(2)); |
|
446 |
layerCnt++; |
|
447 |
} |
|
448 |
|
|
449 |
v.clear(); |
|
450 |
v.add(grp); |
|
451 |
} |
|
452 |
while (true) { |
|
453 |
grp = readGrp(); |
|
454 |
// logger.debug("2:"+grp); |
|
455 |
if (grp.code == 0) break; |
|
456 |
v.add(grp); |
|
457 |
} |
|
458 |
table.add(v); |
|
459 |
} else { |
|
460 |
logger.debug("Dxf: Error de secuencia"); |
|
461 |
grp = readGrp(); |
|
462 |
//logger.debug("3:"+grp); |
|
463 |
} |
|
464 |
} |
|
465 |
logger.debug("Dxf: Seccion TABLAS: " + layerCnt + " Capas. "); |
|
466 |
} |
|
467 |
|
|
468 |
/** |
|
469 |
* M�todo de lectura de secci�n por defecto. Se utiliza mientras se realiza la |
|
470 |
* implementaci�n correspondiente |
|
471 |
* @throws NumberFormatException |
|
472 |
* @throws IOException |
|
473 |
*/ |
|
474 |
private void readAnySection() throws NumberFormatException, IOException { |
|
475 |
logger.debug("Dxf: Seccion '"+((String) grp.getData())+"', linea "+ l); |
|
476 |
while (true) { |
|
477 |
grp = readGrp(); |
|
478 |
if (grp.equals(0, "ENDSEC")) break; |
|
479 |
else if (grp.equals(0, "EOF")) break; |
|
480 |
} |
|
481 |
} |
|
482 |
|
|
483 |
/** |
|
484 |
* Primera aproximaci�n a la implementaci�n de la lectura del HEADER. En principio |
|
485 |
* interesa que se lea la versi�n del DXF. |
|
486 |
* Para implementar esta parte del lector se ha optado por incluir el m�todo |
|
487 |
* setAcadVersion en el interface EntityFactory. A lo mejor conviene implementar |
|
488 |
* un nuevo interface VarSettings. |
|
489 |
* @throws NumberFormatException |
|
490 |
* @throws Exception |
|
491 |
*/ |
|
492 |
private void readHeader() throws NumberFormatException, Exception { |
|
493 |
logger.debug("Dxf: Seccion HEADER, linea "+ l); |
|
494 |
int variableCnt = 0; |
|
495 |
int cntVeces = 0; |
|
496 |
DxfGroupVector v = new DxfGroupVector(); |
|
497 |
grp = readGrp(); |
|
498 |
while (true) { |
|
499 |
if (grp.equals(0, "EOF")) { |
|
500 |
break; |
|
501 |
} |
|
502 |
else if (grp.code==9 || grp.code==0) { |
|
503 |
if (v.size() > 0) { |
|
504 |
String lastVariable = (String) ((DxfGroup) v.get(0)).data; |
|
505 |
//logger.debug(lastVariable); |
|
506 |
if (lastVariable.compareTo("$ACADVER") == 0) { |
|
507 |
//logger.debug("Aqui llega."); |
|
508 |
headerManager.setAcadVersion(v); |
|
509 |
} else if (lastVariable.compareTo("$EXTMIN") == 0) { |
|
510 |
if(v.hasCode(3)) |
|
511 |
headerManager.loadMinZFromHeader(((Double)((DxfGroup) v.get(3)).data).doubleValue()); |
|
512 |
} else if (lastVariable.compareTo("$EXTMAX") == 0) { |
|
513 |
if(v.hasCode(3)) |
|
514 |
headerManager.loadMaxZFromHeader(((Double)((DxfGroup) v.get(3)).data).doubleValue()); |
|
515 |
} else if (lastVariable.compareTo("ENDSEC") == 0) { |
|
516 |
//logger.debug("Llega al ENDSEC."); |
|
517 |
break; |
|
518 |
} /*else |
|
519 |
logger.debug("Dxf: Variable "+lastVariable+" desconocida.");*/ |
|
520 |
} |
|
521 |
v.clear(); |
|
522 |
v.add(grp); |
|
523 |
while (true) { |
|
524 |
grp = readGrp(); |
|
525 |
if (grp.code == 9 || grp.code==0) break; |
|
526 |
v.add(grp); |
|
527 |
} |
|
528 |
variableCnt++; |
|
529 |
} |
|
530 |
cntVeces++; |
|
531 |
} |
|
532 |
logger.debug("Dxf: Seccion HEADER, " + variableCnt + " variables, "+ cntVeces + " veces."); |
|
533 |
//logger.debug("Seccion HEADER, linea "+ l+ " (SALGO)"); |
|
534 |
logger.debug("readHeader: ACAD Version: " + headerManager.getDxfHeaderVars().getAcadVersion()); |
|
535 |
} |
|
536 |
|
|
537 |
/** |
|
538 |
* Permite leer la secci�n ENTITIES del DXF, donde se encuentran las entidades |
|
539 |
* geom�tricas del DXF que no aparecen dentro de ning�n bloque |
|
540 |
* @throws NumberFormatException |
|
541 |
* @throws Exception |
|
542 |
*/ |
|
543 |
private void readEntities() throws NumberFormatException, Exception { |
|
544 |
logger.debug("Dxf: Seccion ENTITIES, linea "+ l); |
|
545 |
int entityCnt = 0; |
|
546 |
int cntVeces = 0; |
|
547 |
DxfGroupVector v = new DxfGroupVector(); |
|
548 |
grp = readGrp(); |
|
549 |
while (true) { |
|
550 |
if (grp.equals(0, "EOF")) break; |
|
551 |
else if (grp.code == 0) { |
|
552 |
if (v.size() > 0) { |
|
553 |
String lastEntity = (String) ((DxfGroup) v.get(0)).data; |
|
554 |
if (lastEntity.compareTo("POLYLINE") == 0) { |
|
555 |
entityMaker.createPolyline(v); |
|
556 |
} else if (lastEntity.compareTo("VERTEX") == 0) { |
|
557 |
entityMaker.addVertex(v); |
|
558 |
} else if (lastEntity.compareTo("SEQEND") == 0) { |
|
559 |
entityMaker.endSeq(); |
|
560 |
} else if (lastEntity.compareTo("LWPOLYLINE") == 0) { |
|
561 |
entityMaker.createLwPolyline(v); |
|
562 |
} else if (lastEntity.compareTo("LINE") == 0) { |
|
563 |
entityMaker.createLine(v); |
|
564 |
} else if (lastEntity.compareTo("TEXT") == 0) { |
|
565 |
entityMaker.createText(v); |
|
566 |
} else if (lastEntity.compareTo("MTEXT") == 0) { |
|
567 |
entityMaker.createMText(v); |
|
568 |
} else if (lastEntity.compareTo("POINT") == 0) { |
|
569 |
entityMaker.createPoint(v); |
|
570 |
} else if (lastEntity.compareTo("CIRCLE") == 0) { |
|
571 |
entityMaker.createCircle(v); |
|
572 |
} else if (lastEntity.compareTo("ELLIPSE") == 0) { |
|
573 |
entityMaker.createEllipse(v); |
|
574 |
} else if (lastEntity.compareTo("ARC") == 0) { |
|
575 |
entityMaker.createArc(v); |
|
576 |
} else if (lastEntity.compareTo("INSERT") == 0) { |
|
577 |
entityMaker.createInsert(v); |
|
578 |
} else if (lastEntity.compareTo("SOLID") == 0) { |
|
579 |
entityMaker.createSolid(v); |
|
580 |
} else if (lastEntity.compareTo("SPLINE") == 0) { |
|
581 |
entityMaker.createSpline(v); |
|
582 |
} else if (lastEntity.compareTo("ATTRIB") == 0) { |
|
583 |
entityMaker.createAttrib(v); |
|
584 |
} else if (lastEntity.compareTo("ENDSEC") == 0) { |
|
585 |
break; |
|
586 |
} else |
|
587 |
logger.debug("Dxf: Entidad "+lastEntity+" desconocida."); |
|
588 |
} |
|
589 |
v.clear(); |
|
590 |
v.add(grp); |
|
591 |
while (true) { |
|
592 |
grp = readGrp(); |
|
593 |
if (grp.code == 0) break; |
|
594 |
v.add(grp); |
|
595 |
} |
|
596 |
entityCnt++; |
|
597 |
} |
|
598 |
cntVeces++; |
|
599 |
} |
|
600 |
logger.debug("Dxf: Seccion ENTITIES, " + entityCnt + " entidades, "+ cntVeces + " veces."); |
|
601 |
//logger.debug("Seccion ENTITIES, linea "+ l+ " (SALGO)"); |
|
602 |
} |
|
603 |
|
|
604 |
/** |
|
605 |
* Permite la secci�n BLOCKS del DXF, donde se encuentran las definiciones de los |
|
606 |
* bloques que componen el DXF |
|
607 |
* @throws NumberFormatException |
|
608 |
* @throws Exception |
|
609 |
*/ |
|
610 |
private void readBlocks() throws NumberFormatException, Exception { |
|
611 |
logger.debug("Dxf: Seccion BLOCKS, linea "+ l); |
|
612 |
int blkCnt = 0; |
|
613 |
int cntVeces = 0; |
|
614 |
DxfGroupVector v = new DxfGroupVector(); |
|
615 |
grp = readGrp(); |
|
616 |
while (true) { |
|
617 |
if (grp.equals(0, "EOF")) break; |
|
618 |
else if (grp.code == 0) { |
|
619 |
if (v.size() > 0) { |
|
620 |
String lastEntity = (String) ((DxfGroup) v.get(0)).data; |
|
621 |
if (lastEntity.compareTo("BLOCK") == 0) { |
|
622 |
//logger.debug("readBlocks(): Empezamos a leer un bloque"); |
|
623 |
entityMaker.createBlock(v); |
|
624 |
} else if (lastEntity.compareTo("POLYLINE") == 0) { |
|
625 |
//logger.debug("readBlocks(): A�adimos una polilinea al bloque"); |
|
626 |
entityMaker.createPolyline(v); |
|
627 |
} else if (lastEntity.compareTo("VERTEX") == 0) { |
|
628 |
//logger.debug("readBlocks(): A�adimos un vertice a la polilinea"); |
|
629 |
entityMaker.addVertex(v); |
|
630 |
} else if (lastEntity.compareTo("SEQEND") == 0) { |
|
631 |
//logger.debug("readBlocks(): Cerramos una polilinea"); |
|
632 |
entityMaker.endSeq(); |
|
633 |
} else if (lastEntity.compareTo("LWPOLYLINE") == 0) { |
|
634 |
//logger.debug("readBlocks(): A�adimos una lwpolilinea al bloque"); |
|
635 |
entityMaker.createLwPolyline(v); |
|
636 |
} else if (lastEntity.compareTo("LINE") == 0) { |
|
637 |
//logger.debug("readBlocks(): A�adimos una linea al bloque"); |
|
638 |
entityMaker.createLine(v); |
|
639 |
} else if (lastEntity.compareTo("TEXT") == 0) { |
|
640 |
//logger.debug("readBlocks(): A�adimos un texto al bloque"); |
|
641 |
entityMaker.createText(v); |
|
642 |
} else if (lastEntity.compareTo("MTEXT") == 0) { |
|
643 |
//logger.debug("readBlocks(): A�adimos un m-texto al bloque"); |
|
644 |
entityMaker.createMText(v); |
|
645 |
} else if (lastEntity.compareTo("POINT") == 0) { |
|
646 |
//logger.debug("readBlocks(): A�adimos un punto al bloque"); |
|
647 |
entityMaker.createPoint(v); |
|
648 |
} else if (lastEntity.compareTo("CIRCLE") == 0) { |
|
649 |
//logger.debug("readBlocks(): A�adimos un circulo al bloque"); |
|
650 |
entityMaker.createCircle(v); |
|
651 |
} else if (lastEntity.compareTo("ARC") == 0) { |
|
652 |
//logger.debug("readBlocks(): A�adimos un arco al bloque"); |
|
653 |
entityMaker.createArc(v); |
|
654 |
} else if (lastEntity.compareTo("INSERT") == 0) { |
|
655 |
//logger.debug("readBlocks(): A�adimos un insert al bloque"); |
|
656 |
entityMaker.createInsert(v); |
|
657 |
} else if (lastEntity.compareTo("SOLID") == 0) { |
|
658 |
//logger.debug("readBlocks(): A�adimos un solido al bloque"); |
|
659 |
entityMaker.createSolid(v); |
|
660 |
} else if (lastEntity.compareTo("SPLINE") == 0) { |
|
661 |
entityMaker.createSpline(v); |
|
662 |
} else if (lastEntity.compareTo("ATTDEF") == 0) { |
|
663 |
entityMaker.createAttdef(v); |
|
664 |
} else if (lastEntity.compareTo("ENDBLK") == 0) { |
|
665 |
//logger.debug("readBlocks(): Cerramos un bloque"+v); |
|
666 |
entityMaker.endBlk(v); |
|
667 |
} else if (lastEntity.compareTo("ENDSEC") == 0) { |
|
668 |
break; |
|
669 |
} else |
|
670 |
logger.debug("Dxf: Entidad de bloque "+lastEntity+" desconocida."); |
|
671 |
} |
|
672 |
v.clear(); |
|
673 |
v.add(grp); |
|
674 |
while (true) { |
|
675 |
grp = readGrp(); |
|
676 |
if (grp.code == 0) break; |
|
677 |
v.add(grp); |
|
678 |
} |
|
679 |
blkCnt++; |
|
680 |
} |
|
681 |
cntVeces++; |
|
682 |
} |
|
683 |
|
|
684 |
entityMaker.testBlocks(); |
|
685 |
// Cuando termina de leer la secci�n de bloques se asegura de que todos los campos |
|
686 |
// son distintos. |
|
687 |
//logger.debug("readBlocks(): entityMaker.getAttributes().size() = " + entityMaker.getAttributes().size()); |
|
688 |
entityMaker.depureAttributes(); |
|
689 |
//logger.debug("readBlocks(): entityMaker.getAttributes().size() = " + entityMaker.getAttributes().size()); |
|
690 |
logger.debug("Dxf: Seccion BLOCKS, " + blkCnt + " elementos de bloque. "+ cntVeces + " veces."); |
|
691 |
} |
|
692 |
|
Also available in: Unified diff