예제 #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)
        {
            //reset the slider index if this is the first time solveinstance is called for this run cycle.
            if (DA.Iteration == 0)
            {
                sliderIndex = 0;
            }

            List <Label> sliderLabels = new List <Label>();
            //container to hold the UIElement_Goo objects wrapping each slider
            List <UIElement_Goo> sliderPanels = new List <UIElement_Goo>();
            //get the GH doc
            GH_Document doc = OnPingDocument();

            if (doc == null)
            {
                return;
            }

            // iterate over doc activeObjects
            foreach (IGH_ActiveObject ao in doc.ActiveObjects())
            {
                // If it's a slider that's connected to this component
                if (DependsOn(ao) && ao is GH_NumberSlider)
                {
                    // Because we're actually outputting a list of objects (unlike most other UI element components) we have to
                    // calc the output index ourselves.
                    sliderPanels.Add(new UIElement_Goo(MakeSlider(ao as GH_NumberSlider, ref sliderLabels), (ao as GH_NumberSlider).ImpliedNickName, InstanceGuid, sliderIndex));
                    sliderIndex++;
                }
            }


            //this sequence makes sure that all the slider labels fed through one component align with one another

            double width = 0;

            foreach (Label l in sliderLabels)
            {
                //measure the label
                l.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                if (width < l.DesiredSize.Width)
                {
                    //update width if it's larger than the current known
                    width = l.DesiredSize.Width;
                }
            }
            //set the width of all the labels to be wide enough to accommodate the widest one.
            foreach (Label l in sliderLabels)
            {
                l.Width = width;
            }
            //pass out the sliders
            DA.SetDataList("Sliders", sliderPanels);
        }
예제 #2
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)
        {
            List <UIElement_Goo> sliderPanels = new List <UIElement_Goo>();
            GH_Document          doc          = OnPingDocument();

            if (doc == null)
            {
                return;
            }
            foreach (IGH_ActiveObject ao in doc.ActiveObjects())
            {
                if (DependsOn(ao) && ao is GH_NumberSlider)
                {
                    sliderPanels.Add(new UIElement_Goo(MakeSlider(ao as GH_NumberSlider), (ao as GH_NumberSlider).ImpliedNickName, InstanceGuid, DA.Iteration));
                }
            }

            DA.SetDataList("Sliders", sliderPanels);
        }
예제 #3
0
        public IGH_ActiveObject GetCapsure(string Name, string NickName)
        {
            GH_Document             ghdoc = Grasshopper.Instances.ActiveCanvas.Document;
            List <IGH_ActiveObject> aos   = ghdoc.ActiveObjects();

            for (int i = 0; i < aos.Count; i++)
            {
                IGH_ActiveObject ao = aos[i];
                Print("Type==> " + ao.Name);
                if (ao.Name == Name)
                {
                    Print("Name==> " + ao.NickName);
                    if (ao.NickName == NickName)
                    {
                        return(ao);
                    }
                }
            }
            return(null);
        }
예제 #4
0
        public virtual void SetParamPointCapsure(string NickName, IEnumerable <Point3d> pts)
        {
            GH_Document             ghdoc = Grasshopper.Instances.ActiveCanvas.Document;
            List <IGH_ActiveObject> aos   = ghdoc.ActiveObjects();

            for (int i = 0; i < aos.Count; i++)
            {
                IGH_ActiveObject ao = aos[i];
                Print("Type==> " + ao.Name);
                if (ao.Name == "Point")
                {
                    Param_Point comp = (Param_Point)ao;
                    Print("Name==> " + comp.NickName);
                    if (ao.NickName == NickName)
                    {
                        GH_Path path = new GH_Path(1);
                        comp.AddVolatileDataList(path, pts);
                    }
                }
            }
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            if (ghDocument == null)
            {
                ghDocument      = OnPingDocument();
                ghActiveObjects = ghDocument.ActiveObjects();
                originalPivots  = new List <PointF>();

                foreach (GH_ActiveObject ghActiveObject in ghActiveObjects)
                {
                    originalPivots.Add(ghActiveObject.Attributes.Pivot);
                }
            }

            if (Keyboard.IsKeyDown(Key.LeftCtrl) && Keyboard.IsKeyDown(Key.LeftAlt))
            {
                isRestarting = true;
            }

            if (isRestarting) // 元の位置に戻す
            {
                isRestarting = false;

                for (int i = 0; i < ghActiveObjects.Count; i++)
                {
                    IGH_ActiveObject ghActiveObject = ghActiveObjects[i];

                    if (ghActiveObject == null)
                    {
                        continue;
                    }

                    if (ghActiveObject == this)
                    {
                        continue;
                    }

                    PointF pivot = ghActiveObject.Attributes.Pivot;

                    // ピポットをもとの位置に戻す
                    PointF newPivot = new PointF(
                        (float)(1.0 - k) * pivot.X + (float)k * originalPivots[i].X,
                        (float)(1.0 - k) * pivot.Y + (float)k * originalPivots[i].Y);

                    // ピボットが元の位置に達したかどうかを確認
                    if (Math.Abs(newPivot.X - pivot.X) > 1.0 || Math.Abs(newPivot.Y - pivot.Y) > 1.0)
                    {
                        isRestarting = true;
                        ghActiveObject.Attributes.Pivot = new PointF((float)newPivot.X, (float)newPivot.Y);
                        ghActiveObject.Attributes.ExpireLayout();
                    }
                }
            }
            else if (flagNum == 0)// マウスカーソルによってコンポーネントを動かしていく
            {
                PointF  cursorF = Instances.ActiveCanvas.CursorCanvasPosition;
                Point3d cursor  = new Point3d(cursorF.X, cursorF.Y, 0.0);

                for (int i = 0; i < ghActiveObjects.Count; i++)
                {
                    IGH_ActiveObject ghActiveObject = ghActiveObjects[i];

                    if (ghActiveObject == null)
                    {
                        continue;
                    }

                    if (ghActiveObject == this) // ここの処理が重要。コンポーネント自体を移動させると削除できなくなる
                    {
                        continue;
                    }

                    RectangleF bounds  = ghActiveObject.Attributes.Bounds; // キャンバス上のコンポーネントの位置と寸法を記述する矩形
                    PointF     centerF = new PointF(
                        (bounds.Left + bounds.Right) * 0.5f,
                        (bounds.Top + bounds.Bottom) * 0.5f);
                    Point3d center = new Point3d(centerF.X, centerF.Y, 0.0);

                    double r = Math.Sqrt(bounds.Width * bounds.Width + bounds.Height * bounds.Height) * 0.5;

                    Vector3d v = center - cursor;

                    if (v.Length < minDistance + r) // マウスカーソルがコンポーネントの位置に十分に近い場合
                    {
                        // コンポーネントをマウスカーソルから離して、minDistanceを満たすまで移動します。
                        PointF  pivot     = ghActiveObject.Attributes.Pivot;
                        Point3d newCenter = center + v / v.Length * k * (minDistance + r - v.Length);

                        PointF newPivot = new PointF(
                            (float)(newCenter.X + pivot.X - center.X),
                            (float)(newCenter.Y + pivot.Y - center.Y));

                        ghActiveObject.Attributes.Pivot = newPivot;
                        ghActiveObject.Attributes.ExpireLayout();
                    }
                }
            }
            else if (flagNum == 1)
            {
                PointF  cursorF = Instances.ActiveCanvas.CursorCanvasPosition;
                Point3d cursor  = new Point3d(cursorF.X, cursorF.Y, 0.0);

                for (int i = 0; i < ghActiveObjects.Count; i++)
                {
                    IGH_ActiveObject ghActiveObject = ghActiveObjects[i];

                    if (ghActiveObject == null)
                    {
                        continue;
                    }

                    if (ghActiveObject == this)
                    {
                        continue;
                    }

                    RectangleF bounds  = ghActiveObject.Attributes.Bounds;
                    PointF     centerF = new PointF(
                        (bounds.Left + bounds.Right) * 0.5f,
                        (bounds.Top + bounds.Bottom) * 0.5f);
                    Point3d center = new Point3d(centerF.X, centerF.Y, 0.0);

                    double r = Math.Sqrt(bounds.Width * bounds.Width + bounds.Height * bounds.Height) * 0.5;

                    Vector3d v = center - cursor;

                    if (v.Length < minDistance + r)
                    {
                        PointF  pivot     = ghActiveObject.Attributes.Pivot;
                        Point3d newCenter = cursor;

                        PointF newPivot = new PointF(
                            (float)(newCenter.X),
                            (float)(newCenter.Y));

                        ghActiveObject.Attributes.Pivot = newPivot;
                        ghActiveObject.Attributes.ExpireLayout();
                    }
                }
            }

            ExpireSolution(true);
        }
예제 #6
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DA.SetData(0, way);
            //Message = "温和破解模式";

            bool s = false;

            DA.GetData(0, ref s);
            if (s)
            {
                if (Absolute2)
                {
                    {
                        this.Message = "暴力解密成功";

                        GH_Document             gH_Document = Grasshopper.Instances.ActiveCanvas.Document;
                        List <IGH_ActiveObject> objList     = gH_Document.ActiveObjects();


                        Type type = typeof(Grasshopper.Kernel.Special.GH_Cluster);
                        for (int i = 0; i < objList.Count; i++)
                        {
                            if (objList[i].GetType() == type)
                            {
                                ((Grasshopper.Kernel.Special.GH_Cluster)(objList[i])).ExplodeCluster();
                            }
                        }
                        GH_Document.EnableSolutions = false;// !GH_Document.EnableSolutions;


                        //   DA.SetData(0,  "破解成功");
                    }
                }
                else if (!Absolute2)


                {
                    this.Message = "温和破解成功";
                    GH_Document             gH_Document = Grasshopper.Instances.ActiveCanvas.Document;
                    List <IGH_ActiveObject> objList     = gH_Document.ActiveObjects();

                    Type type = typeof(Grasshopper.Kernel.Special.GH_Cluster);
                    for (int i = 0; i < objList.Count; i++)
                    {
                        if (objList[i].GetType() == type)
                        {
                            Grasshopper.Kernel.Special.GH_Cluster cluster = (Grasshopper.Kernel.Special.GH_Cluster)objList[i];
                            System.Reflection.FieldInfo[]         field   = type.GetFields(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                            field[0].SetValue(cluster, Convert.FromBase64String(""));
                        }
                    }
                }

                else
                {
                    //  DA.SetData(0, way);

                    DA.SetData(0, "未破解");
                }
            }
        }