def test_02Path(self): import CGNS.PAT.cgnsutils as CGU import CGNS.PAT.cgnserrors as CGE import CGNS.PAT.cgnskeywords as CGK self.genTree() p = '/{Base#1}/{Zone-A}/ZoneBC' self.assertEqual(p, CGU.getPathNoRoot(p)) self.assertEqual(p, CGU.getPathNoRoot('/CGNSTree' + p)) self.assertEqual("/", CGU.getPathNoRoot('/CGNSTree')) self.assertEqual(CGU.getPathNormalize('/./{Base#1}/{Zone-A}/ZoneBC'), p) self.assertEqual(CGU.getPathNormalize('/./{Base#1}/{Zone-A}/ZoneBC//'), p) self.assertEqual(CGU.getPathToList(p), ['', '{Base#1}', '{Zone-A}', 'ZoneBC']) self.assertEqual(CGU.getPathToList(p, True), ['{Base#1}', '{Zone-A}', 'ZoneBC']) self.assertEqual( CGU.getPathAsTypes(self.T, p), [CGK.CGNSTree_ts, CGK.CGNSBase_ts, CGK.Zone_ts, CGK.ZoneBC_ts]) zone = [ 'Zone', None, [['ZoneBC', None, [], CGK.ZoneBC_ts]], CGK.Zone_ts ] p = '/Zone/ZoneBC' self.assertEqual(CGU.getPathAsTypes(zone, p, legacy=False), [CGK.Zone_ts, CGK.ZoneBC_ts]) self.assertEqual(CGU.getPathAsTypes(zone, p, legacy=True), [CGK.ZoneBC_ts])
def treeSave(cls, control, fgprint, f, saveas): flags = CGNS.MAP.S2P_DEFAULT if OCTXT.CHLoneTrace: flags |= CGNS.MAP.S2P_TRACE if not saveas: flags |= CGNS.MAP.S2P_UPDATE flags |= CGNS.MAP.S2P_DELETEMISSING tree = fgprint.tree lazylist = [CGU.getPathNoRoot(path) for path in list(fgprint.lazy)] try: CGNS.MAP.save(f, tree, links=fgprint.links, flags=flags, skip=lazylist) except (CGNS.MAP.error, ) as chlex: txt = """The current save operation has been aborted (CHLone):""" control.readyCursor() MSG.wError(control, 130, chlex[0], txt, chlex[1]) return None except (Exception, ) as e: txt = """The current save operation has been aborted: %s""" % e control.readyCursor() MSG.wError(control, 131, 0, txt, '') return None fgprint.updateFileStats(f, saveas=True)
def setModelData(self, editor, model, index): col = index.column() row = index.row() v = str(editor.text()) if col in [1, 3]: v = CGU.getPathNoRoot(v) self._parent._links[row][self._parent._col2lk[col]] = v self._parent.reset()
def paint(self, painter, option, index): idx = self._parent.modelIndex(index) col = idx.column() nnm = self._parent.modelData(index).sidsName() pth = CGU.getPathNoRoot(self._parent.modelData(index).sidsPath()) if (self._merge is not None) and (pth in self._merge): if self._merge[pth] == MERGE_NA: self._parent.modelData(index).setUserStatePrivate('A') if self._merge[pth] == MERGE_NB: self._parent.modelData(index).setUserStatePrivate('B') if col == NMT.COLUMN_NAME: if nnm not in OCTXT._ReservedNames: option.font.setWeight(QFont.Bold) QStyledItemDelegate.paint(self, painter, option, index) option.font.setWeight(QFont.Light) if (self._diag is not None) and (pth in self._diag): color = self.gray if self._diag[pth] == DIFF_NX: color = self.gray if self._diag[pth] == DIFF_NA: color = self.green if self._diag[pth] == DIFF_ND: color = self.red painter.save() painter.setBrush(Qt.NoBrush) painter.setPen(color) painter.drawRect(option.rect) painter.restore() elif col == NMT.COLUMN_VALUE: option.font.setFamily(OCTXT.Table_Family) QStyledItemDelegate.paint(self, painter, option, index) if (self._diag is not None) and (pth in self._diag): if self._diag[pth] == DIFF_CV: painter.save() painter.setBrush(Qt.NoBrush) painter.setPen(self.orange) painter.drawRect(option.rect) painter.restore() elif col == NMT.COLUMN_DATATYPE: option.font.setFamily(OCTXT.Table_Family) option.font.setPointSize(8) QStyledItemDelegate.paint(self, painter, option, index) if (self._diag is not None) and (pth in self._diag): if self._diag[pth] == DIFF_CQ: painter.save() painter.setBrush(Qt.NoBrush) painter.setPen(self.orange) painter.drawRect(option.rect) painter.restore() elif col == NMT.COLUMN_SHAPE: QStyledItemDelegate.paint(self, painter, option, index) if (self._diag is not None) and (pth in self._diag): if self._diag[pth] == DIFF_CS: painter.save() painter.setBrush(Qt.NoBrush) painter.setPen(self.orange) painter.drawRect(option.rect) painter.restore() elif col == NMT.COLUMN_SIDS: QStyledItemDelegate.paint(self, painter, option, index) if (self._diag is not None) and (pth in self._diag): if self._diag[pth] == DIFF_CT: painter.save() painter.setBrush(Qt.NoBrush) painter.setPen(self.orange) painter.drawRect(option.rect) painter.restore() else: QStyledItemDelegate.paint(self, painter, option, index)
def isLink(self, path): pth = CGU.getPathNoRoot(path) for lk in self.links: if lk[3] == pth: return lk return False