Exemplo n.º 1
0
        private bool SetDecorsForEachDetail(Component2 component, string pathPictName, int number, bool fit = false)
        {
            if (component.IGetModelDoc().GetType() == (int)swDocumentTypes_e.swDocPART)
            {
                double angel = GetAngel(number, component) ? 0 : 90;

                var m = component.IGetModelDoc();
                var rmArr = (object[])m.Extension.GetRenderMaterials();
                RenderMaterial rm = null;
                object swEnt;
                string fileName = pathPictName.Substring(0, pathPictName.Length - 4) + ".p2m";
                if (rmArr == null)
                {
                    component.Select(false);
                    swEnt = (Entity)_swModel.ISelectionManager.GetSelectedObject6(1, -1);
                    _swModel.ClearSelection();
                    //rm = m.Extension.CreateRenderMaterial(fileName);
                }
                else
                {
                    if (_swSelModel.GetCustomInfoValue("", "ExtFanerFeats") == "Yes")
                        swEnt = m;
                    else
                    {
                        rm = (RenderMaterial)rmArr[0];
                        var ent = (object[])rm.GetEntities();
                        swEnt = ent[0];
                    }
                }
                rm = m.Extension.CreateRenderMaterial(fileName);
                rm.AddEntity(swEnt);
                rm.RotationAngle = angel;
                rm.TextureFilename = pathPictName;
                rm.FileName = fileName;
                rm.FixedAspectRatio = false;
                rm.FitWidth = false;
                rm.FitHeight = false;
                rm.Width = 0.3;
                rm.Height = 0.3;
                if (fit)
                {
                    double width = 1;
                    double height = 1;
                    object b = component.GetBox(true, true);
                    if (b != null)
                    {
                        var boxs = (double[])b;
                        double xs1 = boxs[0];
                        double ys1 = boxs[1];
                        double zs1 = boxs[2];
                        double xs2 = boxs[3];
                        double ys2 = boxs[4];
                        double zs2 = boxs[5];
                        double x = Math.Abs(xs1 - xs2);
                        double z = Math.Abs(zs1 - zs2);
                        double y = Math.Abs(ys1 - ys2);
                        if (y < x && y < z)
                        {
                            width = z;
                            height = x;
                        }
                        else if (x < z && x < y)
                        {
                            width = y;
                            height = z;
                        }
                        else if (z < x && z < y)
                        {
                            width = y;
                            height = x;
                        }
                    }
                    rm.Width = width;
                    rm.Height = height;
                    rm.FitWidth = true;
                    rm.FitHeight = true;
                }
                var swConfig = (Configuration)m.GetConfigurationByName(component.ReferencedConfiguration);
                object displayStateNames = swConfig.GetDisplayStates();
                int e1, e2;
                int f;
                //var texture = m.Extension.CreateTexture(pathPictName, 1, 0, false);
                //component.RemoveTexture(string.Empty);
                //component.SetTexture(string.Empty, texture);
                m.Extension.AddRenderMaterial(rm, out f);
                m.Extension.AddDisplayStateSpecificRenderMaterial(rm, (int)swDisplayStateOpts_e.swSpecifyDisplayState,
                                                                  displayStateNames, out e1, out e2);
                if (fit)
                    m.Save2(true);
                return true;
            }
            return false;
        }
Exemplo n.º 2
0
 private void ShowConfigurationDetails(Component2 component, ModelDoc2 model, string nameConfiguration)
 {
     if (SwAddin.needWait)
     {
         ProgressBar.WaitTime.Instance.ShowWait();
         ProgressBar.WaitTime.Instance.SetLabel("Ожидание завершения предедущих операций.");
         lock (SwAddin.workerLocker)
             Monitor.Wait(SwAddin.workerLocker);
         ProgressBar.WaitTime.Instance.HideWait();
     }
     if (component.Select(false) && ((AssemblyDoc)model).CompConfigProperties4(component.GetSuppression(), 0, true, true, nameConfiguration, false))
     {
         int err = 0, wrn = 0;
         var mod = _mSwAddin.SwApp.OpenDoc6(component.IGetModelDoc().GetPathName(),
                                            component.IGetModelDoc().GetType(), 0, nameConfiguration, ref err, ref wrn);
         var dict = new Dictionary<Component2, ModelDoc2>();
         if (mod != null)
         {
             mod.ShowConfiguration2(nameConfiguration);
             if (mod.GetType() == (int)swDocumentTypes_e.swDocASSEMBLY)
             {
                 var outList = new LinkedList<Component2>();
                 if (_mSwAddin.GetComponents(mod.IGetActiveConfiguration().IGetRootComponent2(), outList, true,
                                             false))
                 {
                     foreach (var component2 in outList)
                     {
                         if (mod.GetEquationMgr().GetCount() > 0)
                             for (int i = 0; i < mod.GetEquationMgr().GetCount(); i++)
                             {
                                 if (mod.GetEquationMgr().get_Equation(i).Contains(
                                     Path.GetFileNameWithoutExtension(component2.GetPathName())))
                                 {
                                     if (mod.GetEquationMgr().get_Suppression(i) != component2.IsSuppressed())
                                         mod.GetEquationMgr().set_Suppression(i, component2.IsSuppressed());
                                 }
                             }
                     }
                     foreach (var component2 in outList)
                     {
                         var m = component2.IGetModelDoc();
                         if (m != null && m.GetConfigurationCount() > 1)
                         {
                             if (dict.ContainsKey(component2))
                                 dict.Add(component2, component.IGetModelDoc());
                         }
                     }
                 }
             }
             mod.Save();
             _mSwAddin.SwApp.CloseDoc(mod.GetPathName());
         }
         foreach (var d in dict)
             ShowConfigurationDetails(d.Key, d.Value, d.Key.ReferencedConfiguration);
     }
 }
Exemplo n.º 3
0
 private bool GetAngel(int number, Component2 component2)
 {
     bool vertical = false;
     OleDbConnection oleDb;
     if (_mSwAddin.OpenModelDatabase(_swSelModel, out oleDb))
     {
         OleDbCommand cm = component2.IGetModelDoc().GetConfigurationCount() > 1
                               ? new OleDbCommand(
                                     "SELECT * FROM decors_conf WHERE id = " + number + " AND Configuration = '" +
                                     component2.ReferencedConfiguration + "'", oleDb)
                               : new OleDbCommand("SELECT * FROM decors_conf WHERE id = " + number, oleDb);
         var rd = cm.ExecuteReader();
         if (rd.Read())
         {
             vertical = (bool)rd["Texture direction"];
         }
         rd.Close();
         oleDb.Close();
     }
     return vertical;
 }
Exemplo n.º 4
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]);
                }
            }
        }
        public void PythonTraverseComponent_for_ChBody(Component2 swComp, long nLevel, ref  string asciitext,  int nbody)
        {
            CultureInfo bz = new CultureInfo("en-BZ");
            object[] vmyChildComp = (object[])swComp.GetChildren();
            bool found_chbody_equivalent = false;

            if (nLevel > 1)
                if (nbody == -1)
                    if ((swComp.Solving == (int)swComponentSolvingOption_e.swComponentRigidSolving) ||
                        (vmyChildComp.Length == 0))
            {
                // OK! this is a 'leaf' of the tree of ChBody equivalents (a SDW subassebly or part)

                found_chbody_equivalent = true;

                this.num_comp++;

                nbody = this.num_comp;  // mark the rest of recursion as 'n-th body found'

                if (this.swProgress != null)
                {
                    this.swProgress.UpdateTitle("Exporting " + swComp.Name2 + " ...");
                    this.swProgress.UpdateProgress(this.num_comp % 5);
                }

                // fetch SW attribute with Chrono parameters
                SolidWorks.Interop.sldworks.Attribute myattr = (SolidWorks.Interop.sldworks.Attribute)swComp.FindAttribute(this.mSWintegration.defattr_chbody, 0);

                MathTransform chbodytransform = swComp.GetTotalTransform(true);
                double[] amatr;
                amatr = (double[])chbodytransform.ArrayData;
                string bodyname = "body_" + this.num_comp;

                // Write create body
                asciitext += "# Rigid body part\n";
                asciitext += bodyname + "= chrono.ChBodyAuxRef()" + "\n";

                // Write name
                asciitext += bodyname + ".SetName('" + swComp.Name2 + "')" + "\n";

                // Write position
                asciitext += bodyname + ".SetPos(chrono.ChVectorD("
                           + (amatr[9] * ChScale.L).ToString("g", bz) + ","
                           + (amatr[10]* ChScale.L).ToString("g", bz) + ","
                           + (amatr[11]* ChScale.L).ToString("g", bz) + "))" + "\n";

                // Write rotation
                double[] quat = GetQuaternionFromMatrix(ref chbodytransform);
                asciitext += String.Format(bz, "{0}.SetRot(chrono.ChQuaternionD({1:g},{2:g},{3:g},{4:g}))\n",
                           bodyname, quat[0], quat[1], quat[2], quat[3]);

                // Compute mass

                int nvalid_bodies = 0;
                PythonTraverseComponent_for_countingmassbodies(swComp, ref nvalid_bodies);

                int addedb = 0;
                object[] bodies_nocollshapes = new object[nvalid_bodies];
                PythonTraverseComponent_for_massbodies(swComp, ref bodies_nocollshapes, ref addedb);

                MassProperty swMass;
                swMass = (MassProperty)swComp.IGetModelDoc().Extension.CreateMassProperty();
                bool boolstatus = false;
                boolstatus = swMass.AddBodies((object[])bodies_nocollshapes);
                swMass.SetCoordinateSystem(chbodytransform);
                swMass.UseSystemUnits = true;
                //note: do not set here the COG-to-REF position because here SW express it in absolute coords
                // double cogX = ((double[])swMass.CenterOfMass)[0];
                // double cogY = ((double[])swMass.CenterOfMass)[1];
                // double cogZ = ((double[])swMass.CenterOfMass)[2];
                double mass = swMass.Mass;
                double[] Itensor = (double[])swMass.GetMomentOfInertia((int)swMassPropertyMoment_e.swMassPropertyMomentAboutCenterOfMass);
                double Ixx = Itensor[0];
                double Iyy = Itensor[4];
                double Izz = Itensor[8];
                double Ixy = Itensor[1];
                double Izx = Itensor[2];
                double Iyz = Itensor[5];

                MassProperty swMassb;
                swMassb = (MassProperty)swComp.IGetModelDoc().Extension.CreateMassProperty();
                bool boolstatusb = false;
                boolstatusb = swMassb.AddBodies(bodies_nocollshapes);
                swMassb.UseSystemUnits = true;
                double cogXb = ((double[])swMassb.CenterOfMass)[0];
                double cogYb = ((double[])swMassb.CenterOfMass)[1];
                double cogZb = ((double[])swMassb.CenterOfMass)[2];

                asciitext += String.Format(bz, "{0}.SetMass({1:g})\n",
                           bodyname,
                           mass * ChScale.M);

                // Write inertia tensor
                asciitext += String.Format(bz, "{0}.SetInertiaXX(chrono.ChVectorD({1:g},{2:g},{3:g}))\n",
                           bodyname,
                           Ixx * ChScale.M * ChScale.L * ChScale.L,
                           Iyy * ChScale.M * ChScale.L * ChScale.L,
                           Izz * ChScale.M * ChScale.L * ChScale.L);
                // Note: C::E assumes that's up to you to put a 'minus' sign in values of Ixy, Iyz, Izx
                asciitext += String.Format(bz, "{0}.SetInertiaXY(chrono.ChVectorD({1:g},{2:g},{3:g}))\n",
                           bodyname,
                           -Ixy * ChScale.M * ChScale.L * ChScale.L,
                           -Izx * ChScale.M * ChScale.L * ChScale.L,
                           -Iyz * ChScale.M * ChScale.L * ChScale.L);

                // Write the position of the COG respect to the REF
                asciitext += String.Format(bz, "{0}.SetFrame_COG_to_REF(chrono.ChFrameD(chrono.ChVectorD({1:g},{2:g},{3:g}),chrono.ChQuaternionD(1,0,0,0)))\n",
                            bodyname,
                            cogXb * ChScale.L,
                            cogYb * ChScale.L,
                            cogZb * ChScale.L);

                // Write 'fixed' state
                if (swComp.IsFixed())
                    asciitext += String.Format(bz, "{0}.SetBodyFixed(True)\n", bodyname);

                // Write shapes (saving also Wavefront files .obj)
                if (this.checkBox_surfaces.Checked)
                {
                    int nvisshape = 0;

                    if (swComp.Visible == (int)swComponentVisibilityState_e.swComponentVisible)
                        PythonTraverseComponent_for_visualizationshapes(swComp, nLevel, ref asciitext, nbody, ref nvisshape, swComp);
                }

                // Write markers (SW coordsystems) contained in this component or subcomponents
                // if any.
                PythonTraverseComponent_for_markers(swComp, nLevel, ref asciitext, nbody);

                // Write collision shapes (customized SW solid bodies) contained in this component or subcomponents
                // if any.
                bool param_collide = true;
                if (myattr != null)
                    param_collide = Convert.ToBoolean(((Parameter)myattr.GetParameter("collision_on")).GetDoubleValue());

                if (param_collide)
                {
                    bool found_collisionshapes = false;
                    PythonTraverseComponent_for_collshapes(swComp, nLevel, ref asciitext, nbody, ref chbodytransform, ref found_collisionshapes, swComp);
                    if (found_collisionshapes)
                    {
                        asciitext += String.Format(bz, "{0}.GetCollisionModel().BuildModel()\n", bodyname);
                        asciitext += String.Format(bz, "{0}.SetCollide(True)\n", bodyname);
                    }
                }

                // Insert to a list of exported items
                asciitext += String.Format(bz, "\n" +"exported_items.append({0})\n", bodyname);

                // End writing body in Python-
                asciitext += "\n\n\n";

            } // end if ChBody equivalent (tree leaf or non-flexible assembly)

            // Things to do also for sub-components of 'non flexible' assemblies:
            //

                // store in hashtable, will be useful later when adding constraints
            if ((nLevel > 1) && (nbody != -1))
            try
            {
                string bodyname = "body_" + this.num_comp;

                ModelDocExtension swModelDocExt = default(ModelDocExtension);
                ModelDoc2 swModel = (ModelDoc2)this.mSWApplication.ActiveDoc;
                //if (swModel != null)
                swModelDocExt = swModel.Extension;
                this.saved_parts.Add(swModelDocExt.GetPersistReference3(swComp), bodyname);
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("Cannot add part to hashtable?");
            }

            // Traverse all children, proceeding to subassemblies and parts, if any
            //

            object[] vChildComp;
            Component2 swChildComp;

            vChildComp = (object[])swComp.GetChildren();

            for (long i = 0; i < vChildComp.Length; i++)
            {
                swChildComp = (Component2)vChildComp[i];

                PythonTraverseComponent_for_ChBody(swChildComp, nLevel + 1, ref asciitext, nbody);
            }
        }
Exemplo n.º 6
0
 private void ChangeConfigurationForReferenceModel(Component2 comp, string nameConfiguration)
 {
     int err = 0, wrn = 0;
     var mod =
         _mSwAddin.SwApp.OpenDoc6(
             comp.IGetModelDoc().
                 GetPathName(),
             (int)swDocumentTypes_e.swDocPART, 0, "",
             ref err, ref wrn);
     if (mod != null)
     {
         mod.ShowConfiguration2(nameConfiguration);
         mod.Save();
         _mSwAddin.SwApp.CloseDoc(mod.GetPathName());
     }
 }
Exemplo n.º 7
0
        private bool GetComponentModel(ModelDoc2 swModel, Component2 inComp, out ModelDoc2 swCompModel, out string modelFileName)
        {
            int i = 0;
            modelFileName = "";
            do
            {
                var compState = (swComponentSuppressionState_e)inComp.GetSuppression();

                if (compState.ToString() == "swComponentSuppressed")
                    inComp.SetSuppression2((int)swComponentSuppressionState_e.swComponentFullyResolved);

                swCompModel = (ModelDoc2)inComp.GetModelDoc();

                if (swCompModel == null)
                {
                    string newModelPath = CheckIsCompInOurLib(inComp.GetPathName());
                    if (inComp.Select(false))
                    {
                        ((AssemblyDoc)swModel).ReplaceComponents(newModelPath, "", true, true);
                        //((AssemblyDoc) swModel).ComponentReload();
                        swCompModel = inComp.IGetModelDoc();
                        //((AssemblyDoc) swModel).OpenCompFile();
                        //��� �������������� ��������� ���������� OpenCompFile �� ��������!
                        if (((ModelDoc2)_iSwApp.ActiveDoc).GetPathName() != swModel.GetPathName())
                            swCompModel = (ModelDoc2)_iSwApp.ActiveDoc;
                    }
                }
                i++;
            } while (swCompModel == null && i < 10);

            if (swCompModel != null)
                modelFileName = swCompModel.GetPathName();
            else
            {
                MessageBox.Show(@"��������� " + inComp.Name + @"�� ���������!", MyTitle, MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
                return false;
            }
            return true;
        }
Exemplo n.º 8
0
        private void RebuildEquation(Component2 component)
        {
            ModelDoc2 model = component.IGetModelDoc();
            if (model != null && model.GetConfigurationCount() > 1 &&
                                            model.GetEquationMgr().GetCount() > 0)
            {
                var compList = new LinkedList<Component2>();
                if (GetComponents(component, compList, true, false))
                {
                    foreach (var component2 in compList)
                    {
                        int eqCount = model.GetEquationMgr().GetCount();
                        for (int i = 0; i <= eqCount; i++)
                        {
                            var name = component2.Name;
                            string eq = model.GetEquationMgr().get_Equation(i);
                            if (eq.Contains(Path.GetFileNameWithoutExtension(component2.GetPathName())))
                            {
                                if (component2.IsSuppressed())
                                {
                                    name = component2.Name;
                                    if (compList.Where(x =>
                                                       x.GetPathName() ==
                                                       component2.GetPathName() &&
                                                       x.IsSuppressed() == false).Count() >
                                        0)
                                        model.GetEquationMgr().Suppression[i] = false;
                                    else
                                        model.GetEquationMgr().Suppression[i] = true;
                                }
                                else
                                    model.GetEquationMgr().Suppression[i] = false;
                            }
                            else
                            {
                                string fn = Path.GetFileNameWithoutExtension(component2.GetPathName());

                                if (Properties.Settings.Default.CashModeOn && fn.Length > 5 && eq.Length > 5 && fn.ToUpper().Last() == 'P' && eq.Contains(fn.Substring(0, fn.Length - 4)))
                                {
                                    //�������� ��� ���������
                                    string orig = fn.Substring(0, fn.Length - 4);
                                    string whatToReplace = eq.Substring(eq.IndexOf(orig) + orig.Length, 4);
                                    string replaceWith = fn.Substring(fn.Length - 4, 4);
                                    string newEq = eq.Replace(whatToReplace, replaceWith);
                                    model.GetEquationMgr().set_Equation(i, newEq);
                                }
                            }
                        }
                        if (model.GetType() == (int)swDocumentTypes_e.swDocASSEMBLY)
                            RebuildEquation(component2);
                    }
                }
                model.ForceRebuild3(true);
            }
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
        private bool CheckSuffixModel(Component2 comp, string suffix, out bool notModel)
        {
            notModel = false;
            try
            {
                string tmp = Path.GetFileNameWithoutExtension(comp.GetPathName());
                if (tmp.Substring(tmp.Length - 4, 4)[0] == '#' && (tmp.Substring(tmp.Length - 4, 4)[3] == 'P' || tmp.Substring(tmp.Length - 4, 4)[3] == 'p'))
                {
                    return false;
                }
                var model = comp.IGetModelDoc();
                if (model != null)
                {
                    if (Properties.Settings.Default.CashModeOn && model.get_CustomInfo2("", "Accessories") == "Yes")
                        return false;
                    if (!Path.GetFileNameWithoutExtension(model.GetPathName()).Contains(suffix))
                    {
                        if (model.GetConfigurationCount() == 1 && model.get_CustomInfo2("", "Articul") != "")
                            return true;

                        var configNames = (string[])model.GetConfigurationNames();
                        if (configNames.Any(configName => model.get_CustomInfo2(configName, "Articul") != ""))
                            return true;

                        var outComps = new LinkedList<Component2>();
                        bool val;
                        if (GetComponents(comp, outComps, false, false) &&
                            outComps.Any(component2 => CheckSuffixModel(component2, suffix, out val)))
                            return true;
                    }
                    else
                    {
                        if (model.GetType() != (int)swDocumentTypes_e.swDocASSEMBLY)
                            return false;

                        var comps = (object[])((AssemblyDoc)model).GetComponents(false);
                        return
                            (from Component2 c in comps select Path.GetFileNameWithoutExtension(c.GetPathName())).
                                Any(
                                    name => !name.Contains(suffix));

                    }
                }
                else
                {
                    SwDmDocumentOpenError oe;

                    if (!Path.GetFileNameWithoutExtension(comp.GetPathName()).Contains(suffix))
                    {
                        SwDMApplication swDocMgr = GetSwDmApp();
                        var swDoc = (SwDMDocument)swDocMgr.GetDocument(comp.GetPathName(),
                                                                        SwDmDocumentType.swDmDocumentAssembly, true,
                                                                        out oe);
                        if (swDoc != null)
                        {
                            SwDmCustomInfoType swDm;
                            if (swDoc.ConfigurationManager.GetConfigurationCount() == 1)
                            {
                                var names = (string[])swDoc.GetCustomPropertyNames();
                                if (names.Contains("Articul") && swDoc.GetCustomProperty("Articul", out swDm) != "")
                                    return true;
                            }
                            else
                            {
                                var names = (string[])swDoc.ConfigurationManager.GetConfigurationNames();
                                if ((from name in names
                                     select (SwDMConfiguration)swDoc.ConfigurationManager.GetConfigurationByName(name)
                                         into conf
                                         let nms = (string[])conf.GetCustomPropertyNames()
                                         where nms.Contains("Articul") && conf.GetCustomProperty("Articul", out swDm) != ""
                                         select conf).Any())
                                    return true;
                            }
                        }
                        else
                        {
                            notModel = true;
                            return true;
                        }
                    }
                    else
                    {
                        var outList = new LinkedList<Component2>();
                        if (GetComponents(comp, outList, true, false))
                        {
                            return
                                (from Component2 c in outList select Path.GetFileNameWithoutExtension(c.GetPathName())).
                                    Any(
                                        name => !name.Contains(suffix));
                        }
                    }
                }
            }
            catch
            {
                notModel = true;
                return true;
            }
            return false;
        }
Exemplo n.º 11
0
 public Component2 GetMdbComponentTopLevel(Component2 upComponent, out ModelDoc2 specModel)
 {
     Component2 specComp = null;
     specModel = upComponent.IGetModelDoc();
     bool cycle = true;
     while (cycle)
     {
         Component2 specComp2 = upComponent;
         if (specComp != null && specComp == specComp2)
         {
             var comp = specComp.GetParent();
             if (comp != null)
                 specComp2 = comp;
             else
                 break;
         }
         specComp = specComp2;
         cycle = GetParentLibraryComponent(specComp, out specComp2);
         if (cycle)
         {
             upComponent = specComp2;
         }
     }
     return upComponent;
 }
Exemplo n.º 12
0
 private static void CheckMdbForDecors(SwAddin mSwAddin, ModelDoc2 inModel, List<ModelDoc2> list, Component2 comp, List<ModelDoc2> faulsModels)
 {
     OleDbConnection oleDb;
     if (mSwAddin.OpenModelDatabase(inModel, out oleDb))
     {
         var oleSchem = oleDb.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
         if (oleSchem.Rows.Cast<DataRow>().Any(row => (string)row["TABLE_NAME"] == "decors"))
         {
             if (!list.Contains(inModel))
                 list.Add(inModel);
         }
         else
         {
             if (faulsModels != null && !faulsModels.Contains(inModel))
                 faulsModels.Add(inModel);
             oleDb.Close();
             if (comp != null)
             {
                 comp = comp.GetParent();
                 if (comp != null && !comp.IsSuppressed())
                 {
                     inModel = comp.IGetModelDoc();
                     if (inModel != null && mSwAddin.OpenModelDatabase(inModel, out oleDb) && !list.Contains(inModel))
                     {
                         oleSchem = oleDb.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
                         if (oleSchem.Rows.Cast<DataRow>().Any(row => (string)row["TABLE_NAME"] == "decors"))
                         {
                             if (!list.Contains(inModel))
                                 list.Add(inModel);
                         }
                         oleDb.Close();
                     }
                 }
             }
         }
         if (oleDb != null)
             oleDb.Close();
     }
 }
Exemplo n.º 13
0
        private void SetDecors()
        {
            var swTestSelComp = (Component2)_swSelMgr.GetSelectedObjectsComponent2(1);
            if (swTestSelComp == null || string.IsNullOrEmpty(swTestSelComp.Name))
                return;
            lbMainNameLabel.Text = swTestSelComp.Name.Split('/').First();
            Component2 swTecSelComp;
            _mSwAddin.GetParentLibraryComponent(swTestSelComp, out swTecSelComp);
            OleDbConnection oleDb;
            ModelDoc2 specModel;
            _swSelComp = _mSwAddin.GetMdbComponentTopLevel(swTecSelComp, out specModel);
            var _swSelModel = _swSelComp.IGetModelDoc();
            _swModel = _swSelModel;
            if (!_mSwAddin.OpenModelDatabase(_swSelModel, out oleDb))
                return;
            var oleSchem = oleDb.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] { null, null, null, "TABLE" });

            if (!oleSchem.Rows.Cast<DataRow>().Any(row => (string)row["TABLE_NAME"] == "faners"))
            {
                //Logging.Log.Instance.Fatal("Нет таблицы faners, хотя есть свойство ExFanerFeats! Невозможно задать кромки. " + _swSelComp.Name);
                return;
            }
            OleDbCommand cm;
            OleDbDataReader rd;
            var outComps = new LinkedList<Component2>();

            string decPathDef = Furniture.Helpers.LocalAccounts.decorPathResult;
            cm = new OleDbCommand("SELECT * FROM faners ORDER BY FanerName ", oleDb);
            rd = cm.ExecuteReader();
            List <Faner> faners= new List<Faner>();
            while (rd.Read())
            {
                if (rd["FanerType"] as string !=null)
                {
                    faners.Add(new Faner((string)rd["FanerName"], (string)rd["FanerType"], (string)rd["DecorGroup"]));
                }
                else
                {
                    faners.Add(new Faner((string)rd["FanerName"], string.Empty, (string)rd["DecorGroup"]));
                }
            }
            rd.Close();
            foreach (Faner faner in faners)
            {
                switch(faner.FanerName.Substring(faner.FanerName.Length - 2, 2))
                {
                    case "11":
                        feature11 = FindEdge(_swSelComp, faner.FanerName);
                        axFeature11 = FindEdge(_swSelComp, faner.AxFanerName);
                        SetValuesForGroup(faner, gbEdge11, cbExist11, cbColor11, feature11,  Edge11PropertyName, edge11PropertyColorName);
                        break;
                    case "12":
                        feature12 = FindEdge(_swSelComp, faner.FanerName);
                        axFeature12 = FindEdge(_swSelComp, faner.AxFanerName);
                        SetValuesForGroup(faner, gbEdge12, cbExist12, cbColor12, feature12,  Edge12PropertyName, edge12PropertyColorName);
                        break;
                    case "21":
                        feature21 = FindEdge(_swSelComp, faner.FanerName);
                        axFeature21 = FindEdge(_swSelComp, faner.AxFanerName);
                        SetValuesForGroup(faner, gbEdge21, cbExist21, cbColor21, feature21,  Edge21PropertyName, edge21PropertyColorName);
                        break;
                    case "22":
                        feature22 = FindEdge(_swSelComp, faner.FanerName);
                        axFeature22 = FindEdge(_swSelComp, faner.AxFanerName);
                        SetValuesForGroup(faner, gbEdge22, cbExist22, cbColor22, feature22,  Edge22PropertyName, edge22PropertyColorName);
                        break;
                    default:
                        break;
                }
            }
            return;
        }