Example #1
0
        public void Add_newTab(IEnumerable <ModelItem> items, string[] Lines, int N)
        {
            // Intialize the parameters
            ComApi.InwOpState9 oState              = ComApiBridge.State;
            string[]           OldCategory         = new string[N];
            string[]           OldParameters       = new string[N];
            string[]           NewParameters       = new string[N];
            string[]           Parameters_hasAdded = new string[N];
            int     ind                     = 0;
            Boolean value_notNull           = true;
            Boolean Parameter_isNotRepeated = true;

            ComApi.InwOaProperty[] NewProperties = new ComApi.InwOaProperty[N];

            // Iterate over all the selected items
            foreach (ModelItem oItem in items)
            {
                if (oItem.Children.Count() > 0)
                {
                    // Convert the .NET to COM object
                    ComApi.InwOaPath oPath = ComApiBridge.ToInwOaPath(oItem);
                    // Create new property category
                    ComApi.InwOaPropertyVec newPvec = (ComApi.InwOaPropertyVec)oState.ObjectFactory(ComApi.nwEObjectType.eObjectType_nwOaPropertyVec, null, null);
                    // Get properties collection of the path
                    ComApi.InwGUIPropertyNode2 propn = (ComApi.InwGUIPropertyNode2)oState.GetGUIPropertyNode(oPath, true);
                    // Iterate over all properties in textfile
                    ind = 0;
                    for (int i = 1; i < N; i++)
                    {
                        // Check if line is empty
                        if (Lines[i] != null && Lines[i].Length > 1)
                        {
                            // Get Category, old property and new property from the line
                            string[] WordsInLine = Lines[i].Split('\t');
                            OldCategory[i]   = WordsInLine[0];
                            OldParameters[i] = WordsInLine[1];
                            NewParameters[i] = WordsInLine[2];
                            // By default the property is not repeated
                            Parameter_isNotRepeated = true;
                            // By default the value is not null
                            value_notNull = true;
                            // Iterate over properties of the item
                            foreach (PropertyCategory oPC in oItem.PropertyCategories)
                            {
                                if (oPC.DisplayName == OldCategory[i])
                                {
                                    foreach (DataProperty oDP in oPC.Properties)
                                    {
                                        if (oDP.DisplayName == OldParameters[i])
                                        {
                                            // Create new property
                                            NewProperties[i]          = (ComApi.InwOaProperty)oState.ObjectFactory(ComApi.nwEObjectType.eObjectType_nwOaProperty, null, null);
                                            NewProperties[i].name     = NewParameters[i];
                                            NewProperties[i].UserName = NewParameters[i];

                                            // Check if the property had been added
                                            for (int d = 0; d < ind; d++)
                                            {
                                                if (NewParameters[i] == Parameters_hasAdded[d])
                                                {
                                                    Parameter_isNotRepeated = false;
                                                }
                                            }
                                            //  If the property had not added yet, add it
                                            if (Parameter_isNotRepeated)
                                            {
                                                // Check datatype of the property
                                                switch (oDP.Value.DataType)
                                                {
                                                case VariantDataType.Boolean:
                                                    bool NewValueBool = oDP.Value.ToBoolean();
                                                    NewProperties[i].value = NewValueBool;
                                                    break;

                                                case VariantDataType.DateTime:
                                                    DateTime NewValueDate = oDP.Value.ToDateTime();
                                                    NewProperties[i].value = NewValueDate;
                                                    break;

                                                case VariantDataType.DisplayString:
                                                    string NewValueDString = oDP.Value.ToDisplayString();
                                                    if (NewValueDString == "0.00")
                                                    {
                                                        value_notNull = false;
                                                        break;
                                                    }
                                                    NewProperties[i].value = NewValueDString;
                                                    break;

                                                case VariantDataType.Double:
                                                    double NewValueDouble = oDP.Value.ToDouble();
                                                    if (NewValueDouble == 0)
                                                    {
                                                        value_notNull = false;
                                                        break;
                                                    }
                                                    NewProperties[i].value = NewValueDouble;
                                                    break;

                                                case VariantDataType.DoubleAngle:
                                                    double NewValueAngle = oDP.Value.ToDoubleAngle();
                                                    if (NewValueAngle == 0)
                                                    {
                                                        value_notNull = false;
                                                        break;
                                                    }
                                                    NewProperties[i].value = NewValueAngle;
                                                    break;

                                                case VariantDataType.DoubleArea:
                                                    double NewValueArea = oDP.Value.ToDoubleArea();
                                                    if (NewValueArea == 0)
                                                    {
                                                        value_notNull = false;
                                                        break;
                                                    }
                                                    NewProperties[i].value = NewValueArea * Math.Pow(meter_scale, 2);
                                                    break;

                                                case VariantDataType.DoubleLength:
                                                    double NewValueLength = oDP.Value.ToDoubleLength();
                                                    if (NewValueLength == 0)
                                                    {
                                                        value_notNull = false;
                                                        break;
                                                    }
                                                    NewProperties[i].value = NewValueLength * meter_scale;
                                                    break;

                                                case VariantDataType.DoubleVolume:
                                                    double NewValueVolume = oDP.Value.ToDoubleVolume();
                                                    if (NewValueVolume == 0)
                                                    {
                                                        value_notNull = false;
                                                        break;
                                                    }
                                                    NewProperties[i].value = NewValueVolume * Math.Pow(meter_scale, 3);
                                                    break;

                                                case VariantDataType.IdentifierString:
                                                    string NewValueIString = oDP.Value.ToIdentifierString();
                                                    NewProperties[i].value = NewValueIString;
                                                    break;

                                                case VariantDataType.Int32:
                                                    int NewValueInt = oDP.Value.ToInt32();
                                                    if (NewValueInt == 0)
                                                    {
                                                        value_notNull = false;
                                                        break;
                                                    }
                                                    NewProperties[i].value = NewValueInt;
                                                    break;

                                                case VariantDataType.NamedConstant:
                                                    NamedConstant NewValueConst = oDP.Value.ToNamedConstant();
                                                    String        s             = NewValueConst.DisplayName;
                                                    s = s.Substring(s.IndexOf("\"") + 1);
                                                    s = s.Substring(0, s.IndexOf("\""));

                                                    NewProperties[i].value = s;
                                                    break;

                                                case VariantDataType.None:
                                                    string NewValueNone = oDP.Value.ToString();
                                                    NewProperties[i].value = NewValueNone;
                                                    break;

                                                case VariantDataType.Point3D:
                                                    string NewValuePoint = oDP.Value.ToString();
                                                    NewProperties[i].value = NewValuePoint;
                                                    break;
                                                }
                                                // Add the new property to the new property category
                                                if (value_notNull)
                                                {
                                                    newPvec.Properties().Add(NewProperties[i]);
                                                    Parameters_hasAdded[ind] = NewParameters[i]; ind = ind + 1;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    // Add new tab to the object
                    // The name of the newtab is saved in first line in the textfile
                    propn.SetUserDefined(0, Lines[0], "MyAttribute", newPvec);
                }
            }
        }
        private Tuple <List <IssueBCF>, List <Issue> > AddIssue(string path, bool isBcf)
        {
            try
            {
                // set image export settings
                ComApi.InwOaPropertyVec options = ComBridge.State.GetIOPluginOptions("lcodpimage");
                // configure the option "export.image.format" to export png and image size
                foreach (ComApi.InwOaProperty opt in options.Properties())
                {
                    if (opt.name == "export.image.format")
                    {
                        opt.value = "lcodpexpng";
                    }
                    if (opt.name == "export.image.width")
                    {
                        opt.value = 1600;
                    }
                    if (opt.name == "export.image.height")
                    {
                        opt.value = 900;
                    }
                }

                _savedViewpoints = new List <SavedViewpoint>();

                foreach (SavedItem oSI in _oDoc.SavedViewpoints.ToSavedItemCollection())
                {
                    RecurseItems(oSI);
                }

                var types      = new ObservableCollection <Issuetype>();
                var assignees  = new List <User>();
                var components = new ObservableCollection <Component>();
                var priorities = new ObservableCollection <Priority>();
                var noCom      = true;
                var noPrior    = true;
                var noAssign   = true;

                if (!isBcf)
                {
                    types      = mainPan.jira.TypesCollection;
                    assignees  = mainPan.getAssigneesProj();
                    components = mainPan.jira.ComponentsCollection;
                    priorities = mainPan.jira.PrioritiesCollection;
                    noCom      =
                        mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.components ==
                        null;
                    noPrior =
                        mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.priority ==
                        null;
                    noAssign =
                        mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.assignee ==
                        null;
                }



                AddIssueNavis ain = new AddIssueNavis(_savedViewpoints, types, assignees, components, priorities, noCom, noPrior, noAssign);
                if (isBcf)
                {
                    ain.JiraFieldsBox.Visibility = System.Windows.Visibility.Collapsed;
                }
                ain.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
                ain.ShowDialog();
                if (ain.DialogResult.HasValue && ain.DialogResult.Value)
                {
                    int elemCheck = 2;
                    if (ain.all.IsChecked.Value)
                    {
                        elemCheck = 0;
                    }
                    else if (ain.selected.IsChecked.Value)
                    {
                        elemCheck = 1;
                    }

                    List <SavedViewpoint> savedViewpointsImport = new List <SavedViewpoint>();

                    for (int i = 0; i < ain.issueList.SelectedItems.Count; i++)
                    {
                        int index = ain.issueList.Items.IndexOf(ain.issueList.SelectedItems[i]);
                        savedViewpointsImport.Add(_savedViewpoints[index]);
                    }
                    if (!savedViewpointsImport.Any())
                    {
                        return(null);
                    }
                    //get selection only once!
                    if (elemCheck == 1)
                    {
                        _elementList = _oDoc.CurrentSelection.SelectedItems.Where(o => o.InstanceGuid != Guid.Empty).ToList <ModelItem>();
                    }

                    List <IssueBCF> issues     = new List <IssueBCF>();
                    List <Issue>    issuesJira = new List <Issue>();
                    foreach (var sv in savedViewpointsImport)
                    {
                        Issue issueJira = new Issue();
                        if (!isBcf)
                        {
                            issueJira.fields           = new Fields();
                            issueJira.fields.issuetype = (Issuetype)ain.issueTypeCombo.SelectedItem;
                            issueJira.fields.priority  = (Priority)ain.priorityCombo.SelectedItem;
                            if (!string.IsNullOrEmpty(ain.ChangeAssign.Content.ToString()) &&
                                ain.ChangeAssign.Content.ToString() != "none")
                            {
                                issueJira.fields.assignee      = new User();
                                issueJira.fields.assignee.name = ain.ChangeAssign.Content.ToString();
                            }

                            if (ain.SelectedComponents != null && ain.SelectedComponents.Any())
                            {
                                issueJira.fields.components = ain.SelectedComponents;
                            }
                        }

                        IssueBCF issue       = new IssueBCF();
                        string   folderIssue = Path.Combine(path, issue.guid.ToString());
                        if (!Directory.Exists(folderIssue))
                        {
                            Directory.CreateDirectory(folderIssue);
                        }

                        issue.snapshot = Path.Combine(folderIssue, "snapshot.png");
                        // set the currtent saved viewpoint and then generate sna and BCF viewpoint
                        _oDoc.SavedViewpoints.CurrentSavedViewpoint = sv;
                        issue.viewpoint = generateViewpoint(sv.Viewpoint, elemCheck);
                        generateSnapshot(folderIssue);

                        issue.markup.Topic.Title          = sv.DisplayName;
                        issue.markup.Header[0].IfcProject = "";
                        string projFilename = !string.IsNullOrEmpty(_oDoc.FileName) ? System.IO.Path.GetFileName(_oDoc.FileName) : "";
                        issue.markup.Header[0].Filename = projFilename;
                        issue.markup.Header[0].Date     = DateTime.Now;

                        //comment
                        if (sv.Comments.Any())
                        {
                            foreach (var comm in sv.Comments)
                            {
                                var c = new CommentBCF
                                {
                                    Comment1 = comm.Body,
                                    Topic    = new CommentTopic {
                                        Guid = issue.guid.ToString()
                                    }
                                };
                                ;
                                c.Date         = DateTime.Now;
                                c.VerbalStatus = comm.Status.ToString();
                                c.Author       = (string.IsNullOrWhiteSpace(mainPan.jira.Self.displayName)) ? MySettings.Get("BCFusername") : mainPan.jira.Self.displayName;
                                issue.markup.Comment.Add(c);
                            }
                        }
                        issues.Add(issue);
                        issuesJira.Add(issueJira);
                    } // end foreach
                    return(new Tuple <List <IssueBCF>, List <Issue> >(issues, issuesJira));
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return(null);
        }