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 "QAD_Desktop.h"
35 #include "SALOME_ListIteratorOfListIO.hxx"
37 #include "utilities.h"
39 #include <TColStd_IndexedMapOfInteger.hxx>
41 #include <qmessagebox.h>
42 #include <qtextedit.h>
43 #include <qcheckbox.h>
45 //=================================================================================
46 // class : BlocksGUI_ExplodeDlg()
47 // purpose : Constructs a BlocksGUI_ExplodeDlg which is a child of 'parent'.
48 //=================================================================================
49 BlocksGUI_ExplodeDlg::BlocksGUI_ExplodeDlg (QWidget* parent,
50 SALOME_Selection* Sel,
52 : GEOMBase_Skeleton(parent, "ExplodeDlg", Sel, modal,
53 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
55 QPixmap image1 (QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_BLOCK_EXPLODE")));
56 QPixmap imageS (QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
58 setCaption(tr("GEOM_BLOCK_EXPLODE_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_BLOCK_EXPLODE"));
63 RadioButton1->setPixmap(image1);
64 RadioButton2->close(TRUE);
65 RadioButton3->close(TRUE);
68 myGrp1 = new QGroupBox(1, Qt::Horizontal, tr("GEOM_ARGUMENTS"), this);
70 QGroupBox* aSelGrp = new QGroupBox(3, Qt::Horizontal, myGrp1);
71 aSelGrp->setFrameStyle(QFrame::NoFrame);
72 aSelGrp->setInsideMargin(0);
74 new QLabel(tr("GEOM_MAIN_OBJECT"), aSelGrp);
75 mySelBtn = new QPushButton(aSelGrp);
76 mySelBtn->setPixmap(imageS);
77 mySelName = new QLineEdit(aSelGrp);
78 mySelName->setReadOnly(true);
80 QGroupBox* aSpinGrp = new QGroupBox(2, Qt::Horizontal, myGrp1);
81 aSpinGrp->setFrameStyle(QFrame::NoFrame);
82 aSpinGrp->setInsideMargin(0);
84 new QLabel(tr("NB_FACES_MIN"), aSpinGrp);
85 mySpinBoxMin = new DlgRef_SpinBox(aSpinGrp);
87 new QLabel(tr("NB_FACES_MAX"), aSpinGrp);
88 mySpinBoxMax = new DlgRef_SpinBox(aSpinGrp);
90 QGroupBox* anInfoGrp = new QGroupBox(2, Qt::Horizontal, myGrp1);
91 anInfoGrp->setFrameStyle(QFrame::NoFrame);
92 anInfoGrp->setInsideMargin(0);
94 myBlocksNb = new QTextEdit(anInfoGrp);
95 myBlocksNb->setReadOnly(true);
97 QGroupBox* aCheckGrp = new QGroupBox(3, Qt::Horizontal, myGrp1);
98 aCheckGrp->setFrameStyle(QFrame::NoFrame);
99 aCheckGrp->setInsideMargin(0);
101 myCheckBtn = new QCheckBox(aCheckGrp, "CheckButton1");
102 myCheckBtn->setText(tr("GEOM_SUBSHAPE_SELECT"));
104 // Add groups to layout
105 Layout1->addWidget(myGrp1, 1, 0);
106 /***************************************************************/
111 //=================================================================================
112 // function : ~BlocksGUI_ExplodeDlg()
113 // purpose : Destroys the object and frees any allocated resources
114 //=================================================================================
115 BlocksGUI_ExplodeDlg::~BlocksGUI_ExplodeDlg()
117 // no need to delete child widgets, Qt does it all for us
121 //=================================================================================
124 //=================================================================================
125 void BlocksGUI_ExplodeDlg::Init()
127 // Set range of spinboxes
128 double SpecificStep = 1.0;
129 mySpinBoxMin->RangeStepAndValidator(0.0, 999.0, SpecificStep, 3);
130 mySpinBoxMax->RangeStepAndValidator(0.0, 999.0, SpecificStep, 3);
132 if (QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_OCC)
133 myCheckBtn->setEnabled(false);
135 // signals and slots connections
136 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
137 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
139 connect(mySelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
141 connect(mySpinBoxMin, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
142 connect(mySpinBoxMax, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
144 connect(myCheckBtn, SIGNAL(stateChanged(int)), this, SLOT(SubShapeToggled()));
146 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
148 myConstructorId = -1;
149 ConstructorsClicked(0);
152 //=================================================================================
153 // function : ConstructorsClicked()
154 // purpose : Radio button management
155 //=================================================================================
156 void BlocksGUI_ExplodeDlg::ConstructorsClicked (int constructorId)
158 if (myConstructorId == constructorId)
161 myConstructorId = constructorId;
163 switch (constructorId) {
166 mySpinBoxMin->SetValue(6.0);
167 mySpinBoxMax->SetValue(6.0);
168 myCheckBtn->setChecked(FALSE);
175 myEditCurrentArgument = mySelName;
176 myObject = GEOM::GEOM_Object::_nil();
181 //=================================================================================
182 // function : ClickOnOk()
184 //=================================================================================
185 void BlocksGUI_ExplodeDlg::ClickOnOk()
191 //=================================================================================
192 // function : ClickOnApply()
194 //=================================================================================
195 bool BlocksGUI_ExplodeDlg::ClickOnApply()
197 QAD_Application::getDesktop()->putInfo(tr(""));
199 // Explode all sub shapes
200 if (isAllSubShapes()) {
201 // More than 30 subshapes : ask confirmation
202 if (myNbBlocks > 30) {
203 const QString caption = tr("GEOM_CONFIRM");
204 const QString text = tr("GEOM_CONFIRM_INFO").arg(myNbBlocks);
205 const QString button0 = tr("GEOM_BUT_EXPLODE");
206 const QString button1 = tr("GEOM_BUT_CANCEL");
208 if (QMessageBox::warning(this, caption, text, button0, button1) != 0)
209 return false; /* aborted */
221 //=================================================================================
222 // function : SelectionIntoArgument()
223 // purpose : Called when selection has changed
224 //=================================================================================
225 void BlocksGUI_ExplodeDlg::SelectionIntoArgument()
227 if (!isAllSubShapes())
230 myObject = GEOM::GEOM_Object::_nil();
231 mySelName->setText("");
233 if (mySelection->IObjectCount() == 1) {
234 Standard_Boolean aResult = Standard_False;
235 GEOM::GEOM_Object_var anObj =
236 GEOMBase::ConvertIOinGEOMObject(mySelection->firstIObject(), aResult);
238 if ( aResult && !anObj->_is_nil() && GEOMBase::IsShape( anObj ) ) {
240 mySelName->setText(GEOMBase::GetName(anObj));
247 //=================================================================================
248 // function : SetEditCurrentArgument()
250 //=================================================================================
251 void BlocksGUI_ExplodeDlg::SetEditCurrentArgument()
253 QPushButton* aSender = (QPushButton*)sender();
255 if (mySelBtn == aSender) {
256 mySelName->setFocus();
257 myEditCurrentArgument = mySelName;
258 myCheckBtn->setChecked(FALSE);
264 //=================================================================================
265 // function : ActivateThisDialog()
267 //=================================================================================
268 void BlocksGUI_ExplodeDlg::ActivateThisDialog()
270 GEOMBase_Skeleton::ActivateThisDialog();
271 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
276 //=================================================================================
277 // function : enterEvent()
279 //=================================================================================
280 void BlocksGUI_ExplodeDlg::enterEvent (QEvent* e)
282 if (!GroupConstructors->isEnabled())
283 this->ActivateThisDialog();
286 //=================================================================================
287 // function : ValueChangedInSpinBox()
289 //=================================================================================
290 void BlocksGUI_ExplodeDlg::ValueChangedInSpinBox (double newValue)
292 if (!isAllSubShapes())
298 //=================================================================================
299 // function : SubShapeToggled()
300 // purpose : Allow user selection of all or only selected sub shapes
301 // : Called when 'myCheckBtn' state change
302 //=================================================================================
303 void BlocksGUI_ExplodeDlg::SubShapeToggled()
308 //=================================================================================
309 // function : activateSelection
310 // purpose : Redisplay preview and Activate selection
311 //=================================================================================
312 void BlocksGUI_ExplodeDlg::activateSelection()
317 if (isAllSubShapes()) { // Sub-shapes selection disabled
318 globalSelection( GEOM_ALLSHAPES );
319 SelectionIntoArgument();
322 displayPreview(true, true, false);
323 globalSelection(GEOM_PREVIEW);
327 //=================================================================================
328 // function : updateButtonState
330 //=================================================================================
331 void BlocksGUI_ExplodeDlg::updateButtonState()
333 if (QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_OCC ||
334 myObject->_is_nil()) {
335 myCheckBtn->setChecked(FALSE);
336 myCheckBtn->setEnabled(FALSE);
338 myCheckBtn->setEnabled(TRUE);
343 if (myObject->_is_nil()) {
344 myBlocksNb->setText("");
346 bool isOnlyBlocks = GEOM::GEOM_IBlocksOperations::_narrow
347 (getOperation())->IsCompoundOfBlocks(myObject,
348 (int)mySpinBoxMin->GetValue(),
349 (int)mySpinBoxMax->GetValue(),
352 myBlocksNb->setText(tr("GEOM_NB_BLOCKS_NO_OTHERS").arg(myNbBlocks));
354 myBlocksNb->setText(tr("GEOM_NB_BLOCKS_SOME_OTHERS").arg(myNbBlocks));
358 //=================================================================================
359 // function : isAllSubShapes
361 //=================================================================================
362 bool BlocksGUI_ExplodeDlg::isAllSubShapes() const
364 return !myCheckBtn->isChecked() || !myCheckBtn->isEnabled();
367 //=================================================================================
368 // function : createOperation
370 //=================================================================================
371 GEOM::GEOM_IOperations_ptr BlocksGUI_ExplodeDlg::createOperation()
373 return getGeomEngine()->GetIBlocksOperations(getStudyId());
376 //=================================================================================
377 // function : isValid()
378 // purpose : Verify validity of input data
379 //=================================================================================
380 bool BlocksGUI_ExplodeDlg::isValid (QString&)
382 switch (getConstructorId()) {
385 return !myObject->_is_nil();
387 return !myObject->_is_nil() && (isAllSubShapes() || mySelection->IObjectCount());
395 //=================================================================================
396 // function : execute
398 //=================================================================================
399 bool BlocksGUI_ExplodeDlg::execute (ObjectList& objects)
401 GEOM::ListOfGO_var aList;
403 switch (getConstructorId()) {
405 aList = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->ExplodeCompoundOfBlocks
407 (int)mySpinBoxMin->GetValue(),
408 (int)mySpinBoxMax->GetValue());
412 if (!aList->length())
418 // Store objects. They will be put in study when "Apply" is pressed
419 for (int i = 0, n = aList->length(); i < n; i++) {
420 objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
421 myTmpObjs.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
424 return objects.size() ? true : false;
427 // Throw away sub-shapes not selected by user if not in preview mode
428 // and manual selection is active
429 if (!isAllSubShapes())
431 QMap<QString, char> selected;
433 // Get names of selected objects
434 SALOME_ListIteratorOfListIO it (mySelection->StoredIObjects());
435 for (; it.More(); it.Next()) {
436 selected.insert(it.Value()->getName(), 0);
439 // Iterate through result and select objects with names from selection
440 ObjectList toRemoveFromEnggine;
441 ObjectList::iterator anIter;
442 for (anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter) {
443 if (selected.contains(GeometryGUI::GetORB()->object_to_string(*anIter)))
444 objects.push_back(*anIter);
446 toRemoveFromEnggine.push_back(*anIter);
449 // Remove from engine useless objects
450 ObjectList::iterator anIter2 = toRemoveFromEnggine.begin();
451 for (; anIter2 != toRemoveFromEnggine.end(); ++anIter2)
452 getGeomEngine()->RemoveObject(*anIter2);
457 for (int i = 0, n = aList->length(); i < n; i++)
458 objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
461 return objects.size();
464 //=================================================================================
465 // function : clearTemporary
466 // purpose : Remove temporary objects from engine
467 //=================================================================================
468 void BlocksGUI_ExplodeDlg::clearTemporary()
470 ObjectList::iterator anIter;
471 for (anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter)
472 getGeomEngine()->RemoveObject(*anIter);
477 //================================================================
478 // Function : getFather
479 // Purpose : Get father object for object to be added in study
480 // ( called with addInStudy method )
481 //================================================================
482 GEOM::GEOM_Object_ptr BlocksGUI_ExplodeDlg::getFather (GEOM::GEOM_Object_ptr)