Exemplo n.º 1
0
 public override IMapViewerHighlight[] GetHighlights(Pane pane)
 {
     if (pane == Pane.Map)
     {
         if (highlight != null)
         {
             if (additionalHighlights != null && additionalHighlights.Length > 0)
             {
                 CourseObj[] highlights = new CourseObj[additionalHighlights.Length + 1];
                 highlights[0] = highlight;
                 Array.Copy(additionalHighlights, 0, highlights, 1, additionalHighlights.Length);
                 return(highlights);
             }
             else
             {
                 return(new CourseObj[] { highlight });
             }
         }
         else
         {
             return(null);
         }
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 2
0
        public void SelectCourseObjectAllControls()
        {
            bool success = controller.LoadInitialFile(TestUtil.GetTestFile("selectionmgr\\marymoor1.coursescribe"), true);

            Assert.IsTrue(success);

            selectionMgr.SelectCourseView(Designator(0));
            CourseLayout course = selectionMgr.CourseLayout;

            CourseObj courseobject = course[4];

            Assert.IsTrue(courseobject.controlId.id == 38);
            selectionMgr.SelectCourseObject(courseobject);
            CheckSelectedLines(6, 6);

            courseobject = course[0];
            Assert.IsTrue(courseobject.controlId.id == 1);
            selectionMgr.SelectCourseObject(courseobject);
            CheckSelectedLines(2, 2);

            courseobject = course[37];
            Assert.IsTrue(courseobject.controlId.id == 2);
            selectionMgr.SelectCourseObject(courseobject);
            CheckSelectedLines(39, 39);

            courseobject = course[41];
            Assert.IsTrue(courseobject.controlId.id == 38);
            selectionMgr.SelectCourseObject(courseobject);
            CheckSelectedLines(6, 6);
        }
Exemplo n.º 3
0
        CourseObj[] additionalHighlights;  // additional highlights to show also, for legs to/from control.

        public DragObjectMode(Controller controller, EventDB eventDB, SelectionMgr selectionMgr, CourseObj courseObject, PointF startDrag)
        {
            this.controller        = controller;
            this.eventDB           = eventDB;
            this.selectionMgr      = selectionMgr;
            this.courseObjectStart = courseObject;
            this.courseObjectDrag  = (CourseObj)(courseObject.Clone());
            this.startDrag         = this.currentLocation = startDrag;
        }
Exemplo n.º 4
0
 public DragHandleMode(Controller controller, CourseObj courseObject, PointF handleLocation, PointF startDrag)
 {
     this.controller        = controller;
     this.courseObjectStart = courseObject;
     this.courseObjectDrag  = (CourseObj)(courseObject.Clone());
     this.handleLocation    = handleLocation;
     this.handleCursor      = courseObject.GetHandleCursor(handleLocation);
     this.startDrag         = this.currentLocation = startDrag;
 }
        public override void LeftButtonCancelDrag(Pane pane, ref bool displayUpdateNeeded)
        {
            Debug.Assert(pane == Pane.Topology);

            // Drag was cancelled. Go back to normal mode.
            dropTargetHighlight = null;
            displayUpdateNeeded = true;

            controller.DefaultCommandMode();
        }
 public TopologyDragControlMode(Controller controller, EventDB eventDB, SelectionMgr selectionMgr, CourseObj courseObject, PointF startDrag, PointF currentLocation)
 {
     this.controller          = controller;
     this.eventDB             = eventDB;
     this.selectionMgr        = selectionMgr;
     this.courseObjectStart   = courseObject;
     this.courseObjectDrag    = (CourseObj)(courseObject.Clone());
     this.startDrag           = startDrag;
     this.currentLocation     = currentLocation;
     this.dropTargetHighlight = null;
 }
        public override void LeftButtonDrag(Pane pane, PointF location, PointF locationStart, float pixelSize, ref bool displayUpdateNeeded)
        {
            Debug.Assert(pane == Pane.Topology);

            currentLocation = location;

            // Update the highlight.
            courseObjectDrag = ((CourseObj)courseObjectStart.Clone());
            courseObjectDrag.Offset(location.X - startDrag.X, location.Y - startDrag.Y);

            dropTargetHighlight = FindNearbyDropTarget(location);

            displayUpdateNeeded = true;
        }
Exemplo n.º 8
0
        void CheckHitTest(CourseLayout course, PointF point, CourseLayer layerFilter, Predicate <CourseObj> filter, string expectedObject)
        {
            CourseObj courseobj = course.HitTest(point, 0.1F, layerFilter, filter);

            if (courseobj == null)
            {
                Assert.IsNull(expectedObject);
            }
            else
            {
                Console.WriteLine(courseobj);
                Assert.AreEqual(expectedObject, courseobj.ToString());
            }
        }
Exemplo n.º 9
0
        public override MapViewer.DragAction LeftButtonDown(Pane pane, PointF location, float pixelSize, ref bool displayUpdateNeeded)
        {
            if (pane != Pane.Map)
            {
                return(MapViewer.DragAction.None);
            }

            // Begin dragging out the image.
            startLocation  = location;
            startingObj    = createCourseObj(new RectangleF(location.X, location.Y, 0.001F, 0.001F * aspectRatio));
            handleDragging = location;
            DragTo(location);
            displayUpdateNeeded = true;
            return(MapViewer.DragAction.DelayedDrag);  // Also allow a click.
        }
Exemplo n.º 10
0
        // Left mouse button selects the object clicked on, or drag something already selected.
        public override MapViewer.DragAction LeftButtonDown(Pane pane, PointF location, float pixelSize, ref bool displayUpdateNeeded)
        {
            if (pane == Pane.Map)
            {
                CourseLayout activeCourse = controller.GetCourseLayout();
                CourseObj    clickedObject;
                PointF       handleLocation;
                Cursor       handleCursor;

                // Area we initiating a drag of a corner?
                clickedObject = HitTestHandle(location, pixelSize, out handleLocation, out handleCursor);
                if (clickedObject != null)
                {
                    // being dragging the corner
                    DragHandleMode commandMode = new DragHandleMode(controller, clickedObject, handleLocation, location);
                    controller.SetCommandMode(commandMode);
                    displayUpdateNeeded = true;
                    return(MapViewer.DragAction.ImmediateDrag);
                }

                // Are we initiating a drag of an object?
                clickedObject = HitTestDraggable(location, pixelSize);
                if (clickedObject != null)
                {
                    // Begin dragging the clicked object.
                    DragObjectMode commandMode = new DragObjectMode(controller, eventDB, selectionMgr, clickedObject, location);
                    controller.SetCommandMode(commandMode);
                    displayUpdateNeeded = true;
                    return(MapViewer.DragAction.ImmediateDrag);
                }

                return(MapViewer.DragAction.DelayedDrag);
            }
            else if (pane == Pane.Topology)
            {
                CourseObj clickedObject = HitTest(pane, location, pixelSize, (co => !(co is TopologyDropTargetCourseObj)));
                if (clickedObject is ControlNumberCourseObj || clickedObject is CrossingCourseObj ||
                    (clickedObject is StartCourseObj && (eventDB.GetControl(((StartCourseObj)clickedObject).controlId).kind == ControlPointKind.MapExchange)))
                {
                    // Can drag control numbers, crossing points, or map exchanges.
                    selectionMgr.SelectCourseObject(clickedObject);
                    displayUpdateNeeded = true;
                    return(MapViewer.DragAction.DelayedDrag);
                }
            }

            return(MapViewer.DragAction.None);
        }
Exemplo n.º 11
0
        // Hit test a location to see if it is over a selected, draggable objects. If so,
        // return that course object, otherwise, return null.
        CourseObj HitTestDraggable(PointF location, float pixelSize)
        {
            CourseObj[] selectedObjects = selectionMgr.SelectedCourseObjects;

            if (selectedObjects != null)
            {
                // If the cursor is above a selected control, start, finish that is a moveable object.
                CourseObj hitObject = CourseLayout.HitTestCollection(selectedObjects, location, pixelSize, CourseLayer.All, null);
                if (hitObject != null && DraggableObject(hitObject))
                {
                    return(hitObject);
                }
            }

            return(null);
        }
Exemplo n.º 12
0
        // Is this course object draggable?
        bool DraggableObject(CourseObj courseObject)
        {
            // Legs are not draggable.
            if (courseObject == null || (courseObject is LegCourseObj) || (courseObject is FlaggedLegCourseObj))
            {
                return(false);
            }

            if (courseObject is MapIssueCourseObj && courseObject.controlId.IsNone)
            {
                return(false);
            }

            // Everything else is draggable.
            return(true);
        }
Exemplo n.º 13
0
 public override void LeftButtonDrag(Pane pane, PointF location, PointF locationStart, float pixelSize, ref bool displayUpdateNeeded)
 {
     if (pane == Pane.Map)
     {
         // If we dragged an object or corner, we would have entered a new mode. So this must be a delayed drag that should
         // become map dragging.
         controller.InitiateMapDragging(locationStart, System.Windows.Forms.MouseButtons.Left);
     }
     else if (pane == Pane.Topology)
     {
         CourseObj clickedObject = HitTest(pane, locationStart, pixelSize,
                                           co => !(co.layer == CourseLayer.AllVariations && !(co is TopologyDropTargetCourseObj)) &&
                                           !((co is MapIssueCourseObj) && co.controlId.IsNone));
         TopologyDragControlMode commandMode = new TopologyDragControlMode(controller, eventDB, selectionMgr, clickedObject, locationStart, location);
         controller.SetCommandMode(commandMode);
     }
 }
Exemplo n.º 14
0
 // Select a course object in the current displayed course.
 public void SelectCourseObject(CourseObj courseObject)
 {
     if (courseObject is ControlCourseObj || courseObject is StartCourseObj || courseObject is FinishCourseObj || courseObject is MapIssueCourseObj ||
         (courseObject is CrossingCourseObj && courseObject.specialId.IsNone) || courseObject is CodeCourseObj || courseObject is ControlNumberCourseObj)
     {
         SetSelection(SelectionKind.Control, courseObject.courseControlId, Id<CourseControl>.None, LegInsertionLoc.Normal, courseObject.controlId, Id<Special>.None, null, DescriptionLine.TextLineKind.None);
     }
     else if (courseObject.specialId.IsNotNone) {
         SetSelection(SelectionKind.Special, Id<CourseControl>.None, Id<CourseControl>.None, LegInsertionLoc.Normal, Id<ControlPoint>.None, courseObject.specialId, null, DescriptionLine.TextLineKind.None);
     }
     else if (courseObject is LegCourseObj || courseObject is FlaggedLegCourseObj || courseObject is TopologyLegCourseObj) {
         SetSelection(SelectionKind.Leg, courseObject.courseControlId, ((LineCourseObj) courseObject).courseControlId2, LegInsertionLoc.Normal, courseObject.controlId, Id<Special>.None, null, DescriptionLine.TextLineKind.None);
     }
     else if (courseObject is TopologyDropTargetCourseObj) {
         SetSelection(SelectionKind.Leg, courseObject.courseControlId, ((TopologyDropTargetCourseObj)courseObject).courseControlId2, ((TopologyDropTargetCourseObj)courseObject).InsertionLoc, courseObject.controlId, Id<Special>.None, null, DescriptionLine.TextLineKind.None);
     }
 }
Exemplo n.º 15
0
        public override void LeftButtonEndDrag(Pane pane, PointF location, PointF locationStart, float pixelSize, ref bool displayUpdateNeeded)
        {
            Debug.Assert(pane == Pane.Topology);

            TopologyDropTargetCourseObj dropAt = FindNearbyDropTarget(location);

            if (dropTargetHighlight != null)
            {
                Id <CourseControl> courseControlToMove = courseObjectStart.courseControlId;
                Id <CourseControl> courseControlDest1  = dropAt.courseControlId;
                Id <CourseControl> courseControlDest2  = dropAt.courseControlId2;

                controller.RearrangeControl(courseControlToMove, courseControlDest1, courseControlDest2, dropAt.InsertionLoc);
            }

            dropTargetHighlight = null;
            displayUpdateNeeded = true;
            controller.DefaultCommandMode();
        }
Exemplo n.º 16
0
        public void SelectSpecialCourseObj()
        {
            bool success = controller.LoadInitialFile(TestUtil.GetTestFile("selectionmgr\\sampleevent4.coursescribe"), true);

            Assert.IsTrue(success);

            // Select a special in all controls.
            selectionMgr.SelectCourseView(Designator(0));
            CourseLayout course       = selectionMgr.CourseLayout;
            CourseObj    courseobject = course[1];

            Assert.IsTrue(courseobject.specialId.id == 4);
            selectionMgr.SelectCourseObject(courseobject);

            CheckSelectedLines(-1, -1);
            SelectionMgr.SelectionInfo selectionInfo = selectionMgr.Selection;
            Assert.AreEqual(SelectionMgr.SelectionKind.Special, selectionInfo.SelectionKind);
            Assert.AreEqual(0, selectionInfo.SelectedControl.id);
            Assert.AreEqual(0, selectionInfo.SelectedCourseControl.id);
            Assert.AreEqual(4, selectionInfo.SelectedSpecial.id);

            CourseObj[] selectedObjects = selectionMgr.SelectedCourseObjects;
            Assert.AreEqual(1, selectedObjects.Length);
            Assert.AreEqual(@"OOB:            special:4  scale:1  path:N(3,7)--N(11,2)--N(0,-7)--N(-12,-3)--N(3,7)", selectedObjects[0].ToString());

            // Select a special in a course view
            selectionMgr.SelectCourseView(Designator(3));
            course       = selectionMgr.CourseLayout;
            courseobject = course[2];
            Assert.IsTrue(courseobject.specialId.id == 3);
            selectionMgr.SelectCourseObject(courseobject);

            CheckSelectedLines(-1, -1);
            selectionInfo = selectionMgr.Selection;
            Assert.AreEqual(SelectionMgr.SelectionKind.Special, selectionInfo.SelectionKind);
            Assert.AreEqual(0, selectionInfo.SelectedControl.id);
            Assert.AreEqual(0, selectionInfo.SelectedCourseControl.id);
            Assert.AreEqual(3, selectionInfo.SelectedSpecial.id);

            selectedObjects = selectionMgr.SelectedCourseObjects;
            Assert.AreEqual(1, selectedObjects.Length);
            Assert.AreEqual(@"Boundary:       special:3  scale:0.6666667  path:N(11,2)--N(0,-7)--N(-12,-3)", selectedObjects[0].ToString());
        }
Exemplo n.º 17
0
        public override void LeftButtonClick(Pane pane, PointF location, float pixelSize, ref bool displayUpdateNeeded)
        {
            // Drop targets are the only think in the All Variations layer we can click on.
            // Also, don't click
            CourseObj clickedObject = HitTest(pane, location, pixelSize,
                                              co => !(co.layer == CourseLayer.AllVariations && !(co is TopologyDropTargetCourseObj)) &&
                                              !((co is MapIssueCourseObj) && co.controlId.IsNone));

            if (clickedObject != null)
            {
                selectionMgr.SelectCourseObject(clickedObject);
            }
            else
            {
                if (pane == Pane.Map)
                {
                    // clicked on nothing. Clear selection.
                    controller.ClearSelection();
                }
            }
        }
Exemplo n.º 18
0
        // Udate the selected course objects in the course.
        void UpdateSelectedCourseObjects()
        {
            if (selectionKind == SelectionKind.None) {
                selectedCourseObjects = null;
                return;
            }

            List<CourseObj> list = new List<CourseObj>();

            // Get through each object in the active course and find which ones match. Ignore stuff in the All Controls layer.
            foreach (CourseObj courseobj in activeCourse) {
                if (courseobj.layer != CourseLayer.AllControls) {
                    if (selectionKind == SelectionKind.Control &&
                            !(courseobj is LineCourseObj) &&    // don't select legs
                            courseobj.controlId == selectedControl &&
                            courseobj.courseControlId == selectedCourseControl) 
                    {
                        list.Add(courseobj);
                    }
                    else if (selectionKind == SelectionKind.Leg &&
                            courseobj is LineCourseObj &&
                            courseobj.courseControlId == selectedCourseControl &&
                            ((LineCourseObj) courseobj).courseControlId2 == selectedCourseControl2) 
                    {
                        // The leg may be made up of multiple parts due to flagging and gaps. Create a single course object for the whole thing.
                        CourseObj legObject = CourseFormatter.CreateSimpleLeg(eventDB, activeCourseView, courseobj.courseObjRatio, courseobj.appearance, selectedCourseControl, selectedCourseControl2);
                        if (legObject != null)
                            list.Add(legObject);
                        break;
                    }
                    else if (selectionKind == SelectionKind.Special &&
                        courseobj.specialId == selectedSpecial) 
                    {
                        list.Add(courseobj);
                    }
                }
            }

            selectedCourseObjects = list.ToArray();
        }
Exemplo n.º 19
0
        public override bool GetToolTip(Pane pane, PointF location, float pixelSize, out string tipText, out string titleText)
        {
            CourseLayout activeCourse;
            CourseView   courseView = selectionMgr.ActiveCourseView;

            if (pane == Pane.Map)
            {
                activeCourse = controller.GetCourseLayout();
            }
            else
            {
                activeCourse = controller.GetTopologyLayout();
            }

            CourseObj touchedObject = null;

            for (CourseLayer layer = CourseLayer.MainCourse; layer <= CourseLayer.AllControls; ++layer)
            {
                if (touchedObject == null)
                {
                    touchedObject = activeCourse.HitTest(location, pixelSize, layer, co => !(co is TopologyDropTargetCourseObj));
                }
            }

            if (touchedObject != null)
            {
                TextPart[] textParts = SelectionDescriber.DescribeCourseObject(symbolDB, eventDB, touchedObject, courseView.ScaleRatio);
                if (textParts != null)
                {
                    ConvertTextPartsToToolTip(textParts, out tipText, out titleText);
                    return(true);
                }
            }

            tipText = titleText = "";
            return(false);
        }
Exemplo n.º 20
0
        // Reduce the scale by 50% and check also.
        internal void CheckHighlightBitmapTiny(CourseObj courseobj, string basename)
        {
            courseobj.scaleRatio *= 0.2F;

            CheckHighlightBitmap(courseobj, basename + "_tiny");
        }
Exemplo n.º 21
0
        // Render to a bitmap and check against the saved version.
        internal void CheckOffsetBitmap(CourseObj courseobj, string basename, Color backColor)
        {
            CourseObj offset = (CourseObj) (courseobj.Clone());
            offset.Offset(-1F, -0.5F);

            Bitmap bmNew = RenderToBitmap(courseobj, backColor);
            Matrix matrix = GetTransform(bmNew.Size);

            using (Graphics g = Graphics.FromImage(bmNew)) {
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
                offset.DrawHighlight(g, matrix);
            }
            TestUtil.CheckBitmapsBase(bmNew, "coursesymbols\\" + basename);
        }
Exemplo n.º 22
0
        // Reduce the scale by 50% and check also.
        internal void CheckOffsetBitmapSmall(CourseObj courseobj, string basename)
        {
            courseobj.scaleRatio *= 0.5F;

            CheckOffsetBitmap(courseobj, basename + "_small");
        }
Exemplo n.º 23
0
 // Render to a bitmap and check against the saved version.
 internal void CheckRenderBitmap(CourseObj courseobj, string basename, Color backColor)
 {
     Bitmap bmNew = RenderToBitmap(courseobj, backColor);
     TestUtil.CheckBitmapsBase(bmNew, "coursesymbols\\" + basename);
 }
Exemplo n.º 24
0
 // Check a course made up of a single object.
 void SingleObjectOffset(CourseObj courseobj, string name, bool checkSmall = true)
 {
     CheckOffsetBitmap(courseobj, name);
     if (checkSmall)
         CheckOffsetBitmapSmall(courseobj, name);
 }
Exemplo n.º 25
0
 // Check a course made up of a single object.
 void SingleObjectHighlight(CourseObj courseobj, string name, bool checkSmall = true)
 {
     CheckHighlightBitmap(courseobj, name);
     if (checkSmall) {
         CheckHighlightBitmapSmall(courseobj, name);
         CheckHighlightBitmapTiny(courseobj, name);
     }
 }
Exemplo n.º 26
0
        // Reduce the scale by 50% and check also.
        internal void CheckRenderBitmapSmall(CourseObj courseobj, string basename, Color backColor)
        {
            courseobj.scaleRatio *= 0.5F;

            CheckRenderBitmap(courseobj, basename + "_small", backColor);
        }
Exemplo n.º 27
0
        // Render one course object to a map.
        internal Map RenderCourseObjToMap(CourseObj courseobj)
        {
            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;

                // Create layout symdef.
                ImageSymDef layoutSymDef = new ImageSymDef(SymLayer.Layout);
                map.AddSymdef(layoutSymDef);
                dict[CourseLayout.KeyLayout] = layoutSymDef;

                SymColor symColor = null;
                SpecialColor specialColor = courseobj.CustomColor ?? SpecialColor.Purple;
                switch (specialColor.Kind) {
                    case SpecialColor.ColorKind.Black:
                        symColor = map.AddColor("Black", 1, 0, 0, 0, 1F, false);
                        break;
                    case SpecialColor.ColorKind.Purple:
                        symColor = map.AddColor("Purple", 11, 0.045F, 0.59F, 0, 0.255F, false);
                        break;
                    case SpecialColor.ColorKind.Custom:
                        CmykColor cmyk = specialColor.CustomColor;
                        symColor = map.AddColor("Custom", 61, cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black, false);
                        break;
                }

                courseobj.AddToMap(map, symColor, dict);

                // Make drop targets visible for debugging.
                foreach (SymDef symdef in map.AllSymdefs) {
                    if (symdef.SymbolId == "781")
                        map.SetSymdefVisible(symdef, true);
                }
            }
            return map;
        }
Exemplo n.º 28
0
 // Render to a bitmap and check against the saved version.
 internal void CheckRenderBitmap(CourseObj courseobj, string basename)
 {
     CheckRenderBitmap(courseobj, basename, Color.White);
 }
Exemplo n.º 29
0
 // Is this course object selectable?
 bool SelectableObject(CourseObj courseObject)
 {
     // All course objects are selectable.
     return(courseObject != null);
 }
Exemplo n.º 30
0
 // validate a course object dump against a string.
 void AssertDump(CourseObj courseobj, string expected)
 {
     Assert.AreEqual(expected, courseobj.ToString());
 }
Exemplo n.º 31
0
 // Update currentObj to reflect dragging to the given location.
 void DragTo(PointF location)
 {
     currentObj = (RectCourseObj)startingObj.Clone();
     currentObj.MoveHandle(handleDragging, location);
 }
Exemplo n.º 32
0
 // Describe a course object, and return an array of TextParts for display in the UI. Return null if nothing useful
 // can be said.
 public static TextPart[] DescribeCourseObject(SymbolDB symbolDB, EventDB eventDB, CourseObj courseObj, float scaleRatio)
 {
     if (courseObj is LineCourseObj && courseObj.courseControlId.IsNotNone && ((LineCourseObj)courseObj).courseControlId2.IsNotNone)
     {
         return(DescribeLeg(eventDB, courseObj.courseControlId, ((LineCourseObj)courseObj).courseControlId2, DescKind.Tooltip));
     }
     else if (courseObj.controlId.IsNotNone)
     {
         return(DescribeControlPoint(symbolDB, eventDB, courseObj.controlId, DescKind.Tooltip));
     }
     else if (courseObj.specialId.IsNotNone)
     {
         return(DescribeSpecial(eventDB, courseObj.specialId, scaleRatio, DescKind.Tooltip));
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 33
0
 public DeleteCornerMode(Controller controller, CourseObj courseObject)
 {
     this.controller   = controller;
     this.courseObject = courseObject;
 }
Exemplo n.º 34
0
        // Render to a bitmap and check against the saved version.
        internal void CheckHighlightBitmap(CourseObj courseobj, string basename)
        {
            Bitmap bmNew = RenderToBitmap(courseobj, Color.White);
            Bitmap bmEraseBrush = (Bitmap) bmNew.Clone();
            Bitmap bmHighlighted = (Bitmap) bmNew.Clone();
            Matrix matrix = GetTransform(bmNew.Size);

            using (Graphics g = Graphics.FromImage(bmHighlighted)) {
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
                courseobj.DrawHighlight(g, matrix);
            }
            Bitmap bmErased = (Bitmap) bmHighlighted.Clone();
            TestUtil.CheckBitmapsBase(bmHighlighted, "coursesymbols\\" + basename);

            using (TextureBrush eraseBrush = new TextureBrush(bmEraseBrush))
            using (Graphics g = Graphics.FromImage(bmErased)) {
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
                courseobj.EraseHighlight(g, matrix, eraseBrush);
            }

            Bitmap bmDiff;
            bmDiff = TestUtil.CompareBitmaps(bmNew, bmErased, Color.LightPink, Color.Transparent, 0);
            if (bmDiff != null)
                bmDiff.Save(TestUtil.GetTestFile("coursesymbols\\" + basename + "_diff.png"), ImageFormat.Png);
            Assert.IsNull(bmDiff, "after erase does not match with before highlight");

            bmEraseBrush.Dispose();
        }
        private void QueryData()
        {
            _attendStudents.Clear();
            //取得學生相關資料
            string sql = "select course.id, ic.term, conduct, case when class.grade_year<=2 then '1-2' when class.grade_year<=4 then '3-4' when class.grade_year<=6 then '5-6' end as grade_year";

            sql += " from $ischool.conduct as ic";
            sql += " left join student on ic.ref_student_id=student.id";
            sql += " left join class on student.ref_class_id = class.id";
            sql += " left join sc_attend on ic.ref_student_id=sc_attend.ref_student_id";
            sql += " left join course on sc_attend.ref_course_id=course.id and ic.school_year=course.school_year and ic.semester=course.semester ";
            sql += " where ic.school_year=" + _schoolYear + " and ic.semester=" + _semester + " and student.status = 1 and ic.subject=course.subject and class.grade_year<=6";
            DataTable dt = _Q.Select(sql);

            foreach (DataRow row in dt.Rows)
            {
                string id        = "" + row["id"];
                string term      = "" + row["term"];
                string gredeyear = "" + row["grade_year"];

                if (string.IsNullOrWhiteSpace(term))
                {
                    term = "2";
                }

                string key = id + "_" + term + "_" + gredeyear;

                //if (!_attendStudents.ContainsKey(key))
                //    _attendStudents.Add(key, 0);

                //_attendStudents[key]++;

                bool allFinished = true;
                try
                {
                    System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                    doc.LoadXml("" + row["conduct"]);
                    foreach (System.Xml.XmlElement item in doc.SelectNodes("Conducts/Conduct/Item"))
                    {
                        if (item.GetAttribute("Grade") == "")
                        {
                            allFinished = false;
                        }
                    }
                }
                catch
                {
                    allFinished = false;
                }
                if (allFinished)
                {
                    if (!_attendStudents.ContainsKey(key))
                    {
                        _attendStudents.Add(key, 0);
                    }
                    _attendStudents[key]++;
                }
            }

            _courses.Clear();
            //取得課程相關資料
            sql  = "select course.id,course.course_name,ice.grade_year,case when class.grade_year<=2 then '1-2' when class.grade_year<=4 then '3-4' when class.grade_year<=6 then '5-6' end as sgrade_year,case when cclass.ref_teacher_id = tc_instruct.ref_teacher_id then 'hr' else 'sbj' end as type,count(student.id) from course ";
            sql += "left join sc_attend on sc_attend.ref_course_id=course.id ";
            sql += "left join student on sc_attend.ref_student_id=student.id ";
            sql += "left join class on student.ref_class_id = class.id ";
            sql += "left join class as cclass on course.ref_class_id = cclass.id ";
            sql += "left join $ischool.course.extend as ice on ice.ref_course_id=course.id ";
            sql += "left join tc_instruct on tc_instruct.ref_course_id = course.id and tc_instruct.sequence = 1 ";
            sql += "where course.school_year=" + _schoolYear + " and course.semester=" + _semester + " and student.status = 1 and class.grade_year<=6 and ice.grade_year<=6";
            sql += " group by course.id,course.course_name,ice.grade_year,tc_instruct.ref_teacher_id,cclass.ref_teacher_id,sgrade_year";
            dt   = _Q.Select(sql);
            foreach (DataRow row in dt.Rows)
            {
                CourseObj co = new CourseObj(row);
                co.TeacherName = _teacherName.ContainsKey(co.ID) ? _teacherName[co.ID] : "";
                _courses.Add(co);
            }

            //排序
            _courses.Sort(delegate(CourseObj x, CourseObj y)
            {
                string xx = (x.GradeYear + "").PadLeft(3, '0');
                xx       += x.Name.PadLeft(50, '0');
                xx       += x.SGradeYear.PadLeft(3, '0');
                string yy = (y.GradeYear + "").PadLeft(3, '0');
                yy       += y.Name.PadLeft(50, '0');
                yy       += y.SGradeYear.PadLeft(3, '0');
                return(xx.CompareTo(yy));
            });
        }
Exemplo n.º 36
0
        // Render a course to a bitmap for testing purposes.
        internal Bitmap RenderToBitmap(CourseObj courseobj, Color backColor)
        {
            Map map = RenderCourseObjToMap(courseobj);

            Bitmap bm = new Bitmap(250, 250);
            using (Graphics g = Graphics.FromImage(bm)) {
                RenderOptions options = new RenderOptions();

                options.usePatternBitmaps = true;
                options.minResolution = (float) (8.0 / bm.Width);
                options.renderTemplates = RenderTemplateOption.MapAndTemplates;

                g.MultiplyTransform(GetTransform(bm.Size));

                g.Clear(backColor);
                using (map.Read())
                    map.Draw(new GDIPlus_GraphicsTarget(g), new RectangleF(-100F, -100F, 200F, 200F), options, null);
                DrawGrid(g, new RectangleF(-4.0F, -4.0F, 8.0F, 8.0F), 1.0F);
            }

            return bm;
        }