Salome HOME
rnc: I made a mistake. It should be OK now
[modules/geom.git] / src / TransformationGUI / TransformationGUI_ProjectionDlg.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File   : TransformationGUI_ProjectionDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
25
26 #include "TransformationGUI.h"
27 #include "TransformationGUI_ProjectionDlg.h"
28
29 #include <DlgRef.h>
30 #include <GeometryGUI.h>
31 #include <GEOMBase.h>
32
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
37
38 //=================================================================================
39 // class    : TransformationGUI_ProjectionDlg()
40 // purpose  : Constructs a TransformationGUI_ProjectionDlg which is a child of 'parent', with the
41 //            name 'name' and widget flags set to 'f'.
42 //            The dialog will by default be modeless, unless you set 'modal' to
43 //            TRUE to construct a modal dialog.
44 //=================================================================================
45 TransformationGUI_ProjectionDlg::TransformationGUI_ProjectionDlg (GeometryGUI* theGeometryGUI,
46                                       QWidget* parent, bool modal, Qt::WindowFlags fl)
47   : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl)
48 {
49   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PROJECTION")));
50   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
51
52   setWindowTitle(tr("GEOM_PROJECTION_TITLE"));
53
54   mainFrame()->GroupConstructors->setTitle(tr("GEOM_PROJECTION"));
55   mainFrame()->RadioButton1->setIcon(image0);
56   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
57   mainFrame()->RadioButton2->close();
58   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
59   mainFrame()->RadioButton3->close();
60
61   myGroup = new DlgRef_2Sel (centralWidget());
62
63   myGroup->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
64   myGroup->TextLabel1->setText(tr("GEOM_SOURCE_OBJECT"));
65   myGroup->TextLabel2->setText(tr("GEOM_TARGET_OBJECT"));
66   myGroup->PushButton1->setIcon(image1);
67   myGroup->PushButton2->setIcon(image1);
68   myGroup->LineEdit1->setReadOnly(true);
69   myGroup->LineEdit2->setReadOnly(true);
70
71   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
72   layout->setMargin(0); layout->setSpacing(6);
73   layout->addWidget(myGroup);
74
75   setHelpFileName("projection_operation_page.html");
76
77   // Initialisation
78   Init();
79 }
80
81 //=================================================================================
82 // function : ~TransformationGUI_ProjectionDlg()
83 // purpose  : Destroys the object and frees any allocated resources
84 //=================================================================================
85 TransformationGUI_ProjectionDlg::~TransformationGUI_ProjectionDlg()
86 {
87 }
88
89 //=================================================================================
90 // function : Init()
91 // purpose  :
92 //=================================================================================
93 void TransformationGUI_ProjectionDlg::Init()
94 {
95   mainFrame()->GroupBoxPublish->show();
96
97   // init variables
98   myEditCurrentArgument = myGroup->LineEdit1;
99
100   myGroup->LineEdit1->setText("");
101   myGroup->LineEdit2->setText("");
102   myObject1.nullify();
103   myObject2.nullify();
104
105   showOnlyPreviewControl();
106  
107   // signals and slots connections
108   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
109   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
110
111   connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
112   connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
113
114   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
115            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
116
117   initName(mainFrame()->GroupConstructors->title());
118
119   setTabOrder(mainFrame()->GroupConstructors, mainFrame()->GroupBoxName);
120   setTabOrder(mainFrame()->GroupBoxName, mainFrame()->GroupMedium);
121   setTabOrder(mainFrame()->GroupMedium, mainFrame()->GroupButtons);
122
123   mainFrame()->RadioButton1->setFocus();
124
125   globalSelection(GEOM_ALLSHAPES);
126
127   myGroup->PushButton1->click();
128   SelectionIntoArgument();
129   resize(100,100);
130 }
131
132 //=================================================================================
133 // function : ClickOnOk()
134 // purpose  :
135 //=================================================================================
136 void TransformationGUI_ProjectionDlg::ClickOnOk()
137 {
138   setIsApplyAndClose(true);
139   if (ClickOnApply())
140     ClickOnCancel();
141 }
142
143 //=================================================================================
144 // function : ClickOnApply()
145 // purpose  :
146 //=================================================================================
147 bool TransformationGUI_ProjectionDlg::ClickOnApply()
148 {
149   if (!onAccept())
150     return false;
151
152   initName();
153   // activate selection and connect selection manager
154   myGroup->PushButton1->click();
155   return true;
156 }
157
158 //=================================================================================
159 // function : SelectionIntoArgument()
160 // purpose  : Called when selection is changed or on dialog initialization or activation
161 //=================================================================================
162 void TransformationGUI_ProjectionDlg::SelectionIntoArgument()
163 {
164   myEditCurrentArgument->setText("");
165
166   GEOM::GeomObjPtr aSelectedObject = getSelected(TopAbs_SHAPE);
167   TopoDS_Shape aShape;
168   if (aSelectedObject && GEOMBase::GetShape(aSelectedObject.get(), aShape) && !aShape.IsNull()) {
169     QString aName = GEOMBase::GetName(aSelectedObject.get());
170     myEditCurrentArgument->setText(aName);
171
172     // clear selection
173     disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
174     myGeomGUI->getApp()->selectionMgr()->clearSelected();
175     connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
176             this, SLOT(SelectionIntoArgument()));
177
178     if (myEditCurrentArgument == myGroup->LineEdit1) {
179       myObject1 = aSelectedObject;
180       if (!myObject2)
181         myGroup->PushButton2->click();
182     }
183     else if (myEditCurrentArgument == myGroup->LineEdit2) {
184       myObject2 = aSelectedObject;
185       if (!myObject1)
186         myGroup->PushButton1->click();
187     }
188   }
189   else {
190     if      (myEditCurrentArgument == myGroup->LineEdit1) myObject1.nullify();
191     else if (myEditCurrentArgument == myGroup->LineEdit2) myObject2.nullify();
192   }
193 }
194
195 //=================================================================================
196 // function : SetEditCurrentArgument()
197 // purpose  :
198 //=================================================================================
199 void TransformationGUI_ProjectionDlg::SetEditCurrentArgument()
200 {
201   QPushButton* send = (QPushButton*)sender();
202
203   if (send == myGroup->PushButton1) {
204     myEditCurrentArgument = myGroup->LineEdit1;
205
206     myGroup->PushButton2->setDown(false);
207     myGroup->LineEdit2->setEnabled(false);
208   }
209   else if (send == myGroup->PushButton2) {
210     myEditCurrentArgument = myGroup->LineEdit2;
211
212     myGroup->PushButton1->setDown(false);
213     myGroup->LineEdit1->setEnabled(false);
214   }
215
216   // enable line edit
217   myEditCurrentArgument->setEnabled(true);
218   myEditCurrentArgument->setFocus();
219   // after setFocus(), because it will be setDown(false) when loses focus
220   send->setDown(true);
221 }
222
223 //=================================================================================
224 // function : ActivateThisDialog()
225 // purpose  :
226 //=================================================================================
227 void TransformationGUI_ProjectionDlg::ActivateThisDialog()
228 {
229   GEOMBase_Skeleton::ActivateThisDialog();
230
231   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
232           this, SLOT(SelectionIntoArgument()));
233   processPreview();
234 }
235
236 //=================================================================================
237 // function : enterEvent()
238 // purpose  : when mouse enter onto the QWidget
239 //=================================================================================
240 void TransformationGUI_ProjectionDlg::enterEvent (QEvent*)
241 {
242   if (!mainFrame()->GroupConstructors->isEnabled())
243     ActivateThisDialog();
244 }
245
246 //=================================================================================
247 // function : createOperation
248 // purpose  :
249 //=================================================================================
250 GEOM::GEOM_IOperations_ptr TransformationGUI_ProjectionDlg::createOperation()
251 {
252   return getGeomEngine()->GetITransformOperations(getStudyId());
253 }
254
255 //=================================================================================
256 // function : isValid
257 // purpose  :
258 //=================================================================================
259 bool TransformationGUI_ProjectionDlg::isValid (QString&)
260 {
261   return myObject1 && myObject2;
262 }
263
264 //=================================================================================
265 // function : execute
266 // purpose  :
267 //=================================================================================
268 bool TransformationGUI_ProjectionDlg::execute (ObjectList& objects)
269 {
270   GEOM::GEOM_Object_var anObj;
271
272   GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
273   anObj = anOper->ProjectShapeCopy(myObject1.get(), myObject2.get());
274   if (!anObj->_is_nil())
275     objects.push_back(anObj._retn());
276
277   return true;
278 }