# - text2D (pyTree) - import Geom.PyTree as D import Converter.PyTree as C a = D.text2D("Cassiopee") C.convertPyTree2File(a, 'out.cgns')
def replaceText(event=None): if CTK.t == []: return if CTK.__MAINTREE__ <= 0: CTK.TXT.insert('START', 'Fail on a temporary tree.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return CTK.saveTree() # Recupere l'OBB de la selection Z = [] dels = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] Z.append(CTK.t[2][nob][2][noz]) dels.append(CTK.t[2][nob][0] + Internal.SEP1 + CTK.t[2][nob][2][noz][0]) nob0 = CTK.Nb[nzs[0]] + 1 try: a = T.join(Z) except: a = Z[0] OBB = G.BB(a, method='OBB') P0 = C.getValue(OBB, 'GridCoordinates', 0) P1 = C.getValue(OBB, 'GridCoordinates', 1) P2 = C.getValue(OBB, 'GridCoordinates', 2) P3 = C.getValue(OBB, 'GridCoordinates', 4) v1 = Vector.sub(P1, P0) n1 = Vector.norm(v1) v2 = Vector.sub(P2, P0) n2 = Vector.norm(v2) v3 = Vector.sub(P3, P0) n3 = Vector.norm(v3) v1p = v1 v2p = v2 v3p = v3 if abs(n1) < 1.e-12: v1 = Vector.cross(v2, v3) v1p = (0., 0., 0.) elif abs(n2) < 1.e-12: v2 = Vector.cross(v1, v3) v2p = (0., 0., 0.) elif abs(n3) < 1.e-12: v3 = Vector.cross(v2, v3) v3p = (0., 0., 0.) # Essaie de matcher les vecteur sur la vue p1,p2,p3 # On suppose que dirCam doit etre e2, ... posCam = CPlot.getState('posCam') posEye = CPlot.getState('posEye') dirCam = CPlot.getState('dirCam') e2 = dirCam e3 = Vector.sub(posCam, posEye) e1 = Vector.cross(e2, e3) f1 = None f2 = None f3 = None Pt = P0 s1 = Vector.dot(e1, v1) s2 = Vector.dot(e1, v2) s3 = Vector.dot(e1, v3) if abs(s1) > abs(s2) and abs(s1) > abs(s3): if s1 > 0: f1 = v1 else: f1 = Vector.mul(-1., v1) Pt = Vector.add(Pt, v1p) elif abs(s2) > abs(s1) and abs(s2) > abs(s3): if s2 > 0: f1 = v2 else: f1 = Vector.mul(-1., v2) Pt = Vector.add(Pt, v2p) elif abs(s3) > abs(s1) and abs(s3) > abs(s2): if s3 > 0: f1 = v3 else: f1 = Vector.mul(-1., v3) Pt = Vector.add(Pt, v3p) s1 = Vector.dot(e2, v1) s2 = Vector.dot(e2, v2) s3 = Vector.dot(e2, v3) if abs(s1) > abs(s2) and abs(s1) > abs(s3): if s1 > 0: f2 = v1 else: f2 = Vector.mul(-1., v1) Pt = Vector.add(Pt, v1p) elif abs(s2) > abs(s1) and abs(s2) > abs(s3): if s2 > 0: f2 = v2 else: f2 = Vector.mul(-1., v2) Pt = Vector.add(Pt, v2p) elif abs(s3) > abs(s1) and abs(s3) > abs(s2): if s3 > 0: f2 = v3 else: f2 = Vector.mul(-1., v3) Pt = Vector.add(Pt, v3p) s1 = Vector.dot(e3, v1) s2 = Vector.dot(e3, v2) s3 = Vector.dot(e3, v3) if abs(s1) > abs(s2) and abs(s1) > abs(s3): if s1 > 0: f3 = v1 else: f3 = Vector.mul(-1., v1) Pt = Vector.add(Pt, v1p) elif abs(s2) > abs(s1) and abs(s2) > abs(s3): if s2 > 0: f3 = v2 else: f3 = Vector.mul(-1., v2) Pt = Vector.add(Pt, v2p) elif abs(s3) > abs(s1) and abs(s3) > abs(s2): if s3 > 0: f3 = v3 else: f3 = Vector.mul(-1., v3) Pt = Vector.add(Pt, v3p) (x0, y0, z0) = Pt n2 = Vector.norm(f2) # Cree le texte text = VARS[0].get() type = VARS[1].get() font = VARS[3].get() smoothness = VARS[2].get() smooth = 0 if smoothness == 'Regular': smooth = 0 elif smoothness == 'Smooth': smooth = 2 elif smoothness == 'Very smooth': smooth = 4 if type == '3D': a = D.text3D(text, smooth=smooth, font=font) elif type == '2D': a = D.text2D(text, smooth=smooth, font=font) elif type == '1D': a = D.text1D(text, smooth=smooth, font=font) a = C.convertArray2Tetra(a) a = T.join(a) BB = G.bbox(a) h2 = BB[4] - BB[1] # Scale, positionne le texte factor = n2 / h2 a = T.homothety(a, (BB[0], BB[1], BB[2]), factor) a = T.translate(a, (x0 - BB[0], y0 - BB[1], z0 - BB[2])) a = T.rotate(a, (x0, y0, z0), ((1, 0, 0), (0, 1, 0), (0, 0, 1)), ((f1, f2, f3))) CTK.t = CPlot.deleteSelection(CTK.t, CTK.Nb, CTK.Nz, nzs) CPlot.delete(dels) CTK.add(CTK.t, nob0, -1, a) #C._fillMissingVariables(CTK.t) CTK.TXT.insert('START', 'Text replaced.\n') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()