コード例 #1
0
        /// <summary>
        /// Update the viewport from the element view model
        /// </summary>
        public static void UpdateViewport(NavigationRootVM elem, ViewportVM viewport)
        {
            viewport.Clear();

            // Loop spaces
            foreach (BuildingVM bldg in elem.Children.Where(e => e is BuildingVM))
            {
                var bldg3D       = new ViewportElementVM(bldg, new List <GeometryModel3D>()); // No geom, only grouping
                var bldg3DChilds = new List <ViewportElementVM>();
                foreach (SpaceVM space in bldg.Children)
                {
                    var spacePoly = _spacePolyloops(space.Data);
                    var spaceGeom = _geometryFromPolygons(spacePoly);
                    var space3D   = new ViewportSpaceVM(space, spaceGeom);
                    bldg3DChilds.Add(space3D);
                }
                bldg3D.SetChildren(bldg3DChilds);
                viewport.AddElem(bldg3D);
            }

            // Loop surfaces
            foreach (SurfaceCollectionVM surfColl in elem.Children.Where(e => e is SurfaceCollectionVM))
            {                                                                                         // There is supposed to be only on surface collection
                var surfColl3D       = new ViewportElementVM(surfColl, new List <GeometryModel3D>()); // No geom, only grouping
                var surfColl3DChilds = new List <ViewportElementVM>();
                foreach (SurfaceVM surf in surfColl.Children.Where(e => e is SurfaceVM))
                {
                    // Collect polygons or surface and openings
                    var surfVertices        = _planarVertices(surf.Data);
                    var openingVerticesList = new Dictionary <OpeningVM, List <Point3DCollection> >();
                    foreach (OpeningVM opening in surf.Children.Where(e => e is OpeningVM))
                    {
                        var openingVertices = _planarVertices(opening.Data);
                        openingVerticesList[opening] = openingVertices;
                    }

                    // Apply openings on surface and create surface VM
                    Point3DCollection vertices;
                    Int32Collection   indices;
                    _cutOpenings(surfVertices, openingVerticesList.Values, out vertices, out indices);
                    var surf3D = new ViewportSurfaceVM(surf, _geometryFromTriangles(vertices, indices));
                    surfColl3DChilds.Add(surf3D);

                    // Create opening VMs
                    foreach (var openingRec in openingVerticesList)
                    {
                        var openingGeom = _geometryFromPolygons(openingRec.Value);
                        var opening3D   = new ViewportOpeningVM(openingRec.Key, openingGeom);
                        surfColl3DChilds.Add(opening3D);  // Openings are selected individually from surfaces, but not from surface collections
                    }
                }
                surfColl3D.SetChildren(surfColl3DChilds);
                viewport.AddElem(surfColl3D);
            }
        }
コード例 #2
0
ファイル: ViewportVM.cs プロジェクト: raacztomi/gbxmlviewer
 public void AddElem(ViewportElementVM elem)
 {
     if (!_elementMap.ContainsKey(elem.RefElem))
     {   // Not already added
         _elementMap[elem.RefElem] = elem;
         foreach (var geom in elem.GeometryElements)
         {
             _geometryCollection.Add(geom);
         }
     }
     foreach (var child in elem.Children)
     {
         AddElem(child);
     }
     NotifyPropertyChanged(nameof(GeometryCollection));
 }