Exemplo n.º 1
0
        internal PlacementsConfig.Config GetCfg()
        {
            var cfg = new PlacementsConfig.Config();

            cfg.BaseEditorPath = (BaseEditorPath != null) ? GetBaseUri().MakeRelativeUri(BaseEditorPath).ToString() : "";
            var cellCount = CellCount;

            if (cellCount[0] > 0 && cellCount[1] > 0)
            {
                cfg.CellCountX = (uint)cellCount[0];
                cfg.CellCountY = (uint)cellCount[1];
            }
            var cellsOrigin = CellsOrigin;

            cfg.CellsOriginX = cellsOrigin[0];
            cfg.CellsOriginY = cellsOrigin[1];
            cfg.CellSize     = GetAttribute <float>(FolderST.CellSizeAttribute);
            return(cfg);
        }
Exemplo n.º 2
0
        internal PlacementsConfig.Config GetCfg()
        {
            var cfg = new PlacementsConfig.Config();

            cfg.BaseEditorPath = BaseEditorPath;
            cfg.BaseExportPath = BaseExportPath;
            var cellCount = CellCount;

            if (cellCount[0] > 0 && cellCount[1] > 0)
            {
                cfg.CellCountX = (uint)cellCount[0];
                cfg.CellCountY = (uint)cellCount[1];
            }
            var cellsOrigin = CellsOrigin;

            cfg.CellsOriginX = cellsOrigin[0];
            cfg.CellsOriginY = cellsOrigin[1];
            cfg.CellSize     = GetAttribute <float>(FolderST.CellSizeAttribute);
            return(cfg);
        }
Exemplo n.º 3
0
        internal void Reconfigure(PlacementsConfig.Config cfg)
        {
            // Based on the configuration settings given, remove and attach
            // cell references. First create a list of all of the references
            // we want to see.
            // We can use this to filter out the existing references that should
            // be removed.
            // Then, we should create new references for all new cells that have
            // been added.
            // Cells always have the same basic filename structure, and are
            // arranged in a dense 2d grid. The filenames contain the x and y
            // coordinates of the cell in that grid.

            BaseEditorPath = new Uri(GetBaseUri(), cfg.BaseEditorPath);
            SetAttribute(FolderST.CellCountAttribute, new int[2] {
                (int)cfg.CellCountX, (int)cfg.CellCountY
            });
            SetAttribute(FolderST.CellSizeAttribute, cfg.CellSize);
            SetAttribute(FolderST.CellsOriginAttribute, new float[2] {
                cfg.CellsOriginX, cfg.CellsOriginY
            });

            var newCells  = new List <Tuple <Uri, string, Vec3F, Vec3F> >();
            var cellCount = CellCount;

            for (uint y = 0; y < cellCount[1]; ++y)
            {
                for (uint x = 0; x < cellCount[0]; ++x)
                {
                    var rf   = String.Format("p{0,3:D3}_{1,3:D3}.plcdoc", x, y);
                    var name = String.Format("{0,2:D2}-{1,2:D2}", x, y);
                    var mins = new Vec3F(x * cfg.CellSize + cfg.CellsOriginX, y * cfg.CellSize + cfg.CellsOriginY, -5000.0f);
                    var maxs = new Vec3F((x + 1) * cfg.CellSize + cfg.CellsOriginX, (y + 1) * cfg.CellSize + cfg.CellsOriginY, 5000.0f);
                    newCells.Add(Tuple.Create(new Uri(BaseEditorPath, rf), name, mins, maxs));
                }
            }

            var foundMatching = new bool[newCells.Count];

            Array.Clear(foundMatching, 0, foundMatching.Length);

            var toBeRemoved  = new List <PlacementsCellRef>();
            var existingRefs = Cells;

            foreach (var r in existingRefs)
            {
                var rawRef = r.Uri;
                int index  = newCells.FindIndex(0, newCells.Count, s => s.Item1.Equals(rawRef));
                if (index >= 0)
                {
                    foundMatching[index] = true;
                    r.Name        = newCells[index].Item2;
                    r.CaptureMins = newCells[index].Item3;
                    r.CaptureMaxs = newCells[index].Item4;
                }
                else
                {
                    toBeRemoved.Add(r);
                }
            }

            // \todo -- if we have some cell references to be removed, we should first check if there
            // are any changes, and if they need to be saved!
            foreach (var r in toBeRemoved)
            {
                r.Unresolve();
                r.DomNode.RemoveFromParent();
            }

            // Create the new cell references that are needed...
            var childList = DomNode.GetChildList(Schema.placementsFolderType.cellChild);

            for (int c = 0; c < newCells.Count; ++c)
            {
                if (!foundMatching[c])
                {
                    var newItem = PlacementsCellRef.Create(
                        cfg.UnnamedPlacementDocuments ? null : newCells[c].Item1,
                        newCells[c].Item2, newCells[c].Item3, newCells[c].Item4);
                    childList.Add(newItem);
                    newItem.As <PlacementsCellRef>().CreateAndResolve();
                }
            }
        }