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 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_ClippingDlg.cxx
24 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
27 #include "SMESHGUI_ClippingDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_SpinBox.h"
34 #include <SMESH_Actor.h>
35 #include <SMESH_ActorUtils.h>
37 // SALOME GUI includes
38 #include <SUIT_Desktop.h>
39 #include <SUIT_Session.h>
40 #include <SUIT_OverrideCursor.h>
41 #include <SUIT_MessageBox.h>
42 #include <SUIT_ResourceMgr.h>
44 #include <SALOME_ListIO.hxx>
46 #include <LightApp_Application.h>
47 #include <LightApp_SelectionMgr.h>
49 #include <SVTK_ViewWindow.h>
53 #include <QPushButton>
56 #include <QVBoxLayout>
57 #include <QHBoxLayout>
58 #include <QGridLayout>
65 #include <vtkDataSet.h>
66 #include <vtkDataSetMapper.h>
67 #include <vtkPlaneSource.h>
68 #include <vtkProperty.h>
73 class OrientedPlane: public vtkPlane
75 QPointer<SVTK_ViewWindow> myViewWindow;
77 vtkDataSetMapper* myMapper;
80 static OrientedPlane *New()
82 return new OrientedPlane();
84 static OrientedPlane *New(SVTK_ViewWindow* theViewWindow)
86 return new OrientedPlane(theViewWindow);
88 vtkTypeMacro (OrientedPlane, vtkPlane);
90 SMESH::Orientation myOrientation;
94 vtkPlaneSource* myPlaneSource;
95 SALOME_Actor *myActor;
97 void SetOrientation (SMESH::Orientation theOrientation) { myOrientation = theOrientation; }
98 SMESH::Orientation GetOrientation() { return myOrientation; }
100 void SetDistance (float theDistance) { myDistance = theDistance; }
101 float GetDistance() { return myDistance; }
103 void ShallowCopy (OrientedPlane* theOrientedPlane)
105 SetNormal(theOrientedPlane->GetNormal());
106 SetOrigin(theOrientedPlane->GetOrigin());
108 myOrientation = theOrientedPlane->GetOrientation();
109 myDistance = theOrientedPlane->GetDistance();
111 myAngle[0] = theOrientedPlane->myAngle[0];
112 myAngle[1] = theOrientedPlane->myAngle[1];
114 myPlaneSource->SetNormal(theOrientedPlane->myPlaneSource->GetNormal());
115 myPlaneSource->SetOrigin(theOrientedPlane->myPlaneSource->GetOrigin());
116 myPlaneSource->SetPoint1(theOrientedPlane->myPlaneSource->GetPoint1());
117 myPlaneSource->SetPoint2(theOrientedPlane->myPlaneSource->GetPoint2());
121 OrientedPlane(SVTK_ViewWindow* theViewWindow):
122 myViewWindow(theViewWindow),
123 myOrientation(SMESH::XY),
127 myViewWindow->AddActor(myActor);
131 myOrientation(SMESH::XY),
140 myPlaneSource = vtkPlaneSource::New();
142 myAngle[0] = myAngle[1] = 0.0;
144 // Create and display actor
145 myMapper = vtkDataSetMapper::New();
146 myMapper->SetInput(myPlaneSource->GetOutput());
148 myActor = SALOME_Actor::New();
149 myActor->VisibilityOff();
150 myActor->PickableOff();
151 myActor->SetInfinitive(true);
152 myActor->SetMapper(myMapper);
154 vtkFloatingPointType anRGB[3];
155 vtkProperty* aProp = vtkProperty::New();
156 SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
157 aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
158 aProp->SetOpacity(0.75);
159 myActor->SetProperty(aProp);
162 vtkProperty* aBackProp = vtkProperty::New();
163 SMESH::GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
164 aBackProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
165 aBackProp->SetOpacity(0.75);
166 myActor->SetBackfaceProperty(aBackProp);
172 myViewWindow->RemoveActor(myActor);
175 myMapper->RemoveAllInputs();
178 // commented: porting to vtk 5.0
179 // myPlaneSource->UnRegisterAllOutputs();
180 myPlaneSource->Delete();
185 OrientedPlane (const OrientedPlane&);
186 void operator= (const OrientedPlane&);
190 struct TSetVisiblity {
191 TSetVisiblity(int theIsVisible): myIsVisible(theIsVisible){}
192 void operator()(SMESH::TVTKPlane& theOrientedPlane){
193 theOrientedPlane->myActor->SetVisibility(myIsVisible);
198 //=================================================================================
199 // used in SMESHGUI::restoreVisualParameters() to avoid
200 // declaration of OrientedPlane outside of SMESHGUI_ClippingDlg.cxx
201 //=================================================================================
202 void SMESHGUI_ClippingDlg::AddPlane (SMESH_Actor* theActor,
203 SVTK_ViewWindow* theViewWindow,
204 SMESH::Orientation theOrientation,
206 vtkFloatingPointType theAngle[2])
208 OrientedPlane* aPlane = OrientedPlane::New(theViewWindow);
210 aPlane->myAngle[0] = theAngle[0];
211 aPlane->myAngle[1] = theAngle[1];
213 aPlane->SetOrientation(theOrientation);
214 aPlane->SetDistance(theDistance);
216 vtkFloatingPointType aNormal[3];
217 vtkFloatingPointType aDir[2][3] = {{0, 0, 0}, {0, 0, 0}};
219 static double aCoeff = vtkMath::Pi()/180.0;
221 vtkFloatingPointType anU[2] = {cos(aCoeff * theAngle[0]), cos(aCoeff * theAngle[1])};
222 vtkFloatingPointType aV[2] = {sqrt(1.0 - anU[0]*anU[0]), sqrt(1.0 - anU[1]*anU[1])};
223 aV[0] = theAngle[0] > 0? aV[0]: -aV[0];
224 aV[1] = theAngle[1] > 0? aV[1]: -aV[1];
226 switch (theOrientation) {
253 vtkMath::Cross(aDir[1],aDir[0],aNormal);
254 vtkMath::Normalize(aNormal);
255 vtkMath::Cross(aNormal,aDir[1],aDir[0]);
259 theActor->SetPlaneParam(aNormal, theDistance, aPlane);
261 vtkDataSet* aDataSet = theActor->GetInput();
262 vtkFloatingPointType *aPnt = aDataSet->GetCenter();
264 vtkFloatingPointType* anOrigin = aPlane->GetOrigin();
265 vtkFloatingPointType aDel = aDataSet->GetLength()/2.0;
267 vtkFloatingPointType aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
268 {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
269 vtkFloatingPointType aParam, aPnt0[3], aPnt1[3], aPnt2[3];
271 vtkFloatingPointType aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
272 aPnt[1] - aDelta[0][1] - aDelta[1][1],
273 aPnt[2] - aDelta[0][2] - aDelta[1][2]};
274 vtkFloatingPointType aPnt02[3] = {aPnt01[0] + aNormal[0],
275 aPnt01[1] + aNormal[1],
276 aPnt01[2] + aNormal[2]};
277 vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
279 vtkFloatingPointType aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
280 aPnt[1] - aDelta[0][1] + aDelta[1][1],
281 aPnt[2] - aDelta[0][2] + aDelta[1][2]};
282 vtkFloatingPointType aPnt12[3] = {aPnt11[0] + aNormal[0],
283 aPnt11[1] + aNormal[1],
284 aPnt11[2] + aNormal[2]};
285 vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
287 vtkFloatingPointType aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
288 aPnt[1] + aDelta[0][1] - aDelta[1][1],
289 aPnt[2] + aDelta[0][2] - aDelta[1][2]};
290 vtkFloatingPointType aPnt22[3] = {aPnt21[0] + aNormal[0],
291 aPnt21[1] + aNormal[1],
292 aPnt21[2] + aNormal[2]};
293 vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
295 vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
296 aPlaneSource->SetNormal(aNormal[0],aNormal[1],aNormal[2]);
297 aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
298 aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
299 aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
301 theActor->AddClippingPlane(aPlane);
305 //=================================================================================
306 // used in SMESHGUI::restoreVisualParameters() to avoid
307 // declaration of OrientedPlane outside of SMESHGUI_ClippingDlg.cxx
308 //=================================================================================
309 void SMESHGUI_ClippingDlg::GetPlaneParam (SMESH_Actor* theActor,
311 SMESH::Orientation& theOrientation,
313 vtkFloatingPointType* theAngle)
315 if (vtkPlane* aPln = theActor->GetClippingPlane(thePlaneIndex)) {
316 if (OrientedPlane* aPlane = OrientedPlane::SafeDownCast(aPln)) {
317 theOrientation = aPlane->GetOrientation();
318 theDistance = aPlane->GetDistance();
319 theAngle[0] = aPlane->myAngle[0];
320 theAngle[1] = aPlane->myAngle[1];
325 //=================================================================================
326 // class : SMESHGUI_ClippingDlg()
329 //=================================================================================
330 SMESHGUI_ClippingDlg::SMESHGUI_ClippingDlg( SMESHGUI* theModule ):
331 QDialog( SMESH::GetDesktop(theModule) ),
332 mySelector(SMESH::GetViewWindow(theModule)->GetSelector()),
333 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
334 mySMESHGUI(theModule)
337 setAttribute( Qt::WA_DeleteOnClose, true );
338 setWindowTitle(tr("SMESH_CLIPPING_TITLE"));
339 setSizeGripEnabled(true);
341 QVBoxLayout* SMESHGUI_ClippingDlgLayout = new QVBoxLayout(this);
342 SMESHGUI_ClippingDlgLayout->setSpacing(SPACING);
343 SMESHGUI_ClippingDlgLayout->setMargin(MARGIN);
345 // Controls for selecting, creating, deleting planes
346 QGroupBox* GroupPlanes = new QGroupBox(tr("Clipping planes"), this);
347 QHBoxLayout* GroupPlanesLayout = new QHBoxLayout(GroupPlanes);
348 GroupPlanesLayout->setSpacing(SPACING);
349 GroupPlanesLayout->setMargin(MARGIN);
351 ComboBoxPlanes = new QComboBox(GroupPlanes);
353 buttonNew = new QPushButton(tr("SMESH_BUT_NEW"), GroupPlanes);
355 buttonDelete = new QPushButton(tr("SMESH_BUT_DELETE"), GroupPlanes);
357 GroupPlanesLayout->addWidget(ComboBoxPlanes);
358 GroupPlanesLayout->addStretch();
359 GroupPlanesLayout->addWidget(buttonNew);
360 GroupPlanesLayout->addWidget(buttonDelete);
362 // Controls for defining plane parameters
363 QGroupBox* GroupParameters = new QGroupBox(tr("SMESH_PARAMETERS"), this);
364 QGridLayout* GroupParametersLayout = new QGridLayout(GroupParameters);
365 GroupParametersLayout->setSpacing(SPACING);
366 GroupParametersLayout->setMargin(MARGIN);
368 TextLabelOrientation = new QLabel(tr("SMESH_ORIENTATION"), GroupParameters);
370 ComboBoxOrientation = new QComboBox(GroupParameters);
372 TextLabelDistance = new QLabel(tr("SMESH_DISTANCE"), GroupParameters);
374 SpinBoxDistance = new SMESHGUI_SpinBox(GroupParameters);
376 TextLabelRot1 = new QLabel(tr("Rotation around X (Y to Z):"), GroupParameters);
378 SpinBoxRot1 = new SMESHGUI_SpinBox(GroupParameters);
380 TextLabelRot2 = new QLabel(tr("Rotation around Y (X to Z):"), GroupParameters);
382 SpinBoxRot2 = new SMESHGUI_SpinBox(GroupParameters);
384 PreviewCheckBox = new QCheckBox(tr("Show preview"), GroupParameters);
385 PreviewCheckBox->setChecked(true);
387 AutoApplyCheckBox = new QCheckBox(tr("Auto Apply"), GroupParameters);
388 AutoApplyCheckBox->setChecked(false);
390 GroupParametersLayout->addWidget(TextLabelOrientation, 0, 0);
391 GroupParametersLayout->addWidget(ComboBoxOrientation, 0, 1);
392 GroupParametersLayout->addWidget(TextLabelDistance, 1, 0);
393 GroupParametersLayout->addWidget(SpinBoxDistance, 1, 1);
394 GroupParametersLayout->addWidget(TextLabelRot1, 2, 0);
395 GroupParametersLayout->addWidget(SpinBoxRot1, 2, 1);
396 GroupParametersLayout->addWidget(TextLabelRot2, 3, 0);
397 GroupParametersLayout->addWidget(SpinBoxRot2, 3, 1);
398 GroupParametersLayout->addWidget(PreviewCheckBox, 4, 0);
399 GroupParametersLayout->addWidget(AutoApplyCheckBox, 4, 1);
401 // Controls for "Ok", "Apply" and "Close" button
402 QGroupBox* GroupButtons = new QGroupBox(this);
403 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
404 GroupButtonsLayout->setSpacing(SPACING);
405 GroupButtonsLayout->setMargin(MARGIN);
407 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
408 buttonOk->setAutoDefault(true);
409 buttonOk->setDefault(true);
410 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
411 buttonApply->setAutoDefault(true);
412 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
413 buttonCancel->setAutoDefault(true);
414 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
415 buttonHelp->setAutoDefault(true);
416 GroupButtonsLayout->addWidget(buttonOk);
417 GroupButtonsLayout->addSpacing(10);
418 GroupButtonsLayout->addWidget(buttonApply);
419 GroupButtonsLayout->addSpacing(10);
420 GroupButtonsLayout->addStretch();
421 GroupButtonsLayout->addWidget(buttonCancel);
422 GroupButtonsLayout->addWidget(buttonHelp);
424 SMESHGUI_ClippingDlgLayout->addWidget(GroupPlanes);
425 SMESHGUI_ClippingDlgLayout->addWidget(GroupParameters);
426 SMESHGUI_ClippingDlgLayout->addWidget(GroupButtons);
429 SpinBoxDistance->RangeStepAndValidator(0.0, 1.0, 0.01, 3);
430 SpinBoxRot1->RangeStepAndValidator(-180.0, 180.0, 1, 3);
431 SpinBoxRot2->RangeStepAndValidator(-180.0, 180.0, 1, 3);
433 ComboBoxOrientation->addItem(tr("|| X-Y"));
434 ComboBoxOrientation->addItem(tr("|| Y-Z"));
435 ComboBoxOrientation->addItem(tr("|| Z-X"));
437 SpinBoxDistance->SetValue(0.5);
440 myIsSelectPlane = false;
441 onSelectionChanged();
443 myHelpFileName = "clipping_page.html";
445 // signals and slots connections :
446 connect(ComboBoxPlanes, SIGNAL(activated(int)), this, SLOT(onSelectPlane(int)));
447 connect(buttonNew, SIGNAL(clicked()), this, SLOT(ClickOnNew()));
448 connect(buttonDelete, SIGNAL(clicked()), this, SLOT(ClickOnDelete()));
449 connect(ComboBoxOrientation, SIGNAL(activated(int)), this, SLOT(onSelectOrientation(int)));
450 connect(SpinBoxDistance, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
451 connect(SpinBoxRot1, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
452 connect(SpinBoxRot2, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
453 connect(PreviewCheckBox, SIGNAL(toggled(bool)), this, SLOT(OnPreviewToggle(bool)));
454 connect(AutoApplyCheckBox, SIGNAL(toggled(bool)), this, SLOT(ClickOnApply()));
455 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
456 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
457 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
458 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
459 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
460 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
461 /* to close dialog if study frame change */
462 connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), this, SLOT(ClickOnCancel()));
467 //=================================================================================
468 // function : ~SMESHGUI_ClippingDlg()
470 //=================================================================================
471 SMESHGUI_ClippingDlg::~SMESHGUI_ClippingDlg()
473 // no need to delete child widgets, Qt does it all for us
474 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(false));
476 if (SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow(mySMESHGUI))
477 SMESH::RenderViewWindow(aViewWindow);
480 double SMESHGUI_ClippingDlg::getDistance() const
482 return SpinBoxDistance->GetValue();
485 void SMESHGUI_ClippingDlg::setDistance( const double theDistance )
487 SpinBoxDistance->SetValue( theDistance );
490 double SMESHGUI_ClippingDlg::getRotation1() const
492 return SpinBoxRot1->GetValue();
495 double SMESHGUI_ClippingDlg::getRotation2() const
497 return SpinBoxRot2->GetValue();
500 //=======================================================================
501 // function : ClickOnApply()
503 //=======================================================================
504 void SMESHGUI_ClippingDlg::ClickOnApply()
509 if (SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow(mySMESHGUI)) {
510 SUIT_OverrideCursor wc;
512 QWidget *aCurrWid = this->focusWidget();
513 aCurrWid->clearFocus();
514 aCurrWid->setFocus();
516 myActor->RemoveAllClippingPlanes();
518 SMESH::TPlanes::iterator anIter = myPlanes.begin();
519 for ( ; anIter != myPlanes.end(); anIter++) {
520 OrientedPlane* anOrientedPlane = OrientedPlane::New(aViewWindow);
521 anOrientedPlane->ShallowCopy(anIter->GetPointer());
522 myActor->AddClippingPlane(anOrientedPlane);
523 anOrientedPlane->Delete();
526 SMESH::RenderViewWindow(aViewWindow);
530 //=======================================================================
531 // function : ClickOnOk()
533 //=======================================================================
534 void SMESHGUI_ClippingDlg::ClickOnOk()
540 //=======================================================================
541 // function : ClickOnCancel()
543 //=======================================================================
544 void SMESHGUI_ClippingDlg::ClickOnCancel()
549 //=================================================================================
550 // function : ClickOnHelp()
552 //=================================================================================
553 void SMESHGUI_ClippingDlg::ClickOnHelp()
555 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
557 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
561 platform = "winapplication";
563 platform = "application";
565 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
566 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
567 arg(app->resourceMgr()->stringValue("ExternalBrowser",
569 arg(myHelpFileName));
573 //=================================================================================
574 // function : onSelectionChanged()
575 // purpose : Called when selection is changed
576 //=================================================================================
577 void SMESHGUI_ClippingDlg::onSelectionChanged()
579 if (SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow(mySMESHGUI)) {
580 const SALOME_ListIO& aList = mySelector->StoredIObjects();
581 if (aList.Extent() > 0) {
582 Handle(SALOME_InteractiveObject) IOS = aList.First();
583 myActor = SMESH::FindActorByEntry(IOS->getEntry());
585 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(false));
588 vtkIdType anId = 0, anEnd = myActor->GetNumberOfClippingPlanes();
589 for ( ; anId < anEnd; anId++) {
590 if (vtkImplicitFunction* aFunction = myActor->GetClippingPlane(anId)) {
591 if(OrientedPlane* aPlane = OrientedPlane::SafeDownCast(aFunction)){
592 OrientedPlane* anOrientedPlane = OrientedPlane::New(aViewWindow);
593 SMESH::TVTKPlane aTVTKPlane(anOrientedPlane);
594 anOrientedPlane->Delete();
595 aTVTKPlane->ShallowCopy(aPlane);
596 myPlanes.push_back(aTVTKPlane);
601 std::for_each(myPlanes.begin(),myPlanes.end(),
602 TSetVisiblity(PreviewCheckBox->isChecked()));
605 SMESH::RenderViewWindow(aViewWindow);
610 //=======================================================================
611 // function : onSelectPlane()
613 //=======================================================================
614 void SMESHGUI_ClippingDlg::onSelectPlane (int theIndex)
616 if (!myActor || myPlanes.empty())
619 OrientedPlane* aPlane = myPlanes[theIndex].GetPointer();
622 SMESH::Orientation anOrientation = aPlane->GetOrientation();
625 double aRot[2] = {aPlane->myAngle[0], aPlane->myAngle[1]};
627 // Set plane parameters in the dialog
628 myIsSelectPlane = true;
629 setDistance(aPlane->GetDistance());
630 setRotation(aRot[0], aRot[1]);
631 switch (anOrientation) {
633 ComboBoxOrientation->setCurrentIndex(0);
634 onSelectOrientation(0);
637 ComboBoxOrientation->setCurrentIndex(1);
638 onSelectOrientation(1);
641 ComboBoxOrientation->setCurrentIndex(2);
642 onSelectOrientation(2);
645 myIsSelectPlane = false;
648 //=======================================================================
649 // function : ClickOnNew()
651 //=======================================================================
652 void SMESHGUI_ClippingDlg::ClickOnNew()
657 if(SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow(mySMESHGUI)){
658 OrientedPlane* aPlane = OrientedPlane::New(aViewWindow);
659 SMESH::TVTKPlane aTVTKPlane(aPlane);
660 myPlanes.push_back(aTVTKPlane);
662 if (PreviewCheckBox->isChecked())
663 aTVTKPlane->myActor->VisibilityOn();
666 SetCurrentPlaneParam();
670 //=======================================================================
671 // function : ClickOnDelete()
673 //=======================================================================
674 void SMESHGUI_ClippingDlg::ClickOnDelete()
676 if (!myActor || myPlanes.empty())
679 int aPlaneIndex = ComboBoxPlanes->currentIndex();
681 SMESH::TPlanes::iterator anIter = myPlanes.begin() + aPlaneIndex;
682 anIter->GetPointer()->myActor->SetVisibility(false);
683 myPlanes.erase(anIter);
685 if(AutoApplyCheckBox->isChecked())
689 SMESH::RenderViewWindow(SMESH::GetCurrentVtkView());
692 //=======================================================================
693 // function : onSelectOrientation()
695 //=======================================================================
696 void SMESHGUI_ClippingDlg::onSelectOrientation (int theItem)
698 if (myPlanes.empty())
702 TextLabelRot1->setText(tr("Rotation around X (Y to Z):"));
703 TextLabelRot2->setText(tr("Rotation around Y (X to Z):"));
705 else if (theItem == 1) {
706 TextLabelRot1->setText(tr("Rotation around Y (Z to X):"));
707 TextLabelRot2->setText(tr("Rotation around Z (Y to X):"));
709 else if (theItem == 2) {
710 TextLabelRot1->setText(tr("Rotation around Z (X to Y):"));
711 TextLabelRot2->setText(tr("Rotation around X (Z to Y):"));
714 if((QComboBox*)sender() == ComboBoxOrientation)
715 SetCurrentPlaneParam();
718 //=======================================================================
719 // function : Sinchronize()
721 //=======================================================================
722 void SMESHGUI_ClippingDlg::Sinchronize()
724 int aNbPlanes = myPlanes.size();
725 ComboBoxPlanes->clear();
728 for(int i = 1; i<=aNbPlanes; i++) {
729 aName = QString(tr("Plane# %1")).arg(i);
730 ComboBoxPlanes->addItem(aName);
733 int aPos = ComboBoxPlanes->count() - 1;
734 ComboBoxPlanes->setCurrentIndex(aPos);
736 bool anIsControlsEnable = (aPos >= 0);
737 if (anIsControlsEnable) {
740 ComboBoxPlanes->addItem(tr("No planes"));
741 SpinBoxRot1->SetValue(0.0);
742 SpinBoxRot2->SetValue(0.0);
743 SpinBoxDistance->SetValue(0.5);
746 buttonDelete->setEnabled(anIsControlsEnable);
747 buttonApply->setEnabled(anIsControlsEnable);
748 PreviewCheckBox->setEnabled(anIsControlsEnable);
749 AutoApplyCheckBox->setEnabled(anIsControlsEnable);
750 ComboBoxOrientation->setEnabled(anIsControlsEnable);
751 SpinBoxDistance->setEnabled(anIsControlsEnable);
752 SpinBoxRot1->setEnabled(anIsControlsEnable);
753 SpinBoxRot2->setEnabled(anIsControlsEnable);
756 //=======================================================================
757 // function : setRotation()
759 //=======================================================================
760 void SMESHGUI_ClippingDlg::setRotation (const double theRot1, const double theRot2)
762 SpinBoxRot1->SetValue(theRot1);
763 SpinBoxRot2->SetValue(theRot2);
766 //=======================================================================
767 // function : SetCurrentPlaneParam()
769 //=======================================================================
770 void SMESHGUI_ClippingDlg::SetCurrentPlaneParam()
772 if (myPlanes.empty() || myIsSelectPlane)
775 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
777 OrientedPlane* aPlane = myPlanes[aCurPlaneIndex].GetPointer();
779 vtkFloatingPointType aNormal[3];
780 SMESH::Orientation anOrientation;
781 vtkFloatingPointType aDir[3][3] = {{0, 0, 0}, {0, 0, 0}};
783 static double aCoeff = vtkMath::Pi()/180.0;
785 vtkFloatingPointType aRot[2] = {getRotation1(), getRotation2()};
786 aPlane->myAngle[0] = aRot[0];
787 aPlane->myAngle[1] = aRot[1];
789 vtkFloatingPointType anU[2] = {cos(aCoeff*aRot[0]), cos(aCoeff*aRot[1])};
790 vtkFloatingPointType aV[2] = {sqrt(1.0-anU[0]*anU[0]), sqrt(1.0-anU[1]*anU[1])};
791 aV[0] = aRot[0] > 0? aV[0]: -aV[0];
792 aV[1] = aRot[1] > 0? aV[1]: -aV[1];
794 switch (ComboBoxOrientation->currentIndex()) {
796 anOrientation = SMESH::XY;
806 anOrientation = SMESH::YZ;
816 anOrientation = SMESH::ZX;
827 vtkMath::Cross(aDir[1],aDir[0],aNormal);
828 vtkMath::Normalize(aNormal);
829 vtkMath::Cross(aNormal,aDir[1],aDir[0]);
832 aPlane->SetOrientation(anOrientation);
833 aPlane->SetDistance(getDistance());
835 myActor->SetPlaneParam(aNormal, getDistance(), aPlane);
837 vtkDataSet* aDataSet = myActor->GetInput();
838 vtkFloatingPointType *aPnt = aDataSet->GetCenter();
840 vtkFloatingPointType* anOrigin = aPlane->GetOrigin();
841 vtkFloatingPointType aDel = aDataSet->GetLength()/2.0;
843 vtkFloatingPointType aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
844 {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
845 vtkFloatingPointType aParam, aPnt0[3], aPnt1[3], aPnt2[3];
847 vtkFloatingPointType aPnt01[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 vtkFloatingPointType aPnt02[3] = {aPnt01[0] + aNormal[0],
851 aPnt01[1] + aNormal[1],
852 aPnt01[2] + aNormal[2]};
853 vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
855 vtkFloatingPointType aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
856 aPnt[1] - aDelta[0][1] + aDelta[1][1],
857 aPnt[2] - aDelta[0][2] + aDelta[1][2]};
858 vtkFloatingPointType aPnt12[3] = {aPnt11[0] + aNormal[0],
859 aPnt11[1] + aNormal[1],
860 aPnt11[2] + aNormal[2]};
861 vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
863 vtkFloatingPointType aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
864 aPnt[1] + aDelta[0][1] - aDelta[1][1],
865 aPnt[2] + aDelta[0][2] - aDelta[1][2]};
866 vtkFloatingPointType aPnt22[3] = {aPnt21[0] + aNormal[0],
867 aPnt21[1] + aNormal[1],
868 aPnt21[2] + aNormal[2]};
869 vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
871 vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
872 aPlaneSource->SetNormal(aNormal[0],aNormal[1],aNormal[2]);
873 aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
874 aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
875 aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
877 if(AutoApplyCheckBox->isChecked())
880 SMESH::RenderViewWindow(SMESH::GetCurrentVtkView());
883 //=======================================================================
884 // function : OnPreviewToggle()
886 //=======================================================================
887 void SMESHGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled)
889 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(theIsToggled));
890 SMESH::RenderViewWindow(SMESH::GetCurrentVtkView());
893 //=================================================================================
894 // function : keyPressEvent()
896 //=================================================================================
897 void SMESHGUI_ClippingDlg::keyPressEvent( QKeyEvent* e )
899 QDialog::keyPressEvent( e );
900 if ( e->isAccepted() )
903 if ( e->key() == Qt::Key_F1 ) {