Exemple #1
0
        private void EventHandlerCore_ObjectSelected(object sender, BimPlus.Client.BimPlusEventArgs e)
        {
            if (e.Id == Guid.Empty && e.Selected == true)
            {
                return;
            }
            DtObject dtObject = _integrationBase.ApiCore.DtObjects.GetObject(e.Id, ObjectRequestProperties.InternalValues);

            if (dtObject != null)
            {
                if (e.Multiselect == true)
                {
                    if (_selectedObjects.FirstOrDefault(o => o.Id == e.Id) == null)
                    {
                        _selectedObjects.Add(dtObject);
                    }
                }
                else
                {
                    _selectedObjects.Clear();
                    if (e.Selected == true)
                    {
                        _selectedObjects.Add(dtObject);
                    }
                }
            }

            if (e.Selected == false)
            {
                DtObject exist = _selectedObjects.FirstOrDefault(o => o.Id == e.Id);
                if (exist != null)
                {
                    _selectedObjects.Remove(exist);
                }
                else
                {
                    _selectedObjects.Clear();
                }
            }
            else if (e.Selected == null && e.Id != Guid.Empty)
            {
                if (dtObject != null)
                {
                    if (_selectedObjects.FirstOrDefault(o => o.Id == e.Id) == null)
                    {
                        _selectedObjects.Add(dtObject);
                    }
                }
                else
                {
                    _selectedObjects.Clear();
                }
            }

            List <DtObject> newList = new List <DtObject>();

            newList.AddRange(_selectedObjects);
            _selectedObjects = newList;
            //Trace.WriteLine(string.Format("_selectedObjects.Count:{0}", _selectedObjects.Count()));
        }
        private DtoDivision GetConnectionsModel(bool createModel = true)
        {
            DtoDivision model = null;

            ProgressWindow.Text = "Get Connections model.";
            ProgressWindow.Show();
            try
            {
                model = _integrationBase.ApiCore.Divisions.GetProjectDivisions(_integrationBase.CurrentProject.Id)?.Find(x => x.Name == _modelName);

                if (createModel)
                {
                    if (model == null)
                    {
                        model = _integrationBase.ApiCore.Divisions.CreateModel(_integrationBase.CurrentProject.Id, new DtoDivision {
                            Name = _modelName
                        });
                    }

                    if (model != null)
                    {
                        if (model.TopologyDivisionId == null)
                        {
                            // Create main root TopologyDivision node.
                            DtObject topologyDivision = _integrationBase.ApiCore.DtObjects.PostObject(new TopologyDivision
                            {
                                Name     = _divisionName,
                                Division = model.Id,
                                Parent   = _integrationBase.CurrentProject.Id
                            });

                            if (topologyDivision == null || topologyDivision.Id == Guid.Empty)
                            {
                                MessageBoxHelper.ShowInformation("Could not create TopologyDivision object.", _parentWindow);
                                model = null;
                            }
                            else
                            {
                                model.TopologyDivisionId = topologyDivision.Id;
                                model  = _integrationBase.ApiCore.Divisions.Update(model);
                                _model = model;
                            }
                        }
                    }
                }
            }
            finally
            {
                ProgressWindow.Hide();
            }

            _model = model;

            if (_model != null && model.TopologyDivisionId != null && model.TopologyDivisionId != Guid.Empty)
            {
                SearchElements((Guid)_model.TopologyDivisionId);
            }

            return(_model);
        }
        public MeshGeometry3D MeshObject(DtObject item, MeshBuilder meshBuilder)
        {
            var points  = item.AttributeGroups["geometry"].GetProperty("threejspoints") as List <Point3D>;
            var indices = item.AttributeGroups["geometry"].GetProperty("geometryindices") as List <uint>;

            if (indices == null)
            {
                return(null);
            }

            for (var i = 0; i < indices.Count; i++)
            {
                switch (indices[i])
                {
                case 0:
                    meshBuilder.AddTriangle(points[(int)indices[i + 1]], points[(int)indices[i + 2]],
                                            points[(int)indices[i + 3]]);

                    i = i + 3;
                    break;

                case 1:
                    meshBuilder.AddQuad(points[(int)indices[i + 1]], points[(int)indices[i + 2]],
                                        points[(int)indices[i + 3]],
                                        points[(int)indices[i + 4]]);
                    i = i + 4;
                    break;
                }
            }
            return(meshBuilder.ToMesh(true));
        }
        private void EventHandlerCore_ObjectSelected(object sender, BimPlusEventArgs e)
        {
            Debug.WriteLine(string.Format("Id:{0} Selected:{1} Multiselect:{2}", e.Id, e.Selected, e.Multiselect));

            if (e.Id != Guid.Empty || e.Selected != true)
            {
                DtObject dtObject = _integrationBase.ApiCore.DtObjects.GetObject(e.Id, ObjectRequestProperties.AttributDefinition | ObjectRequestProperties.Pset);

                if (dtObject != null)
                {
                    if (e.Multiselect == true)
                    {
                        if (SelectedObjects.FirstOrDefault(o => o.Id == e.Id) == null)
                        {
                            SelectedObjects.Add(dtObject);
                        }
                    }
                    else
                    {
                        SelectedObjects.Clear();
                        if (e.Selected == true)
                        {
                            SelectedObjects.Add(dtObject);
                        }
                    }
                }

                if (e.Selected == false)
                {
                    DtObject exist = SelectedObjects.FirstOrDefault(o => o.Id == e.Id);
                    if (exist != null)
                    {
                        SelectedObjects.Remove(exist);
                    }
                    else
                    {
                        SelectedObjects.Clear();
                    }
                }
                else if (e.Selected == null && e.Id != Guid.Empty)
                {
                    if (dtObject != null)
                    {
                        if (SelectedObjects.FirstOrDefault(o => o.Id == e.Id) == null)
                        {
                            SelectedObjects.Add(dtObject);
                        }
                    }
                    else
                    {
                        SelectedObjects.Clear();
                    }
                }

                List <DtObject> newList = new List <DtObject>();
                newList.AddRange(SelectedObjects);
                SelectedObjects = newList;
                Trace.WriteLine(string.Format("_selectedObjects.Count:{0}", SelectedObjects.Count()));
            }
        }
Exemple #5
0
        private static string GetStringProperty(this DtObject dtObject, string group, string property)
        {
            DtoAttributesGroup table = PropertyTable(dtObject, group, false);

            if (table == null)
            {
                return(null);
            }
            else
            {
                return(GetStringProperty(table, property));
            }
        }
        /// <summary>
        ///     Parsing the THREEJS Geometry of an Object ... (including the color ...)
        /// </summary>
        /// <param name="geo"></param>
        /// <param name="model"></param>
        /// <param name="color"></param>
        public static void EvaluateAndSaveGeometry(DbGeometry geo, DtObject model, Color color)
        {
            // Create 3DPoints
            var splitpointlist = geo.Vertices
                                 .Select((x, i) => new { Index = i, Value = x })
                                 .GroupBy(x => x.Index / 3)
                                 .Select(x => x.Select(v => v.Value).ToList())
                                 .ToList();

            var points = splitpointlist.Select(item => new Point3D(item[0], item[1], item[2])).ToList();

            // Add the information as AttributeGroup
            model.AttributeGroups["geometry"].AddProperty("threejspoints", points);
            model.AttributeGroups["geometry"].AddProperty("geometryindices", geo.Faces);
            model.AttributeGroups["geometry"].AddProperty("color", color);
        }
        /// <summary>
        ///     Parsing the THREEJS Geometry of an Object ... (including the color ...)
        /// </summary>
        /// <param name="geo"></param>
        /// <param name="model"></param>
        /// <param name="color"></param>
        public static void EvaluateAndSaveGeometry(DbGeometry geo, DtObject model, Color color)
        {
            // Create 3DPoints
            var splitpointlist = geo.Vertices
                .Select((x, i) => new { Index = i, Value = x })
                .GroupBy(x => x.Index / 3)
                .Select(x => x.Select(v => v.Value).ToList())
                .ToList();

            var points = splitpointlist.Select(item => new Point3D(item[0], item[1], item[2])).ToList();

            // Add the information as AttributeGroup
            model.AttributeGroups["geometry"].AddProperty("threejspoints", points);
            model.AttributeGroups["geometry"].AddProperty("geometryindices", geo.Faces);
            model.AttributeGroups["geometry"].AddProperty("color", color);
        }
Exemple #8
0
        public static DtoAttributesGroup PropertyTable(DtObject dtObject, string tableName, bool createIfNotExist)
        {
            DtoAttributesGroup group;

            tableName = tableName.ToLowerInvariant();
            dtObject.AttributeGroups.TryGetValue(tableName, out group);

            if (group == null && (tableName == TableNames.tabAttribGeneral.ToLowerInvariant() || tableName == TableNames.tabAttribElement.ToLowerInvariant()))
            {
                string key = dtObject.AttributeGroups.Keys.FirstOrDefault(k => k.IndexOf(tableName) == 0);
                if (!string.IsNullOrEmpty(key))
                {
                    dtObject.AttributeGroups.TryGetValue(key, out group);
                }
            }

            if (group == null && createIfNotExist)
            {
                group = new DtoAttributesGroup();
                dtObject.AttributeGroups.Add(tableName, group);
            }
            return(group);
        }
        public MeshGeometry3D MeshObject(DtObject item, MeshBuilder meshBuilder)
        {
            var points = item.AttributeGroups["geometry"].GetProperty("threejspoints") as List<Point3D>;
            var indices = item.AttributeGroups["geometry"].GetProperty("geometryindices") as List<uint>;

            if (indices == null)
                return null;

            for (var i = 0; i < indices.Count; i++)
            {
                switch (indices[i])
                {
                    case 0:
                        meshBuilder.AddTriangle(points[(int)indices[i + 1]], points[(int)indices[i + 2]],
                            points[(int)indices[i + 3]]);

                        i = i + 3;
                        break;
                    case 1:
                        meshBuilder.AddQuad(points[(int)indices[i + 1]], points[(int)indices[i + 2]],
                            points[(int)indices[i + 3]],
                            points[(int)indices[i + 4]]);
                        i = i + 4;
                        break;
                }
            }
            return meshBuilder.ToMesh(true);
        }
Exemple #10
0
        public static string GetDtObjectName(this DtObject dtObject)
        {
            string name = GetStringProperty(dtObject, TableNames.tabAttribGeneral, "Name");

            return(name != null ? name : GetStringProperty(dtObject, TableNames.tabAttribElement, "Name"));
        }
        /// <summary>
        /// Fill the TreeView.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GetObjects_Click(object sender, RoutedEventArgs e)
        {
            if (!HasAllowedFlags())
            {
                return;
            }

            AttributeTreeView.Items.Clear();

            List <DtObject> items = null;

            ProgressWindow.Text = "Get properties.";
            ProgressWindow.Show();

            try
            {
                items = _integrationBase.ApiCore.DtObjects.GetObjects(_integrationBase.CurrentProject.Id, SelectedItem,
                                                                      AttributeDefinitionIsChecked, PsetCheckBoxIsChecked, InternalValuesCheckBoxIsChecked);
            }
            finally
            {
                ProgressWindow.Hide();
            }

            if (items != null && items.Count > 0)
            {
                DtObject     dtObject         = items.FirstOrDefault();
                TreeViewItem rootTreeViewItem = new TreeViewItem {
                    Header = dtObject.GetType().Name
                };
                rootTreeViewItem.Header = dtObject.GetType().Name;

                AttributeTreeView.Items.Add(rootTreeViewItem);

                TreeViewItem groupTreeViewItem;
                TreeViewItem attributeTreeViewItem;

                foreach (KeyValuePair <string, DtoAttributesGroup> kvpGroup in dtObject.AttributeGroups)
                {
                    groupTreeViewItem = new TreeViewItem();

                    if (dtObject.LocalizedAttributeGroups != null && dtObject.LocalizedAttributeGroups.ContainsKey(kvpGroup.Key))
                    {
                        groupTreeViewItem.Header = dtObject.LocalizedAttributeGroups[kvpGroup.Key];
                    }
                    else
                    {
                        groupTreeViewItem.Header = kvpGroup.Key;
                    }

                    rootTreeViewItem.Items.Add(groupTreeViewItem);

                    foreach (KeyValuePair <string, object> kvpAttribute in kvpGroup.Value)
                    {
                        // Can not set in TreeView.ItemTemplate.
                        attributeTreeViewItem = new TreeViewItem {
                            FontSize = 13
                        };

                        string header          = null;
                        string value           = "";
                        string definitionValue = "";

                        DtoAttributDefinition dtoAttributDefinition = null;

                        if (!AttributeDefinitionIsChecked)
                        {
                            if (kvpAttribute.Value != null)
                            {
                                value = kvpAttribute.Value.ToString();
                            }
                            header = string.Format("{0} : {1}", kvpAttribute.Key, value);
                        }
                        else
                        {
                            if (kvpAttribute.Value != null)
                            {
                                JObject jObject = kvpAttribute.Value as JObject;
                                if (jObject != null)
                                {
                                    dtoAttributDefinition = jObject.ToObject <DtoAttributDefinition>();
                                    if (dtoAttributDefinition != null && dtoAttributDefinition.EnumDefinition == null)
                                    {
                                        if (dtoAttributDefinition.Value != null)
                                        {
                                            value = dtoAttributDefinition.Value.ToString();
                                        }
                                    }
                                    else
                                    {
                                        value = ExtensionsClass.GetEnumDefinitionValue(dtoAttributDefinition) as string;
                                    }

                                    definitionValue = ExtensionsClass.DtoAttributDefinitionToString(dtoAttributDefinition, _dtoAttributDefinitionProperties);

                                    header = string.Format("{0} : {1}", dtoAttributDefinition.Name, value);
                                }
                            }
                        }

                        attributeTreeViewItem.Header = header;

                        if (!string.IsNullOrEmpty(definitionValue))
                        {
                            attributeTreeViewItem.ToolTip = definitionValue;
                        }

                        if ((dtoAttributDefinition != null && dtoAttributDefinition.IsInternal != true) || dtoAttributDefinition == null)
                        {
                            groupTreeViewItem.Items.Add(attributeTreeViewItem);
                        }
                    }
                }

                ExtensionsClass.ExpandTreeViewItem(rootTreeViewItem);
                AttributeTreeView.InvalidateVisual();

                ScrollViewer scrollViewer = ExtensionsClass.GetTypeObject(AttributeTreeView, typeof(ScrollViewer)) as ScrollViewer;
                if (scrollViewer != null)
                {
                    scrollViewer.ScrollToHome();
                }

                HasTreeViewItems = rootTreeViewItem.Items.Count > 0;
            }
            else
            {
                MessageBoxHelper.ShowInformation("No objects available.", _parentWindow);
            }
        }