Antares Simulator
Power System Simulator
drag-drop.hxx
1 /*
2  * Copyright 2007-2025, RTE (https://www.rte-france.com)
3  * See AUTHORS.txt
4  * SPDX-License-Identifier: MPL-2.0
5  * This file is part of Antares-Simulator,
6  * Adequacy and Performance assessment for interconnected energy networks.
7  *
8  * Antares_Simulator is free software: you can redistribute it and/or modify
9  * it under the terms of the Mozilla Public Licence 2.0 as published by
10  * the Mozilla Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * Antares_Simulator is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * Mozilla Public Licence 2.0 for more details.
17  *
18  * You should have received a copy of the Mozilla Public Licence 2.0
19  * along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20  */
21 
22 #include "main.h"
23 #include <wx/dnd.h>
24 #include "antares/study/study.h"
25 #include "../../toolbox/dispatcher/study.h"
26 #include <ui/common/lock.h>
27 #include "antares/utils/utils.h"
28 
29 using namespace Yuni;
30 
31 namespace Antares::Forms
32 {
33 
34 class StudyDrop final: public wxFileDropTarget
35 {
36 public:
37  StudyDrop():
38  wxFileDropTarget()
39  {
40  }
41 
42  virtual ~StudyDrop()
43  {
44  }
45 
46  virtual bool OnDropFiles(wxCoord /*x*/, wxCoord /*y*/, const wxArrayString& filenames) override
47  {
48  if (IsGUIAboutToQuit() or GUIIsLock())
49  {
50  return false;
51  }
52 
53  String filename;
54  String folder;
55  String title;
56 
57  for (uint i = 0; i != (uint)filenames.size(); ++i)
58  {
59  wxStringToString(filenames[i], filename);
60 
61  if (!Utils::isPathValid(filename.to<std::string>()))
62  {
63  logs.error() << "Drag & drop : study path contains a non ASCII char";
64  return false;
65  }
66 
67  if (not Data::Study::IsInsideStudyFolder(filename, folder, title))
68  {
69  folder.clear();
70  }
71  }
72 
73  if (not folder.empty())
74  {
75  // opening the study
76  Dispatcher::StudyOpen(folder);
77  }
78  else
79  {
80  logs.warning() << "The folder provided by drag & drop is not a valid study: "
81  << filename;
82  }
83 
84  return true;
85  }
86 
87 }; // class StudyDrop
88 
89 } // namespace Antares::Forms
Definition: drag-drop.hxx:35