| /******************************************************************************* |
| * Copyright (c) 2018 Robert Bosch GmbH. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Robert Bosch GmbH - initial API and implementation |
| *******************************************************************************/ |
| |
| package templates |
| |
| import SampleModel.SampleModelFactory |
| import com.google.inject.Inject |
| import java.io.File |
| import org.eclipse.app4mc.amalthea.model.Amalthea |
| import org.eclipse.app4mc.amalthea.model.HWModel |
| import org.eclipse.app4mc.amalthea.model.MappingModel |
| import org.eclipse.app4mc.amalthea.model.OSModel |
| import org.eclipse.app4mc.transformation.extensions.base.templates.Model2ModelRootTransformer |
| import org.eclipse.emf.common.util.URI |
| import org.eclipse.emf.ecore.resource.ResourceSet |
| |
| class AmaltheaModel2ModelTransformer extends Model2ModelRootTransformer { |
| |
| /*- Factory initiaization */ |
| val outputModelFactory = SampleModelFactory.eINSTANCE |
| |
| /*- Transformer classes initiaization */ |
| @Inject extension SWTransformer sw |
| |
| @Inject extension HWTransformer hw |
| |
| @Inject extension OSTransformer os |
| |
| @Inject extension MappingTransformer mt |
| |
| 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("m2m_output_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 outputModelFactory.createModel transform(Amalthea amalthea) { |
| |
| customObjsStore.injectMembers(SWTransformer, sw) |
| |
| customObjsStore.injectMembers(HWTransformer, hw) |
| |
| customObjsStore.injectMembers(OSTransformer, os) |
| |
| customObjsStore.injectMembers(MappingTransformer, mt) |
| |
| hw.transfromHWModel(amalthea.hwModel as HWModel, it) |
| |
| os.transfromOSModel(amalthea.osModel as OSModel, it) |
| |
| mt.transfromMappingModel(amalthea.mappingModel as MappingModel, it) |
| |
| } |
| |
| } |