/// <summary> /// Analizes the state machine from tree. /// </summary> /// <param name="imna">The analized node.</param> internal static void AnalizeStateMachine(IModelNodeAdvance imna) { if (CustomEditors.IsLicensed) { if ((((TypeDesign <Opc.Ua.ModelCompiler.ObjectTypeDesign>)imna.Wrapper4PropertyGrid).BaseType.ToString() == finiteStateMachineTypeString)) { TypeDesign <Opc.Ua.ModelCompiler.ObjectTypeDesign> selectedNodeObjectTypeDesign = (TypeDesign <Opc.Ua.ModelCompiler.ObjectTypeDesign>)imna.Wrapper4PropertyGrid; try { string symbolicNameNameSpace = selectedNodeObjectTypeDesign.SymbolicName.NameSpace; ObjectTypeDesign machineObjectDesign = (ObjectTypeDesign)selectedNodeObjectTypeDesign.Parent; List <string> allStates = new List <string>(); List <Transition> allTransitions = new List <Transition>(); Dictionary <FolderType, IEnumerable <IModelNodeAdvance> > folders = imna.GetFolders(); foreach (Folder folder in folders.Values) { if (folder is ChildrenFolder) { foreach (IModelNode machineIModelNode in folder) { if (machineIModelNode.NodeClass == NodeClassesEnum.Object) { FindStatesAndTransitionsInStateMachine((InstanceDesign <Opc.Ua.ModelCompiler.ObjectDesign>)machineIModelNode.Wrapper4PropertyGrid, allStates, allTransitions); } } } } bool transitionAnalized = false; while (transitionAnalized == false) { transitionAnalized = StateMachineCrossTable.AddImagesOnTransitionButtons(allStates, allTransitions, symbolicNameNameSpace, machineObjectDesign, imna.IsReadOnly); } } catch (Exception) { MessageBox.Show(Resources.ProblemWithStateMachine_Header, Resources.ProblemwithDisplayingStateMachine_Info, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } } else { MessageBox.Show(Resources.ProblemWithStateMachine_Header, Resources.ProblemWithStateMachine_Info, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } } else { MessageBox.Show(Resources.ModelDesignerProLicenseWarning); } }
/// <summary> /// Analizes the transition states and add buttons. /// </summary> /// <param name="allStates">All states.</param> /// <param name="allTransitions">All transitions.</param> /// <param name="symbolicNameNameSpace">The symbolic name name space.</param> /// <param name="machineObjectDesign">The machine object design.</param> /// <returns> /// True if transitions are correctly analized. /// </returns> internal static bool AddImagesOnTransitionButtons(List <string> allStates, List <Transition> allTransitions, string symbolicNameNameSpace, ObjectTypeDesign machineObjectDesign, bool isReadOnly) { StateMachineCrossTable crossTableWindow = DrawStateMachineCrossTableWindow(allStates, allTransitions, symbolicNameNameSpace, machineObjectDesign, isReadOnly); int toStateNumber = 0; int fromStateNumber = 0; bool fromStateExists = false; bool toStateExists = false; string fromStateFoundName = ""; string toStateFoundName = ""; string shortFromState; string shortToState; foreach (Transition transitionOnList in allTransitions) { if (transitionOnList.FromState.Contains("_")) { shortFromState = (transitionOnList.FromState).Substring((transitionOnList.FromState).LastIndexOf("_"), (transitionOnList.FromState).Length - (transitionOnList.FromState).LastIndexOf("_")).Replace("_", ""); } else { shortFromState = transitionOnList.FromState; } if (transitionOnList.ToState.Contains("_")) { shortToState = (transitionOnList.ToState).Substring((transitionOnList.ToState).LastIndexOf("_"), (transitionOnList.ToState).Length - (transitionOnList.ToState).LastIndexOf("_")).Replace("_", ""); } else { shortToState = transitionOnList.ToState; } if (shortFromState == shortToState) { for (int statesCounter = 0; statesCounter < allStates.Count; statesCounter++) { if ((allStates[statesCounter] == shortFromState)) { fromStateNumber = statesCounter + 1; fromStateFoundName = allStates[statesCounter]; fromStateExists = true; toStateNumber = statesCounter + 1; toStateFoundName = allStates[statesCounter]; toStateExists = true; } } } else { for (int statesCounter = 0; statesCounter < allStates.Count; statesCounter++) { if ((allStates[statesCounter] == shortFromState)) { fromStateNumber = statesCounter + 1; fromStateFoundName = allStates[statesCounter]; fromStateExists = true; } else if ((allStates[statesCounter] == shortToState)) { toStateNumber = statesCounter + 1; toStateFoundName = allStates[statesCounter]; toStateExists = true; } } } if (fromStateExists == true && toStateExists == true) { foreach (Control ctrl in crossTableWindow.tableLayoutPanelCrossTable.Controls) { StateMachineControl smc = ctrl as StateMachineControl; if ((smc != null) && (smc.buttonTransition.TransitionData.FromState == fromStateFoundName) && (smc.buttonTransition.TransitionData.ToState == toStateFoundName)) { smc.buttonTransition.TransitionData.Update(transitionOnList); smc.buttonTransition.Image = global::CAS.UA.Model.Designer.Properties.Resources.transition; smc.buttonTransition.FlatStyle = FlatStyle.Standard; } } } else if (fromStateExists == false) { allStates.Add(shortFromState); crossTableWindow = DrawStateMachineCrossTableWindow(allStates, allTransitions, symbolicNameNameSpace, machineObjectDesign, isReadOnly); return(false); } else { allStates.Add(shortToState); crossTableWindow = DrawStateMachineCrossTableWindow(allStates, allTransitions, symbolicNameNameSpace, machineObjectDesign, isReadOnly); return(false); } } crossTableWindow.tableLayoutPanelCrossTable.SuspendLayout(); crossTableWindow.SuspendLayout(); crossTableWindow.Height = crossTableWindow.tableLayoutPanelCrossTable.Height + 50; crossTableWindow.Width = crossTableWindow.tableLayoutPanelCrossTable.Width + 50; crossTableWindow.tableLayoutPanelCrossTable.ResumeLayout(false); crossTableWindow.tableLayoutPanelCrossTable.PerformLayout(); crossTableWindow.ResumeLayout(false); crossTableWindow.PerformLayout(); crossTableWindow.Show(); return(true); }