Ajout Sauvegarde et Ouverture de fichier
This commit is contained in:
parent
aaa450523a
commit
a25cf04d7e
11 changed files with 313 additions and 54 deletions
|
|
@ -64,6 +64,12 @@ namespace DMX2
|
|||
}
|
||||
}
|
||||
|
||||
public Circuit GetCircuitByID (int i)
|
||||
{
|
||||
foreach(Circuit c in circuits)
|
||||
if(c.ID == i) return c;
|
||||
return null;
|
||||
}
|
||||
|
||||
public string Name {
|
||||
get {
|
||||
|
|
@ -184,19 +190,69 @@ namespace DMX2
|
|||
|
||||
public XmlDocument Save ()
|
||||
{
|
||||
XmlDocument doc = new XmlDocument();
|
||||
XmlDocument xmlDoc = new XmlDocument ();
|
||||
XmlElement xmlRoot = xmlDoc.CreateElement ("Conduite");
|
||||
|
||||
xmlDoc.AppendChild (xmlRoot);
|
||||
|
||||
xmlRoot.SetAttribute ("nom", this.Name);
|
||||
|
||||
XmlElement xmlCircuits = xmlDoc.CreateElement ("Circuits");
|
||||
xmlRoot.AppendChild (xmlCircuits);
|
||||
|
||||
return doc;
|
||||
foreach (Circuit c in circuits) {
|
||||
c.Save(xmlCircuits);
|
||||
}
|
||||
|
||||
XmlElement xmlSequenceurs = xmlDoc.CreateElement("Sequenceurs");
|
||||
xmlRoot.AppendChild(xmlSequenceurs);
|
||||
|
||||
foreach(Sequenceur seq in sequenceurs)
|
||||
{
|
||||
seq.Save(xmlSequenceurs);
|
||||
}
|
||||
|
||||
XmlElement xmlUniversList = xmlDoc.CreateElement("ListeUnivers");
|
||||
xmlRoot.AppendChild(xmlUniversList);
|
||||
|
||||
foreach(UniversDMX univ in univers)
|
||||
{
|
||||
univ.Save(xmlUniversList);
|
||||
}
|
||||
|
||||
seqmaitre.Save(xmlRoot);
|
||||
|
||||
return xmlDoc;
|
||||
}
|
||||
|
||||
public static Conduite Load (XmlDocument doc)
|
||||
{
|
||||
return null;
|
||||
Conduite cond = new Conduite ();
|
||||
cond.LoadDoc (doc);
|
||||
return cond;
|
||||
// cond.Dispose();
|
||||
// return null;
|
||||
}
|
||||
|
||||
private void LoadDoc (XmlDocument doc)
|
||||
{
|
||||
XmlElement root = doc.DocumentElement;
|
||||
|
||||
_name = root.Attributes ["nom"].Value;
|
||||
|
||||
foreach (var xc in root["Circuits"].ChildNodes) {
|
||||
Circuit c = Circuit.Load (xc as XmlElement);
|
||||
if (c != null)
|
||||
circuits.Add (c);
|
||||
}
|
||||
|
||||
foreach (var xs in root["Sequenceurs"].ChildNodes) {
|
||||
Sequenceur s = Sequenceur.Load (this,xs as XmlElement);
|
||||
if(s!=null)sequenceurs.Add (s);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -256,8 +312,30 @@ namespace DMX2
|
|||
set {
|
||||
_curval = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void Save (XmlElement parent)
|
||||
{
|
||||
XmlElement el= parent.OwnerDocument.CreateElement ("Circuit");
|
||||
parent.AppendChild(el);
|
||||
el.SetAttribute("ID",id.ToString());
|
||||
el.SetAttribute("name",name);
|
||||
el.SetAttribute("shortName",shortName);
|
||||
}
|
||||
|
||||
public static Circuit Load (XmlElement xc)
|
||||
{
|
||||
if(xc.Name!="Circuit") throw new ErreurLectureFichier("<Circuit> attendu.");
|
||||
return new Circuit(xc);
|
||||
}
|
||||
|
||||
private Circuit(XmlElement xc)
|
||||
{
|
||||
id = int.Parse(xc.GetAttribute("ID"));
|
||||
maxid = Math.Max (maxid,id+1);
|
||||
name = xc.GetAttribute("name");
|
||||
shortName = xc.GetAttribute("shortName");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -107,6 +107,7 @@
|
|||
<Compile Include="DriverDMX.cs" />
|
||||
<Compile Include="DriverBoitierV1.cs" />
|
||||
<Compile Include="SequenceurMaitre.cs" />
|
||||
<Compile Include="ErreurLectureFichier.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ProjectExtensions>
|
||||
|
|
|
|||
|
|
@ -304,9 +304,5 @@ namespace DMX2
|
|||
MajListeDimmer ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,8 +139,8 @@ namespace DMX2
|
|||
void RenderMatriceDuree (TreeViewColumn tree_column, CellRenderer cell, TreeModel tree_model, TreeIter iter)
|
||||
{
|
||||
SequenceurMaitre.Ligne l = tree_model.GetValue (iter, 0) as SequenceurMaitre.Ligne;
|
||||
if (l.Duree==-1) (cell as Gtk.CellRendererText).Text = string.Empty;
|
||||
else (cell as Gtk.CellRendererText).Text = l.Duree.ToString();
|
||||
if (l.Duree== TimeSpan.Zero) (cell as Gtk.CellRendererText).Text = string.Empty;
|
||||
else (cell as Gtk.CellRendererText).Text = (l.Duree.TotalMilliseconds /100).ToString();
|
||||
}
|
||||
|
||||
void RenderMatriceSeqVal (TreeViewColumn tree_column, CellRenderer cell, TreeModel tree_model, TreeIter iter)
|
||||
|
|
@ -172,11 +172,11 @@ namespace DMX2
|
|||
lsMatrice.GetIter (out iter, new Gtk.TreePath (args.Path));
|
||||
SequenceurMaitre.Ligne l = lsMatrice.GetValue (iter, 0) as SequenceurMaitre.Ligne;
|
||||
if (args.NewText.Length == 0)
|
||||
l.Duree = -1;
|
||||
l.Duree = TimeSpan.Zero;
|
||||
else {
|
||||
int val;
|
||||
if(int.TryParse(args.NewText, out val))
|
||||
l.Duree=val;
|
||||
l.Duree = TimeSpan.FromMilliseconds(val *100);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -355,36 +355,104 @@ namespace DMX2
|
|||
|
||||
void SaveFileAs ()
|
||||
{
|
||||
FileChooserDialog fcd = new FileChooserDialog("Sauver sous ...",this,FileChooserAction.Save,
|
||||
"Annuler",ResponseType.Cancel,
|
||||
"Ouvrir",ResponseType.Accept);
|
||||
FileChooserDialog fcd = new FileChooserDialog ("Sauver sous ...", this, FileChooserAction.Save,
|
||||
"Annuler", ResponseType.Cancel,
|
||||
"Enregistrer", ResponseType.Accept);
|
||||
|
||||
fcd.Filter = new FileFilter();
|
||||
fcd.Filter = new FileFilter ();
|
||||
|
||||
fcd.Filter.AddPattern("*.dmx2");
|
||||
fcd.Filter.AddPattern ("*.dmx2");
|
||||
|
||||
if ((ResponseType)fcd.Run() == ResponseType.Cancel)
|
||||
{
|
||||
fcd.Destroy();
|
||||
return;
|
||||
bool ok = false;
|
||||
|
||||
while (!ok) {
|
||||
|
||||
if ((ResponseType)fcd.Run () == ResponseType.Cancel) {
|
||||
fcd.Destroy ();
|
||||
return;
|
||||
}
|
||||
string file = fcd.Filename;
|
||||
|
||||
if (!file.EndsWith (".dmx2"))
|
||||
file += ".dmx2";
|
||||
|
||||
conduiteFile = new FileInfo(file);
|
||||
|
||||
if(conduiteFile.Exists)
|
||||
{
|
||||
MessageDialog msg = new MessageDialog(fcd,DialogFlags.Modal,
|
||||
MessageType.Warning,
|
||||
ButtonsType.YesNo,
|
||||
"Le fichier existe déja. \nVoulez vous écraser le fichier existant ?");
|
||||
if ((ResponseType)msg.Run () == ResponseType.Yes)ok=true;
|
||||
msg.Destroy();
|
||||
|
||||
}
|
||||
else ok=true;
|
||||
}
|
||||
string file = fcd.Filename;
|
||||
|
||||
if(!file.EndsWith(".dmx2"))
|
||||
file+=".dmx2";
|
||||
|
||||
conduiteFile = new FileInfo(fcd.Filename);
|
||||
if (conduiteFile.Exists);
|
||||
|
||||
|
||||
fcd.Destroy();
|
||||
|
||||
SaveFile();
|
||||
}
|
||||
|
||||
void SaveFile()
|
||||
void SaveFile ()
|
||||
{
|
||||
if(conduiteFile==null)return;
|
||||
if (conduiteFile == null)
|
||||
return;
|
||||
|
||||
using (FileStream stream = conduiteFile.Open(FileMode.Create,FileAccess.Write)) {
|
||||
System.Xml.XmlDocument doc = Conduite.Courante.Save ();
|
||||
doc.Save (stream);
|
||||
stream.Close ();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void OnOpenActionActivated (object sender, EventArgs e)
|
||||
{
|
||||
FileChooserDialog fcd = new FileChooserDialog ("Sauver sous ...", this, FileChooserAction.Open,
|
||||
"Annuler", ResponseType.Cancel,
|
||||
"Ouvrir", ResponseType.Accept);
|
||||
|
||||
fcd.Filter = new FileFilter ();
|
||||
fcd.Filter.AddPattern ("*.dmx2");
|
||||
if ((ResponseType)fcd.Run () == ResponseType.Cancel) {
|
||||
fcd.Destroy ();
|
||||
return;
|
||||
}
|
||||
|
||||
FileInfo openFile = new FileInfo (fcd.Filename);
|
||||
fcd.Destroy ();
|
||||
if (!openFile.Exists)
|
||||
return;
|
||||
|
||||
System.Xml.XmlDocument doc;
|
||||
|
||||
try {
|
||||
using(FileStream stream = openFile.OpenRead())
|
||||
{
|
||||
doc = new System.Xml.XmlDocument();
|
||||
doc.Load(stream);
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
Conduite cond = Conduite.Load(doc);
|
||||
if (cond==null)
|
||||
{
|
||||
// TODO Message erreur au chargement
|
||||
return;
|
||||
}
|
||||
|
||||
Conduite.Courante = cond;
|
||||
|
||||
conduiteFile = openFile;
|
||||
|
||||
} catch (IOException) {
|
||||
}
|
||||
|
||||
MajWidgets();
|
||||
NextUpdateFull();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -74,6 +74,7 @@ namespace DMX2
|
|||
dureeCell.Edited += EditDuree;
|
||||
transCell.Edited += EditTrans;
|
||||
|
||||
UpdListeEffets();
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,10 @@ namespace DMX2
|
|||
get {
|
||||
return id;
|
||||
}
|
||||
protected set {
|
||||
id=value;
|
||||
idmax = Math.Max(id+1,idmax);
|
||||
}
|
||||
}
|
||||
|
||||
string name;
|
||||
|
|
@ -45,8 +49,12 @@ namespace DMX2
|
|||
|
||||
public abstract int ValeurCircuit(Circuit c);
|
||||
public abstract void Tick(TimeSpan time);
|
||||
public static Sequenceur Load(XmlElement el)
|
||||
public static Sequenceur Load (Conduite conduite, XmlElement el)
|
||||
{
|
||||
switch (el.Name) {
|
||||
case "SequenceurLineaire":
|
||||
return SequenceurLineaire.Load(conduite, el);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -54,7 +62,7 @@ namespace DMX2
|
|||
{
|
||||
}
|
||||
|
||||
public abstract XmlElement Save ();
|
||||
public abstract void Save (XmlElement parent);
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ namespace DMX2
|
|||
|
||||
string _nom;
|
||||
|
||||
|
||||
public Effet (string nom, Dictionary<Circuit,int> valeurs, TimeSpan duree, TimeSpan transition)
|
||||
{
|
||||
_nom = nom;
|
||||
|
|
@ -63,6 +64,37 @@ namespace DMX2
|
|||
_transition = value;
|
||||
}
|
||||
}
|
||||
public void Save (System.Xml.XmlElement parent)
|
||||
{
|
||||
System.Xml.XmlElement el = parent.OwnerDocument.CreateElement ("Effet");
|
||||
System.Xml.XmlElement xmlVal;
|
||||
parent.AppendChild (el);
|
||||
el.SetAttribute("nom",_nom);
|
||||
el.SetAttribute ("duree", _duree.TotalMilliseconds.ToString ());
|
||||
el.SetAttribute ("transition", _transition.TotalMilliseconds.ToString ());
|
||||
foreach (var valeur in _valeurs) {
|
||||
xmlVal = parent.OwnerDocument.CreateElement("Valeur");
|
||||
el.AppendChild(xmlVal);
|
||||
xmlVal.SetAttribute("circuit",valeur.Key.ID.ToString());
|
||||
xmlVal.SetAttribute("valeur",valeur.Value.ToString());
|
||||
}
|
||||
}
|
||||
public static Effet Load (Conduite conduite, System.Xml.XmlElement el)
|
||||
{
|
||||
Dictionary<Circuit, int> valeurs = new Dictionary<Circuit, int> ();
|
||||
foreach (var xv in el.GetElementsByTagName("Valeur")) {
|
||||
System.Xml.XmlElement xval = xv as System.Xml.XmlElement;
|
||||
valeurs.Add(
|
||||
conduite.GetCircuitByID(int.Parse(xval.GetAttribute("circuit"))),
|
||||
int.Parse(xval.GetAttribute("valeur"))
|
||||
);
|
||||
}
|
||||
return new Effet( el.GetAttribute("nom"),valeurs,
|
||||
TimeSpan.FromMilliseconds(Double.Parse(el.GetAttribute("duree"))),
|
||||
TimeSpan.FromMilliseconds(Double.Parse(el.GetAttribute("transition")))
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TimeSpan timeStamp = TimeSpan.Zero;
|
||||
|
|
@ -91,13 +123,6 @@ namespace DMX2
|
|||
effetcourrant = new Effet ("",valeurscourantes , TimeSpan.Zero, TimeSpan.Zero);
|
||||
}
|
||||
|
||||
public SequenceurLineaire (int id) :base (id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public TimeSpan TimeStamp {
|
||||
get {
|
||||
return timeStamp;
|
||||
|
|
@ -305,9 +330,25 @@ namespace DMX2
|
|||
return index +1;
|
||||
}
|
||||
|
||||
public override System.Xml.XmlElement Save ()
|
||||
public override void Save (System.Xml.XmlElement parent)
|
||||
{
|
||||
throw new System.NotImplementedException ();
|
||||
System.Xml.XmlElement el = parent.OwnerDocument.CreateElement ("SequenceurLineaire");
|
||||
System.Xml.XmlElement xmlC;
|
||||
|
||||
parent.AppendChild (el);
|
||||
el.SetAttribute ("id", ID.ToString ());
|
||||
el.SetAttribute ("name", Name);
|
||||
el.SetAttribute ("master", master.ToString ());
|
||||
|
||||
foreach (Circuit c in circuitsSeq) {
|
||||
el.AppendChild(xmlC = parent.OwnerDocument.CreateElement ("CircuitSeq"));
|
||||
xmlC.SetAttribute("id",c.ID.ToString());
|
||||
}
|
||||
|
||||
foreach (Effet ef in effets) {
|
||||
ef.Save(el);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -326,5 +367,29 @@ namespace DMX2
|
|||
{
|
||||
ui = null;
|
||||
}
|
||||
|
||||
public static SequenceurLineaire Load (Conduite conduite, System.Xml.XmlElement el)
|
||||
{
|
||||
SequenceurLineaire seq = new SequenceurLineaire();
|
||||
seq.LoadSeq(conduite,el);
|
||||
return seq;
|
||||
}
|
||||
|
||||
private void LoadSeq (Conduite conduite, System.Xml.XmlElement el)
|
||||
{
|
||||
ID = int.Parse (el.GetAttribute ("id"));
|
||||
Name = el.GetAttribute ("name");
|
||||
master = int.Parse (el.GetAttribute ("master"));
|
||||
|
||||
foreach (var xc in el.GetElementsByTagName("CircuitSeq")) {
|
||||
System.Xml.XmlElement xcir = xc as System.Xml.XmlElement;
|
||||
Circuit c = conduite.GetCircuitByID (int.Parse (xcir.GetAttribute ("id")));
|
||||
circuitsSeq.Add (c);
|
||||
AjouteCircuit (c);
|
||||
}
|
||||
|
||||
foreach (var xe in el.GetElementsByTagName("Effet"))
|
||||
effets.Add(Effet.Load(conduite,xe as System.Xml.XmlElement));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace DMX2
|
|||
public class Ligne {
|
||||
public Ligne(){}
|
||||
string nom;
|
||||
int duree = -1;
|
||||
TimeSpan duree = TimeSpan.Zero;
|
||||
Dictionary<Sequenceur,string> data = new Dictionary<Sequenceur, string>();
|
||||
|
||||
public string Nom {
|
||||
|
|
@ -21,7 +21,7 @@ namespace DMX2
|
|||
}
|
||||
}
|
||||
|
||||
public int Duree {
|
||||
public TimeSpan Duree {
|
||||
get {
|
||||
return duree;
|
||||
}
|
||||
|
|
@ -37,9 +37,28 @@ namespace DMX2
|
|||
return value;
|
||||
}
|
||||
set {
|
||||
data[index] = value;
|
||||
if(value.Length==0) if(data.ContainsKey(index))
|
||||
data.Remove(index);
|
||||
else
|
||||
data[index] = value;
|
||||
}
|
||||
}
|
||||
public void Save (XmlElement parent)
|
||||
{
|
||||
XmlElement el = parent.OwnerDocument.CreateElement ("Ligne");
|
||||
parent.AppendChild (el);
|
||||
|
||||
el.SetAttribute ("nom", nom);
|
||||
el.SetAttribute ("duree", duree.TotalMilliseconds.ToString ());
|
||||
|
||||
XmlElement xmlSeq;
|
||||
foreach (var val in data) {
|
||||
el.AppendChild(xmlSeq=parent.OwnerDocument.CreateElement ("data"));
|
||||
xmlSeq.SetAttribute("seq",val.Key.ID.ToString());
|
||||
xmlSeq.SetAttribute("val",val.Value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
List<Ligne> lignes = new List<Ligne>();
|
||||
|
|
@ -57,16 +76,20 @@ namespace DMX2
|
|||
lignes.Add(new Ligne());
|
||||
}
|
||||
|
||||
public XmlElement Save ()
|
||||
public void Save (XmlElement parent)
|
||||
{
|
||||
return null;
|
||||
XmlElement el = parent.OwnerDocument.CreateElement("SequenceurMaitre");
|
||||
parent.AppendChild(el);
|
||||
|
||||
foreach(Ligne l in lignes)
|
||||
l.Save(el);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static SequenceurMaitre Load (XmlElement doc)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,9 +84,26 @@ namespace DMX2
|
|||
}
|
||||
}
|
||||
|
||||
public XmlElement Save ()
|
||||
public void Save (XmlElement parent)
|
||||
{
|
||||
return null;
|
||||
XmlElement el = parent.OwnerDocument.CreateElement ("UniversDMX");
|
||||
parent.AppendChild (el);
|
||||
|
||||
el.SetAttribute ("nom", Nom);
|
||||
XmlElement xmlDim; int dim;
|
||||
for(dim=0; dim < _dimmers.Length; dim++)
|
||||
{
|
||||
if(_dimmers[dim].circuitAssocié!=null)
|
||||
{
|
||||
el.AppendChild(xmlDim = el.OwnerDocument.CreateElement("Dimmer"));
|
||||
xmlDim.SetAttribute("num",dim.ToString());
|
||||
xmlDim.SetAttribute("circuit",_dimmers[dim].circuitAssocié.ID.ToString());
|
||||
xmlDim.SetAttribute("ft",_dimmers[dim].fonctionTransfert.ToString());
|
||||
xmlDim.SetAttribute("param1",_dimmers[dim].param1.ToString() );
|
||||
xmlDim.SetAttribute("param2",_dimmers[dim].param2.ToString() );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static UniversDMX Load (XmlElement doc)
|
||||
|
|
|
|||
|
|
@ -375,6 +375,7 @@ namespace DMX2
|
|||
this.DefaultHeight = 709;
|
||||
this.Show ();
|
||||
this.DeleteEvent += new global::Gtk.DeleteEventHandler (this.OnDeleteEvent);
|
||||
this.openAction.Activated += new global::System.EventHandler (this.OnOpenActionActivated);
|
||||
this.saveAction.Activated += new global::System.EventHandler (this.OnSaveActionActivated);
|
||||
this.saveAsAction.Activated += new global::System.EventHandler (this.OnSaveAsActionActivated);
|
||||
this.quitAction.Activated += new global::System.EventHandler (this.OnQuitActionActivated);
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@
|
|||
<property name="Label" translatable="yes">_Ouvrir</property>
|
||||
<property name="ShortLabel" translatable="yes">_Ouvrir</property>
|
||||
<property name="StockId">gtk-open</property>
|
||||
<signal name="Activated" handler="OnOpenActionActivated" />
|
||||
</action>
|
||||
<action id="saveAction">
|
||||
<property name="Type">Action</property>
|
||||
|
|
|
|||
Loading…
Reference in a new issue