Beispiel #1
0
        /// <summary>
        /// Implementation of the marker event logic.
        /// </summary>
        /// <param name="app">Visio application.</param>
        /// <param name="sequenceNum">Sequence number.</param>
        /// <param name="contextString">Context string, as defined in shape.</param>
        private void Application_MarkerEventDo(Visio.Application app, int sequenceNum, string contextString)
        {
            /*
             *
             */
            if (_initializedOk == false)
            {
                return;
            }

            if (contextString == null)
            {
                return;
            }

            if (contextString.Contains("/au=1") == false)
            {
                return;
            }


            /*
             * Don't process any marker events that are being fired as a result
             * of a redo.
             */
            if (this.Application.IsUndoingOrRedoing == true)
            {
                return;
            }



            /*
             *
             */
            Dictionary <string, string> ctx = VU.ParseContext(contextString);

            if (ctx.ContainsKey("cmd") == false)
            {
                return;
            }


            /*
             *
             */
            Visio.Shape shape = VU.GetShape(app, ctx);

            if (shape == null)
            {
                return;
            }

            string modelName = VU.GetProperty(shape, "User", "ModelName");
            string shapeName = VU.GetProperty(shape, "User", "ModelShape");

            if (string.IsNullOrEmpty(modelName) == true ||
                string.IsNullOrEmpty(shapeName) == true)
            {
                return;
            }


            /*
             * Model
             */
            IModelDefinition model;

            try
            {
                model = ModelCache.Load(modelName);
            }
            catch (Exception ex)
            {
                ExceptionMessageBox.Show("Model failed to load.", ex);
                return;
            }

            if (model == null)
            {
                ExceptionMessageBox.Show($"Model '{ modelName }' not found.");
                return;
            }



            /*
             *
             */
            IShapeDefinition shapeDef = model.Shapes.Where(x => x.Name == shapeName).FirstOrDefault();

            if (shapeDef == null)
            {
                ExceptionMessageBox.Show($"No shape definition for '{ shapeName }' found.");
                return;
            }


            /*
             * Drop command
             */
            if (ctx["cmd"] == "drop")
            {
                /*
                 * .Id
                 */
                string shapeId = Guid.NewGuid().ToString();
                VU.SetProperty(shape, "Prop", "ShapeId", shapeId);


                /*
                 * .Code
                 */
                string shapeCode = null;

                if (string.IsNullOrEmpty(shapeDef.ShapeCodePrefix) == false)
                {
                    int sequence = PageIncrementSequence(shape, shapeDef.ShapeCodePrefix);
                    shapeCode = string.Format(CultureInfo.InvariantCulture, shapeDef.ShapeCodeFormat, shapeDef.ShapeCodePrefix, sequence);

                    VU.SetProperty(shape, "Prop", "ShapeCode", shapeCode);
                }


                /*
                 * .Text
                 */
                string shapeXml  = VU.GetProperty(shape, "Prop", "ShapeXml");
                string shapeText = shapeDef.TextGet(shapeCode, shapeXml);

                if (string.IsNullOrEmpty(shapeText) == false)
                {
                    VU.TextSet(shape, shapeText);
                }
            }


            /*
             *
             */
            if (ctx["cmd"] == "edit")
            {
                string mode      = "analysis"; //_toolbar.CurrentMode;
                string shapeCode = VU.GetProperty(shape, "Prop", "ShapeCode");
                string shapeXml  = VU.GetProperty(shape, "Prop", "ShapeXml");

                XmlForm form = new XmlForm();
                form.Initialize(shapeDef, mode, shapeCode, shapeXml);

                DialogResult result = form.ShowDialog();

                if (result == DialogResult.OK)
                {
                    VU.SetProperty(shape, "Prop", "ShapeXml", form.ShapeXml);
                    VU.ShapeColorSet(shape, Visio.VisDefaultColors.visBlack);

                    string shapeText = shapeDef.TextGet(shapeCode, form.ShapeXml);

                    if (string.IsNullOrEmpty(shapeText) == false)
                    {
                        VU.TextSet(shape, shapeText);
                    }
                }
            }
        }