예제 #1
0
        public void DimensionAll()
        {
            //if (!CheckForTearOff())
            //{
            //    MessageBox.Show(@"������ �� ��������. ��������� � ����� ���� � ������� ""�������� ���""");
            //    return;
            //}
            IsEventsEnabled = false;
            var dir = new DirectoryInfo(GetRootFolder(SwApp.IActiveDoc2));
            if (Properties.Settings.Default.CashModeOn)
            {
                LinkedList<ModelDoc2> models;
                GetAllUniqueModels(SwModel, out models);
                LinkedList<string> modelPaths = new LinkedList<string>();
                foreach (var modelDoc2 in models)
                {
                    modelPaths.AddLast(Path.GetFileNameWithoutExtension(modelDoc2.GetPathName()));
                }
                List<FileInfo> drawToDelete = new List<FileInfo>();
                foreach (FileInfo file in dir.GetFiles("*.SLDDRW", SearchOption.AllDirectories))
                {
                    if (!modelPaths.Contains(Path.GetFileNameWithoutExtension(file.Name)))
                        drawToDelete.Add(file);
                }
                foreach (var fileInfo in drawToDelete)
                {
                    fileInfo.Delete();
                }
            }
            var allNeedleFiles = dir.GetFiles("*.SLDDRW", SearchOption.AllDirectories).Where(
                file => Path.GetFileNameWithoutExtension(file.FullName) != dir.Name);
            int count = allNeedleFiles.Count();
            UserProgressBar pb;
            SwApp.GetUserProgressBar(out pb);
            pb.Start(0, count, "��������������");
            int i = 0;
            foreach (var swModel in allNeedleFiles.Select(
                file => (ModelDoc2)SwApp.OpenDoc(file.FullName, (int)swDocumentTypes_e.swDocDRAWING)).Where(
                    swModel => swModel != null))
            {
                using (var dimDraft = new DimensionDraft(this))
                {
                    try
                    {
                        dimDraft.AutoDimensionDrawing(false);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
                        break;
                    }
                    if (dimDraft.isValidXml)
                        swModel.Save();
                }
                SwApp.CloseDoc(swModel.GetPathName());
                i++;
                pb.UpdateProgress(i);
            }
            pb.End();

            if (MessageBox.Show(@"�������������� ���������! ������� ��� �������?", MyTitle, MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question) == DialogResult.Yes)
            {
                OpenDrawings();
                IsEventsEnabled = true;
            }
            else
            {
                IsEventsEnabled = true;
                SwApp.ActivateDoc(SwModel.GetPathName());
                return;
            }
            return;
        }
예제 #2
0
        public void AutoDimensionDrawing()
        {
            IsEventsEnabled = false;

            using (var dimDraft = new DimensionDraft(this))
            {
                try
                {
                    dimDraft.AutoDimensionDrawing(true);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                    throw;
                }
            }

            IsEventsEnabled = true;
            return;
        }
예제 #3
0
        public void DeleteXmlFiles(bool deleteUnActualModels)
        {
            List<string> modelsToDelete, allModels, deletedModels = new List<string>(), deletedFiles = new List<string>();
            bool deleteXml = GetDeleteXmlFiles(SwModel.GetPathName(), out modelsToDelete, out allModels);

            string delDir = Path.Combine(Path.GetDirectoryName(SwModel.GetPathName()), "���������");
            if (Directory.Exists(delDir))
            {
                foreach (var file in Directory.GetFiles(delDir, "*.xml", SearchOption.TopDirectoryOnly))
                {
                    //������ ��� ������� ���� ���� 1) �������� ModelName �� xml 2) ���� �� ���� � modelsToDelete = > �������
                    var currXml = new XmlDocument();
                    currXml.Load(file);
                    if (currXml.ChildNodes.Count == 0)
                    {
                        File.Delete(file);
                        continue;
                    }
                    var modelName = Path.GetFileNameWithoutExtension(currXml.ChildNodes[0].Attributes["Name"].Value);
                    if (modelsToDelete.Contains(modelName) && deleteUnActualModels || (currXml.DocumentElement.GetAttribute("CNCValid") == null || currXml.DocumentElement.GetAttribute("CNCValid") == false.ToString()))
                    {
                        //File.Delete(file);
                        deletedFiles.Add(file);
                        deletedModels.Add(modelName);
                    }
                    else
                    {
                        if (!allModels.Contains(modelName) && !(modelName.Substring(modelName.Length - 4, 4)[0] == '#' && (modelName.Substring(modelName.Length - 4, 4)[3] == 'P' || modelName.Substring(modelName.Length - 4, 4)[3] == 'p')))
                        {
                            File.Delete(file);
                            deletedModels.Add(modelName);
                        }
                    }
                }
            }
            if (!deleteUnActualModels)
                return;
            //������ ��� ��� ������ ������� ���� ������� ������������ ���������
            if (Properties.Settings.Default.CreateProgramsOnFF && deletedModels.Count > 0)
            {
                var vOpenDocs = SwApp.GetDocuments();
                List<IModelView> modelViewsMinimized = new List<IModelView>();
                foreach (var vOpenDoc in vOpenDocs)
                {
                    ModelDoc2 tmpModel = vOpenDoc;
                    if (tmpModel.GetType() == (int)swDocumentTypes_e.swDocDRAWING)
                        SwApp.CloseDoc(tmpModel.GetTitle());
                    else if (tmpModel.GetType() == (int)swDocumentTypes_e.swDocASSEMBLY)
                    {
                        var myModelView1 = (IModelView)tmpModel.GetFirstModelView();
                        if (myModelView1 != null)
                        {
                            myModelView1.FrameState = (int)swWindowState_e.swWindowMinimized;
                            modelViewsMinimized.Add(myModelView1);
                        }
                    }
                }
                if (deletedFiles.Count > 2)
                {
                    string text = "��� ������� � ������ ���� �������� ����� �������������� �������� �� ���. ��� ������� � �������� �������� ��� ������ �������. ���������� ����������� ��������� ���������. ��� ������ �������������� ����� ��� ������������� ��������� ������. ����������� ���������?";
                    if (MessageBox.Show(text, MyTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
                    {
                        //Logging.Log.Instance.SendMail("������������ ��������. ���������� ���������������:" + deletedFiles.Count + " . ����� ������������ - ���");
                        MakeXmlUnvalid(deletedFiles);
                        return;
                    }
                    else
                    {
                        //Logging.Log.Instance.SendMail("������������ ��������. ���������� ���������������:" + deletedFiles.Count + " . ����� ������������ - ��");
                        MakeXmlUnvalid(deletedFiles);
                    }

                }

                foreach (var deletedModel in deletedModels)
                {

                    //��� ������ ������ ���������������...
                    using (var dd = new DimensionDraft(this))
                    {
                        //�������� ������...
                        object[] oComps = null;
                        var tmp = SwModel as AssemblyDoc;
                        if (tmp != null)
                            oComps = tmp.GetComponents(true) as object[];
                        else
                        {
                            //������� AssemblyDoc
                            continue;
                        }

                        if (oComps != null)
                        {
                            foreach (Component2 oComp in oComps)
                            {

                                if (oComp.Name.Contains(deletedModel))
                                {
                                    try
                                    {
                                        if (oComp.Select(false))
                                        {

                                            //������� ������.
                                            OpenDrawing(true);

                                            //�����������
                                            dd.AutoDimensionDrawing(false);
                                            //CloseAllExceptMainAssembly();
                                        }
                                        break;
                                    }
                                    catch (Exception ex)
                                    {
                                        Logging.Log.Instance.Fatal(ex, "������ ��� ������������ ���������..");
                                        continue;
                                    }
                                    finally
                                    {
                                        CloseAllExceptMainAssembly();
                                    }
                                }
                            }
                        }
                    }
                }
                foreach (var modelView in modelViewsMinimized)
                {
                    modelView.FrameState = (int)swWindowState_e.swWindowMaximized;

                }
            }
        }