Esempio n. 1
0
        void OnLoad(object sender, RoutedEventArgs e)
        {
            if (!isLoaded)
            {
                isLoaded = true;
                try
                {
                    if (this.Children.Count > 0)
                    {
                        Label nameLabel = new Label();
                        nameLabel.Content = this.DiagramName;
                        nameLabel.Height = 25;
                        Canvas.SetTop(nameLabel, 0);
                        Canvas.SetLeft(nameLabel, 0);
                        this.Children.Add(nameLabel);

                        Canvas clsCanvas = null;
                        foreach (UIElement u in this.Children)
                            if (u is Canvas)
                            {
                                clsCanvas = u as Canvas;
                                break;
                            }

                        //positioning
                        if (clsCanvas != null)
                        {
                            //MessageBox.Show("in class canvas");
                            //position classes
                            foreach (UIElement uClass in clsCanvas.Children)
                                if (uClass is VisualElement)
                                    if ((uClass as VisualElement).Content is UMLClass)//double check
                                    {
                                        Canvas.SetTop(uClass, 25 + (clsCanvas.Children.IndexOf(uClass) % 2) * 200);
                                        Canvas.SetLeft(uClass, 5 + (clsCanvas.Children.IndexOf(uClass) / 2) * 350);
                                        Canvas.SetZIndex(uClass, 9);
                                        Canvas.SetZIndex(((uClass as VisualElement).Content as UMLClass), 9);
                                    }

                            //reposition associations
                            foreach (UIElement uClass in clsCanvas.Children)
                                if (uClass is VisualElement)
                                    if ((uClass as VisualElement).Content is UMLClass)//double check
                                        if (((uClass as VisualElement).Content as UMLClass).getAssociations().Count > 0)
                                        {
                                            System.Collections.ObjectModel.Collection<UIElement> ass = new System.Collections.ObjectModel.Collection<UIElement>();
                                            ass = ((uClass as VisualElement).Content as UMLClass).getAssociations();
                                            foreach (UIElement assoc in ass)
                                                if ((assoc as VisualElement).Content is UMLAssociation)
                                                {
                                                    //UIElement start = uClass;
                                                    UIElement end = findClass(clsCanvas, ((assoc as VisualElement).Content as UMLAssociation).EndClass);
                                                    if ((end != null))//found end class
                                                    {
                                                        //int sindex = clsCanvas.Children.IndexOf(start);
                                                        int eindex = clsCanvas.Children.IndexOf(end);
                                                        //MessageBox.Show("found end class");
                                                        if (eindex >= 0)
                                                        {
                                                            Point sp = new Point(5, 30);
                                                            Point ep = new Point(5 + (eindex / 2) * 350, 30 + (eindex % 2) * 200);
                                                            //Point ep = new Point(Canvas.GetLeft((end as VisualElement).Content as UMLClass), Canvas.GetTop((end as VisualElement).Content as UMLClass));

                                                            //not a good approach
                                                            ((assoc as VisualElement).Content as UMLAssociation).clearArrow();
                                                            ((assoc as VisualElement).Parent as Canvas).Children.Remove(assoc as VisualElement);

                                                            this.Children.Add(assoc);

                                                            if (ep.X == 5)
                                                            {
                                                                Canvas.SetLeft(assoc, ep.X);
                                                                Canvas.SetTop(assoc, ep.Y - 60);
                                                            }
                                                            else if (ep.Y == 30)
                                                            {
                                                                Canvas.SetLeft(assoc, ep.X - 80);
                                                                Canvas.SetTop(assoc, ep.Y);
                                                            }

                                                            ArrowLine aline1 = new ArrowLine();
                                                            aline1.Stroke = System.Windows.Media.Brushes.Black;
                                                            aline1.StrokeThickness = 1;
                                                            aline1.IsArrowClosed = false;
                                                            aline1.X1 = sp.X;
                                                            aline1.Y1 = sp.Y;
                                                            aline1.X2 = ep.X;
                                                            aline1.Y2 = ep.Y;
                                                            this.Children.Add(aline1);
                                                            Canvas.SetZIndex(aline1, 1);

                                                        }
                                                    }
                                                }

                                        }
                        }

                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
Esempio n. 2
0
        private void ItemElement_Drop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent("TreeNodeViewModel"))//Visualiser
            {
                TreeNodeViewModel sourceNode = e.Data.GetData("TreeNodeViewModel") as TreeNodeViewModel;

                if (templateVM.HeaderNode != null && sourceLatticeNodeToMatch != null)
                {
                    //string source = "";
                    //if (sourceNode.Name.Equals(templateVM.HeaderNode.Name))
                    //    source = ".";
                    // else
                    string source = sourceNode.getRelativeAddress(templateVM.HeaderNode);

                    string target = ((sender as ListBoxItem).DataContext as Element).Address;//was t

                    //string target = t.Substring(t.IndexOf('/') + 1);

                    //MessageBox.Show("in element\n\nDragged\nSource: " + source + "\nTarget: " + target);
                    //MessageBox.Show("in element: "+ sourceNode.ToXML().OuterXml);
                    //============
                    processElement_TreeNodeDrop(source, target, sourceNode);
                    //============

                    //log event
                    (ParentWindow as Visualiser).logger.log("\"" + sourceNode.getRelativeAddress(templateVM.HeaderNode) + "\" was dropped on \"" + target + "\" attribute of Visual Element \"" + this.VEName + "\".", ReportIcon.OK);

                }
                else
                    ShowStatus("Please set the header node first!", ReportIcon.Error);

                e.Handled = true;

                AdornerLayer myAdornerLayer = AdornerLayer.GetAdornerLayer(this);
                myAdornerLayer.Remove(visualDragAdorner);
            }

            else if ((e.Data.GetDataPresent("Element")) && (ParentWindow is Mapper))//Mapper
            {
                Element sourceElement = e.Data.GetData("Element") as Element;
                Element targetElement = (sender as ListBoxItem).DataContext as Element;
                //string rule = (sourceElement.Name + " : " + sourceElement.Address + " -> " + targetElement.Name + " : " + targetElement.Address);

                string targetMatch = targetElement.Address.Substring(targetElement.Address.IndexOf('/') + 1);

                string sourceMatch = sourceElement.Address.Substring(sourceElement.Address.IndexOf('/') + 1);

                if ((ParentWindow as Mapper).NewTemplate != null)
                    (ParentWindow as Mapper).NewTemplate.updateXmlNodeByExactValue(targetMatch, sourceMatch, targetElement.Value);

                //for reverse
                if ((ParentWindow as Mapper).NewTemplateR != null)
                    (ParentWindow as Mapper).NewTemplateR.updateXmlNodeByExactValue(sourceMatch, targetMatch, sourceElement.Value);

                //log event
                (ParentWindow as Mapper).logger.log("Element \"" + sourceElement.Address + "\" was dropped on Element \"" + targetElement.Address + "\".", ReportIcon.OK);

                e.Handled = true;

                AdornerLayer myAdornerLayer = AdornerLayer.GetAdornerLayer(this);
                myAdornerLayer.Remove(visualDragAdorner);

            }

            else if (e.Data.GetDataPresent("VisualElement"))//scheduling
            {

                VisualElement v = e.Data.GetData("VisualElement") as VisualElement;

                string targetBase = ((sender as ListBoxItem).DataContext as Element).Address;
                //what to replace
                string target = targetBase.Substring(targetBase.IndexOf('/') + 1);

                bool replaceElement = false;
                string forwardTemplateCallName = "";

                //get metamodel of source model example to find template element restructure

                if (!target.ToLower().Equals("start"))//not start element of the scheduling
                {
                    //update abstractions
                    AbstractTreeLatticeNode reference = this.abstractTree.getAbstractNodeAtAddress(targetBase);
                    reference.Children.Add(v.abstractTree.Root);
                    //update metamodel(create a partial model example)
                    v.abstractTree.Root.parent = reference;

                    if (ParentWindow != null)
                    {
                        if (ParentWindow is Visualiser)
                        {
                            try
                            {
                                string test = (ParentWindow as Visualiser).sourceASTL.RelativeAddressByName(this.templateVM.TemplateName, v.templateVM.TemplateName);
                                if (!String.IsNullOrEmpty(test))
                                    forwardTemplateCallName = test;

                                //show new abstraction rendered in sample popup - commented due to error
                                //debugger
                                /*(this.ParentWindow as Visualiser).samplePopup.Child = rend.renderPartialVisualisation(this);
                                (this.ParentWindow as Visualiser).showSamplePopup(e.GetPosition(this.ParentWindow as Visualiser));*/
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("Exception occured in ItemElement_Drop -> " + ex.ToString(), "Exception", MessageBoxButton.OK, MessageBoxImage.Error);
                            }

                        }
                        else if (ParentWindow is Mapper)//!! will not get trigered, mapper does not have start!
                        {
                            string test = (ParentWindow as Mapper).sourceASTL.RelativeAddressByName(this.templateVM.TemplateName, v.templateVM.TemplateName);
                            if (!String.IsNullOrEmpty(test))
                                forwardTemplateCallName = test;
                        }
                    }
                    else
                        forwardTemplateCallName = v.templateVM.TemplateName;

                    if (target.Equals(v.Data.Name))
                    {
                        ShowStatus("VisualElement-ItemElementDrop: setting replacement to true -> target = " + target + " v.Data.Name = " + v.Data.Name, ReportIcon.Warning);
                        replaceElement = true;
                    }
                    else
                        replaceElement = false;
                }
                else
                {
                    forwardTemplateCallName = v.templateVM.TemplateName;
                    replaceElement = false;
                }

                templateVM.updateXmlNodeByTempalte(target, forwardTemplateCallName, replaceElement);

                //log event
                (ParentWindow as Visualiser).logger.log("\"" + v.VEName + "\" is set to be placed in \"" + target + "\" of Visual Element \"" + this.VEName + "\".", ReportIcon.OK);

                //******for reverse*******
                //************************
                if (!target.ToLower().Equals("start"))//not start element of the scheduling
                {
                    string reverseTemplateCallName = "";

                    string test = this.abstractTree.RelativeAddressByName(this.templateVMR.TemplateName, v.templateVMR.TemplateName);
                    if (!String.IsNullOrEmpty(test))
                        reverseTemplateCallName = test;

                    if (string.IsNullOrEmpty(reverseTemplateCallName))
                        reverseTemplateCallName = v.templateVMR.TemplateName;

                    if (v.templateVM.TemplateName.Equals(v.ReverseData.Name))
                        replaceElement = true;
                    else
                        replaceElement = false;

                    AbstractLattice tempReverseASTL = new AbstractLattice(this.ReverseData);
                    string toReplace = tempReverseASTL.RelativeAddressByName(this.templateVM.TemplateName, v.templateVM.TemplateName);

                    if (string.IsNullOrEmpty(toReplace))
                        toReplace = v.templateVM.TemplateName;

                    this.templateVMR.updateXmlNodeByTempalte(toReplace, reverseTemplateCallName, replaceElement);

                }
                else //we were at the start of scheduling
                {
                    //create start for reverse template
                    this.templateVMR.updateXmlNodeByTempalte("start", v.templateVMR.TemplateName, false);
                }

                //generate arrow
                if ((ParentWindow != null) && (ParentWindow is Visualiser))
                {
                    //create Arrow
                    ArrowLine aline1 = new ArrowLine();
                    aline1.Stroke = Brushes.Black;
                    aline1.StrokeThickness = 2;
                    aline1.IsArrowClosed = true;

                    //get visual element center point
                    Point vePos = v.TransformToVisual((ParentWindow as Visualiser).schedulingCanvas).Transform(new Point(0, 0));
                    if (v.ActualWidth > 180)
                        aline1.X1 = vePos.X + 180 / 2;
                    else
                        aline1.X1 = vePos.X + v.ActualWidth / 2;

                    if (v.ActualHeight > 180)
                        aline1.Y1 = vePos.Y + 180 / 2;
                    else
                        aline1.Y1 = vePos.Y + v.ActualHeight / 2;

                    //Point lePos = (sender as ListBoxItem).TransformToVisual((current as Visualiser).schedulingCanvas).Transform(new Point(0, 0));
                    aline1.X2 = e.GetPosition((ParentWindow as Visualiser).schedulingCanvas).X + (sender as ListBoxItem).ActualWidth / 2;
                    aline1.Y2 = e.GetPosition((ParentWindow as Visualiser).schedulingCanvas).Y;

                    Canvas.SetZIndex(aline1, 2);
                    (ParentWindow as Visualiser).schedulingCanvas.Children.Add(aline1);

                }

                e.Handled = true;

                AdornerLayer myAdornerLayer = AdornerLayer.GetAdornerLayer(this);
                myAdornerLayer.Remove(visualDragAdorner);
            }

            else if (e.Data.GetDataPresent("VisualFunctionElementDragObject"))//Visualiser functions
            {
                VisualFunctionElementDragObject eleDrag = e.Data.GetData("VisualFunctionElementDragObject") as VisualFunctionElementDragObject;

                if (ParentWindow is Visualiser)
                {
                    string t = ((sender as ListBoxItem).DataContext as Element).Address;
                    string target = t.Substring(t.IndexOf('/') + 1);//target is where the output goes

                    templateVM.updateXmlNodeByVariableName(target, "$" + eleDrag.element.Value);

                    //for reverse generation
                    eleDrag.function.updateOutput(eleDrag.element.Value, target);

                    //draw the line conecting both elements

                    //for reverse
                    //needs to first check if all args of the input have been matched before dragging the output

                    //get elements participating in function
                    XmlNode functionData = eleDrag.function.Data;
                    XmlNode forwardInputs = functionData.SelectSingleNode("inputs");

                    foreach (XmlNode x in forwardInputs.ChildNodes)
                    {
                        //look for output variable name
                        string outputString = "output" + x.Name.Substring(3);//x.Name is like arg1
                        templateVMR.updateXmlNodeByVariableName(x.InnerText, "$" + outputString);
                    }

                    //log event
                    (ParentWindow as Visualiser).logger.log("Function element \"" + eleDrag.element.Address + "\" was dropped on \"" + target + "\" of Visual Element \"" + this.VEName + "\".", ReportIcon.OK);

                    e.Handled = true;
                }
                else if (ParentWindow is Mapper)
                {
                    string t = ((sender as ListBoxItem).DataContext as Element).Address;
                    string target = t.Substring(t.IndexOf('/') + 1);//target is where the output goes

                    (ParentWindow as Mapper).NewTemplate.updateXmlNodeByVariableName(target, "$" + eleDrag.element.Value);

                    //for reverse generation
                    eleDrag.function.updateOutput(eleDrag.element.Value, target);

                    //draw the line conecting both elements

                    //for reverse
                    //needs to first check if alll args of the input have been matched before dragging the output

                    //get elements participating in function
                    XmlNode functionData = eleDrag.function.Data;
                    XmlNode forwardInputs = functionData.SelectSingleNode("inputs");

                    foreach (XmlNode x in forwardInputs.ChildNodes)
                    {
                        //look for output variable name
                        string outputString = "output" + x.Name.Substring(3);//x.Name is like arg1

                        //if X is constant value, then it has come from nowhere! (from th pannel of constant values)
                        //therefore it will not be considered for puttin back to its place becouse it is considered
                        //as lossy data -> for futur processing
                        //so:
                        double Num;
                        bool isNum = double.TryParse(x.InnerText, out Num);

                        if (!(isNum) && !(x.InnerText.StartsWith("'"))) //is not a constant number or string
                            (ParentWindow as Mapper).NewTemplateR.updateXmlNodeByVariableName(x.InnerText, "$" + outputString);
                    }

                    //log event
                    (ParentWindow as Mapper).logger.log("Function element \"" + eleDrag.element.Address + "\" was dropped on \"" + target + "\" of Visual Element \"" + this.VEName + "\".", ReportIcon.OK);

                    e.Handled = true;
                }

                AdornerLayer myAdornerLayer = AdornerLayer.GetAdornerLayer(this);
                myAdornerLayer.Remove(visualDragAdorner);
            }
            else if (e.Data.GetDataPresent("VisualCondition"))//Visualiser Conditions
            {
                VisualCondition cond = (e.Data.GetData("VisualCondition") as VisualCondition);

                string t = ((sender as ListBoxItem).DataContext as Element).Address;

                string target = t.Substring(t.IndexOf('/') + 1);//target is where the output goes

                if (ParentWindow is Visualiser)
                {
                    templateVM.updateNodeByCondition(target, cond.getConditionCode());

                    //log event
                    (ParentWindow as Visualiser).logger.log("Condition \"" + cond.Name + "\" was dropped on \"" + target + "\" of Visual Element \"" + this.VEName + "\".", ReportIcon.OK);
                }
                else if (ParentWindow is Mapper)
                {
                    (ParentWindow as Mapper).NewTemplate.updateNodeByCondition(target, cond.getConditionCode());
                    //log event
                    (ParentWindow as Mapper).logger.log("Condition \"" + cond.Name + "\" was dropped on \"" + target + "\" of Visual Element \"" + this.VEName + "\".", ReportIcon.OK);
                }

                //no reverse for conditions yet

                e.Handled = true;

                AdornerLayer myAdornerLayer = AdornerLayer.GetAdornerLayer(this);
                myAdornerLayer.Remove(visualDragAdorner);
            }
            else
                ShowStatus("Unrecognised drag element -> " + e.Data.GetType().ToString(), ReportIcon.Error);
        }
Esempio n. 3
0
        private void generateChartArea(int h, int w , int barcount)
        {
            int width = w;
            this.Width = width;
            this.Height = h;

            int barLabelGap = (barcount == 0 ? 5 : 25);

            //create axes
            //X
            ArrowLine xaxis = new ArrowLine();
            xaxis.Stroke = Brushes.Black;
            xaxis.StrokeThickness = 2;
            xaxis.IsArrowClosed = true;
            xaxis.ArrowLength = 4;

            xaxis.X1 = 5;
            xaxis.Y1 = Height - barLabelGap - 5;
            xaxis.X2 = width - 5;
            xaxis.Y2 = xaxis.Y1;
            Canvas.SetLeft(xaxis, 0);
            Canvas.SetTop(xaxis, 0);
            this.Children.Add(xaxis);

            //Y
            ArrowLine yaxis = new ArrowLine();
            yaxis.Stroke = Brushes.Black;
            yaxis.StrokeThickness = 2;
            yaxis.IsArrowClosed = true;
            yaxis.ArrowLength = 4;

            yaxis.X1 = 10;
            yaxis.Y1 = h - barLabelGap;
            yaxis.X2 = yaxis.X1;
            yaxis.Y2 = 5;

            Canvas.SetLeft(yaxis, 0);
            Canvas.SetTop(yaxis, 0);
            this.Children.Add(yaxis);
        }
Esempio n. 4
0
        public void drawArrow(Point start, Point end)
        {
            clearArrow();

            double CentreX = Canvas.GetLeft(this);
            double CentreY = Canvas.GetTop(this);

            //Canvas.SetTop(this, 0);
            //Canvas.SetLeft(this, 0);

            ArrowLine aline1 = getArrow();
            if (aline1 == null)
                aline1 = new ArrowLine();

            aline1.Stroke = Brushes.Black;
            aline1.StrokeThickness = 1;
            aline1.IsArrowClosed = false;

            aline1.X1 = start.X;
            aline1.Y1 = start.Y;

            aline1.X2 = end.X;
            aline1.Y2 = end.Y;

            Canvas.SetLeft(aline1, 0);
            Canvas.SetTop(aline1, 0);
            //Canvas.SetZIndex(aline1, 2);

            this.Children.Add(aline1);
        }