Revision 34143

View differences:

branches/v2_0_0_prep/extensions/org.gvsig.geometrymeasurement.app/prepare-workspace.xml
1
<project name="org.gvsig.initial.build" default="prepare-workspace">
2

  
3
	<dirname property="org.gvsig.initial.build.basedir" file="${ant.file.org.gvsig.initial.build}" />
4

  
5
	<property name="workspace.basedir" value="${org.gvsig.initial.build.basedir}/.." />
6
	<property name="build.basedir" value="${workspace.basedir}/org.gvsig.maven.base.build" description="Eclipse workspace location" />
7
	<property name="build.jar.version" value="1.0.6-SNAPSHOT" />
8
	<property name="build.jar.file" value="org.gvsig.maven.base.build-${build.jar.version}.jar" />
9

  
10
	<property name="ant.libs.dir" location="${build.basedir}" description="Additional ant tasks libs folder" />
11

  
12
	<target name="check-maven-base-build-available">
13
		<available file="${user.home}/.m2/repository/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}" property="maven-base-build-available" />
14
	</target>
15

  
16
	<target name="get-maven-base-build-local" depends="check-maven-base-build-available" if="maven-base-build-available">
17
		<!-- Unzip de build jar file from the maven repository into the workspace root folder -->
18
		<copy todir="${workspace.basedir}" preservelastmodified="false" filtering="false">
19
			<zipfileset src="${user.home}/.m2/repository/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}">
20
				<patternset>
21
					<exclude name="META-INF/**" />
22
				</patternset>
23
			</zipfileset>
24
		</copy>
25
	</target>
26

  
27
	<target name="get-maven-base-build-remote" depends="check-maven-base-build-available" unless="maven-base-build-available">
28
		<!-- Download the build jar file -->
29
		<get src="http://gvsig-desktop.forge.osor.eu/downloads/pub/projects/gvSIG-desktop/maven-repository/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}" dest="target/${build.jar.file}" verbose="true" />
30

  
31
		<mkdir dir="target" />
32

  
33
		<!-- Unzip de build jar file into the workspace root folder -->
34
		<copy todir="${workspace.basedir}" preservelastmodified="false" filtering="false">
35
			<zipfileset src="target/${build.jar.file}">
36
				<patternset>
37
					<exclude name="META-INF/**" />
38
				</patternset>
39
			</zipfileset>
40
			<filterset>
41
				<filter token="GVSIG_HOME" value="/home/cordin/projects/gvsig/svn/gvSIG-2.0-build/build/product" />
42
			</filterset>
43
		</copy>
44

  
45
	</target>
46

  
47
	<target name="prepare-workspace" depends="get-maven-base-build-local,get-maven-base-build-remote">
48

  
49
		<mkdir dir="target" />
50

  
51
		<chmod dir="${build.basedir}/maven/bin" perm="u+x" includes="m2,mvn,mvnDebug" />
52

  
53
		<!-- Copy the maven launchers to the workspace metadata folder -->
54
		<copy todir="${workspace.basedir}/.metadata">
55
			<fileset dir="${build.basedir}/eclipse-launchers">
56
				<exclude name="**/org.eclipse.jdt.core.prefs" />
57
				<exclude name="**/org.eclipse.core.variables.prefs" />
58
			</fileset>
59
		</copy>
60

  
61
		<concat destfile="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs" append="true">
62
			<filelist dir="${build.basedir}/eclipse-launchers/.plugins/org.eclipse.core.runtime/.settings" files="org.eclipse.jdt.core.prefs" />
63
		</concat>
64
		<concat destfile="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.variables.prefs" append="true">
65
			<filelist dir="${build.basedir}/eclipse-launchers/.plugins/org.eclipse.core.runtime/.settings" files="org.eclipse.core.variables.prefs" />
66
		</concat>
67

  
68
		<!-- Configure the eclipse workspace -->
69
		<ant antfile="${build.basedir}/maven-goals.xml" target="mvn-configure-eclipse-workspace" />
70

  
71
		<!-- Configure the gvSIG profile -->
72
		<ant antfile="${build.basedir}/check-gvsig-profile.xml" target="initialize" />
73

  
74
		<property name="user-settings-file-location" value="${user.home}/.m2/settings.xml" />
75

  
76
		<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask">
77
			<classpath>
78
				<pathelement location="${ant.libs.dir}/com.oopsconsultancy.xmltask-1.16.1.jar" />
79
			</classpath>
80
		</taskdef>
81

  
82
		<xmltask source="${user-settings-file-location}" dest="${user-settings-file-location}">
83
			<copy path="//:settings/:profiles/:profile[:id/text() = 'gvsig-install']/:properties/:gvsig.install.dir/text()" property="current-gvsig-location" />
84
		</xmltask>
85

  
86
		<replace file="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs" token="@GVSIG_HOME@" value="${current-gvsig-location}" />
87
		<replace file="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.variables.prefs" token="@GVSIG_HOME@" value="${current-gvsig-location}" />
88

  
89
		<!-- Compile, install and generate eclipse projects -->
90
		<ant antfile="${build.basedir}/maven-goals.xml" target="mvn-install-and-eclipse-eclipse" />
91

  
92
		<echo>INFORMATION!!!</echo>
93
		<echo>Restart eclipse and then proceed to import the subprojects contained into the main project</echo>
94

  
95
		<!-- TODO: copiar al proyecto de configuraciĆ³n general -->
96
	</target>
97

  
98
	<target name="clean">
99
		<delete dir="target" />
100
	</target>
101

  
102
</project>
0 103

  
branches/v2_0_0_prep/extensions/org.gvsig.geometrymeasurement.app/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
	<modelVersion>4.0.0</modelVersion>
6
	<groupId>org.gvsig</groupId>
7
	<artifactId>org.gvsig.geometrymeasurement.app</artifactId>
8
	<packaging>pom</packaging>
9
	<version>1.0.0-SNAPSHOT</version>
10
	<name>org.gvsig.geometrymeasurement.app</name>
11
	<description>Extension of the GeometryMeasurement example project</description>
12
	<url>http://gvsig-desktop.forge.osor.eu/downloads/pub/projects/gvSIG-desktop/docs/reference/org.gvsig.geometrymeasurement/${pom.version}/basic/org.gvsig.geometrymeasurement.app</url>
13
	<parent>
14
		<groupId>org.gvsig</groupId>
15
		<artifactId>org.gvsig.maven.base.extension.pom</artifactId>
16
		<version>1.0.6-SNAPSHOT</version>
17
	</parent>
18

  
19
	<scm>
20
		<connection>scm:svn:https://svn.forge.osor.eu/svn/gvsig-geometrymeasurement/org.gvsig.geometrymeasurement/extension/trunk</connection>
21
		<developerConnection>scm:svn:https://svn.forge.osor.eu/svn/gvsig-geometrymeasurement/org.gvsig.geometrymeasurement/extension/trunk</developerConnection>
22
		<url>https://forge.osor.eu/plugins/scmsvn/viewcvs.php/org.gvsig.geometrymeasurement/extension/trunk/?root=gvsig-geometrymeasurement</url>
23
	</scm>
24

  
25
	<developers>
26
		<developer>
27
			<id>vcaballero</id>
28
			<name>Vicente Caballero Navarro</name>
29
			<email>vicente.caballero@iver.es</email>
30
			<roles>				
31
				<role>Developer</role>
32
			</roles>
33
		</developer>
34
		<developer>
35
			<id>jpiera</id>
36
			<name>Jorge Piera Llodr?</name>
37
			<email>jpiera@gvsig.org</email>
38
			<roles>
39
				<role>Developer</role>
40
			</roles>
41
		</developer>		
42
	</developers>
43

  
44
	<distributionManagement>
45
		<site>
46
			<id>gvsig-repository</id>
47
			<url>scp://shell.forge.osor.eu/home/groups/gvsig-desktop/www/downloads/pub/projects/gvSIG-desktop/docs/reference/org.gvsig.geometrymeasurement/${pom.version}/basic/org.gvsig.geometrymeasurement.app</url>
48
		</site>
49
	</distributionManagement>
50
	<repositories>
51
		<repository>
52
			<id>gvsig-public-http-repository</id>
53
			<name>gvSIG maven public HTTP repository</name>
54
			<url>http://gvsig-desktop.forge.osor.eu/downloads/pub/projects/gvSIG-desktop/maven-repository</url>
55
			<releases>
56
				<enabled>true</enabled>
57
				<updatePolicy>daily</updatePolicy>
58
				<checksumPolicy>warn</checksumPolicy>
59
			</releases>
60
			<snapshots>
61
				<enabled>true</enabled>
62
				<updatePolicy>daily</updatePolicy>
63
				<checksumPolicy>warn</checksumPolicy>
64
			</snapshots>
65
		</repository>
66
	</repositories>
67
	<build>
68
		<plugins>
69
			<plugin>
70
				<groupId>org.apache.maven.plugins</groupId>
71
				<artifactId>maven-release-plugin</artifactId>
72
				<configuration>
73
					<tagBase>https://svn.forge.osor.eu/svn/gvsig-geometrymeasurement/org.gvsig.geometrymeasurement/extension/tags</tagBase>
74
				</configuration>
75
			</plugin>
76
		</plugins>
77
	</build>
78
	<dependencyManagement>
79
		<dependencies>
80
			<dependency>
81
				<groupId>org.gvsig</groupId>
82
				<artifactId>org.gvsig.andami</artifactId>
83
				<version>2.0-SNAPSHOT</version>
84
			</dependency>
85
			<dependency>
86
				<groupId>org.gvsig</groupId>
87
				<artifactId>org.gvsig.i18n</artifactId>
88
				<version>2.0-SNAPSHOT</version>
89
			</dependency>
90
			<dependency>
91
				<groupId>org.gvsig</groupId>
92
				<artifactId>org.gvsig.tools.lib</artifactId>
93
				<version>2.1.0-SNAPSHOT</version>
94
			</dependency>			
95
		</dependencies>
96
	</dependencyManagement>
97

  
98
	<modules>
99
		<module>org.gvsig.geometrymeasurement.app.extension</module>
100
	</modules>
101

  
102
</project>
0 103

  
branches/v2_0_0_prep/extensions/org.gvsig.geometrymeasurement.app/README.txt
1
The first time you checkout the current project to a new workspace, 
2
you have to prepare it to be able to work easily with maven from
3
eclipse itself.
4

  
5
Perform the following steps:
6

  
7
1.- Launch the *prepare-workspace.xml* ant build file. 
8
    You can do it by loading the file into the ant view, 
9
    and running the default task, or right-clicking the 
10
    file from the package explorer or the navigator and
11
    select the option: *Run as > Ant build*. 
12
    
13
2.- Restart eclipse.
14

  
15
3.- Import the subprojects of the project you have just checked out.
16

  
17
Those steps are only needed once per workspace.     
18

  
0 19

  
branches/v2_0_0_prep/extensions/org.gvsig.geometrymeasurement.app/distribution/distribution.xml
1
<assembly>
2
</assembly>
0 3

  
branches/v2_0_0_prep/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5
	<modelVersion>4.0.0</modelVersion>
6
	<artifactId>org.gvsig.geometrymeasurement.app.extension</artifactId>
7
	<packaging>jar</packaging>
8
	<name>org.gvsig.geometrymeasurement.app.extension</name>
9
	<parent>
10
		<groupId>org.gvsig</groupId>
11
		<artifactId>org.gvsig.geometrymeasurement.app</artifactId>
12
		<version>1.0.0-SNAPSHOT</version>
13
	</parent>
14

  
15
	<dependencies>
16
		<dependency>
17
			<groupId>org.gvsig</groupId>
18
			<artifactId>org.gvsig.andami</artifactId>
19
		</dependency>
20
		<dependency>
21
           <groupId>org.gvsig</groupId>
22
            <artifactId>org.gvsig.app</artifactId>
23
            <version>2.0-SNAPSHOT</version>
24
        </dependency>
25
		<dependency>
26
			<groupId>org.gvsig</groupId>
27
			<artifactId>org.gvsig.i18n</artifactId>
28
		</dependency>
29
		<dependency>
30
			<groupId>org.gvsig</groupId>
31
			<artifactId>org.gvsig.tools.lib</artifactId>
32
		</dependency>	
33
	</dependencies>
34
	<profiles>
35
		<profile>
36
			<id>gvsig-install</id>
37
			<activation>
38
				<activeByDefault>true</activeByDefault>
39
			</activation>
40
			<properties>
41
				<!--
42
					Default gvSIG installation folder relative to the current workspace
43
				-->
44
				<gvsig.install.dir>${basedir}/../../build/product</gvsig.install.dir>
45
			</properties>
46
		</profile>
47
	</profiles>
48
</project>
0 49

  
branches/v2_0_0_prep/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/distribution/distribution.xml
1
<assembly>
2
	<id>distribution</id>
3
	<formats>
4
		<format>dir</format>
5
	</formats>
6
	<fileSets>
7
		<!-- Estructure for the extension -->
8
		<fileSet>
9
			<directory>src/main/resources</directory>
10
			<outputDirectory>${extension.install.dir.name}
11
			</outputDirectory>
12
		</fileSet>
13
	</fileSets>
14
	<dependencySets>
15
		<dependencySet>
16
			<outputDirectory>${extension.install.dir.name}/${library-dir}
17
			</outputDirectory>
18
			<includes>
19
				<include>org.gvsig:org.gvsig.geometrymeasurement.app.extension</include>
20
				<include>org.gvsig:org.gvsig.geometrymeasurement.lib.api</include>
21
				<include>org.gvsig:org.gvsig.geometrymeasurement.lib.impl</include>
22
			</includes>
23
		</dependencySet>
24
	</dependencySets>
25
</assembly>
0 26

  
branches/v2_0_0_prep/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/test/resources/README.txt
1
Put into this folder the resources needed by your test classes.
2

  
3
This folder is added to the Tests classpath, so you can load any resources 
4
through the ClassLoader.
5

  
6
By default, in this folder you can find an example of log4j configuration,
7
prepared to log messages through the console, so logging works when you
8
run your tests classes.
0 9

  
branches/v2_0_0_prep/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/test/resources/log4j.xml
1
<?xml version="1.0" encoding="ISO-8859-1" ?>
2
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
3

  
4
<!-- 
5
Log4J configuration file for unit tests execution.
6
 -->
7
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
8

  
9
	<!-- Appender configuration to show logging messages through the console -->
10
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
11
		<layout class="org.apache.log4j.PatternLayout">
12
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n  %m%n" />
13
		</layout>
14
	</appender>
15

  
16
	<!-- 
17
	Activate logging messages of DEBUG level of higher only for the
18
	org.gvsig.tools packages.
19
	You can put full classes names or packages instead, to configure
20
	logging for all the classes and subpackages of the package.
21
	-->
22
	<category name="org.gvsig.tools">
23
		<priority value="DEBUG" />
24
	</category>
25
	<category name="org.gvsig.geometrymeasurement">
26
		<priority value="DEBUG" />
27
	</category>
28

  
29
	<!-- 
30
	By default, show only logging messages of INFO level or higher, 
31
	through the previously configured CONSOLE appender. 
32
	-->
33
	<root>
34
		<priority value="INFO" />
35
		<appender-ref ref="CONSOLE" />
36
	</root>
37
</log4j:configuration>
0 38

  
branches/v2_0_0_prep/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/main/java/org/gvsig/geometrymeasurement/app/extension/AreaMeasurementExtension.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.geometrymeasurement.app.extension;
23

  
24
import org.slf4j.Logger;
25
import org.slf4j.LoggerFactory;
26

  
27
import org.gvsig.andami.PluginServices;
28
import org.gvsig.andami.messages.NotificationManager;
29
import org.gvsig.andami.plugins.Extension;
30
import org.gvsig.andami.ui.mdiManager.IWindow;
31
import org.gvsig.app.project.documents.view.gui.IView;
32
import org.gvsig.fmap.dal.exception.DataException;
33
import org.gvsig.fmap.dal.exception.ReadException;
34
import org.gvsig.fmap.dal.feature.FeatureStore;
35
import org.gvsig.fmap.geom.Geometry;
36
import org.gvsig.fmap.geom.operation.GeometryOperationException;
37
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
38
import org.gvsig.fmap.mapcontext.MapContext;
39
import org.gvsig.fmap.mapcontext.layers.FLayer;
40
import org.gvsig.fmap.mapcontext.layers.FLayers;
41
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
42
import org.gvsig.geometrymeasurement.app.extension.utils.Operations;
43

  
44
/**
45
 * Andami extension to show AreaMeasurementExtension in the application.
46
 * 
47
 * @author gvSIG Team
48
 * @version $Id$
49
 */
50
public class AreaMeasurementExtension extends Extension {
51
    private static final Logger LOG = LoggerFactory.getLogger(AreaMeasurementExtension.class);
52
    private MapContext mapContext;
53
    private FLyrVect fLyrVect;
54

  
55
    public void initialize() {
56
        // Do nothing
57
    }
58

  
59
    @Override
60
    public void postInitialize() {
61
        super.postInitialize();      
62
    }
63

  
64
    public void execute(String actionCommand) {       
65
        Operations operations = new Operations();
66
        FeatureStore featureStore = fLyrVect.getFeatureStore();
67
        
68
        try {
69
            operations.addDoubleFieldFromOperation(featureStore, "AREA", "area");
70
        } catch (DataException e) {
71
           LOG.error("Not possible to create the area field", e);
72
           NotificationManager.addError(e);
73
        } catch (GeometryOperationNotSupportedException e) {
74
            LOG.error("Not possible to create the area field", e);
75
            NotificationManager.addError(e);
76
        } catch (GeometryOperationException e) {
77
            LOG.error("Not possible to create the area field", e);
78
            NotificationManager.addError(e);
79
        }  
80
    }  
81

  
82
    public boolean isEnabled() {
83
        return true;
84
    }
85

  
86
    public boolean isVisible() {
87
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
88

  
89
        if (window == null){
90
            return false;
91
        }
92
        if (window instanceof IView){
93
            IView view = (IView) window;            
94
            FLayers layers = view.getMapControl().getMapContext().getLayers();
95
            FLayer[] activeLayers = layers.getActives();
96

  
97
            if (activeLayers.length == 1){
98
                if (activeLayers[0] instanceof FLyrVect){
99
                    fLyrVect = (FLyrVect) activeLayers[0];
100
                    try {
101
                        int type = fLyrVect.getShapeType();
102
                        if (Geometry.TYPES.CIRCLE == type
103
                            || Geometry.TYPES.ELLIPSE == type
104
                            || Geometry.TYPES.SURFACE == type
105
                            || Geometry.TYPES.MULTISURFACE == type){
106
                            return true;
107
                        }
108
                    } catch (ReadException e) {
109
                        LOG.error("Error reading the geometry type", e);
110
                        return false;
111
                    }
112
                }
113
            }
114
        }
115
        return false;
116
    }
117

  
118
}
0 119

  
branches/v2_0_0_prep/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/main/java/org/gvsig/geometrymeasurement/app/extension/PerimeterMeasurementExtension.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.geometrymeasurement.app.extension;
23

  
24
import org.slf4j.Logger;
25
import org.slf4j.LoggerFactory;
26

  
27
import org.gvsig.andami.PluginServices;
28
import org.gvsig.andami.messages.NotificationManager;
29
import org.gvsig.andami.plugins.Extension;
30
import org.gvsig.andami.ui.mdiManager.IWindow;
31
import org.gvsig.app.project.documents.view.gui.IView;
32
import org.gvsig.fmap.dal.exception.DataException;
33
import org.gvsig.fmap.dal.exception.ReadException;
34
import org.gvsig.fmap.dal.feature.FeatureStore;
35
import org.gvsig.fmap.geom.Geometry;
36
import org.gvsig.fmap.geom.operation.GeometryOperationException;
37
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
38
import org.gvsig.fmap.mapcontext.layers.FLayer;
39
import org.gvsig.fmap.mapcontext.layers.FLayers;
40
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
41
import org.gvsig.geometrymeasurement.app.extension.utils.Operations;
42

  
43
/**
44
 * Andami extension to show PerimeterMeasurementExtension in the application.
45
 * 
46
 * @author gvSIG Team
47
 * @version $Id$
48
 */
49
public class PerimeterMeasurementExtension extends Extension {
50
    private static final Logger LOG = LoggerFactory.getLogger(AreaMeasurementExtension.class);
51
    private FLyrVect fLyrVect;
52

  
53
    public void initialize() {
54
        // Do nothing
55
    }
56

  
57
    @Override
58
    public void postInitialize() {
59
        super.postInitialize();       
60
    }
61

  
62
    public void execute(String actionCommand) {        
63
        Operations operations = new Operations();
64
        FeatureStore featureStore = fLyrVect.getFeatureStore();
65
        
66
        try {
67
            operations.addDoubleFieldFromOperation(featureStore, "PERIMETER", "perimeter");
68
        } catch (DataException e) {
69
           LOG.error("Not possible to create the perimeter field", e);
70
           NotificationManager.addError(e);
71
        } catch (GeometryOperationNotSupportedException e) {
72
            LOG.error("Not possible to create the perimeter field", e);
73
            NotificationManager.addError(e);
74
        } catch (GeometryOperationException e) {
75
            LOG.error("Not possible to create the perimeter field", e);
76
            NotificationManager.addError(e);
77
        }  
78
    }
79

  
80
    public boolean isEnabled() {
81
        return true;
82
    }
83

  
84
    public boolean isVisible() {
85
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
86

  
87
        if (window == null){
88
            return false;
89
        }
90
        if (window instanceof IView){
91
            IView view = (IView) window;
92
            FLayers layers = view.getMapControl().getMapContext().getLayers();
93
            FLayer[] activeLayers = layers.getActives();
94

  
95
            if (activeLayers.length == 1){
96
                if (activeLayers[0] instanceof FLyrVect){
97
                    fLyrVect = (FLyrVect) activeLayers[0];
98
                    try {
99
                        int type = fLyrVect.getShapeType();
100
                        if (Geometry.TYPES.POINT != type){                           
101
                            return true;
102
                        }
103
                    } catch (ReadException e) {
104
                        LOG.error("Error reading the geometry type", e);
105
                        return false;
106
                    }
107
                }
108
            }
109
        }
110
        return false;
111
    }
112

  
113
}
0 114

  
branches/v2_0_0_prep/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/main/java/org/gvsig/geometrymeasurement/app/extension/utils/Operations.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.geometrymeasurement.app.extension.utils;
23

  
24
import java.util.Iterator;
25

  
26
import org.gvsig.fmap.dal.exception.DataException;
27
import org.gvsig.fmap.dal.feature.EditableFeature;
28
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
29
import org.gvsig.fmap.dal.feature.EditableFeatureType;
30
import org.gvsig.fmap.dal.feature.Feature;
31
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
32
import org.gvsig.fmap.dal.feature.FeatureSet;
33
import org.gvsig.fmap.dal.feature.FeatureStore;
34
import org.gvsig.fmap.dal.feature.FeatureType;
35
import org.gvsig.fmap.geom.operation.GeometryOperationException;
36
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
37
import org.gvsig.fmap.geom.primitive.Point;
38
import org.gvsig.tools.dataTypes.DataTypes;
39
import org.gvsig.tools.dispose.DisposableIterator;
40

  
41
/**
42
 * Andami extension to show PerimeterMeasurementExtension in the application.
43
 * 
44
 * @author gvSIG Team
45
 * @version $Id$
46
 */
47
public class Operations {
48
    private static final int NUM_DECIMALS = 5;
49

  
50
    public void addDoubleFieldFromOperation(FeatureStore featureStore, String fieldName, String operationName) throws DataException, GeometryOperationNotSupportedException, GeometryOperationException{
51
        boolean isEditing = false;
52
        if (featureStore.isEditing()){
53
            isEditing = true;
54
        }else{
55
            featureStore.edit();
56
        }        
57

  
58
        //Adding the new attribute type
59
        FeatureType featureType = featureStore.getDefaultFeatureType();
60
        EditableFeatureType editableFeatureType = featureType.getEditable();
61

  
62
        String realFieldName = getFieldName(featureStore, fieldName, 0);
63
        EditableFeatureAttributeDescriptor editableFeatureAttributeDescriptor = 
64
            editableFeatureType.add(realFieldName, DataTypes.DOUBLE);
65
        editableFeatureAttributeDescriptor.setPrecision(NUM_DECIMALS);
66
        editableFeatureAttributeDescriptor.setSize(Integer.MAX_VALUE);
67

  
68
        featureStore.update(editableFeatureType);        
69

  
70
        //Adding the attribute value
71
        FeatureSet featureSet = featureStore.getFeatureSet();
72
        DisposableIterator disposableIterator = featureSet.iterator();
73
        while (disposableIterator.hasNext()){
74
            Feature feature = (Feature)disposableIterator.next();
75
            EditableFeature editableFeature = feature.getEditable();        
76
            editableFeature.setDouble(realFieldName, (Double)feature.getDefaultGeometry().invokeOperation(operationName, null));
77
            featureSet.update(editableFeature);
78
        }    
79

  
80
        featureSet.dispose();            
81

  
82
        if (!isEditing){
83
            featureStore.finishEditing();             
84
        }        
85
    }
86

  
87
    public String getFieldName(FeatureStore featureStore, String fieldName, int index) throws DataException{
88
        String fullName = fieldName;
89
        if (index != 0){
90
            fullName = fullName + index;
91
        }
92
        Iterator it = featureStore.getDefaultFeatureType().iterator();        
93
        while (it.hasNext()){
94
            FeatureAttributeDescriptor featureAttributeDescriptor = (FeatureAttributeDescriptor)it.next();
95
            if (featureAttributeDescriptor.getName().equals(fullName)){
96
                return getFieldName(featureStore, fieldName, index+1);
97
            }
98
        }    
99
        return fullName;
100
    }
101

  
102
    /**
103
     * @param featureStore
104
     * @param string
105
     * @param string2
106
     * @throws DataException 
107
     */
108
    public void addXYPoints(FeatureStore featureStore, String xFieldName,
109
        String yFieldName) throws DataException {
110
        boolean isEditing = false;
111
        if (featureStore.isEditing()){
112
            isEditing = true;
113
        }else{
114
            featureStore.edit();
115
        }        
116

  
117
        //Adding the new attribute type
118
        FeatureType featureType = featureStore.getDefaultFeatureType();
119
        EditableFeatureType editableFeatureType = featureType.getEditable();
120

  
121
        String realXFieldName = getFieldName(featureStore, xFieldName, 0);
122
        EditableFeatureAttributeDescriptor editableFeatureAttributeDescriptor = 
123
            editableFeatureType.add(realXFieldName, DataTypes.DOUBLE);
124
        editableFeatureAttributeDescriptor.setPrecision(NUM_DECIMALS);
125
        editableFeatureAttributeDescriptor.setSize(Integer.MAX_VALUE);
126
        
127
        String realYFieldName = getFieldName(featureStore, yFieldName, 0);
128
        editableFeatureAttributeDescriptor = editableFeatureType.add(realYFieldName, DataTypes.DOUBLE);
129
        editableFeatureAttributeDescriptor.setPrecision(NUM_DECIMALS);
130
        editableFeatureAttributeDescriptor.setSize(Integer.MAX_VALUE);
131

  
132
        featureStore.update(editableFeatureType);        
133

  
134
        //Adding the attribute value
135
        FeatureSet featureSet = featureStore.getFeatureSet();
136
        DisposableIterator disposableIterator = featureSet.iterator();
137
        while (disposableIterator.hasNext()){
138
            Feature feature = (Feature)disposableIterator.next();
139
            EditableFeature editableFeature = feature.getEditable();        
140
            editableFeature.setDouble(realXFieldName, ((Point)feature.getDefaultGeometry()).getX());
141
            editableFeature.setDouble(realYFieldName, ((Point)feature.getDefaultGeometry()).getY());
142
            featureSet.update(editableFeature);
143
        }    
144

  
145
        featureSet.dispose();            
146

  
147
        if (!isEditing){
148
            featureStore.finishEditing();             
149
        }        
150

  
151
    }
152

  
153

  
154
}
0 155

  
branches/v2_0_0_prep/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/main/java/org/gvsig/geometrymeasurement/app/extension/AddXYPointThemeExtension.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.geometrymeasurement.app.extension;
23

  
24
import org.slf4j.Logger;
25
import org.slf4j.LoggerFactory;
26

  
27
import org.gvsig.andami.PluginServices;
28
import org.gvsig.andami.messages.NotificationManager;
29
import org.gvsig.andami.plugins.Extension;
30
import org.gvsig.andami.ui.mdiManager.IWindow;
31
import org.gvsig.app.project.documents.view.gui.IView;
32
import org.gvsig.fmap.dal.exception.DataException;
33
import org.gvsig.fmap.dal.exception.ReadException;
34
import org.gvsig.fmap.dal.feature.FeatureStore;
35
import org.gvsig.fmap.geom.Geometry;
36
import org.gvsig.fmap.mapcontext.layers.FLayer;
37
import org.gvsig.fmap.mapcontext.layers.FLayers;
38
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
39
import org.gvsig.geometrymeasurement.app.extension.utils.Operations;
40

  
41
/**
42
 * Andami extension to show PerimeterMeasurementExtension in the application.
43
 * 
44
 * @author gvSIG Team
45
 * @version $Id$
46
 */
47
public class AddXYPointThemeExtension extends Extension {
48
    private static final Logger LOG = LoggerFactory.getLogger(AreaMeasurementExtension.class);
49
    private FLyrVect fLyrVect;  
50

  
51
    public void initialize() {
52
        // Do nothing
53
    }
54

  
55
    @Override
56
    public void postInitialize() {
57
        super.postInitialize();       
58
    }
59

  
60
    public void execute(String actionCommand) {
61
        Operations operations = new Operations();
62
        FeatureStore featureStore = fLyrVect.getFeatureStore();
63
        
64
        try {
65
            operations.addXYPoints(featureStore, "X", "Y");
66
        } catch (DataException e) {
67
           LOG.error("Not possible to create the X and Y fields", e);
68
           NotificationManager.addError(e);
69
        }    
70
    }
71
   
72
    public boolean isEnabled() {
73
        return true;
74
    }
75

  
76
    public boolean isVisible() {
77
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
78

  
79
        if (window == null){
80
            return false;
81
        }
82
        if (window instanceof IView){
83
            IView view = (IView) window;
84
            FLayers layers = view.getMapControl().getMapContext().getLayers();
85
            FLayer[] activeLayers = layers.getActives();
86

  
87
            if (activeLayers.length == 1){
88
                if (activeLayers[0] instanceof FLyrVect){
89
                    fLyrVect = (FLyrVect) activeLayers[0];
90
                    try {
91
                        int type = fLyrVect.getShapeType();
92
                        if (Geometry.TYPES.POINT == type){                           
93
                            return true;
94
                        }
95
                    } catch (ReadException e) {
96
                        LOG.error("Error reading the geometry type", e);
97
                        return false;
98
                    }
99
                }
100
            }
101
        }
102
        return false;
103
    }
104

  
105
}
0 106

  
branches/v2_0_0_prep/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/main/resources/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<plugin-config>
3
	<depends plugin-name="org.gvsig.app" />
4
	<resourceBundle name="text"/>
5
	<libraries library-dir="lib"/>
6
	<extensions>
7
		<extension class-name="org.gvsig.geometrymeasurement.app.extension.AreaMeasurementExtension"
8
			description="Extension that measures the area of all the polygonos they selected."
9
            active="true">
10
            <menu text="Vista/area" tooltip="area"
11
                action-command="AREA"
12
                icon="images/area.png" />
13
            <tool-bar name="area">
14
                <action-tool icon="images/area.png"
15
                    action-command="AREA" tooltip="area"
16
                    enable-text="deber?a de estar activada" last="true"/>
17
            </tool-bar>
18
		</extension>	
19
		<extension class-name="org.gvsig.geometrymeasurement.app.extension.PerimeterMeasurementExtension"
20
           description="Extension that measures the perimeter of all the lines they selected."
21
            active="true">
22
            <menu text="Vista/perimeter" tooltip="perimeter"
23
                action-command="PERIMETER"
24
                icon="images/perimeter.png" />
25
            <tool-bar name="perimeter">
26
                <action-tool icon="images/perimeter.png"
27
                    action-command="PERIMETER" tooltip="perimeter"
28
                    enable-text="deber?a de estar activada" last="true"/>
29
            </tool-bar>
30
        </extension>
31
        <extension class-name="org.gvsig.geometrymeasurement.app.extension.AddXYPointThemeExtension"
32
            description="Extension that add the coordinates x and y."
33
            active="true">
34
            <menu text="Vista/add_x_y" tooltip="add_x_y"
35
                action-command="ADDXYPOINT"
36
                icon="images/xypoint.png" />
37
            <tool-bar name="add_x_y">
38
                <action-tool icon="images/xypoint.png"
39
                    action-command="ADDXYPOINT" tooltip="add_x_y"
40
                    enable-text="deber?a de estar activada" last="true"/>
41
            </tool-bar>
42
        </extension>    	
43
	</extensions>
44
</plugin-config>
0 45

  
branches/v2_0_0_prep/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/main/resources/build.number
1
#Build Number for ANT. Do not edit!
2
#Tue Apr 28 16:00:47 CEST 2009
3
build.number=2005
0 4

  

Also available in: Unified diff