コード例 #1
0
ファイル: MasteringCommands.cs プロジェクト: zparr/ATF
        private object[] ExpandMaster(CircuitEditingContext context, SubCircuitInstance subCircuitInstance)
        {
            // remove the sub-circuit instance
            var circuit = context.CircuitContainer;

            circuit.Elements.Remove(subCircuitInstance);

            SubCircuit subCircuit = subCircuitInstance.SubCircuit as SubCircuit;

            // clone sub-circuit contents
            List <object> subCircuitContents = new List <object>();

            subCircuitContents.AddRange(Adapters.AsIEnumerable <object>(subCircuit.Elements));
            subCircuitContents.AddRange(Adapters.AsIEnumerable <object>(subCircuit.Wires));
            DomNode[] clones = DomNode.Copy(Adapters.AsIEnumerable <DomNode>(subCircuitContents));

            object[] data = new object[clones.Length];
            clones.CopyTo(data, 0);
            return(data);
        }
コード例 #2
0
 public void SetDocument(CircuitEditingContext editingContext, ViewingContext viewingContext)
 {
     m_editingContext = editingContext;
     m_viewingContext = viewingContext;
     SetDefaultPrinterSettings();
 }
コード例 #3
0
ファイル: MasteringCommands.cs プロジェクト: zparr/ATF
        private SubCircuitInstance CreateMaster(CircuitEditingContext context)
        {
            var circuit = context.CircuitContainer;

            // get the selected modules and the connections between them
            HashSet <Element> modules             = new HashSet <Element>();
            List <Wire>       internalConnections = new List <Wire>();
            List <Wire>       externalConnections = new List <Wire>();

            GetSubCircuit(context.Selection, circuit, modules, internalConnections, externalConnections, externalConnections);

            // clone modules and connections, as the originals could be restored in a future undo operation
            List <DomNode> originals = new List <DomNode>();

            originals.AddRange(Adapters.AsIEnumerable <DomNode>(modules));
            originals.AddRange(Adapters.AsIEnumerable <DomNode>(internalConnections));
            IEnumerable <DomNode> clones = DomNode.Copy(originals);

            // translate cloned modules so the top-left most one is at 16, 16
            int left = int.MaxValue, top = int.MaxValue;

            foreach (Element module in modules)
            {
                Point p = module.Position;
                left = Math.Min(left, p.X);
                top  = Math.Min(top, p.Y);
            }

            // remove modules from circuit (connections will be removed by reference validator)
            foreach (Element module in modules)
            {
                circuit.Elements.Remove(module);
            }

            // build the sub-circuit type
            SubCircuit subCircuit = new DomNode(SubCircuitType).As <SubCircuit>();

            subCircuit.Name = "MasterInstance";

            // add modules to sub-circuit, and create pins for "connector" modules
            IList <ICircuitPin> inputPins = subCircuit.Inputs;
            IList <ICircuitPin> outputPins = subCircuit.Outputs;

            foreach (Element module in Adapters.AsIEnumerable <Element>(clones))
            {
                Point p = module.Position;
                module.Position = new Point(p.X - left + 16, p.Y - top + 16);
                subCircuit.Elements.Add(module);
            }

            // Add connections to sub circuit, keeping track of which pins have a connection.
            var connectedInputPins = new HashSet <Pair <Element, ICircuitPin> >();
            var connectedOutputPins = new HashSet <Pair <Element, ICircuitPin> >();

            foreach (Wire connection in Adapters.AsIEnumerable <Wire>(clones))
            {
                subCircuit.Wires.Add(connection);
                connectedInputPins.Add(new Pair <Element, ICircuitPin>(connection.InputElement, connection.InputPin));
                connectedOutputPins.Add(new Pair <Element, ICircuitPin>(connection.OutputElement, connection.OutputPin));
            }

            // Add in the input and output pins to the sub-circuit. Add in only the pins that have
            //  no connections. Only check the types that are connectors.
            foreach (Element module in subCircuit.Elements)
            {
                ElementType elementType = module.Type as ElementType;
                if (elementType != null && elementType.IsConnector)
                {
                    foreach (ICircuitPin outputPin in elementType.Outputs)
                    {
                        if (!connectedOutputPins.Contains(new Pair <Element, ICircuitPin>(module, outputPin)))
                        {
                            Pin pin = new DomNode(CircuitPinType).As <Pin>();
                            pin.Name     = module.Name;
                            pin.TypeName = outputPin.TypeName;
                            pin.Index    = outputPins.Count;
                            outputPins.Add(pin);
                        }
                    }
                    foreach (ICircuitPin inputPin in elementType.Inputs)
                    {
                        if (!connectedInputPins.Contains(new Pair <Element, ICircuitPin>(module, inputPin)))
                        {
                            Pin pin = new DomNode(CircuitPinType).As <Pin>();
                            pin.Name     = module.Name;
                            pin.TypeName = inputPin.TypeName;
                            pin.Index    = inputPins.Count;
                            inputPins.Add(pin);
                        }
                    }
                }
            }

            // create sub circuit instance to replace selection
            SubCircuitInstance subCircuitInstance =
                new DomNode(SubCircuitInstanceType).As <SubCircuitInstance>();

            subCircuitInstance.Id         = "MasterInstance";
            subCircuitInstance.SubCircuit = subCircuit;

            return(subCircuitInstance);
        }