blob: ba221a2b35e51ca99998e384cecfbb7db4c4523c [file] [log] [blame]
/**
********************************************************************************
* Copyright (c) 2018-2021 Robert Bosch GmbH and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Robert Bosch GmbH - initial API and implementation
********************************************************************************
*/
package app4mc.example.transform.m2m.transformers
import app4mc.example.transform.samplemodel.SampleModelFactory
import java.io.File
import java.util.Map
import org.eclipse.app4mc.amalthea.model.Amalthea
import org.eclipse.app4mc.amalthea.model.HWModel
import org.eclipse.app4mc.transformation.ServiceConstants
import org.eclipse.app4mc.transformation.transformers.Model2ModelRootTransformer
import org.eclipse.app4mc.transformation.util.PropertyUtil
import org.eclipse.emf.common.util.URI
import org.eclipse.emf.ecore.resource.ResourceSet
import org.osgi.service.component.annotations.Activate
import org.osgi.service.component.annotations.Component
import org.osgi.service.component.annotations.ConfigurationPolicy
import org.osgi.service.component.annotations.Reference
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@Component(
configurationPid = ServiceConstants.SESSION_CONFIGURATION_PID,
configurationPolicy = ConfigurationPolicy.REQUIRE,
property = #[ "transformation=Amalthea2SampleModel" ],
service = Model2ModelRootTransformer
)
class AmaltheaModel2ModelTransformer extends Model2ModelRootTransformer {
static final Logger LOG = LoggerFactory.getLogger(typeof(AmaltheaModel2ModelTransformer))
/*- Factory initiaization */
val outputModelFactory = SampleModelFactory.eINSTANCE
String outputFolder
@Reference HWTransformer hardwareTransformer
@Activate
def package void activate(Map<String, ?> properties) {
LOG.debug("AmaltheaModel2ModelTransformer activated")
outputFolder = PropertyUtil.getProperty("m2m_output_folder", properties)
}
override m2mTransformation(ResourceSet inputResourceSet, ResourceSet outputResourceSet) {
LOG.debug("HWTransformer : "+hardwareTransformer.hashCode())
var int fileIndex = 1
for (resource : inputResourceSet.resources) {
for (content : resource.contents) {
LOG.info("Processing file : " + resource.URI)
val simulationModelRoot = transform(content as Amalthea)
val out_uri = URI.createFileURI(
outputFolder + File.separator + fileIndex++ + ".root")
val out_resource = outputResourceSet.createResource(out_uri)
out_resource.contents.add(simulationModelRoot)
out_resource.save(null)
LOG.info("Transformed model file generated at : " + out_uri)
}
}
}
def create outputModelFactory.createModel transform(Amalthea amalthea) {
hardwareTransformer.transfromHWModel(amalthea.hwModel as HWModel, it)
}
}