Modify

Opened 8 years ago

Closed 7 years ago

#6694 closed enhancement (fixed)

Key combination to draw lines on multiples of 15 degrees (15°/30°/45°/60°/75°/90°...)

Reported by: anonymous Owned by: team
Priority: normal Milestone:
Component: Core Version:
Keywords: Cc:

Description (last modified by akks)

Could you add a key combination or modifier (Alt + Shift?) to the Draw nodes (A) tool that allows you draw only new segments that are X degrees apart from the previous segment, where X is a multiple of 15?

This would allow the creation of geometrically precise areas in an easy way. Such functionality is available on all the vector graphics applications: Inkscape, Blender, Gimp (in its vector parts), ecc.

Attachments (9)

AngleSnapping.patch (18.7 KB) - added by akks 7 years ago.
AngleSnappingv2.patch (22.5 KB) - added by akks 7 years ago.
sample.JPG (16.1 KB) - added by akks 7 years ago.
helperline.png (2.8 KB) - added by simon04 7 years ago.
ParallelWay.png (20.4 KB) - added by akks 7 years ago.
segment snapping demo
AngleSnappingv3.patch (26.9 KB) - added by akks 7 years ago.
DrawAction.patch (2.8 KB) - added by akks 7 years ago.
snapbutton.patch (11.6 KB) - added by akks 7 years ago.
anglesnap.png (538 bytes) - added by akks 7 years ago.

Download all attachments as: .zip

Change History (48)

comment:1 Changed 8 years ago by simon04

A similar feature is implemented in the plugin buildings_tools (cf. AngleSnap).

comment:2 Changed 8 years ago by Cobra

Type: defectenhancement

comment:3 Changed 7 years ago by akks

Description: modified (diff)

Here is the patch I made. Please have a look at it when you have time.
Patch is looking rather messy because of moving large fragments of code to different lines.

The code of DrawAction is huge and very complex. I tried not to affect its general behaviour, only extracted some code fragments into separate function.

SnapHelper is the new inner class which manages angle snapping.

Angle Snapping is activated by pressing TAB button while in drawing mode currently.

Last edited 7 years ago by akks (previous) (diff)

Changed 7 years ago by akks

Attachment: AngleSnapping.patch added

comment:4 Changed 7 years ago by akks

Summary: Key combination to draw lines on multiples of 15 degrees (15°/30°/45°/60°/75°/90°...)[PATCH] Key combination to draw lines on multiples of 15 degrees (15°/30°/45°/60°/75°/90°...)

comment:5 Changed 7 years ago by stoecker

No additional classes in one source file please. It must be in an own class file somewhere (utils maybe or gui, ...)

comment:6 in reply to:  5 Changed 7 years ago by bastiK

Replying to stoecker:

No additional classes in one source file please. It must be in an own class file somewhere (utils maybe or gui, ...)

We have lots of inner classes in lots of source files. Question is: Can this be used somewhere else?

comment:7 Changed 7 years ago by akks

In current state SnapHelper can not be used anywhere else, because it use some fields from outer class. Is it possible that someone will need such specific functionality?

comment:8 Changed 7 years ago by akks

If we really need to move it to separate file, some data in DrawAction needs to be opened, which is not good...

comment:9 Changed 7 years ago by stoecker

If it is needed nowhere else, then it should be a subclass, not an individua lclass.

comment:10 in reply to:  9 Changed 7 years ago by stoecker

Replying to stoecker:

If it is needed nowhere else, then it should be a subclass, not an individua lclass.

Sorry. It already is. Maybe I should not answer tickets early in the morning on Christmas :-) Forget the comment.

comment:11 Changed 7 years ago by akks

Merry Christmas :-)

Changed 7 years ago by akks

Attachment: AngleSnappingv2.patch added

comment:12 Changed 7 years ago by akks

Here is an updated version of the patch (there hould be much less bugs).
Pressing Tab in drawing mode, user can switch between no snapping - automatic snapping - fixed direction snapping.

Parameters draw.anglesnap.step and draw.anglesnap.tol are introduced to chosse 90,30,15,... degrees step and angle tolerance.

I think it is better to wait for some comments before commiting this patch :)

Changed 7 years ago by akks

Attachment: sample.JPG added

comment:13 Changed 7 years ago by akks


Last edited 7 years ago by akks (previous) (diff)

Changed 7 years ago by simon04

Attachment: helperline.png added

comment:14 Changed 7 years ago by simon04

Replying to akks:

I think it is better to wait for some comments before commiting this patch :)

Wow, this patch works nicely. Some comments:

  1. I'd call the parameter draw.anglesnap.tolerance to make its meaning clearer
  2. The orange color of the helper line is (afaik) not used anywhere else. I like the appearance of the helper lines of the Improve Way Accuracy plugin.
  3. In fact, the result after drawing one segment in the snap mode corresponds to the segment on the orange line from the current node to the circle. Thus, it would probably be more intuitive to interchange red and orange (see below for an illustration).
  4. After drawing a segment in the "fixed mode", the angle is then 0 and the mode remains fixed. Is this intended? I mean, it is probably not very common to extend a line with a straight segment.
  5. When fixing the drawing mode to a wrong angle, it requires three presses on [Tab] to fix it for a different angle. I don't know of any better way, though.
  6. It could be handy to have draw.anglesnap.step set to 30 and 45° at the same time to cover the most used cases (this is a proposition), without having snap angles at e.g. 15°. To support this, you could allow a list of angles. For the example, [30,45] would do it.

As said before, I like this patch a lot and it seems to be working very well. I'd like to hear your opinion on the points above.


This image illustrates my idea for 2.+3. (the line node–cursor could probably be omitted completely, the remaining orange circle and text should be considered to be red as well):


comment:15 Changed 7 years ago by Cobra

Switching back to the last angle could be done by pressing shift-tab.

comment:16 Changed 7 years ago by stoecker

Two comments after short reading. At least one label text is not translated (%d FIX) and the color should not be hardcoded, but a preferences item as all other colors.

comment:17 Changed 7 years ago by akks

Thank you for your comments! I'll rework coloring, preferences and introduce angle list and translation.

Swicthing modes could be tricky. There are some questions to discuss:

When you add one node in "fixed angle" mode, would you like to

  1. Turn off snapping
  2. Enable automatic snapping (without fixing)
  3. Enable snapping to the same line (0'), like now
  4. Enable snapping to the same angle (rotating after each click...)

Possible switching mechanisms:

  1. Tab = Snapping on/off, Shift-Tab = Fixed/unfixed angle
  2. Tab = off -> on(auto angle) -> fixed angle , Shift-Tab = off
  3. Tab = off -> on(auto angle) -> fixed angle , Shift-Tab = on(auto angle)

comment:18 in reply to:  17 Changed 7 years ago by simon04

Replying to akks:

When you add one node in "fixed angle" mode, would you like to

  1. Turn off snapping
  2. Enable automatic snapping (without fixing)
  3. Enable snapping to the same line (0'), like now
  4. Enable snapping to the same angle (rotating after each click...)

I would either like item 2. or item 4. As it is easier to switch from snapping w/o fix to snapping w/ fix, I'd suggest item 2.

Possible switching mechanisms:

  1. Tab = Snapping on/off, Shift-Tab = Fixed/unfixed angle
  2. Tab = off -> on(auto angle) -> fixed angle , Shift-Tab = off
  3. Tab = off -> on(auto angle) -> fixed angle , Shift-Tab = on(auto angle)

I'd stick with the current key bindings (only [Tab], no [Shift]+[Tab]) for the following reason: [Shift]+[Tab] as well as [Tab],[Tab] involves pressing of two keys, respectively, and it is probably easier to switch through all modes with a single key as the user needs to know/remember only a single key.

Nice work – I'm looking forward to seeing this feature being part of JOSM. :-)

comment:19 Changed 7 years ago by akks

After node addition - I choose 2 too, implementing...

It's almost finished...

By the way, I can implement fixing angle while holding [TAB] (have found such code for FastDraw, linux-compatible too), but do not know if is it a good idea.

Changed 7 years ago by akks

Attachment: ParallelWay.png added

segment snapping demo

Changed 7 years ago by akks

Attachment: AngleSnappingv3.patch added

comment:20 Changed 7 years ago by akks

Next verison of the patch is ready. Changes:

  1. Renamed parameter to draw.anglesnap.tolerance
  2. Snap helper line is like in ImproveWayAccuracy, color is in parameter draw.anglesnap.color
  3. Better, more understandable drawing
  4. Fixed angle mode is disabled after addin one point.
  5. Snapping angles are stored in the list draw.anglesnap.angles, angleStep removed.
  6. Translation for "FIX" is enabled.

I did not introduce Shift-TAB or hodling TAB, but there is another new feature:
try RIGHT-clicking any existing line segment while in snap mode :) (it was easy to implement with existing code)

segment snapping demo

What should we do next?

Last edited 7 years ago by akks (previous) (diff)

comment:21 Changed 7 years ago by stoecker

A minor issue: Use color like Main.pref.getColor(marktr("draw angle snap"), Color.ORANGE)). Colors are a bit special, as they are presented to user :-) The resulting key will then be color.draw.angle.snap.

comment:22 in reply to:  21 Changed 7 years ago by akks

Replying to stoecker:

A minor issue: Use color like Main.pref.getColor(marktr("draw angle snap"), Color.ORANGE)). Colors are a bit special, as they are presented to user :-) The resulting key will then be color.draw.angle.snap.

No problem :-)

comment:23 Changed 7 years ago by akks

Preference name is improved, some bugs (like dragging problems and creating duplicate point when closing rectangle) fixed, snapping is changed to 30-45-60-90 by default. I can not find anything else myself.

To have more bugs and enchantment advices, I am committing the changes :)

Last edited 7 years ago by akks (previous) (diff)

comment:24 Changed 7 years ago by akks

In [4768/josm]:

Add aligned segments by TAB and right-clicks in drawing mode, see #6694

comment:25 Changed 7 years ago by bastiK

Lacking mode specific toolbars, I would suggest a checkbox menu entry "Angle snapping" in Edit menu. It could be disabled, when not in edit mode.

comment:26 Changed 7 years ago by akks

Good idea, thank you. At least people will notice something new :)

comment:27 in reply to:  26 Changed 7 years ago by simon04

Summary: [PATCH] Key combination to draw lines on multiples of 15 degrees (15°/30°/45°/60°/75°/90°...)Key combination to draw lines on multiples of 15 degrees (15°/30°/45°/60°/75°/90°...)

Replying to akks:

Good idea, thank you. At least people will notice something new :)

They should also find out via StartupPageSource. :-)

comment:28 Changed 7 years ago by akks

Oops, they have already noticed us :)

Here is the patch for menu item "angle snap". It seems to work, but I do not know, how to make it "checkboxy" and enable/disable together with drawing mapmode... Can someone help, please?

Changed 7 years ago by akks

Attachment: DrawAction.patch added

comment:29 Changed 7 years ago by akks

I have almost figured it, but JosmAction does not like "tab" shortcut at all. Maybe it is better to use "H" for turning snap on/off?

But then what to do with TAB - 1) leave as is; 2) use for angle fixation only; 3) use for fixation while holding.

What is your opinion?

Last edited 7 years ago by akks (previous) (diff)

Changed 7 years ago by akks

Attachment: snapbutton.patch added

Changed 7 years ago by akks

Attachment: anglesnap.png added

comment:30 Changed 7 years ago by akks

Here is the patch with checkbox in menu and "H" shortcut for it, TAB behaviour unchanged.

I have also added advanced preferences "draw.anglesnap.drawConstructionGeometry", "draw.anglesnap.drawProjectedPoint" "draw.anglesnap.showAngle" that users who prefer minimalistic style can turn off.

Can you advice me, what is better to do with shortcuts and behaviour before commiting?

Last edited 7 years ago by akks (previous) (diff)

comment:31 Changed 7 years ago by akks

Summary: Key combination to draw lines on multiples of 15 degrees (15°/30°/45°/60°/75°/90°...)[PATCH needs review] Key combination to draw lines on multiples of 15 degrees (15°/30°/45°/60°/75°/90°...)

comment:32 Changed 7 years ago by bastiK

When in doubt, I would keep the "tab" shortcut as is and don't display anything at all for the menu entry (set null for the JosmAction). Ideally, this should be fixed, such that "tab" works the same way as "H" as menu shortcut.

comment:33 Changed 7 years ago by akks

So, the best is to remove "H" from menu and use tab to switch on-off?
Then we need something else for fixation of angle.
I will use tab holding then (this will also stop fast autoswitching when holding TAB).

Only disadvantage is that we can not change the hardcoded TAB shortcut.

comment:34 Changed 7 years ago by akks

In [4782/josm]:

Angle snapping shown in Edit menu, holding TAB fixes the angle etc. - see #6694

comment:35 Changed 7 years ago by akks

Summary: [PATCH needs review] Key combination to draw lines on multiples of 15 degrees (15°/30°/45°/60°/75°/90°...)Key combination to draw lines on multiples of 15 degrees (15°/30°/45°/60°/75°/90°...)

Next version commited - menu item (checkbox) for angle snapping, holding TAB fixes the angle before turning it off, advanced preferences "draw.anglesnap.drawConstructionGeometry", "draw.anglesnap.drawProjectedPoint" "draw.anglesnap.showAngle".

Possible regression: TAB does not work ags general GUI shortcut while drawing mode is active - is it important? If it is, TAB should be changed.

If I am right, final step should be configuration from GUI - angle list with 90 45 and 30/45 presetts, checkboxes for displaying options in expert mode. Where is the the best place for it in F12 window?

comment:36 Changed 7 years ago by akks

Problem with TAB reported in #7250 , regression fixed in r4775 but now Tab acts as button-switcher and snapmode-switcher simultaneously.
I can not determine the moments when Tab should switch modes (MapView is not focused when drawing)...

Last edited 7 years ago by akks (previous) (diff)

comment:37 Changed 7 years ago by simon04

Ticket #5164 has been marked as a duplicate of this ticket.

comment:38 Changed 7 years ago by akks

In [4803/josm]:

Context menu for "Angle" status panel (Angle snap configuration), see #7260, #6694

comment:39 Changed 7 years ago by simon04

Resolution: fixed
Status: newclosed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.