Ignore:
Timestamp:
2010-11-13T15:12:19+01:00 (14 years ago)
Author:
extropy
Message:

Pdfimport: more options, fixed merge close nodes regression.

Location:
applications/editors/josm/plugins/pdfimport/src/pdfimport
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pdfimport/src/pdfimport/LoadPdfDialog.java

    r24191 r24214  
    134134        private JCheckBox limitPathCountCheck;
    135135        private JTextField limitPathCount;
     136        private JCheckBox splitOnColorChangeCheck;
     137        private JCheckBox splitOnShapeClosedCheck;
     138        private JCheckBox splitOnSingleSegmentCheck;
    136139
    137140
     
    247250                this.limitPathCountCheck = new JCheckBox(tr("Take only first X paths"));
    248251                this.limitPathCount = new JTextField("10000");
     252
     253                this.splitOnColorChangeCheck = new JCheckBox(tr("Color/width change"));
     254                this.splitOnShapeClosedCheck = new JCheckBox(tr("Shape closed"));
     255                this.splitOnSingleSegmentCheck = new JCheckBox(tr("Single segments"));
    249256
    250257                JPanel configPanel = new JPanel(new GridBagLayout());
     
    293300
    294301
    295                 JPanel selectFilePanel = new JPanel(new GridBagLayout());
    296                 selectFilePanel.setBorder(BorderFactory.createTitledBorder(tr("Load file")));
    297                 c.gridx = 0; c.gridy = 0; c.gridwidth = 1;
    298                 selectFilePanel.add(this.loadFileButton, c);
     302                c.gridx = 0; c.gridy = 7; c.gridwidth = 1;
     303                configPanel.add(new JLabel(tr("Introduce separate layers for:")), c);
     304                c.gridx = 1; c.gridy = 7; c.gridwidth = 1;
     305                configPanel.add(this.splitOnShapeClosedCheck, c);
     306                c.gridx = 2; c.gridy = 7; c.gridwidth = 1;
     307                configPanel.add(this.splitOnSingleSegmentCheck, c);
     308                c.gridx = 1; c.gridy = 8; c.gridwidth = 1;
     309                configPanel.add(this.splitOnColorChangeCheck, c);
     310
    299311
    300312                JPanel projectionPanel = new JPanel(new GridBagLayout());
     
    353365                panel.add(configPanel, c);
    354366                c.gridx = 0; c.gridy = 1; c.gridwidth = 1;
    355                 panel.add(selectFilePanel, c);
     367                panel.add(loadFileButton, c);
    356368                c.gridx = 0; c.gridy = 2; c.gridwidth = 1;
    357369                panel.add(projectionPanel, c);
     
    552564                fc.setAcceptAllFileFilterUsed(false);
    553565                fc.setMultiSelectionEnabled(false);
     566                fc.setSelectedFile(this.fileName);
    554567                fc.setFileFilter(new FileFilter(){
    555568                        @Override
     
    671684                monitor.setCustomText(tr("Parsing file"));
    672685
    673                 PathOptimizer data = new PathOptimizer(nodesTolerance, color);
     686                PathOptimizer data = new PathOptimizer(nodesTolerance, color, this.splitOnColorChangeCheck.isSelected());
    674687
    675688                try {
     
    709722                }
    710723
     724                if (nodesTolerance > 0.0) {
     725                        monitor.setTicks(83);
     726                        monitor.setCustomText(tr("Joining nodes"));
     727                        data.mergeNodes();
     728                }
     729
    711730                monitor.setTicks(85);
    712731                monitor.setCustomText(tr("Joining adjacent segments"));
     
    748767                monitor.setTicks(95);
    749768                monitor.setCustomText(tr("Finalizing layers"));
    750                 data.splitLayersByPathKind();
     769                data.splitLayersByPathKind(this.splitOnShapeClosedCheck.isSelected(), this.splitOnSingleSegmentCheck.isSelected());
    751770                data.finish();
    752771
  • applications/editors/josm/plugins/pdfimport/src/pdfimport/OsmBuilder.java

    r24189 r24214  
    122122        private Way insertWay(PdfPath path, Map<Point2D, Node> point2Node, int multipathId, boolean multipolygon) {
    123123
    124                 monitor.setExtraText(tr(" "+this.monitorPos+"/"+this.monitorTotal));
    125                 monitor.setTicks(this.monitorPos);
     124                if (this.monitorPos % 100 == 0) {
     125                        monitor.setExtraText(tr(" "+this.monitorPos+"/"+this.monitorTotal));
     126                        monitor.setTicks(this.monitorPos);
     127                }
    126128                this.monitorPos ++;
    127129
     
    185187                }
    186188
    187                 String s = Integer.toHexString(col.getRGB());
     189                String s = Integer.toHexString(col.getRGB() & 0xffffff);
    188190                while (s.length() < 6) {
    189191                        s = "0" + s;
  • applications/editors/josm/plugins/pdfimport/src/pdfimport/PathOptimizer.java

    r24189 r24214  
    2121        private final double pointsTolerance;
    2222        private final Color color;
    23 
    24         public PathOptimizer(double _pointsTolerance, Color _color)
     23        boolean splitOnColorChange;
     24
     25        LayerContents prevLayer = null;
     26
     27        public PathOptimizer(double _pointsTolerance, Color _color, boolean _splitOnColorChange)
    2528        {
    26 
    2729                uniquePointMap = new HashMap<Point2D, Point2D>();
    2830                uniquePoints = new ArrayList<Point2D>();
     
    3133                pointsTolerance = _pointsTolerance;
    3234                color = _color;
     35                splitOnColorChange = _splitOnColorChange;
    3336        }
    3437
     
    161164        }
    162165
    163         public void splitLayersByPathKind() {
     166        public void splitLayersByPathKind(boolean closed, boolean single) {
    164167                List<LayerContents> newLayers = new ArrayList<LayerContents>();
    165168                for(LayerContents l: this.layers) {
    166                         List<LayerContents> splitResult = splitBySegmentKind(l);
     169                        List<LayerContents> splitResult = splitBySegmentKind(l, closed, single);
    167170
    168171                        for(LayerContents ll: splitResult) {
     
    186189
    187190        private LayerContents getLayer(LayerInfo info) {
    188                 LayerContents layer;
     191
     192                LayerContents layer = null;
    189193
    190194                if (this.layerMap.containsKey(info))
    191195                {
    192196                        layer = this.layerMap.get(info);
    193                 }
    194                 else
     197
     198                        if (layer != this.prevLayer && this.splitOnColorChange) {
     199                                layer = null;
     200                        }
     201                }
     202
     203                if (layer == null)
    195204                {
    196205                        layer = new LayerContents();
     
    201210                }
    202211
     212                this.prevLayer = layer;
    203213                return layer;
    204214        }
     
    573583        }
    574584
    575         private List<LayerContents> splitBySegmentKind(LayerContents layer)
     585        private List<LayerContents> splitBySegmentKind(LayerContents layer, boolean closed, boolean single)
    576586        {
     587                if (!closed && !single) {
     588                        return Collections.singletonList(layer);
     589                }
     590
    577591                List<PdfPath> singleSegmentPaths = new ArrayList<PdfPath>();
    578592                List<PdfPath> multiSegmentPaths = new ArrayList<PdfPath>();
     
    580594
    581595                for(PdfPath path: layer.paths) {
    582                         if (path.points.size() <= 3) {
     596                        if (path.points.size() <= 3 && single) {
    583597                                singleSegmentPaths.add(path);
    584598                        }
    585                         else if (path.isClosed()) {
     599                        else if (!path.isClosed() && closed) {
     600                                multiSegmentPaths.add(path);
     601                        }
     602                        else {
    586603                                closedPaths.add(path);
    587                         }
    588                         else {
    589                                 multiSegmentPaths.add(path);
    590604                        }
    591605                }
  • applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/GraphicsProcessor.java

    r24191 r24214  
    4848        private void addPath(Shape s, boolean closed) {
    4949                pathNo ++;
    50                 this.monitor.setCustomText(tr(" {0} objects so far", pathNo));
     50
     51                if (pathNo % 100 == 0) {
     52                        this.monitor.setCustomText(tr(" {0} objects so far", pathNo));
     53                }
    5154
    5255                if (pathNo >= maxPaths) {
Note: See TracChangeset for help on using the changeset viewer.