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