private void DumpInstanceDefinition(InstanceDefinition instanceDefinition, ref TextLog dump, bool isRoot)
    {
      if (instanceDefinition != null && !instanceDefinition.IsDeleted)
      {
        string node = isRoot ? "─" : "└";
        dump.Print(string.Format("{0} Instance definition {1} = {2}\n", node, instanceDefinition.Index, instanceDefinition.Name));

        if (instanceDefinition.ObjectCount  > 0)
        {
          dump.PushIndent();
          for (int i = 0; i < instanceDefinition.ObjectCount ; i++)
          {
            var obj = instanceDefinition.Object(i);
            if (obj == null) continue;
            if (obj is InstanceObject)
              DumpInstanceDefinition((obj as InstanceObject).InstanceDefinition, ref dump, false); // Recursive...
            else
              dump.Print("\u2514 Object {0} = {1}\n", i, obj.ShortDescription(false));
          }
          dump.PopIndent();
        }
      }
    }
Пример #2
0
 public InsertedInstanceModel(InstanceDefinition definition)
 {
     Definition = definition;
     Insertion  = InstanceInsertionModel.Identity;
 }
Пример #3
0
        public Image GetPreview(InstanceDefinition definition, int width, int height)
        {
            var conduit = GetPreviewConduit(definition);

            return(GetPreviewHelper(conduit, width, height));
        }
Пример #4
0
        public Image GetNestedPreview(InstanceDefinition main, InstanceDefinition nested, int width, int height)
        {
            var conduit = GetNestedPreviewConduit(main, nested);

            return(GetPreviewHelper(conduit, width, height));
        }
 /// <summary>
 /// The InstanceDefinition is considered a "hidden" or "anonymous" InstanceDefinition if the name starts with '*'
 /// </summary>
 /// <param name="idef"></param>
 /// <returns>Returns true if the specified InstanceDefinition is non null and is a hidden InstanceDefinition</returns>
 bool IsHiddenIDef(InstanceDefinition idef)
 {
     // The only current check is if the first char is a '*' then the InstanceDefinition is considered
       // a hidden or anonymous InstanceDefinition
       // July 10, 2012 Tim/JohnM, Potential fix for RR 108618.  Check to make sure Name is good before using it too.
       return (null != idef && !string.IsNullOrEmpty(idef.Name) && idef.Name.StartsWith("*"));
 }
        /// <summary>
        /// Initialize this objects properties by evaluating the specified Rhino
        /// Instance Defintion.
        /// </summary>
        /// <param name="idef"></param>
        public void FromInstanceDefinition(InstanceDefinition idef)
        {
            try
              {
            if (null == idef)
            {
              BlockId = Guid.Empty;

              BlockName = string.Empty;
              BlockDescription = string.Empty;
              UrlDescription = string.Empty;
              Url = string.Empty;
              RhinoDoc doc = Document;
              if (null != doc)
            BlockName = doc.InstanceDefinitions.GetUnusedInstanceDefinitionName();
              SourceArchive = string.Empty;
              InsertSourceArchive = false;
            }
            else
            {
              // Id of block to insert
              BlockId = idef.Id;
              // Name of block to insert
              BlockName = idef.Name;
              // Block description
              BlockDescription = idef.Description;
              // URL display string
              UrlDescription = idef.UrlDescription;
              // URL
              Url = idef.Url;
              // Not linked to any external file
              SourceArchive = idef.UpdateType == InstanceDefinitionUpdateType.Linked || idef.UpdateType == InstanceDefinitionUpdateType.LinkedAndEmbedded ? idef.SourceArchive : string.Empty;
              // Synch the UpdateType with the InstanceDefnition
              UpdateType = idef.UpdateType;
              if (UpdateType == InstanceDefinitionUpdateType.Linked)
            LayerStyle = (idef.LayerStyle == InstanceDefinitionLayerStyle.Reference ? InstanceDefinitionLayerStyle.Reference : InstanceDefinitionLayerStyle.Active);
              else
            LayerStyle = InstanceDefinitionLayerStyle.None;
              SkipNestedLinkedDefinitions = idef.SkipNestedLinkedDefinitions;
              InsertSourceArchive = false;
              //InsertSourceArchive = (UpdateType == InsertCommand.UpdateType.Linked);
            }
              }
              catch (Exception ex)
              {
            Rhino.Runtime.HostUtils.ExceptionReport(ex);
              }
        }
 /// <summary>
 /// Compare properties that appear in the option form; UpdateType, LayerStyle and SkipNestedLinkedDefinitions flags.
 /// </summary>
 /// <param name="idef"></param>
 /// <returns></returns>
 public bool FileNameOptionsMatch(InstanceDefinition idef)
 {
     return (null != idef && UpdateType == idef.UpdateType && LayerStyle == idef.LayerStyle && SkipNestedLinkedDefinitions == idef.SkipNestedLinkedDefinitions);
 }
Пример #8
0
        private static Image GetPreviewImage(InstanceDefinition main, InstanceDefinition active, int width, int height)
        {
            var imageAccess = new PreviewImageTableDataAccess();

            return(imageAccess.GetNestedPreview(main, active, width, height));
        }
Пример #9
0
 /// <summary>
 /// Gets all <see cref="InstanceDefinition"/>s assembled in the given <see cref="InstanceDefinition"/>
 /// </summary>
 /// <param name="definition"></param>
 /// <returns></returns>
 public static IEnumerable <InstanceDefinition> GetPartDefinitions(this InstanceDefinition definition)
 {
     return(from obj in definition.GetPartInstances() select obj.InstanceDefinition);
 }
Пример #10
0
 /// <summary>
 /// Gets all <see cref="InstanceObject"/>s assembled in the given <see cref="InstanceDefinition"/>
 /// </summary>
 /// <param name="definition"></param>
 /// <returns></returns>
 public static IEnumerable <InstanceObject> GetPartInstances(this InstanceDefinition definition)
 {
     return(from obj in definition.GetObjects()
            where obj.ObjectType == ObjectType.InstanceReference
            select(InstanceObject) obj);
 }
Пример #11
0
 public static IEnumerable <ChildBlockInsertionParameters> GetPartRelativeXforms(this InstanceDefinition definition)
 {
     return(from obj in definition.GetObjects()
            where obj.ObjectType == ObjectType.InstanceReference
            let reference = obj as InstanceObject
                            select new ChildBlockInsertionParameters(reference.InsertionPoint, reference.InstanceXform));
 }
Пример #12
0
 public static bool IsInUse(this InstanceDefinition definition)
 {
     return(definition.InUse(0) | definition.InUse(1) | definition.InUse(2));
 }
Пример #13
0
 /// <summary>
 /// Tests a given instance definition, if it is at the root level
 /// meaning it only contains "pure" rhino geometry and no other nested instance definitions.
 /// </summary>
 /// <param name="definition"></param>
 /// <returns>A boolean telling if the given definition is root or not</returns>
 public static bool IsRoot(this InstanceDefinition definition)
 {
     return(!definition.GetObjects().Any(o => o.ObjectType == ObjectType.InstanceReference));
 }
 /// <summary>
 /// Call this method to decide if a InstanceDefinition should be added to the combo box
 /// </summary>
 /// <param name="idef"></param>
 /// <returns></returns>
 bool IncludeIDefInList(InstanceDefinition idef)
 {
     // Ignore delete, tenuous (defined in linked files) and referenced InstanceDefintion objects
       // 20 August 2012 John Morse http://dev.mcneel.com/bugtrack/?q=112140
       // Updating a referenced file that includes blocks causes the documents block table to contain
       // null Instance Definition pointers, when this happens the Id will be Guid.Empty and the
       // Instance Definition Name property will return NULL which causes problems when adding
       // the item to a ComboBox so I added the idef.Id == Guid.Empty test to filter out null definitions.
       if (null == idef || idef.IsDeleted || idef.Id == Guid.Empty || null == idef.Name || idef.IsTenuous || idef.IsReference)
     return false;
       // Pay attention to the hidden block display flag
       if (!ShowHiddenBlockDefinitions && IsHiddenIDef(idef))
     return false;
       return true;
 }
Пример #15
0
 public InsertedInstanceModel(InstanceDefinition definition, InstanceInsertionModel insertion) : this(definition)
 {
     Insertion = insertion;
 }
Пример #16
0
        /// <summary>
        /// Gets a preview image for the given block definition
        /// </summary>
        /// <param name="definition">The definition to draw a preview image for</param>
        /// <param name="width">width of the preview image in pixels</param>
        /// <param name="height">height of the preview image in pixels</param>
        /// <returns></returns>
        private static Image GetPreviewImage(InstanceDefinition definition, int width, int height)
        {
            var imageAccess = new PreviewImageTableDataAccess();

            return(imageAccess.GetPreview(definition, width, height));
        }
Пример #17
0
 public static int PartCount(this InstanceDefinition definition)
 {
     return(definition.GetPartInstances().Count());
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="existingInstanceDefinitions"></param>
 /// <param name="blockName"></param>
 /// <param name="idef"></param>
 public void BlockNameFromFileName(string fileName, InstanceDefinition[] existingInstanceDefinitions, out string blockName, out InstanceDefinition idef)
 {
     blockName = string.Empty;
       idef = null;
       // Get a list of existing InstanceDefinition objects which have a source archive equal to fileName
       if (null == existingInstanceDefinitions)
     existingInstanceDefinitions = InstanceDefintionsFromFileName(fileName);
       if (UpdateType == InstanceDefinitionUpdateType.Linked)
       {
     // If linking to a file check the existing definition list for a linked file
     idef = FindFistLinkedInstanceDefinition(existingInstanceDefinitions);
       }
       // If not linked with a matching liked definition look through the list of InstanceDefinition objects
       // with SourceArchive values equal to fileName for a InstanceDefintion with the same UpdateType,
       // LayerStyle, and SkipNestedLinkedDefinitions values
       for (int i = 0; null == idef && i < existingInstanceDefinitions.Length; i++)
     if (FileNameOptionsMatch(existingInstanceDefinitions[i]))
       idef = existingInstanceDefinitions[i];
       if (null != idef)
       {
     // A matching linked block was found so use it, only ever use one linked definition per file or
     // another InstanceDefinitino with matching properties was found so just use it
     FromInstanceDefinition(idef);
       }
       else
       {
     // This means there was not match found so cook up a block name based on the file name making sure the new name is unique
     blockName = System.IO.Path.GetFileNameWithoutExtension(fileName);
     // Block name is in use so add "01" to end
     if (null != Document.InstanceDefinitions.Find(blockName, true))
       blockName = Document.InstanceDefinitions.GetUnusedInstanceDefinitionName(blockName);
     // Update Command arguments using values specified by the user in the Options form
     FromFileName(fileName, blockName, UpdateType, LayerStyle, SkipNestedLinkedDefinitions);
       }
 }
Пример #19
0
 private InstanceDefinitionConduit GetPreviewConduit(InstanceDefinition definition)
 {
     return(new InstanceDefinitionConduit(
                new InsertedInstanceModel(definition)));
 }
 /// <summary>
 /// Search list of InstanceDefinitions and return the first linked one found
 /// </summary>
 /// <param name="idefs"></param>
 /// <returns></returns>
 public InstanceDefinition FindFistLinkedInstanceDefinition(InstanceDefinition[] idefs)
 {
     foreach (var idef in idefs)
     if (idef.UpdateType == InstanceDefinitionUpdateType.Linked)
       return idef;
       return null;
 }
Пример #21
0
        private NestedInstanceDefinitionConduit GetNestedPreviewConduit(InstanceDefinition main, InstanceDefinition nested)
        {
            var instanceAccess = new InstanceTableDataAccess();
            var relative       = instanceAccess.GetNestedRelativeInserted(main.Id, nested.Id);

            return(new NestedInstanceDefinitionConduit(
                       new InsertedInstanceModel(main),
                       relative));
        }
 /// <summary>
 /// Construct from instance defintion and document Id
 /// </summary>
 /// <param name="idef"></param>
 /// <param name="docId"></param>
 public InsertInstanceOptions(InstanceDefinition idef, int docId)
 {
     Id = Guid.NewGuid();
       DocumentId = docId;
       FromInstanceDefinition(idef);
 }
Пример #23
0
 /// <summary>
 /// Gets all top level nested Instance definitions for the given instance definition
 /// </summary>
 /// <param name="definition"></param>
 /// <returns></returns>
 public IEnumerable <InstanceDefinition> GetNestedDefinitions(InstanceDefinition definition)
 {
     return(definition.GetPartDefinitions());
 }