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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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(QWidget* parent, const char* name, bool modal, WFlags fl)
55 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
57 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_POSITION")));
58 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_POSITION2")));
59 QPixmap imageselect(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
61 setCaption(tr("GEOM_POSITION_TITLE"));
63 /***************************************************************/
64 GroupConstructors->setTitle(tr("GEOM_POSITION"));
65 RadioButton1->setPixmap(image0);
66 RadioButton2->setPixmap(image1);
67 RadioButton3->close(TRUE);
69 Group1 = new DlgRef_3Sel3Spin1Check(this, "Group1");
70 Group1->SpinBox1->hide();
71 Group1->SpinBox2->hide();
72 Group1->SpinBox3->hide();
73 Group1->TextLabel4->hide();
74 Group1->TextLabel5->hide();
75 Group1->TextLabel6->hide();
76 Group1->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
77 Group1->TextLabel1->setText(tr("GEOM_OBJECTS"));
78 Group1->TextLabel2->setText(tr("GEOM_START_LCS"));
79 Group1->TextLabel3->setText(tr("GEOM_END_LCS"));
80 Group1->PushButton1->setPixmap(imageselect);
81 Group1->PushButton2->setPixmap(imageselect);
82 Group1->PushButton3->setPixmap(imageselect);
83 Group1->CheckBox1->setText(tr("GEOM_CREATE_COPY"));
85 Layout1->addWidget(Group1, 2, 0);
87 /***************************************************************/
93 //=================================================================================
94 // function : ~TransformationGUI_PositionDlg()
95 // purpose : Destroys the object and frees any allocated resources
96 //=================================================================================
97 TransformationGUI_PositionDlg::~TransformationGUI_PositionDlg()
99 /* no need to delete child widgets, Qt does it all for us */
103 //=================================================================================
106 //=================================================================================
107 void TransformationGUI_PositionDlg::Init()
110 Group1->LineEdit1->setReadOnly(true);
111 Group1->LineEdit2->setReadOnly(true);
112 Group1->LineEdit3->setReadOnly(true);
114 myStartLCS = GEOM::GEOM_Object::_nil();
115 myEndLCS = GEOM::GEOM_Object::_nil();
117 // Activate Create a Copy mode
118 Group1->CheckBox1->setChecked(true);
119 CreateCopyModeChanged(true);
121 /* signals and slots connections */
122 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
123 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
124 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
126 connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
127 connect(Group1->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
128 connect(Group1->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
130 connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
131 connect(Group1->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
132 connect(Group1->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
134 connect(Group1->CheckBox1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
136 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
137 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
139 initName( tr( "GEOM_POSITION" ) );
140 ConstructorsClicked( 0 );
145 //=================================================================================
146 // function : ConstructorsClicked()
147 // purpose : Radio button management
148 //=================================================================================
149 void TransformationGUI_PositionDlg::ConstructorsClicked(int constructorId)
151 disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
154 myEditCurrentArgument = Group1->LineEdit1;
155 Group1->LineEdit2->clear();
156 Group1->LineEdit3->clear();
157 myStartLCS = GEOM::GEOM_Object::_nil();
158 myEndLCS = GEOM::GEOM_Object::_nil();
160 switch (constructorId)
164 Group1->LineEdit2->hide();
165 Group1->TextLabel2->hide();
166 Group1->PushButton2->hide();
171 Group1->LineEdit2->show();
172 Group1->TextLabel2->show();
173 Group1->PushButton2->show();
177 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
178 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
179 SelectionIntoArgument();
184 //=================================================================================
185 // function : ClickOnOk()
187 //=================================================================================
188 void TransformationGUI_PositionDlg::ClickOnOk()
190 if ( ClickOnApply() )
195 //=================================================================================
196 // function : ClickOnApply()
198 //=================================================================================
199 bool TransformationGUI_PositionDlg::ClickOnApply()
201 if ( !onAccept(Group1->CheckBox1->isChecked()) )
205 ConstructorsClicked( getConstructorId() );
210 //=======================================================================
211 // function : ClickOnCancel()
213 //=======================================================================
214 void TransformationGUI_PositionDlg::ClickOnCancel()
216 GEOMBase_Skeleton::ClickOnCancel();
220 //=================================================================================
221 // function : SelectionIntoArgument()
222 // purpose : Called when selection has changed
223 //=================================================================================
224 void TransformationGUI_PositionDlg::SelectionIntoArgument()
226 myEditCurrentArgument->setText("");
229 if(myEditCurrentArgument == Group1->LineEdit1) {
230 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
236 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
237 if (!myObjects.length()) {
242 else if(myEditCurrentArgument == Group1->LineEdit2) {
243 myStartLCS = GEOM::GEOM_Object::_nil();
244 if(IObjectCount() != 1) {
249 Standard_Boolean testResult = Standard_False;
250 myStartLCS = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
251 if(!testResult || CORBA::is_nil( myStartLCS )) {
255 aName = GEOMBase::GetName( myStartLCS );
257 else if(myEditCurrentArgument == Group1->LineEdit3) {
258 myEndLCS = GEOM::GEOM_Object::_nil();
259 if(IObjectCount() != 1) {
264 Standard_Boolean testResult = Standard_False;
265 myEndLCS = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
266 if(!testResult || CORBA::is_nil( myEndLCS )) {
270 aName = GEOMBase::GetName( myEndLCS );
273 myEditCurrentArgument->setText( aName );
278 //=================================================================================
279 // function : LineEditReturnPressed()
281 //=================================================================================
282 void TransformationGUI_PositionDlg::LineEditReturnPressed()
284 QLineEdit* send = (QLineEdit*)sender();
285 if(send == Group1->LineEdit1 || send == Group1->LineEdit2 || send == Group1->LineEdit3) {
286 myEditCurrentArgument = send;
287 GEOMBase_Skeleton::LineEditReturnPressed();
292 //=================================================================================
293 // function : SetEditCurrentArgument()
295 //=================================================================================
296 void TransformationGUI_PositionDlg::SetEditCurrentArgument()
298 QPushButton* send = (QPushButton*)sender();
300 if(send == Group1->PushButton1){
301 myEditCurrentArgument = Group1->LineEdit1;
304 else if(send == Group1->PushButton2) {
305 myEditCurrentArgument = Group1->LineEdit2;
306 TColStd_MapOfInteger aMap;
307 aMap.Add( GEOM_PLANE );
308 aMap.Add( GEOM_MARKER );
309 globalSelection( aMap );
311 else if(send == Group1->PushButton3) {
312 myEditCurrentArgument = Group1->LineEdit3;
313 TColStd_MapOfInteger aMap;
314 aMap.Add( GEOM_PLANE );
315 aMap.Add( GEOM_MARKER );
316 globalSelection( aMap );
319 myEditCurrentArgument->setFocus();
320 SelectionIntoArgument();
324 //=================================================================================
325 // function : ActivateThisDialog()
327 //=================================================================================
328 void TransformationGUI_PositionDlg::ActivateThisDialog()
330 GEOMBase_Skeleton::ActivateThisDialog();
331 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
332 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
333 ConstructorsClicked( getConstructorId() );
337 //=================================================================================
338 // function : DeactivateActiveDialog()
339 // purpose : public slot to deactivate if active
340 //=================================================================================
341 void TransformationGUI_PositionDlg::DeactivateActiveDialog()
343 GEOMBase_Skeleton::DeactivateActiveDialog();
347 //=================================================================================
348 // function : enterEvent()
349 // purpose : when mouse enter onto the QWidget
350 //=================================================================================
351 void TransformationGUI_PositionDlg::enterEvent(QEvent * e)
353 if(!GroupConstructors->isEnabled())
354 ActivateThisDialog();
358 //=================================================================================
359 // function : createOperation
361 //=================================================================================
362 GEOM::GEOM_IOperations_ptr TransformationGUI_PositionDlg::createOperation()
364 return getGeomEngine()->GetITransformOperations( getStudyId() );
368 //=================================================================================
369 // function : isValid
371 //=================================================================================
372 bool TransformationGUI_PositionDlg::isValid( QString& msg )
375 if (getConstructorId() == 0)
376 res = !(myObjects.length() == 0 || myEndLCS->_is_nil());
378 res = !(myObjects.length() == 0 || myStartLCS->_is_nil() || myEndLCS->_is_nil());
384 //=================================================================================
385 // function : execute
387 //=================================================================================
388 bool TransformationGUI_PositionDlg::execute( ObjectList& objects )
391 bool toCreateCopy = IsPreview() || Group1->CheckBox1->isChecked();
392 GEOM::GEOM_Object_var anObj;
394 switch ( getConstructorId() )
398 for (int i = 0; i < myObjects.length(); i++) {
400 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->PositionShapeCopy( myObjects[i], myObjects[i], myEndLCS );
402 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->PositionShape( myObjects[i], myObjects[i], myEndLCS );
404 if ( !anObj->_is_nil() )
405 objects.push_back( anObj._retn() );
412 for (int i = 0; i < myObjects.length(); i++) {
414 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->PositionShapeCopy( myObjects[i], myStartLCS, myEndLCS );
416 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->PositionShape( myObjects[i], myStartLCS, myEndLCS );
417 if ( !anObj->_is_nil() )
418 objects.push_back( anObj._retn() );
428 //=================================================================================
429 // function : closeEvent
431 //=================================================================================
432 void TransformationGUI_PositionDlg::closeEvent( QCloseEvent* e )
434 GEOMBase_Skeleton::closeEvent( e );
438 //=================================================================================
439 // function : CreateCopyModeChanged()
441 //=================================================================================
442 void TransformationGUI_PositionDlg::CreateCopyModeChanged(bool isCreateCopy)
444 this->GroupBoxName->setEnabled(isCreateCopy);