2 #include "VisuGUI_ClippingDlg.h"
5 #include "VisuGUI_Tools.h"
7 #include "VISU_Prs3d_i.hh"
8 #include "VISU_Result_i.hh"
10 #include "SalomeApp_SelectionMgr.h"
12 #include "SVTK_ViewWindow.h"
14 #include "SUIT_Session.h"
15 #include "SUIT_Desktop.h"
16 #include "SUIT_ResourceMgr.h"
17 #include "SUIT_OverrideCursor.h"
19 #include "SALOME_Actor.h"
23 #include <qpushbutton.h>
24 #include <qcombobox.h>
25 #include <qcheckbox.h>
27 #include <qgroupbox.h>
28 #include <qvalidator.h>
29 #include <qtabwidget.h>
30 #include <qhbuttongroup.h>
31 #include <qradiobutton.h>
36 #include <vtkCamera.h>
37 #include <vtkRenderer.h>
38 #include <vtkDataSet.h>
39 #include <vtkDataSetMapper.h>
40 #include <vtkImplicitFunction.h>
41 #include <vtkPlaneSource.h>
42 #include <vtkPolyData.h>
43 #include <vtkUnstructuredGrid.h>
51 float GetFloat (const QString& theValue, float theDefault)
53 if (theValue.isEmpty()) return theDefault;
54 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
55 QString aValue = aResourceMgr->stringValue(theValue);
56 if (aValue.isEmpty()) return theDefault;
57 return aValue.toFloat();
60 void RenderViewWindow (SVTK_ViewWindow* vw)
63 //if (vw->getRenderer()->GetActors()->GetNumberOfItems() > 0) {
64 vw->getRenderer()->ResetCameraClippingRange();
70 void RangeStepAndValidator (QtxDblSpinBox* theSpinBox, double min, double max,
71 double step, unsigned short decimals)
73 theSpinBox->setRange(min, max);
74 theSpinBox->setLineStep(step);
75 ((QDoubleValidator*)theSpinBox->validator())->setRange(min, max, decimals);
79 //=================================================================================
80 //class : OrientedPlane
82 //=================================================================================
83 class OrientedPlane: public vtkPlane
85 SVTK_ViewWindow* myViewWindow;
87 vtkDataSetMapper* myMapper;
90 static OrientedPlane * New() {
91 return new OrientedPlane();
93 static OrientedPlane * New (SVTK_ViewWindow* vw) {
94 return new OrientedPlane(vw);
96 vtkTypeMacro(OrientedPlane, vtkPlane);
99 VISU::Orientation myOrientation;
103 vtkPlaneSource* myPlaneSource;
104 SALOME_Actor *myActor;
106 void SetOrientation(VISU::Orientation theOrientation) {myOrientation = theOrientation;}
107 VISU::Orientation GetOrientation() {return myOrientation;}
109 void SetDistance(float theDistance) {myDistance = theDistance;}
110 float GetDistance() {return myDistance;}
112 void ShallowCopy(OrientedPlane* theOrientedPlane){
113 SetNormal(theOrientedPlane->GetNormal());
114 SetOrigin(theOrientedPlane->GetOrigin());
116 myOrientation = theOrientedPlane->GetOrientation();
117 myDistance = theOrientedPlane->GetDistance();
119 myAngle[0] = theOrientedPlane->myAngle[0];
120 myAngle[1] = theOrientedPlane->myAngle[1];
122 myPlaneSource->SetNormal(theOrientedPlane->myPlaneSource->GetNormal());
123 myPlaneSource->SetOrigin(theOrientedPlane->myPlaneSource->GetOrigin());
124 myPlaneSource->SetPoint1(theOrientedPlane->myPlaneSource->GetPoint1());
125 myPlaneSource->SetPoint2(theOrientedPlane->myPlaneSource->GetPoint2());
129 OrientedPlane(SVTK_ViewWindow* vw):
130 myOrientation(VISU::XY),
135 myViewWindow->AddActor(myActor);
139 myOrientation(VISU::XY),
147 myPlaneSource = vtkPlaneSource::New();
149 myAngle[0] = myAngle[1] = 0.0;
151 // Create and display actor
152 myMapper = vtkDataSetMapper::New();
153 myMapper->SetInput(myPlaneSource->GetOutput());
155 myActor = SALOME_Actor::New();
156 myActor->VisibilityOff();
157 myActor->PickableOff();
158 myActor->SetInfinitive(true);
159 myActor->SetMapper(myMapper);
161 vtkProperty* aProp = vtkProperty::New();
163 anRGB[0] = VISU::GetFloat("SMESH:SettingsFillColorRed", 0)/255.;
164 anRGB[1] = VISU::GetFloat("SMESH:SettingsFillColorGreen", 170)/255.;
165 anRGB[2] = VISU::GetFloat("SMESH:SettingsFillColorBlue", 255)/255.;
166 aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
167 aProp->SetOpacity(0.75);
168 myActor->SetProperty(aProp);
171 vtkProperty* aBackProp = vtkProperty::New();
172 anRGB[0] = VISU::GetFloat("SMESH:SettingsBackFaceColorRed", 0)/255.;
173 anRGB[1] = VISU::GetFloat("SMESH:SettingsBackFaceColorGreen", 0)/255.;
174 anRGB[2] = VISU::GetFloat("SMESH:SettingsBackFaceColorBlue", 255)/255.;
175 aBackProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
176 aBackProp->SetOpacity(0.75);
177 myActor->SetBackfaceProperty(aBackProp);
184 myViewWindow->RemoveActor(myActor);
188 myMapper->RemoveAllInputs();
191 myPlaneSource->UnRegisterAllOutputs();
192 myPlaneSource->Delete();
197 OrientedPlane(const OrientedPlane&);
198 void operator=(const OrientedPlane&);
201 struct TSetVisiblity {
202 TSetVisiblity(int theIsVisible): myIsVisible(theIsVisible){}
203 void operator()(VISU::TVTKPlane& theOrientedPlane){
204 theOrientedPlane->myActor->SetVisibility(myIsVisible);
209 //=================================================================================
210 // class : VisuGUI_ClippingDlg()
213 //=================================================================================
214 VisuGUI_ClippingDlg::VisuGUI_ClippingDlg (VisuGUI* theModule,
218 : QDialog(VISU::GetDesktop(theModule), name, modal, WStyle_Customize |
219 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
220 mySelectionMgr(VISU::GetSelectionMgr(theModule)),
224 setName("VisuGUI_ClippingDlg");
225 setCaption(tr("TITLE"));
226 setSizeGripEnabled(TRUE);
227 QGridLayout* VisuGUI_ClippingDlgLayout = new QGridLayout(this);
228 VisuGUI_ClippingDlgLayout->setSpacing(6);
229 VisuGUI_ClippingDlgLayout->setMargin(11);
231 // Controls for selecting, creating, deleting planes
232 QGroupBox* GroupPlanes = new QGroupBox (this, "GroupPlanes");
233 GroupPlanes->setTitle(tr("GRP_PLANES"));
234 GroupPlanes->setColumnLayout(0, Qt::Vertical);
235 GroupPlanes->layout()->setSpacing(0);
236 GroupPlanes->layout()->setMargin(0);
237 QGridLayout* GroupPlanesLayout = new QGridLayout (GroupPlanes->layout());
238 GroupPlanesLayout->setAlignment(Qt::AlignTop);
239 GroupPlanesLayout->setSpacing(6);
240 GroupPlanesLayout->setMargin(11);
242 ComboBoxPlanes = new QComboBox (GroupPlanes, "ComboBoxPlanes");
243 GroupPlanesLayout->addWidget(ComboBoxPlanes, 0, 0);
245 QSpacerItem* spacerGP = new QSpacerItem (20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
246 GroupPlanesLayout->addItem(spacerGP, 0, 1);
248 buttonNew = new QPushButton (GroupPlanes, "buttonNew");
249 buttonNew->setText(tr("BUT_NEW"));
250 GroupPlanesLayout->addWidget(buttonNew, 0, 2);
252 buttonDelete = new QPushButton(GroupPlanes, "buttonDelete");
253 buttonDelete->setText(tr("BUT_DELETE"));
254 GroupPlanesLayout->addWidget(buttonDelete, 0, 3);
256 // Controls for defining plane parameters
259 QGroupBox* GroupParameters = new QGroupBox(this, "GroupParameters");
260 GroupParameters->setTitle(tr("GRP_PARAMETERS"));
261 GroupParameters->setColumnLayout(0, Qt::Vertical);
262 GroupParameters->layout()->setSpacing(0);
263 GroupParameters->layout()->setMargin(0);
264 QGridLayout* GroupParametersLayout = new QGridLayout (GroupParameters->layout());
265 GroupParametersLayout->setAlignment(Qt::AlignTop);
266 GroupParametersLayout->setSpacing(6);
267 GroupParametersLayout->setMargin(11);
269 TabPane = new QTabWidget (GroupParameters);
270 TabPane->addTab(createParamsTab() , tr("TAB_NON_STRUCTURED"));
271 TabPane->addTab(createIJKParamsTab(), tr("TAB_IJK_STRUCTURED"));
272 GroupParametersLayout->addWidget(TabPane, 0, 0);
274 // "Show preview" and "Auto Apply" check boxes
276 PreviewCheckBox = new QCheckBox (tr("SHOW_PREVIEW_CHK"), this);
277 PreviewCheckBox->setChecked(true);
279 AutoApplyCheckBox = new QCheckBox (tr("AUTO_APPLY_CHK"), this);
280 AutoApplyCheckBox->setChecked(false);
282 // Controls for "Ok", "Apply" and "Close" button
283 QGroupBox* GroupButtons = new QGroupBox (this, "GroupButtons");
284 GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7,
285 (QSizePolicy::SizeType)0, 0, 0,
286 GroupButtons->sizePolicy().hasHeightForWidth()));
287 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
288 //GroupButtons->setTitle(tr(""));
289 GroupButtons->setColumnLayout(0, Qt::Vertical);
290 GroupButtons->layout()->setSpacing(0);
291 GroupButtons->layout()->setMargin(0);
292 QGridLayout* GroupButtonsLayout = new QGridLayout (GroupButtons->layout());
293 GroupButtonsLayout->setAlignment(Qt::AlignTop);
294 GroupButtonsLayout->setSpacing(6);
295 GroupButtonsLayout->setMargin(11);
296 buttonCancel = new QPushButton (GroupButtons, "buttonCancel");
297 buttonCancel->setText(tr("BUT_CLOSE"));
298 buttonCancel->setAutoDefault(TRUE);
299 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
300 buttonApply = new QPushButton (GroupButtons, "buttonApply");
301 buttonApply->setText(tr("BUT_APPLY"));
302 buttonApply->setAutoDefault(TRUE);
303 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
304 QSpacerItem* spacer_9 = new QSpacerItem (20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
305 GroupButtonsLayout->addItem(spacer_9, 0, 2);
306 buttonOk = new QPushButton (GroupButtons, "buttonOk");
307 buttonOk->setText(tr("BUT_OK"));
308 buttonOk->setAutoDefault(TRUE);
309 buttonOk->setDefault(TRUE);
310 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
312 VisuGUI_ClippingDlgLayout->addMultiCellWidget(GroupPlanes, 0, 0, 0, 1);
313 VisuGUI_ClippingDlgLayout->addMultiCellWidget(GroupParameters, 1, 1, 0, 1);
314 VisuGUI_ClippingDlgLayout->addWidget(PreviewCheckBox, 2, 0);
315 VisuGUI_ClippingDlgLayout->addWidget(AutoApplyCheckBox, 2, 1);
316 VisuGUI_ClippingDlgLayout->addMultiCellWidget(GroupButtons, 3, 3, 0, 1);
319 VISU::RangeStepAndValidator(SpinBoxDistance, 0.0, 1.0, 0.01, 3);
320 VISU::RangeStepAndValidator(SpinBoxRot1, -180.0, 180.0, 1, 3);
321 VISU::RangeStepAndValidator(SpinBoxRot2, -180.0, 180.0, 1, 3);
323 ComboBoxOrientation->insertItem(tr("PARALLEL_XOY_COMBO_ITEM"));
324 ComboBoxOrientation->insertItem(tr("PARALLEL_YOZ_COMBO_ITEM"));
325 ComboBoxOrientation->insertItem(tr("PARALLEL_ZOX_COMBO_ITEM"));
327 SpinBoxDistance->setValue(0.5);
330 myIsSelectPlane = false;
331 onSelectionChanged();
333 // signals and slots connections :
334 connect(ComboBoxPlanes, SIGNAL(activated(int)), this, SLOT(onSelectPlane(int)));
335 connect(buttonNew, SIGNAL(clicked()), this, SLOT(ClickOnNew()));
336 connect(buttonDelete, SIGNAL(clicked()), this, SLOT(ClickOnDelete()));
337 connect(ComboBoxOrientation, SIGNAL(activated(int)), this, SLOT(onSelectOrientation(int)));
338 connect(SpinBoxDistance, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
339 connect(SpinBoxRot1, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
340 connect(SpinBoxRot2, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
341 connect(ButtonGroupIJKAxis, SIGNAL(clicked(int)), this, SLOT(onIJKAxisChanged(int)));
342 connect(SpinBoxIJKIndex, SIGNAL(valueChanged(int)), this, SLOT(SetCurrentPlaneIJKParam()));
343 connect(CheckBoxIJKPlaneReverse, SIGNAL(toggled(bool)), this, SLOT(SetCurrentPlaneIJKParam()));
344 connect(TabPane, SIGNAL(currentChanged (QWidget*)), this, SLOT(onTabChanged(QWidget*)));
346 connect(PreviewCheckBox, SIGNAL(toggled(bool)), this, SLOT(OnPreviewToggle(bool)));
347 connect(AutoApplyCheckBox, SIGNAL(toggled(bool)), this, SLOT(ClickOnApply()));
348 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
349 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
350 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
351 connect(myVisuGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnOk()));
352 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
353 /* to close dialog if study frame change */
354 connect(myVisuGUI, SIGNAL(SignalStudyFrameChanged()), this, SLOT(ClickOnCancel()));
359 //=================================================================================
360 // function : ~VisuGUI_ClippingDlg()
362 //=================================================================================
363 VisuGUI_ClippingDlg::~VisuGUI_ClippingDlg()
365 // no need to delete child widgets, Qt does it all for us
366 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(false));
367 VISU::RenderViewWindow(VISU::GetViewWindow(myVisuGUI));
370 //=================================================================================
371 // function : createParamsTab
373 //=================================================================================
374 QWidget* VisuGUI_ClippingDlg::createParamsTab()
376 QFrame* GroupParameters = new QFrame(this);
377 QGridLayout* GroupParametersLayout = new QGridLayout(GroupParameters);
378 GroupParametersLayout->setAlignment(Qt::AlignTop);
379 GroupParametersLayout->setSpacing(6);
380 GroupParametersLayout->setMargin(11);
382 TextLabelOrientation = new QLabel(GroupParameters, "TextLabelOrientation");
383 TextLabelOrientation->setText(tr("LBL_ORIENTATION"));
384 GroupParametersLayout->addWidget(TextLabelOrientation, 0, 0);
386 ComboBoxOrientation = new QComboBox(GroupParameters, "ComboBoxOrientation");
387 GroupParametersLayout->addWidget(ComboBoxOrientation, 0, 1);
389 TextLabelDistance = new QLabel(GroupParameters, "TextLabelDistance");
390 TextLabelDistance->setText(tr("LBL_DISTANCE"));
391 GroupParametersLayout->addWidget(TextLabelDistance, 1, 0);
393 SpinBoxDistance = new QtxDblSpinBox(GroupParameters, "SpinBoxDistance");
394 GroupParametersLayout->addWidget(SpinBoxDistance, 1, 1);
396 TextLabelRot1 = new QLabel(GroupParameters, "TextLabelRot1");
397 TextLabelRot1->setText(tr("LBL_ROTATION_YZ"));
398 GroupParametersLayout->addWidget(TextLabelRot1, 2, 0);
400 SpinBoxRot1 = new QtxDblSpinBox(GroupParameters, "SpinBoxRot1");
401 GroupParametersLayout->addWidget(SpinBoxRot1, 2, 1);
403 TextLabelRot2 = new QLabel(GroupParameters, "TextLabelRot2");
404 TextLabelRot2->setText(tr("LBL_ROTATION_XZ"));
405 GroupParametersLayout->addWidget(TextLabelRot2, 3, 0);
407 SpinBoxRot2 = new QtxDblSpinBox(GroupParameters, "SpinBoxRot2");
408 GroupParametersLayout->addWidget(SpinBoxRot2, 3, 1);
410 return GroupParameters;
413 //=================================================================================
414 // function : createIJKParamsTab
416 //=================================================================================
417 QWidget* VisuGUI_ClippingDlg::createIJKParamsTab()
420 WidgetIJKTab = new QFrame(this);
421 QGridLayout* IJKParametersLayout = new QGridLayout(WidgetIJKTab);
422 IJKParametersLayout->setAlignment(Qt::AlignTop);
423 IJKParametersLayout->setSpacing(6);
424 IJKParametersLayout->setMargin(11);
427 ButtonGroupIJKAxis = new QHButtonGroup (tr("GRP_IJK_AXIS"), WidgetIJKTab);
428 new QRadioButton (tr("I_RADIO_BTN"), ButtonGroupIJKAxis); // 0
429 new QRadioButton (tr("J_RADIO_BTN"), ButtonGroupIJKAxis); // 1
430 new QRadioButton (tr("K_RADIO_BTN"), ButtonGroupIJKAxis); // 2
431 ButtonGroupIJKAxis->setButton(0);
434 TextLabelIJKIndex = new QLabel(WidgetIJKTab, "TextLabelIJKIndex");
435 TextLabelIJKIndex->setText(tr("LBL_IJK_INDEX"));
436 SpinBoxIJKIndex = new QSpinBox(WidgetIJKTab, "SpinBoxIJKIndex");
439 CheckBoxIJKPlaneReverse = new QCheckBox (tr("REVERSE_NORMAL_CHK"), WidgetIJKTab);
440 CheckBoxIJKPlaneReverse->setChecked(false);
442 IJKParametersLayout->addMultiCellWidget(ButtonGroupIJKAxis, 0, 0, 0, 1);
443 IJKParametersLayout->addWidget(TextLabelIJKIndex, 1, 0);
444 IJKParametersLayout->addWidget(SpinBoxIJKIndex, 1, 1);
445 IJKParametersLayout->addWidget(CheckBoxIJKPlaneReverse, 2, 0);
450 //=================================================================================
451 // function : ClickOnApply()
453 //=================================================================================
454 void VisuGUI_ClippingDlg::ClickOnApply()
459 if (SVTK_ViewWindow* aViewWindow = VISU::GetViewWindow(myVisuGUI)) {
460 SUIT_OverrideCursor wc;
462 myPrs3d->RemoveAllClippingPlanes();
464 VISU::TPlanes::iterator anIter = myPlanes.begin();
465 for (;anIter != myPlanes.end();anIter++) {
466 OrientedPlane* anOrientedPlane = OrientedPlane::New(aViewWindow);
467 anOrientedPlane->ShallowCopy(anIter->GetPointer());
468 myPrs3d->AddClippingPlane(anOrientedPlane);
469 anOrientedPlane->Delete();
472 VISU::RenderViewWindow(aViewWindow);
476 //=================================================================================
477 // function : ClickOnOk()
479 //=================================================================================
480 void VisuGUI_ClippingDlg::ClickOnOk()
486 //=================================================================================
487 // function : ClickOnCancel()
489 //=================================================================================
490 void VisuGUI_ClippingDlg::ClickOnCancel()
495 //=================================================================================
496 // function : onSelectionChanged()
497 // purpose : Called when selection is changed
498 //=================================================================================
499 void VisuGUI_ClippingDlg::onSelectionChanged()
501 if (SVTK_ViewWindow* aViewWindow = VISU::GetViewWindow(myVisuGUI)) {
502 Handle(SALOME_InteractiveObject) anIO;
503 CORBA::Object_var anObject = VISU::GetSelectedObj(myVisuGUI, &anIO);
504 if (CORBA::is_nil(anObject)) return;
505 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
506 if (!aServant.in()) return;
508 myPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
510 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(false));
514 myPrs3d->GetOffset(anOffset);
516 vtkIdType anId = 0, anEnd = myPrs3d->GetNumberOfClippingPlanes();
517 for (; anId < anEnd; anId++) {
518 if (vtkImplicitFunction* aFunction = myPrs3d->GetClippingPlane(anId)) {
519 if (OrientedPlane* aPlane = OrientedPlane::SafeDownCast(aFunction)) {
520 OrientedPlane* anOrientedPlane = OrientedPlane::New(aViewWindow);
521 VISU::TVTKPlane aTVTKPlane(anOrientedPlane);
522 anOrientedPlane->Delete();
523 aTVTKPlane->ShallowCopy(aPlane);
524 aTVTKPlane->myActor->SetPosition(anOffset);
525 myPlanes.push_back(aTVTKPlane);
530 std::for_each(myPlanes.begin(),myPlanes.end(),
531 TSetVisiblity(PreviewCheckBox->isChecked()));
534 // enable/disable IJK tab
535 TabPane->setTabEnabled(WidgetIJKTab, isStructured());
537 VISU::RenderViewWindow(aViewWindow);
541 //=================================================================================
542 // function : onSelectPlane()
544 //=================================================================================
545 void VisuGUI_ClippingDlg::onSelectPlane(int theIndex)
547 if (!myPrs3d || myPlanes.empty())
550 OrientedPlane* aPlane = myPlanes[theIndex].GetPointer();
553 VISU::Orientation anOrientation = aPlane->GetOrientation();
556 double aRot[2] = {aPlane->myAngle[0], aPlane->myAngle[1]};
558 // Set plane parameters in the dialog
559 myIsSelectPlane = true;
560 setDistance(aPlane->GetDistance());
561 setRotation(aRot[0], aRot[1]);
563 switch (anOrientation) {
564 case VISU::XY: item = 0; break;
565 case VISU::YZ: item = 1; break;
566 case VISU::ZX: item = 2; break;
568 ComboBoxOrientation->setCurrentItem(item);
570 bool isIJK = (TabPane->currentPage() == WidgetIJKTab);
572 setIJKByNonStructured();
574 onSelectOrientation(item);
576 myIsSelectPlane = false;
579 //=================================================================================
580 // function : ClickOnNew()
582 //=================================================================================
583 void VisuGUI_ClippingDlg::ClickOnNew()
588 if (SVTK_ViewWindow* aViewWindow = VISU::GetViewWindow(myVisuGUI)) {
589 OrientedPlane* aPlane = OrientedPlane::New(aViewWindow);
590 VISU::TVTKPlane aTVTKPlane(aPlane);
591 myPlanes.push_back(aTVTKPlane);
594 myPrs3d->GetOffset(anOffset);
595 aTVTKPlane->myActor->SetPosition(anOffset);
597 if (PreviewCheckBox->isChecked())
598 aTVTKPlane->myActor->VisibilityOn();
601 SetCurrentPlaneParam();
605 //=================================================================================
606 // function : ClickOnDelete()
608 //=================================================================================
609 void VisuGUI_ClippingDlg::ClickOnDelete()
611 if (!myPrs3d || myPlanes.empty())
614 int aPlaneIndex = ComboBoxPlanes->currentItem();
616 VISU::TPlanes::iterator anIter = myPlanes.begin() + aPlaneIndex;
617 anIter->GetPointer()->myActor->SetVisibility(false);
618 myPlanes.erase(anIter);
620 if(AutoApplyCheckBox->isChecked())
624 if (SVTK_ViewWindow* aViewWindow = VISU::GetViewWindow(myVisuGUI))
625 VISU::RenderViewWindow(aViewWindow);
628 //=================================================================================
629 // function : onSelectOrientation()
631 //=================================================================================
632 void VisuGUI_ClippingDlg::onSelectOrientation(int theItem)
634 if (myPlanes.empty())
638 TextLabelRot1->setText(tr("LBL_ROTATION_YZ"));
639 TextLabelRot2->setText(tr("LBL_ROTATION_XZ"));
641 else if (theItem == 1) {
642 TextLabelRot1->setText(tr("LBL_ROTATION_ZX"));
643 TextLabelRot2->setText(tr("LBL_ROTATION_YX"));
645 else if (theItem == 2) {
646 TextLabelRot1->setText(tr("LBL_ROTATION_XY"));
647 TextLabelRot2->setText(tr("LBL_ROTATION_ZY"));
650 if((QComboBox*)sender() == ComboBoxOrientation)
651 SetCurrentPlaneParam();
654 //=================================================================================
655 // function : Sinchronize()
656 // purpose : update control values according to plane selection
657 //=================================================================================
658 void VisuGUI_ClippingDlg::Sinchronize()
660 int aNbPlanes = myPlanes.size();
661 ComboBoxPlanes->clear();
664 for (int i = 1; i<=aNbPlanes; i++) {
665 aName = QString(tr("PLANES_COMBO_ITEM_i")).arg(i);
666 ComboBoxPlanes->insertItem(aName);
669 int aPos = ComboBoxPlanes->count() - 1;
670 ComboBoxPlanes->setCurrentItem(aPos);
672 bool anIsControlsEnable = (aPos >= 0);
673 if (anIsControlsEnable) {
676 ComboBoxPlanes->insertItem(tr("PLANES_COMBO_ITEM_no"));
677 SpinBoxRot1->setValue(0.0);
678 SpinBoxRot2->setValue(0.0);
679 SpinBoxDistance->setValue(0.5);
682 buttonDelete ->setEnabled(anIsControlsEnable);
683 buttonApply ->setEnabled(anIsControlsEnable);
684 PreviewCheckBox ->setEnabled(anIsControlsEnable);
685 AutoApplyCheckBox ->setEnabled(anIsControlsEnable);
687 ComboBoxOrientation ->setEnabled(anIsControlsEnable);
688 SpinBoxDistance ->setEnabled(anIsControlsEnable);
689 SpinBoxRot1 ->setEnabled(anIsControlsEnable);
690 SpinBoxRot2 ->setEnabled(anIsControlsEnable);
692 ButtonGroupIJKAxis ->setEnabled(anIsControlsEnable);
693 SpinBoxIJKIndex ->setEnabled(anIsControlsEnable);
694 CheckBoxIJKPlaneReverse->setEnabled(anIsControlsEnable);
697 //=================================================================================
698 // function : setRotation()
700 //=================================================================================
701 void VisuGUI_ClippingDlg::setRotation(const double theRot1, const double theRot2)
703 SpinBoxRot1->setValue(theRot1);
704 SpinBoxRot2->setValue(theRot2);
707 //=================================================================================
708 // function : SetCurrentPlaneParam()
710 //=================================================================================
711 void VisuGUI_ClippingDlg::SetCurrentPlaneParam()
713 if (myPlanes.empty() || myIsSelectPlane)
716 int aCurPlaneIndex = ComboBoxPlanes->currentItem();
718 OrientedPlane* aPlane = myPlanes[aCurPlaneIndex].GetPointer();
721 VISU::Orientation anOrientation;
722 float aDir[3][3] = {{0, 0, 0}, {0, 0, 0}};
724 static double aCoeff = vtkMath::Pi()/180.0;
726 float aRot[2] = {getRotation1(), getRotation2()};
727 aPlane->myAngle[0] = aRot[0];
728 aPlane->myAngle[1] = aRot[1];
730 float anU[2] = {cos(aCoeff*aRot[0]), cos(aCoeff*aRot[1])};
731 float aV[2] = {sqrt(1.0-anU[0]*anU[0]), sqrt(1.0-anU[1]*anU[1])};
732 aV[0] = aRot[0] > 0? aV[0]: -aV[0];
733 aV[1] = aRot[1] > 0? aV[1]: -aV[1];
735 switch (ComboBoxOrientation->currentItem()) {
737 anOrientation = VISU::XY;
747 anOrientation = VISU::YZ;
757 anOrientation = VISU::ZX;
768 vtkMath::Cross(aDir[1],aDir[0],aNormal);
769 vtkMath::Normalize(aNormal);
770 vtkMath::Cross(aNormal,aDir[1],aDir[0]);
773 aPlane->SetOrientation(anOrientation);
774 aPlane->SetDistance(getDistance());
776 myPrs3d->SetPlaneParam(aNormal, 1. - getDistance(), aPlane);
778 vtkDataSet* aDataSet = myPrs3d->GetInput();
779 float *aPnt = aDataSet->GetCenter();
781 float* anOrigin = aPlane->GetOrigin();
782 float aDel = aDataSet->GetLength()/2.0;
784 float aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
785 {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
786 float aParam, aPnt0[3], aPnt1[3], aPnt2[3];
788 float aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
789 aPnt[1] - aDelta[0][1] - aDelta[1][1],
790 aPnt[2] - aDelta[0][2] - aDelta[1][2]};
791 float aPnt02[3] = {aPnt01[0] + aNormal[0],
792 aPnt01[1] + aNormal[1],
793 aPnt01[2] + aNormal[2]};
794 vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
796 float aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
797 aPnt[1] - aDelta[0][1] + aDelta[1][1],
798 aPnt[2] - aDelta[0][2] + aDelta[1][2]};
799 float aPnt12[3] = {aPnt11[0] + aNormal[0],
800 aPnt11[1] + aNormal[1],
801 aPnt11[2] + aNormal[2]};
802 vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
804 float aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
805 aPnt[1] + aDelta[0][1] - aDelta[1][1],
806 aPnt[2] + aDelta[0][2] - aDelta[1][2]};
807 float aPnt22[3] = {aPnt21[0] + aNormal[0],
808 aPnt21[1] + aNormal[1],
809 aPnt21[2] + aNormal[2]};
810 vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
812 vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
813 aPlaneSource->SetNormal(aNormal[0],aNormal[1],aNormal[2]);
814 aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
815 aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
816 aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
818 if (AutoApplyCheckBox->isChecked())
821 if (SVTK_ViewWindow* vw = VISU::GetViewWindow(myVisuGUI))
822 VISU::RenderViewWindow(vw);
825 //=================================================================================
826 // function : onTabChanged
828 //=================================================================================
829 void VisuGUI_ClippingDlg::onTabChanged(QWidget* newTab)
831 if (newTab == WidgetIJKTab) // IJK
832 setIJKByNonStructured();
835 //=================================================================================
836 // function : SetCurrentPlaneIJKParam
837 // purpose : set non structured parameters by IJK parameters
838 //=================================================================================
839 void VisuGUI_ClippingDlg::SetCurrentPlaneIJKParam()
841 if (myPlanes.empty() || myIsSelectPlane || !WidgetIJKTab->isEnabled())
844 VISU::Result_i* result = myPrs3d ? myPrs3d->GetResult() : 0;
849 int i, axId = ButtonGroupIJKAxis->id (ButtonGroupIJKAxis->selected());
850 VISU::Result_i::TAxis axis = (VISU::Result_i::TAxis) axId;
852 const vector<float> * values =
853 result->GetAxisInfo(myPrs3d->GetMeshName(), axis, dir);
858 int index = SpinBoxIJKIndex->value();
860 if (index < values->size())
861 distance = (*values)[ index ];
863 // find id of axis closest to dir
867 double cos[3] = { gp::DZ() * dir, gp::DX() * dir, gp::DY() * dir };
869 for (i = 0; i < 3; ++i) {
870 if (Abs(cos[ i ]) > Abs (maxCos)) {
875 // find rotation angles
878 (axId == 0) ? 2 : axId - 1,
879 (axId == 2) ? 0 : axId + 1
881 static double aCoeff = 180.0/vtkMath::Pi();
882 for (i = 0; i < 2; ++i) {
883 float cosin = cos[ rotId[ i ]];
886 angle[ i ] = asin(cosin) * aCoeff;
888 angle[ i ] += 180. * (angle[ i ] < 0 ? 1. : -1.);
890 if (CheckBoxIJKPlaneReverse->isChecked()) {
891 angle[ 0 ] += 180. * (angle[ 0 ] < 0 ? 1. : -1.);
892 distance = 1. - distance;
895 distance = 1. - distance;
898 myIsSelectPlane = true;
899 ComboBoxOrientation->setCurrentItem(axId);
900 setRotation(-angle[0], -angle[1]);
901 setDistance(distance);
902 myIsSelectPlane = false;
904 SetCurrentPlaneParam();
907 //=================================================================================
908 // function : setIJKByNonStructured
909 // purpose : convert current non structured parameters to structured ones
910 //=================================================================================
911 void VisuGUI_ClippingDlg::setIJKByNonStructured()
913 if (!myPrs3d || myPlanes.empty() || !myPrs3d->GetResult())
917 int planeIndex = ComboBoxPlanes->currentItem();
918 OrientedPlane* plane = myPlanes[ planeIndex ].GetPointer();
919 vtkPlaneSource* planeSource = plane->myPlaneSource;
920 float * planeNormal = planeSource->GetNormal();
921 gp_Dir normal(planeNormal[0], planeNormal[1], planeNormal[2]);
923 // find a grid axis most co-directed with plane normal
924 // and cartesian axis most co-directed with plane normal
925 int i, maxAx = 0, gridAxId = 0;
928 const vector<float> *curValues, *values = 0;
929 VISU::Result_i* result = myPrs3d->GetResult();
930 for (i = 0; i < 3; ++i) {
931 VISU::Result_i::TAxis axis = (VISU::Result_i::TAxis) i;
932 curValues = result->GetAxisInfo(myPrs3d->GetMeshName(), axis, dir);
934 double dot = normal * dir;
935 if (Abs(dot) > Abs(maxDot)) {
942 if (Abs (planeNormal[ maxAx ]) < Abs (planeNormal[ i ]))
946 axDir.SetCoord(maxAx + 1, 1.);
949 double v = SpinBoxDistance->value();
951 bool reverse = (normal * axDir < 0); // normal and axis are opposite
952 if (gridDir * axDir < 0) // grid dir and axis are opposite
956 for (i = 0; i < values->size(); ++i)
957 if ((*values)[ i ] > v)
959 if (i == values->size())
961 if (i != 0 && (*values)[ i ] - v > v - (*values)[ i - 1])
964 // set control values
965 myIsSelectPlane = true;
966 CheckBoxIJKPlaneReverse->setChecked(normal * axDir < 0);
967 SpinBoxIJKIndex->setValue(i);
968 ButtonGroupIJKAxis->setButton(gridAxId);
969 onIJKAxisChanged(gridAxId); // update label and range of index
970 myIsSelectPlane = false;
972 SetCurrentPlaneIJKParam();
975 //=================================================================================
976 // function : isStructured
977 // purpose : return true if mesh is structured
978 //=================================================================================
979 bool VisuGUI_ClippingDlg::isStructured() const
981 VISU::Result_i* result = myPrs3d ? myPrs3d->GetResult() : 0;
984 return result->GetAxisInfo(myPrs3d->GetMeshName(),
985 VISU::Result_i::AXIS_X,
991 //=================================================================================
992 // function : onIJKAxisChanged
993 // purpose : update Index range and call SetCurrentPlaneParam()
994 //=================================================================================
995 void VisuGUI_ClippingDlg::onIJKAxisChanged(int axisId)
999 VISU::Result_i* result = myPrs3d ? myPrs3d->GetResult() : 0;
1001 VISU::Result_i::TAxis axis = (VISU::Result_i::TAxis) axisId;
1003 const vector<float> * indices = result->GetAxisInfo(myPrs3d->GetMeshName(),
1006 maxIndex = indices->size() - 1;
1008 QString text = tr("LBL_IJK_INDEX_TO_arg").arg(maxIndex);
1009 TextLabelIJKIndex->setText(text);
1010 SpinBoxIJKIndex->setRange(0, maxIndex);
1012 if (SpinBoxIJKIndex->value() > maxIndex)
1013 SpinBoxIJKIndex->setValue(0);
1015 SetCurrentPlaneIJKParam();
1018 //=================================================================================
1019 // function : OnPreviewToggle()
1021 //=================================================================================
1022 void VisuGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled)
1024 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(theIsToggled));
1025 if (SVTK_ViewWindow* vw = VISU::GetViewWindow(myVisuGUI))
1026 VISU::RenderViewWindow(vw);