Suspend Display component redraw and PropertyGrids update

Feb 2, 2013 at 11:33 AM
Hi,

Is there a way to suspend Display (or Diagram) component redraw and "Shape"/"Model" PropertyGrids update for the time when lots of shapes/models are loaded programmatically?

Just looking for a way to speed up the loading process...
Coordinator
Feb 4, 2013 at 8:01 AM
Load the diagram before assigning it to the Display and/or the PropertyController.
Keep in mind that the AdoNet repository uses deferred loading: The shapes are loaded when accessing them the first time or when loading them explicitly:
    // Load diagram object (without shapes) and its shapes
    Diagram diagram = project.Repository.GetDiagram("...");
    project.Repository.GetDiagramShapes(diagram);
    // Display the completely loaded diagram
    display.Diagram = diagram;
If this does not help, could you please provide me some code then?
Feb 4, 2013 at 10:13 AM
Edited Feb 4, 2013 at 10:26 AM
Thank you for the answer.
Unfortunately I cannot use this approach because I do not create my diagram with Repository.GetDiagram(). I create it with Display.CreateDiagram() and then add shapes one by one from my custom repository - so diagram is "connected" to Display immediately after it is created. What should I do in such case? should I "disconnect" it from Display temporarily and then "connect" back again? [UPDATE] Or I can create my diagram with DiagramSetController.CreateDiagram(), then (probably) insert it into Repository, load my shapes and then "connect" diagram to Display?
Coordinator
Feb 4, 2013 at 10:39 AM
Sure, you could store the created diagram in a local variable, set the display's diagram property to null and add all your shapes.
But this would be highly inefficient as the display does nothing but to ensure that everything is all right (required components are connected, project and repository are open, existing diagram is deleted), then it calls
    Diagram d = new Diagram(diagramName);
    Project.Repository.Insert(d);
    this.Diagram = d;
and updates the graphics.

So it would be the best solution for your host application to create the diagram, fill it, display the whole thing:
    // In your host application:
    Diagram d = new Diagram(diagramName);
    project.Repository.Insert(d);
    
    // Create shapes and add them to the diagram here:
    Shape s = this.CreateAShapeMethod();
    d.Shapes.Add(s, project.Repository.ObtainMaxZOrder());
    project.Repository.Insert(s, d);
    // ...

    // Now that the digram is filled, display it:
    display.Diagram = d;
Feb 4, 2013 at 11:00 AM
Thank you.
Don't know why but I thought that Diagram has no public constructor - that's why I got stuck with Repository.GetDiagram() and DiagramSetController.CreateDiagram() factory methods :)
Feb 5, 2013 at 9:32 AM
Is my correction of Your code valid? -
    // In your host application:
    Diagram d = new Diagram(diagramName);
    project.Repository.Insert(d);
    
    // Create shapes and add them to the diagram here:
    Shape s = this.CreateAShapeMethod();
    d.Shapes.Add(s, project.Repository.ObtainMaxZOrder());
    if (s.ModelObject != null)
        project.Repository.Insert(s.ModelObject);
    project.Repository.Insert(s, d);
    // ...

    // Now that the digram is filled, display it:
    display.Diagram = d;
i.e. if Shape has a Model - this Model should be also inserted into Repository. And this must be done before inserting the Shape itself (otherwise an exception happens).
Coordinator
Feb 5, 2013 at 11:48 AM
Edited Feb 5, 2013 at 11:49 AM
Looks good.
You are right: The model objects have to be inserted before the shapes - you could even insert them before creating the diagram if you want to.
Mar 7, 2013 at 9:28 AM
One more question:
Is it possible to suspend Diagram redraw when performing "batch" operations against shapes on a Diagram which is already displayed?
For example, I need to move several shapes simultaneously, and I want to refresh Diagram when all shapes are moved - not after each of them is moved.
Smth. similar to Control.SuspendLayout() / .ResumeLayout() methods would be nice to have.
Coordinator
Mar 7, 2013 at 9:34 AM
You can use the SuspendUpdate/ResumeUpdate methods of the IDiagramPresenter interface.
As these methods are explicit implementations, you have to call them through the IDiagramPresenter interface:
IDiagramPresenter diagramPresenter = (IDiagramPresenter)display;
diagramPresenter.SuspendUpdate();
// ...
diagramPresenter.ResumeUpdate();
Mar 7, 2013 at 9:52 AM
Thank You, I'll try it!