private void DrawBranch(DesignerItem root, List <DesignerItem> operationPool) { bool branchHasErrors = false; if (operationPool.Count != 0) { //add a dmp under the root DesignerItem dmp = this.AttachDMP(root, operationPool); //add the local root DesignerItem operation = this.CreateItem(Canvas.GetTop(dmp) + 140, this.GlobalOffsetX); operation.Content = this.GetOperationTBPContent(); operation.BoundLogicItem = new Operation(operationPool[0].BoundLogicItem.ID, operation.ID); //move parameters from RBP operation to the created TBP operation.BoundLogicItem.Name = operationPool[0].BoundLogicItem.Name; operation.dispName = operation.BoundLogicItem.Name; operation.Tag = "Operation"; TBPDesigner.Children.Add(operation); TBPDesigner.SetConnectorDecoratorTemplate(operation); this.DrawConnection(dmp.ID, operation.ID); operationPool.RemoveAt(0); if (operationPool.Count == 0) { branchHasErrors = true; } for (int i = 0; i < operationPool.Count; i++) { DesignerItem error = this.CreateItem(Canvas.GetTop(dmp) + 140, this.GlobalOffsetX + 140 * (i + 1)); error.Content = this.GetErrorContent(); error.BoundLogicItem = new GrossError(error.ID); error.Tag = "ErrorTBP"; TBPDesigner.Children.Add(error); TBPDesigner.SetConnectorDecoratorTemplate(error); this.DrawConnection(dmp.ID, error.ID); AttachEndTBP(error); branchHasErrors = true; } //recursive call this.DrawBranch(operation, operationPool); } //add end if this operation is a leaf of the tree if (!branchHasErrors) { if (operationPool.Count == 0) { this.AttachEndTBP(root); } } //inc offset for next branch this.GlobalOffsetX += 100; //recoursive exit return; }
private void AttachEndTBP(DesignerItem item) { //create dmp below stated item DesignerItem end = this.CreateDMP(Canvas.GetTop(item) + 140, Canvas.GetLeft(item)); end.Content = this.GetEndTBPContent(); end.BoundLogicItem = new End(end.ID); end.dispName = end.BoundLogicItem.Name; end.Tag = "EndTBP"; TBPDesigner.Children.Add(end); TBPDesigner.SetConnectorDecoratorTemplate(end); this.DrawConnection(item.ID, end.ID); }
private DesignerItem AttachDMP(DesignerItem item, List <DesignerItem> operationPool) { //create dmp below stated item DesignerItem dmp = this.CreateDMP(Canvas.GetTop(item) + 140, Canvas.GetLeft(item)); dmp.Content = this.GetDMPContent(); dmp.BoundLogicItem = new DMP(dmp.ID, operationPool.Select(x => x.BoundLogicItem).ToList()); dmp.dispName = dmp.BoundLogicItem.Name; TBPDesigner.AddChild(dmp); TBPDesigner.SetConnectorDecoratorTemplate(dmp); this.DrawConnection(item.ID, dmp.ID); return(dmp); }
private void DrawScheme(List <DesignerItem> operationPool) { DesignerItem startTBP = this.CreateItem(0, GlobalOffsetX); startTBP.Content = this.GetStartTBPContent(); startTBP.BoundLogicItem = new Start(startTBP.ID); startTBP.dispName = startTBP.BoundLogicItem.Name; startTBP.Tag = "StartTBP"; TBPDesigner.Children.Add(startTBP); TBPDesigner.SetConnectorDecoratorTemplate(startTBP); var root = startTBP; var localPool = new List <DesignerItem>(); var lastOperation = new DesignerItem(); while (operationPool.Count > 0) { localPool.AddRange(operationPool); localPool.RemoveAt(0); DesignerItem dmp = this.AttachDMP(root, localPool); //add the local root DesignerItem operation = this.CreateItem(Canvas.GetTop(dmp) + 140, this.GlobalOffsetX); operation.Content = this.GetOperationTBPContent(); operation.BoundLogicItem = new Operation(operationPool[0].BoundLogicItem.ID, operation.ID); //move parameters from RBP operation to the created TBP operation.BoundLogicItem.Name = operationPool[0].BoundLogicItem.Name; operation.dispName = operation.BoundLogicItem.Name; operation.Tag = "Operation"; TBPDesigner.Children.Add(operation); TBPDesigner.SetConnectorDecoratorTemplate(operation); this.DrawConnection(dmp.ID, operation.ID); root = operation; for (int j = 0; j < localPool.Count; j++) { DesignerItem error = this.CreateItem(Canvas.GetTop(dmp) + 140, this.GlobalOffsetX + 140 * (j + 1)); error.Content = this.GetErrorContent(); error.BoundLogicItem = new GrossError(error.ID); error.Tag = "ErrorTBP"; TBPDesigner.Children.Add(error); TBPDesigner.SetConnectorDecoratorTemplate(error); this.DrawConnection(dmp.ID, error.ID); AttachEndTBP(error); } lastOperation = root; localPool.Clear(); operationPool.RemoveAt(0); } this.AttachEndTBP(root); #region old //bool branchHasErrors = false; //if (operationPool.Count != 0) //{ // //add a dmp under the root // DesignerItem dmp = this.AttachDMP(root, operationPool); // //add the local root // DesignerItem operation = this.CreateItem(Canvas.GetTop(dmp) + 140, this.GlobalOffsetX); // operation.Content = this.GetOperationTBPContent(); // operation.BoundLogicItem = new OperationTBP(operationPool[0].BoundLogicItem.ID, operation.ID); // //move parameters from RBP operation to the created TBP // operation.BoundLogicItem.Name = operationPool[0].BoundLogicItem.Name; // operation.dispName = operation.BoundLogicItem.Name; // operation.Tag = "OperationTBP"; // TBPDesigner.Children.Add(operation); // TBPDesigner.SetConnectorDecoratorTemplate(operation); // this.DrawConnection(dmp.ID, operation.ID); // operationPool.RemoveAt(0); // if (operationPool.Count == 0) // branchHasErrors = true; // for (int i = 0; i < operationPool.Count; i++) // { // DesignerItem error = this.CreateItem(Canvas.GetTop(dmp) + 140, this.GlobalOffsetX + 140 * (i + 1)); // error.Content = this.GetErrorContent(); // error.BoundLogicItem = new GrossError(Guid.NewGuid(), error.ID); // error.Tag = "ErrorTBP"; // TBPDesigner.Children.Add(error); // TBPDesigner.SetConnectorDecoratorTemplate(error); // this.DrawConnection(dmp.ID, error.ID); // AttachEndTBP(error); // branchHasErrors = true; // } // //recursive call // this.DrawBranch(operation, operationPool); //} ////add end if this operation is a leaf of the tree //if (!branchHasErrors) // if (operationPool.Count == 0) this.AttachEndTBP(root); ////inc offset for next branch //this.GlobalOffsetX += 100; ////recoursive exit ////return; #endregion }
private void Generate_TBP(object sender, ExecutedRoutedEventArgs e) { if (TBPDesigner.Children.Count > 0) { var result = MessageBox.Show("TBP designer is not empty! Are you sure you want to overwrite the current model?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.No) { return; } else { TBPDesigner.Children.Clear(); } } IEnumerable <DesignerItem> designerItems = RBPDesigner.Children.OfType <DesignerItem>(); IEnumerable <Connection> connections = RBPDesigner.Children.OfType <Connection>(); //add operations to items pool List <DesignerItem> operationPool = designerItems.Where(p => p.BoundLogicItem.GetType() == typeof(Operation)).ToList(); if (operationPool.Count < 2) { MessageBox.Show("Not enough operations for generation."); e.Handled = true; return; } BackgroundWorker worker = new BackgroundWorker(); //build map of operations this.GlobalOffsetX = 100; ProgressWindow pbp = new ProgressWindow(); pbp.Owner = App.Current.MainWindow; pbp.Show(); //worker.DoWork += new DoWorkEventHandler( // delegate(object o, DoWorkEventArgs args) // { //add start to canvas DesignerItem startTBP = this.CreateItem(0, GlobalOffsetX); startTBP.Content = this.GetStartTBPContent(); startTBP.BoundLogicItem = new Start(startTBP.ID); startTBP.dispName = startTBP.BoundLogicItem.Name; startTBP.Tag = "StartTBP"; TBPDesigner.Children.Add(startTBP); TBPDesigner.SetConnectorDecoratorTemplate(startTBP); DrawBranch(startTBP, operationPool); // } // ); //worker.RunWorkerAsync(); //works corectly, looks ugly //DrawNonconditionalConnections(); pbp.Close(); TBPDesignerTab.Visibility = System.Windows.Visibility.Visible; DesignerTabs.SelectedIndex = 1; }