public void AddConnection(ConnectableBase source, ConnectableBase destination, int value, string description) { Connection updateOldConnection = null; if (ArrowManagement.CountConnectionsInArrowManagement(source, destination) == 1) { updateOldConnection = PnmlNet.PetriNet.Objects .GetAllConnectionsBetween2Connectables(source, destination).First(); ArrowManagement.Remove(source, destination); } Connection newConnection = new Connection(PnmlNet.PetriNet.CreateId(), source.Id, destination.Id, value, description); PnmlNet.PetriNet.InitDependency(newConnection); PnmlNet.PetriNet.Objects.Add(newConnection); PnmlNet.PetriNet.InitDependency(source); PnmlNet.PetriNet.InitDependency(destination); if (source is Transition trans) { trans.CalcIsExecutable(); } if (destination is Transition transd) { transd.CalcIsExecutable(); } newConnection.CalcIsExecutable(); if (updateOldConnection != null) { updateOldConnection.UpdateArrows(); } newConnection.UpdateArrows(); }
public static void Add(ConnectableBase item1, ConnectableBase item2, double position) { items.Add(new ArrowItem(item1, item2) { Position = position }); }
private async void OnConnected(ConnectableBase sender, ConnectedEventArgs e) { await Client.WriteAsync(new Package(PackageType.Authentication, Id, PasswordHash)); var package = await Client.ReadAsync <Package>(); switch (package.Type) { case PackageType.Error: Client.Disconnect(); break; case PackageType.Success: Client.Account = package.GetContent <Account>(); SessionFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "sessions", Client.SessionId.ToString()); Directory.CreateDirectory(SessionFolderPath); break; } authCallback.Invoke(package.Type == PackageType.Success, package.Type == PackageType.Success ? Client.Account.Id : package.GetContent <string>()); await Listen(); }
public bool Contains(ConnectableBase component1, ConnectableBase component2) { bool oneFound = false; bool twoFound = false; oneFound = component1 == Component1 || component1 == Component2; twoFound = component2 == Component1 || component2 == Component2; return(oneFound && twoFound); }
/// <summary> /// Initializes the dependencies for a ConnectableBase-Object. /// Adds the destination-connections to the output and the source-connections /// to the input. /// </summary> /// <param name="connectable">Connectable</param> public void InitDependency(ConnectableBase connectable) { var destinations = Objects.GetConnections().Where(c => c.SourceId == connectable.Id); var sources = Objects.GetConnections().Where(c => c.DestinationId == connectable.Id); connectable.Input = new ObservableCollection <Connection>(sources); connectable.Output = new ObservableCollection <Connection>(destinations); connectable.Position.PropertyChanged += connectable.PositionChanged; }
public DecoratorAdorner(UIElement uiElement, ISketchItemDisplay parent) : base(uiElement) { _parent = parent; if (uiElement is OutlineUI outline && outline.Model is ConnectableBase connectable) { _model = connectable; } //IsHitTestVisible = false; }
private async void OnConnected(ConnectableBase sender, ConnectedEventArgs e) { EventManager.InvokeEvent(EventType.Connected, new ConnectedEvent { Client = e.Client }, this); Package package = null; string id = null; byte[] password = null; try { package = await e.Client.ReadAsync <Package>(); id = package.GetContent <string>(0); password = package.GetContent <byte[]>(1); } catch { } if (package == null || package.Type != PackageType.Authentication || string.IsNullOrEmpty(id) || password?.Length == 0) { await e.Client.WriteAsync(new Package(PackageType.Error, "no auth data")); e.Client.Disconnect(); return; } var account = DataStorage.Instance.Accounts.Find(a => a.Id == id); if (account == null) { await e.Client.WriteAsync(new Package(PackageType.Error, "account unknown")); e.Client.Disconnect(); return; } if (!account.Password.SequenceEqual(password)) { await e.Client.WriteAsync(new Package(PackageType.Error, "password invalid")); e.Client.Disconnect(); return; } e.Client.Account = account; await e.Client.WriteAsync(new Package(PackageType.Success, account)); EventManager.InvokeEvent(EventType.Authenticated, new AuthenticatedEvent { Account = account }, this); await Listen(e.Client); }
public static int CountAllConnections(ConnectableBase component1, ConnectableBase component2) { int counter = 0; foreach (var conn in ObjectList.GetConnections()) { var comp1Found = component1 == conn.Source || component1 == conn.Destination; var comp2Found = component2 == conn.Source || component2 == conn.Destination; if (comp1Found && comp2Found) { counter++; } } return(counter); }
public static void Remove(ConnectableBase item1, ConnectableBase item2) { List <ArrowItem> removeList = new List <ArrowItem>(); foreach (var arrowItem in items) { if (arrowItem.Contains(item1, item2)) { removeList.Add(arrowItem); } } foreach (var arrowItem in removeList) { items.Remove(arrowItem); } }
public OutlineAdorner(OutlineUI adorned, ISketchItemDisplay parent) : base(adorned) { _adorned = adorned; _parent = parent; _realBody = _adorned.Model as ConnectableBase; _shadowGeometry = _realBody.Outline.Clone(); _shadowGeometry.Rect = new Rect(0, 0, adorned.Bounds.Width, adorned.Bounds.Height); //_realBody.Outline.Clone(); _myBrush = _selectedOutlineBrush; ComputeSensitiveBorder(); _myPen = new Pen(_myBrush, _defaultStroke); _defaultDashstile = _myPen.DashStyle; this.Visibility = System.Windows.Visibility.Visible; }
bool AddConnectionCommandCanExecute(ConnectableBase item) { if (AddConnectionHelper.Source == item) { return(false); } if (AddConnectionHelper.Source != null && AddConnectionHelper.Source.GetType() == item.GetType()) { return(false); } if (AddConnectionHelper.Source != null && AddConnectionHelper.Source.Output.Count(i => i.Destination == item) > 0) { return(false); } return(EditorMode == EditorMode.AddConnection); }
void AddConnectionCommandExecute(ConnectableBase item) { if (AddConnectionHelper.Source == null) { AddConnectionHelper.Source = item; item.SelectedAsSource = true; } else if (AddConnectionHelper.Destination == null && item != AddConnectionHelper.Source) { AddConnectionHelper.Destination = item; AddConnection(AddConnectionHelper.Source, AddConnectionHelper.Destination, 1, AddConnectionHelper.Description); AddConnectionHelper.Source.SelectedAsSource = false; item.SelectedAsSource = false; AddConnectionHelper.Destination = null; AddConnectionHelper.Source = null; } }
public static int CountConnectionsInArrowManagement(ConnectableBase component1, ConnectableBase component2) { int counter = 0; //foreach (var conn in ObjectList.GetConnections()) foreach (var conn in items) { //var comp1Found = conn.Source == component1 || conn.Destination == component1; //var comp2Found = conn.Source == component2 || conn.Destination == component2; //if (comp1Found && comp2Found) counter++; var comp1Found = component1 == conn.Component1 || component1 == conn.Component2; var comp2Found = component2 == conn.Component1 || component2 == conn.Component2; if (comp1Found && comp2Found) { counter++; } } return(counter); }
void InitContextMenu(ConnectableBase model) { Sketch.Helper.RuntimeCheck.Contract.Requires <ArgumentNullException>(model != null, "InitContextMenu() requires valide model"); var commands = model.Commands; if (commands != null && commands.Count > 0) { ContextMenu = OutlineHelper.InitContextMenu(commands); if (_model.CanCopy && _model.IsSerializable) { ContextMenu.Items.Add( new MenuItem() { Header = "Copy", Command = new DelegateCommand(() => { var newElem = _model.Clone(); var t = new TranslateTransform( ConnectableBase.DefaultWidth / 4, ConnectableBase.DefaultHeight / 4); newElem.Move(t); _parent.SketchItems.Add(newElem); }) }); } if (_model.CanChangeZorder) { var z = Canvas.GetZIndex(this); ContextMenu.Items.Add( new MenuItem() { Header = "Bring to front", Command = new DelegateCommand(() => { GetMinMaxZ(out int minZ, out int maxZ); Canvas.SetZIndex(this, maxZ + 1); }) });
public AddConnectorOperation(ISketchItemDisplay pad, ConnectableBase from, Point p) { _from = from; _pad = pad; // // at this point it is not sufficient to consider only the bounds // in case of a lengthy object, we would like to place that start point close to where // the user pressed the button! // hence we should query the from object for a decent start point // var start = p;// ConnectorUtilities.ComputeCenter(from.Bounds); _selector = new ConnectablePairSelector(start, p); _pad.Canvas.Children.Add(_selector); _selector.Visibility = Visibility.Visible; _pad.SetSketchItemEnable(false); _oldContextMenue = _pad.Canvas.ContextMenu; _pad.Canvas.MouseMove += HandleMouseMove; _pad.Canvas.MouseDown += HandleMouseDown; _pad.Canvas.KeyDown += HandleKeyDown; _pad.TakeSnapshot(); }
void EditCommandExecute(ConnectableBase item) { CurrentInformationEntry = item; }
private void OnDisconnected(ConnectableBase sender, DisconnectedEventArgs e) { }
bool EditCommandCanExecute(ConnectableBase item) { return(EditorMode == EditorMode.Edit); }
public ArrowItem(ConnectableBase component1, ConnectableBase component2) { Component1 = component1; Component2 = component2; }
public OutlineUI(SketchPad pad, ISketchItemDisplay parent, object modelInstance) : base() { if (modelInstance is ConnectableBase model) { _sketchPad = pad; _model = model; _model.Decorators.CollectionChanged += Decorators_CollectionChanged; Content = model; IsHitTestVisible = true; Canvas.SetLeft(this, model.Bounds.Left); Canvas.SetTop(this, model.Bounds.Top); _parent = parent; var tools = model.AllowableConnectors; if (tools.Count > 0) { InitTools(tools); } this.DataContext = model; this.SetBinding(LabelProperty, model.LabelPropertyName); var boundsBinding = new Binding(nameof(Bounds)) { Mode = BindingMode.OneWay }; this.SetBinding(BoundsProperty, boundsBinding); this.SetBinding(GeometryProperty, nameof(Geometry)); this.Visibility = System.Windows.Visibility.Visible; // some of the bindings must only occur after the shadow was created! _adorner = new OutlineAdorner(this, parent); _decoratorAdorner = new DecoratorAdorner(this, parent); var isSelecteBinding = new Binding("IsSelected") { Mode = BindingMode.TwoWay }; this.SetBinding(IsSelectedProperty, isSelecteBinding); var isMarkedBinding = new Binding("IsMarked") { Mode = BindingMode.TwoWay }; this.SetBinding(IsMarkedProperty, isMarkedBinding); this.SetBinding(CanChangeSizeProperty, nameof(CanChangeSize)); InitContextMenu(model); } else { throw new NotSupportedException("The model needs to be derived from ConnectableBase"); } }
internal static ArrowItem AlreadyContainsConnection(ConnectableBase item1, ConnectableBase item2) { var connectionAlreadyDrawn = items.FirstOrDefault(p => p.Contains(item1, item2)); return(connectionAlreadyDrawn); }
private async void OnConnected(ConnectableBase sender, ConnectedEventArgs e) { await EventService.InvokeEvent(EventType.Connected, new ConnectedEvent { Client = e.Client }, this); string id = null; byte[] password = null; var package = await e.Client.ReadAsync <Package>(); if (package.Type == PackageType.Information) { await e.Client.WriteAsync(new Package(PackageType.Information, new ServerInformation { AcceptsClients = true, ClientExtensions = ExtensionManager.Extensions.FindAll(_ => _.CreateClientInstance).Select(_ => _.Name), Extensions = ExtensionManager.Extensions.Select(_ => _.Name), Name = "Festival Defectively Horizon Dev Server", Url = "https://festival.ml/" })); Server.DisconnectClient(e.Client); return; } try { id = package.GetContent <string>(); password = package.GetContent <byte[]>(1); } catch { } if (string.IsNullOrEmpty(id) || password?.Length == 0) { await e.Client.WriteAsync(new Package(PackageType.Error, "no_auth_data")); Server.DisconnectClient(e.Client); return; } var account = DataStorage.Instance.Accounts.Find(_ => _.Id == id); if (account == null) { await e.Client.WriteAsync(new Package(PackageType.Error, "account_unknown")); Server.DisconnectClient(e.Client); return; } if (!account.Password.SequenceEqual(password)) { await e.Client.WriteAsync(new Package(PackageType.Error, "password_invalid")); Server.DisconnectClient(e.Client); return; } e.Client.Account = account; await e.Client.WriteAsync(new Package(PackageType.Success, account)); await EventService.InvokeEvent(EventType.Authenticated, new AuthenticatedEvent { Account = account }, this); foreach (var extPath in ExtensionManager.Extensions.FindAll(_ => _.CreateClientInstance).Select(_ => _.ExtensionPath).Distinct()) { await e.Client.WriteAsync(new Package(PackageType.Assembly, File.ReadAllBytes(extPath), new FileInfo(extPath).Name)); } await Listen(e.Client); }