public EditTernaryRelationship(RelationshipShape relationship) { InitializeComponent(); Relationship = new RelationshipShape(relationship.sName, new Point(panelDoubleBuffered1.Width / 2, panelDoubleBuffered1.Height / 2), relationship.type); SelectedEntity1 = new EntityShape(relationship.cardinalities[0].Entity.sName, new Point(panelDoubleBuffered1.Width / 2, ThongSo.ShapeH / 2), relationship.cardinalities[0].Entity.type); SelectedEntity2 = new EntityShape(relationship.cardinalities[1].Entity.sName, new Point(panelDoubleBuffered1.Width / 2 - ThongSo.ShapeW * 3/2, panelDoubleBuffered1.Height - ThongSo.ShapeH/2), relationship.cardinalities[1].Entity.type); SelectedEntity3 = new EntityShape(relationship.cardinalities[2].Entity.sName, new Point(panelDoubleBuffered1.Width / 2 + ThongSo.ShapeW * 3/2, panelDoubleBuffered1.Height - ThongSo.ShapeH/2), relationship.cardinalities[2].Entity.type); cardi1 = Relationship.CreateCardinality(SelectedEntity1, relationship.cardinalities[0].MinCardinality, relationship.cardinalities[0].MaxCardinality); cardi2 = Relationship.CreateCardinality(SelectedEntity2, relationship.cardinalities[1].MinCardinality, relationship.cardinalities[1].MaxCardinality); cardi3 = Relationship.CreateCardinality(SelectedEntity3, relationship.cardinalities[2].MinCardinality, relationship.cardinalities[2].MaxCardinality); panelDoubleBuffered1.Controls.Add(Relationship); panelDoubleBuffered1.Controls.Add(SelectedEntity1); panelDoubleBuffered1.Controls.Add(SelectedEntity2); panelDoubleBuffered1.Controls.Add(SelectedEntity3); panelDoubleBuffered1.Refresh(); int min1, max1, min2, max2, min3, max3; min1 = Relationship.cardinalities[0].MinCardinality; max1 = Relationship.cardinalities[0].MaxCardinality; min2 = Relationship.cardinalities[1].MinCardinality; max2 = Relationship.cardinalities[1].MaxCardinality; min3 = Relationship.cardinalities[2].MinCardinality; max3 = Relationship.cardinalities[2].MaxCardinality; setCardinality(min1, max1, imageComboBoxEdit1); setCardinality(min2, max2, imageComboBoxEdit2); setCardinality(min3, max3, imageComboBoxEdit3); showText(); }
public AddCardinality(RelationshipShape relationship) { InitializeComponent(); Relationship = new RelationshipShape(relationship.sName, new Point(panelDoubleBuffered1.Width / 2, panelDoubleBuffered1.Height / 2), relationship.type); SelectedEntity1 = new EntityShape(relationship.cardinalities[0].Entity.sName, new Point(panelDoubleBuffered1.Width / 2 - ThongSo.ShapeW * 3/2, panelDoubleBuffered1.Height / 2), relationship.cardinalities[0].Entity.type); SelectedEntity2 = new EntityShape(relationship.cardinalities[1].Entity.sName, new Point(panelDoubleBuffered1.Width / 2 + ThongSo.ShapeW * 3/2, panelDoubleBuffered1.Height / 2), relationship.cardinalities[1].Entity.type); cardi1 = Relationship.CreateCardinality(SelectedEntity1, relationship.cardinalities[0].MinCardinality, relationship.cardinalities[0].MaxCardinality); cardi2 = Relationship.CreateCardinality(SelectedEntity2, relationship.cardinalities[1].MinCardinality, relationship.cardinalities[1].MaxCardinality); panelDoubleBuffered1.Controls.Add(Relationship); panelDoubleBuffered1.Controls.Add(SelectedEntity1); panelDoubleBuffered1.Controls.Add(SelectedEntity2); panelDoubleBuffered1.Refresh(); int min1, max1, min2, max2; min1 = Relationship.cardinalities[0].MinCardinality; max1 = Relationship.cardinalities[0].MaxCardinality; min2 = Relationship.cardinalities[1].MinCardinality; max2 = Relationship.cardinalities[1].MaxCardinality; if (min1 == 0 && max1 == 1) imageComboBoxEdit1.SelectedIndex = 0; if (min1 == 1 && max1 == 1) imageComboBoxEdit1.SelectedIndex = 1; if (min1 == 0 && max1 == -1) imageComboBoxEdit1.SelectedIndex = 2; if (min1 == 1 && max1 == -1) imageComboBoxEdit1.SelectedIndex = 3; if (min2 == 0 && max2 == 1) imageComboBoxEdit2.SelectedIndex = 0; if (min2 == 1 && max2 == 1) imageComboBoxEdit2.SelectedIndex = 1; if (min2 == 0 && max2 == -1) imageComboBoxEdit2.SelectedIndex = 2; if (min2 == 1 && max2 == -1) imageComboBoxEdit2.SelectedIndex = 3; showText(); }
//Auto Layout public void AutoLayout() { //B1: Lấy Entity Bậc cao nhất EntityShape MaxEntity = new EntityShape(); int maxbac = -1; foreach (Control c in this.Controls) { if (c.GetType().Name == "EntityShape") { int bac = degreeOfEntity((EntityShape)c); if (bac > maxbac) { maxbac = bac; MaxEntity = (EntityShape)c; } } } //B2: Vẽ con của nó SetLocationTree(MaxEntity, maxbac, 1); this.Refresh(); }
public INotation createNotation() { EntityShape entity = new EntityShape(); entity.sName = this.name; entity.type = this.type; entity.Location = new Point(this.x, this.y); entity.Size = new Size(this.w, this.h); return (INotation)entity; }
//Create SubTypeConnector private void CreateSubTypeConnector(EntityShape supertype) { if (supertype.SubtypeConnector == null) { EntityShape subtype = new EntityShape(); subtype.CenterPoint = this.PointToClient(Control.MousePosition); Point CenterTwoEntity = new Point(Math.Abs(supertype.CenterPoint.X + subtype.CenterPoint.X) / 2, Math.Abs(supertype.CenterPoint.Y + subtype.CenterPoint.Y) / 2); SubTypeConnector subconnector = new SubTypeConnector(supertype, subtype, CenterTwoEntity, SubTypeCompleteness, SubTypeDisjointness); supertype.SubtypeConnector = subconnector; this.Controls.Add(subconnector); this.Controls.Add(subtype); } else { if (supertype.SubtypeConnector.completeness == SubTypeCompleteness && supertype.SubtypeConnector.disjointness == SubTypeDisjointness) { EntityShape subtype = new EntityShape(); subtype.CenterPoint = this.PointToClient(Control.MousePosition); supertype.SubtypeConnector.addSubType((EntityShape)subtype); this.Controls.Add(subtype); } else { DevExpress.XtraEditors.XtraMessageBox.Show("The constraint of the Sub Type you want to add must be the same to existed constraint in this Super Type", "Warning"); } } }
//My function public void CancelDrawing() { isDrawing = false; isDrawEntity = false; isDrawingAtt = false; isDrawRelationship = false; isDrawSubType = false; this.Cursor = Cursors.Default; setAllControlToDefaultCursor(); First_Mouse_Pos.X = -1; First_Mouse_Pos.Y = -1; Last_Mouse_Pos.X = -1; Last_Mouse_Pos.Y = -1; First_Mouse_Click = false; Second_Mouse_Click = false; Third_Mouse_Click = false; FirstEntity = null; SecondEntity = null; ThirdEntity = null; ((MainForm)TopLevelControl).CancelDrawing(); this.Refresh(); }
//Shape (User control) Event void shapeMouseDown(object sender, MouseEventArgs e) { if (isNaming) { AffectingShape.endEditName(); return; } ShapeBase currentCtrl = (ShapeBase)sender; //Đang vẽ relationship if (e.Button == MouseButtons.Left && isDrawing && isDrawRelationship) { //Nếu chưa có điểm đầu if (First_Mouse_Click == false) { if (currentCtrl is EntityShape) { First_Mouse_Click = true; //Tracking First position for Drawing Virtual Line First_Mouse_Pos.X = e.X + currentCtrl.Location.X; First_Mouse_Pos.Y = e.Y + currentCtrl.Location.Y; FirstEntity = (EntityShape)currentCtrl; if (degreeOfRelationship == 1) { //Create Unary Relationship CreateUnaryRelationship(); CancelDrawing(); return; } } else CancelDrawing(); } else { //Ðã có điểm đầu, click lần thứ 2 if (Second_Mouse_Click == false) { if (currentCtrl is EntityShape) { Second_Mouse_Click = true; SecondEntity = (EntityShape)currentCtrl; if (degreeOfRelationship == 2) { //Create Binary Relationship CreateBinaryRelationship(); CancelDrawing(); return; } } else CancelDrawing(); } else { //Ðã có điểm thứ 1 và 2, click lần 3 if (Third_Mouse_Click == false) { if (currentCtrl is EntityShape) { Third_Mouse_Click = true; ThirdEntity = (EntityShape)currentCtrl; if (degreeOfRelationship == 3) { //Create Ternary Relationship CreateTernaryRelationship(); CancelDrawing(); return; } } else CancelDrawing(); } else CancelDrawing(); } } }//End Ðang vẽ relationship //Lưu vết lại Shape đang được tác động (Click) //và set cho shape đó nằm trên cùng AffectingShape = currentCtrl; this.Controls.SetChildIndex(AffectingShape, 0); // click trái: Resizing hoặc Moving hoặc Selecting // Nếu chuột ở mép (border) của Shape thì là resizing // bình thường thì moving if (e.Button == MouseButtons.Left && !isDrawing) { Last_Mouse_Pos.X = e.X; Last_Mouse_Pos.Y = e.Y; if ((e.X + 5) > currentCtrl.Width || (e.Y + 5) > currentCtrl.Height) isResizing = true; else isMoving = true; } // click phải: hiện context menu else if (e.Button == MouseButtons.Right) { ContextMenuStrip ctmn = getContexMenuForControl(currentCtrl); ctmn.Show(currentCtrl, new Point(e.X, e.Y)); } this.Invalidate(); }
void SetLocationTree(EntityShape entity, int degree, int line) { entity.Location = new Point(this.Width / 2 - entity.Width / 2, 150 * line); int stepX = this.Width / (degree + 1); for (int i = 0; i < 4; i++) { for (int j = 0; j < entity.cardinalities[i].Count; j++) { CardinalityShape cardi = new CardinalityShape(); foreach (CardinalityShape cardi2 in entity.cardinalities[i][j].Relationship.cardinalities) { if (cardi2 != entity.cardinalities[i][j]) cardi = cardi2; } EntityShape entity2 = cardi.Entity; entity2.Location = new Point(stepX, 150 * (line + 1)); stepX += this.Width / (degree + 1); Point centerEntity1 = new Point(entity.Location.X + entity.Width / 2, entity.Location.Y + entity.Height / 2); Point centerEntity2 = new Point(entity2.Location.X + entity2.Width / 2, entity2.Location.Y + entity2.Height / 2); Point center = new Point(Math.Abs(centerEntity1.X + centerEntity2.X) / 2, Math.Abs(centerEntity1.Y + centerEntity2.Y) / 2); cardi.Relationship.Location = new Point(center.X - cardi.Relationship.Width / 2, center.Y - cardi.Relationship.Height / 2); } } }
int degreeOfEntity(EntityShape entity) { int bac = 0; bac += entity.cardinalities[0].Count; bac += entity.cardinalities[1].Count; bac += entity.cardinalities[2].Count; bac += entity.cardinalities[3].Count; return bac; }
public override ShapeBase Clone() { EntityShape entity = new EntityShape(); entity.sName = sName; entity.type = type; entity.Size = this.Size; entity.Location = Location; foreach (AttributeShape att in attributes) { entity.addAttribute((AttributeShape)att.Clone()); } for (int i = 0; i < 4; i++) foreach (CardinalityShape cardi in cardinalities[i]) { entity.AddCardiPlace((CardinalityShape)cardi.Clone()); } return (ShapeBase)entity; }
public CardinalityShape(EntityShape en) { Entity = en; }
public CardinalityShape CreateCardinality(EntityShape en, int min, int max) { CardinalityShape cardi = new CardinalityShape(en); cardi.setValue(min, max); cardinalities.Add(cardi); cardi.Relationship = this; en.AddCardiPlace(cardi); this.AddCardiPlace(cardi); cardi.Disposed += new EventHandler(cardi_Disposed); return cardi; }
public CardinalityShape(EntityShape en) { Entity = en; }