public override void ReadXML(System.Xml.XmlReader input)
        {
            input.ReadToDescendant("min");
            var s = input.ReadString().Split(new char[] { ',' });
            if (s.Length != 3) throw new FormatException("Bounding box vector value formatted incorrectly.");
            this.MinX = float.Parse(s[0].Trim());
            this.MinY = float.Parse(s[1].Trim());
            this.MinZ = float.Parse(s[2].Trim());

            input.ReadToNextSibling("max");
            s = input.ReadString().Split(new char[] { ',' });
            if (s.Length != 3) throw new FormatException("Bounding box vector value formatted incorrectly.");
            this.MaxX = float.Parse(s[0].Trim());
            this.MaxY = float.Parse(s[1].Trim());
            this.MaxZ = float.Parse(s[2].Trim());
        }
        /// <summary>
        /// Generates a collection from its XML representation.
        /// </summary>
        /// <param name="reader">System.Xml.XmlReader</param>
        public void ReadXml(System.Xml.XmlReader reader)
        {
            this.Clear();
              if (reader.ReadToDescendant("SerializableStringDictionary"))
              {
            if (reader.ReadToDescendant("DictionaryEntry"))
            {
              do
              {
            reader.MoveToAttribute("Key");
            string key = reader.ReadContentAsString();
            reader.MoveToAttribute("Value");
            string value = reader.ReadContentAsString();

            this.Add(key, value);

              } while (reader.ReadToNextSibling("DictionaryEntry"));
            }
              }
        }
Example #3
0
            public void ReadXml(System.Xml.XmlReader reader)
            {
                reader.MoveToContent();

                int row = 0;
                if (reader.IsStartElement("KeyButtonCollection") || reader.ReadToDescendant("KeyButtonCollection"))
                {
                    int rows = Convert.ToInt32(reader.GetAttribute("rows"));
                    _keys = new KeyButton[rows][];

                    if (reader.ReadToDescendant("KeyButtonRow"))
                    {
                        do
                        {
                            int col = 0;
                            int cols = Convert.ToInt32(reader.GetAttribute("cols"));
                            _keys[row] = new KeyButton[cols];

                            if (reader.ReadToDescendant("KeyButton"))
                            {
                                do
                                {
                                    _keys[row][col] = new KeyButton();
                                    _keys[row][col].ReadXml(reader);
                                    col++;
                                } while (reader.ReadToNextSibling("KeyButton"));
                            }
                            row++;
                        } while (reader.ReadToNextSibling("KeyButtonRow"));
                    }
                }
            }
Example #4
0
 public void ReadXml(System.Xml.XmlReader reader)
 {
     if (reader.ReadToFollowing(this.GetType().Name))
     {
         String s = reader.GetAttribute(Orientation.GetType().Name);
         m_orientation = (Orientation)(Enum.Parse(Orientation.GetType(), s));
         switch (m_orientation)
         {
             case Orientation.Horizontal:
                 if (reader.ReadToDescendant("Column"))
                 {
                     RowDefinitions.Add(NewRowDefinition(new GridLength(1, GridUnitType.Star), m_minGridSize.Height));
                     do
                     {
                         double width = double.Parse(reader.GetAttribute("Width"));
                         IDockLayout layout = null;
                         reader.ReadStartElement();
                         if (reader.LocalName == typeof(DockedWindow).Name)
                         {
                             DockedWindow dockedWindow = new DockedWindow(Root, reader.ReadSubtree());
                             layout = dockedWindow.DockedContent.Children.Count != 0 ? dockedWindow : null;
                             reader.ReadEndElement();
                         }
                         else if (reader.LocalName == typeof(GridLayout).Name)
                         {
                             GridLayout gridLayout = new GridLayout(Root, reader.ReadSubtree());
                             layout = gridLayout.Layouts.Count > 0 ? gridLayout : null;
                             reader.ReadEndElement();
                         }
                         if (layout != null)
                         {
                             if (Children.Count > 0)
                             {
                                 ColumnDefinitions.Add(NewColumnDefinition(new GridLength(1, GridUnitType.Auto), 0));
                                 Children.Add(NewGridSplitter(Orientation));
                             }
                             ColumnDefinitions.Add(NewColumnDefinition(new GridLength(width, GridUnitType.Star), m_minGridSize.Width));
                             m_children.Add(layout);
                             Children.Add((FrameworkElement)layout);
                         }
                     } while (reader.ReadToNextSibling("Column"));
                 }
                 break;
             case Orientation.Vertical:
                 if (reader.ReadToDescendant("Row"))
                 {
                     ColumnDefinitions.Add(NewColumnDefinition(new GridLength(1, GridUnitType.Star), m_minGridSize.Width));
                     do
                     {
                         double height = double.Parse(reader.GetAttribute("Height"));
                         IDockLayout layout = null;
                         reader.ReadStartElement();
                         if (reader.LocalName == typeof(DockedWindow).Name)
                         {
                             DockedWindow dockedWindow = new DockedWindow(Root, reader.ReadSubtree());
                             layout = dockedWindow.DockedContent.Children.Count != 0 ? dockedWindow : null;
                             reader.ReadEndElement();
                         }
                         else if (reader.LocalName == typeof(GridLayout).Name)
                         {
                             GridLayout gridLayout = new GridLayout(Root, reader.ReadSubtree());
                             layout = gridLayout.Layouts.Count > 0 ? gridLayout : null;
                             reader.ReadEndElement();
                         }
                         if (layout != null)
                         {
                             if (Children.Count > 0)
                             {
                                 RowDefinitions.Add(NewRowDefinition(new GridLength(1, GridUnitType.Auto), 0));
                                 Children.Add(NewGridSplitter(Orientation));
                             }
                             RowDefinitions.Add(NewRowDefinition(new GridLength(height, GridUnitType.Star), m_minGridSize.Height));
                             m_children.Add(layout);
                             Children.Add((FrameworkElement)layout);
                         }
                     } while (reader.ReadToNextSibling("Row"));
                 }
                 break;
         }
         for(int i = 0; i < Children.Count; i++)
         {
             Grid.SetColumn(Children[i], Orientation == Orientation.Horizontal ? i : 0);
             Grid.SetRow(Children[i], Orientation == Orientation.Vertical ? i : 0);
         }
         reader.ReadEndElement();
     }
 }
Example #5
0
        internal void UnpersistOutPortMgr(System.Xml.XmlReader reader)
        {
            // Assumes reader has started the read of element "OutputPortMgr"

            if (reader.ReadToDescendant("OutputPort"))
            {
                Guid portId;
                int portIndex = -1;
                UnpersistOutPort(reader, out portId, out portIndex);
                while (reader.ReadToNextSibling("OutputPort"))
                {
                    UnpersistOutPort(reader, out portId, out portIndex);
                }
            }
            if (reader.IsStartElement() && !reader.IsEmptyElement)
            {
                reader.Read();
            }

            // no InputPortMgr id to add to the TicketBuilder
        }
Example #6
0
        internal void UnpersistOutPort(System.Xml.XmlReader reader, out Guid portId, out int portIndex)
        {
            // Assumes reader has started the read of element "OutputPort"
            reader.MoveToAttribute("id");
            string idStr = reader["id"];
            reader.MoveToAttribute("index");
            string indexStr = reader["index"];
            reader.MoveToElement();

            portId = new Guid(idStr);
            portIndex = XmlConvert.ToInt32(indexStr);

            if (reader.ReadToDescendant("OutboundPipe"))
            {
                Guid pipeId;
                UnpersistOutboundPipe(reader, out pipeId);
                while (reader.ReadToNextSibling("OutboundPipe"))
                {
                    UnpersistOutboundPipe(reader, out pipeId);
                }
            }
            if (reader.IsStartElement() && !reader.IsEmptyElement)
            {
                reader.Read();
            }

            TicketBuilder.AddOutputPortId(portId, portIndex);
        }
Example #7
0
        protected string ReceiveXmlMessage(System.Xml.XmlReader reader)
        {
            string strCommand = "";

              if (reader.ReadToFollowing("Command"))
              //if (reader.Name == "Command")
              {
            strCommand = reader.GetAttribute("Type");
            Dictionary<string, string> parameterList = new Dictionary<string, string>();

            if (reader.ReadToDescendant("Parameter"))
            {
              do
              {
            string strParameterName = reader.GetAttribute("Name");
            string strParameterValue = reader.ReadElementString();

            parameterList.Add(strParameterName, strParameterValue);
              } while (reader.ReadToNextSibling("Parameter"));
            }

            switch (strCommand)
            {
              case Commands.Configuration.Command:
            //load saved configuration values
            LoadingConfigValues(parameterList);
            return "";

              case Commands.GetConfiguration.Command:
            return ReturnConfiguration();
              //break;

              case Commands.GetSupportedFeatures.Command: // "GetSupportedFeatures":
            //e.g. Worklist, CurveData, Attachment_Type, Attachment_Path
            return ReturnSupportedFeatures();
              //break;
              case Commands.SearchPatients.Command: // "SearchPatient":
            //list of patients
            return ReturnSearchPatientResult(parameterList);

              case Commands.TestResult.Command: // "TestResult":
            //Do nothing. Results are read from output file.
            return "";
              default:
            return @"
              <ndd>
                <Command Type=""Error"">
                  <Parameter Name=""Message"">Command not supported</Parameter>
                  <Parameter Name=""Details"">" + strCommand + @"</Parameter>
                </Command>
              </ndd>";
            }
              }

              while (reader.Read())
              {
            if (reader.Name == "Patients")
            {
              System.Xml.XmlReader patientReader = reader.ReadSubtree();
              while (patientReader.ReadToFollowing("Patient"))
              {
            if (patientReader.ReadAttributeValue() && patientReader.AttributeCount > 0)
            {
              string strPatientID = patientReader.GetAttribute("ID");
              string strPatientNone = patientReader.GetAttribute("NotAvailable");
            }

            while (patientReader.Read())
            {
              if (patientReader.Name == "FirstName")
              {
                string strName = patientReader.ReadString();
              }
            }

              }
              if (reader.ReadToFollowing("Patient"))
              {

              }
            }
              }

              Console.Beep();

              return "";
        }
Example #8
0
 /// <summary>
 /// Generate object from its XML representation</summary>
 /// <param name="reader">XmlReader stream from which object is deserialized</param>
 public void ReadXml(System.Xml.XmlReader reader)
 {
     if (reader.ReadToFollowing(this.GetType().Name))
     {
         if (reader.ReadToDescendant("Content"))
         {
             do
             {
                 String ucid = reader.GetAttribute("UCID");
                 DockContent content = Root.GetContent(ucid);
                 if (content != null)
                 {
                     AddContent(content);
                 }
             } while (reader.ReadToNextSibling("Content"));
         }
         reader.Read();
     }
 }
Example #9
0
        internal void UnpersistCore(IWorkSpace workSpace, System.Xml.XmlReader reader)
        {
            // Assumes reader has started the read of element "WorkSpace"
            reader.MoveToAttribute("id");
            string idStr = reader["id"];

            reader.MoveToAttribute("mode");
            string modeStr = reader["mode"];

            reader.MoveToElement();

            workSpace.Id = new Guid(idStr);
            workSpace.ExecMode = (ExecutionModes)Enum.Parse(typeof(ExecutionModes), modeStr);

            // -------------------------

            int startDepth = reader.Depth;

            // in expected order
            if (reader.ReadToDescendant("Settings"))
            {
                UnpersistSettingsMgr(workSpace.SettingsMgr, reader);

                if (reader.ReadToNextSibling("Options"))
                {
                    UnpersistOptionsMgr(workSpace.OptionsMgr, reader);
                }
                if (reader.ReadToNextSibling("Variables"))
                {
                    UnpersistVarMgr(workSpace.VarMgr, reader);
                }
                if (reader.ReadToNextSibling("Elements"))
                {
                    UnpersistElements(workSpace.ElementsMgr, reader);
                }
                if (reader.ReadToNextSibling("Pipes"))
                {
                    UnpersistPipes(workSpace.PipesMgr, reader);
                }
                if (reader.ReadToNextSibling("WorkSpaceProperties"))
                {
                    UnpersistProperties(workSpace.WSProperties, reader);
                }
                // read up to the end "WorkSpace" tag
                if (reader.Depth > startDepth)
                {
                    reader.Read();
                }
            }
        }
            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();
            }
Example #11
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();
            }
Example #12
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();
                }
            }
Example #13
0
            private void readGroupConnectionPreferenceListTag(ref System.Xml.XmlReader xmlReader)
            {
                if (!xmlReader.IsEmptyElement)
                {
                    // start to read the subpart
                    bool entryFound = xmlReader.ReadToDescendant("nextIndex");
                    if (entryFound)
                    {
                        if (mGroupInfo == null)
                            mGroupInfo = new GroupInfo();
                        mGroupInfo.mGroupNextPreferedConnection = new Dictionary<int, int>();
                    }

                    while (entryFound)
                    {
                        // read the "from" connection index
                        int from = int.Parse(xmlReader.GetAttribute("from"));
                        int to = xmlReader.ReadElementContentAsInt();

                        // store the prefered connection couple
                        mGroupInfo.mGroupNextPreferedConnection.Add(from, to);

                        // go to next index
                        entryFound = !xmlReader.EOF && xmlReader.ReadToNextSibling("nextIndex");
                    }
                    // finish the connexion
                    if (!xmlReader.EOF)
                        xmlReader.ReadEndElement();
                }
                else
                {
                    xmlReader.Read();
                }
            }
Example #14
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();
                }
            }
Example #15
0
        private void CreateSourceTable(System.Xml.XmlReader reader)
        {
            string[] columnNames;
            ArrayList names = new ArrayList();
            reader.MoveToAttribute("TableName");
            string codeTableName = reader.Value.ToString();

            DataTable fromXml = new DataTable(codeTableName);
            DataRow rowFromXml;

            reader.ReadToFollowing("Item");

            do
            {
                if (reader.MoveToFirstAttribute())
                {
                    string columnName = reader.Name.Replace("__space__", " ");

                    if (fromXml.Columns.Contains(columnName) == false)
                    {
                        fromXml.Columns.Add(columnName, System.Type.GetType("System.String"));
                    }

                    rowFromXml = fromXml.NewRow();
                    rowFromXml[columnName] = reader.Value;

                    while (reader.MoveToNextAttribute())
                    {
                        columnName = reader.Name.Replace("__space__", " ");
                        if (fromXml.Columns.Contains(columnName) == false)
                        {

                            fromXml.Columns.Add(columnName, System.Type.GetType("System.String"));
                            DataRow tempRow = fromXml.NewRow();
                            tempRow.ItemArray = rowFromXml.ItemArray;
                        }

                        rowFromXml[columnName] = reader.Value;
                    }

                    fromXml.Rows.Add(rowFromXml);
                }
            }
            while (reader.ReadToNextSibling("Item"));

            if (mediator.Project.Metadata.TableExists(codeTableName))
            {
                DataTable existing = mediator.Project.Metadata.GetCodeTableData(codeTableName);

                if (TablesAreDifferent(existing, fromXml))
                {
                    foreach (DataColumn column in fromXml.Columns)
                    {
                        names.Add(column.ColumnName);
                    }
                    columnNames = (string[])names.ToArray(typeof(string));

                    DialogResult replaceWithTemplate = MsgBox.ShowQuestion("A code table with the following name already exists in the database: " + existing + ".  Replace code table with the code table defined in the template?" );

                    if (replaceWithTemplate == DialogResult.Yes)
                    {
                        mediator.Project.Metadata.DeleteCodeTable(codeTableName);
                        mediator.Project.Metadata.CreateCodeTable(codeTableName, columnNames);
                        mediator.Project.Metadata.SaveCodeTableData(fromXml, codeTableName, columnNames);
                    }
                    else
                    {
                        string newCodeTableName = codeTableName;

                        DataSets.TableSchema.TablesDataTable tables = mediator.Project.Metadata.GetCodeTableList();

                        int arbitraryMax = 2048;

                        for (int nameExtension = 1; nameExtension < arbitraryMax; nameExtension++)
                        {
                            foreach (DataRow row in tables)
                            {
                                if (newCodeTableName.ToLower() == ((string)row[ColumnNames.TABLE_NAME]).ToLower())
                                {
                                    newCodeTableName = codeTableName + nameExtension.ToString();
                                    break;
                                }
                            }

                            if (newCodeTableName != codeTableName + nameExtension.ToString())
                            {
                                break;
                            }
                        }

                        _sourceTableRenames.Add(codeTableName, newCodeTableName);
                        mediator.Project.Metadata.CreateCodeTable(newCodeTableName, columnNames);
                        mediator.Project.Metadata.SaveCodeTableData(fromXml, newCodeTableName, columnNames);
                    }
                }
            }
            else
            {
                foreach (DataColumn column in fromXml.Columns)
                {
                    string columnName = column.ColumnName.Replace("__space__", " ");
                    names.Add(columnName);
                }
                columnNames = (string[])names.ToArray(typeof(string));

                mediator.Project.Metadata.CreateCodeTable(codeTableName, columnNames);
                mediator.Project.Metadata.SaveCodeTableData(fromXml, codeTableName, columnNames);
            }
        }
Example #16
0
        internal void UnpersistPipes(IPipes pipes, System.Xml.XmlReader reader)
        {
            // Assumes reader has started the read of element "Pipes"

            if (reader.ReadToDescendant("Pipe"))
            {
                UnpersistPipe(pipes, reader);
                while (reader.ReadToNextSibling("Pipe"))
                {
                    UnpersistPipe(pipes, reader);
                }
            }
            if (reader.IsStartElement() && !reader.IsEmptyElement)
            {
                reader.Read();
            }
        }
Example #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();
        }
	/// <summary>
	/// Loads the inventory from XML.
	/// </summary>
	/// <param name="reader">Reader.</param>
	public void LoadInventory(System.Xml.XmlReader reader) {
		int itemCount = 0;
		reader.ReadToFollowing ("Inventory");
		reader.ReadToDescendant ("Item");
		do {
			string id = reader.GetAttribute ("ID");
			inventory [itemCount] = database [int.Parse (id)].Clone ();
			reader.ReadToDescendant ("Quantity");
			inventory [itemCount].stackSize = reader.ReadElementContentAsInt();
			Debug.Log ("Just parsed " + inventory [itemCount]);
			itemCount++;
			reader.ReadEndElement();
		} while(reader.ReadToNextSibling("Item"));
		reader.ReadEndElement ();
	}
Example #19
0
        internal void UnpersistCore(System.Xml.XmlReader reader, out IElement element)
        {
            element = null;

            // Assumes reader has started the read of element "Element"
            reader.MoveToAttribute("id");
            string idStr = reader["id"];

            reader.MoveToAttribute("typeId");
            string typeIdStr = reader["typeId"];

            reader.MoveToAttribute("typeName");
            string typeName = reader["typeName"];

            reader.MoveToElement();

            TicketBuilder.ElementId = new Guid(idStr);
            TicketBuilder.TypeId = new Guid(typeIdStr);

            // -------------------------

            int startDepth = reader.Depth;

            // in expected order
            if (reader.ReadToDescendant("Fx"))  // Fx node must be there, it has an id to read in
            {
                UnpersistFx(reader);

                if (reader.ReadToNextSibling("InputPortMgr"))
                {
                    UnpersistInPortMgr(reader);
                }
                if (reader.ReadToNextSibling("OutputPortMgr"))
                {
                    UnpersistOutPortMgr(reader);
                }

                IElementTicket ticket = TicketBuilder.Ticket;
                element = ReConstitute(ticket);

                if (reader.ReadToNextSibling("Settings"))
                {
                    UnpersistSettingsMgr(element, reader);
                }
                // Options are not currently being used or persisted
                //if (reader.ReadToNextSibling("Options"))
                //{
                //    UnpersistOptionsMgr(reader);
                //}
                if (reader.ReadToNextSibling("ParamMgr"))
                {
                    UnpersistParamMgr(element, reader);
                }

                // read up to the end "Element" tag
                if (reader.Depth > startDepth)
                {
                    reader.Read();
                }
            }
        }
Example #20
0
 /// <summary>
 /// Generate object from its XML representation</summary>
 /// <param name="reader">XmlReader stream from which object is deserialized</param>
 public void ReadXml(System.Xml.XmlReader reader)
 {
     reader.Read();
     if (reader.LocalName == this.GetType().Name || reader.LocalName == "MultiContent") // MultiContent is old name and is used here for compatibility with old saved layouts
     {
         String selectedUcid = reader.GetAttribute("SelectedUID");
         DockContent found = null;
         reader.ReadStartElement();
         if (reader.LocalName == "Content")
         {
             do
             {
                 String ucid = reader.GetAttribute("UCID");
                 DockContent content = Root.GetContent(ucid);
                 if (content != null)
                 {
                     AddOneItem(null, content);
                     if (selectedUcid == ucid)
                     {
                         found = content;
                     }
                 }
             } while (reader.ReadToNextSibling("Content"));
             if (found != null)
             {
                 SelectedItem = found;
             }
         }
         reader.ReadEndElement();
     }
 }
Example #21
0
        public override void ReadXml(System.Xml.XmlReader reader)
        {
            base.ReadXml(reader);
            // before version 5, the transparency was only in the area layer, after it is read in the base class
            if (Map.DataVersionOfTheFileLoaded < 5)
                mTransparency = reader.ReadElementContentAsInt();
            // read the cell size
            mAreaCellSizeInStud = reader.ReadElementContentAsInt();
            // the areas list
            int currentLineIndex = int.MaxValue;
            bool areaFound = reader.ReadToDescendant("Area");
            while (areaFound)
            {
                // read all the data of the area
                reader.ReadToDescendant("x");
                int x = reader.ReadElementContentAsInt();
                int y = reader.ReadElementContentAsInt();
                string stringColor = reader.ReadElementContentAsString();
                Color color = Color.FromArgb(int.Parse(stringColor, System.Globalization.NumberStyles.HexNumber));
                // and paint the appropriate cell
                paintCell(x, y, color);

                // read the next area
                areaFound = reader.ReadToNextSibling("Area");

                // step the progress bar for each line
                if (x != currentLineIndex)
                {
                    MainForm.Instance.stepProgressBar();
                    currentLineIndex = x;
                }
            }
            // read the Areas tag, to finish the list of area
            reader.Read();
        }