Revision 1180
tags/org.gvsig.dwg-2.0.246/org.gvsig.dwg.app/org.gvsig.dwg.app.mainplugin/buildNumber.properties | ||
---|---|---|
1 |
#Thu Jun 08 21:07:48 CEST 2023 |
|
2 |
buildNumber=2315 |
tags/org.gvsig.dwg-2.0.246/org.gvsig.dwg.app/org.gvsig.dwg.app.mainplugin/src/test/java/org/gvsig/dwg/fmap/dal/store/dwg/TestDWG.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
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., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 IVER T.I. S.A. {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.dwg.fmap.dal.store.dwg; |
|
29 |
|
|
30 |
import java.io.File; |
|
31 |
|
|
32 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
33 |
import org.gvsig.fmap.dal.exception.DataException; |
|
34 |
import org.gvsig.fmap.dal.feature.BaseTestFeatureStore; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
36 |
|
|
37 |
public class TestDWG extends BaseTestFeatureStore { |
|
38 |
|
|
39 |
|
|
40 |
protected boolean testDXFInitialized = false; |
|
41 |
|
|
42 |
public static File file_prueba = new File(TestDWG.class.getResource( |
|
43 |
"data/V2000.dwg").getFile()); |
|
44 |
|
|
45 |
/* |
|
46 |
* (non-Javadoc) |
|
47 |
* |
|
48 |
* @see |
|
49 |
* org.gvsig.fmap.dal.feature.BaseTestFeatureStore#getDefaultDataStoreParameters |
|
50 |
* () |
|
51 |
*/ |
|
52 |
public DataStoreParameters getDefaultDataStoreParameters() |
|
53 |
throws DataException { |
|
54 |
DWGStoreParameters dwgParameters = null; |
|
55 |
|
|
56 |
dwgParameters = (DWGStoreParameters) dataManager |
|
57 |
.createStoreParameters(DWGStoreProvider.NAME); |
|
58 |
|
|
59 |
dwgParameters.setFile(file_prueba); |
|
60 |
dwgParameters.setCRS("EPSG:23030"); |
|
61 |
return dwgParameters; |
|
62 |
} |
|
63 |
|
|
64 |
/* |
|
65 |
* (non-Javadoc) |
|
66 |
* |
|
67 |
* @see org.gvsig.fmap.dal.feature.BaseTestFeatureStore#hasExplorer() |
|
68 |
*/ |
|
69 |
public boolean hasExplorer() { |
|
70 |
// TODO Auto-generated method stub |
|
71 |
return false; |
|
72 |
} |
|
73 |
|
|
74 |
public boolean usesResources() { |
|
75 |
return true; |
|
76 |
} |
|
77 |
|
|
78 |
|
|
79 |
public void testLegendAndLabeling() throws Exception { |
|
80 |
DataStoreParameters params = getDefaultDataStoreParameters(); |
|
81 |
FeatureStore store = (FeatureStore) dataManager.openStore(params |
|
82 |
.getDataStoreName(), params); |
|
83 |
|
|
84 |
assertNotNull(store.invokeDynMethod("getLegend", null)); |
|
85 |
assertNotNull(store.invokeDynMethod("getLabeling", null)); |
|
86 |
store.dispose(); |
|
87 |
} |
|
88 |
} |
tags/org.gvsig.dwg-2.0.246/org.gvsig.dwg.app/org.gvsig.dwg.app.mainplugin/src/test/java/org/gvsig/dwg/fmap/dal/store/dwg/TestDWG2004.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
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., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 IVER T.I {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.dwg.fmap.dal.store.dwg; |
|
29 |
|
|
30 |
import java.io.File; |
|
31 |
|
|
32 |
public class TestDWG2004 extends TestDWG { |
|
33 |
public static File file_prueba = new File(TestDWG.class.getResource( |
|
34 |
"data/V2004.dwg").getFile()); |
|
35 |
} |
tags/org.gvsig.dwg-2.0.246/org.gvsig.dwg.app/org.gvsig.dwg.app.mainplugin/src/main/resources-plugin/config.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<plugin-config> |
|
3 |
<libraries library-dir="lib"> |
|
4 |
</libraries> |
|
5 |
<depends plugin-name="org.gvsig.app.mainplugin"/> |
|
6 |
<resourceBundle name="text"/> |
|
7 |
<extensions> |
|
8 |
<extension class-name="org.gvsig.dwg.DWGRegisterExtension" |
|
9 |
description="DWG Driver" |
|
10 |
active="true"> |
|
11 |
</extension> |
|
12 |
|
|
13 |
</extensions> |
|
14 |
</plugin-config> |
tags/org.gvsig.dwg-2.0.246/org.gvsig.dwg.app/org.gvsig.dwg.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml | ||
---|---|---|
1 |
<assembly> |
|
2 |
<id>gvsig-plugin-package</id> |
|
3 |
<formats> |
|
4 |
<format>zip</format> |
|
5 |
</formats> |
|
6 |
<baseDirectory>${project.artifactId}</baseDirectory> |
|
7 |
<includeBaseDirectory>true</includeBaseDirectory> |
|
8 |
<files> |
|
9 |
<file> |
|
10 |
<source>target/${project.artifactId}-${project.version}.jar</source> |
|
11 |
<outputDirectory>lib</outputDirectory> |
|
12 |
</file> |
|
13 |
<file> |
|
14 |
<source>target/package.info</source> |
|
15 |
</file> |
|
16 |
</files> |
|
17 |
|
|
18 |
<fileSets> |
|
19 |
<fileSet> |
|
20 |
<directory>src/main/resources-plugin</directory> |
|
21 |
<outputDirectory>.</outputDirectory> |
|
22 |
</fileSet> |
|
23 |
</fileSets> |
|
24 |
|
|
25 |
<dependencySets> |
|
26 |
<dependencySet> |
|
27 |
<useProjectArtifact>false</useProjectArtifact> |
|
28 |
<useTransitiveDependencies>false</useTransitiveDependencies> |
|
29 |
<outputDirectory>lib</outputDirectory> |
|
30 |
<includes> |
|
31 |
<include>org.gvsig:org.gvsig.dwg.provider.legend</include> |
|
32 |
<include>org.gvsig:org.gvsig.dwg.provider</include> |
|
33 |
<include>org.gvsig:org.gvsig.dwg.lib</include> |
|
34 |
</includes> |
|
35 |
</dependencySet> |
|
36 |
</dependencySets> |
|
37 |
|
|
38 |
</assembly> |
tags/org.gvsig.dwg-2.0.246/org.gvsig.dwg.app/org.gvsig.dwg.app.mainplugin/src/main/java/org/gvsig/dwg/DWGRegisterExtension.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
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., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.dwg; |
|
23 |
|
|
24 |
import org.gvsig.andami.IconThemeHelper; |
|
25 |
import org.gvsig.andami.plugins.Extension; |
|
26 |
import org.gvsig.dwg.fmap.dal.store.dwg.DWGStoreProvider; |
|
27 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
28 |
|
|
29 |
/** |
|
30 |
* Dummy DWG extension, as all the registration happens in the |
|
31 |
* {@link DWGLibrary}. |
|
32 |
* |
|
33 |
* @author gvSIG Team |
|
34 |
*/ |
|
35 |
public class DWGRegisterExtension extends Extension { |
|
36 |
|
|
37 |
public void execute(String actionCommand) { |
|
38 |
// Nothing to do |
|
39 |
} |
|
40 |
|
|
41 |
public void initialize() { |
|
42 |
IconThemeHelper.registerIcon("layer", "layer-icon-dwg", this); |
|
43 |
} |
|
44 |
|
|
45 |
public void postInitialize() { |
|
46 |
MapContextLocator.getMapContextManager().registerIconLayer(DWGStoreProvider.NAME, "layer-icon-dwg"); |
|
47 |
} |
|
48 |
|
|
49 |
public boolean isEnabled() { |
|
50 |
// Nothing to do |
|
51 |
return false; |
|
52 |
} |
|
53 |
|
|
54 |
public boolean isVisible() { |
|
55 |
// Nothing to do |
|
56 |
return false; |
|
57 |
} |
|
58 |
|
|
59 |
} |
tags/org.gvsig.dwg-2.0.246/org.gvsig.dwg.app/org.gvsig.dwg.app.mainplugin/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
|
|
3 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
4 |
|
|
5 |
<modelVersion>4.0.0</modelVersion> |
|
6 |
<artifactId>org.gvsig.dwg.app.mainplugin</artifactId> |
|
7 |
<packaging>jar</packaging> |
|
8 |
<name>${project.artifactId}</name> |
|
9 |
<description> |
|
10 |
DWG file format support (read-only) |
|
11 |
|
|
12 |
Supported versions: |
|
13 |
- v12 |
|
14 |
- v14 |
|
15 |
- v15 |
|
16 |
- v2004 |
|
17 |
|
|
18 |
</description> |
|
19 |
<parent> |
|
20 |
<groupId>org.gvsig</groupId> |
|
21 |
<artifactId>org.gvsig.dwg.app</artifactId> |
|
22 |
<version>2.0.246</version> |
|
23 |
</parent> |
|
24 |
|
|
25 |
<dependencies> |
|
26 |
<dependency> |
|
27 |
<groupId>org.gvsig</groupId> |
|
28 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
29 |
<scope>compile</scope> |
|
30 |
</dependency> |
|
31 |
<dependency> |
|
32 |
<groupId>org.gvsig</groupId> |
|
33 |
<artifactId>org.gvsig.andami</artifactId> |
|
34 |
<scope>compile</scope> |
|
35 |
</dependency> |
|
36 |
<dependency> |
|
37 |
<groupId>org.gvsig</groupId> |
|
38 |
<artifactId>org.gvsig.dwg.provider</artifactId> |
|
39 |
<scope>compile</scope> |
|
40 |
</dependency> |
|
41 |
<dependency> |
|
42 |
<groupId>org.gvsig</groupId> |
|
43 |
<artifactId>org.gvsig.dwg.provider.legend</artifactId> |
|
44 |
<scope>compile</scope> |
|
45 |
</dependency> |
|
46 |
|
|
47 |
<dependency> |
|
48 |
<groupId>org.gvsig</groupId> |
|
49 |
<artifactId>org.gvsig.dwg.lib</artifactId> |
|
50 |
<scope>runtime</scope> |
|
51 |
</dependency> |
|
52 |
|
|
53 |
<!-- Tests --> |
|
54 |
|
|
55 |
<dependency> |
|
56 |
<groupId>org.gvsig</groupId> |
|
57 |
<artifactId>org.gvsig.fmap.dal.impl</artifactId> |
|
58 |
<type>test-jar</type> |
|
59 |
<scope>test</scope> |
|
60 |
</dependency> |
|
61 |
|
|
62 |
<dependency> |
|
63 |
<groupId>org.gvsig</groupId> |
|
64 |
<artifactId>org.gvsig.fmap.dal.impl</artifactId> |
|
65 |
<type>jar</type> |
|
66 |
<scope>test</scope> |
|
67 |
</dependency> |
|
68 |
|
|
69 |
</dependencies> |
|
70 |
|
|
71 |
<properties> |
|
72 |
<!-- Package info property values --> |
|
73 |
<!-- Default values in org.gvsig.desktop --> |
|
74 |
<gvsig.package.info.name>Formats: dwg file format support (read-only)</gvsig.package.info.name> |
|
75 |
<gvsig.package.info.state>testing</gvsig.package.info.state> |
|
76 |
<gvsig.package.info.official>true</gvsig.package.info.official> |
|
77 |
<gvsig.package.info.dependencies>required: org.gvsig.app.mainplugin -ge 2.1.0-A</gvsig.package.info.dependencies> |
|
78 |
<gvsig.package.info.categories>Formats,Vector</gvsig.package.info.categories> |
|
79 |
<gvsig.package.info.poolURL>https://devel.gvsig.org/download/projects/gvsig-dwg/pool</gvsig.package.info.poolURL> |
|
80 |
</properties> |
|
81 |
|
|
82 |
<build> |
|
83 |
<plugins> |
|
84 |
|
|
85 |
<plugin> |
|
86 |
<!-- Skip compilation tests --> |
|
87 |
<groupId>org.apache.maven.plugins</groupId> |
|
88 |
<artifactId>maven-compiler-plugin</artifactId> |
|
89 |
<executions> |
|
90 |
<execution> |
|
91 |
<id>default-testCompile</id> |
|
92 |
<phase>process-test-sources</phase> |
|
93 |
<goals> |
|
94 |
<goal>testCompile</goal> |
|
95 |
</goals> |
|
96 |
<configuration> |
|
97 |
<skip>true</skip> |
|
98 |
</configuration> |
|
99 |
</execution> |
|
100 |
</executions> |
|
101 |
</plugin> |
|
102 |
|
|
103 |
<plugin> |
|
104 |
<!-- Skip test execution --> |
|
105 |
<groupId>org.apache.maven.plugins</groupId> |
|
106 |
<artifactId>maven-surefire-plugin</artifactId> |
|
107 |
<configuration> |
|
108 |
<skipTests>true</skipTests> |
|
109 |
</configuration> |
|
110 |
</plugin> |
|
111 |
|
|
112 |
</plugins> |
|
113 |
</build> |
|
114 |
|
|
115 |
</project> |
|
116 |
|
|
0 | 117 |
tags/org.gvsig.dwg-2.0.246/org.gvsig.dwg.app/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
|
|
3 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
4 |
|
|
5 |
<modelVersion>4.0.0</modelVersion> |
|
6 |
<artifactId>org.gvsig.dwg.app</artifactId> |
|
7 |
<packaging>pom</packaging> |
|
8 |
<name>${project.artifactId}</name> |
|
9 |
<parent> |
|
10 |
<groupId>org.gvsig</groupId> |
|
11 |
<artifactId>org.gvsig.dwg</artifactId> |
|
12 |
<version>2.0.246</version> |
|
13 |
</parent> |
|
14 |
|
|
15 |
<modules> |
|
16 |
<module>org.gvsig.dwg.app.mainplugin</module> |
|
17 |
</modules> |
|
18 |
|
|
19 |
|
|
20 |
</project> |
tags/org.gvsig.dwg-2.0.246/org.gvsig.dwg.lib/src/test/java/org/gvsig/dwg/lib/DwgFileTest.java | ||
---|---|---|
1 |
package org.gvsig.dwg.lib; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.IOException; |
|
5 |
import java.net.URL; |
|
6 |
|
|
7 |
import junit.framework.TestCase; |
|
8 |
|
|
9 |
public class DwgFileTest extends TestCase { |
|
10 |
private File baseDataPath; |
|
11 |
|
|
12 |
protected void setUp() throws Exception { |
|
13 |
super.setUp(); |
|
14 |
URL url = this.getClass().getResource("data"); |
|
15 |
if (url == null) { |
|
16 |
throw new Exception("Can't find 'data' dir"); |
|
17 |
} |
|
18 |
|
|
19 |
baseDataPath = new File(url.getFile()); |
|
20 |
if (!baseDataPath.exists()) { |
|
21 |
throw new Exception("Can't find 'data' dir"); |
|
22 |
} |
|
23 |
|
|
24 |
} |
|
25 |
|
|
26 |
protected void tearDown() throws Exception { |
|
27 |
super.tearDown(); |
|
28 |
} |
|
29 |
public void test1() throws IOException, DwgVersionNotSupportedException { |
|
30 |
// String fileName = baseDataPath.getAbsolutePath()+"/Un punto.dwg"; |
|
31 |
// DwgFile dwg = new DwgFile(fileName); |
|
32 |
// |
|
33 |
// dwg.read(); |
|
34 |
// dwg.calculateGisModelDwgPolylines(); |
|
35 |
// dwg.blockManagement(); |
|
36 |
// LinkedList dwgObjects = dwg.getDwgObjects(); |
|
37 |
} |
|
38 |
|
|
39 |
public void test2() throws RuntimeException, CorruptedDwgEntityException{ |
|
40 |
//Dwg Object that is supposed to be |
|
41 |
//an LWPOLYLINE in V14 version |
|
42 |
/* |
|
43 |
int[] data = new int[]{61,64,64,183,19,227,104,16 |
|
44 |
,0,5,8,59,72,32,252,47,90,142, |
|
45 |
234,145,50,10,71,11,213,36,229, |
|
46 |
162,130,10,228,126,23,174,130, |
|
47 |
145,50,15,98,141,196,244,229, |
|
48 |
162,130,12,126,23,169,66,58, |
|
49 |
145,50,12,47,90,138,68,229, |
|
50 |
162,130,8,0,0,4,7,74,137,50, |
|
51 |
15,177,66,231,252,221,162,130, |
|
52 |
9,130,151,21,242,151,21,190, |
|
53 |
8,21,8,56}; |
|
54 |
*/ |
|
55 |
// int[] data = new int[]{62,128,64,71,99, |
|
56 |
// 40,48,0,5,8,27,72, |
|
57 |
// 100,126,23,169,68, |
|
58 |
// 178,105,50,13,114, |
|
59 |
// 63,11,82,165,162,130, |
|
60 |
// 13,114,63,11,210,138, |
|
61 |
// 105,50,8,173,114,59, |
|
62 |
// 138,205,162,130,15,98, |
|
63 |
// 141,192,241,58,105,50, |
|
64 |
// 11,51,51,52,178,229,162, |
|
65 |
// 130,14,110,102,98,97,234, |
|
66 |
// 105,50,11,51,51,52,179,21, |
|
67 |
// 162,130,10,149,192,240,42, |
|
68 |
// 162,105,50,14,189,27,131, |
|
69 |
// 107,69,162,130,14,31,169, |
|
70 |
// 66,227,74,105,50,9,240,86, |
|
71 |
// 185,27,117,162,130,11,59, |
|
72 |
// 51,51,52,234,105,50,13,114, |
|
73 |
// 63,11,83,85,162,130,9,74,228, |
|
74 |
// 126,22,186,105,50,11,51,51,50, |
|
75 |
// 51,53,162,130,11,137,232,82,190, |
|
76 |
// 58,105,50,9,74,228,122,147,13,162, |
|
77 |
// 130,11,137,232,82,189,106,105,50,9, |
|
78 |
// 74,228,122,146,213,162,130,9,74,228,122,20,202,105,50,12,126,23,171,194,173,162,130,12,126,23,169,68,178,105,50,13,114,63,11,82,165,162,130,9,130,151,22,10,136,182,8,21,8,120}; |
|
79 |
// //1er intento: suponemos que la LWPOLYLINE cumple la especificaci?n |
|
80 |
// //a rajatabla |
|
81 |
// int bitPos = 0; |
|
82 |
// List val = DwgUtil.getBitShort(data, bitPos); |
|
83 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
84 |
// int type = ((Integer) val.get(1)).intValue(); |
|
85 |
// System.out.println("type = " + type); |
|
86 |
// |
|
87 |
// DwgHandleReference hr = new DwgHandleReference(); |
|
88 |
// bitPos = hr.read(data, bitPos); |
|
89 |
// System.out.println("handle, code="+ |
|
90 |
// hr.getCode()+ |
|
91 |
// " ,offset="+ |
|
92 |
// hr.getOffset()); |
|
93 |
// |
|
94 |
// //Ahora pasamos a la extended data |
|
95 |
// val = DwgUtil.getBitShort(data, bitPos); |
|
96 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
97 |
// int extendedDataSize = ((Integer) val.get(1)).intValue(); |
|
98 |
// System.out.println("EED size="+extendedDataSize); |
|
99 |
// //como el size es 0, me lo salto |
|
100 |
// |
|
101 |
// //ver si tiene datos graficos |
|
102 |
// val = DwgUtil.testBit(data, bitPos); |
|
103 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
104 |
// boolean hasGraphicsData = ((Boolean) val.get(1)) |
|
105 |
// .booleanValue(); |
|
106 |
// System.out.println("graphics = "+hasGraphicsData); |
|
107 |
// |
|
108 |
// //como se que no hay graphics me lo salto |
|
109 |
// //tama?o en bits |
|
110 |
// val = DwgUtil.getRawLong(data, bitPos); |
|
111 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
112 |
// int sizeInBits = ((Integer) val.get(1)).intValue(); |
|
113 |
// System.out.println("sizeInBits = "+sizeInBits); |
|
114 |
// |
|
115 |
// /* |
|
116 |
// * Ahora, lo que viene es lo que en la spec se dice |
|
117 |
// * "Common entity data". Revisar bien pues PythonCAD no lo lee |
|
118 |
// * como en la spec. |
|
119 |
// * |
|
120 |
// * pag 42. |
|
121 |
// R13-R14 Only: |
|
122 |
// RL : Size of object data in bits |
|
123 |
// 6B : Flags (FEDCBA) |
|
124 |
// 6B : Common parameters (CCSSII) |
|
125 |
// Segun esto, deberia leer 6 bits y 6 bits |
|
126 |
// |
|
127 |
// FLAGS |
|
128 |
// Mas adelante (pag 43), dice: |
|
129 |
// DC : This is the number of reactors attached to an |
|
130 |
// entity as a bitshort. |
|
131 |
// This feature may have been dormant in R13, |
|
132 |
// but it appears in R14, and in files saved as R13 by R14. |
|
133 |
// |
|
134 |
// Ahora bien, pythoncad las est? leyendo como bitLong |
|
135 |
// ?En que quedamos, son 2 bits, 1 bitLong o 1 bitShort? |
|
136 |
// TODO REVISAR |
|
137 |
// |
|
138 |
// COMMON PARAMETERS |
|
139 |
// Al principio, dice que son 6 bits (CC, SS, II) |
|
140 |
// pero luego dice (pag 43): |
|
141 |
// CC : Color bitshort |
|
142 |
// SS : Linetype scale bitdouble |
|
143 |
// II : "Invisible" flag bitshort |
|
144 |
// |
|
145 |
// Pythoncad, en vez de como 2 bits, los est? leyendo |
|
146 |
// como BitShort, BitDouble y BitShort |
|
147 |
// |
|
148 |
// * */ |
|
149 |
// |
|
150 |
// Integer mode = (Integer) DwgUtil.getBits(data, 2, bitPos); |
|
151 |
// bitPos += 2; |
|
152 |
// System.out.println("mode = "+mode); |
|
153 |
// |
|
154 |
// /* |
|
155 |
// val = DwgUtil.getBitLong(data, bitPos); |
|
156 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
157 |
// int rnum = ((Integer) val.get(1)).intValue(); |
|
158 |
// System.out.println("numReactors = "+rnum); |
|
159 |
//*/ |
|
160 |
// val = DwgUtil.getBitShort(data, bitPos); |
|
161 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
162 |
// int rnum = ((Integer) val.get(1)).intValue(); |
|
163 |
// System.out.println("numReactors = "+rnum); |
|
164 |
// |
|
165 |
// |
|
166 |
// val = DwgUtil.testBit(data, bitPos); |
|
167 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
168 |
// boolean isLyrByLineType = ((Boolean) val.get(1)).booleanValue(); |
|
169 |
// System.out.println("isLyrByLineType="+isLyrByLineType); |
|
170 |
// |
|
171 |
// val = DwgUtil.testBit(data, bitPos); |
|
172 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
173 |
// boolean noLinks = ((Boolean) val.get(1)).booleanValue(); |
|
174 |
// System.out.println("noLinks="+noLinks); |
|
175 |
// |
|
176 |
// |
|
177 |
// val = DwgUtil.getBitShort(data, bitPos); |
|
178 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
179 |
// int color = ((Integer) val.get(1)).intValue(); |
|
180 |
// System.out.println("color="+color); |
|
181 |
// |
|
182 |
// |
|
183 |
// val = DwgUtil.getBitDouble(data, bitPos); |
|
184 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
185 |
// float ltscale = ((Double) val.get(1)).floatValue(); |
|
186 |
// System.out.println("ltscale="+ltscale); |
|
187 |
// |
|
188 |
// val = DwgUtil.getBitShort(data, bitPos); |
|
189 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
190 |
// int invis = ((Integer) val.get(1)).intValue(); |
|
191 |
// System.out.println("invis="+invis); |
|
192 |
// |
|
193 |
// val = DwgUtil.getBitShort(data, bitPos); |
|
194 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
195 |
// int flag = ((Integer) val.get(1)).intValue(); |
|
196 |
// System.out.println("flag="+flag); |
|
197 |
// |
|
198 |
// double dVal = 0d; |
|
199 |
// if((flag & 0x4) > 0){ |
|
200 |
// val = DwgUtil.getBitDouble(data, bitPos); |
|
201 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
202 |
// dVal = ((Double) val.get(1)).doubleValue(); |
|
203 |
// } |
|
204 |
// System.out.println("constWidth="+dVal); |
|
205 |
// |
|
206 |
// dVal = 0d; |
|
207 |
// if((flag & 0x8) > 0){ |
|
208 |
// val = DwgUtil.getBitDouble(data, bitPos); |
|
209 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
210 |
// dVal = ((Double) val.get(1)).doubleValue(); |
|
211 |
// } |
|
212 |
// System.out.println("elevation="+dVal); |
|
213 |
// |
|
214 |
// dVal = 0d; |
|
215 |
// if ((flag & 0x2) > 0){ |
|
216 |
// val = DwgUtil.getBitDouble(data, bitPos); |
|
217 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
218 |
// dVal = ((Double) val.get(1)).doubleValue(); |
|
219 |
// } |
|
220 |
// System.out.println("thickness="+dVal); |
|
221 |
// |
|
222 |
// double x, y, z ; |
|
223 |
// x = 0d; |
|
224 |
// y = 0d; |
|
225 |
// z = 0d; |
|
226 |
// |
|
227 |
// if ((flag & 0x1) > 0){ |
|
228 |
// val = DwgUtil.getBitDouble(data, bitPos); |
|
229 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
230 |
// x = ((Double) val.get(1)).doubleValue(); |
|
231 |
// |
|
232 |
// val = DwgUtil.getBitDouble(data, bitPos); |
|
233 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
234 |
// y = ((Double) val.get(1)).doubleValue(); |
|
235 |
// |
|
236 |
// val = DwgUtil.getBitDouble(data, bitPos); |
|
237 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
238 |
// z = ((Double) val.get(1)).doubleValue(); |
|
239 |
// } |
|
240 |
// System.out.println("normal="+x+","+y+","+z); |
|
241 |
// |
|
242 |
// val = DwgUtil.getBitLong(data, bitPos); |
|
243 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
244 |
// int np = ((Integer) val.get(1)).intValue(); |
|
245 |
// System.out.println("numPoints="+np); |
|
246 |
// |
|
247 |
// int nb = 0; |
|
248 |
// if((flag & 0x10) > 0){ |
|
249 |
// val = DwgUtil.getBitLong(data, bitPos); |
|
250 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
251 |
// nb = ((Integer) val.get(1)).intValue(); |
|
252 |
// } |
|
253 |
// System.out.println("numBulges="+nb); |
|
254 |
// int nw = 0; |
|
255 |
// if((flag & 0x20) > 0){ |
|
256 |
// val = DwgUtil.getBitLong(data, bitPos); |
|
257 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
258 |
// nw = ((Integer) val.get(1)).intValue(); |
|
259 |
// } |
|
260 |
// System.out.println("numWidths="+nw); |
|
261 |
// if(np > 0){ |
|
262 |
// Point2D[] points = new Point2D[np]; |
|
263 |
// for(int i = 0; i < np; i++){ |
|
264 |
// val = DwgUtil.getRawDouble(data, bitPos); |
|
265 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
266 |
// x = ((Double) val.get(1)).doubleValue(); |
|
267 |
// |
|
268 |
// val = DwgUtil.getRawDouble(data, bitPos); |
|
269 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
270 |
// y = ((Double) val.get(1)).doubleValue(); |
|
271 |
// |
|
272 |
// points[i] = new Point2D.Double(x, y); |
|
273 |
// System.out.println("Punto"+i+"="+x+","+y); |
|
274 |
// }//for |
|
275 |
// }//if np |
|
276 |
// |
|
277 |
// if(nb > 0){ |
|
278 |
// double[] bulges = new double[nb]; |
|
279 |
// for(int i = 0; i < nb; i++){ |
|
280 |
// val = DwgUtil.getRawDouble(data, bitPos); |
|
281 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
282 |
// bulges[i] = ((Double) val.get(1)).doubleValue(); |
|
283 |
// System.out.println("Bulge"+i+"="+bulges[i]); |
|
284 |
// }//for |
|
285 |
// |
|
286 |
// }//if nb |
|
287 |
// |
|
288 |
// if(nw > 0){ |
|
289 |
// double[][] widths = new double[nw][2]; |
|
290 |
// for(int i = 0; i < nw; i++){ |
|
291 |
// val = DwgUtil.getBitDouble(data, bitPos); |
|
292 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
293 |
// double sw = ((Double) val.get(1)).doubleValue(); |
|
294 |
// |
|
295 |
// val = DwgUtil.getBitDouble(data, bitPos); |
|
296 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
297 |
// double ew = ((Double) val.get(1)).doubleValue(); |
|
298 |
// |
|
299 |
// widths[i][0] = sw; |
|
300 |
// widths[i][1] = ew; |
|
301 |
// System.out.println("Width"+i+"="+sw+","+ew); |
|
302 |
// }//for |
|
303 |
// } |
|
304 |
} |
|
305 |
|
|
306 |
public void test3(){ |
|
307 |
//test of extrusion |
|
308 |
double[] coord = null; |
|
309 |
double[] extrusion = null; |
|
310 |
double[] extrusion2 = new double[]{0, 0, 1}; |
|
311 |
|
|
312 |
coord = new double[]{790089.65, 4477974.75, 9.560000000114087}; |
|
313 |
extrusion = new double[]{-0.5037965987025721, 0.07005064807841195, 0.8609772899673451}; |
|
314 |
//1. algoritmo original, vector normal distinto |
|
315 |
// double[] newCoord = AcadExtrusionCalculator.extrude(coord, extrusion); |
|
316 |
// newCoord = AcadExtrusionCalculator.extrude3(coord, extrusion); |
|
317 |
// |
|
318 |
//2? ahora con vector normal coincidente con eje Z |
|
319 |
// newCoord = AcadExtrusionCalculator.extrude(coord, extrusion2); |
|
320 |
// newCoord = AcadExtrusionCalculator.extrude3(coord, extrusion2); |
|
321 |
} |
|
322 |
} |
tags/org.gvsig.dwg-2.0.246/org.gvsig.dwg.lib/src/test/java/org/gvsig/dwg/lib/DwgTestSuite.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 08-feb-2007 |
|
3 |
* |
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
5 |
* |
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Generalitat Valenciana |
|
25 |
* Conselleria d'Infraestructures i Transport |
|
26 |
* Av. Blasco Ib??ez, 50 |
|
27 |
* 46010 VALENCIA |
|
28 |
* SPAIN |
|
29 |
* |
|
30 |
* +34 963862235 |
|
31 |
* gvsig@gva.es |
|
32 |
* www.gvsig.gva.es |
|
33 |
* |
|
34 |
* or |
|
35 |
* |
|
36 |
* IVER T.I. S.A |
|
37 |
* Salamanca 50 |
|
38 |
* 46005 Valencia |
|
39 |
* Spain |
|
40 |
* |
|
41 |
* +34 963163400 |
|
42 |
* dac@iver.es |
|
43 |
*/ |
|
44 |
/* CVS MESSAGES: |
|
45 |
* |
|
46 |
* $Id: DwgTestSuite.java 28970 2009-05-25 13:27:14Z jmvivo $ |
|
47 |
* $Log$ |
|
48 |
* Revision 1.1.2.1 2007-02-28 07:35:10 jmvivo |
|
49 |
* Actualizado desde el HEAD. |
|
50 |
* |
|
51 |
* Revision 1.1 2007/02/08 20:27:57 azabala |
|
52 |
* *** empty log message *** |
|
53 |
* |
|
54 |
* |
|
55 |
*/ |
|
56 |
package org.gvsig.dwg.lib; |
|
57 |
|
|
58 |
import junit.framework.Test; |
|
59 |
import junit.framework.TestSuite; |
|
60 |
|
|
61 |
public class DwgTestSuite { |
|
62 |
|
|
63 |
public static Test suite() { |
|
64 |
TestSuite suite = new TestSuite("Test for com.iver.cit.jdwglib.dwg"); |
|
65 |
//$JUnit-BEGIN$ |
|
66 |
suite.addTestSuite(DwgFileTest.class); |
|
67 |
//$JUnit-END$ |
|
68 |
return suite; |
|
69 |
} |
|
70 |
|
|
71 |
} |
|
72 |
|
tags/org.gvsig.dwg-2.0.246/org.gvsig.dwg.lib/src/main/java/org/gvsig/dwg/lib/DwgFile.java | ||
---|---|---|
1 |
/* jdwglib. Java Library for reading Dwg files. |
|
2 |
* |
|
3 |
* Author: Jose Morell Rama (jose.morell@gmail.com). |
|
4 |
* Port from the Pythoncad Dwg library by Art Haas. |
|
5 |
* |
|
6 |
* Copyright (C) 2005 Jose Morell, IVER TI S.A. and Generalitat Valenciana |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Jose Morell (jose.morell@gmail.com) |
|
25 |
* |
|
26 |
* or |
|
27 |
* |
|
28 |
* IVER TI S.A. |
|
29 |
* C/Salamanca, 50 |
|
30 |
* 46005 Valencia |
|
31 |
* Spain |
|
32 |
* +34 963163400 |
|
33 |
* dac@iver.es |
|
34 |
*/ |
|
35 |
package org.gvsig.dwg.lib; |
|
36 |
|
|
37 |
import java.awt.geom.Point2D; |
|
38 |
import java.io.File; |
|
39 |
import java.io.FileInputStream; |
|
40 |
import java.io.IOException; |
|
41 |
import java.nio.ByteBuffer; |
|
42 |
import java.nio.channels.FileChannel; |
|
43 |
import java.util.ArrayList; |
|
44 |
import java.util.HashMap; |
|
45 |
import java.util.Iterator; |
|
46 |
import java.util.List; |
|
47 |
import java.util.Map; |
|
48 |
|
|
49 |
import org.gvsig.dwg.lib.objects.DwgBlockHeader; |
|
50 |
import org.gvsig.dwg.lib.objects.DwgInsert; |
|
51 |
import org.gvsig.dwg.lib.objects.DwgLayer; |
|
52 |
import org.gvsig.dwg.lib.readers.DwgFileV12Reader; |
|
53 |
import org.gvsig.dwg.lib.readers.DwgFileV14Reader; |
|
54 |
import org.gvsig.dwg.lib.readers.DwgFileV15Reader; |
|
55 |
import org.gvsig.dwg.lib.readers.DwgFileVR2004Reader; |
|
56 |
import org.gvsig.dwg.lib.readers.IDwgFileReader; |
|
57 |
import org.slf4j.Logger; |
|
58 |
import org.slf4j.LoggerFactory; |
|
59 |
|
|
60 |
|
|
61 |
/** |
|
62 |
* The DwgFile class provides a revision-neutral interface for reading and handling |
|
63 |
* DWG files |
|
64 |
* Reading methods are useful for reading DWG files, and handling methods like |
|
65 |
* calculateDwgPolylines() are useful for handling more complex |
|
66 |
* objects in the DWG file |
|
67 |
* |
|
68 |
* @author jmorell |
|
69 |
* @author azabala |
|
70 |
*/ |
|
71 |
public class DwgFile { |
|
72 |
/** |
|
73 |
* It has all known DWG version's header. |
|
74 |
* Extracted from Autodesk web. |
|
75 |
*/ |
|
76 |
private static HashMap acadVersions = new HashMap(); |
|
77 |
static{ |
|
78 |
acadVersions.put("AC1004", "Autocad R9"); |
|
79 |
acadVersions.put("AC1006", "Autocad R10"); |
|
80 |
acadVersions.put("AC1007", "Autocad pre-R11"); |
|
81 |
acadVersions.put("AC1007", "Autocad pre-R11"); |
|
82 |
acadVersions.put("AC1008", "Autocad pre-R11b"); |
|
83 |
acadVersions.put("AC1009", "Autocad R12"); |
|
84 |
acadVersions.put("AC1010", "Autocad pre-R13 a"); |
|
85 |
acadVersions.put("AC1011", "Autocad pre-R13 b"); |
|
86 |
acadVersions.put("AC1012", "Autocad R13"); |
|
87 |
acadVersions.put("AC1013", "Autocad pre-R14"); |
|
88 |
acadVersions.put("AC1014", "Autocad R14"); |
|
89 |
acadVersions.put("AC1500", "Autocad pre-2000"); |
|
90 |
acadVersions.put("AC1015", "Autocad R2000, R2000i, R2002"); |
|
91 |
acadVersions.put("AC402a", "Autocad pre-2004a"); |
|
92 |
acadVersions.put("AC402b", "Autocad pre-2004b"); |
|
93 |
acadVersions.put("AC1018", "Autocad R2004, R2005, R2006"); |
|
94 |
acadVersions.put("AC1021", "Autocad R2007"); |
|
95 |
|
|
96 |
} |
|
97 |
|
|
98 |
private static Logger logger = LoggerFactory.getLogger(DwgFile.class.getName()); |
|
99 |
/** |
|
100 |
* Path and name of the dwg file |
|
101 |
* */ |
|
102 |
private String fileName; |
|
103 |
/** |
|
104 |
* DWG version of the file (AC1013, AC1018, etc.) |
|
105 |
* */ |
|
106 |
private String dwgVersion; |
|
107 |
|
|
108 |
/** |
|
109 |
* Offsets to the DWG sections |
|
110 |
*/ |
|
111 |
private ArrayList dwgSectionOffsets; |
|
112 |
/** |
|
113 |
* Header vars readed from the HEADER section of the DWG file |
|
114 |
* */ |
|
115 |
private Map headerVars; |
|
116 |
|
|
117 |
/** |
|
118 |
* This list contains what in OpenDWG specification is called |
|
119 |
* the object map ( a collection of entries where each entry contains |
|
120 |
* the seek of each object, and its size) |
|
121 |
* */ |
|
122 |
private ArrayList dwgObjectOffsets; |
|
123 |
|
|
124 |
/** |
|
125 |
* For each entry in dwgObjectOffsets, we have an instance of |
|
126 |
* DwgObject in the dwgObjects collection |
|
127 |
* |
|
128 |
* */ |
|
129 |
private List dwgObjects; |
|
130 |
private HashMap handle_objects; |
|
131 |
|
|
132 |
|
|
133 |
private ArrayList dwgClasses; |
|
134 |
|
|
135 |
|
|
136 |
/** |
|
137 |
* hash map that indexes all DwgLayer objects |
|
138 |
* by its handle property |
|
139 |
* */ |
|
140 |
private HashMap layerTable; |
|
141 |
|
|
142 |
/** |
|
143 |
* Specific reader of the DWG file version (12, 13, 14, 2000, etc., each |
|
144 |
* version will have an specific reader) |
|
145 |
* */ |
|
146 |
private IDwgFileReader dwgReader; |
|
147 |
private boolean dwg3DFile = false; |
|
148 |
/** |
|
149 |
* Memory mapped byte buffer of the whole DWG file |
|
150 |
* */ |
|
151 |
private ByteBuffer bb; |
|
152 |
|
|
153 |
/* |
|
154 |
* Optimizaciones para evitar leer el fichero completo en cada |
|
155 |
* pasada. |
|
156 |
* */ |
|
157 |
/** |
|
158 |
* Contains all IDwgPolyline implementations |
|
159 |
* */ |
|
160 |
private List dwgPolylines; |
|
161 |
/** |
|
162 |
* Contains all INSERT entities of the dwg file |
|
163 |
* (these entities must be processed in a second pass) |
|
164 |
* |
|
165 |
* */ |
|
166 |
private List insertList; |
|
167 |
|
|
168 |
private List blockList; |
|
169 |
|
|
170 |
|
|
171 |
/** |
|
172 |
* Constructor. |
|
173 |
* @param fileName an absolute path to the DWG file |
|
174 |
*/ |
|
175 |
public DwgFile(String fileName) { |
|
176 |
this.fileName = fileName; |
|
177 |
|
|
178 |
dwgSectionOffsets = new ArrayList(); |
|
179 |
dwgObjectOffsets = new ArrayList(); |
|
180 |
headerVars = new HashMap(); |
|
181 |
|
|
182 |
dwgClasses = new ArrayList(); |
|
183 |
|
|
184 |
dwgObjects = new ArrayList(); |
|
185 |
handle_objects = new HashMap(); |
|
186 |
|
|
187 |
layerTable = new HashMap(); |
|
188 |
|
|
189 |
dwgPolylines = new ArrayList(); |
|
190 |
insertList = new ArrayList(); |
|
191 |
|
|
192 |
blockList = new ArrayList(); |
|
193 |
|
|
194 |
} |
|
195 |
|
|
196 |
public String getDwgVersion() { |
|
197 |
return dwgVersion; |
|
198 |
} |
|
199 |
|
|
200 |
/** |
|
201 |
* Reads a DWG file and put its objects in the dwgObjects Vector |
|
202 |
* This method is version independent |
|
203 |
* |
|
204 |
* @throws IOException If the file location is wrong |
|
205 |
*/ |
|
206 |
public void read() throws IOException, |
|
207 |
DwgVersionNotSupportedException |
|
208 |
{ |
|
209 |
setDwgVersion(); |
|
210 |
if (dwgVersion.equalsIgnoreCase("Autocad R2000, R2000i, R2002")) { |
|
211 |
dwgReader = new DwgFileV15Reader(); |
|
212 |
}else if (dwgVersion.equalsIgnoreCase("Autocad pre-R14")|| |
|
213 |
dwgVersion.equalsIgnoreCase("Autocad R14") || |
|
214 |
dwgVersion.equalsIgnoreCase("Autocad R13")) { |
|
215 |
dwgReader = new DwgFileV14Reader(); |
|
216 |
}else if (dwgVersion.equalsIgnoreCase("Autocad R2004, R2005, R2006")){ |
|
217 |
dwgReader = new DwgFileVR2004Reader(); |
|
218 |
} else if (dwgVersion.equalsIgnoreCase("Autocad R12")|| |
|
219 |
dwgVersion.equalsIgnoreCase("Autocad pre-R13 a") || |
|
220 |
dwgVersion.equalsIgnoreCase("Autocad pre-R13 b")) { |
|
221 |
|
|
222 |
boolean isR13 = true; |
|
223 |
if(dwgVersion.equalsIgnoreCase("Autocad R12")) |
|
224 |
isR13 = false; |
|
225 |
dwgReader = new DwgFileV12Reader(isR13); |
|
226 |
}else { |
|
227 |
DwgVersionNotSupportedException exception = |
|
228 |
new DwgVersionNotSupportedException("Version de DWG no soportada"); |
|
229 |
exception.setDwgVersion(dwgVersion); |
|
230 |
throw exception; |
|
231 |
} |
|
232 |
try{ |
|
233 |
dwgReader.read(this, bb); |
|
234 |
}catch(Throwable t){ |
|
235 |
t.printStackTrace(); |
|
236 |
throw new IOException("Error leyendo dwg"); |
|
237 |
} |
|
238 |
} |
|
239 |
|
|
240 |
private void setDwgVersion() throws IOException { |
|
241 |
File file = new File(fileName); |
|
242 |
FileInputStream fileInputStream = new FileInputStream(file); |
|
243 |
FileChannel fileChannel = fileInputStream.getChannel(); |
|
244 |
long channelSize = fileChannel.size(); |
|
245 |
bb = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, channelSize); |
|
246 |
byte[] versionBytes = {bb.get(0), |
|
247 |
bb.get(1), |
|
248 |
bb.get(2), |
|
249 |
bb.get(3), |
|
250 |
bb.get(4), |
|
251 |
bb.get(5)}; |
|
252 |
ByteBuffer versionByteBuffer = ByteBuffer.wrap(versionBytes); |
|
253 |
String[] bs = new String[versionByteBuffer.capacity()]; |
|
254 |
String versionString = ""; |
|
255 |
for (int i=0; i<versionByteBuffer.capacity(); i++) { |
|
256 |
bs[i] = new String(new byte[]{(byte)(versionByteBuffer.get(i))}); |
|
257 |
versionString = versionString + bs[i]; |
|
258 |
} |
|
259 |
String version = (String) acadVersions.get(versionString); |
|
260 |
if(version == null) |
|
261 |
version = "Unknown Dwg format"; |
|
262 |
this.dwgVersion = version; |
|
263 |
} |
|
264 |
|
|
265 |
public void setHeader(String key, Object value){ |
|
266 |
headerVars.put(key, value); |
|
267 |
} |
|
268 |
|
|
269 |
public Object getHeader(String key){ |
|
270 |
return headerVars.get(key); |
|
271 |
} |
|
272 |
|
|
273 |
/* |
|
274 |
* A DwgLayer is a DWG drawing entity, so all DwgLayer objects are |
|
275 |
* saved in dwgObjects collection. |
|
276 |
* Instead of iterate over the full collection, is faster check every object |
|
277 |
* and save all the DwgLayer instances in their own collection. |
|
278 |
* |
|
279 |
*/ |
|
280 |
protected void addDwgLayer(DwgLayer dwgLayer){ |
|
281 |
layerTable.put(new Integer(dwgLayer.getHandle().getOffset()), |
|
282 |
dwgLayer); |
|
283 |
} |
|
284 |
|
|
285 |
private void printInfoOfAObject (DwgObject entity){ |
|
286 |
logger.info("index = "+entity.getIndex() + " entity.type = " + entity.type + " entityClassName = "+ entity.getClass().getName()); |
|
287 |
logger.info("handleCode = "+entity.getHandle().getCode()); |
|
288 |
logger.info("entityLayerHandle = "+entity.getHandle().getOffset()); |
|
289 |
if(entity.hasLayerHandle()){ |
|
290 |
logger.info("layerHandleCode = "+entity.getLayerHandle().getCode()); |
|
291 |
logger.info("layerHandle = "+entity.getLayerHandle().getOffset()); |
|
292 |
} |
|
293 |
if(entity.hasSubEntityHandle()){ |
|
294 |
logger.info("subEntityHandleCode = "+entity.getSubEntityHandle().getCode()); |
|
295 |
logger.info("subEntityHandle = "+entity.getSubEntityHandle().getOffset()); |
|
296 |
} |
|
297 |
if(entity.hasNextHandle()){ |
|
298 |
logger.info("nextHandleCode = "+entity.getNextHandle().getCode()); |
|
299 |
logger.info("nextHandle = "+entity.getNextHandle().getOffset()); |
|
300 |
} |
|
301 |
if(entity.hasPreviousHandle()){ |
|
302 |
logger.info ("previousHandleCode = "+entity.getPreviousHandle().getCode()); |
|
303 |
logger.info ("previousHandle = "+entity.getPreviousHandle().getOffset()); |
|
304 |
} |
|
305 |
if(entity.hasXDicObjHandle()){ |
|
306 |
logger.info ("xDicObjHandleCode = "+entity.getXDicObjHandle()); |
|
307 |
logger.info ("xDicObjHandle = "+entity.getXDicObjHandle()); |
|
308 |
} |
|
309 |
if(entity.hasReactorsHandles()){ |
|
310 |
ArrayList reactorsHandles = entity.getReactorsHandles(); |
|
311 |
int size = reactorsHandles.size(); |
|
312 |
logger.info ("NUMERO DE reactors = "+size); |
|
313 |
DwgHandleReference hr; |
|
314 |
for(int i=0; i<size; i++){ |
|
315 |
hr=(DwgHandleReference)reactorsHandles.get(i); |
|
316 |
logger.info ("reactorHandleCode = "+hr.getCode()); |
|
317 |
logger.info (" reactorHandle = "+hr.getOffset()); |
|
318 |
} |
|
319 |
} |
|
320 |
|
|
321 |
} |
|
322 |
public DwgLayer getDwgLayer(DwgObject entity){ |
|
323 |
DwgHandleReference handle = entity.getLayerHandle(); |
|
324 |
if(handle == null){ |
|
325 |
return null; |
|
326 |
} |
|
327 |
int handleCode = handle.getCode(); |
|
328 |
int entityLayerHandle = entity.getLayerHandle().getOffset(); |
|
329 |
int layerHandle = -1; |
|
330 |
|
|
331 |
int entityRecord; |
|
332 |
DwgObject object; |
|
333 |
|
|
334 |
|
|
335 |
/* |
|
336 |
* OpenDWG spec, v3, page 11. HANDLE REFERENCES |
|
337 |
* |
|
338 |
* A handle is formed by this fields: |
|
339 |
* a) CODE (4 bits) |
|
340 |
* b) COUNTER (4 bits) |
|
341 |
* c) OFFSET of the object (handle itself). |
|
342 |
* |
|
343 |
* CODE could take these values: |
|
344 |
* 1) 0x2, 0x3, 0x4, 0x5 -> offset is the handle of the layer |
|
345 |
* 2) 0x6 -> offset is the next object handle |
|
346 |
* 3) 0x8 -> offset is the previous object handle |
|
347 |
* 4) 0xA -> result is reference handle plus offset |
|
348 |
* 5) 0xC -> result is reference handle minus offset |
|
349 |
* |
|
350 |
* */ |
|
351 |
|
|
352 |
// FIXME: Esto no esta terminado. Falta considerar los codigo |
|
353 |
// 0x2, 0x3, 0x6, 0xA que no han aparecido en los archivos de prueba. |
|
354 |
switch(handleCode){ |
|
355 |
case 0x4: |
|
356 |
if (entity.hasNextHandle()){ |
|
357 |
int nextHandleCode = entity.getNextHandle().getCode(); |
|
358 |
if (nextHandleCode == 0x5) { |
|
359 |
layerHandle = entity.getNextHandle().getOffset(); |
|
360 |
} else { |
|
361 |
//TODO: No se han previsto nextHandleCode != 0x5 |
|
362 |
// System.out.println ("DwgFile.getDwgLayer: handleCode "+handleCode+ |
|
363 |
// " con nextHandleCode "+ nextHandleCode +" no implementado."); |
|
364 |
} |
|
365 |
} else { |
|
366 |
layerHandle = entity.getLayerHandle().getOffset(); |
|
367 |
} |
|
368 |
break; |
|
369 |
case 0x5: |
|
370 |
layerHandle = entity.getLayerHandle().getOffset(); |
|
371 |
break; |
|
372 |
case 0x8: |
|
373 |
if (entity.hasNextHandle()){ |
|
374 |
int nextHandleCode = entity.getNextHandle().getCode(); |
|
375 |
if (nextHandleCode == 0x5) { |
|
376 |
layerHandle = entity.getNextHandle().getOffset(); |
|
377 |
} else { |
|
378 |
//TODO No se han previsto nextHandleCode != 0x5 |
|
379 |
// System.out.println ("DwgFile.getDwgLayer: handleCode "+handleCode+ |
|
380 |
// " con nextHandleCode "+ nextHandleCode +" no implementado."); |
|
381 |
} |
|
382 |
} else { |
|
383 |
layerHandle = entity.getHandle().getOffset() - 1; |
|
384 |
} |
|
385 |
break; |
|
386 |
case 0xC: |
|
387 |
if (entity.hasNextHandle()){ |
|
388 |
int nextHandleCode = entity.getNextHandle().getCode(); |
|
389 |
if (nextHandleCode == 0x5) { |
|
390 |
layerHandle = entity.getNextHandle().getOffset(); |
|
391 |
} else { |
|
392 |
//TODO: No se han previsto nextHandleCode != 0x5 |
|
393 |
// System.out.println ("DwgFile.getDwgLayer: handleCode "+handleCode+ |
|
394 |
// " con nextHandleCode "+ nextHandleCode +" no implementado."); |
|
395 |
} |
|
396 |
} else { |
|
397 |
layerHandle = entity.getHandle().getOffset() - entity.getLayerHandle().getOffset() + 1; |
|
398 |
} |
|
399 |
break; |
|
400 |
default: |
|
401 |
// System.out.println ("DwgFile.getDwgLayer: handleCode "+handleCode+" no implementado. entityLayerHandle="+entityLayerHandle); |
|
402 |
} |
|
403 |
|
|
404 |
if(layerHandle != -1){ |
|
405 |
Iterator lyrIterator = layerTable.values().iterator(); |
|
406 |
while(lyrIterator.hasNext()){ |
|
407 |
DwgLayer lyr = (DwgLayer) lyrIterator.next(); |
|
408 |
int lyrHdl = lyr.getHandle().getOffset(); |
|
409 |
if (lyrHdl == layerHandle){ |
|
410 |
return lyr; |
|
411 |
} |
|
412 |
} |
|
413 |
} |
|
414 |
// System.out.println("NO SE HA ENCONTRADO UNA CAPA CON HANDLE " + layerHandle); |
|
415 |
// printInfoOfAObject(entity); |
|
416 |
return null; |
|
417 |
} |
|
418 |
|
|
419 |
public DwgObject getDwgSuperEntity(DwgObject entity) { |
|
420 |
if(entity.hasSubEntityHandle()){ |
|
421 |
int handleCode = entity.subEntityHandle.getCode(); |
|
422 |
int offset = entity.subEntityHandle.getOffset(); |
|
423 |
int handle = -1; |
|
424 |
|
|
425 |
DwgObject object; |
|
426 |
|
|
427 |
switch(handleCode){ |
|
428 |
// TODO: case 0x2: |
|
429 |
// TODO: case 0x3: |
|
430 |
case 0x4: |
|
431 |
case 0x5: |
|
432 |
handle = offset; |
|
433 |
break; |
|
434 |
// TODO: case 0x6: |
|
435 |
case 0x8: |
|
436 |
handle=entity.getHandle().getOffset() - 1; |
|
437 |
break; |
|
438 |
case 0xA: |
|
439 |
handle = entity.getHandle().getOffset() + offset; |
|
440 |
break; |
|
441 |
case 0xC: |
|
442 |
handle = entity.getHandle().getOffset() - offset; |
|
443 |
break; |
|
444 |
default: |
|
445 |
logger.warn ("DwgObject.getDwgSuperEntity: handleCode "+handleCode+" no implementado. offset = "+offset); |
|
446 |
} |
|
447 |
if(handle != -1){ |
|
448 |
object = getDwgObjectFromHandle(handle); |
|
449 |
if(object != null) |
|
450 |
return object; |
|
451 |
} |
|
452 |
} |
|
453 |
return null; |
|
454 |
} |
|
455 |
|
|
456 |
public String getLayerName(DwgObject entity) { |
|
457 |
DwgLayer dwgLayer = getDwgLayer(entity); |
|
458 |
if(dwgLayer == null){ |
|
459 |
return ""; |
|
460 |
}else{ |
|
461 |
return dwgLayer.getName(); |
|
462 |
} |
|
463 |
} |
|
464 |
|
|
465 |
/** |
|
466 |
* Returns the color of the layer of a DWG object |
|
467 |
* |
|
468 |
* @param entity DWG object which we want to know its layer color |
|
469 |
* @return int Layer color of the DWG object in the Autocad color code |
|
470 |
*/ |
|
471 |
public int getColorByLayer(DwgObject entity) { |
|
472 |
int colorByLayer; |
|
473 |
DwgLayer dwgLyr = getDwgLayer(entity); |
|
474 |
if(dwgLyr == null) |
|
475 |
colorByLayer = 0; |
|
476 |
else |
|
477 |
colorByLayer = dwgLyr.getColor(); |
|
478 |
return colorByLayer; |
|
479 |
} |
|
480 |
/** |
|
481 |
* Configure the geometry of the polylines in a DWG file from the vertex list in |
|
482 |
* this DWG file. This geometry is given by an array of Points. |
|
483 |
* Besides, manage closed polylines and polylines with bulges in a GIS Data model. |
|
484 |
* It means that the arcs of the polylines will be done through a set of points and |
|
485 |
* a distance between these points. |
|
486 |
*/ |
|
487 |
public void calculateGisModelDwgPolylines() { |
|
488 |
/* |
|
489 |
* In Dwg 12 format, all vertices of a polyline are between polyline entity |
|
490 |
* and endsec entity. Also, polylines dont save any handle of their vertices (first and last). |
|
491 |
* |
|
492 |
* After Dwg 12 version, we have the opposite case: polylines have handles/pointers to their |
|
493 |
* first and last vertices. |
|
494 |
* |
|
495 |
* If dwg file is not V12, we must look for all polyline vertices (and we must to wait until |
|
496 |
* all entities are readed). |
|
497 |
* If dwg file is V12, all polylines already have their vertices. |
|
498 |
* */ |
|
499 |
if(! (dwgReader instanceof DwgFileV12Reader)){ |
|
500 |
for (int i = 0; i < dwgPolylines.size(); i++){ |
|
501 |
DwgObject pol = (DwgObject)dwgPolylines.get(i); |
|
502 |
if (pol instanceof IDwgPolyline) { |
|
503 |
((IDwgPolyline)pol).calculateGisModel(this); |
|
504 |
}//if |
|
505 |
}//for |
|
506 |
} |
|
507 |
} |
|
508 |
|
|
509 |
/** |
|
510 |
* Configure the geometry of the polylines in a DWG file from the vertex list in |
|
511 |
* this DWG file. This geometry is given by an array of Points |
|
512 |
* Besides, manage closed polylines and polylines with bulges in a GIS Data model. |
|
513 |
* It means that the arcs of the polylines will be done through a curvature |
|
514 |
* parameter called bulge associated with the points of the polyline. |
|
515 |
*/ |
|
516 |
//TODO Refactorizar para que solo se aplique a las Polilineas |
|
517 |
|
|
518 |
// public void calculateCadModelDwgPolylines() { |
|
519 |
// for (int i=0;i<dwgObjects.size();i++) { |
|
520 |
// DwgObject pol = (DwgObject)dwgObjects.get(i); |
|
521 |
// if (pol instanceof DwgPolyline2D) { |
|
522 |
// int flags = ((DwgPolyline2D)pol).getFlags(); |
|
523 |
// int firstHandle = ((DwgPolyline2D)pol).getFirstVertexHandle().getOffset(); |
|
524 |
// int lastHandle = ((DwgPolyline2D)pol).getLastVertexHandle().getOffset(); |
|
525 |
// ArrayList pts = new ArrayList(); |
|
526 |
// ArrayList bulges = new ArrayList(); |
|
527 |
// double[] pt = new double[3]; |
|
528 |
// for (int j=0;j<dwgObjects.size();j++) { |
|
529 |
// DwgObject firstVertex = (DwgObject)dwgObjects.get(j); |
|
530 |
// if (firstVertex instanceof DwgVertex2D) { |
|
531 |
// int vertexHandle = firstVertex.getHandle().getOffset(); |
|
532 |
// if (vertexHandle==firstHandle) { |
|
533 |
// int k=0; |
|
534 |
// while (true) { |
|
535 |
// DwgObject vertex = (DwgObject)dwgObjects.get(j+k); |
|
536 |
// int vHandle = vertex.getHandle().getOffset(); |
|
537 |
// if (vertex instanceof DwgVertex2D) { |
|
538 |
// pt = ((DwgVertex2D)vertex).getPoint(); |
|
539 |
// pts.add(new Point2D.Double(pt[0], pt[1])); |
|
540 |
// double bulge = ((DwgVertex2D)vertex).getBulge(); |
|
541 |
// bulges.add(new Double(bulge)); |
|
542 |
// k++; |
|
543 |
// if (vHandle==lastHandle && vertex instanceof DwgVertex2D) { |
|
544 |
// break; |
|
545 |
// } |
|
546 |
// } else if (vertex instanceof DwgSeqend) { |
|
547 |
// break; |
|
548 |
// } |
|
549 |
// } |
|
550 |
// } |
|
551 |
// } |
|
552 |
// } |
|
553 |
// if (pts.size()>0) { |
|
554 |
// /*Point2D[] newPts = new Point2D[pts.size()]; |
|
555 |
// if ((flags & 0x1)==0x1) { |
|
556 |
// newPts = new Point2D[pts.size()+1]; |
|
557 |
// for (int j=0;j<pts.size();j++) { |
|
558 |
// newPts[j] = (Point2D)pts.get(j); |
|
559 |
// } |
|
560 |
// newPts[pts.size()] = (Point2D)pts.get(0); |
|
561 |
// bulges.add(new Double(0)); |
|
562 |
// } else { |
|
563 |
// for (int j=0;j<pts.size();j++) { |
|
564 |
// newPts[j] = (Point2D)pts.get(j); |
|
565 |
// } |
|
566 |
// }*/ |
|
567 |
// double[] bs = new double[bulges.size()]; |
|
568 |
// for (int j=0;j<bulges.size();j++) { |
|
569 |
// bs[j] = ((Double)bulges.get(j)).doubleValue(); |
|
570 |
// } |
|
571 |
// ((DwgPolyline2D)pol).setBulges(bs); |
|
572 |
// //Point2D[] points = GisModelCurveCalculator.calculateGisModelBulge(newPts, bs); |
|
573 |
// Point2D[] points = new Point2D[pts.size()]; |
|
574 |
// for (int j=0;j<pts.size();j++) { |
|
575 |
// points[j] = (Point2D)pts.get(j); |
|
576 |
// } |
|
577 |
// ((DwgPolyline2D)pol).setPts(points); |
|
578 |
// } else { |
|
579 |
//// System.out.println("Encontrada polil�nea sin puntos ..."); |
|
580 |
// // TODO: No se debe mandar nunca una polil�nea sin puntos, si esto |
|
581 |
// // ocurre es porque existe un error que hay que corregir ... |
|
582 |
// } |
|
583 |
// } else if (pol instanceof DwgPolyline3D) { |
|
584 |
// } else if (pol instanceof DwgLwPolyline && ((DwgLwPolyline)pol).getVertices()!=null) { |
|
585 |
// } |
|
586 |
// } |
|
587 |
// } |
|
588 |
|
|
589 |
/* |
|
590 |
* TODO Revisar los bloques que son XREF |
|
591 |
* */ |
|
592 |
public void blockManagement2(){ |
|
593 |
Iterator it = null; |
|
594 |
|
|
595 |
|
|
596 |
//dwg v12 blocks already has their entities added |
|
597 |
//for the rest of versions, we add block entities to their owner block |
|
598 |
if(! (dwgReader instanceof DwgFileV12Reader)){ |
|
599 |
//once we have read all dwg entities, we look for all of them |
|
600 |
//that has a superentity that is a block (to fill in the entity list |
|
601 |
//of each block |
|
602 |
it = dwgObjects.iterator(); |
|
603 |
int i = 0; |
|
604 |
while(it.hasNext()){ |
|
605 |
DwgObject entity = (DwgObject)it.next(); |
|
606 |
DwgObject superEnt = getDwgSuperEntity(entity); |
|
607 |
if(superEnt instanceof DwgBlockHeader){ |
|
608 |
DwgBlockHeader blk = (DwgBlockHeader)superEnt; |
|
609 |
blk.addObject(entity); |
|
610 |
it.remove();//TODO Creo que esto es lento, mejor |
|
611 |
//el metodo original (en java solo se duplican las referencias) |
|
612 |
i++; |
|
613 |
} |
|
614 |
}//while |
|
615 |
}//if dwgfilev12 |
|
616 |
|
|
617 |
//after that, we process the INSERTs |
|
618 |
it = insertList.iterator(); |
|
619 |
while(it.hasNext()){ |
|
620 |
DwgInsert insert = (DwgInsert) it.next(); |
|
621 |
if(insert.isProcessed()){ |
|
622 |
//It has been processed nexted to other insert |
|
623 |
continue; |
|
624 |
} |
|
625 |
insert.setProcessed(true); |
|
626 |
double[] p = insert.getInsertionPoint(); |
|
627 |
Point2D point = new Point2D.Double(p[0], p[1]); |
|
628 |
double[] scale = insert.getScale(); |
|
629 |
double rot = insert.getRotation(); |
|
630 |
int blockHandle = insert.getBlockHeaderHandle().getOffset(); |
|
631 |
manageInsert2(point, scale, |
Also available in: Unified diff