Salome HOME
54a91f95133bca8289a3472eb9528c188ff1b49c
[modules/geom.git] / src / GroupGUI / GroupGUI.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.salome-platform.org or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : GroupGUI.cxx
25 //  Author : Sergey ANIKIN
26 //  Module : GEOM
27 //  $Header$
28
29 #include "GroupGUI.h"
30 #include "GroupGUI_GroupDlg.h" 
31
32 #include "GEOMImpl_Types.hxx"
33
34 #include "SUIT_Session.h"
35 #include "SUIT_Desktop.h"
36 #include "SUIT_MessageBox.h"
37 #include "SalomeApp_Application.h"
38 #include "SalomeApp_Study.h"
39 #include "LightApp_SelectionMgr.h"
40
41 GroupGUI* GroupGUI::myGUIObject = 0;
42
43 //=======================================================================
44 // function : GetGroupGUI()
45 // purpose  : Get the only GroupGUI object [ static ]
46 //=======================================================================
47 GroupGUI* GroupGUI::GetGroupGUI(GeometryGUI* parent)
48 {
49   if ( myGUIObject == 0 ) 
50     myGUIObject = new GroupGUI(parent);
51
52   return myGUIObject;
53 }
54
55 //=======================================================================
56 // function : GroupGUI()
57 // purpose  : Constructor
58 //=======================================================================
59 GroupGUI::GroupGUI(GeometryGUI* parent)
60 : GEOMGUI(parent)
61 {
62 }
63
64 //=======================================================================
65 // function : ~GroupGUI()
66 // purpose  : Destructor
67 //=======================================================================
68 GroupGUI::~GroupGUI()
69 {
70 }
71
72
73 //=======================================================================
74 // function : OnGUIEvent()
75 // purpose  : 
76 //=======================================================================
77 bool GroupGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
78 {
79   getGeometryGUI()->EmitSignalDeactivateDialog();
80
81   QDialog* aDlg = NULL;
82
83   SUIT_Application* suitApp = SUIT_Session::session()->activeApplication();
84   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(suitApp->activeStudy());
85   if ( !appStudy ) return false;
86   _PTR(Study) aStudy = appStudy->studyDS();
87
88   if ( aStudy->GetProperties()->IsLocked() ) {
89     SUIT_MessageBox::warn1 ( parent,
90                              QObject::tr("WRN_WARNING"), 
91                              QObject::tr("WRN_STUDY_LOCKED"),
92                              QObject::tr("BUT_OK") );
93     return false;
94   }
95
96   switch ( theCommandID ) {
97   case 800: 
98   case 8001: // CREATE GROUP
99     aDlg = new GroupGUI_GroupDlg (GroupGUI_GroupDlg::CreateGroup, getGeometryGUI(), parent); 
100     break;
101   case 801:  // EDIT GROUP
102     {
103       SALOME_ListIO aList;
104       aList.Clear();
105
106       SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(suitApp);
107       if (app) {
108         LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
109         if (aSelMgr)
110           aSelMgr->selectedObjects(aList);
111       }
112
113       if (aList.Extent() == 1) {
114         Standard_Boolean aResult = Standard_False;
115         GEOM::GEOM_Object_var anObj =
116           GEOMBase::ConvertIOinGEOMObject( aList.First(), aResult );
117
118         if (aResult && !CORBA::is_nil(anObj) && anObj->GetType() == GEOM_GROUP) {
119           aDlg = new GroupGUI_GroupDlg (GroupGUI_GroupDlg::EditGroup, getGeometryGUI(), parent); 
120           break;
121         }
122       }
123       SUIT_MessageBox::warn1(parent, tr("WRN_WARNING"), tr("NO_GROUP"), tr("BUT_OK") );
124       break;
125     }
126   default: 
127     suitApp->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID)); 
128     break;
129   }
130
131   if (aDlg != NULL)
132     aDlg->show();
133
134   return true;
135 }
136
137 //=====================================================================================
138 // EXPORTED METHODS
139 //=====================================================================================
140 extern "C"
141 {
142 #ifdef WNT
143         __declspec( dllexport )
144 #endif
145   GEOMGUI* GetLibGUI(GeometryGUI* p)
146   {
147     return GroupGUI::GetGroupGUI(p);
148   }
149 }