Example #1
0
        /// <summary>
        /// Displays database attributes so that they can be edited by the user.
        /// </summary>
        /// <param name="r">The row of interest</param>
        /// <returns>True if any changes were saved to the database</returns>
        internal static bool Update(Row r)
        {
            // If the row is associated with any RowText, ensure it is removed from
            // the spatial index NOW (if we wait until the edit has been completed,
            // it's possible we won't be able to update the index properly)
            TextFeature[] text      = r.Id.GetRowText();
            EditingIndex  index     = CadastralMapModel.Current.EditingIndex;
            bool          isChanged = false;

            try
            {
                // Remove the text from the spatial index (but see comment below)
                foreach (TextFeature tf in text)
                {
                    index.RemoveFeature(tf);
                }

                // Display the attribute entry dialog
                AttributeDataForm dial = new AttributeDataForm(r.Table, r.Data);
                isChanged = (dial.ShowDialog() == DialogResult.OK);
                dial.Dispose();

                if (isChanged)
                {
                    IDataServer ds = EditingController.Current.DataServer;
                    if (ds == null)
                    {
                        throw new InvalidOperationException("No database available");
                    }

                    ds.SaveRow(r.Data);
                }
            }

            finally
            {
                // Ensure text has been re-indexed... actually, this is likely to be
                // redundant, because nothing here has actually altered the stored
                // width and height of the text (if the attributes have become more
                // verbose, they'll just be scrunched up a bit tighter). The text
                // metrics probably should be reworked (kind of like AutoSize for
                // Windows labels), but I'm not sure whether this demands a formal
                // editing operation.

                foreach (TextFeature tf in text)
                {
                    index.AddFeature(tf);
                }

                // Re-display the text if any changes have been saved
                if (isChanged)
                {
                    ISpatialDisplay display = EditingController.Current.ActiveDisplay;
                    display.Redraw();
                }
            }

            return(isChanged);
        }
Example #2
0
        /// <summary>
        /// Creates a new polygon label in the map.
        /// </summary>
        /// <param name="posn">Reference position for the label.</param>
        /// <returns>The text feature that was added.</returns>
        internal override TextFeature AddNewLabel(IPosition posn)
        {
            Debug.Assert(m_Polygon != null);
            CadastralMapModel map      = CadastralMapModel.Current;
            TextFeature       newLabel = null;

            // Confirm that the polygon ID has been reserved.
            if (!m_PolygonId.IsReserved)
            {
                MessageBox.Show("NewLabelUI.AddNewLabel - No polygon ID");
                return(null);
            }

            /*
             * // Check whether another label exists in the specified
             * // polygon, but on a layer that is derived from the current
             * // editing layer. If so, note the entity type and free the
             * // supplied ID.
             *
             * // SS20080421 - This bit of code was used to check whether the polygon
             * // was already labelled on a derived layer, in which case the ID would
             * // be promoted to the current layer. However, it's difficult to continue
             * // with that logic, since the polygon object is no longer shared with
             * // any other layer (and won't even exist unless you switch to another
             * // editing layer). Even if the structure was unchanged, I'm not convinced
             * // that it's good to define the ID on the basis of something that the user
             * // can't actually see (if this were to be done, the user should have been
             * // told already, since an explicitly specified ID would be disregarded here).
             *
             *  CeLabel* pOldLabel = m_pPolygon->GetBaseLabel();
             *  const CeEntity* pEnt=0;
             *
             *  if ( pOldLabel ) {
             *          pEnt = m_PolygonId.GetpEntity();
             *          m_PolygonId.FreeId();
             *  }
             */

            // Execute the edit
            NewTextOperation txop = null;

            try
            {
                if (m_Template != null && m_LastRow != null)
                {
                    // Save the attributes in the database
                    IDataServer ds = EditingController.Current.DataServer;
                    if (ds == null)
                    {
                        throw new InvalidOperationException("No database available");
                    }

                    ds.SaveRow(m_LastRow);

                    NewRowTextOperation op = new NewRowTextOperation();
                    txop = op;
                    op.Execute(posn, m_PolygonId, m_LastRow, m_Template, m_Polygon, Height, Width, Rotation);

                    // Confirm that the row got cross-referenced to an ID (not
                    // sure what the above ends up doing).
                    //if (m_LastRow.GetpId()==null)
                    //{
                    //    MessageBox.Show("Attributes were not attached to an ID");
                    //    return null;
                    //}
                }
                else
                {
                    NewKeyTextOperation op = new NewKeyTextOperation();
                    txop = op;
                    op.Execute(posn, m_PolygonId, m_Polygon, Height, Width, Rotation);
                }

                newLabel = txop.Text;
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace, ex.Message);
            }

            return(newLabel);
        }