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.org
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 "SalomeApp_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 (QWidget* parent,
55 : GEOMBase_Skeleton(parent, "ExplodeDlg", modal,
56 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
58 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_BLOCK_EXPLODE")));
59 QPixmap imageS (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
61 setCaption(tr("GEOM_BLOCK_EXPLODE_TITLE"));
63 /***************************************************************/
64 GroupConstructors->setTitle(tr("GEOM_BLOCK_EXPLODE"));
66 RadioButton1->setPixmap(image1);
67 RadioButton2->close(TRUE);
68 RadioButton3->close(TRUE);
71 myGrp1 = new QGroupBox(1, Qt::Horizontal, tr("GEOM_ARGUMENTS"), this);
73 QGroupBox* aSelGrp = new QGroupBox(3, Qt::Horizontal, myGrp1);
74 aSelGrp->setFrameStyle(QFrame::NoFrame);
75 aSelGrp->setInsideMargin(0);
77 new QLabel(tr("GEOM_MAIN_OBJECT"), aSelGrp);
78 mySelBtn = new QPushButton(aSelGrp);
79 mySelBtn->setPixmap(imageS);
80 mySelName = new QLineEdit(aSelGrp);
81 mySelName->setReadOnly(true);
83 QGroupBox* aSpinGrp = new QGroupBox(2, Qt::Horizontal, myGrp1);
84 aSpinGrp->setFrameStyle(QFrame::NoFrame);
85 aSpinGrp->setInsideMargin(0);
87 new QLabel(tr("NB_FACES_MIN"), aSpinGrp);
88 mySpinBoxMin = new DlgRef_SpinBox(aSpinGrp);
90 new QLabel(tr("NB_FACES_MAX"), aSpinGrp);
91 mySpinBoxMax = new DlgRef_SpinBox(aSpinGrp);
93 QGroupBox* anInfoGrp = new QGroupBox(2, Qt::Horizontal, myGrp1);
94 anInfoGrp->setFrameStyle(QFrame::NoFrame);
95 anInfoGrp->setInsideMargin(0);
97 myBlocksNb = new QTextEdit(anInfoGrp);
98 myBlocksNb->setReadOnly(true);
100 QGroupBox* aCheckGrp = new QGroupBox(3, Qt::Horizontal, myGrp1);
101 aCheckGrp->setFrameStyle(QFrame::NoFrame);
102 aCheckGrp->setInsideMargin(0);
104 myCheckBtn = new QCheckBox(aCheckGrp, "CheckButton1");
105 myCheckBtn->setText(tr("GEOM_SUBSHAPE_SELECT"));
107 // Add groups to layout
108 Layout1->addWidget(myGrp1, 1, 0);
109 /***************************************************************/
114 //=================================================================================
115 // function : ~BlocksGUI_ExplodeDlg()
116 // purpose : Destroys the object and frees any allocated resources
117 //=================================================================================
118 BlocksGUI_ExplodeDlg::~BlocksGUI_ExplodeDlg()
120 // no need to delete child widgets, Qt does it all for us
124 //=================================================================================
127 //=================================================================================
128 void BlocksGUI_ExplodeDlg::Init()
130 // Set range of spinboxes
131 double SpecificStep = 1.0;
132 mySpinBoxMin->RangeStepAndValidator(0.0, 999.0, SpecificStep, 3);
133 mySpinBoxMax->RangeStepAndValidator(0.0, 999.0, SpecificStep, 3);
135 if (SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
136 != OCCViewer_Viewer::Type())
137 myCheckBtn->setEnabled(false);
139 // signals and slots connections
140 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
141 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
143 connect(mySelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
145 connect(mySpinBoxMin, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
146 connect(mySpinBoxMax, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
148 connect(myCheckBtn, SIGNAL(stateChanged(int)), this, SLOT(SubShapeToggled()));
150 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
151 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
153 myConstructorId = -1;
154 ConstructorsClicked(0);
157 //=================================================================================
158 // function : ConstructorsClicked()
159 // purpose : Radio button management
160 //=================================================================================
161 void BlocksGUI_ExplodeDlg::ConstructorsClicked (int constructorId)
163 if (myConstructorId == constructorId)
166 myConstructorId = constructorId;
168 switch (constructorId) {
171 mySpinBoxMin->SetValue(6.0);
172 mySpinBoxMax->SetValue(6.0);
173 myCheckBtn->setChecked(FALSE);
180 myEditCurrentArgument = mySelName;
181 myObject = GEOM::GEOM_Object::_nil();
186 //=================================================================================
187 // function : ClickOnOk()
189 //=================================================================================
190 void BlocksGUI_ExplodeDlg::ClickOnOk()
196 //=================================================================================
197 // function : ClickOnApply()
199 //=================================================================================
200 bool BlocksGUI_ExplodeDlg::ClickOnApply()
202 SUIT_Session::session()->activeApplication()->putInfo(tr(""));
204 // Explode all sub shapes
205 if (isAllSubShapes()) {
206 // More than 30 subshapes : ask confirmation
207 if (myNbBlocks > 30) {
208 const QString caption = tr("GEOM_CONFIRM");
209 const QString text = tr("GEOM_CONFIRM_INFO").arg(myNbBlocks);
210 const QString button0 = tr("GEOM_BUT_EXPLODE");
211 const QString button1 = tr("GEOM_BUT_CANCEL");
213 if (QMessageBox::warning(this, caption, text, button0, button1) != 0)
214 return false; /* aborted */
226 //=================================================================================
227 // function : SelectionIntoArgument()
228 // purpose : Called when selection has changed
229 //=================================================================================
230 void BlocksGUI_ExplodeDlg::SelectionIntoArgument()
232 if (!isAllSubShapes())
235 myObject = GEOM::GEOM_Object::_nil();
236 mySelName->setText("");
238 if (IObjectCount() == 1) {
239 Standard_Boolean aResult = Standard_False;
240 GEOM::GEOM_Object_var anObj =
241 GEOMBase::ConvertIOinGEOMObject(firstIObject(), aResult);
243 if ( aResult && !anObj->_is_nil() && GEOMBase::IsShape( anObj ) ) {
245 mySelName->setText(GEOMBase::GetName(anObj));
252 //=================================================================================
253 // function : SetEditCurrentArgument()
255 //=================================================================================
256 void BlocksGUI_ExplodeDlg::SetEditCurrentArgument()
258 QPushButton* aSender = (QPushButton*)sender();
260 if (mySelBtn == aSender) {
261 mySelName->setFocus();
262 myEditCurrentArgument = mySelName;
263 myCheckBtn->setChecked(FALSE);
269 //=================================================================================
270 // function : ActivateThisDialog()
272 //=================================================================================
273 void BlocksGUI_ExplodeDlg::ActivateThisDialog()
275 GEOMBase_Skeleton::ActivateThisDialog();
276 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
277 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
282 //=================================================================================
283 // function : enterEvent()
285 //=================================================================================
286 void BlocksGUI_ExplodeDlg::enterEvent (QEvent* e)
288 if (!GroupConstructors->isEnabled())
289 this->ActivateThisDialog();
292 //=================================================================================
293 // function : ValueChangedInSpinBox()
295 //=================================================================================
296 void BlocksGUI_ExplodeDlg::ValueChangedInSpinBox (double newValue)
298 if (!isAllSubShapes())
304 //=================================================================================
305 // function : SubShapeToggled()
306 // purpose : Allow user selection of all or only selected sub shapes
307 // : Called when 'myCheckBtn' state change
308 //=================================================================================
309 void BlocksGUI_ExplodeDlg::SubShapeToggled()
314 //=================================================================================
315 // function : activateSelection
316 // purpose : Redisplay preview and Activate selection
317 //=================================================================================
318 void BlocksGUI_ExplodeDlg::activateSelection()
323 if (isAllSubShapes()) { // Sub-shapes selection disabled
324 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
325 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
326 globalSelection( GEOM_ALLSHAPES );
327 if (myObject->_is_nil()) {
328 SelectionIntoArgument();
330 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
331 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
333 displayPreview(true, true, false);
334 globalSelection(GEOM_PREVIEW);
338 //=================================================================================
339 // function : updateButtonState
341 //=================================================================================
342 void BlocksGUI_ExplodeDlg::updateButtonState()
344 if (SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
345 != OCCViewer_Viewer::Type() || myObject->_is_nil()) {
346 myCheckBtn->setChecked(FALSE);
347 myCheckBtn->setEnabled(FALSE);
349 myCheckBtn->setEnabled(TRUE);
354 if (myObject->_is_nil()) {
355 myBlocksNb->setText("");
357 bool isOnlyBlocks = GEOM::GEOM_IBlocksOperations::_narrow
358 (getOperation())->IsCompoundOfBlocks(myObject,
359 (int)mySpinBoxMin->GetValue(),
360 (int)mySpinBoxMax->GetValue(),
363 myBlocksNb->setText(tr("GEOM_NB_BLOCKS_NO_OTHERS").arg(myNbBlocks));
365 myBlocksNb->setText(tr("GEOM_NB_BLOCKS_SOME_OTHERS").arg(myNbBlocks));
369 //=================================================================================
370 // function : isAllSubShapes
372 //=================================================================================
373 bool BlocksGUI_ExplodeDlg::isAllSubShapes() const
375 return !myCheckBtn->isChecked() || !myCheckBtn->isEnabled();
378 //=================================================================================
379 // function : createOperation
381 //=================================================================================
382 GEOM::GEOM_IOperations_ptr BlocksGUI_ExplodeDlg::createOperation()
384 return getGeomEngine()->GetIBlocksOperations(getStudyId());
387 //=================================================================================
388 // function : isValid()
389 // purpose : Verify validity of input data
390 //=================================================================================
391 bool BlocksGUI_ExplodeDlg::isValid (QString&)
393 switch (getConstructorId()) {
396 return !myObject->_is_nil();
398 return !myObject->_is_nil() && (isAllSubShapes() || IObjectCount());
406 //=================================================================================
407 // function : execute
409 //=================================================================================
410 bool BlocksGUI_ExplodeDlg::execute (ObjectList& objects)
412 GEOM::ListOfGO_var aList;
414 switch (getConstructorId()) {
416 aList = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->ExplodeCompoundOfBlocks
418 (int)mySpinBoxMin->GetValue(),
419 (int)mySpinBoxMax->GetValue());
423 if (!aList->length())
429 // Store objects. They will be put in study when "Apply" is pressed
430 for (int i = 0, n = aList->length(); i < n; i++) {
431 objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
432 myTmpObjs.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
435 return objects.size() ? true : false;
438 // Throw away sub-shapes not selected by user if not in preview mode
439 // and manual selection is active
440 if (!isAllSubShapes())
442 QMap<QString, char> selected;
444 // Get names of selected objects
445 SALOME_ListIteratorOfListIO it (selectedIO());
446 for (; it.More(); it.Next()) {
447 selected.insert(it.Value()->getName(), 0);
450 // Iterate through result and select objects with names from selection
451 ObjectList toRemoveFromEnggine;
452 ObjectList::iterator anIter;
453 for (anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter) {
454 if (selected.contains(myGeomGUI->getApp()->orb()->object_to_string(*anIter)))
455 objects.push_back(*anIter);
457 toRemoveFromEnggine.push_back(*anIter);
460 // Remove from engine useless objects
461 ObjectList::iterator anIter2 = toRemoveFromEnggine.begin();
462 for (; anIter2 != toRemoveFromEnggine.end(); ++anIter2)
463 getGeomEngine()->RemoveObject(*anIter2);
468 for (int i = 0, n = aList->length(); i < n; i++)
469 objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
472 return objects.size();
475 //=================================================================================
476 // function : clearTemporary
477 // purpose : Remove temporary objects from engine
478 //=================================================================================
479 void BlocksGUI_ExplodeDlg::clearTemporary()
481 ObjectList::iterator anIter;
482 for (anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter)
483 getGeomEngine()->RemoveObject(*anIter);
488 //================================================================
489 // Function : getFather
490 // Purpose : Get father object for object to be added in study
491 // ( called with addInStudy method )
492 //================================================================
493 GEOM::GEOM_Object_ptr BlocksGUI_ExplodeDlg::getFather (GEOM::GEOM_Object_ptr)
498 //================================================================
499 // Function : getNewObjectName
500 // Purpose : Redefine this method to return proper name for a new object
501 //================================================================
502 const char* BlocksGUI_ExplodeDlg::getNewObjectName() const