private void _searchAndPopulateShapes() { _data.Sources = new List <Tuple <FilterSetupShapeBase, int> >(); listViewSources.BeginUpdate(); listViewSources.Items.Clear(); foreach (Shape selectedShape in _data.FilterSetupForm.SelectedShapes.Reverse()) { FilterSetupShapeBase shape = selectedShape as FilterSetupShapeBase; if (shape != null && shape.OutputCount > 0 && shape.DataFlowComponent != null) { string title = shape.Title; for (int i = 0; i < shape.OutputCount; i++) { _data.Sources.Add(new Tuple <FilterSetupShapeBase, int>(shape, i)); // offset the index by 1 to be human-readable listViewSources.Items.Add(shape.OutputCount == 1 ? title : (title + " [Output " + (i + 1) + "]")); } } } listViewSources.EndUpdate(); _WizardStageChanged(); }
private void _searchAndPopulateShapes() { _data.Destinations = new List <FilterSetupShapeBase>(); listViewDestinations.BeginUpdate(); listViewDestinations.Items.Clear(); foreach (Shape selectedShape in _data.FilterSetupForm.SelectedShapes.Reverse()) { FilterSetupShapeBase shape = selectedShape as FilterSetupShapeBase; if (shape != null && shape.InputCount > 0 && shape.DataFlowComponent != null) { string title = shape.Title; _data.Destinations.Add(shape); listViewDestinations.Items.Add(title); } } listViewDestinations.EndUpdate(); _WizardStageChanged(); }
private void _addShapeToDataFlowMap(FilterSetupShapeBase shape, Dictionary<IDataFlowComponent, List<FilterSetupShapeBase>> map) { if (shape.DataFlowComponent != null) { if (!map.ContainsKey(shape.DataFlowComponent)) map[shape.DataFlowComponent] = new List<FilterSetupShapeBase>(); if (!map[shape.DataFlowComponent].Contains(shape)) map[shape.DataFlowComponent].Add(shape); } }
private void UpdateShapeSourceConnections(FilterSetupShapeBase shape) { // find any existing lines that are connected to the point (it might already be connected to something -- right or wrong) IEnumerable<ShapeConnectionInfo> inputConnectionInfos = shape.GetConnectionInfos(shape.GetControlPointIdForInput(0), null); // find the intended source of this particular block IDataFlowComponentReference source = null; if (shape.DataFlowComponent != null && shape.DataFlowComponent.Source != null) { source = shape.DataFlowComponent.Source; } // if this shape has a source, we need to determine what should be on the other end -- a real shape (if displayed), // or nothing (if it's not). Once we have that, iterate through all the existing connection infos and remove any // that aren't connected to what we expect. if (source == null) { // if this shape has no actual source, there shouldn't be anything displayed. Remove all the connected lines. foreach (ShapeConnectionInfo ci in inputConnectionInfos) { DataFlowConnectionLine line = ci.OtherShape as DataFlowConnectionLine; if (line == null) { Logging.Error("a shape was connected to something other than a DataFlowLine! Shape text: " + shape.Text); } else { _RemoveShapeFromDiagram(line, false); } } } else { List<FilterSetupShapeBase> sourceShapes = null; if (source.Component != null) _dataFlowComponentToShapes.TryGetValue(source.Component, out sourceShapes); if (sourceShapes == null) sourceShapes = new List<FilterSetupShapeBase>(); // iterate through all the existing connections for the shape source, and determine if any actually MATCH // the expected source. If so, keep it and delete the rest. If not, delete everything and make a new line. Shape accurateLine = null; foreach (ShapeConnectionInfo ci in inputConnectionInfos) { DataFlowConnectionLine line = ci.OtherShape as DataFlowConnectionLine; if (line == null) { Logging.Error("a shape was connected to something other than a DataFlowLine! Shape text: " + shape.Text); continue; } if (line.DestinationDataComponent != shape.DataFlowComponent) { Logging.Warn("Well this is embarassing; a line shape is destined for a shape that isn't what it should be."); } if ((line.SourceDataFlowComponentReference != null && line.SourceDataFlowComponentReference.Component == shape.DataFlowComponent.Source.Component && line.SourceDataFlowComponentReference.OutputIndex == shape.DataFlowComponent.Source.OutputIndex) || (line.SourceDataFlowComponentReference == null && sourceShapes.Count == 0)) { accurateLine = line; } else { _RemoveShapeFromDiagram(line, false); } } // if there's a shape in the diagram that corresponds to the component source, keep it. Otherwise, fake a line. if (accurateLine == null) { if (sourceShapes.Count > 0) { foreach (FilterSetupShapeBase sourceShape in sourceShapes) { ConnectShapes(sourceShape, source.OutputIndex, shape); } } else { FakeShapeConnection(shape, shape.GetControlPointIdForInput(0), false); } } } }
private void UpdateShapeDestinationConnections(FilterSetupShapeBase shape) { // check shape connection lines against their destination patches. A lot of these may have been done as part of // source patching; we can double check anyway. We also want to remove invalid patches, and add 'fake' ones if // there's a patch to a destination that isn't on the diagram. for (int i = 0; i < shape.OutputCount; i++) { // find any existing lines that are connected to the point (it might already be connected to something -- right or wrong) List<ShapeConnectionInfo> outputConnectionInfos = shape.GetConnectionInfos(shape.GetControlPointIdForOutput(i), null).ToList(); // get what it SHOULD be connected to IEnumerable<IDataFlowComponent> intendedDestinations = Enumerable.Empty<IDataFlowComponent>(); if (shape.DataFlowComponent != null) intendedDestinations = VixenSystem.DataFlow.GetDestinationsOfComponentOutput(shape.DataFlowComponent, i); HashSet<IDataFlowComponent> correctDestinations = new HashSet<IDataFlowComponent>(); int realShapeConnections = 0; DataFlowConnectionLine dummyLine = null; foreach (ShapeConnectionInfo ci in outputConnectionInfos) { DataFlowConnectionLine line = ci.OtherShape as DataFlowConnectionLine; if (line == null) { Logging.Error("a shape was connected to something other than a DataFlowLine! Shape text: " + shape.Text); } if (line.SourceDataFlowComponentReference.Component != shape.DataFlowComponent || line.SourceDataFlowComponentReference.OutputIndex != i) { Logging.Warn("shape destination patch doesn't have a source of this shape DFC! shape: " + shape.Text); } IDataFlowComponent lineDestination = line.DestinationDataComponent; if (lineDestination != null && correctDestinations.Contains(lineDestination)) { Logging.Warn("line destination has already been processed and it's being processed again"); } // see if the line that is there is invalid: ie. doesn't even go to a DFC that matches one we expect to see. If so, remove it. // if not, it could be OK; double check that the shape it's connected to is the shape that represents that DFC (if any) if (lineDestination == null && intendedDestinations.Any() || !intendedDestinations.Contains(lineDestination)) { _RemoveShapeFromDiagram(line, false); } else { List<FilterSetupShapeBase> destinationShapes = new List<FilterSetupShapeBase>(); if (lineDestination != null && _dataFlowComponentToShapes.ContainsKey(lineDestination)) { destinationShapes = _dataFlowComponentToShapes[lineDestination]; } if (destinationShapes.Count == 0) { // a null destination is OK if it's the ONLY line; it may be patched to a hidden shape. Otherwise, remove it. if (lineDestination == null && outputConnectionInfos.Count == 1) { // line should be OK dummyLine = line; } else { _RemoveShapeFromDiagram(line, false); } } else { // really, only element nodes should have multiple shapes for a single element, and they can never be connected // to (as a destination). So, warn if there's multiple shapes here that correspond to a single endpoint. if (destinationShapes.Count > 1) { Logging.Warn("multiple destination shapes for a single DFC for updating destination connections"); } // if the line is connected to a shape that isn't the expected one (based on DFC), delete the line, otherwise we're good if (line.GetConnectionInfo(ControlPointId.LastVertex, null).OtherShape != destinationShapes.First()) { _RemoveShapeFromDiagram(line, false); } else { if (lineDestination != null) { correctDestinations.Add(lineDestination); realShapeConnections++; } } } } } List<IDataFlowComponent> needConnecting = intendedDestinations.Except(correctDestinations).ToList(); foreach (IDataFlowComponent component in needConnecting) { if (component != null && _dataFlowComponentToShapes.ContainsKey(component)) { List<FilterSetupShapeBase> destinationShapes = _dataFlowComponentToShapes[component]; foreach (FilterSetupShapeBase destinationShape in destinationShapes) { ConnectShapes(shape, i, destinationShape); realShapeConnections++; } } } if (realShapeConnections == 0 && intendedDestinations.Count() > 0 && dummyLine == null) { // fake connection since there's nothing else connected FakeShapeConnection(shape, shape.GetControlPointIdForOutput(i), true); } } }
public void FakeShapeConnection(FilterSetupShapeBase shape, ControlPointId controlPoint, bool shapeIsSource) { DataFlowConnectionLine line = (DataFlowConnectionLine)project.ShapeTypes["DataFlowConnectionLine"].CreateInstance(); diagramDisplay.InsertShape(line); diagramDisplay.Diagram.Shapes.SetZOrder(line, 100); line.SecurityDomainName = SECURITY_DOMAIN_FIXED_SHAPE_NO_CONNECTIONS_DELETABLE; line.EndCapStyle = new CapStyle("fakecapstyle", CapShape.Flat, project.Design.ColorStyles.Blue); //line.LineStyle = new LineStyle("fakelinestyle", 1, project.Design.ColorStyles.Gray); line.LineStyle = project.Design.LineStyles.Dashed; if (shapeIsSource) { line.SourceDataFlowComponentReference = new DataFlowComponentReference(shape.DataFlowComponent, shape.GetOutputNumberForControlPoint(controlPoint)); line.Connect(ControlPointId.FirstVertex, shape, controlPoint); line.MoveControlPointTo(ControlPointId.LastVertex, shape.GetControlPointPosition(controlPoint).X + 40, shape.GetControlPointPosition(controlPoint).Y, ResizeModifiers.None); } else { line.DestinationDataComponent = shape.DataFlowComponent; line.Connect(ControlPointId.LastVertex, shape, controlPoint); line.MoveControlPointTo(ControlPointId.FirstVertex, shape.GetControlPointPosition(controlPoint).X - 40, shape.GetControlPointPosition(controlPoint).Y, ResizeModifiers.None); } }
//public void ConnectShapes(FilterSetupShapeBase source, int sourceOutputIndex, FilterSetupShapeBase destination, // bool removeExistingSource = true) public void ConnectShapes(FilterSetupShapeBase source, int sourceOutputIndex, FilterSetupShapeBase destination) { DataFlowConnectionLine line = (DataFlowConnectionLine)project.ShapeTypes["DataFlowConnectionLine"].CreateInstance(); diagramDisplay.InsertShape(line); diagramDisplay.Diagram.Shapes.SetZOrder(line, 100); line.EndCapStyle = project.Design.CapStyles.ClosedArrow; line.SecurityDomainName = SECURITY_DOMAIN_FIXED_SHAPE_NO_CONNECTIONS_DELETABLE; //if (removeExistingSource) { // IEnumerable<ShapeConnectionInfo> connectionInfos = // destination.GetConnectionInfos(destination.GetControlPointIdForInput(0), null); // foreach (ShapeConnectionInfo ci in connectionInfos) { // if (!ci.IsEmpty && ci.OtherShape is DataFlowConnectionLine) { // _RemoveShapeFromDiagram(ci.OtherShape, true); // } // } //} line.SourceDataFlowComponentReference = new DataFlowComponentReference(source.DataFlowComponent, sourceOutputIndex); line.DestinationDataComponent = destination.DataFlowComponent; line.Connect(ControlPointId.FirstVertex, source, source.GetControlPointIdForOutput(sourceOutputIndex)); line.Connect(ControlPointId.LastVertex, destination, destination.GetControlPointIdForInput(0)); }
private void _ShowShape(FilterSetupShapeBase setupShapeBase) { diagramDisplay.Diagram.AddShapeToLayers(setupShapeBase, _visibleLayer.Id); diagramDisplay.Diagram.RemoveShapeFromLayers(setupShapeBase, _hiddenLayer.Id); }
private void _ResizeAndPositionNestingShape(FilterSetupShapeBase shape, int width, int x, int y, bool visible) { if (visible) { _ShowShape(shape); } else { _HideShape(shape); } if (width < SHAPE_MIN_WIDTH) width = SHAPE_MIN_WIDTH; if (visible && (shape is NestingSetupShape) && (shape as NestingSetupShape).Expanded && (shape as NestingSetupShape).ChildFilterShapes.Count > 0) { int curY = y + SHAPE_GROUP_HEADER_HEIGHT; foreach (FilterSetupShapeBase childShape in (shape as NestingSetupShape).ChildFilterShapes) { _ResizeAndPositionNestingShape(childShape, width - SHAPE_CHILD_WIDTH_REDUCTION, x, curY, true); curY += childShape.Height + SHAPE_VERTICAL_SPACING; } shape.Width = width; shape.Height = (curY - SHAPE_VERTICAL_SPACING + SHAPE_GROUP_FOOTER_HEIGHT) - y; } else { shape.Width = width; shape.Height = SHAPE_DEFAULT_HEIGHT; if (shape is NestingSetupShape) { foreach (FilterSetupShapeBase childShape in (shape as NestingSetupShape).ChildFilterShapes) { _ResizeAndPositionNestingShape(childShape, width, x, y, false); } } } shape.X = x; shape.Y = y + shape.Height/2; }
private void _RemoveDataFlowLinksFromShapePoint(FilterSetupShapeBase shape, ControlPointId controlPoint, bool removePatching) { foreach (ShapeConnectionInfo ci in shape.GetConnectionInfos(controlPoint, null)) { if (ci.OtherShape == null) continue; DataFlowConnectionLine line = ci.OtherShape as DataFlowConnectionLine; if (line == null) throw new Exception("a shape was connected to something other than a DataFlowLine!"); // only try and unpatch if we're supposed to; this function can also be used to hide/remove lines from the display if (removePatching) { // if the line is connected with the given shape as the SOURCE, remove the unknown DESTINATION's // source (on the other end of the line). Otherwise, it (should) be that the given shape is the // destination; so reset it's source. If neither of these are true, freak out. if (line.GetConnectionInfo(ControlPointId.FirstVertex, null).OtherShape == shape) { if (line.DestinationDataComponent != null) VixenSystem.DataFlow.ResetComponentSource(line.DestinationDataComponent); } else if (line.GetConnectionInfo(ControlPointId.LastVertex, null).OtherShape == shape) { VixenSystem.DataFlow.ResetComponentSource(shape.DataFlowComponent); } else { throw new Exception("Can't reset a link that has neither the source or destination for the given shape!"); } OnPatchingUpdated(); } _RemoveShapeFromDiagram(line, false); } }
private void _RemoveDataFlowLinksFromAllShapePoints(FilterSetupShapeBase shape, bool removePatching) { ControlPointId pointId; // go through all outputs for the shape, and check for connections to other shapes. for (int i = 0; i < shape.OutputCount; i++) { pointId = shape.GetControlPointIdForOutput(i); _RemoveDataFlowLinksFromShapePoint(shape, pointId, removePatching); } // now check the source of the filter; if it's connected to anything, remove the connecting shape. if (shape.InputCount > 0) { pointId = shape.GetControlPointIdForInput(0); _RemoveDataFlowLinksFromShapePoint(shape, pointId, removePatching); } }
private void _LookupAndConnectShapeToSource(FilterSetupShapeBase shape) { if (shape.DataFlowComponent != null && shape.DataFlowComponent.Source != null) { IDataFlowComponentReference source = shape.DataFlowComponent.Source; if (!_dataFlowComponentToShapes.ContainsKey(source.Component)) { Logging.Error("CreateConnectionsFromExistingLinks: can't find shape for source " + source.Component + source.OutputIndex); return; } List<FilterSetupShapeBase> sourceShapes = _dataFlowComponentToShapes[source.Component]; // TODO: deal with multiple instances of the source data flow component: eg. a element existing as // multiple shapes (currently, we'll assume it's the first shape in the list) ConnectShapes(sourceShapes.First(), source.OutputIndex, shape); } }
private IDataFlowComponent _getDataFlowComponentSourceFromShape(FilterSetupShapeBase shape) { IDataFlowComponent source = null; if (shape.DataFlowComponent != null && shape.DataFlowComponent.Source != null && shape.DataFlowComponent.Source.Component != null) { source = shape.DataFlowComponent.Source.Component; } return source; }