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
24 // File : GenerationGUI_PipeDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "GenerationGUI_PipeDlg.h"
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
38 #include <TopoDS_Edge.hxx>
39 #include <TopoDS_Shape.hxx>
42 #include <TColStd_IndexedMapOfInteger.hxx>
43 #include <TopTools_IndexedMapOfShape.hxx>
44 #include <BRepBuilderAPI_MakeWire.hxx>
45 #include <BRepOffsetAPI_MakePipe.hxx>
46 #if OCC_VERSION_MAJOR >= 5
47 #include <BRepAlgo.hxx>
49 #include <BRepAlgoAPI.hxx>
52 #include "GEOMImpl_Types.hxx"
54 #include "utilities.h"
56 //=================================================================================
57 // class : GenerationGUI_PipeDlg()
58 // purpose : Constructs a GenerationGUI_PipeDlg which is a child of 'parent', with the
59 // name 'name' and widget flags set to 'f'.
60 // The dialog will by default be modeless, unless you set 'modal' to
61 // TRUE to construct a modal dialog.
62 //=================================================================================
63 GenerationGUI_PipeDlg::GenerationGUI_PipeDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
64 const char* name, bool modal, WFlags fl)
65 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
66 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
68 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PIPE")));
69 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
70 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PIPE_BINORMAL")));
72 setCaption(tr("GEOM_PIPE_TITLE"));
74 /***************************************************************/
75 GroupConstructors->setTitle(tr("GEOM_PIPE"));
76 RadioButton1->setPixmap(image0);
77 RadioButton2->setPixmap(image2);
78 RadioButton3->close(TRUE);
80 GroupPoints = new DlgRef_3Sel_QTD(this, "GroupPoints");
81 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
82 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_OBJECT"));
83 GroupPoints->TextLabel2->setText(tr("GEOM_PATH_OBJECT"));
84 GroupPoints->TextLabel3->setText(tr("GEOM_VECTOR"));
85 GroupPoints->PushButton1->setPixmap(image1);
86 GroupPoints->PushButton2->setPixmap(image1);
87 GroupPoints->PushButton3->setPixmap(image1);
89 Layout1->addWidget(GroupPoints, 2, 0);
90 /***************************************************************/
92 setHelpFileName("create_extrusion_alongpath_page.html");
99 //=================================================================================
100 // function : ~GenerationGUI_PipeDlg()
101 // purpose : Destroys the object and frees any allocated resources
102 //=================================================================================
103 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
105 /* no need to delete child widgets, Qt does it all for us */
109 //=================================================================================
112 //=================================================================================
113 void GenerationGUI_PipeDlg::Init()
116 myEditCurrentArgument = GroupPoints->LineEdit1;
117 GroupPoints->LineEdit1->setReadOnly( true );
118 GroupPoints->LineEdit2->setReadOnly( true );
120 myOkBase = myOkPath = myOkVec = false;
122 /* signals and slots connections */
123 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
124 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
125 connect(GroupConstructors, SIGNAL(clicked(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(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
136 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
138 initName(tr("GEOM_PIPE"));
140 // globalSelection( GEOM_ALLSHAPES );
142 GroupPoints->TextLabel3->hide();
143 GroupPoints->PushButton3->hide();
144 GroupPoints->LineEdit3->hide();
145 ConstructorsClicked( 0 );
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();
179 //=================================================================================
180 // function : ClickOnOk()
182 //=================================================================================
183 void GenerationGUI_PipeDlg::ClickOnOk()
185 if ( ClickOnApply() )
190 //=================================================================================
191 // function : ClickOnAply()
193 //=================================================================================
194 bool GenerationGUI_PipeDlg::ClickOnApply()
200 if ( getConstructorId() != 1 )
201 ConstructorsClicked( getConstructorId() );
206 //=================================================================================
207 // function : SelectionIntoArgument()
208 // purpose : Called when selection has changed
209 //=================================================================================
210 void GenerationGUI_PipeDlg::SelectionIntoArgument()
213 myEditCurrentArgument->setText("");
215 if(IObjectCount() != 1) {
216 if(myEditCurrentArgument == GroupPoints->LineEdit1)
218 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
220 else if(myEditCurrentArgument == GroupPoints->LineEdit3)
226 Standard_Boolean testResult = Standard_False;
227 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
234 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
237 if(!GEOMBase::GetShape(aSelectedObject, S) ||
238 S.ShapeType() == TopAbs_COMPSOLID ||
239 S.ShapeType() == TopAbs_COMPOUND ||
240 S.ShapeType() == TopAbs_SOLID ||
241 S.ShapeType() == TopAbs_SHAPE)
243 if ( getConstructorId() == 1 &&
244 (S.ShapeType() == TopAbs_SHELL ||
245 S.ShapeType() == TopAbs_VERTEX))
248 myBase = aSelectedObject;
249 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
252 else if(myEditCurrentArgument == GroupPoints->LineEdit2 ||
253 myEditCurrentArgument == GroupPoints->LineEdit3) {
254 myEditCurrentArgument == GroupPoints->LineEdit2 ? myOkPath = false : myOkVec = false;
257 if( !GEOMBase::GetShape(aSelectedObject, S) )
260 QString aName = GEOMBase::GetName( aSelectedObject );
262 if ( testResult && !aSelectedObject->_is_nil() && aSelectedObject != myBase)
264 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
265 TColStd_IndexedMapOfInteger aMap;
267 aSelMgr->GetIndexes( firstIObject(), aMap );
268 if ( aMap.Extent() == 1 )
270 int anIndex = aMap( 1 );
271 aName.append( ":edge_" + QString::number( anIndex ) );
273 //Find SubShape Object in Father
274 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
276 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
277 GEOM::GEOM_IShapesOperations_var aShapesOp =
278 getGeomEngine()->GetIShapesOperations( getStudyId() );
279 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
282 else { // get Object from study
283 aSelectedObject = aFindedObject;
289 if (S.ShapeType() != TopAbs_EDGE) {
290 aSelectedObject = GEOM::GEOM_Object::_nil();
295 if (myEditCurrentArgument == GroupPoints->LineEdit2) {
296 myPath = aSelectedObject;
299 else if (myEditCurrentArgument == GroupPoints->LineEdit3) {
300 myVec = aSelectedObject;
304 myEditCurrentArgument->setText( aName );
311 //=================================================================================
312 // function : SetEditCurrentArgument()
314 //=================================================================================
315 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
317 QPushButton* send = (QPushButton*)sender();
320 if(send == GroupPoints->PushButton1) {
321 GroupPoints->LineEdit1->setFocus();
322 globalSelection( GEOM_ALLSHAPES );
323 myEditCurrentArgument = GroupPoints->LineEdit1;
325 else if(send == GroupPoints->PushButton2) {
326 GroupPoints->LineEdit2->setFocus();
327 myEditCurrentArgument = GroupPoints->LineEdit2;
329 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
331 else if(send == GroupPoints->PushButton3) {
332 GroupPoints->LineEdit3->setFocus();
333 myEditCurrentArgument = GroupPoints->LineEdit3;
335 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
337 SelectionIntoArgument();
341 //=================================================================================
342 // function : LineEditReturnPressed()
344 //=================================================================================
345 void GenerationGUI_PipeDlg::LineEditReturnPressed()
347 QLineEdit* send = (QLineEdit*)sender();
348 if(send == GroupPoints->LineEdit1 ||
349 send == GroupPoints->LineEdit2 ||
350 send == GroupPoints->LineEdit3)
352 myEditCurrentArgument = send;
353 GEOMBase_Skeleton::LineEditReturnPressed();
358 //=================================================================================
359 // function : enterEvent()
360 // purpose : when mouse enter onto the QWidget
361 //=================================================================================
362 void GenerationGUI_PipeDlg::enterEvent(QEvent* e)
364 if ( !GroupConstructors->isEnabled() )
365 ActivateThisDialog();
369 //=================================================================================
370 // function : ActivateThisDialog()
372 //=================================================================================
373 void GenerationGUI_PipeDlg::ActivateThisDialog()
375 GEOMBase_Skeleton::ActivateThisDialog();
376 globalSelection( GEOM_ALLSHAPES );
377 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
378 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
379 ConstructorsClicked(getConstructorId());
383 //=================================================================================
384 // function : createOperation
386 //=================================================================================
387 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
389 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
392 //=================================================================================
393 // function : isValid
395 //=================================================================================
396 bool GenerationGUI_PipeDlg::isValid( QString& )
398 switch ( getConstructorId() ) {
400 return myOkBase && myOkPath;
402 return myOkBase && myOkPath && myOkVec;
406 //=================================================================================
407 // function : execute
409 //=================================================================================
410 bool GenerationGUI_PipeDlg::execute( ObjectList& objects )
412 GEOM::GEOM_Object_var anObj;
414 switch ( getConstructorId() ) {
416 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
417 getOperation() )->MakePipe( myBase, myPath );
421 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
422 getOperation() )->MakePipeBiNormalAlongVector( myBase, myPath, myVec );
426 if ( !anObj->_is_nil() )
427 objects.push_back( anObj._retn() );
432 //=================================================================================
433 // function : addSubshapeToStudy
434 // purpose : virtual method to add new SubObjects if local selection
435 //=================================================================================
436 void GenerationGUI_PipeDlg::addSubshapesToStudy()
438 QMap<QString, GEOM::GEOM_Object_var> objMap;
440 objMap[GroupPoints->LineEdit2->text()] = myPath;
442 addSubshapesToFather( objMap );