Ejemplo n.º 1
0
        public int OnCommandCloseNotify(int command, int reason)
        {
            if (IsEventsEnabled)
            {
                IsEventsEnabled = false;
                try
                {
                    Component2 swAddedComp = null;

                    if (Properties.Settings.Default.CashModeOn)
                    {
                        #region ��� ���

                        if (_addingComponentNames.Count > 0)
                        {
                            IsEventsEnabled = false;
                            _iSwApp.RefreshTaskpaneContent();

                            if (Properties.Settings.Default.AutoSaveComponents)
                            {
                                foreach (string compName in _addingComponentNames)
                                {
                                    GetComponentByName(SwModel, compName, false, out swAddedComp);
                                }
                            }
                            //��������
                            if (RootModel == null)
                                RootModel = SwModel;

                            int par1 = 0, par2 = 0;
                            RootModel.Save3((int)swSaveAsOptions_e.swSaveAsOptions_Silent, par1, par2);

                            if (par1 > 0)
                            {
                                MessageBox.Show("��� ���������� ������������ ���������� ��������� ������.");
                                IsEventsEnabled = true;
                                return 0;
                            }

                            linksToCash.Save(RootModel.GetPathName());

                            _addingComponentNames.Clear();

                        }
                        else
                            return 0;

                        #endregion
                    }
                    else
                    {
                        #region ��� ����

                        if (_addingComponentNames.Count > 0)
                        {
                            try
                            {
                                if (Properties.Settings.Default.AutoSaveComponents)
                                {
                                    foreach (string compName in _addingComponentNames)
                                    {
                                        if (GetComponentByName(SwModel, compName, false, out swAddedComp))
                                        {
                                            LinkedList<CopiedFileNames> filesNames = null;

                                            if (swAddedComp.Select(false))
                                            {
                                                SaveAsComponents(out filesNames);
                                            }
                                            if (Properties.Settings.Default.ShowRPDBefore)
                                            {
                                                lock (workerLocker)
                                                {
                                                    ThreadPool.QueueUserWorkItem(AddSuffix,
                                                                                 new SuffixCopyPassClass()
                                                                                 {
                                                                                     filesNames = filesNames,
                                                                                     swAddedComp = swAddedComp,
                                                                                     isAsinc = true
                                                                                 });
                                                }
                                                lock (workerLocker2)
                                                    Monitor.Wait(workerLocker2);

                                            }
                                            else
                                            {
                                                AddSuffix(filesNames, swAddedComp, false);

                                            }
                                        }
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                Logging.Log.Instance.Fatal(e.Message + "OnCommandCloseNotify()");
                                MessageBox.Show(e.Message, MyTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                            _addingComponentNames = new LinkedList<string>();
                        }

                        #endregion
                    }

                    if (Properties.Settings.Default.KitchenModeOn)
                    {
                        #region ��������� ������ �����

                        CustomPropertyManager propertyManager = ((ModelDoc2)swAddedComp.GetModelDoc2()).Extension.get_CustomPropertyManager(string.Empty);
                        string kitchenTypeValue = string.Empty;
                        string resolvedKitchenTypeValue = string.Empty;
                        propertyManager.Get4("KitchenType", false, out kitchenTypeValue, out resolvedKitchenTypeValue);

                        if (!string.IsNullOrEmpty(kitchenTypeValue))
                        {
                            var swModel = SwApp.IActiveDoc2;
                            var swConfig = (Configuration)swModel.GetActiveConfiguration();
                            Component2 swRootComponent = null;
                            if (swConfig != null)
                                swRootComponent = (Component2)swConfig.GetRootComponent();
                            KitchenModule km = new KitchenModule(RootModel, swRootComponent, this, swModel);
                            bool isAnglePart, isUpPart, isTabletop;
                            km.GetComponentType(swAddedComp.GetPathName(), out isAnglePart, out isUpPart, out isTabletop);
                            if (isTabletop)
                                km.TableTopProcess(swAddedComp);
                        }

                        #endregion
                    }

                    if (Properties.Settings.Default.AutoShowSetParameters && swAddedComp != null)
                    {
                        if (swAddedComp.Select(false))
                            ShowSetParameters();
                    }

                    RebuildEquation(swAddedComp);
                }
                catch { }
                IsEventsEnabled = true;
            }
            return 0;
        }
Ejemplo n.º 2
0
        public int OnAddNewItem(int entityType, string itemName)
        {
            if (IsEventsEnabled)
            {
                IsEventsEnabled = false;
                try
                {
                    Component2 addedComponent;
                    if (!GetComponentByName(SwModel, itemName, false, out addedComponent))
                    {
                        MessageBox.Show("");
                        IsEventsEnabled = true;
                        return 0;
                    }
                    string addedComponentPath = addedComponent.GetPathName();
                    ModelDoc2 addedModel = addedComponent.GetModelDoc2();

                    if (Properties.Settings.Default.CashModeOn)
                    {
                        #region ��� ���

                        bool saveAlready = !_isCheckedSaving;
                        if (!_isCheckedSaving)
                        {
                            _isCheckedSaving = CheckSaving(SwApp.IActiveDoc2.GetPathName());
                            RootModel = SwModel;
                        }
                        if (RootModel == null)
                            RootModel = SwModel;

                        bool isAlreadyExist = false;
                        string newFilePath = string.Empty;
                        string newNumberString = string.Empty;
                        Logging.Log.Instance.Debug("0");
                        if (entityType == (int)swNotifyEntityType_e.swNotifyComponent) //��� ����������
                        {
                            //��� ��������� ��� �� � ������ ��� ����� ������
                            if (!saveAlready)
                                isAlreadyExist = CheckIfAlreadyExist(addedComponentPath, out newFilePath);
                            else
                                isAlreadyExist = false;

                            if (Path.GetFileNameWithoutExtension(addedComponentPath).Last() == 'P')
                                File.SetAttributes(addedComponentPath, FileAttributes.Hidden);

                            Decors.AddModelToList(this, addedComponent.GetModelDoc2());

                            ////��������� ���� �� ���������
                            if (!isAlreadyExist)
                                newFilePath = GetNextNumberCash(addedComponentPath, out newNumberString);

                            if ((addedComponentPath.ToUpper().Contains("_SWLIB_") || addedComponentPath.ToUpper().Contains("_SWLIB_BACKUP")) && !isAlreadyExist)
                                _addingComponentNames.AddLast(itemName);

                            if (!File.Exists(newFilePath) && !isAlreadyExist)
                                ThreadPool.QueueUserWorkItem(CopyToCash, new KeyValuePair<string, string>(GetOldPath(addedComponent.GetPathName()), newNumberString));
                            else
                            {
                                if (!isAlreadyExist)
                                    File.SetAttributes(newFilePath, FileAttributes.Normal);
                            }

                            if (addedComponent.Select(false) && !isAlreadyExist)
                                ThreadPool.QueueUserWorkItem(CopyDrawings2Thread, null);

                            if (addedModel != null)
                            {
                                Decors.AddModelToList(this, addedModel);
                                string fileName;
                                if (ExistingFileDictionaryWithMdb(out fileName))
                                {
                                    var strArr = File.ReadAllLines(fileName).ToList();
                                    strArr.Add(addedComponent.GetPathName());
                                    File.SetAttributes(fileName, FileAttributes.Normal);
                                    File.WriteAllLines(fileName, strArr);
                                    File.SetAttributes(fileName, FileAttributes.Hidden);
                                }
                            }
                        }

                        if (_frmPrm != null)
                            _frmPrm.Close();
                        SwitchToThisWindow(_swHandle, true);

                        #endregion
                    }
                    else
                    {
                        #region ��� ����

                        if (_frmPrm != null)
                            _frmPrm.Close();

                        if (!_isCheckedSaving)
                        {
                            _isCheckedSaving = CheckSaving(SwApp.IActiveDoc2.GetPathName());
                            RootModel = SwModel;
                        }

                        #region �������� �� ������������ ����� ������

                        var nameFromModel = Path.GetFileNameWithoutExtension(SwModel.GetPathName());
                        var nameFromDirectory = GetOrderName(SwModel);
                        if (nameFromModel != nameFromDirectory)
                        {
                            SwApp.RunCommand((int)swCommands_e.swCommands_PmCancel, "");
                            addedComponent.Select(false);
                            SwModel.DeleteSelection(false);
                            MessageBox.Show(@"������ ����� ����� ������ � �����!�������� �����!", MyTitle,
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);
                            IsEventsEnabled = true;
                            return 0;
                        }

                        string nameForAssembly = GetXNameForAssembly(false, Path.GetFileNameWithoutExtension(SwModel.GetPathName()));
                        if (!Decors.DictionaryListMdb.ContainsKey(nameForAssembly))
                        {
                            Decors.DictionaryListMdb.Add(nameForAssembly, new List<ModelDoc2>());
                            string fileName;
                            if (!ExistingFileDictionaryWithMdb(out fileName))
                            {
                                File.Create(fileName).Close();
                                File.SetAttributes(fileName, FileAttributes.Hidden);
                            }
                        }

                        LinkedList<Component2> outComponents = new LinkedList<Component2>();
                        try
                        {
                            if (GetComponents(SwModel.IGetActiveConfiguration().IGetRootComponent2(), outComponents, false, false))
                            {
                                Component2 comp = outComponents.First(x => x.Name.Contains("#"));
                                string name = comp.Name.Substring(comp.Name.IndexOf("#") + 1,
                                                                  comp.Name.Substring(comp.Name.IndexOf("#")).IndexOf(
                                                                      "-") -
                                                                  1);
                                UInt64 number = Convert.ToUInt64(name, 16);
                                name = number.ToString();
                                string orderNumber = "";
                                var orderNumberArrays = GetOrderName(SwModel).Split('-');
                                orderNumber = orderNumberArrays.Aggregate(orderNumber,
                                                                          (current, orderNumberArray) =>
                                                                          current + orderNumberArray);
                                int i = 0;
                                while (name != orderNumber && i < 255)
                                {
                                    name = "0" + name;
                                    i++;
                                }

                                bool isFailed = (i == 255);

                                if (isFailed)
                                {
                                    string nativeNumber = name;
                                    if (name.Length > 14)
                                        name = name.Substring(name.Length - 14);
                                    if (name.Length == 14)
                                        nativeNumber = name.Substring(0, 6) + "-" + name.Substring(6, 4) + "-" +
                                                       name.Substring(10);

                                    SwApp.RunCommand((int)swCommands_e.swCommands_PmCancel, "");
                                    addedComponent.Select(false);
                                    SwModel.DeleteSelection(false);
                                    var mmb = new MyMessageBox();
                                    mmb.Show(
                                            @"������! �.�. ��� �������� �����/�����
                                            ������ ���� ��������,����������
                                            ����� ������� � ������ ����������!
                                            ������������ ���������� ��� ����� �����!",
                                            "���������� ���: ",
                                        nativeNumber, "OK", "MrDoors");
                                    IsEventsEnabled = true;
                                    return 0;
                                }
                            }
                        }
                        catch { }

                        #endregion

                        try
                        {
                            if (entityType == (int)swNotifyEntityType_e.swNotifyComponent) //��� ����������
                            {
                                if (!addedComponent.Name2.Contains("^")) //�������� �� ���������� � ������ ���������
                                {
                                    var swCompModel = (ModelDoc2)addedComponent.GetModelDoc();
                                    if (swCompModel != null)
                                    {
                                        //������ ���� ������ �� ���������� ��� ������
                                        if (swCompModel.GetPathName().Contains(Furniture.Helpers.LocalAccounts.modelPathResult))
                                        {
                                            Component2 swLibComp;
                                            if (GetParentLibraryComponent(addedComponent, out swLibComp))
                                                _addingComponentNames.AddLast(itemName);
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Logging.Log.Instance.Fatal(e.Message + "OnAddNewItem()");
                            MessageBox.Show(e.Message, MyTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }

                        #endregion
                    }

                    if (Properties.Settings.Default.KitchenModeOn)
                    {
                        #region ��������� ������ �����

                        CustomPropertyManager propertyManager = addedModel.Extension.get_CustomPropertyManager(string.Empty);
                        string kitchenTypeValue = string.Empty;
                        string resolvedKitchenTypeValue = string.Empty;
                        propertyManager.Get4("KitchenType", false, out kitchenTypeValue, out resolvedKitchenTypeValue);

                        if (!string.IsNullOrEmpty(kitchenTypeValue))
                        {
                            ModelDoc2 swModel = SwApp.IActiveDoc2;
                            swModel.ClearSelection2(true);
                            Component2 mainComponent = null;
                            var swConfig = (Configuration)swModel.GetActiveConfiguration();
                            Component2 swRootComponent;
                            if (swConfig != null)
                                swRootComponent = (Component2)swConfig.GetRootComponent();
                            else
                                return 1;
                            KitchenModule km = new KitchenModule(RootModel, swRootComponent, this, swModel);
                            var measure = km.measure;
                            string rootName = km.rootName;
                            GetSymilarComponentByName(SwModel, "�����", out mainComponent);
                            if (mainComponent == null)
                                return 1;

                            bool isAnglePart = itemName.ToLower().Contains("�������");
                            bool isUpPart = itemName.ToLower().Contains("�������");
                            bool isTabletop = false;
                            km.GetComponentType(addedComponentPath, out isAnglePart, out isUpPart, out isTabletop);

                            if (swConfig != null && mainComponent != null)
                            {
                                Feature plane1, plane2;

                                if (isTabletop)
                                    goto endMate;

                                plane1 = mainComponent.FeatureByName("#swrf������");
                                plane2 = addedComponent.FeatureByName("������");
                                AddMate(swModel, plane1, plane2);

                                var minDistance = km.GetSimilarTables(addedComponent, isUpPart, isAnglePart);

                                if (minDistance.planeDist != null && minDistance.planeSource != null)
                                    AddMate(swModel, minDistance.planeDist, minDistance.planeSource);
                                else
                                {
                                    minDistance = km.GetPointsMate(addedComponent, mainComponent, isAnglePart);
                                    if (minDistance.planeDist != null && minDistance.planeSource != null)
                                        AddMate(swModel, minDistance.planeDist, minDistance.planeSource);
                                }

                            endMate:
                                addedComponent.Select(false);
                            }
                            else
                                MessageBox.Show("�� ������� ����� ������ � ������ �����!!");
                        }
                        #endregion
                    }

                    //����� ��� ������������� ���� ���������� ������� � ����� ��� ��������
                    if (Properties.Settings.Default.ImmediatelyDetachModel && !Properties.Settings.Default.CashModeOn)
                    {
                        IsEventsEnabled = true;
                        SwApp.RunCommand((int)swCommands_e.swCommands_PmOK, "");
                        IsEventsEnabled = false;
                    }
                }
                catch { }
                IsEventsEnabled = true;
            }
            return 0;
        }