1 // Copyright (C) 2007-2008 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_PipeDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "GenerationGUI_PipeDlg.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_PipeDlg()
49 // purpose : Constructs a GenerationGUI_PipeDlg 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_PipeDlg::GenerationGUI_PipeDlg (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")));
59 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
60 QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PIPE_BINORMAL")));
62 setWindowTitle(tr("GEOM_PIPE_TITLE"));
64 /***************************************************************/
65 mainFrame()->GroupConstructors->setTitle(tr("GEOM_PIPE"));
66 mainFrame()->RadioButton1->setIcon(image0);
67 mainFrame()->RadioButton2->setIcon(image2);
68 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
69 mainFrame()->RadioButton3->close();
71 GroupPoints = new DlgRef_3Sel1Check(centralWidget());
73 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
74 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_OBJECT"));
75 GroupPoints->TextLabel2->setText(tr("GEOM_PATH_OBJECT"));
76 GroupPoints->TextLabel3->setText(tr("GEOM_BINORMAL"));
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());
83 layout->setMargin(0); layout->setSpacing(6);
84 layout->addWidget(GroupPoints);
85 /***************************************************************/
87 setHelpFileName("create_extrusion_alongpath_page.html");
93 //=================================================================================
94 // function : ~GenerationGUI_PipeDlg()
95 // purpose : Destroys the object and frees any allocated resources
96 //=================================================================================
97 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
99 // no need to delete child widgets, Qt does it all for us
102 //=================================================================================
105 //=================================================================================
106 void GenerationGUI_PipeDlg::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("");
116 myPath = myVec = GEOM::GEOM_Object::_nil();
117 myOkBase = myOkPath = myOkVec = false;
119 GroupPoints->CheckButton1->setEnabled(false);
121 // signals and slots connections
122 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
123 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
125 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
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->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
132 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
133 connect(GroupPoints->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
135 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(SelectionTypeButtonClicked()));
137 initName(tr("GEOM_PIPE"));
140 GroupPoints->TextLabel3->hide();
141 GroupPoints->PushButton3->hide();
142 GroupPoints->LineEdit3->hide();
143 ConstructorsClicked(0);
145 GroupPoints->PushButton1->click();
146 SelectionIntoArgument();
149 //=================================================================================
150 // function : ConstructorsClicked()
151 // purpose : Radio button management
152 //=================================================================================
153 void GenerationGUI_PipeDlg::ConstructorsClicked( int constructorId )
157 switch (constructorId)
161 GroupPoints->TextLabel3->hide();
162 GroupPoints->PushButton3->hide();
163 GroupPoints->LineEdit3->hide();
168 GroupPoints->TextLabel3->show();
169 GroupPoints->PushButton3->show();
170 GroupPoints->LineEdit3->show();
174 qApp->processEvents();
181 //=================================================================================
182 // function : SelectionBittonClicked()
183 // purpose : Selection type Radio button management
184 //=================================================================================
185 void GenerationGUI_PipeDlg::SelectionTypeButtonClicked()
188 if ( GroupPoints->CheckButton1->isChecked() ) {
189 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
191 TColStd_MapOfInteger aMap;
194 globalSelection(aMap);
196 if(myEditCurrentArgument == GroupPoints->LineEdit2) {
197 myEditCurrentArgument->setText("");
203 //=================================================================================
204 // function : ClickOnOk()
206 //=================================================================================
207 void GenerationGUI_PipeDlg::ClickOnOk()
213 //=================================================================================
214 // function : ClickOnApply()
216 //=================================================================================
217 bool GenerationGUI_PipeDlg::ClickOnApply()
223 if ( getConstructorId() != 1 )
224 ConstructorsClicked( getConstructorId() );
225 // activate selection and connect selection manager
226 GroupPoints->PushButton1->click();
230 //=================================================================================
231 // function : SelectionIntoArgument()
232 // purpose : Called when selection is changed or on dialog initialization or activation
233 //=================================================================================
234 void GenerationGUI_PipeDlg::SelectionIntoArgument()
237 myEditCurrentArgument->setText("");
238 if (myEditCurrentArgument == GroupPoints->LineEdit1) myOkBase = false;
239 else if (myEditCurrentArgument == GroupPoints->LineEdit2) myOkPath = false;
240 else if (myEditCurrentArgument == GroupPoints->LineEdit3) myOkVec = false;
242 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
243 SALOME_ListIO aSelList;
244 aSelMgr->selectedObjects(aSelList);
246 if (aSelList.Extent() < 1)
249 Standard_Boolean testResult = Standard_False;
250 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
251 QString aName = GEOMBase::GetName(aSelectedObject);
253 if (!testResult || aSelectedObject->_is_nil())
257 if (!GEOMBase::GetShape(aSelectedObject, S))
260 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
262 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myBaseObjects, true);
263 if (aSelList.Extent() > 1)
264 aName = QString( "%1_objects").arg( aSelList.Extent() );
266 if ( aSelList.Extent() > 0 ) {
268 for (int i=0; i < myBaseObjects.length(); i++) {
269 GEOMBase::GetShape(myBaseObjects[i], S);
270 if (S.ShapeType() == TopAbs_COMPSOLID ||
271 S.ShapeType() == TopAbs_COMPOUND ||
272 S.ShapeType() == TopAbs_SOLID ||
273 S.ShapeType() == TopAbs_SHAPE)
275 if ( getConstructorId() == 1 &&
276 (S.ShapeType() == TopAbs_SHELL ||
277 S.ShapeType() == TopAbs_VERTEX))
282 myEditCurrentArgument->setText(aName);
284 } else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
285 myEditCurrentArgument == GroupPoints->LineEdit3) {
286 myEditCurrentArgument == GroupPoints->LineEdit2 ? myOkPath = false : myOkVec = false;
289 if (myEditCurrentArgument == GroupPoints->LineEdit2 && !GroupPoints->CheckButton1->isChecked() ){
290 myPath = aSelectedObject;
292 myEditCurrentArgument->setText(aName);
294 TColStd_IndexedMapOfInteger aMap;
295 aSelMgr->GetIndexes(aSelList.First(), aMap);
296 if (aMap.Extent() == 1) {
297 int anIndex = aMap(1);
298 aName.append(":edge_" + QString::number(anIndex));
300 //Find SubShape Object in Father
301 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
303 if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
304 GEOM::GEOM_IShapesOperations_var aShapesOp =
305 getGeomEngine()->GetIShapesOperations(getStudyId());
306 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
308 } else { // get Object from study
309 aSelectedObject = aFindedObject;
314 if (S.ShapeType() != TopAbs_EDGE) {
315 aSelectedObject = GEOM::GEOM_Object::_nil();
320 if (myEditCurrentArgument == GroupPoints->LineEdit2) {
321 myPath = aSelectedObject;
323 } else if (myEditCurrentArgument == GroupPoints->LineEdit3) {
324 myVec = aSelectedObject;
327 myEditCurrentArgument->setText(aName);
331 GroupPoints->PushButton1->click();
333 GroupPoints->PushButton3->click();
334 } else if (myOkVec) {
336 GroupPoints->PushButton1->click();
338 GroupPoints->PushButton2->click();
345 //=================================================================================
346 // function : SetEditCurrentArgument()
348 //=================================================================================
349 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
351 QPushButton* send = (QPushButton*)sender();
353 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
354 globalSelection(GEOM_ALLSHAPES);
355 GroupPoints->PushButton1->setDown(false);
356 GroupPoints->PushButton2->setDown(false);
357 GroupPoints->PushButton3->setDown(false);
358 GroupPoints->LineEdit1->setEnabled(false);
359 GroupPoints->LineEdit2->setEnabled(false);
360 GroupPoints->LineEdit3->setEnabled(false);
361 if (send == GroupPoints->PushButton1) {
362 myEditCurrentArgument = GroupPoints->LineEdit1;
363 GroupPoints->CheckButton1->setEnabled(false);
365 else if (send == GroupPoints->PushButton2) {
366 myEditCurrentArgument = GroupPoints->LineEdit2;
368 if ( GroupPoints->CheckButton1->isChecked() ) {
369 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
371 TColStd_MapOfInteger aMap;
374 globalSelection(aMap);
376 GroupPoints->CheckButton1->setEnabled(true);
378 else if(send == GroupPoints->PushButton3) {
379 myEditCurrentArgument = GroupPoints->LineEdit3;
380 GroupPoints->CheckButton1->setEnabled(false);
381 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
383 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
384 this, SLOT(SelectionIntoArgument()));
387 myEditCurrentArgument->setEnabled(true);
388 myEditCurrentArgument->setFocus();
389 // after setFocus(), because it will be setDown(false) when loses focus
392 // seems we need it only to avoid preview disappearing, caused by selection mode change
396 //=================================================================================
397 // function : LineEditReturnPressed()
399 //=================================================================================
400 void GenerationGUI_PipeDlg::LineEditReturnPressed()
402 QLineEdit* send = (QLineEdit*)sender();
403 if (send == GroupPoints->LineEdit1 ||
404 send == GroupPoints->LineEdit2 ||
405 send == GroupPoints->LineEdit3) {
406 myEditCurrentArgument = send;
407 GEOMBase_Skeleton::LineEditReturnPressed();
410 if (send == GroupPoints->LineEdit2)
411 GroupPoints->CheckButton1->setEnabled(true);
413 GroupPoints->CheckButton1->setEnabled(false);
416 //=================================================================================
417 // function : ActivateThisDialog()
419 //=================================================================================
420 void GenerationGUI_PipeDlg::ActivateThisDialog()
422 GEOMBase_Skeleton::ActivateThisDialog();
423 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
424 this, SLOT( SelectionIntoArgument() ) );
426 ConstructorsClicked(getConstructorId());
429 //=================================================================================
430 // function : enterEvent()
431 // purpose : when mouse enter onto the QWidget
432 //=================================================================================
433 void GenerationGUI_PipeDlg::enterEvent (QEvent*)
435 if (!mainFrame()->GroupConstructors->isEnabled())
436 ActivateThisDialog();
439 //=================================================================================
440 // function : createOperation
442 //=================================================================================
443 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
445 return getGeomEngine()->GetI3DPrimOperations(getStudyId());
448 //=================================================================================
449 // function : isValid
451 //=================================================================================
452 bool GenerationGUI_PipeDlg::isValid (QString&)
454 switch ( getConstructorId() ) {
456 return myOkBase && myOkPath;
458 return myOkBase && myOkPath && myOkVec;
462 //=================================================================================
463 // function : execute
465 //=================================================================================
466 bool GenerationGUI_PipeDlg::execute (ObjectList& objects)
468 GEOM::GEOM_Object_var anObj, aBase;
470 GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
472 for (int i=0; i < myBaseObjects.length(); i++) {
473 aBase = myBaseObjects[i];
474 switch ( getConstructorId() ) {
476 anObj = anOper->MakePipe(aBase, myPath);
479 anObj = anOper->MakePipeBiNormalAlongVector(aBase, myPath, myVec);
483 if (!anObj->_is_nil())
484 objects.push_back(anObj._retn());
489 //=================================================================================
490 // function : addSubshapeToStudy
491 // purpose : virtual method to add new SubObjects if local selection
492 //=================================================================================
493 void GenerationGUI_PipeDlg::addSubshapesToStudy()
495 QMap<QString, GEOM::GEOM_Object_var> objMap;
497 objMap[GroupPoints->LineEdit2->text()] = myPath;
499 addSubshapesToFather(objMap);