2 // Radegast Metaverse Client
3 // Copyright (c) 2009-2013, Radegast Development Team
4 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 // * Neither the name of the application "Radegast", nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 using System.Collections.Generic;
33 using System.Windows.Forms;
34 #if (COGBOT_LIBOMV || USE_STHREADS)
36 using Thread = ThreadPoolUtil.Thread;
37 using ThreadPool = ThreadPoolUtil.ThreadPool;
38 using Monitor = ThreadPoolUtil.Monitor;
40 using System.Threading;
46 public partial class AttachmentDetail : UserControl
48 private RadegastInstance instance;
49 private GridClient client { get { return instance.Client; } }
51 private Primitive attachment;
53 public AttachmentDetail(RadegastInstance instance, Avatar av, Primitive attachment)
55 InitializeComponent();
56 Disposed += new EventHandler(AttachmentDetail_Disposed);
58 this.instance = instance;
60 this.attachment = attachment;
62 if (!instance.advancedDebugging)
64 btnSave.Visible = false;
65 boxID.Visible = false;
66 lblAttachment.Visible = false;
70 client.Objects.ObjectProperties += new EventHandler<ObjectPropertiesEventArgs>(Objects_ObjectProperties);
73 void AttachmentDetail_Disposed(object sender, EventArgs e)
75 client.Objects.ObjectProperties -= new EventHandler<ObjectPropertiesEventArgs>(Objects_ObjectProperties);
78 private void AttachmentDetail_Load(object sender, EventArgs e)
80 boxID.Text = attachment.ID.ToString();
82 if (attachment.Properties == null)
84 client.Objects.SelectObject(client.Network.CurrentSim, attachment.LocalID);
92 private void UpdateControls()
96 Invoke(new MethodInvoker(UpdateControls));
100 lblAttachmentPoint.Text = attachment.PrimData.AttachmentPoint.ToString();
101 boxName.Text = attachment.Properties.Name;
103 if ((attachment.Flags & PrimFlags.Touch) == 0)
105 btnTouch.Visible = false;
108 List<Primitive> parts = client.Network.CurrentSim.ObjectsPrimitives.FindAll(
109 delegate(Primitive prim)
111 return (prim.LocalID == attachment.LocalID || prim.ParentID == attachment.LocalID);
115 lblPrimCount.Text = "Prims: " + parts.Count.ToString();
118 void Objects_ObjectProperties(object sender, ObjectPropertiesEventArgs e)
120 if (e.Properties.ObjectID == attachment.ID)
122 attachment.Properties = e.Properties;
127 private void btnTouch_Click(object sender, EventArgs e)
129 client.Self.Touch(attachment.LocalID);
132 private void btnSave_Click(object sender, EventArgs e)
134 WindowWrapper mainWindow = new WindowWrapper(frmMain.ActiveForm.Handle);
135 System.Windows.Forms.SaveFileDialog dlg = new SaveFileDialog();
136 dlg.AddExtension = true;
137 dlg.RestoreDirectory = true;
138 dlg.Title = "Save object as...";
139 dlg.Filter = "XML file (*.xml)|*.xml";
140 DialogResult res = dlg.ShowDialog();
142 if (res == DialogResult.OK)
144 Thread t = new Thread(new ThreadStart(delegate()
148 PrimSerializer s = new PrimSerializer(client);
149 string primsXmls = s.GetSerializedAttachmentPrims(client.Network.CurrentSim, attachment.LocalID);
150 System.IO.File.WriteAllText(dlg.FileName, primsXmls);
153 MessageBox.Show(mainWindow, "Successfully saved " + dlg.FileName, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
155 catch (Exception excp)
157 MessageBox.Show(mainWindow, excp.Message, "Saving failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
161 t.IsBackground = true;
167 private void button1_Click(object sender, EventArgs e)
169 Rendering.frmPrimWorkshop pw = new Rendering.frmPrimWorkshop(instance, attachment.LocalID);
171 pw.SetView(new Vector3(0f, 0.5f, 0f), 0, 0, 90, -10);