Exemplo n.º 1
0
        // big place: 0 - small, 5 - must have
        public virtual void placeLabel(int bigPlace, int fontSize, bool isAdjusting)
        {
            //LibSys.StatusBar.Trace("LiveObject::placeLabel(" + bigPlace + "," + fontSize + ")");
            m_font = Project.getLabelFont(fontSize);

            Graphics g = m_map.getGraphics();

            if (g == null)
            {
                LibSys.StatusBar.Trace("Graphics null in LiveObject::placeLabel()");
                return;
            }
            // other threads can throw "invalid argument" exception in g.MeasureString:
            recalcLabelMetrics(Name, g);

            // Now try to place the label so that it does not intersect with
            // any other label (or at least minimize intersections)
            int jmin = 100000;
            int imin = 0;

            m_labelPosition = 0;
            Rectangle frame = m_map.getFrameRectangle(m_itile);

            for (int i = 0; i < N_LABEL_POSITIONS; i++, nextLabelPosition())
            {
                labelBoundingRect();
                Rectangle lbr = intersectionSensitiveRect();
                // first check if label in this position will be clipped by frame:
                Rectangle tmp = new Rectangle(frame.X, frame.Y, frame.Width, frame.Height);
                tmp.Intersect(lbr);
                if (!lbr.Equals(tmp))
                {
                    //LibSys.StatusBar.Trace("pos=" + m_labelPosition + "  clipped by frame");
                    continue;
                }
                // now count intersections with other labels:
                int j = m_map.countIntersections(m_olm, this, lbr);
                if (j == 0)
                {                       // no intersections; we better pick this choice.
                    imin = i;
                    jmin = 0;
                    break;
                }
                if (j < jmin)
                {                       // minimal intersections is our goal
                    jmin = j;
                    imin = i;
                }
            }
            m_labelPosition = imin;
            m_intersections = jmin;
            if (jmin > MAX_INTERSECTIONS)
            {                   // bad luck - there are too many
                                // places already there
                if (bigPlace < 4 && !isAdjusting && jmin > ((bigPlace + 1) * MAX_BIGCITY_INTERSECTIONS_FACTOR))
                {
                    m_doName = false;
                    boundingRect();
                    //LibSys.StatusBar.Trace("Name omited, intersections=" + jmin + "  Place=" + Name);
                }
            }
        }