Revision 2147
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.124/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/src/test/resources/README.txt | ||
---|---|---|
1 |
==== |
|
2 |
gvSIG. Desktop Geographic Information System. |
|
3 |
|
|
4 |
Copyright (C) 2007-2012 gvSIG Association. |
|
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 |
For any additional information, do not hesitate to contact us |
|
22 |
at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
==== |
|
24 |
|
|
25 |
Put into this folder the resources needed by your test classes. |
|
26 |
|
|
27 |
This folder is added to the Tests classpath, so you can load any resources |
|
28 |
through the ClassLoader. |
|
29 |
|
|
30 |
By default, in this folder you can find an example of log4j configuration, |
|
31 |
prepared to log messages through the console, so logging works when you |
|
32 |
run your tests classes. |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.124/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/src/test/resources/log4j.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1" ?> |
|
2 |
<!-- |
|
3 |
|
|
4 |
gvSIG. Desktop Geographic Information System. |
|
5 |
|
|
6 |
Copyright (C) 2007-2012 gvSIG Association. |
|
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., 51 Franklin Street, Fifth Floor, Boston, |
|
21 |
MA 02110-1301, USA. |
|
22 |
|
|
23 |
For any additional information, do not hesitate to contact us |
|
24 |
at info AT gvsig.com, or visit our website www.gvsig.com. |
|
25 |
|
|
26 |
--> |
|
27 |
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> |
|
28 |
|
|
29 |
<!-- |
|
30 |
Log4J configuration file for unit tests execution. |
|
31 |
--> |
|
32 |
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> |
|
33 |
|
|
34 |
<!-- Appender configuration to show logging messages through the console --> |
|
35 |
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> |
|
36 |
<layout class="org.apache.log4j.PatternLayout"> |
|
37 |
<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n %m%n" /> |
|
38 |
</layout> |
|
39 |
</appender> |
|
40 |
|
|
41 |
<!-- |
|
42 |
Activate logging messages of DEBUG level of higher only for the |
|
43 |
org.gvsig.tools packages. |
|
44 |
You can put full classes names or packages instead, to configure |
|
45 |
logging for all the classes and subpackages of the package. |
|
46 |
--> |
|
47 |
<category name="org.gvsig.tools"> |
|
48 |
<priority value="DEBUG" /> |
|
49 |
</category> |
|
50 |
<category name="org.gvsig.vectorediting"> |
|
51 |
<priority value="DEBUG" /> |
|
52 |
</category> |
|
53 |
|
|
54 |
<!-- |
|
55 |
By default, show only logging messages of INFO level or higher, |
|
56 |
through the previously configured CONSOLE appender. |
|
57 |
--> |
|
58 |
<root> |
|
59 |
<priority value="INFO" /> |
|
60 |
<appender-ref ref="CONSOLE" /> |
|
61 |
</root> |
|
62 |
</log4j:configuration> |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.124/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.vectorediting.lib.impl.DefaultEditingLibrary |
|
2 |
org.gvsig.vectorediting.lib.impl.DefaultEditingProviderLibrary |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.124/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/src/main/java/org/gvsig/vectorediting/lib/impl/DefaultEditingService.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2014 gvSIG Association |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
|
|
25 |
package org.gvsig.vectorediting.lib.impl; |
|
26 |
|
|
27 |
import java.util.List; |
|
28 |
|
|
29 |
import org.gvsig.fmap.geom.Geometry; |
|
30 |
import org.gvsig.fmap.geom.primitive.Point; |
|
31 |
import org.gvsig.tools.service.Manager; |
|
32 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
|
33 |
import org.gvsig.vectorediting.lib.api.EditingService; |
|
34 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
|
35 |
import org.gvsig.vectorediting.lib.api.exceptions.DrawServiceException; |
|
36 |
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException; |
|
37 |
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException; |
|
38 |
import org.gvsig.vectorediting.lib.api.exceptions.StartServiceException; |
|
39 |
import org.gvsig.vectorediting.lib.api.exceptions.StopServiceException; |
|
40 |
import org.gvsig.vectorediting.lib.spi.EditingProvider; |
|
41 |
|
|
42 |
public class DefaultEditingService implements EditingService { |
|
43 |
|
|
44 |
EditingProvider provider; |
|
45 |
|
|
46 |
public DefaultEditingService(EditingProvider provider) { |
|
47 |
this.provider = provider; |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
public Manager getManager() { |
|
52 |
return null; |
|
53 |
} |
|
54 |
|
|
55 |
@Override |
|
56 |
public DrawingStatus getDrawingStatus(Point mousePosition) |
|
57 |
throws DrawServiceException { |
|
58 |
return provider.getDrawingStatus(mousePosition); |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
public List<EditingServiceParameter> getParameters() { |
|
63 |
return provider.getParameters(); |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
public EditingServiceParameter next() { |
|
68 |
return provider.next(); |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public void setValue(Object value) throws InvalidEntryException { |
|
73 |
provider.setValue(value); |
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
public void stop() throws StopServiceException { |
|
78 |
provider.stop(); |
|
79 |
} |
|
80 |
|
|
81 |
@Override |
|
82 |
public void finishAndStore() throws FinishServiceException { |
|
83 |
provider.finishAndStore(); |
|
84 |
} |
|
85 |
|
|
86 |
@Override |
|
87 |
public Geometry finish() throws FinishServiceException { |
|
88 |
return provider.finish(); |
|
89 |
} |
|
90 |
|
|
91 |
@Override |
|
92 |
public void start() throws StartServiceException, InvalidEntryException { |
|
93 |
this.provider.start(); |
|
94 |
} |
|
95 |
|
|
96 |
@Override |
|
97 |
public String getName() { |
|
98 |
return provider.getName(); |
|
99 |
} |
|
100 |
|
|
101 |
@Override |
|
102 |
public void setValue(EditingServiceParameter parameter, Object value) throws InvalidEntryException { |
|
103 |
provider.setValue(parameter, value); |
|
104 |
} |
|
105 |
|
|
106 |
@Override |
|
107 |
public boolean isEnabled(EditingServiceParameter parameter) { |
|
108 |
return provider.isEnabled(parameter); |
|
109 |
} |
|
110 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.124/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/src/main/java/org/gvsig/vectorediting/lib/impl/DefaultEditingLibrary.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2014 gvSIG Association |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.vectorediting.lib.impl; |
|
25 |
|
|
26 |
import org.gvsig.fmap.dal.DALLibrary; |
|
27 |
import org.gvsig.fmap.geom.GeometryLibrary; |
|
28 |
import org.gvsig.tools.library.AbstractLibrary; |
|
29 |
import org.gvsig.tools.library.LibraryException; |
|
30 |
import org.gvsig.vectorediting.lib.api.EditingLibrary; |
|
31 |
import org.gvsig.vectorediting.lib.api.EditingLocator; |
|
32 |
|
|
33 |
/** |
|
34 |
* Library for default implementation initialization and configuration. |
|
35 |
* |
|
36 |
* @author gvSIG team |
|
37 |
* @version $Id$ |
|
38 |
*/ |
|
39 |
public class DefaultEditingLibrary extends AbstractLibrary { |
|
40 |
|
|
41 |
@Override |
|
42 |
public void doRegistration() { |
|
43 |
registerAsImplementationOf(EditingLibrary.class); |
|
44 |
require(DALLibrary.class); |
|
45 |
require(GeometryLibrary.class); |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
protected void doInitialize() throws LibraryException { |
|
50 |
EditingLocator.registerManager(DefaultEditingManager.class); |
|
51 |
} |
|
52 |
|
|
53 |
@Override |
|
54 |
protected void doPostInitialize() throws LibraryException { |
|
55 |
// Do nothing |
|
56 |
} |
|
57 |
|
|
58 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.124/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/src/main/java/org/gvsig/vectorediting/lib/impl/DefaultEditingProviderManager.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2014 gvSIG Association |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
|
|
25 |
package org.gvsig.vectorediting.lib.impl; |
|
26 |
|
|
27 |
import java.net.URL; |
|
28 |
import java.util.HashMap; |
|
29 |
import java.util.Iterator; |
|
30 |
import java.util.Map; |
|
31 |
import java.util.Properties; |
|
32 |
|
|
33 |
import org.slf4j.Logger; |
|
34 |
import org.slf4j.LoggerFactory; |
|
35 |
|
|
36 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
37 |
import org.gvsig.tools.dynobject.DynObject; |
|
38 |
import org.gvsig.tools.service.Service; |
|
39 |
import org.gvsig.tools.service.ServiceException; |
|
40 |
import org.gvsig.tools.service.spi.AbstractProviderManager; |
|
41 |
import org.gvsig.tools.service.spi.Provider; |
|
42 |
import org.gvsig.tools.service.spi.ProviderFactory; |
|
43 |
import org.gvsig.tools.service.spi.ProviderServices; |
|
44 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
45 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
|
46 |
import org.gvsig.vectorediting.lib.api.EditingServiceInfo; |
|
47 |
import org.gvsig.vectorediting.lib.api.exceptions.ServiceInformationException; |
|
48 |
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory; |
|
49 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
|
50 |
|
|
51 |
public class DefaultEditingProviderManager extends AbstractProviderManager |
|
52 |
implements EditingProviderManager { |
|
53 |
|
|
54 |
private static final Logger logger = LoggerFactory |
|
55 |
.getLogger(DefaultEditingProviderManager.class); |
|
56 |
|
|
57 |
Map<String, ISymbol> symbols = |
|
58 |
new HashMap<String, ISymbol>(); |
|
59 |
|
|
60 |
Map<String, Map<String, String>> defaultValues = |
|
61 |
new HashMap<String, Map<String, String>>(); |
|
62 |
|
|
63 |
public ProviderServices createProviderServices(Service service) { |
|
64 |
// TODO Auto-generated method stub |
|
65 |
return null; |
|
66 |
} |
|
67 |
|
|
68 |
@Override |
|
69 |
protected String getRegistryKey() { |
|
70 |
// TODO Auto-generated method stub |
|
71 |
return null; |
|
72 |
} |
|
73 |
|
|
74 |
@Override |
|
75 |
protected String getRegistryDescription() { |
|
76 |
// TODO Auto-generated method stub |
|
77 |
return null; |
|
78 |
} |
|
79 |
|
|
80 |
@Override |
|
81 |
public Provider createProvider(DynObject serviceParameters, |
|
82 |
ProviderServices providerServices) throws ServiceException { |
|
83 |
String providerName = |
|
84 |
(String) serviceParameters |
|
85 |
.getDynValue(EditingProviderFactory.PROVIDER_NAME_FIELD); |
|
86 |
ProviderFactory factory = getProviderFactory(providerName); |
|
87 |
return factory == null ? null : factory.create(serviceParameters, |
|
88 |
providerServices); |
|
89 |
} |
|
90 |
|
|
91 |
public EditingServiceInfo getServiceInfo(String name) |
|
92 |
throws ServiceInformationException { |
|
93 |
EditingProviderFactory factory; |
|
94 |
try { |
|
95 |
factory = (EditingProviderFactory) getProviderFactory(name); |
|
96 |
return (factory == null ? null : factory.getServiceInfo()); |
|
97 |
} catch (Exception e) { |
|
98 |
throw new ServiceInformationException("Can't get service info of " |
|
99 |
+ name, e); |
|
100 |
} |
|
101 |
} |
|
102 |
|
|
103 |
public void registerIcon(String group, String name, ClassLoader loader, |
|
104 |
String provider) { |
|
105 |
String resourceName; |
|
106 |
IconTheme iconTheme = |
|
107 |
ToolsSwingLocator.getIconThemeManager().getCurrent(); |
|
108 |
if ((group == null) || (group.trim().length() == 0)) { |
|
109 |
resourceName = "images/" + name + ".png"; |
|
110 |
} else { |
|
111 |
resourceName = "images/" + group + "/" + name + ".png"; |
|
112 |
} |
|
113 |
|
|
114 |
URL resource = null; |
|
115 |
try { |
|
116 |
resource = loader.getResource(resourceName); |
|
117 |
iconTheme.registerDefault(provider, group, name, null, resource); |
|
118 |
} catch (Throwable e) { |
|
119 |
logger.info("Can't register icon '" + name + "'.", e); |
|
120 |
} |
|
121 |
|
|
122 |
} |
|
123 |
|
|
124 |
|
|
125 |
public void registerSymbol(String name, ISymbol symbol) { |
|
126 |
symbols.put(name, symbol); |
|
127 |
} |
|
128 |
|
|
129 |
public ISymbol getSymbol(String name) { |
|
130 |
return symbols.get(name); |
|
131 |
} |
|
132 |
|
|
133 |
public void registerDefaultValues(String provider, Map values) { |
|
134 |
if (!this.defaultValues.containsKey(provider)) { |
|
135 |
this.defaultValues.put(provider, values); |
|
136 |
} |
|
137 |
} |
|
138 |
|
|
139 |
public void registerDefaultValues(String provider, ClassLoader loader) { |
|
140 |
if (!this.defaultValues.containsKey(provider)) { |
|
141 |
String resourceName = |
|
142 |
"defaultvalues/" + provider + "/defaultvalues.properties"; |
|
143 |
HashMap<String, String> providerDefaultValues = |
|
144 |
new HashMap<String, String>(); |
|
145 |
|
|
146 |
URL resource = null; |
|
147 |
try { |
|
148 |
resource = loader.getResource(resourceName); |
|
149 |
|
|
150 |
Properties properties = new Properties(); |
|
151 |
properties.load(resource.openStream()); |
|
152 |
|
|
153 |
for (Iterator it = properties.keySet().iterator(); it.hasNext();) { |
|
154 |
String key = (String) it.next(); |
|
155 |
providerDefaultValues.put(key, (String) properties.get(key)); |
|
156 |
} |
|
157 |
this.defaultValues.put(provider, providerDefaultValues); |
|
158 |
} catch (Throwable e) { |
|
159 |
logger.info("Can't register default values from '" + provider |
|
160 |
+ "'.", e); |
|
161 |
} |
|
162 |
} |
|
163 |
} |
|
164 |
|
|
165 |
public Map<String, String> getDefaultValues(String name) { |
|
166 |
return this.defaultValues.get(name); |
|
167 |
} |
|
168 |
|
|
169 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.124/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/src/main/java/org/gvsig/vectorediting/lib/impl/DefaultEditingManager.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2014 gvSIG Association |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
|
|
25 |
package org.gvsig.vectorediting.lib.impl; |
|
26 |
|
|
27 |
import org.slf4j.Logger; |
|
28 |
import org.slf4j.LoggerFactory; |
|
29 |
|
|
30 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
31 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
32 |
import org.gvsig.tools.dynobject.DynObject; |
|
33 |
import org.gvsig.tools.service.AbstractManager; |
|
34 |
import org.gvsig.tools.service.Service; |
|
35 |
import org.gvsig.tools.service.ServiceException; |
|
36 |
import org.gvsig.vectorediting.lib.api.EditingManager; |
|
37 |
import org.gvsig.vectorediting.lib.api.EditingService; |
|
38 |
import org.gvsig.vectorediting.lib.api.EditingServiceInfo; |
|
39 |
import org.gvsig.vectorediting.lib.api.exceptions.ServiceInformationException; |
|
40 |
import org.gvsig.vectorediting.lib.spi.EditingProvider; |
|
41 |
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory; |
|
42 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
|
43 |
|
|
44 |
public class DefaultEditingManager extends AbstractManager implements |
|
45 |
EditingManager { |
|
46 |
|
|
47 |
private static final Logger logger = LoggerFactory |
|
48 |
.getLogger(DefaultEditingManager.class); |
|
49 |
|
|
50 |
public DefaultEditingManager() { |
|
51 |
super(new DefaultEditingProviderManager()); |
|
52 |
} |
|
53 |
|
|
54 |
public Service getService(DynObject arg0) throws ServiceException { |
|
55 |
EditingProvider provider = |
|
56 |
(EditingProvider) EditingProviderLocator.getProviderManager() |
|
57 |
.createProvider(arg0, new DefaultEditingProviderServices()); |
|
58 |
return new DefaultEditingService(provider); |
|
59 |
} |
|
60 |
|
|
61 |
public EditingServiceInfo getServiceInfo(String serviceName) |
|
62 |
throws ServiceInformationException { |
|
63 |
return EditingProviderLocator.getProviderManager().getServiceInfo( |
|
64 |
serviceName); |
|
65 |
} |
|
66 |
|
|
67 |
public EditingService getEditingService(String name, |
|
68 |
FeatureStore featureStore, MapContext mapContext) { |
|
69 |
try { |
|
70 |
DynObject params = this.createServiceParameters(name); |
|
71 |
params.setDynValue(EditingProviderFactory.FEATURE_STORE_FIELD, |
|
72 |
featureStore); |
|
73 |
params.setDynValue(EditingProviderFactory.MAPCONTEXT_FIELD, mapContext); |
|
74 |
return (EditingService) this.getService(params); |
|
75 |
} catch (ServiceException e) { |
|
76 |
String msg = |
|
77 |
String |
|
78 |
.format( |
|
79 |
"Some problem getting %1$s editing service. Seems to name is not correct or there is not factory registered with that name. ", |
|
80 |
name); |
|
81 |
logger.info(msg, e); |
|
82 |
} |
|
83 |
|
|
84 |
return null; |
|
85 |
} |
|
86 |
|
|
87 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.124/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/src/main/java/org/gvsig/vectorediting/lib/impl/DefaultEditingProviderServices.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2014 gvSIG Association |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.vectorediting.lib.impl; |
|
25 |
|
|
26 |
import java.util.Iterator; |
|
27 |
import java.util.List; |
|
28 |
import java.util.Map; |
|
29 |
import org.geotools.measure.AngleFormat; |
|
30 |
import org.gvsig.euclidean.EuclideanLine2D; |
|
31 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
|
32 |
import org.gvsig.fmap.dal.DALLocator; |
|
33 |
import org.gvsig.fmap.dal.DataManager; |
|
34 |
|
|
35 |
import org.gvsig.fmap.dal.EditingNotification; |
|
36 |
import org.gvsig.fmap.dal.EditingNotificationManager; |
|
37 |
import org.gvsig.fmap.dal.exception.DataException; |
|
38 |
import org.gvsig.fmap.dal.expressionevaluator.DALExpressionBuilder; |
|
39 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
40 |
import org.gvsig.fmap.dal.feature.Feature; |
|
41 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
42 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
43 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
44 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
45 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
|
46 |
import org.gvsig.fmap.geom.Geometry; |
|
47 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
48 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
49 |
import org.gvsig.fmap.geom.GeometryManager; |
|
50 |
import org.gvsig.fmap.geom.GeometryUtils; |
|
51 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
52 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
53 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
54 |
import org.gvsig.fmap.geom.primitive.Arc; |
|
55 |
import org.gvsig.fmap.geom.primitive.Circle; |
|
56 |
import org.gvsig.fmap.geom.primitive.Ellipse; |
|
57 |
import org.gvsig.fmap.geom.primitive.Line; |
|
58 |
import org.gvsig.fmap.geom.primitive.Point; |
|
59 |
import org.gvsig.fmap.geom.primitive.Spline; |
|
60 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
61 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
62 |
import org.gvsig.fmap.mapcontext.layers.CancelationException; |
|
63 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
64 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
65 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
66 |
import org.gvsig.tools.ToolsLocator; |
|
67 |
import org.gvsig.tools.exception.BaseException; |
|
68 |
import org.gvsig.tools.i18n.I18nManager; |
|
69 |
import org.gvsig.tools.service.spi.AbstractProviderServices; |
|
70 |
import org.gvsig.vectorediting.lib.spi.DefaultDrawingStatus; |
|
71 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
|
72 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
|
73 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
|
74 |
import org.slf4j.Logger; |
|
75 |
import org.slf4j.LoggerFactory; |
|
76 |
|
|
77 |
public class DefaultEditingProviderServices extends AbstractProviderServices |
|
78 |
implements EditingProviderServices { |
|
79 |
|
|
80 |
private static final Logger LOGGER = LoggerFactory |
|
81 |
.getLogger(DefaultEditingProviderServices.class); |
|
82 |
|
|
83 |
@Override |
|
84 |
public void insertFeatureIntoFeatureStore(Feature feature, |
|
85 |
FeatureStore featureStore) { |
|
86 |
EditableFeature eFeature = null; |
|
87 |
try { |
|
88 |
|
|
89 |
if (feature instanceof EditableFeature) { |
|
90 |
eFeature = (EditableFeature) feature; |
|
91 |
} else { |
|
92 |
eFeature = feature.getEditable(); |
|
93 |
} |
|
94 |
|
|
95 |
EditingNotificationManager editingNotificationManager |
|
96 |
= DALSwingLocator.getEditingNotificationManager(); |
|
97 |
|
|
98 |
EditingNotification notification |
|
99 |
= editingNotificationManager.notifyObservers(this, // source |
|
100 |
EditingNotification.BEFORE_INSERT_FEATURE, // type |
|
101 |
null,// document |
|
102 |
null,// layer |
|
103 |
featureStore,// store |
|
104 |
eFeature// feature |
|
105 |
); |
|
106 |
|
|
107 |
if (notification.isCanceled()) { |
|
108 |
String msg |
|
109 |
= String |
|
110 |
.format( |
|
111 |
"Can't insert feature into %1$s, canceled by some observer.", |
|
112 |
featureStore.getName()); |
|
113 |
throw new CancelationException(msg, null); |
|
114 |
} |
|
115 |
|
|
116 |
if (notification.shouldValidateTheFeature()) { |
|
117 |
if (!editingNotificationManager.validateFeature(eFeature)) { |
|
118 |
String msg |
|
119 |
= String.format("%1$s is not valid", eFeature.toString()); |
|
120 |
throw new Exception(msg); |
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
featureStore.insert(eFeature); |
|
125 |
|
|
126 |
editingNotificationManager.notifyObservers(this, |
|
127 |
EditingNotification.AFTER_INSERT_FEATURE, null, null, |
|
128 |
featureStore, eFeature); |
|
129 |
|
|
130 |
} catch (Exception e) { |
|
131 |
String msg |
|
132 |
= String.format("Can't insert %1$s into %2$s", |
|
133 |
eFeature.toString(), featureStore.getName()); |
|
134 |
LOGGER.info(msg, e); |
|
135 |
} |
|
136 |
} |
|
137 |
|
|
138 |
@Override |
|
139 |
public void insertGeometryIntoFeatureStore(Geometry geometry, |
|
140 |
FeatureStore featureStore) { |
|
141 |
EditableFeature eFeature = null; |
|
142 |
|
|
143 |
try { |
|
144 |
eFeature = featureStore.createNewFeature(true); |
|
145 |
|
|
146 |
eFeature.setGeometry(featureStore.getDefaultFeatureType() |
|
147 |
.getDefaultGeometryAttributeName(), geometry); |
|
148 |
|
|
149 |
EditingNotificationManager editingNotificationManager |
|
150 |
= DALSwingLocator.getEditingNotificationManager(); |
|
151 |
|
|
152 |
EditingNotification notification |
|
153 |
= editingNotificationManager.notifyObservers(this, // source |
|
154 |
EditingNotification.BEFORE_INSERT_FEATURE, // type |
|
155 |
null,// document |
|
156 |
null,// layer |
|
157 |
featureStore,// store |
|
158 |
eFeature// feature |
|
159 |
); |
|
160 |
|
|
161 |
if (notification.isCanceled()) { |
|
162 |
String msg |
|
163 |
= String |
|
164 |
.format( |
|
165 |
"Can't insert geometry into %1$s, canceled by some observer.", |
|
166 |
featureStore.getName()); |
|
167 |
throw new CancelationException(msg, null); |
|
168 |
} |
|
169 |
|
|
170 |
if (notification.shouldValidateTheFeature()) { |
|
171 |
if (!editingNotificationManager.validateFeature(eFeature)) { |
|
172 |
String msg |
|
173 |
= String.format("%1$s is not valid", eFeature.toString()); |
|
174 |
throw new Exception(msg); |
|
175 |
} |
|
176 |
} |
|
177 |
|
|
178 |
featureStore.insert(eFeature); |
|
179 |
|
|
180 |
editingNotificationManager.notifyObservers(this, |
|
181 |
EditingNotification.AFTER_INSERT_FEATURE, null, null, |
|
182 |
featureStore, eFeature); |
|
183 |
|
|
184 |
} catch (Exception e) { |
|
185 |
String msg |
|
186 |
= String.format("Can't insert %1$s into %2$s", |
|
187 |
eFeature.toString(), featureStore.getName()); |
|
188 |
LOGGER.info(msg, e); |
|
189 |
} |
|
190 |
} |
|
191 |
|
|
192 |
@Override |
|
193 |
public void deleteFeatureFromFeatureSet(Feature feature, |
|
194 |
FeatureStore featureStore, FeatureSet set) { |
|
195 |
|
|
196 |
try { |
|
197 |
EditingNotificationManager editingNotificationManager |
|
198 |
= DALSwingLocator.getEditingNotificationManager(); |
|
199 |
|
|
200 |
EditingNotification notification |
|
201 |
= editingNotificationManager.notifyObservers(this, // source |
|
202 |
EditingNotification.BEFORE_REMOVE_FEATURE, // type |
|
203 |
null,// document |
|
204 |
null,// layer |
|
205 |
featureStore,// store |
|
206 |
feature// feature |
|
207 |
); |
|
208 |
|
|
209 |
if (notification.isCanceled()) { |
|
210 |
String msg |
|
211 |
= String |
|
212 |
.format( |
|
213 |
"Can't delete feature from %1$s, canceled by some observer.", |
|
214 |
featureStore.getName()); |
|
215 |
throw new CancelationException(msg, null); |
|
216 |
} |
|
217 |
|
|
218 |
set.delete(feature); |
|
219 |
|
|
220 |
editingNotificationManager.notifyObservers(this, |
|
221 |
EditingNotification.AFTER_REMOVE_FEATURE, null, null, |
|
222 |
featureStore, feature); |
|
223 |
|
|
224 |
} catch (Exception e) { |
|
225 |
LOGGER.warn(e.getMessage(), e); |
|
226 |
} |
|
227 |
} |
|
228 |
|
|
229 |
@Override |
|
230 |
public void deleteFeatureFromFeatureStore(Feature feature, |
|
231 |
FeatureStore featureStore) { |
|
232 |
|
|
233 |
try { |
|
234 |
EditingNotificationManager editingNotificationManager |
|
235 |
= DALSwingLocator.getEditingNotificationManager(); |
|
236 |
|
|
237 |
EditingNotification notification |
|
238 |
= editingNotificationManager.notifyObservers(this, // source |
|
239 |
EditingNotification.BEFORE_REMOVE_FEATURE, // type |
|
240 |
null,// document |
|
241 |
null,// layer |
|
242 |
featureStore,// store |
|
243 |
feature// feature |
|
244 |
); |
|
245 |
|
|
246 |
if (notification.isCanceled()) { |
|
247 |
String msg |
|
248 |
= String |
|
249 |
.format( |
|
250 |
"Can't delete feature from %1$s, canceled by some observer.", |
|
251 |
featureStore.getName()); |
|
252 |
throw new CancelationException(msg, null); |
|
253 |
} |
|
254 |
|
|
255 |
featureStore.delete(feature); |
|
256 |
|
|
257 |
editingNotificationManager.notifyObservers(this, |
|
258 |
EditingNotification.AFTER_REMOVE_FEATURE, null, null, |
|
259 |
featureStore, feature); |
|
260 |
|
|
261 |
} catch (Exception e) { |
|
262 |
LOGGER.warn(e.getMessage(), e); |
|
263 |
} |
|
264 |
} |
|
265 |
|
|
266 |
@Override |
|
267 |
public void updateFeatureInFeatureStore(Feature feature, |
|
268 |
FeatureStore featureStore) { |
|
269 |
EditableFeature eFeature = null; |
|
270 |
|
|
271 |
try { |
|
272 |
|
|
273 |
if (feature instanceof EditableFeature) { |
|
274 |
eFeature = (EditableFeature) feature; |
|
275 |
} else { |
|
276 |
eFeature = feature.getEditable(); |
|
277 |
} |
|
278 |
|
|
279 |
EditingNotificationManager editingNotificationManager |
|
280 |
= DALSwingLocator.getEditingNotificationManager(); |
|
281 |
|
|
282 |
EditingNotification notification |
|
283 |
= editingNotificationManager.notifyObservers(this, // source |
|
284 |
EditingNotification.BEFORE_UPDATE_FEATURE, // type |
|
285 |
null,// document |
|
286 |
null,// layer |
|
287 |
featureStore,// store |
|
288 |
eFeature// feature |
|
289 |
); |
|
290 |
|
|
291 |
if (notification.isCanceled()) { |
|
292 |
String msg |
|
293 |
= String |
|
294 |
.format( |
|
295 |
"Can't update feature in %1$s, canceled by some observer.", |
|
296 |
featureStore.getName()); |
|
297 |
throw new CancelationException(msg, null); |
|
298 |
} |
|
299 |
|
|
300 |
if (notification.shouldValidateTheFeature()) { |
|
301 |
if (!editingNotificationManager.validateFeature(eFeature)) { |
|
302 |
String msg |
|
303 |
= String.format("%1$s is not valid", eFeature.toString()); |
|
304 |
throw new Exception(msg); |
|
305 |
} |
|
306 |
} |
|
307 |
|
|
308 |
featureStore.update(eFeature); |
|
309 |
editingNotificationManager.notifyObservers(this, |
|
310 |
EditingNotification.AFTER_UPDATE_FEATURE, null, null, |
|
311 |
featureStore, eFeature); |
|
312 |
|
|
313 |
} catch (Exception e) { |
|
314 |
String msg |
|
315 |
= String.format("Can't update %1$s in %2$s", eFeature.toString(), |
|
316 |
featureStore.getName()); |
|
317 |
LOGGER.info(msg, e); |
|
318 |
} |
|
319 |
} |
|
320 |
|
|
321 |
@Override |
|
322 |
public Circle createCircle(Point center, double radius, int subtype) |
|
323 |
throws CreateGeometryException { |
|
324 |
return GeometryUtils.createCircle(center, radius, subtype); |
|
325 |
} |
|
326 |
|
|
327 |
@Override |
|
328 |
public Circle createCircle(Point firstPoint, Point secondPoint, |
|
329 |
Point thridPoint, int subtype) throws CreateGeometryException { |
|
330 |
return GeometryUtils.createCircle(firstPoint, secondPoint, thridPoint, subtype); |
|
331 |
} |
|
332 |
|
|
333 |
@Override |
|
334 |
public Arc createArc(Point center, double radius, double startAngle, |
|
335 |
double angleExt, int subtype) throws CreateGeometryException { |
|
336 |
return GeometryUtils.createArc(center, radius, startAngle, angleExt, subtype); |
|
337 |
} |
|
338 |
|
|
339 |
@Override |
|
340 |
public Ellipse createFilledEllipse(Point firstPointAxisA, |
|
341 |
Point secondPointAxisA, double halfLengthAxisB, int subtype) |
|
342 |
throws CreateGeometryException { |
|
343 |
return GeometryUtils.createFilledEllipse(firstPointAxisA, secondPointAxisA, halfLengthAxisB, subtype); |
|
344 |
} |
|
345 |
|
|
346 |
@Override |
|
347 |
public Arc createArc(Point start, Point middle, Point end, int subtype) |
|
348 |
throws BaseException { |
|
349 |
return GeometryUtils.createArc(start, middle, end, subtype); |
|
350 |
} |
|
351 |
|
|
352 |
@Override |
|
353 |
public Point createPoint(double x, double y, int subtype) |
|
354 |
throws CreateGeometryException { |
|
355 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
356 |
return geomManager.createPoint(x, y, subtype); |
|
357 |
} |
|
358 |
|
|
359 |
@Override |
|
360 |
public Line createLine(double x1, double y1, double x2, double y2, |
|
361 |
int subtype) throws CreateGeometryException { |
|
362 |
return GeometryUtils.createLine(x1, y1, x2, y2, subtype); |
|
363 |
} |
|
364 |
|
|
365 |
@Override |
|
366 |
public int getSubType(FeatureStore featureStore) throws DataException { |
|
367 |
|
|
368 |
GeometryType geomType = getGeomType(featureStore); |
|
369 |
if (geomType != null) { |
|
370 |
return geomType.getSubType(); |
|
371 |
} |
|
372 |
return SUBTYPES.UNKNOWN; |
|
373 |
} |
|
374 |
|
|
375 |
@Override |
|
376 |
public GeometryType getGeomType(FeatureStore featureStore) |
|
377 |
throws DataException { |
|
378 |
return featureStore.getDefaultFeatureType() |
|
379 |
.getDefaultGeometryAttribute().getGeomType(); |
|
380 |
} |
|
381 |
|
|
382 |
@Override |
|
383 |
public EditableFeature getFeatureCopyWithoutPK(FeatureStore featureStore, |
|
384 |
Feature feature) throws DataException { |
|
385 |
EditableFeature editableFeature |
|
386 |
= featureStore.createNewFeature(feature.getType(), true); |
|
387 |
|
|
388 |
FeatureType type_src = feature.getType(); |
|
389 |
@SuppressWarnings("rawtypes") |
|
390 |
Iterator iterator = type_src.iterator(); |
|
391 |
FeatureType type_dest = editableFeature.getType(); |
|
392 |
|
|
393 |
while (iterator.hasNext()) { |
|
394 |
FeatureAttributeDescriptor attribute_src |
|
395 |
= (FeatureAttributeDescriptor) iterator.next(); |
|
396 |
|
|
397 |
FeatureAttributeDescriptor attribute_dest |
|
398 |
= type_dest.getAttributeDescriptor(attribute_src.getName()); |
|
399 |
if (attribute_dest != null) { |
|
400 |
if (!attribute_dest.isPrimaryKey()) { |
|
401 |
editableFeature.set(attribute_dest.getIndex(), |
|
402 |
feature.get(attribute_src.getIndex())); |
|
403 |
} |
|
404 |
} |
|
405 |
} |
|
406 |
return editableFeature; |
|
407 |
} |
|
408 |
|
|
409 |
@Override |
|
410 |
public Point getCenter(Point a, Point b, Point c, int subtype) |
|
411 |
throws CreateGeometryException { |
|
412 |
return GeometryUtils.getCenter(a, b, c, subtype); |
|
413 |
} |
|
414 |
|
|
415 |
@Override |
|
416 |
public Point getMidPoint(Point a, Point b, int subtype) |
|
417 |
throws CreateGeometryException { |
|
418 |
return GeometryUtils.getMidPoint(a, b, subtype); |
|
419 |
} |
|
420 |
|
|
421 |
@Override |
|
422 |
public Double[] getLineParams(Point point, Point nextPoint) { |
|
423 |
Double[] lineParams = new Double[2]; |
|
424 |
double denom = nextPoint.getX() - point.getX(); |
|
425 |
if (denom != 0) { |
|
426 |
lineParams[0] = (nextPoint.getY() - point.getY()) / denom; |
|
427 |
lineParams[1] = point.getY() - (lineParams[0] * point.getX()); |
|
428 |
} else { |
|
429 |
if (nextPoint.getY() >= point.getY()) { |
|
430 |
lineParams[0] = Double.POSITIVE_INFINITY; |
|
431 |
lineParams[1] = Double.NEGATIVE_INFINITY; |
|
432 |
if (point.getX() == 0) { |
|
433 |
lineParams[1] = 0.0; |
|
434 |
} |
|
435 |
} else { |
|
436 |
lineParams[0] = Double.NEGATIVE_INFINITY; |
|
437 |
lineParams[1] = Double.POSITIVE_INFINITY; |
|
438 |
if (point.getX() == 0) { |
|
439 |
lineParams[1] = 0.0; |
|
440 |
} |
|
441 |
} |
|
442 |
} |
|
443 |
return lineParams; |
|
444 |
} |
|
445 |
|
|
446 |
@Override |
|
447 |
public Point[] getPerpendicular(Double m, Double b, Point point, int subtype) |
|
448 |
throws CreateGeometryException { |
|
449 |
// Pendiente de la recta perpendicular |
|
450 |
Double m1 = -1 / m; |
|
451 |
|
|
452 |
// b de la funcion de la recta perpendicular |
|
453 |
Double b1 = point.getY() - (m1 * point.getX()); |
|
454 |
|
|
455 |
// Obtenemos un par de puntos |
|
456 |
Point[] res = new Point[2]; |
|
457 |
|
|
458 |
if (Double.isInfinite(m1)) { |
|
459 |
if (m1 > 0) { |
|
460 |
//return the director vector of the line |
|
461 |
res[0] = createPoint(point.getX(), 0.0, subtype); |
|
462 |
res[1] = createPoint(point.getX(), 1.0, subtype); |
|
463 |
} else { |
|
464 |
res[0] = createPoint(point.getX(), 0.0, subtype); |
|
465 |
res[1] = createPoint(point.getX(), -1.0, subtype); |
|
466 |
} |
|
467 |
} else { |
|
468 |
//return the director vector of the line |
|
469 |
res[0] = createPoint(0.0, b1, subtype); |
|
470 |
Double mod = Math.sqrt(1 + Math.pow(m1, 2)); |
|
471 |
Double x = 1 / mod; |
|
472 |
Double y = m1 * x + b1; |
|
473 |
res[1] = createPoint(x, y, subtype); |
|
474 |
} |
|
475 |
|
|
476 |
return res; |
|
477 |
} |
|
478 |
|
|
479 |
@Override |
|
480 |
public Point getIntersection(Point[] lineA, Point[] lineB, int subtype) |
|
481 |
throws CreateGeometryException { |
|
482 |
Point p1 = lineA[0]; |
|
483 |
Point p2 = lineA[1]; |
|
484 |
Point p3 = lineB[0]; |
|
485 |
Point p4 = lineB[1]; |
|
486 |
|
|
487 |
double m1 = Double.POSITIVE_INFINITY; |
|
488 |
|
|
489 |
if ((p2.getX() - p1.getX()) != 0) { |
|
490 |
m1 = (p2.getY() - p1.getY()) / (p2.getX() - p1.getX()); |
|
491 |
} |
|
492 |
|
|
493 |
double m2 = Double.POSITIVE_INFINITY; |
|
494 |
|
|
495 |
if ((p4.getX() - p3.getX()) != 0) { |
|
496 |
m2 = (p4.getY() - p3.getY()) / (p4.getX() - p3.getX()); |
|
497 |
} |
|
498 |
|
|
499 |
if ((m1 == Double.POSITIVE_INFINITY) |
|
500 |
&& (m2 == Double.POSITIVE_INFINITY)) { |
|
501 |
return null; |
|
502 |
} |
|
503 |
|
|
504 |
double b1 = p2.getY() - (m1 * p2.getX()); |
|
505 |
|
|
506 |
double b2 = p4.getY() - (m2 * p4.getX()); |
|
507 |
|
|
508 |
if ((m1 != Double.POSITIVE_INFINITY) |
|
509 |
&& (m2 != Double.POSITIVE_INFINITY)) { |
|
510 |
if (m1 == m2) { |
|
511 |
return null; |
|
512 |
} |
|
513 |
|
|
514 |
double x = (b2 - b1) / (m1 - m2); |
|
515 |
|
|
516 |
return createPoint(x, (m1 * x) + b1, subtype); |
|
517 |
} else if (m1 == Double.POSITIVE_INFINITY) { |
|
518 |
double x = p1.getX(); |
|
519 |
|
|
520 |
return createPoint(x, (m2 * x) + b2, subtype); |
|
521 |
} else if (m2 == Double.POSITIVE_INFINITY) { |
|
522 |
double x = p3.getX(); |
|
523 |
|
|
524 |
return createPoint(x, (m1 * x) + b1, subtype); |
|
525 |
} |
|
526 |
|
|
527 |
return null; |
|
528 |
} |
|
529 |
|
|
530 |
@Override |
|
531 |
public double getAngle(Point start, Point end) |
|
532 |
throws GeometryOperationNotSupportedException, |
|
533 |
GeometryOperationException { |
|
534 |
double angle |
|
535 |
= Math.acos((end.getX() - start.getX()) / start.distance(end)); |
|
536 |
|
|
537 |
if (start.getY() > end.getY()) { |
|
538 |
angle = -angle; |
|
539 |
} |
|
540 |
|
|
541 |
if (angle < 0) { |
|
542 |
angle += (2 * Math.PI); |
|
543 |
} |
|
544 |
|
|
545 |
return angle; |
|
546 |
} |
|
547 |
|
|
548 |
@Override |
|
549 |
public double angleDistance(double angle1, double angle2) { |
|
550 |
double result = angle2 - angle1; |
|
551 |
if (result < 0) { |
|
552 |
result = (Math.PI * 2) + result; |
|
553 |
} |
|
554 |
return result; |
|
555 |
} |
|
556 |
|
|
557 |
@Override |
|
558 |
public Line createLine(Point p1, Point p2, int subtype) |
|
559 |
throws CreateGeometryException { |
|
560 |
return GeometryUtils.createLine(p1, p2, subtype); |
|
561 |
} |
|
562 |
|
|
563 |
@Override |
|
564 |
public Spline createSpline(List<Point> points, int subtype) |
|
565 |
throws CreateGeometryException { |
|
566 |
return GeometryUtils.createSpline(points, subtype); |
|
567 |
} |
|
568 |
|
|
569 |
@Override |
|
570 |
public String makeConsoleMessage(String preText, Map<String, String> options) { |
|
571 |
|
|
572 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
573 |
|
|
574 |
StringBuilder stb = new StringBuilder(); |
|
575 |
|
|
576 |
if (preText != null) { |
|
577 |
stb.append(i18nManager.getTranslation(preText)); |
|
578 |
stb.append(" "); |
|
579 |
} |
|
580 |
|
|
581 |
for (String option : options.keySet()) { |
|
582 |
stb.append("["); |
|
583 |
stb.append(option); |
|
584 |
stb.append("]"); |
|
585 |
stb.append(i18nManager.getTranslation(options.get(option))); |
|
586 |
stb.append(" "); |
|
587 |
} |
|
588 |
|
|
589 |
return stb.toString(); |
|
590 |
} |
|
591 |
|
|
592 |
@Override |
|
593 |
public Arc createEllipse(Point firstPointAxisA, Point secondPointAxisA, |
|
594 |
double halfLengthAxisB, int subtype) throws CreateGeometryException { |
|
595 |
return GeometryUtils.createEllipse(firstPointAxisA, secondPointAxisA, halfLengthAxisB, subtype); |
|
596 |
} |
|
597 |
|
|
598 |
@Override |
|
599 |
public Circle createCircle(Point firstPoint, Point secondPoint, Point thirdPoint, Point fourthPoint, Point fifthPoint, int subtype) throws CreateGeometryException { |
|
600 |
return GeometryUtils.createCircle(firstPoint, secondPoint, thirdPoint, fourthPoint, fifthPoint, subtype); |
|
601 |
} |
|
602 |
|
|
603 |
@Override |
|
604 |
public Circle createCircle(EuclideanLine2D line1, EuclideanLine2D line2, Point point, int subtype) throws CreateGeometryException { |
|
605 |
return GeometryUtils.createCircle(line1, line2, point, subtype); |
|
606 |
} |
|
607 |
|
|
608 |
@Override |
|
609 |
public Circle createCircle(Geometry geometry1, Geometry geometry2, double radius, Point firstPoint, Point secondPoint, int subtype) throws CreateGeometryException { |
|
610 |
return GeometryUtils.createCircle(geometry1, geometry2, radius, firstPoint, secondPoint, subtype); |
|
611 |
} |
|
612 |
|
|
613 |
@Override |
|
614 |
public Geometry getGeometry(Point point, FeatureStore store, MapContext mapContext) { |
|
615 |
Geometry geometry = null; |
|
616 |
try { |
|
617 |
double tolerance = mapContext.getViewPort().toMapDistance(mapContext.getLayers().getDefaultTolerance()); |
|
618 |
Geometry buffer = point.buffer(tolerance); |
|
619 |
|
|
620 |
DataManager dataManager = DALLocator.getDataManager(); |
|
621 |
DALExpressionBuilder dalBuilder = dataManager.createDALExpressionBuilder(); |
|
622 |
GeometryExpressionBuilder builder = dalBuilder.expression(); |
|
623 |
String filter = builder.ST_Intersects(builder.geometry(buffer, mapContext.getProjection()), dalBuilder.geometry()).toString(); |
|
624 |
String sortBy = builder.ST_Distance(builder.geometry(buffer), dalBuilder.geometry()).toString(); |
|
625 |
|
|
626 |
Feature f; |
|
627 |
f = store.findFirst(filter, sortBy, true); |
|
628 |
if (f != null) { |
|
629 |
geometry = f.getDefaultGeometry(); |
|
630 |
} |
|
631 |
|
|
632 |
} catch (Exception ex) { |
|
633 |
LOGGER.warn("Can't get geometry on point (" + point.getX() + "," + point.getY(), ex); |
|
634 |
} |
|
635 |
|
|
636 |
return geometry; |
|
637 |
} |
|
638 |
|
|
639 |
@Override |
|
640 |
public Geometry getGeometryOfVisibleLayers(Point point, FeatureStore store, MapContext mapContext) { |
|
641 |
|
|
642 |
// Search in the store itself |
|
643 |
Geometry geometry = this.getGeometry(point, store, mapContext); |
|
644 |
// Search in the store for the layers that are in edit |
|
645 |
if (geometry == null) { |
|
646 |
for (Iterator<FLayer> iterator = mapContext.getLayers().deepiterator(); iterator.hasNext();) { |
|
647 |
FLayer layer = iterator.next(); |
|
648 |
if (layer instanceof FLyrVect) { |
|
649 |
FLyrVect vectLayer = (FLyrVect) layer; |
|
650 |
if (vectLayer.getFeatureStore() != store && vectLayer.isEditing()) { |
|
651 |
geometry = this.getGeometry(point, vectLayer.getFeatureStore(), mapContext); |
|
652 |
if (geometry != null) { |
|
653 |
break; |
|
654 |
} |
|
655 |
} |
|
656 |
} |
|
657 |
} |
|
658 |
} |
|
659 |
// Search in the store for the active layers |
|
660 |
if (geometry == null) { |
|
661 |
FLayer[] activeLayers = mapContext.getLayers().getActives(); |
|
662 |
for (FLayer activeLayer : activeLayers) { |
|
663 |
if (activeLayer instanceof FLyrVect) { |
|
664 |
FLyrVect activeVectLayer = (FLyrVect) activeLayer; |
|
665 |
if (activeVectLayer.getFeatureStore() != store && !activeVectLayer.isEditing()) { |
|
666 |
geometry = this.getGeometry(point, activeVectLayer.getFeatureStore(), mapContext); |
|
667 |
if (geometry != null) { |
|
668 |
break; |
|
669 |
} |
|
670 |
} |
|
671 |
} |
|
672 |
} |
|
673 |
} |
|
674 |
return geometry; |
|
675 |
} |
|
676 |
|
|
677 |
@Override |
|
678 |
public void addAngleToDrawingStatus(DefaultDrawingStatus drawingStatus, ISymbol textSymbol, Point vertex, Point ray1, Point ray2, int subtype) throws CreateGeometryException, GeometryOperationNotSupportedException, GeometryOperationException { |
|
679 |
EditingProviderManager editingProviderManager |
|
680 |
= EditingProviderLocator.getProviderManager(); |
|
681 |
ISymbol auxiliaryLineSymbolEditing = editingProviderManager.getSymbol("auxiliary-line-symbol-editing"); |
|
682 |
|
|
683 |
double angleRay1 = GeometryUtils.calculateAngle(vertex, ray1); |
|
684 |
double angle = GeometryUtils.calculateAngle(vertex, ray1, ray2); |
|
685 |
double radius = vertex.distance(ray1) / 4; |
|
686 |
Arc auxArc = GeometryUtils.createArc( |
|
687 |
vertex, |
|
688 |
radius, |
|
689 |
GeometryUtils.calculateAngle(vertex, ray1), |
|
690 |
angle, |
|
691 |
subtype |
|
692 |
); |
|
693 |
drawingStatus.addStatus(auxArc, auxiliaryLineSymbolEditing, ""); |
|
694 |
|
|
695 |
Point measurePoint = GeometryUtils.createPoint(vertex, radius, angleRay1 + angle / 2); |
|
696 |
|
|
697 |
// drawingStatus.addStatus(measurePoint, textSymbol, new AngleFormat("DD?MM'").format(Math.toDegrees(angle))); |
|
698 |
drawingStatus.addStatus(measurePoint, textSymbol, new AngleFormat("DD.ddd?").format(Math.toDegrees(angle))); |
|
699 |
|
|
700 |
} |
|
701 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.124/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/src/main/java/org/gvsig/vectorediting/lib/impl/DefaultEditingProviderLibrary.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2014 gvSIG Association |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
|
|
25 |
package org.gvsig.vectorediting.lib.impl; |
|
26 |
|
|
27 |
import org.gvsig.fmap.dal.DALLibrary; |
|
28 |
import org.gvsig.tools.library.AbstractLibrary; |
|
29 |
import org.gvsig.tools.library.LibraryException; |
|
30 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLibrary; |
|
31 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
|
32 |
|
|
33 |
public class DefaultEditingProviderLibrary extends AbstractLibrary { |
|
34 |
|
|
35 |
@Override |
|
36 |
public void doRegistration() { |
|
37 |
registerAsImplementationOf(EditingProviderLibrary.class); |
|
38 |
require(DALLibrary.class); |
|
39 |
} |
|
40 |
|
|
41 |
@Override |
|
42 |
protected void doInitialize() throws LibraryException { |
|
43 |
EditingProviderLocator |
|
44 |
.registerEditingProviderManager(DefaultEditingProviderManager.class); |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
protected void doPostInitialize() throws LibraryException { |
|
49 |
|
|
50 |
} |
|
51 |
|
|
52 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.124/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<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/maven-v4_0_0.xsd"> |
|
3 |
<modelVersion>4.0.0</modelVersion> |
|
4 |
<artifactId>org.gvsig.vectorediting.lib.impl</artifactId> |
|
5 |
<packaging>jar</packaging> |
|
6 |
<name>org.gvsig.vectorediting.lib.impl</name> |
|
7 |
<parent> |
|
8 |
<groupId>org.gvsig</groupId> |
|
9 |
<artifactId>org.gvsig.vectorediting.lib</artifactId> |
|
10 |
<version>1.0.124</version> |
|
11 |
</parent> |
|
12 |
<dependencies> |
|
13 |
<dependency> |
|
14 |
<groupId>org.gvsig</groupId> |
|
15 |
<artifactId>org.gvsig.vectorediting.lib.api</artifactId> |
|
16 |
</dependency> |
|
17 |
<dependency> |
|
18 |
<groupId>org.gvsig</groupId> |
|
19 |
<artifactId>org.gvsig.vectorediting.lib.spi</artifactId> |
|
20 |
</dependency> |
|
21 |
<dependency> |
|
22 |
<groupId>org.gvsig</groupId> |
|
23 |
<artifactId>org.gvsig.fmap.dal.swing.api</artifactId> |
|
24 |
</dependency> |
|
25 |
|
|
26 |
<dependency> |
|
27 |
<groupId>org.gvsig</groupId> |
|
28 |
<artifactId>${org.gvsig.fmap.geometry.impl}</artifactId> |
|
29 |
<scope>test</scope> |
|
30 |
</dependency> |
|
31 |
|
|
32 |
</dependencies> |
|
33 |
</project> |
|
0 | 34 |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.124/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.duplicate/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.vectorediting.lib.prov.duplicate.DuplicateEditingLibrary |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.124/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.duplicate/src/main/java/org/gvsig/vectorediting/lib/prov/duplicate/DuplicateEditingProvider.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2014 gvSIG Association |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
|
|
25 |
package org.gvsig.vectorediting.lib.prov.duplicate; |
|
26 |
|
|
27 |
import java.awt.geom.AffineTransform; |
|
28 |
import java.util.ArrayList; |
|
29 |
import java.util.HashMap; |
|
30 |
import java.util.List; |
|
31 |
import java.util.Map; |
|
32 |
|
|
33 |
import org.gvsig.fmap.dal.exception.DataException; |
|
34 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
35 |
import org.gvsig.fmap.dal.feature.Feature; |
|
36 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
37 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
38 |
import org.gvsig.fmap.geom.Geometry; |
|
39 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
40 |
import org.gvsig.fmap.geom.GeometryManager; |
|
41 |
import org.gvsig.fmap.geom.aggregate.Aggregate; |
|
42 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
|
43 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
|
44 |
import org.gvsig.fmap.geom.aggregate.MultiSurface; |
|
45 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
46 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
47 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
48 |
import org.gvsig.fmap.geom.primitive.Curve; |
|
49 |
import org.gvsig.fmap.geom.primitive.Line; |
|
50 |
import org.gvsig.fmap.geom.primitive.Point; |
|
51 |
import org.gvsig.fmap.geom.primitive.Surface; |
|
52 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
53 |
import org.gvsig.tools.ToolsLocator; |
|
54 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
55 |
import org.gvsig.tools.dynobject.DynObject; |
|
56 |
import org.gvsig.tools.exception.BaseException; |
|
57 |
import org.gvsig.tools.service.spi.ProviderServices; |
|
58 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
59 |
import org.gvsig.tools.visitor.Visitor; |
|
60 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
|
61 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
|
62 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
|
63 |
import org.gvsig.vectorediting.lib.api.exceptions.DrawServiceException; |
|
64 |
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException; |
|
65 |
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException; |
|
66 |
import org.gvsig.vectorediting.lib.api.exceptions.StartServiceException; |
|
67 |
import org.gvsig.vectorediting.lib.api.exceptions.StopServiceException; |
|
68 |
import org.gvsig.vectorediting.lib.spi.AbstractEditingProvider; |
|
69 |
import org.gvsig.vectorediting.lib.spi.DefaultDrawingStatus; |
|
70 |
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceParameter; |
|
71 |
import org.gvsig.vectorediting.lib.spi.EditingProvider; |
|
72 |
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory; |
|
73 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
|
74 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
|
75 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
|
76 |
|
|
77 |
/** |
|
78 |
* @author llmarques |
|
79 |
* |
|
80 |
*/ |
|
81 |
public class DuplicateEditingProvider extends AbstractEditingProvider implements |
|
82 |
EditingProvider { |
|
83 |
|
|
84 |
private EditingServiceParameter selection; |
|
85 |
|
|
86 |
private EditingServiceParameter firstPoint; |
|
87 |
|
|
88 |
private EditingServiceParameter secondPoint; |
|
89 |
|
|
90 |
private FeatureStore featureStore; |
|
91 |
|
|
92 |
private Map<EditingServiceParameter, Object> values; |
|
93 |
|
|
94 |
/** |
|
95 |
* Default constructor. |
|
96 |
* |
|
97 |
* @param providerServices |
|
98 |
* available services for this provider |
|
99 |
* @param parameters |
|
100 |
* of this provider |
|
101 |
*/ |
|
102 |
public DuplicateEditingProvider(DynObject parameters, |
|
103 |
ProviderServices services) { |
|
104 |
super(services); |
|
105 |
|
|
106 |
this.featureStore = |
|
107 |
(FeatureStore) parameters |
|
108 |
.getDynValue(EditingProviderFactory.FEATURE_STORE_FIELD); |
|
109 |
|
|
110 |
this.selection = |
|
111 |
new DefaultEditingServiceParameter("selection", "selection", |
|
112 |
TYPE.SELECTION); |
|
113 |
|
Also available in: Unified diff