private void OnDocSolutionEnd(object sender, GH_SolutionEventArgs e)
 {
     if (_document != null)
     {
         _document.Objects.Clear();
     }
 }
Пример #2
0
 private void ends(object sender, GH_SolutionEventArgs e)
 {
     if (this.Save)
     {
         Caputre("");
     }
 }
Пример #3
0
 void AfterDocumentChanged(object sender, GH_SolutionEventArgs args)
 {
     if (this.Locked != m_locked)
     {
         m_locked = this.Locked;
         OnLockedChanged(m_locked);
     }
 }
Пример #4
0
 public void StartSolutionHandler(object o, GH_SolutionEventArgs e)
 {
     if (!InLoop)
     {
         Document.SolutionEnd -= StartSolutionHandler;
         Start();
     }
 }
Пример #5
0
 private void Definition_SolutionEnd(object sender, GH_SolutionEventArgs e)
 {
     if (Tag is Dockpane1View dock && dock.autoupdate.IsChecked == true)
     {
         GhUtil.showDocumentPreview(dock.rhinoDoc);
         // TODO: Add code to harvest display meshes when the Grasshopper Definition solution completes solving.
     }
 }
 void DocumentSolutionStart(object sender, GH_SolutionEventArgs e)
 {
     foreach (IModifiable mod in TargetObjects())
     {
         mod.ModifyValue -= ModifyValue;
         mod.ModifyValue += ModifyValue;
     }
 }
Пример #7
0
        private void Definition_SolutionEnd(object sender, GH_SolutionEventArgs e)
        {
            // Console.WriteLine("GH: Solution End.");

            // Process Meshes
            var mesh = GetDocumentPreview(e.Document);

            cb?.Invoke(Newtonsoft.Json.JsonConvert.SerializeObject(mesh, GeometryResolver.Settings));
        }
Пример #8
0
 private void UpdateFileCallback(object sender, GH_SolutionEventArgs e)
 {
     if (!ShouldContinue())
     {
         return;
     }
     if (!(sender is GH_Document doc))
     {
         return;
     }
     doc.SolutionEnd -= UpdateFileCallback;
     ExpireSolution(false);
     OnPingDocument().ScheduleSolution(100);
     IsBusy = false;
 }
Пример #9
0
        private void WriteCodeToComponent(object sender, GH_SolutionEventArgs e)
        {
            if (!ShouldContinue())
            {
                return;
            }
            if (!(sender is GH_Document doc))
            {
                return;
            }

            doc.SolutionEnd -= WriteCodeToComponent;
            WriteScriptToComponent(TargetComponent, FileNameSafe);
            TargetComponent.ExpireSolution(true);
            IsBusy = false;
        }
Пример #10
0
        //private bool MoveToNextPermutation(ref int MoveToParamIndex)
        //{


        //    if (MoveToParamIndex >= this._inputParams.Count)
        //    {
        //        return false;
        //    }

        //    //System.Windows.Forms.MessageBox.Show(Count.ToString());


        //    var currentParam = this._inputParams[MoveToParamIndex];
        //    var thisSelectedPositions = this._allSelectedPositions[MoveToParamIndex];
        //    //int currentStepPosition = currentStepPositionsIndex[MoveToParamIndex];

        //    int nextPositionIndex = this._currentPositionsIndex[MoveToParamIndex]+1;


        //    if (nextPositionIndex < thisSelectedPositions.Count)
        //    {
        //        int nextPosition = thisSelectedPositions[nextPositionIndex];

        //        currentParam.SetParamTo(nextPosition);

        //        //Increment the current step position
        //        this._currentPositionsIndex[MoveToParamIndex]++ ;

        //        return true;
        //    }else
        //    {

        //        //currentParam.Reset();
        //        currentParam.SetParamTo(thisSelectedPositions.First());

        //        ////The current component is already at the maximum value. Reset it back to zero.
        //        this._currentPositionsIndex[MoveToParamIndex] = 0;

        //        //// Move on to the next slider.
        //        MoveToParamIndex++;

        //        //// If we've run out of sliders to modify, we're done permutatin'
        //        if (MoveToParamIndex >= _inputParams.Count)
        //        {
        //            return false;
        //        }

        //        return MoveToNextPermutation(ref MoveToParamIndex);
        //    }

        //}

        public void Fly(GH_SolutionEventArgs e)
        {
            FirstResetAll(false);

            var flyPositions    = FlyPositions(this._allSelectedPositions);
            var selflyPositions = selectedIterations(this._selections, flyPositions);

            int totalIterations = selflyPositions.Count;


            bool isRunning  = true;
            bool stopByUser = false;

            foreach (var item in selflyPositions)
            {
                //set each param to target positon
                for (int i = 0; i < item.Count; i++)
                {
                    var currentParam   = this._inputParams[i];
                    int moveToPosition = item[i];
                    currentParam.SetParamTo(moveToPosition);
                }


                if (!checkIfStudiedFromCSV())
                {
                    e.Document.NewSolution(false);
                }



                Count++;
                isRunning  = Count < totalIterations;
                stopByUser = !listenToKeepRunning();


                if (!isRunning || stopByUser)
                {
                    // study is over!
                    if (File.Exists(_watchFilePath))
                    {
                        File.Delete(_watchFilePath);
                    }
                    break;
                }
            }
        }
Пример #11
0
        //public void FlyAll(GH_SolutionEventArgs e)
        //{

        //    FirstResetAll(false);


        //    while (true)
        //    {

        //        int currentParamIndex = 0;
        //        bool isRunning = true;

        //        //move to the next set of slider positions
        //        isRunning = MoveToNextPermutation(ref currentParamIndex);



        //        //watch the selection
        //        bool isInSelection = ifInSelectionDomains(this._selections, Count);


        //        if (isInSelection)
        //        {
        //            if (this._overrideFolderMode == OverrideMode.FinishTheRest)
        //            {
        //                bool isStudiedID = this._studiedFlyID.Contains(getCurrentFlyID());
        //                if (!isStudiedID)
        //                {
        //                    // We've just got a new valid permutation. Solve the new solution.
        //                    e.Document.NewSolution(false);
        //                }
        //            }
        //            else
        //            {
        //                e.Document.NewSolution(false);
        //            }

        //        }

        //        Count++;

        //        //watch the user cancel the process
        //        if (GH_Document.IsEscapeKeyDown())
        //        {
        //            if (MessageBox.Show("Do you want to stop the process?\nSo far " + Count.ToString() +
        //              " out of " + this._selectedCounts.ToString() + " iterations are done!", "Stop?", MessageBoxButtons.YesNo) == DialogResult.Yes)
        //            {
        //                // cancel the process by user input!
        //                isRunning = false;
        //            }
        //        }

        //        //watch the file to stop
        //        if (!string.IsNullOrEmpty(_watchFilePath))
        //        {
        //            if (!File.Exists(_watchFilePath))
        //            {
        //                // watch file was deleted by user
        //                isRunning = false;
        //            }
        //        }

        //        if (!isRunning )
        //        {
        //            // study is over!

        //            if (File.Exists(_watchFilePath))
        //            {
        //                File.Delete(_watchFilePath);
        //            }
        //            //e.Document.NewSolution(false);
        //            break;
        //        }

        //    }

        //}

        public void FlyTest(GH_SolutionEventArgs e, int testNumber)
        {
            if (_totalCounts <= testNumber)
            {
                Fly(e);
                return;
            }

            FirstResetAll(true);

            int totalParamCount = _inputParams.Count;
            var random          = new Random();

            var flewID = new HashSet <string>();

            while (true)
            {
                //pick random input param
                int randomParamIndex  = random.Next(totalParamCount);
                var currentInputParam = _inputParams[randomParamIndex];

                //pick random step of param
                int randomStepIndex = random.Next(currentInputParam.TotalCount);
                var flyID           = randomParamIndex + "_" + randomStepIndex;

                //test if the same flyID has already ran
                if (!flewID.Contains(flyID))
                {
                    flewID.Add(flyID);
                    currentInputParam.SetParamTo(randomStepIndex);
                    Count++;

                    e.Document.NewSolution(false);

                    if (flewID.Count >= testNumber)
                    {
                        // study is over!
                        if (File.Exists(_watchFilePath))
                        {
                            File.Delete(_watchFilePath);
                        }
                        break;
                    }
                }
            }
        }
Пример #12
0
        private void Definition_SolutionEnd(object sender, GH_SolutionEventArgs e)
        {
            FMessage.Log(ELogVerbosity.Warning, "Solution End");
            if (definition != e.Document)
            {
                return;
            }

            mesh = GetDocumentPreview(e.Document);

            if (mesh == null)
            {
                return;
            }

            mesh.Faces.ConvertQuadsToTriangles();
            mesh.Flip(true, true, true);
        }
Пример #13
0
        private void OnSolutionEnd(object sender, GH_SolutionEventArgs e)
        {
            // Unregister the event, we don't want to get called again.
            e.Document.SolutionEnd -= OnSolutionEnd;

            // If we're not supposed to run, abort now.
            if (!_run || _running)
            {
                return;
            }

            // Reset run and running states.
            _run     = false;
            _running = true;

            try
            {
                if (_isTestFly)
                {
                    _isTestFly = false;
                    _flyParam.FlyTest(e, 3);
                }
                else
                {
                    _flyParam.Fly(e);
                }

                if (_aggObj != null)
                {
                    _aggObj.setWriteFileToFalse();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                // Always make sure that _running is switched off.
                _running       = false;
                this._flyParam = null;
            }
        }
Пример #14
0
        private void Doc_SolutionEnd(object sender, GH_SolutionEventArgs e)
        {
            DebugEvent("SolutionEnd Event");

            try
            {
                StoreOutput();
            }
            catch (Exception ex)
            {
                ErrorEvent(sender, ex.Message);
            }
            finally
            {
                if (RunningCnt == 0)
                {
                    Commands.ZoomNow.Zoom();
                }
                ++RunningCnt;
                DoneEvent(this, ID.ToString(), IsTaskRestore);
                IsTaskRestore = false;
            }
        }
Пример #15
0
        private void OnSolutionEnd(object sender, GH_SolutionEventArgs e)
        {
            // Unregister the event, we don't want to get called again.
            e.Document.SolutionEnd -= OnSolutionEnd;

            // If we're not supposed to run, abort now.
            if (!_run)
            {
                return;
            }

            // If we're already running, abort now.
            if (_running)
            {
                return;
            }

            // Reset run and running states.
            _run     = false;
            _running = true;

            try
            {
                // Find the Guid for connected slides
                List <System.Guid>          guids           = new List <System.Guid>(); //empty list for guids
                GH.Kernel.IGH_Param         selSlidersInput = this.Params.Input[0];     //ref for input where sliders are connected to this component
                IList <GH.Kernel.IGH_Param> sources         = selSlidersInput.Sources;  //list of things connected on this input
                bool isAnythingConnected = sources.Any();                               //is there actually anything connected?


                // Find connected
                GH.Kernel.IGH_Param trigger = this.Params.Input[2].Sources[0]; //ref for input where a boolean or a button is connected
                GH.Kernel.Special.GH_BooleanToggle boolTrigger = trigger as GH.Kernel.Special.GH_BooleanToggle;

                if (isAnythingConnected)
                {                                                                                                    //if something's connected,
                    foreach (var source in sources)                                                                  //for each of these connected things:
                    {
                        IGH_DocumentObject component = source.Attributes.GetTopLevel.DocObject;                      //for this connected thing, bring it into the code in a way where we can access its properties
                        GH.Kernel.Special.GH_NumberSlider mySlider = component as GH.Kernel.Special.GH_NumberSlider; //...then cast (?) it as a slider
                        if (mySlider == null)                                                                        //of course, if the thing isn't a slider, the cast doesn't work, so we get null. let's filter out the nulls
                        {
                            continue;
                        }
                        guids.Add(mySlider.InstanceGuid); //things left over are sliders and are connected to our input. save this guid.
                                                          //we now have a list of guids of sliders connected to our input, saved in list var 'mySlider'
                    }
                }

                // Find all sliders.
                List <GH.Kernel.Special.GH_NumberSlider> sliders = new List <GH.Kernel.Special.GH_NumberSlider>();
                foreach (IGH_DocumentObject docObject in doc.Objects)
                {
                    GH.Kernel.Special.GH_NumberSlider slider = docObject as GH.Kernel.Special.GH_NumberSlider;
                    if (slider != null)
                    {
                        // check if the slider is in the selected list
                        if (isAnythingConnected)
                        {
                            if (guids.Contains(slider.InstanceGuid))
                            {
                                sliders.Add(slider);
                            }
                        }
                        else
                        {
                            sliders.Add(slider);
                        }
                    }
                }
                if (sliders.Count == 0)
                {
                    System.Windows.Forms.MessageBox.Show("No sliders could be found", "<harsh buzzing sound>", MessageBoxButtons.OK);
                    return;
                }

                //we now have all sliders
                //ask the user to give a sanity check
                int    counter      = 0;
                int    totalLoops   = 1;
                string popupMessage = "";

                // create progress bar by dots and |
                string pb      = ".................................................."; //50 of "." - There should be a better way to create this in C# > 50 * "." does it in Python!
                char[] pbChars = pb.ToCharArray();

                int dummyCounter = 0;
                foreach (GH.Kernel.Special.GH_NumberSlider slider in sliders)
                {
                    totalLoops   *= (sliderSteps[dummyCounter] + 1);
                    popupMessage += slider.ImpliedNickName;
                    popupMessage += "\n";
                    dummyCounter++;
                }
                if (System.Windows.Forms.MessageBox.Show(sliders.Count + " slider(s) connected:\n" + popupMessage +
                                                         "\n" + totalLoops.ToString() + " iterations will be done. Continue?" + "\n\n (Press ESC to pause during progressing!)", "Start?", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    SetBooleanToFalse(boolTrigger);
                    this.Message = "Release the Colibri!";

                    //wipe out colibri variables and compute a new solution
                    sliderNames          = new List <string>();
                    sliderSteps          = new List <int>();
                    sliderStepsPositions = new Dictionary <int, int>();
                    computedValues       = new List <string>();
                    e.Document.NewSolution(false);
                    Rhino.RhinoDoc.ActiveDoc.Views.Redraw();

                    return;
                }

                // Set all sliders back to first tick
                foreach (GH.Kernel.Special.GH_NumberSlider slider in sliders)
                {
                    slider.TickValue = 0;
                }

                //start a stopwatch
                System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();

                // Start a giant loop in which we'll permutate our way across all slider layouts.
                while (true)
                {
                    int idx = 0;

                    // let the user cancel the process
                    if (GH_Document.IsEscapeKeyDown())
                    {
                        if (System.Windows.Forms.MessageBox.Show("Do you want to stop the process?\nSo far " + counter.ToString() +
                                                                 " out of " + totalLoops.ToString() + " iterations are done!", "Stop?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            // cancel the process by user input!
                            SetBooleanToFalse(boolTrigger);
                            this.Message += "\nCanceled by user! :|";
                            return;
                        }
                    }

                    //add the current slider values to our list of already computed values
                    var sliderVals = GetSliderVals(sliders);
                    if (!computedValues.Contains(sliderVals))
                    {
                        computedValues.Add(sliderVals);
                    }

                    //move to the next set of slider positions
                    if (!MoveToNextPermutation(ref idx, sliders))
                    {
                        // study is over!
                        SetBooleanToFalse(boolTrigger);
                        sw.Stop(); //stop start watch
                        UpdateProgressBar(counter, totalLoops, sw, pbChars);
                        this.Message += "\nFinished at " + DateTime.Now.ToShortTimeString();

                        //wipe out colibri variables
                        sliderNames          = new List <string>();
                        sliderSteps          = new List <int>();
                        sliderStepsPositions = new Dictionary <int, int>();
                        computedValues       = new List <string>();
                        e.Document.NewSolution(false);
                        Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
                        break;
                    }

                    // We've just got a new valid permutation. Solve the new solution.
                    counter++;
                    e.Document.NewSolution(false);
                    Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
                    UpdateProgressBar(counter, totalLoops, sw, pbChars);
                }
            }
            catch
            {
                // "something went wrong!";
            }
            finally
            {
                // Always make sure that _running is switched off.
                _running = false;
            }
        }
Пример #16
0
        object RunPermutations(int[] lengths, GH_BooleanToggle boolTrigger, List <GH_NumberSlider> sliders, GH_SolutionEventArgs e, params object[] objs)
        {
            // create progress bar by dots and |
            string pb = ".................................................."; //50 of "." - There should be a better way to create this in C# > 50 * "." does it in Python!

            char[] pbChars = pb.ToCharArray();

            Stopwatch sw      = Stopwatch.StartNew();
            int       counter = 0;

            foreach (int[] idxs in new IterateNDArray(lengths))
            {
                // let the user cancel the process
                if (GH_Document.IsEscapeKeyDown())
                {
                    if (System.Windows.Forms.MessageBox.Show("Do you want to stop the process?\nSo far " + counter.ToString() +
                                                             " out of " + totalLoops.ToString() + " iterations are done!", "Stop?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        // cancel the process by user input!
                        SetBooleanToFalse(boolTrigger);
                        this.Message += "\nCanceled by user! :|";
                        return(null);
                    }
                }

                for (int i = 0; i < sliders.Count; i++)
                {
                    GH_NumberSlider slider = sliders[i];

                    //look up the current slider's current sliderStepsPosition and target number
                    int totalNumberOfSteps = sliderSteps[i];
                    int steps = slider.TickCount / sliderSteps[i];
                    slider.TickValue = steps * idxs[i];
                    //int numTicksToAddAsInt = slider.TickCount / totalNumberOfSteps;
                    //double numTicksToAddAsDouble = (double)slider.TickCount / (double)totalNumberOfSteps;

                    ////find the closest tick
                    //int closestTick = 0;
                    //if (currentSliderStepsPosition + numTicksToAddAsInt >= sliderMidStep)
                    //{
                    //    closestTick = (int)Math.Ceiling(numTicksToAddAsDouble * currentSliderStepsPosition);
                    //}
                    //else
                    //{
                    //    closestTick = (int)Math.Floor(numTicksToAddAsDouble * currentSliderStepsPosition);
                    //}

                    // Increment the slider.
                }

                // We've just got a new valid permutation. Solve the new solution.
                counter++;
                e.Document.NewSolution(false);
                Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
                UpdateProgressBar(counter, totalLoops, sw, pbChars);
            }

            // study is over!
            SetBooleanToFalse(boolTrigger);
            sw.Stop(); //stop start watch
            UpdateProgressBar(counter, totalLoops, sw, pbChars);
            this.Message += "\nFinished at " + DateTime.Now.ToShortTimeString();

            //wipe out colibri variables
            sliderNames          = new List <string>();
            sliderSteps          = new int[sliderNames.Count];
            sliderStepsPositions = new int[sliderNames.Count];
            computedValues       = new List <string>();
            e.Document.NewSolution(false);
            Rhino.RhinoDoc.ActiveDoc.Views.Redraw();

            return(null);
        }
Пример #17
0
        private void OnSolutionEnd(object sender, GH_SolutionEventArgs e)
        {
            // Unregister the event, we don't want to get called again.
            e.Document.SolutionEnd -= OnSolutionEnd;

            // If we're not supposed to run, abort now.
            if (!_run)
            {
                return;
            }

            // If we're already running, abort now.
            if (_running)
            {
                return;
            }

            // Reset run and running states.
            _run     = false;
            _running = true;

            try
            {
                // Find the Guid for connected slides
                List <System.Guid>          guids           = new List <System.Guid>(); //empty list for guids
                GH.Kernel.IGH_Param         selSlidersInput = this.Params.Input[0];     //ref for input where sliders are connected to this component
                IList <GH.Kernel.IGH_Param> sources         = selSlidersInput.Sources;  //list of things connected on this input
                bool isAnythingConnected = sources.Any();                               //is there actually anything connected?


                // Find connected
                GH.Kernel.IGH_Param trigger = this.Params.Input[2].Sources[0]; //ref for input where a boolean or a button is connected
                GH.Kernel.Special.GH_BooleanToggle boolTrigger = trigger as GH.Kernel.Special.GH_BooleanToggle;

                if (isAnythingConnected)
                {                                                                                                    //if something's connected,
                    foreach (var source in sources)                                                                  //for each of these connected things:
                    {
                        IGH_DocumentObject component = source.Attributes.GetTopLevel.DocObject;                      //for this connected thing, bring it into the code in a way where we can access its properties
                        GH.Kernel.Special.GH_NumberSlider mySlider = component as GH.Kernel.Special.GH_NumberSlider; //...then cast (?) it as a slider
                        if (mySlider == null)                                                                        //of course, if the thing isn't a slider, the cast doesn't work, so we get null. let's filter out the nulls
                        {
                            continue;
                        }
                        guids.Add(mySlider.InstanceGuid); //things left over are sliders and are connected to our input. save this guid.
                                                          //we now have a list of guids of sliders connected to our input, saved in list var 'mySlider'
                    }
                }

                // Find all sliders.
                List <GH.Kernel.Special.GH_NumberSlider> sliders = new List <GH.Kernel.Special.GH_NumberSlider>();
                foreach (IGH_DocumentObject docObject in doc.Objects)
                {
                    GH.Kernel.Special.GH_NumberSlider slider = docObject as GH.Kernel.Special.GH_NumberSlider;
                    if (slider != null)
                    {
                        // check if the slider is in the selected list
                        if (isAnythingConnected)
                        {
                            if (guids.Contains(slider.InstanceGuid))
                            {
                                sliders.Add(slider);
                            }
                        }
                        else
                        {
                            sliders.Add(slider);
                        }
                    }
                }
                if (sliders.Count == 0)
                {
                    System.Windows.Forms.MessageBox.Show("No sliders could be found", "<harsh buzzing sound>", MessageBoxButtons.OK);
                    return;
                }

                //we now have all sliders
                //ask the user to give a sanity check


                string popupMessage = "";


                int dummyCounter = 0;
                foreach (GH_NumberSlider slider in sliders)
                {
                    totalLoops   *= (sliderSteps[dummyCounter]);
                    popupMessage += slider.ImpliedNickName;
                    popupMessage += "\n";
                    dummyCounter++;
                }
                if (MessageBox.Show(sliders.Count + " slider(s) connected:\n" + popupMessage +
                                    "\n" + totalLoops.ToString() + " iterations will be done. Continue?" + "\n\n (Press ESC to pause during progressing!)", "Start?", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    SetBooleanToFalse(boolTrigger);
                    this.Message = "Release the Colibri!";

                    //wipe out colibri variables and compute a new solution
                    sliderNames          = null;
                    sliderSteps          = null;
                    sliderStepsPositions = new int[sliderNames.Count];
                    //computedValues = new List<string>();
                    e.Document.NewSolution(false);
                    Rhino.RhinoDoc.ActiveDoc.Views.Redraw();

                    return;
                }

                // Set all sliders back to first tick
                foreach (GH_NumberSlider slider in sliders)
                {
                    slider.TickValue = 0;
                }

                //start a stopwatch
                System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();

                // Start a giant loop in which we'll permutate our way across all slider layouts.
                RunPermutations(sliderSteps, boolTrigger, sliders, e);
            }
            catch (Exception ex)
            {
                // "something went wrong!";
            }
            finally
            {
                // Always make sure that _running is switched off.
                _running = false;
            }
        }
Пример #18
0
 void ActiveDefinition_SolutionEnd(object sender, GH_SolutionEventArgs e)
 {
     RebuildPrimitives = 1;
     Revit.RefreshActiveView();
 }
Пример #19
0
 private void WireConnectRenderItem_SolutionEnd(object sender, GH_SolutionEventArgs e)
 {
     UpdateParamProxy();
 }
Пример #20
0
  private void OnSolutionEnd(object sender, GH_SolutionEventArgs e)
  {
    // Unregister the event, we don't want to get called again.
    e.Document.SolutionEnd -= OnSolutionEnd;

    // If we're not supposed to run, abort now.
    if (!_run)
      return;

    // If we're already running, abort now.
    if (_running)
      return;

    // Reset run and running states.
    _run = false;
    _running = true;

    try
    {
      // Find the Guid for connected slides
      List<System.Guid> guids = new List<System.Guid>(); //empty list for guids
      Grasshopper.Kernel.IGH_Param selSlidersInput = Component.Params.Input[0]; //ref for input where sliders are connected to this component
      IList<Grasshopper.Kernel.IGH_Param> sources = selSlidersInput.Sources; //list of things connected on this input
      bool isAnythingConnected = sources.Any(); //is there actually anything connected?


      // Find connected
      Grasshopper.Kernel.IGH_Param trigger = Component.Params.Input[1].Sources[0]; //ref for input where a boolean or a button is connected
      Grasshopper.Kernel.Special.GH_BooleanToggle boolTrigger = trigger as Grasshopper.Kernel.Special.GH_BooleanToggle;

      if (isAnythingConnected) { //if something's connected,
        foreach (var source in sources) //for each of these connected things:
        {
          IGH_DocumentObject component = source.Attributes.GetTopLevel.DocObject; //for this connected thing, bring it into the code in a way where we can access its properties
          Grasshopper.Kernel.Special.GH_NumberSlider mySlider = component as Grasshopper.Kernel.Special.GH_NumberSlider; //...then cast (?) it as a slider
          if (mySlider == null) //of course, if the thing isn't a slider, the cast doesn't work, so we get null. let's filter out the nulls
            continue;
          guids.Add(mySlider.InstanceGuid); //things left over are sliders and are connected to our input. save this guid.
          //we now have a list of guids of sliders connected to our input, saved in list var 'mySlider'
        }
      }

      // Find all sliders.
      List<Grasshopper.Kernel.Special.GH_NumberSlider> sliders = new List<Grasshopper.Kernel.Special.GH_NumberSlider>();
      foreach (IGH_DocumentObject docObject in GrasshopperDocument.Objects)
      {
        Grasshopper.Kernel.Special.GH_NumberSlider slider = docObject as Grasshopper.Kernel.Special.GH_NumberSlider;
        if (slider != null)
        {
          // check if the slider is in the selected list
          if (isAnythingConnected)
          {
            if (guids.Contains(slider.InstanceGuid)) sliders.Add(slider);
          }
          else sliders.Add(slider);
        }
      }
      if (sliders.Count == 0)
      {
        System.Windows.Forms.MessageBox.Show("No sliders could be found", "<harsh buzzing sound>", MessageBoxButtons.OK);
        return;
      }

      //we now have all sliders
      //ask the user to give a sanity check
      int counter = 0;
      int totalLoops = 1;
      string popupMessage = "";

      // create progress bar by dots and |
      string pb = ".................................................."; //50 of "." - There should be a better way to create this in C# > 50 * "." does it in Python!
      char[] pbChars = pb.ToCharArray();

      foreach(Grasshopper.Kernel.Special.GH_NumberSlider slider in sliders)
      {
        totalLoops *= (slider.TickCount + 1);
        popupMessage += slider.ImpliedNickName;
        popupMessage += "\n";
      }
      if (System.Windows.Forms.MessageBox.Show(sliders.Count + " slider(s) connected:\n" + popupMessage +
        "\n" + totalLoops.ToString() + " iterations will be done. Continue?"+ "\n\n (Press ESC to pause during progressing!)", "Start?", MessageBoxButtons.YesNo) == DialogResult.No)
      {
        SetBooleanToFalse(boolTrigger);
        Component.Message = "Release the fly!";
        return;
      }

      // Set all sliders back to first tick
      foreach (Grasshopper.Kernel.Special.GH_NumberSlider slider in sliders)
        slider.TickValue = 0;

      //start a stopwatch
      System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();

      // Start a giant loop in which we'll permutate our way across all slider layouts.
      while (true)
      {
        int idx = 0;

        // let the user cancel the process
        if (GH_Document.IsEscapeKeyDown())
        {
          if (System.Windows.Forms.MessageBox.Show("Do you want to stop the process?\nSo far " + counter.ToString() +
            " out of " + totalLoops.ToString() + " iterations are done!", "Stop?", MessageBoxButtons.YesNo) == DialogResult.Yes)
          {
            // cancel the process by user input!
            SetBooleanToFalse(boolTrigger);
            Component.Message += "\nCanceled by user! :|";
            return;
          }
        }

        if (!MoveToNextPermutation(ref idx, sliders))
        {
          // study is over!
          SetBooleanToFalse(boolTrigger);
          sw.Stop(); //stop start watch
          UpdateProgressBar(counter, totalLoops, sw, pbChars);
          Component.Message += "\nFinished at " + DateTime.Now.ToShortTimeString();
          break;
        }

        // We've just got a new valid permutation. Solve the new solution.
        counter++;
        e.Document.NewSolution(false);
        Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
        UpdateProgressBar(counter, totalLoops, sw, pbChars);
      }
    }
    catch {
      // "something went wrong!";
    }
    finally {
      // Always make sure that _running is switched off.
      _running = false;
    }
  }
Пример #21
0
 private void ActiveDefinition_SolutionEnd(object sender, GH_SolutionEventArgs e)
 {
     GhDrawingContext.NeedRedraw = true;
 }
 private void OnDocSolutionEnd(object sender, GH_SolutionEventArgs e)
 {
     if (m_document != null)
     m_document.Objects.Clear();
 }
 private void ActiveDefinition_SolutionEnd(object sender, GH_SolutionEventArgs e)
 {
     PlugIn.SetNeetRedraw();
 }
Пример #24
0
 private void Doc_SolutionEnd(object sender, GH_SolutionEventArgs e)
 {
 }
Пример #25
0
 void ActiveDefinition_SolutionEnd(object sender, GH_SolutionEventArgs e)
 {
     Clear();
     Revit.RefreshActiveView();
 }
Пример #26
0
 void AfterDocumentChanged(object sender, GH_SolutionEventArgs args)
 {
     if (this.Locked != m_locked)
       {
     m_locked = this.Locked;
     OnLockedChanged(m_locked);
       }
 }
Пример #27
0
 public void StartSolutionHandler(object o, GH_SolutionEventArgs e)
 {
     if (!InLoop)
     {
         Document.SolutionEnd -= StartSolutionHandler;
         Start();
     }
 }