示例#1
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        ///
        /// 以下代码还需要优化
        ///
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Hu_Layer ParentLayer = new Hu_Layer();
            Hu_Layer ChildLayer  = new Hu_Layer();
            Hu_Layer OutputLayer = new Hu_Layer();

            LayerTable LTable = Rhino.RhinoDoc.ActiveDoc.Layers;

            if (!DA.GetData(0, ref ParentLayer))
            {
                return;
            }
            if (!DA.GetData(1, ref ChildLayer))
            {
                return;
            }

            Layer _ParentLayer = ParentLayer.Value;
            Layer _ChildLayer  = ChildLayer.Value;

            if (!this.LayerExist(_ParentLayer))
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, string.Format("父图层: {0}不存在", _ParentLayer.Name));
                _ParentLayer = LTable.CurrentLayer;
            }
            _ChildLayer.ParentLayerId = _ParentLayer.Id;
            int LayerIndex = this.AddLayerToDocument(_ChildLayer);

            OutputLayer = new Hu_Layer(LTable.FindIndex(LayerIndex));
            DA.SetData(0, OutputLayer);
        }
示例#2
0
        /*
         * public override void AppendAdditionalMenuItems(ToolStripDropDown menu)
         * {
         *  Menu_AppendItem(menu, "Select Layer", Do_Select_Layer);
         *  base.AppendAdditionalMenuItems(menu);
         * }
         *
         * private void Do_Select_Layer(object sender, EventArgs e)
         * {
         *  this.ExpireSolution(true);
         * }*/
        protected override GH_GetterResult Prompt_Singular(ref Types.Hu_Layer value)
        {
            Forms.LayerDialog Dialog = new Forms.LayerDialog();
            Dialog.StartPosition = FormStartPosition.CenterParent;
            LayerTable LT = Rhino.RhinoDoc.ActiveDoc.Layers;

            if (Dialog.ShowDialog() == DialogResult.OK)
            {
                int LayerIndex            = Dialog.LayerIndex;
                Rhino.DocObjects.Layer La = LT.FindIndex(LayerIndex);
                if (La == null)
                {
                    value = null;
                    this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "设置图层在工作空间中不存在");
                }
                else
                {
                    value = new Types.Hu_Layer(La);
                }
                return(GH_GetterResult.success);
            }
            else
            {
                return(GH_GetterResult.cancel);
            }
        }
示例#3
0
        private bool LayerExist(Layer layer)
        {
            LayerTable Layers = Rhino.RhinoDoc.ActiveDoc.Layers;

            if (Layers.FindIndex(layer.Index) == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
示例#4
0
        public override bool CastTo <Q>(ref Q target)
        {
            if (typeof(Q).IsAssignableFrom(typeof(int)))
            {
                object _Index = this.Value.Index;
                target = (Q)_Index;
                return(true);
            }

            if (typeof(Q).IsAssignableFrom(typeof(GH_Integer)))
            {
                object _Index = new GH_Integer(this.Value.Index);
                target = (Q)_Index;
                return(true);
            }
            if (typeof(Q).IsAssignableFrom(typeof(Guid)))
            {
                object _Id = this.Value.Id;
                target = (Q)_Id;
                return(true);
            }
            if (typeof(Q).IsAssignableFrom(typeof(GH_Guid)))
            {
                object _Id = new GH_Guid(this.Value.Id);
                target = (Q)_Id;
                return(true);
            }
            if (typeof(Q).IsAssignableFrom(typeof(GH_String)))
            {
                object _Path = new GH_String(this.Value.FullPath);
                target = (Q)_Path;
                return(true);
            }
            if (typeof(Q).IsAssignableFrom(typeof(string)))
            {
                object _Path = this.Value.FullPath;
                target = (Q)_Path;
                return(true);
            }
            if (typeof(Q).IsAssignableFrom(typeof(Layer)))
            {
                LayerTable LT     = Rhino.RhinoDoc.ActiveDoc.Layers;
                object     _layer = LT.FindIndex(this.Value.Index);
                target = (Q)_layer;
                return(true);
            }
            return(false);
        }
示例#5
0
        public Hu_Layer(int LayerIndex)
        {
            LayerTable LT = Rhino.RhinoDoc.ActiveDoc.Layers;

            this.Value = LT.FindIndex(LayerIndex);
        }
示例#6
0
        public override bool CastFrom(object source)
        {
            if (source == null)
            {
                return(false);
            }
            int        val;
            LayerTable LT = Rhino.RhinoDoc.ActiveDoc.Layers;

            if (GH_Convert.ToInt32(source, out val, GH_Conversion.Both))
            {
                Rhino.DocObjects.Layer La = LT.FindIndex(val);
                if (La == null)
                {
                    Value = null;
                    return(false);
                }
                else
                {
                    Value = La;
                    return(true);
                }
            }
            Guid id;

            if (GH_Convert.ToGUID(source, out id, GH_Conversion.Both))
            {
                Rhino.DocObjects.Layer La = LT.FindId(id);
                if (La == null)
                {
                    Value = null;
                    return(false);
                }
                else
                {
                    Value = La;
                    return(true);
                }
            }
            string Name;

            if (GH_Convert.ToString(source, out Name, GH_Conversion.Both))
            {
                int Index = LT.FindByFullPath(Name, -1);
                if (Index == -1)
                {
                    Rhino.DocObjects.Layer La = new Layer();
                    La.Name = Name;
                    Value   = La;
                    return(true);
                }
                else
                {
                    Value = LT.FindIndex(Index);
                    return(true);
                }
            }
            if (source.GetType() == typeof(Layer))
            {
                Value = (Layer)source;
                return(true);
            }
            if (source.GetType() == typeof(Hu_Layer))
            {
                Value = ((Hu_Layer)source).Value;
                return(true);
            }
            return(false);
        }