Revision 38061
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/FLyrVect.java | ||
---|---|---|
55 | 55 |
|
56 | 56 |
import org.apache.log4j.Logger; |
57 | 57 |
import org.cresques.cts.ICoordTrans; |
58 |
import org.gvsig.exceptions.BaseException; |
|
59 | 58 |
import org.gvsig.tools.file.PathGenerator; |
60 | 59 |
|
61 | 60 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
... | ... | |
88 | 87 |
import com.iver.cit.gvsig.fmap.drivers.IVectorialDatabaseDriver; |
89 | 88 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
90 | 89 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
91 |
import com.iver.cit.gvsig.fmap.drivers.featureiterators.DefaultFeatureIterator; |
|
92 | 90 |
import com.iver.cit.gvsig.fmap.drivers.featureiterators.JoinFeatureIterator; |
93 | 91 |
import com.iver.cit.gvsig.fmap.edition.AfterFieldEditEvent; |
94 | 92 |
import com.iver.cit.gvsig.fmap.edition.AfterRowEditEvent; |
... | ... | |
124 | 122 |
import com.iver.cit.gvsig.fmap.rendering.ZSort; |
125 | 123 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.AttrInTableLabelingStrategy; |
126 | 124 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.ILabelingStrategy; |
127 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelClass; |
|
128 | 125 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelingFactory; |
129 | 126 |
import com.iver.cit.gvsig.fmap.spatialindex.IPersistentSpatialIndex; |
130 | 127 |
import com.iver.cit.gvsig.fmap.spatialindex.ISpatialIndex; |
... | ... | |
145 | 142 |
* @author Fernando Gonz?lez Cort?s |
146 | 143 |
*/ |
147 | 144 |
|
148 |
// TODO Cuando no sea para pruebas debe no ser public |
|
149 | 145 |
public class FLyrVect extends FLyrDefault implements ILabelable, |
150 | 146 |
ClassifiableVectorial, SingleLayer, VectorialData, RandomVectorialData, |
151 | 147 |
AlphanumericData, InfoByPoint, SelectionListener, IEditionListener, LegendContentsChangedListener { |
152 |
private static Logger logger = Logger.getLogger(FLyrVect.class.getName()); |
|
153 |
/** |
|
154 |
* @deprecated Don?t use Strategy, you should be use iterators. |
|
155 |
*/ |
|
156 |
// public static boolean forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD = true; |
|
157 |
/** |
|
158 |
* @deprecated Don?t use Strategy, you should be use iterators. |
|
159 |
*/ |
|
160 |
// private boolean useStrategy=false; |
|
161 | 148 |
|
149 |
private static Logger logger = Logger.getLogger(FLyrVect.class.getName()); |
|
150 |
|
|
162 | 151 |
/** Leyenda de la capa vectorial */ |
163 | 152 |
private IVectorLegend legend; |
164 | 153 |
private int typeShape = -1; |
... | ... | |
628 | 617 |
|
629 | 618 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
630 | 619 |
Cancellable cancel, double scale) throws ReadDriverException { |
631 |
// forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD = true; |
|
632 |
// if (!isUseStrategy()) { |
|
633 | 620 |
if (isWaitTodraw()) { |
634 | 621 |
return; |
635 | 622 |
} |
... | ... | |
639 | 626 |
else { |
640 | 627 |
_draw(image, g, viewPort, cancel, scale); |
641 | 628 |
} |
642 |
// } else { |
|
643 |
//// moved up to FLayers |
|
644 |
//// if (isWithinScale(scale)) { |
|
645 |
// |
|
646 |
// |
|
647 |
// // Las que solo tienen etiquetado sin pintar el shape, |
|
648 |
// // no pasamos por ellas |
|
649 |
// boolean bDrawShapes = true; |
|
650 |
// if (legend instanceof SingleSymbolLegend) { |
|
651 |
// if (legend.getDefaultSymbol().isShapeVisible() == false) |
|
652 |
// bDrawShapes = false; |
|
653 |
// } |
|
654 |
// if (bDrawShapes) { |
|
655 |
// Strategy strategy = StrategyManager.getStrategy(this); |
|
656 |
// try { |
|
657 |
// prepareDrawing(image, g, viewPort); |
|
658 |
// strategy.draw(image, g, viewPort, cancel); |
|
659 |
// } catch (ReadDriverException e) { |
|
660 |
// this.setVisible(false); |
|
661 |
// this.setActive(false); |
|
662 |
// throw e; |
|
663 |
// } |
|
664 |
// } |
|
665 |
// if (getVirtualLayers() != null) { |
|
666 |
// getVirtualLayers().draw(image, g, viewPort, cancel, scale); |
|
667 |
// } |
|
668 |
//// } |
|
669 |
// } |
|
670 | 629 |
} |
671 | 630 |
|
672 |
/** |
|
673 |
* Se llama antes de empezar a pintar. |
|
674 |
* Es ?til para preparar la cache a emplear, las leyendas, etc. |
|
675 |
* @param image |
|
676 |
* @param g |
|
677 |
* @param viewPort |
|
678 |
*/ |
|
679 |
private void prepareDrawing(BufferedImage image, Graphics2D g, ViewPort viewPort) { |
|
680 |
|
|
681 |
} |
|
682 |
|
|
683 | 631 |
public void _print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
684 | 632 |
double scale, PrintRequestAttributeSet properties) throws ReadDriverException { |
685 |
// TEST METHOD |
|
686 |
|
|
687 |
|
|
688 |
/* SVN */ |
|
689 |
|
|
690 |
/* boolean bDrawShapes = true; |
|
691 |
if (legend instanceof SingleSymbolLegend) { |
|
692 |
bDrawShapes = legend.getDefaultSymbol().isShapeVisible(); |
|
693 |
} |
|
694 |
|
|
695 |
|
|
696 |
if (bDrawShapes) { |
|
697 |
double dpi = 72; |
|
698 |
|
|
699 |
PrintQuality resolution=(PrintQuality)properties.get(PrintQuality.class); |
|
700 |
if (resolution.equals(PrintQuality.NORMAL)){ |
|
701 |
dpi = 300; |
|
702 |
} else if (resolution.equals(PrintQuality.HIGH)){ |
|
703 |
dpi = 600; |
|
704 |
} else if (resolution.equals(PrintQuality.DRAFT)){ |
|
705 |
dpi = 72; |
|
706 |
} |
|
707 |
|
|
708 |
|
|
709 |
try { |
|
710 |
prepareDrawing(null, g, viewPort); |
|
711 |
ArrayList<String> fieldList = new ArrayList<String>(); |
|
712 |
String[] aux; |
|
713 |
|
|
714 |
// fields from legend |
|
715 |
if (legend instanceof IClassifiedVectorLegend) { |
|
716 |
aux = ((IClassifiedVectorLegend) legend). |
|
717 |
getClassifyingFieldNames(); |
|
718 |
for (int i = 0; i < aux.length; i++) { |
|
719 |
fieldList.add(aux[i]); |
|
720 |
} |
|
721 |
} |
|
722 |
|
|
723 |
// fields from labeling |
|
724 |
if (isLabeled()) { |
|
725 |
aux = getLabelingStrategy().getUsedFields(); |
|
726 |
for (int i = 0; i < aux.length; i++) { |
|
727 |
fieldList.add(aux[i]); |
|
728 |
} |
|
729 |
} |
|
730 |
|
|
731 |
ZSort zSort = ((IVectorLegend) getLegend()).getZSort(); |
|
732 |
|
|
733 |
// if layer has map levels it will use a ZSort |
|
734 |
boolean useZSort = zSort != null && zSort.isUsingZSort(); |
|
735 |
|
|
736 |
|
|
737 |
int mapLevelCount = (useZSort) ? zSort.getLevelCount() : 1; |
|
738 |
for (int mapPass = 0; mapPass < mapLevelCount; mapPass++) { |
|
739 |
// Get the iterator over the visible features |
|
740 |
IFeatureIterator it = getSource().getFeatureIterator( |
|
741 |
viewPort.getAdjustedExtent(), |
|
742 |
fieldList.toArray(new String[fieldList.size()]), |
|
743 |
viewPort.getProjection(), |
|
744 |
true); |
|
745 |
|
|
746 |
// Iteration over each feature |
|
747 |
while ( !cancel.isCanceled() && it.hasNext()) { |
|
748 |
IFeature feat = it.next(); |
|
749 |
IGeometry geom = feat.getGeometry(); |
|
750 |
|
|
751 |
// retreive the symbol associated to such feature |
|
752 |
ISymbol sym = legend.getSymbolByFeature(feat); |
|
753 |
|
|
754 |
if (useZSort) { |
|
755 |
// Check if this symbol is a multilayer |
|
756 |
if (sym instanceof IMultiLayerSymbol) { |
|
757 |
// if so, get the layer corresponding to the current |
|
758 |
// level. If none, continue to next iteration |
|
759 |
IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym; |
|
760 |
for (int i = 0; i < mlSym.getLayerCount(); i++) { |
|
761 |
ISymbol mySym = mlSym.getLayer(i); |
|
762 |
if (zSort.getSymbolLevel(mySym) == mapPass) { |
|
763 |
sym = mySym; |
|
764 |
break; |
|
765 |
} |
|
766 |
System.out.println("avoided layer "+i+"of symbol '"+mlSym.getDescription()+"' (pass "+mapPass+")"); |
|
767 |
} |
|
768 |
|
|
769 |
if (sym == null) { |
|
770 |
continue; |
|
771 |
} |
|
772 |
} else { |
|
773 |
// else, just draw the symbol in its level |
|
774 |
if (zSort.getSymbolLevel(sym) != mapPass) { |
|
775 |
System.out.println("avoided single layer symbol '"+sym.getDescription()+"' (pass "+mapPass+")"); |
|
776 |
continue; |
|
777 |
} |
|
778 |
} |
|
779 |
} |
|
780 |
|
|
781 |
// Check if this symbol is sized with CartographicSupport |
|
782 |
CartographicSupport csSym = null; |
|
783 |
int symbolType = sym.getSymbolType(); |
|
784 |
boolean bDrawCartographicSupport = false; |
|
785 |
|
|
786 |
if ( symbolType == FShape.POINT |
|
787 |
|| symbolType == FShape.LINE |
|
788 |
|| sym instanceof CartographicSupport) { |
|
789 |
|
|
790 |
csSym = (CartographicSupport) sym; |
|
791 |
bDrawCartographicSupport = (csSym.getUnit() != -1); |
|
792 |
} |
|
793 |
|
|
794 |
System.err.println("passada "+mapPass+" pinte s?mboll "+sym.getDescription()); |
|
795 |
|
|
796 |
if (!bDrawCartographicSupport) { |
|
797 |
geom.drawInts(g, viewPort, sym, null); |
|
798 |
} else { |
|
799 |
geom.drawInts(g, viewPort, dpi, (CartographicSupport) csSym); |
|
800 |
} |
|
801 |
|
|
802 |
} |
|
803 |
it.closeIterator(); |
|
804 |
} |
|
805 |
} catch (ReadDriverException e) { |
|
806 |
this.setVisible(false); |
|
807 |
this.setActive(false); |
|
808 |
throw e; |
|
809 |
} |
|
810 |
*/ |
|
811 |
|
|
812 |
|
|
813 |
// TEST METHOD |
|
814 | 633 |
boolean bDrawShapes = true; |
815 | 634 |
if (legend instanceof SingleSymbolLegend) { |
816 | 635 |
bDrawShapes = legend.getDefaultSymbol().isShapeVisible(); |
... | ... | |
835 | 654 |
|
836 | 655 |
// fields from legend |
837 | 656 |
if (legend instanceof IClassifiedVectorLegend) { |
838 |
aux = ((IClassifiedVectorLegend) legend). |
|
839 |
getClassifyingFieldNames(); |
|
657 |
aux = ((IClassifiedVectorLegend) legend).getClassifyingFieldNames(); |
|
840 | 658 |
for (int i = 0; i < aux.length; i++) { |
841 | 659 |
fieldList.add(aux[i]); |
842 | 660 |
} |
843 | 661 |
} |
844 |
// |
|
845 |
// // fields from labeling |
|
846 |
// if (isLabeled()) { |
|
847 |
// aux = getLabelingStrategy().getUsedFields(); |
|
848 |
// for (int i = 0; i < aux.length; i++) { |
|
849 |
// fieldList.add(aux[i]); |
|
850 |
// } |
|
851 |
// } |
|
662 |
//
|
|
663 |
// // fields from labeling
|
|
664 |
// if (isLabeled()) {
|
|
665 |
// aux = getLabelingStrategy().getUsedFields();
|
|
666 |
// for (int i = 0; i < aux.length; i++) {
|
|
667 |
// fieldList.add(aux[i]);
|
|
668 |
// }
|
|
669 |
// }
|
|
852 | 670 |
|
853 | 671 |
ZSort zSort = ((IVectorLegend) getLegend()).getZSort(); |
854 | 672 |
|
... | ... | |
859 | 677 |
int mapLevelCount = (useZSort) ? zSort.getLevelCount() : 1; |
860 | 678 |
for (int mapPass = 0; mapPass < mapLevelCount; mapPass++) { |
861 | 679 |
// Get the iterator over the visible features |
862 |
// IFeatureIterator it = getSource().getFeatureIterator( |
|
863 |
// viewPort.getAdjustedExtent(), |
|
864 |
// fieldList.toArray(new String[fieldList.size()]), |
|
865 |
// viewPort.getProjection(), |
|
866 |
// true); |
|
867 |
IFeatureIterator it = null;
|
|
868 |
if (isJoined()) {
|
|
869 |
it = new JoinFeatureIterator(this, viewPort,
|
|
870 |
fieldList.toArray(new String[fieldList.size()]));
|
|
871 |
}
|
|
872 |
else {
|
|
873 |
it = getSource().getFeatureIterator(
|
|
874 |
viewPort.getAdjustedExtent(),
|
|
875 |
fieldList.toArray(new String[fieldList.size()]),
|
|
876 |
viewPort.getProjection(),
|
|
877 |
true);
|
|
878 |
}
|
|
680 |
// IFeatureIterator it = getSource().getFeatureIterator(
|
|
681 |
// viewPort.getAdjustedExtent(),
|
|
682 |
// fieldList.toArray(new String[fieldList.size()]),
|
|
683 |
// viewPort.getProjection(),
|
|
684 |
// true);
|
|
685 |
IFeatureIterator it = null;
|
|
686 |
if (isJoined()) {
|
|
687 |
it = new JoinFeatureIterator(this, viewPort,
|
|
688 |
fieldList.toArray(new String[fieldList.size()]));
|
|
689 |
}
|
|
690 |
else {
|
|
691 |
it = getSource().getFeatureIterator(
|
|
692 |
viewPort.getAdjustedExtent(),
|
|
693 |
fieldList.toArray(new String[fieldList.size()]),
|
|
694 |
viewPort.getProjection(),
|
|
695 |
true);
|
|
696 |
}
|
|
879 | 697 |
|
880 | 698 |
// Iteration over each feature |
881 | 699 |
while ( !cancel.isCanceled() && it.hasNext()) { |
... | ... | |
885 | 703 |
// retreive the symbol associated to such feature |
886 | 704 |
ISymbol sym = legend.getSymbolByFeature(feat); |
887 | 705 |
if (sym == null) { |
888 |
continue;
|
|
889 |
}
|
|
706 |
continue;
|
|
707 |
}
|
|
890 | 708 |
if (useZSort) { |
891 |
int[] symLevels = zSort.getLevels(sym);
|
|
892 |
if(symLevels != null){
|
|
893 |
// Check if this symbol is a multilayer
|
|
894 |
if (sym instanceof IMultiLayerSymbol) {
|
|
895 |
// if so, get the layer corresponding to the current
|
|
896 |
// level. If none, continue to next iteration
|
|
897 |
IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym;
|
|
898 |
for (int i = 0; i < mlSym.getLayerCount(); i++) {
|
|
899 |
ISymbol mySym = mlSym.getLayer(i);
|
|
900 |
if (symLevels[i] == mapPass) {
|
|
901 |
sym = mySym;
|
|
902 |
break;
|
|
903 |
}
|
|
904 |
System.out.println("avoided layer "+i+"of symbol '"+mlSym.getDescription()+"' (pass "+mapPass+")");
|
|
905 |
}
|
|
906 |
} else {
|
|
907 |
// else, just draw the symbol in its level
|
|
908 |
if (symLevels[0] != mapPass) {
|
|
909 |
System.out.println("avoided single layer symbol '"+sym.getDescription()+"' (pass "+mapPass+")");
|
|
910 |
continue;
|
|
911 |
}
|
|
912 |
}
|
|
913 |
}
|
|
709 |
int[] symLevels = zSort.getLevels(sym);
|
|
710 |
if(symLevels != null){
|
|
711 |
// Check if this symbol is a multilayer
|
|
712 |
if (sym instanceof IMultiLayerSymbol) {
|
|
713 |
// if so, get the layer corresponding to the current
|
|
714 |
// level. If none, continue to next iteration
|
|
715 |
IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym;
|
|
716 |
for (int i = 0; i < mlSym.getLayerCount(); i++) {
|
|
717 |
ISymbol mySym = mlSym.getLayer(i);
|
|
718 |
if (symLevels[i] == mapPass) {
|
|
719 |
sym = mySym;
|
|
720 |
break;
|
|
721 |
}
|
|
722 |
System.out.println("avoided layer "+i+"of symbol '"+mlSym.getDescription()+"' (pass "+mapPass+")");
|
|
723 |
}
|
|
724 |
} else {
|
|
725 |
// else, just draw the symbol in its level
|
|
726 |
if (symLevels[0] != mapPass) {
|
|
727 |
System.out.println("avoided single layer symbol '"+sym.getDescription()+"' (pass "+mapPass+")");
|
|
728 |
continue;
|
|
729 |
}
|
|
730 |
}
|
|
731 |
}
|
|
914 | 732 |
} |
915 | 733 |
|
916 | 734 |
// Check if this symbol is sized with CartographicSupport |
... | ... | |
924 | 742 |
csSym = (CartographicSupport) sym; |
925 | 743 |
} |
926 | 744 |
|
927 |
// System.err.println("passada "+mapPass+" pinte s?mboll "+sym.getDescription());
|
|
745 |
//System.err.println("passada "+mapPass+" pinte s?mboll "+sym.getDescription());
|
|
928 | 746 |
|
929 | 747 |
if (csSym == null) { |
930 | 748 |
geom.drawInts(g, viewPort, sym, null); |
... | ... | |
946 | 764 |
|
947 | 765 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
948 | 766 |
double scale, PrintRequestAttributeSet properties) throws ReadDriverException { |
949 |
// if (forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD) { |
|
950 | 767 |
if (isVisible() && isWithinScale(scale)) { |
951 | 768 |
_print(g, viewPort, cancel, scale, properties); |
952 | 769 |
} |
953 |
// } else { |
|
954 |
//// moved up to Flayers |
|
955 |
//// if (isVisible() && isWithinScale(scale)) { |
|
956 |
// Strategy strategy = StrategyManager.getStrategy(this); |
|
957 |
// |
|
958 |
// strategy.print(g, viewPort, cancel, properties); |
|
959 |
// ILabelingStrategy labeling; |
|
960 |
// if ( (labeling = getLabelingStrategy() ) != null) { |
|
961 |
// // contains labels |
|
962 |
// labeling.print(g, viewPort, cancel, properties); |
|
963 |
// } |
|
964 |
//// } |
|
965 |
// } |
|
966 | 770 |
} |
967 | 771 |
|
968 | 772 |
public void deleteSpatialIndex() { |
... | ... | |
1045 | 849 |
//request for feature iteration based in spatial queries |
1046 | 850 |
source.setSpatialIndex(spatialIndex); |
1047 | 851 |
} catch (ReadDriverException e) { |
1048 |
// TODO Auto-generated catch block |
|
1049 | 852 |
e.printStackTrace(); |
1050 | 853 |
} |
1051 | 854 |
} |
... | ... | |
1341 | 1144 |
|
1342 | 1145 |
String recordsetName = xml.getStringProperty("recordset-name"); |
1343 | 1146 |
|
1344 |
// SelectableDataSource sds = new SelectableDataSource(LayerFactory |
|
1345 |
// .getDataSourceFactory().createRandomDataSource( |
|
1346 |
// recordsetName, DataSourceFactory.AUTOMATIC_OPENING)); |
|
1347 |
|
|
1348 | 1147 |
LayerFactory.getDataSourceFactory().changeDataSourceName( |
1349 | 1148 |
getSource().getRecordset().getName(), recordsetName); |
1350 | 1149 |
SelectableDataSource sds = new SelectableDataSource(LayerFactory |
... | ... | |
1971 | 1770 |
try { |
1972 | 1771 |
strategy.setLayer(this); |
1973 | 1772 |
} catch (ReadDriverException e) { |
1974 |
// TODO Auto-generated catch block |
|
1975 | 1773 |
e.printStackTrace(); |
1976 | 1774 |
} |
1977 | 1775 |
} |
... | ... | |
2024 | 1822 |
//return linkProperties.getLink(this) |
2025 | 1823 |
return linkProperties.getLink(this,point,tolerance); |
2026 | 1824 |
} |
2027 |
// /** |
|
2028 |
// * @deprecated Don?t use Strategy, you should be use iterators. |
|
2029 |
// */ |
|
2030 |
// public boolean isUseStrategy() { |
|
2031 |
// return useStrategy; |
|
2032 |
// } |
|
2033 |
// /** |
|
2034 |
// * @deprecated Don?t use Strategy, you should be use iterators. |
|
2035 |
// */ |
|
2036 |
// public void setUseStrategy(boolean useStrategy) { |
|
2037 |
// this.useStrategy = useStrategy; |
|
2038 |
// } |
|
2039 |
// |
|
2040 |
// @Override |
|
2041 |
// public void load() throws LoadLayerException { |
|
2042 |
// super.load(); |
|
2043 |
// useStrategy=forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD; |
|
2044 |
// } |
|
2045 | 1825 |
|
2046 | 1826 |
public void selectionChanged(SelectionEvent e) { |
2047 | 1827 |
this.updateDrawVersion(); |
Also available in: Unified diff