1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "VisuGUI_ClippingDlg.h"
25 #include "VisuGUI_Tools.h"
26 #include "VisuGUI_ViewTools.h"
28 #include "VISU_Prs3d_i.hh"
29 #include "VISU_Result_i.hh"
30 #include "VISU_ColoredPrs3dHolder_i.hh"
32 #include "VISU_PipeLine.hxx"
33 #include "VISU_DataSetActor.h"
35 #include "LightApp_SelectionMgr.h"
36 #include "LightApp_Application.h"
38 #include "SVTK_ViewWindow.h"
39 #include <VTKViewer_Utilities.h>
41 #include "SUIT_Session.h"
42 #include "SUIT_Desktop.h"
43 #include "SUIT_MessageBox.h"
44 #include "SUIT_ResourceMgr.h"
45 #include "SUIT_OverrideCursor.h"
47 #include "SALOME_Actor.h"
48 #include "VISU_ViewManager_i.hh"
56 #include <QButtonGroup>
59 #include <QRadioButton>
62 #include <QPushButton>
63 #include <QListWidget>
64 #include <QVBoxLayout>
65 #include <QHBoxLayout>
66 #include <QStackedWidget>
70 #include <vtkCamera.h>
71 #include <vtkRenderer.h>
72 #include <vtkDataSet.h>
73 #include <vtkDataSetMapper.h>
74 #include <vtkImplicitFunction.h>
75 #include <vtkPlaneSource.h>
76 #include <vtkPolyData.h>
77 #include <vtkUnstructuredGrid.h>
78 #include <vtkProperty.h>
79 #include <vtkImplicitFunctionCollection.h>
87 float GetFloat (const QString& theValue, float theDefault)
89 if (theValue.isEmpty()) return theDefault;
90 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
91 QString aValue = aResourceMgr->stringValue("VISU",theValue);
92 if (aValue.isEmpty()) return theDefault;
93 return aValue.toFloat();
96 void RenderViewWindow (SVTK_ViewWindow* vw)
99 vw->getRenderer()->ResetCameraClippingRange();
104 void RangeStepAndValidator (QtxDoubleSpinBox* theSpinBox, double min, double max,
105 double step, unsigned short decimals)
107 theSpinBox->setRange(min, max);
108 theSpinBox->setSingleStep(step);
109 theSpinBox->setRange(min, max );
110 theSpinBox->setDecimals( decimals);
114 //=================================================================================
115 //class : OrientedPlane
117 //=================================================================================
118 OrientedPlane* OrientedPlane::New()
120 return new OrientedPlane();
123 OrientedPlane* OrientedPlane::New (SVTK_ViewWindow* vw)
125 return new OrientedPlane(vw);
128 void OrientedPlane::SetOrientation(VISU::Orientation theOrientation)
130 myOrientation = theOrientation;
133 VISU::Orientation OrientedPlane::GetOrientation()
135 return myOrientation;
138 void OrientedPlane::SetDistance(float theDistance)
140 myDistance = theDistance;
143 float OrientedPlane::GetDistance()
148 void OrientedPlane::ShallowCopy(OrientedPlane* theOrientedPlane)
150 SetNormal(theOrientedPlane->GetNormal());
151 SetOrigin(theOrientedPlane->GetOrigin());
153 myOrientation = theOrientedPlane->GetOrientation();
154 myDistance = theOrientedPlane->GetDistance();
156 myAngle[0] = theOrientedPlane->myAngle[0];
157 myAngle[1] = theOrientedPlane->myAngle[1];
159 myPlaneSource->SetNormal(theOrientedPlane->myPlaneSource->GetNormal());
160 myPlaneSource->SetOrigin(theOrientedPlane->myPlaneSource->GetOrigin());
161 myPlaneSource->SetPoint1(theOrientedPlane->myPlaneSource->GetPoint1());
162 myPlaneSource->SetPoint2(theOrientedPlane->myPlaneSource->GetPoint2());
165 OrientedPlane::OrientedPlane(SVTK_ViewWindow* vw):
166 myOrientation(VISU::XY),
171 myViewWindow->AddActor(myActor);
174 OrientedPlane::OrientedPlane():
175 myOrientation(VISU::XY),
182 void OrientedPlane::Init()
184 myPlaneSource = vtkPlaneSource::New();
186 myAngle[0] = myAngle[1] = 0.0;
188 // Create and display actor
189 myMapper = vtkDataSetMapper::New();
190 myMapper->SetInput(myPlaneSource->GetOutput());
192 myActor = SALOME_Actor::New();
193 myActor->VisibilityOff();
194 myActor->PickableOff();
195 myActor->SetInfinitive(true);
196 myActor->SetMapper(myMapper);
198 vtkProperty* aProp = vtkProperty::New();
201 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
203 QColor aFillColor = aResourceMgr->colorValue("SMESH", "fill_color", QColor(0, 170, 255));
204 anRGB[0] = aFillColor.red()/255.;
205 anRGB[1] = aFillColor.green()/255.;
206 anRGB[2] = aFillColor.blue()/255.;
207 aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
208 aProp->SetOpacity(0.75);
209 myActor->SetProperty(aProp);
212 vtkProperty* aBackProp = vtkProperty::New();
213 QColor aBackFaceColor = aResourceMgr->colorValue("SMESH", "backface_color", QColor(0, 0, 255));//@
214 anRGB[0] = aBackFaceColor.red()/255.;
215 anRGB[1] = aBackFaceColor.green()/255.;
216 anRGB[2] = aBackFaceColor.blue()/255.;
217 aBackProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
218 aBackProp->SetOpacity(0.75);
219 myActor->SetBackfaceProperty(aBackProp);
223 OrientedPlane::~OrientedPlane()
225 if ( !myViewWindow.isNull() )
226 myViewWindow->RemoveActor(myActor);
230 myMapper->RemoveAllInputs();
233 // commented: porting to vtk 5.0
234 //myPlaneSource->UnRegisterAllOutputs();
235 myPlaneSource->Delete();
238 struct TSetVisiblity {
239 TSetVisiblity(int theIsVisible): myIsVisible(theIsVisible){}
240 void operator()(VISU::TVTKPlane& theOrientedPlane){
241 theOrientedPlane->myActor->SetVisibility(myIsVisible);
246 //=================================================================================
247 // class : VisuGUI_ClippingDlg()
250 //=================================================================================
251 VisuGUI_ClippingDlg::VisuGUI_ClippingDlg (VisuGUI* theModule,
253 : QDialog(VISU::GetDesktop(theModule), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
254 mySelectionMgr(VISU::GetSelectionMgr(theModule)),
255 myVisuGUI(theModule),
257 myIsSelectPlane(false),
260 setWindowTitle(tr("TITLE"));
261 setSizeGripEnabled(TRUE);
262 setAttribute( Qt::WA_DeleteOnClose, true );
264 QVBoxLayout* VisuGUI_ClippingDlgLayout = new QVBoxLayout(this);
265 VisuGUI_ClippingDlgLayout->setSpacing(6);
266 VisuGUI_ClippingDlgLayout->setMargin(11);
268 QStackedWidget* aStackWidget = new QStackedWidget(this);
269 VisuGUI_ClippingDlgLayout->addWidget(aStackWidget);
271 QWidget* aLocalPlanes = new QWidget(aStackWidget);
272 QVBoxLayout* aLocalLayout = new QVBoxLayout(aLocalPlanes);
273 aStackWidget->addWidget(aLocalPlanes);
275 // Controls for selecting, creating, deleting planes
276 QGroupBox* GroupPlanes = new QGroupBox (tr("GRP_PLANES"), aLocalPlanes);
277 QGridLayout* GroupPlanesLayout = new QGridLayout (GroupPlanes);
278 GroupPlanesLayout->setAlignment(Qt::AlignTop);
279 GroupPlanesLayout->setSpacing(6);
280 GroupPlanesLayout->setMargin(11);
281 aLocalLayout->addWidget(GroupPlanes);
283 ComboBoxPlanes = new QComboBox (GroupPlanes);
284 GroupPlanesLayout->addWidget(ComboBoxPlanes, 0, 0);
286 QSpacerItem* spacerGP = new QSpacerItem (20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
287 GroupPlanesLayout->addItem(spacerGP, 0, 1);
289 buttonNew = new QPushButton (GroupPlanes );
290 buttonNew->setText(tr("BUT_NEW"));
291 GroupPlanesLayout->addWidget(buttonNew, 0, 2);
293 buttonDelete = new QPushButton(GroupPlanes);
294 buttonDelete->setText(tr("BUT_DELETE"));
295 GroupPlanesLayout->addWidget(buttonDelete, 0, 3);
297 // Controls for defining plane parameters
300 QGroupBox* GroupParameters = new QGroupBox(tr("GRP_PARAMETERS"), aLocalPlanes);
301 QGridLayout* GroupParametersLayout = new QGridLayout (GroupParameters);
302 GroupParametersLayout->setAlignment(Qt::AlignTop);
303 GroupParametersLayout->setSpacing(6);
304 GroupParametersLayout->setMargin(11);
305 aLocalLayout->addWidget(GroupParameters);
307 TabPane = new QTabWidget (GroupParameters);
308 TabPane->addTab(createParamsTab() , tr("TAB_NON_STRUCTURED"));
309 TabPane->addTab(createIJKParamsTab(), tr("TAB_IJK_STRUCTURED"));
310 GroupParametersLayout->addWidget(TabPane, 0, 0);
316 // "Show preview" and "Auto Apply" check boxes
317 QHBoxLayout* aCheckBoxLayout = new QHBoxLayout(this);
318 VisuGUI_ClippingDlgLayout->addLayout(aCheckBoxLayout);
320 PreviewCheckBox = new QCheckBox (tr("SHOW_PREVIEW_CHK"), this);
321 PreviewCheckBox->setChecked(true);
322 aCheckBoxLayout->addWidget(PreviewCheckBox);
323 aCheckBoxLayout->addStretch();
325 AutoApplyCheckBox = new QCheckBox (tr("AUTO_APPLY_CHK"), this);
326 AutoApplyCheckBox->setChecked(false);
327 aCheckBoxLayout->addWidget(AutoApplyCheckBox);
329 // Controls for "Ok", "Apply" and "Close" button
330 QGroupBox* GroupButtons = new QGroupBox (this);
331 VisuGUI_ClippingDlgLayout->addWidget(GroupButtons);
332 QSizePolicy aSizePolicy(QSizePolicy::Expanding,
333 QSizePolicy::Fixed );
334 aSizePolicy.setHeightForWidth( GroupButtons->sizePolicy().hasHeightForWidth() );
335 aSizePolicy.setHorizontalStretch( 0 );
336 aSizePolicy.setVerticalStretch( 0 );
337 GroupButtons->setSizePolicy( aSizePolicy );
338 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
339 QGridLayout* GroupButtonsLayout = new QGridLayout (GroupButtons);
340 GroupButtons->setLayout(GroupButtonsLayout);
341 GroupButtonsLayout->setAlignment(Qt::AlignTop);
342 GroupButtonsLayout->setSpacing(6);
343 GroupButtonsLayout->setMargin(11);
344 buttonHelp = new QPushButton (GroupButtons);
345 buttonHelp->setText(tr("BUT_HELP"));
346 buttonHelp->setAutoDefault(TRUE);
347 GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
348 buttonCancel = new QPushButton (GroupButtons);
349 buttonCancel->setText(tr("BUT_CLOSE"));
350 buttonCancel->setAutoDefault(TRUE);
351 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
352 buttonApply = new QPushButton (GroupButtons);
353 buttonApply->setText(tr("BUT_APPLY"));
354 buttonApply->setAutoDefault(TRUE);
355 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
356 QSpacerItem* spacer_9 = new QSpacerItem (20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
357 GroupButtonsLayout->addItem(spacer_9, 0, 2);
358 buttonOk = new QPushButton (GroupButtons);
359 buttonOk->setText(tr("BUT_OK"));
360 buttonOk->setAutoDefault(TRUE);
361 buttonOk->setDefault(TRUE);
362 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
365 VISU::RangeStepAndValidator(SpinBoxDistance, 0.0, 1.0, 0.01, 3);
366 VISU::RangeStepAndValidator(SpinBoxRot1, -180.0, 180.0, 1, 3);
367 VISU::RangeStepAndValidator(SpinBoxRot2, -180.0, 180.0, 1, 3);
369 ComboBoxOrientation->addItem(tr("PARALLEL_XOY_COMBO_ITEM"));
370 ComboBoxOrientation->addItem(tr("PARALLEL_YOZ_COMBO_ITEM"));
371 ComboBoxOrientation->addItem(tr("PARALLEL_ZOX_COMBO_ITEM"));
373 SpinBoxDistance->setValue(0.5);
375 onSelectionChanged();
377 // signals and slots connections :
378 connect(ComboBoxPlanes , SIGNAL(activated(int)) , this, SLOT(onSelectPlane(int)));
379 connect(buttonNew , SIGNAL(clicked()) , this, SLOT(ClickOnNew()));
380 connect(buttonDelete , SIGNAL(clicked()) , this, SLOT(ClickOnDelete()));
381 connect(ComboBoxOrientation , SIGNAL(activated(int)) , this, SLOT(onSelectOrientation(int)));
382 connect(SpinBoxDistance , SIGNAL(valueChanged(double)) , this, SLOT(SetCurrentPlaneParam()));
383 connect(SpinBoxRot1 , SIGNAL(valueChanged(double)) , this, SLOT(SetCurrentPlaneParam()));
384 connect(SpinBoxRot2 , SIGNAL(valueChanged(double)) , this, SLOT(SetCurrentPlaneParam()));
385 connect(ButtonGroupIJKAxis , SIGNAL(buttonClicked(int)) , this, SLOT(onIJKAxisChanged(int)));
386 connect(SpinBoxIJKIndex , SIGNAL(valueChanged(int)) , this, SLOT(SetCurrentPlaneIJKParam()));
387 connect(CheckBoxIJKPlaneReverse, SIGNAL(toggled(bool)) , this, SLOT(SetCurrentPlaneIJKParam()));
388 connect(TabPane , SIGNAL(currentChanged (QWidget*)), this, SLOT(onTabChanged(QWidget*)));
390 connect(PreviewCheckBox , SIGNAL(toggled(bool)), this, SLOT(OnPreviewToggle(bool)));
391 connect(AutoApplyCheckBox, SIGNAL(toggled(bool)), this, SLOT(ClickOnApply()));
393 connect(buttonOk , SIGNAL(clicked()), this, SLOT(ClickOnOk()));
394 connect(buttonApply , SIGNAL(clicked()), this, SLOT(ClickOnApply()));
395 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
396 connect(buttonHelp , SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
398 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
403 //=================================================================================
404 // function : ~VisuGUI_ClippingDlg()
406 //=================================================================================
407 VisuGUI_ClippingDlg::~VisuGUI_ClippingDlg()
409 // no need to delete child widgets, Qt does it all for us
411 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(false));
412 VISU::RenderViewWindow(VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI));
415 //=================================================================================
416 // function : createParamsTab
418 //=================================================================================
419 QWidget* VisuGUI_ClippingDlg::createParamsTab()
421 QFrame* GroupParameters = new QFrame(this);
422 QGridLayout* GroupParametersLayout = new QGridLayout(GroupParameters);
423 GroupParametersLayout->setAlignment(Qt::AlignTop);
424 GroupParametersLayout->setSpacing(6);
425 GroupParametersLayout->setMargin(11);
427 TextLabelOrientation = new QLabel(GroupParameters);
428 TextLabelOrientation->setText(tr("LBL_ORIENTATION"));
429 GroupParametersLayout->addWidget(TextLabelOrientation, 0, 0);
431 ComboBoxOrientation = new QComboBox(GroupParameters);
432 GroupParametersLayout->addWidget(ComboBoxOrientation, 0, 1);
434 TextLabelDistance = new QLabel(GroupParameters);
435 TextLabelDistance->setText(tr("LBL_DISTANCE"));
436 GroupParametersLayout->addWidget(TextLabelDistance, 1, 0);
438 SpinBoxDistance = new QtxDoubleSpinBox(GroupParameters);
439 GroupParametersLayout->addWidget(SpinBoxDistance, 1, 1);
441 TextLabelRot1 = new QLabel(GroupParameters);
442 TextLabelRot1->setText(tr("LBL_ROTATION_YZ"));
443 GroupParametersLayout->addWidget(TextLabelRot1, 2, 0);
445 SpinBoxRot1 = new QtxDoubleSpinBox(GroupParameters);
446 GroupParametersLayout->addWidget(SpinBoxRot1, 2, 1);
448 TextLabelRot2 = new QLabel(GroupParameters);
449 TextLabelRot2->setText(tr("LBL_ROTATION_XZ"));
450 GroupParametersLayout->addWidget(TextLabelRot2, 3, 0);
452 SpinBoxRot2 = new QtxDoubleSpinBox(GroupParameters);
453 GroupParametersLayout->addWidget(SpinBoxRot2, 3, 1);
455 return GroupParameters;
458 //=================================================================================
459 // function : createIJKParamsTab
461 //=================================================================================
462 QWidget* VisuGUI_ClippingDlg::createIJKParamsTab()
465 WidgetIJKTab = new QFrame(this);
466 QGridLayout* IJKParametersLayout = new QGridLayout(WidgetIJKTab);
467 IJKParametersLayout->setAlignment(Qt::AlignTop);
468 IJKParametersLayout->setSpacing(6);
469 IJKParametersLayout->setMargin(11);
472 ButtonGroupIJKAxis = new QButtonGroup ( WidgetIJKTab);
473 //QGroupBox* aGBGroupBoxIJKAxis= new QGroupBox(tr("GRP_IJK_AXIS"), WidgetIJKTab );
474 GroupBoxIJKAxis= new QGroupBox(tr("GRP_IJK_AXIS"), WidgetIJKTab );
475 QHBoxLayout* aHBLay = new QHBoxLayout( GroupBoxIJKAxis );
476 ButtonGroupIJKAxis->addButton( new QRadioButton (tr("I_RADIO_BTN"), GroupBoxIJKAxis), 0 ); // 0
477 ButtonGroupIJKAxis->addButton( new QRadioButton (tr("J_RADIO_BTN"), GroupBoxIJKAxis), 1 ); // 1
478 ButtonGroupIJKAxis->addButton( new QRadioButton (tr("K_RADIO_BTN"), GroupBoxIJKAxis), 2 ); // 2
479 ButtonGroupIJKAxis->button(0)->setChecked(true);
480 aHBLay->addWidget( ButtonGroupIJKAxis->button(0) );
481 aHBLay->addWidget( ButtonGroupIJKAxis->button(1) );
482 aHBLay->addWidget( ButtonGroupIJKAxis->button(2) );
485 TextLabelIJKIndex = new QLabel(WidgetIJKTab);
486 TextLabelIJKIndex->setText(tr("LBL_IJK_INDEX"));
487 SpinBoxIJKIndex = new QSpinBox(WidgetIJKTab);
490 CheckBoxIJKPlaneReverse = new QCheckBox (tr("REVERSE_NORMAL_CHK"), WidgetIJKTab);
491 CheckBoxIJKPlaneReverse->setChecked(false);
493 IJKParametersLayout->addWidget(GroupBoxIJKAxis, 0, 0, 1, 2);
494 IJKParametersLayout->addWidget(TextLabelIJKIndex, 1, 0);
495 IJKParametersLayout->addWidget(SpinBoxIJKIndex, 1, 1);
496 IJKParametersLayout->addWidget(CheckBoxIJKPlaneReverse, 2, 0);
501 //=================================================================================
502 // function : ClickOnApply()
504 //=================================================================================
505 void VisuGUI_ClippingDlg::ClickOnApply()
511 //=================================================================================
512 // function : applyLocalPlanes()
514 //=================================================================================
515 void VisuGUI_ClippingDlg::applyLocalPlanes()
520 if (SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI)) {
521 SUIT_OverrideCursor wc;
523 QWidget *aCurrWid = this->focusWidget();
524 aCurrWid->clearFocus();
525 aCurrWid->setFocus();
527 // Save clipping planes, currently applied to the presentation
528 // to enable restoring this state in case of failure.
529 // Refer to bugs IPAL8849, IPAL8850 for more information.
530 typedef vtkSmartPointer<vtkPlane> TPln;
531 typedef std::vector<TPln> TPlns;
532 bool isFailed = false;
534 int iopl = 0, nbOldPlanes = myPrs3d->GetNumberOfClippingPlanes();
535 for (; iopl < nbOldPlanes; iopl++) {
536 anOldPlanes.push_back(myPrs3d->GetClippingPlane(iopl));
539 // Try to apply new clipping
540 //myPrs3d->RemoveAllClippingPlanes();
541 removeAllClippingPlanes(myPrs3d);
543 VISU::TPlanes::iterator anIter = myPlanes.begin();
544 for (; anIter != myPlanes.end(); anIter++) {
545 OrientedPlane* anOrientedPlane = OrientedPlane::New(aViewWindow);
546 anOrientedPlane->ShallowCopy(anIter->GetPointer());
547 if (!myPrs3d->AddClippingPlane(anOrientedPlane)) {
550 anOrientedPlane->Delete();
553 // Check contents of the resulting (clipped) presentation data
555 VISU_PipeLine* aPL = myPrs3d->GetPipeLine();
556 vtkMapper* aMapper = aPL->GetMapper();
557 vtkDataSet* aPrsData = aMapper->GetInput();
559 if (aPrsData->GetNumberOfCells() < 1) {
565 // Restore previous clipping state because of failure.
566 //myPrs3d->RemoveAllClippingPlanes();
567 removeAllClippingPlanes(myPrs3d);
569 TPlns::iterator anOldIter = anOldPlanes.begin();
570 for (; anOldIter != anOldPlanes.end(); anOldIter++) {
571 myPrs3d->AddClippingPlane(anOldIter->GetPointer());
574 SUIT_MessageBox::warning(VISU::GetDesktop(myVisuGUI),
576 tr("WRN_EMPTY_RESULTING_PRS"),
580 //VISU::RenderViewWindow(aViewWindow);
581 VISU::RepaintViewWindows(myVisuGUI, myIO);
588 //=================================================================================
589 // function : ClickOnOk()
591 //=================================================================================
592 void VisuGUI_ClippingDlg::ClickOnOk()
598 //=================================================================================
599 // function : ClickOnCancel()
601 //=================================================================================
602 void VisuGUI_ClippingDlg::ClickOnCancel()
607 //=================================================================================
608 // function : ClickOnHelp()
610 //=================================================================================
611 void VisuGUI_ClippingDlg::ClickOnHelp()
613 QString aHelpFileName = "clipping_page.html";
614 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
616 app->onHelpContextModule(myVisuGUI ? app->moduleName(myVisuGUI->moduleName()) : QString(""), aHelpFileName);
620 platform = "winapplication";
622 platform = "application";
624 SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
625 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
626 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
627 QObject::tr("BUT_OK"));
631 //=================================================================================
632 // function : onSelectionChanged()
633 // purpose : Called when selection is changed
634 //=================================================================================
635 void VisuGUI_ClippingDlg::onSelectionChanged()
637 if(SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI)){
639 VISU::TSelectionInfo aSelectionInfo = VISU::GetSelectedObjects(myVisuGUI);
640 if(aSelectionInfo.empty())
643 VISU::TSelectionItem aSelectionItem = aSelectionInfo.front();
644 VISU::Base_i* aBase = aSelectionItem.myObjectInfo.myBase;
648 Handle(SALOME_InteractiveObject) anIO = aSelectionItem.myIO;
653 // rnv: fix for issue 0020114 (EDF VISU 918 : Impossible to
654 // create a new clipping plane on field presentation)
655 // set last visited presentation from holder as myPrs3d
656 VISU::ColoredPrs3dHolder_i* aHolder = dynamic_cast<VISU::ColoredPrs3dHolder_i*>(aBase);
657 VISU::Prs3d_i* aPrs3d = NULL;
659 aPrs3d = aHolder->GetPrs3dDevice();
661 aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aBase);
666 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(false));
669 CORBA::Float anOffset[3];
670 myPrs3d->GetOffset(anOffset[0],anOffset[1],anOffset[2]);
672 vtkIdType anId = 0, anEnd = myPrs3d->GetNumberOfClippingPlanes();
673 for (; anId < anEnd; anId++) {
674 if (vtkImplicitFunction* aFunction = myPrs3d->GetClippingPlane(anId)) {
675 if (OrientedPlane* aPlane = OrientedPlane::SafeDownCast(aFunction)) {
676 OrientedPlane* anOrientedPlane = OrientedPlane::New(aViewWindow);
677 VISU::TVTKPlane aTVTKPlane(anOrientedPlane);
678 anOrientedPlane->Delete();
679 aTVTKPlane->ShallowCopy(aPlane);
680 aTVTKPlane->myActor->SetPosition(anOffset[0],anOffset[1],anOffset[2]);
681 myPlanes.push_back(aTVTKPlane);
686 std::for_each(myPlanes.begin(),myPlanes.end(),
687 TSetVisiblity(PreviewCheckBox->isChecked()));
690 // enable/disable IJK tab
691 TabPane->setTabEnabled(TabPane->indexOf(WidgetIJKTab), isStructured());
693 VISU::RenderViewWindow(aViewWindow);
697 //=================================================================================
698 // function : onSelectPlane()
700 //=================================================================================
701 void VisuGUI_ClippingDlg::onSelectPlane(int theIndex)
703 if (!myPrs3d || myPlanes.empty())
706 OrientedPlane* aPlane = myPlanes[theIndex].GetPointer();
709 VISU::Orientation anOrientation = aPlane->GetOrientation();
712 double aRot[2] = {aPlane->myAngle[0], aPlane->myAngle[1]};
714 // Set plane parameters in the dialog
715 myIsSelectPlane = true;
716 setDistance(aPlane->GetDistance());
717 setRotation(aRot[0], aRot[1]);
719 switch (anOrientation) {
720 case VISU::XY: item = 0; break;
721 case VISU::YZ: item = 1; break;
722 case VISU::ZX: item = 2; break;
724 ComboBoxOrientation->setCurrentIndex(item);
726 bool isIJK = (TabPane->currentWidget() == WidgetIJKTab);
728 setIJKByNonStructured();
730 onSelectOrientation(item);
732 myIsSelectPlane = false;
735 //=================================================================================
736 // function : ClickOnNew()
738 //=================================================================================
739 void VisuGUI_ClippingDlg::ClickOnNew()
741 VISU::TSelectionInfo aSelectionInfo = VISU::GetSelectedObjects(myVisuGUI);
742 if(aSelectionInfo.empty())
745 const VISU::TSelectionItem& aSelectionItem = aSelectionInfo[0];
746 if(!aSelectionItem.myObjectInfo.myBase)
749 SetCurrentPlaneParam();
754 if (SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI)) {
755 OrientedPlane* aPlane = OrientedPlane::New(aViewWindow);
756 VISU::TVTKPlane aTVTKPlane(aPlane);
757 myPlanes.push_back(aTVTKPlane);
759 CORBA::Float anOffset[3];
760 myPrs3d->GetOffset(anOffset[0],anOffset[1],anOffset[2]);
761 aTVTKPlane->myActor->SetPosition(anOffset[0],anOffset[1],anOffset[2]);
763 if (PreviewCheckBox->isChecked())
764 aTVTKPlane->myActor->VisibilityOn();
767 SetCurrentPlaneParam();
771 //=================================================================================
772 // function : ClickOnDelete()
774 //=================================================================================
775 void VisuGUI_ClippingDlg::ClickOnDelete()
777 if (!myPrs3d || myPlanes.empty())
780 int aPlaneIndex = ComboBoxPlanes->currentIndex();
782 VISU::TPlanes::iterator anIter = myPlanes.begin() + aPlaneIndex;
783 anIter->GetPointer()->myActor->SetVisibility(false);
784 myPlanes.erase(anIter);
786 if(AutoApplyCheckBox->isChecked())
790 if (SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI))
791 VISU::RenderViewWindow(aViewWindow);
794 //=================================================================================
795 // function : onSelectOrientation()
797 //=================================================================================
798 void VisuGUI_ClippingDlg::onSelectOrientation(int theItem)
800 if (myPlanes.empty())
804 TextLabelRot1->setText(tr("LBL_ROTATION_YZ"));
805 TextLabelRot2->setText(tr("LBL_ROTATION_XZ"));
807 else if (theItem == 1) {
808 TextLabelRot1->setText(tr("LBL_ROTATION_ZX"));
809 TextLabelRot2->setText(tr("LBL_ROTATION_YX"));
811 else if (theItem == 2) {
812 TextLabelRot1->setText(tr("LBL_ROTATION_XY"));
813 TextLabelRot2->setText(tr("LBL_ROTATION_ZY"));
816 if((QComboBox*)sender() == ComboBoxOrientation)
817 SetCurrentPlaneParam();
820 //=================================================================================
821 // function : Sinchronize()
822 // purpose : update control values according to plane selection
823 //=================================================================================
824 void VisuGUI_ClippingDlg::Sinchronize()
826 int aNbPlanes = myPlanes.size();
827 ComboBoxPlanes->clear();
830 for (int i = 1; i<=aNbPlanes; i++) {
831 aName = QString(tr("PLANES_COMBO_ITEM_i")).arg(i);
832 ComboBoxPlanes->addItem(aName);
835 int aPos = ComboBoxPlanes->count() - 1;
836 ComboBoxPlanes->setCurrentIndex(aPos);
838 bool anIsControlsEnable = (aPos >= 0);
839 if (anIsControlsEnable) {
842 ComboBoxPlanes->addItem(tr("PLANES_COMBO_ITEM_no"));
843 SpinBoxRot1->setValue(0.0);
844 SpinBoxRot2->setValue(0.0);
845 SpinBoxDistance->setValue(0.5);
848 buttonDelete ->setEnabled(anIsControlsEnable);
849 //buttonApply ->setEnabled(anIsControlsEnable);
850 // PreviewCheckBox ->setEnabled(anIsControlsEnable);
851 // AutoApplyCheckBox ->setEnabled(anIsControlsEnable);
853 ComboBoxOrientation ->setEnabled(anIsControlsEnable);
854 SpinBoxDistance ->setEnabled(anIsControlsEnable);
855 SpinBoxRot1 ->setEnabled(anIsControlsEnable);
856 SpinBoxRot2 ->setEnabled(anIsControlsEnable);
858 GroupBoxIJKAxis ->setEnabled(anIsControlsEnable);
859 SpinBoxIJKIndex ->setEnabled(anIsControlsEnable);
860 CheckBoxIJKPlaneReverse->setEnabled(anIsControlsEnable);
861 //ENK: 23.11.2006 - PAL13176 - EDF228 VISU : Enhancement of structured datas processing
863 VISU_PipeLine* aPipeLine = myPrs3d->GetPipeLine();
864 VISU::PIDMapper anIDMapper = aPipeLine->GetIDMapper();
865 if ( anIDMapper->IsStructured() ) {
866 VISU::TStructuredId aStructuredId = anIDMapper->GetStructure();
867 ButtonGroupIJKAxis->button(0)->setEnabled( aStructuredId[0] >= 0 );
868 ButtonGroupIJKAxis->button(1)->setEnabled( aStructuredId[1] >= 0 );
869 ButtonGroupIJKAxis->button(2)->setEnabled( aStructuredId[2] >= 0 );
875 //=================================================================================
876 // function : setRotation()
878 //=================================================================================
879 void VisuGUI_ClippingDlg::setRotation(const double theRot1, const double theRot2)
881 SpinBoxRot1->setValue(theRot1);
882 SpinBoxRot2->setValue(theRot2);
885 //=================================================================================
886 // function : SetCurrentPlaneParam()
888 //=================================================================================
889 void VisuGUI_ClippingDlg::SetCurrentPlaneParam()
891 if (myPlanes.empty() || myIsSelectPlane)
894 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
896 OrientedPlane* aPlane = myPlanes[aCurPlaneIndex].GetPointer();
898 vtkFloatingPointType aNormal[3];
899 VISU::Orientation anOrientation;
900 vtkFloatingPointType aDir[3][3] = {{0, 0, 0}, {0, 0, 0}};
902 static double aCoeff = vtkMath::Pi()/180.0;
904 vtkFloatingPointType aRot[2] = {getRotation1(), getRotation2()};
905 aPlane->myAngle[0] = aRot[0];
906 aPlane->myAngle[1] = aRot[1];
908 vtkFloatingPointType anU[2] = {cos(aCoeff*aRot[0]), cos(aCoeff*aRot[1])};
909 vtkFloatingPointType aV[2] = {sqrt(1.0-anU[0]*anU[0]), sqrt(1.0-anU[1]*anU[1])};
910 aV[0] = aRot[0] > 0? aV[0]: -aV[0];
911 aV[1] = aRot[1] > 0? aV[1]: -aV[1];
913 switch (ComboBoxOrientation->currentIndex()) {
915 anOrientation = VISU::XY;
925 anOrientation = VISU::YZ;
935 anOrientation = VISU::ZX;
946 vtkMath::Cross(aDir[1],aDir[0],aNormal);
947 vtkMath::Normalize(aNormal);
948 vtkMath::Cross(aNormal,aDir[1],aDir[0]);
951 aPlane->SetOrientation(anOrientation);
952 aPlane->SetDistance(getDistance());
954 myPrs3d->SetPlaneParam(aNormal, 1. - getDistance(), aPlane);
956 vtkDataSet* aDataSet = myPrs3d->GetInput();
957 vtkFloatingPointType *aPnt = aDataSet->GetCenter();
959 vtkFloatingPointType* anOrigin = aPlane->GetOrigin();
960 vtkFloatingPointType aDel = aDataSet->GetLength()/2.0;
962 vtkFloatingPointType aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
963 {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
964 vtkFloatingPointType aParam, aPnt0[3], aPnt1[3], aPnt2[3];
966 vtkFloatingPointType aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
967 aPnt[1] - aDelta[0][1] - aDelta[1][1],
968 aPnt[2] - aDelta[0][2] - aDelta[1][2]};
969 vtkFloatingPointType aPnt02[3] = {aPnt01[0] + aNormal[0],
970 aPnt01[1] + aNormal[1],
971 aPnt01[2] + aNormal[2]};
972 vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
974 vtkFloatingPointType aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
975 aPnt[1] - aDelta[0][1] + aDelta[1][1],
976 aPnt[2] - aDelta[0][2] + aDelta[1][2]};
977 vtkFloatingPointType aPnt12[3] = {aPnt11[0] + aNormal[0],
978 aPnt11[1] + aNormal[1],
979 aPnt11[2] + aNormal[2]};
980 vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
982 vtkFloatingPointType aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
983 aPnt[1] + aDelta[0][1] - aDelta[1][1],
984 aPnt[2] + aDelta[0][2] - aDelta[1][2]};
985 vtkFloatingPointType aPnt22[3] = {aPnt21[0] + aNormal[0],
986 aPnt21[1] + aNormal[1],
987 aPnt21[2] + aNormal[2]};
988 vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
990 vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
991 aPlaneSource->SetNormal(aNormal[0],aNormal[1],aNormal[2]);
992 aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
993 aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
994 aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
996 if (AutoApplyCheckBox->isChecked())
999 if (SVTK_ViewWindow* vw = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI))
1000 VISU::RenderViewWindow(vw);
1003 //=================================================================================
1004 // function : onTabChanged
1006 //=================================================================================
1007 void VisuGUI_ClippingDlg::onTabChanged(QWidget* newTab)
1009 if (newTab == WidgetIJKTab) // IJK
1010 setIJKByNonStructured();
1012 // set correct labels of rotation spin boxes
1013 onSelectOrientation(ComboBoxOrientation->currentIndex());
1017 //=================================================================================
1018 // function : SetCurrentPlaneIJKParam
1019 // purpose : set non structured parameters by IJK parameters
1020 //=================================================================================
1021 void VisuGUI_ClippingDlg::SetCurrentPlaneIJKParam()
1023 if (myPlanes.empty() || myIsSelectPlane || !WidgetIJKTab->isEnabled())
1026 VISU::Result_i* result = myPrs3d ? myPrs3d->GetCResult() : 0;
1031 int i, axId = ButtonGroupIJKAxis->id (ButtonGroupIJKAxis->checkedButton());
1032 VISU::Result_i::TAxis axis = (VISU::Result_i::TAxis) axId;
1034 CORBA::String_var aMeshName = myPrs3d->GetMeshName();
1035 const vector<vtkFloatingPointType> * values =
1036 result->GetAxisInfo(aMeshName.in(), axis, dir);
1041 int index = SpinBoxIJKIndex->value();
1042 vtkFloatingPointType distance = 0;
1043 if (index < values->size())
1044 distance = (*values)[ index ];
1046 // find id of axis closest to dir
1047 // 0 || X-Y - axis Z
1048 // 1 || Y-Z - azis X
1049 // 2 || Z-X - axiz Y
1050 double cos[3] = { gp::DZ() * dir, gp::DX() * dir, gp::DY() * dir };
1052 for (i = 0; i < 3; ++i) {
1053 if (Abs(cos[ i ]) > Abs (maxCos)) {
1058 // find rotation angles
1059 vtkFloatingPointType angle[2];
1061 (axId == 0) ? 2 : axId - 1,
1062 (axId == 2) ? 0 : axId + 1
1064 static double aCoeff = 180.0/vtkMath::Pi();
1065 for (i = 0; i < 2; ++i) {
1066 vtkFloatingPointType cosin = cos[ rotId[ i ]];
1069 angle[ i ] = asin(cosin) * aCoeff;
1071 // angle[ i ] += 180. * (angle[ i ] < 0 ? 1. : -1.);
1073 if (CheckBoxIJKPlaneReverse->isChecked()) {
1074 angle[ 0 ] += 180. * (angle[ 0 ] < 0 ? 1. : -1.);
1075 distance = 1. - distance;
1078 // distance = 1. - distance;
1081 myIsSelectPlane = true;
1082 ComboBoxOrientation->setCurrentIndex(axId);
1083 setRotation(-angle[0], -angle[1]);
1084 setDistance(distance);
1085 myIsSelectPlane = false;
1087 SetCurrentPlaneParam();
1090 //=================================================================================
1091 // function : setIJKByNonStructured
1092 // purpose : convert current non structured parameters to structured ones
1093 //=================================================================================
1094 void VisuGUI_ClippingDlg::setIJKByNonStructured()
1096 if (!myPrs3d || myPlanes.empty() || !myPrs3d->GetCResult())
1100 int planeIndex = ComboBoxPlanes->currentIndex();
1101 OrientedPlane* plane = myPlanes[ planeIndex ].GetPointer();
1102 vtkPlaneSource* planeSource = plane->myPlaneSource;
1103 vtkFloatingPointType * planeNormal = planeSource->GetNormal();
1104 gp_Dir normal(planeNormal[0], planeNormal[1], planeNormal[2]);
1106 // find a grid axis most co-directed with plane normal
1107 // and cartesian axis most co-directed with plane normal
1108 int i, maxAx = 0, gridAxId = 0;
1109 gp_Dir dir, gridDir;
1111 const vector<vtkFloatingPointType> *curValues, *values = 0;
1112 VISU::Result_i* result = myPrs3d->GetCResult();
1114 VISU_PipeLine* aPipeLine = myPrs3d->GetPipeLine();
1115 VISU::PIDMapper anIDMapper = aPipeLine->GetIDMapper();
1116 if ( anIDMapper->IsStructured() && !anIDMapper->myIsPolarType )
1117 aNbAxes = anIDMapper->GetStructureDim();
1118 for (i = 0; i < aNbAxes; ++i) {
1119 VISU::Result_i::TAxis axis = (VISU::Result_i::TAxis) i;
1120 CORBA::String_var aMeshName = myPrs3d->GetMeshName();
1121 curValues = result->GetAxisInfo(aMeshName.in(), axis, dir);
1123 double dot = normal * dir;
1124 //ENK: 23.11.2006 - PAL13176
1130 } else if (Abs(dot) >= Abs(maxDot)) {
1138 if (Abs (planeNormal[ maxAx ]) < Abs (planeNormal[ i ]))
1141 gp_XYZ axDir(0,0,0);
1142 axDir.SetCoord(maxAx + 1, 1.);
1145 double v = SpinBoxDistance->value();
1147 // bool reverse = (normal * axDir < 0); // normal and axis are opposite
1148 // if (gridDir * axDir < 0) // grid dir and axis are opposite
1149 // reverse = !reverse;
1152 for (i = 0; i < values->size(); ++i)
1153 if ((*values)[ i ] > v)
1155 if (i == values->size())
1157 if (i != 0 && (*values)[ i ] - v > v - (*values)[ i - 1])
1160 // set control values
1161 myIsSelectPlane = true;
1162 CheckBoxIJKPlaneReverse->setChecked(normal * axDir < 0);
1163 SpinBoxIJKIndex->setValue(i);
1164 ButtonGroupIJKAxis->button(gridAxId)->setChecked( true );
1165 onIJKAxisChanged(gridAxId); // update label and range of index
1166 myIsSelectPlane = false;
1168 SetCurrentPlaneIJKParam();
1171 //=================================================================================
1172 // function : isStructured
1173 // purpose : return true if mesh is structured
1174 //=================================================================================
1175 bool VisuGUI_ClippingDlg::isStructured() const
1177 VISU::Result_i* result = myPrs3d ? myPrs3d->GetCResult() : 0;
1180 return result->GetAxisInfo(myPrs3d->GetCMeshName(),
1181 VISU::Result_i::AXIS_X,
1187 //=================================================================================
1188 // function : onIJKAxisChanged
1189 // purpose : update Index range and call SetCurrentPlaneParam()
1190 //=================================================================================
1191 void VisuGUI_ClippingDlg::onIJKAxisChanged(int axisId)
1195 VISU::Result_i* result = myPrs3d ? myPrs3d->GetCResult() : 0;
1197 VISU::Result_i::TAxis axis = (VISU::Result_i::TAxis) axisId;
1199 CORBA::String_var aMeshName = myPrs3d->GetMeshName();
1200 const vector<vtkFloatingPointType> * indices = result->GetAxisInfo(aMeshName.in(),
1203 maxIndex = indices->size() - 1;
1205 QString text = tr("LBL_IJK_INDEX_TO_arg").arg(maxIndex);
1206 TextLabelIJKIndex->setText(text);
1207 SpinBoxIJKIndex->setRange(0, maxIndex);
1209 if (SpinBoxIJKIndex->value() > maxIndex)
1210 SpinBoxIJKIndex->setValue(0);
1212 SetCurrentPlaneIJKParam();
1215 //=================================================================================
1216 // function : OnPreviewToggle()
1218 //=================================================================================
1219 void VisuGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled)
1221 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(theIsToggled));
1222 if (SVTK_ViewWindow* vw = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI))
1223 VISU::RenderViewWindow(vw);
1227 //=================================================================================
1228 // function : keyPressEvent()
1230 //=================================================================================
1231 void VisuGUI_ClippingDlg::keyPressEvent( QKeyEvent* e )
1233 QDialog::keyPressEvent( e );
1234 if ( e->isAccepted() )
1237 if ( e->key() == Qt::Key_F1 )
1244 void VisuGUI_ClippingDlg::SetPrs3d(VISU::Prs3d_i* thePrs)
1246 if(thePrs != myPrs3d){
1257 void VisuGUI_ClippingDlg::removeAllClippingPlanes(VISU::Prs3d_i* thePrs)
1259 for (int i = thePrs->GetNumberOfClippingPlanes() - 1; i >= 0 ; i--) {
1260 OrientedPlane* aPlane = dynamic_cast<OrientedPlane*>(thePrs->GetClippingPlane(i));
1262 thePrs->RemoveClippingPlane(i);