Пример #1
0
 private void LoadFromFile(string path, params object[] otherParams)
 {
     this.FilePath      = path;
     this.DocumentName  = Path.GetFileNameWithoutExtension(path);
     this.ExtensionName = Path.GetExtension(path);
     if (loadFileThread != null)
     {
         if (loadFileThread.IsAlive)
         {
             return;
         }
     }
     if (!string.IsNullOrEmpty(this.FilePath))
     {
         if (cadImage != null) //处理现有打开的文档
         {
             cadImage.DrawMatrixChanged -= new CADImport.EventHandler(cadImage_DrawMatrixChanged);
             cadImage.AfterRotate       -= new CADImport.EventHandler(cadImage_AfterRotate);
             cadImage.Dispose();
             cadImage = null;
             if (this.HostControl != null && this.HostControl.LayerControl != null)
             {
                 this.HostControl.LayerControl.Clear();
             }
         }
         this.HostControl.SetBusyCursor();
         EventBus.Trigger(new MultiThreadStatusStartEventData("正在打开文件" + this.DocumentName + "...", this, this.HostControl));
         cadImage = CADImage.CreateImageByExtension(FilePath);
         cadImage.NavigateDrawMatrix   = navigateDrawMatrix;
         cadImage.visibleArea          = ((Control)this.HostControl).ClientSize;
         cadImage.Painter.viewportRect = new DRect(0, 0, cadImage.visibleArea.Width, cadImage.visibleArea.Height);
         ImageRectangleF             = new RectangleF(0, 0, (float)cadImage.AbsWidth, (float)cadImage.AbsHeight);
         cadImage.DrawMatrixChanged += new CADImport.EventHandler(cadImage_DrawMatrixChanged);
         cadImage.AfterRotate       += new CADImport.EventHandler(cadImage_AfterRotate);
         CADImport.CADConst.DefaultSHXParameters.UseSHXFonts = cadImportConfiguration.UseSHXFonts;
         if (cadImportConfiguration.UseSHXFonts)
         {
             DoSHXFonts();
         }
         else
         {
             DoTTFFonts();
         }
         cadImage.GraphicsOutMode = cadImportConfiguration.DrawGraphicsMode;
         cadImage.ChangeDrawMode(cadImportConfiguration.DrawGraphicsMode, (Control)this.HostControl);
         cadImage.ChangeGraphicsMode(cadImportConfiguration.DrawGraphicsMode, renderMode);
         if (cadImage is CADRasterImage)
         {
             (cadImage as CADRasterImage).Control = (Control)this.HostControl;
         }
     }
     if (this.cadImage != null)
     {
         CADImage.CodePage           = System.Text.Encoding.Default.CodePage;//note - charset was set here
         CADImage.LastLoadedFilePath = Path.GetDirectoryName(path);
         CreateNewLoadThread(path);
     }
 }
Пример #2
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();
        }
Пример #3
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();
 }
Пример #4
0
        void checkLayout(CADImage cadimage)
        {
            multiView =false;
            foreach(CADLayout layout in cadimage.Layouts)
            {

                if(layout.PaperSpaceBlock!=null)
                {
                    multiView =true;
                    break;
                }
            }
            if(multiView)layouts = cadimage.Layouts;
        }
Пример #5
0
 public void Dispose()
 {
     this.img=null;
     this.grPath.Dispose();
     this.intPoints=null;
     this.svg=null;
 }
Пример #6
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;
        }
Пример #7
0
        public ActionResult GetCSV(string guid)
        {
            string resp = "";

            DrawingState ds = DrawingManager.Get(guid);

            if (ds != null)
            {
                List <AttributesExport> toExcel = new List <AttributesExport>();

                if (DrawingManager.Engine == DrawingEngine.CADNET)
                {
                    CADImage cadImage = ds.Drawing.GetInstance() as CADImage;
                    foreach (CADEntity ent in cadImage.Converter.Entities)
                    {
                        if ((ent is CADInsert) && ((ent as CADInsert).Attribs.Count == 3))
                        {
                            AttributesExport atrExp = new AttributesExport();
                            atrExp.Tags = new Dictionary <string, string>();
                            foreach (CADAttrib attr in (ent as CADInsert).Attribs)
                            {
                                atrExp.Tags.Add(attr.Tag, attr.Value);
                            }
                            atrExp.BlockName = (ent as CADInsert).Block.Name;
                            toExcel.Add(atrExp);
                        }
                    }
                }
                else
                {
                    string xml = ds.Drawing.ProcessXML("<?xml version=\"1.0\" encoding=\"UTF-8\"?><cadsofttools version=\"2\"><get mode=\"5\" /></cadsofttools>");

                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(xml);
                    XmlNodeList nodes = doc.SelectNodes("//cstInsert");

                    foreach (XmlNode node in nodes)
                    {
                        if (node.ChildNodes.Count == 3)
                        {
                            AttributesExport attrExp = new AttributesExport();
                            attrExp.Tags = new Dictionary <string, string>();
                            XmlAttribute attr = node.Attributes["BlockName"];
                            if (attr != null)
                            {
                                attrExp.BlockName = attr.Value;
                            }
                            foreach (XmlNode cNode in node.ChildNodes)
                            {
                                XmlAttribute atrTag   = cNode.Attributes["Tag"];
                                XmlAttribute atrValue = cNode.Attributes["Value"];
                                if ((atrTag != null) && (atrValue != null))
                                {
                                    attrExp.Tags.Add(atrTag.Value, atrValue.Value);
                                }
                            }
                            toExcel.Add(attrExp);
                        }
                    }
                }

                foreach (AttributesExport attr in toExcel)
                {
                    resp += attr.BlockName + "; ";
                    foreach (var tag in attr.Tags)
                    {
                        resp += tag.Key + "; " + tag.Value + "; ";
                    }
                    resp += "\r\n";
                }
            }
            Response.AddHeader("Content-Disposition", "attachment;filename=attribs.csv");
            return(Content(resp, "text/csv"));
        }