1 // Copyright (C) 2007-2013 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>
32 #include <GEOMImpl_Types.hxx>
34 #include <SUIT_Session.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SalomeApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
39 #include <TColStd_MapOfInteger.hxx>
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)
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")));
55 setWindowTitle(tr("GEOM_PROJECTION_TITLE"));
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();
64 myGroup = new DlgRef_2Sel (centralWidget());
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);
74 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
75 layout->setMargin(0); layout->setSpacing(6);
76 layout->addWidget(myGroup);
78 setHelpFileName("projection_operation_page.html");
84 //=================================================================================
85 // function : ~TransformationGUI_ProjectionDlg()
86 // purpose : Destroys the object and frees any allocated resources
87 //=================================================================================
88 TransformationGUI_ProjectionDlg::~TransformationGUI_ProjectionDlg()
92 //=================================================================================
95 //=================================================================================
96 void TransformationGUI_ProjectionDlg::Init()
98 mainFrame()->GroupBoxPublish->show();
101 myEditCurrentArgument = myGroup->LineEdit1;
103 myGroup->LineEdit1->setText("");
104 myGroup->LineEdit2->setText("");
108 showOnlyPreviewControl();
110 // signals and slots connections
111 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
112 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
114 connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
115 connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
117 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
118 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
120 initName(mainFrame()->GroupConstructors->title());
122 setTabOrder(mainFrame()->GroupConstructors, mainFrame()->GroupBoxName);
123 setTabOrder(mainFrame()->GroupBoxName, mainFrame()->GroupMedium);
124 setTabOrder(mainFrame()->GroupMedium, mainFrame()->GroupButtons);
126 mainFrame()->RadioButton1->setFocus();
128 globalSelection(GEOM_ALLSHAPES);
130 myGroup->PushButton1->click();
131 SelectionIntoArgument();
135 //=================================================================================
136 // function : ClickOnOk()
138 //=================================================================================
139 void TransformationGUI_ProjectionDlg::ClickOnOk()
141 setIsApplyAndClose(true);
146 //=================================================================================
147 // function : ClickOnApply()
149 //=================================================================================
150 bool TransformationGUI_ProjectionDlg::ClickOnApply()
156 // activate selection and connect selection manager
157 myGroup->PushButton1->click();
161 //=================================================================================
162 // function : SelectionIntoArgument()
163 // purpose : Called when selection is changed or on dialog initialization or activation
164 //=================================================================================
165 void TransformationGUI_ProjectionDlg::SelectionIntoArgument()
167 myEditCurrentArgument->setText("");
169 GEOM::GeomObjPtr aSelectedObject = getSelected(TopAbs_SHAPE);
171 if (aSelectedObject && GEOMBase::GetShape(aSelectedObject.get(), aShape) && !aShape.IsNull()) {
172 QString aName = GEOMBase::GetName(aSelectedObject.get());
173 myEditCurrentArgument->setText(aName);
176 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
177 myGeomGUI->getApp()->selectionMgr()->clearSelected();
178 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
179 this, SLOT(SelectionIntoArgument()));
181 if (myEditCurrentArgument == myGroup->LineEdit1) {
182 myObject1 = aSelectedObject;
184 myGroup->PushButton2->click();
186 else if (myEditCurrentArgument == myGroup->LineEdit2) {
187 myObject2 = aSelectedObject;
189 myGroup->PushButton1->click();
193 if (myEditCurrentArgument == myGroup->LineEdit1) myObject1.nullify();
194 else if (myEditCurrentArgument == myGroup->LineEdit2) myObject2.nullify();
198 //=================================================================================
199 // function : SetEditCurrentArgument()
201 //=================================================================================
202 void TransformationGUI_ProjectionDlg::SetEditCurrentArgument()
204 QPushButton* send = (QPushButton*)sender();
206 if (send == myGroup->PushButton1) {
207 myEditCurrentArgument = myGroup->LineEdit1;
209 myGroup->PushButton2->setDown(false);
210 myGroup->LineEdit2->setEnabled(false);
212 TColStd_MapOfInteger aMap;
213 aMap.Add( GEOM_POINT );
214 aMap.Add( GEOM_EDGE );
215 aMap.Add( GEOM_WIRE );
216 globalSelection( aMap );
218 else if (send == myGroup->PushButton2) {
219 myEditCurrentArgument = myGroup->LineEdit2;
221 myGroup->PushButton1->setDown(false);
222 myGroup->LineEdit1->setEnabled(false);
224 globalSelection( GEOM_FACE );
228 myEditCurrentArgument->setEnabled(true);
229 myEditCurrentArgument->setFocus();
230 // after setFocus(), because it will be setDown(false) when loses focus
234 //=================================================================================
235 // function : ActivateThisDialog()
237 //=================================================================================
238 void TransformationGUI_ProjectionDlg::ActivateThisDialog()
240 GEOMBase_Skeleton::ActivateThisDialog();
242 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
243 this, SLOT(SelectionIntoArgument()));
247 //=================================================================================
248 // function : enterEvent()
249 // purpose : when mouse enter onto the QWidget
250 //=================================================================================
251 void TransformationGUI_ProjectionDlg::enterEvent (QEvent*)
253 if (!mainFrame()->GroupConstructors->isEnabled())
254 ActivateThisDialog();
257 //=================================================================================
258 // function : createOperation
260 //=================================================================================
261 GEOM::GEOM_IOperations_ptr TransformationGUI_ProjectionDlg::createOperation()
263 return getGeomEngine()->GetITransformOperations(getStudyId());
266 //=================================================================================
267 // function : isValid
269 //=================================================================================
270 bool TransformationGUI_ProjectionDlg::isValid (QString&)
272 return myObject1 && myObject2;
275 //=================================================================================
276 // function : execute
278 //=================================================================================
279 bool TransformationGUI_ProjectionDlg::execute (ObjectList& objects)
281 GEOM::GEOM_Object_var anObj;
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());