static public ShapeTemplate GetShapeTemplate(GraphicStencil stencil) { int i; if (stencil != null) { ElementTemplate[] elementTemplate = new ElementTemplate[stencil.Elements.Count]; i = 0; foreach (Element element in stencil.Elements) { elementTemplate[i] = Element(element); i++; } ElementTemplate[] decorationTemplate = new ElementTemplate[stencil.Decorations.Count]; i = 0; foreach (Element decoration in stencil.Decorations) { decorationTemplate[i] = Element(decoration); i++; } return (new ShapeTemplate(elementTemplate, decorationTemplate, null, stencil.fillMode, stencil.Tag)); } else return null; }
public void GetObjectData(Object obj, SerializationInfo info, StreamingContext context) { GraphicStencil graphicStencil = (GraphicStencil)obj; info.AddValue("defaultSize", graphicStencil.DefaultSize); info.AddValue("anchors", graphicStencil.Anchors); info.AddValue("decorations", graphicStencil.Decorations); info.AddValue("elements", graphicStencil.Elements); info.AddValue("tags", graphicStencil.Tags); info.AddValue("tagArea", graphicStencil.TagArea); }
public static void Serialize(string path, GraphicStencil graphicStencil) { SoapFormatter sf = new SoapFormatter(); StreamWriter streamWriter = new StreamWriter(path); Stream stream = streamWriter.BaseStream; SurrogateSelector ss = new SurrogateSelector(); ss.AddSurrogate(typeof(GraphicStencil), new StreamingContext(StreamingContextStates.All), new GraphicStencilSerializationSurrogate()); sf.SurrogateSelector = ss; sf.Serialize(stream, graphicStencil); stream.Close(); }
public object SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) { GraphicStencil graphicStencil = (GraphicStencil)obj; graphicStencil.DefaultSize = (Size)info.GetValue("defaultSize", typeof(Size)); try { graphicStencil.Anchors = (ArrayList)info.GetValue("anchors", typeof(ArrayList)); } catch { graphicStencil.Anchors = new ArrayList(); } graphicStencil.Decorations = (ArrayList)info.GetValue("decorations", typeof(ArrayList)); graphicStencil.Elements = (ArrayList)info.GetValue("elements", typeof(ArrayList)); graphicStencil.Tags = (ArrayList)info.GetValue("tags", typeof(ArrayList)); graphicStencil.TagArea = (Rectangle)info.GetValue("tagArea", typeof(Rectangle)); return(graphicStencil); }
public void Setup(string stencilPath, Config.AddProjectHandler addProject, Config.AddProjectAnywayHandler addProjectAnyway) { this.addProject = addProject; this.addProjectAnyway = addProjectAnyway; { //int iStencil = 0; //LogNote("Srvr : 0 : ModelStencils:"); String[] files = Directory.GetFiles(stencilPath, "*.modelstencil"); for (int i = 0; i < files.GetLength(0); i++) { String fullpath = files[i]; //try //{ ModelStencil modelStencil = ModelStencil.Deserialize(fullpath); if (ConfirmModelStencil(modelStencil)) { TrimAnchorPoints(modelStencil); ModelStencils.Add(modelStencil.Tag, modelStencil); } //Console.WriteLine(" {0}] {1}", iStencil++, Path.GetFileNameWithoutExtension(fullpath)); //LogNote("Srvr : 0 : " + iStencil++ + " : " + System.IO.Path.GetFileNameWithoutExtension(fullpath)); //} //catch (Exception) //{ // int asdf = 0; // //Message("Error '" + e.Message + "' loading ModelStencil: " + fullpath, MessageType.Error); //} } Console.WriteLine("\n"); } { //int iStencil = 0; //LogNote("Srvr : 0 : GraphicStencils:"); String[] files = Directory.GetFiles(stencilPath, "*.graphicstencil"); for (int i = 0; i < files.GetLength(0); i++) { String fullpath = files[i]; //try //{ GraphicStencil graphicStencil = GraphicStencil.Deserialize(fullpath); foreach (String tag in graphicStencil.Tags) { GraphicStencils.Add(tag, graphicStencil); } //} //catch //{ // int adsf = 0; // //logNote("Config : Error loading GraphicStencil " + fullpath); //} } } }
private void UpdateStencil(GraphicStencil graphicStencil) { double minX = double.MaxValue; double maxX = double.MinValue; double minY = double.MaxValue; double maxY = double.MinValue; UpdateStencil(graphicStencil.Elements, ref minX, ref minY, ref maxX, ref maxY); UpdateStencil(graphicStencil.Decorations, ref minX, ref minY, ref maxX, ref maxY); double textMinX = double.MaxValue; double textMaxX = double.MinValue; double textMinY = double.MaxValue; double textMaxY = double.MinValue; UpdateStencil(graphicStencil.TagArea, ref textMinX, ref textMinY, ref textMaxX, ref textMaxY); ScaleStencil(graphicStencil.Elements, minX, minY, maxX, maxY); ScaleStencil(graphicStencil.Decorations, minX, minY, maxX, maxY); double scale = 1000.0 / Math.Max((maxX - minX), (maxY - minY)); SysCAD.Protocol.Rectangle rect = new SysCAD.Protocol.Rectangle(minX * scale, minY * scale, (maxX - minX) * scale, (maxY - minY) * scale); graphicStencil.defaultSize = new SysCAD.Protocol.Size((maxX - minX), (maxY - minY)); box1.BoundingRect = rect; { GraphicStencil stencil = graphicStencil; bool mirrorX = false; bool mirrorY = false; ElementTemplate[] elementTemplate = new ElementTemplate[stencil.Elements.Count]; { int i = 0; foreach (Element element in stencil.Elements) { if (element is Arc) { elementTemplate[i] = new ArcTemplate( (float)(element as Arc).x, (float)(element as Arc).y, (float)(element as Arc).w, (float)(element as Arc).h, (float)(element as Arc).a, (float)(element as Arc).s); } if (element is Line) { Line line = element as Line; double x1, y1, x2, y2; if (mirrorX) x1 = 100.0 - line.x1; else x1 = line.x1; if (mirrorY) y1 = 100.0 - line.y1; else y1 = line.y1; if (mirrorX) x2 = 100.0 - line.x2; else x2 = line.x2; if (mirrorY) y2 = 100.0 - line.y2; else y2 = line.y2; elementTemplate[i] = new LineTemplate((float)x1, (float)y1, (float)x2, (float)y2); } if (element is Bezier) { Bezier bezier = element as Bezier; double x1, y1, x2, y2, x3, y3, x4, y4; if (mirrorX) x1 = 100.0 - bezier.x1; else x1 = bezier.x1; if (mirrorY) y1 = 100.0 - bezier.y1; else y1 = bezier.y1; if (mirrorX) x2 = 100.0 - bezier.x2; else x2 = bezier.x2; if (mirrorY) y2 = 100.0 - bezier.y2; else y2 = bezier.y2; if (mirrorX) x3 = 100.0 - bezier.x3; else x3 = bezier.x3; if (mirrorY) y3 = 100.0 - bezier.y3; else y3 = bezier.y3; if (mirrorX) x4 = 100.0 - bezier.x4; else x4 = bezier.x4; if (mirrorY) y4 = 100.0 - bezier.y4; else y4 = bezier.y4; elementTemplate[i] = new BezierTemplate((float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3, (float)x4, (float)y4); } i++; } } ElementTemplate[] decorationTemplate = new ElementTemplate[stencil.Decorations.Count]; { int i = 0; foreach (Element decoration in stencil.Decorations) { if (decoration is Arc) { decorationTemplate[i] = new ArcTemplate( (float)(decoration as Arc).x, (float)(decoration as Arc).y, (float)(decoration as Arc).w, (float)(decoration as Arc).h, (float)(decoration as Arc).a, (float)(decoration as Arc).s); } if (decoration is Line) { decorationTemplate[i] = new LineTemplate( (float)(decoration as Line).x1, (float)(decoration as Line).y1, (float)(decoration as Line).x2, (float)(decoration as Line).y2); } if (decoration is Bezier) { decorationTemplate[i] = new BezierTemplate( (float)(decoration as Bezier).x1, (float)(decoration as Bezier).y1, (float)(decoration as Bezier).x2, (float)(decoration as Bezier).y2, (float)(decoration as Bezier).x3, (float)(decoration as Bezier).y3, (float)(decoration as Bezier).x4, (float)(decoration as Bezier).y4); } i++; } } box1.Shape = (new ShapeTemplate(elementTemplate, decorationTemplate, new ElementTemplate[0], stencil.fillMode, stencil.Tag)); } SysCAD.Protocol.Rectangle textRect = new SysCAD.Protocol.Rectangle(textMinX * scale, textMinY * scale, (textMaxX - textMinX) * scale, (textMaxY - textMinY) * scale); textBox1.BoundingRect = textRect; //textBox1.Shape = graphicStencil.TextShapeTemplate(false, false); textBox1.ZTop(); textBox1.FillColor = Color.FromArgb(100, Color.HotPink); double bothMinX = Math.Min(minX, textMinX); double bothMaxX = Math.Max(maxX, textMaxX); double bothMinY = Math.Min(minY, textMinY); double bothMaxY = Math.Max(maxY, textMaxY); SysCAD.Protocol.Rectangle bothRect = new SysCAD.Protocol.Rectangle(bothMinX * scale, bothMinY * scale, (bothMaxX - bothMinX) * scale, (bothMaxY - bothMinY) * scale); bothRect.Inflate((maxX - minX) * scale / 10.0F, (maxY - minY) * scale / 10.0F); flowChart1.DocExtents = bothRect; flowChart1.ZoomToRect(bothRect); }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.AddExtension = true; openFileDialog.CheckFileExists = true; openFileDialog.CheckPathExists = true; openFileDialog.DefaultExt = "GraphicStencil"; openFileDialog.DereferenceLinks = true; openFileDialog.Filter = "Graphic Stencil|*.GraphicStencil|Model Stencil|*.ModelStencil"; openFileDialog.Multiselect = false; openFileDialog.ValidateNames = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { string baseName = openFileDialog.FileName; baseName = baseName.Replace(".GraphicStencil", ""); baseName = baseName.Replace(".ModelStencil", ""); baseName = baseName.Replace(".graphicstencil", ""); baseName = baseName.Replace(".modelstencil", ""); Text = baseName; filename = baseName; this.elementTextBox.TextChanged -= new System.EventHandler(this.textBox_TextChanged); this.decorationTextBox.TextChanged -= new System.EventHandler(this.textBox_TextChanged); this.tagAreaTextBox.TextChanged -= new System.EventHandler(this.textBox_TextChanged); this.anchorTextBox.TextChanged -= new System.EventHandler(this.textBox_TextChanged); toolStripComboBoxModelGroup.Text = ""; elementTextBox.Text = ""; decorationTextBox.Text = ""; tagAreaTextBox.Text = ""; { SoapFormatter sf; Stream stream = null; sf = new SoapFormatter(); stream = new StreamReader(baseName + ".GraphicStencil").BaseStream; graphicStencil = (GraphicStencil)sf.Deserialize(stream); stream.Close(); Generate(graphicStencil.Elements, graphicStencil.defaultSize, elementTextBox); Generate(graphicStencil.Decorations, graphicStencil.defaultSize, decorationTextBox); Generate(graphicStencil.TagArea, graphicStencil.defaultSize, tagAreaTextBox); if (stream != null) stream.Close(); } { SoapFormatter sf; Stream stream = null; sf = new SoapFormatter(); stream = new StreamReader(baseName + ".GraphicStencil").BaseStream; graphicStencil = (GraphicStencil)sf.Deserialize(stream); stream.Close(); if (elementTextBox.Text == "") Generate(graphicStencil.Elements, graphicStencil.defaultSize, elementTextBox); if (decorationTextBox.Text == "") Generate(graphicStencil.Decorations, graphicStencil.defaultSize, decorationTextBox); } Parse(modelStencil.Elements, elementTextBox); Parse(modelStencil.Decorations, decorationTextBox); ParseAnchor(modelStencil.Anchors, anchorTextBox); UpdateStencil(modelStencil); Parse(graphicStencil.Elements, elementTextBox); Parse(graphicStencil.Decorations, decorationTextBox); SysCAD.Protocol.Rectangle textArea = graphicStencil.TagArea; ParseTagArea(ref textArea, tagAreaTextBox); graphicStencil.TagArea = textArea; UpdateStencil(graphicStencil); this.elementTextBox.TextChanged += new System.EventHandler(this.textBox_TextChanged); this.decorationTextBox.TextChanged += new System.EventHandler(this.textBox_TextChanged); this.tagAreaTextBox.TextChanged += new System.EventHandler(this.textBox_TextChanged); this.anchorTextBox.TextChanged += new System.EventHandler(this.textBox_TextChanged); } }
static public ShapeTemplate GetShapeTemplate(GraphicStencil stencil, bool mirrorX, bool mirrorY) { int i; if (stencil != null) { ElementTemplate[] elementTemplate = new ElementTemplate[stencil.Elements.Count]; i = 0; foreach (Element element in stencil.Elements) { elementTemplate[i] = MirroredElement(element, mirrorX, mirrorY); i++; } ElementTemplate[] decorationTemplate = new ElementTemplate[stencil.Decorations.Count]; i = 0; foreach (Element decoration in stencil.Decorations) { decorationTemplate[i] = MirroredElement(decoration, mirrorX, mirrorY); i++; } return (new ShapeTemplate(elementTemplate, decorationTemplate, new ElementTemplate[0], FillMode.Alternate, (String)stencil.Tags[0])); } else return null; }
private static void ProcessGraphicStencil(String upgradeSymbolPath, String path) { GraphicStencil graphicStencil = new GraphicStencil(); String tag = Path.GetFileNameWithoutExtension(path).Split("().".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1].Replace('_', ' '); graphicStencil.Tags = new ArrayList(); graphicStencil.Elements = new ArrayList(); graphicStencil.Decorations = new ArrayList(); graphicStencil.DefaultSize = new Size(0.0, 0.0); Double xMin = 0.0; Double xMax = 0.0; Double yMin = 0.0; Double yMax = 0.0; // Extract min/max's for scaling on-the-fly. foreach (String line in (new StreamReader(path)).ReadToEnd().Split("\n\r".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)) { string[] words = line.Split(" ,".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (words.Length > 0) { switch (words[0]) { case "XMin": xMin = Double.Parse(words[1]); break; case "XMax": xMax = Double.Parse(words[1]); break; case "YMin": yMax = -Double.Parse(words[1]); break; case "YMax": yMin = -Double.Parse(words[1]); break; case "Group": graphicStencil.Tags.Add(words[1] + "/" + tag); break; } } } // Populate graphicStencil. Point oldPt = new Point(Double.NaN, Double.NaN); foreach (String line in (new StreamReader(path)).ReadToEnd().Split("\n\r".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)) { string[] words = line.Split(" ,".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (words.Length > 0) { ArrayList pCurvePts = new ArrayList(); switch (words[0]) { case "MDrw_Poly": int i = 1; while (i + 3 < words.Length) { graphicStencil.Decorations.Add( new Line( (Double.Parse(words[i]) - xMin) / (xMax - xMin) * 100.0, (-Double.Parse(words[i + 1]) - yMin) / (yMax - yMin) * 100.0, (Double.Parse(words[i + 2]) - xMin) / (xMax - xMin) * 100.0, (-Double.Parse(words[i + 3]) - yMin) / (yMax - yMin) * 100.0 ) ); i += 2; } break; case "MDrw_Arc": { Double xc = Double.Parse(words[1]); Double yc = Double.Parse(words[2]); Double r = Double.Parse(words[3]); Double s = Double.Parse(words[4]); Double x1 = Double.Parse(words[5]); Double y1 = Double.Parse(words[6]); Double a = Math.Atan2(y1 - yc, x1 - xc); if (s > 1.95 * Math.PI) { graphicStencil.Decorations.Add( new Arc( ((xc - r) - xMin) / (xMax - xMin) * 100.0, ((-yc - r) - yMin) / (yMax - yMin) * 100.0, (2.0 * r) / (xMax - xMin) * 100.0, (2.0 * r) / (yMax - yMin) * 100.0, 0.0, 360.0 ) ); } else { Bezier bezier = new Bezier(); bezier.x1 = x1; bezier.y1 = y1; bezier.x2 = xc + r * Math.Cos(a + s / 3.0); bezier.y2 = yc + r * Math.Sin(a + s / 3.0); bezier.x3 = xc + r * Math.Cos(a + 2.0 * s / 3.0); bezier.y3 = yc + r * Math.Sin(a + 2.0 * s / 3.0); bezier.x4 = xc + r * Math.Cos(a + s); bezier.y4 = yc + r * Math.Sin(a + s); bezier.x1 = (bezier.x1 - xMin) / (xMax - xMin) * 100.0; bezier.y1 = (-bezier.y1 - yMin) / (yMax - yMin) * 100.0; bezier.x2 = (bezier.x2 - xMin) / (xMax - xMin) * 100.0; bezier.y2 = (-bezier.y2 - yMin) / (yMax - yMin) * 100.0; bezier.x3 = (bezier.x3 - xMin) / (xMax - xMin) * 100.0; bezier.y3 = (-bezier.y3 - yMin) / (yMax - yMin) * 100.0; bezier.x4 = (bezier.x4 - xMin) / (xMax - xMin) * 100.0; bezier.y4 = (-bezier.y4 - yMin) / (yMax - yMin) * 100.0; graphicStencil.Decorations.Add(bezier); } } break; case "MDrw_Arc3": graphicStencil.Decorations.Add( Arc3( Double.Parse(words[1]), -Double.Parse(words[2]), Double.Parse(words[3]), -Double.Parse(words[4]), Double.Parse(words[5]), -Double.Parse(words[6]), xMin, xMax, yMin, yMax) ); break; case "MDrw_PCurve": switch (words[1]) { case "S": pCurvePts.Clear(); oldPt = new Point(Double.Parse(words[3]), -Double.Parse(words[4])); break; case "P": graphicStencil.Decorations.Add( new Line( (oldPt.X - xMin) / (xMax - xMin) * 100.0, (oldPt.Y - yMin) / (yMax - yMin) * 100.0, (Double.Parse(words[3]) - xMin) / (xMax - xMin) * 100.0, (-Double.Parse(words[4]) - yMin) / (yMax - yMin) * 100.0 ) ); oldPt = new Point(Double.Parse(words[3]), -Double.Parse(words[4])); break; case "A": Double x2 = Double.Parse(words[3]); Double y2 = -Double.Parse(words[4]); Double xc = Double.Parse(words[5]); Double yc = -Double.Parse(words[6]); Double r = Double.Parse(words[7]); graphicStencil.Decorations.Add( Arc3( oldPt.X, oldPt.Y, x2, y2, xc, yc, r, xMin, xMax, yMin, yMax) ); break; default: Message("Unknown MDrw_PCurve option", upgradeSymbolPath, path + "\\" + Path.GetFileNameWithoutExtension(path).Split("().".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1] + ".GraphicStencil", line); break; } break; case "Width": graphicStencil.DefaultSize.Width = Double.Parse(words[1]); break; case "Height": graphicStencil.DefaultSize.Height = Double.Parse(words[1]); break; case "TextArea": graphicStencil.TagArea = new Rectangle( (Double.Parse(words[1]) - xMin) / (xMax - xMin) * 100.0, ((-Double.Parse(words[2]) - yMin) - (Double.Parse(words[4]) - yMin)) / (yMax - yMin) * 100.0, (Double.Parse(words[3])) / (xMax - xMin) * 100.0, (Double.Parse(words[4])) / (yMax - yMin) * 100.0 ); break; // Already handled. case "XMin": case "XMax": case "YMin": case "YMax": case "Group": break; // Ignore. case "Insert": case "Symbol": case "MDrw_TagPos": case "MDrw_End": case "InsertX": case "InsertY": break; default: Message("Unknown command", upgradeSymbolPath, path + "\\" + Path.GetFileNameWithoutExtension(path).Split("().".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1] + ".GraphicStencil", line); break; } } } GraphicStencil.Serialize(upgradeSymbolPath + "\\" + ((String)(graphicStencil.Tags[0])).Replace('/', '_').ToLower().Replace(' ', '_') + ".GraphicStencil", graphicStencil); //Console.WriteLine(upgradeSymbolPath + "\\" + ((String)(graphicStencil.Tags[0])).Replace('/', '_').ToLower().Replace(' ', '_') + ".GraphicStencil"); if (xMin == xMax) Message("Zero width", upgradeSymbolPath, path + "\\" + Path.GetFileNameWithoutExtension(path).Split("().".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1] + ".GraphicStencil", ""); if (yMin == yMax) Message("Zero height", upgradeSymbolPath, path + "\\" + Path.GetFileNameWithoutExtension(path).Split("().".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1] + ".GraphicStencil", ""); }