Author Topic: He made it there again  (Read 2067 times)

0 Members and 1 Guest are viewing this topic.


vegbruiser

  • Guest
Re: He made it there again
« Reply #1 on: July 05, 2010, 05:21:01 AM »
Aye, well done that man!

:D

Glenn R

  • Guest
Re: He made it there again
« Reply #2 on: July 05, 2010, 05:42:14 AM »
Thanks lads - just a little something to share with the community.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8816
  • AKA Daniel
Re: He made it there again
« Reply #3 on: July 05, 2010, 05:48:29 AM »
Nice work, even though it demonstrates pointless and wasteful event handling  :laugh:

Glenn R

  • Guest
Re: He made it there again
« Reply #4 on: July 05, 2010, 05:51:39 AM »
Yeah, pisser about that eh? :D Funny, but that's how you do it in ARX as well if memory serves...go figure...

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8816
  • AKA Daniel
Re: He made it there again
« Reply #5 on: July 05, 2010, 06:03:51 AM »
You always do top notch coding, thanks for sharing your talents   :-)

Glenn R

  • Guest
Re: He made it there again
« Reply #6 on: July 05, 2010, 06:09:53 AM »
Thanks for the kind words Dan and glad to help where I can.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: He made it there again
« Reply #7 on: July 05, 2010, 10:30:40 AM »
Well done Glenn.
I see you didn't dispose the TaskDialog, is there no need?
I ask as they look kind of handy and I'll probably start using them a bit.

Glenn R

  • Guest
Re: He made it there again
« Reply #8 on: July 05, 2010, 10:36:51 AM »
Thanks Bryce. From memory, TaskDialog doesn't implement IDisposable. When I wrote this, I automatically wrapped it in a 'using', which went bang with a nasty compiler error the first time I compiled.

kaefer

  • Guest
Re: He made it there again
« Reply #9 on: July 12, 2010, 06:05:56 AM »
Hello, friends!

I'm new here and this is my first post.
My question is: What are your opinions on using Observables for event handlers, now available in .NET 4.0?

As an example take the DocData class inspired by Glenn's RefUcsSpy and Tony's subsequent comments.
Alas, it is not C#, it's in F#; but should be straightforward to port.

Code: [Select]
type DocData(doc: Document) =
    let obs =
        doc.CommandWillStart
        |> Observable.filter
            (fun e ->
                DocDataModule.Contains e.GlobalCommandName &&
                not acadApp.WcsCurrent &&
                not acadApp.ScriptActive &&
                DocDataModule.RequestUserConfirmation() )
        |> Observable.subscribe
            (fun _ ->
                let ucsFollow = acadApp.UcsFollow
                let currentUCS = doc.Editor.CurrentUserCoordinateSystem
                let commandEnded = ref null
                commandEnded :=
                    doc.CommandCancelled
                    |> Observable.merge doc.CommandEnded
                    |> Observable.merge doc.CommandFailed
                    |> Observable.subscribe
                        (fun _ ->
                            acadApp.UcsFollow <- ucsFollow
                            doc.Editor.CurrentUserCoordinateSystem <- currentUCS
                            (!commandEnded).Dispose() )
                acadApp.UcsFollow <- false
                doc.Editor.CurrentUserCoordinateSystem <-
                    Matrix3d.Identity )

    member x.Stop() =
        obs.Dispose()

Look ma, no mutable state.