1 // Copyright (C) 2007-2011 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
23 // File : TransformationGUI_ProjectionDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "TransformationGUI.h"
27 #include "TransformationGUI_ProjectionDlg.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
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)
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")));
52 setWindowTitle(tr("GEOM_PROJECTION_TITLE"));
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();
61 myGroup = new DlgRef_2Sel (centralWidget());
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);
71 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
72 layout->setMargin(0); layout->setSpacing(6);
73 layout->addWidget(myGroup);
75 setHelpFileName("projection_operation_page.html");
81 //=================================================================================
82 // function : ~TransformationGUI_ProjectionDlg()
83 // purpose : Destroys the object and frees any allocated resources
84 //=================================================================================
85 TransformationGUI_ProjectionDlg::~TransformationGUI_ProjectionDlg()
89 //=================================================================================
92 //=================================================================================
93 void TransformationGUI_ProjectionDlg::Init()
95 mainFrame()->GroupBoxPublish->show();
98 myEditCurrentArgument = myGroup->LineEdit1;
100 myGroup->LineEdit1->setText("");
101 myGroup->LineEdit2->setText("");
105 showOnlyPreviewControl();
107 // signals and slots connections
108 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
109 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
111 connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
112 connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
114 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
115 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
117 initName(mainFrame()->GroupConstructors->title());
119 setTabOrder(mainFrame()->GroupConstructors, mainFrame()->GroupBoxName);
120 setTabOrder(mainFrame()->GroupBoxName, mainFrame()->GroupMedium);
121 setTabOrder(mainFrame()->GroupMedium, mainFrame()->GroupButtons);
123 mainFrame()->RadioButton1->setFocus();
125 globalSelection(GEOM_ALLSHAPES);
127 myGroup->PushButton1->click();
128 SelectionIntoArgument();
132 //=================================================================================
133 // function : ClickOnOk()
135 //=================================================================================
136 void TransformationGUI_ProjectionDlg::ClickOnOk()
138 setIsApplyAndClose(true);
143 //=================================================================================
144 // function : ClickOnApply()
146 //=================================================================================
147 bool TransformationGUI_ProjectionDlg::ClickOnApply()
153 // activate selection and connect selection manager
154 myGroup->PushButton1->click();
158 //=================================================================================
159 // function : SelectionIntoArgument()
160 // purpose : Called when selection is changed or on dialog initialization or activation
161 //=================================================================================
162 void TransformationGUI_ProjectionDlg::SelectionIntoArgument()
164 myEditCurrentArgument->setText("");
166 GEOM::GeomObjPtr aSelectedObject = getSelected(TopAbs_SHAPE);
168 if (aSelectedObject && GEOMBase::GetShape(aSelectedObject.get(), aShape) && !aShape.IsNull()) {
169 QString aName = GEOMBase::GetName(aSelectedObject.get());
170 myEditCurrentArgument->setText(aName);
173 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
174 myGeomGUI->getApp()->selectionMgr()->clearSelected();
175 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
176 this, SLOT(SelectionIntoArgument()));
178 if (myEditCurrentArgument == myGroup->LineEdit1) {
179 myObject1 = aSelectedObject;
181 myGroup->PushButton2->click();
183 else if (myEditCurrentArgument == myGroup->LineEdit2) {
184 myObject2 = aSelectedObject;
186 myGroup->PushButton1->click();
190 if (myEditCurrentArgument == myGroup->LineEdit1) myObject1.nullify();
191 else if (myEditCurrentArgument == myGroup->LineEdit2) myObject2.nullify();
195 //=================================================================================
196 // function : SetEditCurrentArgument()
198 //=================================================================================
199 void TransformationGUI_ProjectionDlg::SetEditCurrentArgument()
201 QPushButton* send = (QPushButton*)sender();
203 if (send == myGroup->PushButton1) {
204 myEditCurrentArgument = myGroup->LineEdit1;
206 myGroup->PushButton2->setDown(false);
207 myGroup->LineEdit2->setEnabled(false);
209 else if (send == myGroup->PushButton2) {
210 myEditCurrentArgument = myGroup->LineEdit2;
212 myGroup->PushButton1->setDown(false);
213 myGroup->LineEdit1->setEnabled(false);
217 myEditCurrentArgument->setEnabled(true);
218 myEditCurrentArgument->setFocus();
219 // after setFocus(), because it will be setDown(false) when loses focus
223 //=================================================================================
224 // function : ActivateThisDialog()
226 //=================================================================================
227 void TransformationGUI_ProjectionDlg::ActivateThisDialog()
229 GEOMBase_Skeleton::ActivateThisDialog();
231 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
232 this, SLOT(SelectionIntoArgument()));
236 //=================================================================================
237 // function : enterEvent()
238 // purpose : when mouse enter onto the QWidget
239 //=================================================================================
240 void TransformationGUI_ProjectionDlg::enterEvent (QEvent*)
242 if (!mainFrame()->GroupConstructors->isEnabled())
243 ActivateThisDialog();
246 //=================================================================================
247 // function : createOperation
249 //=================================================================================
250 GEOM::GEOM_IOperations_ptr TransformationGUI_ProjectionDlg::createOperation()
252 return getGeomEngine()->GetITransformOperations(getStudyId());
255 //=================================================================================
256 // function : isValid
258 //=================================================================================
259 bool TransformationGUI_ProjectionDlg::isValid (QString&)
261 return myObject1 && myObject2;
264 //=================================================================================
265 // function : execute
267 //=================================================================================
268 bool TransformationGUI_ProjectionDlg::execute (ObjectList& objects)
270 GEOM::GEOM_Object_var anObj;
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());