示例#1
0
        public static DDTProject createDDTProject()
        {
            List<DDT_Obj_Property> properties = new List<DDT_Obj_Property>();
            properties.Add(new DDT_Obj_Property("p", "d", "v"));
            properties.Add(new DDT_Obj_Property("p1", "d1", "v1"));
            List<DDT_Obj_Event> events = new List<DDT_Obj_Event>();
            events.Add(new DDT_Obj_Event("s","s"));
            events.Add(new DDT_Obj_Event("s1", "s1"));

            DDTObject o1 = new DDTObject(DDT_Obj_Type.ADT, "obj1",properties,events);
            DDTObject o2 = new DDTObject(DDT_Obj_Type.SMOBJECT, "obj2");
            DDTObject o3 = new DDTObject(DDT_Obj_Type.DATASTORE, "obj3");
            DDTObject o4 = new DDTObject(DDT_Obj_Type.TERMINATOR, "obj4");

            DDTConnector from1 = new DDTConnector(1, 3);
            DDTConnector to1 = new DDTConnector(2, 1);
            DDTConnector from2 = new DDTConnector(3, 3);
            DDTConnector to2 = new DDTConnector(2, 3);
            DDTConnector from3 = new DDTConnector(1, 4);
            DDTConnector to3 = new DDTConnector(4, 1);

            DDTRelationTexts text1 = new DDTRelationTexts("1", "s", "s");

            DDTRelation r1 = new DDTRelation(DDT_Rel_Type.ONETOMANY, from1, to1, text1);
            DDTRelation r2 = new DDTRelation(DDT_Rel_Type.WIDEARROW, from2, to2, null);
            DDTRelation r3 = new DDTRelation(DDT_Rel_Type.SINGLEARROW, from3, to3, null);

            List<DDTObjectReference> obl = new List<DDTObjectReference>();
            obl.Add(new DDTObjectReference(1, new Point(100,100)));
            obl.Add(new DDTObjectReference(2, new Point(200, 300)));
            obl.Add(new DDTObjectReference(3, new Point(300, 200)));
            obl.Add(new DDTObjectReference(4, new Point(400, 400)));

            List<int> rel = new List<int>();
            rel.Add(5); rel.Add(6); rel.Add(7);

            DDTDiagram diagram1 = new DDTDiagram("dia1", DDT_Diagram_Type.ERD, obl, rel);

            List<DDTDiagram> dia=new List<DDTDiagram>();
            dia.Add(diagram1);
            List<DDTObject> obj = new List<DDTObject>();
            obj.Add(o1); obj.Add(o2); obj.Add(o3); obj.Add(o4);
            List<DDTRelation> re = new List<DDTRelation>();
            re.Add(r1); re.Add(r2); re.Add(r3);

            DDTProject proj = new DDTProject("pro1", dia,obj ,re);

            return proj;
        }
示例#2
0
        public static void displayTable(DDTDiagram cfd)
        {
            /*
            DataGridView stt = new DataGridView();
            stt.DataSource = getSTT(cfd);

            // want to make our DataGridView look good.
            stt.ReadOnly = true;
            stt.AutoResizeColumns();
            stt.AutoResizeRows();
            stt.AutoSize = true;
            /*
            int width = 0;
            foreach (DataGridViewColumn c in stt.Columns)
            {
                //c.Width = 200;
                width += c.Width;
            }
            int fixedWidth = width;
            stt.Width = fixedWidth;
            stt.Height = 200*stt.RowCount;// stt.GetRowDisplayRectangle(stt.NewRowIndex, true).Bottom + stt.GetRowDisplayRectangle(stt.NewRowIndex, false).Height;
            */

               // Form newForm = new Form();
               // stt.Dock = DockStyle.Fill;

            /*

            newForm.Controls.Add(stt);
            newForm.Size = stt.Size;
            newForm.BackColor = Color.White;
            newForm.Show();

             */
            Netron.NetronLight.Demo.STTForm newform = new Netron.NetronLight.Demo.STTForm();
            newform.dataGridView1.DataSource = getSTT(cfd);
            newform.dataGridView1.ReadOnly = true;
            newform.Show();
        }
        public static void displayChart(DDTDiagram dfd)
        {
            DirectedPathNode root = getDirectedPath(dfd);

            ACNode acRoot = getArchitectureChart(root);

            TreeData.TreeDataTableDataTable dtTree = new TreeData.TreeDataTableDataTable();
            acRoot.getTree(dtTree);
            /*dtTree.AddTreeDataTableRow("12", "", "System", "");
            dtTree.AddTreeDataTableRow("1", "12", "Input", "");
            dtTree.AddTreeDataTableRow("2", "12", "Process", "");
            dtTree.AddTreeDataTableRow("3", "12", "Output", "");
            dtTree.AddTreeDataTableRow("4", "1", "3000", "");
            dtTree.AddTreeDataTableRow("5", "1", "3001", "");
            dtTree.AddTreeDataTableRow("6", "2", "3000", "");
            dtTree.AddTreeDataTableRow("7", "4", "4000", "");
            dtTree.AddTreeDataTableRow("8", "4", "4001", "");
            */

            TreeBuilder t = new TreeBuilder(dtTree);
            //Now - Generate the tree itself
            Image i = Image.FromStream(
                t.GenerateTree(acRoot.id,
                System.Drawing.Imaging.ImageFormat.Bmp));
            i.Save("C://test.bmp");

            //ExecuteCommand("C://test.bmp", 100);
            PictureBox pb = new PictureBox();
            pb.SizeMode = PictureBoxSizeMode.AutoSize;
            pb.Image = i;

            Form newForm = new Form();
            newForm.Controls.Add(pb);
            newForm.AutoSize = true;
            newForm.BackColor = Color.White;
            newForm.Show();
        }
        public static DirectedPathNode getDirectedPath(DDTDiagram dfd)
        {
            DirectedPathNode root = null;
            DirectedPathNode left = null;
            DirectedPathNode right = null;

            // method to produce the list is to do so by brute force, iterate
            // over the existing relations until all are accounted for or 1000
            // tries have been made;
            int timeout = 0;
            List<DDTRelation> totalRelations = new List<DDTRelation>();
            List<DirectedPathNode> nodes = new List<DirectedPathNode>();

            // Step 1. retrieve all of the relations
            foreach (int i in dfd.RelIDList)
            {
                totalRelations.Add(DDTHelper.manager.project.getDDTRelation(i));
            }

            // Step 2. loop until the relations are accounted for or a timeout.

            // create an arbitrary element in the total tree.
            DDTRelation first = totalRelations[0];
            totalRelations.RemoveAt(0);
            left = new DirectedPathNode(DDTHelper.manager.project.getDDTObject(first.from.objectId).name);
            right = new DirectedPathNode(DDTHelper.manager.project.getDDTObject(first.to.objectId).name);
            left.addNode(right);
            nodes.Add(left);
            nodes.Add(right);

            // now add relations as we can to build the tree.
            int index = 0;

                bool canUse = true; // jsut for logic.
            while ((totalRelations.Count > 0) && (timeout < 1000))
            {
                if(!canUse)
                {
                    index++;
                    if (index >= totalRelations.Count)
                    {
                        index = 0;
                    }
                }
                canUse = false;
                // always remove from top of list
                DDTRelation next = totalRelations[0];

                for(int i =0;i<nodes.Count;i++)
                {
                    if (canUse)
                    {
                        continue;
                    }
                    DirectedPathNode current = nodes[i];
                    // case where the currently selected node in in the relations in the from position.
                    if (current.name == DDTHelper.manager.project.getDDTObject(next.from.objectId).name)
                    {
                        right = new DirectedPathNode(DDTHelper.manager.project.getDDTObject(next.to.objectId).name);
                        if (nodes.Contains(right))
                        {
                            // if the right already exists we just need to add the relation.
                            right = nodes.ElementAt(nodes.IndexOf(right));
                            current.addNode(right);
                        }
                        else
                        {
                            // we actually need to create the node.
                            current.addNode(right);
                            nodes.Add(right);
                        }
                        totalRelations.RemoveAt(index); // remove the handled relation.
                        canUse = true;
                    }
                    // case where the currently selected node is in the to position.
                    else if (current.name == DDTHelper.manager.project.getDDTObject(next.to.objectId).name)
                    {
                        left = new DirectedPathNode(DDTHelper.manager.project.getDDTObject(next.from.objectId).name);
                        if (nodes.Contains(left))
                        {
                            // if the left already exists we just need to add the relation.
                            left = nodes.ElementAt(nodes.IndexOf(left));
                            left.addNode(current);
                        }
                        else
                        {
                            // we actually need to create the node.
                            current.addPreviousReference(left);
                            nodes.Add(left);
                        }

                        totalRelations.RemoveAt(index); // remove the handled relation.
                        canUse = true;
                    }

                }

            }

            // Step 3: find the root.
            root = nodes[0];
            while (root.previous[MAIN_PATH] != null)
            {
                root = root.previous[MAIN_PATH];
            }

            return root;
        }
示例#5
0
        static DataTable getSTT(DDTDiagram cfd)
        {
            DataTable table = new DataTable();
            table.Columns.Add("Present State", typeof(string));
            table.Columns.Add("Event", typeof(string));
            table.Columns.Add("Action", typeof(string));
            table.Columns.Add("Next State", typeof(string));

            // TODO Panos- add more logic.

            foreach (int relationID in cfd.RelIDList)
            {
                DataRow newRow = table.NewRow();

                // get Relation
                DDTRelation relation = DDTHelper.manager.project.getDDTRelation(relationID);

                // get source name
                string presentState = DDTHelper.manager.project.getDDTObject(relation.from.objectId).name;
                string eventName = relation.text.from;
                string actionName = relation.text.middle;
                string nextState = DDTHelper.manager.project.getDDTObject(relation.to.objectId).name;
                // get destination name

                newRow["Present State"] = presentState;
                newRow["Event"] = eventName;
                newRow["Action"] = actionName;
                newRow["Next State"] = nextState;

                table.Rows.Add(newRow);
            }
            return table;
        }
示例#6
0
 public void addDiagram(DDTDiagram diagram)
 {
     this.diagrams.Add(diagram);
 }
        public static void displayChart(DDTDiagram dfd, int processingStartID, int outputStartID)
        {
            // first lets get the directed graph from the DFD
            DirectedPathNode root = TransactionDFDConverter.getDirectedPath(dfd);
            string processingStart = DDTHelper.manager.project.getDDTObject(processingStartID).ToString();
            string outputStart = DDTHelper.manager.project.getDDTObject(outputStartID).ToString();

            ACNode nullRoot = new ACNode("null root");
            ACNode acRoot = new ACNode("SYSTEM", nullRoot);
            ACNode input = new ACNode("INPUT", acRoot);
            ACNode processing = new ACNode("PROCESSING", acRoot);
            ACNode output = new ACNode("OUTPUT", acRoot);

            acRoot.addChild(input);
            acRoot.addChild(processing);
            acRoot.addChild(output);

            DirectedPathNode current = root;
            // build the input tree.
            while (current.name != processingStart)
            {
                ACNode newNode = new ACNode(current.name, input);
                input.addChild(newNode);
                current = current.next[0];
            }
            // build the processing tree.
            while (current.name != outputStart)
            {
                ACNode newNode = new ACNode(current.name, processing);
                processing.addChild(newNode);
                current = current.next[0];
            }
            // build output tree.
            while (current != null)
            {
                ACNode newNode = new ACNode(current.name, output);
                output.addChild(newNode);
                current = current.next[0];
            }

            // actually create the architecture chart.
            TreeData.TreeDataTableDataTable dtTree = new TreeData.TreeDataTableDataTable();
            acRoot.getTree(dtTree);

            TreeBuilder t = new TreeBuilder(dtTree);
            //Now - Generate the tree itself
            Image i = Image.FromStream(
                t.GenerateTree(acRoot.id,
                System.Drawing.Imaging.ImageFormat.Bmp));
            i.Save("C://test.bmp");

            //ExecuteCommand("C://test.bmp", 100);
            PictureBox pb = new PictureBox();
            pb.SizeMode = PictureBoxSizeMode.AutoSize;
            pb.Image = i;

            Form newForm = new Form();
            newForm.Controls.Add(pb);
            newForm.AutoSize = true;
            newForm.BackColor = Color.White;
            newForm.Show();
        }
        //assume this Diagram already has a name and type
        //public DDTDiagram(string name, DDT_Diagram_Type type, List<int> ObjIDList, List<int> RelIDList)
        public void saveDiagram(Netron.NetronLight.Win.DiagramControl diagramControl, DDTDiagram diagram)
        {
            List<int> objectListBefore = new List<int>();
            List<int> relListBefore = new List<int>();
            List<int> objectListCurrent = new List<int>();
            List<int> relListCurrent = new List<int>();

            foreach (DDTObjectReference objref in diagram.ObjRefList)
            {
                objectListBefore.Add(objref.ID);
            }
            foreach (int rel in diagram.RelIDList)
            {
                relListBefore.Add(rel);
            }

            diagram.ObjRefList.Clear();
            diagram.RelIDList.Clear();

            foreach (Netron.NetronLight.IDDTDiagramEntity tempObj in diagramControl.controller.Model.Paintables)
            {
                if (tempObj.GetType().IsSubclassOf(typeof(Netron.NetronLight.IDDTObject)))
                {
                    //if it's the first time see an Smallobject, assign an ID and add to list
                    if (tempObj.GetType().IsSubclassOf(typeof(Netron.NetronLight.SmallObject)))
                    {
                        if (!DDTObjectFound((Netron.NetronLight.IDDTObject)tempObj))
                        {
                            //MessageBox.Show("SmallObject:" +((Netron.NetronLight.SmallObject)tempObj).ID );
                            //add to obj list
                            this.project.objects.Add(CanvasToDDTObject((Netron.NetronLight.IDDTObject)tempObj));
                        }
                        updateDDTObject((Netron.NetronLight.IDDTObject)tempObj);
                    }
                    else
                    {
                       updateDDTObject((Netron.NetronLight.IDDTObject)tempObj);

                    }
                    diagram.ObjRefList.Add(new DDTObjectReference(((Netron.NetronLight.IDDTObject)tempObj).ID, ((Netron.NetronLight.IDDTObject)tempObj).Location));
                }
            }

            foreach (Netron.NetronLight.IDDTDiagramEntity tempRel in diagramControl.controller.Model.Paintables)
            {
                if (tempRel.GetType().Equals(typeof(Netron.NetronLight.DDTConnection)))
                {
                    //if first created Netron connection, save it. else just update.
                    //if (((Netron.NetronLight.DDTConnection)tempRel).ID <= 0)
                    if(!DDTRelationFound((Netron.NetronLight.DDTConnection)tempRel))
                    {
                        ((Netron.NetronLight.DDTConnection)tempRel).ID = DDT.staticId.getid();
                        DDT.DDTRelation rel = DDTConnectionToRelationObj((Netron.NetronLight.DDTConnection)tempRel);
                        rel.diagramType = diagram.type;
                        //rel.parentDiagramID = diagram.ID;
                        this.project.relations.Add(rel);
                    }
                    else
                    {

                         updateDDTRelation((Netron.NetronLight.DDTConnection)tempRel);

                    }
                       //MessageBox.Show("new DDTRelation saved:"+rel.ID);
                       //MessageBox.Show("Obj " + tempRel.ToString());

                    diagram.RelIDList.Add(((Netron.NetronLight.DDTConnection)tempRel).ID);
                }
            }

            //remove other objects and relations in the project when they are removed from the canvas
            foreach (DDTObjectReference objref in diagram.ObjRefList)
            {
                objectListCurrent.Add(objref.ID);
            }
            foreach (int rel in diagram.RelIDList)
            {
                relListCurrent.Add(rel);
            }

            //if an Other object is not in the current objectreference, then delete it
            foreach (int tmpobj in objectListBefore)
            {
                if (!objectListCurrent.Contains(tmpobj))
                {
                    DDTObject objToDel = getDDTObjectById(tmpobj, project.objects);
                    if (!objToDel.type.Equals(DDT_Obj_Type.ADT) && !objToDel.type.Equals(DDT_Obj_Type.COBJECT) && !objToDel.type.Equals(DDT_Obj_Type.SMOBJECT))
                    {
                        project.objects.Remove(objToDel);

                    }
                }
            }
            foreach (int tmprel in relListBefore)
            {
                if (!relListCurrent.Contains(tmprel))
                {
                    DDTRelation RelToDel = getDDTRelationById(tmprel, project.relations);
                    project.relations.Remove(RelToDel);
                }
            }

            foreach(DDTRelation tmpRel in project.relations)
            {
                if (!DDTObjectFound(tmpRel.from.objectId) || !DDTObjectFound(tmpRel.to.objectId))
                {
                    project.relations.Remove(tmpRel);
                }
             }
        }
 public void removeDiagram(DDTDiagram diagram)
 {
     foreach (int relID in diagram.RelIDList)
     {
         removeDDTRelationById(relID, project.relations);
     }
     foreach (DDTObjectReference objr in diagram.ObjRefList)
     {
         DDTObject obj = getDDTObjectById(objr.ID, project.objects);
         if (obj.type != DDT_Obj_Type.ADT && obj.type != DDT_Obj_Type.COBJECT && obj.type != DDT_Obj_Type.SMOBJECT)
         {
             removeDDTObjectById(objr.ID, project.objects);
         }
     }
     this.project.diagrams.Remove(diagram);
 }
        public void LoadDiagram(Netron.NetronLight.Win.DiagramControl diagramControl, DDTDiagram diagram)
        {
            diagramControl.controller.Model.Clear();

            foreach (DDTObjectReference objRef in diagram.ObjRefList)
            {
                //get DDTObject

                DDTObject temp = getDDTObjectById(objRef.ID, project.objects);
                Netron.NetronLight.IDDTObject shape = DDTObjectToCanvas(temp, objRef.Location);

                diagramControl.controller.Model.AddShape(shape);

                //MessageBox.Show(shape.ToString());

            }

            foreach (int relId in diagram.RelIDList)
            {

                //MessageBox.Show("rel loaded: "+relId);
                //get DDTObject
                DDTRelation temp = getDDTRelationById(relId, project.relations);

                //get connection
                Netron.NetronLight.DDTConnection connection = DDTRelationToCanvas(temp, diagramControl);

                //MessageBox.Show("rel loaded fin");
                connection.ID = temp.ID;

                ////////////////////////////////////
                diagramControl.controller.Model.AddConnection(connection);

                //add text : from middle to
                if (temp.text != null)
                {
                    addConnectionText(temp, connection, diagramControl);
                }

              // MessageBox.Show(temp.from.objectId.ToString());
               // MessageBox.Show(temp.to.objectId.ToString());
            }
        }