public ClassDiagramRoot() { bar = new DiagramToolBar (); bar.position.x = 6; bar.position.y = 60; bar.Add (new DiagramToolElement (bar, Config.TEX_TOOL_COMPOSITE, Config.TEX_TOOL_REFERENCE, new DiagramDefaultTool ())); bar.Add (new DiagramToolElement (bar, Config.TEX_TOOL_COMPOSITE, Config.TEX_TOOL_REFERENCE, new DiagramConnectTool ())); bar.Add (new DiagramToolElement (bar, Config.TEX_TOOL_COMPOSITE, Config.TEX_TOOL_REFERENCE, new DiagramConnectTool ())); bar.Add (new DiagramToolElement (bar, Config.TEX_TOOL_COMPOSITE, Config.TEX_TOOL_REFERENCE, new DiagramConnectTool ())); DiagramNode node1 = new DiagramNode (); node1.attributes.Add (new Attribute ()); node1.attributes.Add (new Attribute ()); node1.attributes.Add (new Attribute ()); DiagramNode node2 = new DiagramNode (); DiagramNode node3 = new DiagramNode (); DiagramEdge edge1 = new DiagramEdge (); edge1.SetSource (node1); edge1.SetTarget (node2); node1.edges.Add (edge1); nodes.Add (node1); nodes.Add (node2); nodes.Add (node3); classes = new ClassNode [1]; classes [0] = new ClassNode (); diagramName = "diagram name"; types = new string[]{"int", "float", "string", "bool", "Color", "Vector2", "Vector3", "Vector4", "AnimationCurve","Rect", "Texture", "Texture2D", "Object"}; }
protected override DiagramSelectionBorder CalculateEdgeBorder(DiagramEdge edge) { var geometry = edge.Geometry as PathGeometry; if (geometry == null) return null; if (geometry.Figures.Count != 2) return null; var border = new DiagramSelectionBorder(false); var mainFigure = geometry.Figures[0]; var arrowFigure = geometry.Figures[1]; border.ResizeInfos.Add(new ResizeInfo(mainFigure.StartPoint, ResizeDirection.AllRoundSource)); border.ResizeInfos.Add(new ResizeInfo((arrowFigure.Segments[1] as LineSegment).Point, ResizeDirection.AllRoundDestination)); return border; }
/// <summary> /// Serialize the <see cref="DiagramEdge"/> /// </summary> /// <param name="diagramEdge">The <see cref="DiagramEdge"/> to serialize</param> /// <returns>The <see cref="JObject"/></returns> private JObject Serialize(DiagramEdge diagramEdge) { var jsonObject = new JObject(); jsonObject.Add("bounds", this.PropertySerializerMap["bounds"](diagramEdge.Bounds)); jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), diagramEdge.ClassKind))); jsonObject.Add("depictedThing", this.PropertySerializerMap["depictedThing"](diagramEdge.DepictedThing)); jsonObject.Add("diagramElement", this.PropertySerializerMap["diagramElement"](diagramEdge.DiagramElement.OrderBy(x => x, this.guidComparer))); jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](diagramEdge.ExcludedDomain.OrderBy(x => x, this.guidComparer))); jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](diagramEdge.ExcludedPerson.OrderBy(x => x, this.guidComparer))); jsonObject.Add("iid", this.PropertySerializerMap["iid"](diagramEdge.Iid)); jsonObject.Add("localStyle", this.PropertySerializerMap["localStyle"](diagramEdge.LocalStyle)); jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](diagramEdge.ModifiedOn)); jsonObject.Add("name", this.PropertySerializerMap["name"](diagramEdge.Name)); jsonObject.Add("point", this.PropertySerializerMap["point"](diagramEdge.Point.OrderBy(x => x, this.orderedItemComparer))); jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](diagramEdge.RevisionNumber)); jsonObject.Add("sharedStyle", this.PropertySerializerMap["sharedStyle"](diagramEdge.SharedStyle)); jsonObject.Add("source", this.PropertySerializerMap["source"](diagramEdge.Source)); jsonObject.Add("target", this.PropertySerializerMap["target"](diagramEdge.Target)); jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](diagramEdge.ThingPreference)); return(jsonObject); }
/// <summary> /// Persist the DTO composition to the ORM layer. /// </summary> /// <param name="transaction"> /// The transaction object. /// </param> /// <param name="partition"> /// The database partition (schema) where the requested resource will be stored. /// </param> /// <param name="diagramEdge"> /// The diagramEdge instance to persist. /// </param> /// <returns> /// True if the persistence was successful. /// </returns> private bool CreateContainment(NpgsqlTransaction transaction, string partition, DiagramEdge diagramEdge) { var results = new List <bool>(); foreach (var diagramElement in this.ResolveFromRequestCache(diagramEdge.DiagramElement)) { results.Add(this.DiagramElementThingService.CreateConcept(transaction, partition, diagramElement, diagramEdge)); } foreach (var bounds in this.ResolveFromRequestCache(diagramEdge.Bounds)) { results.Add(this.BoundsService.CreateConcept(transaction, partition, bounds, diagramEdge)); } foreach (var localStyle in this.ResolveFromRequestCache(diagramEdge.LocalStyle)) { results.Add(this.OwnedStyleService.CreateConcept(transaction, partition, localStyle, diagramEdge)); } foreach (var point in this.ResolveFromRequestCache(diagramEdge.Point)) { results.Add(this.PointService.CreateConcept(transaction, partition, (Point)point.V, diagramEdge, point.K)); } return(results.All(x => x)); }
/// <summary> /// Initializes a new instance of the <see cref=""/> class /// </summary> /// <param name="diagramEdge">The associated <see cref="DiagramEdge"/></param> /// <param name="session">The current <see cref="ISession"/></param> /// <param name="containerViewModel">The container view-model</param> public DiagramEdgeViewModel(DiagramEdge diagramEdge, ISession session, IViewModelBase <Thing> containerViewModel) : base(diagramEdge, session, containerViewModel) { this.ConnectingPoints = new List <Point>(); this.UpdateProperties(); }
protected virtual Geometry CalculateLabelOnEdge(DiagramLabel label, DiagramEdge edge) { var geometry = edge.Geometry; if (geometry == null) return null; Rect bounds = geometry.Bounds; var textSize = GetTextSize(label.Text); var origin = new Point(bounds.X + bounds.Width / 2, bounds.Y + bounds.Height / 2); origin.Offset(label.RelativePosition.X, label.RelativePosition.Y); origin.Offset(-textSize.Width / 2, -textSize.Height / 2); return new RectangleGeometry(new Rect(origin.X, origin.Y, textSize.Width, textSize.Height)); }
//protected abstract void DrawEdge(DrawingContext dc, DiagramEdge edge); protected void FindBoundaries(DiagramEdge edge, out Point? start, out Point? end) { start = null; end = null; Point? tempStartPoint; Point? tempEndPoint; Geometry sourceNodeShape = null; Geometry destinationNodeShape = null; FindTempBoundaries(edge, out tempStartPoint, out tempEndPoint); switch (edge.AnchoringMode) { case EdgeAnchoringMode.PointToPoint: start = tempStartPoint; end = tempEndPoint; break; case EdgeAnchoringMode.PointToNode: start = tempStartPoint; destinationNodeShape = edge.DestinationNode != null ? edge.DestinationNode.Geometry : null; break; case EdgeAnchoringMode.NodeToPoint: sourceNodeShape = edge.SourceNode != null ? edge.SourceNode.Geometry : null; end = tempEndPoint; break; case EdgeAnchoringMode.NodeToNode: sourceNodeShape = edge.SourceNode != null ? edge.SourceNode.Geometry : null; destinationNodeShape = edge.DestinationNode != null ? edge.DestinationNode.Geometry : null; break; } if (tempStartPoint != null && tempEndPoint != null && sourceNodeShape != null) { var line = new LineGeometry(tempStartPoint.Value, tempEndPoint.Value); var points = new List<Point>(GeometryUtils.Intersect(sourceNodeShape, edge.SourceNode.BorderPen, line, edge.BorderPen)); var min = Double.MaxValue; Point? minPoint = null; foreach (var pointItem in points) { if (MathUtils.Compare(GeometryUtils.Distance(pointItem, tempEndPoint.Value), 0, GlobalData.PointPrecision) == 0) continue; var distance = GeometryUtils.Distance(pointItem, tempEndPoint.Value); if (distance < min) { min = distance; minPoint = pointItem; } } if (minPoint != null) start = new Point(minPoint.Value.X, minPoint.Value.Y); else start = tempStartPoint; } if (tempStartPoint != null && tempEndPoint != null && destinationNodeShape != null) { var line = new LineGeometry(tempStartPoint.Value, tempEndPoint.Value); var points = new List<Point>(GeometryUtils.Intersect(destinationNodeShape, edge.DestinationNode.BorderPen, line, edge.BorderPen)); var min = Double.MaxValue; Point? minPoint = null; foreach (var pointItem in points) { if (MathUtils.Compare(GeometryUtils.Distance(tempStartPoint.Value, pointItem), 0, GlobalData.PointPrecision) == 0) continue; var distance = GeometryUtils.Distance(tempStartPoint.Value, pointItem); if (distance < min) { min = distance; minPoint = pointItem; } } if (minPoint != null) end = new Point(minPoint.Value.X, minPoint.Value.Y); else end = tempEndPoint; } if ((edge.AnchoringMode == EdgeAnchoringMode.NodeToPoint || edge.AnchoringMode == EdgeAnchoringMode.NodeToNode) && start != null) { edge.SourcePoint = start.Value; } if ((edge.AnchoringMode == EdgeAnchoringMode.PointToNode || edge.AnchoringMode == EdgeAnchoringMode.NodeToNode) && end != null) { edge.DestinationPoint = end.Value; } }
protected abstract Geometry CalculateEdgeGeometry(DiagramEdge edge);
protected abstract DiagramSelectionBorder CalculateEdgeBorder(DiagramEdge edge);
protected void FindTempBoundaries(DiagramEdge edge, out Point? start, out Point? end) { start = null; end = null; Rect? sourceNodeBounds = null; if (edge.SourceNode != null) { sourceNodeBounds = edge.SourceNode.Bounds; } Rect? destNodeBounds = null; if (edge.DestinationNode != null) { destNodeBounds = edge.DestinationNode.Bounds; } switch (edge.AnchoringMode) { case EdgeAnchoringMode.PointToPoint: start = new Point(edge.SourcePoint.X, edge.SourcePoint.Y); end = new Point(edge.DestinationPoint.X, edge.DestinationPoint.Y); break; case EdgeAnchoringMode.PointToNode: start = new Point(edge.SourcePoint.X, edge.SourcePoint.Y); if (destNodeBounds.HasValue) { end = new Point((destNodeBounds.Value.Left + destNodeBounds.Value.Right) / 2, (destNodeBounds.Value.Top + destNodeBounds.Value.Bottom) / 2); } break; case EdgeAnchoringMode.NodeToPoint: if (sourceNodeBounds.HasValue) { start = new Point((sourceNodeBounds.Value.Left + sourceNodeBounds.Value.Right) / 2, (sourceNodeBounds.Value.Top + sourceNodeBounds.Value.Bottom) / 2); } end = new Point(edge.DestinationPoint.X, edge.DestinationPoint.Y); break; case EdgeAnchoringMode.NodeToNode: if (edge.SourceNode != null && edge.DestinationNode != null && edge.SourceNode == edge.DestinationNode && sourceNodeBounds.HasValue) { double y = sourceNodeBounds.Value.Top + 0.25 * sourceNodeBounds.Value.Height; start = new Point(sourceNodeBounds.Value.Left, y); end = new Point(sourceNodeBounds.Value.Right, y); } else { if (sourceNodeBounds.HasValue) { start = new Point((sourceNodeBounds.Value.Left + sourceNodeBounds.Value.Right) / 2, (sourceNodeBounds.Value.Top + sourceNodeBounds.Value.Bottom) / 2); } if (destNodeBounds.HasValue) { end = new Point((destNodeBounds.Value.Left + destNodeBounds.Value.Right) / 2, (destNodeBounds.Value.Top + destNodeBounds.Value.Bottom) / 2); } } break; } }
public void Setup() { this.session = new Mock <ISession>(); this.assembler = new Assembler(this.uri); this.permissionService = new Mock <IPermissionService>(); this.mockExtendedDiagramBehavior = new Mock <IExtendedDiagramOrgChartBehavior>(); this.mockDiagramBehavior = new Mock <ICdp4DiagramOrgChartBehavior>(MockBehavior.Strict); this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object); this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>(); this.panelNavigationService = new Mock <IPanelNavigationService>(); this.pluginSettingsService = new Mock <IPluginSettingsService>(); this.dropinfo = new Mock <IDiagramDropInfo>(); this.cache = this.assembler.Cache; this.sitedir = new SiteDirectory(Guid.NewGuid(), this.cache, this.uri); this.srdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri); this.modelsetup = new EngineeringModelSetup(Guid.NewGuid(), this.cache, this.uri) { Name = "model" }; this.iterationsetup = new IterationSetup(Guid.NewGuid(), this.cache, this.uri); this.person = new Person(Guid.NewGuid(), this.cache, this.uri); this.domain = new DomainOfExpertise(Guid.NewGuid(), this.cache, this.uri) { Name = "domain" }; this.participant = new Participant(Guid.NewGuid(), this.cache, this.uri) { Person = this.person, SelectedDomain = this.domain }; this.diagram = new DiagramCanvas(Guid.NewGuid(), this.cache, this.uri) { Name = "model" }; this.sitedir.Model.Add(this.modelsetup); this.sitedir.SiteReferenceDataLibrary.Add(this.srdl); this.sitedir.Person.Add(this.person); this.sitedir.Domain.Add(this.domain); this.modelsetup.IterationSetup.Add(this.iterationsetup); this.modelsetup.Participant.Add(this.participant); this.model = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri) { EngineeringModelSetup = this.modelsetup }; this.iteration = new Iteration(Guid.NewGuid(), this.cache, this.uri) { IterationSetup = this.iterationsetup }; this.iteration.DiagramCanvas.Add(this.diagram); this.model.Iteration.Add(this.iteration); this.specCat = new Category(Guid.NewGuid(), this.cache, this.uri); this.relationshipCat = new Category(Guid.NewGuid(), this.cache, this.uri); this.spec1 = new RequirementsSpecification(Guid.NewGuid(), this.cache, this.uri); this.spec2 = new RequirementsSpecification(Guid.NewGuid(), this.cache, this.uri); this.spec3 = new RequirementsSpecification(Guid.NewGuid(), this.cache, this.uri); this.link1 = new BinaryRelationship(Guid.NewGuid(), this.cache, this.uri) { Source = this.spec1, Target = this.spec2 }; this.link1.Category.Add(this.relationshipCat); this.spec1.Category.Add(this.specCat); this.spec2.Category.Add(this.specCat); this.spec3.Category.Add(this.specCat); this.srdl.DefinedCategory.Add(this.specCat); this.srdl.DefinedCategory.Add(this.relationshipCat); this.iteration.RequirementsSpecification.Add(this.spec1); this.iteration.RequirementsSpecification.Add(this.spec2); this.iteration.RequirementsSpecification.Add(this.spec3); this.iteration.Relationship.Add(this.link1); var tuple = new Tuple <DomainOfExpertise, Participant>(this.domain, this.participant); var openedIterations = new Dictionary <Iteration, Tuple <DomainOfExpertise, Participant> > { { this.iteration, tuple } }; this.diagramObject1 = new DiagramObject(Guid.NewGuid(), this.cache, this.uri) { DepictedThing = this.spec1 }; this.diagramObject2 = new DiagramObject(Guid.NewGuid(), this.cache, this.uri) { DepictedThing = this.spec2 }; this.diagramObject3 = new DiagramObject(Guid.NewGuid(), this.cache, this.uri) { DepictedThing = this.spec3 }; this.connector = new DiagramEdge(Guid.NewGuid(), this.cache, this.uri) { Source = this.diagramObject1, Target = this.diagramObject2, DepictedThing = this.link1 }; this.elementDefinition = new ElementDefinition() { Name = "WhyNot", ShortName = "WhyNot" }; this.bound1 = new Bounds(Guid.NewGuid(), this.cache, this.uri) { X = 1, Y = 1, Height = 12, Width = 10 }; this.bound2 = new Bounds(Guid.NewGuid(), this.cache, this.uri) { X = 1, Y = 1, Height = 12, Width = 10 }; this.diagramObject1.Bounds.Add(this.bound1); this.diagramObject2.Bounds.Add(this.bound2); this.diagram.DiagramElement.Add(this.diagramObject1); this.diagram.DiagramElement.Add(this.diagramObject2); this.diagram.DiagramElement.Add(this.connector); this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.sitedir); this.session.Setup(x => x.ActivePerson).Returns(this.person); this.session.Setup(x => x.OpenIterations).Returns(openedIterations); this.session.Setup(x => x.Assembler).Returns(this.assembler); this.permissionService.Setup(x => x.CanWrite(It.IsAny <Thing>())).Returns(true); this.mockExtendedDiagramBehavior.Setup(x => x.GetDiagramPositionFromMousePosition(It.IsAny <Point>())).Returns(new Point()); this.mockDiagramBehavior.Setup(x => x.GetDiagramPositionFromMousePosition(It.IsAny <Point>())).Returns(new Point()); this.mockDiagramBehavior.Setup(x => x.ItemPositions).Returns(new Dictionary <object, Point>()); this.mockDiagramBehavior.Setup(x => x.ApplyChildLayout(It.IsAny <DiagramItem>())); this.cache.TryAdd(new CacheKey(this.iteration.Iid, null), new Lazy <Thing>(() => this.iteration)); }
protected override Geometry CalculateEdgeGeometry(DiagramEdge edge) { PathGeometry result = new PathGeometry(); PathFigure figure = new PathFigure(); PathFigure arrowFigure = null; Point? start; Point? end; FindBoundaries(edge, out start, out end); if (start != null && end != null) { figure.StartPoint = start.Value; Point arrowStartPoint; arrowFigure = CalculateArrowShape(start.Value, end.Value, out arrowStartPoint); PathSegment mainSegment; if (edge.AnchoringMode == EdgeAnchoringMode.NodeToNode && edge.SourceNode != null && edge.SourceNode == edge.DestinationNode) { double a = edge.SourceNode.Bounds.Width / 2 + GlobalData.SelfArcWingAmplification * edge.SourceNode.Bounds.Width / 2; double b = edge.SourceNode.Bounds.Height / 2; mainSegment = new ArcSegment(arrowStartPoint, new Size(a, b), 0, true, SweepDirection.Clockwise, true); } else { mainSegment = new LineSegment(arrowStartPoint, true); } figure.Segments.Add(mainSegment); } result.Figures.Add(figure); if (arrowFigure != null) { result.Figures.Add(arrowFigure); } return result; }