Exemplo n.º 1
0
        public static bool RemoveLayers(FileFormat slicerFile, List <uint> layersRemove, OperationProgress progress = null)
        {
            if (layersRemove.Count == 0)
            {
                return(false);
            }

            progress ??= new OperationProgress(false);

            progress.Reset("Removed layers", (uint)layersRemove.Count);

            foreach (var layerIndex in layersRemove)
            {
                slicerFile[layerIndex] = null;
                progress++;
            }

            slicerFile.LayerManager.RemoveNulls();

            /*var oldLayers = slicerFile.LayerManager.Layers;
             * var layerHeight = slicerFile.LayerHeight;
             *
             * var layers = new Layer[oldLayers.Length - layersRemove.Count];
             *
             * // Re-set
             * uint newLayerIndex = 0;
             * for (uint layerIndex = 0; layerIndex < oldLayers.Length; layerIndex++)
             * {
             *  if (layersRemove.Contains(layerIndex)) continue;
             *  layers[newLayerIndex] = oldLayers[layerIndex];
             *  layers[newLayerIndex].Index = newLayerIndex;
             *
             *  // Re-Z
             *  float posZ = layerHeight;
             *  if (newLayerIndex > 0)
             *  {
             *      if (oldLayers[layerIndex - 1].PositionZ == oldLayers[layerIndex].PositionZ)
             *      {
             *          posZ = layers[newLayerIndex - 1].PositionZ;
             *      }
             *      else
             *      {
             *          posZ = Layer.RoundHeight(layers[newLayerIndex - 1].PositionZ + layerHeight);
             *      }
             *  }
             *
             *  layers[newLayerIndex].PositionZ = posZ;
             *  layers[newLayerIndex].IsModified = true;
             *
             *  newLayerIndex++;
             *  progress++;
             * }
             *
             * slicerFile.LayerManager.Layers = layers;*/



            return(true);
        }
Exemplo n.º 2
0
        public static bool RemoveLayers(FileFormat slicerFile, List <uint> layersRemove, OperationProgress progress = null)
        {
            if (layersRemove.Count == 0)
            {
                return(false);
            }

            progress ??= new OperationProgress(false);

            progress.Reset("removed layers", (uint)layersRemove.Count);

            var   oldLayers   = slicerFile.LayerManager.Layers;
            float layerHeight = slicerFile.LayerHeight;

            var layers = new Layer[oldLayers.Length - layersRemove.Count];

            // Re-set
            uint newLayerIndex = 0;

            for (uint layerIndex = 0; layerIndex < oldLayers.Length; layerIndex++)
            {
                if (layersRemove.Contains(layerIndex))
                {
                    continue;
                }
                layers[newLayerIndex]       = oldLayers[layerIndex];
                layers[newLayerIndex].Index = newLayerIndex;

                // Re-Z
                float posZ = layerHeight;
                if (newLayerIndex > 0)
                {
                    if (oldLayers[layerIndex - 1].PositionZ == oldLayers[layerIndex].PositionZ)
                    {
                        posZ = layers[newLayerIndex - 1].PositionZ;
                    }
                    else
                    {
                        posZ = (float)Math.Round(layers[newLayerIndex - 1].PositionZ + layerHeight, 2);
                    }
                }

                layers[newLayerIndex].PositionZ  = posZ;
                layers[newLayerIndex].IsModified = true;

                newLayerIndex++;
                progress++;
            }

            slicerFile.LayerManager.Layers = layers;
            slicerFile.RequireFullEncode   = true;

            return(true);
        }