/*******************************************/ public static bool CastToGoo(object value, ref IGH_QuickCast target) { try { if (value is bool) { target = new GH_Boolean((bool)value); } else if (value is Color) { target = new GH_Colour((Color)value); } else if (value is Complex) { target = new GH_ComplexNumber((Complex)value); } else if (value is int) { target = new GH_Integer((int)value); } else if (value is Interval) { target = new GH_Interval((Interval)value); } else if (value is Matrix) { target = new GH_Matrix((Matrix)value); } else if (value is double || value is float) { target = new GH_Number((double)value); } else if (value is Point3d) { target = new GH_Point((Point3d)value); } else if (value is string) { target = new GH_String(value.ToString()); } else if (value is Vector3d) { target = new GH_Vector((Vector3d)value); } return(true); } catch { return(false); } }
private List <GH_Interval> iniDomains(List <GH_Interval> oldDomains, GH_Interval totalDomain) { var domains = new List <GH_Interval>(); var checkedOldDomain = trimDomains(oldDomains, totalDomain); if (checkedOldDomain.IsNullOrEmpty()) { domains.Add(totalDomain); } else { domains = checkedOldDomain; } return(domains); }
private List <GH_Interval> trimDomains(List <GH_Interval> oldDomains, GH_Interval totalDomain) { if (oldDomains.IsNullOrEmpty()) { return(null); } var newDomains = new List <GH_Interval>(); foreach (var item in oldDomains) { double min = 0; double max = 0; //Check the T0 side if (item.Value.Min < 0) { min = 0; } else { min = item.Value.Min; } //Check the T1 side if (item.Value.Max > totalDomain.Value.Max) { max = totalDomain.Value.Max; } else { max = item.Value.Max; } var newIterval = new Interval(min, max); if (totalDomain.Value.IncludesInterval(newIterval)) { newDomains.Add(new GH_Interval(newIterval)); } } return(newDomains); }
//Method public void MatchSelectionFrom(List <ColibriParam> ColibriParams) { this.TotalCounts = ColibriBase.CalTotalCounts(ColibriParams); this._totalDomain = new GH_Interval(new Interval(0, this.TotalCounts - 1)); this._paramNames = ColibriBase.getAllNames(ColibriParams); this._paramsPositions = ColibriBase.AllParamsPositions(ColibriParams); this._paramsDivisionNumbers = iniTakeNumbers(this._userParamsTakeNumbers, ColibriParams); //_paramsSelectedPositions is used to fly params this._paramsSelectedPositions = calParamsSelectedPositions(this._paramsPositions, this._paramsDivisionNumbers, ColibriParams); var selectedPositionCounts = calSelectedPositionsCount(this._paramsSelectedPositions); var selectedTotalDomain = new GH_Interval(new Interval(0, selectedPositionCounts - 1)); //_domains is used to fly params this._domains = iniDomains(this._userDomains, selectedTotalDomain); this.SelectedCounts = calSelectedTotalCount(this._domains, selectedPositionCounts); }
/// <summary> /// Determines object type and calls the appropriate conversion call. /// </summary> /// <param name="o">Object to convert.</param> /// <param name="getEncoded">If set to true, will return a base64 encoded value of more complex objects (ie, breps).</param> /// <returns></returns> private static SpeckleObject fromGhRhObject(object o, bool getEncoded = false, bool getAbstract = true) { GH_Interval int1d = o as GH_Interval; if (int1d != null) { return(GhRhConveter.fromInterval(int1d.Value)); } if (o is Interval) { return(GhRhConveter.fromInterval((Interval)o)); } GH_Interval2D int2d = o as GH_Interval2D; if (int2d != null) { return(GhRhConveter.fromInterval2d(int2d.Value)); } if (o is UVInterval) { return(GhRhConveter.fromInterval2d((UVInterval)o)); } // basic stuff GH_Number num = o as GH_Number; if (num != null) { return(SpeckleConverter.fromNumber(num.Value)); } if (o is double || o is int) { return(SpeckleConverter.fromNumber((double)o)); } GH_Boolean bul = o as GH_Boolean; if (bul != null) { return(SpeckleConverter.fromBoolean(bul.Value)); } if (o is Boolean) { return(GhRhConveter.fromBoolean((bool)o)); } GH_String str = o as GH_String; if (str != null) { return(SpeckleConverter.fromString(str.Value)); } if (o is string) { return(SpeckleConverter.fromString((string)o)); } // simple geometry GH_Point point = o as GH_Point; if (point != null) { return(GhRhConveter.fromPoint(point.Value)); } if (o is Point3d) { return(GhRhConveter.fromPoint((Point3d)o)); } // added because when we assign user data to points they get converted to points. // the above comment does makes sense. check the sdk. if (o is Rhino.Geometry.Point) { return(GhRhConveter.fromPoint(((Rhino.Geometry.Point)o).Location)); } GH_Vector vector = o as GH_Vector; if (vector != null) { return(GhRhConveter.fromVector(vector.Value)); } if (o is Vector3d) { return(GhRhConveter.fromVector((Vector3d)o)); } GH_Plane plane = o as GH_Plane; if (plane != null) { return(GhRhConveter.fromPlane(plane.Value)); } if (o is Plane) { return(GhRhConveter.fromPlane((Plane)o)); } GH_Line line = o as GH_Line; if (line != null) { return(GhRhConveter.fromLine(line.Value)); } if (o is Line) { return(GhRhConveter.fromLine((Line)o)); } GH_Arc arc = o as GH_Arc; if (arc != null) { return(GhRhConveter.fromArc(arc.Value)); } if (o is Arc) { return(GhRhConveter.fromArc((Arc)o)); } GH_Circle circle = o as GH_Circle; if (circle != null) { return(GhRhConveter.fromCircle(circle.Value)); } if (o is Circle) { return(GhRhConveter.fromCircle((Circle)o)); } GH_Rectangle rectangle = o as GH_Rectangle; if (rectangle != null) { return(GhRhConveter.fromRectangle(rectangle.Value)); } if (o is Rectangle3d) { return(GhRhConveter.fromRectangle((Rectangle3d)o)); } GH_Box box = o as GH_Box; if (box != null) { return(GhRhConveter.fromBox(box.Value)); } if (o is Box) { return(GhRhConveter.fromBox((Box)o)); } // getting complex GH_Curve curve = o as GH_Curve; if (curve != null) { Polyline poly; if (curve.Value.TryGetPolyline(out poly)) { return(GhRhConveter.fromPolyline(poly)); } return(GhRhConveter.fromCurve(curve.Value, getEncoded, getAbstract)); } if (o is Polyline) { return(GhRhConveter.fromPolyline((Polyline)o)); } if (o is Curve) { return(GhRhConveter.fromCurve((Curve)o, getEncoded, getAbstract)); } GH_Surface surface = o as GH_Surface; if (surface != null) { return(GhRhConveter.fromBrep(surface.Value, getEncoded, getAbstract)); } GH_Brep brep = o as GH_Brep; if (brep != null) { return(GhRhConveter.fromBrep(brep.Value, getEncoded, getAbstract)); } if (o is Brep) { return(GhRhConveter.fromBrep((Brep)o, getEncoded, getAbstract)); } GH_Mesh mesh = o as GH_Mesh; if (mesh != null) { return(GhRhConveter.fromMesh(mesh.Value)); } if (o is Mesh) { return(GhRhConveter.fromMesh((Mesh)o)); } return(new SpeckleObject() { hash = "404", value = "Type not supported", type = "404" }); }
/*******************************************/ public static bool CastToGoo(object value, ref GH_Interval target) { return(GH_Convert.ToGHInterval(value, GH_Conversion.Both, ref target)); }