1 // Copyright (C) 2007-2010 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
23 #include "VisuGUI_ClippingDlg.h"
26 #include "VisuGUI_Tools.h"
27 #include "VisuGUI_ViewTools.h"
29 #include "VISU_Prs3d_i.hh"
30 #include "VISU_Result_i.hh"
31 #include "VISU_ColoredPrs3dHolder_i.hh"
33 #include "VISU_PipeLine.hxx"
34 #include "VISU_DataSetActor.h"
36 #include <SalomeApp_IntSpinBox.h>
37 #include <SalomeApp_DoubleSpinBox.h>
39 #include "LightApp_SelectionMgr.h"
40 #include "LightApp_Application.h"
42 #include "SVTK_ViewWindow.h"
43 #include <VTKViewer_Utilities.h>
45 #include "SUIT_Session.h"
46 #include "SUIT_Desktop.h"
47 #include "SUIT_MessageBox.h"
48 #include "SUIT_ResourceMgr.h"
49 #include "SUIT_OverrideCursor.h"
51 #include "SALOME_Actor.h"
52 #include "VISU_ViewManager_i.hh"
60 #include <QButtonGroup>
63 #include <QRadioButton>
65 #include <QPushButton>
66 #include <QListWidget>
67 #include <QVBoxLayout>
68 #include <QHBoxLayout>
69 #include <QStackedWidget>
73 #include <vtkCamera.h>
74 #include <vtkRenderer.h>
75 #include <vtkDataSet.h>
76 #include <vtkDataSetMapper.h>
77 #include <vtkImplicitFunction.h>
78 #include <vtkPlaneSource.h>
79 #include <vtkPolyData.h>
80 #include <vtkUnstructuredGrid.h>
81 #include <vtkProperty.h>
82 #include <vtkImplicitFunctionCollection.h>
90 float GetFloat (const QString& theValue, float theDefault)
92 if (theValue.isEmpty()) return theDefault;
93 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
94 QString aValue = aResourceMgr->stringValue("VISU",theValue);
95 if (aValue.isEmpty()) return theDefault;
96 return aValue.toFloat();
99 void RenderViewWindow (SVTK_ViewWindow* vw)
102 vw->getRenderer()->ResetCameraClippingRange();
108 //=================================================================================
109 //class : OrientedPlane
111 //=================================================================================
112 OrientedPlane* OrientedPlane::New()
114 return new OrientedPlane();
117 OrientedPlane* OrientedPlane::New (SVTK_ViewWindow* vw)
119 return new OrientedPlane(vw);
122 void OrientedPlane::SetOrientation(VISU::Orientation theOrientation)
124 myOrientation = theOrientation;
127 VISU::Orientation OrientedPlane::GetOrientation()
129 return myOrientation;
132 void OrientedPlane::SetDistance(float theDistance)
134 myDistance = theDistance;
137 float OrientedPlane::GetDistance()
142 void OrientedPlane::ShallowCopy(OrientedPlane* theOrientedPlane)
144 SetNormal(theOrientedPlane->GetNormal());
145 SetOrigin(theOrientedPlane->GetOrigin());
147 myOrientation = theOrientedPlane->GetOrientation();
148 myDistance = theOrientedPlane->GetDistance();
150 myAngle[0] = theOrientedPlane->myAngle[0];
151 myAngle[1] = theOrientedPlane->myAngle[1];
153 myPlaneSource->SetNormal(theOrientedPlane->myPlaneSource->GetNormal());
154 myPlaneSource->SetOrigin(theOrientedPlane->myPlaneSource->GetOrigin());
155 myPlaneSource->SetPoint1(theOrientedPlane->myPlaneSource->GetPoint1());
156 myPlaneSource->SetPoint2(theOrientedPlane->myPlaneSource->GetPoint2());
159 OrientedPlane::OrientedPlane(SVTK_ViewWindow* vw):
160 myOrientation(VISU::XY),
165 myViewWindow->AddActor(myActor, false, false); // don't adjust actors
168 OrientedPlane::OrientedPlane():
169 myOrientation(VISU::XY),
176 void OrientedPlane::Init()
178 myPlaneSource = vtkPlaneSource::New();
180 myAngle[0] = myAngle[1] = 0.0;
182 // Create and display actor
183 myMapper = vtkDataSetMapper::New();
184 myMapper->SetInput(myPlaneSource->GetOutput());
186 myActor = SALOME_Actor::New();
187 myActor->VisibilityOff();
188 myActor->PickableOff();
189 myActor->SetInfinitive(true);
190 myActor->SetMapper(myMapper);
192 vtkProperty* aProp = vtkProperty::New();
195 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
197 QColor aFillColor = aResourceMgr->colorValue("SMESH", "fill_color", QColor(0, 170, 255));
198 anRGB[0] = aFillColor.red()/255.;
199 anRGB[1] = aFillColor.green()/255.;
200 anRGB[2] = aFillColor.blue()/255.;
201 aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
202 aProp->SetOpacity(0.75);
203 myActor->SetProperty(aProp);
206 vtkProperty* aBackProp = vtkProperty::New();
207 QColor aBackFaceColor = aResourceMgr->colorValue("SMESH", "backface_color", QColor(0, 0, 255));//@
208 anRGB[0] = aBackFaceColor.red()/255.;
209 anRGB[1] = aBackFaceColor.green()/255.;
210 anRGB[2] = aBackFaceColor.blue()/255.;
211 aBackProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
212 aBackProp->SetOpacity(0.75);
213 myActor->SetBackfaceProperty(aBackProp);
217 OrientedPlane::~OrientedPlane()
219 if ( !myViewWindow.isNull() )
220 myViewWindow->RemoveActor(myActor);
224 myMapper->RemoveAllInputs();
227 // commented: porting to vtk 5.0
228 //myPlaneSource->UnRegisterAllOutputs();
229 myPlaneSource->Delete();
232 struct TSetVisiblity {
233 TSetVisiblity(int theIsVisible): myIsVisible(theIsVisible){}
234 void operator()(VISU::TVTKPlane& theOrientedPlane){
235 theOrientedPlane->myActor->SetVisibility(myIsVisible);
240 //=================================================================================
241 // class : VisuGUI_ClippingDlg()
244 //=================================================================================
245 VisuGUI_ClippingDlg::VisuGUI_ClippingDlg (VisuGUI* theModule,
247 : QDialog(VISU::GetDesktop(theModule), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
248 mySelectionMgr(VISU::GetSelectionMgr(theModule)),
249 myVisuGUI(theModule),
251 myIsSelectPlane(false),
254 setWindowTitle(tr("TITLE"));
255 setSizeGripEnabled(TRUE);
256 setAttribute( Qt::WA_DeleteOnClose, true );
258 QVBoxLayout* VisuGUI_ClippingDlgLayout = new QVBoxLayout(this);
259 VisuGUI_ClippingDlgLayout->setSpacing(6);
260 VisuGUI_ClippingDlgLayout->setMargin(11);
262 QStackedWidget* aStackWidget = new QStackedWidget(this);
263 VisuGUI_ClippingDlgLayout->addWidget(aStackWidget);
265 QWidget* aLocalPlanes = new QWidget(aStackWidget);
266 QVBoxLayout* aLocalLayout = new QVBoxLayout(aLocalPlanes);
267 aStackWidget->addWidget(aLocalPlanes);
269 // Controls for selecting, creating, deleting planes
270 QGroupBox* GroupPlanes = new QGroupBox (tr("GRP_PLANES"), aLocalPlanes);
271 QGridLayout* GroupPlanesLayout = new QGridLayout (GroupPlanes);
272 GroupPlanesLayout->setAlignment(Qt::AlignTop);
273 GroupPlanesLayout->setSpacing(6);
274 GroupPlanesLayout->setMargin(11);
275 aLocalLayout->addWidget(GroupPlanes);
277 ComboBoxPlanes = new QComboBox (GroupPlanes);
278 GroupPlanesLayout->addWidget(ComboBoxPlanes, 0, 0);
280 QSpacerItem* spacerGP = new QSpacerItem (20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
281 GroupPlanesLayout->addItem(spacerGP, 0, 1);
283 buttonNew = new QPushButton (GroupPlanes );
284 buttonNew->setText(tr("BUT_NEW"));
285 GroupPlanesLayout->addWidget(buttonNew, 0, 2);
287 buttonDelete = new QPushButton(GroupPlanes);
288 buttonDelete->setText(tr("BUT_DELETE"));
289 GroupPlanesLayout->addWidget(buttonDelete, 0, 3);
291 // Controls for defining plane parameters
294 QGroupBox* GroupParameters = new QGroupBox(tr("GRP_PARAMETERS"), aLocalPlanes);
295 QGridLayout* GroupParametersLayout = new QGridLayout (GroupParameters);
296 GroupParametersLayout->setAlignment(Qt::AlignTop);
297 GroupParametersLayout->setSpacing(6);
298 GroupParametersLayout->setMargin(11);
299 aLocalLayout->addWidget(GroupParameters);
301 TabPane = new QTabWidget (GroupParameters);
302 TabPane->addTab(createParamsTab() , tr("TAB_NON_STRUCTURED"));
303 TabPane->addTab(createIJKParamsTab(), tr("TAB_IJK_STRUCTURED"));
304 GroupParametersLayout->addWidget(TabPane, 0, 0);
310 // "Show preview" and "Auto Apply" check boxes
311 QHBoxLayout* aCheckBoxLayout = new QHBoxLayout(this);
312 VisuGUI_ClippingDlgLayout->addLayout(aCheckBoxLayout);
314 PreviewCheckBox = new QCheckBox (tr("SHOW_PREVIEW_CHK"), this);
315 PreviewCheckBox->setChecked(true);
316 aCheckBoxLayout->addWidget(PreviewCheckBox);
317 aCheckBoxLayout->addStretch();
319 AutoApplyCheckBox = new QCheckBox (tr("AUTO_APPLY_CHK"), this);
320 AutoApplyCheckBox->setChecked(false);
321 aCheckBoxLayout->addWidget(AutoApplyCheckBox);
323 // Controls for "Ok", "Apply" and "Close" button
324 QGroupBox* GroupButtons = new QGroupBox (this);
325 VisuGUI_ClippingDlgLayout->addWidget(GroupButtons);
326 QSizePolicy aSizePolicy(QSizePolicy::Expanding,
327 QSizePolicy::Fixed );
328 aSizePolicy.setHeightForWidth( GroupButtons->sizePolicy().hasHeightForWidth() );
329 aSizePolicy.setHorizontalStretch( 0 );
330 aSizePolicy.setVerticalStretch( 0 );
331 GroupButtons->setSizePolicy( aSizePolicy );
332 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
333 QGridLayout* GroupButtonsLayout = new QGridLayout (GroupButtons);
334 GroupButtons->setLayout(GroupButtonsLayout);
335 GroupButtonsLayout->setAlignment(Qt::AlignTop);
336 GroupButtonsLayout->setSpacing(6);
337 GroupButtonsLayout->setMargin(11);
338 buttonHelp = new QPushButton (GroupButtons);
339 buttonHelp->setText(tr("BUT_HELP"));
340 buttonHelp->setAutoDefault(TRUE);
341 GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
342 buttonCancel = new QPushButton (GroupButtons);
343 buttonCancel->setText(tr("BUT_CLOSE"));
344 buttonCancel->setAutoDefault(TRUE);
345 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
346 buttonApply = new QPushButton (GroupButtons);
347 buttonApply->setText(tr("BUT_APPLY"));
348 buttonApply->setAutoDefault(TRUE);
349 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
350 QSpacerItem* spacer_9 = new QSpacerItem (20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
351 GroupButtonsLayout->addItem(spacer_9, 0, 2);
352 buttonOk = new QPushButton (GroupButtons);
353 buttonOk->setText(tr("BUT_OK"));
354 buttonOk->setAutoDefault(TRUE);
355 buttonOk->setDefault(TRUE);
356 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
359 VISU::initSpinBox( SpinBoxDistance, 0., 1., .01, "length_precision" );
360 VISU::initSpinBox( SpinBoxRot1, -180., 180., 1., "angle_precision" );
361 VISU::initSpinBox( SpinBoxRot2, -180., 180., 1., "angle_precision" );
363 ComboBoxOrientation->addItem(tr("PARALLEL_XOY_COMBO_ITEM"));
364 ComboBoxOrientation->addItem(tr("PARALLEL_YOZ_COMBO_ITEM"));
365 ComboBoxOrientation->addItem(tr("PARALLEL_ZOX_COMBO_ITEM"));
367 SpinBoxDistance->setValue(0.5);
369 onSelectionChanged();
371 // signals and slots connections :
372 connect(ComboBoxPlanes , SIGNAL(activated(int)) , this, SLOT(onSelectPlane(int)));
373 connect(buttonNew , SIGNAL(clicked()) , this, SLOT(ClickOnNew()));
374 connect(buttonDelete , SIGNAL(clicked()) , this, SLOT(ClickOnDelete()));
375 connect(ComboBoxOrientation , SIGNAL(activated(int)) , this, SLOT(onSelectOrientation(int)));
376 connect(SpinBoxDistance , SIGNAL(valueChanged(double)) , this, SLOT(SetCurrentPlaneParam()));
377 connect(SpinBoxRot1 , SIGNAL(valueChanged(double)) , this, SLOT(SetCurrentPlaneParam()));
378 connect(SpinBoxRot2 , SIGNAL(valueChanged(double)) , this, SLOT(SetCurrentPlaneParam()));
379 connect(ButtonGroupIJKAxis , SIGNAL(buttonClicked(int)) , this, SLOT(onIJKAxisChanged(int)));
380 connect(SpinBoxIJKIndex , SIGNAL(valueChanged(int)) , this, SLOT(SetCurrentPlaneIJKParam()));
381 connect(CheckBoxIJKPlaneReverse, SIGNAL(toggled(bool)) , this, SLOT(SetCurrentPlaneIJKParam()));
382 connect(TabPane , SIGNAL(currentChanged (QWidget*)), this, SLOT(onTabChanged(QWidget*)));
384 connect(PreviewCheckBox , SIGNAL(toggled(bool)), this, SLOT(OnPreviewToggle(bool)));
385 connect(AutoApplyCheckBox, SIGNAL(toggled(bool)), this, SLOT(ClickOnApply()));
387 connect(buttonOk , SIGNAL(clicked()), this, SLOT(ClickOnOk()));
388 connect(buttonApply , SIGNAL(clicked()), this, SLOT(ClickOnApply()));
389 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
390 connect(buttonHelp , SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
392 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
397 //=================================================================================
398 // function : ~VisuGUI_ClippingDlg()
400 //=================================================================================
401 VisuGUI_ClippingDlg::~VisuGUI_ClippingDlg()
403 // no need to delete child widgets, Qt does it all for us
405 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(false));
406 VISU::RenderViewWindow(VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI));
409 //=================================================================================
410 // function : createParamsTab
412 //=================================================================================
413 QWidget* VisuGUI_ClippingDlg::createParamsTab()
415 QFrame* GroupParameters = new QFrame(this);
416 QGridLayout* GroupParametersLayout = new QGridLayout(GroupParameters);
417 GroupParametersLayout->setAlignment(Qt::AlignTop);
418 GroupParametersLayout->setSpacing(6);
419 GroupParametersLayout->setMargin(11);
421 TextLabelOrientation = new QLabel(GroupParameters);
422 TextLabelOrientation->setText(tr("LBL_ORIENTATION"));
423 GroupParametersLayout->addWidget(TextLabelOrientation, 0, 0);
425 ComboBoxOrientation = new QComboBox(GroupParameters);
426 GroupParametersLayout->addWidget(ComboBoxOrientation, 0, 1);
428 TextLabelDistance = new QLabel(GroupParameters);
429 TextLabelDistance->setText(tr("LBL_DISTANCE"));
430 GroupParametersLayout->addWidget(TextLabelDistance, 1, 0);
432 SpinBoxDistance = new SalomeApp_DoubleSpinBox(GroupParameters);
433 GroupParametersLayout->addWidget(SpinBoxDistance, 1, 1);
435 TextLabelRot1 = new QLabel(GroupParameters);
436 TextLabelRot1->setText(tr("LBL_ROTATION_YZ"));
437 GroupParametersLayout->addWidget(TextLabelRot1, 2, 0);
439 SpinBoxRot1 = new SalomeApp_DoubleSpinBox(GroupParameters);
440 GroupParametersLayout->addWidget(SpinBoxRot1, 2, 1);
442 TextLabelRot2 = new QLabel(GroupParameters);
443 TextLabelRot2->setText(tr("LBL_ROTATION_XZ"));
444 GroupParametersLayout->addWidget(TextLabelRot2, 3, 0);
446 SpinBoxRot2 = new SalomeApp_DoubleSpinBox(GroupParameters);
447 GroupParametersLayout->addWidget(SpinBoxRot2, 3, 1);
449 return GroupParameters;
452 //=================================================================================
453 // function : createIJKParamsTab
455 //=================================================================================
456 QWidget* VisuGUI_ClippingDlg::createIJKParamsTab()
459 WidgetIJKTab = new QFrame(this);
460 QGridLayout* IJKParametersLayout = new QGridLayout(WidgetIJKTab);
461 IJKParametersLayout->setAlignment(Qt::AlignTop);
462 IJKParametersLayout->setSpacing(6);
463 IJKParametersLayout->setMargin(11);
466 ButtonGroupIJKAxis = new QButtonGroup ( WidgetIJKTab);
467 //QGroupBox* aGBGroupBoxIJKAxis= new QGroupBox(tr("GRP_IJK_AXIS"), WidgetIJKTab );
468 GroupBoxIJKAxis= new QGroupBox(tr("GRP_IJK_AXIS"), WidgetIJKTab );
469 QHBoxLayout* aHBLay = new QHBoxLayout( GroupBoxIJKAxis );
470 ButtonGroupIJKAxis->addButton( new QRadioButton (tr("I_RADIO_BTN"), GroupBoxIJKAxis), 0 ); // 0
471 ButtonGroupIJKAxis->addButton( new QRadioButton (tr("J_RADIO_BTN"), GroupBoxIJKAxis), 1 ); // 1
472 ButtonGroupIJKAxis->addButton( new QRadioButton (tr("K_RADIO_BTN"), GroupBoxIJKAxis), 2 ); // 2
473 ButtonGroupIJKAxis->button(0)->setChecked(true);
474 aHBLay->addWidget( ButtonGroupIJKAxis->button(0) );
475 aHBLay->addWidget( ButtonGroupIJKAxis->button(1) );
476 aHBLay->addWidget( ButtonGroupIJKAxis->button(2) );
479 TextLabelIJKIndex = new QLabel(WidgetIJKTab);
480 TextLabelIJKIndex->setText(tr("LBL_IJK_INDEX"));
481 SpinBoxIJKIndex = new SalomeApp_IntSpinBox(WidgetIJKTab);
482 SpinBoxIJKIndex->setAcceptNames( false );
485 CheckBoxIJKPlaneReverse = new QCheckBox (tr("REVERSE_NORMAL_CHK"), WidgetIJKTab);
486 CheckBoxIJKPlaneReverse->setChecked(false);
488 IJKParametersLayout->addWidget(GroupBoxIJKAxis, 0, 0, 1, 2);
489 IJKParametersLayout->addWidget(TextLabelIJKIndex, 1, 0);
490 IJKParametersLayout->addWidget(SpinBoxIJKIndex, 1, 1);
491 IJKParametersLayout->addWidget(CheckBoxIJKPlaneReverse, 2, 0);
496 //=================================================================================
497 // function : ClickOnApply()
499 //=================================================================================
500 void VisuGUI_ClippingDlg::ClickOnApply()
506 //=================================================================================
507 // function : applyLocalPlanes()
509 //=================================================================================
510 void VisuGUI_ClippingDlg::applyLocalPlanes()
515 if (SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI)) {
516 SUIT_OverrideCursor wc;
518 QWidget *aCurrWid = this->focusWidget();
519 aCurrWid->clearFocus();
520 aCurrWid->setFocus();
522 // Save clipping planes, currently applied to the presentation
523 // to enable restoring this state in case of failure.
524 // Refer to bugs IPAL8849, IPAL8850 for more information.
525 typedef vtkSmartPointer<vtkPlane> TPln;
526 typedef std::vector<TPln> TPlns;
527 bool isFailed = false;
529 int iopl = 0, nbOldPlanes = myPrs3d->GetNumberOfClippingPlanes();
530 for (; iopl < nbOldPlanes; iopl++) {
531 anOldPlanes.push_back(myPrs3d->GetClippingPlane(iopl));
534 // Try to apply new clipping
535 //myPrs3d->RemoveAllClippingPlanes();
536 removeAllClippingPlanes(myPrs3d);
538 VISU::TPlanes::iterator anIter = myPlanes.begin();
539 for (; anIter != myPlanes.end(); anIter++) {
540 OrientedPlane* anOrientedPlane = OrientedPlane::New(aViewWindow);
541 anOrientedPlane->ShallowCopy(anIter->GetPointer());
542 if (!myPrs3d->AddClippingPlane(anOrientedPlane)) {
545 anOrientedPlane->Delete();
548 // Check contents of the resulting (clipped) presentation data
550 VISU_PipeLine* aPL = myPrs3d->GetPipeLine();
551 vtkMapper* aMapper = aPL->GetMapper();
552 vtkDataSet* aPrsData = aMapper->GetInput();
554 if (aPrsData->GetNumberOfCells() < 1) {
560 // Restore previous clipping state because of failure.
561 //myPrs3d->RemoveAllClippingPlanes();
562 removeAllClippingPlanes(myPrs3d);
564 TPlns::iterator anOldIter = anOldPlanes.begin();
565 for (; anOldIter != anOldPlanes.end(); anOldIter++) {
566 myPrs3d->AddClippingPlane(anOldIter->GetPointer());
569 SUIT_MessageBox::warning(VISU::GetDesktop(myVisuGUI),
571 tr("WRN_EMPTY_RESULTING_PRS"),
575 //VISU::RenderViewWindow(aViewWindow);
576 VISU::RepaintViewWindows(myVisuGUI, myIO);
583 //=================================================================================
584 // function : ClickOnOk()
586 //=================================================================================
587 void VisuGUI_ClippingDlg::ClickOnOk()
593 //=================================================================================
594 // function : ClickOnCancel()
596 //=================================================================================
597 void VisuGUI_ClippingDlg::ClickOnCancel()
602 //=================================================================================
603 // function : ClickOnHelp()
605 //=================================================================================
606 void VisuGUI_ClippingDlg::ClickOnHelp()
608 QString aHelpFileName = "clipping_page.html";
609 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
611 app->onHelpContextModule(myVisuGUI ? app->moduleName(myVisuGUI->moduleName()) : QString(""), aHelpFileName);
615 platform = "winapplication";
617 platform = "application";
619 SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
620 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
621 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
622 QObject::tr("BUT_OK"));
626 //=================================================================================
627 // function : onSelectionChanged()
628 // purpose : Called when selection is changed
629 //=================================================================================
630 void VisuGUI_ClippingDlg::onSelectionChanged()
632 if(SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI)){
634 VISU::TSelectionInfo aSelectionInfo = VISU::GetSelectedObjects(myVisuGUI);
635 if(aSelectionInfo.empty())
638 VISU::TSelectionItem aSelectionItem = aSelectionInfo.front();
639 VISU::Base_i* aBase = aSelectionItem.myObjectInfo.myBase;
643 Handle(SALOME_InteractiveObject) anIO = aSelectionItem.myIO;
648 // rnv: fix for issue 0020114 (EDF VISU 918 : Impossible to
649 // create a new clipping plane on field presentation)
650 // set last visited presentation from holder as myPrs3d
651 VISU::ColoredPrs3dHolder_i* aHolder = dynamic_cast<VISU::ColoredPrs3dHolder_i*>(aBase);
652 VISU::Prs3d_i* aPrs3d = NULL;
654 aPrs3d = aHolder->GetPrs3dDevice();
656 aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aBase);
661 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(false));
664 CORBA::Float anOffset[3];
665 myPrs3d->GetOffset(anOffset[0],anOffset[1],anOffset[2]);
667 vtkIdType anId = 0, anEnd = myPrs3d->GetNumberOfClippingPlanes();
668 for (; anId < anEnd; anId++) {
669 if (vtkImplicitFunction* aFunction = myPrs3d->GetClippingPlane(anId)) {
670 if (OrientedPlane* aPlane = OrientedPlane::SafeDownCast(aFunction)) {
671 OrientedPlane* anOrientedPlane = OrientedPlane::New(aViewWindow);
672 VISU::TVTKPlane aTVTKPlane(anOrientedPlane);
673 anOrientedPlane->Delete();
674 aTVTKPlane->ShallowCopy(aPlane);
675 aTVTKPlane->myActor->SetPosition(anOffset[0],anOffset[1],anOffset[2]);
676 myPlanes.push_back(aTVTKPlane);
681 std::for_each(myPlanes.begin(),myPlanes.end(),
682 TSetVisiblity(PreviewCheckBox->isChecked()));
685 // enable/disable IJK tab
686 TabPane->setTabEnabled(TabPane->indexOf(WidgetIJKTab), isStructured());
688 VISU::RenderViewWindow(aViewWindow);
692 //=================================================================================
693 // function : onSelectPlane()
695 //=================================================================================
696 void VisuGUI_ClippingDlg::onSelectPlane(int theIndex)
698 if (!myPrs3d || myPlanes.empty())
701 OrientedPlane* aPlane = myPlanes[theIndex].GetPointer();
704 VISU::Orientation anOrientation = aPlane->GetOrientation();
707 double aRot[2] = {aPlane->myAngle[0], aPlane->myAngle[1]};
709 // Set plane parameters in the dialog
710 myIsSelectPlane = true;
711 setDistance(aPlane->GetDistance());
712 setRotation(aRot[0], aRot[1]);
714 switch (anOrientation) {
715 case VISU::XY: item = 0; break;
716 case VISU::YZ: item = 1; break;
717 case VISU::ZX: item = 2; break;
719 ComboBoxOrientation->setCurrentIndex(item);
721 bool isIJK = (TabPane->currentWidget() == WidgetIJKTab);
723 setIJKByNonStructured();
725 onSelectOrientation(item);
727 myIsSelectPlane = false;
730 //=================================================================================
731 // function : ClickOnNew()
733 //=================================================================================
734 void VisuGUI_ClippingDlg::ClickOnNew()
736 VISU::TSelectionInfo aSelectionInfo = VISU::GetSelectedObjects(myVisuGUI);
737 if(aSelectionInfo.empty())
740 const VISU::TSelectionItem& aSelectionItem = aSelectionInfo[0];
741 if(!aSelectionItem.myObjectInfo.myBase)
744 SetCurrentPlaneParam();
749 if (SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI)) {
750 OrientedPlane* aPlane = OrientedPlane::New(aViewWindow);
751 VISU::TVTKPlane aTVTKPlane(aPlane);
752 myPlanes.push_back(aTVTKPlane);
754 CORBA::Float anOffset[3];
755 myPrs3d->GetOffset(anOffset[0],anOffset[1],anOffset[2]);
756 aTVTKPlane->myActor->SetPosition(anOffset[0],anOffset[1],anOffset[2]);
758 if (PreviewCheckBox->isChecked())
759 aTVTKPlane->myActor->VisibilityOn();
762 SetCurrentPlaneParam();
766 //=================================================================================
767 // function : ClickOnDelete()
769 //=================================================================================
770 void VisuGUI_ClippingDlg::ClickOnDelete()
772 if (!myPrs3d || myPlanes.empty())
775 int aPlaneIndex = ComboBoxPlanes->currentIndex();
777 VISU::TPlanes::iterator anIter = myPlanes.begin() + aPlaneIndex;
778 anIter->GetPointer()->myActor->SetVisibility(false);
779 myPlanes.erase(anIter);
781 if(AutoApplyCheckBox->isChecked())
785 if (SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI))
786 VISU::RenderViewWindow(aViewWindow);
789 //=================================================================================
790 // function : onSelectOrientation()
792 //=================================================================================
793 void VisuGUI_ClippingDlg::onSelectOrientation(int theItem)
795 if (myPlanes.empty())
799 TextLabelRot1->setText(tr("LBL_ROTATION_YZ"));
800 TextLabelRot2->setText(tr("LBL_ROTATION_XZ"));
802 else if (theItem == 1) {
803 TextLabelRot1->setText(tr("LBL_ROTATION_ZX"));
804 TextLabelRot2->setText(tr("LBL_ROTATION_YX"));
806 else if (theItem == 2) {
807 TextLabelRot1->setText(tr("LBL_ROTATION_XY"));
808 TextLabelRot2->setText(tr("LBL_ROTATION_ZY"));
811 if((QComboBox*)sender() == ComboBoxOrientation)
812 SetCurrentPlaneParam();
815 //=================================================================================
816 // function : Sinchronize()
817 // purpose : update control values according to plane selection
818 //=================================================================================
819 void VisuGUI_ClippingDlg::Sinchronize()
821 int aNbPlanes = myPlanes.size();
822 ComboBoxPlanes->clear();
825 for (int i = 1; i<=aNbPlanes; i++) {
826 aName = QString(tr("PLANES_COMBO_ITEM_i")).arg(i);
827 ComboBoxPlanes->addItem(aName);
830 int aPos = ComboBoxPlanes->count() - 1;
831 ComboBoxPlanes->setCurrentIndex(aPos);
833 bool anIsControlsEnable = (aPos >= 0);
834 if (anIsControlsEnable) {
837 ComboBoxPlanes->addItem(tr("PLANES_COMBO_ITEM_no"));
838 SpinBoxRot1->setValue(0.0);
839 SpinBoxRot2->setValue(0.0);
840 SpinBoxDistance->setValue(0.5);
843 buttonDelete ->setEnabled(anIsControlsEnable);
844 //buttonApply ->setEnabled(anIsControlsEnable);
845 // PreviewCheckBox ->setEnabled(anIsControlsEnable);
846 // AutoApplyCheckBox ->setEnabled(anIsControlsEnable);
848 ComboBoxOrientation ->setEnabled(anIsControlsEnable);
849 SpinBoxDistance ->setEnabled(anIsControlsEnable);
850 SpinBoxRot1 ->setEnabled(anIsControlsEnable);
851 SpinBoxRot2 ->setEnabled(anIsControlsEnable);
853 GroupBoxIJKAxis ->setEnabled(anIsControlsEnable);
854 SpinBoxIJKIndex ->setEnabled(anIsControlsEnable);
855 CheckBoxIJKPlaneReverse->setEnabled(anIsControlsEnable);
856 //ENK: 23.11.2006 - PAL13176 - EDF228 VISU : Enhancement of structured datas processing
858 VISU_PipeLine* aPipeLine = myPrs3d->GetPipeLine();
859 VISU::PIDMapper anIDMapper = aPipeLine->GetIDMapper();
860 if ( anIDMapper->IsStructured() ) {
861 VISU::TStructuredId aStructuredId = anIDMapper->GetStructure();
862 ButtonGroupIJKAxis->button(0)->setEnabled( aStructuredId[0] >= 0 );
863 ButtonGroupIJKAxis->button(1)->setEnabled( aStructuredId[1] >= 0 );
864 ButtonGroupIJKAxis->button(2)->setEnabled( aStructuredId[2] >= 0 );
870 //=================================================================================
871 // function : setRotation()
873 //=================================================================================
874 void VisuGUI_ClippingDlg::setRotation(const double theRot1, const double theRot2)
876 SpinBoxRot1->setValue(theRot1);
877 SpinBoxRot2->setValue(theRot2);
880 //=================================================================================
881 // function : SetCurrentPlaneParam()
883 //=================================================================================
884 void VisuGUI_ClippingDlg::SetCurrentPlaneParam()
886 if (myPlanes.empty() || myIsSelectPlane)
889 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
891 OrientedPlane* aPlane = myPlanes[aCurPlaneIndex].GetPointer();
893 vtkFloatingPointType aNormal[3];
894 VISU::Orientation anOrientation;
895 vtkFloatingPointType aDir[3][3] = {{0, 0, 0}, {0, 0, 0}};
897 static double aCoeff = vtkMath::Pi()/180.0;
899 vtkFloatingPointType aRot[2] = {getRotation1(), getRotation2()};
900 aPlane->myAngle[0] = aRot[0];
901 aPlane->myAngle[1] = aRot[1];
903 vtkFloatingPointType anU[2] = {cos(aCoeff*aRot[0]), cos(aCoeff*aRot[1])};
904 vtkFloatingPointType aV[2] = {sqrt(1.0-anU[0]*anU[0]), sqrt(1.0-anU[1]*anU[1])};
905 aV[0] = aRot[0] > 0? aV[0]: -aV[0];
906 aV[1] = aRot[1] > 0? aV[1]: -aV[1];
908 switch (ComboBoxOrientation->currentIndex()) {
910 anOrientation = VISU::XY;
920 anOrientation = VISU::YZ;
930 anOrientation = VISU::ZX;
941 vtkMath::Cross(aDir[1],aDir[0],aNormal);
942 vtkMath::Normalize(aNormal);
943 vtkMath::Cross(aNormal,aDir[1],aDir[0]);
946 aPlane->SetOrientation(anOrientation);
947 aPlane->SetDistance(getDistance());
949 myPrs3d->SetPlaneParam(aNormal, 1. - getDistance(), aPlane);
951 vtkDataSet* aDataSet = myPrs3d->GetInput();
952 vtkFloatingPointType *aPnt = aDataSet->GetCenter();
954 vtkFloatingPointType* anOrigin = aPlane->GetOrigin();
955 vtkFloatingPointType aDel = aDataSet->GetLength()/2.0;
957 vtkFloatingPointType aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
958 {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
959 vtkFloatingPointType aParam, aPnt0[3], aPnt1[3], aPnt2[3];
961 vtkFloatingPointType aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
962 aPnt[1] - aDelta[0][1] - aDelta[1][1],
963 aPnt[2] - aDelta[0][2] - aDelta[1][2]};
964 vtkFloatingPointType aPnt02[3] = {aPnt01[0] + aNormal[0],
965 aPnt01[1] + aNormal[1],
966 aPnt01[2] + aNormal[2]};
967 vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
969 vtkFloatingPointType aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
970 aPnt[1] - aDelta[0][1] + aDelta[1][1],
971 aPnt[2] - aDelta[0][2] + aDelta[1][2]};
972 vtkFloatingPointType aPnt12[3] = {aPnt11[0] + aNormal[0],
973 aPnt11[1] + aNormal[1],
974 aPnt11[2] + aNormal[2]};
975 vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
977 vtkFloatingPointType aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
978 aPnt[1] + aDelta[0][1] - aDelta[1][1],
979 aPnt[2] + aDelta[0][2] - aDelta[1][2]};
980 vtkFloatingPointType aPnt22[3] = {aPnt21[0] + aNormal[0],
981 aPnt21[1] + aNormal[1],
982 aPnt21[2] + aNormal[2]};
983 vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
985 vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
986 aPlaneSource->SetNormal(aNormal[0],aNormal[1],aNormal[2]);
987 aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
988 aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
989 aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
991 if (AutoApplyCheckBox->isChecked())
994 if (SVTK_ViewWindow* vw = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI))
995 VISU::RenderViewWindow(vw);
998 //=================================================================================
999 // function : onTabChanged
1001 //=================================================================================
1002 void VisuGUI_ClippingDlg::onTabChanged(QWidget* newTab)
1004 if (newTab == WidgetIJKTab) // IJK
1005 setIJKByNonStructured();
1007 // set correct labels of rotation spin boxes
1008 onSelectOrientation(ComboBoxOrientation->currentIndex());
1012 //=================================================================================
1013 // function : SetCurrentPlaneIJKParam
1014 // purpose : set non structured parameters by IJK parameters
1015 //=================================================================================
1016 void VisuGUI_ClippingDlg::SetCurrentPlaneIJKParam()
1018 if (myPlanes.empty() || myIsSelectPlane || !WidgetIJKTab->isEnabled())
1021 VISU::Result_i* result = myPrs3d ? myPrs3d->GetCResult() : 0;
1026 int i, axId = ButtonGroupIJKAxis->id (ButtonGroupIJKAxis->checkedButton());
1027 VISU::Result_i::TAxis axis = (VISU::Result_i::TAxis) axId;
1029 CORBA::String_var aMeshName = myPrs3d->GetMeshName();
1030 const vector<vtkFloatingPointType> * values =
1031 result->GetAxisInfo(aMeshName.in(), axis, dir);
1036 int index = SpinBoxIJKIndex->value();
1037 vtkFloatingPointType distance = 0;
1038 if (index < values->size())
1039 distance = (*values)[ index ];
1041 // find id of axis closest to dir
1042 // 0 || X-Y - axis Z
1043 // 1 || Y-Z - azis X
1044 // 2 || Z-X - axiz Y
1045 double cos[3] = { gp::DZ() * dir, gp::DX() * dir, gp::DY() * dir };
1047 for (i = 0; i < 3; ++i) {
1048 if (Abs(cos[ i ]) > Abs (maxCos)) {
1053 // find rotation angles
1054 vtkFloatingPointType angle[2];
1056 (axId == 0) ? 2 : axId - 1,
1057 (axId == 2) ? 0 : axId + 1
1059 static double aCoeff = 180.0/vtkMath::Pi();
1060 for (i = 0; i < 2; ++i) {
1061 vtkFloatingPointType cosin = cos[ rotId[ i ]];
1064 angle[ i ] = asin(cosin) * aCoeff;
1066 // angle[ i ] += 180. * (angle[ i ] < 0 ? 1. : -1.);
1068 if (CheckBoxIJKPlaneReverse->isChecked()) {
1069 angle[ 0 ] += 180. * (angle[ 0 ] < 0 ? 1. : -1.);
1070 distance = 1. - distance;
1073 // distance = 1. - distance;
1076 myIsSelectPlane = true;
1077 ComboBoxOrientation->setCurrentIndex(axId);
1078 setRotation(-angle[0], -angle[1]);
1079 setDistance(distance);
1080 myIsSelectPlane = false;
1082 SetCurrentPlaneParam();
1085 //=================================================================================
1086 // function : setIJKByNonStructured
1087 // purpose : convert current non structured parameters to structured ones
1088 //=================================================================================
1089 void VisuGUI_ClippingDlg::setIJKByNonStructured()
1091 if (!myPrs3d || myPlanes.empty() || !myPrs3d->GetCResult())
1095 int planeIndex = ComboBoxPlanes->currentIndex();
1096 OrientedPlane* plane = myPlanes[ planeIndex ].GetPointer();
1097 vtkPlaneSource* planeSource = plane->myPlaneSource;
1098 vtkFloatingPointType * planeNormal = planeSource->GetNormal();
1099 gp_Dir normal(planeNormal[0], planeNormal[1], planeNormal[2]);
1101 // find a grid axis most co-directed with plane normal
1102 // and cartesian axis most co-directed with plane normal
1103 int i, maxAx = 0, gridAxId = 0;
1104 gp_Dir dir, gridDir;
1106 const vector<vtkFloatingPointType> *curValues, *values = 0;
1107 VISU::Result_i* result = myPrs3d->GetCResult();
1109 VISU_PipeLine* aPipeLine = myPrs3d->GetPipeLine();
1110 VISU::PIDMapper anIDMapper = aPipeLine->GetIDMapper();
1111 if ( anIDMapper->IsStructured() && !anIDMapper->myIsPolarType )
1112 aNbAxes = anIDMapper->GetStructureDim();
1113 for (i = 0; i < aNbAxes; ++i) {
1114 VISU::Result_i::TAxis axis = (VISU::Result_i::TAxis) i;
1115 CORBA::String_var aMeshName = myPrs3d->GetMeshName();
1116 curValues = result->GetAxisInfo(aMeshName.in(), axis, dir);
1118 double dot = normal * dir;
1119 //ENK: 23.11.2006 - PAL13176
1125 } else if (Abs(dot) >= Abs(maxDot)) {
1133 if (Abs (planeNormal[ maxAx ]) < Abs (planeNormal[ i ]))
1136 gp_XYZ axDir(0,0,0);
1137 axDir.SetCoord(maxAx + 1, 1.);
1140 double v = SpinBoxDistance->value();
1142 // bool reverse = (normal * axDir < 0); // normal and axis are opposite
1143 // if (gridDir * axDir < 0) // grid dir and axis are opposite
1144 // reverse = !reverse;
1147 for (i = 0; i < values->size(); ++i)
1148 if ((*values)[ i ] > v)
1150 if (i == values->size())
1152 if (i != 0 && (*values)[ i ] - v > v - (*values)[ i - 1])
1155 // set control values
1156 myIsSelectPlane = true;
1157 CheckBoxIJKPlaneReverse->setChecked(normal * axDir < 0);
1158 SpinBoxIJKIndex->setValue(i);
1159 ButtonGroupIJKAxis->button(gridAxId)->setChecked( true );
1160 onIJKAxisChanged(gridAxId); // update label and range of index
1161 myIsSelectPlane = false;
1163 SetCurrentPlaneIJKParam();
1166 //=================================================================================
1167 // function : isStructured
1168 // purpose : return true if mesh is structured
1169 //=================================================================================
1170 bool VisuGUI_ClippingDlg::isStructured() const
1172 VISU::Result_i* result = myPrs3d ? myPrs3d->GetCResult() : 0;
1175 return result->GetAxisInfo(myPrs3d->GetCMeshName(),
1176 VISU::Result_i::AXIS_X,
1182 //=================================================================================
1183 // function : onIJKAxisChanged
1184 // purpose : update Index range and call SetCurrentPlaneParam()
1185 //=================================================================================
1186 void VisuGUI_ClippingDlg::onIJKAxisChanged(int axisId)
1190 VISU::Result_i* result = myPrs3d ? myPrs3d->GetCResult() : 0;
1192 VISU::Result_i::TAxis axis = (VISU::Result_i::TAxis) axisId;
1194 CORBA::String_var aMeshName = myPrs3d->GetMeshName();
1195 const vector<vtkFloatingPointType> * indices = result->GetAxisInfo(aMeshName.in(),
1198 maxIndex = indices->size() - 1;
1200 QString text = tr("LBL_IJK_INDEX_TO_arg").arg(maxIndex);
1201 TextLabelIJKIndex->setText(text);
1202 SpinBoxIJKIndex->setRange(0, maxIndex);
1204 if (SpinBoxIJKIndex->value() > maxIndex)
1205 SpinBoxIJKIndex->setValue(0);
1207 SetCurrentPlaneIJKParam();
1210 //=================================================================================
1211 // function : OnPreviewToggle()
1213 //=================================================================================
1214 void VisuGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled)
1216 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(theIsToggled));
1217 if (SVTK_ViewWindow* vw = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI))
1218 VISU::RenderViewWindow(vw);
1222 //=================================================================================
1223 // function : keyPressEvent()
1225 //=================================================================================
1226 void VisuGUI_ClippingDlg::keyPressEvent( QKeyEvent* e )
1228 QDialog::keyPressEvent( e );
1229 if ( e->isAccepted() )
1232 if ( e->key() == Qt::Key_F1 )
1239 void VisuGUI_ClippingDlg::SetPrs3d(VISU::Prs3d_i* thePrs)
1241 if(thePrs != myPrs3d){
1243 myPrs3d->UnRegister();
1252 void VisuGUI_ClippingDlg::removeAllClippingPlanes(VISU::Prs3d_i* thePrs)
1254 for (int i = thePrs->GetNumberOfClippingPlanes() - 1; i >= 0 ; i--) {
1255 OrientedPlane* aPlane = dynamic_cast<OrientedPlane*>(thePrs->GetClippingPlane(i));
1257 thePrs->RemoveClippingPlane(i);