Exemplo n.º 1
0
        /// <summary>
        /// copy only the option parameters from the specified layer
        /// </summary>
        /// <param name="layerToCopy">the model to copy from</param>
        public override void CopyOptionsFrom(Layer layerToCopy)
        {
            // and try to cast in grid layer
            LayerGrid gridLayer = layerToCopy as LayerGrid;

            if (gridLayer != null)
            {
                mGridLinePen         = gridLayer.mGridLinePen.Clone() as Pen;
                mSubGridLinePen      = gridLayer.mSubGridLinePen.Clone() as Pen;
                mCellIndexFont       = gridLayer.mCellIndexFont.Clone() as Font;
                mCellIndexBrush      = gridLayer.mCellIndexBrush;
                mGridSizeInStud      = gridLayer.mGridSizeInStud;
                mSubDivisionNumber   = gridLayer.mSubDivisionNumber;
                mDisplayGrid         = gridLayer.mDisplayGrid;
                mDisplaySubGrid      = gridLayer.mDisplaySubGrid;
                mDisplayCellIndex    = gridLayer.mDisplayCellIndex;
                mCellIndexColumnType = gridLayer.mCellIndexColumnType;
                mCellIndexRowType    = gridLayer.mCellIndexRowType;
                mCellIndexCorner     = gridLayer.mCellIndexCorner;
            }
            // call the base method after such as the pen and brush transparency can be correctly set
            base.CopyOptionsFrom(layerToCopy);
        }
Exemplo n.º 2
0
 public MoveGridOrigin(LayerGrid layer, int moveX, int moveY)
 {
     mGridLayer = layer;
     mMoveX = moveX;
     mMoveY = moveY;
 }
Exemplo n.º 3
0
        public void ReadXml(System.Xml.XmlReader reader)
        {
            // reset the counter of modifications because we just load the map (no modification done)
            mNumberOfModificationSinceLastSave = 0;
            // version
            readVersionNumber(reader);
            // check if the BlueBrick program is not too old, that
            // means the user try to load a file generated with
            /// a earlier version of BlueBrick
            if (mDataVersionOfTheFileLoaded > CURRENT_DATA_VERSION)
            {
                MessageBox.Show(null, Properties.Resources.ErrorMsgProgramObsolete,
                    Properties.Resources.ErrorMsgTitleError, MessageBoxButtons.OK,
                    MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return;
            }
            // get the number of layer for the progressbar
            if (mDataVersionOfTheFileLoaded >= 3)
            {
                int nbItems = reader.ReadElementContentAsInt();
                // init the progress bar with the real number of layer items (+1 for the header +1 for the link rebuilding)
                MainForm.Instance.resetProgressBar(nbItems + 2);
            }
            // check is there is a background color
            if (reader.Name.Equals("BackgroundColor"))
                mBackgroundColor = XmlReadWrite.readColor(reader);
            // data of the map
            mAuthor = reader.ReadElementContentAsString();
            mLUG = reader.ReadElementContentAsString();
            mShow = reader.ReadElementContentAsString();
            reader.ReadToDescendant("Day");
            int day = reader.ReadElementContentAsInt();
            int month = reader.ReadElementContentAsInt();
            int year = reader.ReadElementContentAsInt();
            mDate = new DateTime(year, month, day);
            // read the comment if the version is greater than 0
            if (mDataVersionOfTheFileLoaded > 0)
            {
                reader.ReadToFollowing("Comment");
                mComment = reader.ReadElementContentAsString().Replace("\n", Environment.NewLine);
            }
            else
            {
                reader.ReadToFollowing("CurrentSnapGridSize");
            }
            if (mDataVersionOfTheFileLoaded < 2)
            {
                // skip the static data of layers that before we were saving
                // but now I think it is stupid, since we don't have action to change that
                // and we don't have way to update the enabled of the buttons
                reader.ReadElementContentAsFloat(); // CurrentSnapGridSize
                reader.ReadElementContentAsBoolean(); // SnapGridEnabled
                reader.ReadElementContentAsFloat(); // CurrentRotationStep
            }

            // read the export data if the version is 5 or higher
            if (mDataVersionOfTheFileLoaded > 4)
            {
                reader.ReadToDescendant("ExportPath");
                // read the relative export path and store it temporarly in the absolute path variable
                // the absolute path will be computed after the xml serialization is finished
                mExportAbsoluteFileName = reader.ReadElementContentAsString();
                // read the other export info
                mExportFileTypeIndex = reader.ReadElementContentAsInt();
                mExportArea = XmlReadWrite.readRectangleF(reader);
                mExportScale = reader.ReadElementContentAsFloat();
                // read even more info from version 8
                if (mDataVersionOfTheFileLoaded > 7)
                {
                    mExportWatermark = XmlReadWrite.readBoolean(reader);
                    mExportBrickHull = XmlReadWrite.readBoolean(reader);
                    mExportElectricCircuit = XmlReadWrite.readBoolean(reader);
                    mExportConnectionPoints = XmlReadWrite.readBoolean(reader);
                }
                reader.ReadEndElement();
            }

            // selected layer
            int selectedLayerIndex = reader.ReadElementContentAsInt();
            // step the progress bar after the read of the header
            MainForm.Instance.stepProgressBar();

            // layers
            // first clear the hashtable that contains all the bricks
            Map.sHashtableForRulerAttachementRebuilding.Clear();
            // then load all the layers
            bool layerFound = reader.ReadToDescendant("Layer");
            while (layerFound)
            {
                // get the 'type' attribute of the layer
                reader.ReadAttributeValue();
                string layerType = reader.GetAttribute(0);

                // instantiate the right layer according to the type
                Layer layer = null;
                if (layerType.Equals("grid"))
                    layer = new LayerGrid();
                else if (layerType.Equals("brick"))
                    layer = new LayerBrick();
                else if (layerType.Equals("text"))
                    layer = new LayerText();
                else if (layerType.Equals("area"))
                    layer = new LayerArea();
                else if (layerType.Equals("ruler"))
                    layer = new LayerRuler();

                // read and add the new layer
                if (layer != null)
                {
                    layer.ReadXml(reader);
                    mLayers.Add(layer);
                }

                // read the next layer
                layerFound = reader.ReadToNextSibling("Layer");
            }
            reader.ReadEndElement(); // end of Layers

            // once we have finished to read all the layers thus all the items, we need to recreate all the links they have between them
            foreach (Layer layer in mLayers)
                layer.recreateLinksAfterLoading();
            // then clear again the hash table to free the memory
            Map.sHashtableForRulerAttachementRebuilding.Clear();

            // step the progress bar after the rebuilding of links
            MainForm.Instance.stepProgressBar();

            // if the selected index is valid, reset the selected layer
            // use the setter in order to enable the toolbar buttons
            if ((selectedLayerIndex >= 0) && (selectedLayerIndex < mLayers.Count))
                SelectedLayer = mLayers[selectedLayerIndex];
            else
                SelectedLayer = null;

            // DO NOT READ YET THE BRICK URL LIST, BECAUSE THE BRICK DOWNLOAD FEATURE IS NOT READY
            if (false)
            {
                // read the url of all the parts for version 5 or later
                if ((mDataVersionOfTheFileLoaded > 5) && !reader.IsEmptyElement)
                {
                    bool urlFound = reader.ReadToDescendant("BrickUrl");
                    while (urlFound)
                    {
                        // read the next url
                        urlFound = reader.ReadToNextSibling("BrickUrl");
                    }
                    reader.ReadEndElement();
                }
            }

            // construct the watermark
            computeGeneralInfoWatermark();
            // for old version, make disapear the progress bar, since it was just an estimation
            MainForm.Instance.finishProgressBar();
        }
        public ChangeMapAppearance(bool isColorModified, bool isFontModified, bool isSizeModified, bool doesAreaChanged)
        {
            // background color of the map
            mOldBackGroundColor = Map.Instance.BackgroundColor;
            mNewBackGroundColor = BlueBrick.Properties.Settings.Default.DefaultBackgroundColor;

            // and the other modification to the layer
            bool doesGridChanged = isColorModified || isFontModified || isSizeModified;
            foreach (Layer layer in Map.Instance.LayerList)
            {
                if (doesGridChanged)
                {
                    LayerGrid gridLayer = layer as LayerGrid;
                    if (gridLayer != null)
                    {
                        // create a copy of the edited layer to hold the old data
                        LayerGrid oldLayerData = new LayerGrid();
                        oldLayerData.CopyOptionsFrom(gridLayer);
                        // create a new layer to store the new data
                        LayerGrid newLayerData = new LayerGrid();
                        newLayerData.CopyOptionsFrom(gridLayer);
                        // and change only the grid colors
                        if (isColorModified)
                        {
                            newLayerData.GridColor = BlueBrick.Properties.Settings.Default.DefaultGridColor;
                            newLayerData.SubGridColor = BlueBrick.Properties.Settings.Default.DefaultSubGridColor;
                        }
                        if (isFontModified)
                        {
                            newLayerData.CellIndexColor = BlueBrick.Properties.Settings.Default.DefaultTextColor;
                            newLayerData.CellIndexFont = BlueBrick.Properties.Settings.Default.DefaultTextFont;
                        }
                        if (isSizeModified)
                        {
                            newLayerData.GridSizeInStud = BlueBrick.Properties.Settings.Default.DefaultGridSize;
                            newLayerData.SubDivisionNumber = BlueBrick.Properties.Settings.Default.DefaultSubDivisionNumber;
                            newLayerData.DisplayGrid = BlueBrick.Properties.Settings.Default.DefaultGridEnabled;
                            newLayerData.DisplaySubGrid = BlueBrick.Properties.Settings.Default.DefaultSubGridEnabled;
                        }

                        // create a new entry for the list and store it in the list
                        LayerChange layerChange = new LayerChange();
                        layerChange.mReference = gridLayer;
                        layerChange.mOldData = oldLayerData;
                        layerChange.mNewData = newLayerData;
                        mLayerChanges.Add(layerChange);
                    }
                }
                if (doesAreaChanged)
                {
                    LayerArea areaLayer = layer as LayerArea;
                    if (areaLayer != null)
                    {
                        // create a copy of the edited layer to hold the old data
                        LayerArea oldLayerData = new LayerArea();
                        oldLayerData.CopyOptionsFrom(areaLayer);
                        // create a new layer to store the new data
                        LayerArea newLayerData = new LayerArea();
                        newLayerData.CopyOptionsFrom(areaLayer);
                        // and change the area parameters
                        newLayerData.Transparency = BlueBrick.Properties.Settings.Default.DefaultAreaTransparency;
                        newLayerData.AreaCellSizeInStud = BlueBrick.Properties.Settings.Default.DefaultAreaSize;

                        // create a new entry for the list and store it in the list
                        LayerChange layerChange = new LayerChange();
                        layerChange.mReference = areaLayer;
                        layerChange.mOldData = oldLayerData;
                        layerChange.mNewData = newLayerData;
                        layerChange.mOldColorMap = areaLayer.ColorMap;
                        mLayerChanges.Add(layerChange);
                    }
                }
            }
        }