• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Undo stack question

Scheduled Pinned Locked Moved Developers' Forum
6 Posts 2 Posters 276 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    joshb
    last edited by 17 Nov 2011, 20:17

    I've implemented a plugin that does custom coloring of the model based on user defined attributes. When my plugin is active, I want to let the user explore the model but not change anything. Right now I'm launching my web dialog using show and not show_modal to keep the navigation tools available. To undo my custom coloring, I'm using transactions. I do a start_operation when my plugin loads and an abort_operations when it closes.

    Now the problem that has come up, is that if I do anything that modifies the undo stack while my plugin is active, then when I call abort_operation, the model doesn't properly reset since one of the intermediate operations has probably already commited the transaction.

    I'm trying to solve this right now by implementing a model observer and watching the onTransactionStart, Abort, Commit, Empty methods to see if I can make any sense of that. Right now I've just implemented counters to see how many times the various events are firing and there doesnt seem to be a 1-1 correlation with the undo stack... I'm seeing way more start/commit events than things on the Undo stack.

    Does anyone have any tips on how to solve this the right way?

    Thanks,
    Josh

    1 Reply Last reply Reply Quote 0
    • D Offline
      Dan Rathbun
      last edited by 18 Nov 2011, 01:23

      Firstly: a Transaction does not equal an Operation.

      An Operation can have many Transactions.

      In another thread we discussed the need for observers that fire for the Operation as a whole. (There are no such observers at this time.)

      I would suggest abandoning your transaction observer modus, and switch your plugin code to a Tool class. When your tool is active, the user can still use any of the navigators (orbit, etc.) but not any of the other editing tools.

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • J Offline
        joshb
        last edited by 22 Nov 2011, 17:40

        Thanks Dan. Switching over to a tool from a plugin solved just about all of my issues. The only Undo/Redo stack modifier that I seem to be left with is the Layers window. When I've got my tool up, doing anything in the layers dialog causes the stack to be modified so my tool might not close out right. I've started looking at the transaction idea again to see if I can make sense of the stack state that way. Any ideas on this one?

        Thanks again for all of your help,
        Josh

        1 Reply Last reply Reply Quote 0
        • D Offline
          Dan Rathbun
          last edited by 22 Nov 2011, 22:39

          Your Tool could instantiate a custom LayersObserver subclass:
          http://code.google.com/apis/sketchup/docs/ourdoc/layersobserver.html

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • J Offline
            joshb
            last edited by 23 Nov 2011, 14:39

            I saw that class, but it doesn't seem to have an event for letting you know when layer visibility has changed. It can tell you when layer(s) are deleted, or when a the active layer is changed... Is there another event that I'm not seeing that might tell me when visibility changes?

            1 Reply Last reply Reply Quote 0
            • D Offline
              Dan Rathbun
              last edited by 23 Nov 2011, 19:40

              You are correct ...

              ... a Layer is a subclass of Entity, so perhaps the EntityObserver might fire the onChangeEntity() callback. You'd have to try it. I do not know if it will work.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              1 / 1
              • First post
                1/6
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement