Esempio n. 1
0
        // Render the given course id (0 = all controls) and kind to a bitmap, and compare it to the saved version.
        internal void CheckRenderBitmap(string filename, Id <Course> id, DescriptionKind kind, int numColumns = 1)
        {
            SymbolDB   symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            UndoMgr    undomgr  = new UndoMgr(5);
            EventDB    eventDB  = new EventDB(undomgr);
            CourseView courseView;

            eventDB.Load(filename);
            eventDB.Validate();

            courseView = CourseView.CreateViewingCourseView(eventDB, DesignatorFromCourseId(eventDB, id));

            DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting);

            DescriptionLine[] description = descFormatter.CreateDescription(kind == DescriptionKind.Symbols);

            Bitmap bmNew = DescriptionBrowser.RenderToBitmap(symbolDB, description, kind, numColumns);

            if (numColumns > 1)
            {
                TestUtil.CheckBitmapsBase(bmNew, DescriptionBrowser.GetBitmapFileName(eventDB, id, "_" + numColumns + "col", kind));
            }
            else
            {
                TestUtil.CheckBitmapsBase(bmNew, DescriptionBrowser.GetBitmapFileName(eventDB, id, "", kind));
            }
        }
Esempio n. 2
0
        // Render the given course id (0 = all controls) and kind to a map, and compare it to the saved version.
        internal void CheckRenderMapStandardChange(string filename, Id <Course> id, DescriptionKind kind, string newDescStandard)
        {
            SymbolDB   symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            UndoMgr    undomgr  = new UndoMgr(5);
            EventDB    eventDB  = new EventDB(undomgr);
            CourseView courseView;

            eventDB.Load(filename);
            symbolDB.Standard = eventDB.GetEvent().descriptionStandard;
            eventDB.Validate();

            courseView = CourseView.CreateViewingCourseView(eventDB, DesignatorFromCourseId(eventDB, id));

            DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting);

            DescriptionLine[] description = descFormatter.CreateDescription(kind == DescriptionKind.Symbols);

            Bitmap bmNew = RenderToMapThenToBitmap(symbolDB, description, kind, 1);

            TestUtil.CheckBitmapsBase(bmNew, DescriptionBrowser.GetBitmapFileName(eventDB, id, "_std_default", kind));

            undomgr.BeginCommand(71231, "change standard");
            symbolDB.Standard = newDescStandard;
            ChangeEvent.UpdateDescriptionToMatchStandard(eventDB, symbolDB);
            undomgr.EndCommand(71231);
            description = descFormatter.CreateDescription(kind == DescriptionKind.Symbols);

            bmNew = RenderToMapThenToBitmap(symbolDB, description, kind, 1);
            TestUtil.CheckBitmapsBase(bmNew, DescriptionBrowser.GetBitmapFileName(eventDB, id, "_std_" + newDescStandard, kind));
        }
Esempio n. 3
0
        public Project GetItem(int id, DescriptionKind isExtended, params string[] includedProperties)
        {
            var projectEntity  = projectRepository.GetItem(id, includedProperties);
            var elasticProject = elastic.GetProjectById(id, isExtended);

            return(GetMergeProject(projectEntity, elasticProject));
        }
Esempio n. 4
0
 public AddDescriptionMode(Controller controller, UndoMgr undoMgr, SelectionMgr selectionMgr, EventDB eventDB, SymbolDB symbolDB, CourseDesignator courseDesignator, DescriptionLine[] description, DescriptionKind kind)
 {
     this.controller = controller;
     this.undoMgr = undoMgr;
     this.selectionMgr = selectionMgr;
     this.symbolDB = symbolDB;
     this.eventDB = eventDB;
     this.courseDesignator = courseDesignator;
     this.description = description;
     this.kind = kind;
 }
Esempio n. 5
0
 public static void WriteDescriptionKindAttribute(System.Xml.XmlTextWriter xmloutput, DescriptionKind descKind)
 {
     string descKindText;
     switch (descKind) {
         case DescriptionKind.Symbols:           descKindText = "symbols"; break;
         case DescriptionKind.Text:              descKindText = "text"; break;
         case DescriptionKind.SymbolsAndText:    descKindText = "symbols-and-text"; break;
         default:                                Debug.Fail("bad desc kind"); descKindText = "none"; break;
     }
     xmloutput.WriteAttributeString("description-kind", descKindText);
 }
Esempio n. 6
0
 public AddDescriptionMode(Controller controller, UndoMgr undoMgr, SelectionMgr selectionMgr, EventDB eventDB, SymbolDB symbolDB, CourseDesignator courseDesignator, DescriptionLine[] description, DescriptionKind kind)
 {
     this.controller       = controller;
     this.undoMgr          = undoMgr;
     this.selectionMgr     = selectionMgr;
     this.symbolDB         = symbolDB;
     this.eventDB          = eventDB;
     this.courseDesignator = courseDesignator;
     this.description      = description;
     this.kind             = kind;
 }
Esempio n. 7
0
        public IEnumerable <Project> GetItemsList(DescriptionKind isExtended)
        {
            var projectEntities = projectRepository.GetItemsList();
            var elasticProjects = GetElasticProjects(projectEntities, isExtended);

            var e1 = projectEntities.GetEnumerator();
            var e2 = elasticProjects.GetEnumerator();

            while (e1.MoveNext() && e2.MoveNext())
            {
                yield return(GetMergeProject(e1.Current, e2.Current));
            }
        }
Esempio n. 8
0
        public IEnumerable <Project> Search(string request, Paging paging, DescriptionKind isExtended)
        {
            var elasticProjects = elastic.SearchItemsProject(request, paging, isExtended);
            var projectEntities = GetEntityProjects(elasticProjects);

            var e1 = projectEntities.GetEnumerator();
            var e2 = elasticProjects.GetEnumerator();

            while (e1.MoveNext() && e2.MoveNext())
            {
                yield return(GetMergeProject(e1.Current, e2.Current));
            }
        }
Esempio n. 9
0
        // Get a description renderer for rendering the description from a course view.
        private DescriptionRenderer GetRenderer(CourseView courseView)
        {
            DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting);
            DescriptionKind      descKind      = GetDescriptionKind(courseView);

            DescriptionLine[]   description = descFormatter.CreateDescription(descKind == DescriptionKind.Symbols);
            DescriptionRenderer renderer    = new DescriptionRenderer(symbolDB);

            renderer.CellSize        = descPrintSettings.BoxSize / 0.254F;
            renderer.Description     = description;
            renderer.DescriptionKind = descKind;
            renderer.Margin          = 0;

            return(renderer);
        }
Esempio n. 10
0
        public ElasticProjectData(ElasticProjectData data, DescriptionKind isExtended)
        {
            Id            = data.Id;
            Name          = data.Name;
            ExternalDescr = data.ExternalDescr;

            if (isExtended == DescriptionKind.Internal)
            {
                InternalDescr = data.InternalDescr;
            }
            else
            {
                InternalDescr = "Internal description is not available";
            }
        }
Esempio n. 11
0
        // Get the file name for a bitmap description for testing purposes. CourseID == 0 means all controls. Extra
        // is an extra string to suffix to the base name. Does not end in .png unless specified in extra.
        public static string GetBitmapFileName(EventDB eventDB, Id<Course> courseId, string extra, DescriptionKind kind)
        {
            Course course = null;
            string name;

            if (courseId.IsNotNone)
                course = eventDB.GetCourse(courseId);

            if (course != null)
                name = course.name;
            else
                name = "Allcontrols";

            name = "descriptions\\" + name + "_" + kind.ToString() + extra;

            return name;
        }
Esempio n. 12
0
        // Render the given course id (0 = all controls) and kind to a bitmap, and compare it to the saved version.
        internal void CheckRenderBitmapPixelAtATime(Id <Course> id, DescriptionKind kind)
        {
            SymbolDB   symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            UndoMgr    undomgr  = new UndoMgr(5);
            EventDB    eventDB  = new EventDB(undomgr);
            CourseView courseView;

            eventDB.Load(TestUtil.GetTestFile("descriptions\\sampleevent1.coursescribe"));
            eventDB.Validate();

            courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(id));

            DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting);

            DescriptionLine[] description = descFormatter.CreateDescription(false);

            Bitmap bmNew = RenderToBitmapPixelAtATime(symbolDB, description, kind);

            TestUtil.CheckBitmapsBase(bmNew, DescriptionBrowser.GetBitmapFileName(eventDB, id, "", kind));
        }
Esempio n. 13
0
        public ElasticProjectData GetProjectById(int _Id, DescriptionKind isExtended) //works!
        {
            var searchResponse1 = clientProject.Search <ElasticProjectData>(s => s
                                                                            .Query(q => q
                                                                                   .Match(m => m
                                                                                          .Field(f => f.Id).Query(_Id.ToString())
                                                                                          )
                                                                                   )
                                                                            );

            if (searchResponse1.Hits.Count > 1)
            {
                throw new Exception("ElasticSearch: Many projects with same id found: " + _Id);
            }
            else if (searchResponse1.Hits.Count == 0)
            {
                return(ElasticProjectData.NotFound);
            }
            return(new ElasticProjectData(searchResponse1.Hits.First().Source, isExtended));
        }
Esempio n. 14
0
        public override void ReadAttributesAndContent(XmlInput xmlinput)
        {
            string kindText = xmlinput.GetAttributeString("kind");
            switch (kindText) {
                case "normal":      kind = CourseKind.Normal; break;
                case "score":       kind = CourseKind.Score; break;
                default:            xmlinput.BadXml("Invalid course kind '{0}'", kindText); break;
            }

            sortOrder = xmlinput.GetAttributeInt("order", 0);    // 0 sort orders fixed up later in EventDB.FixCourseSortOrders()

            name = "";
            printScale = 15000;
            descKind = DescriptionKind.Symbols;
            firstCourseControl = Id<CourseControl>.None;
            firstControlOrdinal = 1;
            labelKind = (kind == CourseKind.Score) ? ControlLabelKind.Code : ControlLabelKind.Sequence;
            scoreColumn = (kind == CourseKind.Score) ? 0 : -1;

            bool first = true;
            while (xmlinput.FindSubElement(first, "name", "secondary-title", "first", "print-area", "options", "labels", "part-options", "relay")) {
                switch (xmlinput.Name) {
                    case "name":
                        name = xmlinput.GetContentString();
                        break;

                    case "secondary-title":
                        secondaryTitle = xmlinput.GetContentString();
                        break;

                    case "first":
                        firstCourseControl = new Id<CourseControl>(xmlinput.GetAttributeInt("course-control"));
                        firstControlOrdinal = xmlinput.GetAttributeInt("control-number", 1);
                        xmlinput.Skip();
                        break;

                    case "print-area":
                        PrintArea area = new PrintArea();
                        int part = xmlinput.GetAttributeInt("part", -1);
                        area.ReadAttributesAndContent(xmlinput);

                        if (part == -1)
                            printArea = area;
                        else
                            partPrintAreas[part] = area;

                        break;

                    case "options":
                        printScale = xmlinput.GetAttributeFloat("print-scale");
                        climb = xmlinput.GetAttributeFloat("climb", -1F);
                        load = xmlinput.GetAttributeInt("load", -1);
                        if (kind == CourseKind.Score) 
                            scoreColumn = EventDBUtil.ReadScoreColumnAttribute(xmlinput);
                        descKind = EventDBUtil.ReadDescriptionKindAttribute(xmlinput);

                        float len = xmlinput.GetAttributeFloat("course-length", -1F);
                        if (len > 0)
                            overrideCourseLength = len;
                        else
                            overrideCourseLength = null;

                        xmlinput.Skip();
                        break;

                    case "part-options":
                        part = xmlinput.GetAttributeInt("part", -1);
                        bool showFinish = xmlinput.GetAttributeBool("show-finish");

                        if (part != -1)
                            partOptions[part] = new PartOptions() { ShowFinish = showFinish };

                        xmlinput.Skip();
                        break;


                    case "labels":
                        string labelKindText = xmlinput.GetAttributeString("label-kind");
                        switch (labelKindText) {
                            case "sequence":                labelKind = ControlLabelKind.Sequence; break;
                            case "code":                    labelKind = ControlLabelKind.Code; break;
                            case "sequence-and-code":       labelKind = ControlLabelKind.SequenceAndCode; break;
                            case "sequence-and-score":      labelKind = ControlLabelKind.SequenceAndScore; break;
                            case "code-and-score":          labelKind = ControlLabelKind.CodeAndScore; break;
                            default:                        labelKind = ControlLabelKind.Sequence; break;
                        }
                        xmlinput.Skip();
                        break;

                    case "relay":
                        relayTeams = xmlinput.GetAttributeInt("teams", 0);
                        relayLegs = xmlinput.GetAttributeInt("legs", 1);
                        xmlinput.Skip();
                        break;
                }

                first = false;
            }

            if (printArea == null)
                printArea = PrintArea.DefaultPrintArea;
        }
Esempio n. 15
0
        // Create a new course with the given attributes. The course sorts after all existing courses.
        // If addStartAndFinish is true, then if exact one start control exists, it is added. If exactly one finish control exists, it is added.
        public static Id<Course> CreateCourse(EventDB eventDB, CourseKind courseKind, string name, ControlLabelKind labelKind, int scoreColumn, string secondaryTitle, float printScale, float climb, float? length, DescriptionKind descriptionKind, int firstControlOrdinal, bool addStartAndFinish)
        {
            // Find max sort order in use.
            int maxSortOrder = 0;
            foreach (Course course in eventDB.AllCourses)
                if (course.sortOrder > maxSortOrder)
                    maxSortOrder = course.sortOrder;

            PrintArea printArea = (PrintArea) eventDB.GetEvent().printArea.Clone();

            Course newCourse = new Course(courseKind, name, printScale, maxSortOrder + 1);
            newCourse.secondaryTitle = secondaryTitle;
            newCourse.climb = climb;
            newCourse.overrideCourseLength = length;
            newCourse.descKind = descriptionKind;
            newCourse.labelKind = labelKind;
            newCourse.scoreColumn = scoreColumn;
            newCourse.firstControlOrdinal = firstControlOrdinal;
            newCourse.printArea = printArea;

            Id<Course> newCourseId = eventDB.AddCourse(newCourse);

            if (addStartAndFinish) {
                // Add unique start and finish, if they exist.
                Id<ControlPoint> uniqueStart = FindUniqueControl(eventDB, newCourseId, ControlPointKind.Start);
                if (uniqueStart.IsNotNone)
                    AddStartToCourse(eventDB, uniqueStart, newCourseId, false);

                Id<ControlPoint> uniqueFinish = FindUniqueControl(eventDB, newCourseId, ControlPointKind.Finish);
                if (uniqueFinish.IsNotNone)
                    AddFinishToCourse(eventDB, uniqueFinish, newCourseId, false);
            }

            return newCourseId;
        }
Esempio n. 16
0
        // Change the attributes of a all controls display.
        public static void ChangeAllControlsProperties(EventDB eventDB, float printScale, DescriptionKind descriptionKind)
        {
            Event e = eventDB.GetEvent();

            e = (Event) e.Clone();
            e.allControlsPrintScale = printScale;
            e.allControlsDescKind = descriptionKind;

            eventDB.ChangeEvent(e);
        }
Esempio n. 17
0
        DescriptionRenderer renderer; // The description renderer that holds the description.

        #endregion Fields

        #region Constructors

        // Create a new description course object.
        public DescriptionCourseObj(Id<Special> specialId, PointF topLeft, float cellSize, SymbolDB symbolDB, DescriptionLine[] description, DescriptionKind kind, int numColumns)
            : base(Id<ControlPoint>.None, Id<CourseControl>.None, specialId, 1, new CourseAppearance(), GetRect(topLeft, cellSize, symbolDB, description, kind, numColumns))
        {
            // Create the renderer.
            renderer = new DescriptionRenderer(symbolDB);
            renderer.Description = description;
            renderer.DescriptionKind = kind;
            renderer.Margin = cellSize / 20;   // about the thickness of the thick lines.
            renderer.CellSize = cellSize;
            renderer.NumberOfColumns = numColumns;
            aspectAnglesByColumns = ComputeAspectAngles();
        }
        // Render the given course id (0 = all controls) and kind to a map, and compare it to the saved version.
        internal void CheckRenderMap(string filename, Id<Course> id, DescriptionKind kind, int numColumns = 1)
        {
            SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            UndoMgr undomgr = new UndoMgr(5);
            EventDB eventDB = new EventDB(undomgr);
            CourseView courseView;

            eventDB.Load(filename);
            eventDB.Validate();

            courseView = CourseView.CreateViewingCourseView(eventDB, DesignatorFromCourseId(eventDB, id));

            DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB);
            DescriptionLine[] description = descFormatter.CreateDescription(kind == DescriptionKind.Symbols);

            Bitmap bmNew = RenderToMapThenToBitmap(symbolDB, description, kind, numColumns);
            if (numColumns > 1)
                TestUtil.CheckBitmapsBase(bmNew, DescriptionBrowser.GetBitmapFileName(eventDB, id, "_ocad_" + numColumns + "col", kind));
            else
                TestUtil.CheckBitmapsBase(bmNew, DescriptionBrowser.GetBitmapFileName(eventDB, id, "_ocad", kind));
        }
        // Render a description to a map, then to a bitmap for testing purposes. Hardcoded 6 mm box size.
        internal static Bitmap RenderToMapThenToBitmap(SymbolDB symbolDB, DescriptionLine[] description, DescriptionKind kind, int numColumns)
        {
            DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB);
            descriptionRenderer.Description = description;
            descriptionRenderer.DescriptionKind = kind;
            descriptionRenderer.CellSize = 6.0F;
            descriptionRenderer.Margin = 0.7F;
            descriptionRenderer.NumberOfColumns = numColumns;
            PointF location = new PointF(30, -100);

            SizeF size = descriptionRenderer.Measure();

            Bitmap bm = new Bitmap((int) size.Width * 8, (int) size.Height * 8);
            Graphics g = Graphics.FromImage(bm);
            g.ScaleTransform(bm.Width / size.Width, -bm.Height / size.Height);
            g.TranslateTransform(-location.X, -location.Y);

            g.Clear(Color.White);

            Map map = new Map(new GDIPlus_TextMetrics(), null);
            using (map.Write()) {
                Dictionary<object, SymDef> dict = new Dictionary<object, SymDef>();

                // Create white color and white-out symdef.
                SymColor white = map.AddColorBottom("White", 44, 0, 0, 0, 0, false);
                AreaSymDef whiteArea = new AreaSymDef("White out", "890", white, null);
                whiteArea.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.WhiteOut_OcadToolbox);
                map.AddSymdef(whiteArea);
                dict[CourseLayout.KeyWhiteOut] = whiteArea;

                SymColor color = map.AddColor("Purple", 11, 0.045F, 0.59F, 0, 0.255F, false);
                descriptionRenderer.RenderToMap(map, color, location, dict);
            }

            InputOutput.WriteFile(TestUtil.GetTestFile("descriptions\\desc_temp.ocd"), map, new MapFileFormat(MapFileFormatKind.OCAD, 8));

            using (map.Read()) {
                RenderOptions renderOpts = new RenderOptions();
                renderOpts.usePatternBitmaps = true;
                renderOpts.minResolution = 0.1F;
                renderOpts.renderTemplates = RenderTemplateOption.MapAndTemplates;
                map.Draw(new GDIPlus_GraphicsTarget(g), new RectangleF(location.X, location.Y - size.Height, size.Width, size.Height), renderOpts, null);
            }

            g.Dispose();

            return bm;
        }
Esempio n. 20
0
        // Render a description to a bitmap for testing purposes. Does one pixel at a time to test clip rectangle.
        internal static Bitmap RenderToBitmapPixelAtATime(SymbolDB symbolDB, DescriptionLine[] description, DescriptionKind kind)
        {
            DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB);

            descriptionRenderer.Description     = description;
            descriptionRenderer.DescriptionKind = kind;
            descriptionRenderer.CellSize        = 40;
            descriptionRenderer.Margin          = 4;

            SizeF size = descriptionRenderer.Measure();

            Bitmap   bm = new Bitmap((int)size.Width, (int)size.Height);
            Graphics g  = Graphics.FromImage(bm);

            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            g.Clear(Color.White);

            for (int x = 0; x < size.Width; ++x)
            {
                for (int y = 0; y < size.Height; ++y)
                {
                    Rectangle clip = new Rectangle(x, y, 1, 1);
                    g.SetClip(clip);
                    descriptionRenderer.RenderToGraphics(g, clip);
                }
            }

            g.Dispose();

            return(bm);
        }
Esempio n. 21
0
        // Get the file name for a bitmap description for testing purposes. CourseID == 0 means all controls. Extra
        // is an extra string to suffix to the base name. Does not end in .png unless specified in extra.
        public static string GetBitmapFileName(EventDB eventDB, Id <Course> courseId, string extra, DescriptionKind kind)
        {
            Course course = null;
            string name;

            if (courseId.IsNotNone)
            {
                course = eventDB.GetCourse(courseId);
            }


            if (course != null)
            {
                name = course.name;
            }
            else
            {
                name = "Allcontrols";
            }

            name = "descriptions\\" + name + "_" + kind.ToString() + extra;

            return(name);
        }
Esempio n. 22
0
        // Render a description to a bitmap for testing purposes. Hardcoded 40 pixel box size.
        public static Bitmap RenderToBitmap(SymbolDB symbolDB, DescriptionLine[] description, DescriptionKind kind, int numColumns)
        {
            DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB);

            descriptionRenderer.Description     = description;
            descriptionRenderer.DescriptionKind = kind;
            descriptionRenderer.CellSize        = 40;
            descriptionRenderer.Margin          = 4;
            descriptionRenderer.NumberOfColumns = numColumns;

            SizeF size = descriptionRenderer.Measure();

            Bitmap   bm = new Bitmap((int)size.Width, (int)size.Height);
            Graphics g  = Graphics.FromImage(bm);

            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            g.Clear(Color.White);
            descriptionRenderer.RenderToGraphics(g, new RectangleF(0, 0, size.Width, size.Height));

            g.Dispose();

            return(bm);
        }
Esempio n. 23
0
        // Render a description to a map, then to a bitmap for testing purposes. Hardcoded 6 mm box size.
        internal static Bitmap RenderToMapThenToBitmap(SymbolDB symbolDB, DescriptionLine[] description, DescriptionKind kind, int numColumns)
        {
            DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB);

            descriptionRenderer.Description     = description;
            descriptionRenderer.DescriptionKind = kind;
            descriptionRenderer.CellSize        = 6.0F;
            descriptionRenderer.Margin          = 0.7F;
            descriptionRenderer.NumberOfColumns = numColumns;
            PointF location = new PointF(30, -100);

            SizeF size = descriptionRenderer.Measure();

            Bitmap   bm = new Bitmap((int)size.Width * 8, (int)size.Height * 8);
            Graphics g  = Graphics.FromImage(bm);

            g.ScaleTransform(bm.Width / size.Width, -bm.Height / size.Height);
            g.TranslateTransform(-location.X, -location.Y);

            g.Clear(Color.White);

            Map map = new Map(new GDIPlus_TextMetrics(), null);

            using (map.Write()) {
                Dictionary <object, SymDef> dict = new Dictionary <object, SymDef>();

                // Create white color and white-out symdef.
                SymColor   white     = map.AddColorBottom("White", 44, 0, 0, 0, 0, false);
                AreaSymDef whiteArea = new AreaSymDef("White out", "890", white, null);
                whiteArea.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.WhiteOut_OcadToolbox);
                map.AddSymdef(whiteArea);
                dict[CourseLayout.KeyWhiteOut] = whiteArea;

                SymColor color = map.AddColor("Purple", 11, 0.045F, 0.59F, 0, 0.255F, false);
                descriptionRenderer.RenderToMap(map, color, location, dict);
            }

            InputOutput.WriteFile(TestUtil.GetTestFile("descriptions\\desc_temp.ocd"), map, new MapFileFormat(MapFileFormatKind.OCAD, 8));

            using (map.Read()) {
                RenderOptions renderOpts = new RenderOptions();
                renderOpts.usePatternBitmaps = true;
                renderOpts.minResolution     = 0.1F;
                renderOpts.renderTemplates   = RenderTemplateOption.MapAndTemplates;
                map.Draw(new GDIPlus_GraphicsTarget(g), new RectangleF(location.X, location.Y - size.Height, size.Width, size.Height), renderOpts, null);
            }

            g.Dispose();

            return(bm);
        }
Esempio n. 24
0
        // Render a single line of the description. "lastLine" is true if this is the last line (draws the bottom line). The "thickLineCounter"
        // is used to decide when to draw the thick lines.
        // clipRect is the clipping rectangle in world coordinates. Only need to draw things that intersect it.
        private void RenderLine(IRenderer renderer, DescriptionLine descriptionLine, DescriptionKind descriptionKind, bool lastLine, bool drawThickLine, bool noTopLine, RectangleF clipRect)
        {
            float fullWidth = WidthInCells() * 100;

            // Draw top line.
            if (!noTopLine) {
                if (descriptionLine.kind != DescriptionLineKind.Normal || drawThickLine) {
                    renderer.DrawLine(thickPen, 0, 0, fullWidth, 0);
                }
                else {
                    renderer.DrawLine(thinPen, 0, 0, fullWidth, 0);
                }
            }

            // Draw bottom line, if requested
            if (lastLine)
                renderer.DrawLine(thickPen, 0, 100, fullWidth, 100);

            // Draw side lines.
            float lineTop = -DescriptionAppearance.thickDescriptionLine / 2;
            float lineBottom = 100 + DescriptionAppearance.thickDescriptionLine / 2;
            renderer.DrawLine(thickPen, 0, lineTop, 0, lineBottom);
            if (! (descriptionKind == DescriptionKind.SymbolsAndText && (descriptionLine.kind == DescriptionLineKind.Title || descriptionLine.kind == DescriptionLineKind.SecondaryTitle || descriptionLine.kind == DescriptionLineKind.Text)))
                renderer.DrawLine(thickPen, 800, lineTop, 800, lineBottom);
            if (descriptionKind == DescriptionKind.SymbolsAndText)
                renderer.DrawLine(thickPen, 1300, lineTop, 1300, lineBottom);

            switch (descriptionLine.kind) {
                case DescriptionLineKind.Title:
                    RenderSingleLineText(renderer, TITLE_FONT, StringAlignment.Center, (string) (descriptionLine.boxes[0]), 0, 0, fullWidth, 100, clipRect);
                    break;

                case DescriptionLineKind.SecondaryTitle:
                    RenderSingleLineText(renderer, TITLE_FONT, StringAlignment.Center, (string) (descriptionLine.boxes[0]), 0, 0, fullWidth, 100, clipRect);
                    break;

                case DescriptionLineKind.Header2Box:
                    renderer.DrawLine(thickPen, 300, lineTop, 300, lineBottom);
                    RenderSingleLineText(renderer, TITLE_FONT, StringAlignment.Center, (string) (descriptionLine.boxes[0]), 0, 0, 300, 100, clipRect);
                    RenderSingleLineText(renderer, TITLE_FONT, StringAlignment.Center, (string) (descriptionLine.boxes[1]), 300, 0, 800, 100, clipRect);
                    break;

                case DescriptionLineKind.Header3Box:
                    renderer.DrawLine(thickPen, 300, lineTop, 300, lineBottom);
                    renderer.DrawLine(thickPen, 600, lineTop, 600, lineBottom);
                    RenderSingleLineText(renderer, TITLE_FONT, StringAlignment.Center, (string) (descriptionLine.boxes[0]), 0, 0, 300, 100, clipRect);
                    RenderSingleLineText(renderer, TITLE_FONT, StringAlignment.Center, (string) (descriptionLine.boxes[1]), 300, 0, 600, 100, clipRect);
                    RenderSingleLineText(renderer, TITLE_FONT, StringAlignment.Center, (string) (descriptionLine.boxes[2]), 600, 0, 800, 100, clipRect);
                    break;

                case DescriptionLineKind.Directive:
                    if (descriptionKind == DescriptionKind.Text) {
                        RenderWrappedText(renderer, TEXT_FONT, StringAlignment.Near, descriptionLine.textual, 15, 0, 785, 100, clipRect);
                    }
                    else {
                        RenderSymbol(renderer, (Symbol)descriptionLine.boxes[0], 0, 0, 800, 100, clipRect);
                        RenderSingleLineText(renderer, DIRECTIVE_FONT, StringAlignment.Center, (string) (descriptionLine.boxes[1]), 300, 0, 500, 100, clipRect);
                        if (descriptionKind == DescriptionKind.SymbolsAndText)
                            RenderWrappedText(renderer, TEXT_FONT, StringAlignment.Near, descriptionLine.textual, 815, 0, 1285, 100, clipRect);
                    }

                    break;

                case DescriptionLineKind.Normal:
                    int numBoxes;
                    if (descriptionKind == DescriptionKind.Text) {
                        renderer.DrawLine(thinPen, 100, lineTop, 100, lineBottom);
                        renderer.DrawLine(thickPen, 200, lineTop, 200, lineBottom);
                        RenderWrappedText(renderer, TEXT_FONT, StringAlignment.Near, descriptionLine.textual, 215, 0, 785, 100, clipRect);
                        numBoxes = 2;
                    }
                    else {
                        renderer.DrawLine(thinPen, 100, lineTop, 100, lineBottom);
                        renderer.DrawLine(thinPen, 200, lineTop, 200, lineBottom);
                        renderer.DrawLine(thickPen, 300, lineTop, 300, lineBottom);
                        renderer.DrawLine(thinPen, 400, lineTop, 400, lineBottom);
                        renderer.DrawLine(thinPen, 500, lineTop, 500, lineBottom);
                        renderer.DrawLine(thickPen, 600, lineTop, 600, lineBottom);
                        renderer.DrawLine(thinPen, 700, lineTop, 700, lineBottom);
                        numBoxes = 8;

                        if (descriptionKind == DescriptionKind.SymbolsAndText) {
                            renderer.DrawLine(thickPen, 1300, lineTop, 1300, lineBottom);
                            RenderWrappedText(renderer, TEXT_FONT, StringAlignment.Near, descriptionLine.textual, 815, 0, 1285, 100, clipRect);
                        }
                    }

                    for (int i = 0; i < numBoxes; ++i) {
                        if (descriptionLine.boxes[i] is Symbol) {
                            RenderSymbol(renderer, (Symbol)descriptionLine.boxes[i], i * 100, 0, i * 100 + 100, 100, clipRect);
                        }
                        else if (descriptionLine.boxes[i] is String) {
                            if (i == 5)
                                RenderColumnFText(renderer, (string)descriptionLine.boxes[i], i * 100, 0, i * 100 + 100, 100, clipRect);
                            else if (i == 0)
                                RenderSingleLineText(renderer, COLUMNA_FONT, StringAlignment.Center, (string) descriptionLine.boxes[i], i * 100, 0, i * 100 + 100, 100, clipRect);
                            else
                                RenderSingleLineText(renderer, COLUMNB_FONT, StringAlignment.Center, (string) descriptionLine.boxes[i], i * 100, 0, i * 100 + 100, 100, clipRect);
                        }
                    }

                    break;

                case DescriptionLineKind.Key:
                    RenderSymbol(renderer, (Symbol) descriptionLine.boxes[0], 100, 0, 200, 100, clipRect);
                    RenderSingleLineText(renderer, KEY_FONT, StringAlignment.Near, "= " + (string) (descriptionLine.boxes[1]), 200, 0, 800, 100, clipRect);
                    break;

                case DescriptionLineKind.Text:
                    RenderWrappedText(renderer, TEXTLINE_FONT, StringAlignment.Near, (string) (descriptionLine.boxes[0]), 20, 0, fullWidth, 100, clipRect);
                    break;

                default:
                    Debug.Fail("unknown description line kind");
                    break;
            }
        }
Esempio n. 25
0
        // Return the description and description kind for a given CourseView.
        public static DescriptionLine[] GetCourseDescription(EventDB eventDB, SymbolDB symbolDB, CourseDesignator courseDesignator, out DescriptionKind descKind)
        {
            CourseView courseViewDescription;
            DescriptionLine[] description;
            bool noTextOrSymbols = false;

            // Get the course view for the description we're using.
            courseViewDescription = CourseView.CreateViewingCourseView(eventDB, courseDesignator);

            // Create the description. Note the courseId is None only if we're both in all controls, and there are no courses.
            DescriptionFormatter descFormatter = new DescriptionFormatter(courseViewDescription, symbolDB);
            descKind = QueryEvent.GetDefaultDescKind(eventDB, courseDesignator.CourseId);
            description = descFormatter.CreateDescription(descKind == DescriptionKind.Symbols);
            if (noTextOrSymbols)
                DescriptionFormatter.ClearTextAndSymbols(description);

            return description;
        }
Esempio n. 26
0
        // Get the rectangle used by the description.
        static RectangleF GetRect(PointF topLeft, float cellSize, SymbolDB symbolDB, DescriptionLine[] description, DescriptionKind kind, int numColumns)
        {
            // Create the renderer.
            DescriptionRenderer renderer = new DescriptionRenderer(symbolDB);
            renderer.Description = description;
            renderer.DescriptionKind = kind;
            renderer.Margin = cellSize / 20;   // about the thickness of the thick lines.
            renderer.CellSize = cellSize;
            renderer.NumberOfColumns = numColumns;

            SizeF size = renderer.Measure();
            return new RectangleF(topLeft.X, topLeft.Y - size.Height, size.Width, size.Height);
        }
Esempio n. 27
0
        public override void ReadAttributesAndContent(XmlInput xmlinput)
        {
            firstControlCode = 31;
            disallowInvertibleCodes = true;
            courseAppearance.purpleColorBlend = false; // default for existing events is false, true for new events.
            printArea = null;  // Will be set at end if not loaded.

            bool first = true;
            while (xmlinput.FindSubElement(first, "title", "notes", "map", "all-controls", "numbering", "punch-card", "course-appearance", "print-area", "descriptions", "ocad", "custom-symbol-text")) {
                switch (xmlinput.Name) {
                    case "title":
                        title = xmlinput.GetContentString();
                        break;

                    case "notes":
                        notes = xmlinput.GetContentString();
                        break;

                    case "map":
                        mapScale = xmlinput.GetAttributeFloat("scale");

                        string kindString = xmlinput.GetAttributeString("kind");
                        switch (kindString) {
                            case "none": mapType = MapType.None; break;
                            case "OCAD": mapType = MapType.OCAD; break;
                            case "bitmap": mapType = MapType.Bitmap; break;
                            case "PDF": mapType = MapType.PDF; break;
                            default: xmlinput.BadXml("Invalid map kind '{0}'", kindString); break;
                        }

                        if (mapType == MapType.Bitmap)
                            mapDpi = xmlinput.GetAttributeFloat("dpi");
                        else
                            mapDpi = 0;

                        if (mapType == MapType.OCAD)
                            ignoreMissingFonts = xmlinput.GetAttributeBool("ignore-missing-fonts", false);

                        if (mapType != MapType.None) {
                            mapFileName = xmlinput.GetContentString();
                            mapFileName = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(xmlinput.FileName), mapFileName)); // file name is relative to the XML file
                        }
                        else {
                            mapFileName = null;
                            xmlinput.Skip();
                        }

                        break;

                    case "all-controls":
                        allControlsPrintScale = xmlinput.GetAttributeFloat("print-scale", 0);
                        allControlsDescKind = EventDBUtil.ReadDescriptionKindAttribute(xmlinput);
                        xmlinput.Skip();
                        break;

                    case "numbering":
                        firstControlCode = xmlinput.GetAttributeInt("start", 31);
                        disallowInvertibleCodes = xmlinput.GetAttributeBool("disallow-invertible", true);
                        xmlinput.Skip();
                        break;

                    case "punch-card":
                        punchcardFormat.boxesDown = xmlinput.GetAttributeInt("rows", PunchcardAppearance.defaultBoxesDown);
                        punchcardFormat.boxesAcross = xmlinput.GetAttributeInt("columns", PunchcardAppearance.defaultBoxesAcross);
                        punchcardFormat.leftToRight = xmlinput.GetAttributeBool("left-to-right", PunchcardAppearance.defaultLeftToRight);
                        punchcardFormat.topToBottom = xmlinput.GetAttributeBool("top-to-bottom", PunchcardAppearance.defaultTopToBottom);
                        xmlinput.Skip();
                        break;

                    case "course-appearance":
                        courseAppearance.controlCircleSize = xmlinput.GetAttributeFloat("control-circle-size-ratio", 1.0F);
                        courseAppearance.lineWidth = xmlinput.GetAttributeFloat("line-width-ratio", 1.0F);
                        courseAppearance.centerDotDiameter = xmlinput.GetAttributeFloat("center-dot-diameter", 0.0F);
                        courseAppearance.numberHeight = xmlinput.GetAttributeFloat("number-size-ratio", 1.0F);
                        courseAppearance.numberBold = xmlinput.GetAttributeBool("number-bold", false);
                        courseAppearance.numberOutlineWidth = xmlinput.GetAttributeFloat("number-outline-width", 0.0F);
                        courseAppearance.autoLegGapSize = xmlinput.GetAttributeFloat("auto-leg-gap-size", 3.5F);  // default value
                        courseAppearance.purpleColorBlend = xmlinput.GetAttributeBool("blend-purple", false);
                        courseAppearance.purpleC = xmlinput.GetAttributeFloat("purple-cyan", -1F);
                        courseAppearance.purpleM = xmlinput.GetAttributeFloat("purple-magenta", -1F);
                        courseAppearance.purpleY = xmlinput.GetAttributeFloat("purple-yellow", -1F);
                        courseAppearance.purpleK = xmlinput.GetAttributeFloat("purple-black", -1F);
                        if (courseAppearance.purpleC < 0 || courseAppearance.purpleM < 0 || courseAppearance.purpleY < 0 || courseAppearance.purpleK < 0) {
                            courseAppearance.useDefaultPurple = true;
                            courseAppearance.purpleC = courseAppearance.purpleM = courseAppearance.purpleY = courseAppearance.purpleK = 1;
                        }
                        else {
                            courseAppearance.useDefaultPurple = false;
                        }

                        xmlinput.Skip();
                        break;

                    case "print-area":
                        printArea = new PrintArea();
                        printArea.ReadAttributesAndContent(xmlinput);
                        break;

                    case "descriptions":
                        descriptionLangId = xmlinput.GetAttributeString("lang");

                        string descriptionColor = xmlinput.GetAttributeString("color", "black");
                        if (descriptionColor.Equals("purple", StringComparison.InvariantCultureIgnoreCase))
                            courseAppearance.descriptionsPurple = true;
                        else
                            courseAppearance.descriptionsPurple = false;

                        xmlinput.Skip();
                        break;

                    case "ocad":
                        courseAppearance.useOcadOverprint = xmlinput.GetAttributeBool("overprint-colors", false);
                        xmlinput.Skip();
                        break;

                    case "custom-symbol-text":
                        string iof2004id = xmlinput.GetAttributeString("iof-2004-ref");
                        bool key = xmlinput.GetAttributeBool("show-key", false);
                        customSymbolKey[iof2004id] = key;
                        xmlinput.Read();
                        xmlinput.MoveToContent();

                        List<SymbolText> texts = new List<SymbolText>();
                        if (xmlinput.Reader.NodeType == XmlNodeType.Text) {
                            // Reading the old-style custom symbol text.
                            string customText = xmlinput.Reader.ReadString();
                            if (iof2004id.StartsWith("8.", StringComparison.InvariantCulture))
                                customText += " {0}";     // old style for modifiers didn't have the fill-in placeholder.
                            SymbolText text = new SymbolText();
                            text.Lang = "en";
                            text.Plural = false;
                            text.Gender = "";
                            text.Text = customText;
                            texts.Add(text);
                        }
                        else {
                            // Read the new-style custom symbol text.
                            while (xmlinput.Reader.NodeType == XmlNodeType.Element && xmlinput.Name == "text") {
                                SymbolText text = new SymbolText();
                                text.ReadXml(xmlinput);
                                texts.Add(text);
                                xmlinput.Skip();
                            }
                        }
                        
                        customSymbolText[iof2004id] = texts;
                        xmlinput.Skip();
                        break;
                        
                }

                first = false;
            }

            if (allControlsPrintScale == 0)
                allControlsPrintScale = mapScale;

            float scaleRatio;
            if (mapScale > 0 && allControlsPrintScale > 0)
                scaleRatio = allControlsPrintScale / mapScale;
            else
                scaleRatio = 1.0F;

            if (printArea == null) {
                printArea = MapUtil.GetDefaultPrintArea(mapFileName, scaleRatio);
            }
        }
Esempio n. 28
0
        // Render a description to a bitmap for testing purposes. Hardcoded 40 pixel box size.
        public static Bitmap RenderToBitmap(SymbolDB symbolDB, DescriptionLine[] description, DescriptionKind kind, int numColumns)
        {
            DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB);
            descriptionRenderer.Description = description;
            descriptionRenderer.DescriptionKind = kind;
            descriptionRenderer.CellSize = 40;
            descriptionRenderer.Margin = 4;
            descriptionRenderer.NumberOfColumns = numColumns;

            SizeF size = descriptionRenderer.Measure();

            Bitmap bm = new Bitmap((int) size.Width, (int) size.Height);
            Graphics g = Graphics.FromImage(bm);

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            g.Clear(Color.White);
            descriptionRenderer.RenderToGraphics(g, new RectangleF(0, 0, size.Width, size.Height));

            g.Dispose();

            return bm;
        }
Esempio n. 29
0
        private List <ElasticProjectData> HitToDataConvertProject(ISearchResponse <ElasticProjectData> searchResponse, DescriptionKind isExtended)
        {
            List <ElasticProjectData> resultList = new List <ElasticProjectData>();

            foreach (var hit in searchResponse.Hits)
            {
                resultList.Add(new ElasticProjectData(hit.Source, isExtended));
            }
            return(resultList);
        }
        // Render a description to a bitmap for testing purposes. Does one pixel at a time to test clip rectangle.
        internal static Bitmap RenderToBitmapPixelAtATime(SymbolDB symbolDB, DescriptionLine[] description, DescriptionKind kind)
        {
            DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB);
            descriptionRenderer.Description = description;
            descriptionRenderer.DescriptionKind = kind;
            descriptionRenderer.CellSize = 40;
            descriptionRenderer.Margin = 4;

            SizeF size = descriptionRenderer.Measure();

            Bitmap bm = new Bitmap((int)size.Width, (int)size.Height);
            Graphics g = Graphics.FromImage(bm);

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            g.Clear(Color.White);

            for (int x = 0; x < size.Width; ++x) {
                for (int y = 0; y < size.Height; ++y) {
                    Rectangle clip = new Rectangle(x, y, 1, 1);
                    g.SetClip(clip);
                    descriptionRenderer.RenderToGraphics(g, clip);
                }
            }

            g.Dispose();

            return bm;
        }
Esempio n. 31
0
        public List <ElasticProjectData> SearchItemsProject(string tstring, Paging paging, DescriptionKind isExtended)
        {
            int from = paging.From;
            int size = paging.Size;
            var sr   = clientProject.Search <ElasticProjectData>(s => s.
                                                                 From(from)
                                                                 .Size(size).
                                                                 Query(q => q
                                                                       .Bool(b => b.
                                                                             Should(m => m.
                                                                                    Match(mp => mp
                                                                                          .Field(fg => fg.Name)
                                                                                          .Query(tstring)
                                                                                          .Fuzziness(Fuzziness.Auto)
                                                                                          ),

                                                                                    m => m.Match(mp => mp
                                                                                                 .Field(fg => fg.InternalDescr)
                                                                                                 .Query(tstring)
                                                                                                 .Fuzziness(Fuzziness.Auto)
                                                                                                 )

                                                                                    ))));
            var returnlist = new List <ElasticProjectData>();

            List <ElasticProjectData> resultList = new List <ElasticProjectData>();
            var temp = new ElasticProjectData();

            returnlist = HitToDataConvertProject(sr, isExtended);
            return(returnlist);
        }
        // Render the given course id (0 = all controls) and kind to a bitmap, and compare it to the saved version.
        internal void CheckRenderBitmapPixelAtATime(Id<Course> id, DescriptionKind kind)
        {
            SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            UndoMgr undomgr = new UndoMgr(5);
            EventDB eventDB = new EventDB(undomgr);
            CourseView courseView;

            eventDB.Load(TestUtil.GetTestFile("descriptions\\sampleevent1.coursescribe"));
            eventDB.Validate();

            courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(id));

            DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB);
            DescriptionLine[] description = descFormatter.CreateDescription(false);

            Bitmap bmNew = RenderToBitmapPixelAtATime(symbolDB, description, kind);
            TestUtil.CheckBitmapsBase(bmNew, DescriptionBrowser.GetBitmapFileName(eventDB, id, "", kind));
        }
Esempio n. 33
0
 private IEnumerable <ElasticProjectData> GetElasticProjects(IEnumerable <ProjectEntity> projects, DescriptionKind isExtended)
 {
     foreach (var item in projects)
     {
         yield return(elastic.GetProjectById(item.Id, isExtended));
     }
 }
Esempio n. 34
0
 // Update the thick line counter to indicate when a thick line should be drawn (whever counter is 0)
 private void UpdateThickLineCounter(DescriptionLine descriptionLine, DescriptionKind descriptionKind, ref int thickLineCounter)
 {
     if (descriptionLine.kind == DescriptionLineKind.Normal) {
         if (descriptionLine.boxes[0] != null && descriptionLine.boxes[0] is Symbol)
             thickLineCounter = 0;   // after start, put a thick line also.
         else {
             // put a thick line after every three normal lines.
             thickLineCounter += 1;
             if (thickLineCounter == 3)
                 thickLineCounter = 0;
         }
     }
     else {
         thickLineCounter = 0;
     }
 }
Esempio n. 35
0
        // Change the attributes of a course.
        public static void ChangeCourseProperties(EventDB eventDB, Id<Course> courseId, CourseKind courseKind, string courseName, ControlLabelKind labelKind, int scoreColumn, string secondaryTitle, float printScale, float climb, float? length, DescriptionKind descriptionKind, int firstControlOrdinal)
        {
            Course course = eventDB.GetCourse(courseId);

            course = (Course) course.Clone();
            course.kind = courseKind;
            course.labelKind = labelKind;
            course.scoreColumn = scoreColumn;
            course.name = courseName;
            course.secondaryTitle = secondaryTitle;
            course.printScale = printScale;
            course.climb = climb;
            course.overrideCourseLength = length;
            course.descKind = descriptionKind;
            course.firstControlOrdinal = firstControlOrdinal;

            eventDB.ReplaceCourse(courseId, course);
        }