Profile Picture

How to replace the standar Computer image?

Posted By andres caceres 15 Years Ago
Author
Message
andres caceres
Posted 15 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: Forum Members
Last Active: 15 Years Ago
Posts: 3, Visits: 1

Hi Ivo,

My purpose is to replace the predefined shapes with ones of my own. Specifically I want to change the computer shape with a customized one.

I loaded the library in the InitDocument() method (attached file) using the code you posted and called the createinstance in a subclasses I create overriden method diagramTest.CreateComputer().

I'm having a strange behavior (shapes overlaped each other). For testing purposes I'm adding nodes manually in this way: nodes.Rows.Add(1, "Switch 1", "Hub", "On");

Please review the attached file.
Thank you so much,

Andres



Attachments
Source.cs (98 views, 17.00 KB)
Ivo Milanov
Posted 15 Years Ago
View Quick Profile
Forum Member

Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)

Group: Forum Members
Last Active: 2 Months Ago
Posts: 35, Visits: 15
Hi Andres,

I think I am not getting the complete picture of your problem. First lets clarify what a library and shape factory is. A shape factory simply creates predefined shapes. A library is a storage for drawing clippings (masters) each of which can contained one or more shapes. You can create a library from a shape factory, in the case of which each shape that the factory can produce is wrapped by a master. You can also create a library from the diagram designer - as I have explained in my previous mail.

If you override the CreateComputer method then you have created a shape factory that subclasses a network shapes factory. Do you create a library from your shape factory?

When creating a shape from a master to be inserted in a drawing, you need to call the CreateInstance method of the master. You cannot simply get the shape from the master and add it in a drawing, since this will mean that both the drawing and the library reference the same shape. Furthermore if you try to add the same shape once again, strange errors will occur since you will have a drawing with two shapes that are in fact referencing a single shape instance.

If you could post the code that you are working on - I will try to help you with it...

Best regards,
Ivo

andres caceres
Posted 15 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: Forum Members
Last Active: 15 Years Ago
Posts: 3, Visits: 1

Hi Ivo,

 

I'm overriding the CreateComputer() method and as a result I'm getting all the shapes overlaped no matters what location I specify. So, what's the best place to put the piece of code you posted? Is there anyway to let diagram shapes find their rigth position?.

If the CreateComputer() method it's the best place, the how do a reference to the NShape object required by that method. I'm doing it so: return (NShape)master.GetChildAt(0);

 

Thank you so much, I'm stuck on this issue.



Ivo Milanov
Posted 15 Years Ago
View Quick Profile
Forum Member

Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)

Group: Forum Members
Last Active: 2 Months Ago
Posts: 35, Visits: 15
Hi Andres,

You can use the diagram designer to make custom shapes libraries - for example you can drag and drop a predefined shape in the drawing and customize it. You can then click on the New Library toolbar button and drag and drop the shape that you have customized in the newly created library. When done making your custom library you can save it to a .xml file.

In ASP.NET the library that you have visually created can be loaded via the persistency manager:

NPersistencyManager manager = new NPersistencyManager();
NLibraryDocument library = manager.LoadLibraryFromFile("c:\\mylib.nlx");

Creating the shapes contained in the masters of this library is easy - first get the master by name (Note: the code assumes that you have named a master "My Master". To rename a master in the diagram designer - right click on a master and select properties - then modify the Name property):

NMaster master = library.GetChildByName("My Master") as NMaster;

Then create an instance of the master in the drawing document:

master.CreateInstance(drawingDocument, new NPointF(100, 100));

The point argument, specifies the center position of the content that the master will create in the drawing.

Hope this helps...

Best regards,
Ivo

andres caceres
explanationmark Posted 15 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: Forum Members
Last Active: 15 Years Ago
Posts: 3, Visits: 1

Hi there,

 

I need to change the standard Computer image created by the NSimpleNetworkShapesFactory.

As far as I know there are two methods, one is creating it by code:

  public class diagramTest : NSimpleNetworkShapesFactory
    {

        protected override NShape CreateComputer()
        {
            NCompositeShape shape = new NCompositeShape();

            GraphicsPath graphicsPath = new GraphicsPath();
            PointF[] points = new PointF[]
            {
                new PointF(0, 0),
                new PointF(0, 20),
                new PointF(20, 20),
                new PointF(20, 0),
            };

            graphicsPath.AddPolygon(points);

            shape.Primitives.AddChild(new NCustomPath(graphicsPath, PathType.ClosedFigure));
            shape.UpdateModelBounds();

            shape.Style.FillStyle = new NColorFillStyle(Color.AliceBlue);
            shape.Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(0, 0, 0x88));

            return shape;
        }      
    }

 

But that's insane. I also know it's possible to desing my own computer shapes by using the Nevron Diagram for DotNet. I used that editor to make a test shape and I saved it with a .NDB extension.

So, the question is: how do I use that file in my code?

 

My scenario is: an ASPX web app, a NDrawingview in a web form. I'm using it to paint a network diagram.

 

Thank you so much,

 

 

}





Similar Topics


Reading This Topic