Exemplo n.º 1
0
        protected override Pin GetCircuitToDrop(CircuitProject circuitProject)
        {
            Pin pin = circuitProject.PinSet.Create(circuitProject.ProjectSet.Project.LogicalCircuit, this.Circuit.PinType, this.BitWidth);

            pin.PinSide = this.PinSide.Value;
            return(pin);
        }
        public DialogImport(string file, CircuitProject target)
        {
            this.FileName    = file;
            this.DataContext = this;
            this.InitializeComponent();
            Mainframe mainframe = App.Mainframe;
            Thread    thread    = new Thread(new ThreadStart(() => {
                try {
                    CircuitProject import   = CircuitProject.Create(file);
                    List <CircuitInfo> list = new List <CircuitInfo>();
                    foreach (LogicalCircuit circuit in import.LogicalCircuitSet)
                    {
                        list.Add(new CircuitInfo(circuit, target.LogicalCircuitSet.FindByLogicalCircuitId(circuit.LogicalCircuitId) == null));
                    }
                    list.Sort(CircuitDescriptorComparer.Comparer);
                    this.List = list;
                    this.NotifyPropertyChanged(nameof(this.List));
                } catch (SnapStoreException snapStoreException) {
                    Tracer.Report("DialogImport.Load", snapStoreException);
                    mainframe.ErrorMessage(Properties.Resources.ErrorFileCorrupted(file), snapStoreException);
                    mainframe.Dispatcher.BeginInvoke(new Action(() => { this.Close(); }));
                } catch (Exception exception) {
                    Tracer.Report("DialogImport.Load", exception);
                    mainframe.ReportException(exception);
                    mainframe.Dispatcher.BeginInvoke(new Action(() => { this.Close(); }));
                }
            }));

            //TextNote validation will instantiate FlowDocument that in some cases required to happened only on STA.
            thread.SetApartmentState(ApartmentState.STA);
            thread.IsBackground = true;
            thread.Name         = "ImportLoader";
            thread.Priority     = ThreadPriority.AboveNormal;
            thread.Start();
        }
Exemplo n.º 3
0
 // Constructor
 public LedMatrix(CircuitProject store, RowId rowIdLedMatrix, RowId rowIdCircuit) : base(store, rowIdCircuit)
 {
     Debug.Assert(!rowIdLedMatrix.IsEmpty);
     this.LedMatrixRowId = rowIdLedMatrix;
     // Link back to record. Assuming that a transaction is started
     this.Table.SetField(this.LedMatrixRowId, LedMatrixData.LedMatrixField.Field, this);
     this.InitializeLedMatrix();
 }
Exemplo n.º 4
0
 // Constructor
 public Sensor(CircuitProject store, RowId rowIdSensor, RowId rowIdCircuit) : base(store, rowIdCircuit)
 {
     Debug.Assert(!rowIdSensor.IsEmpty);
     this.SensorRowId = rowIdSensor;
     // Link back to record. Assuming that a transaction is started
     this.Table.SetField(this.SensorRowId, SensorData.SensorField.Field, this);
     this.InitializeSensor();
 }
Exemplo n.º 5
0
 // Constructor
 public Sound(CircuitProject store, RowId rowIdSound, RowId rowIdCircuit) : base(store, rowIdCircuit)
 {
     Debug.Assert(!rowIdSound.IsEmpty);
     this.SoundRowId = rowIdSound;
     // Link back to record. Assuming that a transaction is started
     this.Table.SetField(this.SoundRowId, SoundData.SoundField.Field, this);
     this.InitializeSound();
 }
Exemplo n.º 6
0
 // Constructor
 public GraphicsArray(CircuitProject store, RowId rowIdGraphicsArray, RowId rowIdCircuit) : base(store, rowIdCircuit)
 {
     Debug.Assert(!rowIdGraphicsArray.IsEmpty);
     this.GraphicsArrayRowId = rowIdGraphicsArray;
     // Link back to record. Assuming that a transaction is started
     this.Table.SetField(this.GraphicsArrayRowId, GraphicsArrayData.GraphicsArrayField.Field, this);
     this.InitializeGraphicsArray();
 }
Exemplo n.º 7
0
 // Constructor
 public DevicePin(CircuitProject store, RowId rowIdDevicePin, RowId rowIdCircuit) : base(store, rowIdCircuit)
 {
     Debug.Assert(!rowIdDevicePin.IsEmpty);
     this.DevicePinRowId = rowIdDevicePin;
     // Link back to record. Assuming that a transaction is started
     this.Table.SetField(this.DevicePinRowId, DevicePinData.DevicePinField.Field, this);
     this.InitializeDevicePin();
 }
Exemplo n.º 8
0
        protected override CircuitProbe GetCircuitToDrop(CircuitProject circuitProject)
        {
            string name = this.Name;

            this.Name = string.Empty;
            this.NotifyPropertyChanged("Name");
            return(circuitProject.CircuitProbeSet.Create(name));
        }
Exemplo n.º 9
0
 // Constructor
 public CircuitProbe(CircuitProject store, RowId rowIdCircuitProbe, RowId rowIdCircuit) : base(store, rowIdCircuit)
 {
     Debug.Assert(!rowIdCircuitProbe.IsEmpty);
     this.CircuitProbeRowId = rowIdCircuitProbe;
     // Link back to record. Assuming that a transaction is started
     this.Table.SetField(this.CircuitProbeRowId, CircuitProbeData.CircuitProbeField.Field, this);
     this.InitializeCircuitProbe();
 }
Exemplo n.º 10
0
 // Constructor
 public LogicalCircuit(CircuitProject store, RowId rowIdLogicalCircuit, RowId rowIdCircuit) : base(store, rowIdCircuit)
 {
     Debug.Assert(!rowIdLogicalCircuit.IsEmpty);
     this.LogicalCircuitRowId = rowIdLogicalCircuit;
     // Link back to record. Assuming that a transaction is started
     this.Table.SetField(this.LogicalCircuitRowId, LogicalCircuitData.LogicalCircuitField.Field, this);
     this.InitializeLogicalCircuit();
 }
Exemplo n.º 11
0
 // Constructor
 public Memory(CircuitProject store, RowId rowIdMemory, RowId rowIdCircuit) : base(store, rowIdCircuit)
 {
     Debug.Assert(!rowIdMemory.IsEmpty);
     this.MemoryRowId = rowIdMemory;
     // Link back to record. Assuming that a transaction is started
     this.Table.SetField(this.MemoryRowId, MemoryData.MemoryField.Field, this);
     this.InitializeMemory();
 }
Exemplo n.º 12
0
 // Constructor
 public Constant(CircuitProject store, RowId rowIdConstant, RowId rowIdCircuit) : base(store, rowIdCircuit)
 {
     Debug.Assert(!rowIdConstant.IsEmpty);
     this.ConstantRowId = rowIdConstant;
     // Link back to record. Assuming that a transaction is started
     this.Table.SetField(this.ConstantRowId, ConstantData.ConstantField.Field, this);
     this.InitializeConstant();
 }
Exemplo n.º 13
0
 public PinDescriptor(CircuitProject circuitProject, PinType pinType) : base(
         circuitProject.PinSet.Create(circuitProject.ProjectSet.Project.LogicalCircuit, pinType, 1)
         )
 {
     this.BitWidth     = 1;
     this.PinSide      = PinDescriptor.PinSideDescriptor((pinType == PinType.Input) ? LogicCircuit.PinSide.Left : LogicCircuit.PinSide.Right);
     this.Circuit.Note = Properties.Resources.ToolTipDescriptorPin;
 }
Exemplo n.º 14
0
 public SensorDescriptor(CircuitProject circuitProject) : base(circuitProject.SensorSet.Create(LogicCircuit.SensorType.Random, 1, LogicCircuit.PinSide.Right, string.Empty))
 {
     this.sensorType   = SensorDescriptor.sensorTypes.First(t => t.Value == this.Circuit.SensorType);
     this.BitWidth     = this.Circuit.BitWidth;
     this.pinSide      = PinDescriptor.PinSideDescriptor(this.Circuit.PinSide);
     this.Notation     = string.Empty;
     this.Circuit.Note = Properties.Resources.ToolTipDescriptorSensor;
 }
Exemplo n.º 15
0
 // Constructor
 public CollapsedCategory(CircuitProject store, RowId rowIdCollapsedCategory)
 {
     Debug.Assert(!rowIdCollapsedCategory.IsEmpty);
     this.CircuitProject         = store;
     this.CollapsedCategoryRowId = rowIdCollapsedCategory;
     // Link back to record. Assuming that a transaction is started
     this.Table.SetField(this.CollapsedCategoryRowId, CollapsedCategoryData.CollapsedCategoryField.Field, this);
     this.InitializeCollapsedCategory();
 }
Exemplo n.º 16
0
 // Constructor
 public Project(CircuitProject store, RowId rowIdProject)
 {
     Debug.Assert(!rowIdProject.IsEmpty);
     this.CircuitProject = store;
     this.ProjectRowId   = rowIdProject;
     // Link back to record. Assuming that a transaction is started
     this.Table.SetField(this.ProjectRowId, ProjectData.ProjectField.Field, this);
     this.InitializeProject();
 }
Exemplo n.º 17
0
 // Constructor
 protected Circuit(CircuitProject store, RowId rowIdCircuit)
 {
     Debug.Assert(!rowIdCircuit.IsEmpty);
     this.CircuitProject = store;
     this.CircuitRowId   = rowIdCircuit;
     // Link back to record. Assuming that a transaction is started
     this.Table.SetField(this.CircuitRowId, CircuitData.CircuitField.Field, this);
     this.InitializeCircuit();
 }
Exemplo n.º 18
0
 // Constructor
 public TextNote(CircuitProject store, RowId rowIdTextNote)
 {
     Debug.Assert(!rowIdTextNote.IsEmpty);
     this.CircuitProject = store;
     this.TextNoteRowId  = rowIdTextNote;
     // Link back to record. Assuming that a transaction is started
     this.Table.SetField(this.TextNoteRowId, TextNoteData.TextNoteField.Field, this);
     this.InitializeTextNote();
 }
Exemplo n.º 19
0
 // Constructor
 public Wire(CircuitProject store, RowId rowIdWire)
 {
     Debug.Assert(!rowIdWire.IsEmpty);
     this.CircuitProject = store;
     this.WireRowId      = rowIdWire;
     // Link back to record. Assuming that a transaction is started
     this.Table.SetField(this.WireRowId, WireData.WireField.Field, this);
     this.InitializeWire();
 }
Exemplo n.º 20
0
        public TextNoteDescriptor(CircuitProject circuitProject)
        {
            // create dummy circuit to provide category and name for sorting and displaying in list of circuits descriptors
            LogicalCircuit circuit = circuitProject.LogicalCircuitSet.Create();

            circuit.Category = Properties.Resources.TextNotation;
            circuit.Name     = Properties.Resources.TextNotation;
            this.Circuit     = circuit;
        }
Exemplo n.º 21
0
 // Constructor
 public CircuitSymbol(CircuitProject store, RowId rowIdCircuitSymbol)
 {
     Debug.Assert(!rowIdCircuitSymbol.IsEmpty);
     this.CircuitProject     = store;
     this.CircuitSymbolRowId = rowIdCircuitSymbol;
     // Link back to record. Assuming that a transaction is started
     this.Table.SetField(this.CircuitSymbolRowId, CircuitSymbolData.CircuitSymbolField.Field, this);
     this.InitializeCircuitSymbol();
 }
Exemplo n.º 22
0
        public void Paste()
        {
            this.CancelMove();
            this.ClearSelection();
            IEnumerable <Symbol> result = CircuitProject.Paste(Clipboard.GetText());

            Tracer.Assert(result.All(symbol => symbol.LogicalCircuit == this.Project.LogicalCircuit));
            this.EnsureVisible(result);
            this.Select(result);
        }
 public CircuitDescriptorList(CircuitProject circuitProject) : base()
 {
     this.circuitProject = circuitProject;
     this.circuitProject.LogicalCircuitSet.LogicalCircuitSetChanged += new EventHandler(this.LogicalCircuitSetChanged);
     this.circuitProject.ProjectSet.Project.PropertyChanged         += new PropertyChangedEventHandler(this.ProjectPropertyChanged);
     if (CircuitDescriptorList.primitiveList == null)
     {
         CircuitDescriptorList.InitPrimitive();
     }
 }
Exemplo n.º 24
0
        protected override Constant GetCircuitToDrop(CircuitProject circuitProject)
        {
            int value;

            if (!int.TryParse(this.Value, NumberStyles.HexNumber, Properties.Resources.Culture, out value))
            {
                value = 0;
            }
            return(circuitProject.ConstantSet.Create(this.BitWidth, value, this.PinSide.Value));
        }
Exemplo n.º 25
0
        public void CreateSymbol(EditorDiagram editor, GridPoint point)
        {
            CircuitProject project = editor.CircuitProject;
            DialogText     dialog  = new DialogText(null);
            bool?          result  = editor.Mainframe.ShowDialog(dialog);

            if (result.HasValue && result.Value && TextNote.IsValidText(dialog.Document))
            {
                project.InTransaction(() => project.TextNoteSet.Create(editor.Project.LogicalCircuit, point, dialog.Document));
            }
        }
Exemplo n.º 26
0
        protected override Sound GetCircuitToDrop(CircuitProject circuitProject)
        {
            string notation = (this.Notation ?? string.Empty).Trim();

            if (!string.IsNullOrEmpty(notation))
            {
                this.Notation = string.Empty;
                this.NotifyPropertyChanged("Notation");
            }
            return(circuitProject.SoundSet.Create(this.PinSide.Value, notation));
        }
Exemplo n.º 27
0
        protected override CircuitButton GetCircuitToDrop(CircuitProject circuitProject)
        {
            string notation = (this.Notation ?? string.Empty).Trim();

            if (!string.IsNullOrEmpty(notation))
            {
                this.Notation = string.Empty;
                this.NotifyPropertyChanged("Notation");
            }
            return(circuitProject.CircuitButtonSet.Create(notation, this.IsToggle, this.PinSide.Value));
        }
Exemplo n.º 28
0
        private static CircuitProject CreateAndClose(XmlReader xmlReader)
        {
            try {
                CircuitProject.Transform(ref xmlReader);                    // may close original xmlReader and return another one instead.

                CircuitProject circuitProject = new CircuitProject();
                circuitProject.InTransaction(() => circuitProject.Load(xmlReader));
                circuitProject.CircuitSymbolSet.ValidateAll();
                return(circuitProject);
            } finally {
                // Don't use using here. Transform may close original XmlReader and open new one.
                xmlReader.Close();
            }
        }
Exemplo n.º 29
0
        public SplitterDescriptor(CircuitProject circuitProject) : base(circuitProject.SplitterSet.Create(3, 3, true))
        {
            this.PinCountRange  = PinDescriptor.NumberRange(2, BasePin.MaxBitWidth);
            this.BitWidthRange  = PinDescriptor.NumberRange(1, BasePin.MaxBitWidth / 2);
            this.DirectionRange = new DirectionDescriptor[] {
                new DirectionDescriptor(true, Properties.Resources.SplitterDirectionClockwise, 1),
                new DirectionDescriptor(false, Properties.Resources.SplitterDirectionCounterclockwise, -1)
            };

            this.PinCount     = 3;
            this.BitWidth     = 1;
            this.Direction    = this.DirectionRange.First();
            this.Circuit.Note = Properties.Resources.ToolTipDescriptorSplitter;
        }
        public OutputPinSocket(Pin pin)
        {
            Tracer.Assert(pin.PinType == PinType.Output);
            CircuitProject project = pin.CircuitProject;

            this.Pin   = pin;
            this.Value = project.CircuitProbeSet.Create(null);
            CircuitSymbol pinSymbol = project.CircuitSymbolSet.SelectByCircuit(pin).FirstOrDefault();

            Tracer.Assert(pinSymbol != null);
            this.Symbol          = project.CircuitSymbolSet.Create(this.Value, pin.LogicalCircuit, pinSymbol.X, pinSymbol.Y);
            this.Symbol.Rotation = pinSymbol.Rotation;
            pinSymbol.X          = pinSymbol.Y = int.MinValue;
        }