| package com.bosch.m2m.app4mc.m2m.transformation.core.m2m.templates |
| |
| import com.google.inject.Inject |
| import java.io.BufferedWriter |
| import java.io.File |
| import java.io.FileWriter |
| import org.eclipse.app4mc.SampleSimulation.SimulationFactory |
| import org.eclipse.app4mc.amalthea.model.Amalthea |
| import org.eclipse.app4mc.transformation.extensions.base.templates.RootTransformer |
| import org.eclipse.emf.common.util.URI |
| import org.eclipse.emf.ecore.resource.ResourceSet |
| import com.bosch.m2m.app4mc.m2m.transformation.core.m2t.templates.M2T_Output_Transformer |
| |
| class AmaltheaTransformer extends RootTransformer{ |
| |
| /*- Factory initiaization */ |
| val simulationRootFactory = SimulationFactory.eINSTANCE |
| |
| |
| /*- Transformer classes initiaization */ |
| @Inject extension SWTransformer sw |
| |
| @Inject extension HWTransformer hw |
| |
| @Inject extension OSTransformer os |
| |
| @Inject extension MappingTransformer mt |
| |
| |
| override m2tTransformation(ResourceSet inputResourceSet ) { |
| var int fileIndex=1 |
| for(resource : inputResourceSet.resources){ |
| for(content : resource.contents){ |
| //TODO: content is a Amalthea model |
| //check javadoc : https://www.eclipse.org/xtend/documentation/204_activeannotations.html#active-annotations-expression |
| logger.info("Processing file : "+resource.URI) |
| |
| var String outputFileName=getProperty("m2t_file"); |
| var outputFile=new File(outputFileName) |
| |
| outputFile.parentFile.mkdirs |
| |
| outputFile.createNewFile |
| |
| val scriptGenerator=new M2T_Output_Transformer |
| |
| if(content instanceof Amalthea){ |
| val scriptContent = scriptGenerator.generateOutputTextFile(content) |
| |
| /*saving buffer into file */ |
| val bufferedWriter=new BufferedWriter(new FileWriter(outputFile)) |
| bufferedWriter.write(scriptContent) |
| bufferedWriter.close |
| |
| } |
| |
| //TODO: save the file here |
| |
| logger.info("Python model file generated at : "+ outputFileName) |
| |
| } |
| } |
| |
| } |
| override m2mTransformation(ResourceSet inputResourceSet, ResourceSet outputResourceSet) { |
| |
| var int fileIndex=1 |
| |
| for(resource : inputResourceSet.resources){ |
| for(content : resource.contents){ |
| //content is a Amalthea model |
| |
| logger.info("Processing file : "+resource.URI) |
| |
| val simulationModelRoot=transform(content as Amalthea) |
| |
| val out_uri=URI.createFileURI(getProperty("simulation_models_folder")+File.separator+fileIndex+++".root") |
| |
| val out_resource=outputResourceSet.createResource(out_uri) |
| |
| out_resource.contents.add(simulationModelRoot) |
| |
| out_resource.save(null) |
| |
| logger.info("Transformed model file generated at : "+ out_uri) |
| |
| } |
| } |
| } |
| |
| |
| |
| def create simulationRootFactory.createModel transform(Amalthea amalthea){ |
| |
| customObjsStore.injectMembers(SWTransformer , sw) |
| |
| customObjsStore.injectMembers(HWTransformer , hw) |
| |
| customObjsStore.injectMembers(OSTransformer , os) |
| |
| customObjsStore.injectMembers(MappingTransformer , mt) |
| |
| |
| hw.transfromHWModel(amalthea.hwModel,it) |
| |
| os.transfromOSModel(amalthea.osModel,it) |
| |
| mt.transfromMappingModel(amalthea.mappingModel,it) |
| |
| } |
| |
| } |