private void btn_OK_Click(object sender, EventArgs e) { if (Step.getObjectList() != null && Step.getObjectList().Count > 0) { // //Crete the Step's elements. // Step.setName(txtBx_Title.Text); Step.setDescription(txtBx_Description.Text); Step.setObjectList(RenderForm.Objects); if (_Operation == Operation.AddNew) { //Add the created step to the steps list of the procedure. this.Brother.procedure.addEtape(Step); //Fill the list view with the step's data. ListViewItem item = new ListViewItem(new string[] { Step.getId().ToString(), Step.getName(), Step.getDescription() }); this.Brother.lstVew_Steps.Items.Add(item); } else { //Get the selected item (step) from the list. int selected = Brother.lstVew_Steps.SelectedIndices[0]; ListViewItem item = Brother.lstVew_Steps.Items[selected]; //Add the created step to the steps list of the procedure. //Remove the old version of step. this.Brother.procedure.steps.RemoveAt(selected); //Insert the new version at the same place. this.Brother.procedure.steps.Insert(selected, Step); //Fill the list view with the step's data. item = new ListViewItem(new string[] { Step.getId().ToString(), Step.getName(), Step.getDescription() }); //Remove the old version of step. Brother.lstVew_Steps.Items.RemoveAt(selected); //Insert the new version at the same place. Brother.lstVew_Steps.Items.Insert(selected, item); } Dispose(); } else { MessageBox.Show(this, "L'étape doit avoir au minimum un objet.", "Message d'erreur", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btn_ModifySetp_Click(object sender, EventArgs e) { if (lstVew_Steps.SelectedIndices.Count > 0) { //Set the procedure data if its not already set. this.procedure.setName(txtBx_Title.Text); this.procedure.setDescription(txtBx_Description.Text); //Get the selected item (step) from the list. int selected = lstVew_Steps.SelectedIndices[0]; ListViewItem item = lstVew_Steps.Items[selected]; //Etape step = new Etape(Convert.ToInt32(item.SubItems[0].Text), item.SubItems[1].Text, item.SubItems[2].Text, this.procedure); Etape step = null; //Gets the id of the selected Step. int id = Convert.ToInt32(item.SubItems[0].Text); //MessageBox.Show("SelectedStepId: " + id, "frm_AddProcedure.btn_ModifyStep"); //In the list of the procedure steps we look for the step with the previous Id. foreach (Etape stp in this.procedure.steps) { if (stp.getId() == id) { step = stp; break; } } //We send the slected step to the update form. frm_AddStep frm = new frm_AddStep(null, step, this.procedure, Operation.Update); frm.ShowDialog(); //Add the created step to the steps list of the procedure. if (frm.Tag != null) { step = (Etape)frm.Tag; //Remove the old version of step. this.procedure.steps.RemoveAt(selected); //Insert the new version at the same place. this.procedure.steps.Insert(selected, step); //Fill the list view with the step's data. item = new ListViewItem(new string[] { step.getId().ToString(), step.getName(), step.getDescription() }); //Remove the old version of step. lstVew_Steps.Items.RemoveAt(selected); //Insert the new version at the same place. lstVew_Steps.Items.Insert(selected, item); } } else { MessageBox.Show(this, "Sélectionner une étape SVP.", "Message d'erreur", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btn_AddStep_Click(object sender, EventArgs e) { this.procedure.setName(txtBx_Title.Text); this.procedure.setDescription(txtBx_Description.Text); //steps[steps.Count - 1] is the previous step of the one which is about to be created. //The last step is previous of the one to create now. Etape prevStep; if (this.procedure.steps != null && this.procedure.steps.Count > 0) { prevStep = this.procedure.steps[this.procedure.steps.Count - 1]; } else { prevStep = null; } frm_AddStep frm = new frm_AddStep(prevStep, null, this.procedure, Operation.AddNew); frm.ShowDialog(); //Add the created step to the steps list of the procedure. if (frm.Tag != null) { Etape step = (Etape)frm.Tag; this.procedure.addEtape(step); //Fill the list view with the step's data. ListViewItem item = new ListViewItem(new string[] { step.getId().ToString(), step.getName(), step.getDescription() }); lstVew_Steps.Items.Add(item); } }
private void frm_AddStep_Load(object sender, EventArgs e) { lstVw_3dObjects.Width++; lstVw_3dObjects.Width--; //Set the name of the procedure to whom this Step belongs. if (this.Procedure != null) { lbl_ProcedureName.Text = this.Procedure.getName(); } else { MessageBox.Show("Procedure Null", "frm_AddStep.Constructor"); } if (this._Operation == Operation.AddNew) { this.Step = new Etape(); //Since the automatic configuration of the Id depends on the etape.xml file //and the creation of multiple steps doesn't use the etape.xml file for each time //so we set our new Id depending on the previous step's ID which makes our new Id = ID+1. if (prevStep != null) { this.Step.setId(prevStep.getId() + 1); } //Reinitialise the list of 3d RenderForm.Objects RenderForm.Objects = new List <Object3d>(); } else//If this form is used to update a step, we load its data to the text fields first. { if (Step != null) { txtBx_Title.Text = Step.getName(); txtBx_Description.Text = Step.getDescription(); //RenderForm.Objects = Step.getObjectList(); //---------------------------------- if (this.Step.getObjectList() != null) { RenderForm.Objects = new List <Object3d>(); foreach (Object3d obj in this.Step.getObjectList()) { RenderForm.Objects.Add(obj); } } //MessageBox.Show("Step.Objects.count: " + Step.getObjectList().Count.ToString(),"frm_AddStep.FormLoad"); if (RenderForm.Objects != null && RenderForm.Objects.Count > 0) { foreach (Object3d obj in RenderForm.Objects) { //MessageBox.Show("obj.path: " + obj.getPath() + ". name: " + obj.getName() + ". type: " + obj.getObjType(), "frm_AddStep.RenderForm"); obj.setDevice(RenderForm.m_Device); obj.LoadMesh(); //Fill the list view with the RenderForm.Objects data. //System.Windows.Forms.MessageBox.Show("obj.Id: " + obj.getId() + "\nPosX: " + obj.getPosition().X + "\nPosY: " + obj.getPosition().Y + // "\nPosZ: " + obj.getPosition().Z,"frm_AddStep.FromLoad"); ListViewItem item = new ListViewItem(new string[] { obj.getId().ToString(), obj.getNb().ToString(), Path.GetFileNameWithoutExtension(obj.getName()), obj.getObjType(), VectorToString(obj.getPosition()), VectorToString(obj.getRotation()), VectorToString(obj.getScale()) }); lstVw_3dObjects.Items.Add(item); } } } } txtBx_Id.Text = this.Step.getId().ToString(); }
/// <summary> /// Modifies the etape Data. /// </summary> /// <param name="login">The id of the target Etape object.</param> /// <param name="admin">The object that holds the new data.</param> /// <returns></returns> public static bool Update(int id, Etape etape) { try { /* On utilise un XmlDocument et non un XPathDocument car ce dernier ne permet * pas l'édition des données XML. */ XmlDocument XmlDoc = new XmlDocument(); XPathNavigator Navigator; XPathNodeIterator Nodes; string rslt = Helper.service.LoadFile("etape.xml").ToString(); StreamWriter sw = new StreamWriter(System.Windows.Forms.Application.StartupPath + "\\temp.xml"); sw.Write(rslt); sw.Close(); XmlDoc.Load(System.Windows.Forms.Application.StartupPath + "\\temp.xml"); Navigator = XmlDoc.CreateNavigator(); string ExpXPath = "//etape[@id='" + id.ToString() + "']"; Nodes = Navigator.Select(Navigator.Compile(ExpXPath)); if (Nodes.Count != 0) { /* Encodage des nouvelles données */ Nodes.MoveNext(); Nodes.Current.MoveToFirstAttribute(); Nodes.Current.SetValue(id.ToString()); Nodes.Current.MoveToParent(); Nodes.Current.MoveToFirstChild(); //System.Windows.Forms.MessageBox.Show(Nodes.Current.Name.ToString() + " | " + Nodes.Current.Value.ToString()); Nodes.Current.SetValue(etape.getName()); Nodes.Current.MoveToNext(XPathNodeType.Element); Nodes.Current.SetValue(etape.getDescription()); Nodes.Current.MoveToNext(XPathNodeType.Element); //System.Windows.Forms.MessageBox.Show("Update: "+Nodes.Current.Name); { //Delete the set of objects. Nodes.Current.DeleteSelf(); //Recreate the objects. //System.Windows.Forms.MessageBox.Show("XMLStep.Update.Objects.Count: " + etape.getObjectList().Count.ToString()); if (etape.getObjectList().Count > 0) { InsertObjects(id, etape.getObjectList(), Nodes); } } Nodes.Current.MoveToFirstChild(); Nodes.Current.MoveToNext(); //Move to Libelle. Nodes.Current.MoveToNext(); //Move to Description. //System.Windows.Forms.MessageBox.Show("Update: " + Nodes.Current.Name); Nodes.Current.MoveToNext(XPathNodeType.Element); Nodes.Current.SetValue(etape.getprocedure().getId().ToString()); //System.Windows.Forms.MessageBox.Show("Update: " + Nodes.Current.Name); //return false; //XmlDoc.Save((Stream)Helper.service.LoadFile("etape.xml"); Helper.service.SaveXmlFile("etape.xml", XmlDoc); } else { return(false); } } catch (System.IO.FileNotFoundException x) { } catch (Exception x) { System.Windows.Forms.MessageBox.Show(x.ToString()); } return(true); }
/// <summary> /// inserts a step to "etape.xml". /// </summary> /// <param name="expert">The object holding the data</param> /// <returns></returns> private static bool Insert(Etape etape) { try { XmlDocument XmlDoc = new XmlDocument(); XPathNavigator Navigator; XPathNodeIterator Nodes; Int32 ID; /* Variable utilisée pour savoir quel est l'ID qu'il faut affecter au nouveau * noeud créé */ string rslt = Helper.service.LoadFile("etape.xml").ToString(); StreamWriter sw = new StreamWriter(System.Windows.Forms.Application.StartupPath + "\\temp.xml"); sw.Write(rslt); sw.Close(); XmlDoc.Load(System.Windows.Forms.Application.StartupPath + "\\temp.xml"); Navigator = XmlDoc.CreateNavigator(); /* Recherche du noeud MaxID pour déterminer quelle sera l'ID du nouveau * procedure. */ string ExpXPath = "//MaxID"; Nodes = Navigator.Select(Navigator.Compile(ExpXPath)); Nodes.MoveNext(); /* On place l'ID le plus élevé du document dans la variable ID */ ID = Nodes.Current.ValueAsInt; /* On incrémente la valeur du noeud MaxID car une fois notre nouveau noeud * créé, l'ID le plus élevé du document sera aussi incrémenté */ Nodes.Current.SetValue((ID + 1).ToString()); /* On se place sur le noeud ayant l'ID le plus élevé */ //ExpXPath = "//etape[@id='" + ID.ToString() + "']"; //Nodes = Navigator.Select(Navigator.Compile(ExpXPath)); if (Nodes.Count != 0) { //Nodes.MoveNext(); /* On crée le noeud principal (etape). */ Nodes.Current.MoveToPrevious(); //System.Windows.Forms.MessageBox.Show("Current.Previous: " + Nodes.Current.Name,"XMLStep.Insert"); Nodes.Current.InsertElementAfter("", "etape", "", ""); /* On se place sur le noeud ainsi créé. */ Nodes.Current.MoveToNext(XPathNodeType.Element); ID++; /* On incrémente ID pour que sa valeur soit identique à celle se * trouvant dans le noeud MaxID. */ /* Encodage des données */ Nodes.Current.CreateAttribute("", "id", "", ID.ToString()); Nodes.Current.AppendChildElement("", "libelle", "", etape.getName()); Nodes.Current.AppendChildElement("", "description", "", etape.getDescription()); int count = 0; //System.Windows.Forms.MessageBox.Show("3d obj "+etape.getObjectList().Count.ToString()); Nodes.Current.AppendChildElement("", "objets", "", ""); //Create node objets. Nodes.Current.MoveToFollowing(XPathNodeType.Element); //Move to libelle. Nodes.Current.MoveToFollowing(XPathNodeType.Element); //Move to description. Nodes.Current.MoveToFollowing(XPathNodeType.Element); //Move to objets. //System.Windows.Forms.MessageBox.Show("Before Loop:" + Nodes.Current.Name); foreach (Object3d obj in etape.getObjectList()) { //System.Windows.Forms.MessageBox.Show("count:" + count); Nodes.Current.AppendChildElement("", "objet", "", ""); //Create node objet. Nodes.Current.MoveToFollowing(XPathNodeType.Element); //Move to objet. //Move pass all the created object elements. for (int i = 0; i < count + 1; i++) { //Nodes.Current.MoveToFollowing(XPathNodeType.Element);//Move to objet. Nodes.Current.MoveToNext(); } //System.Windows.Forms.MessageBox.Show("for Loop:"+Nodes.Current.Name); Nodes.Current.CreateAttribute("", "id", "", obj.getId().ToString()); //Nodes.Current.CreateAttribute("", "nb", "", obj.getNb().ToString()); Nodes.Current.CreateAttribute("", "nb", "", count.ToString()); count++; Nodes.Current.AppendChildElement("", "position", "", ""); //Create node position. Nodes.Current.MoveToFollowing(XPathNodeType.Element); //Move to node position. //Transform axis float X, Y, Z; X = obj.getPosition().X; Y = obj.getPosition().Y; Z = obj.getPosition().Z; Helper.TransformAxis(ref X, ref Y, ref Z, Transformation.Translation, true); Nodes.Current.CreateAttribute("", "x", "", (X / translateFactor).ToString()); Nodes.Current.CreateAttribute("", "y", "", (Y / translateFactor).ToString()); Nodes.Current.CreateAttribute("", "z", "", (zFactor * Z / translateFactor).ToString()); Nodes.Current.MoveToParent(); //Move back to objet. Nodes.Current.AppendChildElement("", "rotation", "", ""); //Create node rotation. Nodes.Current.MoveToFollowing(XPathNodeType.Element); //Move to node position. Nodes.Current.MoveToFollowing(XPathNodeType.Element); //Move to node rotation. float angleRad = Helper.DegreesToRadians(Constante.stableAngle); Vector3 v = Vector3.Multiply(obj.getRotation(), 1 / angleRad); Vector3 N = Helper.Normalize(v); //System.Windows.Forms.MessageBox.Show("obj/angle: " + v.ToString() + "\nNorm: " + v1.ToString()); angleRad = angleRad / (N.X / v.X); //angle = Helper.RadiansToDegrees(angleRad); angle = Constante.stableAngle; if (obj.getRotation().X + obj.getRotation().Y + obj.getRotation().Z == 0) { Nodes.Current.CreateAttribute("", "angle", "", (0).ToString()); } else { Nodes.Current.CreateAttribute("", "angle", "", (angle).ToString()); } //System.Windows.Forms.MessageBox.Show("Befor: X: " + obj.getRotation().X); X = obj.getRotation().X; Y = obj.getRotation().Y; Z = obj.getRotation().Z; Helper.TransformAxis(ref X, ref Y, ref Z, Transformation.Rotation, true); //System.Windows.Forms.MessageBox.Show("After: X: " + obj.getRotation().X); Nodes.Current.CreateAttribute("", "x", "", (Helper.RadiansToDegrees(X) / angle).ToString()); Nodes.Current.CreateAttribute("", "y", "", (Helper.RadiansToDegrees(Y) / angle).ToString()); Nodes.Current.CreateAttribute("", "z", "", (Helper.RadiansToDegrees(Z) / angle).ToString()); Nodes.Current.MoveToParent(); //Move back to objet. Nodes.Current.AppendChildElement("", "scale", "", ""); //Create node scale. Nodes.Current.MoveToFollowing(XPathNodeType.Element); //Move to node position. Nodes.Current.MoveToFollowing(XPathNodeType.Element); //Move to node rotation. Nodes.Current.MoveToFollowing(XPathNodeType.Element); //Move to node scale. Nodes.Current.CreateAttribute("", "x", "", (obj.getScale().X *scaleFactor).ToString()); Nodes.Current.CreateAttribute("", "y", "", (obj.getScale().Y *scaleFactor).ToString()); Nodes.Current.CreateAttribute("", "z", "", (obj.getScale().Z *scaleFactor).ToString()); Nodes.Current.MoveToParent(); //Move back to objet. //System.Windows.Forms.MessageBox.Show("End "+Nodes.Current.Name); Nodes.Current.MoveToParent(); //Move back to objets. //System.Windows.Forms.MessageBox.Show("End "+Nodes.Current.Name); //System.Windows.Forms.MessageBox.Show(Nodes.Current.Name); //return false; } Nodes.Current.MoveToParent();//Move back to etape. //System.Windows.Forms.MessageBox.Show(Nodes.Current.Name); Nodes.Current.AppendChildElement("", "procedure", "", etape.getprocedure().getId().ToString()); //return false; //XmlDoc.Save((Stream)Helper.service.LoadFile("etape.xml"); //System.Windows.Forms.MessageBox.Show("Saving:"+ Helper.service.SaveXmlFile("etape.xml", XmlDoc).ToString(),"XMLStep.Insert"); Helper.service.SaveXmlFile("etape.xml", XmlDoc); } else { return(false); } } catch (System.IO.FileNotFoundException x) { } catch (Exception x) { System.Windows.Forms.MessageBox.Show(x.ToString()); } return(true); }
/// <summary> /// Creates the file "etape.xml" and inserts the first step to it. /// </summary> /// <param name="expert">The object holding the data.</param> /// <returns></returns> private static bool FirstAdd(Etape etape) { try { XmlWriterSettings wSettings = new XmlWriterSettings(); wSettings.Indent = true; System.IO.MemoryStream ms = new System.IO.MemoryStream(); XmlWriter xw = XmlWriter.Create(ms, wSettings);// Write Declaration xw.WriteStartDocument(); // Write the root node xw.WriteStartElement("Etapes"); xw.WriteStartElement("etape"); xw.WriteStartAttribute("id"); xw.WriteString("0"); xw.WriteEndAttribute(); //---------------- xw.WriteStartElement("libelle"); xw.WriteString(etape.getName()); xw.WriteEndElement(); //----------------- xw.WriteStartElement("description"); xw.WriteString(etape.getDescription()); xw.WriteEndElement(); //----------------- xw.WriteStartElement("objets"); //System.Windows.Forms.MessageBox.Show("Step.Objects.Count: " + etape.getObjectList().Count, "XMLStep.FirstAdd"); for (int i = 0; i < etape.getObjectList().Count; i++) { Object3d obj = etape.getObjectList()[i]; xw.WriteStartElement("objet");//<objet> xw.WriteStartAttribute("id"); xw.WriteString(obj.getId().ToString()); xw.WriteEndAttribute(); xw.WriteStartAttribute("nb"); xw.WriteString(i.ToString()); xw.WriteEndAttribute(); xw.WriteStartElement("position");//<position> //Transform axis float X, Y, Z; X = obj.getPosition().X; Y = obj.getPosition().Y; Z = obj.getPosition().Z; Helper.TransformAxis(ref X, ref Y, ref Z, Transformation.Translation, true); xw.WriteStartAttribute("x"); xw.WriteString((X / translateFactor).ToString()); xw.WriteEndAttribute(); xw.WriteStartAttribute("y"); xw.WriteString((Y / translateFactor).ToString()); xw.WriteEndAttribute(); xw.WriteStartAttribute("z"); xw.WriteString((zFactor * Z / translateFactor).ToString()); xw.WriteEndAttribute(); xw.WriteEndElement(); //</position> xw.WriteStartElement("rotation"); //<rotation> //Transform axis X = obj.getRotation().X; Y = obj.getRotation().Y; Z = obj.getRotation().Z; Helper.TransformAxis(ref X, ref Y, ref Z, Transformation.Rotation, true); float angleRad = Helper.DegreesToRadians(Constante.stableAngle); Vector3 v = Vector3.Multiply(obj.getRotation(), 1 / angleRad); Vector3 N = Helper.Normalize(v); //System.Windows.Forms.MessageBox.Show("obj/angle: " + v.ToString() + "\nNorm: " + v1.ToString()); angleRad = angleRad / (N.X / v.X); //angle = Helper.RadiansToDegrees(angleRad); angle = Constante.stableAngle; xw.WriteStartAttribute("angle"); if (obj.getRotation().X + obj.getRotation().Y + obj.getRotation().Z == 0) { xw.WriteString((0).ToString()); } else { xw.WriteString((angle).ToString()); } xw.WriteEndAttribute(); xw.WriteStartAttribute("x"); xw.WriteString((Helper.RadiansToDegrees(X) / angle).ToString()); xw.WriteEndAttribute(); xw.WriteStartAttribute("y"); xw.WriteString((Helper.RadiansToDegrees(Y) / angle).ToString()); xw.WriteEndAttribute(); xw.WriteStartAttribute("z"); xw.WriteString((Helper.RadiansToDegrees(Z) / angle).ToString()); xw.WriteEndAttribute(); xw.WriteEndElement(); //</rotation> xw.WriteStartElement("scale"); //<scale> xw.WriteStartAttribute("x"); xw.WriteString((obj.getScale().X *scaleFactor).ToString()); xw.WriteEndAttribute(); xw.WriteStartAttribute("y"); xw.WriteString((obj.getScale().Y *scaleFactor).ToString()); xw.WriteEndAttribute(); xw.WriteStartAttribute("z"); xw.WriteString((obj.getScale().Z *scaleFactor).ToString()); xw.WriteEndAttribute(); xw.WriteEndElement(); //</scale> xw.WriteEndElement(); //</objet> } xw.WriteEndElement(); xw.WriteStartElement("procedure"); xw.WriteString(etape.getprocedure().getId().ToString()); xw.WriteEndElement(); //----------------- xw.WriteEndElement(); xw.WriteStartElement("MaxID"); xw.WriteString("0"); xw.WriteEndElement(); // Close the document xw.WriteEndDocument(); // Flush the write xw.Flush(); Byte[] buffer = new Byte[ms.Length]; buffer = ms.ToArray(); string xmlOutput = System.Text.Encoding.UTF8.GetString(buffer); //File.WriteAllText((Stream)Helper.service.LoadFile("etape.xml", xmlOutput); Helper.service.CreateXmlFile("etape.xml", xmlOutput); } catch (System.IO.FileNotFoundException x) { } catch (Exception x) { System.Windows.Forms.MessageBox.Show(x.ToString()); } return(true); }