Salome HOME
Copyright update 2022
[modules/yacs.git] / src / salomegui_swig / YACSGUI_Swig.cxx
1 // Copyright (C) 2006-2022  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "YACSGUI_Swig.hxx"
21 #include <iostream>
22
23 #include "SUIT_Desktop.h"
24 #include "SUIT_Session.h"
25
26 #include "SalomeApp_Application.h"
27 #include "SalomeApp_Study.h"
28
29 #include "SALOME_Event.h"
30 #include "Yacsgui.hxx"
31
32 /*! \class YACS_Swig
33  *  \brief Interface to YACS GUI
34  *
35  *  The YACS_Swig serves as an interface to the YACS GUI to activate it
36  *  or to load a schema.
37  *  It is wrapped with SWIG so it can be used from python to drive YACS GUI.
38  */
39
40 YACS_Swig::YACS_Swig()
41 {
42 }
43
44 YACS_Swig::~YACS_Swig()
45 {
46 }
47
48 //! Activate a module
49 /*!
50  * \param module the module name (default "YACS")
51  */
52 void YACS_Swig::activate(const std::string& module)
53 {
54   class TEvent: public SALOME_Event
55   {
56     YACS_Swig* _obj;
57     std::string _module;
58     public:
59       TEvent(YACS_Swig* obj,const std::string& module) {_obj=obj;_module=module;};
60       virtual void Execute() {
61         _obj->real_activate(_module);
62       };
63   };
64   ProcessVoidEvent(new TEvent(this,module));
65 }
66
67 void YACS_Swig::real_activate(const std::string& module)
68 {
69   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
70   if (!app) return;
71   SalomeApp_Study* ActiveStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
72   if (!ActiveStudy) return;
73   app->activateModule(QString::fromStdString(module));
74 }
75
76 //! Load a schema in edit mode or in run mode
77 /*!
78  * \param filename the schema file to load
79  * \param edit the loading mode. true for edition (default), false for run
80  */
81 void YACS_Swig::loadSchema(const std::string& filename,bool edit, bool arrangeLocalNodes)
82 {
83   class TEvent: public SALOME_Event
84   {
85     YACS_Swig* _obj;
86     std::string fn;
87     bool ed;
88     bool ar;
89     public:
90       TEvent(YACS_Swig* obj,const std::string& filename,bool edit,bool arrangeLocalNodes) {
91         _obj=obj;
92         fn=filename;
93         ed=edit;
94         ar=arrangeLocalNodes;
95       };
96       virtual void Execute() {
97         _obj->real_loadSchema(fn,ed,ar);
98       };
99   };
100   ProcessVoidEvent(new TEvent(this,filename,edit,arrangeLocalNodes));
101 }
102
103 void YACS_Swig::real_loadSchema(const std::string& filename,bool edit, bool arrangeLocalNodes)
104 {
105   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
106   if (!app) return;
107   app->activateModule( "YACS" );
108   CAM_Module* module = app->module("YACS");
109   Yacsgui* appMod = dynamic_cast<Yacsgui*>(module);
110   if (appMod)
111     appMod->loadSchema(filename,edit,arrangeLocalNodes);
112 }