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>
43 #include <GEOMImpl_Types.hxx>
45 //=================================================================================
46 // class : GenerationGUI_PipeDlg()
47 // purpose : Constructs a GenerationGUI_PipeDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 GenerationGUI_PipeDlg::GenerationGUI_PipeDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
53 bool modal, Qt::WindowFlags fl)
54 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl)
56 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PIPE")));
57 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
58 QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PIPE_BINORMAL")));
60 setWindowTitle(tr("GEOM_PIPE_TITLE"));
62 /***************************************************************/
63 mainFrame()->GroupConstructors->setTitle(tr("GEOM_PIPE"));
64 mainFrame()->RadioButton1->setIcon(image0);
65 mainFrame()->RadioButton2->setIcon(image2);
66 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
67 mainFrame()->RadioButton3->close();
69 GroupPoints = new DlgRef_3Sel(centralWidget());
71 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
72 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_OBJECT"));
73 GroupPoints->TextLabel2->setText(tr("GEOM_PATH_OBJECT"));
74 GroupPoints->TextLabel3->setText(tr("GEOM_VECTOR"));
75 GroupPoints->PushButton1->setIcon(image1);
76 GroupPoints->PushButton2->setIcon(image1);
77 GroupPoints->PushButton3->setIcon(image1);
79 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
80 layout->setMargin(0); layout->setSpacing(6);
81 layout->addWidget(GroupPoints);
82 /***************************************************************/
84 setHelpFileName("create_extrusion_alongpath_page.html");
90 //=================================================================================
91 // function : ~GenerationGUI_PipeDlg()
92 // purpose : Destroys the object and frees any allocated resources
93 //=================================================================================
94 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
96 // no need to delete child widgets, Qt does it all for us
99 //=================================================================================
102 //=================================================================================
103 void GenerationGUI_PipeDlg::Init()
106 GroupPoints->LineEdit1->setReadOnly(true);
107 GroupPoints->LineEdit2->setReadOnly(true);
108 GroupPoints->LineEdit3->setReadOnly(true);
110 GroupPoints->LineEdit1->setText("");
111 GroupPoints->LineEdit2->setText("");
112 GroupPoints->LineEdit3->setText("");
113 myBase = myPath = myVec = GEOM::GEOM_Object::_nil();
114 myOkBase = myOkPath = myOkVec = false;
116 // signals and slots connections
117 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
118 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
120 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
122 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
123 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
124 connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
126 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
127 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
128 connect(GroupPoints->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
130 initName(tr("GEOM_PIPE"));
132 GroupPoints->TextLabel3->hide();
133 GroupPoints->PushButton3->hide();
134 GroupPoints->LineEdit3->hide();
135 ConstructorsClicked(0);
137 GroupPoints->PushButton1->click();
138 SelectionIntoArgument();
141 //=================================================================================
142 // function : ConstructorsClicked()
143 // purpose : Radio button management
144 //=================================================================================
145 void GenerationGUI_PipeDlg::ConstructorsClicked( int constructorId )
149 switch (constructorId)
153 GroupPoints->TextLabel3->hide();
154 GroupPoints->PushButton3->hide();
155 GroupPoints->LineEdit3->hide();
160 GroupPoints->TextLabel3->show();
161 GroupPoints->PushButton3->show();
162 GroupPoints->LineEdit3->show();
170 //=================================================================================
171 // function : ClickOnOk()
173 //=================================================================================
174 void GenerationGUI_PipeDlg::ClickOnOk()
180 //=================================================================================
181 // function : ClickOnApply()
183 //=================================================================================
184 bool GenerationGUI_PipeDlg::ClickOnApply()
190 if ( getConstructorId() != 1 )
191 ConstructorsClicked( getConstructorId() );
192 // activate selection and connect selection manager
193 GroupPoints->PushButton1->click();
197 //=================================================================================
198 // function : SelectionIntoArgument()
199 // purpose : Called when selection is changed or on dialog initialization or activation
200 //=================================================================================
201 void GenerationGUI_PipeDlg::SelectionIntoArgument()
204 myEditCurrentArgument->setText("");
205 if (myEditCurrentArgument == GroupPoints->LineEdit1) myOkBase = false;
206 else if (myEditCurrentArgument == GroupPoints->LineEdit2) myOkPath = false;
207 else if (myEditCurrentArgument == GroupPoints->LineEdit3) myOkVec = false;
209 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
210 SALOME_ListIO aSelList;
211 aSelMgr->selectedObjects(aSelList);
213 if (aSelList.Extent() != 1)
217 Standard_Boolean testResult = Standard_False;
218 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
220 if (!testResult || aSelectedObject->_is_nil())
224 if (!GEOMBase::GetShape(aSelectedObject, S))
227 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
228 if (S.ShapeType() == TopAbs_COMPSOLID ||
229 S.ShapeType() == TopAbs_COMPOUND ||
230 S.ShapeType() == TopAbs_SOLID ||
231 S.ShapeType() == TopAbs_SHAPE)
233 if ( getConstructorId() == 1 &&
234 (S.ShapeType() == TopAbs_SHELL ||
235 S.ShapeType() == TopAbs_VERTEX))
238 myBase = aSelectedObject;
239 myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject));
242 GroupPoints->PushButton2->click();
244 GroupPoints->PushButton3->click();
246 else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
247 myEditCurrentArgument == GroupPoints->LineEdit3) {
248 myEditCurrentArgument == GroupPoints->LineEdit2 ? myOkPath = false : myOkVec = false;
250 QString aName = GEOMBase::GetName(aSelectedObject);
252 if (aSelectedObject != myBase) {
253 TColStd_IndexedMapOfInteger aMap;
254 aSelMgr->GetIndexes(aSelList.First(), aMap);
255 if (aMap.Extent() == 1) {
256 int anIndex = aMap(1);
257 aName.append(":edge_" + QString::number(anIndex));
259 //Find SubShape Object in Father
260 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
262 if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
263 GEOM::GEOM_IShapesOperations_var aShapesOp =
264 getGeomEngine()->GetIShapesOperations(getStudyId());
265 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
268 else { // get Object from study
269 aSelectedObject = aFindedObject;
275 if (S.ShapeType() != TopAbs_EDGE) {
276 aSelectedObject = GEOM::GEOM_Object::_nil();
281 if (myEditCurrentArgument == GroupPoints->LineEdit2) {
282 myPath = aSelectedObject;
285 else if (myEditCurrentArgument == GroupPoints->LineEdit3) {
286 myVec = aSelectedObject;
290 myEditCurrentArgument->setText(aName);
293 GroupPoints->PushButton1->click();
295 GroupPoints->PushButton3->click();
299 GroupPoints->PushButton1->click();
301 GroupPoints->PushButton2->click();
306 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
307 myGeomGUI->getApp()->selectionMgr()->clearSelected();
308 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
309 this, SLOT(SelectionIntoArgument()));
314 //=================================================================================
315 // function : SetEditCurrentArgument()
317 //=================================================================================
318 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
320 QPushButton* send = (QPushButton*)sender();
322 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
323 globalSelection(GEOM_ALLSHAPES);
324 GroupPoints->PushButton1->setDown(false);
325 GroupPoints->PushButton2->setDown(false);
326 GroupPoints->PushButton3->setDown(false);
327 GroupPoints->LineEdit1->setEnabled(false);
328 GroupPoints->LineEdit2->setEnabled(false);
329 GroupPoints->LineEdit3->setEnabled(false);
330 if (send == GroupPoints->PushButton1) {
331 myEditCurrentArgument = GroupPoints->LineEdit1;
333 else if (send == GroupPoints->PushButton2) {
334 myEditCurrentArgument = GroupPoints->LineEdit2;
336 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
338 else if(send == GroupPoints->PushButton3) {
339 myEditCurrentArgument = GroupPoints->LineEdit3;
341 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
343 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
344 this, SLOT(SelectionIntoArgument()));
347 myEditCurrentArgument->setEnabled(true);
348 myEditCurrentArgument->setFocus();
349 // after setFocus(), because it will be setDown(false) when loses focus
352 // seems we need it only to avoid preview disappearing, caused by selection mode change
356 //=================================================================================
357 // function : LineEditReturnPressed()
359 //=================================================================================
360 void GenerationGUI_PipeDlg::LineEditReturnPressed()
362 QLineEdit* send = (QLineEdit*)sender();
363 if (send == GroupPoints->LineEdit1 ||
364 send == GroupPoints->LineEdit2 ||
365 send == GroupPoints->LineEdit3) {
366 myEditCurrentArgument = send;
367 GEOMBase_Skeleton::LineEditReturnPressed();
371 //=================================================================================
372 // function : ActivateThisDialog()
374 //=================================================================================
375 void GenerationGUI_PipeDlg::ActivateThisDialog()
377 GEOMBase_Skeleton::ActivateThisDialog();
379 // reinit, because some selected objects could be removed
383 //=================================================================================
384 // function : enterEvent()
385 // purpose : when mouse enter onto the QWidget
386 //=================================================================================
387 void GenerationGUI_PipeDlg::enterEvent (QEvent*)
389 if (!mainFrame()->GroupConstructors->isEnabled())
390 ActivateThisDialog();
393 //=================================================================================
394 // function : createOperation
396 //=================================================================================
397 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
399 return getGeomEngine()->GetI3DPrimOperations(getStudyId());
402 //=================================================================================
403 // function : isValid
405 //=================================================================================
406 bool GenerationGUI_PipeDlg::isValid (QString&)
408 switch ( getConstructorId() ) {
410 return myOkBase && myOkPath;
412 return myOkBase && myOkPath && myOkVec;
416 //=================================================================================
417 // function : execute
419 //=================================================================================
420 bool GenerationGUI_PipeDlg::execute (ObjectList& objects)
422 GEOM::GEOM_Object_var anObj;
424 switch ( getConstructorId() ) {
426 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->MakePipe(myBase, myPath);
429 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
430 MakePipeBiNormalAlongVector(myBase, myPath, myVec);
434 if (!anObj->_is_nil())
435 objects.push_back(anObj._retn());
440 //=================================================================================
441 // function : addSubshapeToStudy
442 // purpose : virtual method to add new SubObjects if local selection
443 //=================================================================================
444 void GenerationGUI_PipeDlg::addSubshapesToStudy()
446 QMap<QString, GEOM::GEOM_Object_var> objMap;
448 objMap[GroupPoints->LineEdit2->text()] = myPath;
450 addSubshapesToFather(objMap);