1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "OperationGUI_TransferDataDlg.h"
23 #include <GeometryGUI.h>
26 #include <SUIT_Desktop.h>
27 #include <SUIT_MessageBox.h>
28 #include <SUIT_Session.h>
29 #include <SUIT_ResourceMgr.h>
30 #include <SalomeApp_Application.h>
31 #include <LightApp_SelectionMgr.h>
33 //==============================================================================
34 // class : OperationGUI_TransferDataDlg()
35 // purpose : Constructs a OperationGUI_TransferDataDlg which is a child of
37 //=================================================================================
38 OperationGUI_TransferDataDlg::OperationGUI_TransferDataDlg (GeometryGUI* theGeometryGUI,
40 : GEOMBase_Skeleton(theGeometryGUI, parent, false),
43 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
44 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TRANSFER_DATA")));
45 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
47 setWindowTitle(tr("GEOM_TRANSFER_DATA_TITLE"));
49 /***************************************************************/
50 mainFrame()->GroupConstructors->setTitle(tr("GEOM_TRANSFER_DATA"));
51 mainFrame()->RadioButton1->setIcon(image0);
52 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
53 mainFrame()->RadioButton2->close();
54 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
55 mainFrame()->RadioButton3->close();
57 mainFrame()->GroupBoxName->hide();
59 myGroup = new DlgRef_2Sel1List(centralWidget());
60 myGroup->GroupBox1->setTitle(tr("GEOM_PARAMETERS"));
61 myGroup->TextLabel1->setText(tr("GEOM_TRANSFER_DATA_FROM"));
62 myGroup->TextLabel2->setText(tr("GEOM_TRANSFER_DATA_TO"));
63 myGroup->TextLabel3->setText(tr("GEOM_TRANSFER_DATA_METHOD"));
64 myGroup->PushButton1->setIcon(image1);
65 myGroup->PushButton2->setIcon(image1);
66 myGroup->LineEdit1->setReadOnly(true);
67 myGroup->LineEdit2->setReadOnly(true);
69 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
70 layout->setMargin(0); layout->setSpacing(6);
71 layout->addWidget(myGroup);
72 /***************************************************************/
74 setHelpFileName("transfer_data_page.html");
79 //=================================================================================
80 // function : ~OperationGUI_TransferDataDlg
81 // purpose : Destroys the object and frees any allocated resources
82 //=================================================================================
83 OperationGUI_TransferDataDlg::~OperationGUI_TransferDataDlg()
87 //=================================================================================
90 //=================================================================================
91 void OperationGUI_TransferDataDlg::Init()
94 myGroup->ComboBox1->addItem(tr("GEOM_TD_METHOD_GETINPLACE"));
95 myGroup->ComboBox1->addItem(tr("GEOM_TD_METHOD_GETINPLACE_OLD"));
96 myGroup->ComboBox1->addItem(tr("GEOM_TD_METHOD_GETINPLACE_HISTORY"));
98 myGroup->LineEdit1->clear();
99 myGroup->LineEdit2->clear();
103 // signals and slots connections
104 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
105 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
107 connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
108 connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
110 connect(myGroup->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
111 connect(myGroup->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
113 connect(myGroup->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
115 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
116 this, SLOT(SelectionIntoArgument()));
118 myGroup->TextLabel3->show();
119 myGroup->ComboBox1->show();
120 myGroup->ComboBox1->setCurrentIndex(0);
122 globalSelection(GEOM_ALLSHAPES);
124 myGroup->PushButton1->click();
125 SelectionIntoArgument();
129 //=================================================================================
130 // function : ClickOnOk()
132 //=================================================================================
133 void OperationGUI_TransferDataDlg::ClickOnOk()
135 setIsApplyAndClose( true );
140 //=================================================================================
141 // function : ClickOnApply()
143 //=================================================================================
144 bool OperationGUI_TransferDataDlg::ClickOnApply()
146 if (!onAccept(false))
148 // activate first line edit
149 myGroup->PushButton1->click();
153 //=================================================================================
154 // function : SelectionIntoArgument()
155 // purpose : Called when selection is changed or on dialog initialization or activation
156 //=================================================================================
157 void OperationGUI_TransferDataDlg::SelectionIntoArgument()
159 GEOM::GeomObjPtr aSelectedObject = getSelected(TopAbs_SHAPE);
161 if (aSelectedObject) {
162 myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject.get()));
164 if (myEditCurrentArgument == myGroup->LineEdit1) {
165 myObject1 = aSelectedObject;
168 myGroup->PushButton2->click();
170 } else if (myEditCurrentArgument == myGroup->LineEdit2) {
171 myObject2 = aSelectedObject;
174 myGroup->PushButton1->click();
178 myEditCurrentArgument->setText("");
180 if (myEditCurrentArgument == myGroup->LineEdit1) {
182 } else if (myEditCurrentArgument == myGroup->LineEdit2) {
188 //=================================================================================
189 // function : SetEditCurrentArgument()
191 //=================================================================================
192 void OperationGUI_TransferDataDlg::SetEditCurrentArgument()
194 QPushButton* send = (QPushButton*)sender();
196 if (send == myGroup->PushButton1) {
197 myEditCurrentArgument = myGroup->LineEdit1;
199 myGroup->PushButton2->setDown(false);
200 myGroup->LineEdit2->setEnabled(false);
202 else if (send == myGroup->PushButton2) {
203 myEditCurrentArgument = myGroup->LineEdit2;
205 myGroup->PushButton1->setDown(false);
206 myGroup->LineEdit1->setEnabled(false);
210 myEditCurrentArgument->setEnabled(true);
211 myEditCurrentArgument->setFocus();
212 // after setFocus(), because it will be setDown(false) when loses focus
216 //=================================================================================
217 // function : LineEditReturnPressed()
219 //=================================================================================
220 void OperationGUI_TransferDataDlg::LineEditReturnPressed()
222 QLineEdit* send = (QLineEdit*)sender();
223 if (send == myGroup->LineEdit1 || send == myGroup->LineEdit2)
225 myEditCurrentArgument = send;
226 GEOMBase_Skeleton::LineEditReturnPressed();
230 //=================================================================================
231 // function : ActivateThisDialog()
233 //=================================================================================
234 void OperationGUI_TransferDataDlg::ActivateThisDialog()
236 GEOMBase_Skeleton::ActivateThisDialog();
237 globalSelection(GEOM_ALLSHAPES);
238 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
239 this, SLOT( SelectionIntoArgument() ) );
242 //=================================================================================
243 // function : enterEvent()
244 // purpose : when mouse enter onto the QWidget
245 //=================================================================================
246 void OperationGUI_TransferDataDlg::enterEvent (QEvent*)
248 if (!mainFrame()->GroupConstructors->isEnabled())
249 ActivateThisDialog();
252 //=================================================================================
253 // function : createOperation
255 //=================================================================================
256 GEOM::GEOM_IOperations_ptr OperationGUI_TransferDataDlg::createOperation()
258 return getGeomEngine()->GetIInsertOperations(getStudyId());
261 //=================================================================================
262 // function : isValid
264 //=================================================================================
265 bool OperationGUI_TransferDataDlg::isValid(QString&)
267 return myObject1 && myObject2;
270 //=================================================================================
271 // function : execute
273 //=================================================================================
274 bool OperationGUI_TransferDataDlg::execute (ObjectList& objects)
276 const int aLimit = myGroup->ComboBox1->currentIndex();
277 GEOM::find_shape_method aMethod;
282 aMethod = GEOM::FSM_GetInPlace;
285 aMethod = GEOM::FSM_GetInPlace_Old;
289 aMethod = GEOM::FSM_GetInPlaceByHistory;
293 GEOM::GEOM_IInsertOperations_var anOper =
294 GEOM::GEOM_IInsertOperations::_narrow(getOperation());
295 GEOM::GEOM_IInsertOperations::ListOfTransferDatum_var aResult;
297 bool isOK = anOper->TransferData
298 (myObject1.get(), myObject2.get(), aMethod, aResult);
301 // Construct info message.
303 int aNbTypes = aResult->length();
306 aMsg = tr("GEOM_TRANSFER_DATA_NOT_COPIED");
308 aMsg = tr("GEOM_TRANSFER_DATA_COPIED");
312 for (i = 0; i < aNbTypes; i++ ) {
317 aMsg += tr(aResult[i].myName).
318 arg(aResult[i].myNumber).arg(aResult[i].myMaxNumber);
322 // Show info message.
323 SUIT_MessageBox::information
324 (SUIT_Session::session()->activeApplication()->desktop(),
325 tr("GEOM_TRANSFER_DATA_INFO"), aMsg, tr("BUT_OK"));
327 objects.push_back(myObject2.copy());
333 //=================================================================================
334 // function : getSourceObjects
335 // purpose : virtual method to get source objects
336 //=================================================================================
337 QList<GEOM::GeomObjPtr> OperationGUI_TransferDataDlg::getSourceObjects()
339 QList<GEOM::GeomObjPtr> res;