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")));
71 setCaption(tr("GEOM_PIPE_TITLE"));
73 /***************************************************************/
74 GroupConstructors->setTitle(tr("GEOM_PIPE"));
75 RadioButton1->setPixmap(image0);
76 RadioButton2->close(TRUE);
77 RadioButton3->close(TRUE);
79 GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
80 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
81 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_OBJECT"));
82 GroupPoints->TextLabel2->setText(tr("GEOM_PATH_OBJECT"));
83 GroupPoints->PushButton1->setPixmap(image1);
84 GroupPoints->PushButton2->setPixmap(image1);
85 GroupPoints->LineEdit1->setReadOnly( true );
86 GroupPoints->LineEdit2->setReadOnly( true );
88 Layout1->addWidget(GroupPoints, 2, 0);
89 /***************************************************************/
91 setHelpFileName("create_extrusion_alongpath_page.html");
98 //=================================================================================
99 // function : ~GenerationGUI_PipeDlg()
100 // purpose : Destroys the object and frees any allocated resources
101 //=================================================================================
102 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
104 /* no need to delete child widgets, Qt does it all for us */
108 //=================================================================================
111 //=================================================================================
112 void GenerationGUI_PipeDlg::Init()
115 myEditCurrentArgument = GroupPoints->LineEdit1;
116 GroupPoints->LineEdit1->setReadOnly( true );
117 GroupPoints->LineEdit2->setReadOnly( true );
119 myOkBase = myOkPath = false;
121 /* signals and slots connections */
122 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
123 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
125 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
126 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
128 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
129 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
131 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
132 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
134 initName(tr("GEOM_PIPE"));
136 // globalSelection( GEOM_ALLSHAPES );
140 //=================================================================================
141 // function : ClickOnOk()
143 //=================================================================================
144 void GenerationGUI_PipeDlg::ClickOnOk()
146 if ( ClickOnApply() )
151 //=================================================================================
152 // function : ClickOnAply()
154 //=================================================================================
155 bool GenerationGUI_PipeDlg::ClickOnApply()
165 //=================================================================================
166 // function : SelectionIntoArgument()
167 // purpose : Called when selection has changed
168 //=================================================================================
169 void GenerationGUI_PipeDlg::SelectionIntoArgument()
172 myEditCurrentArgument->setText("");
174 if(IObjectCount() != 1) {
175 if(myEditCurrentArgument == GroupPoints->LineEdit1)
177 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
183 Standard_Boolean testResult = Standard_False;
184 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
191 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
194 if(!GEOMBase::GetShape(aSelectedObject, S) ||
195 S.ShapeType() == TopAbs_COMPSOLID ||
196 S.ShapeType() == TopAbs_COMPOUND ||
197 S.ShapeType() == TopAbs_SOLID ||
198 S.ShapeType() == TopAbs_SHAPE)
201 myBase = aSelectedObject;
202 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
205 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
208 if( !GEOMBase::GetShape(aSelectedObject, S) )
211 QString aName = GEOMBase::GetName( aSelectedObject );
213 if ( testResult && !aSelectedObject->_is_nil() && aSelectedObject != myBase)
215 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
216 TColStd_IndexedMapOfInteger aMap;
218 aSelMgr->GetIndexes( firstIObject(), aMap );
219 if ( aMap.Extent() == 1 )
221 int anIndex = aMap( 1 );
222 aName.append( ":edge_" + QString::number( anIndex ) );
224 //Find SubShape Object in Father
225 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
227 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
228 GEOM::GEOM_IShapesOperations_var aShapesOp =
229 getGeomEngine()->GetIShapesOperations( getStudyId() );
230 myPath = aShapesOp->GetSubShape(aSelectedObject, anIndex);
233 else { // get Object from study
234 myPath = aFindedObject;
240 if (S.ShapeType() != TopAbs_EDGE) {
241 aSelectedObject = GEOM::GEOM_Object::_nil();
245 myPath = aSelectedObject;
248 myEditCurrentArgument->setText( aName );
255 //=================================================================================
256 // function : SetEditCurrentArgument()
258 //=================================================================================
259 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
261 QPushButton* send = (QPushButton*)sender();
264 if(send == GroupPoints->PushButton1) {
265 GroupPoints->LineEdit1->setFocus();
266 globalSelection( GEOM_ALLSHAPES );
267 myEditCurrentArgument = GroupPoints->LineEdit1;
269 else if(send == GroupPoints->PushButton2) {
270 GroupPoints->LineEdit2->setFocus();
271 myEditCurrentArgument = GroupPoints->LineEdit2;
273 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
275 SelectionIntoArgument();
279 //=================================================================================
280 // function : LineEditReturnPressed()
282 //=================================================================================
283 void GenerationGUI_PipeDlg::LineEditReturnPressed()
285 QLineEdit* send = (QLineEdit*)sender();
286 if(send == GroupPoints->LineEdit1 ||
287 send == GroupPoints->LineEdit2)
289 myEditCurrentArgument = send;
290 GEOMBase_Skeleton::LineEditReturnPressed();
295 //=================================================================================
296 // function : enterEvent()
297 // purpose : when mouse enter onto the QWidget
298 //=================================================================================
299 void GenerationGUI_PipeDlg::enterEvent(QEvent* e)
301 if ( !GroupConstructors->isEnabled() )
302 ActivateThisDialog();
306 //=================================================================================
307 // function : ActivateThisDialog()
309 //=================================================================================
310 void GenerationGUI_PipeDlg::ActivateThisDialog()
312 GEOMBase_Skeleton::ActivateThisDialog();
313 globalSelection( GEOM_ALLSHAPES );
314 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
315 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
320 //=================================================================================
321 // function : createOperation
323 //=================================================================================
324 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
326 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
329 //=================================================================================
330 // function : isValid
332 //=================================================================================
333 bool GenerationGUI_PipeDlg::isValid( QString& )
335 return myOkBase && myOkPath;
338 //=================================================================================
339 // function : execute
341 //=================================================================================
342 bool GenerationGUI_PipeDlg::execute( ObjectList& objects )
344 GEOM::GEOM_Object_var anObj;
346 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
347 getOperation() )->MakePipe( myBase, myPath );
349 if ( !anObj->_is_nil() )
350 objects.push_back( anObj._retn() );
355 //=================================================================================
356 // function : addSubshapeToStudy
357 // purpose : virtual method to add new SubObjects if local selection
358 //=================================================================================
359 void GenerationGUI_PipeDlg::addSubshapesToStudy()
361 QMap<QString, GEOM::GEOM_Object_var> objMap;
363 objMap[GroupPoints->LineEdit2->text()] = myPath;
365 addSubshapesToFather( objMap );