예제 #1
0
        private void ReloadAllSetParameters(Component2 swTestSelComp)
        {
            #region Очистить все словари местные переменные
            int downPos = 0;

            //закоменчено, т.к. этот код вызывает ошибку внутри солида и его закрытие.
            //замена на похожие методы (ClearSelection2 и т.п.) не помогает
            /*/
            if (!_isMate)
            {
                _swAsmDoc.NewSelectionNotify -= NewSelection;
                _swModel.ClearSelection();
                _swAsmDoc.NewSelectionNotify += NewSelection;
            }
            /*/

            _dictHeightPage.Clear();
            _dictPathPict.Clear();
            _dictionary.Clear();
            _dictConfig.Clear();
            _commonList.Clear();
            _objListChanged.Clear();
            _setNewListForComboBox = true;
            _butPlusTxt.Clear();
            _dimensionConfig.Clear();
            _textBoxListForRedraw.Clear();
            _numbAndTextBoxes.Clear();
            _comboBoxListForRedraw.Clear();
            _namesOfColumnNameFromDimLimits.Clear();
            refobj = null;
            #endregion

            if (swTestSelComp != null)
            {
                if (_mSwAddin.GetParentLibraryComponent(swTestSelComp, out _swSelComp))
                {
                    ModelDoc2 specModel;
                    _swSelComp = _mSwAddin.GetMdbComponentTopLevel(_swSelComp, out specModel);
                    _swSelModel = _swSelComp.IGetModelDoc();

                    #region ссылочный эскиз
                    //bool draft = (specModel.CustomInfo2["", "Required Draft"] == "Yes" ||
                    //    specModel.CustomInfo2[specModel.IGetActiveConfiguration().Name, "Required Draft"] == "Yes");

                    //if (draft)
                    //{
                    //    tabMain.Location = new Point(8, 70);
                    //    var dir = new DirectoryInfo(Path.GetDirectoryName(_mSwAddin.SwModel.GetPathName()));

                    //    var paths =
                    //        dir.GetFiles(
                    //            Path.GetFileNameWithoutExtension(specModel.GetPathName()) + ".SLDDRW",
                    //            SearchOption.AllDirectories);
                    //    string path=null;

                    //    if (paths.Any())
                    //        path = paths[0].FullName;
                    //    else
                    //    {
                    //        if (SwAddin.needWait)
                    //        {
                    //            path = Path.Combine(Path.GetDirectoryName(specModel.GetPathName()),
                    //                                Path.GetFileNameWithoutExtension(specModel.GetPathName()) +
                    //                                ".SLDDRW");
                    //            ThreadPool.QueueUserWorkItem(CheckDWRexistAfterCopy, path);
                    //        }
                    //    }

                    //    if (!string.IsNullOrEmpty(path))
                    //    {
                    //        linkLabel1.Name = path;
                    //        linkLabel1.Click += LinkLabel1Click;
                    //        string textInfo = specModel.CustomInfo2["", "Sketch Number"];
                    //        if (textInfo == "" || textInfo == "0" || textInfo == "Sketch Number")
                    //            linkLabel1.Text = @"ЭСКИЗ № н/о";
                    //        else
                    //            linkLabel1.Text = @"ЭСКИЗ № " + textInfo;
                    //    }
                    //    else
                    //        tabMain.Location = new Point(8, 40);
                    //}
                    //else
                    //{
                    //    tabMain.Location = new Point(8, 40);
                    //    linkLabel1.Text = "";
                    //}
                    #endregion

                    _lblPrm.Clear();
                    _btnPrm.Clear();

                    tbpParams.Controls.Clear();
                    tbpPos.Controls.Clear();

                    lblCompName.Text = _swSelComp.Name2;

                    OleDbConnection oleDb;

                    int i;
                    if (_mSwAddin.OpenModelDatabase(_swSelModel, out oleDb))
                    {
                        using (oleDb)
                        {
                            #region Обработка файла *.mdb

                            if (!tabMain.Controls.Contains(tbpParams))
                            {
                                tabMain.Controls.Remove(tbpPos);
                                tabMain.Controls.Add(tbpParams);
                                tabMain.Controls.Add(tbpPos);
                            }
                            if (Properties.Settings.Default.KitchenModeOn)
                            {
                                tabMain.SelectTab(tbpPos);
                            }
                            else
                            {
                                if (tabMain.SelectedTab != tbpParams)
                                {
                                    tabMain.SelectTab(tbpParams);
                                }
                            }
                            var oleSchem = oleDb.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
                                                                     new object[] { null, null, null, "TABLE" });

                            OleDbCommand cm;
                            OleDbDataReader rd;
                            listForDimensions = new List<DimensionConfForList>();

                            #region Если есть objects

                            if (oleSchem.Rows.Cast<DataRow>().Any(
                                row => (string)row["TABLE_NAME"] == "objects"))
                            {
                                _chkMeasure = new CheckBox
                                {
                                    Appearance = Appearance.Button,
                                    Location = new Point(133, 12),
                                    Name = @"chkMeasure",
                                    Size = new Size(80, 24),
                                    Text = @"Измерить",
                                    TextAlign = ContentAlignment.MiddleCenter,
                                    UseVisualStyleBackColor = true
                                };
                                tbpParams.Controls.Add(_chkMeasure);
                                _chkMeasure.CheckedChanged += StartMeasure;

                                i = 0;

                                bool isNumber = false, isIdSlave = false, isAsmConfig = false, isFixedValues = false;

                                #region Dimension Configuration

                                if (
                                    oleSchem.Rows.Cast<DataRow>().Any(
                                        row => (string)row["TABLE_NAME"] == "dimension_conf"))
                                {
                                    cm = new OleDbCommand("SELECT * FROM dimension_conf ORDER BY id", oleDb);
                                    rd = cm.ExecuteReader();
                                    var outComps = new LinkedList<Component2>();
                                    if (_mSwAddin.GetComponents(
                                        _swSelModel.IGetActiveConfiguration().IGetRootComponent2(),
                                        outComps, true, false))
                                    {
                                        _dimensionConfig = Decors.GetListComponentForDimension(_mSwAddin, rd,
                                                                                               outComps);
                                        _dimensionConfig.Sort((x, y) => x.Number.CompareTo(y.Number));
                                        rd.Close();
                                    }
                                }
                                #endregion

                                var thisDataSet = new DataSet();
                                var testAdapter = new OleDbDataAdapter("SELECT * FROM objects", oleDb);
                                testAdapter.Fill(thisDataSet, "objects");
                                testAdapter.Dispose();
                                bool captConfigBool = thisDataSet.Tables["objects"].Columns.Contains("captConf");
                                foreach (var v in thisDataSet.Tables["objects"].Columns)
                                {
                                    var vc = (DataColumn)v;
                                    if (vc.ColumnName == "number")
                                        isNumber = true;
                                    if (vc.ColumnName == "idslave")
                                    {
                                        if (vc.DataType.Name != "String")
                                            MessageBox.Show(
                                                @"Неверно указан тип данных в столбце 'ismaster'",
                                                _mSwAddin.MyTitle, MessageBoxButtons.OK,
                                                MessageBoxIcon.Information);
                                        isIdSlave = true;
                                    }
                                    if (vc.ColumnName == "mainasmconf" &&
                                        _swSelModel.GetConfigurationCount() > 1)
                                        isAsmConfig = true;
                                    if (vc.ColumnName == "fixedvalues")
                                        isFixedValues = true;
                                }
                                thisDataSet.Clear();

                                if (Properties.Settings.Default.CheckParamLimits &&
                                    oleSchem.Rows.Cast<DataRow>().Any(
                                        row => (string)row["TABLE_NAME"] == "dimlimits"))
                                {
                                    testAdapter = new OleDbDataAdapter("SELECT * FROM dimlimits", oleDb);
                                    testAdapter.Fill(thisDataSet, "dimlimits");
                                    testAdapter.Dispose();
                                    foreach (var v in thisDataSet.Tables["dimlimits"].Columns)
                                    {
                                        var vc = (DataColumn)v;
                                        _namesOfColumnNameFromDimLimits.Add(vc.ColumnName);
                                    }
                                    thisDataSet.Clear();
                                }

                                string currentConf = _swSelComp.ReferencedConfiguration;

                                cm = isNumber
                                         ? new OleDbCommand(
                                               "SELECT * FROM objects WHERE number>0 ORDER BY number",
                                               oleDb)
                                         : new OleDbCommand("SELECT * FROM objects ORDER BY id", oleDb);

                                rd = cm.ExecuteReader();

                                #region Размеры

                                #region Считывание данных из objects

                                int k = 1;
                                var dictWithDiscretValues = new Dictionary<string, List<int>>();

                                while (rd.Read())
                                {
                                    if (captConfigBool && rd["captConf"] != null && rd["captConf"].ToString() != "all" && rd["captConf"].ToString() != currentConf && !string.IsNullOrEmpty(rd["captConf"].ToString()))
                                        continue;
                                    if (rd["caption"].ToString() == null || rd["caption"].ToString() == "" ||
                                        rd["caption"].ToString().Trim() == "")
                                        continue;

                                    #region Обработка поля mainasmconf

                                    if (isAsmConfig)
                                    {
                                        var neededConf = rd["mainasmconf"].ToString();
                                        bool isNeededConf = neededConf.Split('+').Select(v => v.Trim()).Any(
                                            f => f == currentConf);
                                        if (neededConf == "all")
                                            isNeededConf = true;
                                        if (!isNeededConf)
                                            continue;
                                    }

                                    #endregion

                                    string strObjName = rd["name"].ToString();

                                    double strObjVal;
                                    if (_swSelModel.GetPathName().Contains("_SWLIB_BACKUP"))
                                    {
                                        string pn = Path.GetFileNameWithoutExtension(_swSelModel.GetPathName());
                                        string last3 = pn.Substring(pn.Length - 4, 4);
                                        string[] arr = strObjName.Split('@');
                                        if (arr.Length != 3)
                                            throw new Exception("что-то не так");
                                        arr[2] = Path.GetFileNameWithoutExtension(arr[2]) + last3 + Path.GetExtension(arr[2]);
                                        strObjName = string.Format("{0}@{1}@{2}", arr[0], arr[1], arr[2]);
                                    }
                                    if (_mSwAddin.GetObjectValue(_swSelModel, strObjName, (int)rd["type"],
                                                                 out strObjVal))
                                    {
                                        int val = GetCorrectIntValue(strObjVal);

                                        int number = isNumber ? (int)rd["number"] : (int)rd["id"];
                                        while (number != k && _dimensionConfig.Count != 0)
                                        {
                                            listForDimensions.AddRange(
                                                from dimensionConfiguration in _dimensionConfig
                                                where dimensionConfiguration.Number == k
                                                select
                                                    new DimensionConfForList(dimensionConfiguration.Number,
                                                                             dimensionConfiguration.Caption,
                                                                             "", -1,
                                                                             GetListIntFromString(
                                                                                 dimensionConfiguration.
                                                                                     IdSlave),
                                                                             dimensionConfiguration.
                                                                                 Component,
                                                                             false,
                                                                             dimensionConfiguration.Id));
                                            //Logging.Log.Instance.Debug("listForDimensions1:" + listForDimensions.Count.ToString());
                                            k++;
                                        }

                                        var listId = new List<int>();
                                        try
                                        {
                                            if (isIdSlave)
                                                listId = GetListIntFromString((string)rd["idslave"]);
                                        }
                                        catch
                                        {
                                            listId = null;
                                        }
                                        string labelName;
                                        try
                                        {
                                            labelName = rd["caption"].ToString();
                                        }
                                        catch
                                        {
                                            string[] strObjNameParts = strObjName.Split('@');
                                            labelName = strObjNameParts[0];
                                        }

                                        if (isFixedValues)
                                        {
                                            try
                                            {
                                                var arr = (string)rd["fixedvalues"];
                                                string[] arrs = arr.Split(',');
                                                var list = arrs.Select(s => Convert.ToInt32(s)).ToList();
                                                if (!dictWithDiscretValues.ContainsKey(strObjName))
                                                    dictWithDiscretValues.Add(strObjName, list);
                                            }
                                            catch { }
                                        }

                                        listForDimensions.Add(new DimensionConfForList(number, labelName,
                                                                                       strObjName, val,
                                                                                       listId,
                                                                                       null,
                                                                                       (bool)rd["ismaster"],
                                                                                       (int)rd["id"]));
                                        //Logging.Log.Instance.Debug("listForDimensions2:" + listForDimensions.Count.ToString());
                                        k++;
                                    }
                                }
                                rd.Close();

                                #endregion

                                listForDimensions.AddRange(
                                    _dimensionConfig.Where(x => x.Number >= k).Select(
                                        b =>
                                        new DimensionConfForList(b.Number, b.Caption, "", -1,
                                                                 GetListIntFromString(b.IdSlave),
                                                                 b.Component,
                                                                 false,
                                                                 b.Id)));
                                listForDimensions.Sort((x, y) => x.Number.CompareTo(y.Number));
                                //Logging.Log.Instance.Debug("listForDimensions3:" + listForDimensions.Count.ToString());
                                foreach (var dimensionConfForList in listForDimensions)
                                {
                                    var lblNew = new Label { Size = new Size(125, 24) };
                                    lblNew.Location = new Point(0, 48 + i * (lblNew.Size.Height + 6));
                                    lblNew.Name = "lblPrm" + i;
                                    lblNew.TextAlign = ContentAlignment.MiddleRight;
                                    lblNew.Text = dimensionConfForList.LabelName;
                                    lblNew.Tag = dimensionConfForList.StrObjName;
                                    tbpParams.Controls.Add(lblNew);
                                    _lblPrm.AddLast(lblNew);

                                    downPos = lblNew.Location.Y + lblNew.Size.Height;
                                    if (dimensionConfForList.StrObjName != "")
                                    {
                                        #region TextBox с размерами

                                        if (dictWithDiscretValues.ContainsKey(dimensionConfForList.StrObjName))
                                        {
                                            #region Если дискретные значения
                                            var comboBoxWithDiscretValues = new ComboBox
                                            {
                                                Size = new Size(53, 24),
                                                Location =
                                                    new Point(
                                                    lblNew.Location.X +
                                                    lblNew.Size.Width + 4,
                                                    lblNew.Location.Y),
                                                Tag = dimensionConfForList.StrObjName,
                                                TabIndex = i
                                            };

                                            int val = dimensionConfForList.ObjVal;

                                            foreach (int vals in dictWithDiscretValues[dimensionConfForList.StrObjName])
                                            {
                                                int ordNumb = comboBoxWithDiscretValues.Items.Add(vals);
                                                if (vals == val)
                                                    comboBoxWithDiscretValues.SelectedIndex = ordNumb;
                                            }

                                            tbpParams.Controls.Add(comboBoxWithDiscretValues);

                                            _comboBoxListForRedraw.Add(comboBoxWithDiscretValues,
                                                                       dimensionConfForList.IdSlave);
                                            comboBoxWithDiscretValues.SelectedIndexChanged +=
                                            ComboBoxWithDiscretValuesSelectedIndexChanged;
                                            #endregion
                                        }
                                        else
                                        {
                                            #region Если обычные значения
                                            int val = GetCorrectIntValue(dimensionConfForList.ObjVal);

                                            var txtNew = new TextBox
                                            {
                                                Size = new Size(35, 24),
                                                Location =
                                                    new Point(
                                                    lblNew.Location.X + lblNew.Size.Width +
                                                    4,
                                                    lblNew.Location.Y),
                                                Name =
                                                    lblNew.Text + "@" +
                                                    dimensionConfForList.ObjVal,
                                                Text = val.ToString(),
                                                TextAlign = HorizontalAlignment.Right,
                                                Tag = dimensionConfForList.StrObjName,
                                                TabIndex = i
                                            };

                                            _numbAndTextBoxes.Add(dimensionConfForList.Id, txtNew);
                                            if (!dimensionConfForList.IsGrey)
                                                txtNew.ReadOnly = true;
                                            else
                                            {
                                                _textBoxListForRedraw.Add(txtNew,
                                                                          dimensionConfForList.IdSlave);
                                                txtNew.KeyDown += TxtPrmKeyDown;
                                                txtNew.TextChanged += TxtNewTextChanged;

                                                var btnNew = new Button
                                                {
                                                    ImageKey = @"Units1.ico",
                                                    ImageList = imageList1,
                                                    Size = new Size(24, 24),
                                                    Location =
                                                        new Point(
                                                        txtNew.Location.X +
                                                        txtNew.Size.Width +
                                                        4,
                                                        lblNew.Location.Y),
                                                    Name =
                                                        dimensionConfForList.ObjVal.
                                                        ToString(),
                                                    Text = "",
                                                    Tag = txtNew.Name,
                                                    Enabled = false
                                                };

                                                if (!_butPlusTxt.ContainsKey(btnNew))
                                                    _butPlusTxt.Add(btnNew, txtNew);

                                                tbpParams.Controls.Add(btnNew);
                                                _btnPrm.AddLast(btnNew);

                                                btnNew.Click += MeasureLength;

                                                #region если есть таблица ref_objects  и в ней есть хоть одна строка с соотв-щем id
                                                if (refobj == null)
                                                {
                                                    refobj = new List<ref_object>();
                                                    if (oleSchem.Rows.Cast<DataRow>().Any(row => (string)row["TABLE_NAME"] == "ref_objects_axe"))
                                                    {

                                                        cm = new OleDbCommand("SELECT * FROM ref_objects  LEFT JOIN ref_objects_axe  ON ref_objects_axe.id=ref_objects.objectsId", oleDb);
                                                        rd = cm.ExecuteReader();

                                                        while (rd.Read())
                                                        {
                                                            refobj.Add(new ref_object((string)rd["componentName"], (int)rd["objectsId"], (string)rd["axe"], (float)rd["correctionLeft_Up"], (float)rd["correctionRight_Down"]));
                                                        }
                                                        rd.Close();
                                                    }
                                                }
                                                ref_object[] currentrefs = refobj.Where(d => d.ObjectId == dimensionConfForList.Id).ToArray();
                                                if (currentrefs.Length > 0)
                                                {
                                                    //добавить кнопку
                                                    //выбрать из refobj только dimensionConfigForList.Id
                                                    var btnRef = new Button
                                                    {
                                                        ImageKey = @"expand.gif",
                                                        ImageList = imageList1,
                                                        Size = new Size(24, 24),
                                                        Location =
                                                            new Point(
                                                            txtNew.Location.X +
                                                            txtNew.Size.Width + btnNew.Size.Width +
                                                            8,
                                                            lblNew.Location.Y),
                                                        Name =
                                                            dimensionConfForList.ObjVal.
                                                            ToString(),
                                                        Text = "",
                                                        Tag = currentrefs,
                                                        Enabled = true
                                                    };

                                                    tbpParams.Controls.Add(btnRef);
                                                    //_btnPrm.AddLast(btnNew);

                                                    btnRef.Click += ExpandBtn;
                                                    if (!_butPlusTxt.ContainsKey(btnRef))
                                                        _butPlusTxt.Add(btnRef, txtNew);
                                                }
                                                #endregion
                                            }
                                            tbpParams.Controls.Add(txtNew);
                                            _commonList.Add(txtNew);

                                            #endregion
                                        }

                                        #endregion
                                    }
                                    else
                                    {
                                        #region ComboBox с конфигурациями

                                        var cmp = dimensionConfForList.Component;
                                        var comboBoxConfForDimTab = new ComboBox
                                        {
                                            Size = new Size(56, 24),
                                            Location =
                                                new Point(
                                                lblNew.Location.X +
                                                lblNew.Size.Width + 4,
                                                lblNew.Location.Y),
                                            Tag = cmp,
                                            TabIndex = i
                                        };

                                        var confNames =
                                            (string[])cmp.IGetModelDoc().GetConfigurationNames();
                                        foreach (var confName in confNames)
                                        {
                                            int lonhName = confName.Length * 6;
                                            if (comboBoxConfForDimTab.DropDownWidth < lonhName)
                                                comboBoxConfForDimTab.DropDownWidth = lonhName;
                                            comboBoxConfForDimTab.Items.Add(confName);
                                        }
                                        comboBoxConfForDimTab.SelectedItem = cmp.ReferencedConfiguration;
                                        tbpParams.Controls.Add(comboBoxConfForDimTab);

                                        _comboBoxListForRedraw.Add(comboBoxConfForDimTab,
                                                                   dimensionConfForList.IdSlave);

                                        comboBoxConfForDimTab.SelectedIndexChanged +=
                                            ComboBoxConfForDimTabSelectedIndexChanged;

                                        #endregion
                                    }
                                    i++;
                                }

                                #region Добавить выбор конфигурации
                                try
                                {
                                    if (_swSelModel.GetConfigurationCount() > 1)
                                    {
                                        var lblNew = new Label { Size = new Size(125, 24) };
                                        lblNew.Location = new Point(0, 48 + i * (lblNew.Size.Height + 6));
                                        lblNew.Name = "lblPrm" + i;
                                        lblNew.TextAlign = ContentAlignment.MiddleRight;
                                        lblNew.Text = "Конфигурации:";
                                        tbpParams.Controls.Add(lblNew);
                                        //lblNew.Tag = dimensionConfForList.StrObjName;
                                        downPos = lblNew.Location.Y + lblNew.Size.Height;
                                        string[] configurations = _swSelModel.GetConfigurationNames();
                                        var comboBoxConfig = new ComboBox
                                        {
                                            Size = new Size(56, 24),
                                            Location = new Point(lblNew.Location.X + lblNew.Size.Width + 4, lblNew.Location.Y),
                                        };
                                        string activeConf = _swSelComp.ReferencedConfiguration;//_swSelModel.IGetActiveConfiguration().Name;
                                        foreach (var configuration in configurations)
                                        {
                                            int currentIndex = comboBoxConfig.Items.Add(configuration);
                                            if (configuration == activeConf)
                                                comboBoxConfig.SelectedIndex = currentIndex;
                                        }
                                        Size size = TextRenderer.MeasureText(activeConf, comboBoxConfig.Font);
                                        int lonhName = size.Width; //nameOfConfiguration.Length * 5;
                                        if (comboBoxConfig.DropDownWidth < lonhName)
                                            comboBoxConfig.DropDownWidth = lonhName;
                                        tbpParams.Controls.Add(comboBoxConfig);
                                        comboBoxConfig.SelectedIndexChanged += ConfigurationChanged;
                                    }
                                }
                                catch
                                { }

                                #endregion
                                #endregion
                                _dictHeightPage.Add(tbpParams, downPos);
                            }

                            #endregion
                            #region Если есть comments
                            if (oleSchem.Rows.Cast<DataRow>().Any(
                               row => (string)row["TABLE_NAME"] == "comments"))
                            {
                                cm = new OleDbCommand("SELECT * FROM comments ORDER BY id", oleDb);
                                rd = cm.ExecuteReader();
                                if (rd.Read())
                                {
                                    try
                                    {
                                        CommentLayout.Visible = true;
                                        WarningPB.Visible = (bool)rd["showSimbol"];
                                        commentsTb.Text = (string)rd["comment"];

                                        Size size = TextRenderer.MeasureText(commentsTb.Text, commentsTb.Font);

                                        commentsTb.Height = (size.Width / (commentsTb.Width - 10)) * 30;

                                    }
                                    catch
                                    {
                                        CommentLayout.Visible = false;
                                    }
                                }
                                rd.Close();

                            }
                            else
                            {
                                CommentLayout.Visible = false;
                            }
                            #endregion

                            #region Decors

                            if (!ReloadDecorTab(oleDb, oleSchem))
                                return;

                            #endregion

                            oleDb.Close();

                            #endregion
                        }
                    }
                    else
                        if (_tabDec != null)
                            tabMain.Controls.Remove(_tabDec);

                    var swFeat = (Feature)_swSelModel.FirstFeature();
                    i = 0;

                    #region Position

                    var mates = _swSelComp.GetMates();
                    Dictionary<string, Mate2> existingMates = new Dictionary<string, Mate2>();
                    if (mates != null)
                    {
                        foreach (var mate in mates)
                        {
                            if (mate is Mate2)
                            {
                                var spec = (Mate2)mate;
                                int mec = spec.GetMateEntityCount();
                                if (mec > 1)
                                {
                                    for (int ik = 0; ik < mec; ik++)
                                    {
                                        MateEntity2 me = spec.MateEntity(ik);
                                        if (me.ReferenceComponent.Name.Contains(_swSelComp.Name))
                                        {
                                            Entity tt = me.Reference;
                                            var tt2 = tt as Feature;

                                            if (tt is RefPlane && tt2 != null)
                                            {

                                                if (!existingMates.ContainsKey(tt2.Name))
                                                    existingMates.Add(tt2.Name, spec);
                                            }

                                        }
                                    }
                                }
                            }
                        }
                    }

                    int downPosPosition = 0;
                    int tabIndex = 0;
                    while (swFeat != null)
                    {
                        if (swFeat.GetTypeName2() == "RefPlane")
                        {
                            string strPlaneName = swFeat.Name;

                            if (strPlaneName.Length > 1)
                            {
                                if (strPlaneName.Substring(0, 1) == "#")
                                {
                                    var btnNew = new Button { Size = new Size(120, 20) };
                                    btnNew.Location = new Point(62, 24 + i * (btnNew.Size.Height + 6));
                                    //if (Properties.Settings.Default.KitchenModeOn)
                                    //    btnNew.Name = strPlaneName;//"btnPos" + i;
                                    //else
                                    btnNew.Name = "btnPos" + i;

                                    btnNew.Text = strPlaneName.Substring(5);
                                    btnNew.Tag = strPlaneName;
                                    btnNew.TabIndex = tabIndex;
                                    tabIndex++;
                                    tbpPos.Controls.Add(btnNew);
                                    btnNew.Click += AddMate;
                                    downPosPosition = btnNew.Location.Y + btnNew.Size.Height;
                                    if (existingMates.ContainsKey(strPlaneName))
                                    {
                                        //добавить кнопку для отвязки
                                        var btnDeattach = new Button { Size = new Size(20, 20) };
                                        btnDeattach.Location = new Point(62 + btnNew.Size.Width + 10, 24 + i * (btnNew.Size.Height + 6));
                                        btnDeattach.Name = strPlaneName;
                                        btnDeattach.Text = "X";
                                        btnDeattach.Tag = existingMates[strPlaneName];
                                        tbpPos.Controls.Add(btnDeattach);
                                        btnDeattach.Click += DeleteMate;
                                    }
                                    i++;

                                }
                            }
                        }
                        swFeat = (Feature)swFeat.GetNextFeature();
                    }
                    _dictHeightPage.Add(tbpPos, downPosPosition);

                    #endregion

                    if (_lblPrm.Count == 0)
                    {
                        tabMain.SelectTab(tbpPos);
                        downPos = downPosPosition;
                        SetSizeForTab(downPos);
                        if (tabMain.Controls.Contains(tbpParams))
                        {
                            tabMain.Controls.Remove(tbpParams);
                            //Logging.Log.Instance.Fatal("Вкладка на РПД не показана.Смотреть listForDimensions");
                        }
                    }
                    if (rbMode1 != null && rbMode2 != null)
                    {
                        if (controlsToHideWhenChangeMode == null || controlsToHideWhenChangeMode.Count == 0)
                            pnlMode.Visible = false;
                        if (Properties.Settings.Default.DefaultRPDView)
                        {
                            rbMode1.CheckedChanged += new EventHandler(ModeCheckedChanged);
                            rbMode1.Checked = true;
                        }
                        else
                        {
                            rbMode2.Checked = true;
                            rbMode1.CheckedChanged += new EventHandler(ModeCheckedChanged);
                        }
                    }
                    SetSizeForTab(_dictHeightPage[tabMain.SelectedTab]);
                }
            }
        }
예제 #2
0
        private decimal execQueryNonProduct(string sql, ModelDoc2 swSelModel)
        {
            string currentConfig = swSelModel.IGetActiveConfiguration().Name;
            if (currentConfig.ToLower().Contains("по умолчани") || currentConfig.ToLower().Contains("default"))
                currentConfig = string.Empty;
            string articul = swSelModel.GetCustomInfoValue(currentConfig, "Articul");
            if (string.IsNullOrEmpty(articul))
            {
                articul = swSelModel.GetCustomInfoValue(string.Empty, "Articul");
                if (string.IsNullOrEmpty(articul))
                    throw new ArticleNotFoundException("Отсутствует артикул!", swSelModel);
            }
            int size1Work = 0, size2Work = 0, size1 = 0, size2 = 0;
            string idColor1 = string.Empty, idColor2 = string.Empty, idColor3 = string.Empty, faner11 = string.Empty, faner12 = string.Empty, faner21 = string.Empty, faner22 = string.Empty, colorfaner11 = string.Empty, colorfaner12 = string.Empty, colorfaner21 = string.Empty, colorfaner22 = string.Empty;
            FillForNonProductQuery(swSelModel, string.Empty, ref size1, ref size2, ref size1Work, ref size2Work, ref idColor1, ref idColor2, ref idColor3, ref faner11, ref faner12, ref faner21, ref faner22, ref colorfaner11, ref colorfaner12, ref colorfaner21, ref colorfaner22);
            if (currentConfig != string.Empty)
                FillForNonProductQuery(swSelModel, currentConfig, ref size1, ref size2, ref size1Work, ref size2Work, ref idColor1, ref idColor2, ref idColor3, ref faner11, ref faner12, ref faner21, ref faner22, ref colorfaner11, ref colorfaner12, ref colorfaner21, ref colorfaner22);

            using (OracleCommand cmd = new OracleCommand(sql))
            {
                cmd.Connection = Connection;
                cmd.CommandType = CommandType.Text;
                cmd.BindByName = true;
                cmd.Parameters.Add(new OracleParameter("P_NUMAGREE", _orderNumber));//"040714-1255-0101"));
                cmd.Parameters.Add(new OracleParameter("P_IDCOMPONENT", articul));
                cmd.Parameters.Add(new OracleParameter("P_SIZE1", size1));
                cmd.Parameters.Add(new OracleParameter("P_SIZE2", size2));
                var curPrm = new OracleParameter("P_SIZE1WORK", OracleDbType.Int32, ParameterDirection.Input);
                curPrm.Value = size1Work;
                cmd.Parameters.Add(curPrm);
                curPrm = new OracleParameter("P_SIZE2WORK", OracleDbType.Int32, ParameterDirection.Input);
                curPrm.Value = size2Work;
                cmd.Parameters.Add(curPrm);
                cmd.Parameters.Add(new OracleParameter("P_IDCOLOR1", idColor1));
                cmd.Parameters.Add(new OracleParameter("P_IDCOLOR2", idColor2));
                cmd.Parameters.Add(new OracleParameter("P_IDCOLOR3", idColor3));
                cmd.Parameters.Add(new OracleParameter("P_IDFANER11", faner11));
                cmd.Parameters.Add(new OracleParameter("P_IDFANER12", faner12));
                cmd.Parameters.Add(new OracleParameter("P_IDCOLORFANER11", colorfaner11));
                cmd.Parameters.Add(new OracleParameter("P_IDCOLORFANER12", colorfaner12));
                cmd.Parameters.Add(new OracleParameter("P_IDFANER21", faner21));
                cmd.Parameters.Add(new OracleParameter("P_IDFANER22", faner22));
                cmd.Parameters.Add(new OracleParameter("P_IDCOLORFANER21", colorfaner21));
                cmd.Parameters.Add(new OracleParameter("P_IDCOLORFANER22", colorfaner22));
                cmd.Parameters.Add(new OracleParameter("P_ITPRODCALCPARENT", DBNull.Value));
                OracleDataReader reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    if (reader["PRICE"] is decimal)
                        return (decimal)reader["PRICE"];
                    else
                        return 0;
                }
                else
                    throw new Exception("Ошибка соединения с БД.");
            }
        }
예제 #3
0
        //через открытое соединение
        private decimal execQueryProduct(string sql, ModelDoc2 swSelModel)
        {
            string currentConfig = swSelModel.IGetActiveConfiguration().Name;
            if (currentConfig.ToLower().Contains("по умолчани") || currentConfig.ToLower().Contains("default"))
                currentConfig = string.Empty;
            string articul = swSelModel.GetCustomInfoValue(currentConfig, "Articul");
            if (string.IsNullOrEmpty(articul))
            {
                articul = swSelModel.GetCustomInfoValue(string.Empty, "Articul");
                if (string.IsNullOrEmpty(articul))
                    throw new ArticleNotFoundException("Отсутствует артикул!", swSelModel);
            }
            int size1 = 0, size2 = 0, size3 = 0, size4 = 0, size5 = 0, size6 = 0, size7 = 0, size8 = 0;
            string idColor1 = string.Empty, idColor2 = string.Empty, idColor3 = string.Empty, idColor4 = string.Empty, idColor5 = string.Empty;
            FillForProductQuery(swSelModel, string.Empty, ref size1, ref size2, ref size3, ref size4, ref size5, ref size6, ref size7, ref size8, ref idColor1, ref idColor2, ref idColor3, ref idColor4, ref idColor5);
            if (currentConfig != string.Empty)
                FillForProductQuery(swSelModel, currentConfig, ref size1, ref size2, ref size3, ref size4, ref size5, ref size6, ref size7, ref size8, ref idColor1, ref idColor2, ref idColor3, ref idColor4, ref idColor5);

            using (OracleCommand cmd = new OracleCommand(sql))
            {
                cmd.Connection = Connection;
                cmd.CommandType = CommandType.Text;
                cmd.BindByName = true;
                cmd.Parameters.Add(new OracleParameter("P_NUMAGREE", _orderNumber));//"040714-1255-0101"));
                cmd.Parameters.Add(new OracleParameter("P_IDCOMPONENT", articul));
                cmd.Parameters.Add(new OracleParameter("P_SIZE1", size1));
                cmd.Parameters.Add(new OracleParameter("P_SIZE2", size2));
                cmd.Parameters.Add(new OracleParameter("P_SIZE3", size3));
                cmd.Parameters.Add(new OracleParameter("P_SIZE4", size4));
                cmd.Parameters.Add(new OracleParameter("P_SIZE5", size5));
                cmd.Parameters.Add(new OracleParameter("P_SIZE6", size6));
                cmd.Parameters.Add(new OracleParameter("P_SIZE7", size7));
                cmd.Parameters.Add(new OracleParameter("P_SIZE8", size8));

                cmd.Parameters.Add(new OracleParameter("P_IDCOLOR1", idColor1));
                cmd.Parameters.Add(new OracleParameter("P_IDCOLOR2", idColor2));
                cmd.Parameters.Add(new OracleParameter("P_IDCOLOR3", idColor3));
                cmd.Parameters.Add(new OracleParameter("P_IDCOLOR4", idColor4));
                cmd.Parameters.Add(new OracleParameter("P_IDCOLOR5", idColor5));

                OracleDataReader reader = cmd.ExecuteReader();

                if (reader.Read())
                {
                    if (reader["PRICE"] is decimal)
                        return (decimal)reader["PRICE"];
                    else
                        throw new Exception("Неправильный результат цены:" + reader["PRICE"]);
                }
                else
                    throw new Exception("Ошибка соединения с БД.");
            }
        }
예제 #4
0
        private void FixColorForEachComponent(ModelDoc2 model, Component2 component, string file,
                                              LinkedList<ModelDoc2> models)
        {
            try
            {
                var swConfig = model.IGetActiveConfiguration();
                object displayStateNames = swConfig.GetDisplayStates();
                var dispNames = (string[])displayStateNames;

                var mod = component.IGetModelDoc();
                if (mod != null && mod.GetType() == (int)swDocumentTypes_e.swDocASSEMBLY && models.Contains(mod))
                {
                    if (component.SetTextureByDisplayState(dispNames[0], mod.Extension.CreateTexture(file, 1, 0, false)))
                        component.RemoveTextureByDisplayState(dispNames[0]);

                    var assembly = (AssemblyDoc)mod;
                    var oComps = assembly.GetComponents(true);
                    foreach (var oComp in oComps)
                    {
                        var comp = (Component2)oComp;
                        FixColorForEachComponent(mod, comp, file, models);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
예제 #5
0
        private void getPriceForComponent(ModelDoc2 model, bool ParentCalcStruct, Action<decimal> nextPrice, Action<Exception, string> nextError)
        {
            string currentConfig = model.IGetActiveConfiguration().Name;

            if (currentConfig.ToLower().Contains("по умолчани") || currentConfig.ToLower().Contains("default"))
                currentConfig = string.Empty;

            string isProduct = model.GetCustomInfoValue(currentConfig, "IsProduct");
            if (string.IsNullOrEmpty(isProduct))
            {
                isProduct = model.GetCustomInfoValue(string.Empty, "IsProduct");
                if (string.IsNullOrEmpty(isProduct))
                    isProduct = "No";
            }

            if (isProduct == "Yes")
            {
                //изделие

                //Проверка существования артикула для компонента в случает отсутствия, расчет цены на сам компонент не производится
                string articul = model.GetCustomInfoValue(string.Empty, "Articul");
                if (string.IsNullOrEmpty(articul))
                    articul = model.GetCustomInfoValue(currentConfig, "Articul");

                if (!string.IsNullOrEmpty(articul))
                {
                    try
                    {
                        nextPrice(сalculatePriceForModel(model));
                    }
                    catch (Exception e)
                    {
                        if (checkError(e))
                            nextError(e, Path.GetFileName(model.GetPathName()));
                    }
                }

                string s = model.GetPathName();
                AssemblyDoc model_assembly = model as AssemblyDoc;
                if (model_assembly != null)
                {
                    bool calcStruct = true;
                    if (!string.IsNullOrEmpty(articul))
                    {
                        string calcStructStr = model.get_CustomInfo2(string.Empty, "CalcStruct");
                        if (calcStructStr.ToLower() == "no")
                            calcStruct = false;
                    }

                    var components = (object[])((AssemblyDoc)model).GetComponents(true);
                    foreach (var component in components)
                    {
                        var comp = (Component2)component;
                        ModelDoc2 _model = comp.IGetModelDoc();
                        if (_model != null)
                        {
                            getPriceForComponent(_model, calcStruct, nextPrice, nextError);
                        }
                    }
                }
            }
            else
            {
                //не изделие

                string articul = model.GetCustomInfoValue(string.Empty, "Articul");
                if (string.IsNullOrEmpty(articul))
                    articul = model.GetCustomInfoValue(currentConfig, "Articul");

                string isIndependentStr = model.get_CustomInfo2(string.Empty, "IsIndependent");
                bool isIndependent = true;
                if (string.IsNullOrEmpty(isIndependentStr) || isIndependentStr.ToLower() == "no")
                    isIndependent = false;

                if (isIndependent)
                {
                    bool calcStruct = true;
                    if (!string.IsNullOrEmpty(articul))
                    {
                        //независимый и с артикулом
                        try
                        {
                            nextPrice(сalculatePriceForModel(model));
                        }
                        catch (Exception e)
                        {
                            if (checkError(e))
                                nextError(e, Path.GetFileName(model.GetPathName()));
                        }
                        string calcStructStr = model.get_CustomInfo2(string.Empty, "CalcStruct");

                        if (calcStructStr.ToLower() == "no")
                            calcStruct = false;
                    }

                    if (calcStruct)
                    {
                        AssemblyDoc model_assembly = model as AssemblyDoc;
                        if (model_assembly != null)
                        {
                            var components = (object[])((AssemblyDoc)model).GetComponents(true);
                            foreach (var component in components)
                            {
                                var comp = (Component2)component;
                                ModelDoc2 _model = comp.IGetModelDoc();
                                if (_model != null)
                                {
                                    getPriceForComponent(_model, calcStruct, nextPrice, nextError);
                                }
                            }
                        }
                    }
                }
                else
                {
                    //компонент входит в состав изделия
                    if (ParentCalcStruct)
                    {
                        //нужно получить цену
                        bool calcStruct = true;
                        if (!string.IsNullOrEmpty(articul))
                        {
                            try
                            {
                                nextPrice(сalculatePriceForModel(model));
                            }
                            catch (Exception e)
                            {
                                if (checkError(e))
                                    nextError(e, Path.GetFileName(model.GetPathName()));
                            }
                            string calcStructStr = model.get_CustomInfo2(string.Empty, "CalcStruct");
                            if (calcStructStr.ToLower() == "no")
                                calcStruct = false;
                        }

                        AssemblyDoc model_assembly = model as AssemblyDoc;
                        if (model_assembly != null)
                        {
                            var components = (object[])((AssemblyDoc)model).GetComponents(true);
                            foreach (var component in components)
                            {
                                var comp = (Component2)component;
                                ModelDoc2 _model = comp.IGetModelDoc();
                                if (_model != null)
                                {
                                    getPriceForComponent(_model, calcStruct, nextPrice, nextError);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (model as AssemblyDoc != null)
                        {
                            var components = (object[])((AssemblyDoc)model).GetComponents(true);
                            foreach (var component in components)
                            {
                                var comp = (Component2)component;
                                ModelDoc2 _model = comp.IGetModelDoc();
                                if (_model != null)
                                {
                                    getPriceForComponent(_model, false, nextPrice, nextError);
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #6
0
 private bool CheckPropForArticul(ModelDoc2 model)
 {
     bool ret = false;
     var commonPropNames = (string[])model.GetCustomInfoNames();
     foreach (var commonPropName in commonPropNames)
     {
         if (commonPropName.ToLower() == "articul" && model.GetCustomInfoValue("", commonPropName) != "")
             ret = true;
     }
     if (model.GetConfigurationCount() >= 1)
     {
         string confName = model.IGetActiveConfiguration().Name;
         var confPropNames = (string[])model.GetCustomInfoNames2(confName);
         foreach (var confPropName in confPropNames)
         {
             if (confPropName.ToLower() == "articul" && model.GetCustomInfoValue(confName, confPropName) != "")
                 ret = true;
         }
     }
     return ret;
 }
예제 #7
0
        public bool SetObjectValue(ModelDoc2 inModel, string inName, int inType, double inVal, bool noArtIfSuppressed = false)
        {
            object swObj;
            Dimension swDim;
            Feature swFeature;
            Component2 swComp;
            bool ret = false;

            if (GetObjectByName(inModel, inName, inType, out swObj))
            {
                double dTestVal;
                switch (inType)
                {
                    case 14:
                        swDim = (Dimension)swObj;
                        dTestVal = swDim.GetSystemValue2("") * 1000;

                        if (dTestVal != inVal)
                        {
                            ret = (swDim.SetSystemValue2(inVal / 1000,
                                                         (int)
                                                         swSetValueInConfiguration_e.swSetValue_InAllConfigurations) ==
                                   (int)swSetValueReturnStatus_e.swSetValue_Successful);
                        }
                        else
                            ret = true;
                        break;

                    case 22:
                        swFeature = (Feature)swObj;
                        dTestVal = (swFeature.IsSuppressed() ? 0 : 1);

                        if (dTestVal != inVal)
                        {
                            //ret = swFeature.SetSuppression(inVal == 0 ? (int) swFeatureSuppressionAction_e.swSuppressFeature : (int)swFeatureSuppressionAction_e.swUnSuppressFeature);
                            ret =
                                swFeature.SetSuppression2(
                                    inVal == 0
                                        ? (int)swFeatureSuppressionAction_e.swSuppressFeature
                                        : (int)swFeatureSuppressionAction_e.swUnSuppressFeature,
                                    (int)swInConfigurationOpts_e.swAllConfiguration, inModel.GetConfigurationNames());

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

                            Component2 newComp = null;

                            var config = inModel.IGetActiveConfiguration();
                            if (config != null)
                            {
                                swComp = config.IGetRootComponent2();
                                if (swComp != null)
                                {
                                    var outComps = new LinkedList<Component2>();
                                    if (GetComponents(swComp, outComps, false, false))
                                    {
                                        foreach (var component2 in outComps)
                                        {
                                            var mod = component2.IGetModelDoc();
                                            if (mod != null)
                                            {
                                                var texture = component2.GetTexture("");
                                                if (mod.GetType() == (int)swDocumentTypes_e.swDocPART &&
                                                    texture != null)
                                                {
                                                    newComp = component2;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            if (newComp != null)
                            {
                                inModel.Save();
                                if (newComp.Select(false))
                                    ((AssemblyDoc)inModel).ComponentReload();
                            }

                            #endregion
                        }
                        else
                            ret = true;
                        break;

                    case 20:
                        swComp = (Component2)swObj;
                        try
                        {
                            if ((swComp.IsSuppressed() ? 0 : 1) == inVal)
                            {
                                ret = true;
                            }
                            else
                            {
                                int k = inVal == 0
                                            ? (int)swComponentSuppressionState_e.swComponentSuppressed
                                            : (int)swComponentSuppressionState_e.swComponentFullyResolved;

                                bool isCavity = false;
                                if (inVal == 0)
                                {
                                    var outC = new LinkedList<Component2>();
                                    if (GetComponents(swComp, outC, true, false))
                                    {
                                        isCavity =
                                            outC.Select(component2 => component2.IGetModelDoc()).Any(
                                                m => m != null && m.get_CustomInfo2("", "swrfIsCut") == "Yes");
                                    }
                                }
                                int tmp = k;
                                if (k == (int)swComponentSuppressionState_e.swComponentFullyResolved)
                                    tmp = swComp.SetSuppression2(k);
                                if (noArtIfSuppressed)
                                {
                                    //���� ���� ������, �� ������ �����..
                                    //���� ���� ��������- �� �������� ��..
                                    ModelDoc2 outModel;

                                    if (GetModelByName(inModel, inName, false, out outModel, true))
                                    {
                                        if (k == (int)swComponentSuppressionState_e.swComponentSuppressed)
                                        {
                                            //������� �������
                                            RenameCustomProperty(outModel, string.Empty, "Articul", "Noarticul");
                                        }
                                        else if (k == (int)swComponentSuppressionState_e.swComponentFullyResolved)
                                        {
                                            //����� �������
                                            RenameCustomProperty(outModel, string.Empty, "Noarticul", "Articul");
                                        }
                                    }
                                }
                                if (k == (int)swComponentSuppressionState_e.swComponentSuppressed)
                                    tmp = swComp.SetSuppression2(k);
                                k = tmp;

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

                                var equMrg = inModel.GetEquationMgr();
                                if (equMrg != null)
                                {
                                    var outList = new LinkedList<Component2>();
                                    if (GetComponents(inModel.IGetActiveConfiguration().IGetRootComponent2(), outList,
                                                      true,
                                                      false))
                                    {
                                        bool notSuppComp =
                                            outList.All(
                                                component2 =>
                                                !swComp.IsSuppressed() ||
                                                swComp.GetPathName() != component2.GetPathName() ||
                                                component2.IsSuppressed());
                                        for (int i = 0; i < inModel.GetEquationMgr().GetCount(); i++)
                                        {
                                            if (equMrg.Equation[i].Contains(
                                                Path.GetFileNameWithoutExtension(swComp.GetPathName())))
                                            {
                                                if ((equMrg.get_Suppression(i) ? 0 : 1) != inVal)
                                                {
                                                    equMrg.set_Suppression(i, inVal == 0 && notSuppComp);
                                                }
                                            }
                                        }
                                    }
                                }

                                #endregion

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

                                if (isCavity)
                                {
                                    LinkedList<Component2> swComps;
                                    List<Feature> list;
                                    if (_features.Count == 0 || _comps.Count == 0)
                                        list = GetAllCavitiesFeatures(out swComps);
                                    else
                                    {
                                        list = _features;
                                        swComps = _comps;
                                    }
                                    string nameMod = Path.GetFileNameWithoutExtension(inModel.GetPathName());

                                    var delList = (from component2 in swComps
                                                   where
                                                       component2.Name.Contains(nameMod) &&
                                                       component2.Name.Contains(swComp.Name)
                                                   from feature in list
                                                   where
                                                       component2.Name ==
                                                       GetSpecialNameFromFeature(feature.IGetFirstSubFeature().Name).
                                                           Split('/').First() + "/" +
                                                       GetSpecialNameFromFeature(feature.IGetFirstSubFeature().Name).
                                                           Split('/').ToArray()[1]
                                                   select feature).ToList();
                                    SwModel.ClearSelection();
                                    foreach (var feature in delList)
                                    {
                                        feature.Select(true);
                                    }
                                    SwModel.DeleteSelection(false);
                                }

                                #endregion

                                ret = (k == (int)swSuppressionError_e.swSuppressionChangeOk);
                            }
                        }
                        catch
                        {
                        }
                        break;
                }
            }
            return ret;
        }
예제 #8
0
파일: Decors.cs 프로젝트: digger1985/MyCode
        private static List<string> GetComponentsNamesOnConfiguration(SwAddin _mSwAddin, ModelDoc2 parentModel, int configNumber)
        {
            List<string> elems = new List<string>();

            OleDbConnection oleDb;
            if (_mSwAddin.OpenModelDatabase(parentModel, out oleDb))
            {
                using (oleDb)
                {
                    OleDbCommand cm = new OleDbCommand("SELECT * FROM decors WHERE Number = " + configNumber, oleDb);
                    OleDbDataReader rd = cm.ExecuteReader();
                    while (rd.Read())
                    {
                        elems.Add((string)rd["Element"]);
                    }
                    rd.Close();
                }
            }

            AssemblyDoc pmAssembly = parentModel as AssemblyDoc;
            if (pmAssembly != null)
            {
                var comps = new LinkedList<Component2>();
                _mSwAddin.GetComponents(parentModel.IGetActiveConfiguration().IGetRootComponent2(), comps, true, false);
                foreach (Component2 comp in comps)
                {
                    ModelDoc2 model = comp.IGetModelDoc();
                    AssemblyDoc aDoc = model as AssemblyDoc;
                    if (aDoc != null)
                        elems.AddRange(GetComponentsNamesOnConfiguration(_mSwAddin, model, configNumber));
                }
            }
            return elems;
        }
예제 #9
0
파일: Decors.cs 프로젝트: digger1985/MyCode
        internal static List<Component2> GetConfigComponents(SwAddin swAddin, ModelDoc2 model, int configNumber)
        {
            List<Component2> outComps = new List<Component2>();

            List<string> compsNames = GetComponentsNamesOnConfiguration(swAddin, model, configNumber);

            LinkedList<Component2> modelComponents = new LinkedList<Component2>();
            swAddin.GetComponents(model.IGetActiveConfiguration().IGetRootComponent2(), modelComponents, true, false);

            foreach (var component in modelComponents)
            {
                if (component.IsSuppressed()) continue;
                string compName = Path.GetFileNameWithoutExtension(swAddin.GetModelNameWithoutSuffix(component.GetPathName()));

                foreach (string name in compsNames)
                {
                    if (compName.Contains(name))
                    {
                        outComps.Add(component);
                        break;
                    }
                }
            }
            return outComps;
        }
예제 #10
0
파일: Decors.cs 프로젝트: digger1985/MyCode
        internal static List<ModelDoc2> GetAllModelsWithMdb(SwAddin mSwAddin, ModelDoc2 swModel)
        {
            UserProgressBar pb;
            mSwAddin.SwApp.GetUserProgressBar(out pb);
            var list = new List<ModelDoc2>();
            var outComps = new LinkedList<Component2>();
            var faulsMod = new List<ModelDoc2>();

            if (mSwAddin.GetComponents(swModel.IGetActiveConfiguration().IGetRootComponent2(),
                                        outComps, true, false))
            {
                pb.Start(0, outComps.Count, "Перебор деталей");
                int i = 0;
                foreach (var component in outComps)
                {
                    if (component.IsSuppressed())
                    {
                        i++;
                        pb.UpdateProgress(i);
                        continue;
                    }
                    var inModel = component.IGetModelDoc();
                    if (list.Contains(inModel))
                    {
                        i++;
                        pb.UpdateProgress(i);
                        continue;
                    }
                    var comp = component;

                    int errCount = 0;
                    while ((inModel == null || mSwAddin.GetModelDatabaseFileName(inModel) == "") && errCount < 10)
                    {
                        if (comp != null)
                        {
                            comp = comp.GetParent();
                            if (comp != null && !comp.IsSuppressed())
                            {
                                inModel = comp.IGetModelDoc();
                            }
                        }
                        errCount++;
                    }
                    if (errCount == 10 && inModel != null)
                    {
                        i++;
                        pb.UpdateProgress(i);
                        continue;
                    }

                    if (inModel != null &&
                        Path.GetFileNameWithoutExtension(inModel.GetPathName()).Contains("#"/* +
                                                                                         mSwAddin.GetXNameForAssembly()*/) &&
                        !list.Contains(inModel) && !faulsMod.Contains(inModel))
                        CheckMdbForDecors(mSwAddin, inModel, list, comp, faulsMod);

                    i++;
                    pb.UpdateProgress(i);
                }
                pb.End();
            }
            return list;
        }