|
|||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionA graphic front end to manage network diagrams can be very useful for a lot of purposes like writing simulation software or simply to organize collected data (for example, by a network scanner). In this simple program, we will see a simple way to implement a graphic front end with these basic functions:
…without requiring any Office library, so you can use this even if you haven’t installed Visio or PowerPoint. General ImplementationThis software has a main library, i.e., GScenario.cs, that implements the memory representation of all the drawn objects. Formally, this is a class with a pointer to the current object ( public class GObject
public string Name;
public string Type;
public int x1;
public int y1;
public string Lnk1;
public int x2;
public int y2;
public string Lnk2;
The properties are: the (supposedly unique) name of the object (i.e., “Router_0”), its type (for each type, there is a different icon), the limits of the containing window, and the links. These parameters are only significant for a line object, and are useful to implement glue links, and tells what object is connected to each terminal point of the line. The icons of the object types are stored in an private Image FindGObjectTypeImage(string ObjType)
All the GDI functions are managed in the main form class while the corresponding information is assigned, modified, and so on by the Drag & Drop FunctionIt is easy to illustrate the drag and drop situation for the two different cases of a shape (rectangular object) and of a line. The first is simple because the second must implement even the “glue link” effect. To manage a drag and drop situation of a shape, we use these event of the main form object:
The Load & SaveThere’s not much to explain about this: simply use these methods of public bool LoadFile(string FileFullPath, ref string sErrFileMsg)
public bool SaveFile(string FileFullPath, ref string sErrFileMsg)
The object=Emitter_0;
type=Emitter;
x1=116;
y1=119;
lnk1=;
x2=196;
y2=199;
lnk2=;
end object.
object=Receiver_0;
type=Receiver;
x1=674;
y1=145;
lnk1=;
x2=754;
y2=225;
lnk2=;
end object.
…
We use the basic function of the [variable_name]=[variable_value];
Further ConsiderationsAn apposite simple function extracts from each “line string”, the (variable, value) couple (for example: x1=116; -> variable=x1; value=116) and saves it to memory or to disk. This example has been developed referring to a TCP network: so the managed objects are clients (TCP flow emitters), servers (receiver), and so on. However, it’s obvious that its validity is general, and can be used for all kinds of hierarchical dependence networks, for example, in logistics, production planning etc… (in this case, the nodes are warehouses). This program doesn’t do anything in terms of calculation on the objects; those contain only the graphics elements, and to be used in a specific contest must be contextualized, for example, adding in the If all goes (almost) good, and if the image area is much smaller than the rectangle area, and not centered … you have to implement a more efficient way to manage the objects, or you have to choose different images. History
|
||||||||||||||||||||||||||||||||||||||||||||