// --------------------------------------------------------------------------------------------------------------------------------------------------------- /// <summary> /// Creates and returns a Relationship Visual Representation shortcut (as Main Central/Main-Symbol) /// to the target Relationship, for the specified target-view, center-position, symbol and connectors format, plus as-shortcut indication. /// </summary> public static RelationshipVisualRepresentation CreateRelationshipVisualRepresentation(Relationship Target, View TargetView, Point CenterPosition, bool AsShortcut = false) { var Representator = new RelationshipVisualRepresentation(Target, TargetView); Representator.IsShortcut = AsShortcut; var Width = Target.RelationshipDefinitor.Value.DefaultSymbolFormat.InitialWidth.SubstituteFor(0, ProductDirector.DefaultRelationshipCentralSymbolSize.Width); var Height = Target.RelationshipDefinitor.Value.DefaultSymbolFormat.InitialHeight.SubstituteFor(0, ProductDirector.DefaultRelationshipCentralSymbolSize.Height); // Notice that "hidden" symbols are not adjusted/snapped to grid if (TargetView.SnapToGrid && !(Target.RelationshipDefinitor.Value.IsSimple && Target.RelationshipDefinitor.Value.HideCentralSymbolWhenSimple)) { var SnappedArea = TargetView.GetGridSnappedArea(CenterPosition, Width, Height); if (!Target.RelationshipDefinitor.Value.DefaultSymbolFormat.HasFixedWidth) { Width = SnappedArea.Width; } if (!Target.RelationshipDefinitor.Value.DefaultSymbolFormat.HasFixedWidth) { Height = SnappedArea.Height; } CenterPosition = new Point(SnappedArea.X + SnappedArea.Width / 2.0, SnappedArea.Y + SnappedArea.Height / 2.0); } var Body = new VisualShape(Representator, EVisualRepresentationPart.RelationshipCentralSymbol, CenterPosition, Width, Height); Body.IsAutoPositionable = true; // Very important (for users) to work easy Representator.AddVisualPart(Body); // Append possible Group Region Complement if (Target.IdeaDefinitor.HasGroupRegion) { var Params = VisualComplement.GetGroupRegionInitialParams(Body); ComplementCreationCommand.CreateComplement(TargetView.OwnerCompositeContainer, Domain.ComplementDefGroupRegion, TargetView, Body, Params.Item1, Params.Item2); } // Append possible Group Line Complement if (Target.IdeaDefinitor.HasGroupLine) { ComplementCreationCommand.CreateComplement(TargetView.OwnerCompositeContainer, Domain.ComplementDefGroupLine, TargetView, Body, VisualComplement.GetGroupLineInitialPosition(Body)); } // NOTE: This does not render because the connectors are expected to be added later. return(Representator); }
public override bool Continue(MouseEventArgs Parameter, bool IsDefinitive = true) { var Go = base.Continue(Parameter, IsDefinitive); if (!Go) { return(false); } TargetLocation = Parameter.GetPosition(this.ContextEngine.CurrentView.PresenterControl); if (this.ContextEngine.CurrentView.SnapToGrid) { TargetLocation = this.ContextEngine.CurrentView.GetGridSnappedPosition(TargetLocation, true); } TargetSymbol = this.ContextEngine.GetPointedVisualObject(TargetLocation) as VisualSymbol; var InitialWidth = 0.0; if (IsDefinitive) { var CreationResult = new OperationResult <VisualComplement>(); if (this.ComplementKind.TechName == Domain.ComplementDefCallout.TechName || this.ComplementKind.TechName == Domain.ComplementDefQuote.TechName) { if (TargetSymbol == null) { Console.WriteLine(this.ComplementKind.Name + " must point to a Symbol"); return(true); } if (this.ComplementKind.TechName == Domain.ComplementDefCallout.TechName) { TargetLocation = new Point(TargetSymbol.BaseCenter.X + 20 + VisualComplement.CALLOUT_INI_WIDTH / 2.0, TargetSymbol.BaseTop - 20 - VisualComplement.CALLOUT_INI_HEIGHT / 2.0); } else { TargetLocation = new Point(TargetSymbol.BaseCenter.X - 25 - VisualComplement.QUOTE_INI_WIDTH / 2.0, TargetSymbol.BaseTop - 15 - VisualComplement.QUOTE_INI_HEIGHT / 2.0); } if (this.ContextEngine.CurrentView.SnapToGrid) { TargetLocation = this.ContextEngine.CurrentView.GetGridSnappedPosition(TargetLocation, true); } } if (this.ComplementKind.TechName == Domain.ComplementDefGroupRegion.TechName || this.ComplementKind.TechName == Domain.ComplementDefGroupLine.TechName) { if (TargetSymbol == null) { Console.WriteLine(this.ComplementKind.Name + " must belong to a Symbol"); return(true); } /*- * if (this.ComplementKind.TechName == Domain.ComplementDefGroupRegion.TechName * && TargetSymbol.AttachedComplements.Count(comp => comp.IsComplementGroupRegion) > 0) * { * Console.WriteLine("Symbol cannot have more than one Group Region."); * return true; * } */ if (this.ComplementKind.TechName == Domain.ComplementDefGroupLine.TechName && TargetSymbol.AttachedComplements.Count(comp => comp.IsComplementGroupLine) > 1) { Console.WriteLine("Symbol cannot have more than two Group Lines."); return(true); } if (this.ComplementKind.TechName == Domain.ComplementDefGroupRegion.TechName) { var Params = VisualComplement.GetGroupRegionInitialParams(TargetSymbol); TargetLocation = Params.Item1; InitialWidth = Params.Item2; } else { TargetLocation = VisualComplement.GetGroupLineInitialPosition(TargetSymbol); } } CreationResult = CreateComplement(this.ContextEngine.CurrentView.VisualizedCompositeIdea, this.ComplementKind, this.ContextEngine.CurrentView, TargetSymbol as VisualSymbol, TargetLocation, InitialWidth); if (CreationResult.WasSuccessful) { this.ContextEngine.CurrentView.Manipulator.ApplySelection(CreationResult.Result); this.ContextEngine.CurrentView.Presenter .PostCall(pres => VisualComplement.Edit(CreationResult.Result, true)); if (this.ComplementKind.TechName == Domain.ComplementDefImage.TechName) { return(false); } } else { Console.WriteLine("Cannot create Complement: " + CreationResult.Message.AbsentDefault("?")); this.Terminate(); return(false); } } // // Stop the command... // this.Terminate(true, Parameter); // return false; // Continue the command... return(true); }