//create a new diagram public DDTDiagram newDiagram(string name,DDT_Diagram_Type type) { string diagramName; if (name == null || name.Length == 0) { diagramName = "new_diagram"; } else diagramName = name; DDT.DDTDiagram newDiagram = new DDT.DDTDiagram(diagramName,type); this.project.addDiagram(newDiagram); return newDiagram; }
public List<DDT.DDTDiagram> getORV(int objID) { List<DDT.DDTDiagram> ORVList = new List<DDTDiagram>(); double max = 4.0; //6 relations a group DDT.DDTObject obj = getDDTObjectById(objID, project.objects); string diaName = obj.name + "_ORV"; List<DDT.DDTRelation> relList = new List<DDTRelation>(); //get all ERD relations related to the object we want foreach (DDTRelation rel in project.relations) { if (rel.diagramType == DDT_Diagram_Type.ERD) { if (rel.from.objectId == objID || rel.to.objectId == objID) { relList.Add(rel); } } } //6+1 obj in a group at maximum int groups = (int)Math.Ceiling((double)(relList.Count) / max); int remainder = relList.Count%(int)max; //last group has such many relations int i; int secondObjID; DDTRelation tmpRel; DDTObject tmpObj; DDT.DDT_Obj_Type t; //get diagram for each group except the last group if (groups >= 2) { for (i = 1; i < groups; i++) { string diaNamei = diaName + "_" + i.ToString(); DDT.DDTDiagram diagram = new DDT.DDTDiagram(diaNamei, DDT_Diagram_Type.ORV); //locate the first object diagram.ObjRefList.Add(new DDTObjectReference(objID, new Point(50, 210))); //get 6 relations for each group for (int k = (int)max * (i - 1); k < (int)max * i; k++) { if (relList[k].from.objectId == objID && relList[k].to.objectId != objID) { secondObjID = relList[k].to.objectId; } else if (relList[k].to.objectId == objID && relList[k].from.objectId != objID) { secondObjID = relList[k].from.objectId; } else { //it's a link to itself tmpRel = getDDTRelationById(relList[k].ID,project.relations).deepClone(); tmpRel.diagramType = DDT_Diagram_Type.ORV; project.relations.Add(tmpRel); diagram.RelIDList.Add(tmpRel.ID); continue; } t = getDDTObjectById(secondObjID, project.objects).type; if (t == DDT_Obj_Type.ADT || t == DDT_Obj_Type.COBJECT || t == DDT_Obj_Type.SMOBJECT) { ; } else {//if not 3 main type. then create need object and add to list tmpObj = getDDTObjectById(secondObjID, project.objects).deepClone(); project.objects.Add(tmpObj); secondObjID = tmpObj.ID; } Point p = getLocator(k); //add relations in group i to diagram i. /* * change connector position */ tmpRel = getDDTRelationById(relList[k].ID, project.relations).deepClone(); tmpRel.diagramType = DDT_Diagram_Type.ORV; //arrange connectors if (tmpRel.from.objectId == objID) { tmpRel.from.pos = DDT.Conn_Position.RIGHT; tmpRel.to.pos = DDT.Conn_Position.LEFT; //change to the second object tmpRel.to.objectId = secondObjID; } else { tmpRel.from.pos = DDT.Conn_Position.LEFT; tmpRel.to.pos = DDT.Conn_Position.RIGHT; tmpRel.from.objectId = secondObjID; } project.relations.Add(tmpRel); diagram.RelIDList.Add(tmpRel.ID); diagram.ObjRefList.Add(new DDTObjectReference(secondObjID, p)); } ORVList.Add(diagram); } //last diagram string lastDiaName = diaName + "_" + groups.ToString(); DDT.DDTDiagram diagramLast = new DDT.DDTDiagram(lastDiaName, DDT_Diagram_Type.ORV); diagramLast.ObjRefList.Add(new DDTObjectReference(objID, new Point(50, 210))); for (i = remainder; i > 0; i--) { int index = relList.Count - i; if (relList[index].from.objectId == objID && relList[index].to.objectId != objID) { secondObjID = relList[index].to.objectId; } else if (relList[index].to.objectId == objID && relList[index].from.objectId != objID) { secondObjID = relList[index].from.objectId; } else { tmpRel = getDDTRelationById(relList[index].ID, project.relations).deepClone(); tmpRel.diagramType = DDT_Diagram_Type.ORV; project.relations.Add(tmpRel); diagramLast.RelIDList.Add(tmpRel.ID); continue; } t = getDDTObjectById(secondObjID, project.objects).type; if (t == DDT_Obj_Type.ADT || t == DDT_Obj_Type.COBJECT || t == DDT_Obj_Type.SMOBJECT) { ; } else {//if not 3 main type. then create need object and add to list tmpObj = getDDTObjectById(secondObjID, project.objects).deepClone(); project.objects.Add(tmpObj); secondObjID = tmpObj.ID; } Point p1 = getLocator(i); /* * change connector position */ tmpRel = getDDTRelationById(relList[index].ID, project.relations).deepClone(); tmpRel.diagramType = DDT_Diagram_Type.ORV; if (tmpRel.from.objectId == objID) { tmpRel.from.pos = DDT.Conn_Position.RIGHT; tmpRel.to.pos = DDT.Conn_Position.LEFT; //change to the second object tmpRel.to.objectId = secondObjID; } else { tmpRel.from.pos = DDT.Conn_Position.LEFT; tmpRel.to.pos = DDT.Conn_Position.RIGHT; tmpRel.from.objectId = secondObjID; } project.relations.Add(tmpRel); diagramLast.RelIDList.Add(tmpRel.ID); diagramLast.ObjRefList.Add(new DDTObjectReference(secondObjID, p1)); } ORVList.Add(diagramLast); } //if only 1 group else if (groups == 1) { if (remainder == 0) remainder = (int)max; string lastDiaName = diaName + "_" + groups.ToString(); DDT.DDTDiagram diagramLast = new DDT.DDTDiagram(lastDiaName, DDT_Diagram_Type.ORV); diagramLast.ObjRefList.Add(new DDTObjectReference(objID, new Point(50, 210))); for (i = remainder; i > 0; i--) { int index = relList.Count - i; if (relList[index].from.objectId == objID && relList[index].to.objectId != objID) { secondObjID = relList[index].to.objectId; } else if (relList[index].to.objectId == objID && relList[index].from.objectId != objID) { secondObjID = relList[index].from.objectId; } else { tmpRel = getDDTRelationById(relList[index].ID, project.relations).deepClone(); tmpRel.diagramType = DDT_Diagram_Type.ORV; project.relations.Add(tmpRel); diagramLast.RelIDList.Add(tmpRel.ID); continue; } t = getDDTObjectById(secondObjID, project.objects).type; if (t == DDT_Obj_Type.ADT || t == DDT_Obj_Type.COBJECT || t == DDT_Obj_Type.SMOBJECT) { ; } else {//if not 3 main type. then create need object and add to list tmpObj = getDDTObjectById(secondObjID, project.objects).deepClone(); project.objects.Add(tmpObj); secondObjID = tmpObj.ID; } Point p1 = getLocator(i); /* * change connector position */ tmpRel = getDDTRelationById(relList[index].ID, project.relations).deepClone(); tmpRel.diagramType = DDT_Diagram_Type.ORV; if (tmpRel.from.objectId == objID) { tmpRel.from.pos = DDT.Conn_Position.RIGHT; tmpRel.to.pos = DDT.Conn_Position.LEFT; //change to the second object tmpRel.to.objectId = secondObjID; } else { tmpRel.from.pos = DDT.Conn_Position.LEFT; tmpRel.to.pos = DDT.Conn_Position.RIGHT; tmpRel.from.objectId = secondObjID; } project.relations.Add(tmpRel); diagramLast.RelIDList.Add(tmpRel.ID); diagramLast.ObjRefList.Add(new DDTObjectReference(secondObjID, p1)); } ORVList.Add(diagramLast); } else { MessageBox.Show("No Object Relation found!!", "WARNING"); return null; } //add last Diagram return ORVList; }