Salome HOME
646379e30d76a3a239f03ed7211efa9c9a88f5d4
[modules/shaper.git] / src / ModelAPI / ModelAPI_Session.cpp
1 // Copyright (C) 2014-2023  CEA, EDF
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 <ModelAPI_Session.h>
21 // to avoid unresolved ModelAPI_Document()
22 #include <ModelAPI_Document.h>
23 // to avoid unresolved ModelAPI_Feature()
24 #include <ModelAPI_Feature.h>
25 #include <ModelAPI_Object.h>
26 // to avoid unresolved ModelAPI_Data()
27 #include <ModelAPI_Data.h>
28 // to avoid unresolved ModelAPI_Plugin()
29 #include <ModelAPI_Plugin.h>
30 #include <ModelAPI_Attribute.h>
31 #include <ModelAPI_AttributeDocRef.h>
32 #include <ModelAPI_AttributeDouble.h>
33 #include <ModelAPI_AttributeBoolean.h>
34 #include <ModelAPI_AttributeInteger.h>
35 #include <ModelAPI_AttributeString.h>
36 #include <ModelAPI_AttributeReference.h>
37 #include <ModelAPI_AttributeRefAttr.h>
38 #include <ModelAPI_AttributeRefList.h>
39 #include <ModelAPI_AttributeBoolean.h>
40 #include <ModelAPI_AttributeSelection.h>
41 #include <ModelAPI_AttributeSelectionList.h>
42 #include <ModelAPI_Events.h>
43 #include <ModelAPI_Validator.h>
44 #include <ModelAPI_ResultBody.h>
45 #include <ModelAPI_ResultConstruction.h>
46
47 #include <Config_ModuleReader.h>
48 #include <Config_PropManager.h>
49
50 #ifdef WIN32
51 #include <windows.h>
52 #else
53 #include <dlfcn.h>
54 #endif
55
56 #ifdef _DEBUG
57 #include <iostream>
58 #endif
59
60 /// Manager that will be initialized from Model package, one per application
61 std::shared_ptr<ModelAPI_Session> MY_MANAGER;
62
63 void ModelAPI_Session::setSession(std::shared_ptr<ModelAPI_Session> theManager)
64 {
65   MY_MANAGER = theManager;
66 }
67
68 std::shared_ptr<ModelAPI_Session> ModelAPI_Session::get()
69 {
70   if (!MY_MANAGER) {  // import Model library that implements this interface of ModelAPI
71     Config_ModuleReader::loadLibrary("Model");
72
73     Config_PropManager::registerProp("Visualization", "body_deflection",
74                                      "Body deflection coefficient",
75                                      Config_Prop::Double,
76                                      ModelAPI_ResultBody::DEFAULT_DEFLECTION());
77
78     Config_PropManager::registerProp("Visualization", "construction_deflection",
79                                      "Construction deflection coefficient",
80                                      Config_Prop::Double,
81                                      ModelAPI_ResultConstruction::DEFAULT_DEFLECTION());
82
83     Config_PropManager::registerProp("Visualization", "shaper_default_transparency",
84       "Default transparency (%)", Config_Prop::IntSpin, "0", "0", "100");
85
86   }
87   return MY_MANAGER;
88 }
89
90 /// instance of the events creator, one pre application
91 const ModelAPI_EventCreator* MY_API_CREATOR = 0;
92
93 const ModelAPI_EventCreator* ModelAPI_EventCreator::get()
94 {
95   if (!MY_API_CREATOR) {  // import Model library that implements this interface of ModelAPI
96     Config_ModuleReader::loadLibrary("Model");
97   }
98   return MY_API_CREATOR;
99 }
100
101 void ModelAPI_EventCreator::set(const ModelAPI_EventCreator* theCreator)
102 {
103   MY_API_CREATOR = theCreator;
104 }