2 #include "VisuGUI_ClippingDlg.h"
5 #include "VisuGUI_Tools.h"
7 #include "VISU_Prs3d_i.hh"
8 #include "VISU_Result_i.hh"
10 #include "VISU_PipeLine.hxx"
12 #include "SalomeApp_SelectionMgr.h"
14 #include "SVTK_ViewWindow.h"
16 #include "SUIT_Session.h"
17 #include "SUIT_Desktop.h"
18 #include "SUIT_MessageBox.h"
19 #include "SUIT_ResourceMgr.h"
20 #include "SUIT_OverrideCursor.h"
22 #include "SALOME_Actor.h"
26 #include <qpushbutton.h>
27 #include <qcombobox.h>
28 #include <qcheckbox.h>
30 #include <qgroupbox.h>
31 #include <qvalidator.h>
32 #include <qtabwidget.h>
33 #include <qhbuttongroup.h>
34 #include <qradiobutton.h>
39 #include <vtkCamera.h>
40 #include <vtkRenderer.h>
41 #include <vtkDataSet.h>
42 #include <vtkDataSetMapper.h>
43 #include <vtkImplicitFunction.h>
44 #include <vtkPlaneSource.h>
45 #include <vtkPolyData.h>
46 #include <vtkUnstructuredGrid.h>
54 float GetFloat (const QString& theValue, float theDefault)
56 if (theValue.isEmpty()) return theDefault;
57 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
58 QString aValue = aResourceMgr->stringValue(theValue);
59 if (aValue.isEmpty()) return theDefault;
60 return aValue.toFloat();
63 void RenderViewWindow (SVTK_ViewWindow* vw)
66 //if (vw->getRenderer()->GetActors()->GetNumberOfItems() > 0) {
67 vw->getRenderer()->ResetCameraClippingRange();
73 void RangeStepAndValidator (QtxDblSpinBox* theSpinBox, double min, double max,
74 double step, unsigned short decimals)
76 theSpinBox->setRange(min, max);
77 theSpinBox->setLineStep(step);
78 ((QDoubleValidator*)theSpinBox->validator())->setRange(min, max, decimals);
82 //=================================================================================
83 //class : OrientedPlane
85 //=================================================================================
86 class OrientedPlane: public vtkPlane
88 SVTK_ViewWindow* myViewWindow;
90 vtkDataSetMapper* myMapper;
93 static OrientedPlane * New() {
94 return new OrientedPlane();
96 static OrientedPlane * New (SVTK_ViewWindow* vw) {
97 return new OrientedPlane(vw);
99 vtkTypeMacro(OrientedPlane, vtkPlane);
102 VISU::Orientation myOrientation;
106 vtkPlaneSource* myPlaneSource;
107 SALOME_Actor *myActor;
109 void SetOrientation(VISU::Orientation theOrientation) {myOrientation = theOrientation;}
110 VISU::Orientation GetOrientation() {return myOrientation;}
112 void SetDistance(float theDistance) {myDistance = theDistance;}
113 float GetDistance() {return myDistance;}
115 void ShallowCopy(OrientedPlane* theOrientedPlane){
116 SetNormal(theOrientedPlane->GetNormal());
117 SetOrigin(theOrientedPlane->GetOrigin());
119 myOrientation = theOrientedPlane->GetOrientation();
120 myDistance = theOrientedPlane->GetDistance();
122 myAngle[0] = theOrientedPlane->myAngle[0];
123 myAngle[1] = theOrientedPlane->myAngle[1];
125 myPlaneSource->SetNormal(theOrientedPlane->myPlaneSource->GetNormal());
126 myPlaneSource->SetOrigin(theOrientedPlane->myPlaneSource->GetOrigin());
127 myPlaneSource->SetPoint1(theOrientedPlane->myPlaneSource->GetPoint1());
128 myPlaneSource->SetPoint2(theOrientedPlane->myPlaneSource->GetPoint2());
132 OrientedPlane(SVTK_ViewWindow* vw):
133 myOrientation(VISU::XY),
138 myViewWindow->AddActor(myActor);
142 myOrientation(VISU::XY),
150 myPlaneSource = vtkPlaneSource::New();
152 myAngle[0] = myAngle[1] = 0.0;
154 // Create and display actor
155 myMapper = vtkDataSetMapper::New();
156 myMapper->SetInput(myPlaneSource->GetOutput());
158 myActor = SALOME_Actor::New();
159 myActor->VisibilityOff();
160 myActor->PickableOff();
161 myActor->SetInfinitive(true);
162 myActor->SetMapper(myMapper);
164 vtkProperty* aProp = vtkProperty::New();
166 anRGB[0] = VISU::GetFloat("SMESH:SettingsFillColorRed", 0)/255.;
167 anRGB[1] = VISU::GetFloat("SMESH:SettingsFillColorGreen", 170)/255.;
168 anRGB[2] = VISU::GetFloat("SMESH:SettingsFillColorBlue", 255)/255.;
169 aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
170 aProp->SetOpacity(0.75);
171 myActor->SetProperty(aProp);
174 vtkProperty* aBackProp = vtkProperty::New();
175 anRGB[0] = VISU::GetFloat("SMESH:SettingsBackFaceColorRed", 0)/255.;
176 anRGB[1] = VISU::GetFloat("SMESH:SettingsBackFaceColorGreen", 0)/255.;
177 anRGB[2] = VISU::GetFloat("SMESH:SettingsBackFaceColorBlue", 255)/255.;
178 aBackProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
179 aBackProp->SetOpacity(0.75);
180 myActor->SetBackfaceProperty(aBackProp);
187 myViewWindow->RemoveActor(myActor);
191 myMapper->RemoveAllInputs();
194 myPlaneSource->UnRegisterAllOutputs();
195 myPlaneSource->Delete();
200 OrientedPlane(const OrientedPlane&);
201 void operator=(const OrientedPlane&);
204 struct TSetVisiblity {
205 TSetVisiblity(int theIsVisible): myIsVisible(theIsVisible){}
206 void operator()(VISU::TVTKPlane& theOrientedPlane){
207 theOrientedPlane->myActor->SetVisibility(myIsVisible);
212 //=================================================================================
213 // class : VisuGUI_ClippingDlg()
216 //=================================================================================
217 VisuGUI_ClippingDlg::VisuGUI_ClippingDlg (VisuGUI* theModule,
221 : QDialog(VISU::GetDesktop(theModule), name, modal, WStyle_Customize |
222 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
223 mySelectionMgr(VISU::GetSelectionMgr(theModule)),
227 setName("VisuGUI_ClippingDlg");
228 setCaption(tr("TITLE"));
229 setSizeGripEnabled(TRUE);
230 QGridLayout* VisuGUI_ClippingDlgLayout = new QGridLayout(this);
231 VisuGUI_ClippingDlgLayout->setSpacing(6);
232 VisuGUI_ClippingDlgLayout->setMargin(11);
234 // Controls for selecting, creating, deleting planes
235 QGroupBox* GroupPlanes = new QGroupBox (this, "GroupPlanes");
236 GroupPlanes->setTitle(tr("GRP_PLANES"));
237 GroupPlanes->setColumnLayout(0, Qt::Vertical);
238 GroupPlanes->layout()->setSpacing(0);
239 GroupPlanes->layout()->setMargin(0);
240 QGridLayout* GroupPlanesLayout = new QGridLayout (GroupPlanes->layout());
241 GroupPlanesLayout->setAlignment(Qt::AlignTop);
242 GroupPlanesLayout->setSpacing(6);
243 GroupPlanesLayout->setMargin(11);
245 ComboBoxPlanes = new QComboBox (GroupPlanes, "ComboBoxPlanes");
246 GroupPlanesLayout->addWidget(ComboBoxPlanes, 0, 0);
248 QSpacerItem* spacerGP = new QSpacerItem (20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
249 GroupPlanesLayout->addItem(spacerGP, 0, 1);
251 buttonNew = new QPushButton (GroupPlanes, "buttonNew");
252 buttonNew->setText(tr("BUT_NEW"));
253 GroupPlanesLayout->addWidget(buttonNew, 0, 2);
255 buttonDelete = new QPushButton(GroupPlanes, "buttonDelete");
256 buttonDelete->setText(tr("BUT_DELETE"));
257 GroupPlanesLayout->addWidget(buttonDelete, 0, 3);
259 // Controls for defining plane parameters
262 QGroupBox* GroupParameters = new QGroupBox(this, "GroupParameters");
263 GroupParameters->setTitle(tr("GRP_PARAMETERS"));
264 GroupParameters->setColumnLayout(0, Qt::Vertical);
265 GroupParameters->layout()->setSpacing(0);
266 GroupParameters->layout()->setMargin(0);
267 QGridLayout* GroupParametersLayout = new QGridLayout (GroupParameters->layout());
268 GroupParametersLayout->setAlignment(Qt::AlignTop);
269 GroupParametersLayout->setSpacing(6);
270 GroupParametersLayout->setMargin(11);
272 TabPane = new QTabWidget (GroupParameters);
273 TabPane->addTab(createParamsTab() , tr("TAB_NON_STRUCTURED"));
274 TabPane->addTab(createIJKParamsTab(), tr("TAB_IJK_STRUCTURED"));
275 GroupParametersLayout->addWidget(TabPane, 0, 0);
277 // "Show preview" and "Auto Apply" check boxes
279 PreviewCheckBox = new QCheckBox (tr("SHOW_PREVIEW_CHK"), this);
280 PreviewCheckBox->setChecked(true);
282 AutoApplyCheckBox = new QCheckBox (tr("AUTO_APPLY_CHK"), this);
283 AutoApplyCheckBox->setChecked(false);
285 // Controls for "Ok", "Apply" and "Close" button
286 QGroupBox* GroupButtons = new QGroupBox (this, "GroupButtons");
287 GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7,
288 (QSizePolicy::SizeType)0, 0, 0,
289 GroupButtons->sizePolicy().hasHeightForWidth()));
290 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
291 //GroupButtons->setTitle(tr(""));
292 GroupButtons->setColumnLayout(0, Qt::Vertical);
293 GroupButtons->layout()->setSpacing(0);
294 GroupButtons->layout()->setMargin(0);
295 QGridLayout* GroupButtonsLayout = new QGridLayout (GroupButtons->layout());
296 GroupButtonsLayout->setAlignment(Qt::AlignTop);
297 GroupButtonsLayout->setSpacing(6);
298 GroupButtonsLayout->setMargin(11);
299 buttonCancel = new QPushButton (GroupButtons, "buttonCancel");
300 buttonCancel->setText(tr("BUT_CLOSE"));
301 buttonCancel->setAutoDefault(TRUE);
302 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
303 buttonApply = new QPushButton (GroupButtons, "buttonApply");
304 buttonApply->setText(tr("BUT_APPLY"));
305 buttonApply->setAutoDefault(TRUE);
306 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
307 QSpacerItem* spacer_9 = new QSpacerItem (20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
308 GroupButtonsLayout->addItem(spacer_9, 0, 2);
309 buttonOk = new QPushButton (GroupButtons, "buttonOk");
310 buttonOk->setText(tr("BUT_OK"));
311 buttonOk->setAutoDefault(TRUE);
312 buttonOk->setDefault(TRUE);
313 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
315 VisuGUI_ClippingDlgLayout->addMultiCellWidget(GroupPlanes, 0, 0, 0, 1);
316 VisuGUI_ClippingDlgLayout->addMultiCellWidget(GroupParameters, 1, 1, 0, 1);
317 VisuGUI_ClippingDlgLayout->addWidget(PreviewCheckBox, 2, 0);
318 VisuGUI_ClippingDlgLayout->addWidget(AutoApplyCheckBox, 2, 1);
319 VisuGUI_ClippingDlgLayout->addMultiCellWidget(GroupButtons, 3, 3, 0, 1);
322 VISU::RangeStepAndValidator(SpinBoxDistance, 0.0, 1.0, 0.01, 3);
323 VISU::RangeStepAndValidator(SpinBoxRot1, -180.0, 180.0, 1, 3);
324 VISU::RangeStepAndValidator(SpinBoxRot2, -180.0, 180.0, 1, 3);
326 ComboBoxOrientation->insertItem(tr("PARALLEL_XOY_COMBO_ITEM"));
327 ComboBoxOrientation->insertItem(tr("PARALLEL_YOZ_COMBO_ITEM"));
328 ComboBoxOrientation->insertItem(tr("PARALLEL_ZOX_COMBO_ITEM"));
330 SpinBoxDistance->setValue(0.5);
333 myIsSelectPlane = false;
334 onSelectionChanged();
336 // signals and slots connections :
337 connect(ComboBoxPlanes , SIGNAL(activated(int)) , this, SLOT(onSelectPlane(int)));
338 connect(buttonNew , SIGNAL(clicked()) , this, SLOT(ClickOnNew()));
339 connect(buttonDelete , SIGNAL(clicked()) , this, SLOT(ClickOnDelete()));
340 connect(ComboBoxOrientation , SIGNAL(activated(int)) , this, SLOT(onSelectOrientation(int)));
341 connect(SpinBoxDistance , SIGNAL(valueChanged(double)) , this, SLOT(SetCurrentPlaneParam()));
342 connect(SpinBoxRot1 , SIGNAL(valueChanged(double)) , this, SLOT(SetCurrentPlaneParam()));
343 connect(SpinBoxRot2 , SIGNAL(valueChanged(double)) , this, SLOT(SetCurrentPlaneParam()));
344 connect(ButtonGroupIJKAxis , SIGNAL(clicked(int)) , this, SLOT(onIJKAxisChanged(int)));
345 connect(SpinBoxIJKIndex , SIGNAL(valueChanged(int)) , this, SLOT(SetCurrentPlaneIJKParam()));
346 connect(CheckBoxIJKPlaneReverse, SIGNAL(toggled(bool)) , this, SLOT(SetCurrentPlaneIJKParam()));
347 connect(TabPane , SIGNAL(currentChanged (QWidget*)), this, SLOT(onTabChanged(QWidget*)));
349 connect(PreviewCheckBox , SIGNAL(toggled(bool)), this, SLOT(OnPreviewToggle(bool)));
350 connect(AutoApplyCheckBox, SIGNAL(toggled(bool)), this, SLOT(ClickOnApply()));
352 connect(buttonOk , SIGNAL(clicked()), this, SLOT(ClickOnOk()));
353 connect(buttonApply , SIGNAL(clicked()), this, SLOT(ClickOnApply()));
354 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
356 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
361 //=================================================================================
362 // function : ~VisuGUI_ClippingDlg()
364 //=================================================================================
365 VisuGUI_ClippingDlg::~VisuGUI_ClippingDlg()
367 // no need to delete child widgets, Qt does it all for us
368 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(false));
369 VISU::RenderViewWindow(VISU::GetViewWindow(myVisuGUI));
372 //=================================================================================
373 // function : createParamsTab
375 //=================================================================================
376 QWidget* VisuGUI_ClippingDlg::createParamsTab()
378 QFrame* GroupParameters = new QFrame(this);
379 QGridLayout* GroupParametersLayout = new QGridLayout(GroupParameters);
380 GroupParametersLayout->setAlignment(Qt::AlignTop);
381 GroupParametersLayout->setSpacing(6);
382 GroupParametersLayout->setMargin(11);
384 TextLabelOrientation = new QLabel(GroupParameters, "TextLabelOrientation");
385 TextLabelOrientation->setText(tr("LBL_ORIENTATION"));
386 GroupParametersLayout->addWidget(TextLabelOrientation, 0, 0);
388 ComboBoxOrientation = new QComboBox(GroupParameters, "ComboBoxOrientation");
389 GroupParametersLayout->addWidget(ComboBoxOrientation, 0, 1);
391 TextLabelDistance = new QLabel(GroupParameters, "TextLabelDistance");
392 TextLabelDistance->setText(tr("LBL_DISTANCE"));
393 GroupParametersLayout->addWidget(TextLabelDistance, 1, 0);
395 SpinBoxDistance = new QtxDblSpinBox(GroupParameters, "SpinBoxDistance");
396 GroupParametersLayout->addWidget(SpinBoxDistance, 1, 1);
398 TextLabelRot1 = new QLabel(GroupParameters, "TextLabelRot1");
399 TextLabelRot1->setText(tr("LBL_ROTATION_YZ"));
400 GroupParametersLayout->addWidget(TextLabelRot1, 2, 0);
402 SpinBoxRot1 = new QtxDblSpinBox(GroupParameters, "SpinBoxRot1");
403 GroupParametersLayout->addWidget(SpinBoxRot1, 2, 1);
405 TextLabelRot2 = new QLabel(GroupParameters, "TextLabelRot2");
406 TextLabelRot2->setText(tr("LBL_ROTATION_XZ"));
407 GroupParametersLayout->addWidget(TextLabelRot2, 3, 0);
409 SpinBoxRot2 = new QtxDblSpinBox(GroupParameters, "SpinBoxRot2");
410 GroupParametersLayout->addWidget(SpinBoxRot2, 3, 1);
412 return GroupParameters;
415 //=================================================================================
416 // function : createIJKParamsTab
418 //=================================================================================
419 QWidget* VisuGUI_ClippingDlg::createIJKParamsTab()
422 WidgetIJKTab = new QFrame(this);
423 QGridLayout* IJKParametersLayout = new QGridLayout(WidgetIJKTab);
424 IJKParametersLayout->setAlignment(Qt::AlignTop);
425 IJKParametersLayout->setSpacing(6);
426 IJKParametersLayout->setMargin(11);
429 ButtonGroupIJKAxis = new QHButtonGroup (tr("GRP_IJK_AXIS"), WidgetIJKTab);
430 new QRadioButton (tr("I_RADIO_BTN"), ButtonGroupIJKAxis); // 0
431 new QRadioButton (tr("J_RADIO_BTN"), ButtonGroupIJKAxis); // 1
432 new QRadioButton (tr("K_RADIO_BTN"), ButtonGroupIJKAxis); // 2
433 ButtonGroupIJKAxis->setButton(0);
436 TextLabelIJKIndex = new QLabel(WidgetIJKTab, "TextLabelIJKIndex");
437 TextLabelIJKIndex->setText(tr("LBL_IJK_INDEX"));
438 SpinBoxIJKIndex = new QSpinBox(WidgetIJKTab, "SpinBoxIJKIndex");
441 CheckBoxIJKPlaneReverse = new QCheckBox (tr("REVERSE_NORMAL_CHK"), WidgetIJKTab);
442 CheckBoxIJKPlaneReverse->setChecked(false);
444 IJKParametersLayout->addMultiCellWidget(ButtonGroupIJKAxis, 0, 0, 0, 1);
445 IJKParametersLayout->addWidget(TextLabelIJKIndex, 1, 0);
446 IJKParametersLayout->addWidget(SpinBoxIJKIndex, 1, 1);
447 IJKParametersLayout->addWidget(CheckBoxIJKPlaneReverse, 2, 0);
452 //=================================================================================
453 // function : ClickOnApply()
455 //=================================================================================
456 void VisuGUI_ClippingDlg::ClickOnApply()
461 if (SVTK_ViewWindow* aViewWindow = VISU::GetViewWindow(myVisuGUI)) {
462 SUIT_OverrideCursor wc;
464 // Save clipping planes, currently applied to the presentation
465 // to enable restoring this state in case of failure.
466 // Refer to bugs IPAL8849, IPAL8850 for more information.
467 typedef vtkSmartPointer<vtkPlane> TPln;
468 typedef std::vector<TPln> TPlns;
469 bool isFailed = false;
471 int iopl = 0, nbOldPlanes = myPrs3d->GetNumberOfClippingPlanes();
472 for (; iopl < nbOldPlanes; iopl++) {
473 anOldPlanes.push_back(myPrs3d->GetClippingPlane(iopl));
476 // Try to apply new clipping
477 myPrs3d->RemoveAllClippingPlanes();
479 VISU::TPlanes::iterator anIter = myPlanes.begin();
480 for (; anIter != myPlanes.end(); anIter++) {
481 OrientedPlane* anOrientedPlane = OrientedPlane::New(aViewWindow);
482 anOrientedPlane->ShallowCopy(anIter->GetPointer());
483 if (!myPrs3d->AddClippingPlane(anOrientedPlane)) {
486 anOrientedPlane->Delete();
489 // Check contents of the resulting (clipped) presentation data
491 VISU_PipeLine* aPL = myPrs3d->GetPL();
492 VISU_PipeLine::TMapper* aM = aPL->GetMapper();
493 vtkDataSet* aPrsData = aM->GetInput();
495 if (aPrsData->GetNumberOfCells() < 1) {
501 // Restore previous clipping state because of failure.
502 myPrs3d->RemoveAllClippingPlanes();
504 TPlns::iterator anOldIter = anOldPlanes.begin();
505 for (; anOldIter != anOldPlanes.end(); anOldIter++) {
506 myPrs3d->AddClippingPlane(anOldIter->GetPointer());
509 SUIT_MessageBox::warn1(VISU::GetDesktop(myVisuGUI),
511 tr("WRN_EMPTY_RESULTING_PRS"),
515 VISU::RenderViewWindow(aViewWindow);
519 //=================================================================================
520 // function : ClickOnOk()
522 //=================================================================================
523 void VisuGUI_ClippingDlg::ClickOnOk()
529 //=================================================================================
530 // function : ClickOnCancel()
532 //=================================================================================
533 void VisuGUI_ClippingDlg::ClickOnCancel()
538 //=================================================================================
539 // function : onSelectionChanged()
540 // purpose : Called when selection is changed
541 //=================================================================================
542 void VisuGUI_ClippingDlg::onSelectionChanged()
544 if (SVTK_ViewWindow* aViewWindow = VISU::GetViewWindow(myVisuGUI)) {
545 Handle(SALOME_InteractiveObject) anIO;
546 CORBA::Object_var anObject = VISU::GetSelectedObj(myVisuGUI, &anIO);
547 if (CORBA::is_nil(anObject)) return;
548 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
549 if (!aServant.in()) return;
551 myPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
553 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(false));
557 myPrs3d->GetOffset(anOffset);
559 vtkIdType anId = 0, anEnd = myPrs3d->GetNumberOfClippingPlanes();
560 for (; anId < anEnd; anId++) {
561 if (vtkImplicitFunction* aFunction = myPrs3d->GetClippingPlane(anId)) {
562 if (OrientedPlane* aPlane = OrientedPlane::SafeDownCast(aFunction)) {
563 OrientedPlane* anOrientedPlane = OrientedPlane::New(aViewWindow);
564 VISU::TVTKPlane aTVTKPlane(anOrientedPlane);
565 anOrientedPlane->Delete();
566 aTVTKPlane->ShallowCopy(aPlane);
567 aTVTKPlane->myActor->SetPosition(anOffset);
568 myPlanes.push_back(aTVTKPlane);
573 std::for_each(myPlanes.begin(),myPlanes.end(),
574 TSetVisiblity(PreviewCheckBox->isChecked()));
577 // enable/disable IJK tab
578 TabPane->setTabEnabled(WidgetIJKTab, isStructured());
580 VISU::RenderViewWindow(aViewWindow);
584 //=================================================================================
585 // function : onSelectPlane()
587 //=================================================================================
588 void VisuGUI_ClippingDlg::onSelectPlane(int theIndex)
590 if (!myPrs3d || myPlanes.empty())
593 OrientedPlane* aPlane = myPlanes[theIndex].GetPointer();
596 VISU::Orientation anOrientation = aPlane->GetOrientation();
599 double aRot[2] = {aPlane->myAngle[0], aPlane->myAngle[1]};
601 // Set plane parameters in the dialog
602 myIsSelectPlane = true;
603 setDistance(aPlane->GetDistance());
604 setRotation(aRot[0], aRot[1]);
606 switch (anOrientation) {
607 case VISU::XY: item = 0; break;
608 case VISU::YZ: item = 1; break;
609 case VISU::ZX: item = 2; break;
611 ComboBoxOrientation->setCurrentItem(item);
613 bool isIJK = (TabPane->currentPage() == WidgetIJKTab);
615 setIJKByNonStructured();
617 onSelectOrientation(item);
619 myIsSelectPlane = false;
622 //=================================================================================
623 // function : ClickOnNew()
625 //=================================================================================
626 void VisuGUI_ClippingDlg::ClickOnNew()
631 if (SVTK_ViewWindow* aViewWindow = VISU::GetViewWindow(myVisuGUI)) {
632 OrientedPlane* aPlane = OrientedPlane::New(aViewWindow);
633 VISU::TVTKPlane aTVTKPlane(aPlane);
634 myPlanes.push_back(aTVTKPlane);
637 myPrs3d->GetOffset(anOffset);
638 aTVTKPlane->myActor->SetPosition(anOffset);
640 if (PreviewCheckBox->isChecked())
641 aTVTKPlane->myActor->VisibilityOn();
644 SetCurrentPlaneParam();
648 //=================================================================================
649 // function : ClickOnDelete()
651 //=================================================================================
652 void VisuGUI_ClippingDlg::ClickOnDelete()
654 if (!myPrs3d || myPlanes.empty())
657 int aPlaneIndex = ComboBoxPlanes->currentItem();
659 VISU::TPlanes::iterator anIter = myPlanes.begin() + aPlaneIndex;
660 anIter->GetPointer()->myActor->SetVisibility(false);
661 myPlanes.erase(anIter);
663 if(AutoApplyCheckBox->isChecked())
667 if (SVTK_ViewWindow* aViewWindow = VISU::GetViewWindow(myVisuGUI))
668 VISU::RenderViewWindow(aViewWindow);
671 //=================================================================================
672 // function : onSelectOrientation()
674 //=================================================================================
675 void VisuGUI_ClippingDlg::onSelectOrientation(int theItem)
677 if (myPlanes.empty())
681 TextLabelRot1->setText(tr("LBL_ROTATION_YZ"));
682 TextLabelRot2->setText(tr("LBL_ROTATION_XZ"));
684 else if (theItem == 1) {
685 TextLabelRot1->setText(tr("LBL_ROTATION_ZX"));
686 TextLabelRot2->setText(tr("LBL_ROTATION_YX"));
688 else if (theItem == 2) {
689 TextLabelRot1->setText(tr("LBL_ROTATION_XY"));
690 TextLabelRot2->setText(tr("LBL_ROTATION_ZY"));
693 if((QComboBox*)sender() == ComboBoxOrientation)
694 SetCurrentPlaneParam();
697 //=================================================================================
698 // function : Sinchronize()
699 // purpose : update control values according to plane selection
700 //=================================================================================
701 void VisuGUI_ClippingDlg::Sinchronize()
703 int aNbPlanes = myPlanes.size();
704 ComboBoxPlanes->clear();
707 for (int i = 1; i<=aNbPlanes; i++) {
708 aName = QString(tr("PLANES_COMBO_ITEM_i")).arg(i);
709 ComboBoxPlanes->insertItem(aName);
712 int aPos = ComboBoxPlanes->count() - 1;
713 ComboBoxPlanes->setCurrentItem(aPos);
715 bool anIsControlsEnable = (aPos >= 0);
716 if (anIsControlsEnable) {
719 ComboBoxPlanes->insertItem(tr("PLANES_COMBO_ITEM_no"));
720 SpinBoxRot1->setValue(0.0);
721 SpinBoxRot2->setValue(0.0);
722 SpinBoxDistance->setValue(0.5);
725 buttonDelete ->setEnabled(anIsControlsEnable);
726 buttonApply ->setEnabled(anIsControlsEnable);
727 PreviewCheckBox ->setEnabled(anIsControlsEnable);
728 AutoApplyCheckBox ->setEnabled(anIsControlsEnable);
730 ComboBoxOrientation ->setEnabled(anIsControlsEnable);
731 SpinBoxDistance ->setEnabled(anIsControlsEnable);
732 SpinBoxRot1 ->setEnabled(anIsControlsEnable);
733 SpinBoxRot2 ->setEnabled(anIsControlsEnable);
735 ButtonGroupIJKAxis ->setEnabled(anIsControlsEnable);
736 SpinBoxIJKIndex ->setEnabled(anIsControlsEnable);
737 CheckBoxIJKPlaneReverse->setEnabled(anIsControlsEnable);
740 //=================================================================================
741 // function : setRotation()
743 //=================================================================================
744 void VisuGUI_ClippingDlg::setRotation(const double theRot1, const double theRot2)
746 SpinBoxRot1->setValue(theRot1);
747 SpinBoxRot2->setValue(theRot2);
750 //=================================================================================
751 // function : SetCurrentPlaneParam()
753 //=================================================================================
754 void VisuGUI_ClippingDlg::SetCurrentPlaneParam()
756 if (myPlanes.empty() || myIsSelectPlane)
759 int aCurPlaneIndex = ComboBoxPlanes->currentItem();
761 OrientedPlane* aPlane = myPlanes[aCurPlaneIndex].GetPointer();
764 VISU::Orientation anOrientation;
765 float aDir[3][3] = {{0, 0, 0}, {0, 0, 0}};
767 static double aCoeff = vtkMath::Pi()/180.0;
769 float aRot[2] = {getRotation1(), getRotation2()};
770 aPlane->myAngle[0] = aRot[0];
771 aPlane->myAngle[1] = aRot[1];
773 float anU[2] = {cos(aCoeff*aRot[0]), cos(aCoeff*aRot[1])};
774 float aV[2] = {sqrt(1.0-anU[0]*anU[0]), sqrt(1.0-anU[1]*anU[1])};
775 aV[0] = aRot[0] > 0? aV[0]: -aV[0];
776 aV[1] = aRot[1] > 0? aV[1]: -aV[1];
778 switch (ComboBoxOrientation->currentItem()) {
780 anOrientation = VISU::XY;
790 anOrientation = VISU::YZ;
800 anOrientation = VISU::ZX;
811 vtkMath::Cross(aDir[1],aDir[0],aNormal);
812 vtkMath::Normalize(aNormal);
813 vtkMath::Cross(aNormal,aDir[1],aDir[0]);
816 aPlane->SetOrientation(anOrientation);
817 aPlane->SetDistance(getDistance());
819 myPrs3d->SetPlaneParam(aNormal, 1. - getDistance(), aPlane);
821 vtkDataSet* aDataSet = myPrs3d->GetInput();
822 float *aPnt = aDataSet->GetCenter();
824 float* anOrigin = aPlane->GetOrigin();
825 float aDel = aDataSet->GetLength()/2.0;
827 float aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
828 {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
829 float aParam, aPnt0[3], aPnt1[3], aPnt2[3];
831 float aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
832 aPnt[1] - aDelta[0][1] - aDelta[1][1],
833 aPnt[2] - aDelta[0][2] - aDelta[1][2]};
834 float aPnt02[3] = {aPnt01[0] + aNormal[0],
835 aPnt01[1] + aNormal[1],
836 aPnt01[2] + aNormal[2]};
837 vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
839 float aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
840 aPnt[1] - aDelta[0][1] + aDelta[1][1],
841 aPnt[2] - aDelta[0][2] + aDelta[1][2]};
842 float aPnt12[3] = {aPnt11[0] + aNormal[0],
843 aPnt11[1] + aNormal[1],
844 aPnt11[2] + aNormal[2]};
845 vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
847 float aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
848 aPnt[1] + aDelta[0][1] - aDelta[1][1],
849 aPnt[2] + aDelta[0][2] - aDelta[1][2]};
850 float aPnt22[3] = {aPnt21[0] + aNormal[0],
851 aPnt21[1] + aNormal[1],
852 aPnt21[2] + aNormal[2]};
853 vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
855 vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
856 aPlaneSource->SetNormal(aNormal[0],aNormal[1],aNormal[2]);
857 aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
858 aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
859 aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
861 if (AutoApplyCheckBox->isChecked())
864 if (SVTK_ViewWindow* vw = VISU::GetViewWindow(myVisuGUI))
865 VISU::RenderViewWindow(vw);
868 //=================================================================================
869 // function : onTabChanged
871 //=================================================================================
872 void VisuGUI_ClippingDlg::onTabChanged(QWidget* newTab)
874 if (newTab == WidgetIJKTab) // IJK
875 setIJKByNonStructured();
877 // set correct labels of rotation spin boxes
878 onSelectOrientation(ComboBoxOrientation->currentItem());
882 //=================================================================================
883 // function : SetCurrentPlaneIJKParam
884 // purpose : set non structured parameters by IJK parameters
885 //=================================================================================
886 void VisuGUI_ClippingDlg::SetCurrentPlaneIJKParam()
888 if (myPlanes.empty() || myIsSelectPlane || !WidgetIJKTab->isEnabled())
891 VISU::Result_i* result = myPrs3d ? myPrs3d->GetResult() : 0;
896 int i, axId = ButtonGroupIJKAxis->id (ButtonGroupIJKAxis->selected());
897 VISU::Result_i::TAxis axis = (VISU::Result_i::TAxis) axId;
899 const vector<float> * values =
900 result->GetAxisInfo(myPrs3d->GetMeshName(), axis, dir);
905 int index = SpinBoxIJKIndex->value();
907 if (index < values->size())
908 distance = (*values)[ index ];
910 // find id of axis closest to dir
914 double cos[3] = { gp::DZ() * dir, gp::DX() * dir, gp::DY() * dir };
916 for (i = 0; i < 3; ++i) {
917 if (Abs(cos[ i ]) > Abs (maxCos)) {
922 // find rotation angles
925 (axId == 0) ? 2 : axId - 1,
926 (axId == 2) ? 0 : axId + 1
928 static double aCoeff = 180.0/vtkMath::Pi();
929 for (i = 0; i < 2; ++i) {
930 float cosin = cos[ rotId[ i ]];
933 angle[ i ] = asin(cosin) * aCoeff;
935 angle[ i ] += 180. * (angle[ i ] < 0 ? 1. : -1.);
937 if (CheckBoxIJKPlaneReverse->isChecked()) {
938 angle[ 0 ] += 180. * (angle[ 0 ] < 0 ? 1. : -1.);
939 distance = 1. - distance;
942 distance = 1. - distance;
945 myIsSelectPlane = true;
946 ComboBoxOrientation->setCurrentItem(axId);
947 setRotation(-angle[0], -angle[1]);
948 setDistance(distance);
949 myIsSelectPlane = false;
951 SetCurrentPlaneParam();
954 //=================================================================================
955 // function : setIJKByNonStructured
956 // purpose : convert current non structured parameters to structured ones
957 //=================================================================================
958 void VisuGUI_ClippingDlg::setIJKByNonStructured()
960 if (!myPrs3d || myPlanes.empty() || !myPrs3d->GetResult())
964 int planeIndex = ComboBoxPlanes->currentItem();
965 OrientedPlane* plane = myPlanes[ planeIndex ].GetPointer();
966 vtkPlaneSource* planeSource = plane->myPlaneSource;
967 float * planeNormal = planeSource->GetNormal();
968 gp_Dir normal(planeNormal[0], planeNormal[1], planeNormal[2]);
970 // find a grid axis most co-directed with plane normal
971 // and cartesian axis most co-directed with plane normal
972 int i, maxAx = 0, gridAxId = 0;
975 const vector<float> *curValues, *values = 0;
976 VISU::Result_i* result = myPrs3d->GetResult();
977 for (i = 0; i < 3; ++i) {
978 VISU::Result_i::TAxis axis = (VISU::Result_i::TAxis) i;
979 curValues = result->GetAxisInfo(myPrs3d->GetMeshName(), axis, dir);
981 double dot = normal * dir;
982 if (Abs(dot) > Abs(maxDot)) {
989 if (Abs (planeNormal[ maxAx ]) < Abs (planeNormal[ i ]))
993 axDir.SetCoord(maxAx + 1, 1.);
996 double v = SpinBoxDistance->value();
998 bool reverse = (normal * axDir < 0); // normal and axis are opposite
999 if (gridDir * axDir < 0) // grid dir and axis are opposite
1003 for (i = 0; i < values->size(); ++i)
1004 if ((*values)[ i ] > v)
1006 if (i == values->size())
1008 if (i != 0 && (*values)[ i ] - v > v - (*values)[ i - 1])
1011 // set control values
1012 myIsSelectPlane = true;
1013 CheckBoxIJKPlaneReverse->setChecked(normal * axDir < 0);
1014 SpinBoxIJKIndex->setValue(i);
1015 ButtonGroupIJKAxis->setButton(gridAxId);
1016 onIJKAxisChanged(gridAxId); // update label and range of index
1017 myIsSelectPlane = false;
1019 SetCurrentPlaneIJKParam();
1022 //=================================================================================
1023 // function : isStructured
1024 // purpose : return true if mesh is structured
1025 //=================================================================================
1026 bool VisuGUI_ClippingDlg::isStructured() const
1028 VISU::Result_i* result = myPrs3d ? myPrs3d->GetResult() : 0;
1031 return result->GetAxisInfo(myPrs3d->GetMeshName(),
1032 VISU::Result_i::AXIS_X,
1038 //=================================================================================
1039 // function : onIJKAxisChanged
1040 // purpose : update Index range and call SetCurrentPlaneParam()
1041 //=================================================================================
1042 void VisuGUI_ClippingDlg::onIJKAxisChanged(int axisId)
1046 VISU::Result_i* result = myPrs3d ? myPrs3d->GetResult() : 0;
1048 VISU::Result_i::TAxis axis = (VISU::Result_i::TAxis) axisId;
1050 const vector<float> * indices = result->GetAxisInfo(myPrs3d->GetMeshName(),
1053 maxIndex = indices->size() - 1;
1055 QString text = tr("LBL_IJK_INDEX_TO_arg").arg(maxIndex);
1056 TextLabelIJKIndex->setText(text);
1057 SpinBoxIJKIndex->setRange(0, maxIndex);
1059 if (SpinBoxIJKIndex->value() > maxIndex)
1060 SpinBoxIJKIndex->setValue(0);
1062 SetCurrentPlaneIJKParam();
1065 //=================================================================================
1066 // function : OnPreviewToggle()
1068 //=================================================================================
1069 void VisuGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled)
1071 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(theIsToggled));
1072 if (SVTK_ViewWindow* vw = VISU::GetViewWindow(myVisuGUI))
1073 VISU::RenderViewWindow(vw);