Self Drawing Object Oriented Shapes

B

BennyEz

I'm attempting to create an object based system where custom business
objects are inherited by a custom Shape object which implements a
custom shape interface exposing a Render method along with other
possible methods.

For example:

public interface ICustomShape
{
double Width { get;set; }
double Height { get;set; }
double StartX { get;set; }
double StartY { get;set; }
string Text { get;set; }

void PreRender(Visio.Window vsoWin);
void Render(Visio.Window vsoWin);
void PostRender(Visio.Window vsoWin);
}

--------------------

class Building
{
private string _Name;
private string _Address;
public List<Room> Rooms = new List<Room>();

public string Name
{
get
{
return _Name.ToString();
}
set
{
_Name = value.ToString();
}
}

public string Address
{
get
{
return _Address.ToString();
}
set
{
_Address = value.ToString();
}
}
}

----------------------------------------------------------------------------

class Room
{
private string _RoomCode;

public string RoomCode
{
get
{
return _RoomCode.ToString();
}
set
{
_RoomCode= value.ToString();
}
}
}

------------------------------------------------------------------------------

class BuildingShape : Building, ICustomShape
{
//Here you would implement the public properties Width, Height,
StartX, StartY, and Text.
//Here you would also implement the Render methods.
}

------------------------------------------------------------------------------

ok, I also have a Diagram interface which represents an overall visio
diagram.

public interface IDiagram
{
double Width { get;set; }
double Height { get;set; }

void PreRender(Visio.Window vsoWin);
void Render(Visio.Window vsoWin);
void PostRender(Visio.Window vsoWin);
}

-------------------------------------------------------------------------------

Next there is also a base Diagram class which implements the above
interface and lets you implement the render methods as you wish as
well as add new functionality.

So now we can have different types of diagrams. I could create a new
interface that passes in a Word Doc instead of a Visio.Window. This
allows you to reuse drawing and sizing function where possible and
still extend what you have.

The Diagram class I currently have has a public list you can add
shapes to. So you can create a bunch of building shapes and inside of
these place Room Shapes and then place all these room shapes into the
Shapes List:
public List<object> Shapes = new List<object>();

I then implement the Render method of the Diagram.cs like so:

public void Render(Microsoft.Office.Interop.Visio.Window
vsoWin)
{
Type FoundInterface;
Type shpType;
TestBed.Interfaces.ICustomShape shpObj;

foreach (object shp in this.Shapes)
{
shpType = shp.GetType();
FoundInterface = shpType.GetInterface("ICustomShape");

if (FoundInterface != null)
{
shpObj = (TestBed.Interfaces.ICustomShape)shp;
shpObj.Render(vsoWin);
}
}
}

-------------------------------------

So for each of the shapes you place in the list it will call the
shapes's render method regardless of what it's base type is. That
shape can then have a collection it iterates through and call the
render method of all of the shapes found in there.

With this you could create self drawing diagrams with much potential
for re-use. Let's say for example that we are not drawing to scale but
rather only making a building large enough to show the rooms, and each
room only large enough to list student names. That means we'd have to
figure out the number of rooms and the size of those rooms before we
could figure out the size of the building. I picture using the pre-
render methods to help out with that.

There are a lot of options. Problem is, I feel like there has to be
something like this out there. Even for all it's "possible" up-sides
it still feels very cubmbersome when trying to do certain things. Am I
re-creating the wheel here or does anyone see a better approach to
what I am trying to do?

Here is a real world example of what it is being used for:

We have business object that represent infrastructure, DataCenters,
Servers, Apps, Firewalls, Routers, Switches, etc. etc....

We want to plot these on a number of different diagrams. Say one is a
global map. We set the diagram to open the global map as a template.
Then set the X and Y of each DataCenter to Long and Lat however now
these data centers must Look at all the servers within, then within
each of these servers look at how many apps are running on that
server. You need room to list the apps and therefore the shape
representing the server will be as big as needed to list all the apps.
Add all those servers together with margins between them and this
represents the data center size. I also want flags being able to tell
the Datacenters to perhaps not draw the apps inside the servers. This
would reduce the size of the DataCenter because the servers would not
need room for the apps. So on and So on..

Any ideas would be appreciated. Thanks
 
M

Mark Nelson [MS]

This seems too abstract and complex to be useful. Typically customers
decide on several typical "views" and then generate each view on a separate
page in a Visio document. Thus you only need to drop a DataCenter shape on
a map without worrying about the contents of the DataCenter. Hyperlinks are
used to "drill down" to a detail page that displays the floorplan with
racks. Additional detail pages display the servers in an individual rack.

Dynamically arranging things is hard in any non-trivial case. If you want
to surface additional information in a given view, try an overlay like the
Data Graphics provided in Visio 2007 Professional.

--
Mark Nelson
Office Graphics - Visio
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top