def test_open(self): t = Tixi() self.assertRaises(TixiException, t.open, "____HOPEFULLY_THIS_FILE_NAME_DOES_NOT_EXIST~~~~") #OPEN_FAILED self.assertRaises(TixiException, t.open, os.path.join("TestData", "illformed.xml")) #NOT_WELL_FORMED t.open(os.path.join("TestData", "in.xml")) self.assertTrue(t._handle.value != -1) t.close()
def __init__(self): super(MainWindow, self).__init__() self.setWindowTitle('Main Window') tixi = Tixi() # tixi.open(conf.path_cpacs_simple) # tixi.open(Config.path_cpacs_D150_3) tixi.openDocument(Config.path_cpacs_simple) #tixi.openDocument(conf.path_cpacs_A320_Wing) #self.tixi.schemaValidateFromFile(cpacs_scheme) tigl = Tigl() try: tigl.open(tixi,"") except TiglException as err: print ('Error opening tigl document: ', err.__str__()) xml_editor = EditorWindow(tixi, Config.path_cpacs_simple) ogl_editor = MainWidget(tixi, tigl) dockWidgets = [('xml editor', xml_editor), ('ogl editor', ogl_editor)] xml_editor.updateAction.triggered.connect(ogl_editor.updateView) for (name, widget) in dockWidgets : self.addSimpleWidget(name, widget)
def test_multiple_tixis(self): ''' Check if we can handle several loaded DLLs and CPACS at the same time. ''' a = Tixi() b = Tixi() self.assertNotEqual(a._handle, b._handle) a.open(os.path.join("TestData", "in.xml")) b.open(os.path.join("TestData", "in.xml")) self.assertNotEqual(a._handle, b._handle) a.close() b.close()
def __init__(self, parent = None): super(MainWidget, self).__init__(parent) self.tixi = Tixi() self.tigl = Tigl() self.loadFile(Config.path_cpacs_A320_Fuse, Config.path_cpacs_21_schema) buttonAirf = QtGui.QPushButton("airfoil") buttonFuse = QtGui.QPushButton("fuselage") grid = QtGui.QGridLayout() grid.addWidget(buttonAirf, 0,0) grid.addWidget(buttonFuse, 0,1) self.setWindowTitle('Profile-Editor-Widget') self.setLayout(grid) self.resize(560,520) # fuse or airfoil window self.window = None # actions buttonAirf.clicked.connect(self.fire_AirfoilMainWidget) buttonFuse.clicked.connect(self.fire_FuselageMainWidget)
def test_validation_and_export(self): t = Tixi() t.open(os.path.join("TestData", "valid_CPACS_dokumentiert.xml")) c = t.exportDocumentAsString() self.assertTrue(c != None and c != "") header = '<?xml version="1.0" encoding="UTF-8"?>' self.assertTrue(c.startswith(header)) t.schemaValidateFromFile( os.path.join("TestData", "valid_cpacs_schema.xsd")) schema = 'invalid' self.assertRaises(TixiException, t.schemaValidateFromString, schema) #OPEN_SCHEMA_FAILED schema = '<?xml version="1.0" encoding="UTF-8"?>\\n<?xml-stylesheet href="xs3p.xsl" type="text/xsl"?>\\n<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/1999/xhtml" targetNamespace="http://www.w3.org/1999/xhtml" elementFormDefault="qualified" attributeFormDefault="unqualified">\\n</xsd:schema>' # TODO self.assertRaises(TixiException, t.schemaValidateFromString, schema) #NOT_SCHEMA_COMPLIANT t.close()
def test_validation_and_export(self): t = Tixi() t.open(os.path.join("TestData", "valid_CPACS_dokumentiert.xml")) c = t.exportDocumentAsString() self.assertTrue(c != None and c != "") header = '<?xml version="1.0" encoding="UTF-8"?>' self.assertTrue(c.startswith(header)) t.schemaValidateFromFile(os.path.join("TestData", "valid_cpacs_schema.xsd")) schema = 'invalid' self.assertRaises(TixiException, t.schemaValidateFromString, schema) #OPEN_SCHEMA_FAILED schema = '<?xml version="1.0" encoding="UTF-8"?>\\n<?xml-stylesheet href="xs3p.xsl" type="text/xsl"?>\\n<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/1999/xhtml" targetNamespace="http://www.w3.org/1999/xhtml" elementFormDefault="qualified" attributeFormDefault="unqualified">\\n</xsd:schema>' # TODO self.assertRaises(TixiException, t.schemaValidateFromString, schema) #NOT_SCHEMA_COMPLIANT t.close()
def test(self): # lxml test try: root = etree.Element("root") print (root.tag) print ("lxml ok") except ImportError : print ("import error lxml") # matplot test try: figure = Figure(figsize=(5,4), dpi=100) plot = figure.add_subplot(111) canvas = FigureCanvas(figure) print ("matplotlib ok") except ImportError : print ("import error matplotlib") # tixi, tigl try: tixi = Tixi() tixi.openDocument("toolOutput.xml") print ("tixi ok") except TixiException : print ("import error Tixi") try: tigl = Tigl() tigl.open(tixi,"") print ("tigl ok") except TixiException : print ("import error Tigl") try: np.arange(10000000) print ("numpy ok") except TixiException : print ("import error numpy")
def test_open(self): t = Tixi() self.assertRaises( TixiException, t.open, "____HOPEFULLY_THIS_FILE_NAME_DOES_NOT_EXIST~~~~") #OPEN_FAILED self.assertRaises(TixiException, t.open, os.path.join("TestData", "illformed.xml")) #NOT_WELL_FORMED t.open(os.path.join("TestData", "in.xml")) self.assertTrue(t._handle.value != -1) t.close()
def __init__(self, parent=None): super(Plotter_LC, self).__init__(parent) self.tixi = Tixi() self.tixi.open(Config.path_cpacs_lc_ref) self.buttonBox = QtGui.QDialogButtonBox() self.buttonBox.addButton(QtGui.QDialogButtonBox.Ok) self.buttonBox.addButton(QtGui.QDialogButtonBox.Reset) self.buttonBox.addButton(QtGui.QDialogButtonBox.Cancel) self.plot_widget = PlotWidget("LC") self.comboBoxLoadCases = QtGui.QComboBox() self.fillComboBoxLoadCases() self.fire_LoadCaseChanged(0) self.grid = QtGui.QGridLayout() self.grid.addWidget(self.comboBoxLoadCases, 0,0) self.grid.addWidget(self.plot_widget, 1, 0) # set the layout layout = QtGui.QGridLayout() layout.addLayout(self.grid, 0,0,1,3) layout.addWidget(self.buttonBox, 5, 0, 1,3) widget = QtGui.QWidget() widget.setLayout(layout) self.setCentralWidget(widget) # =============================================================================================== # actions # =============================================================================================== self.comboBoxLoadCases.currentIndexChanged.connect(self.fire_LoadCaseChanged) self.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked.connect(self.close) self.buttonBox.button(QtGui.QDialogButtonBox.Reset).clicked.connect(self.close) self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).clicked.connect(self.close)
def test_open_http(self): t = Tixi() t.openHttp("http://www.w3schools.com/XML/note.xml") t.close()
def test_open_string(self): t = Tixi() cpacs = '<?xml version="1.0"?><cpacs><header><version>1.2.3</version></header></cpacs>' t.openString(cpacs) t.close()
def test_vector_array(self): t = Tixi() t.open(os.path.join("TestData", "vectorcount.xml")) self.assertEquals(t.getVectorSize("/a/aeroPerformanceMap/cfx"), 32) #v = t.getFloatVector("/a/aeroPerformanceMap/cfx", 32) #print v[0], v[1], v[-1] #1 2 118 t.close() # manual creation of vector t.create('doc') t.addFloatVector('/doc', 'myvec', range(100,130), 30, "%g") size = t.getVectorSize('/doc/myvec') self.assertEquals(size, 30) v = t.getFloatVector('/doc/myvec', 30) self.assertEquals(v, tuple(range(100,130))) t.close() t.open(os.path.join("TestData", "arraytests.xml")) self.assertEquals(t.getArrayDimensions("/root/aeroPerformanceMap"), 4) self.assertEquals(t.getArrayDimensionSizes("/root/aeroPerformanceMap", 4), ((1, 2, 3, 8), 48)) self.assertEquals(t.getArrayDimensionNames("/root/aeroPerformanceMap", 4), ("machNumber", "reynoldsNumber", "angleOfYaw", "angleOfAttack")) # print t.getArrayDimensionValues("/root/aeroPerformanceMap", 0) 1.0 # print t.getArrayDimensionValues("/root/aeroPerformanceMap", 2) 0 5 10 self.assertEquals(t.getArrayParameters("/root/aeroPerformanceMap"), 7) # print t.getArrayParameterNames("/root/aeroPerformanceMap") ("cfx", "cfy", "cfz", "cmx", "cmy", "cmz", "def") # print t.getArray("/root/aeroPerformanceMap", "cmx") None # print t.getArrayValue(arr, "/root/aeroPerformanceMap", "angleOfAttack") #8 #print t.getArrayElementNames("/root/aeroPerformanceMap", "vector") #print t.getArrayElementNames("/root/aeroPerformanceMap", "array") t.getArrayElementCount("/root/aeroPerformanceMap","array") t.createElement("/root", "p1") t.addPoint("/root/p1", 1, 2, 3, None) self.assertEquals(t.getPoint("/root/p1"), (1.0, 2.0, 3.0)) self.assertEquals(t.xPathEvaluateNodeNumber("/root/aeroPerformanceMap"), 1) t.close() t.open(os.path.join("TestData", "in.xml")) self.assertEquals(t.xPathExpressionGetTextByIndex("/plane/wings/wing/centerOfGravity/x", 2), "30.0") t.close() t.open(os.path.join("TestData", "uid_correct.xml")) t.uIDCheckDuplicates() t.uIDCheckExists("schlumpf") t.close() t.open(os.path.join("TestData", "uid_duplicated.xml")) self.assertRaises(TixiException, t.uIDCheckDuplicates) #UID_NOT_UNIQUE
class Plotter(QtGui.QMainWindow): def __init__(self, path, parent=None): super(Plotter, self).__init__(parent) self.tixi = Tixi() t = self.tixi.open(Config.path_cpacs_pm_ref) self.pathPerMap = "/cpacs/vehicles/aircraft/model[1]/analyses/aeroPerformanceMap" self.path_specific = path self.buttonBox = QtGui.QDialogButtonBox() self.buttonBox.addButton(QtGui.QDialogButtonBox.Ok) self.buttonBox.addButton(QtGui.QDialogButtonBox.Reset) self.buttonBox.addButton(QtGui.QDialogButtonBox.Cancel) self.comboBoxXAxis = QtGui.QComboBox() self.comboBoxXAxis.addItem("machNumber") self.comboBoxXAxis.addItem("reynoldsNumber") self.comboBoxXAxis.addItem("angleOfYaw") self.comboBoxXAxis.addItem("angleOfAttack") self.comboBoxPlotPnt = QtGui.QComboBox() self.comboBoxPlotPnt.addItem("curve") self.comboBoxPlotPnt.addItem("points") self.labelXAxis = QtGui.QLabel("set x-axis") self.labelDisplay = QtGui.QLabel("display") self.labelMachNum = QtGui.QLabel("machNumber") self.labelReynoldsNum = QtGui.QLabel("reynoldsNumber") self.labelAngleOfYaw = QtGui.QLabel("angleOfYaw") self.labelAngleOfAtt = QtGui.QLabel("angleOfAttack") self.listMachNum = QtGui.QListWidget() self.listReynoldsNum = QtGui.QListWidget() self.listAngleOfYaw = QtGui.QListWidget() self.listAngleOfAtt = QtGui.QListWidget() #self.comboBoxXAxis.setCurrentIndex(0) self.__hidePlotLists(True, False, False, False) self.__fillPlotLists(self.pathPerMap) self.grid = QtGui.QGridLayout() self.grid.addWidget(self.labelXAxis, 0,0,1,3) self.grid.addWidget(self.labelDisplay, 0,3) self.grid.addWidget(self.comboBoxXAxis, 1,0,1,3) self.grid.addWidget(self.comboBoxPlotPnt, 1,3) self.grid.addWidget(self.labelMachNum, 2,0) self.grid.addWidget(self.listMachNum, 3,0) self.grid.addWidget(self.labelReynoldsNum, 2,1) self.grid.addWidget(self.listReynoldsNum, 3,1) self.grid.addWidget(self.labelAngleOfYaw, 2,2) self.grid.addWidget(self.listAngleOfYaw, 3,2) self.grid.addWidget(self.labelAngleOfAtt, 2,3) self.grid.addWidget(self.listAngleOfAtt, 3,3) # set the layout layout = QtGui.QGridLayout() layout.addLayout(self.grid, 0,0,1,3) layout.addWidget(self.buttonBox, 5, 0, 1,3) widget = QtGui.QWidget() widget.setLayout(layout) self.setCentralWidget(widget) # =============================================================================================== # actions # =============================================================================================== self.comboBoxXAxis.currentIndexChanged.connect(self.fire_XAxisChanged) self.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked.connect(self.plot) self.buttonBox.button(QtGui.QDialogButtonBox.Reset).clicked.connect(self.reset) self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).clicked.connect(self.close) def addSimpleWidget(self, name, widget): dock = QtGui.QDockWidget(name) dock.setWidget(widget) dock.setMinimumWidth(100) dock.setMinimumHeight(300) dock.setAllowedAreas(QtCore.Qt.AllDockWidgetAreas) dock.setFeatures(QtGui.QDockWidget.DockWidgetClosable | QtGui.QDockWidget.DockWidgetMovable | QtGui.QDockWidget.DockWidgetFloatable) self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, dock) return dock def fire_XAxisChanged(self, idx): self.reset() self.__setPlotListVisibility(idx == 0, idx == 1, idx == 2, idx == 3) def plot(self): # get current selection x_axis_idx = self.comboBoxXAxis.currentIndex() mach_idx = self.listMachNum.currentRow() reyn_idx = self.listReynoldsNum.currentRow() yaw_idx = self.listAngleOfYaw.currentRow() att_idx = self.listAngleOfAtt.currentRow() # find x-axis array ; stop one selection missed if x_axis_idx == 0 : x_axis = self.getMachNumberVector(self.pathPerMap) elif x_axis_idx == 1 : x_axis = self.getReynoldsNumberVector(self.pathPerMap) elif x_axis_idx == 2 : x_axis = self.getAngleOfYawVector(self.pathPerMap) elif x_axis_idx == 3 : x_axis = self.getAngleOfAttackVector(self.pathPerMap) # set display option displayOpt = 'go' if self.comboBoxPlotPnt.currentText() == "points" else "" # get values for tixiGetArrayValue ((cnt_mach, cnt_reyn, cnt_angleYaw, cnt_angleAtt), size) = self.tixi.getArrayDimensionSizes(self.pathPerMap, 4) dimSize = [cnt_mach, cnt_reyn, cnt_angleYaw, cnt_angleAtt] dimPos = [mach_idx, reyn_idx, yaw_idx, att_idx] dims = self.tixi.getArrayDimensions(self.pathPerMap) for widget in self.plotWidgets: array = self.getCoefficientArray(self.path_specific, widget.getTitle(), size) widget.setXLabel(self.comboBoxXAxis.currentText()) widget.updatePlot(array, dimSize, dimPos, dims, x_axis, x_axis_idx ,self.tixi, self.pathPerMap, displayOpt) def reset(self): for widget in self.plotWidgets: widget.updateReset() def __fillPlotLists(self, path): for item in self.getMachNumberVector(path) : self.listMachNum.addItem(str(item)) for item in self.getReynoldsNumberVector(path) : self.listReynoldsNum.addItem(str(item)) for item in self.getAngleOfYawVector(path) : self.listAngleOfYaw.addItem(str(item)) for item in self.getAngleOfAttackVector(path) : self.listAngleOfAtt.addItem(str(item)) def getAngleOfYawVector(self, path): return self.tixi.getFloatVector(path + "/angleOfYaw", self.tixi.getVectorSize(path + "/angleOfYaw")) def getAngleOfAttackVector(self, path): return self.tixi.getFloatVector(path + "/angleOfAttack", self.tixi.getVectorSize(path + "/angleOfAttack")) def getReynoldsNumberVector(self, path): return self.tixi.getFloatVector(path + "/reynoldsNumber", self.tixi.getVectorSize(path + "/reynoldsNumber")) def getMachNumberVector(self, path): return self.tixi.getFloatVector(path + "/machNumber", self.tixi.getVectorSize(path + "/machNumber")) def getCoefficientArray(self, path, child, num): return self.tixi.getArray(path , child, num) def __hidePlotLists(self, flag_mach, flag_reyn, flag_yaw, flag_att): self.__setPlotListVisibility(flag_mach, flag_reyn, flag_yaw, flag_att) def __setPlotListVisibility(self, flag_mach, flag_reyn, flag_yaw, flag_att): self.labelMachNum.setHidden(flag_mach) self.labelReynoldsNum.setHidden(flag_reyn) self.labelAngleOfYaw.setHidden(flag_yaw) self.labelAngleOfAtt.setHidden(flag_att) self.listMachNum.setHidden(flag_mach) self.listReynoldsNum.setHidden(flag_reyn) self.listAngleOfYaw.setHidden(flag_yaw) self.listAngleOfAtt.setHidden(flag_att)
def test_elements(self): t = Tixi() t.open(os.path.join("TestData", "in.xml")) self.assertEqual(t.getTextElement("/plane/name"), "Junkers JU 52") t.updateTextElement("/plane/name", "D150") self.assertEqual(t.getTextElement("/plane/name"), "D150") t.addTextElement("/plane", "name", "B747") self.assertEqual(t.getTextElement("/plane/name[2]"), "B747") self.assertEqual(t.getIntegerElement("/plane/numberOfPassengers"), 57) t.addIntegerElement("/plane", "nop", 123456, None) self.assertEqual(t.getIntegerElement("/plane/nop"), 123456) self.assertEqual( t.getDoubleElement("/plane/wings[1]/wing[1]/centerOfGravity/x"), 30.0) t.addDoubleElement("/plane/wings/wing[1]", "cog", 123.456, None) self.assertEqual(t.getDoubleElement("/plane/wings/wing[1]/cog"), 123.456) self.assertFalse(t.getBooleanElement("/plane/bool/aBool2")) self.assertTrue(t.getBooleanElement("/plane/bool/aBool1b")) self.assertFalse(t.checkElement("/plane/xx")) #ELEMENT_NOT_FOUND t.createElement("/plane", "xx") t.checkElement("/plane/xx") self.assertEquals(t.getTextElement("/plane/xx"), "") t.updateTextElement("/plane/xx", "value") self.assertEquals(t.getTextElement("/plane/xx"), "value") t.removeElement("/plane/xx") self.assertEqual(t.checkElement("/plane/xx"), False) self.assertRaises(TixiException, t.getTextElement, "/plane/xx") #ELEMENT_NOT_FOUND
def __init__(self, parent=None): super(Plotter_ControlSurfaces, self).__init__(parent) self.tixi = Tixi() self.tixi.open(Config.path_cpacs_pm_ref) self.buttonBox = QtGui.QDialogButtonBox() self.buttonBox.addButton(QtGui.QDialogButtonBox.Ok) self.buttonBox.addButton(QtGui.QDialogButtonBox.Reset) self.buttonBox.addButton(QtGui.QDialogButtonBox.Cancel) self.comboBoxXAxis = QtGui.QComboBox() self.comboBoxXAxis.addItem("machNumber") self.comboBoxXAxis.addItem("reynoldsNumber") self.comboBoxXAxis.addItem("angleOfYaw") self.comboBoxXAxis.addItem("angleOfAttack") self.comboBoxXAxis.addItem("relDeflection") self.comboBoxPlotPnt = QtGui.QComboBox() self.comboBoxPlotPnt.addItem("curve") self.comboBoxPlotPnt.addItem("points") self.comboBoxCtrlSurUID = QtGui.QComboBox() self.labelCtrlSurUID = QtGui.QLabel("controlSurfaceUID") self.labelXAxis = QtGui.QLabel("set x-axis") self.labelDisplay = QtGui.QLabel("display") self.labelMachNum = QtGui.QLabel("machNumber") self.labelReynoldsNum = QtGui.QLabel("reynoldsNumber") self.labelAngleOfYaw = QtGui.QLabel("angleOfYaw") self.labelAngleOfAtt = QtGui.QLabel("angleOfAttack") self.labelRelDefl = QtGui.QLabel("relDeflection") self.listMachNum = QtGui.QListWidget() self.listReynoldsNum = QtGui.QListWidget() self.listAngleOfYaw = QtGui.QListWidget() self.listAngleOfAtt = QtGui.QListWidget() self.listRelDefl = QtGui.QListWidget() self.hidePlotLists(True, False, False, False, False) self.fillPlotLists("/cpacs/vehicles/aircraft/model[1]/analyses/aeroPerformanceMap") self.grid = QtGui.QGridLayout() self.grid.addWidget(self.labelCtrlSurUID, 0, 0, 1, 5) self.grid.addWidget(self.comboBoxCtrlSurUID,1,0, 1, 5) self.grid.addWidget(self.labelXAxis, 2,0,1,3) self.grid.addWidget(self.labelDisplay, 2,3,1,2) self.grid.addWidget(self.comboBoxXAxis, 3,0,1,3) self.grid.addWidget(self.comboBoxPlotPnt, 3,3,1,2) self.grid.addWidget(self.labelMachNum, 4,0) self.grid.addWidget(self.listMachNum, 5,0) self.grid.addWidget(self.labelReynoldsNum, 4,1) self.grid.addWidget(self.listReynoldsNum, 5,1) self.grid.addWidget(self.labelAngleOfYaw, 4,2) self.grid.addWidget(self.listAngleOfYaw, 5,2) self.grid.addWidget(self.labelAngleOfAtt, 4,3) self.grid.addWidget(self.listAngleOfAtt, 5,3) self.grid.addWidget(self.labelRelDefl, 4,4) self.grid.addWidget(self.listRelDefl, 5,4) # set the layout layout = QtGui.QGridLayout() layout.addLayout(self.grid, 0,0,1,3) layout.addWidget(self.buttonBox, 5, 0, 1,3) widget = QtGui.QWidget() widget.setLayout(layout) self.setCentralWidget(widget) # add observer self.plotWidgets = [PlotWidget("dcfx"), PlotWidget("dcfy"), PlotWidget("dcfz"), PlotWidget("dcmx"), PlotWidget("dcmy"), PlotWidget("dcmz")] self.dockList = [] for widget in self.plotWidgets : dock = self.addSimpleWidget(widget.getTitle(), widget) insertIndex = len(self.dockList) - 1 self.dockList.insert(insertIndex, dock) if len(self.dockList) > 1: for index in range(0, len(self.dockList) - 1): self.tabifyDockWidget(self.dockList[index], self.dockList[index + 1]) self.dockList[0].raise_() self.nextindex = 1 # =============================================================================================== # actions # =============================================================================================== self.comboBoxXAxis.currentIndexChanged.connect(self.fire_XAxisChanged) self.comboBoxCtrlSurUID.currentIndexChanged.connect(self.fire_CtrlSurfacesChanged) self.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked.connect(self.plot) self.buttonBox.button(QtGui.QDialogButtonBox.Reset).clicked.connect(self.reset) self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).clicked.connect(self.close)
class Plotter_LC(QtGui.QMainWindow): def __init__(self, parent=None): super(Plotter_LC, self).__init__(parent) self.tixi = Tixi() self.tixi.open(Config.path_cpacs_lc_ref) self.buttonBox = QtGui.QDialogButtonBox() self.buttonBox.addButton(QtGui.QDialogButtonBox.Ok) self.buttonBox.addButton(QtGui.QDialogButtonBox.Reset) self.buttonBox.addButton(QtGui.QDialogButtonBox.Cancel) self.plot_widget = PlotWidget("LC") self.comboBoxLoadCases = QtGui.QComboBox() self.fillComboBoxLoadCases() self.fire_LoadCaseChanged(0) self.grid = QtGui.QGridLayout() self.grid.addWidget(self.comboBoxLoadCases, 0,0) self.grid.addWidget(self.plot_widget, 1, 0) # set the layout layout = QtGui.QGridLayout() layout.addLayout(self.grid, 0,0,1,3) layout.addWidget(self.buttonBox, 5, 0, 1,3) widget = QtGui.QWidget() widget.setLayout(layout) self.setCentralWidget(widget) # =============================================================================================== # actions # =============================================================================================== self.comboBoxLoadCases.currentIndexChanged.connect(self.fire_LoadCaseChanged) self.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked.connect(self.close) self.buttonBox.button(QtGui.QDialogButtonBox.Reset).clicked.connect(self.close) self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).clicked.connect(self.close) def fire_LoadCaseChanged(self, idx): uid = self.comboBoxLoadCases.currentText() path = '/cpacs/vehicles/aircraft/model[1]/analyses/loadAnalysis/loadCases/flightLoadCase[@uID="' + uid + '"]' x_axis, y_axis = self.getPlotPointValues(path) self.plot_widget.plot.clear() self.plot_widget.plot.grid(True) self.plot_widget.simplePlot(x_axis, y_axis) def fillComboBoxLoadCases(self): path_lc = "/cpacs/vehicles/aircraft/model[1]/analyses/loadAnalysis/loadCases" for idx_lc in range(1, self.tixi.getNumberOfChilds(path_lc) + 1) : tmp_path = path_lc + "/flightLoadCase[" + str(idx_lc) + "]" self.comboBoxLoadCases.addItem( self.tixi.getTextAttribute(tmp_path,"uID") ) def getPlotPointValues(self, path): """... Args: path (String): path to specific flightLoadCase Returns: ... """ xaxis = [] yaxis = [] path_wings = path + "/aeroLoads/wings" for idx_wing in range(1, self.tixi.getNumberOfChilds(path_wings) + 1) : path_segs = path_wings + "/wing[" + str(idx_wing) + "]/segments" for idx_seg in range(1, self.tixi.getNumberOfChilds(path_segs) + 1) : for idx_strip in range(1, self.tixi.getNamedChildrenCount(path_segs + "/segment[" + str(idx_seg) + "]", "strip") + 1) : x = self.tixi.getDoubleElement(path_segs + "/segment[" + str(idx_seg) + "]/strip[" + str(idx_strip) + "]/reference/point/x") y = self.tixi.getDoubleElement(path_segs + "/segment[" + str(idx_seg) + "]/strip[" + str(idx_strip) + "]/reference/point/y") xaxis.append(x) yaxis.append(y) return xaxis, yaxis
class Plotter_ControlSurfaces(QtGui.QMainWindow): def __init__(self, parent=None): super(Plotter_ControlSurfaces, self).__init__(parent) self.tixi = Tixi() self.tixi.open(Config.path_cpacs_pm_ref) self.buttonBox = QtGui.QDialogButtonBox() self.buttonBox.addButton(QtGui.QDialogButtonBox.Ok) self.buttonBox.addButton(QtGui.QDialogButtonBox.Reset) self.buttonBox.addButton(QtGui.QDialogButtonBox.Cancel) self.comboBoxXAxis = QtGui.QComboBox() self.comboBoxXAxis.addItem("machNumber") self.comboBoxXAxis.addItem("reynoldsNumber") self.comboBoxXAxis.addItem("angleOfYaw") self.comboBoxXAxis.addItem("angleOfAttack") self.comboBoxXAxis.addItem("relDeflection") self.comboBoxPlotPnt = QtGui.QComboBox() self.comboBoxPlotPnt.addItem("curve") self.comboBoxPlotPnt.addItem("points") self.comboBoxCtrlSurUID = QtGui.QComboBox() self.labelCtrlSurUID = QtGui.QLabel("controlSurfaceUID") self.labelXAxis = QtGui.QLabel("set x-axis") self.labelDisplay = QtGui.QLabel("display") self.labelMachNum = QtGui.QLabel("machNumber") self.labelReynoldsNum = QtGui.QLabel("reynoldsNumber") self.labelAngleOfYaw = QtGui.QLabel("angleOfYaw") self.labelAngleOfAtt = QtGui.QLabel("angleOfAttack") self.labelRelDefl = QtGui.QLabel("relDeflection") self.listMachNum = QtGui.QListWidget() self.listReynoldsNum = QtGui.QListWidget() self.listAngleOfYaw = QtGui.QListWidget() self.listAngleOfAtt = QtGui.QListWidget() self.listRelDefl = QtGui.QListWidget() self.hidePlotLists(True, False, False, False, False) self.fillPlotLists("/cpacs/vehicles/aircraft/model[1]/analyses/aeroPerformanceMap") self.grid = QtGui.QGridLayout() self.grid.addWidget(self.labelCtrlSurUID, 0, 0, 1, 5) self.grid.addWidget(self.comboBoxCtrlSurUID,1,0, 1, 5) self.grid.addWidget(self.labelXAxis, 2,0,1,3) self.grid.addWidget(self.labelDisplay, 2,3,1,2) self.grid.addWidget(self.comboBoxXAxis, 3,0,1,3) self.grid.addWidget(self.comboBoxPlotPnt, 3,3,1,2) self.grid.addWidget(self.labelMachNum, 4,0) self.grid.addWidget(self.listMachNum, 5,0) self.grid.addWidget(self.labelReynoldsNum, 4,1) self.grid.addWidget(self.listReynoldsNum, 5,1) self.grid.addWidget(self.labelAngleOfYaw, 4,2) self.grid.addWidget(self.listAngleOfYaw, 5,2) self.grid.addWidget(self.labelAngleOfAtt, 4,3) self.grid.addWidget(self.listAngleOfAtt, 5,3) self.grid.addWidget(self.labelRelDefl, 4,4) self.grid.addWidget(self.listRelDefl, 5,4) # set the layout layout = QtGui.QGridLayout() layout.addLayout(self.grid, 0,0,1,3) layout.addWidget(self.buttonBox, 5, 0, 1,3) widget = QtGui.QWidget() widget.setLayout(layout) self.setCentralWidget(widget) # add observer self.plotWidgets = [PlotWidget("dcfx"), PlotWidget("dcfy"), PlotWidget("dcfz"), PlotWidget("dcmx"), PlotWidget("dcmy"), PlotWidget("dcmz")] self.dockList = [] for widget in self.plotWidgets : dock = self.addSimpleWidget(widget.getTitle(), widget) insertIndex = len(self.dockList) - 1 self.dockList.insert(insertIndex, dock) if len(self.dockList) > 1: for index in range(0, len(self.dockList) - 1): self.tabifyDockWidget(self.dockList[index], self.dockList[index + 1]) self.dockList[0].raise_() self.nextindex = 1 # =============================================================================================== # actions # =============================================================================================== self.comboBoxXAxis.currentIndexChanged.connect(self.fire_XAxisChanged) self.comboBoxCtrlSurUID.currentIndexChanged.connect(self.fire_CtrlSurfacesChanged) self.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked.connect(self.plot) self.buttonBox.button(QtGui.QDialogButtonBox.Reset).clicked.connect(self.reset) self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).clicked.connect(self.close) def addSimpleWidget(self, name, widget): ''' create dock widget and set it to main window''' dock = QtGui.QDockWidget(name) dock.setWidget(widget) dock.setMinimumWidth(100) dock.setMinimumHeight(300) dock.setAllowedAreas(QtCore.Qt.AllDockWidgetAreas) dock.setFeatures(QtGui.QDockWidget.DockWidgetClosable | QtGui.QDockWidget.DockWidgetMovable | QtGui.QDockWidget.DockWidgetFloatable) self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, dock) return dock def fire_XAxisChanged(self, idx): '''sets all options if the x-axis was changed''' self.reset() self.hidePlotLists(idx == 0, idx == 1, idx == 2, idx == 3, idx == 4) def fire_CtrlSurfacesChanged(self, idx): '''sets all options if the controlSurface was changed''' self.reset() self.listRelDefl.clear() for item in self.getRelDeflectionVector("/cpacs/vehicles/aircraft/model[1]/analyses/aeroPerformanceMap", self.comboBoxCtrlSurUID.currentText()): self.listRelDefl.addItem(str(item)) def plot(self): '''updates all observer plot widgets''' path = "/cpacs/vehicles/aircraft/model[1]/analyses/aeroPerformanceMap" x_axis_idx = self.comboBoxXAxis.currentIndex() # indices of the lists mach_idx = self.listMachNum.currentRow() reyn_idx = self.listReynoldsNum.currentRow() yaw_idx = self.listAngleOfYaw.currentRow() att_idx = self.listAngleOfAtt.currentRow() relDef_idx = self.listRelDefl.currentRow() # get uid of chosen controlSurfaces relDef_uid = self.comboBoxCtrlSurUID.currentText() # determine x-axis if x_axis_idx == 0 : x_axis = self.getMachNumberVector(path) elif x_axis_idx == 1 : x_axis = self.getReynoldsNumberVector(path) elif x_axis_idx == 2 : x_axis = self.getAngleOfYawVector(path) elif x_axis_idx == 3 : x_axis = self.getAngleOfAttackVector(path) elif x_axis_idx == 4 : x_axis = self.getRelDeflectionVector(path, relDef_uid) # dimSize == product over all sizes (for complete array size) # cnt_mach, cnt_reyn, cnt_angleYaw, cnt_angleAtt) == size of coefficients ((cnt_mach, cnt_reyn, cnt_angleYaw, cnt_angleAtt), size) = self.tixi.getArrayDimensionSizes(path, 4) # the same for controlSurface ((cnt_relDef,_), _) = self.tixi.getArrayDimensionSizes(path + "/controlSurfaces/controlSurface[" + str(self.tixiGetIdxOfUID(relDef_uid)) + "]", 2) # determine complete array size (including relDeflection) size = size * cnt_relDef # set drawing option displayOpt = 'go' if self.comboBoxPlotPnt.currentText() == "points" else "" dimPos = [mach_idx, reyn_idx, yaw_idx, att_idx, relDef_idx] dimSize = [cnt_mach, cnt_reyn, cnt_angleYaw, cnt_angleAtt, cnt_relDef] dims = 5 # self.tixi.getArrayDimensions(path + "/controlSurfaces/controlSurface[" + str(self.tixiGetIdxOfUID(relDef_uid)) + "]") + oben dims # update all observer for widget in self.plotWidgets: # determine coefficient array array = self.getCoefficientArray(path + "/controlSurfaces/controlSurface[1]", widget.getTitle(), size) widget.setXLabel(self.comboBoxXAxis.currentText()) widget.updatePlot(array, dimSize, dimPos, dims, x_axis, x_axis_idx, self.tixi, path, displayOpt) def reset(self): '''resets all observer''' for widget in self.plotWidgets: widget.updateReset() def tixiGetIdxOfUID(self, uID): """determines the index of a given controlSurface uID Args: uID (String): controlSurface uID Returns: the index of the controlSurface with the given uID """ path = "/cpacs/vehicles/aircraft/model[1]/analyses/aeroPerformanceMap/controlSurfaces" for i in range(1, self.tixi.getNumberOfChilds(path) +1 ) : tmp_uid = self.tixi.getTextElement(path + "/controlSurface[" + str(i) + "]/controlSurfaceUID") if uID == tmp_uid : return i return None def fillPlotLists(self, path): """fills the five list boxes Args: path (String): path to aeroPerformanceMap """ for item in self.getMachNumberVector(path) : self.listMachNum.addItem(str(item)) for item in self.getReynoldsNumberVector(path) : self.listReynoldsNum.addItem(str(item)) for item in self.getAngleOfYawVector(path) : self.listAngleOfYaw.addItem(str(item)) for item in self.getAngleOfAttackVector(path) : self.listAngleOfAtt.addItem(str(item)) for i in range(1, self.tixi.getNumberOfChilds(path + "/controlSurfaces") +1) : uid = self.tixi.getTextElement(path + "/controlSurfaces/controlSurface[" + str(i) + "]/controlSurfaceUID") self.comboBoxCtrlSurUID.addItem(uid) if(i == 1): # pre-fill relDeflection list for item in self.getRelDeflectionVector(path, uid): self.listRelDefl.addItem(str(item)) def getAngleOfYawVector(self, path): return self.tixi.getFloatVector(path + "/angleOfYaw", self.tixi.getVectorSize(path + "/angleOfYaw")) def getAngleOfAttackVector(self, path): return self.tixi.getFloatVector(path + "/angleOfAttack", self.tixi.getVectorSize(path + "/angleOfAttack")) def getReynoldsNumberVector(self, path): return self.tixi.getFloatVector(path + "/reynoldsNumber", self.tixi.getVectorSize(path + "/reynoldsNumber")) def getMachNumberVector(self, path): return self.tixi.getFloatVector(path + "/machNumber", self.tixi.getVectorSize(path + "/machNumber")) def getRelDeflectionVector(self, path, uid): """returns relDeflection of a controlSurface given by a uid Args: path (String): path to aeroPerformanceMap """ for i in range(1, self.tixi.getNumberOfChilds(path) +1) : _uid = self.tixi.getTextElement(path + "/controlSurfaces/controlSurface[" + str(i) + "]/controlSurfaceUID") if(_uid == uid): p = path + "/controlSurfaces/controlSurface[" + str(i) + "]/relDeflection" return self.tixi.getFloatVector(p, self.tixi.getVectorSize(p)) return None def getCoefficientArray(self, path, child, num): """returns the array of a given path, child node and element count Args: path (String): path to array child (String): child node to array num (int): count of elements Returns: the square root of n. """ return self.tixi.getArray(path, child, num) # This function hides labels and plot lists. def hidePlotLists(self, flag_mach, flag_reyn, flag_yaw, flag_att, flag_relDef): """hides labels and plot lists. Args: flag_mach (bool): hide label of machNumber and list of machNumber flag_reyn (bool): hide label of reynoldNumber and list of reynoldNumber flag_yaw (bool): hide label of angleOfYaw and list of angleOfYaw flag_att (bool): hide label of angleOfAttack and list of angleOfAttack flag_relDef (bool): hide label of relDeflection and list of relDeflection """ self.labelMachNum.setHidden(flag_mach) self.labelReynoldsNum.setHidden(flag_reyn) self.labelAngleOfYaw.setHidden(flag_yaw) self.labelAngleOfAtt.setHidden(flag_att) self.labelRelDefl.setHidden(flag_relDef) self.listMachNum.setHidden(flag_mach) self.listReynoldsNum.setHidden(flag_reyn) self.listAngleOfYaw.setHidden(flag_yaw) self.listAngleOfAtt.setHidden(flag_att) self.listRelDefl.setHidden(flag_relDef)
def test_elements(self): t = Tixi() t.open(os.path.join("TestData", "in.xml")) self.assertEqual(t.getTextElement("/plane/name"), "Junkers JU 52") t.updateTextElement("/plane/name", "D150") self.assertEqual(t.getTextElement("/plane/name"), "D150") t.addTextElement("/plane", "name", "B747") self.assertEqual(t.getTextElement("/plane/name[2]"), "B747") self.assertEqual(t.getIntegerElement("/plane/numberOfPassengers"), 57) t.addIntegerElement("/plane", "nop", 123456, None) self.assertEqual(t.getIntegerElement("/plane/nop"), 123456) self.assertEqual(t.getDoubleElement("/plane/wings[1]/wing[1]/centerOfGravity/x"), 30.0) t.addDoubleElement("/plane/wings/wing[1]", "cog", 123.456, None) self.assertEqual(t.getDoubleElement("/plane/wings/wing[1]/cog"), 123.456) self.assertFalse(t.getBooleanElement("/plane/bool/aBool2")) self.assertTrue(t.getBooleanElement("/plane/bool/aBool1b")) self.assertFalse(t.checkElement("/plane/xx")) #ELEMENT_NOT_FOUND t.createElement("/plane", "xx") t.checkElement("/plane/xx") self.assertEquals(t.getTextElement("/plane/xx"), "") t.updateTextElement("/plane/xx", "value") self.assertEquals(t.getTextElement("/plane/xx"), "value") t.removeElement("/plane/xx") self.assertEqual(t.checkElement("/plane/xx"),False) self.assertRaises(TixiException, t.getTextElement, "/plane/xx") #ELEMENT_NOT_FOUND
def __init__(self, parent=None): super(Plotter_DamingDerivates, self).__init__(parent) self.tixi = Tixi() self.tixi.open("../cpacs_files/outputfile_PM_Ref.xml") self.buttonBox = QtGui.QDialogButtonBox() self.buttonBox.addButton(QtGui.QDialogButtonBox.Ok) self.buttonBox.addButton(QtGui.QDialogButtonBox.Reset) self.buttonBox.addButton(QtGui.QDialogButtonBox.Cancel) self.comboBoxXAxis = QtGui.QComboBox() self.comboBoxXAxis.addItem("machNumber") self.comboBoxXAxis.addItem("reynoldsNumber") self.comboBoxXAxis.addItem("angleOfYaw") self.comboBoxXAxis.addItem("angleOfAttack") self.comboBoxPlotPnt = QtGui.QComboBox() self.comboBoxPlotPnt.addItem("curve") self.comboBoxPlotPnt.addItem("points") self.labelXAxis = QtGui.QLabel("set x-axis") self.labelDisplay = QtGui.QLabel("display") self.labelMachNum = QtGui.QLabel("machNumber") self.labelReynoldsNum = QtGui.QLabel("reynoldsNumber") self.labelAngleOfYaw = QtGui.QLabel("angleOfYaw") self.labelAngleOfAtt = QtGui.QLabel("angleOfAttack") self.listMachNum = QtGui.QListWidget() self.listReynoldsNum = QtGui.QListWidget() self.listAngleOfYaw = QtGui.QListWidget() self.listAngleOfAtt = QtGui.QListWidget() self.__hidePlotLists(True, False, False, False) self.__fillPlotLists("/cpacs/vehicles/aircraft/model[1]/analyses/aeroPerformanceMap") self.grid = QtGui.QGridLayout() self.grid.addWidget(self.labelXAxis, 0,0,1,3) self.grid.addWidget(self.labelDisplay, 0,3) self.grid.addWidget(self.comboBoxXAxis, 1,0,1,3) self.grid.addWidget(self.comboBoxPlotPnt, 1,3) self.grid.addWidget(self.labelMachNum, 2,0) self.grid.addWidget(self.listMachNum, 3,0) self.grid.addWidget(self.labelReynoldsNum, 2,1) self.grid.addWidget(self.listReynoldsNum, 3,1) self.grid.addWidget(self.labelAngleOfYaw, 2,2) self.grid.addWidget(self.listAngleOfYaw, 3,2) self.grid.addWidget(self.labelAngleOfAtt, 2,3) self.grid.addWidget(self.listAngleOfAtt, 3,3) # set the layout layout = QtGui.QGridLayout() layout.addLayout(self.grid, 0,0,1,3) layout.addWidget(self.buttonBox, 5, 0, 1,3) widget = QtGui.QWidget() widget.setLayout(layout) self.setCentralWidget(widget) self.plotWidgets = [PlotWidget("dcfxdpstar"), PlotWidget("dcfxdqstar"), PlotWidget("dcfxdrstar"), PlotWidget("dcfydpstar"), PlotWidget("dcfydqstar"), PlotWidget("dcfydrstar"), PlotWidget("dcfzdpstar"), PlotWidget("dcfzdqstar"), PlotWidget("dcfzdrstar"), PlotWidget("dcmxdpstar"), PlotWidget("dcmxdqstar"), PlotWidget("dcmxdrstar"), PlotWidget("dcmydpstar"), PlotWidget("dcmydqstar"), PlotWidget("dcmydrstar"), PlotWidget("dcmzdpstar"), PlotWidget("dcmzdqstar"), PlotWidget("dcmzdrstar")] i = 0 ; l = len(self.plotWidgets) / 4 for widget in self.plotWidgets : if i < l : self.addSimpleWidget(widget, QtCore.Qt.LeftDockWidgetArea, True) elif i < 2 * l : self.addSimpleWidget(widget, QtCore.Qt.RightDockWidgetArea, True) else : self.addSimpleWidget(widget, QtCore.Qt.BottomDockWidgetArea, False) i+=1 # =============================================================================================== # actions # =============================================================================================== self.comboBoxXAxis.currentIndexChanged.connect(self.fire_XAxisChanged) self.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked.connect(self.plot) self.buttonBox.button(QtGui.QDialogButtonBox.Reset).clicked.connect(self.reset) self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).clicked.connect(self.close)
def test_create(self): t = Tixi() t.create("cpacs") self.assertTrue(t._handle != -1) t.close()
class MainWidget(QtGui.QWidget): def __init__(self, parent = None): super(MainWidget, self).__init__(parent) self.tixi = Tixi() self.tigl = Tigl() self.loadFile(Config.path_cpacs_A320_Fuse, Config.path_cpacs_21_schema) buttonAirf = QtGui.QPushButton("airfoil") buttonFuse = QtGui.QPushButton("fuselage") grid = QtGui.QGridLayout() grid.addWidget(buttonAirf, 0,0) grid.addWidget(buttonFuse, 0,1) self.setWindowTitle('Profile-Editor-Widget') self.setLayout(grid) self.resize(560,520) # fuse or airfoil window self.window = None # actions buttonAirf.clicked.connect(self.fire_AirfoilMainWidget) buttonFuse.clicked.connect(self.fire_FuselageMainWidget) def loadFile(self, filePath, cpacsSchema): """loads a cpacs file with tixi and tigl. Args: filePath (String): path to cpacs file cpacsSchema (String): path to cpacs schema file """ try: print filePath self.tixi.openDocument(filePath) self.tixi.schemaValidateFromFile(cpacsSchema) try: self.tigl.open(self.tixi,"") except TiglException as e: QtGui.QMessageBox.information(self, "Error", "TIGL: " + str(e.error)) except TixiException as e: msgBox = QtGui.QMessageBox() msgBox.setText('open file or exit application') btnOpen = QtGui.QPushButton('open') msgBox.addButton(btnOpen, QtGui.QMessageBox.YesRole) btnExit = QtGui.QPushButton('exit') msgBox.addButton(btnExit, QtGui.QMessageBox.NoRole) if msgBox.exec_() == 0 : (filePath,_) = QtGui.QFileDialog.getOpenFileName(self, 'Open file') self.loadFile(filePath, cpacsSchema) else: sys.exit() def getVectorX(self, prof_uid): xpath = self.tixi.uIDGetXPath(prof_uid) numX = self.tixi.getVectorSize(xpath + "/pointList/x") return self.tixi.getFloatVector(xpath + "/pointList/x",numX) def getVectorY(self, prof_uid): xpath = self.tixi.uIDGetXPath(prof_uid) numY = self.tixi.getVectorSize(xpath + "/pointList/y") return self.tixi.getFloatVector(xpath + "/pointList/y",numY) def getVectorZ(self, prof_uid): xpath = self.tixi.uIDGetXPath(prof_uid) numZ = self.tixi.getVectorSize(xpath + "/pointList/z") return self.tixi.getFloatVector(xpath + "/pointList/z",numZ) def createPointList(self, uID) : """creates a point list with profile points of given uID Args: uID (String): uID from cpacs profile Returns: lists of top and bottom profile points in format [ [x0,y0,z0] , [x1,y1,z1] , ... ] """ vecX = self.getVectorX(uID) vecY = self.getVectorY(uID) vecZ = self.getVectorZ(uID) res = [] for i in range(len(vecX)) : res.append([vecX[i], vecY[i], vecZ[i]]) return res def fire_AirfoilMainWidget(self, uid='NACA0000'): self.window = AirfoilMainWidget( Airfoil(uid, self.tigl, self.createPointList(uid)) ) def fire_FuselageMainWidget(self, uid='CircleProfile'): self.window = FuselageMainWidget( Fuselage(uid, self.tigl, self.createPointList(uid)) )
def test_api(self): t = Tixi() self.assertEquals(t.version, t.getVersion()) t.create("root") t.addDoubleElement("/root","myDouble",3.2,0) t.addIntegerElement("/root","myInteger",6,None) # Here starts the rest t.addBooleanElement("/root","myBoolean",0) t.updateDoubleElement("/root/myDouble",3.14159262,0) t.updateIntegerElement("/root/myInteger",7,None) t.updateBooleanElement("/root/myBoolean",1) t.addTextElementAtIndex("/root","myNewTextElement","myText",2) t.createElementAtIndex("/root","array",0) t.addFloatVector("/root","myFloatVector",(0.0,1.1,2.2),3, "%g") t.addExternalLink("/root","/externalLink",".xml") t.addHeader("tool","version","author") t.addCpacsHeader("name","creator","version","description","cpacsVersion") t.usePrettyPrint(1) t.uIDCheckLinks() t.uIDSetToXPath("/root/myBoolean","booleanID") self.assertEqual(t.uIDGetXPath("booleanID"),"/root/myBoolean") #t.dTDValidate() #t.xSLTransformationToFile() t.save(os.path.join("TestData", "test_save.xml")) t.close() t.cleanup()
def test_attributes(self): t = Tixi() t.open(os.path.join("TestData", "in.xml")) self.assertEquals(t.getTextAttribute("/plane/wings/wing[1]", "position"), "left") self.assertEquals(t.getIntegerAttribute("/plane/wings", "numberOfWings"), 2) t.addIntegerAttribute("/plane", "intattr", 324, None) self.assertEquals(t.getIntegerAttribute("/plane", "intattr"), 324) t.removeAttribute("/plane", "intattr") self.assertEquals(t.getDoubleAttribute("/plane/coordinateOrigin", "scaling"), 1.3456) self.assertFalse(t.checkAttribute("/plane", "doubleattr")) # ATTRIBUTE_NOT_FOUND \n t.addDoubleAttribute("/plane", "doubleattr", 123.456, None) t.checkAttribute("/plane", "doubleattr") self.assertEquals(t.getDoubleAttribute("/plane", "doubleattr"), 123.456) t.removeAttribute("/plane", "doubleattr") t.addTextAttribute("/plane", "attr", "val") self.assertEquals(t.getTextAttribute("/plane", "attr"), "val") self.assertEquals(t.getNamedChildrenCount("/plane/wings", "wing"), 2) t.addDoubleListWithAttributes("/plane", "list", "elem", "attr", [1., 2., 3.], None, ["a", "b", "c"], 3) self.assertEquals(t.getTextAttribute("/plane/list/elem[1]", "attr"), "a") self.assertEquals(t.getDoubleElement("/plane/list/elem[3]"), 3.0) t.close()
def __init__(self, path, parent=None): super(Plotter, self).__init__(parent) self.tixi = Tixi() t = self.tixi.open(Config.path_cpacs_pm_ref) self.pathPerMap = "/cpacs/vehicles/aircraft/model[1]/analyses/aeroPerformanceMap" self.path_specific = path self.buttonBox = QtGui.QDialogButtonBox() self.buttonBox.addButton(QtGui.QDialogButtonBox.Ok) self.buttonBox.addButton(QtGui.QDialogButtonBox.Reset) self.buttonBox.addButton(QtGui.QDialogButtonBox.Cancel) self.comboBoxXAxis = QtGui.QComboBox() self.comboBoxXAxis.addItem("machNumber") self.comboBoxXAxis.addItem("reynoldsNumber") self.comboBoxXAxis.addItem("angleOfYaw") self.comboBoxXAxis.addItem("angleOfAttack") self.comboBoxPlotPnt = QtGui.QComboBox() self.comboBoxPlotPnt.addItem("curve") self.comboBoxPlotPnt.addItem("points") self.labelXAxis = QtGui.QLabel("set x-axis") self.labelDisplay = QtGui.QLabel("display") self.labelMachNum = QtGui.QLabel("machNumber") self.labelReynoldsNum = QtGui.QLabel("reynoldsNumber") self.labelAngleOfYaw = QtGui.QLabel("angleOfYaw") self.labelAngleOfAtt = QtGui.QLabel("angleOfAttack") self.listMachNum = QtGui.QListWidget() self.listReynoldsNum = QtGui.QListWidget() self.listAngleOfYaw = QtGui.QListWidget() self.listAngleOfAtt = QtGui.QListWidget() #self.comboBoxXAxis.setCurrentIndex(0) self.__hidePlotLists(True, False, False, False) self.__fillPlotLists(self.pathPerMap) self.grid = QtGui.QGridLayout() self.grid.addWidget(self.labelXAxis, 0,0,1,3) self.grid.addWidget(self.labelDisplay, 0,3) self.grid.addWidget(self.comboBoxXAxis, 1,0,1,3) self.grid.addWidget(self.comboBoxPlotPnt, 1,3) self.grid.addWidget(self.labelMachNum, 2,0) self.grid.addWidget(self.listMachNum, 3,0) self.grid.addWidget(self.labelReynoldsNum, 2,1) self.grid.addWidget(self.listReynoldsNum, 3,1) self.grid.addWidget(self.labelAngleOfYaw, 2,2) self.grid.addWidget(self.listAngleOfYaw, 3,2) self.grid.addWidget(self.labelAngleOfAtt, 2,3) self.grid.addWidget(self.listAngleOfAtt, 3,3) # set the layout layout = QtGui.QGridLayout() layout.addLayout(self.grid, 0,0,1,3) layout.addWidget(self.buttonBox, 5, 0, 1,3) widget = QtGui.QWidget() widget.setLayout(layout) self.setCentralWidget(widget) # =============================================================================================== # actions # =============================================================================================== self.comboBoxXAxis.currentIndexChanged.connect(self.fire_XAxisChanged) self.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked.connect(self.plot) self.buttonBox.button(QtGui.QDialogButtonBox.Reset).clicked.connect(self.reset) self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).clicked.connect(self.close)
def test_vector_array(self): t = Tixi() t.open(os.path.join("TestData", "vectorcount.xml")) self.assertEquals(t.getVectorSize("/a/aeroPerformanceMap/cfx"), 32) #v = t.getFloatVector("/a/aeroPerformanceMap/cfx", 32) #print v[0], v[1], v[-1] #1 2 118 t.close() # manual creation of vector t.create('doc') t.addFloatVector('/doc', 'myvec', range(100, 130), 30, "%g") size = t.getVectorSize('/doc/myvec') self.assertEquals(size, 30) v = t.getFloatVector('/doc/myvec', 30) self.assertEquals(v, tuple(range(100, 130))) t.close() t.open(os.path.join("TestData", "arraytests.xml")) self.assertEquals(t.getArrayDimensions("/root/aeroPerformanceMap"), 4) self.assertEquals( t.getArrayDimensionSizes("/root/aeroPerformanceMap", 4), ((1, 2, 3, 8), 48)) self.assertEquals( t.getArrayDimensionNames("/root/aeroPerformanceMap", 4), ("machNumber", "reynoldsNumber", "angleOfYaw", "angleOfAttack")) # print t.getArrayDimensionValues("/root/aeroPerformanceMap", 0) 1.0 # print t.getArrayDimensionValues("/root/aeroPerformanceMap", 2) 0 5 10 self.assertEquals(t.getArrayParameters("/root/aeroPerformanceMap"), 7) # print t.getArrayParameterNames("/root/aeroPerformanceMap") ("cfx", "cfy", "cfz", "cmx", "cmy", "cmz", "def") # print t.getArray("/root/aeroPerformanceMap", "cmx") None # print t.getArrayValue(arr, "/root/aeroPerformanceMap", "angleOfAttack") #8 #print t.getArrayElementNames("/root/aeroPerformanceMap", "vector") #print t.getArrayElementNames("/root/aeroPerformanceMap", "array") t.getArrayElementCount("/root/aeroPerformanceMap", "array") t.createElement("/root", "p1") t.addPoint("/root/p1", 1, 2, 3, None) self.assertEquals(t.getPoint("/root/p1"), (1.0, 2.0, 3.0)) self.assertEquals( t.xPathEvaluateNodeNumber("/root/aeroPerformanceMap"), 1) t.close() t.open(os.path.join("TestData", "in.xml")) self.assertEquals( t.xPathExpressionGetTextByIndex( "/plane/wings/wing/centerOfGravity/x", 2), "30.0") t.close() t.open(os.path.join("TestData", "uid_correct.xml")) t.uIDCheckDuplicates() t.uIDCheckExists("schlumpf") t.close() t.open(os.path.join("TestData", "uid_duplicated.xml")) self.assertRaises(TixiException, t.uIDCheckDuplicates) #UID_NOT_UNIQUE
def python_demo(filename): tixi = Tixi() tigl = Tigl() # open cpacs xml with tixi try: tixi.open(filename) except: print 'Error opening cpacs file with TiXI' return # enable logging of errors and warnings into file tigl.logSetFileEnding('txt') tigl.logSetTimeInFilenameEnabled(TiglBoolean.TIGL_FALSE) tigl.logToFileEnabled('demolog') # open cpacs with tigl try: tigl.open(tixi, '') except: print 'Error opening cpacs file with TiGL' return # query number of wings and fuselages and their names nWings = tigl.getWingCount() nFuselages = tigl.getFuselageCount() for i in range(1,nWings+1): wingUID = tigl.wingGetUID(i) print 'Wing %d name: %s' % (i, wingUID) for i in range(1,nFuselages+1): fuselageUID = tigl.fuselageGetUID(i) print 'Fuselage %d name: %s' % (i, fuselageUID) # query point on the upper wing surface if nWings > 0: (x,y,z) = tigl.wingGetUpperPoint(1, 1, 0.5, 0.5) print 'Point on upper wing surface of wing 1/segment 1: (x,y,z) = (%g, %g, %g)' %(x, y, z) # compute intersection of wing with a x-z plane if nWings > 0: wingUID = tigl.wingGetUID(1) # do the intersection with a plane at p = (0,0.5,0) and normal vector n = (0,1,0) int_id = tigl.intersectWithPlane(wingUID, 0, 0.5, 0, 0, 1, 0) # get number of intersection wires nlines = tigl.intersectGetLineCount(int_id) # query points on the first line if nlines > 0: zeta = 0. print '\nIntersection points of a plane with first wing:' while zeta < 1: (x,y,z) = tigl.intersectGetPoint(int_id, 1, zeta) print 'zeta = %g\tp=(%g, %g, %g)' % (zeta, x, y, z) zeta = zeta + 0.1 print # Export geometry to iges file print 'Exporting geometry to igesexport.igs' tigl.exportIGES('igesexport.igs') tigl.logToFileDisabled() tigl.close() tixi.close() tixi.cleanup()
def test_api(self): t = Tixi() self.assertEquals(t.version, t.getVersion()) t.create("root") t.addDoubleElement("/root", "myDouble", 3.2, 0) t.addIntegerElement("/root", "myInteger", 6, None) # Here starts the rest t.addBooleanElement("/root", "myBoolean", 0) t.updateDoubleElement("/root/myDouble", 3.14159262, 0) t.updateIntegerElement("/root/myInteger", 7, None) t.updateBooleanElement("/root/myBoolean", 1) t.addTextElementAtIndex("/root", "myNewTextElement", "myText", 2) t.createElementAtIndex("/root", "array", 0) t.addFloatVector("/root", "myFloatVector", (0.0, 1.1, 2.2), 3, "%g") t.addExternalLink("/root", "/externalLink", ".xml") t.addHeader("tool", "version", "author") t.addCpacsHeader("name", "creator", "version", "description", "cpacsVersion") t.usePrettyPrint(1) t.uIDCheckLinks() t.uIDSetToXPath("/root/myBoolean", "booleanID") self.assertEqual(t.uIDGetXPath("booleanID"), "/root/myBoolean") #t.dTDValidate() #t.xSLTransformationToFile() t.save(os.path.join("TestData", "test_save.xml")) t.close() t.cleanup()
class Plotter_DamingDerivates(QtGui.QMainWindow): def __init__(self, parent=None): super(Plotter_DamingDerivates, self).__init__(parent) self.tixi = Tixi() self.tixi.open("../cpacs_files/outputfile_PM_Ref.xml") self.buttonBox = QtGui.QDialogButtonBox() self.buttonBox.addButton(QtGui.QDialogButtonBox.Ok) self.buttonBox.addButton(QtGui.QDialogButtonBox.Reset) self.buttonBox.addButton(QtGui.QDialogButtonBox.Cancel) self.comboBoxXAxis = QtGui.QComboBox() self.comboBoxXAxis.addItem("machNumber") self.comboBoxXAxis.addItem("reynoldsNumber") self.comboBoxXAxis.addItem("angleOfYaw") self.comboBoxXAxis.addItem("angleOfAttack") self.comboBoxPlotPnt = QtGui.QComboBox() self.comboBoxPlotPnt.addItem("curve") self.comboBoxPlotPnt.addItem("points") self.labelXAxis = QtGui.QLabel("set x-axis") self.labelDisplay = QtGui.QLabel("display") self.labelMachNum = QtGui.QLabel("machNumber") self.labelReynoldsNum = QtGui.QLabel("reynoldsNumber") self.labelAngleOfYaw = QtGui.QLabel("angleOfYaw") self.labelAngleOfAtt = QtGui.QLabel("angleOfAttack") self.listMachNum = QtGui.QListWidget() self.listReynoldsNum = QtGui.QListWidget() self.listAngleOfYaw = QtGui.QListWidget() self.listAngleOfAtt = QtGui.QListWidget() self.__hidePlotLists(True, False, False, False) self.__fillPlotLists("/cpacs/vehicles/aircraft/model[1]/analyses/aeroPerformanceMap") self.grid = QtGui.QGridLayout() self.grid.addWidget(self.labelXAxis, 0,0,1,3) self.grid.addWidget(self.labelDisplay, 0,3) self.grid.addWidget(self.comboBoxXAxis, 1,0,1,3) self.grid.addWidget(self.comboBoxPlotPnt, 1,3) self.grid.addWidget(self.labelMachNum, 2,0) self.grid.addWidget(self.listMachNum, 3,0) self.grid.addWidget(self.labelReynoldsNum, 2,1) self.grid.addWidget(self.listReynoldsNum, 3,1) self.grid.addWidget(self.labelAngleOfYaw, 2,2) self.grid.addWidget(self.listAngleOfYaw, 3,2) self.grid.addWidget(self.labelAngleOfAtt, 2,3) self.grid.addWidget(self.listAngleOfAtt, 3,3) # set the layout layout = QtGui.QGridLayout() layout.addLayout(self.grid, 0,0,1,3) layout.addWidget(self.buttonBox, 5, 0, 1,3) widget = QtGui.QWidget() widget.setLayout(layout) self.setCentralWidget(widget) self.plotWidgets = [PlotWidget("dcfxdpstar"), PlotWidget("dcfxdqstar"), PlotWidget("dcfxdrstar"), PlotWidget("dcfydpstar"), PlotWidget("dcfydqstar"), PlotWidget("dcfydrstar"), PlotWidget("dcfzdpstar"), PlotWidget("dcfzdqstar"), PlotWidget("dcfzdrstar"), PlotWidget("dcmxdpstar"), PlotWidget("dcmxdqstar"), PlotWidget("dcmxdrstar"), PlotWidget("dcmydpstar"), PlotWidget("dcmydqstar"), PlotWidget("dcmydrstar"), PlotWidget("dcmzdpstar"), PlotWidget("dcmzdqstar"), PlotWidget("dcmzdrstar")] i = 0 ; l = len(self.plotWidgets) / 4 for widget in self.plotWidgets : if i < l : self.addSimpleWidget(widget, QtCore.Qt.LeftDockWidgetArea, True) elif i < 2 * l : self.addSimpleWidget(widget, QtCore.Qt.RightDockWidgetArea, True) else : self.addSimpleWidget(widget, QtCore.Qt.BottomDockWidgetArea, False) i+=1 # =============================================================================================== # actions # =============================================================================================== self.comboBoxXAxis.currentIndexChanged.connect(self.fire_XAxisChanged) self.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked.connect(self.plot) self.buttonBox.button(QtGui.QDialogButtonBox.Reset).clicked.connect(self.reset) self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).clicked.connect(self.close) def addSimpleWidget(self,widget, dockWidgetArea, flag_side): dock = QtGui.QDockWidget() dock.setWidget(widget) if flag_side : dock.setMinimumWidth(100) dock.setMinimumHeight(100) else: dock.setMinimumWidth(100) dock.setMinimumHeight(100) dock.setAllowedAreas(dockWidgetArea) dock.setFeatures(QtGui.QDockWidget.DockWidgetClosable | QtGui.QDockWidget.DockWidgetMovable | QtGui.QDockWidget.DockWidgetFloatable) self.addDockWidget(dockWidgetArea, dock) def fire_XAxisChanged(self, idx): self.reset() self.__setPlotListVisibility(idx == 0, idx == 1, idx == 2, idx == 3) def plot(self): x_axis_idx = self.comboBoxXAxis.currentIndex() mach_idx = self.listMachNum.currentRow() reyn_idx = self.listReynoldsNum.currentRow() yaw_idx = self.listAngleOfYaw.currentRow() att_idx = self.listAngleOfAtt.currentRow() path = "/cpacs/vehicles/aircraft/model[1]/analyses/aeroPerformanceMap" if x_axis_idx == 0 : x_axis = self.getMachNumberVector(path) elif x_axis_idx == 1 : x_axis = self.getReynoldsNumberVector(path) elif x_axis_idx == 2 : x_axis = self.getAngleOfYawVector(path) elif x_axis_idx == 3 : x_axis = self.getAngleOfAttackVector(path) ((mach, reyn, angleYaw, angleAtt), dimSize) = self.tixi.getArrayDimensionSizes(path, 4) display = self.comboBoxPlotPnt.currentText() displayOpt = 'go' if display == "points" else "" for widget in self.plotWidgets: array = self.getCoefficientArray(path + "/dampingDerivatives/positiveRates", widget.getTitle(), dimSize) widget.setXLabel(self.comboBoxXAxis.currentText()) widget.updatePlot(self.tixi, x_axis_idx, mach_idx, reyn_idx, yaw_idx, att_idx, mach, reyn, angleYaw, angleAtt, x_axis, array, path, displayOpt) def reset(self): for widget in self.plotWidgets: widget.updateReset() def __fillPlotLists(self, path): for item in self.getMachNumberVector(path) : self.listMachNum.addItem(str(item)) for item in self.getReynoldsNumberVector(path) : self.listReynoldsNum.addItem(str(item)) for item in self.getAngleOfYawVector(path) : self.listAngleOfYaw.addItem(str(item)) for item in self.getAngleOfAttackVector(path) : self.listAngleOfAtt.addItem(str(item)) def getAngleOfYawVector(self, path): return self.tixi.getFloatVector(path + "/angleOfYaw", self.tixi.getVectorSize(path + "/angleOfYaw")) def getAngleOfAttackVector(self, path): return self.tixi.getFloatVector(path + "/angleOfAttack", self.tixi.getVectorSize(path + "/angleOfAttack")) def getReynoldsNumberVector(self, path): return self.tixi.getFloatVector(path + "/reynoldsNumber", self.tixi.getVectorSize(path + "/reynoldsNumber")) def getMachNumberVector(self, path): return self.tixi.getFloatVector(path + "/machNumber", self.tixi.getVectorSize(path + "/machNumber")) def getCoefficientArray(self, path, child, num): return self.tixi.getArray(path, child, num) def __hidePlotLists(self, flag_mach, flag_reyn, flag_yaw, flag_att): self.__setPlotListVisibility(flag_mach, flag_reyn, flag_yaw, flag_att) def __setPlotListVisibility(self, flag_mach, flag_reyn, flag_yaw, flag_att): self.labelMachNum.setHidden(flag_mach) self.labelReynoldsNum.setHidden(flag_reyn) self.labelAngleOfYaw.setHidden(flag_yaw) self.labelAngleOfAtt.setHidden(flag_att) self.listMachNum.setHidden(flag_mach) self.listReynoldsNum.setHidden(flag_reyn) self.listAngleOfYaw.setHidden(flag_yaw) self.listAngleOfAtt.setHidden(flag_att)
def test_attributes(self): t = Tixi() t.open(os.path.join("TestData", "in.xml")) self.assertEquals( t.getTextAttribute("/plane/wings/wing[1]", "position"), "left") self.assertEquals( t.getIntegerAttribute("/plane/wings", "numberOfWings"), 2) t.addIntegerAttribute("/plane", "intattr", 324, None) self.assertEquals(t.getIntegerAttribute("/plane", "intattr"), 324) t.removeAttribute("/plane", "intattr") self.assertEquals( t.getDoubleAttribute("/plane/coordinateOrigin", "scaling"), 1.3456) self.assertFalse(t.checkAttribute( "/plane", "doubleattr")) # ATTRIBUTE_NOT_FOUND \n t.addDoubleAttribute("/plane", "doubleattr", 123.456, None) t.checkAttribute("/plane", "doubleattr") self.assertEquals(t.getDoubleAttribute("/plane", "doubleattr"), 123.456) t.removeAttribute("/plane", "doubleattr") t.addTextAttribute("/plane", "attr", "val") self.assertEquals(t.getTextAttribute("/plane", "attr"), "val") self.assertEquals(t.getNamedChildrenCount("/plane/wings", "wing"), 2) t.addDoubleListWithAttributes("/plane", "list", "elem", "attr", [1., 2., 3.], None, ["a", "b", "c"], 3) self.assertEquals(t.getTextAttribute("/plane/list/elem[1]", "attr"), "a") self.assertEquals(t.getDoubleElement("/plane/list/elem[3]"), 3.0) t.close()
def python_demo(filename): tixi = Tixi() tigl = Tigl() # open cpacs xml with tixi try: tixi.open(filename) except: print 'Error opening cpacs file with TiXI' return # enable logging of errors and warnings into file tigl.logSetFileEnding('txt') tigl.logSetTimeInFilenameEnabled(TiglBoolean.TIGL_FALSE) tigl.logToFileEnabled('demolog') # open cpacs with tigl try: tigl.open(tixi, '') except: print 'Error opening cpacs file with TiGL' return # query number of wings and fuselages and their names nWings = tigl.getWingCount() nFuselages = tigl.getFuselageCount() for i in range(1, nWings + 1): wingUID = tigl.wingGetUID(i) print 'Wing %d name: %s' % (i, wingUID) for i in range(1, nFuselages + 1): fuselageUID = tigl.fuselageGetUID(i) print 'Fuselage %d name: %s' % (i, fuselageUID) # query point on the upper wing surface if nWings > 0: (x, y, z) = tigl.wingGetUpperPoint(1, 1, 0.5, 0.5) print 'Point on upper wing surface of wing 1/segment 1: (x,y,z) = (%g, %g, %g)' % ( x, y, z) # compute intersection of wing with a x-z plane if nWings > 0: wingUID = tigl.wingGetUID(1) # do the intersection with a plane at p = (0,0.5,0) and normal vector n = (0,1,0) int_id = tigl.intersectWithPlane(wingUID, 0, 0.5, 0, 0, 1, 0) # get number of intersection wires nlines = tigl.intersectGetLineCount(int_id) # query points on the first line if nlines > 0: zeta = 0. print '\nIntersection points of a plane with first wing:' while zeta < 1: (x, y, z) = tigl.intersectGetPoint(int_id, 1, zeta) print 'zeta = %g\tp=(%g, %g, %g)' % (zeta, x, y, z) zeta = zeta + 0.1 print # Export geometry to iges file print 'Exporting geometry to igesexport.igs' tigl.exportIGES('igesexport.igs') tigl.logToFileDisabled() tigl.close() tixi.close() tixi.cleanup()