4 edited tags
| link
    Post Reopened by Karsten 7., bbgodfrey, Michael E2, m_goldberg, Kuba
3 corrected minor typo
source | link

I've created an application with the User Interface being a Graphic with lines, polygons etc. The functionality ifI need is:

I've created an application with the User Interface being a Graphic with lines, polygons etc. The functionality if need is:

I've created an application with the User Interface being a Graphic with lines, polygons etc. The functionality I need is:

2 added 3191 characters in body
source | link

I've created an application with the User Interface being a Graphic with lines, polygons etc. The idea was to click an object and trigger color changes and execution of various functions.functionality if need is:

  1. to be able to place the objects anywhere in {x,y} coords of the Graphic.
  2. to change the size of the object depending on how its used.
  3. to click each object and trigger color changes and execution of various functions.

The application works fine when there are only a few (say 20 objects) but noticeably slows as the number of objects increase. This makes me think the MouseClicked event triggers a Dynamic update on all objects in the graphicAny ideas why, and not justcan it be made more responsive?

Note in the onecode below the mouse. Is that correct? Or is there another reason the interfacePrint[] statement at line 91 inside the DynamicModule is so slowcurrently commented out, and performance is still poor, when its made active performance gets a lot worse .

function1[p_, scale_, state_] := 
Module[
  {body, ghost},
  {ax, by} = scale {1, 0.7};
  body = Polygon[
  {
  {-ax, -by} + p, {-ax, by} + p, {ax, -by} + 
  p, {ax, by} + p
  }];
  ghost = Rectangle[{-ax, -by} + p, {ax, by} + p];
  {
   FaceForm[state], 
   EdgeForm[Black], 
   body, 
   EdgeForm[None], 
   Opacity[0.], 
   ghost, 
   FaceForm[None]
   }
]

function2[p_, scale_, state_] := 
Module[
  {body, plug, ghost},
  {ax, by} = scale {1, 0.7};
  body = Polygon[
  {
  {-ax, -by} + p, {-ax, by} + p, {ax, -by} + 
  p, {ax, by} + p
  }];
  plug = Polygon[
  {
  {0, -by/2} + p, {-0.4, 0} + p, {0., by/2} + 
  p, {0.4, 0} + p, {0., -by/2} + p
  }];
  ghost = Rectangle[{-ax, -by} + p, {ax, by} + p];
  {
   FaceForm[state],  
   EdgeForm[Black], 
   body, 
   plug, 
   EdgeForm[None], 
   Opacity[0.], 
   ghost, 
   FaceForm[None]
  }
 ]

function3[p_, scale_] := Module[
  {actuator, stem},
  {ax, by} = scale {0.75, 0.75};
  actuator = 
  {
  FaceForm[None], EdgeForm[Black],
  Polygon[
     {
     {-ax, 1.5 by} + p, {ax, 1.5 by} + p, {ax, 3. by} + p, {-ax, 3. by} + p
     }],
    Line[{{-ax, 2.25 by} + p, {ax, 2.25 by} + p}]
  };
  stem = Line[{p, {0, 2.25 by} + p}];
  {actuator, stem}
  ]

function13[p_, scale_, rotation_, state_: White] := 
 Rotate[
    Flatten@{function3[p, scale], function1[p, scale, state]}, 
    rotation Degree, p
 ]

function23[p_, scale_, rotation_, state_: White] := 
 Rotate[
    Flatten@{function3[p, scale], function2[p, scale, state]}, 
    rotation Degree, p
 ]

myCol = Black;

list = Table[Null, {i, 1, 100}];

objectDynamic[valveType_, p_, scale_, orientation_ , ID_Integer] :=
  DynamicModule[
     {myCol = Black},
     EventHandler[
       Dynamic@valveType[p, scale, orientation, myCol],
       {
        "MouseDown" :> 
         (
          myCol = 
          myCol /. {Black -> Green, Green -> Red, Red -> Black}; 
          list[[ID]] = myCol; (*Print[p]*)
         )
        },
        Method -> "Queued", PassEventsDown -> False, PassEventsUp -> False
     ]
  ]

tableOfObjects = 
   Table[ 
     {
      objectDynamic[function13, {5 i , 5 j}, 1., 0. , 1  ],
      objectDynamic[function23, {5 i , 5 j + 10}, 1., 0. , 1  ]}, {i, 0, 9}, {j, 0, 4}];

CreateDocument[
   Dynamic[ 
      Graphics[
        Flatten@{
          Line[{{0, -5}, {0,0}, {4,0}, {4,4}, {8,4}, {12,4}, {12,0}}],
          tableOfObjects
        }, 
      Frame -> True, ImageSize -> {700, 500}], 
     SynchronousUpdating -> False
   ], 
   WindowSize -> {1600, 1000}
];

I've created an application with the User Interface being a Graphic with lines, polygons etc. The idea was to click an object and trigger color changes and execution of various functions. The application works fine when there are only a few (say 20 objects) but noticeably slows as the number of objects increase. This makes me think the MouseClicked event triggers a Dynamic update on all objects in the graphic and not just the one below the mouse. Is that correct? Or is there another reason the interface is so slow.

I've created an application with the User Interface being a Graphic with lines, polygons etc. The functionality if need is:

  1. to be able to place the objects anywhere in {x,y} coords of the Graphic.
  2. to change the size of the object depending on how its used.
  3. to click each object and trigger color changes and execution of various functions.

The application works fine when there are only a few (say 20 objects) but noticeably slows as the number of objects increase. Any ideas why, and can it be made more responsive?

Note in the code below that the Print[] statement at line 91 inside the DynamicModule is currently commented out, and performance is still poor, when its made active performance gets a lot worse .

function1[p_, scale_, state_] := 
Module[
  {body, ghost},
  {ax, by} = scale {1, 0.7};
  body = Polygon[
  {
  {-ax, -by} + p, {-ax, by} + p, {ax, -by} + 
  p, {ax, by} + p
  }];
  ghost = Rectangle[{-ax, -by} + p, {ax, by} + p];
  {
   FaceForm[state], 
   EdgeForm[Black], 
   body, 
   EdgeForm[None], 
   Opacity[0.], 
   ghost, 
   FaceForm[None]
   }
]

function2[p_, scale_, state_] := 
Module[
  {body, plug, ghost},
  {ax, by} = scale {1, 0.7};
  body = Polygon[
  {
  {-ax, -by} + p, {-ax, by} + p, {ax, -by} + 
  p, {ax, by} + p
  }];
  plug = Polygon[
  {
  {0, -by/2} + p, {-0.4, 0} + p, {0., by/2} + 
  p, {0.4, 0} + p, {0., -by/2} + p
  }];
  ghost = Rectangle[{-ax, -by} + p, {ax, by} + p];
  {
   FaceForm[state],  
   EdgeForm[Black], 
   body, 
   plug, 
   EdgeForm[None], 
   Opacity[0.], 
   ghost, 
   FaceForm[None]
  }
 ]

function3[p_, scale_] := Module[
  {actuator, stem},
  {ax, by} = scale {0.75, 0.75};
  actuator = 
  {
  FaceForm[None], EdgeForm[Black],
  Polygon[
     {
     {-ax, 1.5 by} + p, {ax, 1.5 by} + p, {ax, 3. by} + p, {-ax, 3. by} + p
     }],
    Line[{{-ax, 2.25 by} + p, {ax, 2.25 by} + p}]
  };
  stem = Line[{p, {0, 2.25 by} + p}];
  {actuator, stem}
  ]

function13[p_, scale_, rotation_, state_: White] := 
 Rotate[
    Flatten@{function3[p, scale], function1[p, scale, state]}, 
    rotation Degree, p
 ]

function23[p_, scale_, rotation_, state_: White] := 
 Rotate[
    Flatten@{function3[p, scale], function2[p, scale, state]}, 
    rotation Degree, p
 ]

myCol = Black;

list = Table[Null, {i, 1, 100}];

objectDynamic[valveType_, p_, scale_, orientation_ , ID_Integer] :=
  DynamicModule[
     {myCol = Black},
     EventHandler[
       Dynamic@valveType[p, scale, orientation, myCol],
       {
        "MouseDown" :> 
         (
          myCol = 
          myCol /. {Black -> Green, Green -> Red, Red -> Black}; 
          list[[ID]] = myCol; (*Print[p]*)
         )
        },
        Method -> "Queued", PassEventsDown -> False, PassEventsUp -> False
     ]
  ]

tableOfObjects = 
   Table[ 
     {
      objectDynamic[function13, {5 i , 5 j}, 1., 0. , 1  ],
      objectDynamic[function23, {5 i , 5 j + 10}, 1., 0. , 1  ]}, {i, 0, 9}, {j, 0, 4}];

CreateDocument[
   Dynamic[ 
      Graphics[
        Flatten@{
          Line[{{0, -5}, {0,0}, {4,0}, {4,4}, {8,4}, {12,4}, {12,0}}],
          tableOfObjects
        }, 
      Frame -> True, ImageSize -> {700, 500}], 
     SynchronousUpdating -> False
   ], 
   WindowSize -> {1600, 1000}
];
    Post Closed as "off-topic" by Kuba, user9660, MarcoB, kjo, m_goldberg
1
source | link