1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 CEA
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : BlocksGUI_ExplodeDlg.cxx
24 // Author : Julia DOROVSKIKH
28 #include "BlocksGUI_ExplodeDlg.h"
30 #include "DlgRef_SpinBox.h"
32 #include "GEOM_Displayer.h"
34 #include "SUIT_Session.h"
35 #include "SalomeApp_Application.h"
36 #include "LightApp_SelectionMgr.h"
37 #include "OCCViewer_ViewModel.h"
38 #include "SALOME_ListIteratorOfListIO.hxx"
40 #include "utilities.h"
42 #include <TColStd_IndexedMapOfInteger.hxx>
44 #include <qmessagebox.h>
45 #include <qtextedit.h>
46 #include <qcheckbox.h>
49 //=================================================================================
50 // class : BlocksGUI_ExplodeDlg()
51 // purpose : Constructs a BlocksGUI_ExplodeDlg which is a child of 'parent'.
52 //=================================================================================
53 BlocksGUI_ExplodeDlg::BlocksGUI_ExplodeDlg (GeometryGUI* theGeometryGUI, QWidget* parent, bool modal)
54 : GEOMBase_Skeleton(theGeometryGUI, parent, "ExplodeDlg", modal,
55 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
57 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_BLOCK_EXPLODE")));
58 QPixmap imageS (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
60 setCaption(tr("GEOM_BLOCK_EXPLODE_TITLE"));
62 /***************************************************************/
63 GroupConstructors->setTitle(tr("GEOM_BLOCK_EXPLODE"));
65 RadioButton1->setPixmap(image1);
66 RadioButton2->close(TRUE);
67 RadioButton3->close(TRUE);
70 myGrp1 = new QGroupBox(1, Qt::Horizontal, tr("GEOM_ARGUMENTS"), this);
72 QGroupBox* aSelGrp = new QGroupBox(3, Qt::Horizontal, myGrp1);
73 aSelGrp->setFrameStyle(QFrame::NoFrame);
74 aSelGrp->setInsideMargin(0);
76 new QLabel(tr("GEOM_MAIN_OBJECT"), aSelGrp);
77 mySelBtn = new QPushButton(aSelGrp);
78 mySelBtn->setPixmap(imageS);
79 mySelName = new QLineEdit(aSelGrp);
80 mySelName->setReadOnly(true);
82 QGroupBox* aSpinGrp = new QGroupBox(2, Qt::Horizontal, myGrp1);
83 aSpinGrp->setFrameStyle(QFrame::NoFrame);
84 aSpinGrp->setInsideMargin(0);
86 new QLabel(tr("NB_FACES_MIN"), aSpinGrp);
87 mySpinBoxMin = new DlgRef_SpinBox(aSpinGrp);
89 new QLabel(tr("NB_FACES_MAX"), aSpinGrp);
90 mySpinBoxMax = new DlgRef_SpinBox(aSpinGrp);
92 QGroupBox* anInfoGrp = new QGroupBox(2, Qt::Horizontal, myGrp1);
93 anInfoGrp->setFrameStyle(QFrame::NoFrame);
94 anInfoGrp->setInsideMargin(0);
96 myBlocksNb = new QTextEdit(anInfoGrp);
97 myBlocksNb->setReadOnly(true);
99 QGroupBox* aCheckGrp = new QGroupBox(3, Qt::Horizontal, myGrp1);
100 aCheckGrp->setFrameStyle(QFrame::NoFrame);
101 aCheckGrp->setInsideMargin(0);
103 myCheckBtn = new QCheckBox(aCheckGrp, "CheckButton1");
104 myCheckBtn->setText(tr("GEOM_SUBSHAPE_SELECT"));
106 // Add groups to layout
107 Layout1->addWidget(myGrp1, 1, 0);
108 /***************************************************************/
110 setHelpFileName("explode_on_blocks.htm");
115 //=================================================================================
116 // function : ~BlocksGUI_ExplodeDlg()
117 // purpose : Destroys the object and frees any allocated resources
118 //=================================================================================
119 BlocksGUI_ExplodeDlg::~BlocksGUI_ExplodeDlg()
121 // no need to delete child widgets, Qt does it all for us
125 //=================================================================================
128 //=================================================================================
129 void BlocksGUI_ExplodeDlg::Init()
131 // Set range of spinboxes
132 double SpecificStep = 1.0;
133 mySpinBoxMin->RangeStepAndValidator(0.0, 999.0, SpecificStep, 3);
134 mySpinBoxMax->RangeStepAndValidator(0.0, 999.0, SpecificStep, 3);
136 if (SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
137 != OCCViewer_Viewer::Type())
138 myCheckBtn->setEnabled(false);
140 // signals and slots connections
141 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
142 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
144 connect(mySelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146 connect(mySpinBoxMin, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
147 connect(mySpinBoxMax, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
149 connect(myCheckBtn, SIGNAL(stateChanged(int)), this, SLOT(SubShapeToggled()));
151 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
152 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
154 myConstructorId = -1;
155 ConstructorsClicked(0);
158 //=================================================================================
159 // function : ConstructorsClicked()
160 // purpose : Radio button management
161 //=================================================================================
162 void BlocksGUI_ExplodeDlg::ConstructorsClicked (int constructorId)
164 if (myConstructorId == constructorId)
167 myConstructorId = constructorId;
169 switch (constructorId) {
172 mySpinBoxMin->SetValue(6.0);
173 mySpinBoxMax->SetValue(6.0);
174 myCheckBtn->setChecked(FALSE);
181 myEditCurrentArgument = mySelName;
182 myObject = GEOM::GEOM_Object::_nil();
187 //=================================================================================
188 // function : ClickOnOk()
190 //=================================================================================
191 void BlocksGUI_ExplodeDlg::ClickOnOk()
197 //=================================================================================
198 // function : ClickOnApply()
200 //=================================================================================
201 bool BlocksGUI_ExplodeDlg::ClickOnApply()
203 SUIT_Session::session()->activeApplication()->putInfo(tr(""));
205 // Explode all sub shapes
206 if (isAllSubShapes()) {
207 // More than 30 subshapes : ask confirmation
208 if (myNbBlocks > 30) {
209 const QString caption = tr("GEOM_CONFIRM");
210 const QString text = tr("GEOM_CONFIRM_INFO").arg(myNbBlocks);
211 const QString button0 = tr("GEOM_BUT_EXPLODE");
212 const QString button1 = tr("GEOM_BUT_CANCEL");
214 if (QMessageBox::warning(this, caption, text, button0, button1) != 0)
215 return false; /* aborted */
227 //=================================================================================
228 // function : SelectionIntoArgument()
229 // purpose : Called when selection has changed
230 //=================================================================================
231 void BlocksGUI_ExplodeDlg::SelectionIntoArgument()
233 if (!isAllSubShapes())
236 myObject = GEOM::GEOM_Object::_nil();
237 mySelName->setText("");
239 if (IObjectCount() == 1) {
240 Standard_Boolean aResult = Standard_False;
241 GEOM::GEOM_Object_var anObj =
242 GEOMBase::ConvertIOinGEOMObject(firstIObject(), aResult);
244 if ( aResult && !anObj->_is_nil() && GEOMBase::IsShape( anObj ) ) {
246 mySelName->setText(GEOMBase::GetName(anObj));
253 //=================================================================================
254 // function : SetEditCurrentArgument()
256 //=================================================================================
257 void BlocksGUI_ExplodeDlg::SetEditCurrentArgument()
259 QPushButton* aSender = (QPushButton*)sender();
261 if (mySelBtn == aSender) {
262 mySelName->setFocus();
263 myEditCurrentArgument = mySelName;
264 myCheckBtn->setChecked(FALSE);
270 //=================================================================================
271 // function : ActivateThisDialog()
273 //=================================================================================
274 void BlocksGUI_ExplodeDlg::ActivateThisDialog()
276 GEOMBase_Skeleton::ActivateThisDialog();
277 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
278 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
283 //=================================================================================
284 // function : enterEvent()
286 //=================================================================================
287 void BlocksGUI_ExplodeDlg::enterEvent (QEvent* e)
289 if (!GroupConstructors->isEnabled())
290 this->ActivateThisDialog();
293 //=================================================================================
294 // function : ValueChangedInSpinBox()
296 //=================================================================================
297 void BlocksGUI_ExplodeDlg::ValueChangedInSpinBox (double newValue)
299 if (!isAllSubShapes())
305 //=================================================================================
306 // function : SubShapeToggled()
307 // purpose : Allow user selection of all or only selected sub shapes
308 // : Called when 'myCheckBtn' state change
309 //=================================================================================
310 void BlocksGUI_ExplodeDlg::SubShapeToggled()
315 //=================================================================================
316 // function : activateSelection
317 // purpose : Redisplay preview and Activate selection
318 //=================================================================================
319 void BlocksGUI_ExplodeDlg::activateSelection()
324 if (isAllSubShapes()) { // Sub-shapes selection disabled
325 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
326 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
327 globalSelection( GEOM_ALLSHAPES );
328 if (myObject->_is_nil()) {
329 SelectionIntoArgument();
331 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
332 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
334 displayPreview(true, true, false);
335 globalSelection(GEOM_PREVIEW);
339 //=================================================================================
340 // function : updateButtonState
342 //=================================================================================
343 void BlocksGUI_ExplodeDlg::updateButtonState()
345 if (SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
346 != OCCViewer_Viewer::Type() || myObject->_is_nil()) {
347 myCheckBtn->setChecked(FALSE);
348 myCheckBtn->setEnabled(FALSE);
350 myCheckBtn->setEnabled(TRUE);
355 if (myObject->_is_nil()) {
356 myBlocksNb->setText("");
358 bool isOnlyBlocks = GEOM::GEOM_IBlocksOperations::_narrow
359 (getOperation())->IsCompoundOfBlocks(myObject,
360 (int)mySpinBoxMin->GetValue(),
361 (int)mySpinBoxMax->GetValue(),
364 myBlocksNb->setText(tr("GEOM_NB_BLOCKS_NO_OTHERS").arg(myNbBlocks));
366 myBlocksNb->setText(tr("GEOM_NB_BLOCKS_SOME_OTHERS").arg(myNbBlocks));
370 //=================================================================================
371 // function : isAllSubShapes
373 //=================================================================================
374 bool BlocksGUI_ExplodeDlg::isAllSubShapes() const
376 return !myCheckBtn->isChecked() || !myCheckBtn->isEnabled();
379 //=================================================================================
380 // function : createOperation
382 //=================================================================================
383 GEOM::GEOM_IOperations_ptr BlocksGUI_ExplodeDlg::createOperation()
385 return getGeomEngine()->GetIBlocksOperations(getStudyId());
388 //=================================================================================
389 // function : isValid()
390 // purpose : Verify validity of input data
391 //=================================================================================
392 bool BlocksGUI_ExplodeDlg::isValid (QString&)
394 switch (getConstructorId()) {
397 return !myObject->_is_nil();
399 return !myObject->_is_nil() && (isAllSubShapes() || IObjectCount());
407 //=================================================================================
408 // function : execute
410 //=================================================================================
411 bool BlocksGUI_ExplodeDlg::execute (ObjectList& objects)
413 GEOM::ListOfGO_var aList;
415 switch (getConstructorId()) {
417 aList = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->ExplodeCompoundOfBlocks
419 (int)mySpinBoxMin->GetValue(),
420 (int)mySpinBoxMax->GetValue());
424 if (!aList->length())
430 // Store objects. They will be put in study when "Apply" is pressed
431 for (int i = 0, n = aList->length(); i < n; i++) {
432 objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
433 myTmpObjs.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
436 return objects.size() ? true : false;
439 // Throw away sub-shapes not selected by user if not in preview mode
440 // and manual selection is active
441 if (!isAllSubShapes())
443 QMap<QString, char> selected;
445 // Get names of selected objects
446 SALOME_ListIteratorOfListIO it (selectedIO());
447 for (; it.More(); it.Next()) {
448 selected.insert(it.Value()->getName(), 0);
451 // Iterate through result and select objects with names from selection
452 ObjectList toRemoveFromEnggine;
453 ObjectList::iterator anIter;
454 for (anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter) {
455 CORBA::String_var objStr = myGeomGUI->getApp()->orb()->object_to_string(*anIter);
456 if (selected.contains(QString(objStr.in())))
457 objects.push_back(*anIter);
459 toRemoveFromEnggine.push_back(*anIter);
462 // Remove from engine useless objects
463 ObjectList::iterator anIter2 = toRemoveFromEnggine.begin();
464 for (; anIter2 != toRemoveFromEnggine.end(); ++anIter2)
465 getGeomEngine()->RemoveObject(*anIter2);
470 for (int i = 0, n = aList->length(); i < n; i++)
471 objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
474 return objects.size();
477 //=================================================================================
478 // function : clearTemporary
479 // purpose : Remove temporary objects from engine
480 //=================================================================================
481 void BlocksGUI_ExplodeDlg::clearTemporary()
483 ObjectList::iterator anIter;
484 for (anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter)
485 getGeomEngine()->RemoveObject(*anIter);
490 //================================================================
491 // Function : getFather
492 // Purpose : Get father object for object to be added in study
493 // ( called with addInStudy method )
494 //================================================================
495 GEOM::GEOM_Object_ptr BlocksGUI_ExplodeDlg::getFather (GEOM::GEOM_Object_ptr)
500 //================================================================
501 // Function : getNewObjectName
502 // Purpose : Redefine this method to return proper name for a new object
503 //================================================================
504 const char* BlocksGUI_ExplodeDlg::getNewObjectName() const