Last active
April 29, 2024 06:42
-
-
Save schoeller/1d66ac531167b2d0db79001890d510ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import traceback | |
from pyrx_imp import Rx, Ge, Gi, Db, Ap, Ed, Cv | |
def PyRxCmd_pydebug() -> None: | |
import PyRxDebug | |
PyRxDebug.startListener() | |
drawProps = {'colorIndex': 255,'radius': 0.2} | |
def getIds(vAlignment): | |
try: | |
ids = [] | |
elementId = vAlignment.firstElementId() | |
while elementId != 0: | |
element = vAlignment.elementAtId(elementId) | |
if elementId != 0: | |
ids.append(elementId) | |
elementId = element.nextId() | |
return ids | |
except Exception as err: | |
traceback.print_exception(err) | |
def getElementPoints(valign,spt,ept): | |
try: | |
coords = [] | |
sdist = valign.getDistAtPoint(Ge.Point3d(spt.x,spt.y,0)) | |
edist = valign.getDistAtPoint(Ge.Point3d(ept.x,ept.y,0)) | |
dist = sdist | |
while dist < edist: | |
# print(dist) | |
pt = valign.getPointAtDist(dist) | |
coords.append([pt.x, pt.y]) | |
dist += (edist-sdist)/100 | |
return coords | |
except Exception as err: | |
traceback.print_exception(err) | |
def getVMaxPoint(valign,spt,ept): | |
try: | |
no = 100 | |
coords = [] | |
sdist = valign.getDistAtPoint(Ge.Point3d(spt.x,spt.y,0)) | |
edist = valign.getDistAtPoint(Ge.Point3d(ept.x,ept.y,0)) | |
dist = sdist | |
while dist < edist: | |
pt = valign.getPointAtDist(dist) | |
coords.append([pt.x, pt.y]) | |
dist += (edist-sdist)/no | |
x, ymax = max(coords, key=lambda x: (x[1])) | |
return Ge.Point3d(x,ymax,0) | |
except Exception as err: | |
traceback.print_exception(err) | |
def getVMinPoint(valign,spt,ept): | |
try: | |
no = 100 | |
coords = [] | |
sdist = valign.getDistAtPoint(Ge.Point3d(spt.x,spt.y,0)) | |
edist = valign.getDistAtPoint(Ge.Point3d(ept.x,ept.y,0)) | |
dist = sdist | |
while dist < edist: | |
pt = valign.getPointAtDist(dist) | |
coords.append([pt.x, pt.y]) | |
dist += (edist-sdist)/no | |
x, ymax = min(coords, key=lambda x: (x[1])) | |
return Ge.Point3d(x,ymax,0) | |
except Exception as err: | |
traceback.print_exception(err) | |
def getVMidPoint(valign,spt,ept): | |
try: | |
sdist = valign.getDistAtPoint(Ge.Point3d(spt.x,spt.y,0)) | |
edist = valign.getDistAtPoint(Ge.Point3d(ept.x,ept.y,0)) | |
pt = valign.getPointAtDist(((edist-sdist)/2)+sdist) | |
return pt | |
except Exception as err: | |
traceback.print_exception(err) | |
def generateCrestPVIPoints(point, scale): | |
try: | |
plist = [] | |
plist.append(Ge.Point2d(point.x, point.y)) # append top point | |
plist.append(Ge.Point2d(point.x - .1 * scale, point.y - .5 * scale)) # append bottom-left point | |
plist.append(Ge.Point2d(point.x + .1 * scale, point.y - .5 * scale)) # append bottom-right point | |
plist.append(Ge.Point2d(point.x, point.y)) # append top point | |
return plist | |
except Exception as err: | |
traceback.print_exception(err) | |
def generateSagPVIPoints(point, scale): | |
try: | |
plist = [] | |
plist.append(Ge.Point2d(point.x, point.y)) # append bottom point | |
plist.append(Ge.Point2d(point.x - .1 * scale, point.y + .5 * scale)) # append top-left point | |
plist.append(Ge.Point2d(point.x + .1 * scale, point.y + .5 * scale)) # append top-right point | |
plist.append(Ge.Point2d(point.x, point.y)) # append bottom point | |
return plist | |
except Exception as err: | |
traceback.print_exception(err) | |
def generateCrestGripPoints(point, scale): | |
try: | |
plist = [] | |
plist.append(Ge.Point3d(point.x, point.y, 0)) # append bottom point | |
plist.append(Ge.Point3d(point.x - .5 * scale, point.y + .5 * scale, 0)) # append top-left point | |
plist.append(Ge.Point3d(point.x + .5 * scale, point.y + .5 * scale, 0)) # append top-right point | |
plist.append(Ge.Point3d(point.x, point.y, 0)) # append bottom point | |
return plist | |
except Exception as err: | |
traceback.print_exception(err) | |
def generateSagGripPoints(point, scale): | |
try: | |
plist = [] | |
plist.append(Ge.Point3d(point.x, point.y, 0)) # append top point | |
plist.append(Ge.Point3d(point.x - .5 * scale, point.y - .5 * scale, 0)) # append bottom-left point | |
plist.append(Ge.Point3d(point.x + .5 * scale, point.y - .5 * scale, 0)) # append bottom-right point | |
plist.append(Ge.Point3d(point.x, point.y, 0)) # append top point | |
return plist | |
except Exception as err: | |
traceback.print_exception(err) | |
def generateCrestMidPoints(point, scale): | |
try: | |
plist = [] | |
plist.append(Ge.Point2d(point.x, point.y)) # append bottom point | |
plist.append(Ge.Point2d(point.x - .5 * scale, point.y + .5 * scale)) # append top-left point | |
plist.append(Ge.Point2d(point.x + .5 * scale, point.y + .5 * scale)) # append top-right point | |
plist.append(Ge.Point2d(point.x, point.y)) # append bottom point | |
return plist | |
except Exception as err: | |
traceback.print_exception(err) | |
def generateSagMidPoints(point, scale): | |
try: | |
plist = [] | |
plist.append(Ge.Point2d(point.x, point.y)) # append top point | |
plist.append(Ge.Point2d(point.x - .5 * scale, point.y - .5 * scale)) # append bottom-left point | |
plist.append(Ge.Point2d(point.x + .5 * scale, point.y - .5 * scale)) # append bottom-right point | |
plist.append(Ge.Point2d(point.x, point.y)) # append top point | |
return plist | |
except Exception as err: | |
traceback.print_exception(err) | |
def drawCrestGripLabel(vvorigin, point): | |
try: | |
plist = generateCrestGripPoints(point, 1) | |
# Ed.Core.grDrawPoly2d(plist, drawProps["colorIndex"]) | |
# Ed.Core.grDraw(plist[0], Ge.Point2d(plist[0].x, vvorigin.y), drawProps["colorIndex"], 0) | |
Ed.Core.grDrawArc(plist[1], plist[0], plist[2], 24, drawProps["colorIndex"]) | |
Ed.Core.grDraw(plist[1], plist[2], drawProps["colorIndex"], 0) | |
Ed.Core.grDraw(Ge.Point2d(plist[0].x, plist[0].y), Ge.Point2d(plist[0].x, vvorigin.y), drawProps["colorIndex"], 0) | |
except Exception as err: | |
traceback.print_exception(err) | |
def drawSagGripLabel(vvorigin, point): | |
try: | |
plist = generateSagGripPoints(point, 1) | |
Ed.Core.grDrawArc(plist[1], plist[0], plist[2], 24, drawProps["colorIndex"]) | |
Ed.Core.grDraw(plist[1], plist[2], drawProps["colorIndex"], 0) | |
Ed.Core.grDraw(Ge.Point2d(plist[0].x, plist[0].y), Ge.Point2d(plist[0].x, vvorigin.y), drawProps["colorIndex"], 0) | |
except Exception as err: | |
traceback.print_exception(err) | |
def drawCrestPVILabel(vvorigin, point): | |
try: | |
plist = generateCrestPVIPoints(point, 1) | |
Ed.Core.grDrawPoly2d(plist, drawProps["colorIndex"]) | |
Ed.Core.grDraw(plist[0], Ge.Point2d(plist[0].x, vvorigin.y), drawProps["colorIndex"], 0) | |
except Exception as err: | |
traceback.print_exception(err) | |
def drawSagPVILabel(vvorigin, point): | |
try: | |
plist = generateSagPVIPoints(point, 1) | |
Ed.Core.grDrawPoly2d(plist, drawProps["colorIndex"]) | |
Ed.Core.grDraw(plist[0], Ge.Point2d(plist[0].x, vvorigin.y), drawProps["colorIndex"], 0) | |
except Exception as err: | |
traceback.print_exception(err) | |
def drawCrestMPLabel(vvorigin, point): | |
try: | |
# drawing triangle | |
plist = generateCrestMidPoints(point, 1) | |
Ed.Core.grDrawPoly2d(plist, drawProps["colorIndex"]) | |
Ed.Core.grDraw(plist[0], Ge.Point2d(plist[0].x, vvorigin.y), drawProps["colorIndex"], 0) | |
# drawing circle | |
Ed.Core.grDrawCircle(point,drawProps["radius"],24,drawProps["colorIndex"]) | |
Ed.Core.grDraw(Ge.Point2d(point.x, point.y), Ge.Point2d(point.x, vvorigin.y), drawProps["colorIndex"], 0) | |
except Exception as err: | |
traceback.print_exception(err) | |
def drawSagMPLabel(vvorigin, point): | |
try: | |
# drawing triangle | |
plist = generateSagMidPoints(point, 1) | |
Ed.Core.grDrawPoly2d(plist, drawProps["colorIndex"]) | |
Ed.Core.grDraw(plist[0], Ge.Point2d(plist[0].x, vvorigin.y), drawProps["colorIndex"], 0) | |
# drawing circle | |
Ed.Core.grDrawCircle(point,drawProps["radius"],24,drawProps["colorIndex"]) | |
Ed.Core.grDraw(Ge.Point2d(point.x, point.y), Ge.Point2d(point.x, vvorigin.y), drawProps["colorIndex"], 0) | |
except Exception as err: | |
traceback.print_exception(err) | |
def annotateCrestCurve(curvedElement, verticalAlignment, verticalAlignmentView): | |
try: | |
#get the end point for this section | |
sp2d = curvedElement.startPoint() | |
ep2d = curvedElement.endPoint() | |
#get the vmax point | |
vmax = getVMaxPoint(verticalAlignment, sp2d, ep2d) | |
#get the mid point | |
vmid = getVMidPoint(verticalAlignment, sp2d, ep2d) | |
# transform the point from to WCS | |
vmax.x = verticalAlignmentView.toWCSX(vmax.x) | |
vmax.y = verticalAlignmentView.toWCSY(vmax.y) | |
sp2d.x = verticalAlignmentView.toWCSX(sp2d.x) | |
sp2d.y = verticalAlignmentView.toWCSY(sp2d.y) | |
ep2d.x = verticalAlignmentView.toWCSX(ep2d.x) | |
ep2d.y = verticalAlignmentView.toWCSY(ep2d.y) | |
vmid.x = verticalAlignmentView.toWCSX(vmid.x) | |
vmid.y = verticalAlignmentView.toWCSY(vmid.y) | |
# draw crest grip | |
drawCrestGripLabel(verticalAlignmentView.origin(), vmax) | |
# draw PVI grips | |
drawCrestPVILabel(verticalAlignmentView.origin(), sp2d) | |
drawCrestPVILabel(verticalAlignmentView.origin(), ep2d) | |
# draw mid grip | |
drawCrestMPLabel(verticalAlignmentView.origin(), vmid) | |
except Exception as err: | |
traceback.print_exception(err) | |
def annotateSagCurve(curvedElement, verticalAlignment, verticalAlignmentView): | |
try: | |
#get the end point for this section | |
sp2d = curvedElement.startPoint() | |
ep2d = curvedElement.endPoint() | |
#get the vmax point | |
vmin = getVMinPoint(verticalAlignment, sp2d, ep2d) | |
#get the mid point | |
vmid = getVMidPoint(verticalAlignment, sp2d, ep2d) | |
# transform the point from to WCS | |
vmin.x = verticalAlignmentView.toWCSX(vmin.x) | |
vmin.y = verticalAlignmentView.toWCSY(vmin.y) | |
sp2d.x = verticalAlignmentView.toWCSX(sp2d.x) | |
sp2d.y = verticalAlignmentView.toWCSY(sp2d.y) | |
ep2d.x = verticalAlignmentView.toWCSX(ep2d.x) | |
ep2d.y = verticalAlignmentView.toWCSY(ep2d.y) | |
vmid.x = verticalAlignmentView.toWCSX(vmid.x) | |
vmid.y = verticalAlignmentView.toWCSY(vmid.y) | |
# draw sag grip | |
drawSagGripLabel(verticalAlignmentView.origin(), vmin) | |
# draw PVI grips | |
drawSagPVILabel(verticalAlignmentView.origin(), sp2d) | |
drawSagPVILabel(verticalAlignmentView.origin(), ep2d) | |
# draw mid grip | |
drawSagMPLabel(verticalAlignmentView.origin(), vmid) | |
except Exception as err: | |
traceback.print_exception(err) | |
def PyRxCmd_cv_alignment_annotate(): | |
try: | |
#select the view, wee need this to transform | |
vsel = Ed.Editor.entSel("\nSelect vertical alignment view: ", Cv.CvDbVAlignmentView.desc()) | |
if vsel[0] != Ed.PromptStatus.eOk: | |
print("Oops {}: ".format(vsel[0])) | |
vAlignmentView = Cv.CvDbVAlignmentView(vsel[1], Db.OpenMode.kForRead) | |
# select the vAlignment | |
esel = Ed.Editor.entSel("\nSelect vertical alignment: ", Cv.CvDbVAlignment.desc()) | |
if esel[0] != Ed.PromptStatus.eOk: | |
print("Oops {}: ".format(esel[0])) | |
vAlignment = Cv.CvDbVAlignment(esel[1], Db.OpenMode.kForRead) | |
# get annotation scale setting | |
# db = Db.curDb() | |
# ctxman = db.objectContextManager() | |
# ctxcoll = ctxman.contextCollection("ACDB_ANNOTATIONSCALES") | |
# print(ctxcoll.toList()) | |
for id in getIds(vAlignment): | |
element = vAlignment.elementAtId(id) | |
# checking whether element is first/last and setting flag | |
if element.previousId(): | |
prevElement : Cv.CvDbVAlignmentElement = vAlignment.elementAtId(element.previousId()) | |
else: | |
prevElement = None | |
if element.nextId(): | |
nextElement : Cv.CvDbVAlignmentElement = vAlignment.elementAtId(element.nextId()) | |
else: | |
nextElement = None | |
match element.type(): | |
case Cv.VAlignmentElementType.eTangent: | |
# print("\nI'm a tangent") | |
tangent: Cv.CvDbVAlignmentTangent = Cv.CvDbVAlignmentTangent.cast(element) | |
case Cv.VAlignmentElementType.ePVI: | |
print("I'm a PVI") | |
pvi: Cv.CvDbVAlignmentPVI = Cv.CvDbVAlignmentPVI.cast(element) | |
case Cv.VAlignmentElementType.eArc: | |
print("I'm an arc") | |
arc: Cv.CvDbVAlignmentArc = Cv.CvDbVAlignmentArc.cast(element) | |
if arc.gradeIn() >= 0: #We'are risin | |
annotateCrestCurve(arc, vAlignment, vAlignmentView) | |
else: | |
annotateSagCurve(arc, vAlignment, vAlignmentView) | |
case Cv.VAlignmentElementType.eParabola: | |
print("I'm a parabola") | |
parabola: Cv.CvDbVAlignmentParabola = Cv.CvDbVAlignmentParabola.cast(element) | |
if parabola.gradeIn() >= 0: #We'are risin | |
annotateCrestCurve(parabola, vAlignment, vAlignmentView) | |
else: | |
annotateSagCurve(parabola, vAlignment, vAlignmentView) | |
case Cv.VAlignmentElementType.eUndefined: | |
print("I'm a undefined") | |
except Exception as err: | |
traceback.print_exception(err) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment