1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : TransformationGUI_PositionDlg.cxx
24 // Author : Damien COQUERET
28 #include "TransformationGUI_PositionDlg.h"
30 #include "SUIT_Desktop.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
36 #include <qcheckbox.h>
38 #include "TColStd_MapOfInteger.hxx"
40 #include "GEOMImpl_Types.hxx"
42 #include "utilities.h"
46 //=================================================================================
47 // class : TransformationGUI_PositionDlg()
48 // purpose : Constructs a TransformationGUI_PositionDlg which is a child of 'parent', with the
49 // name 'name' and widget flags set to 'f'.
50 // The dialog will by default be modeless, unless you set 'modal' to
51 // TRUE to construct a modal dialog.
52 //=================================================================================
53 TransformationGUI_PositionDlg::TransformationGUI_PositionDlg
54 (GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
55 : GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
56 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
58 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
59 QPixmap image0(aResMgr->loadPixmap("GEOM",tr("ICON_DLG_POSITION")));
60 QPixmap image1(aResMgr->loadPixmap("GEOM",tr("ICON_DLG_POSITION2")));
61 QPixmap imageselect(aResMgr->loadPixmap("GEOM",tr("ICON_SELECT")));
63 setCaption(tr("GEOM_POSITION_TITLE"));
65 /***************************************************************/
66 GroupConstructors->setTitle(tr("GEOM_POSITION"));
67 RadioButton1->setPixmap(image0);
68 RadioButton2->setPixmap(image1);
69 RadioButton3->close(TRUE);
71 Group1 = new DlgRef_3Sel3Spin1Check(this, "Group1");
72 Group1->SpinBox1->hide();
73 Group1->SpinBox2->hide();
74 Group1->SpinBox3->hide();
75 Group1->TextLabel4->hide();
76 Group1->TextLabel5->hide();
77 Group1->TextLabel6->hide();
78 Group1->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
79 Group1->TextLabel1->setText(tr("GEOM_OBJECTS"));
80 Group1->TextLabel2->setText(tr("GEOM_START_LCS"));
81 Group1->TextLabel3->setText(tr("GEOM_END_LCS"));
82 Group1->PushButton1->setPixmap(imageselect);
83 Group1->PushButton2->setPixmap(imageselect);
84 Group1->PushButton3->setPixmap(imageselect);
85 Group1->CheckBox1->setText(tr("GEOM_CREATE_COPY"));
87 Layout1->addWidget(Group1, 2, 0);
89 /***************************************************************/
91 setHelpFileName("modify_location_operation_page.html");
97 //=================================================================================
98 // function : ~TransformationGUI_PositionDlg()
99 // purpose : Destroys the object and frees any allocated resources
100 //=================================================================================
101 TransformationGUI_PositionDlg::~TransformationGUI_PositionDlg()
103 /* no need to delete child widgets, Qt does it all for us */
107 //=================================================================================
110 //=================================================================================
111 void TransformationGUI_PositionDlg::Init()
114 Group1->LineEdit1->setReadOnly(true);
115 Group1->LineEdit2->setReadOnly(true);
116 Group1->LineEdit3->setReadOnly(true);
118 myStartLCS = GEOM::GEOM_Object::_nil();
119 myEndLCS = GEOM::GEOM_Object::_nil();
121 // Activate Create a Copy mode
122 Group1->CheckBox1->setChecked(true);
123 CreateCopyModeChanged(true);
125 GroupBoxPublish->show();
127 /* signals and slots connections */
128 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
129 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
130 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
132 connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 connect(Group1->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
134 connect(Group1->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
136 connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
137 connect(Group1->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
138 connect(Group1->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
140 connect(Group1->CheckBox1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
142 connect(myGeomGUI->getApp()->selectionMgr(),
143 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
145 initName( tr( "GEOM_POSITION" ) );
146 ConstructorsClicked( 0 );
151 //=================================================================================
152 // function : ConstructorsClicked()
153 // purpose : Radio button management
154 //=================================================================================
155 void TransformationGUI_PositionDlg::ConstructorsClicked(int constructorId)
157 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
160 myEditCurrentArgument = Group1->LineEdit1;
161 Group1->LineEdit2->clear();
162 Group1->LineEdit3->clear();
163 myStartLCS = GEOM::GEOM_Object::_nil();
164 myEndLCS = GEOM::GEOM_Object::_nil();
166 switch (constructorId)
170 Group1->LineEdit2->hide();
171 Group1->TextLabel2->hide();
172 Group1->PushButton2->hide();
177 Group1->LineEdit2->show();
178 Group1->TextLabel2->show();
179 Group1->PushButton2->show();
183 connect(myGeomGUI->getApp()->selectionMgr(),
184 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
185 SelectionIntoArgument();
189 //=================================================================================
190 // function : ClickOnOk()
192 //=================================================================================
193 void TransformationGUI_PositionDlg::ClickOnOk()
195 if ( ClickOnApply() )
200 //=================================================================================
201 // function : ClickOnApply()
203 //=================================================================================
204 bool TransformationGUI_PositionDlg::ClickOnApply()
206 if ( !onAccept(Group1->CheckBox1->isChecked()) )
210 ConstructorsClicked( getConstructorId() );
215 //=================================================================================
216 // function : SelectionIntoArgument()
217 // purpose : Called when selection has changed
218 //=================================================================================
219 void TransformationGUI_PositionDlg::SelectionIntoArgument()
221 myEditCurrentArgument->setText("");
224 if(myEditCurrentArgument == Group1->LineEdit1) {
225 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
231 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
232 if (!myObjects.length()) {
237 else if(myEditCurrentArgument == Group1->LineEdit2) {
238 myStartLCS = GEOM::GEOM_Object::_nil();
239 if(IObjectCount() != 1) {
244 Standard_Boolean testResult = Standard_False;
245 myStartLCS = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
246 if(!testResult || CORBA::is_nil( myStartLCS )) {
250 aName = GEOMBase::GetName( myStartLCS );
252 else if(myEditCurrentArgument == Group1->LineEdit3) {
253 myEndLCS = GEOM::GEOM_Object::_nil();
254 if(IObjectCount() != 1) {
259 Standard_Boolean testResult = Standard_False;
260 myEndLCS = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
261 if(!testResult || CORBA::is_nil( myEndLCS )) {
265 aName = GEOMBase::GetName( myEndLCS );
268 myEditCurrentArgument->setText( aName );
273 //=================================================================================
274 // function : LineEditReturnPressed()
276 //=================================================================================
277 void TransformationGUI_PositionDlg::LineEditReturnPressed()
279 QLineEdit* send = (QLineEdit*)sender();
280 if(send == Group1->LineEdit1 || send == Group1->LineEdit2 || send == Group1->LineEdit3) {
281 myEditCurrentArgument = send;
282 GEOMBase_Skeleton::LineEditReturnPressed();
287 //=================================================================================
288 // function : SetEditCurrentArgument()
290 //=================================================================================
291 void TransformationGUI_PositionDlg::SetEditCurrentArgument()
293 QPushButton* send = (QPushButton*)sender();
295 if(send == Group1->PushButton1){
296 myEditCurrentArgument = Group1->LineEdit1;
299 else if(send == Group1->PushButton2) {
300 myEditCurrentArgument = Group1->LineEdit2;
301 TColStd_MapOfInteger aMap;
302 aMap.Add( GEOM_PLANE );
303 aMap.Add( GEOM_MARKER );
304 globalSelection( aMap );
306 else if(send == Group1->PushButton3) {
307 myEditCurrentArgument = Group1->LineEdit3;
308 TColStd_MapOfInteger aMap;
309 aMap.Add( GEOM_PLANE );
310 aMap.Add( GEOM_MARKER );
311 globalSelection( aMap );
314 myEditCurrentArgument->setFocus();
315 SelectionIntoArgument();
319 //=================================================================================
320 // function : ActivateThisDialog()
322 //=================================================================================
323 void TransformationGUI_PositionDlg::ActivateThisDialog()
325 GEOMBase_Skeleton::ActivateThisDialog();
326 connect(myGeomGUI->getApp()->selectionMgr(),
327 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
328 ConstructorsClicked( getConstructorId() );
332 //=================================================================================
333 // function : enterEvent()
334 // purpose : when mouse enter onto the QWidget
335 //=================================================================================
336 void TransformationGUI_PositionDlg::enterEvent(QEvent * e)
338 if(!GroupConstructors->isEnabled())
339 ActivateThisDialog();
343 //=================================================================================
344 // function : createOperation
346 //=================================================================================
347 GEOM::GEOM_IOperations_ptr TransformationGUI_PositionDlg::createOperation()
349 return getGeomEngine()->GetITransformOperations( getStudyId() );
353 //=================================================================================
354 // function : isValid
356 //=================================================================================
357 bool TransformationGUI_PositionDlg::isValid( QString& msg )
360 if (getConstructorId() == 0)
361 res = !(myObjects.length() == 0 || myEndLCS->_is_nil());
363 res = !(myObjects.length() == 0 || myStartLCS->_is_nil() || myEndLCS->_is_nil());
369 //=================================================================================
370 // function : execute
372 //=================================================================================
373 bool TransformationGUI_PositionDlg::execute( ObjectList& objects )
376 bool toCreateCopy = IsPreview() || Group1->CheckBox1->isChecked();
377 GEOM::GEOM_Object_var anObj;
379 switch ( getConstructorId() )
383 for (int i = 0; i < myObjects.length(); i++) {
385 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
386 PositionShapeCopy( myObjects[i], myObjects[i], myEndLCS );
388 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
389 PositionShape( myObjects[i], myObjects[i], myEndLCS );
391 if ( !anObj->_is_nil() )
392 objects.push_back( anObj._retn() );
399 for (int i = 0; i < myObjects.length(); i++) {
401 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
402 PositionShapeCopy( myObjects[i], myStartLCS, myEndLCS );
404 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
405 PositionShape( myObjects[i], myStartLCS, myEndLCS );
406 if ( !anObj->_is_nil() )
407 objects.push_back( anObj._retn() );
417 //=================================================================================
418 // function : restoreSubShapes
420 //=================================================================================
421 void TransformationGUI_PositionDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
422 SALOMEDS::SObject_ptr theSObject)
424 if (CheckBoxRestoreSS->isChecked()) {
425 // empty list of arguments means that all arguments should be restored
426 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
427 /*theFindMethod=*/GEOM::FSM_Transformed,
428 /*theInheritFirstArg=*/true);
432 //=================================================================================
433 // function : CreateCopyModeChanged()
435 //=================================================================================
436 void TransformationGUI_PositionDlg::CreateCopyModeChanged(bool isCreateCopy)
438 this->GroupBoxName->setEnabled(isCreateCopy);