Salome HOME
68bd77be8e211befdff4c62df1d9a827f7fceac6
[modules/geom.git] / src / BooleanGUI / BooleanGUI_Dialog.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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : BooleanGUI_Dialog.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "BooleanGUI_Dialog.h"
31 #include "BooleanGUI.h"
32 #include "DlgRef_2Sel_QTD.h"
33
34 #include "QAD_Desktop.h"
35
36 //=================================================================================
37 // class    : BooleanGUI_Dialog()
38 // purpose  : Constructs a BooleanGUI_Dialog which is a child of 'parent', with the
39 //            name 'name' and widget flags set to 'f'.
40 //            The dialog will by default be modeless, unless you set 'modal' to
41 //            TRUE to construct a modal dialog.
42 //=================================================================================
43 BooleanGUI_Dialog::BooleanGUI_Dialog( const int theOperation, QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
44   :GEOMBase_Skeleton(parent, name, Sel, modal, fl),
45    myOperation( theOperation )
46 {
47   QPixmap image0;
48   QString aTitle, aCaption;
49   switch ( myOperation )
50   {
51         case BooleanGUI::COMMON:
52           image0 = QPixmap( QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_COMMON")));
53                         aTitle = tr("GEOM_COMMON");
54                         aCaption = tr("GEOM_COMMON_TITLE");
55                         break;
56                 case BooleanGUI::CUT:
57           image0 = QPixmap( QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CUT")));
58                         aTitle = tr("GEOM_CUT");
59                         aCaption = tr("GEOM_CUT_TITLE");
60                         break;
61                 case BooleanGUI::FUSE:
62           image0 = QPixmap( QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_FUSE")));
63                         aTitle = tr("GEOM_FUSE");
64                         aCaption = tr("GEOM_FUSE_TITLE");
65                         break;
66                 case BooleanGUI::SECTION:
67           image0 = QPixmap( QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_SECTION")));
68                         aTitle = tr("GEOM_SECTION");
69                         aCaption = tr("GEOM_SECTION_TITLE");
70                         break;
71         }
72   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
73
74   setCaption( aCaption );
75
76   /***************************************************************/
77   GroupConstructors->setTitle( aTitle );
78   RadioButton1->setPixmap( image0 );
79   RadioButton2->close(TRUE);
80   RadioButton3->close(TRUE);
81
82   myGroup = new DlgRef_2Sel_QTD(this, "GroupCommon");
83   myGroup->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
84   if ( myOperation != BooleanGUI::CUT )
85   {
86         myGroup->TextLabel1->setText(tr("GEOM_OBJECT_I").arg("1"));
87         myGroup->TextLabel2->setText(tr("GEOM_OBJECT_I").arg("2"));
88   }
89   else
90   {
91         myGroup->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
92         myGroup->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
93   }
94   
95   myGroup->PushButton1->setPixmap(image1);
96   myGroup->PushButton2->setPixmap(image1);
97   myGroup->LineEdit1->setReadOnly( true );
98   myGroup->LineEdit2->setReadOnly( true );
99
100   Layout1->addWidget(myGroup, 2, 0);
101   /***************************************************************/
102
103   /* Initialisation */
104   Init();
105 }
106
107
108 //=================================================================================
109 // function : ~BooleanGUI_Dialog()
110 // purpose  : Destroys the object and frees any allocated resources
111 //=================================================================================
112 BooleanGUI_Dialog::~BooleanGUI_Dialog()
113 {
114 }
115
116
117
118 //=================================================================================
119 // function : Init()
120 // purpose  :
121 //=================================================================================
122 void BooleanGUI_Dialog::Init()
123 {
124   /* init variables */
125   myEditCurrentArgument = myGroup->LineEdit1;
126
127    /* signals and slots connections */
128   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
129   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
130
131   connect(myGroup->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
132   connect(myGroup->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
133
134   connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
135   connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
136
137   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
138
139   initName( GroupConstructors->title() );
140
141   globalSelection( GEOM_ALLSHAPES );
142 }
143
144
145 //=================================================================================
146 // function : ClickOnOk()
147 // purpose  :
148 //=================================================================================
149 void BooleanGUI_Dialog::ClickOnOk()
150 {
151   if ( ClickOnApply() )
152     ClickOnCancel();
153 }
154
155
156 //=================================================================================
157 // function : ClickOnApply()
158 // purpose  :
159 //=================================================================================
160 bool BooleanGUI_Dialog::ClickOnApply()
161 {
162   if ( !onAccept() )
163     return false;  
164
165   initName();
166   return true;
167 }
168
169
170 //=================================================================================
171 // function : SelectionIntoArgument()
172 // purpose  : Called when selection has changed
173 //=================================================================================
174 void BooleanGUI_Dialog::SelectionIntoArgument()
175 {
176   myEditCurrentArgument->setText( "" );
177
178   if ( mySelection->IObjectCount() != 1 )
179   {
180     if      ( myEditCurrentArgument == myGroup->LineEdit1 )   myObject1 = GEOM::GEOM_Object::_nil();
181     else if ( myEditCurrentArgument == myGroup->LineEdit2 )   myObject2 = GEOM::GEOM_Object::_nil();
182     return;
183   }
184
185   // nbSel == 1
186   Standard_Boolean aRes = Standard_False;
187   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), aRes );
188   if ( !CORBA::is_nil( aSelectedObject ) && aRes && GEOMBase::IsShape( aSelectedObject ) )
189   {
190     myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
191     if      ( myEditCurrentArgument == myGroup->LineEdit1 )   myObject1 = aSelectedObject;
192     else if ( myEditCurrentArgument == myGroup->LineEdit2 )   myObject2 = aSelectedObject;
193   }
194 }
195
196
197 //=================================================================================
198 // function : SetEditCurrentArgument()
199 // purpose  :
200 //=================================================================================
201 void BooleanGUI_Dialog::SetEditCurrentArgument()
202 {
203   QPushButton* send = (QPushButton*)sender();
204
205   if      ( send == myGroup->PushButton1 ) myEditCurrentArgument = myGroup->LineEdit1;
206   else if ( send == myGroup->PushButton2 ) myEditCurrentArgument = myGroup->LineEdit2;
207
208   myEditCurrentArgument->setFocus();
209   SelectionIntoArgument();
210 }
211
212
213
214 //=================================================================================
215 // function : LineEditReturnPressed()
216 // purpose  :
217 //=================================================================================
218 void BooleanGUI_Dialog::LineEditReturnPressed()
219 {
220   QLineEdit* send = (QLineEdit*)sender();
221   if ( send == myGroup->LineEdit1 || send == myGroup->LineEdit2 )
222   {
223     myEditCurrentArgument = send;
224     GEOMBase_Skeleton::LineEditReturnPressed();
225   }
226 }
227
228
229 //=================================================================================
230 // function : ActivateThisDialog()
231 // purpose  :
232 //=================================================================================
233 void BooleanGUI_Dialog::ActivateThisDialog()
234 {
235   GEOMBase_Skeleton::ActivateThisDialog();
236   globalSelection( GEOM_ALLSHAPES );
237   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
238 }
239
240
241 //=================================================================================
242 // function : enterEvent()
243 // purpose  : when mouse enter onto the QWidget
244 //=================================================================================
245 void BooleanGUI_Dialog::enterEvent(QEvent * e)
246 {
247   if ( !GroupConstructors->isEnabled() )
248     ActivateThisDialog();
249 }
250
251 //=================================================================================
252 // function : createOperation
253 // purpose  :
254 //=================================================================================
255 GEOM::GEOM_IOperations_ptr BooleanGUI_Dialog::createOperation()
256 {
257   return getGeomEngine()->GetIBooleanOperations( getStudyId() );
258 }
259
260 //=================================================================================
261 // function : isValid
262 // purpose  :
263 //=================================================================================
264 bool BooleanGUI_Dialog::isValid( QString& msg )
265 {
266   return !CORBA::is_nil( myObject1 ) && !CORBA::is_nil( myObject2 );
267 }
268
269 //=================================================================================
270 // function : execute
271 // purpose  :
272 //=================================================================================
273 bool BooleanGUI_Dialog::execute( ObjectList& objects )
274 {
275   GEOM::GEOM_Object_var anObj;
276  
277   anObj = GEOM::GEOM_IBooleanOperations::_narrow( getOperation() )->MakeBoolean( myObject1, myObject2, myOperation );
278   if ( !anObj->_is_nil() )
279     objects.push_back( anObj._retn() );
280
281   return true;
282 }