1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : TransformationGUI_PositionDlg.cxx
25 // Author : Damien COQUERET
29 #include "TransformationGUI_PositionDlg.h"
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
37 #include <qcheckbox.h>
39 #include "TColStd_MapOfInteger.hxx"
41 #include "GEOMImpl_Types.hxx"
43 #include "utilities.h"
47 //=================================================================================
48 // class : TransformationGUI_PositionDlg()
49 // purpose : Constructs a TransformationGUI_PositionDlg which is a child of 'parent', with the
50 // name 'name' and widget flags set to 'f'.
51 // The dialog will by default be modeless, unless you set 'modal' to
52 // TRUE to construct a modal dialog.
53 //=================================================================================
54 TransformationGUI_PositionDlg::TransformationGUI_PositionDlg
55 (GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
56 : GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
57 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
59 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
60 QPixmap image0(aResMgr->loadPixmap("GEOM",tr("ICON_DLG_POSITION")));
61 QPixmap image1(aResMgr->loadPixmap("GEOM",tr("ICON_DLG_POSITION2")));
62 QPixmap imageselect(aResMgr->loadPixmap("GEOM",tr("ICON_SELECT")));
64 setCaption(tr("GEOM_POSITION_TITLE"));
66 /***************************************************************/
67 GroupConstructors->setTitle(tr("GEOM_POSITION"));
68 RadioButton1->setPixmap(image0);
69 RadioButton2->setPixmap(image1);
70 RadioButton3->close(TRUE);
72 Group1 = new DlgRef_3Sel3Spin1Check(this, "Group1");
73 Group1->SpinBox1->hide();
74 Group1->SpinBox2->hide();
75 Group1->SpinBox3->hide();
76 Group1->TextLabel4->hide();
77 Group1->TextLabel5->hide();
78 Group1->TextLabel6->hide();
79 Group1->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
80 Group1->TextLabel1->setText(tr("GEOM_OBJECTS"));
81 Group1->TextLabel2->setText(tr("GEOM_START_LCS"));
82 Group1->TextLabel3->setText(tr("GEOM_END_LCS"));
83 Group1->PushButton1->setPixmap(imageselect);
84 Group1->PushButton2->setPixmap(imageselect);
85 Group1->PushButton3->setPixmap(imageselect);
86 Group1->CheckBox1->setText(tr("GEOM_CREATE_COPY"));
88 Layout1->addWidget(Group1, 2, 0);
90 /***************************************************************/
92 setHelpFileName("modify_the_location.htm");
98 //=================================================================================
99 // function : ~TransformationGUI_PositionDlg()
100 // purpose : Destroys the object and frees any allocated resources
101 //=================================================================================
102 TransformationGUI_PositionDlg::~TransformationGUI_PositionDlg()
104 /* no need to delete child widgets, Qt does it all for us */
108 //=================================================================================
111 //=================================================================================
112 void TransformationGUI_PositionDlg::Init()
115 Group1->LineEdit1->setReadOnly(true);
116 Group1->LineEdit2->setReadOnly(true);
117 Group1->LineEdit3->setReadOnly(true);
119 myStartLCS = GEOM::GEOM_Object::_nil();
120 myEndLCS = GEOM::GEOM_Object::_nil();
122 // Activate Create a Copy mode
123 Group1->CheckBox1->setChecked(true);
124 CreateCopyModeChanged(true);
126 /* signals and slots connections */
127 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
128 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
129 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
131 connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
132 connect(Group1->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 connect(Group1->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
135 connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
136 connect(Group1->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
137 connect(Group1->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
139 connect(Group1->CheckBox1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
141 connect(myGeomGUI->getApp()->selectionMgr(),
142 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
144 initName( tr( "GEOM_POSITION" ) );
145 ConstructorsClicked( 0 );
150 //=================================================================================
151 // function : ConstructorsClicked()
152 // purpose : Radio button management
153 //=================================================================================
154 void TransformationGUI_PositionDlg::ConstructorsClicked(int constructorId)
156 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
159 myEditCurrentArgument = Group1->LineEdit1;
160 Group1->LineEdit2->clear();
161 Group1->LineEdit3->clear();
162 myStartLCS = GEOM::GEOM_Object::_nil();
163 myEndLCS = GEOM::GEOM_Object::_nil();
165 switch (constructorId)
169 Group1->LineEdit2->hide();
170 Group1->TextLabel2->hide();
171 Group1->PushButton2->hide();
176 Group1->LineEdit2->show();
177 Group1->TextLabel2->show();
178 Group1->PushButton2->show();
182 connect(myGeomGUI->getApp()->selectionMgr(),
183 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
184 SelectionIntoArgument();
188 //=================================================================================
189 // function : ClickOnOk()
191 //=================================================================================
192 void TransformationGUI_PositionDlg::ClickOnOk()
194 if ( ClickOnApply() )
199 //=================================================================================
200 // function : ClickOnApply()
202 //=================================================================================
203 bool TransformationGUI_PositionDlg::ClickOnApply()
205 if ( !onAccept(Group1->CheckBox1->isChecked()) )
209 ConstructorsClicked( getConstructorId() );
214 //=================================================================================
215 // function : SelectionIntoArgument()
216 // purpose : Called when selection has changed
217 //=================================================================================
218 void TransformationGUI_PositionDlg::SelectionIntoArgument()
220 myEditCurrentArgument->setText("");
223 if(myEditCurrentArgument == Group1->LineEdit1) {
224 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
230 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
231 if (!myObjects.length()) {
236 else if(myEditCurrentArgument == Group1->LineEdit2) {
237 myStartLCS = GEOM::GEOM_Object::_nil();
238 if(IObjectCount() != 1) {
243 Standard_Boolean testResult = Standard_False;
244 myStartLCS = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
245 if(!testResult || CORBA::is_nil( myStartLCS )) {
249 aName = GEOMBase::GetName( myStartLCS );
251 else if(myEditCurrentArgument == Group1->LineEdit3) {
252 myEndLCS = GEOM::GEOM_Object::_nil();
253 if(IObjectCount() != 1) {
258 Standard_Boolean testResult = Standard_False;
259 myEndLCS = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
260 if(!testResult || CORBA::is_nil( myEndLCS )) {
264 aName = GEOMBase::GetName( myEndLCS );
267 myEditCurrentArgument->setText( aName );
272 //=================================================================================
273 // function : LineEditReturnPressed()
275 //=================================================================================
276 void TransformationGUI_PositionDlg::LineEditReturnPressed()
278 QLineEdit* send = (QLineEdit*)sender();
279 if(send == Group1->LineEdit1 || send == Group1->LineEdit2 || send == Group1->LineEdit3) {
280 myEditCurrentArgument = send;
281 GEOMBase_Skeleton::LineEditReturnPressed();
286 //=================================================================================
287 // function : SetEditCurrentArgument()
289 //=================================================================================
290 void TransformationGUI_PositionDlg::SetEditCurrentArgument()
292 QPushButton* send = (QPushButton*)sender();
294 if(send == Group1->PushButton1){
295 myEditCurrentArgument = Group1->LineEdit1;
298 else if(send == Group1->PushButton2) {
299 myEditCurrentArgument = Group1->LineEdit2;
300 TColStd_MapOfInteger aMap;
301 aMap.Add( GEOM_PLANE );
302 aMap.Add( GEOM_MARKER );
303 globalSelection( aMap );
305 else if(send == Group1->PushButton3) {
306 myEditCurrentArgument = Group1->LineEdit3;
307 TColStd_MapOfInteger aMap;
308 aMap.Add( GEOM_PLANE );
309 aMap.Add( GEOM_MARKER );
310 globalSelection( aMap );
313 myEditCurrentArgument->setFocus();
314 SelectionIntoArgument();
318 //=================================================================================
319 // function : ActivateThisDialog()
321 //=================================================================================
322 void TransformationGUI_PositionDlg::ActivateThisDialog()
324 GEOMBase_Skeleton::ActivateThisDialog();
325 connect(myGeomGUI->getApp()->selectionMgr(),
326 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
327 ConstructorsClicked( getConstructorId() );
331 //=================================================================================
332 // function : enterEvent()
333 // purpose : when mouse enter onto the QWidget
334 //=================================================================================
335 void TransformationGUI_PositionDlg::enterEvent(QEvent * e)
337 if(!GroupConstructors->isEnabled())
338 ActivateThisDialog();
342 //=================================================================================
343 // function : createOperation
345 //=================================================================================
346 GEOM::GEOM_IOperations_ptr TransformationGUI_PositionDlg::createOperation()
348 return getGeomEngine()->GetITransformOperations( getStudyId() );
352 //=================================================================================
353 // function : isValid
355 //=================================================================================
356 bool TransformationGUI_PositionDlg::isValid( QString& msg )
359 if (getConstructorId() == 0)
360 res = !(myObjects.length() == 0 || myEndLCS->_is_nil());
362 res = !(myObjects.length() == 0 || myStartLCS->_is_nil() || myEndLCS->_is_nil());
368 //=================================================================================
369 // function : execute
371 //=================================================================================
372 bool TransformationGUI_PositionDlg::execute( ObjectList& objects )
375 bool toCreateCopy = IsPreview() || Group1->CheckBox1->isChecked();
376 GEOM::GEOM_Object_var anObj;
378 switch ( getConstructorId() )
382 for (int i = 0; i < myObjects.length(); i++) {
384 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->PositionShapeCopy( myObjects[i], myObjects[i], myEndLCS );
386 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->PositionShape( myObjects[i], myObjects[i], myEndLCS );
388 if ( !anObj->_is_nil() )
389 objects.push_back( anObj._retn() );
396 for (int i = 0; i < myObjects.length(); i++) {
398 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->PositionShapeCopy( myObjects[i], myStartLCS, myEndLCS );
400 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->PositionShape( myObjects[i], myStartLCS, myEndLCS );
401 if ( !anObj->_is_nil() )
402 objects.push_back( anObj._retn() );
412 //=================================================================================
413 // function : closeEvent
415 //=================================================================================
416 void TransformationGUI_PositionDlg::closeEvent( QCloseEvent* e )
418 GEOMBase_Skeleton::closeEvent( e );
422 //=================================================================================
423 // function : CreateCopyModeChanged()
425 //=================================================================================
426 void TransformationGUI_PositionDlg::CreateCopyModeChanged(bool isCreateCopy)
428 this->GroupBoxName->setEnabled(isCreateCopy);