public GraphicHelper(CachedRepository repository, Project project, Diagram tableDiagram, Display tableDisplay)
 {
     Project = project;
     Repository = repository;
     TableDiagram = tableDiagram;
     TableDisplay = tableDisplay;
 }
Пример #2
0
        private void fileLoadStatisticsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Delete all diagrams (with shapes)
            List<Diagram> diagrams = new List<Diagram>(project1.Repository.GetDiagrams());
            for (int i = diagrams.Count - 1; i >= 0; --i)
                project1.Repository.DeleteAll(diagrams[i]);

            Dictionary<string, RectangleBase> shapeDict = new Dictionary<string, RectangleBase>(1000);
            Diagram diagram = new Diagram("D1");

            int x = 10;
            int y = 500;
            string statisticsFilePath = Path.Combine(GetBasicTutorialPath(), @"Sample Data\Small.txt");
            TextReader reader = new StreamReader(statisticsFilePath);
            string line = reader.ReadLine();
            while (line != null) {
                int idx1 = line.IndexOf(';');
                int idx2 = line.IndexOf(';', idx1 + 1);
                RectangleBase shape;
                string url = line.Substring(0, idx1);
                if (!shapeDict.TryGetValue(url, out shape)) {
                    shape = (RectangleBase)project1.ShapeTypes["Ellipse"].CreateInstance();
                    shape.Width = 100;
                    shape.Height = 60;
                    shape.X = x + 50;
                    shape.Y = y + 50;
                    x += 120;
                    if (x > 1200) {
                        x = 10;
                        y += 70;
                    }
                    shape.SetCaptionText(0, Path.GetFileNameWithoutExtension(url));
                    shapeDict.Add(url, shape);
                    diagram.Shapes.Add(shape);
                }
                url = line.Substring(idx1 + 1, idx2 - idx1 - 1);
                if (!shapeDict.TryGetValue(url, out shape)) {
                    shape = (RectangleBase)project1.ShapeTypes["Ellipse"].CreateInstance();
                    shape.Width = 100;
                    shape.Height = 60;
                    shape.X = x + 50;
                    shape.Y = y + 50;
                    x += 120;
                    if (x > 1200) {
                        x = 10;
                        y += 70;
                    }
                    shape.SetCaptionText(0, Path.GetFileNameWithoutExtension(url));
                    shapeDict.Add(url, shape);
                    diagram.Shapes.Add(shape);
                }
                line = reader.ReadLine();
            }
            reader.Close();
            cachedRepository1.InsertAll(diagram);

            display1.Diagram = diagram;
        }
Пример #3
0
		private void ShowDisplayChildForm(Diagram diagram) {
			DisplayChildForm childForm = new DisplayChildForm();
			RegisterChildFormEvents(childForm);
			childForm.MdiParent = this;
			childForm.Display.DiagramSetController = diagramSetController;
			childForm.Display.Diagram = diagram;
			childForm.Show();

			displayChildForms.Add(diagram.Name, childForm);
		}
Пример #4
0
		private void fileLoadStatisticsToolStripMenuItem_Click(object sender, EventArgs e) {
			string appDir = Path.GetDirectoryName(Path.GetDirectoryName(Application.StartupPath));
			string statisticsFilePath = Path.GetFullPath(Path.Combine(appDir, @"Demo Programs\Tutorials\Basic\Sample Data\Small.txt"));

			Dictionary<string, RectangleBase> shapeDict = new Dictionary<string, RectangleBase>(1000);
			Diagram diagram = new Diagram("D1");

			int x = 10;
			int y = 500;
			TextReader reader = new StreamReader(statisticsFilePath);
			string line = reader.ReadLine();
			while (line != null) {
				int idx1 = line.IndexOf(';');
				int idx2 = line.IndexOf(';', idx1 + 1);
				RectangleBase shape;
				string url = line.Substring(0, idx1);
				if (!shapeDict.TryGetValue(url, out shape)) {
					shape = (RectangleBase)project1.ShapeTypes["Ellipse"].CreateInstance();
					shape.Width = 100;
					shape.Height = 60;
					shape.X = x + 50;
					shape.Y = y + 50;
					x += 120;
					if (x > 1200) {
						x = 10;
						y += 70;
					}
					shape.SetCaptionText(0, Path.GetFileNameWithoutExtension(url));
					shapeDict.Add(url, shape);
					diagram.Shapes.Add(shape);
				}
				url = line.Substring(idx1 + 1, idx2 - idx1 - 1);
				if (!shapeDict.TryGetValue(url, out shape)) {
					shape = (RectangleBase)project1.ShapeTypes["Ellipse"].CreateInstance();
					shape.Width = 100;
					shape.Height = 60;
					shape.X = x + 50;
					shape.Y = y + 50;
					x += 120;
					if (x > 1200) {
						x = 10;
						y += 70;
					}
					shape.SetCaptionText(0, Path.GetFileNameWithoutExtension(url));
					shapeDict.Add(url, shape);
					diagram.Shapes.Add(shape);
				}
				line = reader.ReadLine();
			}
			reader.Close();
			cachedRepository1.InsertDiagram(diagram);
			display1.Diagram = diagram;
		}
        public DiagramDisplayControl()
        {
            InitializeComponent();

            _xmlStore.DirectoryName = System.IO.Path.GetDirectoryName( Application.ExecutablePath );
            _xmlStore.FileExtension = ".nspj";

            _NShapeProject.Name = ".NET Diagram";
            _NShapeProject.AddLibrary( typeof( Ellipse ).Assembly, false );
            _NShapeProject.Create();

            _NShapeDiagram = new Diagram( "diagram" );
            _NShapeDiagram.Height = _NShapeDisplay.Height;
            _NShapeDiagram.Width = _NShapeDisplay.Width;

            _NShapeDisplay.Diagram = _NShapeDiagram;
        }
Пример #6
0
        public DiagramDisplayControl()
        {
            InitializeComponent();

            _xmlStore.DirectoryName = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
            _xmlStore.FileExtension = ".nspj";

            _NShapeProject.Name = ".NET Diagram";
            _NShapeProject.AddLibrary(typeof(Ellipse).Assembly, false);
            _NShapeProject.Create();

            _NShapeDiagram        = new Diagram("diagram");
            _NShapeDiagram.Height = _NShapeDisplay.Height;
            _NShapeDiagram.Width  = _NShapeDisplay.Width;



            _NShapeDisplay.Diagram = _NShapeDiagram;
        }
Пример #7
0
        public Form1()
        {
            InitializeComponent();

            // Initialize project with a shape library
            project.AddLibrary(typeof(ThickArrow).Assembly, false);
            // Add this application as model object library
            project.AddLibrary(GetType().Assembly, false);

            project.Name = "Model Mapping Demo";
            project.Create();

            // Create an instance of the test object (that implements IModelObject)
            Template template = project.Repository.GetTemplate("ThickArrow");
            MyBusinessObject model =  (MyBusinessObject)project.ModelObjectTypes["MyBusinessObjectType"].CreateInstance();
            InitPropertyMappings(template, model);

            // Create a diagram with a shape that is bound to a business object
            const string diagramName = "Demo Diagram";
            Diagram diagram = new Diagram(diagramName);

            // Create a shape from the prepared template
            ThickArrow shape = (ThickArrow)project.Repository.GetTemplate("ThickArrow").CreateShape();
            shape.MoveTo(diagram.Width / 2, diagram.Height / 2);
            shape.Width = 120;
            shape.HeadWidth = 60;
            shape.Height = 100;

            diagram.Shapes.Add(shape);
            project.Repository.Insert(shape.ModelObject);
            project.Repository.InsertAll(diagram);

            display1.LoadDiagram(diagramName);

            // Store model object to modify
            businessObj = shape.ModelObject as MyBusinessObject;
            // Update start values
            businessObj.MyBooleanProperty = checkBox.Checked;
            businessObj.MyIntegerProperty = (int)intTrackBar.Value;
            businessObj.MyFloatProperty = (float)floatTrackBar.Value;
        }
Пример #8
0
 /// <ToBeCompleted></ToBeCompleted>
 public RepositoryShapesEventArgs(IEnumerable<Shape> shapes, Diagram diagram)
 {
     if (shapes == null) throw new ArgumentNullException("shapes");
     SetShapes(shapes, diagram);
 }
Пример #9
0
 /// <ToBeCompleted></ToBeCompleted>
 public RepositoryShapeEventArgs(Shape shape, Diagram diagram)
 {
     if (shape == null) throw new ArgumentNullException("shape");
     this.shape = shape;
     this.diagram = diagram;
 }
Пример #10
0
		private void fileLoadStatisticsToolStripMenuItem_Click(object sender, EventArgs e) {
			string appDir = Path.GetDirectoryName(Path.GetDirectoryName(Application.StartupPath));
			string statisticsFilePath = Path.GetFullPath(Path.Combine(appDir, @"Demo Programs\Tutorials\Basic\Sample Data\Small.txt"));

			Dictionary<string, RectangleBase> shapeDict = new Dictionary<string, RectangleBase>(1000);
			Diagram diagram = new Diagram("D1");
			Template webPageTemplate = project1.Repository.GetTemplate("Web Page");

			int x = 10;
			int y = 500;
			TextReader reader = new StreamReader(statisticsFilePath);
			string line = reader.ReadLine();
			while (line != null) {
				int idx1 = line.IndexOf(';');
				int idx2 = line.IndexOf(';', idx1 + 1);
				string url = line.Substring(0, idx1);
				RectangleBase referringShape;
				if (!shapeDict.TryGetValue(url, out referringShape)) {
					referringShape = (RectangleBase)webPageTemplate.CreateShape();
					referringShape.Width = 100;
					referringShape.Height = 60;
					referringShape.X = x + 50;
					referringShape.Y = y + 50;
					x += 120;
					if (x > 1200) {
						x = 10;
						y += 70;
					}
					referringShape.SetCaptionText(0, Path.GetFileNameWithoutExtension(url));
					shapeDict.Add(url, referringShape);
					diagram.Shapes.Add(referringShape);
				}
				url = line.Substring(idx1 + 1, idx2 - idx1 - 1);
				RectangleBase referredShape;
				if (!shapeDict.TryGetValue(url, out referredShape)) {
					referredShape = (RectangleBase)webPageTemplate.CreateShape();
					referredShape.Width = 100;
					referredShape.Height = 60;
					referredShape.X = x + 50;
					referredShape.Y = y + 50;
					x += 120;
					if (x > 1200) {
						x = 10;
						y += 70;
					}
					referredShape.SetCaptionText(0, Path.GetFileNameWithoutExtension(url));
					shapeDict.Add(url, referredShape);
					diagram.Shapes.Add(referredShape);
				}
				// Add the connection
				Polyline arrow = (Polyline)project1.ShapeTypes["Polyline"].CreateInstance();
				diagram.Shapes.Add(arrow);
				arrow.EndCapStyle = project1.Design.CapStyles.Arrow; 
				arrow.Connect(ControlPointId.FirstVertex, referringShape, ControlPointId.Reference);
				arrow.Connect(ControlPointId.LastVertex, referredShape, ControlPointId.Reference);
				//
				// Next line
				line = reader.ReadLine();
			}
			reader.Close();
			cachedRepository1.InsertDiagram(diagram);
			display1.Diagram = diagram;
		}
Пример #11
0
		public void TemplateTest() {
			Project project = new Project();
			project.Name = "Test";
			project.Repository = new CachedRepository();
			((CachedRepository)project.Repository).Store = RepositoryHelper.CreateXmlStore();
			project.Repository.Erase();
			project.Create();
			project.AddLibrary(typeof(Dataweb.NShape.GeneralShapes.Circle).Assembly);
			Template template = new Template("Template1", project.ShapeTypes["RoundedBox"].CreateInstance());
			((IPlanarShape)template.Shape).FillStyle = project.Design.FillStyles.Red;
			project.Repository.InsertTemplate(template);
			Diagram diagram = new Diagram("Diagram A");
			diagram.Shapes.Add(template.CreateShape(), 1);
			project.Repository.InsertDiagram(diagram);
			Assert.ReferenceEquals(((IPlanarShape)diagram.Shapes.Bottom).FillStyle, ((IPlanarShape)template.Shape).FillStyle);
			IFillStyle fillStyle = project.Design.FillStyles.Green;
			((IPlanarShape)template.Shape).FillStyle = fillStyle;
			Assert.ReferenceEquals(((IPlanarShape)diagram.Shapes.Bottom).FillStyle, ((IPlanarShape)template.Shape).FillStyle);
			project.Repository.SaveChanges();
			project.Close();
			//
			project.Open();
			template = project.Repository.GetTemplate("Template1");
			diagram = project.Repository.GetDiagram("Diagram A");
			Assert.AreEqual(((IPlanarShape)diagram.Shapes.Bottom).FillStyle.BaseColorStyle, ((IPlanarShape)template.Shape).FillStyle.BaseColorStyle);
			project.Close();
		}
Пример #12
0
        private void DisplayNewDiagram()
        {
            // Find a unique name for the new Diagram
            int N = 0;
            string newName;
            bool found;
            do {
                ++N;
                newName = string.Format("Diagram {0}", N);
                // Search name in list of diagrams
                found = false;
                foreach (Diagram d in project.Repository.GetDiagrams())
                    if (d.Name.Equals(newName, StringComparison.InvariantCultureIgnoreCase)) {
                        found = true;
                        break;
                    }
            } while (found);

            Diagram diagram = new Diagram(newName);
            CreateDiagramCommand cmd = new CreateDiagramCommand(diagram);
            project.ExecuteCommand(cmd);

            UpdateDiagramCombo();
            diagramComboBox.Text = newName;
        }
Пример #13
0
		private void loadWebStatisticsToolStripMenuItem_Click(object sender, EventArgs e) {
			string statsDir = Path.Combine("Demo Programs", Path.Combine("WebVisits", "Sample Web Statistics"));
			openFileDialog.Filter = "Web Statistics|*.xml|All files|*.*";
			openFileDialog.InitialDirectory = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Application.StartupPath)), statsDir);
			openFileDialog.FileName = string.Empty;
			if (openFileDialog.ShowDialog() == DialogResult.OK) {
				// Create a new diagram
				ShapeType boxType = project.ShapeTypes["Ellipse"];
				ShapeType multiLineType = project.ShapeTypes["Polyline"];
				
				Dictionary<int, RectangleBase> boxes = new Dictionary<int, RectangleBase>();
				List<Polyline> lines = new List<Polyline>();
				//
				// Create shapes for the web pages and connect them with lines
				XmlScanner scanner = new XmlScanner(openFileDialog.FileName);
				scanner.ReadElement();
				scanner.ReadElement("WebVisits");
				scanner.ReadChild("Pages");
				if (scanner.ReadChild("Page")) do {
					scanner.ReadAttribute(); // id attribute
					RectangleBase box = (RectangleBase)boxType.CreateInstance(pageTemplate);
					box.Width = 140;
					boxes.Add(scanner.IntValue, box);
					scanner.ReadAttribute();
					box.Text = scanner.StringValue;
				} while (scanner.ReadElement());
				scanner.ReadParent();
				if (scanner.ReadChild("Referral"))
					do {
						scanner.ReadAttribute(); // id1
						int id1 = scanner.IntValue;
						Shape shape1 = boxes[id1];
						scanner.ReadAttribute(); // id2
						int id2 = scanner.IntValue;
						Shape shape2 = boxes[id2];
						scanner.ReadAttribute(); // count
						int count = scanner.IntValue;
						Polyline line = (Polyline)multiLineType.CreateInstance();
						line.EndCapStyle = project.Design.CapStyles.Arrow;
						line.LineStyle = GetLineStyle(count);
						line.Connect(ControlPointId.FirstVertex, shape1, ControlPointId.Reference);
						line.Connect(ControlPointId.LastVertex, shape2, ControlPointId.Reference);
						lines.Add(line);
					} while (scanner.ReadElement());
				scanner.ReadParent();
				scanner.Close();
				//
				// Insert all shapes into the diagram
				int cnt = 0;
				foreach (Diagram d in project.Repository.GetDiagrams())
					++cnt;
				Diagram diagram = new Diagram(string.Format("WebVisits Diagram {0}", cnt));
				diagram.Width = 1000;
				diagram.Height = 1000;
				diagram.BackgroundImageLayout = Dataweb.NShape.ImageLayoutMode.Fit;
				foreach (RectangleBase b in boxes.Values)
					diagram.Shapes.Add(b, project.Repository.ObtainNewTopZOrder(diagram));
				foreach (Polyline l in lines)
					diagram.Shapes.Add(l, project.Repository.ObtainNewBottomZOrder(diagram));
				
				boxes.Clear();
				lines.Clear();
				//
				// Insert the diagram (including all shapes) into the repository
				project.Repository.InsertDiagram(diagram);
				//
				// Layout the shapes
				if (layouter == null)
					layouter = new RepulsionLayouter(project);
				layouter.SpringRate = 14;
				layouter.Repulsion = 7;
				layouter.RepulsionRange = 400;
				layouter.Friction = 0;
				layouter.Mass = 50;
				//
				layouter.AllShapes = diagram.Shapes;
				layouter.Shapes = diagram.Shapes;

				layouter.Prepare();
				layouter.Execute(10);
				layouter.Fit(50, 50, diagram.Width- 100, diagram.Height-100);
				//
				// Display the result
				display.Diagram = diagram;
			}
		}
Пример #14
0
 internal void SetShapes(IEnumerable<Shape> shapes, Diagram diagram)
 {
     this.shapes.Clear();
     foreach (Shape s in shapes) this.shapes.Add(s, diagram);
 }
Пример #15
0
 internal DiagramShapeCollection(Diagram owner, int capacity)
     : base(capacity)
 {
     if (owner == null) throw new ArgumentNullException("owner");
     this.owner = owner;
 }
Пример #16
0
 internal DiagramShapeCollection(Diagram owner)
     : this(owner, 1000)
 {
 }
Пример #17
0
        private void DeleteDiagram(Diagram diagram)
        {
            for (int i = diagramsDropDownButton.DropDown.Items.Count - 1; i >= 0; --i) {
                if (diagramsDropDownButton.DropDown.Items[i].Tag == diagram) {
                    diagramsDropDownButton.DropDown.Items[i].Click -= new EventHandler(diagramDropDownItem_Click);
                    diagramsDropDownButton.DropDown.Items.RemoveAt(i);

                    project.Repository.DeleteAll(diagram);
                    diagram.Clear();
                    diagram = null;
                }
            }

            if (display.Diagram == null && diagramsDropDownButton.DropDown.Items.Count > 0)
                display.Diagram = diagramsDropDownButton.DropDown.Items[0].Tag as Diagram;
            else {
                display.Refresh();
                diagramsDropDownButton.Text = "<No Diagrams>";
            }
        }
Пример #18
0
		public void BaseTest() {
			// -- Create a project --
			Project project = new Project();
			project.Name = "Test";
			project.Repository = new CachedRepository();
			((CachedRepository)project.Repository).Store = RepositoryHelper.CreateXmlStore();
			project.Repository.Erase();
			project.Create();

			project.AddLibrary(typeof(Dataweb.NShape.GeneralShapes.Circle).Assembly);
			//
			Diagram diagram = new Diagram("All Shapes");
			diagram.Width = 800;
			diagram.Height = 600;
			project.Repository.InsertDiagram(diagram);
			int x = 0;
			int shapeCount = 0;
			foreach (ShapeType st in project.ShapeTypes) {
				x += 50;
				Shape s = st.CreateInstance();
				s.X = x;
				s.Y = 50;
				if (s is IPlanarShape) {
					((IPlanarShape)s).Angle = -300;
					//((IPlanarShape)s).FillStyle
					// ((ILinearShape)s).LineStyle
				}
				diagram.Shapes.Add(s, shapeCount + 1);
				project.Repository.InsertShape(s, diagram);
				++shapeCount;
			}
			//
			Diagram diagram2 = new Diagram("Connections");
			diagram2.Width = 800;
			diagram2.Height = 600;
			Circle circle = (Circle)project.ShapeTypes["Circle"].CreateInstance();
			circle.X = 50;
			circle.Y = 50;
			circle.Diameter = 10;
			diagram2.Shapes.Add(circle, diagram.Shapes.MaxZOrder + 10);
			Box box = (Box)project.ShapeTypes["Box"].CreateInstance();
			box.X = 100;
			box.Y = 50;
			box.Width = 20;
			box.Height = 10;
			box.Angle = 450;
			diagram2.Shapes.Add(box, diagram2.Shapes.MaxZOrder + 10);
			Polyline polyLine = (Polyline)project.ShapeTypes["Polyline"].CreateInstance();
			polyLine.Connect(1, box, 3);
			polyLine.Connect(2, circle, 7);
			diagram2.Shapes.Add(polyLine, diagram2.Shapes.MaxZOrder + 10);
			project.Repository.InsertDiagram(diagram2);
			//
			project.Repository.SaveChanges();
			project.Close();
			//
			// -- Reload project and modify --
			project.Open();
			diagram = project.Repository.GetDiagram("All Shapes");
			project.Repository.GetDiagramShapes(diagram);
			foreach (Shape s in diagram.Shapes) {
				s.MoveBy(300, 300);
				if (s is ICaptionedShape)
					((ICaptionedShape)s).SetCaptionText(0, s.Type.Name);
				project.Repository.UpdateShape(s);
			}
			project.Repository.SaveChanges();
			project.Close();
			//
			// -- Reload and check --
			project.Open();
			diagram = project.Repository.GetDiagram("All Shapes");
			int c = 0;
			foreach (Shape s in diagram.Shapes) {
				Assert.AreEqual(350, s.Y);
				if (s is IPlanarShape) Assert.AreEqual(3300, ((IPlanarShape)s).Angle, s.Type.Name);
				if (s is ICaptionedShape)
					Assert.AreEqual(((ICaptionedShape)s).GetCaptionText(0), s.Type.Name);
				++c;
			}
			Assert.AreEqual(shapeCount, diagram.Shapes.Count);
			Assert.AreEqual(shapeCount, c);
			project.Close();
		}
Пример #19
0
		public void BoundingRectangleTest() {
			// -- Create a project --
			Project project = new Project();
			project.Name = "BoundingRectangleTest";
			project.Repository = new CachedRepository();
			((CachedRepository)project.Repository).Store = new XmlStore(@"C:\Temp", ".xml");
			project.Repository.Erase();
			project.Create();

			// Add Libraries:
			// GeneralShapes
			project.AddLibrary(typeof(Dataweb.NShape.GeneralShapes.Circle).Assembly);
			// ElectricalShapes
			project.AddLibrary(typeof(Dataweb.NShape.ElectricalShapes.AutoDisconnectorSymbol).Assembly);
			// FlowChartShapes
			project.AddLibrary(typeof(Dataweb.NShape.FlowChartShapes.ProcessSymbol).Assembly);
			// SoftwareArchitectureShapes
			project.AddLibrary(typeof(Dataweb.NShape.SoftwareArchitectureShapes.CloudSymbol).Assembly);

			//
			Diagram diagram = new Diagram("All Shapes");
			diagram.Width = 500;
			diagram.Height = 500;
			project.Repository.InsertDiagram(diagram);
			int shapeCount = 0;
			foreach (ShapeType st in project.ShapeTypes) {
				Shape s = st.CreateInstance();
				diagram.Shapes.Add(s, shapeCount + 1);
				project.Repository.InsertShape(s, diagram);
				++shapeCount;
			}

			BoundingRectangleTestCore(diagram.Shapes, 0, 100, 0);
			BoundingRectangleTestCore(diagram.Shapes, 200, 100, 300);
			BoundingRectangleTestCore(diagram.Shapes, 100, 2, 600);

			project.Close();
		}
Пример #20
0
		public void CommandTest() {
			// Initialize the project
			Project project = new Project();
			project.Repository = new CachedRepository();
			((CachedRepository)project.Repository).Store = RepositoryHelper.CreateXmlStore();
			project.Name = "Test";
			project.Repository.Erase();
			project.Create();
			project.AddLibrary(typeof(Dataweb.NShape.GeneralShapes.Circle).Assembly);
			// Create a diagram with one shape
			Diagram diagram = new Diagram("Diagram A");
			project.Repository.InsertDiagram(diagram);
			Shape shape = project.ShapeTypes["Square"].CreateInstance();
			shape.X = 100;
			shape.Y = 100;
			// Execute commands
			project.ExecuteCommand(new InsertShapeCommand(diagram, LayerIds.None, shape, true, false));
			project.ExecuteCommand(new MoveShapeByCommand(shape, 200, 200));
			project.History.Undo();
			project.History.Undo();
			Assert.AreEqual(diagram.Shapes.Count, 0);
			project.History.Redo();
			Assert.AreEqual(diagram.Shapes.Count, 1);
			Assert.AreEqual(diagram.Shapes.Bottom.X, 100);
			project.History.Redo();
			Assert.AreEqual(diagram.Shapes.Bottom.X, 300);
			project.Repository.SaveChanges();
			project.Close();
		}
Пример #21
0
 internal void AddShape(Shape shape, Diagram diagram)
 {
     shapes.Add(shape, diagram);
 }
Пример #22
0
 internal void SetShape(Shape shape, Diagram diagram)
 {
     this.shapes.Clear();
     this.shapes.Add(shape, diagram);
 }
Пример #23
0
 internal DiagramShapeCollection(Diagram owner, IEnumerable<Shape> collection)
     : this(owner, (collection is ICollection) ? ((ICollection)collection).Count : 0)
 {
     AddRangeCore(collection);
 }
Пример #24
0
 /// <ToBeCompleted></ToBeCompleted>
 public RepositoryDiagramEventArgs(Diagram diagram)
 {
     if (diagram == null) throw new ArgumentNullException("diagram");
     this.diagram = diagram;
 }
        private void AdjustZoomToDiagram(Display dsp, Diagram dispDiagram)
        {
            int minX = int.MaxValue, maxX = int.MinValue, minY = int.MaxValue, maxY = int.MinValue;
            var shapes = dispDiagram.Shapes.ToList();
            foreach (Shape shape in shapes)
            {
                var shapeRect = shape.GetBoundingRectangle(true);
                if (shapeRect.X < minX)
                    minX = shapeRect.X;

                if (shapeRect.Y < minY)
                    minY = shapeRect.Y;

                if (shapeRect.X + shapeRect.Width > maxX)
                    maxX = shapeRect.X + shapeRect.Width;

                if (shapeRect.Y + shapeRect.Height > maxY)
                    maxY = shapeRect.Y + shapeRect.Height;
            }

            var viewRect = new Rectangle(minX, minY, maxX - minX, maxY - minY);

            dsp.ZoomLevel = 400;
            dsp.EnsureVisible(dispDiagram.Shapes.ElementAt(0));
            dsp.EnsureVisible(viewRect);
            dsp.ZoomLevel -= (dsp.ZoomLevel/5)*2;
        }
Пример #26
0
        private void fileLoadStatisticsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Delete all diagrams (with shapes)
            List<Diagram> diagrams = new List<Diagram>(project1.Repository.GetDiagrams());
            for (int i = diagrams.Count - 1; i >= 0; --i)
                project1.Repository.DeleteAll(diagrams[i]);

            Dictionary<string, RectangleBase> shapeDict = new Dictionary<string, RectangleBase>(1000);
            Diagram diagram = new Diagram("D1");
            Template webPageTemplate = project1.Repository.GetTemplate("Web Page");

            int x = 10;
            int y = 500;
            string statisticsFilePath = Path.Combine(GetBasicTutorialPath(), @"Sample Data\Small.txt");
            TextReader reader = new StreamReader(statisticsFilePath);
            string line = reader.ReadLine();
            while (line != null) {
                int idx1 = line.IndexOf(';');
                int idx2 = line.IndexOf(';', idx1 + 1);
                string url = line.Substring(0, idx1);
                RectangleBase referringShape;
                if (!shapeDict.TryGetValue(url, out referringShape)) {
                    referringShape = (RectangleBase)webPageTemplate.CreateShape();
                    referringShape.SecurityDomainName = 'G';
                    referringShape.Width = 100;
                    referringShape.Height = 60;
                    referringShape.X = x + 50;
                    referringShape.Y = y + 50;
                    x += 120;
                    if (x > 1200) {
                        x = 10;
                        y += 70;
                    }
                    referringShape.SetCaptionText(0, Path.GetFileNameWithoutExtension(url));
                    shapeDict.Add(url, referringShape);
                    diagram.Shapes.Add(referringShape);
                }
                url = line.Substring(idx1 + 1, idx2 - idx1 - 1);
                RectangleBase referredShape;
                if (!shapeDict.TryGetValue(url, out referredShape)) {
                    referredShape = (RectangleBase)webPageTemplate.CreateShape();
                    referredShape.SecurityDomainName = 'G';
                    referredShape.Width = 100;
                    referredShape.Height = 60;
                    referredShape.X = x + 50;
                    referredShape.Y = y + 50;
                    x += 120;
                    if (x > 1200) {
                        x = 10;
                        y += 70;
                    }
                    referredShape.SetCaptionText(0, Path.GetFileNameWithoutExtension(url));
                    shapeDict.Add(url, referredShape);
                    diagram.Shapes.Add(referredShape);
                }
                // Add the connection
                Polyline arrow = (Polyline)project1.ShapeTypes["Polyline"].CreateInstance();
                diagram.Shapes.Add(arrow);
                arrow.EndCapStyle = project1.Design.CapStyles.ClosedArrow;
                arrow.Connect(ControlPointId.FirstVertex, referringShape, ControlPointId.Reference);
                arrow.Connect(ControlPointId.LastVertex, referredShape, ControlPointId.Reference);
                //
                // Next line
                line = reader.ReadLine();
            }
            reader.Close();
            cachedRepository1.InsertAll(diagram);
            display1.Diagram = diagram;
        }
Пример #27
0
        private void AddNewDiagram()
        {
            // Count diagrams
            int diagramCnt = 0;
            foreach (Diagram d in project.Repository.GetDiagrams())
                diagramCnt++;

            Diagram diagram = new Diagram(string.Format("Diagram {0}", diagramCnt + 1));
            diagram.Width = 1600;
            diagram.Height = 1200;
            diagram.BackgroundGradientColor = Color.WhiteSmoke;
            if (diagramCnt % 2 == 0)
                diagram.BackgroundColor = Color.DarkRed;
            else diagram.BackgroundColor = Color.DarkBlue;
            diagram.BackgroundImage = new NamedImage(Database_Designer.Properties.Resources.NY028_3, "BackgroundImage");
            diagram.BackgroundImageLayout = ImageLayoutMode.Fit;

            project.Repository.InsertAll(diagram);
            display.Diagram = diagram;

            ToolStripMenuItem item = new ToolStripMenuItem();
            item.Text = diagram.Name;
            item.Tag = diagram;
            item.Click += new EventHandler(diagramDropDownItem_Click);

            diagramsDropDownButton.DropDown.Items.Add(item);
            diagramsDropDownButton.Text = diagram.Name;
        }
        private void Main_Designer_Load(object sender, EventArgs e)
        {
            WriteConfigLabel();

            project.AddLibraryByName("Dataweb.NShape.GeneralShapes", false);
            project.AddLibraryByName("Dataweb.NShape.SoftwareArchitectureShapes", false);
            project.Name = "DesigningProject";
            project.Create();

            toolBoxAdapter.ToolSetController.Clear();
            toolBoxAdapter.ToolSetController.AddTool(new SelectionTool(), true);
            toolBoxAdapter.ToolSetController.SelectedTool = toolBoxAdapter.ToolSetController.DefaultTool;

            diagramTab = new Diagram(string.Format("Diagramma Tabelle"))
            {
                Width = 6000,
                Height = 6000,
                BackgroundGradientColor = Color.WhiteSmoke
            };

            ColorStyle colorStyleBlack = new ColorStyle("colorStyleBlack", Color.Black);
            ColorStyle colorStyleDarkRed = new ColorStyle("colorStyleDarkRed", Color.DarkRed);
            CharacterStyle charStyleLabel = new CharacterStyle("LabelStyle", 16, colorStyleBlack);
            CharacterStyle charStyleLabelNotGenerated = new CharacterStyle("LabelStyleNotGen", 16, colorStyleDarkRed);
            LineStyle relGenerated = new LineStyle("RelGenerated", 2, colorStyleBlack);
            LineStyle relNotGenerated = new LineStyle("RelNotGenerated", 2, colorStyleDarkRed);

            project.Design.AddStyle(colorStyleBlack);
            project.Repository.Insert(project.Design, colorStyleBlack);
            project.Design.AddStyle(colorStyleDarkRed);
            project.Repository.Insert(project.Design, colorStyleDarkRed);
            project.Design.AddStyle(charStyleLabel);
            project.Repository.Insert(project.Design, charStyleLabel);
            project.Design.AddStyle(charStyleLabelNotGenerated);
            project.Repository.Insert(project.Design, charStyleLabelNotGenerated);
            project.Design.AddStyle(relGenerated);
            project.Repository.Insert(project.Design, relGenerated);
            project.Design.AddStyle(relNotGenerated);
            project.Repository.Insert(project.Design, relNotGenerated);

            GraphicHelper = new GraphicHelper(cachedRepository, project, diagramTab, dspTables);
            GraphicHelper.SetDefaultShapes(project.ShapeTypes["Entity"], project.ShapeTypes["RectangularLine"], project.ShapeTypes["Label"]);
            InitBoard();
        }
Пример #29
0
		public void AggregationTest() {
			// -- Create a project --
			Project project = new Project();
			project.Name = "Test";
			project.Repository = new CachedRepository();
			((CachedRepository)project.Repository).Store = RepositoryHelper.CreateXmlStore();
			project.Repository.Erase();
			project.Create();
			project.AddLibrary(typeof(Dataweb.NShape.GeneralShapes.Circle).Assembly);
			Diagram diagram = new Diagram("Diagram A");
			// Create a group
			ShapeGroup group = (ShapeGroup)project.ShapeTypes["ShapeGroup"].CreateInstance();
			group.Children.Add(project.ShapeTypes["Circle"].CreateInstance(), 1);
			group.Children.Add(project.ShapeTypes["Square"].CreateInstance(), 2);
			group.Children.Add(project.ShapeTypes["Diamond"].CreateInstance(), 3);
			group.MoveTo(200, 200);
			diagram.Shapes.Add(group, 1);
			// Create an aggregation
			Box box = (Box)project.ShapeTypes["Box"].CreateInstance();
			box.Children.Add(project.ShapeTypes["Circle"].CreateInstance(), 1);
			box.Children.Add(project.ShapeTypes["Square"].CreateInstance(), 2);
			box.Children.Add(project.ShapeTypes["Diamond"].CreateInstance(), 3);
			box.MoveTo(400, 200);
			diagram.Shapes.Add(box, 2);
			// Save everything
			project.Repository.InsertDiagram(diagram);
			project.Repository.SaveChanges();
			project.Close();
			//
			// -- Reload and modify --
			project.Open();
			foreach (Diagram d in project.Repository.GetDiagrams())
				diagram = d;
			group = (ShapeGroup)diagram.Shapes.Bottom;
			Shape shape = null;
			foreach (Shape s in group.Children)
				shape = s;
			group.Children.Remove(shape);
			project.Repository.DeleteShape(shape);
			box = (Box)diagram.Shapes.TopMost;
			foreach (Shape s in box.Children)
				shape = s;
			box.Children.Remove(shape);
			project.Repository.DeleteShape(shape);
			project.Repository.SaveChanges();
			project.Close();
			//
			// -- Check --
			project.Open();
			foreach (Diagram d in project.Repository.GetDiagrams()) {
				project.Repository.GetDiagramShapes(d);
				foreach (Shape s in d.Shapes)
					Assert.AreEqual(2, s.Children.Count);
			}
			project.Close();
		}
Пример #30
0
		private void CreateDiagramTab(Diagram diagram) {
			// Create tab items and add them to the tab control
			TabItem tabItem = new TabItem();
			tabItem.Header = diagram.Title;
			tabControl.Items.Add(tabItem);

			// Create a new grid to host other controls
			Grid grid = new Grid();
			// Create WindowsFormsHost and add it to grid
			System.Windows.Forms.Integration.WindowsFormsHost displayHost = new System.Windows.Forms.Integration.WindowsFormsHost();
			grid.Children.Add(displayHost);

			// Create display and assign it to the WinFormsHost
			//
			Display display = new Display();
			// Connect with other NSHape components
			display.DiagramSetController = diagramSetController;
			display.PropertyController = propertyController;
			display.Diagram = diagram;
			// Setup display properties
			display.BackColor = System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.ControlDark);
			display.BackColorGradient = System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.ControlLight);
			display.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			displayHost.Child = display;

			// Set the grid as the content of a tab item
			tabItem.Content = grid;
		}
Пример #31
0
        private void AddLoadedDiagram(Diagram diagram)
        {
            display.Diagram = diagram;

            ToolStripMenuItem item = new ToolStripMenuItem();
            item.Text = diagram.Name;
            item.Tag = diagram;
            item.Click += new EventHandler(diagramDropDownItem_Click);

            diagramsDropDownButton.DropDown.Items.Add(item);
            diagramsDropDownButton.Text = diagram.Name;
        }