Exemplo n.º 1
0
        /// <summary>
        ///  Event of Nesting Finish, that make the process and paint the nested objects
        /// </summary>
        /// <param name="sender"> object: Support all classes in the .NET Framework class hierachy and provides low-level service to derived classes.</param>
        /// <param name="e"> RhinoNestEventArgs: Class used in events.</param>
        private void nesting_OnNestingFinish(object sender, EventArgs e)
        {
            //For the nested objects
            if (_nesting.NestingResult.NestedObjects != null)
            {
                var listguid = new List<Guid>();
                //creation and cleans for the var
                var objresult = _nesting.NestingResult.NestedObjects;
                var nestedGeometry2 = new RhinoNestObject[objresult.Count];
                var objtrans = new Transform[objresult.Count];

                //get the objects
                objresult.Keys.CopyTo(nestedGeometry2, 0);
                objresult.Values.CopyTo(objtrans, 0);

                var curves = new List<Curve>();
                //do the modify to every object (position and rotation) and add to the list of curves
                for (int i = 0; i < objresult.Count; i++)
                {
                    curves.Add(nestedGeometry2[i].ExternalCurve.DuplicateCurve());

                    foreach (var id in nestedGeometry2[i].SubObjectsIds)
                    {
                        listguid.Add(RhinoDoc.ActiveDoc.Objects.Transform(id, objtrans[i], false));
                    }

                    curves[i].Transform(objtrans[i]);

                    listguid.Add(RhinoDoc.ActiveDoc.Objects.AddCurve(curves[i]));
                }
                _mycurves.AddRange(listguid);
                //add every object to a buffer for put on the output
                _buffOut.Add(new List<RhinoNestObject>());
                for (int i = 0; i < objresult.Count; i++)
                {
                    _buffOut[_tryies].Add(new RhinoNestObject(curves[i]));
                }

                //create var for make the report
                var rnProject = new RhinoNestProject(_nesting.NestingResult, _sheets2);
                var objs = new List<Tuple<RhinoNestObject, Transform, List<Guid>>>();
                for (int i = 0; i < _nesting.NestingResult.NestedObjects.Count; i++)
                {
                    var guids = new List<Guid> { listguid[i] };
                    var tup = new Tuple<RhinoNestObject, Transform, List<Guid>>(nestedGeometry2[i], objtrans[i], guids);
                    objs.Add(tup);
                }

                _sheetsresults.Add(new RhinoNestSheetResult(rnProject, objs));

                //get the bound for print if it isn't the first sheet and print it  if is the first don't print the sheet
                var print = _sheets2.GetBounds();
                _mycurves.Add(RhinoDoc.ActiveDoc.Objects.AddPolyline(print));
                //add trie for the next time
                _tryies++;

                //redraw all
                RhinoDoc.ActiveDoc.Views.Redraw();
            }

            //if there is more object for nest
            if (_nesting.NestingResult.RemainingObjects.Any())
            {
                //get the remaining object and count how many is for nest
                var send = _nesting.NestingResult.RemainingObjects;
                Int32 count = 0;
                foreach (var item in send)
                {
                    count = count + item.Parameters.RemainingCopies;
                }

                //if have ramaining object to nest
                if (count > 0 && _buffold != count)
                {
                    _nonest.Clear();

                    _buffold = count;
                    _nonest.AddRange(send);

                    //move the sheet it's being used
                    _sheets2.NextPosition();

                    //renew the nesting
                    _nesting = new RhinoNestNesting(send, _sheets2, _parameters);

                    //delete the actual events
                    _nesting.OnNestingFinish -= nesting_OnNestingFinish;
                    _nesting.OnNestingProgressChange -= Nesting_OnNestingProgressChange;

                    //create the new events
                    _nesting.OnNestingFinish += nesting_OnNestingFinish;
                    _nesting.OnNestingProgressChange += Nesting_OnNestingProgressChange;

                    //start nasting again
                    _nesting.StartNesting();
                }
                else
                {
                    // if it's not item to nest then call to shedulesolution for the expire solution
                    _setOutput = true;
                    GH_Document doc = OnPingDocument();
                    if (doc != null)
                    {
                        doc.ScheduleSolution(1, MyCallback);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///  Event of Nesting Finish, that make the process and paint the nested objects
        /// </summary>
        /// <param name="sender"> object: Support all classes in the .NET Framework class hierachy and provides low-level service to derived classes.</param>
        /// <param name="e"> RhinoNestEventArgs: Class used in events.</param>
        private void nesting_OnNestingFinish(object sender, EventArgs e)
        {
            //For the nested objects
            if (_nesting.NestingResult.NestedObjects != null)
            {
                var listguid = new List <Guid>();
                //creation and cleans for the var
                var objresult       = _nesting.NestingResult.NestedObjects;
                var nestedGeometry2 = new RhinoNestObject[objresult.Count];
                var objtrans        = new Transform[objresult.Count];

                //get the objects
                objresult.Keys.CopyTo(nestedGeometry2, 0);
                objresult.Values.CopyTo(objtrans, 0);

                var curves = new List <Curve>();
                //do the modify to every object (position and rotation) and add to the list of curves
                for (int i = 0; i < objresult.Count; i++)
                {
                    curves.Add(nestedGeometry2[i].ExternalCurve.DuplicateCurve());

                    foreach (var id in nestedGeometry2[i].SubObjectsIds)
                    {
                        listguid.Add(RhinoDoc.ActiveDoc.Objects.Transform(id, objtrans[i], false));
                    }

                    curves[i].Transform(objtrans[i]);

                    listguid.Add(RhinoDoc.ActiveDoc.Objects.AddCurve(curves[i]));
                }
                _mycurves.AddRange(listguid);
                //add every object to a buffer for put on the output
                _buffOut.Add(new List <RhinoNestObject>());
                for (int i = 0; i < objresult.Count; i++)
                {
                    _buffOut[_tryies].Add(new RhinoNestObject(curves[i]));
                }

                //create var for make the report
                var rnProject = new RhinoNestProject(_nesting.NestingResult, _sheets2);
                var objs      = new List <Tuple <RhinoNestObject, Transform, List <Guid> > >();
                for (int i = 0; i < _nesting.NestingResult.NestedObjects.Count; i++)
                {
                    var guids = new List <Guid> {
                        listguid[i]
                    };
                    var tup = new Tuple <RhinoNestObject, Transform, List <Guid> >(nestedGeometry2[i], objtrans[i], guids);
                    objs.Add(tup);
                }

                _sheetsresults.Add(new RhinoNestSheetResult(rnProject, objs));

                //get the bound for print if it isn't the first sheet and print it  if is the first don't print the sheet
                var print = _sheets2.GetBounds();
                _mycurves.Add(RhinoDoc.ActiveDoc.Objects.AddPolyline(print));
                //add trie for the next time
                _tryies++;

                //redraw all
                RhinoDoc.ActiveDoc.Views.Redraw();
            }

            //if there is more object for nest
            if (_nesting.NestingResult.RemainingObjects.Any())
            {
                //get the remaining object and count how many is for nest
                var   send  = _nesting.NestingResult.RemainingObjects;
                Int32 count = 0;
                foreach (var item in send)
                {
                    count = count + item.Parameters.RemainingCopies;
                }

                //if have ramaining object to nest
                if (count > 0 && _buffold != count)
                {
                    _nonest.Clear();

                    _buffold = count;
                    _nonest.AddRange(send);

                    //move the sheet it's being used
                    _sheets2.NextPosition();

                    //renew the nesting
                    _nesting = new RhinoNestNesting(send, _sheets2, _parameters);

                    //delete the actual events
                    _nesting.OnNestingFinish         -= nesting_OnNestingFinish;
                    _nesting.OnNestingProgressChange -= Nesting_OnNestingProgressChange;

                    //create the new events
                    _nesting.OnNestingFinish         += nesting_OnNestingFinish;
                    _nesting.OnNestingProgressChange += Nesting_OnNestingProgressChange;

                    //start nasting again
                    _nesting.StartNesting();
                }
                else
                {
                    // if it's not item to nest then call to shedulesolution for the expire solution
                    _setOutput = true;
                    GH_Document doc = OnPingDocument();
                    if (doc != null)
                    {
                        doc.ScheduleSolution(1, MyCallback);
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="da">IGH_DataAccess: The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess da)
        {
            // _setOutput put var to the exit
            if (_setOutput)
            {
                for (int a = _buffOut.Count - 1; a > 0; a--)
                {
                    if (_buffOut[a].Count == 0)
                        _buffOut.RemoveAt(a);
                }

                da.SetDataList(0, _buffOut);
                da.SetDataList(1, _nonest);
                da.SetDataList(2, _sheetsresults);

                _setOutput = false;
                IsWorking = false;
                _mSolveme = false;
            }

            //if the user doesn't make a double click force out
            if (!_mSolveme)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Double click me to start solving");
                _mSolveme = false;
                return;
            }

            //if the user does the double ckcik start getting var
            if (!IsWorking)
            {
                //if have curves delete all
                if (_mycurves.Count > 0)
                {
                    foreach (Guid t in _mycurves)
                    {
                        RhinoDoc.ActiveDoc.Objects.Delete(t, true);
                    }
                    RhinoDoc.ActiveDoc.Views.Redraw();
                }
                _sheetsresults = new List<RhinoNestSheetResult>();
                //cleaning the var
                IsWorking = true;
                var sheets = new RhinoNestSheet();
                _parameters = new RhinoNestKernel.Nesting.RhinoNestNestingParameters();
                var _object = new List<RhinoNestObject>();
                _buffold = 0;
                _tryies = 0;
                _nonest.Clear();

                for (int i = 0; i < _buffOut.Count; i++)
                    _buffOut.RemoveAt(i);

                //getting var
                if (!da.GetDataList(0, _object)) return;
                if (!da.GetData(1, ref sheets)) return;
                if (!da.GetData(2, ref _parameters)) return;

                //saving thats
                _sheets2 = new RhinoNestSheet(sheets);

                //duplicate the list
                var send = new List<RhinoNestObject>();
                _object.ForEach(item => send.Add(new RhinoNestObject(item)));

                //declaring nesting
                _nesting = new RhinoNestNesting(send, sheets, _parameters);

                //active the Flag for the event for finish and other for progress
                _nesting.OnNestingFinish += nesting_OnNestingFinish;
                _nesting.OnNestingProgressChange += Nesting_OnNestingProgressChange;

                //start nesting
                _nesting.StartNesting();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="da">IGH_DataAccess: The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess da)
        {
            // _setOutput put var to the exit
            if (_setOutput)
            {
                for (int a = _buffOut.Count - 1; a > 0; a--)
                {
                    if (_buffOut[a].Count == 0)
                    {
                        _buffOut.RemoveAt(a);
                    }
                }

                da.SetDataList(0, _buffOut);
                da.SetDataList(1, _nonest);
                da.SetDataList(2, _sheetsresults);

                _setOutput = false;
                IsWorking  = false;
                _mSolveme  = false;
            }

            //if the user doesn't make a double click force out
            if (!_mSolveme)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Double click me to start solving");
                _mSolveme = false;
                return;
            }

            //if the user does the double ckcik start getting var
            if (!IsWorking)
            {
                //if have curves delete all
                if (_mycurves.Count > 0)
                {
                    foreach (Guid t in _mycurves)
                    {
                        RhinoDoc.ActiveDoc.Objects.Delete(t, true);
                    }
                    RhinoDoc.ActiveDoc.Views.Redraw();
                }
                _sheetsresults = new List <RhinoNestSheetResult>();
                //cleaning the var
                IsWorking = true;
                var sheets = new RhinoNestSheet();
                _parameters = new RhinoNestKernel.Nesting.RhinoNestNestingParameters();
                var _object = new List <RhinoNestObject>();
                _buffold = 0;
                _tryies  = 0;
                _nonest.Clear();

                for (int i = 0; i < _buffOut.Count; i++)
                {
                    _buffOut.RemoveAt(i);
                }

                //getting var
                if (!da.GetDataList(0, _object))
                {
                    return;
                }
                if (!da.GetData(1, ref sheets))
                {
                    return;
                }
                if (!da.GetData(2, ref _parameters))
                {
                    return;
                }

                //saving thats
                _sheets2 = new RhinoNestSheet(sheets);

                //duplicate the list
                var send = new List <RhinoNestObject>();
                _object.ForEach(item => send.Add(new RhinoNestObject(item)));

                //declaring nesting
                _nesting = new RhinoNestNesting(send, sheets, _parameters);

                //active the Flag for the event for finish and other for progress
                _nesting.OnNestingFinish         += nesting_OnNestingFinish;
                _nesting.OnNestingProgressChange += Nesting_OnNestingProgressChange;

                //start nesting
                _nesting.StartNesting();
            }
        }