Esempio 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);
                    }
                }
            }
        }
Esempio 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);
                    }
                }
            }
        }