1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GenerationGUI_PipePathDlg.cxx
26 #include "GenerationGUI_PipePathDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
37 #include <TopoDS_Shape.hxx>
40 #include <TColStd_IndexedMapOfInteger.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
42 #include <TColStd_IndexedMapOfInteger.hxx>
43 #include <TColStd_MapOfInteger.hxx>
45 #include <GEOMImpl_Types.hxx>
47 //=================================================================================
48 // class : GenerationGUI_PipePathDlg()
49 // purpose : Constructs a GenerationGUI_PipePathDlg which is a child of 'parent', with the
50 // name 'name' and widget flags set to 'f'.
51 // The dialog will by default be modeless, unless you set 'modal' to
52 // TRUE to construct a modal dialog.
53 //=================================================================================
54 GenerationGUI_PipePathDlg::GenerationGUI_PipePathDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
55 bool modal, Qt::WindowFlags fl)
56 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl)
58 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PIPE_PATH")));
59 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
61 setWindowTitle(tr("GEOM_PIPE_PATH_TITLE"));
63 /***************************************************************/
64 mainFrame()->GroupConstructors->setTitle(tr("GEOM_PIPE_PATH"));
65 mainFrame()->RadioButton1->setIcon(image0);
66 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
67 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
68 mainFrame()->RadioButton2->close();
69 mainFrame()->RadioButton3->close();
71 GroupPoints = new DlgRef_3Sel1Check(centralWidget());
73 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
74 GroupPoints->TextLabel1->setText(tr("GEOM_PIPE_LIKE_SHAPE"));
75 GroupPoints->TextLabel2->setText(tr("GEOM_PIPE_BASE1_OBJECT"));
76 GroupPoints->TextLabel3->setText(tr("GEOM_PIPE_BASE2_OBJECT"));
77 GroupPoints->PushButton1->setIcon(image1);
78 GroupPoints->PushButton2->setIcon(image1);
79 GroupPoints->PushButton3->setIcon(image1);
80 GroupPoints->CheckButton1->setText(tr("GEOM_SELECT_UNPUBLISHED_EDGES"));
82 QVBoxLayout* layout = new QVBoxLayout (centralWidget());
84 layout->setSpacing(6);
85 layout->addWidget(GroupPoints);
86 /***************************************************************/
88 setHelpFileName("create_pipe_path_page.html");
94 //=================================================================================
95 // function : ~GenerationGUI_PipePathDlg()
96 // purpose : Destroys the object and frees any allocated resources
97 //=================================================================================
98 GenerationGUI_PipePathDlg::~GenerationGUI_PipePathDlg()
100 // no need to delete child widgets, Qt does it all for us
103 //=================================================================================
106 //=================================================================================
107 void GenerationGUI_PipePathDlg::Init()
110 GroupPoints->LineEdit1->setReadOnly(true);
111 GroupPoints->LineEdit2->setReadOnly(true);
112 GroupPoints->LineEdit3->setReadOnly(true);
114 GroupPoints->LineEdit1->setText("");
115 GroupPoints->LineEdit2->setText("");
116 GroupPoints->LineEdit3->setText("");
120 GroupPoints->CheckButton1->setEnabled(false);
122 showOnlyPreviewControl();
124 // signals and slots connections
125 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
126 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
128 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
129 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
130 connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
132 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(SelectionTypeButtonClicked()));
134 initName(tr("GEOM_PIPE_PATH"));
139 GroupPoints->PushButton1->click();
140 SelectionIntoArgument();
143 //=================================================================================
144 // function : SelectionBittonClicked()
145 // purpose : Selection type Radio button management
146 //=================================================================================
147 void GenerationGUI_PipePathDlg::SelectionTypeButtonClicked()
150 if (GroupPoints->CheckButton1->isChecked()) {
151 localSelection(TopAbs_EDGE);
154 TColStd_MapOfInteger aMap;
158 globalSelection(aMap);
163 //=================================================================================
164 // function : ClickOnOk()
166 //=================================================================================
167 void GenerationGUI_PipePathDlg::ClickOnOk()
169 setIsApplyAndClose(true);
174 //=================================================================================
175 // function : ClickOnApply()
177 //=================================================================================
178 bool GenerationGUI_PipePathDlg::ClickOnApply()
184 // activate selection and connect selection manager
185 GroupPoints->PushButton1->click();
189 //=================================================================================
190 // function : SelectionIntoArgument()
191 // purpose : Called when selection is changed or on dialog initialization or activation
192 //=================================================================================
193 void GenerationGUI_PipePathDlg::SelectionIntoArgument()
196 myEditCurrentArgument->setText("");
198 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
199 QList<TopAbs_ShapeEnum> types;
200 types << TopAbs_SOLID << TopAbs_SHELL << TopAbs_FACE;
201 myShape = getSelected(types);
203 QString aName = GEOMBase::GetName(myShape.get());
204 myEditCurrentArgument->setText(aName);
205 if (myBase1Objects.isEmpty())
206 GroupPoints->PushButton2->click();
207 else if (myBase2Objects.isEmpty())
208 GroupPoints->PushButton3->click();
211 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
212 myBase1Objects.clear();
213 QList<GEOM::GeomObjPtr> objects = getSelected(TopAbs_SHAPE, -1);
214 for (int i = 0; i < objects.count(); i++) {
215 GEOM::shape_type stype = objects[i]->GetMaxShapeType();
216 if (GEOM::FACE <= stype && stype <= GEOM::EDGE)
217 myBase1Objects << objects[i];
219 int nbObj = myBase1Objects.count();
222 nbObj > 1 ? QString("%1_objects").arg(nbObj) : GEOMBase::GetName(myBase1Objects[0].get());
223 myEditCurrentArgument->setText(aName);
226 else if (myEditCurrentArgument == GroupPoints->LineEdit3) {
227 myBase2Objects.clear();
228 QList<GEOM::GeomObjPtr> objects = getSelected(TopAbs_SHAPE, -1);
229 for (int i = 0; i < objects.count(); i++) {
230 GEOM::shape_type stype = objects[i]->GetMaxShapeType();
231 if (GEOM::FACE <= stype && stype <= GEOM::EDGE)
232 myBase2Objects << objects[i];
234 int nbObj = myBase2Objects.count();
237 nbObj > 1 ? QString("%1_objects").arg(nbObj) : GEOMBase::GetName(myBase2Objects[0].get());
238 myEditCurrentArgument->setText(aName);
245 //=================================================================================
246 // function : SetEditCurrentArgument()
248 //=================================================================================
249 void GenerationGUI_PipePathDlg::SetEditCurrentArgument()
251 QPushButton* send = (QPushButton*)sender();
253 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
255 globalSelection(GEOM_ALLSHAPES);
257 GroupPoints->PushButton1->setDown(false);
258 GroupPoints->PushButton2->setDown(false);
259 GroupPoints->PushButton3->setDown(false);
260 GroupPoints->LineEdit1->setEnabled(false);
261 GroupPoints->LineEdit2->setEnabled(false);
262 GroupPoints->LineEdit3->setEnabled(false);
264 if (send == GroupPoints->PushButton1) {
265 myEditCurrentArgument = GroupPoints->LineEdit1;
266 GroupPoints->CheckButton1->setEnabled(false);
268 else if (send == GroupPoints->PushButton2) {
269 myEditCurrentArgument = GroupPoints->LineEdit2;
271 if (GroupPoints->CheckButton1->isChecked()) {
272 localSelection(TopAbs_EDGE);
275 TColStd_MapOfInteger aMap;
279 globalSelection(aMap);
281 GroupPoints->CheckButton1->setEnabled(true);
283 else if (send == GroupPoints->PushButton3) {
284 myEditCurrentArgument = GroupPoints->LineEdit3;
286 if (GroupPoints->CheckButton1->isChecked()) {
287 localSelection(TopAbs_EDGE);
290 TColStd_MapOfInteger aMap;
294 globalSelection(aMap);
296 GroupPoints->CheckButton1->setEnabled(true);
298 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
299 this, SLOT(SelectionIntoArgument()));
302 myEditCurrentArgument->setEnabled(true);
303 myEditCurrentArgument->setFocus();
304 // after setFocus(), because it will be setDown(false) when loses focus
307 // seems we need it only to avoid preview disappearing, caused by selection mode change
311 //=================================================================================
312 // function : ActivateThisDialog()
314 //=================================================================================
315 void GenerationGUI_PipePathDlg::ActivateThisDialog()
317 GEOMBase_Skeleton::ActivateThisDialog();
319 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
320 this, SLOT(SelectionIntoArgument()));
322 GroupPoints->PushButton1->click();
323 SelectionIntoArgument();
326 //=================================================================================
327 // function : enterEvent()
328 // purpose : when mouse enter onto the QWidget
329 //=================================================================================
330 void GenerationGUI_PipePathDlg::enterEvent (QEvent*)
332 if (!mainFrame()->GroupConstructors->isEnabled())
333 ActivateThisDialog();
336 //=================================================================================
337 // function : createOperation
339 //=================================================================================
340 GEOM::GEOM_IOperations_ptr GenerationGUI_PipePathDlg::createOperation()
342 return getGeomEngine()->GetI3DPrimOperations(getStudyId());
345 //=================================================================================
346 // function : isValid
348 //=================================================================================
349 bool GenerationGUI_PipePathDlg::isValid (QString&)
351 bool ok = myShape && !myBase1Objects.isEmpty() && !myBase2Objects.isEmpty();
355 //=================================================================================
356 // function : execute
358 //=================================================================================
359 bool GenerationGUI_PipePathDlg::execute (ObjectList& objects)
361 GEOM::ListOfGO_var aBase1 = new GEOM::ListOfGO();
362 GEOM::ListOfGO_var aBase2 = new GEOM::ListOfGO();
364 aBase1->length(myBase1Objects.count());
365 aBase2->length(myBase2Objects.count());
368 for (i = 0; i < myBase1Objects.count(); i++)
369 aBase1[i] = myBase1Objects[i].copy();
370 for (i = 0; i < myBase2Objects.count(); i++)
371 aBase2[i] = myBase2Objects[i].copy();
373 GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
374 GEOM::GEOM_Object_var anObj = anOper->RestorePathEdges(myShape.get(), aBase1.in(), aBase2.in());
376 if (!anObj->_is_nil())
377 objects.push_back(anObj._retn());
382 //=================================================================================
383 // function : addSubshapeToStudy
384 // purpose : virtual method to add new SubObjects if local selection
385 //=================================================================================
386 void GenerationGUI_PipePathDlg::addSubshapesToStudy()
389 for (i = 0; i < myBase1Objects.count(); i++)
390 GEOMBase::PublishSubObject(myBase1Objects[i].get());
391 for (i = 0; i < myBase2Objects.count(); i++)
392 GEOMBase::PublishSubObject(myBase2Objects[i].get());
395 //=================================================================================
396 // function : getSourceObjects
397 // purpose : virtual method to get source objects
398 //=================================================================================
399 QList<GEOM::GeomObjPtr> GenerationGUI_PipePathDlg::getSourceObjects()
401 QList<GEOM::GeomObjPtr> res(myBase1Objects);
403 for (int i = 0; i < myBase2Objects.count(); i++)
404 res << myBase2Objects[i];