Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » how to sort elements ?
how to sort elements ? [message #876853] Fri, 25 May 2012 07:49 Go to next message
Kosala Yapa is currently offline Kosala Yapa
Messages: 159
Registered: September 2010
Senior Member
Input:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi=".../XMI" xmlns="source">
<DeviceList>
<DeviceItem
Name="PSSuniversal22222"
DeviceCommReference= "001417C3-00000003-001417B3-00000002-00112001-0000013A"
DeviceReference="{7F6AC5F1-E8E0-49E5-ABA1-26E4A6A74175}{001417C3-00000003-001417B3-00000002-00112001-00000107}{SD_example1}">
<ParameterList>
<ParameterItem Name="NameOfStation" Value="PSSuniversal2222"/>
<ParameterItem Name="IPAddress" Value="192.168.10.103"/>
<ParameterItem Name="SubnetMask" Value="255.255.255.0"/>
<ParameterItem Name="DefaultGateway" Value="0.0.0.0"/>
<ParameterItem Name="IdentNumber" Value="0x0001"/>
<ParameterItem Name="VendorID" Value="0x092F"/>
<ParameterItem Name="ObjectUUID_LocalIndex" Value="1"/>
<ParameterItem Name="UsedConfigFile" Value="D:\Program Files\Siemens\Step7\S7data\gsd\GSDML-V2.25-Pilz-PSSuniversal-20120122.xml"/>
</ParameterList>

<ModuleList>
<ModuleItem
Name="PSSu E F PS (PROFIsafe)"
IsSelected="false"
ModuleReference="{9A856DAC-1D0A-46F7-B69F-40E2DC6511DD}{001417C5-0000002F-001417C3-0000002A-00112001-00000107}{SD_example1}">
<ParameterList>
<ParameterItem Name="Slot" Value="2"/>
<ParameterItem Name="IdentNumber" Value="0x00000801"/>
</ParameterList>
</ModuleItem>
<ModuleItem
Name="PSSuES4DO0.5_1"
IsSelected="false"
ModuleReference="CFAF3ED5-37E4-476B-AE64-94FDD6429D1E}{001417C5-00000009-001417C3-00000003-00112001-00000107">
<ParameterList>
<ParameterItem Name="Slot" Value="0"/>
<ParameterItem Name="IdentNumber" Value="0x00000C00"/>
<ParameterItem Name="API" Value="0"/>
<ParameterItem Name="RecordDataObject" Value="000000020840000100010096BB95"/>
</ParameterList>
</ModuleItem>
<ModuleItem
Name="PSSuniversal33333"
IsSelected="false"
ModuleReference="CFAF3ED5-37E4-476B-AE64-94FDD6429D1E}{001417C5-00000009-001417C3-00000003-00112001-00000108">
<ParameterList>
<ParameterItem Name="Slot" Value="1"/>
<ParameterItem Name="IdentNumber" Value="0x00000229"/>
<ParameterItem Name="API" Value="0"/>
</ParameterList>
</ModuleItem>

</ModuleList>

</DeviceItem>

</DeviceList>

</xmi:XMI>




Output:

<?xml version="1.0" encoding="ISO-8859-1"?>
<Device xmi:version="2.0" xmlns:xmi=".../XMI" xmlns:xsi=".../2001/XMLSchema-instance" xmlns="target" name="PSSuniversal22222" s7DeviceReference="{7F6AC5F1-E8E0-49E5-ABA1-26E4A6A74175}{001417C3-00000003-001417B3-00000002-00112001-00000107}{SD_example1}">
<Module name="PSSu E F PS (PROFIsafe)" deviceID="0x00000801" s7ModuleReference="{9A856DAC-1D0A-46F7-B69F-40E2DC6511DD}{001417C5-0000002F-001417C3-0000002A-00112001-00000107}{SD_example1}" isSelectedWithinStep7="false"/>
<Module name="PSSuniversal33333" deviceID="0x00000229" s7ModuleReference="CFAF3ED5-37E4-476B-AE64-94FDD6429D1E}{001417C5-00000009-001417C3-00000003-00112001-00000108" isSelectedWithinStep7="false"/>
<HeadModule xsi:type="Module" name="PSSuES4DO0.5_1" deviceID="0x00000C00" s7ModuleReference="CFAF3ED5-37E4-476B-AE64-94FDD6429D1E}{001417C5-00000009-001417C3-00000003-00112001-00000107" isSelectedWithinStep7="false"/>
</Device>



ATL program:

-- @path source=file:/.../TPF/source.ecore
-- @path target=file:/.../TPF/target.ecore

module tpf3;
create OUT : target from IN : source;



helper context source!ModuleItem def : getIdentNumber():
String = self.ParameterList.ParameterItem->select(pi | pi.Name='IdentNumber')->collect(e|e.Value)->first();


helper context source!ModuleItem def : getSlotValue():
String = self.ParameterList.ParameterItem->select(pi | pi.Name='Slot')->collect(e|e.Value)->first();


rule Rule_Device{
from
a: source!DeviceItem
to
p:target!Device(
name <- a.Name,
s7DeviceReference<-a.DeviceReference,
HeadModule<-a.ModuleList.ModuleItem->select(mi|mi.getSlotValue()='0')->collect(e|thisModule.Rule_getModule(e))->first(),
Module<-a.ModuleList.ModuleItem->select(mi|mi.getSlotValue()<>'0')->collect(e|thisModule.Rule_getModule(e))
)
}



lazy rule Rule_getModule{
from
b:source!ModuleItem

to
d:target!Module(
deviceID<-b.getIdentNumber(),
name <- b.Name,
s7ModuleReference <- b.ModuleReference,
isSelectedWithinStep7<-b.IsSelected
)

}


Problem: How to get elements in the output file sorted by the Slot Value parameter?

I appriciate any help.

Thanks in advance.
Kosala

Re: how to sort elements ? [message #876899 is a reply to message #876853] Fri, 25 May 2012 09:35 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4035
Registered: July 2009
Senior Member
Hi

OCL defines a sortedBy() iteration.

Regards

Ed Willink
Re: how to sort elements ? [message #878070 is a reply to message #876899] Mon, 28 May 2012 09:01 Go to previous message
Kosala Yapa is currently offline Kosala Yapa
Messages: 159
Registered: September 2010
Senior Member
Thanks ED. Sorted out!
Previous Topic:API ATL Analyser
Next Topic:how to extract objects from eclipse IModel objects?
Goto Forum:
  


Current Time: Sun Aug 31 06:37:16 EDT 2014

Powered by FUDForum. Page generated in 0.01792 seconds