Example #1
0
        /// <summary>
        /// create a sample motor
        /// </summary>
        private void createNewSampleProject(Type motorType)
        {
            // sample motor
            Motor = GetSampleMotor(motorType);
            // get analyser attached to motor
            staticAnalyser     = Motor.GetStaticAnalyser();
            analyticalAnalyser = Motor.GetAnalyticalAnalyser();
            // sample analysis config
            TransAnalysisGroup = new Dictionary <String, AbstractTransientAnalyser>();
            AbstractTransientAnalyser ta_sample = GetDefaultTransientAnalyser();

            TransAnalysisGroup.Add(ta_sample.AnalysisName, ta_sample);

            mmAnalyser        = GetDefaultMMAnalyser();
            dqcurrentAnalyser = GetDefaultDQCurrentAnalyser();

            pSweeper = new ParamSweeper();
        }
Example #2
0
        /// <summary>
        /// Open existed project
        /// </summary>
        /// <param name="fn"></param>
        /// <returns></returns>
        public bool openProject(String fn)
        {
            // read params from file
            using (StreamReader sr = new StreamReader(fn))
            {
                //String str = sr.ReadToEnd();
                var        dict    = JSON.Parse(sr.ReadToEnd()) as Dictionary <string, object>;
                JsonObject jsonAll = dict;

                JsonObject joDatatype = (JsonObject)jsonAll[JSONNAME_DATATYPE];
                JsonObject joData     = (JsonObject)jsonAll[JSONNAME_DATA];

                // motor
                Type motortype = Type.GetType(joDatatype[JSONNAME_MOTOR].ToString());
                if (motortype != null)
                {
                    string str = JSON.ToJSON(joData[JSONNAME_MOTOR]);
                    Motor = JSON.ToObject(str, motortype) as AbstractMotor;
                }
                else
                {
                    log.Error("Cannot load motor as " + joDatatype[JSONNAME_MOTOR].ToString());
                    Motor = GetSampleMotor(DefaultMotorType);
                }

                // transient
                TransAnalysisGroup = new Dictionary <String, AbstractTransientAnalyser>();
                Type taType = Type.GetType(joDatatype[JSONNAME_TRANSIENTANALYSERS].ToString());
                if (taType != null)
                {
                    var TransAnalysers = JSON.Parse(JSON.ToJSON(joData[JSONNAME_TRANSIENTANALYSERS])) as IDictionary <string, object>;
                    foreach (string ta_name in TransAnalysers.Keys)
                    {
                        var ta_value = TransAnalysers[ta_name];
                        AbstractTransientAnalyser ta = (AbstractTransientAnalyser)JSON.ToObject(JSON.ToJSON(ta_value), taType);
                        TransAnalysisGroup.Add(ta_name.ToString(), ta);
                    }
                }
                else //type not match, just get a default one
                {
                    log.Error("Cannot load transient analyser as " + joDatatype[JSONNAME_TRANSIENTANALYSERS].ToString());
                    AbstractTransientAnalyser ta_sample = GetDefaultTransientAnalyser();
                    TransAnalysisGroup.Add(ta_sample.AnalysisName, ta_sample);
                }

                // mm
                Type mmatype = Type.GetType(joDatatype[JSONNAME_MMANALYSERS].ToString());
                if (mmatype != null)
                {
                    mmAnalyser = (AbstractMMAnalyser)JSON.ToObject(JSON.ToJSON(joData[JSONNAME_MMANALYSERS]), mmatype);
                }
                else
                {
                    log.Error("Cannot load mm analyser as " + joDatatype[JSONNAME_MMANALYSERS].ToString());
                    mmAnalyser = GetDefaultMMAnalyser();
                }

                // dqa
                Type dqatype = joDatatype.ContainsKey(JSONNAME_DQCURRENTANALYSER) ? Type.GetType(joDatatype[JSONNAME_DQCURRENTANALYSER].ToString()) : null;
                if (dqatype != null)
                {
                    dqcurrentAnalyser = (PM_DQCurrentAnalyser)JSON.ToObject(JSON.ToJSON(joData[JSONNAME_DQCURRENTANALYSER]), dqatype);
                }
                else
                {
                    log.Error("Cannot load dq current analyser");
                    dqcurrentAnalyser = GetDefaultDQCurrentAnalyser();
                }

                // finished load params to a parameterscollection
                log.Info("Loaded params from " + fn + ".");

                // assign new name
                CurrentProjectFile = fn;
            }

            // refresh components since references to those before open new file are expired
            RefreshComponents();

            // from components make params (save/load with components)
            ComponentsToNewParams();

            // calculate gmc, show error
            validateMotor();

            // new sweeper
            pSweeper = new ParamSweeper();

            // try load analysis results from disk
            loadResultsFromDisk();

            // update UI
            refreshAnalysisResults();
            OnMotorAnalysisResultsUpdate(this, null);

            return(true);
        }