Exemplo n.º 1
0
 /// <summary>
 /// Puts the sensor into initial state.
 /// </summary>
 /// <param name="scale">Full scale acceleration range.</param>
 /// <param name="bandwidth">Bandwidth defining type and quality of filters.</param>
 public void Init(ScaleRange scale = ScaleRange.G2, Bandwidth bandwidth = Bandwidth.Hz150)
 {
     EnableSettingsEditing();
     SetScaleRange((byte)scale);
     SetBandwidth((byte)bandwidth);
     BlockMsbWhileLsbIsRead();
 }
Exemplo n.º 2
0
        private void okButton_Click(object sender, EventArgs e)
        {
            try
            {
                ClosedWithOK = true;

                // Note: SubScale should be already updated

                if (radioButtonAll.Checked)
                {
                    Range = ScaleRange.All;
                }
                else
                {
                    Range = ScaleRange.Selected;
                }

                SubtitleAnchor = Subtitle.ParseHMSTime(textBoxSubFirstRef.Text);
                MovieAnchor    = Subtitle.ParseHMSTime(textBoxMovieFirstRef.Text);

                RecalcDuration = false; // todo put this in a button

                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 3
0
        public static SparseItemInt ProcessTextAndGetSparseItem(FeatureExtractionPipeline pipeline, FeatureStatisticsDictionaryBuilder featureStatisticsDictBuilder, int minFeaturesFrequency, bool normalize, ScaleRange scaleRange, string docContent, int classLabelIndex)
        {
            Dictionary<string, double> docFeatures = new Dictionary<string, double>();
            pipeline.ProcessDocument(docContent, docFeatures);
            //Append extracted features

            //A - Extracted indexed features
            var itemIndexedFeatures = LibSvmFileBuilder.GetIndexedFeaturesFromStringFeatures(docFeatures, featureStatisticsDictBuilder.FeatureInfoStatistics, minFeaturesFrequency, normalize, scaleRange);
            var sparseItem = new SparseItemInt() { Label = classLabelIndex, Features = itemIndexedFeatures };
            return sparseItem;
        }
Exemplo n.º 4
0
 public static void SetParams(out string modulesConfig, out string inputRawFile, out string classLabelsOutputFileName, out string featuresDictOutputFile, out string modelOutputFileName, out string libSvmOutputFileName, out SolverType liblinearSolver, out double liblinearC, out double liblinearEps, out int minFeaturesFrequency, out bool normalize, out ScaleRange scaleRange)
 {
     modulesConfig = ConfigurationManager.AppSettings["PIPELINE_MODULES_CONFIG"] ?? "annotate_words,plain_bow,nsuff_3,chngram_3,word2gram,doc_end";
     inputRawFile = ConfigurationManager.AppSettings["TRAIN_RAW_FILE"] ?? "data\troll-comments.txt";
     classLabelsOutputFileName = ConfigurationManager.AppSettings["MODEL_CLASSLABELS_FILE"] != null ? ConfigurationManager.AppSettings["MODEL_CLASSLABELS_FILE"] : inputRawFile + ".classlabels";
     featuresDictOutputFile = ConfigurationManager.AppSettings["MODEL_FEATURES_FILE"] != null ? ConfigurationManager.AppSettings["MODEL_FEATURES_FILE"] : inputRawFile + ".features";
     modelOutputFileName = ConfigurationManager.AppSettings["MODEL_MODEL_FILE"] != null ? ConfigurationManager.AppSettings["MODEL_MODEL_FILE"] : inputRawFile + ".model";
     libSvmOutputFileName = inputRawFile + ".libsvm";
     liblinearSolver = SolverType.L1R_LR;
     liblinearC = ConfigurationManager.AppSettings["LIBLINEAR_C"] != null ? double.Parse(ConfigurationManager.AppSettings["LIBLINEAR_C"]) : 1.0;
     liblinearEps = ConfigurationManager.AppSettings["LIBLINEAR_EPS"] != null ? double.Parse(ConfigurationManager.AppSettings["LIBLINEAR_EPS"]) : 0.01;
     minFeaturesFrequency = 5;
     normalize = false;
     scaleRange = ScaleRange.ZeroToOne;
 }
Exemplo n.º 5
0
        public static void Train(string modulesConfig, string inputRawFile, SolverType liblinearSolver, double liblinearC, double liblinearEps,
                string classLabelsOutputFileName, string featuresDictOutputFile, string modelOutputFileName, string libSvmOutputFileName, 
                int minFeaturesFrequency,bool normalize, ScaleRange scaleRange)
        {
            //Define feature extraction modules
            #region 1 - Define all possible feature extraction modules
            List<FeatureExtractionModule> modules = PipelineConfiguration.GetExtractionModules();

            //Print possible module options
            foreach (var module in modules)
            {
                Debug.Write(module.Name + ",");
            }
            #endregion

            //configure which modules to use
            #region 2 - Configure which module configurations
            //string modulesConfig = "annotate_words,plain_bow,npref_2,npref_3,npref_4,nsuff_2,nsuff_3,nsuff_4,chngram_2,chngram_3,chngram_4,plain_word_stems,word2gram,word3gram, word4gram,count_punct,emoticons_dnevnikbg,doc_start,doc_end";

            //string settingsConfig = "annotate_words,plain_word_stems, npref_4, nsuff_3";

            FeatureExtractionPipeline pipeline = PipelineConfiguration.BuildPipeline(modulesConfig, modules);
            #endregion

            Console.WriteLine("Input file:{0}", inputRawFile);
            //char fieldSeparator = '\t';

            #region 3 - Build features dictionary - process documents and extract all possible features
            //build features dictionary
            var featureStatisticsDictBuilder = new FeatureStatisticsDictionaryBuilder();

            Console.WriteLine("Building a features dictionary...");
            var timeStart = DateTime.Now;
            int itemsCnt = 0;
            Dictionary<string, int> classLabels = new Dictionary<string, int>();
            int maxClassLabelIndex = 0;

            using (var filereader = new LabeledTextDocumentFileReader(inputRawFile))
            {
                while (!filereader.EndOfSource())
                {
                    var doc = filereader.ReadDocument();

                    //class label and doc contents
                    string classLabel = doc.ClassLabel;
                    string docContent = doc.DocContent;

                    //build class labels dictionary
                    if (!classLabels.ContainsKey(classLabel))
                    {
                        classLabels[classLabel] = maxClassLabelIndex;
                        maxClassLabelIndex++;
                    }

                    Dictionary<string, double> docFeatures = new Dictionary<string, double>();
                    pipeline.ProcessDocument(docContent, docFeatures);
                    featureStatisticsDictBuilder.UpdateInfoStatisticsFromSingleDoc(docFeatures);
                    itemsCnt++;

                    if (itemsCnt % 500 == 0)
                    {
                        Console.WriteLine("{0} processed so far", itemsCnt);
                    }
                }
            }

            //order classes by name - until now they are ordered by first occurence in dataset

            var ordered = classLabels.OrderBy(cv => cv.Key);
            var orderedClassLabels = new Dictionary<string, int>();
            int classIndexCounter = 0;
            foreach (var item in ordered)
            {
                orderedClassLabels.Add(item.Key, classIndexCounter);
                classIndexCounter++;
            }
            classLabels = orderedClassLabels;
            LexiconReaderHelper.SaveDictionaryToFile(classLabels, classLabelsOutputFileName);
            Console.WriteLine("Class labels saved to file {0}", classLabelsOutputFileName);

            Console.WriteLine("Extracted {0} features from {1} documents", featureStatisticsDictBuilder.FeatureInfoStatistics.Count, itemsCnt);
            Console.WriteLine("Done - {0}", (DateTime.Now - timeStart));

            RecomputeFeatureIndexes(featureStatisticsDictBuilder, minFeaturesFrequency);
            Console.WriteLine("Selected {0} features with min freq {1} ", featureStatisticsDictBuilder.FeatureInfoStatistics.Count, minFeaturesFrequency);

            //save fetures for later use
            if (System.IO.File.Exists(featuresDictOutputFile))
            {
                System.IO.File.Delete(featuresDictOutputFile);
            }

            featureStatisticsDictBuilder.SaveToFile(featuresDictOutputFile);
            Console.WriteLine("Features saved to file {0}", featuresDictOutputFile);
            #endregion

            //4- Load features from file
            featureStatisticsDictBuilder.LoadFromFile(featuresDictOutputFile);
            classLabels = LexiconReaderHelper.LoadDictionaryFromFile(classLabelsOutputFileName);

            #region 5 - Build items with features from text documents and features dictionary
            //Build libsvm file from text insput file and features dictionary

            var sparseItemsWithIndexFeatures = new List<SparseItemInt>();
            timeStart = DateTime.Now;
            Console.WriteLine("Exporting to libsvm file format...");

            using (System.IO.TextWriter textWriter = new System.IO.StreamWriter(libSvmOutputFileName, false))
            {
                LibSvmFileBuilder libSvmFileBuilder = new LibSvmFileBuilder(textWriter);
                using (var filereader = new LabeledTextDocumentFileReader(inputRawFile))
                {
                    while (!filereader.EndOfSource())
                    {
                        var doc = filereader.ReadDocument();

                        //class label and doc contents
                        string classLabel = doc.ClassLabel;
                        string docContent = doc.DocContent;
                        int classLabelIndex = classLabels[classLabel];

                        SparseItemInt sparseItem = ProcessingHelpers.ProcessTextAndGetSparseItem(pipeline, featureStatisticsDictBuilder, minFeaturesFrequency, normalize, scaleRange, docContent, classLabelIndex);

                        libSvmFileBuilder.AppendItem(sparseItem.Label, sparseItem.Features);
                        sparseItemsWithIndexFeatures.Add(sparseItem);

                        //B - Or extract indexed features and append
                        //libSvmFileBuilder.PreprocessStringFeaturesAndAppendItem(classLabelIndex, docFeatures, featureStatisticsDictBuilder.FeatureInfoStatistics, minFeaturesFrequency);
                    }
                }
            }

            Console.WriteLine("Done - {0}", (DateTime.Now - timeStart));
            Console.WriteLine("Libsvm file saved to {0}", libSvmOutputFileName);
            Console.WriteLine();
            #endregion

            #region 6 - Train and test classifier
            //LIBLINEAR - TRAIN AND EVAL CLASSIFIER
            //Build problem X and Y

            //Split data on train and test dataset
            int trainRate = 4;
            int testRate = 1;

            int allItemsCnt = sparseItemsWithIndexFeatures.Count;
            int trainCnt = (int)((double)allItemsCnt * trainRate / (double)(trainRate + testRate));
            int testCnt = allItemsCnt - trainCnt;

            var trainItems = sparseItemsWithIndexFeatures.Take(trainCnt).ToList();
            var testItems = sparseItemsWithIndexFeatures.Skip(trainCnt).Take(testCnt).ToList();

            string trainDataModelFileName = inputRawFile + ".train.model";

            FeatureNode[][] problemXTrain = null;
            double[] problemYTrain = null;

            SetLibLinearProblemXandYFromSparseItems(trainItems, out problemXTrain, out problemYTrain);

            TrainLibLinearProblemAndSveModel(liblinearSolver, liblinearC, liblinearEps, featureStatisticsDictBuilder, trainDataModelFileName, problemXTrain, problemYTrain);

            var modelFileLoad = new java.io.File(trainDataModelFileName);
            var modelLoaded = Model.load(modelFileLoad);

            //evaluation
            List<FeatureNode[]> problemXEvalList = new List<FeatureNode[]>();
            List<double> problemYEvalList = new List<double>();
            //SetLibLinearProblemXandYFromSparseItems(testItems, out problemXEval, out problemYEval);

            //EVALUATE
            List<double> predictedY = new List<double>();
            foreach (var item in testItems)
            {
                var itemFeatureNodes = ProcessingHelpers.ConvertToSortedFeatureNodeArray(item.Features);

                //fill eval list
                problemXEvalList.Add(itemFeatureNodes);
                problemYEvalList.Add((double)item.Label);

                //predict
                double prediction = Linear.predict(modelLoaded, itemFeatureNodes);
                predictedY.Add(prediction);
            }

            int[][] matrix = ResultCalculationMetricsHelpers.BuildConfusionMatrix(problemYEvalList.ToArray(), predictedY, classLabels.Count);

            Console.WriteLine("Class labels:");
            foreach (var label in classLabels)
            {
                Console.WriteLine(string.Format("{1} - {0}", label.Key, label.Value));
            }
            Console.WriteLine();
            ResultCalculationMetricsHelpers.PrintMatrix(matrix, true);

            for (int i = 0; i < matrix.Length; i++)
            {
                int truePositivesCnt = matrix[i][i];
                int falsePositievesCnt = matrix[i].Sum() - matrix[i][i];
                int falseNegativesCnt = matrix.Select(m => m[i]).Sum() - matrix[i][i];

                double precision;
                double recall;
                double fScore;

                ResultCalculationMetricsHelpers.CalculatePRF(truePositivesCnt, falsePositievesCnt, falseNegativesCnt, out precision, out recall, out fScore);
                Console.WriteLine(string.Format("[{0} - {4}] P={1:0.0000}, R={2:0.0000}, F={3:0.0000} ", i, precision, recall, fScore, orderedClassLabels.ToList().ToDictionary(kv => kv.Value, kv => kv.Key)[i]));
            }

            int truePositivesCntOverall = 0;
            int testedCnt = 0;
            for (int i = 0; i < matrix.Length; i++)
            {
                truePositivesCntOverall += matrix[i][i];
                testedCnt += matrix[i].Sum();
            }

            double accuracyOverall = (double)truePositivesCntOverall / (double)testedCnt;
            Console.WriteLine(string.Format("[{0}] Accuracy={1:0.0000}", "Overall", accuracyOverall));

            //----TRAIN MODEL IWTH ALL DATA
            Console.WriteLine("------------------------------------------------");
            Console.WriteLine("Train model on all data");

            FeatureNode[][] problemXAll = null;
            double[] problemYAll = null;

            var allItems = sparseItemsWithIndexFeatures;
            SetLibLinearProblemXandYFromSparseItems(allItems, out problemXAll, out problemYAll);

            TrainLibLinearProblemAndSveModel(liblinearSolver, liblinearC, liblinearEps, featureStatisticsDictBuilder, modelOutputFileName, problemXAll, problemYAll);

            //CROSSVALIDATION
            //int crossValidationFold = 5;
            //Console.WriteLine("Training with {0} items and 5 fold crossvalidation...", sparseItemsWithIndexFeatures.Count);
            //timeStart = DateTime.Now;
            //double[] target = new double[problem.l];
            //Linear.crossValidation(problem, parameter, crossValidationFold, target);
            //Console.WriteLine("Done - {0}", (DateTime.Now - timeStart));

            //WriteResult(target);
            #endregion

            //Console.ReadKey();

            //var instancesToTest = new Feature[] { new FeatureNode(1, 0.0), new FeatureNode(2, 1.0) };
            //var prediction = Linear.predict(model, instancesToTest);
        }
Exemplo n.º 6
0
        private static void CategorizeText(string text, int minFeaturesFrequency, bool normalize, ScaleRange scaleRange, FeatureExtractionPipeline pipeline, FeatureStatisticsDictionaryBuilder featureStatisticsDictBuilder, Dictionary<string, int> classLabels, Model modelLoaded, out double prediction, out int label, out string labelName, out double confidence)
        {
            SparseItemInt sparseItem = ProcessingHelpers.ProcessTextAndGetSparseItem(pipeline, featureStatisticsDictBuilder, minFeaturesFrequency, normalize, scaleRange, text, 0);
            var itemFeatureNodes = ProcessingHelpers.ConvertToSortedFeatureNodeArray(sparseItem.Features);

            //predict
            prediction = Linear.predict(modelLoaded, itemFeatureNodes);
            label = (int)prediction;
            labelName = "unknown";
            var labelInt = label;
            if (classLabels.ContainsValue(labelInt))
            {
                labelName = classLabels.ToList().Where(k => k.Value == labelInt).Select(k => k.Key).FirstOrDefault();
            }
            confidence = 0.00;
            //not supported
        }
 /// <summary>
 /// Восстановить сохранненые значения.
 /// </summary>
 public void RestoreSettings(ScaleRange range)
 {
     range.IncludeInAxisScale = IncludeInAxisScale;
 }
 public ScaleRangeSettingsWrapper(ScaleRange range) 
 {
     IncludeInAxisScale = range.IncludeInAxisScale;
 }
 internal ScaleRangeInstance(ScaleRange defObject)
     : base(defObject.GaugePanelDef)
 {
     m_defObject = defObject;
 }
Exemplo n.º 10
0
        public IPersistable CreateRIFObject(ObjectType objectType, ref IntermediateFormatReader context)
        {
            IPersistable persistable = null;

            if (objectType == ObjectType.Null)
            {
                return(null);
            }
            IDOwner    parentIDOwner    = this.m_parentIDOwner;
            ReportItem parentReportItem = this.m_parentReportItem;

            switch (objectType)
            {
            case ObjectType.PageSection:
                persistable             = new PageSection(this.m_parentReportItem);
                this.m_parentReportItem = (ReportItem)persistable;
                break;

            case ObjectType.Line:
                persistable             = new Line(this.m_parentReportItem);
                this.m_parentReportItem = (ReportItem)persistable;
                break;

            case ObjectType.Rectangle:
                persistable             = new Rectangle(this.m_parentReportItem);
                this.m_parentReportItem = (ReportItem)persistable;
                break;

            case ObjectType.Image:
                persistable             = new Image(this.m_parentReportItem);
                this.m_parentReportItem = (ReportItem)persistable;
                break;

            case ObjectType.TextBox:
                persistable             = new TextBox(this.m_parentReportItem);
                this.m_parentReportItem = (ReportItem)persistable;
                break;

            case ObjectType.SubReport:
                persistable             = new SubReport(this.m_parentReportItem);
                this.m_parentReportItem = (ReportItem)persistable;
                break;

            case ObjectType.Grouping:
                persistable = new Grouping(ConstructionPhase.Deserializing);
                break;

            case ObjectType.Sorting:
                persistable = new Sorting(ConstructionPhase.Deserializing);
                break;

            case ObjectType.ReportItemCollection:
                persistable = new ReportItemCollection();
                break;

            case ObjectType.ReportItemIndexer:
                persistable = (IPersistable)(object)default(ReportItemIndexer);
                break;

            case ObjectType.Style:
                persistable = new Style(ConstructionPhase.Deserializing);
                break;

            case ObjectType.AttributeInfo:
                persistable = new AttributeInfo();
                break;

            case ObjectType.Visibility:
                persistable = new Visibility();
                break;

            case ObjectType.ExpressionInfo:
                persistable = new ExpressionInfo();
                break;

            case ObjectType.ExpressionInfoTypeValuePair:
                persistable = new ExpressionInfoTypeValuePair();
                break;

            case ObjectType.DataAggregateInfo:
                persistable = new DataAggregateInfo();
                break;

            case ObjectType.RunningValueInfo:
                persistable = new RunningValueInfo();
                break;

            case ObjectType.Filter:
                persistable = new Filter();
                break;

            case ObjectType.DataSource:
                persistable = new DataSource();
                break;

            case ObjectType.DataSet:
                persistable = new DataSet();
                break;

            case ObjectType.ReportQuery:
                persistable = new ReportQuery();
                break;

            case ObjectType.Field:
                persistable = new Field();
                break;

            case ObjectType.ParameterValue:
                persistable = new ParameterValue();
                break;

            case ObjectType.ReportSnapshot:
                persistable = new ReportSnapshot();
                break;

            case ObjectType.DocumentMapNode:
                persistable = new DocumentMapNode();
                break;

            case ObjectType.DocumentMapBeginContainer:
                persistable = DocumentMapBeginContainer.Instance;
                break;

            case ObjectType.DocumentMapEndContainer:
                persistable = DocumentMapEndContainer.Instance;
                break;

            case ObjectType.ReportInstance:
                persistable = new ReportInstance();
                break;

            case ObjectType.ParameterInfo:
                persistable = new ParameterInfo();
                break;

            case ObjectType.ValidValue:
                persistable = new ValidValue();
                break;

            case ObjectType.ParameterDataSource:
                persistable = new ParameterDataSource();
                break;

            case ObjectType.ParameterDef:
                persistable = new ParameterDef();
                break;

            case ObjectType.ProcessingMessage:
                persistable = new ProcessingMessage();
                break;

            case ObjectType.CodeClass:
                persistable = (IPersistable)(object)default(CodeClass);
                break;

            case ObjectType.Action:
                persistable = new Action();
                break;

            case ObjectType.RenderingPagesRanges:
                persistable = (IPersistable)(object)default(RenderingPagesRanges);
                break;

            case ObjectType.IntermediateFormatVersion:
                persistable = new IntermediateFormatVersion();
                break;

            case ObjectType.ImageInfo:
                persistable = new ImageInfo();
                break;

            case ObjectType.ActionItem:
                persistable = new ActionItem();
                break;

            case ObjectType.DataValue:
                persistable = new DataValue();
                break;

            case ObjectType.CustomReportItem:
                persistable             = new CustomReportItem(this.m_parentReportItem);
                this.m_parentReportItem = (ReportItem)persistable;
                break;

            case ObjectType.SortFilterEventInfoMap:
                persistable = new SortFilterEventInfoMap();
                break;

            case ObjectType.SortFilterEventInfo:
                persistable = new SortFilterEventInfo();
                break;

            case ObjectType.EndUserSort:
                persistable = new EndUserSort();
                break;

            case ObjectType.ScopeLookupTable:
                persistable = new ScopeLookupTable();
                break;

            case ObjectType.Tablix:
                persistable             = new Tablix(this.m_parentReportItem);
                this.m_parentReportItem = (ReportItem)persistable;
                break;

            case ObjectType.TablixHeader:
                persistable = new TablixHeader();
                break;

            case ObjectType.TablixMember:
                persistable = new TablixMember();
                break;

            case ObjectType.TablixColumn:
                persistable = new TablixColumn();
                break;

            case ObjectType.TablixRow:
                persistable = new TablixRow();
                break;

            case ObjectType.TablixCornerCell:
                persistable = new TablixCornerCell();
                break;

            case ObjectType.TablixCell:
                persistable = new TablixCell();
                break;

            case ObjectType.Chart:
                persistable             = new Chart(this.m_parentReportItem);
                this.m_parentReportItem = (ReportItem)persistable;
                break;

            case ObjectType.ChartMember:
                persistable = new ChartMember();
                break;

            case ObjectType.ChartSeries:
                persistable = new ChartSeries();
                break;

            case ObjectType.ChartDataPoint:
                persistable = new ChartDataPoint();
                break;

            case ObjectType.ChartDataPointValues:
                persistable = new ChartDataPointValues();
                break;

            case ObjectType.ChartArea:
                persistable = new ChartArea();
                break;

            case ObjectType.ChartLegend:
                persistable = new ChartLegend();
                break;

            case ObjectType.ChartLegendTitle:
                persistable = new ChartLegendTitle();
                break;

            case ObjectType.ChartAxis:
                persistable = new ChartAxis();
                break;

            case ObjectType.ThreeDProperties:
                persistable = new ChartThreeDProperties();
                break;

            case ObjectType.ChartDataLabel:
                persistable = new ChartDataLabel();
                break;

            case ObjectType.ChartMarker:
                persistable = new ChartMarker();
                break;

            case ObjectType.ChartTitle:
                persistable = new ChartTitle();
                break;

            case ObjectType.ChartAxisScaleBreak:
                persistable = new ChartAxisScaleBreak();
                break;

            case ObjectType.ChartDerivedSeries:
                persistable = new ChartDerivedSeries();
                break;

            case ObjectType.ChartBorderSkin:
                persistable = new ChartBorderSkin();
                break;

            case ObjectType.ChartNoDataMessage:
                persistable = new ChartNoDataMessage();
                break;

            case ObjectType.ChartItemInLegend:
                persistable = new ChartItemInLegend();
                break;

            case ObjectType.ChartEmptyPoints:
                persistable = new ChartEmptyPoints();
                break;

            case ObjectType.ChartNoMoveDirections:
                persistable = new ChartNoMoveDirections();
                break;

            case ObjectType.ChartFormulaParameter:
                persistable = new ChartFormulaParameter();
                break;

            case ObjectType.ChartLegendColumn:
                persistable = new ChartLegendColumn();
                break;

            case ObjectType.ChartLegendColumnHeader:
                persistable = new ChartLegendColumnHeader();
                break;

            case ObjectType.ChartLegendCustomItem:
                persistable = new ChartLegendCustomItem();
                break;

            case ObjectType.ChartLegendCustomItemCell:
                persistable = new ChartLegendCustomItemCell();
                break;

            case ObjectType.ChartAlignType:
                persistable = new ChartAlignType();
                break;

            case ObjectType.ChartElementPosition:
                persistable = new ChartElementPosition();
                break;

            case ObjectType.ChartSmartLabel:
                persistable = new ChartSmartLabel();
                break;

            case ObjectType.ChartStripLine:
                persistable = new ChartStripLine();
                break;

            case ObjectType.ChartAxisTitle:
                persistable = new ChartAxisTitle();
                break;

            case ObjectType.ChartCustomPaletteColor:
                persistable = new ChartCustomPaletteColor();
                break;

            case ObjectType.GridLines:
                persistable = new ChartGridLines();
                break;

            case ObjectType.ChartTickMarks:
                persistable = new ChartTickMarks();
                break;

            case ObjectType.DataMember:
                persistable = new DataMember();
                break;

            case ObjectType.CustomDataRow:
                persistable = new CustomDataRow();
                break;

            case ObjectType.DataCell:
                persistable = new DataCell();
                break;

            case ObjectType.Variable:
                persistable = new Variable();
                break;

            case ObjectType.Page:
                persistable = new Page();
                break;

            case ObjectType.Paragraph:
                persistable = new Paragraph();
                break;

            case ObjectType.TextRun:
                persistable = new TextRun();
                break;

            case ObjectType.Report:
                persistable             = new Report(this.m_parentReportItem);
                this.m_parentReportItem = (ReportItem)persistable;
                break;

            case ObjectType.GaugePanel:
                persistable             = new GaugePanel(this.m_parentReportItem);
                this.m_parentReportItem = (ReportItem)persistable;
                break;

            case ObjectType.GaugeMember:
                persistable = new GaugeMember();
                break;

            case ObjectType.GaugeRow:
                persistable = new GaugeRow();
                break;

            case ObjectType.GaugeCell:
                persistable = new GaugeCell();
                break;

            case ObjectType.BackFrame:
                persistable = new BackFrame();
                break;

            case ObjectType.CapImage:
                persistable = new CapImage();
                break;

            case ObjectType.FrameBackground:
                persistable = new FrameBackground();
                break;

            case ObjectType.FrameImage:
                persistable = new FrameImage();
                break;

            case ObjectType.CustomLabel:
                persistable = new CustomLabel();
                break;

            case ObjectType.GaugeImage:
                persistable = new GaugeImage();
                break;

            case ObjectType.GaugeInputValue:
                persistable = new GaugeInputValue();
                break;

            case ObjectType.GaugeLabel:
                persistable = new GaugeLabel();
                break;

            case ObjectType.GaugePanelItem:
                persistable = new GaugePanelItem();
                break;

            case ObjectType.GaugeTickMarks:
                persistable = new GaugeTickMarks();
                break;

            case ObjectType.LinearGauge:
                persistable = new LinearGauge();
                break;

            case ObjectType.LinearPointer:
                persistable = new LinearPointer();
                break;

            case ObjectType.LinearScale:
                persistable = new LinearScale();
                break;

            case ObjectType.NumericIndicator:
                persistable = new NumericIndicator();
                break;

            case ObjectType.PinLabel:
                persistable = new PinLabel();
                break;

            case ObjectType.PointerCap:
                persistable = new PointerCap();
                break;

            case ObjectType.PointerImage:
                persistable = new PointerImage();
                break;

            case ObjectType.RadialGauge:
                persistable = new RadialGauge();
                break;

            case ObjectType.RadialPointer:
                persistable = new RadialPointer();
                break;

            case ObjectType.RadialScale:
                persistable = new RadialScale();
                break;

            case ObjectType.ScaleLabels:
                persistable = new ScaleLabels();
                break;

            case ObjectType.ScalePin:
                persistable = new ScalePin();
                break;

            case ObjectType.ScaleRange:
                persistable = new ScaleRange();
                break;

            case ObjectType.IndicatorImage:
                persistable = new IndicatorImage();
                break;

            case ObjectType.StateIndicator:
                persistable = new StateIndicator();
                break;

            case ObjectType.Thermometer:
                persistable = new Thermometer();
                break;

            case ObjectType.TickMarkStyle:
                persistable = new TickMarkStyle();
                break;

            case ObjectType.TopImage:
                persistable = new TopImage();
                break;

            case ObjectType.LookupInfo:
                persistable = new LookupInfo();
                break;

            case ObjectType.LookupDestinationInfo:
                persistable = new LookupDestinationInfo();
                break;

            case ObjectType.ReportSection:
                persistable = new ReportSection();
                break;

            case ObjectType.MapFieldDefinition:
                persistable = new MapFieldDefinition();
                break;

            case ObjectType.MapFieldName:
                persistable = new MapFieldName();
                break;

            case ObjectType.MapLineLayer:
                persistable = new MapLineLayer();
                break;

            case ObjectType.MapShapefile:
                persistable = new MapShapefile();
                break;

            case ObjectType.MapPolygonLayer:
                persistable = new MapPolygonLayer();
                break;

            case ObjectType.MapSpatialDataRegion:
                persistable = new MapSpatialDataRegion();
                break;

            case ObjectType.MapSpatialDataSet:
                persistable = new MapSpatialDataSet();
                break;

            case ObjectType.MapPointLayer:
                persistable = new MapPointLayer();
                break;

            case ObjectType.MapTile:
                persistable = new MapTile();
                break;

            case ObjectType.MapTileLayer:
                persistable = new MapTileLayer();
                break;

            case ObjectType.MapField:
                persistable = new MapField();
                break;

            case ObjectType.MapLine:
                persistable = new MapLine();
                break;

            case ObjectType.MapPolygon:
                persistable = new MapPolygon();
                break;

            case ObjectType.MapPoint:
                persistable = new MapPoint();
                break;

            case ObjectType.MapLineTemplate:
                persistable = new MapLineTemplate();
                break;

            case ObjectType.MapPolygonTemplate:
                persistable = new MapPolygonTemplate();
                break;

            case ObjectType.MapMarkerTemplate:
                persistable = new MapMarkerTemplate();
                break;

            case ObjectType.Map:
                persistable             = new Map(this.m_parentReportItem);
                this.m_parentReportItem = (ReportItem)persistable;
                break;

            case ObjectType.MapBorderSkin:
                persistable = new MapBorderSkin();
                break;

            case ObjectType.MapDataRegion:
                persistable = new MapDataRegion(this.m_parentReportItem);
                break;

            case ObjectType.MapMember:
                persistable = new MapMember();
                break;

            case ObjectType.MapRow:
                persistable = new MapRow();
                break;

            case ObjectType.MapCell:
                persistable = new MapCell();
                break;

            case ObjectType.MapLocation:
                persistable = new MapLocation();
                break;

            case ObjectType.MapSize:
                persistable = new MapSize();
                break;

            case ObjectType.MapGridLines:
                persistable = new MapGridLines();
                break;

            case ObjectType.MapBindingFieldPair:
                persistable = new MapBindingFieldPair();
                break;

            case ObjectType.MapCustomView:
                persistable = new MapCustomView();
                break;

            case ObjectType.MapDataBoundView:
                persistable = new MapDataBoundView();
                break;

            case ObjectType.MapElementView:
                persistable = new MapElementView();
                break;

            case ObjectType.MapViewport:
                persistable = new MapViewport();
                break;

            case ObjectType.MapLimits:
                persistable = new MapLimits();
                break;

            case ObjectType.MapColorScale:
                persistable = new MapColorScale();
                break;

            case ObjectType.MapColorScaleTitle:
                persistable = new MapColorScaleTitle();
                break;

            case ObjectType.MapDistanceScale:
                persistable = new MapDistanceScale();
                break;

            case ObjectType.MapTitle:
                persistable = new MapTitle();
                break;

            case ObjectType.MapLegend:
                persistable = new MapLegend();
                break;

            case ObjectType.MapLegendTitle:
                persistable = new MapLegendTitle();
                break;

            case ObjectType.MapBucket:
                persistable = new MapBucket();
                break;

            case ObjectType.MapColorPaletteRule:
                persistable = new MapColorPaletteRule();
                break;

            case ObjectType.MapColorRangeRule:
                persistable = new MapColorRangeRule();
                break;

            case ObjectType.MapCustomColorRule:
                persistable = new MapCustomColorRule();
                break;

            case ObjectType.MapCustomColor:
                persistable = new MapCustomColor();
                break;

            case ObjectType.MapLineRules:
                persistable = new MapLineRules();
                break;

            case ObjectType.MapPolygonRules:
                persistable = new MapPolygonRules();
                break;

            case ObjectType.MapSizeRule:
                persistable = new MapSizeRule();
                break;

            case ObjectType.MapMarkerImage:
                persistable = new MapMarkerImage();
                break;

            case ObjectType.MapMarker:
                persistable = new MapMarker();
                break;

            case ObjectType.MapMarkerRule:
                persistable = new MapMarkerRule();
                break;

            case ObjectType.MapPointRules:
                persistable = new MapPointRules();
                break;

            case ObjectType.PageBreak:
                persistable = new PageBreak();
                break;

            case ObjectType.DataScopeInfo:
                persistable = new DataScopeInfo();
                break;

            case ObjectType.LinearJoinInfo:
                persistable = new LinearJoinInfo();
                break;

            case ObjectType.IntersectJoinInfo:
                persistable = new IntersectJoinInfo();
                break;

            case ObjectType.BucketedDataAggregateInfos:
                persistable = new BucketedDataAggregateInfos();
                break;

            case ObjectType.DataAggregateInfoBucket:
                persistable = new DataAggregateInfoBucket();
                break;

            case ObjectType.NumericIndicatorRange:
                persistable = new NumericIndicatorRange();
                break;

            case ObjectType.IndicatorState:
                persistable = new IndicatorState();
                break;

            case ObjectType.SharedDataSetQuery:
                persistable = new SharedDataSetQuery();
                break;

            case ObjectType.DataSetCore:
                persistable = new DataSetCore();
                break;

            case ObjectType.DataSetParameterValue:
                persistable = new DataSetParameterValue();
                break;

            case ObjectType.RIFVariantContainer:
                persistable = new RIFVariantContainer();
                break;

            case ObjectType.IdcRelationship:
                persistable = new IdcRelationship();
                break;

            case ObjectType.DefaultRelationship:
                persistable = new DefaultRelationship();
                break;

            case ObjectType.JoinCondition:
                persistable = new Relationship.JoinCondition();
                break;

            case ObjectType.BandLayoutOptions:
                persistable = new BandLayoutOptions();
                break;

            case ObjectType.LabelData:
                persistable = new LabelData();
                break;

            case ObjectType.Slider:
                persistable = new Slider();
                break;

            case ObjectType.Coverflow:
                persistable = new Coverflow();
                break;

            case ObjectType.PlayAxis:
                persistable = new PlayAxis();
                break;

            case ObjectType.BandNavigationCell:
                persistable = new BandNavigationCell();
                break;

            case ObjectType.Tabstrip:
                persistable = new Tabstrip();
                break;

            case ObjectType.NavigationItem:
                persistable = new NavigationItem();
                break;

            case ObjectType.ScopedFieldInfo:
                persistable = new ScopedFieldInfo();
                break;

            default:
                Global.Tracer.Assert(false, "Unsupported object type: " + objectType.ToString());
                break;
            }
            IDOwner iDOwner = persistable as IDOwner;

            if (iDOwner != null)
            {
                iDOwner.ParentInstancePath = this.m_parentIDOwner;
                this.m_parentIDOwner       = iDOwner;
            }
            persistable.Deserialize(context);
            this.m_parentIDOwner    = parentIDOwner;
            this.m_parentReportItem = parentReportItem;
            return(persistable);
        }
        public MapGuideLayer(ServerConnectionI con, string layername)
        {
            m_con = con;

            m_layerDef = m_con.GetLayerDefinition(layername);
            if (!(m_layerDef.Item is VectorLayerDefinitionType))
                throw new Exception("The resource " + layername + " is not a vector layer");

            VectorLayerDefinitionType vldef = m_layerDef.Item as VectorLayerDefinitionType;

            m_columnnames = new Dictionary<string, string>();

            m_columnnames[vldef.Geometry] = null;

            ExtractColumnNames(vldef.Url, m_columnnames);
            ExtractColumnNames(vldef.ToolTip, m_columnnames);

            try
            {
                FeatureSource fs = m_con.GetFeatureSource(vldef.ResourceId);
                FdoSpatialContextList lst = fs.GetSpatialInfo();
                if (lst != null && lst.SpatialContext != null && lst.SpatialContext.Count > 0)
                {
                    Topology.CoordinateSystems.CoordinateSystemFactory cf = new Topology.CoordinateSystems.CoordinateSystemFactory();
                    m_coordSys = cf.CreateFromWkt(lst.SpatialContext[0].CoordinateSystemWkt);
                }
            }
            catch
            {
            }

            foreach (VectorScaleRangeType vsr in vldef.VectorScaleRange)
            {
                ScaleRange sr = new ScaleRange(vsr.MinScaleSpecified ? vsr.MinScale : 0, vsr.MaxScaleSpecified ? vsr.MaxScale : double.MaxValue);

                foreach (object style in vsr.Items)
                    if (style is PointTypeStyleType)
                    {
                        if (((PointTypeStyleType)style).PointRule != null)
                            foreach (PointRuleType rule in ((PointTypeStyleType)style).PointRule)
                            {
                                if (rule.Item != null && rule.Item.Item != null)
                                {
                                    OperationOrParameter op = ExtractColumnNames(rule.Filter, m_columnnames);
                                    if (rule.Label != null)
                                        ExtractColumnNames(rule.Label.Text, m_columnnames);

                                    LittleSharpRenderEngine.Style.Point p = new LittleSharpRenderEngine.Style.Point();
                                    p.Center = new System.Drawing.Point(
                                        (int)(rule.Item.Item.InsertionPointXSpecified ? rule.Item.Item.InsertionPointX : 0.5),
                                        (int)(rule.Item.Item.InsertionPointYSpecified ? rule.Item.Item.InsertionPointY : 0.5));

                                    p.Rotation = double.Parse(rule.Item.Item.Rotation, System.Globalization.CultureInfo.InvariantCulture);
                                    p.Size = new System.Drawing.Size(
                                        (int)double.Parse(rule.Item.Item.SizeX, System.Globalization.CultureInfo.InvariantCulture),
                                        (int)double.Parse(rule.Item.Item.SizeY, System.Globalization.CultureInfo.InvariantCulture));

                                    if (rule.Item.Item is MarkSymbolType)
                                    {
                                        MarkSymbolType mark = rule.Item.Item as MarkSymbolType;
                                        switch (mark.Shape)
                                        {
                                            case ShapeType.Circle:
                                                p.Type = LittleSharpRenderEngine.Style.Point.PointType.Circle;
                                                break;
                                            case ShapeType.Square:
                                                p.Type = LittleSharpRenderEngine.Style.Point.PointType.Square;
                                                break;
                                            case ShapeType.Triangle:
                                                p.Type = LittleSharpRenderEngine.Style.Point.PointType.Triangle;
                                                break;
                                            default:
                                                p.Type = LittleSharpRenderEngine.Style.Point.PointType.Circle;
                                                break;
                                        }

                                        if (mark.Fill != null)
                                        {
                                            p.Fill = new LittleSharpRenderEngine.Style.Base.Fill();
                                            p.Fill.BackgroundColor = mark.Fill.BackgroundColor;
                                            p.Fill.ForegroundColor = mark.Fill.ForegroundColor;
                                            //p.Fill.Pattern = mark.Fill.FillPattern;
                                            //TODO: Deal with unit/sizecontext
                                        }

                                        if (mark.Edge != null)
                                        {
                                            p.Outline = new LittleSharpRenderEngine.Style.Base.Outline();
                                            p.Outline.ForegroundColor = mark.Edge.Color;
                                            //p.Outline.DashStyle = mark.Edge.LineStyle;
                                            //p.Outline.Pattern = mark.Edge.LineStyle;
                                            p.Outline.Width = (int)double.Parse(mark.Edge.Thickness, System.Globalization.CultureInfo.InvariantCulture);
                                            //TODO: Deal with unit/sizecontext
                                        }
                                    }
                                    else
                                    {
                                        p.Type = LittleSharpRenderEngine.Style.Point.PointType.Circle;
                                        p.Outline = new LittleSharpRenderEngine.Style.Base.Outline();
                                        p.Fill = new LittleSharpRenderEngine.Style.Base.Fill();
                                        p.Fill.BackgroundColor = System.Drawing.Color.Red;
                                        p.Fill.ForegroundColor = System.Drawing.Color.Black;

                                        p.Outline.ForegroundColor = System.Drawing.Color.Black;
                                    }

                                    sr.PointRules.Add(new KeyValuePair<OperationOrParameter, IPointStyle>(op, p));
                                }
                            }
                    }
                    else if (style is LineTypeStyleType)
                    {
                        if (((LineTypeStyleType)style).LineRule != null)
                            foreach (LineRuleType rule in ((LineTypeStyleType)style).LineRule)
                            {
                                if (rule.Items != null && rule.Items.Count > 0)
                                {
                                    List<IOutline> lines = new List<IOutline>();
                                    OperationOrParameter op = ExtractColumnNames(rule.Filter, m_columnnames);
                                    if (rule.Label != null)
                                        ExtractColumnNames(rule.Label.Text, m_columnnames);

                                    foreach (StrokeType st in rule.Items)
                                    {
                                        LittleSharpRenderEngine.Style.Base.Outline outline = new LittleSharpRenderEngine.Style.Base.Outline();
                                        outline.ForegroundColor = st.Color;
                                        outline.Width = (int)double.Parse(st.Thickness, System.Globalization.CultureInfo.InvariantCulture);
                                        //outline.Pattern = st.LineStyle;
                                        //outline.DashStyle = st.LineStyle;
                                        //TODO: Deal with unit/sizecontext

                                        lines.Add(outline);
                                    }

                                    sr.LineRules.Add(new KeyValuePair<OperationOrParameter, ILineStyle>(op, new LittleSharpRenderEngine.Style.Line(lines)));
                                }

                            }
                    }
                    else if (style is AreaTypeStyleType)
                    {
                        if (((AreaTypeStyleType)style).AreaRule != null)
                            foreach (AreaRuleType rule in ((AreaTypeStyleType)style).AreaRule)
                            {
                                OperationOrParameter op = ExtractColumnNames(rule.Filter, m_columnnames);
                                if (rule.Label != null)
                                    ExtractColumnNames(rule.Label.Text, m_columnnames);

                                LittleSharpRenderEngine.Style.Area a = new Area();
                                if (rule.Item != null)
                                {
                                    if (rule.Item.Fill != null)
                                    {
                                        a.Fill = new LittleSharpRenderEngine.Style.Base.Fill();
                                        a.Fill.BackgroundColor = rule.Item.Fill.BackgroundColor;
                                        a.Fill.ForegroundColor = rule.Item.Fill.ForegroundColor;
                                        //p.Fill.Pattern = rule.Item.Fill.FillPattern;
                                        //TODO: Deal with unit/sizecontext
                                    }

                                    if (rule.Item.Stroke != null)
                                    {
                                        a.Outline = new LittleSharpRenderEngine.Style.Base.Outline();
                                        a.Outline.ForegroundColor = rule.Item.Stroke.Color;
                                        //p.Outline.DashStyle = rule.Item.Stroke.LineStyle;
                                        //p.Outline.Pattern = rule.Item.Stroke.LineStyle;
                                        a.Outline.Width = (int)double.Parse(rule.Item.Stroke.Thickness, System.Globalization.CultureInfo.InvariantCulture);
                                        //TODO: Deal with unit/sizecontext
                                    }

                                    sr.AreaRules.Add(new KeyValuePair<OperationOrParameter, IAreaStyle>(op, a));
                                }
                            }
                    }

                if (sr.PointRules.Count + sr.LineRules.Count + sr.AreaRules.Count > 0)
                    m_scaleRanges.Add(sr);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Восстановить сохранненые значения.
        /// </summary>
        public void RestoreSettings(Axis axis)
        {
            AlternateGridBackground.RestoreSettings(axis.AlternateGridBackground);
            axis.CenterTickMarks = CenterTickMarks;
            axis.ClearValues = ClearValues;
            axis.ClusterColumns = ClusterColumns;
            axis.CombinedElementsCalculation = CombinedElementsCalculation;
            axis.CultureName = CultureName;
            DefaultTick.RestoreSettings(axis.DefaultTick);
            
            axis.ExtraTicks.Clear();
            for (int i = 0; i < ExtraTicks.Length; i++)
            {
                AxisTick tick =new AxisTick();
                ExtraTicks[i].RestoreSettings(tick);
                axis.ExtraTicks.Add(tick);
            }
            axis.FormatString = FormatString;
            axis.GaugeLabelMode = GaugeLabelMode;
            axis.GaugeNeedleType = GaugeNeedleType;
            axis.GenerateElementTicks = GenerateElementTicks;
            axis.Interval = Interval;
            axis.InvertScale = InvertScale;
            Label.RestoreSettings(axis.Label);
            axis.LabelRotate = LabelRotate;
            Line.RestoreSettings(axis.Line);
            axis.LogarithmicBase = LogarithmicBase;
            Maximum = axis.Maximum;
            axis.Minimum = Minimum;
            axis.MinimumInterval = MinimumInterval;
            axis.MinorInterval = MinorInterval;
            axis.MinorTicksPerInterval = MinorTicksPerInterval;
            MinorTimeIntervalAdvanced.RestoreSettings(axis.MinorTimeIntervalAdvanced);
            axis.Name = Name;
            axis.NumberPercision = NumberPercision;
            axis.NumberPrecision = NumberPrecision;
            axis.Orientation = Orientation;
            axis.OrientationAngle = OrientationAngle;
            axis.OverlappingCircularLabelSeparator = OverlappingCircularLabelSeparator;
            axis.Percent = Percent;
            axis.Position = Position;
            axis.RadarMode = RadarMode;
            axis.RangeAngle = RangeAngle;
            axis.ReverseSeries = ReverseSeries;
            axis.ReverseSeriesPositions = ReverseSeriesPositions;
            axis.ReverseStack = ReverseStack;
            axis.Scale = Scale;

            axis.ScaleBreaks.Clear();
            for (int i = 0; i < ScaleBreaks.Length; i++)
            {
                ScaleRange range=new ScaleRange();
                ScaleBreaks[i].RestoreSettings(range);
                axis.ScaleBreaks.Add(range);
            }

            axis.ScaleBreakStyle = ScaleBreakStyle;
            ScaleRange.RestoreSettings(axis.ScaleRange);
            axis.ShowGrid = ShowGrid;
            axis.SmartMinorTicks = SmartMinorTicks;
            axis.SmartScaleBreak = SmartScaleBreak;
            axis.SmartScaleBreakLimit = SmartScaleBreakLimit;
            axis.SpacingPercentage = SpacingPercentage;
            axis.StaticColumnWidth = StaticColumnWidth;
            axis.SweepAngle = SweepAngle;
            axis.TickLabelAngle = TickLabelAngle;
            axis.TickLabelMode = TickLabelMode;
            axis.TickLabelPadding = TickLabelPadding;
            TickLabelSeparatorLine.RestoreSettings(axis.TickLabelSeparatorLine);
            TickLine.RestoreSettings(axis.TickLine);
            axis.TickNumberMaximum = TickNumberMaximum;
            axis.TimeInterval = (TimeInterval)TimeInterval;
            TimeIntervalAdvanced.RestoreSettings(axis.TimeIntervalAdvanced);
            axis.TimePadding = TimePadding;
            TimeScaleLabels.RestoreSettings(axis.TimeScaleLabels);
            ZeroLine.RestoreSettings(axis.ZeroLine);
            ZeroTick.RestoreSettings(axis.ZeroTick);   

        }
Exemplo n.º 13
0
 public ScaleRangeInstance(ScaleRange defObject)
     : base(defObject.GaugePanelDef)
 {
     this.m_defObject = defObject;
 }
Exemplo n.º 14
0
        public MapGuideLayer(ServerConnectionI con, string layername)
        {
            m_con = con;

            m_layerDef = m_con.GetLayerDefinition(layername);
            if (!(m_layerDef.Item is VectorLayerDefinitionType))
            {
                throw new Exception("The resource " + layername + " is not a vector layer");
            }

            VectorLayerDefinitionType vldef = m_layerDef.Item as VectorLayerDefinitionType;

            m_columnnames = new Dictionary <string, string>();

            m_columnnames[vldef.Geometry] = null;

            ExtractColumnNames(vldef.Url, m_columnnames);
            ExtractColumnNames(vldef.ToolTip, m_columnnames);

            try
            {
                FeatureSource         fs  = m_con.GetFeatureSource(vldef.ResourceId);
                FdoSpatialContextList lst = fs.GetSpatialInfo();
                if (lst != null && lst.SpatialContext != null && lst.SpatialContext.Count > 0)
                {
                    Topology.CoordinateSystems.CoordinateSystemFactory cf = new Topology.CoordinateSystems.CoordinateSystemFactory();
                    m_coordSys = cf.CreateFromWkt(lst.SpatialContext[0].CoordinateSystemWkt);
                }
            }
            catch
            {
            }

            foreach (VectorScaleRangeType vsr in vldef.VectorScaleRange)
            {
                ScaleRange sr = new ScaleRange(vsr.MinScaleSpecified ? vsr.MinScale : 0, vsr.MaxScaleSpecified ? vsr.MaxScale : double.MaxValue);

                foreach (object style in vsr.Items)
                {
                    if (style is PointTypeStyleType)
                    {
                        if (((PointTypeStyleType)style).PointRule != null)
                        {
                            foreach (PointRuleType rule in ((PointTypeStyleType)style).PointRule)
                            {
                                if (rule.Item != null && rule.Item.Item != null)
                                {
                                    OperationOrParameter op = ExtractColumnNames(rule.Filter, m_columnnames);
                                    if (rule.Label != null)
                                    {
                                        ExtractColumnNames(rule.Label.Text, m_columnnames);
                                    }

                                    LittleSharpRenderEngine.Style.Point p = new LittleSharpRenderEngine.Style.Point();
                                    p.Center = new System.Drawing.Point(
                                        (int)(rule.Item.Item.InsertionPointXSpecified ? rule.Item.Item.InsertionPointX : 0.5),
                                        (int)(rule.Item.Item.InsertionPointYSpecified ? rule.Item.Item.InsertionPointY : 0.5));

                                    p.Rotation = double.Parse(rule.Item.Item.Rotation, System.Globalization.CultureInfo.InvariantCulture);
                                    p.Size     = new System.Drawing.Size(
                                        (int)double.Parse(rule.Item.Item.SizeX, System.Globalization.CultureInfo.InvariantCulture),
                                        (int)double.Parse(rule.Item.Item.SizeY, System.Globalization.CultureInfo.InvariantCulture));

                                    if (rule.Item.Item is MarkSymbolType)
                                    {
                                        MarkSymbolType mark = rule.Item.Item as MarkSymbolType;
                                        switch (mark.Shape)
                                        {
                                        case ShapeType.Circle:
                                            p.Type = LittleSharpRenderEngine.Style.Point.PointType.Circle;
                                            break;

                                        case ShapeType.Square:
                                            p.Type = LittleSharpRenderEngine.Style.Point.PointType.Square;
                                            break;

                                        case ShapeType.Triangle:
                                            p.Type = LittleSharpRenderEngine.Style.Point.PointType.Triangle;
                                            break;

                                        default:
                                            p.Type = LittleSharpRenderEngine.Style.Point.PointType.Circle;
                                            break;
                                        }

                                        if (mark.Fill != null)
                                        {
                                            p.Fill = new LittleSharpRenderEngine.Style.Base.Fill();
                                            p.Fill.BackgroundColor = mark.Fill.BackgroundColor;
                                            p.Fill.ForegroundColor = mark.Fill.ForegroundColor;
                                            //p.Fill.Pattern = mark.Fill.FillPattern;
                                            //TODO: Deal with unit/sizecontext
                                        }

                                        if (mark.Edge != null)
                                        {
                                            p.Outline = new LittleSharpRenderEngine.Style.Base.Outline();
                                            p.Outline.ForegroundColor = mark.Edge.Color;
                                            //p.Outline.DashStyle = mark.Edge.LineStyle;
                                            //p.Outline.Pattern = mark.Edge.LineStyle;
                                            p.Outline.Width = (int)double.Parse(mark.Edge.Thickness, System.Globalization.CultureInfo.InvariantCulture);
                                            //TODO: Deal with unit/sizecontext
                                        }
                                    }
                                    else
                                    {
                                        p.Type    = LittleSharpRenderEngine.Style.Point.PointType.Circle;
                                        p.Outline = new LittleSharpRenderEngine.Style.Base.Outline();
                                        p.Fill    = new LittleSharpRenderEngine.Style.Base.Fill();
                                        p.Fill.BackgroundColor = System.Drawing.Color.Red;
                                        p.Fill.ForegroundColor = System.Drawing.Color.Black;

                                        p.Outline.ForegroundColor = System.Drawing.Color.Black;
                                    }

                                    sr.PointRules.Add(new KeyValuePair <OperationOrParameter, IPointStyle>(op, p));
                                }
                            }
                        }
                    }
                    else if (style is LineTypeStyleType)
                    {
                        if (((LineTypeStyleType)style).LineRule != null)
                        {
                            foreach (LineRuleType rule in ((LineTypeStyleType)style).LineRule)
                            {
                                if (rule.Items != null && rule.Items.Count > 0)
                                {
                                    List <IOutline>      lines = new List <IOutline>();
                                    OperationOrParameter op    = ExtractColumnNames(rule.Filter, m_columnnames);
                                    if (rule.Label != null)
                                    {
                                        ExtractColumnNames(rule.Label.Text, m_columnnames);
                                    }

                                    foreach (StrokeType st in rule.Items)
                                    {
                                        LittleSharpRenderEngine.Style.Base.Outline outline = new LittleSharpRenderEngine.Style.Base.Outline();
                                        outline.ForegroundColor = st.Color;
                                        outline.Width           = (int)double.Parse(st.Thickness, System.Globalization.CultureInfo.InvariantCulture);
                                        //outline.Pattern = st.LineStyle;
                                        //outline.DashStyle = st.LineStyle;
                                        //TODO: Deal with unit/sizecontext

                                        lines.Add(outline);
                                    }

                                    sr.LineRules.Add(new KeyValuePair <OperationOrParameter, ILineStyle>(op, new LittleSharpRenderEngine.Style.Line(lines)));
                                }
                            }
                        }
                    }
                    else if (style is AreaTypeStyleType)
                    {
                        if (((AreaTypeStyleType)style).AreaRule != null)
                        {
                            foreach (AreaRuleType rule in ((AreaTypeStyleType)style).AreaRule)
                            {
                                OperationOrParameter op = ExtractColumnNames(rule.Filter, m_columnnames);
                                if (rule.Label != null)
                                {
                                    ExtractColumnNames(rule.Label.Text, m_columnnames);
                                }

                                LittleSharpRenderEngine.Style.Area a = new Area();
                                if (rule.Item != null)
                                {
                                    if (rule.Item.Fill != null)
                                    {
                                        a.Fill = new LittleSharpRenderEngine.Style.Base.Fill();
                                        a.Fill.BackgroundColor = rule.Item.Fill.BackgroundColor;
                                        a.Fill.ForegroundColor = rule.Item.Fill.ForegroundColor;
                                        //p.Fill.Pattern = rule.Item.Fill.FillPattern;
                                        //TODO: Deal with unit/sizecontext
                                    }

                                    if (rule.Item.Stroke != null)
                                    {
                                        a.Outline = new LittleSharpRenderEngine.Style.Base.Outline();
                                        a.Outline.ForegroundColor = rule.Item.Stroke.Color;
                                        //p.Outline.DashStyle = rule.Item.Stroke.LineStyle;
                                        //p.Outline.Pattern = rule.Item.Stroke.LineStyle;
                                        a.Outline.Width = (int)double.Parse(rule.Item.Stroke.Thickness, System.Globalization.CultureInfo.InvariantCulture);
                                        //TODO: Deal with unit/sizecontext
                                    }

                                    sr.AreaRules.Add(new KeyValuePair <OperationOrParameter, IAreaStyle>(op, a));
                                }
                            }
                        }
                    }
                }

                if (sr.PointRules.Count + sr.LineRules.Count + sr.AreaRules.Count > 0)
                {
                    m_scaleRanges.Add(sr);
                }
            }
        }
Exemplo n.º 15
0
        public IEnumerable <IFeature> GetFeatures(IEnvelope bbox, string filter, double scale)
        {
            ScaleRange sr = null;

            foreach (ScaleRange sx in m_scaleRanges)
            {
                if (scale >= sx.Min && scale < sx.Max)
                {
                    sr = sx;
                    break;
                }
            }

            //Hack to test renderings speed in the test application
            if (sr == null && double.IsNaN(scale) && m_scaleRanges.Count > 0)
            {
                sr = m_scaleRanges[0];
            }

            if (sr == null)
            {
                return(new List <IFeature>());
            }

            if (m_featureCache == null)
            {
                VectorLayerDefinitionType vldef = m_layerDef.Item as VectorLayerDefinitionType;

                string        local_filter = ""; //TODO: Apply filter, from layer and passed in
                List <string> columns      = new List <string>(m_columnnames.Keys);

                List <IFeature> cache = new List <IFeature>();

                try
                {
                    using (FeatureSetReader fsr = m_layerDef.CurrentConnection.QueryFeatureSource(vldef.ResourceId, vldef.FeatureName, local_filter, columns.ToArray()))
                        while (fsr.Read())
                        {
                            IGeometry geom = fsr.Row[vldef.Geometry] as IGeometry;

                            if (geom == null)
                            {
                                continue;
                            }

                            //TODO: Evaluate rules and pick the correct one
                            if ((geom is IPoint || geom is IMultiPoint) && sr.PointRules.Count > 0)
                            {
                                cache.Add(new FeatureImpl(geom, sr.PointRules[0].Value));
                            }
                            else if ((geom is ILineString || geom is IMultiLineString) && sr.LineRules.Count > 0)
                            {
                                cache.Add(new FeatureImpl(geom, sr.LineRules[0].Value));
                            }
                            else if ((geom is IPolygon || geom is IMultiPolygon) && sr.AreaRules.Count > 0)
                            {
                                cache.Add(new FeatureImpl(geom, sr.AreaRules[0].Value));
                            }
                        }
                }
                catch
                {
                    cache = new List <IFeature>();
                }

                m_featureCache = cache;
            }

            return(m_featureCache);
        }