Group Abstract Group Abstract

Message Boards Message Boards

0
|
6.9K Views
|
7 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How to enable/disable locators independently in manipulate

Posted 11 years ago

I am trying to enable/disable locators inside Manipulate. However, when I try the following code, either both locators are disabled, or both are enabled.

Manipulate[Graphics[{Line[{p1, p2}]}], {{p1, {0, 0}}, Locator, Enabled -> move}, {{p2, {1, 1}}, Locator, Enabled -> ! move}, {move, {False, True}} ]

Is there any way to show locators so that when one of them is enabled, then the other is disabled? As with my previous posts, I need this to be done within the Manipulate. Any suggestions?

POSTED BY: Ferenc Beleznay
7 Replies
POSTED BY: David Reiss
Posted 11 years ago

Yes indeed, this is exactly what I needed. Thank you very much.

POSTED BY: Ferenc Beleznay

Here is an updated version which, I believe, works (note also that I updated the DynamicModule version in the previous poste since it was not quite correct and did not work). Note both the use of the Deployed -> True option so that the content of the Manipulate is not selectable and also adding a Dynamic around the Line graphics directive. In essence I am forcing the Manipulate to behave exactly like the DynamicModule in the earlier (edited) posting. My guess as to why your original Manipulate did not work properly is that it is trying to create internally a LocatorPane. However, the Enabled option to LocatorPane only applies to all of the locators at once: there is no fine-graned use of Enabled in the LocatorPane which can restrict it to a selected subset of the locators. A WRI developer can perhaps comment....

Manipulate[
 Graphics[{
   Locator[Dynamic[p1], Enabled -> move],
   Locator[Dynamic[p2], Enabled -> ! move],
   Dynamic@Line[{p1, p2}]},
  PlotRange -> 1.1,
  Background -> White],
 {{p1, {0, 0}}, ControlType -> None},
 {{p2, {1, 1}}, ControlType -> None},
 {{move, False}, {False, True}},
 Deployed -> True]
POSTED BY: David Reiss
Posted 11 years ago

Works perfectly, thank you very much. Ferenc

POSTED BY: Ferenc Beleznay
Posted 11 years ago
POSTED BY: Ferenc Beleznay
Posted 11 years ago

Thank you very much, these solutions show me directions. However, when I tried the second one, I ended up with an output, which I could edit. Clicking on the background or the line (and even on the locator point after changing the "move" setting), I get an orange frame. After this, I could resize the background, move the line sometimes without, sometimes with the control points. Is this because p1 and p2 are control variables without being controlled? I am new using Mathematica, I could not figure out what is happening here.

POSTED BY: Ferenc Beleznay

Though I am not sure why you are seeing the behavior in Manipulate that you indicate (it appears to be a bug but others should chime in) here is an example of an implementation using DynamicModule [I have updated this code from an earlier version which did not work properly]:

Deploy@DynamicModule[{p1 = {0, 0}, p2 = {1, 1}, move = False},
  Panel@Column[
    {Checkbox[Dynamic[move]],
     Graphics[
      {Locator[Dynamic[p1], Enabled -> Dynamic[move]],
       Locator[Dynamic[p2], Enabled -> Dynamic[! move]],
       Dynamic@Line[{p1, p2}]},
      PlotRange -> 1.1,
      Background -> White]}]]

And, if you want this to be within a Manipulate, you can do something like this:

Manipulate[

 Graphics[{
   Locator[Dynamic[p1], Enabled -> move],
   Locator[Dynamic[p2], Enabled -> ! move],
   Line[{p1, p2}]}, PlotRange -> 1.1, Background -> White],

 {{p1, {0, 0}}, ControlType -> None},
 {{p2, {1, 1}}, ControlType -> None},
 {{move, False}, {False, True}}]
POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard