From Microsoft Visio to MetaEdit+ via Eclipse EMF

The approach of M3-Level-based Bridges (M3B) is very powerful to achieve interoperability between modeling tools.  In this article we want present a further interesting M3B application that allows the import of Visio models into MetaEdit+.

Our solution uses the following tools/components:

The import of Visio models works as follows. First, we need corresponding language definitions in both tools. In this article, we use as example the EPC language that is already available in Visio (as a default stencil) and MetaEdit+ (see this article “Processing of MetaEdit+ Models with oAW“). These two language definitions are transformed with the help of the two M3Bs into Ecore models (visio_epc.ecore and metaedit_epc.ecore). Based on these Ecore models, we can define a migration (model-to-model transformation) that transforms visio_epc.ecore into metaedit_epc.ecore. Now, we can import with the Visio-EMF-Bridge a Visio model (visio_epc_model.xmi). This Visio-EMF model is the input of the migration that creates a MetaEdit-EMF model (metaedit_epc_model.xmi). Finally, we can import this MetaEdit-EMF model with the MetaEdit-EMF-Bridge into MetaEdit+. The complete process is shown in the following screencast: From Visio to MetaEdit+.

Language Migration

The actual work to import Visio models lies in the definition of the transformation between visio_epc.ecore and metaedit_epc.ecore. Hence, we want to talk about this transformation.  We use as transformation language ETL/EOL from Epsilon (Other EMF-based transformation tools, such as ATL or oAW, are also possible.) The script can be divided into two parts. The first part contains language-independent rules that transform a Visio document into a MetaEdit project and a Visio page into a MetaEdit graph with corresponding diagram. The both operations select the position of a Visio shape and the post processing step transforms the different coordinate systems.

rule Document2Project
	transform document : Visio!EVisioDocument
  	to project : MetaEdit!Me_Project
  	{
  		project.me_containGraphs := document.visioPages.equivalent();
  		project.me_containObjects := MetaEdit!Me_Object.allInstances();
  		project.me_containRelationships := MetaEdit!Me_Relationship.allInstances();
  		project.me_containRoles := MetaEdit!Me_Role.allInstances();
  	}
 
@abstract
rule Page2Graph
	transform page : Visio!EVisioPage
	to graph : MetaEdit!Me_Graph
	{
		var diagram := new MetaEdit!Me_Diagram;
		graph.me_containDiagrams.add(diagram);
 
		var simpleShapes := page.visioContainedShapes->select(e | not e.isKindOf(Visio!EVisioConnectionShape));
		graph.me_referenceObjects := simpleShapes.equivalent();
		for (shape : Visio!EVisioShape in simpleShapes) {
			var symbol := new MetaEdit!Me_Symbol;
			diagram.me_containSymbols.add(symbol);
			symbol.me_refObject := shape.equivalent();
			symbol.me_position := shape.getPinX()+','+shape.getPinY();
		}
 
		var conShapes := page.visioContainedShapes->select(e | e.isKindOf(Visio!EVisioConnectionShape));
		graph.me_referenceRelationships := conShapes.equivalent().select(e | e.isKindOf(MetaEdit!Me_Relationship));
		graph.me_referenceRoles := conShapes.equivalent().select(e | e.isKindOf(MetaEdit!Me_Role));
 
	}	
 
operation Visio!EVisioShape getPinX() : Integer {
	return self.visioShapeSheet
		.visioSections.select(e | e.visioName = 'visSectionObject').first()
		.visioRows.select(e | e.visioName = '1').first()
		.visioCells.select(e | e.visioName = 'PinX').first()
		.visioValue.asReal();
}
 
operation Visio!EVisioShape getPinY() : Integer {
	return self.visioShapeSheet
		.visioSections.select(e | e.visioName = 'visSectionObject').first()
		.visioRows.select(e | e.visioName = '1').first()
		.visioCells.select(e | e.visioName = 'PinY').first()
		.visioValue.asReal();
}
 
post CoordinateTransformation {
 
	var ymax : Real := MetaEdit!Me_Symbol.allInstances.sortBy(e|e.me_position.split(',').last())
		.last().me_position.split(',').last().asReal();
 
	for (symbol : MetaEdit!Me_Symbol in MetaEdit!Me_Symbol.allInstances) {
		var x : Real := symbol.me_position.split(',').first().asReal();
		var y : Real := symbol.me_position.split(',').last().asReal();
 
		x := x*100;
		y := (ymax*120+20)-y*100;
 
		symbol.me_position := x.asInteger() + ',' + y.asInteger();
	}
}

The second part of the script is more interesting than the first one, because this is the language-dependent part that maps the different language types. For instance, we map VisioEvent to MetaEditEvent, VisioFunction to MetaEditFunction and so on. These rules are very easy and that is what we want. We hide the complexity of tool interfaces, thus, we are able to concentrate on the language migration.

---------------------
-- EPC-Transformation
---------------------
rule VisioEpc2MetaEditEpc
	transform page : Visio!EVisioPage
	to graph : MetaEdit!Event_Driven_Process_Chain_3395083925
	extends Page2Graph
	{
		graph.Name := page.visioName;
	}
 
rule VisioEvent2MetaEditEvent
	transform shape : Visio!Ereignis
	to object : MetaEdit!Event_3395083771
	{
		object.Name := shape.visioText;
	}
 
rule VisioFunction2MetaEditFunction
	transform shape : Visio!Funktion
	to object : MetaEdit!Function_3395083784
	{
		object.Name := shape.visioText;
	}
 
rule VisioXOR2MetaEditXOR
	transform shape : Visio!XOR
	to object : MetaEdit!XOR_3395083733 {}
 
rule VisioOR2MetaEditOR
	transform shape : Visio!OR
	to object : MetaEdit!OR_3395083742 {}
 
rule VisioAND2MetaEditAND
	transform shape : Visio!AND
	to object : MetaEdit!AND_3395083748 {}
 
rule VisioConnection2MetaEditArc
	transform shape : Visio!Dynamischer_Verbinder
	to relation : MetaEdit!Arc_3395083800,
	fromRole : MetaEdit!From_3395083804,
	toRole : MetaEdit!To_3395083810
	{
		relation.me_role.add(fromRole);
		relation.me_role.add(toRole);
		fromRole.me_object := shape.visioSourceShape.equivalent();
		toRole.me_object := shape.visioTargetShape.equivalent();
	}

Download

Dieser Beitrag wurde unter Allgemeines abgelegt und mit , , , verschlagwortet. Setze ein Lesezeichen auf den Permalink.

Eine Antwort auf From Microsoft Visio to MetaEdit+ via Eclipse EMF

  1. Pingback: From MetaEdit+ to Microsoft Visio via Eclispe EMF « Service and Integration Technology

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

*

*

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">