/// <summary> /// Adds new model to this composition. /// </summary> /// <param name="omiFilename">Relative or absolute path to OMI file describing the model.</param> /// <param name="directory">Directory <c>omiFilename</c> is relative to, or <c>null</c> if <c>omiFilename</c> is absolute or relative to current directory.</param> /// <returns>Returns newly added model.</returns> /// <remarks>See <see cref="Utils.GetFileInfo">Utils.GetFileInfo</see> for more info about how /// specified file is searched.</remarks> public UIModel AddModel(string directory, string omiFilename) { UIModel newUiModel; if (omiFilename == TriggerModelID) { newUiModel = UIModel.NewTrigger(); } else { newUiModel = new UIModel(); newUiModel.ReadOMIFile(directory, omiFilename); } // check whether ModelID is unique and also calculate newUiModel's positon foreach (UIModel uiModel in _models) { if (newUiModel.ModelID == uiModel.ModelID) { throw (new Exception("Composition already contains model with ModelID \"" + newUiModel.ModelID + "\" ")); } if (newUiModel.Rect.X == uiModel.Rect.X && newUiModel.Rect.Y == uiModel.Rect.Y) { newUiModel.Rect.X = newUiModel.Rect.X + newUiModel.Rect.Width / 2; newUiModel.Rect.Y = newUiModel.Rect.Y + newUiModel.Rect.Height / 2; } } _models.Add(newUiModel); _shouldBeSaved = true; return(newUiModel); }
/// <summary> /// Adds new model to this composition. /// </summary> /// <param name="omiFilename">Relative or absolute path to OMI file describing the model.</param> /// <param name="directory">Directory <c>omiFilename</c> is relative to, or <c>null</c> if <c>omiFilename</c> is absolute or relative to current directory.</param> /// <returns>Returns newly added model.</returns> /// <remarks>See <see cref="Utils.GetFileInfo">Utils.GetFileInfo</see> for more info about how /// specified file is searched.</remarks> public UIModel AddModel(string directory, string omiFilename) { UIModel newUiModel; //UIModel temp = new UIModel(); //temp.ReadOMIFile(directory, omiFilename); //check to see if model component implements ITrigger //if (temp.LinkableComponent is ILinkableComponent) //{ //} //else if (omiFilename == TriggerModelID) { newUiModel = UIModel.NewTrigger(); newUiModel.Color = System.Drawing.Color.Salmon; newUiModel.Rect = new System.Drawing.Rectangle(100, 100, 100, 100); newUiModel.Shape = DotSpatial.Modeling.Forms.ModelShape.Triangle; } else { newUiModel = new UIModel(); newUiModel.Color = System.Drawing.Color.LightGreen; newUiModel.Shape = DotSpatial.Modeling.Forms.ModelShape.Ellipse; newUiModel.Rect = new System.Drawing.Rectangle(100, 100, 115, 75); newUiModel.ReadOMIFile(directory, omiFilename); } // check whether ModelID is unique and also calculate newUiModel's positon foreach (UIModel uiModel in _models) { if (newUiModel.ModelID == uiModel.ModelID) { throw (new Exception("Composition already contains model with ModelID \"" + newUiModel.ModelID + "\" ")); } if (newUiModel.Rect.X == uiModel.Rect.X && newUiModel.Rect.Y == uiModel.Rect.Y) { newUiModel.Rect.X = newUiModel.Rect.X + newUiModel.Rect.Width / 2; newUiModel.Rect.Y = newUiModel.Rect.Y + newUiModel.Rect.Height / 2; } } _models.Add(newUiModel); _shouldBeSaved = true; return(newUiModel); }