ITS_OPLibF.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <DateUtils.hpp>
  4. #pragma hdrstop
  5. #include "ITS_OPLibF.h"
  6. #include "CDSCodeF.h"
  7. #include "CDSVmsCtlrF.h"
  8. #include "CDSVmsObjTypeF.h"
  9. //---------------------------------------------------------------------------
  10. #pragma package(smart_init)
  11. TITSLog *ITSLog = NULL;
  12. String g_sMapDir = "";
  13. int g_nMapSource = 1;
  14. ST_GISINFO g_GisInfo;
  15. ST_SELLINK g_SelLink;
  16. APP_CONFIG g_AppCfg;
  17. TColor g_DispColor[MAX_DISPCOLOR];
  18. void APP_InitDisplayColor()
  19. {
  20. #if 0
  21. g_DispColor[ 0] = Graphics::clBlue;
  22. g_DispColor[ 1] = Graphics::clRed;
  23. g_DispColor[ 2] = Graphics::clLime;
  24. g_DispColor[ 3] = Graphics::clMaroon;
  25. g_DispColor[ 4] = Graphics::clGreen;
  26. g_DispColor[ 5] = Graphics::clMenuHighlight;
  27. g_DispColor[ 6] = Graphics::clBackground;
  28. g_DispColor[ 7] = Graphics::clPurple;
  29. g_DispColor[ 8] = Graphics::clTeal;
  30. g_DispColor[ 9] = Graphics::clYellow;
  31. g_DispColor[10] = Graphics::clFuchsia;
  32. g_DispColor[11] = Graphics::clAqua;
  33. g_DispColor[12] = Graphics::clMoneyGreen;
  34. g_DispColor[13] = Graphics::clSkyBlue;
  35. g_DispColor[14] = Graphics::clRed;
  36. g_DispColor[15] = Graphics::clLime;
  37. g_DispColor[16] = Graphics::clYellow;
  38. g_DispColor[17] = Graphics::clBlue;
  39. g_DispColor[18] = Graphics::clFuchsia;
  40. g_DispColor[19] = Graphics::clAqua;
  41. g_DispColor[20] = Graphics::clMoneyGreen;
  42. g_DispColor[21] = Graphics::clActiveCaption;
  43. #else
  44. g_DispColor[ 0] = Graphics::clLime;
  45. g_DispColor[ 1] = (TColor)RGB(0xFF, 0x00, 0x00);
  46. g_DispColor[ 2] = (TColor)RGB(0x00, 0x00, 0xFF);
  47. g_DispColor[ 3] = (TColor)RGB(0xFF, 0x82, 0x00);
  48. g_DispColor[ 4] = (TColor)RGB(0x94, 0x00, 0xD3);
  49. g_DispColor[ 5] = (TColor)RGB(0x00, 0x00, 0x00);
  50. g_DispColor[ 6] = (TColor)RGB(0x82, 0x82, 0x82);
  51. g_DispColor[ 7] = (TColor)RGB(0x1E, 0x90, 0xFF);
  52. g_DispColor[ 8] = (TColor)RGB(0xB9, 0x06, 0x2F);
  53. g_DispColor[ 9] = (TColor)RGB(0x8c, 0x00, 0x8c);
  54. g_DispColor[10] = (TColor)RGB(0xFF, 0x82, 0x00);
  55. g_DispColor[11] = (TColor)RGB(0x94, 0x00, 0xD3);
  56. g_DispColor[12] = (TColor)RGB(0xB0, 0xC4, 0xDE);
  57. g_DispColor[13] = (TColor)RGB(0x00, 0xBF, 0xFF);
  58. g_DispColor[14] = (TColor)RGB(0x87, 0xCE, 0xEB);
  59. g_DispColor[15] = (TColor)RGB(0x87, 0xCE, 0xFA);
  60. g_DispColor[16] = (TColor)RGB(0xAD, 0xD8, 0xE6);
  61. g_DispColor[17] = (TColor)RGB(0xB0, 0xE0, 0xE6);
  62. g_DispColor[18] = (TColor)RGB(0xE6, 0xE6, 0xFA);
  63. g_DispColor[19] = (TColor)RGB(0xF0, 0xF8, 0xFF);
  64. #endif
  65. }
  66. //---------------------------------------------------------------------------
  67. TColor APP_GetDisplayColor(int ASeq)
  68. {
  69. return g_DispColor[ASeq % MAX_DISPCOLOR];
  70. }
  71. //---------------------------------------------------------------------------
  72. void APP_ImageClear(TCanvas *c, int offX, int offY, int w, int h, TColor color)
  73. {
  74. try
  75. {
  76. c->Pen->Color = clWhite;
  77. c->Pen->Width = 0;
  78. c->Pen->Style = psClear;
  79. c->Brush->Style = bsSolid;
  80. c->Brush->Color = color;
  81. c->Rectangle(offX, offY, w+offX+2, h+offY+2);
  82. }
  83. catch(...)
  84. {
  85. }
  86. }
  87. //---------------------------------------------------------------------------
  88. TDateTime APP_StrToDateTime(String AStrDateTime)
  89. {
  90. TDateTime dtReturnValue = NULL;
  91. if (AStrDateTime.IsEmpty()) return dtReturnValue;
  92. if (AStrDateTime.Length() != 14) return dtReturnValue;
  93. AnsiString sDateTime = AnsiString(AStrDateTime);
  94. try
  95. {
  96. #if 0
  97. sDateTime.printf(L"%s-%s-%s %s:%s:%s",
  98. AStrDateTime.SubString( 1, 4).c_str(),
  99. AStrDateTime.SubString( 5, 2).c_str(),
  100. AStrDateTime.SubString( 7, 2).c_str(),
  101. AStrDateTime.SubString( 9, 2).c_str(),
  102. AStrDateTime.SubString(11, 2).c_str(),
  103. AStrDateTime.SubString(13, 2).c_str());
  104. dtReturnValue = StrToDateTime(sDateTime);
  105. #endif
  106. // swscanf(sRgb.c_str(), L"%d,%d,%d", &r, &g, &b);
  107. int year, month, day, hour, minute, second;
  108. sscanf(sDateTime.c_str(), "%4d%2d%2d%2d%2d%2d", &year, &month, &day, &hour, &minute, &second);
  109. dtReturnValue = EncodeDateTime(year, month, day, hour, minute, second, 0);
  110. }
  111. catch(...)
  112. {
  113. }
  114. return dtReturnValue;
  115. }
  116. //---------------------------------------------------------------------------
  117. void APP_ShowErrorMsg(String ATitle, String AErrMsg)
  118. {
  119. Application->NormalizeTopMosts();
  120. Application->MessageBox(AErrMsg.c_str(), ATitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  121. Application->RestoreTopMosts();
  122. }
  123. //----------------------------------------------------------------------------
  124. String APP_FillCode(TcxComboBox *ACombo, String ACode)
  125. {
  126. String sReturn = "";
  127. ACombo->Properties->Items->Clear();
  128. TItsCode *FCodeRMF = ItsCodeManager->FLists.Find(ACode);
  129. if (FCodeRMF)
  130. {
  131. FOR_STL(TItsSubCode *, pSubCode, FCodeRMF->FSubLists)
  132. {
  133. if (pSubCode->USE_YN == "N") continue;
  134. ACombo->Properties->Items->Add(" [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
  135. if (sReturn == "")
  136. {
  137. sReturn = " [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM;
  138. }
  139. }
  140. }
  141. ACombo->ItemIndex = 0;
  142. return sReturn;
  143. }
  144. //----------------------------------------------------------------------------
  145. String APP_GetCode(TcxComboBox *ACombo)
  146. {
  147. String sReturn = "";
  148. if (ACombo->ItemIndex >= 0)
  149. {
  150. String sDesc = ACombo->Properties->Items->Strings[ACombo->ItemIndex];
  151. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  152. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  153. sReturn = sCode;
  154. }
  155. return sReturn;
  156. }
  157. //----------------------------------------------------------------------------
  158. String APP_GetCodeName(TcxComboBox *ACombo, String ACode)
  159. {
  160. String sReturn = "";
  161. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  162. {
  163. String sDesc = ACombo->Properties->Items->Strings[ii];
  164. String sName = sDesc.SubString(sDesc.Pos("]") + 1, sDesc.Length());
  165. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  166. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  167. if (ACode == sCode)
  168. {
  169. sReturn = sName.Trim();
  170. break;
  171. }
  172. }
  173. return sReturn;
  174. }
  175. //----------------------------------------------------------------------------
  176. String APP_GetCodeIdByName(TcxComboBox *ACombo, String AName)
  177. {
  178. String sReturn = "3";
  179. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  180. {
  181. String sDesc = ACombo->Properties->Items->Strings[ii];
  182. String sName = sDesc.SubString(sDesc.Pos("]") + 1, sDesc.Length());
  183. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  184. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  185. if (sName.Trim() == AName.Trim())
  186. {
  187. sReturn = sCode;
  188. break;
  189. }
  190. }
  191. return sReturn;
  192. }
  193. //----------------------------------------------------------------------------
  194. String APP_GetCodeDesc(TcxComboBox *ACombo, String ACode)
  195. {
  196. String sReturn = "";
  197. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  198. {
  199. String sDesc = ACombo->Properties->Items->Strings[ii];
  200. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  201. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  202. if (ACode == sCode)
  203. {
  204. sReturn = sDesc;
  205. break;
  206. }
  207. }
  208. return sReturn;
  209. }
  210. //----------------------------------------------------------------------------
  211. String APP_GetCodeDefCode(TcxComboBox *ACombo)
  212. {
  213. String sReturn = "";
  214. if (ACombo->Properties->Items->Count > 0)
  215. {
  216. String sDesc = ACombo->Properties->Items->Strings[0];
  217. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  218. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  219. sReturn = sCode;
  220. }
  221. return sReturn;
  222. }
  223. //----------------------------------------------------------------------------
  224. String APP_GetCodeDefDesc(TcxComboBox *ACombo)
  225. {
  226. String sReturn = "";
  227. if (ACombo->Properties->Items->Count > 0)
  228. {
  229. String sDesc = ACombo->Properties->Items->Strings[0];
  230. sReturn = sDesc;
  231. }
  232. return sReturn;
  233. }
  234. //----------------------------------------------------------------------------
  235. int APP_SetCode(TcxComboBox *ACombo, String ACode)
  236. {
  237. int nItemIndex = -1;
  238. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  239. {
  240. String sDesc = ACombo->Properties->Items->Strings[ii];
  241. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  242. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  243. if (ACode == sCode)
  244. {
  245. nItemIndex = ii;
  246. break;
  247. }
  248. }
  249. ACombo->ItemIndex = nItemIndex;
  250. return nItemIndex;
  251. }
  252. //----------------------------------------------------------------------------
  253. void APP_DelVmsSizeCombo(TcxComboBox *cboBox)
  254. {
  255. TStrings *pStrItems;
  256. TVmsSizeType *Ov;
  257. pStrItems = ((TcxComboBox *)cboBox)->Properties->Items;
  258. for (int ii = pStrItems->Count-1; ii >= 0; ii--)
  259. {
  260. Ov = (TVmsSizeType *)pStrItems->Objects[ii];
  261. if (Ov != NULL)
  262. {
  263. delete Ov;
  264. Ov = NULL;
  265. }
  266. }
  267. }
  268. //---------------------------------------------------------------------------
  269. void APP_FillVmsSizeType(TcxComboBox *cboBox, bool bAddAll/*=false*/)
  270. {
  271. String sQry;
  272. TStrings *pStrItems;
  273. TADOQuery *pADO = NULL;
  274. APP_DelVmsSizeCombo(cboBox);
  275. pStrItems = ((TcxComboBox *)cboBox)->Properties->Items;
  276. ((TcxComboBox *)cboBox)->Properties->Items->Clear();
  277. FOR_STL(TVmsType*, pObj, VmsTypeManager->FLists)
  278. {
  279. String sTypeCd = pObj->VMS_TYPE_CD;
  280. String sTypeNm = pObj->VMS_TYPE_NM;
  281. int nW = pObj->VMS_WDTH;
  282. int nH = pObj->VMS_HGHT;
  283. pStrItems->AddObject(" [" + sTypeCd + "] " + sTypeNm + " (" + String(nW) + "x" + String(nH) + ")", new TVmsSizeType(sTypeCd, sTypeNm, nW, nH) );
  284. }
  285. if (bAddAll)
  286. {
  287. String sAllName = "전체";
  288. pStrItems->AddObject(" [ALL] 전체" , new TVmsSizeType("ALL", sAllName, 384, 64));
  289. }
  290. cboBox->ItemIndex = 0;
  291. }
  292. //---------------------------------------------------------------------------
  293. TVmsSizeType* APP_GetVmsSizeTypeObject(TcxComboBox *cboBox)
  294. {
  295. TStrings *pStrItems;
  296. TVmsSizeType *Ov = NULL;
  297. int nItemIndex;
  298. pStrItems = ((TcxComboBox *)cboBox)->Properties->Items;
  299. nItemIndex= ((TcxComboBox *)cboBox)->ItemIndex;
  300. if (nItemIndex < 0)
  301. {
  302. return Ov;
  303. }
  304. Ov = (TVmsSizeType *)pStrItems->Objects[nItemIndex];
  305. if (Ov == NULL)
  306. {
  307. Ov = NULL;
  308. }
  309. return Ov;
  310. }
  311. //---------------------------------------------------------------------------
  312. bool APP_WriteConfigInfo(String sCfgFile, String sTitle, String sItem, String sValue)
  313. {
  314. String ConfigFile;
  315. TIniFile *pIniFile = NULL;
  316. ConfigFile = sCfgFile;
  317. try
  318. {
  319. pIniFile = new TIniFile(ConfigFile);
  320. if (pIniFile == NULL)
  321. {
  322. return false;
  323. }
  324. pIniFile->WriteString(sTitle, sItem, sValue);
  325. }
  326. catch(...)
  327. {
  328. }
  329. if (pIniFile)
  330. {
  331. pIniFile->Free();
  332. pIniFile = NULL;
  333. }
  334. return true;
  335. }
  336. //---------------------------------------------------------------------------
  337. String APP_FormatStr(String AStrDateTime, String AFormat)
  338. {
  339. #define SYEAR "-"
  340. #define STIME ":"
  341. #define SPACE " "
  342. String sDateTime = "";
  343. String sInData = AStrDateTime;//AnsiString(AStrDateTime);
  344. String sFormat = AFormat;
  345. if (sInData.IsEmpty())
  346. return sInData;
  347. try
  348. {
  349. if (sFormat == STR_DATETIME)
  350. {
  351. if (sInData.Length() < 14) return sInData;
  352. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  353. sInData.SubString( 5, 2) + SYEAR +
  354. sInData.SubString( 7, 2) + SPACE +
  355. sInData.SubString( 9, 2) + STIME +
  356. sInData.SubString(11, 2) + STIME +
  357. sInData.SubString(13, 2);
  358. }
  359. else
  360. if (sFormat == STR_HHNN)
  361. {
  362. if (sInData.Length() < 12) return sInData;
  363. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  364. sInData.SubString( 5, 2) + SYEAR +
  365. sInData.SubString( 7, 2) + SPACE +
  366. sInData.SubString( 9, 2) + STIME +
  367. sInData.SubString(11, 2);
  368. }
  369. else
  370. if (sFormat == STR_DATEHOUR)
  371. {
  372. if (sInData.Length() < 10) return sInData;
  373. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  374. sInData.SubString( 5, 2) + SYEAR +
  375. sInData.SubString( 7, 2) + SPACE +
  376. sInData.SubString( 9, 2);
  377. }
  378. else
  379. if (sFormat == STR_DATE)
  380. {
  381. if (sInData.Length() < 8) return sInData;
  382. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  383. sInData.SubString( 5, 2) + SYEAR +
  384. sInData.SubString( 7, 2);
  385. }
  386. else
  387. if (sFormat == STR_MM)
  388. {
  389. if (sInData.Length() < 6) return sInData;
  390. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  391. sInData.SubString( 5, 2);
  392. }
  393. else
  394. {
  395. sDateTime = sInData;
  396. }
  397. }
  398. catch(Exception &E)
  399. {
  400. throw Exception(String(E.ClassName()) + E.Message);
  401. }
  402. return sDateTime;
  403. }
  404. //---------------------------------------------------------------------------
  405. void APP_SetSummaryItemKind(TcxSummaryEventArguments &Arguments,
  406. TcxSummaryEventOutArguments &OutArguments,
  407. int pKind,
  408. bool pCaptionDisplay,
  409. bool pPointDisplay)
  410. {
  411. #if 0
  412. String sAvgCaption, sSumCaption, sMinCaption, sMaxCaption, sCntCaption;
  413. sAvgCaption = "";
  414. sMinCaption = "";
  415. sMaxCaption = "";
  416. //sCntCaption = "";
  417. sSumCaption = "";
  418. if (pCaptionDisplay)
  419. {
  420. sAvgCaption = "";//"평균: ";
  421. sMinCaption = "최소: ";
  422. sMaxCaption = "최대: ";
  423. if (pKind == 1)
  424. {
  425. sSumCaption = "소계: ";
  426. }
  427. else
  428. {
  429. sSumCaption = "합계: ";
  430. }
  431. }
  432. //sCntCaption = " 건";
  433. #endif
  434. #if 0
  435. if (VarIsNull(OutArguments.Value))
  436. {
  437. OutArguments.Done = true;
  438. return;
  439. }
  440. #endif
  441. #if 0
  442. if (Arguments.SummaryItem->Kind == skSum)
  443. {
  444. if (!VarIsNull(OutArguments.Value))
  445. {
  446. if (!VarSameValue(OutArguments.Value, Variant(0)))
  447. {
  448. OutArguments.CountValue++;
  449. OutArguments.SummaryValue += OutArguments.Value;
  450. OutArguments.Done = true;
  451. }
  452. else
  453. {
  454. //OutArguments.CountValue--;
  455. OutArguments.Done = true;
  456. }
  457. }
  458. else
  459. {
  460. //OutArguments.CountValue--;
  461. OutArguments.Done = true;
  462. }
  463. }
  464. else
  465. #endif
  466. if (Arguments.SummaryItem->Kind == skAverage)
  467. {
  468. if (!VarIsNull(OutArguments.Value))
  469. {
  470. if (!VarSameValue(OutArguments.Value, Variant(0)))
  471. {
  472. OutArguments.CountValue++;
  473. //OutArguments.Value = Variant(0);
  474. OutArguments.SummaryValue += OutArguments.Value;
  475. OutArguments.Done = true;
  476. }
  477. else
  478. {
  479. //OutArguments.CountValue--;
  480. OutArguments.Done = true;
  481. }
  482. }
  483. else
  484. {
  485. //OutArguments.CountValue--;
  486. OutArguments.Done = true;
  487. }
  488. #if 0
  489. if (pPointDisplay)
  490. Arguments.SummaryItem->Format = sAvgCaption + "#,##0.0";
  491. else
  492. Arguments.SummaryItem->Format = sAvgCaption + "#,##0";
  493. #endif
  494. }
  495. #if 0
  496. else if (Arguments.SummaryItem->Kind == skSum)
  497. Arguments.SummaryItem->Format = sSumCaption + "#,##0.##";
  498. else if (Arguments.SummaryItem->Kind == skMin)
  499. Arguments.SummaryItem->Format = sMinCaption + "#,##0.##";
  500. else if (Arguments.SummaryItem->Kind == skMax)
  501. Arguments.SummaryItem->Format = sMaxCaption + "#,##0.##";
  502. else if (Arguments.SummaryItem->Kind == skCount)
  503. Arguments.SummaryItem->Format = "#,##0" + sCntCaption;
  504. #endif
  505. }
  506. //---------------------------------------------------------------------------
  507. ULONG ProcIDFromWnd(HWND hwnd) // 윈도우 핸들로 프로세스 아이디 얻기
  508. {
  509. ULONG idProc;
  510. GetWindowThreadProcessId( hwnd, &idProc );
  511. return idProc;
  512. }
  513. //----------------------------------------------------------------------------
  514. HWND GetWinHandle(ULONG pid) // 프로세스 아이디로 윈도우 핸들 얻기
  515. {
  516. HWND tempHwnd = FindWindow(NULL,NULL); // 최상위 윈도우 핸들 찾기
  517. while( tempHwnd != NULL )
  518. {
  519. if( GetParent(tempHwnd) == NULL ) // 최상위 핸들인지 체크, 버튼 등도 핸들을 가질 수 있으므로 무시하기 위해
  520. if( pid == ProcIDFromWnd(tempHwnd) )
  521. return tempHwnd;
  522. tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT); // 다음 윈도우 핸들 찾기
  523. }
  524. return NULL;
  525. }
  526. //----------------------------------------------------------------------------
  527. //DeleteLogFiles((PTCHAR)g_sLogDir.c_str(), 30, (PTCHAR)"*.*");
  528. //bool DeleteLogFiles(PTCHAR pszPath, int nDays, PTCHAR pszFile);
  529. #include <windows.h>
  530. #include <shlwapi.h>
  531. #pragma comment (lib, "shlwapi.lib")
  532. bool APP_IsDirectoryExists(LPCTSTR path)
  533. {
  534. return PathFileExists(path);
  535. #if 0
  536. struct _stat buffer;
  537. int iRetTemp = 0;
  538. memset((void*)&buffer, 0, sizeof(buffer));
  539. iRetTemp = _stat(path, &buffer);
  540. if (iRetTemp == 0)
  541. {
  542. if (buffer.st_mode & _S_IFDIR)
  543. {
  544. return true;
  545. }
  546. }
  547. return false;
  548. #endif
  549. }
  550. //---------------------------------------------------------------------------