]> SALOME platform Git repositories - tools/yacsgen.git/blob - Examples/cppgui1/cppcomposGUI.cxx
Salome HOME
Merge from V6_main_20120808 08Aug12
[tools/yacsgen.git] / Examples / cppgui1 / cppcomposGUI.cxx
1 // Copyright (C) 2009-2012  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.
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 "cppcomposGUI.h"
21 #include <SUIT_MessageBox.h>
22 #include <SUIT_ResourceMgr.h>
23 #include <SUIT_Desktop.h>
24 #include <SUIT_Study.h>
25 #include <SalomeApp_Application.h>
26 #include <SALOME_LifeCycleCORBA.hxx>
27
28 #include <SALOMEconfig.h>
29 #include CORBA_CLIENT_HEADER(cppcompos)
30 #include CORBA_CLIENT_HEADER(SALOMEDS)
31 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
32
33 // QT Includes
34 #include <QInputDialog>
35 #include <QIcon>
36
37 // Export the module
38 extern "C" {
39   CAM_Module* createModule()
40   {
41     return new cppcomposGUI();
42   }
43 }
44
45 // Constructor
46 cppcomposGUI::cppcomposGUI() :
47   SalomeApp_Module( "cppcompos" ), // default name
48   LightApp_Module( "cppcompos" )
49 {
50 }
51
52 static cppcompos_ORB::cppcompos_var engine;
53
54 // Module's initialization
55 void cppcomposGUI::initialize( CAM_Application* app )
56 {
57
58   SalomeApp_Module::initialize( app );
59
60   Engines::EngineComponent_var comp = dynamic_cast<SalomeApp_Application*>(app)->lcc()->FindOrLoad_Component( "FactoryServer","cppcompos" );
61   engine = cppcompos_ORB::cppcompos::_narrow(comp);
62
63   QWidget* aParent = application()->desktop();
64   SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
65
66   // create actions
67   QPixmap aPixmap = aResourceMgr->loadPixmap( "cppcompos","exec.png" );
68   createAction( 901, "Banner", QIcon( aPixmap ), "Banner", "Banner", 0, aParent, false, this, SLOT( OnGetBanner() ) );
69   createAction( 902, "Designer", QIcon( aPixmap ), "Designer", "Designer", 0, aParent, false, this, SLOT( OnDesigner() ) );
70
71   // create menus
72   int aMenuId;
73   aMenuId = createMenu( "cppcompos", -1, -1, 30 );
74   createMenu( 901, aMenuId, 10 );
75
76   // create toolbars
77   int aToolId = createTool ( "cppcompos" );
78   createTool( 901, aToolId );
79   createTool( 902, aToolId );
80 }
81
82 // Get compatible dockable windows.
83 void cppcomposGUI::windows( QMap<int, int>& theMap ) const
84 {
85   theMap.clear();
86   theMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
87   theMap.insert( SalomeApp_Application::WT_PyConsole,     Qt::BottomDockWidgetArea );
88 }
89
90 // Module's engine IOR
91 QString cppcomposGUI::engineIOR() const
92 {
93   return "bidon";
94 }
95
96 // Module's activation
97 bool cppcomposGUI::activateModule( SUIT_Study* theStudy )
98 {
99   bool bOk = SalomeApp_Module::activateModule( theStudy );
100
101   setMenuShown( true );
102   setToolShown( true );
103
104   SALOME_NamingService *aNamingService = SalomeApp_Application::namingService();
105   CORBA::Object_var aSMObject = aNamingService->Resolve("/myStudyManager");
106   SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject);
107   SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID(theStudy->id());
108
109   SALOMEDS::SComponent_var aFather = aDSStudy->FindComponent("cppcompos");
110   if (aFather->_is_nil())
111     {
112       SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder();
113       aFather = aStudyBuilder->NewComponent("cppcompos");
114       SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
115       SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
116       aName->SetValue("cppcompos");
117       aName->UnRegister();
118       aStudyBuilder->DefineComponentInstance(aFather, engine);
119     }
120   CORBA::Boolean valid;
121   engine->DumpPython(aDSStudy,1,0,valid);
122
123   return bOk;
124 }
125
126 // Module's deactivation
127 bool cppcomposGUI::deactivateModule( SUIT_Study* theStudy )
128 {
129   setMenuShown( false );
130   setToolShown( false );
131
132   return SalomeApp_Module::deactivateModule( theStudy );
133 }
134
135 // Action slot
136 void cppcomposGUI::OnGetBanner()
137 {
138   // Dialog to get the Name
139   bool ok = FALSE;
140   QString myName = QInputDialog::getText( getApp()->desktop(), "label", "name", QLineEdit::Normal, QString::null, &ok );
141
142   if ( ok && !myName.isEmpty()) 
143   {
144     ::CORBA::Double c;
145     engine->s1(1.,2.,c);
146     std::cerr << c << std::endl;
147     QString banner = "Hello " + myName;
148     SUIT_MessageBox::information( getApp()->desktop(), "info", banner, "OK" );
149   }
150 }
151
152 // Action slot
153 void cppcomposGUI::OnDesigner()
154 {
155   QWidget* wid= new MyDemo(getApp()->desktop());
156   wid->show();
157 }
158
159 MyDemo::MyDemo(QWidget *parent)
160         :QDialog(parent)
161 {
162   ui.setupUi(this);
163 }