/////////////////////////////////////////////////////////////////////////
 // STEP 5: Override this virtual function to provide your own custom
 //         method get a transform object.
 public virtual IRhinoGet.result GetXform()
 {
     IRhinoGet.result res = base.GetPoint();
     if (res == IRhinoGet.result.cancel)
     {
         for (int i = 0; i < m_list.m_grip_owners.Length; i++)
         {
             MRhinoObjectGrips grips = m_list.m_grip_owners[i].m_grips;
             if (grips != null)
             {
                 grips.Reset();
             }
         }
     }
     return(res);
 }
Example #2
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoGetObject go = new MRhinoGetObject();

            go.SetCommandPrompt("Select surface or polysurface for direction display");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            MRhinoObjRef obj_ref = go.Object(0);
            IOnBrep      brep    = obj_ref.Brep();

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

            bool bIsSolid = brep.IsSolid();
            bool bFlip    = false;

            SampleCsSurfaceDirectionConduit conduit = new SampleCsSurfaceDirectionConduit();

            conduit.SetBrep(brep);
            conduit.Enable();
            context.m_doc.Redraw();

            MRhinoGetOption gf = new MRhinoGetOption();

            gf.SetCommandPrompt("Press Enter when done");
            gf.AcceptNothing();
            if (!bIsSolid)
            {
                gf.AddCommandOption(new MRhinoCommandOptionName("Flip"));
            }

            for (; ;)
            {
                IRhinoGet.result res = gf.GetOption();

                if (res == IRhinoGet.result.option)
                {
                    bFlip = !bFlip;
                    conduit.SetFlip(bFlip);
                    context.m_doc.Redraw();
                    continue;
                }

                if (res == IRhinoGet.result.nothing)
                {
                    if (!bIsSolid && bFlip)
                    {
                        OnBrep flipped_brep = new OnBrep(brep);
                        flipped_brep.Flip();
                        context.m_doc.ReplaceObject(obj_ref, flipped_brep);
                    }
                }

                break;
            }

            conduit.Disable();
            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);
        }