1 // Copyright (C) 2007-2012 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : GenerationGUI_PipePathDlg.cxx
25 #include "GenerationGUI_PipePathDlg.h"
28 #include <GeometryGUI.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SalomeApp_Application.h>
34 #include <LightApp_SelectionMgr.h>
36 #include <TopoDS_Shape.hxx>
39 #include <TColStd_IndexedMapOfInteger.hxx>
40 #include <TopTools_IndexedMapOfShape.hxx>
41 #include <TColStd_IndexedMapOfInteger.hxx>
42 #include <TColStd_MapOfInteger.hxx>
44 #include <GEOMImpl_Types.hxx>
46 //=================================================================================
47 // class : GenerationGUI_PipePathDlg()
48 // purpose : Constructs a GenerationGUI_PipePathDlg which is a child of 'parent', with the
49 // name 'name' and widget flags set to 'f'.
50 // The dialog will by default be modeless, unless you set 'modal' to
51 // TRUE to construct a modal dialog.
52 //=================================================================================
53 GenerationGUI_PipePathDlg::GenerationGUI_PipePathDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
54 bool modal, Qt::WindowFlags fl)
55 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl)
57 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PIPE_PATH")));
58 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
60 setWindowTitle(tr("GEOM_PIPE_PATH_TITLE"));
62 /***************************************************************/
63 mainFrame()->GroupConstructors->setTitle(tr("GEOM_PIPE_PATH"));
64 mainFrame()->RadioButton1->setIcon(image0);
65 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
66 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
67 mainFrame()->RadioButton2->close();
68 mainFrame()->RadioButton3->close();
70 GroupPoints = new DlgRef_3Sel1Check(centralWidget());
72 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
73 GroupPoints->TextLabel1->setText(tr("GEOM_PIPE_LIKE_SHAPE"));
74 GroupPoints->TextLabel2->setText(tr("GEOM_PIPE_BASE1_OBJECT"));
75 GroupPoints->TextLabel3->setText(tr("GEOM_PIPE_BASE2_OBJECT"));
76 GroupPoints->PushButton1->setIcon(image1);
77 GroupPoints->PushButton2->setIcon(image1);
78 GroupPoints->PushButton3->setIcon(image1);
79 GroupPoints->CheckButton1->setText(tr("GEOM_SELECT_UNPUBLISHED_EDGES"));
81 QVBoxLayout* layout = new QVBoxLayout (centralWidget());
83 layout->setSpacing(6);
84 layout->addWidget(GroupPoints);
85 /***************************************************************/
87 setHelpFileName("create_pipe_path_page.html");
93 //=================================================================================
94 // function : ~GenerationGUI_PipePathDlg()
95 // purpose : Destroys the object and frees any allocated resources
96 //=================================================================================
97 GenerationGUI_PipePathDlg::~GenerationGUI_PipePathDlg()
99 // no need to delete child widgets, Qt does it all for us
102 //=================================================================================
105 //=================================================================================
106 void GenerationGUI_PipePathDlg::Init()
109 GroupPoints->LineEdit1->setReadOnly(true);
110 GroupPoints->LineEdit2->setReadOnly(true);
111 GroupPoints->LineEdit3->setReadOnly(true);
113 GroupPoints->LineEdit1->setText("");
114 GroupPoints->LineEdit2->setText("");
115 GroupPoints->LineEdit3->setText("");
119 GroupPoints->CheckButton1->setEnabled(false);
121 showOnlyPreviewControl();
123 // signals and slots connections
124 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
125 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
127 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
128 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
129 connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
131 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(SelectionTypeButtonClicked()));
133 initName(tr("GEOM_PIPE_PATH"));
138 GroupPoints->PushButton1->click();
139 SelectionIntoArgument();
142 //=================================================================================
143 // function : SelectionBittonClicked()
144 // purpose : Selection type Radio button management
145 //=================================================================================
146 void GenerationGUI_PipePathDlg::SelectionTypeButtonClicked()
149 if (GroupPoints->CheckButton1->isChecked()) {
150 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
153 TColStd_MapOfInteger aMap;
157 globalSelection(aMap);
162 //=================================================================================
163 // function : ClickOnOk()
165 //=================================================================================
166 void GenerationGUI_PipePathDlg::ClickOnOk()
168 setIsApplyAndClose(true);
173 //=================================================================================
174 // function : ClickOnApply()
176 //=================================================================================
177 bool GenerationGUI_PipePathDlg::ClickOnApply()
183 // activate selection and connect selection manager
184 GroupPoints->PushButton1->click();
188 //=================================================================================
189 // function : SelectionIntoArgument()
190 // purpose : Called when selection is changed or on dialog initialization or activation
191 //=================================================================================
192 void GenerationGUI_PipePathDlg::SelectionIntoArgument()
195 myEditCurrentArgument->setText("");
197 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
198 QList<TopAbs_ShapeEnum> types;
199 types << TopAbs_SOLID << TopAbs_SHELL << TopAbs_FACE;
200 myShape = getSelected(types);
202 QString aName = GEOMBase::GetName(myShape.get());
203 myEditCurrentArgument->setText(aName);
204 if (myBase1Objects.isEmpty())
205 GroupPoints->PushButton2->click();
206 else if (myBase2Objects.isEmpty())
207 GroupPoints->PushButton3->click();
210 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
211 myBase1Objects.clear();
212 QList<GEOM::GeomObjPtr> objects = getSelected(TopAbs_SHAPE, -1);
213 for (int i = 0; i < objects.count(); i++) {
214 GEOM::shape_type stype = objects[i]->GetMaxShapeType();
215 if (GEOM::FACE <= stype && stype <= GEOM::EDGE)
216 myBase1Objects << objects[i];
218 int nbObj = myBase1Objects.count();
221 nbObj > 1 ? QString("%1_objects").arg(nbObj) : GEOMBase::GetName(myBase1Objects[0].get());
222 myEditCurrentArgument->setText(aName);
225 else if (myEditCurrentArgument == GroupPoints->LineEdit3) {
226 myBase2Objects.clear();
227 QList<GEOM::GeomObjPtr> objects = getSelected(TopAbs_SHAPE, -1);
228 for (int i = 0; i < objects.count(); i++) {
229 GEOM::shape_type stype = objects[i]->GetMaxShapeType();
230 if (GEOM::FACE <= stype && stype <= GEOM::EDGE)
231 myBase2Objects << objects[i];
233 int nbObj = myBase2Objects.count();
236 nbObj > 1 ? QString("%1_objects").arg(nbObj) : GEOMBase::GetName(myBase2Objects[0].get());
237 myEditCurrentArgument->setText(aName);
244 //=================================================================================
245 // function : SetEditCurrentArgument()
247 //=================================================================================
248 void GenerationGUI_PipePathDlg::SetEditCurrentArgument()
250 QPushButton* send = (QPushButton*)sender();
252 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
254 globalSelection(GEOM_ALLSHAPES);
256 GroupPoints->PushButton1->setDown(false);
257 GroupPoints->PushButton2->setDown(false);
258 GroupPoints->PushButton3->setDown(false);
259 GroupPoints->LineEdit1->setEnabled(false);
260 GroupPoints->LineEdit2->setEnabled(false);
261 GroupPoints->LineEdit3->setEnabled(false);
263 if (send == GroupPoints->PushButton1) {
264 myEditCurrentArgument = GroupPoints->LineEdit1;
265 GroupPoints->CheckButton1->setEnabled(false);
267 else if (send == GroupPoints->PushButton2) {
268 myEditCurrentArgument = GroupPoints->LineEdit2;
270 if (GroupPoints->CheckButton1->isChecked()) {
271 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
274 TColStd_MapOfInteger aMap;
278 globalSelection(aMap);
280 GroupPoints->CheckButton1->setEnabled(true);
282 else if (send == GroupPoints->PushButton3) {
283 myEditCurrentArgument = GroupPoints->LineEdit3;
285 if (GroupPoints->CheckButton1->isChecked()) {
286 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
289 TColStd_MapOfInteger aMap;
293 globalSelection(aMap);
295 GroupPoints->CheckButton1->setEnabled(true);
297 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
298 this, SLOT(SelectionIntoArgument()));
301 myEditCurrentArgument->setEnabled(true);
302 myEditCurrentArgument->setFocus();
303 // after setFocus(), because it will be setDown(false) when loses focus
306 // seems we need it only to avoid preview disappearing, caused by selection mode change
310 //=================================================================================
311 // function : ActivateThisDialog()
313 //=================================================================================
314 void GenerationGUI_PipePathDlg::ActivateThisDialog()
316 GEOMBase_Skeleton::ActivateThisDialog();
318 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
319 this, SLOT(SelectionIntoArgument()));
321 GroupPoints->PushButton1->click();
322 SelectionIntoArgument();
325 //=================================================================================
326 // function : enterEvent()
327 // purpose : when mouse enter onto the QWidget
328 //=================================================================================
329 void GenerationGUI_PipePathDlg::enterEvent (QEvent*)
331 if (!mainFrame()->GroupConstructors->isEnabled())
332 ActivateThisDialog();
335 //=================================================================================
336 // function : createOperation
338 //=================================================================================
339 GEOM::GEOM_IOperations_ptr GenerationGUI_PipePathDlg::createOperation()
341 return getGeomEngine()->GetI3DPrimOperations(getStudyId());
344 //=================================================================================
345 // function : isValid
347 //=================================================================================
348 bool GenerationGUI_PipePathDlg::isValid (QString&)
350 bool ok = myShape && !myBase1Objects.isEmpty() && !myBase2Objects.isEmpty();
354 //=================================================================================
355 // function : execute
357 //=================================================================================
358 bool GenerationGUI_PipePathDlg::execute (ObjectList& objects)
360 GEOM::ListOfGO_var aBase1 = new GEOM::ListOfGO();
361 GEOM::ListOfGO_var aBase2 = new GEOM::ListOfGO();
363 aBase1->length(myBase1Objects.count());
364 aBase2->length(myBase2Objects.count());
367 for (i = 0; i < myBase1Objects.count(); i++)
368 aBase1[i] = myBase1Objects[i].copy();
369 for (i = 0; i < myBase2Objects.count(); i++)
370 aBase2[i] = myBase2Objects[i].copy();
372 GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
373 GEOM::GEOM_Object_var anObj = anOper->RestorePathEdges(myShape.get(), aBase1.in(), aBase2.in());
375 if (!anObj->_is_nil())
376 objects.push_back(anObj._retn());
381 //=================================================================================
382 // function : addSubshapeToStudy
383 // purpose : virtual method to add new SubObjects if local selection
384 //=================================================================================
385 void GenerationGUI_PipePathDlg::addSubshapesToStudy()
388 for (i = 0; i < myBase1Objects.count(); i++)
389 GEOMBase::PublishSubObject(myBase1Objects[i].get());
390 for (i = 0; i < myBase2Objects.count(); i++)
391 GEOMBase::PublishSubObject(myBase2Objects[i].get());