Skip to main content



      Home
Home » Modeling » ATL » GUIDE ATL(use ATL)
GUIDE ATL [message #1841680] Tue, 25 May 2021 11:09 Go to next message
Eclipse UserFriend
I wrote this rule in ATL :
rule ListOfPart2MExpert {
	from nomenclature : ListOfPart!CI
	to ME : MExpert!MExpert(),
	p :MExpert!pou (
					   name<-'POU_Principal',
					   pouType<-'program' --,

					   ),
	 a :MExpert!localVars(), 
	variable:MExpert!variables(
		  		name <-nomenclature.nature 
				),
	t:MExpert!type(
		REAL<- if nomenclature.type='WORD'
				then 
					VR
				else
					OclUndefined 
				endif,
		BOOL<- if nomenclature.type='STRING'
				then 
					VB
				else
						OclUndefined 
				endif
			),
	VR :MExpert!REAL(),
	VB :MExpert!BOOL(),
	b :MExpert!FBD() 
}


and I got that :

  <pou name="POU_Principal" pouType="program"/>
  <localVars/>
  <variables name="Type"/>
  <type/>
  <REAL/>
  <BOOL/>
  <FBD/>
  <MExpert/>
  <pou name="POU_Principal" pouType="program"/>
  <localVars/>
  <variables name="Unité"/>
  <type/>
  <REAL/>
  <BOOL/>
  <FBD/>
  <MExpert/>
  <pou name="POU_Principal" pouType="program"/>
  <localVars/>
  <variables name="Offset"/>
  <type/>
  <REAL/>
  <BOOL/>
  <FBD/>
  <MExpert/>
  <pou name="POU_Principal" pouType="program"/>
  <localVars/>
  <variables name="Date"/>
  <type/>
  <REAL/>
  <BOOL/>
  <FBD/>
  <MExpert/>
  <pou name="POU_Principal" pouType="program"/>
  <localVars/>
  <variables name="Donnée_1"/>
  <type/>
  <REAL/>
  <BOOL/>
  <FBD/>
  <MExpert/>
  <pou name="POU_Principal" pouType="program"/>
  <localVars/>
  <variables name="Donnée_2"/>
  <type/>
  <REAL/>
  <BOOL/>
  <FBD/>
  <MExpert/>
  <pou name="POU_Principal" pouType="program"/>
  <localVars/>
  <variables name="Donnée_3"/>
  <type/>
  <REAL/>
  <BOOL/>
  <FBD/>
  <MExpert/>
  <pou name="POU_Principal" pouType="program"/>
  <localVars/>
  <variables name="Donnée_4"/>
  <type/>
  <REAL/>
  <BOOL/>
  <FBD/>
  <MExpert/>
  <pou name="POU_Principal" pouType="program"/>
  <localVars/>
  <variables name="Nom"/>
  <type/>
  <REAL/>
  <BOOL/>
  <FBD/>


But my objectif is to get this structure
<pou name="POU_Principal" pouType="program">
                <interface>
                  <localVars>
                    <variable name="Val4_MxIn">
                      <type>
                        <REAL />
                      </type>
                    </variable>
                    <variable name="Val5_MiOu">
                      <type>
                        <REAL />
                      </type>
                    </variable>
                    <variable name="Val6_MxOu">
                      <type>
                        <REAL />
                      </type>
                    </variable>
                    <variable name="Val7_BOOL">
                      <type>
                        <BOOL />
                      </type>
                    </variable>
                    <variable name="Sortie_1_BOOL">
                      <type>
                        <BOOL />
                      </type>
                    </variable>
                    <variable name="Sortie_2_REAL">
                      <type>
                        <REAL />
                      </type>
                    </variable>
                    <variable name="Sortie_3_BOOL">
                      <type>
                        <BOOL />
                      </type>
                    </variable>
                    <variable name="Sortie_4_UINT">
                      <type>
                        <UINT />
                      </type>
                    </variable>
                    <variable name="Exemple_Temperature">
                      <type>
                        <derived name="FB_Scaling" />
                      </type>
                    </variable>
                  </localVars>
                </interface>

as you notice, these lines
<pou name="POU_Principal" pouType="program"/>
 <localVars/>
<FBD/>
 <MExpert/>

repeat until the end
Re: GUIDE ATL [message #1841687 is a reply to message #1841680] Tue, 25 May 2021 13:32 Go to previous messageGo to next message
Eclipse UserFriend
You need to set the containment properties of each model element to have nested elements in your result, i.e. pou.interface, interface.localVars, etc.
Re: GUIDE ATL [message #1841770 is a reply to message #1841687] Fri, 28 May 2021 03:26 Go to previous messageGo to next message
Eclipse UserFriend
I didn't find where I can modify
Re: GUIDE ATL [message #1841786 is a reply to message #1841770] Fri, 28 May 2021 12:59 Go to previous messageGo to next message
Eclipse UserFriend
Can you share the MExpert metamodel?
Re: GUIDE ATL [message #1841844 is a reply to message #1841786] Tue, 01 June 2021 03:04 Go to previous messageGo to next message
Eclipse UserFriend
Of course
  • Attachment: Capture1.PNG
    (Size: 34.68KB, Downloaded 113 times)
Re: GUIDE ATL [message #1841845 is a reply to message #1841786] Tue, 01 June 2021 03:05 Go to previous messageGo to next message
Eclipse UserFriend
and this is the MM of ListOfPart:
  • Attachment: Capture1.PNG
    (Size: 29.92KB, Downloaded 112 times)
Re: GUIDE ATL [message #1841851 is a reply to message #1841786] Tue, 01 June 2021 05:21 Go to previous messageGo to next message
Eclipse UserFriend
I made some modification to the transformation code and to the metamodel of MExpert,
The code :
rule ListOfPart2MExpert {
	from nomenclature : ListOfPart!CI
	to 	p :MExpert!pou (
					   name<-'POU_Principal',
					   pouType<-'program' ,
					   interface<-a
					   ),
	 a :MExpert!Interface(
	 	localVars<-l
	 ), 
	l :MExpert!localVars(
		variable<-v
	),
	v :MExpert!variables(
		  		name <-nomenclature.nature,
				type<-t
				),
	t :MExpert!type(
		REAL<- if nomenclature.type='WORD'
				then 
					VR
				else
					OclUndefined 
				endif,
		BOOL<- if nomenclature.type='STRING'
				then 
					VB
				else
						OclUndefined 
				endif
			),
	VR :MExpert!REAL(),
	VB :MExpert!BOOL()
	
}

And I got this
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns="MachineExpert">
  <pou name="POU_Principal" pouType="program">
    <interface>
      <localVars>
        <variable name="Type">
          <type/>
        </variable>
      </localVars>
    </interface>
  </pou>
  <REAL/>
  <BOOL/>
  <pou name="POU_Principal" pouType="program">
    <interface>
      <localVars>
        <variable name="Unité">
          <type/>
        </variable>
      </localVars>
    </interface>
  </pou>
  <REAL/>
  <BOOL/>
  <pou name="POU_Principal" pouType="program">
    <interface>
      <localVars>
        <variable name="Offset">
          <type/>
        </variable>
      </localVars>
    </interface>
  </pou>
  <REAL/>
  <BOOL/>
  <pou name="POU_Principal" pouType="program">
    <interface>
      <localVars>
        <variable name="Date">
          <type/>
        </variable>
      </localVars>
    </interface>
  </pou>
  <REAL/>
  <BOOL/>
  <pou name="POU_Principal" pouType="program">
    <interface>
      <localVars>
        <variable name="Donnée_1">
          <type/>
        </variable>
      </localVars>
    </interface>
  </pou>
  <REAL/>
  <BOOL/>
  <pou name="POU_Principal" pouType="program">
    <interface>
      <localVars>
        <variable name="Donnée_2">
          <type/>
        </variable>
      </localVars>
    </interface>
  </pou>
  <REAL/>
  <BOOL/>
  <pou name="POU_Principal" pouType="program">
    <interface>
      <localVars>
        <variable name="Donnée_3">
          <type/>
        </variable>
      </localVars>
    </interface>
  </pou>
  <REAL/>
  <BOOL/>
  <pou name="POU_Principal" pouType="program">
    <interface>
      <localVars>
        <variable name="Donnée_4">
          <type/>
        </variable>
      </localVars>
    </interface>
  </pou>
  <REAL/>
  <BOOL/>
  <pou name="POU_Principal" pouType="program">
    <interface>
      <localVars>
        <variable name="Nom">
          <type/>
        </variable>
      </localVars>
    </interface>
  </pou>
  <REAL/>
  <BOOL/>
</xmi:XMI>

  • Attachment: Capture1.PNG
    (Size: 53.31KB, Downloaded 114 times)
Re: GUIDE ATL [message #1841909 is a reply to message #1841851] Wed, 02 June 2021 15:36 Go to previous messageGo to next message
Eclipse UserFriend
You appear to understand the principle now, where you need to assign values to the containment properties (interface, localVars, variable, ...) in order to have contained XMI elements.

However, none of the "if nomenclature.type=..." conditions in your transformation code seem to trigger, as no values are assigned to the REAL or BOOL property. You can debug this situation by inserting the "debug()" helper method into your code. Also, the VR and VB models elements are always created, whereas you likely meant to only create the value object of the applicable type instead of all of them. This can be achieved by using lazy rules.

Here's a reworked example (assumes you use EMFTVM):
rule ListOfPart2MExpert {
	from nomenclature : ListOfPart!CI
	to p :MExpert!pou (
		name<-'POU_Principal',
		pouType<-'program' ,
		interface<-a
	),
	a :MExpert!Interface(
		localVars<-l
	), 
	l :MExpert!localVars(
		variable<-v
	),
	v :MExpert!variables(
		name <-nomenclature.nature,
		type<-t
	),
	t :MExpert!type(
		REAL<- thisModule.RealValue(nomenclature),
		BOOL<- thisModule.BoolValue(nomenclature)
	)
}

lazy rule RealValue {
	from nomenclature : ListOfPart!CI (
		nomenclature.type.debug('RealValue')='WORD')
	to VR :MExpert!REAL
}

lazy rule BoolValue {
	from nomenclature : ListOfPart!CI (
		nomenclature.type.debug('RealValue')='STRING')
	to VR :MExpert!BOOL
}
Re: GUIDE ATL [message #1841915 is a reply to message #1841909] Thu, 03 June 2021 03:13 Go to previous messageGo to next message
Eclipse UserFriend
This code allows me to have this structure:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns="MachineExpert">
  <pou name="POU_Principal" pouType="program">
    <interface>
      <localVars>
        <variable name="Type">
          <type>
            <REAL/>
            <BOOL/>
          </type>
        </variable>
      </localVars>
    </interface>
  </pou>
  <pou name="POU_Principal" pouType="program">
    <interface>
      <localVars>
        <variable name="Unité">
          <type>
            <REAL/>
            <BOOL/>
          </type>
        </variable>
      </localVars>
    </interface>
  </pou>
  <pou name="POU_Principal" pouType="program">
    <interface>
      <localVars>
        <variable name="Offset">
          <type>
            <REAL/>
            <BOOL/>
          </type>
        </variable>
      </localVars>
    </interface>
  </pou>
  <pou name="POU_Principal" pouType="program">
    <interface>
      <localVars>
        <variable name="Date">
          <type>
            <REAL/>
            <BOOL/>
          </type>
        </variable>
      </localVars>
    </interface>
  </pou>
  <pou name="POU_Principal" pouType="program">
    <interface>
      <localVars>
        <variable name="Donnée_1">
          <type>
            <REAL/>
            <BOOL/>
          </type>
        </variable>
      </localVars>
    </interface>
  </pou>
  <pou name="POU_Principal" pouType="program">
    <interface>
      <localVars>
        <variable name="Donnée_2">
          <type>
            <REAL/>
            <BOOL/>
          </type>
        </variable>
      </localVars>
    </interface>
  </pou>
  <pou name="POU_Principal" pouType="program">
    <interface>
      <localVars>
        <variable name="Donnée_3">
          <type>
            <REAL/>
            <BOOL/>
          </type>
        </variable>
      </localVars>
    </interface>
  </pou>
  <pou name="POU_Principal" pouType="program">
    <interface>
      <localVars>
        <variable name="Donnée_4">
          <type>
            <REAL/>
            <BOOL/>
          </type>
        </variable>
      </localVars>
    </interface>
  </pou>
  <pou name="POU_Principal" pouType="program">
    <interface>
      <localVars>
        <variable name="Nom">
          <type>
            <REAL/>
            <BOOL/>
          </type>
        </variable>
      </localVars>
    </interface>
  </pou>
</xmi:XMI>

and it's not quite the structure I'm looking for. I still tried to improve my code:
rule ListOfPart2MExpert {
	from nomenclature : ListOfPart!Instance
	to 	p :MExpert!pou (
			name<-'POU_Principal',
			pouType<-'program' ,
			interface<-a
		),
		
	 a :MExpert!Interface(
	 	localVars<-l
	 ),
	 l : MExpert!localVars (
			variable<-v
	),
	v : distinct MExpert!variables foreach(e in nomenclature.ci)(
		name <- e.nature,
		type <- t
		),
	t: distinct MExpert!type foreach(e in nomenclature.ci)(
	REAL<- VR,
	BOOL<- VB
	  ),	
	VR :distinct MExpert!REAL foreach(e in nomenclature.ci)(
	REAL<- if e.type='WORD'
				then 
					VR
				else
					OclUndefined 
				endif
		),
	VB :distinct MExpert!BOOL foreach(e in nomenclature.ci)(
			BOOL<- if e.type='STRING'
				then 
					VB
				else
						OclUndefined 
				endif
	)

	
}

and I get this structure:
<pou xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns="MachineExpert" name="POU_Principal" pouType="program">
  <interface>
    <localVars>
      <variable name="Type">
        <type>
          <REAL/>
          <BOOL/>
        </type>
      </variable>
      <variable name="Unité">
        <type>
          <REAL/>
          <BOOL/>
        </type>
      </variable>
      <variable name="Offset">
        <type>
          <REAL/>
          <BOOL/>
        </type>
      </variable>
      <variable name="Date">
        <type>
          <REAL/>
          <BOOL/>
        </type>
      </variable>
      <variable name="Donnée_1">
        <type>
          <REAL/>
          <BOOL/>
        </type>
      </variable>
      <variable name="Donnée_2">
        <type>
          <REAL/>
          <BOOL/>
        </type>
      </variable>
      <variable name="Donnée_3">
        <type>
          <REAL/>
          <BOOL/>
        </type>
      </variable>
      <variable name="Donnée_4">
        <type>
          <REAL/>
          <BOOL/>
        </type>
      </variable>
      <variable name="Nom">
        <type>
          <REAL/>
          <BOOL/>
        </type>
      </variable>
    </localVars>
  </interface>
</pou>

It only remains to succeed in distinguishing between a "STRING" and a "WORD"
Re: GUIDE ATL [message #1841922 is a reply to message #1841909] Thu, 03 June 2021 10:15 Go to previous messageGo to next message
Eclipse UserFriend

I finally managed to put it on the right structure and now it makes the difference between a BOOL and a REAL. Except that it adds me tags at the end of the program but that will not affecte my progress in the project. If you have any ideas how to remove them that will be nice ...
The problem was that I had to write #STRING instead of 'STRING'
rule Variables2MExpert {
	from nomenclature : ListOfPart!Instance
	to
		p :MExpert!pou (
			name<-'POU_Principal',
			pouType<-'program' ,
			interface<-a
		),
		a :MExpert!Interface(
			localVars<-l
		),
		l : MExpert!localVars (
			variable<-v
		),
		v : distinct MExpert!variables foreach(e in nomenclature.ci)(
			name <- e.nature,
			type <- t
		),
		t :distinct MExpert!type foreach(e in nomenclature.ci)(
			BOOL<-if (e.type=#STRING)
				then
					VB
				else 
					OclUndefined
				endif,
			REAL<-if (e.type=#WORD)
				then
					VR
				else 
					OclUndefined
				endif
		),
		VB :distinct MExpert!BOOL foreach(e in nomenclature.ci),
		VR :distinct MExpert!REAL foreach(e in nomenclature.ci)
}


and this is the result
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns="MachineExpert">
  <pou name="POU_Principal" pouType="program">
    <interface>
      <localVars>
        <variable name="Type">
          <type>
            <BOOL/>
          </type>
        </variable>
        <variable name="Unité">
          <type>
            <BOOL/>
          </type>
        </variable>
        <variable name="Offset">
          <type>
            <REAL/>
          </type>
        </variable>
        <variable name="Date">
          <type>
            <BOOL/>
          </type>
        </variable>
        <variable name="Donnée_1">
          <type>
            <REAL/>
          </type>
        </variable>
        <variable name="Donnée_2">
          <type>
            <REAL/>
          </type>
        </variable>
        <variable name="Donnée_3">
          <type>
            <REAL/>
          </type>
        </variable>
        <variable name="Donnée_4">
          <type>
            <REAL/>
          </type>
        </variable>
        <variable name="Nom">
          <type>
            <BOOL/>
          </type>
        </variable>
      </localVars>
    </interface>
  </pou>
  <BOOL/>
  <BOOL/>
  <BOOL/>
  <BOOL/>
  <BOOL/>
  <REAL/>
  <REAL/>
  <REAL/>
  <REAL/>
</xmi:XMI>
Re: GUIDE ATL [message #1841969 is a reply to message #1841922] Fri, 04 June 2021 12:22 Go to previous message
Eclipse UserFriend
Which ATL VM are you using?

See also https://wiki.eclipse.org/ATL/VM_Comparison
Previous Topic:Executing ATL Launcher with 2 MetaModels as input
Next Topic:ATL to ATL transformation: Order of source elements is getting changed in the output transformation
Goto Forum:
  


Current Time: Sun Jul 06 05:36:21 EDT 2025

Powered by FUDForum. Page generated in 0.06327 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top