« Back to University of Vienna - OMILAB

BeforeDiscardModelWindow

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
BeforeDiscardModelWindow
Answer
28/10/14 13:08
Hi,

I am facing the problem, that the platform (ADOxx 1.5) is handling the closing of a single modeling window differently compared to pressing the "global" X to close the whole Modling Toolkit.
Context:
I have four models that should be visible at the same time. If the user closes one of the four models, the other three should be closed automatically, as well. That works fine!
Problem:
If the four models are open and the modeler clicks on the global "X" for closing the whole Modeling Toolkit, ADOxx crashes.

Here is my code for the "BeforeDiscardModelWindow" event. Attached is the current library.

Any help would be highly appreciated.
Thank you very much in advance.
- Dominik

EDIT:
My suggestion is that is has something to do with the new modeltype "ADOxx Start Page" that is open in the background.However I am not sure and, at the moment, I cannot track down my coding/thinking mistake.
Attachments: before_discard_model_window.asc (2.5k), library.abl (10,199.5k)

RE: BeforeDiscardModelWindow
Answer
28/10/14 15:40 as a reply to Dominik Bork.
Dear Dominik,

thank you for your post. We will look into that shortly - it seems to relate to the event behaviour - the ADOxx Startpage is not a modeltype but a default UI element and should not cause the problem. We will come back to you as soon as we have further details!

RE: BeforeDiscardModelWindow
Answer
05/11/14 19:48 as a reply to Wilfrid Utz.
Hi Dominik,
thanks for your patience. The problem in the implementation, especially the crash during the execution of the shutdown command or also "Close all windows" results in a recursive trigger of the event, since all models are closed simulantously, triggering a retrievel of the related models and triggering another round. This results in an endless loop of closing.

Please find below a proposal on how to solve that issue. The idea is
a) to stop the event from being triggered in case related models are found using a global variable that is toggled
b) do not perform the CLOSE AdoScript within the event but only store a list of related, to-be closed model IDs
c) trigger an update action within the set of models
d) close the related, open and to-be-closed models in the UpdateActions event and reset the global variables.

Some code snipplets can be found below - let me know what you think on that approach!
 1# init the needed global Variable
 2ON_EVENT "AppInitialized" {
 3  # Check wheter the Window Discard event should be triggered or not
 4  SETG bPerformCloseEvent:1
 5  # Global Variable to list all open and related models to the one to be closed and close if anything in there plus clean up
 6  SETG lRelatedOpenModels:""
 7  # other things in the eve
 8  ....
 9}
Modify the event "BeforeDiscardModelWindow" to only run in case the global variable bPerformCloseEvent is 1
1ON_EVENT "BeforeDiscardModelWindow" {
2  # only trigger the event if set accordingly in parent event, no recursion should be done 
3  IF (bPerformCloseEvent) {
4    EVENT_LOG msgType:"EVENT_LOG" message: ("BeforeDiscardModelWindow")
5    EXECUTE file: (g_path_asc + "before_discard_model_window.asc") scope:same
6  }
7}

Within the script "before_discard_model_window.asc", collect the related models, check if they are open and create a list, set the list in the global variable lRelatedOpenModels. In case the list is not empty after the search, trigger an UpdateAction by activating a model
 1# search for models related to the one open
 2SET lRelatedModels: ("")
 3FIND_MODEL_ID (activeModelId) modelType: (modelNameObjDecomp) resultModelId:modelIdObjDecomp
 4SET lRelatedModels: (tokunion(lRelatedModels, STR modelIdObjDecomp))
 5FIND_MODEL_ID (activeModelId) modelType: (modelNameIAS) resultModelId:modelIdIAS
 6SET lRelatedModels: (tokunion(lRelatedModels, STR modelIdIAS))
 7FIND_MODEL_ID (activeModelId) modelType: (modelNameTransDecomp) resultModelId:modelIdTransDecomp
 8SET lRelatedModels: (tokunion(lRelatedModels, STR modelIdTransDecomp))
 9FIND_MODEL_ID (activeModelId) modelType: (modelNameVES) resultModelId:modelIdVES
10SET lRelatedModels: (tokunion(lRelatedModels, STR modelIdVES))
11
12SET lRelatedOpenModels: ("")
13FOR sRelatedModel in: (lRelatedModels) {
14  CC "Modeling" IS_OPENED modelid: (VAL sRelatedModel)
15  IF (isopened = 1) {
16     SET lRelatedOpenModels: (tokunion(lRelatedOpenModels, sRelatedModel))
17  }
18}
19
20IF (tokcnt (lRelatedOpenModels) > 0 ) {
21  SETG bPerformCloseEvent:0
22  # remember open models, that need to be closed and do so in UpdateActions when modelid != -1
23  SETG lRelatedOpenModels: (lRelatedOpenModels)
24  # need to trigger ONE updateActions event
25  CC "Modeling" GET_ACT_MODEL
26  # find a model but not the current active one, since activating the active one does not trigger an event
27  SET possibleActivates: (tokdiff (lRelatedOpenModels, STR modelid))
28  CC "Modeling" ACTIVATE_MODEL (VAL token(possibleActivates, 1))
29}
Perform the close in the UpdateAction and reset the global variables
 1ON_EVENT "UpdateActions" {
 2  # only consider this event if the modelid != -1, this means that a model is open during the update, this should exclude already the close all and shutdown crashes
 3  IF (modelid != -1) {
 4    # check for the the lRelatedOpenModels global variable, this would mean that a close action was detected, and the necessary shutdown should happen
 5    IF (tokcnt (lRelatedOpenModels) > 0) {
 6      EVENT_LOG msgType:"EVENT_LOG" message: ("UpdateActions for modelid: " + STR modelid + " count " + STR (tokcnt (lRelatedOpenModels)))
 7      # make sure to only run the shutdown once!
 8      FOR sRelatedOpenModel in :(lRelatedOpenModels) {
 9        CC "Modeling" SET_MODIFIED modelid: (VAL sRelatedOpenModel)
10        CC "Modeling" SAVE modelid: (VAL sRelatedOpenModel)      
11        CC "Modeling" CLOSE modelid: (VAL sRelatedOpenModel) quiet
12      }
13      # clean up lRelatedOpenModels
14      SETG lRelatedOpenModels:""
15      # turn on event listing again
16      SETG bPerformCloseEvent:1      
17    }
18  }
19}