Modify

Opened 13 years ago

Closed 12 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 12 years ago.
AngleSnappingv2.patch (22.5 KB ) - added by akks 12 years ago.
sample.JPG (16.1 KB ) - added by akks 12 years ago.
helperline.png (2.8 KB ) - added by simon04 12 years ago.
ParallelWay.png (20.4 KB ) - added by akks 12 years ago.
segment snapping demo
AngleSnappingv3.patch (26.9 KB ) - added by akks 12 years ago.
DrawAction.patch (2.8 KB ) - added by akks 12 years ago.
snapbutton.patch (11.6 KB ) - added by akks 12 years ago.
anglesnap.png (538 bytes ) - added by akks 12 years ago.

Download all attachments as: .zip

Change History (48)

comment:1 by simon04, 13 years ago

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

comment:2 by Cobra, 13 years ago

Type: defectenhancement

comment:3 by akks, 12 years ago

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 12 years ago by akks (previous) (diff)

by akks, 12 years ago

Attachment: AngleSnapping.patch added

comment:4 by akks, 12 years ago

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 by stoecker, 12 years ago

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

in reply to:  5 comment:6 by bastiK, 12 years ago

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 by akks, 12 years ago

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 by akks, 12 years ago

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

comment:9 by stoecker, 12 years ago

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

in reply to:  9 comment:10 by stoecker, 12 years ago

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 by akks, 12 years ago

Merry Christmas :-)

by akks, 12 years ago

Attachment: AngleSnappingv2.patch added

comment:12 by akks, 12 years ago

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 :)

by akks, 12 years ago

Attachment: sample.JPG added

comment:13 by akks, 12 years ago


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

by simon04, 12 years ago

Attachment: helperline.png added

comment:14 by simon04, 12 years ago

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 by Cobra, 12 years ago

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

comment:16 by stoecker, 12 years ago

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 by akks, 12 years ago

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)

in reply to:  17 comment:18 by simon04, 12 years ago

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 by akks, 12 years ago

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.

by akks, 12 years ago

Attachment: ParallelWay.png added

segment snapping demo

by akks, 12 years ago

Attachment: AngleSnappingv3.patch added

comment:20 by akks, 12 years ago

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 12 years ago by akks (previous) (diff)

comment:21 by stoecker, 12 years ago

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.

in reply to:  21 comment:22 by akks, 12 years ago

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 by akks, 12 years ago

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 12 years ago by akks (previous) (diff)

comment:24 by akks, 12 years ago

In [4768/josm]:

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

comment:25 by bastiK, 12 years ago

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 by akks, 12 years ago

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

in reply to:  26 comment:27 by simon04, 12 years ago

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 by akks, 12 years ago

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?

by akks, 12 years ago

Attachment: DrawAction.patch added

comment:29 by akks, 12 years ago

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 12 years ago by akks (previous) (diff)

by akks, 12 years ago

Attachment: snapbutton.patch added

by akks, 12 years ago

Attachment: anglesnap.png added

comment:30 by akks, 12 years ago

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

I have also added advanced prefernces "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?

Version 0, edited 12 years ago by akks (next)

comment:31 by akks, 12 years ago

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 by bastiK, 12 years ago

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 by akks, 12 years ago

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 by akks, 12 years ago

In [4782/josm]:

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

comment:35 by akks, 12 years ago

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 by akks, 12 years ago

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 12 years ago by akks (previous) (diff)

comment:37 by simon04, 12 years ago

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

comment:38 by akks, 12 years ago

In [4803/josm]:

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

comment:39 by simon04, 12 years ago

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. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.