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_ClippingPlaneDlg.h"
24 #include "VisuGUI_Tools.h"
25 #include "VisuGUI_ViewTools.h"
27 #include <VISU_Gen_i.hh>
29 #include <LightApp_Application.h>
30 #include <SUIT_Desktop.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_ViewManager.h>
33 #include <SUIT_MessageBox.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <QtxDoubleSpinBox.h>
36 #include <SVTK_ViewWindow.h>
37 #include <VTKViewer_Utilities.h>
39 #include <QVBoxLayout>
40 #include <QHBoxLayout>
44 #include <QGridLayout>
46 #include <QPushButton>
48 #include <vtkCallbackCommand.h>
49 #include <vtkImplicitPlaneWidget.h>
52 #define SIZEFACTOR 1.1
57 //****************************************************************
58 //****************************************************************
59 //****************************************************************
60 VisuGUI_ClippingPlaneDlg::VisuGUI_ClippingPlaneDlg(VisuGUI* theModule)
61 : QDialog(VISU::GetDesktop(theModule), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
63 myCallback( vtkCallbackCommand::New() ),
68 myViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myModule);
69 VISU::ComputeVisiblePropBounds(myViewWindow, myBounds);
71 setWindowTitle(tr("TITLE"));
72 setSizeGripEnabled(true);
75 myCallback->SetClientData(this);
76 myCallback->SetCallback(VisuGUI_ClippingPlaneDlg::ProcessEvents);
78 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
80 QWidget* aPlanesWgt = new QWidget(this);
81 aMainLayout->addWidget(aPlanesWgt);
82 QVBoxLayout* aFrameLayout = new QVBoxLayout(aPlanesWgt);
84 QWidget* aNameBox = new QWidget(aPlanesWgt);
85 aFrameLayout->addWidget(aNameBox);
86 QHBoxLayout* aNameLayout = new QHBoxLayout(aNameBox);
88 aNameLayout->addWidget(new QLabel(tr("LBL_NAME"), aPlanesWgt));
89 myNameEdt = new QLineEdit();
91 _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myModule));
92 _PTR(SObject) aFolderSO;
93 if (VISU::getClippingPlanesFolder(aStudy, aFolderSO)) {
94 _PTR(ChildIterator) aIter = aStudy->NewChildIterator(aFolderSO);
96 for (; aIter->More(); aIter->Next()) i++;
98 myNameEdt->setText(QString("Plane %1").arg(i));
100 aNameLayout->addWidget(myNameEdt);
102 QGroupBox* aOriginGroup = new QGroupBox( tr( "ORIGIN_TITLE" ), aPlanesWgt );
103 aFrameLayout->addWidget(aOriginGroup);
104 QHBoxLayout* aOriginLayout = new QHBoxLayout(aOriginGroup);
106 aOriginLayout->addWidget( new QLabel("X", aOriginGroup) );
107 myXOrigin = new QtxDoubleSpinBox( -1000.0, 1000.0, 0.1, aOriginGroup );
108 myXOrigin->setValue( 0.0 );
109 connect(myXOrigin, SIGNAL(valueChanged(double)), this, SLOT(onValueChanged()));
110 aOriginLayout->addWidget( myXOrigin );
112 aOriginLayout->addWidget( new QLabel("Y", aOriginGroup) );
113 myYOrigin = new QtxDoubleSpinBox( -1000.0, 1000, 0.1, aOriginGroup );
114 myYOrigin->setValue( 0.0 );
115 connect(myYOrigin, SIGNAL(valueChanged(double)), this, SLOT(onValueChanged()));
116 aOriginLayout->addWidget( myYOrigin );
118 aOriginLayout->addWidget( new QLabel("Z", aOriginGroup) );
119 myZOrigin = new QtxDoubleSpinBox( -1000.0, 1000.0, 0.1, aOriginGroup );
120 myZOrigin->setValue( 0.0 );
121 connect(myZOrigin, SIGNAL(valueChanged(double)), this, SLOT(onValueChanged()));
122 aOriginLayout->addWidget( myZOrigin );
124 QGroupBox* aDirGroup = new QGroupBox( tr( "DIRECTION_TITLE" ), aPlanesWgt );
125 aFrameLayout->addWidget(aDirGroup);
126 QHBoxLayout* aDirLayout = new QHBoxLayout(aDirGroup);
128 aDirLayout->addWidget( new QLabel("dX", aDirGroup) );
129 myXDir = new QtxDoubleSpinBox( -1000.0, 1000.0, 0.1, aDirGroup );
130 myXDir->setValue( 0.0 );
131 connect(myXDir, SIGNAL(valueChanged(double)), this, SLOT(onValueChanged()));
132 aDirLayout->addWidget( myXDir );
134 aDirLayout->addWidget( new QLabel("dY", aDirGroup) );
135 myYDir = new QtxDoubleSpinBox( -1000.0, 1000.0, 0.1, aDirGroup );
136 myYDir->setValue( 0.0 );
137 connect(myYDir, SIGNAL(valueChanged(double)), this, SLOT(onValueChanged()));
138 aDirLayout->addWidget( myYDir );
140 aDirLayout->addWidget( new QLabel("dZ", aDirGroup) );
141 myZDir = new QtxDoubleSpinBox( -1000.0, 1000.0, 0.1, aDirGroup );
142 myZDir->setValue( 1.0 );
143 connect(myZDir, SIGNAL(valueChanged(double)), this, SLOT(onValueChanged()));
144 aDirLayout->addWidget( myZDir );
146 myAutoApply = new QCheckBox(tr("CHK_AUTOAPPLY"), aPlanesWgt);
147 myAutoApply->setCheckState(Qt::Checked);
148 aFrameLayout->addWidget(myAutoApply);
151 QGroupBox* aGroupButtons = new QGroupBox (this);
152 aMainLayout->addWidget(aGroupButtons);
154 QSizePolicy aSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed );
155 QHBoxLayout* aButtonsLayout = new QHBoxLayout(aGroupButtons);
157 QPushButton* aBtnOk = new QPushButton(tr("BUT_OK"), aGroupButtons);
158 aButtonsLayout->addWidget(aBtnOk);
160 aButtonsLayout->addStretch();
162 QPushButton* aBtnClose = new QPushButton(tr("BUT_CANCEL"), aGroupButtons);
163 aButtonsLayout->addWidget(aBtnClose);
165 QPushButton* aBtnHelp = new QPushButton(tr("BUT_HELP"), aGroupButtons);
166 aButtonsLayout->addWidget(aBtnHelp);
168 connect(aBtnOk , SIGNAL(clicked()), this, SLOT(accept()));
169 connect(aBtnClose, SIGNAL(clicked()), this, SLOT(reject()));
170 connect(aBtnHelp , SIGNAL(clicked()), this, SLOT(onHelp()));
173 myPreviewWidget = createPreviewWidget();
174 myViewWindow->Repaint();
177 VisuGUI_ClippingPlaneDlg::~VisuGUI_ClippingPlaneDlg()
179 if (myPreviewWidget) {
180 myPreviewWidget->Off();
181 myPreviewWidget->Delete();
184 myCallback->Delete();
187 //****************************************************************
188 void VisuGUI_ClippingPlaneDlg::ProcessEvents(vtkObject* theObject,
189 unsigned long theEvent,
191 void* vtkNotUsed(theCallData))
193 vtkImplicitPlaneWidget* aWidget = vtkImplicitPlaneWidget::SafeDownCast(theObject);
194 if (aWidget == NULL) return;
195 if (theClientData == NULL) return;
197 VisuGUI_ClippingPlaneDlg* aDlg = (VisuGUI_ClippingPlaneDlg*) theClientData;
203 case vtkCommand::InteractionEvent:
204 aWidget->GetOrigin(aOrigin);
205 aWidget->GetNormal(aDir);
207 aDlg->setOrigin(aOrigin);
208 aDlg->setDirection(aDir);
214 //****************************************************************
215 void VisuGUI_ClippingPlaneDlg::setOrigin(double theVal[3])
217 myXOrigin->setValue(theVal[0]);
218 myYOrigin->setValue(theVal[1]);
219 myZOrigin->setValue(theVal[2]);
222 //****************************************************************
223 void VisuGUI_ClippingPlaneDlg::setDirection(double theVal[3])
225 myXDir->setValue(theVal[0]);
226 myYDir->setValue(theVal[1]);
227 myZDir->setValue(theVal[2]);
230 //****************************************************************
231 void VisuGUI_ClippingPlaneDlg::onValueChanged()
233 if (!myPreviewWidget) return;
236 aOrigin[0] = myXOrigin->value();
237 aOrigin[1] = myYOrigin->value();
238 aOrigin[2] = myZOrigin->value();
240 aDir[0] = myXDir->value();
241 aDir[1] = myYDir->value();
242 aDir[2] = myZDir->value();
244 myPreviewWidget->SetOrigin(aOrigin);
245 myPreviewWidget->SetNormal(aDir);
246 myViewWindow->Repaint();
249 //****************************************************************
250 vtkImplicitPlaneWidget* VisuGUI_ClippingPlaneDlg::createPreviewWidget()
252 vtkImplicitPlaneWidget* aPlaneWgt = vtkImplicitPlaneWidget::New();
253 aPlaneWgt->SetInteractor(myViewWindow->getInteractor());
254 aPlaneWgt->SetPlaceFactor(SIZEFACTOR);
255 aPlaneWgt->ScaleEnabledOff();
256 aPlaneWgt->PlaceWidget(myBounds[0],myBounds[1],myBounds[2],myBounds[3],myBounds[4],myBounds[5]);
257 aPlaneWgt->SetOrigin(0,0,0);
258 aPlaneWgt->SetNormal(0,0,1);
261 //aPlaneWgt->OutlineTranslationOff();
262 //aPlaneWgt->ScaleEnabledOn();
263 aPlaneWgt->AddObserver(vtkCommand::InteractionEvent,
264 myCallback.GetPointer(),
270 //****************************************************************
271 void VisuGUI_ClippingPlaneDlg::setPlaneId(int theId)
274 VISU_ClippingPlaneMgr& aMgr = VISU::GetVisuGen(myModule)->GetClippingPlaneMgr();
276 VISU_CutPlaneFunction* aPlane = aMgr.GetClippingPlane(myPlaneId);
278 myNameEdt->setText(QString(aPlane->getName().c_str()));
279 double aOrigin[3], aDir[3];
280 aPlane->GetOrigin(aOrigin);
281 aPlane->GetNormal(aDir);
283 myXOrigin->setValue(aOrigin[0]);
284 myYOrigin->setValue(aOrigin[1]);
285 myZOrigin->setValue(aOrigin[2]);
286 myPreviewWidget->SetOrigin(aOrigin);
288 myXDir->setValue(aDir[0]);
289 myYDir->setValue(aDir[1]);
290 myZDir->setValue(aDir[2]);
292 myPreviewWidget->SetNormal(aDir);
294 myAutoApply->setCheckState((aPlane->isAuto())? Qt::Checked : Qt::Unchecked);
295 myViewWindow->Repaint();
298 /*void VisuGUI_ClippingPlaneDlg::setPlaneObj(_PTR(SObject) thePlaneObj)
300 myPlaneObj = thePlaneObj;
302 myNameEdt->setText(QString(myPlaneObj->GetName().c_str()));
304 _PTR(GenericAttribute) anAttr;
305 if (myPlaneObj->FindAttribute(anAttr, "AttributeSequenceOfReal")) {
306 _PTR(AttributeSequenceOfReal) aArray(anAttr);
307 myXOrigin->setValue(aArray->Value(1));
308 myYOrigin->setValue(aArray->Value(2));
309 myZOrigin->setValue(aArray->Value(3));
311 myPreviewWidget->SetOrigin(aArray->Value(1), aArray->Value(2), aArray->Value(3));
313 myXDir->setValue(aArray->Value(4));
314 myYDir->setValue(aArray->Value(5));
315 myZDir->setValue(aArray->Value(6));
317 myPreviewWidget->SetNormal(aArray->Value(4), aArray->Value(5), aArray->Value(6));
319 if (myPlaneObj->FindAttribute(anAttr, "AttributeInteger")) {
320 _PTR(AttributeInteger) aFlag(anAttr);
321 myAutoApply->setCheckState((aFlag->Value() == 1)? Qt::Checked : Qt::Unchecked);
324 myViewWindow->Repaint();
327 //****************************************************************
328 void VisuGUI_ClippingPlaneDlg::accept()
330 _PTR(Study) aStudy = VISU::GetCStudy( VISU::GetAppStudy( myModule ) );
331 if(!aStudy->GetProperties()->IsLocked()) {
332 VISU_ClippingPlaneMgr& aMgr = VISU::GetVisuGen(myModule)->GetClippingPlaneMgr();
333 if (myPlaneId == -1) { // Create a New plane
334 myPlaneId = aMgr.CreateClippingPlane(myXOrigin->value(), myYOrigin->value(), myZOrigin->value(),
335 myXDir->value(), myYDir->value(), myZDir->value(),
336 myAutoApply->checkState() == Qt::Checked,
337 qPrintable(myNameEdt->text()));
338 } else { // Edit Plane
339 aMgr.EditClippingPlane(myPlaneId,
340 myXOrigin->value(), myYOrigin->value(), myZOrigin->value(),
341 myXDir->value(), myYDir->value(), myZDir->value(),
342 myAutoApply->checkState() == Qt::Checked,
343 qPrintable(myNameEdt->text()));
345 VISU::UpdateObjBrowser(myModule);
347 /* _PTR(Study) aStudy = VISU::GetCStudy( VISU::GetAppStudy( myModule ) );
348 if(!aStudy->GetProperties()->IsLocked()) {
349 _PTR(SObject) aFolder;
350 if (VISU::getClippingPlanesFolder(aStudy, aFolder)) {
351 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
352 if (myPlaneObj == 0) { // Create a New plane
353 myPlaneObj = aBuilder->NewObject(aFolder);
356 _PTR(GenericAttribute) anAttr;
357 anAttr = aBuilder->FindOrCreateAttribute(myPlaneObj,"AttributeName");
358 _PTR(AttributeName) aName(anAttr);
359 aName->SetValue(myNameEdt->text().toStdString());
363 aParams[0] = myXOrigin->value();
364 aParams[1] = myYOrigin->value();
365 aParams[2] = myZOrigin->value();
366 aParams[3] = myXDir->value();
367 aParams[4] = myYDir->value();
368 aParams[5] = myZDir->value();
370 anAttr = aBuilder->FindOrCreateAttribute(myPlaneObj,"AttributeSequenceOfReal");
371 _PTR(AttributeSequenceOfReal) aArray(anAttr);
372 if (aArray->Length() == 6) {
373 for (int i = 0; i < 6; i++)
374 aArray->ChangeValue(i+1, aParams[i]);
376 for (int i = 0; i < 6; i++)
377 aArray->Add(aParams[i]);
380 anAttr = aBuilder->FindOrCreateAttribute(myPlaneObj,"AttributeInteger");
381 _PTR(AttributeInteger) aFlag(anAttr);
382 aFlag->SetValue((myAutoApply->checkState() == Qt::Checked)? 1 : 0);
384 VISU::UpdateObjBrowser(myModule);
391 //****************************************************************
392 void VisuGUI_ClippingPlaneDlg::onHelp()
394 QString aHelpFileName = "clipping_page.html";
395 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
397 app->onHelpContextModule(myModule ? app->moduleName(myModule->moduleName()) : QString(""), aHelpFileName);
401 platform = "winapplication";
403 platform = "application";
405 SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
406 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
407 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
408 QObject::tr("BUT_OK"));