From 1ccc53d70f2bf9213ef167ab7e9c14ef86943287 Mon Sep 17 00:00:00 2001 From: vwaurich Date: Wed, 19 Oct 2016 11:08:41 +0200 Subject: [PATCH] use CevalScript.getFullPathFromUri to get animation file paths --- Compiler/BackEnd/VisualXML.mo | 37 +++++++++++----------------- Compiler/SimCode/HpcOmSimCodeMain.mo | 8 +++--- Compiler/SimCode/SimCodeMain.mo | 29 +++++++++++----------- Compiler/SimCode/SimCodeUtil.mo | 25 ++----------------- 4 files changed, 35 insertions(+), 64 deletions(-) diff --git a/Compiler/BackEnd/VisualXML.mo b/Compiler/BackEnd/VisualXML.mo index 4df235e2ee9..0b6d0fcb3be 100644 --- a/Compiler/BackEnd/VisualXML.mo +++ b/Compiler/BackEnd/VisualXML.mo @@ -46,6 +46,7 @@ import BackendDAE; import BackendDAEUtil; import BackendEquation; import BackendVariable; +import CevalScript; import ComponentReference; import DAE; import DAEUtil; @@ -88,7 +89,7 @@ public function visualizationInfoXML"dumps an xml containing information about v author:Waurich TUD 2015-04" input BackendDAE.BackendDAE daeIn; input String fileName; - input list> packagePaths; + input Absyn.Program program; output BackendDAE.BackendDAE daeOut; protected BackendDAE.EqSystems eqs, eqs0; @@ -117,7 +118,7 @@ algorithm //fill theses visualization objects with information allVarLst := listAppend(globalKnownVarLst,listAppend(allVarLst,aliasVarLst)); - (visuals,_,_) := List.mapFold2(allVisuals, fillVisualizationObjects,allVarLst, packagePaths); + (visuals,_,_) := List.mapFold2(allVisuals, fillVisualizationObjects,allVarLst, program); //print("\nvisuals :\n"+stringDelimitList(List.map(visuals,printVisualization),"\n")+"\n"); //dump xml file @@ -208,12 +209,12 @@ protected function fillVisualizationObjects"gets the identifier of a visualizati author:Waurich TUD 2015-04" input DAE.ComponentRef crefIn; input list allVarsIn; - input list> packagePathsIn; + input Absyn.Program programIn; output Visualization visOut; output list allVarsOut; - output list> packagePathsOut; + output Absyn.Program programOut; algorithm - (visOut,allVarsOut,packagePathsOut) := matchcontinue(crefIn,allVarsIn,packagePathsIn) + (visOut,allVarsOut,programOut) := matchcontinue(crefIn,allVarsIn,programIn) local String name; list nameChars,prefix; @@ -230,8 +231,8 @@ algorithm vis := SHAPE(crefIn,"",arrayCreate(3,{DAE.RCONST(-1),DAE.RCONST(-1),DAE.RCONST(-1)}), arrayCreate(3,DAE.RCONST(-1)), arrayCreate(3,DAE.RCONST(-1)), arrayCreate(3,DAE.RCONST(-1)),arrayCreate(3,DAE.RCONST(-1)), DAE.RCONST(-1),DAE.RCONST(-1),DAE.RCONST(-1),DAE.RCONST(-1), arrayCreate(3,DAE.RCONST(-1)), DAE.RCONST(-1)); - (_,vis) := List.fold2(allVarsIn,fillVisualizationObjects1,true,packagePathsIn,({},vis)); - then (vis,allVarsIn,packagePathsIn); + (_,vis) := List.fold2(allVarsIn,fillVisualizationObjects1,true,programIn,({},vis)); + then (vis,allVarsIn,programIn); else algorithm print("fillVisualizationObjects failed! - not yet supported type"); @@ -293,7 +294,7 @@ protected function fillVisualizationObjects1"checks if a variable belongs to a c author:Waurich TUD 2015-04" input BackendDAE.Var varIn; //check this var input Boolean storeProtectedCrefs; // if you want to store the protected crefs instead of the bidning expression - input list> packagePaths; + input Absyn.Program program; input tuple,Visualization> tplIn; // fold output tuple,Visualization> tplOut; algorithm @@ -308,7 +309,7 @@ algorithm //this var belongs to the visualization object //crefIdent := makeCrefQualFromString(ident); // make a qualified cref out of the shape ident (cref1,true) := splitCrefAfter(cref,ident); // check if this occures in the qualified var cref - vis := fillShapeObject(cref1,varIn,storeProtectedCrefs,packagePaths,vis); + vis := fillShapeObject(cref1,varIn,storeProtectedCrefs,program,vis); then (vars, vis); else algorithm @@ -320,7 +321,7 @@ end fillVisualizationObjects1; protected function getFullCADFilePath "Get the absolute path for the given modelica uri. author: vwaurich TUD 2016-10" input String sIn; - input list> packagePaths; + input Absyn.Program program; output String sOut = sIn; protected String head,packName,file, path; @@ -328,15 +329,7 @@ protected algorithm chars := stringListStringChar(sIn); if listLength(chars) > 11 and stringEqual(stringDelimitList(List.firstN(chars,11),""),"modelica://") then - (head,packName,file) := System.uriToClassAndPath(sIn); - //Check if its a file reference and create absolute path - if stringEqual(head,"modelica://") then - (_,path) := List.find1(packagePaths,packagePathEqual,packName); - hierarchy := System.strtok(path, "/"); - hierarchy := List.firstN(hierarchy,listLength(hierarchy)-1); - //print("hierarchy: "+stringDelimitList(hierarchy," ")+"\n"); - sOut := head+stringDelimitList(hierarchy,"/")+file; - end if; + sOut := "modelica://"+CevalScript.getFullPathFromUri(program,sIn,true); end if; end getFullCADFilePath; @@ -354,11 +347,11 @@ author:Waurich TUD 2015-04" input DAE.ComponentRef cref; input BackendDAE.Var var; input Boolean storeProtectedCrefs; - input list> packagePaths; + input Absyn.Program program; input Visualization visIn; output Visualization visOut; algorithm - visOut := matchcontinue(cref,var,storeProtectedCrefs,packagePaths,visIn) + visOut := matchcontinue(cref,var,storeProtectedCrefs,program,visIn) local Option bind; DAE.ComponentRef ident; @@ -371,7 +364,7 @@ algorithm array> T; case(DAE.CREF_IDENT(ident="shapeType"),BackendDAE.VAR(bindExp=SOME(DAE.SCONST(svalue))),_ ,_ , SHAPE(ident=ident, shapeType=shapeType, T=T, r=r, r_shape=r_shape, lengthDir=lengthDir, widthDir=widthDir, length=length, width=width, height=height, extra=extra, color=color, specularCoeff=specularCoeff)) algorithm - svalue := getFullCADFilePath(svalue,packagePaths); + svalue := getFullCADFilePath(svalue,program); then (SHAPE(ident, svalue, T, r, r_shape, lengthDir, widthDir, length, width, height, extra, color, specularCoeff)); case(DAE.CREF_QUAL(ident="R",componentRef=DAE.CREF_IDENT(ident="T", subscriptLst = {DAE.INDEX(DAE.ICONST(pos)),DAE.INDEX(DAE.ICONST(pos1))})),BackendDAE.VAR(bindExp=bind),_ ,_ , SHAPE(ident=ident, shapeType=shapeType, T=T, r=r, r_shape=r_shape, lengthDir=lengthDir, widthDir=widthDir, length=length, width=width, height=height, extra=extra, color=color, specularCoeff=specularCoeff)) diff --git a/Compiler/SimCode/HpcOmSimCodeMain.mo b/Compiler/SimCode/HpcOmSimCodeMain.mo index 4681a3bbe10..1e37ada8b42 100644 --- a/Compiler/SimCode/HpcOmSimCodeMain.mo +++ b/Compiler/SimCode/HpcOmSimCodeMain.mo @@ -82,14 +82,14 @@ public function createSimCode " input list includeDirs; input list libs; input list libPaths; - input list> packagePaths; + input Absyn.Program program; input Option simSettingsOpt; input list recordDecls; input tuple> literals; input Absyn.FunctionArgs args; output SimCode.SimCode simCode; algorithm - simCode := matchcontinue (inBackendDAE, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs, libPaths,packagePaths,simSettingsOpt, recordDecls, literals, args) + simCode := matchcontinue (inBackendDAE, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs, libPaths,program,simSettingsOpt, recordDecls, literals, args) local Integer lastEqMappingIdx; BackendDAE.EqSystems eqs; @@ -137,7 +137,7 @@ algorithm //----- (simCode,(lastEqMappingIdx,equationSccMapping)) = SimCodeUtil.createSimCode( inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, inClassName, filenamePrefix, inString11, functions, - externalFunctionIncludes, includeDirs, libs,libPaths,packagePaths, simSettingsOpt, recordDecls, literals, args ); + externalFunctionIncludes, includeDirs, libs,libPaths,program, simSettingsOpt, recordDecls, literals, args ); //get simCode-backendDAE mappings //---------------------------- @@ -192,7 +192,7 @@ algorithm System.realtimeTick(ClockIndexes.RT_CLOCK_EXECSTAT_HPCOM_MODULES); (simCode,(lastEqMappingIdx,equationSccMapping)) = SimCodeUtil.createSimCode( inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, inClassName, filenamePrefix, inString11, functions, - externalFunctionIncludes, includeDirs, libs,libPaths,packagePaths, simSettingsOpt, recordDecls, literals, args ); + externalFunctionIncludes, includeDirs, libs,libPaths,program, simSettingsOpt, recordDecls, literals, args ); //get simCode-backendDAE mappings //---------------------------- diff --git a/Compiler/SimCode/SimCodeMain.mo b/Compiler/SimCode/SimCodeMain.mo index b38dc80779f..88eed279fda 100644 --- a/Compiler/SimCode/SimCodeMain.mo +++ b/Compiler/SimCode/SimCodeMain.mo @@ -144,15 +144,14 @@ protected Absyn.ComponentRef a_cref; list libPaths; tuple> literals; - list> packagePaths; algorithm System.realtimeTick(ClockIndexes.RT_CLOCK_SIMCODE); a_cref := Absyn.pathToCref(className); fileDir := CevalScriptBackend.getFileDir(a_cref, p); - (libs,libPaths,includes, includeDirs, recordDecls, functions, literals, packagePaths) := + (libs,libPaths,includes, includeDirs, recordDecls, functions, literals) := SimCodeUtil.createFunctions(p, inBackendDAE); simCode := createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, - className, filenamePrefix, fileDir, functions, includes, includeDirs, libs, libPaths,packagePaths, SOME(simSettings), recordDecls, literals, Absyn.FUNCTIONARGS({},{}), isFMU=true, FMUVersion=FMUVersion); + className, filenamePrefix, fileDir, functions, includes, includeDirs, libs, libPaths, p, SOME(simSettings), recordDecls, literals, Absyn.FUNCTIONARGS({},{}), isFMU=true, FMUVersion=FMUVersion); timeSimCode := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMCODE); ExecStat.execStat("SimCode"); @@ -190,15 +189,15 @@ protected list libPaths; Absyn.ComponentRef a_cref; tuple> literals; - list> packagePaths; + list> program; algorithm System.realtimeTick(ClockIndexes.RT_CLOCK_SIMCODE); a_cref := Absyn.pathToCref(className); fileDir := CevalScriptBackend.getFileDir(a_cref, p); - (libs, libPaths, includes, includeDirs, recordDecls, functions, literals, packagePaths) := + (libs, libPaths, includes, includeDirs, recordDecls, functions, literals) := SimCodeUtil.createFunctions(p, inBackendDAE); (simCode,_) := SimCodeUtil.createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, - className, filenamePrefix, fileDir, functions, includes, includeDirs, libs,libPaths,packagePaths, simSettingsOpt, recordDecls, literals,Absyn.FUNCTIONARGS({},{})); + className, filenamePrefix, fileDir, functions, includes, includeDirs, libs,libPaths, p, simSettingsOpt, recordDecls, literals,Absyn.FUNCTIONARGS({},{})); timeSimCode := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMCODE); ExecStat.execStat("SimCode"); @@ -414,7 +413,7 @@ protected list recordDecls; Absyn.ComponentRef a_cref; tuple> literals; - list> packagePaths; + list> program; algorithm if Flags.isSet(Flags.GRAPHML) then HpcOmTaskGraph.dumpTaskGraph(inBackendDAE, filenamePrefix); @@ -423,8 +422,8 @@ algorithm a_cref := Absyn.pathToCref(className); fileDir := CevalScriptBackend.getFileDir(a_cref, p); - (libs, libPaths, includes, includeDirs, recordDecls, functions, literals, packagePaths) := SimCodeUtil.createFunctions(p, inBackendDAE); - simCode := createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, className, filenamePrefix, fileDir, functions, includes, includeDirs, libs,libPaths,packagePaths, simSettingsOpt, recordDecls, literals, args); + (libs, libPaths, includes, includeDirs, recordDecls, functions, literals) := SimCodeUtil.createFunctions(p, inBackendDAE); + simCode := createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, className, filenamePrefix, fileDir, functions, includes, includeDirs, libs,libPaths, p, simSettingsOpt, recordDecls, literals, args); timeSimCode := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMCODE); ExecStat.execStat("SimCode"); @@ -456,7 +455,7 @@ protected function createSimCode " input list includeDirs; input list libs; input list libPaths; - input list> packagePaths; + input Absyn.Program program; input Option simSettingsOpt; input list recordDecls; input tuple> literals; @@ -465,7 +464,7 @@ protected function createSimCode " input String FMUVersion=""; output SimCode.SimCode simCode; algorithm - simCode := matchcontinue(inBackendDAE, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs, libPaths, packagePaths,simSettingsOpt, recordDecls, literals, args) + simCode := matchcontinue(inBackendDAE, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs, libPaths, program,simSettingsOpt, recordDecls, literals, args) local Integer numProc; SimCode.SimCode tmpSimCode; @@ -473,7 +472,7 @@ algorithm case(_, _, _, _, _, _, _, _, _, _,_, _, _, _) equation // MULTI_RATE PARTITIONINIG true = Flags.isSet(Flags.MULTIRATE_PARTITION); - then HpcOmSimCodeMain.createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs,libPaths,packagePaths, simSettingsOpt, recordDecls, literals, args); + then HpcOmSimCodeMain.createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs,libPaths, program, simSettingsOpt, recordDecls, literals, args); case(_, _, _, _, _, _, _, _, _, _,_, _, _, _) equation true = Flags.isSet(Flags.HPCOM); @@ -486,7 +485,7 @@ algorithm numProc = Flags.getConfigInt(Flags.NUM_PROC); true = numProc == 0; print("hpcom computes the ideal number of processors. If you want to set the number manually, use the flag +n=_ \n"); - then HpcOmSimCodeMain.createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs,libPaths,packagePaths, simSettingsOpt, recordDecls, literals, args); + then HpcOmSimCodeMain.createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs,libPaths,program, simSettingsOpt, recordDecls, literals, args); case(_, _, _, _, _, _, _, _, _,_, _, _, _, _) equation true = Flags.isSet(Flags.HPCOM); @@ -498,10 +497,10 @@ algorithm numProc = Flags.getConfigInt(Flags.NUM_PROC); true = (numProc > 0); - then HpcOmSimCodeMain.createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs, libPaths,packagePaths,simSettingsOpt, recordDecls, literals, args); + then HpcOmSimCodeMain.createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs, libPaths,program,simSettingsOpt, recordDecls, literals, args); else equation - (tmpSimCode, _) = SimCodeUtil.createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs,libPaths,packagePaths, simSettingsOpt, recordDecls, literals, args, isFMU=isFMU, FMUVersion=FMUVersion); + (tmpSimCode, _) = SimCodeUtil.createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs,libPaths,program, simSettingsOpt, recordDecls, literals, args, isFMU=isFMU, FMUVersion=FMUVersion); then tmpSimCode; end matchcontinue; end createSimCode; diff --git a/Compiler/SimCode/SimCodeUtil.mo b/Compiler/SimCode/SimCodeUtil.mo index 604c2a7609d..625346b89ae 100644 --- a/Compiler/SimCode/SimCodeUtil.mo +++ b/Compiler/SimCode/SimCodeUtil.mo @@ -175,7 +175,7 @@ public function createSimCode "entry point to create SimCode from BackendDAE." input list includeDirs; input list libs; input list libPaths; - input list> packagePaths; + input Absyn.Program program; input Option simSettingsOpt; input list recordDecls; input tuple> literals; @@ -263,7 +263,7 @@ algorithm backendMapping := setUpBackendMapping(inBackendDAE); if Flags.isSet(Flags.VISUAL_XML) then - dlow := VisualXML.visualizationInfoXML(dlow, filenamePrefix, packagePaths); + dlow := VisualXML.visualizationInfoXML(dlow, filenamePrefix, program); end if; if Flags.isSet(Flags.ITERATION_VARS) then @@ -563,7 +563,6 @@ public function createFunctions output list outRecordDecls; output list outFunctions; output tuple> outLiterals; - output list> packagePaths; protected list funcelems; DAE.FunctionTree functionTree; @@ -576,32 +575,12 @@ algorithm funcelems := Inline.inlineCallsInFunctions(funcelems, (NONE(), {DAE.NORM_INLINE(), DAE.AFTER_INDEX_RED_INLINE()}), {}); (funcelems, outLiterals as (_, _, lits)) := simulationFindLiterals(inBackendDAE, funcelems); (outFunctions, outRecordDecls, outIncludes, outIncludeDirs, outLibs, outLibPaths) := SimCodeFunctionUtil.elaborateFunctions(inProgram, funcelems, {}, lits, {}); // Do we need metarecords here as well? - packagePaths := getPackagePathInfo(inProgram); - //GlobalScriptDump.dumpAST(inProgram); else Error.addInternalError("Creation of Modelica functions failed.", sourceInfo()); fail(); end try; end createFunctions; -protected function getPackagePathInfo " Create a list of tuples which store the loaded files and their absolute paths on the system. -This is used to get the paths for resource files which are needed e.g. for animation of CAD-files. -author: vwaurich TUD 2016-10" - input Absyn.Program inProgram; - output list> packagePaths = {}; //(packageName, absolute path) -protected - String pack, path; - Absyn.Class class_; - list classes; -algorithm - Absyn.PROGRAM(classes) := inProgram; - for class_ in classes loop - Absyn.CLASS(name = pack, info = SOURCEINFO(fileName = path)) := class_; - packagePaths := (pack,path)::packagePaths; - //print("getPackagePathInfo "+pack+" :"+path+"\n"); - end for; -end getPackagePathInfo; - protected function getParamAsserts"splits the equationArray in variable-dependent and parameter-dependent equations. author: Waurich TUD-2015-04" input BackendDAE.Equation eqIn;