Пример #1
0
 public static float[] readFloatArray(System.Xml.XmlReader reader)
 {
     List<float> result = new List<float>();
     reader.ReadToDescendant("value");
     while (reader.Name.Equals("value"))
         result.Add(reader.ReadElementContentAsFloat());
     reader.ReadEndElement();
     return result.ToArray();
 }
Пример #2
0
 public static Font readFont(System.Xml.XmlReader reader)
 {
     reader.ReadToDescendant("FontFamily");
     string fontFamily = reader.ReadElementContentAsString();
     float size = reader.ReadElementContentAsFloat();
     FontStyle style = FontStyle.Regular;
     // the style (italic, bold, etc...)
     if (Map.DataVersionOfTheFileLoaded >= 6)
         style = (FontStyle)Enum.Parse(typeof(FontStyle), reader.ReadElementContentAsString());
     // end of Font
     reader.ReadEndElement();
     return new Font(fontFamily, size, style);
 }
Пример #3
0
 public static PointF readPointF(System.Xml.XmlReader reader)
 {
     reader.ReadToDescendant("X");
     float x = reader.ReadElementContentAsFloat();
     float y = reader.ReadElementContentAsFloat();
     reader.ReadEndElement();
     return new PointF(x, y);
 }
Пример #4
0
 public static float readFloat(System.Xml.XmlReader reader)
 {
     return reader.ReadElementContentAsFloat();
 }
Пример #5
0
            private void readLDRAWTag(ref System.Xml.XmlReader xmlReader)
            {
                // check if the description is not empty
                bool continueToRead = !xmlReader.IsEmptyElement;
                if (continueToRead)
                {
                    // the LDRAW tag is not empty, instanciate the class that will hold the data
                    mLDrawRemapData = new LDrawRemapData();

                    // read the first child node
                    xmlReader.Read();
                    continueToRead = !xmlReader.EOF;
                    while (continueToRead)
                    {
                        if (xmlReader.Name.Equals("Angle"))
                            mLDrawRemapData.mAngle = xmlReader.ReadElementContentAsFloat();
                        else if (xmlReader.Name.Equals("Translation"))
                            mLDrawRemapData.mTranslation = readPointTag(ref xmlReader, "Translation");
                        else if (xmlReader.Name.Equals("PreferredHeight"))
                            mLDrawRemapData.mPreferredHeight = xmlReader.ReadElementContentAsFloat();
                        else if (xmlReader.Name.Equals("SleeperID"))
                        {
                            readBlueBrickId(ref xmlReader, ref mLDrawRemapData.mSleeperBrickNumber, ref mLDrawRemapData.mSleeperBrickColor);
                            if (mLDrawRemapData.mSleeperBrickColor == null)
                                mLDrawRemapData.mSleeperBrickColor = "0"; // black as default color
                        }
                        else if (xmlReader.Name.Equals("Alias"))
                        {
                            // before reading the alias content check if we need to create a remaping by reading the attribute
                            bool needToAddRemap = !(xmlReader.HasAttributes && (xmlReader.GetAttribute("noremap") == "true"));
                            // read the alias
                            string fullPartId = readBlueBrickId(ref xmlReader, ref mLDrawRemapData.mAliasPartNumber, ref mLDrawRemapData.mAliasPartColor);
                            // add the part to the remap list if need
                            if (needToAddRemap)
                                BrickLibrary.Instance.AddToTempRenamedPartList(fullPartId, this);
                        }
                        else
                            xmlReader.Read();
                        // check if we need to continue
                        continueToRead = !xmlReader.Name.Equals("LDraw") && !xmlReader.EOF;
                    }

                    // finish the LDraw tag
                    if (!xmlReader.EOF)
                        xmlReader.ReadEndElement();
                }
                else
                {
                    xmlReader.Read();
                }
            }
Пример #6
0
 public static RectangleF readRectangleF(System.Xml.XmlReader reader)
 {
     reader.ReadToDescendant("X");
     float x = reader.ReadElementContentAsFloat();
     float y = reader.ReadElementContentAsFloat();
     float width = reader.ReadElementContentAsFloat();
     float height = reader.ReadElementContentAsFloat();
     reader.ReadEndElement();
     return (new RectangleF(x, y, width, height));
 }
Пример #7
0
 public override void ReadXml(System.Xml.XmlReader reader)
 {
     base.ReadXml(reader);
     // avoid using the accessor to reduce the number of call of updateBitmap
     // for some strange reason, the new lines are read "/n" no matter the environnement,
     // so reset it as the environnement wants it, such as the edit text form works correctly
     mText = reader.ReadElementContentAsString().Replace("\n", Environment.NewLine);
     mOrientation = reader.ReadElementContentAsFloat();
     mTextBrush.Color = XmlReadWrite.readColor(reader);
     mTextFont = XmlReadWrite.readFont(reader);
     // for the last use the accessor to recreate the bitmap
     string alignment = reader.ReadElementContentAsString();
     if (alignment.Equals("Near"))
         TextAlignment = StringAlignment.Near;
     else if (alignment.Equals("Far"))
         TextAlignment = StringAlignment.Far;
     else
         TextAlignment = StringAlignment.Center;
     // read the end element of the brick
     reader.ReadEndElement();
 }
Пример #8
0
 public override void ReadXml(System.Xml.XmlReader reader)
 {
     // read the LayerItem properties
     base.ReadXml(reader);
     // read the common data of the ruler
     mColor = XmlReadWrite.readColor(reader);
     mLineThickness = reader.ReadElementContentAsFloat();
     mDisplayDistance = reader.ReadElementContentAsBoolean();
     mDisplayUnit = reader.ReadElementContentAsBoolean();
     mGuidelineColor = XmlReadWrite.readColor(reader);
     mGuidelineThickness = XmlReadWrite.readFloat(reader);
     mGuidelineDashPattern = XmlReadWrite.readFloatArray(reader);
     this.CurrentUnit = (Tools.Distance.Unit)(XmlReadWrite.readInteger(reader));
     mMeasureFont = XmlReadWrite.readFont(reader);
     this.MeasureColor = XmlReadWrite.readColor(reader);
     // the update method will be called by the non abstract derivated class
 }
Пример #9
0
            private void readTrackDesignerBitmapTag(ref System.Xml.XmlReader xmlReader)
            {
                bool bitmapFound = xmlReader.ReadToDescendant("TDBitmap");
                // instanciate the list of bitmap id
                if (bitmapFound)
                    mTDRemapData.mConnexionData = new List<TDRemapData.ConnexionData>();

                while (bitmapFound)
                {
                    // instanciate a connection point for the current connexion
                    TDRemapData.ConnexionData connexionData = new TDRemapData.ConnexionData();

                    // read the first child node
                    xmlReader.Read();
                    bool continueToRead = !xmlReader.EOF;
                    while (continueToRead)
                    {
                        if (xmlReader.Name.Equals("BBConnexionPointIndex"))
                            connexionData.mBBConnexionPointIndex = xmlReader.ReadElementContentAsInt();
                        else if (xmlReader.Name.Equals("Type"))
                            connexionData.mType = xmlReader.ReadElementContentAsInt();
                        else if (xmlReader.Name.Equals("AngleBetweenTDandBB"))
                            connexionData.mDiffAngleBtwTDandBB = xmlReader.ReadElementContentAsFloat();
                        else
                            xmlReader.Read();

                        // check if we need to continue
                        continueToRead = !xmlReader.Name.Equals("TDBitmap") && !xmlReader.EOF;
                    }

                    // add the current connexion in the list
                    mTDRemapData.mConnexionData.Add(connexionData);

                    // go to next bitmap
                    bitmapFound = !xmlReader.EOF && xmlReader.ReadToNextSibling("TDBitmap");
                }

                // finish the bitmap list
                if (!xmlReader.EOF)
                    xmlReader.ReadEndElement();
            }
Пример #10
0
            public override void ReadXml(System.Xml.XmlReader reader)
            {
                // read the id of the brick, then add this brick in the hashtable
                if (Map.DataVersionOfTheFileLoaded >= 7)
                {
                    int brickId = int.Parse(reader.GetAttribute(0));
                    Id = brickId.ToString();
                    Map.sHashtableForRulerAttachementRebuilding.Add(brickId, this);
                }
                // read the base class
                base.ReadXml(reader);
                // avoid using the accessor to reduce the number of call of updateBitmap
                mPartNumber = BrickLibrary.Instance.getActualPartNumber(reader.ReadElementContentAsString().ToUpperInvariant());
                // but then update its electric list
                mElectricCircuitIndexList = BrickLibrary.Instance.getElectricCircuitList(mPartNumber);
                mOrientation = reader.ReadElementContentAsFloat();
                mActiveConnectionPointIndex = reader.ReadElementContentAsInt();
                // the altitude
                if (Map.DataVersionOfTheFileLoaded >= 3)
                    mAltitude = reader.ReadElementContentAsFloat();
                // update the bitmap
                updateImage();
                updateSnapMargin();
                // read the connexion points if any
                reader.ReadAttributeValue();
                int count = int.Parse(reader.GetAttribute(0));

                // check the number of connection is the same in the Brick library and in the loading file.
                // They can be different if the file was saved with an old part library and then one part
                // was updated to add or remove connection. So there is 3 different cases:
                // - if they are the same: no problems.
                // - if there is more connections in the part lib than in the file: we reserve enough space in the list,
                // based on the library value, and then we will add empty connections instances to fullfill the list
                // after finishing reading the connection tag.
                // - if there is more parts in the file than in the list, we need to discard some connection,
                // so we add a check in the parsing to create the last connections as default one (of type brick).
                // This will ensure that the link will be broken (because all connections or type BRICK are
                // broken after the loading of the file is finished) and then the GC will destroy these connections.
                // And of course the list is reserved based on the library value.

                // So first, we ask the number of connection to the part lib then allocate
                // the list of connection based on the number set in the library and not the number
                // read in the file, because finally the number of connection must be like the part lib says
                int connectionCountInBrickLibrary = BrickLibrary.Instance.getConnectionCount(mPartNumber);
                if (connectionCountInBrickLibrary > 0)
                    mConnectionPoints = new List<ConnectionPoint>(connectionCountInBrickLibrary);

                // now check if we need to parse some connection in the file
                if (count > 0)
                {
                    // declare a counter for the connections
                    int connexionIndex = 0;
                    bool connexionFound = reader.ReadToDescendant("Connexion");
                    while (connexionFound)
                    {
                        // a boolean saying if the current connection is valid or will be destroyed later
                        // because it is over the number indicated by the part library
                        // be careful mConnectionPoints can be null, so use the int var instead
                        bool isConnectionValid = (connexionIndex < connectionCountInBrickLibrary);

                        // read the id (hashcode key) of the connexion
                        reader.ReadAttributeValue();
                        String id = reader.GetAttribute(0);
                        int hashCode = int.Parse(id.Substring(1));

                        // look in the hastable if this connexion alread exists, else create it
                        ConnectionPoint connexion = ConnectionPoint.sHashtableForLinkRebuilding[hashCode] as ConnectionPoint;
                        if (connexion == null)
                        {
                            // instanciate a ConnectionPoint, and add it in the hash table
                            if (isConnectionValid)
                                connexion = new ConnectionPoint(this, connexionIndex);
                            else
                                connexion = new ConnectionPoint();
                            ConnectionPoint.sHashtableForLinkRebuilding.Add(hashCode, connexion);
                        }
                        else
                        {
                            // set the connexion type, if not set during the above creation
                            if (isConnectionValid)
                                connexion.Type = BrickLibrary.Instance.getConnexionType(this.PartNumber, connexionIndex);
                        }

                        //read the connexion data and add it in the Connection list
                        connexion.mMyBrick = this;
                        connexion.ReadXml(reader);

                        // during the reading of the connection list in the file, we check if
                        // we didn't reached the limit of the part library. If there is more connection
                        // in the file than in the part lib, we continue to read the connections,
                        // but we don't add them in the connection list.
                        if (isConnectionValid)
                            mConnectionPoints.Add(connexion);

                        // increment the connexion index
                        connexionIndex++;

                        // read the next brick
                        connexionFound = reader.ReadToNextSibling("Connexion");
                    }
                    reader.ReadEndElement();

                    // check if we read all the connections in the file, if not we have to instanciate
                    // empty connection to fullfill the list
                    if (mConnectionPoints != null)
                        for (int i = mConnectionPoints.Count; i < mConnectionPoints.Capacity; ++i)
                        {
                            ConnectionPoint connexion = new ConnectionPoint(this, i);
                            mConnectionPoints.Add(connexion);
                            // we don't need to add this connection in the hastable since we know this
                            // connection doesn't exist in the file, so there is no link attached to it
                        }

                    // update the connexion position which is not stored in the bbm file
                    // in file version before 3 it was stored, but I removed it because the connexion
                    // point can move in different part libraries
                    updateConnectionPosition();
                }
                else
                {
                    reader.Read();
                }
                // read the end element of the brick
                reader.ReadEndElement();
            }
Пример #11
0
            private void readSubPartListTag(ref System.Xml.XmlReader xmlReader)
            {
                if (!xmlReader.IsEmptyElement)
                {
                    // start to read the subpart
                    bool subpartFound = xmlReader.ReadToDescendant("SubPart");
                    if (subpartFound)
                    {
                        if (mGroupInfo == null)
                            mGroupInfo = new GroupInfo();
                        mGroupInfo.mGroupSubPartList = new List<SubPart>();
                    }

                    while (subpartFound)
                    {
                        // instanciate a sub part for the current one read
                        SubPart subPart = new SubPart();

                        // read the id of the sub part
                        subPart.mSubPartNumber = xmlReader.GetAttribute("id").ToUpperInvariant();

                        // variable to store the position of the sub part from which we will construct a transform
                        PointF position = new PointF();

                        // read the first child node of the connexion
                        xmlReader.Read();
                        bool continueToReadSubPart = (subPart.mSubPartNumber.Length > 0);
                        while (continueToReadSubPart)
                        {
                            if (xmlReader.Name.Equals("position"))
                                position = readPointTag(ref xmlReader, "position");
                            else if (xmlReader.Name.Equals("angle"))
                                subPart.mOrientation = xmlReader.ReadElementContentAsFloat();
                            else
                                xmlReader.Read();
                            // check if we reach the end of the connexion
                            continueToReadSubPart = !xmlReader.Name.Equals("SubPart") && !xmlReader.EOF;
                        }

                        // create the local transform with the rotion and the translate
                        subPart.mLocalTransformInStud = new Matrix();
                        subPart.mLocalTransformInStud.Rotate(subPart.mOrientation);
                        subPart.mLocalTransformInStud.Translate(position.X, position.Y, MatrixOrder.Append);

                        // add the current connexion in the list
                        if (subPart.mSubPartNumber.Length > 0)
                            mGroupInfo.mGroupSubPartList.Add(subPart);

                        // go to next connexion
                        subpartFound = !xmlReader.EOF && xmlReader.ReadToNextSibling("SubPart");
                    }
                    // finish the connexion
                    if (!xmlReader.EOF)
                        xmlReader.ReadEndElement();
                }
                else
                {
                    xmlReader.Read();
                }
            }
Пример #12
0
 private void readSnapMarginTag(ref System.Xml.XmlReader xmlReader)
 {
     // check if the margin is not empty
     bool continueToRead = !xmlReader.IsEmptyElement;
     if (continueToRead)
     {
         // read the first child node
         xmlReader.Read();
         while (continueToRead)
         {
             if (xmlReader.Name.Equals("left"))
                 mSnapMargin.mLeft = xmlReader.ReadElementContentAsFloat();
             else if (xmlReader.Name.Equals("right"))
                 mSnapMargin.mRight = xmlReader.ReadElementContentAsFloat();
             else if (xmlReader.Name.Equals("top"))
                 mSnapMargin.mTop = xmlReader.ReadElementContentAsFloat();
             else if (xmlReader.Name.Equals("bottom"))
                 mSnapMargin.mBottom = xmlReader.ReadElementContentAsFloat();
             else
                 xmlReader.Read();
             // check if we reach the end of the snap margin
             continueToRead = !xmlReader.Name.Equals("SnapMargin") && !xmlReader.EOF;
         }
         // finish the snap margin
         if (!xmlReader.EOF)
             xmlReader.ReadEndElement();
     }
     else
     {
         xmlReader.Read();
     }
 }
Пример #13
0
 private PointF readPointTag(ref System.Xml.XmlReader xmlReader, string pointTagName)
 {
     float x = 0;
     float y = 0;
     if (!xmlReader.IsEmptyElement)
     {
         // read the first child node (x or y)
         xmlReader.Read();
         bool continueToReadPoint = true;
         while (continueToReadPoint)
         {
             if (xmlReader.Name.Equals("x") && !xmlReader.IsEmptyElement)
                 x = xmlReader.ReadElementContentAsFloat();
             else if (xmlReader.Name.Equals("y") && !xmlReader.IsEmptyElement)
                 y = xmlReader.ReadElementContentAsFloat();
             else
                 xmlReader.Read();
             // check if we reach the end of the point
             continueToReadPoint = !xmlReader.Name.Equals(pointTagName) && !xmlReader.EOF;
         }
         // finish the point
         if (!xmlReader.EOF)
             xmlReader.ReadEndElement();
     }
     else
     {
         xmlReader.Read();
     }
     // return the point (or default 0,0 point)
     return new PointF(x, y);
 }
Пример #14
0
        public override void ReadXml(System.Xml.XmlReader reader)
        {
            //XmlSerializer serializer = new XmlSerializer(typeof(PointF));

            //reader.Get("P"), StockAnalyzerApp.Global.EnglishCulture

            //this.Point1= (PointF)serializer.Deserialize(reader);
            //this.Point2= (PointF)serializer.Deserialize(reader);
            reader.ReadStartElement();

            // Point1
            reader.ReadStartElement();
            float x, y;
            x = reader.ReadElementContentAsFloat();
            y = reader.ReadElementContentAsFloat();
            this.Point1 = new PointF(x, y);
            reader.ReadEndElement();

            // Point2
            reader.ReadStartElement();
            x = reader.ReadElementContentAsFloat();
            y = reader.ReadElementContentAsFloat();
            this.Point2 = new PointF(x, y);
            reader.ReadEndElement();

            // Pen if exists
            if (reader.Name == "Pen")
            {
                this.Pen = GraphCurveType.PenFromString(reader.ReadElementContentAsString());
            }
            else
            {
                this.Pen = DefaultPen;
            }
            reader.ReadEndElement();
        }
Пример #15
0
 public override void ReadXml(System.Xml.XmlReader reader)
 {
     base.ReadXml(reader);
     GridColor = XmlReadWrite.readColor(reader);
     GridThickness = reader.ReadElementContentAsFloat();
     SubGridColor = XmlReadWrite.readColor(reader);
     SubGridThickness = reader.ReadElementContentAsFloat();
     mGridSizeInStud = reader.ReadElementContentAsInt();
     mSubDivisionNumber = Math.Max(reader.ReadElementContentAsInt(), 2);
     if (reader.Name.Equals("DisplayGrid"))
         mDisplayGrid = reader.ReadElementContentAsBoolean();
     mDisplaySubGrid = reader.ReadElementContentAsBoolean();
     mDisplayCellIndex = reader.ReadElementContentAsBoolean();
     mCellIndexFont = XmlReadWrite.readFont(reader);
     CellIndexColor = XmlReadWrite.readColor(reader);
     mCellIndexColumnType = (CellIndexType)reader.ReadElementContentAsInt();
     mCellIndexRowType = (CellIndexType)reader.ReadElementContentAsInt();
     mCellIndexCorner = XmlReadWrite.readPoint(reader);
     // step the progress bar for the grid
     MainForm.Instance.stepProgressBar();
 }
Пример #16
0
 public override void ReadXml(System.Xml.XmlReader reader)
 {
     base.ReadXml(reader);
     // read the data of the ruler (don't use accessor to avoid multiple call to the update functions
     mControlPoint[0].mPoint = XmlReadWrite.readPointF(reader);
     mControlPoint[1].mPoint = XmlReadWrite.readPointF(reader);
     // read the id of the attached brick (if any)
     mControlPoint[0].mAttachedBrickHashCodeUsedDuringLoading = reader.ReadElementContentAsInt();
     mControlPoint[1].mAttachedBrickHashCodeUsedDuringLoading = reader.ReadElementContentAsInt();
     mOffsetDistance = reader.ReadElementContentAsFloat();
     mAllowOffset = reader.ReadElementContentAsBoolean();
     // read the end element of the ruler
     reader.ReadEndElement();
     // update the computing data after reading the 2 points and offset
     updateDisplayDataAndMesurementImage();
 }
Пример #17
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();
        }
Пример #18
0
 public override void ReadXml(System.Xml.XmlReader reader)
 {
     base.ReadXml(reader);
     // read data of the ruler (don't use this.Center because at that time the object is out of synch
     // the display area may have been read but not center yet
     mSelectionArea[0] = XmlReadWrite.readPointF(reader);
     this.Radius = reader.ReadElementContentAsFloat();
     // read the id of the attached brick (if any)
     mAttachedBrickHashCodeUsedDuringLoading = XmlReadWrite.readItemId(reader);
     // read the end element of the ruler
     reader.ReadEndElement();
     // don't need to update the display area after reading the data values, because the accessor of Radius did it
 }
Пример #19
0
            private void readConnexionListTag(ref System.Xml.XmlReader xmlReader, Dictionary<string, int> connectionRemapingDictionary)
            {
                if (!xmlReader.IsEmptyElement)
                {
                    // the connexion
                    bool connexionFound = xmlReader.ReadToDescendant("connexion");
                    if (connexionFound)
                    {
                        mConnectionPoints = new List<ConnectionPoint>();
                        mConnectionPositionList = new List<PointF>();
                    }

                    while (connexionFound)
                    {
                        // instanciate a connection point for the current connexion
                        ConnectionPoint connectionPoint = new ConnectionPoint();

                        // read the first child node of the connexion
                        xmlReader.Read();
                        bool continueToReadConnexion = true;
                        while (continueToReadConnexion)
                        {
                            if (xmlReader.Name.Equals("type"))
                                connectionPoint.mType = readConnectionType(ref xmlReader, connectionRemapingDictionary);
                            else if (xmlReader.Name.Equals("position"))
                                connectionPoint.mPosition = readPointTag(ref xmlReader, "position");
                            else if (xmlReader.Name.Equals("angle"))
                                connectionPoint.mAngle = xmlReader.ReadElementContentAsFloat();
                            else if (xmlReader.Name.Equals("angleToPrev"))
                                connectionPoint.mAngleToPrev = xmlReader.ReadElementContentAsFloat();
                            else if (xmlReader.Name.Equals("angleToNext"))
                                connectionPoint.mAngleToNext = xmlReader.ReadElementContentAsFloat();
                            else if (xmlReader.Name.Equals("nextConnexionPreference"))
                                connectionPoint.mNextPreferedIndex = xmlReader.ReadElementContentAsInt();
                            else if (xmlReader.Name.Equals("electricPlug"))
                                connectionPoint.mElectricPlug = xmlReader.ReadElementContentAsInt();
                            else
                                xmlReader.Read();
                            // check if we reach the end of the connexion
                            continueToReadConnexion = !xmlReader.Name.Equals("connexion") && !xmlReader.EOF;
                        }

                        // add the current connexion in the list
                        mConnectionPoints.Add(connectionPoint);
                        mConnectionPositionList.Add(connectionPoint.mPosition);

                        // go to next connexion
                        connexionFound = !xmlReader.EOF && xmlReader.ReadToNextSibling("connexion");
                    }
                    // finish the connexion
                    if (!xmlReader.EOF)
                        xmlReader.ReadEndElement();

                    // build the electric circuit if these connections are electrical
                    // to know if there's a circuit between two connections, we must find pairs like
                    // 1/-1 or 2/-2 or 3/-3, etc...
                    if (mConnectionPoints != null)
                    {
                        int nbPossibleCircuits = mConnectionPoints.Count - 1;
                        for (int i = 0; i < nbPossibleCircuits; ++i)
                            for (int j = i + 1; j < mConnectionPoints.Count; ++j)
                                if ((mConnectionPoints[i].mElectricPlug != 0) &&
                                    (mConnectionPoints[i].mElectricPlug == -mConnectionPoints[j].mElectricPlug))
                                {
                                    // we found a circuit, so create the list if not already done
                                    if (this.mElectricCircuitList == null)
                                        this.mElectricCircuitList = new List<ElectricCircuit>();
                                    // compute the distance between the two connection (length of the circuit)
                                    PointF distance = new PointF(	mConnectionPoints[i].mPosition.X - mConnectionPoints[j].mPosition.X,
                                                                    mConnectionPoints[i].mPosition.Y - mConnectionPoints[j].mPosition.Y);
                                    float length = (float)Math.Sqrt((distance.X * distance.X) + (distance.Y * distance.Y));
                                    // add the new circuit in the list
                                    this.mElectricCircuitList.Add(new ElectricCircuit(i, j, length));
                                }
                    }
                }
                else
                {
                    xmlReader.Read();
                }
            }