def PsimReadGraphFile(self, graphFilePath) -> PSIM_result:
result = PSIM_result(self)
if not self.IsValid():
result.ErrorMessage = "PSIM object was not loaded."
result.Result = 0;
result.IsError = 1;
return result;
try:
grf = PSIM.__private_OpenGraphFile(self, graphFilePath)
if(grf > 0):
result.graphHandle = grf
Graph_GetColCount = getattr(self.psimHandle, "Graph_GetColCount")
if not Graph_GetColCount:
raise AttributeError(self.VersionErrorMessage)
Graph_GetRowCount = getattr(self.psimHandle, "Graph_GetRowCount")
if not Graph_GetRowCount:
raise AttributeError(self.VersionErrorMessage)
Graph_GetColInfo = getattr(self.psimHandle, "Graph_GetColInfo")
if not Graph_GetColInfo:
raise AttributeError(self.VersionErrorMessage)
Graph_GetColCount.restype = ctypes.c_int
Graph_GetRowCount.restype = ctypes.c_int
Graph_GetColInfo.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.POINTER(ctypes.POINTER(ctypes.c_wchar)), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.POINTER(ctypes.c_double)), ctypes.POINTER(ctypes.POINTER(ctypes.c_byte))]
Graph_GetColInfo.restype = ctypes.c_int
pnRows = ctypes.c_int(0)
pnIncDec = ctypes.c_int(0)
numberOfCol = Graph_GetColCount(ctypes.c_int(grf))
numberOfRows = Graph_GetRowCount(ctypes.c_int(grf))
for col in range(0 , numberOfCol):
ppValues1_B = (ctypes.c_double * numberOfRows)()
ppValidState1_B = (ctypes.c_byte * numberOfRows)()
ppValues = ctypes.cast(ppValues1_B, ctypes.POINTER(ctypes.c_double))
ppValidState = ctypes.cast(ppValidState1_B, ctypes.POINTER(ctypes.c_byte))
ptrName1 = (ctypes.c_wchar * 100)()
ptrName = ctypes.cast(ptrName1, ctypes.POINTER(ctypes.c_wchar))
b = Graph_GetColInfo(ctypes.c_int(grf), ctypes.c_int (0), ctypes.c_int(col), ctypes.byref(ptrName), ctypes.byref(pnRows), ctypes.byref(pnIncDec), ctypes.byref(ppValues), ctypes.byref(ppValidState))
ptrName3 = ctypes.cast(ptrName, ctypes.POINTER(ctypes.c_wchar * 100))
crv = PSIM_curve(pnRows.value, ptrName3.contents.value, ppValues, ppValidState)
result.Graph.add_curve(crv)
result.ErrorMessage = ""
result.IsError = 0
result.Result = 1;
else:
result.IsError = 1
result.Result = 0;
result.ErrorMessage = "Unable to open following file: " + graphFilePath
except Exception as e:
print(f"Error: {e}")
return result
def __private_OpenGraphFile(self, graphFilePath):
OpenGraphFile = getattr(self.psimHandle, "Graph_ReadFile")
if not OpenGraphFile:
raise AttributeError(self.VersionErrorMessage)
OpenGraphFile.restype = ctypes.c_int
grf = OpenGraphFile(ctypes.c_wchar_p(graphFilePath));
return grf