public BlockPropertiesViewModel(Rhino.RhinoDoc doc, string fileName, InsertInstanceCommandOptions options) : base(doc) { // Create a new set of command arguments from the options passed to the constructor CommandArgs = new InsertInstanceCommandOptions(options); // Make sure the docId is set to the requested document CommandArgs.DocumentId = options.DocumentId; // Use the default layer style, gets set to None if the default update style is other than "Linked" CommandArgs.LayerStyle = InsertInstanceOptions.Defaults.LayerStyle; ExistingInstanceDefinitions = CommandArgs.InstanceDefintionsFromFileName(fileName); // Cook up the block name from the file name looking for existing matches in the process InstanceDefinition found; string block; CommandArgs.BlockNameFromFileName(fileName, ExistingInstanceDefinitions, out block, out found); if (null != found) CommandArgs.FromInstanceDefinition(found); else if (ExistingInstanceDefinitions.Length > 0) CommandArgs.FromInstanceDefinition(ExistingInstanceDefinitions[0]); // If the block name property is empty then cook up a new, unused name if (string.IsNullOrWhiteSpace(block) && null != CommandArgs.Document) block = CommandArgs.Document.InstanceDefinitions.GetUnusedInstanceDefinitionName(); blockName = block; CommandArgs.BlockId = Guid.Empty; CommandArgs.InsertSourceArchive = true; sourceArchive = fileName; CreatePreviewImage(); }
public void CopyFrom(InsertInstanceCommandOptions source) { DocumentId = source.DocumentId; InsertAs = source.InsertAs; PromptForInsertionPoint = source.PromptForInsertionPoint; InsertionPoint = source.InsertionPoint; PromptForScale = source.PromptForScale; UniformlyScale = source.UniformlyScale; Scale = source.Scale; PromptForRotationAngle = source.PromptForRotationAngle; RotationAngle = source.RotationAngle; NeedToDisplayOptionsForm = source.NeedToDisplayOptionsForm; CopyFrom((InsertInstanceOptions)source); }
/// <summary> /// Constructor /// </summary> /// <param name="doc">Document used to create the new point</param> public InsertCommandViewModel(RhinoDoc doc, InsertInstanceCommandOptions initialCommandOptions, bool droppingFileOnRhino) : base(doc) { _doc = doc; _droppingFileOnRhino = droppingFileOnRhino; CommandOptions = initialCommandOptions; CommandOptions.DocumentId = doc.DocumentId; promptInsertionPoint = CommandOptions.PromptForInsertionPoint; InsertionPoint = CommandOptions.InsertionPoint; promptScale = CommandOptions.PromptForScale; uniformlyScale = CommandOptions.UniformlyScale; Scale = CommandOptions.Scale; promptRotation = CommandOptions.PromptForRotationAngle; rotation = RhinoMath.ToDegrees(CommandOptions.RotationAngle); // // Initialize list of hidden instance definitions // // The combo box is disabled when DroppingFileOnRhino is true so hidden InstanceDefinition objects will // never get added so don't bother building the list if (!DroppingFileOnRhino) foreach (var idef in Document.InstanceDefinitions) if (IsHiddenIDef(idef)) HiddenIDefs.Add(new InsertInstanceOptions(idef, doc.DocumentId)); // // Initialize bock name combo box // // IncludeIDefInList checks this flag so set it before initializing the combo box if (DroppingFileOnRhino) { // TODO: //InsertCommandArgs item = new InsertCommandArgs(InsertCommandArgs); //item.DroppingFileOnRhino = true; //comboBoxName.Items.Add(item); //comboBoxName.SelectedIndex = 0; //buttonFile.Enabled = false; } else if (null != Document) { // Process the active documents InstanceDefinitions table and create a list of items to add var blocks = new List<InsertInstanceOptions>(); foreach (var idef in Document.InstanceDefinitions) if (IncludeIDefInList(idef)) blocks.Add(new InsertInstanceOptions(idef, Document.DocumentId)); // Sort the list blocks.Sort(InsertInstanceOptions.Compare); int foundBlockName = -1; // Copy the list to the view model observable collection for binding by WPF or XCode foreach (var block in blocks) { blockList.Add(block); if (block.BlockId == BlockId) blockListSelectedIndex = blockList.Count - 1; if (foundBlockName < 0 && string.IsNullOrWhiteSpace(BlockName) && null != Document) { if (block.BlockName.Equals(BlockName, StringComparison.OrdinalIgnoreCase)) foundBlockName = blockList.Count - 1; } } // TRR 21538: If no previous name exists, use the first active one on the list. if (blockListSelectedIndex < 0 && blockList.Count > 0) blockListSelectedIndex = Math.Max(0, foundBlockName); } #if ON_OS_WINDOWS // Register command callbacks for button click (command) events BrowseForFileButtonClickDelegate = new RhinoWindows.Input.DelegateCommand(WinBrowseForFileButtonClick, null); #endif }
InsertInstanceOptions ShowOptionsForm(string fileName, string description, string urlDescription, string url, bool hideThisForm) { // Inserting as a block so display the block options form var args = new InsertInstanceCommandOptions(CommandOptions); args.BlockDescription = description; args.UrlDescription = urlDescription; args.Url = url; var model = new BlockPropertiesViewModel(Document, fileName, args); model.sourceArchiveVisible = false; bool? dialogResult = null; #if ON_OS_WINDOWS model.Window = new Win.BlockPropertiesWindow(); model.Window.DataContext = model; model.Window.Owner = Window; // TODO: //if (hideThisForm) //{ // model.Window.ContentRendered += Window_ContentRendered; // model.Window.Closing += Window_Closed; // Window.Closing += Window_Closing; //} model.Window.ShowDialog(); //if (hideThisForm) //{ // model.Window.ContentRendered -= Window_ContentRendered; // model.Window.Closed -= Window_Closed; //} dialogResult = model.Window.DialogResult; #endif #if ON_OS_MAC // Create a NSWindow from a Nib file var window = RhinoMac.Window.FromNib("InsertFileOptionsWindow", model); // Associate the window with the View Model so that the // model's Okay and Cancel methods can close the window model.Window = window; // Display the window window.ShowModal(); // Success will be true if the window was closed by the // OK button otherwise it should be false. dialogResult = window.DialogResult; #endif if (dialogResult != true) return null; InsertInstanceOptions result = null; // This use to be connected to a Win Form but it is now connected to a // model view controller which gets modified by either a WPF Window or // a XCode Window if (model.CommandArgs.InsertSourceArchive && Guid.Empty == model.CommandArgs.BlockId) { // A brand new block is being created so add the new block to the list _blockList.Add(new InsertInstanceOptions(model.CommandArgs)); blockListSelectedIndex = (_blockList.Count - 1); result = SelectedBlock; } else { // Find existing item and make it match what was returned int i = IndexFromBlockId(model.CommandArgs.BlockId); if (i >= 0) { if (model.CommandArgs.InsertSourceArchive) { var item = _blockList[i]; if (null != item) { // Copy data from the new item to the existing combo box item, this will clear // the preview image item.CopyFrom(model.CommandArgs); } } // Set the combo box selection to the item being overridden blockListSelectedIndex = i; result = SelectedBlock; } } return result; }
public InsertInstanceCommandOptions(InsertInstanceCommandOptions source) { CopyFrom(source); }