|
Hi.
I have a number of different sounds associated with defferent objects.
e.g.
ECGMachine objeect - beep1.wab, beep2.wav
Patient - breathNormal.wav, breathFast.wav, shout.wav
etc
Should I add the file path and relevent code of the sounds in each class, or create a soundPlay object?
If I do create a seperate object to play all sounds, what is the best way for all my objects to interact with it?
Thank you
Steve
|
|
|
|
|
I guess the classes you created that work together (with the possible exception of the application itself) are going to end up in one separate namespace and DLL file? If so, the sounds they use should all be resources, embedded in that same DLL (unless they logically belong to your app, and not those classes).
|
|
|
|
|
Thank you again, Luc.
Regards,
Steve
|
|
|
|
|
I've read this article Nested Set Model Treebuilder[^] and run into an issue. I can't figure out how to use proposed Nested Set algorythm to process not only a binary tree? How can I extend the current implementation to support building a tree with any structure?
|
|
|
|
|
I'd start by thoroughly understanding the node numbering algorithms of the binary tree version (see Trees in SQL - nested set model
[^] as referenced in the Nested Set Model Treebuilder[^] article.
Then, I'd devise and test (on paper) an algorithm with 3, 10, 100, or whatever, nodes at each level. This is about understanding the data model: it is not about implementing anything in code.
Only when I thoroughly understood how to number nodes, and how to move, insert and remove nodes (and adjust the node numberings accordingly) would I start to design an implementation of classes that build a tree in my application.
Also, if you are thinking of having a variable number of child nodes on a node, the move/insert/remove logic may become exceedingly complex.
You may find that you can 'simply' replace the left and right delegates with a selector delegate - which must now be a Func<T, int, V> , where the int identifies the child node of interest. I think you'll also have to supply a comparator delegate to aid with sorting nodes - but sorting nodes may now have to account for 'sibling position' which is a concept new to the Nested Set Model as implemented in the article.
To reiterate - I strongly recommend studying the theory of the data models you're wanting to implement before attempting to write any code.
Have fun and let us know how it turns out!
Chris
|
|
|
|
|
Thanks for your reply! I'm not going to implement moving/insert, but could you please show an example of recursion through Nested Set for the multi-child case? I just need to convert Nested Set table flat structure to multi-dimensional array. Thanks in advance!
|
|
|
|
|
I'm sure I could show an example of how to do so, but: "Give a man a fish - feed him for a day. Teach a man to fish - feed him for life" ... so I'm not going to.
There is much more value for you in attempting to think about the problem than having us spoon feed you with the solution.
If you share with us the thoughts you've had about how to adapt the binary tree problem to an n-ary problem you'll get some useful feedback. If you just ask us to do your job for you, you're unlikely to get any support.
|
|
|
|
|
Hi all, I have a server/client application. Program Works fine but I think I miss one little point. I put down a basic example. The question is; If I put a second strReadLine to server code and nothing comes from client, it gives error. Because it tries to read. So what can I do to prevent this?
string string1FromClient = strReader.ReadLine();
strWriter.WriteLine("client sent: "+ string1FromClient);
strWriter.Flush();
string string2FromClient = strReader.ReadLine();
strWriter.WriteLine("message");
strWriter.Flush();
string stringFromServer = strReader.ReadLine();
strWriter.WriteLine("message");
strWriter.Flush();
|
|
|
|
|
teknolog123 wrote: So what can I do to prevent this?
Don't read when you're not expecting a message - you can't read something that's not there. The client could tell the server how many "readlines" it should do to get the complete message across. That way you're still flexible in the amount of lines that you want to send, and the server won't be reading anything that's not there.
You might want to research the "handshaking" principle.
I are Troll
|
|
|
|
|
Thank you very much Eddy for the answer and for the reference also.
|
|
|
|
|
You're welcome
|
|
|
|
|
Hi everyone, I am wondering if any can help me how add on interface for user
to add or set color on application. User wants to choose color for themself.
All I need to do is have the custom color blend table available.
thanks.
|
|
|
|
|
If you search the articles on this site for Color Picker I'm sure you'll find some. If you want to use the .NET color picker you can use a class like this:
public class ColorPicker
{
public event EventHandler ColorChanged;
private Color color;
public ColorPicker()
{
color = Control.DefaultBackColor;
}
public Color Color
{
get { return color; }
set
{
if (color != value)
{
color = value;
OnColorChanged(EventArgs.Empty);
}
}
}
protected virtual void OnColorChanged(EventArgs e)
{
EventHandler eh = ColorChanged;
if (eh != null)
eh(this, e);
}
}
... and drop a PropertyGrid onto your form so you can do something like this:
public partial class FormMain : Form
{
private ColorPicker colorPicker;
public FormMain()
{
InitializeComponent();
colorPicker = new ColorPicker();
colorPicker.ColorChanged += new EventHandler(colorPicker_ColorChanged);
propertyGrid.SelectedObject = colorPicker;
}
private void colorPicker_ColorChanged(object sender, EventArgs e)
{
BackColor = colorPicker.Color;
}
}
|
|
|
|
|
I work with Visual Studio 2008 and programming in C #. I want to debug my code, but debug mode (F5) does not work (light gray, not active). How can I enable debug mode? Sincerely, A.
|
|
|
|
|
Most likely, you do not have a project or solution loaded.
This can happen if you double click a .CS file - the editor window shows the source code of your program, but the environment doesn't know what EXE the source belongs to.
Use File | Open | Project/Solution... to open a project (.CSPROJ) or solution (.SLN) file. Then Debug | Start Debugging will be enabled.
|
|
|
|
|
Hello.
OK, So I have managed to create my own control, derived from a panal class.
This control is an ECG display, required to draw and update itsself.
I have overided the ondraw() and added a timer to triger every 500ms, and added the code to draw a standard ecg graph using standard draw functions.
Now, I add the control to my form and set its name.
BUT, how do I refer to the control in the code WITHIN the control.
For example, my ondraw code requires to get the width of itsself.
I tried replacing the original variables (this control was on a form) with "this" but it does not work...
I then tried the following...
panal ecg = new panal();
constructor_function(panal ecg)
{
display = ecg;
}
But that seems to have no effect either.
Obviosly I can refer to the control from within my form very easy with its member, but because I have derived the class, I need to refer to my control in a number of function within the class.
My Idea was to create an ECG display class to handle its own drawing, and will eventualy get and set a range of ECG graphs, I didnt want all this functionality in the GUI.
Also, this object is representing the actual ECG machine and will soon have other functions such as Reset(), SwitchOn() etc, to be trigered from the main form and other objects.
Thank you in advance for any help...
Steve
|
|
|
|
|
You don't have to refer to it. this does that.
This is going to get a bit complex without digrams, but here goes...
Within your control class (or any class) this refers to the specific instance of your control (ignore static classes for the moment - you will meet them another day.)
It's as if you have a car class.
You can define a Color field, and a StartEngine method.
Within your class you can say
Console.WriteLine(this.Color); or just
Console.WriteLine(Color); because the this is implied.
When you execute the method containing the code, you will print the color (Americanisms! hah!) of your car. Not my car, or his car, your car.
If your form code had
Car mine = new Car(Blue);
Car yours = new Car(Red);
Car his = new Car(Green);
mine.PrintColor(); You would expect (and get) "Blue" printed.
his.PrintColor(); would give you Green.
Within your class, you don't need to know which instance of a Car it is - this takes care of it for you.
Equally, you would expect
yours.StartEngine(); to only start the Red cars engine - and it would.
Does that make sense?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
OK yes I got it, and my code is working thank you.
One more thing.
Am I on the right track with my class structure.
form - my main form with controls including an ecg display, sats (oxygen, temp, pulse etc) display
engine - a simulation object that looks after everything, loads data from the form, and interacts with the following objects...
ECGDisplay the panal derived class to display an ecg, draw itsself, get ecg data, swithon, off etc
patient - the class to hold details about the patient and there current state (e.g is he conscience?)
form runs, and has a static member of the simulator class and calls its timer event to run the simulation.
the simulation object has members of all other objects to update the state of the patient, calculate stats, start the displays, update stuff etc!
Have I got this right or am I way off, it is confusing what objewct should pass what to what object, and what should communicate with what.
(Gosh! its even complecated to simply exaplin ha)
Thank you again
Steve
|
|
|
|
|
stephen.darling wrote: (Gosh! its even complecated to simply exaplin ha)
Ain't that the truth!
Without actually seeing it, from your description it sounds ok. Not sure you need the simulation object to be static, but if there is only ever going to one of it, then fine. If you ever need to expand this to two patients it could be a problem though.
Otherwise, looks OK to me
Good luck!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
I have a class,
public class Collection<T>
and I was wondering if there was a way to determine if the data type used implements an interface.
I have used this code.
if (typeof(T) == typeof(ICollectable))
variance = 1.2;
but it never gets into this if block, regardless if the class I use implements ICollectable.
Any ideas?
|
|
|
|
|
I've come up with this, which will work for now. I am unsure of it's efficency though, I assume it uses Reflection
if (typeof(T).GetInterface("ICollectable") != null)
|
|
|
|
|
Sure... When you call typeof(T) , it returns a Type object, which has plenty of useful methods like GetInterface(), FindInterface(), etc.
Just don't use IsSubclassOf(), as that won't work for interfaces.
|
|
|
|
|
Reflection is probably the best way to go, but here is another technique which may be faster, though is not as flexible (i.e., you must know in advance if the type is a class or a struct, and it requires the class have a default constructor):
public bool IsClassAnimal<T>()
where T:new()
{
T t = new T();
return t is IAnimal;
}
public bool IsStructAnimal<T>()
{
T t = default(T);
if (t == null)
{
throw new InvalidOperationException("The type was a class.");
}
else
{
return t is IAnimal;
}
}
Sample interface/struct/class:
public interface IAnimal
{
}
public class Dog : IAnimal
{
}
struct Cat : IAnimal
{
}
Sample usage:
if (IsClassAnimal<Dog>())
{
MessageBox.Show("A dog is an animal!");
}
if (IsStructAnimal<Cat>())
{
MessageBox.Show("A cat is an animal!");
}
You could simplify that by just passing an instance of the class/struct, but that doesn't seem like what you're after. Also, if your class/struct is large (e.g., with lots of member variables), this could be a very expensive operation; not to mention it could have some weird side-effects. But, hey, thought I'd throw the technique out there anyway in case somebody can make use of it.
|
|
|
|
|
What about :
T myObj;
if (myObj is ICollectable)
variance = 1.2;
?
|
|
|
|
|
Hi,
I am currently doing my school project , which is about robot fish.
So the robot fish is used to detect the temperature inside the water.
2 types of devices I am using :
- Access device : this is usb-based, to connect to the pc, and also measure the temperature around it
- end device : this will measure the temperature somewhere else and transmit the wireless data to access device.
Both devices has been downloaded with some programs inside.
I have successfully displayed the data to the pc, using the software called sensor monitor visualizer( texas instrument ).
The problem is that I have to display the data using C# code programming , instead of that software from texas.
So I may need to find out the code to access or display or read the data from the usb device, and display the data again to the pc using some circles or whatever.
The detail is in http://focus.ti.com/lit/ug/slau227e/slau227e.pdf , including the screenshot of the display.
Please help me if you have any idea about this, as I am very poor in programming languages.
Thank you all.
|
|
|
|
|