Пример #1
0
        /// <summary>
        /// This gets called when when the user runs this command.
        /// </summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            // Select objects to animate
            MRhinoGetObject go = new MRhinoGetObject();

            go.SetCommandPrompt("Select objects to animate");
            go.GetObjects(1, 0);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            // Select path curve
            MRhinoGetObject gc = new MRhinoGetObject();

            gc.SetCommandPrompt("Select path curve");
            gc.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
            gc.SetGeometryAttributeFilter(IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.open_curve);
            gc.EnableDeselectAllBeforePostSelect(false);
            gc.GetObjects(1, 1);
            if (gc.CommandResult() != IRhinoCommand.result.success)
            {
                return(gc.CommandResult());
            }

            // Get the curve
            IOnCurve crv = gc.Object(0).Curve();

            if (null == crv)
            {
                return(IRhinoCommand.result.failure);
            }

            // Create an array of normalized curve parameters
            List <double> slist = new List <double>(m_max_steps);

            for (int i = 0; i < m_max_steps; i++)
            {
                double s = (double)i / ((double)m_max_steps - 1);
                slist.Add(s);
            }

            // Get the real parameters along the curve
            double[] tlist = new double[m_max_steps];
            if (!crv.GetNormalizedArcLengthPoints(slist.ToArray(), ref tlist))
            {
                return(IRhinoCommand.result.failure);
            }

            // Create the display conduit
            SampleCsAnimatorConduit conduit = new SampleCsAnimatorConduit();

            // Get points along curve
            On3dPoint        start = new On3dPoint(crv.PointAtStart());
            List <On3dPoint> plist = new List <On3dPoint>(tlist.Length);

            for (int i = 0; i < m_max_steps; i++)
            {
                On3dPoint pt = new On3dPoint(crv.PointAt(tlist[i]));
                plist.Add(pt);
            }

            // Hide objects and add them to conduit's object array
            for (int i = 0; i < go.ObjectCount(); i++)
            {
                MRhinoObjRef objref = go.Object(i);
                context.m_doc.HideObject(objref);
                conduit.m_objects.Add(objref.Object());
            }

            // Do animation...
            conduit.Enable();

            for (int i = 0; i < m_max_steps; i++)
            {
                On3dVector v = plist[i] - start;
                conduit.m_xform.Translation(v);
                context.m_doc.Redraw();
                Thread.Sleep(100);
            }

            for (int i = m_max_steps - 1; i >= 0; i--)
            {
                On3dVector v = plist[i] - start;
                conduit.m_xform.Translation(v);
                if (0 != i)
                {
                    context.m_doc.Redraw();
                    Thread.Sleep(100);
                }
            }

            conduit.Disable();

            // Show hidden objects
            for (int i = 0; i < go.ObjectCount(); i++)
            {
                MRhinoObjRef objref = go.Object(i);
                context.m_doc.ShowObject(objref);
            }

            context.m_doc.Redraw();

            return(IRhinoCommand.result.success);
        }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            int    nValue = _nValue;
            double dValue = _dValue;

            MRhinoGetObject go = new MRhinoGetObject();

            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
            go.EnableGroupSelect(true);
            go.EnableSubObjectSelect(false);
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.EnableDeselectAllBeforePostSelect(false);

            bool bHavePreselectedObjects = false;

            for (; ;)
            {
                go.ClearCommandOptions();

                int dOptionIndex = go.AddCommandOptionNumber(
                    new MRhinoCommandOptionName("Double"),
                    new MRhinoGet.DoubleOption(dValue),
                    "Double value", false, 0.1, 99.9
                    );

                int nOptionIndex = go.AddCommandOptionInteger(
                    new MRhinoCommandOptionName("Integer"),
                    new MRhinoGet.IntegerOption(nValue),
                    "Integer value", 1, 99
                    );

                IRhinoGet.result res = go.GetObjects(1, 0);

                if (res == IRhinoGet.result.option)
                {
                    IRhinoCommandOption commandOption = go.Option();
                    if (null != commandOption)
                    {
                        int optionIndex = commandOption.m_option_index;
                        if (optionIndex == nOptionIndex)
                        {
                            nValue = (int)commandOption.m_number_option_value;
                        }
                        else if (optionIndex == dOptionIndex)
                        {
                            dValue = commandOption.m_number_option_value;
                        }
                    }

                    go.EnablePreSelect(false);
                    continue;
                }

                else if (res != IRhinoGet.result.@object)
                {
                    return(IRhinoCommand.result.cancel);
                }

                if (go.ObjectsWerePreSelected())
                {
                    bHavePreselectedObjects = true;
                    go.EnablePreSelect(false);
                    continue;
                }

                break;
            }

            if (bHavePreselectedObjects)
            {
                // Normally, pre-selected objects will remain selected, when a
                // command finishes, and post-selected objects will be unselected.
                // This this way of picking, it is possible to have a combination
                // of pre-selected and post-selected. So, to make sure everything
                // "looks the same", lets unselect everything before finishing
                // the command.
                for (int i = 0; i < go.ObjectCount(); i++)
                {
                    IRhinoObject rhinoObject = go.Object(i).Object();
                    if (null != rhinoObject)
                    {
                        rhinoObject.Select(false);
                    }
                }
                context.m_doc.Redraw();
            }

            int objectCount = go.ObjectCount();

            _dValue = dValue;
            _nValue = nValue;

            RhUtil.RhinoApp().Print(string.Format("Select object count = {0}\n", objectCount));
            RhUtil.RhinoApp().Print(string.Format("Value of double = {0}\n", _dValue));
            RhUtil.RhinoApp().Print(string.Format("Value of integer = {0}\n", _nValue));

            return(IRhinoCommand.result.success);
        }
        /// <summary> 
        /// This gets called when when the user runs this command.
        /// </summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            // Select objects to animate
              MRhinoGetObject go = new MRhinoGetObject();
              go.SetCommandPrompt("Select objects to animate");
              go.GetObjects(1, 0);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              // Select path curve
              MRhinoGetObject gc = new MRhinoGetObject();
              gc.SetCommandPrompt("Select path curve");
              gc.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
              gc.SetGeometryAttributeFilter(IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.open_curve);
              gc.EnableDeselectAllBeforePostSelect(false);
              gc.GetObjects(1, 1);
              if (gc.CommandResult() != IRhinoCommand.result.success)
            return gc.CommandResult();

              // Get the curve
              IOnCurve crv = gc.Object(0).Curve();
              if (null == crv )
            return IRhinoCommand.result.failure;

              // Create an array of normalized curve parameters
              List<double> slist = new List<double>(m_max_steps);
              for (int i = 0; i < m_max_steps; i++ )
              {
            double s = (double)i / ( (double)m_max_steps - 1 );
            slist.Add(s);
              }

              // Get the real parameters along the curve
              double[] tlist = new double[m_max_steps];
              if (!crv.GetNormalizedArcLengthPoints(slist.ToArray(), ref tlist))
            return IRhinoCommand.result.failure;

              // Create the display conduit
              SampleCsAnimatorConduit conduit = new SampleCsAnimatorConduit();

              // Get points along curve
              On3dPoint start = new On3dPoint(crv.PointAtStart());
              List<On3dPoint> plist = new List<On3dPoint>(tlist.Length);
              for (int i = 0; i < m_max_steps; i++)
              {
            On3dPoint pt = new On3dPoint(crv.PointAt(tlist[i]));
            plist.Add(pt);
              }

              // Hide objects and add them to conduit's object array
              for (int i = 0; i < go.ObjectCount(); i++ )
              {
            MRhinoObjRef objref = go.Object(i);
            context.m_doc.HideObject(objref);
            conduit.m_objects.Add(objref.Object());
              }

              // Do animation...
              conduit.Enable();

              for (int i = 0; i < m_max_steps; i++)
              {
            On3dVector v = plist[i] - start;
            conduit.m_xform.Translation(v);
            context.m_doc.Redraw();
            Thread.Sleep(100);
              }

              for (int i = m_max_steps - 1; i >= 0; i--)
              {
            On3dVector v = plist[i] - start;
            conduit.m_xform.Translation(v);
            if (0 != i)
            {
              context.m_doc.Redraw();
              Thread.Sleep(100);
            }
              }

              conduit.Disable();

              // Show hidden objects
              for (int i = 0; i < go.ObjectCount(); i++)
              {
            MRhinoObjRef objref = go.Object(i);
            context.m_doc.ShowObject(objref);
              }

              context.m_doc.Redraw();

              return IRhinoCommand.result.success;
        }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            int nValue = _nValue;
              double dValue = _dValue;

              MRhinoGetObject go = new MRhinoGetObject();
              go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
              go.EnableGroupSelect(true);
              go.EnableSubObjectSelect(false);
              go.EnableClearObjectsOnEntry(false);
              go.EnableUnselectObjectsOnExit(false);
              go.EnableDeselectAllBeforePostSelect(false);

              bool bHavePreselectedObjects = false;

              for (; ; )
              {
            go.ClearCommandOptions();

            int dOptionIndex = go.AddCommandOptionNumber(
              new MRhinoCommandOptionName("Double"),
              new MRhinoGet.DoubleOption(dValue),
              "Double value", false, 0.1, 99.9
              );

            int nOptionIndex = go.AddCommandOptionInteger(
              new MRhinoCommandOptionName("Integer"),
              new MRhinoGet.IntegerOption(nValue),
              "Integer value", 1, 99
              );

            IRhinoGet.result res = go.GetObjects(1, 0);

            if (res == IRhinoGet.result.option)
            {
              IRhinoCommandOption commandOption = go.Option();
              if (null != commandOption)
              {
            int optionIndex = commandOption.m_option_index;
            if (optionIndex == nOptionIndex)
              nValue = (int)commandOption.m_number_option_value;
            else if (optionIndex == dOptionIndex)
              dValue = commandOption.m_number_option_value;
              }

              go.EnablePreSelect(false);
              continue;
            }

            else if (res != IRhinoGet.result.@object)
              return IRhinoCommand.result.cancel;

            if (go.ObjectsWerePreSelected())
            {
              bHavePreselectedObjects = true;
              go.EnablePreSelect(false);
              continue;
            }

            break;
              }

              if (bHavePreselectedObjects)
              {
            // Normally, pre-selected objects will remain selected, when a
            // command finishes, and post-selected objects will be unselected.
            // This this way of picking, it is possible to have a combination
            // of pre-selected and post-selected. So, to make sure everything
            // "looks the same", lets unselect everything before finishing
            // the command.
            for (int i = 0; i < go.ObjectCount(); i++)
            {
              IRhinoObject rhinoObject = go.Object(i).Object();
              if (null != rhinoObject)
            rhinoObject.Select(false);
            }
            context.m_doc.Redraw();
              }

              int objectCount = go.ObjectCount();
              _dValue = dValue;
              _nValue = nValue;

              RhUtil.RhinoApp().Print(string.Format("Select object count = {0}\n", objectCount));
              RhUtil.RhinoApp().Print(string.Format("Value of double = {0}\n", _dValue));
              RhUtil.RhinoApp().Print(string.Format("Value of integer = {0}\n", _nValue));

              return IRhinoCommand.result.success;
        }