Book a Demo

Author Topic: Trouble with Add-in's event model  (Read 4642 times)

Volkov

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Trouble with Add-in's event model
« on: November 15, 2015, 09:41:39 pm »
Hi guys and little foreword describing my trouble.
As every EA programmer knows, there is no way to draw custom shape except using ShapeScript. But customization on the run is almost impossible. The one and only tool available is calling ‘hasproperty()’ function from ShapeSctipt. I'm trying to make add-in getting signals from ShapeScript and replying back with coded values letting know the script how to draw some elements, depending on user’s settings.
Well, this notification mechanism is ok and running smoothly. But what’s really bothering me is inconsistent event model. So, you can not get any notification when you’re opening diagram. You will be notified only after it’s been opened and painted already. And if you want to change something BEFORE the diagram drawn you’re out of luck. For some strange reasons, there is only EA_OnPostOpenDiagram event fired post-factum. And there are no EA_OnPreOpenDiagram or EA_OnOpeningDiagram though it’d be logically correct model.
There are basically 2 possible solutions: to catch first ‘hasproperty()’ call from ShapeScript to your add-in’s replying function and make customisation right in time, or catch EA_OnTabChanged event to understand that new diagram is being opened right now. Yessssss!!!! Did you see this documentation excerpt?
Quote
EA_OnTabChanged notifies Add-Ins that the currently open tab has changed. Diagrams do not generate the message when they are first opened - use the broadcast event EA_OnPostOpenDiagram for this purpose.
Hell, no! You’ll get this event EVERY time you’re opening diagram or switching between diagrams! The only difference is when you open diagram the ’DiagramID’ parameter will be 0 (bug??) but ‘TabName’ will be absolutely correct and will contain the name of diagram being opened. Really good signal to start customization if you open diagram but really terrible if you closing one and got to customize diagram previously obscured but now being activated! You know why? Because when you close a diagram there will NO SIGNAL telling that hidden diagram is exposed and visible now :(
What is real pain and shame, you’ll never know when diagram want to redraw itself. That makes customization via catching calls from ShapeScript to your add-in almost useless. I know for sure now, that
1. ShapeScript works 2 (!) times on diagram opening
2. ShapeScript can run or not run when you switching diagrams tabs
3. ShapeScript starts if you select any diagram element
4. ShapeScript starts if you open some drop down menu partially covering the diagram thus invalidating drawing canvas
It drives me nuts!
So! Guys, can you either update your documentation or make a patch which will notify add-ins when diagram gonna paint itself (to be able to prepare the context for that particular diagram), and sending EA_OnTabChanged with diagram ID of diagram being exposed when old active diagram’s tab is closed?
Dear Spars! We all love you fabolous software but THAT kind of documentation and lack of state machine showing events sequencing is as crappy as it gets (especially lack of C# samples in docs). Sorry! But I spent 2 days sitting in front of MS VS debugger trying to understand why it works not like documented. Debug your documentation, finally! Even half of menus are documented wrong since you've changed the GUI but left its description as is.

Ready to listen to your advices how to:
1. Catch the moment of diagram’s beginning of paining
2. Know what diagram is becoming active after previous one is closed

Thanks!
Andrey  
« Last Edit: November 15, 2015, 09:44:45 pm by volchok »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Trouble with Add-in's event model
« Reply #1 on: November 15, 2015, 10:36:27 pm »
Welcome to the wonderful world of Sparx. Do you see the bottle on the table that reads "Drink Me"? Well, do so and you will know how it feels to be Sparxian.

Or if you don't like [ch8206]Lewis Carroll I could also cite from Dante's Inferno: "Abandon all hope, ye who enter in!"

q.
« Last Edit: November 15, 2015, 10:39:19 pm by qwerty »

Volkov

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Trouble with Add-in's event model
« Reply #2 on: November 16, 2015, 04:31:31 am »
You won't believe but I even don't expect any reply from the Sparx :) And yes, I know so much about EA internals regarding add-ins that I'm afraid to keep writing add-ins  :-[
P.S. Prefer Dante, Carrol was too optimistic from IT industry POV