Пример #1
0
		public IModelObject Clone() {
			MyBusinessObject clone = new MyBusinessObject(this.modelObjectType);
			clone.MyBooleanProperty = this.MyBooleanProperty;
			clone.MyFloatProperty = this.MyFloatProperty;
			clone.MyIntegerProperty = this.MyIntegerProperty;
			return clone;
		}
Пример #2
0
        private void InitPropertyMappings(Template template, MyBusinessObject modelObj)
        {
            Debug.Assert(template != null && template.Shape != null && modelObj != null);

            // Assign model object to template shape
            template.Shape.ModelObject = modelObj;

            // Delete and clear all property mappings
            // (not really necessary in this case)
            project.Repository.Delete(template.GetPropertyMappings());
            template.UnmapAllProperties();

            // Prepare property mappings (One mapping per property!):
            //
            // Float to Style
            // Change color depending on the integer property
            StyleModelMapping lineStyleMapping = new StyleModelMapping(1, MyBusinessObject.FloatPropertyId, StyleModelMapping.MappingType.FloatStyle);

            lineStyleMapping.AddValueRange(float.MinValue, project.Design.LineStyles.None);
            lineStyleMapping.AddValueRange(16.66f, project.Design.LineStyles.Dotted);
            lineStyleMapping.AddValueRange(33.33f, project.Design.LineStyles.Special2);
            lineStyleMapping.AddValueRange(50.00f, project.Design.LineStyles.Special1);
            lineStyleMapping.AddValueRange(66.66f, project.Design.LineStyles.Dashed);
            lineStyleMapping.AddValueRange(83.33f, project.Design.LineStyles.Normal);
            template.MapProperties(lineStyleMapping);
            // Save mapping
            project.Repository.Insert(lineStyleMapping, template);
            //
            // Integer to Style
            // Change outline thickness depending on the boolean property
            StyleModelMapping fillStyleMapping = new StyleModelMapping(3, MyBusinessObject.BooleanPropertyId, StyleModelMapping.MappingType.IntegerStyle);

            fillStyleMapping.AddValueRange(0, project.Design.FillStyles.Green);
            fillStyleMapping.AddValueRange(1, project.Design.FillStyles.Red);
            template.MapProperties(fillStyleMapping);
            // Save mapping
            project.Repository.Insert(fillStyleMapping, template);
            //
            // Integer to Integer
            // Change shape's angle depending on the integer property
            // Note: Value is modified by a slope factor of 10 because angle is specified in tenths of degrees.
            NumericModelMapping angleMapping = new NumericModelMapping(2, MyBusinessObject.IntegerPropertyId, NumericModelMapping.MappingType.IntegerInteger, 0, 10);

            template.MapProperties(angleMapping);
            // Save mapping
            project.Repository.Insert(angleMapping, template);

            // Add model object and update template
            project.Repository.Insert(modelObj);
            project.Repository.Update(template);
        }
Пример #3
0
        public MainForm()
        {
            InitializeComponent();

            // Initialize project with a shape library
            project.AddLibrary(typeof(ThickArrow).Assembly, false);
            // Add this application as model object library
            project.AddLibrary(GetType().Assembly, false);

            project.Name = "Model Mapping Demo";
            project.Create();

            // Create an instance of the test object (that implements IModelObject)
            Template         template = project.Repository.GetTemplate("ThickArrow");
            MyBusinessObject model    = (MyBusinessObject)project.ModelObjectTypes["MyBusinessObjectType"].CreateInstance();

            InitPropertyMappings(template, model);

            // Create a diagram with a shape that is bound to a business object
            const string diagramName = "Demo Diagram";
            Diagram      diagram     = new Diagram(diagramName);

            // Create a shape from the prepared template
            ThickArrow shape = (ThickArrow)project.Repository.GetTemplate("ThickArrow").CreateShape();

            shape.MoveTo(diagram.Width / 2, diagram.Height / 2);
            shape.Width     = 120;
            shape.HeadWidth = 60;
            shape.Height    = 100;

            diagram.Shapes.Add(shape);
            project.Repository.Insert(shape.ModelObject);
            project.Repository.InsertAll(diagram);

            display1.LoadDiagram(diagramName);

            // Store model object to modify
            businessObj = shape.ModelObject as MyBusinessObject;
            // Update start values
            businessObj.MyBooleanProperty = checkBox.Checked;
            businessObj.MyIntegerProperty = (int)intTrackBar.Value;
            businessObj.MyFloatProperty   = (float)floatTrackBar.Value;
        }
Пример #4
0
        private void InitPropertyMappings(Template template, MyBusinessObject modelObj)
        {
            Debug.Assert(template != null && template.Shape != null && modelObj != null);

            // Assign model object to template shape
            template.Shape.ModelObject = modelObj;

            // Delete and clear all property mappings
            // (not really necessary in this case)
            project.Repository.Delete(template.GetPropertyMappings());
            template.UnmapAllProperties();

            // Prepare property mappings (One mapping per property!):
            //
            // Float to Style
            // Change color depending on the integer property
            StyleModelMapping lineStyleMapping = new StyleModelMapping(1, MyBusinessObject.FloatPropertyId, StyleModelMapping.MappingType.FloatStyle);
            lineStyleMapping.AddValueRange(float.MinValue, project.Design.LineStyles.None);
            lineStyleMapping.AddValueRange(16.66f, project.Design.LineStyles.Dotted);
            lineStyleMapping.AddValueRange(33.33f, project.Design.LineStyles.Special2);
            lineStyleMapping.AddValueRange(50.00f, project.Design.LineStyles.Special1);
            lineStyleMapping.AddValueRange(66.66f, project.Design.LineStyles.Dashed);
            lineStyleMapping.AddValueRange(83.33f, project.Design.LineStyles.Normal);
            template.MapProperties(lineStyleMapping);
            //
            // Integer to Style
            // Change outline thickness depending on the boolean property
            StyleModelMapping fillStyleMapping = new StyleModelMapping(3, MyBusinessObject.BooleanPropertyId, StyleModelMapping.MappingType.IntegerStyle);
            fillStyleMapping.AddValueRange(0, project.Design.FillStyles.Green);
            fillStyleMapping.AddValueRange(1, project.Design.FillStyles.Red);
            template.MapProperties(fillStyleMapping);
            //
            // Integer to Integer
            // Change shape's angle depending on the integer property
            // Note: Value is modified by a slope factor of 10 because angle is specified in tenths of degrees.
            NumericModelMapping angleMapping = new NumericModelMapping(2, MyBusinessObject.IntegerPropertyId, NumericModelMapping.MappingType.IntegerInteger, 0, 10);
            template.MapProperties(angleMapping);

            // Add model object and update template
            project.Repository.Insert(modelObj);
            project.Repository.Update(template);
        }
Пример #5
0
        public Form1()
        {
            InitializeComponent();

            // Initialize project with a shape library
            project.AddLibrary(typeof(ThickArrow).Assembly, false);
            // Add this application as model object library
            project.AddLibrary(GetType().Assembly, false);

            project.Name = "Model Mapping Demo";
            project.Create();

            // Create an instance of the test object (that implements IModelObject)
            Template template = project.Repository.GetTemplate("ThickArrow");
            MyBusinessObject model =  (MyBusinessObject)project.ModelObjectTypes["MyBusinessObjectType"].CreateInstance();
            InitPropertyMappings(template, model);

            // Create a diagram with a shape that is bound to a business object
            const string diagramName = "Demo Diagram";
            Diagram diagram = new Diagram(diagramName);

            // Create a shape from the prepared template
            ThickArrow shape = (ThickArrow)project.Repository.GetTemplate("ThickArrow").CreateShape();
            shape.MoveTo(diagram.Width / 2, diagram.Height / 2);
            shape.Width = 120;
            shape.HeadWidth = 60;
            shape.Height = 100;

            diagram.Shapes.Add(shape);
            project.Repository.Insert(shape.ModelObject);
            project.Repository.InsertAll(diagram);

            display1.LoadDiagram(diagramName);

            // Store model object to modify
            businessObj = shape.ModelObject as MyBusinessObject;
            // Update start values
            businessObj.MyBooleanProperty = checkBox.Checked;
            businessObj.MyIntegerProperty = (int)intTrackBar.Value;
            businessObj.MyFloatProperty = (float)floatTrackBar.Value;
        }
Пример #6
0
 public IModelObject Clone()
 {
     MyBusinessObject clone = new MyBusinessObject(this.modelObjectType);
     clone.MyBooleanProperty = this.MyBooleanProperty;
     clone.MyFloatProperty = this.MyFloatProperty;
     clone.MyIntegerProperty = this.MyIntegerProperty;
     return clone;
 }