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_ClippingPanel.h"
24 #include "VisuGUI_Tools.h"
25 #include "VisuGUI_ClippingPlaneDlg.h"
26 #include "VisuGUI_ViewTools.h"
28 #include <VISU_ColoredPrs3dCache_i.hh>
30 #include <VISU_Gen_i.hh>
31 #include <VISU_ColoredPrs3dHolder_i.hh>
33 #include <LightApp_Application.h>
34 #include <SUIT_Desktop.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_ViewManager.h>
37 #include <SUIT_MessageBox.h>
38 #include <SUIT_ResourceMgr.h>
39 #include <SUIT_ViewWindow.h>
40 #include <SVTK_ViewWindow.h>
41 #include <VTKViewer_Utilities.h>
45 #include <QVBoxLayout>
46 #include <QHBoxLayout>
47 #include <QPushButton>
48 #include <QToolButton>
50 #include <QListWidget>
51 #include <QTableWidget>
52 #include <QStringList>
53 #include <QMessageBox>
56 #include <vtkImageData.h>
57 #include <vtkCutter.h>
58 #include <vtkPolyDataMapper.h>
60 #include <SALOMEDSClient_AttributeSequenceOfReal.hxx>
61 #include <SALOMEDSClient_AttributeInteger.hxx>
65 #define SIZEFACTOR 1.1
68 #define PRINT3(MARK, VAL) printf("#### %s x=%f, y=%f, z=%f\n", MARK, VAL[0], VAL[1], VAL[2]);
73 void AdjustBounds(const double bounds[6], double newBounds[6], double center[3])
75 center[0] = (bounds[0] + bounds[1])/2.0;
76 center[1] = (bounds[2] + bounds[3])/2.0;
77 center[2] = (bounds[4] + bounds[5])/2.0;
79 newBounds[0] = center[0] + SIZEFACTOR*(bounds[0]-center[0]);
80 newBounds[1] = center[0] + SIZEFACTOR*(bounds[1]-center[0]);
81 newBounds[2] = center[1] + SIZEFACTOR*(bounds[2]-center[1]);
82 newBounds[3] = center[1] + SIZEFACTOR*(bounds[3]-center[1]);
83 newBounds[4] = center[2] + SIZEFACTOR*(bounds[4]-center[2]);
84 newBounds[5] = center[2] + SIZEFACTOR*(bounds[5]-center[2]);
89 //****************************************************************
90 //PreviewPlane::PreviewPlane(SVTK_ViewWindow* theWindow, const PlaneDef& thePlane, const double* theBounds):
91 PreviewPlane::PreviewPlane(SVTK_ViewWindow* theWindow,
92 VISU_CutPlaneFunction* thePlane,
93 const double* theBounds):
100 AdjustBounds(myBounds, aBound, aCenter);
102 //myPlane = thePlane.plane;
105 myBox = vtkImageData::New();
106 myBox->SetDimensions(2, 2, 2);
107 myBox->SetOrigin(aBound[0],aBound[2],aBound[4]);
108 myBox->SetSpacing((aBound[1]-aBound[0]),
109 (aBound[3]-aBound[2]),
110 (aBound[5]-aBound[4]));
112 myCutter = vtkCutter::New();
113 myCutter->SetInput(myBox);
114 myCutter->SetCutFunction(myPlane);
116 myMapper = vtkPolyDataMapper::New();
117 myMapper->SetInput(myCutter->GetOutput());
119 myActor = vtkActor::New();
120 myActor->VisibilityOff();
121 myActor->PickableOff();
122 myActor->SetMapper(myMapper);
123 vtkProperty* aProp = vtkProperty::New();
126 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
128 QColor aFillColor = aResourceMgr->colorValue("SMESH", "fill_color", QColor(0, 170, 255));
129 anRGB[0] = aFillColor.red()/255.;
130 anRGB[1] = aFillColor.green()/255.;
131 anRGB[2] = aFillColor.blue()/255.;
132 aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
133 aProp->SetOpacity(0.75);
134 myActor->SetBackfaceProperty(aProp);
137 vtkProperty* aBackProp = vtkProperty::New();
138 QColor aBackFaceColor = aResourceMgr->colorValue("SMESH", "backface_color", QColor(0, 0, 255));
139 anRGB[0] = aBackFaceColor.red()/255.;
140 anRGB[1] = aBackFaceColor.green()/255.;
141 anRGB[2] = aBackFaceColor.blue()/255.;
142 aBackProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
143 aBackProp->SetOpacity(0.75);
144 myActor->SetProperty(aBackProp);
147 myWindow->getRenderer()->AddActor(myActor);
150 //****************************************************************
151 PreviewPlane::~PreviewPlane()
153 myWindow->getRenderer()->RemoveActor(myActor);
156 myMapper->RemoveAllInputs();
166 //****************************************************************
167 //****************************************************************
168 //****************************************************************
169 /*CutPlaneFunction* CutPlaneFunction::New()
171 return new CutPlaneFunction();
174 void CutPlaneFunction::setActive(bool theActive)
176 myIsActive = theActive;
180 double CutPlaneFunction::EvaluateFunction(double x[3])
183 return vtkPlane::EvaluateFunction(x);
188 double CutPlaneFunction::EvaluateFunction(double x, double y, double z)
191 return vtkPlane::EvaluateFunction(x,y,z);
196 CutPlaneFunction::CutPlaneFunction():
202 CutPlaneFunction::~CutPlaneFunction()
208 //****************************************************************
209 //****************************************************************
210 //****************************************************************
211 VisuGUI_ClippingPanel::VisuGUI_ClippingPanel( VisuGUI* theModule, QWidget* theParent )
212 : VisuGUI_Panel( tr( "TITLE" ), theModule, theParent, ApplyBtn | HelpBtn ),
217 setWindowTitle( tr( "TITLE" ) );
218 setObjectName( tr( "TITLE" ) );
220 QVBoxLayout* aMainLayout = new QVBoxLayout(mainFrame());
222 // List of presentations
223 aMainLayout->addWidget(new QLabel(tr("PRESENTATIONS_LBL"), mainFrame()));
224 myPrsList = new QListWidget(mainFrame());
225 myPrsList->setSelectionMode(QAbstractItemView::SingleSelection);
226 connect(myPrsList, SIGNAL(currentRowChanged(int)), this, SLOT(onPrsSelected(int)));
227 aMainLayout->addWidget(myPrsList);
230 aMainLayout->addWidget(new QLabel(tr("PLANES_LBL"), mainFrame()));
231 myPlanesList = new QTableWidget(0, 2, mainFrame());
232 myPlanesList->setColumnWidth(1, 50);
233 myPlanesList->setSelectionMode(QAbstractItemView::SingleSelection);
234 connect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)));
235 aMainLayout->addWidget(myPlanesList);
237 // Management buttons
238 QWidget* aButtonsWgt = new QWidget(mainFrame());
239 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtonsWgt);
240 aMainLayout->addWidget(aButtonsWgt);
242 QToolButton* aNewBtn = new QToolButton(aButtonsWgt);
243 aNewBtn->setToolButtonStyle(Qt::ToolButtonTextOnly);
244 aNewBtn->setText(tr("NEW_BTN"));
245 connect(aNewBtn, SIGNAL(clicked(bool)), this, SLOT(onNew()));
246 aBtnLayout->addWidget(aNewBtn);
248 QToolButton* aEditBtn = new QToolButton(aButtonsWgt);
249 aEditBtn->setToolButtonStyle(Qt::ToolButtonTextOnly);
250 aEditBtn->setText(tr("EDIT_BTN"));
251 connect(aEditBtn, SIGNAL(clicked(bool)), this, SLOT(onEdit()));
252 aBtnLayout->addWidget(aEditBtn);
254 QToolButton* aDeleteBtn = new QToolButton(aButtonsWgt);
255 aDeleteBtn->setToolButtonStyle(Qt::ToolButtonTextOnly);
256 aDeleteBtn->setText(tr("DELETE_BTN"));
257 connect(aDeleteBtn, SIGNAL(clicked(bool)), this, SLOT(onPlaneDelete()));
258 aBtnLayout->addWidget(aDeleteBtn);
260 myShowPlanes = new QCheckBox(tr("CHK_SHOW_PLANES"), mainFrame());
261 connect(myShowPlanes, SIGNAL( toggled(bool) ), this, SLOT( setPlanesVisible(bool) ));
262 aMainLayout->addWidget(myShowPlanes);
264 myNonActivePlanes = new QCheckBox(tr("CHK_ACTIVATE_PLANES"), mainFrame());
265 connect(myNonActivePlanes, SIGNAL(toggled(bool)), this, SLOT(setPlanesNonActive(bool)));
266 aMainLayout->addWidget(myNonActivePlanes);
268 myAutoApply = new QCheckBox(tr("CHK_AUTO_APPLY"), mainFrame());
269 connect(myAutoApply, SIGNAL(toggled(bool)), myApply, SLOT(setDisabled(bool)));
270 myAutoApply->setCheckState(Qt::Checked);
271 aMainLayout->addWidget(myAutoApply);
277 connect(myModule, SIGNAL(presentationCreated(VISU::Prs3d_i*)),
278 this, SLOT(onPresentationCreate(VISU::Prs3d_i*)));
279 connect(myModule, SIGNAL(beforeObjectDelete(QString)),
280 this, SLOT(onObjectDelete(QString)));
282 SUIT_Desktop* aDesktop = VISU::GetDesktop(myModule);
283 connect(aDesktop, SIGNAL(windowActivated(SUIT_ViewWindow*)),
284 this, SLOT(onWindowActivated(SUIT_ViewWindow*)));
288 //*************************************************************************
289 VisuGUI_ClippingPanel::~VisuGUI_ClippingPanel()
294 //*************************************************************************
295 void VisuGUI_ClippingPanel::fillPrsList()
298 _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myModule));
299 _PTR(SComponent) aVisuSO = aStudy->FindComponent("VISU");
303 myPresentations = getPrsList(aStudy, aVisuSO);
305 //Process Cache system folder
306 _PTR(SObject) aSObjPtr = aStudy->FindObject(VISU::ColoredPrs3dCache_i::GetFolderName().c_str());
308 _PTR(ChildIterator) Iter = aStudy->NewChildIterator( aSObjPtr );
309 for ( ; Iter->More(); Iter->Next() ) {
310 _PTR(SObject) aChildObj = Iter->Value();
311 myPresentations.append(aChildObj->GetID().c_str());
316 for (int i = 0; i < myPresentations.size(); i++) {
317 if (VISU::Prs3d_i* aPrs = getPrs(myPresentations.at(i)))
318 aNames.append(getPrsName(aPrs));
320 myPrsList->addItems(aNames);
323 //*************************************************************************
324 QString VisuGUI_ClippingPanel::getPrsName(VISU::Prs3d_i* thePrs)
329 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
330 if (!aSObject->_is_nil()) {
331 SALOMEDS::SObject_var aFather = aSObject->GetFather();
332 while (!aFather->_is_nil()) {
333 QString aFName = aFather->GetName();
334 aPath.append(aFName);
335 if (aFName == "Post-Pro") break;
336 aFather = aFather->GetFather();
338 aObjName = aSObject->GetName();
340 VISU::ColoredPrs3d_i* aColPrs = dynamic_cast<VISU::ColoredPrs3d_i*>(thePrs);
342 _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myModule));
343 _PTR(SObject) aSObjPtr = aStudy->FindObjectID(aColPrs->GetHolderEntry().c_str());
345 _PTR(SObject) aFather = aSObjPtr->GetFather();
347 QString aFName(aFather->GetName().c_str());
348 aPath.append(aFName);
349 if (aFName == "Post-Pro") break;
350 aFather = aFather->GetFather();
353 aObjName = aSObjPtr->GetName().c_str();
356 for (int j = aPath.size() - 2; j >= 0; j--)
357 aName += aPath.at(j) + "/";
362 //*************************************************************************
363 QStringList VisuGUI_ClippingPanel::getPrsList(_PTR(Study) theStudy,
364 _PTR(SObject) theObject)
366 //QList<VISU::Prs3d_i*> aList;
368 _PTR(ChildIterator) aIter = theStudy->NewChildIterator(theObject);
369 for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
370 _PTR(SObject) aSObject = aIter->Value();
371 std::vector<VISU::Prs3d_i*> aSTLList = VISU::GetPrs3dList(myModule, aSObject);
372 for (int i = 0; i < aSTLList.size(); i++) {
373 VISU::Prs3d_i* aPrs = aSTLList[i];
374 if (!aList.contains(aPrs->GetEntry().c_str()))
375 aList.append(aPrs->GetEntry().c_str());
377 if (aList.size() == 0) {
378 //QList<VISU::Prs3d_i*> aSubList = getPrsList(theStudy, aSObject);
379 QStringList aSubList = getPrsList(theStudy, aSObject);
380 for (int i = 0; i < aSubList.size(); i++) {
381 //VISU::Prs3d_i* aPrs = aSubList[i];
382 QString aPrsEntry = aSubList[i];
383 if (!aList.contains(aPrsEntry))
384 aList.append(aPrsEntry);
391 //*************************************************************************
392 VISU_ClippingPlaneMgr& VisuGUI_ClippingPanel::getPlanesMgr() const
394 return VISU::GetVisuGen(myModule)->GetClippingPlaneMgr();
397 //*************************************************************************
398 void VisuGUI_ClippingPanel::fillPlanesList()
400 disconnect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)));
401 myPlanesList->clear();
402 _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myModule));
403 VISU_ClippingPlaneMgr& aMgr = getPlanesMgr();
404 for (int i = 0; i < aMgr.GetClippingPlanesNb(); i++) {
405 VISU_CutPlaneFunction* aPlane = aMgr.GetClippingPlane(i);
406 myPlanesList->insertRow(i);
407 QTableWidgetItem* aItem = new QTableWidgetItem(aPlane->getName().c_str());
408 QTableWidgetItem* aCheckItem = new QTableWidgetItem();
409 aCheckItem->setCheckState((myNonActivePlanes->checkState() == Qt::Checked)?
410 Qt::Unchecked : Qt::Checked);
411 if (aPlane->isAuto()) { // If this is Auto plane
413 aItem->setCheckState(Qt::Checked);
414 } else { // if it is not auto
415 aItem->setCheckState(Qt::Unchecked);
416 // Check current presentation
417 int aPrsNum = myPrsList->currentRow();
419 if (VISU_ClippingPlaneMgr::ContainsPlane(getPrs(myPresentations.at(aPrsNum)), aPlane))
420 aItem->setCheckState(Qt::Checked);
423 myPlanesList->setItem(i, 0, aItem);
424 myPlanesList->setItem(i, 1, aCheckItem);
426 myPlanesList->setHorizontalHeaderLabels(QString(tr("PLANES_TABLE_TITLES")).split(","));
428 myViewWindow->Repaint();
430 /*_PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myModule));
431 _PTR(SObject) aFolder;
432 if (VISU::getClippingPlanesFolder(aStudy, aFolder)) {
433 _PTR(ChildIterator) aIter = aStudy->NewChildIterator(aFolder);
435 for (i = 0; aIter->More(); aIter->Next(), i++) { // For each plane
436 _PTR(SObject) aSObject = aIter->Value();
437 PlaneDef aNewPlane = createEmptyPlane();
438 updatePlane(aSObject, aNewPlane);
440 myPlanesList->insertRow(i);
441 QTableWidgetItem* aItem = new QTableWidgetItem(aNewPlane.name);
442 QTableWidgetItem* aCheckItem = new QTableWidgetItem();
443 aCheckItem->setCheckState((myNonActivePlanes->checkState() == Qt::Checked)? Qt::Unchecked : Qt::Checked);
445 if (aNewPlane.isAuto) { // If this is Auto plane
447 // apply to all presentations
448 aItem->setCheckState(Qt::Checked);
449 foreach(QString aPrsEntry, myPresentations) {
450 getPrs(aPrsEntry)->AddClippingPlane(aNewPlane.plane);
452 } else { // if it is not auto
453 foreach(QString aPrsEntry, myPresentations) {
454 _PTR(ChildIterator) aRefIter = aStudy->NewChildIterator(aSObject);
455 for (; aRefIter->More(); aRefIter->Next()) {
456 _PTR(SObject) aObj = aRefIter->Value();
457 _PTR(SObject) aRefPrsObject;
458 if (aObj->ReferencedObject(aRefPrsObject)) { // If it is referenced on current plane
459 if (QString(aRefPrsObject->GetID().c_str()) == aPrsEntry) {
460 getPrs(aPrsEntry)->AddClippingPlane(aNewPlane.plane);
465 aItem->setCheckState(Qt::Unchecked);
466 // Check current presentation
467 int aPrsNum = myPrsList->currentRow();
469 if (containsPlane(getPrs(myPresentations.at(aPrsNum)), aNewPlane))
470 aItem->setCheckState(Qt::Checked);
473 myPlanesList->setItem(i, 0, aItem);
474 myPlanesList->setItem(i, 1, aCheckItem);
475 myPlanes.append(aNewPlane);
478 myPlanesList->setHorizontalHeaderLabels(QString(tr("PLANES_TABLE_TITLES")).split(","));
480 myViewWindow->Repaint();*/
481 connect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)));
485 //*************************************************************************
486 void VisuGUI_ClippingPanel::init()
488 myViewWindow = VISU::GetViewWindow<SVTK_Viewer>(myModule);
490 connect(myViewWindow, SIGNAL(destroyed(QObject*)), this, SLOT(onWindowDestroyed(QObject*)));
495 void VisuGUI_ClippingPanel::onWindowDestroyed(QObject* theWnd)
497 if (theWnd == myViewWindow) {
502 //*************************************************************************
503 //void VisuGUI_ClippingPanel::showEvent(QShowEvent* event)
505 // VisuGUI_Panel::showEvent(event);
508 //*************************************************************************
509 // void VisuGUI_ClippingPanel::hideEvent(QHideEvent* event)
511 // disconnect(myModule, SIGNAL(presentationCreated()), this, SLOT(onPresentationCreate()));
512 // VisuGUI_Panel::hideEvent(event);
515 //*************************************************************************
516 void VisuGUI_ClippingPanel::onPresentationCreate(VISU::Prs3d_i* thePrs)
518 myPrsList->addItem(getPrsName(thePrs));
519 string aEntry = thePrs->GetEntry();
520 if (aEntry.length() == 0) {
521 VISU::ColoredPrs3d_i* aColPrs = dynamic_cast<VISU::ColoredPrs3d_i*>(thePrs);
523 aEntry = aColPrs->GetHolderEntry();
526 myPresentations.append(aEntry.c_str());
527 VISU_ClippingPlaneMgr& aMgr = getPlanesMgr();
528 for (int i = 0; i < aMgr.GetClippingPlanesNb(); i++) {
529 VISU_CutPlaneFunction* aPlane = aMgr.GetClippingPlane(i);
530 if (aPlane->isAuto())
531 aMgr.ApplyClippingPlane(thePrs, i);
533 /* for (int i = 0; i < myPlanes.size(); i++) {
534 const PlaneDef& aPlane = myPlanes.at(i);
536 thePrs->AddClippingPlane(aPlane.plane);
540 //*************************************************************************
541 /*PlaneDef VisuGUI_ClippingPanel::createEmptyPlane()
544 aPlane.name = QString("Plane");
545 aPlane.plane = CutPlaneFunction::New();
546 aPlane.plane->Delete();
547 aPlane.plane->SetOrigin(0.,0.,0.);
548 aPlane.plane->SetNormal(0.,0.,1.);
549 aPlane.isAuto = true;
553 //*************************************************************************
554 /*void VisuGUI_ClippingPanel::updatePlane(_PTR(SObject) theObject, PlaneDef& thePlane)
556 thePlane.name = QString(theObject->GetName().c_str());
557 thePlane.plane->setPlaneObject(theObject);
559 _PTR(GenericAttribute) anAttr;
560 if (theObject->FindAttribute(anAttr, "AttributeSequenceOfReal")) {
561 _PTR(AttributeSequenceOfReal) aArray(anAttr);
562 thePlane.plane->SetOrigin(aArray->Value(1), aArray->Value(2), aArray->Value(3));
563 thePlane.plane->SetNormal(aArray->Value(4), aArray->Value(5), aArray->Value(6));
565 if (theObject->FindAttribute(anAttr, "AttributeInteger")) {
566 _PTR(AttributeInteger) aFlag(anAttr);
567 thePlane.isAuto = (aFlag->Value() == 1);
571 //*************************************************************************
572 void VisuGUI_ClippingPanel::onNewPlane()
574 disconnect(myPlaneDlg, SIGNAL(accepted()), this, SLOT(onNewPlane()));
575 disconnect(myPlaneDlg, SIGNAL(rejected()), this, SLOT(onCancelDialog()));
576 disconnect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)));
577 //_PTR(SObject) aPlaneSObj = myPlaneDlg->getPlaneObj();
578 int aId = myPlaneDlg->planeId();
579 VISU_ClippingPlaneMgr& aMgr = getPlanesMgr();
581 VISU_CutPlaneFunction* aPlane = aMgr.GetClippingPlane(aId);
582 //PlaneDef aNewPlane = createEmptyPlane();
583 //updatePlane(aPlaneSObj, aNewPlane);
584 int aRow = myPlanesList->rowCount();
585 myPlanesList->insertRow(aRow);
587 //QTableWidgetItem* aItem = new QTableWidgetItem(aNewPlane.name);
588 QTableWidgetItem* aItem = new QTableWidgetItem(aPlane->getName().c_str());
589 QTableWidgetItem* aCheckItem = new QTableWidgetItem();
590 aCheckItem->setCheckState((myNonActivePlanes->checkState() == Qt::Checked)?
591 Qt::Unchecked : Qt::Checked);
592 //aNewPlane.plane->setActive(myNonActivePlanes->checkState() != Qt::Checked);
593 aPlane->setActive(myNonActivePlanes->checkState() != Qt::Checked);
594 //if (aNewPlane.isAuto) {
595 if (aPlane->isAuto()) {
597 aItem->setCheckState(Qt::Checked);
598 // for (int i = 0; i < myPresentations.size(); i++) {
599 // getPrs(myPresentations.at(i))->AddClippingPlane(aNewPlane.plane);
602 aItem->setCheckState(Qt::Unchecked);
604 myPlanesList->setItem(aRow, 0, aItem);
605 myPlanesList->setItem(aRow, 1, aCheckItem);
606 //myPlanes.append(aNewPlane);
611 setPlanesVisible(myShowPlanes->checkState() == Qt::Checked);
614 myViewWindow->Repaint();
615 connect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)));
618 //*************************************************************************
619 void VisuGUI_ClippingPanel::onPlaneEdited()
621 disconnect(myPlaneDlg, SIGNAL(accepted()), this, SLOT(onNewPlane()));
622 disconnect(myPlaneDlg, SIGNAL(rejected()), this, SLOT(onCancelDialog()));
623 disconnect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)));
624 //_PTR(SObject) aPlaneSObj = myPlaneDlg->getPlaneObj();
626 int aId = myPlaneDlg->planeId();
627 VISU_ClippingPlaneMgr& aMgr = getPlanesMgr();
628 VISU_CutPlaneFunction* aPlane = aMgr.GetClippingPlane(aId);
629 // PlaneDef aPlane = myPlanes.at(myEditingPlanePos);
630 //updatePlane(aPlaneSObj, aPlane);
632 //QTableWidgetItem* aItem = myPlanesList->item(myEditingPlanePos, 0);
633 QTableWidgetItem* aItem = myPlanesList->item(aId, 0);
634 // if (aPlane.isAuto) {
635 if (aPlane->isAuto()) {
636 aItem->setCheckState(Qt::Checked);
638 QString name = aPlane->getName().c_str();
639 aItem->setText(name);
640 // _PTR(Study) aStudy = VISU::GetCStudy( VISU::GetAppStudy( myModule ) );
641 // _PTR(ChildIterator) aIter = aStudy->NewChildIterator(aPlaneSObj);
642 // for (; aIter->More(); aIter->Next()) {
643 // _PTR(SObject) aObj = aIter->Value();
644 // VISU::DeleteSObject(myModule, aStudy, aObj);
646 VISU::UpdateObjBrowser(myModule);
648 aItem->setCheckState(Qt::Unchecked);
649 aItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
650 int aPrsNum = myPrsList->currentRow();
652 if (VISU_ClippingPlaneMgr::ContainsPlane(getPrs(myPresentations.at(aPrsNum)), aPlane))
653 aItem->setCheckState(Qt::Checked);
660 //myPlanes.replace(myEditingPlanePos, aPlane);
661 setPlanesVisible(myShowPlanes->checkState() == Qt::Checked);
664 myViewWindow->Repaint();
665 connect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)));
668 //*************************************************************************
669 void VisuGUI_ClippingPanel::onEdit()
671 if (!isVISUDataReady()) return;
672 if (myPlaneDlg) return;
674 int aRow = myPlanesList->currentRow();
675 if (aRow < 0) return;
677 // const PlaneDef& aPlane = myPlanes.at(aRow);
679 myPlaneDlg = new VisuGUI_ClippingPlaneDlg(myModule);
680 //myPlaneDlg->setPlaneObj(aPlane.plane->getPlaneObject());
681 myPlaneDlg->setPlaneId(aRow);
682 connect(myPlaneDlg, SIGNAL(accepted()), this, SLOT(onPlaneEdited()));
683 connect(myPlaneDlg, SIGNAL(rejected()), this, SLOT(onCancelDialog()));
684 //myEditingPlanePos = aRow;
688 //*************************************************************************
689 void VisuGUI_ClippingPanel::onNew()
691 if (!isVISUDataReady()) return;
693 if (myPlaneDlg) return;
695 myPlaneDlg = new VisuGUI_ClippingPlaneDlg(myModule);
696 connect(myPlaneDlg, SIGNAL(accepted()), this, SLOT(onNewPlane()));
697 connect(myPlaneDlg, SIGNAL(rejected()), this, SLOT(onCancelDialog()));
701 //*************************************************************************
702 void VisuGUI_ClippingPanel::onPlaneDelete()
704 if (!isVISUDataReady()) return;
705 if (myPlaneDlg) return;
707 _PTR(Study) aStudy = VISU::GetCStudy( VISU::GetAppStudy( myModule ) );
710 int aRow = myPlanesList->currentRow();
711 if (aRow < 0) return;
713 // const PlaneDef& aPlane = myPlanes.at(aRow);
714 VISU_ClippingPlaneMgr& aMgr = getPlanesMgr();
715 VISU_CutPlaneFunction* aPlane = aMgr.GetClippingPlane(aRow);
716 QMessageBox::StandardButton aRes =
717 QMessageBox::warning(VISU::GetDesktop(myModule),
718 tr("TIT_DELETE_PLANE"),
719 tr("MSG_DELETE_PLANE").arg(aPlane->getName().c_str()),
720 QMessageBox::Yes | QMessageBox::No,
722 if (aRes == QMessageBox::Yes) {
723 aMgr.DeleteClippingPlane(aRow);
724 /* short aTag1 = aPlane.plane->getPlaneObject()->Tag();
725 for (int i = 0; i < myPresentations.size(); i++) {
726 VISU::Prs3d_i* aPrs = getPrs(myPresentations.at(i));
727 for (int j = aPrs->GetNumberOfClippingPlanes()-1; j > -1; j--) {
728 CutPlaneFunction* aPln = dynamic_cast<CutPlaneFunction*>(aPrs->GetClippingPlane(j));
730 short aTag2 = aPln->getPlaneObject()->Tag();
731 if (aTag1 == aTag2) {
732 aPrs->RemoveClippingPlane(j);
738 _PTR(SObject) aSObj = aPlane.plane->getPlaneObject();
739 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
740 aBuilder->RemoveObject(aSObj);
742 myPlanesList->removeRow(aRow);
743 //myPlanes.removeAt(aRow);
745 VISU::UpdateObjBrowser(myModule);
748 myViewWindow->Repaint();
752 //*************************************************************************
753 bool VisuGUI_ClippingPanel::isVISUDataReady()
755 _PTR(Study) aStudy = VISU::GetCStudy( VISU::GetAppStudy( myModule ) );
757 _PTR(SComponent) aVisuSO = aStudy->FindComponent("VISU");
758 if (!aVisuSO) return false;
760 if(aStudy->GetProperties()->IsLocked()) return false;
764 //*************************************************************************
765 void VisuGUI_ClippingPanel::onApply()
767 if (myIsApplied) return;
771 VISU_ClippingPlaneMgr& aMgr = getPlanesMgr();
772 for (i = 0; i < aMgr.GetClippingPlanesNb(); i++) {
773 aMgr.GetClippingPlane(i)->setActive((myPlanesList->item(i, 1)->checkState() == Qt::Checked));
775 // for(i = 0; i < myPlanes.size(); i++) {
776 // aPlane = myPlanes.at(i);
777 // aPlane.plane->setActive((myPlanesList->item(i, 1)->checkState() == Qt::Checked));
781 int aPrsNum = myPrsList->currentRow();
783 // for(i = 0; i < myPlanes.size(); i++) {
784 for(i = 0; i < aMgr.GetClippingPlanesNb(); i++) {
785 applyPlaneToPrs(i, aPrsNum, (myPlanesList->item(i, 0)->checkState() == Qt::Checked));
787 //myCheckedPlanes.clear();
788 VISU::UpdateObjBrowser(myModule);
791 myViewWindow->Repaint();
794 //*************************************************************************
795 void VisuGUI_ClippingPanel::setPlanesNonActive(bool theState)
798 disconnect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)));
799 //for (int i = 0; i < myPlanes.size(); i++) {
800 VISU_ClippingPlaneMgr& aMgr = getPlanesMgr();
801 VISU_CutPlaneFunction* aPlane = 0;
802 for (int i = 0; i < aMgr.GetClippingPlanesNb(); i++) {
803 //aPlane = myPlanes.at(i);
804 aPlane = aMgr.GetClippingPlane(i);
805 //aPlane.plane->setActive(!theState);
806 aPlane->setActive(!theState);
807 myPlanesList->item(i, 1)->setCheckState((theState)? Qt::Unchecked : Qt::Checked);
810 myViewWindow->Repaint();
811 connect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)));
814 //*************************************************************************
815 void VisuGUI_ClippingPanel::setPlanesVisible(bool theVisible)
817 if (!myViewWindow) return;
821 setPlanesVisible(false);
824 ComputeVisiblePropBounds(myViewWindow->getRenderer(), aBounds);
825 VISU_ClippingPlaneMgr& aMgr = getPlanesMgr();
826 //for (int i = 0; i < myPlanes.size(); i++) {
827 for (int i = 0; i < aMgr.GetClippingPlanesNb(); i++) {
828 //PreviewPlane* aPreview = new PreviewPlane(myViewWindow, myPlanes.at(i), aBounds);
829 PreviewPlane* aPreview = new PreviewPlane(myViewWindow, aMgr.GetClippingPlane(i), aBounds);
830 aPreview->setVisible(true);
831 myPreview.append(aPreview);
834 PreviewPlane* aPreview;
835 while (myPreview.size() > 0) {
836 aPreview = myPreview.last();
837 myPreview.removeLast();
841 myViewWindow->Repaint();
844 //*************************************************************************
845 void VisuGUI_ClippingPanel::onCancelDialog()
847 disconnect(myPlaneDlg, SIGNAL(accepted()), this, SLOT(onNewPlane()));
848 disconnect(myPlaneDlg, SIGNAL(rejected()), this, SLOT(onCancelDialog()));
855 //*************************************************************************
856 void VisuGUI_ClippingPanel::onWindowActivated(SUIT_ViewWindow* theWindow)
858 setPlanesVisible(false);
859 myViewWindow = dynamic_cast<SVTK_ViewWindow*>(theWindow);
861 connect(myViewWindow, SIGNAL(destroyed(QObject*)), this, SLOT(onWindowDestroyed(QObject*)));
862 setPlanesVisible(myShowPlanes->checkState() == Qt::Checked);
865 //*************************************************************************
866 void VisuGUI_ClippingPanel::onCellChanged(int row, int col)
868 //PlaneDef aPlane = myPlanes.at(row);
869 VISU_ClippingPlaneMgr& aMgr = getPlanesMgr();
870 VISU_CutPlaneFunction* aPlane = aMgr.GetClippingPlane(row);
871 bool isChecked = (myPlanesList->item(row, col)->checkState() == Qt::Checked);
872 if (col == 1) { // activate column clicked
874 //aPlane.plane->setActive(isChecked);
875 aPlane->setActive(isChecked);
880 } else { // Plane checked
882 //if (aPlane.isAuto) return;
883 if (aPlane->isAuto()) return;
885 if (!isAutoApply()) {
886 //myCheckedPlanes.append(row);
890 int aPrsNum = myPrsList->currentRow();
891 if (aPrsNum < 0) return;
893 applyPlaneToPrs(row, aPrsNum, isChecked);
894 VISU::UpdateObjBrowser(myModule);
897 myViewWindow->Repaint();
900 //*************************************************************************
901 void VisuGUI_ClippingPanel::applyPlaneToPrs(int thePlaneNum, int thePrsNum, bool isChecked)
903 VISU::Prs3d_i* aPrs = getPrs(myPresentations.at(thePrsNum));
904 VISU_ClippingPlaneMgr& aMgr = getPlanesMgr();
905 if (isChecked) { // Apply
906 aMgr.ApplyClippingPlane(aPrs, thePlaneNum);
908 aMgr.DetachClippingPlane(aPrs, thePlaneNum);
910 /* PlaneDef aPlane = myPlanes.at(thePlaneNum);
911 _PTR(Study) aStudy = VISU::GetCStudy( VISU::GetAppStudy( myModule ) );
912 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
913 VISU::Prs3d_i* aPrs = getPrs(myPresentations.at(thePrsNum));
914 _PTR(SObject) aSObject = aPlane.plane->getPlaneObject();
915 _PTR(SObject) aPrsSObj = aStudy->FindObjectID(aPrs->GetEntry());
917 if (!containsPlane(aPrs, aPlane)) {
918 aPrs->AddClippingPlane(aPlane.plane);
920 if(!aStudy->GetProperties()->IsLocked()) {
921 _PTR(SObject) aNewObj = aBuilder->NewObject(aSObject);
922 aBuilder->Addreference(aNewObj, aPrsSObj);
926 for (int i = 0; i < aPrs->GetNumberOfClippingPlanes(); i++) {
927 if (aPrs->GetClippingPlane(i) == aPlane.plane.GetPointer()) {
928 aPrs->RemoveClippingPlane(i);
932 if(!aStudy->GetProperties()->IsLocked()) {
933 _PTR(ChildIterator) aIter = aStudy->NewChildIterator(aSObject);
934 for (; aIter->More(); aIter->Next()) {
935 _PTR(SObject) aRefObj = aIter->Value();
937 _PTR(SObject) aRefPrsObject;
938 if (aRefObj->ReferencedObject(aRefPrsObject)) {
939 if (QString(aRefPrsObject->GetID().c_str()) == QString(aPrs->GetEntry().c_str())) {
940 VISU::DeleteSObject(myModule, aStudy, aRefObj);
950 //*************************************************************************
951 /*bool VisuGUI_ClippingPanel::containsPlane(VISU::Prs3d_i* thePrs, const PlaneDef& thePlane)
953 //bool isContains = false;
954 for (int i = 0; i < thePrs->GetNumberOfClippingPlanes(); i++) {
955 if (thePrs->GetClippingPlane(i) == thePlane.plane.GetPointer()) {
963 //*************************************************************************
964 void VisuGUI_ClippingPanel::onObjectDelete(QString theEntry)
966 disconnect(myPrsList, SIGNAL(currentRowChanged(int)), this, SLOT(onPrsSelected(int)));
968 foreach (QString aPrsEntry, myPresentations) {
969 VISU::Prs3d_i* aPrs = getPrs(aPrsEntry);
971 QString aID(aPrs->GetEntry().c_str());
972 if (aID == theEntry) {
973 myPresentations.removeAt(i);
974 myPrsList->takeItem(i);
980 connect(myPrsList, SIGNAL(currentRowChanged(int)), this, SLOT(onPrsSelected(int)));
981 onPrsSelected(myPrsList->currentRow());
984 //*************************************************************************
985 void VisuGUI_ClippingPanel::onPrsSelected(int thePrs)
987 if (thePrs < 0) return;
988 if (thePrs > myPresentations.size()) return;
989 disconnect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)));
990 VISU::Prs3d_i* aPrs = getPrs(myPresentations.at(thePrs));
992 //QListOfPlanes::const_iterator aIt;
993 VISU_ClippingPlaneMgr& aMgr = getPlanesMgr();
994 for (int i = 0; i < aMgr.GetClippingPlanesNb(); i++) {
995 QTableWidgetItem* aItem = myPlanesList->item(i, 0);
996 VISU_CutPlaneFunction* aPlane = aMgr.GetClippingPlane(i);
997 if (!aPlane->isAuto())
998 aItem->setCheckState(VISU_ClippingPlaneMgr::ContainsPlane(aPrs, aPlane)?
999 Qt::Checked : Qt::Unchecked);
1001 /* for (aIt = myPlanes.begin(), i = 0; aIt != myPlanes.end(); ++aIt, i++) {
1002 QTableWidgetItem* aItem = myPlanesList->item(i, 0);
1003 const PlaneDef& aPlane = *aIt;
1005 aItem->setCheckState(containsPlane(aPrs, aPlane)? Qt::Checked : Qt::Unchecked);
1007 connect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)));
1010 //*************************************************************************
1011 bool VisuGUI_ClippingPanel::isAutoApply() const
1013 return myAutoApply->checkState() == Qt::Checked;
1017 //*************************************************************************
1018 VISU::Prs3d_i* VisuGUI_ClippingPanel::getPrs(QString theEntry)
1020 VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(VISU::GetAppStudy(myModule),
1021 qPrintable(theEntry));
1022 return VISU::GetPrs3dFromBase(anObjectInfo.myBase);
1026 //*************************************************************************
1027 void VisuGUI_ClippingPanel::onHelp()
1029 QString aHelpFileName = "clipping_page.html";
1030 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1032 app->onHelpContextModule(myModule ? app->moduleName(myModule->moduleName()) : QString(""), aHelpFileName);
1036 platform = "winapplication";
1038 platform = "application";
1040 SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
1041 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1042 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
1043 QObject::tr("BUT_OK"));