Example #1
0
        public CADTestForm()
        {
            fileSettingsName = Application.StartupPath + @"\Settings.txt";
            InitializeComponent();
            string path = @"C:\Users\Rajeesh\Documents\CAD .NET 11\Files\123.dxf";

            _cadImage = CADImage.CreateImageByExtension(path);
            _cadImage.LoadFromFile(path);
            InitializeSettings();
        }
Example #2
0
 private void button1_Click(object sender, System.EventArgs e)
 {
     if (openFileDialog1.ShowDialog(this) != DialogResult.OK)
     {
         return;
     }
     if (openFileDialog1.FileName != null)
     {
         FCADImage        = new CADImage();
         FCADImage.Base.Y = Bottom - 100;
         FCADImage.Base.X = 100;
         FCADImage.LoadFromFile(openFileDialog1.FileName);
     }
     this.Invalidate();
 }
Example #3
0
        private ItopVector.Core.Document.SvgDocument getSvg(string filename)
        {
            flashwindow.RefleshStatus("���ڷ���CAD�ļ�...");
            string exten=Path.GetExtension(filename);
            string svgFile = filename;
            double pWidth =800;
            double pHeight =600;
            ArrayList selectLayout = new ArrayList();
            CADImage cadimage=null;
            if (exten.ToLower()==".dwg")
            {
                if(useCache && filename==cacheFile)
                {
                    cadimage = cacheCAD;
                }
                else
                {
                    DWGImage dwg =new DWGImage();
                    dwg.LoadFromFile(filename);
                    cadimage = dwg;

                }
                svgFile = filename +".svg";
            }
            else if(exten.ToLower()==".dxf")
            {
                if(useCache && filename==cacheFile)
                {
                    cadimage = cacheCAD;
                }
                else
                {
                    cadimage =new CADImage();
                    cadimage.LoadFromFile(filename);
                }
                svgFile = filename +".svg";
            }
            else if(exten.ToLower()==".svg")
            {
                flashwindow.RefleshStatus("���ڷ���SVG�ļ�...");

                goto label_01;
            }
            else
            {
                return null;
            }
            if(useCache)
            {
                cacheFile = filename;
                cacheCAD = cadimage;
            }
            checkLayout(cadimage);
            if (multiView)
            {
                paperspace = cadimage.converter.Entities[0].PaperSpace;
                cadimage.CurrentLayout = cadimage.Layouts[paperspace];
                using(frmLayout dlg =new frmLayout(cadimage.Layouts))
                      {
                    dlg.Layouts = selectLayout;
                    dlg.ShowDialog();
                }
            }
            pWidth = cadimage.AbsWidth;
            pHeight = cadimage.AbsHeight;
            //			cadimage.Layouts[0].PaperSpaceBlock!=null;

            flashwindow.RefleshStatus(string.Format("������������ģ��{0}...",""));
            //			cadimage.converter.Layers
            stw =File.CreateText(svgFile);
            stw.AutoFlush=true;

            string hd = "<?xml version=\"1.0\" encoding=\"utf-8\"?><!----><!DOCTYPE svg PUBLIC \"-/W3C/DTD SVG 1.1/EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">" +
                "\r\n<svg id=\"svg\" width=\"" +pWidth + "\" height=\"" + pHeight + "\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:tonli=\"http://www.tonli.com/tonli\">";

            stw.Write(hd);

            string lar = "\r\n<defs id=\"defs00001\">"+createLayer(cadimage.converter.Layers) +
                "\r\n</defs>";
            stw.Write(lar);

            if(!multiView || selectLayout.Contains(paperspace))
            {

                Parse(cadimage.converter.Entities,cadimage.AbsHeight,cadimage.AbsWidth,cadimage.xMin,cadimage.yMin,"");
            }

            if (multiView)
            {
                paperspace=-1;
                foreach(CADLayout layout in cadimage.Layouts)
                {
                    paperspace++;
                    if(!selectLayout.Contains(paperspace))continue;
                    if(layout.PaperSpaceBlock !=null)
                    {
                        cadimage.CurrentLayout = cadimage.Layouts[paperspace];

                        DRect rect = layout.PaperSpaceBlock.Box;
                        pWidth = Math.Max(pWidth,cadimage.AbsWidth);
                        pHeight = Math.Max(pHeight,cadimage.AbsHeight);
                        Parse(layout.PaperSpaceBlock.Entities,cadimage.AbsHeight,cadimage.AbsWidth,cadimage.xMin,cadimage.yMin,"");
                    }
                }

            }

            stw.Write("\r\n</svg>");

            stw.Flush();
            stw.Close();

            label_01:
            ItopVector.Core.Document.SvgDocument doc= ItopVector.Core.Document.SvgDocumentFactory.CreateDocumentFromFile(svgFile);
            //			doc.PreserveWhitespace = true;
            //			DateTime dt1 =DateTime.Now;
            //			doc.Load(svgFile);

            if (doc==null)return null;

            bool flag = doc.AcceptChanges;
            doc.AcceptChanges=false;

            if(multiView)
            {
                doc.RootElement.SetAttribute("width",""+pWidth);
                doc.RootElement.SetAttribute("height",""+pHeight);
            }
            for(int i=doc.Layers.Count-1;i>=0;i--)
            {
                Layer layer = doc.Layers[i] as Layer;
                if(layer.GraphList.Count==0)layer.Remove();
            }
            if(multiView && doc.Layers.Count>0 )
            {
                (doc.Layers[0] as Layer).Visible=true;
            }

            #if !DEBUG
            File.Delete(filename+".svg");
            #endif
            doc.FilePath="";
            doc.FileName=Path.GetFileNameWithoutExtension(filename);
            doc.AcceptChanges=flag;

            layouts =null;
            cadimage =null;
            return doc;
        }