def ask_xml_file(message, object_type=""): """ Ask for an XML file and do some checks """ verif_choix = False while not verif_choix: filename = ask_input_file(message) verif_choix = filename.endswith(".xml") if not verif_choix: print(filename+" is not a XML file !") # Some checks if object_type == "engine" or object_type == "building": # Build an empty project Project.create() import_infra(filename, object_type) return filename
def test_import_infra(self): """ Test loading an infrastructure """ project = Project.create() # Read an engine and check infra = import_infra("A320.xml", "engine") self.assertEqual(len(infra.engines), 1) engine = infra.engines[0] self.assertEqual(engine.name, "Machine 0") self.assertEqual(engine.hauteur, 0.0) # Local frame: self.assertEqual(engine.position.x, 0.0) self.assertEqual(engine.position.y, 0.0) self.assertEqual(engine.position.z, 0.0) # Read a building and check infra = import_infra("Building.xml", "building") self.assertEqual(len(infra.buildings), 1) building = infra.buildings[0] self.assertEqual(building.name, "MyBuilding") self.assertEqual(building.hauteur, 0.0) # Local frame: self.assertEqual(building.position.x, 0.0) self.assertEqual(building.position.y, 0.0) self.assertEqual(building.position.z, 0.0) # Check a no radiant building is refused: try: infra = import_infra("Building_no_radiant.xml", "building") except: print("Ok, non radiant building is refused as expected.") else: print("Non radiant building should be refused.") sys.exit(-1)
import os from tympan.models.project import Project if __name__ == "__main__": print("Tentative de création d'un projet TYMPAN ex nihilo") proj = Project(Project.create()) proj.create() proj.to_xml("toto.xml") print("That's all folks !")
def main(object_file_list, object_positions_file_list, object_type_list, object_name_list, input_xml, output_xml): """ Import csv file with TYMPAN coordinates and create new project with objects Or add objects to an existing project """ # Create new project if no project entered by user project = Project.create() if input_xml == '' else Project.from_xml( input_xml) # Loop on objects for object_file, object_positions_file, object_type, object_name in zip( object_file_list, object_positions_file_list, object_type_list, object_name_list): # Import the object read in the xml file: if object_file != "": # Import the elements from XML file: elements = import_infra(object_file, object_type) # Create numpy array with csv file containing TYMPAN coordinates of the objects my_data = np.genfromtxt(object_positions_file, dtype='float', delimiter=';', skip_header=1) if my_data.shape[1] < 3: print("Error! Should read x,y,z or x,y,z,angle in " + object_positions_file) sys.exit(-1) # Add object to project site for each position site = project.site rotation = Point3D(0, 0, 0) for i in range(len(my_data[:, 0])): position = Point3D() height = my_data[i, 2] position.set_x(my_data[i, 0]) position.set_y(my_data[i, 1]) position.set_z(height) # Add rotation if found if my_data.shape[1] == 4: rotation.set_z(my_data[i, 3]) name = object_name + str(i) # Add object: if object_type == "source": # Source src = User_source(height, name, position) site.add_user_source(src, position, height) elif object_type == "receptor": # Receptor project.add_user_receptor(position, height, name) elif object_type == "engine": # Engine site.add_engine(elements.engines[0], position, rotation, height) elif object_type == "building": # Building site.add_building(elements.buildings[0], position, rotation, height) else: print("Error: Unknown object type: ", object_type) sys.exit(-1) # Add project user_receptors to the last computation if object_type == "receptor": calcul = project.computations[-1] for rec in project.user_receptors: calcul.addReceptor(rec) # Write the project project.to_xml(output_xml) print('Project saved to ', output_xml)