1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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 // File : GenerationGUI_PipeDlg.cxx
23 // 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_VECTOR"));
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 myBase = 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"));
139 GroupPoints->TextLabel3->hide();
140 GroupPoints->PushButton3->hide();
141 GroupPoints->LineEdit3->hide();
142 ConstructorsClicked(0);
144 GroupPoints->PushButton1->click();
145 SelectionIntoArgument();
148 //=================================================================================
149 // function : ConstructorsClicked()
150 // purpose : Radio button management
151 //=================================================================================
152 void GenerationGUI_PipeDlg::ConstructorsClicked( int constructorId )
156 switch (constructorId)
160 GroupPoints->TextLabel3->hide();
161 GroupPoints->PushButton3->hide();
162 GroupPoints->LineEdit3->hide();
167 GroupPoints->TextLabel3->show();
168 GroupPoints->PushButton3->show();
169 GroupPoints->LineEdit3->show();
177 //=================================================================================
178 // function : SelectionBittonClicked()
179 // purpose : Selection type Radio button management
180 //=================================================================================
181 void GenerationGUI_PipeDlg::SelectionTypeButtonClicked()
184 if ( GroupPoints->CheckButton1->isChecked() ) {
185 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
187 TColStd_MapOfInteger aMap;
190 globalSelection(aMap);
192 if(myEditCurrentArgument == GroupPoints->LineEdit2) {
193 myEditCurrentArgument->setText("");
199 //=================================================================================
200 // function : ClickOnOk()
202 //=================================================================================
203 void GenerationGUI_PipeDlg::ClickOnOk()
209 //=================================================================================
210 // function : ClickOnApply()
212 //=================================================================================
213 bool GenerationGUI_PipeDlg::ClickOnApply()
219 if ( getConstructorId() != 1 )
220 ConstructorsClicked( getConstructorId() );
221 // activate selection and connect selection manager
222 GroupPoints->PushButton1->click();
226 //=================================================================================
227 // function : SelectionIntoArgument()
228 // purpose : Called when selection is changed or on dialog initialization or activation
229 //=================================================================================
230 void GenerationGUI_PipeDlg::SelectionIntoArgument()
233 myEditCurrentArgument->setText("");
234 if (myEditCurrentArgument == GroupPoints->LineEdit1) myOkBase = false;
235 else if (myEditCurrentArgument == GroupPoints->LineEdit2) myOkPath = false;
236 else if (myEditCurrentArgument == GroupPoints->LineEdit3) myOkVec = false;
238 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
239 SALOME_ListIO aSelList;
240 aSelMgr->selectedObjects(aSelList);
242 if (aSelList.Extent() != 1)
246 Standard_Boolean testResult = Standard_False;
247 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
249 if (!testResult || aSelectedObject->_is_nil())
253 if (!GEOMBase::GetShape(aSelectedObject, S))
256 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
257 if (S.ShapeType() == TopAbs_COMPSOLID ||
258 S.ShapeType() == TopAbs_COMPOUND ||
259 S.ShapeType() == TopAbs_SOLID ||
260 S.ShapeType() == TopAbs_SHAPE)
262 if ( getConstructorId() == 1 &&
263 (S.ShapeType() == TopAbs_SHELL ||
264 S.ShapeType() == TopAbs_VERTEX))
267 myBase = aSelectedObject;
268 myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject));
271 GroupPoints->PushButton2->click();
273 GroupPoints->PushButton3->click();
275 else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
276 myEditCurrentArgument == GroupPoints->LineEdit3) {
277 myEditCurrentArgument == GroupPoints->LineEdit2 ? myOkPath = false : myOkVec = false;
279 QString aName = GEOMBase::GetName(aSelectedObject);
281 if (myEditCurrentArgument == GroupPoints->LineEdit2 && !GroupPoints->CheckButton1->isChecked() ){
282 myPath = aSelectedObject;
284 myEditCurrentArgument->setText(aName);
288 if (aSelectedObject != myBase) {
289 TColStd_IndexedMapOfInteger aMap;
290 aSelMgr->GetIndexes(aSelList.First(), aMap);
291 if (aMap.Extent() == 1) {
292 int anIndex = aMap(1);
293 aName.append(":edge_" + QString::number(anIndex));
295 //Find SubShape Object in Father
296 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
298 if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
299 GEOM::GEOM_IShapesOperations_var aShapesOp =
300 getGeomEngine()->GetIShapesOperations(getStudyId());
301 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
304 else { // get Object from study
305 aSelectedObject = aFindedObject;
311 if (S.ShapeType() != TopAbs_EDGE) {
312 aSelectedObject = GEOM::GEOM_Object::_nil();
317 if (myEditCurrentArgument == GroupPoints->LineEdit2) {
318 myPath = aSelectedObject;
321 else if (myEditCurrentArgument == GroupPoints->LineEdit3) {
322 myVec = aSelectedObject;
326 myEditCurrentArgument->setText(aName);
330 GroupPoints->PushButton1->click();
332 GroupPoints->PushButton3->click();
336 GroupPoints->PushButton1->click();
338 GroupPoints->PushButton2->click();
344 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
345 myGeomGUI->getApp()->selectionMgr()->clearSelected();
346 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
347 this, SLOT(SelectionIntoArgument()));
352 //=================================================================================
353 // function : SetEditCurrentArgument()
355 //=================================================================================
356 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
358 QPushButton* send = (QPushButton*)sender();
360 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
361 globalSelection(GEOM_ALLSHAPES);
362 GroupPoints->PushButton1->setDown(false);
363 GroupPoints->PushButton2->setDown(false);
364 GroupPoints->PushButton3->setDown(false);
365 GroupPoints->LineEdit1->setEnabled(false);
366 GroupPoints->LineEdit2->setEnabled(false);
367 GroupPoints->LineEdit3->setEnabled(false);
368 if (send == GroupPoints->PushButton1) {
369 myEditCurrentArgument = GroupPoints->LineEdit1;
370 GroupPoints->CheckButton1->setEnabled(false);
372 else if (send == GroupPoints->PushButton2) {
373 myEditCurrentArgument = GroupPoints->LineEdit2;
375 if ( GroupPoints->CheckButton1->isChecked() ) {
376 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
378 TColStd_MapOfInteger aMap;
381 globalSelection(aMap);
383 GroupPoints->CheckButton1->setEnabled(true);
385 else if(send == GroupPoints->PushButton3) {
386 myEditCurrentArgument = GroupPoints->LineEdit3;
387 GroupPoints->CheckButton1->setEnabled(false);
388 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
390 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
391 this, SLOT(SelectionIntoArgument()));
394 myEditCurrentArgument->setEnabled(true);
395 myEditCurrentArgument->setFocus();
396 // after setFocus(), because it will be setDown(false) when loses focus
399 // seems we need it only to avoid preview disappearing, caused by selection mode change
403 //=================================================================================
404 // function : LineEditReturnPressed()
406 //=================================================================================
407 void GenerationGUI_PipeDlg::LineEditReturnPressed()
409 QLineEdit* send = (QLineEdit*)sender();
410 if (send == GroupPoints->LineEdit1 ||
411 send == GroupPoints->LineEdit2 ||
412 send == GroupPoints->LineEdit3) {
413 myEditCurrentArgument = send;
414 GEOMBase_Skeleton::LineEditReturnPressed();
417 if (send == GroupPoints->LineEdit2)
418 GroupPoints->CheckButton1->setEnabled(true);
420 GroupPoints->CheckButton1->setEnabled(false);
423 //=================================================================================
424 // function : ActivateThisDialog()
426 //=================================================================================
427 void GenerationGUI_PipeDlg::ActivateThisDialog()
429 GEOMBase_Skeleton::ActivateThisDialog();
430 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
431 this, SLOT( SelectionIntoArgument() ) );
433 ConstructorsClicked(getConstructorId());
436 //=================================================================================
437 // function : enterEvent()
438 // purpose : when mouse enter onto the QWidget
439 //=================================================================================
440 void GenerationGUI_PipeDlg::enterEvent (QEvent*)
442 if (!mainFrame()->GroupConstructors->isEnabled())
443 ActivateThisDialog();
446 //=================================================================================
447 // function : createOperation
449 //=================================================================================
450 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
452 return getGeomEngine()->GetI3DPrimOperations(getStudyId());
455 //=================================================================================
456 // function : isValid
458 //=================================================================================
459 bool GenerationGUI_PipeDlg::isValid (QString&)
461 switch ( getConstructorId() ) {
463 return myOkBase && myOkPath;
465 return myOkBase && myOkPath && myOkVec;
469 //=================================================================================
470 // function : execute
472 //=================================================================================
473 bool GenerationGUI_PipeDlg::execute (ObjectList& objects)
475 GEOM::GEOM_Object_var anObj;
477 switch ( getConstructorId() ) {
479 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->MakePipe(myBase, myPath);
482 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
483 MakePipeBiNormalAlongVector(myBase, myPath, myVec);
487 if (!anObj->_is_nil())
488 objects.push_back(anObj._retn());
493 //=================================================================================
494 // function : addSubshapeToStudy
495 // purpose : virtual method to add new SubObjects if local selection
496 //=================================================================================
497 void GenerationGUI_PipeDlg::addSubshapesToStudy()
499 QMap<QString, GEOM::GEOM_Object_var> objMap;
501 objMap[GroupPoints->LineEdit2->text()] = myPath;
503 addSubshapesToFather(objMap);