This project has moved and is read-only. For the latest updates, please go here.

Can I create new shapes template like a group of shapes?

Apr 30, 2015 at 3:35 PM
Edited Apr 30, 2015 at 4:46 PM
Hi. and again thansk for the framewors.
My question is about the next problem. I need template with 2 o 3 text and 2 or 3 box.
Like this:
https://drive.google.com/file/d/0B2dAKGMSSJyFQXRsUDJST3pNalk/view?usp=sharing

Is it possible?
How can I do that?
Apr 30, 2015 at 3:55 PM
I use this code to add an custom box. Ok work.
 Template BoxPPal = null;
                foreach (Template template in project_NShape.Repository.GetTemplates())
                {
                    if (template.Name == "MyBox")
                    {
                        BoxPPal = template;
                        break;
                    }
                }

                if (BoxPPal == null)
                { Box boxPPal = (Box)project_NShape.ShapeTypes["Box"].CreateInstance();
                    boxPPal.LineStyle = project_NShape.Design.LineStyles.Normal;
                    boxPPal.Text = ActivityName;
                    boxPPal.Height = 100;
                    boxPPal.Width = 100;
                    boxPPal.FillStyle = project_NShape.Design.FillStyles.Transparent;
                    // ToDo: Customize shape's appearence
                    BoxPPal = new Template("BoxUC", boxPPal);
                    BoxPPal.Title = "BoxUC";                        // Used as tool's display name
                    //project_NShape.Repository.Insert(BoxPPal); 


                    PlanarShapeCreationTool boxUC = new PlanarShapeCreationTool(BoxPPal);
                    boxUC.Category = "My Shapes ☺ ";
                    boxUC.Description = "Creates a Box Use Case.";        // Used as ToolTip text
                    toolSetController_NShape.AddTool(boxUC);

                }
But when I try to add two box conected. I do this:
ShapeGroup shapeGroup = (ShapeGroup)project_NShape.ShapeTypes["2Box"].CreateInstance();
                    shapeGroup.Children.Add(BoxPAct.Shape);
                    shapeGroup.Children.Add(BoxUC.Shape);
And when I try to add this group to my category, I can't find the function for to do that.
                    PlanarShapeCreationTool shapeGroups = new PlanarShapeCreationTool(shapeGroup);
Thanks again for your time!!
May 4, 2015 at 3:33 PM
Edited May 4, 2015 at 3:34 PM
You cannot create tools from group shapes (by design).
But you can add child shapes to any other shape, e.g.
Box box = (Box)project_NShape.ShapeTypes["Box"].CreateInstance();
        // Do not add the shape of a template A to template B because 
        // this would mean that template B is dependent on template A. 
        // Clone the shapes in order to avoid dependencies between templates.
        box.Children.Add(BoxPAct.Shape.Clone());
        box.Children.Add(BoxUC.Shape.Clone());
May 4, 2015 at 5:20 PM
Edited May 4, 2015 at 5:22 PM
Hi Kurt.
Thanks for your reply!
It is similar to how I solved my initial question.
I did this code:
#region activity + UC

                // 1. Create the container shape which will host all child shapes
                RectangleBase containerShape =
                    (RectangleBase)project_NShape.ShapeTypes["Box"].CreateInstance();
                containerShape.Width = 136;
                containerShape.Height = 160; //136 + 24 
                containerShape.Tag = ctteUC;
                containerShape.FillStyle = project_NShape.Design.FillStyles.Transparent;
                System.Drawing.Rectangle containerBounds = containerShape.GetBoundingRectangle(true);
                int cnt = 2;
                for (int i = 0; i < cnt; ++i)
                {

                    if (i == 0)
                    {
                        Box childShapeActName = (Box)project_NShape.ShapeTypes["Box"].CreateInstance();
                        containerShape.Children.Add(childShapeActName);
                        // Calculate child shape size
                        childShapeActName.Width = 136;
                        childShapeActName.Height = 136;
                        childShapeActName.FillStyle = project_NShape.Design.FillStyles.White;
                        childShapeActName.Text = ctteActivityName;
                        // Calculate child shape position
                        childShapeActName.X = containerBounds.Left + 68;
                        childShapeActName.Y = containerBounds.Top + 68;
                    }
                    if (i == 1)
                    {
                        Box childShapeSI = (Box)project_NShape.ShapeTypes["Box"].CreateInstance();
                        containerShape.Children.Add(childShapeSI);
                        // Calculate child shape size
                        childShapeSI.Width = 136;
                        childShapeSI.Height = 24;
                        childShapeSI.FillStyle = project_NShape.Design.FillStyles.Yellow;
                        childShapeSI.Text = ctteUC;
                        // Calculate child shape position
                        childShapeSI.X = containerBounds.Left + 68;
                        childShapeSI.Y = containerBounds.Bottom - 12;
                    }
                }
                // 3.Create a template from the container shape
                Template compositeShapeTemplate =
                    new Template(string.Format("UC"), containerShape);
                // Insert the template into the repository
                project_NShape.Repository.InsertAll(compositeShapeTemplate);
                //
                // 4. Create a toolbox item
                toolSetController_NShape.CreateTemplateTool(compositeShapeTemplate);

                #endregion
thanks again.
greetings !!