Exemplo n.º 1
0
        /// <summary>
        ///     Prompts a user to place the current tag.
        /// </summary>
        public void Place()
        {
            if (!Application.IsConnected)
                throw SprExceptions.SprNotConnected;

            if (IsPlaced)
                throw new SprException("Tag {0} is already placed", Id);

            var tagOrigin = new SprPoint3D();

            // Get an object on screen and set the origin point to its location
            Application.HighlightClear();
            var objId = Application.GetObjectId("SELECT TAG START POINT", ref tagOrigin);
            if (objId == 0)
            {
                Application.Windows.TextWindow.Text = "Tag placement canceled.";
                return;
            }

            // Highlight the selected object
            Application.HighlightObject(objId, Color.Fuchsia);

            // Get the tag leader point using the origin for depth
            var tagLeader = Application.GetPoint("SELECT TAG LEADER LOCATION", tagOrigin);
            if (tagLeader == null)
            {
                Application.HighlightClear();
                Application.Windows.TextWindow.Text = "Tag placement canceled.";
                return;
            }

            _linkedObject = Application.GetObjectData(objId);

            Flags |= SprConstants.SprTagLabel;
            Id = Application.NextTag;

            // Set the tag registry values
            SprUtilities.SetTagRegistry(this);

            // Place the tag
            Application.SprStatus = Application.DrApi.TagSetDbl(Id, 0, Flags, ref tagLeader.DrPointDbl,
                                            ref tagOrigin.DrPointDbl, LinkedObject.Linkage.DrKey, Text);
            if (Application.SprStatus != 0)
                throw Application.SprException;

            //IsPlaced = true;
            _leaderPoint = tagLeader;
            _originPoint = tagOrigin;

            Application.Tags.Add(this);
            Refresh();

            // Clear the tag registry
            SprUtilities.ClearTagRegistry();

            SendToTextWindow();

            Application.HighlightClear();
            Application.SprStatus = Application.DrApi.ViewUpdate(1);
            if (Application.SprStatus != 0)
                throw Application.SprException;
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Uses an Object Id to retrieve detailed object information.
        /// </summary>
        /// <param name="objectId">The ObjectId that is looked up inside SmartPlant Review.</param>
        /// <returns>SprObjectData object containing the retrieved information.</returns>
        public SprObject GetObjectData(int objectId)
        {
            if (!IsConnected)
                throw SprExceptions.SprNotConnected;

            if (objectId == 0)
                return null;

            var returnData = new SprObject {Id = objectId};

            // Get the DataDbl object
            SprStatus = DrApi.ObjectDataGetDbl(objectId, 2, ref returnData.DrObjectDataDbl);
            if (SprStatus != 0)
                throw SprException;

            // Iterate through the labels
            string lblName = string.Empty, lblValue = string.Empty;
            for (var i = 0; i < returnData.DrObjectDataDbl.LabelDataCount; i++)
            {
                SprStatus = DrApi.ObjectDataLabelGet(ref lblName, ref lblValue, i);
                if (SprStatus != 0)
                    throw SprException;

                var trimmedName = lblName.TrimEnd(':');
                if (!returnData.Labels.ContainsKey(trimmedName))
                    returnData.Labels.Add(trimmedName, lblValue);
            }
            return returnData;
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Prompts a user to select new leader points for an existing tag.
        ///     DisplayLeader will automatically be set to true.
        /// </summary>
        public void EditLeader()
        {
            if (!Application.IsConnected)
                throw SprExceptions.SprNotConnected;

            if (!IsPlaced)
                throw new SprException("Tag {0} is not placed.", Id);

            var tagOrigin = new SprPoint3D();

            // Get an object on screen and set the origin point to its location
            Application.HighlightClear();
            var objId = Application.GetObjectId("SELECT NEW TAG START POINT", ref tagOrigin);
            if (objId == 0)
            {
                Application.Windows.TextWindow.Text = "Tag placement canceled.";
                return;
            }

            // Highlight the selected object
            Application.HighlightObject(objId, Color.Fuchsia);

            // Get the tag leader point on screen
            var tagLeader = Application.GetPoint("SELECT NEW LEADER LOCATION", tagOrigin);
            if (tagLeader == null)
            {
                Application.HighlightClear();
                Application.Windows.TextWindow.Text = "Tag placement canceled.";
                return;
            }

            _linkedObject = Application.GetObjectData(objId);

            DisplayLeader = true;
            Flags |= SprConstants.SprTagLabel;
            Flags |= SprConstants.SprTagEdit;

            // Update the tag with the new leader points
            Application.SprStatus = Application.DrApi.TagSetDbl(Id, 0, Flags, tagLeader.DrPointDbl,
                                                tagOrigin.DrPointDbl, LinkedObject.Linkage.DrKey, Text);
            if (Application.SprStatus != 0)
                throw Application.SprException;

            Refresh();

            // Flip the tag 180 degrees.  Intergraph is AWESOME!
            var swap = LeaderPoint;
            LeaderPoint = OriginPoint;
            OriginPoint = swap;

            Update();

            SendToTextWindow();
            Application.HighlightClear();

            Application.SprStatus = Application.DrApi.ViewUpdate(1);
            if (Application.SprStatus != 0)
                throw Application.SprException;
        }