|
| 1 | +# Grasshopper Module Version 0.0.1.5 |
| 2 | +# Developed by Mahmoud Abdelrahman |
| 3 | + |
| 4 | +""" |
| 5 | +This Module is part of GH_CPython |
| 6 | +BSD 2-Clause License |
| 7 | +
|
| 8 | +This project has been started by: Mahmoud M. Abdelrahman |
| 9 | +<arch.mahmoud.ouf111[at]gmail.com> |
| 10 | +Copyright (c) 2017, Mahmoud AbdelRahman |
| 11 | +
|
| 12 | +All rights reserved. |
| 13 | +https://github.com/MahmoudAbdelRahman/GH_CPython/blob/master/LICENSE |
| 14 | +""" |
| 15 | +import sys |
| 16 | + |
| 17 | +version = sys.version_info[0] |
| 18 | + |
| 19 | + |
| 20 | +class Line: |
| 21 | + def __init__(self, *args): |
| 22 | + """Adds new line using two input points, or two input lists or 6 input doubles |
| 23 | +
|
| 24 | + :param args: |
| 25 | + """ |
| 26 | + if len(args) == 2: |
| 27 | + if isinstance(args[0], Point) and isinstance(args[1], Point): |
| 28 | + self.X1 = args[0].X |
| 29 | + self.Y1 = args[0].Y |
| 30 | + self.Z1 = args[0].X |
| 31 | + self.X2 = args[1].Z |
| 32 | + self.Y2 = args[1].Y |
| 33 | + self.Z2 = args[1].Z |
| 34 | + elif isinstance(args[0], list) and isinstance(args[1], list): |
| 35 | + self.X1 = args[0][0] |
| 36 | + self.Y1 = args[0][1] |
| 37 | + self.Z1 = args[0][2] |
| 38 | + self.X2 = args[1][0] |
| 39 | + self.Y2 = args[1][1] |
| 40 | + self.Z2 = args[1][2] |
| 41 | + elif version == 2: |
| 42 | + if isinstance(args[0], basestring) and isinstance(args[1], basestring): |
| 43 | + pointa = Point(args[0]) |
| 44 | + pointb = Point(args[1]) |
| 45 | + self.X1 = pointa.X |
| 46 | + self.Y1 = pointa.Y |
| 47 | + self.Z1 = pointa.Z |
| 48 | + self.X2 = pointb.X |
| 49 | + self.Y2 = pointb.Y |
| 50 | + self.Z2 = pointb.Z |
| 51 | + elif version == 3: |
| 52 | + if isinstance(args[0], str) and isinstance(args[1], str): |
| 53 | + pointa = Point(args[0]) |
| 54 | + pointb = Point(args[1]) |
| 55 | + self.X1 = pointa.X |
| 56 | + self.Y1 = pointa.Y |
| 57 | + self.Z1 = pointa.Z |
| 58 | + self.X2 = pointb.X |
| 59 | + self.Y2 = pointb.Y |
| 60 | + self.Z2 = pointb.Z |
| 61 | + elif len(args) == 6: |
| 62 | + self.X1 = args[0] |
| 63 | + self.Y1 = args[1] |
| 64 | + self.Z1 = args[2] |
| 65 | + self.X2 = args[3] |
| 66 | + self.Y2 = args[4] |
| 67 | + self.Z2 = args[5] |
| 68 | + |
| 69 | + '''def addLine(self): |
| 70 | + return "gCPy.Line(" + str(self.X1) + ", " \ |
| 71 | + + str(self.Y1) + ", " \ |
| 72 | + + str(self.Z1) + ", " \ |
| 73 | + + str(self.X2) + ", " \ |
| 74 | + + str(self.Y2) + ", " \ |
| 75 | + + str(self.Z2) + ")"''' |
| 76 | + |
| 77 | + def addLine(self): |
| 78 | + return ["<Line>", self.X1, self.Y1, self.Z1, self.X2, self.Y2, self.Z2] |
| 79 | + |
| 80 | + def __repr__(self): |
| 81 | + return str(["<Line>",self.X1,self.Y1,self.Z1,self.X2,self.Y2,self.Z2,"</line>"]) |
| 82 | + |
| 83 | + def length(self): |
| 84 | + return ((self.X2 - self.X1) ** 2 + (self.Y2 - self.Y1) ** 2 + (self.Z2 - self.Z1) ** 2) ** 0.5 |
| 85 | + |
| 86 | + def pointOnLine(self, parameter=0.5): |
| 87 | + return Point((self.X2 - self.X1) * parameter + self.X1, \ |
| 88 | + (self.Y2 - self.Y1) * parameter + self.Y1, \ |
| 89 | + (self.Z2 - self.Z1) * parameter + self.Z1) |
| 90 | + |
| 91 | + def __str__(self): |
| 92 | + return str(["<Line>", self.X1, self.Y1, self.Z1, self.X2, self.Y2, self.Z2, "</Line>"]) |
| 93 | + |
| 94 | + |
| 95 | +class Point: |
| 96 | + """Adds new point in cartesian coordinates using 3 doubles x, y, z as input |
| 97 | +
|
| 98 | + :param: |
| 99 | + x (double): is the x coordinate |
| 100 | + y (double): is the y coordinate |
| 101 | + z (double): is the z coordinate |
| 102 | + :return: |
| 103 | + representation of 3d point |
| 104 | + :Example: |
| 105 | + import Grasshopper as gh |
| 106 | + point1 = gh.Point(0, 0, 0) |
| 107 | + point2 = gh.Point(1., 1., 0.) |
| 108 | + """ |
| 109 | + |
| 110 | + def __init__(self, x=0., y=0., z=0.): |
| 111 | + if version == 2: |
| 112 | + if isinstance(x, list): |
| 113 | + self.X = x[0] |
| 114 | + self.Y = x[1] |
| 115 | + self.Z = x[2] |
| 116 | + self.repr = ['<Point>', x[0], x[1], x[2], '</Point>'] |
| 117 | + else: |
| 118 | + self.X = x |
| 119 | + self.Y = y |
| 120 | + self.Z = z |
| 121 | + self.repr = ['<Point>', x, y, z, '</Point>'] |
| 122 | + |
| 123 | + def __repr__(self): |
| 124 | + return str(self.repr) |
| 125 | + |
| 126 | + def __str__(self): |
| 127 | + return str(self.repr) |
| 128 | + |
| 129 | + |
| 130 | +class Surface: |
| 131 | + """ |
| 132 | +
|
| 133 | + """ |
| 134 | + def __init__(self, *args): |
| 135 | + if len(args) == 4: |
| 136 | + if isinstance(args[0], Point) and isinstance(args[1], Point) and isinstance(args[2], Point) and isinstance(args[3], Point): |
| 137 | + self.P1 = args[0] |
| 138 | + self.P2 = args[1] |
| 139 | + self.P3 = args[2] |
| 140 | + self.P4 = args[3] |
| 141 | + self.addSurface = "gCPy.Surface("+ str(args[0].X) + "," \ |
| 142 | + + str(args[0].Y) + "," \ |
| 143 | + + str(args[0].Z) + "," \ |
| 144 | + + str(args[1].X) + "," \ |
| 145 | + + str(args[1].Y) + "," \ |
| 146 | + + str(args[1].Z) + "," \ |
| 147 | + + str(args[2].X) + "," \ |
| 148 | + + str(args[2].Y) + "," \ |
| 149 | + + str(args[2].Z) + "," \ |
| 150 | + + str(args[3].X) + "," \ |
| 151 | + + str(args[3].Y) + "," \ |
| 152 | + + str(args[3].Z) + "," \ |
| 153 | + + ")" |
| 154 | + elif len(args) == 2: |
| 155 | + if isinstance(args[0],Line) and isinstance(args[1], Line): |
| 156 | + pass |
| 157 | + else: |
| 158 | + print "you have to create surface from 4 points" |
| 159 | + |
| 160 | + |
| 161 | +class Curve: |
| 162 | + """ |
| 163 | + Adds new curve object |
| 164 | + """ |
| 165 | + def __init__(self, *args): |
| 166 | + if args[0] == '<Curve>' and args[-1] == '</Curve>': |
| 167 | + if args[1] == 'AddArc': self.repr = ['<Curve>', 'AddArc', args[2], args[3], args[4], args[5]] |
| 168 | + elif args[1] == 'AddArc3Pt': self.repr = ['<Curve>', 'AddArc3Pt', args[2], args[3], args[4], args[5]] |
| 169 | + elif args[1] == 'AddArcPtTanPt':self.repr = ['<Curve>', 'AddArc3Pt', args[2], args[3], args[4], args[5]] |
| 170 | + elif args[1] == 'AddBlendCurve': |
| 171 | + pass |
| 172 | + elif args[1] == 'AddCircle': |
| 173 | + pass |
| 174 | + elif args[1] == 'AddCircle3Pt': |
| 175 | + pass |
| 176 | + elif args[1] == 'AddCurve': |
| 177 | + pass |
| 178 | + elif args[1] == 'AddEllipse': |
| 179 | + pass |
| 180 | + elif args[1] == 'AddEllipse3Pt': |
| 181 | + pass |
| 182 | + elif args[1] == 'AddFilletCurve': |
| 183 | + pass |
| 184 | + elif args[1] == 'AddInterpCrvOnSrf': |
| 185 | + pass |
| 186 | + elif args[1] == 'AddInterpCrvOnSrfUV': |
| 187 | + pass |
| 188 | + elif args[1] == 'AddInterpCurve': |
| 189 | + pass |
| 190 | + elif args[1] == 'AddLine': |
| 191 | + pass |
| 192 | + elif args[1] == 'AddNurbsCurve': |
| 193 | + pass |
| 194 | + elif args[1] == 'AddPolyline': |
| 195 | + pass |
| 196 | + elif args[1] == 'AddRectangle': |
| 197 | + pass |
| 198 | + elif args[1] == 'AddSpiral': |
| 199 | + pass |
| 200 | + elif args[1] == 'AddSubCrv': |
| 201 | + pass |
| 202 | + elif args[1] == 'CloseCurve': |
| 203 | + pass |
| 204 | + elif args[1] == 'ConvertCurveToPolyline': |
| 205 | + pass |
| 206 | + elif args[1] == 'CurveBooleanDifference': |
| 207 | + pass |
| 208 | + elif args[1] == 'CurveBooleanIntersection': |
| 209 | + pass |
| 210 | + elif args[1] == 'CurveBooleanUnion': |
| 211 | + pass |
| 212 | + elif args[1] == 'ExplodeCurves': |
| 213 | + pass |
| 214 | + elif args[1] == 'ExtendCurve': |
| 215 | + pass |
| 216 | + elif args[1] == 'ExtendCurveLength': |
| 217 | + pass |
| 218 | + elif args[1] == 'ExtendCurvePoint': |
| 219 | + pass |
| 220 | + elif args[1] == 'FitCurve': |
| 221 | + pass |
| 222 | + elif args[1] == 'JoinCurves': |
| 223 | + pass |
| 224 | + elif args[1] == 'MakeCurveNonPeriodic': |
| 225 | + pass |
| 226 | + elif args[1] == 'MeanCurve': |
| 227 | + pass |
| 228 | + elif args[1] == 'OffsetCurve': |
| 229 | + pass |
| 230 | + elif args[1] == 'OffsetCurveOnSurface': |
| 231 | + pass |
| 232 | + elif args[1] == 'ProjectCurveToMesh': |
| 233 | + pass |
| 234 | + elif args[1] == 'ProjectCurveToSurface': |
| 235 | + pass |
| 236 | + elif args[1] == 'SimplifyCurve': |
| 237 | + pass |
| 238 | + elif args[1] == 'SplitCurve': |
| 239 | + pass |
| 240 | + elif args[1] == 'TrimCurve': |
| 241 | + pass |
| 242 | + else: |
| 243 | + self.text = "Curve of other Type" |
| 244 | + else: |
| 245 | + self.text = "Pring me here" |
| 246 | + |
| 247 | + def __repr__(self): |
| 248 | + return str(self.repr) |
| 249 | + |
| 250 | + def __str__(self): |
| 251 | + return str(self.repr) |
| 252 | + |
| 253 | + |
| 254 | +class Plane: |
| 255 | + pass |
| 256 | + |
| 257 | + |
| 258 | +class Vector: |
| 259 | + pass |
| 260 | + |
| 261 | + |
| 262 | +class Mesh: |
| 263 | + pass |
| 264 | + |
| 265 | + |
| 266 | +if __name__ == '__main__': |
| 267 | + print __name__ |
0 commit comments