Skip to content

Instantly share code, notes, and snippets.

@Leosky
Created June 13, 2017 19:51
Show Gist options
  • Save Leosky/e776335e5f0a7f180d8604baf217b91b to your computer and use it in GitHub Desktop.
Save Leosky/e776335e5f0a7f180d8604baf217b91b to your computer and use it in GitHub Desktop.
{
Leosky
}
unit CLOTH_functions;
uses mteFunctions;
procedure AddAttachPoint(e: IInterface; mRecAttachPoint: IwbMainRecord; mrecDefaultMod: IwbMainRecord);
var
GRUP: IInterface;
ap: IInterface;
i : integer;
begin
Add(e, 'APPR', true); //Create an null element in GRUP but the return value still GRUP field;
GRUP := ElementByPath(e,'APPR');
if NOT HasAttachPoint(e, mRecAttachPoint) then begin //AP not already present
ap := ElementAssign(GRUP, HighInteger, nil, false);
SetEditValue(ap, GetEditValue(mRecAttachPoint));
end;
if mrecDefaultMod <> nil then //a default mod EDID have been provided
begin
GRUP := ElementByIP(e,'OBTE\Combinations');
for i := 0 to ElementCount(GRUP) -1 do
begin
AddOMODToOBTS(ElementByPath(ElementByIndex(GRUP,i),'OBTS'), mrecDefaultMod);
end
end;
end;
function HasAttachPoint(e: IInterface; mRecAttachPoint: IwbMainRecord): boolean;
var
APPR: IInterface;
n: integer;
begin
Result := HasLinkTo(ElementByPath(e, 'APPR'), mRecAttachPoint);
end;
function HasAttachPointL(e: IInterface; edidAttachPoint: string): boolean;
var
APPR: IInterface;
n: integer;
begin
Result := false;
APPR := ElementByPath(e, 'APPR');
for n := 0 to ElementCount(APPR) - 1 do
if GetElementEditValues(LinksTo(ElementByIndex(APPR, n)), 'EDID') = edidAttachPoint then
Result := true;
end;
procedure AddOMODToOBTS(OBTS: IInterface; OMOD: IwbMainRecord);
var
includes: IInterface;
inc: IInterface;
begin
if NOT HasOMODonOBTS(OBTS, OMOD) then
begin
includes := ElementByPath(OBTS,'Includes');
inc := ElementAssign(includes, HighInteger, nil, false);
SetEditValue(ElementByIndex(inc, 0),GetEditValue(OMOD));
SetEditValue(ElementByIndex(inc, 3),true);
end;
end;
function HasOMODonOBTS(OBTS: IInterface; OMOD: IwbMainRecord): boolean;
var
n: integer;
container :IInterface;
begin
Result := false;
container := ElementByPath(OBTS,'Includes');
for n := 0 to ElementCount(container) - 1 do
if Equals(OMOD, LinksTo(ElementByIndex(ElementByIndex(container, n),0))) then
Result := true;
end;
function HasLinkTo(container: IInterface; linked: IInterface): boolean;
var
n: integer;
begin
Result := false;
for n := 0 to ElementCount(container) - 1 do
if Equals(linked, LinksTo(ElementByIndex(container, n))) then
Result := true;
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment