Salome HOME
0020695: EDF 1076 GEOM: Add a new shape in GEOM: T-shape
[modules/geom.git] / src / GroupGUI / GroupGUI.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.com
21 //
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File   : GroupGUI.cxx
24 // Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
25 //
26 #include "GroupGUI.h"
27 #include "GroupGUI_GroupDlg.h" 
28
29 #include <GeometryGUI.h>
30 #include "GeometryGUI_Operations.h"
31
32 #include <GEOMBase.h>
33 #include <GEOMImpl_Types.hxx>
34
35 #include <SUIT_Session.h>
36 #include <SUIT_Desktop.h>
37 #include <SUIT_MessageBox.h>
38 #include <SalomeApp_Application.h>
39 #include <SalomeApp_Study.h>
40 #include <LightApp_SelectionMgr.h>
41
42 //=======================================================================
43 // function : GroupGUI()
44 // purpose  : Constructor
45 //=======================================================================
46 GroupGUI::GroupGUI( GeometryGUI* parent )
47   : GEOMGUI( parent )
48 {
49 }
50
51 //=======================================================================
52 // function : ~GroupGUI()
53 // purpose  : Destructor
54 //=======================================================================
55 GroupGUI::~GroupGUI()
56 {
57 }
58
59
60 //=======================================================================
61 // function : OnGUIEvent()
62 // purpose  : 
63 //=======================================================================
64 bool GroupGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
65 {
66   SalomeApp_Application* app = getGeometryGUI()->getApp();
67   if ( !app ) return false;
68
69   getGeometryGUI()->EmitSignalDeactivateDialog();
70
71   QDialog* aDlg = 0;
72
73   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
74   if ( !appStudy ) return false;
75   _PTR(Study) aStudy = appStudy->studyDS();
76
77   if ( aStudy->GetProperties()->IsLocked() ) {
78     SUIT_MessageBox::warning( parent,
79                               tr( "WRN_WARNING" ), 
80                               tr( "WRN_STUDY_LOCKED" ) );
81     return false;
82   }
83
84   switch ( theCommandID ) {
85   case GEOMOp::OpGroupCreate: 
86   case GEOMOp::OpGroupCreatePopup: // CREATE GROUP
87     aDlg = new GroupGUI_GroupDlg( GroupGUI_GroupDlg::CreateGroup, getGeometryGUI(), parent ); 
88     break;
89   case GEOMOp::OpGroupEdit:  // EDIT GROUP
90     {
91       SALOME_ListIO aList;
92       aList.Clear();
93
94       LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
95       if ( aSelMgr )
96         aSelMgr->selectedObjects( aList );
97
98       if ( aList.Extent() == 1 ) {
99         Standard_Boolean aResult = Standard_False;
100         GEOM::GEOM_Object_var anObj =
101           GEOMBase::ConvertIOinGEOMObject( aList.First(), aResult );
102
103         if ( aResult && !CORBA::is_nil( anObj ) && anObj->GetType() == GEOM_GROUP ) {
104           aDlg = new GroupGUI_GroupDlg( GroupGUI_GroupDlg::EditGroup, getGeometryGUI(), parent ); 
105           break;
106         }
107       }
108       SUIT_MessageBox::warning( parent, tr( "WRN_WARNING" ), tr( "NO_GROUP" ) );
109       break;
110     }
111   default: 
112     app->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) ); 
113     break;
114   }
115
116   if ( aDlg ) {
117     aDlg->updateGeometry();
118     aDlg->resize( aDlg->minimumSizeHint() );
119     aDlg->show();
120   }
121
122   return true;
123 }
124
125 //=====================================================================================
126 // EXPORTED METHODS
127 //=====================================================================================
128 extern "C"
129 {
130 #ifdef WIN32
131   __declspec( dllexport )
132 #endif
133   GEOMGUI* GetLibGUI( GeometryGUI* p )
134   {
135     return new GroupGUI( p );
136   }
137 }