937{
938 ArcFlashProtectionData result = data;
939
940 auto showError = [&](const wxString& message) {
941 wxMessageBox(message, _("Invalid data"), wxOK | wxICON_WARNING, m_parent);
942 return false;
943 };
944
945 auto parseDouble = [&](const wxString& text, double& value, const wxString& field) {
946 return m_bus->DoubleFromString(
947 m_parent,
948 text,
949 value,
950 wxString::Format(_("Value entered incorrectly in the field \"%s\"."), field));
951 };
952
953 auto requirePositive = [&](double value, const wxString& field) {
954 if (!std::isfinite(value) || value <= 0.0)
955 return showError(wxString::Format(
956 _("The field \"%s\" must be greater than zero."), field));
957
958 return true;
959 };
960
961
962 const int typeSelection = m_choiceType->GetSelection();
963
964 if (typeSelection < 0 || typeSelection > 1)
965 return showError(_("Select a valid protection type."));
966
967 result.type = typeSelection == 0
968 ? ArcFlashProtectionType::CIRCUIT_BREAKER
969 : ArcFlashProtectionType::FUSE;
970
971
972 const int methodSelection = m_choiceMethod->GetSelection();
973
974 if (methodSelection < 0 || methodSelection > 1)
975 return showError(_("Select a valid protection method."));
976
977 if (methodSelection == 0)
978 result.method = ArcFlashProtectionMethod::TCC_CURVE;
979 else if (result.type == ArcFlashProtectionType::CIRCUIT_BREAKER)
980 result.method = ArcFlashProtectionMethod::ANNEX_I;
981 else
982 result.method = ArcFlashProtectionMethod::ANNEX_H;
983
984
985 wxString delayText = m_textCtrlDelay->GetValue();
986 delayText.Trim(false).Trim(true);
987
988 if (delayText.IsEmpty())
989 result.additionalDelay = 0.0;
990 else if (!parseDouble(delayText, result.additionalDelay, _("Additional delay (s)")))
991 return false;
992
993 if (!std::isfinite(result.additionalDelay) || result.additionalDelay < 0.0)
994 return showError(_("The additional delay must be greater than or equal to zero."));
995
996
997 if (result.method == ArcFlashProtectionMethod::TCC_CURVE) {
998 const int rows = m_gridTCC->GetNumberRows();
999
1000 if (m_gridTCC->GetNumberCols() < 2 || rows < 2)
1001 return showError(_("The TCC curve must contain at least two points."));
1002
1003 std::vector<ArcFlashTCCPoint> points;
1004 points.reserve(rows);
1005
1006 for (int row = 0; row < rows; ++row) {
1007 ArcFlashTCCPoint point;
1008
1009 const wxString currentField =
1010 wxString::Format(_("Current (A), row %d of the TCC curve"), row + 1);
1011
1012 const wxString timeField =
1013 wxString::Format(_("Time (s), row %d of the TCC curve"), row + 1);
1014
1015 if (!parseDouble(m_gridTCC->GetCellValue(row, 0), point.current, currentField))
1016 return false;
1017
1018 if (!requirePositive(point.current, currentField))
1019 return false;
1020
1021 if (!parseDouble(m_gridTCC->GetCellValue(row, 1), point.time, timeField))
1022 return false;
1023
1024 if (!requirePositive(point.time, timeField))
1025 return false;
1026
1027 points.push_back(point);
1028 }
1029
1030 result.tccPoints = points;
1031 result.curveIsMeltTimeOnly = m_checkBoxIsMeltTime->GetValue();
1032 }
1033
1034
1035 if (result.method == ArcFlashProtectionMethod::ANNEX_I) {
1036 const int cbType = m_choiceCBType->GetSelection();
1037 const int currentRange = m_choiceCBCurrent->GetSelection();
1038 const int tripUnit = m_choiceCBTrip->GetSelection();
1039
1040 if (cbType < 0 || cbType > 2 || currentRange < 0 || tripUnit < 0)
1041 return showError(_("Select valid circuit breaker parameters."));
1042
1043
1044 switch (cbType) {
1045 case 0:
1046 if (currentRange == 0 && tripUnit == 0) {
1047 result.breakerFamily = ArcFlashBreakerFamily::MCCB_100_400A;
1048 }
1049 else if (currentRange == 1 && tripUnit == 0) {
1050 result.breakerFamily = ArcFlashBreakerFamily::MCCB_600_1200A_TM_OR_M;
1051 }
1052 else if (currentRange == 1 && tripUnit == 1) {
1053 result.breakerFamily = ArcFlashBreakerFamily::MCCB_600_1200A_E_LI;
1054 }
1055 else {
1056 return showError(
1057 _("The selected MCCB current range and trip unit are not compatible."));
1058 }
1059 break;
1060
1061 case 1:
1062 if (currentRange != 0 || tripUnit != 0)
1063 return showError(
1064 _("The selected ICCB current range and trip unit are not compatible."));
1065
1066 result.breakerFamily = ArcFlashBreakerFamily::MCCB_OR_ICCB_1600_6000A;
1067 break;
1068
1069 case 2:
1070 if (currentRange != 0 || (tripUnit != 0 && tripUnit != 1))
1071 return showError(
1072 _("The selected LVPCB current range and trip unit are not compatible."));
1073
1074 result.breakerFamily = tripUnit == 0
1075 ? ArcFlashBreakerFamily::LVPCB_800_6300A_E_LI
1076 : ArcFlashBreakerFamily::LVPCB_800_6300A_E_LS;
1077 break;
1078 }
1079
1080
1081 const int voltageSelection = m_choiceCBVoltage->GetSelection();
1082
1083 if (voltageSelection < 0 || voltageSelection > 1)
1084 return showError(_("Select a valid circuit breaker voltage range."));
1085
1086 result.breakerVoltageBand = voltageSelection == 0
1087 ? ArcFlashBreakerVoltageBand::V480_AND_LOWER
1088 : ArcFlashBreakerVoltageBand::V575_TO_690;
1089
1090
1091 if (!parseDouble(m_textCtrlI2->GetValue(), result.i2_kA,
1092 _("Interrupting capacity (I₂) [kA]")))
1093 return false;
1094
1095 if (!requirePositive(result.i2_kA, _("Interrupting capacity (I₂) [kA]")))
1096 return false;
1097
1098
1099 const int i1Selection = m_radioBoxI1->GetSelection();
1100
1101 if (i1Selection < 0 || i1Selection > 1)
1102 return showError(_("Select a valid minimum current calculation method."));
1103
1104 if (i1Selection == 0) {
1105 double i1_A = 0.0;
1106
1107 if (!parseDouble(m_textCtrl1->GetValue(), i1_A,
1108 _("Minimum current (I₁) [A]")))
1109 return false;
1110
1111 if (!requirePositive(i1_A, _("Minimum current (I₁) [A]")))
1112 return false;
1113
1114 result.i1Source = ArcFlashI1Source::DIRECT;
1115 result.i1_kA = i1_A / 1000.0;
1116 result.it_A = 0.0;
1117 result.breakerNominalCurrent_A = 0.0;
1118 }
1119 else {
1120 double nominalCurrent_A = 0.0;
1121 double it_A = 0.0;
1122
1123 if (!parseDouble(m_textCtrlIn->GetValue(), nominalCurrent_A,
1124 _("Nominal current [A]")))
1125 return false;
1126
1127 if (!requirePositive(nominalCurrent_A, _("Nominal current [A]")))
1128 return false;
1129
1130 if (!parseDouble(m_textCtrl1->GetValue(), it_A,
1131 _("Instant/Short-Time current (Iₜ) [A]")))
1132 return false;
1133
1134 if (!requirePositive(it_A, _("Instant/Short-Time current (Iₜ) [A]")))
1135 return false;
1136
1137 result.i1Source = ArcFlashI1Source::FROM_IT;
1138 result.breakerNominalCurrent_A = nominalCurrent_A;
1139 result.it_A = it_A;
1140 result.i1_kA = 0.0;
1141 }
1142 }
1143
1144
1145 if (result.method == ArcFlashProtectionMethod::ANNEX_H) {
1146 const int fuseClass = m_choiceFuseClass->GetSelection();
1147 const int currentSelection = m_choiceFuseCurrent->GetSelection();
1148 const int currentCount = static_cast<int>(m_choiceFuseCurrent->GetCount());
1149
1150 if (fuseClass < 0 || fuseClass > 1 || currentSelection < 0)
1151 return showError(_("Select a valid fuse class and current range."));
1152
1153 int familyIndex = -1;
1154
1155 if (currentCount == 4) {
1156
1157 familyIndex = fuseClass * 4 + currentSelection;
1158 }
1159 else if (currentCount == 8) {
1160
1161 const int firstIndex = fuseClass * 4;
1162
1163 if (currentSelection < firstIndex || currentSelection >= firstIndex + 4)
1164 return showError(
1165 _("The selected fuse current range does not match the fuse class."));
1166
1167 familyIndex = currentSelection;
1168 }
1169 else {
1170 return showError(_("The fuse current range choices are invalid."));
1171 }
1172
1173 if (familyIndex < 0 || familyIndex > 7)
1174 return showError(_("Select a valid fuse current range."));
1175
1176 result.fuseFamily = static_cast<ArcFlashFuseFamily>(familyIndex);
1177 }
1178
1179
1180 const int selectedRow = m_dvListCtrlDevices->GetSelectedRow();
1181
1182
1183
1184
1185
1186 result.configured = true;
1187
1188 data = result;
1189 return true;
1190}