Salome HOME
d85d85d89e3066f396c36b08f7ce1dd115511171
[modules/geom.git] / src / GroupGUI / GroupGUI.cxx
1 // Copyright (C) 2007-2023  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, or (at your option) any later version.
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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : GroupGUI.cxx
25 // Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
26
27 #include "GroupGUI.h"
28 #include "GroupGUI_GroupDlg.h" 
29 #include "GroupGUI_BooleanDlg.h" 
30
31 #include <GeometryGUI.h>
32 #include "GeometryGUI_Operations.h"
33
34 #include <GEOMBase.h>
35 #include <GEOMImpl_Types.hxx>
36
37 #include <SUIT_Session.h>
38 #include <SUIT_Desktop.h>
39 #include <SUIT_MessageBox.h>
40 #include <SalomeApp_Application.h>
41 #include <SalomeApp_Study.h>
42 #include <LightApp_SelectionMgr.h>
43
44 //=======================================================================
45 // function : GroupGUI()
46 // purpose  : Constructor
47 //=======================================================================
48 GroupGUI::GroupGUI (GeometryGUI* parent)
49   : GEOMGUI(parent)
50 {
51 }
52
53 //=======================================================================
54 // function : ~GroupGUI()
55 // purpose  : Destructor
56 //=======================================================================
57 GroupGUI::~GroupGUI()
58 {
59 }
60
61
62 //=======================================================================
63 // function : OnGUIEvent()
64 // purpose  : 
65 //=======================================================================
66 bool GroupGUI::OnGUIEvent (int theCommandID, SUIT_Desktop* parent)
67 {
68   SalomeApp_Application* app = getGeometryGUI()->getApp();
69   if (!app) return false;
70
71   getGeometryGUI()->EmitSignalDeactivateDialog();
72
73   QDialog* aDlg = 0;
74
75   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
76   if (!appStudy) return false;
77   _PTR(Study) aStudy = appStudy->studyDS();
78
79   if (aStudy->GetProperties()->IsLocked()) {
80     SUIT_MessageBox::warning(parent, tr("WRN_WARNING"), 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         GEOM::GEOM_Object_var anObj =
100           GEOMBase::ConvertIOinGEOMObject(aList.First());
101
102         if (!CORBA::is_nil(anObj) && anObj->GetType() == GEOM_GROUP) {
103           aDlg = new GroupGUI_GroupDlg (GroupGUI_GroupDlg::EditGroup, getGeometryGUI(), parent); 
104           break;
105         }
106       }
107       SUIT_MessageBox::warning(parent, tr("WRN_WARNING"), tr("NO_GROUP"));
108     }
109     break;
110   case GEOMOp::OpGroupUnion: // UNION GROUPS
111     aDlg = new GroupGUI_BooleanDlg (GroupGUI_BooleanDlg::UNION, getGeometryGUI(), parent); 
112     break;
113   case GEOMOp::OpGroupIntersect: // INTERSECT GROUPS
114     aDlg = new GroupGUI_BooleanDlg (GroupGUI_BooleanDlg::INTERSECT, getGeometryGUI(), parent); 
115     break;
116   case GEOMOp::OpGroupCut: // CUT GROUPS
117     aDlg = new GroupGUI_BooleanDlg (GroupGUI_BooleanDlg::CUT, getGeometryGUI(), parent); 
118     break;
119   default: 
120     app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID)); 
121     break;
122   }
123
124   if (aDlg) {
125     aDlg->updateGeometry();
126     aDlg->resize(aDlg->minimumSizeHint());
127     aDlg->show();
128   }
129
130   return true;
131 }
132
133 //=====================================================================================
134 // EXPORTED METHODS
135 //=====================================================================================
136 extern "C"
137 {
138 #ifdef WIN32
139   __declspec( dllexport )
140 #endif
141   GEOMGUI* GetLibGUI( GeometryGUI* p )
142   {
143     return new GroupGUI( p );
144   }
145 }