Changeset 21801 in osm


Ignore:
Timestamp:
2010-06-19T19:31:12+02:00 (14 years ago)
Author:
upliner
Message:

buildings_tools: implement wishlist by Komяpa

Location:
applications/editors/josm
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/buildings_tools/.settings/org.eclipse.jdt.core.prefs

    r21236 r21801  
    1 #Wed May 12 12:21:49 MSD 2010
     1#Sat Jun 19 21:24:56 MSD 2010
    22eclipse.preferences.version=1
    33org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
     
    243243org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
    244244org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
     245org.eclipse.jdt.core.formatter.join_lines_in_comments=true
     246org.eclipse.jdt.core.formatter.join_wrapped_lines=false
    245247org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
    246248org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
  • applications/editors/josm/plugins/buildings_tools/.settings/org.eclipse.jdt.ui.prefs

    r21236 r21801  
    1 #Wed May 12 12:21:49 MSD 2010
     1#Sat Jun 19 21:24:56 MSD 2010
    22eclipse.preferences.version=1
     3editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
    34formatter_profile=_BTProf
    45formatter_settings_version=11
    5 org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates/>
     6sp_cleanup.add_default_serial_version_id=true
     7sp_cleanup.add_generated_serial_version_id=false
     8sp_cleanup.add_missing_annotations=true
     9sp_cleanup.add_missing_deprecated_annotations=true
     10sp_cleanup.add_missing_methods=false
     11sp_cleanup.add_missing_nls_tags=false
     12sp_cleanup.add_missing_override_annotations=true
     13sp_cleanup.add_serial_version_id=false
     14sp_cleanup.always_use_blocks=true
     15sp_cleanup.always_use_parentheses_in_expressions=false
     16sp_cleanup.always_use_this_for_non_static_field_access=false
     17sp_cleanup.always_use_this_for_non_static_method_access=false
     18sp_cleanup.convert_to_enhanced_for_loop=false
     19sp_cleanup.correct_indentation=false
     20sp_cleanup.format_source_code=true
     21sp_cleanup.format_source_code_changes_only=false
     22sp_cleanup.make_local_variable_final=false
     23sp_cleanup.make_parameters_final=false
     24sp_cleanup.make_private_fields_final=true
     25sp_cleanup.make_type_abstract_if_missing_method=false
     26sp_cleanup.make_variable_declarations_final=true
     27sp_cleanup.never_use_blocks=false
     28sp_cleanup.never_use_parentheses_in_expressions=true
     29sp_cleanup.on_save_use_additional_actions=false
     30sp_cleanup.organize_imports=false
     31sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
     32sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
     33sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
     34sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
     35sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
     36sp_cleanup.remove_private_constructors=true
     37sp_cleanup.remove_trailing_whitespaces=false
     38sp_cleanup.remove_trailing_whitespaces_all=true
     39sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
     40sp_cleanup.remove_unnecessary_casts=true
     41sp_cleanup.remove_unnecessary_nls_tags=false
     42sp_cleanup.remove_unused_imports=false
     43sp_cleanup.remove_unused_local_variables=false
     44sp_cleanup.remove_unused_private_fields=true
     45sp_cleanup.remove_unused_private_members=false
     46sp_cleanup.remove_unused_private_methods=true
     47sp_cleanup.remove_unused_private_types=true
     48sp_cleanup.sort_members=false
     49sp_cleanup.sort_members_all=false
     50sp_cleanup.use_blocks=false
     51sp_cleanup.use_blocks_only_for_return_and_throw=false
     52sp_cleanup.use_parentheses_in_expressions=false
     53sp_cleanup.use_this_for_non_static_field_access=false
     54sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
     55sp_cleanup.use_this_for_non_static_method_access=false
     56sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
  • applications/editors/josm/plugins/buildings_tools/build.xml

    r21706 r21801  
    3333        <property name="commit.message" value="fix address dialog" />
    3434        <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    35         <property name="plugin.main.version" value="2830" />
     35        <property name="plugin.main.version" value="3177" />
    3636
    3737
     
    111111                                <attribute name="Plugin-Mainversion" value="${plugin.main.version}"/>
    112112                                <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/>
    113                                 <attribute name="2561_Plugin-Url" value="29;http://upliner.openstreetmap.ru/josm/buildings_tools/2561/buildings_tools.jar"/>
    114113                        </manifest>
    115114                </jar>
  • applications/editors/josm/plugins/buildings_tools/src/buildings_tools/Building.java

    r21702 r21801  
    2929        private EastNorth en3;
    3030        private EastNorth en4;
    31        
     31
    3232        private EastNorth p1;
    3333        private Node node;
    3434        double meter = 0;
    35        
     35
    3636        private double len = 0;
    37         private double lwidth;
     37        private double width;
    3838        private double heading;
    39         private boolean angconstrainted;
    40         private double angconstraint = 0;
    41        
     39        private boolean angConstrained;
     40        private double angConstraint = 0;
     41
    4242        public void disableAngConstraint() {
    43                 angconstrainted = false;
    44         }
     43                angConstrained = false;
     44        }
     45
    4546        public void setAngConstraint(double angle) {
    46                 angconstrainted = true;
    47                 angconstraint = angle;
    48                 while (angconstraint>(Math.PI/4)) angconstraint-=Math.PI/4;
    49         }
     47                angConstrained = true;
     48                angConstraint = angle;
     49        }
     50
    5051        public double getLength() {
    5152                return len;
    5253        }
    53        
     54
     55        public double getWidth() {
     56                return width;
     57        }
     58
     59        public boolean isRectDrawing() {
     60                return angConstrained && ToolSettings.getWidth() == 0 && ToolSettings.getLenStep() == 0;
     61        }
     62
    5463        public void reset() {
    5564                len = 0;
    56                 en1=null;
    57                 en2=null;
    58                 en3=null;
    59                 en4=null;
    60         }
    61         public EastNorth Point1() { return en1; }
    62         public EastNorth Point2() { return en2; }
    63         public EastNorth Point3() { return en3; }
    64         public EastNorth Point4() { return en4; }
     65                en1 = null;
     66                en2 = null;
     67                en3 = null;
     68                en4 = null;
     69        }
     70
     71        public EastNorth point1() {
     72                return en1;
     73        }
     74
     75        public EastNorth point2() {
     76                return en2;
     77        }
     78
     79        public EastNorth point3() {
     80                return en3;
     81        }
     82
     83        public EastNorth point4() {
     84                return en4;
     85        }
     86
    6587        private void updMetrics() {
    66                 meter = 2*Math.PI/(Math.cos(Math.toRadians(eastNorth2latlon(p1).lat())) * eqlen);
     88                meter = 2 * Math.PI / (Math.cos(Math.toRadians(eastNorth2latlon(p1).lat())) * eqlen);
    6789                reset();
    6890        }
     91
    6992        public void setBase(EastNorth base) {
    7093                node = null;
     
    7295                updMetrics();
    7396        }
     97
    7498        public void setBase(Node base) {
    7599                node = base;
     
    77101                updMetrics();
    78102        }
     103
     104        /**
     105         * @returns Projection of the point to the heading vector in metres
     106         */
     107        private double projection1(EastNorth p) {
     108                final EastNorth vec = p1.sub(p);
     109                return (Math.sin(heading) * vec.east() + Math.cos(heading) * vec.north()) / meter;
     110        }
     111
     112        /**
     113         * @returns Projection of the point to the perpendicular of the heading
     114         *          vector in metres
     115         */
     116        private double projection2(EastNorth p) {
     117                final EastNorth vec = p1.sub(p);
     118                return (Math.cos(heading) * vec.east() - Math.sin(heading) * vec.north()) / meter;
     119        }
     120
    79121        private void updatePos() {
     122                if (len == 0)
     123                        return;
    80124                en1 = p1;
    81                 en2 = new EastNorth(p1.east()+Math.sin(heading)*len*meter,p1.north()+Math.cos(heading)*len*meter);
    82                 en3 = new EastNorth(p1.east()+Math.sin(heading)*len*meter+Math.cos(heading)*lwidth*meter,p1.north()+Math.cos(heading)*len*meter-Math.sin(heading)*lwidth*meter);
    83                 en4 = new EastNorth(p1.east()+Math.cos(heading)*lwidth*meter,p1.north()-Math.sin(heading)*lwidth*meter);
    84         }
    85         public void setPlace(EastNorth p2,double width,double lenstep,boolean ignoreConstraint) {
    86                 heading = p1.heading(p2);
     125                en2 = new EastNorth(p1.east() + Math.sin(heading) * len * meter, p1.north() + Math.cos(heading) * len * meter);
     126                en3 = new EastNorth(p1.east() + Math.sin(heading) * len * meter + Math.cos(heading) * width * meter, p1.north()
     127                                + Math.cos(heading) * len * meter - Math.sin(heading) * width * meter);
     128                en4 = new EastNorth(p1.east() + Math.cos(heading) * width * meter, p1.north() - Math.sin(heading) * width
     129                                * meter);
     130        }
     131
     132        public void setLengthWidth(double length, double width) {
     133                this.len = length;
     134                this.width = width;
     135                updatePos();
     136        }
     137
     138        public void setWidth(EastNorth p3) {
     139                this.width = projection2(p3);
     140                updatePos();
     141        }
     142
     143        public void setPlace(EastNorth p2, double width, double lenstep, boolean ignoreConstraints) {
     144                this.heading = p1.heading(p2);
    87145                double hdang = 0;
    88                 if (angconstrainted && !ignoreConstraint) {
    89                         hdang = Math.round((heading-angconstraint)/Math.PI*4);
    90                         if (hdang>=8)hdang-=8;
    91                         if (hdang<0)hdang+=8;
    92                         heading = hdang*Math.PI/4+angconstraint;
    93                 }
    94                 double distance = eastNorth2latlon(p1).greatCircleDistance(eastNorth2latlon(p2));
    95                 if (lenstep <= 0) len=distance; else len = Math.round(distance/lenstep)*lenstep;
    96                 if (len == 0) return;
    97                 lwidth = width;
     146                if (angConstrained && !ignoreConstraints) {
     147                        hdang = Math.round((heading - angConstraint) / Math.PI * 4);
     148                        hdang = hdang % 8;
     149                        if (hdang < 0)
     150                                hdang += 8;
     151                        heading = (hdang * Math.PI / 4 + angConstraint) % (2 * Math.PI);
     152                }
     153
     154                this.width = width;
     155                this.len = projection1(p2);
     156                if (lenstep > 0 && !ignoreConstraints)
     157                        this.len = Math.round(this.len / lenstep) * lenstep;
     158
    98159                updatePos();
     160
    99161                Main.map.statusLine.setHeading(Math.toDegrees(heading));
    100                 if (angconstrainted && !ignoreConstraint) {
    101                         Main.map.statusLine.setAngle(hdang*45);
    102                 }
    103         }
    104         public void setWidth(double width) {
    105                 lwidth = width;
    106                 updatePos();
    107         }
     162                if (angConstrained && !ignoreConstraints) {
     163                        Main.map.statusLine.setAngle(hdang * 45);
     164                }
     165        }
     166
     167        public void setPlaceRect(EastNorth p2) {
     168                if (!isRectDrawing())
     169                        throw new IllegalStateException("Invalid drawing mode");
     170                heading = angConstraint;
     171                setLengthWidth(projection1(p2), projection2(p2));
     172                Main.map.statusLine.setHeading(Math.toDegrees(heading));
     173        }
     174
     175        public void angFix(EastNorth point) {
     176                EastNorth en3 = this.en3;
     177                heading = p1.heading(point);
     178                setLengthWidth(projection1(en3), projection2(en3));
     179                this.en3 = en3;
     180        }
     181
    108182        public void paint(Graphics2D g, MapView mv) {
    109                 if (len == 0) return;
     183                if (len == 0)
     184                        return;
    110185                GeneralPath b = new GeneralPath();
    111186                Point pp1 = mv.getPoint(eastNorth2latlon(en1));
     
    114189                Point pp4 = mv.getPoint(eastNorth2latlon(en3));
    115190
    116                 b.moveTo(pp1.x, pp1.y); b.lineTo(pp3.x, pp3.y);
    117                 b.lineTo(pp4.x, pp4.y); b.lineTo(pp2.x, pp2.y);
     191                b.moveTo(pp1.x, pp1.y);
     192                b.lineTo(pp3.x, pp3.y);
     193                b.lineTo(pp4.x, pp4.y);
     194                b.lineTo(pp2.x, pp2.y);
    118195                b.lineTo(pp1.x, pp1.y);
    119196                g.draw(b);
    120197        }
     198
    121199        public Way create() {
    122                 if (len == 0) return null;
     200                if (len == 0)
     201                        return null;
    123202                Node n1;
    124                 if (node==null)
     203                if (node == null)
    125204                        n1 = new Node(eastNorth2latlon(en1));
    126205                else
     
    129208                Node n3 = new Node(eastNorth2latlon(en3));
    130209                Node n4 = new Node(eastNorth2latlon(en4));
    131                 if (n1.getCoor().isOutSideWorld()||n2.getCoor().isOutSideWorld()||
    132                                 n3.getCoor().isOutSideWorld()||n4.getCoor().isOutSideWorld()) {
     210                if (n1.getCoor().isOutSideWorld() || n2.getCoor().isOutSideWorld() ||
     211                                n3.getCoor().isOutSideWorld() || n4.getCoor().isOutSideWorld()) {
    133212                        JOptionPane.showMessageDialog(Main.parent,
    134                                 tr("Cannot place building outside of the world."));
     213                                        tr("Cannot place building outside of the world."));
    135214                        return null;
    136215                }
    137216                Way w = new Way();
    138217                w.addNode(n1);
    139                 if (lwidth>=0) {
     218                if (projection1(en3) > 0) {
    140219                        w.addNode(n2);
    141220                        w.addNode(n3);
     
    147226                }
    148227                w.addNode(n1);
    149                 w.put("building", "yes");
     228                w.put("building", ToolSettings.getTag());
    150229                Collection<Command> cmds = new LinkedList<Command>();
    151                 if (node==null) cmds.add(new AddCommand(n1));
     230                if (node == null)
     231                        cmds.add(new AddCommand(n1));
    152232                cmds.add(new AddCommand(n2));
    153233                cmds.add(new AddCommand(n3));
  • applications/editors/josm/plugins/buildings_tools/src/buildings_tools/BuildingSizeAction.java

    r21236 r21801  
    1111@SuppressWarnings("serial")
    1212public class BuildingSizeAction extends JosmAction {
    13        
     13
    1414        public BuildingSizeAction() {
    15                 super(tr("Set buildings size"),"mapmode/building",tr("Set buildings size"),
     15                super(tr("Set buildings size"), "mapmode/building", tr("Set buildings size"),
    1616                                Shortcut.registerShortcut("edit:buildingsdialog",
    17                                         tr("Edit: {0}", tr("Set buildings size")),
    18                                         KeyEvent.VK_W, Shortcut.GROUP_EDIT,
    19                                         Shortcut.SHIFT_DEFAULT),
     17                                tr("Edit: {0}", tr("Set buildings size")),
     18                                KeyEvent.VK_W, Shortcut.GROUP_EDIT,
     19                                Shortcut.SHIFT_DEFAULT),
    2020                                true);
    2121        }
     22
    2223        public void actionPerformed(ActionEvent arg0) {
    2324                BuildingSizeDialog dlg = new BuildingSizeDialog();
    24                 int answer = dlg.getValue();
    25                 if (answer == 1) {
    26                         DrawBuildingAction.SetSizes(dlg.width(), dlg.lenstep());
    27                         DrawBuildingAction.SetAddrDialog(dlg.useAddr());
     25                if (dlg.getValue() == 1) {
     26                        ToolSettings.setSizes(dlg.width(), dlg.lenstep());
     27                        ToolSettings.setAddrDialog(dlg.useAddr());
    2828                }
    2929        }
    30 
    3130}
  • applications/editors/josm/plugins/buildings_tools/src/buildings_tools/BuildingSizeDialog.java

    r21236 r21801  
    55import java.awt.Component;
    66import java.awt.GridBagLayout;
     7import java.awt.event.ActionEvent;
     8import java.awt.event.ActionListener;
    79import java.text.NumberFormat;
    810import java.text.ParseException;
    911
     12import javax.swing.JButton;
    1013import javax.swing.JFormattedTextField;
    1114import javax.swing.JCheckBox;
     
    2124        private JFormattedTextField twidth = new JFormattedTextField(NumberFormat.getInstance());
    2225        private JFormattedTextField tlenstep = new JFormattedTextField(NumberFormat.getInstance());
    23         private JPanel panel = new JPanel(new GridBagLayout());
    2426        private JCheckBox caddr = new JCheckBox(tr("Use Address dialog"));
    25         private void addLabelled(String str, Component c) {
     27
     28        static void addLabelled(JPanel panel, String str, Component c) {
    2629                JLabel label = new JLabel(str);
    2730                panel.add(label, GBC.std());
     
    2932                panel.add(c, GBC.eol().fill(GBC.HORIZONTAL));
    3033        }
     34
    3135        public BuildingSizeDialog() {
    32                 super(Main.parent, tr("Set buildings size"), 
     36                super(Main.parent, tr("Set buildings size"),
    3337                                new String[] { tr("OK"), tr("Cancel") },
    3438                                true);
    35                 contentConstraints = GBC.eol().fill().insets(15,15,15,5);
    36                 setButtonIcons(new String[] {"ok.png", "cancel.png" });
    37                
    38                 addLabelled(tr("Buildings width:"),twidth);
    39                 addLabelled(tr("Length step:"),tlenstep);
    40                 twidth.setValue(DrawBuildingAction.getWidth());
    41                 tlenstep.setValue(DrawBuildingAction.getLenStep());
    42                 panel.add(caddr,GBC.eol().fill(GBC.HORIZONTAL));
     39                contentConstraints = GBC.eol().fill().insets(15, 15, 15, 5);
     40                setButtonIcons(new String[] { "ok.png", "cancel.png" });
     41
     42                final JPanel panel = new JPanel(new GridBagLayout());
     43                addLabelled(panel, tr("Buildings width:"), twidth);
     44                addLabelled(panel, tr("Length step:"), tlenstep);
     45                panel.add(caddr, GBC.eol().fill(GBC.HORIZONTAL));
     46
     47                twidth.setValue(ToolSettings.getWidth());
     48                tlenstep.setValue(ToolSettings.getLenStep());
     49                caddr.setSelected(ToolSettings.isUsingAddr());
     50
     51                JButton bAdv = new JButton(tr("Advanced..."));
     52                bAdv.addActionListener(new ActionListener() {
     53                        @Override
     54                        public void actionPerformed(ActionEvent arg0) {
     55                                AdvancedSettingsDialog dlg = new AdvancedSettingsDialog();
     56                                if (dlg.getValue() == 1) {
     57                                        ToolSettings.setTag(dlg.getTag());
     58                                        ToolSettings.setBBMode(dlg.isBBMode());
     59                                }
     60                        }
     61                });
     62                panel.add(bAdv, GBC.eol().insets(0, 5, 0, 0).anchor(GBC.EAST));
     63
    4364                setContent(panel);
    4465                setupDialog();
    4566                setVisible(true);
    4667        }
     68
    4769        public double width() {
    4870                try {
    4971                        return NumberFormat.getInstance().parse(twidth.getText()).doubleValue();
    50                 } catch (ParseException e) {                   
     72                } catch (ParseException e) {
    5173                        return 0;
    5274                }
    5375        }
     76
    5477        public double lenstep() {
    5578                try {
    5679                        return NumberFormat.getInstance().parse(tlenstep.getText()).doubleValue();
    57                 } catch (ParseException e) {                   
    58                   return 0;
     80                } catch (ParseException e) {
     81                        return 0;
    5982                }
    6083        }
     84
    6185        public boolean useAddr() {
    6286                return caddr.isSelected();
  • applications/editors/josm/plugins/buildings_tools/src/buildings_tools/DrawBuildingAction.java

    r21704 r21801  
    3838@SuppressWarnings("serial")
    3939public class DrawBuildingAction extends MapMode
    40 implements MapViewPaintable, AWTEventListener, SelectionChangedListener
    41 {
    42         enum Mode {None, Drawing, DrawingWidth}
     40implements MapViewPaintable, AWTEventListener, SelectionChangedListener {
     41        enum Mode {None, Drawing, DrawingWidth, DrawingAngFix}
    4342        final private Cursor cursorCrosshair;
    4443        final private Cursor cursorJoinNode;
    4544        private Cursor currCursor;
    4645       
    47         private static double width = 0;
    48         private static double lenstep = 0;
    49         private static boolean useAddr;
    50        
    5146        private Mode mode = Mode.None;
    52         private EastNorth p1,p2,p3;
     47        private Mode nextMode = Mode.None;
     48       
    5349        private Color selectedColor;
    5450        private Point mousePos;
    55        
    5651        private Point drawStartPos;
    5752       
    5853        Building building = new Building();
    5954       
    60         public static void SetAddrDialog(boolean _useAddr) {
    61                 useAddr = _useAddr;
    62         }
    63         public static void SetSizes(double newwidth,double newlenstep) {
    64                 width = newwidth;
    65                 lenstep = newlenstep;
    66         }
    67         public static double getWidth() {
    68                 return width;
    69         }
    70        
    71         public static double getLenStep() {
    72                 return lenstep;
    73         }
    7455        public DrawBuildingAction(MapFrame mapFrame) {
    7556                super(tr("Draw buildings"),"building",tr("Draw buildings"),
     
    136117                Main.map.mapView.addTemporaryLayer(this);
    137118                DataSet.selListeners.add(this);
    138                 UpdateConstraint(getCurrentDataSet().getSelected());
     119                updateConstraint(getCurrentDataSet().getSelected());
    139120                try {
    140121                        Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
     
    159140                if(Main.map == null || Main.map.mapView == null)
    160141                        return;
     142                Main.map.statusLine.setHeading(-1);
     143                Main.map.statusLine.setAngle(-1);
     144                building.reset();
    161145                Main.map.mapView.repaint();
     146                updateStatusLine();
    162147        }
    163148
     
    168153                        cancelDrawing();
    169154        }
    170 
    171         private void ProcessMouseEvent(MouseEvent e) {
     155       
     156        private EastNorth getPoint(MouseEvent e) {
     157                Node n;
     158                if (e.isControlDown()) {
     159                        n = null;
     160                } else {
     161                        n = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive.isUsablePredicate);
     162                }
     163                if (n == null) {
     164                        return latlon2eastNorth(Main.map.mapView.getLatLon(mousePos.x, mousePos.y));
     165                } else {
     166                        return latlon2eastNorth(n.getCoor());
     167                }
     168        }
     169       
     170        private Mode modeDrawing(MouseEvent e) {
     171                EastNorth p = getPoint(e);
     172                if (building.isRectDrawing() && (!e.isShiftDown() || ToolSettings.isBBMode())) {
     173                        building.setPlaceRect(p);
     174                        return e.isShiftDown() ? Mode.DrawingAngFix : Mode.None;
     175                } else {
     176                        building.setPlace(p, ToolSettings.getWidth(),
     177                                        ToolSettings.getLenStep(),e.isShiftDown());
     178                        Main.map.statusLine.setDist(building.getLength());
     179                        return this.nextMode = ToolSettings.getWidth() == 0? Mode.DrawingWidth : Mode.None;
     180                }
     181        }
     182
     183        private Mode modeDrawingWidth(MouseEvent e) {
     184                building.setWidth(getPoint(e));
     185                Main.map.statusLine.setDist(Math.abs(building.getWidth()));
     186                return Mode.None;
     187        }
     188
     189        private Mode modeDrawingAngFix(MouseEvent e) {
     190                building.angFix(getPoint(e));
     191                return Mode.None;
     192        }
     193
     194        private void processMouseEvent(MouseEvent e) {
    172195                mousePos = e.getPoint();
    173                 if (mode == Mode.None) return;
    174                 Node n;
     196                if (mode == Mode.None) {
     197                        nextMode = Mode.None;
     198                        return;
     199                }
     200
    175201                if (mode == Mode.Drawing) {
    176                         if (e.isControlDown()) {
    177                                 n = null;
    178                         } else {
    179                                 n = Main.map.mapView.getNearestNode(mousePos);
    180                         }
    181                         if (n == null) {
    182                                 p2 = latlon2eastNorth(Main.map.mapView.getLatLon(mousePos.x, mousePos.y));
    183                         } else {
    184                                 p2 = latlon2eastNorth(n.getCoor());
    185                         }
    186                         building.setPlace(p2, width, e.isShiftDown()?0:lenstep,e.isShiftDown());
    187                         Main.map.statusLine.setDist(building.getLength());
    188                         return;
    189                 }
    190                 if (mode == Mode.DrawingWidth) {
    191                         if (e.isControlDown()) {
    192                                 n = null;
    193                         } else {
    194                                 n = Main.map.mapView.getNearestNode(mousePos);
    195                         }
    196                         if (n == null) {
    197                                 p3 = latlon2eastNorth(Main.map.mapView.getLatLon(mousePos.x, mousePos.y));
    198                         } else {
    199                                 p3 = latlon2eastNorth(n.getCoor());
    200                         }
    201                         double mwidth =
    202                                 ((p3.east()-p2.east())*(p2.north()-p1.north())+
    203                                  (p3.north()-p2.north())*(p1.east()-p2.east()))
    204                                 /p1.distanceSq(p2) * building.getLength();
    205                        
    206                         building.setWidth(mwidth);
    207                         Main.map.statusLine.setDist(Math.abs(mwidth));                 
    208                         return;
    209                 }
    210         }
     202                        nextMode = modeDrawing(e);
     203                } else if (mode == Mode.DrawingWidth) {
     204                        nextMode = modeDrawingWidth(e);
     205                } else if (mode == Mode.DrawingAngFix) {
     206                        nextMode = modeDrawingAngFix(e);
     207                } else
     208                        throw new AssertionError("Invalid drawing mode");
     209        }
     210       
    211211        public void paint(Graphics2D g, MapView mv,Bounds bbox)
    212212        {
     
    228228                drawStartPos = mousePos;
    229229               
    230                 Node n = Main.map.mapView.getNearestNode(mousePos);
     230                Node n = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive.isUsablePredicate);
    231231                if (n == null) {
    232                         p1 = latlon2eastNorth(Main.map.mapView.getLatLon(mousePos.x, mousePos.y));
    233                         building.setBase(p1);
     232                        building.setBase(latlon2eastNorth(Main.map.mapView.getLatLon(mousePos.x, mousePos.y)));
    234233                } else {
    235                         p1 = latlon2eastNorth(n.getCoor());
    236234                        building.setBase(n);
    237235                }
     
    241239
    242240        private void drawingAdvance(MouseEvent e) {
    243                 ProcessMouseEvent(e);
    244                 if (building.getLength() > 0) {
    245                         if (width == 0 && mode == Mode.Drawing) {
    246                                 p2 = building.Point2();
    247                                 mode = Mode.DrawingWidth;
    248                                 updateStatusLine();
    249                                 return;
    250                         }
     241                processMouseEvent(e);
     242                if (this.mode != Mode.None && this.nextMode == Mode.None) {
     243                        drawingFinish();
     244                } else {
     245                        mode = this.nextMode;
     246                        updateStatusLine();
     247                }
     248        }
     249       
     250        private void drawingFinish() {
     251                if (building.getLength() != 0) {
    251252                        Way w = building.create();
    252                         if (w != null && useAddr)
     253                        if (w != null && ToolSettings.isUsingAddr())
    253254                                showAddrDialog(w);
    254255                }
    255                 Main.map.mapView.repaint();
    256                 mode = Mode.None;
    257                 Main.map.statusLine.setHeading(-1);
    258                 Main.map.statusLine.setAngle(-1);
    259                 building.reset();
    260                 updateStatusLine();
     256                cancelDrawing();
    261257        }
    262258
     
    270266
    271267        @Override public void mouseDragged(MouseEvent e) {
    272                 ProcessMouseEvent(e);
     268                processMouseEvent(e);
    273269                updCursor();
    274270                if (mode!=Mode.None) Main.map.mapView.repaint();
     
    283279                drawStartPos = null;
    284280
    285                 if ((mode == Mode.Drawing && dragged) || mode == Mode.DrawingWidth)
    286                         drawingAdvance(e);
     281                if (mode == Mode.Drawing && !dragged) return;
     282                if (mode == Mode.None) return;
     283
     284                drawingAdvance(e);
    287285        }
    288286       
    289287        private void updCursor() {
    290288                if (mousePos==null) return;
    291                 Node n = Main.map.mapView.getNearestNode(mousePos);
     289                Node n = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive.isUsablePredicate);
    292290                if (n != null) setCursor(cursorJoinNode); else setCursor(cursorCrosshair);
    293291
     
    295293        @Override public void mouseMoved(MouseEvent e) {
    296294                if(!Main.map.mapView.isActiveLayerDrawable()) return;
    297                 ProcessMouseEvent(e);
     295                processMouseEvent(e);
    298296                updCursor();
    299297                if (mode!=Mode.None) Main.map.mapView.repaint();
     
    301299
    302300        @Override public String getModeHelpText() {
    303                 if (mode==Mode.None) return tr("Point on the corner of building to start drawing");
    304                 if (mode==Mode.Drawing) return tr("Point on opposite end of building");
    305                 if (mode==Mode.DrawingWidth) return tr("Set width of building");
     301                if (mode==Mode.None) return tr("Point on the corner of the building to start drawing");
     302                if (mode==Mode.Drawing) return tr("Point on opposite end of the building");
     303                if (mode==Mode.DrawingWidth) return tr("Set width of the building");
    306304                return "";
    307305        }
     
    311309        }
    312310       
    313         public void UpdateConstraint(Collection<? extends OsmPrimitive> newSelection) {
     311        public void updateConstraint(Collection<? extends OsmPrimitive> newSelection) {
    314312                building.disableAngConstraint();
    315313                if (newSelection.size()!=2)return;
     
    323321       
    324322        public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    325                 UpdateConstraint(newSelection);
     323                updateConstraint(newSelection);
    326324        }
    327325}
Note: See TracChangeset for help on using the changeset viewer.