Ejemplo n.º 1
0
        // Registers entity types for styles, designs, projectData, templates and diagramControllers
        // with the cache.
        private void RegisterBaseLibraryTypes(bool create)
        {
            int version;

            // When creating a repository without a valid version, we use the last supported save version.
            if (create && repository.Version <= 0)
            {
                repository.Version = LastSupportedSaveVersion;
            }
            version = repository.Version;
            //
            repository.AddEntityType(new EntityType(CapStyle.EntityTypeName, EntityCategory.Style,
                                                    version, () => new CapStyle(), CapStyle.GetPropertyDefinitions(version)));
            repository.AddEntityType(new EntityType(CharacterStyle.EntityTypeName, EntityCategory.Style,
                                                    version, () => new CharacterStyle(), CharacterStyle.GetPropertyDefinitions(version)));
            repository.AddEntityType(new EntityType(ColorStyle.EntityTypeName, EntityCategory.Style,
                                                    version, () => new ColorStyle(), ColorStyle.GetPropertyDefinitions(version)));
            repository.AddEntityType(new EntityType(FillStyle.EntityTypeName, EntityCategory.Style,
                                                    version, () => new FillStyle(), FillStyle.GetPropertyDefinitions(version)));
            repository.AddEntityType(new EntityType(LineStyle.EntityTypeName, EntityCategory.Style,
                                                    version, () => new LineStyle(), LineStyle.GetPropertyDefinitions(version)));
            repository.AddEntityType(new EntityType(ParagraphStyle.EntityTypeName, EntityCategory.Style,
                                                    version, () => new ParagraphStyle(), ParagraphStyle.GetPropertyDefinitions(version)));
            repository.AddEntityType(new EntityType(Design.EntityTypeName, EntityCategory.Design,
                                                    version, () => new Design(), Design.GetPropertyDefinitions(version)));
            repository.AddEntityType(new EntityType(ProjectSettings.EntityTypeName, EntityCategory.ProjectSettings,
                                                    version, () => new ProjectSettings(), ProjectSettings.GetPropertyDefinitions(version)));
            repository.AddEntityType(new EntityType(Template.EntityTypeName, EntityCategory.Template,
                                                    version, () => new Template(), Template.GetPropertyDefinitions(version)));
            repository.AddEntityType(new EntityType(Diagram.EntityTypeName, EntityCategory.Diagram,
                                                    version, () => new Diagram(""), Diagram.GetPropertyDefinitions(version)));
            // Register ModelMapping types
            // Create mandatory Model type
            repository.AddEntityType(new EntityType(Model.EntityTypeName, EntityCategory.Model,
                                                    version, () => new Model(), Model.GetPropertyDefinitions(version)));
            // Register mandatory ModelMapping types
            repository.AddEntityType(new EntityType(NumericModelMapping.EntityTypeName, EntityCategory.ModelMapping,
                                                    version, () => new NumericModelMapping(), NumericModelMapping.GetPropertyDefinitions(version)));
            repository.AddEntityType(new EntityType(FormatModelMapping.EntityTypeName, EntityCategory.ModelMapping,
                                                    version, () => new FormatModelMapping(), FormatModelMapping.GetPropertyDefinitions(version)));
            repository.AddEntityType(new EntityType(StyleModelMapping.EntityTypeName, EntityCategory.ModelMapping,
                                                    version, () => new StyleModelMapping(), StyleModelMapping.GetPropertyDefinitions(version)));

            //
            // Create the mandatory shape types
            initializingLibrary = new Library(GetType().Assembly);
            ((IRegistrar)this).RegisterLibrary("Core", LastSupportedSaveVersion);
            ShapeType groupShapeType = new ShapeType(
                "ShapeGroup", "Core", "Core", ShapeGroup.CreateInstance, ShapeGroup.GetPropertyDefinitions, false);

            ((IRegistrar)this).RegisterShapeType(groupShapeType);
            // Create mandatory model object types
            ModelObjectType genericModelObjectType = new GenericModelObjectType(
                "GenericModelObject", "Core", "Core", GenericModelObject.CreateInstance, GenericModelObject.GetPropertyDefinitions, 4);

            ((IRegistrar)this).RegisterModelObjectType(genericModelObjectType);
            initializingLibrary = null;
            //
            // Register static model entity types
            foreach (ModelObjectType mot in modelObjectTypes)
            {
                RegisterModelObjectEntityType(mot, create);
            }
            // Register static shape entity types
            foreach (ShapeType st in shapeTypes)
            {
                RegisterShapeEntityType(st, create);
            }
        }
Ejemplo n.º 2
0
        public static void CreateDiagram(Project project, string diagramName, int shapesPerRow, int shapesPerColumn, bool connectShapes, bool withModels, bool withTerminalMappings, bool withModelMappings, bool withLayers)
        {
            const int shapeSize  = 80;
            int       lineLength = shapeSize / 2;
            //
            // Create ModelMappings
            NumericModelMapping numericModelMapping = null;
            FormatModelMapping  formatModelMapping  = null;
            StyleModelMapping   styleModelMapping   = null;

            if (withModelMappings)
            {
                // Create numeric- and format model mappings
                numericModelMapping = new NumericModelMapping(2, 4, NumericModelMapping.MappingType.FloatInteger, 10, 0);
                formatModelMapping  = new FormatModelMapping(4, 2, FormatModelMapping.MappingType.StringString, "{0}");
                // Create style model mapping
                float range = (shapesPerRow * shapesPerColumn) / 15f;
                styleModelMapping = new StyleModelMapping(1, 4, StyleModelMapping.MappingType.FloatStyle);
                for (int i = 0; i < 15; ++i)
                {
                    IStyle style = null;
                    switch (i)
                    {
                    case 0: style = project.Design.LineStyles.None; break;

                    case 1: style = project.Design.LineStyles.Dotted; break;

                    case 2: style = project.Design.LineStyles.Dashed; break;

                    case 3: style = project.Design.LineStyles.Special1; break;

                    case 4: style = project.Design.LineStyles.Special2; break;

                    case 5: style = project.Design.LineStyles.Normal; break;

                    case 6: style = project.Design.LineStyles.Blue; break;

                    case 7: style = project.Design.LineStyles.Green; break;

                    case 8: style = project.Design.LineStyles.Yellow; break;

                    case 9: style = project.Design.LineStyles.Red; break;

                    case 10: style = project.Design.LineStyles.HighlightDotted; break;

                    case 11: style = project.Design.LineStyles.HighlightDashed; break;

                    case 12: style = project.Design.LineStyles.Highlight; break;

                    case 13: style = project.Design.LineStyles.HighlightThick; break;

                    case 14: style = project.Design.LineStyles.Thick; break;

                    default: style = null; break;
                    }
                    if (style != null)
                    {
                        styleModelMapping.AddValueRange(i * range, style);
                    }
                }
            }
            //
            // Create model obejct for the planar shape's template
            IModelObject planarModel = null;

            if (withModels)
            {
                planarModel = project.ModelObjectTypes["Core.GenericModelObject"].CreateInstance();
            }
            //
            // Create a shape for the planar shape's template
            Circle circleShape = (Circle)project.ShapeTypes["Circle"].CreateInstance();

            circleShape.Diameter = shapeSize;
            //
            // Create a template for the planar shapes
            Template planarTemplate = new Template("PlanarShape Template", circleShape);

            if (withModels)
            {
                planarTemplate.Shape.ModelObject = planarModel;
                planarTemplate.MapTerminal(TerminalId.Generic, ControlPointId.Reference);
                if (withTerminalMappings)
                {
                    foreach (ControlPointId id in planarTemplate.Shape.GetControlPointIds(ControlPointCapabilities.Connect))
                    {
                        planarTemplate.MapTerminal(TerminalId.Generic, id);
                    }
                }
                if (withModelMappings)
                {
                    planarTemplate.MapProperties(numericModelMapping);
                    planarTemplate.MapProperties(formatModelMapping);
                    planarTemplate.MapProperties(styleModelMapping);
                }
            }
            //
            // Create a template for the linear shapes
            Template linearTemplate = null;

            if (connectShapes)
            {
                linearTemplate = new Template("LinearShape Template", project.ShapeTypes["Polyline"].CreateInstance());
            }
            //
            // Insert the created templates into the repository
            project.Repository.InsertAll(planarTemplate);
            if (connectShapes)
            {
                project.Repository.InsertAll(linearTemplate);
            }
            //
            // Prepare the connection points
            ControlPointId leftPoint   = withModels ? ControlPointId.Reference : 4;
            ControlPointId rightPoint  = withModels ? ControlPointId.Reference : 5;
            ControlPointId topPoint    = withModels ? ControlPointId.Reference : 2;
            ControlPointId bottomPoint = withModels ? ControlPointId.Reference : 7;
            //
            // Create the diagram
            Diagram diagram = new Diagram(diagramName);
            //
            // Create and add layers
            LayerIds planarLayer = LayerIds.None, linearLayer = LayerIds.None, oddRowLayer = LayerIds.None,
                     evenRowLayer = LayerIds.None, oddColLayer = LayerIds.None, evenColLayer = LayerIds.None;

            if (withLayers)
            {
                const string planarLayerName   = "PlanarShapesLayer";
                const string linearLayerName   = "LinearShapesLayer";
                const string oddRowsLayerName  = "OddRowsLayer";
                const string evenRowsLayerName = "EvenRowsLayer";
                const string oddColsLayerName  = "OddColsLayer";
                const string evenColsLayerName = "EvenColsLayer";
                // Create Layers
                Layer planarShapesLayer = new Layer(planarLayerName);
                planarShapesLayer.Title = "Planar Shapes";
                planarShapesLayer.LowerZoomThreshold = 5;
                planarShapesLayer.UpperZoomThreshold = 750;
                diagram.Layers.Add(planarShapesLayer);
                Layer linearShapesLayer = new Layer(linearLayerName);
                linearShapesLayer.Title = "Linear Shapes";
                linearShapesLayer.LowerZoomThreshold = 10;
                linearShapesLayer.UpperZoomThreshold = 500;
                diagram.Layers.Add(linearShapesLayer);
                Layer oddRowsLayer = new Layer(oddRowsLayerName);
                oddRowsLayer.Title = "Odd Rows";
                oddRowsLayer.LowerZoomThreshold = 2;
                oddRowsLayer.UpperZoomThreshold = 1000;
                diagram.Layers.Add(oddRowsLayer);
                Layer evenRowsLayer = new Layer(evenRowsLayerName);
                evenRowsLayer.Title = "Even Rows";
                evenRowsLayer.LowerZoomThreshold = 2;
                evenRowsLayer.UpperZoomThreshold = 1000;
                diagram.Layers.Add(evenRowsLayer);
                Layer oddColsLayer = new Layer(oddColsLayerName);
                oddColsLayer.Title = "Odd Columns";
                oddColsLayer.LowerZoomThreshold = 2;
                oddColsLayer.UpperZoomThreshold = 1000;
                diagram.Layers.Add(oddColsLayer);
                Layer evenColsLayer = new Layer(evenColsLayerName);
                evenColsLayer.Title = "Even Columns";
                evenColsLayer.LowerZoomThreshold = 2;
                evenColsLayer.UpperZoomThreshold = 1000;
                diagram.Layers.Add(evenColsLayer);
                // Assign LayerIds
                planarLayer  = diagram.Layers.FindLayer(planarLayerName).Id;
                linearLayer  = diagram.Layers.FindLayer(linearLayerName).Id;
                oddRowLayer  = diagram.Layers.FindLayer(oddRowsLayerName).Id;
                evenRowLayer = diagram.Layers.FindLayer(evenRowsLayerName).Id;
                oddColLayer  = diagram.Layers.FindLayer(oddColsLayerName).Id;
                evenColLayer = diagram.Layers.FindLayer(evenColsLayerName).Id;
            }

            for (int rowIdx = 0; rowIdx < shapesPerRow; ++rowIdx)
            {
                LayerIds rowLayer = ((rowIdx + 1) % 2 == 0) ? evenRowLayer : oddRowLayer;
                for (int colIdx = 0; colIdx < shapesPerRow; ++colIdx)
                {
                    LayerIds colLayer  = ((colIdx + 1) % 2 == 0) ? evenColLayer : oddColLayer;
                    int      shapePosX = shapeSize + colIdx * (lineLength + shapeSize);
                    int      shapePosY = shapeSize + rowIdx * (lineLength + shapeSize);

                    circleShape      = (Circle)planarTemplate.CreateShape();
                    circleShape.Text = string.Format("{0} / {1}", rowIdx + 1, colIdx + 1);
                    circleShape.MoveTo(shapePosX, shapePosY);
                    if (withModels)
                    {
                        project.Repository.Insert(circleShape.ModelObject);
                        ((GenericModelObject)circleShape.ModelObject).IntegerValue = rowIdx;
                    }

                    diagram.Shapes.Add(circleShape, project.Repository.ObtainNewTopZOrder(diagram));
                    if (withLayers)
                    {
                        diagram.AddShapeToLayers(circleShape, planarLayer | rowLayer | colLayer);
                    }
                    if (connectShapes)
                    {
                        if (rowIdx > 0)
                        {
                            Shape lineShape = linearTemplate.CreateShape();
                            lineShape.Connect(ControlPointId.FirstVertex, circleShape, topPoint);
                            Assert.AreNotEqual(ControlPointId.None, lineShape.IsConnected(ControlPointId.FirstVertex, circleShape));

                            Shape otherShape = diagram.Shapes.FindShape(shapePosX, shapePosY - shapeSize, ControlPointCapabilities.None, 0, null);
                            lineShape.Connect(ControlPointId.LastVertex, otherShape, bottomPoint);
                            diagram.Shapes.Add(lineShape, project.Repository.ObtainNewBottomZOrder(diagram));
                            if (withLayers)
                            {
                                diagram.AddShapeToLayers(lineShape, linearLayer);
                            }
                            Assert.AreNotEqual(ControlPointId.None, lineShape.IsConnected(ControlPointId.LastVertex, otherShape));
                        }
                        if (colIdx > 0)
                        {
                            Shape lineShape = linearTemplate.CreateShape();
                            lineShape.Connect(1, circleShape, leftPoint);
                            Assert.AreNotEqual(ControlPointId.None, lineShape.IsConnected(ControlPointId.FirstVertex, circleShape));

                            Shape otherShape = diagram.Shapes.FindShape(shapePosX - shapeSize, shapePosY, ControlPointCapabilities.None, 0, null);
                            lineShape.Connect(2, otherShape, rightPoint);
                            diagram.Shapes.Add(lineShape, project.Repository.ObtainNewBottomZOrder(diagram));
                            if (withLayers)
                            {
                                diagram.AddShapeToLayers(lineShape, linearLayer);
                            }
                            Assert.AreNotEqual(ControlPointId.None, lineShape.IsConnected(ControlPointId.LastVertex, otherShape));
                        }
                    }
                }
            }
            diagram.Width  = (lineLength + shapeSize) * shapesPerRow + 2 * shapeSize;
            diagram.Height = (lineLength + shapeSize) * shapesPerColumn + 2 * shapeSize;
            project.Repository.InsertAll(diagram);
        }
Ejemplo n.º 3
0
        private static void CreateTemplatesFromShapeTypes(Project project, IList <String> shapeTypeNames, Int32 shapeSize, Boolean withModels, Boolean withTerminalMappings, Boolean withModelMappings, Int32 expectedShapeCount)
        {
            if (shapeTypeNames == null)
            {
                shapeTypeNames = new List <String>();
                shapeTypeNames.Add("Circle");
                shapeTypeNames.Add("PolyLine");
            }
            //
            foreach (String shapeTypeName in shapeTypeNames)
            {
                ShapeType shapeType = project.ShapeTypes[shapeTypeName];
                // Create a shape for the template
                Shape shape = shapeType.CreateInstance();
                shape.Fit(0, 0, shapeSize, shapeSize);
                // Create the template
                Template template = new Template(String.Format("{0} Template", shapeType.Name), shapeType.CreateInstance());
                if (shape is IPlanarShape)
                {
                    // Add optional data
                    if (withModels)
                    {
                        template.Shape.ModelObject = project.ModelObjectTypes["Core.GenericModelObject"].CreateInstance();
                        template.MapTerminal(TerminalId.Generic, ControlPointId.Reference);
                        if (withTerminalMappings)
                        {
                            foreach (ControlPointId id in template.Shape.GetControlPointIds(ControlPointCapabilities.Connect))
                            {
                                template.MapTerminal(TerminalId.Generic, id);
                            }
                        }
                        if (withModelMappings)
                        {
                            //
                            // Create ModelMappings
                            List <IModelMapping> modelMappings = new List <IModelMapping>(3);
                            // Create numeric- and format model mappings
                            NumericModelMapping numericMapping = new NumericModelMapping(2, 4, NumericModelMapping.MappingType.FloatInteger, 10, 0);
                            FormatModelMapping  formatMapping  = new FormatModelMapping(4, 2, FormatModelMapping.MappingType.StringString, "{0}");
                            // Create style model mapping
                            float             range             = expectedShapeCount / 15f;
                            StyleModelMapping styleModelMapping = new StyleModelMapping(1, 4, StyleModelMapping.MappingType.FloatStyle);
                            for (int i = 0; i < 15; ++i)
                            {
                                IStyle style = null;
                                switch (i)
                                {
                                case 0: style = project.Design.LineStyles.None; break;

                                case 1: style = project.Design.LineStyles.Dotted; break;

                                case 2: style = project.Design.LineStyles.Dashed; break;

                                case 3: style = project.Design.LineStyles.Special1; break;

                                case 4: style = project.Design.LineStyles.Special2; break;

                                case 5: style = project.Design.LineStyles.Normal; break;

                                case 6: style = project.Design.LineStyles.Blue; break;

                                case 7: style = project.Design.LineStyles.Green; break;

                                case 8: style = project.Design.LineStyles.Yellow; break;

                                case 9: style = project.Design.LineStyles.Red; break;

                                case 10: style = project.Design.LineStyles.HighlightDotted; break;

                                case 11: style = project.Design.LineStyles.HighlightDashed; break;

                                case 12: style = project.Design.LineStyles.Highlight; break;

                                case 13: style = project.Design.LineStyles.HighlightThick; break;

                                case 14: style = project.Design.LineStyles.Thick; break;

                                default: style = null; break;
                                }
                                if (style != null)
                                {
                                    styleModelMapping.AddValueRange(i * range, style);
                                }
                            }
                            modelMappings.Add(styleModelMapping);
                            //
                            foreach (IModelMapping modelMapping in modelMappings)
                            {
                                template.MapProperties(modelMapping);
                            }
                        }
                    }
                }
                else if (shape is ILinearShape)
                {
                    // Nothing else to do
                }
                else
                {
                    throw new NotImplementedException();
                }
                // Insert the template into the repository
                project.Repository.InsertAll(template);
            }
            Assert.AreEqual(EnumerationHelper.Count(project.Repository.GetTemplates()), shapeTypeNames.Count);
        }
Ejemplo n.º 4
0
 public static void Compare(FormatModelMapping savedMapping, FormatModelMapping loadedMapping, int version)
 {
     Assert.AreEqual <FormatModelMapping.MappingType>(savedMapping.Type, loadedMapping.Type);
     Assert.AreEqual <string>(savedMapping.Format, loadedMapping.Format);
 }
Ejemplo n.º 5
0
 public static void Compare(FormatModelMapping mappingA, FormatModelMapping mappingB, int version)
 {
     Assert.AreEqual <FormatModelMapping.MappingType>(mappingA.Type, mappingB.Type);
     Assert.AreEqual <string>(mappingA.Format, mappingB.Format);
 }