Skip to content

Commit

Permalink
API: change defaults from [0.0] to [], etc. (rebased)
Browse files Browse the repository at this point in the history
A compatibility setting was added to keep the old/COM behavior.
Closes #77

# Conflicts:
#	src/CAPI/CAPI_DSS.pas
#	src/CAPI/CAPI_LoadShapes.pas
#	src/CAPI/CAPI_Monitors.pas
#	src/Common/DSSGlobals.pas
#	src/dss_capi.lpr
  • Loading branch information
PMeira committed May 13, 2021
1 parent f747a9a commit dd63f01
Show file tree
Hide file tree
Showing 44 changed files with 315 additions and 295 deletions.
23 changes: 21 additions & 2 deletions include/dss_capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1554,7 +1554,7 @@ extern "C" {
If enabled, the legacy/deprecated models for PVSystem, InvControl, Storage and StorageControl are used.
WARNING: Changing the active value runs a "Clear" command, discarding the current circuit.
Defaults to False (disabled state).
Defaults to False/0 (disabled state).
This can also be set through the environment variable DSS_CAPI_LEGACY_MODELS. Setting it to 1 enables
the legacy components, using the old models from the start.
Expand All @@ -1570,7 +1570,7 @@ extern "C" {
If you have issues with long paths, enabling this might help in some scenarios.
Defaults to True (allow changes, backwards compatible) in the 0.10.x versions of DSS C-API.
Defaults to True (allow changes, backwards compatible) in the 0.12.x versions of DSS C-API.
This might change to false in future versions.
This can also be set through the environment variable DSS_CAPI_ALLOW_CHANGE_DIR. Setting it to 0 to
Expand All @@ -1581,6 +1581,25 @@ extern "C" {
DSS_CAPI_DLL uint16_t DSS_Get_AllowChangeDir(void);
DSS_CAPI_DLL void DSS_Set_AllowChangeDir(uint16_t Value);

/*
If enabled, in case of errors or empty arrays, the API returns arrays with values compatible with the
official OpenDSS COM interface.
For example, consider the function Loads_Get_ZIPV. If there is no active circuit or active load element:
- In the disabled state (COMErrorResults=False), the function will return "[]", an array with 0 elements.
- In the enabled state (COMErrorResults=True), the function will return "[0.0]" instead. This should
be compatible with the return value of the official COM interface.
Defaults to True/1 (enabled state) in the v0.12.x series. This will change to false in future series.
This can also be set through the environment variable DSS_CAPI_COM_DEFAULTS. Setting it to 0 disables
the legacy/COM behavior. The value can be toggled through the API at any time.
(API Extension)
*/
DSS_CAPI_DLL uint16_t DSS_Get_COMErrorResults(void);
DSS_CAPI_DLL void DSS_Set_COMErrorResults(uint16_t Value);

/*
Array of strings containing the names of all properties for the active DSS object.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/CAPI/CAPI_ActiveClass.pas
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ procedure ActiveClass_Get_AllNames(var ResultPtr: PPAnsiChar; ResultCount: PAPIS
begin
if (InvalidCircuit) or (ActiveDSSClass = NIL) then
begin
DSS_RecreateArray_PPAnsiChar(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount, '');
Exit;
end;

Expand Down
50 changes: 25 additions & 25 deletions src/CAPI/CAPI_Bus.pas
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ procedure Bus_Get_SeqVoltages(var ResultPtr: PDouble; ResultCount: PAPISize); CD
if (InvalidCircuit) or
(not ((ActiveCircuit.ActiveBusIndex > 0) and (ActiveCircuit.ActiveBusIndex <= ActiveCircuit.NumBuses))) then
begin
Result := DSS_RecreateArray_PDouble(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount);
Exit;
end;

Expand Down Expand Up @@ -197,7 +197,7 @@ procedure Bus_Get_Voltages(var ResultPtr: PDouble; ResultCount: PAPISize); CDECL
begin
if not _activeObj(pBus) then
begin
Result := DSS_RecreateArray_PDouble(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount);
Exit;
end;

Expand Down Expand Up @@ -241,7 +241,7 @@ procedure Bus_Get_Nodes(var ResultPtr: PInteger; ResultCount: PAPISize); CDECL;
begin
if not _activeObj(pBus) then
begin
Result := DSS_RecreateArray_PInteger(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount);
Exit;
end;

Expand Down Expand Up @@ -282,7 +282,7 @@ procedure Bus_Get_Isc(var ResultPtr: PDouble; ResultCount: PAPISize); CDECL;
if (InvalidCircuit) or
(not ((ActiveCircuit.ActiveBusIndex > 0) and (ActiveCircuit.ActiveBusIndex <= ActiveCircuit.NumBuses))) then
begin
Result := DSS_RecreateArray_PDouble(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount);
Exit;
end;

Expand All @@ -303,7 +303,7 @@ procedure Bus_Get_Isc(var ResultPtr: PDouble; ResultCount: PAPISize); CDECL;
end;
end
else
Result := DSS_RecreateArray_PDouble(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount);
end
end;

Expand All @@ -325,7 +325,7 @@ procedure Bus_Get_Voc(var ResultPtr: PDouble; ResultCount: PAPISize); CDECL;
if (InvalidCircuit) or
(not ((ActiveCircuit.ActiveBusIndex > 0) and (ActiveCircuit.ActiveBusIndex <= ActiveCircuit.NumBuses))) then
begin
Result := DSS_RecreateArray_PDouble(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount);
Exit;
end;

Expand All @@ -346,7 +346,7 @@ procedure Bus_Get_Voc(var ResultPtr: PDouble; ResultCount: PAPISize); CDECL;
end;
end
else
Result := DSS_RecreateArray_PDouble(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount);
end
end;

Expand Down Expand Up @@ -379,7 +379,7 @@ procedure Bus_Get_puVoltages(var ResultPtr: PDouble; ResultCount: PAPISize); CDE
begin
if not _activeObj(pBus) then
begin
Result := DSS_RecreateArray_PDouble(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount);
Exit;
end;

Expand Down Expand Up @@ -426,7 +426,7 @@ procedure Bus_Get_Zsc0(var ResultPtr: PDouble; ResultCount: PAPISize); CDECL;
if (InvalidCircuit) or
(not ((ActiveCircuit.ActiveBusIndex > 0) and (ActiveCircuit.ActiveBusIndex <= ActiveCircuit.NumBuses))) then
begin
Result := DSS_RecreateArray_PDouble(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount);
Exit;
end;

Expand Down Expand Up @@ -454,7 +454,7 @@ procedure Bus_Get_Zsc1(var ResultPtr: PDouble; ResultCount: PAPISize); CDECL;
if (InvalidCircuit) or
(not ((ActiveCircuit.ActiveBusIndex > 0) and (ActiveCircuit.ActiveBusIndex <= ActiveCircuit.NumBuses))) then
begin
Result := DSS_RecreateArray_PDouble(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount);
Exit;
end;

Expand All @@ -481,7 +481,7 @@ procedure Bus_Get_ZscMatrix(var ResultPtr: PDouble; ResultCount: PAPISize); CDEC
Z: Complex;

begin
Result := DSS_RecreateArray_PDouble(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount);
if (InvalidCircuit) or
(not ((ActiveCircuit.ActiveBusIndex > 0) and (ActiveCircuit.ActiveBusIndex <= ActiveCircuit.NumBuses))) then
Exit;
Expand Down Expand Up @@ -536,7 +536,7 @@ procedure Bus_Get_YscMatrix(var ResultPtr: PDouble; ResultCount: PAPISize); CDEC
Y1: Complex;

begin
Result := DSS_RecreateArray_PDouble(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount);
if (InvalidCircuit) or
(not ((ActiveCircuit.ActiveBusIndex > 0) and (ActiveCircuit.ActiveBusIndex <= ActiveCircuit.NumBuses))) then
Exit;
Expand Down Expand Up @@ -665,7 +665,7 @@ procedure Bus_Get_CplxSeqVoltages(var ResultPtr: PDouble; ResultCount: PAPISize)
if (InvalidCircuit) or
(not ((ActiveCircuit.ActiveBusIndex > 0) and (ActiveCircuit.ActiveBusIndex <= ActiveCircuit.NumBuses))) then
begin
Result := DSS_RecreateArray_PDouble(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount);
Exit;
end;

Expand Down Expand Up @@ -778,7 +778,7 @@ procedure Bus_Get_puVLL(var ResultPtr: PDouble; ResultCount: PAPISize); CDECL;
begin
if not _activeObj(pBus) then
begin
Result := DSS_RecreateArray_PDouble(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount);
Exit;
end;

Expand Down Expand Up @@ -830,7 +830,7 @@ procedure Bus_Get_puVLL(var ResultPtr: PDouble; ResultCount: PAPISize); CDECL;
if NodeIdxj = 0 then
begin
// Could not find appropriate node
Result := DSS_RecreateArray_PDouble(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount);
Exit;
end;
//------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -868,7 +868,7 @@ procedure Bus_Get_VLL(var ResultPtr: PDouble; ResultCount: PAPISize); CDECL;
begin
if not _activeObj(pBus) then
begin
Result := DSS_RecreateArray_PDouble(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount);
Exit;
end;

Expand Down Expand Up @@ -914,7 +914,7 @@ procedure Bus_Get_VLL(var ResultPtr: PDouble; ResultCount: PAPISize); CDECL;
if NodeIdxj = 0 then
begin
// Could not find appropriate node
Result := DSS_RecreateArray_PDouble(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount);
Exit;
end;
//------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -953,7 +953,7 @@ procedure Bus_Get_puVmagAngle(var ResultPtr: PDouble; ResultCount: PAPISize); CD
begin
if not _activeObj(pBus) then
begin
Result := DSS_RecreateArray_PDouble(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount);
Exit;
end;

Expand Down Expand Up @@ -1005,7 +1005,7 @@ procedure Bus_Get_VMagAngle(var ResultPtr: PDouble; ResultCount: PAPISize); CDEC
begin
if not _activeObj(pBus) then
begin
Result := DSS_RecreateArray_PDouble(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount);
Exit;
end;

Expand Down Expand Up @@ -1106,7 +1106,7 @@ procedure Bus_Get_LineList(var ResultPtr: PPAnsiChar; ResultCount: PAPISize); CD
begin
if not _activeObj(pBus) then
begin
DSS_RecreateArray_PPAnsiChar(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount, '');
Exit;
end;

Expand All @@ -1125,7 +1125,7 @@ procedure Bus_Get_LineList(var ResultPtr: PPAnsiChar; ResultCount: PAPISize); CD

if LineCount <= 0 then
begin
DSS_RecreateArray_PPAnsiChar(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount, '');
Exit;
end;

Expand Down Expand Up @@ -1163,7 +1163,7 @@ procedure Bus_Get_LoadList(var ResultPtr: PPAnsiChar; ResultCount: PAPISize); CD
begin
if not _activeObj(pBus) then
begin
DSS_RecreateArray_PPAnsiChar(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount, '');
Exit;
end;

Expand All @@ -1182,7 +1182,7 @@ procedure Bus_Get_LoadList(var ResultPtr: PPAnsiChar; ResultCount: PAPISize); CD

if LoadCount <= 0 then
begin
DSS_RecreateArray_PPAnsiChar(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount, '');
Exit;
end;

Expand Down Expand Up @@ -1219,15 +1219,15 @@ procedure Bus_Get_ZSC012Matrix(var ResultPtr: PDouble; ResultCount: PAPISize); C
begin
if not _activeObj(pBus) then
begin
DSS_RecreateArray_PDouble(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount);
Exit;
end;

with pBus do
begin
if NumNodesThisBus <> 3 then
begin
DSS_RecreateArray_PDouble(ResultPtr, ResultCount, 1);
DefaultResult(ResultPtr, ResultCount);
Exit;
end;

Expand Down
5 changes: 1 addition & 4 deletions src/CAPI/CAPI_CNData.pas
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,8 @@ procedure CNData_Set_Name(const Value: PAnsiChar); CDECL;
end;
//------------------------------------------------------------------------------
procedure CNData_Get_AllNames(var ResultPtr: PPAnsiChar; ResultCount: PAPISize); CDECL;
var
Result: PPAnsiCharArray;
begin
Result := DSS_RecreateArray_PPAnsiChar(ResultPtr, ResultCount, 1);
Result[0] := DSS_CopyStringAsPChar('NONE');
DefaultResult(ResultPtr, ResultCount);
if InvalidCircuit then
Exit;

Expand Down
5 changes: 1 addition & 4 deletions src/CAPI/CAPI_CapControls.pas
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,8 @@ procedure Set_Parameter(const parm: String; const val: String);
end;
//------------------------------------------------------------------------------
procedure CapControls_Get_AllNames(var ResultPtr: PPAnsiChar; ResultCount: PAPISize); CDECL;
var
Result: PPAnsiCharArray;
begin
Result := DSS_RecreateArray_PPAnsiChar(ResultPtr, ResultCount, 1);
Result[0] := DSS_CopyStringAsPChar('NONE');
DefaultResult(ResultPtr, ResultCount);
if InvalidCircuit then
Exit;
Generic_Get_AllNames(ResultPtr, ResultCount, ActiveCircuit.CapControls, False);
Expand Down
9 changes: 3 additions & 6 deletions src/CAPI/CAPI_Capacitors.pas
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,8 @@ procedure Set_Parameter(const parm: String; const val: String);
end;
//------------------------------------------------------------------------------
procedure Capacitors_Get_AllNames(var ResultPtr: PPAnsiChar; ResultCount: PAPISize); CDECL;
var
Result: PPAnsiCharArray;
begin
Result := DSS_RecreateArray_PPAnsiChar(ResultPtr, ResultCount, 1);
Result[0] := DSS_CopyStringAsPChar('NONE');
DefaultResult(ResultPtr, ResultCount);
if InvalidCircuit then
Exit;

Expand Down Expand Up @@ -280,8 +277,8 @@ procedure Capacitors_Get_States(var ResultPtr: PInteger; ResultCount: PAPISize);
begin
if not _activeObj(elem) then
begin
Result := DSS_RecreateArray_PInteger(ResultPtr, ResultCount, 1);
Result[0] := -1; // error code
DefaultResult(ResultPtr, ResultCount, -1);
Exit;
end;

DSS_RecreateArray_PInteger(Result, ResultPtr, ResultCount, elem.NumSteps);
Expand Down
Loading

0 comments on commit dd63f01

Please sign in to comment.