Exemplo n.º 1
0
        public ModulationEditor(ModulationKrystal outputKrystal)
        {
            InitializeComponent();

            _outputKrystal = outputKrystal;
            _modulator = _outputKrystal.Modulator;
            if(string.IsNullOrEmpty(_outputKrystal.Name))
                _originalKrystalName = "";
            else
                _originalKrystalName = _outputKrystal.Name;
            _originalModulatorName = _modulator.Name;

            //_modulator.Name = "";
            //_outputKrystal.Name = "";

            if(String.IsNullOrEmpty(_originalModulatorName)) // the modulator has not been loaded from a file
                _modulatorWasOriginallyLoadedFromAFile = false;
            else
                _modulatorWasOriginallyLoadedFromAFile = true;

            //if(String.IsNullOrEmpty(_originalKrystalName)) // the krystal has not been loaded from a file
            //    _krystalWasOriginallyLoadedFromAFile = false;
            //else
            //    _krystalWasOriginallyLoadedFromAFile = true;

            _modulationTreeView = new ModulationTreeView(TreeView, _outputKrystal );

            _uintTable = new UIntTable(_modulator.XDim, _modulator.YDim,
                                        outputKrystal.XInputKrystal, outputKrystal.YInputKrystal);

            this.splitContainer.Panel2.Controls.Add(_uintTable);

            if(_modulatorWasOriginallyLoadedFromAFile) // the modulator has been loaded from a file
                _uintTable.IntArray = _modulator.Array;

            _uintTable.EventHandler += new UIntTable.UIntTableEventHandler(HandleUIntTableEvents);

            this.DoModulation();
            _saved = true;

            SetFormTextAndButtons();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns 0 if both matrices are identical, otherwise compares the two names.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public int CompareTo(object other)
        {
            Modulator otherModulator = other as Modulator;

            if (otherModulator == null)
            {
                throw new ArgumentException();
            }

            bool modulatorsAreEquivalent = false;

            if (this.XDim == otherModulator.XDim &&
                this.YDim == otherModulator.YDim)
            {
                modulatorsAreEquivalent = true;
                for (int x = 0; x < this.XDim; x++)
                {
                    for (int y = 0; y < this.YDim; y++)
                    {
                        if (this.Array[x, y] != otherModulator.Array[x, y])
                        {
                            modulatorsAreEquivalent = false;
                            break;
                        }
                    }
                    if (modulatorsAreEquivalent == false)
                    {
                        break;
                    }
                }
            }

            if (modulatorsAreEquivalent)
            {
                return(0);
            }
            else
            {
                return(this.Name.CompareTo(otherModulator.Name));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// constructor for loading a complete modulated krystal from a file
        /// </summary>
        /// <param name="filepath"></param>
        public ModulationKrystal(string filepath)
            : base(filepath)
        {
            string modulatorName = "";

            using (XmlReader r = XmlReader.Create(filepath))
            {
                K.ReadToXmlElementTag(r, "modulation"); // check that this is a modulation (the other checks have been done in base()
                for (int attr = 0; attr < 3; attr++)
                {
                    r.MoveToAttribute(attr);
                    switch (r.Name)
                    {
                    case "x":
                        this._xInputFilename = r.Value;
                        break;

                    case "y":
                        this._yInputFilename = r.Value;
                        break;

                    case "modulator":
                        modulatorName = r.Value;
                        break;
                    }
                }
            }
            string xInputFilepath    = K.KrystalsFolder + @"\" + _xInputFilename;
            string yInputFilepath    = K.KrystalsFolder + @"\" + _yInputFilename;
            string modulatorFilepath = K.ModulationOperatorsFolder + @"\" + modulatorName;

            _xInputKrystal = new ModulationInputKrystal(xInputFilepath);
            _yInputKrystal = new ModulationInputKrystal(yInputFilepath);
            _modulator     = new Modulator(modulatorFilepath);

            _modulationNodeList = GetModulationNodeList();

            SetRedundantQualifierCoordinates();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Constructor used when beginning to edit a new modulated krystal (which has no modulator or strands yet).
        /// </summary>
        /// <param name="xInputFilepath">The file path to the x input</param>
        /// <param name="yInputFilepath">The file path to the y input</param>
        /// <param name="modulatorFilepath">The file path to the krystal containing the modulator (may be null or empty)</param>
        public ModulationKrystal(string xInputFilepath, string yInputFilepath, string modulatorFilepath)
            : base()
        {
            _xInputFilename = Path.GetFileName(xInputFilepath);
            _yInputFilename = Path.GetFileName(yInputFilepath);

            _xInputKrystal = new ModulationInputKrystal(xInputFilepath);
            _yInputKrystal = new ModulationInputKrystal(yInputFilepath);

            _modulationNodeList = GetModulationNodeList();

            this._level = _yInputKrystal.Level > _xInputKrystal.Level ? _yInputKrystal.Level : _xInputKrystal.Level;

            if (_yInputKrystal.Level == _xInputKrystal.Level && _yInputKrystal.NumValues != _xInputKrystal.NumValues)
            {
                throw new ApplicationException("Error: the two input krystals are not of compatible size.");
            }
            if (_yInputKrystal.Level == 0 && _xInputKrystal.Level == 0)
            {
                throw new ApplicationException("Error: the two input krystals cannot both be constants.");
            }

            if (string.IsNullOrEmpty(modulatorFilepath))
            {
                _modulator = new Modulator((int)_xInputKrystal.MaxValue, (int)_yInputKrystal.MaxValue);
            }
            else
            {
                _modulator = new Modulator(modulatorFilepath);

                if (_modulator.XDim < _xInputKrystal.MaxValue || _modulator.YDim < _yInputKrystal.MaxValue)
                {
                    throw new ApplicationException("Error: One or more input values exceed the bounds of the modulator.");
                }
            }
            SetRedundantQualifierCoordinates();
        }
Exemplo n.º 5
0
        /// <summary>
        /// constructor for loading a complete modulated krystal from a file
        /// </summary>
        /// <param name="filepath"></param>
        public ModulationKrystal(string filepath)
            : base(filepath)
        {
            string modulatorName = "";
            using(XmlReader r = XmlReader.Create(filepath))
            {
                K.ReadToXmlElementTag(r, "modulation"); // check that this is a modulation (the other checks have been done in base()
                for(int attr = 0; attr < 3; attr++)
                {
                    r.MoveToAttribute(attr);
                    switch(r.Name)
                    {
                        case "x":
                            this._xInputFilename = r.Value;
                            break;
                        case "y":
                            this._yInputFilename = r.Value;
                            break;
                        case "modulator":
                            modulatorName = r.Value;
                            break;
                    }
                }
            }
            string xInputFilepath = K.KrystalsFolder + @"\" + _xInputFilename;
            string yInputFilepath = K.KrystalsFolder + @"\" + _yInputFilename;
            string modulatorFilepath = K.ModulationOperatorsFolder + @"\" + modulatorName;

            _xInputKrystal = new ModulationInputKrystal(xInputFilepath);
            _yInputKrystal = new ModulationInputKrystal(yInputFilepath);
            _modulator = new Modulator(modulatorFilepath);

            _modulationNodeList = GetModulationNodeList();

            SetRedundantQualifierCoordinates();
        }
Exemplo n.º 6
0
        public void Save()
        {
            bool   equivalentExists = false;
            string pathname         = "";

            if (string.IsNullOrEmpty(_name)) // this is a new or newly edited modulator
            {
                DirectoryInfo dir = new DirectoryInfo(K.ModulationOperatorsFolder);
                foreach (FileInfo fileInfo in dir.GetFiles("m*.kmod"))
                {
                    Modulator otherModulator = new Modulator(K.ModulationOperatorsFolder + @"\" + fileInfo.Name);
                    if (this.CompareTo(otherModulator) == 0)
                    {
                        equivalentExists = true;
                        _name            = otherModulator.Name;
                        pathname         = K.ModulationOperatorsFolder + @"\" + _name;
                        break;
                    }
                }

                if (!equivalentExists) // generate a new name
                {
                    int fileIndex = 1;
                    do
                    {
                        _name = String.Format("m{0}x{1}({2})-{3}{4}",
                                              _xDim, _yDim, MaxValue, fileIndex, K.ModulatorFilenameSuffix);
                        pathname = K.ModulationOperatorsFolder + @"\" + _name;
                        fileIndex++;
                    } while(File.Exists(pathname));
                }
            }
            else
            {
                pathname = K.ModulationOperatorsFolder + @"\" + _name;
            }

            if (MaxValueHasChanged()) // rename the current modulator
            {
                File.Delete(pathname);
                _name = "";
                Save(); // recursive call saves under a new name
            }
            else if (!equivalentExists)
            {
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent      = true;
                settings.IndentChars = ("\t");
                settings.CloseOutput = true;

                using (XmlWriter w = XmlWriter.Create(pathname, settings))
                {
                    w.WriteStartDocument();
                    w.WriteComment("created: " + K.Now);

                    w.WriteStartElement("modulator");
                    w.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
                    w.WriteAttributeString("xsi", "noNamespaceSchemaLocation", null, K.MoritzXmlSchemasFolder + @"\krystals.xsd");

                    w.WriteStartElement("array");
                    w.WriteAttributeString("xdim", _xDim.ToString());
                    w.WriteAttributeString("ydim", _yDim.ToString());
                    w.WriteString(MatrixAsString);
                    w.WriteEndElement(); // array
                    w.WriteEndElement(); // modulator
                    w.Close();
                }
            }
        }
Exemplo n.º 7
0
        public void Save()
        {
            bool equivalentExists = false;
            string pathname = "";
            if(string.IsNullOrEmpty(_name)) // this is a new or newly edited modulator
            {
                DirectoryInfo dir = new DirectoryInfo(K.ModulationOperatorsFolder);
                foreach(FileInfo fileInfo in dir.GetFiles("m*.kmod"))
                {
                    Modulator otherModulator = new Modulator(K.ModulationOperatorsFolder + @"\" + fileInfo.Name);
                    if(this.CompareTo(otherModulator) == 0)
                    {
                        equivalentExists = true;
                        _name = otherModulator.Name;
                        pathname = K.ModulationOperatorsFolder + @"\" + _name;
                        break;
                    }
                }

                if(!equivalentExists) // generate a new name
                {
                    int fileIndex = 1;
                    do
                    {
                        _name = String.Format("m{0}x{1}({2})-{3}{4}",
                            _xDim, _yDim, MaxValue, fileIndex, K.ModulatorFilenameSuffix);
                        pathname = K.ModulationOperatorsFolder + @"\" + _name;
                        fileIndex++;
                    } while(File.Exists(pathname));
                }
            }
            else pathname = K.ModulationOperatorsFolder + @"\" + _name;

            if(MaxValueHasChanged()) // rename the current modulator
            {
                File.Delete(pathname);
                _name = "";
                Save(); // recursive call saves under a new name
            }
            else if(!equivalentExists)
            {
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent = true;
                settings.IndentChars = ("\t");
                settings.CloseOutput = true;

                using(XmlWriter w = XmlWriter.Create(pathname, settings))
                {
                    w.WriteStartDocument();
                    w.WriteComment("created: " + K.Now);

                    w.WriteStartElement("modulator");
                    w.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
                    w.WriteAttributeString("xsi", "noNamespaceSchemaLocation", null, K.MoritzXmlSchemasFolder + @"\krystals.xsd");

                    w.WriteStartElement("array");
                    w.WriteAttributeString("xdim", _xDim.ToString());
                    w.WriteAttributeString("ydim", _yDim.ToString());
                    w.WriteString(MatrixAsString);
                    w.WriteEndElement(); // array
                    w.WriteEndElement(); // modulator
                    w.Close();
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Constructor used when beginning to edit a new modulated krystal (which has no modulator or strands yet).
        /// </summary>
        /// <param name="xInputFilepath">The file path to the x input</param>
        /// <param name="yInputFilepath">The file path to the y input</param>
        /// <param name="modulatorFilepath">The file path to the krystal containing the modulator (may be null or empty)</param>
        public ModulationKrystal(string xInputFilepath, string yInputFilepath, string modulatorFilepath)
            : base()
        {
            _xInputFilename = Path.GetFileName(xInputFilepath);
            _yInputFilename = Path.GetFileName(yInputFilepath);

            _xInputKrystal = new ModulationInputKrystal(xInputFilepath);
            _yInputKrystal = new ModulationInputKrystal(yInputFilepath);

            _modulationNodeList = GetModulationNodeList();

            this._level = _yInputKrystal.Level > _xInputKrystal.Level ? _yInputKrystal.Level : _xInputKrystal.Level;

            if(_yInputKrystal.Level == _xInputKrystal.Level && _yInputKrystal.NumValues != _xInputKrystal.NumValues)
                throw new ApplicationException("Error: the two input krystals are not of compatible size.");
            if(_yInputKrystal.Level == 0 && _xInputKrystal.Level == 0)
                throw new ApplicationException("Error: the two input krystals cannot both be constants.");

            if(string.IsNullOrEmpty(modulatorFilepath))
            {
                _modulator = new Modulator((int)_xInputKrystal.MaxValue, (int)_yInputKrystal.MaxValue);
            }
            else
            {
                _modulator = new Modulator(modulatorFilepath);

                if(_modulator.XDim < _xInputKrystal.MaxValue || _modulator.YDim < _yInputKrystal.MaxValue)
                    throw new ApplicationException("Error: One or more input values exceed the bounds of the modulator.");
            }
            SetRedundantQualifierCoordinates();
        }