Exemple #1
0
        public override void Stop()
        {
            if (myPolygon != null)
            {
                myPolygon.Remove();
                if (PolygonCreatedWithPoints != null)
                {
                    PolygonCreatedWithPoints(myPolygon.GetPointString());
                }
                myPolygon = null;
            }

            this.View.Cursor = previous;
        }
Exemple #2
0
        public override void DoMouseDown()
        {
            if (myPolygon == null)
            {
                myPolygon = new DiagramPolygon(this.View);
                myPolygon.Style = GoPolygonStyle.Line;
                myPolygon.Brush = Brushes.LightBlue;

                myPolygon.AddPoint(this.LastInput.DocPoint);
                myPolygon.AddPoint(this.LastInput.DocPoint); // pivot point
                this.View.Layers.Default.Add(myPolygon);
            }
            else
            {
                myPolygon.AddPoint(this.LastInput.DocPoint);
            }
        }
Exemple #3
0
        private void CreateNode(XPathNavigator nodeNav, Dictionary<int, DiagramNode> docNodes, ref int startX, ref int startY)
        {
            // base data
            int nodeID = Int32.Parse(nodeNav.GetAttribute(IDAttribute, nodeNav.NamespaceURI));
            String nodeType = nodeNav.GetAttribute(TypeAttribute, nodeNav.NamespaceURI);
            String nodeName = nodeNav.GetAttribute(NameAttribute, nodeNav.NamespaceURI);

            String linkString = nodeNav.GetAttribute(LinkIDAttribute, nodeNav.NamespaceURI);
            int linkID;

            if (linkString.Length > 0)
            {

                linkID = Int32.Parse(linkString);
            }
            else
            {
                linkID = -1;
            }

            // Trim names
            nodeName = nodeName.Trim();

            List<Function> nodeFunctions = FunctionHelper.GetFunctions(nodeNav);

            List<ParsedFunction> parsedFunctions = FunctionHelper.ParseFunctions(nodeFunctions);

            // X and Y that are passed in are 'default' x if no Point exists in the file OR in the DB
            // starts at 20, 20 

            //start
            Dictionary<String, String> parameterMap = new Dictionary<String, String>();
           
            XPathNodeIterator parameters = nodeNav.Select(categories);

            String name, category, value;
            while (parameters.MoveNext())
            {
                category = parameters.Current.GetAttribute(categoryAttr, String.Empty);
                if (category.Equals(categoryImage) || category.EndsWith(categoryLocation) || category.Equals(categoryColor))
                {
                    name = parameters.Current.GetAttribute(displayedNameAttr, String.Empty);
                    value = parameters.Current.GetAttribute(ConfigFileConstants.Value, String.Empty);
                    parameterMap.Add(String.Concat(category, SchemaConstants.ParameterDelimiter, name), value);
                }
            }
            //end

            Boolean xyFromDB = false;

            // first do the MoveAction and replace XY with DB XY if it exists
            ParsedFunction moveActionDBInsert = parsedFunctions.Find(delegate(ParsedFunction pf) { return pf.FunctionName == "MoveAction" && pf.ActionIdentifier == "InsertXYIntoDB"; });
            if (moveActionDBInsert != null)
            {
                List<String> moveActionValues = moveActionDBInsert.ActionValues;

                if (moveActionValues.Count >= 2)
                {
                    String x = parameterMap[moveActionValues[0]];
                    String y = parameterMap[moveActionValues[1]];

                    startX = (int)float.Parse(x);
                    startY = (int)float.Parse(y);

                    xyFromDB = true;
                }
            }

            ParsedFunction vrPF = parsedFunctions.Find(delegate(ParsedFunction pf) { return pf.FunctionName == "VisualRepresentation"; });

            if (vrPF != null)
            {
                String functionName = vrPF.FunctionName;
                String actionIdentifier = vrPF.ActionIdentifier;
                List<string>  actionValues = vrPF.ActionValues;

                String imagePath = String.Empty;

                switch (actionIdentifier)
                {
                    case "Image":      // parse [email protected] File         
                        if (actionValues.Count >= 1)
                        {
                            String paramValueForImage = parameterMap[actionValues[0]];

                            try
                            {
                                imagePath = FunctionHelper.UpdateImageList(this.Controller, globalIL, paramValueForImage, true);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, "Image Load");
                                // use type
                                imagePath = nodeType;
                            }

                            LoadNode(nodeID, linkID, nodeName, nodeType, nodeFunctions, imagePath, xyFromDB, ref startX, ref startY, docNodes);
                        }
                        break;

                    case "Polygon":              // parse [email protected] Points
                        // param name should have three parameters - poly points, color, alpha
                        if (actionValues.Count >= 3)
                        {
                            String polyPoints = parameterMap[actionValues[0]];
                            String polyColor = parameterMap[actionValues[1]];
                            String alpha = parameterMap[actionValues[2]];

                            DiagramPolygon polygon = new DiagramPolygon(this, nodeID, linkID, nodeName, nodeType, actionValues[0]);
                            polygon.Style = GoPolygonStyle.Line;

                            if (polyColor.Length > 0)
                            {
                                try
                                {
                                    ColorConverter convertFromString = new ColorConverter();

                                    Color convert = (Color)convertFromString.ConvertFrom(polyColor);

                                    byte alphaByte = 255;

                                    if (alpha.Length > 0)
                                    {
                                        alphaByte = Byte.Parse(alpha);
                                    }

                                    convert = Color.FromArgb(alphaByte, convert);
                                    if (FillPolygon)
                                    {
                                        polygon.Brush = new SolidBrush(convert);
                                    }

                                    if (OutlinePolygon)
                                    {
                                        polygon.Pen = new Pen(convert, 2.0f);
                                    }
                                }
                                catch (FormatException fex)
                                {
                                    MessageBox.Show("Could not convert color", fex.Message);
                                }
                            }
                            polygon.Functions = nodeFunctions;

                            try
                            {
                                // this will throw an exception if an invalid string is used
                                List<PointF> polygonPoints = FunctionHelper.ParsePolygonString(polyPoints, nodeType, m_coordinateTransformer);

                                foreach (PointF polyPoint in polygonPoints)
                                {
                                    polygon.AddPoint(polyPoint);
                                }
                            }
                            catch (Exception e)
                            {
                                MessageBox.Show("Invalid format for vertex list", e.Message);
                            }

                            if (polygon.PointsCount > 0)
                            {
                                this.Document.Add(polygon);
                            }
                        }
                        break;
                    default:
                        {
                            // The visual representation is not recognized  - try external code
    
                            Type type = AMEManager.GetType(actionIdentifier);
    
                            if (type != null)
                            {
                /*
                 * (Diagram dg, List<String> actionValues, XPathNavigator nodeNav, Dictionary<String, Bitmap> nodeImages,
                                int nodeID, int linkID, String nodeName, String nodeType, List<Function> nodeFunctions, 
                                    bool xyFromDB, ref int startX, ref int startY, Dictionary<int, DiagramNode> docNodes)
                 */
                                try
                                {
                                    Activator.CreateInstance(type, new object[] {this, actionValues, nodeNav, globalIL, nodeID, 
                                    linkID, nodeName, nodeType, nodeFunctions, xyFromDB, startX, startY, docNodes});
                                }
                                catch (Exception e)
                                {
                                    MessageBox.Show(e.Message);
                                }
                            }
                            break;
                        }
                } // switch
            }// if 
            else // no VR function, use type as default image
            {
                LoadNode(nodeID, linkID, nodeName, nodeType, nodeFunctions, xyFromDB, ref startX, ref startY, docNodes);
            }
        }