1 // Copyright (C) 2007-2013 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GenerationGUI_PipeDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "GenerationGUI_PipeDlg.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
38 #include <TopoDS_Shape.hxx>
41 #include <TColStd_IndexedMapOfInteger.hxx>
42 #include <TopTools_IndexedMapOfShape.hxx>
43 #include <TColStd_IndexedMapOfInteger.hxx>
44 #include <TColStd_MapOfInteger.hxx>
46 #include <GEOMImpl_Types.hxx>
48 //=================================================================================
49 // class : GenerationGUI_PipeDlg()
50 // purpose : Constructs a GenerationGUI_PipeDlg which is a child of 'parent', with the
51 // name 'name' and widget flags set to 'f'.
52 // The dialog will by default be modeless, unless you set 'modal' to
53 // TRUE to construct a modal dialog.
54 //=================================================================================
55 GenerationGUI_PipeDlg::GenerationGUI_PipeDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
56 bool modal, Qt::WindowFlags fl)
57 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl)
59 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PIPE")));
60 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
61 QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PIPE_BINORMAL")));
62 QPixmap image3 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PIPE_SECTION")));
64 setWindowTitle(tr("GEOM_PIPE_TITLE"));
66 /***************************************************************/
67 mainFrame()->GroupConstructors->setTitle(tr("GEOM_PIPE"));
68 mainFrame()->RadioButton1->setIcon(image0);
69 mainFrame()->RadioButton2->setIcon(image2);
70 mainFrame()->RadioButton3->setIcon(image3);
71 // mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
72 // mainFrame()->RadioButton3->close();
74 GroupPoints = new DlgRef_3Sel1Check(centralWidget());
76 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
77 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_OBJECT"));
78 GroupPoints->TextLabel2->setText(tr("GEOM_PATH_OBJECT"));
79 GroupPoints->TextLabel3->setText(tr("GEOM_BINORMAL"));
80 GroupPoints->PushButton1->setIcon(image1);
81 GroupPoints->PushButton2->setIcon(image1);
82 GroupPoints->PushButton3->setIcon(image1);
83 GroupPoints->CheckButton1->setText(tr("GEOM_SELECT_UNPUBLISHED_EDGES"));
85 GroupMakePoints = new DlgRef_3Sel2Check3Spin(centralWidget());
87 GroupMakePoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
88 GroupMakePoints->TextLabel1->setText(tr("GEOM_BASE_OBJECT"));
89 GroupMakePoints->TextLabel2->setText(tr("GEOM_LOCATIONS"));
90 GroupMakePoints->TextLabel3->setText(tr("GEOM_PATH_OBJECT"));
91 GroupMakePoints->PushButton1->setIcon(image1);
92 GroupMakePoints->PushButton2->setIcon(image1);
93 GroupMakePoints->PushButton3->setIcon(image1);
94 GroupMakePoints->CheckBox1->setText(tr("GEOM_WITH_CONTACT"));
95 GroupMakePoints->CheckBox2->setText(tr("GEOM_WITH_CORRECTION"));
96 GroupMakePoints->SpinBox1->close();
97 GroupMakePoints->SpinBox2->close();
98 GroupMakePoints->SpinBox3->close();
99 GroupMakePoints->TextLabel4->close();
100 GroupMakePoints->TextLabel5->close();
101 GroupMakePoints->TextLabel6->close();
103 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
104 layout->setMargin(0); layout->setSpacing(6);
105 layout->addWidget(GroupPoints);
106 layout->addWidget(GroupMakePoints);
107 /***************************************************************/
109 setHelpFileName("create_extrusion_alongpath_page.html");
115 //=================================================================================
116 // function : ~GenerationGUI_PipeDlg()
117 // purpose : Destroys the object and frees any allocated resources
118 //=================================================================================
119 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
121 // no need to delete child widgets, Qt does it all for us
124 //=================================================================================
127 //=================================================================================
128 void GenerationGUI_PipeDlg::Init()
131 GroupPoints->LineEdit1->setReadOnly(true);
132 GroupPoints->LineEdit2->setReadOnly(true);
133 GroupPoints->LineEdit3->setReadOnly(true);
135 GroupPoints->LineEdit1->setText("");
136 GroupPoints->LineEdit2->setText("");
137 GroupPoints->LineEdit3->setText("");
141 GroupPoints->CheckButton1->setEnabled(false);
143 GroupMakePoints->LineEdit1->setReadOnly(true);
144 GroupMakePoints->LineEdit2->setReadOnly(true);
145 GroupMakePoints->LineEdit3->setReadOnly(true);
147 GroupMakePoints->LineEdit1->setText("");
148 GroupMakePoints->LineEdit2->setText("");
149 GroupMakePoints->LineEdit3->setText("");
151 showOnlyPreviewControl();
153 // signals and slots connections
154 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
155 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
157 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
159 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
160 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
161 connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
163 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(SelectionTypeButtonClicked()));
165 connect(GroupMakePoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
166 connect(GroupMakePoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
167 connect(GroupMakePoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
169 initName(tr("GEOM_PIPE"));
172 GroupPoints->TextLabel3->hide();
173 GroupPoints->PushButton3->hide();
174 GroupPoints->LineEdit3->hide();
175 ConstructorsClicked(0);
177 GroupPoints->PushButton1->click();
178 SelectionIntoArgument();
181 //=================================================================================
182 // function : ConstructorsClicked()
183 // purpose : Radio button management
184 //=================================================================================
185 void GenerationGUI_PipeDlg::ConstructorsClicked( int constructorId )
189 switch (constructorId) {
191 GroupMakePoints->hide();
193 GroupPoints->TextLabel3->hide();
194 GroupPoints->PushButton3->hide();
195 GroupPoints->LineEdit3->hide();
196 GroupPoints->PushButton1->click();
199 GroupMakePoints->hide();
201 GroupPoints->TextLabel3->show();
202 GroupPoints->PushButton3->show();
203 GroupPoints->LineEdit3->show();
204 GroupPoints->PushButton1->click();
208 GroupMakePoints->show();
209 GroupMakePoints->PushButton1->click();
215 qApp->processEvents();
219 SelectionIntoArgument();
223 //=================================================================================
224 // function : SelectionBittonClicked()
225 // purpose : Selection type Radio button management
226 //=================================================================================
227 void GenerationGUI_PipeDlg::SelectionTypeButtonClicked()
230 if ( GroupPoints->CheckButton1->isChecked() ) {
231 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
233 TColStd_MapOfInteger aMap;
234 aMap.Add(GEOM_COMPOUND);
237 globalSelection(aMap);
239 if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
240 myEditCurrentArgument->setText("");
246 //=================================================================================
247 // function : ClickOnOk()
249 //=================================================================================
250 void GenerationGUI_PipeDlg::ClickOnOk()
252 setIsApplyAndClose( true );
257 //=================================================================================
258 // function : ClickOnApply()
260 //=================================================================================
261 bool GenerationGUI_PipeDlg::ClickOnApply()
267 if ( getConstructorId() != 1 )
268 ConstructorsClicked( getConstructorId() );
269 // activate selection and connect selection manager
270 // GroupPoints->PushButton1->click();
274 //=================================================================================
275 // function : SelectionIntoArgument()
276 // purpose : Called when selection is changed or on dialog initialization or activation
277 //=================================================================================
278 void GenerationGUI_PipeDlg::SelectionIntoArgument()
281 myEditCurrentArgument->setText("");
283 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
284 myBaseObjects.clear();
285 QList<GEOM::GeomObjPtr> objects = getSelected( TopAbs_SHAPE, -1 );
286 for ( int i = 0; i < objects.count(); i++ ) {
287 GEOM::shape_type stype = objects[i]->GetMaxShapeType();
288 GEOM::shape_type maxallowed = getConstructorId() == 1 ? GEOM::FACE : GEOM::SHELL;
289 GEOM::shape_type minallowed = getConstructorId() == 1 ? GEOM::EDGE : GEOM::VERTEX;
290 if ( stype < maxallowed || stype > minallowed )
292 myBaseObjects << objects[i];
294 if ( !myBaseObjects.isEmpty() ) {
295 QString aName = myBaseObjects.count() > 1 ? QString( "%1_objects").arg( myBaseObjects.count() ) : GEOMBase::GetName( myBaseObjects[0].get() );
296 myEditCurrentArgument->setText( aName );
299 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
300 QList<TopAbs_ShapeEnum> types;
301 types << TopAbs_EDGE << TopAbs_WIRE;
302 myPath = getSelected( types );
304 QString aName = GEOMBase::GetName( myPath.get() );
305 myEditCurrentArgument->setText( aName );
306 if ( getConstructorId() == 1 && !myVec )
307 GroupPoints->PushButton3->click();
308 else if ( myBaseObjects.isEmpty() )
309 GroupPoints->PushButton1->click();
312 else if (myEditCurrentArgument == GroupPoints->LineEdit3) {
313 myVec = getSelected( TopAbs_EDGE );
315 QString aName = GEOMBase::GetName( myVec.get() );
316 myEditCurrentArgument->setText( aName );
317 if ( myBaseObjects.isEmpty() )
318 GroupPoints->PushButton1->click();
320 GroupPoints->PushButton2->click();
323 else if ( myEditCurrentArgument == GroupMakePoints->LineEdit1 ) {
324 myBaseObjects.clear();
325 QList<GEOM::GeomObjPtr> objects = getSelected( TopAbs_SHAPE, -1 );
326 for ( int i = 0; i < objects.count(); i++ ) {
327 GEOM::shape_type stype = objects[i]->GetMaxShapeType();
328 if ( stype < GEOM::SHELL || stype > GEOM::VERTEX )
330 myBaseObjects << objects[i];
332 if ( !myBaseObjects.isEmpty() ) {
333 QString aName = myBaseObjects.count() > 1 ? QString( "%1_objects").arg( myBaseObjects.count() ) : GEOMBase::GetName( myBaseObjects[0].get() );
334 myEditCurrentArgument->setText( aName );
337 else if ( myEditCurrentArgument == GroupMakePoints->LineEdit2 ) {
339 QList<GEOM::GeomObjPtr> objects = getSelected( TopAbs_SHAPE, -1 );
340 for ( int i = 0; i < objects.count(); i++ ) {
341 GEOM::shape_type stype = objects[i]->GetMaxShapeType();
342 if ( stype < GEOM::SHELL || stype > GEOM::VERTEX )
344 myLocations << objects[i];
346 if ( !myLocations.isEmpty() ) {
347 QString aName = myLocations.count() > 1 ? QString( "%1_objects").arg( myLocations.count() ) : GEOMBase::GetName( myLocations[0].get() );
348 myEditCurrentArgument->setText( aName );
351 else if ( myEditCurrentArgument == GroupMakePoints->LineEdit3 ) {
352 QList<TopAbs_ShapeEnum> types;
353 types << TopAbs_EDGE << TopAbs_WIRE;
354 myPath = getSelected( types );
356 QString aName = GEOMBase::GetName( myPath.get() );
357 myEditCurrentArgument->setText( aName );
364 //=================================================================================
365 // function : SetEditCurrentArgument()
367 //=================================================================================
368 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
370 QPushButton* send = (QPushButton*)sender();
372 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
373 globalSelection(GEOM_ALLSHAPES);
374 GroupPoints->PushButton1->setDown(false);
375 GroupPoints->PushButton2->setDown(false);
376 GroupPoints->PushButton3->setDown(false);
377 GroupPoints->LineEdit1->setEnabled(false);
378 GroupPoints->LineEdit2->setEnabled(false);
379 GroupPoints->LineEdit3->setEnabled(false);
380 if (send == GroupPoints->PushButton1) {
381 myEditCurrentArgument = GroupPoints->LineEdit1;
382 GroupPoints->CheckButton1->setEnabled(false);
384 else if (send == GroupPoints->PushButton2) {
385 myEditCurrentArgument = GroupPoints->LineEdit2;
387 if ( GroupPoints->CheckButton1->isChecked() ) {
388 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
390 TColStd_MapOfInteger aMap;
391 aMap.Add(GEOM_COMPOUND);
394 globalSelection(aMap);
396 GroupPoints->CheckButton1->setEnabled(true);
398 else if(send == GroupPoints->PushButton3) {
399 myEditCurrentArgument = GroupPoints->LineEdit3;
400 GroupPoints->CheckButton1->setEnabled(false);
401 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
404 GroupMakePoints->PushButton1->setDown(false);
405 GroupMakePoints->PushButton2->setDown(false);
406 GroupMakePoints->PushButton3->setDown(false);
407 GroupMakePoints->LineEdit1->setEnabled(false);
408 GroupMakePoints->LineEdit2->setEnabled(false);
409 GroupMakePoints->LineEdit3->setEnabled(false);
410 if (send == GroupMakePoints->PushButton1) {
411 myEditCurrentArgument = GroupMakePoints->LineEdit1;
413 else if(send == GroupMakePoints->PushButton2) {
414 myEditCurrentArgument = GroupMakePoints->LineEdit2;
416 else if (send == GroupMakePoints->PushButton3) {
417 myEditCurrentArgument = GroupMakePoints->LineEdit3;
420 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
421 this, SLOT(SelectionIntoArgument()));
424 myEditCurrentArgument->setEnabled(true);
425 myEditCurrentArgument->setFocus();
426 // after setFocus(), because it will be setDown(false) when loses focus
429 // seems we need it only to avoid preview disappearing, caused by selection mode change
433 //=================================================================================
434 // function : ActivateThisDialog()
436 //=================================================================================
437 void GenerationGUI_PipeDlg::ActivateThisDialog()
439 GEOMBase_Skeleton::ActivateThisDialog();
440 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
441 this, SLOT( SelectionIntoArgument() ) );
443 ConstructorsClicked(getConstructorId());
446 //=================================================================================
447 // function : enterEvent()
448 // purpose : when mouse enter onto the QWidget
449 //=================================================================================
450 void GenerationGUI_PipeDlg::enterEvent (QEvent*)
452 if (!mainFrame()->GroupConstructors->isEnabled())
453 ActivateThisDialog();
456 //=================================================================================
457 // function : createOperation
459 //=================================================================================
460 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
462 return getGeomEngine()->GetI3DPrimOperations(getStudyId());
465 //=================================================================================
466 // function : isValid
468 //=================================================================================
469 bool GenerationGUI_PipeDlg::isValid (QString&)
472 switch ( getConstructorId() ) {
474 ok = !myBaseObjects.isEmpty() && myPath;
477 ok = !myBaseObjects.isEmpty() && myPath && myVec;
480 ok = !myBaseObjects.isEmpty() && ( myLocations.isEmpty() || myBaseObjects.count() == myLocations.count() ) && myPath;
488 //=================================================================================
489 // function : execute
491 //=================================================================================
492 bool GenerationGUI_PipeDlg::execute (ObjectList& objects)
494 GEOM::GEOM_Object_var anObj;
496 GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
497 switch( getConstructorId() ) {
500 for (int i = 0; i < myBaseObjects.count(); i++) {
501 switch ( getConstructorId() ) {
503 anObj = anOper->MakePipe(myBaseObjects[i].get(), myPath.get());
506 anObj = anOper->MakePipeBiNormalAlongVector(myBaseObjects[i].get(), myPath.get(), myVec.get());
510 if (!anObj->_is_nil())
511 objects.push_back(anObj._retn());
516 GEOM::ListOfGO_var myBaseGO = new GEOM::ListOfGO();
517 GEOM::ListOfGO_var myLocationsGO = new GEOM::ListOfGO();
518 myBaseGO->length( myBaseObjects.count() );
519 myLocationsGO->length( myLocations.count() );
520 for (int i = 0; i < myBaseObjects.count(); i++) {
521 myBaseGO[i] = myBaseObjects[i].copy();
523 for (int i = 0; i < myLocations.count(); i++) {
524 myLocationsGO[i] = myLocations[i].copy();
527 anObj = anOper->MakePipeWithDifferentSections(myBaseGO.in(), myLocationsGO.in(), myPath.get(),
528 GroupMakePoints->CheckBox1->isChecked(),
529 GroupMakePoints->CheckBox2->isChecked());
530 if (!anObj->_is_nil())
531 objects.push_back(anObj._retn());
540 //=================================================================================
541 // function : addSubshapeToStudy
542 // purpose : virtual method to add new SubObjects if local selection
543 //=================================================================================
544 void GenerationGUI_PipeDlg::addSubshapesToStudy()
546 GEOMBase::PublishSubObject( myPath.get() );
547 GEOMBase::PublishSubObject( myVec.get() );
550 //=================================================================================
551 // function : extractPrefix
552 // purpose : redefined from GEOMBase_Helper class
553 //=================================================================================
554 bool GenerationGUI_PipeDlg::extractPrefix() const
556 return myBaseObjects.count() > 1;