Navigate To at start up simulation - anylogic

When I run the model, I want my model to go to the viewarea of the simulation parameters in the agent of this user interface. So at the simulation and java actions I added this by the next code (also a screenshot is added at the bottom):
root.uI_startUP.SimulationParameters.navigateTo();
The strange thing is when I run the model for the first time, he goes for like 1 second to this view area, but then automatically returns to the main agent. When I stop the model and restart it again (and keep the run window open), this problem is not happening and it is staying in the good user-interface agent view area.
What could be the reason behind this? and how can this be solved.
Added later:
At the moment I fixed it by creating an event which is triggered by the variable start==true, and after that navigates to the interface and sets this value to false. see figure below
This works, and seems to be a solution.
But I'm still curious why the first method is not working..

Seems to be the code in "Initial experiment setup" that messes here.
Remove both code snippets and only call uI_startUP.SimulationParameters.navigateTo() on the "On startup" of Main.
This is how you should do it anyway :)

Related

Plotly Dash - Callback triggers sometimes & the same callback doesnt trigger sometime

I am facing issue with callbacks. I have 3 drop downs, one scattermap , one table and one slider on the screen and they all need to work in tandem and i have 5 call backs. When i execute the application all my callbacks associated with these controls execute in random order. After that when i click on scattermap it may or may not work. Say we assume it worked. Then i can navigate all around without any hassle. Then if i execute the application then click on the scattermap then as i mentioned it may or may not work. Say suppose it didn't work this time. If so is the case it will not work at all no matter what i do and simulaneously one specific dropdown also becomes dysfunctional. However if click any of the other two drop downs then evrything will start functioning as normal.
I have digged really deep into this and figured out that this has nothing to do with my code. The underlying issue is that when the click doesn't work the reason the reason behind that is the callback isn't getting triggered. I found out this by applying some debugging techniques and i am 100% sure the callback is not firing. Can anyone help me resolve/understand this please.

Issue with setting AutomationElement value

I have an issue with setting value of AutomationElement by using method ValuePattern.SetValue().
Everything works just fine until some dialog appears. When the dialog appears the code execution got stuck. No exception is thrown. After the dialog is confirmed, the code exection continues. Bellow is a sample of the code:
BasePattern basePattern = null;
ValuePattern valuePattern = null;
AutomationElement elementA = Window.GetElement(SearchCriteria.ByText(propertyName));
object patternObjectA = null;
elementA.TryGetCurrentPattern(ValuePattern.Pattern, out patternObjectA);
basePattern = (BasePattern)patternObjectA;
valuePattern = (ValuePattern)patternObjectA;
valuePattern.SetValue(optionToSet);
// Window.GetElement() is a method from TestStack.White framework
// The code execution got stuck on the last line until the dialog is confirmed
Is there any other way to set AutomationElement value?
Is somehow possible to avoid of getting stuck by dialog?
I'll by grateful for any help.
Thanks advance.
It could be that this dialog is not supporting UI Automation correctly or that you simply target the wrong element.
To verify that you may use Inspect.exe from Microsoft or similiar tools.
If it works, check if you really target the correct component with your code again.
If it does not work and:
if you are able to change the application
you can change the so called AutomationPeer of the UI component - here is a link for more infos
Or simply use another UI component that supports UI Automation correctly.
if you are not able to change the application, and also do not need to run in background, parallel, etc.. you might just focus the component (call setFocus() onto the AutomationElement, or expand it (via IsExpandCollapsePatternAvailable or simulated MouseClick onto the components coordinates)) and then use the SendKeys.SendWait("test") method.
EDIT: There is one more thing you should have a look at, and I wonder why I didn't mentioned it in the first place: Register to UI Automation Events
For example you could register a callback for the Structure change event type, and check if the dialog you talk about appeared.
If so --> click the confirmed button of the dialog.
Probably you will have to synchronize your execution, so that every further action in the UI Automation script waits until the registered callback got executed and the confirmed button got clicked.

Inner Workings of Unity3d's GUI.Button

I'm still pretty new to scripting in Unity3D, and I'm following along with a tutorial that uses GUI.Button() to draw a button on the screen.
I am intrigued by how this function works. Looking through the documentation, the proper use of GUI.Button is to invoke the function in an if statement and put the code to be called when the button is pushed within the if statement's block.
What I want to know is, how does Unity3D "magically" delay the code in the if statement until after the button is clicked? If it was being passed in as a callback function or something, then I could understand what was going on. Perhaps Unity is using continuations under the hood to delay the execution of the code, but then I feel like it would cause code after the if statement to be executed multiple times. I just like to understand how my code is working, and this particular function continues to remain "magical" to me.
I don't know if it's the right term, but I usually refer to such system as immediate mode GUI.
how does Unity3D "magically" delay the code in the if statement until
after the button is clicked?
GUI.Button simply returns true if a click event happened inside the button bounds during last frame. Basically calling that function you are polling: every frame for every button asking the engine if an event which regards that button (screen area) is happened.
If it was being passed in as a callback function or something, then I
could understand what was going on
You are probably used to an MVC like pattern, where you pass a controller delegate that's called when an UI event is raised from the view. This is something really different.
Perhaps Unity is using continuations under the hood to delay the
execution of the code, but then I feel like it would cause code after
the if statement to be executed multiple times.
No. The function simply returns immediately and return true only if an event happened. If returns false the code after the if won't be executed at all.
Side notes:
That kind of system is hard to maintain, especially for complex structured GUI.
It has really serious performance implications (memory allocation, 1 drawcall for UI element)
Unless you are writing an editor extension or custom inspector code, I'd stay away from it. If you want to build a menu implement your own system or use an external plugin (there are several good ones NGUI, EZGUI,..).
Unity has already announced a new integrated UI System, it should be released soon.
Good question. The unity3d gui goes through several event phases, or in the documentation
Events correspond to user input (key presses, mouse actions), or are UnityGUI layout or rendering events.
For each event OnGUI is called in the scripts; so OnGUI is potentially called multiple times per frame. Event.current corresponds to "current" event inside OnGUI call."
In OnGUI you can find out which event is currently happening with >Event.current
The following events are processed link:
Types of UnityGUI input and processing events.
-MouseDown
-MouseUp,mouse button was released
-MouseMove,Mouse was moved (editor views only)
-MouseDrag,Mouse was dragged
-KeyDown, A keyboard key was pressed
-KeyUp A keyboard key was released.
-ScrollWheel The scroll wheel was moved.
-Repaint A repaint event. One is sent every frame.
-Layout A layout event.
-DragUpdated Editor only: drag & drop operation updated.
-DragPerform Editor only: drag & drop operation performed.
-DragExited Editor only: drag & drop operation exited.
-Ignore Event should be ignored.
-Used Already processed event.
-ValidateCommand Validates a special command (e.g. copy & paste).
-ExecuteCommand Execute a special command (eg. copy & paste).
-ContextClick User has right-clicked (or control-clicked on the mac).
Unity GUI has much improved lately and is quite usefull if you want to handle things programmatically. If you want to handle things visually, i recommend looking at the plugins heisenbug refers to.
If you decide to use unity gui, i recommend using only one object with ongui, and let this object handle all your gui.

Xcode/iPhone -- break when the next event enters my code?

I am working on a large (>30k lines) event-driven app. I have a sequence of inputs that produces a bug. What I want to do is to break as soon as the final input enters my code.
Is there a general way to do that?
I understand that for any specific sequence of inputs, I can find out where that last input is going to enter my code, then set a breakpoint there. What I would like to do is take out the step of "find out where that last input enters my code." In other words, I am running the app in the simulator, and I want to set a flag somewhere that says "break the next time you are going to enter non-system Objective C code." Then I send the event that causes the problem.
I understand what you are asking, but have you tried using an Exception Breakpoint? This will basically act like an auto-inserted breakpoint on the piece of code that throws the exception. If that doesn't work for you, try a symbolic breakpoint
If you want to intercept UI events, you can try subclassing UIWindow and overriding its sendEvent: method, then setting this class as the class of the UIWindow object in your main XIB file. sendEvent: will be called each time the user generates a touch event. Unfortunately, at this point you cannot yet know which UI object will finally consume the event (read: which event handler code will be ultimately called) since that depends on the actual state of the responder chain. But anyway, you can use this method to inject events into the system.

How do you get the Eclipse menubar to update on demand?

I'm working on a plugin aiming to hide a swathe of menu contributions, then slowly reintroduce them to the UI according to how confident/experienced the user is, with help and introductory information given to the user at each step. So far I can happily hide menu contributions using activities. Getting them back has proved to be slightly more difficult, however.
I have menu contributions being hidden and shown via activities, but the problem I've run in to is that the menu isn't instantly updating to reflect the activites. When my provided variable is changed, the activities are being started/stopped appropriately, but the menu doesn't immediately change. That is, until you change view or perspective- actions which cause the menu to be refreshed.
I've tried calling refresh() on the MenuManager, as per this question, to no avail.
Obviously my expression is being evaluated immediately, but how can I get the menu itself to update/refresh immediately?
Thanks!
It turns out there were issues with fireSourceChanged().
Calling: fireSourceChanged(int sourcePriority, Map sourceValuesByName) doesn't work for me.
But calling fireSourceChanged(int sourcePriority, String sourceName, Object sourceValue) does work.
I really don't know why that is - could be an Eclipse bug??